@octane-xplat/table 0.0.1 → 0.10.0
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/LICENSE +21 -0
- package/README.md +427 -3
- package/dist/native/ColumnDrag.tsrx.js +237 -0
- package/dist/native/DataGrid.tsrx.js +957 -0
- package/dist/native/GridControls.tsrx.js +424 -0
- package/dist/native/grid-accessibility.js +12 -0
- package/dist/native/grid-layout.js +43 -0
- package/dist/native/index.js +4 -0
- package/dist/native/octane-client-build.json +8 -0
- package/dist/native/table.js +56 -0
- package/dist/native/useTable.tsrx.js +24 -0
- package/dist/web/ColumnDrag.tsrx.js +85 -0
- package/dist/web/DataGrid.tsrx.js +242 -0
- package/dist/web/GridControls.tsrx.js +114 -0
- package/dist/web/grid-accessibility.js +12 -0
- package/dist/web/grid-layout.js +43 -0
- package/dist/web/index.js +4 -0
- package/dist/web/octane-client-build.json +8 -0
- package/dist/web/table.js +56 -0
- package/dist/web/useTable.tsrx.js +26 -0
- package/package.json +75 -3
- package/src/ColumnDrag.tsrx +123 -0
- package/src/DataGrid.mobile.test.tsrx +55 -0
- package/src/DataGrid.tsrx +350 -0
- package/src/DataGrid.web.test.tsrx +277 -0
- package/src/GridControls.tsrx +157 -0
- package/src/grid-accessibility.ts +14 -0
- package/src/grid-layout.test.ts +32 -0
- package/src/grid-layout.ts +52 -0
- package/src/index.macos.ts +8 -0
- package/src/index.ts +7 -0
- package/src/index.web.ts +8 -0
- package/src/props.ts +122 -0
- package/src/table.test.ts +114 -0
- package/src/table.ts +91 -0
- package/src/useTable.tsrx +34 -0
- package/types/index.d.ts +20 -0
- package/types/index.macos.d.ts +17 -0
- package/types/props.d.ts +96 -0
- package/types/table.d.ts +83 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { moveColumn } from "./grid-layout.js";
|
|
2
|
+
import { defineUniversalComponent, hookSlots, universalChildren, universalComponent, universalPlan, universalProps, universalValue, useState } from "@nativescript-community/octane";
|
|
3
|
+
import { CheckboxInput, HStack, Pressable, Text, TextInput, View } from "@octane-xplat/ui";
|
|
4
|
+
//#region src/GridControls.tsrx
|
|
5
|
+
var _h$0 = /* @__PURE__ */ Symbol(/* @__PURE__ */ hookSlots(1));
|
|
6
|
+
var __octaneUniversalPlan0 = universalPlan("nativescript", {
|
|
7
|
+
"kind": "slot",
|
|
8
|
+
"slot": 0
|
|
9
|
+
});
|
|
10
|
+
var __octaneUniversalPlan1 = universalPlan("nativescript", {
|
|
11
|
+
"kind": "slot",
|
|
12
|
+
"slot": 0
|
|
13
|
+
});
|
|
14
|
+
var __octaneUniversalPlan2 = universalPlan("nativescript", {
|
|
15
|
+
"kind": "slot",
|
|
16
|
+
"slot": 0
|
|
17
|
+
});
|
|
18
|
+
var __octaneUniversalPlan3 = universalPlan("nativescript", {
|
|
19
|
+
"kind": "slot",
|
|
20
|
+
"slot": 0
|
|
21
|
+
});
|
|
22
|
+
var __octaneUniversalPlan4 = universalPlan("nativescript", {
|
|
23
|
+
"kind": "range",
|
|
24
|
+
"children": [{
|
|
25
|
+
"kind": "slot",
|
|
26
|
+
"slot": 0
|
|
27
|
+
}, {
|
|
28
|
+
"kind": "slot",
|
|
29
|
+
"slot": 1
|
|
30
|
+
}]
|
|
31
|
+
});
|
|
32
|
+
var __octaneUniversalPlan5 = universalPlan("nativescript", {
|
|
33
|
+
"kind": "range",
|
|
34
|
+
"children": [
|
|
35
|
+
{
|
|
36
|
+
"kind": "slot",
|
|
37
|
+
"slot": 0
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"kind": "slot",
|
|
41
|
+
"slot": 1
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"kind": "slot",
|
|
45
|
+
"slot": 2
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
var __octaneUniversalPlan6 = universalPlan("nativescript", {
|
|
50
|
+
"kind": "slot",
|
|
51
|
+
"slot": 0
|
|
52
|
+
});
|
|
53
|
+
var __octaneUniversalPlan7 = universalPlan("nativescript", {
|
|
54
|
+
"kind": "range",
|
|
55
|
+
"children": [{
|
|
56
|
+
"kind": "slot",
|
|
57
|
+
"slot": 0
|
|
58
|
+
}, {
|
|
59
|
+
"kind": "slot",
|
|
60
|
+
"slot": 1
|
|
61
|
+
}]
|
|
62
|
+
});
|
|
63
|
+
var __octaneUniversalPlan8 = universalPlan("nativescript", {
|
|
64
|
+
"kind": "slot",
|
|
65
|
+
"slot": 0
|
|
66
|
+
});
|
|
67
|
+
var __octaneUniversalPlan9 = universalPlan("nativescript", {
|
|
68
|
+
"kind": "range",
|
|
69
|
+
"children": [{
|
|
70
|
+
"kind": "slot",
|
|
71
|
+
"slot": 0
|
|
72
|
+
}, {
|
|
73
|
+
"kind": "slot",
|
|
74
|
+
"slot": 1
|
|
75
|
+
}]
|
|
76
|
+
});
|
|
77
|
+
var __octaneUniversalPlan10 = universalPlan("nativescript", {
|
|
78
|
+
"kind": "slot",
|
|
79
|
+
"slot": 0
|
|
80
|
+
});
|
|
81
|
+
var __octaneUniversalPlan11 = universalPlan("nativescript", {
|
|
82
|
+
"kind": "slot",
|
|
83
|
+
"slot": 0
|
|
84
|
+
});
|
|
85
|
+
var __octaneUniversalPlan12 = universalPlan("nativescript", {
|
|
86
|
+
"kind": "range",
|
|
87
|
+
"children": [
|
|
88
|
+
{
|
|
89
|
+
"kind": "slot",
|
|
90
|
+
"slot": 0
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"kind": "slot",
|
|
94
|
+
"slot": 1
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"kind": "slot",
|
|
98
|
+
"slot": 2
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"kind": "slot",
|
|
102
|
+
"slot": 3
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
var __octaneUniversalPlan13 = universalPlan("nativescript", {
|
|
107
|
+
"kind": "slot",
|
|
108
|
+
"slot": 0
|
|
109
|
+
});
|
|
110
|
+
var Action = defineUniversalComponent("nativescript", function Action(props) {
|
|
111
|
+
return universalValue(__octaneUniversalPlan1, [universalComponent("nativescript", Pressable, universalProps([
|
|
112
|
+
[
|
|
113
|
+
"set",
|
|
114
|
+
"id",
|
|
115
|
+
props.id
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"set",
|
|
119
|
+
"className",
|
|
120
|
+
"vx-datagrid-action"
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
"set",
|
|
124
|
+
"disabled",
|
|
125
|
+
props.disabled
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
"set",
|
|
129
|
+
"onPress",
|
|
130
|
+
props.onPress
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
"set",
|
|
134
|
+
"accessibilityLabel",
|
|
135
|
+
props.label
|
|
136
|
+
]
|
|
137
|
+
], universalChildren("nativescript", () => {
|
|
138
|
+
return universalValue(__octaneUniversalPlan0, [universalComponent("nativescript", Text, universalProps([], props.label))]);
|
|
139
|
+
})))]);
|
|
140
|
+
}, { "module": "@nativescript-community/octane" });
|
|
141
|
+
var GridControls = defineUniversalComponent("nativescript", function GridControls(props) {
|
|
142
|
+
const [settingsOpen, setSettingsOpen] = useState(false, _h$0);
|
|
143
|
+
props.state;
|
|
144
|
+
const table = props.table;
|
|
145
|
+
const columns = table.getAllLeafColumns();
|
|
146
|
+
const order = columns.map((column) => column.id);
|
|
147
|
+
const move = (id, index) => table.setColumnOrder(moveColumn(order, id, order[index]));
|
|
148
|
+
return universalValue(__octaneUniversalPlan10, [universalComponent("nativescript", View, universalProps([], universalChildren("nativescript", () => {
|
|
149
|
+
return universalValue(__octaneUniversalPlan9, [universalComponent("nativescript", HStack, universalProps([[
|
|
150
|
+
"set",
|
|
151
|
+
"className",
|
|
152
|
+
"vx-datagrid-controls"
|
|
153
|
+
]], universalChildren("nativescript", () => {
|
|
154
|
+
return universalValue(__octaneUniversalPlan4, [props.search ? universalValue(__octaneUniversalPlan2, [universalComponent("nativescript", TextInput, universalProps([
|
|
155
|
+
[
|
|
156
|
+
"set",
|
|
157
|
+
"id",
|
|
158
|
+
props.id ? `${props.id}-search` : void 0
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
"set",
|
|
162
|
+
"className",
|
|
163
|
+
"flex-1"
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
"set",
|
|
167
|
+
"value",
|
|
168
|
+
String(props.state.globalFilter ?? "")
|
|
169
|
+
],
|
|
170
|
+
[
|
|
171
|
+
"set",
|
|
172
|
+
"placeholder",
|
|
173
|
+
"Filter rows"
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
"set",
|
|
177
|
+
"accessibilityLabel",
|
|
178
|
+
"Filter rows"
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
"set",
|
|
182
|
+
"onChange",
|
|
183
|
+
(value) => {
|
|
184
|
+
table.setGlobalFilter(value);
|
|
185
|
+
table.setPageIndex(0);
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
]))]) : null, props.settings ? universalValue(__octaneUniversalPlan3, [universalComponent("nativescript", Action, universalProps([
|
|
189
|
+
[
|
|
190
|
+
"set",
|
|
191
|
+
"id",
|
|
192
|
+
props.id ? `${props.id}-settings` : void 0
|
|
193
|
+
],
|
|
194
|
+
[
|
|
195
|
+
"set",
|
|
196
|
+
"label",
|
|
197
|
+
"Columns"
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
"set",
|
|
201
|
+
"onPress",
|
|
202
|
+
() => setSettingsOpen(!settingsOpen)
|
|
203
|
+
]
|
|
204
|
+
]))]) : null]);
|
|
205
|
+
}))), props.settings && settingsOpen ? universalValue(__octaneUniversalPlan8, [universalComponent("nativescript", View, universalProps([[
|
|
206
|
+
"set",
|
|
207
|
+
"className",
|
|
208
|
+
"vx-datagrid-settings"
|
|
209
|
+
]], universalChildren("nativescript", () => {
|
|
210
|
+
return universalValue(__octaneUniversalPlan7, [columns.map((column, index) => universalValue(__octaneUniversalPlan6, [universalComponent("nativescript", HStack, universalProps([[
|
|
211
|
+
"set",
|
|
212
|
+
"key",
|
|
213
|
+
column.id
|
|
214
|
+
], [
|
|
215
|
+
"set",
|
|
216
|
+
"className",
|
|
217
|
+
"vx-datagrid-controls"
|
|
218
|
+
]], universalChildren("nativescript", () => {
|
|
219
|
+
return universalValue(__octaneUniversalPlan5, [
|
|
220
|
+
universalComponent("nativescript", CheckboxInput, universalProps([
|
|
221
|
+
[
|
|
222
|
+
"set",
|
|
223
|
+
"id",
|
|
224
|
+
props.id ? `${props.id}-visible-${column.id}` : void 0
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
"set",
|
|
228
|
+
"checked",
|
|
229
|
+
column.getIsVisible()
|
|
230
|
+
],
|
|
231
|
+
[
|
|
232
|
+
"set",
|
|
233
|
+
"isDisabled",
|
|
234
|
+
!column.getCanHide()
|
|
235
|
+
],
|
|
236
|
+
[
|
|
237
|
+
"set",
|
|
238
|
+
"label",
|
|
239
|
+
typeof column.columnDef.header === "string" ? column.columnDef.header : column.id
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
"set",
|
|
243
|
+
"accessibilityLabel",
|
|
244
|
+
`Show ${column.id}`
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
"set",
|
|
248
|
+
"onCheckedChange",
|
|
249
|
+
(checked) => column.toggleVisibility(checked)
|
|
250
|
+
]
|
|
251
|
+
])),
|
|
252
|
+
universalComponent("nativescript", Action, universalProps([
|
|
253
|
+
[
|
|
254
|
+
"set",
|
|
255
|
+
"id",
|
|
256
|
+
props.id ? `${props.id}-earlier-${column.id}` : void 0
|
|
257
|
+
],
|
|
258
|
+
[
|
|
259
|
+
"set",
|
|
260
|
+
"label",
|
|
261
|
+
`Move ${column.id} earlier`
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
"set",
|
|
265
|
+
"disabled",
|
|
266
|
+
index === 0
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
"set",
|
|
270
|
+
"onPress",
|
|
271
|
+
() => move(column.id, index - 1)
|
|
272
|
+
]
|
|
273
|
+
])),
|
|
274
|
+
universalComponent("nativescript", Action, universalProps([
|
|
275
|
+
[
|
|
276
|
+
"set",
|
|
277
|
+
"id",
|
|
278
|
+
props.id ? `${props.id}-later-${column.id}` : void 0
|
|
279
|
+
],
|
|
280
|
+
[
|
|
281
|
+
"set",
|
|
282
|
+
"label",
|
|
283
|
+
`Move ${column.id} later`
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
"set",
|
|
287
|
+
"disabled",
|
|
288
|
+
index === columns.length - 1
|
|
289
|
+
],
|
|
290
|
+
[
|
|
291
|
+
"set",
|
|
292
|
+
"onPress",
|
|
293
|
+
() => move(column.id, index + 1)
|
|
294
|
+
]
|
|
295
|
+
]))
|
|
296
|
+
]);
|
|
297
|
+
})))])), universalComponent("nativescript", Action, universalProps([
|
|
298
|
+
[
|
|
299
|
+
"set",
|
|
300
|
+
"id",
|
|
301
|
+
props.id ? `${props.id}-reset-columns` : void 0
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
"set",
|
|
305
|
+
"label",
|
|
306
|
+
"Reset columns"
|
|
307
|
+
],
|
|
308
|
+
[
|
|
309
|
+
"set",
|
|
310
|
+
"onPress",
|
|
311
|
+
() => {
|
|
312
|
+
table.resetColumnVisibility();
|
|
313
|
+
table.resetColumnOrder();
|
|
314
|
+
table.resetColumnSizing();
|
|
315
|
+
}
|
|
316
|
+
]
|
|
317
|
+
]))]);
|
|
318
|
+
})))]) : null]);
|
|
319
|
+
})))]);
|
|
320
|
+
}, { "module": "@nativescript-community/octane" });
|
|
321
|
+
var GridPagination = defineUniversalComponent("nativescript", function GridPagination(props) {
|
|
322
|
+
props.state;
|
|
323
|
+
const table = props.table;
|
|
324
|
+
const { pageIndex, pageSize } = props.state.pagination;
|
|
325
|
+
const count = table.getPageCount();
|
|
326
|
+
const sizes = [...new Set((props.sizes ?? [
|
|
327
|
+
10,
|
|
328
|
+
25,
|
|
329
|
+
50
|
|
330
|
+
]).filter((size) => Number.isInteger(size) && size > 0))];
|
|
331
|
+
return universalValue(__octaneUniversalPlan13, [universalComponent("nativescript", HStack, universalProps([[
|
|
332
|
+
"set",
|
|
333
|
+
"className",
|
|
334
|
+
"vx-datagrid-controls"
|
|
335
|
+
], [
|
|
336
|
+
"set",
|
|
337
|
+
"accessibilityLabel",
|
|
338
|
+
"Pagination"
|
|
339
|
+
]], universalChildren("nativescript", () => {
|
|
340
|
+
return universalValue(__octaneUniversalPlan12, [
|
|
341
|
+
universalComponent("nativescript", Action, universalProps([
|
|
342
|
+
[
|
|
343
|
+
"set",
|
|
344
|
+
"id",
|
|
345
|
+
props.id ? `${props.id}-previous` : void 0
|
|
346
|
+
],
|
|
347
|
+
[
|
|
348
|
+
"set",
|
|
349
|
+
"label",
|
|
350
|
+
"Previous page"
|
|
351
|
+
],
|
|
352
|
+
[
|
|
353
|
+
"set",
|
|
354
|
+
"disabled",
|
|
355
|
+
!table.getCanPreviousPage()
|
|
356
|
+
],
|
|
357
|
+
[
|
|
358
|
+
"set",
|
|
359
|
+
"onPress",
|
|
360
|
+
() => table.previousPage()
|
|
361
|
+
]
|
|
362
|
+
])),
|
|
363
|
+
universalComponent("nativescript", Text, universalProps([[
|
|
364
|
+
"set",
|
|
365
|
+
"id",
|
|
366
|
+
props.id ? `${props.id}-page` : void 0
|
|
367
|
+
]], count < 0 ? `Page ${pageIndex + 1}` : `Page ${count === 0 ? 0 : pageIndex + 1} of ${count}`)),
|
|
368
|
+
universalComponent("nativescript", Action, universalProps([
|
|
369
|
+
[
|
|
370
|
+
"set",
|
|
371
|
+
"id",
|
|
372
|
+
props.id ? `${props.id}-next` : void 0
|
|
373
|
+
],
|
|
374
|
+
[
|
|
375
|
+
"set",
|
|
376
|
+
"label",
|
|
377
|
+
"Next page"
|
|
378
|
+
],
|
|
379
|
+
[
|
|
380
|
+
"set",
|
|
381
|
+
"disabled",
|
|
382
|
+
!table.getCanNextPage()
|
|
383
|
+
],
|
|
384
|
+
[
|
|
385
|
+
"set",
|
|
386
|
+
"onPress",
|
|
387
|
+
() => table.nextPage()
|
|
388
|
+
]
|
|
389
|
+
])),
|
|
390
|
+
sizes.map((size) => universalValue(__octaneUniversalPlan11, [universalComponent("nativescript", Action, universalProps([
|
|
391
|
+
[
|
|
392
|
+
"set",
|
|
393
|
+
"key",
|
|
394
|
+
size
|
|
395
|
+
],
|
|
396
|
+
[
|
|
397
|
+
"set",
|
|
398
|
+
"id",
|
|
399
|
+
props.id ? `${props.id}-size-${size}` : void 0
|
|
400
|
+
],
|
|
401
|
+
[
|
|
402
|
+
"set",
|
|
403
|
+
"label",
|
|
404
|
+
`${size} per page`
|
|
405
|
+
],
|
|
406
|
+
[
|
|
407
|
+
"set",
|
|
408
|
+
"disabled",
|
|
409
|
+
pageSize === size
|
|
410
|
+
],
|
|
411
|
+
[
|
|
412
|
+
"set",
|
|
413
|
+
"onPress",
|
|
414
|
+
() => {
|
|
415
|
+
table.setPageSize(size);
|
|
416
|
+
table.setPageIndex(0);
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
]))]))
|
|
420
|
+
]);
|
|
421
|
+
})))]);
|
|
422
|
+
}, { "module": "@nativescript-community/octane" });
|
|
423
|
+
//#endregion
|
|
424
|
+
export { GridControls, GridPagination };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/grid-accessibility.ts
|
|
2
|
+
/** Positions describe the final flat row model, before VirtualList windowing.
|
|
3
|
+
* Header rows count toward ARIA indices, but not the spoken data-row ordinal. */
|
|
4
|
+
function gridRowPosition(index, pagination, headerRows, rowCount) {
|
|
5
|
+
const ordinal = pagination.pageIndex * pagination.pageSize + index + 1;
|
|
6
|
+
return {
|
|
7
|
+
ariaIndex: headerRows + ordinal,
|
|
8
|
+
label: rowCount < 0 ? `Row ${ordinal}` : `Row ${ordinal} of ${rowCount}`
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { gridRowPosition };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/grid-layout.ts
|
|
2
|
+
/** Resolve the displayed width without changing flexible legacy columns. */
|
|
3
|
+
function columnStyle(column, fixed, sizing) {
|
|
4
|
+
return fixed || column.columnDef.size != null || sizing[column.id] != null ? {
|
|
5
|
+
width: column.getSize(),
|
|
6
|
+
flexGrow: 0,
|
|
7
|
+
flexShrink: 0
|
|
8
|
+
} : {
|
|
9
|
+
flexGrow: 1,
|
|
10
|
+
flexShrink: 1
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Move a column within the complete order, preserving hidden columns. */
|
|
14
|
+
function moveColumn(order, source, target) {
|
|
15
|
+
const from = order.indexOf(source);
|
|
16
|
+
const to = order.indexOf(target);
|
|
17
|
+
if (from < 0 || to < 0 || from === to) return order;
|
|
18
|
+
const next = [...order];
|
|
19
|
+
next.splice(from, 1);
|
|
20
|
+
next.splice(to, 0, source);
|
|
21
|
+
return next;
|
|
22
|
+
}
|
|
23
|
+
/** Find the visible column whose midpoint a horizontal drag has crossed. */
|
|
24
|
+
function dragTarget(columns, id, dx) {
|
|
25
|
+
const from = columns.findIndex((column) => column.id === id);
|
|
26
|
+
if (from < 0 || !Number.isFinite(dx)) return id;
|
|
27
|
+
let distance = columns[from].getSize() / 2;
|
|
28
|
+
let target = id;
|
|
29
|
+
const direction = dx < 0 ? -1 : 1;
|
|
30
|
+
for (let i = from + direction; i >= 0 && i < columns.length; i += direction) {
|
|
31
|
+
distance += columns[i].getSize() / 2;
|
|
32
|
+
if (Math.abs(dx) < distance) break;
|
|
33
|
+
target = columns[i].id;
|
|
34
|
+
distance += columns[i].getSize() / 2;
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
}
|
|
38
|
+
/** Clamp interactive widths to the column's configured bounds. */
|
|
39
|
+
function resizedWidth(column, width) {
|
|
40
|
+
return Math.max(column.columnDef.minSize ?? 20, Math.min(column.columnDef.maxSize ?? Number.MAX_SAFE_INTEGER, width));
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { columnStyle, dragTarget, moveColumn, resizedWidth };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { aggregationFns, columnFacetingFeature, columnFilteringFeature, columnGroupingFeature, columnOrderingFeature, columnPinningFeature, columnSizingFeature, columnVisibilityFeature, constructTable, createExpandedRowModel, createFacetedMinMaxValues, createFacetedRowModel, createFacetedUniqueValues, createFilteredRowModel, createGroupedRowModel, createPaginatedRowModel, createSortedRowModel, filterFns, globalFilteringFeature, rowAggregationFeature, rowExpandingFeature, rowPaginationFeature, rowPinningFeature, rowSelectionFeature, rowSortingFeature, sortFns, tableFeatures } from "@tanstack/table-core";
|
|
2
|
+
import { storeReactivityBindings } from "@tanstack/table-core/store-reactivity-bindings";
|
|
3
|
+
//#region src/table.ts
|
|
4
|
+
/** DataGrid's default feature slots: every stock feature whose machinery is
|
|
5
|
+
* DOM-free — sorting, filtering, grouping, expanding, pagination, pinning,
|
|
6
|
+
* selection, column ordering/visibility/sizing, faceting, global filtering,
|
|
7
|
+
* aggregation — plus the row-model factories and builtin fn registries that
|
|
8
|
+
* v9 keeps as separate slots. Omitted: `columnResizingFeature` (its drag
|
|
9
|
+
* handler installs global event listeners — web-only; resize gesture UI
|
|
10
|
+
* belongs to platform leaves) and `cellSelectionFeature`/`cellSpanningFeature`
|
|
11
|
+
* (range-selection UX is web-spreadsheet-shaped, not a v1 xplat idiom). Pass
|
|
12
|
+
* `features` to add them where a platform leaf supports them. */
|
|
13
|
+
var dataGridFeatures = tableFeatures({
|
|
14
|
+
columnFacetingFeature,
|
|
15
|
+
columnFilteringFeature,
|
|
16
|
+
columnGroupingFeature,
|
|
17
|
+
columnOrderingFeature,
|
|
18
|
+
columnPinningFeature,
|
|
19
|
+
columnSizingFeature,
|
|
20
|
+
columnVisibilityFeature,
|
|
21
|
+
globalFilteringFeature,
|
|
22
|
+
rowAggregationFeature,
|
|
23
|
+
rowExpandingFeature,
|
|
24
|
+
rowPaginationFeature,
|
|
25
|
+
rowPinningFeature,
|
|
26
|
+
rowSelectionFeature,
|
|
27
|
+
rowSortingFeature,
|
|
28
|
+
sortedRowModel: createSortedRowModel(),
|
|
29
|
+
filteredRowModel: createFilteredRowModel(),
|
|
30
|
+
groupedRowModel: createGroupedRowModel(),
|
|
31
|
+
expandedRowModel: createExpandedRowModel(),
|
|
32
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
33
|
+
facetedRowModel: createFacetedRowModel(),
|
|
34
|
+
facetedMinMaxValues: createFacetedMinMaxValues(),
|
|
35
|
+
facetedUniqueValues: createFacetedUniqueValues(),
|
|
36
|
+
sortFns,
|
|
37
|
+
filterFns,
|
|
38
|
+
aggregationFns
|
|
39
|
+
});
|
|
40
|
+
/** Construct a table instance bound to TanStack Store reactivity — the
|
|
41
|
+
* vanilla/non-framework binding (`table.optionsStore` subscribable, atoms
|
|
42
|
+
* from `@tanstack/store`, `queueMicrotask` scheduling — all DOM-free). Wrap
|
|
43
|
+
* with `useTable` inside a component; call directly for non-rendering
|
|
44
|
+
* consumers (tests, headless row models). */
|
|
45
|
+
function createTable(options) {
|
|
46
|
+
return constructTable({
|
|
47
|
+
...options,
|
|
48
|
+
features: {
|
|
49
|
+
coreReactivityFeature: storeReactivityBindings(),
|
|
50
|
+
...dataGridFeatures,
|
|
51
|
+
...options.features
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { createTable, dataGridFeatures };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createTable } from "./table.js";
|
|
2
|
+
import { hookSlots, useCallback, useState, useSyncExternalStore } from "@nativescript-community/octane";
|
|
3
|
+
//#region src/useTable.tsrx
|
|
4
|
+
var _hs$ = /* @__PURE__ */ hookSlots(3);
|
|
5
|
+
var _h$0 = /* @__PURE__ */ Symbol(_hs$);
|
|
6
|
+
var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
|
|
7
|
+
var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
|
|
8
|
+
function useTable(options) {
|
|
9
|
+
const [{ table }] = useState(() => ({ table: createTable(options) }), _h$0);
|
|
10
|
+
table.setOptions((prev) => ({
|
|
11
|
+
...prev,
|
|
12
|
+
...options
|
|
13
|
+
}));
|
|
14
|
+
const subscribe = useCallback((notify) => {
|
|
15
|
+
const sub = table.store.subscribe(() => notify());
|
|
16
|
+
return () => sub.unsubscribe();
|
|
17
|
+
}, [table], _h$1);
|
|
18
|
+
return {
|
|
19
|
+
table,
|
|
20
|
+
state: useSyncExternalStore(subscribe, () => table.store.get(), _h$2)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { useTable };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { dragTarget, moveColumn, resizedWidth } from "./grid-layout.js";
|
|
2
|
+
import { Fragment, createScopedElement, createScopedValue, hookSlots, positionalChildren, useRef } from "octane";
|
|
3
|
+
import { createElementFromConfig } from "octane/internal/client";
|
|
4
|
+
import { HStack, Pressable, Text, View } from "@octane-xplat/ui";
|
|
5
|
+
//#region src/ColumnDrag.tsrx
|
|
6
|
+
var _h$0 = /* @__PURE__ */ Symbol(/* @__PURE__ */ hookSlots(1));
|
|
7
|
+
function ColumnDrag(props) {
|
|
8
|
+
props.state;
|
|
9
|
+
const drag = useRef(null, _h$0);
|
|
10
|
+
const begin = () => {
|
|
11
|
+
drag.current = {
|
|
12
|
+
size: props.column.getSize(),
|
|
13
|
+
sizing: { ...props.table.store.get().columnSizing },
|
|
14
|
+
order: props.table.getAllLeafColumns().map((column) => column.id),
|
|
15
|
+
columns: props.table.getVisibleLeafColumns().map((column) => {
|
|
16
|
+
const size = column.getSize();
|
|
17
|
+
return {
|
|
18
|
+
id: column.id,
|
|
19
|
+
getSize: () => size
|
|
20
|
+
};
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const onPan = (event, resize) => {
|
|
25
|
+
if (event.state === "began") {
|
|
26
|
+
begin();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const start = drag.current;
|
|
30
|
+
if (!start) return;
|
|
31
|
+
if (event.state === "cancelled") {
|
|
32
|
+
if (resize) props.table.setColumnSizing((old) => {
|
|
33
|
+
const next = { ...old };
|
|
34
|
+
if (start.sizing[props.column.id] == null) delete next[props.column.id];
|
|
35
|
+
else next[props.column.id] = start.sizing[props.column.id];
|
|
36
|
+
return next;
|
|
37
|
+
});
|
|
38
|
+
drag.current = null;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const dx = event.dx * (props.direction === "rtl" ? -1 : 1);
|
|
42
|
+
if (resize && Number.isFinite(dx)) props.table.setColumnSizing((old) => ({
|
|
43
|
+
...old,
|
|
44
|
+
[props.column.id]: resizedWidth(props.column, start.size + dx)
|
|
45
|
+
}));
|
|
46
|
+
if (event.state === "ended") {
|
|
47
|
+
if (!resize) {
|
|
48
|
+
const target = dragTarget(start.columns, props.column.id, dx);
|
|
49
|
+
props.table.setColumnOrder(moveColumn(start.order, props.column.id, target));
|
|
50
|
+
}
|
|
51
|
+
drag.current = null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const adjust = (delta) => props.table.setColumnSizing((old) => ({
|
|
55
|
+
...old,
|
|
56
|
+
[props.column.id]: resizedWidth(props.column, props.column.getSize() + delta)
|
|
57
|
+
}));
|
|
58
|
+
return createScopedElement(HStack, { className: "vx-datagrid-handles" }, () => positionalChildren([props.reorder ? createScopedValue(() => createScopedElement(View, {
|
|
59
|
+
id: props.id ? `${props.id}-drag` : void 0,
|
|
60
|
+
className: "vx-datagrid-handle",
|
|
61
|
+
onPan: (event) => onPan(event, false),
|
|
62
|
+
accessibilityLabel: `Drag ${props.column.id} to reorder`
|
|
63
|
+
}, () => createElementFromConfig("c:d5e6d01e", Text, {}, ["↔"]), "c:9da8188a")) : null, props.resize ? createScopedElement(Fragment, {}, () => positionalChildren([
|
|
64
|
+
createScopedValue(() => createScopedElement(Pressable, {
|
|
65
|
+
id: props.id ? `${props.id}-narrow` : void 0,
|
|
66
|
+
className: "vx-datagrid-handle",
|
|
67
|
+
onPress: () => adjust(-10),
|
|
68
|
+
accessibilityLabel: `Narrow ${props.column.id}`
|
|
69
|
+
}, () => createElementFromConfig("c:376fb3c0", Text, {}, ["−"]), "c:f1407fa0")),
|
|
70
|
+
createScopedValue(() => createScopedElement(View, {
|
|
71
|
+
id: props.id ? `${props.id}-resize` : void 0,
|
|
72
|
+
className: "vx-datagrid-handle",
|
|
73
|
+
onPan: (event) => onPan(event, true),
|
|
74
|
+
accessibilityLabel: `Drag to resize ${props.column.id}`
|
|
75
|
+
}, () => createElementFromConfig("c:a915504c", Text, {}, ["│"]), "c:0441cf15")),
|
|
76
|
+
createScopedValue(() => createScopedElement(Pressable, {
|
|
77
|
+
id: props.id ? `${props.id}-widen` : void 0,
|
|
78
|
+
className: "vx-datagrid-handle",
|
|
79
|
+
onPress: () => adjust(10),
|
|
80
|
+
accessibilityLabel: `Widen ${props.column.id}`
|
|
81
|
+
}, () => createElementFromConfig("c:0b4f279f", Text, {}, ["+"]), "c:862eb88c"))
|
|
82
|
+
])) : null]), "c:1fd84f18");
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { ColumnDrag };
|