@dxos/lit-grid 0.6.13 → 0.6.14-main.1366248
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.
- package/dist/src/dx-grid-axis-resize-handle.d.ts +16 -0
- package/dist/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
- package/dist/src/dx-grid-axis-resize-handle.js +96 -0
- package/dist/src/dx-grid-axis-resize-handle.js.map +1 -0
- package/dist/src/dx-grid-multiselect-cell.d.ts +13 -0
- package/dist/src/dx-grid-multiselect-cell.d.ts.map +1 -0
- package/dist/src/dx-grid-multiselect-cell.js +56 -0
- package/dist/src/dx-grid-multiselect-cell.js.map +1 -0
- package/dist/src/dx-grid.d.ts +147 -0
- package/dist/src/dx-grid.d.ts.map +1 -0
- package/dist/src/dx-grid.js +1375 -0
- package/dist/src/dx-grid.js.map +1 -0
- package/dist/src/dx-grid.lit-stories.d.ts +43 -0
- package/dist/src/dx-grid.lit-stories.d.ts.map +1 -0
- package/dist/src/dx-grid.lit-stories.js +176 -0
- package/dist/src/dx-grid.lit-stories.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +123 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +44 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/util.d.ts +9 -0
- package/dist/src/util.d.ts.map +1 -0
- package/dist/src/util.js +19 -0
- package/dist/src/util.js.map +1 -0
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts +16 -0
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
- package/dist/types/src/dx-grid-axis-resize-handle.js +96 -0
- package/dist/types/src/dx-grid-axis-resize-handle.js.map +1 -0
- package/dist/types/src/dx-grid-multiselect-cell.d.ts +13 -0
- package/dist/types/src/dx-grid-multiselect-cell.d.ts.map +1 -0
- package/dist/types/src/dx-grid-multiselect-cell.js +56 -0
- package/dist/types/src/dx-grid-multiselect-cell.js.map +1 -0
- package/dist/types/src/dx-grid.d.ts +121 -57
- package/dist/types/src/dx-grid.d.ts.map +1 -1
- package/dist/types/src/dx-grid.js +1375 -0
- package/dist/types/src/dx-grid.js.map +1 -0
- package/dist/types/src/dx-grid.lit-stories.d.ts +28 -2
- package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
- package/dist/types/src/dx-grid.lit-stories.js +176 -0
- package/dist/types/src/dx-grid.lit-stories.js.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/index.js +7 -0
- package/dist/types/src/index.js.map +1 -0
- package/dist/types/src/types.d.ts +115 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/types.js +44 -0
- package/dist/types/src/types.js.map +1 -0
- package/dist/types/src/util.d.ts +9 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/dist/types/src/util.js +19 -0
- package/dist/types/src/util.js.map +1 -0
- package/package.json +7 -7
- package/src/dx-grid-axis-resize-handle.pcss +23 -0
- package/src/dx-grid-axis-resize-handle.ts +87 -0
- package/src/dx-grid-multiselect-cell.pcss +32 -0
- package/src/dx-grid-multiselect-cell.ts +46 -0
- package/src/dx-grid.lit-stories.ts +159 -21
- package/src/dx-grid.pcss +70 -71
- package/src/dx-grid.ts +1307 -363
- package/src/index.ts +1 -0
- package/src/types.ts +165 -1
- package/src/util.ts +28 -0
- package/dist/lib/browser/index.mjs +0 -578
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -2,18 +2,182 @@
|
|
|
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
|
|
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' | 'edit-select';
|
|
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
|
+
* Whether this cell is read-only.
|
|
78
|
+
*/
|
|
79
|
+
readonly?: boolean;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type DxGridAxisMetaProps = {
|
|
83
|
+
size: number;
|
|
84
|
+
description?: string;
|
|
85
|
+
resizeable?: boolean;
|
|
86
|
+
readonly?: boolean;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type DxGridAxisSizes = DxGridPlaneRecord<DxGridFrozenPlane, Record<string, number>>;
|
|
90
|
+
|
|
91
|
+
export type DxGridProps = Partial<
|
|
92
|
+
Pick<
|
|
93
|
+
DxGrid,
|
|
94
|
+
| 'gridId'
|
|
95
|
+
| 'rowDefault'
|
|
96
|
+
| 'columnDefault'
|
|
97
|
+
| 'rows'
|
|
98
|
+
| 'columns'
|
|
99
|
+
| 'initialCells'
|
|
100
|
+
| 'mode'
|
|
101
|
+
| 'limitColumns'
|
|
102
|
+
| 'limitRows'
|
|
103
|
+
| 'frozen'
|
|
104
|
+
| 'overscroll'
|
|
105
|
+
| 'activeRefs'
|
|
106
|
+
>
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
export type DxGridSelectionProps = {
|
|
110
|
+
plane: DxGridPlane;
|
|
111
|
+
colMin: number;
|
|
112
|
+
colMax: number;
|
|
113
|
+
rowMin: number;
|
|
114
|
+
rowMax: number;
|
|
115
|
+
visible?: boolean;
|
|
116
|
+
};
|
|
8
117
|
|
|
9
118
|
export class DxAxisResize extends Event {
|
|
10
119
|
public readonly axis: DxGridAxis;
|
|
120
|
+
public readonly plane: 'grid' | DxGridFrozenPlane;
|
|
11
121
|
public readonly index: string;
|
|
12
122
|
public readonly size: number;
|
|
13
123
|
constructor(props: DxAxisResizeProps) {
|
|
14
124
|
super('dx-axis-resize');
|
|
15
125
|
this.axis = props.axis;
|
|
126
|
+
this.plane = props.plane;
|
|
16
127
|
this.index = props.index;
|
|
17
128
|
this.size = props.size;
|
|
18
129
|
}
|
|
19
130
|
}
|
|
131
|
+
|
|
132
|
+
export class DxAxisResizeInternal extends Event {
|
|
133
|
+
public readonly axis: DxGridAxis;
|
|
134
|
+
public readonly plane: 'grid' | DxGridFrozenPlane;
|
|
135
|
+
public readonly index: string;
|
|
136
|
+
public readonly size: number;
|
|
137
|
+
public readonly delta: number;
|
|
138
|
+
public readonly state: 'dragging' | 'dropped';
|
|
139
|
+
constructor(props: DxAxisResizeInternalProps) {
|
|
140
|
+
super('dx-axis-resize-internal', { composed: true, bubbles: true });
|
|
141
|
+
this.axis = props.axis;
|
|
142
|
+
this.plane = props.plane;
|
|
143
|
+
this.index = props.index;
|
|
144
|
+
this.size = props.size;
|
|
145
|
+
this.delta = props.delta;
|
|
146
|
+
this.state = props.state;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type DxEditRequestProps = Pick<DxEditRequest, 'cellIndex' | 'cellBox' | 'initialContent'>;
|
|
151
|
+
|
|
152
|
+
export class DxEditRequest extends Event {
|
|
153
|
+
public readonly cellIndex: DxGridCellIndex;
|
|
154
|
+
public readonly cellBox: Record<'insetInlineStart' | 'insetBlockStart' | 'inlineSize' | 'blockSize', number>;
|
|
155
|
+
public readonly initialContent?: string;
|
|
156
|
+
constructor(props: DxEditRequestProps) {
|
|
157
|
+
super('dx-edit-request');
|
|
158
|
+
this.cellIndex = props.cellIndex;
|
|
159
|
+
this.cellBox = props.cellBox;
|
|
160
|
+
this.initialContent = props.initialContent;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type DxGridPlaneRange = { start: DxGridPlanePosition; end: DxGridPlanePosition };
|
|
165
|
+
export type DxGridRange = { start: DxGridPosition; end: DxGridPosition };
|
|
166
|
+
|
|
167
|
+
export class DxGridCellsSelect extends Event {
|
|
168
|
+
public readonly start: string;
|
|
169
|
+
public readonly end: string;
|
|
170
|
+
public readonly minCol: number;
|
|
171
|
+
public readonly maxCol: number;
|
|
172
|
+
public readonly minRow: number;
|
|
173
|
+
public readonly maxRow: number;
|
|
174
|
+
constructor({ start, end }: DxGridRange) {
|
|
175
|
+
super('dx-grid-cells-select');
|
|
176
|
+
this.start = toCellIndex(start);
|
|
177
|
+
this.end = toCellIndex(end);
|
|
178
|
+
this.minCol = Math.min(start.col, end.col);
|
|
179
|
+
this.maxCol = Math.max(start.col, end.col);
|
|
180
|
+
this.minRow = Math.min(start.row, end.row);
|
|
181
|
+
this.maxRow = Math.max(start.row, end.row);
|
|
182
|
+
}
|
|
183
|
+
}
|
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
|
+
};
|