@dxos/lit-grid 0.6.12 → 0.6.13-main.09887cd

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 +117 -0
  6. package/dist/src/dx-grid.d.ts.map +1 -0
  7. package/dist/src/dx-grid.js +1070 -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 +110 -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 +95 -61
  30. package/dist/types/src/dx-grid.d.ts.map +1 -1
  31. package/dist/types/src/dx-grid.js +1070 -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 +102 -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 +5 -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 +72 -68
  51. package/src/dx-grid.ts +934 -329
  52. package/src/types.ts +139 -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,156 @@
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 DxGridPlaneCells = Record<DxGridCellIndex, DxGridCellValue>;
26
+ export type DxGridCells = { grid: DxGridPlaneCells } & Partial<
27
+ Record<DxGridFixedPlane | DxGridFrozenPlane, DxGridPlaneCells>
28
+ >;
29
+
30
+ export type DxGridPlaneAxisMeta = Record<string, DxGridAxisMetaProps>;
31
+ export type DxGridAxisMeta = DxGridPlaneRecord<DxGridFrozenPlane, DxGridPlaneAxisMeta>;
32
+
33
+ export type DxGridPointer =
34
+ | null
35
+ | ({ state: 'maybeSelecting' } & Pick<PointerEvent, 'pageX' | 'pageY'>)
36
+ | { state: 'selecting' };
37
+
38
+ export type DxAxisResizeProps = Pick<DxAxisResize, 'axis' | 'plane' | 'index' | 'size'>;
39
+ export type DxAxisResizeInternalProps = DxAxisResizeProps & { delta: number; state: 'dragging' | 'dropped' };
40
+
41
+ export type DxGridMode = 'browse' | 'edit';
42
+
43
+ export type DxGridFrozenAxes = Partial<Record<DxGridFrozenPlane, number>>;
44
+
45
+ export type DxGridCellValue = {
46
+ /**
47
+ * The content value
48
+ */
49
+ value: string;
50
+ /**
51
+ * Accessory HTML to render alongside the value.
52
+ */
53
+ accessoryHtml?: string;
54
+ /**
55
+ * If this is a merged cell, the bottomright-most of the range in numeric notation, otherwise undefined.
56
+ */
57
+ end?: string;
58
+ /**
59
+ * `class` attribute value to apply to the gridcell element.
60
+ */
61
+ className?: string;
62
+ /**
63
+ * Whether to render a resize handle for this cell’s row or column.
64
+ */
65
+ resizeHandle?: DxGridAxis;
66
+ };
67
+
68
+ export type DxGridAxisMetaProps = {
69
+ size: number;
70
+ description?: string;
71
+ resizeable?: boolean;
72
+ };
73
+
74
+ export type DxGridAxisSizes = DxGridPlaneRecord<DxGridFrozenPlane, Record<string, number>>;
75
+
76
+ export type DxGridProps = Partial<
77
+ Pick<
78
+ DxGrid,
79
+ 'initialCells' | 'rows' | 'columns' | 'rowDefault' | 'columnDefault' | 'limitRows' | 'limitColumns' | 'frozen'
80
+ >
81
+ >;
82
+
83
+ export type DxGridSelectionProps = {
84
+ plane: DxGridPlane;
85
+ colMin: number;
86
+ colMax: number;
87
+ rowMin: number;
88
+ rowMax: number;
89
+ visible?: boolean;
90
+ };
8
91
 
9
92
  export class DxAxisResize extends Event {
10
93
  public readonly axis: DxGridAxis;
94
+ public readonly plane: 'grid' | DxGridFrozenPlane;
11
95
  public readonly index: string;
12
96
  public readonly size: number;
13
97
  constructor(props: DxAxisResizeProps) {
14
98
  super('dx-axis-resize');
15
99
  this.axis = props.axis;
100
+ this.plane = props.plane;
16
101
  this.index = props.index;
17
102
  this.size = props.size;
18
103
  }
19
104
  }
105
+
106
+ export class DxAxisResizeInternal extends Event {
107
+ public readonly axis: DxGridAxis;
108
+ public readonly plane: 'grid' | DxGridFrozenPlane;
109
+ public readonly index: string;
110
+ public readonly size: number;
111
+ public readonly delta: number;
112
+ public readonly state: 'dragging' | 'dropped';
113
+ constructor(props: DxAxisResizeInternalProps) {
114
+ super('dx-axis-resize-internal', { composed: true, bubbles: true });
115
+ this.axis = props.axis;
116
+ this.plane = props.plane;
117
+ this.index = props.index;
118
+ this.size = props.size;
119
+ this.delta = props.delta;
120
+ this.state = props.state;
121
+ }
122
+ }
123
+
124
+ export type DxEditRequestProps = Pick<DxEditRequest, 'cellIndex' | 'cellBox' | 'initialContent'>;
125
+
126
+ export class DxEditRequest extends Event {
127
+ public readonly cellIndex: DxGridCellIndex;
128
+ public readonly cellBox: Record<'insetInlineStart' | 'insetBlockStart' | 'inlineSize' | 'blockSize', number>;
129
+ public readonly initialContent?: string;
130
+ constructor(props: DxEditRequestProps) {
131
+ super('dx-edit-request');
132
+ this.cellIndex = props.cellIndex;
133
+ this.cellBox = props.cellBox;
134
+ this.initialContent = props.initialContent;
135
+ }
136
+ }
137
+
138
+ export type DxGridPlaneRange = { start: DxGridPlanePosition; end: DxGridPlanePosition };
139
+ export type DxGridRange = { start: DxGridPosition; end: DxGridPosition };
140
+
141
+ export class DxGridCellsSelect extends Event {
142
+ public readonly start: string;
143
+ public readonly end: string;
144
+ public readonly minCol: number;
145
+ public readonly maxCol: number;
146
+ public readonly minRow: number;
147
+ public readonly maxRow: number;
148
+ constructor({ start, end }: DxGridRange) {
149
+ super('dx-grid-cells-select');
150
+ this.start = toCellIndex(start);
151
+ this.end = toCellIndex(end);
152
+ this.minCol = Math.min(start.col, end.col);
153
+ this.maxCol = Math.max(start.col, end.col);
154
+ this.minRow = Math.min(start.row, end.row);
155
+ this.maxRow = Math.max(start.row, end.row);
156
+ }
157
+ }
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
+ };