@dxos/plugin-kanban 0.8.2-main.f081794 → 0.8.2-main.fbd8ed0

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 (84) hide show
  1. package/dist/lib/browser/{artifact-definition-SVNHDJQT.mjs → artifact-definition-HABFQLG4.mjs} +12 -12
  2. package/dist/lib/browser/artifact-definition-HABFQLG4.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-G6H6HZRG.mjs +297 -0
  7. package/dist/lib/browser/intent-resolver-G6H6HZRG.mjs.map +7 -0
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/{react-surface-R25PYWQV.mjs → react-surface-BIBGD5OD.mjs} +67 -35
  10. package/dist/lib/browser/react-surface-BIBGD5OD.mjs.map +7 -0
  11. package/dist/lib/browser/types.mjs +1 -3
  12. package/dist/lib/node/{artifact-definition-M2XAYUI2.cjs → artifact-definition-M57SFWWP.cjs} +19 -19
  13. package/dist/lib/node/artifact-definition-M57SFWWP.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-IBMSLMHX.cjs +308 -0
  18. package/dist/lib/node/intent-resolver-IBMSLMHX.cjs.map +7 -0
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/{react-surface-FVM64YAQ.cjs → react-surface-ZABOI7UC.cjs} +74 -42
  21. package/dist/lib/node/react-surface-ZABOI7UC.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-OLVK4DCO.mjs} +12 -12
  25. package/dist/lib/node-esm/artifact-definition-OLVK4DCO.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-X66YN6H5.mjs +298 -0
  30. package/dist/lib/node-esm/intent-resolver-X66YN6H5.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-LDR423Y7.mjs} +67 -35
  33. package/dist/lib/node-esm/react-surface-LDR423Y7.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 +30 -25
  58. package/src/capabilities/artifact-definition.ts +10 -10
  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 +191 -0
  62. package/src/components/KanbanContainer.tsx +22 -9
  63. package/src/components/KanbanViewEditor.tsx +9 -7
  64. package/src/testing/index.ts +6 -0
  65. package/src/testing/initialize-kanban.ts +139 -0
  66. package/src/testing/kanban-manager.ts +13 -0
  67. package/src/testing/playwright/playwright.config.cts +18 -0
  68. package/src/testing/playwright/smoke.spec.ts +7 -0
  69. package/src/types.ts +26 -43
  70. package/dist/lib/browser/artifact-definition-SVNHDJQT.mjs.map +0 -7
  71. package/dist/lib/browser/chunk-K5BYEZ4Z.mjs.map +0 -7
  72. package/dist/lib/browser/intent-resolver-XCDQ5N3Q.mjs +0 -132
  73. package/dist/lib/browser/intent-resolver-XCDQ5N3Q.mjs.map +0 -7
  74. package/dist/lib/browser/react-surface-R25PYWQV.mjs.map +0 -7
  75. package/dist/lib/node/artifact-definition-M2XAYUI2.cjs.map +0 -7
  76. package/dist/lib/node/chunk-3EUR6ZR2.cjs.map +0 -7
  77. package/dist/lib/node/intent-resolver-P3PSZO7H.cjs +0 -146
  78. package/dist/lib/node/intent-resolver-P3PSZO7H.cjs.map +0 -7
  79. package/dist/lib/node/react-surface-FVM64YAQ.cjs.map +0 -7
  80. package/dist/lib/node-esm/artifact-definition-HQ5I2OO5.mjs.map +0 -7
  81. package/dist/lib/node-esm/chunk-2N7CO3DI.mjs.map +0 -7
  82. package/dist/lib/node-esm/intent-resolver-4G47V67J.mjs +0 -133
  83. package/dist/lib/node-esm/intent-resolver-4G47V67J.mjs.map +0 -7
  84. 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.f081794",
3
+ "version": "0.8.2-main.fbd8ed0",
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,26 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@preact/signals-core": "^1.6.0",
37
- "@dxos/artifact": "0.8.2-main.f081794",
38
- "@dxos/app-framework": "0.8.2-main.f081794",
39
- "@dxos/assistant": "0.8.2-main.f081794",
40
- "@dxos/echo-schema": "0.8.2-main.f081794",
41
- "@dxos/async": "0.8.2-main.f081794",
42
- "@dxos/effect": "0.8.2-main.f081794",
43
- "@dxos/plugin-graph": "0.8.2-main.f081794",
44
- "@dxos/plugin-search": "0.8.2-main.f081794",
45
- "@dxos/plugin-client": "0.8.2-main.f081794",
46
- "@dxos/plugin-space": "0.8.2-main.f081794",
47
- "@dxos/invariant": "0.8.2-main.f081794",
48
- "@dxos/random": "0.8.2-main.f081794",
49
- "@dxos/react-client": "0.8.2-main.f081794",
50
- "@dxos/react-ui-form": "0.8.2-main.f081794",
51
- "@dxos/react-ui-kanban": "0.8.2-main.f081794",
52
- "@dxos/react-ui-stack": "0.8.2-main.f081794",
53
- "@dxos/util": "0.8.2-main.f081794",
54
- "@dxos/schema": "0.8.2-main.f081794"
37
+ "effect": "3.14.21",
38
+ "@dxos/app-framework": "0.8.2-main.fbd8ed0",
39
+ "@dxos/assistant": "0.8.2-main.fbd8ed0",
40
+ "@dxos/artifact": "0.8.2-main.fbd8ed0",
41
+ "@dxos/echo": "0.8.2-main.fbd8ed0",
42
+ "@dxos/effect": "0.8.2-main.fbd8ed0",
43
+ "@dxos/async": "0.8.2-main.fbd8ed0",
44
+ "@dxos/invariant": "0.8.2-main.fbd8ed0",
45
+ "@dxos/plugin-client": "0.8.2-main.fbd8ed0",
46
+ "@dxos/plugin-graph": "0.8.2-main.fbd8ed0",
47
+ "@dxos/echo-schema": "0.8.2-main.fbd8ed0",
48
+ "@dxos/plugin-search": "0.8.2-main.fbd8ed0",
49
+ "@dxos/react-client": "0.8.2-main.fbd8ed0",
50
+ "@dxos/plugin-space": "0.8.2-main.fbd8ed0",
51
+ "@dxos/random": "0.8.2-main.fbd8ed0",
52
+ "@dxos/react-ui-form": "0.8.2-main.fbd8ed0",
53
+ "@dxos/react-ui-kanban": "0.8.2-main.fbd8ed0",
54
+ "@dxos/react-ui-stack": "0.8.2-main.fbd8ed0",
55
+ "@dxos/schema": "0.8.2-main.fbd8ed0",
56
+ "@dxos/util": "0.8.2-main.fbd8ed0"
55
57
  },
56
58
  "devDependencies": {
57
59
  "@types/react": "~18.2.0",
@@ -59,16 +61,19 @@
59
61
  "react": "~18.2.0",
60
62
  "react-dom": "~18.2.0",
61
63
  "vite": "5.4.7",
62
- "@dxos/react-ui": "0.8.2-main.f081794",
63
- "@dxos/react-ui-theme": "0.8.2-main.f081794",
64
- "@dxos/storybook-utils": "0.8.2-main.f081794"
64
+ "@dxos/plugin-theme": "0.8.2-main.fbd8ed0",
65
+ "@dxos/plugin-preview": "0.8.2-main.fbd8ed0",
66
+ "@dxos/react-ui-syntax-highlighter": "0.8.2-main.fbd8ed0",
67
+ "@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
68
+ "@dxos/storybook-utils": "0.8.2-main.fbd8ed0",
69
+ "@dxos/react-ui": "0.8.2-main.fbd8ed0"
65
70
  },
66
71
  "peerDependencies": {
67
- "effect": "3.13.3",
72
+ "effect": "^3.13.3",
68
73
  "react": "~18.2.0",
69
74
  "react-dom": "~18.2.0",
70
- "@dxos/react-ui": "0.8.2-main.f081794",
71
- "@dxos/react-ui-theme": "0.8.2-main.f081794"
75
+ "@dxos/react-ui": "0.8.2-main.fbd8ed0",
76
+ "@dxos/react-ui-theme": "0.8.2-main.fbd8ed0"
72
77
  },
73
78
  "publishConfig": {
74
79
  "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,11 +83,11 @@ 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;
90
- const { objects: boards } = await space.db.query(Filter.schema(KanbanType)).run();
90
+ const { objects: boards } = await space.db.query(Filter.type(KanbanType)).run();
91
91
 
92
92
  const boardInfo = await Promise.all(
93
93
  boards.map(async (board: KanbanType) => {
@@ -106,11 +106,11 @@ 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;
113
- const { objects: boards } = await space.db.query(Filter.schema(KanbanType)).run();
113
+ const { objects: boards } = await space.db.query(Filter.type(KanbanType)).run();
114
114
  const board = boards.find((board: KanbanType) => fullyQualifiedId(board) === id);
115
115
  invariant(isInstanceOf(KanbanType, board));
116
116
 
@@ -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 PluginContext } 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: PluginContext) =>
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.getCapability(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,191 @@
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 { Type } from '@dxos/echo';
12
+ import { assertEchoSchema } from '@dxos/echo-schema';
13
+ import { invariant } from '@dxos/invariant';
14
+ import { ClientPlugin } from '@dxos/plugin-client';
15
+ import { PreviewPlugin } from '@dxos/plugin-preview';
16
+ import { useGlobalFilteredObjects } from '@dxos/plugin-search';
17
+ import { SpacePlugin } from '@dxos/plugin-space';
18
+ import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
19
+ import { ThemePlugin } from '@dxos/plugin-theme';
20
+ import { faker } from '@dxos/random';
21
+ import { useClient } from '@dxos/react-client';
22
+ import { Filter, useSpaces, useQuery, useSchema, live } from '@dxos/react-client/echo';
23
+ import { ViewEditor } from '@dxos/react-ui-form';
24
+ import { Kanban, KanbanType, useKanbanModel } from '@dxos/react-ui-kanban';
25
+ import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
26
+ import { defaultTx } from '@dxos/react-ui-theme';
27
+ import { DataType, ViewProjection } from '@dxos/schema';
28
+ import { withLayout } from '@dxos/storybook-utils';
29
+
30
+ import { initializeKanban } from '../testing';
31
+ import translations from '../translations';
32
+
33
+ faker.seed(0);
34
+
35
+ //
36
+ // Story components.
37
+ //
38
+
39
+ const rollOrg = () => ({
40
+ name: faker.commerce.productName(),
41
+ description: faker.lorem.paragraph(),
42
+ image: faker.image.url(),
43
+ website: faker.internet.url(),
44
+ status: faker.helpers.arrayElement(DataType.OrganizationStatusOptions).id,
45
+ });
46
+
47
+ const StorybookKanban = () => {
48
+ const client = useClient();
49
+ const spaces = useSpaces();
50
+ const space = spaces[spaces.length - 1];
51
+ const kanbans = useQuery(space, Filter.type(KanbanType));
52
+ const [kanban, setKanban] = useState<KanbanType>();
53
+ const [projection, setProjection] = useState<ViewProjection>();
54
+ const schema = useSchema(client, space, kanban?.cardView?.target?.query.typename);
55
+
56
+ useEffect(() => {
57
+ if (kanbans.length && !kanban) {
58
+ const kanban = kanbans[0];
59
+ setKanban(kanban);
60
+ }
61
+ }, [kanbans]);
62
+
63
+ useEffect(() => {
64
+ if (kanban?.cardView?.target && schema) {
65
+ const jsonSchema = Type.toJsonSchema(schema);
66
+ setProjection(new ViewProjection(jsonSchema, kanban.cardView.target));
67
+ }
68
+ // TODO(ZaymonFC): Is there a better way to get notified about deep changes in the json schema?
69
+ // @dmaretskyi? Once resolved, update in multiple places (e.g., storybooks).
70
+ }, [kanban?.cardView?.target, schema, JSON.stringify(schema ? Type.toJsonSchema(schema) : {})]);
71
+
72
+ const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
73
+ const filteredObjects = useGlobalFilteredObjects(objects);
74
+
75
+ const model = useKanbanModel({
76
+ kanban,
77
+ schema,
78
+ projection,
79
+ items: filteredObjects,
80
+ });
81
+
82
+ const handleAddCard = useCallback(
83
+ (columnValue: string | undefined) => {
84
+ const path = model?.columnFieldPath;
85
+ if (space && schema && path) {
86
+ const card = live(schema, {
87
+ ...rollOrg(),
88
+ [path]: columnValue,
89
+ });
90
+
91
+ space.db.add(card);
92
+ return card.id;
93
+ }
94
+ },
95
+ [space, schema, model],
96
+ );
97
+
98
+ const handleRemoveCard = useCallback((card: { id: string }) => space.db.remove(card), [space]);
99
+
100
+ const handleTypenameChanged = useCallback(
101
+ (typename: string) => {
102
+ invariant(schema);
103
+ invariant(kanban?.cardView?.target);
104
+ assertEchoSchema(schema).updateTypename(typename);
105
+ kanban.cardView.target.query.typename = typename;
106
+ },
107
+ [kanban?.cardView?.target, schema],
108
+ );
109
+
110
+ if (!schema || !kanban) {
111
+ return null;
112
+ }
113
+
114
+ return (
115
+ <div className='grow grid grid-cols-[1fr_350px]'>
116
+ {model ? <Kanban model={model} onAddCard={handleAddCard} onRemoveCard={handleRemoveCard} /> : <div />}
117
+ <div className='flex flex-col bs-full border-is border-separator overflow-y-auto'>
118
+ {kanban.cardView && (
119
+ <ViewEditor
120
+ registry={space?.db.schemaRegistry}
121
+ schema={schema}
122
+ view={kanban.cardView.target!}
123
+ onTypenameChanged={handleTypenameChanged}
124
+ onDelete={(fieldId: string) => {
125
+ console.log('[ViewEditor]', 'onDelete', fieldId);
126
+ }}
127
+ />
128
+ )}
129
+ <SyntaxHighlighter language='json' className='w-full text-xs'>
130
+ {JSON.stringify({ cardView: kanban.cardView?.target, cardSchema: schema }, null, 2)}
131
+ </SyntaxHighlighter>
132
+ </div>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ type StoryProps = {
138
+ rows?: number;
139
+ };
140
+
141
+ //
142
+ // Story definitions.
143
+ //
144
+
145
+ const meta: Meta<StoryProps> = {
146
+ title: 'ui/plugin-kanban/Kanban',
147
+ component: StorybookKanban,
148
+ render: () => <StorybookKanban />,
149
+ parameters: { translations },
150
+ decorators: [
151
+ withLayout({ fullscreen: true }),
152
+ withPluginManager({
153
+ plugins: [
154
+ ThemePlugin({ tx: defaultTx }),
155
+ ClientPlugin({
156
+ types: [DataType.Organization, DataType.Person, KanbanType],
157
+ onClientInitialized: async (_, client) => {
158
+ await client.halo.createIdentity();
159
+ const space = await client.spaces.create();
160
+ await space.waitUntilReady();
161
+ const { schema, kanban } = await initializeKanban({
162
+ space,
163
+ client,
164
+ typename: DataType.Organization.typename,
165
+ initialPivotColumn: 'status',
166
+ });
167
+ space.db.add(kanban);
168
+
169
+ if (schema) {
170
+ // TODO(burdon): Replace with sdk/schema/testing.
171
+ Array.from({ length: 80 }).map(() => {
172
+ return space.db.add(live(schema, rollOrg()));
173
+ });
174
+ }
175
+ },
176
+ }),
177
+ StorybookLayoutPlugin(),
178
+ PreviewPlugin(),
179
+ SpacePlugin(),
180
+ IntentPlugin(),
181
+ SettingsPlugin(),
182
+ ],
183
+ }),
184
+ ],
185
+ };
186
+
187
+ export default meta;
188
+
189
+ type Story = StoryObj<StoryProps>;
190
+
191
+ 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,13 +50,13 @@ 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
- const objects = useQuery(space, cardSchema ? Filter.schema(cardSchema) : Filter.nothing());
59
+ const objects = useQuery(space, cardSchema ? Filter.type(cardSchema) : Filter.nothing());
47
60
  const filteredObjects = useGlobalFilteredObjects(objects);
48
61
 
49
62
  const model = useKanbanModel({
@@ -5,7 +5,8 @@
5
5
  import React, { useCallback, useMemo } from 'react';
6
6
 
7
7
  import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
8
- import { FormatEnum } from '@dxos/echo-schema';
8
+ import { Type } from '@dxos/echo';
9
+ import { assertEchoSchema, FormatEnum, isMutable } from '@dxos/echo-schema';
9
10
  import { invariant } from '@dxos/invariant';
10
11
  import { useClient } from '@dxos/react-client';
11
12
  import { Filter, getSpace, useQuery, useSchema } from '@dxos/react-client/echo';
@@ -26,7 +27,7 @@ export const KanbanViewEditor = ({ kanban }: KanbanViewEditorProps) => {
26
27
  [kanban?.cardView?.target?.query?.typename],
27
28
  );
28
29
  const schema = useSchema(client, space, currentTypename);
29
- const views = useQuery(space, Filter.schema(ViewType));
30
+ const views = useQuery(space, Filter.type(ViewType));
30
31
 
31
32
  const handleUpdateTypename = useCallback(
32
33
  (newTypename: string) => {
@@ -36,7 +37,7 @@ export const KanbanViewEditor = ({ kanban }: KanbanViewEditorProps) => {
36
37
  view.query.typename = newTypename;
37
38
  }
38
39
 
39
- schema.mutable.updateTypename(newTypename);
40
+ assertEchoSchema(schema).updateTypename(newTypename);
40
41
  },
41
42
  [views, schema],
42
43
  );
@@ -50,9 +51,10 @@ export const KanbanViewEditor = ({ kanban }: KanbanViewEditorProps) => {
50
51
 
51
52
  const projection = useMemo(() => {
52
53
  if (kanban?.cardView?.target && schema) {
53
- return new ViewProjection(schema.jsonSchema, kanban.cardView.target);
54
+ const jsonSchema = Type.toJsonSchema(schema);
55
+ return new ViewProjection(jsonSchema, kanban.cardView.target);
54
56
  }
55
- }, [kanban?.cardView?.target, schema, JSON.stringify(schema)]);
57
+ }, [kanban?.cardView?.target, schema, JSON.stringify(schema ? Type.toJsonSchema(schema) : {})]);
56
58
 
57
59
  const fieldProjections = projection?.getFieldProjections() || [];
58
60
  const selectFields = fieldProjections
@@ -83,8 +85,8 @@ export const KanbanViewEditor = ({ kanban }: KanbanViewEditorProps) => {
83
85
  registry={space.db.schemaRegistry}
84
86
  schema={schema}
85
87
  view={kanban.cardView.target}
86
- onTypenameChanged={schema.readonly ? undefined : handleUpdateTypename}
87
- onDelete={schema.readonly ? undefined : handleDelete}
88
+ onTypenameChanged={isMutable(schema) ? handleUpdateTypename : undefined}
89
+ onDelete={isMutable(schema) ? handleDelete : undefined}
88
90
  />
89
91
  </>
90
92
  );
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './kanban-manager';
6
+ export * from './initialize-kanban';