@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
|
@@ -5,8 +5,8 @@ import { printf } from '../../core/i18n.js';
|
|
|
5
5
|
import { Select } from '../select/select.js';
|
|
6
6
|
import { TagPicker } from '../tag-picker/tag-picker.js';
|
|
7
7
|
import {
|
|
8
|
-
cloneFilterAst, cloneFilterValue, emptyFilterAst, filterCondition, filterGroup,
|
|
9
|
-
|
|
8
|
+
checkFilterAst, cloneFilterAst, cloneFilterValue, emptyFilterAst, filterCondition, filterGroup, filterOperatorLabel,
|
|
9
|
+
filterOperators, filterText, parseFilterAst
|
|
10
10
|
} from './filter-model.js';
|
|
11
11
|
|
|
12
12
|
/** @typedef {import('./filter-model.js').FilterAst} FilterAst */
|
|
@@ -78,6 +78,13 @@ export const RELATIVE_DATE_UNITS = Object.freeze(['days', 'weeks', 'months']);
|
|
|
78
78
|
/** English unit words the relative-date editor falls back to. */
|
|
79
79
|
const RELATIVE_UNIT_WORDS = Object.freeze({ days: 'days', weeks: 'weeks', months: 'months' });
|
|
80
80
|
|
|
81
|
+
/** What an empty picker asks for, by the part of the condition it sets. */
|
|
82
|
+
const PART_PROMPTS = Object.freeze({
|
|
83
|
+
field: { key: 'filter.choosePart.field', fallback: 'Choose field…' },
|
|
84
|
+
operator: { key: 'filter.choosePart.operator', fallback: 'Choose operator…' },
|
|
85
|
+
value: { key: 'filter.choosePart.value', fallback: 'Choose value…' }
|
|
86
|
+
});
|
|
87
|
+
|
|
81
88
|
/** English text the value builders fall back to when they are called without a component. */
|
|
82
89
|
const BUILT_IN_VALUE_MESSAGES = Object.freeze({
|
|
83
90
|
choose: 'Choose…',
|
|
@@ -119,6 +126,8 @@ export class Filter extends Component {
|
|
|
119
126
|
this._snapshot = this._createdRoot ? null : snapshotTarget(root);
|
|
120
127
|
this._fields = (Array.isArray(this.options.fields) ? this.options.fields : []).map((field) => ({ ...field }));
|
|
121
128
|
this._operators = mergeOperators(filterOperators, this.options.operators);
|
|
129
|
+
/** @type {import('./filter-model.js').FilterText} */
|
|
130
|
+
this._text = (key, ...args) => this.msg(key, ...args);
|
|
122
131
|
this._readonly = Boolean(this.options.readonly);
|
|
123
132
|
this._disabled = Boolean(this.options.disabled);
|
|
124
133
|
this._async = new Map();
|
|
@@ -241,7 +250,7 @@ export class Filter extends Component {
|
|
|
241
250
|
|
|
242
251
|
/** Returns semantic validity and errors. @returns {{valid:boolean,errors:Array<Record<string,string>>}} */
|
|
243
252
|
validate() {
|
|
244
|
-
const result =
|
|
253
|
+
const result = checkFilterAst(this._value, this._fields, this._operators, this._text);
|
|
245
254
|
for (const node of conditionNodes(this._value.root)) {
|
|
246
255
|
if (!isRelativeDateOperator(this._operator(node.operator))) continue;
|
|
247
256
|
// The model only checks that both halves of the pair are filled; a span also needs a
|
|
@@ -253,7 +262,7 @@ export class Filter extends Component {
|
|
|
253
262
|
else result.errors.push({ nodeId: node.id, code: 'value', message });
|
|
254
263
|
result.valid = false;
|
|
255
264
|
}
|
|
256
|
-
const error =
|
|
265
|
+
const error = logicError(this._value, this.options.rootLogic, this._text);
|
|
257
266
|
if (error) { result.valid = false; result.errors.push(error); }
|
|
258
267
|
return result;
|
|
259
268
|
}
|
|
@@ -415,7 +424,7 @@ export class Filter extends Component {
|
|
|
415
424
|
const operator = this._operator(node.operator);
|
|
416
425
|
const fieldChoices = this._fields.map((candidate) => ({value: candidate.id, label: candidate.label, icon: candidate.icon}));
|
|
417
426
|
if (node.field && !field) fieldChoices.push({value: node.field, label: this._unavailable(node.field)});
|
|
418
|
-
const operatorChoices = operators.map((candidate) => ({value: candidate.id, label: candidate.
|
|
427
|
+
const operatorChoices = operators.map((candidate) => ({value: candidate.id, label: filterOperatorLabel(candidate, this._text)}));
|
|
419
428
|
if (node.operator && !operators.some((candidate) => candidate.id === node.operator)) operatorChoices.push({value: node.operator, label: this._unavailable(node.operator)});
|
|
420
429
|
const fieldSelect = this.options.searchable ? this._searchSelect(fieldChoices, node.field, this._message('filter.field', 'Filter field'), node.id, 'field', (value) => {
|
|
421
430
|
const selectedField = this._field(String(value));
|
|
@@ -436,7 +445,7 @@ export class Filter extends Component {
|
|
|
436
445
|
ariaLabel: this._message('filter.operator', 'Filter operator'), disabled: this._blocked()
|
|
437
446
|
},
|
|
438
447
|
h('option', { value: '', selected: !node.operator }, this._message('filter.chooseOperator', 'Choose an operator…')),
|
|
439
|
-
operators.map((candidate) => h('option', { value: candidate.id, selected: candidate.id === node.operator }, candidate.
|
|
448
|
+
operators.map((candidate) => h('option', { value: candidate.id, selected: candidate.id === node.operator }, filterOperatorLabel(candidate, this._text))),
|
|
440
449
|
node.operator && !operators.some((candidate) => candidate.id === node.operator)
|
|
441
450
|
? h('option', { value: node.operator, selected: true }, this._unavailable(node.operator)) : null);
|
|
442
451
|
return h('li', { class: 'zx-filter__condition', dataset: { nodeId: node.id } },
|
|
@@ -449,7 +458,7 @@ export class Filter extends Component {
|
|
|
449
458
|
_renderValue(node, field, operator) {
|
|
450
459
|
const host = h('div', { class: 'zx-filter__value' });
|
|
451
460
|
if (!field || !operator) return host;
|
|
452
|
-
if (operator.arity === 'none') return h('div', { class: 'zx-filter__value
|
|
461
|
+
if (operator.arity === 'none') return h('div', { class: 'zx-filter__value', 'data-empty': '' }, this._message('filter.noValue', 'No value'));
|
|
453
462
|
if (field.type === 'custom' && typeof field.editor === 'function') {
|
|
454
463
|
const renderVersion = this._renderVersion;
|
|
455
464
|
queueMicrotask(() => {
|
|
@@ -518,7 +527,7 @@ export class Filter extends Component {
|
|
|
518
527
|
* @param {unknown} value Selected value.
|
|
519
528
|
* @param {string} label Accessible name.
|
|
520
529
|
* @param {string} nodeId Condition ID.
|
|
521
|
-
* @param {
|
|
530
|
+
* @param {keyof typeof PART_PROMPTS} part Focus target name, which also picks the placeholder.
|
|
522
531
|
* @param {(value:unknown)=>void} changed Selection handler.
|
|
523
532
|
* @returns {HTMLElement} Picker root.
|
|
524
533
|
*/
|
|
@@ -533,7 +542,7 @@ export class Filter extends Component {
|
|
|
533
542
|
} : {};
|
|
534
543
|
const select = new Select(null, {
|
|
535
544
|
items, valueKey: 'value', labelKey: 'label', value, label, filter: 'local',
|
|
536
|
-
disabled: this._blocked(), placeholder: this._message(
|
|
545
|
+
disabled: this._blocked(), placeholder: this._message(PART_PROMPTS[part].key, PART_PROMPTS[part].fallback),
|
|
537
546
|
...glyphs,
|
|
538
547
|
onchange: ({detail}) => queueMicrotask(() => {
|
|
539
548
|
if (!this._disposed && version === this._renderVersion && this._canMutate()) changed(detail.value);
|
|
@@ -999,6 +1008,16 @@ function cssEscape(value) { return globalThis.CSS?.escape ? CSS.escape(value) :
|
|
|
999
1008
|
* @returns {Record<string,string>|null} Actionable validation error, or null.
|
|
1000
1009
|
*/
|
|
1001
1010
|
export function rootLogicError(value, logic) {
|
|
1011
|
+
return logicError(value, logic, filterText);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* @param {FilterAst} value Expression to validate.
|
|
1016
|
+
* @param {'and'|'or'|null} logic Required root logic.
|
|
1017
|
+
* @param {import('./filter-model.js').FilterText} [text=filterText] Resolves the error's message.
|
|
1018
|
+
* @returns {Record<string,string>|null} Actionable validation error, or null.
|
|
1019
|
+
*/
|
|
1020
|
+
function logicError(value, logic, text = filterText) {
|
|
1002
1021
|
if (!logic || value.root.logic === logic) return null;
|
|
1003
|
-
return {nodeId: value.root.id, code: 'root-logic', message:
|
|
1022
|
+
return {nodeId: value.root.id, code: 'root-logic', message: text(logic === 'or' ? 'filter.requiresAny' : 'filter.requiresAll')};
|
|
1004
1023
|
}
|
|
@@ -4,7 +4,7 @@ import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
|
|
|
4
4
|
import { printf } from '../../core/i18n.js';
|
|
5
5
|
import { uid } from '../../core/util.js';
|
|
6
6
|
import { Checklist } from '../checklist/checklist.js';
|
|
7
|
-
import { NumberField, parseNumber } from '../number-field/number-field.js';
|
|
7
|
+
import { NumberField, parseNumber, snapNumber } from '../number-field/number-field.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Number of options past which the select filter's `Checklist` gets its search box. Below it the
|
|
@@ -810,8 +810,8 @@ export function toDraft(value, fields, timeZone = null) {
|
|
|
810
810
|
: toDateInput(raw, timeZone);
|
|
811
811
|
} else {
|
|
812
812
|
draft[key] = spec.range
|
|
813
|
-
? { from: toNumberValue(readEdge(raw, 'from'), spec), to: toNumberValue(readEdge(raw, 'to'), spec) }
|
|
814
|
-
: toNumberValue(raw, spec);
|
|
813
|
+
? { from: toNumberValue(readEdge(raw, 'from'), spec, field), to: toNumberValue(readEdge(raw, 'to'), spec, field) }
|
|
814
|
+
: toNumberValue(raw, spec, field);
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
817
|
return draft;
|
|
@@ -924,12 +924,20 @@ function readEdge(raw, edge) {
|
|
|
924
924
|
/**
|
|
925
925
|
* @param {unknown} raw Candidate number.
|
|
926
926
|
* @param {FilterPanelSpec} spec Resolved type.
|
|
927
|
+
* @param {FilterPanelField} field Numeric constraints.
|
|
927
928
|
* @returns {number|null}
|
|
928
929
|
*/
|
|
929
|
-
function toNumberValue(raw, spec) {
|
|
930
|
+
function toNumberValue(raw, spec, field) {
|
|
930
931
|
const parsed = parseNumber(raw);
|
|
931
932
|
if (parsed === null) return null;
|
|
932
|
-
|
|
933
|
+
const step = Number.isFinite(Number(field.step)) && Number(field.step) > 0
|
|
934
|
+
? Number(field.step) : (spec.integer ? 1 : FLOAT_STEP);
|
|
935
|
+
const text = String(step);
|
|
936
|
+
const precision = spec.integer ? 0 : Number(text.match(/e-(\d+)/i)?.[1] ?? (text.split('.')[1]?.length || 0));
|
|
937
|
+
return snapNumber(parsed, {
|
|
938
|
+
min: field.min == null ? null : Number(field.min),
|
|
939
|
+
max: field.max == null ? null : Number(field.max), step, precision
|
|
940
|
+
});
|
|
933
941
|
}
|
|
934
942
|
|
|
935
943
|
/**
|
|
@@ -20,7 +20,8 @@ import { createReaders, isBranch, pathTo } from '../tree/hierarchy.js';
|
|
|
20
20
|
* @property {number|string|null} [height=320] Component height in pixels or any CSS length.
|
|
21
21
|
* @property {boolean} [icons=true] Whether to render folder and file icons.
|
|
22
22
|
* @property {((node: TreeNode) => Node|string)|null} [renderItem=null] Row renderer.
|
|
23
|
-
* @property {string} [emptyText
|
|
23
|
+
* @property {string|null} [emptyText] Text shown in an empty column, by default the `finder.noItems`
|
|
24
|
+
* message ("Empty"). Null shows none.
|
|
24
25
|
* @property {Record<string, string>|Record<string, Record<string, string>>} [msg] Localized messages.
|
|
25
26
|
* @property {(event: CustomEvent<{path: unknown[], nodes: TreeNode[], node: TreeNode|null}>) => void} [onchange] Path listener.
|
|
26
27
|
* @property {(event: CustomEvent<{node: TreeNode, id: unknown}>) => void} [onactivate] Activation listener.
|
|
@@ -56,7 +57,8 @@ export class Finder extends Component {
|
|
|
56
57
|
height: 320,
|
|
57
58
|
icons: true,
|
|
58
59
|
renderItem: null,
|
|
59
|
-
|
|
60
|
+
// Undefined rather than null, which shows nothing.
|
|
61
|
+
emptyText: undefined
|
|
60
62
|
};
|
|
61
63
|
|
|
62
64
|
/** @returns {HTMLElement} */
|
|
@@ -66,8 +68,10 @@ export class Finder extends Component {
|
|
|
66
68
|
this._path = [];
|
|
67
69
|
this._columns = [];
|
|
68
70
|
this._activeColumn = 0;
|
|
69
|
-
/** @type {Map<unknown, Promise<
|
|
71
|
+
/** @type {Map<unknown, Promise<{children?: TreeNode[], error?: Error}>>} In-flight lazy loads, keyed by node ID. */
|
|
70
72
|
this._loading = new Map();
|
|
73
|
+
this._loadGeneration = 0;
|
|
74
|
+
this._destroyed = false;
|
|
71
75
|
this._pathSequence = 0;
|
|
72
76
|
this._createdRoot = this.el === null;
|
|
73
77
|
this._snapshot = this._createdRoot ? null : snapshotTarget(this.el);
|
|
@@ -142,6 +146,7 @@ export class Finder extends Component {
|
|
|
142
146
|
* @fires Finder#change
|
|
143
147
|
*/
|
|
144
148
|
async setPath(ids, { silent = false, focus = false } = {}) {
|
|
149
|
+
if (this._destroyed) return this;
|
|
145
150
|
const sequence = this._pathSequence + 1;
|
|
146
151
|
this._pathSequence = sequence;
|
|
147
152
|
const wanted = Array.isArray(ids) ? ids.slice() : [];
|
|
@@ -153,9 +158,9 @@ export class Finder extends Component {
|
|
|
153
158
|
if (!node) break;
|
|
154
159
|
path.push(id);
|
|
155
160
|
if (!isBranch(node, this._readers)) break;
|
|
156
|
-
await this._ensureChildren(node);
|
|
161
|
+
await this._ensureChildren(node, sequence);
|
|
157
162
|
// A slower earlier call must not overwrite a newer path once its loaders resolve.
|
|
158
|
-
if (sequence !== this._pathSequence) return this;
|
|
163
|
+
if (this._destroyed || sequence !== this._pathSequence) return this;
|
|
159
164
|
level = this._readers.children(node) ?? [];
|
|
160
165
|
}
|
|
161
166
|
this._path = path;
|
|
@@ -183,6 +188,9 @@ export class Finder extends Component {
|
|
|
183
188
|
* @returns {this}
|
|
184
189
|
*/
|
|
185
190
|
setItems(items) {
|
|
191
|
+
this._pathSequence += 1;
|
|
192
|
+
this._loadGeneration += 1;
|
|
193
|
+
this._loading.clear();
|
|
186
194
|
this._items = Array.isArray(items) ? items.slice() : [];
|
|
187
195
|
this._path = [];
|
|
188
196
|
this._render({});
|
|
@@ -252,9 +260,10 @@ export class Finder extends Component {
|
|
|
252
260
|
|
|
253
261
|
if (column.nodes.length === 0) {
|
|
254
262
|
const loading = column.owner !== null && this._loading.has(this._readers.value(column.owner));
|
|
263
|
+
const { emptyText = this.msg('finder.noItems') } = this.options;
|
|
255
264
|
list.append(h('div', { class: 'zx-finder__empty' }, loading
|
|
256
265
|
? this._message('finder.loading', 'Loading…')
|
|
257
|
-
: this._message('finder.empty',
|
|
266
|
+
: this._message('finder.empty', emptyText)));
|
|
258
267
|
}
|
|
259
268
|
|
|
260
269
|
for (const node of column.nodes) {
|
|
@@ -352,6 +361,7 @@ export class Finder extends Component {
|
|
|
352
361
|
case 'ArrowLeft':
|
|
353
362
|
event.preventDefault();
|
|
354
363
|
if (column === 0) return;
|
|
364
|
+
this._pathSequence += 1;
|
|
355
365
|
this._path = this._path.slice(0, column);
|
|
356
366
|
this._activeColumn = column - 1;
|
|
357
367
|
this._render({ focus: true });
|
|
@@ -379,12 +389,14 @@ export class Finder extends Component {
|
|
|
379
389
|
* @fires Finder#change
|
|
380
390
|
*/
|
|
381
391
|
async _selectAt(column, index, { focus = false } = {}) {
|
|
392
|
+
if (this._destroyed) return;
|
|
382
393
|
const node = this._columnNodes(column)[index];
|
|
383
394
|
if (!node) return;
|
|
395
|
+
const sequence = ++this._pathSequence;
|
|
384
396
|
const id = this._readers.value(node);
|
|
385
397
|
// Re-selecting the row that is already selected would replace the element under the pointer
|
|
386
398
|
// and break the browser's own double-click detection.
|
|
387
|
-
if (this._path.length === column + 1 && Object.is(this._path[column], id)) {
|
|
399
|
+
if (this._path.length === column + 1 && Object.is(this._path[column], id) && !this._loading.has(id)) {
|
|
388
400
|
this._activeColumn = column;
|
|
389
401
|
this._syncTabStop();
|
|
390
402
|
if (focus) this.focus();
|
|
@@ -392,7 +404,8 @@ export class Finder extends Component {
|
|
|
392
404
|
}
|
|
393
405
|
this._path = [...this._path.slice(0, column), id];
|
|
394
406
|
this._activeColumn = column;
|
|
395
|
-
if (isBranch(node, this._readers)) await this._ensureChildren(node);
|
|
407
|
+
if (isBranch(node, this._readers)) await this._ensureChildren(node, sequence);
|
|
408
|
+
if (this._destroyed || sequence !== this._pathSequence) return;
|
|
396
409
|
this._render({ focus });
|
|
397
410
|
this._emitChange();
|
|
398
411
|
}
|
|
@@ -404,7 +417,10 @@ export class Finder extends Component {
|
|
|
404
417
|
* @returns {Promise<void>}
|
|
405
418
|
*/
|
|
406
419
|
async _enter(column, index) {
|
|
407
|
-
|
|
420
|
+
const selecting = this._selectAt(column, index);
|
|
421
|
+
const sequence = this._pathSequence;
|
|
422
|
+
await selecting;
|
|
423
|
+
if (this._destroyed || sequence !== this._pathSequence) return;
|
|
408
424
|
const children = this._columnNodes(column + 1);
|
|
409
425
|
if (children.length === 0) {
|
|
410
426
|
this._activeColumn = column;
|
|
@@ -426,29 +442,34 @@ export class Finder extends Component {
|
|
|
426
442
|
/**
|
|
427
443
|
* Loads a branch's children through the configured loader, once.
|
|
428
444
|
* @param {TreeNode} node Branch node.
|
|
445
|
+
* @param {number} sequence Navigation that requested the children.
|
|
429
446
|
* @returns {Promise<void>}
|
|
430
447
|
*/
|
|
431
|
-
async _ensureChildren(node) {
|
|
448
|
+
async _ensureChildren(node, sequence) {
|
|
432
449
|
const loaded = this._readers.children(node);
|
|
433
450
|
if (!this.options.load || (loaded && loaded.length > 0)) return;
|
|
434
451
|
const id = this._readers.value(node);
|
|
435
452
|
// One in-flight request per branch, so a double navigation never calls the loader twice.
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
this.
|
|
451
|
-
|
|
453
|
+
const generation = this._loadGeneration;
|
|
454
|
+
let request = this._loading.get(id);
|
|
455
|
+
if (!request) {
|
|
456
|
+
request = (async () => {
|
|
457
|
+
try {
|
|
458
|
+
const children = await this.options.load(node);
|
|
459
|
+
return { children: Array.isArray(children) ? children : [] };
|
|
460
|
+
} catch (error) {
|
|
461
|
+
return { error };
|
|
462
|
+
}
|
|
463
|
+
})();
|
|
464
|
+
this._loading.set(id, request);
|
|
465
|
+
}
|
|
466
|
+
const result = await request;
|
|
467
|
+
if (this._destroyed || generation !== this._loadGeneration) return;
|
|
468
|
+
if (this._loading.get(id) === request) this._loading.delete(id);
|
|
469
|
+
if (sequence !== this._pathSequence) return;
|
|
470
|
+
node[this._childrenKey] = result.children ?? [];
|
|
471
|
+
if ('error' in result) this.emit('error', { error: result.error, node, id });
|
|
472
|
+
else if (node[this._childrenKey].length === 0) node.hasChildren = false;
|
|
452
473
|
}
|
|
453
474
|
|
|
454
475
|
/** @param {number} column @returns {TreeNode[]} */
|
|
@@ -498,6 +519,9 @@ export class Finder extends Component {
|
|
|
498
519
|
destroy() {
|
|
499
520
|
// Invalidate any in-flight path resolution so a late loader cannot re-render a dead component.
|
|
500
521
|
this._pathSequence += 1;
|
|
522
|
+
this._loadGeneration += 1;
|
|
523
|
+
this._destroyed = true;
|
|
524
|
+
this._loading.clear();
|
|
501
525
|
const root = this.el;
|
|
502
526
|
super.destroy();
|
|
503
527
|
if (!this._createdRoot && root) restoreTarget(root, this._snapshot);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* A flag is a fixed footprint, whatever draws it, so rows of mixed flags and chips line up. It is
|
|
2
|
+
sized in em: it follows the text it stands beside, in a picker row or a table cell alike. */
|
|
3
|
+
.zx-flag {
|
|
4
|
+
display: inline-grid;
|
|
5
|
+
flex: none;
|
|
6
|
+
place-items: center;
|
|
7
|
+
min-inline-size: 1.5em;
|
|
8
|
+
block-size: 1.125em;
|
|
9
|
+
line-height: 1;
|
|
10
|
+
user-select: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.zx-flag[data-kind="emoji"] {
|
|
14
|
+
font-size: 1.25em;
|
|
15
|
+
min-inline-size: 1.2em;
|
|
16
|
+
block-size: 0.9em;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* A chip stands in where no flag is drawn: a language without a country, or a platform without
|
|
20
|
+
flag glyphs. Same footprint, muted, so it never reads as a status badge. */
|
|
21
|
+
.zx-flag[data-kind="code"] {
|
|
22
|
+
padding-inline: 0.25em;
|
|
23
|
+
border-radius: var(--zx-radius-sm);
|
|
24
|
+
background: var(--zx-color-bg-muted);
|
|
25
|
+
color: var(--zx-color-text-muted);
|
|
26
|
+
font-size: 0.6875em;
|
|
27
|
+
font-weight: var(--zx-weight-semibold);
|
|
28
|
+
min-inline-size: 2.2em;
|
|
29
|
+
block-size: 1.65em;
|
|
30
|
+
letter-spacing: 0.02em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.zx-flag__image {
|
|
34
|
+
display: block;
|
|
35
|
+
inline-size: 1.5em;
|
|
36
|
+
block-size: 1.125em;
|
|
37
|
+
border-radius: var(--zx-radius-sm);
|
|
38
|
+
object-fit: cover;
|
|
39
|
+
box-shadow: 0 0 0 1px var(--zx-color-border-subtle);
|
|
40
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { h } from '../../core/dom.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How a flag is drawn: `emoji` is the platform's flag glyph, `code` a small chip carrying the code
|
|
5
|
+
* as text, `image` an `<img>` from a URL the application supplies, and `auto` the emoji where the
|
|
6
|
+
* platform draws flag glyphs and the chip where it does not.
|
|
7
|
+
* @typedef {'auto'|'emoji'|'code'|'image'} FlagKind
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} FlagOptions
|
|
11
|
+
* @property {FlagKind} [kind='auto'] Drawing; `src` implies `image`.
|
|
12
|
+
* @property {string|null} [src=null] Image URL. `{code}` in it is replaced by the lower-case region
|
|
13
|
+
* code and `{CODE}` by the upper-case one, so `'/flags/{code}.svg'` serves a whole flag set.
|
|
14
|
+
* @property {string|null} [text=null] Text of the code chip, by default the region code. A chip
|
|
15
|
+
* also stands in for a flag when there is no valid region, as for a language without a country.
|
|
16
|
+
* @property {string|null} [label=null] Accessible name. Without one the flag is decorative
|
|
17
|
+
* (`aria-hidden`) and must sit beside text that names the country or language.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* What a picker draws in front of each choice: a {@link FlagKind} other than `image`, `none` for
|
|
21
|
+
* nothing, or a function returning the content itself.
|
|
22
|
+
* @typedef {'auto'|'emoji'|'code'|'none'|((region: string|null, item: Record<string, any>) => Node|string|null)} FlagMode
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Every officially assigned ISO 3166-1 alpha-2 code, and `XK` (Kosovo), which is user-assigned but
|
|
27
|
+
* in common use, in alphabetical order. `Select.country()` lists these when given no `countries`.
|
|
28
|
+
* @type {ReadonlyArray<string>}
|
|
29
|
+
*/
|
|
30
|
+
export const COUNTRY_CODES = Object.freeze((
|
|
31
|
+
'AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS '
|
|
32
|
+
+ 'BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE '
|
|
33
|
+
+ 'EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM '
|
|
34
|
+
+ 'HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC '
|
|
35
|
+
+ 'LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA '
|
|
36
|
+
+ 'NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW '
|
|
37
|
+
+ 'SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO '
|
|
38
|
+
+ 'TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS XK YE YT ZA ZM ZW'
|
|
39
|
+
).split(' '));
|
|
40
|
+
|
|
41
|
+
/** Code point of REGIONAL INDICATOR SYMBOL LETTER A, minus the code of `A`. */
|
|
42
|
+
const INDICATOR_OFFSET = 0x1F1E6 - 65;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Settles a region code: two ASCII letters, upper-cased. Anything else — a numeric UN M.49 region
|
|
46
|
+
* such as `419`, an empty value — is not a flag and reads as null.
|
|
47
|
+
* @param {unknown} code Candidate region code.
|
|
48
|
+
* @returns {string|null}
|
|
49
|
+
*/
|
|
50
|
+
export function normalizeRegion(code) {
|
|
51
|
+
const text = typeof code === 'string' ? code.trim() : '';
|
|
52
|
+
return /^[a-z]{2}$/i.test(text) ? text.toUpperCase() : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Spells a region as its flag emoji: the pair of regional indicator symbols the platform's emoji
|
|
57
|
+
* font draws as a flag (`'DE'` → 🇩🇪). Where the font has no flags the pair shows as two letters.
|
|
58
|
+
* @param {unknown} code ISO 3166-1 alpha-2 region code.
|
|
59
|
+
* @returns {string} The emoji, or `''` when the code is not two letters.
|
|
60
|
+
*/
|
|
61
|
+
export function flagEmoji(code) {
|
|
62
|
+
const region = normalizeRegion(code);
|
|
63
|
+
if (!region) return '';
|
|
64
|
+
return String.fromCodePoint(...[...region].map((letter) => letter.charCodeAt(0) + INDICATOR_OFFSET));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Reports whether this platform draws flag emoji as flags. Windows, for one, draws the regional
|
|
69
|
+
* indicators as plain letters. The test draws a flag into a small canvas and looks for colour,
|
|
70
|
+
* which costs a little each call, so a picker asks once and keeps the answer.
|
|
71
|
+
* @param {Document|null} [doc=globalThis.document] Document to test in.
|
|
72
|
+
* @returns {boolean} False without a document or a 2D canvas, as in Node.
|
|
73
|
+
*/
|
|
74
|
+
export function supportsFlagEmoji(doc = globalThis.document) {
|
|
75
|
+
const canvas = /** @type {HTMLCanvasElement|null} */ (doc?.createElement?.('canvas') ?? null);
|
|
76
|
+
let context = null;
|
|
77
|
+
try {
|
|
78
|
+
context = canvas?.getContext?.('2d', { willReadFrequently: true }) ?? null;
|
|
79
|
+
} catch {
|
|
80
|
+
context = null;
|
|
81
|
+
}
|
|
82
|
+
if (!canvas || !context) return false;
|
|
83
|
+
const size = 24;
|
|
84
|
+
canvas.width = size;
|
|
85
|
+
canvas.height = size;
|
|
86
|
+
context.textBaseline = 'top';
|
|
87
|
+
context.font = `${size - 4}px sans-serif`;
|
|
88
|
+
// Letters come out in the default black; a flag brings colour of its own.
|
|
89
|
+
context.fillText(flagEmoji('DE'), 0, 0);
|
|
90
|
+
let data;
|
|
91
|
+
try {
|
|
92
|
+
data = context.getImageData(0, 0, size, size).data;
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
for (let index = 0; index < data.length; index += 4) {
|
|
97
|
+
if (data[index + 3] > 0 && (data[index] !== data[index + 1] || data[index + 1] !== data[index + 2])) return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Fills a flag URL template: `{code}` becomes the lower-case region code, `{CODE}` the upper-case.
|
|
104
|
+
* @param {string} template URL template, such as `'/flags/{code}.svg'`.
|
|
105
|
+
* @param {string} region Two-letter region code.
|
|
106
|
+
* @returns {string}
|
|
107
|
+
*/
|
|
108
|
+
export function flagSource(template, region) {
|
|
109
|
+
return String(template).replaceAll('{code}', region.toLowerCase()).replaceAll('{CODE}', region.toUpperCase());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Draws a country flag, for a picker row, a table cell, or a profile — so a country reads the same
|
|
114
|
+
* wherever it appears. The flag is decorative unless `label` is given: put the country's name
|
|
115
|
+
* beside it.
|
|
116
|
+
*
|
|
117
|
+
* Zx ships no flag artwork. The default is the platform's flag emoji, and a code chip where the
|
|
118
|
+
* platform has none; pass `src` to draw from any flag set the application serves.
|
|
119
|
+
*
|
|
120
|
+
* @param {string|null|undefined} code ISO 3166-1 alpha-2 region code (`'DE'`, `'at'`).
|
|
121
|
+
* @param {FlagOptions} [options={}] Drawing and accessible-name options.
|
|
122
|
+
* @returns {HTMLSpanElement} A `.zx-flag` element whose `data-kind` says how it was drawn.
|
|
123
|
+
*/
|
|
124
|
+
export function flag(code, options = {}) {
|
|
125
|
+
const { kind = 'auto', src = null, text = null, label = null } = options ?? {};
|
|
126
|
+
const region = normalizeRegion(code);
|
|
127
|
+
let resolved = src ? 'image' : kind;
|
|
128
|
+
if (resolved === 'auto') resolved = supportsFlagEmoji() ? 'emoji' : 'code';
|
|
129
|
+
if (!region || (resolved === 'image' && !src)) resolved = 'code';
|
|
130
|
+
let content;
|
|
131
|
+
if (resolved === 'image') {
|
|
132
|
+
content = h('img', {
|
|
133
|
+
class: 'zx-flag__image',
|
|
134
|
+
src: flagSource(/** @type {string} */ (src), /** @type {string} */ (region)),
|
|
135
|
+
alt: '',
|
|
136
|
+
loading: 'lazy',
|
|
137
|
+
decoding: 'async'
|
|
138
|
+
});
|
|
139
|
+
} else if (resolved === 'emoji') {
|
|
140
|
+
content = flagEmoji(region);
|
|
141
|
+
} else {
|
|
142
|
+
resolved = 'code';
|
|
143
|
+
content = String(text ?? region ?? '').trim();
|
|
144
|
+
}
|
|
145
|
+
const element = /** @type {HTMLSpanElement} */ (h('span', {
|
|
146
|
+
class: 'zx-flag',
|
|
147
|
+
dataset: { kind: resolved, ...(region ? { region } : {}) }
|
|
148
|
+
}, content));
|
|
149
|
+
const name = label == null ? '' : String(label).trim();
|
|
150
|
+
if (name) {
|
|
151
|
+
element.setAttribute('role', 'img');
|
|
152
|
+
element.setAttribute('aria-label', name);
|
|
153
|
+
} else {
|
|
154
|
+
element.setAttribute('aria-hidden', 'true');
|
|
155
|
+
}
|
|
156
|
+
return element;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Builds the function a picker draws its flags with, resolving `auto` once rather than per row.
|
|
161
|
+
* @param {FlagMode} mode What to draw.
|
|
162
|
+
* @param {string|null} template Flag URL template; wins over the emoji and chip modes.
|
|
163
|
+
* @returns {(region: string|null, text: string, item: Record<string, any>) => Node|string|null}
|
|
164
|
+
*/
|
|
165
|
+
export function flagRenderer(mode, template) {
|
|
166
|
+
if (typeof mode === 'function') return (region, _text, item) => mode(region, item);
|
|
167
|
+
if (mode === 'none' || mode === /** @type {any} */ (false)) return () => null;
|
|
168
|
+
/** @type {FlagKind} */
|
|
169
|
+
let kind = mode === 'emoji' || mode === 'code' ? mode : 'auto';
|
|
170
|
+
if (template && kind !== 'code') kind = 'image';
|
|
171
|
+
else if (kind === 'auto') kind = supportsFlagEmoji() ? 'emoji' : 'code';
|
|
172
|
+
return (region, text) => flag(region, {
|
|
173
|
+
kind,
|
|
174
|
+
src: kind === 'image' ? template : null,
|
|
175
|
+
text: text || null
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -118,7 +118,7 @@ export class Form extends Component {
|
|
|
118
118
|
setActions(list) {
|
|
119
119
|
this._actionDescriptors = Array.isArray(list) ? list.map((action) => ({ ...action })) : [];
|
|
120
120
|
this._actions.replaceChildren(...this._actionDescriptors.map((action, index) => {
|
|
121
|
-
const label = String(action.label ?? action.id ?? '
|
|
121
|
+
const label = String(action.label ?? action.id ?? this.msg('form.action'));
|
|
122
122
|
return h('button', {
|
|
123
123
|
class: 'zx-btn',
|
|
124
124
|
type: ['submit', 'reset'].includes(action.type) ? action.type : 'button',
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Component } from '../../core/component.js';
|
|
2
|
+
import { translate } from '../../core/i18n.js';
|
|
1
3
|
import { Table } from '../table/table.js';
|
|
2
4
|
|
|
3
5
|
/** @typedef {Record<string, any>} BillingRow */
|
|
@@ -90,7 +92,9 @@ export function billingItemsConfig(options = {}) {
|
|
|
90
92
|
return quantity !== null && price !== null ? quantity * price : null;
|
|
91
93
|
};
|
|
92
94
|
const columns = Array.isArray(suppliedColumns) ? suppliedColumns.map((column) => ({ ...column }))
|
|
93
|
-
|
|
95
|
+
// No instance exists yet, so a `msg` option is read the way `msg()` reads it off a borrower.
|
|
96
|
+
: presetColumns(fields, { units, currencies, currency, locale, decimals, columnOverrides },
|
|
97
|
+
(key) => Component.prototype.msg.call({ options }, key));
|
|
94
98
|
return {
|
|
95
99
|
rowId: fields.id,
|
|
96
100
|
editMode: 'cell',
|
|
@@ -150,21 +154,31 @@ export function isBillingLine(row, fields = DEFAULT_FIELDS) {
|
|
|
150
154
|
* @param {{units: unknown, currencies: unknown, currency: string, locale?: string, decimals: number, columnOverrides: Record<string, object>}} options Formatting/editor options.
|
|
151
155
|
* @returns {import('../table/table.js').TableColumn[]}
|
|
152
156
|
*/
|
|
153
|
-
export function billingColumns(fields,
|
|
157
|
+
export function billingColumns(fields, options) {
|
|
158
|
+
return presetColumns(fields, options, translate);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {BillingFields} fields Field map.
|
|
163
|
+
* @param {{units: unknown, currencies: unknown, currency: string, locale?: string, decimals: number, columnOverrides: Record<string, object>}} options Formatting/editor options.
|
|
164
|
+
* @param {(key: string) => string} text Resolves the column names.
|
|
165
|
+
* @returns {import('../table/table.js').TableColumn[]}
|
|
166
|
+
*/
|
|
167
|
+
function presetColumns(fields, { units, currencies, currency, locale, decimals, columnOverrides }, text) {
|
|
154
168
|
const editableLine = (type) => (row) => isBillingLine(row, fields) ? type : false;
|
|
155
169
|
const rowCurrency = (row) => String(row?.[fields.currency] || currency);
|
|
156
170
|
const rowUnit = (row) => String(row?.[fields.unit] ?? '');
|
|
157
171
|
const columns = {
|
|
158
172
|
item: {
|
|
159
173
|
id: fields.item,
|
|
160
|
-
label: '
|
|
174
|
+
label: text('grid.item'),
|
|
161
175
|
width: '2fr',
|
|
162
176
|
sortable: true,
|
|
163
177
|
editable: editableLine('text')
|
|
164
178
|
},
|
|
165
179
|
quantity: {
|
|
166
180
|
id: fields.quantity,
|
|
167
|
-
label: '
|
|
181
|
+
label: text('grid.quantity'),
|
|
168
182
|
width: '1fr',
|
|
169
183
|
type: 'unit',
|
|
170
184
|
locale,
|
|
@@ -174,14 +188,14 @@ export function billingColumns(fields, { units, currencies, currency, locale, de
|
|
|
174
188
|
},
|
|
175
189
|
unit: {
|
|
176
190
|
id: fields.unit,
|
|
177
|
-
label: '
|
|
191
|
+
label: text('grid.unit'),
|
|
178
192
|
width: '.8fr',
|
|
179
193
|
editable: editableLine(hasChoices(units) ? 'select' : 'text'),
|
|
180
194
|
options: units
|
|
181
195
|
},
|
|
182
196
|
unitPrice: {
|
|
183
197
|
id: fields.unitPrice,
|
|
184
|
-
label: '
|
|
198
|
+
label: text('grid.unitPrice'),
|
|
185
199
|
width: '1fr',
|
|
186
200
|
type: 'currency',
|
|
187
201
|
locale,
|
|
@@ -192,14 +206,14 @@ export function billingColumns(fields, { units, currencies, currency, locale, de
|
|
|
192
206
|
},
|
|
193
207
|
currency: {
|
|
194
208
|
id: fields.currency,
|
|
195
|
-
label: '
|
|
209
|
+
label: text('grid.currency'),
|
|
196
210
|
width: '.8fr',
|
|
197
211
|
editable: editableLine(hasChoices(currencies) ? 'select' : 'text'),
|
|
198
212
|
options: currencies
|
|
199
213
|
},
|
|
200
214
|
total: {
|
|
201
215
|
id: fields.total,
|
|
202
|
-
label: '
|
|
216
|
+
label: text('grid.lineTotal'),
|
|
203
217
|
width: '1fr',
|
|
204
218
|
type: 'currency',
|
|
205
219
|
locale,
|