@dxos/plugin-testing 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright (c) 2022 DXOS
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @dxos/plugin-testing
2
+
3
+ A plugin that provides a simple layout to integrate and test other plugins in storybook without bringing in the complexity of @dxos/app-graph.
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@dxos/plugin-testing",
3
+ "version": "0.0.0",
4
+ "description": "Plugin testing utils",
5
+ "homepage": "https://dxos.org",
6
+ "bugs": "https://github.com/dxos/dxos/issues",
7
+ "license": "MIT",
8
+ "author": "DXOS.org",
9
+ "sideEffects": true,
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "source": "./src/index.ts",
14
+ "types": "./dist/types/src/index.d.ts",
15
+ "browser": "./dist/lib/browser/index.mjs"
16
+ }
17
+ },
18
+ "types": "dist/types/src/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "src"
22
+ ],
23
+ "dependencies": {
24
+ "@preact-signals/safe-react": "^0.9.0",
25
+ "@dxos/app-framework": "0.8.3",
26
+ "@dxos/operation": "0.0.0",
27
+ "@dxos/live-object": "0.8.3",
28
+ "@dxos/plugin-attention": "0.8.3",
29
+ "@dxos/plugin-client": "0.8.3",
30
+ "@dxos/util": "0.8.3",
31
+ "@dxos/plugin-theme": "0.8.3",
32
+ "@dxos/plugin-graph": "0.8.3"
33
+ },
34
+ "devDependencies": {
35
+ "@types/react": "~19.2.7",
36
+ "@types/react-dom": "~19.2.3",
37
+ "effect": "3.19.11",
38
+ "react": "~19.2.3",
39
+ "react-dom": "~19.2.3",
40
+ "vite": "7.1.9",
41
+ "@dxos/react-ui": "0.8.3",
42
+ "@dxos/ui-theme": "0.0.0"
43
+ },
44
+ "peerDependencies": {
45
+ "effect": "3.19.11",
46
+ "react": "~19.2.3",
47
+ "react-dom": "~19.2.3",
48
+ "@dxos/react-ui": "0.8.3",
49
+ "@dxos/ui-theme": "0.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }
@@ -0,0 +1,38 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Capability, Common, Plugin } from '@dxos/app-framework';
8
+
9
+ import { OperationResolver, State } from './capabilities';
10
+ import { Layout } from './components';
11
+ import { meta } from './meta';
12
+ import { type LayoutState } from './types';
13
+
14
+ export type StorybookPluginOptions = {
15
+ initialState?: Partial<LayoutState>;
16
+ };
17
+
18
+ export const StorybookPlugin = Plugin.define<StorybookPluginOptions>(meta).pipe(
19
+ Plugin.addModule(({ initialState }) => ({
20
+ id: Capability.getModuleTag(State),
21
+ activatesOn: Common.ActivationEvent.Startup,
22
+ activatesAfter: [Common.ActivationEvent.LayoutReady],
23
+ activate: () => State({ initialState }),
24
+ })),
25
+ Common.Plugin.addReactContextModule({
26
+ activate: () =>
27
+ Effect.succeed(
28
+ Capability.contributes(Common.Capability.ReactContext, {
29
+ id: 'storybook-layout',
30
+ context: Layout,
31
+ }),
32
+ ),
33
+ }),
34
+ Common.Plugin.addOperationResolverModule({
35
+ activate: OperationResolver,
36
+ }),
37
+ Plugin.make,
38
+ );
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './operation-resolver';
6
+ export * from './state';
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capability } from '@dxos/app-framework';
6
+
7
+ export const OperationResolver = Capability.lazy('OperationResolver', () => import('./operation-resolver'));
@@ -0,0 +1,82 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Capability, Common } from '@dxos/app-framework';
8
+ import { OperationResolver } from '@dxos/operation';
9
+
10
+ import { LayoutState } from '../../types';
11
+
12
+ export default Capability.makeModule(
13
+ Effect.fnUntraced(function* () {
14
+ return Capability.contributes(Common.Capability.OperationResolver, [
15
+ OperationResolver.make({
16
+ operation: Common.LayoutOperation.UpdateSidebar,
17
+ handler: Effect.fnUntraced(function* ({ state }) {
18
+ const layout = yield* Capability.get(LayoutState);
19
+ const next = state ?? layout.sidebarState;
20
+ if (next !== layout.sidebarState) {
21
+ layout.sidebarState = next;
22
+ }
23
+ }),
24
+ }),
25
+ OperationResolver.make({
26
+ operation: Common.LayoutOperation.UpdateComplementary,
27
+ handler: Effect.fnUntraced(function* ({ state }) {
28
+ const layout = yield* Capability.get(LayoutState);
29
+ const next = state ?? layout.complementarySidebarState;
30
+ if (next !== layout.complementarySidebarState) {
31
+ layout.complementarySidebarState = next;
32
+ }
33
+ }),
34
+ }),
35
+ OperationResolver.make({
36
+ operation: Common.LayoutOperation.UpdateDialog,
37
+ handler: Effect.fnUntraced(function* ({
38
+ subject,
39
+ state,
40
+ type,
41
+ blockAlign,
42
+ overlayClasses,
43
+ overlayStyle,
44
+ props,
45
+ }) {
46
+ const layout = yield* Capability.get(LayoutState);
47
+ layout.dialogOpen = state ?? Boolean(subject);
48
+ layout.dialogType = type ?? 'default';
49
+ layout.dialogBlockAlign = blockAlign ?? 'center';
50
+ layout.dialogOverlayClasses = overlayClasses;
51
+ layout.dialogOverlayStyle = overlayStyle;
52
+ layout.dialogContent = subject ? { component: subject, props } : null;
53
+ }),
54
+ }),
55
+ OperationResolver.make({
56
+ operation: Common.LayoutOperation.UpdatePopover,
57
+ handler: Effect.fnUntraced(function* (input) {
58
+ const layout = yield* Capability.get(LayoutState);
59
+ const { subject, state, side, props } = input;
60
+ layout.popoverContent =
61
+ typeof subject === 'string' ? { component: subject, props } : subject ? { subject } : undefined;
62
+ layout.popoverOpen = state ?? Boolean(subject);
63
+ layout.popoverSide = side;
64
+ if ('variant' in input && input.variant === 'virtual') {
65
+ layout.popoverVariant = 'virtual';
66
+ layout.popoverAnchor = input.anchor;
67
+ } else if ('anchorId' in input) {
68
+ layout.popoverVariant = 'react';
69
+ layout.popoverAnchorId = input.anchorId;
70
+ }
71
+ }),
72
+ }),
73
+ OperationResolver.make({
74
+ operation: Common.LayoutOperation.SwitchWorkspace,
75
+ handler: Effect.fnUntraced(function* ({ subject }) {
76
+ const layout = yield* Capability.get(LayoutState);
77
+ layout.workspace = subject;
78
+ }),
79
+ }),
80
+ ]);
81
+ }),
82
+ );
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capability } from '@dxos/app-framework';
6
+
7
+ export const State = Capability.lazy('State', () => import('./state'));
@@ -0,0 +1,53 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+
7
+ import { Capability, Common } from '@dxos/app-framework';
8
+ import { live } from '@dxos/live-object';
9
+
10
+ import { LayoutState } from '../../types';
11
+
12
+ const defaultState: LayoutState = {
13
+ sidebarState: 'closed',
14
+ complementarySidebarState: 'closed',
15
+ dialogOpen: false,
16
+ workspace: 'default',
17
+ };
18
+
19
+ export default Capability.makeModule(
20
+ Effect.fnUntraced(function* (props?: { initialState?: Partial<LayoutState> }) {
21
+ const { initialState } = props ?? {};
22
+ const state = live<LayoutState>({ ...defaultState, ...initialState });
23
+
24
+ const layout = live<Common.Capability.Layout>({
25
+ get mode() {
26
+ return 'storybook';
27
+ },
28
+ get dialogOpen() {
29
+ return state.dialogOpen;
30
+ },
31
+ get sidebarOpen() {
32
+ return state.sidebarState === 'expanded';
33
+ },
34
+ get complementarySidebarOpen() {
35
+ return state.complementarySidebarState === 'expanded';
36
+ },
37
+ get workspace() {
38
+ return state.workspace;
39
+ },
40
+ get active() {
41
+ return [];
42
+ },
43
+ get inactive() {
44
+ return [];
45
+ },
46
+ get scrollIntoView() {
47
+ return undefined;
48
+ },
49
+ });
50
+
51
+ return [Capability.contributes(LayoutState, state), Capability.contributes(Common.Capability.Layout, layout)];
52
+ }),
53
+ );
@@ -0,0 +1,132 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { type PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react';
6
+
7
+ import { Surface, useCapability } from '@dxos/app-framework/react';
8
+ import {
9
+ AlertDialog,
10
+ Dialog,
11
+ Main,
12
+ Popover,
13
+ type PopoverContentInteractOutsideEvent,
14
+ useTranslation,
15
+ } from '@dxos/react-ui';
16
+ import { descriptionMessage, mx } from '@dxos/ui-theme';
17
+
18
+ import { meta } from '../meta';
19
+ import { LayoutState } from '../types';
20
+
21
+ const debounce_delay = 100;
22
+
23
+ // TODO(wittjosiah): Support dialogs, tooltips, maybe toast.
24
+ export const Layout = ({ children }: PropsWithChildren<{}>) => {
25
+ const trigger = useRef<HTMLButtonElement | null>(null);
26
+ const layout = useCapability(LayoutState);
27
+ const [iter, setIter] = useState(0);
28
+ const [open, setOpen] = useState(false);
29
+ const debounceRef = useRef<NodeJS.Timeout | null>(null);
30
+
31
+ useEffect(() => {
32
+ setOpen(false);
33
+ if (debounceRef.current) {
34
+ clearTimeout(debounceRef.current);
35
+ debounceRef.current = null;
36
+ }
37
+ trigger.current = layout.popoverAnchor ?? null;
38
+ setIter((iter) => iter + 1);
39
+ if (layout.popoverOpen) {
40
+ debounceRef.current = setTimeout(() => setOpen(true), debounce_delay);
41
+ }
42
+ }, [layout.popoverAnchor, layout.popoverContent, layout.popoverOpen]);
43
+
44
+ const handleInteractOutside = useCallback((event: KeyboardEvent | PopoverContentInteractOutsideEvent) => {
45
+ if (
46
+ // TODO(thure): CodeMirror should not focus itself when it updates.
47
+ event.type === 'dismissableLayer.focusOutside' &&
48
+ (event.currentTarget as HTMLElement | undefined)?.classList.contains('cm-content')
49
+ ) {
50
+ event.preventDefault();
51
+ } else {
52
+ setOpen(false);
53
+ layout.popoverOpen = false;
54
+ layout.popoverAnchor = undefined;
55
+ layout.popoverAnchorId = undefined;
56
+ layout.popoverSide = undefined;
57
+ }
58
+ }, []);
59
+
60
+ const DialogRoot = layout.dialogType === 'alert' ? AlertDialog.Root : Dialog.Root;
61
+ const DialogOverlay = layout.dialogType === 'alert' ? AlertDialog.Overlay : Dialog.Overlay;
62
+
63
+ return (
64
+ <div role='none' className='fixed inset-0 flex overflow-hidden'>
65
+ <Popover.Root open={open}>
66
+ <Main.Root
67
+ navigationSidebarState={layout.sidebarState}
68
+ complementarySidebarState={layout.complementarySidebarState}
69
+ onNavigationSidebarStateChange={(next) => (layout.sidebarState = next)}
70
+ onComplementarySidebarStateChange={(next) => (layout.complementarySidebarState = next)}
71
+ >
72
+ {children}
73
+ </Main.Root>
74
+
75
+ <DialogRoot
76
+ modal={layout.dialogBlockAlign !== 'end'}
77
+ open={layout.dialogOpen}
78
+ onOpenChange={(nextOpen) => (layout.dialogOpen = nextOpen)}
79
+ >
80
+ {layout.dialogBlockAlign === 'end' ? (
81
+ <Surface
82
+ role='dialog'
83
+ data={layout.dialogContent}
84
+ limit={1}
85
+ fallback={ContentError}
86
+ placeholder={<div />}
87
+ />
88
+ ) : (
89
+ <DialogOverlay
90
+ blockAlign={layout.dialogBlockAlign}
91
+ classNames={layout.dialogOverlayClasses}
92
+ style={layout.dialogOverlayStyle}
93
+ >
94
+ <Surface role='dialog' data={layout.dialogContent} limit={1} fallback={ContentError} />
95
+ </DialogOverlay>
96
+ )}
97
+ </DialogRoot>
98
+
99
+ <Popover.VirtualTrigger key={iter} virtualRef={trigger} />
100
+ <Popover.Portal>
101
+ <Popover.Content
102
+ side={layout.popoverSide}
103
+ onInteractOutside={handleInteractOutside}
104
+ onEscapeKeyDown={handleInteractOutside}
105
+ sticky='always'
106
+ hideWhenDetached
107
+ >
108
+ <Popover.Viewport>
109
+ <Surface role='card--popover' data={layout.popoverContent} limit={1} />
110
+ </Popover.Viewport>
111
+ <Popover.Arrow />
112
+ </Popover.Content>
113
+ </Popover.Portal>
114
+ </Popover.Root>
115
+ </div>
116
+ );
117
+ };
118
+
119
+ export const ContentError = ({ error }: { error?: Error }) => {
120
+ const { t } = useTranslation(meta.id);
121
+ const errorString = error?.toString() ?? '';
122
+ return (
123
+ <div role='none' className='overflow-auto p-8 attention-surface grid place-items-center'>
124
+ <p
125
+ role='alert'
126
+ className={mx(descriptionMessage, 'break-words rounded-md p-8', errorString.length < 256 && 'text-lg')}
127
+ >
128
+ {error ? errorString : t('error fallback message')}
129
+ </p>
130
+ </div>
131
+ );
132
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './Layout';
package/src/core.ts ADDED
@@ -0,0 +1,35 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { OperationPlugin, type Plugin, RuntimePlugin, SettingsPlugin } from '@dxos/app-framework';
6
+ import { AttentionPlugin } from '@dxos/plugin-attention';
7
+ import { ClientPlugin } from '@dxos/plugin-client';
8
+ import { GraphPlugin } from '@dxos/plugin-graph';
9
+ import { ThemePlugin } from '@dxos/plugin-theme';
10
+ import { defaultTx } from '@dxos/ui-theme';
11
+
12
+ export {
13
+ // Re-export common framework plugins.
14
+ AttentionPlugin,
15
+ ClientPlugin,
16
+ GraphPlugin,
17
+ OperationPlugin,
18
+ RuntimePlugin,
19
+ SettingsPlugin,
20
+ ThemePlugin,
21
+ };
22
+
23
+ /**
24
+ * Core plugins for testing/storybook environments.
25
+ * NOTE: Does not include SpacePlugin to avoid circular dependencies.
26
+ * Import SpacePlugin directly in your stories if needed.
27
+ */
28
+ export const corePlugins = (): Plugin.Plugin[] => [
29
+ AttentionPlugin(),
30
+ GraphPlugin(),
31
+ OperationPlugin(),
32
+ RuntimePlugin(),
33
+ SettingsPlugin(),
34
+ ThemePlugin({ tx: defaultTx }),
35
+ ];
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './core';
6
+ export * from './meta';
7
+
8
+ export * from './StorybookPlugin';
package/src/meta.ts ADDED
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type Plugin } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
7
+
8
+ export const meta: Plugin.Meta = {
9
+ id: 'dxos.org/plugin/storybook-layout',
10
+ name: 'Storybook',
11
+ description: trim`
12
+ Development layout optimized for Storybook component testing and documentation.
13
+ Provides specialized views for component development and design system exploration.
14
+ `,
15
+ source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-testing',
16
+ };
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capability } from '@dxos/app-framework';
6
+
7
+ import { meta } from '../meta';
8
+
9
+ export type LayoutState = {
10
+ sidebarState?: 'expanded' | 'collapsed' | 'closed';
11
+ complementarySidebarState?: 'expanded' | 'collapsed' | 'closed';
12
+
13
+ dialogOpen: boolean;
14
+ dialogType?: 'default' | 'alert';
15
+ dialogBlockAlign?: 'start' | 'center' | 'end';
16
+ dialogOverlayClasses?: string;
17
+ dialogOverlayStyle?: Record<string, any>;
18
+ /** Data to be passed to the dialog Surface. */
19
+ dialogContent?: any;
20
+
21
+ popoverOpen?: boolean;
22
+ popoverSide?: 'top' | 'right' | 'bottom' | 'left';
23
+ popoverVariant?: 'virtual' | 'react';
24
+ popoverAnchor?: HTMLButtonElement;
25
+ popoverAnchorId?: string;
26
+ popoverContent?: any;
27
+
28
+ workspace: string;
29
+ };
30
+
31
+ export const LayoutState = Capability.make<LayoutState>(`${meta.id}/state`);
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './capabilities';