@archie/devtools 0.0.10 → 0.0.11

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 CHANGED
@@ -1,82 +1,54 @@
1
1
  # @archie/devtools
2
2
 
3
- DevTools for Archie generated applications. Route sync with the editor and optional element inspector script.
3
+ Devtools runtime for Archie-generated applications.
4
4
 
5
- ## Installation
5
+ ## Public API
6
6
 
7
- ```bash
8
- npm install @archie/devtools
9
- # or
10
- pnpm add @archie/devtools
11
- ```
7
+ This package exposes only two supported entrypoints:
12
8
 
13
- ## Features
9
+ - `@archie/devtools` -> `archieDevTools`
10
+ - `@archie/devtools/client` -> `ArchieDevToolProvider`, `ArchieDevToolProviderProps`
14
11
 
15
- - **Route synchronization** – Current route is sent to the Archie editor for live preview.
16
- - **Inspector script (optional)** – Injects the element inspector at runtime (no URL, bundled).
17
- - **Vite plugin (optional)** – Build-time hook for future features.
12
+ Everything else is internal implementation detail.
18
13
 
19
14
  ## Usage
20
15
 
21
- ### 1. Configure Vite Plugin (Optional)
16
+ ### 1. Configure the Vite plugin
22
17
 
23
- ```typescript
24
- // vite.config.ts
25
- import { defineConfig } from "vite";
26
- import { archieDevTools } from "@archie/devtools";
18
+ ```ts
19
+ import { defineConfig } from 'vite';
20
+ import react from '@vitejs/plugin-react';
21
+ import { archieDevTools } from '@archie/devtools';
27
22
 
28
23
  export default defineConfig({
29
- plugins: [archieDevTools()],
24
+ plugins: [react(), archieDevTools()],
30
25
  });
31
26
  ```
32
27
 
33
- ### 2. Inspector script (optional)
34
-
35
- Injects the inspector when the client bundle runs. Safe in SSR (no-op on server). One line, no `useEffect`:
36
-
37
- ```typescript
38
- // App root, e.g. layout.tsx or main.tsx
39
- import "@archie/devtools/client/inject-inspector/auto";
40
- ```
41
-
42
- **¿Afecta que la función tenga opciones?** No. El auto-import llama `injectInspector()` sin argumentos. Por defecto se usan orígenes Archie + localhost en dev y el target desde el parent (iframe). Solo si quieres cambiar algo pasas opciones:
43
-
44
- ```typescript
45
- import { injectInspector } from "@archie/devtools/client";
46
-
47
- // Igual que el auto: sin argumentos, valores por defecto seguros
48
- injectInspector();
49
-
50
- // Opcional: incluir localhost explícitamente, o fijar orígenes/target
51
- injectInspector({ dev: true });
52
- injectInspector({ id: "my-inspector" });
53
- injectInspector({ allowedOrigins: ["https://app.archie.com"], targetOrigin: "https://app.archie.com" });
54
- ```
55
-
56
- Paths:
57
-
58
- - `@archie/devtools/client` – route listener + `injectInspector`
59
- - `@archie/devtools/client/inject-inspector/auto` – side-effect only (import and it runs)
60
-
61
- ### 3. Route listener (required for preview sync)
62
-
63
- ```typescript
64
- // e.g. src/main.tsx
65
- import { setupArchieRouteListener } from "@archie/devtools/client";
66
- import App, { router } from "./App";
67
-
68
- setupArchieRouteListener(router);
69
- createRoot(document.getElementById("root")!).render(<App />);
28
+ ### 2. Bootstrap the app runtime
29
+
30
+ ```tsx
31
+ import { StrictMode } from 'react';
32
+ import { createRoot } from 'react-dom/client';
33
+ import { ArchieDevToolProvider } from '@archie/devtools/client';
34
+ import App, { router } from './App';
35
+
36
+ createRoot(document.getElementById('root')!).render(
37
+ <StrictMode>
38
+ <ArchieDevToolProvider router={router}>
39
+ <App />
40
+ </ArchieDevToolProvider>
41
+ </StrictMode>,
42
+ );
70
43
  ```
71
44
 
72
- ### 4. Export router from App
45
+ ### 3. Export the router
73
46
 
74
- ```typescript
75
- // src/App.tsx
76
- import { createBrowserRouter, RouterProvider } from "react-router-dom";
47
+ ```tsx
48
+ import { createBrowserRouter, RouterProvider } from 'react-router-dom';
77
49
 
78
50
  export const router = createBrowserRouter([
79
- // ... your routes
51
+ // routes
80
52
  ]);
81
53
 
82
54
  export default function App() {
@@ -84,68 +56,38 @@ export default function App() {
84
56
  }
85
57
  ```
86
58
 
87
- ## Message Format
88
-
89
- The route listener broadcasts messages to the parent window with this structure:
90
-
91
- ```typescript
92
- interface ArchieRouteUpdateMessage {
93
- type: "ARCHIE_ROUTE_UPDATE";
94
- payload: {
95
- path: string;
96
- search: string;
97
- hash: string;
98
- matches: Array<{
99
- id: string | undefined;
100
- pathname: string;
101
- params: Record<string, string | undefined>;
102
- }>;
103
- timestamp: number;
104
- };
105
- }
106
- ```
107
-
108
- ## Host (editor) integration
59
+ ## Responsibilities
109
60
 
110
- If your editor receives postMessage from the inspector iframe:
61
+ - `archieDevTools()` handles compile-time editor metadata and internal DnD scope injection.
62
+ - `ArchieDevToolProvider` handles runtime bootstrap: DnD provider, route sync, sanitizer install, and inspector initialization.
111
63
 
112
- 1. **Validate origin with an allowlist (recommended)**
113
- In the **host**, allow the iframe’s origins (localhost for dev + your app URLs in production) so it works everywhere.
114
- **Archie host origins:** `https://app.dev.archie-platform.com`, `https://app.staging.archie-platform.com`, `https://app.archie.com`. For local testing use `getAllowedOrigins(true)` (adds localhost). Example:
115
- ```js
116
- import { getAllowedOrigins } from "@archie/devtools/constants";
117
- const ALLOWED_ORIGINS = getAllowedOrigins(true); // true = include localhost for local dev
118
- window.addEventListener("message", (e) => {
119
- if (!ALLOWED_ORIGINS.includes(e.origin)) return;
120
- // handle e.data
121
- });
122
- ```
123
- 2. **Inspector origins (iframe):** Only configured domains are allowed; **`"*"` is never used.** If you use `injectInspector()` (recommended), it sets Archie host origins + localhost in dev by default. You can override with `allowedOrigins` and `targetOrigin` (or set `window.__ARCHIE_INSPECTOR_ALLOWED_ORIGINS__` / `__ARCHIE_INSPECTOR_TARGET_ORIGIN__` before the script runs).
64
+ ## Requirements
124
65
 
125
- 4. **Globals (backward compatible)**
126
- The inspector still sets `window._inspectorDebug`, `window._inspectorSelectedElement`, `window._inspectorMessageHandler`, and `window._inspectorQuerySelectorProtected`.
127
- Prefer the namespace: `window.__ARCHIE_INSPECTOR__` with `debug`, `selectedElement`, `messageHandler` (same values, no DOM pollution on the namespace object).
66
+ - React 18+
67
+ - React Router DOM 6.4+
68
+ - Vite 5+
128
69
 
129
- 5. **Message types** (from iframe to parent)
130
- `INSPECTOR_SCRIPT_LOADED`, `ELEMENT_SELECTED`, `STOP_INSPECTION`, `INSPECTION_CANCELLED`, `ELEMENT_POSITION_UPDATE`, `STYLE_CHANGE_APPLIED` / `STYLE_CHANGE_FAILED`, `TEXT_CHANGE_APPLIED` / `TEXT_CHANGE_FAILED`, `ELEMENT_REMOVED` / `ELEMENT_REMOVAL_FAILED`.
131
- Payload shapes are unchanged; only the postMessage `targetOrigin` is configurable.
70
+ ## Local linking
132
71
 
133
- To **activate the inspector from the parent** (the site that contains the iframe): you don't call `runInspector()` from the parent. The app inside the iframe already loads the inspector; from the parent send `iframe.contentWindow.postMessage({ type: "START_INSPECTION" }, iframeOrigin)` to start inspection. See [docs/HOST_INTEGRATION.md](docs/HOST_INTEGRATION.md) for full flow, local testing, and all commands.
72
+ ```bash
73
+ pnpm add file:../archie-devtools
74
+ ```
134
75
 
135
- ## Linking locally
76
+ After changing the library:
136
77
 
137
78
  ```bash
138
- # In the app repo
139
- pnpm add file:../archie-devtools
140
- # After changing the lib: run `pnpm run build` in archie-devtools
79
+ pnpm build
141
80
  ```
142
81
 
143
- ## Requirements
82
+ ## Development
144
83
 
145
- - React 18+
146
- - React Router DOM 6.4+ (Data Router API)
147
- - Vite 5+ (for plugin)
84
+ ```bash
85
+ pnpm test
86
+ pnpm typecheck
87
+ ```
148
88
 
149
- ## License
89
+ Tests follow a colocated-by-feature convention:
150
90
 
151
- MIT
91
+ - small modules keep `*.test.ts(x)` beside the source file
92
+ - larger subsystems may use a local `__tests__/` folder next to the feature
93
+ - `src/client/dnd/design-mode/__tests__/` is the reference pattern for multi-file feature coverage
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ export {
6
+ __publicField
7
+ };
@@ -1,2 +1,41 @@
1
- export { ArchieRouteUpdateMessage, RouteInfo, setupArchieRouteListener } from './route-listener/routeListener.mjs';
2
- import '@remix-run/router';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface ArchieRouteObjectLike {
5
+ id?: string;
6
+ path?: string;
7
+ index?: boolean;
8
+ children?: readonly ArchieRouteObjectLike[];
9
+ }
10
+ interface ArchieRouteMatchLike {
11
+ route: {
12
+ id?: string;
13
+ };
14
+ pathname: string;
15
+ params: Record<string, string | undefined>;
16
+ }
17
+ interface ArchieRouterStateLike {
18
+ location: {
19
+ pathname: string;
20
+ search: string;
21
+ hash: string;
22
+ };
23
+ matches: readonly ArchieRouteMatchLike[];
24
+ }
25
+ interface ArchieRouterLike {
26
+ routes: readonly ArchieRouteObjectLike[];
27
+ state: ArchieRouterStateLike;
28
+ subscribe(listener: (state: ArchieRouterStateLike) => void): () => void;
29
+ }
30
+
31
+ interface ArchieDevToolsRuntimeOptions {
32
+ router: ArchieRouterLike;
33
+ inspector?: boolean;
34
+ }
35
+
36
+ interface ArchieDevToolProviderProps extends ArchieDevToolsRuntimeOptions {
37
+ children: ReactNode;
38
+ }
39
+ declare function ArchieDevToolProvider({ children, router, inspector, }: ArchieDevToolProviderProps): react_jsx_runtime.JSX.Element;
40
+
41
+ export { ArchieDevToolProvider, type ArchieDevToolProviderProps };
@@ -1,2 +1,41 @@
1
- export { ArchieRouteUpdateMessage, RouteInfo, setupArchieRouteListener } from './route-listener/routeListener.js';
2
- import '@remix-run/router';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface ArchieRouteObjectLike {
5
+ id?: string;
6
+ path?: string;
7
+ index?: boolean;
8
+ children?: readonly ArchieRouteObjectLike[];
9
+ }
10
+ interface ArchieRouteMatchLike {
11
+ route: {
12
+ id?: string;
13
+ };
14
+ pathname: string;
15
+ params: Record<string, string | undefined>;
16
+ }
17
+ interface ArchieRouterStateLike {
18
+ location: {
19
+ pathname: string;
20
+ search: string;
21
+ hash: string;
22
+ };
23
+ matches: readonly ArchieRouteMatchLike[];
24
+ }
25
+ interface ArchieRouterLike {
26
+ routes: readonly ArchieRouteObjectLike[];
27
+ state: ArchieRouterStateLike;
28
+ subscribe(listener: (state: ArchieRouterStateLike) => void): () => void;
29
+ }
30
+
31
+ interface ArchieDevToolsRuntimeOptions {
32
+ router: ArchieRouterLike;
33
+ inspector?: boolean;
34
+ }
35
+
36
+ interface ArchieDevToolProviderProps extends ArchieDevToolsRuntimeOptions {
37
+ children: ReactNode;
38
+ }
39
+ declare function ArchieDevToolProvider({ children, router, inspector, }: ArchieDevToolProviderProps): react_jsx_runtime.JSX.Element;
40
+
41
+ export { ArchieDevToolProvider, type ArchieDevToolProviderProps };