@bagelink/vue 1.22.1 → 1.22.5

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.
Files changed (43) hide show
  1. package/dist/{StructuredEditor-BiBhDIf8.js → StructuredEditor-1mcyEtzh.js} +143 -143
  2. package/dist/{StructuredEditor-Cdl9_djZ.cjs → StructuredEditor-yW9FO5Tn.cjs} +1 -1
  3. package/dist/components/FilterQuery.vue.d.ts +5 -0
  4. package/dist/components/FilterQuery.vue.d.ts.map +1 -1
  5. package/dist/components/FilterQueryBuilder.vue.d.ts +47 -0
  6. package/dist/components/FilterQueryBuilder.vue.d.ts.map +1 -0
  7. package/dist/components/Icon/baseline.d.ts +14 -0
  8. package/dist/components/Icon/baseline.d.ts.map +1 -0
  9. package/dist/components/index.d.ts +1 -0
  10. package/dist/components/index.d.ts.map +1 -1
  11. package/dist/components/layout/AppLayout.vue.d.ts.map +1 -1
  12. package/dist/composables/index.d.ts +1 -0
  13. package/dist/composables/index.d.ts.map +1 -1
  14. package/dist/composables/useKeyboardInset.d.ts +5 -0
  15. package/dist/composables/useKeyboardInset.d.ts.map +1 -0
  16. package/dist/core.css +1 -1
  17. package/dist/dialog/Dialog.vue.d.ts.map +1 -1
  18. package/dist/i18n/index.d.ts +2 -0
  19. package/dist/i18n/index.d.ts.map +1 -1
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.mjs +312 -310
  24. package/dist/src-BHNIZfpF.cjs +764 -0
  25. package/dist/{src-lXTK29UB.js → src-CtOtibj7.js} +13464 -13199
  26. package/dist/src.css +1 -1
  27. package/dist/style.css +1 -1
  28. package/dist/utils/useKeyboardInset.d.ts +7 -0
  29. package/dist/utils/useKeyboardInset.d.ts.map +1 -0
  30. package/package.json +3 -3
  31. package/src/components/FilterQuery.vue +139 -750
  32. package/src/components/FilterQueryBuilder.vue +797 -0
  33. package/src/components/Icon/baseline.ts +80 -0
  34. package/src/components/index.ts +1 -0
  35. package/src/components/layout/AppLayout.vue +3 -1
  36. package/src/composables/index.ts +1 -0
  37. package/src/composables/useKeyboardInset.ts +89 -0
  38. package/src/dialog/Dialog.vue +15 -6
  39. package/src/i18n/locales/en.json +2 -1
  40. package/src/i18n/locales/he.json +2 -1
  41. package/src/index.ts +1 -0
  42. package/src/utils/useKeyboardInset.ts +36 -0
  43. package/dist/src-CyUKZxJV.cjs +0 -764
@@ -5,18 +5,14 @@ export type { FilterField, QueryOption, OptionsSource }
5
5
  </script>
6
6
 
7
7
  <script setup lang="ts" generic="T extends Record<string, any>">
8
- import type { ComparisonOperator, LogicalOperator, QueryConditions } from '../utils/queryFilter'
9
- import { parseQuery } from '../utils/queryFilter'
10
- import { Btn, Card, DateInput, Dropdown, Icon, SelectInput, TextInput, useI18n, useDebounceFn } from '../index'
11
- import { computed, getCurrentInstance, ref } from 'vue'
12
-
13
- interface UICondition {
14
- id: string
15
- field: string
16
- operator: ComparisonOperator
17
- value: string | number | boolean | null | Array<string | number | boolean | null>
18
- connector: LogicalOperator | ''
19
- }
8
+ /**
9
+ * FilterQuery — compact on mobile (chip + bottom sheet), dropdown/inline on desktop.
10
+ * Builder logic lives in FilterQueryBuilder.
11
+ */
12
+ import type { QueryConditions } from '../utils/queryFilter'
13
+ import { Btn, Card, Dialog, Dropdown, useDevice, useI18n } from '../index'
14
+ import { computed, getCurrentInstance, ref, watch } from 'vue'
15
+ import FilterQueryBuilder from './FilterQueryBuilder.vue'
20
16
 
21
17
  const props = withDefaults(defineProps<{
22
18
  fields: FilterField[]
@@ -25,10 +21,16 @@ const props = withDefaults(defineProps<{
25
21
  inline?: boolean
26
22
  /** Keep the desktop row layout and controls on mobile screens. */
27
23
  desktopLayoutOnMobile?: boolean
24
+ /**
25
+ * On mobile, show a compact trigger + bottom sheet instead of the full
26
+ * inline builder / dropdown panel. Default true.
27
+ */
28
+ compactOnMobile?: boolean
28
29
  }>(), {
29
30
  placement: 'bottom-end',
30
31
  inline: false,
31
32
  desktopLayoutOnMobile: false,
33
+ compactOnMobile: true,
32
34
  })
33
35
 
34
36
  const emit = defineEmits<{
@@ -38,763 +40,150 @@ const emit = defineEmits<{
38
40
 
39
41
  const model = defineModel<QueryConditions<T>>({ default: () => [] })
40
42
 
41
- // Internal working copy — may contain incomplete conditions for UI purposes.
42
- // On init, detect any queryOption presets from the incoming model.
43
- const internalModel = ref<QueryConditions<T>>(collapseToPresets([...model.value] as QueryConditions<T>))
44
-
43
+ const { isMobile } = useDevice()
45
44
  const { $t } = useI18n()
46
45
  const instance = getCurrentInstance()
47
46
  const hasSaveListener = computed(() => !!instance?.vnode.props?.onSave)
48
- const filterLabel = computed(() =>
49
- activeFiltersCount.value > 0
50
- ? `${currentTexts.value.filter} (${activeFiltersCount.value})`
51
- : currentTexts.value.filter,
52
- )
53
- const dropdownProps = computed(() => props.inline
54
- ? {}
55
- : {
56
- flat: true,
57
- placement: props.placement,
58
- icon: 'filter_alt',
59
- value: filterLabel.value,
60
- sm: true,
61
- })
62
47
 
63
- function isComplete(c: { field: string, op: ComparisonOperator, value?: any }) {
64
- if (!c.field || !c.op) return false
65
- // queryOption presets are complete if they have a selected value
66
- if (isQueryOptionField(c.field as string)) return c.value !== '' && c.value != null
67
- if (c.op === 'pr' || c.op === 'is_null') return true
68
- if (c.op === 'in' || c.op === 'nin' || c.op === 'sw_any') return Array.isArray(c.value) && c.value.length > 0
69
- if (c.op === 'between') {
70
- return Array.isArray(c.value) && c.value.length === 2
71
- && c.value[0] !== '' && c.value[0] != null
72
- && c.value[1] !== '' && c.value[1] != null
73
- }
74
- return c.value !== '' && c.value !== null && c.value !== undefined
75
- }
48
+ const useMobileSheet = computed(() =>
49
+ isMobile.value && props.compactOnMobile && !props.desktopLayoutOnMobile,
50
+ )
51
+ const sheetOpen = ref(false)
76
52
 
77
- const debouncedFlush = useDebounceFn(() => {
78
- const complete = internalModel.value.filter(isComplete) as QueryConditions<T>
79
- const expanded = expandQueryOptions(complete)
80
- model.value = expanded
81
- emit('change', expanded)
82
- }, 400)
53
+ const builderRef = ref<{ clearAll: () => void } | null>(null)
83
54
 
84
- let conditionIdCounter = 0
85
- function generateId() {
86
- return `cond_${++conditionIdCounter}_${Date.now()}`
87
- }
55
+ /** Complete filters only (builder flushes incompletes out of the model). */
56
+ const activeFiltersCount = computed(() =>
57
+ Array.isArray(model.value) ? model.value.length : 0,
58
+ )
59
+ const filterLabel = computed(() =>
60
+ activeFiltersCount.value > 0
61
+ ? `${$t('filter.filter')} (${activeFiltersCount.value})`
62
+ : $t('filter.filter'),
63
+ )
88
64
 
89
- // Computed texts using i18n
90
- const currentTexts = computed(() => ({
91
- filter: $t('filter.filter'),
92
- noActiveFilters: $t('filter.noActiveFilters'),
93
- connectors: {
94
- and: $t('filter.connectors.and'),
95
- or: $t('filter.connectors.or'),
96
- },
97
- operators: {
98
- eq: $t('filter.operators.eq'),
99
- ne: $t('filter.operators.ne'),
100
- gt: $t('filter.operators.gt'),
101
- ge: $t('filter.operators.ge'),
102
- lt: $t('filter.operators.lt'),
103
- le: $t('filter.operators.le'),
104
- co: $t('filter.operators.co'),
105
- sw: $t('filter.operators.sw'),
106
- sw_any: $t('filter.operators.swAny'),
107
- ew: $t('filter.operators.ew'),
108
- pr: $t('filter.operators.pr'),
109
- is_null: $t('filter.operators.isNull'),
110
- in: $t('filter.operators.in'),
111
- nin: $t('filter.operators.nin'),
112
- between: $t('filter.operators.between'),
113
- },
114
- placeholders: {
115
- selectField: $t('filter.placeholders.selectField'),
116
- selectOption: $t('filter.placeholders.selectOption'),
117
- selectDate: $t('filter.placeholders.selectDate'),
118
- enterValue: $t('filter.placeholders.enterValue'),
119
- from: $t('filter.placeholders.from'),
120
- to: $t('filter.placeholders.to'),
121
- commaSeparated: $t('filter.placeholders.commaSeparated'),
122
- },
123
- buttons: {
124
- addCondition: $t('filter.buttons.addCondition'),
125
- clearAll: $t('filter.buttons.clearAll'),
126
- },
127
- boolean: {
128
- true: $t('select.yes'),
129
- false: $t('select.no'),
130
- },
65
+ const dropdownProps = computed(() => ({
66
+ flat: true,
67
+ placement: props.placement,
68
+ icon: 'filter_alt' as const,
69
+ value: filterLabel.value,
70
+ sm: true,
131
71
  }))
132
72
 
133
- // Map model conditions to UI conditions with stable IDs
134
- const conditionIds = new Map<number, string>()
135
-
136
- const conditions = computed(() => {
137
- const arr = internalModel.value || []
138
- return arr.map((cond, index) => {
139
- // Get or create stable ID for this index
140
- if (!conditionIds.has(index)) {
141
- conditionIds.set(index, generateId())
142
- }
143
- const id = conditionIds.get(index)!
144
-
145
- const uiCond: UICondition = {
146
- id,
147
- field: cond.field as string,
148
- operator: cond.op,
149
- value: Array.isArray(cond.value)
150
- ? [...cond.value]
151
- : (cond.value === undefined ? '' : cond.value),
152
- connector: index > 0 ? (cond.connector || 'and') : '',
153
- }
154
- return uiCond
155
- })
73
+ watch(useMobileSheet, (sheet) => {
74
+ if (!sheet) sheetOpen.value = false
156
75
  })
157
76
 
158
- const allOperatorOptions = computed(() => [
159
- { label: currentTexts.value.operators.eq, value: 'eq' as ComparisonOperator },
160
- { label: currentTexts.value.operators.ne, value: 'ne' as ComparisonOperator },
161
- { label: currentTexts.value.operators.gt, value: 'gt' as ComparisonOperator },
162
- { label: currentTexts.value.operators.ge, value: 'ge' as ComparisonOperator },
163
- { label: currentTexts.value.operators.lt, value: 'lt' as ComparisonOperator },
164
- { label: currentTexts.value.operators.le, value: 'le' as ComparisonOperator },
165
- { label: currentTexts.value.operators.co, value: 'co' as ComparisonOperator },
166
- { label: currentTexts.value.operators.sw, value: 'sw' as ComparisonOperator },
167
- { label: currentTexts.value.operators.sw_any, value: 'sw_any' as ComparisonOperator },
168
- { label: currentTexts.value.operators.ew, value: 'ew' as ComparisonOperator },
169
- { label: currentTexts.value.operators.pr, value: 'pr' as ComparisonOperator },
170
- { label: currentTexts.value.operators.is_null, value: 'is_null' as ComparisonOperator },
171
- { label: currentTexts.value.operators.in, value: 'in' as ComparisonOperator },
172
- { label: currentTexts.value.operators.nin, value: 'nin' as ComparisonOperator },
173
- { label: currentTexts.value.operators.between, value: 'between' as ComparisonOperator },
174
- ])
175
-
176
- function getOperatorsForType(fieldType: string, hasOptions: boolean, isMultiple: boolean, fieldValue: string) {
177
- const allow = (ops: string[]) => allOperatorOptions.value.filter(o => ops.includes(o.value))
178
- const withAdditional = (ops: string[]) => [
179
- ...ops,
180
- ...(getFieldDef(fieldValue)?.additionalOperators ?? []),
181
- ]
182
- if (isMultiple && hasOptions) {
183
- return allow(withAdditional(['in', 'nin', 'pr', 'is_null']))
184
- }
185
- if (hasOptions) {
186
- return allow(withAdditional(['eq', 'ne', 'in', 'nin', 'pr', 'is_null']))
187
- }
188
- switch (fieldType) {
189
- case 'boolean':
190
- return allow(withAdditional(['eq', 'ne', 'pr', 'is_null']))
191
- case 'number':
192
- case 'date':
193
- return allow(withAdditional(['eq', 'ne', 'gt', 'ge', 'lt', 'le', 'between', 'in', 'nin', 'pr', 'is_null']))
194
- default:
195
- return allow(withAdditional(['eq', 'ne', 'co', 'sw', 'ew', 'in', 'nin', 'pr', 'is_null']))
196
- }
197
- }
198
-
199
- function getFieldDef(fieldValue: string) {
200
- return props.fields.find(f => f.value === fieldValue)
77
+ function onChange(value: QueryConditions<T>) {
78
+ emit('change', value)
201
79
  }
202
80
 
203
- function getFieldOptions(fieldValue: string): OptionsSource | undefined {
204
- return getFieldDef(fieldValue)?.options
81
+ function onSave(value: QueryConditions<T>) {
82
+ emit('save', value)
205
83
  }
206
84
 
207
- function isQueryOptionField(fieldValue: string): boolean {
208
- const def = getFieldDef(fieldValue)
209
- return !!(def?.queryOptions && def.queryOptions.length > 0)
85
+ function closeSheet() {
86
+ sheetOpen.value = false
210
87
  }
211
88
 
212
- function isMultipleField(fieldValue: string): boolean {
213
- const def = getFieldDef(fieldValue)
214
- return !!(def?.multiple && def?.options)
215
- }
216
-
217
- /** On flush: replace queryOption markers with parsed conditions from the raw SCIM string */
218
- function expandQueryOptions(conditions: QueryConditions<T>): QueryConditions<T> {
219
- const result: QueryConditions<T> = []
220
- for (const c of conditions) {
221
- const def = getFieldDef(c.field as string)
222
- const opt = def?.queryOptions?.find(o => o.value === c.value)
223
- if (opt) {
224
- const parsed = parseQuery(opt.query) as QueryConditions<T>
225
- if (parsed.length) {
226
- // Preserve the original connector on the first parsed condition
227
- parsed[0] = { ...parsed[0], connector: c.connector }
228
- result.push(...parsed)
229
- }
230
- } else {
231
- result.push(c)
232
- }
233
- }
234
- return result
235
- }
236
-
237
- /** On init: detect consecutive conditions that match a queryOption's SCIM string and collapse to a single marker */
238
- function collapseToPresets(conditions: QueryConditions<T>): QueryConditions<T> {
239
- const queryOptionFields = props.fields.filter(f => f.queryOptions?.length)
240
- if (!queryOptionFields.length) return conditions
241
-
242
- const result: QueryConditions<T> = []
243
- let i = 0
244
- while (i < conditions.length) {
245
- let matched = false
246
- for (const fieldDef of queryOptionFields) {
247
- for (const opt of fieldDef.queryOptions!) {
248
- const parsed = parseQuery(opt.query)
249
- const qLen = parsed.length
250
- if (!qLen || i + qLen > conditions.length) continue
251
- const slice = conditions.slice(i, i + qLen)
252
- const matches = slice.every((c, idx) => {
253
- const expected = parsed[idx]
254
- return c.field === expected.field
255
- && c.op === expected.op
256
- && c.value === expected.value
257
- && (idx === 0 || c.connector === expected.connector)
258
- })
259
- if (matches) {
260
- result.push({
261
- field: fieldDef.value,
262
- op: 'eq',
263
- value: opt.value,
264
- connector: slice[0].connector,
265
- } as any)
266
- i += qLen
267
- matched = true
268
- break
269
- }
270
- }
271
- if (matched) break
272
- }
273
- if (!matched) {
274
- result.push(conditions[i])
275
- i++
276
- }
277
- }
278
- return result
279
- }
280
-
281
- const booleanOptions = computed(() => [
282
- { label: currentTexts.value.boolean.true, value: true },
283
- { label: currentTexts.value.boolean.false, value: false },
284
- ])
285
-
286
- function parseValue(value: string | number | boolean | null, fieldType: string): string | number | boolean | null {
287
- if (typeof value === 'number' || typeof value === 'boolean' || value === null) return value
288
- if (fieldType === 'boolean') {
289
- if (value === 'true') return true
290
- if (value === 'false') return false
291
- }
292
- if (fieldType === 'number' && !Number.isNaN(Number(value)) && value.trim() !== '') return Number(value)
293
- return value
294
- }
295
-
296
- function updateConditionAtIndex(index: number, updates: Partial<{ field: string, op: ComparisonOperator, value: UICondition['value'], connector: LogicalOperator }>) {
297
- const newModel = [...internalModel.value]
298
- const existing = newModel[index]
299
- if (!existing) return
300
-
301
- const updated = { ...existing }
302
- if (updates.field !== undefined) updated.field = updates.field
303
- if (updates.op !== undefined) updated.op = updates.op
304
- if (updates.value !== undefined) {
305
- const fieldType = getFieldType(updated.field as string)
306
- updated.value = Array.isArray(updates.value)
307
- // Coerce each list/range element (e.g. "18" → 18) so numeric filters
308
- // emit bare numbers in the bracket literal.
309
- ? updates.value.map(v => parseValue(v, fieldType))
310
- : parseValue(updates.value, fieldType)
311
- }
312
- if (updates.connector !== undefined) updated.connector = updates.connector
313
-
314
- newModel[index] = updated
315
- internalModel.value = newModel as QueryConditions<T>
316
- debouncedFlush()
317
- }
318
-
319
- function addCondition() {
320
- const field = props.fields[0]?.value || 'field'
321
- const multi = isMultipleField(field)
322
- const newCondition = {
323
- field,
324
- op: (multi ? 'in' : 'eq') as ComparisonOperator,
325
- value: (multi ? [] : '') as any,
326
- connector: model.value.length > 0 ? 'and' as LogicalOperator : undefined,
327
- }
328
- const newModel = [...internalModel.value, newCondition]
329
- internalModel.value = newModel as QueryConditions<T>
330
- console.log('[Filter] addCondition - skipping flush (incomplete)')
331
- }
332
-
333
- function removeCondition(index: number) {
334
- const newModel = [...internalModel.value]
335
- newModel.splice(index, 1)
336
- if (newModel.length > 0 && newModel[0].connector) {
337
- newModel[0] = { ...newModel[0], connector: undefined }
338
- }
339
- conditionIds.delete(index)
340
- internalModel.value = newModel as QueryConditions<T>
341
- debouncedFlush()
342
- }
343
-
344
- function clearAll() {
345
- conditionIds.clear()
346
- internalModel.value = [] as unknown as QueryConditions<T>
347
- model.value = [] as unknown as QueryConditions<T>
348
- console.log('[Filter] clearAll')
349
- emit('change', [] as unknown as QueryConditions<T>)
350
- }
351
-
352
- function getFieldType(fieldValue: string): string {
353
- return props.fields.find(f => f.value === fieldValue)?.type || 'string'
354
- }
355
-
356
- function needsValue(operator: ComparisonOperator): boolean {
357
- return operator !== 'pr' && operator !== 'is_null'
358
- }
359
-
360
- function isMultiOperator(operator: ComparisonOperator): boolean {
361
- return operator === 'in' || operator === 'nin' || operator === 'sw_any'
362
- }
363
-
364
- function isBetweenOperator(operator: ComparisonOperator): boolean {
365
- return operator === 'between'
366
- }
367
-
368
- /** in/nin on a field WITHOUT predefined options → comma-separated free text. */
369
- function isFreeListOperator(condition: UICondition): boolean {
370
- return isMultiOperator(condition.operator) && !getFieldOptions(condition.field)
371
- }
372
-
373
- /** Convert an array value to comma-separated text for the free-list input. */
374
- function listToText(value: UICondition['value']): string {
375
- return Array.isArray(value) ? value.join(', ') : String(value ?? '')
376
- }
377
-
378
- function selectModelValue(value: UICondition['value']): any {
379
- return value ?? undefined
380
- }
381
-
382
- function selectMultiModelValue(value: UICondition['value']): any[] {
383
- return Array.isArray(value) ? value.filter(item => item != null) : []
384
- }
385
-
386
- /** Split comma-separated free-list text into a trimmed string[]. */
387
- function textToList(text: string): string[] {
388
- return text.split(',').map(s => s.trim()).filter(s => s !== '')
389
- }
390
-
391
- /** Read one bound of a `between` value ([lo, hi]); index 0 = lo, 1 = hi. */
392
- function betweenBound(condition: UICondition, index: 0 | 1): string {
393
- return Array.isArray(condition.value) ? String(condition.value[index] ?? '') : ''
394
- }
395
-
396
- /** Update one bound of a `between` value, preserving the other. */
397
- function onBetweenBoundChange(id: string, index: 0 | 1, v: string) {
398
- const cond = conditions.value.find(c => c.id === id)
399
- const current = cond && Array.isArray(cond.value) ? [...cond.value] : ['', '']
400
- current[index] = v
401
- onValueChange(id, [current[0] ?? '', current[1] ?? ''])
402
- }
403
-
404
- const activeFiltersCount = computed(() => {
405
- return conditions.value.filter(c => isComplete({ field: c.field, op: c.operator, value: c.value })).length
406
- })
407
-
408
- function getConditionIndex(id: string): number {
409
- return conditions.value.findIndex((c: UICondition) => c.id === id)
410
- }
411
-
412
- function onFieldChange(id: string, newField: string) {
413
- const index = getConditionIndex(id)
414
- if (index < 0) return
415
- const fieldDef = getFieldDef(newField)
416
- if (fieldDef?.queryOptions?.length) {
417
- updateConditionAtIndex(index, { field: newField, op: 'eq', value: '' })
418
- return
419
- }
420
- const multi = !!(fieldDef?.multiple && fieldDef?.options)
421
- const validOps = getOperatorsForType(fieldDef?.type || 'string', !!fieldDef?.options, multi, newField)
422
- const defaultOp = (multi ? 'in' : validOps[0]?.value ?? 'eq') as ComparisonOperator
423
- updateConditionAtIndex(index, {
424
- field: newField,
425
- op: defaultOp,
426
- value: multi ? [] : '',
427
- })
428
- }
429
-
430
- function onOperatorChange(id: string, operator: ComparisonOperator) {
431
- const index = getConditionIndex(id)
432
- if (index < 0) return
433
- const current = conditions.value[index]
434
- const prevOp = current?.operator
435
- const updates: Parameters<typeof updateConditionAtIndex>[1] = { op: operator }
436
-
437
- // Reset the value shape when the operator's expected value type changes.
438
- const wasList = prevOp === 'in' || prevOp === 'nin' || prevOp === 'sw_any'
439
- const wasBetween = prevOp === 'between'
440
- const isList = operator === 'in' || operator === 'nin' || operator === 'sw_any'
441
- const isBetween = operator === 'between'
442
-
443
- if (isBetween && !wasBetween) updates.value = ['', '']
444
- else if (isList && !wasList) updates.value = []
445
- else if (!isList && !isBetween && (wasList || wasBetween)) updates.value = ''
446
-
447
- updateConditionAtIndex(index, updates)
448
- }
449
-
450
- function onValueChange(id: string, value: UICondition['value']) {
451
- const index = getConditionIndex(id)
452
- if (index >= 0) updateConditionAtIndex(index, { value })
453
- }
454
-
455
- function onQueryOptionChange(id: string, optionValue: string) {
456
- const index = getConditionIndex(id)
457
- if (index >= 0) updateConditionAtIndex(index, { value: optionValue })
458
- }
459
-
460
- function getQueryOptionValue(condition: UICondition): string {
461
- return Array.isArray(condition.value) ? '' : String(condition.value ?? '')
462
- }
463
-
464
- function onConnectorChange(id: string, connector: LogicalOperator) {
465
- const index = getConditionIndex(id)
466
- if (index >= 0) updateConditionAtIndex(index, { connector })
89
+ function saveAndClose() {
90
+ onSave((model.value || []) as QueryConditions<T>)
91
+ closeSheet()
467
92
  }
468
93
  </script>
469
94
 
470
95
  <template>
471
- <component
472
- :is="props.inline ? 'div' : Dropdown"
473
- v-bind="dropdownProps"
474
- class="filter-query-wrap"
475
- :class="{
476
- 'filter-query-inline': props.inline,
477
- 'filter-query-desktop-mobile': props.inline || props.desktopLayoutOnMobile,
478
- }"
479
- >
480
- <component :is="props.inline ? 'div' : Card" :class="{ 'p-05': !props.inline }">
481
- <div class="p-025 bg-bg radius-1 mb-05 m_max-h-300px m_overflow m_border">
482
- <!-- Empty state -->
483
- <div v-if="conditions.length === 0" class="opacity-3 flex gap-05 p-025 min-w-450px m_min-0">
484
- <Icon name="info" />
485
- <div class="">
486
- {{ currentTexts.noActiveFilters }}
487
- </div>
488
- </div>
489
- <TransitionGroup name="condition">
490
- <div
491
- v-for="(condition, index) in conditions" :key="condition.id"
492
- class="grid gap-025 align-items-center py-025" :class="{
493
- '': index > 0 && condition.connector === 'or',
494
- 'pt-075 border-top-or': index > 0 && condition.connector === 'or',
495
- 'first-filter-row': index === 0,
496
- 'filter-row': index > 0,
497
- }"
498
- >
499
- <!-- Connector (AND/OR) -->
500
- <div v-if="index > 0" class="w-fit">
501
- <SelectInput
502
- :model-value="condition.connector || 'and'" :options="[
503
- { label: currentTexts.connectors.and, value: 'and' },
504
- { label: currentTexts.connectors.or, value: 'or' },
505
- ]" class="m-0 and-or-select txt-12"
506
- @update:model-value="(v: LogicalOperator) => onConnectorChange(condition.id, v)"
507
- />
508
- </div>
509
-
510
- <!-- Field selector -->
511
- <SelectInput
512
- :model-value="condition.field" :options="fields"
513
- :placeholder="currentTexts.placeholders.selectField"
514
- class="m-0 light-input borderHover"
515
- :class="{ 'first-filter-field': index === 0 }"
516
- searchable
517
- @update:model-value="(v: string) => onFieldChange(condition.id, v)"
518
- />
519
-
520
- <!-- Query-option preset: single select spanning operator+value columns -->
521
- <template v-if="isQueryOptionField(condition.field)">
522
- <SelectInput
523
- :key="`${condition.id}-${condition.field}-qpreset`"
524
- :model-value="getQueryOptionValue(condition)"
525
- :options="getFieldDef(condition.field)!.queryOptions!"
526
- :placeholder="currentTexts.placeholders.selectOption"
527
- class="m-0 light-input borderHover" style="grid-column: span 2"
528
- @update:model-value="(v: string) => onQueryOptionChange(condition.id, v)"
529
- />
530
- </template>
531
-
532
- <!-- Standard: Operator + Value -->
533
- <template v-else>
534
- <!-- Operator selector -->
535
- <SelectInput
536
- :model-value="condition.operator"
537
- :options="getOperatorsForType(getFieldType(condition.field), !!getFieldOptions(condition.field), isMultipleField(condition.field), condition.field)"
538
- class="m-0 light-input borderHover"
539
- @update:model-value="(v: ComparisonOperator) => onOperatorChange(condition.id, v)"
540
- />
541
-
542
- <!-- Value input - type-specific -->
543
- <template v-if="needsValue(condition.operator)">
544
- <!-- between: two type-aware bound inputs (min / max) -->
545
- <div
546
- v-if="isBetweenOperator(condition.operator)"
547
- :key="`${condition.id}-${condition.field}-between`"
548
- class="flex gap-025 align-items-center between-inputs"
549
- >
550
- <DateInput
551
- v-if="getFieldType(condition.field) === 'date'"
552
- :model-value="betweenBound(condition, 0)"
553
- :placeholder="currentTexts.placeholders.from" class="m-0 light-input borderHover"
554
- @update:model-value="(v: any) => onBetweenBoundChange(condition.id, 0, String(v))"
555
- />
556
- <TextInput
557
- v-else
558
- :model-value="betweenBound(condition, 0)" placeholder="0"
559
- :type="getFieldType(condition.field) === 'number' ? 'number' : 'text'"
560
- class="m-0 light-input borderHover"
561
- @update:model-value="(v: string) => onBetweenBoundChange(condition.id, 0, v)"
562
- />
563
- <span class="opacity-4 txt-12">–</span>
564
- <DateInput
565
- v-if="getFieldType(condition.field) === 'date'"
566
- :model-value="betweenBound(condition, 1)"
567
- :placeholder="currentTexts.placeholders.to" class="m-0 light-input borderHover"
568
- @update:model-value="(v: any) => onBetweenBoundChange(condition.id, 1, String(v))"
569
- />
570
- <TextInput
571
- v-else
572
- :model-value="betweenBound(condition, 1)" placeholder="0"
573
- :type="getFieldType(condition.field) === 'number' ? 'number' : 'text'"
574
- class="m-0 light-input borderHover"
575
- @update:model-value="(v: string) => onBetweenBoundChange(condition.id, 1, v)"
576
- />
577
- </div>
578
- <!-- in/nin with predefined options: multiselect -->
579
- <SelectInput
580
- v-else-if="getFieldOptions(condition.field) && isMultiOperator(condition.operator)"
581
- :key="`${condition.id}-${condition.field}-multi`"
582
- :model-value="selectMultiModelValue(condition.value)"
583
- :options="getFieldOptions(condition.field)!"
584
- :placeholder="currentTexts.placeholders.selectOption"
585
- class="m-0 light-input borderHover" searchable multiselect
586
- @update:model-value="(v: string[]) => onValueChange(condition.id, v)"
587
- />
588
- <!-- in/nin without options: comma-separated free-text list -->
589
- <TextInput
590
- v-else-if="isFreeListOperator(condition)"
591
- :key="`${condition.id}-${condition.field}-freelist`"
592
- :model-value="listToText(condition.value)"
593
- :placeholder="currentTexts.placeholders.commaSeparated"
594
- class="m-0 light-input borderHover"
595
- @update:model-value="(v: string) => onValueChange(condition.id, textToList(v))"
596
- />
597
- <SelectInput
598
- v-else-if="getFieldOptions(condition.field)"
599
- :key="`${condition.id}-${condition.field}-single`"
600
- :model-value="selectModelValue(condition.value)"
601
- :options="getFieldOptions(condition.field)!"
602
- :placeholder="currentTexts.placeholders.selectOption"
603
- class="m-0 light-input borderHover" searchable
604
- @update:model-value="(v: string) => onValueChange(condition.id, v)"
605
- />
606
- <SelectInput
607
- v-else-if="getFieldType(condition.field) === 'boolean'"
608
- :key="`${condition.id}-${condition.field}-bool`"
609
- :model-value="selectModelValue(condition.value)" :options="booleanOptions"
610
- :placeholder="currentTexts.placeholders.selectOption"
611
- class="m-0 light-input borderHover"
612
- @update:model-value="(v: boolean) => onValueChange(condition.id, v)"
613
- />
614
- <DateInput
615
- v-else-if="getFieldType(condition.field) === 'date'"
616
- :key="`${condition.id}-${condition.field}-date`"
617
- :model-value="(condition.value as string)"
618
- :placeholder="currentTexts.placeholders.selectDate" class="m-0 light-input borderHover"
619
- @update:model-value="(v: any) => onValueChange(condition.id, String(v))"
620
- />
621
- <TextInput
622
- v-else-if="getFieldType(condition.field) === 'number'"
623
- :key="`${condition.id}-${condition.field}-number`"
624
- :model-value="(condition.value as string)" placeholder="0" type="number"
625
- class="m-0 light-input borderHover"
626
- @update:model-value="(v: string) => onValueChange(condition.id, v)"
627
- />
628
- <TextInput
629
- v-else :model-value="(condition.value as string)"
630
- :placeholder="currentTexts.placeholders.enterValue" class="m-0 light-input borderHover"
631
- @update:model-value="(v: string) => onValueChange(condition.id, v)"
632
- />
633
- </template>
634
- <div v-else />
635
- </template>
636
-
637
- <!-- Remove button -->
638
- <Btn
639
- icon="close" sm flat size="sm"
640
- :class="{ 'm_bg-gray-40 m_px-3 m_mx-auto': !props.inline && !props.desktopLayoutOnMobile }"
641
- @click="removeCondition(index)"
642
- />
643
- </div>
644
- </TransitionGroup>
645
- </div>
646
-
647
- <div class="flex gap-1 space-between m_flex-wrap">
648
- <Btn icon="add" flat sm :value="currentTexts.buttons.addCondition" @click="addCondition" />
649
- <div class="flex gap-05">
650
- <Btn
651
- v-if="conditions.length > 0" icon="delete_sweep" flat sm color="gray"
652
- :value="currentTexts.buttons.clearAll" @click="clearAll"
653
- />
654
- <Btn
655
- v-if="hasSaveListener" :disabled="conditions.length === 0" class="color-green" icon="save" sm
656
- color="green-light" :value="$t('filter.buttons.save')"
657
- @click="emit('save', internalModel.filter(isComplete))"
658
- />
659
- </div>
660
- </div>
661
- </component>
662
- </component>
96
+ <!-- Mobile: compact chip + bottom sheet -->
97
+ <template v-if="useMobileSheet">
98
+ <Btn
99
+ flat
100
+ sm
101
+ icon="filter_alt"
102
+ :value="filterLabel"
103
+ class="filter-query-wrap"
104
+ :class="{ 'color-primary': activeFiltersCount > 0 }"
105
+ @click="sheetOpen = true"
106
+ />
107
+ <Dialog
108
+ :open="sheetOpen"
109
+ position="bottom"
110
+ width="l"
111
+ :title="filterLabel"
112
+ @update:open="sheetOpen = $event"
113
+ >
114
+ <FilterQueryBuilder
115
+ ref="builderRef"
116
+ v-model="model"
117
+ :fields="fields"
118
+ :desktop-layout-on-mobile="false"
119
+ :hide-footer-actions="true"
120
+ :show-save="hasSaveListener"
121
+ @change="onChange"
122
+ @save="onSave"
123
+ />
124
+ <template #footer>
125
+ <Btn
126
+ v-if="activeFiltersCount > 0"
127
+ flat
128
+ sm
129
+ icon="delete_sweep"
130
+ color="gray"
131
+ :value="$t('filter.buttons.clearAll')"
132
+ @click="builderRef?.clearAll()"
133
+ />
134
+ <div class="flex-grow-1" />
135
+ <Btn
136
+ v-if="hasSaveListener"
137
+ sm
138
+ icon="save"
139
+ color="green-light"
140
+ class="color-green"
141
+ :disabled="activeFiltersCount === 0"
142
+ :value="$t('filter.buttons.save')"
143
+ @click="saveAndClose"
144
+ />
145
+ <Btn
146
+ color="primary"
147
+ :value="$t('filter.buttons.done')"
148
+ @click="closeSheet"
149
+ />
150
+ </template>
151
+ </Dialog>
152
+ </template>
153
+
154
+ <!-- Desktop / opt-out: dropdown or inline -->
155
+ <template v-else>
156
+ <Dropdown
157
+ v-if="!props.inline"
158
+ v-bind="dropdownProps"
159
+ class="filter-query-wrap"
160
+ >
161
+ <Card class="p-05">
162
+ <FilterQueryBuilder
163
+ ref="builderRef"
164
+ v-model="model"
165
+ :fields="fields"
166
+ :desktop-layout-on-mobile="props.desktopLayoutOnMobile"
167
+ :show-save="hasSaveListener"
168
+ @change="onChange"
169
+ @save="onSave"
170
+ />
171
+ </Card>
172
+ </Dropdown>
173
+ <div
174
+ v-else
175
+ class="filter-query-wrap"
176
+ :class="{ 'filter-query-desktop-mobile': props.desktopLayoutOnMobile }"
177
+ >
178
+ <FilterQueryBuilder
179
+ ref="builderRef"
180
+ v-model="model"
181
+ :fields="fields"
182
+ :desktop-layout-on-mobile="true"
183
+ :show-save="hasSaveListener"
184
+ @change="onChange"
185
+ @save="onSave"
186
+ />
187
+ </div>
188
+ </template>
663
189
  </template>
664
-
665
- <style>
666
- .filter-query-wrap{
667
- font-size: var(--bgl-input-font-size);
668
- }
669
- .and-or-select {
670
- --bgl-input-font-size: 12px !important;
671
- --input-background-color: transparent !important;
672
- min-width: 60px !important;
673
- }
674
-
675
- .between-inputs {
676
- min-width: 0;
677
- }
678
- .between-inputs > * {
679
- min-width: 0;
680
- flex: 1 1 0;
681
- }
682
- .between-inputs > span {
683
- flex: 0 0 auto;
684
- }
685
-
686
- .and-or-select .selectinput-btn {
687
- border: none;
688
- width: 100%;
689
- box-shadow: none;
690
- padding: 0 0.5rem !important;
691
- font-size: 12px !important;
692
- width: 100%;
693
- }
694
-
695
- .first-filter-row {
696
- grid-template-columns: minmax(calc(140px + 0.25rem), 0.5fr) minmax(170px, 0.75fr) minmax(120px, 0.5fr) auto;
697
- padding-top: 0 !important;
698
- }
699
-
700
- .filter-row {
701
- grid-template-columns: 50px minmax(90px, 0.5fr) minmax(170px, 0.75fr) minmax(120px, 0.5fr) auto;
702
- }
703
-
704
- .filter-query-inline {
705
- width: 100%;
706
- max-width: 100%;
707
- min-width: 0;
708
- box-sizing: border-box;
709
- }
710
-
711
- .filter-query-inline > *,
712
- .filter-query-inline .m_overflow,
713
- .filter-query-inline .first-filter-row > *,
714
- .filter-query-inline .filter-row > * {
715
- max-width: 100%;
716
- min-width: 0;
717
- box-sizing: border-box;
718
- }
719
-
720
- .filter-query-inline .m_overflow {
721
- overflow-x: hidden;
722
- overflow-y: visible;
723
- max-height: none;
724
- }
725
-
726
- .filter-query-inline .filter-row {
727
- grid-template-columns: 60px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
728
- }
729
-
730
- .filter-query-inline .first-filter-row {
731
- grid-template-columns: 60px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
732
- }
733
-
734
- .filter-query-inline .first-filter-field {
735
- grid-column: span 2;
736
- }
737
-
738
- .filter-query-inline .min-w-450px {
739
- min-width: 0 !important;
740
- }
741
-
742
- /* Transition animations */
743
- .condition-enter-active,
744
- .condition-leave-active {
745
- transition: all 0.25s ease;
746
- }
747
-
748
- .condition-enter-from {
749
- opacity: 0;
750
- transform: translateX(-10px);
751
- }
752
-
753
- .condition-leave-to {
754
- opacity: 0;
755
- transform: translateX(10px);
756
- }
757
-
758
- :dir(rtl) .condition-enter-from {
759
- transform: translateX(10px);
760
- }
761
-
762
- :dir(rtl) .condition-leave-to {
763
- transform: translateX(-10px);
764
- }
765
-
766
- @media (max-width: 910px) {
767
-
768
- .filter-row,
769
- .first-filter-row {
770
- grid-template-columns: auto;
771
- }
772
-
773
- .filter-query-desktop-mobile .filter-row,
774
- .filter-query-desktop-mobile .first-filter-row {
775
- grid-template-columns: 50px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
776
- }
777
-
778
- .filter-query-desktop-mobile .first-filter-row > *,
779
- .filter-query-desktop-mobile .filter-row > * {
780
- min-width: 0;
781
- }
782
-
783
- .filter-query-desktop-mobile .first-filter-field {
784
- grid-column: span 2;
785
- }
786
- }
787
-
788
- </style>
789
-
790
- <style>
791
-
792
- .borderHover * {
793
- transition: all 0.2s ease-in-out !important;
794
- }
795
-
796
- .borderHover:hover {
797
- --bgl-border-color: var(--bgl-primary);
798
- }
799
-
800
- </style>