@dxos/react-ui-table 0.8.4-main.5ea62a8 → 0.8.4-main.ae835ea

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