@dxos/react-ui-table 0.8.2-main.f081794 → 0.8.2-main.fbd8ed0
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 → chunk-PFFO5LYM.mjs} +7 -6
- package/dist/lib/browser/chunk-PFFO5LYM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +323 -174
- 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-TGG6OZ54.cjs → chunk-VREQOYRW.cjs} +9 -8
- package/dist/lib/node/chunk-VREQOYRW.cjs.map +7 -0
- package/dist/lib/node/index.cjs +302 -156
- 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-KKLP54L3.mjs → chunk-34JG3SDI.mjs} +7 -6
- package/dist/lib/node-esm/chunk-34JG3SDI.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +323 -174
- 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/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +3 -4
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +2 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +1 -0
- 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/TableCellEditor/FormCellEditor.d.ts +13 -0
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -2
- package/dist/types/src/components/TableToolbar/TableToolbar.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/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.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 +44 -43
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +4 -3
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +12 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/src/util/signals.d.ts.map +1 -1
- package/dist/types/src/util/table-buttons.d.ts +0 -14
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.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/dist/types/src/util/tag.d.ts +11 -0
- package/dist/types/src/util/tag.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -33
- package/src/components/Table/CreateRefPanel.tsx +3 -3
- package/src/components/Table/DynamicTable.stories.tsx +2 -2
- package/src/components/Table/DynamicTable.tsx +4 -5
- package/src/components/Table/Table.stories.tsx +66 -20
- package/src/components/Table/Table.tsx +25 -28
- package/src/components/Table/relations.stories.tsx +37 -30
- package/src/components/TableCellEditor/FormCellEditor.tsx +94 -0
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +8 -7
- package/src/components/TableCellEditor/TableCellEditor.tsx +45 -4
- package/src/components/TableToolbar/TableToolbar.tsx +10 -11
- package/src/components/testing.ts +7 -6
- package/src/model/table-model.test.ts +4 -3
- package/src/model/table-model.ts +17 -0
- package/src/model/table-presentation.test.ts +4 -3
- package/src/model/table-presentation.ts +54 -10
- package/src/types/table.ts +15 -7
- package/src/util/dynamic-table.ts +7 -4
- package/src/util/index.ts +1 -0
- package/src/util/schema.ts +36 -0
- package/src/util/table-buttons.ts +0 -23
- package/src/util/table.ts +12 -15
- package/src/util/tag.ts +33 -0
- package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +0 -7
- package/dist/lib/node/chunk-TGG6OZ54.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +0 -7
- package/dist/types/src/components/Table/RefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/RefPanel.d.ts.map +0 -1
- package/src/components/Table/RefPanel.tsx +0 -52
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TableSchema,
|
|
3
3
|
TableType
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PFFO5LYM.mjs";
|
|
5
5
|
|
|
6
6
|
// packages/ui/react-ui-table/src/translations.ts
|
|
7
7
|
var translationKey = "table";
|
|
@@ -36,13 +36,13 @@ var translations_default = [
|
|
|
36
36
|
];
|
|
37
37
|
|
|
38
38
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
39
|
-
import React7, { forwardRef, useCallback as
|
|
39
|
+
import React7, { forwardRef, useCallback as useCallback5, useImperativeHandle, useState as useState2, useMemo as useMemo5, useEffect as useEffect3 } from "react";
|
|
40
40
|
import { getValue as getValue4 } from "@dxos/echo-schema";
|
|
41
|
-
import { invariant as
|
|
41
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
42
42
|
import { Filter } from "@dxos/react-client/echo";
|
|
43
43
|
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
44
44
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
45
|
-
import { closestCell, Grid } from "@dxos/react-ui-grid";
|
|
45
|
+
import { closestCell, Grid, gridSeparatorInlineEnd, gridSeparatorBlockEnd } from "@dxos/react-ui-grid";
|
|
46
46
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
47
47
|
import { isNotFalsy, safeParseInt } from "@dxos/util";
|
|
48
48
|
|
|
@@ -150,8 +150,8 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
// packages/ui/react-ui-table/src/components/Table/CreateRefPanel.tsx
|
|
153
|
+
import { Schema } from "effect";
|
|
153
154
|
import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
154
|
-
import { S } from "@dxos/echo-schema";
|
|
155
155
|
import { live } from "@dxos/react-client/echo";
|
|
156
156
|
import { Popover } from "@dxos/react-ui";
|
|
157
157
|
import { Form } from "@dxos/react-ui-form";
|
|
@@ -168,7 +168,7 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
168
168
|
typename: state.typename
|
|
169
169
|
}).runSync();
|
|
170
170
|
if (schema2) {
|
|
171
|
-
const omit =
|
|
171
|
+
const omit = Schema.omit("id");
|
|
172
172
|
return omit(schema2);
|
|
173
173
|
}
|
|
174
174
|
}, [
|
|
@@ -223,46 +223,8 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
223
223
|
}), /* @__PURE__ */ React3.createElement(Popover.Arrow, null))));
|
|
224
224
|
};
|
|
225
225
|
|
|
226
|
-
// packages/ui/react-ui-table/src/components/Table/RefPanel.tsx
|
|
227
|
-
import React4 from "react";
|
|
228
|
-
import { Popover as Popover2 } from "@dxos/react-ui";
|
|
229
|
-
import { Form as Form2 } from "@dxos/react-ui-form";
|
|
230
|
-
var getRefTargetObj = (space, id) => {
|
|
231
|
-
if (space && id) {
|
|
232
|
-
return space?.db.getObjectById(id);
|
|
233
|
-
} else {
|
|
234
|
-
return void 0;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
var RefPanel = ({ model, modals }) => {
|
|
238
|
-
const state = modals.state.value;
|
|
239
|
-
const space = model?.space;
|
|
240
|
-
const targetObj = getRefTargetObj(space, state?.type === "refPanel" ? state.targetId : void 0);
|
|
241
|
-
const schema = space && state?.type === "refPanel" ? space.db.schemaRegistry.getSchema(state.typename) : void 0;
|
|
242
|
-
if (!model.view || !model.projection) {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
return /* @__PURE__ */ React4.createElement(Popover2.Root, {
|
|
246
|
-
modal: false,
|
|
247
|
-
open: state?.type === "refPanel" && !!targetObj && !!schema,
|
|
248
|
-
onOpenChange: (nextOpen) => {
|
|
249
|
-
if (!nextOpen) {
|
|
250
|
-
return modals.close();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}, /* @__PURE__ */ React4.createElement(Popover2.VirtualTrigger, {
|
|
254
|
-
virtualRef: modals.trigger
|
|
255
|
-
}), /* @__PURE__ */ React4.createElement(Popover2.Portal, null, /* @__PURE__ */ React4.createElement(Popover2.Content, {
|
|
256
|
-
classNames: "md:is-64"
|
|
257
|
-
}, targetObj && schema && /* @__PURE__ */ React4.createElement(Form2, {
|
|
258
|
-
readonly: true,
|
|
259
|
-
values: targetObj,
|
|
260
|
-
schema
|
|
261
|
-
}), /* @__PURE__ */ React4.createElement(Popover2.Arrow, null))));
|
|
262
|
-
};
|
|
263
|
-
|
|
264
226
|
// packages/ui/react-ui-table/src/components/Table/RowActionsMenu.tsx
|
|
265
|
-
import
|
|
227
|
+
import React4 from "react";
|
|
266
228
|
import { DropdownMenu as DropdownMenu3, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
267
229
|
var RowActionsMenu = ({ model, modals }) => {
|
|
268
230
|
const { t } = useTranslation2(translationKey);
|
|
@@ -271,23 +233,23 @@ var RowActionsMenu = ({ model, modals }) => {
|
|
|
271
233
|
if (state?.type !== "row") {
|
|
272
234
|
return null;
|
|
273
235
|
}
|
|
274
|
-
return /* @__PURE__ */
|
|
236
|
+
return /* @__PURE__ */ React4.createElement(DropdownMenu3.Root, {
|
|
275
237
|
modal: false,
|
|
276
238
|
open: true,
|
|
277
239
|
onOpenChange: modals.close
|
|
278
|
-
}, /* @__PURE__ */
|
|
240
|
+
}, /* @__PURE__ */ React4.createElement(DropdownMenu3.VirtualTrigger, {
|
|
279
241
|
virtualRef: modals.trigger
|
|
280
|
-
}), /* @__PURE__ */
|
|
242
|
+
}), /* @__PURE__ */ React4.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu3.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React4.createElement(DropdownMenu3.Item, {
|
|
281
243
|
"data-testid": "row-menu-delete",
|
|
282
244
|
onClick: () => model.deleteRow(state.rowIndex)
|
|
283
|
-
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */
|
|
245
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React4.createElement(DropdownMenu3.Item, {
|
|
284
246
|
key: action.id,
|
|
285
247
|
"data-testid": `row-action-${action.id}`,
|
|
286
248
|
onClick: () => {
|
|
287
249
|
modals.close();
|
|
288
250
|
model.handleRowAction(action.id, state.rowIndex);
|
|
289
251
|
}
|
|
290
|
-
}, t(action.translationKey)))), /* @__PURE__ */
|
|
252
|
+
}, t(action.translationKey)))), /* @__PURE__ */ React4.createElement(DropdownMenu3.Arrow, null)));
|
|
291
253
|
};
|
|
292
254
|
|
|
293
255
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
@@ -295,7 +257,7 @@ import { computed as computed3, effect as effect2, signal as signal3 } from "@pr
|
|
|
295
257
|
import { Resource as Resource2 } from "@dxos/context";
|
|
296
258
|
import { FormatEnum as FormatEnum3, getValue as getValue2, setValue } from "@dxos/echo-schema";
|
|
297
259
|
import { invariant } from "@dxos/invariant";
|
|
298
|
-
import { isLiveObject, makeRef as
|
|
260
|
+
import { isLiveObject, makeRef as makeRef2 } from "@dxos/live-object";
|
|
299
261
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
300
262
|
|
|
301
263
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
@@ -303,9 +265,10 @@ import { computed, effect, signal } from "@preact/signals-core";
|
|
|
303
265
|
import { Resource } from "@dxos/context";
|
|
304
266
|
|
|
305
267
|
// packages/ui/react-ui-table/src/util/dynamic-table.ts
|
|
268
|
+
import { getTypename, toJsonSchema } from "@dxos/echo-schema";
|
|
306
269
|
import { live as live2, makeRef } from "@dxos/live-object";
|
|
307
270
|
import { createView, getSchemaFromPropertyDefinitions, ViewProjection } from "@dxos/schema";
|
|
308
|
-
var
|
|
271
|
+
var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
309
272
|
if (typename && properties) {
|
|
310
273
|
const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
|
|
311
274
|
return {
|
|
@@ -314,8 +277,8 @@ var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
314
277
|
};
|
|
315
278
|
} else if (schema) {
|
|
316
279
|
return {
|
|
317
|
-
typename: schema
|
|
318
|
-
jsonSchema: schema
|
|
280
|
+
typename: getTypename(schema),
|
|
281
|
+
jsonSchema: toJsonSchema(schema)
|
|
319
282
|
};
|
|
320
283
|
} else if (typename && jsonSchema) {
|
|
321
284
|
return {
|
|
@@ -382,9 +345,10 @@ var setProperties = (view, projection, properties) => {
|
|
|
382
345
|
var touch = (value) => value;
|
|
383
346
|
|
|
384
347
|
// packages/ui/react-ui-table/src/util/table.ts
|
|
385
|
-
import {
|
|
348
|
+
import { Schema as Schema2, SchemaAST } from "effect";
|
|
349
|
+
import { Format, FormatEnum, Ref, TypedObject, TypeEnum } from "@dxos/echo-schema";
|
|
386
350
|
import { PublicKey } from "@dxos/react-client";
|
|
387
|
-
import { live as live3
|
|
351
|
+
import { live as live3 } from "@dxos/react-client/echo";
|
|
388
352
|
import { createFieldId, createView as createView2, getSchemaProperties, ViewProjection as ViewProjection2 } from "@dxos/schema";
|
|
389
353
|
var initializeTable = async ({ client, space, table, typename, initialRow = true }) => {
|
|
390
354
|
if (typename) {
|
|
@@ -392,8 +356,8 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
|
|
|
392
356
|
if (!schema) {
|
|
393
357
|
throw new Error(`Schema not found: ${typename}`);
|
|
394
358
|
}
|
|
395
|
-
const fields = getSchemaProperties(schema.ast).
|
|
396
|
-
table.view =
|
|
359
|
+
const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
|
|
360
|
+
table.view = Ref.make(createView2({
|
|
397
361
|
// TODO(ZaymonFC): Don't hardcode name?
|
|
398
362
|
name: "View",
|
|
399
363
|
typename: schema.typename,
|
|
@@ -406,7 +370,7 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
|
|
|
406
370
|
ContactSchema
|
|
407
371
|
]);
|
|
408
372
|
const fields = ContactFields;
|
|
409
|
-
table.view =
|
|
373
|
+
table.view = Ref.make(createView2({
|
|
410
374
|
name: "View",
|
|
411
375
|
typename: schema.typename,
|
|
412
376
|
jsonSchema: schema.jsonSchema,
|
|
@@ -423,13 +387,13 @@ var ContactSchema = TypedObject({
|
|
|
423
387
|
typename: `example.com/type/${PublicKey.random().truncate()}`,
|
|
424
388
|
version: "0.1.0"
|
|
425
389
|
})({
|
|
426
|
-
name:
|
|
427
|
-
[
|
|
390
|
+
name: Schema2.optional(Schema2.String).annotations({
|
|
391
|
+
[SchemaAST.TitleAnnotationId]: "Name"
|
|
428
392
|
}),
|
|
429
|
-
active:
|
|
430
|
-
email:
|
|
431
|
-
salary:
|
|
432
|
-
[
|
|
393
|
+
active: Schema2.optional(Schema2.Boolean),
|
|
394
|
+
email: Schema2.optional(Format.Email),
|
|
395
|
+
salary: Schema2.optional(Format.Currency()).annotations({
|
|
396
|
+
[SchemaAST.TitleAnnotationId]: "Salary"
|
|
433
397
|
})
|
|
434
398
|
});
|
|
435
399
|
var ContactFields = [
|
|
@@ -518,26 +482,6 @@ var columnSettingsButton = {
|
|
|
518
482
|
fieldId: el.getAttribute("data-field-id")
|
|
519
483
|
})
|
|
520
484
|
};
|
|
521
|
-
var referencedCellButton = {
|
|
522
|
-
attr: BUTTON_IDENTIFIERS.referencedCell,
|
|
523
|
-
icon: "ph--link-simple-horizontal--regular",
|
|
524
|
-
render: ({ targetId, schemaId }) => {
|
|
525
|
-
return createButton({
|
|
526
|
-
attr: BUTTON_IDENTIFIERS.referencedCell,
|
|
527
|
-
icon: referencedCellButton.icon,
|
|
528
|
-
data: {
|
|
529
|
-
"data-target-id": targetId,
|
|
530
|
-
"data-schema-id": schemaId
|
|
531
|
-
},
|
|
532
|
-
testId: "table-ref-cell-button"
|
|
533
|
-
});
|
|
534
|
-
},
|
|
535
|
-
getData: (el) => ({
|
|
536
|
-
type: "referencedCell",
|
|
537
|
-
targetId: el.getAttribute("data-target-id"),
|
|
538
|
-
schemaId: el.getAttribute("data-schema-id")
|
|
539
|
-
})
|
|
540
|
-
};
|
|
541
485
|
var rowMenuButton = {
|
|
542
486
|
attr: BUTTON_IDENTIFIERS.rowMenu,
|
|
543
487
|
icon: "ph--dots-three--regular",
|
|
@@ -582,7 +526,6 @@ var sortButton = {
|
|
|
582
526
|
var tableButtons = {
|
|
583
527
|
addColumn: addColumnButton,
|
|
584
528
|
columnSettings: columnSettingsButton,
|
|
585
|
-
referencedCell: referencedCellButton,
|
|
586
529
|
rowMenu: rowMenuButton,
|
|
587
530
|
sort: sortButton
|
|
588
531
|
};
|
|
@@ -641,6 +584,21 @@ var tableControls = {
|
|
|
641
584
|
}
|
|
642
585
|
};
|
|
643
586
|
|
|
587
|
+
// packages/ui/react-ui-table/src/util/schema.ts
|
|
588
|
+
import { Schema as Schema3 } from "effect";
|
|
589
|
+
import { isTypeLiteral, TypeLiteral } from "effect/SchemaAST";
|
|
590
|
+
var narrowSchema = (schema, paths) => {
|
|
591
|
+
const ast = schema?.ast;
|
|
592
|
+
if (isTypeLiteral(ast)) {
|
|
593
|
+
const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
|
|
594
|
+
if (propertySignatures.length > 0) {
|
|
595
|
+
const narrowType = new TypeLiteral(propertySignatures, []);
|
|
596
|
+
return Schema3.make(narrowType);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return void 0;
|
|
600
|
+
};
|
|
601
|
+
|
|
644
602
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
645
603
|
var SelectionModel = class extends Resource {
|
|
646
604
|
constructor(_rows, _selectionMode, _onSelectionChanged) {
|
|
@@ -893,6 +851,22 @@ var TableSorting = class {
|
|
|
893
851
|
}
|
|
894
852
|
};
|
|
895
853
|
|
|
854
|
+
// packages/ui/react-ui-table/src/util/tag.ts
|
|
855
|
+
var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
856
|
+
var extractTagIds = (value) => {
|
|
857
|
+
if (typeof value !== "string") {
|
|
858
|
+
return void 0;
|
|
859
|
+
}
|
|
860
|
+
const ids = [];
|
|
861
|
+
let match;
|
|
862
|
+
while ((match = TAG_PATTERN_REGEX.exec(value)) !== null) {
|
|
863
|
+
if (match[2]) {
|
|
864
|
+
ids.push(match[2]);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return ids.length > 0 ? ids : void 0;
|
|
868
|
+
};
|
|
869
|
+
|
|
896
870
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
897
871
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
898
872
|
var defaultFeatures = {
|
|
@@ -993,7 +967,21 @@ var TableModel = class extends Resource2 {
|
|
|
993
967
|
switch (props.format) {
|
|
994
968
|
case FormatEnum3.Ref: {
|
|
995
969
|
if (isLiveObject(value)) {
|
|
996
|
-
setValue(this._rows.value[rowIdx], field.path,
|
|
970
|
+
setValue(this._rows.value[rowIdx], field.path, makeRef2(value));
|
|
971
|
+
}
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
case FormatEnum3.SingleSelect: {
|
|
975
|
+
const ids = extractTagIds(value);
|
|
976
|
+
if (ids && ids.length > 0) {
|
|
977
|
+
setValue(this._rows.value[rowIdx], field.path, ids[0]);
|
|
978
|
+
}
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
case FormatEnum3.MultiSelect: {
|
|
982
|
+
const ids = extractTagIds(value);
|
|
983
|
+
if (ids) {
|
|
984
|
+
setValue(this._rows.value[rowIdx], field.path, ids);
|
|
997
985
|
}
|
|
998
986
|
break;
|
|
999
987
|
}
|
|
@@ -1017,7 +1005,7 @@ var TableModel = class extends Resource2 {
|
|
|
1017
1005
|
};
|
|
1018
1006
|
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
1019
1007
|
F: __dxlog_file,
|
|
1020
|
-
L:
|
|
1008
|
+
L: 115,
|
|
1021
1009
|
S: this,
|
|
1022
1010
|
A: [
|
|
1023
1011
|
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
@@ -1077,7 +1065,7 @@ var TableModel = class extends Resource2 {
|
|
|
1077
1065
|
get columnMeta() {
|
|
1078
1066
|
invariant(this._columnMeta, void 0, {
|
|
1079
1067
|
F: __dxlog_file,
|
|
1080
|
-
L:
|
|
1068
|
+
L: 184,
|
|
1081
1069
|
S: this,
|
|
1082
1070
|
A: [
|
|
1083
1071
|
"this._columnMeta",
|
|
@@ -1303,7 +1291,8 @@ var ModalController = class {
|
|
|
1303
1291
|
|
|
1304
1292
|
// packages/ui/react-ui-table/src/model/table-presentation.ts
|
|
1305
1293
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1306
|
-
import {
|
|
1294
|
+
import { isNotNullable } from "effect/Predicate";
|
|
1295
|
+
import { FormatEnum as FormatEnum4, getDXN, getValue as getValue3, TypeEnum as TypeEnum3 } from "@dxos/echo-schema";
|
|
1307
1296
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1308
1297
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1309
1298
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -1365,6 +1354,9 @@ var TablePresentation = class {
|
|
|
1365
1354
|
if (value == null) {
|
|
1366
1355
|
return "";
|
|
1367
1356
|
}
|
|
1357
|
+
if (props.type === "array") {
|
|
1358
|
+
return "";
|
|
1359
|
+
}
|
|
1368
1360
|
switch (props.format) {
|
|
1369
1361
|
case FormatEnum4.Boolean:
|
|
1370
1362
|
case FormatEnum4.SingleSelect:
|
|
@@ -1402,13 +1394,38 @@ var TablePresentation = class {
|
|
|
1402
1394
|
if (classes.length > 0) {
|
|
1403
1395
|
cell.className = mx(classes.flat());
|
|
1404
1396
|
}
|
|
1397
|
+
if (props.type === TypeEnum3.Array) {
|
|
1398
|
+
const targetArray = getValue3(obj, field.path);
|
|
1399
|
+
if (targetArray && Array.isArray(targetArray)) {
|
|
1400
|
+
const getLabel = (value) => {
|
|
1401
|
+
if (!value) {
|
|
1402
|
+
return void 0;
|
|
1403
|
+
}
|
|
1404
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1405
|
+
return String(value);
|
|
1406
|
+
}
|
|
1407
|
+
if (Array.isArray(value)) {
|
|
1408
|
+
return "Array";
|
|
1409
|
+
}
|
|
1410
|
+
if (typeof value === "object" && value.name) {
|
|
1411
|
+
return value.name;
|
|
1412
|
+
}
|
|
1413
|
+
if (typeof value === "object" && value.value) {
|
|
1414
|
+
return `${value.value}`;
|
|
1415
|
+
}
|
|
1416
|
+
return "Object";
|
|
1417
|
+
};
|
|
1418
|
+
const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
|
|
1419
|
+
return `<span class="dx-tag rounded-xl" data-hue="neutral">${title}</span>`;
|
|
1420
|
+
}).join("");
|
|
1421
|
+
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1405
1424
|
if (props.format === FormatEnum4.Ref && props.referenceSchema) {
|
|
1406
1425
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1407
1426
|
if (targetObj) {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
schemaId: props.referenceSchema
|
|
1411
|
-
});
|
|
1427
|
+
const dxn = getDXN(targetObj)?.toString();
|
|
1428
|
+
cell.accessoryHtml = `<dx-ref-tag ref=${dxn} class="dx-button block is-6 pli-[3px] plb-[3px] pbe-[2px] min-bs-0 absolute inline-end-1"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
|
|
1412
1429
|
}
|
|
1413
1430
|
}
|
|
1414
1431
|
if (props.format === FormatEnum4.Boolean) {
|
|
@@ -1442,7 +1459,7 @@ var TablePresentation = class {
|
|
|
1442
1459
|
return null;
|
|
1443
1460
|
}).filter(Boolean).join(" ");
|
|
1444
1461
|
if (tags) {
|
|
1445
|
-
cell.accessoryHtml = tags
|
|
1462
|
+
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1">${tags}</div>`;
|
|
1446
1463
|
}
|
|
1447
1464
|
}
|
|
1448
1465
|
}
|
|
@@ -1487,7 +1504,7 @@ var TablePresentation = class {
|
|
|
1487
1504
|
fieldId: field.id
|
|
1488
1505
|
})}
|
|
1489
1506
|
`,
|
|
1490
|
-
className: "!bg-
|
|
1507
|
+
className: "!bg-toolbarSurface"
|
|
1491
1508
|
};
|
|
1492
1509
|
}
|
|
1493
1510
|
return cells;
|
|
@@ -1538,7 +1555,7 @@ var TablePresentation = class {
|
|
|
1538
1555
|
col: 0,
|
|
1539
1556
|
row: 0
|
|
1540
1557
|
})]: {
|
|
1541
|
-
className: "!bg-
|
|
1558
|
+
className: "!bg-toolbarSurface",
|
|
1542
1559
|
readonly: true,
|
|
1543
1560
|
value: ""
|
|
1544
1561
|
}
|
|
@@ -1554,7 +1571,7 @@ var TablePresentation = class {
|
|
|
1554
1571
|
header: true,
|
|
1555
1572
|
checked: this.model.selection.allRowsSeleted.value
|
|
1556
1573
|
}),
|
|
1557
|
-
className: "!bg-
|
|
1574
|
+
className: "!bg-toolbarSurface",
|
|
1558
1575
|
readonly: true,
|
|
1559
1576
|
value: ""
|
|
1560
1577
|
}
|
|
@@ -1569,7 +1586,7 @@ var TablePresentation = class {
|
|
|
1569
1586
|
accessoryHtml: this.model.features.schemaEditable ? tableButtons.addColumn.render({
|
|
1570
1587
|
disabled: (this.model.view?.fields?.length ?? 0) >= VIEW_FIELD_LIMIT
|
|
1571
1588
|
}) : void 0,
|
|
1572
|
-
className: "!bg-
|
|
1589
|
+
className: "!bg-toolbarSurface",
|
|
1573
1590
|
readonly: true,
|
|
1574
1591
|
value: ""
|
|
1575
1592
|
}
|
|
@@ -1600,14 +1617,109 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
|
1600
1617
|
};
|
|
1601
1618
|
|
|
1602
1619
|
// packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
|
|
1603
|
-
import React6, { useCallback as
|
|
1604
|
-
import { FormatEnum as FormatEnum5 } from "@dxos/echo-schema";
|
|
1605
|
-
import { invariant as
|
|
1620
|
+
import React6, { useCallback as useCallback4, useMemo as useMemo4, useRef as useRef2 } from "react";
|
|
1621
|
+
import { FormatEnum as FormatEnum5, TypeEnum as TypeEnum4 } from "@dxos/echo-schema";
|
|
1622
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1606
1623
|
import { useThemeContext } from "@dxos/react-ui";
|
|
1607
1624
|
import { createMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
1608
|
-
import { cellQuery, editorKeys, parseCellIndex, useGridContext as
|
|
1625
|
+
import { cellQuery, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3, GridCellEditor } from "@dxos/react-ui-grid";
|
|
1609
1626
|
import { tagPickerExtension, createLinks } from "@dxos/react-ui-tag-picker";
|
|
1610
1627
|
|
|
1628
|
+
// packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx
|
|
1629
|
+
import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef } from "react";
|
|
1630
|
+
import { getSnapshot } from "@dxos/echo-schema";
|
|
1631
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1632
|
+
import { Popover as Popover2 } from "@dxos/react-ui";
|
|
1633
|
+
import { Form as Form2 } from "@dxos/react-ui-form";
|
|
1634
|
+
import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
|
|
1635
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
1636
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
|
|
1637
|
+
var FormCellEditor = ({ fieldProjection, model, schema, __gridScope }) => {
|
|
1638
|
+
const { editing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
|
|
1639
|
+
const cellRef = useRef(null);
|
|
1640
|
+
useEffect2(() => {
|
|
1641
|
+
if (editing && editing.cellElement) {
|
|
1642
|
+
cellRef.current = editing.cellElement;
|
|
1643
|
+
}
|
|
1644
|
+
}, [
|
|
1645
|
+
editing?.cellElement
|
|
1646
|
+
]);
|
|
1647
|
+
const narrowedSchema = useMemo3(() => {
|
|
1648
|
+
if (!schema) {
|
|
1649
|
+
return void 0;
|
|
1650
|
+
}
|
|
1651
|
+
return narrowSchema(schema, [
|
|
1652
|
+
fieldProjection.field.path
|
|
1653
|
+
]);
|
|
1654
|
+
}, [
|
|
1655
|
+
JSON.stringify(schema),
|
|
1656
|
+
fieldProjection.field.path
|
|
1657
|
+
]);
|
|
1658
|
+
const originalRow = useMemo3(() => {
|
|
1659
|
+
if (model && editing) {
|
|
1660
|
+
const cell = parseCellIndex(editing.index);
|
|
1661
|
+
const row = model.getRowAt(cell.row);
|
|
1662
|
+
invariant2(row, void 0, {
|
|
1663
|
+
F: __dxlog_file3,
|
|
1664
|
+
L: 47,
|
|
1665
|
+
S: void 0,
|
|
1666
|
+
A: [
|
|
1667
|
+
"row",
|
|
1668
|
+
""
|
|
1669
|
+
]
|
|
1670
|
+
});
|
|
1671
|
+
return row;
|
|
1672
|
+
}
|
|
1673
|
+
return void 0;
|
|
1674
|
+
}, [
|
|
1675
|
+
model,
|
|
1676
|
+
editing
|
|
1677
|
+
]);
|
|
1678
|
+
const formValues = useMemo3(() => {
|
|
1679
|
+
if (originalRow) {
|
|
1680
|
+
return getSnapshot(originalRow);
|
|
1681
|
+
}
|
|
1682
|
+
}, [
|
|
1683
|
+
originalRow
|
|
1684
|
+
]);
|
|
1685
|
+
const handleSave = useCallback3((values) => {
|
|
1686
|
+
const path = fieldProjection.field.path;
|
|
1687
|
+
const value = getDeep(values, [
|
|
1688
|
+
path
|
|
1689
|
+
]);
|
|
1690
|
+
setDeep(originalRow, [
|
|
1691
|
+
path
|
|
1692
|
+
], value);
|
|
1693
|
+
setEditing(null);
|
|
1694
|
+
}, [
|
|
1695
|
+
fieldProjection.field.path,
|
|
1696
|
+
originalRow
|
|
1697
|
+
]);
|
|
1698
|
+
const handleOpenChange = useCallback3((nextOpen) => {
|
|
1699
|
+
if (nextOpen === false) {
|
|
1700
|
+
setEditing(null);
|
|
1701
|
+
}
|
|
1702
|
+
}, [
|
|
1703
|
+
setEditing
|
|
1704
|
+
]);
|
|
1705
|
+
if (!editing) {
|
|
1706
|
+
return null;
|
|
1707
|
+
}
|
|
1708
|
+
return /* @__PURE__ */ React5.createElement(Popover2.Root, {
|
|
1709
|
+
open: editing !== null,
|
|
1710
|
+
onOpenChange: handleOpenChange
|
|
1711
|
+
}, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
|
|
1712
|
+
virtualRef: cellRef
|
|
1713
|
+
}), /* @__PURE__ */ React5.createElement(Popover2.Content, {
|
|
1714
|
+
tabIndex: -1,
|
|
1715
|
+
classNames: "popover-consistent-width"
|
|
1716
|
+
}, /* @__PURE__ */ React5.createElement(Popover2.Arrow, null), /* @__PURE__ */ React5.createElement(Form2, {
|
|
1717
|
+
values: formValues,
|
|
1718
|
+
schema: narrowedSchema,
|
|
1719
|
+
onSave: handleSave
|
|
1720
|
+
})));
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1611
1723
|
// packages/ui/react-ui-table/src/components/TableCellEditor/extension.ts
|
|
1612
1724
|
import { autocompletion, pickedCompletion } from "@codemirror/autocomplete";
|
|
1613
1725
|
import { EditorView } from "@codemirror/view";
|
|
@@ -1648,27 +1760,67 @@ var completion = ({ debug, onQuery, onMatch }) => {
|
|
|
1648
1760
|
};
|
|
1649
1761
|
|
|
1650
1762
|
// packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
|
|
1651
|
-
var
|
|
1763
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
1652
1764
|
var newValue = Symbol.for("newValue");
|
|
1653
1765
|
var createOption = (text) => ({
|
|
1654
1766
|
[newValue]: true,
|
|
1655
1767
|
text
|
|
1656
1768
|
});
|
|
1657
1769
|
var isCreateOption = (data) => typeof data === "object" && data[newValue];
|
|
1770
|
+
var TableValueEditor = ({ model, modals, schema, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
1771
|
+
const { editing } = useGridContext3("TableValueEditor", __gridScope);
|
|
1772
|
+
const fieldProjection = useMemo4(() => {
|
|
1773
|
+
if (!model || !editing) {
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
const { col } = parseCellIndex2(editing.index);
|
|
1777
|
+
const field = model.projection.view.fields[col];
|
|
1778
|
+
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1779
|
+
invariant3(fieldProjection2, void 0, {
|
|
1780
|
+
F: __dxlog_file4,
|
|
1781
|
+
L: 73,
|
|
1782
|
+
S: void 0,
|
|
1783
|
+
A: [
|
|
1784
|
+
"fieldProjection",
|
|
1785
|
+
""
|
|
1786
|
+
]
|
|
1787
|
+
});
|
|
1788
|
+
return fieldProjection2;
|
|
1789
|
+
}, [
|
|
1790
|
+
model,
|
|
1791
|
+
editing
|
|
1792
|
+
]);
|
|
1793
|
+
if (fieldProjection?.props.type === TypeEnum4.Array) {
|
|
1794
|
+
return /* @__PURE__ */ React6.createElement(FormCellEditor, {
|
|
1795
|
+
fieldProjection,
|
|
1796
|
+
model,
|
|
1797
|
+
schema,
|
|
1798
|
+
__gridScope
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
return /* @__PURE__ */ React6.createElement(TableCellEditor, {
|
|
1802
|
+
model,
|
|
1803
|
+
modals,
|
|
1804
|
+
onEnter,
|
|
1805
|
+
onFocus,
|
|
1806
|
+
onQuery,
|
|
1807
|
+
__gridScope
|
|
1808
|
+
});
|
|
1809
|
+
};
|
|
1658
1810
|
var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
1659
|
-
const { id: gridId, editing, setEditing } =
|
|
1660
|
-
const suppressNextBlur =
|
|
1811
|
+
const { id: gridId, editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
|
|
1812
|
+
const suppressNextBlur = useRef2(false);
|
|
1661
1813
|
const { themeMode } = useThemeContext();
|
|
1662
|
-
const fieldProjection =
|
|
1814
|
+
const fieldProjection = useMemo4(() => {
|
|
1663
1815
|
if (!model || !editing) {
|
|
1664
1816
|
return;
|
|
1665
1817
|
}
|
|
1666
|
-
const { col } =
|
|
1818
|
+
const { col } = parseCellIndex2(editing.index);
|
|
1667
1819
|
const field = model.projection.view.fields[col];
|
|
1668
1820
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1669
|
-
|
|
1670
|
-
F:
|
|
1671
|
-
L:
|
|
1821
|
+
invariant3(fieldProjection2, void 0, {
|
|
1822
|
+
F: __dxlog_file4,
|
|
1823
|
+
L: 114,
|
|
1672
1824
|
S: void 0,
|
|
1673
1825
|
A: [
|
|
1674
1826
|
"fieldProjection",
|
|
@@ -1680,11 +1832,11 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1680
1832
|
model,
|
|
1681
1833
|
editing
|
|
1682
1834
|
]);
|
|
1683
|
-
const handleEnter =
|
|
1835
|
+
const handleEnter = useCallback4((value) => {
|
|
1684
1836
|
if (!model || !editing) {
|
|
1685
1837
|
return;
|
|
1686
1838
|
}
|
|
1687
|
-
const cell =
|
|
1839
|
+
const cell = parseCellIndex2(editing.index);
|
|
1688
1840
|
model.setCellData(cell, value);
|
|
1689
1841
|
onEnter?.(cell);
|
|
1690
1842
|
onFocus?.();
|
|
@@ -1696,7 +1848,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1696
1848
|
onFocus,
|
|
1697
1849
|
setEditing
|
|
1698
1850
|
]);
|
|
1699
|
-
const handleBlur =
|
|
1851
|
+
const handleBlur = useCallback4((value) => {
|
|
1700
1852
|
if (!model || !editing) {
|
|
1701
1853
|
return;
|
|
1702
1854
|
}
|
|
@@ -1704,7 +1856,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1704
1856
|
suppressNextBlur.current = false;
|
|
1705
1857
|
return;
|
|
1706
1858
|
}
|
|
1707
|
-
const cell =
|
|
1859
|
+
const cell = parseCellIndex2(editing.index);
|
|
1708
1860
|
if (value !== void 0) {
|
|
1709
1861
|
model.setCellData(cell, value);
|
|
1710
1862
|
}
|
|
@@ -1712,11 +1864,11 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1712
1864
|
model,
|
|
1713
1865
|
editing
|
|
1714
1866
|
]);
|
|
1715
|
-
const handleClose =
|
|
1867
|
+
const handleClose = useCallback4((value, event) => {
|
|
1716
1868
|
if (!model || !editing || !fieldProjection) {
|
|
1717
1869
|
return;
|
|
1718
1870
|
}
|
|
1719
|
-
const cell =
|
|
1871
|
+
const cell = parseCellIndex2(editing.index);
|
|
1720
1872
|
onEnter?.(cell);
|
|
1721
1873
|
if (event && onFocus) {
|
|
1722
1874
|
onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
|
|
@@ -1728,7 +1880,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1728
1880
|
onEnter,
|
|
1729
1881
|
fieldProjection
|
|
1730
1882
|
]);
|
|
1731
|
-
const extension =
|
|
1883
|
+
const extension = useMemo4(() => {
|
|
1732
1884
|
if (!fieldProjection) {
|
|
1733
1885
|
return [];
|
|
1734
1886
|
}
|
|
@@ -1809,9 +1961,9 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1809
1961
|
handleClose,
|
|
1810
1962
|
themeMode
|
|
1811
1963
|
]);
|
|
1812
|
-
const getCellContent =
|
|
1964
|
+
const getCellContent = useCallback4(() => {
|
|
1813
1965
|
if (model && editing) {
|
|
1814
|
-
const cell =
|
|
1966
|
+
const cell = parseCellIndex2(editing.index);
|
|
1815
1967
|
const { col } = cell;
|
|
1816
1968
|
const field = model.projection.view.fields[col];
|
|
1817
1969
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
@@ -1887,21 +2039,19 @@ var determineNavigationDelta = ({ key, shift }) => {
|
|
|
1887
2039
|
};
|
|
1888
2040
|
|
|
1889
2041
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
1890
|
-
var
|
|
1891
|
-
var inlineEndLine = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-separator";
|
|
1892
|
-
var blockEndLine = "[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-separator";
|
|
2042
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
|
|
1893
2043
|
var TableRoot = ({ children, role }) => {
|
|
1894
2044
|
return /* @__PURE__ */ React7.createElement("div", {
|
|
1895
2045
|
role: "none",
|
|
1896
2046
|
className: mx2("relative !border-separator", role === "section" ? "attention-surface overflow-hidden [&_.dx-grid]:max-is-[--dx-grid-content-inline-size]" : "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:bs-0 [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]")
|
|
1897
2047
|
}, children);
|
|
1898
2048
|
};
|
|
1899
|
-
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, onRowClick }, forwardedRef) => {
|
|
2049
|
+
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, onRowClick }, forwardedRef) => {
|
|
1900
2050
|
const [dxGrid, setDxGrid] = useState2(null);
|
|
1901
2051
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
1902
2052
|
const { t } = useTranslation3(translationKey);
|
|
1903
|
-
const modals =
|
|
1904
|
-
const frozen =
|
|
2053
|
+
const modals = useMemo5(() => new ModalController(), []);
|
|
2054
|
+
const frozen = useMemo5(() => {
|
|
1905
2055
|
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
1906
2056
|
return {
|
|
1907
2057
|
frozenRowsStart: 1,
|
|
@@ -1911,14 +2061,18 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1911
2061
|
}, [
|
|
1912
2062
|
model
|
|
1913
2063
|
]);
|
|
1914
|
-
|
|
2064
|
+
const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
|
|
2065
|
+
presentation
|
|
2066
|
+
]);
|
|
2067
|
+
useEffect3(() => {
|
|
1915
2068
|
if (!presentation || !dxGrid) {
|
|
1916
2069
|
return;
|
|
1917
2070
|
}
|
|
1918
|
-
dxGrid.getCells =
|
|
2071
|
+
dxGrid.getCells = getCells;
|
|
1919
2072
|
}, [
|
|
1920
2073
|
presentation,
|
|
1921
|
-
dxGrid
|
|
2074
|
+
dxGrid,
|
|
2075
|
+
getCells
|
|
1922
2076
|
]);
|
|
1923
2077
|
useImperativeHandle(forwardedRef, () => {
|
|
1924
2078
|
if (!presentation || !dxGrid) {
|
|
@@ -1938,7 +2092,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1938
2092
|
presentation,
|
|
1939
2093
|
dxGrid
|
|
1940
2094
|
]);
|
|
1941
|
-
const handleGridClick =
|
|
2095
|
+
const handleGridClick = useCallback5((event) => {
|
|
1942
2096
|
const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
|
|
1943
2097
|
if (rowIndex != null) {
|
|
1944
2098
|
if (onRowClick) {
|
|
@@ -1974,10 +2128,6 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1974
2128
|
modals.showColumnCreator();
|
|
1975
2129
|
break;
|
|
1976
2130
|
}
|
|
1977
|
-
case "referencedCell": {
|
|
1978
|
-
modals.showReferencePanel(data.targetId, data.schemaId);
|
|
1979
|
-
break;
|
|
1980
|
-
}
|
|
1981
2131
|
case "sort": {
|
|
1982
2132
|
model?.sorting?.toggleSort(data.fieldId);
|
|
1983
2133
|
break;
|
|
@@ -2017,14 +2167,14 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2017
2167
|
model,
|
|
2018
2168
|
modals
|
|
2019
2169
|
]);
|
|
2020
|
-
const handleFocus =
|
|
2170
|
+
const handleFocus = useCallback5((increment, delta) => {
|
|
2021
2171
|
if (dxGrid) {
|
|
2022
2172
|
dxGrid.refocus(increment, delta);
|
|
2023
2173
|
}
|
|
2024
2174
|
}, [
|
|
2025
2175
|
dxGrid
|
|
2026
2176
|
]);
|
|
2027
|
-
const handleEnter =
|
|
2177
|
+
const handleEnter = useCallback5((cell) => {
|
|
2028
2178
|
if (!model?.features.dataEditable) {
|
|
2029
2179
|
return;
|
|
2030
2180
|
}
|
|
@@ -2041,7 +2191,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2041
2191
|
model,
|
|
2042
2192
|
dxGrid
|
|
2043
2193
|
]);
|
|
2044
|
-
const handleKeyDown =
|
|
2194
|
+
const handleKeyDown = useCallback5((event) => {
|
|
2045
2195
|
if (!model?.features.dataEditable) {
|
|
2046
2196
|
return;
|
|
2047
2197
|
}
|
|
@@ -2059,7 +2209,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2059
2209
|
}, [
|
|
2060
2210
|
model
|
|
2061
2211
|
]);
|
|
2062
|
-
const handleAxisResize =
|
|
2212
|
+
const handleAxisResize = useCallback5((event) => {
|
|
2063
2213
|
if (event.axis === "col") {
|
|
2064
2214
|
const columnIndex = parseInt(event.index, 10);
|
|
2065
2215
|
model?.setColumnWidth(columnIndex, event.size);
|
|
@@ -2067,7 +2217,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2067
2217
|
}, [
|
|
2068
2218
|
model
|
|
2069
2219
|
]);
|
|
2070
|
-
const handleWheel =
|
|
2220
|
+
const handleWheel = useCallback5((event) => {
|
|
2071
2221
|
if (!ignoreAttention && !hasAttention) {
|
|
2072
2222
|
event.stopPropagation();
|
|
2073
2223
|
}
|
|
@@ -2075,7 +2225,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2075
2225
|
hasAttention,
|
|
2076
2226
|
ignoreAttention
|
|
2077
2227
|
]);
|
|
2078
|
-
const handleNewColumn =
|
|
2228
|
+
const handleNewColumn = useCallback5(() => {
|
|
2079
2229
|
const columns = model?.getColumnCount();
|
|
2080
2230
|
if (dxGrid && columns) {
|
|
2081
2231
|
dxGrid.scrollToColumn(columns - 1);
|
|
@@ -2084,21 +2234,21 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2084
2234
|
model,
|
|
2085
2235
|
dxGrid
|
|
2086
2236
|
]);
|
|
2087
|
-
const handleQuery =
|
|
2237
|
+
const handleQuery = useCallback5(async ({ field, props }, text) => {
|
|
2088
2238
|
if (model && props.referenceSchema && field.referencePath) {
|
|
2089
2239
|
const space = model.space;
|
|
2090
|
-
|
|
2091
|
-
F:
|
|
2092
|
-
L:
|
|
2240
|
+
invariant4(space, void 0, {
|
|
2241
|
+
F: __dxlog_file5,
|
|
2242
|
+
L: 309,
|
|
2093
2243
|
S: void 0,
|
|
2094
2244
|
A: [
|
|
2095
2245
|
"space",
|
|
2096
2246
|
""
|
|
2097
2247
|
]
|
|
2098
2248
|
});
|
|
2099
|
-
const
|
|
2100
|
-
if (
|
|
2101
|
-
const { objects } = await space.db.query(Filter.
|
|
2249
|
+
const schema2 = space.db.schemaRegistry.getSchema(props.referenceSchema);
|
|
2250
|
+
if (schema2) {
|
|
2251
|
+
const { objects } = await space.db.query(Filter.type(schema2)).run();
|
|
2102
2252
|
const options = objects.map((obj) => {
|
|
2103
2253
|
const value = getValue4(obj, field.referencePath);
|
|
2104
2254
|
if (!value || typeof value !== "string") {
|
|
@@ -2133,14 +2283,15 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2133
2283
|
}
|
|
2134
2284
|
return /* @__PURE__ */ React7.createElement(Grid.Root, {
|
|
2135
2285
|
id: model.id ?? "table-grid"
|
|
2136
|
-
}, /* @__PURE__ */ React7.createElement(
|
|
2286
|
+
}, /* @__PURE__ */ React7.createElement(TableValueEditor, {
|
|
2137
2287
|
model,
|
|
2138
2288
|
modals,
|
|
2289
|
+
schema,
|
|
2139
2290
|
onEnter: handleEnter,
|
|
2140
2291
|
onFocus: handleFocus,
|
|
2141
2292
|
onQuery: handleQuery
|
|
2142
2293
|
}), /* @__PURE__ */ React7.createElement(Grid.Content, {
|
|
2143
|
-
className: mx2("[--dx-grid-base:var(--
|
|
2294
|
+
className: mx2("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
|
|
2144
2295
|
frozen,
|
|
2145
2296
|
// getCells={getCells}
|
|
2146
2297
|
columns: model.columnMeta.value,
|
|
@@ -2165,9 +2316,6 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2165
2316
|
}), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
|
|
2166
2317
|
model,
|
|
2167
2318
|
modals
|
|
2168
|
-
}), /* @__PURE__ */ React7.createElement(RefPanel, {
|
|
2169
|
-
model,
|
|
2170
|
-
modals
|
|
2171
2319
|
}));
|
|
2172
2320
|
});
|
|
2173
2321
|
var Table = {
|
|
@@ -2176,19 +2324,19 @@ var Table = {
|
|
|
2176
2324
|
};
|
|
2177
2325
|
|
|
2178
2326
|
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
2179
|
-
import React8, { useRef as
|
|
2327
|
+
import React8, { useRef as useRef3, useMemo as useMemo6, useCallback as useCallback6 } from "react";
|
|
2180
2328
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
2181
2329
|
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
2182
2330
|
|
|
2183
2331
|
// packages/ui/react-ui-table/src/hooks/useTableModel.ts
|
|
2184
2332
|
import { effect as effect3 } from "@preact/signals-core";
|
|
2185
|
-
import { useEffect as
|
|
2333
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
2186
2334
|
import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
|
|
2187
2335
|
import { useSelectionActions } from "@dxos/react-ui-attention";
|
|
2188
2336
|
import { isNonNullable } from "@dxos/util";
|
|
2189
2337
|
var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
2190
2338
|
const [model, setModel] = useState3();
|
|
2191
|
-
|
|
2339
|
+
useEffect4(() => {
|
|
2192
2340
|
if (!table || !projection) {
|
|
2193
2341
|
return;
|
|
2194
2342
|
}
|
|
@@ -2218,7 +2366,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2218
2366
|
features,
|
|
2219
2367
|
rowActions
|
|
2220
2368
|
]);
|
|
2221
|
-
|
|
2369
|
+
useEffect4(() => {
|
|
2222
2370
|
if (rows) {
|
|
2223
2371
|
model?.setRows(rows);
|
|
2224
2372
|
}
|
|
@@ -2230,7 +2378,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2230
2378
|
table?.id,
|
|
2231
2379
|
table?.view?.target?.query.typename
|
|
2232
2380
|
].filter(isNonNullable));
|
|
2233
|
-
|
|
2381
|
+
useEffect4(() => {
|
|
2234
2382
|
if (!model) {
|
|
2235
2383
|
return;
|
|
2236
2384
|
}
|
|
@@ -2254,8 +2402,8 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2254
2402
|
|
|
2255
2403
|
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
2256
2404
|
var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
2257
|
-
const { table, projection } =
|
|
2258
|
-
const props2 =
|
|
2405
|
+
const { table, projection } = useMemo6(() => {
|
|
2406
|
+
const props2 = getBaseSchema({
|
|
2259
2407
|
typename: name,
|
|
2260
2408
|
properties,
|
|
2261
2409
|
jsonSchema,
|
|
@@ -2271,11 +2419,11 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2271
2419
|
schema,
|
|
2272
2420
|
jsonSchema
|
|
2273
2421
|
]);
|
|
2274
|
-
const tableRef =
|
|
2275
|
-
const handleCellUpdate =
|
|
2422
|
+
const tableRef = useRef3(null);
|
|
2423
|
+
const handleCellUpdate = useCallback6((cell) => {
|
|
2276
2424
|
tableRef.current?.update?.(cell);
|
|
2277
2425
|
}, []);
|
|
2278
|
-
const handleRowOrderChange =
|
|
2426
|
+
const handleRowOrderChange = useCallback6(() => {
|
|
2279
2427
|
tableRef.current?.update?.();
|
|
2280
2428
|
}, []);
|
|
2281
2429
|
const features = useDefaultValue(props.features, () => ({
|
|
@@ -2294,7 +2442,7 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2294
2442
|
onRowOrderChange: handleRowOrderChange,
|
|
2295
2443
|
onRowAction
|
|
2296
2444
|
});
|
|
2297
|
-
const presentation =
|
|
2445
|
+
const presentation = useMemo6(() => {
|
|
2298
2446
|
if (model) {
|
|
2299
2447
|
return new TablePresentation(model);
|
|
2300
2448
|
}
|
|
@@ -2317,11 +2465,11 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2317
2465
|
};
|
|
2318
2466
|
|
|
2319
2467
|
// packages/ui/react-ui-table/src/components/TableToolbar/TableToolbar.tsx
|
|
2320
|
-
import React9, { useCallback as
|
|
2468
|
+
import React9, { useCallback as useCallback7, useMemo as useMemo7 } from "react";
|
|
2321
2469
|
import { live as live4 } from "@dxos/live-object";
|
|
2322
2470
|
import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
|
|
2323
|
-
var createTableToolbarActions = (state) => {
|
|
2324
|
-
const add = createMenuAction("add-row", {
|
|
2471
|
+
var createTableToolbarActions = (state, onAction) => {
|
|
2472
|
+
const add = createMenuAction("add-row", () => onAction(add), {
|
|
2325
2473
|
type: "add-row",
|
|
2326
2474
|
icon: "ph--plus--regular",
|
|
2327
2475
|
label: [
|
|
@@ -2332,7 +2480,7 @@ var createTableToolbarActions = (state) => {
|
|
|
2332
2480
|
],
|
|
2333
2481
|
testId: "table.toolbar.add-row"
|
|
2334
2482
|
});
|
|
2335
|
-
const save = createMenuAction("save-view", {
|
|
2483
|
+
const save = createMenuAction("save-view", () => onAction(save), {
|
|
2336
2484
|
type: "save-view",
|
|
2337
2485
|
icon: "ph--floppy-disk--regular",
|
|
2338
2486
|
label: [
|
|
@@ -2346,7 +2494,7 @@ var createTableToolbarActions = (state) => {
|
|
|
2346
2494
|
hidden: !state.viewDirty
|
|
2347
2495
|
});
|
|
2348
2496
|
const gap = createGapSeparator();
|
|
2349
|
-
const comment = createMenuAction("comment", {
|
|
2497
|
+
const comment = createMenuAction("comment", () => onAction(comment), {
|
|
2350
2498
|
type: "comment",
|
|
2351
2499
|
icon: "ph--chat-text--regular",
|
|
2352
2500
|
label: [
|
|
@@ -2372,17 +2520,17 @@ var createTableToolbarActions = (state) => {
|
|
|
2372
2520
|
};
|
|
2373
2521
|
};
|
|
2374
2522
|
var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
|
|
2375
|
-
const state =
|
|
2523
|
+
const state = useMemo7(() => live4({
|
|
2376
2524
|
viewDirty
|
|
2377
2525
|
}), []);
|
|
2378
|
-
const actionsCreator =
|
|
2379
|
-
state
|
|
2526
|
+
const actionsCreator = useCallback7(() => createTableToolbarActions(state, onAction), [
|
|
2527
|
+
state,
|
|
2528
|
+
onAction
|
|
2380
2529
|
]);
|
|
2381
2530
|
const menu = useMenuActions(actionsCreator);
|
|
2382
2531
|
return /* @__PURE__ */ React9.createElement(MenuProvider, {
|
|
2383
2532
|
...menu,
|
|
2384
|
-
attendableId
|
|
2385
|
-
onAction
|
|
2533
|
+
attendableId
|
|
2386
2534
|
}, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
|
|
2387
2535
|
classNames
|
|
2388
2536
|
}));
|
|
@@ -2401,9 +2549,10 @@ export {
|
|
|
2401
2549
|
TableToolbar,
|
|
2402
2550
|
TableType,
|
|
2403
2551
|
cellClassesForRowSelection,
|
|
2404
|
-
|
|
2552
|
+
getBaseSchema,
|
|
2405
2553
|
initializeTable,
|
|
2406
2554
|
makeDynamicTable,
|
|
2555
|
+
narrowSchema,
|
|
2407
2556
|
tableButtons,
|
|
2408
2557
|
tableControls,
|
|
2409
2558
|
touch,
|