@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.
Files changed (84) hide show
  1. package/dist/cjs/components/ChildTable/index.cjs +4 -2
  2. package/dist/cjs/components/ChildTable/index.native.js +4 -2
  3. package/dist/cjs/components/ChildTable/index.native.js.map +1 -1
  4. package/dist/cjs/components/DataTableCell/index.cjs +5 -0
  5. package/dist/cjs/components/DataTableCell/index.native.js +5 -0
  6. package/dist/cjs/components/DataTableCell/index.native.js.map +1 -1
  7. package/dist/cjs/components/TableInput/ChildRowList.cjs +262 -0
  8. package/dist/cjs/components/TableInput/ChildRowList.native.js +287 -0
  9. package/dist/cjs/components/TableInput/ChildRowList.native.js.map +1 -0
  10. package/dist/cjs/components/TableInput/RowDetailEditor.cjs +14 -3
  11. package/dist/cjs/components/TableInput/index.cjs +200 -13
  12. package/dist/cjs/components/TableInput/index.native.js +1 -0
  13. package/dist/cjs/components/TableInput/index.native.js.map +1 -1
  14. package/dist/cjs/components/TableInput/shared.cjs +37 -0
  15. package/dist/cjs/components/TableInput/shared.native.js +48 -0
  16. package/dist/cjs/components/TableInput/shared.native.js.map +1 -1
  17. package/dist/esm/components/ChildTable/index.mjs +4 -2
  18. package/dist/esm/components/ChildTable/index.mjs.map +1 -1
  19. package/dist/esm/components/ChildTable/index.native.js +4 -2
  20. package/dist/esm/components/ChildTable/index.native.js.map +1 -1
  21. package/dist/esm/components/DataTableCell/index.mjs +5 -0
  22. package/dist/esm/components/DataTableCell/index.mjs.map +1 -1
  23. package/dist/esm/components/DataTableCell/index.native.js +5 -0
  24. package/dist/esm/components/DataTableCell/index.native.js.map +1 -1
  25. package/dist/esm/components/TableInput/ChildRowList.mjs +235 -0
  26. package/dist/esm/components/TableInput/ChildRowList.mjs.map +1 -0
  27. package/dist/esm/components/TableInput/ChildRowList.native.js +257 -0
  28. package/dist/esm/components/TableInput/ChildRowList.native.js.map +1 -0
  29. package/dist/esm/components/TableInput/RowDetailEditor.mjs +15 -4
  30. package/dist/esm/components/TableInput/RowDetailEditor.mjs.map +1 -1
  31. package/dist/esm/components/TableInput/index.mjs +204 -17
  32. package/dist/esm/components/TableInput/index.mjs.map +1 -1
  33. package/dist/esm/components/TableInput/index.native.js +2 -1
  34. package/dist/esm/components/TableInput/index.native.js.map +1 -1
  35. package/dist/esm/components/TableInput/shared.mjs +35 -1
  36. package/dist/esm/components/TableInput/shared.mjs.map +1 -1
  37. package/dist/esm/components/TableInput/shared.native.js +46 -1
  38. package/dist/esm/components/TableInput/shared.native.js.map +1 -1
  39. package/dist/jsx/components/ChildTable/index.mjs +4 -2
  40. package/dist/jsx/components/ChildTable/index.mjs.map +1 -1
  41. package/dist/jsx/components/ChildTable/index.native.js +4 -2
  42. package/dist/jsx/components/ChildTable/index.native.js.map +1 -1
  43. package/dist/jsx/components/DataTableCell/index.mjs +5 -0
  44. package/dist/jsx/components/DataTableCell/index.mjs.map +1 -1
  45. package/dist/jsx/components/DataTableCell/index.native.js +5 -0
  46. package/dist/jsx/components/DataTableCell/index.native.js.map +1 -1
  47. package/dist/jsx/components/TableInput/ChildRowList.mjs +235 -0
  48. package/dist/jsx/components/TableInput/ChildRowList.mjs.map +1 -0
  49. package/dist/jsx/components/TableInput/ChildRowList.native.js +287 -0
  50. package/dist/jsx/components/TableInput/ChildRowList.native.js.map +1 -0
  51. package/dist/jsx/components/TableInput/RowDetailEditor.mjs +15 -4
  52. package/dist/jsx/components/TableInput/RowDetailEditor.mjs.map +1 -1
  53. package/dist/jsx/components/TableInput/index.mjs +204 -17
  54. package/dist/jsx/components/TableInput/index.mjs.map +1 -1
  55. package/dist/jsx/components/TableInput/index.native.js +1 -0
  56. package/dist/jsx/components/TableInput/index.native.js.map +1 -1
  57. package/dist/jsx/components/TableInput/shared.mjs +35 -1
  58. package/dist/jsx/components/TableInput/shared.mjs.map +1 -1
  59. package/dist/jsx/components/TableInput/shared.native.js +48 -0
  60. package/dist/jsx/components/TableInput/shared.native.js.map +1 -1
  61. package/package.json +12 -12
  62. package/src/components/ChildTable/ChildTable.stories.tsx +50 -0
  63. package/src/components/ChildTable/index.tsx +4 -0
  64. package/src/components/DataTableCell/index.tsx +3 -0
  65. package/src/components/TableInput/ChildRowList.tsx +290 -0
  66. package/src/components/TableInput/RowDetailEditor.tsx +15 -4
  67. package/src/components/TableInput/childRowList.spec.tsx +141 -0
  68. package/src/components/TableInput/index.native.tsx +13 -2
  69. package/src/components/TableInput/index.tsx +349 -115
  70. package/src/components/TableInput/shared.ts +51 -0
  71. package/src/components/TableInput/tableInput.fit.spec.tsx +157 -0
  72. package/src/components/TableInput/tableInput.phoneIndex.spec.tsx +61 -0
  73. package/types/components/ChildTable/index.d.ts +2 -0
  74. package/types/components/ChildTable/index.d.ts.map +1 -1
  75. package/types/components/DataTableCell/index.d.ts.map +1 -1
  76. package/types/components/TableInput/ChildRowList.d.ts +38 -0
  77. package/types/components/TableInput/ChildRowList.d.ts.map +1 -0
  78. package/types/components/TableInput/RowDetailEditor.d.ts +3 -1
  79. package/types/components/TableInput/RowDetailEditor.d.ts.map +1 -1
  80. package/types/components/TableInput/index.d.ts +8 -1
  81. package/types/components/TableInput/index.d.ts.map +1 -1
  82. package/types/components/TableInput/index.native.d.ts.map +1 -1
  83. package/types/components/TableInput/shared.d.ts +22 -0
  84. package/types/components/TableInput/shared.d.ts.map +1 -1
@@ -0,0 +1,141 @@
1
+ /**
2
+ * LC-298: on a phone a child table drills in. The rows are a read-only inset
3
+ * group that shows the title and one value; a tap opens the row in a sheet
4
+ * whose fields sit in one inset group, with a trash glyph in its bar. `inline` keeps
5
+ * the grid of fields, and so does a wide screen.
6
+ */
7
+
8
+ import { fireEvent, renderWithProviders, screen } from "@multiplatform.one/test-utils";
9
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
10
+ import type { DataTableColumn, DataTableData } from "../../types";
11
+
12
+ const media = {
13
+ set phone(on: boolean) {
14
+ Object.defineProperty(window, "innerWidth", { configurable: true, value: on ? 390 : 1280 });
15
+ },
16
+ };
17
+
18
+ vi.mock("@multiplatform.one/router", async (importOriginal) => {
19
+ const actual = await importOriginal<Record<string, unknown>>();
20
+ return { ...actual, useUrlState: () => [{}, () => {}] };
21
+ });
22
+
23
+ const { TableInput } = await import("./index");
24
+ const { childRowViewportRows, childRowWindowFrom } = await import("./ChildRowList");
25
+
26
+ interface Row extends DataTableData {
27
+ id: string;
28
+ stat: string;
29
+ baseStat: number;
30
+ effort: number;
31
+ }
32
+
33
+ const rows: Row[] = [
34
+ { id: "a", stat: "hp", baseStat: 45, effort: 1 },
35
+ { id: "b", stat: "attack", baseStat: 30, effort: 0 },
36
+ ];
37
+ const columns: DataTableColumn<Row>[] = [
38
+ { accessorKey: "stat", header: "Stat", field: "input" },
39
+ { accessorKey: "baseStat", header: "Base Stat", field: "stepper" },
40
+ { accessorKey: "effort", header: "Effort", field: "stepper" },
41
+ ];
42
+
43
+ describe("ChildTable drills in on a phone (LC-298)", () => {
44
+ it("a phone lists read-only rows with the title and one value", () => {
45
+ media.phone = true;
46
+ const { container } = renderWithProviders(<TableInput<Row> data={rows} columns={columns} />);
47
+ expect(container.querySelector("table")).toBeNull();
48
+ expect(container.querySelector("input")).toBeNull();
49
+ const first = screen.getByRole("button", { name: "hp" });
50
+ expect(first.textContent).toContain("45");
51
+ expect(first.textContent).not.toContain("1");
52
+ expect(screen.getByRole("button", { name: "Add Row" })).toBeTruthy();
53
+ });
54
+
55
+ it("a tap opens the row as fields, and the bar's trash glyph deletes it", async () => {
56
+ media.phone = true;
57
+ const onChange = vi.fn();
58
+ renderWithProviders(<TableInput<Row> data={rows} columns={columns} onChange={onChange} />);
59
+ fireEvent.click(screen.getByRole("button", { name: "attack" }));
60
+ const trash = await screen.findByRole("button", { name: "Delete" });
61
+ expect(trash.textContent?.trim()).toBe("");
62
+ expect(screen.queryByTestId("danger-section")).toBeNull();
63
+ expect(screen.getAllByDisplayValue("attack").length).toBeGreaterThan(0);
64
+ fireEvent.click(trash);
65
+ expect(onChange).toHaveBeenCalledWith([rows[0]]);
66
+ });
67
+
68
+ it("inline opts out to the grid of fields", () => {
69
+ media.phone = true;
70
+ const { container } = renderWithProviders(
71
+ <TableInput<Row> data={rows} columns={columns} phoneRows="inline" />,
72
+ );
73
+ expect(container.querySelector("table")).not.toBeNull();
74
+ });
75
+
76
+ it("a wide screen keeps the grid of fields", () => {
77
+ media.phone = false;
78
+ const { container } = renderWithProviders(<TableInput<Row> data={rows} columns={columns} />);
79
+ expect(container.querySelector("table")).not.toBeNull();
80
+ expect(container.querySelector("input")).not.toBeNull();
81
+ });
82
+ });
83
+
84
+ describe("a long child table windows its rows on a phone (LC-201)", () => {
85
+ const many = (count: number): Row[] =>
86
+ Array.from({ length: count }, (_, i) => ({
87
+ id: `r${i}`,
88
+ stat: `stat ${i}`,
89
+ baseStat: i,
90
+ effort: 0,
91
+ }));
92
+ const mountedRows = () => screen.queryAllByRole("button", { name: /^stat \d+$/ });
93
+ // happy-dom lays nothing out, so every row would measure 0 tall and the
94
+ // whole list would fit FlashList's window. A phone's geometry: 390 wide,
95
+ // a box as tall as its style says, a row at the 44 floor.
96
+ beforeEach(() => {
97
+ vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(390);
98
+ vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockImplementation(
99
+ function (this: HTMLElement) {
100
+ return Number.parseFloat(this.style.height) || 44;
101
+ },
102
+ );
103
+ });
104
+ afterEach(() => {
105
+ vi.restoreAllMocks();
106
+ });
107
+
108
+ it("200 rows mount a window, not all 200, in a ten-row viewport over the add row", () => {
109
+ media.phone = true;
110
+ const { container } = renderWithProviders(
111
+ <TableInput<Row> data={many(200)} columns={columns} />,
112
+ );
113
+ const viewport = container.querySelector<HTMLElement>("[data-child-row-window]");
114
+ expect(viewport).not.toBeNull();
115
+ const height = Number.parseFloat(viewport?.style.height ?? "");
116
+ expect(height).toBeGreaterThan(0);
117
+ expect(height % childRowViewportRows).toBe(0);
118
+ expect(mountedRows().length).toBeGreaterThan(0);
119
+ expect(mountedRows().length).toBeLessThan(200);
120
+ expect(screen.queryByRole("button", { name: "stat 199" })).toBeNull();
121
+ expect(screen.getByRole("button", { name: "stat 0" })).toBeTruthy();
122
+ expect(screen.getByRole("button", { name: "Add Row" })).toBeTruthy();
123
+ });
124
+
125
+ it("a windowed row still opens its sheet", async () => {
126
+ media.phone = true;
127
+ renderWithProviders(<TableInput<Row> data={many(200)} columns={columns} />);
128
+ fireEvent.click(screen.getByRole("button", { name: "stat 1" }));
129
+ expect((await screen.findAllByDisplayValue("stat 1")).length).toBeGreaterThan(0);
130
+ });
131
+
132
+ it("below the line every row sits in the page's flow", () => {
133
+ media.phone = true;
134
+ const count = childRowWindowFrom - 1;
135
+ const { container } = renderWithProviders(
136
+ <TableInput<Row> data={many(count)} columns={columns} />,
137
+ );
138
+ expect(container.querySelector("[data-child-row-window]")).toBeNull();
139
+ expect(mountedRows()).toHaveLength(count);
140
+ });
141
+ });
@@ -38,7 +38,13 @@ import type {
38
38
  import { DataTableCell } from "../DataTableCell";
39
39
  import { withInterp } from "../../utils/withInterp";
40
40
  import { RowDetailEditor } from "./RowDetailEditor";
41
- import { generateRowId, isEmptyRows, SKELETON_ROW_COUNT, type ChildCellHidden } from "./shared";
41
+ import {
42
+ childColumnJustify,
43
+ generateRowId,
44
+ isEmptyRows,
45
+ SKELETON_ROW_COUNT,
46
+ type ChildCellHidden,
47
+ } from "./shared";
42
48
  import { Text } from "@multiplatform.one/components";
43
49
 
44
50
  export interface TableInputProps<TData extends DataTableData = DataTableData> {
@@ -294,7 +300,12 @@ function TableInputInner<TData extends DataTableData>({
294
300
  </View>
295
301
  )}
296
302
  {columns.map((col, index) => (
297
- <View key={columnIds[index]} flex={1} paddingHorizontal="$1">
303
+ <View
304
+ key={columnIds[index]}
305
+ flex={1}
306
+ paddingHorizontal="$1"
307
+ alignItems={childColumnJustify(col)}
308
+ >
298
309
  <Text color="$color12" fontSize={knobProps.label.fontSize}>
299
310
  {typeof col.header === "string" ? col.header : columnIds[index]}
300
311
  </Text>