@dataloop-ai/components 0.19.132 → 0.19.134
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 +1 -1
- package/src/components/compound/DlSearches/DlSmartSearch/components/DlSmartSearchInput.vue +19 -3
- package/src/components/compound/DlSearches/DlSmartSearch/components/SuggestionsDropdown.vue +8 -1
- package/src/demos/SmartSearchDemo/DlSmartSearchDemo.vue +1 -0
- package/src/hooks/use-suggestions.ts +31 -13
package/package.json
CHANGED
|
@@ -281,6 +281,11 @@ export default defineComponent({
|
|
|
281
281
|
|
|
282
282
|
showSuggestions.value = false
|
|
283
283
|
|
|
284
|
+
// to handle typing . after accepting a suggestion
|
|
285
|
+
if (/\s+\.$/.test(value)) {
|
|
286
|
+
value = value.replace(/\s+\.$/, '.')
|
|
287
|
+
}
|
|
288
|
+
|
|
284
289
|
// to handle date suggestion modal to open automatically.
|
|
285
290
|
if (value.includes('(dd/mm/yyyy)')) {
|
|
286
291
|
value = value.trimEnd()
|
|
@@ -316,6 +321,7 @@ export default defineComponent({
|
|
|
316
321
|
}
|
|
317
322
|
|
|
318
323
|
updateEditor(input.value, editorStyle.value)
|
|
324
|
+
setSelectionOffset(input.value, caretAt.value, caretAt.value)
|
|
319
325
|
setMenuOffset(isEligibleToChange(input.value, expanded.value))
|
|
320
326
|
|
|
321
327
|
if (!expanded.value) {
|
|
@@ -346,7 +352,8 @@ export default defineComponent({
|
|
|
346
352
|
}
|
|
347
353
|
}
|
|
348
354
|
|
|
349
|
-
const setInputFromSuggestion = (
|
|
355
|
+
const setInputFromSuggestion = (suggestion: any) => {
|
|
356
|
+
const value = '' + suggestion
|
|
350
357
|
let stringValue = ''
|
|
351
358
|
let caretPosition = 0
|
|
352
359
|
if (searchQuery.value.length) {
|
|
@@ -364,7 +371,12 @@ export default defineComponent({
|
|
|
364
371
|
queryRightSide = leftover + queryRightSide
|
|
365
372
|
} else if (value.startsWith('.')) {
|
|
366
373
|
// dot notation case
|
|
367
|
-
|
|
374
|
+
const words = queryLeftSide.trimEnd().split('.')
|
|
375
|
+
const lastWord = words.pop()
|
|
376
|
+
if (!value.startsWith('.' + lastWord)) {
|
|
377
|
+
words.push(lastWord)
|
|
378
|
+
}
|
|
379
|
+
queryLeftSide = words.join('.')
|
|
368
380
|
} else if (queryLeftSide.endsWith(' ')) {
|
|
369
381
|
// caret after space: only replace multiple spaces on the left
|
|
370
382
|
queryLeftSide = queryLeftSide.trimEnd() + ' '
|
|
@@ -546,7 +558,11 @@ export default defineComponent({
|
|
|
546
558
|
|
|
547
559
|
const onInput = (e: Event) => {
|
|
548
560
|
const text = (e.target as HTMLElement).textContent
|
|
549
|
-
|
|
561
|
+
if (text.endsWith('.')) {
|
|
562
|
+
setInputValue(text)
|
|
563
|
+
} else {
|
|
564
|
+
debouncedSetInputValue(text)
|
|
565
|
+
}
|
|
550
566
|
}
|
|
551
567
|
|
|
552
568
|
const onDateSelection = (value: DateInterval) => {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
:highlighted="suggestionIndex === highlightedIndex"
|
|
29
29
|
@click="handleOption(item)"
|
|
30
30
|
>
|
|
31
|
-
{{ item }}
|
|
31
|
+
{{ removeQuotes(item) }}
|
|
32
32
|
</dl-list-item>
|
|
33
33
|
</dl-list>
|
|
34
34
|
</dl-menu>
|
|
@@ -115,11 +115,18 @@ export default defineComponent({
|
|
|
115
115
|
emit('update:model-value', false)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
const removeQuotes = (item: any) => {
|
|
119
|
+
const str = '' + item
|
|
120
|
+
const match = str.match(/^'(.*)'$/)
|
|
121
|
+
return match ? match[1] : str
|
|
122
|
+
}
|
|
123
|
+
|
|
118
124
|
return {
|
|
119
125
|
defaultTarget,
|
|
120
126
|
setHighlightedIndex,
|
|
121
127
|
handleSelectedItem,
|
|
122
128
|
highlightedIndex,
|
|
129
|
+
removeQuotes,
|
|
123
130
|
onShow,
|
|
124
131
|
onHide,
|
|
125
132
|
emitModelValue,
|
|
@@ -178,7 +178,7 @@ export const useSuggestions = (
|
|
|
178
178
|
|
|
179
179
|
if (!field) continue
|
|
180
180
|
|
|
181
|
-
const fieldSeparated:
|
|
181
|
+
const fieldSeparated: string[] = field.split('.')
|
|
182
182
|
|
|
183
183
|
if (fieldSeparated.length > 1) {
|
|
184
184
|
localSuggestions = []
|
|
@@ -229,21 +229,35 @@ export const useSuggestions = (
|
|
|
229
229
|
localSuggestions = getOperators(ops)
|
|
230
230
|
|
|
231
231
|
if (!operator) {
|
|
232
|
-
const dotSeparated = matchedField.split('.')
|
|
232
|
+
const dotSeparated = matchedField.split('.')
|
|
233
|
+
const lastWord = dotSeparated.pop()
|
|
233
234
|
let fieldOf = schemaValue
|
|
234
235
|
for (const key of dotSeparated) {
|
|
235
236
|
fieldOf = fieldOf[key] as Schema
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
const toAdd: string[] = []
|
|
240
|
+
|
|
241
|
+
if (fieldOf[lastWord]) {
|
|
242
|
+
fieldOf = fieldOf[lastWord] as Schema
|
|
243
|
+
|
|
244
|
+
if (isObject(fieldOf) && !Array.isArray(fieldOf)) {
|
|
245
|
+
for (const key of Object.keys(fieldOf)) {
|
|
246
|
+
if (key === '*') continue
|
|
247
|
+
toAdd.push(`.${key}`)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
for (const key in fieldOf) {
|
|
241
252
|
if (key === '*') continue
|
|
242
|
-
|
|
253
|
+
if (key.startsWith(lastWord)) {
|
|
254
|
+
toAdd.push(`.${key}`)
|
|
255
|
+
}
|
|
243
256
|
}
|
|
244
|
-
localSuggestions = localSuggestions.concat(toConcat)
|
|
245
257
|
}
|
|
246
258
|
|
|
259
|
+
localSuggestions = toAdd.concat(localSuggestions)
|
|
260
|
+
|
|
247
261
|
continue
|
|
248
262
|
}
|
|
249
263
|
|
|
@@ -260,11 +274,15 @@ export const useSuggestions = (
|
|
|
260
274
|
}
|
|
261
275
|
|
|
262
276
|
if (Array.isArray(dataType)) {
|
|
263
|
-
localSuggestions = dataType
|
|
264
|
-
(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
localSuggestions = dataType
|
|
278
|
+
.filter(
|
|
279
|
+
(type) =>
|
|
280
|
+
!knownDataTypes.includes(type as string) &&
|
|
281
|
+
typeof type !== 'object'
|
|
282
|
+
)
|
|
283
|
+
.map((type) =>
|
|
284
|
+
typeof type === 'string' ? `'${type}'` : type
|
|
285
|
+
) as string[]
|
|
268
286
|
|
|
269
287
|
if (!value) continue
|
|
270
288
|
|
|
@@ -704,7 +722,7 @@ const getValueSuggestions = (
|
|
|
704
722
|
!knownDataTypes.includes(type as string) &&
|
|
705
723
|
typeof type !== 'object'
|
|
706
724
|
) {
|
|
707
|
-
suggestion.push(type)
|
|
725
|
+
suggestion.push(typeof type === 'string' ? `'${type}'` : type)
|
|
708
726
|
}
|
|
709
727
|
}
|
|
710
728
|
}
|