@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.
- package/README.md +4 -1
- package/library/assets/components/VcFilterBar/VcFilterAddMenu.css +1 -0
- package/library/assets/components/VcFilterBar/VcFilterBar.css +1 -0
- package/library/assets/components/VcFilterBar/VcFilterChip.css +1 -0
- package/library/assets/components/VcFilterBar/VcFilterChipEditor.css +1 -0
- package/library/assets/components/VcFilterBar/VcFilterEditorModal.css +1 -0
- package/library/assets/components/VcFilterBar/VcFilterEditorPanel.css +1 -0
- package/library/assets/components/VcFilterBar/editors/VcFilterBooleanEditor.css +1 -0
- package/library/assets/components/VcFilterBar/editors/VcFilterMultiselectEditor.css +1 -0
- package/library/assets/components/VcFilterBar/editors/VcFilterRangeEditor.css +1 -0
- package/library/assets/components/VcFilterBar/editors/VcFilterSelectEditor.css +1 -0
- package/library/assets/components/VcFilterBar/editors/VcFilterTextEditor.css +1 -0
- package/library/assets/components/VcFilterBar/editors/VcFilterTextListEditor.css +1 -0
- package/library/assets/components/VcTimeInput/VcTimeInput.css +1 -1
- package/library/components/VcFilterBar/VcFilterAddMenu.vue.mjs +380 -0
- package/library/components/VcFilterBar/VcFilterAddMenu.vue3.mjs +5 -0
- package/library/components/VcFilterBar/VcFilterBar.vue.mjs +469 -0
- package/library/components/VcFilterBar/VcFilterBar.vue3.mjs +5 -0
- package/library/components/VcFilterBar/VcFilterChip.vue.mjs +136 -0
- package/library/components/VcFilterBar/VcFilterChip.vue3.mjs +5 -0
- package/library/components/VcFilterBar/VcFilterChipEditor.vue.mjs +133 -0
- package/library/components/VcFilterBar/VcFilterChipEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/VcFilterEditorModal.vue.mjs +90 -0
- package/library/components/VcFilterBar/VcFilterEditorModal.vue3.mjs +5 -0
- package/library/components/VcFilterBar/VcFilterEditorPanel.vue.mjs +179 -0
- package/library/components/VcFilterBar/VcFilterEditorPanel.vue3.mjs +5 -0
- package/library/components/VcFilterBar/editors/VcFilterBooleanEditor.vue.mjs +62 -0
- package/library/components/VcFilterBar/editors/VcFilterBooleanEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/editors/VcFilterMultiselectEditor.vue.mjs +199 -0
- package/library/components/VcFilterBar/editors/VcFilterMultiselectEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/editors/VcFilterRangeEditor.vue.mjs +124 -0
- package/library/components/VcFilterBar/editors/VcFilterRangeEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/editors/VcFilterSelectEditor.vue.mjs +96 -0
- package/library/components/VcFilterBar/editors/VcFilterSelectEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/editors/VcFilterTextEditor.vue.mjs +58 -0
- package/library/components/VcFilterBar/editors/VcFilterTextEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/editors/VcFilterTextListEditor.vue.mjs +155 -0
- package/library/components/VcFilterBar/editors/VcFilterTextListEditor.vue3.mjs +5 -0
- package/library/components/VcFilterBar/filterBarChip.mjs +59 -0
- package/library/components/VcFilterBar/filterBarDate.mjs +69 -0
- package/library/components/VcFilterBar/filterBarDraft.mjs +86 -0
- package/library/components/VcFilterBar/filterBarEditors.mjs +36 -0
- package/library/components/VcFilterBar/filterBarErrors.mjs +57 -0
- package/library/components/VcFilterBar/filterBarModel.mjs +378 -0
- package/library/components/VcFilterBar/filterBarOptions.mjs +253 -0
- package/library/components/VcFilterBar/filterBarSearch.mjs +89 -0
- package/library/components/VcFilterBar/filterBarValidate.mjs +99 -0
- package/library/components/VcTimeInput/VcTimeInput.vue.mjs +178 -36
- package/library/index.mjs +227 -162
- package/library/index.mjs.br +0 -0
- package/library/index.mjs.gz +0 -0
- package/library/localization/locales/en.json.mjs +51 -1
- package/library/plugin-components.gen.mjs +125 -122
- package/library/plugin.mjs +225 -160
- package/library/plugin.mjs.br +0 -0
- package/library/plugin.mjs.gz +0 -0
- package/library/style.css +25 -1
- package/library/style.css.br +0 -0
- package/library/style.css.gz +0 -0
- package/library/tokens/tokens.mjs +2 -0
- package/library/types/components/VcFilterBar/VcFilterAddMenu.vue.d.ts +39 -0
- package/library/types/components/VcFilterBar/VcFilterBar.vue.d.ts +132 -0
- package/library/types/components/VcFilterBar/VcFilterChip.vue.d.ts +42 -0
- package/library/types/components/VcFilterBar/VcFilterChipEditor.vue.d.ts +46 -0
- package/library/types/components/VcFilterBar/VcFilterEditorModal.vue.d.ts +40 -0
- package/library/types/components/VcFilterBar/VcFilterEditorPanel.vue.d.ts +116 -0
- package/library/types/components/VcFilterBar/editors/VcFilterBooleanEditor.vue.d.ts +66 -0
- package/library/types/components/VcFilterBar/editors/VcFilterMultiselectEditor.vue.d.ts +73 -0
- package/library/types/components/VcFilterBar/editors/VcFilterRangeEditor.vue.d.ts +62 -0
- package/library/types/components/VcFilterBar/editors/VcFilterSelectEditor.vue.d.ts +62 -0
- package/library/types/components/VcFilterBar/editors/VcFilterTextEditor.vue.d.ts +68 -0
- package/library/types/components/VcFilterBar/editors/VcFilterTextListEditor.vue.d.ts +64 -0
- package/library/types/components/VcFilterBar/filterBarChip.d.ts +23 -0
- package/library/types/components/VcFilterBar/filterBarDate.d.ts +14 -0
- package/library/types/components/VcFilterBar/filterBarDraft.d.ts +28 -0
- package/library/types/components/VcFilterBar/filterBarEditors.d.ts +7 -0
- package/library/types/components/VcFilterBar/filterBarErrors.d.ts +22 -0
- package/library/types/components/VcFilterBar/filterBarModel.d.ts +83 -0
- package/library/types/components/VcFilterBar/filterBarOptions.d.ts +52 -0
- package/library/types/components/VcFilterBar/filterBarSearch.d.ts +23 -0
- package/library/types/components/VcFilterBar/filterBarValidate.d.ts +34 -0
- package/library/types/components/VcJsonSchema/Components/JsonSchemaEditor.vue.d.ts +1 -1
- package/library/types/components/VcTimeInput/VcTimeInput.vue.d.ts +29 -6
- package/library/types/components/exports.d.ts +3 -1
- package/library/types/components.gen.d.ts +1 -0
- package/library/types/entity/components/Table/VcEntityListTable.vue.d.ts +3 -3
- package/library/types/index.d.ts +8 -0
- package/library/types/localization/locales/en.json.d.ts +51 -1
- package/library/types/tokens/tokens.d.ts +2 -1
- package/library/types/types/VcFilterBar.types.d.ts +329 -0
- package/library/types/types/VcTimeInput.types.d.ts +3 -0
- package/library/types/types/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { provide, getCurrentInstance, inject, computed, toValue, shallowReactive, watch } from "vue";
|
|
5
|
+
import { VcFilterOptionsStoreKey } from "../../tokens/tokens.mjs";
|
|
6
|
+
const DEFAULT_OPTIONS_TTL = 5 * 60 * 1e3;
|
|
7
|
+
class VcFilterOptionsDeniedError extends Error {
|
|
8
|
+
constructor(reason) {
|
|
9
|
+
super(reason);
|
|
10
|
+
__publicField(this, "disabledReason");
|
|
11
|
+
this.name = "VcFilterOptionsDeniedError";
|
|
12
|
+
this.disabledReason = reason;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function getDeniedReason(error) {
|
|
19
|
+
if (error instanceof VcFilterOptionsDeniedError) {
|
|
20
|
+
return error.disabledReason;
|
|
21
|
+
}
|
|
22
|
+
return isRecord(error) && typeof error.disabledReason === "string" ? error.disabledReason : void 0;
|
|
23
|
+
}
|
|
24
|
+
function stableStringify(value) {
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
27
|
+
}
|
|
28
|
+
if (isRecord(value)) {
|
|
29
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(",")}}`;
|
|
30
|
+
}
|
|
31
|
+
return JSON.stringify(value) ?? "null";
|
|
32
|
+
}
|
|
33
|
+
function getOptionsKey(source, params = {}) {
|
|
34
|
+
return `${source.id}:${stableStringify(params)}`;
|
|
35
|
+
}
|
|
36
|
+
function createFilterOptionsStore(options = {}) {
|
|
37
|
+
const defaultTtl = options.ttl ?? DEFAULT_OPTIONS_TTL;
|
|
38
|
+
const dropUnused = options.dropUnused ?? false;
|
|
39
|
+
const now = options.now ?? Date.now;
|
|
40
|
+
const entries = shallowReactive({});
|
|
41
|
+
const running = /* @__PURE__ */ new Map();
|
|
42
|
+
let lastToken = 0;
|
|
43
|
+
function ensureEntry(source, params) {
|
|
44
|
+
const key = getOptionsKey(source, params);
|
|
45
|
+
const existing = entries[key];
|
|
46
|
+
if (existing) {
|
|
47
|
+
return existing;
|
|
48
|
+
}
|
|
49
|
+
const entry = shallowReactive({
|
|
50
|
+
key,
|
|
51
|
+
sourceId: source.id,
|
|
52
|
+
params,
|
|
53
|
+
data: [],
|
|
54
|
+
loading: false,
|
|
55
|
+
loaded: false,
|
|
56
|
+
error: void 0,
|
|
57
|
+
deniedReason: void 0,
|
|
58
|
+
loadedAt: void 0,
|
|
59
|
+
users: 0
|
|
60
|
+
});
|
|
61
|
+
entries[key] = entry;
|
|
62
|
+
return entry;
|
|
63
|
+
}
|
|
64
|
+
function isFresh(entry, source) {
|
|
65
|
+
return entry.loadedAt !== void 0 && now() - entry.loadedAt < (source.ttl ?? defaultTtl);
|
|
66
|
+
}
|
|
67
|
+
function load(source, params) {
|
|
68
|
+
const entry = ensureEntry(source, params);
|
|
69
|
+
const key = entry.key;
|
|
70
|
+
lastToken += 1;
|
|
71
|
+
const token = lastToken;
|
|
72
|
+
const isCurrent = () => {
|
|
73
|
+
var _a;
|
|
74
|
+
return ((_a = running.get(key)) == null ? void 0 : _a.token) === token;
|
|
75
|
+
};
|
|
76
|
+
entry.loading = true;
|
|
77
|
+
entry.error = void 0;
|
|
78
|
+
const promise = source.load(params).then(
|
|
79
|
+
(data) => {
|
|
80
|
+
if (isCurrent()) {
|
|
81
|
+
entry.data = data;
|
|
82
|
+
entry.loaded = true;
|
|
83
|
+
entry.deniedReason = void 0;
|
|
84
|
+
entry.loadedAt = now();
|
|
85
|
+
}
|
|
86
|
+
return data;
|
|
87
|
+
},
|
|
88
|
+
(error) => {
|
|
89
|
+
if (isCurrent()) {
|
|
90
|
+
entry.error = error;
|
|
91
|
+
const reason = getDeniedReason(error);
|
|
92
|
+
if (reason !== void 0) {
|
|
93
|
+
entry.data = [];
|
|
94
|
+
entry.deniedReason = reason;
|
|
95
|
+
entry.loadedAt = now();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
).finally(() => {
|
|
101
|
+
if (isCurrent()) {
|
|
102
|
+
entry.loading = false;
|
|
103
|
+
running.delete(key);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
running.set(key, {
|
|
107
|
+
token,
|
|
108
|
+
promise
|
|
109
|
+
});
|
|
110
|
+
return promise;
|
|
111
|
+
}
|
|
112
|
+
function get(source, params = {}) {
|
|
113
|
+
const key = getOptionsKey(source, params);
|
|
114
|
+
const inFlight = running.get(key);
|
|
115
|
+
if (inFlight) {
|
|
116
|
+
return inFlight.promise;
|
|
117
|
+
}
|
|
118
|
+
const entry = entries[key];
|
|
119
|
+
if (entry && isFresh(entry, source)) {
|
|
120
|
+
return entry.deniedReason === void 0 ? Promise.resolve(entry.data) : Promise.reject(entry.error);
|
|
121
|
+
}
|
|
122
|
+
return load(source, params);
|
|
123
|
+
}
|
|
124
|
+
function refresh(source, params = {}) {
|
|
125
|
+
return load(source, params);
|
|
126
|
+
}
|
|
127
|
+
function peek(source, params = {}) {
|
|
128
|
+
return entries[getOptionsKey(source, params)];
|
|
129
|
+
}
|
|
130
|
+
function drop(key) {
|
|
131
|
+
running.delete(key);
|
|
132
|
+
delete entries[key];
|
|
133
|
+
}
|
|
134
|
+
function retain(source, params = {}) {
|
|
135
|
+
const entry = ensureEntry(source, params);
|
|
136
|
+
entry.users += 1;
|
|
137
|
+
let released = false;
|
|
138
|
+
return () => {
|
|
139
|
+
if (released) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
released = true;
|
|
143
|
+
const current = entries[entry.key];
|
|
144
|
+
if (current !== entry) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
entry.users -= 1;
|
|
148
|
+
if (entry.users <= 0 && dropUnused && entry.deniedReason === void 0) {
|
|
149
|
+
drop(entry.key);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function clear() {
|
|
154
|
+
Object.keys(entries).forEach(drop);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
entries,
|
|
158
|
+
get,
|
|
159
|
+
refresh,
|
|
160
|
+
peek,
|
|
161
|
+
retain,
|
|
162
|
+
clear
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function provideFilterOptionsStore(store) {
|
|
166
|
+
const provided = store ?? createFilterOptionsStore({ dropUnused: true });
|
|
167
|
+
provide(VcFilterOptionsStoreKey, provided);
|
|
168
|
+
return provided;
|
|
169
|
+
}
|
|
170
|
+
function useFilterOptionsStore() {
|
|
171
|
+
const injected = getCurrentInstance() ? inject(VcFilterOptionsStoreKey, void 0) : void 0;
|
|
172
|
+
return injected ?? createFilterOptionsStore({ dropUnused: true });
|
|
173
|
+
}
|
|
174
|
+
function useFilterOptions(source, params, options = {}) {
|
|
175
|
+
const store = useFilterOptionsStore();
|
|
176
|
+
const currentSource = computed(() => {
|
|
177
|
+
const value = toValue(source);
|
|
178
|
+
return value === void 0 || Array.isArray(value) ? void 0 : value;
|
|
179
|
+
});
|
|
180
|
+
const staticData = computed(() => {
|
|
181
|
+
const value = toValue(source);
|
|
182
|
+
return Array.isArray(value) ? value : [];
|
|
183
|
+
});
|
|
184
|
+
const currentParams = computed(() => toValue(params) ?? {});
|
|
185
|
+
const key = computed(() => currentSource.value ? getOptionsKey(currentSource.value, currentParams.value) : void 0);
|
|
186
|
+
const entry = computed(() => key.value === void 0 ? void 0 : store.entries[key.value]);
|
|
187
|
+
function run(action) {
|
|
188
|
+
const active = currentSource.value;
|
|
189
|
+
if (!active) {
|
|
190
|
+
return Promise.resolve(staticData.value);
|
|
191
|
+
}
|
|
192
|
+
return store[action](active, currentParams.value).catch(() => []);
|
|
193
|
+
}
|
|
194
|
+
watch(key, (_key, _previous, onCleanup) => {
|
|
195
|
+
const active = currentSource.value;
|
|
196
|
+
if (!active) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
onCleanup(store.retain(active, currentParams.value));
|
|
200
|
+
if (options.immediate) {
|
|
201
|
+
void run("get");
|
|
202
|
+
}
|
|
203
|
+
}, { immediate: true });
|
|
204
|
+
return {
|
|
205
|
+
data: computed(() => {
|
|
206
|
+
var _a;
|
|
207
|
+
return currentSource.value ? ((_a = entry.value) == null ? void 0 : _a.data) ?? [] : staticData.value;
|
|
208
|
+
}),
|
|
209
|
+
loading: computed(() => {
|
|
210
|
+
var _a;
|
|
211
|
+
return ((_a = entry.value) == null ? void 0 : _a.loading) ?? false;
|
|
212
|
+
}),
|
|
213
|
+
loaded: computed(() => {
|
|
214
|
+
var _a;
|
|
215
|
+
return currentSource.value ? ((_a = entry.value) == null ? void 0 : _a.loaded) ?? false : true;
|
|
216
|
+
}),
|
|
217
|
+
error: computed(() => {
|
|
218
|
+
var _a;
|
|
219
|
+
return (_a = entry.value) == null ? void 0 : _a.error;
|
|
220
|
+
}),
|
|
221
|
+
deniedReason: computed(() => {
|
|
222
|
+
var _a;
|
|
223
|
+
return (_a = entry.value) == null ? void 0 : _a.deniedReason;
|
|
224
|
+
}),
|
|
225
|
+
get: () => run("get"),
|
|
226
|
+
refresh: () => run("refresh")
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function useFieldOptions(field, options = {}) {
|
|
230
|
+
const fieldValue = computed(() => toValue(field));
|
|
231
|
+
return useFilterOptions(
|
|
232
|
+
() => fieldValue.value.kind === "multiselect" || fieldValue.value.kind === "select" ? fieldValue.value.options : void 0,
|
|
233
|
+
() => {
|
|
234
|
+
const current = fieldValue.value;
|
|
235
|
+
if (current.kind !== "multiselect" && current.kind !== "select") {
|
|
236
|
+
return void 0;
|
|
237
|
+
}
|
|
238
|
+
return typeof current.optionsParams === "function" ? current.optionsParams() : current.optionsParams;
|
|
239
|
+
},
|
|
240
|
+
options
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
export {
|
|
244
|
+
DEFAULT_OPTIONS_TTL,
|
|
245
|
+
VcFilterOptionsDeniedError,
|
|
246
|
+
createFilterOptionsStore,
|
|
247
|
+
getDeniedReason,
|
|
248
|
+
getOptionsKey,
|
|
249
|
+
provideFilterOptionsStore,
|
|
250
|
+
useFieldOptions,
|
|
251
|
+
useFilterOptions,
|
|
252
|
+
useFilterOptionsStore
|
|
253
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { addFieldValue, isEmptyFilterValue } from "./filterBarModel.mjs";
|
|
2
|
+
const DEFAULT_SEARCH_DEBOUNCE = 400;
|
|
3
|
+
function getSearchTarget(text, config, picked) {
|
|
4
|
+
const trimmed = text.trim();
|
|
5
|
+
if (!trimmed || config.local) {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
8
|
+
const chosen = picked ? config.targets.find((target) => target.valueKey === picked) : void 0;
|
|
9
|
+
return chosen ?? config.targets.find((target) => !target.match || target.match(trimmed));
|
|
10
|
+
}
|
|
11
|
+
function setTargets(config) {
|
|
12
|
+
return config.targets.filter((target) => (target.mode ?? "set") === "set");
|
|
13
|
+
}
|
|
14
|
+
function readSearchText(model, config) {
|
|
15
|
+
for (const target of setTargets(config)) {
|
|
16
|
+
const value = model[target.valueKey];
|
|
17
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
function getSearchKeys(config) {
|
|
24
|
+
if (config.local) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
return setTargets(config).flatMap((target) => target.linked ? [target.valueKey, target.linked.valueKey] : [target.valueKey]);
|
|
28
|
+
}
|
|
29
|
+
function readLinkedValue(model, linked) {
|
|
30
|
+
const value = model[linked.valueKey];
|
|
31
|
+
return typeof value === "string" || typeof value === "number" ? value : linked.default;
|
|
32
|
+
}
|
|
33
|
+
function withLinked(model, linked, value) {
|
|
34
|
+
const next = { ...model };
|
|
35
|
+
if (linked.omitDefault && value === linked.default) {
|
|
36
|
+
delete next[linked.valueKey];
|
|
37
|
+
} else {
|
|
38
|
+
next[linked.valueKey] = value;
|
|
39
|
+
}
|
|
40
|
+
return next;
|
|
41
|
+
}
|
|
42
|
+
function writeLinkedValue(model, target, value) {
|
|
43
|
+
if (!target.linked || isEmptyFilterValue(model[target.valueKey])) {
|
|
44
|
+
return model;
|
|
45
|
+
}
|
|
46
|
+
return withLinked(model, target.linked, value);
|
|
47
|
+
}
|
|
48
|
+
function writeSearchText(model, text, config, picked) {
|
|
49
|
+
var _a;
|
|
50
|
+
const previous = getSearchTarget(readSearchText(model, config), config);
|
|
51
|
+
const keptLinked = (previous == null ? void 0 : previous.linked) ? readLinkedValue(model, previous.linked) : void 0;
|
|
52
|
+
let next = { ...model };
|
|
53
|
+
getSearchKeys(config).forEach((key) => {
|
|
54
|
+
delete next[key];
|
|
55
|
+
});
|
|
56
|
+
const target = getSearchTarget(text, config, picked);
|
|
57
|
+
if (!target || (target.mode ?? "set") !== "set") {
|
|
58
|
+
return next;
|
|
59
|
+
}
|
|
60
|
+
const trimmed = text.trim();
|
|
61
|
+
next[target.valueKey] = target.normalize ? target.normalize(trimmed) : trimmed;
|
|
62
|
+
if (target.linked) {
|
|
63
|
+
const linkedValue = ((_a = previous == null ? void 0 : previous.linked) == null ? void 0 : _a.valueKey) === target.linked.valueKey && keptLinked !== void 0 ? keptLinked : target.linked.default;
|
|
64
|
+
next = withLinked(next, target.linked, linkedValue);
|
|
65
|
+
}
|
|
66
|
+
return next;
|
|
67
|
+
}
|
|
68
|
+
function appendSearchText(model, text, config, fields, options, picked) {
|
|
69
|
+
const target = getSearchTarget(text, config, picked);
|
|
70
|
+
if (!target || target.mode !== "append") {
|
|
71
|
+
return model;
|
|
72
|
+
}
|
|
73
|
+
const field = fields.find((item) => item.key === target.valueKey);
|
|
74
|
+
if (!field) {
|
|
75
|
+
return model;
|
|
76
|
+
}
|
|
77
|
+
const trimmed = text.trim();
|
|
78
|
+
return addFieldValue(model, field, "include", [target.normalize ? target.normalize(trimmed) : trimmed], options);
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
DEFAULT_SEARCH_DEBOUNCE,
|
|
82
|
+
appendSearchText,
|
|
83
|
+
getSearchKeys,
|
|
84
|
+
getSearchTarget,
|
|
85
|
+
readLinkedValue,
|
|
86
|
+
readSearchText,
|
|
87
|
+
writeLinkedValue,
|
|
88
|
+
writeSearchText
|
|
89
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { isEmptyFilterValue, isFilterRangeValue, isFilterListValue } from "./filterBarModel.mjs";
|
|
2
|
+
function isCustomValue(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function lengthProblem(text, minLength, maxLength, pattern) {
|
|
6
|
+
if (minLength !== void 0 && text.length < minLength) {
|
|
7
|
+
return {
|
|
8
|
+
code: "tooShort",
|
|
9
|
+
count: minLength
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (maxLength !== void 0 && text.length > maxLength) {
|
|
13
|
+
return {
|
|
14
|
+
code: "tooLong",
|
|
15
|
+
count: maxLength
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (pattern && !new RegExp(pattern.source, pattern.flags.replace("g", "")).test(text)) {
|
|
19
|
+
return { code: "pattern" };
|
|
20
|
+
}
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
function validateFieldValue(field, value, applied = []) {
|
|
24
|
+
if (value === void 0 || isEmptyFilterValue(value)) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
switch (field.kind) {
|
|
28
|
+
case "text":
|
|
29
|
+
return typeof value === "string" ? lengthProblem(value.trim(), field.minLength, field.maxLength, field.pattern) : void 0;
|
|
30
|
+
case "multiselect":
|
|
31
|
+
case "textList": {
|
|
32
|
+
if (!isFilterListValue(value)) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
const total = (/* @__PURE__ */ new Set([...applied, ...value])).size;
|
|
36
|
+
if (field.maxValues !== void 0 && total > field.maxValues) {
|
|
37
|
+
return {
|
|
38
|
+
code: "tooMany",
|
|
39
|
+
count: field.maxValues
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (field.kind === "textList" && field.pattern) {
|
|
43
|
+
const pattern = field.pattern;
|
|
44
|
+
const wrong = value.some((item) => lengthProblem(String(item), void 0, void 0, pattern));
|
|
45
|
+
return wrong ? { code: "pattern" } : void 0;
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
case "range": {
|
|
50
|
+
if (!isFilterRangeValue(value)) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const bounds = [value.from, value.to].filter((bound) => bound !== null);
|
|
54
|
+
const { min, max } = field;
|
|
55
|
+
if (min !== void 0 && bounds.some((bound) => bound < min)) {
|
|
56
|
+
return {
|
|
57
|
+
code: "belowMin",
|
|
58
|
+
count: min
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (max !== void 0 && bounds.some((bound) => bound > max)) {
|
|
62
|
+
return {
|
|
63
|
+
code: "aboveMax",
|
|
64
|
+
count: max
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return value.from !== null && value.to !== null && value.from > value.to ? { code: "rangeOrder" } : void 0;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function canAddFieldValue(field, value, applied = []) {
|
|
74
|
+
if (value === void 0 || isEmptyFilterValue(value)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (field.kind === "custom" && isCustomValue(value)) {
|
|
78
|
+
const isEmpty = field.isEmpty ?? ((custom) => Object.values(custom).every(isEmptyFilterValue));
|
|
79
|
+
if (isEmpty(value)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return validateFieldValue(field, value, applied) === void 0;
|
|
84
|
+
}
|
|
85
|
+
function getProblemMessage(problem) {
|
|
86
|
+
const key = `voicenterUi.filterBar.problem.${problem.code}`;
|
|
87
|
+
return "count" in problem ? {
|
|
88
|
+
key,
|
|
89
|
+
params: { count: problem.count }
|
|
90
|
+
} : {
|
|
91
|
+
key,
|
|
92
|
+
params: {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
canAddFieldValue,
|
|
97
|
+
getProblemMessage,
|
|
98
|
+
validateFieldValue
|
|
99
|
+
};
|