@dxos/lit-grid 0.6.13 → 0.6.14-main.2b6a0f3

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 (56) hide show
  1. package/dist/src/dx-grid-axis-resize-handle.d.ts +16 -0
  2. package/dist/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
  3. package/dist/src/dx-grid-axis-resize-handle.js +96 -0
  4. package/dist/src/dx-grid-axis-resize-handle.js.map +1 -0
  5. package/dist/src/dx-grid.d.ts +138 -0
  6. package/dist/src/dx-grid.d.ts.map +1 -0
  7. package/dist/src/dx-grid.js +1224 -0
  8. package/dist/src/dx-grid.js.map +1 -0
  9. package/dist/src/dx-grid.lit-stories.d.ts +42 -0
  10. package/dist/src/dx-grid.lit-stories.d.ts.map +1 -0
  11. package/dist/src/dx-grid.lit-stories.js +166 -0
  12. package/dist/src/dx-grid.lit-stories.js.map +1 -0
  13. package/dist/src/index.d.ts +3 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +6 -0
  16. package/dist/src/index.js.map +1 -0
  17. package/dist/src/types.d.ts +119 -0
  18. package/dist/src/types.d.ts.map +1 -0
  19. package/dist/src/types.js +44 -0
  20. package/dist/src/types.js.map +1 -0
  21. package/dist/src/util.d.ts +9 -0
  22. package/dist/src/util.d.ts.map +1 -0
  23. package/dist/src/util.js +19 -0
  24. package/dist/src/util.js.map +1 -0
  25. package/dist/types/src/dx-grid-axis-resize-handle.d.ts +16 -0
  26. package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
  27. package/dist/types/src/dx-grid-axis-resize-handle.js +96 -0
  28. package/dist/types/src/dx-grid-axis-resize-handle.js.map +1 -0
  29. package/dist/types/src/dx-grid.d.ts +112 -57
  30. package/dist/types/src/dx-grid.d.ts.map +1 -1
  31. package/dist/types/src/dx-grid.js +1224 -0
  32. package/dist/types/src/dx-grid.js.map +1 -0
  33. package/dist/types/src/dx-grid.lit-stories.d.ts +27 -2
  34. package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
  35. package/dist/types/src/dx-grid.lit-stories.js +166 -0
  36. package/dist/types/src/dx-grid.lit-stories.js.map +1 -0
  37. package/dist/types/src/index.js +6 -0
  38. package/dist/types/src/index.js.map +1 -0
  39. package/dist/types/src/types.d.ts +111 -1
  40. package/dist/types/src/types.d.ts.map +1 -1
  41. package/dist/types/src/types.js +44 -0
  42. package/dist/types/src/types.js.map +1 -0
  43. package/dist/types/src/util.d.ts +9 -0
  44. package/dist/types/src/util.d.ts.map +1 -0
  45. package/dist/types/src/util.js +19 -0
  46. package/dist/types/src/util.js.map +1 -0
  47. package/package.json +6 -6
  48. package/src/dx-grid-axis-resize-handle.ts +87 -0
  49. package/src/dx-grid.lit-stories.ts +148 -21
  50. package/src/dx-grid.pcss +68 -69
  51. package/src/dx-grid.ts +1116 -343
  52. package/src/types.ts +161 -1
  53. package/src/util.ts +28 -0
  54. package/dist/lib/browser/index.mjs +0 -578
  55. package/dist/lib/browser/index.mjs.map +0 -7
  56. package/dist/lib/browser/meta.json +0 -1
package/src/types.ts CHANGED
@@ -2,18 +2,178 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { type DxGrid } from './dx-grid';
6
+ import { toCellIndex } from './util';
7
+
8
+ export type DxGridCellIndex = `${string},${string}`;
9
+
5
10
  export type DxGridAxis = 'row' | 'col';
6
11
 
7
- export type DxAxisResizeProps = Pick<DxAxisResize, 'axis' | 'index' | 'size'>;
12
+ export type DxGridFrozenColsPlane = `frozenCols${'Start' | 'End'}`;
13
+ export type DxGridFrozenRowsPlane = `frozenRows${'Start' | 'End'}`;
14
+
15
+ export type DxGridFrozenPlane = DxGridFrozenColsPlane | DxGridFrozenRowsPlane;
16
+ export type DxGridFixedPlane = `fixed${'Start' | 'End'}${'Start' | 'End'}`;
17
+
18
+ export type DxGridPlane = 'grid' | DxGridFrozenPlane | DxGridFixedPlane;
19
+ export type DxGridPlaneRecord<P extends Exclude<DxGridPlane, 'grid'>, T> = Record<'grid', T> & Partial<Record<P, T>>;
20
+
21
+ export type DxGridPlanePosition = Record<DxGridAxis, number>;
22
+ export type DxGridPosition = DxGridPlanePosition & { plane: DxGridPlane };
23
+ export type DxGridPositionNullable = DxGridPosition | null;
24
+
25
+ export type DxGridAnnotatedWheelEvent = WheelEvent &
26
+ Partial<{
27
+ overscrollInline: number;
28
+ overscrollBlock: number;
29
+ }>;
30
+
31
+ export type DxGridPlaneCells = Record<DxGridCellIndex, DxGridCellValue>;
32
+ export type DxGridCells = { grid: DxGridPlaneCells } & Partial<
33
+ Record<DxGridFixedPlane | DxGridFrozenPlane, DxGridPlaneCells>
34
+ >;
35
+
36
+ export type DxGridPlaneAxisMeta = Record<string, DxGridAxisMetaProps>;
37
+ export type DxGridAxisMeta = DxGridPlaneRecord<DxGridFrozenPlane, DxGridPlaneAxisMeta>;
38
+
39
+ export type DxGridPointer =
40
+ | null
41
+ | ({ state: 'maybeSelecting' } & Pick<PointerEvent, 'pageX' | 'pageY'>)
42
+ | { state: 'selecting' };
43
+
44
+ export type DxAxisResizeProps = Pick<DxAxisResize, 'axis' | 'plane' | 'index' | 'size'>;
45
+ export type DxAxisResizeInternalProps = DxAxisResizeProps & { delta: number; state: 'dragging' | 'dropped' };
46
+
47
+ export type DxGridMode = 'browse' | 'edit';
48
+
49
+ export type DxGridFrozenAxes = Partial<Record<DxGridFrozenPlane, number>>;
50
+
51
+ export type DxGridCellValue = {
52
+ /**
53
+ * The content value
54
+ */
55
+ value: string;
56
+ /**
57
+ * Accessory HTML to render alongside the value.
58
+ */
59
+ accessoryHtml?: string;
60
+ /**
61
+ * If this is a merged cell, the bottomright-most of the range in numeric notation, otherwise undefined.
62
+ */
63
+ end?: string;
64
+ /**
65
+ * `class` attribute value to apply to the gridcell element.
66
+ */
67
+ className?: string;
68
+ /**
69
+ * `data-refs` attribute to apply to the gridcell element.
70
+ */
71
+ dataRefs?: string;
72
+ /**
73
+ * Whether to render a resize handle for this cell’s row or column.
74
+ */
75
+ resizeHandle?: DxGridAxis;
76
+ };
77
+
78
+ export type DxGridAxisMetaProps = {
79
+ size: number;
80
+ description?: string;
81
+ resizeable?: boolean;
82
+ readonly?: boolean;
83
+ };
84
+
85
+ export type DxGridAxisSizes = DxGridPlaneRecord<DxGridFrozenPlane, Record<string, number>>;
86
+
87
+ export type DxGridProps = Partial<
88
+ Pick<
89
+ DxGrid,
90
+ | 'gridId'
91
+ | 'rowDefault'
92
+ | 'columnDefault'
93
+ | 'rows'
94
+ | 'columns'
95
+ | 'initialCells'
96
+ | 'mode'
97
+ | 'limitColumns'
98
+ | 'limitRows'
99
+ | 'frozen'
100
+ | 'overscroll'
101
+ | 'activeRefs'
102
+ >
103
+ >;
104
+
105
+ export type DxGridSelectionProps = {
106
+ plane: DxGridPlane;
107
+ colMin: number;
108
+ colMax: number;
109
+ rowMin: number;
110
+ rowMax: number;
111
+ visible?: boolean;
112
+ };
8
113
 
9
114
  export class DxAxisResize extends Event {
10
115
  public readonly axis: DxGridAxis;
116
+ public readonly plane: 'grid' | DxGridFrozenPlane;
11
117
  public readonly index: string;
12
118
  public readonly size: number;
13
119
  constructor(props: DxAxisResizeProps) {
14
120
  super('dx-axis-resize');
15
121
  this.axis = props.axis;
122
+ this.plane = props.plane;
16
123
  this.index = props.index;
17
124
  this.size = props.size;
18
125
  }
19
126
  }
127
+
128
+ export class DxAxisResizeInternal extends Event {
129
+ public readonly axis: DxGridAxis;
130
+ public readonly plane: 'grid' | DxGridFrozenPlane;
131
+ public readonly index: string;
132
+ public readonly size: number;
133
+ public readonly delta: number;
134
+ public readonly state: 'dragging' | 'dropped';
135
+ constructor(props: DxAxisResizeInternalProps) {
136
+ super('dx-axis-resize-internal', { composed: true, bubbles: true });
137
+ this.axis = props.axis;
138
+ this.plane = props.plane;
139
+ this.index = props.index;
140
+ this.size = props.size;
141
+ this.delta = props.delta;
142
+ this.state = props.state;
143
+ }
144
+ }
145
+
146
+ export type DxEditRequestProps = Pick<DxEditRequest, 'cellIndex' | 'cellBox' | 'initialContent'>;
147
+
148
+ export class DxEditRequest extends Event {
149
+ public readonly cellIndex: DxGridCellIndex;
150
+ public readonly cellBox: Record<'insetInlineStart' | 'insetBlockStart' | 'inlineSize' | 'blockSize', number>;
151
+ public readonly initialContent?: string;
152
+ constructor(props: DxEditRequestProps) {
153
+ super('dx-edit-request');
154
+ this.cellIndex = props.cellIndex;
155
+ this.cellBox = props.cellBox;
156
+ this.initialContent = props.initialContent;
157
+ }
158
+ }
159
+
160
+ export type DxGridPlaneRange = { start: DxGridPlanePosition; end: DxGridPlanePosition };
161
+ export type DxGridRange = { start: DxGridPosition; end: DxGridPosition };
162
+
163
+ export class DxGridCellsSelect extends Event {
164
+ public readonly start: string;
165
+ public readonly end: string;
166
+ public readonly minCol: number;
167
+ public readonly maxCol: number;
168
+ public readonly minRow: number;
169
+ public readonly maxRow: number;
170
+ constructor({ start, end }: DxGridRange) {
171
+ super('dx-grid-cells-select');
172
+ this.start = toCellIndex(start);
173
+ this.end = toCellIndex(end);
174
+ this.minCol = Math.min(start.col, end.col);
175
+ this.maxCol = Math.max(start.col, end.col);
176
+ this.minRow = Math.min(start.row, end.row);
177
+ this.maxRow = Math.max(start.row, end.row);
178
+ }
179
+ }
package/src/util.ts ADDED
@@ -0,0 +1,28 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type DxGridCellIndex, type DxGridPosition } from './types';
6
+
7
+ /**
8
+ * Separator for serializing cell position vectors
9
+ */
10
+ export const separator = ',';
11
+
12
+ export const toCellIndex = (cellCoords: DxGridPosition): DxGridCellIndex =>
13
+ `${cellCoords.col}${separator}${cellCoords.row}`;
14
+
15
+ //
16
+ // A1 notation is the fallback for numbering columns and rows.
17
+ //
18
+
19
+ export const colToA1Notation = (col: number): string => {
20
+ return (
21
+ (col >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(col / 26) - 1) : '') +
22
+ String.fromCharCode('A'.charCodeAt(0) + (col % 26))
23
+ );
24
+ };
25
+
26
+ export const rowToA1Notation = (row: number): string => {
27
+ return `${row + 1}`;
28
+ };