@magitch/vite-plugin-dev-connect 1.0.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 ADDED
@@ -0,0 +1,48 @@
1
+ # @magitch/vite-plugin-dev-connect
2
+
3
+ Vite plugin for [Magitch](https://magitch.app) dev environment.
4
+
5
+ Injects the **preview-protocol** bridge script into HTML during development, enabling cross-origin communication between the IDE and the sandbox preview iframe.
6
+
7
+ ## Features
8
+
9
+ - **Navigation** — back, forward, reload, navigate-to-url
10
+ - **Element Inspector** — select, highlight, get bounds
11
+ - **Readiness Detection** — PING/PONG handshake
12
+ - **Dev-only** — does nothing during `vite build`
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install -D @magitch/vite-plugin-dev-connect
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ // vite.config.ts
24
+ import { defineConfig } from 'vite'
25
+ import react from '@vitejs/plugin-react'
26
+ import { magitchDevConnect } from '@magitch/vite-plugin-dev-connect'
27
+
28
+ export default defineConfig({
29
+ plugins: [react(), magitchDevConnect()],
30
+ })
31
+ ```
32
+
33
+ ## Options
34
+
35
+ ```ts
36
+ magitchDevConnect({
37
+ // Override preview-protocol script URL
38
+ previewProtocolUrl: 'https://custom-cdn.example.com/preview-protocol.min.js',
39
+ // Trusted hosts for postMessage (default: ["*"])
40
+ trustedHosts: ['magitch.app', 'localhost'],
41
+ // Enable debug logging (default: false)
42
+ debug: true,
43
+ })
44
+ ```
45
+
46
+ ## License
47
+
48
+ MIT
@@ -0,0 +1,45 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface MagitchDevConnectOptions {
4
+ /**
5
+ * Override the preview-protocol script URL.
6
+ * @default S3 CDN URL
7
+ */
8
+ previewProtocolUrl?: string;
9
+ /**
10
+ * Trusted hosts for postMessage communication.
11
+ * Use ["*"] to allow all origins (default — safe because preview-protocol
12
+ * only sends non-sensitive UI state like navigation, element bounds, etc.)
13
+ * @default ["*"]
14
+ */
15
+ trustedHosts?: string[];
16
+ /**
17
+ * Enable debug logging in preview-protocol.
18
+ * @default false
19
+ */
20
+ debug?: boolean;
21
+ }
22
+ /**
23
+ * Vite plugin for Magitch dev environment.
24
+ *
25
+ * Injects the preview-protocol bridge script into HTML during development.
26
+ * This enables the IDE to communicate with the sandbox preview via postMessage:
27
+ * - Navigation (back/forward/reload/navigate-to-url)
28
+ * - Element Inspector (select, highlight, get bounds)
29
+ * - Readiness detection (PING/PONG)
30
+ *
31
+ * Only runs in dev mode (`vite dev`). Does nothing during `vite build`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // vite.config.ts
36
+ * import { magitchDevConnect } from '@magitch/vite-plugin-dev-connect'
37
+ *
38
+ * export default defineConfig({
39
+ * plugins: [react(), magitchDevConnect()],
40
+ * })
41
+ * ```
42
+ */
43
+ declare function magitchDevConnect(options?: MagitchDevConnectOptions): Plugin;
44
+
45
+ export { type MagitchDevConnectOptions, magitchDevConnect as default, magitchDevConnect };
@@ -0,0 +1,45 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface MagitchDevConnectOptions {
4
+ /**
5
+ * Override the preview-protocol script URL.
6
+ * @default S3 CDN URL
7
+ */
8
+ previewProtocolUrl?: string;
9
+ /**
10
+ * Trusted hosts for postMessage communication.
11
+ * Use ["*"] to allow all origins (default — safe because preview-protocol
12
+ * only sends non-sensitive UI state like navigation, element bounds, etc.)
13
+ * @default ["*"]
14
+ */
15
+ trustedHosts?: string[];
16
+ /**
17
+ * Enable debug logging in preview-protocol.
18
+ * @default false
19
+ */
20
+ debug?: boolean;
21
+ }
22
+ /**
23
+ * Vite plugin for Magitch dev environment.
24
+ *
25
+ * Injects the preview-protocol bridge script into HTML during development.
26
+ * This enables the IDE to communicate with the sandbox preview via postMessage:
27
+ * - Navigation (back/forward/reload/navigate-to-url)
28
+ * - Element Inspector (select, highlight, get bounds)
29
+ * - Readiness detection (PING/PONG)
30
+ *
31
+ * Only runs in dev mode (`vite dev`). Does nothing during `vite build`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // vite.config.ts
36
+ * import { magitchDevConnect } from '@magitch/vite-plugin-dev-connect'
37
+ *
38
+ * export default defineConfig({
39
+ * plugins: [react(), magitchDevConnect()],
40
+ * })
41
+ * ```
42
+ */
43
+ declare function magitchDevConnect(options?: MagitchDevConnectOptions): Plugin;
44
+
45
+ export { type MagitchDevConnectOptions, magitchDevConnect as default, magitchDevConnect };
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => index_default,
24
+ magitchDevConnect: () => magitchDevConnect
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var DEFAULT_PREVIEW_PROTOCOL_URL = "https://magitch.s3.eu-north-1.amazonaws.com/assets/js/preview-protocol.min.js?v=1.2.2";
28
+ function magitchDevConnect(options = {}) {
29
+ const {
30
+ previewProtocolUrl = DEFAULT_PREVIEW_PROTOCOL_URL,
31
+ trustedHosts = ["*"],
32
+ debug = false
33
+ } = options;
34
+ return {
35
+ name: "magitch-dev-connect",
36
+ apply: "serve",
37
+ // Only during dev server — not in production builds
38
+ transformIndexHtml() {
39
+ return [
40
+ // Preview Protocol Configuration
41
+ {
42
+ tag: "script",
43
+ children: [
44
+ `window.TRUSTED_PREVIEW_HOSTS=${JSON.stringify(trustedHosts)};`,
45
+ `window.PREVIEW_PROTOCOL_DEBUG=${debug};`
46
+ ].join(""),
47
+ injectTo: "head"
48
+ },
49
+ // Preview Protocol Script — cross-origin communication & element inspector
50
+ {
51
+ tag: "script",
52
+ attrs: { src: previewProtocolUrl },
53
+ injectTo: "head"
54
+ }
55
+ ];
56
+ }
57
+ };
58
+ }
59
+ var index_default = magitchDevConnect;
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ magitchDevConnect
63
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,38 @@
1
+ // src/index.ts
2
+ var DEFAULT_PREVIEW_PROTOCOL_URL = "https://magitch.s3.eu-north-1.amazonaws.com/assets/js/preview-protocol.min.js?v=1.2.2";
3
+ function magitchDevConnect(options = {}) {
4
+ const {
5
+ previewProtocolUrl = DEFAULT_PREVIEW_PROTOCOL_URL,
6
+ trustedHosts = ["*"],
7
+ debug = false
8
+ } = options;
9
+ return {
10
+ name: "magitch-dev-connect",
11
+ apply: "serve",
12
+ // Only during dev server — not in production builds
13
+ transformIndexHtml() {
14
+ return [
15
+ // Preview Protocol Configuration
16
+ {
17
+ tag: "script",
18
+ children: [
19
+ `window.TRUSTED_PREVIEW_HOSTS=${JSON.stringify(trustedHosts)};`,
20
+ `window.PREVIEW_PROTOCOL_DEBUG=${debug};`
21
+ ].join(""),
22
+ injectTo: "head"
23
+ },
24
+ // Preview Protocol Script — cross-origin communication & element inspector
25
+ {
26
+ tag: "script",
27
+ attrs: { src: previewProtocolUrl },
28
+ injectTo: "head"
29
+ }
30
+ ];
31
+ }
32
+ };
33
+ }
34
+ var index_default = magitchDevConnect;
35
+ export {
36
+ index_default as default,
37
+ magitchDevConnect
38
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@magitch/vite-plugin-dev-connect",
3
+ "version": "1.0.0",
4
+ "description": "Vite plugin for Magitch dev environment — injects preview bridge (preview-protocol) for cross-origin communication between IDE and sandbox preview.",
5
+ "keywords": [
6
+ "vite-plugin",
7
+ "magitch",
8
+ "preview",
9
+ "dev-tools",
10
+ "iframe",
11
+ "postmessage"
12
+ ],
13
+ "author": "Magitch",
14
+ "license": "MIT",
15
+ "homepage": "https://magitch.app",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/magitch/vite-plugin-dev-connect"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/magitch/vite-plugin-dev-connect/issues"
22
+ },
23
+ "main": "dist/index.js",
24
+ "module": "dist/index.mjs",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.mjs",
30
+ "require": "./dist/index.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
41
+ "prepublishOnly": "pnpm build"
42
+ },
43
+ "peerDependencies": {
44
+ "vite": ">=4.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "tsup": "^8.0.0",
48
+ "typescript": "^5.0.0",
49
+ "vite": "^6.0.0"
50
+ }
51
+ }