@dxos/plugin-kanban 0.7.5-main.9d2a38b → 0.7.5-main.b19bfc8

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 (80) hide show
  1. package/dist/lib/browser/artifact-definition-RSO5XMKU.mjs +173 -0
  2. package/dist/lib/browser/artifact-definition-RSO5XMKU.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-L4PZ5BVV.mjs → chunk-ILL6UKZE.mjs} +37 -12
  4. package/dist/lib/browser/chunk-ILL6UKZE.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +33 -22
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/intent-resolver-6BD4KUAU.mjs +122 -0
  8. package/dist/lib/browser/intent-resolver-6BD4KUAU.mjs.map +7 -0
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/react-surface-6NYIVXVG.mjs +285 -0
  11. package/dist/lib/browser/react-surface-6NYIVXVG.mjs.map +7 -0
  12. package/dist/lib/browser/types.mjs +7 -1
  13. package/dist/lib/node/artifact-definition-UTF2PHQN.cjs +189 -0
  14. package/dist/lib/node/artifact-definition-UTF2PHQN.cjs.map +7 -0
  15. package/dist/lib/node/{chunk-QCB2U2J2.cjs → chunk-63KJGDFJ.cjs} +40 -12
  16. package/dist/lib/node/chunk-63KJGDFJ.cjs.map +7 -0
  17. package/dist/lib/node/index.cjs +35 -25
  18. package/dist/lib/node/index.cjs.map +3 -3
  19. package/dist/lib/node/intent-resolver-DHL5HBJM.cjs +136 -0
  20. package/dist/lib/node/intent-resolver-DHL5HBJM.cjs.map +7 -0
  21. package/dist/lib/node/meta.json +1 -1
  22. package/dist/lib/node/react-surface-65D6R6Z7.cjs +301 -0
  23. package/dist/lib/node/react-surface-65D6R6Z7.cjs.map +7 -0
  24. package/dist/lib/node/types.cjs +10 -4
  25. package/dist/lib/node/types.cjs.map +2 -2
  26. package/dist/lib/node-esm/artifact-definition-MVIL3EEK.mjs +174 -0
  27. package/dist/lib/node-esm/artifact-definition-MVIL3EEK.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-PNSRVZBP.mjs → chunk-TZ3QKBLD.mjs} +37 -12
  29. package/dist/lib/node-esm/chunk-TZ3QKBLD.mjs.map +7 -0
  30. package/dist/lib/node-esm/index.mjs +33 -22
  31. package/dist/lib/node-esm/index.mjs.map +3 -3
  32. package/dist/lib/node-esm/intent-resolver-QQWZXC5O.mjs +123 -0
  33. package/dist/lib/node-esm/intent-resolver-QQWZXC5O.mjs.map +7 -0
  34. package/dist/lib/node-esm/meta.json +1 -1
  35. package/dist/lib/node-esm/react-surface-4JPB2SZX.mjs +286 -0
  36. package/dist/lib/node-esm/react-surface-4JPB2SZX.mjs.map +7 -0
  37. package/dist/lib/node-esm/types.mjs +7 -1
  38. package/dist/types/src/KanbanPlugin.d.ts.map +1 -1
  39. package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
  40. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
  41. package/dist/types/src/capabilities/index.d.ts +3 -2
  42. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  43. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  44. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  45. package/dist/types/src/components/KanbanContainer.d.ts +1 -2
  46. package/dist/types/src/components/KanbanContainer.d.ts.map +1 -1
  47. package/dist/types/src/components/KanbanViewEditor.d.ts +1 -2
  48. package/dist/types/src/components/KanbanViewEditor.d.ts.map +1 -1
  49. package/dist/types/src/meta.d.ts +1 -0
  50. package/dist/types/src/meta.d.ts.map +1 -1
  51. package/dist/types/src/translations.d.ts +3 -0
  52. package/dist/types/src/translations.d.ts.map +1 -1
  53. package/dist/types/src/types.d.ts +32 -16
  54. package/dist/types/src/types.d.ts.map +1 -1
  55. package/package.json +26 -21
  56. package/src/KanbanPlugin.tsx +25 -21
  57. package/src/capabilities/artifact-definition.ts +131 -0
  58. package/src/capabilities/index.ts +1 -0
  59. package/src/capabilities/intent-resolver.ts +47 -21
  60. package/src/capabilities/react-surface.tsx +63 -2
  61. package/src/components/KanbanContainer.tsx +38 -37
  62. package/src/components/KanbanViewEditor.tsx +43 -42
  63. package/src/meta.ts +3 -1
  64. package/src/translations.ts +1 -0
  65. package/src/types.ts +34 -7
  66. package/dist/lib/browser/chunk-L4PZ5BVV.mjs.map +0 -7
  67. package/dist/lib/browser/intent-resolver-ILMGO3TT.mjs +0 -70
  68. package/dist/lib/browser/intent-resolver-ILMGO3TT.mjs.map +0 -7
  69. package/dist/lib/browser/react-surface-KCOBVPKL.mjs +0 -180
  70. package/dist/lib/browser/react-surface-KCOBVPKL.mjs.map +0 -7
  71. package/dist/lib/node/chunk-QCB2U2J2.cjs.map +0 -7
  72. package/dist/lib/node/intent-resolver-6QZ6AMZF.cjs +0 -84
  73. package/dist/lib/node/intent-resolver-6QZ6AMZF.cjs.map +0 -7
  74. package/dist/lib/node/react-surface-MOZ2OTXW.cjs +0 -198
  75. package/dist/lib/node/react-surface-MOZ2OTXW.cjs.map +0 -7
  76. package/dist/lib/node-esm/chunk-PNSRVZBP.mjs.map +0 -7
  77. package/dist/lib/node-esm/intent-resolver-LRZVOK2C.mjs +0 -71
  78. package/dist/lib/node-esm/intent-resolver-LRZVOK2C.mjs.map +0 -7
  79. package/dist/lib/node-esm/react-surface-HNVSKYHF.mjs +0 -181
  80. package/dist/lib/node-esm/react-surface-HNVSKYHF.mjs.map +0 -7
@@ -2,23 +2,16 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import {
6
- createIntent,
7
- defineModule,
8
- contributes,
9
- Capabilities,
10
- Events,
11
- definePlugin,
12
- oneOf,
13
- } from '@dxos/app-framework';
14
- import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
15
- import { type Space } from '@dxos/react-client/echo';
5
+ import { createIntent, defineModule, contributes, Capabilities, Events, definePlugin } from '@dxos/app-framework';
6
+ import { ClientEvents } from '@dxos/plugin-client';
7
+ import { SpaceCapabilities } from '@dxos/plugin-space';
8
+ import { defineObjectForm } from '@dxos/plugin-space/types';
16
9
  import { KanbanType, translations as kanbanTranslations } from '@dxos/react-ui-kanban';
17
10
 
18
- import { IntentResolver, ReactSurface } from './capabilities';
11
+ import { ArtifactDefinition, IntentResolver, ReactSurface } from './capabilities';
19
12
  import { KANBAN_PLUGIN, meta } from './meta';
20
13
  import translations from './translations';
21
- import { KanbanAction } from './types';
14
+ import { CreateKanbanSchema, KanbanAction } from './types';
22
15
 
23
16
  export const KanbanPlugin = () =>
24
17
  definePlugin(meta, [
@@ -29,31 +22,42 @@ export const KanbanPlugin = () =>
29
22
  }),
30
23
  defineModule({
31
24
  id: `${meta.id}/module/metadata`,
32
- activatesOn: oneOf(Events.Startup, Events.SetupAppGraph),
25
+ activatesOn: Events.SetupMetadata,
33
26
  activate: () =>
34
27
  contributes(Capabilities.Metadata, {
35
28
  id: KanbanType.typename,
36
29
  metadata: {
37
- createObject: (props: { name?: string }, options: { space: Space }) =>
38
- createIntent(KanbanAction.Create, { ...props, space: options.space }),
39
30
  placeholder: ['kanban title placeholder', { ns: KANBAN_PLUGIN }],
40
31
  icon: 'ph--kanban--regular',
41
32
  },
42
33
  }),
43
34
  }),
44
35
  defineModule({
45
- id: `${meta.id}/module/schema`,
46
- activatesOn: ClientEvents.SetupClient,
47
- activate: () => contributes(ClientCapabilities.Schema, [KanbanType]),
36
+ id: `${meta.id}/module/object-form`,
37
+ activatesOn: ClientEvents.SetupSchema,
38
+ activate: () =>
39
+ contributes(
40
+ SpaceCapabilities.ObjectForm,
41
+ defineObjectForm({
42
+ objectSchema: KanbanType,
43
+ formSchema: CreateKanbanSchema,
44
+ getIntent: (props, options) => createIntent(KanbanAction.Create, { ...props, space: options.space }),
45
+ }),
46
+ ),
48
47
  }),
49
48
  defineModule({
50
49
  id: `${meta.id}/module/react-surface`,
51
- activatesOn: Events.Startup,
50
+ activatesOn: Events.SetupReactSurface,
52
51
  activate: ReactSurface,
53
52
  }),
54
53
  defineModule({
55
54
  id: `${meta.id}/module/intent-resolver`,
56
- activatesOn: Events.SetupIntents,
55
+ activatesOn: Events.SetupIntentResolver,
57
56
  activate: IntentResolver,
58
57
  }),
58
+ defineModule({
59
+ id: `${meta.id}/module/artifact-definition`,
60
+ activatesOn: Events.SetupArtifactDefinition,
61
+ activate: ArtifactDefinition,
62
+ }),
59
63
  ]);
@@ -0,0 +1,131 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { pipe } from 'effect';
6
+
7
+ import { Capabilities, chain, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
8
+ import { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';
9
+ import { createArtifactElement } from '@dxos/assistant';
10
+ import { isInstanceOf, S } from '@dxos/echo-schema';
11
+ import { invariant } from '@dxos/invariant';
12
+ import { SpaceAction } from '@dxos/plugin-space/types';
13
+ import { Filter, fullyQualifiedId, type Space } from '@dxos/react-client/echo';
14
+ import { KanbanType } from '@dxos/react-ui-kanban';
15
+
16
+ import { KanbanAction } from '../types';
17
+
18
+ const QualifiedId = S.String.annotations({
19
+ description: 'The fully qualified ID of the kanban `spaceID:objectID`',
20
+ });
21
+
22
+ declare global {
23
+ interface ToolContextExtensions {
24
+ space?: Space;
25
+ dispatch?: PromiseIntentDispatcher;
26
+ }
27
+ }
28
+
29
+ export default () => {
30
+ const definition = defineArtifact({
31
+ id: 'plugin-kanban',
32
+ instructions: `
33
+ When working with kanban boards here are some additional instructions:
34
+ - Before adding items to a kanban board, inspect the board to see its schema
35
+ - When adding items, you must not include the 'id' field -- it is automatically generated
36
+ - BEFORE adding items, always make sure the board has been shown to the user!
37
+ `,
38
+ schema: KanbanType,
39
+ tools: [
40
+ defineTool({
41
+ name: 'kanban_new',
42
+ description: `
43
+ Create a new kanban board using an existing schema.
44
+ Use schema_create first to create a schema, or schema_list to choose an existing one.`,
45
+ schema: S.Struct({
46
+ typename: S.String.annotations({
47
+ description: 'The fully qualified typename of the schema to use for the kanban cards.',
48
+ }),
49
+ pivotColumn: S.optional(S.String).annotations({
50
+ description: 'Optional field name to use as the column pivot.',
51
+ }),
52
+ }),
53
+ execute: async ({ typename, pivotColumn }, { extensions }) => {
54
+ invariant(extensions?.space, 'No space');
55
+ invariant(extensions?.dispatch, 'No intent dispatcher');
56
+
57
+ // Validate schema exists first
58
+ const schema = await extensions.space.db.schemaRegistry.query({ typename }).firstOrUndefined();
59
+ if (!schema) {
60
+ return ToolResult.Error(`Schema not found: ${typename}`);
61
+ }
62
+
63
+ const intent = pipe(
64
+ createIntent(KanbanAction.Create, {
65
+ space: extensions.space,
66
+ initialSchema: typename,
67
+ initialPivotColumn: pivotColumn,
68
+ }),
69
+ chain(SpaceAction.AddObject, { target: extensions.space }),
70
+ );
71
+
72
+ const { data, error } = await extensions.dispatch(intent);
73
+ if (!data || error) {
74
+ return ToolResult.Error(error?.message ?? 'Failed to create kanban board');
75
+ }
76
+
77
+ return ToolResult.Success(createArtifactElement(data.id));
78
+ },
79
+ }),
80
+ defineTool({
81
+ name: 'kanban_list',
82
+ description: 'List all kanban boards in the current space.',
83
+ schema: S.Struct({}),
84
+ execute: async (_input, { extensions }) => {
85
+ invariant(extensions?.space, 'No space');
86
+ const space = extensions.space;
87
+ const { objects: boards } = await space.db.query(Filter.schema(KanbanType)).run();
88
+
89
+ const boardInfo = await Promise.all(
90
+ boards.map(async (board: KanbanType) => {
91
+ const view = await board.cardView?.load();
92
+ return {
93
+ id: fullyQualifiedId(board),
94
+ typename: view?.query.type,
95
+ };
96
+ }),
97
+ );
98
+
99
+ return ToolResult.Success(boardInfo);
100
+ },
101
+ }),
102
+ defineTool({
103
+ name: 'kanban_inspect',
104
+ description: 'Get details about a specific kanban board.',
105
+ schema: S.Struct({ id: QualifiedId }),
106
+ execute: async ({ id }, { extensions }) => {
107
+ invariant(extensions?.space, 'No space');
108
+ const space = extensions.space;
109
+ const { objects: boards } = await space.db.query(Filter.schema(KanbanType)).run();
110
+ const board = boards.find((board: KanbanType) => fullyQualifiedId(board) === id);
111
+ invariant(isInstanceOf(KanbanType, board));
112
+
113
+ const view = await board.cardView?.load();
114
+ invariant(view);
115
+
116
+ const typename = view.query.type;
117
+ const schema = await space.db.schemaRegistry.query({ typename }).firstOrUndefined();
118
+ invariant(schema);
119
+
120
+ return ToolResult.Success({
121
+ schema,
122
+ columnField: board.columnFieldId,
123
+ viewFields: view.fields,
124
+ });
125
+ },
126
+ }),
127
+ ],
128
+ });
129
+
130
+ return contributes(Capabilities.ArtifactDefinition, definition);
131
+ };
@@ -4,5 +4,6 @@
4
4
 
5
5
  import { lazy } from '@dxos/app-framework';
6
6
 
7
+ export const ArtifactDefinition = lazy(() => import('./artifact-definition'));
7
8
  export const IntentResolver = lazy(() => import('./intent-resolver'));
8
9
  export const ReactSurface = lazy(() => import('./react-surface'));
@@ -12,28 +12,54 @@ import { createKanban, KanbanAction } from '../types';
12
12
 
13
13
  export default () =>
14
14
  contributes(Capabilities.IntentResolver, [
15
- createResolver(KanbanAction.Create, async ({ space }) => ({
16
- data: { object: await createKanban(space) },
17
- })),
18
- createResolver(KanbanAction.DeleteCardField, ({ kanban, fieldId, deletionData }, undo) => {
19
- invariant(kanban.cardView);
15
+ createResolver({
16
+ intent: KanbanAction.Create,
17
+ resolve: async ({ space, initialSchema, initialPivotColumn }) => ({
18
+ data: { object: await createKanban({ space, initialSchema, initialPivotColumn }) },
19
+ }),
20
+ }),
21
+ createResolver({
22
+ intent: KanbanAction.DeleteCardField,
23
+ resolve: ({ kanban, fieldId, deletionData }, undo) => {
24
+ invariant(kanban.cardView);
25
+ invariant(kanban.cardView.target?.query.type);
26
+
27
+ const schema =
28
+ kanban.cardView.target && getSpace(kanban)?.db.schemaRegistry.getSchema(kanban.cardView.target.query.type);
29
+ invariant(schema);
30
+ const projection = new ViewProjection(schema, kanban.cardView.target!);
20
31
 
21
- const schema =
22
- kanban.cardView.target && getSpace(kanban)?.db.schemaRegistry.getSchema(kanban.cardView.target.query.type);
23
- invariant(schema);
24
- const projection = new ViewProjection(schema, kanban.cardView.target!);
32
+ if (!undo) {
33
+ const { deleted, index } = projection.deleteFieldProjection(fieldId);
34
+ return {
35
+ undoable: {
36
+ message: ['card field deleted label', { ns: KANBAN_PLUGIN }],
37
+ data: { deletionData: { ...deleted, index } },
38
+ },
39
+ };
40
+ } else if (undo && deletionData) {
41
+ const { field, props, index } = deletionData;
42
+ projection.setFieldProjection({ field, props }, index);
43
+ }
44
+ },
45
+ }),
46
+ createResolver({
47
+ intent: KanbanAction.DeleteCard,
48
+ resolve: ({ card }, undo) => {
49
+ const space = getSpace(card);
50
+ invariant(space);
25
51
 
26
- if (!undo) {
27
- const { deleted, index } = projection.deleteFieldProjection(fieldId);
28
- return {
29
- undoable: {
30
- message: ['card field deleted label', { ns: KANBAN_PLUGIN }],
31
- data: { deletionData: { ...deleted, index } },
32
- },
33
- };
34
- } else if (undo && deletionData) {
35
- const { field, props, index } = deletionData;
36
- projection.setFieldProjection({ field, props }, index);
37
- }
52
+ if (!undo) {
53
+ space.db.remove(card);
54
+ return {
55
+ undoable: {
56
+ message: ['card deleted label', { ns: KANBAN_PLUGIN }],
57
+ data: { card },
58
+ },
59
+ };
60
+ } else {
61
+ space.db.add(card);
62
+ }
63
+ },
38
64
  }),
39
65
  ]);
@@ -2,14 +2,19 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import React, { useMemo } from 'react';
6
6
 
7
7
  import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
8
+ import { type S } from '@dxos/echo-schema';
9
+ import { findAnnotation } from '@dxos/effect';
10
+ import { type CollectionType } from '@dxos/plugin-space/types';
11
+ import { getSpace, isSpace, type Space } from '@dxos/react-client/echo';
12
+ import { type InputProps, SelectInput, useFormValues } from '@dxos/react-ui-form';
8
13
  import { type KanbanType } from '@dxos/react-ui-kanban';
9
14
 
10
15
  import { KanbanContainer, KanbanViewEditor } from '../components';
11
16
  import { KANBAN_PLUGIN } from '../meta';
12
- import { isKanban } from '../types';
17
+ import { isKanban, InitialSchemaAnnotationId, InitialPivotColumnAnnotationId } from '../types';
13
18
 
14
19
  export default () =>
15
20
  contributes(Capabilities.ReactSurface, [
@@ -25,4 +30,60 @@ export default () =>
25
30
  filter: (data): data is { subject: KanbanType } => isKanban(data.subject),
26
31
  component: ({ data }) => <KanbanViewEditor kanban={data.subject} />,
27
32
  }),
33
+ createSurface({
34
+ id: `${KANBAN_PLUGIN}/create-initial-schema-form-[schema]`,
35
+ role: 'form-input',
36
+ filter: (data): data is { prop: string; schema: S.Schema<any>; target: Space | CollectionType | undefined } => {
37
+ const annotation = findAnnotation<boolean>((data.schema as S.Schema.All).ast, InitialSchemaAnnotationId);
38
+ return !!annotation;
39
+ },
40
+ component: ({ data: { target }, ...inputProps }) => {
41
+ const props = inputProps as any as InputProps;
42
+ const space = isSpace(target) ? target : getSpace(target);
43
+ if (!space) {
44
+ return null;
45
+ }
46
+ const schemata = space?.db.schemaRegistry.query().runSync();
47
+
48
+ return <SelectInput {...props} options={schemata.map((schema) => ({ value: schema.typename }))} />;
49
+ },
50
+ }),
51
+ createSurface({
52
+ id: `${KANBAN_PLUGIN}/create-initial-schema-form-[pivot-column]`,
53
+ role: 'form-input',
54
+ filter: (data): data is { prop: string; schema: S.Schema<any>; target: Space | CollectionType | undefined } => {
55
+ const annotation = findAnnotation<boolean>((data.schema as S.Schema.All).ast, InitialPivotColumnAnnotationId);
56
+ return !!annotation;
57
+ },
58
+ component: ({ data: { target }, ...inputProps }) => {
59
+ const props = inputProps as any as InputProps;
60
+ const space = isSpace(target) ? target : getSpace(target);
61
+ if (!space) {
62
+ return null;
63
+ }
64
+ const { initialSchema } = useFormValues();
65
+ const [selectedSchema] = space?.db.schemaRegistry.query({ typename: initialSchema }).runSync();
66
+
67
+ const singleSelectColumns = useMemo(() => {
68
+ if (!selectedSchema?.jsonSchema?.properties) {
69
+ return [];
70
+ }
71
+
72
+ const columns = Object.entries(selectedSchema.jsonSchema.properties).reduce<string[]>((acc, [key, value]) => {
73
+ if (typeof value === 'object' && value?.format === 'single-select') {
74
+ acc.push(key);
75
+ }
76
+ return acc;
77
+ }, []);
78
+
79
+ return columns;
80
+ }, [selectedSchema?.jsonSchema]);
81
+
82
+ if (!initialSchema) {
83
+ return null;
84
+ }
85
+
86
+ return <SelectInput {...props} options={singleSelectColumns.map((column) => ({ value: column }))} />;
87
+ },
88
+ }),
28
89
  ]);
@@ -4,21 +4,44 @@
4
4
 
5
5
  import React, { useCallback, useEffect, useState } from 'react';
6
6
 
7
+ import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
7
8
  import { type EchoSchema } from '@dxos/echo-schema';
8
- import { invariant } from '@dxos/invariant';
9
9
  import { useGlobalFilteredObjects } from '@dxos/plugin-search';
10
10
  import { Filter, useQuery, getSpace, create } from '@dxos/react-client/echo';
11
11
  import { type KanbanType, useKanbanModel, Kanban } from '@dxos/react-ui-kanban';
12
12
  import { StackItem } from '@dxos/react-ui-stack';
13
+ import { ViewProjection } from '@dxos/schema';
14
+
15
+ import { KanbanAction } from '../types';
13
16
 
14
17
  export const KanbanContainer = ({ kanban }: { kanban: KanbanType; role: string }) => {
15
18
  const [cardSchema, setCardSchema] = useState<EchoSchema>();
19
+ const [projection, setProjection] = useState<ViewProjection>();
16
20
  const space = getSpace(kanban);
21
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
22
+
23
+ useEffect(() => {
24
+ if (kanban.cardView?.target?.query?.type && space) {
25
+ const query = space.db.schemaRegistry.query({ typename: kanban.cardView.target.query.type });
26
+ const unsubscribe = query.subscribe(
27
+ () => {
28
+ const [schema] = query.results;
29
+ if (schema) {
30
+ setCardSchema(schema);
31
+ }
32
+ },
33
+ { fire: true },
34
+ );
35
+ return unsubscribe;
36
+ }
37
+ }, [kanban.cardView?.target?.query, space]);
38
+
17
39
  useEffect(() => {
18
- if (kanban.cardView && space) {
19
- setCardSchema(space.db.schemaRegistry.getSchema(kanban.cardView.target!.query.type));
40
+ if (kanban.cardView?.target && cardSchema) {
41
+ setProjection(new ViewProjection(cardSchema, kanban.cardView.target));
20
42
  }
21
- }, [kanban.cardView, space]);
43
+ // TODO(ZaymonFC): Is there a better way to get notified about deep changes in the json schema?
44
+ }, [kanban.cardView?.target, cardSchema, JSON.stringify(cardSchema?.jsonSchema)]);
22
45
 
23
46
  const objects = useQuery(space, cardSchema ? Filter.schema(cardSchema) : Filter.nothing());
24
47
  const filteredObjects = useGlobalFilteredObjects(objects);
@@ -26,54 +49,32 @@ export const KanbanContainer = ({ kanban }: { kanban: KanbanType; role: string }
26
49
  const model = useKanbanModel({
27
50
  kanban,
28
51
  cardSchema,
52
+ projection,
29
53
  items: filteredObjects,
30
54
  });
31
55
 
32
- const handleAddColumn = useCallback((columnValue: string) => model?.addEmptyColumn(columnValue), [model]);
33
-
34
56
  const handleAddCard = useCallback(
35
- (columnValue: string) => {
36
- if (space && cardSchema) {
37
- space.db.add(
38
- create(cardSchema, {
39
- title: '',
40
- description: '',
41
- state: columnValue,
42
- }),
43
- );
57
+ (columnValue: string | undefined) => {
58
+ const path = model?.columnFieldPath;
59
+ if (space && cardSchema && path) {
60
+ const card = create(cardSchema, { [path]: columnValue });
61
+ space.db.add(card);
62
+ return card.id;
44
63
  }
45
64
  },
46
- [space, cardSchema],
65
+ [space, cardSchema, model],
47
66
  );
48
67
 
49
68
  const handleRemoveCard = useCallback(
50
69
  (card: { id: string }) => {
51
- invariant(space);
52
- space.db.remove(card);
53
- },
54
- [space],
55
- );
56
-
57
- const handleRemoveEmptyColumn = useCallback(
58
- (columnValue: string) => {
59
- model?.removeColumnFromArrangement(columnValue);
70
+ void dispatch(createIntent(KanbanAction.DeleteCard, { card }));
60
71
  },
61
- [model],
72
+ [dispatch],
62
73
  );
63
74
 
64
75
  return (
65
76
  <StackItem.Content toolbar={false}>
66
- {model ? (
67
- <Kanban
68
- model={model}
69
- onAddCard={handleAddCard}
70
- onAddColumn={handleAddColumn}
71
- onRemoveCard={handleRemoveCard}
72
- onRemoveEmptyColumn={handleRemoveEmptyColumn}
73
- />
74
- ) : (
75
- <span>Loading</span>
76
- )}
77
+ {model && <Kanban model={model} onAddCard={handleAddCard} onRemoveCard={handleRemoveCard} />}
77
78
  </StackItem.Content>
78
79
  );
79
80
  };
@@ -1,14 +1,16 @@
1
1
  //
2
- // Copyright 2023 DXOS.org
2
+ // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
5
+ import React, { useCallback, useMemo } from 'react';
6
6
 
7
7
  import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
8
- import { Filter, getSpace, useQuery } from '@dxos/react-client/echo';
9
- import { ViewEditor, Form } from '@dxos/react-ui-form';
10
- import { type KanbanType, KanbanPropsSchema } from '@dxos/react-ui-kanban';
11
- import { ViewType } from '@dxos/schema';
8
+ import { FormatEnum } from '@dxos/echo-schema';
9
+ import { invariant } from '@dxos/invariant';
10
+ import { Filter, getSpace, useQuery, useSchema } from '@dxos/react-client/echo';
11
+ import { ViewEditor, Form, SelectInput, type CustomInputMap } from '@dxos/react-ui-form';
12
+ import { type KanbanType, KanbanSettingsSchema } from '@dxos/react-ui-kanban';
13
+ import { ViewType, ViewProjection } from '@dxos/schema';
12
14
 
13
15
  import { KanbanAction } from '../types';
14
16
 
@@ -17,22 +19,13 @@ type KanbanViewEditorProps = { kanban: KanbanType };
17
19
  export const KanbanViewEditor = ({ kanban }: KanbanViewEditorProps) => {
18
20
  const { dispatchPromise: dispatch } = useIntentDispatcher();
19
21
  const space = getSpace(kanban);
20
-
21
- // TODO(ZaymonFC): The schema registry needs an API where we can query with initial value and
22
- // endure typename changes. We shouldn't need to manage a subscription at this layer.
23
- const [schema, setSchema] = useState(
24
- space && kanban?.cardView?.target?.query?.type
25
- ? space.db.schemaRegistry.getSchema(kanban.cardView.target.query.type)
26
- : undefined,
27
- );
28
-
29
- const views = useQuery(space, Filter.schema(ViewType));
30
22
  const currentTypename = useMemo(() => kanban?.cardView?.target?.query?.type, [kanban?.cardView?.target?.query?.type]);
23
+ const schema = useSchema(space, currentTypename);
24
+ const views = useQuery(space, Filter.schema(ViewType));
25
+
31
26
  const updateViewTypename = useCallback(
32
27
  (newTypename: string) => {
33
- if (!schema) {
34
- return;
35
- }
28
+ invariant(schema);
36
29
  const matchingViews = views.filter((view) => view.query.type === currentTypename);
37
30
  for (const view of matchingViews) {
38
31
  view.query.type = newTypename;
@@ -42,40 +35,48 @@ export const KanbanViewEditor = ({ kanban }: KanbanViewEditorProps) => {
42
35
  [views, schema],
43
36
  );
44
37
 
45
- useEffect(() => {
46
- if (space && kanban?.cardView?.target?.query?.type) {
47
- const unsubscribe = space.db.schemaRegistry
48
- .query({ typename: kanban?.cardView?.target?.query?.type })
49
- .subscribe((query) => {
50
- const [schema] = query.results;
51
- if (schema) {
52
- setSchema(schema);
53
- }
54
- });
55
-
56
- return unsubscribe;
57
- }
58
- }, [space, kanban?.cardView?.target?.query?.type]);
59
-
60
38
  const handleDelete = useCallback(
61
39
  (fieldId: string) => dispatch?.(createIntent(KanbanAction.DeleteCardField, { kanban, fieldId })),
62
40
  [dispatch, kanban],
63
41
  );
64
42
 
43
+ const projection = useMemo(() => {
44
+ if (kanban?.cardView?.target && schema) {
45
+ return new ViewProjection(schema, kanban.cardView.target);
46
+ }
47
+ }, [kanban?.cardView?.target, schema, JSON.stringify(schema)]);
48
+
49
+ const selectFields = useMemo(() => {
50
+ if (!projection) {
51
+ return [];
52
+ }
53
+
54
+ return projection
55
+ .getFieldProjections()
56
+ .filter((field) => field.props.format === FormatEnum.SingleSelect)
57
+ .map(({ field }) => ({ value: field.id, label: field.path }));
58
+ }, [projection]);
59
+
60
+ const onSave = useCallback(
61
+ (values: Partial<{ columnFieldId: string }>) => {
62
+ kanban.columnFieldId = values.columnFieldId;
63
+ },
64
+ [kanban],
65
+ );
66
+
67
+ const initialValues = useMemo(() => ({ columnFieldId: kanban.columnFieldId }), [kanban]);
68
+ const custom: CustomInputMap = useMemo(
69
+ () => ({ columnFieldId: (props) => <SelectInput {...props} options={selectFields} /> }),
70
+ [selectFields],
71
+ );
72
+
65
73
  if (!space || !schema || !kanban.cardView?.target) {
66
74
  return null;
67
75
  }
68
76
 
69
77
  return (
70
78
  <>
71
- <Form
72
- schema={KanbanPropsSchema}
73
- values={{ columnField: kanban.columnField }}
74
- onSave={({ columnField }) => {
75
- kanban.columnField = columnField;
76
- kanban.arrangement = undefined;
77
- }}
78
- />
79
+ <Form schema={KanbanSettingsSchema} values={initialValues} onSave={onSave} autoSave Custom={custom} />
79
80
  <ViewEditor
80
81
  registry={space.db.schemaRegistry}
81
82
  schema={schema}
package/src/meta.ts CHANGED
@@ -9,8 +9,10 @@ export const KANBAN_PLUGIN = 'dxos.org/plugin/kanban';
9
9
  export const meta = {
10
10
  id: KANBAN_PLUGIN,
11
11
  name: 'Kanban',
12
- description: 'Kanban board for managing tasks.',
12
+ description:
13
+ 'Kanban allows you to explore Table data in sorted columns defined by your custom schema. You can use Kanbans to track progress or trigger custom automations when cards are moved from one state to another.',
13
14
  icon: 'ph--kanban--regular',
14
15
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-kanban',
15
16
  tags: ['experimental'],
17
+ screenshots: ['https://dxos.network/plugin-details-kanban-dark.png'],
16
18
  } satisfies PluginMeta;
@@ -26,6 +26,7 @@ export default [
26
26
  'delete item label': 'Delete card',
27
27
  'create kanban label': 'Create kanban',
28
28
  'card field deleted label': 'Card field deleted',
29
+ 'card deleted label': 'Card deleted',
29
30
  },
30
31
  },
31
32
  },