@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.
@@ -21,6 +21,7 @@ import { type ViewType, type ViewProjection } from '@dxos/schema';
21
21
  import { type SelectionMode, SelectionModel } from './selection-model';
22
22
  import { TableSorting } from './table-sorting';
23
23
  import { touch } from '../util';
24
+ import { extractTagIds } from '../util/tag';
24
25
 
25
26
  // TODO(burdon): Use schema types.
26
27
  export type TableRow = Record<JsonProp, any> & { id: string };
@@ -348,6 +349,22 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
348
349
  break;
349
350
  }
350
351
 
352
+ case FormatEnum.SingleSelect: {
353
+ const ids = extractTagIds(value);
354
+ if (ids && ids.length > 0) {
355
+ setValue(this._rows.value[rowIdx], field.path, ids[0]);
356
+ }
357
+ break;
358
+ }
359
+
360
+ case FormatEnum.MultiSelect: {
361
+ const ids = extractTagIds(value);
362
+ if (ids) {
363
+ setValue(this._rows.value[rowIdx], field.path, ids);
364
+ }
365
+ break;
366
+ }
367
+
351
368
  default: {
352
369
  setValue(
353
370
  this._rows.value[rowIdx],
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { signal } from '@preact/signals-core';
6
6
 
7
- import { FormatEnum, getValue } from '@dxos/echo-schema';
7
+ import { FormatEnum, getDXN, getValue } from '@dxos/echo-schema';
8
8
  import { cellClassesForFieldType, formatForDisplay } from '@dxos/react-ui-form';
9
9
  import {
10
10
  type DxGridPlane,
@@ -124,10 +124,8 @@ export class TablePresentation<T extends TableRow = TableRow> {
124
124
  if (props.format === FormatEnum.Ref && props.referenceSchema) {
125
125
  const targetObj = getValue(obj, field.path)?.target;
126
126
  if (targetObj) {
127
- cell.accessoryHtml = tableButtons.referencedCell.render({
128
- targetId: targetObj.id as any as string,
129
- schemaId: props.referenceSchema,
130
- });
127
+ const dxn = getDXN(targetObj)?.toString();
128
+ 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>`;
131
129
  }
132
130
  }
133
131
 
@@ -15,7 +15,6 @@ export const BUTTON_IDENTIFIERS: { [K in TableButton]: string } = {
15
15
  type ButtonData =
16
16
  | { type: 'columnSettings'; fieldId: string }
17
17
  | { type: 'newColumn'; disabled?: boolean }
18
- | { type: 'referencedCell'; schemaId: string; targetId: string }
19
18
  | { type: 'rowMenu'; rowIndex: number }
20
19
  | { type: 'sort'; fieldId: string; direction?: 'asc' | 'desc' };
21
20
 
@@ -76,27 +75,6 @@ const columnSettingsButton = {
76
75
  }),
77
76
  } as const;
78
77
 
79
- const referencedCellButton = {
80
- attr: BUTTON_IDENTIFIERS.referencedCell,
81
- icon: 'ph--link-simple-horizontal--regular',
82
- render: ({ targetId, schemaId }: Omit<Extract<ButtonData, { type: 'referencedCell' }>, 'type'>) => {
83
- return createButton({
84
- attr: BUTTON_IDENTIFIERS.referencedCell,
85
- icon: referencedCellButton.icon,
86
- data: {
87
- 'data-target-id': targetId,
88
- 'data-schema-id': schemaId,
89
- },
90
- testId: 'table-ref-cell-button',
91
- });
92
- },
93
- getData: (el: HTMLElement): Extract<ButtonData, { type: 'referencedCell' }> => ({
94
- type: 'referencedCell',
95
- targetId: el.getAttribute('data-target-id')!,
96
- schemaId: el.getAttribute('data-schema-id')!,
97
- }),
98
- } as const;
99
-
100
78
  const rowMenuButton = {
101
79
  attr: BUTTON_IDENTIFIERS.rowMenu,
102
80
  icon: 'ph--dots-three--regular',
@@ -143,7 +121,6 @@ const sortButton = {
143
121
  export const tableButtons = {
144
122
  addColumn: addColumnButton,
145
123
  columnSettings: columnSettingsButton,
146
- referencedCell: referencedCellButton,
147
124
  rowMenu: rowMenuButton,
148
125
  sort: sortButton,
149
126
  } as const;
package/src/util/table.ts CHANGED
@@ -41,11 +41,7 @@ export const initializeTable = async ({
41
41
  throw new Error(`Schema not found: ${typename}`);
42
42
  }
43
43
 
44
- // We need to get the schema properties here.
45
- // For now, only simple types and refs, not compound types are going to be supported.
46
- const fields = getSchemaProperties(schema.ast)
47
- .filter((prop) => prop.format !== FormatEnum.Ref)
48
- .map((prop) => prop.name);
44
+ const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
49
45
 
50
46
  table.view = makeRef(
51
47
  createView({
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // TODO(ZaymonFC): Push this into the tag picker module.
6
+
7
+ /**
8
+ * Regex pattern for matching tags in the format [Label](id)
9
+ */
10
+ export const TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
11
+
12
+ /**
13
+ * Extracts tag IDs from a string in the format [Label](id)
14
+ * @param value The string to extract IDs from
15
+ * @returns Array of extracted IDs or undefined if no matches or value is not a string
16
+ */
17
+ export const extractTagIds = (value: unknown): string[] | undefined => {
18
+ if (typeof value !== 'string') {
19
+ return undefined;
20
+ }
21
+
22
+ const ids: string[] = [];
23
+ let match;
24
+
25
+ // Use the global regex to find all matches
26
+ while ((match = TAG_PATTERN_REGEX.exec(value)) !== null) {
27
+ if (match[2]) {
28
+ ids.push(match[2]);
29
+ }
30
+ }
31
+
32
+ return ids.length > 0 ? ids : undefined;
33
+ };
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { type TableModel, type ModalController } from '../../model';
3
- type RefPanelProps = {
4
- model: TableModel;
5
- modals: ModalController;
6
- };
7
- export declare const RefPanel: ({ model, modals }: RefPanelProps) => React.JSX.Element | null;
8
- export {};
9
- //# sourceMappingURL=RefPanel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RefPanel.d.ts","sourceRoot":"","sources":["../../../../../src/components/Table/RefPanel.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAEpE,KAAK,aAAa,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAUpE,eAAO,MAAM,QAAQ,sBAAuB,aAAa,6BA6BxD,CAAC"}
@@ -1,52 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import React from 'react';
6
-
7
- import { type Space } from '@dxos/react-client/echo';
8
- import { Popover } from '@dxos/react-ui';
9
- import { Form } from '@dxos/react-ui-form';
10
-
11
- import { type TableModel, type ModalController } from '../../model';
12
-
13
- type RefPanelProps = { model: TableModel; modals: ModalController };
14
-
15
- const getRefTargetObj = (space?: Space, id?: string) => {
16
- if (space && id) {
17
- return space?.db.getObjectById(id);
18
- } else {
19
- return undefined;
20
- }
21
- };
22
-
23
- export const RefPanel = ({ model, modals }: RefPanelProps) => {
24
- const state = modals.state.value;
25
- const space = model?.space;
26
- const targetObj = getRefTargetObj(space, state?.type === 'refPanel' ? state.targetId : undefined);
27
- const schema = space && state?.type === 'refPanel' ? space.db.schemaRegistry.getSchema(state.typename) : undefined;
28
-
29
- if (!model.view || !model.projection) {
30
- return null;
31
- }
32
-
33
- return (
34
- <Popover.Root
35
- modal={false}
36
- open={state?.type === 'refPanel' && !!targetObj && !!schema}
37
- onOpenChange={(nextOpen) => {
38
- if (!nextOpen) {
39
- return modals.close();
40
- }
41
- }}
42
- >
43
- <Popover.VirtualTrigger virtualRef={modals.trigger} />
44
- <Popover.Portal>
45
- <Popover.Content classNames='md:is-64'>
46
- {targetObj && schema && <Form readonly values={targetObj} schema={schema} />}
47
- <Popover.Arrow />
48
- </Popover.Content>
49
- </Popover.Portal>
50
- </Popover.Root>
51
- );
52
- };