@dataloop-ai/components 0.20.259 → 0.20.261-new-input.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -175,10 +175,16 @@
|
|
|
175
175
|
bordered
|
|
176
176
|
:style="{ maxWidth: suggestMenuWidth }"
|
|
177
177
|
>
|
|
178
|
+
<slot name="suggestion-header">
|
|
179
|
+
<dl-list-item v-if="suggestionHeader">
|
|
180
|
+
{{ suggestionHeader }}
|
|
181
|
+
</dl-list-item>
|
|
182
|
+
</slot>
|
|
178
183
|
<dl-list-item
|
|
179
184
|
v-for="(item, suggestIndex) in suggestItems"
|
|
180
185
|
:key="item.suggestion"
|
|
181
186
|
clickable
|
|
187
|
+
:start-icon="getSuggestionStartIcon(item)"
|
|
182
188
|
style="
|
|
183
189
|
font-size: var(
|
|
184
190
|
--dl-typography-body-body3-font-size
|
|
@@ -189,35 +195,44 @@
|
|
|
189
195
|
"
|
|
190
196
|
@click="onClick($event, item)"
|
|
191
197
|
>
|
|
192
|
-
<
|
|
193
|
-
|
|
194
|
-
:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
<span
|
|
198
|
-
v-for="(word, index) in getSuggestWords(
|
|
199
|
-
item.suggestion,
|
|
200
|
-
modelValue
|
|
201
|
-
)"
|
|
202
|
-
:key="JSON.stringify(word) + index"
|
|
203
|
-
:class="{
|
|
204
|
-
'dl-input__suggestion--highlighted':
|
|
205
|
-
word.highlighted
|
|
206
|
-
}"
|
|
198
|
+
<slot
|
|
199
|
+
name="suggestion-item"
|
|
200
|
+
:item="item"
|
|
201
|
+
:keyword="modelValue"
|
|
202
|
+
:suggest-index="suggestIndex"
|
|
207
203
|
>
|
|
208
|
-
<
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
204
|
+
<img
|
|
205
|
+
v-if="item.image"
|
|
206
|
+
:src="item.image"
|
|
207
|
+
class="dl-input__suggestion--image"
|
|
208
|
+
/>
|
|
212
209
|
<span
|
|
213
|
-
v-
|
|
214
|
-
word
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
v-for="(
|
|
211
|
+
word, index
|
|
212
|
+
) in getSuggestWords(
|
|
213
|
+
item.suggestion,
|
|
214
|
+
modelValue
|
|
215
|
+
)"
|
|
216
|
+
:key="JSON.stringify(word) + index"
|
|
217
|
+
:class="{
|
|
218
|
+
'dl-input__suggestion--highlighted':
|
|
219
|
+
word.highlighted
|
|
220
|
+
}"
|
|
219
221
|
>
|
|
220
|
-
|
|
222
|
+
<span v-if="word.value[0] === ' '"
|
|
223
|
+
> </span
|
|
224
|
+
>
|
|
225
|
+
{{ word.value }}
|
|
226
|
+
<span
|
|
227
|
+
v-if="
|
|
228
|
+
word.value[
|
|
229
|
+
word.value.length - 1
|
|
230
|
+
] === ' '
|
|
231
|
+
"
|
|
232
|
+
> </span
|
|
233
|
+
>
|
|
234
|
+
</span>
|
|
235
|
+
</slot>
|
|
221
236
|
</dl-list-item>
|
|
222
237
|
</dl-list>
|
|
223
238
|
</dl-menu>
|
|
@@ -609,6 +624,20 @@ export default defineComponent({
|
|
|
609
624
|
type: String,
|
|
610
625
|
default: 'auto'
|
|
611
626
|
},
|
|
627
|
+
/**
|
|
628
|
+
* Text shown at the top of the suggestions list
|
|
629
|
+
*/
|
|
630
|
+
suggestionHeader: {
|
|
631
|
+
type: String,
|
|
632
|
+
default: ''
|
|
633
|
+
},
|
|
634
|
+
/**
|
|
635
|
+
* Open suggestion menu when input is focused
|
|
636
|
+
*/
|
|
637
|
+
openSuggestionsOnFocus: {
|
|
638
|
+
type: Boolean,
|
|
639
|
+
default: false
|
|
640
|
+
},
|
|
612
641
|
/**
|
|
613
642
|
* Tooltip showed when hovering over the clear button
|
|
614
643
|
*/
|
|
@@ -697,12 +726,17 @@ export default defineComponent({
|
|
|
697
726
|
const isInternalChange = ref(false)
|
|
698
727
|
|
|
699
728
|
const suggestItems = computed<DlInputSuggestion[]>(() => {
|
|
700
|
-
|
|
729
|
+
const inputValue =
|
|
730
|
+
modelValue.value === null || modelValue.value === undefined
|
|
731
|
+
? ''
|
|
732
|
+
: modelValue.value.toString()
|
|
701
733
|
return getSuggestItems(
|
|
702
734
|
autoSuggestItems.value,
|
|
703
|
-
|
|
735
|
+
inputValue
|
|
704
736
|
) as DlInputSuggestion[]
|
|
705
737
|
})
|
|
738
|
+
const getSuggestionStartIcon = (item: DlInputSuggestion) =>
|
|
739
|
+
(item as any).startIcon
|
|
706
740
|
const input = ref(null)
|
|
707
741
|
|
|
708
742
|
const setHighlightedIndex = (value: any) => {
|
|
@@ -977,6 +1011,7 @@ export default defineComponent({
|
|
|
977
1011
|
emitAddFile,
|
|
978
1012
|
emitRemoveFile,
|
|
979
1013
|
updateSyntax,
|
|
1014
|
+
getSuggestionStartIcon,
|
|
980
1015
|
stringSuggestions,
|
|
981
1016
|
showPlaceholder,
|
|
982
1017
|
spanText,
|
|
@@ -1124,7 +1159,14 @@ export default defineComponent({
|
|
|
1124
1159
|
return !this.$slots.append && this.type === 'password'
|
|
1125
1160
|
},
|
|
1126
1161
|
showSuggestItems(): boolean {
|
|
1127
|
-
|
|
1162
|
+
const hasValue =
|
|
1163
|
+
this.modelValue !== null &&
|
|
1164
|
+
this.modelValue !== undefined &&
|
|
1165
|
+
`${this.modelValue}`.length > 0
|
|
1166
|
+
return (
|
|
1167
|
+
!!this.suggestItems?.length &&
|
|
1168
|
+
(hasValue || (this.openSuggestionsOnFocus && this.focused))
|
|
1169
|
+
)
|
|
1128
1170
|
},
|
|
1129
1171
|
debouncedBlur(): any {
|
|
1130
1172
|
if (stateManager.disableDebounce) {
|
|
@@ -1286,6 +1328,9 @@ export default defineComponent({
|
|
|
1286
1328
|
el.scroll(el.scrollWidth, 0)
|
|
1287
1329
|
}
|
|
1288
1330
|
this.focused = true
|
|
1331
|
+
if (this.openSuggestionsOnFocus && this.suggestItems?.length) {
|
|
1332
|
+
this.isMenuOpen = true
|
|
1333
|
+
}
|
|
1289
1334
|
this.$emit('focus', e)
|
|
1290
1335
|
},
|
|
1291
1336
|
blur(): void {
|
|
@@ -1299,6 +1344,7 @@ export default defineComponent({
|
|
|
1299
1344
|
: el.innerText
|
|
1300
1345
|
el.scroll(0, 0)
|
|
1301
1346
|
this.focused = false
|
|
1347
|
+
this.isMenuOpen = false
|
|
1302
1348
|
this.$emit('blur', e)
|
|
1303
1349
|
this.handleValueTrim()
|
|
1304
1350
|
},
|
|
@@ -1310,10 +1356,14 @@ export default defineComponent({
|
|
|
1310
1356
|
},
|
|
1311
1357
|
onNativeFocus(e: FocusEvent): void {
|
|
1312
1358
|
this.focused = true
|
|
1359
|
+
if (this.openSuggestionsOnFocus && this.suggestItems?.length) {
|
|
1360
|
+
this.isMenuOpen = true
|
|
1361
|
+
}
|
|
1313
1362
|
this.$emit('focus', e)
|
|
1314
1363
|
},
|
|
1315
1364
|
onNativeBlur(e: FocusEvent): void {
|
|
1316
1365
|
this.focused = false
|
|
1366
|
+
this.isMenuOpen = false
|
|
1317
1367
|
this.$emit('blur', e)
|
|
1318
1368
|
},
|
|
1319
1369
|
onNativeEnterPress(e: KeyboardEvent): void {
|
|
@@ -53,6 +53,11 @@ export default defineComponent({
|
|
|
53
53
|
required: false,
|
|
54
54
|
type: String as PropType<Mode>,
|
|
55
55
|
default: Mode.text
|
|
56
|
+
},
|
|
57
|
+
autoFocus: {
|
|
58
|
+
required: false,
|
|
59
|
+
type: Boolean,
|
|
60
|
+
default: true
|
|
56
61
|
}
|
|
57
62
|
},
|
|
58
63
|
emits: [
|
|
@@ -64,11 +69,20 @@ export default defineComponent({
|
|
|
64
69
|
'blur'
|
|
65
70
|
],
|
|
66
71
|
setup(props, { emit }) {
|
|
67
|
-
const { modelValue, indentation, readonly, mode } =
|
|
72
|
+
const { modelValue, indentation, readonly, mode, autoFocus } =
|
|
73
|
+
toRefs(props)
|
|
68
74
|
|
|
69
75
|
const jsonEditorRef = ref(null)
|
|
70
76
|
const jsonEditor = ref<JSONEditor>(null as any)
|
|
71
77
|
const innerUpdate = ref(false)
|
|
78
|
+
const suppressNextFocus = ref(false)
|
|
79
|
+
|
|
80
|
+
const blurActiveEditorElement = () => {
|
|
81
|
+
const target = jsonEditorRef.value as HTMLElement | null
|
|
82
|
+
if (target?.contains(document.activeElement)) {
|
|
83
|
+
;(document.activeElement as HTMLElement)?.blur()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
72
86
|
|
|
73
87
|
watch(modelValue, (val) => {
|
|
74
88
|
if (innerUpdate.value) {
|
|
@@ -76,9 +90,18 @@ export default defineComponent({
|
|
|
76
90
|
return
|
|
77
91
|
}
|
|
78
92
|
|
|
93
|
+
if (!autoFocus.value) {
|
|
94
|
+
suppressNextFocus.value = true
|
|
95
|
+
}
|
|
79
96
|
jsonEditor.value?.set({
|
|
80
97
|
text: val
|
|
81
98
|
})
|
|
99
|
+
if (!autoFocus.value) {
|
|
100
|
+
nextTick(() => {
|
|
101
|
+
blurActiveEditorElement()
|
|
102
|
+
suppressNextFocus.value = false
|
|
103
|
+
})
|
|
104
|
+
}
|
|
82
105
|
})
|
|
83
106
|
|
|
84
107
|
watch(mode, (val) => {
|
|
@@ -136,6 +159,10 @@ export default defineComponent({
|
|
|
136
159
|
navigationBar: false,
|
|
137
160
|
statusBar: false,
|
|
138
161
|
onFocus: () => {
|
|
162
|
+
if (suppressNextFocus.value) {
|
|
163
|
+
blurActiveEditorElement()
|
|
164
|
+
return
|
|
165
|
+
}
|
|
139
166
|
emit('focus')
|
|
140
167
|
},
|
|
141
168
|
onBlur: () => {
|
|
@@ -156,10 +183,15 @@ export default defineComponent({
|
|
|
156
183
|
jsonEditor.value?.set({
|
|
157
184
|
text: modelValue.value
|
|
158
185
|
})
|
|
159
|
-
|
|
160
186
|
nextTick(() => {
|
|
161
187
|
jsonEditor.value?.refresh()
|
|
162
188
|
})
|
|
189
|
+
|
|
190
|
+
if (!autoFocus.value) {
|
|
191
|
+
nextTick(() => {
|
|
192
|
+
blurActiveEditorElement()
|
|
193
|
+
})
|
|
194
|
+
}
|
|
163
195
|
}
|
|
164
196
|
|
|
165
197
|
watch(readonly, (val) => {
|