@zeyos/zx 5.6.0 → 5.7.1
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/CHANGELOG.md +188 -0
- package/README.md +73 -7
- package/bin/zx-css.js +328 -0
- package/dist/types/components/account-menu/account-menu.d.ts +4 -2
- package/dist/types/components/activity-list/activity-list.d.ts +14 -8
- package/dist/types/components/agent-thread/ag-ui.d.ts +340 -0
- package/dist/types/components/agent-thread/agent-thread.d.ts +142 -14
- package/dist/types/components/agent-thread/ui-message-stream.d.ts +401 -0
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +14 -8
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +3 -3
- package/dist/types/components/calendar/calendar-model.d.ts +9 -2
- package/dist/types/components/calendar/calendar.d.ts +12 -4
- package/dist/types/components/chart/chart.d.ts +25 -13
- package/dist/types/components/checklist/checklist.d.ts +29 -0
- package/dist/types/components/code-editor/code-editor.d.ts +7 -2
- package/dist/types/components/composer/composer.d.ts +206 -4
- package/dist/types/components/composer/queue.d.ts +76 -0
- package/dist/types/components/copy/copy-button.d.ts +6 -4
- package/dist/types/components/copy/copy-input.d.ts +10 -6
- package/dist/types/components/datebox/date-range-box.d.ts +33 -0
- package/dist/types/components/datebox/placeholder.d.ts +7 -0
- package/dist/types/components/dialog/dialog.d.ts +2 -2
- package/dist/types/components/dock/dock.d.ts +12 -3
- package/dist/types/components/entity-ref/entity-ref.d.ts +5 -3
- package/dist/types/components/field-upload/field-upload.d.ts +3 -2
- package/dist/types/components/file-item/file-item.d.ts +3 -2
- package/dist/types/components/file-list/file-list.d.ts +14 -8
- package/dist/types/components/filter/filter-model.d.ts +31 -1
- package/dist/types/components/filter/filter.d.ts +20 -2
- package/dist/types/components/finder/finder.d.ts +14 -6
- package/dist/types/components/flag/flag.d.ts +99 -0
- package/dist/types/components/grid/grid.d.ts +1 -1
- package/dist/types/components/kanban-view/kanban-view.d.ts +8 -66
- package/dist/types/components/launcher/launcher.d.ts +2 -0
- package/dist/types/components/modal/modal.d.ts +34 -8
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +3 -2
- package/dist/types/components/number-field/number-field.d.ts +41 -7
- package/dist/types/components/prompt-starters/prompt-starters.d.ts +107 -0
- package/dist/types/components/prose/prose.d.ts +9 -6
- package/dist/types/components/questionnaire/conditions.d.ts +270 -0
- package/dist/types/components/questionnaire/items.d.ts +52 -30
- package/dist/types/components/questionnaire/questionnaire.d.ts +44 -4
- package/dist/types/components/rating/rating.d.ts +5 -3
- package/dist/types/components/select/country.d.ts +106 -0
- package/dist/types/components/select/field-adapter.d.ts +2 -1
- package/dist/types/components/select/locale.d.ts +102 -0
- package/dist/types/components/select/select.d.ts +41 -2
- package/dist/types/components/sheet/sheet.d.ts +2 -2
- package/dist/types/components/slider/slider.d.ts +1 -0
- package/dist/types/components/sort-control/sort-control.d.ts +7 -3
- package/dist/types/components/source-list/source-list.d.ts +7 -5
- package/dist/types/components/split-view/split-view.d.ts +5 -3
- package/dist/types/components/surface/catalog.d.ts +260 -0
- package/dist/types/components/surface/elicit.d.ts +81 -0
- package/dist/types/components/surface/mcp.d.ts +165 -0
- package/dist/types/components/surface/schema.d.ts +314 -0
- package/dist/types/components/surface/stream.d.ts +118 -0
- package/dist/types/components/surface/surface.d.ts +718 -0
- package/dist/types/components/surface/text.d.ts +277 -0
- package/dist/types/components/surface/validate.d.ts +339 -0
- package/dist/types/components/table/table.d.ts +55 -3
- package/dist/types/components/table/window.d.ts +203 -0
- package/dist/types/components/toolbar/toolbar.d.ts +10 -6
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/components/tree/tree.d.ts +20 -13
- package/dist/types/core/component.d.ts +10 -0
- package/dist/types/core/date.d.ts +8 -1
- package/dist/types/core/dom.d.ts +15 -0
- package/dist/types/core/http.d.ts +10 -0
- package/dist/types/core/i18n.d.ts +38 -0
- package/dist/types/core/messages.d.ts +344 -1
- package/dist/types/core/storage.d.ts +7 -2
- package/dist/types/elements/define.d.ts +21 -46
- package/dist/types/elements/definitions.d.ts +147 -0
- package/dist/types/elements/kit.d.ts +7 -0
- package/dist/types/elements/reflect.d.ts +6 -3
- package/dist/types/index.d.ts +10 -1
- package/dist/types/internal/date-locale.d.ts +7 -0
- package/dist/types/internal/json-patch.d.ts +146 -0
- package/dist/types/locales/de.d.ts +13 -0
- package/dist/types/locales/en.d.ts +2 -0
- package/dist/types/locales/index.d.ts +823 -0
- package/dist/types/zeyos/view.d.ts +8 -1
- package/dist/zx-zeyos.esm.js +16852 -15131
- package/dist/zx-zeyos.esm.min.js +5 -5
- package/dist/zx.core.css +1276 -0
- package/dist/zx.core.min.css +1 -0
- package/dist/zx.css +520 -143
- package/dist/zx.esm.js +40940 -29684
- package/dist/zx.esm.min.js +36 -23
- package/dist/zx.global.js +40940 -29684
- package/dist/zx.global.min.js +36 -23
- package/dist/zx.layered.css +17315 -0
- package/dist/zx.layered.min.css +1 -0
- package/dist/zx.min.css +1 -1
- package/docs/agent-catalog.json +12501 -0
- package/docs/agent-surfaces.md +340 -0
- package/docs/api.json +909 -137
- package/docs/llms.md +1046 -80
- package/docs/llms.txt +30 -9
- package/package.json +29 -6
- package/src/components/account-menu/account-menu.js +6 -3
- package/src/components/activity-item/activity-item.js +2 -1
- package/src/components/activity-list/activity-list.js +16 -10
- package/src/components/agent-thread/ag-ui.js +1439 -0
- package/src/components/agent-thread/agent-thread.js +359 -54
- package/src/components/agent-thread/ui-message-stream.js +1281 -0
- package/src/components/app-sidebar/app-sidebar.js +18 -8
- package/src/components/approval-card/approval-card.js +3 -2
- package/src/components/block-view/block-view.js +7 -6
- package/src/components/breadcrumb/breadcrumb.js +8 -5
- package/src/components/button/button.css +24 -11
- package/src/components/calendar/calendar-model.js +8 -2
- package/src/components/calendar/calendar.js +53 -18
- package/src/components/chart/chart.js +54 -23
- package/src/components/checklist/checklist.css +9 -1
- package/src/components/checklist/checklist.js +59 -3
- package/src/components/checklist/field-adapter.js +2 -11
- package/src/components/code-editor/code-editor.js +45 -8
- package/src/components/code-editor/field-adapter.js +1 -1
- package/src/components/composer/composer.css +80 -1
- package/src/components/composer/composer.js +390 -16
- package/src/components/composer/queue.js +78 -0
- package/src/components/context-menu/context-menu.js +12 -1
- package/src/components/copy/copy-button.js +9 -7
- package/src/components/copy/copy-input.js +10 -6
- package/src/components/date-picker/date-picker.js +2 -1
- package/src/components/date-picker/date-range-picker.js +8 -7
- package/src/components/datebox/date-range-box.js +3 -9
- package/src/components/datebox/datebox.js +18 -21
- package/src/components/datebox/placeholder.js +18 -0
- package/src/components/dialog/dialog.js +4 -5
- package/src/components/dock/dock.js +34 -13
- package/src/components/entity-ref/entity-ref.js +16 -5
- package/src/components/field-upload/field-upload.js +81 -38
- package/src/components/file-item/file-item.js +70 -40
- package/src/components/file-list/file-list.js +15 -9
- package/src/components/filter/filter-model.js +46 -8
- package/src/components/filter/filter.css +3 -3
- package/src/components/filter/filter.js +29 -10
- package/src/components/filter-panel/filter-panel.js +13 -5
- package/src/components/finder/finder.js +50 -26
- package/src/components/flag/flag.css +40 -0
- package/src/components/flag/flag.js +177 -0
- package/src/components/form/form.js +1 -1
- package/src/components/grid/grid.js +22 -8
- package/src/components/kanban-view/kanban-view.js +51 -81
- package/src/components/launcher/launcher.js +17 -2
- package/src/components/list-toolbar/list-toolbar.js +2 -1
- package/src/components/master-panel/master-panel.js +1 -1
- package/src/components/menu-button/menu-button.js +4 -0
- package/src/components/message/message.js +3 -0
- package/src/components/modal/modal.js +62 -8
- package/src/components/multi-value-editor/multi-value-editor.js +10 -9
- package/src/components/navigation-bar/navigation-bar.js +3 -3
- package/src/components/number-field/number-field.js +98 -29
- package/src/components/prompt-starters/prompt-starters.css +91 -0
- package/src/components/prompt-starters/prompt-starters.js +206 -0
- package/src/components/prose/prose.js +14 -10
- package/src/components/questionnaire/conditions.js +666 -0
- package/src/components/questionnaire/items.js +150 -41
- package/src/components/questionnaire/questionnaire.js +126 -32
- package/src/components/rating/rating.js +5 -4
- package/src/components/run-status/run-status.js +2 -2
- package/src/components/select/country.js +136 -0
- package/src/components/select/field-adapter.js +7 -2
- package/src/components/select/locale.js +219 -0
- package/src/components/select/select.css +20 -22
- package/src/components/select/select.js +94 -12
- package/src/components/sheet/sheet-stack.js +10 -1
- package/src/components/sheet/sheet.js +12 -5
- package/src/components/slider/slider.js +7 -2
- package/src/components/sort-control/sort-control.js +15 -5
- package/src/components/source-list/source-list.js +7 -4
- package/src/components/split-view/split-view.js +5 -3
- package/src/components/surface/catalog.js +1334 -0
- package/src/components/surface/elicit.js +107 -0
- package/src/components/surface/mcp.js +243 -0
- package/src/components/surface/schema.js +644 -0
- package/src/components/surface/stream.js +245 -0
- package/src/components/surface/surface.css +308 -0
- package/src/components/surface/surface.js +2291 -0
- package/src/components/surface/text.js +513 -0
- package/src/components/surface/validate.js +2218 -0
- package/src/components/tabbox/tabbox.js +9 -0
- package/src/components/table/table.css +63 -3
- package/src/components/table/table.js +167 -28
- package/src/components/table/window.js +317 -0
- package/src/components/toolbar/toolbar.js +12 -7
- package/src/components/tooltip/tooltip.css +2 -3
- package/src/components/tooltip/tooltip.js +32 -5
- package/src/components/tree/tree.js +53 -23
- package/src/core/component.js +25 -1
- package/src/core/date.js +62 -16
- package/src/core/dom.js +67 -4
- package/src/core/format.js +15 -13
- package/src/core/http.js +29 -20
- package/src/core/i18n.js +83 -10
- package/src/core/icons.js +13 -2
- package/src/core/keyboard.js +79 -8
- package/src/core/messages.js +376 -2
- package/src/core/overlay-host.js +1 -0
- package/src/core/position.js +3 -2
- package/src/core/storage.js +59 -6
- package/src/elements/define.js +178 -130
- package/src/elements/definitions.js +229 -0
- package/src/elements/kit.js +444 -0
- package/src/elements/reflect.js +8 -3
- package/src/index.js +10 -1
- package/src/internal/date-locale.js +11 -0
- package/src/internal/json-patch.js +405 -0
- package/src/locales/de.js +911 -0
- package/src/locales/en.js +2 -0
- package/src/locales/index.js +7 -0
- package/src/zeyos/calendar.js +2 -1
- package/src/zeyos/form.js +2 -1
- package/src/zeyos/launcher.js +7 -6
- package/src/zeyos/module-bar.js +2 -1
- package/src/zeyos/schema.js +37 -23
- package/src/zeyos/select.js +4 -3
- package/src/zeyos/table.js +2 -13
- package/src/zeyos/view.js +57 -17
- package/styles/core.css +11 -0
- package/styles/tokens/semantic.css +1 -0
- package/styles/zeyos.css +2 -0
- package/styles/zx.css +4 -8
- package/styles/zx.layered.css +1 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component } from '../../core/component.js';
|
|
2
2
|
import { h } from '../../core/dom.js';
|
|
3
3
|
import { uid } from '../../core/util.js';
|
|
4
|
+
import { Http, parseResult } from '../../core/http.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {Object} UploadTransport
|
|
@@ -91,22 +92,22 @@ export class FieldUpload extends Component {
|
|
|
91
92
|
class: 'zx-field-upload__dropzone',
|
|
92
93
|
type: 'button',
|
|
93
94
|
ariaControls: inputId,
|
|
94
|
-
ariaLabel: this.options.multiple ? '
|
|
95
|
+
ariaLabel: this.msg(this.options.multiple ? 'fieldUpload.chooseMany' : 'fieldUpload.choose')
|
|
95
96
|
},
|
|
96
|
-
h('span', { class: 'zx-field-upload__prompt' }, this.options.multiple ? '
|
|
97
|
-
h('span', { class: 'zx-field-upload__hint' }, uploadHint(this
|
|
97
|
+
h('span', { class: 'zx-field-upload__prompt' }, this.msg(this.options.multiple ? 'fieldUpload.dropMany' : 'fieldUpload.drop')),
|
|
98
|
+
h('span', { class: 'zx-field-upload__hint' }, uploadHint(this)));
|
|
98
99
|
this._preview = h('div', { class: 'zx-field-upload__preview' });
|
|
99
100
|
this._progress = h('progress', {
|
|
100
101
|
class: 'zx-field-upload__progress',
|
|
101
102
|
max: 100,
|
|
102
103
|
value: 0,
|
|
103
|
-
ariaLabel: '
|
|
104
|
+
ariaLabel: this.msg('fieldUpload.progress')
|
|
104
105
|
});
|
|
105
106
|
this._progressText = h('span', { class: 'zx-field-upload__progress-text' }, '0%');
|
|
106
107
|
this._abort = h('button', {
|
|
107
108
|
class: 'zx-btn zx-field-upload__abort',
|
|
108
109
|
type: 'button'
|
|
109
|
-
}, '
|
|
110
|
+
}, this.msg('fieldUpload.abort'));
|
|
110
111
|
this._progressWrap = h('div', {
|
|
111
112
|
class: 'zx-field-upload__progress-wrap',
|
|
112
113
|
hidden: true
|
|
@@ -154,7 +155,7 @@ export class FieldUpload extends Component {
|
|
|
154
155
|
this._progressWrap.hidden = false;
|
|
155
156
|
this._abort.hidden = false;
|
|
156
157
|
this._setProgress(0);
|
|
157
|
-
this._status.textContent = '
|
|
158
|
+
this._status.textContent = this.msg('fieldUpload.uploading');
|
|
158
159
|
|
|
159
160
|
try {
|
|
160
161
|
const response = this.options.http ? await this._uploadInjected() : await this._uploadXhr();
|
|
@@ -165,7 +166,7 @@ export class FieldUpload extends Component {
|
|
|
165
166
|
this._abort.hidden = true;
|
|
166
167
|
this._setProgress(100);
|
|
167
168
|
this._setState('success');
|
|
168
|
-
this._status.textContent = '
|
|
169
|
+
this._status.textContent = this.msg('fieldUpload.complete');
|
|
169
170
|
this.emit('success', { response });
|
|
170
171
|
return response;
|
|
171
172
|
} catch (caught) {
|
|
@@ -245,12 +246,12 @@ export class FieldUpload extends Component {
|
|
|
245
246
|
if (normalized.length === 0) return false;
|
|
246
247
|
const invalid = normalized.find((file) => !matchesAccept(file, this.options.accept));
|
|
247
248
|
if (invalid) {
|
|
248
|
-
this._selectionError(new Error(
|
|
249
|
+
this._selectionError(new Error(this.msg('fieldUpload.rejectedType', invalid.name)));
|
|
249
250
|
return false;
|
|
250
251
|
}
|
|
251
252
|
const oversized = this.options.maxSize == null ? null : normalized.find((file) => file.size > Number(this.options.maxSize));
|
|
252
253
|
if (oversized) {
|
|
253
|
-
this._selectionError(new Error(
|
|
254
|
+
this._selectionError(new Error(this.msg('fieldUpload.rejectedSize', oversized.name)));
|
|
254
255
|
return false;
|
|
255
256
|
}
|
|
256
257
|
this._files = normalized;
|
|
@@ -270,14 +271,19 @@ export class FieldUpload extends Component {
|
|
|
270
271
|
/** @returns {Promise<unknown>} */
|
|
271
272
|
_uploadInjected() {
|
|
272
273
|
const transport = this.options.http;
|
|
274
|
+
if (transport instanceof Http && transport.request === Http.prototype.request
|
|
275
|
+
&& typeof transport.upload !== 'function') return this._uploadXhr(transport);
|
|
273
276
|
this._transportController = new AbortController();
|
|
277
|
+
const runId = this._runId;
|
|
274
278
|
const uploadOptions = {
|
|
275
279
|
files: this._files.slice(),
|
|
276
280
|
paramName: String(this.options.paramName),
|
|
277
281
|
params: { ...this.options.params },
|
|
278
282
|
headers: { ...this.options.headers },
|
|
279
283
|
signal: this._transportController.signal,
|
|
280
|
-
onProgress: (percent) =>
|
|
284
|
+
onProgress: (percent) => {
|
|
285
|
+
if (this._running && runId === this._runId) this._setProgress(percent);
|
|
286
|
+
}
|
|
281
287
|
};
|
|
282
288
|
if (typeof transport.upload === 'function') return transport.upload(String(this.options.url), uploadOptions);
|
|
283
289
|
if (typeof transport.request === 'function') {
|
|
@@ -294,28 +300,64 @@ export class FieldUpload extends Component {
|
|
|
294
300
|
return Promise.reject(new TypeError('Injected upload transport requires upload() or request()'));
|
|
295
301
|
}
|
|
296
302
|
|
|
297
|
-
/** @returns {Promise<unknown>} */
|
|
298
|
-
_uploadXhr() {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
303
|
+
/** @param {Http|null} [http=null] Optional client defaults. @returns {Promise<unknown>} */
|
|
304
|
+
async _uploadXhr(http = null) {
|
|
305
|
+
const path = String(this.options.url);
|
|
306
|
+
const options = {
|
|
307
|
+
method: 'POST', data: this.options.params, files: this._files.slice(),
|
|
308
|
+
headers: this.options.headers, paramName: String(this.options.paramName)
|
|
309
|
+
};
|
|
310
|
+
const runId = this._runId;
|
|
311
|
+
const cleanups = [];
|
|
312
|
+
const listen = (target, type, handler) => {
|
|
313
|
+
this.listen(target, type, handler);
|
|
314
|
+
cleanups.push(() => target.removeEventListener(type, handler));
|
|
315
|
+
};
|
|
316
|
+
try {
|
|
317
|
+
if (typeof XMLHttpRequest !== 'function') throw new Error('XMLHttpRequest is not available');
|
|
318
|
+
return await new Promise((resolve, reject) => {
|
|
319
|
+
const xhr = new XMLHttpRequest();
|
|
320
|
+
this._xhr = xhr;
|
|
321
|
+
xhr.open('POST', (http?.base ?? '') + path);
|
|
322
|
+
if (http) xhr.timeout = http.timeout > 0 ? http.timeout : 0;
|
|
323
|
+
const headers = new Headers(http?.headers);
|
|
324
|
+
for (const [name, value] of Object.entries(options.headers ?? {})) headers.set(name, String(value));
|
|
325
|
+
if (http && !headers.has('Accept')) headers.set('Accept', 'application/json');
|
|
326
|
+
headers.delete('Content-Type');
|
|
327
|
+
for (const [name, value] of headers) xhr.setRequestHeader(name, value);
|
|
328
|
+
listen(xhr.upload, 'progress', (event) => {
|
|
329
|
+
if (this._running && runId === this._runId && event.lengthComputable) {
|
|
330
|
+
this._setProgress((event.loaded / event.total) * 100);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
listen(xhr, 'load', () => {
|
|
334
|
+
try {
|
|
335
|
+
let response = parseResponse(xhr.responseText);
|
|
336
|
+
if (http) {
|
|
337
|
+
try { response = xhr.responseText ? JSON.parse(xhr.responseText) : null; }
|
|
338
|
+
catch (cause) { throw new Error('Invalid JSON response', { cause }); }
|
|
339
|
+
response = parseResult(response);
|
|
340
|
+
}
|
|
341
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
342
|
+
throw new Error(this.msg('fieldUpload.httpFailed', xhr.status));
|
|
343
|
+
}
|
|
344
|
+
resolve(response);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
error.response = xhr;
|
|
347
|
+
reject(error);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
listen(xhr, 'error', () => reject(new Error(this.msg('fieldUpload.requestFailed'))));
|
|
351
|
+
listen(xhr, 'abort', () => reject(abortError()));
|
|
352
|
+
listen(xhr, 'timeout', () => reject(new DOMException('Request timed out', 'TimeoutError')));
|
|
353
|
+
xhr.send(createFormData(options.files, options.paramName, options.data));
|
|
314
354
|
});
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
355
|
+
} catch (error) {
|
|
356
|
+
try { http?.onError?.(error, { path, options }); } catch { /* Preserve the transport failure. */ }
|
|
357
|
+
throw error;
|
|
358
|
+
} finally {
|
|
359
|
+
for (const cleanup of cleanups) cleanup();
|
|
360
|
+
}
|
|
319
361
|
}
|
|
320
362
|
|
|
321
363
|
/** @param {number} percent @returns {void} */
|
|
@@ -335,7 +377,7 @@ export class FieldUpload extends Component {
|
|
|
335
377
|
this._transportController = null;
|
|
336
378
|
this._abort.hidden = true;
|
|
337
379
|
this._setState('idle');
|
|
338
|
-
this._status.textContent = '
|
|
380
|
+
this._status.textContent = this.msg('fieldUpload.aborted');
|
|
339
381
|
this.emit('abort', {});
|
|
340
382
|
}
|
|
341
383
|
|
|
@@ -356,7 +398,7 @@ export class FieldUpload extends Component {
|
|
|
356
398
|
this._preview.append(h('img', {
|
|
357
399
|
class: 'zx-field-upload__image',
|
|
358
400
|
src: this._previewUrl,
|
|
359
|
-
alt:
|
|
401
|
+
alt: this.msg('fieldUpload.preview', file.name)
|
|
360
402
|
}));
|
|
361
403
|
}
|
|
362
404
|
|
|
@@ -385,12 +427,13 @@ export class FieldUpload extends Component {
|
|
|
385
427
|
}
|
|
386
428
|
}
|
|
387
429
|
|
|
388
|
-
/** @param {
|
|
389
|
-
function uploadHint(
|
|
430
|
+
/** @param {FieldUpload} upload @returns {string} */
|
|
431
|
+
function uploadHint(upload) {
|
|
432
|
+
const { accept, maxSize } = upload.options;
|
|
390
433
|
const parts = [];
|
|
391
|
-
if (
|
|
392
|
-
if (
|
|
393
|
-
return parts.join(' · ') || '
|
|
434
|
+
if (accept) parts.push(String(accept));
|
|
435
|
+
if (maxSize != null) parts.push(upload.msg('fieldUpload.maxSize', formatBytes(Number(maxSize))));
|
|
436
|
+
return parts.join(' · ') || upload.msg('fieldUpload.hint');
|
|
394
437
|
}
|
|
395
438
|
|
|
396
439
|
/** @param {number} bytes @returns {string} */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Component } from '../../core/component.js';
|
|
3
3
|
import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
|
|
4
4
|
import { formatFileSize } from '../../core/format.js';
|
|
5
|
+
import { translate } from '../../core/i18n.js';
|
|
5
6
|
import { getIconConfig, iconNames } from '../../core/icons.js';
|
|
6
7
|
import { isElement } from '../../core/util.js';
|
|
7
8
|
import { badge } from '../badge/badge.js';
|
|
@@ -37,7 +38,8 @@ import {
|
|
|
37
38
|
* @property {boolean} [indeterminate=false] Whether active progress has no known amount.
|
|
38
39
|
* @property {'sm'|'md'|'lg'} [identitySize='md'] Size of the file's icon and name.
|
|
39
40
|
* @property {boolean} [wrap=false] Whether long identity text may wrap.
|
|
40
|
-
* @property {string} [actionsLabel=
|
|
41
|
+
* @property {string|null} [actionsLabel=null] Accessible name for secondary actions; null reads the
|
|
42
|
+
* `fileItem.actions` message ("File actions").
|
|
41
43
|
* @property {string} [locale] Locale passed to `formatFileSize`.
|
|
42
44
|
* @property {(event: CustomEvent<{id: unknown, file: Readonly<FileItemState>, href: string, event: MouseEvent}>) => void} [onactivate]
|
|
43
45
|
* Preventable native-link listener.
|
|
@@ -71,14 +73,15 @@ const FILE_STATUSES = new Set([
|
|
|
71
73
|
'ready', 'temporary', 'waiting', 'uploading', 'processing', 'success', 'error'
|
|
72
74
|
]);
|
|
73
75
|
|
|
76
|
+
/** The word each status shows. `ready` shows none. */
|
|
74
77
|
const STATUS_LABELS = Object.freeze({
|
|
75
|
-
ready:
|
|
76
|
-
temporary: 'Temporary',
|
|
77
|
-
waiting: 'Waiting',
|
|
78
|
-
uploading: 'Uploading',
|
|
79
|
-
processing: 'Processing',
|
|
80
|
-
success: 'Complete',
|
|
81
|
-
error: 'Failed'
|
|
78
|
+
ready: null,
|
|
79
|
+
temporary: { key: 'fileItem.status.temporary', label: 'Temporary' },
|
|
80
|
+
waiting: { key: 'fileItem.status.waiting', label: 'Waiting' },
|
|
81
|
+
uploading: { key: 'fileItem.status.uploading', label: 'Uploading' },
|
|
82
|
+
processing: { key: 'fileItem.status.processing', label: 'Processing' },
|
|
83
|
+
success: { key: 'fileItem.status.success', label: 'Complete' },
|
|
84
|
+
error: { key: 'fileItem.status.error', label: 'Failed' }
|
|
82
85
|
});
|
|
83
86
|
|
|
84
87
|
/**
|
|
@@ -109,7 +112,7 @@ export class FileItem extends Component {
|
|
|
109
112
|
indeterminate: false,
|
|
110
113
|
identitySize: 'md',
|
|
111
114
|
wrap: false,
|
|
112
|
-
actionsLabel:
|
|
115
|
+
actionsLabel: null
|
|
113
116
|
};
|
|
114
117
|
|
|
115
118
|
/**
|
|
@@ -128,7 +131,7 @@ export class FileItem extends Component {
|
|
|
128
131
|
this.el = root;
|
|
129
132
|
this._snapshot = this._createdRoot ? null : snapshotTarget(root);
|
|
130
133
|
this._destroyed = false;
|
|
131
|
-
this._state =
|
|
134
|
+
this._state = fileItemState(this.options, this.msg('fileItem.actions'));
|
|
132
135
|
|
|
133
136
|
const entityHost = h('div', { ref: 'entity', class: 'zx-file-item__entity' });
|
|
134
137
|
root.replaceChildren(
|
|
@@ -145,7 +148,7 @@ export class FileItem extends Component {
|
|
|
145
148
|
}, h('div', { ref: 'progressFill', class: 'zx-file-item__progress-fill' })))
|
|
146
149
|
);
|
|
147
150
|
|
|
148
|
-
this._entity = new EntityRef(entityHost, entityOptions(this._state));
|
|
151
|
+
this._entity = new EntityRef(entityHost, entityOptions(this._state, (key) => this.msg(key)));
|
|
149
152
|
this.listen(this._entity.el, 'zx-activate', (event) => this._forwardActivate(/** @type {CustomEvent} */ (event)));
|
|
150
153
|
this.listen(this._entity.el, 'zx-action', (event) => this._forwardAction(/** @type {CustomEvent} */ (event)));
|
|
151
154
|
this._sync();
|
|
@@ -159,7 +162,7 @@ export class FileItem extends Component {
|
|
|
159
162
|
*/
|
|
160
163
|
set(values = {}) {
|
|
161
164
|
if (!values || typeof values !== 'object' || Array.isArray(values)) return this;
|
|
162
|
-
this._state =
|
|
165
|
+
this._state = fileItemState({ ...this._state, ...values }, this.msg('fileItem.actions'));
|
|
163
166
|
this._sync();
|
|
164
167
|
return this;
|
|
165
168
|
}
|
|
@@ -215,9 +218,9 @@ export class FileItem extends Component {
|
|
|
215
218
|
const fill = /** @type {HTMLElement} */ (this.refs.progressFill);
|
|
216
219
|
root.dataset.status = state.status;
|
|
217
220
|
root.dataset.identitySize = state.identitySize;
|
|
218
|
-
this._entity.set(entityOptions(state));
|
|
221
|
+
this._entity.set(entityOptions(state, (key) => this.msg(key)));
|
|
219
222
|
|
|
220
|
-
const label = fileStatusLabel(state);
|
|
223
|
+
const label = fileStatusLabel(state, (key) => this.msg(key));
|
|
221
224
|
status.replaceChildren(...(label ? [badge({
|
|
222
225
|
label,
|
|
223
226
|
kind: statusKind(state.status),
|
|
@@ -231,10 +234,11 @@ export class FileItem extends Component {
|
|
|
231
234
|
progress.toggleAttribute('data-indeterminate', state.indeterminate);
|
|
232
235
|
if (!visible) return;
|
|
233
236
|
|
|
234
|
-
const
|
|
237
|
+
const progressName = label || this.msg('fileItem.progress');
|
|
238
|
+
const progressLabel = `${progressName}${state.indeterminate || state.progress === null
|
|
235
239
|
? '' : ` — ${Math.round(state.progress)}%`}`;
|
|
236
240
|
this.refs.progressHead.textContent = progressLabel;
|
|
237
|
-
track.setAttribute('aria-label', `${state.name || '
|
|
241
|
+
track.setAttribute('aria-label', `${state.name || this.msg('fileItem.file')}: ${progressName}`);
|
|
238
242
|
if (state.indeterminate) {
|
|
239
243
|
track.removeAttribute('aria-valuenow');
|
|
240
244
|
track.removeAttribute('aria-valuetext');
|
|
@@ -279,6 +283,15 @@ export class FileItem extends Component {
|
|
|
279
283
|
* @returns {FileItemState}
|
|
280
284
|
*/
|
|
281
285
|
export function normalizeFileItem(values = {}) {
|
|
286
|
+
return fileItemState(values, translate('fileItem.actions'));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {Partial<FileItemOptions>|null|undefined} values Candidate values.
|
|
291
|
+
* @param {string} actionsLabel Name of the secondary actions when the values give none.
|
|
292
|
+
* @returns {FileItemState}
|
|
293
|
+
*/
|
|
294
|
+
function fileItemState(values, actionsLabel) {
|
|
282
295
|
const source = values && typeof values === 'object' && !Array.isArray(values) ? values : {};
|
|
283
296
|
const rawSize = source.size == null || source.size === '' ? null : Number(source.size);
|
|
284
297
|
const rawProgress = source.progress == null ? null : Number(source.progress);
|
|
@@ -302,19 +315,23 @@ export function normalizeFileItem(values = {}) {
|
|
|
302
315
|
indeterminate: Boolean(source.indeterminate),
|
|
303
316
|
identitySize: source.identitySize === 'sm' || source.identitySize === 'lg' ? source.identitySize : 'md',
|
|
304
317
|
wrap: Boolean(source.wrap),
|
|
305
|
-
actionsLabel: String(source.actionsLabel ||
|
|
318
|
+
actionsLabel: String(source.actionsLabel || actionsLabel),
|
|
306
319
|
locale: normalizeLocale(source.locale)
|
|
307
320
|
};
|
|
308
321
|
}
|
|
309
322
|
|
|
310
|
-
/**
|
|
311
|
-
|
|
323
|
+
/**
|
|
324
|
+
* @param {FileItemState} state
|
|
325
|
+
* @param {(key: string) => string} text Resolves the metadata's names.
|
|
326
|
+
* @returns {import('../entity-ref/entity-ref.js').EntityRefOptions}
|
|
327
|
+
*/
|
|
328
|
+
function entityOptions(state, text) {
|
|
312
329
|
const metadata = [];
|
|
313
|
-
const type = state.typeLabel ??
|
|
314
|
-
if (type) metadata.push({ label: '
|
|
330
|
+
const type = state.typeLabel ?? typeLabel(state.mime, state.name, text);
|
|
331
|
+
if (type) metadata.push({ label: text('fileItem.type'), value: type, showLabel: false });
|
|
315
332
|
if (state.size !== null) {
|
|
316
333
|
metadata.push({
|
|
317
|
-
label: '
|
|
334
|
+
label: text('fileItem.size'),
|
|
318
335
|
value: formatFileSize(state.size, { locale: state.locale }),
|
|
319
336
|
showLabel: false
|
|
320
337
|
});
|
|
@@ -337,17 +354,18 @@ function entityOptions(state) {
|
|
|
337
354
|
/**
|
|
338
355
|
* What a MIME type is called and drawn as. Labels are what a reader recognises — a format's own
|
|
339
356
|
* acronym where it has a well-known one, the family otherwise — and icons are Font Awesome names
|
|
340
|
-
* in order of preference, used only when the active icon set can draw them.
|
|
341
|
-
*
|
|
357
|
+
* in order of preference, used only when the active icon set can draw them. A format's name is the
|
|
358
|
+
* same in every language; a family word has a `key` into the catalogue.
|
|
359
|
+
* @type {Readonly<Record<string, {key?: string, label: string, icons: string[]}>>}
|
|
342
360
|
*/
|
|
343
361
|
const FILE_KINDS = Object.freeze({
|
|
344
362
|
pdf: { label: 'PDF', icons: ['file-pdf'] },
|
|
345
363
|
csv: { label: 'CSV', icons: ['file-csv', 'file-excel'] },
|
|
346
364
|
tsv: { label: 'TSV', icons: ['file-csv', 'file-excel'] },
|
|
347
|
-
spreadsheet: { label: 'Spreadsheet', icons: ['file-excel'] },
|
|
348
|
-
document: { label: 'Document', icons: ['file-word', 'file-lines'] },
|
|
349
|
-
presentation: { label: 'Presentation', icons: ['file-powerpoint'] },
|
|
350
|
-
text: { label: 'Text', icons: ['file-lines'] },
|
|
365
|
+
spreadsheet: { key: 'fileItem.kind.spreadsheet', label: 'Spreadsheet', icons: ['file-excel'] },
|
|
366
|
+
document: { key: 'fileItem.kind.document', label: 'Document', icons: ['file-word', 'file-lines'] },
|
|
367
|
+
presentation: { key: 'fileItem.kind.presentation', label: 'Presentation', icons: ['file-powerpoint'] },
|
|
368
|
+
text: { key: 'fileItem.kind.text', label: 'Text', icons: ['file-lines'] },
|
|
351
369
|
markdown: { label: 'Markdown', icons: ['file-lines'] },
|
|
352
370
|
html: { label: 'HTML', icons: ['file-code', 'code'] },
|
|
353
371
|
css: { label: 'CSS', icons: ['file-code', 'code'] },
|
|
@@ -359,13 +377,13 @@ const FILE_KINDS = Object.freeze({
|
|
|
359
377
|
tar: { label: 'TAR', icons: ['file-zipper'] },
|
|
360
378
|
rar: { label: 'RAR', icons: ['file-zipper'] },
|
|
361
379
|
sevenZip: { label: '7Z', icons: ['file-zipper'] },
|
|
362
|
-
email: { label: 'Email', icons: ['envelope'] },
|
|
363
|
-
calendar: { label: 'Calendar', icons: ['calendar'] },
|
|
364
|
-
contact: { label: 'Contact', icons: ['address-card'] },
|
|
365
|
-
image: { label: 'Image', icons: ['file-image', 'image'] },
|
|
366
|
-
video: { label: 'Video', icons: ['file-video', 'video'] },
|
|
367
|
-
audio: { label: 'Audio', icons: ['file-audio'] },
|
|
368
|
-
font: { label: 'Font', icons: ['font'] }
|
|
380
|
+
email: { key: 'fileItem.kind.email', label: 'Email', icons: ['envelope'] },
|
|
381
|
+
calendar: { key: 'fileItem.kind.calendar', label: 'Calendar', icons: ['calendar'] },
|
|
382
|
+
contact: { key: 'fileItem.kind.contact', label: 'Contact', icons: ['address-card'] },
|
|
383
|
+
image: { key: 'fileItem.kind.image', label: 'Image', icons: ['file-image', 'image'] },
|
|
384
|
+
video: { key: 'fileItem.kind.video', label: 'Video', icons: ['file-video', 'video'] },
|
|
385
|
+
audio: { key: 'fileItem.kind.audio', label: 'Audio', icons: ['file-audio'] },
|
|
386
|
+
font: { key: 'fileItem.kind.font', label: 'Font', icons: ['font'] }
|
|
369
387
|
});
|
|
370
388
|
|
|
371
389
|
/** Exact MIME types, lower case and without parameters, mapped to their kind. */
|
|
@@ -419,7 +437,7 @@ const MIME_FAMILIES = new Map([
|
|
|
419
437
|
|
|
420
438
|
/**
|
|
421
439
|
* @param {string} mime MIME type, possibly with parameters.
|
|
422
|
-
* @returns {{label: string, icons: string[]}|null}
|
|
440
|
+
* @returns {{key?: string, label: string, icons: string[]}|null}
|
|
423
441
|
*/
|
|
424
442
|
function fileKind(mime) {
|
|
425
443
|
const essence = String(mime ?? '').split(';')[0].trim().toLowerCase();
|
|
@@ -437,9 +455,19 @@ function fileKind(mime) {
|
|
|
437
455
|
* @returns {string}
|
|
438
456
|
*/
|
|
439
457
|
export function fileTypeLabel(mime, name = '') {
|
|
458
|
+
return typeLabel(mime, name, translate);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @param {string} mime MIME type, possibly with parameters.
|
|
463
|
+
* @param {string} name File name.
|
|
464
|
+
* @param {(key: string) => string} text Resolves a family word; a FileItem passes its `msg()`.
|
|
465
|
+
* @returns {string}
|
|
466
|
+
*/
|
|
467
|
+
function typeLabel(mime, name, text) {
|
|
440
468
|
if (!String(mime ?? '').trim()) return '';
|
|
441
469
|
const kind = fileKind(mime);
|
|
442
|
-
if (kind) return kind.label;
|
|
470
|
+
if (kind) return kind.key ? text(kind.key) : kind.label;
|
|
443
471
|
const extension = /\.([a-z0-9]{1,5})$/i.exec(String(name ?? ''))?.[1];
|
|
444
472
|
return extension ? extension.toUpperCase() : '';
|
|
445
473
|
}
|
|
@@ -459,9 +487,11 @@ export function fileTypeIcon(mime) {
|
|
|
459
487
|
return candidates.find((name) => available.has(name)) ?? 'file';
|
|
460
488
|
}
|
|
461
489
|
|
|
462
|
-
/** @param {FileItemState} state @returns {string} */
|
|
463
|
-
function fileStatusLabel(state) {
|
|
464
|
-
|
|
490
|
+
/** @param {FileItemState} state @param {(key: string) => string} text @returns {string} */
|
|
491
|
+
function fileStatusLabel(state, text) {
|
|
492
|
+
if (state.statusLabel !== null) return state.statusLabel;
|
|
493
|
+
const entry = STATUS_LABELS[state.status];
|
|
494
|
+
return entry ? text(entry.key) : '';
|
|
465
495
|
}
|
|
466
496
|
|
|
467
497
|
/** @param {FileStatus} status @returns {'neutral'|'accent'|'success'|'warning'|'danger'|'info'} */
|
|
@@ -11,11 +11,14 @@ import { FileItem, normalizeFileItem } from '../file-item/file-item.js';
|
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {Object} FileListOptions
|
|
13
13
|
* @property {FileItemOptions[]} [items=[]] Initial files in host-supplied order.
|
|
14
|
-
* @property {string} [label=
|
|
14
|
+
* @property {string|null} [label=null] Accessible collection name; null reads the `fileList.label`
|
|
15
|
+
* message ("Files").
|
|
15
16
|
* @property {boolean} [loading=false] Whether initial or incremental files are loading.
|
|
16
17
|
* @property {number} [loadingCount=3] Placeholder rows shown for an empty loading list.
|
|
17
|
-
* @property {string} [loadingText
|
|
18
|
-
*
|
|
18
|
+
* @property {string|null} [loadingText] Loading status text, by default the `fileList.loading`
|
|
19
|
+
* message ("Loading files"). Null shows none.
|
|
20
|
+
* @property {string|number|Node|Component|null} [emptyText] Empty-state content, by default the
|
|
21
|
+
* `fileList.empty` message ("No files"). Null shows none.
|
|
19
22
|
* @property {(event: CustomEvent<{id: unknown, index: number, file: Readonly<FileItemState>, href: string, event: MouseEvent}>) => void} [onactivate]
|
|
20
23
|
* Preventable native-file-link listener.
|
|
21
24
|
* @property {(event: CustomEvent<{id: string, fileId: unknown, index: number, action: object, file: Readonly<FileItemState>, event: MouseEvent}>) => void} [onaction]
|
|
@@ -44,11 +47,12 @@ export class FileList extends Component {
|
|
|
44
47
|
/** @type {Readonly<FileListOptions>} */
|
|
45
48
|
static defaults = {
|
|
46
49
|
items: [],
|
|
47
|
-
label:
|
|
50
|
+
label: null,
|
|
48
51
|
loading: false,
|
|
49
52
|
loadingCount: 3,
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
// Undefined rather than null, which shows nothing.
|
|
54
|
+
loadingText: undefined,
|
|
55
|
+
emptyText: undefined
|
|
52
56
|
};
|
|
53
57
|
|
|
54
58
|
/**
|
|
@@ -77,7 +81,7 @@ export class FileList extends Component {
|
|
|
77
81
|
this._loadingRegion = /** @type {HTMLElement|null} */ (null);
|
|
78
82
|
this._loadingPlaceholders = false;
|
|
79
83
|
|
|
80
|
-
root.setAttribute('aria-label', String(this.options.label || '
|
|
84
|
+
root.setAttribute('aria-label', String(this.options.label || this.msg('fileList.label')));
|
|
81
85
|
this.listen(root, 'zx-activate', (event) => this._forwardActivate(/** @type {CustomEvent} */ (event)));
|
|
82
86
|
this.listen(root, 'zx-action', (event) => this._forwardAction(/** @type {CustomEvent} */ (event)));
|
|
83
87
|
try {
|
|
@@ -201,9 +205,10 @@ export class FileList extends Component {
|
|
|
201
205
|
const content = [];
|
|
202
206
|
if (this._items.length) content.push(/** @type {HTMLElement} */ (this._itemList));
|
|
203
207
|
else if (!this._loading) {
|
|
208
|
+
const { emptyText = this.msg('fileList.empty') } = this.options;
|
|
204
209
|
this._emptyRegion ??= h('div', {
|
|
205
210
|
class: 'zx-file-list__empty', role: 'status'
|
|
206
|
-
}, listContent(
|
|
211
|
+
}, listContent(emptyText, 'FileList emptyText'));
|
|
207
212
|
content.push(this._emptyRegion);
|
|
208
213
|
}
|
|
209
214
|
if (this._loading) content.push(this._createLoading(this._items.length === 0));
|
|
@@ -277,9 +282,10 @@ export class FileList extends Component {
|
|
|
277
282
|
|
|
278
283
|
/** @param {boolean} placeholders @returns {HTMLElement} */
|
|
279
284
|
_buildLoading(placeholders) {
|
|
285
|
+
const { loadingText = this.msg('fileList.loading') } = this.options;
|
|
280
286
|
const region = h('div', {
|
|
281
287
|
class: 'zx-file-list__loading', role: 'status', ariaLive: 'polite'
|
|
282
|
-
}, h('span', { class: 'zx-file-list__loading-label' }, String(
|
|
288
|
+
}, h('span', { class: 'zx-file-list__loading-label' }, String(loadingText ?? '')));
|
|
283
289
|
if (!placeholders) return region;
|
|
284
290
|
const rows = h('div', { class: 'zx-file-list__skeletons', ariaHidden: 'true' });
|
|
285
291
|
for (let index = 0; index < normalizeLoadingCount(this.options.loadingCount); index += 1) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { translate } from '../../core/i18n.js';
|
|
1
2
|
import { uid } from '../../core/util.js';
|
|
2
3
|
|
|
3
4
|
/** @typedef {null|boolean|number|string|FilterJson[]|{[key:string]: FilterJson}} FilterJson */
|
|
@@ -8,8 +9,13 @@ import { uid } from '../../core/util.js';
|
|
|
8
9
|
/** @typedef {{id:string, label:string, arity:'none'|'single'|'pair'|'many', types:string[]}} FilterOperator */
|
|
9
10
|
/** @typedef {{id:string, label:string, type:string, operators?:string[], defaultOperator?:string}} FilterField */
|
|
10
11
|
/** @typedef {{nodeId:string, code:string, message:string}} FilterValidationError */
|
|
12
|
+
/** @typedef {(key:string, ...args:unknown[]) => string} FilterText Resolves a message; a component passes its `msg()`. */
|
|
11
13
|
|
|
12
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Core operators are application-neutral IDs; an adapter maps them to executable query syntax. The
|
|
16
|
+
* labels here are English data that hosts read. What `Filter` shows for a built-in is the
|
|
17
|
+
* `filter.op.<id>` message, see {@link filterOperatorLabel}.
|
|
18
|
+
*/
|
|
13
19
|
export const filterOperators = Object.freeze([
|
|
14
20
|
op('contains', 'contains', 'single', ['text']),
|
|
15
21
|
op('notContains', 'does not contain', 'single', ['text']),
|
|
@@ -40,6 +46,26 @@ export const filterOperators = Object.freeze([
|
|
|
40
46
|
op('isNotEmpty', 'is not empty', 'none', ['text', 'number', 'money', 'date', 'datetime', 'boolean', 'enum', 'status', 'priority', 'country', 'currency', 'unit', 'entity', 'tags'])
|
|
41
47
|
]);
|
|
42
48
|
|
|
49
|
+
/** The catalogue, for code that runs without a component. @type {FilterText} */
|
|
50
|
+
export const filterText = (key, ...args) => translate(key, args);
|
|
51
|
+
|
|
52
|
+
/** Built-in English labels by operator ID. */
|
|
53
|
+
const BUILT_IN_LABELS = new Map(filterOperators.map((operator) => [operator.id, operator.label]));
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The name to show for an operator. A built-in reads its `filter.op.<id>` message. A host-supplied
|
|
57
|
+
* operator keeps its own label, or its lack of one, unless that label is the built-in text for its
|
|
58
|
+
* ID: labels are compared rather than objects so that `operators: filterOperators`, or a spread of a
|
|
59
|
+
* built-in that changes something else, translates too.
|
|
60
|
+
* @param {FilterOperator} operator
|
|
61
|
+
* @param {FilterText} [text=filterText]
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
64
|
+
export function filterOperatorLabel(operator, text = filterText) {
|
|
65
|
+
const builtIn = BUILT_IN_LABELS.has(operator.id) && BUILT_IN_LABELS.get(operator.id) === operator.label;
|
|
66
|
+
return builtIn ? text(`filter.op.${operator.id}`) : operator.label;
|
|
67
|
+
}
|
|
68
|
+
|
|
43
69
|
/** @returns {FilterAst} */
|
|
44
70
|
export function emptyFilterAst() {
|
|
45
71
|
return { version: 1, root: { kind: 'group', id: uid('filter-root'), logic: 'and', children: [] } };
|
|
@@ -131,33 +157,45 @@ export function stringifyFilterAst(value) {
|
|
|
131
157
|
* @returns {{valid:boolean, errors:FilterValidationError[]}}
|
|
132
158
|
*/
|
|
133
159
|
export function validateFilterAst(ast, fields, operators = filterOperators) {
|
|
160
|
+
return checkFilterAst(ast, fields, operators, filterText);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* {@link validateFilterAst} with the messages of a component, not exported from the package.
|
|
165
|
+
* @param {FilterAst} ast
|
|
166
|
+
* @param {FilterField[]} fields
|
|
167
|
+
* @param {FilterOperator[]} operators
|
|
168
|
+
* @param {FilterText} [text=filterText] Resolves the messages of the errors.
|
|
169
|
+
* @returns {{valid:boolean, errors:FilterValidationError[]}}
|
|
170
|
+
*/
|
|
171
|
+
export function checkFilterAst(ast, fields, operators, text = filterText) {
|
|
134
172
|
const errors = [];
|
|
135
173
|
const fieldMap = new Map((Array.isArray(fields) ? fields : []).map((field) => [String(field.id), field]));
|
|
136
174
|
const operatorMap = new Map((Array.isArray(operators) ? operators : []).map((operator) => [String(operator.id), operator]));
|
|
137
175
|
const visit = (node, root = false) => {
|
|
138
176
|
if (node.kind === 'group') {
|
|
139
|
-
if (!root && node.children.length === 0) errors.push(error(node.id, 'empty-group', '
|
|
177
|
+
if (!root && node.children.length === 0) errors.push(error(node.id, 'empty-group', text('filter.emptyGroup')));
|
|
140
178
|
node.children.forEach((child) => visit(child));
|
|
141
179
|
return;
|
|
142
180
|
}
|
|
143
181
|
const field = fieldMap.get(node.field);
|
|
144
|
-
if (!field) errors.push(error(node.id, 'unknown-field', node.field ?
|
|
182
|
+
if (!field) errors.push(error(node.id, 'unknown-field', node.field ? text('filter.fieldUnavailable', node.field) : text('filter.fieldRequired')));
|
|
145
183
|
const operator = operatorMap.get(node.operator);
|
|
146
184
|
if (!operator) {
|
|
147
|
-
errors.push(error(node.id, 'unknown-operator', node.operator ?
|
|
185
|
+
errors.push(error(node.id, 'unknown-operator', node.operator ? text('filter.operatorUnavailable', node.operator) : text('filter.operatorRequired')));
|
|
148
186
|
return;
|
|
149
187
|
}
|
|
150
188
|
if (field) {
|
|
151
189
|
const allowed = Array.isArray(field.operators) && field.operators.length
|
|
152
190
|
? field.operators : operators.filter((candidate) => candidate.types.includes(field.type)).map((candidate) => candidate.id);
|
|
153
191
|
if (!allowed.includes(operator.id) || !operator.types.includes(field.type)) {
|
|
154
|
-
errors.push(error(node.id, 'operator-type',
|
|
192
|
+
errors.push(error(node.id, 'operator-type', text('filter.operatorType', String(filterOperatorLabel(operator, text)), String(field.label))));
|
|
155
193
|
}
|
|
156
194
|
}
|
|
157
195
|
if (!validArity(operator.arity, node.value)) {
|
|
158
|
-
errors.push(error(node.id, 'value', operator.arity === 'pair' ? '
|
|
159
|
-
: operator.arity === 'many' ? '
|
|
160
|
-
: operator.arity === 'none' ? '
|
|
196
|
+
errors.push(error(node.id, 'value', text(operator.arity === 'pair' ? 'filter.valuePair'
|
|
197
|
+
: operator.arity === 'many' ? 'filter.valueMany'
|
|
198
|
+
: operator.arity === 'none' ? 'filter.valueNone' : 'filter.valueOne')));
|
|
161
199
|
}
|
|
162
200
|
};
|
|
163
201
|
visit(ast.root, true);
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
|
|
59
59
|
.zx-filter__logic {
|
|
60
60
|
inline-size: auto;
|
|
61
|
-
min-block-size:
|
|
61
|
+
min-block-size: calc(var(--zx-control-height) - 2px);
|
|
62
62
|
font-size: var(--zx-text-sm);
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -97,11 +97,11 @@
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
.zx-filter__value > :only-child,
|
|
100
|
-
.zx-filter__value
|
|
100
|
+
.zx-filter__value[data-empty] {
|
|
101
101
|
grid-column: 1 / -1;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
.zx-filter__value
|
|
104
|
+
.zx-filter__value[data-empty] {
|
|
105
105
|
display: flex;
|
|
106
106
|
align-items: center;
|
|
107
107
|
min-block-size: var(--zx-control-height);
|