@dxos/react-ui-table 0.6.12-main.7907542 → 0.6.12-main.ac23639

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 (36) hide show
  1. package/dist/lib/browser/index.mjs +12 -85
  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/ColumnMenu.d.ts +6 -3
  5. package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts.map +1 -1
  6. package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts +3 -3
  7. package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -1
  8. package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts +6 -3
  9. package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts.map +1 -1
  10. package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts +7 -6
  11. package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -1
  12. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  13. package/dist/types/src/schema/index.d.ts +0 -2
  14. package/dist/types/src/schema/index.d.ts.map +1 -1
  15. package/dist/types/src/schema/types.d.ts +4 -4
  16. package/dist/types/src/schema/types.d.ts.map +1 -1
  17. package/package.json +18 -19
  18. package/src/components/ColumnMenu/ColumnMenu.stories.tsx +7 -6
  19. package/src/components/ColumnMenu/ColumnMenu.tsx +6 -3
  20. package/src/components/ColumnMenu/ColumnSettings.stories.tsx +9 -8
  21. package/src/components/ColumnMenu/ColumnSettings.tsx +9 -5
  22. package/src/components/Table/Table.tsx +5 -6
  23. package/src/components/Table/props.ts +4 -4
  24. package/src/schema/column-utils.ts +7 -7
  25. package/src/schema/index.ts +0 -2
  26. package/src/schema/types.ts +7 -7
  27. package/src/translations.ts +1 -1
  28. package/dist/types/src/components/Form/Form.stories.d.ts +0 -42
  29. package/dist/types/src/components/Form/Form.stories.d.ts.map +0 -1
  30. package/dist/types/src/schema/schema.d.ts +0 -4
  31. package/dist/types/src/schema/schema.d.ts.map +0 -1
  32. package/dist/types/src/schema/schema.test.d.ts +0 -2
  33. package/dist/types/src/schema/schema.test.d.ts.map +0 -1
  34. package/src/components/Form/Form.stories.tsx +0 -69
  35. package/src/schema/schema.test.ts +0 -76
  36. package/src/schema/schema.ts +0 -86
@@ -6,7 +6,7 @@ var translations_default = [
6
6
  [translationKey]: {
7
7
  "no selection label": "\xA0",
8
8
  "number column type label": "Number",
9
- "boolean column type label": "Toggle",
9
+ "boolean column type label": "Boolean",
10
10
  "date column type label": "Date",
11
11
  "string column type label": "Text",
12
12
  "ref column type label": "Reference",
@@ -99,6 +99,7 @@ import { getSize as getSize2, mx as mx2 } from "@dxos/react-ui-theme";
99
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
+ import { FieldValueTypes } from "@dxos/schema";
102
103
  import { safeParseInt } from "@dxos/util";
103
104
  var ColumnSettings = ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose }) => {
104
105
  const [formState, setFormState] = useState2({
@@ -169,12 +170,7 @@ var ColumnSettings = ({ column, tableDef, tablesToReference, onUpdate, onDelete,
169
170
  }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
170
171
  classNames: "is-full",
171
172
  placeholder: "Type"
172
- }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, [
173
- "number",
174
- "boolean",
175
- "string",
176
- "ref"
177
- ].map((type) => /* @__PURE__ */ React2.createElement(Select.Option, {
173
+ }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, FieldValueTypes.map((type) => /* @__PURE__ */ React2.createElement(Select.Option, {
178
174
  key: type,
179
175
  value: type
180
176
  }, 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, {
@@ -532,7 +528,7 @@ var SortIndicator = ({ direction, onClick }) => {
532
528
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
533
529
  import { Slot } from "@radix-ui/react-slot";
534
530
  import { getCoreRowModel, getExpandedRowModel, getGroupedRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
535
- import React8, { Fragment, useCallback as useCallback7, useEffect as useEffect3, useState as useState8, useContext as useContext3, memo } from "react";
531
+ import React8, { Fragment, memo, useCallback as useCallback7, useEffect as useEffect3, useState as useState8, useContext as useContext3 } from "react";
536
532
  import { DensityProvider, useDefaultValue } from "@dxos/react-ui";
537
533
  import { mx as mx4 } from "@dxos/react-ui-theme";
538
534
 
@@ -783,7 +779,7 @@ var TableViewport = ({ children, classNames, asChild, ...props }) => {
783
779
  }, children);
784
780
  };
785
781
  var TablePrimitive = (props) => {
786
- const { role, onColumnResize, columnVisibility, header = true, rowsSelectable, debug, onDataSelectionChange, pinLastRow } = props;
782
+ const { role, header = true, rowsSelectable, debug, pinLastRow, columnVisibility, onColumnResize, onDataSelectionChange } = props;
787
783
  const columns = useDefaultValue(props.columns, () => []);
788
784
  const incomingData = useDefaultValue(props.data, () => []);
789
785
  const [data, setData] = useState8([
@@ -1395,108 +1391,40 @@ var ColumnBuilder = class {
1395
1391
  }
1396
1392
  };
1397
1393
 
1398
- // packages/ui/react-ui-table/src/schema/schema.ts
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) => {
1404
- const propName = prop.name.toString();
1405
- if (prop.isOptional) {
1406
- const unwrappedAst = unwrapOptionProperty(prop);
1407
- if (isStruct(unwrappedAst)) {
1408
- return visitNode(unwrappedAst, [
1409
- ...path,
1410
- propName
1411
- ], acc);
1412
- }
1413
- }
1414
- if (isStruct(prop.type)) {
1415
- visitNode(prop.type, [
1416
- ...path,
1417
- propName
1418
- ], acc);
1419
- } else {
1420
- acc.push([
1421
- path.concat(propName).join("."),
1422
- propertyToColumn(prop)
1423
- ]);
1424
- }
1425
- });
1426
- return acc;
1427
- };
1428
- return visitNode(schema.ast);
1429
- };
1430
- var isStruct = (node) => AST.isTypeLiteral(node);
1431
- var propertyToColumn = (prop) => {
1432
- let type = prop.type;
1433
- if (prop.isOptional) {
1434
- type = unwrapOptionProperty(prop);
1435
- }
1436
- return typeToColumn(type);
1437
- };
1438
- var unwrapOptionProperty = (prop) => {
1439
- if (!AST.isUnion(prop.type)) {
1440
- throw new Error(`Not a union type: ${String(prop.name)}`);
1441
- }
1442
- const [type] = prop.type.types;
1443
- return type;
1444
- };
1445
- var typeToColumn = (type) => {
1446
- if (AST.isStringKeyword(type)) {
1447
- return "string";
1448
- } else if (AST.isNumberKeyword(type)) {
1449
- return "number";
1450
- } else if (AST.isBooleanKeyword(type)) {
1451
- return "boolean";
1452
- }
1453
- if (AST.isRefinement(type)) {
1454
- return typeToColumn(type.from);
1455
- }
1456
- if (AST.isTransformation(type)) {
1457
- const identifier = AST.getIdentifierAnnotation(type);
1458
- if (identifier._tag === "Some") {
1459
- if (identifier.value === "DateFromString") {
1460
- return "date";
1461
- }
1462
- }
1463
- }
1464
- return "json";
1465
- };
1466
-
1467
1394
  // packages/ui/react-ui-table/src/schema/column-utils.ts
1395
+ import { FieldValueType, mapSchemaToFields } from "@dxos/schema";
1468
1396
  var schemaToColumnDefs = (schema) => {
1469
1397
  const { helper, builder } = createColumnBuilder();
1470
- const classified = getColumnTypes(schema);
1398
+ const classified = mapSchemaToFields(schema);
1471
1399
  return classified.map(([name, type]) => {
1472
1400
  const propertyKey = name.toString();
1473
1401
  let column;
1474
1402
  switch (type) {
1475
- case "string": {
1403
+ case FieldValueType.String: {
1476
1404
  column = builder.string({
1477
1405
  label: propertyKey
1478
1406
  });
1479
1407
  break;
1480
1408
  }
1481
- case "number": {
1409
+ case FieldValueType.Number: {
1482
1410
  column = builder.number({
1483
1411
  label: propertyKey
1484
1412
  });
1485
1413
  break;
1486
1414
  }
1487
- case "boolean": {
1415
+ case FieldValueType.Boolean: {
1488
1416
  column = builder.switch({
1489
1417
  label: propertyKey
1490
1418
  });
1491
1419
  break;
1492
1420
  }
1493
- case "date": {
1421
+ case FieldValueType.Date: {
1494
1422
  column = builder.date({
1495
1423
  label: propertyKey
1496
1424
  });
1497
1425
  break;
1498
1426
  }
1499
- case "json": {
1427
+ case FieldValueType.JSON: {
1500
1428
  column = builder.json({
1501
1429
  label: propertyKey,
1502
1430
  id: propertyKey
@@ -1525,7 +1453,6 @@ export {
1525
1453
  createColumnBuilder,
1526
1454
  currentRow,
1527
1455
  flushPadding,
1528
- getColumnTypes,
1529
1456
  gridCellFocusRing,
1530
1457
  groupTh,
1531
1458
  headPadding,