@dxos/plugin-kanban 0.8.2-main.12df754 → 0.8.2-main.30e4dbb

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 (83) hide show
  1. package/dist/lib/browser/{artifact-definition-SVNHDJQT.mjs → artifact-definition-VGRBHXJ6.mjs} +10 -10
  2. package/dist/lib/browser/artifact-definition-VGRBHXJ6.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-K5BYEZ4Z.mjs → chunk-6JAA7YSW.mjs} +23 -35
  4. package/dist/lib/browser/chunk-6JAA7YSW.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +4 -4
  6. package/dist/lib/browser/intent-resolver-44SXCRIH.mjs +297 -0
  7. package/dist/lib/browser/intent-resolver-44SXCRIH.mjs.map +7 -0
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/{react-surface-R25PYWQV.mjs → react-surface-H5UD7LKX.mjs} +56 -26
  10. package/dist/lib/browser/react-surface-H5UD7LKX.mjs.map +7 -0
  11. package/dist/lib/browser/types.mjs +1 -3
  12. package/dist/lib/node/{artifact-definition-M2XAYUI2.cjs → artifact-definition-KDTULJLX.cjs} +17 -17
  13. package/dist/lib/node/artifact-definition-KDTULJLX.cjs.map +7 -0
  14. package/dist/lib/node/{chunk-3EUR6ZR2.cjs → chunk-O4U7ZQ2I.cjs} +25 -38
  15. package/dist/lib/node/chunk-O4U7ZQ2I.cjs.map +7 -0
  16. package/dist/lib/node/index.cjs +16 -16
  17. package/dist/lib/node/intent-resolver-23TVN46D.cjs +308 -0
  18. package/dist/lib/node/intent-resolver-23TVN46D.cjs.map +7 -0
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/{react-surface-FVM64YAQ.cjs → react-surface-LKFQ3TZH.cjs} +61 -31
  21. package/dist/lib/node/react-surface-LKFQ3TZH.cjs.map +7 -0
  22. package/dist/lib/node/types.cjs +6 -8
  23. package/dist/lib/node/types.cjs.map +2 -2
  24. package/dist/lib/node-esm/{artifact-definition-HQ5I2OO5.mjs → artifact-definition-G2R5LF26.mjs} +10 -10
  25. package/dist/lib/node-esm/artifact-definition-G2R5LF26.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-2N7CO3DI.mjs → chunk-NOC32MF5.mjs} +23 -35
  27. package/dist/lib/node-esm/chunk-NOC32MF5.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +4 -4
  29. package/dist/lib/node-esm/intent-resolver-SUADAOIJ.mjs +298 -0
  30. package/dist/lib/node-esm/intent-resolver-SUADAOIJ.mjs.map +7 -0
  31. package/dist/lib/node-esm/meta.json +1 -1
  32. package/dist/lib/node-esm/{react-surface-LZ7MP3CQ.mjs → react-surface-TUKDSY4T.mjs} +56 -26
  33. package/dist/lib/node-esm/react-surface-TUKDSY4T.mjs.map +7 -0
  34. package/dist/lib/node-esm/types.mjs +1 -3
  35. package/dist/types/src/capabilities/index.d.ts +1 -1
  36. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  37. package/dist/types/src/capabilities/intent-resolver.d.ts +2 -2
  38. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  39. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  40. package/dist/types/src/components/KanbanContainer.d.ts.map +1 -1
  41. package/dist/types/src/components/KanbanContainer.stories.d.ts +10 -0
  42. package/dist/types/src/components/KanbanContainer.stories.d.ts.map +1 -0
  43. package/dist/types/src/components/KanbanViewEditor.d.ts.map +1 -1
  44. package/dist/types/src/testing/index.d.ts +3 -0
  45. package/dist/types/src/testing/index.d.ts.map +1 -0
  46. package/dist/types/src/testing/initialize-kanban.d.ts +17 -0
  47. package/dist/types/src/testing/initialize-kanban.d.ts.map +1 -0
  48. package/dist/types/src/testing/kanban-manager.d.ts +7 -0
  49. package/dist/types/src/testing/kanban-manager.d.ts.map +1 -0
  50. package/dist/types/src/testing/playwright/smoke.spec.d.ts +2 -0
  51. package/dist/types/src/testing/playwright/smoke.spec.d.ts.map +1 -0
  52. package/dist/types/src/translations.d.ts +2 -28
  53. package/dist/types/src/translations.d.ts.map +1 -1
  54. package/dist/types/src/types.d.ts +34 -41
  55. package/dist/types/src/types.d.ts.map +1 -1
  56. package/dist/types/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +29 -25
  58. package/src/capabilities/artifact-definition.ts +8 -8
  59. package/src/capabilities/intent-resolver.ts +10 -6
  60. package/src/capabilities/react-surface.tsx +46 -12
  61. package/src/components/KanbanContainer.stories.tsx +186 -0
  62. package/src/components/KanbanContainer.tsx +21 -8
  63. package/src/testing/index.ts +6 -0
  64. package/src/testing/initialize-kanban.ts +139 -0
  65. package/src/testing/kanban-manager.ts +13 -0
  66. package/src/testing/playwright/playwright.config.cts +18 -0
  67. package/src/testing/playwright/smoke.spec.ts +7 -0
  68. package/src/types.ts +26 -43
  69. package/dist/lib/browser/artifact-definition-SVNHDJQT.mjs.map +0 -7
  70. package/dist/lib/browser/chunk-K5BYEZ4Z.mjs.map +0 -7
  71. package/dist/lib/browser/intent-resolver-XCDQ5N3Q.mjs +0 -132
  72. package/dist/lib/browser/intent-resolver-XCDQ5N3Q.mjs.map +0 -7
  73. package/dist/lib/browser/react-surface-R25PYWQV.mjs.map +0 -7
  74. package/dist/lib/node/artifact-definition-M2XAYUI2.cjs.map +0 -7
  75. package/dist/lib/node/chunk-3EUR6ZR2.cjs.map +0 -7
  76. package/dist/lib/node/intent-resolver-P3PSZO7H.cjs +0 -146
  77. package/dist/lib/node/intent-resolver-P3PSZO7H.cjs.map +0 -7
  78. package/dist/lib/node/react-surface-FVM64YAQ.cjs.map +0 -7
  79. package/dist/lib/node-esm/artifact-definition-HQ5I2OO5.mjs.map +0 -7
  80. package/dist/lib/node-esm/chunk-2N7CO3DI.mjs.map +0 -7
  81. package/dist/lib/node-esm/intent-resolver-4G47V67J.mjs +0 -133
  82. package/dist/lib/node-esm/intent-resolver-4G47V67J.mjs.map +0 -7
  83. package/dist/lib/node-esm/react-surface-LZ7MP3CQ.mjs.map +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-kanban",
3
- "version": "0.8.2-main.12df754",
3
+ "version": "0.8.2-main.30e4dbb",
4
4
  "description": "Kanban DXOS Surface plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -34,24 +34,25 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@preact/signals-core": "^1.6.0",
37
- "@dxos/app-framework": "0.8.2-main.12df754",
38
- "@dxos/assistant": "0.8.2-main.12df754",
39
- "@dxos/async": "0.8.2-main.12df754",
40
- "@dxos/echo-schema": "0.8.2-main.12df754",
41
- "@dxos/invariant": "0.8.2-main.12df754",
42
- "@dxos/artifact": "0.8.2-main.12df754",
43
- "@dxos/effect": "0.8.2-main.12df754",
44
- "@dxos/plugin-client": "0.8.2-main.12df754",
45
- "@dxos/plugin-graph": "0.8.2-main.12df754",
46
- "@dxos/plugin-search": "0.8.2-main.12df754",
47
- "@dxos/random": "0.8.2-main.12df754",
48
- "@dxos/react-client": "0.8.2-main.12df754",
49
- "@dxos/plugin-space": "0.8.2-main.12df754",
50
- "@dxos/react-ui-kanban": "0.8.2-main.12df754",
51
- "@dxos/react-ui-form": "0.8.2-main.12df754",
52
- "@dxos/react-ui-stack": "0.8.2-main.12df754",
53
- "@dxos/schema": "0.8.2-main.12df754",
54
- "@dxos/util": "0.8.2-main.12df754"
37
+ "effect": "3.14.21",
38
+ "@dxos/app-framework": "0.8.2-main.30e4dbb",
39
+ "@dxos/artifact": "0.8.2-main.30e4dbb",
40
+ "@dxos/assistant": "0.8.2-main.30e4dbb",
41
+ "@dxos/async": "0.8.2-main.30e4dbb",
42
+ "@dxos/effect": "0.8.2-main.30e4dbb",
43
+ "@dxos/echo-schema": "0.8.2-main.30e4dbb",
44
+ "@dxos/invariant": "0.8.2-main.30e4dbb",
45
+ "@dxos/plugin-client": "0.8.2-main.30e4dbb",
46
+ "@dxos/plugin-graph": "0.8.2-main.30e4dbb",
47
+ "@dxos/plugin-search": "0.8.2-main.30e4dbb",
48
+ "@dxos/plugin-space": "0.8.2-main.30e4dbb",
49
+ "@dxos/react-client": "0.8.2-main.30e4dbb",
50
+ "@dxos/random": "0.8.2-main.30e4dbb",
51
+ "@dxos/react-ui-kanban": "0.8.2-main.30e4dbb",
52
+ "@dxos/react-ui-form": "0.8.2-main.30e4dbb",
53
+ "@dxos/react-ui-stack": "0.8.2-main.30e4dbb",
54
+ "@dxos/util": "0.8.2-main.30e4dbb",
55
+ "@dxos/schema": "0.8.2-main.30e4dbb"
55
56
  },
56
57
  "devDependencies": {
57
58
  "@types/react": "~18.2.0",
@@ -59,16 +60,19 @@
59
60
  "react": "~18.2.0",
60
61
  "react-dom": "~18.2.0",
61
62
  "vite": "5.4.7",
62
- "@dxos/storybook-utils": "0.8.2-main.12df754",
63
- "@dxos/react-ui-theme": "0.8.2-main.12df754",
64
- "@dxos/react-ui": "0.8.2-main.12df754"
63
+ "@dxos/plugin-preview": "0.8.2-main.30e4dbb",
64
+ "@dxos/plugin-theme": "0.8.2-main.30e4dbb",
65
+ "@dxos/react-ui": "0.8.2-main.30e4dbb",
66
+ "@dxos/react-ui-syntax-highlighter": "0.8.2-main.30e4dbb",
67
+ "@dxos/react-ui-theme": "0.8.2-main.30e4dbb",
68
+ "@dxos/storybook-utils": "0.8.2-main.30e4dbb"
65
69
  },
66
70
  "peerDependencies": {
67
- "effect": "3.13.3",
71
+ "effect": "^3.13.3",
68
72
  "react": "~18.2.0",
69
73
  "react-dom": "~18.2.0",
70
- "@dxos/react-ui-theme": "0.8.2-main.12df754",
71
- "@dxos/react-ui": "0.8.2-main.12df754"
74
+ "@dxos/react-ui": "0.8.2-main.30e4dbb",
75
+ "@dxos/react-ui-theme": "0.8.2-main.30e4dbb"
72
76
  },
73
77
  "publishConfig": {
74
78
  "access": "public"
@@ -2,12 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { pipe } from 'effect';
5
+ import { Schema, pipe } from 'effect';
6
6
 
7
7
  import { Capabilities, chain, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
8
8
  import { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';
9
9
  import { createArtifactElement } from '@dxos/assistant';
10
- import { isInstanceOf, S } from '@dxos/echo-schema';
10
+ import { isInstanceOf } from '@dxos/echo-schema';
11
11
  import { invariant } from '@dxos/invariant';
12
12
  import { SpaceAction } from '@dxos/plugin-space/types';
13
13
  import { Filter, fullyQualifiedId, type Space } from '@dxos/react-client/echo';
@@ -16,7 +16,7 @@ import { KanbanType } from '@dxos/react-ui-kanban';
16
16
  import { meta } from '../meta';
17
17
  import { KanbanAction } from '../types';
18
18
 
19
- const QualifiedId = S.String.annotations({
19
+ const QualifiedId = Schema.String.annotations({
20
20
  description: 'The fully qualified ID of the kanban `spaceID:objectID`',
21
21
  });
22
22
 
@@ -44,11 +44,11 @@ export default () => {
44
44
  Create a new kanban board using an existing schema.
45
45
  Use schema_create first to create a schema, or schema_list to choose an existing one.`,
46
46
  caption: 'Creating kanban board...',
47
- schema: S.Struct({
48
- typename: S.String.annotations({
47
+ schema: Schema.Struct({
48
+ typename: Schema.String.annotations({
49
49
  description: 'The fully qualified typename of the schema to use for the kanban cards.',
50
50
  }),
51
- pivotColumn: S.optional(S.String).annotations({
51
+ pivotColumn: Schema.optional(Schema.String).annotations({
52
52
  description: 'Optional field name to use as the column pivot.',
53
53
  }),
54
54
  }),
@@ -83,7 +83,7 @@ export default () => {
83
83
  name: 'list',
84
84
  description: 'List all kanban boards in the current space.',
85
85
  caption: 'Listing kanban boards...',
86
- schema: S.Struct({}),
86
+ schema: Schema.Struct({}),
87
87
  execute: async (_input, { extensions }) => {
88
88
  invariant(extensions?.space, 'No space');
89
89
  const space = extensions.space;
@@ -106,7 +106,7 @@ export default () => {
106
106
  name: 'inspect',
107
107
  description: 'Get details about a specific kanban board.',
108
108
  caption: 'Inspecting kanban board...',
109
- schema: S.Struct({ id: QualifiedId }),
109
+ schema: Schema.Struct({ id: QualifiedId }),
110
110
  execute: async ({ id }, { extensions }) => {
111
111
  invariant(extensions?.space, 'No space');
112
112
  const space = extensions.space;
@@ -2,21 +2,25 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { contributes, Capabilities, createResolver } from '@dxos/app-framework';
5
+ import { contributes, Capabilities, createResolver, type PluginsContext } from '@dxos/app-framework';
6
6
  import { invariant } from '@dxos/invariant';
7
+ import { ClientCapabilities } from '@dxos/plugin-client';
7
8
  import { getSpace } from '@dxos/react-client/echo';
8
9
  import { ViewProjection } from '@dxos/schema';
9
10
 
10
11
  import { KANBAN_PLUGIN } from '../meta';
11
- import { createKanban, KanbanAction } from '../types';
12
+ import { initializeKanban } from '../testing';
13
+ import { KanbanAction } from '../types';
12
14
 
13
- export default () =>
15
+ export default (context: PluginsContext) =>
14
16
  contributes(Capabilities.IntentResolver, [
15
17
  createResolver({
16
18
  intent: KanbanAction.Create,
17
- resolve: async ({ space, name, typename, initialPivotColumn }) => ({
18
- data: { object: await createKanban({ space, name, typename, initialPivotColumn }) },
19
- }),
19
+ resolve: async ({ space, name, typename, initialPivotColumn }) => {
20
+ const client = context.requestCapability(ClientCapabilities.Client);
21
+ const { kanban } = await initializeKanban({ client, space, name, typename, initialPivotColumn });
22
+ return { data: { object: kanban } };
23
+ },
20
24
  }),
21
25
  createResolver({
22
26
  intent: KanbanAction.DeleteCardField,
@@ -2,12 +2,15 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { type Schema } from 'effect';
5
6
  import React, { useMemo } from 'react';
6
7
 
7
- import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
8
- import { type S } from '@dxos/echo-schema';
8
+ import { Capabilities, contributes, createSurface, useCapabilities } from '@dxos/app-framework';
9
+ import { getTypenameOrThrow, toJsonSchema } from '@dxos/echo-schema';
9
10
  import { findAnnotation } from '@dxos/effect';
11
+ import { ClientCapabilities } from '@dxos/plugin-client';
10
12
  import { type CollectionType } from '@dxos/plugin-space/types';
13
+ import { useClient } from '@dxos/react-client';
11
14
  import { getSpace, isSpace, type Space } from '@dxos/react-client/echo';
12
15
  import { type InputProps, SelectInput, useFormValues } from '@dxos/react-ui-form';
13
16
  import { type KanbanType } from '@dxos/react-ui-kanban';
@@ -31,28 +34,53 @@ export default () =>
31
34
  component: ({ data }) => <KanbanViewEditor kanban={data.subject} />,
32
35
  }),
33
36
  createSurface({
34
- id: `${KANBAN_PLUGIN}/create-initial-schema-form-[schema]`,
37
+ id: `${KANBAN_PLUGIN}/create-initial-schema-form`,
35
38
  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, TypenameAnnotationId);
39
+ filter: (
40
+ data,
41
+ ): data is { prop: string; schema: Schema.Schema<any>; target: Space | CollectionType | undefined } => {
42
+ if (data.prop !== 'typename') {
43
+ return false;
44
+ }
45
+
46
+ const annotation = findAnnotation<boolean>((data.schema as Schema.Schema.All).ast, TypenameAnnotationId);
38
47
  return !!annotation;
39
48
  },
40
49
  component: ({ data: { target }, ...inputProps }) => {
50
+ const client = useClient();
41
51
  const props = inputProps as any as InputProps;
42
52
  const space = isSpace(target) ? target : getSpace(target);
43
53
  if (!space) {
44
54
  return null;
45
55
  }
46
56
 
47
- const schemata = space?.db.schemaRegistry.query().runSync();
48
- return <SelectInput {...props} options={schemata.map((schema) => ({ value: schema.typename }))} />;
57
+ const schemaWhitelists = useCapabilities(ClientCapabilities.SchemaWhiteList);
58
+ const whitelistedTypenames = useMemo(
59
+ () => new Set(schemaWhitelists.flatMap((typeArray) => typeArray.map((type) => type.typename))),
60
+ [schemaWhitelists],
61
+ );
62
+
63
+ const fixed = client.graph.schemaRegistry.schemas.filter((schema) =>
64
+ whitelistedTypenames.has(getTypenameOrThrow(schema)),
65
+ );
66
+ const dynamic = space?.db.schemaRegistry.query().runSync();
67
+ const typenames = Array.from(
68
+ new Set<string>([
69
+ ...fixed.map((schema) => getTypenameOrThrow(schema)),
70
+ ...dynamic.map((schema) => schema.typename),
71
+ ]),
72
+ ).sort();
73
+
74
+ return <SelectInput {...props} options={typenames.map((typename) => ({ value: typename }))} />;
49
75
  },
50
76
  }),
51
77
  createSurface({
52
78
  id: `${KANBAN_PLUGIN}/create-initial-schema-form-[pivot-column]`,
53
79
  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, PivotColumnAnnotationId);
80
+ filter: (
81
+ data,
82
+ ): data is { prop: string; schema: Schema.Schema<any>; target: Space | CollectionType | undefined } => {
83
+ const annotation = findAnnotation<boolean>((data.schema as Schema.Schema.All).ast, PivotColumnAnnotationId);
56
84
  return !!annotation;
57
85
  },
58
86
  component: ({ data: { target }, ...inputProps }) => {
@@ -62,14 +90,20 @@ export default () =>
62
90
  return null;
63
91
  }
64
92
  const { typename } = useFormValues();
93
+ // TODO(wittjosiah): Unify this schema lookup.
94
+ const schemaWhitelists = useCapabilities(ClientCapabilities.SchemaWhiteList);
95
+ const staticSchema = schemaWhitelists.flat().find((schema) => getTypenameOrThrow(schema) === typename);
65
96
  const [selectedSchema] = space?.db.schemaRegistry.query({ typename }).runSync();
66
97
 
67
98
  const singleSelectColumns = useMemo(() => {
68
- if (!selectedSchema?.jsonSchema?.properties) {
99
+ const properties = staticSchema
100
+ ? toJsonSchema(staticSchema).properties
101
+ : selectedSchema?.jsonSchema?.properties;
102
+ if (!properties) {
69
103
  return [];
70
104
  }
71
105
 
72
- const columns = Object.entries(selectedSchema.jsonSchema.properties).reduce<string[]>((acc, [key, value]) => {
106
+ const columns = Object.entries(properties).reduce<string[]>((acc, [key, value]) => {
73
107
  if (typeof value === 'object' && value?.format === 'single-select') {
74
108
  acc.push(key);
75
109
  }
@@ -77,7 +111,7 @@ export default () =>
77
111
  }, []);
78
112
 
79
113
  return columns;
80
- }, [selectedSchema?.jsonSchema]);
114
+ }, [selectedSchema?.jsonSchema, staticSchema]);
81
115
 
82
116
  if (!typename) {
83
117
  return null;
@@ -0,0 +1,186 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+ import { type StoryObj, type Meta } from '@storybook/react';
7
+ import React, { useCallback, useEffect, useState } from 'react';
8
+
9
+ import { IntentPlugin, SettingsPlugin } from '@dxos/app-framework';
10
+ import { withPluginManager } from '@dxos/app-framework/testing';
11
+ import { ClientPlugin } from '@dxos/plugin-client';
12
+ import { PreviewPlugin } from '@dxos/plugin-preview';
13
+ import { useGlobalFilteredObjects } from '@dxos/plugin-search';
14
+ import { SpacePlugin } from '@dxos/plugin-space';
15
+ import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
16
+ import { ThemePlugin } from '@dxos/plugin-theme';
17
+ import { faker } from '@dxos/random';
18
+ import { useClient } from '@dxos/react-client';
19
+ import { Filter, useSpaces, useQuery, useSchema, live } from '@dxos/react-client/echo';
20
+ import { ViewEditor } from '@dxos/react-ui-form';
21
+ import { Kanban, KanbanType, useKanbanModel } from '@dxos/react-ui-kanban';
22
+ import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
23
+ import { defaultTx } from '@dxos/react-ui-theme';
24
+ import { DataType, ViewProjection } from '@dxos/schema';
25
+ import { withLayout } from '@dxos/storybook-utils';
26
+
27
+ import { initializeKanban } from '../testing';
28
+ import translations from '../translations';
29
+
30
+ faker.seed(0);
31
+
32
+ //
33
+ // Story components.
34
+ //
35
+
36
+ const rollOrg = () => ({
37
+ name: faker.commerce.productName(),
38
+ description: faker.lorem.paragraph(),
39
+ image: faker.image.url(),
40
+ website: faker.internet.url(),
41
+ status: faker.helpers.arrayElement(DataType.OrganizationStatusOptions).id,
42
+ });
43
+
44
+ const StorybookKanban = () => {
45
+ const client = useClient();
46
+ const spaces = useSpaces();
47
+ const space = spaces[spaces.length - 1];
48
+ const kanbans = useQuery(space, Filter.schema(KanbanType));
49
+ const [kanban, setKanban] = useState<KanbanType>();
50
+ const [projection, setProjection] = useState<ViewProjection>();
51
+ const schema = useSchema(client, space, kanban?.cardView?.target?.query.typename);
52
+
53
+ useEffect(() => {
54
+ if (kanbans.length && !kanban) {
55
+ const kanban = kanbans[0];
56
+ setKanban(kanban);
57
+ }
58
+ }, [kanbans]);
59
+
60
+ useEffect(() => {
61
+ if (kanban?.cardView?.target && schema) {
62
+ setProjection(new ViewProjection(schema.jsonSchema, kanban.cardView.target));
63
+ }
64
+ // TODO(ZaymonFC): Is there a better way to get notified about deep changes in the json schema?
65
+ }, [kanban?.cardView?.target, schema, JSON.stringify(schema?.jsonSchema)]);
66
+
67
+ const objects = useQuery(space, schema ? Filter.schema(schema) : Filter.nothing());
68
+ const filteredObjects = useGlobalFilteredObjects(objects);
69
+
70
+ const model = useKanbanModel({
71
+ kanban,
72
+ schema,
73
+ projection,
74
+ items: filteredObjects,
75
+ });
76
+
77
+ const handleAddCard = useCallback(
78
+ (columnValue: string | undefined) => {
79
+ const path = model?.columnFieldPath;
80
+ if (space && schema && path) {
81
+ const card = live(schema, {
82
+ ...rollOrg(),
83
+ [path]: columnValue,
84
+ });
85
+
86
+ space.db.add(card);
87
+ return card.id;
88
+ }
89
+ },
90
+ [space, schema, model],
91
+ );
92
+
93
+ const handleRemoveCard = useCallback((card: { id: string }) => space.db.remove(card), [space]);
94
+
95
+ const handleTypenameChanged = useCallback(
96
+ (typename: string) => {
97
+ if (kanban?.cardView?.target) {
98
+ schema?.mutable.updateTypename(typename);
99
+ kanban.cardView.target.query.typename = typename;
100
+ }
101
+ },
102
+ [kanban?.cardView?.target, schema],
103
+ );
104
+
105
+ if (!schema || !kanban) {
106
+ return null;
107
+ }
108
+
109
+ return (
110
+ <div className='grow grid grid-cols-[1fr_350px]'>
111
+ {model ? <Kanban model={model} onAddCard={handleAddCard} onRemoveCard={handleRemoveCard} /> : <div />}
112
+ <div className='flex flex-col bs-full border-is border-separator overflow-y-auto'>
113
+ {kanban.cardView && (
114
+ <ViewEditor
115
+ registry={space?.db.schemaRegistry}
116
+ schema={schema}
117
+ view={kanban.cardView.target!}
118
+ onTypenameChanged={handleTypenameChanged}
119
+ onDelete={(fieldId: string) => {
120
+ console.log('[ViewEditor]', 'onDelete', fieldId);
121
+ }}
122
+ />
123
+ )}
124
+ <SyntaxHighlighter language='json' className='w-full text-xs'>
125
+ {JSON.stringify({ cardView: kanban.cardView?.target, cardSchema: schema }, null, 2)}
126
+ </SyntaxHighlighter>
127
+ </div>
128
+ </div>
129
+ );
130
+ };
131
+
132
+ type StoryProps = {
133
+ rows?: number;
134
+ };
135
+
136
+ //
137
+ // Story definitions.
138
+ //
139
+
140
+ const meta: Meta<StoryProps> = {
141
+ title: 'ui/plugin-kanban/Kanban',
142
+ component: StorybookKanban,
143
+ render: () => <StorybookKanban />,
144
+ parameters: { translations },
145
+ decorators: [
146
+ withLayout({ fullscreen: true }),
147
+ withPluginManager({
148
+ plugins: [
149
+ ThemePlugin({ tx: defaultTx }),
150
+ ClientPlugin({
151
+ types: [DataType.Organization, DataType.Person, KanbanType],
152
+ onClientInitialized: async (_, client) => {
153
+ await client.halo.createIdentity();
154
+ const space = await client.spaces.create();
155
+ await space.waitUntilReady();
156
+ const { schema, kanban } = await initializeKanban({
157
+ space,
158
+ client,
159
+ typename: DataType.Organization.typename,
160
+ initialPivotColumn: 'status',
161
+ });
162
+ space.db.add(kanban);
163
+
164
+ if (schema) {
165
+ // TODO(burdon): Replace with sdk/schema/testing.
166
+ Array.from({ length: 80 }).map(() => {
167
+ return space.db.add(live(schema, rollOrg()));
168
+ });
169
+ }
170
+ },
171
+ }),
172
+ StorybookLayoutPlugin(),
173
+ PreviewPlugin(),
174
+ SpacePlugin(),
175
+ IntentPlugin(),
176
+ SettingsPlugin(),
177
+ ],
178
+ }),
179
+ ],
180
+ };
181
+
182
+ export default meta;
183
+
184
+ type Story = StoryObj<StoryProps>;
185
+
186
+ export const Default: Story = {};
@@ -2,11 +2,12 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import React, { useCallback, useEffect, useState } from 'react';
5
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
6
6
 
7
7
  import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
8
- import { type EchoSchema } from '@dxos/echo-schema';
8
+ import { EchoSchema, getTypenameOrThrow, toJsonSchema, type TypedObject } from '@dxos/echo-schema';
9
9
  import { useGlobalFilteredObjects } from '@dxos/plugin-search';
10
+ import { useClient } from '@dxos/react-client';
10
11
  import { Filter, useQuery, getSpace, live } from '@dxos/react-client/echo';
11
12
  import { type KanbanType, useKanbanModel, Kanban } from '@dxos/react-ui-kanban';
12
13
  import { StackItem } from '@dxos/react-ui-stack';
@@ -15,14 +16,26 @@ import { ViewProjection } from '@dxos/schema';
15
16
  import { KanbanAction } from '../types';
16
17
 
17
18
  export const KanbanContainer = ({ kanban }: { kanban: KanbanType; role: string }) => {
18
- const [cardSchema, setCardSchema] = useState<EchoSchema>();
19
+ const client = useClient();
20
+ const [cardSchema, setCardSchema] = useState<TypedObject<any, any>>();
19
21
  const [projection, setProjection] = useState<ViewProjection>();
20
22
  const space = getSpace(kanban);
21
23
  const { dispatchPromise: dispatch } = useIntentDispatcher();
22
24
 
25
+ const jsonSchema = useMemo(
26
+ () =>
27
+ cardSchema instanceof EchoSchema ? cardSchema.jsonSchema : cardSchema ? toJsonSchema(cardSchema) : undefined,
28
+ [cardSchema],
29
+ );
30
+
23
31
  useEffect(() => {
24
- if (kanban.cardView?.target?.query?.typename && space) {
25
- const query = space.db.schemaRegistry.query({ typename: kanban.cardView.target.query.typename });
32
+ const typename = kanban.cardView?.target?.query?.typename;
33
+ const staticSchema = client.graph.schemaRegistry.schemas.find((schema) => getTypenameOrThrow(schema) === typename);
34
+ if (staticSchema) {
35
+ setCardSchema(() => staticSchema as TypedObject<any, any>);
36
+ }
37
+ if (!staticSchema && typename && space) {
38
+ const query = space.db.schemaRegistry.query({ typename });
26
39
  const unsubscribe = query.subscribe(
27
40
  () => {
28
41
  const [schema] = query.results;
@@ -37,11 +50,11 @@ export const KanbanContainer = ({ kanban }: { kanban: KanbanType; role: string }
37
50
  }, [kanban.cardView?.target?.query, space]);
38
51
 
39
52
  useEffect(() => {
40
- if (kanban.cardView?.target && cardSchema) {
41
- setProjection(new ViewProjection(cardSchema.jsonSchema, kanban.cardView.target));
53
+ if (kanban.cardView?.target && jsonSchema) {
54
+ setProjection(new ViewProjection(jsonSchema, kanban.cardView.target));
42
55
  }
43
56
  // 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)]);
57
+ }, [kanban.cardView?.target, JSON.stringify(jsonSchema)]);
45
58
 
46
59
  const objects = useQuery(space, cardSchema ? Filter.schema(cardSchema) : Filter.nothing());
47
60
  const filteredObjects = useGlobalFilteredObjects(objects);
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './kanban-manager';
6
+ export * from './initialize-kanban';
@@ -0,0 +1,139 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Schema, SchemaAST } from 'effect';
6
+
7
+ import {
8
+ TypedObject,
9
+ FormatEnum,
10
+ TypeEnum,
11
+ type JsonProp,
12
+ type EchoSchema,
13
+ getTypenameOrThrow,
14
+ toJsonSchema,
15
+ } from '@dxos/echo-schema';
16
+ import { invariant } from '@dxos/invariant';
17
+ import { type Client, PublicKey } from '@dxos/react-client';
18
+ import { type Space, live, makeRef } from '@dxos/react-client/echo';
19
+ import { KanbanType } from '@dxos/react-ui-kanban';
20
+ import { createView, ViewProjection, createFieldId, getSchemaProperties } from '@dxos/schema';
21
+ import { capitalize } from '@dxos/util';
22
+
23
+ // TODO(wittjosiah): UI package shouldn't depend on client.
24
+
25
+ type InitializeKanbanProps = {
26
+ client: Client;
27
+ space: Space;
28
+ name?: string;
29
+ typename?: string;
30
+ initialPivotColumn?: string;
31
+ };
32
+
33
+ const createDefaultTaskSchema = () => {
34
+ const stateOptions = [
35
+ { id: PublicKey.random().truncate(), title: 'Draft', color: 'indigo' },
36
+ { id: PublicKey.random().truncate(), title: 'Active', color: 'cyan' },
37
+ { id: PublicKey.random().truncate(), title: 'Completed', color: 'emerald' },
38
+ ];
39
+
40
+ const schema = TypedObject({
41
+ typename: `example.com/type/${PublicKey.random().truncate()}`,
42
+ version: '0.1.0',
43
+ })({
44
+ title: Schema.optional(Schema.String).annotations({
45
+ [SchemaAST.TitleAnnotationId]: 'Title',
46
+ }),
47
+ description: Schema.optional(Schema.String).annotations({
48
+ [SchemaAST.TitleAnnotationId]: 'Description',
49
+ }),
50
+ state: Schema.optional(Schema.String),
51
+ });
52
+
53
+ return { schema, stateOptions };
54
+ };
55
+
56
+ export const initializeKanban = async ({
57
+ client,
58
+ space,
59
+ name,
60
+ typename,
61
+ initialPivotColumn,
62
+ }: InitializeKanbanProps): Promise<{ kanban: KanbanType; schema?: EchoSchema }> => {
63
+ if (typename) {
64
+ const staticSchema = client.graph.schemaRegistry.schemas.find((schema) => getTypenameOrThrow(schema) === typename);
65
+ const schema = await space.db.schemaRegistry.query({ typename }).firstOrUndefined();
66
+
67
+ const ast = staticSchema?.ast ?? schema?.ast;
68
+ const jsonSchema = staticSchema ? toJsonSchema(staticSchema) : schema?.jsonSchema;
69
+ invariant(ast, `Schema not found: ${typename}`);
70
+ invariant(jsonSchema, `Schema not found: ${typename}`);
71
+
72
+ const fields = getSchemaProperties(ast)
73
+ .filter((prop) => prop.type !== 'object' || prop.format === FormatEnum.Ref)
74
+ .map((prop) => prop.name);
75
+
76
+ const view = createView({
77
+ name: "Kanban's card view",
78
+ typename,
79
+ jsonSchema,
80
+ fields,
81
+ });
82
+
83
+ const kanban = live(KanbanType, { cardView: makeRef(view), columnFieldId: undefined, name });
84
+ if (initialPivotColumn) {
85
+ const viewProjection = new ViewProjection(jsonSchema, view);
86
+ const fieldId = viewProjection.getFieldId(initialPivotColumn);
87
+ if (fieldId) {
88
+ kanban.columnFieldId = fieldId;
89
+ }
90
+ }
91
+ return { kanban, schema };
92
+ } else {
93
+ const { schema: taskSchema, stateOptions } = createDefaultTaskSchema();
94
+ const [schema] = await space.db.schemaRegistry.register([taskSchema]);
95
+
96
+ const view = createView({
97
+ name: "Kanban's card view",
98
+ typename: schema.typename,
99
+ jsonSchema: schema.jsonSchema,
100
+ fields: ['title', 'description'],
101
+ });
102
+
103
+ const viewProjection = new ViewProjection(schema.jsonSchema, view);
104
+
105
+ // Set description field to Markdown format.
106
+ const descriptionFieldId = viewProjection.getFieldId('description');
107
+ if (descriptionFieldId) {
108
+ const fieldProjection = viewProjection.getFieldProjection(descriptionFieldId);
109
+ if (fieldProjection) {
110
+ viewProjection.setFieldProjection({
111
+ ...fieldProjection,
112
+ props: { ...fieldProjection.props, format: FormatEnum.Markdown },
113
+ });
114
+ }
115
+ }
116
+
117
+ const initialPivotField = 'state';
118
+ viewProjection.setFieldProjection({
119
+ field: {
120
+ id: createFieldId(),
121
+ path: initialPivotField as JsonProp,
122
+ size: 150,
123
+ },
124
+ props: {
125
+ property: initialPivotField as JsonProp,
126
+ type: TypeEnum.String,
127
+ format: FormatEnum.SingleSelect,
128
+ title: capitalize(initialPivotField),
129
+ options: stateOptions,
130
+ },
131
+ });
132
+
133
+ const fieldId = viewProjection.getFieldId(initialPivotField);
134
+ invariant(fieldId);
135
+
136
+ const kanban = live(KanbanType, { cardView: makeRef(view), columnFieldId: fieldId });
137
+ return { kanban, schema };
138
+ }
139
+ };