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