@immediately-run/sdk 0.1.5 → 0.2.0
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/contribute.cjs +32 -0
- package/dist/contribute.cjs.map +1 -0
- package/dist/contribute.d.cts +100 -0
- package/dist/contribute.d.ts +100 -0
- package/dist/contribute.js +8 -0
- package/dist/contribute.js.map +1 -0
- package/dist/editorContext.cjs +46 -0
- package/dist/editorContext.cjs.map +1 -0
- package/dist/editorContext.d.cts +32 -0
- package/dist/editorContext.d.ts +32 -0
- package/dist/editorContext.js +20 -0
- package/dist/editorContext.js.map +1 -0
- package/dist/formFactor.cjs +46 -0
- package/dist/formFactor.cjs.map +1 -0
- package/dist/formFactor.d.cts +29 -0
- package/dist/formFactor.d.ts +29 -0
- package/dist/formFactor.js +20 -0
- package/dist/formFactor.js.map +1 -0
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/mounts.cjs +18 -6
- package/dist/mounts.cjs.map +1 -1
- package/dist/mounts.d.cts +25 -3
- package/dist/mounts.d.ts +25 -3
- package/dist/mounts.js +15 -6
- package/dist/mounts.js.map +1 -1
- package/dist/protocolStream.cjs +87 -0
- package/dist/protocolStream.cjs.map +1 -0
- package/dist/protocolStream.d.cts +44 -0
- package/dist/protocolStream.d.ts +44 -0
- package/dist/protocolStream.js +61 -0
- package/dist/protocolStream.js.map +1 -0
- package/dist/theme.cjs +57 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +38 -0
- package/dist/theme.d.ts +38 -0
- package/dist/theme.js +30 -0
- package/dist/theme.js.map +1 -0
- package/package.json +1 -1
package/dist/theme.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host UI theme, mirrored from the immediately.run host window into the
|
|
3
|
+
* sandbox. Your app can read this to render in step with the host chrome
|
|
4
|
+
* (light / dark).
|
|
5
|
+
*
|
|
6
|
+
* This is the baseline `theme:read` capability — every app may read it. Changing
|
|
7
|
+
* the host theme is a separate, elevated action (`theme:set`), available only to
|
|
8
|
+
* the theme-toggle system app.
|
|
9
|
+
*/
|
|
10
|
+
type HostTheme = 'light' | 'dark';
|
|
11
|
+
/**
|
|
12
|
+
* Returns the current host theme. Poll this for a one-off read; use
|
|
13
|
+
* {@link onHostThemeChange} or {@link useHostTheme} to react to changes.
|
|
14
|
+
*/
|
|
15
|
+
declare const getHostTheme: () => HostTheme;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to host theme changes. The listener is invoked immediately with the
|
|
18
|
+
* current theme, then again on every change. Returns an unsubscribe fn.
|
|
19
|
+
*/
|
|
20
|
+
declare const onHostThemeChange: (listener: (theme: HostTheme) => void) => (() => void);
|
|
21
|
+
/**
|
|
22
|
+
* React hook returning the current host theme, re-rendering when it changes.
|
|
23
|
+
* The recommended way to implement an app's own `useTheme`: follow the host,
|
|
24
|
+
* allow a local override.
|
|
25
|
+
*/
|
|
26
|
+
declare const useHostTheme: () => HostTheme;
|
|
27
|
+
/**
|
|
28
|
+
* Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host
|
|
29
|
+
* applies it and re-pushes the new value to every `theme:read` iframe, so your
|
|
30
|
+
* own {@link useHostTheme} confirms the change (the loop closes with no special
|
|
31
|
+
* case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may
|
|
32
|
+
* call this; any other app is rejected host-side with a `forbidden`
|
|
33
|
+
* {@link Error} (carrying `.code`), regardless of what the app claims. Update
|
|
34
|
+
* optimistically and let the re-push confirm.
|
|
35
|
+
*/
|
|
36
|
+
declare const setHostTheme: (theme: HostTheme) => Promise<void>;
|
|
37
|
+
|
|
38
|
+
export { type HostTheme, getHostTheme, onHostThemeChange, setHostTheme, useHostTheme };
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host UI theme, mirrored from the immediately.run host window into the
|
|
3
|
+
* sandbox. Your app can read this to render in step with the host chrome
|
|
4
|
+
* (light / dark).
|
|
5
|
+
*
|
|
6
|
+
* This is the baseline `theme:read` capability — every app may read it. Changing
|
|
7
|
+
* the host theme is a separate, elevated action (`theme:set`), available only to
|
|
8
|
+
* the theme-toggle system app.
|
|
9
|
+
*/
|
|
10
|
+
type HostTheme = 'light' | 'dark';
|
|
11
|
+
/**
|
|
12
|
+
* Returns the current host theme. Poll this for a one-off read; use
|
|
13
|
+
* {@link onHostThemeChange} or {@link useHostTheme} to react to changes.
|
|
14
|
+
*/
|
|
15
|
+
declare const getHostTheme: () => HostTheme;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to host theme changes. The listener is invoked immediately with the
|
|
18
|
+
* current theme, then again on every change. Returns an unsubscribe fn.
|
|
19
|
+
*/
|
|
20
|
+
declare const onHostThemeChange: (listener: (theme: HostTheme) => void) => (() => void);
|
|
21
|
+
/**
|
|
22
|
+
* React hook returning the current host theme, re-rendering when it changes.
|
|
23
|
+
* The recommended way to implement an app's own `useTheme`: follow the host,
|
|
24
|
+
* allow a local override.
|
|
25
|
+
*/
|
|
26
|
+
declare const useHostTheme: () => HostTheme;
|
|
27
|
+
/**
|
|
28
|
+
* Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host
|
|
29
|
+
* applies it and re-pushes the new value to every `theme:read` iframe, so your
|
|
30
|
+
* own {@link useHostTheme} confirms the change (the loop closes with no special
|
|
31
|
+
* case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may
|
|
32
|
+
* call this; any other app is rejected host-side with a `forbidden`
|
|
33
|
+
* {@link Error} (carrying `.code`), regardless of what the app claims. Update
|
|
34
|
+
* optimistically and let the re-push confirm.
|
|
35
|
+
*/
|
|
36
|
+
declare const setHostTheme: (theme: HostTheme) => Promise<void>;
|
|
37
|
+
|
|
38
|
+
export { type HostTheme, getHostTheme, onHostThemeChange, setHostTheme, useHostTheme };
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { protocolRequest } from "./sandboxUtils";
|
|
3
|
+
const themeService = () => {
|
|
4
|
+
return module.evaluation.module.bundler.theme;
|
|
5
|
+
};
|
|
6
|
+
const getHostTheme = () => themeService().getTheme();
|
|
7
|
+
const onHostThemeChange = (listener) => {
|
|
8
|
+
const disposable = themeService().onChange(listener);
|
|
9
|
+
return () => disposable.dispose();
|
|
10
|
+
};
|
|
11
|
+
const useHostTheme = () => {
|
|
12
|
+
const [theme, setTheme] = useState(getHostTheme);
|
|
13
|
+
useEffect(() => onHostThemeChange(setTheme), []);
|
|
14
|
+
return theme;
|
|
15
|
+
};
|
|
16
|
+
const setHostTheme = async (theme) => {
|
|
17
|
+
const res = await protocolRequest("theme", "set", [{ theme }]);
|
|
18
|
+
if (!res || res.ok !== true) {
|
|
19
|
+
const err = new Error(res?.message ?? "setHostTheme failed");
|
|
20
|
+
err.code = (res && "code" in res ? res.code : void 0) ?? "unknown";
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
getHostTheme,
|
|
26
|
+
onHostThemeChange,
|
|
27
|
+
setHostTheme,
|
|
28
|
+
useHostTheme
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/theme.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { protocolRequest } from './sandboxUtils';\n\n/**\n * The host UI theme, mirrored from the immediately.run host window into the\n * sandbox. Your app can read this to render in step with the host chrome\n * (light / dark).\n *\n * This is the baseline `theme:read` capability — every app may read it. Changing\n * the host theme is a separate, elevated action (`theme:set`), available only to\n * the theme-toggle system app.\n */\nexport type HostTheme = 'light' | 'dark';\n\ninterface ThemeService {\n getTheme(): HostTheme;\n onChange(listener: (theme: HostTheme) => void): { dispose(): void };\n}\n\n// `module.evaluation.module.bundler.theme` is the sandbox bundler injected into\n// the evaluation context (same path the other SDK helpers use for `auth`).\nconst themeService = (): ThemeService => {\n // @ts-ignore - injected by the sandbox runtime\n return module.evaluation.module.bundler.theme;\n};\n\n/**\n * Returns the current host theme. Poll this for a one-off read; use\n * {@link onHostThemeChange} or {@link useHostTheme} to react to changes.\n */\nexport const getHostTheme = (): HostTheme => themeService().getTheme();\n\n/**\n * Subscribe to host theme changes. The listener is invoked immediately with the\n * current theme, then again on every change. Returns an unsubscribe fn.\n */\nexport const onHostThemeChange = (\n listener: (theme: HostTheme) => void,\n): (() => void) => {\n const disposable = themeService().onChange(listener);\n return () => disposable.dispose();\n};\n\n/**\n * React hook returning the current host theme, re-rendering when it changes.\n * The recommended way to implement an app's own `useTheme`: follow the host,\n * allow a local override.\n */\nexport const useHostTheme = (): HostTheme => {\n const [theme, setTheme] = useState<HostTheme>(getHostTheme);\n useEffect(() => onHostThemeChange(setTheme), []);\n return theme;\n};\n\n/**\n * Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host\n * applies it and re-pushes the new value to every `theme:read` iframe, so your\n * own {@link useHostTheme} confirms the change (the loop closes with no special\n * case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may\n * call this; any other app is rejected host-side with a `forbidden`\n * {@link Error} (carrying `.code`), regardless of what the app claims. Update\n * optimistically and let the re-push confirm.\n */\nexport const setHostTheme = async (theme: HostTheme): Promise<void> => {\n const res = (await protocolRequest('theme', 'set', [{ theme }])) as\n | { ok: true; data?: unknown }\n | { ok: false; code?: string; message?: string }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? 'setHostTheme failed') as Error & {\n code?: string;\n };\n err.code = (res && 'code' in res ? res.code : undefined) ?? 'unknown';\n throw err;\n }\n};\n"],"mappings":"AAAA,SAAS,WAAW,gBAAgB;AACpC,SAAS,uBAAuB;AAoBhC,MAAM,eAAe,MAAoB;AAEvC,SAAO,OAAO,WAAW,OAAO,QAAQ;AAC1C;AAMO,MAAM,eAAe,MAAiB,aAAa,EAAE,SAAS;AAM9D,MAAM,oBAAoB,CAC/B,aACiB;AACjB,QAAM,aAAa,aAAa,EAAE,SAAS,QAAQ;AACnD,SAAO,MAAM,WAAW,QAAQ;AAClC;AAOO,MAAM,eAAe,MAAiB;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB,YAAY;AAC1D,YAAU,MAAM,kBAAkB,QAAQ,GAAG,CAAC,CAAC;AAC/C,SAAO;AACT;AAWO,MAAM,eAAe,OAAO,UAAoC;AACrE,QAAM,MAAO,MAAM,gBAAgB,SAAS,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AAI9D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,qBAAqB;AAG3D,QAAI,QAAQ,OAAO,UAAU,MAAM,IAAI,OAAO,WAAc;AAC5D,UAAM;AAAA,EACR;AACF;","names":[]}
|
package/package.json
CHANGED