@dxos/react-ui-table 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a

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.
Files changed (88) hide show
  1. package/dist/lib/browser/{chunk-63UUF4IG.mjs → chunk-4K7JPALT.mjs} +5 -5
  2. package/dist/lib/browser/chunk-4K7JPALT.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GPZSXPSA.mjs → chunk-OZTXLZGM.mjs} +25 -43
  4. package/dist/lib/browser/chunk-OZTXLZGM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +123 -269
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +8 -6
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types/index.mjs +1 -1
  11. package/dist/lib/node-esm/{chunk-K734DJB7.mjs → chunk-MK6OVUF6.mjs} +5 -5
  12. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +7 -0
  13. package/dist/lib/node-esm/{chunk-XUD6W42C.mjs → chunk-S56Z4V4X.mjs} +25 -43
  14. package/dist/lib/node-esm/chunk-S56Z4V4X.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +123 -269
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +8 -6
  19. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/types/index.mjs +1 -1
  21. package/dist/types/src/components/Table/DynamicTable.d.ts +2 -2
  22. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +3 -3
  24. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/Relations.stories.d.ts +71 -7
  26. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/Table.d.ts +5 -2
  28. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Table.stories.d.ts +5 -6
  30. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +7 -5
  32. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  33. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -3
  34. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  35. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +1 -2
  36. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  38. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  39. package/dist/types/src/components/testing.d.ts +3 -3
  40. package/dist/types/src/components/testing.d.ts.map +1 -1
  41. package/dist/types/src/hooks/useAddRow.d.ts +1 -1
  42. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  43. package/dist/types/src/hooks/useTableModel.d.ts +1 -1
  44. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  45. package/dist/types/src/model/modal-controller.d.ts +0 -7
  46. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  47. package/dist/types/src/model/table-model.d.ts +1 -1
  48. package/dist/types/src/model/table-model.d.ts.map +1 -1
  49. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  50. package/dist/types/src/testing/useTestTableModel.d.ts +1 -1
  51. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  52. package/dist/types/src/types/schema.d.ts +3 -3
  53. package/dist/types/src/types/schema.d.ts.map +1 -1
  54. package/dist/types/src/util/dynamic-table.d.ts +3 -4
  55. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  56. package/dist/types/src/util/schema.d.ts +1 -1
  57. package/dist/types/src/util/schema.d.ts.map +1 -1
  58. package/dist/types/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +50 -50
  60. package/src/components/Table/DynamicTable.stories.tsx +8 -7
  61. package/src/components/Table/DynamicTable.tsx +4 -7
  62. package/src/components/Table/Relations.stories.tsx +126 -11
  63. package/src/components/Table/Table.stories.tsx +33 -32
  64. package/src/components/Table/Table.tsx +13 -9
  65. package/src/components/TableCellEditor/FormCellEditor.tsx +51 -41
  66. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +17 -45
  67. package/src/components/TableCellEditor/TableCellEditor.tsx +7 -94
  68. package/src/components/TableCellEditor/index.ts +1 -0
  69. package/src/components/testing.ts +2 -2
  70. package/src/hooks/useAddRow.ts +1 -1
  71. package/src/hooks/useTableModel.ts +1 -1
  72. package/src/model/modal-controller.ts +0 -28
  73. package/src/model/table-model.test.ts +16 -6
  74. package/src/model/table-model.ts +2 -1
  75. package/src/model/table-presentation.test.ts +19 -17
  76. package/src/model/table-presentation.ts +4 -5
  77. package/src/model/table-sorting.ts +1 -1
  78. package/src/testing/useTestTableModel.ts +6 -4
  79. package/src/types/schema.ts +4 -4
  80. package/src/util/dynamic-table.ts +6 -7
  81. package/src/util/schema.ts +4 -4
  82. package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
  83. package/dist/lib/browser/chunk-GPZSXPSA.mjs.map +0 -7
  84. package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
  85. package/dist/lib/node-esm/chunk-XUD6W42C.mjs.map +0 -7
  86. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  87. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  88. package/src/components/Table/CreateRefPanel.tsx +0 -103
@@ -15,8 +15,8 @@ import {
15
15
  touch,
16
16
  useAddRow,
17
17
  useTableModel
18
- } from "./chunk-GPZSXPSA.mjs";
19
- import "./chunk-63UUF4IG.mjs";
18
+ } from "./chunk-OZTXLZGM.mjs";
19
+ import "./chunk-4K7JPALT.mjs";
20
20
 
21
21
  // src/translations.ts
22
22
  var translationKey = "react-ui-table";
@@ -51,8 +51,9 @@ var translations = [
51
51
  ];
52
52
 
53
53
  // src/components/Table/Table.tsx
54
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
55
- import React8, { forwardRef, useCallback as useCallback5, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo5, useState as useState4 } from "react";
54
+ import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
55
+ import * as String2 from "effect/String";
56
+ import React7, { forwardRef, useCallback as useCallback4, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo4, useState as useState4 } from "react";
56
57
  import { useAttention } from "@dxos/react-ui-attention";
57
58
  import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
58
59
  import { DxEditRequest } from "@dxos/react-ui-grid";
@@ -63,11 +64,9 @@ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking"
63
64
  import { EditorView } from "@codemirror/view";
64
65
  import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
65
66
  import { debounce } from "@dxos/async";
66
- import { FormatEnum, TypeEnum } from "@dxos/echo-schema";
67
+ import { FormatEnum as FormatEnum2, TypeEnum } from "@dxos/echo/internal";
67
68
  import { invariant as invariant2 } from "@dxos/invariant";
68
- import { createMarkdownExtensions } from "@dxos/react-ui-editor";
69
69
  import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
70
- import { createLinks, tagPicker } from "@dxos/react-ui-tag-picker";
71
70
 
72
71
  // src/components/TableCellEditor/CellValidationMessage.tsx
73
72
  import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
@@ -102,16 +101,17 @@ var CellValidationMessage = ({ validationError, variant = "error", __gridScope }
102
101
 
103
102
  // src/components/TableCellEditor/FormCellEditor.tsx
104
103
  import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
104
+ import * as Schema from "effect/Schema";
105
105
  import React2, { useCallback, useEffect, useMemo, useRef, useState } from "react";
106
106
  import { Filter, Obj } from "@dxos/echo";
107
- import { Ref, getValue } from "@dxos/echo-schema";
107
+ import { FormatEnum, Ref, getValue } from "@dxos/echo/internal";
108
108
  import { invariant } from "@dxos/invariant";
109
109
  import { getSnapshot } from "@dxos/live-object";
110
110
  import { getSpace } from "@dxos/react-client/echo";
111
111
  import { Popover } from "@dxos/react-ui";
112
112
  import { Form } from "@dxos/react-ui-form";
113
- import { cellQuery, parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
114
- import { getDeep, isNotFalsy, setDeep } from "@dxos/util";
113
+ import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
114
+ import { getDeep, isTruthy, setDeep } from "@dxos/util";
115
115
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
116
116
  var createOptionLabel = [
117
117
  "create new object label",
@@ -119,7 +119,7 @@ var createOptionLabel = [
119
119
  ns: translationKey
120
120
  }
121
121
  ];
122
- var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, __gridScope, ...formProps }) => {
122
+ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, onCreate, __gridScope, ...formProps }) => {
123
123
  var _effect = _useSignals2();
124
124
  try {
125
125
  const { editing: contextEditing, setEditing, id: gridId } = useGridContext2("ArrayEditor", __gridScope);
@@ -129,7 +129,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
129
129
  const space = getSpace(model.view);
130
130
  invariant(space, void 0, {
131
131
  F: __dxlog_file,
132
- L: 53,
132
+ L: 57,
133
133
  S: void 0,
134
134
  A: [
135
135
  "space",
@@ -160,7 +160,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
160
160
  dxn: Obj.getDXN(obj),
161
161
  label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
162
162
  };
163
- }).filter(isNotFalsy);
163
+ }).filter(isTruthy);
164
164
  }
165
165
  return [];
166
166
  }, [
@@ -174,7 +174,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
174
174
  const draftRow = model.draftRows.value[cell.row];
175
175
  invariant(draftRow, void 0, {
176
176
  F: __dxlog_file,
177
- L: 94,
177
+ L: 98,
178
178
  S: void 0,
179
179
  A: [
180
180
  "draftRow",
@@ -186,7 +186,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
186
186
  const row = model.getRowAt(cell.row);
187
187
  invariant(row, void 0, {
188
188
  F: __dxlog_file,
189
- L: 98,
189
+ L: 102,
190
190
  S: void 0,
191
191
  A: [
192
192
  "row",
@@ -219,38 +219,6 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
219
219
  contextEditing,
220
220
  originalRow
221
221
  ]);
222
- const handleCreate = useCallback((object) => {
223
- const ref = Ref.make(object);
224
- const path = fieldProjection.field.path;
225
- setDeep(originalRow, [
226
- path
227
- ], ref);
228
- contextEditing?.cellElement?.focus();
229
- setEditing(null);
230
- setLocalEditing(false);
231
- onSave?.();
232
- }, [
233
- fieldProjection.field.path,
234
- onSave,
235
- contextEditing,
236
- originalRow
237
- ]);
238
- const handleCreateFromQuery = useCallback(async (typeAnnotation, query) => {
239
- if (model && modals && contextEditing?.index) {
240
- setLocalEditing(false);
241
- modals.openCreateRef(typeAnnotation.typename, document.querySelector(cellQuery(contextEditing.index, gridId)), {
242
- [fieldProjection.field.referencePath]: query
243
- }, handleCreate);
244
- }
245
- }, [
246
- model,
247
- modals,
248
- client,
249
- contextEditing?.index,
250
- gridId,
251
- fieldProjection,
252
- handleSave
253
- ]);
254
222
  useEffect(() => {
255
223
  if (contextEditing && contextEditing.cellElement) {
256
224
  anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
@@ -283,6 +251,46 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
283
251
  }
284
252
  setLocalEditing(nextOpen);
285
253
  }, []);
254
+ const createSchema = useMemo(() => {
255
+ if (fieldProjection.props.format === FormatEnum.Ref && fieldProjection.props.referenceSchema) {
256
+ const { schema: refSchema } = getSchema({
257
+ typename: fieldProjection.props.referenceSchema
258
+ });
259
+ if (!refSchema) {
260
+ return null;
261
+ }
262
+ const omit2 = Schema.omit("id");
263
+ return omit2(refSchema);
264
+ }
265
+ return null;
266
+ }, [
267
+ fieldProjection.props.format,
268
+ fieldProjection.props.referenceSchema,
269
+ getSchema
270
+ ]);
271
+ const handleCreate = useCallback((values) => {
272
+ if (schema && onCreate) {
273
+ const objectWithId = onCreate(schema, values);
274
+ if (objectWithId) {
275
+ const ref = Ref.make(objectWithId);
276
+ const path = fieldProjection.field.path;
277
+ setDeep(originalRow, [
278
+ path
279
+ ], ref);
280
+ }
281
+ }
282
+ contextEditing?.cellElement?.focus();
283
+ setEditing(null);
284
+ setLocalEditing(false);
285
+ onSave?.();
286
+ }, [
287
+ fieldProjection.field.path,
288
+ onSave,
289
+ contextEditing,
290
+ originalRow,
291
+ createSchema,
292
+ onCreate
293
+ ]);
286
294
  if (!editing) {
287
295
  return null;
288
296
  }
@@ -301,9 +309,13 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
301
309
  onSave: handleSave,
302
310
  ...formProps,
303
311
  onQueryRefOptions: handleQueryRefOptions,
304
- onCreateFromQuery: handleCreateFromQuery,
305
- createOptionIcon: "ph--plus--regular",
306
- createOptionLabel
312
+ ...createSchema && {
313
+ onCreate: handleCreate,
314
+ createSchema,
315
+ createInitialValuePath: fieldProjection.field.referencePath,
316
+ createOptionIcon: "ph--plus--regular",
317
+ createOptionLabel
318
+ }
307
319
  })))));
308
320
  } finally {
309
321
  _effect.f();
@@ -313,7 +325,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
313
325
  // src/components/TableCellEditor/TableCellEditor.tsx
314
326
  var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
315
327
  var adaptValidationMessage = (message) => message ? message.endsWith("is missing") ? "Can\u2019t be blank" : message : null;
316
- var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __gridScope }) => {
328
+ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, onCreate, client, __gridScope }) => {
317
329
  var _effect = _useSignals3();
318
330
  try {
319
331
  const { editing } = useGridContext3("TableValueEditor", __gridScope);
@@ -338,13 +350,14 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __grid
338
350
  model,
339
351
  editing
340
352
  ]);
341
- if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === FormatEnum.SingleSelect || fieldProjection?.props.format === FormatEnum.Ref) {
353
+ if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === FormatEnum2.SingleSelect || fieldProjection?.props.format === FormatEnum2.Ref) {
342
354
  return /* @__PURE__ */ React3.createElement(FormCellEditor, {
343
355
  fieldProjection,
344
356
  model,
345
357
  schema,
346
358
  __gridScope,
347
359
  onSave,
360
+ onCreate,
348
361
  client,
349
362
  modals
350
363
  });
@@ -381,7 +394,7 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
381
394
  const fieldProjection2 = model.projection.getFieldProjection(field.id);
382
395
  invariant2(fieldProjection2, void 0, {
383
396
  F: __dxlog_file2,
384
- L: 120,
397
+ L: 121,
385
398
  S: void 0,
386
399
  A: [
387
400
  "fieldProjection",
@@ -483,35 +496,6 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
483
496
  }
484
497
  })
485
498
  ];
486
- const format = fieldProjection.props.format;
487
- if (format === FormatEnum.SingleSelect || format === FormatEnum.MultiSelect) {
488
- const options = fieldProjection.props.options || [];
489
- const mode = format === FormatEnum.SingleSelect ? "single-select" : "multi-select";
490
- extensions2.push(createMarkdownExtensions());
491
- extensions2.push(tagPicker({
492
- mode,
493
- keymap: false,
494
- onSearch: (text, selectedIds) => {
495
- return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
496
- id: option.id,
497
- label: option.title,
498
- hue: option.color
499
- }));
500
- },
501
- onUpdate: (ids) => {
502
- if (model && editing) {
503
- if (ids.length === 0) {
504
- return;
505
- }
506
- if (mode === "single-select") {
507
- void handleEnter(ids[0]);
508
- } else {
509
- void handleEnter(ids);
510
- }
511
- }
512
- }
513
- }));
514
- }
515
499
  if (model && editing) {
516
500
  extensions2.push(EditorView.updateListener.of(debounce((update) => {
517
501
  const content = update.state.doc.toString();
@@ -537,42 +521,6 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
537
521
  const getCellContent = useCallback2(() => {
538
522
  if (model && editing) {
539
523
  const cell = parseCellIndex2(editing.index);
540
- const { col } = cell;
541
- const field = model.projection.fields[col];
542
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
543
- if (fieldProjection2?.props.format === FormatEnum.SingleSelect || fieldProjection2?.props.format === FormatEnum.MultiSelect) {
544
- const value2 = model.getCellData(cell);
545
- if (value2 !== void 0) {
546
- const options = fieldProjection2.props.options || [];
547
- if (fieldProjection2.props.format === FormatEnum.MultiSelect) {
548
- const tagItems = value2.split(",").map((id) => {
549
- const option = options.find((o) => o.id === id);
550
- if (option) {
551
- return {
552
- id,
553
- label: option.title,
554
- hue: option.color
555
- };
556
- }
557
- return void 0;
558
- }).filter((item) => item !== void 0);
559
- return createLinks(tagItems);
560
- } else {
561
- const option = options.find((o) => o.id === value2);
562
- if (option) {
563
- const tagItem = {
564
- id: value2,
565
- label: option.title,
566
- hue: option.color
567
- };
568
- return createLinks([
569
- tagItem
570
- ]);
571
- }
572
- }
573
- }
574
- return "";
575
- }
576
524
  const value = model.getCellData(cell);
577
525
  return value !== void 0 ? String(value) : "";
578
526
  }
@@ -732,106 +680,12 @@ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
732
680
  }
733
681
  };
734
682
 
735
- // src/components/Table/CreateRefPanel.tsx
736
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
737
- import { Schema } from "effect";
738
- import React6, { useCallback as useCallback4, useMemo as useMemo4 } from "react";
739
- import { Type } from "@dxos/echo";
740
- import { live } from "@dxos/live-object";
741
- import { useClient } from "@dxos/react-client";
742
- import { getSpace as getSpace2 } from "@dxos/react-client/echo";
743
- import { Popover as Popover3 } from "@dxos/react-ui";
744
- import { Form as Form2 } from "@dxos/react-ui-form";
745
- import { useGridContext as useGridContext4 } from "@dxos/react-ui-grid";
746
- var CreateRefPanel = ({ model, modals, __gridScope }) => {
747
- var _effect = _useSignals6();
748
- try {
749
- const { id: gridId } = useGridContext4("TableCellEditor", __gridScope);
750
- const client = useClient();
751
- const space = model && getSpace2(model?.view);
752
- const state = modals.state.value;
753
- const getSchema = useCallback4(() => {
754
- if (!space || state?.type !== "createRefPanel") {
755
- return;
756
- }
757
- const staticSchema = client.graph.schemaRegistry.schemas.find((schema3) => Type.getTypename(schema3) === state.typename);
758
- if (staticSchema) {
759
- return staticSchema;
760
- }
761
- const [schema2] = space.db.schemaRegistry.query({
762
- typename: state.typename
763
- }).runSync();
764
- return schema2;
765
- }, [
766
- space,
767
- state
768
- ]);
769
- const schema = useMemo4(() => {
770
- const schema2 = getSchema();
771
- if (!schema2) {
772
- return;
773
- }
774
- const omit = Schema.omit("id");
775
- return omit(schema2);
776
- }, [
777
- getSchema
778
- ]);
779
- const handleSave = useCallback4((values) => {
780
- if (!model || !space || state?.type !== "createRefPanel") {
781
- return;
782
- }
783
- const schema2 = getSchema();
784
- if (schema2) {
785
- const obj = space.db.add(live(schema2, values));
786
- state.onCreate?.(obj);
787
- }
788
- void modals.close();
789
- }, [
790
- model,
791
- modals,
792
- space,
793
- state
794
- ]);
795
- const handleCancel = useCallback4(() => {
796
- if (model) {
797
- modals.close();
798
- }
799
- }, [
800
- modals
801
- ]);
802
- if (!model?.projection) {
803
- return null;
804
- }
805
- return /* @__PURE__ */ React6.createElement(Popover3.Root, {
806
- modal: false,
807
- open: state?.type === "createRefPanel" && !!schema,
808
- onOpenChange: (nextOpen) => {
809
- if (model && !nextOpen) {
810
- return modals.close();
811
- }
812
- }
813
- }, /* @__PURE__ */ React6.createElement(Popover3.VirtualTrigger, {
814
- virtualRef: modals.trigger
815
- }), /* @__PURE__ */ React6.createElement(Popover3.Portal, null, /* @__PURE__ */ React6.createElement(Popover3.Content, {
816
- classNames: "md:is-64",
817
- "data-grid": gridId
818
- }, /* @__PURE__ */ React6.createElement(Popover3.Viewport, null, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React6.createElement(Form2, {
819
- schema,
820
- values: state.initialValues ?? {},
821
- onSave: handleSave,
822
- onCancel: handleCancel
823
- })), /* @__PURE__ */ React6.createElement(Popover3.Arrow, null))));
824
- } finally {
825
- _effect.f();
826
- }
827
- };
828
-
829
683
  // src/components/Table/RowActionsMenu.tsx
830
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
831
- import React7 from "react";
684
+ import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
685
+ import React6 from "react";
832
686
  import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
833
687
  var RowActionsMenu = ({ model, modals }) => {
834
- var _effect = _useSignals7();
688
+ var _effect = _useSignals6();
835
689
  try {
836
690
  const { t } = useTranslation2(translationKey);
837
691
  const hasSelection = model.selection.hasSelection.value;
@@ -839,23 +693,23 @@ var RowActionsMenu = ({ model, modals }) => {
839
693
  if (state?.type !== "row") {
840
694
  return null;
841
695
  }
842
- return /* @__PURE__ */ React7.createElement(DropdownMenu2.Root, {
696
+ return /* @__PURE__ */ React6.createElement(DropdownMenu2.Root, {
843
697
  modal: false,
844
698
  open: true,
845
699
  onOpenChange: modals.close
846
- }, /* @__PURE__ */ React7.createElement(DropdownMenu2.VirtualTrigger, {
700
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu2.VirtualTrigger, {
847
701
  virtualRef: modals.trigger
848
- }), /* @__PURE__ */ React7.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React7.createElement(DropdownMenu2.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
702
+ }), /* @__PURE__ */ React6.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
849
703
  "data-testid": "row-menu-delete",
850
704
  onClick: () => model.deleteRow(state.rowIndex)
851
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
705
+ }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
852
706
  key: action.id,
853
707
  "data-testid": `row-action-${action.id}`,
854
708
  onClick: () => {
855
709
  modals.close();
856
710
  model.handleRowAction(action.id, state.rowIndex);
857
711
  }
858
- }, toLocalizedString(action.label, t)))), /* @__PURE__ */ React7.createElement(DropdownMenu2.Arrow, null)));
712
+ }, toLocalizedString(action.label, t)))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Arrow, null)));
859
713
  } finally {
860
714
  _effect.f();
861
715
  }
@@ -875,9 +729,9 @@ var rowDefault = {
875
729
  }
876
730
  };
877
731
  var TableRoot = ({ children, role = "article" }) => {
878
- var _effect = _useSignals8();
732
+ var _effect = _useSignals7();
879
733
  try {
880
- return /* @__PURE__ */ React8.createElement("div", {
734
+ return /* @__PURE__ */ React7.createElement("div", {
881
735
  role: "none",
882
736
  className: mx("relative !border-separator [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]", role === "card--popover" && "popover-card-height", role === "section" && "attention-surface", role === "card--intrinsic" && "[&_.dx-grid]:bs-[--dx-grid-content-block-size]", [
883
737
  "card--popover",
@@ -892,20 +746,20 @@ var TableRoot = ({ children, role = "article" }) => {
892
746
  _effect.f();
893
747
  }
894
748
  };
895
- var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onRowClick }, forwardedRef) => {
896
- var _effect = _useSignals8();
749
+ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onCreate, onRowClick, testId }, forwardedRef) => {
750
+ var _effect = _useSignals7();
897
751
  try {
898
752
  const [dxGrid, setDxGrid] = useState4(null);
899
753
  const { hasAttention } = useAttention(model?.id ?? "table");
900
- const modals = useMemo5(() => new ModalController(), []);
754
+ const modals = useMemo4(() => new ModalController(), []);
901
755
  const draftRowCount = model?.getDraftRowCount() ?? 0;
902
- const handleSave = useCallback5(() => {
756
+ const handleSave = useCallback4(() => {
903
757
  dxGrid?.updateCells(true);
904
758
  dxGrid?.requestUpdate();
905
759
  }, [
906
760
  dxGrid
907
761
  ]);
908
- const frozen = useMemo5(() => {
762
+ const frozen = useMemo4(() => {
909
763
  const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
910
764
  return {
911
765
  frozenRowsStart: 1,
@@ -917,7 +771,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
917
771
  model,
918
772
  draftRowCount
919
773
  ]);
920
- const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
774
+ const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
921
775
  presentation
922
776
  ]);
923
777
  useEffect3(() => {
@@ -930,7 +784,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
930
784
  dxGrid,
931
785
  getCells
932
786
  ]);
933
- const handleInsertRowResult = useCallback5((insertResult) => {
787
+ const handleInsertRowResult = useCallback4((insertResult) => {
934
788
  if (insertResult === "draft") {
935
789
  requestAnimationFrame(() => {
936
790
  dxGrid?.setFocus({
@@ -974,7 +828,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
974
828
  dxGrid,
975
829
  model
976
830
  ]);
977
- const handleSaveDraftRow = useCallback5((rowIndex = 0) => {
831
+ const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
978
832
  if (model && dxGrid) {
979
833
  const didCommitSuccessfully = model.commitDraftRow(rowIndex);
980
834
  if (didCommitSuccessfully) {
@@ -987,7 +841,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
987
841
  model,
988
842
  dxGrid
989
843
  ]);
990
- const handleGridClick = useCallback5((event) => {
844
+ const handleGridClick = useCallback4((event) => {
991
845
  const cell = closestCell(event.target);
992
846
  if (cell) {
993
847
  const { row: rowIndex, plane } = cell;
@@ -1072,9 +926,9 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1072
926
  modals,
1073
927
  dxGrid
1074
928
  ]);
1075
- const handleFocus = useCallback5((increment, delta, cell) => {
929
+ const handleFocus = useCallback4((increment, delta, cell) => {
1076
930
  if (dxGrid && model) {
1077
- if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1) {
931
+ if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1 && increment !== "col") {
1078
932
  handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
1079
933
  } else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
1080
934
  handleSaveDraftRow(cell.row);
@@ -1087,7 +941,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1087
941
  dxGrid,
1088
942
  model
1089
943
  ]);
1090
- const handleKeyDown = useCallback5((event) => {
944
+ const handleKeyDown = useCallback4((event) => {
1091
945
  if (!model?.features.dataEditable) {
1092
946
  return;
1093
947
  }
@@ -1112,7 +966,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1112
966
  event.preventDefault();
1113
967
  void navigator.clipboard.readText().then((clipboardText) => {
1114
968
  try {
1115
- model.setCellData(cell, clipboardText);
969
+ model.setCellData(cell, String2.trim(clipboardText).replace(/[\n\r]+/, " "));
1116
970
  handleSave();
1117
971
  } catch {
1118
972
  const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
@@ -1143,6 +997,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1143
997
  try {
1144
998
  model.setCellData(cell, void 0);
1145
999
  event.preventDefault();
1000
+ handleSave();
1146
1001
  } catch {
1147
1002
  }
1148
1003
  break;
@@ -1153,7 +1008,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1153
1008
  dxGrid,
1154
1009
  handleSave
1155
1010
  ]);
1156
- const handleAxisResize = useCallback5((event) => {
1011
+ const handleAxisResize = useCallback4((event) => {
1157
1012
  if (event.axis === "col") {
1158
1013
  const columnIndex = parseInt(event.index, 10);
1159
1014
  model?.setColumnWidth(columnIndex, event.size);
@@ -1161,7 +1016,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1161
1016
  }, [
1162
1017
  model
1163
1018
  ]);
1164
- const handleWheel = useCallback5((event) => {
1019
+ const handleWheel = useCallback4((event) => {
1165
1020
  if (!ignoreAttention && !hasAttention) {
1166
1021
  event.stopPropagation();
1167
1022
  }
@@ -1169,7 +1024,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1169
1024
  hasAttention,
1170
1025
  ignoreAttention
1171
1026
  ]);
1172
- const handleNewColumn = useCallback5(() => {
1027
+ const handleNewColumn = useCallback4(() => {
1173
1028
  const columns = model?.getColumnCount();
1174
1029
  if (dxGrid && columns) {
1175
1030
  dxGrid.scrollToColumn(columns - 1);
@@ -1179,21 +1034,22 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1179
1034
  dxGrid
1180
1035
  ]);
1181
1036
  if (!model || !modals) {
1182
- return /* @__PURE__ */ React8.createElement("span", {
1037
+ return /* @__PURE__ */ React7.createElement("span", {
1183
1038
  role: "none",
1184
1039
  className: "attention-surface"
1185
1040
  });
1186
1041
  }
1187
- return /* @__PURE__ */ React8.createElement(Grid.Root, {
1042
+ return /* @__PURE__ */ React7.createElement(Grid.Root, {
1188
1043
  id: model.id ?? "table-grid"
1189
- }, /* @__PURE__ */ React8.createElement(TableValueEditor, {
1044
+ }, /* @__PURE__ */ React7.createElement(TableValueEditor, {
1190
1045
  model,
1191
1046
  modals,
1192
1047
  schema,
1193
1048
  onFocus: handleFocus,
1194
1049
  onSave: handleSave,
1050
+ onCreate,
1195
1051
  client
1196
- }), /* @__PURE__ */ React8.createElement(Grid.Content, {
1052
+ }), /* @__PURE__ */ React7.createElement(Grid.Content, {
1197
1053
  className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
1198
1054
  frozen,
1199
1055
  columns: model.columnMeta.value,
@@ -1206,20 +1062,20 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1206
1062
  onClick: handleGridClick,
1207
1063
  onKeyDownCapture: handleKeyDown,
1208
1064
  onWheelCapture: handleWheel,
1065
+ ...testId && {
1066
+ "data-testid": testId
1067
+ },
1209
1068
  ref: setDxGrid
1210
- }), /* @__PURE__ */ React8.createElement(RowActionsMenu, {
1069
+ }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
1211
1070
  model,
1212
1071
  modals
1213
- }), /* @__PURE__ */ React8.createElement(ColumnActionsMenu, {
1072
+ }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
1214
1073
  model,
1215
1074
  modals
1216
- }), /* @__PURE__ */ React8.createElement(ColumnSettings, {
1075
+ }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
1217
1076
  model,
1218
1077
  modals,
1219
1078
  onNewColumn: handleNewColumn
1220
- }), /* @__PURE__ */ React8.createElement(CreateRefPanel, {
1221
- model,
1222
- modals
1223
1079
  }));
1224
1080
  } finally {
1225
1081
  _effect.f();
@@ -1231,14 +1087,14 @@ var Table = {
1231
1087
  };
1232
1088
 
1233
1089
  // src/components/Table/DynamicTable.tsx
1234
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1235
- import React9, { useCallback as useCallback6, useMemo as useMemo6, useRef as useRef3 } from "react";
1090
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
1091
+ import React8, { useCallback as useCallback5, useMemo as useMemo5, useRef as useRef3 } from "react";
1236
1092
  import { useDefaultValue } from "@dxos/react-ui";
1237
1093
  import { mx as mx2 } from "@dxos/react-ui-theme";
1238
1094
  var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
1239
- var _effect = _useSignals9();
1095
+ var _effect = _useSignals8();
1240
1096
  try {
1241
- const { typename, jsonSchema } = useMemo6(() => getBaseSchema({
1097
+ const { jsonSchema } = useMemo5(() => getBaseSchema({
1242
1098
  typename: name,
1243
1099
  properties,
1244
1100
  jsonSchema: _jsonSchema,
@@ -1249,20 +1105,18 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
1249
1105
  _jsonSchema,
1250
1106
  schema
1251
1107
  ]);
1252
- const { projection, view } = useMemo6(() => makeDynamicTable({
1253
- typename,
1108
+ const { projection, view } = useMemo5(() => makeDynamicTable({
1254
1109
  jsonSchema,
1255
1110
  properties
1256
1111
  }), [
1257
- typename,
1258
1112
  jsonSchema,
1259
1113
  properties
1260
1114
  ]);
1261
1115
  const tableRef = useRef3(null);
1262
- const handleCellUpdate = useCallback6((cell) => {
1116
+ const handleCellUpdate = useCallback5((cell) => {
1263
1117
  tableRef.current?.update?.(cell);
1264
1118
  }, []);
1265
- const handleRowOrderChange = useCallback6(() => {
1119
+ const handleRowOrderChange = useCallback5(() => {
1266
1120
  tableRef.current?.update?.();
1267
1121
  }, []);
1268
1122
  const features = useDefaultValue(props.features, () => ({
@@ -1282,20 +1136,20 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
1282
1136
  onRowOrderChange: handleRowOrderChange,
1283
1137
  onRowAction
1284
1138
  });
1285
- const presentation = useMemo6(() => {
1139
+ const presentation = useMemo5(() => {
1286
1140
  if (model) {
1287
1141
  return new TablePresentation(model);
1288
1142
  }
1289
1143
  }, [
1290
1144
  model
1291
1145
  ]);
1292
- return /* @__PURE__ */ React9.createElement("div", {
1146
+ return /* @__PURE__ */ React8.createElement("div", {
1293
1147
  role: "none",
1294
1148
  className: mx2("is-full bs-full grow grid", classNames)
1295
- }, /* @__PURE__ */ React9.createElement("div", {
1149
+ }, /* @__PURE__ */ React8.createElement("div", {
1296
1150
  role: "none",
1297
1151
  className: "grid min-bs-0 overflow-hidden"
1298
- }, /* @__PURE__ */ React9.createElement(Table.Root, null, /* @__PURE__ */ React9.createElement(Table.Main, {
1152
+ }, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
1299
1153
  ref: tableRef,
1300
1154
  model,
1301
1155
  presentation,
@@ -1308,10 +1162,10 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
1308
1162
  };
1309
1163
 
1310
1164
  // src/components/TableToolbar/TableToolbar.tsx
1311
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
1165
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1312
1166
  import { Rx } from "@effect-rx/rx-react";
1313
- import React10, { useMemo as useMemo7 } from "react";
1314
- import { live as live2 } from "@dxos/live-object";
1167
+ import React9, { useMemo as useMemo6 } from "react";
1168
+ import { live } from "@dxos/live-object";
1315
1169
  import { MenuProvider, ToolbarMenu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
1316
1170
  import { rxFromSignal } from "@dxos/react-ui-menu";
1317
1171
  var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.make((get) => {
@@ -1360,12 +1214,12 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.
1360
1214
  };
1361
1215
  });
1362
1216
  var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
1363
- var _effect = _useSignals10();
1217
+ var _effect = _useSignals9();
1364
1218
  try {
1365
- const state = useMemo7(() => live2({
1219
+ const state = useMemo6(() => live({
1366
1220
  viewDirty
1367
1221
  }), []);
1368
- const actionsCreator = useMemo7(() => createTableToolbarActions({
1222
+ const actionsCreator = useMemo6(() => createTableToolbarActions({
1369
1223
  state,
1370
1224
  onAdd,
1371
1225
  onSave,
@@ -1377,10 +1231,10 @@ var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, custom
1377
1231
  customActions
1378
1232
  ]);
1379
1233
  const menu = useMenuActions(actionsCreator);
1380
- return /* @__PURE__ */ React10.createElement(MenuProvider, {
1234
+ return /* @__PURE__ */ React9.createElement(MenuProvider, {
1381
1235
  ...menu,
1382
1236
  attendableId
1383
- }, /* @__PURE__ */ React10.createElement(ToolbarMenu, {
1237
+ }, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
1384
1238
  classNames
1385
1239
  }));
1386
1240
  } finally {