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