@archie/devtools 0.0.1

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,92 @@
1
+ # @archie/devtools
2
+
3
+ DevTools for Archie generated applications. Provides seamless communication between the generated app and the Archie editor.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @archie/devtools
9
+ ```
10
+
11
+ ## Features
12
+
13
+ ### Route Synchronization
14
+
15
+ Automatically syncs the current route from your app to the Archie editor, enabling real-time preview navigation.
16
+
17
+ ### Vite Plugin (Optional)
18
+
19
+ Provides build-time integration for future features like component tagging and HMR overrides.
20
+
21
+ ## Usage
22
+
23
+ ### 1. Configure Vite Plugin (Optional)
24
+
25
+ ```typescript
26
+ // vite.config.ts
27
+ import { defineConfig } from "vite";
28
+ import { archieDevTools } from "@archie/devtools";
29
+
30
+ export default defineConfig({
31
+ plugins: [archieDevTools()],
32
+ });
33
+ ```
34
+
35
+ ### 2. Initialize Route Listener (Required)
36
+
37
+ ```typescript
38
+ // src/main.tsx
39
+ import { setupArchieRouteListener } from "@archie/devtools/client";
40
+ import App, { router } from "./App";
41
+
42
+ // Initialize route synchronization
43
+ setupArchieRouteListener(router);
44
+
45
+ createRoot(document.getElementById("root")!).render(<App />);
46
+ ```
47
+
48
+ ### 3. Export Router from App
49
+
50
+ ```typescript
51
+ // src/App.tsx
52
+ import { createBrowserRouter, RouterProvider } from "react-router-dom";
53
+
54
+ export const router = createBrowserRouter([
55
+ // ... your routes
56
+ ]);
57
+
58
+ export default function App() {
59
+ return <RouterProvider router={router} />;
60
+ }
61
+ ```
62
+
63
+ ## Message Format
64
+
65
+ The route listener broadcasts messages to the parent window with this structure:
66
+
67
+ ```typescript
68
+ interface ArchieRouteUpdateMessage {
69
+ type: "ARCHIE_ROUTE_UPDATE";
70
+ payload: {
71
+ path: string;
72
+ search: string;
73
+ hash: string;
74
+ matches: Array<{
75
+ id: string | undefined;
76
+ pathname: string;
77
+ params: Record<string, string | undefined>;
78
+ }>;
79
+ timestamp: number;
80
+ };
81
+ }
82
+ ```
83
+
84
+ ## Requirements
85
+
86
+ - React 18+
87
+ - React Router DOM 6.4+ (Data Router API)
88
+ - Vite 5+ (for plugin)
89
+
90
+ ## License
91
+
92
+ MIT
@@ -0,0 +1,49 @@
1
+ import { Router } from '@remix-run/router';
2
+
3
+ /**
4
+ * Archie Route Listener Setup
5
+ *
6
+ * Subscribes to the React Router instance to detect route changes
7
+ * and broadcast them to the host editor (iframe parent or popup opener).
8
+ *
9
+ * @param router - The React Router instance (from createBrowserRouter)
10
+ * @returns Unsubscribe function to stop listening
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { setupArchieRouteListener } from '@archie/devtools/client';
15
+ * import { router } from './App';
16
+ *
17
+ * const unsubscribe = setupArchieRouteListener(router);
18
+ * // Later: unsubscribe();
19
+ * ```
20
+ */
21
+ declare function setupArchieRouteListener(router: Router): () => void;
22
+ /**
23
+ * Route information for the sitemap
24
+ */
25
+ interface RouteInfo {
26
+ id: string | undefined;
27
+ path: string;
28
+ hasChildren: boolean;
29
+ }
30
+ /**
31
+ * Type definition for the route update message
32
+ */
33
+ interface ArchieRouteUpdateMessage {
34
+ type: 'ARCHIE_ROUTE_UPDATE';
35
+ payload: {
36
+ path: string;
37
+ search: string;
38
+ hash: string;
39
+ matches: Array<{
40
+ id: string | undefined;
41
+ pathname: string;
42
+ params: Record<string, string | undefined>;
43
+ }>;
44
+ allRoutes: RouteInfo[];
45
+ timestamp: number;
46
+ };
47
+ }
48
+
49
+ export { type ArchieRouteUpdateMessage, type RouteInfo, setupArchieRouteListener };
@@ -0,0 +1,49 @@
1
+ import { Router } from '@remix-run/router';
2
+
3
+ /**
4
+ * Archie Route Listener Setup
5
+ *
6
+ * Subscribes to the React Router instance to detect route changes
7
+ * and broadcast them to the host editor (iframe parent or popup opener).
8
+ *
9
+ * @param router - The React Router instance (from createBrowserRouter)
10
+ * @returns Unsubscribe function to stop listening
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { setupArchieRouteListener } from '@archie/devtools/client';
15
+ * import { router } from './App';
16
+ *
17
+ * const unsubscribe = setupArchieRouteListener(router);
18
+ * // Later: unsubscribe();
19
+ * ```
20
+ */
21
+ declare function setupArchieRouteListener(router: Router): () => void;
22
+ /**
23
+ * Route information for the sitemap
24
+ */
25
+ interface RouteInfo {
26
+ id: string | undefined;
27
+ path: string;
28
+ hasChildren: boolean;
29
+ }
30
+ /**
31
+ * Type definition for the route update message
32
+ */
33
+ interface ArchieRouteUpdateMessage {
34
+ type: 'ARCHIE_ROUTE_UPDATE';
35
+ payload: {
36
+ path: string;
37
+ search: string;
38
+ hash: string;
39
+ matches: Array<{
40
+ id: string | undefined;
41
+ pathname: string;
42
+ params: Record<string, string | undefined>;
43
+ }>;
44
+ allRoutes: RouteInfo[];
45
+ timestamp: number;
46
+ };
47
+ }
48
+
49
+ export { type ArchieRouteUpdateMessage, type RouteInfo, setupArchieRouteListener };
package/dist/client.js ADDED
@@ -0,0 +1,80 @@
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/client.ts
21
+ var client_exports = {};
22
+ __export(client_exports, {
23
+ setupArchieRouteListener: () => setupArchieRouteListener
24
+ });
25
+ module.exports = __toCommonJS(client_exports);
26
+ function setupArchieRouteListener(router) {
27
+ const target = window.parent !== window ? window.parent : window.opener;
28
+ if (!target) {
29
+ return () => {
30
+ };
31
+ }
32
+ const allRoutes = extractAllRoutes(router.routes);
33
+ broadcastRouteState(target, router.state, allRoutes);
34
+ const unsubscribe = router.subscribe((state) => {
35
+ broadcastRouteState(target, state, allRoutes);
36
+ });
37
+ return unsubscribe;
38
+ }
39
+ function extractAllRoutes(routes, parentPath = "") {
40
+ const result = [];
41
+ for (const route of routes) {
42
+ const path = route.path ? (parentPath + "/" + route.path).replace(/\/+/g, "/") : parentPath || "/";
43
+ if (route.path !== void 0 || route.index) {
44
+ result.push({
45
+ id: route.id,
46
+ path: route.index ? parentPath || "/" : path,
47
+ hasChildren: !!(route.children && route.children.length > 0)
48
+ });
49
+ }
50
+ if (route.children) {
51
+ result.push(...extractAllRoutes(route.children, path));
52
+ }
53
+ }
54
+ return result;
55
+ }
56
+ function broadcastRouteState(target, state, allRoutes) {
57
+ try {
58
+ const message = {
59
+ type: "ARCHIE_ROUTE_UPDATE",
60
+ payload: {
61
+ path: state.location.pathname,
62
+ search: state.location.search,
63
+ hash: state.location.hash,
64
+ matches: state.matches.map((m) => ({
65
+ id: m.route.id,
66
+ pathname: m.pathname,
67
+ params: m.params
68
+ })),
69
+ allRoutes,
70
+ timestamp: Date.now()
71
+ }
72
+ };
73
+ target.postMessage(message, "*");
74
+ } catch {
75
+ }
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ setupArchieRouteListener
80
+ });
@@ -0,0 +1,55 @@
1
+ // src/client.ts
2
+ function setupArchieRouteListener(router) {
3
+ const target = window.parent !== window ? window.parent : window.opener;
4
+ if (!target) {
5
+ return () => {
6
+ };
7
+ }
8
+ const allRoutes = extractAllRoutes(router.routes);
9
+ broadcastRouteState(target, router.state, allRoutes);
10
+ const unsubscribe = router.subscribe((state) => {
11
+ broadcastRouteState(target, state, allRoutes);
12
+ });
13
+ return unsubscribe;
14
+ }
15
+ function extractAllRoutes(routes, parentPath = "") {
16
+ const result = [];
17
+ for (const route of routes) {
18
+ const path = route.path ? (parentPath + "/" + route.path).replace(/\/+/g, "/") : parentPath || "/";
19
+ if (route.path !== void 0 || route.index) {
20
+ result.push({
21
+ id: route.id,
22
+ path: route.index ? parentPath || "/" : path,
23
+ hasChildren: !!(route.children && route.children.length > 0)
24
+ });
25
+ }
26
+ if (route.children) {
27
+ result.push(...extractAllRoutes(route.children, path));
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ function broadcastRouteState(target, state, allRoutes) {
33
+ try {
34
+ const message = {
35
+ type: "ARCHIE_ROUTE_UPDATE",
36
+ payload: {
37
+ path: state.location.pathname,
38
+ search: state.location.search,
39
+ hash: state.location.hash,
40
+ matches: state.matches.map((m) => ({
41
+ id: m.route.id,
42
+ pathname: m.pathname,
43
+ params: m.params
44
+ })),
45
+ allRoutes,
46
+ timestamp: Date.now()
47
+ }
48
+ };
49
+ target.postMessage(message, "*");
50
+ } catch {
51
+ }
52
+ }
53
+ export {
54
+ setupArchieRouteListener
55
+ };
@@ -0,0 +1,31 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface ArchieDevToolsOptions {
4
+ /**
5
+ * Enable debug logging
6
+ * @default false
7
+ */
8
+ debug?: boolean;
9
+ }
10
+ /**
11
+ * Archie DevTools Vite Plugin
12
+ *
13
+ * Provides build-time integration for Archie generated applications.
14
+ * Currently serves as an extensibility point for future features:
15
+ * - Component tagging (click-to-edit)
16
+ * - HMR overrides
17
+ * - Virtual file injection
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // vite.config.ts
22
+ * import { archieDevTools } from '@archie/devtools';
23
+ *
24
+ * export default defineConfig({
25
+ * plugins: [archieDevTools()]
26
+ * })
27
+ * ```
28
+ */
29
+ declare function archieDevTools(options?: ArchieDevToolsOptions): Plugin;
30
+
31
+ export { type ArchieDevToolsOptions, archieDevTools };
@@ -0,0 +1,31 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface ArchieDevToolsOptions {
4
+ /**
5
+ * Enable debug logging
6
+ * @default false
7
+ */
8
+ debug?: boolean;
9
+ }
10
+ /**
11
+ * Archie DevTools Vite Plugin
12
+ *
13
+ * Provides build-time integration for Archie generated applications.
14
+ * Currently serves as an extensibility point for future features:
15
+ * - Component tagging (click-to-edit)
16
+ * - HMR overrides
17
+ * - Virtual file injection
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // vite.config.ts
22
+ * import { archieDevTools } from '@archie/devtools';
23
+ *
24
+ * export default defineConfig({
25
+ * plugins: [archieDevTools()]
26
+ * })
27
+ * ```
28
+ */
29
+ declare function archieDevTools(options?: ArchieDevToolsOptions): Plugin;
30
+
31
+ export { type ArchieDevToolsOptions, archieDevTools };
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
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
+ archieDevTools: () => archieDevTools
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ function archieDevTools(options = {}) {
27
+ const { debug = false } = options;
28
+ const log = (...args) => {
29
+ if (debug) {
30
+ console.log("[Archie DevTools]", ...args);
31
+ }
32
+ };
33
+ return {
34
+ name: "vite-plugin-archie-devtools",
35
+ enforce: "pre",
36
+ configResolved(config) {
37
+ log("Plugin initialized for project:", config.root);
38
+ },
39
+ configureServer() {
40
+ log("Dev server configured");
41
+ }
42
+ };
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ archieDevTools
47
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,22 @@
1
+ // src/index.ts
2
+ function archieDevTools(options = {}) {
3
+ const { debug = false } = options;
4
+ const log = (...args) => {
5
+ if (debug) {
6
+ console.log("[Archie DevTools]", ...args);
7
+ }
8
+ };
9
+ return {
10
+ name: "vite-plugin-archie-devtools",
11
+ enforce: "pre",
12
+ configResolved(config) {
13
+ log("Plugin initialized for project:", config.root);
14
+ },
15
+ configureServer() {
16
+ log("Dev server configured");
17
+ }
18
+ };
19
+ }
20
+ export {
21
+ archieDevTools
22
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@archie/devtools",
3
+ "version": "0.0.1",
4
+ "description": "DevTools for Archie generated applications - Route synchronization and editor communication",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./client": {
15
+ "types": "./dist/client.d.ts",
16
+ "import": "./dist/client.mjs",
17
+ "require": "./dist/client.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsup src/index.ts src/client.ts --format cjs,esm --dts",
22
+ "dev": "tsup src/index.ts src/client.ts --format cjs,esm --dts --watch",
23
+ "typecheck": "tsc --noEmit",
24
+ "release": "node publish.js"
25
+ },
26
+ "files": [
27
+ "dist/**/*"
28
+ ],
29
+ "keywords": [
30
+ "vite",
31
+ "plugin",
32
+ "archie",
33
+ "devtools",
34
+ "react-router"
35
+ ],
36
+ "author": "8base",
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@remix-run/router": "^1.0.0",
40
+ "@types/react": "^19.0.0",
41
+ "@types/react-dom": "^19.0.0",
42
+ "react": "^19.0.0",
43
+ "react-dom": "^19.0.0",
44
+ "react-router-dom": "^7.0.0",
45
+ "tsup": "^8.0.0",
46
+ "typescript": "^5.0.0",
47
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "react": ">=18.0.0",
51
+ "react-dom": ">=18.0.0",
52
+ "react-router-dom": ">=6.4.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "vite": {
56
+ "optional": true
57
+ }
58
+ }
59
+ }