@zeyos/zx 5.6.0 → 5.7.0
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 +154 -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/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/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/multi-value-editor/multi-value-editor.d.ts +3 -2
- package/dist/types/components/number-field/number-field.d.ts +17 -6
- 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/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 +1 -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 +16802 -15180
- 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 +498 -134
- package/dist/zx.esm.js +40778 -29654
- package/dist/zx.esm.min.js +36 -23
- package/dist/zx.global.js +40778 -29654
- package/dist/zx.global.min.js +36 -23
- package/dist/zx.layered.css +17302 -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 +851 -121
- package/docs/llms.md +1018 -71
- 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/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/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 +1 -1
- 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/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 +29 -13
- 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/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 +22 -2
- package/src/core/format.js +15 -13
- package/src/core/http.js +29 -20
- package/src/core/i18n.js +83 -10
- 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/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
package/src/core/component.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { h, resolveElement } from './dom.js';
|
|
3
|
-
import { defaultMessage, getLanguage, hostMessage, legacyMessageKey, printf } from './i18n.js';
|
|
3
|
+
import { defaultMessage, getLanguage, hostMessage, legacyMessageKey, pluralKeys, pluralMessage, printf } from './i18n.js';
|
|
4
4
|
import { deepMerge, isElement } from './util.js';
|
|
5
5
|
|
|
6
6
|
/** @typedef {Record<string, any>} ComponentOptions */
|
|
@@ -249,6 +249,30 @@ export class Component extends EventTarget {
|
|
|
249
249
|
return printf(text, args);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Resolves a cardinal plural message, keeping the numeric count separate from displayed values.
|
|
254
|
+
* Each source tries the selected category, `other`, and the unsuffixed/legacy key before moving
|
|
255
|
+
* from instance messages to the host, class defaults, and finally English plural rules.
|
|
256
|
+
* @param {string} key Unsuffixed message key.
|
|
257
|
+
* @param {number} count Finite numeric count.
|
|
258
|
+
* @param {...unknown} args Positional interpolation values.
|
|
259
|
+
* @returns {string}
|
|
260
|
+
*/
|
|
261
|
+
msgPlural(key, count, ...args) {
|
|
262
|
+
const lang = this.options?.lang ?? this.options?.language ?? getLanguage();
|
|
263
|
+
const keys = pluralKeys(key, count, lang);
|
|
264
|
+
const tables = messageTables.get(this) ?? {
|
|
265
|
+
own: isMessageTable(this.options?.msg) ? this.options.msg : null,
|
|
266
|
+
inherited: null
|
|
267
|
+
};
|
|
268
|
+
const text = pluralMessage(keys, (candidate) => pickMessage(tables.own, lang, candidate))
|
|
269
|
+
?? pluralMessage(keys, hostMessage)
|
|
270
|
+
?? pluralMessage(keys, (candidate) => pickMessage(tables.inherited, lang, candidate))
|
|
271
|
+
?? pluralMessage(pluralKeys(key, count, 'en'), defaultMessage)
|
|
272
|
+
?? key;
|
|
273
|
+
return printf(text, args);
|
|
274
|
+
}
|
|
275
|
+
|
|
252
276
|
/**
|
|
253
277
|
* Aborts listeners, unregisters the component, and removes roots created by the component.
|
|
254
278
|
* Safe to call repeatedly.
|
package/src/core/date.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import { getLanguage,
|
|
2
|
+
import { formattingLocale, getLanguage, hostMessage } from './i18n.js';
|
|
3
3
|
|
|
4
4
|
const MONTHS = [
|
|
5
5
|
'January', 'February', 'March', 'April', 'May', 'June',
|
|
6
6
|
'July', 'August', 'September', 'October', 'November', 'December'
|
|
7
7
|
];
|
|
8
8
|
const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
9
|
+
const ENGLISH_NAMES = { month: MONTHS, weekday: WEEKDAYS };
|
|
9
10
|
const TOKEN_PATTERN = /%[demYyHMSaAbBs]/g;
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* `Intl` formatters for month and weekday names, under their locale and style, because a calendar
|
|
14
|
+
* formats dozens of cells per render. A locale `Intl` cannot use is cached as null: one it refuses,
|
|
15
|
+
* and one it has no data for, which it would otherwise answer in the runtime's own language.
|
|
16
|
+
* @type {Map<string, Intl.DateTimeFormat|null>}
|
|
17
|
+
*/
|
|
18
|
+
const nameFormatters = new Map();
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Formats a local Date using strftime-style kernel tokens.
|
|
22
|
+
*
|
|
23
|
+
* Month and weekday names come from the host translator's `date.month.*` and `date.weekday.*` keys
|
|
24
|
+
* when no explicit locale is given, and otherwise from `Intl` in the effective formatting locale.
|
|
25
|
+
* Explicit supported locales take precedence over host translations.
|
|
13
26
|
* @param {Date} date Date to format.
|
|
14
27
|
* @param {string} fmt Format containing `%d %e %m %Y %y %H %M %S %a %A %b %B %s` tokens.
|
|
28
|
+
* @param {{locale?: string|null}|null} [options] `locale` defaults to `getLanguage()`.
|
|
15
29
|
* @returns {string}
|
|
16
30
|
*/
|
|
17
|
-
export function formatDate(date, fmt) {
|
|
31
|
+
export function formatDate(date, fmt, options) {
|
|
32
|
+
const locale = formattingLocale(options?.locale, Intl.DateTimeFormat);
|
|
33
|
+
const useHost = options?.locale == null;
|
|
18
34
|
if (!(date instanceof Date) || Number.isNaN(date.getTime())) return '';
|
|
19
35
|
return String(fmt).replace(TOKEN_PATTERN, (token) => {
|
|
20
36
|
switch (token) {
|
|
@@ -26,10 +42,10 @@ export function formatDate(date, fmt) {
|
|
|
26
42
|
case '%H': return pad(date.getHours());
|
|
27
43
|
case '%M': return pad(date.getMinutes());
|
|
28
44
|
case '%S': return pad(date.getSeconds());
|
|
29
|
-
case '%a': return localizedShortName('weekday', date
|
|
30
|
-
case '%A': return localizedName('weekday', date
|
|
31
|
-
case '%b': return localizedShortName('month', date
|
|
32
|
-
case '%B': return localizedName('month', date
|
|
45
|
+
case '%a': return localizedShortName('weekday', date, locale, useHost);
|
|
46
|
+
case '%A': return localizedName('weekday', date, locale, useHost);
|
|
47
|
+
case '%b': return localizedShortName('month', date, locale, useHost);
|
|
48
|
+
case '%B': return localizedName('month', date, locale, useHost);
|
|
33
49
|
case '%s': return String(Math.floor(date.getTime() / 1000));
|
|
34
50
|
default: return token;
|
|
35
51
|
}
|
|
@@ -174,19 +190,49 @@ function pad(value) {
|
|
|
174
190
|
return String(value).padStart(2, '0');
|
|
175
191
|
}
|
|
176
192
|
|
|
177
|
-
/** @param {'month'|'weekday'} type @param {
|
|
178
|
-
function
|
|
193
|
+
/** @param {'month'|'weekday'} type @param {Date} date @returns {number} */
|
|
194
|
+
function nameIndex(type, date) {
|
|
195
|
+
return type === 'month' ? date.getMonth() : date.getDay();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @param {'month'|'weekday'} type @param {Date} date @param {string|string[]} locale @param {boolean} useHost @returns {string} */
|
|
199
|
+
function localizedName(type, date, locale, useHost) {
|
|
200
|
+
const index = nameIndex(type, date);
|
|
179
201
|
const key = `date.${type}.${index}`;
|
|
180
|
-
const value =
|
|
181
|
-
|
|
202
|
+
const value = useHost ? hostMessage(key) : null;
|
|
203
|
+
if (value !== null) return value;
|
|
204
|
+
return nameFormatter(type, 'long', locale)?.format(date) ?? ENGLISH_NAMES[type][index];
|
|
182
205
|
}
|
|
183
206
|
|
|
184
|
-
/** @param {'month'|'weekday'} type @param {
|
|
185
|
-
function localizedShortName(type,
|
|
186
|
-
const
|
|
187
|
-
const shortValue =
|
|
188
|
-
if (shortValue !==
|
|
189
|
-
return
|
|
207
|
+
/** @param {'month'|'weekday'} type @param {Date} date @param {string|string[]} locale @param {boolean} useHost @returns {string} */
|
|
208
|
+
function localizedShortName(type, date, locale, useHost) {
|
|
209
|
+
const index = nameIndex(type, date);
|
|
210
|
+
const shortValue = useHost ? hostMessage(`date.${type}.short.${index}`) : null;
|
|
211
|
+
if (shortValue !== null) return shortValue;
|
|
212
|
+
return nameFormatter(type, 'short', locale)?.format(date) ?? ENGLISH_NAMES[type][index].slice(0, 3);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The cached `Intl` formatter for one kind of name, or null when the English constants answer.
|
|
217
|
+
* The calendar is fixed because `%d`, `%m` and `%Y` are Gregorian in every locale.
|
|
218
|
+
* @param {'month'|'weekday'} type Kind of name.
|
|
219
|
+
* @param {'long'|'short'} style Length of the name.
|
|
220
|
+
* @param {string|string[]} locale BCP 47 language tag or locale list.
|
|
221
|
+
* @returns {Intl.DateTimeFormat|null}
|
|
222
|
+
*/
|
|
223
|
+
function nameFormatter(type, style, locale) {
|
|
224
|
+
const key = `${locale}\u0000${type}\u0000${style}`;
|
|
225
|
+
let formatter = nameFormatters.get(key);
|
|
226
|
+
if (formatter === undefined) {
|
|
227
|
+
try {
|
|
228
|
+
formatter = Intl.DateTimeFormat.supportedLocalesOf(locale).length > 0
|
|
229
|
+
? new Intl.DateTimeFormat(locale, { [type]: style, calendar: 'gregory' }) : null;
|
|
230
|
+
} catch {
|
|
231
|
+
formatter = null;
|
|
232
|
+
}
|
|
233
|
+
nameFormatters.set(key, formatter);
|
|
234
|
+
}
|
|
235
|
+
return formatter;
|
|
190
236
|
}
|
|
191
237
|
|
|
192
238
|
/** @param {string} token @returns {string|null} */
|
package/src/core/dom.js
CHANGED
|
@@ -20,6 +20,9 @@ const DOM_BUILDER_PROPERTIES = new Set([
|
|
|
20
20
|
'href', 'id', 'lang', 'name', 'rel', 'src', 'target', 'title', 'value'
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
|
+
/** HTML parsing belongs only to the explicit trusted `h.raw()` path. */
|
|
24
|
+
const HTML_SINK_PROPERTIES = new Set(['innerhtml', 'outerhtml', 'srcdoc']);
|
|
25
|
+
|
|
23
26
|
/** @type {WeakMap<EventTarget, Map<string, {handlers: Function[], listener: EventListener}>>} */
|
|
24
27
|
const compactEvents = new WeakMap();
|
|
25
28
|
|
|
@@ -208,16 +211,23 @@ export function fragment(...children) {
|
|
|
208
211
|
* @param {(HProps & Record<string, any>)|DomChild} [props] Properties and attributes, or the first child.
|
|
209
212
|
* @param {...DomChild} children Child values.
|
|
210
213
|
* @returns {HTMLElement}
|
|
214
|
+
* @throws {TypeError} When properties contain an HTML sink; use `h.raw()` for trusted HTML.
|
|
211
215
|
*/
|
|
212
216
|
export function h(tag, props, ...children) {
|
|
213
|
-
const element = document.createElement(tag);
|
|
214
217
|
let properties = props;
|
|
215
218
|
if (!isPropsObject(properties)) {
|
|
216
219
|
children.unshift(/** @type {DomChild} */ (properties));
|
|
217
220
|
properties = {};
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
|
|
223
|
+
const entries = Object.entries(properties);
|
|
224
|
+
for (const [key] of entries) {
|
|
225
|
+
if (HTML_SINK_PROPERTIES.has(key.toLowerCase())) {
|
|
226
|
+
throw new TypeError(`HTML property ${key} requires trusted h.raw() content`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const element = document.createElement(tag);
|
|
230
|
+
for (const [key, value] of entries) {
|
|
221
231
|
applyProperty(element, key, value);
|
|
222
232
|
}
|
|
223
233
|
appendChildren(element, children);
|
|
@@ -365,6 +375,16 @@ function isPropsObject(value) {
|
|
|
365
375
|
|
|
366
376
|
/** @param {HTMLElement} element @param {string} key @param {any} value @returns {void} */
|
|
367
377
|
function applyProperty(element, key, value) {
|
|
378
|
+
if (key.toLowerCase() === 'href') {
|
|
379
|
+
const href = safeHref(value);
|
|
380
|
+
if (href !== null) {
|
|
381
|
+
if ('href' in element) {
|
|
382
|
+
try { element.href = href; return; } catch { /* Attribute fallback for read-only properties. */ }
|
|
383
|
+
}
|
|
384
|
+
element.setAttribute('href', href);
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
368
388
|
if (key === 'ref') {
|
|
369
389
|
if (activeRefs && typeof value === 'string') activeRefs[value] = element;
|
|
370
390
|
return;
|
package/src/core/format.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import {
|
|
2
|
+
import { formattingLocale } from './i18n.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {Object} NumberFormatOptions
|
|
@@ -77,7 +77,7 @@ const relativeFormatters = new Map();
|
|
|
77
77
|
export function formatNumber(value, options = {}) {
|
|
78
78
|
const number = toFiniteNumber(value);
|
|
79
79
|
if (number === null) return '';
|
|
80
|
-
const { locale
|
|
80
|
+
const { locale, decimals, minDecimals, maxDecimals, group = true } = options;
|
|
81
81
|
return format(locale, digitOptions({ decimals, minDecimals, maxDecimals, group }), number);
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -92,7 +92,7 @@ export function formatNumber(value, options = {}) {
|
|
|
92
92
|
export function formatCurrency(value, currency, options = {}) {
|
|
93
93
|
const number = toFiniteNumber(value);
|
|
94
94
|
if (number === null) return '';
|
|
95
|
-
const { locale
|
|
95
|
+
const { locale, decimals } = options;
|
|
96
96
|
const code = currencyCode(currency);
|
|
97
97
|
if (code === null) return formatNumber(number, { locale, decimals });
|
|
98
98
|
|
|
@@ -109,7 +109,7 @@ export function formatCurrency(value, currency, options = {}) {
|
|
|
109
109
|
export function formatPercent(value, options = {}) {
|
|
110
110
|
const number = toFiniteNumber(value);
|
|
111
111
|
if (number === null) return '';
|
|
112
|
-
const { locale
|
|
112
|
+
const { locale, decimals = 0 } = options;
|
|
113
113
|
return format(locale, { ...digitOptions({ decimals, group: true }), style: 'percent' }, number);
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -122,7 +122,7 @@ export function formatPercent(value, options = {}) {
|
|
|
122
122
|
export function formatFileSize(bytes, options = {}) {
|
|
123
123
|
const number = toFiniteNumber(bytes);
|
|
124
124
|
if (number === null) return '';
|
|
125
|
-
const { locale
|
|
125
|
+
const { locale, decimals = 1, standard = 'iec' } = options;
|
|
126
126
|
if (number === 0) return `${formatNumber(0, { locale, decimals: 0 })} B`;
|
|
127
127
|
|
|
128
128
|
const units = standard === 'si' ? SI_UNITS : IEC_UNITS;
|
|
@@ -152,7 +152,7 @@ export function formatFileSize(bytes, options = {}) {
|
|
|
152
152
|
export function formatRelativeTime(date, options = {}) {
|
|
153
153
|
const target = toDate(date);
|
|
154
154
|
if (target === null) return '';
|
|
155
|
-
const { now = new Date(), locale
|
|
155
|
+
const { now = new Date(), locale, numeric = 'auto' } = options;
|
|
156
156
|
const reference = toDate(now);
|
|
157
157
|
if (reference === null) return '';
|
|
158
158
|
|
|
@@ -165,13 +165,14 @@ export function formatRelativeTime(date, options = {}) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
* Returns a cached `Intl.NumberFormat`, falling back to the
|
|
169
|
-
* @param {string} locale BCP 47 language tag.
|
|
168
|
+
* Returns a cached `Intl.NumberFormat`, falling back to the active language for unusable locales.
|
|
169
|
+
* @param {string|string[]|undefined} locale BCP 47 language tag.
|
|
170
170
|
* @param {Intl.NumberFormatOptions} options Formatter options.
|
|
171
171
|
* @param {number} value Number to format.
|
|
172
172
|
* @returns {string}
|
|
173
173
|
*/
|
|
174
174
|
function format(locale, options, value) {
|
|
175
|
+
locale = formattingLocale(locale);
|
|
175
176
|
const key = `${locale}\u0000${JSON.stringify(options)}`;
|
|
176
177
|
let formatter = numberFormatters.get(key);
|
|
177
178
|
if (formatter === undefined) {
|
|
@@ -182,7 +183,7 @@ function format(locale, options, value) {
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
/**
|
|
185
|
-
* @param {string} locale BCP 47 language tag.
|
|
186
|
+
* @param {string|string[]|undefined} locale BCP 47 language tag.
|
|
186
187
|
* @param {Intl.NumberFormatOptions} options Formatter options.
|
|
187
188
|
* @returns {Intl.NumberFormat}
|
|
188
189
|
*/
|
|
@@ -191,27 +192,28 @@ function createNumberFormat(locale, options) {
|
|
|
191
192
|
return new Intl.NumberFormat(locale, options);
|
|
192
193
|
} catch {
|
|
193
194
|
try {
|
|
194
|
-
return new Intl.NumberFormat(
|
|
195
|
+
return new Intl.NumberFormat(formattingLocale(), options);
|
|
195
196
|
} catch {
|
|
196
197
|
// Unusable options (an unsupported currency style, say) still have to produce digits.
|
|
197
|
-
return new Intl.NumberFormat();
|
|
198
|
+
return new Intl.NumberFormat(formattingLocale());
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
/**
|
|
203
|
-
* @param {string} locale BCP 47 language tag.
|
|
204
|
+
* @param {string|string[]|undefined} locale BCP 47 language tag.
|
|
204
205
|
* @param {'auto'|'always'} numeric Numeric-phrasing mode.
|
|
205
206
|
* @returns {Intl.RelativeTimeFormat}
|
|
206
207
|
*/
|
|
207
208
|
function relativeFormatter(locale, numeric) {
|
|
209
|
+
locale = formattingLocale(locale, Intl.RelativeTimeFormat);
|
|
208
210
|
const key = `${locale}\u0000${numeric}`;
|
|
209
211
|
let formatter = relativeFormatters.get(key);
|
|
210
212
|
if (formatter === undefined) {
|
|
211
213
|
try {
|
|
212
214
|
formatter = new Intl.RelativeTimeFormat(locale, { numeric });
|
|
213
215
|
} catch {
|
|
214
|
-
formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
|
|
216
|
+
formatter = new Intl.RelativeTimeFormat(formattingLocale(undefined, Intl.RelativeTimeFormat), { numeric: 'auto' });
|
|
215
217
|
}
|
|
216
218
|
relativeFormatters.set(key, formatter);
|
|
217
219
|
}
|
package/src/core/http.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* @property {File|FileList|File[]} [files=null] Files that switch the body to FormData.
|
|
15
15
|
* @property {string|URLSearchParams|Record<string, unknown>} [query=null] Query parameters.
|
|
16
16
|
* @property {Record<string, string>} [headers={}] Per-request headers.
|
|
17
|
+
* @property {AbortSignal|null} [signal=null] Caller cancellation signal.
|
|
18
|
+
* @property {string} [paramName='files'] Multipart field name used for each file.
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
/** Dependency-free JSON fetch wrapper with legacy ZeyOS envelope handling. */
|
|
@@ -45,25 +47,29 @@ export class Http {
|
|
|
45
47
|
*/
|
|
46
48
|
async request(path, options = {}) {
|
|
47
49
|
const {
|
|
48
|
-
method = 'GET', data = null, files = null, query = null, headers = {}
|
|
50
|
+
method = 'GET', data = null, files = null, query = null, headers = {}, signal = null, paramName = 'files'
|
|
49
51
|
} = options;
|
|
50
52
|
const controller = new AbortController();
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (files !== null) {
|
|
58
|
-
body = createFormData(data, files);
|
|
59
|
-
requestHeaders.delete('Content-Type');
|
|
60
|
-
} else if (data !== null && method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'HEAD') {
|
|
61
|
-
body = JSON.stringify(data);
|
|
62
|
-
requestHeaders.set('Content-Type', requestHeaders.get('Content-Type') ?? 'application/json');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const url = appendQuery(this.base + path, query);
|
|
53
|
+
const abort = () => controller.abort(signal?.reason);
|
|
54
|
+
if (signal?.aborted) abort();
|
|
55
|
+
else signal?.addEventListener('abort', abort, { once: true });
|
|
56
|
+
const timeoutId = this.timeout > 0 ? setTimeout(() => {
|
|
57
|
+
controller.abort(new DOMException('Request timed out', 'TimeoutError'));
|
|
58
|
+
}, this.timeout) : null;
|
|
66
59
|
try {
|
|
60
|
+
controller.signal.throwIfAborted();
|
|
61
|
+
const requestHeaders = new Headers(this.headers);
|
|
62
|
+
for (const [name, value] of Object.entries(headers)) requestHeaders.set(name, value);
|
|
63
|
+
requestHeaders.set('Accept', requestHeaders.get('Accept') ?? 'application/json');
|
|
64
|
+
let body;
|
|
65
|
+
if (files !== null) {
|
|
66
|
+
body = createFormData(data, files, String(paramName));
|
|
67
|
+
requestHeaders.delete('Content-Type');
|
|
68
|
+
} else if (data !== null && method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'HEAD') {
|
|
69
|
+
body = JSON.stringify(data);
|
|
70
|
+
requestHeaders.set('Content-Type', requestHeaders.get('Content-Type') ?? 'application/json');
|
|
71
|
+
}
|
|
72
|
+
const url = appendQuery(this.base + path, query);
|
|
67
73
|
const response = await fetch(url, {
|
|
68
74
|
method: method.toUpperCase(),
|
|
69
75
|
headers: requestHeaders,
|
|
@@ -71,6 +77,7 @@ export class Http {
|
|
|
71
77
|
signal: controller.signal
|
|
72
78
|
});
|
|
73
79
|
const text = await response.text();
|
|
80
|
+
controller.signal.throwIfAborted();
|
|
74
81
|
let json = null;
|
|
75
82
|
if (text !== '') {
|
|
76
83
|
try {
|
|
@@ -110,6 +117,7 @@ export class Http {
|
|
|
110
117
|
throw error;
|
|
111
118
|
} finally {
|
|
112
119
|
if (timeoutId !== null) clearTimeout(timeoutId);
|
|
120
|
+
signal?.removeEventListener('abort', abort);
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
|
|
@@ -175,7 +183,8 @@ export function zeyosService(service, accesskey = '', options = {}) {
|
|
|
175
183
|
*/
|
|
176
184
|
export function parseResult(json) {
|
|
177
185
|
if (json && typeof json === 'object') {
|
|
178
|
-
if (Object.prototype.hasOwnProperty.call(json, 'error') && json.error != null
|
|
186
|
+
if (Object.prototype.hasOwnProperty.call(json, 'error') && json.error != null
|
|
187
|
+
&& json.error !== false && json.error !== 0) {
|
|
179
188
|
const message = typeof json.error === 'string' ? json.error : JSON.stringify(json.error);
|
|
180
189
|
throw new Error(message || 'Server error');
|
|
181
190
|
}
|
|
@@ -213,8 +222,8 @@ function appendParameter(parameters, key, value) {
|
|
|
213
222
|
}
|
|
214
223
|
}
|
|
215
224
|
|
|
216
|
-
/** @param {unknown} data @param {File|FileList|File[]} files @returns {FormData} */
|
|
217
|
-
function createFormData(data, files) {
|
|
225
|
+
/** @param {unknown} data @param {File|FileList|File[]} files @param {string} paramName @returns {FormData} */
|
|
226
|
+
function createFormData(data, files, paramName) {
|
|
218
227
|
const form = new FormData();
|
|
219
228
|
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
220
229
|
for (const [key, value] of Object.entries(data)) appendFormValue(form, key, value);
|
|
@@ -223,7 +232,7 @@ function createFormData(data, files) {
|
|
|
223
232
|
}
|
|
224
233
|
|
|
225
234
|
const list = isFileList(files) || Array.isArray(files) ? Array.from(files) : [files];
|
|
226
|
-
for (const file of list) form.append(
|
|
235
|
+
for (const file of list) form.append(paramName, file);
|
|
227
236
|
return form;
|
|
228
237
|
}
|
|
229
238
|
|
package/src/core/i18n.js
CHANGED
|
@@ -8,6 +8,8 @@ export { defaultMessages };
|
|
|
8
8
|
/** @type {Translator|null} */
|
|
9
9
|
let translator = null;
|
|
10
10
|
let language = 'en';
|
|
11
|
+
/** @type {Map<string, Intl.PluralRules>} */
|
|
12
|
+
const pluralRules = new Map();
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Installs the host application's translation function, or clears it with null. The function
|
|
@@ -88,6 +90,78 @@ export function translate(key, args) {
|
|
|
88
90
|
return printf(text, args);
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Selects a cardinal plural message before interpolation. The host's selected category, `other`,
|
|
95
|
+
* and unsuffixed message are tried before English, which uses its own plural rules.
|
|
96
|
+
* @param {string} key Unsuffixed translation key.
|
|
97
|
+
* @param {number} count Finite numeric count, independent of interpolation arguments.
|
|
98
|
+
* @param {unknown[]|Record<string, unknown>|string|number} [args] Interpolation arguments.
|
|
99
|
+
* @param {{locale?: string}} [options={}] Plural-rule locale; defaults to the active language.
|
|
100
|
+
* @returns {string}
|
|
101
|
+
*/
|
|
102
|
+
export function translatePlural(key, count, args, { locale } = {}) {
|
|
103
|
+
const text = pluralMessage(pluralKeys(key, count, locale), hostMessage)
|
|
104
|
+
?? pluralMessage(pluralKeys(key, count, 'en'), defaultMessage)
|
|
105
|
+
?? key;
|
|
106
|
+
return printf(text, args);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Resolves a supported explicit locale, then the active language, then English. Locale lists
|
|
111
|
+
* retain their preference order. Support is checked by the consuming Intl service, whose locale
|
|
112
|
+
* data may differ from NumberFormat's; internal formatting consumers share this precedence.
|
|
113
|
+
* @param {string|string[]|null} [option] Explicit locale or locale list.
|
|
114
|
+
* @param {{supportedLocalesOf: (locales: string|string[]) => string[]}} [service=Intl.NumberFormat] Consuming Intl service.
|
|
115
|
+
* @returns {string|string[]}
|
|
116
|
+
*/
|
|
117
|
+
export function formattingLocale(option, service = Intl.NumberFormat) {
|
|
118
|
+
for (const candidate of [option, getLanguage(), 'en']) {
|
|
119
|
+
if (candidate == null) continue;
|
|
120
|
+
try {
|
|
121
|
+
const locales = service.supportedLocalesOf(Intl.getCanonicalLocales(candidate));
|
|
122
|
+
if (locales.length) return Array.isArray(candidate) ? locales : locales[0];
|
|
123
|
+
} catch { /* An unusable explicit option falls through to the active language. */ }
|
|
124
|
+
}
|
|
125
|
+
return 'en';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Ordered keys within one message source. Internal helper shared with Component.msgPlural.
|
|
130
|
+
* @param {string} key Unsuffixed key.
|
|
131
|
+
* @param {number} count Finite numeric count.
|
|
132
|
+
* @param {string} [locale] Plural-rule locale.
|
|
133
|
+
* @returns {string[]}
|
|
134
|
+
*/
|
|
135
|
+
export function pluralKeys(key, count, locale) {
|
|
136
|
+
if (typeof count !== 'number' || !Number.isFinite(count)) {
|
|
137
|
+
throw new TypeError('Plural count must be a finite number');
|
|
138
|
+
}
|
|
139
|
+
const effective = formattingLocale(locale, Intl.PluralRules);
|
|
140
|
+
const cacheKey = String(effective);
|
|
141
|
+
let rules = pluralRules.get(cacheKey);
|
|
142
|
+
if (!rules) {
|
|
143
|
+
rules = new Intl.PluralRules(effective);
|
|
144
|
+
pluralRules.set(cacheKey, rules);
|
|
145
|
+
}
|
|
146
|
+
const category = rules.select(count);
|
|
147
|
+
const legacy = legacyMessageKey(key);
|
|
148
|
+
return [...new Set([`${key}.${category}`, `${key}.other`, key, ...(legacy ? [legacy] : [])])];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns the first available message without asking a translator for subsequent keys.
|
|
153
|
+
* @param {string[]} keys Candidate keys.
|
|
154
|
+
* @param {(key: string) => string|null} lookup One message source.
|
|
155
|
+
* @returns {string|null}
|
|
156
|
+
*/
|
|
157
|
+
export function pluralMessage(keys, lookup) {
|
|
158
|
+
for (const key of keys) {
|
|
159
|
+
const text = lookup(key);
|
|
160
|
+
if (text !== null) return text;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
91
165
|
/**
|
|
92
166
|
* Replaces one-based numeric placeholders and legacy percent-delimited placeholders.
|
|
93
167
|
* Arrays replace `%1`, `%2`, and legacy placeholders in encounter order; objects replace
|
|
@@ -101,16 +175,16 @@ export function printf(str, args) {
|
|
|
101
175
|
|
|
102
176
|
const positional = Array.isArray(args) ? args :
|
|
103
177
|
(typeof args === 'object' ? null : [args]);
|
|
104
|
-
|
|
105
|
-
const index = Number(indexText) - 1;
|
|
106
|
-
let value;
|
|
107
|
-
if (positional) value = positional[index];
|
|
108
|
-
else if (Object.prototype.hasOwnProperty.call(args, indexText)) value = args[indexText];
|
|
109
|
-
return value == null ? placeholder : String(value);
|
|
110
|
-
});
|
|
111
|
-
|
|
178
|
+
// One pass: a value already written into the text is never read as a placeholder.
|
|
112
179
|
let legacyIndex = 0;
|
|
113
|
-
|
|
180
|
+
return String(str).replace(/%(\d+)|%([A-Za-z_][\w.-]*)%(?!\d)/g, (placeholder, indexText, key) => {
|
|
181
|
+
if (indexText !== undefined) {
|
|
182
|
+
const index = Number(indexText) - 1;
|
|
183
|
+
let value;
|
|
184
|
+
if (positional) value = positional[index];
|
|
185
|
+
else if (Object.prototype.hasOwnProperty.call(args, indexText)) value = args[indexText];
|
|
186
|
+
return value == null ? placeholder : String(value);
|
|
187
|
+
}
|
|
114
188
|
if (!positional && Object.prototype.hasOwnProperty.call(args, key)) {
|
|
115
189
|
const value = args[key];
|
|
116
190
|
return value == null ? placeholder : String(value);
|
|
@@ -122,5 +196,4 @@ export function printf(str, args) {
|
|
|
122
196
|
}
|
|
123
197
|
return placeholder;
|
|
124
198
|
});
|
|
125
|
-
return output;
|
|
126
199
|
}
|