@zeyos/zx 5.4.0 → 5.6.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 +136 -0
- package/README.md +23 -16
- package/dist/types/components/agent-thread/agent-thread.d.ts +583 -0
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +33 -0
- package/dist/types/components/approval-card/approval-card.d.ts +596 -0
- package/dist/types/components/avatar/avatar.d.ts +91 -4
- package/dist/types/components/badge/badge.d.ts +5 -4
- package/dist/types/components/block-view/block-view.d.ts +205 -0
- package/dist/types/components/composer/composer.d.ts +736 -0
- package/dist/types/components/datebox/date-range-box.d.ts +15 -2
- package/dist/types/components/datebox/datebox.d.ts +37 -3
- package/dist/types/components/kbd/kbd.d.ts +41 -0
- package/dist/types/components/launcher/launcher.d.ts +4 -2
- package/dist/types/components/prose/prose.d.ts +69 -0
- package/dist/types/components/questionnaire/questionnaire.d.ts +0 -36
- package/dist/types/components/run-status/run-status.d.ts +393 -0
- package/dist/types/components/run-trace/run-trace.d.ts +624 -0
- package/dist/types/components/source-list/source-list.d.ts +177 -0
- package/dist/types/components/stat-tile/stat-tile.d.ts +20 -0
- package/dist/types/components/tag-picker/tag-picker.d.ts +11 -5
- package/dist/types/components/tree/tree.d.ts +44 -3
- package/dist/types/core/icons.d.ts +22 -1
- package/dist/types/core/messages.d.ts +135 -0
- package/dist/types/index.d.ts +12 -2
- package/dist/types/internal/agent-model.d.ts +587 -0
- package/dist/types/internal/app-rail.d.ts +10 -3
- package/dist/types/internal/highlight.d.ts +24 -0
- package/dist/types/internal/presence-loop.d.ts +148 -0
- package/dist/types/internal/row-actions.d.ts +151 -0
- package/dist/zx-zeyos.esm.js +4852 -4535
- package/dist/zx-zeyos.esm.min.js +4 -4
- package/dist/zx.css +3152 -434
- package/dist/zx.esm.js +13730 -6595
- package/dist/zx.esm.min.js +27 -8
- package/dist/zx.global.js +13730 -6595
- package/dist/zx.global.min.js +27 -8
- package/dist/zx.min.css +1 -1
- package/docs/api.json +1474 -205
- package/docs/llms.md +698 -39
- package/docs/llms.txt +12 -1
- package/package.json +1 -1
- package/src/components/account-menu/account-menu.js +2 -2
- package/src/components/agent-thread/agent-thread.css +417 -0
- package/src/components/agent-thread/agent-thread.js +1365 -0
- package/src/components/app-rail/app-rail.css +11 -11
- package/src/components/app-sidebar/app-sidebar.css +90 -17
- package/src/components/app-sidebar/app-sidebar.js +120 -12
- package/src/components/approval-card/approval-card.css +289 -0
- package/src/components/approval-card/approval-card.js +1377 -0
- package/src/components/avatar/avatar.css +56 -1
- package/src/components/avatar/avatar.js +148 -26
- package/src/components/badge/badge.css +33 -20
- package/src/components/badge/badge.js +5 -4
- package/src/components/block-view/block-view.css +300 -0
- package/src/components/block-view/block-view.js +523 -0
- package/src/components/breadcrumb/breadcrumb.css +28 -3
- package/src/components/breadcrumb/breadcrumb.js +2 -2
- package/src/components/button/button.css +24 -13
- package/src/components/button/button.js +20 -2
- package/src/components/calendar/calendar.css +14 -4
- package/src/components/card-view/card-view.js +2 -2
- package/src/components/chart/chart.js +20 -5
- package/src/components/check-button/check-button.css +11 -3
- package/src/components/check-button/check-button.js +3 -3
- package/src/components/composer/composer.css +403 -0
- package/src/components/composer/composer.js +1441 -0
- package/src/components/context-menu/context-menu.css +7 -1
- package/src/components/date-picker/date-picker.css +6 -0
- package/src/components/date-picker/date-picker.js +5 -5
- package/src/components/date-picker/date-range-picker.css +6 -0
- package/src/components/date-picker/date-range-picker.js +3 -3
- package/src/components/date-picker/month-picker.js +3 -3
- package/src/components/date-picker/time-picker.css +6 -0
- package/src/components/datebox/date-range-box.js +30 -6
- package/src/components/datebox/datebox.js +44 -7
- package/src/components/dialog/dialog.css +0 -1
- package/src/components/dialog/dialog.js +2 -1
- package/src/components/dock/dock.js +2 -2
- package/src/components/dropdown/dropdown.css +2 -1
- package/src/components/entity-ref/entity-ref.css +8 -1
- package/src/components/file-item/file-item.css +1 -1
- package/src/components/finder/finder.js +2 -2
- package/src/components/groupbox/groupbox.js +2 -2
- package/src/components/kanban-view/kanban-view.css +8 -4
- package/src/components/kanban-view/kanban-view.js +3 -3
- package/src/components/kbd/kbd.css +64 -0
- package/src/components/kbd/kbd.js +121 -0
- package/src/components/launcher/launcher.css +30 -25
- package/src/components/launcher/launcher.js +15 -21
- package/src/components/list-toolbar/list-toolbar.css +7 -1
- package/src/components/menu-button/menu-button.css +9 -2
- package/src/components/message/message.js +2 -2
- package/src/components/module-bar/module-bar.css +11 -1
- package/src/components/multi-value-editor/multi-value-editor.js +4 -4
- package/src/components/navigation-bar/navigation-bar.css +3 -2
- package/src/components/pagination/pagination.js +2 -2
- package/src/components/panel/panel.js +2 -2
- package/src/components/prose/prose.css +53 -0
- package/src/components/prose/prose.js +152 -0
- package/src/components/questionnaire/questionnaire.css +7 -17
- package/src/components/questionnaire/questionnaire.js +16 -1
- package/src/components/rating/rating.css +3 -1
- package/src/components/run-status/run-status.css +208 -0
- package/src/components/run-status/run-status.js +782 -0
- package/src/components/run-trace/run-trace.css +443 -0
- package/src/components/run-trace/run-trace.js +1209 -0
- package/src/components/search/search.js +2 -2
- package/src/components/select/glyphs.js +3 -3
- package/src/components/select/select.css +35 -7
- package/src/components/select/select.js +4 -4
- package/src/components/source-list/source-list.css +208 -0
- package/src/components/source-list/source-list.js +355 -0
- package/src/components/stat-tile/stat-tile.css +56 -2
- package/src/components/stat-tile/stat-tile.js +25 -2
- package/src/components/stepper/stepper.css +2 -1
- package/src/components/stepper/stepper.js +3 -3
- package/src/components/tabbox/tabbox.css +2 -2
- package/src/components/tabbox/tabbox.js +2 -2
- package/src/components/table/table.css +52 -16
- package/src/components/table/table.js +7 -5
- package/src/components/tag-picker/tag-picker.css +56 -43
- package/src/components/tag-picker/tag-picker.js +21 -16
- package/src/components/tree/tree.css +44 -0
- package/src/components/tree/tree.js +97 -9
- package/src/components/value-list/value-list.css +25 -4
- package/src/components/value-list/value-list.js +2 -1
- package/src/components/view/record-view.js +3 -3
- package/src/components/view-settings/view-settings.css +2 -1
- package/src/components/workspace-switcher/workspace-switcher.js +3 -3
- package/src/core/icons.js +34 -3
- package/src/core/messages.js +143 -0
- package/src/elements/define.js +1 -0
- package/src/index.js +12 -2
- package/src/internal/agent-model.js +488 -0
- package/src/internal/app-rail.js +5 -1
- package/src/internal/highlight.js +104 -0
- package/src/internal/presence-loop.js +343 -0
- package/src/internal/row-actions.js +203 -0
- package/styles/base.css +26 -1
- package/styles/prose.css +306 -0
- package/styles/tokens/dark.css +97 -120
- package/styles/tokens/global.css +24 -9
- package/styles/tokens/semantic.css +464 -184
- package/styles/tokens/themes.css +9 -0
- package/styles/zx.css +10 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Component } from '../../core/component.js';
|
|
3
|
+
import { h, restoreTarget, safeHref, snapshotTarget } from '../../core/dom.js';
|
|
4
|
+
import { icon } from '../../core/icons.js';
|
|
5
|
+
import { prefersReducedMotion } from '../../core/motion.js';
|
|
6
|
+
import { uid } from '../../core/util.js';
|
|
7
|
+
import { Tooltip } from '../tooltip/tooltip.js';
|
|
8
|
+
|
|
9
|
+
/** @typedef {import('../../internal/agent-model.js').Source} Source */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What a source is: it picks the glyph, and whether activating it can open an address.
|
|
13
|
+
* @typedef {'web'|'file'|'record'|'call'} SourceKind
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} SourceListOptions
|
|
18
|
+
* @property {Source[]} [sources=[]] The sources, in the order an answer's `[n]` citations number
|
|
19
|
+
* them. Model text is data: every string reaches the page as text.
|
|
20
|
+
* @property {string} [label='Sources'] The visible label the list is named by. Empty hides it and
|
|
21
|
+
* names the list with the `sourceList.label` message instead.
|
|
22
|
+
* @property {'chips'|'list'} [layout='chips'] `'chips'` wraps short chips beside the label;
|
|
23
|
+
* `'list'` gives each source a full-width row with its title and site.
|
|
24
|
+
* @property {boolean} [numbered=true] Whether each source shows its number.
|
|
25
|
+
* @property {Partial<Record<SourceKind, string>>} [icons={}] Icon names per source kind, over the
|
|
26
|
+
* built-in `SOURCE_ICONS`.
|
|
27
|
+
* @property {Record<string, string>|Record<string, Record<string, string>>} [msg] Localized messages.
|
|
28
|
+
* @property {(event: CustomEvent<{source: Source, n: number}>) => void} [onselect] Activation
|
|
29
|
+
* listener; `preventDefault()` keeps a web source from opening.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** Built-in glyph per source kind. */
|
|
33
|
+
export const SOURCE_ICONS = Object.freeze({
|
|
34
|
+
web: 'link-2',
|
|
35
|
+
file: 'file',
|
|
36
|
+
record: 'table',
|
|
37
|
+
call: 'gear'
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const MESSAGES = Object.freeze({
|
|
41
|
+
'sourceList.label': 'Sources',
|
|
42
|
+
'sourceList.source': 'Source'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** How long a highlighted source stays marked, in milliseconds. */
|
|
46
|
+
const HIGHLIGHT_MS = 2000;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The sources an answer cites: a numbered chip (or row) for each, naming its site or title, with a
|
|
50
|
+
* card of its title, site, and the passage used on hover and focus.
|
|
51
|
+
*
|
|
52
|
+
* Activating a source emits a preventable `select`. Unless it is prevented, a `web` source opens
|
|
53
|
+
* its address in a new tab — only an absolute `https:` address, and never with access back to this
|
|
54
|
+
* page; every other kind is left to the application, which might reveal the trace step the source
|
|
55
|
+
* came from. The list never loads a favicon, a thumbnail, or any other remote resource.
|
|
56
|
+
*
|
|
57
|
+
* @fires SourceList#select
|
|
58
|
+
* @extends {Component<SourceListOptions>}
|
|
59
|
+
*/
|
|
60
|
+
export class SourceList extends Component {
|
|
61
|
+
static cssName = 'source-list';
|
|
62
|
+
|
|
63
|
+
/** @type {Readonly<SourceListOptions>} */
|
|
64
|
+
static defaults = {
|
|
65
|
+
sources: [],
|
|
66
|
+
label: 'Sources',
|
|
67
|
+
layout: 'chips',
|
|
68
|
+
numbered: true,
|
|
69
|
+
icons: {},
|
|
70
|
+
msg: MESSAGES
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** @returns {HTMLElement} */
|
|
74
|
+
render() {
|
|
75
|
+
const created = !this.el;
|
|
76
|
+
const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
|
|
77
|
+
this.el = root;
|
|
78
|
+
this._original = created ? null : snapshotTarget(root);
|
|
79
|
+
if (!created) root.replaceChildren();
|
|
80
|
+
this._destroyed = false;
|
|
81
|
+
/** @type {Array<Source & {id: string}>} */
|
|
82
|
+
this._sources = [];
|
|
83
|
+
/** @type {HTMLButtonElement[]} */
|
|
84
|
+
this._buttons = [];
|
|
85
|
+
/** @type {Tooltip[]} */
|
|
86
|
+
this._tooltips = [];
|
|
87
|
+
/** @type {ReturnType<typeof setTimeout>|null} */
|
|
88
|
+
this._highlightTimer = null;
|
|
89
|
+
this._layout = this.options.layout === 'list' ? 'list' : 'chips';
|
|
90
|
+
root.dataset.layout = this._layout;
|
|
91
|
+
|
|
92
|
+
const label = typeof this.options.label === 'string' ? this.options.label.trim() : '';
|
|
93
|
+
const labelId = uid('zx-source-list');
|
|
94
|
+
const heading = label ? h('span', { class: 'zx-source-list__label', id: labelId }, label) : null;
|
|
95
|
+
this._list = h('ol', {
|
|
96
|
+
class: 'zx-source-list__items',
|
|
97
|
+
'aria-labelledby': heading ? labelId : null,
|
|
98
|
+
'aria-label': heading ? null : this.msg('sourceList.label')
|
|
99
|
+
});
|
|
100
|
+
root.append(...[heading, this._list].filter((node) => node !== null));
|
|
101
|
+
|
|
102
|
+
this.listen(root, 'click', (event) => this._onClick(/** @type {MouseEvent} */ (event)));
|
|
103
|
+
this._build(this.options.sources);
|
|
104
|
+
return root;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Replaces every source. Focus on a source stays on the source with the same `id`.
|
|
109
|
+
* @param {Source[]} sources
|
|
110
|
+
* @returns {this}
|
|
111
|
+
*/
|
|
112
|
+
setSources(sources) {
|
|
113
|
+
this._build(sources);
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Points at one source, as a citation `[n]` in the answer does: scrolls it into view, puts focus
|
|
119
|
+
* on it, and marks it with `data-state="highlighted"` for two seconds. A number is the source's
|
|
120
|
+
* position, from 1; a string is its `id`. Anything else does nothing.
|
|
121
|
+
* @param {number|string} n
|
|
122
|
+
* @returns {this}
|
|
123
|
+
*/
|
|
124
|
+
highlight(n) {
|
|
125
|
+
const index = typeof n === 'number'
|
|
126
|
+
? Math.trunc(n) - 1
|
|
127
|
+
: this._sources.findIndex((source) => source.id === String(n));
|
|
128
|
+
const button = this._buttons[index];
|
|
129
|
+
if (!button) return this;
|
|
130
|
+
if (typeof button.scrollIntoView === 'function') {
|
|
131
|
+
button.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: prefersReducedMotion(this.el) ? 'auto' : 'smooth' });
|
|
132
|
+
}
|
|
133
|
+
button.focus({ preventScroll: true });
|
|
134
|
+
if (this._highlightTimer) clearTimeout(this._highlightTimer);
|
|
135
|
+
for (const other of this._buttons) if (other !== button) delete other.dataset.state;
|
|
136
|
+
button.dataset.state = 'highlighted';
|
|
137
|
+
this._highlightTimer = setTimeout(() => {
|
|
138
|
+
this._highlightTimer = null;
|
|
139
|
+
if (button.dataset.state === 'highlighted') delete button.dataset.state;
|
|
140
|
+
}, HIGHLIGHT_MS);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** @returns {Source[]} Copies of the sources, in order. */
|
|
145
|
+
getSources() {
|
|
146
|
+
return this._sources.map(cloneSource);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** @returns {void} */
|
|
150
|
+
destroy() {
|
|
151
|
+
if (this._destroyed) return;
|
|
152
|
+
this._destroyed = true;
|
|
153
|
+
if (this._highlightTimer) clearTimeout(this._highlightTimer);
|
|
154
|
+
this._highlightTimer = null;
|
|
155
|
+
this._releaseTooltips();
|
|
156
|
+
super.destroy();
|
|
157
|
+
if (this._original) restoreTarget(this.el, this._original);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @private
|
|
162
|
+
* @param {unknown} sources
|
|
163
|
+
* @returns {void}
|
|
164
|
+
*/
|
|
165
|
+
_build(sources) {
|
|
166
|
+
const active = this.el.ownerDocument?.activeElement ?? null;
|
|
167
|
+
const focused = active && this._list.contains(active)
|
|
168
|
+
? /** @type {HTMLElement|null} */ (active.closest('[data-source]'))?.dataset.source ?? null
|
|
169
|
+
: null;
|
|
170
|
+
if (this._highlightTimer) clearTimeout(this._highlightTimer);
|
|
171
|
+
this._highlightTimer = null;
|
|
172
|
+
this._releaseTooltips();
|
|
173
|
+
this._sources = normalizeSources(sources);
|
|
174
|
+
this._buttons = [];
|
|
175
|
+
this._list.replaceChildren(...this._sources.map((source, index) => this._item(source, index)));
|
|
176
|
+
const root = /** @type {HTMLElement} */ (this.el);
|
|
177
|
+
if (this._sources.length) delete root.dataset.empty;
|
|
178
|
+
else root.dataset.empty = '';
|
|
179
|
+
if (focused) this._buttons.find((button) => button.dataset.source === focused)?.focus({ preventScroll: true });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @private
|
|
184
|
+
* @param {Source & {id: string}} source
|
|
185
|
+
* @param {number} index
|
|
186
|
+
* @returns {HTMLElement}
|
|
187
|
+
*/
|
|
188
|
+
_item(source, index) {
|
|
189
|
+
const kind = sourceKind(source);
|
|
190
|
+
const n = index + 1;
|
|
191
|
+
const numbered = this.options.numbered !== false;
|
|
192
|
+
const where = sourcePlace(source);
|
|
193
|
+
const button = /** @type {HTMLButtonElement} */ (h('button', {
|
|
194
|
+
type: 'button',
|
|
195
|
+
class: 'zx-source-list__source',
|
|
196
|
+
dataset: { source: source.id, n: String(n), kind }
|
|
197
|
+
},
|
|
198
|
+
// Named "Source 1: bank.example", which keeps the visible "1" and name in the accessible name.
|
|
199
|
+
numbered ? [
|
|
200
|
+
h('span', { class: 'zx-source-list__sr' }, `${this.msg('sourceList.source')} `),
|
|
201
|
+
h('span', { class: 'zx-source-list__n' }, String(n)),
|
|
202
|
+
h('span', { class: 'zx-source-list__sr' }, ': ')
|
|
203
|
+
] : null,
|
|
204
|
+
h('span', { class: 'zx-source-list__glyph', 'aria-hidden': 'true' }, icon(this._icon(kind), { size: 14 })),
|
|
205
|
+
this._layout === 'list'
|
|
206
|
+
? h('span', { class: 'zx-source-list__copy' },
|
|
207
|
+
h('span', { class: 'zx-source-list__title' }, source.title || sourceName(source)),
|
|
208
|
+
where && where !== source.title ? h('span', { class: 'zx-source-list__site' }, where) : null)
|
|
209
|
+
: h('span', { class: 'zx-source-list__name' }, sourceName(source))));
|
|
210
|
+
this._buttons.push(button);
|
|
211
|
+
this._tooltips.push(new Tooltip(button, {
|
|
212
|
+
content: () => this._card(source),
|
|
213
|
+
placement: 'top-start',
|
|
214
|
+
maxWidth: 320
|
|
215
|
+
}));
|
|
216
|
+
return h('li', { class: 'zx-source-list__item' }, button);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The card a source shows on hover and focus: its title, where it is (the host of a web
|
|
221
|
+
* address), and the passage used.
|
|
222
|
+
* @private
|
|
223
|
+
* @param {Source & {id: string}} source
|
|
224
|
+
* @returns {HTMLElement}
|
|
225
|
+
*/
|
|
226
|
+
_card(source) {
|
|
227
|
+
const kind = sourceKind(source);
|
|
228
|
+
const where = sourcePlace(source);
|
|
229
|
+
return h('span', { class: 'zx-source-list__card' },
|
|
230
|
+
h('span', { class: 'zx-source-list__card-title' }, source.title || sourceName(source)),
|
|
231
|
+
// A file named by its own title would say its name twice.
|
|
232
|
+
where && where !== (source.title || sourceName(source))
|
|
233
|
+
? h('span', { class: 'zx-source-list__card-site' }, icon(this._icon(kind), { size: 12 }), where) : null,
|
|
234
|
+
source.snippet ? h('span', { class: 'zx-source-list__card-snippet' }, String(source.snippet)) : null);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** @private @param {SourceKind} kind @returns {string} */
|
|
238
|
+
_icon(kind) {
|
|
239
|
+
const custom = this.options.icons?.[kind];
|
|
240
|
+
return typeof custom === 'string' && custom ? custom : SOURCE_ICONS[kind];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** @private @returns {void} */
|
|
244
|
+
_releaseTooltips() {
|
|
245
|
+
for (const tooltip of this._tooltips) tooltip.destroy();
|
|
246
|
+
this._tooltips = [];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @private
|
|
251
|
+
* @param {MouseEvent} event
|
|
252
|
+
* @returns {void}
|
|
253
|
+
*/
|
|
254
|
+
_onClick(event) {
|
|
255
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
256
|
+
const button = /** @type {HTMLElement|null} */ (target?.closest('[data-source]') ?? null);
|
|
257
|
+
if (!button || !this._list.contains(button)) return;
|
|
258
|
+
const index = Number(button.dataset.n) - 1;
|
|
259
|
+
const source = this._sources[index];
|
|
260
|
+
if (!source) return;
|
|
261
|
+
const selected = this.emit('select', { source: cloneSource(source), n: index + 1 }, { honorDomCancellation: true });
|
|
262
|
+
if (selected.defaultPrevented) return;
|
|
263
|
+
const href = sourceHref(source);
|
|
264
|
+
if (href) window.open(href, '_blank', 'noopener,noreferrer');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Fired when a source is activated. Preventable: `preventDefault()` keeps a web source from
|
|
270
|
+
* opening its address.
|
|
271
|
+
* @event SourceList#select
|
|
272
|
+
* @type {CustomEvent<{source: Source, n: number}>}
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
/* ------------------------------------------------------------------ pure helpers -- */
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @param {unknown} sources
|
|
279
|
+
* @returns {Array<Source & {id: string}>}
|
|
280
|
+
*/
|
|
281
|
+
function normalizeSources(sources) {
|
|
282
|
+
/** @type {Array<Source & {id: string}>} */
|
|
283
|
+
const out = [];
|
|
284
|
+
(Array.isArray(sources) ? sources : []).forEach((source, index) => {
|
|
285
|
+
if (!source || typeof source !== 'object') return;
|
|
286
|
+
const id = source.id == null || source.id === '' ? `source-${index + 1}` : String(source.id);
|
|
287
|
+
out.push({ ...cloneSource(source), id, title: source.title == null ? '' : String(source.title) });
|
|
288
|
+
});
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** @param {Source} source @returns {Source} A copy that shares nothing with the original. */
|
|
293
|
+
function cloneSource(source) {
|
|
294
|
+
const copy = { ...source };
|
|
295
|
+
if (source.ref && typeof source.ref === 'object') copy.ref = { ...source.ref };
|
|
296
|
+
return copy;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* A source's kind; a source without one is a web source.
|
|
301
|
+
* @param {Source|null|undefined} source
|
|
302
|
+
* @returns {SourceKind}
|
|
303
|
+
*/
|
|
304
|
+
export function sourceKind(source) {
|
|
305
|
+
const kind = source?.kind ?? 'web';
|
|
306
|
+
return Object.hasOwn(SOURCE_ICONS, kind) ? kind : 'web';
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The address a source may open: a `web` source's `href`, only when it is an absolute `https:`
|
|
311
|
+
* URL that `safeHref()` accepts. Anything else — another kind, a relative or `http:` address, a
|
|
312
|
+
* script scheme — gives null.
|
|
313
|
+
* @param {Source|null|undefined} source
|
|
314
|
+
* @returns {string|null}
|
|
315
|
+
*/
|
|
316
|
+
export function sourceHref(source) {
|
|
317
|
+
if (!source || typeof source !== 'object' || sourceKind(source) !== 'web') return null;
|
|
318
|
+
const href = safeHref(source.href);
|
|
319
|
+
if (!href) return null;
|
|
320
|
+
try {
|
|
321
|
+
const url = new URL(href);
|
|
322
|
+
return url.protocol === 'https:' ? url.href : null;
|
|
323
|
+
} catch {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* The host a web source opens, for its card: "bank.example". Null when it opens nothing.
|
|
330
|
+
* @param {Source|null|undefined} source
|
|
331
|
+
* @returns {string|null}
|
|
332
|
+
*/
|
|
333
|
+
export function sourceHost(source) {
|
|
334
|
+
const href = sourceHref(source);
|
|
335
|
+
return href ? new URL(href).host : null;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The short name a chip shows: the source's `site`, else its title.
|
|
340
|
+
* @param {Source|null|undefined} source
|
|
341
|
+
* @returns {string}
|
|
342
|
+
*/
|
|
343
|
+
export function sourceName(source) {
|
|
344
|
+
const site = source?.site == null ? '' : String(source.site).trim();
|
|
345
|
+
return site || (source?.title == null ? '' : String(source.title));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Where a source is, for its card and list row: the host a web source opens, else its `site`.
|
|
350
|
+
* @param {Source} source
|
|
351
|
+
* @returns {string}
|
|
352
|
+
*/
|
|
353
|
+
function sourcePlace(source) {
|
|
354
|
+
return sourceHost(source) ?? (source.site == null ? '' : String(source.site));
|
|
355
|
+
}
|
|
@@ -20,6 +20,53 @@
|
|
|
20
20
|
color: var(--zx-color-text);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/* One figure leads a row: a framed tile steps past the display size, and a plain row sets its
|
|
24
|
+
figures a size down so the emphasised one can lead at the display size. */
|
|
25
|
+
.zx-stat-tile[data-emphasis="true"] {
|
|
26
|
+
--zx-stat-tile-value-size: var(--zx-text-3xl);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Plain: a figure on the page rather than a tile on it. No frame, no fill, no padding — its text
|
|
31
|
+
* sits on the content edge beside the title above it, and space alone separates it from the next.
|
|
32
|
+
* The label and caption stay muted and the figure keeps its weight and tabular digits; only its
|
|
33
|
+
* size steps down, so the emphasised figure in the row is the one that reads first.
|
|
34
|
+
*/
|
|
35
|
+
.zx-stat-tile[data-variant="plain"] {
|
|
36
|
+
--zx-stat-tile-value-size: var(--zx-text-lg);
|
|
37
|
+
padding: 0;
|
|
38
|
+
border: 0;
|
|
39
|
+
border-radius: var(--zx-radius-md);
|
|
40
|
+
background: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.zx-stat-tile[data-variant="plain"][data-emphasis="true"] {
|
|
44
|
+
--zx-stat-tile-value-size: var(--zx-text-2xl);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Without a frame there is no corner to hold the icon, so it leads the label instead. */
|
|
48
|
+
.zx-stat-tile[data-variant="plain"] .zx-stat-tile__header {
|
|
49
|
+
justify-content: start;
|
|
50
|
+
gap: var(--zx-space-1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.zx-stat-tile[data-variant="plain"] .zx-stat-tile__icon {
|
|
54
|
+
order: -1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.zx-stat-tile[data-variant="plain"] .zx-stat-tile__value {
|
|
58
|
+
margin-block-start: 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* A plain tile you can activate keeps its text on the edge; its hover fill and focus ring bleed
|
|
62
|
+
past it instead of pushing the figure inwards. */
|
|
63
|
+
a.zx-stat-tile[data-variant="plain"],
|
|
64
|
+
button.zx-stat-tile[data-variant="plain"] {
|
|
65
|
+
margin: calc(var(--zx-space-2) * -1);
|
|
66
|
+
inline-size: calc(100% + var(--zx-space-2) * 2);
|
|
67
|
+
padding: var(--zx-space-2);
|
|
68
|
+
}
|
|
69
|
+
|
|
23
70
|
/* The link and button shapes are the same tile, so their native chrome is taken back off. */
|
|
24
71
|
a.zx-stat-tile,
|
|
25
72
|
button.zx-stat-tile {
|
|
@@ -86,7 +133,7 @@ button.zx-stat-tile:focus-visible {
|
|
|
86
133
|
min-inline-size: 0;
|
|
87
134
|
margin-block-start: var(--zx-space-1);
|
|
88
135
|
font-size: var(--zx-stat-tile-value-size);
|
|
89
|
-
font-weight:
|
|
136
|
+
font-weight: var(--zx-weight-title);
|
|
90
137
|
font-variant-numeric: tabular-nums;
|
|
91
138
|
letter-spacing: var(--zx-tracking-title);
|
|
92
139
|
line-height: 1.15;
|
|
@@ -159,7 +206,8 @@ button.zx-stat-tile:focus-visible {
|
|
|
159
206
|
block-size: 2rem;
|
|
160
207
|
margin-block-start: auto;
|
|
161
208
|
padding-block-start: var(--zx-space-2);
|
|
162
|
-
|
|
209
|
+
/* The sparkline is the tile's only data mark, so it needs a mark's 3:1, not placeholder ink. */
|
|
210
|
+
color: var(--zx-color-text-subtle);
|
|
163
211
|
}
|
|
164
212
|
|
|
165
213
|
.zx-stat-tile__loading {
|
|
@@ -193,6 +241,12 @@ button.zx-stat-tile:focus-visible {
|
|
|
193
241
|
border-color: CanvasText;
|
|
194
242
|
}
|
|
195
243
|
|
|
244
|
+
/* A plain figure has no frame to restore; its hover outline is the one a linked tile draws. */
|
|
245
|
+
a.zx-stat-tile[data-variant="plain"]:hover,
|
|
246
|
+
button.zx-stat-tile[data-variant="plain"]:hover {
|
|
247
|
+
outline: 1px solid Highlight;
|
|
248
|
+
}
|
|
249
|
+
|
|
196
250
|
a.zx-stat-tile:hover,
|
|
197
251
|
button.zx-stat-tile:hover {
|
|
198
252
|
border-color: Highlight;
|
|
@@ -12,6 +12,7 @@ import { skeleton } from '../skeleton/skeleton.js';
|
|
|
12
12
|
/** @typedef {'neutral'|'accent'|'success'|'warning'|'danger'|'info'} StatTileKind */
|
|
13
13
|
/** @typedef {'positive'|'negative'|'neutral'} StatTileDeltaKind */
|
|
14
14
|
/** @typedef {'up'|'down'|'flat'} StatTileDirection */
|
|
15
|
+
/** @typedef {'default'|'plain'} StatTileVariant */
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @typedef {Object} StatTileDelta
|
|
@@ -53,6 +54,13 @@ import { skeleton } from '../skeleton/skeleton.js';
|
|
|
53
54
|
* a glyph, not a coloured chip.
|
|
54
55
|
* @property {StatTileKind} [kind='neutral'] Semantic intent. It tints the sparkline and never the
|
|
55
56
|
* value, which stays at full text contrast whatever intent a record carries.
|
|
57
|
+
* @property {StatTileVariant} [variant='default'] `'default'` is a framed tile on its own surface,
|
|
58
|
+
* for a figure that stands among other content (a dashboard). `'plain'` drops the frame, the fill
|
|
59
|
+
* and the padding and sets the figure a size smaller, for a row of figures on a page (a record's
|
|
60
|
+
* amounts under its title). Reflected as `data-variant` on the root.
|
|
61
|
+
* @property {boolean} [emphasis=false] The figure leads its row: in a plain row it is set at the
|
|
62
|
+
* display size while the others stay smaller, on a framed tile one step above the display size.
|
|
63
|
+
* Give it to one tile per row. Reflected as `data-emphasis="true"`.
|
|
56
64
|
* @property {string|null} [href=null] Destination. A tile with an href is an `<a>`.
|
|
57
65
|
* @property {boolean} [clickable=false] Renders a `<button>` without an href. Passing `onclick`
|
|
58
66
|
* sets this implicitly; set it directly to subscribe with `on('click', …)` instead.
|
|
@@ -104,6 +112,8 @@ const defaults = Object.freeze({
|
|
|
104
112
|
trend: [],
|
|
105
113
|
icon: null,
|
|
106
114
|
kind: 'neutral',
|
|
115
|
+
variant: 'default',
|
|
116
|
+
emphasis: false,
|
|
107
117
|
href: null,
|
|
108
118
|
clickable: false,
|
|
109
119
|
loading: false
|
|
@@ -293,6 +303,15 @@ export function statDelta(delta, options = {}) {
|
|
|
293
303
|
return { direction, sign, magnitude, text: `${sign}${magnitude}` };
|
|
294
304
|
}
|
|
295
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Resolves the `variant` option to one the stylesheet knows; anything else is the framed tile.
|
|
308
|
+
* @param {unknown} value Requested variant.
|
|
309
|
+
* @returns {StatTileVariant}
|
|
310
|
+
*/
|
|
311
|
+
export function normalizeStatTileVariant(value) {
|
|
312
|
+
return value === 'plain' ? 'plain' : 'default';
|
|
313
|
+
}
|
|
314
|
+
|
|
296
315
|
/**
|
|
297
316
|
* Chooses the element a tile must be, from what the tile does.
|
|
298
317
|
*
|
|
@@ -374,6 +393,9 @@ function fillStatTile(root, options, message) {
|
|
|
374
393
|
// put on it, and a redraw through `update()` does not quietly strip them.
|
|
375
394
|
root.classList.add('zx-stat-tile');
|
|
376
395
|
root.dataset.kind = kind;
|
|
396
|
+
root.dataset.variant = normalizeStatTileVariant(options.variant);
|
|
397
|
+
if (options.emphasis === true) root.dataset.emphasis = 'true';
|
|
398
|
+
else delete root.dataset.emphasis;
|
|
377
399
|
root.dataset.loading = String(loading);
|
|
378
400
|
if (root.tagName.toLowerCase() === 'a') {
|
|
379
401
|
// `setAttribute` rather than the reflected property, so `update()` can also take a destination
|
|
@@ -482,14 +504,15 @@ function trendBody(values) {
|
|
|
482
504
|
|
|
483
505
|
/**
|
|
484
506
|
* Builds the placeholder: the tile's own shape in grey, not a spinner, so nothing moves when the
|
|
485
|
-
* numbers arrive.
|
|
507
|
+
* numbers arrive. The figure's block reads the same size property as the figure, so a plain or an
|
|
508
|
+
* emphasised tile's placeholder is as tall as the number that replaces it.
|
|
486
509
|
* @param {StatTileOptions} options Fully merged options.
|
|
487
510
|
* @returns {HTMLElement}
|
|
488
511
|
*/
|
|
489
512
|
function loadingBody(options) {
|
|
490
513
|
const blocks = [
|
|
491
514
|
h('div', { class: 'zx-stat-tile__header' }, skeleton({ width: '55%', height: '0.75rem' })),
|
|
492
|
-
skeleton({ width: '70%', height: '1.
|
|
515
|
+
skeleton({ width: '70%', height: 'calc(var(--zx-stat-tile-value-size) * 1.15)', radius: 'md' })
|
|
493
516
|
];
|
|
494
517
|
if (asText(options.caption).trim()) blocks.push(skeleton({ width: '35%', height: '0.75rem' }));
|
|
495
518
|
if (options.delta !== null && options.delta !== undefined) {
|
|
@@ -144,8 +144,9 @@ button.zx-stepper__control:disabled {
|
|
|
144
144
|
overflow-wrap: anywhere;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
/* Real text, so it takes the muted text role: placeholder ink is for empty fields only. */
|
|
147
148
|
.zx-stepper__optional {
|
|
148
|
-
color: var(--zx-color-text-
|
|
149
|
+
color: var(--zx-color-text-muted);
|
|
149
150
|
font-size: var(--zx-text-xs);
|
|
150
151
|
font-style: italic;
|
|
151
152
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Component } from '../../core/component.js';
|
|
2
2
|
import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
|
|
3
3
|
import { printf } from '../../core/i18n.js';
|
|
4
|
-
import { icon } from '../../core/icons.js';
|
|
4
|
+
import { ICON_SIZE, icon } from '../../core/icons.js';
|
|
5
5
|
import { completedByAdvance, normalizeSteps, resolveStepIndex, stepIndex, stepState } from './steps.js';
|
|
6
6
|
|
|
7
7
|
/** @typedef {import('./steps.js').StepDefinition} StepDefinition */
|
|
@@ -387,8 +387,8 @@ export class Stepper extends Component {
|
|
|
387
387
|
* @returns {Array<Node|string>}
|
|
388
388
|
*/
|
|
389
389
|
_markerContent(state, index) {
|
|
390
|
-
if (state === 'complete') return [icon('check', { size:
|
|
391
|
-
if (state === 'error') return [icon('warning', { size:
|
|
390
|
+
if (state === 'complete') return [icon('check', { size: ICON_SIZE.check })];
|
|
391
|
+
if (state === 'error') return [icon('warning', { size: ICON_SIZE.check })];
|
|
392
392
|
return this.options.showNumbers ? [String(index + 1)] : [];
|
|
393
393
|
}
|
|
394
394
|
|
|
@@ -207,8 +207,8 @@
|
|
|
207
207
|
|
|
208
208
|
.zx-tabbox[data-variant="segmented"] .zx-tabbox__tab {
|
|
209
209
|
block-size: 100%;
|
|
210
|
-
/*
|
|
211
|
-
border-radius: max(0px, calc(var(--zx-tabbox-radius) -
|
|
210
|
+
/* Concentric with the frame: its corner less the 1px border and the 2px padding between them. */
|
|
211
|
+
border-radius: max(0px, calc(var(--zx-tabbox-radius) - 3px));
|
|
212
212
|
padding-inline: var(--zx-space-3);
|
|
213
213
|
font-size: var(--zx-text-sm);
|
|
214
214
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component } from '../../core/component.js';
|
|
2
2
|
import { h } from '../../core/dom.js';
|
|
3
|
-
import { icon } from '../../core/icons.js';
|
|
3
|
+
import { ICON_SIZE, icon } from '../../core/icons.js';
|
|
4
4
|
import { uid } from '../../core/util.js';
|
|
5
5
|
|
|
6
6
|
/** @typedef {Node|Component|(() => Node|Component)} TabContent */
|
|
@@ -184,7 +184,7 @@ export class Tabbox extends Component {
|
|
|
184
184
|
class: 'zx-tabbox__close zx-icon-btn',
|
|
185
185
|
ariaHidden: 'true',
|
|
186
186
|
title: this._message('tabbox.close', 'Close')
|
|
187
|
-
}, icon('x', { size:
|
|
187
|
+
}, icon('x', { size: ICON_SIZE.dismiss })));
|
|
188
188
|
}
|
|
189
189
|
const tab = /** @type {HTMLButtonElement} */ (h('button', {
|
|
190
190
|
class: 'zx-tabbox__tab',
|