@opentray/ext-webview 0.0.0 → 0.1.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/README.md +8 -0
- package/dist/index.d.mts +66 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +32 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -9,3 +9,11 @@ Official rich popup extension for OpenTray.
|
|
|
9
9
|
- Route WebView messages through the owning `surfaceId` / `trayId`.
|
|
10
10
|
|
|
11
11
|
This package is an extension atom. It must not become the owner of core tray lifecycle.
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
Run a broker-free example that sends WebView `show`, `navigate`, `postMessage`, and `hide` commands through the normal OpenTray extension command path:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm --filter @opentray/ext-webview example:webview
|
|
19
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TrayHandle } from "opentray";
|
|
2
|
+
|
|
3
|
+
//#region ../spec/src/index.d.ts
|
|
4
|
+
type SurfaceId = string;
|
|
5
|
+
type TrayId = string;
|
|
6
|
+
interface Rect {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
interface ExtensionScope {
|
|
13
|
+
surfaceId: SurfaceId;
|
|
14
|
+
trayId?: TrayId;
|
|
15
|
+
ext: string;
|
|
16
|
+
}
|
|
17
|
+
interface ExtensionEnvelope<TData = unknown> {
|
|
18
|
+
scope: ExtensionScope;
|
|
19
|
+
data: TData;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/index.d.ts
|
|
23
|
+
type WebviewCommand = {
|
|
24
|
+
type: "show";
|
|
25
|
+
html?: string;
|
|
26
|
+
url?: string;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
fallbackRect?: Rect;
|
|
30
|
+
} | {
|
|
31
|
+
type: "hide";
|
|
32
|
+
} | {
|
|
33
|
+
type: "navigate";
|
|
34
|
+
url: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "evaluate";
|
|
37
|
+
js: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "postMessage";
|
|
40
|
+
payload: unknown;
|
|
41
|
+
};
|
|
42
|
+
type WebviewEvent = {
|
|
43
|
+
type: "shown";
|
|
44
|
+
} | {
|
|
45
|
+
type: "hidden";
|
|
46
|
+
} | {
|
|
47
|
+
type: "message";
|
|
48
|
+
payload: unknown;
|
|
49
|
+
} | {
|
|
50
|
+
type: "positionFallback";
|
|
51
|
+
strategy: "cursor" | "platformDefault";
|
|
52
|
+
};
|
|
53
|
+
interface WebviewHandle {
|
|
54
|
+
show(command: Extract<WebviewCommand, {
|
|
55
|
+
type: "show";
|
|
56
|
+
}>): Promise<void>;
|
|
57
|
+
hide(): Promise<void>;
|
|
58
|
+
navigate(url: string): Promise<void>;
|
|
59
|
+
evaluate(js: string): Promise<void>;
|
|
60
|
+
postMessage(payload: unknown): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
declare const attachWebview: (tray: TrayHandle) => WebviewHandle;
|
|
63
|
+
declare const isWebviewEvent: (event: ExtensionEnvelope) => event is ExtensionEnvelope<WebviewEvent>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { WebviewCommand, WebviewEvent, WebviewHandle, attachWebview, isWebviewEvent };
|
|
66
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../spec/src/index.ts","../src/index.ts"],"mappings":";;;KACY,SAAA;AAAA,KACA,MAAA;AAAA,UAuEK,IAAA;EACf,CAAA;EACA,CAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,UAWe,cAAA;EACf,SAAA,EAAW,SAAA;EACX,MAAA,GAAS,MAAM;EACf,GAAA;AAAA;AAAA,UAGe,iBAAA;EACf,KAAA,EAAO,cAAA;EACP,IAAA,EAAM,KAAK;AAAA;;;KC7FD,cAAA;EACN,IAAA;EAAc,IAAA;EAAe,GAAA;EAAc,KAAA;EAAe,MAAA;EAAgB,YAAA,GAAe,IAAI;AAAA;EAC7F,IAAA;AAAA;EACA,IAAA;EAAkB,GAAA;AAAA;EAClB,IAAA;EAAkB,EAAA;AAAA;EAClB,IAAA;EAAqB,OAAA;AAAA;AAAA,KAEf,YAAA;EACN,IAAA;AAAA;EACA,IAAA;AAAA;EACA,IAAA;EAAiB,OAAA;AAAA;EACjB,IAAA;EAA0B,QAAA;AAAA;AAAA,UAEf,aAAA;EACf,IAAA,CAAK,OAAA,EAAS,OAAA,CAAQ,cAAA;IAAkB,IAAA;EAAA,KAAkB,OAAA;EAC1D,IAAA,IAAQ,OAAA;EACR,QAAA,CAAS,GAAA,WAAc,OAAA;EACvB,QAAA,CAAS,EAAA,WAAa,OAAA;EACtB,WAAA,CAAY,OAAA,YAAmB,OAAA;AAAA;AAAA,cAGpB,aAAA,GAAiB,IAAA,EAAM,UAAA,KAAa,aAgB/C;AAAA,cAEW,cAAA,GAAkB,KAAA,EAAO,iBAAA,KAAoB,KAAA,IAAS,iBAAA,CAAkB,YAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
const attachWebview = (tray) => ({
|
|
3
|
+
show(command) {
|
|
4
|
+
return tray.commandExtension("webview", command);
|
|
5
|
+
},
|
|
6
|
+
hide() {
|
|
7
|
+
return tray.commandExtension("webview", { type: "hide" });
|
|
8
|
+
},
|
|
9
|
+
navigate(url) {
|
|
10
|
+
return tray.commandExtension("webview", {
|
|
11
|
+
type: "navigate",
|
|
12
|
+
url
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
evaluate(js) {
|
|
16
|
+
return tray.commandExtension("webview", {
|
|
17
|
+
type: "evaluate",
|
|
18
|
+
js
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
postMessage(payload) {
|
|
22
|
+
return tray.commandExtension("webview", {
|
|
23
|
+
type: "postMessage",
|
|
24
|
+
payload
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const isWebviewEvent = (event) => event.scope.ext === "webview" && typeof event.data === "object" && event.data !== null && "type" in event.data;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { attachWebview, isWebviewEvent };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { ExtensionEnvelope, Rect } from \"@opentray/spec\";\nimport type { TrayHandle } from \"opentray\";\n\nexport type WebviewCommand =\n | { type: \"show\"; html?: string; url?: string; width: number; height: number; fallbackRect?: Rect }\n | { type: \"hide\" }\n | { type: \"navigate\"; url: string }\n | { type: \"evaluate\"; js: string }\n | { type: \"postMessage\"; payload: unknown };\n\nexport type WebviewEvent =\n | { type: \"shown\" }\n | { type: \"hidden\" }\n | { type: \"message\"; payload: unknown }\n | { type: \"positionFallback\"; strategy: \"cursor\" | \"platformDefault\" };\n\nexport interface WebviewHandle {\n show(command: Extract<WebviewCommand, { type: \"show\" }>): Promise<void>;\n hide(): Promise<void>;\n navigate(url: string): Promise<void>;\n evaluate(js: string): Promise<void>;\n postMessage(payload: unknown): Promise<void>;\n}\n\nexport const attachWebview = (tray: TrayHandle): WebviewHandle => ({\n show(command) {\n return tray.commandExtension(\"webview\", command);\n },\n hide() {\n return tray.commandExtension(\"webview\", { type: \"hide\" } satisfies WebviewCommand);\n },\n navigate(url) {\n return tray.commandExtension(\"webview\", { type: \"navigate\", url } satisfies WebviewCommand);\n },\n evaluate(js) {\n return tray.commandExtension(\"webview\", { type: \"evaluate\", js } satisfies WebviewCommand);\n },\n postMessage(payload) {\n return tray.commandExtension(\"webview\", { type: \"postMessage\", payload } satisfies WebviewCommand);\n },\n});\n\nexport const isWebviewEvent = (event: ExtensionEnvelope): event is ExtensionEnvelope<WebviewEvent> =>\n event.scope.ext === \"webview\" &&\n typeof event.data === \"object\" &&\n event.data !== null &&\n \"type\" in event.data;\n"],"mappings":";AAwBA,MAAa,iBAAiB,UAAqC;CACjE,KAAK,SAAS;EACZ,OAAO,KAAK,iBAAiB,WAAW,OAAO;CACjD;CACA,OAAO;EACL,OAAO,KAAK,iBAAiB,WAAW,EAAE,MAAM,OAAO,CAA0B;CACnF;CACA,SAAS,KAAK;EACZ,OAAO,KAAK,iBAAiB,WAAW;GAAE,MAAM;GAAY;EAAI,CAA0B;CAC5F;CACA,SAAS,IAAI;EACX,OAAO,KAAK,iBAAiB,WAAW;GAAE,MAAM;GAAY;EAAG,CAA0B;CAC3F;CACA,YAAY,SAAS;EACnB,OAAO,KAAK,iBAAiB,WAAW;GAAE,MAAM;GAAe;EAAQ,CAA0B;CACnG;AACF;AAEA,MAAa,kBAAkB,UAC7B,MAAM,MAAM,QAAQ,aACpB,OAAO,MAAM,SAAS,YACtB,MAAM,SAAS,QACf,UAAU,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentray/ext-webview",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Official OpenTray rich popup extension backed by platform WebView engines.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/jixoai/opentray"
|
|
10
|
+
},
|
|
7
11
|
"exports": {
|
|
8
12
|
".": {
|
|
9
|
-
"types": "./dist/index.d.
|
|
10
|
-
"import": "./dist/index.
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"import": "./dist/index.mjs"
|
|
11
15
|
},
|
|
12
16
|
"./package.json": "./package.json"
|
|
13
17
|
},
|
|
@@ -21,6 +25,16 @@
|
|
|
21
25
|
"opentray": ">=0.0.0"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
24
|
-
"
|
|
28
|
+
"tsdown": "^0.22.1",
|
|
29
|
+
"typescript": "^6.0.3",
|
|
30
|
+
"vitest": "^4.1.7",
|
|
31
|
+
"@opentray/spec": "0.1.0",
|
|
32
|
+
"opentray": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown src/index.ts --format esm --dts",
|
|
36
|
+
"example:webview": "bun run examples/webview-command.ts",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
25
39
|
}
|
|
26
40
|
}
|