@fusion.dev/helix-headless 0.239.0 → 0.240.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/api.json +1 -1
  2. package/custom-elements.json +1 -1
  3. package/dist/column-manager/index.d.ts +1 -0
  4. package/dist/column-manager/index.js +1 -0
  5. package/dist/column-manager/root/column-manager-root.d.ts +137 -0
  6. package/dist/column-manager/root/column-manager-root.js +253 -0
  7. package/dist/data-table/binding.d.ts +85 -0
  8. package/dist/data-table/binding.js +58 -0
  9. package/dist/data-table/edit.d.ts +47 -0
  10. package/dist/data-table/edit.js +60 -0
  11. package/dist/data-table/events/before-cell-commit.d.ts +16 -0
  12. package/dist/data-table/events/before-cell-commit.js +11 -0
  13. package/dist/data-table/events/before-cell-edit.d.ts +13 -0
  14. package/dist/data-table/events/before-cell-edit.js +11 -0
  15. package/dist/data-table/events/before-export.d.ts +15 -0
  16. package/dist/data-table/events/before-export.js +11 -0
  17. package/dist/data-table/events/before-view-change.d.ts +16 -0
  18. package/dist/data-table/events/before-view-change.js +11 -0
  19. package/dist/data-table/events/cell-commit.d.ts +12 -0
  20. package/dist/data-table/events/cell-commit.js +11 -0
  21. package/dist/data-table/events/cell-edit.d.ts +11 -0
  22. package/dist/data-table/events/cell-edit.js +11 -0
  23. package/dist/data-table/events/details.d.ts +47 -0
  24. package/dist/data-table/events/export.d.ts +11 -0
  25. package/dist/data-table/events/export.js +11 -0
  26. package/dist/data-table/events/index.d.ts +18 -2
  27. package/dist/data-table/events/index.js +17 -1
  28. package/dist/data-table/events/view-change.d.ts +12 -0
  29. package/dist/data-table/events/view-change.js +11 -0
  30. package/dist/data-table/export.d.ts +43 -0
  31. package/dist/data-table/export.js +26 -0
  32. package/dist/data-table/index.d.ts +2 -0
  33. package/dist/data-table/index.js +2 -0
  34. package/dist/data-table/root/data-table-root.d.ts +406 -26
  35. package/dist/data-table/root/data-table-root.js +959 -30
  36. package/dist/data-table/view.d.ts +124 -0
  37. package/dist/data-table/view.js +249 -0
  38. package/dist/data-table/xlsx/index.d.ts +27 -0
  39. package/dist/data-table/xlsx/index.js +119 -0
  40. package/dist/date-input/root/date-input-root.d.ts +7 -0
  41. package/dist/date-input/root/date-input-root.js +9 -1
  42. package/dist/element-events.generated.js +9 -0
  43. package/dist/filter-input/root/filter-input-root.d.ts +31 -0
  44. package/dist/filter-input/root/filter-input-root.js +94 -12
  45. package/dist/filter-input/table.d.ts +64 -0
  46. package/dist/filter-input/table.js +76 -0
  47. package/dist/index.d.ts +5 -0
  48. package/dist/index.js +5 -0
  49. package/dist/input/root/input-root.d.ts +7 -0
  50. package/dist/input/root/input-root.js +9 -1
  51. package/dist/number-input/root/number-input-root.d.ts +7 -0
  52. package/dist/number-input/root/number-input-root.js +9 -1
  53. package/dist/quick-filters/events/before-view-save.d.ts +14 -0
  54. package/dist/quick-filters/events/before-view-save.js +11 -0
  55. package/dist/quick-filters/events/details.d.ts +10 -0
  56. package/dist/quick-filters/events/details.js +1 -0
  57. package/dist/quick-filters/events/index.d.ts +16 -0
  58. package/dist/quick-filters/events/index.js +9 -0
  59. package/dist/quick-filters/events/view-save.d.ts +11 -0
  60. package/dist/quick-filters/events/view-save.js +11 -0
  61. package/dist/quick-filters/filter/quick-filter.d.ts +48 -0
  62. package/dist/quick-filters/filter/quick-filter.js +33 -0
  63. package/dist/quick-filters/index.d.ts +3 -0
  64. package/dist/quick-filters/index.js +3 -0
  65. package/dist/quick-filters/root/quick-filters-root.d.ts +118 -0
  66. package/dist/quick-filters/root/quick-filters-root.js +183 -0
  67. package/dist/selection-bar/index.d.ts +1 -0
  68. package/dist/selection-bar/index.js +1 -0
  69. package/dist/selection-bar/root/selection-bar-root.d.ts +65 -0
  70. package/dist/selection-bar/root/selection-bar-root.js +44 -0
  71. package/dist/table/column/table-column.d.ts +82 -0
  72. package/dist/table/column/table-column.js +54 -0
  73. package/dist/table/column-type.d.ts +7 -0
  74. package/dist/table/column-type.js +1 -0
  75. package/dist/table-export/index.d.ts +1 -0
  76. package/dist/table-export/index.js +1 -0
  77. package/dist/table-export/root/table-export-root.d.ts +132 -0
  78. package/dist/table-export/root/table-export-root.js +233 -0
  79. package/dist/view-panel/index.d.ts +1 -0
  80. package/dist/view-panel/index.js +1 -0
  81. package/dist/view-panel/root/view-panel-root.d.ts +132 -0
  82. package/dist/view-panel/root/view-panel-root.js +209 -0
  83. package/examples.json +1 -1
  84. package/lint.json +1 -1
  85. package/package.json +5 -5
  86. package/types/jsx.d.ts +1231 -9
  87. package/types/svelte.d.ts +6 -0
  88. package/types/vue.d.ts +605 -6
  89. package/types/words.d.ts +305 -5
@@ -0,0 +1 @@
1
+ export * from './root/column-manager-root.js';
@@ -0,0 +1 @@
1
+ export * from './root/column-manager-root.js';
@@ -0,0 +1,137 @@
1
+ import { HelixElement } from '@fusion.dev/helix-core';
2
+ import { type TemplateResult } from 'lit';
3
+ import { TableBinding, type ToolColumn, type ToolTable } from '../../data-table/binding.js';
4
+ /**
5
+ * @summary A list of a Data Table's columns, to show, hide, reorder, and pin them.
6
+ *
7
+ * @description
8
+ * Set `for` to the id of a `DataTable`, and the list holds a row for each of
9
+ * its columns with a `field`, in the order the table shows them. Put it in a
10
+ * `Popover` opened by a Columns button, or in a `Drawer` on a phone.
11
+ *
12
+ * ```html
13
+ * <helix-column-manager for="invoices"></helix-column-manager>
14
+ * ```
15
+ *
16
+ * Each row has:
17
+ *
18
+ * - A checkbox that shows or hides the column. The last column showing cannot be hidden.
19
+ * - A grip that moves the column. Drag it, or press Alt with Up or Down.
20
+ * - A pin button that pins the column to the start of the row, then to the end, then unpins it.
21
+ * A pinned column stays in view while the table scrolls sideways.
22
+ * - A note that says "Pinned", or "Hidden at this width" for a column the table leaves out
23
+ * because it is narrower than the column's `min-table-width`.
24
+ *
25
+ * Reset puts the columns back as they were when the list first read the
26
+ * table.
27
+ *
28
+ * **It writes the table's `view.columns` and nothing else.** Every change asks
29
+ * the table with `requestView`, so the table fires `helix-before-view-change`,
30
+ * which you can refuse, and `helix-view-change`. Store the view to keep a
31
+ * reader's columns.
32
+ *
33
+ * **Keyboard.** Each row's checkbox, grip and pin button are in the tab order.
34
+ *
35
+ * | Key | What it does |
36
+ * |---|---|
37
+ * | Space on a checkbox | Shows or hides the column. |
38
+ * | Alt with Up or Down | Moves the column one place, from anywhere in its row. |
39
+ * | Enter, Space on a pin button | Pins the column to the start, then to the end, then unpins it. |
40
+ *
41
+ * A move is said in the `live` region.
42
+ *
43
+ * @since 0.238.0
44
+ * @status experimental
45
+ * @category data
46
+ * @aliases Column picker, Column chooser
47
+ * @documentation https://fusion.dev/helix/components/column-manager
48
+ *
49
+ * @csspart checkbox - The checkbox that shows or hides a column.
50
+ * @csspart grip - The button that moves a column.
51
+ * @csspart grip-mark - The icon on the grip.
52
+ * @csspart header - The row above the list that holds the title and the reset button.
53
+ * @csspart item - One column's row.
54
+ * @csspart item-dragging - Added to `item` while it is being dragged.
55
+ * @csspart item-hidden - Added to `item` while its column is hidden.
56
+ * @csspart list - The list of columns.
57
+ * @csspart live - The region that says a move. Visually hidden in the styled tier.
58
+ * @csspart name - A column's name, which labels its checkbox.
59
+ * @csspart note - Says "Pinned" or "Hidden at this width" beside a column's name.
60
+ * @csspart pin - The button that pins a column.
61
+ * @csspart pin-mark - The icon on the pin button.
62
+ * @csspart pin-pinned - Added to `pin` while its column is pinned.
63
+ * @csspart reset - The button that puts the columns back.
64
+ * @csspart title - The list's heading.
65
+ */
66
+ export declare class HelixHeadlessColumnManager extends HelixElement {
67
+ /**
68
+ * The key this family's words are registered under, its styled tag:
69
+ * `registerWords('de', { 'helix-column-manager': { resetLabel: 'Zurücksetzen' } })`.
70
+ */
71
+ static words: string;
72
+ /** The note on a column the table leaves out at its width. */
73
+ droppedLabel: string;
74
+ /** The name the element gives itself where `label` is empty. */
75
+ fallbackLabel: string;
76
+ /**
77
+ * The id of the `DataTable` whose columns the list holds, in the same
78
+ * document or shadow root.
79
+ */
80
+ for: string;
81
+ /**
82
+ * The name of the list, which a screen reader announces before its items.
83
+ *
84
+ * Empty by default, which leaves the name to `fallbackLabel`.
85
+ */
86
+ label: string;
87
+ /**
88
+ * What a screen reader hears after a move. `{name}` is the column's heading,
89
+ * `{position}` its place and `{count}` the number of columns.
90
+ */
91
+ movedLabel: string;
92
+ /** The name of a column's grip. `{name}` is the column's heading. */
93
+ moveLabel: string;
94
+ /** The name of the pin button on a column pinned to the start. `{name}` is its heading. */
95
+ pinEndLabel: string;
96
+ /** The note on a pinned column. */
97
+ pinnedLabel: string;
98
+ /** The name of the pin button on a column that is not pinned. `{name}` is its heading. */
99
+ pinStartLabel: string;
100
+ /** The words on the button that puts the columns back. */
101
+ resetLabel: string;
102
+ /** The name of the pin button on a column pinned to the end. `{name}` is its heading. */
103
+ unpinLabel: string;
104
+ /** What the live region says. */
105
+ private said;
106
+ /** The field being dragged, while a pointer drags one. */
107
+ private dragging;
108
+ /** The columns as the list first read them, which Reset puts back. */
109
+ private first;
110
+ protected readonly binding: TableBinding;
111
+ /** The bound table, once it is in the tree. */
112
+ get table(): ToolTable | null;
113
+ /** The columns with a field, in the order the table shows them. */
114
+ private columns;
115
+ /** Asks the table for its columns arranged another way. */
116
+ private ask;
117
+ /** Shows or hides one column. */
118
+ toggleColumn(field: string, shown: boolean): boolean;
119
+ /** Moves one column by some places among the columns, and says where it went. */
120
+ moveColumn(field: string, by: number): boolean;
121
+ /** Pins a column to an end of the row, or unpins it with `undefined`. */
122
+ pinColumn(field: string, edge: 'end' | 'start' | undefined): boolean;
123
+ /** Puts the columns back as they were when the list first read the table. */
124
+ reset(): boolean;
125
+ protected willUpdate(): void;
126
+ private readonly handleKey;
127
+ private readonly handleDragStart;
128
+ private readonly handleDragOver;
129
+ private readonly handleDrop;
130
+ protected renderItem(table: ToolTable, column: ToolColumn, onlyShown: boolean): TemplateResult;
131
+ protected render(): TemplateResult;
132
+ }
133
+ declare global {
134
+ interface HTMLElementTagNameMap {
135
+ 'helix-headless-column-manager': HelixHeadlessColumnManager;
136
+ }
137
+ }
@@ -0,0 +1,253 @@
1
+ import { __decorate } from "tslib";
2
+ import { customElement, formatWords, HelixElement, words } from '@fusion.dev/helix-core';
3
+ import { dotsSixVertical, pushPin, pushPinSlash } from '@fusion.dev/helix-icons';
4
+ import { html, nothing } from 'lit';
5
+ import { property, state } from 'lit/decorators.js';
6
+ import { repeat } from 'lit/directives/repeat.js';
7
+ import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
8
+ import { columnName, TableBinding, } from '../../data-table/binding.js';
9
+ const nextPin = (now) => now === undefined ? 'start' : now === 'start' ? 'end' : undefined;
10
+ let HelixHeadlessColumnManager = class HelixHeadlessColumnManager extends HelixElement {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.droppedLabel = 'Hidden at this width';
14
+ this.fallbackLabel = 'Columns';
15
+ this.for = '';
16
+ this.label = '';
17
+ this.movedLabel = '{name} moved to {position} of {count}';
18
+ this.moveLabel = 'Move {name}';
19
+ this.pinEndLabel = 'Pin {name} to the end';
20
+ this.pinnedLabel = 'Pinned';
21
+ this.pinStartLabel = 'Pin {name} to the start';
22
+ this.resetLabel = 'Reset';
23
+ this.unpinLabel = 'Unpin {name}';
24
+ this.said = '';
25
+ this.dragging = undefined;
26
+ this.first = undefined;
27
+ this.binding = new TableBinding(this);
28
+ this.handleKey = (event, field) => {
29
+ if (!event.altKey || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown')) {
30
+ return;
31
+ }
32
+ event.preventDefault();
33
+ if (this.moveColumn(field, event.key === 'ArrowUp' ? -1 : 1)) {
34
+ const at = event.target.getAttribute('part')?.split(' ')[0];
35
+ this.updateComplete.then(() => {
36
+ this.renderRoot
37
+ .querySelector(`[data-field="${CSS.escape(field)}"] [part~="${at ?? 'grip'}"]`)
38
+ ?.focus();
39
+ });
40
+ }
41
+ };
42
+ this.handleDragStart = (event, field) => {
43
+ this.dragging = field;
44
+ event.dataTransfer?.setData('text/plain', field);
45
+ if (event.dataTransfer) {
46
+ event.dataTransfer.effectAllowed = 'move';
47
+ }
48
+ };
49
+ this.handleDragOver = (event) => {
50
+ if (this.dragging !== undefined) {
51
+ event.preventDefault();
52
+ }
53
+ };
54
+ this.handleDrop = (event, field) => {
55
+ const table = this.table;
56
+ const moving = this.dragging;
57
+ this.dragging = undefined;
58
+ if (!table || moving === undefined || moving === field) {
59
+ return;
60
+ }
61
+ event.preventDefault();
62
+ const fields = this.columns(table).map((column) => column.field);
63
+ this.moveColumn(moving, fields.indexOf(field) - fields.indexOf(moving));
64
+ };
65
+ }
66
+ static { this.words = 'helix-column-manager'; }
67
+ get table() {
68
+ return this.binding.table;
69
+ }
70
+ columns(table) {
71
+ const columns = table.tableColumns.filter((column) => column.field !== '');
72
+ const order = table.view.columns.order;
73
+ if (order.length === 0) {
74
+ return columns;
75
+ }
76
+ const rank = new Map(order.map((field, place) => [field, place]));
77
+ return [...columns].sort((a, b) => (rank.get(a.field) ?? Number.POSITIVE_INFINITY) -
78
+ (rank.get(b.field) ?? Number.POSITIVE_INFINITY));
79
+ }
80
+ ask(table, columns) {
81
+ return table.requestView({ columns });
82
+ }
83
+ toggleColumn(field, shown) {
84
+ const table = this.table;
85
+ if (!table) {
86
+ return false;
87
+ }
88
+ const hidden = table.view.columns.hidden.filter((one) => one !== field);
89
+ return this.ask(table, { hidden: shown ? hidden : [...hidden, field] });
90
+ }
91
+ moveColumn(field, by) {
92
+ const table = this.table;
93
+ if (!table) {
94
+ return false;
95
+ }
96
+ const columns = this.columns(table);
97
+ const fields = columns.map((column) => column.field);
98
+ const from = fields.indexOf(field);
99
+ const to = Math.max(0, Math.min(fields.length - 1, from + by));
100
+ if (from < 0 || to === from) {
101
+ return false;
102
+ }
103
+ fields.splice(to, 0, ...fields.splice(from, 1));
104
+ if (!this.ask(table, { order: fields })) {
105
+ return false;
106
+ }
107
+ const column = columns[from];
108
+ this.said = formatWords(this, 'movedLabel', {
109
+ count: fields.length,
110
+ name: columnName(column),
111
+ position: to + 1,
112
+ });
113
+ return true;
114
+ }
115
+ pinColumn(field, edge) {
116
+ const table = this.table;
117
+ if (!table) {
118
+ return false;
119
+ }
120
+ const pinned = { ...table.view.columns.pinned };
121
+ if (edge) {
122
+ pinned[field] = edge;
123
+ }
124
+ else {
125
+ delete pinned[field];
126
+ }
127
+ return this.ask(table, { pinned });
128
+ }
129
+ reset() {
130
+ const table = this.table;
131
+ const first = this.first;
132
+ return table && first ? this.ask(table, first) : false;
133
+ }
134
+ willUpdate() {
135
+ const table = this.table;
136
+ if (table && !this.first) {
137
+ const { columns } = table.view;
138
+ this.first = {
139
+ hidden: [...columns.hidden],
140
+ order: [...columns.order],
141
+ pinned: { ...columns.pinned },
142
+ widths: { ...columns.widths },
143
+ };
144
+ }
145
+ }
146
+ renderItem(table, column, onlyShown) {
147
+ const { field } = column;
148
+ const name = columnName(column);
149
+ const shown = !table.view.columns.hidden.includes(field);
150
+ const pin = table.view.columns.pinned[field];
151
+ const dropped = shown && table.droppedFields.includes(field);
152
+ const note = pin ? this.pinnedLabel : dropped ? this.droppedLabel : '';
153
+ const pinName = pin === 'start' ? 'pinEndLabel' : pin === 'end' ? 'unpinLabel' : 'pinStartLabel';
154
+ const icon = pin === 'end' ? pushPinSlash : pushPin;
155
+ return html `<li
156
+ part="item${this.dragging === field ? ' item-dragging' : ''}${shown ? '' : ' item-hidden'}"
157
+ data-field=${field}
158
+ draggable="true"
159
+ @dragstart=${(event) => this.handleDragStart(event, field)}
160
+ @dragend=${() => (this.dragging = undefined)}
161
+ @dragover=${this.handleDragOver}
162
+ @drop=${(event) => this.handleDrop(event, field)}
163
+ @keydown=${(event) => this.handleKey(event, field)}
164
+ >
165
+ <button part="grip" type="button" aria-label=${formatWords(this, 'moveLabel', { name })}
166
+ ><svg aria-hidden="true" fill="currentColor" part="grip-mark" viewBox=${dotsSixVertical.viewBox}>${unsafeSVG(dotsSixVertical.content)}</svg></button
167
+ ><label part="name"
168
+ ><input
169
+ part="checkbox"
170
+ type="checkbox"
171
+ .checked=${shown}
172
+ ?disabled=${shown && onlyShown}
173
+ @change=${(event) => this.toggleColumn(field, event.target.checked)}
174
+ />${name}</label
175
+ >${note ? html `<span part="note">${note}</span>` : nothing}<button
176
+ part="pin${pin ? ' pin-pinned' : ''}"
177
+ type="button"
178
+ aria-label=${formatWords(this, pinName, { name })}
179
+ aria-pressed=${pin ? 'true' : 'false'}
180
+ @click=${() => this.pinColumn(field, nextPin(pin))}
181
+ ><svg aria-hidden="true" fill="currentColor" part="pin-mark" viewBox=${icon.viewBox}>${unsafeSVG(icon.content)}</svg></button>
182
+ </li>`;
183
+ }
184
+ render() {
185
+ const table = this.table;
186
+ const columns = table ? this.columns(table) : [];
187
+ const shownCount = table
188
+ ? columns.filter((column) => !table.view.columns.hidden.includes(column.field)).length
189
+ : 0;
190
+ return html `<div part="header">
191
+ <span part="title" id="title">${this.label || this.fallbackLabel}</span>
192
+ <button part="reset" type="button" @click=${() => this.reset()}>${this.resetLabel}</button>
193
+ </div>
194
+ <ul part="list" aria-labelledby="title">
195
+ ${table
196
+ ? repeat(columns, (column) => column.field, (column) => this.renderItem(table, column, shownCount <= 1))
197
+ : nothing}
198
+ </ul>
199
+ <span part="live" aria-live="polite">${this.said}</span>`;
200
+ }
201
+ };
202
+ __decorate([
203
+ words,
204
+ property({ attribute: 'dropped-label' })
205
+ ], HelixHeadlessColumnManager.prototype, "droppedLabel", void 0);
206
+ __decorate([
207
+ words,
208
+ property({ attribute: 'fallback-label' })
209
+ ], HelixHeadlessColumnManager.prototype, "fallbackLabel", void 0);
210
+ __decorate([
211
+ property()
212
+ ], HelixHeadlessColumnManager.prototype, "for", void 0);
213
+ __decorate([
214
+ property()
215
+ ], HelixHeadlessColumnManager.prototype, "label", void 0);
216
+ __decorate([
217
+ words,
218
+ property({ attribute: 'moved-label' })
219
+ ], HelixHeadlessColumnManager.prototype, "movedLabel", void 0);
220
+ __decorate([
221
+ words,
222
+ property({ attribute: 'move-label' })
223
+ ], HelixHeadlessColumnManager.prototype, "moveLabel", void 0);
224
+ __decorate([
225
+ words,
226
+ property({ attribute: 'pin-end-label' })
227
+ ], HelixHeadlessColumnManager.prototype, "pinEndLabel", void 0);
228
+ __decorate([
229
+ words,
230
+ property({ attribute: 'pinned-label' })
231
+ ], HelixHeadlessColumnManager.prototype, "pinnedLabel", void 0);
232
+ __decorate([
233
+ words,
234
+ property({ attribute: 'pin-start-label' })
235
+ ], HelixHeadlessColumnManager.prototype, "pinStartLabel", void 0);
236
+ __decorate([
237
+ words,
238
+ property({ attribute: 'reset-label' })
239
+ ], HelixHeadlessColumnManager.prototype, "resetLabel", void 0);
240
+ __decorate([
241
+ words,
242
+ property({ attribute: 'unpin-label' })
243
+ ], HelixHeadlessColumnManager.prototype, "unpinLabel", void 0);
244
+ __decorate([
245
+ state()
246
+ ], HelixHeadlessColumnManager.prototype, "said", void 0);
247
+ __decorate([
248
+ state()
249
+ ], HelixHeadlessColumnManager.prototype, "dragging", void 0);
250
+ HelixHeadlessColumnManager = __decorate([
251
+ customElement('helix-headless-column-manager')
252
+ ], HelixHeadlessColumnManager);
253
+ export { HelixHeadlessColumnManager };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * How a tool bound to a Data Table by `for` finds the table and hears it
3
+ * change: the Column Manager, the Quick Filters, the Table Export, the
4
+ * Selection Bar and the View Drawer.
5
+ *
6
+ * **By shape, and this module registers nothing.** A tool reads the table
7
+ * through the methods it calls, so a page that writes a tool and a table
8
+ * imports both, and a tool's entry does not carry the table's code.
9
+ */
10
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
11
+ import type { DataTableView, Facet, PartialView } from './view.js';
12
+ /** One column of a bound table, as a tool reads it. */
13
+ export interface ToolColumn extends HTMLElement {
14
+ readonly field: string;
15
+ readonly filterable: boolean;
16
+ minTableWidth: string;
17
+ readonly shown: boolean;
18
+ readonly sortable: boolean;
19
+ readonly type?: string | undefined;
20
+ }
21
+ /** What a tool needs of the table it is bound to. */
22
+ export interface ToolTable extends HTMLElement, ReactiveControllerHost {
23
+ /** The fields left out at the table's width, for their `min-table-width`. */
24
+ readonly droppedFields: readonly string[];
25
+ /** Every row before the search and the filters narrow them. */
26
+ readonly everyRowCount: number;
27
+ facetsOf(field: string): Facet[];
28
+ /**
29
+ * How many rows a partial view would show, from the rows the table holds,
30
+ * or nothing in `server` mode, where the table holds one page.
31
+ */
32
+ countView(part: PartialView): number | undefined;
33
+ /** How many rows pass the search and the filters. */
34
+ readonly matched: number;
35
+ requestView(next: PartialView): boolean;
36
+ /** The keys of the selected rows, separated by commas. */
37
+ selected: string;
38
+ selectRows(keys: readonly string[]): boolean;
39
+ /** The sort order, as `field:direction`. */
40
+ sort: string;
41
+ readonly tableColumns: readonly ToolColumn[];
42
+ readonly view: DataTableView;
43
+ }
44
+ /** Whether an element is a Data Table a tool can bind to. */
45
+ export declare const isToolTable: (element: Element | null) => element is ToolTable;
46
+ /** A column's name as a reader sees it: its heading, or its field where it has none. */
47
+ export declare const columnName: (column: ToolColumn) => string;
48
+ /** The host a binding serves: an element with a `for`. */
49
+ type BoundHost = ReactiveControllerHost & HTMLElement & {
50
+ for: string;
51
+ };
52
+ /**
53
+ * Finds the table a tool's `for` names, in the tool's own tree, and asks the
54
+ * tool to draw again whenever the table does.
55
+ *
56
+ * **Looked up on every read**, so a table defined after the tool, or one that
57
+ * replaces another under the same id, is found the next time the tool draws.
58
+ *
59
+ * **A controller on the table, and no events.** A page that sets `view` or
60
+ * `selected` fires nothing, and a table that leaves a column out at a narrow
61
+ * width fires nothing either, and each is something a tool shows. So the
62
+ * binding adds a controller to the table, whose `hostUpdated` runs after every
63
+ * update the table makes, as Checkbox Group hears its boxes.
64
+ */
65
+ export declare class TableBinding implements ReactiveController {
66
+ private readonly host;
67
+ private heard;
68
+ /** Whether the tool has drawn once, after which it looks for the table. */
69
+ private drawn;
70
+ /** What the binding adds to the table it follows. */
71
+ private readonly watcher;
72
+ constructor(host: BoundHost);
73
+ /**
74
+ * The table, once it is in the tree and defined, or nothing. Without a
75
+ * `for`, a tool written inside a table, as a Selection Bar in its
76
+ * `selection` slot is, takes that table.
77
+ */
78
+ get table(): ToolTable | null;
79
+ hostConnected(): void;
80
+ hostDisconnected(): void;
81
+ hostUpdated(): void;
82
+ private listen;
83
+ private follow;
84
+ }
85
+ export {};
@@ -0,0 +1,58 @@
1
+ export const isToolTable = (element) => element !== null &&
2
+ typeof element.requestView === 'function' &&
3
+ typeof element.countView === 'function';
4
+ export const columnName = (column) => column.textContent?.trim() || column.field;
5
+ export class TableBinding {
6
+ constructor(host) {
7
+ this.host = host;
8
+ this.heard = null;
9
+ this.drawn = false;
10
+ this.watcher = {
11
+ hostUpdated: () => this.host.requestUpdate(),
12
+ };
13
+ host.addController(this);
14
+ }
15
+ get table() {
16
+ if (typeof document === 'undefined' || !this.drawn) {
17
+ return null;
18
+ }
19
+ if (this.host.for === '') {
20
+ const parent = this.host.parentElement;
21
+ return isToolTable(parent) ? parent : null;
22
+ }
23
+ const scope = this.host.getRootNode();
24
+ const found = scope.getElementById?.(this.host.for) ?? null;
25
+ return isToolTable(found) ? found : null;
26
+ }
27
+ hostConnected() {
28
+ this.listen();
29
+ if (!this.table && this.host.for !== '' && typeof customElements !== 'undefined') {
30
+ const scope = this.host.getRootNode();
31
+ const tag = scope.getElementById?.(this.host.for)?.localName;
32
+ if (tag?.includes('-')) {
33
+ customElements.whenDefined(tag).then(() => this.host.requestUpdate());
34
+ }
35
+ }
36
+ }
37
+ hostDisconnected() {
38
+ this.follow(null);
39
+ }
40
+ hostUpdated() {
41
+ this.drawn = true;
42
+ this.listen();
43
+ }
44
+ listen() {
45
+ this.follow(this.table);
46
+ }
47
+ follow(table) {
48
+ if (table === this.heard) {
49
+ return;
50
+ }
51
+ this.heard?.removeController(this.watcher);
52
+ table?.addController(this.watcher);
53
+ this.heard = table;
54
+ if (table) {
55
+ this.host.requestUpdate();
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Editing a Data Table's cells: reading what a reader typed as the column's
3
+ * type, checking it against the column's rules, and writing it into a row.
4
+ *
5
+ * No DOM in it, so the pure spec covers it directly. The table owns the keys,
6
+ * the events and the drawing.
7
+ */
8
+ import type { ColumnType } from '../table/column-type.js';
9
+ /** The rules a column sets on what its cells may hold. */
10
+ export interface EditRules {
11
+ /** The largest value: a number, or a date as `YYYY-MM-DD`. */
12
+ max?: string | undefined;
13
+ /** The smallest value. */
14
+ min?: string | undefined;
15
+ /** A pattern a text value matches whole, as in an input's `pattern`. */
16
+ pattern?: string | undefined;
17
+ /** Whether a cell may be left empty. */
18
+ required?: boolean | undefined;
19
+ }
20
+ /** Which rule a value broke, with what the words need. */
21
+ export type EditProblem = {
22
+ kind: 'max';
23
+ max: string;
24
+ } | {
25
+ kind: 'min';
26
+ min: string;
27
+ } | {
28
+ kind: 'number';
29
+ } | {
30
+ kind: 'pattern';
31
+ } | {
32
+ kind: 'required';
33
+ };
34
+ /**
35
+ * Reads what a reader typed as the column's type: a number for a number
36
+ * column, `true` or `false` for a boolean, and text, a date as text, otherwise.
37
+ * An empty number is `null`. Text that is not a number stays text, so the
38
+ * check can say so.
39
+ */
40
+ export declare const readEdit: (value: unknown, type: ColumnType) => unknown;
41
+ /** The first rule a value breaks, or nothing where it keeps them all. */
42
+ export declare const checkEdit: (value: unknown, type: ColumnType, rules: EditRules) => EditProblem | undefined;
43
+ /**
44
+ * A copy of a row with one field set. A dot path sets a nested value, copying
45
+ * each object on the way, so the row a page handed over is never changed.
46
+ */
47
+ export declare const withValue: (row: Readonly<Record<string, unknown>>, field: string, value: unknown) => Record<string, unknown>;
@@ -0,0 +1,60 @@
1
+ const blank = (value) => value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
2
+ export const readEdit = (value, type) => {
3
+ if (type === 'number') {
4
+ if (typeof value === 'number') {
5
+ return value;
6
+ }
7
+ if (blank(value)) {
8
+ return null;
9
+ }
10
+ const number = Number(String(value).replaceAll(',', ''));
11
+ return Number.isNaN(number) ? String(value) : number;
12
+ }
13
+ if (type === 'boolean') {
14
+ return value === true || value === 'true';
15
+ }
16
+ return value === undefined || value === null ? '' : value;
17
+ };
18
+ export const checkEdit = (value, type, rules) => {
19
+ if (blank(value)) {
20
+ return rules.required ? { kind: 'required' } : undefined;
21
+ }
22
+ if (type === 'number') {
23
+ if (typeof value !== 'number') {
24
+ return { kind: 'number' };
25
+ }
26
+ if (rules.min !== undefined && rules.min !== '' && value < Number(rules.min)) {
27
+ return { kind: 'min', min: rules.min };
28
+ }
29
+ if (rules.max !== undefined && rules.max !== '' && value > Number(rules.max)) {
30
+ return { kind: 'max', max: rules.max };
31
+ }
32
+ return undefined;
33
+ }
34
+ if (type === 'date') {
35
+ const text = String(value);
36
+ if (rules.min && text < rules.min) {
37
+ return { kind: 'min', min: rules.min };
38
+ }
39
+ if (rules.max && text > rules.max) {
40
+ return { kind: 'max', max: rules.max };
41
+ }
42
+ return undefined;
43
+ }
44
+ if (rules.pattern && !new RegExp(`^(?:${rules.pattern})$`, 'v').test(String(value))) {
45
+ return { kind: 'pattern' };
46
+ }
47
+ return undefined;
48
+ };
49
+ export const withValue = (row, field, value) => {
50
+ const [head, ...rest] = field.split('.');
51
+ const key = head;
52
+ if (rest.length === 0) {
53
+ return { ...row, [key]: value };
54
+ }
55
+ const inner = row[key];
56
+ return {
57
+ ...row,
58
+ [key]: withValue(inner && typeof inner === 'object' ? inner : {}, rest.join('.'), value),
59
+ };
60
+ };
@@ -0,0 +1,16 @@
1
+ import type { CellCommitDetail } from './details.js';
2
+ /**
3
+ * A reader is saving a cell's new value, by leaving the cell, with Enter or
4
+ * Tab, or by toggling a boolean.
5
+ *
6
+ * Cancelable: cancel it to keep the old value. To check the value on your
7
+ * server first, pass the check to `detail.waitUntil`: the cell shows that it
8
+ * is saving until the check settles, and a message it resolves to refuses
9
+ * the value.
10
+ *
11
+ * @followedBy helix-cell-commit
12
+ */
13
+ export declare class HelixBeforeCellCommitEvent extends CustomEvent<CellCommitDetail> {
14
+ static readonly eventName = "helix-before-cell-commit";
15
+ constructor(detail: CellCommitDetail);
16
+ }
@@ -0,0 +1,11 @@
1
+ export class HelixBeforeCellCommitEvent extends CustomEvent {
2
+ static { this.eventName = 'helix-before-cell-commit'; }
3
+ constructor(detail) {
4
+ super(HelixBeforeCellCommitEvent.eventName, {
5
+ bubbles: true,
6
+ cancelable: true,
7
+ composed: true,
8
+ detail,
9
+ });
10
+ }
11
+ }