@owdproject/react 4.0.0-alpha.3 → 4.0.0-alpha.4
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/index.d.mts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.mjs +99 -0
- package/package.json +11 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ApplicationConfig, WindowConfig, Desktop, WindowInstance, ApplicationInstance, WindowBounds, DesktopWorkareaRect, DesktopSnapshot, ResizeDirection, WindowState, WindowManager } from '@owdproject/core';
|
|
2
|
+
export * from '@owdproject/core';
|
|
3
|
+
import { SnapZoneHint } from '@owdproject/core/types';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { ComponentType } from 'react';
|
|
6
|
+
|
|
7
|
+
/** Runtime props shared by React application windows, independently of a theme. */
|
|
8
|
+
interface ReactApplicationWindowProps {
|
|
9
|
+
desktop: Desktop;
|
|
10
|
+
window: WindowInstance;
|
|
11
|
+
application: ApplicationInstance;
|
|
12
|
+
/** Closes through the owning application, including its cancellable hooks. */
|
|
13
|
+
close: () => Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
interface ReactApplicationWindowConfig extends Omit<WindowConfig, 'component'> {
|
|
16
|
+
component: ComponentType<ReactApplicationWindowProps>;
|
|
17
|
+
}
|
|
18
|
+
interface ReactApplicationConfig extends Omit<ApplicationConfig, 'windows'> {
|
|
19
|
+
windows?: Record<string, ReactApplicationWindowConfig>;
|
|
20
|
+
}
|
|
21
|
+
/** Registration and launch retain the engine's lifecycle and singleton behavior. */
|
|
22
|
+
declare function registerReactApplication(desktop: Desktop, config: ReactApplicationConfig): ApplicationInstance;
|
|
23
|
+
declare function closeReactApplicationWindow(desktop: Desktop, window: WindowInstance): Promise<boolean>;
|
|
24
|
+
/** Render the component from this window's registered model, without a theme app catalog. */
|
|
25
|
+
declare function ReactApplicationWindow({ desktop, window }: {
|
|
26
|
+
desktop: Desktop;
|
|
27
|
+
window: WindowInstance;
|
|
28
|
+
}): react.ReactElement<ReactApplicationWindowProps, string | react.JSXElementConstructor<any>> | null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @owdproject/react
|
|
32
|
+
* Official React 18/19 reactive adapter for @owdproject/core using useSyncExternalStore.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
declare function useDesktop(desktop: Desktop): DesktopSnapshot & {
|
|
36
|
+
desktop: Desktop;
|
|
37
|
+
};
|
|
38
|
+
declare function useWindowManager(manager: WindowManager): {
|
|
39
|
+
windows: WindowInstance[];
|
|
40
|
+
focused: WindowInstance | undefined;
|
|
41
|
+
manager: WindowManager;
|
|
42
|
+
};
|
|
43
|
+
declare function useWindowInstance(instance: WindowInstance): {
|
|
44
|
+
state: WindowState;
|
|
45
|
+
instance: WindowInstance;
|
|
46
|
+
};
|
|
47
|
+
interface ReactDesktopDragOptions {
|
|
48
|
+
getBounds: () => WindowBounds;
|
|
49
|
+
getWorkarea?: () => DesktopWorkareaRect | undefined;
|
|
50
|
+
onStart?: () => void;
|
|
51
|
+
onMove?: (bounds: WindowBounds, snapZone: SnapZoneHint | null) => void;
|
|
52
|
+
onEnd?: (finalBounds: WindowBounds, snapZone: SnapZoneHint | null) => void;
|
|
53
|
+
onCancel?: () => void;
|
|
54
|
+
}
|
|
55
|
+
declare function useDesktopDrag(options: ReactDesktopDragOptions): {
|
|
56
|
+
startDrag: (event: PointerEvent) => () => void;
|
|
57
|
+
};
|
|
58
|
+
interface ReactDesktopResizeOptions {
|
|
59
|
+
getBounds: () => WindowBounds;
|
|
60
|
+
minWidth?: number;
|
|
61
|
+
minHeight?: number;
|
|
62
|
+
maxWidth?: number;
|
|
63
|
+
maxHeight?: number;
|
|
64
|
+
onStart?: () => void;
|
|
65
|
+
onMove?: (bounds: WindowBounds) => void;
|
|
66
|
+
onEnd?: (finalBounds: WindowBounds) => void;
|
|
67
|
+
onCancel?: () => void;
|
|
68
|
+
}
|
|
69
|
+
declare function useDesktopResize(options: ReactDesktopResizeOptions): {
|
|
70
|
+
startResize: (event: PointerEvent, direction: ResizeDirection) => () => void;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { ReactApplicationWindow, closeReactApplicationWindow, registerReactApplication, useDesktop, useDesktopDrag, useDesktopResize, useWindowInstance, useWindowManager };
|
|
74
|
+
export type { ReactApplicationConfig, ReactApplicationWindowConfig, ReactApplicationWindowProps, ReactDesktopDragOptions, ReactDesktopResizeOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ApplicationConfig, WindowConfig, Desktop, WindowInstance, ApplicationInstance, WindowBounds, DesktopWorkareaRect, DesktopSnapshot, ResizeDirection, WindowState, WindowManager } from '@owdproject/core';
|
|
2
|
+
export * from '@owdproject/core';
|
|
3
|
+
import { SnapZoneHint } from '@owdproject/core/types';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { ComponentType } from 'react';
|
|
6
|
+
|
|
7
|
+
/** Runtime props shared by React application windows, independently of a theme. */
|
|
8
|
+
interface ReactApplicationWindowProps {
|
|
9
|
+
desktop: Desktop;
|
|
10
|
+
window: WindowInstance;
|
|
11
|
+
application: ApplicationInstance;
|
|
12
|
+
/** Closes through the owning application, including its cancellable hooks. */
|
|
13
|
+
close: () => Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
interface ReactApplicationWindowConfig extends Omit<WindowConfig, 'component'> {
|
|
16
|
+
component: ComponentType<ReactApplicationWindowProps>;
|
|
17
|
+
}
|
|
18
|
+
interface ReactApplicationConfig extends Omit<ApplicationConfig, 'windows'> {
|
|
19
|
+
windows?: Record<string, ReactApplicationWindowConfig>;
|
|
20
|
+
}
|
|
21
|
+
/** Registration and launch retain the engine's lifecycle and singleton behavior. */
|
|
22
|
+
declare function registerReactApplication(desktop: Desktop, config: ReactApplicationConfig): ApplicationInstance;
|
|
23
|
+
declare function closeReactApplicationWindow(desktop: Desktop, window: WindowInstance): Promise<boolean>;
|
|
24
|
+
/** Render the component from this window's registered model, without a theme app catalog. */
|
|
25
|
+
declare function ReactApplicationWindow({ desktop, window }: {
|
|
26
|
+
desktop: Desktop;
|
|
27
|
+
window: WindowInstance;
|
|
28
|
+
}): react.ReactElement<ReactApplicationWindowProps, string | react.JSXElementConstructor<any>> | null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @owdproject/react
|
|
32
|
+
* Official React 18/19 reactive adapter for @owdproject/core using useSyncExternalStore.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
declare function useDesktop(desktop: Desktop): DesktopSnapshot & {
|
|
36
|
+
desktop: Desktop;
|
|
37
|
+
};
|
|
38
|
+
declare function useWindowManager(manager: WindowManager): {
|
|
39
|
+
windows: WindowInstance[];
|
|
40
|
+
focused: WindowInstance | undefined;
|
|
41
|
+
manager: WindowManager;
|
|
42
|
+
};
|
|
43
|
+
declare function useWindowInstance(instance: WindowInstance): {
|
|
44
|
+
state: WindowState;
|
|
45
|
+
instance: WindowInstance;
|
|
46
|
+
};
|
|
47
|
+
interface ReactDesktopDragOptions {
|
|
48
|
+
getBounds: () => WindowBounds;
|
|
49
|
+
getWorkarea?: () => DesktopWorkareaRect | undefined;
|
|
50
|
+
onStart?: () => void;
|
|
51
|
+
onMove?: (bounds: WindowBounds, snapZone: SnapZoneHint | null) => void;
|
|
52
|
+
onEnd?: (finalBounds: WindowBounds, snapZone: SnapZoneHint | null) => void;
|
|
53
|
+
onCancel?: () => void;
|
|
54
|
+
}
|
|
55
|
+
declare function useDesktopDrag(options: ReactDesktopDragOptions): {
|
|
56
|
+
startDrag: (event: PointerEvent) => () => void;
|
|
57
|
+
};
|
|
58
|
+
interface ReactDesktopResizeOptions {
|
|
59
|
+
getBounds: () => WindowBounds;
|
|
60
|
+
minWidth?: number;
|
|
61
|
+
minHeight?: number;
|
|
62
|
+
maxWidth?: number;
|
|
63
|
+
maxHeight?: number;
|
|
64
|
+
onStart?: () => void;
|
|
65
|
+
onMove?: (bounds: WindowBounds) => void;
|
|
66
|
+
onEnd?: (finalBounds: WindowBounds) => void;
|
|
67
|
+
onCancel?: () => void;
|
|
68
|
+
}
|
|
69
|
+
declare function useDesktopResize(options: ReactDesktopResizeOptions): {
|
|
70
|
+
startResize: (event: PointerEvent, direction: ResizeDirection) => () => void;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { ReactApplicationWindow, closeReactApplicationWindow, registerReactApplication, useDesktop, useDesktopDrag, useDesktopResize, useWindowInstance, useWindowManager };
|
|
74
|
+
export type { ReactApplicationConfig, ReactApplicationWindowConfig, ReactApplicationWindowProps, ReactDesktopDragOptions, ReactDesktopResizeOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createElement, useCallback, useSyncExternalStore } from 'react';
|
|
2
|
+
import { DesktopPointerSession } from '@owdproject/core';
|
|
3
|
+
export * from '@owdproject/core';
|
|
4
|
+
|
|
5
|
+
function registerReactApplication(desktop, config) {
|
|
6
|
+
return desktop.applications.register(config);
|
|
7
|
+
}
|
|
8
|
+
async function closeReactApplicationWindow(desktop, window) {
|
|
9
|
+
const application = window.applicationId ? desktop.applications.get(window.applicationId) : void 0;
|
|
10
|
+
return application ? application.closeWindow(window.id) : desktop.windows.closeWindow(window.id);
|
|
11
|
+
}
|
|
12
|
+
function ReactApplicationWindow({ desktop, window }) {
|
|
13
|
+
const application = window.applicationId ? desktop.applications.get(window.applicationId) : void 0;
|
|
14
|
+
const Component = window.config.component;
|
|
15
|
+
if (!application || !Component) return null;
|
|
16
|
+
return createElement(Component, {
|
|
17
|
+
desktop,
|
|
18
|
+
window,
|
|
19
|
+
application,
|
|
20
|
+
close: () => closeReactApplicationWindow(desktop, window)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function useDesktop(desktop) {
|
|
25
|
+
const subscribe = useCallback(
|
|
26
|
+
(onStoreChange) => desktop.subscribe(onStoreChange),
|
|
27
|
+
[desktop]
|
|
28
|
+
);
|
|
29
|
+
const getSnapshot = useCallback(() => desktop.getSnapshot(), [desktop]);
|
|
30
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
31
|
+
return {
|
|
32
|
+
desktop,
|
|
33
|
+
...snapshot
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function useWindowManager(manager) {
|
|
37
|
+
const subscribe = useCallback(
|
|
38
|
+
(onStoreChange) => manager.subscribe(onStoreChange),
|
|
39
|
+
[manager]
|
|
40
|
+
);
|
|
41
|
+
const getSnapshot = useCallback(() => manager.getSnapshot(), [manager]);
|
|
42
|
+
const windows = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
43
|
+
const focused = windows.find((w) => w.state.focused);
|
|
44
|
+
return {
|
|
45
|
+
windows,
|
|
46
|
+
focused,
|
|
47
|
+
manager
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function useWindowInstance(instance) {
|
|
51
|
+
const subscribe = useCallback(
|
|
52
|
+
(onStoreChange) => instance.subscribe(onStoreChange),
|
|
53
|
+
[instance]
|
|
54
|
+
);
|
|
55
|
+
const getSnapshot = useCallback(() => instance.getSnapshot(), [instance]);
|
|
56
|
+
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
57
|
+
return {
|
|
58
|
+
state,
|
|
59
|
+
instance
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function useDesktopDrag(options) {
|
|
63
|
+
const startDrag = useCallback(
|
|
64
|
+
(event) => {
|
|
65
|
+
return DesktopPointerSession.startDrag(event, {
|
|
66
|
+
initialBounds: options.getBounds(),
|
|
67
|
+
workarea: options.getWorkarea?.(),
|
|
68
|
+
onStart: options.onStart,
|
|
69
|
+
onMove: options.onMove,
|
|
70
|
+
onEnd: options.onEnd,
|
|
71
|
+
onCancel: options.onCancel
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
[options]
|
|
75
|
+
);
|
|
76
|
+
return { startDrag };
|
|
77
|
+
}
|
|
78
|
+
function useDesktopResize(options) {
|
|
79
|
+
const startResize = useCallback(
|
|
80
|
+
(event, direction) => {
|
|
81
|
+
return DesktopPointerSession.startResize(event, {
|
|
82
|
+
direction,
|
|
83
|
+
initialBounds: options.getBounds(),
|
|
84
|
+
minWidth: options.minWidth,
|
|
85
|
+
minHeight: options.minHeight,
|
|
86
|
+
maxWidth: options.maxWidth,
|
|
87
|
+
maxHeight: options.maxHeight,
|
|
88
|
+
onStart: options.onStart,
|
|
89
|
+
onMove: options.onMove,
|
|
90
|
+
onEnd: options.onEnd,
|
|
91
|
+
onCancel: options.onCancel
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
[options]
|
|
95
|
+
);
|
|
96
|
+
return { startResize };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { ReactApplicationWindow, closeReactApplicationWindow, registerReactApplication, useDesktop, useDesktopDrag, useDesktopResize, useWindowInstance, useWindowManager };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owdproject/react",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
4
|
-
"description": "Official React 18/19 adapter for @owdproject/
|
|
3
|
+
"version": "4.0.0-alpha.4",
|
|
4
|
+
"description": "Official React 18/19 adapter for @owdproject/core",
|
|
5
5
|
"homepage": "https://github.com/owdproject/react#readme",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"dist",
|
|
21
21
|
"README.md"
|
|
22
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "unbuild",
|
|
25
|
+
"prepack": "unbuild"
|
|
26
|
+
},
|
|
23
27
|
"publishConfig": {
|
|
24
28
|
"access": "public",
|
|
25
29
|
"tag": "alpha",
|
|
@@ -33,9 +37,13 @@
|
|
|
33
37
|
}
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@owdproject/
|
|
40
|
+
"@owdproject/core": "^4.0.0-alpha.3"
|
|
37
41
|
},
|
|
38
42
|
"peerDependencies": {
|
|
39
43
|
"react": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"unbuild": "^3.6.1",
|
|
47
|
+
"typescript": "~6.0.3"
|
|
40
48
|
}
|
|
41
49
|
}
|