@dxos/react-ui-table 0.6.13 → 0.6.14-main.7bd9c89
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/lib/browser/index.mjs +45 -131
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts +6 -3
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts.map +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts +3 -3
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts +15 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts +84 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/index.d.ts +1 -1
- package/dist/types/src/components/ColumnMenu/index.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +9 -27
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContext.d.ts +2 -4
- package/dist/types/src/components/Table/TableContext.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableHead.d.ts.map +1 -1
- package/dist/types/src/components/Table/index.d.ts +2 -1
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/hooks/useRowSelection.d.ts.map +1 -1
- package/dist/types/src/schema/{SchemaToTable.stories.d.ts → Schema.stories.d.ts} +2 -3
- package/dist/types/src/schema/Schema.stories.d.ts.map +1 -0
- package/dist/types/src/schema/{schemaToColumns.d.ts → column-utils.d.ts} +2 -2
- package/dist/types/src/schema/column-utils.d.ts.map +1 -0
- package/dist/types/src/schema/index.d.ts +1 -1
- package/dist/types/src/schema/index.d.ts.map +1 -1
- package/dist/types/src/schema/types.d.ts +10 -4
- package/dist/types/src/schema/types.d.ts.map +1 -1
- package/package.json +22 -20
- package/src/components/ColumnMenu/ColumnMenu.stories.tsx +14 -13
- package/src/components/ColumnMenu/ColumnMenu.tsx +8 -5
- package/src/components/ColumnMenu/{ColumnSettingsForm.stories.tsx → ColumnSettings.stories.tsx} +27 -23
- package/src/components/ColumnMenu/{ColumnSettingsForm.tsx → ColumnSettings.tsx} +44 -43
- package/src/components/ColumnMenu/index.ts +1 -1
- package/src/components/Table/Table.stories.tsx +93 -95
- package/src/components/Table/Table.tsx +10 -15
- package/src/components/Table/TableContext.tsx +13 -7
- package/src/components/Table/TableHead.tsx +0 -1
- package/src/components/Table/index.ts +2 -1
- package/src/components/Table/props.ts +4 -4
- package/src/helpers.tsx +4 -6
- package/src/hooks/useRowSelection.ts +1 -0
- package/src/schema/{SchemaToTable.stories.tsx → Schema.stories.tsx} +11 -23
- package/src/schema/{schemaToColumns.ts → column-utils.ts} +9 -9
- package/src/schema/index.ts +1 -1
- package/src/schema/types.ts +14 -6
- package/src/translations.ts +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts +0 -12
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts +0 -63
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts.map +0 -1
- package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +0 -1
- package/dist/types/src/schema/schema.d.ts +0 -5
- package/dist/types/src/schema/schema.d.ts.map +0 -1
- package/dist/types/src/schema/schema.test.d.ts +0 -2
- package/dist/types/src/schema/schema.test.d.ts.map +0 -1
- package/dist/types/src/schema/schemaToColumns.d.ts.map +0 -1
- package/src/schema/schema.test.ts +0 -148
- package/src/schema/schema.ts +0 -93
|
@@ -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": "
|
|
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",
|
|
@@ -96,11 +96,14 @@ 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/
|
|
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
|
-
var
|
|
104
|
+
var ColumnSettings = ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose }) => {
|
|
105
|
+
const { t } = useTranslation2(translationKey);
|
|
106
|
+
const propRef = useRef(null);
|
|
104
107
|
const [formState, setFormState] = useState2({
|
|
105
108
|
prop: column.id,
|
|
106
109
|
refTable: column.refTable,
|
|
@@ -109,8 +112,6 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
109
112
|
label: column.label,
|
|
110
113
|
digits: String(column.digits ?? "0")
|
|
111
114
|
});
|
|
112
|
-
const propRef = useRef(null);
|
|
113
|
-
const { t } = useTranslation2(translationKey);
|
|
114
115
|
const handleSave = () => {
|
|
115
116
|
const { prop, refTable, refProp, type, label, digits } = formState;
|
|
116
117
|
if (!prop.length || !prop.match(/^[a-zA-Z_].+/i)) {
|
|
@@ -140,9 +141,9 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
140
141
|
onClose?.();
|
|
141
142
|
};
|
|
142
143
|
return /* @__PURE__ */ React2.createElement("div", {
|
|
143
|
-
className: "
|
|
144
|
+
className: "flex flex-col w-full gap-4"
|
|
144
145
|
}, /* @__PURE__ */ React2.createElement("div", {
|
|
145
|
-
className: "
|
|
146
|
+
className: "flex flex-col gap-2"
|
|
146
147
|
}, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column label label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
147
148
|
placeholder: "Column label",
|
|
148
149
|
value: formState.label ?? "",
|
|
@@ -152,9 +153,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
152
153
|
})),
|
|
153
154
|
autoFocus: true,
|
|
154
155
|
"data-testid": "table.column-settings.label"
|
|
155
|
-
}))
|
|
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, {
|
|
156
|
+
})), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("property key label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
158
157
|
ref: propRef,
|
|
159
158
|
placeholder: "Property key",
|
|
160
159
|
value: formState.prop ?? "",
|
|
@@ -162,9 +161,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
162
161
|
...prevState,
|
|
163
162
|
prop: event.target.value.replace(/[^\w_]/g, "")
|
|
164
163
|
}))
|
|
165
|
-
}))
|
|
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, {
|
|
164
|
+
})), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column type label")), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
168
165
|
value: formState.type,
|
|
169
166
|
onValueChange: (value) => setFormState((prevState) => ({
|
|
170
167
|
...prevState,
|
|
@@ -173,25 +170,16 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
173
170
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
174
171
|
classNames: "is-full",
|
|
175
172
|
placeholder: "Type"
|
|
176
|
-
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null,
|
|
177
|
-
"number",
|
|
178
|
-
"boolean",
|
|
179
|
-
"string",
|
|
180
|
-
"ref"
|
|
181
|
-
].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, {
|
|
182
174
|
key: type,
|
|
183
175
|
value: type
|
|
184
|
-
}, t(`${type} column type label`))))))))
|
|
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, {
|
|
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, {
|
|
187
177
|
value: formState.digits ?? "",
|
|
188
178
|
onChange: (event) => setFormState((prevState) => ({
|
|
189
179
|
...prevState,
|
|
190
180
|
digits: event.target.value
|
|
191
181
|
}))
|
|
192
|
-
}))
|
|
193
|
-
className: "space-y-1"
|
|
194
|
-
}, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table"), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
182
|
+
})), 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
183
|
value: formState.refTable,
|
|
196
184
|
onValueChange: (value) => setFormState((prevState) => ({
|
|
197
185
|
...prevState,
|
|
@@ -203,9 +191,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
203
191
|
}), /* @__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
192
|
key: id,
|
|
205
193
|
value: id
|
|
206
|
-
}, name ?? id)))))))
|
|
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, {
|
|
194
|
+
}, name ?? id))))))), formState.refTable && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table property"), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
209
195
|
value: formState.refProp,
|
|
210
196
|
onValueChange: (value) => setFormState((prevState) => ({
|
|
211
197
|
...prevState,
|
|
@@ -216,10 +202,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
216
202
|
}), /* @__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
203
|
key: id,
|
|
218
204
|
value: id
|
|
219
|
-
}, label ?? id))))))))), /* @__PURE__ */ React2.createElement("div", {
|
|
220
|
-
role: "none",
|
|
221
|
-
className: "h-1"
|
|
222
|
-
}), /* @__PURE__ */ React2.createElement("div", {
|
|
205
|
+
}, label ?? id))))))))), /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement("div", {
|
|
223
206
|
className: "flex flex-row justify-end gap-1"
|
|
224
207
|
}, /* @__PURE__ */ React2.createElement(Button, {
|
|
225
208
|
onClick: handleDelete,
|
|
@@ -228,7 +211,7 @@ var ColumnSettingsForm = ({ column, tableDef, tablesToReference, onUpdate, onDel
|
|
|
228
211
|
variant: "primary",
|
|
229
212
|
onClick: handleSave,
|
|
230
213
|
"data-testid": "table.column-settings.save"
|
|
231
|
-
}, t("save label"))));
|
|
214
|
+
}, t("save label")))));
|
|
232
215
|
};
|
|
233
216
|
|
|
234
217
|
// packages/ui/react-ui-table/src/hooks/useColumnSizing.ts
|
|
@@ -269,14 +252,16 @@ import { useState as useState4 } from "react";
|
|
|
269
252
|
|
|
270
253
|
// packages/ui/react-ui-table/src/components/Table/TableContext.tsx
|
|
271
254
|
import React3, { useContext, createContext } from "react";
|
|
272
|
-
|
|
255
|
+
import { raise } from "@dxos/debug";
|
|
256
|
+
var TABLE_NAME = "Table";
|
|
257
|
+
var TableContext = /* @__PURE__ */ createContext(void 0);
|
|
273
258
|
var TableProvider = ({ children, ...value }) => {
|
|
274
259
|
return /* @__PURE__ */ React3.createElement(TableContext.Provider, {
|
|
275
260
|
value
|
|
276
261
|
}, children);
|
|
277
262
|
};
|
|
278
263
|
var useTableContext = () => {
|
|
279
|
-
return useContext(TableContext);
|
|
264
|
+
return useContext(TableContext) ?? raise(new Error("Missing TableContext"));
|
|
280
265
|
};
|
|
281
266
|
|
|
282
267
|
// packages/ui/react-ui-table/src/hooks/useColumnSorting.ts
|
|
@@ -511,7 +496,7 @@ var ColumnMenu = ({ column, columnOrderable, columnPosition, onColumnReorder, ..
|
|
|
511
496
|
className: "opacity-50"
|
|
512
497
|
}, /* @__PURE__ */ React4.createElement(GearSix, {
|
|
513
498
|
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(
|
|
499
|
+
})))), /* @__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
500
|
...props,
|
|
516
501
|
column,
|
|
517
502
|
onClose: () => setIsColumnSettingsOpen(false)
|
|
@@ -543,8 +528,8 @@ var SortIndicator = ({ direction, onClick }) => {
|
|
|
543
528
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
544
529
|
import { Slot } from "@radix-ui/react-slot";
|
|
545
530
|
import { getCoreRowModel, getExpandedRowModel, getGroupedRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
546
|
-
import React8, { Fragment, useCallback as useCallback7, useEffect as useEffect3, useState as useState8, useContext as useContext3
|
|
547
|
-
import {
|
|
531
|
+
import React8, { Fragment, memo, useCallback as useCallback7, useEffect as useEffect3, useState as useState8, useContext as useContext3 } from "react";
|
|
532
|
+
import { useDefaultValue } from "@dxos/react-ui";
|
|
548
533
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
549
534
|
|
|
550
535
|
// packages/ui/react-ui-table/src/components/Table/TableBody.tsx
|
|
@@ -775,9 +760,7 @@ var TableRoot = ({ children }) => {
|
|
|
775
760
|
const contextValue = useTableRootContext();
|
|
776
761
|
return /* @__PURE__ */ React8.createElement(TableRootContext.Provider, {
|
|
777
762
|
value: contextValue
|
|
778
|
-
},
|
|
779
|
-
density: "fine"
|
|
780
|
-
}, children));
|
|
763
|
+
}, children);
|
|
781
764
|
};
|
|
782
765
|
var TableViewport = ({ children, classNames, asChild, ...props }) => {
|
|
783
766
|
const { scrollContextRef } = useContext3(TableRootContext);
|
|
@@ -794,9 +777,9 @@ var TableViewport = ({ children, classNames, asChild, ...props }) => {
|
|
|
794
777
|
}, children);
|
|
795
778
|
};
|
|
796
779
|
var TablePrimitive = (props) => {
|
|
797
|
-
const { role,
|
|
798
|
-
const columns = useDefaultValue(props.columns, []);
|
|
799
|
-
const incomingData = useDefaultValue(props.data, []);
|
|
780
|
+
const { role, header = true, rowsSelectable, debug, pinLastRow, columnVisibility, onColumnResize, onDataSelectionChange } = props;
|
|
781
|
+
const columns = useDefaultValue(props.columns, () => []);
|
|
782
|
+
const incomingData = useDefaultValue(props.data, () => []);
|
|
800
783
|
const [data, setData] = useState8([
|
|
801
784
|
...incomingData
|
|
802
785
|
]);
|
|
@@ -828,7 +811,7 @@ var TablePrimitive = (props) => {
|
|
|
828
811
|
// Columns
|
|
829
812
|
columns,
|
|
830
813
|
defaultColumn: {
|
|
831
|
-
size:
|
|
814
|
+
size: 400,
|
|
832
815
|
maxSize: 1024
|
|
833
816
|
},
|
|
834
817
|
// State
|
|
@@ -1229,7 +1212,7 @@ var ColumnBuilder = class {
|
|
|
1229
1212
|
value
|
|
1230
1213
|
}, {
|
|
1231
1214
|
F: __dxlog_file,
|
|
1232
|
-
L:
|
|
1215
|
+
L: 377,
|
|
1233
1216
|
S: this,
|
|
1234
1217
|
C: (f, a) => f(...a)
|
|
1235
1218
|
});
|
|
@@ -1327,7 +1310,7 @@ var ColumnBuilder = class {
|
|
|
1327
1310
|
size: 50,
|
|
1328
1311
|
minSize: 50,
|
|
1329
1312
|
header: (column) => label ?? column.header.id,
|
|
1330
|
-
// TODO(zan): Implement sort algorithm
|
|
1313
|
+
// TODO(zan): Implement sort algorithm.
|
|
1331
1314
|
enableSorting: true,
|
|
1332
1315
|
cell: SwitchBuilderCell,
|
|
1333
1316
|
...props,
|
|
@@ -1352,7 +1335,7 @@ var ColumnBuilder = class {
|
|
|
1352
1335
|
const IconOff = off?.Icon ?? X2;
|
|
1353
1336
|
return {
|
|
1354
1337
|
size: size ?? 32,
|
|
1355
|
-
// TODO(zan): Implement sort algorithm
|
|
1338
|
+
// TODO(zan): Implement sort algorithm.
|
|
1356
1339
|
enableSorting: false,
|
|
1357
1340
|
header: (column) => /* @__PURE__ */ React9.createElement("div", {
|
|
1358
1341
|
className: "justify-center"
|
|
@@ -1377,7 +1360,7 @@ var ColumnBuilder = class {
|
|
|
1377
1360
|
/**
|
|
1378
1361
|
* This display column type is for nested/unhandled data to appear as JSON.
|
|
1379
1362
|
*/
|
|
1380
|
-
|
|
1363
|
+
json({ label, classNames, ...props } = {}) {
|
|
1381
1364
|
return {
|
|
1382
1365
|
size: 120,
|
|
1383
1366
|
minSize: 120,
|
|
@@ -1406,113 +1389,41 @@ var ColumnBuilder = class {
|
|
|
1406
1389
|
}
|
|
1407
1390
|
};
|
|
1408
1391
|
|
|
1409
|
-
// packages/ui/react-ui-table/src/schema/
|
|
1410
|
-
import
|
|
1411
|
-
var classifySchemaProperties = (schema) => {
|
|
1412
|
-
const recurse = (node, path, acc) => {
|
|
1413
|
-
const properties = AST.getPropertySignatures(node);
|
|
1414
|
-
properties.forEach((prop) => {
|
|
1415
|
-
const propName = prop.name.toString();
|
|
1416
|
-
if (prop.isOptional) {
|
|
1417
|
-
const unwrappedAst = unwrapOptionProperty(prop);
|
|
1418
|
-
if (isStruct(unwrappedAst)) {
|
|
1419
|
-
return recurse(unwrappedAst, [
|
|
1420
|
-
...path,
|
|
1421
|
-
propName
|
|
1422
|
-
], acc);
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
if (isStruct(prop.type)) {
|
|
1426
|
-
recurse(prop.type, [
|
|
1427
|
-
...path,
|
|
1428
|
-
propName
|
|
1429
|
-
], acc);
|
|
1430
|
-
} else {
|
|
1431
|
-
acc.push([
|
|
1432
|
-
path.concat(propName).join("."),
|
|
1433
|
-
propertyToColumn(prop)
|
|
1434
|
-
]);
|
|
1435
|
-
}
|
|
1436
|
-
});
|
|
1437
|
-
return acc;
|
|
1438
|
-
};
|
|
1439
|
-
return recurse(schema.ast, [], []);
|
|
1440
|
-
};
|
|
1441
|
-
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)}`);
|
|
1446
|
-
}
|
|
1447
|
-
if (!AST.isUnion(prop.type)) {
|
|
1448
|
-
throw new Error(`Not a union type: ${String(prop.name)}`);
|
|
1449
|
-
}
|
|
1450
|
-
const [type, _undefinedCase] = prop.type.types;
|
|
1451
|
-
return type;
|
|
1452
|
-
};
|
|
1453
|
-
var typeToColumn = (type) => {
|
|
1454
|
-
if (AST.isStringKeyword(type)) {
|
|
1455
|
-
return "string";
|
|
1456
|
-
} else if (AST.isNumberKeyword(type)) {
|
|
1457
|
-
return "number";
|
|
1458
|
-
} else if (AST.isBooleanKeyword(type)) {
|
|
1459
|
-
return "boolean";
|
|
1460
|
-
}
|
|
1461
|
-
if (AST.isRefinement(type)) {
|
|
1462
|
-
return typeToColumn(type.from);
|
|
1463
|
-
}
|
|
1464
|
-
if (AST.isTransformation(type)) {
|
|
1465
|
-
const identifier = AST.getIdentifierAnnotation(type);
|
|
1466
|
-
if (identifier._tag === "Some") {
|
|
1467
|
-
if (identifier.value === "DateFromString") {
|
|
1468
|
-
return "date";
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
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);
|
|
1480
|
-
};
|
|
1481
|
-
|
|
1482
|
-
// packages/ui/react-ui-table/src/schema/schemaToColumns.ts
|
|
1392
|
+
// packages/ui/react-ui-table/src/schema/column-utils.ts
|
|
1393
|
+
import { FieldValueType, mapSchemaToFields } from "@dxos/schema";
|
|
1483
1394
|
var schemaToColumnDefs = (schema) => {
|
|
1484
1395
|
const { helper, builder } = createColumnBuilder();
|
|
1485
|
-
const classified =
|
|
1396
|
+
const classified = mapSchemaToFields(schema);
|
|
1486
1397
|
return classified.map(([name, type]) => {
|
|
1487
1398
|
const propertyKey = name.toString();
|
|
1488
1399
|
let column;
|
|
1489
1400
|
switch (type) {
|
|
1490
|
-
case
|
|
1401
|
+
case FieldValueType.String: {
|
|
1491
1402
|
column = builder.string({
|
|
1492
1403
|
label: propertyKey
|
|
1493
1404
|
});
|
|
1494
1405
|
break;
|
|
1495
1406
|
}
|
|
1496
|
-
case
|
|
1407
|
+
case FieldValueType.Number: {
|
|
1497
1408
|
column = builder.number({
|
|
1498
1409
|
label: propertyKey
|
|
1499
1410
|
});
|
|
1500
1411
|
break;
|
|
1501
1412
|
}
|
|
1502
|
-
case
|
|
1413
|
+
case FieldValueType.Boolean: {
|
|
1503
1414
|
column = builder.switch({
|
|
1504
1415
|
label: propertyKey
|
|
1505
1416
|
});
|
|
1506
1417
|
break;
|
|
1507
1418
|
}
|
|
1508
|
-
case
|
|
1419
|
+
case FieldValueType.Date: {
|
|
1509
1420
|
column = builder.date({
|
|
1510
1421
|
label: propertyKey
|
|
1511
1422
|
});
|
|
1512
1423
|
break;
|
|
1513
1424
|
}
|
|
1514
|
-
case
|
|
1515
|
-
column = builder.
|
|
1425
|
+
case FieldValueType.JSON: {
|
|
1426
|
+
column = builder.json({
|
|
1516
1427
|
label: propertyKey,
|
|
1517
1428
|
id: propertyKey
|
|
1518
1429
|
});
|
|
@@ -1529,11 +1440,13 @@ export {
|
|
|
1529
1440
|
CellCombobox,
|
|
1530
1441
|
ColumnBuilder,
|
|
1531
1442
|
ColumnMenu,
|
|
1532
|
-
|
|
1443
|
+
ColumnSettings,
|
|
1533
1444
|
MemoizedVirtualizedTableContent,
|
|
1534
1445
|
SortIndicator,
|
|
1446
|
+
TABLE_NAME,
|
|
1535
1447
|
Table,
|
|
1536
1448
|
TablePrimitive,
|
|
1449
|
+
TableProvider,
|
|
1537
1450
|
TableRootContext,
|
|
1538
1451
|
createColumnBuilder,
|
|
1539
1452
|
currentRow,
|
|
@@ -1558,6 +1471,7 @@ export {
|
|
|
1558
1471
|
usePinLastRow,
|
|
1559
1472
|
useRowSelection,
|
|
1560
1473
|
useSortColumn,
|
|
1474
|
+
useTableContext,
|
|
1561
1475
|
useTableRootContext
|
|
1562
1476
|
};
|
|
1563
1477
|
//# sourceMappingURL=index.mjs.map
|