@gramlot/gramlot 0.3.20 → 0.3.24

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 (102) hide show
  1. package/dist/components/chat/__init__.py +13 -0
  2. package/dist/components/chat/assets/collection.js +9 -0
  3. package/dist/components/chat/assets/index.js +3 -0
  4. package/dist/components/chat/commands.json +7 -0
  5. package/dist/components/chat/grammar.json +48 -0
  6. package/dist/components/editors/__init__.py +2 -2
  7. package/dist/components/editors/assets/collection.js +22 -120909
  8. package/dist/components/editors/assets/index.js +2 -1
  9. package/dist/components/editors/assets/modules/chunk-AU4HFPIY.js +1 -0
  10. package/dist/components/editors/assets/modules/chunk-MMJXUHRQ.js +3 -0
  11. package/dist/components/editors/assets/modules/chunk-OCFLP2K4.js +16 -0
  12. package/dist/components/editors/assets/modules/chunk-YSGSC7KM.js +1 -0
  13. package/dist/components/editors/assets/modules/code-mirror-engine-QX4A5FVO.js +92 -0
  14. package/dist/components/editors/assets/modules/jodit-engine-MMSPIWM7.js +1853 -0
  15. package/dist/components/editors/assets/modules/prose-mirror-engine-IXTRTG6B.js +24 -0
  16. package/dist/components/grid/__init__.py +13 -0
  17. package/dist/components/grid/assets/collection.js +211 -0
  18. package/dist/components/grid/assets/index.js +3 -0
  19. package/dist/components/grid/commands.json +7 -0
  20. package/dist/components/grid/grammar.json +714 -0
  21. package/dist/components/grouplets/__init__.py +13 -0
  22. package/dist/components/grouplets/assets/collection.js +202 -0
  23. package/dist/components/grouplets/assets/index.js +3 -0
  24. package/dist/components/grouplets/commands.json +7 -0
  25. package/dist/components/grouplets/grammar.json +355 -0
  26. package/dist/components/inputs/__init__.py +1 -1
  27. package/dist/components/inputs/assets/collection.js +32 -24503
  28. package/dist/components/inputs/assets/index.js +2 -1
  29. package/dist/components/inputs/grammar.json +214 -6
  30. package/dist/components/layout/__init__.py +1 -1
  31. package/dist/components/layout/assets/collection.js +27 -26701
  32. package/dist/components/layout/assets/index.js +2 -1
  33. package/dist/components/layout/grammar.json +4 -0
  34. package/dist/components/selection_trial/__init__.py +13 -0
  35. package/dist/components/selection_trial/assets/collection.js +4 -0
  36. package/dist/components/selection_trial/assets/index.js +3 -0
  37. package/dist/components/selection_trial/commands.json +7 -0
  38. package/dist/components/selection_trial/grammar.json +552 -0
  39. package/dist/components/tree/__init__.py +1 -1
  40. package/dist/components/tree/assets/collection.js +24 -24612
  41. package/dist/components/tree/assets/index.js +2 -1
  42. package/dist/components/typst/__init__.py +2 -2
  43. package/dist/components/typst/assets/collection.js +12 -4
  44. package/dist/components/typst/assets/index.js +2 -1
  45. package/dist/components/typst/assets/modules/chunk-BLMUM44K.js +1 -0
  46. package/dist/components/typst/assets/modules/typst-client-JHC6UVYG.js +4 -0
  47. package/dist/gramlot.js +2749 -1627
  48. package/dist/gramlot.min.js +46 -41
  49. package/package.json +7 -2
  50. package/src/binding/grid-struct.js +63 -0
  51. package/src/binding/installation.js +5 -2
  52. package/src/binding/runtime.js +51 -6
  53. package/src/builder/gramlot-builder.d.ts +5 -0
  54. package/src/builder/gramlot-builder.js +16 -0
  55. package/src/builder/source.js +23 -0
  56. package/src/chat.d.ts +12 -0
  57. package/src/chat.js +198 -0
  58. package/src/collection-artifact.js +1 -1
  59. package/src/components/bases.js +2 -0
  60. package/src/components/chat.js +28 -0
  61. package/src/components/choice-editor.js +89 -34
  62. package/src/components/database-choices.js +131 -9
  63. package/src/components/field-state.js +10 -1
  64. package/src/components/grid-grammar.json +237 -0
  65. package/src/components/grid-header-interaction.js +196 -0
  66. package/src/components/grid-row-interaction.js +184 -0
  67. package/src/components/grid-row-layout.js +96 -0
  68. package/src/components/grid-rows.js +28 -0
  69. package/src/components/grid-search-box.js +142 -0
  70. package/src/components/grid-search-styles.js +42 -0
  71. package/src/components/grid-search.js +37 -0
  72. package/src/components/grid-structure.js +84 -0
  73. package/src/components/grid-styles.js +151 -0
  74. package/src/components/grid.js +589 -0
  75. package/src/components/grouplet-card.js +437 -0
  76. package/src/components/grouplets.js +17 -0
  77. package/src/components/menus.js +1 -0
  78. package/src/components/registry.js +4 -3
  79. package/src/components/tray-pane.js +32 -4
  80. package/src/components/typed-editor.js +4 -2
  81. package/src/experiments/selection-transfer.js +78 -0
  82. package/src/experiments/selection-trial.js +48 -0
  83. package/src/experiments/window-selection.js +124 -0
  84. package/src/form-state.d.ts +20 -0
  85. package/src/form-state.js +198 -0
  86. package/src/index-page-styles.js +1 -1
  87. package/src/index.d.ts +3 -1
  88. package/src/index.js +3 -1
  89. package/src/renderer/gramlot-renderer.js +8 -1
  90. package/src/server/gramlot-server.d.ts +2 -0
  91. package/src/server/gramlot-server.js +13 -1
  92. package/src/stores/bag-collection-store.js +51 -0
  93. package/src/stores/bag-collection-view.js +127 -0
  94. package/src/stores/collection-filter.js +77 -0
  95. package/src/view/controls.js +33 -1
  96. package/src/view/grouplet-card.js +54 -0
  97. package/src/view/html.js +20 -3
  98. package/src/view/labelbox.js +7 -3
  99. package/themes/gramlot-base/theme.css +28 -0
  100. package/themes/gramlot-compact/theme.css +8 -0
  101. package/themes/joanna/theme.css +8 -0
  102. package/themes/mimi/theme.css +8 -0
@@ -0,0 +1,237 @@
1
+ {
2
+ "elements": {
3
+ "struct": {
4
+ "doc": null,
5
+ "sub_tags": "column,colgroup",
6
+ "parent_tags": "grid",
7
+ "inherits_from": null,
8
+ "ns": null,
9
+ "node_label": null,
10
+ "collection_key": null,
11
+ "attributes": {
12
+ "parameters": [],
13
+ "accepts_var_keyword": false,
14
+ "accepts_var_positional": false
15
+ },
16
+ "_meta": {
17
+ "data_element": true,
18
+ "gridStruct": true
19
+ }
20
+ },
21
+ "column": {
22
+ "doc": null,
23
+ "sub_tags": "",
24
+ "parent_tags": "struct,colgroup",
25
+ "inherits_from": null,
26
+ "ns": null,
27
+ "node_label": null,
28
+ "collection_key": null,
29
+ "attributes": {
30
+ "parameters": [
31
+ {
32
+ "name": "field",
33
+ "kind": "positional_or_keyword",
34
+ "role": "attribute",
35
+ "annotation": {
36
+ "kind": "annotated",
37
+ "base": {
38
+ "kind": "dtype",
39
+ "dtype": "T"
40
+ },
41
+ "metadata": [
42
+ {
43
+ "kind": "regex",
44
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
45
+ "flags": 0
46
+ }
47
+ ]
48
+ },
49
+ "has_default": false
50
+ },
51
+ {
52
+ "name": "name",
53
+ "kind": "keyword_only",
54
+ "role": "attribute",
55
+ "annotation": {
56
+ "kind": "dtype",
57
+ "dtype": "T"
58
+ },
59
+ "has_default": true,
60
+ "default": null
61
+ },
62
+ {
63
+ "name": "dtype",
64
+ "kind": "keyword_only",
65
+ "role": "attribute",
66
+ "annotation": {
67
+ "kind": "annotated",
68
+ "base": {
69
+ "kind": "dtype",
70
+ "dtype": "T"
71
+ },
72
+ "metadata": [
73
+ {
74
+ "kind": "regex",
75
+ "pattern": "^(T|B|L|R|N|D|H|DHZ)$",
76
+ "flags": 0
77
+ }
78
+ ]
79
+ },
80
+ "has_default": true,
81
+ "default": null
82
+ },
83
+ {
84
+ "name": "width",
85
+ "kind": "keyword_only",
86
+ "role": "attribute",
87
+ "annotation": {
88
+ "kind": "annotated",
89
+ "base": {
90
+ "kind": "dtype",
91
+ "dtype": "T"
92
+ },
93
+ "metadata": [
94
+ {
95
+ "kind": "regex",
96
+ "pattern": "^[0-9]+([.][0-9]+)?(px|em|rem|ch|%)$",
97
+ "flags": 0
98
+ }
99
+ ]
100
+ },
101
+ "has_default": true,
102
+ "default": null
103
+ },
104
+ {
105
+ "name": "align",
106
+ "kind": "keyword_only",
107
+ "role": "attribute",
108
+ "annotation": {
109
+ "kind": "annotated",
110
+ "base": {
111
+ "kind": "dtype",
112
+ "dtype": "T"
113
+ },
114
+ "metadata": [
115
+ {
116
+ "kind": "regex",
117
+ "pattern": "^(start|center|end)$",
118
+ "flags": 0
119
+ }
120
+ ]
121
+ },
122
+ "has_default": true,
123
+ "default": null
124
+ },
125
+ {
126
+ "name": "format",
127
+ "kind": "keyword_only",
128
+ "role": "attribute",
129
+ "annotation": {
130
+ "kind": "dtype",
131
+ "dtype": "T"
132
+ },
133
+ "has_default": true,
134
+ "default": null
135
+ },
136
+ {
137
+ "name": "white_space",
138
+ "kind": "keyword_only",
139
+ "role": "attribute",
140
+ "annotation": {
141
+ "kind": "annotated",
142
+ "base": {
143
+ "kind": "dtype",
144
+ "dtype": "T"
145
+ },
146
+ "metadata": [
147
+ {
148
+ "kind": "regex",
149
+ "pattern": "^(normal|nowrap|pre-wrap)$",
150
+ "flags": 0
151
+ }
152
+ ]
153
+ },
154
+ "has_default": true,
155
+ "default": null
156
+ }
157
+ ],
158
+ "accepts_var_keyword": false,
159
+ "accepts_var_positional": false
160
+ },
161
+ "_meta": {
162
+ "data_element": true
163
+ }
164
+ },
165
+ "colgroup": {
166
+ "doc": null,
167
+ "sub_tags": "column",
168
+ "parent_tags": "struct",
169
+ "inherits_from": null,
170
+ "ns": null,
171
+ "node_label": null,
172
+ "collection_key": null,
173
+ "attributes": {
174
+ "parameters": [
175
+ {
176
+ "name": "code",
177
+ "kind": "positional_or_keyword",
178
+ "role": "attribute",
179
+ "annotation": {
180
+ "kind": "annotated",
181
+ "base": {
182
+ "kind": "dtype",
183
+ "dtype": "T"
184
+ },
185
+ "metadata": [
186
+ {
187
+ "kind": "regex",
188
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
189
+ "flags": 0
190
+ }
191
+ ]
192
+ },
193
+ "has_default": false
194
+ },
195
+ {
196
+ "name": "name",
197
+ "kind": "keyword_only",
198
+ "role": "attribute",
199
+ "annotation": {
200
+ "kind": "dtype",
201
+ "dtype": "T"
202
+ },
203
+ "has_default": true,
204
+ "default": null
205
+ },
206
+ {
207
+ "name": "background",
208
+ "kind": "keyword_only",
209
+ "role": "attribute",
210
+ "annotation": {
211
+ "kind": "dtype",
212
+ "dtype": "T"
213
+ },
214
+ "has_default": true,
215
+ "default": null
216
+ },
217
+ {
218
+ "name": "color",
219
+ "kind": "keyword_only",
220
+ "role": "attribute",
221
+ "annotation": {
222
+ "kind": "dtype",
223
+ "dtype": "T"
224
+ },
225
+ "has_default": true,
226
+ "default": null
227
+ }
228
+ ],
229
+ "accepts_var_keyword": false,
230
+ "accepts_var_positional": false
231
+ },
232
+ "_meta": {
233
+ "data_element": true
234
+ }
235
+ }
236
+ }
237
+ }
@@ -0,0 +1,196 @@
1
+ /** Shared column resize gestures; Data owns field widths, per-grid layout owns the row header. */
2
+ export class GridHeaderInteraction {
3
+ #head;
4
+ #control;
5
+ #structure;
6
+ #sort;
7
+ #rowLayout;
8
+ #layoutChanged;
9
+ #suppressClick = false;
10
+ #gesture = null;
11
+ #drag = null;
12
+ constructor(head, control, structure, sort, rowLayout, layoutChanged) {
13
+ this.#head = head;
14
+ this.#control = control;
15
+ this.#structure = structure;
16
+ this.#sort = sort;
17
+ this.#rowLayout = rowLayout;
18
+ this.#layoutChanged = layoutChanged;
19
+ }
20
+ connect() {
21
+ this.#head.addEventListener('click', this.#click);
22
+ this.#head.addEventListener('pointerdown', this.#start);
23
+ this.#head.addEventListener('pointermove', this.#move);
24
+ this.#head.addEventListener('pointerup', this.#finish);
25
+ this.#head.addEventListener('pointercancel', this.#cancel);
26
+ this.#head.addEventListener('lostpointercapture', this.#cancel);
27
+ this.#head.addEventListener('keydown', this.#key);
28
+ this.#head.addEventListener('dragstart', this.#dragStart);
29
+ this.#head.addEventListener('dragover', this.#dragOver);
30
+ this.#head.addEventListener('drop', this.#drop);
31
+ this.#head.addEventListener('dragend', this.#clearDrag);
32
+ }
33
+ disconnect() {
34
+ this.cancel();
35
+ this.#head.removeEventListener('click', this.#click);
36
+ this.#head.removeEventListener('pointerdown', this.#start);
37
+ this.#head.removeEventListener('pointermove', this.#move);
38
+ this.#head.removeEventListener('pointerup', this.#finish);
39
+ this.#head.removeEventListener('pointercancel', this.#cancel);
40
+ this.#head.removeEventListener('lostpointercapture', this.#cancel);
41
+ this.#head.removeEventListener('keydown', this.#key);
42
+ this.#head.removeEventListener('dragstart', this.#dragStart);
43
+ this.#head.removeEventListener('dragover', this.#dragOver);
44
+ this.#head.removeEventListener('drop', this.#drop);
45
+ this.#head.removeEventListener('dragend', this.#clearDrag);
46
+ }
47
+ #click = event => {
48
+ if (this.#suppressClick) { this.#suppressClick = false; return; }
49
+ if (event.target.closest('.column-resize')) return;
50
+ const header = event.target.closest('th[data-field]');
51
+ if (header) this.#sort(header.dataset.field, event.shiftKey);
52
+ };
53
+ #dragStart = event => {
54
+ const header = event.target.closest('th[data-field]');
55
+ if (!header || this.#gesture) { event.preventDefault(); return; }
56
+ this.#suppressClick = true;
57
+ this.#drag = {field:header.dataset.field, node:this.#structure().columnNode(header.dataset.field)};
58
+ event.dataTransfer.effectAllowed = 'move';
59
+ event.dataTransfer.setData('text/plain', header.textContent);
60
+ header.classList.add('column-dragging');
61
+ };
62
+ #dropTarget(event) {
63
+ const header = event.target.closest('th[data-field]');
64
+ if (!this.#drag || !header) return null;
65
+ const target = this.#structure().columnNode(header.dataset.field);
66
+ if (this.#structure().columnNode(this.#drag.field) !== this.#drag.node ||
67
+ target === this.#drag.node || target.parentBag !== this.#drag.node.parentBag) return null;
68
+ return {header, field:header.dataset.field,
69
+ after:event.clientX > header.getBoundingClientRect().left + header.getBoundingClientRect().width / 2};
70
+ }
71
+ #dragOver = event => {
72
+ const target = this.#dropTarget(event);
73
+ for (const cell of this.#head.querySelectorAll('[data-drop]')) cell.removeAttribute('data-drop');
74
+ if (!target) return;
75
+ event.preventDefault(); event.dataTransfer.dropEffect = 'move';
76
+ target.header.dataset.drop = target.after ? 'after' : 'before';
77
+ };
78
+ #drop = event => {
79
+ const target = this.#dropTarget(event);
80
+ if (!target) return;
81
+ event.preventDefault();
82
+ const field = this.#drag.field;
83
+ this.#clearDrag();
84
+ this.#structure().moveColumn(field, target.field, target.after);
85
+ this.#head.querySelector(`th[data-field="${field}"]`).focus({preventScroll:true});
86
+ };
87
+ #clearDrag = () => {
88
+ this.#drag = null;
89
+ for (const cell of this.#head.querySelectorAll('th')) {
90
+ cell.classList.remove('column-dragging'); cell.removeAttribute('data-drop');
91
+ }
92
+ };
93
+ #target(header) {
94
+ const field = header.dataset.field;
95
+ if (field === undefined) {
96
+ const layout = this.#rowLayout();
97
+ return {identity:layout, width:layout.headerWidth, setWidth:width => {
98
+ layout.setHeaderWidth(width); this.#layoutChanged();
99
+ }};
100
+ }
101
+ const structure = this.#structure(), node = structure.columnNode(field);
102
+ return {identity:node, width:node.getAttr('width'), setWidth:width => structure.setColumnWidth(field, width)};
103
+ }
104
+ #minimum(header) {
105
+ if (header.classList.contains('row-heading')) {
106
+ return Math.max(40, Math.ceil(header.querySelector('.row-number-measure').getBoundingClientRect().width));
107
+ }
108
+ return Number.parseFloat(this.#control.ownerDocument.defaultView.getComputedStyle(this.#control)
109
+ .getPropertyValue('--gramlot-grid-column-min-width')) || 40;
110
+ }
111
+ #start = event => {
112
+ this.#suppressClick = false;
113
+ const handle = event.target.closest('.column-resize');
114
+ if (!handle || event.button !== 0 || this.#gesture) return;
115
+ const header = handle.closest('th');
116
+ const field = header.dataset.field;
117
+ const target = this.#target(header);
118
+ const tables = [...this.#control.querySelectorAll('table')];
119
+ const headers = [...this.#head.querySelectorAll('th[scope=col]')];
120
+ const widths = headers.map(cell => cell.getBoundingClientRect().width);
121
+ this.#gesture = {pointerId:event.pointerId, field, header, identity:target.identity, originalWidth:target.width,
122
+ x:event.clientX, index:headers.indexOf(header), widths, width:header.getBoundingClientRect().width,
123
+ tables:tables.map(table => ({table, width:table.style.width,
124
+ columns:[...table.querySelectorAll('col')].map(col => ({col, width:col.style.width}))}))};
125
+ this.#head.setPointerCapture(event.pointerId);
126
+ this.#control.classList.add('resizing');
127
+ event.preventDefault();
128
+ };
129
+ #move = event => {
130
+ const gesture = this.#gesture;
131
+ if (!gesture || gesture.pointerId !== event.pointerId) return;
132
+ gesture.width = Math.max(this.#minimum(gesture.header), Math.round(gesture.widths[gesture.index] + event.clientX - gesture.x));
133
+ const widths = gesture.widths.map((width, index) => index === gesture.index ? gesture.width : width);
134
+ for (const {table, columns} of gesture.tables) {
135
+ table.style.width = `${widths.reduce((sum, width) => sum + width, 0)}px`;
136
+ columns.forEach(({col}, index) => { col.style.width = `${widths[index]}px`; });
137
+ }
138
+ };
139
+ #finish = event => {
140
+ const gesture = this.#gesture;
141
+ if (!gesture || gesture.pointerId !== event.pointerId) return;
142
+ this.#move(event);
143
+ const current = this.#target(gesture.header);
144
+ this.#suppressClick = true;
145
+ this.cancel();
146
+ // A retargeted/replaced struct or concurrent width edit must win over this gesture.
147
+ if (current.identity !== gesture.identity || current.width !== gesture.originalWidth) return;
148
+ current.setWidth(gesture.width);
149
+ this.#focus(gesture.field);
150
+ };
151
+ #key = event => {
152
+ if (event.key === 'Escape' && this.#gesture) {
153
+ this.cancel(); event.preventDefault(); return;
154
+ }
155
+ const handle = event.target.closest('.column-resize');
156
+ if (!handle && ['Enter', ' '].includes(event.key)) {
157
+ const header = event.target.closest('th[data-field]');
158
+ if (header) { event.preventDefault(); this.#sort(header.dataset.field, event.shiftKey); }
159
+ return;
160
+ }
161
+ if (!['ArrowLeft', 'ArrowRight'].includes(event.key)) return;
162
+ if (!handle) {
163
+ const header = event.target.closest('th[data-field]');
164
+ if (!header || !event.altKey) return;
165
+ const field = header.dataset.field, structure = this.#structure();
166
+ const node = structure.columnNode(field), siblings = node.parentBag.getNodes();
167
+ const target = siblings[siblings.indexOf(node) + (event.key === 'ArrowRight' ? 1 : -1)];
168
+ if (target?.getAttr('tag') === 'cell') {
169
+ structure.moveColumn(field, target.getAttr('field'), event.key === 'ArrowRight');
170
+ this.#head.querySelector(`th[data-field="${field}"]`).focus({preventScroll:true});
171
+ }
172
+ event.preventDefault(); return;
173
+ }
174
+ const header = handle.closest('th');
175
+ const delta = (event.key === 'ArrowRight' ? 1 : -1) * (event.shiftKey ? 1 : 10);
176
+ this.#target(header).setWidth(Math.max(this.#minimum(header), Math.round(header.getBoundingClientRect().width + delta)));
177
+ this.#focus(header.dataset.field);
178
+ event.preventDefault();
179
+ };
180
+ #focus(field) {
181
+ this.#head.querySelector(field === undefined ? '.row-heading .column-resize' : `th[data-field="${field}"] .column-resize`).focus({preventScroll:true});
182
+ }
183
+ #cancel = () => { if (this.#gesture) this.cancel(); };
184
+ cancel() {
185
+ this.#clearDrag();
186
+ const gesture = this.#gesture;
187
+ if (!gesture) return;
188
+ this.#gesture = null;
189
+ for (const {table, width, columns} of gesture.tables) {
190
+ table.style.width = width;
191
+ for (const {col, width} of columns) col.style.width = width;
192
+ }
193
+ this.#control.classList.remove('resizing');
194
+ if (this.#head.hasPointerCapture(gesture.pointerId)) this.#head.releasePointerCapture(gesture.pointerId);
195
+ }
196
+ }
@@ -0,0 +1,184 @@
1
+ /** PoC row-header gestures, with preview separated from Source-owned heights. */
2
+ export class GridRowInteraction {
3
+ #body;
4
+ #control;
5
+ #layout;
6
+ #nodeForRow;
7
+ #gesture = null;
8
+ #drag = null;
9
+ #store;
10
+ #dragEnabled;
11
+ #layoutChanged;
12
+ constructor(body, control, layout, nodeForRow, store, dragEnabled, layoutChanged) {
13
+ this.#body = body;
14
+ this.#control = control;
15
+ this.#layout = layout;
16
+ this.#nodeForRow = nodeForRow;
17
+ this.#store = store;
18
+ this.#dragEnabled = dragEnabled;
19
+ this.#layoutChanged = layoutChanged;
20
+ }
21
+ get resizing() { return this.#gesture !== null; }
22
+ connect() {
23
+ this.#body.addEventListener('pointerdown', this.#start);
24
+ this.#body.addEventListener('pointermove', this.#move);
25
+ this.#body.addEventListener('pointerup', this.#finish);
26
+ this.#body.addEventListener('pointercancel', this.#cancel);
27
+ this.#body.addEventListener('lostpointercapture', this.#cancel);
28
+ this.#body.addEventListener('keydown', this.#key);
29
+ this.#body.addEventListener('dblclick', this.#reset);
30
+ this.#body.addEventListener('dragstart', this.#dragStart);
31
+ this.#body.addEventListener('dragover', this.#dragOver);
32
+ this.#body.addEventListener('dragleave', this.#dragLeave);
33
+ this.#body.addEventListener('drop', this.#drop);
34
+ this.#body.addEventListener('dragend', this.#dragEnd);
35
+ }
36
+ disconnect() {
37
+ this.cancel();
38
+ this.cancelDrag();
39
+ this.#body.removeEventListener('pointerdown', this.#start);
40
+ this.#body.removeEventListener('pointermove', this.#move);
41
+ this.#body.removeEventListener('pointerup', this.#finish);
42
+ this.#body.removeEventListener('pointercancel', this.#cancel);
43
+ this.#body.removeEventListener('lostpointercapture', this.#cancel);
44
+ this.#body.removeEventListener('keydown', this.#key);
45
+ this.#body.removeEventListener('dblclick', this.#reset);
46
+ this.#body.removeEventListener('dragstart', this.#dragStart);
47
+ this.#body.removeEventListener('dragover', this.#dragOver);
48
+ this.#body.removeEventListener('dragleave', this.#dragLeave);
49
+ this.#body.removeEventListener('drop', this.#drop);
50
+ this.#body.removeEventListener('dragend', this.#dragEnd);
51
+ }
52
+ #dragStart = event => {
53
+ const row = event.target.closest('tr');
54
+ const node = this.#nodeForRow(row);
55
+ if (!this.#dragEnabled() || !node || this.#gesture || event.target.closest('.row-height-handle')) {
56
+ event.preventDefault(); return;
57
+ }
58
+ this.#drag = {node, bag:this.#store().bag};
59
+ event.dataTransfer.effectAllowed = 'move';
60
+ event.dataTransfer.setData('text/plain', node.label);
61
+ row.classList.add('row-dragging');
62
+ };
63
+ #dropTarget(event) {
64
+ if (!this.#drag || !this.#dragEnabled()) return null;
65
+ const {node, bag} = this.#drag;
66
+ const row = event.target.closest('tr'), target = this.#nodeForRow(row);
67
+ if (!target || target === node || this.#store().bag !== bag || node.parentBag !== bag || target.parentBag !== bag) return null;
68
+ const box = row.getBoundingClientRect();
69
+ return {row, target, after:event.clientY > box.top + box.height/2};
70
+ }
71
+ #clearMarker() {
72
+ for (const row of this.#body.querySelectorAll('[data-row-drop]')) row.removeAttribute('data-row-drop');
73
+ }
74
+ #dragOver = event => {
75
+ this.#clearMarker();
76
+ const target = this.#dropTarget(event);
77
+ if (!target) return;
78
+ event.preventDefault(); event.dataTransfer.dropEffect = 'move';
79
+ target.row.dataset.rowDrop = target.after ? 'after' : 'before';
80
+ };
81
+ #dragLeave = event => {
82
+ if (!this.#body.contains(event.relatedTarget)) this.#clearMarker();
83
+ };
84
+ #drop = event => {
85
+ const target = this.#dropTarget(event);
86
+ if (!target) return;
87
+ event.preventDefault(); event.stopPropagation();
88
+ const {node} = this.#drag;
89
+ this.cancelDrag();
90
+ this.#store().moveRow(node, target.target, target.after);
91
+ };
92
+ #dragEnd = () => { this.cancelDrag(); };
93
+ cancelDrag() {
94
+ this.#drag = null;
95
+ this.#clearMarker();
96
+ for (const row of this.#body.querySelectorAll('.row-dragging')) row.classList.remove('row-dragging');
97
+ }
98
+ #target(event) {
99
+ const handle = event.target.closest('.row-height-handle');
100
+ if (!handle) return null;
101
+ const row = handle.closest('tr');
102
+ const node = this.#nodeForRow(row);
103
+ return node ? {handle, row, node} : null;
104
+ }
105
+ project(row, node) {
106
+ const height = this.#layout().height(node);
107
+ row.style.height = height === null ? '' : `${height}px`;
108
+ }
109
+ #value(row) {
110
+ const handle = row.querySelector('.row-height-handle');
111
+ if (handle) handle.setAttribute('aria-valuenow', String(Math.round(row.getBoundingClientRect().height)));
112
+ this.#layoutChanged();
113
+ }
114
+ #start = event => {
115
+ const target = this.#target(event);
116
+ if (!target || event.button !== 0 || this.#gesture) return;
117
+ const {row} = target;
118
+ const height = row.getBoundingClientRect().height;
119
+ const original = row.style.height;
120
+ // A table row cannot be shorter than its contents; measure that same native layout.
121
+ row.style.height = '';
122
+ const minimum = row.getBoundingClientRect().height;
123
+ row.style.height = original;
124
+ this.#gesture = {...target, pointerId:event.pointerId, y:event.clientY, height, minimum, preview:height};
125
+ target.handle.focus({preventScroll:true});
126
+ target.handle.setPointerCapture(event.pointerId);
127
+ this.#control.classList.add('resizing-row');
128
+ event.preventDefault();
129
+ };
130
+ #move = event => {
131
+ const gesture = this.#gesture;
132
+ if (!gesture || gesture.pointerId !== event.pointerId) return;
133
+ gesture.preview = Math.max(gesture.minimum, Math.round(gesture.height + event.clientY - gesture.y));
134
+ gesture.row.style.height = `${gesture.preview}px`;
135
+ this.#value(gesture.row);
136
+ };
137
+ #finish = event => {
138
+ const gesture = this.#gesture;
139
+ if (!gesture || gesture.pointerId !== event.pointerId) return;
140
+ this.#move(event);
141
+ this.cancel();
142
+ if (this.#nodeForRow(gesture.row) !== gesture.node || gesture.preview === gesture.height) return;
143
+ this.#layout().setHeight(gesture.node, gesture.preview);
144
+ this.project(gesture.row, gesture.node);
145
+ this.#value(gesture.row);
146
+ };
147
+ #key = event => {
148
+ if (event.key === 'Escape' && (this.#gesture || this.#drag)) {
149
+ this.cancel(); this.cancelDrag(); event.preventDefault(); return;
150
+ }
151
+ const target = this.#target(event);
152
+ if (!target || !['ArrowUp','ArrowDown','Home'].includes(event.key)) return;
153
+ this.cancel();
154
+ let height = null;
155
+ if (event.key !== 'Home') {
156
+ const current = target.row.getBoundingClientRect().height;
157
+ target.row.style.height = '';
158
+ const minimum = target.row.getBoundingClientRect().height;
159
+ height = Math.max(minimum, current + (event.key === 'ArrowDown' ? 10 : -10));
160
+ }
161
+ this.#layout().setHeight(target.node, height);
162
+ this.project(target.row, target.node);
163
+ this.#value(target.row);
164
+ event.preventDefault();
165
+ };
166
+ #reset = event => {
167
+ const target = this.#target(event);
168
+ if (!target) return;
169
+ this.cancel();
170
+ this.#layout().setHeight(target.node, null);
171
+ this.project(target.row, target.node);
172
+ this.#value(target.row);
173
+ event.preventDefault();
174
+ };
175
+ #cancel = () => { this.cancel(); };
176
+ cancel() {
177
+ const gesture = this.#gesture;
178
+ if (!gesture) return;
179
+ this.#gesture = null;
180
+ this.project(gesture.row, gesture.node);
181
+ this.#control.classList.remove('resizing-row');
182
+ if (gesture.handle.hasPointerCapture(gesture.pointerId)) gesture.handle.releasePointerCapture(gesture.pointerId);
183
+ }
184
+ }