@dxos/react-ui-table 0.8.1-staging.5be625a → 0.8.1-staging.9eaf14f

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 (172) hide show
  1. package/dist/lib/browser/{chunk-5MKYB7NF.mjs → chunk-YWNRUF4J.mjs} +7 -3
  2. package/dist/lib/browser/{chunk-5MKYB7NF.mjs.map → chunk-YWNRUF4J.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +295 -97
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/types/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-NRFKBRPV.cjs → chunk-TGG6OZ54.cjs} +10 -6
  8. package/dist/lib/node/{chunk-NRFKBRPV.cjs.map → chunk-TGG6OZ54.cjs.map} +3 -3
  9. package/dist/lib/node/index.cjs +293 -93
  10. package/dist/lib/node/index.cjs.map +3 -3
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/types/index.cjs +3 -3
  13. package/dist/lib/node/types/index.cjs.map +1 -1
  14. package/dist/lib/node-esm/{chunk-SU4D55KI.mjs → chunk-KKLP54L3.mjs} +7 -3
  15. package/dist/lib/node-esm/{chunk-SU4D55KI.mjs.map → chunk-KKLP54L3.mjs.map} +3 -3
  16. package/dist/lib/node-esm/index.mjs +295 -97
  17. package/dist/lib/node-esm/index.mjs.map +3 -3
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/types/index.mjs +1 -1
  20. package/dist/types/src/components/Table/DynamicTable.d.ts +15 -10
  21. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  22. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +10 -0
  23. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -0
  24. package/dist/types/src/components/Table/Table.d.ts +1 -1
  25. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  26. package/dist/types/src/components/Table/Table.stories.d.ts +2 -3
  27. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  28. package/dist/types/src/components/Table/relations.stories.d.ts +9 -0
  29. package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -0
  30. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  31. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  32. package/dist/types/src/components/testing.d.ts.map +1 -1
  33. package/dist/types/src/hooks/useTableModel.d.ts +6 -10
  34. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  35. package/dist/types/src/model/index.d.ts +1 -0
  36. package/dist/types/src/model/index.d.ts.map +1 -1
  37. package/dist/types/src/model/selection-model.d.ts +6 -3
  38. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  39. package/dist/types/src/model/table-model.d.ts +13 -14
  40. package/dist/types/src/model/table-model.d.ts.map +1 -1
  41. package/dist/types/src/model/table-presentation.d.ts +4 -4
  42. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  43. package/dist/types/src/model/table-sorting.d.ts +2 -2
  44. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  45. package/dist/types/src/types/table.d.ts +2 -1
  46. package/dist/types/src/types/table.d.ts.map +1 -1
  47. package/dist/types/src/util/dynamic-table.d.ts +21 -30
  48. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  49. package/dist/types/src/util/table-controls.d.ts +2 -2
  50. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  51. package/dist/types/src/util/table.d.ts.map +1 -1
  52. package/package.json +33 -32
  53. package/src/components/Table/DynamicTable.stories.tsx +155 -0
  54. package/src/components/Table/DynamicTable.tsx +46 -28
  55. package/src/components/Table/Table.stories.tsx +129 -125
  56. package/src/components/Table/Table.tsx +51 -26
  57. package/src/components/Table/relations.stories.tsx +113 -0
  58. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +8 -3
  59. package/src/components/TableCellEditor/TableCellEditor.tsx +102 -4
  60. package/src/components/testing.ts +0 -1
  61. package/src/hooks/useTableModel.ts +11 -11
  62. package/src/model/index.ts +1 -0
  63. package/src/model/selection-model.ts +12 -2
  64. package/src/model/table-model.test.ts +1 -1
  65. package/src/model/table-model.ts +27 -18
  66. package/src/model/table-presentation.test.ts +1 -1
  67. package/src/model/table-presentation.ts +65 -11
  68. package/src/model/table-sorting.ts +2 -2
  69. package/src/playwright/smoke.spec.ts +2 -3
  70. package/src/types/table.ts +6 -5
  71. package/src/util/dynamic-table.ts +57 -25
  72. package/src/util/table-controls.ts +4 -4
  73. package/src/util/table.ts +2 -1
  74. package/dist/lib/browser/deprecated/index.mjs +0 -1483
  75. package/dist/lib/browser/deprecated/index.mjs.map +0 -7
  76. package/dist/lib/node/deprecated/index.cjs +0 -1511
  77. package/dist/lib/node/deprecated/index.cjs.map +0 -7
  78. package/dist/lib/node-esm/deprecated/index.mjs +0 -1485
  79. package/dist/lib/node-esm/deprecated/index.mjs.map +0 -7
  80. package/dist/types/src/deprecated/components/Cell/Cell.d.ts +0 -12
  81. package/dist/types/src/deprecated/components/Cell/Cell.d.ts.map +0 -1
  82. package/dist/types/src/deprecated/components/Cell/CellCombobox.d.ts +0 -13
  83. package/dist/types/src/deprecated/components/Cell/CellCombobox.d.ts.map +0 -1
  84. package/dist/types/src/deprecated/components/Cell/index.d.ts +0 -2
  85. package/dist/types/src/deprecated/components/Cell/index.d.ts.map +0 -1
  86. package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.d.ts +0 -23
  87. package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +0 -1
  88. package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts +0 -36
  89. package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +0 -1
  90. package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.d.ts +0 -15
  91. package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +0 -1
  92. package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts +0 -84
  93. package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +0 -1
  94. package/dist/types/src/deprecated/components/ColumnMenu/index.d.ts +0 -3
  95. package/dist/types/src/deprecated/components/ColumnMenu/index.d.ts.map +0 -1
  96. package/dist/types/src/deprecated/components/Table/Table.d.ts +0 -20
  97. package/dist/types/src/deprecated/components/Table/Table.d.ts.map +0 -1
  98. package/dist/types/src/deprecated/components/Table/Table.stories.d.ts +0 -116
  99. package/dist/types/src/deprecated/components/Table/Table.stories.d.ts.map +0 -1
  100. package/dist/types/src/deprecated/components/Table/TableBody.d.ts +0 -12
  101. package/dist/types/src/deprecated/components/Table/TableBody.d.ts.map +0 -1
  102. package/dist/types/src/deprecated/components/Table/TableContext.d.ts +0 -13
  103. package/dist/types/src/deprecated/components/Table/TableContext.d.ts.map +0 -1
  104. package/dist/types/src/deprecated/components/Table/TableHead.d.ts +0 -9
  105. package/dist/types/src/deprecated/components/Table/TableHead.d.ts.map +0 -1
  106. package/dist/types/src/deprecated/components/Table/TableRootContext.d.ts +0 -17
  107. package/dist/types/src/deprecated/components/Table/TableRootContext.d.ts.map +0 -1
  108. package/dist/types/src/deprecated/components/Table/index.d.ts +0 -5
  109. package/dist/types/src/deprecated/components/Table/index.d.ts.map +0 -1
  110. package/dist/types/src/deprecated/components/Table/props.d.ts +0 -42
  111. package/dist/types/src/deprecated/components/Table/props.d.ts.map +0 -1
  112. package/dist/types/src/deprecated/components/index.d.ts +0 -4
  113. package/dist/types/src/deprecated/components/index.d.ts.map +0 -1
  114. package/dist/types/src/deprecated/helpers.d.ts +0 -91
  115. package/dist/types/src/deprecated/helpers.d.ts.map +0 -1
  116. package/dist/types/src/deprecated/hooks/index.d.ts +0 -5
  117. package/dist/types/src/deprecated/hooks/index.d.ts.map +0 -1
  118. package/dist/types/src/deprecated/hooks/useColumnSizing.d.ts +0 -12
  119. package/dist/types/src/deprecated/hooks/useColumnSizing.d.ts.map +0 -1
  120. package/dist/types/src/deprecated/hooks/useColumnSorting.d.ts +0 -15
  121. package/dist/types/src/deprecated/hooks/useColumnSorting.d.ts.map +0 -1
  122. package/dist/types/src/deprecated/hooks/usePinLastRow.d.ts +0 -3
  123. package/dist/types/src/deprecated/hooks/usePinLastRow.d.ts.map +0 -1
  124. package/dist/types/src/deprecated/hooks/useRowSelection.d.ts +0 -7
  125. package/dist/types/src/deprecated/hooks/useRowSelection.d.ts.map +0 -1
  126. package/dist/types/src/deprecated/index.d.ts +0 -8
  127. package/dist/types/src/deprecated/index.d.ts.map +0 -1
  128. package/dist/types/src/deprecated/schema/Schema.stories.d.ts +0 -11
  129. package/dist/types/src/deprecated/schema/Schema.stories.d.ts.map +0 -1
  130. package/dist/types/src/deprecated/schema/column-utils.d.ts +0 -7
  131. package/dist/types/src/deprecated/schema/column-utils.d.ts.map +0 -1
  132. package/dist/types/src/deprecated/schema/index.d.ts +0 -3
  133. package/dist/types/src/deprecated/schema/index.d.ts.map +0 -1
  134. package/dist/types/src/deprecated/schema/types.d.ts +0 -27
  135. package/dist/types/src/deprecated/schema/types.d.ts.map +0 -1
  136. package/dist/types/src/deprecated/theme.d.ts +0 -29
  137. package/dist/types/src/deprecated/theme.d.ts.map +0 -1
  138. package/dist/types/src/deprecated/translations.d.ts +0 -21
  139. package/dist/types/src/deprecated/translations.d.ts.map +0 -1
  140. package/dist/types/src/deprecated/types.d.ts +0 -26
  141. package/dist/types/src/deprecated/types.d.ts.map +0 -1
  142. package/src/deprecated/components/Cell/Cell.tsx +0 -88
  143. package/src/deprecated/components/Cell/CellCombobox.tsx +0 -103
  144. package/src/deprecated/components/Cell/index.ts +0 -5
  145. package/src/deprecated/components/ColumnMenu/ColumnMenu.stories.tsx +0 -129
  146. package/src/deprecated/components/ColumnMenu/ColumnMenu.tsx +0 -182
  147. package/src/deprecated/components/ColumnMenu/ColumnSettings.stories.tsx +0 -108
  148. package/src/deprecated/components/ColumnMenu/ColumnSettings.tsx +0 -207
  149. package/src/deprecated/components/ColumnMenu/index.ts +0 -6
  150. package/src/deprecated/components/Table/Table.stories.tsx +0 -508
  151. package/src/deprecated/components/Table/Table.tsx +0 -301
  152. package/src/deprecated/components/Table/TableBody.tsx +0 -82
  153. package/src/deprecated/components/Table/TableContext.tsx +0 -34
  154. package/src/deprecated/components/Table/TableHead.tsx +0 -78
  155. package/src/deprecated/components/Table/TableRootContext.ts +0 -39
  156. package/src/deprecated/components/Table/index.ts +0 -8
  157. package/src/deprecated/components/Table/props.ts +0 -60
  158. package/src/deprecated/components/index.ts +0 -7
  159. package/src/deprecated/helpers.tsx +0 -526
  160. package/src/deprecated/hooks/index.ts +0 -8
  161. package/src/deprecated/hooks/useColumnSizing.ts +0 -46
  162. package/src/deprecated/hooks/useColumnSorting.ts +0 -64
  163. package/src/deprecated/hooks/usePinLastRow.ts +0 -47
  164. package/src/deprecated/hooks/useRowSelection.ts +0 -40
  165. package/src/deprecated/index.ts +0 -12
  166. package/src/deprecated/schema/Schema.stories.tsx +0 -59
  167. package/src/deprecated/schema/column-utils.ts +0 -54
  168. package/src/deprecated/schema/index.ts +0 -6
  169. package/src/deprecated/schema/types.ts +0 -40
  170. package/src/deprecated/theme.ts +0 -82
  171. package/src/deprecated/translations.ts +0 -26
  172. package/src/deprecated/types.ts +0 -38
@@ -1,1485 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // packages/ui/react-ui-table/src/deprecated/translations.ts
4
- var translationKey = "table";
5
- var translations_default = [
6
- {
7
- "en-US": {
8
- [translationKey]: {
9
- "no selection label": "\xA0",
10
- "number column type label": "Number",
11
- "boolean column type label": "Boolean",
12
- "date column type label": "Date",
13
- "string column type label": "Text",
14
- "ref column type label": "Reference",
15
- "digits label": "Decimal places",
16
- "save label": "Save",
17
- "delete label": "Delete",
18
- "column label label": "Label",
19
- "property key label": "Property",
20
- "column type label": "Type"
21
- }
22
- }
23
- }
24
- ];
25
-
26
- // packages/ui/react-ui-table/src/deprecated/components/Cell/CellCombobox.tsx
27
- import { CaretDown } from "@phosphor-icons/react";
28
- import React, { useCallback, useState } from "react";
29
- import { Popover, useTranslation } from "@dxos/react-ui";
30
- import { PopoverCombobox } from "@dxos/react-ui-searchlist";
31
- import { descriptionText, getSize, mx, staticPlaceholderText } from "@dxos/react-ui-theme";
32
- var initialItems = (model, value) => value ? {
33
- [model.getId(value)]: {
34
- label: model.getText(value),
35
- data: value
36
- }
37
- } : {};
38
- var CellCombobox = ({ model, value, onValueChange }) => {
39
- const { t } = useTranslation(translationKey);
40
- const [items, setItems] = useState(initialItems(model, value));
41
- const [loading, setLoading] = useState(false);
42
- const [searchInputValue, setSearchInputValue] = useState("");
43
- const handleSearchInputValueChange = async (text) => {
44
- setSearchInputValue(text ?? "");
45
- setLoading(true);
46
- const items2 = await model.query(text);
47
- setItems(items2.reduce((acc, item) => {
48
- acc[model.getId(item)] = {
49
- label: model.getText(item),
50
- data: item
51
- };
52
- return acc;
53
- }, initialItems(model, value)));
54
- setLoading(false);
55
- };
56
- const handleValueChange = useCallback((id) => {
57
- onValueChange(items[id]?.data);
58
- }, [
59
- items,
60
- onValueChange
61
- ]);
62
- return /* @__PURE__ */ React.createElement(PopoverCombobox.Root, {
63
- placeholder: t("no selection label")
64
- }, /* @__PURE__ */ React.createElement(PopoverCombobox.Trigger, {
65
- variant: "ghost",
66
- classNames: "is-full rounded-none ring-inset"
67
- }, value ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
68
- className: mx("font-normal text-start text-baseText flex-1 min-is-0 truncate mie-2", !value && staticPlaceholderText)
69
- }, model.getText(value)), /* @__PURE__ */ React.createElement(CaretDown, {
70
- weight: "bold",
71
- className: getSize(3)
72
- })) : null), /* @__PURE__ */ React.createElement(PopoverCombobox.Content, {
73
- shouldFilter: false,
74
- classNames: "is-[--radix-popover-trigger-width]"
75
- }, /* @__PURE__ */ React.createElement(PopoverCombobox.Input, {
76
- value: searchInputValue,
77
- onValueChange: handleSearchInputValueChange
78
- }), /* @__PURE__ */ React.createElement(PopoverCombobox.List, null, searchInputValue.length < 1 ? /* @__PURE__ */ React.createElement("p", {
79
- className: mx("text-center", descriptionText)
80
- }, "Start typing to search") : loading ? /* @__PURE__ */ React.createElement("p", {
81
- className: mx("text-center", descriptionText)
82
- }, "Searching\u2026") : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(PopoverCombobox.Empty, {
83
- classNames: [
84
- "text-center",
85
- descriptionText
86
- ]
87
- }, "No results"), Object.entries(items).map(([id, { label }]) => /* @__PURE__ */ React.createElement(PopoverCombobox.Item, {
88
- key: id,
89
- value: id,
90
- onSelect: handleValueChange,
91
- classNames: "truncate"
92
- }, label)))), /* @__PURE__ */ React.createElement(Popover.Arrow, null)));
93
- };
94
-
95
- // packages/ui/react-ui-table/src/deprecated/components/ColumnMenu/ColumnMenu.tsx
96
- import { X, GearSix, CaretDown as CaretDown2, ArrowDown, ArrowUp, ArrowRight, ArrowLeft } from "@phosphor-icons/react";
97
- import React4, { useRef as useRef2, useState as useState6, useCallback as useCallback5 } from "react";
98
- import { Button as Button2, Popover as Popover2, DropdownMenu } from "@dxos/react-ui";
99
- import { getSize as getSize2, mx as mx2 } from "@dxos/react-ui-theme";
100
-
101
- // packages/ui/react-ui-table/src/deprecated/components/ColumnMenu/ColumnSettings.tsx
102
- import React2, { useRef, useState as useState2 } from "react";
103
- import { FormatEnums } from "@dxos/echo-schema";
104
- import { Button, Input, Select, useTranslation as useTranslation2 } from "@dxos/react-ui";
105
- import { safeParseInt } from "@dxos/util";
106
- var ColumnSettings = ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose }) => {
107
- const { t } = useTranslation2(translationKey);
108
- const propRef = useRef(null);
109
- const [formState, setFormState] = useState2({
110
- prop: column.id,
111
- refTable: column.refTable,
112
- refProp: column.refProp,
113
- type: String(column.type),
114
- label: column.label,
115
- digits: String(column.digits ?? "0")
116
- });
117
- const handleSave = () => {
118
- const { prop, refTable, refProp, type, label, digits } = formState;
119
- if (!prop.length || !prop.match(/^[a-zA-Z_].+/i)) {
120
- propRef.current?.focus();
121
- return;
122
- }
123
- const current = tableDef.columns.find((c) => c.id !== column.id && c.id === prop);
124
- if (current) {
125
- if (current.type !== "ref") {
126
- propRef.current?.focus();
127
- return;
128
- }
129
- }
130
- onUpdate?.(column.id, {
131
- id: prop,
132
- prop,
133
- label,
134
- type,
135
- refTable,
136
- refProp,
137
- digits: safeParseInt(digits)
138
- });
139
- onClose?.();
140
- };
141
- const handleDelete = () => {
142
- onDelete?.(column.id);
143
- onClose?.();
144
- };
145
- return /* @__PURE__ */ React2.createElement("div", {
146
- className: "flex flex-col w-full gap-4"
147
- }, /* @__PURE__ */ React2.createElement("div", {
148
- className: "flex flex-col gap-2"
149
- }, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column label label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
150
- placeholder: "Column label",
151
- value: formState.label ?? "",
152
- onChange: (event) => setFormState((prevState) => ({
153
- ...prevState,
154
- label: event.target.value
155
- })),
156
- autoFocus: true,
157
- "data-testid": "table.column-settings.label"
158
- })), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("property key label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
159
- ref: propRef,
160
- placeholder: "Property key",
161
- value: formState.prop ?? "",
162
- onChange: (event) => setFormState((prevState) => ({
163
- ...prevState,
164
- prop: event.target.value.replace(/[^\w_]/g, "")
165
- }))
166
- })), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("column type label")), /* @__PURE__ */ React2.createElement(Select.Root, {
167
- value: formState.type,
168
- onValueChange: (value) => setFormState((prevState) => ({
169
- ...prevState,
170
- type: value
171
- }))
172
- }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
173
- classNames: "is-full",
174
- placeholder: "Type"
175
- }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, FormatEnums.map((type) => /* @__PURE__ */ React2.createElement(Select.Option, {
176
- key: type,
177
- value: type
178
- }, t(`${type} column type label`)))))))), formState.type === "number" && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, t("digits label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
179
- value: formState.digits ?? "",
180
- onChange: (event) => setFormState((prevState) => ({
181
- ...prevState,
182
- digits: event.target.value
183
- }))
184
- })), formState.type === "ref" && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table"), /* @__PURE__ */ React2.createElement(Select.Root, {
185
- value: formState.refTable,
186
- onValueChange: (value) => setFormState((prevState) => ({
187
- ...prevState,
188
- refTable: value
189
- }))
190
- }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
191
- placeholder: "Table",
192
- classNames: "is-full"
193
- }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tablesToReference.filter((t2) => t2.id !== tableDef.id).map(({ id, name }) => /* @__PURE__ */ React2.createElement(Select.Option, {
194
- key: id,
195
- value: id
196
- }, name ?? id))))))), formState.refTable && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, null, "Table property"), /* @__PURE__ */ React2.createElement(Select.Root, {
197
- value: formState.refProp,
198
- onValueChange: (value) => setFormState((prevState) => ({
199
- ...prevState,
200
- refProp: value
201
- }))
202
- }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
203
- placeholder: "Property"
204
- }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tablesToReference.find((tableDef2) => tableDef2.id === formState.refTable)?.columns.map(({ id, label }) => /* @__PURE__ */ React2.createElement(Select.Option, {
205
- key: id,
206
- value: id
207
- }, label ?? id))))))))), /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement("div", {
208
- className: "flex flex-row justify-end gap-1"
209
- }, /* @__PURE__ */ React2.createElement(Button, {
210
- onClick: handleDelete,
211
- "data-testid": "table.column-settings.delete"
212
- }, t("delete label")), /* @__PURE__ */ React2.createElement(Button, {
213
- variant: "primary",
214
- onClick: handleSave,
215
- "data-testid": "table.column-settings.save"
216
- }, t("save label")))));
217
- };
218
-
219
- // packages/ui/react-ui-table/src/deprecated/hooks/useColumnSizing.ts
220
- import { useCallback as useCallback2, useEffect, useState as useState3 } from "react";
221
- import { useOnTransition } from "@dxos/react-ui";
222
- var useColumnResizing = ({ columns, onColumnResize }) => {
223
- const [columnsInitialised, setColumnsInitialised] = useState3(false);
224
- const [columnSizing, setColumnSizing] = useState3({});
225
- useEffect(() => {
226
- if (columnsInitialised) {
227
- return;
228
- }
229
- setColumnSizing(columns.filter((column) => !!column.size && column.prop !== void 0).reduce((state, column) => {
230
- state[column.prop] = column.size;
231
- return state;
232
- }, {}));
233
- setColumnsInitialised(true);
234
- }, [
235
- columns,
236
- setColumnSizing
237
- ]);
238
- const [columnSizingInfo, setColumnSizingInfo] = useState3({});
239
- const notifyColumnResize = useCallback2(() => onColumnResize?.(columnSizing), [
240
- onColumnResize,
241
- columnSizing
242
- ]);
243
- useOnTransition(columnSizingInfo.isResizingColumn, (v) => typeof v === "string", false, notifyColumnResize);
244
- return {
245
- columnSizing,
246
- columnSizingInfo,
247
- setColumnSizing,
248
- setColumnSizingInfo
249
- };
250
- };
251
-
252
- // packages/ui/react-ui-table/src/deprecated/hooks/useColumnSorting.ts
253
- import { useState as useState4 } from "react";
254
-
255
- // packages/ui/react-ui-table/src/deprecated/components/Table/TableContext.tsx
256
- import React3, { useContext, createContext } from "react";
257
- import { raise } from "@dxos/debug";
258
- var TABLE_NAME = "Table";
259
- var TableContext = /* @__PURE__ */ createContext(void 0);
260
- var TableProvider = ({ children, ...value }) => {
261
- return /* @__PURE__ */ React3.createElement(TableContext.Provider, {
262
- value
263
- }, children);
264
- };
265
- var useTableContext = () => {
266
- return useContext(TableContext) ?? raise(new Error("Missing TableContext"));
267
- };
268
-
269
- // packages/ui/react-ui-table/src/deprecated/hooks/useColumnSorting.ts
270
- var useColumnSorting = () => {
271
- const [columnSorting, setColumnSorting] = useState4([]);
272
- const sortColumn = (columnId, sortDirection) => {
273
- setColumnSorting([
274
- {
275
- id: columnId,
276
- desc: sortDirection === "desc"
277
- }
278
- ]);
279
- };
280
- const clearColumnSorting = () => {
281
- setColumnSorting([]);
282
- };
283
- return {
284
- sorting: columnSorting,
285
- sortColumn,
286
- clearColumnSorting
287
- };
288
- };
289
- var useSortColumn = (column) => {
290
- const { sorting, sortColumn, clearColumnSorting } = useTableContext();
291
- const [initialSortDirection, setInitialSortDirection] = useState4();
292
- const columnSort = sorting.find((s) => s.id === column.id);
293
- const sortDirection = columnSort ? columnSort.desc ? "desc" : "asc" : void 0;
294
- const canSort = column.getCanSort();
295
- const updateColumnSort = (direction) => {
296
- sortColumn(column.id, direction);
297
- };
298
- const onToggleSort = () => {
299
- if (sortDirection === void 0) {
300
- return;
301
- }
302
- if (sortDirection === initialSortDirection) {
303
- updateColumnSort(initialSortDirection === "asc" ? "desc" : "asc");
304
- } else {
305
- clearColumnSorting();
306
- }
307
- };
308
- const onSelectSort = (direction) => {
309
- clearColumnSorting();
310
- setInitialSortDirection(direction);
311
- updateColumnSort(direction);
312
- };
313
- const onClearSort = () => {
314
- clearColumnSorting();
315
- };
316
- return {
317
- canSort,
318
- sortDirection,
319
- onSelectSort,
320
- onToggleSort,
321
- onClearSort
322
- };
323
- };
324
-
325
- // packages/ui/react-ui-table/src/deprecated/hooks/usePinLastRow.ts
326
- import { useCallback as useCallback3, useEffect as useEffect2, useState as useState5 } from "react";
327
- var usePinLastRow = (pinLastRow, table, data) => {
328
- const [pinnedRowKey, setPinnedRowKey] = useState5();
329
- const pinRow = useCallback3((rowToPin) => {
330
- table.resetRowPinning();
331
- rowToPin.pin("bottom");
332
- setPinnedRowKey(rowToPin.id);
333
- }, [
334
- table
335
- ]);
336
- const clearRowPinning = useCallback3(() => {
337
- table.resetRowPinning();
338
- setPinnedRowKey(void 0);
339
- }, [
340
- table
341
- ]);
342
- const pinLastRowCallback = useCallback3(() => {
343
- const rows = table.getRowModel().rows;
344
- if (rows.length === 0) {
345
- return clearRowPinning();
346
- }
347
- const lastRow = rows[rows.length - 1];
348
- if (lastRow.id === pinnedRowKey) {
349
- return;
350
- }
351
- pinRow(lastRow);
352
- }, [
353
- table,
354
- pinnedRowKey
355
- ]);
356
- useEffect2(() => {
357
- if (pinLastRow) {
358
- pinLastRowCallback();
359
- }
360
- }, [
361
- data,
362
- pinLastRow,
363
- pinLastRowCallback
364
- ]);
365
- };
366
-
367
- // packages/ui/react-ui-table/src/deprecated/hooks/useRowSelection.ts
368
- import { useControllableState } from "@radix-ui/react-use-controllable-state";
369
- import { useCallback as useCallback4 } from "react";
370
- var useRowSelection = (props) => {
371
- const [rowSelection = {}, setRowSelection] = useControllableState({
372
- prop: props.rowSelection,
373
- onChange: props.onRowSelectionChange,
374
- defaultProp: props.defaultRowSelection
375
- });
376
- const handleRowSelectionChange = useCallback4((updaterOrValue) => {
377
- const nextRowSelection = typeof updaterOrValue === "function" ? updaterOrValue(rowSelection) : updaterOrValue;
378
- if (props.rowsSelectable === "multi") {
379
- setRowSelection(nextRowSelection);
380
- } else if (props.rowsSelectable) {
381
- const nextRowSelectionKey = Object.keys(nextRowSelection).filter((id) => !rowSelection[id])[0];
382
- setRowSelection(nextRowSelectionKey ? {
383
- [nextRowSelectionKey]: true
384
- } : {});
385
- } else {
386
- setRowSelection({});
387
- }
388
- }, [
389
- props.rowsSelectable,
390
- setRowSelection,
391
- rowSelection
392
- ]);
393
- return {
394
- rowSelection,
395
- handleRowSelectionChange
396
- };
397
- };
398
-
399
- // packages/ui/react-ui-table/src/deprecated/components/ColumnMenu/ColumnMenu.tsx
400
- var ColumnMenu = ({ column, columnOrderable, columnPosition, onColumnReorder, ...props }) => {
401
- const title = column.label?.length ? column.label : column.id;
402
- const header = props.context.header;
403
- const { canSort, sortDirection, onSelectSort, onToggleSort, onClearSort } = useSortColumn(header.column);
404
- const columnSettingsAnchorRef = useRef2(null);
405
- const [isColumnSettingsOpen, setIsColumnSettingsOpen] = useState6(false);
406
- const shouldPreventFocusOnClose = useRef2(false);
407
- const onOpenColumnSettings = useCallback5(() => {
408
- shouldPreventFocusOnClose.current = true;
409
- setIsColumnSettingsOpen(true);
410
- }, [
411
- shouldPreventFocusOnClose,
412
- setIsColumnSettingsOpen
413
- ]);
414
- const onDropdownCloseAutoFocus = useCallback5((event) => {
415
- if (shouldPreventFocusOnClose.current) {
416
- event.preventDefault();
417
- shouldPreventFocusOnClose.current = false;
418
- }
419
- }, [
420
- shouldPreventFocusOnClose
421
- ]);
422
- return /* @__PURE__ */ React4.createElement("div", {
423
- className: "flex items-center justify-between"
424
- }, /* @__PURE__ */ React4.createElement("div", {
425
- className: "flex items-center gap-1 truncate",
426
- title
427
- }, /* @__PURE__ */ React4.createElement(SortIndicator, {
428
- direction: sortDirection,
429
- onClick: onToggleSort
430
- }), /* @__PURE__ */ React4.createElement("div", {
431
- className: "truncate"
432
- }, title)), /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
433
- modal: false
434
- }, /* @__PURE__ */ React4.createElement(Popover2.Root, {
435
- open: isColumnSettingsOpen,
436
- onOpenChange: setIsColumnSettingsOpen,
437
- modal: false
438
- }, /* @__PURE__ */ React4.createElement(DropdownMenu.Trigger, {
439
- ref: columnSettingsAnchorRef,
440
- asChild: true
441
- }, /* @__PURE__ */ React4.createElement(Popover2.Anchor, {
442
- asChild: true
443
- }, /* @__PURE__ */ React4.createElement(Button2, {
444
- variant: "ghost",
445
- "data-testid": "table.column-menu"
446
- }, /* @__PURE__ */ React4.createElement(CaretDown2, {
447
- className: getSize2(4)
448
- })))), /* @__PURE__ */ React4.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Content, {
449
- onCloseAutoFocus: onDropdownCloseAutoFocus,
450
- sideOffset: 4,
451
- collisionPadding: 8
452
- }, /* @__PURE__ */ React4.createElement(DropdownMenu.Viewport, null, canSort && /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
453
- onClick: () => onSelectSort("asc")
454
- }, /* @__PURE__ */ React4.createElement("span", {
455
- className: "grow"
456
- }, "Sort ascending"), /* @__PURE__ */ React4.createElement("span", {
457
- className: "opacity-50"
458
- }, /* @__PURE__ */ React4.createElement(ArrowUp, {
459
- className: getSize2(4)
460
- }))), /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
461
- onClick: () => onSelectSort("desc")
462
- }, /* @__PURE__ */ React4.createElement("span", {
463
- className: "grow"
464
- }, "Sort descending"), /* @__PURE__ */ React4.createElement("span", {
465
- className: "opacity-50"
466
- }, /* @__PURE__ */ React4.createElement(ArrowDown, {
467
- className: getSize2(4)
468
- }))), sortDirection && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
469
- onClick: onClearSort
470
- }, /* @__PURE__ */ React4.createElement("span", {
471
- className: "grow"
472
- }, "Clear sort"), /* @__PURE__ */ React4.createElement("span", {
473
- className: "opacity-50"
474
- }, /* @__PURE__ */ React4.createElement(X, {
475
- className: getSize2(4)
476
- })))), columnOrderable && /* @__PURE__ */ React4.createElement(React4.Fragment, null, columnPosition !== "start" && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
477
- onClick: () => onColumnReorder(header.column.id, "left")
478
- }, /* @__PURE__ */ React4.createElement("span", {
479
- className: "grow"
480
- }, "Move left"), /* @__PURE__ */ React4.createElement("span", {
481
- className: "opacity-50"
482
- }, /* @__PURE__ */ React4.createElement(ArrowLeft, {
483
- className: mx2(getSize2(4))
484
- }))), columnPosition !== "end" && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
485
- onClick: () => onColumnReorder(header.column.id, "right")
486
- }, /* @__PURE__ */ React4.createElement("span", {
487
- className: "grow"
488
- }, "Move right"), /* @__PURE__ */ React4.createElement("span", {
489
- className: "opacity-50"
490
- }, /* @__PURE__ */ React4.createElement(ArrowRight, {
491
- className: mx2(getSize2(4))
492
- })))), /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
493
- onClick: onOpenColumnSettings,
494
- "data-testid": "table.open-column-settings"
495
- }, /* @__PURE__ */ React4.createElement("span", {
496
- className: "grow"
497
- }, "Column settings"), /* @__PURE__ */ React4.createElement("span", {
498
- className: "opacity-50"
499
- }, /* @__PURE__ */ React4.createElement(GearSix, {
500
- className: mx2(getSize2(4), "rotate-90")
501
- })))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))), /* @__PURE__ */ React4.createElement(Popover2.Portal, null, /* @__PURE__ */ React4.createElement(Popover2.Content, null, /* @__PURE__ */ React4.createElement(Popover2.Viewport, null, /* @__PURE__ */ React4.createElement(ColumnSettings, {
502
- ...props,
503
- column,
504
- onClose: () => setIsColumnSettingsOpen(false)
505
- })), /* @__PURE__ */ React4.createElement(Popover2.Arrow, null))))));
506
- };
507
- var SortIndicator = ({ direction, onClick }) => {
508
- if (direction === void 0) {
509
- return null;
510
- }
511
- let icon;
512
- switch (direction) {
513
- case "asc":
514
- icon = /* @__PURE__ */ React4.createElement(ArrowUp, {
515
- className: getSize2(3)
516
- });
517
- break;
518
- case "desc":
519
- icon = /* @__PURE__ */ React4.createElement(ArrowDown, {
520
- className: getSize2(3)
521
- });
522
- break;
523
- }
524
- return /* @__PURE__ */ React4.createElement("div", {
525
- onClick,
526
- className: "flex items-center cursor-pointer"
527
- }, icon);
528
- };
529
-
530
- // packages/ui/react-ui-table/src/deprecated/components/Table/Table.tsx
531
- import { Slot } from "@radix-ui/react-slot";
532
- import { getCoreRowModel, getExpandedRowModel, getGroupedRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
533
- import React8, { Fragment, memo, useCallback as useCallback7, useEffect as useEffect3, useState as useState8, useContext as useContext3 } from "react";
534
- import { useDefaultValue } from "@dxos/react-ui";
535
- import { mx as mx4 } from "@dxos/react-ui-theme";
536
-
537
- // packages/ui/react-ui-table/src/deprecated/components/Table/TableBody.tsx
538
- import { useArrowNavigationGroup } from "@fluentui/react-tabster";
539
- import { flexRender } from "@tanstack/react-table";
540
- import React6, { useContext as useContext2 } from "react";
541
-
542
- // packages/ui/react-ui-table/src/deprecated/components/Table/TableRootContext.ts
543
- import { useVirtualizer } from "@tanstack/react-virtual";
544
- import { createContext as createContext2, useRef as useRef3, useState as useState7 } from "react";
545
- var useTableRootContext = () => {
546
- const scrollContextRef = useRef3(null);
547
- const [tableCount, setTableCount] = useState7(0);
548
- const virtualizer = useVirtualizer({
549
- getScrollElement: () => scrollContextRef?.current ?? null,
550
- count: tableCount,
551
- overscan: 8,
552
- estimateSize: () => 40
553
- });
554
- const dispatch = (action) => {
555
- switch (action.type) {
556
- case "updateTableCount":
557
- setTableCount(action.count);
558
- break;
559
- default:
560
- break;
561
- }
562
- };
563
- return {
564
- scrollContextRef,
565
- virtualizer,
566
- dispatch
567
- };
568
- };
569
- var TableRootContext = createContext2({});
570
-
571
- // packages/ui/react-ui-table/src/deprecated/theme.ts
572
- import { focusRing, ghostSelected, ghostSelectedCurrent, mx as mx3 } from "@dxos/react-ui-theme";
573
- var currentRow = "!bg-neutral-75 !dark:bg-neutral-850";
574
- var selectedRow = "!bg-primary-100 dark:!bg-primary-700";
575
- var flushPadding = "pli-0 plb-0";
576
- var textPadding = "pli-2 plb-0";
577
- var headPadding = "pli-2 plb-0";
578
- var gridCellFocusRing = "relative focus-within:outline focus-within:outline-1 outline-primary-500 outline-offset-[-1px]";
579
- var borderColors = "border-neutral-200 dark:border-neutral-700";
580
- var stickyRowColors = "bg-neutral-50 dark:bg-neutral-800";
581
- var tableRoot = ({ fullWidth }, ...etc) => mx3("table-fixed", "text-neutral-800 dark:text-neutral-200", fullWidth && "is-full", ...etc);
582
- var groupTh = (_props, ...etc) => mx3("text-start font-medium", flushPadding, ...etc);
583
- var theadRoot = ({ header, stickyHeader }, ...etc) => mx3(header ? stickyHeader && "sticky block-start-[--sticky-top] z-[1]" : "collapse", stickyRowColors, ...etc);
584
- var theadTr = (_props, ...etc) => mx3("group", ...etc);
585
- var theadTh = ({ border }, ...etc) => mx3("relative", "text-start text-xs select-none truncate", headPadding, border && borderColors, border && "border-t border-b border-l last:border-r", ...etc);
586
- var theadResizeRoot = ({ isResizing }) => {
587
- return mx3("absolute h-full w-[4px] top-0 right-0", "cursor-col-resize", "user-select-none", "touch-action-none", "pointer-coarse:bg-neutral-100 dark:pointer-coarse:bg-neutral-800", !isResizing && "group-hover:bg-neutral-100 dark:group-hover:bg-neutral-800", isResizing && "bg-primary-500");
588
- };
589
- var tbodyRoot = (_props, ...etc) => mx3(...etc);
590
- var tbodyTr = ({ canBeCurrent, isPinned }, ...etc) => mx3("group", canBeCurrent ? ghostSelectedCurrent : ghostSelected, canBeCurrent && focusRing, canBeCurrent && "cursor-pointer", isPinned && "sticky z-1 block-end-0", isPinned && stickyRowColors, ...etc);
591
- var tdRoot = ({ border, isGrid, pinned }, ...etc) => mx3("relative", "focus-within:!bg-neutral-50 dark:focus-within:!bg-neutral-900", flushPadding, border && "border-b border-l last:border-r border-neutral-200 dark:border-neutral-700", pinned && "border-t", isGrid && gridCellFocusRing, ...etc);
592
-
593
- // packages/ui/react-ui-table/src/deprecated/components/Cell/Cell.tsx
594
- import { useFocusableGroup } from "@fluentui/react-tabster";
595
- import React5, { useCallback as useCallback6 } from "react";
596
- var CELL_NAME = "Cell";
597
- var FocusableCell = ({ cell, children }) => {
598
- const tableContext = useTableContext();
599
- const focusableGroupAttrs = useFocusableGroup({
600
- tabBehavior: "limited"
601
- });
602
- const pinned = tableContext.table.getState().rowPinning?.bottom?.includes(cell.row.id);
603
- const className = tdRoot({
604
- ...tableContext,
605
- pinned
606
- }, cell.column.columnDef.meta?.cell?.classNames);
607
- const handleKeyDown = useCallback6(({ key, currentTarget }) => {
608
- if (key !== "Enter") {
609
- return;
610
- }
611
- const currentRow2 = currentTarget.closest("tr");
612
- if (!currentRow2) {
613
- return;
614
- }
615
- const cellIndex = Array.from(currentRow2.cells || []).indexOf(currentTarget);
616
- const nextSibling = currentRow2.nextElementSibling;
617
- if (!(nextSibling instanceof HTMLTableRowElement)) {
618
- let depth = 0;
619
- const pollForNewRow = () => {
620
- const newNextSibling = currentRow2.nextElementSibling;
621
- if (newNextSibling instanceof HTMLTableRowElement) {
622
- const nextCell = newNextSibling.cells[cellIndex];
623
- const input = nextCell.querySelector("input");
624
- if (input) {
625
- input.focus();
626
- }
627
- currentRow2.scrollIntoView({
628
- behavior: "smooth",
629
- block: "center"
630
- });
631
- } else if (depth++ < 100) {
632
- requestAnimationFrame(pollForNewRow);
633
- }
634
- };
635
- requestAnimationFrame(pollForNewRow);
636
- }
637
- }, []);
638
- return /* @__PURE__ */ React5.createElement("td", {
639
- "data-testid": "table.cell",
640
- tabIndex: 0,
641
- ...focusableGroupAttrs,
642
- className,
643
- onKeyDown: handleKeyDown
644
- }, children);
645
- };
646
- var StaticCell = ({ cell, children }) => {
647
- const tableContext = useTableContext();
648
- return /* @__PURE__ */ React5.createElement("td", {
649
- "data-testid": "table.cell",
650
- className: tdRoot(tableContext, cell.column.columnDef.meta?.cell?.classNames)
651
- }, children);
652
- };
653
- var Cell = ({ cell, children }) => {
654
- const { isGrid } = useTableContext();
655
- const Root = isGrid ? FocusableCell : StaticCell;
656
- return /* @__PURE__ */ React5.createElement(Root, {
657
- cell
658
- }, children);
659
- };
660
- Cell.displayName = CELL_NAME;
661
-
662
- // packages/ui/react-ui-table/src/deprecated/components/Table/TableBody.tsx
663
- var TABLE_BODY_NAME = "TableBody";
664
- var TableBody = ({ rows }) => {
665
- const { table, keyAccessor, currentDatum, debug, expand, isGrid, onDatumClick } = useTableContext();
666
- const rowSelection = table.getState().rowSelection;
667
- const arrowNavigationAttrs = useArrowNavigationGroup({
668
- axis: "grid"
669
- });
670
- const canBeCurrent = !isGrid && !!onDatumClick;
671
- const { virtualizer } = useContext2(TableRootContext);
672
- return /* @__PURE__ */ React6.createElement("tbody", isGrid && arrowNavigationAttrs, rows.map((row) => {
673
- const isCurrent = currentDatum === row.original;
674
- const isSelected = rowSelection?.[row.id];
675
- const isPinned = row.getIsPinned();
676
- const classNames = tbodyTr({
677
- canBeCurrent,
678
- isPinned: isPinned !== false
679
- });
680
- return /* @__PURE__ */ React6.createElement("tr", {
681
- key: keyAccessor ? keyAccessor(row.original) : row.id,
682
- className: classNames,
683
- "data-index": row.index,
684
- "data-testid": "table.data-row",
685
- ref: virtualizer.measureElement,
686
- ...isCurrent && {
687
- "aria-current": "location"
688
- },
689
- ...isSelected && {
690
- "aria-selected": "true"
691
- },
692
- ...canBeCurrent && {
693
- tabIndex: 0,
694
- onClick: () => {
695
- onDatumClick(row.original);
696
- },
697
- onKeyUp: ({ key }) => {
698
- if (key === "Enter" || key === " ") {
699
- onDatumClick(row.original);
700
- }
701
- }
702
- }
703
- }, debug && /* @__PURE__ */ React6.createElement("td", null, row.id), row.getVisibleCells().map((cell) => {
704
- return /* @__PURE__ */ React6.createElement(Cell, {
705
- key: cell.id,
706
- cell
707
- }, flexRender(cell.column.columnDef.cell, {
708
- ...cell.getContext()
709
- }));
710
- }), expand && /* @__PURE__ */ React6.createElement("td", null));
711
- }));
712
- };
713
- TableBody.displayName = TABLE_BODY_NAME;
714
-
715
- // packages/ui/react-ui-table/src/deprecated/components/Table/TableHead.tsx
716
- import { flexRender as flexRender2 } from "@tanstack/react-table";
717
- import React7 from "react";
718
- import { defaultSizeCol } from "@dxos/react-ui-grid";
719
- var TABLE_HEAD_NAME = "TableHeader";
720
- var TableHead = (_props) => {
721
- const tableContext = useTableContext();
722
- const headerGroups = tableContext.table.getHeaderGroups();
723
- return /* @__PURE__ */ React7.createElement("thead", {
724
- className: theadRoot(tableContext)
725
- }, headerGroups.map((headerGroup) => {
726
- return (
727
- // Group element to hover resize handles.
728
- /* @__PURE__ */ React7.createElement("tr", {
729
- key: headerGroup.id,
730
- className: theadTr(tableContext)
731
- }, tableContext.debug && /* @__PURE__ */ React7.createElement("th", {
732
- className: "font-mono",
733
- style: {
734
- width: defaultSizeCol
735
- }
736
- }, "#"), headerGroup.headers.map((header) => {
737
- const isResizing = header.column.getIsResizing();
738
- const onResize = header.getResizeHandler();
739
- const resizable = header.column.columnDef.meta?.resizable;
740
- return /* @__PURE__ */ React7.createElement("th", {
741
- key: header.id,
742
- style: {
743
- width: header.getSize()
744
- },
745
- className: theadTh(tableContext, header.column.columnDef.meta?.header?.classNames),
746
- "data-testid": "table.header-cell"
747
- }, !header || header.isPlaceholder ? null : flexRender2(header.column.columnDef.header, header.getContext()), resizable && /* @__PURE__ */ React7.createElement("div", {
748
- className: theadResizeRoot({
749
- isResizing
750
- }),
751
- onDoubleClick: header.column.resetSize,
752
- onMouseDown: onResize,
753
- onTouchStart: onResize
754
- }));
755
- }), tableContext.expand && /* @__PURE__ */ React7.createElement("th", null))
756
- );
757
- }));
758
- };
759
- TableHead.displayName = TABLE_HEAD_NAME;
760
-
761
- // packages/ui/react-ui-table/src/deprecated/components/Table/Table.tsx
762
- var TableRoot = ({ children }) => {
763
- const contextValue = useTableRootContext();
764
- return /* @__PURE__ */ React8.createElement(TableRootContext.Provider, {
765
- value: contextValue
766
- }, children);
767
- };
768
- var TableViewport = ({ children, classNames, asChild, ...props }) => {
769
- const { scrollContextRef } = useContext3(TableRootContext);
770
- const classes = mx4(classNames, "overflow-auto");
771
- return asChild ? /* @__PURE__ */ React8.createElement(Slot, {
772
- ref: scrollContextRef,
773
- className: classes,
774
- ...props
775
- }, children) : /* @__PURE__ */ React8.createElement("div", {
776
- role: "none",
777
- className: classes,
778
- ref: scrollContextRef,
779
- ...props
780
- }, children);
781
- };
782
- var TablePrimitive = (props) => {
783
- const { role, header = true, rowsSelectable, debug, pinLastRow, columnVisibility, onColumnResize, onDataSelectionChange } = props;
784
- const columns = useDefaultValue(props.columns, () => []);
785
- const incomingData = useDefaultValue(props.data, () => []);
786
- const [data, setData] = useState8([
787
- ...incomingData
788
- ]);
789
- const forceUpdate = useCallback7(() => setData([
790
- ...incomingData
791
- ]), [
792
- incomingData
793
- ]);
794
- useEffect3(() => forceUpdate(), [
795
- JSON.stringify(incomingData),
796
- forceUpdate
797
- ]);
798
- const TableProvider2 = TableProvider;
799
- const { columnSizing, setColumnSizing, columnSizingInfo, setColumnSizingInfo } = useColumnResizing({
800
- columns,
801
- onColumnResize
802
- });
803
- const { rowSelection, handleRowSelectionChange } = useRowSelection(props);
804
- const [grouping, handleGroupingChange] = useState8(props.grouping ?? []);
805
- useEffect3(() => handleGroupingChange(props.grouping ?? []), [
806
- handleGroupingChange,
807
- props.grouping
808
- ]);
809
- const columnSorting = useColumnSorting();
810
- const table = useReactTable({
811
- // Data
812
- meta: {},
813
- data,
814
- // Columns
815
- columns,
816
- defaultColumn: {
817
- size: 400,
818
- maxSize: 1024
819
- },
820
- // State
821
- state: {
822
- columnVisibility,
823
- columnSizing,
824
- columnSizingInfo,
825
- sorting: columnSorting.sorting,
826
- rowSelection,
827
- grouping
828
- },
829
- // Resize columns
830
- columnResizeMode: "onChange",
831
- enableColumnResizing: true,
832
- onColumnSizingChange: setColumnSizing,
833
- onColumnSizingInfoChange: setColumnSizingInfo,
834
- // Rows
835
- getCoreRowModel: getCoreRowModel(),
836
- getSortedRowModel: getSortedRowModel(),
837
- getExpandedRowModel: getExpandedRowModel(),
838
- // Grouping
839
- getGroupedRowModel: grouping.length > 1 ? getGroupedRowModel() : void 0,
840
- onGroupingChange: handleGroupingChange,
841
- enableMultiRowSelection: rowsSelectable === "multi" ? true : void 0,
842
- enableRowSelection: rowsSelectable === true ? true : void 0,
843
- onRowSelectionChange: handleRowSelectionChange,
844
- enableSorting: true,
845
- enableColumnPinning: true,
846
- // Debug
847
- debugTable: debug
848
- });
849
- useEffect3(() => {
850
- onDataSelectionChange?.(Object.keys(rowSelection).map((id) => table.getRowModel().rowsById[id].original));
851
- }, [
852
- onDataSelectionChange,
853
- rowSelection,
854
- table
855
- ]);
856
- usePinLastRow(pinLastRow, table, data);
857
- const expand = false;
858
- return /* @__PURE__ */ React8.createElement(TableProvider2, {
859
- ...props,
860
- ...columnSorting,
861
- table,
862
- header,
863
- expand,
864
- isGrid: role === "grid" || role === "treegrid"
865
- }, /* @__PURE__ */ React8.createElement(TableImpl, {
866
- debug: false,
867
- ...props
868
- }));
869
- };
870
- var TableImpl = (props) => {
871
- const { debug, classNames, role, grouping, fullWidth } = props;
872
- const { table } = useTableContext();
873
- if (debug) {
874
- return /* @__PURE__ */ React8.createElement("pre", {
875
- className: "font-mono text-xs text-neutral-500 m-1 p-2 ring"
876
- }, /* @__PURE__ */ React8.createElement("code", null, JSON.stringify(table.getState(), void 0, 2)));
877
- }
878
- const isResizingColumn = table.getState().columnSizingInfo.isResizingColumn;
879
- const TableComponent = isResizingColumn ? MemoizedVirtualizedTableContent : VirtualizedTableContent;
880
- return /* @__PURE__ */ React8.createElement("table", {
881
- role,
882
- className: tableRoot(props, classNames),
883
- style: {
884
- // borderCollapse: 'separate',
885
- borderSpacing: 0,
886
- ...!fullWidth && {
887
- width: table.getTotalSize()
888
- }
889
- }
890
- }, /* @__PURE__ */ React8.createElement(TableHead, null), grouping?.length !== 0 ? /* @__PURE__ */ React8.createElement(TableComponent, null) : /* @__PURE__ */ React8.createElement(GroupedTableContent, null));
891
- };
892
- var VirtualizedTableContent = () => {
893
- const { table } = useTableContext();
894
- const { virtualizer, dispatch } = useContext3(TableRootContext);
895
- const centerRows = table.getCenterRows();
896
- let pinnedRows = [];
897
- useEffect3(() => {
898
- dispatch({
899
- type: "updateTableCount",
900
- count: centerRows.length
901
- });
902
- }, [
903
- centerRows.length
904
- ]);
905
- try {
906
- pinnedRows = table.getBottomRows();
907
- } catch (_) {
908
- }
909
- const { getTotalSize, getVirtualItems } = virtualizer;
910
- const virtualRows = getVirtualItems();
911
- const totalSize = getTotalSize();
912
- const paddingTop = virtualRows.length > 0 ? virtualRows?.[0]?.start || 0 : 0;
913
- const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows?.[virtualRows.length - 1]?.end || 0) : 0;
914
- const rowsToRender = [
915
- ...virtualRows.map((virtualRow) => centerRows[virtualRow.index]),
916
- ...pinnedRows
917
- ].filter((r) => !!r);
918
- return /* @__PURE__ */ React8.createElement(Fragment, null, paddingTop > 0 && /* @__PURE__ */ React8.createElement("tbody", {
919
- role: "none"
920
- }, /* @__PURE__ */ React8.createElement("tr", {
921
- role: "none"
922
- }, /* @__PURE__ */ React8.createElement("td", {
923
- style: {
924
- height: `${paddingTop}px`
925
- },
926
- role: "none"
927
- }))), /* @__PURE__ */ React8.createElement(TableBody, {
928
- rows: rowsToRender
929
- }), paddingBottom > 0 && /* @__PURE__ */ React8.createElement("tbody", {
930
- role: "none"
931
- }, /* @__PURE__ */ React8.createElement("tr", {
932
- role: "none"
933
- }, /* @__PURE__ */ React8.createElement("td", {
934
- style: {
935
- height: `${paddingBottom}px`
936
- },
937
- role: "none"
938
- }))));
939
- };
940
- var MemoizedVirtualizedTableContent = /* @__PURE__ */ memo(VirtualizedTableContent);
941
- var GroupedTableContent = () => {
942
- const { table: { getGroupedRowModel: getGroupedRowModel2, getHeaderGroups, getState }, debug } = useTableContext();
943
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, getGroupedRowModel2().rows.map((row, i) => {
944
- return /* @__PURE__ */ React8.createElement(Fragment, {
945
- key: i
946
- }, /* @__PURE__ */ React8.createElement("thead", null, /* @__PURE__ */ React8.createElement("tr", null, debug && /* @__PURE__ */ React8.createElement("th", null), /* @__PURE__ */ React8.createElement("th", {
947
- // TODO(burdon): Calculate row span.
948
- colSpan: getHeaderGroups()[0].headers.length,
949
- className: groupTh({})
950
- }, getState().grouping[0], "[", String(row.getGroupingValue(getState().grouping[0])), "]"))), /* @__PURE__ */ React8.createElement(TableBody, {
951
- rows: row.subRows
952
- }));
953
- }));
954
- };
955
- var Table = {
956
- Root: TableRoot,
957
- Viewport: TableViewport,
958
- Main: TablePrimitive
959
- };
960
-
961
- // packages/ui/react-ui-table/src/deprecated/helpers.tsx
962
- import { useFocusFinders } from "@fluentui/react-tabster";
963
- import { Check, ClipboardText, X as X2 } from "@phosphor-icons/react";
964
- import { createColumnHelper } from "@tanstack/react-table";
965
- import { format } from "date-fns/format";
966
- import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
967
- import React9, { useCallback as useCallback8, useEffect as useEffect4, useRef as useRef4, useState as useState9 } from "react";
968
- import { log } from "@dxos/log";
969
- import { Input as Input2, Tooltip } from "@dxos/react-ui";
970
- import { defaultSizeRow } from "@dxos/react-ui-grid";
971
- import { getSize as getSize3, mx as mx5 } from "@dxos/react-ui-theme";
972
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/deprecated/helpers.tsx";
973
- var createColumnBuilder = () => ({
974
- helper: createColumnHelper(),
975
- builder: new ColumnBuilder()
976
- });
977
- var ComboboxBuilderCell = (cellContext) => {
978
- const { model, onUpdate } = cellContext.column.columnDef.meta;
979
- return model ? /* @__PURE__ */ React9.createElement(CellCombobox, {
980
- model,
981
- value: cellContext.getValue(),
982
- onValueChange: (value) => onUpdate?.(cellContext.row.original, cellContext.column.id, value)
983
- }) : null;
984
- };
985
- var StringBuilderCell = (cellContext) => {
986
- const ref = useRef4(null);
987
- const { findPrevFocusable } = useFocusFinders();
988
- const { onUpdate, cell } = cellContext.column.columnDef.meta;
989
- const initialValue = cellContext.getValue();
990
- const getInitialValue = useCallback8(() => {
991
- return initialValue?.content ?? initialValue;
992
- }, [
993
- initialValue
994
- ]);
995
- const [value, setValue] = useState9(getInitialValue);
996
- useEffect4(() => setValue(getInitialValue()), [
997
- getInitialValue
998
- ]);
999
- const handleSave = () => {
1000
- ref.current && document.activeElement === ref.current && findPrevFocusable(ref.current)?.focus();
1001
- if (value !== initialValue) {
1002
- onUpdate?.(cellContext.row.original, cellContext.column.id, value);
1003
- }
1004
- };
1005
- const handleCancel = () => setValue(initialValue);
1006
- let placeholder = false;
1007
- const columns = cellContext.table.getVisibleFlatColumns();
1008
- if (columns[0].id === cellContext.column.id) {
1009
- const rowCount = cellContext.table.getRowModel().rows.length;
1010
- placeholder = cellContext.row.index === rowCount - 1 && columns[0].id === cellContext.column.id;
1011
- }
1012
- return /* @__PURE__ */ React9.createElement(Input2.Root, null, /* @__PURE__ */ React9.createElement(Input2.TextInput, {
1013
- ref,
1014
- variant: "subdued",
1015
- placeholder: placeholder ? "Add row..." : void 0,
1016
- classNames: [
1017
- "is-full",
1018
- textPadding,
1019
- cell?.classNames
1020
- ],
1021
- value: value ?? "",
1022
- onBlur: handleSave,
1023
- onChange: (event) => setValue(event.target.value),
1024
- onKeyDown: (event) => event.key === "Enter" && handleSave() || event.key === "Escape" && handleCancel(),
1025
- autoComplete: "off"
1026
- }));
1027
- };
1028
- var parseNumber = (text) => text?.trim().length ? Number(text) : NaN;
1029
- var displayNumber = (value, digits) => value || value === 0 ? value.toLocaleString(void 0, {
1030
- minimumFractionDigits: digits ?? 0,
1031
- maximumFractionDigits: digits ?? 2
1032
- }) : "";
1033
- var NumberBuilderCell = (cellContext) => {
1034
- const { onUpdate, digits } = cellContext.column.columnDef.meta;
1035
- const value = cellContext.getValue();
1036
- const [text, setText] = useState9(displayNumber(value, digits));
1037
- const { findPrevFocusable } = useFocusFinders();
1038
- const ref = useRef4(null);
1039
- useEffect4(() => {
1040
- (!document.activeElement || document.activeElement !== ref.current) && setText(displayNumber(value, digits));
1041
- }, [
1042
- digits,
1043
- value
1044
- ]);
1045
- const handleEdit = () => setText(value !== void 0 ? String(value) : "");
1046
- const handleSave = () => {
1047
- const nextValue = parseNumber(text);
1048
- if (!isNaN(nextValue)) {
1049
- onUpdate?.(cellContext.row.original, cellContext.column.id, nextValue);
1050
- setText(displayNumber(nextValue, digits));
1051
- } else {
1052
- setText(displayNumber(value, digits));
1053
- }
1054
- ref.current && document.activeElement === ref.current && findPrevFocusable(ref.current)?.focus();
1055
- };
1056
- const _handleCancel = () => {
1057
- setText(displayNumber(value, digits));
1058
- ref.current && findPrevFocusable(ref.current)?.focus();
1059
- };
1060
- return /* @__PURE__ */ React9.createElement(Input2.Root, null, /* @__PURE__ */ React9.createElement(Input2.TextInput, {
1061
- ref,
1062
- variant: "subdued",
1063
- value: text,
1064
- classNames: [
1065
- "is-full text-end font-mono",
1066
- textPadding
1067
- ],
1068
- onBlur: handleSave,
1069
- onFocus: handleEdit,
1070
- onChange: ({ target: { value: value2 } }) => setText(value2),
1071
- onKeyDown: (event) => {
1072
- return (
1073
- /* (event.key === 'Escape' && handleCancel()) || */
1074
- event.key === "Enter" && handleSave()
1075
- );
1076
- },
1077
- autoComplete: "off"
1078
- }));
1079
- };
1080
- var RowSelectorBuilderCell = (cellContext) => {
1081
- const { cell } = cellContext.column.columnDef.meta;
1082
- const { row } = cellContext;
1083
- const checked = row.getCanSelect() ? row.getIsSelected() : row.getCanSelectSubRows() && (row.getIsSomeSelected() ? "indeterminate" : row.getIsAllSubRowsSelected());
1084
- return /* @__PURE__ */ React9.createElement("div", {
1085
- className: "flex justify-center w-full h-full",
1086
- role: "presentation"
1087
- }, /* @__PURE__ */ React9.createElement(Input2.Root, null, /* @__PURE__ */ React9.createElement(Input2.Checkbox, {
1088
- size: 4,
1089
- classNames: [
1090
- cell?.classNames
1091
- ],
1092
- checked,
1093
- onCheckedChange: (event) => {
1094
- if (row.getCanSelect()) {
1095
- row.getToggleSelectedHandler()(event);
1096
- }
1097
- },
1098
- disabled: !(row.getCanSelect() || row.getCanSelectSubRows())
1099
- })));
1100
- };
1101
- var SwitchBuilderCell = (cellContext) => {
1102
- const { onUpdate } = cellContext.column.columnDef.meta;
1103
- const value = cellContext.getValue();
1104
- return /* @__PURE__ */ React9.createElement(Input2.Root, null, /* @__PURE__ */ React9.createElement(Input2.Switch, {
1105
- classNames: "block mli-auto",
1106
- onClick: (event) => event.stopPropagation(),
1107
- disabled: !onUpdate,
1108
- checked: !!value,
1109
- onCheckedChange: (value2) => {
1110
- onUpdate?.(cellContext.row.original, cellContext.column.id, !!value2);
1111
- }
1112
- }));
1113
- };
1114
- var ColumnBuilder = class {
1115
- /**
1116
- * Combobox value
1117
- */
1118
- combobox({ label, classNames, model, onUpdate, ...props }) {
1119
- return {
1120
- minSize: 100,
1121
- header: (column) => {
1122
- return label ?? column.header.id;
1123
- },
1124
- cell: model && onUpdate ? ComboboxBuilderCell : (cellContext) => {
1125
- const cellValue = cellContext.getValue();
1126
- return /* @__PURE__ */ React9.createElement("div", {
1127
- className: mx5("truncate", classNames)
1128
- }, cellValue ? model?.getText(cellValue) : "");
1129
- },
1130
- ...props,
1131
- meta: {
1132
- ...props.meta,
1133
- model,
1134
- onUpdate,
1135
- cell: {
1136
- classNames,
1137
- ...props.meta?.cell
1138
- }
1139
- }
1140
- };
1141
- }
1142
- /**
1143
- * String formats.
1144
- */
1145
- string({ label, classNames, onUpdate, ...props } = {}) {
1146
- return {
1147
- minSize: 100,
1148
- // TODO(burdon): Default.
1149
- header: (column) => {
1150
- return label ?? column.header.id;
1151
- },
1152
- cell: onUpdate ? StringBuilderCell : (cell) => {
1153
- let value = cell.getValue();
1154
- if (typeof value === "object" && value?.type === "dxos.Text.v0") {
1155
- value = value.content;
1156
- }
1157
- return /* @__PURE__ */ React9.createElement("div", {
1158
- className: mx5("truncate", textPadding, classNames)
1159
- }, value);
1160
- },
1161
- ...props,
1162
- meta: {
1163
- ...props.meta,
1164
- onUpdate,
1165
- cell: {
1166
- ...props.meta?.cell,
1167
- classNames
1168
- }
1169
- }
1170
- };
1171
- }
1172
- /**
1173
- * Number formats.
1174
- */
1175
- number({ label, minSize, classNames, digits, onUpdate, ...props } = {}) {
1176
- return {
1177
- size: 100,
1178
- minSize: 100,
1179
- header: (cell) => label ?? cell.header.id,
1180
- cell: NumberBuilderCell,
1181
- ...props,
1182
- meta: {
1183
- ...props.meta,
1184
- onUpdate,
1185
- digits,
1186
- header: {
1187
- ...props.meta?.header
1188
- },
1189
- cell: {
1190
- ...props.meta?.cell,
1191
- classNames
1192
- }
1193
- }
1194
- };
1195
- }
1196
- /**
1197
- * Date formats.
1198
- */
1199
- // TODO(burdon): Date picker (pluggable renderers?)
1200
- date({ label, format: formatSpec, relative, classNames, ...props } = {}) {
1201
- return {
1202
- size: 220,
1203
- minSize: 100,
1204
- header: (cell) => label ?? cell.header.id,
1205
- cell: (cell) => {
1206
- const value = cell.getValue();
1207
- try {
1208
- const str = value ? formatSpec ? format(value, formatSpec) : relative ? formatDistanceToNow(value, {
1209
- addSuffix: true
1210
- }) : value.toISOString() : void 0;
1211
- return /* @__PURE__ */ React9.createElement("div", {
1212
- className: mx5(textPadding, classNames)
1213
- }, str);
1214
- } catch (err) {
1215
- log.info("formatError", {
1216
- value
1217
- }, {
1218
- F: __dxlog_file,
1219
- L: 378,
1220
- S: this,
1221
- C: (f, a) => f(...a)
1222
- });
1223
- return null;
1224
- }
1225
- },
1226
- ...props,
1227
- meta: {
1228
- ...props.meta,
1229
- cell: {
1230
- ...props.meta?.cell,
1231
- classNames
1232
- }
1233
- }
1234
- };
1235
- }
1236
- /**
1237
- * PublicKey with tooltip.
1238
- */
1239
- key({ label, tooltip, classNames, ...props } = {}) {
1240
- return {
1241
- size: 94,
1242
- minSize: 94,
1243
- header: (cell) => label ?? cell.header.id,
1244
- cell: (cell) => {
1245
- const value = cell.getValue();
1246
- if (!value) {
1247
- return;
1248
- }
1249
- const element = value.truncate();
1250
- if (!tooltip) {
1251
- return element;
1252
- }
1253
- return /* @__PURE__ */ React9.createElement(Tooltip.Provider, null, /* @__PURE__ */ React9.createElement(Tooltip.Root, null, /* @__PURE__ */ React9.createElement(Tooltip.Trigger, null, element), /* @__PURE__ */ React9.createElement(Tooltip.Portal, null, /* @__PURE__ */ React9.createElement(Tooltip.Content, {
1254
- side: "right"
1255
- }, /* @__PURE__ */ React9.createElement(Tooltip.Arrow, null), /* @__PURE__ */ React9.createElement(ClipboardText, {
1256
- onClick: (ev) => {
1257
- ev.stopPropagation();
1258
- void navigator.clipboard.writeText(value.toHex());
1259
- }
1260
- })))));
1261
- },
1262
- ...props,
1263
- meta: {
1264
- ...props.meta,
1265
- cell: {
1266
- ...props.meta?.cell,
1267
- classNames: [
1268
- "font-mono",
1269
- textPadding,
1270
- classNames
1271
- ]
1272
- }
1273
- }
1274
- };
1275
- }
1276
- /**
1277
- * Row selector
1278
- */
1279
- selectRow({ classNames, onUpdate, id = "selectRow" } = {}) {
1280
- return {
1281
- id,
1282
- size: defaultSizeRow,
1283
- enableResizing: false,
1284
- meta: {
1285
- onUpdate,
1286
- cell: {
1287
- classNames
1288
- }
1289
- },
1290
- header: ({ table }) => {
1291
- const { rowsSelectable } = useTableContext();
1292
- const checked = table.getIsSomeRowsSelected() ? "indeterminate" : table.getIsAllRowsSelected();
1293
- return rowsSelectable === "multi" ? /* @__PURE__ */ React9.createElement("div", {
1294
- className: "flex justify-center w-full h-full",
1295
- role: "presentation"
1296
- }, /* @__PURE__ */ React9.createElement(Input2.Root, null, /* @__PURE__ */ React9.createElement(Input2.Checkbox, {
1297
- size: 4,
1298
- classNames: [
1299
- "mli-auto",
1300
- classNames
1301
- ],
1302
- checked,
1303
- onCheckedChange: () => table.toggleAllRowsSelected()
1304
- }))) : null;
1305
- },
1306
- cell: RowSelectorBuilderCell
1307
- };
1308
- }
1309
- /**
1310
- * Switch
1311
- */
1312
- switch({ label, classNames, onUpdate, ...props } = {}) {
1313
- return {
1314
- size: 50,
1315
- minSize: 50,
1316
- header: (column) => label ?? column.header.id,
1317
- // TODO(zan): Implement sort algorithm.
1318
- enableSorting: true,
1319
- cell: SwitchBuilderCell,
1320
- ...props,
1321
- meta: {
1322
- ...props.meta,
1323
- onUpdate,
1324
- cell: {
1325
- ...props.meta?.cell,
1326
- classNames: [
1327
- textPadding,
1328
- classNames
1329
- ]
1330
- }
1331
- }
1332
- };
1333
- }
1334
- /**
1335
- * Icon based on boolean value.
1336
- */
1337
- icon({ label, size, on, off, ...props } = {}) {
1338
- const IconOn = on?.Icon ?? Check;
1339
- const IconOff = off?.Icon ?? X2;
1340
- return {
1341
- size: size ?? defaultSizeRow,
1342
- // TODO(zan): Implement sort algorithm.
1343
- enableSorting: false,
1344
- header: (column) => /* @__PURE__ */ React9.createElement("div", {
1345
- className: "justify-center"
1346
- }, label ?? column.header.id),
1347
- cell: (cell) => {
1348
- const value = cell.getValue();
1349
- if (value) {
1350
- return /* @__PURE__ */ React9.createElement(IconOn, {
1351
- className: mx5("block mli-auto", getSize3(6), on?.className ?? "text-green-700")
1352
- });
1353
- } else if (value === false) {
1354
- return /* @__PURE__ */ React9.createElement(IconOff, {
1355
- className: mx5("block mli-auto", getSize3(6), off?.className ?? "text-red-700")
1356
- });
1357
- } else {
1358
- return null;
1359
- }
1360
- },
1361
- ...props
1362
- };
1363
- }
1364
- /**
1365
- * This display column type is for nested/unhandled data to appear as JSON.
1366
- */
1367
- json({ label, classNames, ...props } = {}) {
1368
- return {
1369
- size: 120,
1370
- minSize: 120,
1371
- header: (cell) => label ?? cell.header.id,
1372
- cell: (cell) => {
1373
- const value = cell.getValue();
1374
- return /* @__PURE__ */ React9.createElement("div", {
1375
- className: "overflow-scroll"
1376
- }, /* @__PURE__ */ React9.createElement("code", {
1377
- className: "text-xs"
1378
- }, JSON.stringify(value)));
1379
- },
1380
- ...props,
1381
- meta: {
1382
- ...props.meta,
1383
- cell: {
1384
- ...props.meta?.cell,
1385
- classNames: [
1386
- "font-mono",
1387
- textPadding,
1388
- classNames
1389
- ]
1390
- }
1391
- }
1392
- };
1393
- }
1394
- };
1395
-
1396
- // packages/ui/react-ui-table/src/deprecated/schema/column-utils.ts
1397
- import { TypeEnum } from "@dxos/echo-schema";
1398
- import { FormatEnum } from "@dxos/echo-schema";
1399
- import { mapSchemaToFields } from "@dxos/schema";
1400
- var schemaToColumnDefs = (schema) => {
1401
- const { helper, builder } = createColumnBuilder();
1402
- return mapSchemaToFields(schema).map(({ property, type, format: format2 }) => {
1403
- const propertyKey = property.toString();
1404
- if (!format2) {
1405
- switch (type) {
1406
- case TypeEnum.String: {
1407
- return helper.accessor(propertyKey, builder.string({
1408
- label: propertyKey,
1409
- classNames: [
1410
- property === "id" && "font-mono"
1411
- ]
1412
- }));
1413
- }
1414
- case TypeEnum.Number: {
1415
- return helper.accessor(propertyKey, builder.number({
1416
- label: propertyKey
1417
- }));
1418
- }
1419
- case TypeEnum.Boolean: {
1420
- return helper.accessor(propertyKey, builder.switch({
1421
- label: propertyKey
1422
- }));
1423
- }
1424
- default: {
1425
- throw new Error(`Unhandled scalar type: ${type}`);
1426
- }
1427
- }
1428
- }
1429
- switch (format2) {
1430
- case FormatEnum.Date: {
1431
- return helper.accessor(propertyKey, builder.date({
1432
- label: propertyKey
1433
- }));
1434
- }
1435
- case FormatEnum.JSON: {
1436
- return helper.accessor(propertyKey, builder.json({
1437
- label: propertyKey,
1438
- id: propertyKey
1439
- }));
1440
- }
1441
- default: {
1442
- throw new Error(`Unhandled format: ${format2}`);
1443
- }
1444
- }
1445
- });
1446
- };
1447
- export {
1448
- CellCombobox,
1449
- ColumnBuilder,
1450
- ColumnMenu,
1451
- ColumnSettings,
1452
- MemoizedVirtualizedTableContent,
1453
- SortIndicator,
1454
- TABLE_NAME,
1455
- Table,
1456
- TablePrimitive,
1457
- TableProvider,
1458
- TableRootContext,
1459
- createColumnBuilder,
1460
- currentRow,
1461
- flushPadding,
1462
- gridCellFocusRing,
1463
- groupTh,
1464
- headPadding,
1465
- schemaToColumnDefs,
1466
- selectedRow,
1467
- tableRoot,
1468
- tbodyRoot,
1469
- tbodyTr,
1470
- tdRoot,
1471
- textPadding,
1472
- theadResizeRoot,
1473
- theadRoot,
1474
- theadTh,
1475
- theadTr,
1476
- translations_default as translations,
1477
- useColumnResizing,
1478
- useColumnSorting,
1479
- usePinLastRow,
1480
- useRowSelection,
1481
- useSortColumn,
1482
- useTableContext,
1483
- useTableRootContext
1484
- };
1485
- //# sourceMappingURL=index.mjs.map