@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
|
@@ -12,7 +12,8 @@ import { uid } from '../../core/util.js';
|
|
|
12
12
|
* @property {boolean} [clearable=true] Whether re-selecting the current value clears it.
|
|
13
13
|
* @property {boolean} [readonly=false] Whether the rating is display-only.
|
|
14
14
|
* @property {boolean} [disabled=false] Whether interaction is disabled.
|
|
15
|
-
* @property {string} [label=
|
|
15
|
+
* @property {string|null} [label=null] Accessible name of the group; null reads the `rating.label`
|
|
16
|
+
* message ("Rating").
|
|
16
17
|
* @property {string} [icon='star'] Icon name used for each symbol.
|
|
17
18
|
* @property {string[]|null} [labels=null] Per-step accessible names, lowest first.
|
|
18
19
|
* @property {boolean} [showValue=false] Whether to render the numeric value beside the symbols.
|
|
@@ -43,7 +44,7 @@ export class Rating extends Component {
|
|
|
43
44
|
clearable: true,
|
|
44
45
|
readonly: false,
|
|
45
46
|
disabled: false,
|
|
46
|
-
label:
|
|
47
|
+
label: null,
|
|
47
48
|
icon: 'star',
|
|
48
49
|
labels: null,
|
|
49
50
|
showValue: false,
|
|
@@ -75,7 +76,7 @@ export class Rating extends Component {
|
|
|
75
76
|
ref: 'symbols',
|
|
76
77
|
class: 'zx-rating__symbols',
|
|
77
78
|
role: 'radiogroup',
|
|
78
|
-
ariaLabel: String(this.options.label ?? '
|
|
79
|
+
ariaLabel: String(this.options.label ?? this.msg('rating.label'))
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
for (let index = 1; index <= this._max; index += 1) {
|
|
@@ -350,7 +351,7 @@ export class Rating extends Component {
|
|
|
350
351
|
const parts = [];
|
|
351
352
|
if (this.options.showValue) parts.push(formatValue(this._value, this._step));
|
|
352
353
|
if (count !== null && count !== undefined) {
|
|
353
|
-
parts.push(this.
|
|
354
|
+
parts.push(this.msgPlural('rating.count', Number(count), count));
|
|
354
355
|
}
|
|
355
356
|
readout.textContent = parts.join(' · ');
|
|
356
357
|
}
|
|
@@ -125,7 +125,7 @@ const MESSAGES = Object.freeze({
|
|
|
125
125
|
'runStatus.costLabel': 'Cost',
|
|
126
126
|
'runStatus.cost': '%1 of %2',
|
|
127
127
|
'runStatus.stepsLabel': 'Steps done',
|
|
128
|
-
|
|
128
|
+
// Step plurals come from the English catalogue so its own cardinal rules select the fallback.
|
|
129
129
|
'runStatus.timeFormat': '%H:%M',
|
|
130
130
|
'runStatus.dateTimeFormat': '%e %b, %H:%M'
|
|
131
131
|
});
|
|
@@ -441,7 +441,7 @@ export class RunStatus extends Component {
|
|
|
441
441
|
'aria-valuemin': '0',
|
|
442
442
|
'aria-valuemax': String(steps.total),
|
|
443
443
|
'aria-valuenow': String(steps.done),
|
|
444
|
-
'aria-valuetext': this.
|
|
444
|
+
'aria-valuetext': this.msgPlural('runStatus.steps', steps.total, done, total)
|
|
445
445
|
}, h('span', { class: 'zx-run-status__bar-fill', style: { inlineSize: `${steps.percent}%` } })),
|
|
446
446
|
h('span', { class: 'zx-run-status__steps-text', 'aria-hidden': 'true' }, `${done}/${total}`));
|
|
447
447
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Component } from '../../core/component.js';
|
|
2
|
+
import { h } from '../../core/dom.js';
|
|
3
|
+
import { getLanguage } from '../../core/i18n.js';
|
|
4
|
+
import { COUNTRY_CODES, flagRenderer, normalizeRegion } from '../flag/flag.js';
|
|
5
|
+
|
|
6
|
+
/** @typedef {import('./select.js').SelectOptions} SelectOptions */
|
|
7
|
+
/** @typedef {import('../flag/flag.js').FlagMode} FlagMode */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A country the picker offers, when a bare code is not enough.
|
|
11
|
+
* @typedef {Object} CountryItem
|
|
12
|
+
* @property {string} code ISO 3166-1 alpha-2 code (`'DE'`).
|
|
13
|
+
* @property {string} [name] Label, replacing the one `Intl.DisplayNames` gives.
|
|
14
|
+
* @property {string} [description] Secondary text, such as a calling code or a currency.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} CountrySelectOptions
|
|
18
|
+
* @property {Array<string|CountryItem>} [countries] The countries to offer. Without it, every
|
|
19
|
+
* ISO 3166-1 country (`COUNTRY_CODES`). A code that is not two letters is left out.
|
|
20
|
+
* @property {Array<string|CountryItem>} [preferred=[]] Countries pinned above the list, in the
|
|
21
|
+
* order given and kept through filtering — the markets an application serves, say.
|
|
22
|
+
* @property {string|null} [preferredLabel=null] Heading above the pinned countries.
|
|
23
|
+
* @property {string|null} [displayLocale=null] The language country names are written in. By
|
|
24
|
+
* default the component's `lang` option, then the library language (`setLanguage()`).
|
|
25
|
+
* @property {FlagMode} [flags='auto'] What stands before each country: its flag (`auto` draws flag
|
|
26
|
+
* emoji where the platform has them and a code chip where it does not; `emoji` forces the emoji),
|
|
27
|
+
* the code chip (`code`), nothing (`none`), or a function returning the content.
|
|
28
|
+
* @property {string|null} [flagUrl=null] Flag image URL template, such as `'/flags/{code}.svg'`;
|
|
29
|
+
* `{code}` is the lower-case code, `{CODE}` the upper-case. Draws flags from the application's
|
|
30
|
+
* own flag set instead of emoji.
|
|
31
|
+
* @property {boolean} [showCode=false] Shows the ISO code as secondary text.
|
|
32
|
+
* @property {boolean} [sort=true] Orders the countries by name in the display language; `false`
|
|
33
|
+
* keeps the order given.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds the items a country picker lists, without the DOM: one `{ID, name, description, alias}`
|
|
38
|
+
* per valid code, where `alias` is the English name. Exposed for a table or a summary that names
|
|
39
|
+
* countries the same way.
|
|
40
|
+
* @param {Array<string|CountryItem>} [countries=COUNTRY_CODES] Codes or country items.
|
|
41
|
+
* @param {Pick<CountrySelectOptions, 'displayLocale'|'showCode'|'sort'>} [options={}] Naming options.
|
|
42
|
+
* @returns {Array<{ID: string, name: string, description: string, alias: string}>}
|
|
43
|
+
*/
|
|
44
|
+
export function countryItems(countries = COUNTRY_CODES, options = {}) {
|
|
45
|
+
const displayLocale = options.displayLocale || getLanguage() || 'en';
|
|
46
|
+
const names = displayNames(displayLocale);
|
|
47
|
+
const english = displayNames('en');
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
const items = [];
|
|
50
|
+
for (const entry of Array.isArray(countries) ? countries : []) {
|
|
51
|
+
const spec = typeof entry === 'string' ? { code: entry } : entry;
|
|
52
|
+
const code = normalizeRegion(spec?.code);
|
|
53
|
+
if (!code || seen.has(code)) continue;
|
|
54
|
+
seen.add(code);
|
|
55
|
+
items.push({
|
|
56
|
+
ID: code,
|
|
57
|
+
name: String(spec.name ?? names?.of(code) ?? code),
|
|
58
|
+
description: String(spec.description ?? (options.showCode ? code : '')),
|
|
59
|
+
alias: String(english?.of(code) ?? code)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (options.sort ?? true) {
|
|
63
|
+
const collator = new Intl.Collator(displayLocale);
|
|
64
|
+
items.sort((a, b) => collator.compare(a.name, b.name));
|
|
65
|
+
}
|
|
66
|
+
return items;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Turns country preset options into the Select options behind them.
|
|
71
|
+
* @param {CountrySelectOptions & SelectOptions} options Country preset options.
|
|
72
|
+
* @returns {SelectOptions}
|
|
73
|
+
*/
|
|
74
|
+
export function countrySelectOptions(options) {
|
|
75
|
+
const {
|
|
76
|
+
countries = COUNTRY_CODES, preferred = [], preferredLabel = null, displayLocale = null,
|
|
77
|
+
flags = 'auto', flagUrl = null, showCode = false, sort = true, value = null, ...rest
|
|
78
|
+
} = options ?? {};
|
|
79
|
+
const naming = { displayLocale: displayLocale || rest.lang || rest.language || getLanguage(), showCode };
|
|
80
|
+
const items = countryItems(countries, { ...naming, sort });
|
|
81
|
+
const pinned = countryItems(preferred, { ...naming, sort: false });
|
|
82
|
+
const drawFlag = flagRenderer(flags, flagUrl);
|
|
83
|
+
const visual = (item) => drawFlag(item.ID, item.ID, item);
|
|
84
|
+
return {
|
|
85
|
+
filter: 'local',
|
|
86
|
+
...rest,
|
|
87
|
+
label: rest.label || message('countryPicker.label', options),
|
|
88
|
+
placeholder: rest.placeholder || message('countryPicker.placeholder', options),
|
|
89
|
+
items,
|
|
90
|
+
fixedItems: pinned,
|
|
91
|
+
fixedLabel: pinned.length ? preferredLabel : null,
|
|
92
|
+
valueKey: 'ID',
|
|
93
|
+
labelKey: 'name',
|
|
94
|
+
searchKeys: ['name', 'ID', 'alias', 'description'],
|
|
95
|
+
value: typeof value === 'string' ? normalizeRegion(value) ?? value : value,
|
|
96
|
+
renderItem: (item) => pickerRow(visual(item), item.name, item.description),
|
|
97
|
+
renderValueAdornment: (item) => visual(item)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Draws one picker row with the Select entity anatomy: a visual, a label, and secondary text.
|
|
103
|
+
* @param {Node|string|null} visual Flag or chip.
|
|
104
|
+
* @param {string} label Primary text.
|
|
105
|
+
* @param {string} subtitle Secondary text, or `''`.
|
|
106
|
+
* @returns {HTMLElement}
|
|
107
|
+
*/
|
|
108
|
+
function pickerRow(visual, label, subtitle) {
|
|
109
|
+
return h('span', { class: 'zx-select__entity' },
|
|
110
|
+
visual ? h('span', { class: 'zx-select__entity-icon', ariaHidden: 'true' }, visual) : null,
|
|
111
|
+
h('span', { class: 'zx-select__entity-copy' },
|
|
112
|
+
h('span', { class: 'zx-select__entity-label' }, label),
|
|
113
|
+
subtitle ? h('span', { class: 'zx-select__entity-subtitle' }, subtitle) : null));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @param {string} locale Display locale.
|
|
118
|
+
* @returns {Intl.DisplayNames|null}
|
|
119
|
+
*/
|
|
120
|
+
function displayNames(locale) {
|
|
121
|
+
try {
|
|
122
|
+
return new Intl.DisplayNames([locale, 'en'], { type: 'region', fallback: 'code' });
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Resolves a message before the instance exists, honouring the picker's own `msg` option.
|
|
130
|
+
* @param {string} key Message key.
|
|
131
|
+
* @param {Record<string, any>} options Options the picker was given.
|
|
132
|
+
* @returns {string}
|
|
133
|
+
*/
|
|
134
|
+
function message(key, options) {
|
|
135
|
+
return Component.prototype.msg.call({ options }, key);
|
|
136
|
+
}
|
|
@@ -2,7 +2,8 @@ import { Field } from '../field/field.js';
|
|
|
2
2
|
import { Select } from './select.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Registers the Select-backed `zxselect` field type.
|
|
5
|
+
* Registers the Select-backed `zxselect` field type. `props.preset` picks a preset: `'priority'`,
|
|
6
|
+
* `'status'`, `'locale'`, or `'country'`.
|
|
6
7
|
* @returns {void}
|
|
7
8
|
*/
|
|
8
9
|
export function registerSelectFieldAdapter() {
|
|
@@ -20,7 +21,11 @@ export function registerSelectFieldAdapter() {
|
|
|
20
21
|
? Select.priority(null, selectOptions)
|
|
21
22
|
: preset === 'status'
|
|
22
23
|
? Select.status(null, selectOptions)
|
|
23
|
-
:
|
|
24
|
+
: preset === 'locale'
|
|
25
|
+
? Select.locale(null, selectOptions)
|
|
26
|
+
: preset === 'country'
|
|
27
|
+
? Select.country(null, selectOptions)
|
|
28
|
+
: new Select(null, selectOptions));
|
|
24
29
|
field.listen(select.el, 'change', (event) => event.stopImmediatePropagation());
|
|
25
30
|
select.on('change', (event) => field.emit('change', { value: event.detail.value }));
|
|
26
31
|
return {
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Component } from '../../core/component.js';
|
|
2
|
+
import { h } from '../../core/dom.js';
|
|
3
|
+
import { getLanguage } from '../../core/i18n.js';
|
|
4
|
+
import { flagRenderer, normalizeRegion } from '../flag/flag.js';
|
|
5
|
+
|
|
6
|
+
/** @typedef {import('./select.js').SelectOptions} SelectOptions */
|
|
7
|
+
/** @typedef {import('../flag/flag.js').FlagMode} FlagMode */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A locale the picker offers, when a bare tag is not enough.
|
|
11
|
+
* @typedef {Object} LocaleItem
|
|
12
|
+
* @property {string} code BCP 47 language tag (`'de'`, `'de-AT'`, `'zh-Hant-TW'`).
|
|
13
|
+
* @property {string} [name] Label, replacing the one `Intl.DisplayNames` gives.
|
|
14
|
+
* @property {string} [description] Secondary text, replacing the localized name.
|
|
15
|
+
* @property {string|null} [region] Flag region, replacing the one the tag implies; `null` draws the
|
|
16
|
+
* language chip instead of a flag.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} LocaleSelectOptions
|
|
20
|
+
* @property {Array<string|LocaleItem>} [locales] The locales to offer, in the order given. Tags are
|
|
21
|
+
* canonicalized (`'de_at'` → `'de-AT'`); an invalid tag is left out. Without it the picker offers
|
|
22
|
+
* a short list of widely used languages.
|
|
23
|
+
* @property {Array<string|LocaleItem>} [preferred=[]] Locales pinned above the list, kept through
|
|
24
|
+
* filtering — the application's own languages above a long list, say.
|
|
25
|
+
* @property {string|null} [preferredLabel=null] Heading above the pinned locales.
|
|
26
|
+
* @property {string|null} [displayLocale=null] The language the secondary name is written in. By
|
|
27
|
+
* default the component's `lang` option, then the library language (`setLanguage()`).
|
|
28
|
+
* @property {'both'|'native'|'localized'} [display='both'] `native` names each locale in its own
|
|
29
|
+
* language ("Deutsch"), `localized` in the display language ("German"), and `both` shows the
|
|
30
|
+
* native name with the localized one beneath it where the two differ — so a reader finds their
|
|
31
|
+
* language whichever language the interface is in.
|
|
32
|
+
* @property {FlagMode} [flags='auto'] What stands before each locale: the flag of its region
|
|
33
|
+
* (`auto` draws flag emoji where the platform has them and a language chip where it does not;
|
|
34
|
+
* `emoji` forces the emoji), a language chip (`code`, the honest choice where a language is not a
|
|
35
|
+
* country), nothing (`none`), or a function returning the content.
|
|
36
|
+
* @property {string|null} [flagUrl=null] Flag image URL template, such as `'/flags/{code}.svg'`;
|
|
37
|
+
* `{code}` is the lower-case region, `{CODE}` the upper-case. Draws flags from the application's
|
|
38
|
+
* own flag set instead of emoji.
|
|
39
|
+
* @property {Record<string, string|null>} [flagRegions={}] Flag region per tag or language, for a
|
|
40
|
+
* language whose likely region is not the one the application means: `{ en: 'GB' }`. A tag with
|
|
41
|
+
* a region of its own (`en-US`) keeps it unless it is listed here itself.
|
|
42
|
+
* @property {boolean} [sort=false] Orders the locales by label rather than as given.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/** Languages offered when the application names none, as a starting point. */
|
|
46
|
+
const DEFAULT_LOCALES = Object.freeze([
|
|
47
|
+
'en', 'de', 'fr', 'es', 'it', 'pt', 'nl', 'pl', 'cs', 'sv', 'da', 'fi', 'nb', 'tr', 'ru', 'uk',
|
|
48
|
+
'el', 'ar', 'he', 'hi', 'ja', 'ko', 'zh'
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Builds the items a locale picker lists, without the DOM: one `{ID, name, nameLang, description,
|
|
53
|
+
* region, language}` per valid tag; `nameLang` is the language `name` is written in. Exposed for
|
|
54
|
+
* a table or a summary that names locales the same way.
|
|
55
|
+
* @param {Array<string|LocaleItem>} locales Tags or locale items.
|
|
56
|
+
* @param {Pick<LocaleSelectOptions, 'displayLocale'|'display'|'flagRegions'|'sort'>} [options={}]
|
|
57
|
+
* Naming options.
|
|
58
|
+
* @returns {Array<{ID: string, name: string, nameLang: string|null, description: string, region: string|null, language: string}>}
|
|
59
|
+
*/
|
|
60
|
+
export function localeItems(locales, options = {}) {
|
|
61
|
+
const displayLocale = options.displayLocale || getLanguage() || 'en';
|
|
62
|
+
const display = options.display ?? 'both';
|
|
63
|
+
const flagRegions = options.flagRegions ?? {};
|
|
64
|
+
const localized = displayNames(displayLocale, 'language');
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
const items = [];
|
|
67
|
+
for (const entry of Array.isArray(locales) ? locales : []) {
|
|
68
|
+
const spec = typeof entry === 'string' ? { code: entry } : entry;
|
|
69
|
+
const code = canonicalLocale(spec?.code);
|
|
70
|
+
if (!code || seen.has(code)) continue;
|
|
71
|
+
seen.add(code);
|
|
72
|
+
const locale = new Intl.Locale(code);
|
|
73
|
+
const base = locale.baseName;
|
|
74
|
+
const nativeName = capitalize(displayNames(base, 'language')?.of(base) ?? base, base);
|
|
75
|
+
const localizedName = capitalize(localized?.of(base) ?? base, displayLocale);
|
|
76
|
+
const name = spec.name ?? (display === 'localized' ? localizedName : nativeName);
|
|
77
|
+
const description = spec.description
|
|
78
|
+
?? (display === 'both' && localizedName.toLocaleLowerCase() !== nativeName.toLocaleLowerCase() ? localizedName : '');
|
|
79
|
+
items.push({
|
|
80
|
+
ID: code,
|
|
81
|
+
name: String(name),
|
|
82
|
+
nameLang: spec.name != null ? null : display === 'localized' ? displayLocale : code,
|
|
83
|
+
description: String(description),
|
|
84
|
+
region: 'region' in spec ? normalizeRegion(spec.region) : localeRegion(locale, code, flagRegions),
|
|
85
|
+
language: locale.language
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (options.sort) {
|
|
89
|
+
const collator = new Intl.Collator(displayLocale);
|
|
90
|
+
items.sort((a, b) => collator.compare(a.name, b.name));
|
|
91
|
+
}
|
|
92
|
+
return items;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Turns locale preset options into the Select options behind them.
|
|
97
|
+
* @param {LocaleSelectOptions & SelectOptions} options Locale preset options.
|
|
98
|
+
* @returns {SelectOptions}
|
|
99
|
+
*/
|
|
100
|
+
export function localeSelectOptions(options) {
|
|
101
|
+
const {
|
|
102
|
+
locales = DEFAULT_LOCALES, preferred = [], preferredLabel = null, displayLocale = null,
|
|
103
|
+
display = 'both', flags = 'auto', flagUrl = null, flagRegions = {}, sort = false,
|
|
104
|
+
value = null, ...rest
|
|
105
|
+
} = options ?? {};
|
|
106
|
+
const naming = {
|
|
107
|
+
displayLocale: displayLocale || rest.lang || rest.language || getLanguage(),
|
|
108
|
+
display,
|
|
109
|
+
flagRegions,
|
|
110
|
+
sort
|
|
111
|
+
};
|
|
112
|
+
const items = localeItems(locales, naming);
|
|
113
|
+
const pinned = localeItems(preferred, { ...naming, sort: false });
|
|
114
|
+
const drawFlag = flagRenderer(flags, flagUrl);
|
|
115
|
+
const visual = (item) => drawFlag(item.region, item.language.toUpperCase(), item);
|
|
116
|
+
return {
|
|
117
|
+
filter: items.length + pinned.length > 7 ? 'local' : false,
|
|
118
|
+
...rest,
|
|
119
|
+
label: rest.label || message('localePicker.label', options),
|
|
120
|
+
placeholder: rest.placeholder || message('localePicker.placeholder', options),
|
|
121
|
+
items,
|
|
122
|
+
fixedItems: pinned,
|
|
123
|
+
fixedLabel: pinned.length ? preferredLabel : null,
|
|
124
|
+
valueKey: 'ID',
|
|
125
|
+
labelKey: 'name',
|
|
126
|
+
searchKeys: ['name', 'description', 'ID'],
|
|
127
|
+
value: typeof value === 'string' ? canonicalLocale(value) ?? value : value,
|
|
128
|
+
renderItem: (item) => pickerRow(visual(item), item.name, item.description, item.nameLang),
|
|
129
|
+
renderValueAdornment: (item) => visual(item)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Draws one picker row with the Select entity anatomy: a visual, a label, and secondary text.
|
|
135
|
+
* @param {Node|string|null} visual Flag or chip.
|
|
136
|
+
* @param {string} label Primary text.
|
|
137
|
+
* @param {string} subtitle Secondary text, or `''`.
|
|
138
|
+
* @param {string|null} labelLang Language of the label, so a screen reader speaks "Deutsch" in German.
|
|
139
|
+
* @returns {HTMLElement}
|
|
140
|
+
*/
|
|
141
|
+
function pickerRow(visual, label, subtitle, labelLang) {
|
|
142
|
+
return h('span', { class: 'zx-select__entity' },
|
|
143
|
+
visual ? h('span', { class: 'zx-select__entity-icon', ariaHidden: 'true' }, visual) : null,
|
|
144
|
+
h('span', { class: 'zx-select__entity-copy' },
|
|
145
|
+
h('span', { class: 'zx-select__entity-label', ...(labelLang ? { lang: labelLang } : {}) }, label),
|
|
146
|
+
subtitle ? h('span', { class: 'zx-select__entity-subtitle' }, subtitle) : null));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Canonicalizes a BCP 47 tag, accepting `_` for `-`.
|
|
151
|
+
* @param {unknown} tag Candidate tag.
|
|
152
|
+
* @returns {string|null} The canonical tag, or null when it is not one.
|
|
153
|
+
*/
|
|
154
|
+
export function canonicalLocale(tag) {
|
|
155
|
+
if (typeof tag !== 'string' || !tag.trim()) return null;
|
|
156
|
+
try {
|
|
157
|
+
return Intl.getCanonicalLocales(tag.trim().replaceAll('_', '-'))[0] ?? null;
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The flag region of a locale: an override for the tag or its language, else its own region, else
|
|
165
|
+
* the likely region of its language (`de` → `DE`, `ja` → `JP`).
|
|
166
|
+
* @param {Intl.Locale} locale Parsed locale.
|
|
167
|
+
* @param {string} code Canonical tag.
|
|
168
|
+
* @param {Record<string, string|null>} overrides `flagRegions`.
|
|
169
|
+
* @returns {string|null}
|
|
170
|
+
*/
|
|
171
|
+
function localeRegion(locale, code, overrides) {
|
|
172
|
+
if (Object.hasOwn(overrides, code)) return normalizeRegion(overrides[code]);
|
|
173
|
+
if (locale.region) return normalizeRegion(locale.region);
|
|
174
|
+
if (Object.hasOwn(overrides, locale.language)) return normalizeRegion(overrides[locale.language]);
|
|
175
|
+
try {
|
|
176
|
+
return normalizeRegion(locale.maximize().region);
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @param {string} locale Display locale.
|
|
184
|
+
* @param {'language'|'region'} type Name type.
|
|
185
|
+
* @returns {Intl.DisplayNames|null}
|
|
186
|
+
*/
|
|
187
|
+
function displayNames(locale, type) {
|
|
188
|
+
try {
|
|
189
|
+
return new Intl.DisplayNames([locale, 'en'], { type, fallback: 'code', languageDisplay: 'standard' });
|
|
190
|
+
} catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Upper-cases the first letter in the given locale's rules: some languages name themselves in
|
|
197
|
+
* lower case ("français"), which reads as a typo at the head of a list row.
|
|
198
|
+
* @param {string} text Name.
|
|
199
|
+
* @param {string} locale Locale of the name.
|
|
200
|
+
* @returns {string}
|
|
201
|
+
*/
|
|
202
|
+
function capitalize(text, locale) {
|
|
203
|
+
const [first = '', ...rest] = String(text);
|
|
204
|
+
try {
|
|
205
|
+
return first.toLocaleUpperCase(locale) + rest.join('');
|
|
206
|
+
} catch {
|
|
207
|
+
return first.toUpperCase() + rest.join('');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Resolves a message before the instance exists, honouring the picker's own `msg` option.
|
|
213
|
+
* @param {string} key Message key.
|
|
214
|
+
* @param {Record<string, any>} options Options the picker was given.
|
|
215
|
+
* @returns {string}
|
|
216
|
+
*/
|
|
217
|
+
function message(key, options) {
|
|
218
|
+
return Component.prototype.msg.call({ options }, key);
|
|
219
|
+
}
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
|
|
27
27
|
.zx-select__value-adornment[hidden] { display: none; }
|
|
28
28
|
|
|
29
|
-
.zx-select__value-adornment:not([hidden]) + .zx-select__input {
|
|
30
|
-
padding-inline-start: var(--zx-space-2)
|
|
29
|
+
.zx-select .zx-select__value-adornment:not([hidden]) + .zx-select__input {
|
|
30
|
+
padding-inline-start: var(--zx-space-2);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/* The ring follows keyboard focus. A text input matches :focus-visible on a click as well, so the
|
|
@@ -37,32 +37,31 @@
|
|
|
37
37
|
box-shadow: var(--zx-focus-ring);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
.zx-select__input {
|
|
40
|
+
.zx-select .zx-select__input {
|
|
41
41
|
grid-column: 2;
|
|
42
42
|
inline-size: 100%;
|
|
43
43
|
min-inline-size: 0;
|
|
44
|
-
min-block-size: calc(var(--zx-control-height) - 2px)
|
|
45
|
-
border: 0
|
|
46
|
-
border-radius: 0
|
|
47
|
-
background: none
|
|
48
|
-
box-shadow: none
|
|
44
|
+
min-block-size: calc(var(--zx-control-height) - 2px);
|
|
45
|
+
border: 0;
|
|
46
|
+
border-radius: 0;
|
|
47
|
+
background: none;
|
|
48
|
+
box-shadow: none;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
.zx-select__input:read-only {
|
|
52
52
|
cursor: default;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
.zx-select__clear,
|
|
56
|
-
.zx-select__toggle {
|
|
55
|
+
.zx-select .zx-select__control :is(.zx-select__clear, .zx-select__toggle) {
|
|
57
56
|
display: grid;
|
|
58
57
|
place-items: center;
|
|
59
58
|
inline-size: var(--zx-control-height);
|
|
60
|
-
min-block-size: calc(var(--zx-control-height) - 2px)
|
|
61
|
-
border: 0
|
|
62
|
-
border-radius: 0
|
|
63
|
-
background: none
|
|
59
|
+
min-block-size: calc(var(--zx-control-height) - 2px);
|
|
60
|
+
border: 0;
|
|
61
|
+
border-radius: 0;
|
|
62
|
+
background: none;
|
|
64
63
|
color: var(--zx-color-text-muted);
|
|
65
|
-
padding: 0
|
|
64
|
+
padding: 0;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
.zx-select__clear { grid-column: 3; }
|
|
@@ -70,19 +69,19 @@
|
|
|
70
69
|
.zx-select__toggle { grid-column: 5; align-self: stretch; }
|
|
71
70
|
.zx-select__toggle > .zx-icon { display: block; }
|
|
72
71
|
|
|
73
|
-
.zx-select__clear:hover,
|
|
74
|
-
.zx-select__toggle:hover {
|
|
72
|
+
.zx-select .zx-select__clear:hover,
|
|
73
|
+
.zx-select .zx-select__toggle:hover {
|
|
75
74
|
color: var(--zx-color-text);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
.zx-select__clear[hidden],
|
|
77
|
+
.zx-select .zx-select__clear[hidden],
|
|
79
78
|
.zx-select__loading[hidden] {
|
|
80
79
|
display: none;
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
.zx-select__loading {
|
|
84
|
-
inline-size:
|
|
85
|
-
block-size:
|
|
83
|
+
inline-size: calc(var(--zx-control-height) / 2 - 1px);
|
|
84
|
+
block-size: calc(var(--zx-control-height) / 2 - 1px);
|
|
86
85
|
border: 2px solid var(--zx-color-border);
|
|
87
86
|
border-block-start-color: var(--zx-color-accent);
|
|
88
87
|
border-radius: var(--zx-radius-full);
|
|
@@ -91,7 +90,7 @@
|
|
|
91
90
|
/* Disabled reads the way a disabled Field does: text and frame fade together, nothing else
|
|
92
91
|
changes. Inside a disabled Field the field has already faded, so the Select does not again. */
|
|
93
92
|
.zx-select[aria-disabled="true"] {
|
|
94
|
-
opacity:
|
|
93
|
+
opacity: var(--zx-control-disabled-opacity);
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
.zx-field[data-disabled="true"] .zx-select[aria-disabled="true"] {
|
|
@@ -103,7 +102,6 @@
|
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
.zx-select__panel {
|
|
106
|
-
z-index: 20;
|
|
107
105
|
inline-size: max-content;
|
|
108
106
|
max-inline-size: calc(100vw - var(--zx-space-4));
|
|
109
107
|
overflow: hidden;
|