@dxos/react-ui-table 0.7.4 → 0.7.5-main.499c70c

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 (90) hide show
  1. package/dist/lib/browser/{chunk-IYCSJDMB.mjs → chunk-AT7O4RAD.mjs} +4 -4
  2. package/dist/lib/browser/{chunk-IYCSJDMB.mjs.map → chunk-AT7O4RAD.mjs.map} +2 -2
  3. package/dist/lib/browser/index.mjs +1398 -1216
  4. package/dist/lib/browser/index.mjs.map +4 -4
  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-MHBMVCFZ.cjs → chunk-YSBXNBDJ.cjs} +6 -6
  8. package/dist/lib/node/{chunk-MHBMVCFZ.cjs.map → chunk-YSBXNBDJ.cjs.map} +2 -2
  9. package/dist/lib/node/index.cjs +1130 -934
  10. package/dist/lib/node/index.cjs.map +4 -4
  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-BMWGPXPL.mjs → chunk-6OH2NHUX.mjs} +4 -4
  15. package/dist/lib/node-esm/{chunk-BMWGPXPL.mjs.map → chunk-6OH2NHUX.mjs.map} +2 -2
  16. package/dist/lib/node-esm/index.mjs +1398 -1216
  17. package/dist/lib/node-esm/index.mjs.map +4 -4
  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/_deprecated/hooks/useColumnSorting.d.ts +1 -1
  21. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +4 -3
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -2
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/CreateRefPanel.d.ts +3 -2
  26. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/RefPanel.d.ts +4 -3
  28. package/dist/types/src/components/Table/RefPanel.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/RowActionsMenu.d.ts +3 -2
  30. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/Table.d.ts +2 -1
  32. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  34. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -2
  35. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  36. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/testing.d.ts +55 -71
  38. package/dist/types/src/components/testing.d.ts.map +1 -1
  39. package/dist/types/src/index.d.ts +1 -0
  40. package/dist/types/src/index.d.ts.map +1 -1
  41. package/dist/types/src/model/index.d.ts +1 -0
  42. package/dist/types/src/model/index.d.ts.map +1 -1
  43. package/dist/types/src/model/modal-controller.d.ts +6 -2
  44. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  45. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  46. package/dist/types/src/model/table-model.d.ts +8 -12
  47. package/dist/types/src/model/table-model.d.ts.map +1 -1
  48. package/dist/types/src/model/table-presentation.d.ts +22 -0
  49. package/dist/types/src/model/table-presentation.d.ts.map +1 -0
  50. package/dist/types/src/model/table-presentation.test.d.ts +2 -0
  51. package/dist/types/src/model/table-presentation.test.d.ts.map +1 -0
  52. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  53. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  54. package/dist/types/src/types/table.d.ts +118 -154
  55. package/dist/types/src/types/table.d.ts.map +1 -1
  56. package/dist/types/src/util/index.d.ts +1 -0
  57. package/dist/types/src/util/index.d.ts.map +1 -1
  58. package/dist/types/src/util/table-buttons.d.ts +50 -20
  59. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  60. package/dist/types/src/util/table-controls.d.ts +32 -9
  61. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  62. package/dist/types/src/util/table.d.ts +2 -2
  63. package/dist/types/src/util/table.d.ts.map +1 -1
  64. package/dist/types/tsconfig.tsbuildinfo +1 -0
  65. package/package.json +29 -29
  66. package/src/components/Table/ColumnActionsMenu.tsx +8 -8
  67. package/src/components/Table/ColumnSettings.tsx +11 -11
  68. package/src/components/Table/CreateRefPanel.tsx +10 -10
  69. package/src/components/Table/RefPanel.tsx +9 -9
  70. package/src/components/Table/RowActionsMenu.tsx +6 -7
  71. package/src/components/Table/Table.stories.tsx +40 -23
  72. package/src/components/Table/Table.tsx +235 -148
  73. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +13 -12
  74. package/src/components/TableCellEditor/TableCellEditor.tsx +6 -4
  75. package/src/components/testing.ts +10 -8
  76. package/src/index.ts +2 -0
  77. package/src/model/index.ts +1 -0
  78. package/src/model/modal-controller.ts +15 -48
  79. package/src/model/selection-model.ts +12 -1
  80. package/src/model/table-model.test.ts +4 -71
  81. package/src/model/table-model.ts +59 -232
  82. package/src/model/table-presentation.test.ts +102 -0
  83. package/src/model/table-presentation.ts +214 -0
  84. package/src/playwright/TableManager.ts +5 -1
  85. package/src/playwright/smoke.spec.ts +64 -1
  86. package/src/types/table.ts +3 -3
  87. package/src/util/index.ts +1 -0
  88. package/src/util/table-buttons.ts +97 -48
  89. package/src/util/table-controls.ts +71 -7
  90. package/src/util/table.ts +21 -13
@@ -2,26 +2,90 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export const checkboxAttributes = {
5
+ // Core types.
6
+ export type TableControl = 'checkbox' | 'switch';
7
+
8
+ export type ControlData =
9
+ | { type: 'checkbox'; rowIndex: number; header?: boolean }
10
+ | { type: 'switch'; colIndex: number; rowIndex: number };
11
+
12
+ type CommonRenderProps = {
13
+ checked?: boolean;
14
+ disabled?: boolean;
15
+ };
16
+
17
+ export type RenderCheckboxProps = CommonRenderProps & Omit<Extract<ControlData, { type: 'checkbox' }>, 'type'>;
18
+ export type RenderSwitchProps = CommonRenderProps & Omit<Extract<ControlData, { type: 'switch' }>, 'type'>;
19
+
20
+ export const CONTROL_IDENTIFIERS = {
6
21
  checkbox: 'data-table-checkbox',
7
- header: 'data-table-header',
22
+ switch: 'data-table-switch',
8
23
  } as const;
9
24
 
10
- export type RenderCheckboxProps = { rowIndex: number; header?: boolean; checked?: boolean; disabled?: boolean };
25
+ const BASE_CLASSES = {
26
+ checkbox: 'absolute inset-block-[.375rem] inline-end-[.375rem] ch-checkbox',
27
+ switch: 'absolute inset-block-[.25rem] inline-end-[.25rem] ch-checkbox--switch',
28
+ } as const;
29
+
30
+ const renderAttributes = (data: Record<string, string>) => {
31
+ return Object.entries(data)
32
+ .map(([k, v]) => `${k}="${v}"`)
33
+ .join(' ');
34
+ };
35
+
36
+ const renderInput = (
37
+ baseClass: string,
38
+ attrs: Record<string, string>,
39
+ checked = false,
40
+ disabled = false,
41
+ preventToggle = false,
42
+ testId: string,
43
+ ) => {
44
+ return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? 'checked' : ''} ${preventToggle ? 'onclick="return false"' : ''} ${disabled ? 'disabled' : ''} data-testid="${testId}"/>`;
45
+ };
46
+
11
47
  export const renderCheckbox = ({
12
48
  rowIndex,
13
49
  header = false,
14
50
  checked = false,
15
51
  disabled = false,
16
52
  }: RenderCheckboxProps): string => {
17
- const baseClasses = 'absolute inset-block-[6px] inline-end-[6px] ch-checkbox' as const;
18
- const { attributes } = tableControls.checkbox;
19
- return `<input type="checkbox" class="${baseClasses}" ${attributes.checkbox}="${rowIndex}" ${header ? attributes.header : ''} ${checked ? 'checked' : ''} ${disabled ? 'disabled' : ''} data-testid="table-selection"/>`;
53
+ const attrs = {
54
+ [CONTROL_IDENTIFIERS.checkbox]: '',
55
+ 'data-row-index': rowIndex.toString(),
56
+ ...(header && { 'data-header': '' }),
57
+ };
58
+
59
+ return renderInput(BASE_CLASSES.checkbox, attrs, checked, disabled, true, 'table-selection');
60
+ };
61
+
62
+ export const renderSwitch = ({ colIndex, rowIndex, checked = false, disabled = false }: RenderSwitchProps): string => {
63
+ const attrs = {
64
+ [CONTROL_IDENTIFIERS.switch]: '',
65
+ 'data-row-index': rowIndex.toString(),
66
+ 'data-col-index': colIndex.toString(),
67
+ };
68
+
69
+ return renderInput(BASE_CLASSES.switch, attrs, checked, disabled, true, 'table-switch');
20
70
  };
21
71
 
22
72
  export const tableControls = {
23
73
  checkbox: {
24
- attributes: checkboxAttributes,
74
+ attr: CONTROL_IDENTIFIERS.checkbox,
25
75
  render: renderCheckbox,
76
+ getData: (el: HTMLElement): Extract<ControlData, { type: 'checkbox' }> => ({
77
+ type: 'checkbox',
78
+ rowIndex: Number(el.getAttribute('data-row-index')),
79
+ header: el.hasAttribute('data-header'),
80
+ }),
81
+ },
82
+ switch: {
83
+ attr: CONTROL_IDENTIFIERS.switch,
84
+ render: renderSwitch,
85
+ getData: (el: HTMLElement): Extract<ControlData, { type: 'switch' }> => ({
86
+ type: 'switch',
87
+ rowIndex: Number(el.getAttribute('data-row-index')),
88
+ colIndex: Number(el.getAttribute('data-col-index')),
89
+ }),
26
90
  },
27
91
  } as const;
package/src/util/table.ts CHANGED
@@ -8,14 +8,14 @@ import {
8
8
  FormatEnum,
9
9
  type JsonPath,
10
10
  type JsonProp,
11
- type MutableSchema,
11
+ type EchoSchema,
12
12
  S,
13
13
  TypedObject,
14
14
  TypeEnum,
15
15
  } from '@dxos/echo-schema';
16
16
  import { log } from '@dxos/log';
17
17
  import { PublicKey } from '@dxos/react-client';
18
- import { create, type Space } from '@dxos/react-client/echo';
18
+ import { create, makeRef, type Space } from '@dxos/react-client/echo';
19
19
  import { createFieldId, createView, ViewProjection } from '@dxos/schema';
20
20
 
21
21
  import { type TableType } from '../types';
@@ -28,8 +28,12 @@ type InitialiseTableProps = {
28
28
 
29
29
  // TODO(burdon): Pass in type.
30
30
  // TODO(burdon): User should determine typename.
31
- export const initializeTable = ({ space, table, initialRow = true }: InitialiseTableProps): MutableSchema => {
32
- log.info('initializeTable', { table });
31
+ export const initializeTable = async ({
32
+ space,
33
+ table,
34
+ initialRow = true,
35
+ }: InitialiseTableProps): Promise<EchoSchema> => {
36
+ log('initializeTable', { table });
33
37
 
34
38
  const ContactSchema = TypedObject({
35
39
  typename: `example.com/type/${PublicKey.random().truncate()}`,
@@ -38,24 +42,28 @@ export const initializeTable = ({ space, table, initialRow = true }: InitialiseT
38
42
  name: S.optional(S.String).annotations({
39
43
  [AST.TitleAnnotationId]: 'Name',
40
44
  }),
45
+ active: S.optional(S.Boolean),
41
46
  email: S.optional(Format.Email),
42
47
  salary: S.optional(Format.Currency()).annotations({
43
48
  [AST.TitleAnnotationId]: 'Salary',
44
49
  }), // TODO(burdon): Should default to prop name?
45
50
  });
46
51
 
47
- const contactSchema = space.db.schemaRegistry.addSchema(ContactSchema);
48
- table.view = createView({
49
- name: 'Test',
50
- typename: contactSchema.typename,
51
- jsonSchema: contactSchema.jsonSchema,
52
- fields: ['name', 'email', 'salary'],
53
- });
52
+ const [contactSchema] = await space.db.schemaRegistry.register([ContactSchema]);
53
+
54
+ table.view = makeRef(
55
+ createView({
56
+ name: 'Test',
57
+ typename: contactSchema.typename,
58
+ jsonSchema: contactSchema.jsonSchema,
59
+ fields: ['name', 'active', 'email', 'salary'],
60
+ }),
61
+ );
54
62
 
55
- const projection = new ViewProjection(contactSchema, table.view!);
63
+ const projection = new ViewProjection(contactSchema, table.view.target!);
56
64
  projection.setFieldProjection({
57
65
  field: {
58
- id: table.view.fields[2].id,
66
+ id: table.view.target!.fields.find((f) => f.path === 'salary')!.id,
59
67
  path: 'salary' as JsonPath,
60
68
  size: 150,
61
69
  },