Fix tags-input:
* the code handling `separators` was buggy, so i simplified to use only one separator * was not practical for bot quotes (can't edit), so replaced by a textarea
This commit is contained in:
parent
8cc9061092
commit
7cabf12864
@ -62,7 +62,7 @@ export function tplChannelConfiguration (el: ChannelConfigurationElement): Templ
|
|||||||
entries: {
|
entries: {
|
||||||
inputType: 'tags',
|
inputType: 'tags',
|
||||||
default: [],
|
default: [],
|
||||||
separators: ['\n', '\t', ';']
|
separator: '\n'
|
||||||
},
|
},
|
||||||
regexp: {
|
regexp: {
|
||||||
inputType: 'checkbox',
|
inputType: 'checkbox',
|
||||||
@ -87,9 +87,9 @@ export function tplChannelConfiguration (el: ChannelConfigurationElement): Templ
|
|||||||
},
|
},
|
||||||
quotes: {
|
quotes: {
|
||||||
messages: {
|
messages: {
|
||||||
inputType: 'tags',
|
inputType: 'textarea',
|
||||||
default: [],
|
default: [],
|
||||||
separators: ['\n', '\t', ';']
|
separator: '\n'
|
||||||
},
|
},
|
||||||
delay: {
|
delay: {
|
||||||
inputType: 'number',
|
inputType: 'number',
|
||||||
|
@ -67,7 +67,7 @@ interface CellDataSchema {
|
|||||||
label?: TemplateResult | string
|
label?: TemplateResult | string
|
||||||
options?: { [key: string]: string }
|
options?: { [key: string]: string }
|
||||||
datalist?: DynamicTableAcceptedTypes[]
|
datalist?: DynamicTableAcceptedTypes[]
|
||||||
separators?: string[]
|
separator?: string
|
||||||
inputType?: DynamicTableAcceptedInputTypes
|
inputType?: DynamicTableAcceptedInputTypes
|
||||||
default?: DynamicTableAcceptedTypes
|
default?: DynamicTableAcceptedTypes
|
||||||
colClassList?: string[] // CSS classes to add to the <td> element.
|
colClassList?: string[] // CSS classes to add to the <td> element.
|
||||||
@ -148,7 +148,9 @@ export class DynamicTableFormElement extends LivechatElement {
|
|||||||
// Note: we make multiple querySelector, to be sure to not get a nested table.
|
// Note: we make multiple querySelector, to be sure to not get a nested table.
|
||||||
// We want the top level table associated tr.
|
// We want the top level table associated tr.
|
||||||
const input = this.querySelector('table')?.querySelector(
|
const input = this.querySelector('table')?.querySelector(
|
||||||
'&>tbody>tr:last-child>td input:not([type=hidden]),&>tbody>tr:last-child>td livechat-tags-input'
|
'&>tbody>tr:last-child>td input:not([type=hidden]),' +
|
||||||
|
'&>tbody>tr:last-child>td livechat-tags-input,' +
|
||||||
|
'&>tbody>tr:last-child>td textarea'
|
||||||
)
|
)
|
||||||
if (input) {
|
if (input) {
|
||||||
(input as HTMLElement).focus()
|
(input as HTMLElement).focus()
|
||||||
@ -462,7 +464,7 @@ export class DynamicTableFormElement extends LivechatElement {
|
|||||||
inputName,
|
inputName,
|
||||||
propertyName,
|
propertyName,
|
||||||
propertySchema,
|
propertySchema,
|
||||||
(propertyValue)?.join(propertySchema.separators?.[0] ?? ',') ??
|
(propertyValue)?.join(propertySchema.separator ?? ',') ??
|
||||||
propertyValue ?? propertySchema.default ?? '',
|
propertyValue ?? propertySchema.default ?? '',
|
||||||
originalIndex)}
|
originalIndex)}
|
||||||
${feedback}
|
${feedback}
|
||||||
@ -477,7 +479,7 @@ export class DynamicTableFormElement extends LivechatElement {
|
|||||||
inputName,
|
inputName,
|
||||||
propertyName,
|
propertyName,
|
||||||
propertySchema,
|
propertySchema,
|
||||||
(propertyValue)?.join(propertySchema.separators?.[0] ?? ',') ??
|
(propertyValue)?.join(propertySchema.separator ?? ',') ??
|
||||||
propertyValue ?? propertySchema.default ?? '',
|
propertyValue ?? propertySchema.default ?? '',
|
||||||
originalIndex)}
|
originalIndex)}
|
||||||
${feedback}
|
${feedback}
|
||||||
@ -568,7 +570,7 @@ export class DynamicTableFormElement extends LivechatElement {
|
|||||||
.minlength=${propertySchema.minlength}
|
.minlength=${propertySchema.minlength}
|
||||||
.maxlength=${propertySchema.maxlength}
|
.maxlength=${propertySchema.maxlength}
|
||||||
.datalist=${propertySchema.datalist as any}
|
.datalist=${propertySchema.datalist as any}
|
||||||
.separators=${propertySchema.separators}
|
.separator=${propertySchema.separator}
|
||||||
@change=${(event: Event) => this._updatePropertyFromValue(event, propertyName, propertySchema, rowId)}
|
@change=${(event: Event) => this._updatePropertyFromValue(event, propertyName, propertySchema, rowId)}
|
||||||
.value=${propertyValue as any}
|
.value=${propertyValue as any}
|
||||||
></livechat-tags-input>`
|
></livechat-tags-input>`
|
||||||
@ -725,13 +727,11 @@ export class DynamicTableFormElement extends LivechatElement {
|
|||||||
if (rowById._id === rowId) {
|
if (rowById._id === rowId) {
|
||||||
switch (propertySchema.default?.constructor) {
|
switch (propertySchema.default?.constructor) {
|
||||||
case Array:
|
case Array:
|
||||||
if (value.constructor === Array) {
|
if (value.constructor === Array || !propertySchema.separator) {
|
||||||
rowById.row[propertyName] = value
|
rowById.row[propertyName] = value
|
||||||
} else {
|
} else {
|
||||||
rowById.row[propertyName] = (value as string)
|
rowById.row[propertyName] = (value as string)
|
||||||
.split(new RegExp(`(?:${propertySchema.separators
|
.split(propertySchema.separator)
|
||||||
?.map((c: string) => c.replace(/^[.\\+*?[^\]$(){}=!<>|:-]$/, '\\'))
|
|
||||||
.join('|') ?? ''})+)`))
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
@ -46,7 +46,7 @@ export class TagsInputElement extends LivechatElement {
|
|||||||
private readonly _isPressingKey: string[] = []
|
private readonly _isPressingKey: string[] = []
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public separators?: string[] = ['\n']
|
public separator: string = '\n'
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public animDuration: number = 200
|
public animDuration: number = 200
|
||||||
@ -145,15 +145,13 @@ export class TagsInputElement extends LivechatElement {
|
|||||||
target?.value?.slice(target.selectionEnd ?? target?.value?.length ?? 0) ?? ''
|
target?.value?.slice(target.selectionEnd ?? target?.value?.length ?? 0) ?? ''
|
||||||
}`
|
}`
|
||||||
|
|
||||||
let values = newValue.split(new RegExp(`(?:${this.separators
|
let values = newValue.split(this.separator)
|
||||||
?.map((c: string) => c.replace(/^[.\\+*?[^\]$(){}=!<>|:-]$/, '\\'))
|
|
||||||
.join('|') ?? ''})+`))
|
|
||||||
|
|
||||||
values = values.map(v => v.trim()).filter(v => v !== '')
|
values = values.map(v => v.trim()).filter(v => v !== '')
|
||||||
|
|
||||||
if (values.length > 0) {
|
if (values.length > 0) {
|
||||||
// Keep last value in input if value doesn't finish with a separator
|
// Keep last value in input if value doesn't finish with a separator
|
||||||
if (!this.separators?.some(separator => newValue.match(/\s+$/m)?.[0]?.includes(separator))) {
|
if (!newValue.match(/\s+$/m)?.[0]?.includes(this.separator)) {
|
||||||
target.value = values.pop() ?? ''
|
target.value = values.pop() ?? ''
|
||||||
} else {
|
} else {
|
||||||
target.value = ''
|
target.value = ''
|
||||||
@ -257,7 +255,7 @@ export class TagsInputElement extends LivechatElement {
|
|||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
this._inputValue = target.value
|
this._inputValue = target.value
|
||||||
if (this.separators?.includes(target.value.slice(-1))) {
|
if (this.separator === target.value.slice(-1)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
target.value = target.value.slice(0, -1)
|
target.value = target.value.slice(0, -1)
|
||||||
this._handleNewTag(e)
|
this._handleNewTag(e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user