@zeyos/zx 5.7.1 → 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 +296 -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 +19 -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 +13 -2
- 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 +11 -0
- 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 +7 -0
- 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 +18 -4
- 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/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 +2998 -451
- 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 +948 -48
- package/dist/zx.esm.js +7432 -3408
- package/dist/zx.esm.min.js +26 -26
- package/dist/zx.global.js +7432 -3408
- package/dist/zx.global.min.js +26 -26
- package/dist/zx.layered.css +950 -48
- 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 +3122 -528
- 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 +697 -100
- 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/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.js +46 -17
- package/src/components/checklist/field-adapter.js +4 -1
- 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 +22 -30
- 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 +70 -25
- 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 +2 -1
- 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 +27 -8
- 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/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 +51 -10
- package/src/core/keyboard.js +83 -9
- package/src/core/messages.js +3 -0
- package/src/core/position.js +2 -2
- 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,12 +5,13 @@ import { formatCurrency, formatNumber, formatPercent } from '../../core/format.j
|
|
|
5
5
|
import { ICON_SIZE, icon } from '../../core/icons.js';
|
|
6
6
|
import { printf } from '../../core/i18n.js';
|
|
7
7
|
import { uid } from '../../core/util.js';
|
|
8
|
+
import { sameArray, sameSet } from '../../internal/collections.js';
|
|
8
9
|
import { Datebox } from '../datebox/datebox.js';
|
|
9
10
|
import { NumberField } from '../number-field/number-field.js';
|
|
10
11
|
import { Select } from '../select/select.js';
|
|
11
12
|
import { Toggle } from '../toggle/toggle.js';
|
|
12
13
|
import { sortRows } from './sort.js';
|
|
13
|
-
import { RowWindow } from './window.js';
|
|
14
|
+
import { RowWindow, cancelFrame, nextFrame, pageStepRows } from './window.js';
|
|
14
15
|
|
|
15
16
|
/** @typedef {Record<string, any>} TableRow */
|
|
16
17
|
/** @typedef {'asc'|'desc'} TableSortDirection */
|
|
@@ -28,6 +29,7 @@ import { RowWindow } from './window.js';
|
|
|
28
29
|
* @property {string} [column] Column that receives indentation and the disclosure control; the
|
|
29
30
|
* first column is used when omitted.
|
|
30
31
|
* @property {boolean|unknown[]} [expanded=false] Initially expanded branches: all, none, or ids.
|
|
32
|
+
* Read at construction only; `setExpanded()` replaces the set afterwards.
|
|
31
33
|
*/
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -69,7 +71,27 @@ import { RowWindow } from './window.js';
|
|
|
69
71
|
* @property {boolean} [sortable=false] Whether the header changes the active sort.
|
|
70
72
|
* @property {string} [width='auto'] CSS width, `auto`, or an `fr` proportion. `fr` values are
|
|
71
73
|
* converted into proportional percentages on `<col>` elements and enable `table-layout: fixed`;
|
|
72
|
-
* this preserves a single aligned header/body table without measuring layout in JavaScript.
|
|
74
|
+
* this preserves a single aligned header/body table without measuring layout in JavaScript. The
|
|
75
|
+
* `fr` columns share what the columns with a CSS length leave over, and never less than their
|
|
76
|
+
* `minWidth`: a container too narrow for that scrolls the table inline instead of squeezing them.
|
|
77
|
+
* @property {string|number} [minWidth='5rem'] Narrowest an `fr` column gets, as a CSS length or a
|
|
78
|
+
* number of pixels; `0` lifts the floor. Also honoured on an `auto` column of a table with a fixed
|
|
79
|
+
* layout (one with `fr` columns, or `virtual`), where it has no default. The table takes a minimum
|
|
80
|
+
* width from it, so every `fr` column keeps at least its floor whatever its share. A column with
|
|
81
|
+
* a CSS length `width` ignores it.
|
|
82
|
+
* @property {'start'|'end'} [pin] Keeps the column in view at the inline start or end edge of the
|
|
83
|
+
* scroll region while the table scrolls sideways (`position: sticky`, so it follows the writing
|
|
84
|
+
* direction). A pinned column stays where the column order puts it and sticks once it reaches the
|
|
85
|
+
* edge, so declare a `'start'` column before the columns it should stay in front of and an `'end'`
|
|
86
|
+
* column after them. Several pinned columns stack beside each other in column order, and the row
|
|
87
|
+
* handle and selection checkbox columns are pinned along with the first `'start'` column. Give a
|
|
88
|
+
* pinned column a `width` or keep it short: what is pinned is taken from the room the other
|
|
89
|
+
* columns scroll in. Not applied while the table is stacked (`responsive`).
|
|
90
|
+
* @property {string} [group] Label of a header group. Adjacent visible columns with the same
|
|
91
|
+
* `group` (and the same `pin`) share one header cell in a second header row above the column
|
|
92
|
+
* labels: a `<th scope="col">` spanning them, so assistive technology announces it with every
|
|
93
|
+
* cell beneath. Columns without a `group` leave that row blank above them. The group row takes
|
|
94
|
+
* no part in sorting or keyboard navigation.
|
|
73
95
|
* @property {'start'|'center'|'end'|'left'|'right'} [align='start'] Cell alignment.
|
|
74
96
|
* @property {(row: TableRow, rowIndex: number) => Node|string|number|null|undefined} [render]
|
|
75
97
|
* Cell renderer. Non-Node results are inserted as text.
|
|
@@ -111,7 +133,10 @@ import { RowWindow } from './window.js';
|
|
|
111
133
|
* @property {{id: string, dir: TableSortDirection}|null} [sort=null] Initial sort.
|
|
112
134
|
* @property {'local'|'server'} [sortMode='local'] Whether sorting reorders local rows.
|
|
113
135
|
* @property {TableSelectionMode} [selectable=false] Row selection mode.
|
|
114
|
-
* @property {boolean} [stickyHeader=true] Whether column headers stick
|
|
136
|
+
* @property {boolean} [stickyHeader=true] Whether column headers stick to the top of the table's
|
|
137
|
+
* own scroll region while its rows scroll. That takes a bounded region: set `height` (or use
|
|
138
|
+
* `virtual`, which caps the region at the window height). A table without one grows to the height
|
|
139
|
+
* of its rows, never scrolls itself, and its header leaves with the page.
|
|
115
140
|
* @property {false|number} [growing=false] Number of rows to render at first, with a control that
|
|
116
141
|
* appends the next batch on demand. A result set an ERP query returns happily — tens of thousands
|
|
117
142
|
* of rows — costs more to lay out than anyone will ever scroll through.
|
|
@@ -291,7 +316,9 @@ const FOCUSABLE = 'input, textarea, select, button, [tabindex]:not([tabindex="-1
|
|
|
291
316
|
* does not scroll). Enter activates the row exactly as a click does (`rowclick`), Space toggles the
|
|
292
317
|
* row's selection when `selectable` (and activates otherwise), Shift+Arrow extends a `multi`
|
|
293
318
|
* selection, and Ctrl/Cmd+A selects every rendered row. The focused row survives `setData`, sorting,
|
|
294
|
-
* expansion, and `updateRow`. Column headers keep their sort buttons in the Tab order
|
|
319
|
+
* expansion, and `updateRow`. Column headers keep their sort buttons in the Tab order; the header
|
|
320
|
+
* row of column groups (`TableColumn.group`) holds no controls and takes no focus. A cell focused
|
|
321
|
+
* by keyboard scrolls clear of pinned columns (`TableColumn.pin`). With `virtual`
|
|
295
322
|
* all of this runs over every row, drawn or not: the keys draw the row they move to, and a selection
|
|
296
323
|
* reaches rows that are not in the DOM.
|
|
297
324
|
* @fires Table#rowclick
|
|
@@ -415,6 +442,15 @@ export class Table extends Component {
|
|
|
415
442
|
this._columnControlIds = new Map();
|
|
416
443
|
this._columnStatus = null;
|
|
417
444
|
this._expanded = initialExpanded(this._hierarchy?.expanded);
|
|
445
|
+
// Pinned columns and header groups. The layout is derived from the visible columns each time
|
|
446
|
+
// they change; the offsets are measured off the header, which is the only row always drawn.
|
|
447
|
+
this._pinLayout = tablePinLayout([], 0);
|
|
448
|
+
this._headerRows = 1;
|
|
449
|
+
this._headerRow = null;
|
|
450
|
+
this._groupRow = null;
|
|
451
|
+
this._pinObserver = null;
|
|
452
|
+
this._pinFrame = 0;
|
|
453
|
+
this._pinProps = [];
|
|
418
454
|
|
|
419
455
|
if (this._sort && this.options.sortMode === 'local') this._sortData();
|
|
420
456
|
if (this._hierarchy?.expanded === true) {
|
|
@@ -489,6 +525,14 @@ export class Table extends Component {
|
|
|
489
525
|
this._window.start();
|
|
490
526
|
this.listen(this._scroll, 'scroll', () => this._window.update(), { passive: true });
|
|
491
527
|
}
|
|
528
|
+
// Without a ResizeObserver (jsdom) nothing reports a size change, so the window's resize is the
|
|
529
|
+
// one signal left for the row window and the pinned offsets to measure again.
|
|
530
|
+
if (typeof ResizeObserver !== 'function' && typeof window !== 'undefined') {
|
|
531
|
+
this.listen(window, 'resize', () => {
|
|
532
|
+
this._window?.schedule();
|
|
533
|
+
this._schedulePins();
|
|
534
|
+
});
|
|
535
|
+
}
|
|
492
536
|
this.listen(this._tbody, 'click', (event) => this._handleBodyClick(event));
|
|
493
537
|
this.listen(this._tbody, 'dblclick', (event) => this._handleBodyDoubleClick(event));
|
|
494
538
|
if (this.options.rowReorder) {
|
|
@@ -1009,6 +1053,35 @@ export class Table extends Component {
|
|
|
1009
1053
|
return this;
|
|
1010
1054
|
}
|
|
1011
1055
|
|
|
1056
|
+
/**
|
|
1057
|
+
* Replaces the set of expanded branches in one render — the runtime counterpart of
|
|
1058
|
+
* `hierarchy.expanded`, which is read at construction only, and what to call when restoring a
|
|
1059
|
+
* saved state: a loop over `expandRow()` renders the body once per branch. Ids are compared as
|
|
1060
|
+
* `rowId` returns them (`1` is not `'1'`); ids that are not in the data, or name a row without
|
|
1061
|
+
* children, are dropped. A set equal to the current one renders nothing and fires nothing.
|
|
1062
|
+
* @param {unknown[]|boolean} ids Branch ids to leave expanded; `true` expands every branch and
|
|
1063
|
+
* `false` (or an empty array) collapses them all, as in `hierarchy.expanded`.
|
|
1064
|
+
* @param {{silent?: boolean}} [options={}] Event behavior. When not silent, one `rowtoggle`
|
|
1065
|
+
* event is emitted per branch whose state changed, after the render: the collapsed branches
|
|
1066
|
+
* first, then the expanded ones, each in data order — the same events `expandAll()` and
|
|
1067
|
+
* `collapseAll()` fire.
|
|
1068
|
+
* @returns {this}
|
|
1069
|
+
* @fires Table#rowtoggle
|
|
1070
|
+
*/
|
|
1071
|
+
setExpanded(ids, options = {}) {
|
|
1072
|
+
if (!this._hierarchy) return this;
|
|
1073
|
+
const branchIds = hierarchyBranchIds(this._data, this.options.rowId, this._hierarchy.parentId);
|
|
1074
|
+
const change = resolveExpandedChange(branchIds, this._expanded, ids);
|
|
1075
|
+
if (change.opened.length === 0 && change.closed.length === 0) return this;
|
|
1076
|
+
this._expanded = change.expanded;
|
|
1077
|
+
this._renderBody();
|
|
1078
|
+
if (!options.silent) {
|
|
1079
|
+
for (const id of change.closed) this._emitRowToggle(id, false);
|
|
1080
|
+
for (const id of change.opened) this._emitRowToggle(id, true);
|
|
1081
|
+
}
|
|
1082
|
+
return this;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1012
1085
|
/**
|
|
1013
1086
|
* Returns expanded branch ids in current flat-data order.
|
|
1014
1087
|
* @returns {unknown[]} Expanded branch ids.
|
|
@@ -1320,11 +1393,8 @@ export class Table extends Component {
|
|
|
1320
1393
|
}
|
|
1321
1394
|
const label = this._message('table.more', 'Show %1 more', [remaining]);
|
|
1322
1395
|
if (!this._more) {
|
|
1323
|
-
this._more = h('button', {
|
|
1324
|
-
|
|
1325
|
-
type: 'button',
|
|
1326
|
-
onclick: () => this.growBy()
|
|
1327
|
-
});
|
|
1396
|
+
this._more = h('button', { class: 'zx-table__more', type: 'button' });
|
|
1397
|
+
this.listen(this._more, 'click', () => this.growBy());
|
|
1328
1398
|
this.el.append(this._more);
|
|
1329
1399
|
}
|
|
1330
1400
|
this._more.textContent = label;
|
|
@@ -1460,6 +1530,9 @@ export class Table extends Component {
|
|
|
1460
1530
|
destroy() {
|
|
1461
1531
|
this._teardownEdit();
|
|
1462
1532
|
this._window?.stop();
|
|
1533
|
+
this._pinObserver?.disconnect();
|
|
1534
|
+
this._pinObserver = null;
|
|
1535
|
+
cancelFrame(this._pinFrame);
|
|
1463
1536
|
this._width?.destroy();
|
|
1464
1537
|
this._width = null;
|
|
1465
1538
|
if (!this._restored && !this._createdRoot) {
|
|
@@ -1770,27 +1843,178 @@ export class Table extends Component {
|
|
|
1770
1843
|
fragment.append(h('col', { class: 'zx-table__selection-column' }));
|
|
1771
1844
|
}
|
|
1772
1845
|
const columns = this._visibleColumns();
|
|
1773
|
-
const
|
|
1774
|
-
const total = fractions.reduce((sum, value) => sum + value, 0);
|
|
1846
|
+
const structural = this._structuralColumns();
|
|
1775
1847
|
// A windowed table cannot size a column by content that is mostly not drawn: the widths would
|
|
1776
1848
|
// move under the reader on every scroll.
|
|
1777
|
-
|
|
1778
|
-
|
|
1849
|
+
const sizing = tableColumnSizing(columns, { virtual: this._virtual, structural });
|
|
1850
|
+
this._table.dataset.layout = sizing.layout;
|
|
1851
|
+
// The narrowest the table gets before its scroll region scrolls inline instead: without it a
|
|
1852
|
+
// `1fr` column beside two fixed ones is handed the few pixels a narrow container leaves over.
|
|
1853
|
+
if (sizing.minInlineSize) this._table.style.setProperty('--zx-table-min-inline-size', sizing.minInlineSize);
|
|
1854
|
+
else this._table.style.removeProperty('--zx-table-min-inline-size');
|
|
1855
|
+
sizing.widths.forEach((width) => {
|
|
1779
1856
|
const col = h('col');
|
|
1780
|
-
if (
|
|
1781
|
-
else if (column.width && column.width !== 'auto') col.style.width = String(column.width);
|
|
1857
|
+
if (width) col.style.width = width;
|
|
1782
1858
|
fragment.append(col);
|
|
1783
1859
|
});
|
|
1784
1860
|
this._colgroup.replaceChildren(fragment);
|
|
1861
|
+
this._pinLayout = tablePinLayout(columns, structural);
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
/** @returns {number} Columns the table renders before the data columns: row handle, checkbox. */
|
|
1865
|
+
_structuralColumns() {
|
|
1866
|
+
return (this.options.rowReorder ? 1 : 0) + (this.options.selectable === 'multi' ? 1 : 0);
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* Marks a header or body cell as part of a pinned column. The offset is a reference to a custom
|
|
1871
|
+
* property on the scroll region, which `_measurePins()` keeps at the width of the pinned columns
|
|
1872
|
+
* before this one, so a row drawn later — a windowed table draws them all the time — needs no
|
|
1873
|
+
* measuring of its own.
|
|
1874
|
+
* @param {HTMLElement} cell Header or body cell.
|
|
1875
|
+
* @param {'start'|'end'} side Edge the column is pinned to.
|
|
1876
|
+
* @param {number} slot Position among the columns pinned to that edge, counted from the edge.
|
|
1877
|
+
* @param {boolean} [edge=false] Whether this is the pinned column next to the scrolling ones.
|
|
1878
|
+
* @returns {void}
|
|
1879
|
+
*/
|
|
1880
|
+
_markPin(cell, side, slot, edge = false) {
|
|
1881
|
+
cell.dataset.pin = side;
|
|
1882
|
+
cell.style.setProperty('--zx-table-pin-offset', `var(--zx-table-pin-${side}-${slot}, 0px)`);
|
|
1883
|
+
if (edge) cell.dataset.pinEdge = '';
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* Builds the header row that names column groups, or null when no visible column has a group.
|
|
1888
|
+
* One cell per run of adjacent columns sharing a group and a pin: a `<th scope="col">` spanning
|
|
1889
|
+
* the run, or a blank `<td>` above columns that belong to no group and above the structural
|
|
1890
|
+
* columns. Native `colspan` carries the span to assistive technology; the cells take no focus.
|
|
1891
|
+
* @returns {HTMLTableRowElement|null}
|
|
1892
|
+
*/
|
|
1893
|
+
_renderGroupRow() {
|
|
1894
|
+
const runs = tableHeaderGroups(this._visibleColumns());
|
|
1895
|
+
if (runs.length === 0) return null;
|
|
1896
|
+
const layout = this._pinLayout;
|
|
1897
|
+
const row = /** @type {HTMLTableRowElement} */ (h('tr', { class: 'zx-table__group-row' }));
|
|
1898
|
+
const structural = this._structuralColumns();
|
|
1899
|
+
if (structural > 0) {
|
|
1900
|
+
const blank = h('td', { class: 'zx-table__group-blank', colspan: structural });
|
|
1901
|
+
if (layout.structural) this._markPin(blank, 'start', 0);
|
|
1902
|
+
row.append(blank);
|
|
1903
|
+
}
|
|
1904
|
+
for (const run of runs) {
|
|
1905
|
+
const cell = run.label === null
|
|
1906
|
+
? h('td', { class: 'zx-table__group-blank', colspan: run.columns.length })
|
|
1907
|
+
: h('th', {
|
|
1908
|
+
class: 'zx-table__group', scope: 'col', colspan: run.columns.length, dataset: { group: run.label }
|
|
1909
|
+
}, h('span', { class: 'zx-table__group-label' }, run.label));
|
|
1910
|
+
if (run.pin) {
|
|
1911
|
+
const pins = run.columns.map((id) => layout.columns.get(id));
|
|
1912
|
+
// The cell sticks where its first column does at the start edge, its last at the end edge.
|
|
1913
|
+
const anchor = run.pin === 'start' ? pins[0] : pins[pins.length - 1];
|
|
1914
|
+
this._markPin(cell, run.pin, anchor.slot, pins.some((pin) => pin.edge));
|
|
1915
|
+
}
|
|
1916
|
+
row.append(cell);
|
|
1917
|
+
}
|
|
1918
|
+
return row;
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
/**
|
|
1922
|
+
* Follows the widths the pinned offsets are made of: the header cells of the pinned columns, and
|
|
1923
|
+
* the group row, whose height is where the column labels stick below it.
|
|
1924
|
+
* @returns {void}
|
|
1925
|
+
*/
|
|
1926
|
+
_watchPins() {
|
|
1927
|
+
this._pinObserver?.disconnect();
|
|
1928
|
+
const cells = this._headerRow ? [...this._headerRow.cells].filter((cell) => cell.dataset.pin) : [];
|
|
1929
|
+
if (this._groupRow?.cells[0]) cells.push(this._groupRow.cells[0]);
|
|
1930
|
+
if (cells.length === 0) {
|
|
1931
|
+
this._measurePins();
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1934
|
+
if (typeof ResizeObserver !== 'function') {
|
|
1935
|
+
this._schedulePins();
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
// Setting an inset from the callback resizes nothing, so there is no loop to defer out of.
|
|
1939
|
+
this._pinObserver ??= new ResizeObserver(() => this._measurePins());
|
|
1940
|
+
for (const cell of cells) this._pinObserver.observe(cell);
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/** Measures the pinned offsets on the next frame. @returns {void} */
|
|
1944
|
+
_schedulePins() {
|
|
1945
|
+
cancelFrame(this._pinFrame);
|
|
1946
|
+
this._pinFrame = nextFrame(() => this._measurePins());
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
/**
|
|
1950
|
+
* Writes where each pinned column sticks, as custom properties on the scroll region: the summed
|
|
1951
|
+
* width of the pinned columns between it and its edge. Also the room the pinned columns take on
|
|
1952
|
+
* each side, which pads the scroll region so a cell focused by keyboard scrolls clear of them,
|
|
1953
|
+
* and the height of the group row. A table that is not laid out keeps what it had.
|
|
1954
|
+
* @returns {void}
|
|
1955
|
+
*/
|
|
1956
|
+
_measurePins() {
|
|
1957
|
+
const style = this._scroll.style;
|
|
1958
|
+
const cells = this._headerRow ? [...this._headerRow.cells] : [];
|
|
1959
|
+
const pinned = cells.some((cell) => cell.dataset.pin);
|
|
1960
|
+
if (!pinned && !this._groupRow) {
|
|
1961
|
+
for (const name of this._pinProps) style.removeProperty(name);
|
|
1962
|
+
this._pinProps = [];
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
const widths = cells.map((cell) => cell.getBoundingClientRect().width);
|
|
1966
|
+
if (!widths.some((width) => width > 0)) return;
|
|
1967
|
+
/** @type {Array<[string, string]>} */
|
|
1968
|
+
const next = [];
|
|
1969
|
+
for (const side of /** @type {const} */ (['start', 'end'])) {
|
|
1970
|
+
const order = side === 'start' ? cells.map((_cell, index) => index)
|
|
1971
|
+
: cells.map((_cell, index) => cells.length - 1 - index);
|
|
1972
|
+
let slot = 0;
|
|
1973
|
+
let offset = 0;
|
|
1974
|
+
for (const index of order) {
|
|
1975
|
+
if (cells[index].dataset.pin !== side) continue;
|
|
1976
|
+
// Rounded down: a pinned column may overlap its neighbour by a fraction of a pixel, but a
|
|
1977
|
+
// gap between two of them would let the scrolling cells show through.
|
|
1978
|
+
next.push([`--zx-table-pin-${side}-${slot}`, `${Math.floor(offset)}px`]);
|
|
1979
|
+
slot += 1;
|
|
1980
|
+
offset += widths[index];
|
|
1981
|
+
}
|
|
1982
|
+
if (slot > 0) next.push([`--zx-table-pin-${side}`, `${Math.ceil(offset)}px`]);
|
|
1983
|
+
}
|
|
1984
|
+
if (this._groupRow) {
|
|
1985
|
+
const height = this._groupRow.getBoundingClientRect().height;
|
|
1986
|
+
if (height > 0) next.push(['--zx-table-group-row-size', `${height}px`]);
|
|
1987
|
+
}
|
|
1988
|
+
const names = new Set(next.map(([name]) => name));
|
|
1989
|
+
for (const name of this._pinProps) if (!names.has(name)) style.removeProperty(name);
|
|
1990
|
+
for (const [name, value] of next) {
|
|
1991
|
+
if (style.getPropertyValue(name) !== value) style.setProperty(name, value);
|
|
1992
|
+
}
|
|
1993
|
+
this._pinProps = [...names];
|
|
1785
1994
|
}
|
|
1786
1995
|
|
|
1787
1996
|
/** @returns {void} */
|
|
1788
1997
|
_renderHeader() {
|
|
1789
|
-
const row = h('tr', { class: 'zx-table__header-row' });
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1998
|
+
const row = /** @type {HTMLTableRowElement} */ (h('tr', { class: 'zx-table__header-row' }));
|
|
1999
|
+
const layout = this._pinLayout;
|
|
2000
|
+
const groupRow = this._renderGroupRow();
|
|
2001
|
+
// The group row is a header row like the other: it counts in the row indices a table that
|
|
2002
|
+
// draws only part of its rows has to state.
|
|
2003
|
+
this._headerRows = groupRow ? 2 : 1;
|
|
2004
|
+
this._groupRow = groupRow;
|
|
2005
|
+
this._headerRow = row;
|
|
2006
|
+
this.el.toggleAttribute('data-header-groups', Boolean(groupRow));
|
|
2007
|
+
if (this._indexed) {
|
|
2008
|
+
groupRow?.setAttribute('aria-rowindex', '1');
|
|
2009
|
+
row.setAttribute('aria-rowindex', String(this._headerRows));
|
|
2010
|
+
}
|
|
2011
|
+
if (this.options.rowReorder) {
|
|
2012
|
+
const reorderHeader = h('th', {
|
|
2013
|
+
class: 'zx-table__reorder-header', scope: 'col', ariaLabel: this._message('table.rowOrder', 'Row order', [])
|
|
2014
|
+
});
|
|
2015
|
+
if (layout.structural) this._markPin(reorderHeader, 'start', 0);
|
|
2016
|
+
row.append(reorderHeader);
|
|
2017
|
+
}
|
|
1794
2018
|
if (this.options.selectable === 'multi') {
|
|
1795
2019
|
this._selectAll = h('input', {
|
|
1796
2020
|
class: 'zx-table__checkbox zx-table__select-all',
|
|
@@ -1801,6 +2025,7 @@ export class Table extends Component {
|
|
|
1801
2025
|
class: 'zx-table__selection-header',
|
|
1802
2026
|
scope: 'col'
|
|
1803
2027
|
}, this._selectAll);
|
|
2028
|
+
if (layout.structural) this._markPin(selectionHeader, 'start', this.options.rowReorder ? 1 : 0);
|
|
1804
2029
|
row.append(selectionHeader);
|
|
1805
2030
|
this.listen(this._selectAll, 'click', () => {
|
|
1806
2031
|
/*
|
|
@@ -1836,6 +2061,8 @@ export class Table extends Component {
|
|
|
1836
2061
|
// is announced with an empty column header.
|
|
1837
2062
|
const name = tableHeaderName(column);
|
|
1838
2063
|
if (name !== null) th.setAttribute('aria-label', name);
|
|
2064
|
+
const pin = layout.columns.get(column.id);
|
|
2065
|
+
if (pin) this._markPin(th, pin.side, pin.slot, pin.edge);
|
|
1839
2066
|
// Withheld, not disabled: a header that invites a sort the component will refuse is worse
|
|
1840
2067
|
// than a header that never offered one. The label still reads exactly the same.
|
|
1841
2068
|
if (column.sortable && !this._spanning) {
|
|
@@ -1857,8 +2084,9 @@ export class Table extends Component {
|
|
|
1857
2084
|
this._headers.set(column.id, th);
|
|
1858
2085
|
row.append(th);
|
|
1859
2086
|
}
|
|
1860
|
-
this._thead.replaceChildren(row);
|
|
2087
|
+
this._thead.replaceChildren(...(groupRow ? [groupRow, row] : [row]));
|
|
1861
2088
|
this._syncSortHeader();
|
|
2089
|
+
this._watchPins();
|
|
1862
2090
|
}
|
|
1863
2091
|
|
|
1864
2092
|
/** @returns {void} @fires Table#editcancel */
|
|
@@ -1911,9 +2139,9 @@ export class Table extends Component {
|
|
|
1911
2139
|
+ (this.options.selectable === 'multi' ? 1 : 0) + (this.options.rowReorder ? 1 : 0)));
|
|
1912
2140
|
/*
|
|
1913
2141
|
* With `growing` or `virtual` on, the DOM holds part of the data — so without this a screen
|
|
1914
|
-
* reader announces "row 3 of 10" for a table of ten thousand.
|
|
2142
|
+
* reader announces "row 3 of 10" for a table of ten thousand. Each header row counts as a row.
|
|
1915
2143
|
*/
|
|
1916
|
-
if (this._indexed) this._table.setAttribute('aria-rowcount', String(projected.length +
|
|
2144
|
+
if (this._indexed) this._table.setAttribute('aria-rowcount', String(projected.length + this._headerRows));
|
|
1917
2145
|
this._syncSelectAll();
|
|
1918
2146
|
this._syncGrowing();
|
|
1919
2147
|
if (this._stacked) this._applyStackedRoles(true);
|
|
@@ -1946,7 +2174,7 @@ export class Table extends Component {
|
|
|
1946
2174
|
const id = this._idFor(row);
|
|
1947
2175
|
const tr = /** @type {HTMLTableRowElement} */ (h('tr', { dataset: { row: '' } }));
|
|
1948
2176
|
// Only part of the rows is in the DOM, so each drawn row states where it really is.
|
|
1949
|
-
if (this._indexed) tr.setAttribute('aria-rowindex', String(tree.visibleIndex +
|
|
2177
|
+
if (this._indexed) tr.setAttribute('aria-rowindex', String(tree.visibleIndex + 1 + this._headerRows));
|
|
1950
2178
|
if (this._virtual && tree.visibleIndex % 2 === 1) tr.dataset.stripe = '';
|
|
1951
2179
|
const rowClass = typeof this.options.rowClass === 'function' ? this.options.rowClass(row) : '';
|
|
1952
2180
|
if (rowClass) tr.classList.add(...String(rowClass).split(/\s+/).filter(Boolean));
|
|
@@ -2001,7 +2229,9 @@ export class Table extends Component {
|
|
|
2001
2229
|
title: this._sort && this.options.sortMode === 'local'
|
|
2002
2230
|
? this._message('table.reorderBlocked', 'Clear sorting to reorder rows', []) : null
|
|
2003
2231
|
}, icon('drag', { size: 14 }));
|
|
2004
|
-
|
|
2232
|
+
const handleCell = h('td', { class: 'zx-table__reorder-cell' }, handle);
|
|
2233
|
+
if (this._pinLayout.structural) this._markPin(handleCell, 'start', 0);
|
|
2234
|
+
tr.append(handleCell);
|
|
2005
2235
|
}
|
|
2006
2236
|
|
|
2007
2237
|
if (this.options.selectable === 'multi') {
|
|
@@ -2013,7 +2243,9 @@ export class Table extends Component {
|
|
|
2013
2243
|
tabIndex: -1,
|
|
2014
2244
|
checked: this._selected.has(id)
|
|
2015
2245
|
});
|
|
2016
|
-
|
|
2246
|
+
const selectionCell = h('td', { class: 'zx-table__selection-cell' }, checkbox);
|
|
2247
|
+
if (this._pinLayout.structural) this._markPin(selectionCell, 'start', this.options.rowReorder ? 1 : 0);
|
|
2248
|
+
tr.append(selectionCell);
|
|
2017
2249
|
}
|
|
2018
2250
|
|
|
2019
2251
|
this._visibleColumns().forEach((column) => {
|
|
@@ -2025,6 +2257,8 @@ export class Table extends Component {
|
|
|
2025
2257
|
cell.dataset.label = column.label;
|
|
2026
2258
|
cell.dataset.column = column.id;
|
|
2027
2259
|
if (column.popin === false) cell.dataset.popin = 'false';
|
|
2260
|
+
const pin = this._pinLayout.columns.get(column.id);
|
|
2261
|
+
if (pin) this._markPin(cell, pin.side, pin.slot, pin.edge);
|
|
2028
2262
|
if (this._focusMode === 'cell') cell.tabIndex = -1;
|
|
2029
2263
|
if (this._editMode !== false && resolveEditable(column, row) !== false) cell.dataset.editable = 'true';
|
|
2030
2264
|
this._renderCellContent(cell, column, row, index, tree);
|
|
@@ -2129,9 +2363,9 @@ export class Table extends Component {
|
|
|
2129
2363
|
return;
|
|
2130
2364
|
}
|
|
2131
2365
|
|
|
2132
|
-
//
|
|
2133
|
-
//
|
|
2134
|
-
if (
|
|
2366
|
+
// A click on a control the host rendered into a cell — a button, a link, a field — belongs to
|
|
2367
|
+
// that control: it neither activates the row nor opens an editor over it.
|
|
2368
|
+
if (isInteractiveCellContent(target)) return;
|
|
2135
2369
|
|
|
2136
2370
|
if (this._editMode !== false && this._editTrigger === 'single') {
|
|
2137
2371
|
const cell = target?.closest('td[data-editable="true"]');
|
|
@@ -2175,7 +2409,7 @@ export class Table extends Component {
|
|
|
2175
2409
|
if (!rowElement || !this._tbody.contains(rowElement)) return;
|
|
2176
2410
|
const meta = this._rowMeta.get(rowElement);
|
|
2177
2411
|
if (!meta) return;
|
|
2178
|
-
if (
|
|
2412
|
+
if (isInteractiveCellContent(target)) return;
|
|
2179
2413
|
if (this._editMode !== false && this._editTrigger === 'double') {
|
|
2180
2414
|
const cell = target?.closest('td[data-editable="true"]');
|
|
2181
2415
|
if (cell && this._tbody.contains(cell)) {
|
|
@@ -3078,13 +3312,16 @@ export class Table extends Component {
|
|
|
3078
3312
|
}
|
|
3079
3313
|
|
|
3080
3314
|
/**
|
|
3081
|
-
* Row activation event.
|
|
3315
|
+
* Row activation event: a click on a row, or Enter on the focused row or cell. A click on a
|
|
3316
|
+
* control inside a cell — a button, link, field, `<label>`, an element with a widget role or in
|
|
3317
|
+
* the Tab order, editable content, or anything marked `data-zx-table-no-edit` — belongs to that
|
|
3318
|
+
* control and does not fire it, nor select the row in a `single` selection.
|
|
3082
3319
|
* @event Table#rowclick
|
|
3083
3320
|
* @type {CustomEvent<TableRowClickDetail>}
|
|
3084
3321
|
*/
|
|
3085
3322
|
|
|
3086
3323
|
/**
|
|
3087
|
-
* Row double-activation event.
|
|
3324
|
+
* Row double-activation event. Like `rowclick`, not fired for a control inside a cell.
|
|
3088
3325
|
* @event Table#rowdblclick
|
|
3089
3326
|
* @type {CustomEvent<TableRowClickDetail>}
|
|
3090
3327
|
*/
|
|
@@ -3176,10 +3413,7 @@ export function tableGridTarget(position, key, grid) {
|
|
|
3176
3413
|
* @returns {number} At least 1.
|
|
3177
3414
|
*/
|
|
3178
3415
|
export function tablePageSize(viewport, rowHeight, fallback = 10) {
|
|
3179
|
-
|
|
3180
|
-
const height = Number(rowHeight);
|
|
3181
|
-
if (!(visible > 0) || !(height > 0)) return Math.max(1, Math.trunc(fallback) || 10);
|
|
3182
|
-
return Math.max(1, Math.floor(visible / height) - 1);
|
|
3416
|
+
return pageStepRows(viewport, rowHeight, fallback);
|
|
3183
3417
|
}
|
|
3184
3418
|
|
|
3185
3419
|
/**
|
|
@@ -3764,13 +3998,33 @@ function isInsideEditor(target) {
|
|
|
3764
3998
|
return Boolean(target?.closest?.('.zx-table__editor'));
|
|
3765
3999
|
}
|
|
3766
4000
|
|
|
3767
|
-
/**
|
|
4001
|
+
/**
|
|
4002
|
+
* What counts as a control inside a cell: native controls and links, a `<label>` (a click on one
|
|
4003
|
+
* is a click on its control), editable content, the ARIA widget roles, anything in the Tab order,
|
|
4004
|
+
* and anything the host marks with `data-zx-table-no-edit`. Zx controls rendered into a cell are
|
|
4005
|
+
* covered by the first and the last three: each is, or wraps, one of these.
|
|
4006
|
+
*/
|
|
4007
|
+
export const TABLE_INTERACTIVE_SELECTOR = [
|
|
4008
|
+
'a[href]', 'button', 'input', 'select', 'textarea', 'summary', 'label',
|
|
4009
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
4010
|
+
...['button', 'link', 'checkbox', 'switch', 'radio', 'menuitem', 'menuitemcheckbox',
|
|
4011
|
+
'menuitemradio', 'tab', 'option', 'combobox', 'listbox', 'slider', 'spinbutton', 'textbox',
|
|
4012
|
+
'searchbox'].map((role) => `[role="${role}"]`),
|
|
4013
|
+
'[tabindex]:not([tabindex="-1"])', '[data-zx-table-no-edit]'
|
|
4014
|
+
].join(',');
|
|
4015
|
+
|
|
4016
|
+
/**
|
|
4017
|
+
* Whether a click landed on a control inside a body cell rather than on the cell: such a click
|
|
4018
|
+
* neither activates the row (`rowclick`, `rowdblclick`, the `single` selection) nor opens an
|
|
4019
|
+
* editor. The cell and the row are in the Tab order themselves, so only a match strictly inside
|
|
4020
|
+
* the cell counts. The table's own controls — checkbox, disclosure, row handle, an open editor —
|
|
4021
|
+
* are handled before this is asked.
|
|
4022
|
+
* @param {Element|null} target Click target.
|
|
4023
|
+
* @returns {boolean}
|
|
4024
|
+
*/
|
|
3768
4025
|
function isInteractiveCellContent(target) {
|
|
3769
|
-
const cell = target?.closest?.('td[data-column]');
|
|
3770
|
-
const interactive = target?.closest?.(
|
|
3771
|
-
'a[href]', 'button', 'input', 'select', 'textarea', 'summary', '[contenteditable="true"]',
|
|
3772
|
-
'[role="button"]', '[role="link"]', '[tabindex]:not([tabindex="-1"])', '[data-zx-table-no-edit]'
|
|
3773
|
-
].join(','));
|
|
4026
|
+
const cell = target?.closest?.('td[data-column], th.zx-table__section-cell');
|
|
4027
|
+
const interactive = target?.closest?.(TABLE_INTERACTIVE_SELECTOR);
|
|
3774
4028
|
return Boolean(cell && interactive && interactive !== cell && cell.contains(interactive));
|
|
3775
4029
|
}
|
|
3776
4030
|
|
|
@@ -3901,6 +4155,189 @@ function normalizeSort(sort, columns) {
|
|
|
3901
4155
|
return { id: sort.id, dir: sort.dir === 'desc' ? 'desc' : 'asc' };
|
|
3902
4156
|
}
|
|
3903
4157
|
|
|
4158
|
+
/** Narrowest an `fr` column gets when its `minWidth` does not say. */
|
|
4159
|
+
export const TABLE_FR_MIN_WIDTH = '5rem';
|
|
4160
|
+
|
|
4161
|
+
/**
|
|
4162
|
+
* Whether a column width can be added up in a `calc()`: a length with a unit, or a CSS function
|
|
4163
|
+
* that holds no percentage — a percentage would resolve against the container, not the table.
|
|
4164
|
+
* @param {unknown} value Column `width` or `minWidth`.
|
|
4165
|
+
* @returns {boolean}
|
|
4166
|
+
*/
|
|
4167
|
+
function isCssLength(value) {
|
|
4168
|
+
if (typeof value !== 'string') return false;
|
|
4169
|
+
const text = value.trim();
|
|
4170
|
+
if (/^\d*\.?\d+[a-z]+$/i.test(text)) return !/fr$/i.test(text);
|
|
4171
|
+
return /^(?:calc|min|max|clamp|var)\(.*\)$/i.test(text) && !text.includes('%');
|
|
4172
|
+
}
|
|
4173
|
+
|
|
4174
|
+
/**
|
|
4175
|
+
* Reads a column's `minWidth`.
|
|
4176
|
+
* @param {unknown} value Configured value.
|
|
4177
|
+
* @returns {string|null|undefined} A CSS length; null when the column asks for no floor (`0`);
|
|
4178
|
+
* undefined when it says nothing usable, which leaves the default to the caller.
|
|
4179
|
+
*/
|
|
4180
|
+
function columnMinWidth(value) {
|
|
4181
|
+
if (value === 0 || value === '0' || value === false) return null;
|
|
4182
|
+
if (typeof value === 'number') return Number.isFinite(value) && value > 0 ? `${value}px` : undefined;
|
|
4183
|
+
return isCssLength(value) ? /** @type {string} */ (value).trim() : undefined;
|
|
4184
|
+
}
|
|
4185
|
+
|
|
4186
|
+
/**
|
|
4187
|
+
* How the visible columns are sized: the table layout, the width of each `<col>`, and the
|
|
4188
|
+
* narrowest the table may get. Pure, so the decisions can be tested without a layout engine.
|
|
4189
|
+
*
|
|
4190
|
+
* `fr` columns become percentages in proportion to each other and switch the table to a fixed
|
|
4191
|
+
* layout, as a windowed table always is. In a fixed layout the columns with a CSS length keep it
|
|
4192
|
+
* and the `fr` columns share what is left — which in a narrow container is next to nothing. So the
|
|
4193
|
+
* table gets a minimum width: the lengths, plus enough for the `fr` column that needs the most
|
|
4194
|
+
* room to reach its floor at its share, and the scroll region scrolls inline below that. The floor
|
|
4195
|
+
* is the column's `minWidth`, or `TABLE_FR_MIN_WIDTH`; an `auto` column counts with its `minWidth`
|
|
4196
|
+
* when it has one, and percentage widths are left out of the sum.
|
|
4197
|
+
* @param {Array<Partial<TableColumn>>} columns Visible columns, in display order.
|
|
4198
|
+
* @param {{virtual?: boolean, structural?: number}} [options={}] Whether the table is windowed, and
|
|
4199
|
+
* how many control-height columns (row handle, checkbox) it renders before the data columns.
|
|
4200
|
+
* @returns {{layout: 'fixed'|'auto', widths: Array<string|null>, minInlineSize: string|null}}
|
|
4201
|
+
* `widths` holds one `<col>` width per column, null where the column has none.
|
|
4202
|
+
*/
|
|
4203
|
+
export function tableColumnSizing(columns, options = {}) {
|
|
4204
|
+
const list = Array.isArray(columns) ? columns : [];
|
|
4205
|
+
const fractions = list.map((column) => parseFraction(column?.width));
|
|
4206
|
+
const total = fractions.reduce((sum, value) => sum + value, 0);
|
|
4207
|
+
const layout = total > 0 || options.virtual ? 'fixed' : 'auto';
|
|
4208
|
+
const widths = list.map((column, index) => {
|
|
4209
|
+
if (fractions[index] > 0) return `${fractions[index] / total * 100}%`;
|
|
4210
|
+
return column?.width && column.width !== 'auto' ? String(column.width) : null;
|
|
4211
|
+
});
|
|
4212
|
+
if (layout !== 'fixed') return { layout, widths, minInlineSize: null };
|
|
4213
|
+
|
|
4214
|
+
/** @type {string[]} */
|
|
4215
|
+
const lengths = [];
|
|
4216
|
+
/** @type {Map<string, number>} Floor of the `fr` columns → the largest factor it is scaled by. */
|
|
4217
|
+
const floors = new Map();
|
|
4218
|
+
let guarded = false;
|
|
4219
|
+
list.forEach((column, index) => {
|
|
4220
|
+
const min = columnMinWidth(column?.minWidth);
|
|
4221
|
+
if (fractions[index] > 0) {
|
|
4222
|
+
const floor = min === undefined ? TABLE_FR_MIN_WIDTH : min;
|
|
4223
|
+
if (floor === null) return;
|
|
4224
|
+
guarded = true;
|
|
4225
|
+
// The column gets `fraction / total` of what the `fr` columns share, so they need this many
|
|
4226
|
+
// floors between them for it to reach one.
|
|
4227
|
+
floors.set(floor, Math.max(floors.get(floor) ?? 0, total / fractions[index]));
|
|
4228
|
+
} else if (isCssLength(column?.width)) {
|
|
4229
|
+
lengths.push(String(column.width).trim());
|
|
4230
|
+
} else if (min && (!column?.width || column.width === 'auto')) {
|
|
4231
|
+
guarded = true;
|
|
4232
|
+
lengths.push(min);
|
|
4233
|
+
}
|
|
4234
|
+
});
|
|
4235
|
+
if (!guarded) return { layout, widths, minInlineSize: null };
|
|
4236
|
+
const structural = Math.max(0, Math.trunc(Number(options.structural) || 0));
|
|
4237
|
+
if (structural > 0) lengths.unshift(structural === 1 ? 'var(--zx-control-height)' : `var(--zx-control-height) * ${structural}`);
|
|
4238
|
+
const shares = [...floors].map(([floor, factor]) => {
|
|
4239
|
+
const rounded = Math.ceil(factor * 1000) / 1000;
|
|
4240
|
+
return rounded === 1 ? floor : `${floor} * ${rounded}`;
|
|
4241
|
+
});
|
|
4242
|
+
if (shares.length === 1) lengths.push(shares[0]);
|
|
4243
|
+
else if (shares.length > 1) lengths.push(`max(${shares.join(', ')})`);
|
|
4244
|
+
const minInlineSize = lengths.length === 1 && !lengths[0].includes('*') ? lengths[0] : `calc(${lengths.join(' + ')})`;
|
|
4245
|
+
return { layout, widths, minInlineSize };
|
|
4246
|
+
}
|
|
4247
|
+
|
|
4248
|
+
/**
|
|
4249
|
+
* The edge a column is pinned to.
|
|
4250
|
+
* @param {Partial<TableColumn>|null|undefined} column Column descriptor.
|
|
4251
|
+
* @returns {'start'|'end'|null} Null for an unpinned column and for any other value.
|
|
4252
|
+
*/
|
|
4253
|
+
export function tableColumnPin(column) {
|
|
4254
|
+
return column?.pin === 'start' || column?.pin === 'end' ? column.pin : null;
|
|
4255
|
+
}
|
|
4256
|
+
|
|
4257
|
+
/**
|
|
4258
|
+
* Where each pinned column sits among the columns pinned to its edge. A slot counts from the edge:
|
|
4259
|
+
* slot 0 at the start is the first pinned column in display order, slot 0 at the end the last. The
|
|
4260
|
+
* structural columns (row handle, selection checkbox) take the first start slots once any column
|
|
4261
|
+
* is pinned to the start, so they stay in view with it. The `edge` column of a side is the one next
|
|
4262
|
+
* to the scrolling columns — the last pinned to the start, the first pinned to the end — which is
|
|
4263
|
+
* where the dividing rule is drawn.
|
|
4264
|
+
* @param {Array<Partial<TableColumn>>} columns Visible columns, in display order.
|
|
4265
|
+
* @param {number} [structural=0] Structural columns rendered before them.
|
|
4266
|
+
* @returns {{start: number, end: number, structural: boolean,
|
|
4267
|
+
* columns: Map<string, {side: 'start'|'end', slot: number, edge: boolean}>}} Slots taken on each
|
|
4268
|
+
* side, whether the structural columns are pinned, and the placement of each pinned column by id.
|
|
4269
|
+
*/
|
|
4270
|
+
export function tablePinLayout(columns, structural = 0) {
|
|
4271
|
+
const list = Array.isArray(columns) ? columns : [];
|
|
4272
|
+
const sides = list.map((column) => tableColumnPin(column));
|
|
4273
|
+
const placed = new Map();
|
|
4274
|
+
const leading = Math.max(0, Math.trunc(Number(structural) || 0));
|
|
4275
|
+
const pinsStructural = leading > 0 && sides.includes('start');
|
|
4276
|
+
let start = pinsStructural ? leading : 0;
|
|
4277
|
+
const lastStart = sides.lastIndexOf('start');
|
|
4278
|
+
const firstEnd = sides.indexOf('end');
|
|
4279
|
+
sides.forEach((side, index) => {
|
|
4280
|
+
if (side !== 'start') return;
|
|
4281
|
+
placed.set(String(list[index].id), { side, slot: start, edge: index === lastStart });
|
|
4282
|
+
start += 1;
|
|
4283
|
+
});
|
|
4284
|
+
let end = 0;
|
|
4285
|
+
for (let index = list.length - 1; index >= 0; index -= 1) {
|
|
4286
|
+
if (sides[index] !== 'end') continue;
|
|
4287
|
+
placed.set(String(list[index].id), { side: 'end', slot: end, edge: index === firstEnd });
|
|
4288
|
+
end += 1;
|
|
4289
|
+
}
|
|
4290
|
+
return { start, end, structural: pinsStructural, columns: placed };
|
|
4291
|
+
}
|
|
4292
|
+
|
|
4293
|
+
/**
|
|
4294
|
+
* The cells of the header row that names column groups: one per run of adjacent columns sharing a
|
|
4295
|
+
* `group` and a `pin`, in display order, with a null label for a run that belongs to no group. A
|
|
4296
|
+
* run is split where the pin changes because a header cell sticks as a whole or not at all. Empty
|
|
4297
|
+
* when no column has a group, which is when the table renders no such row.
|
|
4298
|
+
* @param {Array<Partial<TableColumn>>} columns Visible columns, in display order.
|
|
4299
|
+
* @returns {Array<{label: string|null, pin: 'start'|'end'|null, columns: string[]}>} Runs; the
|
|
4300
|
+
* length of `columns` is the cell's `colspan`.
|
|
4301
|
+
*/
|
|
4302
|
+
export function tableHeaderGroups(columns) {
|
|
4303
|
+
const list = Array.isArray(columns) ? columns : [];
|
|
4304
|
+
/** @type {Array<{label: string|null, pin: 'start'|'end'|null, columns: string[]}>} */
|
|
4305
|
+
const runs = [];
|
|
4306
|
+
let grouped = false;
|
|
4307
|
+
for (const column of list) {
|
|
4308
|
+
const label = column?.group == null ? null : String(column.group).trim() || null;
|
|
4309
|
+
const pin = tableColumnPin(column);
|
|
4310
|
+
if (label !== null) grouped = true;
|
|
4311
|
+
const last = runs[runs.length - 1];
|
|
4312
|
+
if (last && last.label === label && last.pin === pin) last.columns.push(String(column.id));
|
|
4313
|
+
else runs.push({ label, pin, columns: [String(column.id)] });
|
|
4314
|
+
}
|
|
4315
|
+
return grouped ? runs : [];
|
|
4316
|
+
}
|
|
4317
|
+
|
|
4318
|
+
/**
|
|
4319
|
+
* What replacing the set of expanded branches changes. Ids that are not branches of the current
|
|
4320
|
+
* data are dropped, exactly as the table drops them from `hierarchy.expanded`.
|
|
4321
|
+
* @param {unknown[]} branchIds Ids of every row that has children, in data order.
|
|
4322
|
+
* @param {Set<unknown>} current Branches expanded now.
|
|
4323
|
+
* @param {unknown} ids Branches to leave expanded: an array (or any iterable) of ids, `true` for
|
|
4324
|
+
* every branch, anything else for none.
|
|
4325
|
+
* @returns {{expanded: Set<unknown>, opened: unknown[], closed: unknown[]}} The new set, and the
|
|
4326
|
+
* branches whose state changes, each in data order.
|
|
4327
|
+
*/
|
|
4328
|
+
export function resolveExpandedChange(branchIds, current, ids) {
|
|
4329
|
+
const branches = Array.isArray(branchIds) ? branchIds : [];
|
|
4330
|
+
const before = current instanceof Set ? current : new Set();
|
|
4331
|
+
const iterable = ids != null && typeof ids === 'object' && typeof ids[Symbol.iterator] === 'function';
|
|
4332
|
+
const wanted = ids === true ? null : new Set(iterable ? /** @type {Iterable<unknown>} */ (ids) : []);
|
|
4333
|
+
const expanded = new Set(branches.filter((id) => wanted === null || wanted.has(id)));
|
|
4334
|
+
return {
|
|
4335
|
+
expanded,
|
|
4336
|
+
opened: branches.filter((id) => expanded.has(id) && !before.has(id)),
|
|
4337
|
+
closed: branches.filter((id) => before.has(id) && !expanded.has(id))
|
|
4338
|
+
};
|
|
4339
|
+
}
|
|
4340
|
+
|
|
3904
4341
|
/** @param {unknown} width @returns {number} */
|
|
3905
4342
|
function parseFraction(width) {
|
|
3906
4343
|
if (typeof width !== 'string') return 0;
|
|
@@ -3913,16 +4350,6 @@ function assertRows(rows) {
|
|
|
3913
4350
|
if (!Array.isArray(rows)) throw new TypeError('Table data must be an array');
|
|
3914
4351
|
}
|
|
3915
4352
|
|
|
3916
|
-
/** @param {Set<unknown>} left @param {Set<unknown>} right @returns {boolean} */
|
|
3917
|
-
function sameSet(left, right) {
|
|
3918
|
-
return left.size === right.size && [...left].every((value) => right.has(value));
|
|
3919
|
-
}
|
|
3920
|
-
|
|
3921
|
-
/** @param {unknown[]} left @param {unknown[]} right @returns {boolean} */
|
|
3922
|
-
function sameArray(left, right) {
|
|
3923
|
-
return left.length === right.length && left.every((value, index) => Object.is(value, right[index]));
|
|
3924
|
-
}
|
|
3925
|
-
|
|
3926
4353
|
/**
|
|
3927
4354
|
* Normalizes the `growing` option into a batch size.
|
|
3928
4355
|
* @param {unknown} growing Option value.
|