@dxos/react-ui-table 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549
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/chunk-5XWSB3JP.mjs +71 -0
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GS2UNGJK.mjs → chunk-KNC7XYT6.mjs} +116 -108
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +25 -13
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/{chunk-TRR3C5NX.mjs → chunk-CWSGS3Y2.mjs} +116 -108
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs +72 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +25 -13
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +14 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +2 -2
- 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 +67 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +2 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +0 -2
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +4 -5
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +6 -8
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +7 -3
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +1 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +21 -15
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/types/Table.d.ts +28 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +7 -6
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -38
- package/src/components/Table/DynamicTable.stories.tsx +7 -7
- package/src/components/Table/DynamicTable.tsx +12 -4
- package/src/components/Table/Relations.stories.tsx +9 -14
- package/src/components/Table/Table.stories.tsx +47 -42
- package/src/components/TableCellEditor/FormCellEditor.tsx +2 -2
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +5 -4
- package/src/components/TableCellEditor/TableCellEditor.tsx +4 -4
- package/src/components/TableToolbar/TableToolbar.tsx +1 -1
- package/src/components/testing.ts +3 -3
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useProjectionModel.ts +19 -0
- package/src/hooks/useTableModel.ts +10 -12
- package/src/model/table-model.test.ts +4 -4
- package/src/model/table-model.ts +27 -36
- package/src/model/table-presentation.test.ts +4 -4
- package/src/model/table-presentation.ts +9 -9
- package/src/model/table-sorting.ts +21 -12
- package/src/playwright/TableManager.ts +3 -3
- package/src/playwright/smoke.spec.ts +1 -1
- package/src/testing/useTestTableModel.ts +32 -24
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +89 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +9 -12
- package/dist/lib/browser/chunk-2PFAPQL4.mjs +0 -66
- package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +0 -7
- package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs +0 -67
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +0 -7
- package/dist/types/src/types/schema.d.ts +0 -28
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/types/schema.ts +0 -73
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/types/Table.ts
|
|
8
|
+
var Table_exports = {};
|
|
9
|
+
__export(Table_exports, {
|
|
10
|
+
Table: () => Table,
|
|
11
|
+
TableV1: () => TableV1,
|
|
12
|
+
make: () => make
|
|
13
|
+
});
|
|
14
|
+
import * as Match from "effect/Match";
|
|
15
|
+
import * as Schema from "effect/Schema";
|
|
16
|
+
import { Obj, Ref, Type } from "@dxos/echo";
|
|
17
|
+
import { FormInputAnnotation, LabelAnnotation } from "@dxos/echo/internal";
|
|
18
|
+
import { View, ViewAnnotation, getSchemaProperties } from "@dxos/schema";
|
|
19
|
+
var TableSchema = Schema.Struct({
|
|
20
|
+
name: Schema.String.pipe(Schema.optional),
|
|
21
|
+
view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
22
|
+
sizes: Schema.Record({
|
|
23
|
+
// TODO(wittjosiah): Should be JsonPath.
|
|
24
|
+
key: Schema.String,
|
|
25
|
+
value: Schema.Number
|
|
26
|
+
}).pipe(Schema.mutable, FormInputAnnotation.set(false))
|
|
27
|
+
}).pipe(Type.Obj({
|
|
28
|
+
typename: "dxos.org/type/Table",
|
|
29
|
+
version: "0.2.0"
|
|
30
|
+
}), LabelAnnotation.set([
|
|
31
|
+
"name"
|
|
32
|
+
]), ViewAnnotation.set(true));
|
|
33
|
+
var Table = TableSchema;
|
|
34
|
+
var make = ({ name, sizes = {}, view, jsonSchema }) => {
|
|
35
|
+
const table = Obj.make(Table, {
|
|
36
|
+
name,
|
|
37
|
+
view: Ref.make(view),
|
|
38
|
+
sizes
|
|
39
|
+
});
|
|
40
|
+
if (jsonSchema) {
|
|
41
|
+
const schema = Type.toEffectSchema(jsonSchema);
|
|
42
|
+
const properties = getSchemaProperties(schema.ast, {});
|
|
43
|
+
for (const property of properties) {
|
|
44
|
+
if (sizes?.[property.name]) {
|
|
45
|
+
table.sizes[property.name] = sizes[property.name];
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
Match.type().pipe(Match.when("boolean", () => {
|
|
49
|
+
table.sizes[property.name] = 100;
|
|
50
|
+
}), Match.when("number", () => {
|
|
51
|
+
table.sizes[property.name] = 100;
|
|
52
|
+
}), Match.orElse(() => {
|
|
53
|
+
}))(property.type);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return table;
|
|
57
|
+
};
|
|
58
|
+
var TableV1 = Schema.Struct({
|
|
59
|
+
sizes: Schema.Record({
|
|
60
|
+
key: Schema.String,
|
|
61
|
+
value: Schema.Number
|
|
62
|
+
}).pipe(Schema.mutable)
|
|
63
|
+
}).pipe(Type.Obj({
|
|
64
|
+
typename: "dxos.org/type/Table",
|
|
65
|
+
version: "0.1.0"
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
Table_exports
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=chunk-5XWSB3JP.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/Table.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\nimport * as Schema from 'effect/Schema';\n\nimport { Obj, Ref, Type } from '@dxos/echo';\nimport { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';\nimport { type SimpleType } from '@dxos/effect';\nimport { View, ViewAnnotation, getSchemaProperties } from '@dxos/schema';\n\nconst TableSchema = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n\n view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),\n\n sizes: Schema.Record({\n // TODO(wittjosiah): Should be JsonPath.\n key: Schema.String,\n value: Schema.Number,\n }).pipe(Schema.mutable, FormInputAnnotation.set(false)),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.2.0',\n }),\n LabelAnnotation.set(['name']),\n ViewAnnotation.set(true),\n);\n\nexport interface Table extends Schema.Schema.Type<typeof TableSchema> {}\nexport interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}\nexport const Table: Schema.Schema<Table, TableEncoded> = TableSchema;\n\ntype MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {\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 const table = Obj.make(Table, { name, view: Ref.make(view), sizes });\n\n // Preset sizes.\n if (jsonSchema) {\n const schema = Type.toEffectSchema(jsonSchema);\n const properties = getSchemaProperties(schema.ast, {});\n for (const property of properties) {\n if (sizes?.[property.name]) {\n table.sizes[property.name] = sizes[property.name];\n continue;\n }\n\n Match.type<SimpleType>().pipe(\n Match.when('boolean', () => {\n table.sizes[property.name as JsonPath] = 100;\n }),\n Match.when('number', () => {\n table.sizes[property.name as JsonPath] = 100;\n }),\n Match.orElse(() => {\n // Noop.\n }),\n )(property.type);\n }\n }\n\n return table;\n};\n\n//\n// V1\n//\n\nexport const TableV1 = Schema.Struct({\n sizes: Schema.Record({\n key: Schema.String,\n value: Schema.Number,\n }).pipe(Schema.mutable),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.1.0',\n }),\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;;;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,YAAY;AAExB,SAASC,KAAKC,KAAKC,YAAY;AAC/B,SAASC,qBAAyDC,uBAAuB;AAEzF,SAASC,MAAMC,gBAAgBC,2BAA2B;AAE1D,IAAMC,cAAqBC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EAExCC,MAAMC,KAAKC,IAAIC,KAAKA,IAAI,EAAEL,KAAKM,oBAAoBC,IAAI,KAAA,CAAA;EAEvDC,OAAcC,cAAO;;IAEnBC,KAAYX;IACZY,OAAcC;EAChB,CAAA,EAAGZ,KAAYa,gBAASP,oBAAoBC,IAAI,KAAA,CAAA;AAClD,CAAA,EAAGP,KACDG,KAAKW,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,gBAAgBV,IAAI;EAAC;CAAO,GAC5BW,eAAeX,IAAI,IAAA,CAAA;AAKd,IAAMY,QAA4CvB;AAWlD,IAAMwB,OAAO,CAAC,EAAEtB,MAAMU,QAAQ,CAAC,GAAGN,MAAMmB,WAAU,MAAa;AACpE,QAAMC,QAAQR,IAAIM,KAAKD,OAAO;IAAErB;IAAMI,MAAME,IAAIgB,KAAKlB,IAAAA;IAAOM;EAAM,CAAA;AAGlE,MAAIa,YAAY;AACd,UAAME,SAASpB,KAAKqB,eAAeH,UAAAA;AACnC,UAAMI,aAAaC,oBAAoBH,OAAOI,KAAK,CAAC,CAAA;AACpD,eAAWC,YAAYH,YAAY;AACjC,UAAIjB,QAAQoB,SAAS9B,IAAI,GAAG;AAC1BwB,cAAMd,MAAMoB,SAAS9B,IAAI,IAAIU,MAAMoB,SAAS9B,IAAI;AAChD;MACF;AAEA+B,MAAMC,WAAI,EAAe9B,KACjB+B,WAAK,WAAW,MAAA;AACpBT,cAAMd,MAAMoB,SAAS9B,IAAI,IAAgB;MAC3C,CAAA,GACMiC,WAAK,UAAU,MAAA;AACnBT,cAAMd,MAAMoB,SAAS9B,IAAI,IAAgB;MAC3C,CAAA,GACMkC,aAAO,MAAA;MAEb,CAAA,CAAA,EACAJ,SAASE,IAAI;IACjB;EACF;AAEA,SAAOR;AACT;AAMO,IAAMW,UAAiBpC,cAAO;EACnCW,OAAcC,cAAO;IACnBC,KAAYX;IACZY,OAAcC;EAChB,CAAA,EAAGZ,KAAYa,cAAO;AACxB,CAAA,EAAGb,KACDG,KAAKW,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;",
|
|
6
|
+
"names": ["Match", "Schema", "Obj", "Ref", "Type", "FormInputAnnotation", "LabelAnnotation", "View", "ViewAnnotation", "getSchemaProperties", "TableSchema", "Struct", "name", "String", "pipe", "optional", "view", "Type", "Ref", "View", "FormInputAnnotation", "set", "sizes", "Record", "key", "value", "Number", "mutable", "Obj", "typename", "version", "LabelAnnotation", "ViewAnnotation", "Table", "make", "jsonSchema", "table", "schema", "toEffectSchema", "properties", "getSchemaProperties", "ast", "property", "Match", "type", "when", "orElse", "TableV1"]
|
|
7
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
Table_exports
|
|
3
|
+
} from "./chunk-5XWSB3JP.mjs";
|
|
4
4
|
|
|
5
5
|
// src/util/dynamic-table.ts
|
|
6
|
-
import { Filter, Obj, Query } from "@dxos/echo";
|
|
7
|
-
import { getTypename, toJsonSchema } from "@dxos/echo/internal";
|
|
6
|
+
import { Filter, Obj, Query, Ref, Type } from "@dxos/echo";
|
|
8
7
|
import { ProjectionModel, View, getSchemaFromPropertyDefinitions } from "@dxos/schema";
|
|
9
8
|
var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
10
9
|
if (typename && properties) {
|
|
@@ -15,8 +14,8 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
15
14
|
};
|
|
16
15
|
} else if (schema) {
|
|
17
16
|
return {
|
|
18
|
-
typename: getTypename(schema),
|
|
19
|
-
jsonSchema: toJsonSchema(schema)
|
|
17
|
+
typename: Type.getTypename(schema),
|
|
18
|
+
jsonSchema: Type.toJsonSchema(schema)
|
|
20
19
|
};
|
|
21
20
|
} else if (typename && jsonSchema) {
|
|
22
21
|
return {
|
|
@@ -28,25 +27,25 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
var makeDynamicTable = ({ jsonSchema, properties }) => {
|
|
31
|
-
const table = Obj.make(schema_exports.Table, {
|
|
32
|
-
sizes: {}
|
|
33
|
-
});
|
|
34
30
|
const view = View.make({
|
|
35
31
|
query: Query.select(Filter.everything()),
|
|
36
32
|
jsonSchema,
|
|
37
|
-
presentation: table,
|
|
38
33
|
...properties && {
|
|
39
34
|
fields: properties.map((property) => property.name)
|
|
40
35
|
}
|
|
41
36
|
});
|
|
37
|
+
const object = Obj.make(Table_exports.Table, {
|
|
38
|
+
view: Ref.make(view),
|
|
39
|
+
sizes: {}
|
|
40
|
+
});
|
|
42
41
|
const projection = new ProjectionModel(jsonSchema, view.projection);
|
|
43
42
|
projection.normalizeView();
|
|
44
43
|
if (properties && projection.fields) {
|
|
45
|
-
setProperties(view, projection,
|
|
44
|
+
setProperties(view, projection, object, properties);
|
|
46
45
|
}
|
|
47
46
|
return {
|
|
48
47
|
projection,
|
|
49
|
-
|
|
48
|
+
object
|
|
50
49
|
};
|
|
51
50
|
};
|
|
52
51
|
var setProperties = (view, projection, table, properties) => {
|
|
@@ -273,13 +272,13 @@ var narrowSchema = (schema, paths) => {
|
|
|
273
272
|
// src/model/table-model.ts
|
|
274
273
|
import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
|
|
275
274
|
import { Resource as Resource2 } from "@dxos/context";
|
|
276
|
-
import { Obj as Obj2, Ref } from "@dxos/echo";
|
|
277
|
-
import {
|
|
275
|
+
import { Format as Format2, Obj as Obj2, Ref as Ref2 } from "@dxos/echo";
|
|
276
|
+
import { getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
|
|
278
277
|
import { invariant } from "@dxos/invariant";
|
|
279
278
|
import { ObjectId } from "@dxos/keys";
|
|
280
279
|
import { getSnapshot, isLiveObject } from "@dxos/live-object";
|
|
281
280
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
282
|
-
import {
|
|
281
|
+
import { validateSchema } from "@dxos/schema";
|
|
283
282
|
|
|
284
283
|
// src/util/tag.ts
|
|
285
284
|
var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
@@ -394,23 +393,23 @@ var SelectionModel = class extends Resource {
|
|
|
394
393
|
// src/model/table-sorting.ts
|
|
395
394
|
import { computed as computed2, signal as signal2 } from "@preact/signals-core";
|
|
396
395
|
import orderBy from "lodash.orderby";
|
|
397
|
-
import {
|
|
396
|
+
import { Format, TypeEnum, getValue } from "@dxos/echo/internal";
|
|
398
397
|
import { formatForDisplay } from "@dxos/react-ui-form";
|
|
399
398
|
var TableSorting = class {
|
|
400
|
-
_view;
|
|
401
|
-
_projection;
|
|
402
399
|
_displayToDataIndex = /* @__PURE__ */ new Map();
|
|
403
400
|
_rows;
|
|
401
|
+
_getView;
|
|
402
|
+
_projection;
|
|
404
403
|
_localSort = signal2(void 0);
|
|
405
404
|
_isDirty;
|
|
406
405
|
sortedRows;
|
|
407
|
-
constructor(rows,
|
|
408
|
-
this._view = _view;
|
|
409
|
-
this._projection = _projection;
|
|
406
|
+
constructor({ rows, projection, getView }) {
|
|
410
407
|
this._rows = rows;
|
|
408
|
+
this._getView = getView;
|
|
409
|
+
this._projection = projection;
|
|
411
410
|
this._isDirty = computed2(() => {
|
|
412
411
|
const local = this._localSort.value;
|
|
413
|
-
const viewSort = this.
|
|
412
|
+
const viewSort = this._getView().sort?.[0];
|
|
414
413
|
if (local?.type === "cleared") {
|
|
415
414
|
return viewSort !== void 0;
|
|
416
415
|
}
|
|
@@ -436,7 +435,7 @@ var TableSorting = class {
|
|
|
436
435
|
if (local?.type === "active") {
|
|
437
436
|
return local.sort;
|
|
438
437
|
}
|
|
439
|
-
return this.
|
|
438
|
+
return this._getView().sort?.[0];
|
|
440
439
|
}
|
|
441
440
|
/**
|
|
442
441
|
* @reactive
|
|
@@ -479,12 +478,13 @@ var TableSorting = class {
|
|
|
479
478
|
}
|
|
480
479
|
save() {
|
|
481
480
|
if (this._localSort.value !== void 0) {
|
|
481
|
+
const view = this._getView();
|
|
482
482
|
if (this._localSort.value.type === "active") {
|
|
483
|
-
|
|
483
|
+
view.sort = [
|
|
484
484
|
this._localSort.value.sort
|
|
485
485
|
];
|
|
486
486
|
} else {
|
|
487
|
-
|
|
487
|
+
view.sort = [];
|
|
488
488
|
}
|
|
489
489
|
this._localSort.value = void 0;
|
|
490
490
|
}
|
|
@@ -541,7 +541,7 @@ var TableSorting = class {
|
|
|
541
541
|
if (value == null) {
|
|
542
542
|
return value;
|
|
543
543
|
}
|
|
544
|
-
if (format ===
|
|
544
|
+
if (format === Format.TypeFormat.SingleSelect) {
|
|
545
545
|
const options = props.options;
|
|
546
546
|
if (!options) {
|
|
547
547
|
return void 0;
|
|
@@ -549,7 +549,7 @@ var TableSorting = class {
|
|
|
549
549
|
const option = options.find((option2) => option2.id === value);
|
|
550
550
|
return option ? options.indexOf(option) : void 0;
|
|
551
551
|
}
|
|
552
|
-
if (format ===
|
|
552
|
+
if (format === Format.TypeFormat.Ref && field.referencePath) {
|
|
553
553
|
const refValue = getValue(value.target, field.referencePath);
|
|
554
554
|
return refValue;
|
|
555
555
|
}
|
|
@@ -572,9 +572,8 @@ var defaultFeatures = {
|
|
|
572
572
|
schemaEditable: false
|
|
573
573
|
};
|
|
574
574
|
var TableModel = class extends Resource2 {
|
|
575
|
-
|
|
575
|
+
_object;
|
|
576
576
|
_projection;
|
|
577
|
-
_table;
|
|
578
577
|
_visibleRange = signal3({
|
|
579
578
|
start: {
|
|
580
579
|
row: 0,
|
|
@@ -599,13 +598,13 @@ var TableModel = class extends Resource2 {
|
|
|
599
598
|
_pinnedRows;
|
|
600
599
|
_selection;
|
|
601
600
|
_columnMeta;
|
|
602
|
-
constructor({
|
|
601
|
+
constructor({ object, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
603
602
|
top: [],
|
|
604
603
|
bottom: []
|
|
605
604
|
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
606
605
|
super();
|
|
607
|
-
this.
|
|
608
|
-
this._projection = projection
|
|
606
|
+
this._object = object;
|
|
607
|
+
this._projection = projection;
|
|
609
608
|
this._projection.normalizeView();
|
|
610
609
|
this._features = {
|
|
611
610
|
...defaultFeatures,
|
|
@@ -613,14 +612,18 @@ var TableModel = class extends Resource2 {
|
|
|
613
612
|
};
|
|
614
613
|
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
615
614
|
F: __dxlog_file,
|
|
616
|
-
L:
|
|
615
|
+
L: 137,
|
|
617
616
|
S: this,
|
|
618
617
|
A: [
|
|
619
618
|
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
620
619
|
"'Single selection is not compatible with editable tables.'"
|
|
621
620
|
]
|
|
622
621
|
});
|
|
623
|
-
this._sorting = new TableSorting(
|
|
622
|
+
this._sorting = new TableSorting({
|
|
623
|
+
rows: this._rows,
|
|
624
|
+
getView: () => this.view,
|
|
625
|
+
projection: this._projection
|
|
626
|
+
});
|
|
624
627
|
if (sorting.length > 0) {
|
|
625
628
|
const [sort] = sorting;
|
|
626
629
|
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
@@ -636,22 +639,23 @@ var TableModel = class extends Resource2 {
|
|
|
636
639
|
this._onRowAction = onRowAction;
|
|
637
640
|
}
|
|
638
641
|
get id() {
|
|
639
|
-
return Obj2.getDXN(this.
|
|
642
|
+
return Obj2.getDXN(this._object).toString();
|
|
640
643
|
}
|
|
641
644
|
get view() {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
get table() {
|
|
645
|
-
invariant(this._table, "Model not initialized", {
|
|
645
|
+
const view = this._object.view.target;
|
|
646
|
+
invariant(view, "Table model not initialized", {
|
|
646
647
|
F: __dxlog_file,
|
|
647
|
-
L:
|
|
648
|
+
L: 176,
|
|
648
649
|
S: this,
|
|
649
650
|
A: [
|
|
650
|
-
"
|
|
651
|
-
"'
|
|
651
|
+
"view",
|
|
652
|
+
"'Table model not initialized'"
|
|
652
653
|
]
|
|
653
654
|
});
|
|
654
|
-
return
|
|
655
|
+
return view;
|
|
656
|
+
}
|
|
657
|
+
get table() {
|
|
658
|
+
return this._object;
|
|
655
659
|
}
|
|
656
660
|
get projection() {
|
|
657
661
|
return this._projection;
|
|
@@ -683,7 +687,7 @@ var TableModel = class extends Resource2 {
|
|
|
683
687
|
get columnMeta() {
|
|
684
688
|
invariant(this._columnMeta, void 0, {
|
|
685
689
|
F: __dxlog_file,
|
|
686
|
-
L:
|
|
690
|
+
L: 219,
|
|
687
691
|
S: this,
|
|
688
692
|
A: [
|
|
689
693
|
"this._columnMeta",
|
|
@@ -706,17 +710,7 @@ var TableModel = class extends Resource2 {
|
|
|
706
710
|
// Initialisation
|
|
707
711
|
//
|
|
708
712
|
async _open() {
|
|
709
|
-
|
|
710
|
-
invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
|
|
711
|
-
F: __dxlog_file,
|
|
712
|
-
L: 248,
|
|
713
|
-
S: this,
|
|
714
|
-
A: [
|
|
715
|
-
"Obj.instanceOf(Table.Table, presentation)",
|
|
716
|
-
""
|
|
717
|
-
]
|
|
718
|
-
});
|
|
719
|
-
this._table = presentation;
|
|
713
|
+
await this._object.view.load();
|
|
720
714
|
this.initializeColumnMeta();
|
|
721
715
|
this.initializeEffects();
|
|
722
716
|
await this._selection.open(this._ctx);
|
|
@@ -913,7 +907,7 @@ var TableModel = class extends Resource2 {
|
|
|
913
907
|
}
|
|
914
908
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
915
909
|
switch (props.format) {
|
|
916
|
-
case
|
|
910
|
+
case Format2.TypeFormat.Ref: {
|
|
917
911
|
if (!field.referencePath) {
|
|
918
912
|
return "";
|
|
919
913
|
}
|
|
@@ -971,7 +965,7 @@ var TableModel = class extends Resource2 {
|
|
|
971
965
|
const currentRow = this._rows.value[rowIdx];
|
|
972
966
|
invariant(currentRow, "Invalid row index", {
|
|
973
967
|
F: __dxlog_file,
|
|
974
|
-
L:
|
|
968
|
+
L: 516,
|
|
975
969
|
S: this,
|
|
976
970
|
A: [
|
|
977
971
|
"currentRow",
|
|
@@ -980,10 +974,10 @@ var TableModel = class extends Resource2 {
|
|
|
980
974
|
});
|
|
981
975
|
const snapshot = getSnapshot(currentRow);
|
|
982
976
|
setValue(snapshot, field.path, transformedValue);
|
|
983
|
-
const schema = getSchema(currentRow);
|
|
977
|
+
const schema = Obj2.getSchema(currentRow);
|
|
984
978
|
invariant(schema, void 0, {
|
|
985
979
|
F: __dxlog_file,
|
|
986
|
-
L:
|
|
980
|
+
L: 522,
|
|
987
981
|
S: this,
|
|
988
982
|
A: [
|
|
989
983
|
"schema",
|
|
@@ -995,7 +989,7 @@ var TableModel = class extends Resource2 {
|
|
|
995
989
|
const error = validationResult[0];
|
|
996
990
|
invariant(error.path === field.path, void 0, {
|
|
997
991
|
F: __dxlog_file,
|
|
998
|
-
L:
|
|
992
|
+
L: 527,
|
|
999
993
|
S: this,
|
|
1000
994
|
A: [
|
|
1001
995
|
"error.path === field.path",
|
|
@@ -1021,7 +1015,7 @@ var TableModel = class extends Resource2 {
|
|
|
1021
1015
|
const field = fields[col];
|
|
1022
1016
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
1023
1017
|
const transformedValue = editorTextToCellValue(props, value);
|
|
1024
|
-
if (props.format ===
|
|
1018
|
+
if (props.format === Format2.TypeFormat.Ref && !isLiveObject(value)) {
|
|
1025
1019
|
return;
|
|
1026
1020
|
}
|
|
1027
1021
|
if (plane === "frozenRowsEnd") {
|
|
@@ -1117,14 +1111,14 @@ var TableModel = class extends Resource2 {
|
|
|
1117
1111
|
};
|
|
1118
1112
|
var editorTextToCellValue = (props, value) => {
|
|
1119
1113
|
switch (props.format) {
|
|
1120
|
-
case
|
|
1114
|
+
case Format2.TypeFormat.Ref: {
|
|
1121
1115
|
if (isLiveObject(value)) {
|
|
1122
|
-
return
|
|
1116
|
+
return Ref2.make(value);
|
|
1123
1117
|
} else {
|
|
1124
1118
|
return value;
|
|
1125
1119
|
}
|
|
1126
1120
|
}
|
|
1127
|
-
case
|
|
1121
|
+
case Format2.TypeFormat.SingleSelect: {
|
|
1128
1122
|
const ids = extractTagIds(value);
|
|
1129
1123
|
if (ids && ids.length > 0) {
|
|
1130
1124
|
return ids[0];
|
|
@@ -1132,7 +1126,7 @@ var editorTextToCellValue = (props, value) => {
|
|
|
1132
1126
|
return value;
|
|
1133
1127
|
}
|
|
1134
1128
|
}
|
|
1135
|
-
case
|
|
1129
|
+
case Format2.TypeFormat.MultiSelect: {
|
|
1136
1130
|
const ids = extractTagIds(value);
|
|
1137
1131
|
return ids || value;
|
|
1138
1132
|
}
|
|
@@ -1216,7 +1210,7 @@ var ModalController = class {
|
|
|
1216
1210
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1217
1211
|
import * as Predicate from "effect/Predicate";
|
|
1218
1212
|
import { Obj as Obj3 } from "@dxos/echo";
|
|
1219
|
-
import {
|
|
1213
|
+
import { Format as Format3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
|
|
1220
1214
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1221
1215
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1222
1216
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -1303,12 +1297,12 @@ var TablePresentation = class {
|
|
|
1303
1297
|
return "";
|
|
1304
1298
|
}
|
|
1305
1299
|
switch (props.format) {
|
|
1306
|
-
case
|
|
1307
|
-
case
|
|
1308
|
-
case
|
|
1300
|
+
case Format3.TypeFormat.Boolean:
|
|
1301
|
+
case Format3.TypeFormat.SingleSelect:
|
|
1302
|
+
case Format3.TypeFormat.MultiSelect: {
|
|
1309
1303
|
return "";
|
|
1310
1304
|
}
|
|
1311
|
-
case
|
|
1305
|
+
case Format3.TypeFormat.Ref: {
|
|
1312
1306
|
if (!field.referencePath) {
|
|
1313
1307
|
return "";
|
|
1314
1308
|
}
|
|
@@ -1361,14 +1355,14 @@ var TablePresentation = class {
|
|
|
1361
1355
|
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
1362
1356
|
}
|
|
1363
1357
|
}
|
|
1364
|
-
if (props.format ===
|
|
1358
|
+
if (props.format === Format3.TypeFormat.Ref && props.referenceSchema) {
|
|
1365
1359
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1366
1360
|
if (targetObj) {
|
|
1367
1361
|
const dxn = Obj3.getDXN(targetObj)?.toString();
|
|
1368
1362
|
cell.accessoryHtml = `<div role="none" class="absolute inline-end-0 inset-block-0 p-[--dx-grid-cell-content-padding-block]"><dx-anchor refId=${dxn} class="dx-button is-6 aspect-square min-bs-0" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-anchor></div>`;
|
|
1369
1363
|
}
|
|
1370
1364
|
}
|
|
1371
|
-
if (props.format ===
|
|
1365
|
+
if (props.format === Format3.TypeFormat.Boolean) {
|
|
1372
1366
|
const value = getValue3(obj, field.path);
|
|
1373
1367
|
cell.accessoryHtml = tableControls.switch.render({
|
|
1374
1368
|
colIndex,
|
|
@@ -1377,7 +1371,7 @@ var TablePresentation = class {
|
|
|
1377
1371
|
});
|
|
1378
1372
|
cell.readonly = "no-text-select";
|
|
1379
1373
|
}
|
|
1380
|
-
if (props.format ===
|
|
1374
|
+
if (props.format === Format3.TypeFormat.SingleSelect) {
|
|
1381
1375
|
const value = getValue3(obj, field.path);
|
|
1382
1376
|
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1383
1377
|
if (options) {
|
|
@@ -1387,7 +1381,7 @@ var TablePresentation = class {
|
|
|
1387
1381
|
}
|
|
1388
1382
|
}
|
|
1389
1383
|
}
|
|
1390
|
-
if (props.format ===
|
|
1384
|
+
if (props.format === Format3.TypeFormat.MultiSelect) {
|
|
1391
1385
|
const values = getValue3(obj, field.path);
|
|
1392
1386
|
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1393
1387
|
if (options && values && values.length > 0) {
|
|
@@ -1646,31 +1640,65 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
|
1646
1640
|
}
|
|
1647
1641
|
};
|
|
1648
1642
|
|
|
1643
|
+
// src/hooks/useAddRow.ts
|
|
1644
|
+
import { useCallback } from "react";
|
|
1645
|
+
import { Obj as Obj4 } from "@dxos/echo";
|
|
1646
|
+
var useAddRow = ({ space, schema }) => {
|
|
1647
|
+
return useCallback((data) => {
|
|
1648
|
+
if (space && schema) {
|
|
1649
|
+
try {
|
|
1650
|
+
space.db.add(Obj4.make(schema, data ?? {}));
|
|
1651
|
+
return "final";
|
|
1652
|
+
} catch (error) {
|
|
1653
|
+
return "draft";
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
return "final";
|
|
1657
|
+
}, [
|
|
1658
|
+
space,
|
|
1659
|
+
schema
|
|
1660
|
+
]);
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1663
|
+
// src/hooks/useProjectionModel.ts
|
|
1664
|
+
import { useMemo } from "react";
|
|
1665
|
+
import { Type as Type2 } from "@dxos/echo";
|
|
1666
|
+
import { ProjectionModel as ProjectionModel2 } from "@dxos/schema";
|
|
1667
|
+
var useProjectionModel = (schema, table) => useMemo(() => {
|
|
1668
|
+
if (schema && table?.view.target?.projection) {
|
|
1669
|
+
const projection = new ProjectionModel2(Type2.toJsonSchema(schema), table.view.target.projection);
|
|
1670
|
+
projection.normalizeView();
|
|
1671
|
+
return projection;
|
|
1672
|
+
}
|
|
1673
|
+
}, [
|
|
1674
|
+
schema,
|
|
1675
|
+
table?.view.target?.projection
|
|
1676
|
+
]);
|
|
1677
|
+
|
|
1649
1678
|
// src/hooks/useTableModel.ts
|
|
1650
1679
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
1651
1680
|
import { effect as effect3 } from "@preact/signals-core";
|
|
1652
1681
|
import orderBy2 from "lodash.orderby";
|
|
1653
|
-
import { useEffect, useMemo, useState } from "react";
|
|
1654
|
-
import { Obj as
|
|
1682
|
+
import { useEffect, useMemo as useMemo2, useState } from "react";
|
|
1683
|
+
import { Obj as Obj5 } from "@dxos/echo";
|
|
1655
1684
|
import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
|
|
1656
1685
|
import { isNonNullable } from "@dxos/util";
|
|
1657
|
-
var useTableModel = ({
|
|
1686
|
+
var useTableModel = ({ object, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
1658
1687
|
var _effect = _useSignals();
|
|
1659
1688
|
try {
|
|
1660
|
-
const selected = useSelected(
|
|
1661
|
-
const initialSelection =
|
|
1662
|
-
|
|
1689
|
+
const selected = useSelected(object && Obj5.getDXN(object).toString(), "multi");
|
|
1690
|
+
const initialSelection = useMemo2(() => selected, [
|
|
1691
|
+
object
|
|
1663
1692
|
]);
|
|
1664
1693
|
const [model, setModel] = useState();
|
|
1665
1694
|
useEffect(() => {
|
|
1666
|
-
if (!
|
|
1695
|
+
if (!object || !projection) {
|
|
1667
1696
|
return;
|
|
1668
1697
|
}
|
|
1669
1698
|
let model2;
|
|
1670
1699
|
const t = setTimeout(async () => {
|
|
1671
1700
|
model2 = new TableModel({
|
|
1672
|
-
|
|
1673
|
-
schema,
|
|
1701
|
+
object,
|
|
1674
1702
|
projection,
|
|
1675
1703
|
features,
|
|
1676
1704
|
rowActions,
|
|
@@ -1686,8 +1714,7 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
|
|
|
1686
1714
|
void model2?.close();
|
|
1687
1715
|
};
|
|
1688
1716
|
}, [
|
|
1689
|
-
|
|
1690
|
-
schema,
|
|
1717
|
+
object,
|
|
1691
1718
|
projection,
|
|
1692
1719
|
features,
|
|
1693
1720
|
rowActions,
|
|
@@ -1734,26 +1761,6 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
|
|
|
1734
1761
|
}
|
|
1735
1762
|
};
|
|
1736
1763
|
|
|
1737
|
-
// src/hooks/useAddRow.ts
|
|
1738
|
-
import { useCallback } from "react";
|
|
1739
|
-
import { Obj as Obj5 } from "@dxos/echo";
|
|
1740
|
-
var useAddRow = ({ space, schema }) => {
|
|
1741
|
-
return useCallback((data) => {
|
|
1742
|
-
if (space && schema) {
|
|
1743
|
-
try {
|
|
1744
|
-
space.db.add(Obj5.make(schema, data ?? {}));
|
|
1745
|
-
return "final";
|
|
1746
|
-
} catch (error) {
|
|
1747
|
-
return "draft";
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
return "final";
|
|
1751
|
-
}, [
|
|
1752
|
-
space,
|
|
1753
|
-
schema
|
|
1754
|
-
]);
|
|
1755
|
-
};
|
|
1756
|
-
|
|
1757
1764
|
export {
|
|
1758
1765
|
getBaseSchema,
|
|
1759
1766
|
makeDynamicTable,
|
|
@@ -1769,7 +1776,8 @@ export {
|
|
|
1769
1776
|
ModalController,
|
|
1770
1777
|
TablePresentation,
|
|
1771
1778
|
cellClassesForRowSelection,
|
|
1772
|
-
|
|
1773
|
-
|
|
1779
|
+
useAddRow,
|
|
1780
|
+
useProjectionModel,
|
|
1781
|
+
useTableModel
|
|
1774
1782
|
};
|
|
1775
|
-
//# sourceMappingURL=chunk-
|
|
1783
|
+
//# sourceMappingURL=chunk-KNC7XYT6.mjs.map
|