@dxos/react-ui-table 0.7.4 → 0.7.5-main.937ce75
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.
- package/dist/lib/browser/{chunk-IYCSJDMB.mjs → chunk-AT7O4RAD.mjs} +4 -4
- package/dist/lib/browser/{chunk-IYCSJDMB.mjs.map → chunk-AT7O4RAD.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +1442 -1219
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{chunk-MHBMVCFZ.cjs → chunk-YSBXNBDJ.cjs} +6 -6
- package/dist/lib/node/{chunk-MHBMVCFZ.cjs.map → chunk-YSBXNBDJ.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +1351 -1111
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +3 -3
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{chunk-BMWGPXPL.mjs → chunk-6OH2NHUX.mjs} +4 -4
- package/dist/lib/node-esm/{chunk-BMWGPXPL.mjs.map → chunk-6OH2NHUX.mjs.map} +2 -2
- package/dist/lib/node-esm/index.mjs +1442 -1219
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +4 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +3 -2
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RefPanel.d.ts +4 -3
- package/dist/types/src/components/Table/RefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +3 -2
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +2 -1
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +55 -71
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +1 -0
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +6 -2
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +14 -27
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +22 -0
- package/dist/types/src/model/table-presentation.d.ts.map +1 -0
- package/dist/types/src/model/table-presentation.test.d.ts +2 -0
- package/dist/types/src/model/table-presentation.test.d.ts.map +1 -0
- package/dist/types/src/model/table-sorting.d.ts +48 -0
- package/dist/types/src/model/table-sorting.d.ts.map +1 -0
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +118 -154
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/table-buttons.d.ts +50 -20
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +32 -9
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts +2 -2
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -29
- package/src/components/Table/ColumnActionsMenu.tsx +8 -8
- package/src/components/Table/ColumnSettings.tsx +11 -11
- package/src/components/Table/CreateRefPanel.tsx +13 -14
- package/src/components/Table/RefPanel.tsx +9 -9
- package/src/components/Table/RowActionsMenu.tsx +6 -7
- package/src/components/Table/Table.stories.tsx +40 -23
- package/src/components/Table/Table.tsx +235 -148
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +13 -12
- package/src/components/TableCellEditor/TableCellEditor.tsx +6 -4
- package/src/components/testing.ts +10 -8
- package/src/index.ts +2 -0
- package/src/model/index.ts +1 -0
- package/src/model/modal-controller.ts +15 -48
- package/src/model/selection-model.ts +12 -1
- package/src/model/table-model.test.ts +4 -71
- package/src/model/table-model.ts +61 -292
- package/src/model/table-presentation.test.ts +102 -0
- package/src/model/table-presentation.ts +217 -0
- package/src/model/table-sorting.ts +131 -0
- package/src/playwright/TableManager.ts +5 -1
- package/src/playwright/smoke.spec.ts +79 -1
- package/src/types/table.ts +3 -3
- package/src/util/index.ts +1 -0
- package/src/util/table-buttons.ts +97 -48
- package/src/util/table-controls.ts +71 -7
- package/src/util/table.ts +21 -13
|
@@ -2,26 +2,90 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
22
|
+
switch: 'data-table-switch',
|
|
8
23
|
} as const;
|
|
9
24
|
|
|
10
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
|
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 = ({
|
|
32
|
-
|
|
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.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
66
|
+
id: table.view.target!.fields.find((f) => f.path === 'salary')!.id,
|
|
59
67
|
path: 'salary' as JsonPath,
|
|
60
68
|
size: 150,
|
|
61
69
|
},
|