@voicenter-team/voicenter-ui-plus 4.0.0-beta.6 → 4.0.0-beta.8

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 (93) hide show
  1. package/README.md +4 -1
  2. package/library/assets/components/VcFilterBar/VcFilterAddMenu.css +1 -0
  3. package/library/assets/components/VcFilterBar/VcFilterBar.css +1 -0
  4. package/library/assets/components/VcFilterBar/VcFilterChip.css +1 -0
  5. package/library/assets/components/VcFilterBar/VcFilterChipEditor.css +1 -0
  6. package/library/assets/components/VcFilterBar/VcFilterEditorModal.css +1 -0
  7. package/library/assets/components/VcFilterBar/VcFilterEditorPanel.css +1 -0
  8. package/library/assets/components/VcFilterBar/editors/VcFilterBooleanEditor.css +1 -0
  9. package/library/assets/components/VcFilterBar/editors/VcFilterMultiselectEditor.css +1 -0
  10. package/library/assets/components/VcFilterBar/editors/VcFilterRangeEditor.css +1 -0
  11. package/library/assets/components/VcFilterBar/editors/VcFilterSelectEditor.css +1 -0
  12. package/library/assets/components/VcFilterBar/editors/VcFilterTextEditor.css +1 -0
  13. package/library/assets/components/VcFilterBar/editors/VcFilterTextListEditor.css +1 -0
  14. package/library/assets/components/VcTimeInput/VcTimeInput.css +1 -1
  15. package/library/components/VcFilterBar/VcFilterAddMenu.vue.mjs +380 -0
  16. package/library/components/VcFilterBar/VcFilterAddMenu.vue3.mjs +5 -0
  17. package/library/components/VcFilterBar/VcFilterBar.vue.mjs +469 -0
  18. package/library/components/VcFilterBar/VcFilterBar.vue3.mjs +5 -0
  19. package/library/components/VcFilterBar/VcFilterChip.vue.mjs +136 -0
  20. package/library/components/VcFilterBar/VcFilterChip.vue3.mjs +5 -0
  21. package/library/components/VcFilterBar/VcFilterChipEditor.vue.mjs +133 -0
  22. package/library/components/VcFilterBar/VcFilterChipEditor.vue3.mjs +5 -0
  23. package/library/components/VcFilterBar/VcFilterEditorModal.vue.mjs +90 -0
  24. package/library/components/VcFilterBar/VcFilterEditorModal.vue3.mjs +5 -0
  25. package/library/components/VcFilterBar/VcFilterEditorPanel.vue.mjs +179 -0
  26. package/library/components/VcFilterBar/VcFilterEditorPanel.vue3.mjs +5 -0
  27. package/library/components/VcFilterBar/editors/VcFilterBooleanEditor.vue.mjs +62 -0
  28. package/library/components/VcFilterBar/editors/VcFilterBooleanEditor.vue3.mjs +5 -0
  29. package/library/components/VcFilterBar/editors/VcFilterMultiselectEditor.vue.mjs +199 -0
  30. package/library/components/VcFilterBar/editors/VcFilterMultiselectEditor.vue3.mjs +5 -0
  31. package/library/components/VcFilterBar/editors/VcFilterRangeEditor.vue.mjs +124 -0
  32. package/library/components/VcFilterBar/editors/VcFilterRangeEditor.vue3.mjs +5 -0
  33. package/library/components/VcFilterBar/editors/VcFilterSelectEditor.vue.mjs +96 -0
  34. package/library/components/VcFilterBar/editors/VcFilterSelectEditor.vue3.mjs +5 -0
  35. package/library/components/VcFilterBar/editors/VcFilterTextEditor.vue.mjs +58 -0
  36. package/library/components/VcFilterBar/editors/VcFilterTextEditor.vue3.mjs +5 -0
  37. package/library/components/VcFilterBar/editors/VcFilterTextListEditor.vue.mjs +155 -0
  38. package/library/components/VcFilterBar/editors/VcFilterTextListEditor.vue3.mjs +5 -0
  39. package/library/components/VcFilterBar/filterBarChip.mjs +59 -0
  40. package/library/components/VcFilterBar/filterBarDate.mjs +69 -0
  41. package/library/components/VcFilterBar/filterBarDraft.mjs +86 -0
  42. package/library/components/VcFilterBar/filterBarEditors.mjs +36 -0
  43. package/library/components/VcFilterBar/filterBarErrors.mjs +57 -0
  44. package/library/components/VcFilterBar/filterBarModel.mjs +378 -0
  45. package/library/components/VcFilterBar/filterBarOptions.mjs +253 -0
  46. package/library/components/VcFilterBar/filterBarSearch.mjs +89 -0
  47. package/library/components/VcFilterBar/filterBarValidate.mjs +99 -0
  48. package/library/components/VcTimeInput/VcTimeInput.vue.mjs +178 -36
  49. package/library/index.mjs +227 -162
  50. package/library/index.mjs.br +0 -0
  51. package/library/index.mjs.gz +0 -0
  52. package/library/localization/locales/en.json.mjs +51 -1
  53. package/library/plugin-components.gen.mjs +125 -122
  54. package/library/plugin.mjs +225 -160
  55. package/library/plugin.mjs.br +0 -0
  56. package/library/plugin.mjs.gz +0 -0
  57. package/library/style.css +25 -1
  58. package/library/style.css.br +0 -0
  59. package/library/style.css.gz +0 -0
  60. package/library/tokens/tokens.mjs +2 -0
  61. package/library/types/components/VcFilterBar/VcFilterAddMenu.vue.d.ts +39 -0
  62. package/library/types/components/VcFilterBar/VcFilterBar.vue.d.ts +132 -0
  63. package/library/types/components/VcFilterBar/VcFilterChip.vue.d.ts +42 -0
  64. package/library/types/components/VcFilterBar/VcFilterChipEditor.vue.d.ts +46 -0
  65. package/library/types/components/VcFilterBar/VcFilterEditorModal.vue.d.ts +40 -0
  66. package/library/types/components/VcFilterBar/VcFilterEditorPanel.vue.d.ts +116 -0
  67. package/library/types/components/VcFilterBar/editors/VcFilterBooleanEditor.vue.d.ts +66 -0
  68. package/library/types/components/VcFilterBar/editors/VcFilterMultiselectEditor.vue.d.ts +73 -0
  69. package/library/types/components/VcFilterBar/editors/VcFilterRangeEditor.vue.d.ts +62 -0
  70. package/library/types/components/VcFilterBar/editors/VcFilterSelectEditor.vue.d.ts +62 -0
  71. package/library/types/components/VcFilterBar/editors/VcFilterTextEditor.vue.d.ts +68 -0
  72. package/library/types/components/VcFilterBar/editors/VcFilterTextListEditor.vue.d.ts +64 -0
  73. package/library/types/components/VcFilterBar/filterBarChip.d.ts +23 -0
  74. package/library/types/components/VcFilterBar/filterBarDate.d.ts +14 -0
  75. package/library/types/components/VcFilterBar/filterBarDraft.d.ts +28 -0
  76. package/library/types/components/VcFilterBar/filterBarEditors.d.ts +7 -0
  77. package/library/types/components/VcFilterBar/filterBarErrors.d.ts +22 -0
  78. package/library/types/components/VcFilterBar/filterBarModel.d.ts +83 -0
  79. package/library/types/components/VcFilterBar/filterBarOptions.d.ts +52 -0
  80. package/library/types/components/VcFilterBar/filterBarSearch.d.ts +23 -0
  81. package/library/types/components/VcFilterBar/filterBarValidate.d.ts +34 -0
  82. package/library/types/components/VcJsonSchema/Components/JsonSchemaEditor.vue.d.ts +1 -1
  83. package/library/types/components/VcTimeInput/VcTimeInput.vue.d.ts +29 -6
  84. package/library/types/components/exports.d.ts +3 -1
  85. package/library/types/components.gen.d.ts +1 -0
  86. package/library/types/entity/components/Table/VcEntityListTable.vue.d.ts +3 -3
  87. package/library/types/index.d.ts +8 -0
  88. package/library/types/localization/locales/en.json.d.ts +51 -1
  89. package/library/types/tokens/tokens.d.ts +2 -1
  90. package/library/types/types/VcFilterBar.types.d.ts +329 -0
  91. package/library/types/types/VcTimeInput.types.d.ts +3 -0
  92. package/library/types/types/index.d.ts +2 -0
  93. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ import { isFilterListValue, isFilterRangeValue } from "./filterBarModel.mjs";
2
+ const CHIP_MAX_NAMES = 2;
3
+ function joinNames(names, maxNames) {
4
+ const shown = names.slice(0, maxNames).join(", ");
5
+ const rest = names.length - maxNames;
6
+ return {
7
+ text: rest > 0 ? `${shown} +${rest}` : shown,
8
+ full: names.join(", ")
9
+ };
10
+ }
11
+ function isCustomValue(value) {
12
+ return typeof value === "object" && value !== null && !Array.isArray(value);
13
+ }
14
+ function same(text) {
15
+ return {
16
+ text,
17
+ full: text
18
+ };
19
+ }
20
+ function formatChipValue(field, value, context) {
21
+ if (field.formatValue) {
22
+ return same(field.formatValue(value));
23
+ }
24
+ const maxNames = context.maxNames ?? CHIP_MAX_NAMES;
25
+ if (isFilterListValue(value)) {
26
+ const names = value.map((item) => context.optionLabel(item) ?? String(item));
27
+ return joinNames(names, maxNames);
28
+ }
29
+ if (field.kind === "range" && isFilterRangeValue(value)) {
30
+ const bound = (item) => field.formatBound ? field.formatBound(item) : String(item);
31
+ if (value.from !== null && value.to !== null) {
32
+ return same(`${bound(value.from)}–${bound(value.to)}`);
33
+ }
34
+ return same(value.from !== null ? `≥ ${bound(value.from)}` : `≤ ${bound(value.to ?? 0)}`);
35
+ }
36
+ if (typeof value === "boolean") {
37
+ return same(value ? context.yes : context.no);
38
+ }
39
+ if (field.kind === "select" && (typeof value === "string" || typeof value === "number")) {
40
+ return same(context.optionLabel(value) ?? String(value));
41
+ }
42
+ if (field.kind === "custom" && isCustomValue(value)) {
43
+ return same(field.summary ? field.summary(value) : "");
44
+ }
45
+ return same(`“${String(value)}”`);
46
+ }
47
+ const RIGHT_TO_LEFT_LETTER = /[\p{Script=Hebrew}\p{Script=Arabic}]/u;
48
+ function getTextDirection(text) {
49
+ return RIGHT_TO_LEFT_LETTER.test(text) ? "rtl" : "ltr";
50
+ }
51
+ function readOptionKey(option, key) {
52
+ return Reflect.get(option, key);
53
+ }
54
+ export {
55
+ CHIP_MAX_NAMES,
56
+ formatChipValue,
57
+ getTextDirection,
58
+ readOptionKey
59
+ };
@@ -0,0 +1,69 @@
1
+ const DEFAULT_START_KEY = "StartTime";
2
+ const DEFAULT_END_KEY = "EndTime";
3
+ const DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;
4
+ function pad(value) {
5
+ return String(value).padStart(2, "0");
6
+ }
7
+ function startOfDay(date) {
8
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
9
+ }
10
+ function endOfDay(date) {
11
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
12
+ }
13
+ function toModelDate(date, format, edge, keepTime = false) {
14
+ const day = keepTime ? new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()) : edge === "start" ? startOfDay(date) : endOfDay(date);
15
+ const datePart = `${day.getFullYear()}-${pad(day.getMonth() + 1)}-${pad(day.getDate())}`;
16
+ if (format === "date") {
17
+ return datePart;
18
+ }
19
+ if (format === "datetime") {
20
+ return `${datePart}T${pad(day.getHours())}:${pad(day.getMinutes())}:${pad(day.getSeconds())}`;
21
+ }
22
+ return Math.floor(day.getTime() / 1e3);
23
+ }
24
+ function fromModelDate(value) {
25
+ if (typeof value === "number" && Number.isFinite(value)) {
26
+ return new Date(value * 1e3);
27
+ }
28
+ if (typeof value !== "string") {
29
+ return void 0;
30
+ }
31
+ const parts = DATE_PATTERN.exec(value);
32
+ if (!parts) {
33
+ return void 0;
34
+ }
35
+ const [, year, month, day, hours = "0", minutes = "0", seconds = "0"] = parts;
36
+ return new Date(Number(year), Number(month) - 1, Number(day), Number(hours), Number(minutes), Number(seconds));
37
+ }
38
+ function getDateKeys(config) {
39
+ return [config.startKey ?? DEFAULT_START_KEY, config.endKey ?? DEFAULT_END_KEY];
40
+ }
41
+ function readDateRange(model, config) {
42
+ const [startKey, endKey] = getDateKeys(config);
43
+ const start = fromModelDate(model[startKey]);
44
+ const end = fromModelDate(model[endKey]);
45
+ return start && end ? [start, end] : void 0;
46
+ }
47
+ function writeDateRange(model, range, config) {
48
+ const [startKey, endKey] = getDateKeys(config);
49
+ const format = config.valueFormat ?? "date";
50
+ const next = { ...model };
51
+ if (!range) {
52
+ delete next[startKey];
53
+ delete next[endKey];
54
+ return next;
55
+ }
56
+ const keepTime = config.picker === "datetime";
57
+ next[startKey] = toModelDate(range[0], format, "start", keepTime);
58
+ next[endKey] = toModelDate(range[1], format, "end", keepTime);
59
+ return next;
60
+ }
61
+ export {
62
+ DEFAULT_END_KEY,
63
+ DEFAULT_START_KEY,
64
+ fromModelDate,
65
+ getDateKeys,
66
+ readDateRange,
67
+ toModelDate,
68
+ writeDateRange
69
+ };
@@ -0,0 +1,86 @@
1
+ import { shallowRef, ref, computed } from "vue";
2
+ import { withoutSide, getAppliedValues, getBlockedValues, getFieldModes, isSameFieldValue, addFieldValue, isEmptyFilterValue, editFieldValue, isFilterListValue } from "./filterBarModel.mjs";
3
+ import { validateFieldValue, canAddFieldValue } from "./filterBarValidate.mjs";
4
+ function useFilterDraft(context) {
5
+ const field = shallowRef();
6
+ const origin = ref("add");
7
+ const startMode = ref("include");
8
+ const startValue = shallowRef();
9
+ const mode = ref("include");
10
+ const value = shallowRef();
11
+ const base = computed(() => {
12
+ const current = field.value;
13
+ if (!current || origin.value === "add") {
14
+ return context.model();
15
+ }
16
+ return withoutSide(context.model(), current, startMode.value, context.modelOptions());
17
+ });
18
+ const applied = computed(() => field.value && origin.value === "add" ? getAppliedValues(base.value, field.value, mode.value, context.modelOptions()) : []);
19
+ const blocked = computed(() => field.value ? getBlockedValues(base.value, field.value, mode.value, context.modelOptions()) : []);
20
+ const canExclude = computed(() => !!field.value && getFieldModes(field.value).includes("exclude"));
21
+ const problem = computed(() => field.value ? validateFieldValue(field.value, value.value, applied.value) : void 0);
22
+ const canCommit = computed(() => {
23
+ if (!field.value) {
24
+ return false;
25
+ }
26
+ if (origin.value === "add") {
27
+ return canAddFieldValue(field.value, value.value, applied.value);
28
+ }
29
+ return problem.value === void 0;
30
+ });
31
+ const changed = computed(() => !!field.value && (mode.value !== startMode.value || !isSameFieldValue(field.value, value.value, startValue.value)));
32
+ function start(next) {
33
+ field.value = next.field;
34
+ origin.value = next.origin;
35
+ startMode.value = next.mode ?? "include";
36
+ startValue.value = next.value;
37
+ mode.value = startMode.value;
38
+ value.value = next.value;
39
+ }
40
+ function clear() {
41
+ field.value = void 0;
42
+ value.value = void 0;
43
+ startValue.value = void 0;
44
+ }
45
+ function setMode(next) {
46
+ mode.value = next;
47
+ if (isFilterListValue(value.value)) {
48
+ const kept = value.value.filter((item) => !blocked.value.includes(item) && !applied.value.includes(item));
49
+ value.value = kept.length ? kept : void 0;
50
+ }
51
+ }
52
+ function result() {
53
+ const current = field.value;
54
+ if (!current || !canCommit.value) {
55
+ return void 0;
56
+ }
57
+ if (origin.value === "add") {
58
+ return addFieldValue(context.model(), current, mode.value, value.value, context.modelOptions());
59
+ }
60
+ if (!changed.value) {
61
+ return void 0;
62
+ }
63
+ const next = value.value === void 0 || isEmptyFilterValue(value.value) ? void 0 : value.value;
64
+ return editFieldValue(context.model(), current, startMode.value, mode.value, next, context.modelOptions());
65
+ }
66
+ const preview = computed(() => result() ?? context.model());
67
+ return {
68
+ field,
69
+ origin,
70
+ preview,
71
+ mode,
72
+ value,
73
+ applied,
74
+ blocked,
75
+ canExclude,
76
+ canCommit,
77
+ changed,
78
+ start,
79
+ clear,
80
+ setMode,
81
+ result
82
+ };
83
+ }
84
+ export {
85
+ useFilterDraft
86
+ };
@@ -0,0 +1,36 @@
1
+ import _sfc_main$4 from "./editors/VcFilterBooleanEditor.vue.mjs";
2
+ import '../../assets/components/VcFilterBar/editors/VcFilterTextListEditor.css';import '../../assets/components/VcFilterBar/editors/VcFilterTextEditor.css';import '../../assets/components/VcFilterBar/editors/VcFilterSelectEditor.css';import '../../assets/components/VcFilterBar/editors/VcFilterRangeEditor.css';import '../../assets/components/VcFilterBar/editors/VcFilterMultiselectEditor.css';import '../../assets/components/VcFilterBar/editors/VcFilterBooleanEditor.css';/* empty css */
3
+ import _sfc_main$5 from "./editors/VcFilterMultiselectEditor.vue.mjs";
4
+ /* empty css */
5
+ import _sfc_main$2 from "./editors/VcFilterRangeEditor.vue.mjs";
6
+ /* empty css */
7
+ import _sfc_main from "./editors/VcFilterSelectEditor.vue.mjs";
8
+ /* empty css */
9
+ import _sfc_main$3 from "./editors/VcFilterTextEditor.vue.mjs";
10
+ /* empty css */
11
+ import _sfc_main$1 from "./editors/VcFilterTextListEditor.vue.mjs";
12
+ /* empty css */
13
+ const BUILT_IN_EDITORS = {
14
+ multiselect: _sfc_main$5,
15
+ boolean: _sfc_main$4,
16
+ text: _sfc_main$3,
17
+ range: _sfc_main$2,
18
+ textList: _sfc_main$1,
19
+ select: _sfc_main
20
+ };
21
+ function getEditorSlot(field, slots) {
22
+ return slots == null ? void 0 : slots[`editor-${field.key}`];
23
+ }
24
+ function hasFilterEditor(field, slots) {
25
+ return !!getEditorSlot(field, slots) || !!field.editor || !!BUILT_IN_EDITORS[field.kind];
26
+ }
27
+ function isModalField(field) {
28
+ var _a;
29
+ return ((_a = field.editorContainer) == null ? void 0 : _a.in) === "modal";
30
+ }
31
+ export {
32
+ BUILT_IN_EDITORS,
33
+ getEditorSlot,
34
+ hasFilterEditor,
35
+ isModalField
36
+ };
@@ -0,0 +1,57 @@
1
+ import { findFieldByErrorPath, readFieldValue, isSameFieldValue, getAppliedId, getFieldErrorPath, isFilterListValue } from "./filterBarModel.mjs";
2
+ function join(current, message) {
3
+ return current ? `${current} ${message}` : message;
4
+ }
5
+ function rootKey(path, options) {
6
+ const excludePrefix = `${(options == null ? void 0 : options.excludeKey) ?? "Exclude"}.`;
7
+ const rest = path.startsWith(excludePrefix) ? path.slice(excludePrefix.length) : path;
8
+ return rest.split(/[.[]/)[0];
9
+ }
10
+ function sameKeys(a, b, keys) {
11
+ return keys.every((key) => JSON.stringify(a[key]) === JSON.stringify(b[key]));
12
+ }
13
+ function placeFilterErrors(errors, context) {
14
+ const placement = {
15
+ byChip: {},
16
+ other: []
17
+ };
18
+ Object.entries(errors ?? {}).forEach(([path, message]) => {
19
+ const target = findFieldByErrorPath(path, context.fields, context.options);
20
+ if (target) {
21
+ const now = readFieldValue(context.model, target.field, target.mode, context.options);
22
+ const then = readFieldValue(context.snapshot, target.field, target.mode, context.options);
23
+ if (isSameFieldValue(target.field, now, then)) {
24
+ const id = getAppliedId(target.field, target.mode);
25
+ placement.byChip[id] = join(placement.byChip[id], message);
26
+ }
27
+ return;
28
+ }
29
+ const key = rootKey(path, context.options);
30
+ if (context.dateKeys.includes(key)) {
31
+ if (sameKeys(context.model, context.snapshot, context.dateKeys)) {
32
+ placement.date = join(placement.date, message);
33
+ }
34
+ return;
35
+ }
36
+ if (context.searchKeys.includes(key)) {
37
+ if (sameKeys(context.model, context.snapshot, context.searchKeys)) {
38
+ placement.search = join(placement.search, message);
39
+ }
40
+ return;
41
+ }
42
+ placement.other.push(message);
43
+ });
44
+ return placement;
45
+ }
46
+ function getRefusedValues(refused, field, mode, model, options) {
47
+ if (!refused) {
48
+ return [];
49
+ }
50
+ const ids = refused[getFieldErrorPath(field, mode, options)] ?? [];
51
+ const value = readFieldValue(model, field, mode, options);
52
+ return isFilterListValue(value) ? value.filter((item) => ids.includes(item)) : [];
53
+ }
54
+ export {
55
+ getRefusedValues,
56
+ placeFilterErrors
57
+ };
@@ -0,0 +1,378 @@
1
+ const DEFAULT_EXCLUDE_KEY = "Exclude";
2
+ const MODES = ["include", "exclude"];
3
+ function isEmptyFilterValue(value) {
4
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
5
+ }
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ function isListItem(value) {
10
+ return typeof value === "string" || typeof value === "number";
11
+ }
12
+ function isFilterListValue(value) {
13
+ return Array.isArray(value) && value.every(isListItem);
14
+ }
15
+ function isFilterRangeValue(value) {
16
+ return isRecord(value) && (value.from === null || typeof value.from === "number") && (value.to === null || typeof value.to === "number");
17
+ }
18
+ function isListField(field) {
19
+ return field.kind === "multiselect" || field.kind === "textList";
20
+ }
21
+ function uniqueItems(items) {
22
+ return items.filter((item, index) => items.indexOf(item) === index);
23
+ }
24
+ function isEmptyCustomValue(field, value) {
25
+ if (field.isEmpty) {
26
+ return field.isEmpty(value);
27
+ }
28
+ return Object.values(value).every(isEmptyFilterValue);
29
+ }
30
+ function getFieldKeys(field) {
31
+ if (field.kind === "range") {
32
+ return [...field.valueKey];
33
+ }
34
+ if (field.kind === "custom") {
35
+ return Array.isArray(field.valueKey) ? [...field.valueKey] : [field.valueKey];
36
+ }
37
+ return [field.valueKey ?? field.key];
38
+ }
39
+ function supportsExclude(field) {
40
+ return !!field.exclude;
41
+ }
42
+ function getFieldModes(field) {
43
+ return supportsExclude(field) ? MODES : ["include"];
44
+ }
45
+ function getExcludeKey(options) {
46
+ return (options == null ? void 0 : options.excludeKey) ?? DEFAULT_EXCLUDE_KEY;
47
+ }
48
+ function getFieldLocation(field, mode) {
49
+ const keys = getFieldKeys(field);
50
+ if (mode === "include") {
51
+ return {
52
+ nested: false,
53
+ keys
54
+ };
55
+ }
56
+ if (!field.exclude) {
57
+ throw new Error(`VcFilterBar: the field "${field.key}" cannot be excluded`);
58
+ }
59
+ if (field.exclude === true) {
60
+ return {
61
+ nested: true,
62
+ keys
63
+ };
64
+ }
65
+ const excludeKeys = Array.isArray(field.exclude.valueKey) ? [...field.exclude.valueKey] : [field.exclude.valueKey];
66
+ if (excludeKeys.length !== keys.length) {
67
+ throw new Error(`VcFilterBar: the field "${field.key}" has ${keys.length} keys but ${excludeKeys.length} exclude keys`);
68
+ }
69
+ return {
70
+ nested: false,
71
+ keys: excludeKeys
72
+ };
73
+ }
74
+ function getFieldErrorPath(field, mode, options) {
75
+ const location = getFieldLocation(field, mode);
76
+ const key = location.keys[0];
77
+ return location.nested ? `${getExcludeKey(options)}.${key}` : key;
78
+ }
79
+ function findFieldByErrorPath(path, fields, options) {
80
+ const excludePrefix = `${getExcludeKey(options)}.`;
81
+ const nested = path.startsWith(excludePrefix);
82
+ const rest = nested ? path.slice(excludePrefix.length) : path;
83
+ const key = rest.split(/[.[]/)[0];
84
+ for (const field of fields) {
85
+ for (const mode of getFieldModes(field)) {
86
+ const location = getFieldLocation(field, mode);
87
+ if (location.nested === nested && location.keys.includes(key)) {
88
+ return {
89
+ field,
90
+ mode
91
+ };
92
+ }
93
+ }
94
+ }
95
+ return void 0;
96
+ }
97
+ function readRaw(model, location, options) {
98
+ const container = location.nested ? model[getExcludeKey(options)] : model;
99
+ if (!isRecord(container)) {
100
+ return location.keys.map(() => void 0);
101
+ }
102
+ return location.keys.map((key) => container[key]);
103
+ }
104
+ function parseValue(field, raw) {
105
+ const first = raw[0];
106
+ switch (field.kind) {
107
+ case "multiselect":
108
+ case "textList": {
109
+ if (!Array.isArray(first)) {
110
+ return void 0;
111
+ }
112
+ const items = uniqueItems(first.filter(isListItem));
113
+ return items.length ? items : void 0;
114
+ }
115
+ case "range": {
116
+ const from = typeof raw[0] === "number" ? raw[0] : null;
117
+ const to = typeof raw[1] === "number" ? raw[1] : null;
118
+ return from === null && to === null ? void 0 : {
119
+ from,
120
+ to
121
+ };
122
+ }
123
+ case "text":
124
+ return typeof first === "string" && first !== "" ? first : void 0;
125
+ case "boolean":
126
+ return typeof first === "boolean" ? first : void 0;
127
+ case "select":
128
+ return isListItem(first) && first !== "" ? first : void 0;
129
+ case "custom": {
130
+ const value = {};
131
+ getFieldKeys(field).forEach((key, index) => {
132
+ if (!isEmptyFilterValue(raw[index])) {
133
+ value[key] = raw[index];
134
+ }
135
+ });
136
+ return isEmptyCustomValue(field, value) ? void 0 : value;
137
+ }
138
+ }
139
+ }
140
+ function readFieldValue(model, field, mode, options) {
141
+ return parseValue(field, readRaw(model, getFieldLocation(field, mode), options));
142
+ }
143
+ function readListValue(model, field, mode, options) {
144
+ if (!isListField(field) || !getFieldModes(field).includes(mode)) {
145
+ return [];
146
+ }
147
+ const value = readFieldValue(model, field, mode, options);
148
+ return isFilterListValue(value) ? value : [];
149
+ }
150
+ function oppositeMode(mode) {
151
+ return mode === "include" ? "exclude" : "include";
152
+ }
153
+ function getBlockedValues(model, field, mode, options) {
154
+ return readListValue(model, field, oppositeMode(mode), options);
155
+ }
156
+ function getAppliedValues(model, field, mode, options) {
157
+ return readListValue(model, field, mode, options);
158
+ }
159
+ function isFieldApplied(model, field, mode, options) {
160
+ return getFieldModes(field).includes(mode) && readFieldValue(model, field, mode, options) !== void 0;
161
+ }
162
+ function findOverlaps(model, fields, options) {
163
+ return fields.flatMap((field) => {
164
+ const excluded = readListValue(model, field, "exclude", options);
165
+ const values = readListValue(model, field, "include", options).filter((item) => excluded.includes(item));
166
+ return values.length ? [{
167
+ field,
168
+ values
169
+ }] : [];
170
+ });
171
+ }
172
+ function serializeValue(model, field, mode, value, options) {
173
+ const keys = getFieldKeys(field);
174
+ if (value === void 0) {
175
+ return keys.map(() => void 0);
176
+ }
177
+ const mismatch = () => new TypeError(`VcFilterBar: the value does not fit the ${field.kind} field "${field.key}"`);
178
+ switch (field.kind) {
179
+ case "multiselect":
180
+ case "textList": {
181
+ if (!isFilterListValue(value)) {
182
+ throw mismatch();
183
+ }
184
+ const blocked = getBlockedValues(model, field, mode, options);
185
+ return [uniqueItems(value).filter((item) => !blocked.includes(item))];
186
+ }
187
+ case "range":
188
+ if (!isFilterRangeValue(value)) {
189
+ throw mismatch();
190
+ }
191
+ return [value.from, value.to];
192
+ case "text":
193
+ if (typeof value !== "string") {
194
+ throw mismatch();
195
+ }
196
+ return [value];
197
+ case "boolean":
198
+ if (typeof value !== "boolean") {
199
+ throw mismatch();
200
+ }
201
+ return [value];
202
+ case "select":
203
+ if (!isListItem(value)) {
204
+ throw mismatch();
205
+ }
206
+ return [value];
207
+ case "custom": {
208
+ if (!isRecord(value)) {
209
+ throw mismatch();
210
+ }
211
+ return isEmptyCustomValue(field, value) ? keys.map(() => void 0) : keys.map((key) => value[key]);
212
+ }
213
+ }
214
+ }
215
+ function writeFieldValue(model, field, mode, value, options) {
216
+ const location = getFieldLocation(field, mode);
217
+ const raw = serializeValue(model, field, mode, value, options);
218
+ const excludeKey = getExcludeKey(options);
219
+ const next = { ...model };
220
+ const current = location.nested ? next[excludeKey] : next;
221
+ const container = isRecord(current) ? { ...current } : {};
222
+ location.keys.forEach((key, index) => {
223
+ if (isEmptyFilterValue(raw[index])) {
224
+ delete container[key];
225
+ } else {
226
+ container[key] = raw[index];
227
+ }
228
+ });
229
+ if (!location.nested) {
230
+ return container;
231
+ }
232
+ if (Object.keys(container).length) {
233
+ next[excludeKey] = container;
234
+ } else {
235
+ delete next[excludeKey];
236
+ }
237
+ return next;
238
+ }
239
+ function removeFieldValue(model, field, mode, options) {
240
+ return writeFieldValue(model, field, mode, void 0, options);
241
+ }
242
+ function editFieldValue(model, field, fromMode, toMode, value, options) {
243
+ if (fromMode === toMode) {
244
+ return writeFieldValue(model, field, toMode, value, options);
245
+ }
246
+ const without = removeFieldValue(model, field, fromMode, options);
247
+ return addFieldValue(without, field, toMode, value, options);
248
+ }
249
+ function withoutSide(model, field, mode, options) {
250
+ return removeFieldValue(model, field, mode, options);
251
+ }
252
+ function addFieldValue(model, field, mode, value, options) {
253
+ if (value === void 0 || isEmptyFilterValue(value)) {
254
+ return model;
255
+ }
256
+ if (isListField(field)) {
257
+ if (!isFilterListValue(value)) {
258
+ throw new TypeError(`VcFilterBar: the value does not fit the ${field.kind} field "${field.key}"`);
259
+ }
260
+ return writeFieldValue(model, field, mode, [...getAppliedValues(model, field, mode, options), ...value], options);
261
+ }
262
+ if (field.kind === "custom" && field.merge && isRecord(value)) {
263
+ const current = readFieldValue(model, field, mode, options);
264
+ if (isRecord(current)) {
265
+ return writeFieldValue(model, field, mode, field.merge(current, value), options);
266
+ }
267
+ }
268
+ return writeFieldValue(model, field, mode, value, options);
269
+ }
270
+ function getAppliedId(field, mode) {
271
+ return `${field.key}:${mode}`;
272
+ }
273
+ function getAppliedFilters(model, fields, options) {
274
+ return fields.flatMap((field) => getFieldModes(field).flatMap((mode) => {
275
+ const value = readFieldValue(model, field, mode, options);
276
+ return value === void 0 ? [] : [{
277
+ id: getAppliedId(field, mode),
278
+ field,
279
+ mode,
280
+ value
281
+ }];
282
+ }));
283
+ }
284
+ function getOwnedKeys(fields) {
285
+ const top = /* @__PURE__ */ new Set();
286
+ const nested = /* @__PURE__ */ new Set();
287
+ fields.forEach((field) => getFieldModes(field).forEach((mode) => {
288
+ const location = getFieldLocation(field, mode);
289
+ location.keys.forEach((key) => (location.nested ? nested : top).add(key));
290
+ }));
291
+ return {
292
+ top,
293
+ nested
294
+ };
295
+ }
296
+ function splitFilterModel(model, fields, options) {
297
+ const owned = getOwnedKeys(fields);
298
+ const excludeKey = getExcludeKey(options);
299
+ const rest = {};
300
+ Object.entries(model).forEach(([key, value]) => {
301
+ if (key === excludeKey && isRecord(value) && owned.nested.size) {
302
+ const unowned = Object.fromEntries(Object.entries(value).filter(([nestedKey]) => !owned.nested.has(nestedKey)));
303
+ if (Object.keys(unowned).length) {
304
+ rest[key] = unowned;
305
+ }
306
+ return;
307
+ }
308
+ if (!owned.top.has(key)) {
309
+ rest[key] = value;
310
+ }
311
+ });
312
+ return {
313
+ applied: getAppliedFilters(model, fields, options),
314
+ rest
315
+ };
316
+ }
317
+ function joinFilterModel(applied, rest = {}, options) {
318
+ return applied.reduce(
319
+ (model, item) => writeFieldValue(model, item.field, item.mode, item.value, options),
320
+ { ...rest }
321
+ );
322
+ }
323
+ function isDeepEqual(a, b) {
324
+ if (Object.is(a, b)) {
325
+ return true;
326
+ }
327
+ if (Array.isArray(a) && Array.isArray(b)) {
328
+ return a.length === b.length && a.every((item, index) => isDeepEqual(item, b[index]));
329
+ }
330
+ if (isRecord(a) && isRecord(b)) {
331
+ const keysA = Object.keys(a).filter((key) => !isEmptyFilterValue(a[key]));
332
+ const keysB = Object.keys(b).filter((key) => !isEmptyFilterValue(b[key]));
333
+ return keysA.length === keysB.length && keysA.every((key) => isDeepEqual(a[key], b[key]));
334
+ }
335
+ return false;
336
+ }
337
+ function isSameFieldValue(field, a, b) {
338
+ const emptyA = a === void 0 || isEmptyFilterValue(a);
339
+ const emptyB = b === void 0 || isEmptyFilterValue(b);
340
+ if (emptyA || emptyB) {
341
+ return emptyA && emptyB;
342
+ }
343
+ if (isListField(field) && isFilterListValue(a) && isFilterListValue(b)) {
344
+ const setA = uniqueItems(a);
345
+ const setB = uniqueItems(b);
346
+ return setA.length === setB.length && setA.every((item) => setB.includes(item));
347
+ }
348
+ if (field.kind === "custom" && field.isSame && isRecord(a) && isRecord(b)) {
349
+ return field.isSame(a, b);
350
+ }
351
+ return isDeepEqual(a, b);
352
+ }
353
+ export {
354
+ DEFAULT_EXCLUDE_KEY,
355
+ addFieldValue,
356
+ editFieldValue,
357
+ findFieldByErrorPath,
358
+ findOverlaps,
359
+ getAppliedFilters,
360
+ getAppliedId,
361
+ getAppliedValues,
362
+ getBlockedValues,
363
+ getFieldErrorPath,
364
+ getFieldKeys,
365
+ getFieldModes,
366
+ isEmptyFilterValue,
367
+ isFieldApplied,
368
+ isFilterListValue,
369
+ isFilterRangeValue,
370
+ isSameFieldValue,
371
+ joinFilterModel,
372
+ readFieldValue,
373
+ removeFieldValue,
374
+ splitFilterModel,
375
+ supportsExclude,
376
+ withoutSide,
377
+ writeFieldValue
378
+ };