@dataloop-ai/components 0.19.11 → 0.19.13
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
|
@@ -237,8 +237,8 @@ export default defineComponent({
|
|
|
237
237
|
// todo: these can be stale data. we need to update them on schema change.
|
|
238
238
|
const { hasEllipsis } = useSizeObserver(input)
|
|
239
239
|
const { suggestions, error, findSuggestions } = useSuggestions(
|
|
240
|
-
schema
|
|
241
|
-
aliases
|
|
240
|
+
schema,
|
|
241
|
+
aliases,
|
|
242
242
|
{ strict }
|
|
243
243
|
)
|
|
244
244
|
//#endregion
|
|
@@ -465,6 +465,9 @@ export default defineComponent({
|
|
|
465
465
|
if (!focused.value) {
|
|
466
466
|
focus()
|
|
467
467
|
}
|
|
468
|
+
nextTick(() => {
|
|
469
|
+
findSuggestions('')
|
|
470
|
+
})
|
|
468
471
|
}
|
|
469
472
|
|
|
470
473
|
const endsWithOperator = computed(() => {
|
|
@@ -117,20 +117,20 @@ const mergeWords = (words: string[]) => {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
export const useSuggestions = (
|
|
120
|
-
schema: Schema
|
|
121
|
-
aliases: Alias[]
|
|
120
|
+
schema: Ref<Schema>,
|
|
121
|
+
aliases: Ref<Alias[]>,
|
|
122
122
|
options: { strict?: Ref<boolean> } = {}
|
|
123
123
|
) => {
|
|
124
124
|
const { strict } = options
|
|
125
125
|
const initialSuggestions = Object.keys(schema)
|
|
126
|
-
const aliasedKeys = aliases.map((alias) => alias.key)
|
|
126
|
+
const aliasedKeys = aliases.value.map((alias) => alias.key)
|
|
127
127
|
const aliasedSuggestions = initialSuggestions.map((suggestion) =>
|
|
128
128
|
aliasedKeys.includes(suggestion)
|
|
129
|
-
? aliases.find((alias) => alias.key === suggestion)?.alias
|
|
129
|
+
? aliases.value.find((alias) => alias.key === suggestion)?.alias
|
|
130
130
|
: suggestion
|
|
131
131
|
)
|
|
132
132
|
|
|
133
|
-
for (const alias of aliases) {
|
|
133
|
+
for (const alias of aliases.value) {
|
|
134
134
|
if (aliasedSuggestions.includes(alias.alias)) {
|
|
135
135
|
continue
|
|
136
136
|
}
|
|
@@ -185,7 +185,11 @@ export const useSuggestions = (
|
|
|
185
185
|
continue
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
const dataType = getDataType(
|
|
188
|
+
const dataType = getDataType(
|
|
189
|
+
schema.value,
|
|
190
|
+
aliases.value,
|
|
191
|
+
matchedField
|
|
192
|
+
)
|
|
189
193
|
if (!dataType) {
|
|
190
194
|
localSuggestions = []
|
|
191
195
|
continue
|
|
@@ -207,7 +211,7 @@ export const useSuggestions = (
|
|
|
207
211
|
|
|
208
212
|
if (!operator) {
|
|
209
213
|
const dotSeparated = matchedField.split('.').filter((el) => el)
|
|
210
|
-
let fieldOf = schema
|
|
214
|
+
let fieldOf = schema.value
|
|
211
215
|
for (const key of dotSeparated) {
|
|
212
216
|
fieldOf = fieldOf[key] as Schema
|
|
213
217
|
}
|
|
@@ -276,7 +280,7 @@ export const useSuggestions = (
|
|
|
276
280
|
}
|
|
277
281
|
|
|
278
282
|
error.value = input.length
|
|
279
|
-
? getError(schema, aliases, expressions, { strict })
|
|
283
|
+
? getError(schema.value, aliases.value, expressions, { strict })
|
|
280
284
|
: null
|
|
281
285
|
|
|
282
286
|
suggestions.value = localSuggestions
|
|
@@ -337,7 +341,8 @@ const getError = (
|
|
|
337
341
|
.filter(({ field, value }) => field !== null && value !== null)
|
|
338
342
|
.reduce<string | null>((acc, { field, value, operator }, _, arr) => {
|
|
339
343
|
if (acc === 'warning') return acc
|
|
340
|
-
const
|
|
344
|
+
const fieldKey: string =
|
|
345
|
+
getAliasObjByAlias(aliases, field)?.key ?? field
|
|
341
346
|
|
|
342
347
|
/**
|
|
343
348
|
* Handle nested keys to validate if the key exists in the schema or not.
|
|
@@ -352,14 +357,31 @@ const getError = (
|
|
|
352
357
|
}
|
|
353
358
|
}
|
|
354
359
|
|
|
355
|
-
|
|
356
|
-
|
|
360
|
+
function hasValidExpression(
|
|
361
|
+
arr: string[],
|
|
362
|
+
pattern: RegExp
|
|
363
|
+
): boolean {
|
|
364
|
+
for (const item of arr) {
|
|
365
|
+
if (pattern.test(item)) {
|
|
366
|
+
return true
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return false
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const pattern = new RegExp(`${fieldKey}\\.\\d`)
|
|
373
|
+
const isValid = isInputAllowed(fieldKey, keys)
|
|
374
|
+
if (
|
|
375
|
+
!keys.includes(fieldKey) &&
|
|
376
|
+
!hasValidExpression(keys, pattern) &&
|
|
377
|
+
!isValid
|
|
378
|
+
) {
|
|
357
379
|
return strict.value ? errors.INVALID_EXPRESSION : 'warning'
|
|
358
380
|
}
|
|
359
381
|
|
|
360
382
|
const valid = isValidByDataType(
|
|
361
383
|
validateBracketValues(value),
|
|
362
|
-
getDataType(schema, aliases,
|
|
384
|
+
getDataType(schema, aliases, fieldKey),
|
|
363
385
|
operator
|
|
364
386
|
)
|
|
365
387
|
|