@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.
Files changed (145) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/README.md +23 -16
  3. package/dist/types/components/agent-thread/agent-thread.d.ts +583 -0
  4. package/dist/types/components/app-sidebar/app-sidebar.d.ts +33 -0
  5. package/dist/types/components/approval-card/approval-card.d.ts +596 -0
  6. package/dist/types/components/avatar/avatar.d.ts +91 -4
  7. package/dist/types/components/badge/badge.d.ts +5 -4
  8. package/dist/types/components/block-view/block-view.d.ts +205 -0
  9. package/dist/types/components/composer/composer.d.ts +736 -0
  10. package/dist/types/components/datebox/date-range-box.d.ts +15 -2
  11. package/dist/types/components/datebox/datebox.d.ts +37 -3
  12. package/dist/types/components/kbd/kbd.d.ts +41 -0
  13. package/dist/types/components/launcher/launcher.d.ts +4 -2
  14. package/dist/types/components/prose/prose.d.ts +69 -0
  15. package/dist/types/components/questionnaire/questionnaire.d.ts +0 -36
  16. package/dist/types/components/run-status/run-status.d.ts +393 -0
  17. package/dist/types/components/run-trace/run-trace.d.ts +624 -0
  18. package/dist/types/components/source-list/source-list.d.ts +177 -0
  19. package/dist/types/components/stat-tile/stat-tile.d.ts +20 -0
  20. package/dist/types/components/tag-picker/tag-picker.d.ts +11 -5
  21. package/dist/types/components/tree/tree.d.ts +44 -3
  22. package/dist/types/core/icons.d.ts +22 -1
  23. package/dist/types/core/messages.d.ts +135 -0
  24. package/dist/types/index.d.ts +12 -2
  25. package/dist/types/internal/agent-model.d.ts +587 -0
  26. package/dist/types/internal/app-rail.d.ts +10 -3
  27. package/dist/types/internal/highlight.d.ts +24 -0
  28. package/dist/types/internal/presence-loop.d.ts +148 -0
  29. package/dist/types/internal/row-actions.d.ts +151 -0
  30. package/dist/zx-zeyos.esm.js +4852 -4535
  31. package/dist/zx-zeyos.esm.min.js +4 -4
  32. package/dist/zx.css +3152 -434
  33. package/dist/zx.esm.js +13730 -6595
  34. package/dist/zx.esm.min.js +27 -8
  35. package/dist/zx.global.js +13730 -6595
  36. package/dist/zx.global.min.js +27 -8
  37. package/dist/zx.min.css +1 -1
  38. package/docs/api.json +1474 -205
  39. package/docs/llms.md +698 -39
  40. package/docs/llms.txt +12 -1
  41. package/package.json +1 -1
  42. package/src/components/account-menu/account-menu.js +2 -2
  43. package/src/components/agent-thread/agent-thread.css +417 -0
  44. package/src/components/agent-thread/agent-thread.js +1365 -0
  45. package/src/components/app-rail/app-rail.css +11 -11
  46. package/src/components/app-sidebar/app-sidebar.css +90 -17
  47. package/src/components/app-sidebar/app-sidebar.js +120 -12
  48. package/src/components/approval-card/approval-card.css +289 -0
  49. package/src/components/approval-card/approval-card.js +1377 -0
  50. package/src/components/avatar/avatar.css +56 -1
  51. package/src/components/avatar/avatar.js +148 -26
  52. package/src/components/badge/badge.css +33 -20
  53. package/src/components/badge/badge.js +5 -4
  54. package/src/components/block-view/block-view.css +300 -0
  55. package/src/components/block-view/block-view.js +523 -0
  56. package/src/components/breadcrumb/breadcrumb.css +28 -3
  57. package/src/components/breadcrumb/breadcrumb.js +2 -2
  58. package/src/components/button/button.css +24 -13
  59. package/src/components/button/button.js +20 -2
  60. package/src/components/calendar/calendar.css +14 -4
  61. package/src/components/card-view/card-view.js +2 -2
  62. package/src/components/chart/chart.js +20 -5
  63. package/src/components/check-button/check-button.css +11 -3
  64. package/src/components/check-button/check-button.js +3 -3
  65. package/src/components/composer/composer.css +403 -0
  66. package/src/components/composer/composer.js +1441 -0
  67. package/src/components/context-menu/context-menu.css +7 -1
  68. package/src/components/date-picker/date-picker.css +6 -0
  69. package/src/components/date-picker/date-picker.js +5 -5
  70. package/src/components/date-picker/date-range-picker.css +6 -0
  71. package/src/components/date-picker/date-range-picker.js +3 -3
  72. package/src/components/date-picker/month-picker.js +3 -3
  73. package/src/components/date-picker/time-picker.css +6 -0
  74. package/src/components/datebox/date-range-box.js +30 -6
  75. package/src/components/datebox/datebox.js +44 -7
  76. package/src/components/dialog/dialog.css +0 -1
  77. package/src/components/dialog/dialog.js +2 -1
  78. package/src/components/dock/dock.js +2 -2
  79. package/src/components/dropdown/dropdown.css +2 -1
  80. package/src/components/entity-ref/entity-ref.css +8 -1
  81. package/src/components/file-item/file-item.css +1 -1
  82. package/src/components/finder/finder.js +2 -2
  83. package/src/components/groupbox/groupbox.js +2 -2
  84. package/src/components/kanban-view/kanban-view.css +8 -4
  85. package/src/components/kanban-view/kanban-view.js +3 -3
  86. package/src/components/kbd/kbd.css +64 -0
  87. package/src/components/kbd/kbd.js +121 -0
  88. package/src/components/launcher/launcher.css +30 -25
  89. package/src/components/launcher/launcher.js +15 -21
  90. package/src/components/list-toolbar/list-toolbar.css +7 -1
  91. package/src/components/menu-button/menu-button.css +9 -2
  92. package/src/components/message/message.js +2 -2
  93. package/src/components/module-bar/module-bar.css +11 -1
  94. package/src/components/multi-value-editor/multi-value-editor.js +4 -4
  95. package/src/components/navigation-bar/navigation-bar.css +3 -2
  96. package/src/components/pagination/pagination.js +2 -2
  97. package/src/components/panel/panel.js +2 -2
  98. package/src/components/prose/prose.css +53 -0
  99. package/src/components/prose/prose.js +152 -0
  100. package/src/components/questionnaire/questionnaire.css +7 -17
  101. package/src/components/questionnaire/questionnaire.js +16 -1
  102. package/src/components/rating/rating.css +3 -1
  103. package/src/components/run-status/run-status.css +208 -0
  104. package/src/components/run-status/run-status.js +782 -0
  105. package/src/components/run-trace/run-trace.css +443 -0
  106. package/src/components/run-trace/run-trace.js +1209 -0
  107. package/src/components/search/search.js +2 -2
  108. package/src/components/select/glyphs.js +3 -3
  109. package/src/components/select/select.css +35 -7
  110. package/src/components/select/select.js +4 -4
  111. package/src/components/source-list/source-list.css +208 -0
  112. package/src/components/source-list/source-list.js +355 -0
  113. package/src/components/stat-tile/stat-tile.css +56 -2
  114. package/src/components/stat-tile/stat-tile.js +25 -2
  115. package/src/components/stepper/stepper.css +2 -1
  116. package/src/components/stepper/stepper.js +3 -3
  117. package/src/components/tabbox/tabbox.css +2 -2
  118. package/src/components/tabbox/tabbox.js +2 -2
  119. package/src/components/table/table.css +52 -16
  120. package/src/components/table/table.js +7 -5
  121. package/src/components/tag-picker/tag-picker.css +56 -43
  122. package/src/components/tag-picker/tag-picker.js +21 -16
  123. package/src/components/tree/tree.css +44 -0
  124. package/src/components/tree/tree.js +97 -9
  125. package/src/components/value-list/value-list.css +25 -4
  126. package/src/components/value-list/value-list.js +2 -1
  127. package/src/components/view/record-view.js +3 -3
  128. package/src/components/view-settings/view-settings.css +2 -1
  129. package/src/components/workspace-switcher/workspace-switcher.js +3 -3
  130. package/src/core/icons.js +34 -3
  131. package/src/core/messages.js +143 -0
  132. package/src/elements/define.js +1 -0
  133. package/src/index.js +12 -2
  134. package/src/internal/agent-model.js +488 -0
  135. package/src/internal/app-rail.js +5 -1
  136. package/src/internal/highlight.js +104 -0
  137. package/src/internal/presence-loop.js +343 -0
  138. package/src/internal/row-actions.js +203 -0
  139. package/styles/base.css +26 -1
  140. package/styles/prose.css +306 -0
  141. package/styles/tokens/dark.css +97 -120
  142. package/styles/tokens/global.css +24 -9
  143. package/styles/tokens/semantic.css +464 -184
  144. package/styles/tokens/themes.css +9 -0
  145. package/styles/zx.css +10 -0
@@ -0,0 +1,523 @@
1
+ // @ts-check
2
+ import { Component } from '../../core/component.js';
3
+ import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
4
+ import { icon } from '../../core/icons.js';
5
+ import { blocksToMarkdown, blocksToText, figureRow, parseInline } from '../../internal/agent-model.js';
6
+ import { highlight } from '../../internal/highlight.js';
7
+ import { copyButton } from '../copy/copy-button.js';
8
+
9
+ /** @typedef {import('../../internal/agent-model.js').Block} Block */
10
+ /** @typedef {import('../../internal/agent-model.js').Source} Source */
11
+
12
+ /**
13
+ * @typedef {Object} BlockViewOptions
14
+ * @property {Block[]} [blocks=[]] The answer's blocks. Model text is data: every string reaches
15
+ * the page as text, through the inline grammar of `**bold**`, `` `code` `` and `[n]` citations.
16
+ * @property {2|3|4|5} [headingLevel=3] Element level of a `heading` block of level 2; a level-3
17
+ * heading goes one deeper. Set it one below the heading that names the answer.
18
+ * @property {'sm'|'md'} [size='sm'] Prose size: `'sm'` sets the answer at the interface size, for
19
+ * a conversation; `'md'` at the reading size, for a document.
20
+ * @property {boolean} [streaming=false] Whether more is still being written. The last block stays
21
+ * open to `appendText()`, and the root is busy until `end()` or `stop()`.
22
+ * @property {Source[]|null} [sources=null] The sources citations point at; their titles name the
23
+ * citation buttons.
24
+ * @property {Record<string, string>|Record<string, Record<string, string>>} [msg] Localized messages.
25
+ * @property {(event: CustomEvent<{n: number, source: Source|null}>) => void} [oncite] Citation listener.
26
+ * @property {(event: CustomEvent<{id: string}>) => void} [onartifact] Artifact listener.
27
+ * @property {(event: CustomEvent<Record<string, never>>) => void} [onend] End-of-stream listener.
28
+ */
29
+
30
+ /**
31
+ * Options for drawing blocks without a component.
32
+ * @typedef {Object} RenderBlocksOptions
33
+ * @property {2|3|4|5} [headingLevel=3] Element level of a level-2 `heading` block.
34
+ * @property {(key: string, ...args: unknown[]) => string} [msg] Message lookup for the few words
35
+ * the blocks add (code copy, artifact kinds).
36
+ */
37
+
38
+ const MESSAGES = Object.freeze({
39
+ 'blockView.cite': 'Source %1',
40
+ 'blockView.citeTitled': 'Source %1: %2',
41
+ 'blockView.copyCode': 'Copy code',
42
+ 'blockView.code': 'Code',
43
+ 'blockView.document': 'Document',
44
+ 'blockView.versions': '%1 versions',
45
+ 'blockView.version': '1 version',
46
+ 'blockView.table': 'Table',
47
+ 'blockView.stopped': 'Stopped here.'
48
+ });
49
+
50
+ /** Glyph for each callout tone. */
51
+ const CALLOUT_ICONS = Object.freeze({ info: 'info', success: 'success', warning: 'warning', danger: 'error' });
52
+
53
+ /**
54
+ * An answer an agent wrote, drawn block by block as semantic elements inside `.zx-prose`, and
55
+ * written to as it streams. Finished blocks are never redrawn: `appendText()` and `append()` touch
56
+ * only the last block, so a reader's selection or focus in an earlier paragraph survives the rest
57
+ * of the answer arriving.
58
+ *
59
+ * @fires BlockView#cite
60
+ * @fires BlockView#artifact
61
+ * @fires BlockView#end
62
+ * @extends {Component<BlockViewOptions>}
63
+ */
64
+ export class BlockView extends Component {
65
+ static cssName = 'block-view';
66
+
67
+ /** @type {Readonly<BlockViewOptions>} */
68
+ static defaults = {
69
+ blocks: [],
70
+ headingLevel: 3,
71
+ size: 'sm',
72
+ streaming: false,
73
+ sources: null,
74
+ msg: MESSAGES
75
+ };
76
+
77
+ /** @returns {HTMLElement} */
78
+ render() {
79
+ const created = !this.el;
80
+ const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
81
+ this.el = root;
82
+ this._original = created ? null : snapshotTarget(root);
83
+ if (!created) root.replaceChildren();
84
+ root.classList.add('zx-prose');
85
+ /** @type {Block[]} */
86
+ this._blocks = [];
87
+ /** @type {HTMLElement[]} */
88
+ this._nodes = [];
89
+ /** @type {Source[]} */
90
+ this._sources = Array.isArray(this.options.sources) ? [...this.options.sources] : [];
91
+ this._streaming = Boolean(this.options.streaming);
92
+ this._stopped = false;
93
+ /** @type {HTMLElement|null} */
94
+ this._stoppedNote = null;
95
+ if (this.options.size !== 'md') root.dataset.size = 'sm';
96
+ root.dataset.zxMeasure = 'full';
97
+ this._syncState();
98
+ this.listen(root, 'click', (event) => this._onClick(/** @type {MouseEvent} */ (event)));
99
+ this._observer = typeof ResizeObserver === 'function'
100
+ ? new ResizeObserver(() => this._syncScrollers())
101
+ : null;
102
+ this._observer?.observe(root);
103
+ for (const block of Array.isArray(this.options.blocks) ? this.options.blocks : []) this._push(block);
104
+ return root;
105
+ }
106
+
107
+ /**
108
+ * Replaces every block, clearing a stopped state.
109
+ * @param {Block[]} blocks
110
+ * @param {{streaming?: boolean}} [options={}] `streaming: true` starts a new streamed answer
111
+ * from these blocks; otherwise the streaming state is kept.
112
+ * @returns {this}
113
+ */
114
+ setBlocks(blocks, options = {}) {
115
+ for (const node of this._nodes) node.remove();
116
+ this._blocks = [];
117
+ this._nodes = [];
118
+ this._stoppedNote?.remove();
119
+ this._stoppedNote = null;
120
+ this._stopped = false;
121
+ if (typeof options.streaming === 'boolean') this._streaming = options.streaming;
122
+ for (const block of Array.isArray(blocks) ? blocks : []) this._push(block);
123
+ this._syncState();
124
+ return this;
125
+ }
126
+
127
+ /**
128
+ * Adds a block after the last one. The blocks before it are left as they are.
129
+ * @param {Block} block
130
+ * @returns {this}
131
+ */
132
+ append(block) {
133
+ this._push(block);
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Streams text into the answer. It continues the last paragraph, or opens one when the answer
139
+ * ends in anything else; a blank line in the text starts a new paragraph. Only the last
140
+ * paragraph is redrawn, so a marker split across two calls (`**bo` … `ld**`) resolves as soon as
141
+ * its close arrives.
142
+ * @param {string} text
143
+ * @returns {this}
144
+ */
145
+ appendText(text) {
146
+ const chunk = String(text ?? '');
147
+ if (!chunk) return this;
148
+ const last = this._blocks.at(-1);
149
+ if (last?.type !== 'p') {
150
+ this._push({ type: 'p', text: '' });
151
+ }
152
+ const tail = /** @type {{type: 'p', text: string}} */ (this._blocks.at(-1));
153
+ // Split on a blank line only once text follows it: a chunk may end between the two newlines,
154
+ // or right after them, and the paragraph must not open until there is something to put in it.
155
+ const parts = (tail.text + chunk).split(/\n{2,}(?=\S)/);
156
+ tail.text = /** @type {string} */ (parts.shift());
157
+ this._redrawLast();
158
+ for (const part of parts) this._push({ type: 'p', text: part });
159
+ return this;
160
+ }
161
+
162
+ /**
163
+ * Marks the answer finished.
164
+ * @returns {this}
165
+ */
166
+ end() {
167
+ const wasStreaming = this._streaming;
168
+ this._streaming = false;
169
+ this._syncState();
170
+ if (wasStreaming) this.emit('end', {});
171
+ return this;
172
+ }
173
+
174
+ /**
175
+ * Marks the answer stopped where it is, with a line saying so.
176
+ * @returns {this}
177
+ */
178
+ stop() {
179
+ this._streaming = false;
180
+ if (!this._stopped) {
181
+ this._stopped = true;
182
+ this._stoppedNote = h('p', { class: 'zx-block-view__stopped' }, this.msg('blockView.stopped'));
183
+ this.el.append(this._stoppedNote);
184
+ }
185
+ this._syncState();
186
+ return this;
187
+ }
188
+
189
+ /**
190
+ * Sets the sources citations point at.
191
+ * @param {Source[]} sources
192
+ * @returns {this}
193
+ */
194
+ setSources(sources) {
195
+ this._sources = Array.isArray(sources) ? [...sources] : [];
196
+ for (const button of this.el.querySelectorAll('[data-cite]')) {
197
+ button.setAttribute('aria-label', this._citeLabel(Number(/** @type {HTMLElement} */ (button).dataset.cite)));
198
+ }
199
+ return this;
200
+ }
201
+
202
+ /**
203
+ * Says whether an artifact's card has its artifact open somewhere — an inspector, a drawer — so
204
+ * the card reads as pressed and names what it controls. The application owns the open state;
205
+ * the card only reflects it.
206
+ * @param {string} id Artifact id.
207
+ * @param {{expanded?: boolean|null, controls?: string|null}} state `expanded` sets or (null)
208
+ * removes `aria-expanded`; `controls` sets or (null) removes `aria-controls`.
209
+ * @returns {this}
210
+ */
211
+ setArtifactState(id, state = {}) {
212
+ for (const card of /** @type {NodeListOf<HTMLElement>} */ (this.el.querySelectorAll('button[data-artifact]'))) {
213
+ if (card.dataset.artifact !== String(id)) continue;
214
+ if ('expanded' in state) {
215
+ if (state.expanded == null) card.removeAttribute('aria-expanded');
216
+ else card.setAttribute('aria-expanded', String(Boolean(state.expanded)));
217
+ }
218
+ if ('controls' in state) {
219
+ if (state.controls) card.setAttribute('aria-controls', String(state.controls));
220
+ else card.removeAttribute('aria-controls');
221
+ }
222
+ }
223
+ return this;
224
+ }
225
+
226
+ /** @returns {Block[]} A copy of the blocks. */
227
+ getBlocks() {
228
+ return structuredClone(this._blocks);
229
+ }
230
+
231
+ /** @returns {boolean} Whether more is still being written. */
232
+ isStreaming() {
233
+ return this._streaming;
234
+ }
235
+
236
+ /** @returns {string} The answer as plain text. */
237
+ toText() {
238
+ return blocksToText(this._blocks);
239
+ }
240
+
241
+ /** @returns {string} The answer as Markdown. */
242
+ toMarkdown() {
243
+ return blocksToMarkdown(this._blocks);
244
+ }
245
+
246
+ /** @returns {void} */
247
+ destroy() {
248
+ if (this._destroyed) return;
249
+ this._destroyed = true;
250
+ this._observer?.disconnect();
251
+ this._observer = null;
252
+ super.destroy();
253
+ if (this._original) restoreTarget(this.el, this._original);
254
+ }
255
+
256
+ /**
257
+ * @private
258
+ * @param {Block} block
259
+ * @returns {void}
260
+ */
261
+ _push(block) {
262
+ if (!block || typeof block !== 'object') return;
263
+ const copy = /** @type {Block} */ (structuredClone(block));
264
+ const node = renderBlock(copy, this._renderOptions());
265
+ this._blocks.push(copy);
266
+ this._nodes.push(node);
267
+ if (this._stoppedNote) this._stoppedNote.before(node);
268
+ else this.el.append(node);
269
+ if (copy.type === 'table') this._syncScrollers();
270
+ }
271
+
272
+ /** @private @returns {void} */
273
+ _redrawLast() {
274
+ const index = this._blocks.length - 1;
275
+ if (index < 0) return;
276
+ const node = renderBlock(this._blocks[index], this._renderOptions());
277
+ this._nodes[index].replaceWith(node);
278
+ this._nodes[index] = node;
279
+ }
280
+
281
+ /** @private @returns {RenderBlocksOptions & {cite: (n: number) => Node, artifact: boolean}} */
282
+ _renderOptions() {
283
+ return {
284
+ headingLevel: this.options.headingLevel,
285
+ msg: (key, ...args) => this.msg(key, ...args),
286
+ cite: (n) => h('sup', { class: 'zx-block-view__cite' }, h('button', {
287
+ type: 'button', class: 'zx-block-view__cite-button', dataset: { cite: String(n) }, 'aria-label': this._citeLabel(n)
288
+ }, String(n))),
289
+ artifact: true
290
+ };
291
+ }
292
+
293
+ /** @private @param {number} n @returns {string} */
294
+ _citeLabel(n) {
295
+ const source = this._sourceAt(n);
296
+ return source ? this.msg('blockView.citeTitled', n, source.title) : this.msg('blockView.cite', n);
297
+ }
298
+
299
+ /** @private @param {number} n @returns {Source|null} */
300
+ _sourceAt(n) {
301
+ return this._sources[n - 1] ?? null;
302
+ }
303
+
304
+ /** @private @returns {void} */
305
+ _syncState() {
306
+ const root = /** @type {HTMLElement} */ (this.el);
307
+ root.dataset.state = this._stopped ? 'stopped' : this._streaming ? 'streaming' : 'done';
308
+ if (this._streaming) root.setAttribute('aria-busy', 'true');
309
+ else root.removeAttribute('aria-busy');
310
+ }
311
+
312
+ /**
313
+ * A wide table scrolls inside the answer; while it does, its wrapper is a named, focusable
314
+ * region so the keyboard can scroll it too. A table that fits is not a tab stop.
315
+ * @private
316
+ * @returns {void}
317
+ */
318
+ _syncScrollers() {
319
+ for (const wrap of /** @type {NodeListOf<HTMLElement>} */ (this.el.querySelectorAll('.zx-block-view__table'))) {
320
+ const overflowing = wrap.scrollWidth > wrap.clientWidth + 1;
321
+ if (overflowing && !wrap.hasAttribute('tabindex')) {
322
+ wrap.tabIndex = 0;
323
+ wrap.setAttribute('role', 'region');
324
+ wrap.setAttribute('aria-label', this.msg('blockView.table'));
325
+ } else if (!overflowing && wrap.hasAttribute('tabindex')) {
326
+ wrap.removeAttribute('tabindex');
327
+ wrap.removeAttribute('role');
328
+ wrap.removeAttribute('aria-label');
329
+ }
330
+ }
331
+ }
332
+
333
+ /** @private @param {MouseEvent} event @returns {void} */
334
+ _onClick(event) {
335
+ const target = /** @type {Element|null} */ (event.target instanceof Element ? event.target : null);
336
+ const cite = /** @type {HTMLElement|null} */ (target?.closest('[data-cite]') ?? null);
337
+ if (cite && this.el.contains(cite)) {
338
+ const n = Number(cite.dataset.cite);
339
+ this.emit('cite', { n, source: this._sourceAt(n) });
340
+ return;
341
+ }
342
+ const artifact = /** @type {HTMLElement|null} */ (target?.closest('[data-artifact]') ?? null);
343
+ if (artifact && this.el.contains(artifact)) this.emit('artifact', { id: String(artifact.dataset.artifact) });
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Citation listener payload.
349
+ * @event BlockView#cite
350
+ * @type {CustomEvent<{n: number, source: Source|null}>}
351
+ */
352
+ /**
353
+ * Artifact card listener payload.
354
+ * @event BlockView#artifact
355
+ * @type {CustomEvent<{id: string}>}
356
+ */
357
+ /**
358
+ * Fired when a streaming answer is marked finished.
359
+ * @event BlockView#end
360
+ * @type {CustomEvent<Record<string, never>>}
361
+ */
362
+
363
+ /**
364
+ * Draws blocks without a component, for a static answer: a transcript, a print view, a preview.
365
+ * Citations are plain superscripts and artifacts plain cards; use `BlockView` for them to act.
366
+ * @param {Block[]} blocks
367
+ * @param {RenderBlocksOptions} [options={}]
368
+ * @returns {DocumentFragment}
369
+ */
370
+ export function renderBlocks(blocks, options = {}) {
371
+ const fragment = document.createDocumentFragment();
372
+ for (const block of Array.isArray(blocks) ? blocks : []) {
373
+ if (block && typeof block === 'object') fragment.append(renderBlock(block, options));
374
+ }
375
+ return fragment;
376
+ }
377
+
378
+ /**
379
+ * @param {string} key
380
+ * @param {...unknown} args
381
+ * @returns {string}
382
+ */
383
+ function englishMessage(key, ...args) {
384
+ const text = MESSAGES[/** @type {keyof typeof MESSAGES} */ (key)] ?? key;
385
+ return text.replace(/%(\d+)/g, (match, index) => String(args[Number(index) - 1] ?? match));
386
+ }
387
+
388
+ /**
389
+ * Draws a run of model text as text nodes, `<strong>`, `<code>`, and citations — never as HTML.
390
+ * @param {string} text
391
+ * @param {((n: number) => Node)|undefined} cite Draws a citation; a plain superscript without it.
392
+ * @returns {Array<Node|string>}
393
+ */
394
+ function inlineNodes(text, cite) {
395
+ return parseInline(text).map((segment) => {
396
+ if (segment.kind === 'strong') return h('strong', {}, segment.text);
397
+ if (segment.kind === 'code') return h('code', {}, segment.text);
398
+ if (segment.kind === 'cite') return cite ? cite(segment.n) : h('sup', { class: 'zx-block-view__cite' }, String(segment.n));
399
+ return segment.text;
400
+ });
401
+ }
402
+
403
+ /**
404
+ * @param {Block} block
405
+ * @param {RenderBlocksOptions & {cite?: (n: number) => Node, artifact?: boolean}} options
406
+ * @returns {HTMLElement}
407
+ */
408
+ function renderBlock(block, options) {
409
+ const msg = options.msg ?? englishMessage;
410
+ const cite = options.cite;
411
+ const base = Math.min(5, Math.max(2, Number(options.headingLevel) || 3));
412
+ switch (block.type) {
413
+ case 'heading':
414
+ return h(`h${block.level === 3 ? base + 1 : base}`, {}, inlineNodes(block.text, cite));
415
+ case 'quote':
416
+ return h('blockquote', { class: 'zx-block-view__quote' },
417
+ String(block.text ?? '').split(/\n{2,}/).map((paragraph) => h('p', {}, inlineNodes(paragraph, cite))));
418
+ case 'list':
419
+ return h(block.ordered ? 'ol' : 'ul', {},
420
+ (Array.isArray(block.items) ? block.items : []).map((item) => h('li', {}, inlineNodes(item, cite))));
421
+ case 'code':
422
+ return renderCode(block, msg);
423
+ case 'table':
424
+ return renderTable(block, cite);
425
+ case 'figures':
426
+ return h('dl', { class: 'zx-block-view__figures' }, (Array.isArray(block.rows) ? block.rows : []).map((entry) => {
427
+ const row = figureRow(entry);
428
+ return h('div', { class: 'zx-block-view__figure' },
429
+ h('dt', { class: 'zx-block-view__figure-label' }, row.label),
430
+ row.detail ? h('dd', { class: 'zx-block-view__figure-detail' }, row.detail) : null,
431
+ h('dd', { class: 'zx-block-view__figure-value' }, row.value));
432
+ }));
433
+ case 'callout': {
434
+ const tone = Object.hasOwn(CALLOUT_ICONS, String(block.tone)) ? String(block.tone) : null;
435
+ return h('div', { class: 'zx-callout zx-block-view__callout', dataset: { kind: tone } },
436
+ tone ? h('span', { class: 'zx-callout__icon', 'aria-hidden': 'true' },
437
+ icon(CALLOUT_ICONS[/** @type {keyof typeof CALLOUT_ICONS} */ (tone)], { size: 16 })) : null,
438
+ h('div', { class: 'zx-callout__body' },
439
+ block.title ? h('p', { class: 'zx-callout__title' }, block.title) : null,
440
+ h('p', {}, inlineNodes(block.text, cite))));
441
+ }
442
+ case 'artifact':
443
+ return renderArtifact(block, msg, Boolean(options.artifact));
444
+ default:
445
+ return h('p', {}, inlineNodes(/** @type {{text?: string}} */ (block).text ?? '', cite));
446
+ }
447
+ }
448
+
449
+ /**
450
+ * @param {Extract<Block, {type: 'code'}>} block
451
+ * @param {(key: string, ...args: unknown[]) => string} msg
452
+ * @returns {HTMLElement}
453
+ */
454
+ function renderCode(block, msg) {
455
+ const language = typeof block.language === 'string' ? block.language : '';
456
+ return h('figure', { class: 'zx-block-view__code' },
457
+ h('figcaption', { class: 'zx-block-view__code-head' },
458
+ h('span', { class: 'zx-block-view__code-language' }, language || msg('blockView.code')),
459
+ copyButton({ text: String(block.code ?? ''), title: msg('blockView.copyCode'), size: 'sm' })),
460
+ block.lines
461
+ ? h('pre', { class: 'zx-block-view__pre', dataset: { lines: '' }, tabindex: '0' }, h('code', {},
462
+ String(block.code ?? '').split('\n').map((line) => h('span', {
463
+ class: 'zx-block-view__line', style: { '--zx-block-view-indent': `${/^\s*/.exec(line)?.[0].length ?? 0}ch` }
464
+ }, codeSegments(language, line)))))
465
+ : h('pre', { class: 'zx-block-view__pre', tabindex: '0' }, h('code', {}, codeSegments(language, block.code))));
466
+ }
467
+
468
+ /**
469
+ * Coloured code as text nodes and spans, never HTML.
470
+ * @param {string} language
471
+ * @param {string} code
472
+ * @returns {Array<Node|string>}
473
+ */
474
+ function codeSegments(language, code) {
475
+ return highlight(language, code).map((segment) => (segment.token
476
+ ? h('span', { class: 'zx-block-view__token', dataset: { token: segment.token } }, segment.text)
477
+ : segment.text));
478
+ }
479
+
480
+ /**
481
+ * @param {Extract<Block, {type: 'table'}>} block
482
+ * @param {((n: number) => Node)|undefined} cite
483
+ * @returns {HTMLElement}
484
+ */
485
+ function renderTable(block, cite) {
486
+ const columns = Array.isArray(block.columns) ? block.columns : [];
487
+ const rows = Array.isArray(block.rows) ? block.rows : [];
488
+ const align = (/** @type {number} */ index) => {
489
+ const value = block.align?.[index];
490
+ return value === 'end' || value === 'center' ? value : null;
491
+ };
492
+ return h('div', { class: 'zx-block-view__table' }, h('table', {},
493
+ h('thead', {}, h('tr', {}, columns.map((column, index) => h('th', { scope: 'col', dataset: { align: align(index) } },
494
+ inlineNodes(column, cite))))),
495
+ h('tbody', {}, rows.map((row) => h('tr', {}, (Array.isArray(row) ? row : []).map((cell, index) => h('td', {
496
+ dataset: { align: align(index) }
497
+ }, inlineNodes(cell, cite))))))));
498
+ }
499
+
500
+ /**
501
+ * @param {Extract<Block, {type: 'artifact'}>} block
502
+ * @param {(key: string, ...args: unknown[]) => string} msg
503
+ * @param {boolean} interactive
504
+ * @returns {HTMLElement}
505
+ */
506
+ function renderArtifact(block, msg, interactive) {
507
+ const kind = block.kind === 'code' ? 'code' : 'document';
508
+ const versions = Number(block.versions) || 0;
509
+ const meta = [msg(kind === 'code' ? 'blockView.code' : 'blockView.document'),
510
+ versions > 1 ? msg('blockView.versions', versions) : versions === 1 ? msg('blockView.version') : null].filter(Boolean).join(' · ');
511
+ const content = [
512
+ h('span', { class: 'zx-block-view__artifact-tile', dataset: { kind }, 'aria-hidden': 'true' },
513
+ icon(kind === 'code' ? 'code' : 'file', { size: 16 })),
514
+ h('span', { class: 'zx-block-view__artifact-copy' },
515
+ h('span', { class: 'zx-block-view__artifact-name' }, String(block.title ?? '')),
516
+ h('span', { class: 'zx-block-view__artifact-meta' }, meta)),
517
+ interactive ? h('span', { class: 'zx-block-view__artifact-chevron', 'aria-hidden': 'true' }, icon('chevron-right', { size: 14 })) : null
518
+ ];
519
+ return interactive
520
+ ? h('p', { class: 'zx-block-view__artifact-row' },
521
+ h('button', { type: 'button', class: 'zx-block-view__artifact', dataset: { artifact: String(block.id ?? '') } }, content))
522
+ : h('p', { class: 'zx-block-view__artifact-row' }, h('span', { class: 'zx-block-view__artifact' }, content));
523
+ }
@@ -21,15 +21,31 @@
21
21
  font-size: var(--zx-text-sm);
22
22
  }
23
23
 
24
+ /*
25
+ * When the trail runs short of room — a host that keeps it on one line — the ancestors give way
26
+ * first: each shortens to an ellipsis, down to its separator and a letter or two, before the page
27
+ * you are on gives anything. The folded levels behind "…" and the separators never shrink. An
28
+ * item's floor is its own minimum width (see the label below), so a shortened level never spills
29
+ * over its neighbour.
30
+ */
24
31
  .zx-breadcrumb__item {
25
32
  display: inline-flex;
33
+ flex: 0 1000 auto;
26
34
  align-items: center;
27
35
  gap: var(--zx-space-1);
28
- min-inline-size: 0;
36
+ }
37
+
38
+ .zx-breadcrumb__item:has(> .zx-breadcrumb__current) {
39
+ flex-shrink: 1;
40
+ }
41
+
42
+ .zx-breadcrumb__item:has(> .zx-breadcrumb__more) {
43
+ flex-shrink: 0;
29
44
  }
30
45
 
31
46
  .zx-breadcrumb__separator {
32
47
  display: inline-flex;
48
+ flex: none;
33
49
  align-items: center;
34
50
  color: var(--zx-color-text-placeholder);
35
51
  }
@@ -72,10 +88,19 @@
72
88
  font-weight: 600;
73
89
  }
74
90
 
91
+ /* One line, ending in an ellipsis when it is cut. Clamped rather than kept from wrapping: a label
92
+ that may break between any two letters fills its line before the ellipsis, and is narrow at its
93
+ narrowest — a letter and the ellipsis — which is what lets an item shrink to a stub instead of
94
+ holding its full width or collapsing to nothing. Start-aligned, since a crumb without an href is
95
+ a button, which centres its text. */
75
96
  .zx-breadcrumb__label {
97
+ display: -webkit-box;
98
+ min-inline-size: 1.5em;
76
99
  overflow: hidden;
77
- text-overflow: ellipsis;
78
- white-space: nowrap;
100
+ text-align: start;
101
+ word-break: break-all;
102
+ -webkit-box-orient: vertical;
103
+ -webkit-line-clamp: 1;
79
104
  }
80
105
 
81
106
  .zx-breadcrumb__icon {
@@ -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 { MenuButton } from '../menu-button/menu-button.js';
6
6
 
7
7
  /** @typedef {'chevron'|'slash'} BreadcrumbSeparator */
@@ -296,7 +296,7 @@ export class Breadcrumb extends Component {
296
296
  /** @returns {HTMLElement} */
297
297
  _renderSeparator() {
298
298
  return h('span', { class: 'zx-breadcrumb__separator', ariaHidden: 'true' },
299
- this.options.separator === 'slash' ? '/' : icon('chevron-right', { size: 11 }));
299
+ this.options.separator === 'slash' ? '/' : icon('chevron-right', { size: ICON_SIZE.chevron }));
300
300
  }
301
301
 
302
302
  /**
@@ -23,7 +23,10 @@
23
23
  box-shadow var(--zx-dur-fast) var(--zx-ease);
24
24
  }
25
25
 
26
- .zx-btn:hover:not(:disabled) {
26
+ /* A trigger whose menu or popover is open holds its hover fill for as long as the panel is open,
27
+ in every kind, so the panel in front always points back to what opened it. */
28
+ .zx-btn:hover:not(:disabled),
29
+ .zx-btn[aria-expanded="true"]:not(:disabled) {
27
30
  background: var(--zx-color-glass-control-hover);
28
31
  }
29
32
 
@@ -48,7 +51,8 @@
48
51
  color: var(--zx-color-on-accent-solid);
49
52
  }
50
53
 
51
- .zx-btn[data-kind="primary"]:hover:not(:disabled) {
54
+ .zx-btn[data-kind="primary"]:hover:not(:disabled),
55
+ .zx-btn[data-kind="primary"][aria-expanded="true"]:not(:disabled) {
52
56
  border-color: var(--zx-color-accent-solid-hover);
53
57
  background: var(--zx-color-accent-solid-hover);
54
58
  }
@@ -58,13 +62,20 @@
58
62
  background: var(--zx-color-accent-solid-active);
59
63
  }
60
64
 
65
+ /* The focus ring is the accent too, so on the solid fill a 1px line in the button's own ink keeps
66
+ the two apart; without it focus would only make the button look two pixels larger. */
67
+ .zx-btn[data-kind="primary"]:focus-visible {
68
+ box-shadow: inset 0 0 0 1px var(--zx-color-on-accent-solid), var(--zx-focus-ring);
69
+ }
70
+
61
71
  .zx-btn[data-kind="danger"] {
62
72
  border-color: var(--zx-color-danger);
63
73
  background: var(--zx-color-danger);
64
74
  color: var(--zx-color-on-accent);
65
75
  }
66
76
 
67
- .zx-btn[data-kind="danger"]:hover:not(:disabled) {
77
+ .zx-btn[data-kind="danger"]:hover:not(:disabled),
78
+ .zx-btn[data-kind="danger"][aria-expanded="true"]:not(:disabled) {
68
79
  background: color-mix(in srgb, var(--zx-color-danger) 88%, var(--zx-color-text));
69
80
  }
70
81
 
@@ -86,12 +97,14 @@
86
97
  color: var(--zx-color-text-subtle);
87
98
  }
88
99
 
89
- .zx-btn[data-kind="ghost"]:hover:not(:disabled) {
100
+ .zx-btn[data-kind="ghost"]:hover:not(:disabled),
101
+ .zx-btn[data-kind="ghost"][aria-expanded="true"]:not(:disabled) {
90
102
  border-color: transparent;
91
103
  background: var(--zx-color-bg-hover);
92
104
  }
93
105
 
94
- .zx-btn[data-kind="ghost"]:hover:not(:disabled) > .zx-icon {
106
+ .zx-btn[data-kind="ghost"]:hover:not(:disabled) > .zx-icon,
107
+ .zx-btn[data-kind="ghost"][aria-expanded="true"]:not(:disabled) > .zx-icon {
95
108
  color: var(--zx-color-text);
96
109
  }
97
110
 
@@ -143,19 +156,17 @@
143
156
  flex: none;
144
157
  }
145
158
 
146
- /* The key hint is quieter than the label by colour and weight, not by opacity: faded white on a
147
- solid fill falls below 4.5:1. On a solid button it keeps the button's ink at a lighter weight. */
159
+ /* The key hint is a keycap (`kbd()`), so "New company N" reads as a label and a key, not as a
160
+ typo. On a solid button the cap is drawn in the button's own ink — a tint of it for the fill,
161
+ a stronger one for the edge — never a faded white, which falls below 4.5:1. */
148
162
  .zx-btn__shortcut {
149
- font: inherit;
150
- font-size: var(--zx-text-xs);
151
- font-weight: 400;
152
- color: var(--zx-color-text-muted);
153
163
  margin-inline-start: var(--zx-space-1);
154
- white-space: nowrap;
155
164
  }
156
165
 
157
166
  .zx-btn:is([data-kind="primary"], [data-kind="danger"]) .zx-btn__shortcut {
158
- color: inherit;
167
+ --zx-kbd-ink: currentColor;
168
+ --zx-kbd-fill: color-mix(in srgb, currentColor 14%, transparent);
169
+ --zx-kbd-line: color-mix(in srgb, currentColor 32%, transparent);
159
170
  }
160
171
 
161
172
  .zx-btn-group > .zx-btn:not(:first-child) {