@dxos/plugin-testing 0.0.0 → 0.8.4-main.03d5cd7b56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/neutral/StorybookPlugin.mjs +10 -0
- package/dist/lib/neutral/StorybookPlugin.mjs.map +7 -0
- package/dist/lib/neutral/add-toast-Z2RXG4RX.mjs +23 -0
- package/dist/lib/neutral/add-toast-Z2RXG4RX.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +11 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7UPIIIZM.mjs +22 -0
- package/dist/lib/neutral/chunk-7UPIIIZM.mjs.map +7 -0
- package/dist/lib/neutral/chunk-E4LBVPH5.mjs +8 -0
- package/dist/lib/neutral/chunk-E4LBVPH5.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-NZ2VT6N2.mjs +17 -0
- package/dist/lib/neutral/chunk-NZ2VT6N2.mjs.map +7 -0
- package/dist/lib/neutral/chunk-R7AV233N.mjs +31 -0
- package/dist/lib/neutral/chunk-R7AV233N.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ULNF6GTG.mjs +21 -0
- package/dist/lib/neutral/chunk-ULNF6GTG.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ZVN23V74.mjs +16 -0
- package/dist/lib/neutral/chunk-ZVN23V74.mjs.map +7 -0
- package/dist/lib/neutral/close-L3FBJQ3J.mjs +12 -0
- package/dist/lib/neutral/close-L3FBJQ3J.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +183 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/core.mjs +8 -0
- package/dist/lib/neutral/core.mjs.map +7 -0
- package/dist/lib/neutral/harness.mjs +37 -0
- package/dist/lib/neutral/harness.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +20 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/open-WBONYQ47.mjs +14 -0
- package/dist/lib/neutral/open-WBONYQ47.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-LQIWHQVY.mjs +13 -0
- package/dist/lib/neutral/operation-handler-LQIWHQVY.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/scroll-into-view-BKOOOECC.mjs +12 -0
- package/dist/lib/neutral/scroll-into-view-BKOOOECC.mjs.map +7 -0
- package/dist/lib/neutral/set-layout-mode-2KHD2AEY.mjs +12 -0
- package/dist/lib/neutral/set-layout-mode-2KHD2AEY.mjs.map +7 -0
- package/dist/lib/neutral/state-AJ62JEEG.mjs +43 -0
- package/dist/lib/neutral/state-AJ62JEEG.mjs.map +7 -0
- package/dist/lib/neutral/switch-workspace-SAT2NGXV.mjs +20 -0
- package/dist/lib/neutral/switch-workspace-SAT2NGXV.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +8 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/lib/neutral/update-complementary-JP2OL73Z.mjs +26 -0
- package/dist/lib/neutral/update-complementary-JP2OL73Z.mjs.map +7 -0
- package/dist/lib/neutral/update-dialog-MX6IKKJX.mjs +28 -0
- package/dist/lib/neutral/update-dialog-MX6IKKJX.mjs.map +7 -0
- package/dist/lib/neutral/update-popover-DOORE3TD.mjs +46 -0
- package/dist/lib/neutral/update-popover-DOORE3TD.mjs.map +7 -0
- package/dist/lib/neutral/update-sidebar-LWQ3IA6S.mjs +26 -0
- package/dist/lib/neutral/update-sidebar-LWQ3IA6S.mjs.map +7 -0
- package/dist/types/src/StorybookPlugin.d.ts +8 -0
- package/dist/types/src/StorybookPlugin.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +16 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/state.d.ts +18 -0
- package/dist/types/src/capabilities/state.d.ts.map +1 -0
- package/dist/types/src/components/Layout/Layout.d.ts +6 -0
- package/dist/types/src/components/Layout/Layout.d.ts.map +1 -0
- package/dist/types/src/components/Layout/index.d.ts +2 -0
- package/dist/types/src/components/Layout/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/core.d.ts +8 -0
- package/dist/types/src/core.d.ts.map +1 -0
- package/dist/types/src/harness.d.ts +20 -0
- package/dist/types/src/harness.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +3 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/dist/types/src/operations/add-toast.d.ts +5 -0
- package/dist/types/src/operations/add-toast.d.ts.map +1 -0
- package/dist/types/src/operations/close.d.ts +5 -0
- package/dist/types/src/operations/close.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/open.d.ts +5 -0
- package/dist/types/src/operations/open.d.ts.map +1 -0
- package/dist/types/src/operations/scroll-into-view.d.ts +5 -0
- package/dist/types/src/operations/scroll-into-view.d.ts.map +1 -0
- package/dist/types/src/operations/set-layout-mode.d.ts +5 -0
- package/dist/types/src/operations/set-layout-mode.d.ts.map +1 -0
- package/dist/types/src/operations/switch-workspace.d.ts +5 -0
- package/dist/types/src/operations/switch-workspace.d.ts.map +1 -0
- package/dist/types/src/operations/update-complementary.d.ts +5 -0
- package/dist/types/src/operations/update-complementary.d.ts.map +1 -0
- package/dist/types/src/operations/update-dialog.d.ts +5 -0
- package/dist/types/src/operations/update-dialog.d.ts.map +1 -0
- package/dist/types/src/operations/update-popover.d.ts +5 -0
- package/dist/types/src/operations/update-popover.d.ts.map +1 -0
- package/dist/types/src/operations/update-sidebar.d.ts +5 -0
- package/dist/types/src/operations/update-sidebar.d.ts.map +1 -0
- package/dist/types/src/operations/update-state.d.ts +5 -0
- package/dist/types/src/operations/update-state.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +5 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/types/StorybookCapabilities.d.ts +27 -0
- package/dist/types/src/types/StorybookCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +66 -18
- package/src/StorybookPlugin.ts +20 -17
- package/src/capabilities/index.ts +8 -2
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/state.tsx +45 -0
- package/src/components/Layout/Layout.tsx +236 -0
- package/src/components/Layout/index.ts +5 -0
- package/src/core.ts +20 -16
- package/src/harness.ts +52 -0
- package/src/index.ts +6 -0
- package/src/meta.ts +1 -1
- package/src/operations/add-toast.ts +22 -0
- package/src/operations/close.ts +14 -0
- package/src/operations/index.ts +18 -0
- package/src/operations/open.ts +18 -0
- package/src/operations/scroll-into-view.ts +14 -0
- package/src/operations/set-layout-mode.ts +14 -0
- package/src/operations/switch-workspace.ts +20 -0
- package/src/operations/update-complementary.ts +27 -0
- package/src/operations/update-dialog.ts +27 -0
- package/src/operations/update-popover.ts +37 -0
- package/src/operations/update-sidebar.ts +26 -0
- package/src/operations/update-state.ts +19 -0
- package/src/plugin.ts +12 -0
- package/src/types/{capabilities.ts → StorybookCapabilities.ts} +13 -3
- package/src/types/index.ts +1 -1
- package/src/capabilities/operation-resolver/index.ts +0 -7
- package/src/capabilities/operation-resolver/operation-resolver.ts +0 -82
- package/src/capabilities/state/index.ts +0 -7
- package/src/capabilities/state/state.tsx +0 -53
- package/src/components/Layout.tsx +0 -132
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { OperationHandlerSet } from '@dxos/compute';
|
|
6
|
+
|
|
7
|
+
export const TestingOperationHandlerSet = OperationHandlerSet.lazy(
|
|
8
|
+
() => import('./add-toast'),
|
|
9
|
+
() => import('./close'),
|
|
10
|
+
() => import('./open'),
|
|
11
|
+
() => import('./scroll-into-view'),
|
|
12
|
+
() => import('./set-layout-mode'),
|
|
13
|
+
() => import('./switch-workspace'),
|
|
14
|
+
() => import('./update-complementary'),
|
|
15
|
+
() => import('./update-dialog'),
|
|
16
|
+
() => import('./update-popover'),
|
|
17
|
+
() => import('./update-sidebar'),
|
|
18
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.Open> = LayoutOperation.Open.pipe(
|
|
11
|
+
Operation.withHandler(
|
|
12
|
+
Effect.fnUntraced(function* (input) {
|
|
13
|
+
return input.subject;
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default handler;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.ScrollIntoView> = LayoutOperation.ScrollIntoView.pipe(
|
|
11
|
+
Operation.withHandler(() => Effect.void),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default handler;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.SetLayoutMode> = LayoutOperation.SetLayoutMode.pipe(
|
|
11
|
+
Operation.withHandler(() => Effect.void),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default handler;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { updateState } from './update-state';
|
|
11
|
+
|
|
12
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.SwitchWorkspace> = LayoutOperation.SwitchWorkspace.pipe(
|
|
13
|
+
Operation.withHandler(
|
|
14
|
+
Effect.fnUntraced(function* ({ subject }) {
|
|
15
|
+
yield* updateState(() => ({ workspace: subject }));
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export default handler;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { updateState } from './update-state';
|
|
11
|
+
|
|
12
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.UpdateComplementary> =
|
|
13
|
+
LayoutOperation.UpdateComplementary.pipe(
|
|
14
|
+
Operation.withHandler(
|
|
15
|
+
Effect.fnUntraced(function* ({ state }) {
|
|
16
|
+
yield* updateState((layout) => {
|
|
17
|
+
const next = state ?? layout.complementarySidebarState;
|
|
18
|
+
if (next !== layout.complementarySidebarState) {
|
|
19
|
+
return { complementarySidebarState: next };
|
|
20
|
+
}
|
|
21
|
+
return {};
|
|
22
|
+
});
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export default handler;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { updateState } from './update-state';
|
|
11
|
+
|
|
12
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.UpdateDialog> = LayoutOperation.UpdateDialog.pipe(
|
|
13
|
+
Operation.withHandler(
|
|
14
|
+
Effect.fnUntraced(function* ({ subject, state, type, blockAlign, overlayClasses, overlayStyle, props }) {
|
|
15
|
+
yield* updateState(() => ({
|
|
16
|
+
dialogOpen: state ?? Boolean(subject),
|
|
17
|
+
dialogType: type ?? 'default',
|
|
18
|
+
dialogBlockAlign: blockAlign ?? 'center',
|
|
19
|
+
dialogOverlayClasses: overlayClasses,
|
|
20
|
+
dialogOverlayStyle: overlayStyle,
|
|
21
|
+
dialogContent: subject ? { component: subject, props } : null,
|
|
22
|
+
}));
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export default handler;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { StorybookCapabilities } from '../types';
|
|
11
|
+
import { updateState } from './update-state';
|
|
12
|
+
|
|
13
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.UpdatePopover> = LayoutOperation.UpdatePopover.pipe(
|
|
14
|
+
Operation.withHandler(
|
|
15
|
+
Effect.fnUntraced(function* (input) {
|
|
16
|
+
const { subject, state, side, kind, props } = input;
|
|
17
|
+
yield* updateState(() => {
|
|
18
|
+
const base: Partial<StorybookCapabilities.LayoutStateProps> = {
|
|
19
|
+
popoverKind: kind ?? 'base',
|
|
20
|
+
popoverTitle: kind === 'card' ? input.title : undefined,
|
|
21
|
+
popoverContent:
|
|
22
|
+
typeof subject === 'string' ? { component: subject, props } : subject ? { subject } : undefined,
|
|
23
|
+
popoverOpen: state ?? Boolean(subject),
|
|
24
|
+
popoverSide: side,
|
|
25
|
+
};
|
|
26
|
+
if ('variant' in input && input.variant === 'virtual') {
|
|
27
|
+
return { ...base, popoverVariant: 'virtual', popoverAnchor: input.anchor };
|
|
28
|
+
} else if ('anchorId' in input) {
|
|
29
|
+
return { ...base, popoverVariant: 'react', popoverAnchorId: input.anchorId };
|
|
30
|
+
}
|
|
31
|
+
return base;
|
|
32
|
+
});
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export default handler;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { updateState } from './update-state';
|
|
11
|
+
|
|
12
|
+
const handler: Operation.WithHandler<typeof LayoutOperation.UpdateSidebar> = LayoutOperation.UpdateSidebar.pipe(
|
|
13
|
+
Operation.withHandler(
|
|
14
|
+
Effect.fnUntraced(function* ({ state }) {
|
|
15
|
+
yield* updateState((layout) => {
|
|
16
|
+
const next = state ?? layout.sidebarState;
|
|
17
|
+
if (next !== layout.sidebarState) {
|
|
18
|
+
return { sidebarState: next };
|
|
19
|
+
}
|
|
20
|
+
return {};
|
|
21
|
+
});
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export default handler;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
8
|
+
|
|
9
|
+
import { StorybookCapabilities } from '../types';
|
|
10
|
+
|
|
11
|
+
export const updateState = (
|
|
12
|
+
fn: (state: StorybookCapabilities.LayoutStateProps) => Partial<StorybookCapabilities.LayoutStateProps>,
|
|
13
|
+
) =>
|
|
14
|
+
Effect.gen(function* () {
|
|
15
|
+
const registry = yield* Capability.get(Capabilities.AtomRegistry);
|
|
16
|
+
const stateAtom = yield* Capability.get(StorybookCapabilities.LayoutState);
|
|
17
|
+
const current = registry.get(stateAtom);
|
|
18
|
+
registry.set(stateAtom, { ...current, ...fn(current) });
|
|
19
|
+
});
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
8
|
+
|
|
9
|
+
export const StorybookPlugin = Plugin.lazy(meta, () => import('#plugin'));
|
|
10
|
+
export type { StorybookPluginOptions } from '#plugin';
|
|
11
|
+
|
|
12
|
+
export { TestingOperationHandlerSet } from './operations';
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import { type Atom } from '@effect-atom/atom-react';
|
|
8
|
+
|
|
5
9
|
import { Capability } from '@dxos/app-framework';
|
|
10
|
+
import { type LayoutOperation } from '@dxos/app-toolkit';
|
|
11
|
+
import { type Label } from '@dxos/react-ui';
|
|
6
12
|
|
|
7
|
-
import { meta } from '
|
|
13
|
+
import { meta } from '#meta';
|
|
8
14
|
|
|
9
|
-
export type
|
|
15
|
+
export type LayoutStateProps = {
|
|
10
16
|
sidebarState?: 'expanded' | 'collapsed' | 'closed';
|
|
11
17
|
complementarySidebarState?: 'expanded' | 'collapsed' | 'closed';
|
|
12
18
|
|
|
@@ -23,9 +29,13 @@ export type LayoutState = {
|
|
|
23
29
|
popoverVariant?: 'virtual' | 'react';
|
|
24
30
|
popoverAnchor?: HTMLButtonElement;
|
|
25
31
|
popoverAnchorId?: string;
|
|
32
|
+
popoverKind?: 'base' | 'card';
|
|
33
|
+
popoverTitle?: Label;
|
|
26
34
|
popoverContent?: any;
|
|
27
35
|
|
|
36
|
+
toasts: LayoutOperation.Toast[];
|
|
37
|
+
|
|
28
38
|
workspace: string;
|
|
29
39
|
};
|
|
30
40
|
|
|
31
|
-
export const LayoutState = Capability.make<
|
|
41
|
+
export const LayoutState = Capability.make<Atom.Writable<LayoutStateProps>>(`${meta.id}.state`);
|
package/src/types/index.ts
CHANGED
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
);
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
);
|
|
@@ -1,132 +0,0 @@
|
|
|
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
|
-
};
|