@dxos/react-ui-table 0.8.2-main.f081794 → 0.8.2-main.f11618f

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.
@@ -36,13 +36,13 @@ var translations_default = [
36
36
  ];
37
37
 
38
38
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
39
- import React7, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4, useEffect as useEffect2 } from "react";
39
+ import React6, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4, useEffect as useEffect2 } from "react";
40
40
  import { getValue as getValue4 } from "@dxos/echo-schema";
41
41
  import { invariant as invariant3 } from "@dxos/invariant";
42
42
  import { Filter } from "@dxos/react-client/echo";
43
43
  import { useTranslation as useTranslation3 } from "@dxos/react-ui";
44
44
  import { useAttention } from "@dxos/react-ui-attention";
45
- import { closestCell, Grid } from "@dxos/react-ui-grid";
45
+ import { closestCell, Grid, gridSeparatorInlineEnd, gridSeparatorBlockEnd } from "@dxos/react-ui-grid";
46
46
  import { mx as mx2 } from "@dxos/react-ui-theme";
47
47
  import { isNotFalsy, safeParseInt } from "@dxos/util";
48
48
 
@@ -223,46 +223,8 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
223
223
  }), /* @__PURE__ */ React3.createElement(Popover.Arrow, null))));
224
224
  };
225
225
 
226
- // packages/ui/react-ui-table/src/components/Table/RefPanel.tsx
227
- import React4 from "react";
228
- import { Popover as Popover2 } from "@dxos/react-ui";
229
- import { Form as Form2 } from "@dxos/react-ui-form";
230
- var getRefTargetObj = (space, id) => {
231
- if (space && id) {
232
- return space?.db.getObjectById(id);
233
- } else {
234
- return void 0;
235
- }
236
- };
237
- var RefPanel = ({ model, modals }) => {
238
- const state = modals.state.value;
239
- const space = model?.space;
240
- const targetObj = getRefTargetObj(space, state?.type === "refPanel" ? state.targetId : void 0);
241
- const schema = space && state?.type === "refPanel" ? space.db.schemaRegistry.getSchema(state.typename) : void 0;
242
- if (!model.view || !model.projection) {
243
- return null;
244
- }
245
- return /* @__PURE__ */ React4.createElement(Popover2.Root, {
246
- modal: false,
247
- open: state?.type === "refPanel" && !!targetObj && !!schema,
248
- onOpenChange: (nextOpen) => {
249
- if (!nextOpen) {
250
- return modals.close();
251
- }
252
- }
253
- }, /* @__PURE__ */ React4.createElement(Popover2.VirtualTrigger, {
254
- virtualRef: modals.trigger
255
- }), /* @__PURE__ */ React4.createElement(Popover2.Portal, null, /* @__PURE__ */ React4.createElement(Popover2.Content, {
256
- classNames: "md:is-64"
257
- }, targetObj && schema && /* @__PURE__ */ React4.createElement(Form2, {
258
- readonly: true,
259
- values: targetObj,
260
- schema
261
- }), /* @__PURE__ */ React4.createElement(Popover2.Arrow, null))));
262
- };
263
-
264
226
  // packages/ui/react-ui-table/src/components/Table/RowActionsMenu.tsx
265
- import React5 from "react";
227
+ import React4 from "react";
266
228
  import { DropdownMenu as DropdownMenu3, useTranslation as useTranslation2 } from "@dxos/react-ui";
267
229
  var RowActionsMenu = ({ model, modals }) => {
268
230
  const { t } = useTranslation2(translationKey);
@@ -271,23 +233,23 @@ var RowActionsMenu = ({ model, modals }) => {
271
233
  if (state?.type !== "row") {
272
234
  return null;
273
235
  }
274
- return /* @__PURE__ */ React5.createElement(DropdownMenu3.Root, {
236
+ return /* @__PURE__ */ React4.createElement(DropdownMenu3.Root, {
275
237
  modal: false,
276
238
  open: true,
277
239
  onOpenChange: modals.close
278
- }, /* @__PURE__ */ React5.createElement(DropdownMenu3.VirtualTrigger, {
240
+ }, /* @__PURE__ */ React4.createElement(DropdownMenu3.VirtualTrigger, {
279
241
  virtualRef: modals.trigger
280
- }), /* @__PURE__ */ React5.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React5.createElement(DropdownMenu3.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React5.createElement(DropdownMenu3.Item, {
242
+ }), /* @__PURE__ */ React4.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu3.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React4.createElement(DropdownMenu3.Item, {
281
243
  "data-testid": "row-menu-delete",
282
244
  onClick: () => model.deleteRow(state.rowIndex)
283
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React5.createElement(DropdownMenu3.Item, {
245
+ }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React4.createElement(DropdownMenu3.Item, {
284
246
  key: action.id,
285
247
  "data-testid": `row-action-${action.id}`,
286
248
  onClick: () => {
287
249
  modals.close();
288
250
  model.handleRowAction(action.id, state.rowIndex);
289
251
  }
290
- }, t(action.translationKey)))), /* @__PURE__ */ React5.createElement(DropdownMenu3.Arrow, null)));
252
+ }, t(action.translationKey)))), /* @__PURE__ */ React4.createElement(DropdownMenu3.Arrow, null)));
291
253
  };
292
254
 
293
255
  // packages/ui/react-ui-table/src/model/table-model.ts
@@ -392,7 +354,7 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
392
354
  if (!schema) {
393
355
  throw new Error(`Schema not found: ${typename}`);
394
356
  }
395
- const fields = getSchemaProperties(schema.ast).filter((prop) => prop.format !== FormatEnum.Ref).map((prop) => prop.name);
357
+ const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
396
358
  table.view = makeRef2(createView2({
397
359
  // TODO(ZaymonFC): Don't hardcode name?
398
360
  name: "View",
@@ -518,26 +480,6 @@ var columnSettingsButton = {
518
480
  fieldId: el.getAttribute("data-field-id")
519
481
  })
520
482
  };
521
- var referencedCellButton = {
522
- attr: BUTTON_IDENTIFIERS.referencedCell,
523
- icon: "ph--link-simple-horizontal--regular",
524
- render: ({ targetId, schemaId }) => {
525
- return createButton({
526
- attr: BUTTON_IDENTIFIERS.referencedCell,
527
- icon: referencedCellButton.icon,
528
- data: {
529
- "data-target-id": targetId,
530
- "data-schema-id": schemaId
531
- },
532
- testId: "table-ref-cell-button"
533
- });
534
- },
535
- getData: (el) => ({
536
- type: "referencedCell",
537
- targetId: el.getAttribute("data-target-id"),
538
- schemaId: el.getAttribute("data-schema-id")
539
- })
540
- };
541
483
  var rowMenuButton = {
542
484
  attr: BUTTON_IDENTIFIERS.rowMenu,
543
485
  icon: "ph--dots-three--regular",
@@ -582,7 +524,6 @@ var sortButton = {
582
524
  var tableButtons = {
583
525
  addColumn: addColumnButton,
584
526
  columnSettings: columnSettingsButton,
585
- referencedCell: referencedCellButton,
586
527
  rowMenu: rowMenuButton,
587
528
  sort: sortButton
588
529
  };
@@ -893,6 +834,22 @@ var TableSorting = class {
893
834
  }
894
835
  };
895
836
 
837
+ // packages/ui/react-ui-table/src/util/tag.ts
838
+ var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
839
+ var extractTagIds = (value) => {
840
+ if (typeof value !== "string") {
841
+ return void 0;
842
+ }
843
+ const ids = [];
844
+ let match;
845
+ while ((match = TAG_PATTERN_REGEX.exec(value)) !== null) {
846
+ if (match[2]) {
847
+ ids.push(match[2]);
848
+ }
849
+ }
850
+ return ids.length > 0 ? ids : void 0;
851
+ };
852
+
896
853
  // packages/ui/react-ui-table/src/model/table-model.ts
897
854
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
898
855
  var defaultFeatures = {
@@ -997,6 +954,20 @@ var TableModel = class extends Resource2 {
997
954
  }
998
955
  break;
999
956
  }
957
+ case FormatEnum3.SingleSelect: {
958
+ const ids = extractTagIds(value);
959
+ if (ids && ids.length > 0) {
960
+ setValue(this._rows.value[rowIdx], field.path, ids[0]);
961
+ }
962
+ break;
963
+ }
964
+ case FormatEnum3.MultiSelect: {
965
+ const ids = extractTagIds(value);
966
+ if (ids) {
967
+ setValue(this._rows.value[rowIdx], field.path, ids);
968
+ }
969
+ break;
970
+ }
1000
971
  default: {
1001
972
  setValue(this._rows.value[rowIdx], field.path, parseValue({
1002
973
  type: props.type,
@@ -1017,7 +988,7 @@ var TableModel = class extends Resource2 {
1017
988
  };
1018
989
  invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1019
990
  F: __dxlog_file,
1020
- L: 114,
991
+ L: 115,
1021
992
  S: this,
1022
993
  A: [
1023
994
  "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
@@ -1077,7 +1048,7 @@ var TableModel = class extends Resource2 {
1077
1048
  get columnMeta() {
1078
1049
  invariant(this._columnMeta, void 0, {
1079
1050
  F: __dxlog_file,
1080
- L: 183,
1051
+ L: 184,
1081
1052
  S: this,
1082
1053
  A: [
1083
1054
  "this._columnMeta",
@@ -1303,7 +1274,7 @@ var ModalController = class {
1303
1274
 
1304
1275
  // packages/ui/react-ui-table/src/model/table-presentation.ts
1305
1276
  import { signal as signal5 } from "@preact/signals-core";
1306
- import { FormatEnum as FormatEnum4, getValue as getValue3 } from "@dxos/echo-schema";
1277
+ import { FormatEnum as FormatEnum4, getDXN, getValue as getValue3 } from "@dxos/echo-schema";
1307
1278
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1308
1279
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1309
1280
  import { mx } from "@dxos/react-ui-theme";
@@ -1405,10 +1376,8 @@ var TablePresentation = class {
1405
1376
  if (props.format === FormatEnum4.Ref && props.referenceSchema) {
1406
1377
  const targetObj = getValue3(obj, field.path)?.target;
1407
1378
  if (targetObj) {
1408
- cell.accessoryHtml = tableButtons.referencedCell.render({
1409
- targetId: targetObj.id,
1410
- schemaId: props.referenceSchema
1411
- });
1379
+ const dxn = getDXN(targetObj)?.toString();
1380
+ cell.accessoryHtml = `<dx-ref-tag ref=${dxn} class="dx-button block is-6 pli-[3px] plb-[3px] pbe-[2px] min-bs-0 absolute inline-end-1"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
1412
1381
  }
1413
1382
  }
1414
1383
  if (props.format === FormatEnum4.Boolean) {
@@ -1600,7 +1569,7 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1600
1569
  };
1601
1570
 
1602
1571
  // packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
1603
- import React6, { useCallback as useCallback3, useMemo as useMemo3, useRef } from "react";
1572
+ import React5, { useCallback as useCallback3, useMemo as useMemo3, useRef } from "react";
1604
1573
  import { FormatEnum as FormatEnum5 } from "@dxos/echo-schema";
1605
1574
  import { invariant as invariant2 } from "@dxos/invariant";
1606
1575
  import { useThemeContext } from "@dxos/react-ui";
@@ -1855,7 +1824,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
1855
1824
  model,
1856
1825
  editing
1857
1826
  ]);
1858
- return /* @__PURE__ */ React6.createElement(GridCellEditor, {
1827
+ return /* @__PURE__ */ React5.createElement(GridCellEditor, {
1859
1828
  extension,
1860
1829
  getCellContent,
1861
1830
  onBlur: handleBlur
@@ -1888,10 +1857,8 @@ var determineNavigationDelta = ({ key, shift }) => {
1888
1857
 
1889
1858
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
1890
1859
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
1891
- var inlineEndLine = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-separator";
1892
- var blockEndLine = "[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-separator";
1893
1860
  var TableRoot = ({ children, role }) => {
1894
- return /* @__PURE__ */ React7.createElement("div", {
1861
+ return /* @__PURE__ */ React6.createElement("div", {
1895
1862
  role: "none",
1896
1863
  className: mx2("relative !border-separator", role === "section" ? "attention-surface overflow-hidden [&_.dx-grid]:max-is-[--dx-grid-content-inline-size]" : "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:bs-0 [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]")
1897
1864
  }, children);
@@ -1911,14 +1878,18 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1911
1878
  }, [
1912
1879
  model
1913
1880
  ]);
1881
+ const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
1882
+ presentation
1883
+ ]);
1914
1884
  useEffect2(() => {
1915
1885
  if (!presentation || !dxGrid) {
1916
1886
  return;
1917
1887
  }
1918
- dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
1888
+ dxGrid.getCells = getCells;
1919
1889
  }, [
1920
1890
  presentation,
1921
- dxGrid
1891
+ dxGrid,
1892
+ getCells
1922
1893
  ]);
1923
1894
  useImperativeHandle(forwardedRef, () => {
1924
1895
  if (!presentation || !dxGrid) {
@@ -1974,10 +1945,6 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
1974
1945
  modals.showColumnCreator();
1975
1946
  break;
1976
1947
  }
1977
- case "referencedCell": {
1978
- modals.showReferencePanel(data.targetId, data.schemaId);
1979
- break;
1980
- }
1981
1948
  case "sort": {
1982
1949
  model?.sorting?.toggleSort(data.fieldId);
1983
1950
  break;
@@ -2089,7 +2056,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
2089
2056
  const space = model.space;
2090
2057
  invariant3(space, void 0, {
2091
2058
  F: __dxlog_file4,
2092
- L: 312,
2059
+ L: 307,
2093
2060
  S: void 0,
2094
2061
  A: [
2095
2062
  "space",
@@ -2126,21 +2093,21 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
2126
2093
  t
2127
2094
  ]);
2128
2095
  if (!model || !modals) {
2129
- return /* @__PURE__ */ React7.createElement("span", {
2096
+ return /* @__PURE__ */ React6.createElement("span", {
2130
2097
  role: "none",
2131
2098
  className: "attention-surface"
2132
2099
  });
2133
2100
  }
2134
- return /* @__PURE__ */ React7.createElement(Grid.Root, {
2101
+ return /* @__PURE__ */ React6.createElement(Grid.Root, {
2135
2102
  id: model.id ?? "table-grid"
2136
- }, /* @__PURE__ */ React7.createElement(TableCellEditor, {
2103
+ }, /* @__PURE__ */ React6.createElement(TableCellEditor, {
2137
2104
  model,
2138
2105
  modals,
2139
2106
  onEnter: handleEnter,
2140
2107
  onFocus: handleFocus,
2141
2108
  onQuery: handleQuery
2142
- }), /* @__PURE__ */ React7.createElement(Grid.Content, {
2143
- className: mx2("[--dx-grid-base:var(--surface-bg)]", inlineEndLine, blockEndLine),
2109
+ }), /* @__PURE__ */ React6.createElement(Grid.Content, {
2110
+ className: mx2("[--dx-grid-base:var(--surface-bg)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
2144
2111
  frozen,
2145
2112
  // getCells={getCells}
2146
2113
  columns: model.columnMeta.value,
@@ -2152,20 +2119,17 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
2152
2119
  onKeyDown: handleKeyDown,
2153
2120
  onWheelCapture: handleWheel,
2154
2121
  ref: setDxGrid
2155
- }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
2122
+ }), /* @__PURE__ */ React6.createElement(RowActionsMenu, {
2156
2123
  model,
2157
2124
  modals
2158
- }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
2125
+ }), /* @__PURE__ */ React6.createElement(ColumnActionsMenu, {
2159
2126
  model,
2160
2127
  modals
2161
- }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
2128
+ }), /* @__PURE__ */ React6.createElement(ColumnSettings, {
2162
2129
  model,
2163
2130
  modals,
2164
2131
  onNewColumn: handleNewColumn
2165
- }), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
2166
- model,
2167
- modals
2168
- }), /* @__PURE__ */ React7.createElement(RefPanel, {
2132
+ }), /* @__PURE__ */ React6.createElement(CreateRefPanel, {
2169
2133
  model,
2170
2134
  modals
2171
2135
  }));
@@ -2176,7 +2140,7 @@ var Table = {
2176
2140
  };
2177
2141
 
2178
2142
  // packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
2179
- import React8, { useRef as useRef2, useMemo as useMemo5, useCallback as useCallback5 } from "react";
2143
+ import React7, { useRef as useRef2, useMemo as useMemo5, useCallback as useCallback5 } from "react";
2180
2144
  import { useDefaultValue } from "@dxos/react-ui";
2181
2145
  import { mx as mx3 } from "@dxos/react-ui-theme";
2182
2146
 
@@ -2301,13 +2265,13 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
2301
2265
  }, [
2302
2266
  model
2303
2267
  ]);
2304
- return /* @__PURE__ */ React8.createElement("div", {
2268
+ return /* @__PURE__ */ React7.createElement("div", {
2305
2269
  role: "none",
2306
2270
  className: mx3("is-full bs-full grow grid", classNames)
2307
- }, /* @__PURE__ */ React8.createElement("div", {
2271
+ }, /* @__PURE__ */ React7.createElement("div", {
2308
2272
  role: "none",
2309
2273
  className: "grid min-bs-0 overflow-hidden"
2310
- }, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
2274
+ }, /* @__PURE__ */ React7.createElement(Table.Root, null, /* @__PURE__ */ React7.createElement(Table.Main, {
2311
2275
  ref: tableRef,
2312
2276
  model,
2313
2277
  presentation,
@@ -2317,7 +2281,7 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
2317
2281
  };
2318
2282
 
2319
2283
  // packages/ui/react-ui-table/src/components/TableToolbar/TableToolbar.tsx
2320
- import React9, { useCallback as useCallback6, useMemo as useMemo6 } from "react";
2284
+ import React8, { useCallback as useCallback6, useMemo as useMemo6 } from "react";
2321
2285
  import { live as live4 } from "@dxos/live-object";
2322
2286
  import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
2323
2287
  var createTableToolbarActions = (state) => {
@@ -2379,11 +2343,11 @@ var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
2379
2343
  state
2380
2344
  ]);
2381
2345
  const menu = useMenuActions(actionsCreator);
2382
- return /* @__PURE__ */ React9.createElement(MenuProvider, {
2346
+ return /* @__PURE__ */ React8.createElement(MenuProvider, {
2383
2347
  ...menu,
2384
2348
  attendableId,
2385
2349
  onAction
2386
- }, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
2350
+ }, /* @__PURE__ */ React8.createElement(ToolbarMenu, {
2387
2351
  classNames
2388
2352
  }));
2389
2353
  };