@owdproject/react 0.0.0-stage → 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/LICENSE +20 -0
- package/README.md +67 -2
- package/dist/index.d.mts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.mjs +99 -0
- package/package.json +47 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Open Web Desktop Team ~ github.com/owdproject
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
19
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
20
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<h1>@owdproject/react</h1>
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<strong>Official React 18 & 19 Adapter for Open Web Desktop.</strong><br /><br />
|
|
7
|
+
Concurrent-safe <code>useSyncExternalStore</code> hooks and pointer drag/resize<br />
|
|
8
|
+
bindings powered by <code>@owdproject/core</code>.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<br />
|
|
12
|
+
|
|
13
|
+
<p>
|
|
14
|
+
<a href="https://npmjs.com/package/@owdproject/react"><img src="https://img.shields.io/npm/v/@owdproject/react/alpha.svg?style=flat&colorA=020420&colorB=00DC82" alt="npm version" /></a>
|
|
15
|
+
<a href="https://react.dev"><img src="https://img.shields.io/badge/React-020420?logo=react" alt="React" /></a>
|
|
16
|
+
<a href="https://github.com/owdproject/core/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-00DC82.svg?style=flat&colorA=020420&colorB=00DC82" alt="License" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
`@owdproject/react` (`4.0.0-alpha.0`) connects [`@owdproject/core`](https://npmjs.com/package/@owdproject/core)'s frozen immutable snapshots (`Object.freeze`) directly to React 18/19 `useSyncExternalStore` with zero state tearing.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add @owdproject/core@4.0.0-alpha.0 @owdproject/react@4.0.0-alpha.0
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { createDesktop, useDesktop, useWindowInstance, useDesktopDrag } from '@owdproject/react'
|
|
37
|
+
|
|
38
|
+
const desktop = createDesktop()
|
|
39
|
+
|
|
40
|
+
export function DesktopShell() {
|
|
41
|
+
const { windows, focusedWindow } = useDesktop(desktop)
|
|
42
|
+
return (
|
|
43
|
+
<div>
|
|
44
|
+
{windows.map((win) => (
|
|
45
|
+
<div key={win.id}>{win.config.title}</div>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Exported Hooks
|
|
55
|
+
|
|
56
|
+
| Hook | Description |
|
|
57
|
+
| :--- | :--- |
|
|
58
|
+
| **`useDesktop(instanceOrOptions?)`** | Subscribes to a `Desktop` instance via `useSyncExternalStore`. |
|
|
59
|
+
| **`useWindowManager(manager?)`** | Subscribes to `WindowManager` window lists and focus state. |
|
|
60
|
+
| **`useWindowInstance(instance)`** | Subscribes to an individual `WindowInstance` actor. |
|
|
61
|
+
| **`useDesktopDrag(options)`** | Returns `{ isDragging, activeSnapZone, startDrag, cancelDrag }`. |
|
|
62
|
+
| **`useDesktopResize(options)`** | Returns `{ isResizing, startResize, cancelResize }`. |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
[MIT](https://opensource.org/licenses/MIT)
|
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,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owdproject/react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.0.0-alpha.4",
|
|
4
|
+
"description": "Official React 18/19 adapter for @owdproject/core",
|
|
5
|
+
"homepage": "https://github.com/owdproject/react#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/owdproject/react.git"
|
|
9
|
+
},
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Diego Villa (@dxlliv)",
|
|
12
|
+
"url": "https://github.com/dxlliv"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.mjs",
|
|
17
|
+
"module": "./dist/index.mjs",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "unbuild",
|
|
25
|
+
"prepack": "unbuild"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"tag": "alpha",
|
|
30
|
+
"registry": "https://registry.npmjs.org/"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.mjs",
|
|
36
|
+
"default": "./dist/index.mjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@owdproject/core": "^4.0.0-alpha.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"unbuild": "^3.6.1",
|
|
47
|
+
"typescript": "~6.0.3"
|
|
48
|
+
}
|
|
49
|
+
}
|