@promakeai/inspector-hook 1.3.0 → 1.3.2

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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RefObject } from "react";
2
- import type { InspectorCallbacks, InspectorLabels, InspectorTheme, UseInspectorReturn } from "@promakeai/inspector-types";
3
- export declare function useInspector(iframeRef: RefObject<HTMLIFrameElement>, callbacks?: InspectorCallbacks, labels?: InspectorLabels, theme?: InspectorTheme): UseInspectorReturn;
4
- export type { ComponentInfo, ElementPosition, SelectedElementData, UrlChangeData, PromptSubmittedData, TextUpdatedData, ImageUpdatedData, StyleChanges, StyleUpdatedData, ErrorData, HighlightOptions, ElementInfoData, ElementDeletedData, ElementDuplicatedData, ChangeType, ChangeHistoryEntry, InspectorChange, InspectorChangeType, InspectorChangesSavedData, InspectorLabels, InspectorTheme, ContentInputRequestData, InspectorCallbacks, UseInspectorReturn, InspectorTab, } from "@promakeai/inspector-types";
2
+ import type { InspectorCallbacks, InspectorLabels, InspectorTheme, InspectorInitialConfig, UseInspectorReturn } from "@promakeai/inspector-types";
3
+ export declare function useInspector(iframeRef: RefObject<HTMLIFrameElement>, callbacks?: InspectorCallbacks, labels?: InspectorLabels, theme?: InspectorTheme, initialConfig?: InspectorInitialConfig): UseInspectorReturn;
4
+ export type { ComponentInfo, ElementPosition, SelectedElementData, UrlChangeData, PromptSubmittedData, TextUpdatedData, ImageUpdatedData, StyleChanges, StyleUpdatedData, ErrorData, HighlightOptions, ElementInfoData, ElementDeletedData, ElementDuplicatedData, ChangeType, ChangeHistoryEntry, InspectorChange, InspectorChangeType, InspectorChangesSavedData, InspectorLabels, InspectorTheme, ContentInputRequestData, InspectorCallbacks, UseInspectorReturn, InspectorTab, InspectorInitialConfig, InspectorInitializedData, } from "@promakeai/inspector-types";
5
5
  export { updateJSXSource, deleteJSXElement, duplicateJSXElement, updateTextContent, applyChangesToJSXSource, } from "./utils/jsxUpdater.js";
6
6
  export type { UpdateJSXSourceOptions, UpdateJSXSourceResult, DeleteJSXElementOptions, DuplicateJSXElementOptions, UpdateTextContentOptions, ApplyChangesOptions, ApplyChangesResult, ChangeApplicationResult, } from "./utils/jsxUpdater.js";
7
7
  export { inspectorHookPlugin } from "./vite-plugin.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAenB,MAAM,4BAA4B,CAAC;AAsIpC,wBAAgB,YAAY,CAC1B,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,EACvC,SAAS,CAAC,EAAE,kBAAkB,EAC9B,MAAM,CAAC,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,cAAc,GACrB,kBAAkB,CAuYpB;AAGD,YAAY,EACV,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,GACb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,sBAAsB,EAEtB,kBAAkB,EAenB,MAAM,4BAA4B,CAAC;AA+IpC,wBAAgB,YAAY,CAC1B,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,EACvC,SAAS,CAAC,EAAE,kBAAkB,EAC9B,MAAM,CAAC,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,cAAc,EACtB,aAAa,CAAC,EAAE,sBAAsB,GACrC,kBAAkB,CAqepB;AAGD,YAAY,EACV,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import { useEffect, useState, useCallback } from "react";
2
- export function useInspector(iframeRef, callbacks, labels, theme) {
1
+ import { useEffect, useState, useCallback, useRef } from "react";
2
+ export function useInspector(iframeRef, callbacks, labels, theme, initialConfig) {
3
3
  const [isInspecting, setIsInspecting] = useState(false);
4
+ const [isReady, setIsReady] = useState(false);
5
+ const initialConfigSentRef = useRef(false);
4
6
  /**
5
7
  * Send message to iframe
6
8
  */
@@ -255,6 +257,10 @@ export function useInspector(iframeRef, callbacks, labels, theme) {
255
257
  setIsInspecting(false);
256
258
  callbacks?.onInspectorUnmounted?.();
257
259
  break;
260
+ case "INSPECTOR_INITIALIZED":
261
+ setIsReady(true);
262
+ callbacks?.onInspectorInitialized?.(messageData.data);
263
+ break;
258
264
  default:
259
265
  // Unknown message type - ignore
260
266
  break;
@@ -265,6 +271,87 @@ export function useInspector(iframeRef, callbacks, labels, theme) {
265
271
  window.removeEventListener("message", handleMessage);
266
272
  };
267
273
  }, [callbacks]);
274
+ /**
275
+ * Send initial config when inspector is ready
276
+ * Priority: method calls > initialConfig > inspector defaults
277
+ */
278
+ useEffect(() => {
279
+ if (isReady && initialConfig && !initialConfigSentRef.current) {
280
+ initialConfigSentRef.current = true;
281
+ // Send behavior settings
282
+ if (initialConfig.inspectOnRightClick !== undefined) {
283
+ sendMessage({
284
+ type: "SET_INSPECT_ON_RIGHT_CLICK",
285
+ enabled: initialConfig.inspectOnRightClick,
286
+ });
287
+ }
288
+ if (initialConfig.allowEditForMultipleInstances !== undefined) {
289
+ sendMessage({
290
+ type: "SET_ALLOW_EDIT_FOR_MULTIPLE_INSTANCES",
291
+ enabled: initialConfig.allowEditForMultipleInstances,
292
+ });
293
+ }
294
+ if (initialConfig.isDraggable !== undefined) {
295
+ sendMessage({
296
+ type: "SET_IS_DRAGGABLE",
297
+ enabled: initialConfig.isDraggable,
298
+ });
299
+ }
300
+ if (initialConfig.isResizable !== undefined) {
301
+ sendMessage({
302
+ type: "SET_IS_RESIZABLE",
303
+ enabled: initialConfig.isResizable,
304
+ });
305
+ }
306
+ // Send visibility settings
307
+ if (initialConfig.showContentInput !== undefined) {
308
+ sendMessage({
309
+ type: "SHOW_CONTENT_INPUT",
310
+ show: initialConfig.showContentInput,
311
+ });
312
+ }
313
+ if (initialConfig.showImageInput !== undefined) {
314
+ sendMessage({
315
+ type: "SHOW_IMAGE_INPUT",
316
+ show: initialConfig.showImageInput,
317
+ });
318
+ }
319
+ if (initialConfig.showStyleEditor !== undefined) {
320
+ sendMessage({
321
+ type: "SHOW_STYLE_EDITOR",
322
+ show: initialConfig.showStyleEditor,
323
+ });
324
+ }
325
+ if (initialConfig.showActionsTab !== undefined) {
326
+ sendMessage({
327
+ type: "SHOW_ACTIONS_TAB",
328
+ show: initialConfig.showActionsTab,
329
+ });
330
+ }
331
+ if (initialConfig.showChildBorders !== undefined) {
332
+ sendMessage({
333
+ type: "SET_SHOW_CHILD_BORDERS",
334
+ show: initialConfig.showChildBorders,
335
+ });
336
+ }
337
+ if (initialConfig.badgeVisible !== undefined) {
338
+ sendMessage({
339
+ type: "SET_BADGE_VISIBLE",
340
+ visible: initialConfig.badgeVisible,
341
+ badgeText: labels?.badgeText,
342
+ });
343
+ }
344
+ // Send image validation settings
345
+ if (initialConfig.maxImageSize !== undefined ||
346
+ initialConfig.allowedImageTypes !== undefined) {
347
+ sendMessage({
348
+ type: "SET_IMAGE_VALIDATION",
349
+ maxImageSize: initialConfig.maxImageSize,
350
+ allowedImageTypes: initialConfig.allowedImageTypes,
351
+ });
352
+ }
353
+ }
354
+ }, [isReady, initialConfig, sendMessage, labels]);
268
355
  /**
269
356
  * Cleanup: Turn off inspector on unmount
270
357
  */
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
- {
2
- "name": "@promakeai/inspector-hook",
3
- "version": "1.3.0",
4
- "description": "React hook for controlling inspector in parent applications",
5
- "author": "Promake",
6
- "type": "module",
7
- "main": "./dist/index.js",
8
- "module": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js"
14
- },
15
- "./package.json": "./package.json"
16
- },
17
- "files": [
18
- "dist"
19
- ],
20
- "scripts": {
21
- "build": "tsc --build",
22
- "dev": "tsc --watch",
23
- "clean": "rm -rf dist",
24
- "lint": "tsc --build --force --dry",
25
- "test": "vitest run",
26
- "test:watch": "vitest",
27
- "test:coverage": "vitest run --coverage",
28
- "prepublishOnly": "bun run build",
29
- "release": "bun run build && npm publish --access public"
30
- },
31
- "keywords": [
32
- "react",
33
- "hook",
34
- "inspector",
35
- "iframe"
36
- ],
37
- "peerDependencies": {
38
- "react": ">=18.0.0",
39
- "react-dom": ">=18.0.0",
40
- "vite": ">=5.0.0"
41
- },
42
- "peerDependenciesMeta": {
43
- "vite": {
44
- "optional": true
45
- }
46
- },
47
- "devDependencies": {
48
- "@promakeai/inspector-types": "1.0.2",
49
- "vitest": "^1.0.0"
50
- },
51
- "publishConfig": {
52
- "access": "public"
53
- }
54
- }
1
+ {
2
+ "name": "@promakeai/inspector-hook",
3
+ "version": "1.3.2",
4
+ "description": "React hook for controlling inspector in parent applications",
5
+ "author": "Promake",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc --build",
22
+ "dev": "tsc --watch",
23
+ "clean": "rm -rf dist",
24
+ "lint": "tsc --build --force --dry",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "test:coverage": "vitest run --coverage",
28
+ "prepublishOnly": "bun run build",
29
+ "release": "bun run build && npm publish --access public"
30
+ },
31
+ "keywords": [
32
+ "react",
33
+ "hook",
34
+ "inspector",
35
+ "iframe"
36
+ ],
37
+ "peerDependencies": {
38
+ "react": ">=18.0.0",
39
+ "react-dom": ">=18.0.0",
40
+ "vite": ">=5.0.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "vite": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "@promakeai/inspector-types": "1.3.1",
49
+ "vitest": "^1.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }