@go-go-golems/os-scripting 0.1.1 → 0.1.2
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/README.md +56 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,28 @@ npm install react react-dom react-redux @reduxjs/toolkit
|
|
|
13
13
|
|
|
14
14
|
`react`, `react-dom`, `react-redux`, and `@reduxjs/toolkit` are peer dependencies.
|
|
15
15
|
|
|
16
|
+
## Bundler note
|
|
17
|
+
|
|
18
|
+
Starting with `@go-go-golems/os-scripting@0.1.1`, package-internal QuickJS bootstrap code is shipped as ordinary generated JavaScript string modules. Consumers do **not** need package-specific Vite dependency-optimization workarounds such as:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
optimizeDeps: {
|
|
22
|
+
exclude: ['@go-go-golems/os-scripting'],
|
|
23
|
+
include: ['debug'],
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
If your own application imports local VM bundle files with Vite raw imports, for example `import code from './bundle.vm.js?raw'`, keep a local declaration such as:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
declare module '*.vm.js?raw' {
|
|
31
|
+
const source: string;
|
|
32
|
+
export default source;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
That declaration is for your app-authored VM bundles only; it is not required because of package internals.
|
|
37
|
+
|
|
16
38
|
## Main exports
|
|
17
39
|
|
|
18
40
|
```ts
|
|
@@ -65,25 +87,42 @@ export function AppProviders({ children }: { children: React.ReactNode }) {
|
|
|
65
87
|
}
|
|
66
88
|
```
|
|
67
89
|
|
|
68
|
-
Use `createAppStore` when rendering VM surfaces. It includes `runtimeSessions`, runtime lifecycle middleware, and artifact projection middleware. For shell-only apps that never render VM surfaces, `createLauncherStore` from `@go-go-golems/os-shell` is lighter.
|
|
90
|
+
Use `createAppStore` when rendering VM surfaces. It includes `runtimeSessions`, `notifications`, runtime lifecycle middleware, and artifact projection middleware. For shell-only apps that never render VM surfaces, `createLauncherStore` from `@go-go-golems/os-shell` is lighter.
|
|
69
91
|
|
|
70
92
|
## Minimal surface host
|
|
71
93
|
|
|
72
94
|
```tsx
|
|
73
|
-
import {
|
|
95
|
+
import { clearToast, selectToast, Toast } from '@go-go-golems/os-core';
|
|
96
|
+
import { RuntimeSurfaceSessionHost, createAppStore } from '@go-go-golems/os-scripting';
|
|
74
97
|
import type { RuntimeBundleDefinition } from '@go-go-golems/os-shell';
|
|
98
|
+
import { Provider, useDispatch, useSelector } from 'react-redux';
|
|
99
|
+
|
|
100
|
+
const { store } = createAppStore({});
|
|
101
|
+
|
|
102
|
+
function RuntimeToastHost() {
|
|
103
|
+
const dispatch = useDispatch();
|
|
104
|
+
const toast = useSelector((state) => selectToast(state as any));
|
|
105
|
+
|
|
106
|
+
if (!toast) return null;
|
|
107
|
+
return <Toast message={toast} onDone={() => dispatch(clearToast())} />;
|
|
108
|
+
}
|
|
75
109
|
|
|
76
110
|
export function RuntimeWindow({ bundle }: { bundle: RuntimeBundleDefinition }) {
|
|
77
111
|
return (
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
112
|
+
<Provider store={store}>
|
|
113
|
+
<RuntimeSurfaceSessionHost
|
|
114
|
+
windowId="window:demo"
|
|
115
|
+
sessionId="session:demo"
|
|
116
|
+
bundle={bundle}
|
|
117
|
+
/>
|
|
118
|
+
<RuntimeToastHost />
|
|
119
|
+
</Provider>
|
|
83
120
|
);
|
|
84
121
|
}
|
|
85
122
|
```
|
|
86
123
|
|
|
124
|
+
`RuntimeSurfaceSessionHost` routes host effects such as `notify.show` into Redux. Mount host chrome such as `Toast` inside the same `Provider` if your runtime bundles use notification capabilities.
|
|
125
|
+
|
|
87
126
|
## Runtime bundle shape
|
|
88
127
|
|
|
89
128
|
Host TypeScript:
|
|
@@ -100,7 +139,7 @@ export const BUNDLE: RuntimeBundleDefinition = {
|
|
|
100
139
|
plugin: {
|
|
101
140
|
packageIds: ['ui'],
|
|
102
141
|
bundleCode,
|
|
103
|
-
capabilities: { domain: [], system: [] },
|
|
142
|
+
capabilities: { domain: [], system: ['notify.show'] },
|
|
104
143
|
},
|
|
105
144
|
surfaces: {
|
|
106
145
|
home: {
|
|
@@ -128,8 +167,17 @@ defineRuntimeBundle(({ ui }) => ({
|
|
|
128
167
|
return ui.panel([
|
|
129
168
|
ui.text('Hello from QuickJS'),
|
|
130
169
|
ui.text('Session: ' + state.self.sessionId),
|
|
170
|
+
ui.button('Notify host', { onClick: { handler: 'notify' } }),
|
|
131
171
|
]);
|
|
132
172
|
},
|
|
173
|
+
handlers: {
|
|
174
|
+
notify(ctx) {
|
|
175
|
+
ctx.dispatch({
|
|
176
|
+
type: 'notify.show',
|
|
177
|
+
payload: { message: 'Hello from the VM' },
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
},
|
|
133
181
|
},
|
|
134
182
|
},
|
|
135
183
|
}));
|