@dxos/plugin-simple-layout 0.8.4-main.21d9917 → 0.8.4-main.2244d791bb
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/browser/{chunk-CLPGTNWJ.mjs → chunk-7VLT3S46.mjs} +3 -3
- package/dist/lib/browser/chunk-7VLT3S46.mjs.map +7 -0
- package/dist/lib/browser/chunk-U632CHRU.mjs +1167 -0
- package/dist/lib/browser/chunk-U632CHRU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +27 -20
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{operation-resolver-LTB63NKP.mjs → operation-resolver-BYRIQOQT.mjs} +66 -29
- package/dist/lib/browser/operation-resolver-BYRIQOQT.mjs.map +7 -0
- package/dist/lib/browser/{react-root-6ARAPH3O.mjs → react-root-ZQTWLJYR.mjs} +5 -5
- package/dist/lib/browser/react-root-ZQTWLJYR.mjs.map +7 -0
- package/dist/lib/browser/{react-surface-SO7B23GS.mjs → react-surface-IOYDLMNR.mjs} +10 -8
- package/dist/lib/browser/react-surface-IOYDLMNR.mjs.map +7 -0
- package/dist/lib/browser/{spotlight-dismiss-VSNOPETH.mjs → spotlight-dismiss-67PHYS5B.mjs} +3 -3
- package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs.map +7 -0
- package/dist/lib/browser/{state-H4IGICBB.mjs → state-A3PGDWWZ.mjs} +8 -5
- package/dist/lib/browser/state-A3PGDWWZ.mjs.map +7 -0
- package/dist/lib/browser/url-handler-HTIUY6WL.mjs +152 -0
- package/dist/lib/browser/url-handler-HTIUY6WL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UXFYLQJA.mjs +1168 -0
- package/dist/lib/node-esm/chunk-UXFYLQJA.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-MUVVYBUE.mjs → chunk-VIDE5UMB.mjs} +3 -3
- package/dist/lib/node-esm/chunk-VIDE5UMB.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +27 -20
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{operation-resolver-7O6O7T4Q.mjs → operation-resolver-BDTFNCS2.mjs} +66 -29
- package/dist/lib/node-esm/operation-resolver-BDTFNCS2.mjs.map +7 -0
- package/dist/lib/node-esm/{react-root-2CPA2ZUS.mjs → react-root-FMAUHDJI.mjs} +5 -5
- package/dist/lib/node-esm/react-root-FMAUHDJI.mjs.map +7 -0
- package/dist/lib/node-esm/{react-surface-FKAV56MO.mjs → react-surface-ZAZRIKZQ.mjs} +10 -8
- package/dist/lib/node-esm/react-surface-ZAZRIKZQ.mjs.map +7 -0
- package/dist/lib/node-esm/{spotlight-dismiss-L5PCWIJG.mjs → spotlight-dismiss-RMLRZUVY.mjs} +3 -3
- package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs.map +7 -0
- package/dist/lib/node-esm/{state-QIU2LMLT.mjs → state-ZCFZTTPL.mjs} +8 -5
- package/dist/lib/node-esm/state-ZCFZTTPL.mjs.map +7 -0
- package/dist/lib/node-esm/url-handler-WBVVKVPC.mjs +153 -0
- package/dist/lib/node-esm/url-handler-WBVVKVPC.mjs.map +7 -0
- package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -1
- package/dist/types/src/capabilities/state/state.d.ts.map +1 -1
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts +2 -0
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -1
- package/dist/types/src/components/ContentError.stories.d.ts +6 -0
- package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
- package/dist/types/src/components/Home/Home.d.ts.map +1 -1
- package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
- package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts +26 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts +9 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Main.d.ts +1 -1
- package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts +13 -3
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +13 -9
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +10 -0
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
- package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
- package/dist/types/src/components/Workspace/Workspace.d.ts +3 -1
- package/dist/types/src/components/Workspace/Workspace.d.ts.map +1 -1
- package/dist/types/src/components/hooks.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/actions.d.ts +20 -0
- package/dist/types/src/hooks/actions.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
- package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
- package/dist/types/src/hooks/useCompanions.d.ts +12 -0
- package/dist/types/src/hooks/useCompanions.d.ts.map +1 -0
- package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
- package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
- package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +8 -3
- package/dist/types/src/types/capabilities.d.ts.map +1 -1
- package/dist/types/src/types/events.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -30
- package/src/SimpleLayoutPlugin.ts +10 -9
- package/src/capabilities/operation-resolver/operation-resolver.ts +65 -26
- package/src/capabilities/react-root/react-root.tsx +2 -2
- package/src/capabilities/react-surface/react-surface.tsx +6 -5
- package/src/capabilities/spotlight-dismiss/spotlight-dismiss.ts +2 -2
- package/src/capabilities/state/state.tsx +6 -3
- package/src/capabilities/url-handler/url-handler.ts +111 -34
- package/src/components/ContentError.stories.tsx +1 -1
- package/src/components/ContentLoading.stories.tsx +1 -1
- package/src/components/Dialog/Dialog.tsx +4 -4
- package/src/components/Home/Home.tsx +23 -20
- package/src/components/MobileLayout/MobileLayout.stories.tsx +125 -0
- package/src/components/MobileLayout/MobileLayout.tsx +305 -0
- package/src/components/MobileLayout/index.ts +5 -0
- package/src/components/Popover/Popover.tsx +4 -4
- package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
- package/src/components/SimpleLayout/AppBar.tsx +97 -0
- package/src/components/SimpleLayout/Drawer.tsx +102 -0
- package/src/components/SimpleLayout/Main.tsx +44 -44
- package/src/components/SimpleLayout/NavBar.stories.tsx +129 -24
- package/src/components/SimpleLayout/NavBar.tsx +24 -58
- package/src/components/SimpleLayout/SimpleLayout.stories.tsx +22 -9
- package/src/components/SimpleLayout/SimpleLayout.tsx +45 -6
- package/src/components/SimpleLayout/index.ts +3 -0
- package/src/components/Workspace/Workspace.tsx +16 -11
- package/src/components/hooks.ts +9 -13
- package/src/components/index.ts +1 -0
- package/src/hooks/actions.ts +85 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useAppBarProps.ts +112 -0
- package/src/hooks/useCompanions.ts +22 -0
- package/src/hooks/useDrawerActions.ts +98 -0
- package/src/hooks/useNavbarActions.ts +86 -0
- package/src/hooks/useSimpleLayoutState.ts +5 -5
- package/src/translations.ts +6 -0
- package/src/types/capabilities.ts +12 -3
- package/src/types/events.ts +3 -2
- package/dist/lib/browser/chunk-CLPGTNWJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-FK4M7GJV.mjs +0 -613
- package/dist/lib/browser/chunk-FK4M7GJV.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-LTB63NKP.mjs.map +0 -7
- package/dist/lib/browser/react-root-6ARAPH3O.mjs.map +0 -7
- package/dist/lib/browser/react-surface-SO7B23GS.mjs.map +0 -7
- package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
- package/dist/lib/browser/state-H4IGICBB.mjs.map +0 -7
- package/dist/lib/browser/url-handler-7CFGTLNG.mjs +0 -54
- package/dist/lib/browser/url-handler-7CFGTLNG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EGFZAVBD.mjs +0 -614
- package/dist/lib/node-esm/chunk-EGFZAVBD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MUVVYBUE.mjs.map +0 -7
- package/dist/lib/node-esm/operation-resolver-7O6O7T4Q.mjs.map +0 -7
- package/dist/lib/node-esm/react-root-2CPA2ZUS.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-FKAV56MO.mjs.map +0 -7
- package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
- package/dist/lib/node-esm/state-QIU2LMLT.mjs.map +0 -7
- package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs +0 -55
- package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs.map +0 -7
- package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
- package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
- package/src/components/SimpleLayout/Banner.tsx +0 -82
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { Surface } from '@dxos/app-framework/
|
|
7
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
8
8
|
import { AlertDialog, Dialog as NaturalDialog } from '@dxos/react-ui';
|
|
9
9
|
|
|
10
10
|
import { useSimpleLayoutState } from '../../hooks';
|
|
@@ -20,17 +20,17 @@ export const Dialog = () => {
|
|
|
20
20
|
<DialogRoot
|
|
21
21
|
modal={state.dialogBlockAlign !== 'end'}
|
|
22
22
|
open={state.dialogOpen}
|
|
23
|
-
onOpenChange={(nextOpen) => updateState((
|
|
23
|
+
onOpenChange={(nextOpen) => updateState((state) => ({ ...state, dialogOpen: nextOpen }))}
|
|
24
24
|
>
|
|
25
25
|
{state.dialogBlockAlign === 'end' ? (
|
|
26
|
-
<Surface role='dialog' data={state.dialogContent} limit={1} fallback={ContentError} />
|
|
26
|
+
<Surface.Surface role='dialog' data={state.dialogContent} limit={1} fallback={ContentError} />
|
|
27
27
|
) : (
|
|
28
28
|
<DialogOverlay
|
|
29
29
|
blockAlign={state.dialogBlockAlign}
|
|
30
30
|
classNames={state.dialogOverlayClasses}
|
|
31
31
|
style={state.dialogOverlayStyle}
|
|
32
32
|
>
|
|
33
|
-
<Surface role='dialog' data={state.dialogContent} limit={1} fallback={ContentError} />
|
|
33
|
+
<Surface.Surface role='dialog' data={state.dialogContent} limit={1} fallback={ContentError} />
|
|
34
34
|
</DialogOverlay>
|
|
35
35
|
)}
|
|
36
36
|
</DialogRoot>
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { useOperationInvoker } from '@dxos/app-framework/ui';
|
|
8
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
9
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
9
10
|
import { Node, useConnections } from '@dxos/plugin-graph';
|
|
10
|
-
import { Avatar, Icon, Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import { Card,
|
|
11
|
+
import { Avatar, Icon, Layout, ScrollArea, Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
12
|
+
import { Card, Mosaic, type MosaicStackTileComponent } from '@dxos/react-ui-mosaic';
|
|
12
13
|
import { SearchList, useSearchListItem, useSearchListResults } from '@dxos/react-ui-searchlist';
|
|
13
14
|
import { mx } from '@dxos/ui-theme';
|
|
14
15
|
import { byPosition } from '@dxos/util';
|
|
@@ -46,9 +47,11 @@ export const Home = (_: HomeProps) => {
|
|
|
46
47
|
</Toolbar.Root>
|
|
47
48
|
<SearchList.Content>
|
|
48
49
|
<Mosaic.Container asChild>
|
|
49
|
-
<
|
|
50
|
-
<
|
|
51
|
-
|
|
50
|
+
<ScrollArea.Root orientation='vertical'>
|
|
51
|
+
<ScrollArea.Viewport classNames='p-2'>
|
|
52
|
+
<Mosaic.Stack items={results} getId={(node) => node.id} Tile={WorkspaceTile} />
|
|
53
|
+
</ScrollArea.Viewport>
|
|
54
|
+
</ScrollArea.Root>
|
|
52
55
|
</Mosaic.Container>
|
|
53
56
|
</SearchList.Content>
|
|
54
57
|
</SearchList.Root>
|
|
@@ -56,26 +59,26 @@ export const Home = (_: HomeProps) => {
|
|
|
56
59
|
);
|
|
57
60
|
};
|
|
58
61
|
|
|
59
|
-
const WorkspaceTile:
|
|
62
|
+
const WorkspaceTile: MosaicStackTileComponent<Node.Node> = (props) => {
|
|
63
|
+
const data = props.data;
|
|
60
64
|
const { t } = useTranslation(meta.id);
|
|
61
65
|
const { invokePromise } = useOperationInvoker();
|
|
62
66
|
const { selectedValue, registerItem, unregisterItem } = useSearchListItem();
|
|
63
|
-
const
|
|
67
|
+
const name = toLocalizedString(data.properties.label, t);
|
|
68
|
+
const isSelected = selectedValue === data.id;
|
|
69
|
+
const cardRef = useRef<HTMLDivElement>(null);
|
|
70
|
+
|
|
71
|
+
useLoadDescendents(data.id);
|
|
64
72
|
|
|
65
73
|
const handleSelect = useCallback(
|
|
66
|
-
() => invokePromise(
|
|
74
|
+
() => invokePromise(LayoutOperation.SwitchWorkspace, { subject: data.id }),
|
|
67
75
|
[invokePromise, data.id],
|
|
68
76
|
);
|
|
69
77
|
|
|
70
|
-
useLoadDescendents(data.id);
|
|
71
|
-
|
|
72
|
-
const name = toLocalizedString(data.properties.label, t);
|
|
73
|
-
const isSelected = selectedValue === data.id;
|
|
74
|
-
|
|
75
78
|
// Register this workspace with the search context.
|
|
76
79
|
useEffect(() => {
|
|
77
|
-
if (
|
|
78
|
-
registerItem(data.id,
|
|
80
|
+
if (cardRef.current) {
|
|
81
|
+
registerItem(data.id, cardRef.current, handleSelect);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
return () => unregisterItem(data.id);
|
|
@@ -83,20 +86,20 @@ const WorkspaceTile: StackTileComponent<Node.Node> = ({ data }) => {
|
|
|
83
86
|
|
|
84
87
|
// Scroll into view when selected.
|
|
85
88
|
useEffect(() => {
|
|
86
|
-
if (isSelected &&
|
|
87
|
-
|
|
89
|
+
if (isSelected && cardRef.current) {
|
|
90
|
+
cardRef.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
88
91
|
}
|
|
89
92
|
}, [isSelected]);
|
|
90
93
|
|
|
91
94
|
return (
|
|
92
95
|
<Card.Root
|
|
93
|
-
ref={ref}
|
|
94
96
|
role='button'
|
|
95
97
|
fullWidth
|
|
96
98
|
tabIndex={-1} // TODO(burdon): Use Mosaic.Focus.
|
|
97
99
|
data-selected={isSelected}
|
|
98
100
|
classNames={mx('dx-focus-ring', isSelected && 'bg-hoverOverlay')}
|
|
99
101
|
onClick={handleSelect}
|
|
102
|
+
ref={cardRef}
|
|
100
103
|
>
|
|
101
104
|
<Card.Toolbar density='coarse'>
|
|
102
105
|
<Avatar.Root>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { type PropsWithChildren, useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { addEventListener, combine } from '@dxos/async';
|
|
9
|
+
import { Flex, Input, Layout, Splitter, type SplitterMode, Toolbar } from '@dxos/react-ui';
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
|
+
|
|
12
|
+
import { MobileLayout, type MobileLayoutRootProps } from './MobileLayout';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Simulate ios keyboard.
|
|
16
|
+
*/
|
|
17
|
+
const WithKeyboard = ({ children }: PropsWithChildren) => {
|
|
18
|
+
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
return combine(
|
|
22
|
+
addEventListener(document, 'focusin', (event: FocusEvent) => {
|
|
23
|
+
const target = event.target as HTMLElement;
|
|
24
|
+
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
|
|
25
|
+
setKeyboardOpen(true);
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
addEventListener(document, 'focusout', (event: FocusEvent) => {
|
|
29
|
+
const target = event.target as HTMLElement;
|
|
30
|
+
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
|
|
31
|
+
setKeyboardOpen(false);
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const keyboardHeight = keyboardOpen ? 300 : 0;
|
|
39
|
+
document.documentElement.style.setProperty('--kb-height', `${keyboardHeight}px`);
|
|
40
|
+
document.documentElement.style.setProperty('--kb-open', keyboardOpen ? '1' : '0');
|
|
41
|
+
|
|
42
|
+
// Dispatch custom keyboard event that useIOSKeyboard listens for.
|
|
43
|
+
window.dispatchEvent(
|
|
44
|
+
new CustomEvent('keyboard', {
|
|
45
|
+
detail: {
|
|
46
|
+
type: keyboardOpen ? 'show' : 'hide',
|
|
47
|
+
height: keyboardHeight,
|
|
48
|
+
duration: 300,
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
}, [keyboardOpen]);
|
|
53
|
+
|
|
54
|
+
return <div className='h-screen relative'>{children}</div>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const Panel = ({ children, label }: PropsWithChildren<{ label: string }>) => {
|
|
58
|
+
return (
|
|
59
|
+
<Layout.Main toolbar>
|
|
60
|
+
<Toolbar.Root>
|
|
61
|
+
{label}
|
|
62
|
+
<Toolbar.Separator variant='gap' />
|
|
63
|
+
{children}
|
|
64
|
+
</Toolbar.Root>
|
|
65
|
+
<Flex column classNames='p-1'>
|
|
66
|
+
<Input.Root>
|
|
67
|
+
<Input.TextInput />
|
|
68
|
+
</Input.Root>
|
|
69
|
+
</Flex>
|
|
70
|
+
</Layout.Main>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const DefaultStory = () => {
|
|
75
|
+
const [splitterMode, setSplitterMode] = useState<SplitterMode>('upper');
|
|
76
|
+
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
setSplitterMode(splitterMode === 'both' ? 'lower' : splitterMode);
|
|
80
|
+
}, [keyboardOpen]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<WithKeyboard>
|
|
84
|
+
<MobileLayout.Root onKeyboardOpenChange={setKeyboardOpen}>
|
|
85
|
+
<MobileLayout.Panel safe={{ top: true, bottom: splitterMode === 'upper' }}>
|
|
86
|
+
<Splitter.Root mode={splitterMode} ratio={0.5}>
|
|
87
|
+
<Splitter.Panel position='upper'>
|
|
88
|
+
<Panel label='Main'>
|
|
89
|
+
{splitterMode === 'upper' && (
|
|
90
|
+
<Toolbar.IconButton icon='ph--plus--regular' label='Open' onClick={() => setSplitterMode('both')} />
|
|
91
|
+
)}
|
|
92
|
+
</Panel>
|
|
93
|
+
</Splitter.Panel>
|
|
94
|
+
<Splitter.Panel position='lower'>
|
|
95
|
+
<Panel label='Drawer'>
|
|
96
|
+
<Toolbar.IconButton
|
|
97
|
+
icon={splitterMode === 'lower' ? 'ph--arrow-down--regular' : 'ph--arrow-up--regular'}
|
|
98
|
+
label={splitterMode === 'lower' ? 'Collapse' : 'Expand'}
|
|
99
|
+
onClick={() => setSplitterMode((splitterMode) => (splitterMode === 'both' ? 'lower' : 'both'))}
|
|
100
|
+
/>
|
|
101
|
+
<Toolbar.IconButton icon='ph--x--regular' label='Close' onClick={() => setSplitterMode('upper')} />
|
|
102
|
+
</Panel>
|
|
103
|
+
</Splitter.Panel>
|
|
104
|
+
</Splitter.Root>
|
|
105
|
+
</MobileLayout.Panel>
|
|
106
|
+
</MobileLayout.Root>
|
|
107
|
+
</WithKeyboard>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const meta: Meta<MobileLayoutRootProps> = {
|
|
112
|
+
title: 'plugins/plugin-simple-layout/MobileLayout',
|
|
113
|
+
component: MobileLayout.Root,
|
|
114
|
+
render: DefaultStory,
|
|
115
|
+
decorators: [withTheme(), withLayout({ layout: 'column', classNames: 'relative' })],
|
|
116
|
+
parameters: {
|
|
117
|
+
layout: 'fullscreen',
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export default meta;
|
|
122
|
+
|
|
123
|
+
type Story = StoryObj<MobileLayoutRootProps>;
|
|
124
|
+
|
|
125
|
+
export const Default: Story = {};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createContext } from '@radix-ui/react-context';
|
|
6
|
+
import React, { type PropsWithChildren, forwardRef, useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { addEventListener, combine } from '@dxos/async';
|
|
9
|
+
import { log } from '@dxos/log';
|
|
10
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
|
+
|
|
13
|
+
// TODO(burdon): Move into @dxos/react-ui?
|
|
14
|
+
|
|
15
|
+
const MOBILE_LAYOUT_NAME = 'MobileLayout';
|
|
16
|
+
const MOBILE_LAYOUT_ROOT_NAME = 'MobileLayout.Root';
|
|
17
|
+
const MOBILE_LAYOUT_PANEL_NAME = 'MobileLayout.Panel';
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// Context
|
|
21
|
+
//
|
|
22
|
+
|
|
23
|
+
type MobileLayoutContextValue = {
|
|
24
|
+
keyboardOpen: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const [MobileLayoutProvider, useMobileLayout] = createContext<MobileLayoutContextValue>(MOBILE_LAYOUT_NAME);
|
|
28
|
+
|
|
29
|
+
//
|
|
30
|
+
// Root
|
|
31
|
+
//
|
|
32
|
+
|
|
33
|
+
type MobileLayoutRootProps = ThemedClassName<
|
|
34
|
+
PropsWithChildren<{
|
|
35
|
+
transition?: number;
|
|
36
|
+
onKeyboardOpenChange?: (nextState: boolean) => void;
|
|
37
|
+
}>
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Mobile layout root container that handles iOS keyboard detection.
|
|
42
|
+
*/
|
|
43
|
+
// TODO(burdon): Should this be ios-only?
|
|
44
|
+
const MobileLayoutRoot = forwardRef<HTMLDivElement, MobileLayoutRootProps>(
|
|
45
|
+
({ classNames, children, transition = 250, onKeyboardOpenChange, ...props }, forwardedRef) => {
|
|
46
|
+
const { open: keyboardOpen } = useIOSKeyboard();
|
|
47
|
+
useAutoScroll();
|
|
48
|
+
useEffect(() => onKeyboardOpenChange?.(keyboardOpen), [onKeyboardOpenChange, keyboardOpen]);
|
|
49
|
+
useLockBodyScroll(keyboardOpen);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<MobileLayoutProvider keyboardOpen={keyboardOpen}>
|
|
53
|
+
<div
|
|
54
|
+
{...props}
|
|
55
|
+
role='none'
|
|
56
|
+
style={{
|
|
57
|
+
transition: `block-size ${transition}ms ease-out`,
|
|
58
|
+
blockSize: 'calc(100vh - var(--kb-height, 0px))',
|
|
59
|
+
}}
|
|
60
|
+
className={mx('absolute top-0 left-0 right-0 flex flex-col', classNames)}
|
|
61
|
+
ref={forwardedRef}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</div>
|
|
65
|
+
</MobileLayoutProvider>
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
MobileLayoutRoot.displayName = MOBILE_LAYOUT_ROOT_NAME;
|
|
71
|
+
|
|
72
|
+
//
|
|
73
|
+
// Panel
|
|
74
|
+
//
|
|
75
|
+
|
|
76
|
+
type MobileLayoutPanelProps = ThemedClassName<
|
|
77
|
+
PropsWithChildren<{
|
|
78
|
+
safe?: {
|
|
79
|
+
top: boolean;
|
|
80
|
+
bottom: boolean;
|
|
81
|
+
};
|
|
82
|
+
}>
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Mobile layout panel that applies safe area insets.
|
|
87
|
+
*/
|
|
88
|
+
const MobileLayoutPanel = forwardRef<HTMLDivElement, MobileLayoutPanelProps>(
|
|
89
|
+
({ classNames, children, safe, ...props }, forwardedRef) => {
|
|
90
|
+
return (
|
|
91
|
+
<div
|
|
92
|
+
{...props}
|
|
93
|
+
role='none'
|
|
94
|
+
style={{
|
|
95
|
+
paddingTop: safe?.top ? 'env(safe-area-inset-top)' : undefined,
|
|
96
|
+
paddingBottom: safe?.bottom ? `calc((1 - var(--kb-open, 0)) * env(safe-area-inset-bottom))` : undefined,
|
|
97
|
+
}}
|
|
98
|
+
className={mx('relative bs-full flex flex-col overflow-hidden', classNames)}
|
|
99
|
+
ref={forwardedRef}
|
|
100
|
+
>
|
|
101
|
+
{children}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
MobileLayoutPanel.displayName = MOBILE_LAYOUT_PANEL_NAME;
|
|
108
|
+
|
|
109
|
+
//
|
|
110
|
+
// Exports
|
|
111
|
+
//
|
|
112
|
+
|
|
113
|
+
export const MobileLayout = {
|
|
114
|
+
Root: MobileLayoutRoot,
|
|
115
|
+
Panel: MobileLayoutPanel,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { useMobileLayout };
|
|
119
|
+
|
|
120
|
+
export type { MobileLayoutRootProps, MobileLayoutPanelProps };
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Prevent auto-scroll when input is focused.
|
|
124
|
+
*/
|
|
125
|
+
const useAutoScroll = () => {
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
// Prevent auto-scroll when input is focused.
|
|
128
|
+
return addEventListener(
|
|
129
|
+
document,
|
|
130
|
+
'focus',
|
|
131
|
+
(event: FocusEvent) => {
|
|
132
|
+
const target = event.target as HTMLElement;
|
|
133
|
+
if (
|
|
134
|
+
target.tagName === 'INPUT' ||
|
|
135
|
+
target.tagName === 'TEXTAREA' ||
|
|
136
|
+
(target.tagName === 'DIV' && target.isContentEditable)
|
|
137
|
+
) {
|
|
138
|
+
// Prevent default focus behavior.
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
|
|
141
|
+
// Manually focus without scroll.
|
|
142
|
+
target.focus({ preventScroll: true });
|
|
143
|
+
|
|
144
|
+
// Lock current scroll position.
|
|
145
|
+
const scrollX = window.scrollX;
|
|
146
|
+
const scrollY = window.scrollY;
|
|
147
|
+
requestAnimationFrame(() => {
|
|
148
|
+
window.scrollTo(scrollX, scrollY);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// TODO(burdon): Scroll to position in parent; this may need to be via an intent,
|
|
152
|
+
// since it may be plugin-specific (e.g., codemirror document.)
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
// Important: focus events don't bubble, so capture phase is required.
|
|
156
|
+
{ capture: true },
|
|
157
|
+
);
|
|
158
|
+
}, []);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Prevent iOS Safari viewport scroll when enabled.
|
|
163
|
+
* Setting overflow:hidden doesn't work on iOS, so we must preventDefault on touchmove events.
|
|
164
|
+
* Only allows scrolling if the target is within a scrollable container.
|
|
165
|
+
*/
|
|
166
|
+
const useLockBodyScroll = (enabled: boolean) => {
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (!enabled) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const isScrollable = (el: HTMLElement | null, axis: 'x' | 'y'): boolean => {
|
|
173
|
+
while (el && el !== document.body) {
|
|
174
|
+
const style = getComputedStyle(el);
|
|
175
|
+
if (axis === 'y') {
|
|
176
|
+
const overflow = style.overflowY;
|
|
177
|
+
if ((overflow === 'auto' || overflow === 'scroll') && el.scrollHeight > el.clientHeight) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
const overflow = style.overflowX;
|
|
182
|
+
if ((overflow === 'auto' || overflow === 'scroll') && el.scrollWidth > el.clientWidth) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
el = el.parentElement;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return false;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
let touchStartX = 0;
|
|
194
|
+
let touchStartY = 0;
|
|
195
|
+
|
|
196
|
+
return combine(
|
|
197
|
+
// Record initial touch position.
|
|
198
|
+
addEventListener(
|
|
199
|
+
document,
|
|
200
|
+
'touchstart',
|
|
201
|
+
(event: TouchEvent) => {
|
|
202
|
+
const touch = event.touches[0];
|
|
203
|
+
touchStartX = touch.clientX;
|
|
204
|
+
touchStartY = touch.clientY;
|
|
205
|
+
},
|
|
206
|
+
{ passive: true },
|
|
207
|
+
),
|
|
208
|
+
|
|
209
|
+
// Prevent scrolling the viewport.
|
|
210
|
+
addEventListener(
|
|
211
|
+
document,
|
|
212
|
+
'touchmove',
|
|
213
|
+
(event: TouchEvent) => {
|
|
214
|
+
const touch = event.touches[0];
|
|
215
|
+
const dx = Math.abs(touch.clientX - touchStartX);
|
|
216
|
+
const dy = Math.abs(touch.clientY - touchStartY);
|
|
217
|
+
if (!isScrollable(event.target as HTMLElement, dx > dy ? 'x' : 'y')) {
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{ passive: false },
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
}, [enabled]);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
//
|
|
228
|
+
// Hooks
|
|
229
|
+
//
|
|
230
|
+
|
|
231
|
+
type IOSKeyboard = {
|
|
232
|
+
open: boolean;
|
|
233
|
+
height: number;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Mobile container that handles iOS keyboard layout adjustments.
|
|
238
|
+
*
|
|
239
|
+
* Uses two strategies for keyboard detection:
|
|
240
|
+
* 1. Tauri iOS: Native keyboard plugin for reliable height/animation events.
|
|
241
|
+
* 2. Web/PWA: visualViewport API as fallback.
|
|
242
|
+
*
|
|
243
|
+
* iPhone (portrait, points)
|
|
244
|
+
* - Without predictive bar: ~291 pt
|
|
245
|
+
* - With predictive bar: ~335 pt
|
|
246
|
+
* - With accessory view: ~380–420 pt
|
|
247
|
+
*
|
|
248
|
+
* Example:
|
|
249
|
+
* - Viewport: 874 (entire screen)
|
|
250
|
+
* - SafeArea: 96 (62+34)
|
|
251
|
+
* - Main: 778
|
|
252
|
+
* - Keyboard: 318; 413 (incl. Input Accessory View)
|
|
253
|
+
*
|
|
254
|
+
* CSS Variables set on document.documentElement:
|
|
255
|
+
* --vvh: Visual viewport height (use as container height).
|
|
256
|
+
* --kb-height: Keyboard height in pixels.
|
|
257
|
+
* --kb-open: 1 when keyboard is open, 0 when closed.
|
|
258
|
+
*
|
|
259
|
+
* NOTE: By default when an input is selected on iOS the Input Accessory View is shown above the keyboard.
|
|
260
|
+
* This can be disabled by setting the `inputAccessoryView` property to `false`.
|
|
261
|
+
*
|
|
262
|
+
* On iOS (Tauri), listens for 'keyboard' CustomEvents dispatched by the native KeyboardObserver.swift.
|
|
263
|
+
* Falls back to VisualViewport API on other platforms.
|
|
264
|
+
*/
|
|
265
|
+
const useIOSKeyboard = (): IOSKeyboard => {
|
|
266
|
+
const [open, setOpen] = useState(false);
|
|
267
|
+
const [height, setHeight] = useState(0);
|
|
268
|
+
|
|
269
|
+
// Detect keybaord state.
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
const viewport = window.visualViewport;
|
|
272
|
+
if (!viewport) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Handler for VisualViewport resize (fallback for non-iOS).
|
|
277
|
+
const initialHeight = viewport.height ?? window.innerHeight;
|
|
278
|
+
|
|
279
|
+
const updateState = (keyboardHeight: number, keyboardOpen: boolean) => {
|
|
280
|
+
setOpen(keyboardOpen);
|
|
281
|
+
setHeight(keyboardHeight);
|
|
282
|
+
|
|
283
|
+
const vvh = initialHeight - keyboardHeight;
|
|
284
|
+
document.documentElement.style.setProperty('--vvh', `${vvh}px`);
|
|
285
|
+
document.documentElement.style.setProperty('--kb-height', `${keyboardHeight}px`);
|
|
286
|
+
document.documentElement.style.setProperty('--kb-open', keyboardOpen ? '1' : '0');
|
|
287
|
+
log.info('viewport size', { initialHeight, vvh, keyboardHeight, keyboardOpen });
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return combine(
|
|
291
|
+
// Handler for native iOS keyboard events (from KeyboardObserver.swift).
|
|
292
|
+
addEventListener(
|
|
293
|
+
window,
|
|
294
|
+
'keyboard' as any,
|
|
295
|
+
(event: CustomEvent<{ type: 'show' | 'hide'; height: number; duration: number }>) => {
|
|
296
|
+
const { type, height } = event.detail;
|
|
297
|
+
log.info('keyboard event', { type, height });
|
|
298
|
+
updateState(height, type === 'show');
|
|
299
|
+
},
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
}, []);
|
|
303
|
+
|
|
304
|
+
return { open, height };
|
|
305
|
+
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { createContext } from '@radix-ui/react-context';
|
|
6
6
|
import React, { type PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { Surface } from '@dxos/app-framework/
|
|
8
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
9
9
|
import { Popover, type PopoverContentInteractOutsideEvent, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
10
10
|
import { Card } from '@dxos/react-ui-mosaic';
|
|
11
11
|
|
|
@@ -100,18 +100,18 @@ export const PopoverContent = () => {
|
|
|
100
100
|
onEscapeKeyDown={handleInteractOutside}
|
|
101
101
|
>
|
|
102
102
|
<Popover.Viewport>
|
|
103
|
+
{state.popoverKind === 'base' && <Surface.Surface role='popover' data={state.popoverContent} limit={1} />}
|
|
103
104
|
{state.popoverKind === 'card' && (
|
|
104
|
-
<Card.Root>
|
|
105
|
+
<Card.Root border={false} classNames='popover-card-max-width'>
|
|
105
106
|
<Card.Toolbar>
|
|
106
107
|
{/* TODO(wittjosiah): Cleaner way to handle no drag handle in toolbar? */}
|
|
107
108
|
<span />
|
|
108
109
|
{state.popoverTitle ? <Card.Title>{toLocalizedString(state.popoverTitle, t)}</Card.Title> : <span />}
|
|
109
110
|
<Card.Close onClick={handleClose} />
|
|
110
111
|
</Card.Toolbar>
|
|
111
|
-
<Surface role='card--content' data={state.popoverContent} limit={1} />
|
|
112
|
+
<Surface.Surface role='card--content' data={state.popoverContent} limit={1} />
|
|
112
113
|
</Card.Root>
|
|
113
114
|
)}
|
|
114
|
-
{state.popoverKind === 'base' && <Surface role='popover' data={state.popoverContent} limit={1} />}
|
|
115
115
|
</Popover.Viewport>
|
|
116
116
|
<Popover.Arrow />
|
|
117
117
|
</Popover.Content>
|