@multiplatform.one/table 9.4.0 → 9.6.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/dist/cjs/components/ChildTable/index.cjs +4 -2
- package/dist/cjs/components/ChildTable/index.native.js +4 -2
- package/dist/cjs/components/ChildTable/index.native.js.map +1 -1
- package/dist/cjs/components/DataTableCell/index.cjs +5 -0
- package/dist/cjs/components/DataTableCell/index.native.js +5 -0
- package/dist/cjs/components/DataTableCell/index.native.js.map +1 -1
- package/dist/cjs/components/TableInput/ChildRowList.cjs +262 -0
- package/dist/cjs/components/TableInput/ChildRowList.native.js +287 -0
- package/dist/cjs/components/TableInput/ChildRowList.native.js.map +1 -0
- package/dist/cjs/components/TableInput/RowDetailEditor.cjs +14 -3
- package/dist/cjs/components/TableInput/index.cjs +200 -13
- package/dist/cjs/components/TableInput/index.native.js +1 -0
- package/dist/cjs/components/TableInput/index.native.js.map +1 -1
- package/dist/cjs/components/TableInput/shared.cjs +37 -0
- package/dist/cjs/components/TableInput/shared.native.js +48 -0
- package/dist/cjs/components/TableInput/shared.native.js.map +1 -1
- package/dist/esm/components/ChildTable/index.mjs +4 -2
- package/dist/esm/components/ChildTable/index.mjs.map +1 -1
- package/dist/esm/components/ChildTable/index.native.js +4 -2
- package/dist/esm/components/ChildTable/index.native.js.map +1 -1
- package/dist/esm/components/DataTableCell/index.mjs +5 -0
- package/dist/esm/components/DataTableCell/index.mjs.map +1 -1
- package/dist/esm/components/DataTableCell/index.native.js +5 -0
- package/dist/esm/components/DataTableCell/index.native.js.map +1 -1
- package/dist/esm/components/TableInput/ChildRowList.mjs +235 -0
- package/dist/esm/components/TableInput/ChildRowList.mjs.map +1 -0
- package/dist/esm/components/TableInput/ChildRowList.native.js +257 -0
- package/dist/esm/components/TableInput/ChildRowList.native.js.map +1 -0
- package/dist/esm/components/TableInput/RowDetailEditor.mjs +15 -4
- package/dist/esm/components/TableInput/RowDetailEditor.mjs.map +1 -1
- package/dist/esm/components/TableInput/index.mjs +204 -17
- package/dist/esm/components/TableInput/index.mjs.map +1 -1
- package/dist/esm/components/TableInput/index.native.js +2 -1
- package/dist/esm/components/TableInput/index.native.js.map +1 -1
- package/dist/esm/components/TableInput/shared.mjs +35 -1
- package/dist/esm/components/TableInput/shared.mjs.map +1 -1
- package/dist/esm/components/TableInput/shared.native.js +46 -1
- package/dist/esm/components/TableInput/shared.native.js.map +1 -1
- package/dist/jsx/components/ChildTable/index.mjs +4 -2
- package/dist/jsx/components/ChildTable/index.mjs.map +1 -1
- package/dist/jsx/components/ChildTable/index.native.js +4 -2
- package/dist/jsx/components/ChildTable/index.native.js.map +1 -1
- package/dist/jsx/components/DataTableCell/index.mjs +5 -0
- package/dist/jsx/components/DataTableCell/index.mjs.map +1 -1
- package/dist/jsx/components/DataTableCell/index.native.js +5 -0
- package/dist/jsx/components/DataTableCell/index.native.js.map +1 -1
- package/dist/jsx/components/TableInput/ChildRowList.mjs +235 -0
- package/dist/jsx/components/TableInput/ChildRowList.mjs.map +1 -0
- package/dist/jsx/components/TableInput/ChildRowList.native.js +287 -0
- package/dist/jsx/components/TableInput/ChildRowList.native.js.map +1 -0
- package/dist/jsx/components/TableInput/RowDetailEditor.mjs +15 -4
- package/dist/jsx/components/TableInput/RowDetailEditor.mjs.map +1 -1
- package/dist/jsx/components/TableInput/index.mjs +204 -17
- package/dist/jsx/components/TableInput/index.mjs.map +1 -1
- package/dist/jsx/components/TableInput/index.native.js +1 -0
- package/dist/jsx/components/TableInput/index.native.js.map +1 -1
- package/dist/jsx/components/TableInput/shared.mjs +35 -1
- package/dist/jsx/components/TableInput/shared.mjs.map +1 -1
- package/dist/jsx/components/TableInput/shared.native.js +48 -0
- package/dist/jsx/components/TableInput/shared.native.js.map +1 -1
- package/package.json +12 -12
- package/src/components/ChildTable/ChildTable.stories.tsx +50 -0
- package/src/components/ChildTable/index.tsx +4 -0
- package/src/components/DataTableCell/index.tsx +3 -0
- package/src/components/TableInput/ChildRowList.tsx +290 -0
- package/src/components/TableInput/RowDetailEditor.tsx +15 -4
- package/src/components/TableInput/childRowList.spec.tsx +141 -0
- package/src/components/TableInput/index.native.tsx +13 -2
- package/src/components/TableInput/index.tsx +349 -115
- package/src/components/TableInput/shared.ts +51 -0
- package/src/components/TableInput/tableInput.fit.spec.tsx +157 -0
- package/src/components/TableInput/tableInput.phoneIndex.spec.tsx +61 -0
- package/types/components/ChildTable/index.d.ts +2 -0
- package/types/components/ChildTable/index.d.ts.map +1 -1
- package/types/components/DataTableCell/index.d.ts.map +1 -1
- package/types/components/TableInput/ChildRowList.d.ts +38 -0
- package/types/components/TableInput/ChildRowList.d.ts.map +1 -0
- package/types/components/TableInput/RowDetailEditor.d.ts +3 -1
- package/types/components/TableInput/RowDetailEditor.d.ts.map +1 -1
- package/types/components/TableInput/index.d.ts +8 -1
- package/types/components/TableInput/index.d.ts.map +1 -1
- package/types/components/TableInput/index.native.d.ts.map +1 -1
- package/types/components/TableInput/shared.d.ts +22 -0
- package/types/components/TableInput/shared.d.ts.map +1 -1
|
@@ -26,13 +26,17 @@ var shared_exports = {};
|
|
|
26
26
|
__export(shared_exports, {
|
|
27
27
|
SKELETON_ROW_COUNT: () => SKELETON_ROW_COUNT,
|
|
28
28
|
changedColumns: () => changedColumns,
|
|
29
|
+
childColumnJustify: () => childColumnJustify,
|
|
29
30
|
childRowAttrs: () => childRowAttrs,
|
|
31
|
+
childScrollEdges: () => childScrollEdges,
|
|
30
32
|
childTableKeyAction: () => childTableKeyAction,
|
|
31
33
|
columnKey: () => columnKey,
|
|
34
|
+
fitChildColumns: () => fitChildColumns,
|
|
32
35
|
generateRowId: () => generateRowId,
|
|
33
36
|
isEmptyRows: () => isEmptyRows
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(shared_exports);
|
|
39
|
+
var import_columnAlign = require("../../utils/columnAlign.native.js");
|
|
36
40
|
var rowIdCounter = 0;
|
|
37
41
|
function generateRowId() {
|
|
38
42
|
rowIdCounter += 1;
|
|
@@ -78,9 +82,53 @@ function childTableKeyAction(e, ctx) {
|
|
|
78
82
|
function columnKey(col) {
|
|
79
83
|
return typeof col.accessorKey === "string" ? col.accessorKey : col.id || String(col.accessorKey);
|
|
80
84
|
}
|
|
85
|
+
function childColumnJustify(col) {
|
|
86
|
+
var _col_field;
|
|
87
|
+
return (0, import_columnAlign.alignToFlex)((0, import_columnAlign.getDefaultColumnAlign)({
|
|
88
|
+
id: columnKey(col),
|
|
89
|
+
align: col.align,
|
|
90
|
+
field: (_col_field = col.field) !== null && _col_field !== void 0 ? _col_field : "input",
|
|
91
|
+
fieldProps: col.fieldProps,
|
|
92
|
+
meta: col.meta
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
81
95
|
function changedColumns(before, after, columns) {
|
|
82
96
|
return columns.map(columnKey).filter(function (key) {
|
|
83
97
|
return !Object.is(before[key], after[key]);
|
|
84
98
|
});
|
|
85
99
|
}
|
|
100
|
+
function fitChildColumns(boxWidth, chromePx, chromeTotal, shares) {
|
|
101
|
+
var floors = shares.map(function (share) {
|
|
102
|
+
return (share + 1) * chromePx;
|
|
103
|
+
});
|
|
104
|
+
var floorTotal = floors.reduce(function (sum, floor) {
|
|
105
|
+
return sum + floor;
|
|
106
|
+
}, 0);
|
|
107
|
+
var shareTotal = shares.reduce(function (sum, share) {
|
|
108
|
+
return sum + share;
|
|
109
|
+
}, 0);
|
|
110
|
+
if (boxWidth <= 0 || shareTotal === 0) return {
|
|
111
|
+
scrolls: false,
|
|
112
|
+
widths: shares.map(function () {
|
|
113
|
+
return void 0;
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
if (chromeTotal + floorTotal > boxWidth) return {
|
|
117
|
+
scrolls: true,
|
|
118
|
+
widths: floors
|
|
119
|
+
};
|
|
120
|
+
var room = boxWidth - chromeTotal;
|
|
121
|
+
return {
|
|
122
|
+
scrolls: false,
|
|
123
|
+
widths: shares.map(function (share) {
|
|
124
|
+
return room * share / shareTotal;
|
|
125
|
+
})
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function childScrollEdges(scroller) {
|
|
129
|
+
return {
|
|
130
|
+
start: scroller.scrollLeft > 1,
|
|
131
|
+
end: scroller.scrollLeft + scroller.clientWidth < scroller.scrollWidth - 1
|
|
132
|
+
};
|
|
133
|
+
}
|
|
86
134
|
//# sourceMappingURL=shared.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","shared_exports","SKELETON_ROW_COUNT","changedColumns","childRowAttrs","childTableKeyAction","columnKey","generateRowId","isEmptyRows","module","exports","rowIdCounter","Date","now","isEmptyRows2","Array","isArray","length","row"],"sources":["../../../../src/components/TableInput/shared.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","shared_exports","SKELETON_ROW_COUNT","changedColumns","childColumnJustify","childRowAttrs","childScrollEdges","childTableKeyAction","columnKey","fitChildColumns","generateRowId","isEmptyRows","module","exports","import_columnAlign","require","rowIdCounter","Date","now","isEmptyRows2","Array","isArray","length","row","rowId","rowIndex","columnId","lastInput","field","active","STEPPER_FIELD","e","ctx","altKey","metaKey","ctrlKey","tagName","listboxOpen","shiftKey","inLastDataCell","rowCount","canAddRow","type","next"],"sources":["../../../../src/components/TableInput/shared.ts"],"sourcesContent":[null],"mappings":"AAGA,YAAS;;AAET,IAAIA,SAAA,GAAAC,MAAe,CAAAC,cAAA;AAOZ,IAAAC,gBAAS,GAAAF,MAAwB,CAAAG,wBAAA;AACt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C7BX,CAAA,CAAAnC,GAAK,cAAS,IAAAmC,CAAA,CAAanC,GAAA,gBAAS,SAAc,IAAS;EAC7D,KAAAoC,GAAA,CAAAN,QAAA;EACF,IAAAiB,IAAA,GAAAZ,CAAA,CAAAnC,GAAA,mBAAAoC,GAAA,CAAAP,QAAA,OAAAO,GAAA,CAAAP,QAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/table",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.6.0",
|
|
4
4
|
"description": "Advanced table components with filtering, pagination, sorting, and URL state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cross-platform",
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@multiplatform.one/components": "^9.
|
|
65
|
-
"@multiplatform.one/forms": "^9.
|
|
66
|
-
"@multiplatform.one/platform": "^9.
|
|
67
|
-
"@multiplatform.one/rich-text": "^9.
|
|
68
|
-
"@multiplatform.one/router": "^9.
|
|
69
|
-
"@multiplatform.one/table-primitives": "^9.
|
|
70
|
-
"@multiplatform.one/theme": "^9.
|
|
64
|
+
"@multiplatform.one/components": "^9.6.0",
|
|
65
|
+
"@multiplatform.one/forms": "^9.6.0",
|
|
66
|
+
"@multiplatform.one/platform": "^9.6.0",
|
|
67
|
+
"@multiplatform.one/rich-text": "^9.6.0",
|
|
68
|
+
"@multiplatform.one/router": "^9.6.0",
|
|
69
|
+
"@multiplatform.one/table-primitives": "^9.6.0",
|
|
70
|
+
"@multiplatform.one/theme": "^9.6.0",
|
|
71
71
|
"@phosphor-icons/react": "^2.1.10",
|
|
72
72
|
"@shopify/flash-list": "^2.3.1",
|
|
73
73
|
"@tamagui/roving-focus": "2.7.6",
|
|
@@ -77,10 +77,10 @@
|
|
|
77
77
|
"tamagui": "2.7.6"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@multiplatform.one/config": "9.
|
|
81
|
-
"@multiplatform.one/router": "9.
|
|
82
|
-
"@multiplatform.one/storybook": "9.
|
|
83
|
-
"@multiplatform.one/test-utils": "9.
|
|
80
|
+
"@multiplatform.one/config": "9.6.0",
|
|
81
|
+
"@multiplatform.one/router": "9.6.0",
|
|
82
|
+
"@multiplatform.one/storybook": "9.6.0",
|
|
83
|
+
"@multiplatform.one/test-utils": "9.6.0",
|
|
84
84
|
"@tamagui/build": "2.7.6",
|
|
85
85
|
"@testing-library/react": "^16.3.3",
|
|
86
86
|
"@types/react-dom": "^19.2.3",
|
|
@@ -251,3 +251,53 @@ const RowDetailStory = (args: Record<string, unknown>) => {
|
|
|
251
251
|
export const RowDetail: Story = {
|
|
252
252
|
render: (args) => <RowDetailStory {...args} />,
|
|
253
253
|
};
|
|
254
|
+
|
|
255
|
+
interface StatLine extends DataTableData {
|
|
256
|
+
id: string;
|
|
257
|
+
idx: number;
|
|
258
|
+
stat: string;
|
|
259
|
+
baseStat: number;
|
|
260
|
+
effort: number;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const statLines: StatLine[] = [
|
|
264
|
+
{ id: "stat-1", idx: 1, stat: "hp", baseStat: 45, effort: 1 },
|
|
265
|
+
{ id: "stat-2", idx: 2, stat: "attack", baseStat: 30, effort: 0 },
|
|
266
|
+
{ id: "stat-3", idx: 3, stat: "defense", baseStat: 35, effort: 0 },
|
|
267
|
+
{ id: "stat-4", idx: 4, stat: "speed", baseStat: 45, effort: 0 },
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
const statColumns: DataTableColumn<StatLine>[] = [
|
|
271
|
+
{ accessorKey: "stat", header: "Stat", field: "input" },
|
|
272
|
+
{ accessorKey: "baseStat", header: "Base stat", field: "stepper", fieldProps: { min: 0 } },
|
|
273
|
+
{ accessorKey: "effort", header: "Effort", field: "stepper", fieldProps: { min: 0 } },
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
const PhoneRowsStory = ({
|
|
277
|
+
phoneRows,
|
|
278
|
+
...args
|
|
279
|
+
}: Record<string, unknown> & { phoneRows: "inline" | "drill" }) => {
|
|
280
|
+
const [rows, setRows] = React.useState<StatLine[]>(statLines);
|
|
281
|
+
return (
|
|
282
|
+
<ChildTable<StatLine>
|
|
283
|
+
{...args}
|
|
284
|
+
label="Stats"
|
|
285
|
+
helperText={undefined}
|
|
286
|
+
value={rows}
|
|
287
|
+
columns={statColumns}
|
|
288
|
+
rowDetail
|
|
289
|
+
phoneRows={phoneRows}
|
|
290
|
+
onChange={setRows}
|
|
291
|
+
/>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export const PhoneInline: Story = {
|
|
296
|
+
name: "Phone Inline",
|
|
297
|
+
render: (args) => <PhoneRowsStory {...args} phoneRows="inline" />,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export const PhoneDrillIn: Story = {
|
|
301
|
+
name: "Phone Drill In",
|
|
302
|
+
render: (args) => <PhoneRowsStory {...args} phoneRows="drill" />,
|
|
303
|
+
};
|
|
@@ -44,6 +44,8 @@ export type ChildTableProps<TRow extends DataTableData = DataTableData> = {
|
|
|
44
44
|
detailColumns?: DataTableColumn<TRow>[];
|
|
45
45
|
/** Hides one row's cell, in the grid and in the detail editor (MPO-22). */
|
|
46
46
|
isCellHidden?: ChildCellHidden<TRow>;
|
|
47
|
+
/** How the rows read on a phone: `drill` (default) or `inline`; see TableInput (LC-298). */
|
|
48
|
+
phoneRows?: "inline" | "drill";
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
/**
|
|
@@ -99,6 +101,7 @@ export function ChildTable<TRow extends DataTableData = DataTableData>(
|
|
|
99
101
|
rowDetail,
|
|
100
102
|
detailColumns,
|
|
101
103
|
isCellHidden,
|
|
104
|
+
phoneRows,
|
|
102
105
|
} = useProps(props);
|
|
103
106
|
|
|
104
107
|
const { knobProps, id, resolvedForm } = useFormField({ form, id: idProp, size });
|
|
@@ -142,6 +145,7 @@ export function ChildTable<TRow extends DataTableData = DataTableData>(
|
|
|
142
145
|
rowDetail={rowDetail}
|
|
143
146
|
detailColumns={detailColumns}
|
|
144
147
|
isCellHidden={isCellHidden}
|
|
148
|
+
phoneRows={phoneRows}
|
|
145
149
|
/>
|
|
146
150
|
</Surface>
|
|
147
151
|
);
|
|
@@ -392,6 +392,9 @@ export function DataTableCell({
|
|
|
392
392
|
// the column header (same fallback chain as checkbox/select).
|
|
393
393
|
inputProps={{
|
|
394
394
|
"aria-label": (restProps as any)["aria-label"] ?? columnLabel ?? columnId,
|
|
395
|
+
// An input that fills a narrow column keeps its text on the
|
|
396
|
+
// column's edge, where the header ends (DG-TBL-01).
|
|
397
|
+
...(cellJustify === "flex-end" ? { textAlign: "right" as const } : null),
|
|
395
398
|
...(restProps as any).inputProps,
|
|
396
399
|
}}
|
|
397
400
|
/>
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChildRowList — a child table on a phone as an inset group of rows (the
|
|
3
|
+
* iOS Settings list, LC-298). Each row reads its first column as the title
|
|
4
|
+
* and its second as the one trailing value; a tap opens the whole row in a
|
|
5
|
+
* sheet, an inset grouped form with every detail column as a labelled row,
|
|
6
|
+
* and a bare trash glyph beside the sheet's ✓ deletes it. The last row adds
|
|
7
|
+
* one.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
ListGroup,
|
|
12
|
+
ListGroupItem,
|
|
13
|
+
ListRow,
|
|
14
|
+
ListRowMeta,
|
|
15
|
+
OverlayHeader,
|
|
16
|
+
SheetModal,
|
|
17
|
+
Text,
|
|
18
|
+
} from "@multiplatform.one/components";
|
|
19
|
+
import { TableCellContext } from "@multiplatform.one/table-primitives";
|
|
20
|
+
import {
|
|
21
|
+
getGroupPosition,
|
|
22
|
+
MIN_PRESS_TARGET,
|
|
23
|
+
useIdentityInkOnSurface,
|
|
24
|
+
useResolvedKnobs,
|
|
25
|
+
useTouchSurface,
|
|
26
|
+
type GroupPosition,
|
|
27
|
+
} from "@multiplatform.one/theme";
|
|
28
|
+
import { IconButton } from "@multiplatform.one/forms";
|
|
29
|
+
import { CaretRightIcon, PlusIcon, TrashIcon } from "@phosphor-icons/react";
|
|
30
|
+
import { FlashList } from "@shopify/flash-list";
|
|
31
|
+
import { useCallback, useRef, useState } from "react";
|
|
32
|
+
import { useTheme, View, XStack, YStack } from "tamagui";
|
|
33
|
+
import type {
|
|
34
|
+
DataTableColumn,
|
|
35
|
+
DataTableData,
|
|
36
|
+
DataTableField,
|
|
37
|
+
DataTableFieldProps,
|
|
38
|
+
} from "../../types";
|
|
39
|
+
import { withInterp } from "../../utils/withInterp";
|
|
40
|
+
import { DataTableCell } from "../DataTableCell";
|
|
41
|
+
import { changedColumns, columnKey, type ChildCellHidden } from "./shared";
|
|
42
|
+
|
|
43
|
+
export interface ChildRowListProps<TData extends DataTableData> {
|
|
44
|
+
rows: TData[];
|
|
45
|
+
columns: DataTableColumn<TData>[];
|
|
46
|
+
detailColumns: DataTableColumn<TData>[];
|
|
47
|
+
readOnly: boolean;
|
|
48
|
+
canAdd: boolean;
|
|
49
|
+
canDelete: boolean;
|
|
50
|
+
showAdd: boolean;
|
|
51
|
+
showDelete: boolean;
|
|
52
|
+
emptyMessage: string;
|
|
53
|
+
ariaLabel: string;
|
|
54
|
+
isCellHidden?: ChildCellHidden<TData>;
|
|
55
|
+
t: (key: string, options?: Record<string, unknown>) => string;
|
|
56
|
+
onAddRow: () => void;
|
|
57
|
+
onDeleteRow: (rowIndex: number) => void;
|
|
58
|
+
onCommitRow: (rowIndex: number, next: TData, changed: string[]) => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const shown = (value: unknown) => (value == null ? "" : String(value));
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* LC-201: a child table that reaches 50 rows windows them through FlashList.
|
|
65
|
+
* Below that the rows sit in the page's flow and the page owns the scroll;
|
|
66
|
+
* from there they scroll in a viewport ten rows tall, the cap the house
|
|
67
|
+
* `List` takes while it is long (§ List scroll owner). The add row stays
|
|
68
|
+
* under the viewport.
|
|
69
|
+
*/
|
|
70
|
+
export const childRowWindowFrom = 50;
|
|
71
|
+
export const childRowViewportRows = 10;
|
|
72
|
+
|
|
73
|
+
export function ChildRowList<TData extends DataTableData>({
|
|
74
|
+
rows,
|
|
75
|
+
columns,
|
|
76
|
+
detailColumns,
|
|
77
|
+
readOnly,
|
|
78
|
+
canAdd,
|
|
79
|
+
canDelete,
|
|
80
|
+
showAdd,
|
|
81
|
+
showDelete,
|
|
82
|
+
emptyMessage,
|
|
83
|
+
ariaLabel,
|
|
84
|
+
isCellHidden,
|
|
85
|
+
t,
|
|
86
|
+
onAddRow,
|
|
87
|
+
onDeleteRow,
|
|
88
|
+
onCommitRow,
|
|
89
|
+
}: ChildRowListProps<TData>) {
|
|
90
|
+
const { knobProps } = useResolvedKnobs();
|
|
91
|
+
const theme = useTheme();
|
|
92
|
+
const muted = theme.textMuted?.val ?? "currentColor";
|
|
93
|
+
const accent = useIdentityInkOnSurface();
|
|
94
|
+
const [openIndex, setOpenIndex] = useState<number | null>(null);
|
|
95
|
+
const [draft, setDraft] = useState<TData | null>(null);
|
|
96
|
+
const draftRef = useRef(draft);
|
|
97
|
+
draftRef.current = draft;
|
|
98
|
+
const rowLabel = (index: number) =>
|
|
99
|
+
withInterp(t("Row {{row}}", { row: index + 1 }), { row: index + 1 });
|
|
100
|
+
|
|
101
|
+
const open = useCallback(
|
|
102
|
+
(index: number) => {
|
|
103
|
+
const seeded = { ...rows[index] } as TData;
|
|
104
|
+
draftRef.current = seeded;
|
|
105
|
+
setDraft(seeded);
|
|
106
|
+
setOpenIndex(index);
|
|
107
|
+
},
|
|
108
|
+
[rows],
|
|
109
|
+
);
|
|
110
|
+
const close = useCallback(() => {
|
|
111
|
+
draftRef.current = null;
|
|
112
|
+
setDraft(null);
|
|
113
|
+
setOpenIndex(null);
|
|
114
|
+
}, []);
|
|
115
|
+
const confirm = useCallback(() => {
|
|
116
|
+
const active = draftRef.current;
|
|
117
|
+
if (openIndex != null && active && !readOnly) {
|
|
118
|
+
const changed = changedColumns(rows[openIndex] as TData, active, detailColumns);
|
|
119
|
+
if (changed.length > 0) onCommitRow(openIndex, active, changed);
|
|
120
|
+
}
|
|
121
|
+
close();
|
|
122
|
+
}, [openIndex, readOnly, rows, detailColumns, onCommitRow, close]);
|
|
123
|
+
|
|
124
|
+
const [titleColumn, valueColumn] = columns;
|
|
125
|
+
const current = openIndex == null ? null : (draft ?? rows[openIndex] ?? null);
|
|
126
|
+
const addShown = showAdd && !readOnly;
|
|
127
|
+
const windowed = rows.length >= childRowWindowFrom;
|
|
128
|
+
const touch = useTouchSurface();
|
|
129
|
+
const rowHeight = touch
|
|
130
|
+
? Math.max(MIN_PRESS_TARGET, knobProps.control.height)
|
|
131
|
+
: knobProps.control.height;
|
|
132
|
+
const positionOf = (index: number) => getGroupPosition(index, rows.length + (addShown ? 1 : 0));
|
|
133
|
+
|
|
134
|
+
const renderRow = (row: TData, index: number, groupPosition?: GroupPosition) => {
|
|
135
|
+
const title = titleColumn ? shown(row[columnKey(titleColumn) as keyof TData]) : "";
|
|
136
|
+
const value =
|
|
137
|
+
valueColumn && !isCellHidden?.(row, columnKey(valueColumn), index)
|
|
138
|
+
? shown(row[columnKey(valueColumn) as keyof TData])
|
|
139
|
+
: "";
|
|
140
|
+
return (
|
|
141
|
+
<ListGroupItem
|
|
142
|
+
key={String(row.id ?? index)}
|
|
143
|
+
groupPosition={groupPosition}
|
|
144
|
+
onPress={() => open(index)}
|
|
145
|
+
aria-label={title || rowLabel(index)}
|
|
146
|
+
>
|
|
147
|
+
<ListRow
|
|
148
|
+
title={title || <Text color="$color10">{rowLabel(index)}</Text>}
|
|
149
|
+
meta={
|
|
150
|
+
<XStack alignItems="center" {...knobProps.gap}>
|
|
151
|
+
{value === "" ? null : <ListRowMeta>{value}</ListRowMeta>}
|
|
152
|
+
<CaretRightIcon size={16} color={muted} weight="bold" />
|
|
153
|
+
</XStack>
|
|
154
|
+
}
|
|
155
|
+
/>
|
|
156
|
+
</ListGroupItem>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<YStack {...knobProps.gap}>
|
|
162
|
+
<ListGroup aria-label={ariaLabel}>
|
|
163
|
+
{rows.length === 0 ? (
|
|
164
|
+
<ListGroupItem key="empty">
|
|
165
|
+
<ListRow title={<Text color="$color10">{emptyMessage}</Text>} />
|
|
166
|
+
</ListGroupItem>
|
|
167
|
+
) : null}
|
|
168
|
+
{windowed ? (
|
|
169
|
+
<View
|
|
170
|
+
key="rows"
|
|
171
|
+
style={{ height: rowHeight * childRowViewportRows }}
|
|
172
|
+
{...({ "data-child-row-window": true } as Record<string, unknown>)}
|
|
173
|
+
>
|
|
174
|
+
<FlashList
|
|
175
|
+
keyboardShouldPersistTaps="handled"
|
|
176
|
+
data={rows}
|
|
177
|
+
extraData={{ columns, isCellHidden, muted, t }}
|
|
178
|
+
drawDistance={rowHeight * childRowViewportRows}
|
|
179
|
+
keyExtractor={(row, index) => String(row.id ?? index)}
|
|
180
|
+
renderItem={({ item, index }) => renderRow(item, index, positionOf(index))}
|
|
181
|
+
/>
|
|
182
|
+
</View>
|
|
183
|
+
) : (
|
|
184
|
+
rows.map((row, index) => renderRow(row, index))
|
|
185
|
+
)}
|
|
186
|
+
{addShown ? (
|
|
187
|
+
<ListGroupItem
|
|
188
|
+
key="add"
|
|
189
|
+
onPress={canAdd ? onAddRow : undefined}
|
|
190
|
+
aria-label={t("Add Row")}
|
|
191
|
+
opacity={canAdd ? 1 : 0.5}
|
|
192
|
+
>
|
|
193
|
+
<ListRow
|
|
194
|
+
icon={<PlusIcon color={accent} />}
|
|
195
|
+
title={
|
|
196
|
+
<Text {...knobProps.body} color={accent} numberOfLines={1}>
|
|
197
|
+
{t("Add Row")}
|
|
198
|
+
</Text>
|
|
199
|
+
}
|
|
200
|
+
/>
|
|
201
|
+
</ListGroupItem>
|
|
202
|
+
) : null}
|
|
203
|
+
</ListGroup>
|
|
204
|
+
<SheetModal
|
|
205
|
+
open={openIndex != null}
|
|
206
|
+
onOpenChange={(next) => {
|
|
207
|
+
if (!next) close();
|
|
208
|
+
}}
|
|
209
|
+
scrollable
|
|
210
|
+
header={
|
|
211
|
+
<OverlayHeader
|
|
212
|
+
title={
|
|
213
|
+
openIndex == null
|
|
214
|
+
? ""
|
|
215
|
+
: titleColumn
|
|
216
|
+
? shown(rows[openIndex]?.[columnKey(titleColumn) as keyof TData]) ||
|
|
217
|
+
rowLabel(openIndex)
|
|
218
|
+
: rowLabel(openIndex)
|
|
219
|
+
}
|
|
220
|
+
closeKind={readOnly ? "close" : "cancel"}
|
|
221
|
+
onClose={close}
|
|
222
|
+
{...(readOnly ? null : { onConfirm: confirm, confirmKind: "done" as const })}
|
|
223
|
+
actions={
|
|
224
|
+
showDelete && !readOnly && openIndex != null ? (
|
|
225
|
+
<IconButton
|
|
226
|
+
icon={TrashIcon}
|
|
227
|
+
aria-label={t("Delete")}
|
|
228
|
+
disabled={!canDelete}
|
|
229
|
+
onPress={() => {
|
|
230
|
+
const index = openIndex;
|
|
231
|
+
close();
|
|
232
|
+
onDeleteRow(index);
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
235
|
+
) : undefined
|
|
236
|
+
}
|
|
237
|
+
/>
|
|
238
|
+
}
|
|
239
|
+
>
|
|
240
|
+
{current && openIndex != null ? (
|
|
241
|
+
<YStack {...knobProps.gapLg}>
|
|
242
|
+
<TableCellContext.Provider value={{ inTableCell: true }}>
|
|
243
|
+
<ListGroup aria-label={rowLabel(openIndex)}>
|
|
244
|
+
{detailColumns
|
|
245
|
+
.filter((col) => !isCellHidden?.(current, columnKey(col), openIndex))
|
|
246
|
+
.map((col) => {
|
|
247
|
+
const columnId = columnKey(col);
|
|
248
|
+
const label = typeof col.header === "string" ? col.header : columnId;
|
|
249
|
+
return (
|
|
250
|
+
<ListGroupItem key={columnId} paddingVertical={0}>
|
|
251
|
+
<XStack alignItems="center" width="100%" minWidth={0} {...knobProps.gap}>
|
|
252
|
+
<Text
|
|
253
|
+
{...knobProps.textRole.label}
|
|
254
|
+
width="35%"
|
|
255
|
+
flexShrink={0}
|
|
256
|
+
numberOfLines={1}
|
|
257
|
+
>
|
|
258
|
+
{label}
|
|
259
|
+
</Text>
|
|
260
|
+
<YStack flex={1} minWidth={0}>
|
|
261
|
+
<DataTableCell
|
|
262
|
+
value={current[columnId as keyof TData]}
|
|
263
|
+
onChange={(value) => {
|
|
264
|
+
const base = draftRef.current;
|
|
265
|
+
if (!base) return;
|
|
266
|
+
const next = { ...base, [columnId]: value } as TData;
|
|
267
|
+
draftRef.current = next;
|
|
268
|
+
setDraft(next);
|
|
269
|
+
}}
|
|
270
|
+
field={(col.field || "input") as DataTableField}
|
|
271
|
+
fieldProps={col.fieldProps as DataTableFieldProps | undefined}
|
|
272
|
+
readOnly={readOnly}
|
|
273
|
+
columnId={columnId}
|
|
274
|
+
columnLabel={label}
|
|
275
|
+
rowIndex={openIndex}
|
|
276
|
+
rowData={current}
|
|
277
|
+
/>
|
|
278
|
+
</YStack>
|
|
279
|
+
</XStack>
|
|
280
|
+
</ListGroupItem>
|
|
281
|
+
);
|
|
282
|
+
})}
|
|
283
|
+
</ListGroup>
|
|
284
|
+
</TableCellContext.Provider>
|
|
285
|
+
</YStack>
|
|
286
|
+
) : null}
|
|
287
|
+
</SheetModal>
|
|
288
|
+
</YStack>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
@@ -25,7 +25,7 @@ import { TableCellContext } from "@multiplatform.one/table-primitives";
|
|
|
25
25
|
import { useResolvedKnobs } from "@multiplatform.one/theme";
|
|
26
26
|
import { PencilSimpleIcon } from "@phosphor-icons/react";
|
|
27
27
|
import { useCallback, useRef, useState } from "react";
|
|
28
|
-
import { Dialog, XStack, YStack } from "tamagui";
|
|
28
|
+
import { Dialog, XStack, YStack, useTheme } from "tamagui";
|
|
29
29
|
import type {
|
|
30
30
|
DataTableColumn,
|
|
31
31
|
DataTableData,
|
|
@@ -45,6 +45,8 @@ export interface RowDetailEditorProps<TData extends DataTableData> {
|
|
|
45
45
|
isCellHidden?: ChildCellHidden<TData>;
|
|
46
46
|
/** Receives the edited row once per session, only when a value changed. */
|
|
47
47
|
onCommit: (row: TData, changed: string[]) => void;
|
|
48
|
+
/** The pencil as an icon button's row-sized glyph (LC-176), not a 16pt one. */
|
|
49
|
+
glyphTrigger?: boolean;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export function RowDetailEditor<TData extends DataTableData>({
|
|
@@ -54,8 +56,10 @@ export function RowDetailEditor<TData extends DataTableData>({
|
|
|
54
56
|
readOnly,
|
|
55
57
|
isCellHidden,
|
|
56
58
|
onCommit,
|
|
59
|
+
glyphTrigger = false,
|
|
57
60
|
}: RowDetailEditorProps<TData>) {
|
|
58
61
|
const { knobProps } = useResolvedKnobs();
|
|
62
|
+
const theme = useTheme();
|
|
59
63
|
const [draft, setDraft] = useState<TData | null>(null);
|
|
60
64
|
const draftRef = useRef(draft);
|
|
61
65
|
draftRef.current = draft;
|
|
@@ -109,9 +113,16 @@ export function RowDetailEditor<TData extends DataTableData>({
|
|
|
109
113
|
return (
|
|
110
114
|
<Dialog open={draft !== null} onOpenChange={handleOpenChange} modal>
|
|
111
115
|
<Dialog.Trigger asChild>
|
|
112
|
-
|
|
113
|
-
<
|
|
114
|
-
|
|
116
|
+
{glyphTrigger ? (
|
|
117
|
+
<Button
|
|
118
|
+
icon={<PencilSimpleIcon color={theme.textMuted?.val} weight="regular" />}
|
|
119
|
+
aria-label={triggerLabel}
|
|
120
|
+
/>
|
|
121
|
+
) : (
|
|
122
|
+
<Button chromeless hitSlop={knobProps.nestedControl.hitSlop} aria-label={triggerLabel}>
|
|
123
|
+
<PencilSimpleIcon size={16} style={{ flexShrink: 0 }} />
|
|
124
|
+
</Button>
|
|
125
|
+
)}
|
|
115
126
|
</Dialog.Trigger>
|
|
116
127
|
<Dialog.Portal>
|
|
117
128
|
<DialogOverlay />
|