@zeyos/zx 5.7.0 → 5.8.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 +330 -0
- package/README.md +47 -9
- package/dist/types/components/activity-item/activity-item.d.ts +14 -3
- package/dist/types/components/agent-avatar/agent-avatar.d.ts +165 -0
- package/dist/types/components/agent-avatar/agent-face.d.ts +93 -0
- package/dist/types/components/agent-thread/ag-ui.d.ts +21 -9
- package/dist/types/components/agent-thread/agent-thread.d.ts +26 -0
- package/dist/types/components/agent-thread/ui-message-stream.d.ts +3 -1
- package/dist/types/components/approval-card/approval-card.d.ts +31 -2
- package/dist/types/components/aurora/aurora.d.ts +31 -5
- package/dist/types/components/calendar/calendar.d.ts +39 -26
- package/dist/types/components/chart/chart.d.ts +250 -20
- package/dist/types/components/chart/color.d.ts +66 -0
- package/dist/types/components/chart/svg-adapter.d.ts +103 -0
- package/dist/types/components/chart/svg-geometry.d.ts +203 -0
- package/dist/types/components/check-button/check-button.d.ts +1 -4
- package/dist/types/components/checklist/checklist.d.ts +48 -5
- package/dist/types/components/code-editor/code-editor.d.ts +55 -1
- package/dist/types/components/composer/composer.d.ts +41 -6
- package/dist/types/components/context-menu/context-menu.d.ts +36 -8
- package/dist/types/components/copy/copy-button.d.ts +6 -0
- package/dist/types/components/copy/copy-input.d.ts +1 -0
- package/dist/types/components/date-picker/date-picker.d.ts +14 -0
- package/dist/types/components/date-picker/time-picker.d.ts +26 -17
- package/dist/types/components/datebox/datebox.d.ts +8 -4
- package/dist/types/components/dialog/dialog.d.ts +15 -4
- package/dist/types/components/empty-state/empty-state.d.ts +10 -1
- package/dist/types/components/field/field.d.ts +4 -2
- package/dist/types/components/form/form.d.ts +2 -1
- package/dist/types/components/kanban-view/kanban-card.d.ts +7 -0
- package/dist/types/components/kanban-view/kanban-view.d.ts +15 -3
- package/dist/types/components/launcher/launcher.d.ts +26 -0
- package/dist/types/components/master-panel/master-panel.d.ts +9 -4
- package/dist/types/components/menu-button/menu-button.d.ts +29 -5
- package/dist/types/components/message/message.d.ts +308 -5
- package/dist/types/components/modal/modal.d.ts +45 -8
- package/dist/types/components/modal/native-dialog.d.ts +40 -0
- package/dist/types/components/module-bar/module-bar.d.ts +9 -2
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +5 -4
- package/dist/types/components/number-field/number-field.d.ts +31 -1
- package/dist/types/components/pagination/pagination.d.ts +341 -19
- package/dist/types/components/run-status/run-status.d.ts +26 -0
- package/dist/types/components/run-trace/run-trace.d.ts +10 -6
- package/dist/types/components/search/search.d.ts +16 -4
- package/dist/types/components/select/select.d.ts +19 -1
- package/dist/types/components/sheet/sheet.d.ts +20 -6
- package/dist/types/components/slider/slider.d.ts +2 -1
- package/dist/types/components/stat-tile/stat-tile.d.ts +20 -3
- package/dist/types/components/stepper/stepper.d.ts +17 -4
- package/dist/types/components/surface/catalog.d.ts +61 -17
- package/dist/types/components/surface/surface.d.ts +6 -4
- package/dist/types/components/table/table.d.ts +207 -5
- package/dist/types/components/table/window.d.ts +25 -1
- package/dist/types/components/toggle/toggle.d.ts +38 -6
- package/dist/types/components/tooltip/tooltip.d.ts +5 -4
- package/dist/types/components/tree/tree.d.ts +43 -6
- package/dist/types/components/truncate/truncate.d.ts +4 -2
- package/dist/types/components/value-list/value-list.d.ts +9 -2
- package/dist/types/core/date.d.ts +2 -1
- package/dist/types/core/dom.d.ts +14 -0
- package/dist/types/core/drag-axis.d.ts +10 -5
- package/dist/types/core/export.d.ts +2 -2
- package/dist/types/core/format.d.ts +3 -1
- package/dist/types/core/icons.d.ts +36 -3
- package/dist/types/core/keyboard.d.ts +7 -3
- package/dist/types/core/messages.d.ts +3 -0
- package/dist/types/core/storage.d.ts +4 -3
- package/dist/types/core/util.d.ts +3 -1
- package/dist/types/elements/define.d.ts +5 -2
- package/dist/types/index.d.ts +6 -4
- package/dist/types/internal/agent-model.d.ts +99 -0
- package/dist/types/internal/app-rail.d.ts +37 -2
- package/dist/types/internal/collections.d.ts +18 -0
- package/dist/types/internal/menu-items.d.ts +27 -0
- package/dist/types/internal/overlay-content.d.ts +23 -0
- package/dist/types/internal/presence-loop.d.ts +5 -2
- package/dist/types/locales/index.d.ts +3 -0
- package/dist/types/zeyos/calendar.d.ts +43 -7
- package/dist/types/zeyos/connect.d.ts +4 -0
- package/dist/types/zeyos/form.d.ts +13 -5
- package/dist/types/zeyos/select.d.ts +5 -2
- package/dist/types/zeyos/table.d.ts +16 -8
- package/dist/types/zeyos/view.d.ts +2 -1
- package/dist/zx-zeyos.esm.js +3161 -515
- package/dist/zx-zeyos.esm.min.js +4 -4
- package/dist/zx.core.css +4 -0
- package/dist/zx.core.min.css +1 -1
- package/dist/zx.css +970 -57
- package/dist/zx.esm.js +6405 -2249
- package/dist/zx.esm.min.js +26 -26
- package/dist/zx.global.js +6405 -2249
- package/dist/zx.global.min.js +26 -26
- package/dist/zx.layered.css +972 -57
- package/dist/zx.layered.min.css +1 -1
- package/dist/zx.min.css +1 -1
- package/docs/agent-catalog.json +159 -1
- package/docs/agent-surfaces.md +21 -21
- package/docs/api.json +3154 -518
- package/docs/components/account-menu.md +24 -0
- package/docs/components/activity-item.md +23 -0
- package/docs/components/activity-list.md +28 -0
- package/docs/components/agent-avatar.md +59 -0
- package/docs/components/agent-thread.md +275 -0
- package/docs/components/app-icon.md +36 -0
- package/docs/components/app-sidebar.md +92 -0
- package/docs/components/approval-card.md +71 -0
- package/docs/components/aurora.md +34 -0
- package/docs/components/avatar.md +37 -0
- package/docs/components/badge.md +36 -0
- package/docs/components/block-view.md +34 -0
- package/docs/components/breadcrumb.md +20 -0
- package/docs/components/button.md +23 -0
- package/docs/components/calendar.md +68 -0
- package/docs/components/card-view.md +73 -0
- package/docs/components/card.md +25 -0
- package/docs/components/chart.md +109 -0
- package/docs/components/check-button.md +16 -0
- package/docs/components/checklist.md +19 -0
- package/docs/components/code-editor.md +38 -0
- package/docs/components/composer.md +107 -0
- package/docs/components/context-menu.md +32 -0
- package/docs/components/copy.md +37 -0
- package/docs/components/data-filter.md +16 -0
- package/docs/components/date-picker.md +31 -0
- package/docs/components/date-range.md +21 -0
- package/docs/components/datebox.md +31 -0
- package/docs/components/dialog.md +25 -0
- package/docs/components/dock.md +57 -0
- package/docs/components/dropdown.md +39 -0
- package/docs/components/elements.md +63 -0
- package/docs/components/empty-state.md +17 -0
- package/docs/components/entity-ref.md +26 -0
- package/docs/components/field-upload.md +18 -0
- package/docs/components/file-item.md +27 -0
- package/docs/components/file-list.md +23 -0
- package/docs/components/filter-panel.md +45 -0
- package/docs/components/filter.md +47 -0
- package/docs/components/finder.md +25 -0
- package/docs/components/form-widgets.md +42 -0
- package/docs/components/form.md +80 -0
- package/docs/components/grid.md +26 -0
- package/docs/components/groupbox.md +11 -0
- package/docs/components/helpers.md +359 -0
- package/docs/components/icons.md +87 -0
- package/docs/components/index.md +99 -0
- package/docs/components/kanban-view.md +42 -0
- package/docs/components/kbd.md +23 -0
- package/docs/components/kernel.md +41 -0
- package/docs/components/launcher.md +66 -0
- package/docs/components/layout.md +33 -0
- package/docs/components/list-toolbar.md +38 -0
- package/docs/components/loading.md +48 -0
- package/docs/components/menu-button.md +47 -0
- package/docs/components/message.md +76 -0
- package/docs/components/modal.md +27 -0
- package/docs/components/module-bar.md +71 -0
- package/docs/components/multi-value-editor.md +16 -0
- package/docs/components/navigation-bar.md +22 -0
- package/docs/components/number-field.md +34 -0
- package/docs/components/pagination.md +73 -0
- package/docs/components/panel.md +28 -0
- package/docs/components/prompt-starters.md +40 -0
- package/docs/components/prose.md +38 -0
- package/docs/components/questionnaire.md +115 -0
- package/docs/components/rating.md +19 -0
- package/docs/components/run-status.md +50 -0
- package/docs/components/run-trace.md +72 -0
- package/docs/components/search.md +11 -0
- package/docs/components/select.md +129 -0
- package/docs/components/sheet-stack.md +39 -0
- package/docs/components/sheet.md +77 -0
- package/docs/components/skeleton.md +27 -0
- package/docs/components/slider.md +29 -0
- package/docs/components/sort-control.md +21 -0
- package/docs/components/source-list.md +30 -0
- package/docs/components/split-view.md +12 -0
- package/docs/components/stat-tile.md +49 -0
- package/docs/components/stepper.md +27 -0
- package/docs/components/surface.md +152 -0
- package/docs/components/tabbox.md +33 -0
- package/docs/components/table-view.md +43 -0
- package/docs/components/table.md +232 -0
- package/docs/components/tag-picker.md +39 -0
- package/docs/components/timebox.md +16 -0
- package/docs/components/toggle.md +21 -0
- package/docs/components/tokens.md +82 -0
- package/docs/components/toolbar.md +26 -0
- package/docs/components/tooltip.md +16 -0
- package/docs/components/tree.md +48 -0
- package/docs/components/truncate.md +21 -0
- package/docs/components/value-list.md +14 -0
- package/docs/components/view-settings.md +56 -0
- package/docs/components/workspace-switcher.md +42 -0
- package/docs/components/zeyos.md +196 -0
- package/docs/llms-small.txt +299 -0
- package/docs/llms.md +725 -109
- package/docs/llms.txt +46 -19
- package/package.json +9 -4
- package/src/components/activity-item/activity-item.js +21 -2
- package/src/components/agent-avatar/agent-avatar.css +195 -0
- package/src/components/agent-avatar/agent-avatar.js +333 -0
- package/src/components/agent-avatar/agent-face.js +292 -0
- package/src/components/agent-thread/ag-ui.js +44 -11
- package/src/components/agent-thread/agent-thread.js +103 -11
- package/src/components/agent-thread/ui-message-stream.js +3 -1
- package/src/components/app-rail/app-rail.css +5 -0
- package/src/components/app-sidebar/app-sidebar.css +3 -0
- package/src/components/app-sidebar/app-sidebar.js +4 -3
- package/src/components/approval-card/approval-card.css +6 -0
- package/src/components/approval-card/approval-card.js +55 -7
- package/src/components/aurora/aurora.css +149 -14
- package/src/components/aurora/aurora.js +49 -6
- package/src/components/button/button.css +24 -11
- package/src/components/calendar/calendar.css +6 -2
- package/src/components/calendar/calendar.js +127 -47
- package/src/components/card-view/card-view.js +5 -6
- package/src/components/chart/chart.css +159 -1
- package/src/components/chart/chart.js +450 -62
- package/src/components/chart/color.js +297 -0
- package/src/components/chart/svg-adapter.js +576 -0
- package/src/components/chart/svg-geometry.js +323 -0
- package/src/components/check-button/check-button.js +3 -18
- package/src/components/checklist/checklist.css +9 -1
- package/src/components/checklist/checklist.js +105 -20
- package/src/components/checklist/field-adapter.js +6 -12
- package/src/components/code-editor/code-editor.css +33 -0
- package/src/components/code-editor/code-editor.js +97 -8
- package/src/components/code-editor/field-adapter.js +3 -0
- package/src/components/composer/composer.css +3 -0
- package/src/components/composer/composer.js +100 -22
- package/src/components/context-menu/context-menu.js +41 -5
- package/src/components/copy/copy-button.js +9 -1
- package/src/components/copy/copy-input.js +5 -0
- package/src/components/data-filter/filter-core.js +0 -1
- package/src/components/date-picker/date-picker.css +8 -0
- package/src/components/date-picker/date-picker.js +47 -8
- package/src/components/date-picker/date-range-picker.js +1 -1
- package/src/components/date-picker/month-picker.js +19 -3
- package/src/components/date-picker/time-picker.js +54 -19
- package/src/components/datebox/date-range-box.js +7 -3
- package/src/components/datebox/datebox.js +32 -6
- package/src/components/dialog/dialog.css +6 -0
- package/src/components/dialog/dialog.js +24 -33
- package/src/components/dropdown/dropdown.js +1 -18
- package/src/components/empty-state/empty-state.js +21 -2
- package/src/components/field/field.js +19 -3
- package/src/components/fieldset/fieldset.js +3 -1
- package/src/components/filter/filter.js +9 -0
- package/src/components/form/form.js +19 -2
- package/src/components/kanban-view/kanban-card.js +15 -2
- package/src/components/kanban-view/kanban-view.css +21 -0
- package/src/components/kanban-view/kanban-view.js +29 -16
- package/src/components/launcher/launcher.css +14 -0
- package/src/components/launcher/launcher.js +54 -9
- package/src/components/master-panel/master-panel.js +24 -22
- package/src/components/menu-button/menu-button.js +26 -4
- package/src/components/message/message.css +228 -29
- package/src/components/message/message.js +664 -30
- package/src/components/modal/modal.js +129 -30
- package/src/components/modal/native-dialog.js +91 -0
- package/src/components/module-bar/module-bar.css +3 -0
- package/src/components/module-bar/module-bar.js +17 -4
- package/src/components/multi-value-editor/multi-value-editor.css +7 -2
- package/src/components/multi-value-editor/multi-value-editor.js +3 -2
- package/src/components/navigation-bar/navigation-bar.js +13 -1
- package/src/components/number-field/field-adapter.js +3 -0
- package/src/components/number-field/number-field.js +70 -16
- package/src/components/pagination/pagination.css +26 -2
- package/src/components/pagination/pagination.js +551 -65
- package/src/components/prose/prose.js +7 -1
- package/src/components/rating/field-adapter.js +3 -0
- package/src/components/run-status/run-status.js +43 -3
- package/src/components/run-trace/run-trace.js +15 -7
- package/src/components/search/search.js +3 -18
- package/src/components/select/field-adapter.js +8 -1
- package/src/components/select/select.js +68 -13
- package/src/components/sheet/sheet.js +39 -13
- package/src/components/slider/field-adapter.js +3 -0
- package/src/components/slider/slider.js +4 -6
- package/src/components/stat-tile/stat-tile.js +24 -9
- package/src/components/stepper/stepper.css +15 -0
- package/src/components/stepper/stepper.js +34 -2
- package/src/components/surface/catalog.js +185 -28
- package/src/components/surface/surface.js +10 -5
- package/src/components/tabbox/tabbox.js +13 -1
- package/src/components/table/table.css +160 -2
- package/src/components/table/table.js +479 -52
- package/src/components/table/window.js +46 -4
- package/src/components/table-view/table-view.js +1 -10
- package/src/components/tag-picker/field-adapter.js +3 -0
- package/src/components/tag-picker/tag-picker.js +2 -0
- package/src/components/timebox/field-adapter.js +3 -0
- package/src/components/toggle/toggle.js +51 -27
- package/src/components/tooltip/tooltip.js +21 -14
- package/src/components/tree/tree.js +87 -14
- package/src/components/truncate/truncate.js +21 -5
- package/src/components/value-list/value-list.js +37 -9
- package/src/components/view-settings/view-settings.js +1 -5
- package/src/core/component.js +34 -2
- package/src/core/date.js +5 -4
- package/src/core/dom.js +45 -2
- package/src/core/drag-axis.js +24 -7
- package/src/core/export.js +4 -4
- package/src/core/fontawesome.js +34 -3
- package/src/core/format.js +3 -1
- package/src/core/http.js +23 -11
- package/src/core/icons.js +60 -8
- package/src/core/keyboard.js +83 -9
- package/src/core/messages.js +3 -0
- package/src/core/position.js +4 -3
- package/src/core/storage.js +80 -31
- package/src/core/util.js +16 -5
- package/src/elements/define.js +82 -47
- package/src/elements/kit.js +46 -35
- package/src/index.js +8 -4
- package/src/internal/agent-model.js +152 -0
- package/src/internal/app-rail.js +53 -2
- package/src/internal/collections.js +25 -0
- package/src/internal/menu-items.js +59 -0
- package/src/internal/overlay-content.js +35 -0
- package/src/internal/presence-loop.js +61 -14
- package/src/locales/de.js +3 -0
- package/src/zeyos/calendar.js +81 -19
- package/src/zeyos/connect.js +5 -1
- package/src/zeyos/form.js +29 -10
- package/src/zeyos/select.js +36 -12
- package/src/zeyos/table.js +43 -11
- package/src/zeyos/view.js +2 -1
- package/styles/tokens/semantic.css +7 -1
- package/styles/zx.css +1 -0
|
@@ -5,6 +5,39 @@ const ASSUMED_ROW_HEIGHT = 36;
|
|
|
5
5
|
/** Scroll-region height assumed until one has been measured. */
|
|
6
6
|
const ASSUMED_VIEWPORT = 600;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Runs a callback before the next paint, or shortly after where there are no animation frames
|
|
10
|
+
* (jsdom without `pretendToBeVisual`, a server-side DOM).
|
|
11
|
+
* @param {() => void} callback Work to run.
|
|
12
|
+
* @returns {number} Handle for `cancelFrame()`.
|
|
13
|
+
*/
|
|
14
|
+
export function nextFrame(callback) {
|
|
15
|
+
return typeof requestAnimationFrame === 'function'
|
|
16
|
+
? requestAnimationFrame(callback) : /** @type {any} */ (setTimeout(callback, 16));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @param {number} handle What `nextFrame()` returned. @returns {void} */
|
|
20
|
+
export function cancelFrame(handle) {
|
|
21
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(handle);
|
|
22
|
+
else clearTimeout(handle);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* How many rows a PageUp or PageDown moves: the rows that fit in the visible height, less one so
|
|
27
|
+
* the row focus leaves stays in view as context. Falls back when either height is unknown. Shared
|
|
28
|
+
* by the components that page through rows with the keyboard.
|
|
29
|
+
* @param {number} viewport Visible height of the scroll region, below any sticky header.
|
|
30
|
+
* @param {number} rowHeight Height of one row.
|
|
31
|
+
* @param {number} [fallback=10] Rows to move when the heights are unusable.
|
|
32
|
+
* @returns {number} At least 1.
|
|
33
|
+
*/
|
|
34
|
+
export function pageStepRows(viewport, rowHeight, fallback = 10) {
|
|
35
|
+
const visible = Number(viewport);
|
|
36
|
+
const height = Number(rowHeight);
|
|
37
|
+
if (!(visible > 0) || !(height > 0)) return Math.max(1, Math.trunc(fallback) || 10);
|
|
38
|
+
return Math.max(1, Math.floor(visible / height) - 1);
|
|
39
|
+
}
|
|
40
|
+
|
|
8
41
|
/**
|
|
9
42
|
* Which rows to draw for a scroll position: those in view, plus `overscan` viewports' worth above
|
|
10
43
|
* and below. Positions are zero-based and `end` is exclusive. The scroll position is clamped to
|
|
@@ -99,7 +132,7 @@ export function tableWindowScroll({ index, rowHeight, scrollTop, viewport }) {
|
|
|
99
132
|
* Keeps a table body down to the rows around the scroll position. Spacer rows stand in for the rest,
|
|
100
133
|
* sized from one measured row, so the scroll height is the height of every row. Rows that stay in
|
|
101
134
|
* the window are never touched: moving one would blur it. Holds no listeners of its own except the
|
|
102
|
-
* `ResizeObserver` released by `stop()
|
|
135
|
+
* `ResizeObserver` released by `stop()`, and does without one where the environment has none.
|
|
103
136
|
*/
|
|
104
137
|
export class RowWindow {
|
|
105
138
|
/** @param {RowWindowHost} host Table side of the arrangement. */
|
|
@@ -136,10 +169,19 @@ export class RowWindow {
|
|
|
136
169
|
* through the observer too, so it happens once the table is laid out and styled, however late it
|
|
137
170
|
* is attached. It waits for the next frame because a measurement may resize the scroll region
|
|
138
171
|
* itself, which an observer callback must not do.
|
|
172
|
+
*
|
|
173
|
+
* Where there is no `ResizeObserver` (jsdom) the window still works: it measures once on the next
|
|
174
|
+
* frame and again whenever the host calls `schedule()` — `Table` does on a window resize — and
|
|
175
|
+
* until a measurement succeeds it draws for the assumed row height and viewport, which is what a
|
|
176
|
+
* DOM without layout gets for good.
|
|
139
177
|
* @returns {void}
|
|
140
178
|
*/
|
|
141
179
|
start() {
|
|
142
180
|
this.live = true;
|
|
181
|
+
if (typeof ResizeObserver !== 'function') {
|
|
182
|
+
this.schedule();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
143
185
|
this.observer = new ResizeObserver(() => this.schedule());
|
|
144
186
|
this.observer.observe(this.host.scroller);
|
|
145
187
|
this.observer.observe(this.probe);
|
|
@@ -147,14 +189,14 @@ export class RowWindow {
|
|
|
147
189
|
|
|
148
190
|
/** Measures on the next frame, however many times this is asked before it. @returns {void} */
|
|
149
191
|
schedule() {
|
|
150
|
-
|
|
151
|
-
this.frame =
|
|
192
|
+
cancelFrame(this.frame);
|
|
193
|
+
this.frame = nextFrame(() => this.measure());
|
|
152
194
|
}
|
|
153
195
|
|
|
154
196
|
/** Stops measuring. @returns {void} */
|
|
155
197
|
stop() {
|
|
156
198
|
this.live = false;
|
|
157
|
-
|
|
199
|
+
cancelFrame(this.frame);
|
|
158
200
|
this.observer?.disconnect();
|
|
159
201
|
this.observer = null;
|
|
160
202
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
|
|
3
|
+
import { sameArray, sameSet } from '../../internal/collections.js';
|
|
3
4
|
import { formatTableCell, Table } from '../table/table.js';
|
|
4
5
|
import { normalizeViewFieldControls, RecordView, readViewField } from '../view/record-view.js';
|
|
5
6
|
|
|
@@ -350,13 +351,3 @@ function sameSort(left, right) {
|
|
|
350
351
|
return left === null && right === null
|
|
351
352
|
|| Boolean(left && right && left.id === right.id && left.dir === right.dir);
|
|
352
353
|
}
|
|
353
|
-
|
|
354
|
-
/** @param {Set<unknown>} left @param {Set<unknown>} right @returns {boolean} */
|
|
355
|
-
function sameSet(left, right) {
|
|
356
|
-
return left.size === right.size && [...left].every((value) => right.has(value));
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/** @param {unknown[]} left @param {unknown[]} right @returns {boolean} */
|
|
360
|
-
function sameArray(left, right) {
|
|
361
|
-
return left.length === right.length && left.every((value, index) => Object.is(value, right[index]));
|
|
362
|
-
}
|
|
@@ -19,6 +19,9 @@ export function registerTagPickerFieldAdapter() {
|
|
|
19
19
|
});
|
|
20
20
|
return {
|
|
21
21
|
el: picker.el,
|
|
22
|
+
// The combobox input is what the label names (in place of its generic "Add a value") and
|
|
23
|
+
// what the field's description and validity belong to.
|
|
24
|
+
labelTarget: picker.refs.input,
|
|
22
25
|
get: () => picker.getValues(),
|
|
23
26
|
set: (value) => {
|
|
24
27
|
setting = true;
|
|
@@ -539,6 +539,8 @@ export class TagPicker extends Component {
|
|
|
539
539
|
/** @param {KeyboardEvent} event @returns {void} */
|
|
540
540
|
_onKeydown(event) {
|
|
541
541
|
if (this._disabled || this._readonly) return;
|
|
542
|
+
// Keys that confirm or steer an IME composition (Enter, arrows) belong to the IME.
|
|
543
|
+
if (event.isComposing || event.keyCode === 229) return;
|
|
542
544
|
const input = /** @type {HTMLInputElement} */ (this.refs.input);
|
|
543
545
|
|
|
544
546
|
switch (event.key) {
|
|
@@ -15,6 +15,9 @@ export function registerTimeboxFieldAdapter() {
|
|
|
15
15
|
timebox.on('change', (event) => field.emit('change', { value: event.detail.value }));
|
|
16
16
|
return {
|
|
17
17
|
el: timebox.el,
|
|
18
|
+
// The segment group is what the label names and what the field's description and validity
|
|
19
|
+
// belong to; each segment keeps its own name (Hours, Minutes) inside it.
|
|
20
|
+
labelTarget: timebox.el.querySelector('.zx-timebox__content') ?? undefined,
|
|
18
21
|
get: () => timebox.get(),
|
|
19
22
|
set: (value) => timebox.set(Number(value) || 0, { silent: true }),
|
|
20
23
|
focus: () => timebox.el.querySelector('input:not([disabled]), button:not([disabled])')?.focus(),
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Component } from '../../core/component.js';
|
|
2
|
-
import { h } from '../../core/dom.js';
|
|
2
|
+
import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {Object} ToggleOptions
|
|
6
6
|
* @property {boolean} [checked=false] Initial switch state.
|
|
7
7
|
* @property {*} [value=true] Value returned while on.
|
|
8
|
-
* @property {string|null} [label=null]
|
|
8
|
+
* @property {string|null} [label=null] The switch's name, drawn beside the track and read as its
|
|
9
|
+
* accessible name. Null renders no text: the switch then needs a name from somewhere else — a
|
|
10
|
+
* Field or `<label for>` around it, or `aria-labelledby` on the element.
|
|
11
|
+
* @property {boolean} [hideLabel=false] Whether the label is kept for assistive technology only:
|
|
12
|
+
* no visible text, and the label becomes the switch's `aria-label`. For a switch whose meaning
|
|
13
|
+
* the surrounding layout already shows — a table cell under a column header, a settings row.
|
|
9
14
|
* @property {boolean} [disabled=false] Initial disabled state.
|
|
10
15
|
* @property {(event: CustomEvent<{checked: boolean, value: *}>) => void} [onchange] Change callback.
|
|
11
16
|
*/
|
|
@@ -23,6 +28,7 @@ export class Toggle extends Component {
|
|
|
23
28
|
checked: false,
|
|
24
29
|
value: true,
|
|
25
30
|
label: null,
|
|
31
|
+
hideLabel: false,
|
|
26
32
|
disabled: false
|
|
27
33
|
};
|
|
28
34
|
|
|
@@ -34,19 +40,18 @@ export class Toggle extends Component {
|
|
|
34
40
|
if (root.localName !== 'button') throw new TypeError('Toggle target must be a button element');
|
|
35
41
|
|
|
36
42
|
this._createdRoot = created;
|
|
37
|
-
this._original = created ? null :
|
|
43
|
+
this._original = created ? null : snapshotTarget(root);
|
|
38
44
|
this._checked = Boolean(this.options.checked);
|
|
39
45
|
this._disabled = Boolean(this.options.disabled);
|
|
40
46
|
root.type = 'button';
|
|
41
47
|
root.setAttribute('role', 'switch');
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
root.replaceChildren(...children);
|
|
48
|
+
/** The `aria-label` the target arrived with, put back whenever the switch stops writing its own. */
|
|
49
|
+
this._ariaLabel = root.getAttribute('aria-label');
|
|
50
|
+
/** @type {HTMLElement|null} The visible label, when there is one. */
|
|
51
|
+
this._labelEl = null;
|
|
52
|
+
root.replaceChildren(h('span', { class: 'zx-toggle__track', ariaHidden: 'true' },
|
|
53
|
+
h('span', { class: 'zx-toggle__thumb' })));
|
|
54
|
+
this._syncLabel(this.options.label ?? null);
|
|
50
55
|
this._sync();
|
|
51
56
|
this.listen(root, 'click', () => this.toggle());
|
|
52
57
|
return root;
|
|
@@ -93,6 +98,16 @@ export class Toggle extends Component {
|
|
|
93
98
|
return this._checked ? this.options.value : false;
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Replaces the switch's name: the visible label, or the `aria-label` under `hideLabel`.
|
|
103
|
+
* @param {string|null} label New name; null removes it.
|
|
104
|
+
* @returns {this}
|
|
105
|
+
*/
|
|
106
|
+
setLabel(label) {
|
|
107
|
+
this._syncLabel(label ?? null);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
|
|
96
111
|
/**
|
|
97
112
|
* Enables user interaction.
|
|
98
113
|
* @returns {this}
|
|
@@ -118,7 +133,31 @@ export class Toggle extends Component {
|
|
|
118
133
|
if (this._cleaned) return;
|
|
119
134
|
this._cleaned = true;
|
|
120
135
|
super.destroy();
|
|
121
|
-
if (!this._createdRoot && this._original)
|
|
136
|
+
if (!this._createdRoot && this._original) restoreTarget(this.el, this._original);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Writes the name where the options put it: a text node beside the track, or `aria-label` when
|
|
141
|
+
* the label is hidden. With no name of its own the switch leaves `aria-label` as it found it.
|
|
142
|
+
* @param {string|null} label Name, or null for none.
|
|
143
|
+
* @returns {void}
|
|
144
|
+
*/
|
|
145
|
+
_syncLabel(label) {
|
|
146
|
+
const text = label === null ? '' : String(label);
|
|
147
|
+
const hidden = Boolean(this.options.hideLabel);
|
|
148
|
+
if (text && !hidden) {
|
|
149
|
+
if (!this._labelEl) {
|
|
150
|
+
this._labelEl = h('span', { class: 'zx-toggle__label' });
|
|
151
|
+
this.el.append(this._labelEl);
|
|
152
|
+
}
|
|
153
|
+
this._labelEl.textContent = text;
|
|
154
|
+
} else {
|
|
155
|
+
this._labelEl?.remove();
|
|
156
|
+
this._labelEl = null;
|
|
157
|
+
}
|
|
158
|
+
if (text && hidden) this.el.setAttribute('aria-label', text);
|
|
159
|
+
else if (this._ariaLabel === null) this.el.removeAttribute('aria-label');
|
|
160
|
+
else this.el.setAttribute('aria-label', this._ariaLabel);
|
|
122
161
|
}
|
|
123
162
|
|
|
124
163
|
/** @returns {void} */
|
|
@@ -133,18 +172,3 @@ export class Toggle extends Component {
|
|
|
133
172
|
* @event Toggle#change
|
|
134
173
|
* @type {CustomEvent<{checked: boolean, value: *}>}
|
|
135
174
|
*/
|
|
136
|
-
|
|
137
|
-
/** @param {Element} element @returns {{attributes: [string, string][], children: Node[]}} */
|
|
138
|
-
function snapshot(element) {
|
|
139
|
-
return {
|
|
140
|
-
attributes: Array.from(element.attributes, (attribute) => [attribute.name, attribute.value]),
|
|
141
|
-
children: Array.from(element.childNodes)
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** @param {Element} element @param {{attributes: [string, string][], children: Node[]}} state */
|
|
146
|
-
function restore(element, state) {
|
|
147
|
-
for (const attribute of Array.from(element.attributes)) element.removeAttribute(attribute.name);
|
|
148
|
-
for (const [name, value] of state.attributes) element.setAttribute(name, value);
|
|
149
|
-
element.replaceChildren(...state.children);
|
|
150
|
-
}
|
|
@@ -43,8 +43,9 @@ const TRIGGERS = new Set(['hover', 'focus', 'both', 'manual']);
|
|
|
43
43
|
* The bubble is a manual popover in the top layer, positioned by `position()` from the kernel, so
|
|
44
44
|
* it escapes clipping and stacking contexts and flips near a viewport edge. It never takes focus
|
|
45
45
|
* but remains visible while the pointer is over either the anchor or the bubble. While open, the
|
|
46
|
-
* anchor
|
|
47
|
-
*
|
|
46
|
+
* anchor's `aria-describedby` also names the bubble; closing takes out that one id and leaves the
|
|
47
|
+
* rest of the list as it is then, ids the application added meanwhile included — and removes the
|
|
48
|
+
* attribute only when the bubble's id was all it held.
|
|
48
49
|
*
|
|
49
50
|
* A hover opens it after `delay`; keyboard focus opens it at once, because a keyboard user has no
|
|
50
51
|
* way to "hover a little longer". Touch never opens it: a bubble that cannot be dismissed by
|
|
@@ -75,8 +76,6 @@ export class Tooltip extends Component {
|
|
|
75
76
|
#content;
|
|
76
77
|
/** @type {ReturnType<typeof position>|null} */
|
|
77
78
|
#position = null;
|
|
78
|
-
/** The anchor's `aria-describedby` before this tooltip touched it; `null` when it had none. */
|
|
79
|
-
#describedBy = null;
|
|
80
79
|
/** Handle of the pending open timer; `0` when none is scheduled. */
|
|
81
80
|
#openTimer = 0;
|
|
82
81
|
/** Handle of the pending close timer; `0` when none is scheduled. */
|
|
@@ -108,7 +107,6 @@ export class Tooltip extends Component {
|
|
|
108
107
|
connectedOverlayHost(resolved, { dialog: false })?.append(this.el);
|
|
109
108
|
this.#content = this.options.content;
|
|
110
109
|
this.#disabled = Boolean(this.options.disabled);
|
|
111
|
-
this.#describedBy = resolved.getAttribute('aria-describedby');
|
|
112
110
|
this.el.style.setProperty('--zx-tooltip-max-inline-size', cssLength(this.options.maxWidth));
|
|
113
111
|
|
|
114
112
|
const trigger = TRIGGERS.has(this.options.trigger) ? this.options.trigger : 'both';
|
|
@@ -207,7 +205,8 @@ export class Tooltip extends Component {
|
|
|
207
205
|
this.el.style.setProperty('position-try-fallbacks', 'flip-inline, top span-all, bottom span-all');
|
|
208
206
|
}
|
|
209
207
|
this.el.dataset.state = 'open';
|
|
210
|
-
|
|
208
|
+
// Read now, not at construction: a field error described since then stays described.
|
|
209
|
+
this.#anchor.setAttribute('aria-describedby', appendToken(this.#anchor.getAttribute('aria-describedby'), this.el.id));
|
|
211
210
|
/*
|
|
212
211
|
* On the stack even when manual, so the order is shared and a closing parent takes the bubble
|
|
213
212
|
* with it; only a dismissible tooltip takes Escape (WCAG 1.4.13), presses, and focus. Escape
|
|
@@ -233,7 +232,7 @@ export class Tooltip extends Component {
|
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
/**
|
|
236
|
-
* Closes the tooltip and
|
|
235
|
+
* Closes the tooltip and takes its id out of the anchor's `aria-describedby`.
|
|
237
236
|
* @returns {this}
|
|
238
237
|
* @fires Tooltip#close
|
|
239
238
|
*/
|
|
@@ -245,7 +244,7 @@ export class Tooltip extends Component {
|
|
|
245
244
|
this.#bubbleHovered = false;
|
|
246
245
|
this.el.dataset.state = 'closed';
|
|
247
246
|
this.el.replaceChildren();
|
|
248
|
-
this.#
|
|
247
|
+
this.#removeDescribedBy();
|
|
249
248
|
const overlay = this.#overlay;
|
|
250
249
|
this.#overlay = null;
|
|
251
250
|
overlay?.release();
|
|
@@ -320,14 +319,14 @@ export class Tooltip extends Component {
|
|
|
320
319
|
}
|
|
321
320
|
|
|
322
321
|
/**
|
|
323
|
-
* Closes the tooltip, removes the bubble, and
|
|
322
|
+
* Closes the tooltip, removes the bubble, and takes its id out of the anchor's ARIA.
|
|
324
323
|
* @returns {void}
|
|
325
324
|
*/
|
|
326
325
|
destroy() {
|
|
327
326
|
if (this.#destroyed) return;
|
|
328
327
|
this.#destroyed = true;
|
|
329
328
|
this.hide();
|
|
330
|
-
this.#
|
|
329
|
+
this.#removeDescribedBy();
|
|
331
330
|
super.destroy();
|
|
332
331
|
}
|
|
333
332
|
|
|
@@ -370,10 +369,18 @@ export class Tooltip extends Component {
|
|
|
370
369
|
this.#closeTimer = 0;
|
|
371
370
|
}
|
|
372
371
|
|
|
373
|
-
/**
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Takes the bubble's id out of the anchor's `aria-describedby`, leaving every other id in place.
|
|
374
|
+
* @returns {void}
|
|
375
|
+
*/
|
|
376
|
+
#removeDescribedBy() {
|
|
377
|
+
const current = this.#anchor.getAttribute('aria-describedby');
|
|
378
|
+
if (current === null) return;
|
|
379
|
+
const tokens = current.split(/\s+/).filter(Boolean);
|
|
380
|
+
if (!tokens.includes(this.el.id)) return;
|
|
381
|
+
const rest = tokens.filter((token) => token !== this.el.id);
|
|
382
|
+
if (rest.length) this.#anchor.setAttribute('aria-describedby', rest.join(' '));
|
|
383
|
+
else this.#anchor.removeAttribute('aria-describedby');
|
|
377
384
|
}
|
|
378
385
|
}
|
|
379
386
|
|
|
@@ -16,7 +16,9 @@ import {
|
|
|
16
16
|
* @property {string|((node: TreeNode) => unknown)} [valueKey='ID'] Node ID property or reader.
|
|
17
17
|
* @property {string|((node: TreeNode) => string)} [labelKey='name'] Node label property or reader.
|
|
18
18
|
* @property {string} [childrenKey='children'] Property holding child nodes.
|
|
19
|
-
* @property {unknown[]} [expanded=[]] Initially expanded node IDs.
|
|
19
|
+
* @property {unknown[]} [expanded=[]] Initially expanded node IDs. A lazy branch among them
|
|
20
|
+
* (`hasChildren` with no children loaded yet) shows collapsed until it is expanded on its own —
|
|
21
|
+
* clicked, →, or `expand()` — which loads it.
|
|
20
22
|
* @property {false|'single'|'multi'} [selection='single'] Selection mode.
|
|
21
23
|
* @property {unknown[]} [selected=[]] Initially selected node IDs.
|
|
22
24
|
* @property {boolean} [checkboxes=false] Whether to render tri-state checkboxes.
|
|
@@ -97,6 +99,8 @@ export class TreeView extends Component {
|
|
|
97
99
|
this._checked = new Set();
|
|
98
100
|
/** @type {Map<unknown, Promise<boolean>>} In-flight lazy loads, keyed by node ID. */
|
|
99
101
|
this._loading = new Map();
|
|
102
|
+
/** @type {Set<unknown>} Lazy branches whose children are not loaded yet, as of the last render. */
|
|
103
|
+
this._unloaded = new Set();
|
|
100
104
|
this._loadGeneration = 0;
|
|
101
105
|
this._destroyed = false;
|
|
102
106
|
this._expanding = new Map();
|
|
@@ -217,16 +221,22 @@ export class TreeView extends Component {
|
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
/**
|
|
220
|
-
* Filters the tree by a label substring, keeping the ancestors of every match.
|
|
224
|
+
* Filters the tree by a label substring, keeping the ancestors of every match. Only loaded
|
|
225
|
+
* children are searched, and every surviving branch opens except a lazy one not loaded yet.
|
|
221
226
|
* @param {string} query Search text; an empty string restores the full tree.
|
|
222
227
|
* @returns {this}
|
|
223
228
|
*/
|
|
224
229
|
setFilter(query) {
|
|
225
230
|
this._filter = String(query ?? '');
|
|
226
231
|
if (this._filter !== '') {
|
|
227
|
-
// A filtered tree is only useful expanded, so every surviving branch opens
|
|
232
|
+
// A filtered tree is only useful expanded, so every surviving branch opens; one that would
|
|
233
|
+
// have to be fetched first stays closed rather than claim children it does not show.
|
|
234
|
+
const unloaded = this._unloadedIds();
|
|
228
235
|
for (const node of this._visibleItems()) {
|
|
229
|
-
walk([node], this._readers, (child) =>
|
|
236
|
+
walk([node], this._readers, (child) => {
|
|
237
|
+
const id = this._readers.value(child);
|
|
238
|
+
if (!unloaded.has(id)) this._expanded.add(id);
|
|
239
|
+
});
|
|
230
240
|
}
|
|
231
241
|
}
|
|
232
242
|
this._renderRows();
|
|
@@ -278,22 +288,24 @@ export class TreeView extends Component {
|
|
|
278
288
|
}
|
|
279
289
|
|
|
280
290
|
/**
|
|
281
|
-
* Expands or collapses one branch.
|
|
291
|
+
* Expands or collapses one branch. A lazy branch not loaded yet counts as collapsed, so this
|
|
292
|
+
* loads and expands it.
|
|
282
293
|
* @param {unknown} id Node ID.
|
|
283
294
|
* @returns {Promise<this>}
|
|
284
295
|
*/
|
|
285
296
|
async toggle(id) {
|
|
286
|
-
if (this.
|
|
297
|
+
if (this._isOpen(id, this.getNode(id))) return this.collapse(id);
|
|
287
298
|
return this.expand(id);
|
|
288
299
|
}
|
|
289
300
|
|
|
290
301
|
/**
|
|
291
|
-
* Expands every already-loaded branch.
|
|
302
|
+
* Expands every already-loaded branch. A lazy branch whose children have not been loaded stays
|
|
303
|
+
* collapsed; `expand(id)` loads it.
|
|
292
304
|
* @returns {this}
|
|
293
305
|
*/
|
|
294
306
|
expandAll() {
|
|
295
307
|
walk(this._items, this._readers, (node) => {
|
|
296
|
-
if (isBranch(node, this._readers)) this._expanded.add(this._readers.value(node));
|
|
308
|
+
if (isBranch(node, this._readers) && !this._needsLoad(node)) this._expanded.add(this._readers.value(node));
|
|
297
309
|
});
|
|
298
310
|
this._renderRows();
|
|
299
311
|
return this;
|
|
@@ -455,6 +467,7 @@ export class TreeView extends Component {
|
|
|
455
467
|
_renderRows() {
|
|
456
468
|
const items = this._visibleItems();
|
|
457
469
|
this._rows = flattenVisible(items, this._readers, this._expanded);
|
|
470
|
+
this._unloaded = this._unloadedIds();
|
|
458
471
|
for (const strip of this._strips.splice(0)) strip?.destroy();
|
|
459
472
|
|
|
460
473
|
if (this._rows.length === 0) {
|
|
@@ -473,7 +486,7 @@ export class TreeView extends Component {
|
|
|
473
486
|
*/
|
|
474
487
|
_renderRow(row, index) {
|
|
475
488
|
const branch = isBranch(row.node, this._readers);
|
|
476
|
-
const expanded = branch && this.
|
|
489
|
+
const expanded = branch && this._shownOpen(row.id);
|
|
477
490
|
const element = h('div', {
|
|
478
491
|
class: 'zx-tree__row',
|
|
479
492
|
role: 'treeitem',
|
|
@@ -546,7 +559,7 @@ export class TreeView extends Component {
|
|
|
546
559
|
const row = this._rows[index];
|
|
547
560
|
if (!row) return;
|
|
548
561
|
const branch = isBranch(row.node, this._readers);
|
|
549
|
-
const expanded = branch && this.
|
|
562
|
+
const expanded = branch && this._shownOpen(row.id);
|
|
550
563
|
if (branch) element.setAttribute('aria-expanded', String(expanded));
|
|
551
564
|
else element.removeAttribute('aria-expanded');
|
|
552
565
|
if (this.options.selection !== false) {
|
|
@@ -643,7 +656,7 @@ export class TreeView extends Component {
|
|
|
643
656
|
if (index < 0 || this._rows.length === 0) return;
|
|
644
657
|
const row = this._rows[index];
|
|
645
658
|
const branch = isBranch(row.node, this._readers);
|
|
646
|
-
const expanded = branch && this.
|
|
659
|
+
const expanded = branch && this._shownOpen(row.id);
|
|
647
660
|
|
|
648
661
|
switch (event.key) {
|
|
649
662
|
case 'ArrowDown':
|
|
@@ -663,7 +676,8 @@ export class TreeView extends Component {
|
|
|
663
676
|
this._focusNodeId(row.id);
|
|
664
677
|
}
|
|
665
678
|
});
|
|
666
|
-
|
|
679
|
+
// Into the first child — never onto the next sibling of a branch that shows no children.
|
|
680
|
+
else if (expanded && this._rows[index + 1]?.parent === row.node) this._focusRow(index + 1);
|
|
667
681
|
return;
|
|
668
682
|
}
|
|
669
683
|
case 'ArrowLeft': {
|
|
@@ -713,22 +727,81 @@ export class TreeView extends Component {
|
|
|
713
727
|
}
|
|
714
728
|
|
|
715
729
|
/**
|
|
716
|
-
* Expands every sibling branch of a row, the APG `*` shortcut.
|
|
730
|
+
* Expands every sibling branch of a row, the APG `*` shortcut. A lazy sibling is loaded first,
|
|
731
|
+
* exactly as → on it would; each one opens as its children arrive, and focus stays put.
|
|
717
732
|
* @param {{parent: TreeNode|null}} row Focused row.
|
|
718
733
|
* @returns {void}
|
|
719
734
|
*/
|
|
720
735
|
_expandSiblings(row) {
|
|
721
736
|
const siblings = row.parent ? this._readers.children(row.parent) ?? [] : this._visibleItems();
|
|
722
737
|
const focused = this._focusId;
|
|
738
|
+
const lazy = [];
|
|
723
739
|
for (const node of siblings) {
|
|
724
|
-
if (isBranch(node, this._readers))
|
|
740
|
+
if (!isBranch(node, this._readers)) continue;
|
|
741
|
+
const id = this._readers.value(node);
|
|
742
|
+
if (this._unloaded.has(id)) lazy.push(id);
|
|
743
|
+
else this._expanded.add(id);
|
|
725
744
|
}
|
|
726
745
|
this._renderRows();
|
|
727
746
|
this._focusNodeId(focused);
|
|
747
|
+
const generation = this._loadGeneration;
|
|
748
|
+
for (const id of lazy) {
|
|
749
|
+
void this.expand(id).then(() => {
|
|
750
|
+
if (!this._destroyed && generation === this._loadGeneration && Object.is(this._focusId, focused)) {
|
|
751
|
+
this._focusNodeId(focused);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
}
|
|
728
755
|
}
|
|
729
756
|
|
|
730
757
|
/* ------------------------------------------------------------------ internals -- */
|
|
731
758
|
|
|
759
|
+
/**
|
|
760
|
+
* Whether expanding a branch has to call the loader first: a loader is configured and the
|
|
761
|
+
* branch has no children yet. The same test `expand()` applies.
|
|
762
|
+
* @param {TreeNode|null} node Node in the working tree.
|
|
763
|
+
* @returns {boolean}
|
|
764
|
+
*/
|
|
765
|
+
_needsLoad(node) {
|
|
766
|
+
if (!this.options.load || !node) return false;
|
|
767
|
+
const children = this._readers.children(node);
|
|
768
|
+
return !children || children.length === 0;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Whether a branch is open now: expanded, and not a lazy branch still waiting for its children —
|
|
773
|
+
* an ID can sit in the expanded set before its children were ever fetched.
|
|
774
|
+
* @param {unknown} id Node ID.
|
|
775
|
+
* @param {TreeNode|null} node The node in the working tree.
|
|
776
|
+
* @returns {boolean}
|
|
777
|
+
*/
|
|
778
|
+
_isOpen(id, node) {
|
|
779
|
+
return this._expanded.has(id) && !(node && isBranch(node, this._readers) && this._needsLoad(node));
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* The lazy branches whose children have not been loaded, read off the working tree — a filtered
|
|
784
|
+
* copy's pruned children say nothing about whether a branch was ever loaded.
|
|
785
|
+
* @returns {Set<unknown>} Their IDs; empty without a loader.
|
|
786
|
+
*/
|
|
787
|
+
_unloadedIds() {
|
|
788
|
+
const ids = new Set();
|
|
789
|
+
if (!this.options.load) return ids;
|
|
790
|
+
walk(this._items, this._readers, (node) => {
|
|
791
|
+
if (isBranch(node, this._readers) && this._needsLoad(node)) ids.add(this._readers.value(node));
|
|
792
|
+
});
|
|
793
|
+
return ids;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* {@link _isOpen} for a rendered row, from what the last render found unloaded.
|
|
798
|
+
* @param {unknown} id Node ID.
|
|
799
|
+
* @returns {boolean}
|
|
800
|
+
*/
|
|
801
|
+
_shownOpen(id) {
|
|
802
|
+
return this._expanded.has(id) && !this._unloaded.has(id);
|
|
803
|
+
}
|
|
804
|
+
|
|
732
805
|
/**
|
|
733
806
|
* Loads a branch's children through the configured loader, once.
|
|
734
807
|
* @param {TreeNode} node Branch node.
|
|
@@ -12,7 +12,8 @@ import { clamp } from '../../core/util.js';
|
|
|
12
12
|
* @typedef {Object} TruncateController
|
|
13
13
|
* @property {() => boolean} update Re-measures and returns whether the text is currently cut off.
|
|
14
14
|
* @property {() => boolean} isTruncated Whether the text was cut off at the last measurement.
|
|
15
|
-
* @property {() => void} destroy Removes the classes, the observer, and any title
|
|
15
|
+
* @property {() => void} destroy Removes the classes, the observer, and any title or line count
|
|
16
|
+
* this set, putting back the `title`, `data-lines`, and `--zx-truncate-lines` the element had.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -33,15 +34,22 @@ export function truncate(target, options = {}) {
|
|
|
33
34
|
|
|
34
35
|
const lines = clamp(Math.trunc(Number(options.lines) || 1), 1, 10);
|
|
35
36
|
const withTitle = options.title !== false;
|
|
37
|
+
const style = /** @type {HTMLElement} */ (element).style;
|
|
36
38
|
const hadClass = element.classList.contains('zx-truncate');
|
|
39
|
+
const hadClassAttribute = element.getAttribute('class') !== null;
|
|
37
40
|
const previousTitle = element.getAttribute('title');
|
|
41
|
+
// What a multi-line clamp overwrites, so `destroy()` hands back settings the element came with.
|
|
42
|
+
const previousLines = element.getAttribute('data-lines');
|
|
43
|
+
const hadStyle = element.getAttribute('style') !== null;
|
|
44
|
+
const previousProperty = style.getPropertyValue('--zx-truncate-lines');
|
|
45
|
+
const previousPriority = style.getPropertyPriority('--zx-truncate-lines');
|
|
38
46
|
let truncated = false;
|
|
39
47
|
let observer = null;
|
|
40
48
|
|
|
41
49
|
element.classList.add('zx-truncate');
|
|
42
50
|
if (lines > 1) {
|
|
43
|
-
element.
|
|
44
|
-
|
|
51
|
+
element.setAttribute('data-lines', String(lines));
|
|
52
|
+
style.setProperty('--zx-truncate-lines', String(lines));
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
const update = () => {
|
|
@@ -67,8 +75,16 @@ export function truncate(target, options = {}) {
|
|
|
67
75
|
observer?.disconnect();
|
|
68
76
|
observer = null;
|
|
69
77
|
if (!hadClass) element.classList.remove('zx-truncate');
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
if (!hadClassAttribute && element.getAttribute('class') === '') element.removeAttribute('class');
|
|
79
|
+
if (lines > 1) {
|
|
80
|
+
if (previousLines === null) element.removeAttribute('data-lines');
|
|
81
|
+
else element.setAttribute('data-lines', previousLines);
|
|
82
|
+
// Through the CSSOM, never the style attribute, which a strict style-src policy blocks.
|
|
83
|
+
if (previousProperty) style.setProperty('--zx-truncate-lines', previousProperty, previousPriority);
|
|
84
|
+
else style.removeProperty('--zx-truncate-lines');
|
|
85
|
+
// Removing the only property leaves `style=""` behind on an element that had no style.
|
|
86
|
+
if (!hadStyle && element.getAttribute('style') === '') element.removeAttribute('style');
|
|
87
|
+
}
|
|
72
88
|
if (!withTitle) return;
|
|
73
89
|
if (previousTitle === null) element.removeAttribute('title');
|
|
74
90
|
else element.setAttribute('title', previousTitle);
|