@dxos/react-ui-table 0.8.2-main.2f9c567 → 0.8.2-main.36232bc
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-YWNRUF4J.mjs +26 -0
- package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +107 -40
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{chunk-2QLLIPZK.cjs → chunk-TGG6OZ54.cjs} +11 -13
- package/dist/lib/node/chunk-TGG6OZ54.cjs.map +7 -0
- package/dist/lib/node/index.cjs +173 -108
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +3 -3
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{chunk-N2RRVR7F.mjs → chunk-KKLP54L3.mjs} +9 -11
- package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +107 -40
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RefPanel.d.ts +9 -0
- package/dist/types/src/components/Table/RefPanel.d.ts.map +1 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +39 -39
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +43 -43
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/table-buttons.d.ts +14 -0
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts +2 -2
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/package.json +33 -35
- package/src/components/Table/CreateRefPanel.tsx +3 -3
- package/src/components/Table/RefPanel.tsx +52 -0
- package/src/components/Table/Table.stories.tsx +2 -1
- package/src/components/Table/Table.tsx +6 -0
- package/src/components/Table/relations.stories.tsx +9 -10
- package/src/components/testing.ts +6 -7
- package/src/model/table-model.test.ts +3 -4
- package/src/model/table-presentation.test.ts +3 -4
- package/src/model/table-presentation.ts +5 -3
- package/src/types/table.ts +8 -16
- package/src/util/table-buttons.ts +23 -0
- package/src/util/table.ts +7 -7
- package/dist/lib/browser/chunk-UGGYKLOH.mjs +0 -28
- package/dist/lib/browser/chunk-UGGYKLOH.mjs.map +0 -7
- package/dist/lib/node/chunk-2QLLIPZK.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-N2RRVR7F.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -37,9 +37,9 @@ __export(node_exports, {
|
|
|
37
37
|
Table: () => Table,
|
|
38
38
|
TableModel: () => TableModel,
|
|
39
39
|
TablePresentation: () => TablePresentation,
|
|
40
|
-
TableSchema: () =>
|
|
40
|
+
TableSchema: () => import_chunk_TGG6OZ54.TableSchema,
|
|
41
41
|
TableToolbar: () => TableToolbar,
|
|
42
|
-
TableType: () =>
|
|
42
|
+
TableType: () => import_chunk_TGG6OZ54.TableType,
|
|
43
43
|
cellClassesForRowSelection: () => cellClassesForRowSelection,
|
|
44
44
|
getBaseSchems: () => getBaseSchems,
|
|
45
45
|
initializeTable: () => initializeTable,
|
|
@@ -51,7 +51,7 @@ __export(node_exports, {
|
|
|
51
51
|
useTableModel: () => useTableModel
|
|
52
52
|
});
|
|
53
53
|
module.exports = __toCommonJS(node_exports);
|
|
54
|
-
var
|
|
54
|
+
var import_chunk_TGG6OZ54 = require("./chunk-TGG6OZ54.cjs");
|
|
55
55
|
var import_react = __toESM(require("react"));
|
|
56
56
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
57
57
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -66,59 +66,61 @@ var import_react_ui2 = require("@dxos/react-ui");
|
|
|
66
66
|
var import_react3 = __toESM(require("react"));
|
|
67
67
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
68
68
|
var import_react_ui_form = require("@dxos/react-ui-form");
|
|
69
|
-
var import_effect = require("effect");
|
|
70
69
|
var import_react4 = __toESM(require("react"));
|
|
70
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
71
71
|
var import_echo2 = require("@dxos/react-client/echo");
|
|
72
72
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
73
73
|
var import_react_ui_form2 = require("@dxos/react-ui-form");
|
|
74
74
|
var import_react_ui_grid2 = require("@dxos/react-ui-grid");
|
|
75
75
|
var import_react5 = __toESM(require("react"));
|
|
76
76
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
77
|
+
var import_react_ui_form3 = require("@dxos/react-ui-form");
|
|
78
|
+
var import_react6 = __toESM(require("react"));
|
|
79
|
+
var import_react_ui6 = require("@dxos/react-ui");
|
|
77
80
|
var import_signals_core = require("@preact/signals-core");
|
|
78
81
|
var import_context = require("@dxos/context");
|
|
79
|
-
var
|
|
82
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
80
83
|
var import_invariant2 = require("@dxos/invariant");
|
|
81
84
|
var import_live_object = require("@dxos/live-object");
|
|
82
|
-
var
|
|
85
|
+
var import_react_ui_form4 = require("@dxos/react-ui-form");
|
|
83
86
|
var import_signals_core2 = require("@preact/signals-core");
|
|
84
87
|
var import_context2 = require("@dxos/context");
|
|
85
88
|
var import_live_object2 = require("@dxos/live-object");
|
|
86
89
|
var import_schema = require("@dxos/schema");
|
|
87
|
-
var
|
|
88
|
-
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
90
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
89
91
|
var import_react_client = require("@dxos/react-client");
|
|
90
92
|
var import_echo3 = require("@dxos/react-client/echo");
|
|
91
93
|
var import_schema2 = require("@dxos/schema");
|
|
92
94
|
var import_signals_core3 = require("@preact/signals-core");
|
|
93
95
|
var import_lodash = __toESM(require("lodash.orderby"));
|
|
94
|
-
var
|
|
95
|
-
var
|
|
96
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
97
|
+
var import_react_ui_form5 = require("@dxos/react-ui-form");
|
|
96
98
|
var import_signals_core4 = require("@preact/signals-core");
|
|
97
99
|
var import_log = require("@dxos/log");
|
|
98
100
|
var import_signals_core5 = require("@preact/signals-core");
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
102
|
+
var import_react_ui_form6 = require("@dxos/react-ui-form");
|
|
101
103
|
var import_react_ui_grid3 = require("@dxos/react-ui-grid");
|
|
102
104
|
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
103
105
|
var import_schema3 = require("@dxos/schema");
|
|
104
|
-
var
|
|
105
|
-
var
|
|
106
|
+
var import_react7 = __toESM(require("react"));
|
|
107
|
+
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
106
108
|
var import_invariant3 = require("@dxos/invariant");
|
|
107
|
-
var
|
|
109
|
+
var import_react_ui7 = require("@dxos/react-ui");
|
|
108
110
|
var import_react_ui_editor = require("@dxos/react-ui-editor");
|
|
109
111
|
var import_react_ui_grid4 = require("@dxos/react-ui-grid");
|
|
110
112
|
var import_react_ui_tag_picker = require("@dxos/react-ui-tag-picker");
|
|
111
113
|
var import_autocomplete = require("@codemirror/autocomplete");
|
|
112
114
|
var import_view = require("@codemirror/view");
|
|
113
|
-
var
|
|
114
|
-
var
|
|
115
|
+
var import_react8 = __toESM(require("react"));
|
|
116
|
+
var import_react_ui8 = require("@dxos/react-ui");
|
|
115
117
|
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
116
118
|
var import_signals_core6 = require("@preact/signals-core");
|
|
117
|
-
var
|
|
119
|
+
var import_react9 = require("react");
|
|
118
120
|
var import_echo4 = require("@dxos/react-client/echo");
|
|
119
121
|
var import_react_ui_attention2 = require("@dxos/react-ui-attention");
|
|
120
122
|
var import_util2 = require("@dxos/util");
|
|
121
|
-
var
|
|
123
|
+
var import_react10 = __toESM(require("react"));
|
|
122
124
|
var import_live_object3 = require("@dxos/live-object");
|
|
123
125
|
var import_react_ui_menu = require("@dxos/react-ui-menu");
|
|
124
126
|
var translationKey = "table";
|
|
@@ -257,7 +259,7 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
257
259
|
typename: state.typename
|
|
258
260
|
}).runSync();
|
|
259
261
|
if (schema2) {
|
|
260
|
-
const omit =
|
|
262
|
+
const omit = import_echo_schema2.S.omit("id");
|
|
261
263
|
return omit(schema2);
|
|
262
264
|
}
|
|
263
265
|
}, [
|
|
@@ -311,30 +313,63 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
311
313
|
onCancel: handleCancel
|
|
312
314
|
}), /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Popover.Arrow, null))));
|
|
313
315
|
};
|
|
316
|
+
var getRefTargetObj = (space, id) => {
|
|
317
|
+
if (space && id) {
|
|
318
|
+
return space?.db.getObjectById(id);
|
|
319
|
+
} else {
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
var RefPanel = ({ model, modals }) => {
|
|
324
|
+
const state = modals.state.value;
|
|
325
|
+
const space = model?.space;
|
|
326
|
+
const targetObj = getRefTargetObj(space, state?.type === "refPanel" ? state.targetId : void 0);
|
|
327
|
+
const schema = space && state?.type === "refPanel" ? space.db.schemaRegistry.getSchema(state.typename) : void 0;
|
|
328
|
+
if (!model.view || !model.projection) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Popover.Root, {
|
|
332
|
+
modal: false,
|
|
333
|
+
open: state?.type === "refPanel" && !!targetObj && !!schema,
|
|
334
|
+
onOpenChange: (nextOpen) => {
|
|
335
|
+
if (!nextOpen) {
|
|
336
|
+
return modals.close();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Popover.VirtualTrigger, {
|
|
340
|
+
virtualRef: modals.trigger
|
|
341
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Popover.Portal, null, /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Popover.Content, {
|
|
342
|
+
classNames: "md:is-64"
|
|
343
|
+
}, targetObj && schema && /* @__PURE__ */ import_react5.default.createElement(import_react_ui_form3.Form, {
|
|
344
|
+
readonly: true,
|
|
345
|
+
values: targetObj,
|
|
346
|
+
schema
|
|
347
|
+
}), /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Popover.Arrow, null))));
|
|
348
|
+
};
|
|
314
349
|
var RowActionsMenu = ({ model, modals }) => {
|
|
315
|
-
const { t } = (0,
|
|
350
|
+
const { t } = (0, import_react_ui6.useTranslation)(translationKey);
|
|
316
351
|
const hasSelection = model.selection.hasSelection.value;
|
|
317
352
|
const state = modals.state.value;
|
|
318
353
|
if (state?.type !== "row") {
|
|
319
354
|
return null;
|
|
320
355
|
}
|
|
321
|
-
return /* @__PURE__ */
|
|
356
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Root, {
|
|
322
357
|
modal: false,
|
|
323
358
|
open: true,
|
|
324
359
|
onOpenChange: modals.close
|
|
325
|
-
}, /* @__PURE__ */
|
|
360
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.VirtualTrigger, {
|
|
326
361
|
virtualRef: modals.trigger
|
|
327
|
-
}), /* @__PURE__ */
|
|
362
|
+
}), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Item, {
|
|
328
363
|
"data-testid": "row-menu-delete",
|
|
329
364
|
onClick: () => model.deleteRow(state.rowIndex)
|
|
330
|
-
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */
|
|
365
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Item, {
|
|
331
366
|
key: action.id,
|
|
332
367
|
"data-testid": `row-action-${action.id}`,
|
|
333
368
|
onClick: () => {
|
|
334
369
|
modals.close();
|
|
335
370
|
model.handleRowAction(action.id, state.rowIndex);
|
|
336
371
|
}
|
|
337
|
-
}, t(action.translationKey)))), /* @__PURE__ */
|
|
372
|
+
}, t(action.translationKey)))), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Arrow, null)));
|
|
338
373
|
};
|
|
339
374
|
var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
|
|
340
375
|
if (typename && properties) {
|
|
@@ -366,7 +401,7 @@ var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
|
|
|
366
401
|
fields: properties.map((property) => property.name)
|
|
367
402
|
}
|
|
368
403
|
});
|
|
369
|
-
const table = (0, import_live_object2.live)(
|
|
404
|
+
const table = (0, import_live_object2.live)(import_chunk_TGG6OZ54.TableType, {
|
|
370
405
|
name: "dynamic-table",
|
|
371
406
|
view: (0, import_live_object2.makeRef)(view)
|
|
372
407
|
});
|
|
@@ -442,17 +477,17 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
|
|
|
442
477
|
return schema;
|
|
443
478
|
}
|
|
444
479
|
};
|
|
445
|
-
var ContactSchema = (0,
|
|
480
|
+
var ContactSchema = (0, import_echo_schema4.TypedObject)({
|
|
446
481
|
typename: `example.com/type/${import_react_client.PublicKey.random().truncate()}`,
|
|
447
482
|
version: "0.1.0"
|
|
448
483
|
})({
|
|
449
|
-
name:
|
|
450
|
-
[
|
|
484
|
+
name: import_echo_schema4.S.optional(import_echo_schema4.S.String).annotations({
|
|
485
|
+
[import_echo_schema4.AST.TitleAnnotationId]: "Name"
|
|
451
486
|
}),
|
|
452
|
-
active:
|
|
453
|
-
email:
|
|
454
|
-
salary:
|
|
455
|
-
[
|
|
487
|
+
active: import_echo_schema4.S.optional(import_echo_schema4.S.Boolean),
|
|
488
|
+
email: import_echo_schema4.S.optional(import_echo_schema4.Format.Email),
|
|
489
|
+
salary: import_echo_schema4.S.optional(import_echo_schema4.Format.Currency()).annotations({
|
|
490
|
+
[import_echo_schema4.AST.TitleAnnotationId]: "Salary"
|
|
456
491
|
})
|
|
457
492
|
});
|
|
458
493
|
var ContactFields = [
|
|
@@ -485,8 +520,8 @@ var createProjection = (schema, view) => {
|
|
|
485
520
|
},
|
|
486
521
|
props: {
|
|
487
522
|
property: "manager",
|
|
488
|
-
type:
|
|
489
|
-
format:
|
|
523
|
+
type: import_echo_schema4.TypeEnum.Ref,
|
|
524
|
+
format: import_echo_schema4.FormatEnum.Ref,
|
|
490
525
|
referenceSchema: schema.typename,
|
|
491
526
|
title: "Manager"
|
|
492
527
|
}
|
|
@@ -539,6 +574,26 @@ var columnSettingsButton = {
|
|
|
539
574
|
fieldId: el.getAttribute("data-field-id")
|
|
540
575
|
})
|
|
541
576
|
};
|
|
577
|
+
var referencedCellButton = {
|
|
578
|
+
attr: BUTTON_IDENTIFIERS.referencedCell,
|
|
579
|
+
icon: "ph--link-simple-horizontal--regular",
|
|
580
|
+
render: ({ targetId, schemaId }) => {
|
|
581
|
+
return createButton({
|
|
582
|
+
attr: BUTTON_IDENTIFIERS.referencedCell,
|
|
583
|
+
icon: referencedCellButton.icon,
|
|
584
|
+
data: {
|
|
585
|
+
"data-target-id": targetId,
|
|
586
|
+
"data-schema-id": schemaId
|
|
587
|
+
},
|
|
588
|
+
testId: "table-ref-cell-button"
|
|
589
|
+
});
|
|
590
|
+
},
|
|
591
|
+
getData: (el) => ({
|
|
592
|
+
type: "referencedCell",
|
|
593
|
+
targetId: el.getAttribute("data-target-id"),
|
|
594
|
+
schemaId: el.getAttribute("data-schema-id")
|
|
595
|
+
})
|
|
596
|
+
};
|
|
542
597
|
var rowMenuButton = {
|
|
543
598
|
attr: BUTTON_IDENTIFIERS.rowMenu,
|
|
544
599
|
icon: "ph--dots-three--regular",
|
|
@@ -583,6 +638,7 @@ var sortButton = {
|
|
|
583
638
|
var tableButtons = {
|
|
584
639
|
addColumn: addColumnButton,
|
|
585
640
|
columnSettings: columnSettingsButton,
|
|
641
|
+
referencedCell: referencedCellButton,
|
|
586
642
|
rowMenu: rowMenuButton,
|
|
587
643
|
sort: sortButton
|
|
588
644
|
};
|
|
@@ -828,7 +884,7 @@ var TableSorting = class {
|
|
|
828
884
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
829
885
|
const dataWithIndices = this._rows.value.map((item, index) => {
|
|
830
886
|
const sortValue = this.getSortValue(props, field, item);
|
|
831
|
-
const isEmpty = !(props.type ===
|
|
887
|
+
const isEmpty = !(props.type === import_echo_schema5.TypeEnum.Boolean) && (sortValue == null || sortValue === "");
|
|
832
888
|
return {
|
|
833
889
|
item,
|
|
834
890
|
index,
|
|
@@ -853,17 +909,17 @@ var TableSorting = class {
|
|
|
853
909
|
}
|
|
854
910
|
getSortValue(props, field, item) {
|
|
855
911
|
const { type, format } = props;
|
|
856
|
-
const value = (0,
|
|
857
|
-
if (type ===
|
|
912
|
+
const value = (0, import_echo_schema5.getValue)(item, field.path);
|
|
913
|
+
if (type === import_echo_schema5.TypeEnum.Boolean) {
|
|
858
914
|
return !!value;
|
|
859
915
|
}
|
|
860
|
-
if (type ===
|
|
916
|
+
if (type === import_echo_schema5.TypeEnum.Number) {
|
|
861
917
|
return value;
|
|
862
918
|
}
|
|
863
919
|
if (value == null) {
|
|
864
920
|
return value;
|
|
865
921
|
}
|
|
866
|
-
if (format ===
|
|
922
|
+
if (format === import_echo_schema5.FormatEnum.SingleSelect) {
|
|
867
923
|
const options = props.options;
|
|
868
924
|
if (!options) {
|
|
869
925
|
return void 0;
|
|
@@ -871,11 +927,11 @@ var TableSorting = class {
|
|
|
871
927
|
const option = options.find((option2) => option2.id === value);
|
|
872
928
|
return option ? options.indexOf(option) : void 0;
|
|
873
929
|
}
|
|
874
|
-
if (format ===
|
|
875
|
-
const refValue = (0,
|
|
930
|
+
if (format === import_echo_schema5.FormatEnum.Ref && field.referencePath) {
|
|
931
|
+
const refValue = (0, import_echo_schema5.getValue)(value.target, field.referencePath);
|
|
876
932
|
return refValue;
|
|
877
933
|
}
|
|
878
|
-
return (0,
|
|
934
|
+
return (0, import_react_ui_form5.formatForDisplay)({
|
|
879
935
|
type,
|
|
880
936
|
format,
|
|
881
937
|
value
|
|
@@ -960,20 +1016,20 @@ var TableModel = class extends import_context.Resource {
|
|
|
960
1016
|
}
|
|
961
1017
|
const field = fields[col];
|
|
962
1018
|
const dataIndex = this._sorting.getDataIndex(row);
|
|
963
|
-
const value = (0,
|
|
1019
|
+
const value = (0, import_echo_schema3.getValue)(this._rows.value[dataIndex], field.path);
|
|
964
1020
|
if (value == null) {
|
|
965
1021
|
return "";
|
|
966
1022
|
}
|
|
967
1023
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
968
1024
|
switch (props.format) {
|
|
969
|
-
case
|
|
1025
|
+
case import_echo_schema3.FormatEnum.Ref: {
|
|
970
1026
|
if (!field.referencePath) {
|
|
971
1027
|
return "";
|
|
972
1028
|
}
|
|
973
|
-
return (0,
|
|
1029
|
+
return (0, import_echo_schema3.getValue)(value.target, field.referencePath);
|
|
974
1030
|
}
|
|
975
1031
|
default: {
|
|
976
|
-
return (0,
|
|
1032
|
+
return (0, import_react_ui_form4.formatForEditing)({
|
|
977
1033
|
type: props.type,
|
|
978
1034
|
format: props.format,
|
|
979
1035
|
value
|
|
@@ -990,28 +1046,28 @@ var TableModel = class extends import_context.Resource {
|
|
|
990
1046
|
const field = fields[col];
|
|
991
1047
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
992
1048
|
switch (props.format) {
|
|
993
|
-
case
|
|
1049
|
+
case import_echo_schema3.FormatEnum.Ref: {
|
|
994
1050
|
if ((0, import_live_object.isLiveObject)(value)) {
|
|
995
|
-
(0,
|
|
1051
|
+
(0, import_echo_schema3.setValue)(this._rows.value[rowIdx], field.path, (0, import_live_object.makeRef)(value));
|
|
996
1052
|
}
|
|
997
1053
|
break;
|
|
998
1054
|
}
|
|
999
|
-
case
|
|
1055
|
+
case import_echo_schema3.FormatEnum.SingleSelect: {
|
|
1000
1056
|
const ids = extractTagIds(value);
|
|
1001
1057
|
if (ids && ids.length > 0) {
|
|
1002
|
-
(0,
|
|
1058
|
+
(0, import_echo_schema3.setValue)(this._rows.value[rowIdx], field.path, ids[0]);
|
|
1003
1059
|
}
|
|
1004
1060
|
break;
|
|
1005
1061
|
}
|
|
1006
|
-
case
|
|
1062
|
+
case import_echo_schema3.FormatEnum.MultiSelect: {
|
|
1007
1063
|
const ids = extractTagIds(value);
|
|
1008
1064
|
if (ids) {
|
|
1009
|
-
(0,
|
|
1065
|
+
(0, import_echo_schema3.setValue)(this._rows.value[rowIdx], field.path, ids);
|
|
1010
1066
|
}
|
|
1011
1067
|
break;
|
|
1012
1068
|
}
|
|
1013
1069
|
default: {
|
|
1014
|
-
(0,
|
|
1070
|
+
(0, import_echo_schema3.setValue)(this._rows.value[rowIdx], field.path, (0, import_react_ui_form4.parseValue)({
|
|
1015
1071
|
type: props.type,
|
|
1016
1072
|
format: props.format,
|
|
1017
1073
|
value
|
|
@@ -1157,7 +1213,7 @@ var TableModel = class extends import_context.Resource {
|
|
|
1157
1213
|
for (let row = start.row; row <= end.row; row++) {
|
|
1158
1214
|
rowEffects.push((0, import_signals_core.effect)(() => {
|
|
1159
1215
|
const obj = this._sorting.sortedRows.value[row];
|
|
1160
|
-
this._view?.fields.forEach((field) => touch((0,
|
|
1216
|
+
this._view?.fields.forEach((field) => touch((0, import_echo_schema3.getValue)(obj, field.path)));
|
|
1161
1217
|
this._onCellUpdate?.({
|
|
1162
1218
|
row,
|
|
1163
1219
|
col: start.col,
|
|
@@ -1178,9 +1234,9 @@ var TableModel = class extends import_context.Resource {
|
|
|
1178
1234
|
const dataRow = this._sorting.getDataIndex(row);
|
|
1179
1235
|
const fields = this._view?.fields ?? [];
|
|
1180
1236
|
const field = fields[col];
|
|
1181
|
-
const value = (0,
|
|
1237
|
+
const value = (0, import_echo_schema3.getValue)(this._rows.value[dataRow], field.path);
|
|
1182
1238
|
const updatedValue = update(value);
|
|
1183
|
-
(0,
|
|
1239
|
+
(0, import_echo_schema3.setValue)(this._rows.value[dataRow], field.path, updatedValue);
|
|
1184
1240
|
}
|
|
1185
1241
|
//
|
|
1186
1242
|
// Column Operations
|
|
@@ -1362,24 +1418,24 @@ var TablePresentation = class {
|
|
|
1362
1418
|
const { props } = this.model.projection.getFieldProjection(field.id);
|
|
1363
1419
|
const cell = {
|
|
1364
1420
|
get value() {
|
|
1365
|
-
const value = (0,
|
|
1421
|
+
const value = (0, import_echo_schema6.getValue)(obj, field.path);
|
|
1366
1422
|
if (value == null) {
|
|
1367
1423
|
return "";
|
|
1368
1424
|
}
|
|
1369
1425
|
switch (props.format) {
|
|
1370
|
-
case
|
|
1371
|
-
case
|
|
1372
|
-
case
|
|
1426
|
+
case import_echo_schema6.FormatEnum.Boolean:
|
|
1427
|
+
case import_echo_schema6.FormatEnum.SingleSelect:
|
|
1428
|
+
case import_echo_schema6.FormatEnum.MultiSelect: {
|
|
1373
1429
|
return "";
|
|
1374
1430
|
}
|
|
1375
|
-
case
|
|
1431
|
+
case import_echo_schema6.FormatEnum.Ref: {
|
|
1376
1432
|
if (!field.referencePath) {
|
|
1377
1433
|
return "";
|
|
1378
1434
|
}
|
|
1379
|
-
return (0,
|
|
1435
|
+
return (0, import_echo_schema6.getValue)(value.target, field.referencePath);
|
|
1380
1436
|
}
|
|
1381
1437
|
default: {
|
|
1382
|
-
return (0,
|
|
1438
|
+
return (0, import_react_ui_form6.formatForDisplay)({
|
|
1383
1439
|
type: props.type,
|
|
1384
1440
|
format: props.format,
|
|
1385
1441
|
value
|
|
@@ -1389,7 +1445,7 @@ var TablePresentation = class {
|
|
|
1389
1445
|
}
|
|
1390
1446
|
};
|
|
1391
1447
|
const classes = [];
|
|
1392
|
-
const formatClasses = (0,
|
|
1448
|
+
const formatClasses = (0, import_react_ui_form6.cellClassesForFieldType)({
|
|
1393
1449
|
type: props.type,
|
|
1394
1450
|
format: props.format
|
|
1395
1451
|
});
|
|
@@ -1403,15 +1459,17 @@ var TablePresentation = class {
|
|
|
1403
1459
|
if (classes.length > 0) {
|
|
1404
1460
|
cell.className = (0, import_react_ui_theme2.mx)(classes.flat());
|
|
1405
1461
|
}
|
|
1406
|
-
if (props.format ===
|
|
1407
|
-
const targetObj = (0,
|
|
1462
|
+
if (props.format === import_echo_schema6.FormatEnum.Ref && props.referenceSchema) {
|
|
1463
|
+
const targetObj = (0, import_echo_schema6.getValue)(obj, field.path)?.target;
|
|
1408
1464
|
if (targetObj) {
|
|
1409
|
-
|
|
1410
|
-
|
|
1465
|
+
cell.accessoryHtml = tableButtons.referencedCell.render({
|
|
1466
|
+
targetId: targetObj.id,
|
|
1467
|
+
schemaId: props.referenceSchema
|
|
1468
|
+
});
|
|
1411
1469
|
}
|
|
1412
1470
|
}
|
|
1413
|
-
if (props.format ===
|
|
1414
|
-
const value = (0,
|
|
1471
|
+
if (props.format === import_echo_schema6.FormatEnum.Boolean) {
|
|
1472
|
+
const value = (0, import_echo_schema6.getValue)(obj, field.path);
|
|
1415
1473
|
cell.accessoryHtml = tableControls.switch.render({
|
|
1416
1474
|
colIndex,
|
|
1417
1475
|
rowIndex: displayIndex,
|
|
@@ -1419,8 +1477,8 @@ var TablePresentation = class {
|
|
|
1419
1477
|
});
|
|
1420
1478
|
cell.readonly = "no-text-select";
|
|
1421
1479
|
}
|
|
1422
|
-
if (props.format ===
|
|
1423
|
-
const value = (0,
|
|
1480
|
+
if (props.format === import_echo_schema6.FormatEnum.SingleSelect) {
|
|
1481
|
+
const value = (0, import_echo_schema6.getValue)(obj, field.path);
|
|
1424
1482
|
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1425
1483
|
if (options) {
|
|
1426
1484
|
const option = options.find((o) => o.id === value);
|
|
@@ -1429,8 +1487,8 @@ var TablePresentation = class {
|
|
|
1429
1487
|
}
|
|
1430
1488
|
}
|
|
1431
1489
|
}
|
|
1432
|
-
if (props.format ===
|
|
1433
|
-
const values = (0,
|
|
1490
|
+
if (props.format === import_echo_schema6.FormatEnum.MultiSelect) {
|
|
1491
|
+
const values = (0, import_echo_schema6.getValue)(obj, field.path);
|
|
1434
1492
|
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1435
1493
|
if (options && values && values.length > 0) {
|
|
1436
1494
|
const tags = values.map((value) => {
|
|
@@ -1641,9 +1699,9 @@ var createOption = (text) => ({
|
|
|
1641
1699
|
var isCreateOption = (data) => typeof data === "object" && data[newValue];
|
|
1642
1700
|
var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
1643
1701
|
const { id: gridId, editing, setEditing } = (0, import_react_ui_grid4.useGridContext)("TableCellEditor", __gridScope);
|
|
1644
|
-
const suppressNextBlur = (0,
|
|
1645
|
-
const { themeMode } = (0,
|
|
1646
|
-
const fieldProjection = (0,
|
|
1702
|
+
const suppressNextBlur = (0, import_react7.useRef)(false);
|
|
1703
|
+
const { themeMode } = (0, import_react_ui7.useThemeContext)();
|
|
1704
|
+
const fieldProjection = (0, import_react7.useMemo)(() => {
|
|
1647
1705
|
if (!model || !editing) {
|
|
1648
1706
|
return;
|
|
1649
1707
|
}
|
|
@@ -1664,7 +1722,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1664
1722
|
model,
|
|
1665
1723
|
editing
|
|
1666
1724
|
]);
|
|
1667
|
-
const handleEnter = (0,
|
|
1725
|
+
const handleEnter = (0, import_react7.useCallback)((value) => {
|
|
1668
1726
|
if (!model || !editing) {
|
|
1669
1727
|
return;
|
|
1670
1728
|
}
|
|
@@ -1680,7 +1738,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1680
1738
|
onFocus,
|
|
1681
1739
|
setEditing
|
|
1682
1740
|
]);
|
|
1683
|
-
const handleBlur = (0,
|
|
1741
|
+
const handleBlur = (0, import_react7.useCallback)((value) => {
|
|
1684
1742
|
if (!model || !editing) {
|
|
1685
1743
|
return;
|
|
1686
1744
|
}
|
|
@@ -1696,7 +1754,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1696
1754
|
model,
|
|
1697
1755
|
editing
|
|
1698
1756
|
]);
|
|
1699
|
-
const handleClose = (0,
|
|
1757
|
+
const handleClose = (0, import_react7.useCallback)((value, event) => {
|
|
1700
1758
|
if (!model || !editing || !fieldProjection) {
|
|
1701
1759
|
return;
|
|
1702
1760
|
}
|
|
@@ -1712,7 +1770,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1712
1770
|
onEnter,
|
|
1713
1771
|
fieldProjection
|
|
1714
1772
|
]);
|
|
1715
|
-
const extension = (0,
|
|
1773
|
+
const extension = (0, import_react7.useMemo)(() => {
|
|
1716
1774
|
if (!fieldProjection) {
|
|
1717
1775
|
return [];
|
|
1718
1776
|
}
|
|
@@ -1725,12 +1783,12 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1725
1783
|
})
|
|
1726
1784
|
];
|
|
1727
1785
|
const format = fieldProjection.props.format;
|
|
1728
|
-
if (format ===
|
|
1786
|
+
if (format === import_echo_schema7.FormatEnum.SingleSelect || format === import_echo_schema7.FormatEnum.MultiSelect) {
|
|
1729
1787
|
extension2.push((0, import_react_ui_editor.createMarkdownExtensions)({
|
|
1730
1788
|
themeMode
|
|
1731
1789
|
}));
|
|
1732
1790
|
const options = fieldProjection.props.options || [];
|
|
1733
|
-
const mode = format ===
|
|
1791
|
+
const mode = format === import_echo_schema7.FormatEnum.SingleSelect ? "single-select" : "multi-select";
|
|
1734
1792
|
extension2.push((0, import_react_ui_tag_picker.tagPickerExtension)({
|
|
1735
1793
|
mode,
|
|
1736
1794
|
inGrid: true,
|
|
@@ -1757,7 +1815,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1757
1815
|
}
|
|
1758
1816
|
if (onQuery) {
|
|
1759
1817
|
switch (fieldProjection.props.format) {
|
|
1760
|
-
case
|
|
1818
|
+
case import_echo_schema7.FormatEnum.Ref: {
|
|
1761
1819
|
extension2.push([
|
|
1762
1820
|
completion({
|
|
1763
1821
|
onQuery: (text) => onQuery(fieldProjection, text),
|
|
@@ -1793,17 +1851,17 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1793
1851
|
handleClose,
|
|
1794
1852
|
themeMode
|
|
1795
1853
|
]);
|
|
1796
|
-
const getCellContent = (0,
|
|
1854
|
+
const getCellContent = (0, import_react7.useCallback)(() => {
|
|
1797
1855
|
if (model && editing) {
|
|
1798
1856
|
const cell = (0, import_react_ui_grid4.parseCellIndex)(editing.index);
|
|
1799
1857
|
const { col } = cell;
|
|
1800
1858
|
const field = model.projection.view.fields[col];
|
|
1801
1859
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1802
|
-
if (fieldProjection2?.props.format ===
|
|
1860
|
+
if (fieldProjection2?.props.format === import_echo_schema7.FormatEnum.SingleSelect || fieldProjection2?.props.format === import_echo_schema7.FormatEnum.MultiSelect) {
|
|
1803
1861
|
const value2 = model.getCellData(cell);
|
|
1804
1862
|
if (value2 !== void 0) {
|
|
1805
1863
|
const options = fieldProjection2.props.options || [];
|
|
1806
|
-
if (fieldProjection2.props.format ===
|
|
1864
|
+
if (fieldProjection2.props.format === import_echo_schema7.FormatEnum.MultiSelect && Array.isArray(value2)) {
|
|
1807
1865
|
const tagItems = value2.map((id) => {
|
|
1808
1866
|
const option = options.find((o) => o.id === id);
|
|
1809
1867
|
if (option) {
|
|
@@ -1839,7 +1897,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1839
1897
|
model,
|
|
1840
1898
|
editing
|
|
1841
1899
|
]);
|
|
1842
|
-
return /* @__PURE__ */
|
|
1900
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui_grid4.GridCellEditor, {
|
|
1843
1901
|
extension,
|
|
1844
1902
|
getCellContent,
|
|
1845
1903
|
onBlur: handleBlur
|
|
@@ -1958,6 +2016,10 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
|
|
|
1958
2016
|
modals.showColumnCreator();
|
|
1959
2017
|
break;
|
|
1960
2018
|
}
|
|
2019
|
+
case "referencedCell": {
|
|
2020
|
+
modals.showReferencePanel(data.targetId, data.schemaId);
|
|
2021
|
+
break;
|
|
2022
|
+
}
|
|
1961
2023
|
case "sort": {
|
|
1962
2024
|
model?.sorting?.toggleSort(data.fieldId);
|
|
1963
2025
|
break;
|
|
@@ -2069,7 +2131,7 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
|
|
|
2069
2131
|
const space = model.space;
|
|
2070
2132
|
(0, import_invariant.invariant)(space, void 0, {
|
|
2071
2133
|
F: __dxlog_file4,
|
|
2072
|
-
L:
|
|
2134
|
+
L: 312,
|
|
2073
2135
|
S: void 0,
|
|
2074
2136
|
A: [
|
|
2075
2137
|
"space",
|
|
@@ -2145,6 +2207,9 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
|
|
|
2145
2207
|
}), /* @__PURE__ */ import_react.default.createElement(CreateRefPanel, {
|
|
2146
2208
|
model,
|
|
2147
2209
|
modals
|
|
2210
|
+
}), /* @__PURE__ */ import_react.default.createElement(RefPanel, {
|
|
2211
|
+
model,
|
|
2212
|
+
modals
|
|
2148
2213
|
}));
|
|
2149
2214
|
});
|
|
2150
2215
|
var Table = {
|
|
@@ -2152,8 +2217,8 @@ var Table = {
|
|
|
2152
2217
|
Main: TableMain
|
|
2153
2218
|
};
|
|
2154
2219
|
var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
2155
|
-
const [model, setModel] = (0,
|
|
2156
|
-
(0,
|
|
2220
|
+
const [model, setModel] = (0, import_react9.useState)();
|
|
2221
|
+
(0, import_react9.useEffect)(() => {
|
|
2157
2222
|
if (!table || !projection) {
|
|
2158
2223
|
return;
|
|
2159
2224
|
}
|
|
@@ -2183,7 +2248,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2183
2248
|
features,
|
|
2184
2249
|
rowActions
|
|
2185
2250
|
]);
|
|
2186
|
-
(0,
|
|
2251
|
+
(0, import_react9.useEffect)(() => {
|
|
2187
2252
|
if (rows) {
|
|
2188
2253
|
model?.setRows(rows);
|
|
2189
2254
|
}
|
|
@@ -2195,7 +2260,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2195
2260
|
table?.id,
|
|
2196
2261
|
table?.view?.target?.query.typename
|
|
2197
2262
|
].filter(import_util2.isNonNullable));
|
|
2198
|
-
(0,
|
|
2263
|
+
(0, import_react9.useEffect)(() => {
|
|
2199
2264
|
if (!model) {
|
|
2200
2265
|
return;
|
|
2201
2266
|
}
|
|
@@ -2217,7 +2282,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2217
2282
|
return model;
|
|
2218
2283
|
};
|
|
2219
2284
|
var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
2220
|
-
const { table, projection } = (0,
|
|
2285
|
+
const { table, projection } = (0, import_react8.useMemo)(() => {
|
|
2221
2286
|
const props2 = getBaseSchems({
|
|
2222
2287
|
typename: name,
|
|
2223
2288
|
properties,
|
|
@@ -2234,14 +2299,14 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2234
2299
|
schema,
|
|
2235
2300
|
jsonSchema
|
|
2236
2301
|
]);
|
|
2237
|
-
const tableRef = (0,
|
|
2238
|
-
const handleCellUpdate = (0,
|
|
2302
|
+
const tableRef = (0, import_react8.useRef)(null);
|
|
2303
|
+
const handleCellUpdate = (0, import_react8.useCallback)((cell) => {
|
|
2239
2304
|
tableRef.current?.update?.(cell);
|
|
2240
2305
|
}, []);
|
|
2241
|
-
const handleRowOrderChange = (0,
|
|
2306
|
+
const handleRowOrderChange = (0, import_react8.useCallback)(() => {
|
|
2242
2307
|
tableRef.current?.update?.();
|
|
2243
2308
|
}, []);
|
|
2244
|
-
const features = (0,
|
|
2309
|
+
const features = (0, import_react_ui8.useDefaultValue)(props.features, () => ({
|
|
2245
2310
|
selection: {
|
|
2246
2311
|
enabled: false
|
|
2247
2312
|
},
|
|
@@ -2257,20 +2322,20 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2257
2322
|
onRowOrderChange: handleRowOrderChange,
|
|
2258
2323
|
onRowAction
|
|
2259
2324
|
});
|
|
2260
|
-
const presentation = (0,
|
|
2325
|
+
const presentation = (0, import_react8.useMemo)(() => {
|
|
2261
2326
|
if (model) {
|
|
2262
2327
|
return new TablePresentation(model);
|
|
2263
2328
|
}
|
|
2264
2329
|
}, [
|
|
2265
2330
|
model
|
|
2266
2331
|
]);
|
|
2267
|
-
return /* @__PURE__ */
|
|
2332
|
+
return /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
2268
2333
|
role: "none",
|
|
2269
2334
|
className: (0, import_react_ui_theme3.mx)("is-full bs-full grow grid", classNames)
|
|
2270
|
-
}, /* @__PURE__ */
|
|
2335
|
+
}, /* @__PURE__ */ import_react8.default.createElement("div", {
|
|
2271
2336
|
role: "none",
|
|
2272
2337
|
className: "grid min-bs-0 overflow-hidden"
|
|
2273
|
-
}, /* @__PURE__ */
|
|
2338
|
+
}, /* @__PURE__ */ import_react8.default.createElement(Table.Root, null, /* @__PURE__ */ import_react8.default.createElement(Table.Main, {
|
|
2274
2339
|
ref: tableRef,
|
|
2275
2340
|
model,
|
|
2276
2341
|
presentation,
|
|
@@ -2330,18 +2395,18 @@ var createTableToolbarActions = (state) => {
|
|
|
2330
2395
|
};
|
|
2331
2396
|
};
|
|
2332
2397
|
var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
|
|
2333
|
-
const state = (0,
|
|
2398
|
+
const state = (0, import_react10.useMemo)(() => (0, import_live_object3.live)({
|
|
2334
2399
|
viewDirty
|
|
2335
2400
|
}), []);
|
|
2336
|
-
const actionsCreator = (0,
|
|
2401
|
+
const actionsCreator = (0, import_react10.useCallback)(() => createTableToolbarActions(state), [
|
|
2337
2402
|
state
|
|
2338
2403
|
]);
|
|
2339
2404
|
const menu = (0, import_react_ui_menu.useMenuActions)(actionsCreator);
|
|
2340
|
-
return /* @__PURE__ */
|
|
2405
|
+
return /* @__PURE__ */ import_react10.default.createElement(import_react_ui_menu.MenuProvider, {
|
|
2341
2406
|
...menu,
|
|
2342
2407
|
attendableId,
|
|
2343
2408
|
onAction
|
|
2344
|
-
}, /* @__PURE__ */
|
|
2409
|
+
}, /* @__PURE__ */ import_react10.default.createElement(import_react_ui_menu.ToolbarMenu, {
|
|
2345
2410
|
classNames
|
|
2346
2411
|
}));
|
|
2347
2412
|
};
|