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