@dxos/lit-grid 0.6.12-main.5cc132e → 0.6.12-main.7907542

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.
@@ -1,46 +1,202 @@
1
1
  // packages/ui/lit-grid/src/dx-grid.ts
2
- import { LitElement, html } from "lit";
3
- import { customElement, state, property, eventOptions } from "lit/decorators.js";
4
- import { ref, createRef } from "lit/directives/ref.js";
2
+ import { LitElement as LitElement2, html as html2, nothing } from "lit";
3
+ import { customElement as customElement2, state, property as property2 } from "lit/decorators.js";
4
+ import { ref as ref2, createRef } from "lit/directives/ref.js";
5
+ import { styleMap } from "lit/directives/style-map.js";
6
+
7
+ // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
8
+ import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
9
+ import { disableNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview";
10
+ import { preventUnhandled } from "@atlaskit/pragmatic-drag-and-drop/prevent-unhandled";
11
+ import { html, LitElement } from "lit";
12
+ import { customElement, property } from "lit/decorators.js";
13
+ import { ref } from "lit/directives/ref.js";
14
+
15
+ // packages/ui/lit-grid/src/util.ts
16
+ var separator = ",";
17
+ var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
18
+ var colToA1Notation = (col) => {
19
+ return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
20
+ };
21
+ var rowToA1Notation = (row) => {
22
+ return `${row + 1}`;
23
+ };
5
24
 
6
25
  // packages/ui/lit-grid/src/types.ts
7
26
  var DxAxisResize = class extends Event {
8
27
  constructor(props) {
9
28
  super("dx-axis-resize");
10
29
  this.axis = props.axis;
30
+ this.plane = props.plane;
11
31
  this.index = props.index;
12
32
  this.size = props.size;
13
33
  }
14
34
  };
35
+ var DxAxisResizeInternal = class extends Event {
36
+ constructor(props) {
37
+ super("dx-axis-resize-internal", {
38
+ composed: true,
39
+ bubbles: true
40
+ });
41
+ this.axis = props.axis;
42
+ this.plane = props.plane;
43
+ this.index = props.index;
44
+ this.size = props.size;
45
+ this.delta = props.delta;
46
+ this.state = props.state;
47
+ }
48
+ };
15
49
  var DxEditRequest = class extends Event {
16
50
  constructor(props) {
17
51
  super("dx-edit-request");
18
52
  this.cellIndex = props.cellIndex;
19
53
  this.cellBox = props.cellBox;
54
+ this.initialContent = props.initialContent;
55
+ }
56
+ };
57
+ var DxGridCellsSelect = class extends Event {
58
+ constructor({ start, end }) {
59
+ super("dx-grid-cells-select");
60
+ this.start = toCellIndex(start);
61
+ this.end = toCellIndex(end);
62
+ this.minCol = Math.min(start.col, end.col);
63
+ this.maxCol = Math.max(start.col, end.col);
64
+ this.minRow = Math.min(start.row, end.row);
65
+ this.maxRow = Math.max(start.row, end.row);
20
66
  }
21
67
  };
22
68
 
23
- // packages/ui/lit-grid/src/dx-grid.ts
69
+ // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
24
70
  function _ts_decorate(decorators, target, key, desc) {
25
71
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
72
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
27
73
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
28
74
  return c > 3 && r && Object.defineProperty(target, key, r), r;
29
75
  }
76
+ var DxGridAxisResizeHandle = class extends LitElement {
77
+ constructor() {
78
+ super(...arguments);
79
+ this.axis = "row";
80
+ this.plane = "grid";
81
+ this.index = "-1";
82
+ this.size = 128;
83
+ this.dragStartSize = 128;
84
+ this.cleanup = null;
85
+ }
86
+ render() {
87
+ return html`<button class="dx-grid__resize-handle" data-dx-grid-axis=${this.axis} ${ref(this.mount)}>
88
+ <span class="sr-only">Resize</span>
89
+ </button>`;
90
+ }
91
+ dispatchResize(location, state2) {
92
+ const client = this.axis === "row" ? "clientY" : "clientX";
93
+ const event = new DxAxisResizeInternal({
94
+ axis: this.axis,
95
+ plane: this.plane,
96
+ size: this.dragStartSize,
97
+ index: this.index,
98
+ delta: location.current.input[client] - location.initial.input[client],
99
+ state: state2
100
+ });
101
+ this.dispatchEvent(event);
102
+ }
103
+ mount(element) {
104
+ this.cleanup?.();
105
+ const host = this;
106
+ if (element) {
107
+ this.cleanup = draggable({
108
+ element,
109
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
110
+ disableNativeDragPreview({
111
+ nativeSetDragImage
112
+ });
113
+ preventUnhandled.start();
114
+ },
115
+ onDragStart() {
116
+ host.dragStartSize = host.size;
117
+ },
118
+ onDrag({ location }) {
119
+ host.dispatchResize(location, "dragging");
120
+ },
121
+ onDrop({ location }) {
122
+ host.dispatchResize(location, "dropped");
123
+ }
124
+ });
125
+ }
126
+ }
127
+ disconnectedCallback() {
128
+ super.disconnectedCallback();
129
+ this.cleanup?.();
130
+ }
131
+ createRenderRoot() {
132
+ return this;
133
+ }
134
+ };
135
+ _ts_decorate([
136
+ property({
137
+ type: String
138
+ })
139
+ ], DxGridAxisResizeHandle.prototype, "axis", void 0);
140
+ _ts_decorate([
141
+ property({
142
+ type: String
143
+ })
144
+ ], DxGridAxisResizeHandle.prototype, "plane", void 0);
145
+ _ts_decorate([
146
+ property({
147
+ type: String
148
+ })
149
+ ], DxGridAxisResizeHandle.prototype, "index", void 0);
150
+ _ts_decorate([
151
+ property({
152
+ type: Number
153
+ })
154
+ ], DxGridAxisResizeHandle.prototype, "size", void 0);
155
+ DxGridAxisResizeHandle = _ts_decorate([
156
+ customElement("dx-grid-axis-resize-handle")
157
+ ], DxGridAxisResizeHandle);
158
+
159
+ // packages/ui/lit-grid/src/dx-grid.ts
160
+ function _ts_decorate2(decorators, target, key, desc) {
161
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
162
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
163
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
164
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
165
+ }
30
166
  var gap = 1;
31
- var resizeTolerance = 8;
167
+ var resizeTolerance = 1;
168
+ var selectTolerance = 4;
32
169
  var overscanCol = 1;
33
170
  var overscanRow = 1;
34
171
  var sizeColMin = 32;
35
172
  var sizeColMax = 1024;
36
173
  var sizeRowMin = 16;
37
174
  var sizeRowMax = 1024;
38
- var separator = ",";
39
- var colToA1Notation = (col) => {
40
- return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
175
+ var shouldSelect = (pointer, { pageX, pageY }) => {
176
+ if (pointer?.state === "maybeSelecting") {
177
+ return Math.hypot(Math.abs(pointer.pageX - pageX), Math.abs(pointer.pageY - pageY)) >= selectTolerance;
178
+ } else {
179
+ return false;
180
+ }
41
181
  };
42
- var rowToA1Notation = (row) => {
43
- return `${row + 1}`;
182
+ var selectionProps = (selectionStart, selectionEnd) => {
183
+ const colMin = Math.min(selectionStart.col, selectionEnd.col);
184
+ const colMax = Math.max(selectionStart.col, selectionEnd.col);
185
+ const rowMin = Math.min(selectionStart.row, selectionEnd.row);
186
+ const rowMax = Math.max(selectionStart.row, selectionEnd.row);
187
+ const plane = selectionStart.plane;
188
+ const visible = colMin !== colMax || rowMin !== rowMax;
189
+ return {
190
+ colMin,
191
+ colMax,
192
+ rowMin,
193
+ rowMax,
194
+ plane,
195
+ visible
196
+ };
197
+ };
198
+ var cellSelected = (col, row, plane, selection) => {
199
+ return plane === selection.plane && col >= selection.colMin && col <= selection.colMax && row >= selection.rowMin && row <= selection.rowMax;
44
200
  };
45
201
  var closestAction = (target) => {
46
202
  const actionEl = target?.closest("[data-dx-grid-action]") ?? null;
@@ -60,7 +216,9 @@ var closestCell = (target, actionEl) => {
60
216
  if (cellElement) {
61
217
  const col = parseInt(cellElement.getAttribute("aria-colindex") ?? "never");
62
218
  const row = parseInt(cellElement.getAttribute("aria-rowindex") ?? "never");
219
+ const plane = cellElement.closest("[data-dx-grid-plane]")?.getAttribute("data-dx-grid-plane") ?? "grid";
63
220
  return {
221
+ plane,
64
222
  col,
65
223
  row
66
224
  };
@@ -68,24 +226,92 @@ var closestCell = (target, actionEl) => {
68
226
  return null;
69
227
  }
70
228
  };
71
- var isSameCell = (a, b) => a && b && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
72
- var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
73
- var localChId = (c0) => `ch--${c0}`;
74
- var localRhId = (r0) => `rh--${r0}`;
75
- var getPage = (axis, event) => axis === "col" ? event.pageX : event.pageY;
76
- var DxGrid = class extends LitElement {
229
+ var resolveRowPlane = (plane) => {
230
+ switch (plane) {
231
+ case "fixedStartStart":
232
+ case "fixedStartEnd":
233
+ case "frozenRowsStart":
234
+ return "frozenRowsStart";
235
+ case "fixedEndStart":
236
+ case "fixedEndEnd":
237
+ case "frozenRowsEnd":
238
+ return "frozenRowsEnd";
239
+ default:
240
+ return "grid";
241
+ }
242
+ };
243
+ var resolveColPlane = (plane) => {
244
+ switch (plane) {
245
+ case "fixedStartStart":
246
+ case "fixedEndStart":
247
+ case "frozenColsStart":
248
+ return "frozenColsStart";
249
+ case "fixedStartEnd":
250
+ case "fixedEndEnd":
251
+ case "frozenColsEnd":
252
+ return "frozenColsEnd";
253
+ default:
254
+ return "grid";
255
+ }
256
+ };
257
+ var resolveResizePlane = (resizeAxis, cellPlane) => {
258
+ switch (cellPlane) {
259
+ case "fixedStartStart":
260
+ return resizeAxis === "col" ? "frozenColsStart" : "frozenRowsStart";
261
+ case "fixedStartEnd":
262
+ return resizeAxis === "col" ? "frozenColsEnd" : "frozenRowsStart";
263
+ case "fixedEndStart":
264
+ return resizeAxis === "col" ? "frozenColsStart" : "frozenRowsEnd";
265
+ case "fixedEndEnd":
266
+ return resizeAxis === "col" ? "frozenColsEnd" : "frozenRowsEnd";
267
+ case "frozenColsStart":
268
+ case "frozenColsEnd":
269
+ return resizeAxis === "col" ? cellPlane : "grid";
270
+ case "frozenRowsStart":
271
+ case "frozenRowsEnd":
272
+ return resizeAxis === "row" ? cellPlane : "grid";
273
+ default:
274
+ return cellPlane;
275
+ }
276
+ };
277
+ var isSameCell = (a, b) => a && b && a.plane === b.plane && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
278
+ var defaultRowSize = 32;
279
+ var defaultColSize = 180;
280
+ var DxGrid = class extends LitElement2 {
77
281
  constructor() {
78
- super(...arguments);
282
+ super();
283
+ this.gridId = "default-grid-id";
79
284
  this.rowDefault = {
80
- size: 32
285
+ grid: {
286
+ size: defaultRowSize
287
+ }
81
288
  };
82
289
  this.columnDefault = {
83
- size: 180
290
+ grid: {
291
+ size: defaultColSize
292
+ }
293
+ };
294
+ this.rows = {
295
+ grid: {}
296
+ };
297
+ this.columns = {
298
+ grid: {}
299
+ };
300
+ this.initialCells = {
301
+ grid: {}
84
302
  };
85
- this.rows = {};
86
- this.columns = {};
87
- this.cells = {};
88
303
  this.mode = "browse";
304
+ this.limitColumns = Infinity;
305
+ this.limitRows = Infinity;
306
+ this.frozen = {};
307
+ /**
308
+ * When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back
309
+ * to `cells`.
310
+ */
311
+ this.getCells = null;
312
+ this.cells = {
313
+ grid: {}
314
+ };
89
315
  //
90
316
  // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
91
317
  //
@@ -105,9 +331,9 @@ var DxGrid = class extends LitElement {
105
331
  // `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.
106
332
  //
107
333
  this.binInlineMin = 0;
108
- this.binInlineMax = this.colSize(0);
334
+ this.binInlineMax = defaultColSize;
109
335
  this.binBlockMin = 0;
110
- this.binBlockMax = this.rowSize(0);
336
+ this.binBlockMax = defaultRowSize;
111
337
  //
112
338
  // `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
113
339
  // the viewport. These start with naïve values that are updated before first contentful render.
@@ -119,68 +345,89 @@ var DxGrid = class extends LitElement {
119
345
  //
120
346
  // `template` is the rendered value of `grid-{axis}-template`.
121
347
  //
122
- this.templateColumns = `${this.colSize(0)}px`;
123
- this.templateRows = `${this.rowSize(0)}px`;
348
+ this.templateGridColumns = "0";
349
+ this.templatefrozenColsStart = "";
350
+ this.templatefrozenColsEnd = "";
351
+ this.templateGridRows = "0";
352
+ this.templatefrozenRowsStart = "";
353
+ this.templatefrozenRowsEnd = "";
124
354
  //
125
- // Resize state
355
+ // Focus, selection, and resize states
126
356
  //
127
- this.colSizes = {};
128
- this.rowSizes = {};
129
- this.resizing = null;
357
+ this.pointer = null;
358
+ this.colSizes = {
359
+ grid: {}
360
+ };
361
+ this.rowSizes = {
362
+ grid: {}
363
+ };
364
+ this.focusActive = false;
365
+ this.focusedCell = {
366
+ plane: "grid",
367
+ col: 0,
368
+ row: 0
369
+ };
370
+ this.selectionStart = {
371
+ plane: "grid",
372
+ col: 0,
373
+ row: 0
374
+ };
375
+ this.selectionEnd = {
376
+ plane: "grid",
377
+ col: 0,
378
+ row: 0
379
+ };
130
380
  //
131
- // Primary pointer and keyboard handlers
381
+ // Limits
132
382
  //
383
+ this.intrinsicInlineSize = Infinity;
384
+ this.intrinsicBlockSize = Infinity;
133
385
  this.handlePointerDown = (event) => {
134
- const { action, actionEl } = closestAction(event.target);
135
- if (action) {
136
- if (action.startsWith("resize") && this.mode === "browse") {
137
- const [resize, index] = action.split(",");
138
- const [_, axis] = resize.split("-");
139
- this.resizing = {
140
- axis,
141
- size: axis === "col" ? this.colSize(index) : this.rowSize(index),
142
- page: getPage(axis, event),
143
- index
144
- };
145
- } else if (action === "cell") {
146
- const cellCoords = closestCell(event.target, actionEl);
147
- if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
148
- this.dispatchEvent(new DxEditRequest({
149
- cellIndex: toCellIndex(cellCoords),
150
- cellBox: this.focusedCellBox()
151
- }));
386
+ if (event.isPrimary) {
387
+ const { action, actionEl } = closestAction(event.target);
388
+ if (action) {
389
+ if (action === "cell") {
390
+ const cellCoords = closestCell(event.target, actionEl);
391
+ if (cellCoords) {
392
+ this.pointer = {
393
+ state: "maybeSelecting",
394
+ pageX: event.pageX,
395
+ pageY: event.pageY
396
+ };
397
+ this.selectionStart = cellCoords;
398
+ this.selectionEnd = cellCoords;
399
+ }
400
+ if (this.mode === "edit") {
401
+ event.preventDefault();
402
+ } else {
403
+ if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
404
+ this.dispatchEditRequest();
405
+ }
406
+ }
152
407
  }
153
408
  }
154
409
  }
155
410
  };
156
- this.handlePointerUp = (_event) => {
157
- if (this.resizing) {
158
- const resizeEvent = new DxAxisResize({
159
- axis: this.resizing.axis,
160
- index: this.resizing.index,
161
- size: this[this.resizing.axis === "col" ? "colSize" : "rowSize"](this.resizing.index)
162
- });
163
- this.dispatchEvent(resizeEvent);
164
- this.resizing = null;
411
+ this.handlePointerUp = (event) => {
412
+ const cell = closestCell(event.target);
413
+ if (cell) {
414
+ this.selectionEnd = cell;
415
+ this.dispatchEvent(new DxGridCellsSelect({
416
+ start: this.selectionStart,
417
+ end: this.selectionEnd
418
+ }));
165
419
  }
420
+ this.pointer = null;
166
421
  };
167
422
  this.handlePointerMove = (event) => {
168
- if (this.resizing) {
169
- const delta = getPage(this.resizing.axis, event) - this.resizing.page;
170
- if (this.resizing.axis === "col") {
171
- const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.resizing.size + delta));
172
- this.colSizes = {
173
- ...this.colSizes,
174
- [this.resizing.index]: nextSize
175
- };
176
- this.updateVisInline();
177
- } else {
178
- const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.resizing.size + delta));
179
- this.rowSizes = {
180
- ...this.rowSizes,
181
- [this.resizing.index]: nextSize
182
- };
183
- this.updateVisBlock();
423
+ if (shouldSelect(this.pointer, event)) {
424
+ this.pointer = {
425
+ state: "selecting"
426
+ };
427
+ } else if (this.pointer?.state === "selecting") {
428
+ const cell = closestCell(event.target);
429
+ if (cell && cell.plane === this.selectionStart.plane && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
430
+ this.selectionEnd = cell;
184
431
  }
185
432
  }
186
433
  };
@@ -196,25 +443,51 @@ var DxGrid = class extends LitElement {
196
443
  this.sizeInline = inlineSize;
197
444
  this.sizeBlock = blockSize;
198
445
  this.updateVis();
446
+ queueMicrotask(() => this.updatePos());
199
447
  }
200
448
  });
201
449
  this.viewportRef = createRef();
450
+ this.maybeUpdateVisInline = () => {
451
+ if (this.posInline < this.binInlineMin || this.posInline >= this.binInlineMax) {
452
+ this.updateVisInline();
453
+ }
454
+ };
455
+ this.maybeUpdateVisBlock = () => {
456
+ if (this.posBlock < this.binBlockMin || this.posBlock >= this.binBlockMax) {
457
+ this.updateVisBlock();
458
+ }
459
+ };
202
460
  this.handleWheel = ({ deltaX, deltaY }) => {
203
461
  if (this.mode === "browse") {
204
- this.posInline = Math.max(0, this.posInline + deltaX);
205
- this.posBlock = Math.max(0, this.posBlock + deltaY);
206
- if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
207
- } else {
208
- this.updateVis();
209
- }
462
+ this.updatePos(this.posInline + deltaX, this.posBlock + deltaY);
210
463
  }
211
464
  };
212
- // Focus handlers
213
- this.focusedCell = {
214
- col: 0,
215
- row: 0
216
- };
217
- this.focusActive = false;
465
+ this.addEventListener("dx-axis-resize-internal", this.handleAxisResizeInternal);
466
+ this.addEventListener("wheel", this.handleWheel, {
467
+ passive: true
468
+ });
469
+ this.addEventListener("pointerdown", this.handlePointerDown);
470
+ this.addEventListener("pointermove", this.handlePointerMove);
471
+ this.addEventListener("pointerup", this.handlePointerUp);
472
+ this.addEventListener("pointerleave", this.handlePointerUp);
473
+ this.addEventListener("focus", this.handleFocus, {
474
+ capture: true
475
+ });
476
+ this.addEventListener("blur", this.handleBlur, {
477
+ capture: true
478
+ });
479
+ this.addEventListener("keydown", this.handleKeydown);
480
+ }
481
+ //
482
+ // Primary pointer and keyboard handlers
483
+ //
484
+ dispatchEditRequest(initialContent) {
485
+ this.snapPosToFocusedCell();
486
+ queueMicrotask(() => this.dispatchEvent(new DxEditRequest({
487
+ cellIndex: toCellIndex(this.focusedCell),
488
+ cellBox: this.focusedCellBox(),
489
+ initialContent
490
+ })));
218
491
  }
219
492
  handleKeydown(event) {
220
493
  if (this.focusActive && this.mode === "browse") {
@@ -222,7 +495,7 @@ var DxGrid = class extends LitElement {
222
495
  case "ArrowDown":
223
496
  this.focusedCell = {
224
497
  ...this.focusedCell,
225
- row: this.focusedCell.row + 1
498
+ row: Math.min(this.limitRows - 1, this.focusedCell.row + 1)
226
499
  };
227
500
  break;
228
501
  case "ArrowUp":
@@ -234,7 +507,7 @@ var DxGrid = class extends LitElement {
234
507
  case "ArrowRight":
235
508
  this.focusedCell = {
236
509
  ...this.focusedCell,
237
- col: this.focusedCell.col + 1
510
+ col: Math.min(this.limitColumns - 1, this.focusedCell.col + 1)
238
511
  };
239
512
  break;
240
513
  case "ArrowLeft":
@@ -246,10 +519,12 @@ var DxGrid = class extends LitElement {
246
519
  }
247
520
  switch (event.key) {
248
521
  case "Enter":
249
- this.dispatchEvent(new DxEditRequest({
250
- cellIndex: toCellIndex(this.focusedCell),
251
- cellBox: this.focusedCellBox()
252
- }));
522
+ this.dispatchEditRequest();
523
+ break;
524
+ default:
525
+ if (event.key.length === 1 && event.key.match(/\P{Cc}/u)) {
526
+ this.dispatchEditRequest(event.key);
527
+ }
253
528
  break;
254
529
  }
255
530
  switch (event.key) {
@@ -266,20 +541,26 @@ var DxGrid = class extends LitElement {
266
541
  //
267
542
  // Accessors
268
543
  //
269
- colSize(c) {
270
- return this.colSizes?.[c] ?? this.columnDefault.size;
544
+ colSize(c, plane) {
545
+ const resolvedPlane = resolveColPlane(plane);
546
+ return this.colSizes?.[resolvedPlane]?.[c] ?? this.columnDefault[resolvedPlane]?.size ?? defaultColSize;
547
+ }
548
+ rowSize(r, plane) {
549
+ const resolvedPlane = resolveRowPlane(plane);
550
+ return this.rowSizes?.[resolvedPlane]?.[r] ?? this.rowDefault[resolvedPlane]?.size ?? defaultRowSize;
271
551
  }
272
- rowSize(r) {
273
- return this.rowSizes?.[r] ?? this.rowDefault.size;
552
+ cell(c, r, plane) {
553
+ const index = `${c}${separator}${r}`;
554
+ return this.cells?.[plane]?.[index] ?? this.initialCells?.[plane]?.[index];
274
555
  }
275
- cell(c, r) {
276
- return this.cells[`${c}${separator}${r}`];
556
+ cellActive(c, r, plane) {
557
+ return this.focusActive && this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r;
277
558
  }
278
559
  focusedCellBox() {
279
560
  const cellElement = this.focusedCellElement();
280
561
  const cellSize = {
281
- inlineSize: this.colSize(this.focusedCell.col),
282
- blockSize: this.rowSize(this.focusedCell.row)
562
+ inlineSize: this.colSize(this.focusedCell.col, this.focusedCell.plane),
563
+ blockSize: this.rowSize(this.focusedCell.row, this.focusedCell.plane)
283
564
  };
284
565
  if (!cellElement) {
285
566
  return {
@@ -299,60 +580,168 @@ var DxGrid = class extends LitElement {
299
580
  ...cellSize
300
581
  };
301
582
  }
583
+ updatePosInline(inline) {
584
+ this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, inline ?? this.posInline));
585
+ this.maybeUpdateVisInline();
586
+ }
587
+ updatePosBlock(block) {
588
+ this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, block ?? this.posBlock));
589
+ this.maybeUpdateVisBlock();
590
+ }
591
+ updatePos(inline, block) {
592
+ this.updatePosInline(inline);
593
+ this.updatePosBlock(block);
594
+ }
302
595
  updateVisInline() {
303
596
  let colIndex = 0;
304
- let pxInline = this.colSize(colIndex);
597
+ let pxInline = this.colSize(colIndex, "grid");
305
598
  while (pxInline < this.posInline) {
306
599
  colIndex += 1;
307
- pxInline += this.colSize(colIndex) + gap;
600
+ pxInline += this.colSize(colIndex, "grid") + gap;
308
601
  }
309
602
  this.visColMin = colIndex - overscanCol;
310
- this.binInlineMin = pxInline - this.colSize(colIndex) - gap;
603
+ this.binInlineMin = pxInline - this.colSize(colIndex, "grid") - gap;
311
604
  this.binInlineMax = pxInline + gap;
312
605
  this.overscanInline = [
313
606
  ...Array(overscanCol)
314
607
  ].reduce((acc, _, c0) => {
315
- acc += this.colSize(this.visColMin + c0);
608
+ acc += this.colSize(this.visColMin + c0, "grid");
316
609
  return acc;
317
610
  }, 0) + gap * (overscanCol - 1);
318
- while (pxInline < this.binInlineMax + this.sizeInline + gap) {
611
+ while (pxInline < this.binInlineMax + this.sizeInline - gap * 2) {
319
612
  colIndex += 1;
320
- pxInline += this.colSize(colIndex) + gap;
613
+ pxInline += this.colSize(colIndex, "grid") + gap;
321
614
  }
322
- this.visColMax = colIndex + overscanCol;
323
- this.templateColumns = [
615
+ this.visColMax = Math.min(this.limitColumns, colIndex + overscanCol);
616
+ this.templateGridColumns = [
324
617
  ...Array(this.visColMax - this.visColMin)
325
- ].map((_, c0) => `${this.colSize(this.visColMin + c0)}px`).join(" ");
618
+ ].map((_, c0) => `${this.colSize(this.visColMin + c0, "grid")}px`).join(" ");
619
+ this.templatefrozenColsStart = [
620
+ ...Array(this.frozen.frozenColsStart ?? 0)
621
+ ].map((_, c0) => `${this.colSize(c0, "frozenColsStart")}px`).join(" ");
622
+ this.templatefrozenColsEnd = [
623
+ ...Array(this.frozen.frozenColsEnd ?? 0)
624
+ ].map((_, c0) => `${this.colSize(c0, "frozenColsEnd")}px`).join(" ");
326
625
  }
327
626
  updateVisBlock() {
328
627
  let rowIndex = 0;
329
- let pxBlock = this.rowSize(rowIndex);
628
+ let pxBlock = this.rowSize(rowIndex, "grid");
330
629
  while (pxBlock < this.posBlock) {
331
630
  rowIndex += 1;
332
- pxBlock += this.rowSize(rowIndex) + gap;
631
+ pxBlock += this.rowSize(rowIndex, "grid") + gap;
333
632
  }
334
633
  this.visRowMin = rowIndex - overscanRow;
335
- this.binBlockMin = pxBlock - this.rowSize(rowIndex) - gap;
634
+ this.binBlockMin = pxBlock - this.rowSize(rowIndex, "grid") - gap;
336
635
  this.binBlockMax = pxBlock + gap;
337
636
  this.overscanBlock = [
338
637
  ...Array(overscanRow)
339
638
  ].reduce((acc, _, r0) => {
340
- acc += this.rowSize(this.visRowMin + r0);
639
+ acc += this.rowSize(this.visRowMin + r0, "grid");
341
640
  return acc;
342
641
  }, 0) + gap * (overscanRow - 1);
343
- while (pxBlock < this.binBlockMax + this.sizeBlock) {
642
+ while (pxBlock < this.binBlockMax + this.sizeBlock - gap * 2) {
344
643
  rowIndex += 1;
345
- pxBlock += this.rowSize(rowIndex) + gap;
644
+ pxBlock += this.rowSize(rowIndex, "grid") + gap;
346
645
  }
347
- this.visRowMax = rowIndex + overscanRow;
348
- this.templateRows = [
646
+ this.visRowMax = Math.min(this.limitRows, rowIndex + overscanRow);
647
+ this.templateGridRows = [
349
648
  ...Array(this.visRowMax - this.visRowMin)
350
- ].map((_, r0) => `${this.rowSize(this.visRowMin + r0)}px`).join(" ");
649
+ ].map((_, r0) => `${this.rowSize(this.visRowMin + r0, "grid")}px`).join(" ");
650
+ this.templatefrozenRowsStart = [
651
+ ...Array(this.frozen.frozenRowsStart ?? 0)
652
+ ].map((_, r0) => `${this.rowSize(r0, "frozenRowsStart")}px`).join(" ");
653
+ this.templatefrozenRowsEnd = [
654
+ ...Array(this.frozen.frozenRowsEnd ?? 0)
655
+ ].map((_, r0) => `${this.rowSize(r0, "frozenRowsEnd")}px`).join(" ");
351
656
  }
352
657
  updateVis() {
353
658
  this.updateVisInline();
354
659
  this.updateVisBlock();
355
660
  }
661
+ updateCells(includeFixed) {
662
+ this.cells.grid = this.getCells({
663
+ start: {
664
+ col: this.visColMin,
665
+ row: this.visRowMin
666
+ },
667
+ end: {
668
+ col: this.visColMax,
669
+ row: this.visRowMax
670
+ }
671
+ }, "grid");
672
+ Object.entries(this.frozen).filter(([_, limit]) => limit && limit > 0).forEach(([plane, limit]) => {
673
+ this.cells[plane] = this.getCells(plane.startsWith("frozenRows") ? {
674
+ start: {
675
+ col: this.visColMin,
676
+ row: 0
677
+ },
678
+ end: {
679
+ col: this.visColMax,
680
+ row: limit
681
+ }
682
+ } : {
683
+ start: {
684
+ col: 0,
685
+ row: this.visRowMin
686
+ },
687
+ end: {
688
+ col: limit,
689
+ row: this.visRowMax
690
+ }
691
+ }, plane);
692
+ });
693
+ if (includeFixed) {
694
+ if ((this.frozen.frozenColsStart ?? 0) > 0 && (this.frozen.frozenRowsStart ?? 0) > 0) {
695
+ this.cells.fixedStartStart = this.getCells({
696
+ start: {
697
+ col: 0,
698
+ row: 0
699
+ },
700
+ end: {
701
+ col: this.frozen.frozenColsStart,
702
+ row: this.frozen.frozenRowsStart
703
+ }
704
+ }, "fixedStartStart");
705
+ }
706
+ if ((this.frozen.frozenColsEnd ?? 0) > 0 && (this.frozen.frozenRowsStart ?? 0) > 0) {
707
+ this.cells.fixedStartEnd = this.getCells({
708
+ start: {
709
+ col: 0,
710
+ row: 0
711
+ },
712
+ end: {
713
+ col: this.frozen.frozenColsEnd,
714
+ row: this.frozen.frozenRowsStart
715
+ }
716
+ }, "fixedStartEnd");
717
+ }
718
+ if ((this.frozen.frozenColsStart ?? 0) > 0 && (this.frozen.frozenRowsEnd ?? 0) > 0) {
719
+ this.cells.fixedEndStart = this.getCells({
720
+ start: {
721
+ col: 0,
722
+ row: 0
723
+ },
724
+ end: {
725
+ col: this.frozen.frozenColsStart,
726
+ row: this.frozen.frozenRowsEnd
727
+ }
728
+ }, "fixedEndStart");
729
+ }
730
+ if ((this.frozen.frozenColsEnd ?? 0) > 0 && (this.frozen.frozenRowsEnd ?? 0) > 0) {
731
+ this.cells.fixedEndEnd = this.getCells({
732
+ start: {
733
+ col: 0,
734
+ row: 0
735
+ },
736
+ end: {
737
+ col: this.frozen.frozenColsEnd,
738
+ row: this.frozen.frozenRowsEnd
739
+ }
740
+ }, "fixedEndEnd");
741
+ }
742
+ }
743
+ }
744
+ // Focus handlers
356
745
  handleFocus(event) {
357
746
  const cellCoords = closestCell(event.target);
358
747
  if (cellCoords) {
@@ -361,136 +750,298 @@ var DxGrid = class extends LitElement {
361
750
  }
362
751
  }
363
752
  handleBlur(event) {
364
- if (!event.relatedTarget || event.relatedTarget.closest(".dx-grid__viewport") !== this.viewportRef.value) {
753
+ if (!event.relatedTarget || !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
365
754
  this.focusActive = false;
366
755
  }
367
756
  }
368
757
  focusedCellElement() {
369
- return this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
758
+ return this.viewportRef.value?.querySelector(`[data-dx-grid-plane=${this.focusedCell.plane}] > [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
759
+ }
760
+ //
761
+ // `outOfVis` returns by how many rows/cols the focused cell is outside of the `vis` range for an axis, inset by a
762
+ // `delta`, otherwise zero if it is within that range.
763
+ //
764
+ focusedCellRowOutOfVis(minDelta = 0, maxDelta = minDelta) {
765
+ return this.focusedCell.row <= this.visRowMin + minDelta ? this.focusedCell.row - (this.visRowMin + minDelta) : this.focusedCell.row >= this.visRowMax - maxDelta ? -(this.focusedCell.row - this.visRowMax - maxDelta) : 0;
766
+ }
767
+ focusedCellColOutOfVis(minDelta = 0, maxDelta = minDelta) {
768
+ return this.focusedCell.col <= this.visColMin + minDelta ? this.focusedCell.col - (this.visColMin + minDelta) : this.focusedCell.col >= this.visColMax - maxDelta ? -(this.focusedCell.col - this.visColMax - maxDelta) : 0;
769
+ }
770
+ focusedCellOutOfVis(colDelta = 0, rowDelta = colDelta) {
771
+ switch (this.focusedCell.plane) {
772
+ case "grid":
773
+ return {
774
+ row: this.focusedCellRowOutOfVis(rowDelta),
775
+ col: this.focusedCellColOutOfVis(colDelta)
776
+ };
777
+ case "frozenRowsStart":
778
+ case "frozenRowsEnd":
779
+ return {
780
+ col: this.focusedCellColOutOfVis(colDelta),
781
+ row: 0
782
+ };
783
+ case "frozenColsStart":
784
+ case "frozenColsEnd":
785
+ return {
786
+ col: 0,
787
+ row: this.focusedCellRowOutOfVis(rowDelta)
788
+ };
789
+ default:
790
+ return {
791
+ col: 0,
792
+ row: 0
793
+ };
794
+ }
370
795
  }
371
796
  /**
372
797
  * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
373
798
  */
374
- refocus(increment) {
799
+ refocus(increment, delta = 1) {
375
800
  switch (increment) {
376
- case "down":
801
+ case "row":
377
802
  this.focusedCell = {
378
803
  ...this.focusedCell,
379
- row: this.focusedCell.row + 1
804
+ row: this.focusedCell.row + delta
380
805
  };
381
806
  break;
382
- case "right":
807
+ case "col":
383
808
  this.focusedCell = {
384
809
  ...this.focusedCell,
385
- col: this.focusedCell.col + 1
810
+ col: this.focusedCell.col + delta
386
811
  };
387
812
  }
388
- (this.focusedCell.row < this.visRowMin || this.focusedCell.row > this.visRowMax || this.focusedCell.col < this.visColMin || this.focusedCell.col > this.visColMax ? this.viewportRef.value : this.focusedCellElement())?.focus({
389
- preventScroll: true
813
+ if (increment) {
814
+ this.snapPosToFocusedCell();
815
+ }
816
+ queueMicrotask(() => {
817
+ const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
818
+ (outOfVis.col !== 0 || outOfVis.row !== 0 ? this.viewportRef.value : this.focusedCellElement())?.focus({
819
+ preventScroll: true
820
+ });
390
821
  });
391
822
  }
823
+ findPosInlineFromVisColMin(deltaCols) {
824
+ return [
825
+ ...Array(deltaCols)
826
+ ].reduce((acc, _, c0) => acc - this.colSize(this.visColMin - c0, "grid") - gap, this.binInlineMin + gap);
827
+ }
828
+ findPosBlockFromVisRowMin(deltaRows) {
829
+ return [
830
+ ...Array(deltaRows)
831
+ ].reduce((acc, _, r0) => acc - this.rowSize(this.visRowMin - r0, "grid") - gap, this.binBlockMin + gap);
832
+ }
392
833
  /**
393
834
  * Updates `pos` so that a cell in focus is fully within the viewport
394
835
  */
395
836
  snapPosToFocusedCell() {
396
- if (this.focusedCell.col < this.visColMin || this.focusedCell.col > this.visColMax || this.focusedCell.row < this.visRowMin || this.focusedCell.row > this.visRowMax) {
397
- } else if (this.focusedCell.col > this.visColMin + overscanCol && this.focusedCell.col < this.visColMax - overscanCol - 1 && this.focusedCell.row > this.visRowMin + overscanRow && this.focusedCell.row < this.visRowMax - overscanRow - 1) {
837
+ const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
838
+ if (outOfVis.col < 0) {
839
+ this.posInline = this.findPosInlineFromVisColMin(-outOfVis.col);
840
+ this.updateVisInline();
841
+ } else if (outOfVis.col > 0) {
842
+ const sizeSumCol = [
843
+ ...Array(this.focusedCell.col - this.visColMin)
844
+ ].reduce((acc, _, c0) => {
845
+ acc += this.colSize(this.visColMin + overscanCol + c0, "grid") + gap;
846
+ return acc;
847
+ }, 0);
848
+ this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, this.binInlineMin + sizeSumCol - this.sizeInline));
849
+ this.updateVisInline();
850
+ }
851
+ if (outOfVis.row < 0) {
852
+ this.posBlock = this.findPosBlockFromVisRowMin(-outOfVis.row);
853
+ this.updateVisBlock();
854
+ } else if (outOfVis.row > 0) {
855
+ const sizeSumRow = [
856
+ ...Array(this.focusedCell.row - this.visRowMin)
857
+ ].reduce((acc, _, r0) => {
858
+ acc += this.rowSize(this.visRowMin + overscanRow + r0, "grid") + gap;
859
+ return acc;
860
+ }, 0);
861
+ this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, this.binBlockMin + sizeSumRow - this.sizeBlock));
862
+ this.updateVisBlock();
863
+ }
864
+ }
865
+ //
866
+ // Map scroll DOM methods to virtualized value.
867
+ //
868
+ get scrollLeft() {
869
+ return this.posInline;
870
+ }
871
+ set scrollLeft(nextValue) {
872
+ this.posInline = nextValue;
873
+ this.maybeUpdateVisInline();
874
+ }
875
+ get scrollTop() {
876
+ return this.posBlock;
877
+ }
878
+ set scrollTop(nextValue) {
879
+ this.posBlock = nextValue;
880
+ this.maybeUpdateVisBlock();
881
+ }
882
+ //
883
+ // Resize handlers
884
+ //
885
+ axisResizeable(plane, axis, index) {
886
+ return axis === "col" ? !!(this.columns[plane]?.[index]?.resizeable ?? this.columnDefault[plane]?.resizeable) : !!(this.rows[plane]?.[index]?.resizeable ?? this.rowDefault[plane]?.resizeable);
887
+ }
888
+ handleAxisResizeInternal(event) {
889
+ event.stopPropagation();
890
+ const { plane, axis, delta, size, index, state: state2 } = event;
891
+ if (axis === "col") {
892
+ const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
893
+ this.colSizes = {
894
+ ...this.colSizes,
895
+ [plane]: {
896
+ ...this.colSizes[plane],
897
+ [index]: nextSize
898
+ }
899
+ };
900
+ this.updateVisInline();
901
+ this.updateIntrinsicInlineSize();
398
902
  } else {
399
- if (this.focusedCell.col <= this.visColMin + overscanCol) {
400
- this.posInline = this.binInlineMin;
401
- this.updateVisInline();
402
- } else if (this.focusedCell.col >= this.visColMax - overscanCol - 1) {
403
- const sizeSumCol = [
404
- ...Array(this.focusedCell.col - this.visColMin)
405
- ].reduce((acc, _, c0) => {
406
- acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
407
- return acc;
408
- }, 0);
409
- this.posInline = this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline;
410
- this.updateVisInline();
411
- }
412
- if (this.focusedCell.row <= this.visRowMin + overscanRow) {
413
- this.posBlock = this.binBlockMin;
414
- this.updateVisBlock();
415
- } else if (this.focusedCell.row >= this.visRowMax - overscanRow - 1) {
416
- const sizeSumRow = [
417
- ...Array(this.focusedCell.row - this.visRowMin)
418
- ].reduce((acc, _, r0) => {
419
- acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
420
- return acc;
421
- }, 0);
422
- this.posBlock = this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock;
423
- this.updateVisBlock();
424
- }
903
+ const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
904
+ this.rowSizes = {
905
+ ...this.colSizes,
906
+ [plane]: {
907
+ ...this.rowSizes[plane],
908
+ [index]: nextSize
909
+ }
910
+ };
911
+ this.updateVisBlock();
912
+ this.updateIntrinsicBlockSize();
913
+ }
914
+ if (state2 === "dropped") {
915
+ this.dispatchEvent(new DxAxisResize({
916
+ plane,
917
+ axis,
918
+ index,
919
+ size: this[`${axis}Size`](index, plane)
920
+ }));
425
921
  }
426
922
  }
427
923
  //
428
924
  // Render and other lifecycle methods
429
925
  //
430
- render() {
431
- const visibleCols = this.visColMax - this.visColMin;
432
- const visibleRows = this.visRowMax - this.visRowMin;
433
- const offsetInline = gap + this.binInlineMin - this.posInline - this.overscanInline;
434
- const offsetBlock = gap + this.binBlockMin - this.posBlock - this.overscanBlock;
435
- return html`<div
436
- role="none"
437
- class="dx-grid"
438
- @pointerdown=${this.handlePointerDown}
439
- @pointerup=${this.handlePointerUp}
440
- @pointermove=${this.handlePointerMove}
441
- @focus=${this.handleFocus}
442
- @blur=${this.handleBlur}
443
- @keydown=${this.handleKeydown}
444
- >
445
- <div role="none" class="dx-grid__corner"></div>
446
- <div role="none" class="dx-grid__columnheader">
447
- <div
926
+ renderFixed(plane, selection) {
927
+ const colPlane = resolveColPlane(plane);
928
+ const rowPlane = resolveRowPlane(plane);
929
+ const cols = this.frozen[colPlane];
930
+ const rows = this.frozen[rowPlane];
931
+ return (cols ?? 0) > 0 && (rows ?? 0) > 0 ? html2`<div
448
932
  role="none"
449
- class="dx-grid__columnheader__content"
450
- style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateColumns};"
933
+ data-dx-grid-plane=${plane}
934
+ class="dx-grid__plane--fixed"
935
+ style=${styleMap({
936
+ "grid-template-columns": this[`template${colPlane}`],
937
+ "grid-template-rows": this[`template${rowPlane}`]
938
+ })}
451
939
  >
452
940
  ${[
941
+ ...Array(cols)
942
+ ].map((_, c) => {
943
+ return [
944
+ ...Array(rows)
945
+ ].map((_2, r) => {
946
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection));
947
+ });
948
+ })}
949
+ </div>` : null;
950
+ }
951
+ renderFrozenRows(plane, visibleCols, offsetInline, selection) {
952
+ const rowPlane = resolveRowPlane(plane);
953
+ const rows = this.frozen[rowPlane];
954
+ return (rows ?? 0) > 0 ? html2`<div role="none" class="dx-grid__plane--frozen-row">
955
+ <div
956
+ role="none"
957
+ data-dx-grid-plane=${plane}
958
+ class="dx-grid__plane--frozen-row__content"
959
+ style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateGridColumns};grid-template-rows:${this[`template${rowPlane}`]}"
960
+ >
961
+ ${[
453
962
  ...Array(visibleCols)
454
963
  ].map((_, c0) => {
455
- const c = this.visColMin + c0;
456
- return html`<div
457
- role="columnheader"
458
- ?inert=${c < 0}
459
- style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
460
- >
461
- <span id=${localChId(c0)}>${colToA1Notation(c)}</span>
462
- ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-col,${c}`}>
463
- <span class="sr-only">Resize</span>
464
- </button>`}
465
- </div>`;
964
+ return [
965
+ ...Array(rows)
966
+ ].map((_2, r) => {
967
+ const c = this.visColMin + c0;
968
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c0, r);
969
+ });
466
970
  })}
467
- </div>
468
- </div>
469
- <div role="none" class="dx-grid__corner"></div>
470
- <div role="none" class="dx-grid__rowheader">
471
- <div
472
- role="none"
473
- class="dx-grid__rowheader__content"
474
- style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateRows};"
475
- >
476
- ${[
477
- ...Array(visibleRows)
478
- ].map((_, r0) => {
479
- const r = this.visRowMin + r0;
480
- return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
481
- <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
482
- ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-row,${r}`}>
483
- <span class="sr-only">Resize</span>
484
- </button>`}
485
- </div>`;
971
+ </div>
972
+ </div>` : null;
973
+ }
974
+ renderFrozenColumns(plane, visibleRows, offsetBlock, selection) {
975
+ const colPlane = resolveColPlane(plane);
976
+ const cols = this.frozen[colPlane];
977
+ return (cols ?? 0) > 0 ? html2`<div role="none" class="dx-grid__plane--frozen-col">
978
+ <div
979
+ role="none"
980
+ data-dx-grid-plane=${plane}
981
+ class="dx-grid__plane--frozen-col__content"
982
+ style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateGridRows};grid-template-columns:${this[`template${colPlane}`]}"
983
+ >
984
+ ${[
985
+ ...Array(cols)
986
+ ].map((_, c) => {
987
+ return [
988
+ ...Array(visibleRows)
989
+ ].map((_2, r0) => {
990
+ const r = this.visRowMin + r0;
991
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c, r0);
992
+ });
486
993
  })}
487
- </div>
488
- </div>
489
- <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
994
+ </div>
995
+ </div>` : null;
996
+ }
997
+ renderCell(col, row, plane, selected, visCol = col, visRow = row) {
998
+ const cell = this.cell(col, row, plane);
999
+ const active = this.cellActive(col, row, plane);
1000
+ const resizeIndex = cell?.resizeHandle ? cell.resizeHandle === "col" ? col : row : void 0;
1001
+ const resizePlane = cell?.resizeHandle ? resolveResizePlane(cell.resizeHandle, plane) : void 0;
1002
+ return html2`<div
1003
+ role="gridcell"
1004
+ tabindex="0"
1005
+ ?inert=${col < 0 || row < 0}
1006
+ ?aria-selected=${selected}
1007
+ class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
1008
+ aria-colindex=${col}
1009
+ aria-rowindex=${row}
1010
+ data-dx-grid-action="cell"
1011
+ style="grid-column:${visCol + 1};grid-row:${visRow + 1}"
1012
+ >
1013
+ ${cell?.value}${cell?.resizeHandle && this.axisResizeable(resizePlane, cell.resizeHandle, resizeIndex) ? html2`<dx-grid-axis-resize-handle
1014
+ axis=${cell.resizeHandle}
1015
+ plane=${resizePlane}
1016
+ index=${resizeIndex}
1017
+ size=${this[`${cell.resizeHandle}Size`](resizeIndex, plane)}
1018
+ ></dx-grid-axis-resize-handle>` : null}
1019
+ </div>`;
1020
+ }
1021
+ render() {
1022
+ const visibleCols = this.visColMax - this.visColMin;
1023
+ const visibleRows = this.visRowMax - this.visRowMin;
1024
+ const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
1025
+ const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
1026
+ const selection = selectionProps(this.selectionStart, this.selectionEnd);
1027
+ return html2`<div
1028
+ role="none"
1029
+ class="dx-grid"
1030
+ style=${styleMap({
1031
+ "grid-template-columns": `${this.templatefrozenColsStart ? "min-content " : ""}minmax(0, ${Number.isFinite(this.limitColumns) ? `${this.intrinsicInlineSize}px` : "1fr"})${this.templatefrozenColsEnd ? " min-content" : ""}`,
1032
+ "grid-template-rows": `${this.templatefrozenRowsStart ? "min-content " : ""}minmax(0, ${Number.isFinite(this.limitRows) ? `${this.intrinsicBlockSize}px` : "1fr"})${this.templatefrozenRowsEnd ? " min-content" : ""}`
1033
+ })}
1034
+ data-grid=${this.gridId}
1035
+ data-grid-mode=${this.mode}
1036
+ ?data-grid-select=${selection.visible}
1037
+ >
1038
+ ${this.renderFixed("fixedStartStart", selection)}${this.renderFrozenRows("frozenRowsStart", visibleCols, offsetInline, selection)}${this.renderFixed("fixedStartEnd", selection)}${this.renderFrozenColumns("frozenColsStart", visibleRows, offsetBlock, selection)}
1039
+ <div role="grid" class="dx-grid__plane--grid" tabindex="0" ${ref2(this.viewportRef)}>
490
1040
  <div
491
1041
  role="none"
492
- class="dx-grid__content"
493
- style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this.templateColumns};grid-template-rows:${this.templateRows};"
1042
+ class="dx-grid__plane--grid__content"
1043
+ data-dx-grid-plane="grid"
1044
+ style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this.templateGridColumns};grid-template-rows:${this.templateGridRows};"
494
1045
  >
495
1046
  ${[
496
1047
  ...Array(visibleCols)
@@ -500,52 +1051,84 @@ var DxGrid = class extends LitElement {
500
1051
  ].map((_2, r0) => {
501
1052
  const c = c0 + this.visColMin;
502
1053
  const r = r0 + this.visRowMin;
503
- const cell = this.cell(c, r);
504
- return html`<div
505
- role="gridcell"
506
- tabindex="0"
507
- ?inert=${c < 0 || r < 0}
508
- aria-rowindex=${r}
509
- aria-colindex=${c}
510
- data-dx-grid-action="cell"
511
- style="grid-column:${c0 + 1};grid-row:${r0 + 1}"
512
- >
513
- ${cell?.value}
514
- </div>`;
1054
+ return this.renderCell(c, r, "grid", cellSelected(c, r, "grid", selection), c0, r0);
515
1055
  });
516
1056
  })}
517
1057
  </div>
518
1058
  </div>
519
- <div role="none" class="dx-grid__scrollbar" aria-orientation="vertical">
520
- <div role="none" class="dx-grid__scrollbar__thumb"></div>
521
- </div>
522
- <div role="none" class="dx-grid__corner"></div>
523
- <div role="none" class="dx-grid__scrollbar" aria-orientation="horizontal">
524
- <div role="none" class="dx-grid__scrollbar__thumb"></div>
525
- </div>
526
- <div role="none" class="dx-grid__corner"></div>
1059
+ ${this.renderFrozenColumns("frozenColsEnd", visibleRows, offsetBlock, selection)}${this.renderFixed("fixedEndStart", selection)}${this.renderFrozenRows("frozenRowsEnd", visibleCols, offsetInline, selection)}${this.renderFixed("fixedEndEnd", selection)}
527
1060
  </div>`;
528
1061
  }
1062
+ updateIntrinsicInlineSize() {
1063
+ this.intrinsicInlineSize = Number.isFinite(this.limitColumns) ? [
1064
+ ...Array(this.limitColumns)
1065
+ ].reduce((acc, _, c0) => acc + this.colSize(c0, "grid"), 0) + gap * (this.limitColumns - 1) : Infinity;
1066
+ }
1067
+ updateIntrinsicBlockSize() {
1068
+ this.intrinsicBlockSize = Number.isFinite(this.limitRows) ? [
1069
+ ...Array(this.limitRows)
1070
+ ].reduce((acc, _, r0) => acc + this.rowSize(r0, "grid"), 0) + gap * (this.limitRows - 1) : Infinity;
1071
+ }
1072
+ updateIntrinsicSizes() {
1073
+ this.updateIntrinsicInlineSize();
1074
+ this.updateIntrinsicBlockSize();
1075
+ }
529
1076
  firstUpdated() {
1077
+ if (this.getCells) {
1078
+ this.updateCells(true);
1079
+ }
530
1080
  this.observer.observe(this.viewportRef.value);
531
- this.colSizes = Object.entries(this.columns).reduce((acc, [colId, colMeta]) => {
532
- if (colMeta?.size) {
533
- acc[colId] = colMeta.size;
534
- }
1081
+ this.colSizes = Object.entries(this.columns).reduce((acc, [plane, planeColMeta]) => {
1082
+ acc[plane] = Object.entries(planeColMeta).reduce((planeAcc, [col, colMeta]) => {
1083
+ if (colMeta?.size) {
1084
+ planeAcc[col] = colMeta.size;
1085
+ }
1086
+ return planeAcc;
1087
+ }, {});
535
1088
  return acc;
536
- }, {});
537
- this.rowSizes = Object.entries(this.rows).reduce((acc, [rowId, rowMeta]) => {
538
- if (rowMeta?.size) {
539
- acc[rowId] = rowMeta.size;
540
- }
1089
+ }, {
1090
+ grid: {}
1091
+ });
1092
+ this.rowSizes = Object.entries(this.rows).reduce((acc, [plane, planeRowMeta]) => {
1093
+ acc[plane] = Object.entries(planeRowMeta).reduce((planeAcc, [row, rowMeta]) => {
1094
+ if (rowMeta?.size) {
1095
+ planeAcc[row] = rowMeta.size;
1096
+ }
1097
+ return planeAcc;
1098
+ }, {});
541
1099
  return acc;
542
- }, {});
1100
+ }, {
1101
+ grid: {}
1102
+ });
1103
+ this.updateIntrinsicSizes();
1104
+ }
1105
+ willUpdate(changedProperties) {
1106
+ if (this.getCells && (changedProperties.has("initialCells") || changedProperties.has("visColMin") || changedProperties.has("visColMax") || changedProperties.has("visRowMin") || changedProperties.has("visRowMax"))) {
1107
+ this.updateCells();
1108
+ }
1109
+ if (changedProperties.has("rowDefault") || changedProperties.has("rows") || changedProperties.has("limitRows")) {
1110
+ this.updateIntrinsicBlockSize();
1111
+ this.updatePosBlock();
1112
+ this.updateVisBlock();
1113
+ }
1114
+ if (changedProperties.has("colDefault") || changedProperties.has("columns") || changedProperties.has("limitColumns")) {
1115
+ this.updateIntrinsicInlineSize();
1116
+ this.updatePosInline();
1117
+ this.updateVisInline();
1118
+ }
543
1119
  }
544
1120
  updated(changedProperties) {
545
1121
  if (this.focusActive && (changedProperties.has("visRowMin") || changedProperties.has("visColMin") || changedProperties.has("focusedCell"))) {
546
1122
  this.refocus();
547
1123
  }
548
1124
  }
1125
+ updateIfWithinBounds({ col, row }) {
1126
+ if (col >= this.visColMin && col <= this.visColMax && row >= this.visRowMin && row <= this.visRowMax) {
1127
+ this.requestUpdate();
1128
+ return true;
1129
+ }
1130
+ return false;
1131
+ }
549
1132
  disconnectedCallback() {
550
1133
  super.disconnectedCallback();
551
1134
  if (this.viewportRef.value) {
@@ -556,118 +1139,159 @@ var DxGrid = class extends LitElement {
556
1139
  return this;
557
1140
  }
558
1141
  };
559
- _ts_decorate([
560
- property({
1142
+ _ts_decorate2([
1143
+ property2({
1144
+ type: String
1145
+ })
1146
+ ], DxGrid.prototype, "gridId", void 0);
1147
+ _ts_decorate2([
1148
+ property2({
561
1149
  type: Object
562
1150
  })
563
1151
  ], DxGrid.prototype, "rowDefault", void 0);
564
- _ts_decorate([
565
- property({
1152
+ _ts_decorate2([
1153
+ property2({
566
1154
  type: Object
567
1155
  })
568
1156
  ], DxGrid.prototype, "columnDefault", void 0);
569
- _ts_decorate([
570
- property({
1157
+ _ts_decorate2([
1158
+ property2({
571
1159
  type: Object
572
1160
  })
573
1161
  ], DxGrid.prototype, "rows", void 0);
574
- _ts_decorate([
575
- property({
1162
+ _ts_decorate2([
1163
+ property2({
576
1164
  type: Object
577
1165
  })
578
1166
  ], DxGrid.prototype, "columns", void 0);
579
- _ts_decorate([
580
- property({
1167
+ _ts_decorate2([
1168
+ property2({
581
1169
  type: Object
582
1170
  })
583
- ], DxGrid.prototype, "cells", void 0);
584
- _ts_decorate([
585
- property({
1171
+ ], DxGrid.prototype, "initialCells", void 0);
1172
+ _ts_decorate2([
1173
+ property2({
586
1174
  type: String
587
1175
  })
588
1176
  ], DxGrid.prototype, "mode", void 0);
589
- _ts_decorate([
1177
+ _ts_decorate2([
1178
+ property2({
1179
+ type: Number
1180
+ })
1181
+ ], DxGrid.prototype, "limitColumns", void 0);
1182
+ _ts_decorate2([
1183
+ property2({
1184
+ type: Number
1185
+ })
1186
+ ], DxGrid.prototype, "limitRows", void 0);
1187
+ _ts_decorate2([
1188
+ property2({
1189
+ type: Object
1190
+ })
1191
+ ], DxGrid.prototype, "frozen", void 0);
1192
+ _ts_decorate2([
1193
+ state()
1194
+ ], DxGrid.prototype, "cells", void 0);
1195
+ _ts_decorate2([
590
1196
  state()
591
1197
  ], DxGrid.prototype, "posInline", void 0);
592
- _ts_decorate([
1198
+ _ts_decorate2([
593
1199
  state()
594
1200
  ], DxGrid.prototype, "posBlock", void 0);
595
- _ts_decorate([
1201
+ _ts_decorate2([
596
1202
  state()
597
1203
  ], DxGrid.prototype, "sizeInline", void 0);
598
- _ts_decorate([
1204
+ _ts_decorate2([
599
1205
  state()
600
1206
  ], DxGrid.prototype, "sizeBlock", void 0);
601
- _ts_decorate([
1207
+ _ts_decorate2([
602
1208
  state()
603
1209
  ], DxGrid.prototype, "overscanInline", void 0);
604
- _ts_decorate([
1210
+ _ts_decorate2([
605
1211
  state()
606
1212
  ], DxGrid.prototype, "overscanBlock", void 0);
607
- _ts_decorate([
1213
+ _ts_decorate2([
608
1214
  state()
609
1215
  ], DxGrid.prototype, "binInlineMin", void 0);
610
- _ts_decorate([
1216
+ _ts_decorate2([
611
1217
  state()
612
1218
  ], DxGrid.prototype, "binInlineMax", void 0);
613
- _ts_decorate([
1219
+ _ts_decorate2([
614
1220
  state()
615
1221
  ], DxGrid.prototype, "binBlockMin", void 0);
616
- _ts_decorate([
1222
+ _ts_decorate2([
617
1223
  state()
618
1224
  ], DxGrid.prototype, "binBlockMax", void 0);
619
- _ts_decorate([
1225
+ _ts_decorate2([
620
1226
  state()
621
1227
  ], DxGrid.prototype, "visColMin", void 0);
622
- _ts_decorate([
1228
+ _ts_decorate2([
623
1229
  state()
624
1230
  ], DxGrid.prototype, "visColMax", void 0);
625
- _ts_decorate([
1231
+ _ts_decorate2([
626
1232
  state()
627
1233
  ], DxGrid.prototype, "visRowMin", void 0);
628
- _ts_decorate([
1234
+ _ts_decorate2([
629
1235
  state()
630
1236
  ], DxGrid.prototype, "visRowMax", void 0);
631
- _ts_decorate([
1237
+ _ts_decorate2([
632
1238
  state()
633
- ], DxGrid.prototype, "templateColumns", void 0);
634
- _ts_decorate([
1239
+ ], DxGrid.prototype, "templateGridColumns", void 0);
1240
+ _ts_decorate2([
635
1241
  state()
636
- ], DxGrid.prototype, "templateRows", void 0);
637
- _ts_decorate([
1242
+ ], DxGrid.prototype, "templatefrozenColsStart", void 0);
1243
+ _ts_decorate2([
1244
+ state()
1245
+ ], DxGrid.prototype, "templatefrozenColsEnd", void 0);
1246
+ _ts_decorate2([
1247
+ state()
1248
+ ], DxGrid.prototype, "templateGridRows", void 0);
1249
+ _ts_decorate2([
1250
+ state()
1251
+ ], DxGrid.prototype, "templatefrozenRowsStart", void 0);
1252
+ _ts_decorate2([
1253
+ state()
1254
+ ], DxGrid.prototype, "templatefrozenRowsEnd", void 0);
1255
+ _ts_decorate2([
1256
+ state()
1257
+ ], DxGrid.prototype, "pointer", void 0);
1258
+ _ts_decorate2([
638
1259
  state()
639
1260
  ], DxGrid.prototype, "colSizes", void 0);
640
- _ts_decorate([
1261
+ _ts_decorate2([
641
1262
  state()
642
1263
  ], DxGrid.prototype, "rowSizes", void 0);
643
- _ts_decorate([
1264
+ _ts_decorate2([
644
1265
  state()
645
- ], DxGrid.prototype, "resizing", void 0);
646
- _ts_decorate([
647
- state()
648
- ], DxGrid.prototype, "observer", void 0);
649
- _ts_decorate([
1266
+ ], DxGrid.prototype, "focusActive", void 0);
1267
+ _ts_decorate2([
650
1268
  state()
651
1269
  ], DxGrid.prototype, "focusedCell", void 0);
652
- _ts_decorate([
1270
+ _ts_decorate2([
653
1271
  state()
654
- ], DxGrid.prototype, "focusActive", void 0);
655
- _ts_decorate([
656
- eventOptions({
657
- capture: true
658
- })
659
- ], DxGrid.prototype, "handleFocus", null);
660
- _ts_decorate([
661
- eventOptions({
662
- capture: true
663
- })
664
- ], DxGrid.prototype, "handleBlur", null);
665
- DxGrid = _ts_decorate([
666
- customElement("dx-grid")
1272
+ ], DxGrid.prototype, "selectionStart", void 0);
1273
+ _ts_decorate2([
1274
+ state()
1275
+ ], DxGrid.prototype, "selectionEnd", void 0);
1276
+ _ts_decorate2([
1277
+ state()
1278
+ ], DxGrid.prototype, "intrinsicInlineSize", void 0);
1279
+ _ts_decorate2([
1280
+ state()
1281
+ ], DxGrid.prototype, "intrinsicBlockSize", void 0);
1282
+ _ts_decorate2([
1283
+ state()
1284
+ ], DxGrid.prototype, "observer", void 0);
1285
+ DxGrid = _ts_decorate2([
1286
+ customElement2("dx-grid")
667
1287
  ], DxGrid);
668
1288
  export {
669
1289
  DxAxisResize,
1290
+ DxAxisResizeInternal,
670
1291
  DxEditRequest,
671
- DxGrid
1292
+ DxGrid,
1293
+ DxGridCellsSelect,
1294
+ colToA1Notation,
1295
+ rowToA1Notation
672
1296
  };
673
1297
  //# sourceMappingURL=index.mjs.map