@dxos/react-ui-table 0.7.5-labs.a279d8c → 0.7.5-labs.c0e040f

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.
@@ -398,7 +398,7 @@ var BUTTON_IDENTIFIERS = {
398
398
  var createButton = ({ attr, data, disabled = false, icon, testId, type = "primary" }) => {
399
399
  const dataAttrs = Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
400
400
  const positionClass = type === "primary" ? "inline-end-2" : "inline-end-9";
401
- return `<button ${attr} data-testid="${testId}" class="ch-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? "disabled" : ""}><svg><use href="/icons.svg#${icon}"/></svg></button>`;
401
+ return `<button ${attr} data-testid="${testId}" class="dx-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? "disabled" : ""}><svg><use href="/icons.svg#${icon}"/></svg></button>`;
402
402
  };
403
403
  var addColumnButton = {
404
404
  attr: BUTTON_IDENTIFIERS.newColumn,
@@ -509,8 +509,8 @@ var CONTROL_IDENTIFIERS = {
509
509
  switch: "data-table-switch"
510
510
  };
511
511
  var BASE_CLASSES = {
512
- checkbox: "absolute inset-block-[.375rem] inline-end-[.375rem] ch-checkbox",
513
- switch: "absolute inset-block-[.25rem] inline-end-[.25rem] ch-checkbox--switch"
512
+ checkbox: "absolute inset-block-[.375rem] inline-end-[.375rem] dx-checkbox",
513
+ switch: "absolute inset-block-[.25rem] inline-end-[.25rem] dx-checkbox--switch"
514
514
  };
515
515
  var renderAttributes = (data) => {
516
516
  return Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
@@ -782,6 +782,14 @@ var TableSorting = class {
782
782
  if (value == null) {
783
783
  return value;
784
784
  }
785
+ if (format === FormatEnum2.SingleSelect) {
786
+ const options = props.options;
787
+ if (!options) {
788
+ return void 0;
789
+ }
790
+ const option = options.find((option2) => option2.id === value);
791
+ return option ? options.indexOf(option) : void 0;
792
+ }
785
793
  if (format === FormatEnum2.Ref && field.referencePath) {
786
794
  const refValue = getValue(value.target, field.referencePath);
787
795
  return refValue;
@@ -1199,7 +1207,8 @@ var TablePresentation = class {
1199
1207
  return "";
1200
1208
  }
1201
1209
  switch (props.format) {
1202
- case FormatEnum4.Boolean: {
1210
+ case FormatEnum4.Boolean:
1211
+ case FormatEnum4.SingleSelect: {
1203
1212
  return "";
1204
1213
  }
1205
1214
  case FormatEnum4.Ref: {
@@ -1251,6 +1260,16 @@ var TablePresentation = class {
1251
1260
  });
1252
1261
  cell.readonly = true;
1253
1262
  }
1263
+ if (props.format === FormatEnum4.SingleSelect) {
1264
+ const value = getValue3(obj, field.path);
1265
+ const options = this.model.projection.getFieldProjection(field.id).props.options;
1266
+ if (options) {
1267
+ const option = options.find((o) => o.id === value);
1268
+ if (option) {
1269
+ cell.accessoryHtml = `<span class="dx-tag" data-hue="${option.color}">${option.title}</span>`;
1270
+ }
1271
+ }
1272
+ }
1254
1273
  const idx = toPlaneCellIndex({
1255
1274
  col: colIndex,
1256
1275
  row: displayIndex
@@ -1914,7 +1933,9 @@ var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
1914
1933
  };
1915
1934
 
1916
1935
  // packages/ui/react-ui-table/src/hooks/useTableModel.ts
1936
+ import { effect as effect3 } from "@preact/signals-core";
1917
1937
  import { useEffect as useEffect2, useState as useState3 } from "react";
1938
+ import { useSelectionActions } from "@dxos/react-ui-attention";
1918
1939
  var useTableModel = ({ objects, table, projection, ...props }) => {
1919
1940
  const [model, setModel] = useState3();
1920
1941
  useEffect2(() => {
@@ -1947,6 +1968,23 @@ var useTableModel = ({ objects, table, projection, ...props }) => {
1947
1968
  model,
1948
1969
  objects
1949
1970
  ]);
1971
+ const { select, clear } = useSelectionActions(table?.id);
1972
+ useEffect2(() => {
1973
+ if (!model) {
1974
+ return;
1975
+ }
1976
+ const unsubscribe = effect3(() => {
1977
+ select([
1978
+ ...model.selection.selection.value
1979
+ ]);
1980
+ });
1981
+ return () => {
1982
+ clear();
1983
+ unsubscribe();
1984
+ };
1985
+ }, [
1986
+ model
1987
+ ]);
1950
1988
  return model;
1951
1989
  };
1952
1990
  export {