@dxos/react-ui-table 0.8.4-main.67995b8 → 0.8.4-main.69d29f4

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 (155) hide show
  1. package/dist/lib/browser/chunk-I5IFW7UF.mjs +1746 -0
  2. package/dist/lib/browser/chunk-I5IFW7UF.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-OZBLY7XM.mjs +76 -0
  4. package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1163 -1120
  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 +30 -37
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types/index.mjs +3 -3
  11. package/dist/lib/node-esm/chunk-DDJKYJFY.mjs +1748 -0
  12. package/dist/lib/node-esm/chunk-DDJKYJFY.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs +77 -0
  14. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1163 -1120
  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 +30 -37
  19. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/types/index.mjs +3 -3
  21. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -3
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -3
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +5 -6
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +37 -3
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  32. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.d.ts +13 -9
  34. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/Table.stories.d.ts +108 -4
  36. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  38. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  39. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +13 -9
  40. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +11 -18
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  43. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
  44. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  45. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  46. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  47. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +4 -4
  48. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  49. package/dist/types/src/components/testing.d.ts +23 -16
  50. package/dist/types/src/components/testing.d.ts.map +1 -1
  51. package/dist/types/src/hooks/index.d.ts +2 -1
  52. package/dist/types/src/hooks/index.d.ts.map +1 -1
  53. package/dist/types/src/hooks/useAddRow.d.ts +6 -6
  54. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  55. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  56. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  57. package/dist/types/src/hooks/useTableModel.d.ts +9 -9
  58. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  59. package/dist/types/src/model/modal-controller.d.ts +5 -8
  60. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  61. package/dist/types/src/model/selection-model.d.ts +17 -8
  62. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  63. package/dist/types/src/model/table-model.d.ts +109 -28
  64. package/dist/types/src/model/table-model.d.ts.map +1 -1
  65. package/dist/types/src/model/table-presentation.d.ts +5 -2
  66. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  67. package/dist/types/src/playwright/TableManager.d.ts +1 -1
  68. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  69. package/dist/types/src/testing/useTestTableModel.d.ts +18 -34
  70. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  71. package/dist/types/src/translations.d.ts +4 -4
  72. package/dist/types/src/translations.d.ts.map +1 -1
  73. package/dist/types/src/types/Table.d.ts +31 -0
  74. package/dist/types/src/types/Table.d.ts.map +1 -0
  75. package/dist/types/src/types/index.d.ts +1 -1
  76. package/dist/types/src/types/index.d.ts.map +1 -1
  77. package/dist/types/src/util/dynamic-table.d.ts +13 -12
  78. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  79. package/dist/types/src/util/index.d.ts +2 -1
  80. package/dist/types/src/util/index.d.ts.map +1 -1
  81. package/dist/types/src/util/query-ast.d.ts +7 -0
  82. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  83. package/dist/types/src/util/schema.d.ts +1 -1
  84. package/dist/types/src/util/schema.d.ts.map +1 -1
  85. package/dist/types/src/util/sort.d.ts +12 -0
  86. package/dist/types/src/util/sort.d.ts.map +1 -0
  87. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  88. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  89. package/dist/types/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +65 -64
  91. package/src/components/Table/ColumnActionsMenu.tsx +11 -7
  92. package/src/components/Table/ColumnSettings.tsx +7 -7
  93. package/src/components/Table/DynamicTable.stories.tsx +25 -22
  94. package/src/components/Table/DynamicTable.tsx +26 -21
  95. package/src/components/Table/Relations.stories.tsx +237 -0
  96. package/src/components/Table/RowActionsMenu.tsx +26 -17
  97. package/src/components/Table/Table.stories.tsx +110 -102
  98. package/src/components/Table/Table.tsx +353 -298
  99. package/src/components/TableCellEditor/CellValidationMessage.tsx +2 -2
  100. package/src/components/TableCellEditor/FormCellEditor.tsx +128 -40
  101. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +30 -66
  102. package/src/components/TableCellEditor/TableCellEditor.tsx +88 -238
  103. package/src/components/TableCellEditor/index.ts +1 -0
  104. package/src/components/TableToolbar/TableToolbar.tsx +49 -33
  105. package/src/components/testing.ts +39 -13
  106. package/src/hooks/index.ts +2 -1
  107. package/src/hooks/useAddRow.ts +14 -14
  108. package/src/hooks/useProjectionModel.ts +39 -0
  109. package/src/hooks/useTableModel.ts +35 -33
  110. package/src/model/modal-controller.ts +24 -41
  111. package/src/model/selection-model.ts +75 -43
  112. package/src/model/table-model.test.ts +92 -55
  113. package/src/model/table-model.ts +445 -168
  114. package/src/model/table-presentation.test.ts +70 -58
  115. package/src/model/table-presentation.ts +103 -57
  116. package/src/playwright/TableManager.ts +5 -5
  117. package/src/playwright/playwright.config.ts +1 -1
  118. package/src/playwright/smoke.spec.ts +135 -40
  119. package/src/testing/useTestTableModel.ts +45 -34
  120. package/src/translations.ts +3 -3
  121. package/src/types/Table.ts +90 -0
  122. package/src/types/index.ts +1 -1
  123. package/src/util/dynamic-table.ts +44 -32
  124. package/src/util/index.ts +2 -1
  125. package/src/util/query-ast.ts +19 -0
  126. package/src/util/schema.ts +4 -4
  127. package/src/util/sort.ts +90 -0
  128. package/src/util/table-buttons.ts +4 -3
  129. package/src/util/table-controls.ts +4 -1
  130. package/dist/lib/browser/chunk-5XLSHLOG.mjs +0 -1751
  131. package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
  132. package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
  133. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
  134. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
  135. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
  136. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs +0 -1752
  137. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
  138. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  139. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  140. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  141. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  142. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  143. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  144. package/dist/types/src/model/table-sorting.d.ts +0 -53
  145. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  146. package/dist/types/src/types/schema.d.ts +0 -8
  147. package/dist/types/src/types/schema.d.ts.map +0 -1
  148. package/dist/types/src/util/table.d.ts +0 -11
  149. package/dist/types/src/util/table.d.ts.map +0 -1
  150. package/src/components/Table/CreateRefPanel.tsx +0 -86
  151. package/src/components/Table/relations.stories.tsx +0 -116
  152. package/src/components/TableCellEditor/extension.ts +0 -61
  153. package/src/model/table-sorting.ts +0 -216
  154. package/src/types/schema.ts +0 -16
  155. package/src/util/table.ts +0 -49
@@ -2,25 +2,27 @@ import {
2
2
  BUTTON_IDENTIFIERS,
3
3
  CONTROL_IDENTIFIERS,
4
4
  CheckboxStory,
5
- ModalController,
6
5
  SwitchStory,
7
6
  TableModel,
8
7
  TablePresentation,
9
8
  cellClassesForRowSelection,
10
- createTable,
11
- getBaseSchema,
12
- makeDynamicTable,
13
- narrowSchema,
9
+ compareValues,
10
+ createDirectChangeCallback,
11
+ createEchoChangeCallback,
12
+ extractOrder,
13
+ getSortValue,
14
14
  tableButtons,
15
15
  tableControls,
16
- touch,
17
16
  useAddRow,
17
+ useProjectionModel,
18
18
  useTableModel
19
- } from "./chunk-5XLSHLOG.mjs";
20
- import "./chunk-L2LSB6KV.mjs";
19
+ } from "./chunk-I5IFW7UF.mjs";
20
+ import {
21
+ Table_exports
22
+ } from "./chunk-OZBLY7XM.mjs";
21
23
 
22
24
  // src/translations.ts
23
- var translationKey = "react-ui-table";
25
+ var translationKey = "@dxos/react-ui-table";
24
26
  var translations = [
25
27
  {
26
28
  "en-US": {
@@ -29,8 +31,8 @@ var translations = [
29
31
  "create object label": "Create table",
30
32
  "table name placeholder": "Table name",
31
33
  "settings title": "Table settings",
32
- "table schema label": "Schema",
33
- "new schema": "New schema",
34
+ "table schema label": "Type",
35
+ "new schema": "New type",
34
36
  "continue label": "Continue",
35
37
  "create stack section label": "Create table",
36
38
  "add row label": "Add row",
@@ -52,333 +54,284 @@ var translations = [
52
54
  ];
53
55
 
54
56
  // src/components/Table/Table.tsx
55
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
56
- import React8, { forwardRef, useCallback as useCallback5, useImperativeHandle, useState as useState4, useMemo as useMemo5, useEffect as useEffect4 } from "react";
57
- import { Filter } from "@dxos/echo";
58
- import { getValue } from "@dxos/echo-schema";
59
- import { invariant as invariant3 } from "@dxos/invariant";
60
- import { getSpace as getSpace2 } from "@dxos/react-client/echo";
61
- import { useTranslation as useTranslation3 } from "@dxos/react-ui";
57
+ import { Atom as Atom2, RegistryContext, useAtomValue as useAtomValue4 } from "@effect-atom/atom-react";
58
+ import * as String2 from "effect/String";
59
+ import React7, { forwardRef, useCallback as useCallback4, useContext, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo4, useState as useState4 } from "react";
60
+ import { log } from "@dxos/log";
62
61
  import { useAttention } from "@dxos/react-ui-attention";
63
- import { closestCell, Grid, gridSeparatorInlineEnd, gridSeparatorBlockEnd } from "@dxos/react-ui-grid";
64
- import { mx } from "@dxos/react-ui-theme";
65
- import { isNotFalsy, safeParseInt } from "@dxos/util";
62
+ import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
63
+ import { DxEditRequest } from "@dxos/react-ui-grid";
64
+ import { mx } from "@dxos/ui-theme";
66
65
 
67
- // src/components/Table/ColumnActionsMenu.tsx
68
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
69
- import React from "react";
70
- import { DropdownMenu, useTranslation } from "@dxos/react-ui";
71
- var ColumnActionsMenu = ({ model, modals }) => {
72
- var _effect = _useSignals();
73
- try {
74
- const { t } = useTranslation(translationKey);
75
- const state = modals.state.value;
76
- if (state?.type !== "column") {
77
- return null;
66
+ // src/util/dynamic-table.ts
67
+ import { Filter, Obj, Order, Query, Ref, Type } from "@dxos/echo";
68
+ import { ProjectionModel, View, createDirectChangeCallback as createDirectChangeCallback2, getSchemaFromPropertyDefinitions } from "@dxos/schema";
69
+ var getBaseSchema = ({ schema, typename, properties, jsonSchema }) => {
70
+ if (typename && properties) {
71
+ const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
72
+ return {
73
+ typename: schema2.typename,
74
+ jsonSchema: schema2.jsonSchema
75
+ };
76
+ } else if (schema) {
77
+ return {
78
+ typename: Type.getTypename(schema),
79
+ jsonSchema: Type.toJsonSchema(schema)
80
+ };
81
+ } else if (typename && jsonSchema) {
82
+ return {
83
+ typename,
84
+ jsonSchema
85
+ };
86
+ } else {
87
+ throw new Error("invalid properties");
88
+ }
89
+ };
90
+ var makeDynamicTable = ({ registry, jsonSchema, properties }) => {
91
+ const view = View.make({
92
+ query: Query.select(Filter.everything()),
93
+ jsonSchema,
94
+ ...properties && {
95
+ fields: properties.map((property) => property.name)
78
96
  }
79
- const currentSort = model.sorting?.sorting;
80
- const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
81
- return /* @__PURE__ */ React.createElement(DropdownMenu.Root, {
82
- modal: false,
83
- open: true,
84
- onOpenChange: modals.close
85
- }, /* @__PURE__ */ React.createElement(DropdownMenu.VirtualTrigger, {
86
- virtualRef: modals.trigger
87
- }), /* @__PURE__ */ React.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React.createElement(DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
88
- "data-testid": "column-sort-descending",
89
- onClick: () => model.sorting?.setSort(state.fieldId, "desc")
90
- }, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
91
- "data-testid": "column-sort-ascending",
92
- onClick: () => model.sorting?.setSort(state.fieldId, "asc")
93
- }, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
94
- "data-testid": "column-clear-sort",
95
- onClick: () => model.sorting?.clearSort()
96
- }, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
97
- "data-testid": "column-delete",
98
- onClick: () => model.deleteColumn(state.fieldId)
99
- }, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
100
- "data-testid": "column-settings",
101
- onClick: () => modals.openColumnSettings()
102
- }, t("column action settings"))), /* @__PURE__ */ React.createElement(DropdownMenu.Arrow, null))));
103
- } finally {
104
- _effect.f();
97
+ });
98
+ const object = Obj.make(Table_exports.Table, {
99
+ view: Ref.make(view),
100
+ sizes: {}
101
+ });
102
+ const projection = new ProjectionModel({
103
+ registry,
104
+ view,
105
+ baseSchema: jsonSchema,
106
+ change: createDirectChangeCallback2(view.projection, jsonSchema)
107
+ });
108
+ projection.normalizeView();
109
+ if (properties && projection.getFields()) {
110
+ setProperties(view, projection, object, properties);
105
111
  }
112
+ return {
113
+ projection,
114
+ object
115
+ };
106
116
  };
107
-
108
- // src/components/Table/ColumnSettings.tsx
109
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
110
- import React2, { useCallback, useEffect, useMemo, useState } from "react";
111
- import { Popover } from "@dxos/react-ui";
112
- import { FieldEditor } from "@dxos/react-ui-form";
113
- var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
114
- var _effect = _useSignals2();
115
- try {
116
- const [newField, setNewField] = useState();
117
- const state = modals.state.value;
118
- useEffect(() => {
119
- if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
120
- setNewField(model.projection.createFieldProjection());
121
- requestAnimationFrame(() => {
122
- onNewColumn();
117
+ var setProperties = (view, projection, table, properties) => {
118
+ for (const property of properties) {
119
+ const field = projection.getFields().find((field2) => field2.path === property.name);
120
+ if (field) {
121
+ if (property.size !== void 0) {
122
+ Obj.change(table, (t) => {
123
+ t.sizes[field.path] = property.size;
123
124
  });
124
- } else {
125
- setNewField(void 0);
126
125
  }
127
- }, [
128
- model?.projection,
129
- state
130
- ]);
131
- const existingField = useMemo(() => {
132
- if (state?.type === "columnSettings") {
133
- const { mode } = state;
134
- if (mode.type === "edit") {
135
- return model?.projection?.fields.find((f) => f.id === mode.fieldId);
136
- }
126
+ if (property.title !== void 0) {
127
+ const fieldProjection = projection.getFieldProjection(field.id);
128
+ projection.setFieldProjection({
129
+ ...fieldProjection,
130
+ props: {
131
+ ...fieldProjection.props,
132
+ title: property.title
133
+ }
134
+ });
137
135
  }
138
- return void 0;
139
- }, [
140
- model?.projection?.fields,
141
- state
142
- ]);
143
- const field = existingField ?? newField;
144
- const handleSave = useCallback(() => {
145
- modals.close();
146
- }, [
147
- modals
148
- ]);
149
- const handleCancel = useCallback(() => {
150
- if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
151
- model?.projection.deleteFieldProjection(newField.id);
136
+ if (property.sort) {
137
+ const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
138
+ const newQuery = currentQuery.orderBy(Order.property(field.path, property.sort));
139
+ Obj.change(view, (v) => {
140
+ v.query.ast = newQuery.ast;
141
+ });
152
142
  }
153
- }, [
154
- model?.projection,
155
- state,
156
- newField
157
- ]);
158
- if (!model?.projection || !field) {
159
- return null;
160
143
  }
161
- return /* @__PURE__ */ React2.createElement(Popover.Root, {
162
- modal: false,
163
- open: state?.type === "columnSettings"
164
- }, /* @__PURE__ */ React2.createElement(Popover.VirtualTrigger, {
165
- virtualRef: modals.trigger
166
- }), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
167
- classNames: "md:is-64"
168
- }, /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(FieldEditor, {
169
- projection: model.projection,
170
- field,
171
- registry,
172
- onSave: handleSave,
173
- onCancel: handleCancel
174
- })), /* @__PURE__ */ React2.createElement(Popover.Arrow, null))));
175
- } finally {
176
- _effect.f();
177
144
  }
178
145
  };
179
146
 
180
- // src/components/Table/CreateRefPanel.tsx
181
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
182
- import { Schema } from "effect";
183
- import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
184
- import { live } from "@dxos/live-object";
185
- import { getSpace } from "@dxos/react-client/echo";
186
- import { Popover as Popover2 } from "@dxos/react-ui";
187
- import { Form } from "@dxos/react-ui-form";
188
- import { useGridContext } from "@dxos/react-ui-grid";
189
- var CreateRefPanel = ({ model, modals, __gridScope }) => {
190
- var _effect = _useSignals3();
191
- try {
192
- const { id: gridId } = useGridContext("TableCellEditor", __gridScope);
193
- const space = model && getSpace(model?.view);
194
- const state = modals.state.value;
195
- const schema = useMemo2(() => {
196
- if (!space || state?.type !== "createRefPanel") {
197
- return;
198
- }
199
- const [schema2] = space.db.schemaRegistry.query({
200
- typename: state.typename
201
- }).runSync();
202
- if (schema2) {
203
- const omit = Schema.omit("id");
204
- return omit(schema2);
205
- }
206
- }, [
207
- space,
208
- state
209
- ]);
210
- const handleSave = useCallback2((values) => {
211
- if (!model || !space || state?.type !== "createRefPanel") {
212
- return;
213
- }
214
- const [schema2] = space.db.schemaRegistry.query({
215
- typename: state.typename
216
- }).runSync();
217
- if (schema2) {
218
- const obj = space.db.add(live(schema2, values));
219
- state.onCreate?.(obj);
220
- }
221
- void modals.close();
222
- }, [
223
- modals,
224
- space,
225
- state
226
- ]);
227
- const handleCancel = useCallback2(() => {
228
- if (model) {
229
- modals.close();
230
- }
231
- }, [
232
- modals
233
- ]);
234
- if (!model?.projection) {
235
- return null;
147
+ // src/util/signals.ts
148
+ var touch = (value) => value;
149
+
150
+ // src/util/schema.ts
151
+ import * as Schema from "effect/Schema";
152
+ import * as SchemaAST from "effect/SchemaAST";
153
+ var narrowSchema = (schema, paths) => {
154
+ const ast = schema?.ast;
155
+ if (SchemaAST.isTypeLiteral(ast)) {
156
+ const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
157
+ if (propertySignatures.length > 0) {
158
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
159
+ return Schema.make(narrowType);
236
160
  }
237
- return /* @__PURE__ */ React3.createElement(Popover2.Root, {
238
- modal: false,
239
- open: state?.type === "createRefPanel" && !!schema,
240
- onOpenChange: (nextOpen) => {
241
- if (model && !nextOpen) {
242
- return modals.close();
243
- }
244
- }
245
- }, /* @__PURE__ */ React3.createElement(Popover2.VirtualTrigger, {
246
- virtualRef: modals.trigger
247
- }), /* @__PURE__ */ React3.createElement(Popover2.Portal, null, /* @__PURE__ */ React3.createElement(Popover2.Content, {
248
- classNames: "md:is-64",
249
- "data-grid": gridId
250
- }, /* @__PURE__ */ React3.createElement(Popover2.Viewport, null, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React3.createElement(Form, {
251
- schema,
252
- values: state.initialValues ?? {},
253
- onSave: handleSave,
254
- onCancel: handleCancel
255
- })), /* @__PURE__ */ React3.createElement(Popover2.Arrow, null))));
256
- } finally {
257
- _effect.f();
258
161
  }
162
+ return void 0;
259
163
  };
260
164
 
261
- // src/components/Table/RowActionsMenu.tsx
262
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
263
- import React4 from "react";
264
- import { DropdownMenu as DropdownMenu2, useTranslation as useTranslation2 } from "@dxos/react-ui";
265
- var RowActionsMenu = ({ model, modals }) => {
266
- var _effect = _useSignals4();
267
- try {
268
- const { t } = useTranslation2(translationKey);
269
- const hasSelection = model.selection.hasSelection.value;
270
- const state = modals.state.value;
271
- if (state?.type !== "row") {
272
- return null;
273
- }
274
- return /* @__PURE__ */ React4.createElement(DropdownMenu2.Root, {
275
- modal: false,
276
- open: true,
277
- onOpenChange: modals.close
278
- }, /* @__PURE__ */ React4.createElement(DropdownMenu2.VirtualTrigger, {
279
- virtualRef: modals.trigger
280
- }), /* @__PURE__ */ React4.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu2.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React4.createElement(DropdownMenu2.Item, {
281
- "data-testid": "row-menu-delete",
282
- onClick: () => model.deleteRow(state.rowIndex)
283
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React4.createElement(DropdownMenu2.Item, {
284
- key: action.id,
285
- "data-testid": `row-action-${action.id}`,
286
- onClick: () => {
287
- modals.close();
288
- model.handleRowAction(action.id, state.rowIndex);
289
- }
290
- }, t(action.translationKey)))), /* @__PURE__ */ React4.createElement(DropdownMenu2.Arrow, null)));
291
- } finally {
292
- _effect.f();
165
+ // src/model/modal-controller.ts
166
+ import { Atom } from "@effect-atom/atom-react";
167
+ var ModalController = class {
168
+ _registry;
169
+ _state;
170
+ _triggerRef = {
171
+ current: null
172
+ };
173
+ constructor(registry) {
174
+ this._registry = registry;
175
+ this._state = Atom.make({
176
+ type: "closed"
177
+ });
293
178
  }
179
+ get state() {
180
+ return this._state;
181
+ }
182
+ get stateValue() {
183
+ return this._registry.get(this._state);
184
+ }
185
+ get trigger() {
186
+ return this._triggerRef;
187
+ }
188
+ setTrigger = (trigger) => {
189
+ this._triggerRef.current = trigger;
190
+ };
191
+ showRowMenu = (rowIndex) => {
192
+ this._registry.set(this._state, {
193
+ type: "row",
194
+ rowIndex
195
+ });
196
+ };
197
+ showColumnMenu = (fieldId) => {
198
+ this._registry.set(this._state, {
199
+ type: "column",
200
+ fieldId
201
+ });
202
+ };
203
+ showColumnCreator = () => {
204
+ this._registry.set(this._state, {
205
+ type: "columnSettings",
206
+ mode: {
207
+ type: "create"
208
+ }
209
+ });
210
+ };
211
+ showReferencePanel = (targetId, schemaId) => {
212
+ this._registry.set(this._state, {
213
+ type: "refPanel",
214
+ targetId,
215
+ typename: schemaId
216
+ });
217
+ };
218
+ openColumnSettings = () => {
219
+ const currentState = this._registry.get(this._state);
220
+ if (currentState.type === "column") {
221
+ const fieldId = currentState.fieldId;
222
+ requestAnimationFrame(() => {
223
+ this._registry.set(this._state, {
224
+ type: "columnSettings",
225
+ mode: {
226
+ type: "edit",
227
+ fieldId
228
+ }
229
+ });
230
+ });
231
+ }
232
+ };
233
+ close = () => {
234
+ this._registry.set(this._state, {
235
+ type: "closed"
236
+ });
237
+ };
294
238
  };
295
239
 
296
240
  // src/components/TableCellEditor/TableCellEditor.tsx
297
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
298
- import React7, { useCallback as useCallback4, useEffect as useEffect3, useMemo as useMemo4, useRef as useRef2, useState as useState3 } from "react";
299
- import { FormatEnum, TypeEnum } from "@dxos/echo-schema";
241
+ import { EditorView } from "@codemirror/view";
242
+ import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
243
+ import { debounce } from "@dxos/async";
244
+ import { Format, TypeEnum } from "@dxos/echo/internal";
300
245
  import { invariant as invariant2 } from "@dxos/invariant";
301
- import { useThemeContext } from "@dxos/react-ui";
302
- import { createMarkdownExtensions } from "@dxos/react-ui-editor";
303
- import { cellQuery, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext4, GridCellEditor } from "@dxos/react-ui-grid";
304
- import { tagPicker, createLinks } from "@dxos/react-ui-tag-picker";
246
+ import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
305
247
 
306
248
  // src/components/TableCellEditor/CellValidationMessage.tsx
307
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
308
- import React5 from "react";
309
- import { useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
310
- var CellValidationMessage = ({ validationError, variant = "error", __gridScope }) => {
311
- var _effect = _useSignals5();
312
- try {
313
- const { editing, editBox: box } = useGridContext2("GridSheetCellEditor", __gridScope);
314
- if (!editing || !validationError) {
315
- return null;
316
- }
317
- const bgClass = variant === "error" ? "bg-errorSurface" : "bg-warningSurface";
318
- const textClass = variant === "error" ? "text-errorSurfaceText" : "text-warningSurfaceText";
319
- return /* @__PURE__ */ React5.createElement("div", {
320
- role: "none",
321
- className: `absolute ${bgClass} ${textClass} rounded-bs-sm text-xs p-1`,
322
- style: {
323
- ...{
324
- "--dx-gridCellWidth": `${box?.inlineSize ?? 200}px`
325
- },
326
- zIndex: 10,
327
- insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
328
- insetInlineStart: box.insetInlineStart,
329
- inlineSize: box.inlineSize
330
- }
331
- }, validationError);
332
- } finally {
333
- _effect.f();
249
+ import React from "react";
250
+ import { useGridContext } from "@dxos/react-ui-grid";
251
+ var CellValidationMessage = ({ __gridScope, validationError, variant = "error" }) => {
252
+ const { editing, editBox: box } = useGridContext("GridSheetCellEditor", __gridScope);
253
+ if (!editing || !validationError) {
254
+ return null;
334
255
  }
256
+ const bgClass = variant === "error" ? "bg-errorSurface" : "bg-warningSurface";
257
+ const textClass = variant === "error" ? "text-errorSurfaceText" : "text-warningSurfaceText";
258
+ return /* @__PURE__ */ React.createElement("div", {
259
+ role: "none",
260
+ className: `absolute ${bgClass} ${textClass} rounded-bs-sm text-xs p-1`,
261
+ style: {
262
+ ...{
263
+ "--dx-gridCellWidth": `${box?.inlineSize ?? 200}px`
264
+ },
265
+ zIndex: 10,
266
+ insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
267
+ insetInlineStart: box.insetInlineStart,
268
+ inlineSize: box.inlineSize
269
+ }
270
+ }, validationError);
335
271
  };
336
272
 
337
273
  // src/components/TableCellEditor/FormCellEditor.tsx
338
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
339
- import React6, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef, useState as useState2 } from "react";
340
- import { getSnapshot } from "@dxos/echo-schema";
274
+ import React2, { useCallback, useEffect, useMemo, useRef, useState } from "react";
275
+ import { Entity } from "@dxos/echo";
276
+ import { Ref as Ref2, getValue } from "@dxos/echo/internal";
341
277
  import { invariant } from "@dxos/invariant";
342
- import { Popover as Popover3 } from "@dxos/react-ui";
343
- import { Form as Form2 } from "@dxos/react-ui-form";
344
- import { parseCellIndex, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
345
- import { getDeep, setDeep } from "@dxos/util";
278
+ import { Popover } from "@dxos/react-ui";
279
+ import { Form } from "@dxos/react-ui-form";
280
+ import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
281
+ import { getDeep, isTruthy, setDeep } from "@dxos/util";
346
282
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
347
- var FormCellEditor = ({ fieldProjection, model, schema, onSave, __gridScope }) => {
348
- var _effect = _useSignals6();
349
- try {
350
- const { editing: contextEditing, setEditing } = useGridContext3("ArrayEditor", __gridScope);
351
- const [editing, setLocalEditing] = useState2(false);
352
- const anchorRef = useRef(null);
353
- useEffect2(() => {
354
- if (contextEditing && contextEditing.cellElement) {
355
- anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
356
- setLocalEditing(true);
357
- } else {
358
- anchorRef.current = null;
359
- setLocalEditing(false);
360
- }
361
- }, [
362
- contextEditing
363
- ]);
364
- const narrowedSchema = useMemo3(() => {
365
- if (!schema) {
366
- return void 0;
367
- }
368
- return narrowSchema(schema, [
369
- fieldProjection.field.path
370
- ]);
371
- }, [
372
- JSON.stringify(schema),
283
+ var createOptionLabel = [
284
+ "create new object label",
285
+ {
286
+ ns: translationKey
287
+ }
288
+ ];
289
+ var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onCreate, ...formProps }) => {
290
+ const anchorRef = useRef(null);
291
+ const { id: _gridId, editing: contextEditing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
292
+ const [editing, setLocalEditing] = useState(false);
293
+ useEffect(() => {
294
+ if (contextEditing && contextEditing.cellElement) {
295
+ anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
296
+ setLocalEditing(true);
297
+ } else {
298
+ anchorRef.current = null;
299
+ setLocalEditing(false);
300
+ }
301
+ }, [
302
+ contextEditing
303
+ ]);
304
+ const narrowedSchema = useMemo(() => {
305
+ if (!schema) {
306
+ return void 0;
307
+ }
308
+ return narrowSchema(schema, [
373
309
  fieldProjection.field.path
374
310
  ]);
375
- const originalRow = useMemo3(() => {
376
- if (model && contextEditing) {
377
- const cell = parseCellIndex(contextEditing.index);
311
+ }, [
312
+ JSON.stringify(schema),
313
+ fieldProjection.field.path
314
+ ]);
315
+ const originalRow = useMemo(() => {
316
+ if (model && contextEditing) {
317
+ const cell = parseCellIndex(contextEditing.index);
318
+ if (model.isDraftCell(cell)) {
319
+ const draftRow = model.getDraftRows()[cell.row];
320
+ invariant(draftRow, void 0, {
321
+ F: __dxlog_file,
322
+ L: 74,
323
+ S: void 0,
324
+ A: [
325
+ "draftRow",
326
+ ""
327
+ ]
328
+ });
329
+ return draftRow.data;
330
+ } else {
378
331
  const row = model.getRowAt(cell.row);
379
332
  invariant(row, void 0, {
380
333
  F: __dxlog_file,
381
- L: 55,
334
+ L: 78,
382
335
  S: void 0,
383
336
  A: [
384
337
  "row",
@@ -387,259 +340,216 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, __gridScope }) =
387
340
  });
388
341
  return row;
389
342
  }
390
- return void 0;
391
- }, [
392
- model,
393
- contextEditing
394
- ]);
395
- const formValues = useMemo3(() => {
396
- if (originalRow) {
397
- return getSnapshot(originalRow);
398
- }
399
- }, [
400
- originalRow
343
+ }
344
+ return void 0;
345
+ }, [
346
+ model,
347
+ contextEditing
348
+ ]);
349
+ const formValues = useMemo(() => originalRow ? JSON.parse(JSON.stringify(originalRow)) : {}, [
350
+ originalRow
351
+ ]);
352
+ const handleOpenChange = useCallback((nextOpen) => {
353
+ if (nextOpen === false) {
354
+ setEditing(null);
355
+ onSave?.();
356
+ }
357
+ setLocalEditing(nextOpen);
358
+ }, []);
359
+ const handleSave = useCallback((values) => {
360
+ if (!originalRow) {
361
+ return;
362
+ }
363
+ const path = fieldProjection.field.path;
364
+ const value = getDeep(values, [
365
+ path
401
366
  ]);
402
- const handleSave = useCallback3((values) => {
403
- const path = fieldProjection.field.path;
404
- const value = getDeep(values, [
405
- path
406
- ]);
367
+ if (model) {
368
+ model.changeRow(originalRow, (mutableRow) => {
369
+ setDeep(mutableRow, [
370
+ path
371
+ ], value);
372
+ });
373
+ } else {
407
374
  setDeep(originalRow, [
408
375
  path
409
376
  ], value);
410
- setEditing(null);
411
- setLocalEditing(false);
412
- onSave?.();
413
- }, [
414
- fieldProjection.field.path,
415
- originalRow
416
- ]);
417
- const handleOpenChange = useCallback3((nextOpen) => {
418
- if (nextOpen === false) {
419
- setEditing(null);
420
- onSave?.();
377
+ }
378
+ contextEditing?.cellElement?.focus();
379
+ setEditing(null);
380
+ setLocalEditing(false);
381
+ onSave?.();
382
+ }, [
383
+ fieldProjection.field.path,
384
+ onSave,
385
+ contextEditing,
386
+ originalRow,
387
+ model
388
+ ]);
389
+ const handleCreate = useCallback((schema2, values) => {
390
+ const objectWithId = onCreate?.(schema2, values);
391
+ if (objectWithId && originalRow) {
392
+ const ref = Ref2.make(objectWithId);
393
+ const path = fieldProjection.field.path;
394
+ if (model) {
395
+ model.changeRow(originalRow, (mutableRow) => {
396
+ setDeep(mutableRow, [
397
+ path
398
+ ], ref);
399
+ });
400
+ } else {
401
+ setDeep(originalRow, [
402
+ path
403
+ ], ref);
421
404
  }
422
- setLocalEditing(nextOpen);
423
- }, []);
424
- if (!editing) {
425
- return null;
426
405
  }
427
- return /* @__PURE__ */ React6.createElement(Popover3.Root, {
428
- open: editing,
429
- onOpenChange: handleOpenChange
430
- }, /* @__PURE__ */ React6.createElement(Popover3.VirtualTrigger, {
431
- virtualRef: anchorRef
432
- }), /* @__PURE__ */ React6.createElement(Popover3.Content, {
433
- tabIndex: -1,
434
- classNames: "popover-card-width density-fine"
435
- }, /* @__PURE__ */ React6.createElement(Popover3.Arrow, null), /* @__PURE__ */ React6.createElement(Popover3.Viewport, null, /* @__PURE__ */ React6.createElement(Form2, {
436
- values: formValues,
437
- schema: narrowedSchema,
438
- onSave: handleSave
439
- }))));
440
- } finally {
441
- _effect.f();
406
+ contextEditing?.cellElement?.focus();
407
+ setEditing(null);
408
+ setLocalEditing(false);
409
+ onSave?.();
410
+ }, [
411
+ fieldProjection.field.path,
412
+ onSave,
413
+ contextEditing,
414
+ originalRow,
415
+ onCreate,
416
+ model
417
+ ]);
418
+ const getOptions = useCallback((results) => results.map((obj) => {
419
+ return {
420
+ id: Entity.getDXN(obj).toString(),
421
+ label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
422
+ };
423
+ }).filter(isTruthy), [
424
+ fieldProjection
425
+ ]);
426
+ if (!editing) {
427
+ return null;
442
428
  }
443
- };
444
-
445
- // src/components/TableCellEditor/extension.ts
446
- import { autocompletion, pickedCompletion } from "@codemirror/autocomplete";
447
- import { EditorView } from "@codemirror/view";
448
- var completion = ({ debug, onQuery, onMatch }) => {
449
- return [
450
- EditorView.theme({
451
- ".cm-completionDialog": {
452
- width: "var(--dx-gridCellWidth)"
453
- }
454
- }),
455
- autocompletion({
456
- icons: false,
457
- activateOnTyping: true,
458
- closeOnBlur: !debug,
459
- override: [
460
- async (context) => {
461
- const text = context.state.doc.toString();
462
- return {
463
- from: 0,
464
- options: await onQuery(text)
465
- };
466
- }
467
- ],
468
- // TODO(burdon): Consts from grid (to line-up with grid).
469
- tooltipClass: () => "cm-completionDialog !mt-[8px] !-ml-[4px] [&>ul]:!max-h-[264px]",
470
- optionClass: () => "flex h-[33px] items-center"
471
- }),
472
- // Check for accepted completion metadata in the transaction.
473
- EditorView.updateListener.of((update) => {
474
- update.transactions.forEach((tr) => {
475
- const completion2 = tr.annotation(pickedCompletion);
476
- if (completion2) {
477
- onMatch(completion2.data);
478
- }
479
- });
480
- })
481
- ];
429
+ return /* @__PURE__ */ React2.createElement(Popover.Root, {
430
+ open: editing,
431
+ onOpenChange: handleOpenChange
432
+ }, /* @__PURE__ */ React2.createElement(Popover.VirtualTrigger, {
433
+ virtualRef: anchorRef
434
+ }), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
435
+ tabIndex: -1,
436
+ classNames: "popover-card-width density-fine"
437
+ }, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Root, {
438
+ ...formProps,
439
+ autoFocus: true,
440
+ schema: narrowedSchema,
441
+ values: formValues,
442
+ createInitialValuePath: fieldProjection.field.referencePath,
443
+ createOptionIcon: "ph--plus--regular",
444
+ createOptionLabel,
445
+ db: model?.db,
446
+ getOptions,
447
+ onCreate: handleCreate,
448
+ onSave: handleSave
449
+ }, /* @__PURE__ */ React2.createElement(Form.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Content, null, /* @__PURE__ */ React2.createElement(Form.FieldSet, null), /* @__PURE__ */ React2.createElement(Form.Actions, null))))))));
482
450
  };
483
451
 
484
452
  // src/components/TableCellEditor/TableCellEditor.tsx
485
453
  var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
486
- var newValue = Symbol.for("newValue");
487
- var createOption = (text) => ({
488
- [newValue]: true,
489
- text
490
- });
491
- var isCreateOption = (data) => typeof data === "object" && data[newValue];
492
- var TableValueEditor = ({ model, modals, schema, onEnter, onFocus, onSave, onQuery, __gridScope }) => {
493
- var _effect = _useSignals7();
494
- try {
495
- const { editing } = useGridContext4("TableValueEditor", __gridScope);
496
- const fieldProjection = useMemo4(() => {
497
- if (!model || !editing) {
498
- return;
499
- }
500
- const { col } = parseCellIndex2(editing.index);
501
- const field = model.projection.fields[col];
502
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
503
- invariant2(fieldProjection2, void 0, {
504
- F: __dxlog_file2,
505
- L: 76,
506
- S: void 0,
507
- A: [
508
- "fieldProjection",
509
- ""
510
- ]
511
- });
512
- return fieldProjection2;
513
- }, [
514
- model,
515
- editing
516
- ]);
517
- if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === FormatEnum.SingleSelect) {
518
- return /* @__PURE__ */ React7.createElement(FormCellEditor, {
519
- fieldProjection,
520
- model,
521
- schema,
522
- __gridScope,
523
- onSave
524
- });
454
+ var editorSlots = {
455
+ scroll: {
456
+ className: "!plb-[--dx-grid-cell-editor-padding-block]"
457
+ }
458
+ };
459
+ var TableValueEditor = ({ __gridScope, schema, model, modals, onFocus, onSave, onCreate }) => {
460
+ const { editing } = useGridContext3("TableValueEditor", __gridScope);
461
+ const fieldProjection = useMemo2(() => {
462
+ if (!model || !editing) {
463
+ return;
525
464
  }
526
- return /* @__PURE__ */ React7.createElement(TableCellEditor, {
465
+ const { col } = parseCellIndex2(editing.index);
466
+ const field = model.projection.getFields()[col];
467
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
468
+ invariant2(fieldProjection2, void 0, {
469
+ F: __dxlog_file2,
470
+ L: 73,
471
+ S: void 0,
472
+ A: [
473
+ "fieldProjection",
474
+ ""
475
+ ]
476
+ });
477
+ return fieldProjection2;
478
+ }, [
479
+ model,
480
+ editing
481
+ ]);
482
+ if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === Format.TypeFormat.SingleSelect || fieldProjection?.props.format === Format.TypeFormat.Ref) {
483
+ return /* @__PURE__ */ React3.createElement(FormCellEditor, {
484
+ __gridScope,
485
+ schema,
527
486
  model,
487
+ fieldProjection,
528
488
  modals,
529
- onEnter,
530
- onFocus,
531
- onQuery,
532
489
  onSave,
533
- __gridScope
490
+ onCreate
534
491
  });
535
- } finally {
536
- _effect.f();
537
- }
538
- };
539
- var editorSlots = {
540
- scroller: {
541
- className: "!plb-[--dx-grid-cell-editor-padding-block]"
542
492
  }
493
+ return /* @__PURE__ */ React3.createElement(TableCellEditor, {
494
+ model,
495
+ modals,
496
+ onFocus,
497
+ onSave,
498
+ __gridScope
499
+ });
543
500
  };
544
- var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, onSave, __gridScope }) => {
545
- var _effect = _useSignals7();
546
- try {
547
- const { id: gridId, editing, setEditing } = useGridContext4("TableCellEditor", __gridScope);
548
- const suppressNextBlur = useRef2(false);
549
- const { themeMode } = useThemeContext();
550
- const [_validationError, setValidationError] = useState3(null);
551
- const [_validationVariant, setValidationVariant] = useState3("error");
552
- const fieldProjection = useMemo4(() => {
553
- if (!model || !editing) {
554
- return;
555
- }
556
- const { col } = parseCellIndex2(editing.index);
557
- const field = model.projection.fields[col];
558
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
559
- invariant2(fieldProjection2, void 0, {
560
- F: __dxlog_file2,
561
- L: 135,
562
- S: void 0,
563
- A: [
564
- "fieldProjection",
565
- ""
566
- ]
567
- });
568
- return fieldProjection2;
569
- }, [
570
- model,
571
- editing
572
- ]);
573
- useEffect3(() => {
574
- if (!model || !editing || !fieldProjection) {
575
- setValidationError(null);
576
- return;
577
- }
578
- const cell = parseCellIndex2(editing.index);
579
- const { row, col } = cell;
580
- if (model.isDraftCell(cell)) {
581
- const field = model.projection.fields[col];
582
- const hasValidationError = model.hasDraftRowValidationError(row, field.path);
583
- if (hasValidationError) {
584
- const draftRows = model.draftRows.value;
585
- if (row >= 0 && row < draftRows.length) {
586
- const draftRow = draftRows[row];
587
- const validationError = draftRow.validationErrors?.find((error) => error.path === field.path);
588
- if (validationError) {
589
- setValidationError(validationError.message);
590
- setValidationVariant("warning");
591
- }
592
- }
593
- } else {
594
- setValidationError(null);
595
- }
596
- } else {
597
- setValidationError(null);
598
- }
599
- }, [
600
- model,
601
- editing,
602
- fieldProjection
603
- ]);
604
- const handleEnter = useCallback4(async (value) => {
605
- if (!model || !editing) {
606
- return;
607
- }
608
- const cell = parseCellIndex2(editing.index);
609
- const validationResult = await model.validateCellData(cell, value);
610
- if (validationResult.valid) {
611
- setValidationError(null);
612
- model.setCellData(cell, value);
613
- onEnter?.(cell);
614
- onFocus?.();
615
- setEditing(null);
616
- onSave?.();
617
- } else {
618
- setValidationError(validationResult.error);
619
- setValidationVariant("error");
620
- }
621
- }, [
622
- model,
623
- editing,
624
- onEnter,
625
- onFocus,
626
- setEditing
627
- ]);
628
- const handleBlur = useCallback4(async (value) => {
629
- if (!model || !editing) {
630
- return;
631
- }
632
- if (suppressNextBlur.current) {
633
- suppressNextBlur.current = false;
634
- }
635
- }, [
636
- model,
637
- editing
638
- ]);
639
- const handleClose = useCallback4(async (value, event) => {
640
- if (!model || !editing || !fieldProjection) {
641
- return;
642
- }
501
+ var TableCellEditor = ({ __gridScope, model, modals, onFocus, onSave }) => {
502
+ const { editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
503
+ const suppressNextBlur = useRef2(false);
504
+ const [validationError, setValidationError] = useState2(null);
505
+ const [validationVariant, setValidationVariant] = useState2("error");
506
+ const fieldProjection = useMemo2(() => {
507
+ if (!model || !editing) {
508
+ return;
509
+ }
510
+ const { col } = parseCellIndex2(editing.index);
511
+ const field = model.projection.getFields()[col];
512
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
513
+ invariant2(fieldProjection2, void 0, {
514
+ F: __dxlog_file2,
515
+ L: 120,
516
+ S: void 0,
517
+ A: [
518
+ "fieldProjection",
519
+ ""
520
+ ]
521
+ });
522
+ return fieldProjection2;
523
+ }, [
524
+ model,
525
+ editing
526
+ ]);
527
+ const handleEnter = useCallback2(async (value) => {
528
+ if (!model || !editing) {
529
+ return;
530
+ }
531
+ const cell = parseCellIndex2(editing.index);
532
+ const validationResult = await model.validateCellData(cell, value);
533
+ if (validationResult.valid) {
534
+ setValidationError(null);
535
+ model.setCellData(cell, value);
536
+ onFocus?.();
537
+ setEditing(null);
538
+ onSave?.();
539
+ } else {
540
+ setValidationError(validationResult.error);
541
+ setValidationVariant("error");
542
+ }
543
+ }, [
544
+ model,
545
+ editing,
546
+ onFocus,
547
+ setEditing
548
+ ]);
549
+ const handleBlur = useCallback2(async (value) => {
550
+ if (suppressNextBlur.current) {
551
+ suppressNextBlur.current = false;
552
+ } else if (model && editing) {
643
553
  const cell = parseCellIndex2(editing.index);
644
554
  if (value !== void 0) {
645
555
  const result = await model.validateCellData(cell, value);
@@ -648,171 +558,104 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, onSave, __gri
648
558
  model.setCellData(cell, value);
649
559
  setEditing(null);
650
560
  onSave?.();
651
- onEnter?.(cell);
652
- if (event && onFocus) {
653
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
654
- }
655
- } else {
656
- setValidationError(result.error);
657
- setValidationVariant("error");
658
561
  }
659
- } else {
562
+ }
563
+ }
564
+ }, [
565
+ model,
566
+ editing
567
+ ]);
568
+ const handleClose = useCallback2(async (value, event) => {
569
+ if (!model || !editing || !fieldProjection) {
570
+ return;
571
+ }
572
+ const cell = parseCellIndex2(editing.index);
573
+ if (value !== void 0) {
574
+ const result = await model.validateCellData(cell, value);
575
+ if (result.valid) {
576
+ suppressNextBlur.current = true;
660
577
  setValidationError(null);
578
+ model.setCellData(cell, value);
661
579
  setEditing(null);
662
580
  onSave?.();
663
581
  if (event && onFocus) {
664
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
582
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event), cell);
665
583
  }
584
+ } else {
585
+ setValidationError(result.error);
586
+ setValidationVariant("error");
666
587
  }
667
- }, [
668
- model,
669
- editing,
670
- onFocus,
671
- onEnter,
672
- fieldProjection,
673
- setEditing,
674
- onSave
675
- ]);
676
- const extension = useMemo4(() => {
677
- if (!fieldProjection) {
678
- return [];
679
- }
680
- const extension2 = [
681
- editorKeys({
682
- onClose: handleClose,
683
- ...editing?.initialContent && {
684
- onNav: handleClose
685
- }
686
- })
687
- ];
688
- const format = fieldProjection.props.format;
689
- if (format === FormatEnum.SingleSelect || format === FormatEnum.MultiSelect) {
690
- extension2.push(createMarkdownExtensions({
691
- themeMode
692
- }));
693
- const options = fieldProjection.props.options || [];
694
- const mode = format === FormatEnum.SingleSelect ? "single-select" : "multi-select";
695
- extension2.push(tagPicker({
696
- mode,
697
- keymap: false,
698
- onSearch: (text, selectedIds) => {
699
- return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
700
- id: option.id,
701
- label: option.title,
702
- hue: option.color
703
- }));
704
- },
705
- onUpdate: (ids) => {
706
- if (model && editing) {
707
- if (ids.length === 0) {
708
- return;
709
- }
710
- if (mode === "single-select") {
711
- void handleEnter(ids[0]);
712
- } else {
713
- void handleEnter(ids);
714
- }
715
- }
716
- }
717
- }));
588
+ } else {
589
+ suppressNextBlur.current = true;
590
+ setValidationError(null);
591
+ setEditing(null);
592
+ onSave?.();
593
+ if (event && onFocus) {
594
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
718
595
  }
719
- if (onQuery) {
720
- switch (fieldProjection.props.format) {
721
- case FormatEnum.Ref: {
722
- extension2.push([
723
- completion({
724
- onQuery: (text) => onQuery(fieldProjection, text),
725
- onMatch: (data) => {
726
- if (model && editing && modals) {
727
- if (isCreateOption(data)) {
728
- const { field, props } = fieldProjection;
729
- if (props.referenceSchema) {
730
- suppressNextBlur.current = true;
731
- modals.openCreateRef(props.referenceSchema, document.querySelector(cellQuery(editing.index, gridId)), {
732
- [field.referencePath]: data.text
733
- }, (data2) => {
734
- void handleEnter(data2);
735
- });
736
- }
737
- } else {
738
- void handleEnter(data);
739
- }
740
- }
741
- }
742
- })
743
- ]);
744
- break;
745
- }
596
+ }
597
+ }, [
598
+ model,
599
+ editing,
600
+ onFocus,
601
+ fieldProjection,
602
+ setEditing,
603
+ onSave
604
+ ]);
605
+ const extensions = useMemo2(() => {
606
+ if (!fieldProjection) {
607
+ return [];
608
+ }
609
+ const extensions2 = [
610
+ editorKeys({
611
+ onClose: handleClose,
612
+ ...editing?.initialContent && {
613
+ onNav: handleClose
746
614
  }
747
- }
748
- return extension2;
749
- }, [
750
- model,
751
- modals,
752
- editing,
753
- fieldProjection,
754
- handleClose,
755
- themeMode
756
- ]);
757
- const getCellContent = useCallback4(() => {
758
- if (model && editing) {
615
+ })
616
+ ];
617
+ if (model && editing) {
618
+ extensions2.push(EditorView.updateListener.of(debounce((update) => {
619
+ const content = update.state.doc.toString();
759
620
  const cell = parseCellIndex2(editing.index);
760
- const { col } = cell;
761
- const field = model.projection.fields[col];
762
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
763
- if (fieldProjection2?.props.format === FormatEnum.SingleSelect || fieldProjection2?.props.format === FormatEnum.MultiSelect) {
764
- const value2 = model.getCellData(cell);
765
- if (value2 !== void 0) {
766
- const options = fieldProjection2.props.options || [];
767
- if (fieldProjection2.props.format === FormatEnum.MultiSelect) {
768
- const tagItems = value2.split(",").map((id) => {
769
- const option = options.find((o) => o.id === id);
770
- if (option) {
771
- return {
772
- id,
773
- label: option.title,
774
- hue: option.color
775
- };
776
- }
777
- return void 0;
778
- }).filter((item) => item !== void 0);
779
- return createLinks(tagItems);
780
- } else {
781
- const option = options.find((o) => o.id === value2);
782
- if (option) {
783
- const tagItem = {
784
- id: value2,
785
- label: option.title,
786
- hue: option.color
787
- };
788
- return createLinks([
789
- tagItem
790
- ]);
791
- }
792
- }
621
+ void model.validateCellData(cell, content).then((result) => {
622
+ if (result.valid) {
623
+ setValidationError(null);
624
+ } else {
625
+ setValidationError(result.error);
626
+ setValidationVariant("error");
793
627
  }
794
- return "";
795
- }
796
- const value = model.getCellData(cell);
797
- return value !== void 0 ? String(value) : "";
798
- }
799
- }, [
800
- model,
801
- editing
802
- ]);
803
- return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(CellValidationMessage, {
804
- validationError: _validationError,
805
- variant: _validationVariant,
806
- __gridScope
807
- }), /* @__PURE__ */ React7.createElement(GridCellEditor, {
808
- extension,
809
- getCellContent,
810
- onBlur: handleBlur,
811
- slots: editorSlots
812
- }));
813
- } finally {
814
- _effect.f();
815
- }
628
+ });
629
+ }, 10)));
630
+ }
631
+ return extensions2;
632
+ }, [
633
+ model,
634
+ modals,
635
+ editing,
636
+ fieldProjection,
637
+ handleClose
638
+ ]);
639
+ const getCellContent = useCallback2(() => {
640
+ if (model && editing) {
641
+ const cell = parseCellIndex2(editing.index);
642
+ const value = model.getCellData(cell);
643
+ return value !== void 0 ? String(value) : "";
644
+ }
645
+ }, [
646
+ model,
647
+ editing
648
+ ]);
649
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CellValidationMessage, {
650
+ validationError,
651
+ variant: validationVariant,
652
+ __gridScope
653
+ }), /* @__PURE__ */ React3.createElement(GridCellEditor, {
654
+ extensions,
655
+ getCellContent,
656
+ onBlur: handleBlur,
657
+ slots: editorSlots
658
+ }));
816
659
  };
817
660
  var determineNavigationAxis = ({ key }) => {
818
661
  switch (key) {
@@ -839,454 +682,644 @@ var determineNavigationDelta = ({ key, shift }) => {
839
682
  return shift ? -1 : 1;
840
683
  };
841
684
 
685
+ // src/components/Table/ColumnActionsMenu.tsx
686
+ import { useAtomValue } from "@effect-atom/atom-react";
687
+ import React4 from "react";
688
+ import { DropdownMenu, useTranslation } from "@dxos/react-ui";
689
+ var ColumnActionsMenu = ({ model, modals }) => {
690
+ const { t } = useTranslation(translationKey);
691
+ const state = useAtomValue(modals.state);
692
+ if (state?.type !== "column") {
693
+ return null;
694
+ }
695
+ const currentSort = model.getSorting();
696
+ const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
697
+ return /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
698
+ modal: false,
699
+ open: true,
700
+ onOpenChange: modals.close
701
+ }, /* @__PURE__ */ React4.createElement(DropdownMenu.VirtualTrigger, {
702
+ virtualRef: modals.trigger
703
+ }), /* @__PURE__ */ React4.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
704
+ "data-testid": "column-sort-descending",
705
+ onClick: () => model.setSort(state.fieldId, "desc")
706
+ }, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
707
+ "data-testid": "column-sort-ascending",
708
+ onClick: () => model.setSort(state.fieldId, "asc")
709
+ }, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
710
+ "data-testid": "column-clear-sort",
711
+ onClick: () => model.clearSort()
712
+ }, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
713
+ "data-testid": "column-delete",
714
+ onClick: () => model.deleteColumn(state.fieldId)
715
+ }, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
716
+ "data-testid": "column-settings",
717
+ onClick: () => modals.openColumnSettings()
718
+ }, t("column action settings"))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))));
719
+ };
720
+
721
+ // src/components/Table/ColumnSettings.tsx
722
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
723
+ import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useState as useState3 } from "react";
724
+ import { Popover as Popover2 } from "@dxos/react-ui";
725
+ import { FieldEditor } from "@dxos/react-ui-form";
726
+ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
727
+ const [newField, setNewField] = useState3();
728
+ const state = useAtomValue2(modals.state);
729
+ useEffect2(() => {
730
+ if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
731
+ setNewField(model.projection.createFieldProjection());
732
+ requestAnimationFrame(() => {
733
+ onNewColumn();
734
+ });
735
+ } else {
736
+ setNewField(void 0);
737
+ }
738
+ }, [
739
+ model?.projection,
740
+ state
741
+ ]);
742
+ const existingField = useMemo3(() => {
743
+ if (state?.type === "columnSettings") {
744
+ const { mode } = state;
745
+ if (mode.type === "edit") {
746
+ return model?.projection?.getFields().find((f) => f.id === mode.fieldId);
747
+ }
748
+ }
749
+ return void 0;
750
+ }, [
751
+ model?.projection,
752
+ state
753
+ ]);
754
+ const field = existingField ?? newField;
755
+ const handleSave = useCallback3(() => {
756
+ modals.close();
757
+ }, [
758
+ modals
759
+ ]);
760
+ const handleCancel = useCallback3(() => {
761
+ if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
762
+ model?.projection.deleteFieldProjection(newField.id);
763
+ }
764
+ }, [
765
+ model?.projection,
766
+ state,
767
+ newField
768
+ ]);
769
+ if (!model?.projection || !field) {
770
+ return null;
771
+ }
772
+ return /* @__PURE__ */ React5.createElement(Popover2.Root, {
773
+ modal: false,
774
+ open: state?.type === "columnSettings"
775
+ }, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
776
+ virtualRef: modals.trigger
777
+ }), /* @__PURE__ */ React5.createElement(Popover2.Portal, null, /* @__PURE__ */ React5.createElement(Popover2.Content, {
778
+ classNames: "md:is-64"
779
+ }, /* @__PURE__ */ React5.createElement(Popover2.Viewport, null, /* @__PURE__ */ React5.createElement(FieldEditor, {
780
+ projection: model.projection,
781
+ field,
782
+ registry,
783
+ onSave: handleSave,
784
+ onCancel: handleCancel
785
+ })), /* @__PURE__ */ React5.createElement(Popover2.Arrow, null))));
786
+ };
787
+
788
+ // src/components/Table/RowActionsMenu.tsx
789
+ import { useAtomValue as useAtomValue3 } from "@effect-atom/atom-react";
790
+ import React6 from "react";
791
+ import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
792
+ var RowActionsMenu = ({ model, modals }) => {
793
+ const { t } = useTranslation2(translationKey);
794
+ const hasSelection = model.selection.hasSelection;
795
+ const state = useAtomValue3(modals.state);
796
+ if (state?.type !== "row") {
797
+ return null;
798
+ }
799
+ return /* @__PURE__ */ React6.createElement(DropdownMenu2.Root, {
800
+ modal: false,
801
+ open: true,
802
+ onOpenChange: modals.close
803
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu2.VirtualTrigger, {
804
+ virtualRef: modals.trigger
805
+ }), /* @__PURE__ */ React6.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Viewport, null, model.rowActions?.length > 0 && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Group, null, model.rowActions?.map((action) => /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
806
+ key: action.id,
807
+ "data-testid": `row-action-${action.id}`,
808
+ onClick: () => {
809
+ modals.close();
810
+ model.handleRowAction(action.id, state.rowIndex);
811
+ }
812
+ }, toLocalizedString(action.label, t)))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Separator, null)), model.features.dataEditable !== false && /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
813
+ "data-testid": "row-menu-delete",
814
+ onClick: () => model.deleteRow(state.rowIndex)
815
+ }, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Arrow, null)));
816
+ };
817
+
842
818
  // src/components/Table/Table.tsx
843
819
  var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
844
- var TableRoot = ({ children, role = "article" }) => {
845
- var _effect = _useSignals8();
846
- try {
847
- return /* @__PURE__ */ React8.createElement("div", {
848
- role: "none",
849
- 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]", [
850
- "card--popover",
851
- "section",
852
- "card--extrinsic"
853
- ].includes(role) && "overflow-hidden", [
854
- "article",
855
- "slide"
856
- ].includes(role) && "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:bs-0")
857
- }, children);
858
- } finally {
859
- _effect.f();
820
+ var columnDefault = {
821
+ grid: {
822
+ minSize: 80,
823
+ maxSize: 640
860
824
  }
861
825
  };
862
- var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onRowClick }, forwardedRef) => {
863
- var _effect = _useSignals8();
864
- try {
865
- const [dxGrid, setDxGrid] = useState4(null);
866
- const { hasAttention } = useAttention(model?.id ?? "table");
867
- const { t } = useTranslation3(translationKey);
868
- const modals = useMemo5(() => new ModalController(), []);
869
- const draftRowCount = model?.getDraftRowCount() ?? 0;
870
- const frozen = useMemo5(() => {
871
- const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
872
- return {
873
- frozenRowsStart: 1,
874
- frozenRowsEnd: draftRowCount,
875
- frozenColsStart: model?.features.selection.enabled ? 1 : 0,
876
- frozenColsEnd: noActionColumn ? 0 : 1
877
- };
878
- }, [
879
- model,
880
- draftRowCount
881
- ]);
882
- const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
883
- presentation
884
- ]);
885
- useEffect4(() => {
886
- if (!presentation || !dxGrid) {
887
- return;
888
- }
889
- dxGrid.getCells = getCells;
890
- }, [
891
- presentation,
892
- dxGrid,
893
- getCells
894
- ]);
895
- useImperativeHandle(forwardedRef, () => {
896
- if (!presentation || !dxGrid) {
897
- return {};
826
+ var rowDefault = {
827
+ frozenRowsStart: {
828
+ readonly: true,
829
+ focusUnfurl: false
830
+ }
831
+ };
832
+ var emptyColumnMeta = Atom2.make({
833
+ grid: {}
834
+ });
835
+ var TableRoot = ({ children, role = "article" }) => {
836
+ return /* @__PURE__ */ React7.createElement("div", {
837
+ role: "none",
838
+ 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]", [
839
+ "card--popover",
840
+ "section",
841
+ "card--extrinsic"
842
+ ].includes(role) && "overflow-hidden", [
843
+ "article",
844
+ "slide"
845
+ ].includes(role) && "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:bs-0")
846
+ }, children);
847
+ };
848
+ var emptyRowsAtom = Atom2.make([]);
849
+ var emptyCellUpdateAtom = Atom2.make(0);
850
+ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId }, forwardedRef) => {
851
+ const registry = useContext(RegistryContext);
852
+ const [dxGrid, setDxGrid] = useState4(null);
853
+ const { hasAttention } = useAttention(model?.id ?? "table");
854
+ const modals = useMemo4(() => new ModalController(registry), [
855
+ registry
856
+ ]);
857
+ const columnMeta = useAtomValue4(model?.columnMeta ?? emptyColumnMeta);
858
+ const rows = useAtomValue4(model?.rows ?? emptyRowsAtom);
859
+ const cellUpdateCounter = useAtomValue4(model?.cellUpdate ?? emptyCellUpdateAtom);
860
+ const columnCount = Object.keys(columnMeta.grid).length || model?.projection.getFields().length || 0;
861
+ const draftRowCount = model?.getDraftRowCount() ?? 0;
862
+ const frozen = useMemo4(() => {
863
+ const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
864
+ return {
865
+ frozenRowsStart: 1,
866
+ frozenRowsEnd: Math.max(1, draftRowCount),
867
+ frozenColsStart: model?.features.selection.enabled ? 1 : 0,
868
+ frozenColsEnd: noActionColumn ? 0 : 1
869
+ };
870
+ }, [
871
+ model,
872
+ draftRowCount
873
+ ]);
874
+ const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
875
+ presentation
876
+ ]);
877
+ useEffect3(() => {
878
+ if (!dxGrid || !presentation) {
879
+ return;
880
+ }
881
+ dxGrid.getCells = getCells;
882
+ }, [
883
+ dxGrid,
884
+ presentation,
885
+ getCells
886
+ ]);
887
+ useEffect3(() => {
888
+ if (!dxGrid) {
889
+ return;
890
+ }
891
+ dxGrid.updateCells(true);
892
+ dxGrid.requestUpdate();
893
+ }, [
894
+ dxGrid,
895
+ rows,
896
+ cellUpdateCounter
897
+ ]);
898
+ const handleInsertRowResult = useCallback4((insertResult) => {
899
+ if (insertResult === "draft") {
900
+ requestAnimationFrame(() => {
901
+ dxGrid?.setFocus({
902
+ plane: "frozenRowsEnd",
903
+ col: 0,
904
+ row: 0
905
+ });
906
+ dxGrid?.refocus();
907
+ });
908
+ } else {
909
+ requestAnimationFrame(() => {
910
+ dxGrid?.setFocus({
911
+ plane: "grid",
912
+ col: 0,
913
+ row: model ? model.getRowCount() - 1 : 0
914
+ });
915
+ dxGrid?.refocus();
916
+ });
917
+ }
918
+ }, [
919
+ model,
920
+ dxGrid
921
+ ]);
922
+ const handleSave = useCallback4(() => {
923
+ dxGrid?.updateCells(true);
924
+ dxGrid?.requestUpdate();
925
+ }, [
926
+ dxGrid
927
+ ]);
928
+ const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
929
+ if (model && dxGrid) {
930
+ const didCommitSuccessfully = model.commitDraftRow(rowIndex);
931
+ if (didCommitSuccessfully) {
932
+ requestAnimationFrame(() => {
933
+ dxGrid.scrollToEndRow();
934
+ });
898
935
  }
899
- return {
900
- update: (cell) => {
901
- if (cell) {
902
- dxGrid.updateIfWithinBounds(cell, true);
903
- } else {
904
- dxGrid.updateCells(true);
905
- dxGrid.requestUpdate();
906
- }
907
- }
908
- };
909
- }, [
910
- presentation,
911
- dxGrid
912
- ]);
913
- const handleGridClick = useCallback5((event) => {
914
- const rowIndex = safeParseInt(event.target.closest("[aria-rowindex]")?.ariaRowIndex ?? "");
915
- if (rowIndex != null) {
916
- if (onRowClick) {
936
+ }
937
+ }, [
938
+ model,
939
+ dxGrid
940
+ ]);
941
+ const handleGridClick = useCallback4((event) => {
942
+ const cell = closestCell(event.target);
943
+ if (cell) {
944
+ const { row: rowIndex, plane } = cell;
945
+ if (onRowClick) {
946
+ if (plane === "grid") {
917
947
  const row = model?.getRowAt(rowIndex);
918
948
  row && onRowClick(row);
949
+ } else {
950
+ onRowClick(cell);
919
951
  }
920
- if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
921
- model.selection.toggleSelectionForRowIndex(rowIndex);
922
- }
923
952
  }
924
- if (!modals) {
953
+ if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
954
+ model.selection.toggleSelectionForRowIndex(rowIndex);
955
+ }
956
+ }
957
+ if (!modals) {
958
+ return;
959
+ }
960
+ const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
961
+ const tableButtonElement = event.target.closest(buttonSelector);
962
+ if (tableButtonElement) {
963
+ const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
964
+ if (!button) {
925
965
  return;
926
966
  }
927
- const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
928
- const tableButtonElement = event.target.closest(buttonSelector);
929
- if (tableButtonElement) {
930
- const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
931
- if (!button) {
932
- return;
967
+ modals.setTrigger(tableButtonElement);
968
+ const data = button.getData(tableButtonElement);
969
+ switch (data.type) {
970
+ case "rowMenu": {
971
+ modals.showRowMenu(data.rowIndex);
972
+ break;
933
973
  }
934
- modals.setTrigger(tableButtonElement);
935
- const data = button.getData(tableButtonElement);
936
- switch (data.type) {
937
- case "rowMenu": {
938
- modals.showRowMenu(data.rowIndex);
939
- break;
940
- }
941
- case "columnSettings": {
942
- modals.showColumnMenu(data.fieldId);
943
- break;
944
- }
945
- case "newColumn": {
946
- modals.showColumnCreator();
947
- break;
948
- }
949
- case "sort": {
950
- model?.sorting?.toggleSort(data.fieldId);
951
- break;
952
- }
953
- case "saveDraftRow": {
954
- if (model) {
955
- const didCommitSuccessfully = model.commitDraftRow(data.rowIndex);
956
- if (dxGrid && didCommitSuccessfully) {
957
- requestAnimationFrame(() => {
958
- dxGrid.scrollToEndRow();
959
- });
960
- }
961
- }
962
- break;
963
- }
974
+ case "columnSettings": {
975
+ modals.showColumnMenu(data.fieldId);
976
+ break;
964
977
  }
965
- return;
966
- }
967
- const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
968
- const controlElement = event.target.closest(controlSelector);
969
- if (controlElement) {
970
- const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
971
- if (!control) {
972
- return;
978
+ case "newColumn": {
979
+ modals.showColumnCreator();
980
+ break;
973
981
  }
974
- const data = control.getData(controlElement);
975
- switch (data.type) {
976
- case "checkbox": {
977
- if (data.header) {
978
- model?.selection.setSelection(model.selection.allRowsSeleted.value ? "none" : "all");
979
- } else {
980
- model?.selection.toggleSelectionForRowIndex(data.rowIndex);
981
- }
982
- break;
983
- }
984
- case "switch": {
985
- if (model) {
986
- model.updateCellData({
987
- row: data.rowIndex,
988
- col: data.colIndex
989
- }, (value) => !value);
990
- }
991
- break;
992
- }
982
+ case "sort": {
983
+ model?.toggleSort(data.fieldId);
984
+ break;
985
+ }
986
+ case "saveDraftRow": {
987
+ handleSaveDraftRow();
988
+ break;
993
989
  }
994
990
  }
995
- }, [
996
- model,
997
- modals,
998
- dxGrid
999
- ]);
1000
- const handleFocus = useCallback5((increment, delta) => {
1001
- if (dxGrid) {
1002
- dxGrid.refocus(increment, delta);
1003
- }
1004
- }, [
1005
- dxGrid
1006
- ]);
1007
- const handleEnter = useCallback5((cell) => {
1008
- if (!model?.features.dataEditable) {
991
+ return;
992
+ }
993
+ const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
994
+ const controlElement = event.target.closest(controlSelector);
995
+ if (controlElement) {
996
+ const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
997
+ if (!control) {
1009
998
  return;
1010
999
  }
1011
- if (model && cell.row === model.getRowCount() - 1) {
1012
- model.insertRow();
1013
- if (dxGrid) {
1014
- requestAnimationFrame(() => {
1015
- dxGrid?.scrollToRow(cell.row + 1);
1016
- dxGrid?.refocus("row", 1);
1017
- });
1000
+ const data = control.getData(controlElement);
1001
+ switch (data.type) {
1002
+ case "checkbox": {
1003
+ if (data.header) {
1004
+ model?.selection.setSelection(model.selection.allRowsSelected ? "none" : "all");
1005
+ } else {
1006
+ model?.selection.toggleSelectionForRowIndex(data.rowIndex);
1007
+ }
1008
+ break;
1009
+ }
1010
+ case "switch": {
1011
+ if (model) {
1012
+ model.updateCellData({
1013
+ row: data.rowIndex,
1014
+ col: data.colIndex
1015
+ }, (value) => !value);
1016
+ }
1017
+ break;
1018
1018
  }
1019
1019
  }
1020
- }, [
1021
- model,
1022
- dxGrid
1023
- ]);
1024
- const handleKeyDown = useCallback5((event) => {
1025
- if (!model?.features.dataEditable) {
1026
- return;
1027
- }
1028
- const cell = closestCell(event.target);
1029
- if (!model || !cell) {
1030
- return;
1020
+ }
1021
+ }, [
1022
+ model,
1023
+ modals,
1024
+ dxGrid
1025
+ ]);
1026
+ const handleFocus = useCallback4((increment, delta, cell) => {
1027
+ if (dxGrid && model) {
1028
+ if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1 && increment !== "col") {
1029
+ handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
1030
+ } else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
1031
+ handleSaveDraftRow(cell.row);
1032
+ handleInsertRowResult(model.insertRow());
1033
+ } else {
1034
+ dxGrid.refocus(increment, delta);
1031
1035
  }
1036
+ }
1037
+ }, [
1038
+ dxGrid,
1039
+ model
1040
+ ]);
1041
+ const handleKeyDown = useCallback4((event) => {
1042
+ if (!model?.features.dataEditable) {
1043
+ return;
1044
+ }
1045
+ const cell = closestCell(event.target);
1046
+ if (!model || !cell) {
1047
+ return;
1048
+ }
1049
+ if (event.metaKey || event.ctrlKey) {
1032
1050
  switch (event.key) {
1033
- case "Backspace":
1034
- case "Delete": {
1051
+ case "c": {
1035
1052
  try {
1036
- model.setCellData(cell, void 0);
1053
+ const cellData = model.getCellData(cell);
1054
+ const textContent = cellData?.toString() ?? "";
1055
+ void navigator.clipboard.writeText(textContent);
1037
1056
  event.preventDefault();
1038
- } catch {
1057
+ } catch (error) {
1058
+ log.catch(error, void 0, {
1059
+ F: __dxlog_file3,
1060
+ L: 322,
1061
+ S: void 0,
1062
+ C: (f, a) => f(...a)
1063
+ });
1039
1064
  }
1040
1065
  break;
1041
1066
  }
1042
- }
1043
- }, [
1044
- model
1045
- ]);
1046
- const handleAxisResize = useCallback5((event) => {
1047
- if (event.axis === "col") {
1048
- const columnIndex = parseInt(event.index, 10);
1049
- model?.setColumnWidth(columnIndex, event.size);
1050
- }
1051
- }, [
1052
- model
1053
- ]);
1054
- const handleWheel = useCallback5((event) => {
1055
- if (!ignoreAttention && !hasAttention) {
1056
- event.stopPropagation();
1057
- }
1058
- }, [
1059
- hasAttention,
1060
- ignoreAttention
1061
- ]);
1062
- const handleNewColumn = useCallback5(() => {
1063
- const columns = model?.getColumnCount();
1064
- if (dxGrid && columns) {
1065
- dxGrid.scrollToColumn(columns - 1);
1066
- }
1067
- }, [
1068
- model,
1069
- dxGrid
1070
- ]);
1071
- const handleQuery = useCallback5(async ({ field, props }, text) => {
1072
- if (model && props.referenceSchema && field.referencePath) {
1073
- const space = getSpace2(model.view);
1074
- invariant3(space, void 0, {
1075
- F: __dxlog_file3,
1076
- L: 330,
1077
- S: void 0,
1078
- A: [
1079
- "space",
1080
- ""
1081
- ]
1082
- });
1083
- let schema2;
1084
- if (client) {
1085
- schema2 = client.graph.schemaRegistry.getSchema(props.referenceSchema);
1086
- }
1087
- if (!schema2) {
1088
- schema2 = space.db.schemaRegistry.getSchema(props.referenceSchema);
1089
- }
1090
- if (schema2) {
1091
- const { objects } = await space.db.query(Filter.type(schema2)).run();
1092
- const options = objects.map((obj) => {
1093
- const value = getValue(obj, field.referencePath);
1094
- if (!value || typeof value !== "string") {
1095
- return void 0;
1096
- }
1097
- return {
1098
- label: value,
1099
- data: obj
1100
- };
1101
- }).filter(isNotFalsy);
1102
- return [
1103
- ...options,
1104
- {
1105
- label: t("create new object label", {
1106
- text
1107
- }),
1108
- data: createOption(text)
1067
+ case "v": {
1068
+ event.preventDefault();
1069
+ void navigator.clipboard.readText().then((clipboardText) => {
1070
+ try {
1071
+ model.setCellData(cell, String2.trim(clipboardText).replace(/[\n\r]+/, " "));
1072
+ handleSave();
1073
+ } catch {
1074
+ const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
1075
+ if (cellElement) {
1076
+ const rect = cellElement.getBoundingClientRect();
1077
+ const editRequest = new DxEditRequest({
1078
+ cellIndex: `${cell.plane},${cell.col},${cell.row}`,
1079
+ cellBox: {
1080
+ insetInlineStart: rect.left,
1081
+ insetBlockStart: rect.top,
1082
+ inlineSize: rect.width,
1083
+ blockSize: rect.height
1084
+ },
1085
+ cellElement,
1086
+ initialContent: clipboardText
1087
+ });
1088
+ cellElement.dispatchEvent(editRequest);
1089
+ }
1109
1090
  }
1110
- ];
1091
+ });
1092
+ break;
1111
1093
  }
1112
1094
  }
1113
- return [];
1114
- }, [
1115
- model,
1116
- client,
1117
- t
1118
- ]);
1119
- const handleSave = useCallback5(() => {
1120
- dxGrid?.updateCells(true);
1121
- }, [
1122
- dxGrid
1123
- ]);
1124
- if (!model || !modals) {
1125
- return /* @__PURE__ */ React8.createElement("span", {
1126
- role: "none",
1127
- className: "attention-surface"
1128
- });
1129
1095
  }
1130
- return /* @__PURE__ */ React8.createElement(Grid.Root, {
1131
- id: model.id ?? "table-grid"
1132
- }, /* @__PURE__ */ React8.createElement(TableValueEditor, {
1133
- model,
1134
- modals,
1135
- schema,
1136
- onEnter: handleEnter,
1137
- onFocus: handleFocus,
1138
- onQuery: handleQuery,
1139
- onSave: handleSave
1140
- }), /* @__PURE__ */ React8.createElement(Grid.Content, {
1141
- className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
1142
- frozen,
1143
- columns: model.columnMeta.value,
1144
- limitRows: model.getRowCount() ?? 0,
1145
- limitColumns: model.projection.fields.length,
1146
- overscroll: "trap",
1147
- onAxisResize: handleAxisResize,
1148
- onClick: handleGridClick,
1149
- onKeyDownCapture: handleKeyDown,
1150
- onWheelCapture: handleWheel,
1151
- ref: setDxGrid
1152
- }), /* @__PURE__ */ React8.createElement(RowActionsMenu, {
1153
- model,
1154
- modals
1155
- }), /* @__PURE__ */ React8.createElement(ColumnActionsMenu, {
1156
- model,
1157
- modals
1158
- }), /* @__PURE__ */ React8.createElement(ColumnSettings, {
1159
- model,
1160
- modals,
1161
- onNewColumn: handleNewColumn
1162
- }), /* @__PURE__ */ React8.createElement(CreateRefPanel, {
1163
- model,
1164
- modals
1165
- }));
1166
- } finally {
1167
- _effect.f();
1096
+ switch (event.key) {
1097
+ case "Backspace":
1098
+ case "Delete": {
1099
+ try {
1100
+ model.setCellData(cell, void 0);
1101
+ event.preventDefault();
1102
+ handleSave();
1103
+ } catch {
1104
+ }
1105
+ break;
1106
+ }
1107
+ }
1108
+ }, [
1109
+ model,
1110
+ dxGrid,
1111
+ handleSave
1112
+ ]);
1113
+ const handleAxisResize = useCallback4((event) => {
1114
+ if (event.axis === "col") {
1115
+ const columnIndex = parseInt(event.index, 10);
1116
+ model?.setColumnWidth(columnIndex, event.size);
1117
+ }
1118
+ }, [
1119
+ model
1120
+ ]);
1121
+ const handleWheel = useCallback4((event) => {
1122
+ if (!ignoreAttention && !hasAttention) {
1123
+ event.stopPropagation();
1124
+ }
1125
+ }, [
1126
+ hasAttention,
1127
+ ignoreAttention
1128
+ ]);
1129
+ const handleNewColumn = useCallback4(() => {
1130
+ const columns = model?.getColumnCount();
1131
+ if (dxGrid && columns) {
1132
+ dxGrid.scrollToColumn(columns - 1);
1133
+ }
1134
+ }, [
1135
+ model,
1136
+ dxGrid
1137
+ ]);
1138
+ useImperativeHandle(forwardedRef, () => {
1139
+ if (!dxGrid || !presentation) {
1140
+ return {};
1141
+ }
1142
+ return {
1143
+ update: (cell) => {
1144
+ if (cell) {
1145
+ dxGrid.updateIfWithinBounds(cell, true);
1146
+ } else {
1147
+ dxGrid.updateCells(true);
1148
+ dxGrid.requestUpdate();
1149
+ }
1150
+ },
1151
+ handleInsertRowResult
1152
+ };
1153
+ }, [
1154
+ dxGrid,
1155
+ model,
1156
+ presentation
1157
+ ]);
1158
+ if (!model || !modals) {
1159
+ return /* @__PURE__ */ React7.createElement("span", {
1160
+ role: "none",
1161
+ className: "attention-surface"
1162
+ });
1168
1163
  }
1169
- });
1164
+ return /* @__PURE__ */ React7.createElement(Grid.Root, {
1165
+ id: model.id ?? "table-grid"
1166
+ }, /* @__PURE__ */ React7.createElement(TableValueEditor, {
1167
+ model,
1168
+ modals,
1169
+ schema,
1170
+ onFocus: handleFocus,
1171
+ onSave: handleSave,
1172
+ onCreate
1173
+ }), /* @__PURE__ */ React7.createElement(Grid.Content, {
1174
+ className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
1175
+ frozen,
1176
+ columns: columnMeta,
1177
+ columnDefault,
1178
+ rowDefault,
1179
+ limitRows: rows.length,
1180
+ limitColumns: columnCount,
1181
+ overscroll: "trap",
1182
+ onAxisResize: handleAxisResize,
1183
+ onClick: handleGridClick,
1184
+ onKeyDownCapture: handleKeyDown,
1185
+ onWheelCapture: handleWheel,
1186
+ ...testId && {
1187
+ "data-testid": testId
1188
+ },
1189
+ ref: setDxGrid
1190
+ }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
1191
+ model,
1192
+ modals
1193
+ }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
1194
+ model,
1195
+ modals
1196
+ }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
1197
+ model,
1198
+ modals,
1199
+ onNewColumn: handleNewColumn
1200
+ }));
1201
+ };
1202
+ var TableMain = /* @__PURE__ */ forwardRef(TableMainInner);
1170
1203
  var Table = {
1171
1204
  Root: TableRoot,
1172
1205
  Main: TableMain
1173
1206
  };
1174
1207
 
1175
1208
  // src/components/Table/DynamicTable.tsx
1176
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1177
- import React9, { useRef as useRef3, useMemo as useMemo6, useCallback as useCallback6 } from "react";
1209
+ import { RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
1210
+ import React8, { useCallback as useCallback5, useContext as useContext2, useEffect as useEffect4, useMemo as useMemo5, useRef as useRef3, useState as useState5 } from "react";
1178
1211
  import { useDefaultValue } from "@dxos/react-ui";
1179
- import { mx as mx2 } from "@dxos/react-ui-theme";
1180
- var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
1181
- var _effect = _useSignals9();
1182
- try {
1183
- const { typename, jsonSchema } = useMemo6(() => getBaseSchema({
1184
- typename: name,
1185
- properties,
1186
- jsonSchema: _jsonSchema,
1187
- schema
1188
- }), [
1189
- name,
1190
- properties,
1191
- _jsonSchema,
1192
- schema
1193
- ]);
1194
- const { projection, view } = useMemo6(() => makeDynamicTable({
1195
- typename,
1196
- jsonSchema,
1197
- properties
1198
- }), [
1199
- typename,
1212
+ import { mx as mx2 } from "@dxos/ui-theme";
1213
+ var DynamicTable = ({ classNames, schema, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, rowActions, onRowClick, onRowAction, ...props }) => {
1214
+ const registry = useContext2(RegistryContext2);
1215
+ const [dynamicTable, setDynamicTable] = useState5();
1216
+ const { jsonSchema } = useMemo5(() => getBaseSchema({
1217
+ typename: name,
1218
+ properties,
1219
+ jsonSchema: _jsonSchema,
1220
+ schema
1221
+ }), [
1222
+ name,
1223
+ properties,
1224
+ _jsonSchema,
1225
+ schema
1226
+ ]);
1227
+ useEffect4(() => {
1228
+ setDynamicTable(makeDynamicTable({
1229
+ registry,
1200
1230
  jsonSchema,
1201
1231
  properties
1202
- ]);
1203
- const tableRef = useRef3(null);
1204
- const handleCellUpdate = useCallback6((cell) => {
1205
- tableRef.current?.update?.(cell);
1206
- }, []);
1207
- const handleRowOrderChange = useCallback6(() => {
1208
- tableRef.current?.update?.();
1209
- }, []);
1210
- const features = useDefaultValue(props.features, () => ({
1211
- selection: {
1212
- enabled: false
1213
- },
1214
- dataEditable: false
1215
1232
  }));
1216
- const model = useTableModel({
1217
- rows,
1218
- view,
1219
- schema: jsonSchema,
1220
- projection,
1221
- features,
1222
- rowActions,
1223
- onCellUpdate: handleCellUpdate,
1224
- onRowOrderChange: handleRowOrderChange,
1225
- onRowAction
1226
- });
1227
- const presentation = useMemo6(() => {
1228
- if (model) {
1229
- return new TablePresentation(model);
1230
- }
1231
- }, [
1232
- model
1233
- ]);
1234
- return /* @__PURE__ */ React9.createElement("div", {
1235
- role: "none",
1236
- className: mx2("is-full bs-full grow grid", classNames)
1237
- }, /* @__PURE__ */ React9.createElement("div", {
1238
- role: "none",
1239
- className: "grid min-bs-0 overflow-hidden"
1240
- }, /* @__PURE__ */ React9.createElement(Table.Root, null, /* @__PURE__ */ React9.createElement(Table.Main, {
1241
- ref: tableRef,
1242
- model,
1243
- presentation,
1244
- ignoreAttention: true,
1245
- onRowClick
1246
- }))));
1247
- } finally {
1248
- _effect.f();
1249
- }
1233
+ }, [
1234
+ registry,
1235
+ jsonSchema,
1236
+ properties
1237
+ ]);
1238
+ const tableRef = useRef3(null);
1239
+ const handleCellUpdate = useCallback5((cell) => {
1240
+ tableRef.current?.update?.(cell);
1241
+ }, []);
1242
+ const handleRowOrderChange = useCallback5(() => {
1243
+ tableRef.current?.update?.();
1244
+ }, []);
1245
+ const features = useDefaultValue(props.features, () => ({
1246
+ selection: {
1247
+ enabled: false
1248
+ },
1249
+ dataEditable: false
1250
+ }));
1251
+ const model = useTableModel({
1252
+ rows,
1253
+ object: dynamicTable?.object,
1254
+ projection: dynamicTable?.projection,
1255
+ features,
1256
+ rowActions,
1257
+ onCellUpdate: handleCellUpdate,
1258
+ onRowOrderChange: handleRowOrderChange,
1259
+ onRowAction
1260
+ });
1261
+ const presentation = useMemo5(() => {
1262
+ if (model) {
1263
+ return new TablePresentation(registry, model);
1264
+ }
1265
+ }, [
1266
+ registry,
1267
+ model
1268
+ ]);
1269
+ return /* @__PURE__ */ React8.createElement("div", {
1270
+ role: "none",
1271
+ className: mx2("is-full bs-full grow grid", classNames)
1272
+ }, /* @__PURE__ */ React8.createElement("div", {
1273
+ role: "none",
1274
+ className: "grid min-bs-0 overflow-hidden"
1275
+ }, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
1276
+ ref: tableRef,
1277
+ model,
1278
+ presentation,
1279
+ ignoreAttention: true,
1280
+ onRowClick
1281
+ }))));
1250
1282
  };
1251
1283
 
1252
1284
  // src/components/TableToolbar/TableToolbar.tsx
1253
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
1254
- import { Rx } from "@effect-rx/rx-react";
1255
- import React10, { useMemo as useMemo7 } from "react";
1256
- import { live as live2 } from "@dxos/live-object";
1257
- import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
1258
- import { rxFromSignal } from "@dxos/react-ui-menu";
1259
- var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.make((get) => {
1260
- const add = createMenuAction("add-row", onAdd, {
1261
- type: "add-row",
1262
- icon: "ph--plus--regular",
1263
- label: [
1264
- "add row",
1265
- {
1266
- ns: translationKey
1267
- }
1268
- ],
1269
- testId: "table.toolbar.add-row"
1270
- });
1271
- const save = createMenuAction("save-view", onSave, {
1272
- type: "save-view",
1273
- icon: "ph--floppy-disk--regular",
1274
- label: [
1275
- "save view label",
1276
- {
1277
- ns: translationKey
1278
- }
1279
- ],
1280
- testId: "table.toolbar.save-view",
1281
- iconOnly: false,
1282
- hidden: get(rxFromSignal(() => !state.viewDirty))
1283
- });
1285
+ import { Atom as Atom3, RegistryContext as RegistryContext3 } from "@effect-atom/atom-react";
1286
+ import React9, { useContext as useContext3, useEffect as useEffect5, useMemo as useMemo6 } from "react";
1287
+ import { MenuProvider, ToolbarMenu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
1288
+ var createTableToolbarActions = ({ stateAtom, onAdd, onSave, customActions }) => Atom3.make((get) => {
1289
+ const nodes = [];
1290
+ if (onAdd) {
1291
+ const add = createMenuAction("add-row", onAdd, {
1292
+ type: "add-row",
1293
+ icon: "ph--plus--regular",
1294
+ label: [
1295
+ "add row label",
1296
+ {
1297
+ ns: translationKey
1298
+ }
1299
+ ],
1300
+ testId: "table.toolbar.add-row"
1301
+ });
1302
+ nodes.push(add);
1303
+ }
1304
+ if (onSave) {
1305
+ const state = get(stateAtom);
1306
+ const save = createMenuAction("save-view", onSave, {
1307
+ type: "save-view",
1308
+ icon: "ph--floppy-disk--regular",
1309
+ label: [
1310
+ "save view label",
1311
+ {
1312
+ ns: translationKey
1313
+ }
1314
+ ],
1315
+ testId: "table.toolbar.save-view",
1316
+ iconOnly: false,
1317
+ hidden: !state.viewDirty
1318
+ });
1319
+ nodes.push(save);
1320
+ }
1284
1321
  const gap = createGapSeparator();
1285
- const nodes = [
1286
- add,
1287
- save,
1288
- ...gap.nodes
1289
- ];
1322
+ nodes.push(...gap.nodes);
1290
1323
  const edges = nodes.map(({ id: target }) => ({
1291
1324
  source: "root",
1292
1325
  target
@@ -1302,32 +1335,37 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.
1302
1335
  };
1303
1336
  });
1304
1337
  var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
1305
- var _effect = _useSignals10();
1306
- try {
1307
- const state = useMemo7(() => live2({
1338
+ const registry = useContext3(RegistryContext3);
1339
+ const stateAtom = useMemo6(() => Atom3.make({
1340
+ viewDirty
1341
+ }), []);
1342
+ useEffect5(() => {
1343
+ registry.set(stateAtom, {
1308
1344
  viewDirty
1309
- }), []);
1310
- const actionsCreator = useMemo7(() => createTableToolbarActions({
1311
- state,
1312
- onAdd,
1313
- onSave,
1314
- customActions
1315
- }), [
1316
- state,
1317
- onAdd,
1318
- onSave,
1319
- customActions
1320
- ]);
1321
- const menu = useMenuActions(actionsCreator);
1322
- return /* @__PURE__ */ React10.createElement(MenuProvider, {
1323
- ...menu,
1324
- attendableId
1325
- }, /* @__PURE__ */ React10.createElement(ToolbarMenu, {
1326
- classNames
1327
- }));
1328
- } finally {
1329
- _effect.f();
1330
- }
1345
+ });
1346
+ }, [
1347
+ registry,
1348
+ stateAtom,
1349
+ viewDirty
1350
+ ]);
1351
+ const actionsCreator = useMemo6(() => createTableToolbarActions({
1352
+ stateAtom,
1353
+ onAdd,
1354
+ onSave,
1355
+ customActions
1356
+ }), [
1357
+ stateAtom,
1358
+ onAdd,
1359
+ onSave,
1360
+ customActions
1361
+ ]);
1362
+ const menu = useMenuActions(actionsCreator);
1363
+ return /* @__PURE__ */ React9.createElement(MenuProvider, {
1364
+ ...menu,
1365
+ attendableId
1366
+ }, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
1367
+ classNames
1368
+ }));
1331
1369
  };
1332
1370
  export {
1333
1371
  BUTTON_IDENTIFIERS,
@@ -1341,8 +1379,12 @@ export {
1341
1379
  TablePresentation,
1342
1380
  TableToolbar,
1343
1381
  cellClassesForRowSelection,
1344
- createTable,
1382
+ compareValues,
1383
+ createDirectChangeCallback,
1384
+ createEchoChangeCallback,
1385
+ extractOrder,
1345
1386
  getBaseSchema,
1387
+ getSortValue,
1346
1388
  makeDynamicTable,
1347
1389
  narrowSchema,
1348
1390
  tableButtons,
@@ -1350,6 +1392,7 @@ export {
1350
1392
  touch,
1351
1393
  translations,
1352
1394
  useAddRow,
1395
+ useProjectionModel,
1353
1396
  useTableModel
1354
1397
  };
1355
1398
  //# sourceMappingURL=index.mjs.map