@dxos/react-ui-table 0.6.11 → 0.6.12-main.568932b

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 (55) hide show
  1. package/dist/lib/browser/index.mjs +49 -60
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts +12 -0
  5. package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts.map +1 -0
  6. package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts +83 -0
  7. package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -0
  8. package/dist/types/src/components/ColumnMenu/index.d.ts +1 -1
  9. package/dist/types/src/components/ColumnMenu/index.d.ts.map +1 -1
  10. package/dist/types/src/components/Form/Form.stories.d.ts +42 -0
  11. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/Table/TableContext.d.ts +2 -4
  13. package/dist/types/src/components/Table/TableContext.d.ts.map +1 -1
  14. package/dist/types/src/components/Table/TableHead.d.ts.map +1 -1
  15. package/dist/types/src/components/Table/index.d.ts +2 -1
  16. package/dist/types/src/components/Table/index.d.ts.map +1 -1
  17. package/dist/types/src/helpers.d.ts +1 -1
  18. package/dist/types/src/helpers.d.ts.map +1 -1
  19. package/dist/types/src/hooks/useRowSelection.d.ts.map +1 -1
  20. package/dist/types/src/schema/{SchemaToTable.stories.d.ts → Schema.stories.d.ts} +2 -3
  21. package/dist/types/src/schema/Schema.stories.d.ts.map +1 -0
  22. package/dist/types/src/schema/{schemaToColumns.d.ts → column-utils.d.ts} +2 -2
  23. package/dist/types/src/schema/column-utils.d.ts.map +1 -0
  24. package/dist/types/src/schema/index.d.ts +3 -1
  25. package/dist/types/src/schema/index.d.ts.map +1 -1
  26. package/dist/types/src/schema/schema.d.ts +2 -3
  27. package/dist/types/src/schema/schema.d.ts.map +1 -1
  28. package/dist/types/src/schema/types.d.ts +1 -1
  29. package/dist/types/src/schema/types.d.ts.map +1 -1
  30. package/package.json +22 -20
  31. package/src/components/ColumnMenu/ColumnMenu.stories.tsx +9 -9
  32. package/src/components/ColumnMenu/ColumnMenu.tsx +2 -2
  33. package/src/components/ColumnMenu/{ColumnSettingsForm.stories.tsx → ColumnSettings.stories.tsx} +18 -15
  34. package/src/components/ColumnMenu/{ColumnSettingsForm.tsx → ColumnSettings.tsx} +34 -36
  35. package/src/components/ColumnMenu/index.ts +1 -1
  36. package/src/components/Form/Form.stories.tsx +69 -0
  37. package/src/components/Table/Table.stories.tsx +2 -2
  38. package/src/components/Table/Table.tsx +3 -3
  39. package/src/components/Table/TableContext.tsx +13 -7
  40. package/src/components/Table/TableHead.tsx +0 -1
  41. package/src/components/Table/index.ts +2 -1
  42. package/src/helpers.tsx +4 -6
  43. package/src/hooks/useRowSelection.ts +1 -0
  44. package/src/schema/{SchemaToTable.stories.tsx → Schema.stories.tsx} +6 -15
  45. package/src/schema/{schemaToColumns.ts → column-utils.ts} +5 -5
  46. package/src/schema/index.ts +3 -1
  47. package/src/schema/schema.test.ts +21 -93
  48. package/src/schema/schema.ts +23 -30
  49. package/src/schema/types.ts +4 -2
  50. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts +0 -12
  51. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +0 -1
  52. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts +0 -63
  53. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts.map +0 -1
  54. package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +0 -1
  55. package/dist/types/src/schema/schemaToColumns.d.ts.map +0 -1
@@ -96,11 +96,11 @@ import React4, { useRef as useRef2, useState as useState6, useCallback as useCal
96
96
  import { Button as Button2, Popover as Popover2, DropdownMenu } from "@dxos/react-ui";
97
97
  import { getSize as getSize2, mx as mx2 } from "@dxos/react-ui-theme";
98
98
 
99
- // packages/ui/react-ui-table/src/components/ColumnMenu/ColumnSettingsForm.tsx
99
+ // packages/ui/react-ui-table/src/components/ColumnMenu/ColumnSettings.tsx
100
100
  import React2, { useRef, useState as useState2 } from "react";
101
101
  import { Button, Input, Select, useTranslation as useTranslation2 } from "@dxos/react-ui";
102
102
  import { safeParseInt } from "@dxos/util";
103
- var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose }) => {
103
+ var ColumnSettings = ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose }) => {
104
104
  const [formState, setFormState] = useState2({
105
105
  prop: column.id,
106
106
  refTable: column.refTable,
@@ -140,9 +140,9 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
140
140
  onClose?.();
141
141
  };
142
142
  return /* @__PURE__ */ React2.createElement("div", {
143
- className: "p-1 space-y-2"
143
+ className: "flex flex-col w-full gap-4"
144
144
  }, /* @__PURE__ */ React2.createElement("div", {
145
- className: "space-y-1"
145
+ className: "flex flex-col gap-2"
146
146
  }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column label label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
147
147
  placeholder: "Column label",
148
148
  value: formState.label ?? "",
@@ -152,9 +152,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
152
152
  })),
153
153
  autoFocus: true,
154
154
  "data-testid": "table.column-settings.label"
155
- }))), /* @__PURE__ */ React2.createElement("div", {
156
- className: "space-y-1"
157
- }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("property key label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
155
+ })), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("property key label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
158
156
  ref: propRef,
159
157
  placeholder: "Property key",
160
158
  value: formState.prop ?? "",
@@ -162,9 +160,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
162
160
  ...prevState,
163
161
  prop: event.target.value.replace(/[^\w_]/g, "")
164
162
  }))
165
- }))), /* @__PURE__ */ React2.createElement("div", {
166
- className: "space-y-1"
167
- }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column type label")), /* @__PURE__ */ React2.createElement(Select.Root, {
163
+ })), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column type label")), /* @__PURE__ */ React2.createElement(Select.Root, {
168
164
  value: formState.type,
169
165
  onValueChange: (value) => setFormState((prevState) => ({
170
166
  ...prevState,
@@ -181,17 +177,13 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
181
177
  ].map((type) => /* @__PURE__ */ React2.createElement(Select.Option, {
182
178
  key: type,
183
179
  value: type
184
- }, t(`${type} column type label`))))))))), formState.type === "number" && /* @__PURE__ */ React2.createElement("div", {
185
- className: "space-y-1"
186
- }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("digits label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
180
+ }, t(`${type} column type label`)))))))), formState.type === "number" && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("digits label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
187
181
  value: formState.digits ?? "",
188
182
  onChange: (event) => setFormState((prevState) => ({
189
183
  ...prevState,
190
184
  digits: event.target.value
191
185
  }))
192
- }))), formState.type === "ref" && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", {
193
- className: "space-y-1"
194
- }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table"), /* @__PURE__ */ React2.createElement(Select.Root, {
186
+ })), formState.type === "ref" && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table"), /* @__PURE__ */ React2.createElement(Select.Root, {
195
187
  value: formState.refTable,
196
188
  onValueChange: (value) => setFormState((prevState) => ({
197
189
  ...prevState,
@@ -203,9 +195,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
203
195
  }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tablesToReference.filter((t2) => t2.id !== tableDef.id).map(({ id, name }) => /* @__PURE__ */ React2.createElement(Select.Option, {
204
196
  key: id,
205
197
  value: id
206
- }, name ?? id)))))))), formState.refTable && /* @__PURE__ */ React2.createElement("div", {
207
- className: "space-y-1"
208
- }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table property"), /* @__PURE__ */ React2.createElement(Select.Root, {
198
+ }, name ?? id))))))), formState.refTable && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table property"), /* @__PURE__ */ React2.createElement(Select.Root, {
209
199
  value: formState.refProp,
210
200
  onValueChange: (value) => setFormState((prevState) => ({
211
201
  ...prevState,
@@ -216,10 +206,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
216
206
  }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tablesToReference.find((tableDef2) => tableDef2.id === formState.refTable)?.columns.map(({ id, label }) => /* @__PURE__ */ React2.createElement(Select.Option, {
217
207
  key: id,
218
208
  value: id
219
- }, label ?? id))))))))), /* @__PURE__ */ React2.createElement("div", {
220
- role: "none",
221
- className: "h-1"
222
- }), /* @__PURE__ */ React2.createElement("div", {
209
+ }, label ?? id))))))))), /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement("div", {
223
210
  className: "flex flex-row justify-end gap-1"
224
211
  }, /* @__PURE__ */ React2.createElement(Button, {
225
212
  onClick: handleDelete,
@@ -228,7 +215,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
228
215
  variant: "primary",
229
216
  onClick: handleSave,
230
217
  "data-testid": "table.column-settings.save"
231
- }, t("save label"))));
218
+ }, t("save label")))));
232
219
  };
233
220
 
234
221
  // packages/ui/react-ui-table/src/hooks/useColumnSizing.ts
@@ -269,14 +256,16 @@ import { useState as useState4 } from "react";
269
256
 
270
257
  // packages/ui/react-ui-table/src/components/Table/TableContext.tsx
271
258
  import React3, { useContext, createContext } from "react";
272
- var TableContext = /* @__PURE__ */ createContext({});
259
+ import { raise } from "@dxos/debug";
260
+ var TABLE_NAME = "Table";
261
+ var TableContext = /* @__PURE__ */ createContext(void 0);
273
262
  var TableProvider = ({ children, ...value }) => {
274
263
  return /* @__PURE__ */ React3.createElement(TableContext.Provider, {
275
264
  value
276
265
  }, children);
277
266
  };
278
267
  var useTableContext = () => {
279
- return useContext(TableContext);
268
+ return useContext(TableContext) ?? raise(new Error("Missing TableContext"));
280
269
  };
281
270
 
282
271
  // packages/ui/react-ui-table/src/hooks/useColumnSorting.ts
@@ -511,7 +500,7 @@ var ColumnMenu = ({ column, columnOrderable, columnPosition, onColumnReorder, ..
511
500
  className: "opacity-50"
512
501
  }, /* @__PURE__ */ React4.createElement(GearSix, {
513
502
  className: mx2(getSize2(4), "rotate-90")
514
- })))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))), /* @__PURE__ */ React4.createElement(Popover2.Portal, null, /* @__PURE__ */ React4.createElement(Popover2.Content, null, /* @__PURE__ */ React4.createElement(Popover2.Viewport, null, /* @__PURE__ */ React4.createElement(ColumnSettingsForm, {
503
+ })))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))), /* @__PURE__ */ React4.createElement(Popover2.Portal, null, /* @__PURE__ */ React4.createElement(Popover2.Content, null, /* @__PURE__ */ React4.createElement(Popover2.Viewport, null, /* @__PURE__ */ React4.createElement(ColumnSettings, {
515
504
  ...props,
516
505
  column,
517
506
  onClose: () => setIsColumnSettingsOpen(false)
@@ -795,8 +784,8 @@ var TableViewport = ({ children, classNames, asChild, ...props }) => {
795
784
  };
796
785
  var TablePrimitive = (props) => {
797
786
  const { role, onColumnResize, columnVisibility, header = true, rowsSelectable, debug, onDataSelectionChange, pinLastRow } = props;
798
- const columns = useDefaultValue(props.columns, []);
799
- const incomingData = useDefaultValue(props.data, []);
787
+ const columns = useDefaultValue(props.columns, () => []);
788
+ const incomingData = useDefaultValue(props.data, () => []);
800
789
  const [data, setData] = useState8([
801
790
  ...incomingData
802
791
  ]);
@@ -828,7 +817,7 @@ var TablePrimitive = (props) => {
828
817
  // Columns
829
818
  columns,
830
819
  defaultColumn: {
831
- size: 256,
820
+ size: 400,
832
821
  maxSize: 1024
833
822
  },
834
823
  // State
@@ -1229,7 +1218,7 @@ var ColumnBuilder = class {
1229
1218
  value
1230
1219
  }, {
1231
1220
  F: __dxlog_file,
1232
- L: 378,
1221
+ L: 377,
1233
1222
  S: this,
1234
1223
  C: (f, a) => f(...a)
1235
1224
  });
@@ -1327,7 +1316,7 @@ var ColumnBuilder = class {
1327
1316
  size: 50,
1328
1317
  minSize: 50,
1329
1318
  header: (column) => label ?? column.header.id,
1330
- // TODO(zan): Implement sort algorithm
1319
+ // TODO(zan): Implement sort algorithm.
1331
1320
  enableSorting: true,
1332
1321
  cell: SwitchBuilderCell,
1333
1322
  ...props,
@@ -1352,7 +1341,7 @@ var ColumnBuilder = class {
1352
1341
  const IconOff = off?.Icon ?? X2;
1353
1342
  return {
1354
1343
  size: size ?? 32,
1355
- // TODO(zan): Implement sort algorithm
1344
+ // TODO(zan): Implement sort algorithm.
1356
1345
  enableSorting: false,
1357
1346
  header: (column) => /* @__PURE__ */ React9.createElement("div", {
1358
1347
  className: "justify-center"
@@ -1377,7 +1366,7 @@ var ColumnBuilder = class {
1377
1366
  /**
1378
1367
  * This display column type is for nested/unhandled data to appear as JSON.
1379
1368
  */
1380
- display({ label, classNames, ...props } = {}) {
1369
+ json({ label, classNames, ...props } = {}) {
1381
1370
  return {
1382
1371
  size: 120,
1383
1372
  minSize: 120,
@@ -1407,23 +1396,23 @@ var ColumnBuilder = class {
1407
1396
  };
1408
1397
 
1409
1398
  // packages/ui/react-ui-table/src/schema/schema.ts
1410
- import * as AST from "@effect/schema/AST";
1411
- var classifySchemaProperties = (schema) => {
1412
- const recurse = (node, path, acc) => {
1413
- const properties = AST.getPropertySignatures(node);
1414
- properties.forEach((prop) => {
1399
+ import { AST } from "@dxos/effect";
1400
+ var getColumnTypes = (schema) => {
1401
+ const visitNode = (node, path = [], acc = []) => {
1402
+ const props = AST.getPropertySignatures(node);
1403
+ props.forEach((prop) => {
1415
1404
  const propName = prop.name.toString();
1416
1405
  if (prop.isOptional) {
1417
1406
  const unwrappedAst = unwrapOptionProperty(prop);
1418
1407
  if (isStruct(unwrappedAst)) {
1419
- return recurse(unwrappedAst, [
1408
+ return visitNode(unwrappedAst, [
1420
1409
  ...path,
1421
1410
  propName
1422
1411
  ], acc);
1423
1412
  }
1424
1413
  }
1425
1414
  if (isStruct(prop.type)) {
1426
- recurse(prop.type, [
1415
+ visitNode(prop.type, [
1427
1416
  ...path,
1428
1417
  propName
1429
1418
  ], acc);
@@ -1436,18 +1425,21 @@ var classifySchemaProperties = (schema) => {
1436
1425
  });
1437
1426
  return acc;
1438
1427
  };
1439
- return recurse(schema.ast, [], []);
1428
+ return visitNode(schema.ast);
1440
1429
  };
1441
1430
  var isStruct = (node) => AST.isTypeLiteral(node);
1442
- var isOptionalUnion = (prop) => AST.isUnion(prop.type) && prop.isOptional;
1443
- var unwrapOptionProperty = (prop) => {
1444
- if (!isOptionalUnion(prop)) {
1445
- throw new Error(`Not an optional property: ${String(prop.name)}`);
1431
+ var propertyToColumn = (prop) => {
1432
+ let type = prop.type;
1433
+ if (prop.isOptional) {
1434
+ type = unwrapOptionProperty(prop);
1446
1435
  }
1436
+ return typeToColumn(type);
1437
+ };
1438
+ var unwrapOptionProperty = (prop) => {
1447
1439
  if (!AST.isUnion(prop.type)) {
1448
1440
  throw new Error(`Not a union type: ${String(prop.name)}`);
1449
1441
  }
1450
- const [type, _undefinedCase] = prop.type.types;
1442
+ const [type] = prop.type.types;
1451
1443
  return type;
1452
1444
  };
1453
1445
  var typeToColumn = (type) => {
@@ -1469,20 +1461,13 @@ var typeToColumn = (type) => {
1469
1461
  }
1470
1462
  }
1471
1463
  }
1472
- return "display";
1473
- };
1474
- var propertyToColumn = (prop) => {
1475
- let type = prop.type;
1476
- if (prop.isOptional) {
1477
- type = unwrapOptionProperty(prop);
1478
- }
1479
- return typeToColumn(type);
1464
+ return "json";
1480
1465
  };
1481
1466
 
1482
- // packages/ui/react-ui-table/src/schema/schemaToColumns.ts
1467
+ // packages/ui/react-ui-table/src/schema/column-utils.ts
1483
1468
  var schemaToColumnDefs = (schema) => {
1484
1469
  const { helper, builder } = createColumnBuilder();
1485
- const classified = classifySchemaProperties(schema);
1470
+ const classified = getColumnTypes(schema);
1486
1471
  return classified.map(([name, type]) => {
1487
1472
  const propertyKey = name.toString();
1488
1473
  let column;
@@ -1511,8 +1496,8 @@ var schemaToColumnDefs = (schema) => {
1511
1496
  });
1512
1497
  break;
1513
1498
  }
1514
- case "display": {
1515
- column = builder.display({
1499
+ case "json": {
1500
+ column = builder.json({
1516
1501
  label: propertyKey,
1517
1502
  id: propertyKey
1518
1503
  });
@@ -1529,15 +1514,18 @@ export {
1529
1514
  CellCombobox,
1530
1515
  ColumnBuilder,
1531
1516
  ColumnMenu,
1532
- ColumnSettingsForm,
1517
+ ColumnSettings,
1533
1518
  MemoizedVirtualizedTableContent,
1534
1519
  SortIndicator,
1520
+ TABLE_NAME,
1535
1521
  Table,
1536
1522
  TablePrimitive,
1523
+ TableProvider,
1537
1524
  TableRootContext,
1538
1525
  createColumnBuilder,
1539
1526
  currentRow,
1540
1527
  flushPadding,
1528
+ getColumnTypes,
1541
1529
  gridCellFocusRing,
1542
1530
  groupTh,
1543
1531
  headPadding,
@@ -1558,6 +1546,7 @@ export {
1558
1546
  usePinLastRow,
1559
1547
  useRowSelection,
1560
1548
  useSortColumn,
1549
+ useTableContext,
1561
1550
  useTableRootContext
1562
1551
  };
1563
1552
  //# sourceMappingURL=index.mjs.map