@mndw/ui 0.0.0-stage → 0.1.1

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 (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +674 -2
  3. package/dist/button/button.d.ts +27 -0
  4. package/dist/button/button.d.ts.map +1 -0
  5. package/dist/button/button.js +147 -0
  6. package/dist/button/button.js.map +1 -0
  7. package/dist/charts/bar-chart.d.ts +33 -0
  8. package/dist/charts/bar-chart.d.ts.map +1 -0
  9. package/dist/charts/bar-chart.js +235 -0
  10. package/dist/charts/bar-chart.js.map +1 -0
  11. package/dist/charts/chart-frame-controller.d.ts +23 -0
  12. package/dist/charts/chart-frame-controller.d.ts.map +1 -0
  13. package/dist/charts/chart-frame-controller.js +66 -0
  14. package/dist/charts/chart-frame-controller.js.map +1 -0
  15. package/dist/charts/chart-frame.d.ts +20 -0
  16. package/dist/charts/chart-frame.d.ts.map +1 -0
  17. package/dist/charts/chart-frame.js +95 -0
  18. package/dist/charts/chart-frame.js.map +1 -0
  19. package/dist/charts/chart-types.d.ts +67 -0
  20. package/dist/charts/chart-types.d.ts.map +1 -0
  21. package/dist/charts/chart-types.js +2 -0
  22. package/dist/charts/chart-types.js.map +1 -0
  23. package/dist/charts/chart-utils.d.ts +17 -0
  24. package/dist/charts/chart-utils.d.ts.map +1 -0
  25. package/dist/charts/chart-utils.js +118 -0
  26. package/dist/charts/chart-utils.js.map +1 -0
  27. package/dist/charts/heat-strip.d.ts +43 -0
  28. package/dist/charts/heat-strip.d.ts.map +1 -0
  29. package/dist/charts/heat-strip.js +269 -0
  30. package/dist/charts/heat-strip.js.map +1 -0
  31. package/dist/charts/line-chart.d.ts +40 -0
  32. package/dist/charts/line-chart.d.ts.map +1 -0
  33. package/dist/charts/line-chart.js +307 -0
  34. package/dist/charts/line-chart.js.map +1 -0
  35. package/dist/charts/sparkline-geometry.d.ts +21 -0
  36. package/dist/charts/sparkline-geometry.d.ts.map +1 -0
  37. package/dist/charts/sparkline-geometry.js +31 -0
  38. package/dist/charts/sparkline-geometry.js.map +1 -0
  39. package/dist/charts/sparkline.d.ts +56 -0
  40. package/dist/charts/sparkline.d.ts.map +1 -0
  41. package/dist/charts/sparkline.js +303 -0
  42. package/dist/charts/sparkline.js.map +1 -0
  43. package/dist/checkbox/checkbox.d.ts +46 -0
  44. package/dist/checkbox/checkbox.d.ts.map +1 -0
  45. package/dist/checkbox/checkbox.js +243 -0
  46. package/dist/checkbox/checkbox.js.map +1 -0
  47. package/dist/field/field.d.ts +61 -0
  48. package/dist/field/field.d.ts.map +1 -0
  49. package/dist/field/field.js +359 -0
  50. package/dist/field/field.js.map +1 -0
  51. package/dist/focus.d.ts +24 -0
  52. package/dist/focus.d.ts.map +1 -0
  53. package/dist/focus.js +226 -0
  54. package/dist/focus.js.map +1 -0
  55. package/dist/forms/form-associated.d.ts +39 -0
  56. package/dist/forms/form-associated.d.ts.map +1 -0
  57. package/dist/forms/form-associated.js +124 -0
  58. package/dist/forms/form-associated.js.map +1 -0
  59. package/dist/forms/text-control.d.ts +83 -0
  60. package/dist/forms/text-control.d.ts.map +1 -0
  61. package/dist/forms/text-control.js +238 -0
  62. package/dist/forms/text-control.js.map +1 -0
  63. package/dist/i18n/en.json +43 -0
  64. package/dist/i18n/ru.json +43 -0
  65. package/dist/i18n.d.ts +7 -0
  66. package/dist/i18n.d.ts.map +1 -0
  67. package/dist/i18n.js +65 -0
  68. package/dist/i18n.js.map +1 -0
  69. package/dist/icon/generated/names.d.ts +4 -0
  70. package/dist/icon/generated/names.d.ts.map +1 -0
  71. package/dist/icon/generated/names.js +39 -0
  72. package/dist/icon/generated/names.js.map +1 -0
  73. package/dist/icon/icon.d.ts +26 -0
  74. package/dist/icon/icon.d.ts.map +1 -0
  75. package/dist/icon/icon.js +74 -0
  76. package/dist/icon/icon.js.map +1 -0
  77. package/dist/icon/sprite-config.d.ts +4 -0
  78. package/dist/icon/sprite-config.d.ts.map +1 -0
  79. package/dist/icon/sprite-config.js +24 -0
  80. package/dist/icon/sprite-config.js.map +1 -0
  81. package/dist/icons.svg +189 -0
  82. package/dist/index.d.ts +59 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +105 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/input/input.d.ts +71 -0
  87. package/dist/input/input.d.ts.map +1 -0
  88. package/dist/input/input.js +304 -0
  89. package/dist/input/input.js.map +1 -0
  90. package/dist/locale-controller.d.ts +19 -0
  91. package/dist/locale-controller.d.ts.map +1 -0
  92. package/dist/locale-controller.js +29 -0
  93. package/dist/locale-controller.js.map +1 -0
  94. package/dist/localized-property.d.ts +11 -0
  95. package/dist/localized-property.d.ts.map +1 -0
  96. package/dist/localized-property.js +144 -0
  97. package/dist/localized-property.js.map +1 -0
  98. package/dist/overlay-adapter.d.ts +4 -0
  99. package/dist/overlay-adapter.d.ts.map +1 -0
  100. package/dist/overlay-adapter.js +72 -0
  101. package/dist/overlay-adapter.js.map +1 -0
  102. package/dist/overlay.d.ts +24 -0
  103. package/dist/overlay.d.ts.map +1 -0
  104. package/dist/overlay.js +210 -0
  105. package/dist/overlay.js.map +1 -0
  106. package/dist/position/position.d.ts +56 -0
  107. package/dist/position/position.d.ts.map +1 -0
  108. package/dist/position/position.js +194 -0
  109. package/dist/position/position.js.map +1 -0
  110. package/dist/scroll-area/scroll-area.d.ts +47 -0
  111. package/dist/scroll-area/scroll-area.d.ts.map +1 -0
  112. package/dist/scroll-area/scroll-area.js +332 -0
  113. package/dist/scroll-area/scroll-area.js.map +1 -0
  114. package/dist/segmented/segment.d.ts +23 -0
  115. package/dist/segmented/segment.d.ts.map +1 -0
  116. package/dist/segmented/segment.js +75 -0
  117. package/dist/segmented/segment.js.map +1 -0
  118. package/dist/segmented/segmented.d.ts +55 -0
  119. package/dist/segmented/segmented.d.ts.map +1 -0
  120. package/dist/segmented/segmented.js +265 -0
  121. package/dist/segmented/segmented.js.map +1 -0
  122. package/dist/select/option-model.d.ts +8 -0
  123. package/dist/select/option-model.d.ts.map +1 -0
  124. package/dist/select/option-model.js +11 -0
  125. package/dist/select/option-model.js.map +1 -0
  126. package/dist/select/option.d.ts +23 -0
  127. package/dist/select/option.d.ts.map +1 -0
  128. package/dist/select/option.js +58 -0
  129. package/dist/select/option.js.map +1 -0
  130. package/dist/select/select-panel.d.ts +35 -0
  131. package/dist/select/select-panel.d.ts.map +1 -0
  132. package/dist/select/select-panel.js +212 -0
  133. package/dist/select/select-panel.js.map +1 -0
  134. package/dist/select/select-popover.d.ts +32 -0
  135. package/dist/select/select-popover.d.ts.map +1 -0
  136. package/dist/select/select-popover.js +73 -0
  137. package/dist/select/select-popover.js.map +1 -0
  138. package/dist/select/select-position.d.ts +2 -0
  139. package/dist/select/select-position.d.ts.map +1 -0
  140. package/dist/select/select-position.js +2 -0
  141. package/dist/select/select-position.js.map +1 -0
  142. package/dist/select/select.d.ts +68 -0
  143. package/dist/select/select.d.ts.map +1 -0
  144. package/dist/select/select.js +413 -0
  145. package/dist/select/select.js.map +1 -0
  146. package/dist/slider/slider.d.ts +67 -0
  147. package/dist/slider/slider.d.ts.map +1 -0
  148. package/dist/slider/slider.js +380 -0
  149. package/dist/slider/slider.js.map +1 -0
  150. package/dist/styles/base.d.ts +22 -0
  151. package/dist/styles/base.d.ts.map +1 -0
  152. package/dist/styles/base.js +36 -0
  153. package/dist/styles/base.js.map +1 -0
  154. package/dist/styles.css +266 -0
  155. package/dist/switch/switch.d.ts +41 -0
  156. package/dist/switch/switch.d.ts.map +1 -0
  157. package/dist/switch/switch.js +182 -0
  158. package/dist/switch/switch.js.map +1 -0
  159. package/dist/table/column-menu.d.ts +35 -0
  160. package/dist/table/column-menu.d.ts.map +1 -0
  161. package/dist/table/column-menu.js +150 -0
  162. package/dist/table/column-menu.js.map +1 -0
  163. package/dist/table/table-builder.d.ts +15 -0
  164. package/dist/table/table-builder.d.ts.map +1 -0
  165. package/dist/table/table-builder.js +7 -0
  166. package/dist/table/table-builder.js.map +1 -0
  167. package/dist/table/table-cells.d.ts +22 -0
  168. package/dist/table/table-cells.d.ts.map +1 -0
  169. package/dist/table/table-cells.js +127 -0
  170. package/dist/table/table-cells.js.map +1 -0
  171. package/dist/table/table-focus.d.ts +5 -0
  172. package/dist/table/table-focus.d.ts.map +1 -0
  173. package/dist/table/table-focus.js +10 -0
  174. package/dist/table/table-focus.js.map +1 -0
  175. package/dist/table/table-geometry.d.ts +25 -0
  176. package/dist/table/table-geometry.d.ts.map +1 -0
  177. package/dist/table/table-geometry.js +36 -0
  178. package/dist/table/table-geometry.js.map +1 -0
  179. package/dist/table/table-state.d.ts +35 -0
  180. package/dist/table/table-state.d.ts.map +1 -0
  181. package/dist/table/table-state.js +265 -0
  182. package/dist/table/table-state.js.map +1 -0
  183. package/dist/table/table-test-geometry.d.ts +29 -0
  184. package/dist/table/table-test-geometry.d.ts.map +1 -0
  185. package/dist/table/table-test-geometry.js +108 -0
  186. package/dist/table/table-test-geometry.js.map +1 -0
  187. package/dist/table/table-types.d.ts +142 -0
  188. package/dist/table/table-types.d.ts.map +1 -0
  189. package/dist/table/table-types.js +8 -0
  190. package/dist/table/table-types.js.map +1 -0
  191. package/dist/table/table-virtualizer.d.ts +62 -0
  192. package/dist/table/table-virtualizer.d.ts.map +1 -0
  193. package/dist/table/table-virtualizer.js +289 -0
  194. package/dist/table/table-virtualizer.js.map +1 -0
  195. package/dist/table/table.d.ts +155 -0
  196. package/dist/table/table.d.ts.map +1 -0
  197. package/dist/table/table.js +1417 -0
  198. package/dist/table/table.js.map +1 -0
  199. package/dist/tabs/tab-panel.d.ts +21 -0
  200. package/dist/tabs/tab-panel.d.ts.map +1 -0
  201. package/dist/tabs/tab-panel.js +48 -0
  202. package/dist/tabs/tab-panel.js.map +1 -0
  203. package/dist/tabs/tab.d.ts +21 -0
  204. package/dist/tabs/tab.d.ts.map +1 -0
  205. package/dist/tabs/tab.js +80 -0
  206. package/dist/tabs/tab.js.map +1 -0
  207. package/dist/tabs/tabs.d.ts +52 -0
  208. package/dist/tabs/tabs.d.ts.map +1 -0
  209. package/dist/tabs/tabs.js +248 -0
  210. package/dist/tabs/tabs.js.map +1 -0
  211. package/dist/testing/harness.d.ts +12 -0
  212. package/dist/testing/harness.d.ts.map +1 -0
  213. package/dist/testing/harness.js +31 -0
  214. package/dist/testing/harness.js.map +1 -0
  215. package/dist/testing/index.d.ts +4 -0
  216. package/dist/testing/index.d.ts.map +1 -0
  217. package/dist/testing/index.js +19 -0
  218. package/dist/testing/index.js.map +1 -0
  219. package/dist/testing/setup.d.ts +2 -0
  220. package/dist/testing/setup.d.ts.map +1 -0
  221. package/dist/testing/setup.js +9 -0
  222. package/dist/testing/setup.js.map +1 -0
  223. package/dist/textarea/textarea.d.ts +59 -0
  224. package/dist/textarea/textarea.d.ts.map +1 -0
  225. package/dist/textarea/textarea.js +227 -0
  226. package/dist/textarea/textarea.js.map +1 -0
  227. package/dist/tokens-required.d.ts +3 -0
  228. package/dist/tokens-required.d.ts.map +1 -0
  229. package/dist/tokens-required.js +62 -0
  230. package/dist/tokens-required.js.map +1 -0
  231. package/dist/tooltip/tooltip.d.ts +52 -0
  232. package/dist/tooltip/tooltip.d.ts.map +1 -0
  233. package/dist/tooltip/tooltip.js +240 -0
  234. package/dist/tooltip/tooltip.js.map +1 -0
  235. package/package.json +75 -3
@@ -0,0 +1,1417 @@
1
+ import { LitElement, css, html, nothing } from 'lit';
2
+ import { repeat } from 'lit/directives/repeat.js';
3
+ import { getMndwUiText } from '../i18n.js';
4
+ import { LocaleController } from '../locale-controller.js';
5
+ import { getOverlayProvider } from '../overlay.js';
6
+ import { focusRing, hostTypography } from '../styles/base.js';
7
+ import { CellRegistry } from './table-cells.js';
8
+ import { resolveFocusedRowKey } from './table-focus.js';
9
+ import { createDomTableGeometryProvider, lookupTableMeasurementTarget, registerTableMeasurementTarget, } from './table-geometry.js';
10
+ import { TableVirtualizer } from './table-virtualizer.js';
11
+ import { MNDW_COLUMN_MENU_CHECK_EVENT, MNDW_COLUMN_MENU_TAG, } from './column-menu.js';
12
+ import { ColumnVisibilityState, effectiveSort, nextSortState, resolveCellValue, resolveRowKey, selectAllState, sortRows, toggleKey, toggleSelectAll, validateColumns, validateRows, } from './table-state.js';
13
+ import { DETAIL_COL_ID, MNDW_COLUMN_VISIBILITY_CHANGE_EVENT, MNDW_ERROR_EVENT, MNDW_ROW_EXPAND_EVENT, MNDW_ROW_REORDER_EVENT, MNDW_SELECTION_CHANGE_EVENT, MNDW_SORT_CHANGE_EVENT, } from './table-types.js';
14
+ export const MNDW_TABLE_TAG = 'mndw-table';
15
+ const EVENT_OPTIONS = { bubbles: true, composed: true, cancelable: false };
16
+ function formatTemplate(template, values) {
17
+ return template.replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ''));
18
+ }
19
+ function classAttr(list) {
20
+ return list.length > 0 ? list.join(' ') : nothing;
21
+ }
22
+ function defaultLabels() {
23
+ return {
24
+ selectRow: (rowName) => formatTemplate(getMndwUiText('table.selectRow'), { rowName }),
25
+ selectAll: getMndwUiText('table.selectAll'),
26
+ sortBy: (columnLabel) => formatTemplate(getMndwUiText('table.sortBy'), { column: columnLabel }),
27
+ columnMenu: getMndwUiText('table.columnMenu'),
28
+ rowFallback: (index1Based) => formatTemplate(getMndwUiText('table.rowFallback'), { index: index1Based }),
29
+ reordered: (rowName, pos, total) => formatTemplate(getMndwUiText('table.reordered'), { rowName, pos, total }),
30
+ invalidData: getMndwUiText('table.invalidData'),
31
+ expandRow: (rowName) => `Expand ${rowName}`,
32
+ collapseRow: (rowName) => `Collapse ${rowName}`,
33
+ };
34
+ }
35
+ export class MndwTable extends LitElement {
36
+ static properties = {
37
+ columns: { type: Array, attribute: false },
38
+ rows: { type: Array, attribute: false },
39
+ rowKey: { type: String, attribute: 'row-key' },
40
+ virtual: { type: Boolean, reflect: true },
41
+ estimatedRowHeight: { type: Number, attribute: 'estimated-row-height', reflect: true },
42
+ overscan: { type: Number, attribute: 'overscan', reflect: true },
43
+ selectable: { type: Boolean, reflect: true },
44
+ selected: { type: Array, attribute: false },
45
+ reorderable: { type: Boolean, reflect: true },
46
+ expandable: { type: Boolean, attribute: false },
47
+ expandOn: { type: String, attribute: 'expand-on' },
48
+ toggleCell: { type: String, attribute: 'toggle-cell' },
49
+ toggleAfterColumn: { type: String, attribute: 'toggle-after-column' },
50
+ expanded: { type: Array, attribute: false },
51
+ expandedRenderer: { type: Object, attribute: false },
52
+ sort: { type: Object, attribute: false },
53
+ sortMode: { type: String, attribute: 'sort-mode' },
54
+ hiddenColumns: { type: Array, attribute: false },
55
+ columnMenu: { type: Boolean, attribute: false },
56
+ columnMenuPanelClass: { type: String, attribute: 'column-menu-panel-class' },
57
+ caption: { type: String },
58
+ rowLabel: { type: Object, attribute: false },
59
+ labels: { type: Object, attribute: false },
60
+ emptyLabel: { type: String, attribute: 'empty-label' },
61
+ layout: { type: String, reflect: true },
62
+ minWidth: { type: String, attribute: 'min-width' },
63
+ stickyHeader: { type: Boolean, attribute: 'sticky-header', reflect: true },
64
+ };
65
+ static styles = css `
66
+ :host {
67
+ ${hostTypography}
68
+ display: block;
69
+ color: var(--mndw-text);
70
+ }
71
+
72
+ [part='viewport'] {
73
+ overflow: auto;
74
+ min-height: 0;
75
+ overflow-anchor: none;
76
+ scroll-behavior: auto !important;
77
+ scrollbar-gutter: stable;
78
+ /* Keep native table scrolling visually aligned with <mndw-scroll-area>'s custom scrollbar. */
79
+ scrollbar-width: thin;
80
+ scrollbar-color: var(--mndw-scrollbar-thumb) var(--mndw-scrollbar-track);
81
+ }
82
+
83
+ [part='viewport']::-webkit-scrollbar {
84
+ width: var(--mndw-scrollbar-size);
85
+ height: var(--mndw-scrollbar-size);
86
+ }
87
+
88
+ [part='viewport']::-webkit-scrollbar-track {
89
+ background: var(--mndw-scrollbar-track);
90
+ }
91
+
92
+ [part='viewport']::-webkit-scrollbar-thumb {
93
+ border: var(--mndw-focus-w) solid var(--mndw-scrollbar-track);
94
+ border-radius: var(--mndw-scrollbar-radius);
95
+ background: var(--mndw-scrollbar-thumb);
96
+ }
97
+
98
+ [part='viewport']::-webkit-scrollbar-thumb:hover {
99
+ background: var(--mndw-scrollbar-thumb-hover);
100
+ }
101
+
102
+ [part='viewport']::-webkit-scrollbar-corner {
103
+ background: var(--mndw-scrollbar-track);
104
+ }
105
+
106
+ [part='table'] {
107
+ width: 100%;
108
+ border-collapse: collapse;
109
+ table-layout: fixed;
110
+ }
111
+
112
+ :host([layout='auto']) [part='table'] {
113
+ table-layout: auto;
114
+ width: max-content;
115
+ }
116
+
117
+ :host([virtual][layout='auto']) [part='table'] {
118
+ table-layout: fixed;
119
+ width: 100%;
120
+ }
121
+
122
+ [part='caption'] {
123
+ text-align: start;
124
+ }
125
+
126
+ [part~='header-cell'] {
127
+ text-align: start;
128
+ padding: var(--mndw-space-2);
129
+ border-bottom: 1px solid var(--mndw-border);
130
+ font-size: var(--mndw-text-sm);
131
+ color: var(--mndw-text-muted);
132
+ }
133
+
134
+ [part~='cell'] {
135
+ padding: var(--mndw-space-2);
136
+ border-bottom: 1px solid var(--mndw-border);
137
+ }
138
+
139
+ [part~='select-cell'] {
140
+ width: 2.5rem;
141
+ padding-inline: var(--mndw-space-1);
142
+ text-align: center;
143
+ }
144
+
145
+ [part~='expand-cell'] {
146
+ width: 2.5rem;
147
+ padding-inline: var(--mndw-space-1);
148
+ text-align: center;
149
+ }
150
+
151
+ [part='expand-toggle'] {
152
+ border: 0;
153
+ background: none;
154
+ color: inherit;
155
+ font: inherit;
156
+ cursor: pointer;
157
+ padding: var(--mndw-space-1);
158
+ font-size: var(--mndw-text-lg);
159
+ line-height: 1;
160
+ }
161
+
162
+ [part='expand-toggle']:focus-visible {
163
+ ${focusRing}
164
+ }
165
+
166
+ [part='detail-cell'] {
167
+ padding: 0;
168
+ border-bottom: 1px solid var(--mndw-border);
169
+ }
170
+
171
+ [part='detail-row'] [part='detail-cell'] {
172
+ background: var(--mndw-surface-raised);
173
+ }
174
+
175
+ [part='row']:hover [part~='cell'] {
176
+ background: var(--mndw-surface-hover);
177
+ }
178
+
179
+ .nowrap {
180
+ white-space: nowrap;
181
+ }
182
+
183
+ .pinned {
184
+ position: sticky;
185
+ z-index: 1;
186
+ background: var(--mndw-surface);
187
+ }
188
+
189
+ [part~='header-cell'].pinned {
190
+ z-index: 2;
191
+ }
192
+
193
+ .pinned-last {
194
+ border-inline-end: 1px solid var(--mndw-border);
195
+ }
196
+
197
+ :host([sticky-header]) [part~='header-cell'] {
198
+ position: sticky;
199
+ top: 0;
200
+ z-index: 2;
201
+ background: var(--mndw-surface);
202
+ }
203
+
204
+ :host([sticky-header]) [part~='header-cell'].pinned {
205
+ z-index: 3;
206
+ }
207
+
208
+ [part='sort-indicator'] {
209
+ margin-inline-start: var(--mndw-space-1);
210
+ }
211
+
212
+ [part='drag-handle'] {
213
+ cursor: grab;
214
+ }
215
+
216
+ [part='error'] {
217
+ padding: var(--mndw-space-2);
218
+ color: var(--mndw-danger);
219
+ background: var(--mndw-danger-bg);
220
+ border-radius: var(--mndw-radius-sm);
221
+ margin-bottom: var(--mndw-space-2);
222
+ }
223
+
224
+ [part='empty'] {
225
+ padding: var(--mndw-space-3);
226
+ color: var(--mndw-text-muted);
227
+ text-align: center;
228
+ }
229
+
230
+ [part='badge'] {
231
+ display: inline-flex;
232
+ align-items: center;
233
+ gap: var(--mndw-space-1);
234
+ padding: var(--mndw-space-1) var(--mndw-space-2);
235
+ border-radius: var(--mndw-radius-sm);
236
+ background: var(--mndw-surface-raised);
237
+ color: var(--mndw-text);
238
+ font-size: var(--mndw-text-sm);
239
+ }
240
+
241
+ [part='badge-dot'] {
242
+ width: 0.5rem;
243
+ height: 0.5rem;
244
+ border-radius: 50%;
245
+ }
246
+
247
+ .align-end {
248
+ text-align: end;
249
+ }
250
+
251
+ .align-center {
252
+ text-align: center;
253
+ }
254
+
255
+ .cell-kind-number {
256
+ font-family: var(--mndw-font-mono);
257
+ }
258
+
259
+ .sort-button {
260
+ border: 0;
261
+ background: none;
262
+ color: inherit;
263
+ font: inherit;
264
+ cursor: pointer;
265
+ padding: 0;
266
+ display: inline-flex;
267
+ align-items: center;
268
+ }
269
+
270
+ .sort-button:focus-visible,
271
+ [part='drag-handle']:focus-visible,
272
+ [part='column-menu-trigger']:focus-visible {
273
+ ${focusRing}
274
+ }
275
+ `;
276
+ visibilityState = new ColumnVisibilityState();
277
+ geometryProvider;
278
+ virtualizer = null;
279
+ resizeObserver = null;
280
+ observedElements = new Set();
281
+ observedViewport = null;
282
+ pendingGeometryFrame = null;
283
+ observerAttempted = false;
284
+ warnedInactiveReason = null;
285
+ warnedStickyReason = null;
286
+ pinState = { byKey: new Map(), inactiveReason: null, inactiveColumnId: null };
287
+ lastViewportContentWidth;
288
+ pendingScrollTarget = null;
289
+ expectedProgrammaticScrollTop;
290
+ cellRegistry = null;
291
+ localeController = new LocaleController(this);
292
+ menuLayer = null;
293
+ effectiveColumns = [];
294
+ displayRows = [];
295
+ effectiveHidden = new Set();
296
+ effectiveSortState = null;
297
+ selectedKeySet = new Set();
298
+ lastCellReconcileSignature = null;
299
+ lastExpandedKeys = new Set();
300
+ windowRows = [];
301
+ virtualRange = null;
302
+ violations = [];
303
+ lastViolationSignature = '';
304
+ optimisticOrder = null;
305
+ dragKey = null;
306
+ announceText = '';
307
+ static WIDTH_EPSILON = 1;
308
+ static UTILITY_COL_WIDTH = '2.5rem';
309
+ static PIN_KEYS = {
310
+ expandLead: '__mndw_pin_expandLead',
311
+ select: '__mndw_pin_select',
312
+ drag: '__mndw_pin_drag',
313
+ };
314
+ constructor(geometryProvider) {
315
+ super();
316
+ this.geometryProvider = geometryProvider ?? createDomTableGeometryProvider();
317
+ this.columns = [];
318
+ this.rows = [];
319
+ this.rowKey = 'id';
320
+ this.virtual = false;
321
+ this.estimatedRowHeight = 49;
322
+ this.overscan = 400;
323
+ this.selectable = false;
324
+ this.selected = [];
325
+ this.reorderable = false;
326
+ this.expandable = false;
327
+ this.expandOn = 'toggle';
328
+ this.toggleCell = 'leading';
329
+ this.toggleAfterColumn = undefined;
330
+ this.expanded = [];
331
+ this.expandedRenderer = undefined;
332
+ this.sort = null;
333
+ this.sortMode = 'client';
334
+ this.hiddenColumns = undefined;
335
+ this.columnMenu = true;
336
+ this.columnMenuPanelClass = '';
337
+ this.caption = '';
338
+ this.rowLabel = undefined;
339
+ this.labels = undefined;
340
+ this.emptyLabel = '';
341
+ this.layout = 'fixed';
342
+ this.minWidth = '';
343
+ this.stickyHeader = false;
344
+ this.addEventListener('mndwchange', this.handleCheckboxChange);
345
+ this.addEventListener('click', this.handleClick);
346
+ this.addEventListener('keydown', this.handleKeyDown);
347
+ }
348
+ connectedCallback() {
349
+ super.connectedCallback();
350
+ this.observerAttempted = false;
351
+ this.cellRegistry = new CellRegistry(this);
352
+ this.lastCellReconcileSignature = null;
353
+ }
354
+ disconnectedCallback() {
355
+ this.teardownGeometry();
356
+ this.closeColumnMenu();
357
+ this.cellRegistry?.drain();
358
+ this.cellRegistry = null;
359
+ super.disconnectedCallback();
360
+ }
361
+ willUpdate(changedProperties) {
362
+ if (!this.hasUpdated || changedProperties.size > 0) {
363
+ this.reconcileState(true);
364
+ }
365
+ else {
366
+ this.updateVirtualWindow();
367
+ }
368
+ this.unobserveStaleGeometryTargets();
369
+ }
370
+ reconcileState(forceCellReconcile) {
371
+ const previousSortState = this.effectiveSortState;
372
+ const previousStructureSignature = this.logicalStructureSignature(this.displayRows, this.lastExpandedKeys);
373
+ const anchorBeforeLogicalChange = this.captureCurrentAnchor();
374
+ this.configureGeometryMode();
375
+ this.configureLayoutMode();
376
+ const columnViolations = validateColumns(this.columns);
377
+ const { rows: validRows, violations: rowViolations } = validateRows(this.rows, this.rowKey);
378
+ this.violations = [...columnViolations, ...rowViolations];
379
+ this.emitErrorIfChanged();
380
+ this.effectiveColumns = this.columns
381
+ .filter((column, index, all) => all.findIndex((candidate) => candidate.id === column.id) === index)
382
+ .filter((column) => !column.id.startsWith('__mndw_'));
383
+ this.effectiveHidden = this.visibilityState.effectiveHidden(this.effectiveColumns, this.hiddenColumns);
384
+ this.effectiveSortState = effectiveSort(this.effectiveColumns, this.sort, this.effectiveHidden);
385
+ this.pinState = this.computePinState();
386
+ this.applyStickyInactive(this.pinState);
387
+ const sortChanged = !this.sameSortState(previousSortState, this.effectiveSortState);
388
+ const visibleColumnIds = new Set(this.effectiveColumns.filter((column) => !this.effectiveHidden.has(column.id)).map((column) => column.id));
389
+ if (this.optimisticOrder !== null) {
390
+ this.displayRows = this.optimisticOrder;
391
+ }
392
+ else if (this.sortMode === 'client' && this.effectiveSortState !== null) {
393
+ this.displayRows = sortRows(validRows, this.effectiveColumns, this.effectiveSortState, this.locale());
394
+ }
395
+ else {
396
+ this.displayRows = validRows;
397
+ }
398
+ const expandedKeys = this.expandedSet();
399
+ this.selectedKeySet = new Set(this.selected);
400
+ const structureChanged = previousStructureSignature !== this.logicalStructureSignature(this.displayRows, expandedKeys);
401
+ if (this.isVirtualRenderingActive()) {
402
+ const virtualizer = this.getVirtualizer();
403
+ const keys = this.displayRows.map((row) => resolveRowKey(this.rowKey, row));
404
+ for (const key of this.lastExpandedKeys) {
405
+ if (!expandedKeys.has(key)) {
406
+ virtualizer.clearDetailMeasurement(key);
407
+ }
408
+ }
409
+ virtualizer.configure({
410
+ estimatedRowHeight: this.normalizedEstimatedRowHeight(),
411
+ detailEstimate: 160,
412
+ });
413
+ virtualizer.setRows(keys, expandedKeys);
414
+ this.updateVirtualWindow(false);
415
+ if (sortChanged) {
416
+ const viewport = this.viewportElement();
417
+ const header = this.headerElement();
418
+ if (viewport !== null && header !== null) {
419
+ this.pendingScrollTarget = null;
420
+ this.writeBodyScrollOffset(viewport, header, 0);
421
+ this.updateVirtualWindow(false);
422
+ }
423
+ }
424
+ else if (structureChanged && anchorBeforeLogicalChange !== undefined) {
425
+ const viewport = this.viewportElement();
426
+ const header = this.headerElement();
427
+ if (viewport !== null && header !== null) {
428
+ const currentRange = virtualizer.range(this.bodyScrollOffset(viewport, header), this.geometryProvider.getViewportClientHeight(viewport), this.normalizedOverscan());
429
+ const maxBodyOffset = Math.max(0, currentRange.totalHeight - this.geometryProvider.getViewportClientHeight(viewport));
430
+ const restoredOffset = virtualizer.restoreAnchor(anchorBeforeLogicalChange, maxBodyOffset);
431
+ this.writeBodyScrollOffset(viewport, header, restoredOffset);
432
+ this.updateVirtualWindow(false);
433
+ }
434
+ }
435
+ this.lastExpandedKeys = new Set(expandedKeys);
436
+ }
437
+ else {
438
+ this.virtualRange = null;
439
+ this.windowRows = this.displayRows;
440
+ }
441
+ if (this.pendingScrollTarget !== null
442
+ && !this.displayRows.some((row) => resolveRowKey(this.rowKey, row) === this.pendingScrollTarget?.key)) {
443
+ this.pendingScrollTarget = null;
444
+ }
445
+ this.reconcileVisibleCells(forceCellReconcile, visibleColumnIds);
446
+ }
447
+ updated(_changedProperties) {
448
+ if (!this.isVirtualRenderingActive()) {
449
+ this.teardownGeometry();
450
+ return;
451
+ }
452
+ this.syncGeometryTargets();
453
+ this.scheduleGeometryFrame();
454
+ }
455
+ render() {
456
+ const labels = this.resolveLabels();
457
+ const showEmpty = this.displayRows.length === 0 && this.emptyLabel;
458
+ return html `
459
+ ${this.violations.length > 0 ? html `<div part="error" role="alert">${labels.invalidData}</div>` : nothing}
460
+ ${showEmpty
461
+ ? html `<div part="empty">${this.emptyLabel}</div>`
462
+ : html `
463
+ <div class="mndw-table-viewport" part="viewport" tabindex="-1">
464
+ <table
465
+ part="table"
466
+ style=${this.tableStyle()}
467
+ aria-rowcount=${this.virtual ? this.logicalRowCount() : nothing}
468
+ >
469
+ ${this.caption ? html `<caption part="caption">${this.caption}</caption>` : nothing}
470
+ ${this.renderHeader(labels)}
471
+ <tbody>
472
+ ${this.virtualRange === null ? nothing : this.renderSpacer(this.virtualRange.paddingBefore)}
473
+ ${repeat(this.windowRows, (row) => resolveRowKey(this.rowKey, row), (row, index) => this.renderRow(row, index, labels))}
474
+ ${this.virtualRange === null ? nothing : this.renderSpacer(this.virtualRange.paddingAfter)}
475
+ </tbody>
476
+ </table>
477
+ </div>`}
478
+ <div part="live-region" aria-live="polite">${this.announceText}</div>
479
+ `;
480
+ }
481
+ renderSpacer(height) {
482
+ if (!Number.isFinite(height) || height <= 0) {
483
+ return nothing;
484
+ }
485
+ return html `<tr part="virtual-spacer" aria-hidden="true">
486
+ <td colspan=${this.columnSpan()} style="height: ${height}px; padding: 0; border: 0;"></td>
487
+ </tr>`;
488
+ }
489
+ renderHeader(labels) {
490
+ return html `
491
+ <thead part="header">
492
+ <tr part="header-row" aria-rowindex=${this.virtual ? 1 : nothing}>
493
+ ${this.shouldRenderLeadingToggle() ? this.renderExpandHeaderCell(MndwTable.PIN_KEYS.expandLead) : nothing}
494
+ ${this.selectable
495
+ ? html `<th
496
+ part="header-cell select-cell"
497
+ scope="col"
498
+ class=${classAttr(this.pinClasses(MndwTable.PIN_KEYS.select))}
499
+ style=${this.utilityPinStyle(MndwTable.PIN_KEYS.select)}
500
+ >
501
+ ${this.renderCheckbox({
502
+ ariaLabel: labels.selectAll,
503
+ checked: this.isAllSelected(),
504
+ indeterminate: this.isIndeterminate(),
505
+ selectAll: true,
506
+ })}
507
+ </th>`
508
+ : nothing}
509
+ ${this.reorderable && this.effectiveSortState === null
510
+ ? html `<th
511
+ part="header-cell"
512
+ scope="col"
513
+ class=${classAttr(this.pinClasses(MndwTable.PIN_KEYS.drag))}
514
+ style=${this.utilityPinStyle(MndwTable.PIN_KEYS.drag)}
515
+ ></th>`
516
+ : nothing}
517
+ ${this.effectiveColumns
518
+ .filter((column) => !this.effectiveHidden.has(column.id))
519
+ .map((column) => html `
520
+ ${this.renderHeaderCell(column, labels)}
521
+ ${this.shouldRenderToggleAfter(column.id) ? this.renderExpandHeaderCell() : nothing}
522
+ `)}
523
+ ${this.columnMenu
524
+ ? html `<th part="header-cell" scope="col" class="align-end">
525
+ <button
526
+ part="column-menu-trigger"
527
+ class="sort-button"
528
+ type="button"
529
+ aria-label=${labels.columnMenu}
530
+ ><mndw-icon name="settings"></mndw-icon></button>
531
+ </th>`
532
+ : nothing}
533
+ ${this.shouldRenderTrailingToggle() ? this.renderExpandHeaderCell() : nothing}
534
+ </tr>
535
+ </thead>
536
+ `;
537
+ }
538
+ renderExpandHeaderCell(pinKey) {
539
+ return html `<th
540
+ part="header-cell expand-cell"
541
+ scope="col"
542
+ class=${classAttr(pinKey === undefined ? [] : this.pinClasses(pinKey))}
543
+ style=${pinKey === undefined ? nothing : this.utilityPinStyle(pinKey)}
544
+ ></th>`;
545
+ }
546
+ renderHeaderCell(column, labels) {
547
+ const align = classAttr([...this.alignClassList(column), ...this.pinClasses(column.id)]);
548
+ const style = this.columnStyle(column);
549
+ if (column.sortable !== true) {
550
+ return html `<th part="header-cell" scope="col" class=${align} style=${style}>${column.label}</th>`;
551
+ }
552
+ const direction = this.effectiveSortState?.columnId === column.id ? this.effectiveSortState?.direction : undefined;
553
+ const ariaSort = direction === 'asc' ? 'ascending' : direction === 'desc' ? 'descending' : nothing;
554
+ const indicator = direction === 'asc'
555
+ ? html `<mndw-icon name="arrow-up"></mndw-icon>`
556
+ : direction === 'desc'
557
+ ? html `<mndw-icon name="arrow-down"></mndw-icon>`
558
+ : nothing;
559
+ return html `
560
+ <th part="header-cell" scope="col" class=${align} style=${style} aria-sort=${ariaSort}>
561
+ <button
562
+ class="sort-button"
563
+ type="button"
564
+ data-sort-column=${column.id}
565
+ aria-label=${labels.sortBy(column.label)}
566
+ >${column.label}<span part="sort-indicator">${indicator}</span></button>
567
+ </th>
568
+ `;
569
+ }
570
+ renderRow(row, index, labels) {
571
+ const key = resolveRowKey(this.rowKey, row);
572
+ const isExpanded = this.expandedSet().has(key);
573
+ const detailSlot = this.cellRegistry?.getSlotId(key, DETAIL_COL_ID);
574
+ return html `
575
+ <tr part="row" data-row-key=${key} aria-rowindex=${this.virtual ? this.logicalRowIndex(key, false) : nothing}>
576
+ ${this.shouldRenderLeadingToggle()
577
+ ? this.renderExpandCell(row, index, key, labels, MndwTable.PIN_KEYS.expandLead)
578
+ : nothing}
579
+ ${this.selectable
580
+ ? html `<td
581
+ part="select-cell cell"
582
+ class=${classAttr(this.pinClasses(MndwTable.PIN_KEYS.select))}
583
+ style=${this.utilityPinStyle(MndwTable.PIN_KEYS.select)}
584
+ >
585
+ ${this.renderCheckbox({
586
+ ariaLabel: labels.selectRow(this.rowName(row, index)),
587
+ checked: this.selectedKeySet.has(key),
588
+ indeterminate: false,
589
+ rowKey: key,
590
+ })}
591
+ </td>`
592
+ : nothing}
593
+ ${this.reorderable && this.effectiveSortState === null
594
+ ? html `<td
595
+ part="cell"
596
+ class=${classAttr(this.pinClasses(MndwTable.PIN_KEYS.drag))}
597
+ style=${this.utilityPinStyle(MndwTable.PIN_KEYS.drag)}
598
+ >
599
+ <button
600
+ part="drag-handle"
601
+ type="button"
602
+ data-row-key=${key}
603
+ aria-label=${labels.selectRow(this.rowName(row, index))}
604
+ >⠿</button>
605
+ </td>`
606
+ : nothing}
607
+ ${this.effectiveColumns
608
+ .filter((column) => !this.effectiveHidden.has(column.id))
609
+ .map((column) => html `
610
+ ${this.renderCell(column, row)}
611
+ ${this.shouldRenderToggleAfter(column.id) ? this.renderExpandCell(row, index, key, labels) : nothing}
612
+ `)}
613
+ ${this.columnMenu ? html `<td part="cell"></td>` : nothing}
614
+ ${this.shouldRenderTrailingToggle() ? this.renderExpandCell(row, index, key, labels) : nothing}
615
+ </tr>
616
+ ${this.expandable && isExpanded
617
+ ? html `<tr
618
+ part="detail-row"
619
+ data-row-key=${key}
620
+ aria-rowindex=${this.virtual ? this.logicalRowIndex(key, true) : nothing}
621
+ ><td part="detail-cell" colspan=${this.columnSpan()}>${detailSlot !== undefined
622
+ ? html `<slot name=${detailSlot}></slot>`
623
+ : nothing}</td></tr>`
624
+ : nothing}
625
+ `;
626
+ }
627
+ renderExpandCell(row, index, key, labels, pinKey) {
628
+ const isExpanded = this.expandedSet().has(key);
629
+ const name = this.rowName(row, index);
630
+ return html `<td
631
+ part="cell expand-cell"
632
+ class=${classAttr(pinKey === undefined ? [] : this.pinClasses(pinKey))}
633
+ style=${pinKey === undefined ? nothing : this.utilityPinStyle(pinKey)}
634
+ >
635
+ <button
636
+ part="expand-toggle"
637
+ type="button"
638
+ data-expand-key=${key}
639
+ aria-expanded=${isExpanded ? 'true' : 'false'}
640
+ aria-label=${isExpanded ? labels.collapseRow(name) : labels.expandRow(name)}
641
+ ><mndw-icon name=${isExpanded ? 'chevron-down' : 'chevron-right'}></mndw-icon></button>
642
+ </td>`;
643
+ }
644
+ renderCell(column, row) {
645
+ const align = [...this.alignClassList(column), ...this.pinClasses(column.id)];
646
+ const style = this.columnStyle(column);
647
+ const slotId = column.renderer !== undefined
648
+ ? this.cellRegistry?.getSlotId(resolveRowKey(this.rowKey, row), column.id)
649
+ : undefined;
650
+ // Custom-renderer cells: align classes only, NO cell-kind-number (matches the old build order).
651
+ if (slotId !== undefined) {
652
+ return html `<td part="cell" class=${classAttr(align)} style=${style}><slot name=${slotId}></slot></td>`;
653
+ }
654
+ const classes = column.kind === 'number' ? [...align, 'cell-kind-number'] : align;
655
+ const value = resolveCellValue(column, row);
656
+ return html `<td part="cell" class=${classAttr(classes)} style=${style}>${this.renderBuiltIn(column, value, row)}</td>`;
657
+ }
658
+ renderBuiltIn(column, value, row) {
659
+ if (column.kind === 'badge') {
660
+ const badge = column.badge?.(value, row);
661
+ // undefined badge -> empty cell (the old empty Text node is intentionally dropped; both ''
662
+ // and nothing render no node in a Lit child expression).
663
+ if (badge === undefined) {
664
+ return nothing;
665
+ }
666
+ return html `<span part="badge"
667
+ ><span part="badge-dot" style="background: ${this.toneColor(badge.tone)};"></span>${badge.text}</span>`;
668
+ }
669
+ if (column.kind === 'boolean') {
670
+ return value
671
+ ? html `<mndw-icon name="check"></mndw-icon>`
672
+ : html `<mndw-icon name="minus"></mndw-icon>`;
673
+ }
674
+ return value === null || value === undefined ? '' : String(value);
675
+ }
676
+ renderCheckbox(options) {
677
+ return html `<mndw-checkbox
678
+ aria-label=${options.ariaLabel}
679
+ part=${options.selectAll ? 'select-all' : nothing}
680
+ ?data-select-all=${options.selectAll ?? false}
681
+ data-row-key=${options.rowKey ?? nothing}
682
+ .checked=${options.checked}
683
+ .indeterminate=${options.indeterminate}
684
+ ></mndw-checkbox>`;
685
+ }
686
+ expandedSet() {
687
+ return new Set(this.expanded);
688
+ }
689
+ getVirtualizer() {
690
+ if (this.virtualizer === null) {
691
+ this.virtualizer = new TableVirtualizer({
692
+ estimatedRowHeight: this.normalizedEstimatedRowHeight(),
693
+ detailEstimate: 160,
694
+ });
695
+ }
696
+ return this.virtualizer;
697
+ }
698
+ captureCurrentAnchor() {
699
+ if (!this.isVirtualRenderingActive() || this.virtualizer === null) {
700
+ return undefined;
701
+ }
702
+ const viewport = this.viewportElement();
703
+ const header = this.headerElement();
704
+ return viewport === null || header === null
705
+ ? undefined
706
+ : this.virtualizer.captureAnchor(this.bodyScrollOffset(viewport, header));
707
+ }
708
+ logicalStructureSignature(rows, expandedKeys) {
709
+ return [
710
+ rows.map((row) => resolveRowKey(this.rowKey, row)).join('\u0000'),
711
+ [...expandedKeys].join('\u0000'),
712
+ ].join('\u0001');
713
+ }
714
+ configureGeometryMode() {
715
+ if (!this.virtual) {
716
+ this.setVirtualInactiveReason(null);
717
+ this.teardownGeometry();
718
+ return;
719
+ }
720
+ if (this.resizeObserver === null && !this.observerAttempted) {
721
+ this.observerAttempted = true;
722
+ this.resizeObserver = this.geometryProvider.createResizeObserver(this.handleGeometryResize);
723
+ }
724
+ if (this.resizeObserver === null) {
725
+ this.setVirtualInactiveReason('resize-observer-unavailable');
726
+ return;
727
+ }
728
+ if (this.reorderable) {
729
+ this.teardownGeometry();
730
+ this.setVirtualInactiveReason('reorderable');
731
+ return;
732
+ }
733
+ this.setVirtualInactiveReason(null);
734
+ }
735
+ configureLayoutMode() {
736
+ const inactive = this.virtual && this.layout === 'auto';
737
+ if (inactive) {
738
+ this.setAttribute('data-mndw-layout-inactive', 'virtual');
739
+ }
740
+ else {
741
+ this.removeAttribute('data-mndw-layout-inactive');
742
+ }
743
+ }
744
+ isVirtualRenderingActive() {
745
+ return this.virtual && !this.reorderable && this.resizeObserver !== null;
746
+ }
747
+ setVirtualInactiveReason(reason) {
748
+ if (reason === null) {
749
+ this.removeAttribute('data-mndw-virtual-inactive');
750
+ }
751
+ else {
752
+ this.setAttribute('data-mndw-virtual-inactive', reason);
753
+ if (this.warnedInactiveReason !== reason) {
754
+ this.warnedInactiveReason = reason;
755
+ console.warn(`<${MNDW_TABLE_TAG}> virtualization inactive: ${reason}`);
756
+ }
757
+ }
758
+ }
759
+ updateVirtualWindow(reconcileCells = true) {
760
+ if (!this.isVirtualRenderingActive() || this.virtualizer === null) {
761
+ return;
762
+ }
763
+ const viewport = this.viewportElement();
764
+ const header = this.headerElement();
765
+ const scrollOffset = viewport === null || header === null ? 0 : this.bodyScrollOffset(viewport, header);
766
+ const viewportHeight = viewport === null ? 0 : this.geometryProvider.getViewportClientHeight(viewport);
767
+ this.virtualRange = this.virtualizer.range(scrollOffset, viewportHeight, this.normalizedOverscan());
768
+ const nextRows = this.displayRows.slice(this.virtualRange.start, this.virtualRange.end);
769
+ if (viewport !== null && this.windowRows !== nextRows) {
770
+ const previousWindow = this.windowRows.map((row) => resolveRowKey(this.rowKey, row)).join('\u0000');
771
+ const nextWindow = nextRows.map((row) => resolveRowKey(this.rowKey, row)).join('\u0000');
772
+ if (previousWindow !== nextWindow) {
773
+ this.evacuateFocusBeforeWindowRemoval(viewport, this.windowRows, nextRows);
774
+ }
775
+ }
776
+ this.windowRows = nextRows;
777
+ if (reconcileCells) {
778
+ this.reconcileVisibleCells(false);
779
+ }
780
+ }
781
+ reconcileVisibleCells(force, visibleColumnIds) {
782
+ const visibleIds = visibleColumnIds ?? new Set(this.effectiveColumns.filter((column) => !this.effectiveHidden.has(column.id)).map((column) => column.id));
783
+ const signature = [
784
+ this.windowRows.map((row) => resolveRowKey(this.rowKey, row)).join('\u0000'),
785
+ [...visibleIds].join('\u0000'),
786
+ [...this.expandedSet()].join('\u0000'),
787
+ ].join('\u0001');
788
+ if (!force && signature === this.lastCellReconcileSignature) {
789
+ return;
790
+ }
791
+ this.cellRegistry?.reconcile(this.windowRows, (row) => resolveRowKey(this.rowKey, row), this.effectiveColumns, visibleIds, resolveCellValue, this.expandedSet(), this.expandedRenderer);
792
+ this.lastCellReconcileSignature = signature;
793
+ }
794
+ bodyScrollOffset(viewport, header) {
795
+ return Math.max(0, this.geometryProvider.getViewportScrollTop(viewport) - this.geometryProvider.measure(header).height);
796
+ }
797
+ writeBodyScrollOffset(viewport, header, bodyOffset) {
798
+ if (this.virtualizer === null) {
799
+ return;
800
+ }
801
+ const headerHeight = this.geometryProvider.measure(header).height;
802
+ const viewportHeight = this.geometryProvider.getViewportClientHeight(viewport);
803
+ const currentScrollTop = this.geometryProvider.getViewportScrollTop(viewport);
804
+ const totalHeight = this.virtualizer.range(this.bodyScrollOffset(viewport, header), viewportHeight, this.normalizedOverscan()).totalHeight;
805
+ const maxScrollTop = Math.max(0, headerHeight + totalHeight - viewportHeight);
806
+ const requestedScrollTop = bodyOffset <= 0 && currentScrollTop < headerHeight
807
+ ? currentScrollTop
808
+ : headerHeight + Math.max(0, bodyOffset);
809
+ const nextScrollTop = Math.min(maxScrollTop, Math.max(0, requestedScrollTop));
810
+ this.expectedProgrammaticScrollTop = nextScrollTop;
811
+ this.geometryProvider.setViewportScrollTop(viewport, nextScrollTop);
812
+ }
813
+ syncGeometryTargets() {
814
+ const observer = this.resizeObserver;
815
+ const viewport = this.viewportElement();
816
+ const header = this.headerElement();
817
+ if (observer === null || viewport === null || header === null) {
818
+ return;
819
+ }
820
+ const targets = new Map();
821
+ targets.set(viewport, { kind: 'viewport' });
822
+ targets.set(header, { kind: 'header' });
823
+ for (const row of this.shadowRoot?.querySelectorAll('[part="row"]') ?? []) {
824
+ const rowKey = row.getAttribute('data-row-key');
825
+ if (rowKey !== null && rowKey !== '') {
826
+ targets.set(row, { kind: 'summary', rowKey });
827
+ }
828
+ }
829
+ for (const detail of this.shadowRoot?.querySelectorAll('[part="detail-row"]') ?? []) {
830
+ const rowKey = detail.getAttribute('data-row-key');
831
+ if (rowKey !== null && rowKey !== '') {
832
+ targets.set(detail, { kind: 'detail', rowKey });
833
+ }
834
+ }
835
+ for (const element of this.observedElements) {
836
+ if (!targets.has(element)) {
837
+ observer.unobserve(element);
838
+ this.observedElements.delete(element);
839
+ }
840
+ }
841
+ for (const [element, target] of targets) {
842
+ registerTableMeasurementTarget(element, target);
843
+ if (!this.observedElements.has(element)) {
844
+ observer.observe(element);
845
+ this.observedElements.add(element);
846
+ }
847
+ }
848
+ if (this.observedViewport !== viewport) {
849
+ this.observedViewport?.removeEventListener('scroll', this.handleViewportScroll);
850
+ viewport.addEventListener('scroll', this.handleViewportScroll);
851
+ this.observedViewport = viewport;
852
+ }
853
+ }
854
+ unobserveStaleGeometryTargets() {
855
+ if (this.resizeObserver === null) {
856
+ return;
857
+ }
858
+ const desiredKeys = new Set(this.windowRows.map((row) => resolveRowKey(this.rowKey, row)));
859
+ const expandedKeys = this.expandedSet();
860
+ for (const element of this.observedElements) {
861
+ const target = lookupTableMeasurementTarget(element);
862
+ if (target?.kind === 'summary' && !desiredKeys.has(target.rowKey)
863
+ || target?.kind === 'detail' && (!desiredKeys.has(target.rowKey) || !expandedKeys.has(target.rowKey))) {
864
+ this.resizeObserver.unobserve(element);
865
+ this.observedElements.delete(element);
866
+ }
867
+ }
868
+ }
869
+ scheduleGeometryFrame() {
870
+ if (!this.isVirtualRenderingActive() || this.pendingGeometryFrame !== null) {
871
+ return;
872
+ }
873
+ this.pendingGeometryFrame = this.geometryProvider.requestAnimationFrame(this.handleGeometryFrame);
874
+ }
875
+ handleGeometryResize = () => {
876
+ this.scheduleGeometryFrame();
877
+ };
878
+ handleViewportScroll = () => {
879
+ const viewport = this.observedViewport;
880
+ if (viewport !== null && this.expectedProgrammaticScrollTop !== undefined) {
881
+ const current = this.geometryProvider.getViewportScrollTop(viewport);
882
+ if (Math.abs(current - this.expectedProgrammaticScrollTop) <= 0.25) {
883
+ this.expectedProgrammaticScrollTop = undefined;
884
+ this.scheduleGeometryFrame();
885
+ return;
886
+ }
887
+ }
888
+ this.pendingScrollTarget = null;
889
+ this.scheduleGeometryFrame();
890
+ };
891
+ handleGeometryFrame = () => {
892
+ this.pendingGeometryFrame = null;
893
+ if (!this.isConnected || !this.isVirtualRenderingActive() || this.virtualizer === null) {
894
+ return;
895
+ }
896
+ const viewport = this.viewportElement();
897
+ const header = this.headerElement();
898
+ if (viewport === null || header === null) {
899
+ return;
900
+ }
901
+ this.geometryProvider.measure(viewport);
902
+ const headerRect = this.geometryProvider.measure(header);
903
+ const nextWidth = this.geometryProvider.getViewportContentWidth(viewport);
904
+ const bodyOffsetBeforeMeasure = this.bodyScrollOffset(viewport, header);
905
+ const anchor = this.virtualizer.captureAnchor(bodyOffsetBeforeMeasure);
906
+ let geometryChanged = false;
907
+ if (this.lastViewportContentWidth === undefined) {
908
+ this.lastViewportContentWidth = nextWidth;
909
+ }
910
+ else if (Number.isFinite(nextWidth)
911
+ && Math.abs(nextWidth - this.lastViewportContentWidth) >= MndwTable.WIDTH_EPSILON) {
912
+ this.lastViewportContentWidth = nextWidth;
913
+ this.virtualizer.resetWidthEpoch();
914
+ geometryChanged = true;
915
+ }
916
+ for (const element of this.observedElements) {
917
+ const target = lookupTableMeasurementTarget(element);
918
+ if (target?.kind === 'summary') {
919
+ geometryChanged =
920
+ this.virtualizer.recordSummaryMeasurement(target.rowKey, this.geometryProvider.measure(element).height)
921
+ || geometryChanged;
922
+ }
923
+ else if (target?.kind === 'detail') {
924
+ geometryChanged =
925
+ this.virtualizer.recordDetailMeasurement(target.rowKey, this.geometryProvider.measure(element).height)
926
+ || geometryChanged;
927
+ }
928
+ }
929
+ const scrollOffset = Math.max(0, this.geometryProvider.getViewportScrollTop(viewport) - headerRect.height);
930
+ const nextRange = this.virtualizer.range(scrollOffset, this.geometryProvider.getViewportClientHeight(viewport), this.normalizedOverscan());
931
+ const previousWindow = this.windowRows.map((row) => resolveRowKey(this.rowKey, row)).join('\u0000');
932
+ const nextRows = this.displayRows.slice(nextRange.start, nextRange.end);
933
+ const nextWindow = nextRows.map((row) => resolveRowKey(this.rowKey, row)).join('\u0000');
934
+ if (previousWindow !== nextWindow) {
935
+ this.evacuateFocusBeforeWindowRemoval(viewport, this.windowRows, nextRows);
936
+ }
937
+ this.virtualRange = nextRange;
938
+ this.windowRows = nextRows;
939
+ this.reconcileVisibleCells(false);
940
+ let targetCorrected = false;
941
+ if (this.pendingScrollTarget !== null) {
942
+ const target = this.pendingScrollTarget;
943
+ const targetElement = [...this.observedElements].find((element) => {
944
+ const measurementTarget = lookupTableMeasurementTarget(element);
945
+ return measurementTarget?.kind === 'summary' && measurementTarget.rowKey === target.key;
946
+ });
947
+ if (targetElement !== undefined) {
948
+ const targetOffset = this.virtualizer.offsetForRow(target.key, target.align, this.geometryProvider.getViewportClientHeight(viewport), scrollOffset);
949
+ if (targetOffset !== undefined) {
950
+ this.writeBodyScrollOffset(viewport, header, targetOffset);
951
+ }
952
+ this.pendingScrollTarget = null;
953
+ targetCorrected = true;
954
+ }
955
+ }
956
+ if (geometryChanged && !targetCorrected && anchor !== undefined) {
957
+ const maxBodyOffset = Math.max(0, nextRange.totalHeight - this.geometryProvider.getViewportClientHeight(viewport));
958
+ const restoredOffset = this.virtualizer.restoreAnchor(anchor, maxBodyOffset);
959
+ this.writeBodyScrollOffset(viewport, header, restoredOffset);
960
+ }
961
+ if (geometryChanged || previousWindow !== nextWindow) {
962
+ this.requestUpdate();
963
+ }
964
+ };
965
+ teardownGeometry() {
966
+ this.observedViewport?.removeEventListener('scroll', this.handleViewportScroll);
967
+ this.observedViewport = null;
968
+ if (this.resizeObserver !== null) {
969
+ for (const element of this.observedElements) {
970
+ this.resizeObserver.unobserve(element);
971
+ }
972
+ this.resizeObserver.disconnect();
973
+ this.resizeObserver = null;
974
+ }
975
+ this.observedElements.clear();
976
+ this.observerAttempted = false;
977
+ if (this.pendingGeometryFrame !== null) {
978
+ this.geometryProvider.cancelAnimationFrame(this.pendingGeometryFrame);
979
+ this.pendingGeometryFrame = null;
980
+ }
981
+ this.lastViewportContentWidth = undefined;
982
+ this.expectedProgrammaticScrollTop = undefined;
983
+ }
984
+ normalizedEstimatedRowHeight() {
985
+ return Number.isFinite(this.estimatedRowHeight) && this.estimatedRowHeight > 0
986
+ ? this.estimatedRowHeight
987
+ : 49;
988
+ }
989
+ normalizedOverscan() {
990
+ return Number.isFinite(this.overscan) && this.overscan >= 0 ? this.overscan : 400;
991
+ }
992
+ viewportElement() {
993
+ return this.shadowRoot?.querySelector('[part="viewport"]') ?? null;
994
+ }
995
+ headerElement() {
996
+ return this.shadowRoot?.querySelector('[part="header-row"]') ?? null;
997
+ }
998
+ collectFocusChain() {
999
+ const chain = [];
1000
+ let activeElement = document.activeElement;
1001
+ while (activeElement !== null) {
1002
+ chain.push({ rowKey: this.focusedRowKeyForElement(activeElement) });
1003
+ const nestedActive = activeElement.shadowRoot?.activeElement;
1004
+ if (!(nestedActive instanceof Element) || nestedActive === activeElement) {
1005
+ break;
1006
+ }
1007
+ activeElement = nestedActive;
1008
+ }
1009
+ return chain;
1010
+ }
1011
+ focusedRowKeyForElement(element) {
1012
+ const parkedRowKey = this.cellRegistry?.getRowKeyForNode(element);
1013
+ if (parkedRowKey !== undefined) {
1014
+ return parkedRowKey;
1015
+ }
1016
+ return element.closest('[part="row"], [part="detail-row"]')?.getAttribute('data-row-key') ?? undefined;
1017
+ }
1018
+ evacuateFocusBeforeWindowRemoval(viewport, previousRows, nextRows) {
1019
+ const previousKeys = new Set(previousRows.map((row) => resolveRowKey(this.rowKey, row)));
1020
+ const nextKeys = new Set(nextRows.map((row) => resolveRowKey(this.rowKey, row)));
1021
+ const focusedKey = resolveFocusedRowKey(this.collectFocusChain());
1022
+ if (focusedKey !== undefined && previousKeys.has(focusedKey) && !nextKeys.has(focusedKey)) {
1023
+ viewport.focus();
1024
+ }
1025
+ }
1026
+ shouldRenderLeadingToggle() {
1027
+ return this.expandable && this.toggleAfterColumn === undefined && this.toggleCell === 'leading';
1028
+ }
1029
+ shouldRenderTrailingToggle() {
1030
+ return this.expandable && this.toggleAfterColumn === undefined && this.toggleCell === 'trailing';
1031
+ }
1032
+ shouldRenderToggleAfter(columnId) {
1033
+ return this.expandable && this.toggleAfterColumn === columnId;
1034
+ }
1035
+ leadingUtilityKeys() {
1036
+ const keys = [];
1037
+ if (this.shouldRenderLeadingToggle()) {
1038
+ keys.push(MndwTable.PIN_KEYS.expandLead);
1039
+ }
1040
+ if (this.selectable) {
1041
+ keys.push(MndwTable.PIN_KEYS.select);
1042
+ }
1043
+ if (this.reorderable && this.effectiveSortState === null) {
1044
+ keys.push(MndwTable.PIN_KEYS.drag);
1045
+ }
1046
+ return keys;
1047
+ }
1048
+ computePinState() {
1049
+ const visible = this.effectiveColumns.filter((column) => !this.effectiveHidden.has(column.id));
1050
+ const pinnedData = [];
1051
+ let inactiveReason = null;
1052
+ let inactiveColumnId = null;
1053
+ for (const column of visible) {
1054
+ if (column.sticky !== 'start') {
1055
+ break;
1056
+ }
1057
+ if (column.width === undefined) {
1058
+ inactiveReason = 'missing-width';
1059
+ inactiveColumnId = column.id;
1060
+ break;
1061
+ }
1062
+ pinnedData.push({ ...column, width: column.width });
1063
+ }
1064
+ if (inactiveReason === null) {
1065
+ const offending = visible.slice(pinnedData.length).find((column) => column.sticky === 'start');
1066
+ if (offending !== undefined) {
1067
+ inactiveReason = 'not-leading';
1068
+ inactiveColumnId = offending.id;
1069
+ }
1070
+ }
1071
+ const byKey = new Map();
1072
+ if (pinnedData.length > 0) {
1073
+ const slots = [
1074
+ ...this.leadingUtilityKeys().map((key) => ({ key, width: MndwTable.UTILITY_COL_WIDTH })),
1075
+ ...pinnedData.map((column) => ({ key: column.id, width: column.width })),
1076
+ ];
1077
+ const widthsSoFar = [];
1078
+ slots.forEach((slot, index) => {
1079
+ const inset = widthsSoFar.length === 0
1080
+ ? '0'
1081
+ : widthsSoFar.length === 1
1082
+ ? widthsSoFar[0]
1083
+ : `calc(${widthsSoFar.join(' + ')})`;
1084
+ byKey.set(slot.key, { insetInlineStart: inset, isLast: index === slots.length - 1 });
1085
+ widthsSoFar.push(slot.width);
1086
+ });
1087
+ }
1088
+ return { byKey, inactiveReason, inactiveColumnId };
1089
+ }
1090
+ applyStickyInactive(state) {
1091
+ if (state.inactiveReason === null) {
1092
+ this.removeAttribute('data-mndw-sticky-inactive');
1093
+ this.warnedStickyReason = null;
1094
+ return;
1095
+ }
1096
+ this.setAttribute('data-mndw-sticky-inactive', state.inactiveReason);
1097
+ const signature = `${state.inactiveReason}:${state.inactiveColumnId ?? ''}`;
1098
+ if (this.warnedStickyReason !== signature) {
1099
+ this.warnedStickyReason = signature;
1100
+ console.warn(`<${MNDW_TABLE_TAG}> sticky column "${state.inactiveColumnId ?? ''}" inactive: ${state.inactiveReason}`);
1101
+ }
1102
+ }
1103
+ tableStyle() {
1104
+ return this.minWidth === '' ? nothing : `min-width: ${this.minWidth};`;
1105
+ }
1106
+ columnStyle(column) {
1107
+ const pin = this.pinState.byKey.get(column.id);
1108
+ const parts = [];
1109
+ if (column.width !== undefined) {
1110
+ parts.push(`width: ${column.width};`);
1111
+ }
1112
+ if (pin !== undefined && column.width !== undefined) {
1113
+ parts.push(`min-width: ${column.width};`, `max-width: ${column.width};`, 'box-sizing: border-box;', `inset-inline-start: ${pin.insetInlineStart};`);
1114
+ }
1115
+ return parts.length === 0 ? nothing : parts.join(' ');
1116
+ }
1117
+ pinClasses(key) {
1118
+ const pin = this.pinState.byKey.get(key);
1119
+ if (pin === undefined) {
1120
+ return [];
1121
+ }
1122
+ return pin.isLast ? ['pinned', 'pinned-last'] : ['pinned'];
1123
+ }
1124
+ utilityPinStyle(key) {
1125
+ const pin = this.pinState.byKey.get(key);
1126
+ if (pin === undefined) {
1127
+ return nothing;
1128
+ }
1129
+ const width = MndwTable.UTILITY_COL_WIDTH;
1130
+ return `width: ${width}; min-width: ${width}; max-width: ${width}; box-sizing: border-box; inset-inline-start: ${pin.insetInlineStart};`;
1131
+ }
1132
+ columnSpan() {
1133
+ const visibleData = this.effectiveColumns.filter((column) => !this.effectiveHidden.has(column.id)).length;
1134
+ return (this.expandable ? 1 : 0)
1135
+ + (this.selectable ? 1 : 0)
1136
+ + (this.reorderable && this.effectiveSortState === null ? 1 : 0)
1137
+ + visibleData
1138
+ + (this.columnMenu ? 1 : 0);
1139
+ }
1140
+ alignClassList(column) {
1141
+ const classes = [];
1142
+ if (column.align === 'end') {
1143
+ classes.push('align-end');
1144
+ }
1145
+ if (column.align === 'center') {
1146
+ classes.push('align-center');
1147
+ }
1148
+ if (column.nowrap === true) {
1149
+ classes.push('nowrap');
1150
+ }
1151
+ return classes;
1152
+ }
1153
+ toneColor(tone) {
1154
+ return `var(--mndw-${tone === 'neutral' ? 'text-muted' : tone})`;
1155
+ }
1156
+ resolveLabels() {
1157
+ return { ...defaultLabels(), ...this.labels };
1158
+ }
1159
+ rowName(row, index) {
1160
+ return this.rowLabel?.(row) ?? this.resolveLabels().rowFallback(index + 1);
1161
+ }
1162
+ sameSortState(left, right) {
1163
+ return left?.columnId === right?.columnId && left?.direction === right?.direction;
1164
+ }
1165
+ logicalRowCount() {
1166
+ const expandedKeys = this.expandedSet();
1167
+ const validKeys = new Set(this.displayRows.map((row) => resolveRowKey(this.rowKey, row)));
1168
+ const detailCount = [...expandedKeys].filter((key) => validKeys.has(key)).length;
1169
+ return 1 + this.displayRows.length + detailCount;
1170
+ }
1171
+ logicalRowIndex(key, detail) {
1172
+ let rowIndex = 2;
1173
+ const expandedKeys = this.expandedSet();
1174
+ for (const row of this.displayRows) {
1175
+ const rowKey = resolveRowKey(this.rowKey, row);
1176
+ if (rowKey === key) {
1177
+ return detail ? rowIndex + 1 : rowIndex;
1178
+ }
1179
+ rowIndex += 1;
1180
+ if (expandedKeys.has(rowKey)) {
1181
+ rowIndex += 1;
1182
+ }
1183
+ }
1184
+ return rowIndex;
1185
+ }
1186
+ locale() {
1187
+ return document.documentElement.lang || 'en';
1188
+ }
1189
+ isAllSelected() {
1190
+ return selectAllState(this.selectedKeySet, this.displayRows.map((row) => resolveRowKey(this.rowKey, row)))
1191
+ === 'all';
1192
+ }
1193
+ isIndeterminate() {
1194
+ return selectAllState(this.selectedKeySet, this.displayRows.map((row) => resolveRowKey(this.rowKey, row)))
1195
+ === 'indeterminate';
1196
+ }
1197
+ emitErrorIfChanged() {
1198
+ const signature = JSON.stringify(this.violations);
1199
+ if (signature === this.lastViolationSignature) {
1200
+ return;
1201
+ }
1202
+ this.lastViolationSignature = signature;
1203
+ if (this.violations.length === 0) {
1204
+ return;
1205
+ }
1206
+ this.dispatchEvent(new CustomEvent(MNDW_ERROR_EVENT, { ...EVENT_OPTIONS, detail: { violations: this.violations } }));
1207
+ }
1208
+ handleCheckboxChange = (event) => {
1209
+ const target = (event.composedPath()[0] ?? null);
1210
+ if (target === null) {
1211
+ return;
1212
+ }
1213
+ if (target.hasAttribute('data-select-all')) {
1214
+ const keys = this.displayRows.map((row) => resolveRowKey(this.rowKey, row));
1215
+ const next = toggleSelectAll(this.selected, keys);
1216
+ this.dispatchEvent(new CustomEvent(MNDW_SELECTION_CHANGE_EVENT, {
1217
+ ...EVENT_OPTIONS,
1218
+ detail: { selected: next },
1219
+ }));
1220
+ return;
1221
+ }
1222
+ const rowKey = target.getAttribute('data-row-key');
1223
+ if (rowKey !== null) {
1224
+ const next = toggleKey(this.selected, rowKey);
1225
+ this.dispatchEvent(new CustomEvent(MNDW_SELECTION_CHANGE_EVENT, {
1226
+ ...EVENT_OPTIONS,
1227
+ detail: { selected: next },
1228
+ }));
1229
+ }
1230
+ };
1231
+ handleClick = (event) => {
1232
+ const target = (event.composedPath()[0] ?? null);
1233
+ const expandToggle = target?.closest?.('[part="expand-toggle"]');
1234
+ if (expandToggle !== null && expandToggle !== undefined) {
1235
+ this.emitExpand(expandToggle.getAttribute('data-expand-key') ?? '');
1236
+ return;
1237
+ }
1238
+ if (this.expandable && this.expandOn === 'row') {
1239
+ const path = event.composedPath();
1240
+ const interactive = path.some((node) => node instanceof HTMLElement && (node.tagName === 'BUTTON'
1241
+ || node.tagName === 'A'
1242
+ || node.tagName === 'INPUT'
1243
+ || node.tagName === 'MNDW-CHECKBOX'
1244
+ || node.getAttribute('part') === 'drag-handle'
1245
+ || node.hasAttribute('data-no-expand')));
1246
+ if (!interactive) {
1247
+ const row = path.find((node) => node instanceof HTMLElement && node.getAttribute('part') === 'row');
1248
+ const key = row instanceof HTMLElement ? row.getAttribute('data-row-key') : null;
1249
+ if (key !== null && key !== undefined && key !== '') {
1250
+ this.emitExpand(key);
1251
+ }
1252
+ }
1253
+ }
1254
+ const sortButton = target?.closest?.('[data-sort-column]');
1255
+ if (sortButton !== null && sortButton !== undefined) {
1256
+ this.activateSort(sortButton.getAttribute('data-sort-column') ?? '');
1257
+ return;
1258
+ }
1259
+ if (target?.closest?.('[part="column-menu-trigger"]') !== null
1260
+ && target?.closest?.('[part="column-menu-trigger"]') !== undefined) {
1261
+ this.openColumnMenu(target);
1262
+ }
1263
+ };
1264
+ emitExpand(key) {
1265
+ const expanded = new Set(this.expanded);
1266
+ if (expanded.has(key)) {
1267
+ expanded.delete(key);
1268
+ }
1269
+ else {
1270
+ expanded.add(key);
1271
+ }
1272
+ this.dispatchEvent(new CustomEvent(MNDW_ROW_EXPAND_EVENT, {
1273
+ ...EVENT_OPTIONS,
1274
+ detail: { expanded: [...expanded] },
1275
+ }));
1276
+ }
1277
+ handleKeyDown = (event) => {
1278
+ const handle = (event.composedPath()[0] ?? null);
1279
+ if (handle?.getAttribute('part') !== 'drag-handle') {
1280
+ return;
1281
+ }
1282
+ if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
1283
+ event.preventDefault();
1284
+ this.keyboardReorder(handle.getAttribute('data-row-key') ?? '', event.key === 'ArrowUp' ? -1 : 1);
1285
+ }
1286
+ };
1287
+ activateSort(columnId) {
1288
+ const column = this.effectiveColumns.find((candidate) => candidate.id === columnId);
1289
+ if (column?.sortable !== true) {
1290
+ return;
1291
+ }
1292
+ const next = nextSortState(this.sort, columnId);
1293
+ this.dispatchEvent(new CustomEvent(MNDW_SORT_CHANGE_EVENT, {
1294
+ ...EVENT_OPTIONS,
1295
+ detail: { sort: next },
1296
+ }));
1297
+ }
1298
+ keyboardReorder(key, direction) {
1299
+ const index = this.displayRows.findIndex((row) => resolveRowKey(this.rowKey, row) === key);
1300
+ if (index === -1) {
1301
+ return;
1302
+ }
1303
+ const targetIndex = index + direction;
1304
+ if (targetIndex < 0 || targetIndex >= this.displayRows.length) {
1305
+ return;
1306
+ }
1307
+ const beforeIndex = direction === -1 ? targetIndex : targetIndex + 1;
1308
+ const beforeKey = beforeIndex < this.displayRows.length
1309
+ ? resolveRowKey(this.rowKey, this.displayRows[beforeIndex])
1310
+ : null;
1311
+ this.emitReorder(key, beforeKey);
1312
+ }
1313
+ emitReorder(key, beforeKey) {
1314
+ const labels = this.resolveLabels();
1315
+ const row = this.displayRows.find((candidate) => resolveRowKey(this.rowKey, candidate) === key);
1316
+ this.announceText = row === undefined
1317
+ ? ''
1318
+ : labels.reordered(this.rowName(row, this.displayRows.indexOf(row)), this.displayRows.indexOf(row) + 1, this.displayRows.length);
1319
+ this.dispatchEvent(new CustomEvent(MNDW_ROW_REORDER_EVENT, {
1320
+ ...EVENT_OPTIONS,
1321
+ detail: { key, beforeKey },
1322
+ }));
1323
+ }
1324
+ applyColumnVisibility(hidden) {
1325
+ this.dispatchEvent(new CustomEvent(MNDW_COLUMN_VISIBILITY_CHANGE_EVENT, {
1326
+ ...EVENT_OPTIONS,
1327
+ detail: { hidden },
1328
+ }));
1329
+ }
1330
+ getVisibleColumnIds() {
1331
+ return this.effectiveColumns.filter((column) => !this.effectiveHidden.has(column.id)).map((column) => column.id);
1332
+ }
1333
+ scrollToRow(key, options = {}) {
1334
+ const rowExists = this.displayRows.some((row) => resolveRowKey(this.rowKey, row) === key);
1335
+ if (!rowExists) {
1336
+ return false;
1337
+ }
1338
+ const viewport = this.viewportElement();
1339
+ const header = this.headerElement();
1340
+ if (viewport === null || header === null) {
1341
+ return false;
1342
+ }
1343
+ const virtualizer = this.getVirtualizer();
1344
+ virtualizer.configure({ estimatedRowHeight: this.normalizedEstimatedRowHeight(), detailEstimate: 160 });
1345
+ virtualizer.setRows(this.displayRows.map((row) => resolveRowKey(this.rowKey, row)), this.expandedSet());
1346
+ const align = options.align ?? 'nearest';
1347
+ const bodyOffset = virtualizer.offsetForRow(key, align, this.geometryProvider.getViewportClientHeight(viewport), this.bodyScrollOffset(viewport, header));
1348
+ if (bodyOffset === undefined) {
1349
+ return false;
1350
+ }
1351
+ if (this.isVirtualRenderingActive()) {
1352
+ this.pendingScrollTarget = { key, align };
1353
+ }
1354
+ this.writeBodyScrollOffset(viewport, header, bodyOffset);
1355
+ this.updateVirtualWindow();
1356
+ if (this.isVirtualRenderingActive()) {
1357
+ this.requestUpdate();
1358
+ }
1359
+ return true;
1360
+ }
1361
+ openColumnMenu(trigger) {
1362
+ if (this.menuLayer !== null) {
1363
+ return;
1364
+ }
1365
+ const options = this.effectiveColumns
1366
+ .filter((column) => column.hideable !== false)
1367
+ .map((column) => ({ id: column.id, label: column.label }));
1368
+ const layer = getOverlayProvider().open({
1369
+ anchor: trigger,
1370
+ presentation: 'popover',
1371
+ className: this.columnMenuPanelClass || undefined,
1372
+ trapFocus: false,
1373
+ restoreFocus: false,
1374
+ });
1375
+ const menu = document.createElement(MNDW_COLUMN_MENU_TAG);
1376
+ menu.columns = options;
1377
+ menu.hiddenColumns = [...this.effectiveHidden];
1378
+ menu.addEventListener(MNDW_COLUMN_MENU_CHECK_EVENT, this.onColumnMenuCheck);
1379
+ menu.addEventListener('mndwpaneldismiss', this.onColumnMenuDismiss);
1380
+ layer.contentElement.appendChild(menu);
1381
+ this.menuLayer = layer;
1382
+ void menu.updateComplete.then(() => {
1383
+ if (this.menuLayer === layer) {
1384
+ layer.reposition();
1385
+ menu.focusFirstOption();
1386
+ }
1387
+ });
1388
+ void layer.closed.then(() => {
1389
+ this.forgetColumnMenu();
1390
+ });
1391
+ }
1392
+ closeColumnMenu() {
1393
+ this.menuLayer?.close();
1394
+ this.forgetColumnMenu();
1395
+ }
1396
+ forgetColumnMenu() {
1397
+ this.menuLayer = null;
1398
+ }
1399
+ onColumnMenuCheck = (event) => {
1400
+ const hidden = event.detail.hidden;
1401
+ if (this.hiddenColumns !== undefined) {
1402
+ this.applyColumnVisibility(hidden);
1403
+ return;
1404
+ }
1405
+ this.visibilityState.applyInternal(hidden);
1406
+ this.requestUpdate();
1407
+ this.applyColumnVisibility(hidden);
1408
+ };
1409
+ onColumnMenuDismiss = (event) => {
1410
+ const restoreFocus = event.detail.restoreFocus;
1411
+ this.closeColumnMenu();
1412
+ if (restoreFocus) {
1413
+ this.shadowRoot?.querySelector('[part="column-menu-trigger"]')?.focus();
1414
+ }
1415
+ };
1416
+ }
1417
+ //# sourceMappingURL=table.js.map