@dxos/react-ui-table 0.11.1 → 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
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/chunk-types.mjs +13 -22
- package/dist/lib/chunk-types.mjs.map +1 -1
- package/dist/lib/chunk-useTableModel.mjs +24 -20
- package/dist/lib/chunk-useTableModel.mjs.map +1 -1
- package/dist/lib/index.mjs +43 -43
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/testing.mjs +3 -2
- package/dist/lib/testing.mjs.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +3 -4
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +7 -6
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +7 -6
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableToolbar.d.ts +1 -1
- package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +4 -3
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +2 -2
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +3 -2
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +3 -2
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +6 -4
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +2 -2
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-view-state.d.ts +2 -2
- package/dist/types/src/translations.d.ts +1 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +2 -2
- package/dist/types/src/types/Table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +2 -2
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +2 -2
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -53
- package/src/components/Table/ColumnActionsMenu.tsx +1 -1
- package/src/components/Table/ColumnSettings.tsx +1 -1
- package/src/components/Table/DynamicTable.tsx +1 -1
- package/src/components/Table/Relations.stories.tsx +1 -1
- package/src/components/Table/RowActionsMenu.tsx +1 -1
- package/src/components/Table/Table.stories.tsx +6 -6
- package/src/components/Table/Table.tsx +1 -1
- package/src/components/Table/TableContent.tsx +3 -1
- package/src/components/Table/TableToolbar.tsx +5 -2
- package/src/components/TableCellEditor/FormCellEditor.tsx +1 -1
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +1 -1
- package/src/hooks/useProjectionModel.ts +2 -2
- package/src/hooks/useTableModel.ts +1 -1
- package/src/model/modal-controller.ts +4 -3
- package/src/model/selection-model.ts +4 -3
- package/src/model/table-model.test.ts +4 -4
- package/src/model/table-model.ts +5 -4
- package/src/model/table-presentation.test.ts +4 -4
- package/src/model/table-presentation.ts +4 -4
- package/src/playwright/playwright.config.ts +2 -6
- package/src/testing/useTestTableModel.ts +1 -1
- package/src/types/Table.ts +17 -27
- package/src/util/dynamic-table.test.ts +1 -1
- package/src/util/dynamic-table.ts +2 -2
- package/src/util/schema.ts +6 -5
- package/dist/types/src/components/testing.d.ts +0 -35
- package/dist/types/src/components/testing.d.ts.map +0 -1
- package/src/components/testing.ts +0 -125
package/dist/lib/chunk-types.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Annotation, DXN, JsonSchema, Obj, Ref, Type, View } from "@dxos/echo";
|
|
2
|
+
import { SchemaAST } from "@dxos/effect";
|
|
2
3
|
import { ViewAnnotation } from "@dxos/schema";
|
|
3
|
-
import * as Match from "effect/Match";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
|
-
import * as SchemaAST from "effect/SchemaAST";
|
|
6
5
|
import { FormInputAnnotation, LabelAnnotation } from "@dxos/echo/Annotation";
|
|
7
6
|
//#region \0rolldown/runtime.js
|
|
8
7
|
var __defProp = Object.defineProperty;
|
|
@@ -24,10 +23,7 @@ var Table_exports = /* @__PURE__ */ __exportAll({
|
|
|
24
23
|
var Table = class extends Type.makeObject(DXN.make("org.dxos.type.table", "0.1.0"))(Schema.Struct({
|
|
25
24
|
name: Schema.String.pipe(Schema.optional),
|
|
26
25
|
view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
27
|
-
sizes: Schema.Record(
|
|
28
|
-
key: Schema.String,
|
|
29
|
-
value: Schema.Number
|
|
30
|
-
}).pipe(Schema.mutable, FormInputAnnotation.set(false))
|
|
26
|
+
sizes: Schema.Record(Schema.String, Schema.Number).pipe(Schema.mutableKey, FormInputAnnotation.set(false))
|
|
31
27
|
}).pipe(LabelAnnotation.set(["name"]), ViewAnnotation.set(["view"]), Annotation.IconAnnotation.set({
|
|
32
28
|
icon: "ph--table--regular",
|
|
33
29
|
hue: "green"
|
|
@@ -36,28 +32,23 @@ var Table = class extends Type.makeObject(DXN.make("org.dxos.type.table", "0.1.0
|
|
|
36
32
|
* Make a table as a view of a data set.
|
|
37
33
|
*/
|
|
38
34
|
var make = ({ name, sizes = {}, view, jsonSchema }) => {
|
|
39
|
-
const
|
|
40
|
-
name,
|
|
41
|
-
view: Ref.make(view),
|
|
42
|
-
sizes
|
|
43
|
-
});
|
|
35
|
+
const initialSizes = { ...sizes };
|
|
44
36
|
if (jsonSchema) {
|
|
45
37
|
const schema = JsonSchema.toEffectSchema(jsonSchema);
|
|
46
|
-
const
|
|
47
|
-
for (const property of properties) {
|
|
38
|
+
for (const property of SchemaAST.getPropertySignatures(schema.ast)) {
|
|
48
39
|
const name = property.name.toString();
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
if (initialSizes[name] !== void 0) continue;
|
|
41
|
+
switch (property.type._tag) {
|
|
42
|
+
case "Boolean":
|
|
43
|
+
case "Number": initialSizes[name] = 100;
|
|
52
44
|
}
|
|
53
|
-
Match.type().pipe(Match.when({ _tag: "BooleanKeyword" }, () => {
|
|
54
|
-
table.sizes[name] = 100;
|
|
55
|
-
}), Match.when({ _tag: "NumberKeyword" }, () => {
|
|
56
|
-
table.sizes[name] = 100;
|
|
57
|
-
}), Match.orElse(() => {}))(property.type);
|
|
58
45
|
}
|
|
59
46
|
}
|
|
60
|
-
return
|
|
47
|
+
return Obj.make(Table, {
|
|
48
|
+
name,
|
|
49
|
+
view: Ref.make(view),
|
|
50
|
+
sizes: initialSizes
|
|
51
|
+
});
|
|
61
52
|
};
|
|
62
53
|
//#endregion
|
|
63
54
|
export { Table_exports as n, Table as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-types.mjs","names":[],"sources":["../../src/types/Table.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as
|
|
1
|
+
{"version":3,"file":"chunk-types.mjs","names":[],"sources":["../../src/types/Table.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// QueryAST is referenced indirectly through `Type.InstanceType<typeof TableSchema>`\n// (Ref.Ref(View.View) → View.View → QueryAST.Query) in the emitted .d.ts; the\n// namespace import keeps the inferred types portable.\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { Annotation, DXN, JsonSchema, Obj, QueryAST, Ref, Type, View } from '@dxos/echo';\nimport { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/Annotation';\nimport { type JsonSchema as JsonSchemaType } from '@dxos/echo/JsonSchema';\nimport { SchemaAST, SchemaEx } from '@dxos/effect';\nimport { ViewAnnotation } from '@dxos/schema';\n\n// TODO(wittjosiah): Try to clean up this type inference.\nexport class Table extends Type.makeObject<Table>(DXN.make('org.dxos.type.table', '0.1.0'))(\n Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n\n view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),\n\n // TODO(wittjosiah): Key should be JsonPath.\n sizes: Schema.Record(Schema.String, Schema.Number).pipe(Schema.mutableKey, FormInputAnnotation.set(false)),\n }).pipe(\n LabelAnnotation.set(['name']),\n ViewAnnotation.set(['view']),\n Annotation.IconAnnotation.set({ icon: 'ph--table--regular', hue: 'green' }),\n ),\n) {}\n\ntype MakeProps = {\n name?: string;\n sizes?: Record<string, number>;\n view: View.View;\n /** Required to auto-size columns. */\n jsonSchema?: JsonSchemaType;\n};\n\n/**\n * Make a table as a view of a data set.\n */\nexport const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {\n // Preset sizes are computed before construction: Effect 4 records are readonly at the type level,\n // so the defaults go in as initial props rather than being assigned onto the live object.\n const initialSizes: Record<string, number> = { ...sizes };\n if (jsonSchema) {\n const schema = JsonSchema.toEffectSchema(jsonSchema);\n for (const property of SchemaAST.getPropertySignatures(schema.ast)) {\n const name = property.name.toString() as SchemaEx.JsonPath;\n if (initialSizes[name] !== undefined) {\n continue;\n }\n\n // A plain switch rather than `Match.when({ _tag })`: matching an object pattern against\n // Effect 4's mutually recursive AST union expands into a mapped type the checker cannot resolve.\n switch (property.type._tag) {\n case 'Boolean':\n case 'Number':\n initialSizes[name] = 100;\n break;\n }\n }\n }\n\n return Obj.make(Table, { name, view: Ref.make(view), sizes: initialSizes } as Obj.MakeProps<typeof Table>);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAa,QAAb,cAA2B,KAAK,WAAkB,IAAI,KAAK,uBAAuB,OAAO,CAAC,CAAC,CACzF,OAAO,OAAO;CACZ,MAAM,OAAO,OAAO,KAAK,OAAO,QAAQ;CAExC,MAAM,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,KAAK,oBAAoB,IAAI,KAAK,CAAC;CAG5D,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,KAAK,OAAO,YAAY,oBAAoB,IAAI,KAAK,CAAC;AAC3G,CAAC,CAAC,CAAC,KACD,gBAAgB,IAAI,CAAC,MAAM,CAAC,GAC5B,eAAe,IAAI,CAAC,MAAM,CAAC,GAC3B,WAAW,eAAe,IAAI;CAAE,MAAM;CAAsB,KAAK;AAAQ,CAAC,CAC5E,CACF,CAAC,CAAC,CAAC;;;;AAaH,IAAa,QAAQ,EAAE,MAAM,QAAQ,CAAC,GAAG,MAAM,iBAAmC;CAGhF,MAAM,eAAuC,EAAE,GAAG,MAAM;CACxD,IAAI,YAAY;EACd,MAAM,SAAS,WAAW,eAAe,UAAU;EACnD,KAAK,MAAM,YAAY,UAAU,sBAAsB,OAAO,GAAG,GAAG;GAClE,MAAM,OAAO,SAAS,KAAK,SAAS;GACpC,IAAI,aAAa,UAAU,KAAA,GACzB;GAKF,QAAQ,SAAS,KAAK,MAAtB;IACE,KAAK;IACL,KAAK,UACH,aAAa,QAAQ;GAEzB;EACF;CACF;CAEA,OAAO,IAAI,KAAK,OAAO;EAAE;EAAM,MAAM,IAAI,KAAK,IAAI;EAAG,OAAO;CAAa,CAAgC;AAC3G"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Atom from "effect/unstable/reactivity/Atom";
|
|
2
2
|
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { RegistryContext } from "@effect
|
|
3
|
+
import { RegistryContext } from "@effect/atom-react/RegistryContext";
|
|
4
4
|
import { useAsyncEffect } from "@dxos/react-ui";
|
|
5
5
|
import { ViewState, useManagerOptional, useSelection, useSelectionActions } from "@dxos/react-ui-attention";
|
|
6
6
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
@@ -341,9 +341,7 @@ var SelectionModel = class extends Resource {
|
|
|
341
341
|
case "all":
|
|
342
342
|
this._registry.set(this._selection, new Set(this._registry.get(this._rows).map((row) => row.id)));
|
|
343
343
|
break;
|
|
344
|
-
case "none":
|
|
345
|
-
this._registry.set(this._selection, /* @__PURE__ */ new Set());
|
|
346
|
-
break;
|
|
344
|
+
case "none": this._registry.set(this._selection, /* @__PURE__ */ new Set());
|
|
347
345
|
}
|
|
348
346
|
};
|
|
349
347
|
};
|
|
@@ -444,7 +442,7 @@ var TableModel = class extends Resource {
|
|
|
444
442
|
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
445
443
|
"~LogMeta": "~LogMeta",
|
|
446
444
|
F: __dxlog_file,
|
|
447
|
-
L:
|
|
445
|
+
L: 209,
|
|
448
446
|
S: this,
|
|
449
447
|
A: ["!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')", "'Single selection is not compatible with editable tables.'"]
|
|
450
448
|
});
|
|
@@ -517,7 +515,7 @@ var TableModel = class extends Resource {
|
|
|
517
515
|
invariant(view, "Table model not initialized", {
|
|
518
516
|
"~LogMeta": "~LogMeta",
|
|
519
517
|
F: __dxlog_file,
|
|
520
|
-
L:
|
|
518
|
+
L: 329,
|
|
521
519
|
S: this,
|
|
522
520
|
A: ["view", "'Table model not initialized'"]
|
|
523
521
|
});
|
|
@@ -634,7 +632,7 @@ var TableModel = class extends Resource {
|
|
|
634
632
|
invariant(this._columnMeta, void 0, {
|
|
635
633
|
"~LogMeta": "~LogMeta",
|
|
636
634
|
F: __dxlog_file,
|
|
637
|
-
L:
|
|
635
|
+
L: 471,
|
|
638
636
|
S: this,
|
|
639
637
|
A: ["this._columnMeta", ""]
|
|
640
638
|
});
|
|
@@ -656,7 +654,7 @@ var TableModel = class extends Resource {
|
|
|
656
654
|
invariant(this._object.view.target, "View must be loaded before initializing column meta", {
|
|
657
655
|
"~LogMeta": "~LogMeta",
|
|
658
656
|
F: __dxlog_file,
|
|
659
|
-
L:
|
|
657
|
+
L: 495,
|
|
660
658
|
S: this,
|
|
661
659
|
A: ["this._object.view.target", "'View must be loaded before initializing column meta'"]
|
|
662
660
|
});
|
|
@@ -784,7 +782,8 @@ var TableModel = class extends Resource {
|
|
|
784
782
|
this._registry.set(this._draftRows, newDraftRows);
|
|
785
783
|
}
|
|
786
784
|
validateDraftRowData(data) {
|
|
787
|
-
|
|
785
|
+
const schema = toEffectSchema(this._projection.baseSchema);
|
|
786
|
+
return validateSchema(schema, data) || [];
|
|
788
787
|
}
|
|
789
788
|
commitDraftRow = (draftRowIndex) => {
|
|
790
789
|
if (draftRowIndex < 0 || draftRowIndex >= this._registry.get(this._draftRows).length) return false;
|
|
@@ -818,9 +817,10 @@ var TableModel = class extends Resource {
|
|
|
818
817
|
if (fieldIndex === void 0 || fieldIndex < 0 || fieldIndex >= fields.length) return;
|
|
819
818
|
const field = fields[fieldIndex];
|
|
820
819
|
let value;
|
|
821
|
-
if (plane === "frozenRowsEnd")
|
|
822
|
-
|
|
823
|
-
|
|
820
|
+
if (plane === "frozenRowsEnd") {
|
|
821
|
+
if (row >= 0 && row < this._registry.get(this._draftRows).length) value = SchemaEx.getValue(this._registry.get(this._draftRows)[row].data, field.path);
|
|
822
|
+
else return;
|
|
823
|
+
} else {
|
|
824
824
|
const sortedRows = this._registry.get(this._sortedRows);
|
|
825
825
|
value = SchemaEx.getValue(sortedRows[row], field.path);
|
|
826
826
|
}
|
|
@@ -868,7 +868,7 @@ var TableModel = class extends Resource {
|
|
|
868
868
|
invariant(currentRow, "Invalid row index", {
|
|
869
869
|
"~LogMeta": "~LogMeta",
|
|
870
870
|
F: __dxlog_file,
|
|
871
|
-
L:
|
|
871
|
+
L: 814,
|
|
872
872
|
S: this,
|
|
873
873
|
A: ["currentRow", "'Invalid row index'"]
|
|
874
874
|
});
|
|
@@ -878,11 +878,12 @@ var TableModel = class extends Resource {
|
|
|
878
878
|
invariant(type, void 0, {
|
|
879
879
|
"~LogMeta": "~LogMeta",
|
|
880
880
|
F: __dxlog_file,
|
|
881
|
-
L:
|
|
881
|
+
L: 821,
|
|
882
882
|
S: this,
|
|
883
883
|
A: ["type", ""]
|
|
884
884
|
});
|
|
885
|
-
const
|
|
885
|
+
const schema = Type.getSchema(type);
|
|
886
|
+
const validationResult = validateSchema(schema, snapshot);
|
|
886
887
|
if (validationResult && validationResult.length > 0) {
|
|
887
888
|
const error = validationResult.find((err) => err.path === field.path);
|
|
888
889
|
if (error) return {
|
|
@@ -1168,7 +1169,7 @@ var TablePresentation = class {
|
|
|
1168
1169
|
if (typeof value === "object" && value.value) return `${value.value}`;
|
|
1169
1170
|
return "Object";
|
|
1170
1171
|
};
|
|
1171
|
-
cell.accessoryHtml = `<div class="flex flex-row gap-1 overflow-x-auto">${targetArray.map(getLabel).filter(Predicate.
|
|
1172
|
+
cell.accessoryHtml = `<div class="flex flex-row gap-1 overflow-x-auto">${targetArray.map(getLabel).filter(Predicate.isNotNullish).map((title) => {
|
|
1172
1173
|
return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
|
|
1173
1174
|
}).join("")}</div>`;
|
|
1174
1175
|
}
|
|
@@ -1477,8 +1478,10 @@ var safeHttpUrl = (value) => {
|
|
|
1477
1478
|
*/
|
|
1478
1479
|
var escapeHtmlAttribute = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
1479
1480
|
var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
1480
|
-
if (!selected)
|
|
1481
|
-
|
|
1481
|
+
if (!selected) {
|
|
1482
|
+
if (selectionMode === "single") return ["cursor-pointer!"];
|
|
1483
|
+
else return;
|
|
1484
|
+
}
|
|
1482
1485
|
switch (selectionMode) {
|
|
1483
1486
|
case "single": return ["dx-grid__cell--no-focus-unfurl bg-current-surface! hover:bg-hover-surface cursor-pointer!"];
|
|
1484
1487
|
case "multiple": return ["bg-grid-cell-selected!"];
|
|
@@ -1510,11 +1513,12 @@ var useProjectionModel = (schema, table, registry) => {
|
|
|
1510
1513
|
if (schema && table) {
|
|
1511
1514
|
const view = await table.view.load();
|
|
1512
1515
|
const jsonSchema = schema.jsonSchema;
|
|
1516
|
+
const change = createEchoChangeCallback(view, Type.getDatabase(schema) != null ? schema : void 0);
|
|
1513
1517
|
const projection = new ProjectionModel({
|
|
1514
1518
|
registry,
|
|
1515
1519
|
view,
|
|
1516
1520
|
baseSchema: jsonSchema,
|
|
1517
|
-
change
|
|
1521
|
+
change
|
|
1518
1522
|
});
|
|
1519
1523
|
projection.normalizeView();
|
|
1520
1524
|
setProjection(projection);
|