@dxos/lit-grid 0.6.12-main.ed7cda7 → 0.6.12-main.f9d0246

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,7 +1,15 @@
1
1
  // packages/ui/lit-grid/src/dx-grid.ts
2
- import { LitElement, html, nothing } 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, eventOptions } from "lit/decorators.js";
4
+ import { ref as ref2, createRef } from "lit/directives/ref.js";
5
+
6
+ // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
7
+ import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
8
+ import { disableNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview";
9
+ import { preventUnhandled } from "@atlaskit/pragmatic-drag-and-drop/prevent-unhandled";
10
+ import { html, LitElement } from "lit";
11
+ import { customElement, property } from "lit/decorators.js";
12
+ import { ref } from "lit/directives/ref.js";
5
13
 
6
14
  // packages/ui/lit-grid/src/util.ts
7
15
  var separator = ",";
@@ -16,6 +24,19 @@ var DxAxisResize = class extends Event {
16
24
  this.size = props.size;
17
25
  }
18
26
  };
27
+ var DxAxisResizeInternal = class extends Event {
28
+ constructor(props) {
29
+ super("dx-axis-resize-internal", {
30
+ composed: true,
31
+ bubbles: true
32
+ });
33
+ this.axis = props.axis;
34
+ this.index = props.index;
35
+ this.size = props.size;
36
+ this.delta = props.delta;
37
+ this.state = props.state;
38
+ }
39
+ };
19
40
  var DxEditRequest = class extends Event {
20
41
  constructor(props) {
21
42
  super("dx-edit-request");
@@ -36,13 +57,96 @@ var DxGridCellsSelect = class extends Event {
36
57
  }
37
58
  };
38
59
 
39
- // packages/ui/lit-grid/src/dx-grid.ts
60
+ // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
40
61
  function _ts_decorate(decorators, target, key, desc) {
41
62
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
42
63
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
43
64
  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;
44
65
  return c > 3 && r && Object.defineProperty(target, key, r), r;
45
66
  }
67
+ var DxGridAxisResizeHandle = class extends LitElement {
68
+ constructor() {
69
+ super(...arguments);
70
+ this.axis = "row";
71
+ this.index = "-1";
72
+ this.size = 128;
73
+ this.dragStartSize = 128;
74
+ this.cleanup = null;
75
+ }
76
+ render() {
77
+ return html`<button class="dx-grid__resize-handle" ${ref(this.mount)}>
78
+ <span class="sr-only">Resize</span>
79
+ </button>`;
80
+ }
81
+ dispatchResize(location, state2) {
82
+ const client = this.axis === "row" ? "clientY" : "clientX";
83
+ const event = new DxAxisResizeInternal({
84
+ axis: this.axis,
85
+ size: this.dragStartSize,
86
+ index: this.index,
87
+ delta: location.current.input[client] - location.initial.input[client],
88
+ state: state2
89
+ });
90
+ this.dispatchEvent(event);
91
+ }
92
+ mount(element) {
93
+ this.cleanup?.();
94
+ const host = this;
95
+ if (element) {
96
+ this.cleanup = draggable({
97
+ element,
98
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
99
+ disableNativeDragPreview({
100
+ nativeSetDragImage
101
+ });
102
+ preventUnhandled.start();
103
+ },
104
+ onDragStart() {
105
+ host.dragStartSize = host.size;
106
+ },
107
+ onDrag({ location }) {
108
+ host.dispatchResize(location, "dragging");
109
+ },
110
+ onDrop({ location }) {
111
+ host.dispatchResize(location, "dropped");
112
+ }
113
+ });
114
+ }
115
+ }
116
+ disconnectedCallback() {
117
+ super.disconnectedCallback();
118
+ this.cleanup?.();
119
+ }
120
+ createRenderRoot() {
121
+ return this;
122
+ }
123
+ };
124
+ _ts_decorate([
125
+ property({
126
+ type: String
127
+ })
128
+ ], DxGridAxisResizeHandle.prototype, "axis", void 0);
129
+ _ts_decorate([
130
+ property({
131
+ type: String
132
+ })
133
+ ], DxGridAxisResizeHandle.prototype, "index", void 0);
134
+ _ts_decorate([
135
+ property({
136
+ type: Number
137
+ })
138
+ ], DxGridAxisResizeHandle.prototype, "size", void 0);
139
+ DxGridAxisResizeHandle = _ts_decorate([
140
+ customElement("dx-grid-axis-resize-handle")
141
+ ], DxGridAxisResizeHandle);
142
+
143
+ // packages/ui/lit-grid/src/dx-grid.ts
144
+ function _ts_decorate2(decorators, target, key, desc) {
145
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
146
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
147
+ 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;
148
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
149
+ }
46
150
  var gap = 1;
47
151
  var resizeTolerance = 8;
48
152
  var overscanCol = 1;
@@ -87,9 +191,9 @@ var isSameCell = (a, b) => a && b && Number.isFinite(a.col) && Number.isFinite(a
87
191
  var localChId = (c0) => `ch--${c0}`;
88
192
  var localRhId = (r0) => `rh--${r0}`;
89
193
  var getPage = (axis, event) => axis === "col" ? event.pageX : event.pageY;
90
- var DxGrid = class extends LitElement {
194
+ var DxGrid = class extends LitElement2 {
91
195
  constructor() {
92
- super(...arguments);
196
+ super();
93
197
  this.gridId = "default-grid-id";
94
198
  this.rowDefault = {
95
199
  size: 32
@@ -196,12 +300,6 @@ var DxGrid = class extends LitElement {
196
300
  };
197
301
  this.handlePointerUp = (event) => {
198
302
  if (this.pointer?.state === "resizing") {
199
- const resizeEvent = new DxAxisResize({
200
- axis: this.pointer.axis,
201
- index: this.pointer.index,
202
- size: this[this.pointer.axis === "col" ? "colSize" : "rowSize"](this.pointer.index)
203
- });
204
- this.dispatchEvent(resizeEvent);
205
303
  } else {
206
304
  const cell = closestCell(event.target);
207
305
  if (cell) {
@@ -215,24 +313,7 @@ var DxGrid = class extends LitElement {
215
313
  this.pointer = null;
216
314
  };
217
315
  this.handlePointerMove = (event) => {
218
- if (this.pointer?.state === "resizing") {
219
- const delta = getPage(this.pointer.axis, event) - this.pointer.page;
220
- if (this.pointer.axis === "col") {
221
- const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.pointer.size + delta));
222
- this.colSizes = {
223
- ...this.colSizes,
224
- [this.pointer.index]: nextSize
225
- };
226
- this.updateVisInline();
227
- } else {
228
- const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.pointer.size + delta));
229
- this.rowSizes = {
230
- ...this.rowSizes,
231
- [this.pointer.index]: nextSize
232
- };
233
- this.updateVisBlock();
234
- }
235
- } else if (this.pointer?.state === "selecting") {
316
+ if (this.pointer?.state === "selecting") {
236
317
  const cell = closestCell(event.target);
237
318
  if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
238
319
  this.selectionEnd = cell;
@@ -254,16 +335,32 @@ var DxGrid = class extends LitElement {
254
335
  }
255
336
  });
256
337
  this.viewportRef = createRef();
338
+ this.maybeUpdateVis = () => {
339
+ if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
340
+ } else {
341
+ this.updateVis();
342
+ }
343
+ };
257
344
  this.handleWheel = ({ deltaX, deltaY }) => {
258
345
  if (this.mode === "browse") {
259
346
  this.posInline = Math.max(0, this.posInline + deltaX);
260
347
  this.posBlock = Math.max(0, this.posBlock + deltaY);
261
- if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
262
- } else {
263
- this.updateVis();
264
- }
348
+ this.maybeUpdateVis();
265
349
  }
266
350
  };
351
+ this.addEventListener("dx-axis-resize-internal", this.handleAxisResizeInternal);
352
+ this.addEventListener("wheel", this.handleWheel);
353
+ this.addEventListener("pointerdown", this.handlePointerDown);
354
+ this.addEventListener("pointermove", this.handlePointerMove);
355
+ this.addEventListener("pointerup", this.handlePointerUp);
356
+ this.addEventListener("pointerleave", this.handlePointerUp);
357
+ this.addEventListener("focus", this.handleFocus, {
358
+ capture: true
359
+ });
360
+ this.addEventListener("blur", this.handleBlur, {
361
+ capture: true
362
+ });
363
+ this.addEventListener("keydown", this.handleKeydown);
267
364
  }
268
365
  //
269
366
  // Primary pointer and keyboard handlers
@@ -492,6 +589,52 @@ var DxGrid = class extends LitElement {
492
589
  }
493
590
  }
494
591
  //
592
+ // Map scroll DOM methods to virtualized value.
593
+ //
594
+ get scrollLeft() {
595
+ return this.posInline;
596
+ }
597
+ set scrollLeft(nextValue) {
598
+ this.posInline = nextValue;
599
+ this.maybeUpdateVis();
600
+ }
601
+ get scrollTop() {
602
+ return this.posBlock;
603
+ }
604
+ set scrollTop(nextValue) {
605
+ this.posBlock = nextValue;
606
+ this.maybeUpdateVis();
607
+ }
608
+ //
609
+ // Resize handlers
610
+ //
611
+ handleAxisResizeInternal(event) {
612
+ event.stopPropagation();
613
+ const { axis, delta, size, index, type } = event;
614
+ if (axis === "col") {
615
+ const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
616
+ this.colSizes = {
617
+ ...this.colSizes,
618
+ [index]: nextSize
619
+ };
620
+ this.updateVisInline();
621
+ } else {
622
+ const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
623
+ this.rowSizes = {
624
+ ...this.rowSizes,
625
+ [index]: nextSize
626
+ };
627
+ this.updateVisBlock();
628
+ }
629
+ if (type === "dropped") {
630
+ this.dispatchEvent(new DxAxisResize({
631
+ axis,
632
+ index,
633
+ size: this[axis === "col" ? "colSize" : "rowSize"](index)
634
+ }));
635
+ }
636
+ }
637
+ //
495
638
  // Render and other lifecycle methods
496
639
  //
497
640
  render() {
@@ -504,19 +647,12 @@ var DxGrid = class extends LitElement {
504
647
  const selectRowMin = Math.min(this.selectionStart.row, this.selectionEnd.row);
505
648
  const selectRowMax = Math.max(this.selectionStart.row, this.selectionEnd.row);
506
649
  const selectVisible = selectColMin !== selectColMax || selectRowMin !== selectRowMax;
507
- return html`<div
650
+ return html2`<div
508
651
  role="none"
509
652
  class="dx-grid"
510
653
  data-grid=${this.gridId}
511
654
  data-grid-mode=${this.mode}
512
655
  ?data-grid-select=${selectVisible}
513
- @pointerdown=${this.handlePointerDown}
514
- @pointerup=${this.handlePointerUp}
515
- @pointermove=${this.handlePointerMove}
516
- @pointerleave=${this.handlePointerUp}
517
- @focus=${this.handleFocus}
518
- @blur=${this.handleBlur}
519
- @keydown=${this.handleKeydown}
520
656
  >
521
657
  <div role="none" class="dx-grid__corner"></div>
522
658
  <div role="none" class="dx-grid__columnheader">
@@ -529,15 +665,18 @@ var DxGrid = class extends LitElement {
529
665
  ...Array(visibleCols)
530
666
  ].map((_, c0) => {
531
667
  const c = this.visColMin + c0;
532
- return html`<div
668
+ return html2`<div
533
669
  role="columnheader"
534
670
  ?inert=${c < 0}
535
671
  style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
536
672
  >
537
673
  <span id=${localChId(c0)}>${colToA1Notation(c)}</span>
538
- ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-col,${c}`}>
539
- <span class="sr-only">Resize</span>
540
- </button>`}
674
+ ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html2`<dx-grid-axis-resize-handle
675
+ axis="col"
676
+ index=${c}
677
+ size=${this.colSize(c)}
678
+ @dxaxisresizeinternal=${this.handleAxisResizeInternal}
679
+ ></dx-grid-axis-resize-handle>`}
541
680
  </div>`;
542
681
  })}
543
682
  </div>
@@ -553,16 +692,18 @@ var DxGrid = class extends LitElement {
553
692
  ...Array(visibleRows)
554
693
  ].map((_, r0) => {
555
694
  const r = this.visRowMin + r0;
556
- return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
695
+ return html2`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
557
696
  <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
558
- ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-row,${r}`}>
559
- <span class="sr-only">Resize</span>
560
- </button>`}
697
+ ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html2`<dx-grid-axis-resize-handle
698
+ axis="row"
699
+ index=${r}
700
+ size=${this.rowSize(r)}
701
+ ></dx-grid-axis-resize-handle>`}
561
702
  </div>`;
562
703
  })}
563
704
  </div>
564
705
  </div>
565
- <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
706
+ <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref2(this.viewportRef)}>
566
707
  <div
567
708
  role="none"
568
709
  class="dx-grid__content"
@@ -579,7 +720,7 @@ var DxGrid = class extends LitElement {
579
720
  const cell = this.cell(c, r);
580
721
  const active = this.focusActive && this.focusedCell.col === c && this.focusedCell.row === r;
581
722
  const selected = c >= selectColMin && c <= selectColMax && r >= selectRowMin && r <= selectRowMax;
582
- return html`<div
723
+ return html2`<div
583
724
  role="gridcell"
584
725
  tabindex="0"
585
726
  ?inert=${c < 0 || r < 0}
@@ -662,131 +803,132 @@ var DxGrid = class extends LitElement {
662
803
  return this;
663
804
  }
664
805
  };
665
- _ts_decorate([
666
- property({
806
+ _ts_decorate2([
807
+ property2({
667
808
  type: String
668
809
  })
669
810
  ], DxGrid.prototype, "gridId", void 0);
670
- _ts_decorate([
671
- property({
811
+ _ts_decorate2([
812
+ property2({
672
813
  type: Object
673
814
  })
674
815
  ], DxGrid.prototype, "rowDefault", void 0);
675
- _ts_decorate([
676
- property({
816
+ _ts_decorate2([
817
+ property2({
677
818
  type: Object
678
819
  })
679
820
  ], DxGrid.prototype, "columnDefault", void 0);
680
- _ts_decorate([
681
- property({
821
+ _ts_decorate2([
822
+ property2({
682
823
  type: Object
683
824
  })
684
825
  ], DxGrid.prototype, "rows", void 0);
685
- _ts_decorate([
686
- property({
826
+ _ts_decorate2([
827
+ property2({
687
828
  type: Object
688
829
  })
689
830
  ], DxGrid.prototype, "columns", void 0);
690
- _ts_decorate([
691
- property({
831
+ _ts_decorate2([
832
+ property2({
692
833
  type: Object
693
834
  })
694
835
  ], DxGrid.prototype, "initialCells", void 0);
695
- _ts_decorate([
696
- property({
836
+ _ts_decorate2([
837
+ property2({
697
838
  type: String
698
839
  })
699
840
  ], DxGrid.prototype, "mode", void 0);
700
- _ts_decorate([
841
+ _ts_decorate2([
701
842
  state()
702
843
  ], DxGrid.prototype, "cells", void 0);
703
- _ts_decorate([
844
+ _ts_decorate2([
704
845
  state()
705
846
  ], DxGrid.prototype, "posInline", void 0);
706
- _ts_decorate([
847
+ _ts_decorate2([
707
848
  state()
708
849
  ], DxGrid.prototype, "posBlock", void 0);
709
- _ts_decorate([
850
+ _ts_decorate2([
710
851
  state()
711
852
  ], DxGrid.prototype, "sizeInline", void 0);
712
- _ts_decorate([
853
+ _ts_decorate2([
713
854
  state()
714
855
  ], DxGrid.prototype, "sizeBlock", void 0);
715
- _ts_decorate([
856
+ _ts_decorate2([
716
857
  state()
717
858
  ], DxGrid.prototype, "overscanInline", void 0);
718
- _ts_decorate([
859
+ _ts_decorate2([
719
860
  state()
720
861
  ], DxGrid.prototype, "overscanBlock", void 0);
721
- _ts_decorate([
862
+ _ts_decorate2([
722
863
  state()
723
864
  ], DxGrid.prototype, "binInlineMin", void 0);
724
- _ts_decorate([
865
+ _ts_decorate2([
725
866
  state()
726
867
  ], DxGrid.prototype, "binInlineMax", void 0);
727
- _ts_decorate([
868
+ _ts_decorate2([
728
869
  state()
729
870
  ], DxGrid.prototype, "binBlockMin", void 0);
730
- _ts_decorate([
871
+ _ts_decorate2([
731
872
  state()
732
873
  ], DxGrid.prototype, "binBlockMax", void 0);
733
- _ts_decorate([
874
+ _ts_decorate2([
734
875
  state()
735
876
  ], DxGrid.prototype, "visColMin", void 0);
736
- _ts_decorate([
877
+ _ts_decorate2([
737
878
  state()
738
879
  ], DxGrid.prototype, "visColMax", void 0);
739
- _ts_decorate([
880
+ _ts_decorate2([
740
881
  state()
741
882
  ], DxGrid.prototype, "visRowMin", void 0);
742
- _ts_decorate([
883
+ _ts_decorate2([
743
884
  state()
744
885
  ], DxGrid.prototype, "visRowMax", void 0);
745
- _ts_decorate([
886
+ _ts_decorate2([
746
887
  state()
747
888
  ], DxGrid.prototype, "templateColumns", void 0);
748
- _ts_decorate([
889
+ _ts_decorate2([
749
890
  state()
750
891
  ], DxGrid.prototype, "templateRows", void 0);
751
- _ts_decorate([
892
+ _ts_decorate2([
752
893
  state()
753
894
  ], DxGrid.prototype, "pointer", void 0);
754
- _ts_decorate([
895
+ _ts_decorate2([
755
896
  state()
756
897
  ], DxGrid.prototype, "colSizes", void 0);
757
- _ts_decorate([
898
+ _ts_decorate2([
758
899
  state()
759
900
  ], DxGrid.prototype, "rowSizes", void 0);
760
- _ts_decorate([
901
+ _ts_decorate2([
761
902
  state()
762
903
  ], DxGrid.prototype, "focusActive", void 0);
763
- _ts_decorate([
904
+ _ts_decorate2([
764
905
  state()
765
906
  ], DxGrid.prototype, "focusedCell", void 0);
766
- _ts_decorate([
907
+ _ts_decorate2([
767
908
  state()
768
909
  ], DxGrid.prototype, "selectionStart", void 0);
769
- _ts_decorate([
910
+ _ts_decorate2([
770
911
  state()
771
912
  ], DxGrid.prototype, "selectionEnd", void 0);
772
- _ts_decorate([
913
+ _ts_decorate2([
773
914
  state()
774
915
  ], DxGrid.prototype, "observer", void 0);
775
- _ts_decorate([
916
+ _ts_decorate2([
776
917
  eventOptions({
777
918
  capture: true
778
919
  })
779
920
  ], DxGrid.prototype, "handleFocus", null);
780
- _ts_decorate([
921
+ _ts_decorate2([
781
922
  eventOptions({
782
923
  capture: true
783
924
  })
784
925
  ], DxGrid.prototype, "handleBlur", null);
785
- DxGrid = _ts_decorate([
786
- customElement("dx-grid")
926
+ DxGrid = _ts_decorate2([
927
+ customElement2("dx-grid")
787
928
  ], DxGrid);
788
929
  export {
789
930
  DxAxisResize,
931
+ DxAxisResizeInternal,
790
932
  DxEditRequest,
791
933
  DxGrid,
792
934
  DxGridCellsSelect