@dxos/plugin-kanban 0.8.4-main.ae835ea → 0.8.4-main.bcb3aa67d6
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/blueprints/index.mjs +27 -0
- package/dist/lib/browser/blueprints/index.mjs.map +7 -0
- package/dist/lib/browser/chunk-A3PBV3S5.mjs +105 -0
- package/dist/lib/browser/chunk-A3PBV3S5.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/delete-card-VPNVIWOA.mjs +32 -0
- package/dist/lib/browser/delete-card-VPNVIWOA.mjs.map +7 -0
- package/dist/lib/browser/delete-card-field-4HHF2GYX.mjs +50 -0
- package/dist/lib/browser/delete-card-field-4HHF2GYX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +101 -85
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operations/index.mjs +13 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/restore-card-4GG2RYKR.mjs +29 -0
- package/dist/lib/browser/restore-card-4GG2RYKR.mjs.map +7 -0
- package/dist/lib/browser/restore-card-field-3T26ACYX.mjs +48 -0
- package/dist/lib/browser/restore-card-field-3T26ACYX.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +95 -6
- package/dist/lib/browser/types/index.mjs.map +4 -4
- package/dist/lib/node-esm/blueprints/index.mjs +28 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6LELYA2G.mjs +106 -0
- package/dist/lib/node-esm/chunk-6LELYA2G.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/delete-card-5PW5OMFN.mjs +33 -0
- package/dist/lib/node-esm/delete-card-5PW5OMFN.mjs.map +7 -0
- package/dist/lib/node-esm/delete-card-field-KPJU2AQ3.mjs +51 -0
- package/dist/lib/node-esm/delete-card-field-KPJU2AQ3.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +101 -85
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/operations/index.mjs +14 -0
- package/dist/lib/node-esm/operations/index.mjs.map +7 -0
- package/dist/lib/node-esm/restore-card-X2TKMU5A.mjs +30 -0
- package/dist/lib/node-esm/restore-card-X2TKMU5A.mjs.map +7 -0
- package/dist/lib/node-esm/restore-card-field-IUTL4RTR.mjs +49 -0
- package/dist/lib/node-esm/restore-card-field-IUTL4RTR.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +95 -6
- package/dist/lib/node-esm/types/index.mjs.map +4 -4
- package/dist/types/src/KanbanPlugin.d.ts +2 -1
- package/dist/types/src/KanbanPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +2 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/kanban-blueprint.d.ts +4 -0
- package/dist/types/src/blueprints/kanban-blueprint.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts +3 -2
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -4
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +6 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/undo-mappings.d.ts +5 -0
- package/dist/types/src/capabilities/undo-mappings.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.d.ts +65 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.stories.d.ts +72 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.stories.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanCard.d.ts +10 -0
- package/dist/types/src/components/KanbanBoard/KanbanCard.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanColumn.d.ts +9 -0
- package/dist/types/src/components/KanbanBoard/KanbanColumn.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/index.d.ts +2 -0
- package/dist/types/src/components/KanbanBoard/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.d.ts +6 -0
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.stories.d.ts +79 -0
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.stories.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanContainer/index.d.ts +3 -0
- package/dist/types/src/containers/KanbanContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanViewEditor/KanbanViewEditor.d.ts +6 -0
- package/dist/types/src/containers/KanbanViewEditor/KanbanViewEditor.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanViewEditor/index.d.ts +3 -0
- package/dist/types/src/containers/KanbanViewEditor/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +4 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +6 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useEchoChangeCallback.d.ts +13 -0
- package/dist/types/src/hooks/useEchoChangeCallback.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanBoardModel.d.ts +16 -0
- package/dist/types/src/hooks/useKanbanBoardModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanBoardModel.test.d.ts +2 -0
- package/dist/types/src/hooks/useKanbanBoardModel.test.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanColumnEventHandler.d.ts +22 -0
- package/dist/types/src/hooks/useKanbanColumnEventHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanItemEventHandler.d.ts +19 -0
- package/dist/types/src/hooks/useKanbanItemEventHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts +15 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/definitions.d.ts +52 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/delete-card-field.d.ts +5 -0
- package/dist/types/src/operations/delete-card-field.d.ts.map +1 -0
- package/dist/types/src/operations/delete-card.d.ts +5 -0
- package/dist/types/src/operations/delete-card.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/restore-card-field.d.ts +5 -0
- package/dist/types/src/operations/restore-card-field.d.ts.map +1 -0
- package/dist/types/src/operations/restore-card.d.ts +5 -0
- package/dist/types/src/operations/restore-card.d.ts.map +1 -0
- package/dist/types/src/playwright/board-manager.d.ts +5 -0
- package/dist/types/src/playwright/board-manager.d.ts.map +1 -0
- package/dist/types/src/playwright/playwright.config.d.ts +3 -0
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
- package/dist/types/src/playwright/smoke.spec.d.ts +2 -0
- package/dist/types/src/playwright/smoke.spec.d.ts.map +1 -0
- package/dist/types/src/testing/KanbanCardTileSimple.d.ts +7 -0
- package/dist/types/src/testing/KanbanCardTileSimple.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +50 -22
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Kanban.d.ts +37 -0
- package/dist/types/src/types/Kanban.d.ts.map +1 -0
- package/dist/types/src/types/constants.d.ts +6 -0
- package/dist/types/src/types/constants.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +3 -51
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +28 -0
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/util/arrangement.d.ts +68 -0
- package/dist/types/src/util/arrangement.d.ts.map +1 -0
- package/dist/types/src/util/arrangement.test.d.ts +2 -0
- package/dist/types/src/util/arrangement.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +84 -46
- package/src/KanbanPlugin.tsx +49 -56
- package/src/blueprints/index.ts +5 -0
- package/src/blueprints/kanban-blueprint.ts +28 -0
- package/src/capabilities/artifact-definition.ts +115 -112
- package/src/capabilities/blueprint-definition.ts +11 -24
- package/src/capabilities/index.ts +9 -4
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/react-surface.tsx +70 -68
- package/src/capabilities/undo-mappings.ts +34 -0
- package/src/components/KanbanBoard/KanbanBoard.stories.tsx +142 -0
- package/src/components/KanbanBoard/KanbanBoard.tsx +193 -0
- package/src/components/KanbanBoard/KanbanCard.tsx +86 -0
- package/src/components/KanbanBoard/KanbanColumn.tsx +69 -0
- package/src/components/KanbanBoard/index.ts +5 -0
- package/src/components/index.ts +1 -2
- package/src/containers/KanbanContainer/KanbanContainer.stories.tsx +269 -0
- package/src/containers/KanbanContainer/KanbanContainer.tsx +96 -0
- package/src/containers/KanbanContainer/index.ts +7 -0
- package/src/containers/KanbanViewEditor/KanbanViewEditor.tsx +63 -0
- package/src/containers/KanbanViewEditor/index.ts +7 -0
- package/src/containers/index.ts +8 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useEchoChangeCallback.ts +30 -0
- package/src/hooks/useKanbanBoardModel.test.ts +235 -0
- package/src/hooks/useKanbanBoardModel.ts +143 -0
- package/src/hooks/useKanbanColumnEventHandler.ts +106 -0
- package/src/hooks/useKanbanItemEventHandler.ts +133 -0
- package/src/hooks/useProjectionModel.ts +58 -0
- package/src/meta.ts +3 -3
- package/src/operations/definitions.ts +63 -0
- package/src/operations/delete-card-field.ts +47 -0
- package/src/operations/delete-card.ts +23 -0
- package/src/operations/index.ts +12 -0
- package/src/operations/restore-card-field.ts +41 -0
- package/src/operations/restore-card.ts +21 -0
- package/src/playwright/board-manager.ts +13 -0
- package/src/playwright/playwright.config.ts +19 -0
- package/src/playwright/smoke.spec.ts +107 -0
- package/src/testing/KanbanCardTileSimple.tsx +82 -0
- package/src/testing/index.ts +5 -0
- package/src/translations.ts +28 -20
- package/src/types/Kanban.ts +71 -0
- package/src/types/constants.ts +9 -0
- package/src/types/index.ts +2 -0
- package/src/types/schema.ts +14 -44
- package/src/types/types.ts +35 -0
- package/src/util/arrangement.test.ts +208 -0
- package/src/util/arrangement.ts +167 -0
- package/src/util/index.ts +5 -0
- package/dist/lib/browser/blueprint-definition-UYVX622Q.mjs +0 -28
- package/dist/lib/browser/blueprint-definition-UYVX622Q.mjs.map +0 -7
- package/dist/lib/browser/chunk-3UDST345.mjs +0 -85
- package/dist/lib/browser/chunk-3UDST345.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-VVBNS2TO.mjs +0 -111
- package/dist/lib/browser/intent-resolver-VVBNS2TO.mjs.map +0 -7
- package/dist/lib/browser/react-surface-FNXJ6VJX.mjs +0 -255
- package/dist/lib/browser/react-surface-FNXJ6VJX.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-42P47FUY.mjs +0 -30
- package/dist/lib/node-esm/blueprint-definition-42P47FUY.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JBOARUAT.mjs +0 -87
- package/dist/lib/node-esm/chunk-JBOARUAT.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-ACN7UALP.mjs +0 -112
- package/dist/lib/node-esm/intent-resolver-ACN7UALP.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-ZHYHCV5N.mjs +0 -256
- package/dist/lib/node-esm/react-surface-ZHYHCV5N.mjs.map +0 -7
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/KanbanContainer.d.ts +0 -7
- package/dist/types/src/components/KanbanContainer.d.ts.map +0 -1
- package/dist/types/src/components/KanbanContainer.stories.d.ts +0 -41
- package/dist/types/src/components/KanbanContainer.stories.d.ts.map +0 -1
- package/dist/types/src/components/KanbanViewEditor.d.ts +0 -8
- package/dist/types/src/components/KanbanViewEditor.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -71
- package/src/components/KanbanContainer.stories.tsx +0 -193
- package/src/components/KanbanContainer.tsx +0 -95
- package/src/components/KanbanViewEditor.tsx +0 -64
|
@@ -2,83 +2,85 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
5
6
|
import type * as Schema from 'effect/Schema';
|
|
6
7
|
import React, { useMemo } from 'react';
|
|
7
8
|
|
|
8
|
-
import { Capabilities,
|
|
9
|
-
import {
|
|
9
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
10
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
11
|
+
import { Database, JsonSchema, Obj } from '@dxos/echo';
|
|
12
|
+
import { type Collection } from '@dxos/echo';
|
|
10
13
|
import { findAnnotation } from '@dxos/effect';
|
|
11
|
-
import {
|
|
12
|
-
import { type Space, getSpace, isSpace } from '@dxos/react-client/echo';
|
|
13
|
-
import { type InputProps, SelectInput, useFormValues } from '@dxos/react-ui-form';
|
|
14
|
-
import { Kanban } from '@dxos/react-ui-kanban/types';
|
|
15
|
-
import { DataType } from '@dxos/schema';
|
|
14
|
+
import { type FormFieldComponentProps, SelectField, useFormValues } from '@dxos/react-ui-form';
|
|
16
15
|
|
|
17
|
-
import { KanbanContainer, KanbanViewEditor } from '
|
|
18
|
-
import { meta } from '
|
|
19
|
-
import { PivotColumnAnnotationId } from '
|
|
16
|
+
import { KanbanContainer, KanbanViewEditor } from '#containers';
|
|
17
|
+
import { meta } from '#meta';
|
|
18
|
+
import { Kanban, PivotColumnAnnotationId } from '#types';
|
|
20
19
|
|
|
21
|
-
export default () =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
data
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const schemaWhitelists = useCapabilities(ClientCapabilities.SchemaWhiteList);
|
|
56
|
-
const staticSchema = schemaWhitelists.flat().find((schema) => Type.getTypename(schema) === typename);
|
|
57
|
-
const [selectedSchema] = space?.db.schemaRegistry.query({ typename }).runSync();
|
|
58
|
-
|
|
59
|
-
const singleSelectColumns = useMemo(() => {
|
|
60
|
-
const properties = staticSchema
|
|
61
|
-
? Type.toJsonSchema(staticSchema).properties
|
|
62
|
-
: selectedSchema?.jsonSchema?.properties;
|
|
63
|
-
if (!properties) {
|
|
64
|
-
return [];
|
|
20
|
+
export default Capability.makeModule(() =>
|
|
21
|
+
Effect.succeed(
|
|
22
|
+
Capability.contributes(Capabilities.ReactSurface, [
|
|
23
|
+
Surface.create({
|
|
24
|
+
id: meta.id,
|
|
25
|
+
role: ['article', 'section'],
|
|
26
|
+
filter: (data): data is { subject: Kanban.Kanban } => Obj.instanceOf(Kanban.Kanban, data.subject),
|
|
27
|
+
component: ({ data, role }) => <KanbanContainer role={role} subject={data.subject} />,
|
|
28
|
+
}),
|
|
29
|
+
Surface.create({
|
|
30
|
+
id: `${meta.id}.object-settings`,
|
|
31
|
+
role: 'object-settings',
|
|
32
|
+
position: 'hoist',
|
|
33
|
+
filter: (data): data is { subject: Kanban.Kanban } => Obj.instanceOf(Kanban.Kanban, data.subject),
|
|
34
|
+
component: ({ data }) => <KanbanViewEditor subject={data.subject} />,
|
|
35
|
+
}),
|
|
36
|
+
Surface.create({
|
|
37
|
+
id: `${meta.id}.create-initial-schema-form-[pivot-column]`,
|
|
38
|
+
role: 'form-input',
|
|
39
|
+
filter: (
|
|
40
|
+
data,
|
|
41
|
+
): data is {
|
|
42
|
+
prop: string;
|
|
43
|
+
schema: Schema.Schema<any>;
|
|
44
|
+
target: Database.Database | Collection.Collection | undefined;
|
|
45
|
+
} => {
|
|
46
|
+
const annotation = findAnnotation<boolean>((data.schema as Schema.Schema.All).ast, PivotColumnAnnotationId);
|
|
47
|
+
return !!annotation;
|
|
48
|
+
},
|
|
49
|
+
component: ({ data: { target }, ...inputProps }) => {
|
|
50
|
+
const props = inputProps as any as FormFieldComponentProps;
|
|
51
|
+
const db = Database.isDatabase(target) ? target : target && Obj.getDatabase(target);
|
|
52
|
+
if (!db) {
|
|
53
|
+
return null;
|
|
65
54
|
}
|
|
66
55
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
const { typename } = useFormValues('KanbanForm');
|
|
57
|
+
const [selectedSchema] = useMemo(
|
|
58
|
+
() => db.schemaRegistry.query({ location: ['database', 'runtime'], typename }).runSync(),
|
|
59
|
+
[db, typename],
|
|
60
|
+
);
|
|
61
|
+
const singleSelectColumns = useMemo(() => {
|
|
62
|
+
const properties = JsonSchema.toJsonSchema(selectedSchema).properties;
|
|
63
|
+
if (!properties) {
|
|
64
|
+
return [];
|
|
70
65
|
}
|
|
71
|
-
return acc;
|
|
72
|
-
}, []);
|
|
73
66
|
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
const columns = Object.entries(properties).reduce<string[]>((acc, [key, value]) => {
|
|
68
|
+
if (typeof value === 'object' && value?.format === 'single-select') {
|
|
69
|
+
acc.push(key);
|
|
70
|
+
}
|
|
71
|
+
return acc;
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
74
|
+
return columns;
|
|
75
|
+
}, [selectedSchema]);
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if (!typename) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
return <SelectField {...props} options={singleSelectColumns.map((column) => ({ value: column }))} />;
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
]),
|
|
85
|
+
),
|
|
86
|
+
);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
|
|
5
|
+
import { Capabilities, Capability, UndoMapping } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { meta } from '#meta';
|
|
8
|
+
import { KanbanOperation } from '#operations';
|
|
9
|
+
|
|
10
|
+
export default Capability.makeModule(() =>
|
|
11
|
+
Effect.succeed(
|
|
12
|
+
Capability.contributes(Capabilities.UndoMapping, [
|
|
13
|
+
UndoMapping.make({
|
|
14
|
+
operation: KanbanOperation.DeleteCardField,
|
|
15
|
+
inverse: KanbanOperation.RestoreCardField,
|
|
16
|
+
deriveContext: (input, output) => ({
|
|
17
|
+
view: input.view,
|
|
18
|
+
field: output.field,
|
|
19
|
+
props: output.props,
|
|
20
|
+
index: output.index,
|
|
21
|
+
}),
|
|
22
|
+
message: ['card-field-deleted.label', { ns: meta.id }],
|
|
23
|
+
}),
|
|
24
|
+
UndoMapping.make({
|
|
25
|
+
operation: KanbanOperation.DeleteCard,
|
|
26
|
+
inverse: KanbanOperation.RestoreCard,
|
|
27
|
+
deriveContext: (_input, output) => ({
|
|
28
|
+
card: output.card,
|
|
29
|
+
}),
|
|
30
|
+
message: ['card-deleted.label', { ns: meta.id }],
|
|
31
|
+
}),
|
|
32
|
+
]),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Filter, JsonSchema, Obj, Query } from '@dxos/echo';
|
|
10
|
+
import { type View } from '@dxos/echo';
|
|
11
|
+
import { faker } from '@dxos/random';
|
|
12
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
|
+
import { withMosaic } from '@dxos/react-ui-mosaic/testing';
|
|
14
|
+
import { ProjectionModel, ViewModel, createEchoChangeCallback } from '@dxos/schema';
|
|
15
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
|
+
import { Organization } from '@dxos/types';
|
|
17
|
+
|
|
18
|
+
import { createEchoChangeCallback as createKanbanChangeCallback } from '#hooks';
|
|
19
|
+
import { KanbanCardTileSimple } from '#testing';
|
|
20
|
+
import { translations } from '../../translations';
|
|
21
|
+
import { Kanban } from '#types';
|
|
22
|
+
|
|
23
|
+
import { KanbanBoard } from './KanbanBoard';
|
|
24
|
+
|
|
25
|
+
faker.seed(1);
|
|
26
|
+
|
|
27
|
+
const createOrg = () => ({
|
|
28
|
+
name: faker.commerce.productName(),
|
|
29
|
+
description: faker.lorem.sentence(),
|
|
30
|
+
image: faker.image.url(),
|
|
31
|
+
website: faker.internet.url(),
|
|
32
|
+
status: faker.helpers.arrayElement(Organization.StatusOptions).id as Organization.Organization['status'],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* In-memory Kanban board: View + ProjectionModel + Kanban + items, no plugin manager or Space.
|
|
37
|
+
* Similar to react-ui-kanban Kanban.stories.tsx.
|
|
38
|
+
*/
|
|
39
|
+
const DefaultStory = () => {
|
|
40
|
+
const registry = useContext(RegistryContext);
|
|
41
|
+
const items = useMemo(() => Atom.make<Obj.Unknown[]>([]), []);
|
|
42
|
+
const [state, setState] = useState<{
|
|
43
|
+
view: View.View;
|
|
44
|
+
kanban: Kanban.Kanban;
|
|
45
|
+
projection: ProjectionModel;
|
|
46
|
+
change: ReturnType<typeof createKanbanChangeCallback>;
|
|
47
|
+
}>();
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const view = ViewModel.make({
|
|
51
|
+
query: Query.select(Filter.typename(Organization.Organization.typename)),
|
|
52
|
+
jsonSchema: JsonSchema.toJsonSchema(Organization.Organization),
|
|
53
|
+
pivotFieldName: 'status',
|
|
54
|
+
});
|
|
55
|
+
const kanban = Kanban.make({ view });
|
|
56
|
+
const change = createKanbanChangeCallback(kanban);
|
|
57
|
+
const projection = new ProjectionModel({
|
|
58
|
+
registry,
|
|
59
|
+
view,
|
|
60
|
+
baseSchema: JsonSchema.toJsonSchema(Organization.Organization),
|
|
61
|
+
change: createEchoChangeCallback(view),
|
|
62
|
+
});
|
|
63
|
+
projection.normalizeView();
|
|
64
|
+
|
|
65
|
+
const statuses = Organization.StatusOptions.map((o) => o.id);
|
|
66
|
+
const initialItems = Array.from({ length: 12 }, () =>
|
|
67
|
+
Obj.make(Organization.Organization, {
|
|
68
|
+
...createOrg(),
|
|
69
|
+
status: faker.helpers.arrayElement(statuses) as Organization.Organization['status'],
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
setState({ view, kanban, projection, change });
|
|
74
|
+
registry.set(items, initialItems);
|
|
75
|
+
}, [registry, items]);
|
|
76
|
+
|
|
77
|
+
const columnFieldPath =
|
|
78
|
+
state?.projection.tryGetFieldProjection(state.projection.getFieldId('status') ?? '')?.props.property ?? 'status';
|
|
79
|
+
|
|
80
|
+
const handleCardAdd = useCallback(
|
|
81
|
+
(columnValue: string | undefined) => {
|
|
82
|
+
if (!state || !columnFieldPath || !registry) return undefined;
|
|
83
|
+
const card = Obj.make(Organization.Organization, {
|
|
84
|
+
...createOrg(),
|
|
85
|
+
...(columnFieldPath ? { [columnFieldPath]: columnValue } : {}),
|
|
86
|
+
});
|
|
87
|
+
const current = registry.get(items) ?? [];
|
|
88
|
+
registry.set(items, [...current, card]);
|
|
89
|
+
return card.id;
|
|
90
|
+
},
|
|
91
|
+
[state, columnFieldPath, registry, items],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const handleCardRemove = useCallback(
|
|
95
|
+
(card: Obj.Unknown) => {
|
|
96
|
+
if (!registry) return;
|
|
97
|
+
const current = registry.get(items) ?? [];
|
|
98
|
+
registry.set(
|
|
99
|
+
items,
|
|
100
|
+
current.filter((i) => i.id !== card.id),
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
[registry, items],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (!state) {
|
|
107
|
+
return <></>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<KanbanBoard.Root
|
|
112
|
+
kanban={state.kanban}
|
|
113
|
+
projection={state.projection}
|
|
114
|
+
items={items}
|
|
115
|
+
itemTile={KanbanCardTileSimple}
|
|
116
|
+
change={state.change}
|
|
117
|
+
onCardAdd={handleCardAdd}
|
|
118
|
+
onCardRemove={handleCardRemove}
|
|
119
|
+
>
|
|
120
|
+
<KanbanBoard.Content />
|
|
121
|
+
</KanbanBoard.Root>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const meta = {
|
|
126
|
+
title: 'plugins/plugin-kanban/components/KanbanBoard',
|
|
127
|
+
component: DefaultStory,
|
|
128
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withMosaic(), withRegistry],
|
|
129
|
+
parameters: {
|
|
130
|
+
layout: 'fullscreen',
|
|
131
|
+
translations,
|
|
132
|
+
},
|
|
133
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
134
|
+
|
|
135
|
+
export default meta;
|
|
136
|
+
|
|
137
|
+
type Story = StoryObj<typeof meta>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* In-memory board with Echo-shaped objects. No plugin manager, client, or Space.
|
|
141
|
+
*/
|
|
142
|
+
export const Default: Story = {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Atom, RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { createContext } from '@radix-ui/react-context';
|
|
7
|
+
import React, {
|
|
8
|
+
type ComponentPropsWithoutRef,
|
|
9
|
+
type ComponentType,
|
|
10
|
+
type PropsWithChildren,
|
|
11
|
+
useCallback,
|
|
12
|
+
useContext,
|
|
13
|
+
useMemo,
|
|
14
|
+
} from 'react';
|
|
15
|
+
|
|
16
|
+
import { Obj } from '@dxos/echo';
|
|
17
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
18
|
+
import { Board, useBoard } from '@dxos/react-ui-mosaic';
|
|
19
|
+
import type { ProjectionModel } from '@dxos/schema';
|
|
20
|
+
import { composable, composableProps } from '@dxos/ui-theme';
|
|
21
|
+
|
|
22
|
+
import { useKanbanBoardModel, useKanbanColumnEventHandler } from '#hooks';
|
|
23
|
+
import { meta } from '#meta';
|
|
24
|
+
import { type Kanban, type KanbanChangeCallback, UNCATEGORIZED_ATTRIBUTES, UNCATEGORIZED_VALUE } from '#types';
|
|
25
|
+
|
|
26
|
+
import { KanbanCard, type KanbanCardProps } from './KanbanCard';
|
|
27
|
+
import { KanbanColumn, type KanbanColumnProps } from './KanbanColumn';
|
|
28
|
+
|
|
29
|
+
// TODO(burdon): Rename Kanban.
|
|
30
|
+
|
|
31
|
+
//
|
|
32
|
+
// Context
|
|
33
|
+
//
|
|
34
|
+
|
|
35
|
+
const KANBAN_BOARD_NAME = 'KanbanBoard.Context';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Context value for the Kanban board.
|
|
39
|
+
* Items are Echo objects (Obj.Unknown).
|
|
40
|
+
*/
|
|
41
|
+
type KanbanBoardContextValue = {
|
|
42
|
+
kanbanId: string;
|
|
43
|
+
projection: ProjectionModel | undefined;
|
|
44
|
+
columnFieldPath: string | undefined;
|
|
45
|
+
change: KanbanChangeCallback<Obj.Unknown>;
|
|
46
|
+
pivotFieldId: string | undefined;
|
|
47
|
+
getPivotAttributes: (columnValue: string) => { title: string; color: string };
|
|
48
|
+
itemTile?: ComponentType<KanbanCardProps>; // TODO(burdon): Prop.
|
|
49
|
+
onCardAdd?: (columnValue: string | undefined) => string | undefined;
|
|
50
|
+
onCardRemove?: (card: Obj.Unknown) => void;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const [KanbanBoardContext, useKanbanBoard] = createContext<KanbanBoardContextValue>(KANBAN_BOARD_NAME, {
|
|
54
|
+
kanbanId: 'never',
|
|
55
|
+
projection: undefined,
|
|
56
|
+
columnFieldPath: undefined,
|
|
57
|
+
change: { kanban: () => {}, setItemField: () => {} },
|
|
58
|
+
pivotFieldId: undefined,
|
|
59
|
+
getPivotAttributes: (id: string) =>
|
|
60
|
+
id === UNCATEGORIZED_VALUE ? UNCATEGORIZED_ATTRIBUTES : { title: id, color: 'neutral' },
|
|
61
|
+
itemTile: (() => null) as ComponentType<KanbanCardProps>,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
//
|
|
65
|
+
// Root
|
|
66
|
+
//
|
|
67
|
+
|
|
68
|
+
const KANBAN_BOARD_ROOT = 'KanbanBoard.Root';
|
|
69
|
+
|
|
70
|
+
type KanbanBoardRootProps = PropsWithChildren<
|
|
71
|
+
{
|
|
72
|
+
kanban: Kanban.Kanban;
|
|
73
|
+
/** Required when providing context; Root derives columnFieldPath, pivotFieldId, getPivotAttributes from kanban + projection. */
|
|
74
|
+
projection: ProjectionModel;
|
|
75
|
+
/** Atom of items (e.g. from AtomQuery for DB, or Atom.make([]) for in-memory). */
|
|
76
|
+
items: Atom.Atom<Obj.Unknown[]>;
|
|
77
|
+
onCardAdd?: (columnValue: string | undefined) => string | undefined;
|
|
78
|
+
onCardRemove?: (card: Obj.Unknown) => void;
|
|
79
|
+
} & Pick<KanbanBoardContextValue, 'change' | 'itemTile'> &
|
|
80
|
+
ComponentPropsWithoutRef<'div'>
|
|
81
|
+
>;
|
|
82
|
+
|
|
83
|
+
export const KanbanBoardRoot = ({
|
|
84
|
+
children,
|
|
85
|
+
kanban,
|
|
86
|
+
projection,
|
|
87
|
+
items,
|
|
88
|
+
change,
|
|
89
|
+
itemTile = KanbanCard,
|
|
90
|
+
onCardAdd,
|
|
91
|
+
onCardRemove,
|
|
92
|
+
}: KanbanBoardRootProps) => {
|
|
93
|
+
const registry = useContext(RegistryContext);
|
|
94
|
+
const { t } = useTranslation(meta.id);
|
|
95
|
+
const model = useKanbanBoardModel(kanban, projection, items, registry);
|
|
96
|
+
const columns = model?.getColumns?.() ?? [];
|
|
97
|
+
const view = kanban?.view?.target;
|
|
98
|
+
const pivotFieldId = view?.projection?.pivotFieldId;
|
|
99
|
+
const columnFieldPath = useMemo(() => {
|
|
100
|
+
if (pivotFieldId === undefined || !projection) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return projection.tryGetFieldProjection(pivotFieldId)?.props.property;
|
|
105
|
+
}, [projection, pivotFieldId]);
|
|
106
|
+
|
|
107
|
+
const getPivotAttributes = useCallback<KanbanBoardContextValue['getPivotAttributes']>(
|
|
108
|
+
(columnValue) => {
|
|
109
|
+
if (columnValue === UNCATEGORIZED_VALUE) {
|
|
110
|
+
return UNCATEGORIZED_ATTRIBUTES;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const options = projection?.tryGetFieldProjection(pivotFieldId ?? '')?.props.options ?? [];
|
|
114
|
+
const option = options.find((option) => option.id === columnValue);
|
|
115
|
+
return option ?? ({ title: columnValue, color: 'neutral' } as const);
|
|
116
|
+
},
|
|
117
|
+
[projection, pivotFieldId],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (columns.length === 0) {
|
|
121
|
+
return (
|
|
122
|
+
<div role='none' className='flex flex-1 items-center justify-center p-8 text-center text-description'>
|
|
123
|
+
{t('select-pivot.placeholder')}
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<KanbanBoardContext
|
|
130
|
+
kanbanId={Obj.getDXN(kanban).toString()}
|
|
131
|
+
projection={projection}
|
|
132
|
+
columnFieldPath={columnFieldPath}
|
|
133
|
+
pivotFieldId={pivotFieldId}
|
|
134
|
+
getPivotAttributes={getPivotAttributes}
|
|
135
|
+
itemTile={itemTile}
|
|
136
|
+
change={change}
|
|
137
|
+
onCardAdd={onCardAdd}
|
|
138
|
+
onCardRemove={onCardRemove}
|
|
139
|
+
>
|
|
140
|
+
<Board.Root model={model}>{children}</Board.Root>
|
|
141
|
+
</KanbanBoardContext>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
KanbanBoardRoot.displayName = KANBAN_BOARD_ROOT;
|
|
146
|
+
|
|
147
|
+
//
|
|
148
|
+
// KanbanBoardContent
|
|
149
|
+
//
|
|
150
|
+
|
|
151
|
+
const KANBAN_BOARD_CONTENT = 'KanbanBoard.Content';
|
|
152
|
+
|
|
153
|
+
type KanbanBoardContentProps = {};
|
|
154
|
+
|
|
155
|
+
export const KanbanBoardContent = composable<HTMLDivElement, KanbanBoardContentProps>((props, forwardedRef) => {
|
|
156
|
+
const { model } = useBoard(KANBAN_BOARD_CONTENT);
|
|
157
|
+
const { kanbanId, projection, pivotFieldId, change } = useKanbanBoard(KANBAN_BOARD_CONTENT);
|
|
158
|
+
|
|
159
|
+
const columnEventHandler = useKanbanColumnEventHandler({
|
|
160
|
+
id: `${kanbanId}-columns`,
|
|
161
|
+
model,
|
|
162
|
+
projection: projection ?? undefined,
|
|
163
|
+
pivotFieldId: pivotFieldId ?? undefined,
|
|
164
|
+
change,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<Board.Content
|
|
169
|
+
{...composableProps(props)}
|
|
170
|
+
ref={forwardedRef}
|
|
171
|
+
id={kanbanId}
|
|
172
|
+
eventHandler={columnEventHandler}
|
|
173
|
+
Tile={KanbanColumn}
|
|
174
|
+
/>
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
KanbanBoardContent.displayName = KANBAN_BOARD_CONTENT;
|
|
179
|
+
|
|
180
|
+
//
|
|
181
|
+
// KanbanBoard
|
|
182
|
+
//
|
|
183
|
+
|
|
184
|
+
export const KanbanBoard = {
|
|
185
|
+
Root: KanbanBoardRoot,
|
|
186
|
+
Content: KanbanBoardContent,
|
|
187
|
+
Column: KanbanColumn,
|
|
188
|
+
Card: KanbanCard,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export { useKanbanBoard };
|
|
192
|
+
|
|
193
|
+
export type { KanbanBoardRootProps as KanbanBoardProps, KanbanCardProps, KanbanColumnProps };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { forwardRef, useCallback, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
8
|
+
import { useObjectMenuItems } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { Card, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
11
|
+
import { Menu, createMenuAction } from '@dxos/react-ui-menu';
|
|
12
|
+
import { Focus, Mosaic, type MosaicTileProps, useBoard } from '@dxos/react-ui-mosaic';
|
|
13
|
+
|
|
14
|
+
import { meta } from '#meta';
|
|
15
|
+
|
|
16
|
+
import { useKanbanBoard } from './KanbanBoard';
|
|
17
|
+
|
|
18
|
+
const KANBAN_CARD_TILE_NAME = 'KanbanBoard.Card';
|
|
19
|
+
|
|
20
|
+
export type KanbanCardProps = Pick<MosaicTileProps<Obj.Unknown>, 'location' | 'data' | 'debug'>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Mosaic Tile for Kanban card.
|
|
24
|
+
* Uses Surface for content; requires plugin manager context.
|
|
25
|
+
*/
|
|
26
|
+
export const KanbanCard = forwardRef<HTMLDivElement, KanbanCardProps>(({ data, location, debug }, forwardedRef) => {
|
|
27
|
+
const { t } = useTranslation(meta.id);
|
|
28
|
+
const { model } = useBoard(KANBAN_CARD_TILE_NAME);
|
|
29
|
+
const { projection, onCardRemove } = useKanbanBoard(KANBAN_CARD_TILE_NAME);
|
|
30
|
+
const [dragHandle, setDragHandle] = useState<HTMLButtonElement | null>(null);
|
|
31
|
+
const dragHandleRef = useCallback((el: HTMLButtonElement | null) => setDragHandle(el), []);
|
|
32
|
+
|
|
33
|
+
const objectMenuItems = useObjectMenuItems(data);
|
|
34
|
+
|
|
35
|
+
const menuItems = useMemo(
|
|
36
|
+
() => [
|
|
37
|
+
...objectMenuItems,
|
|
38
|
+
...(onCardRemove
|
|
39
|
+
? [
|
|
40
|
+
createMenuAction('remove', () => onCardRemove(data), {
|
|
41
|
+
label: t('remove-card.label'),
|
|
42
|
+
icon: 'ph--trash--regular',
|
|
43
|
+
}),
|
|
44
|
+
]
|
|
45
|
+
: []),
|
|
46
|
+
],
|
|
47
|
+
[objectMenuItems, onCardRemove, data, t],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Menu.Root>
|
|
52
|
+
<Mosaic.Tile
|
|
53
|
+
asChild
|
|
54
|
+
id={model.getItemId(data)}
|
|
55
|
+
data={data}
|
|
56
|
+
location={location}
|
|
57
|
+
debug={debug}
|
|
58
|
+
dragHandle={dragHandle}
|
|
59
|
+
>
|
|
60
|
+
<Focus.Item asChild>
|
|
61
|
+
<Card.Root ref={forwardedRef} data-testid='board-item'>
|
|
62
|
+
<Card.Toolbar>
|
|
63
|
+
<Card.DragHandle ref={dragHandleRef} testId='mosaicBoard.cardDragHandle' />
|
|
64
|
+
<Card.Title data-testid='mosaicBoard.cardTitle'>{Obj.getLabel(data)}</Card.Title>
|
|
65
|
+
{/* TODO(wittjosiah): Reconcile with Card.Menu. */}
|
|
66
|
+
<Menu.Trigger asChild disabled={!menuItems?.length}>
|
|
67
|
+
<Toolbar.IconButton
|
|
68
|
+
iconOnly
|
|
69
|
+
variant='ghost'
|
|
70
|
+
icon='ph--dots-three-vertical--regular'
|
|
71
|
+
label={t('action-menu.label')}
|
|
72
|
+
/>
|
|
73
|
+
</Menu.Trigger>
|
|
74
|
+
<Menu.Content items={menuItems} />
|
|
75
|
+
</Card.Toolbar>
|
|
76
|
+
<Card.Content>
|
|
77
|
+
{projection && <Surface.Surface role='card--content' limit={1} data={{ subject: data, projection }} />}
|
|
78
|
+
</Card.Content>
|
|
79
|
+
</Card.Root>
|
|
80
|
+
</Focus.Item>
|
|
81
|
+
</Mosaic.Tile>
|
|
82
|
+
</Menu.Root>
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
KanbanCard.displayName = KANBAN_CARD_TILE_NAME;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { FC, forwardRef, RefObject, useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
import type { Obj } from '@dxos/echo';
|
|
8
|
+
import { Board, type MosaicTileProps, useBoard } from '@dxos/react-ui-mosaic';
|
|
9
|
+
|
|
10
|
+
import { useKanbanItemEventHandler } from '#hooks';
|
|
11
|
+
import { type ColumnStructure, UNCATEGORIZED_VALUE } from '#types';
|
|
12
|
+
|
|
13
|
+
import { useKanbanBoard } from './KanbanBoard';
|
|
14
|
+
|
|
15
|
+
const KANBAN_COLUMN_NAME = 'KanbanBoard.Column';
|
|
16
|
+
|
|
17
|
+
export type KanbanColumnProps = Pick<MosaicTileProps<ColumnStructure>, 'location' | 'data' | 'debug'>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Mosaic Tile for Kanban column.
|
|
21
|
+
*/
|
|
22
|
+
export const KanbanColumn = forwardRef<HTMLDivElement, KanbanColumnProps>(
|
|
23
|
+
({ data: column, location, debug }, forwardedRef) => {
|
|
24
|
+
const { model } = useBoard<ColumnStructure, Obj.Unknown>(KANBAN_COLUMN_NAME);
|
|
25
|
+
const { columnFieldPath, change, onCardAdd, getPivotAttributes, itemTile } = useKanbanBoard(KANBAN_COLUMN_NAME);
|
|
26
|
+
|
|
27
|
+
const { title } = getPivotAttributes(column.columnValue);
|
|
28
|
+
const uncategorized = column.columnValue === UNCATEGORIZED_VALUE;
|
|
29
|
+
const dragHandleRef = useRef<HTMLButtonElement | null>(null);
|
|
30
|
+
|
|
31
|
+
const eventHandler = useKanbanItemEventHandler({
|
|
32
|
+
column,
|
|
33
|
+
columnFieldPath,
|
|
34
|
+
model,
|
|
35
|
+
change,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Board.Column.Root
|
|
40
|
+
data={column}
|
|
41
|
+
location={location}
|
|
42
|
+
classNames='grid grid-rows-[var(--dx-rail-action)_1fr_var(--dx-rail-action)]'
|
|
43
|
+
debug={debug}
|
|
44
|
+
dragHandleRef={dragHandleRef}
|
|
45
|
+
ref={forwardedRef}
|
|
46
|
+
>
|
|
47
|
+
{uncategorized ? (
|
|
48
|
+
<div className='border-b border-separator p-2' data-testid='board-column-header'>
|
|
49
|
+
<span className='font-medium'>{title}</span>
|
|
50
|
+
</div>
|
|
51
|
+
) : (
|
|
52
|
+
<Board.Column.Header label={title} dragHandleRef={dragHandleRef as RefObject<HTMLButtonElement>} />
|
|
53
|
+
)}
|
|
54
|
+
<Board.Column.Body
|
|
55
|
+
data={column}
|
|
56
|
+
eventHandler={eventHandler}
|
|
57
|
+
Tile={itemTile as FC<MosaicTileProps<Obj.Unknown>>}
|
|
58
|
+
/>
|
|
59
|
+
{onCardAdd && (
|
|
60
|
+
<Board.Column.Footer
|
|
61
|
+
onAdd={() => onCardAdd(column.columnValue === UNCATEGORIZED_VALUE ? undefined : column.columnValue)}
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
</Board.Column.Root>
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
KanbanColumn.displayName = KANBAN_COLUMN_NAME;
|