@promakeai/inspector 0.0.3 → 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 +285 -80
- package/dist/hook.d.ts +38 -5
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +89 -14
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +575 -29
- package/dist/types.d.ts +26 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/hook.js
CHANGED
|
@@ -12,16 +12,22 @@
|
|
|
12
12
|
* function App() {
|
|
13
13
|
* const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
14
14
|
*
|
|
15
|
-
* const { isInspecting, toggleInspector, showContentInput } = useInspector(
|
|
15
|
+
* const { isInspecting, toggleInspector, showContentInput, showImageInput } = useInspector(
|
|
16
16
|
* iframeRef,
|
|
17
17
|
* {
|
|
18
18
|
* onElementSelected: (data) => {
|
|
19
19
|
* console.log('Element selected:', data);
|
|
20
20
|
* console.log('Is text node:', data.isTextNode);
|
|
21
|
+
* console.log('Is image node:', data.isImageNode);
|
|
21
22
|
*
|
|
22
23
|
* // Dynamically show content input for text nodes
|
|
23
24
|
* if (data.isTextNode) {
|
|
24
|
-
* showContentInput(true);
|
|
25
|
+
* showContentInput(true, true); // updateImmediately: true for instant feedback
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* // Dynamically show image input for image nodes
|
|
29
|
+
* if (data.isImageNode) {
|
|
30
|
+
* showImageInput(true, true); // updateImmediately: true for instant feedback
|
|
25
31
|
* }
|
|
26
32
|
* },
|
|
27
33
|
* onPromptSubmitted: (data) => {
|
|
@@ -35,6 +41,19 @@
|
|
|
35
41
|
* onTextUpdated: (data) => {
|
|
36
42
|
* console.log('Text updated:', data.text);
|
|
37
43
|
* },
|
|
44
|
+
* onImageUpdated: (data) => {
|
|
45
|
+
* console.log('Image updated:', data.imageFile.name);
|
|
46
|
+
* console.log('Image data (base64):', data.imageData);
|
|
47
|
+
* // Upload to server
|
|
48
|
+
* fetch('/api/upload-image', {
|
|
49
|
+
* method: 'POST',
|
|
50
|
+
* body: JSON.stringify(data)
|
|
51
|
+
* });
|
|
52
|
+
* },
|
|
53
|
+
* onInspectorClosed: () => {
|
|
54
|
+
* console.log('Inspector closed');
|
|
55
|
+
* // Update UI state, re-enable elements, etc.
|
|
56
|
+
* },
|
|
38
57
|
* onError: (data) => {
|
|
39
58
|
* console.error('Error:', data);
|
|
40
59
|
* // Send to error tracking service
|
|
@@ -45,7 +64,12 @@
|
|
|
45
64
|
* editText: 'Edit Text',
|
|
46
65
|
* textPlaceholder: 'Enter text...',
|
|
47
66
|
* updateText: 'Update',
|
|
48
|
-
* promptPlaceholder: 'Ask AI for changes...'
|
|
67
|
+
* promptPlaceholder: 'Ask AI for changes...',
|
|
68
|
+
* editImage: 'Change Image',
|
|
69
|
+
* imageUploadTitle: 'Select Image',
|
|
70
|
+
* imageUploadHint: 'Click or drag',
|
|
71
|
+
* updateImage: 'Update Image',
|
|
72
|
+
* badgeText: 'Built with Promake'
|
|
49
73
|
* },
|
|
50
74
|
* {
|
|
51
75
|
* // Optional: Custom theme colors (all optional)
|
|
@@ -55,7 +79,10 @@
|
|
|
55
79
|
* buttonTextColor: '#ffffff',
|
|
56
80
|
* inputBackgroundColor: '#f9fafb',
|
|
57
81
|
* inputTextColor: '#111827',
|
|
58
|
-
* inputBorderColor: '#d1d5db'
|
|
82
|
+
* inputBorderColor: '#d1d5db',
|
|
83
|
+
* badgeGradientStart: '#411E93',
|
|
84
|
+
* badgeGradientEnd: '#E87C85',
|
|
85
|
+
* badgeTextColor: '#ffffff'
|
|
59
86
|
* }
|
|
60
87
|
* );
|
|
61
88
|
*
|
|
@@ -66,7 +93,13 @@
|
|
|
66
93
|
* Toggle Inspector
|
|
67
94
|
* </button>
|
|
68
95
|
* <button onClick={() => showContentInput(true)}>
|
|
69
|
-
* Show
|
|
96
|
+
* Show Text Input
|
|
97
|
+
* </button>
|
|
98
|
+
* <button onClick={() => showImageInput(true)}>
|
|
99
|
+
* Show Image Input
|
|
100
|
+
* </button>
|
|
101
|
+
* <button onClick={() => setBadgeVisible(true)}>
|
|
102
|
+
* Show Promake Badge
|
|
70
103
|
* </button>
|
|
71
104
|
* </div>
|
|
72
105
|
* <iframe ref={iframeRef} src="http://localhost:5173" />
|
|
@@ -122,37 +155,77 @@ export function useInspector(iframeRef, callbacks, labels, theme) {
|
|
|
122
155
|
/**
|
|
123
156
|
* Show or hide content input
|
|
124
157
|
*/
|
|
125
|
-
const showContentInput = useCallback((show) => {
|
|
158
|
+
const showContentInput = useCallback((show, updateImmediately) => {
|
|
126
159
|
sendMessage({
|
|
127
160
|
type: "SHOW_CONTENT_INPUT",
|
|
128
161
|
show: show,
|
|
162
|
+
updateImmediately: updateImmediately,
|
|
129
163
|
});
|
|
130
164
|
}, [sendMessage]);
|
|
165
|
+
/**
|
|
166
|
+
* Show or hide image input
|
|
167
|
+
*/
|
|
168
|
+
const showImageInput = useCallback((show, updateImmediately) => {
|
|
169
|
+
sendMessage({
|
|
170
|
+
type: "SHOW_IMAGE_INPUT",
|
|
171
|
+
show: show,
|
|
172
|
+
updateImmediately: updateImmediately,
|
|
173
|
+
});
|
|
174
|
+
}, [sendMessage]);
|
|
175
|
+
/**
|
|
176
|
+
* Show or hide "Built with Promake" badge
|
|
177
|
+
*/
|
|
178
|
+
const setBadgeVisible = useCallback((visible) => {
|
|
179
|
+
sendMessage({
|
|
180
|
+
type: "SET_BADGE_VISIBLE",
|
|
181
|
+
visible: visible,
|
|
182
|
+
badgeText: labels?.badgeText,
|
|
183
|
+
});
|
|
184
|
+
}, [sendMessage, labels]);
|
|
131
185
|
/**
|
|
132
186
|
* Listen for messages from iframe
|
|
133
187
|
*/
|
|
134
188
|
useEffect(() => {
|
|
135
189
|
const handleMessage = (event) => {
|
|
190
|
+
// Parse message if it's a string (JSON stringified)
|
|
191
|
+
let messageData;
|
|
192
|
+
if (typeof event.data === "string") {
|
|
193
|
+
try {
|
|
194
|
+
messageData = JSON.parse(event.data);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return; // Invalid JSON, ignore
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
messageData = event.data;
|
|
202
|
+
}
|
|
136
203
|
// Security: Only handle expected message types
|
|
137
|
-
if (!
|
|
204
|
+
if (!messageData || typeof messageData.type !== "string") {
|
|
138
205
|
return;
|
|
139
206
|
}
|
|
140
|
-
|
|
141
|
-
switch (type) {
|
|
207
|
+
switch (messageData.type) {
|
|
142
208
|
case "INSPECTOR_ELEMENT_SELECTED":
|
|
143
|
-
callbacks?.onElementSelected?.(data);
|
|
209
|
+
callbacks?.onElementSelected?.(messageData.data);
|
|
144
210
|
break;
|
|
145
211
|
case "URL_CHANGED":
|
|
146
|
-
callbacks?.onUrlChange?.(data);
|
|
212
|
+
callbacks?.onUrlChange?.(messageData.data);
|
|
147
213
|
break;
|
|
148
214
|
case "INSPECTOR_PROMPT_SUBMITTED":
|
|
149
|
-
callbacks?.onPromptSubmitted?.(data);
|
|
215
|
+
callbacks?.onPromptSubmitted?.(messageData.data);
|
|
150
216
|
break;
|
|
151
217
|
case "INSPECTOR_TEXT_UPDATED":
|
|
152
|
-
callbacks?.onTextUpdated?.(data);
|
|
218
|
+
callbacks?.onTextUpdated?.(messageData.data);
|
|
219
|
+
break;
|
|
220
|
+
case "INSPECTOR_IMAGE_UPDATED":
|
|
221
|
+
callbacks?.onImageUpdated?.(messageData.data);
|
|
222
|
+
break;
|
|
223
|
+
case "INSPECTOR_CLOSED":
|
|
224
|
+
setIsInspecting(false);
|
|
225
|
+
callbacks?.onInspectorClosed?.();
|
|
153
226
|
break;
|
|
154
227
|
case "INSPECTOR_ERROR":
|
|
155
|
-
callbacks?.onError?.(data);
|
|
228
|
+
callbacks?.onError?.(messageData.data);
|
|
156
229
|
break;
|
|
157
230
|
default:
|
|
158
231
|
// Unknown message type - ignore
|
|
@@ -185,5 +258,7 @@ export function useInspector(iframeRef, callbacks, labels, theme) {
|
|
|
185
258
|
startInspecting,
|
|
186
259
|
stopInspecting,
|
|
187
260
|
showContentInput,
|
|
261
|
+
showImageInput,
|
|
262
|
+
setBadgeVisible,
|
|
188
263
|
};
|
|
189
264
|
}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,eAAe,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,eAAe,IAAI,MAAM,CA+rCxC"}
|