fixdog 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 +478 -0
- package/USAGE.md +77 -0
- package/dist/client/index.d.mts +110 -0
- package/dist/client/index.d.ts +110 -0
- package/dist/client/index.js +1601 -0
- package/dist/client/index.mjs +1582 -0
- package/dist/client/init.d.mts +67 -0
- package/dist/client/init.d.ts +67 -0
- package/dist/client/init.js +1609 -0
- package/dist/client/init.mjs +1593 -0
- package/dist/index.d.mts +158 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +1635 -0
- package/dist/index.mjs +1606 -0
- package/package.json +57 -0
- package/src/api/client.ts +141 -0
- package/src/client/index.ts +75 -0
- package/src/client/init.tsx +78 -0
- package/src/components/ConversationalInputReact.tsx +406 -0
- package/src/components/ElementInfoDisplayReact.tsx +84 -0
- package/src/components/UiDogSidebarReact.tsx +49 -0
- package/src/element-detector.ts +186 -0
- package/src/index.ts +228 -0
- package/src/instrument.ts +171 -0
- package/src/sidebar-initializer.ts +171 -0
- package/src/source-resolver.ts +121 -0
- package/src/styles/sidebarStyles.ts +597 -0
- package/src/types/css.d.ts +9 -0
- package/src/types/sidebar.ts +56 -0
- package/src/types.ts +119 -0
- package/tsconfig.json +23 -0
- package/tsup.config.ts +40 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1606 @@
|
|
|
1
|
+
// src/instrument.ts
|
|
2
|
+
import {
|
|
3
|
+
instrument,
|
|
4
|
+
secure,
|
|
5
|
+
isCompositeFiber,
|
|
6
|
+
isHostFiber,
|
|
7
|
+
traverseFiber,
|
|
8
|
+
getDisplayName,
|
|
9
|
+
getFiberFromHostInstance
|
|
10
|
+
} from "bippy";
|
|
11
|
+
import { getSource } from "bippy/source";
|
|
12
|
+
var isInstrumented = false;
|
|
13
|
+
function setupBippyInstrumentation() {
|
|
14
|
+
if (isInstrumented)
|
|
15
|
+
return;
|
|
16
|
+
if (typeof window === "undefined")
|
|
17
|
+
return;
|
|
18
|
+
isInstrumented = true;
|
|
19
|
+
instrument(
|
|
20
|
+
secure({
|
|
21
|
+
onCommitFiberRoot: (_rendererID, _fiberRoot) => {
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
async function getSourceFromElement(element) {
|
|
27
|
+
try {
|
|
28
|
+
const fiber = getFiberFromHostInstance(element);
|
|
29
|
+
if (!fiber) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const source = await getSource(fiber);
|
|
33
|
+
if (source && source.fileName) {
|
|
34
|
+
if (source.fileName.includes("node_modules") || source.fileName.includes("react-dom") || source.fileName.includes("react/")) {
|
|
35
|
+
return await findUserSourceFromFiber(fiber);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
fileName: source.fileName,
|
|
39
|
+
lineNumber: source.lineNumber ?? 1,
|
|
40
|
+
columnNumber: source.columnNumber ?? 1,
|
|
41
|
+
functionName: source.functionName ?? void 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return await findUserSourceFromFiber(fiber);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.warn("[UiDog Next] Error getting source from element:", error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function findUserSourceFromFiber(startFiber) {
|
|
51
|
+
let result = null;
|
|
52
|
+
traverseFiber(
|
|
53
|
+
startFiber,
|
|
54
|
+
async (fiber) => {
|
|
55
|
+
if (isCompositeFiber(fiber)) {
|
|
56
|
+
try {
|
|
57
|
+
const source = await getSource(fiber);
|
|
58
|
+
if (source && source.fileName) {
|
|
59
|
+
if (!source.fileName.includes("node_modules") && !source.fileName.includes("react-dom") && !source.fileName.includes("react/")) {
|
|
60
|
+
result = {
|
|
61
|
+
fileName: source.fileName,
|
|
62
|
+
lineNumber: source.lineNumber ?? 1,
|
|
63
|
+
columnNumber: source.columnNumber ?? 1,
|
|
64
|
+
functionName: source.functionName ?? getDisplayName(fiber) ?? void 0
|
|
65
|
+
};
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
},
|
|
74
|
+
true
|
|
75
|
+
// Traverse upward (toward root)
|
|
76
|
+
);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function getComponentNameFromFiber(fiber) {
|
|
80
|
+
if (!fiber)
|
|
81
|
+
return "Unknown";
|
|
82
|
+
const displayName = getDisplayName(fiber);
|
|
83
|
+
if (displayName && displayName !== "Unknown") {
|
|
84
|
+
return displayName;
|
|
85
|
+
}
|
|
86
|
+
let componentName = "Unknown";
|
|
87
|
+
traverseFiber(
|
|
88
|
+
fiber,
|
|
89
|
+
(f) => {
|
|
90
|
+
if (isCompositeFiber(f)) {
|
|
91
|
+
const name = getDisplayName(f);
|
|
92
|
+
if (name && name !== "Unknown") {
|
|
93
|
+
componentName = name;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
},
|
|
99
|
+
true
|
|
100
|
+
// Traverse upward
|
|
101
|
+
);
|
|
102
|
+
return componentName;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/source-resolver.ts
|
|
106
|
+
var EDITOR_SCHEMES = {
|
|
107
|
+
vscode: "vscode://file/{path}:{line}:{column}",
|
|
108
|
+
"vscode-insiders": "vscode-insiders://file/{path}:{line}:{column}",
|
|
109
|
+
cursor: "cursor://file/{path}:{line}:{column}",
|
|
110
|
+
webstorm: "webstorm://open?file={path}&line={line}&column={column}",
|
|
111
|
+
atom: "atom://core/open/file?filename={path}&line={line}&column={column}",
|
|
112
|
+
sublime: "subl://open?url=file://{path}&line={line}&column={column}"
|
|
113
|
+
};
|
|
114
|
+
function buildEditorUrl(source, editor = "cursor", projectPath = "") {
|
|
115
|
+
const template = EDITOR_SCHEMES[editor] || EDITOR_SCHEMES.cursor;
|
|
116
|
+
let fullPath = normalizeFileName(source.fileName);
|
|
117
|
+
if (projectPath && !fullPath.startsWith("/")) {
|
|
118
|
+
const normalizedProjectPath = projectPath.endsWith("/") ? projectPath.slice(0, -1) : projectPath;
|
|
119
|
+
fullPath = `${normalizedProjectPath}/${fullPath}`;
|
|
120
|
+
}
|
|
121
|
+
return template.replace("{path}", fullPath).replace("{line}", String(source.lineNumber || 1)).replace("{column}", String(source.columnNumber || 1));
|
|
122
|
+
}
|
|
123
|
+
function normalizeFileName(fileName) {
|
|
124
|
+
if (!fileName)
|
|
125
|
+
return "";
|
|
126
|
+
let normalized = fileName;
|
|
127
|
+
const prefixPatterns = [
|
|
128
|
+
/^webpack:\/\/[^/]*\//,
|
|
129
|
+
/^webpack-internal:\/\/\//,
|
|
130
|
+
/^file:\/\//,
|
|
131
|
+
/^about:react/,
|
|
132
|
+
/^\.\//,
|
|
133
|
+
/^https?:\/\/localhost:\d+\//,
|
|
134
|
+
/^https?:\/\/[^/]+\/@fs\//,
|
|
135
|
+
/^https?:\/\/[^/]+\//,
|
|
136
|
+
/^\/@fs\//,
|
|
137
|
+
/^@fs\//
|
|
138
|
+
];
|
|
139
|
+
for (const pattern of prefixPatterns) {
|
|
140
|
+
normalized = normalized.replace(pattern, "");
|
|
141
|
+
}
|
|
142
|
+
normalized = normalized.split("?")[0].split("#")[0];
|
|
143
|
+
normalized = normalized.replace(/^\/+/, "/");
|
|
144
|
+
return normalized;
|
|
145
|
+
}
|
|
146
|
+
function isSourceFile(fileName) {
|
|
147
|
+
if (!fileName)
|
|
148
|
+
return false;
|
|
149
|
+
const normalized = normalizeFileName(fileName);
|
|
150
|
+
const excludePatterns = [
|
|
151
|
+
/node_modules/,
|
|
152
|
+
/react-dom/,
|
|
153
|
+
/^react\//,
|
|
154
|
+
/\.next\//,
|
|
155
|
+
/_next\//,
|
|
156
|
+
/webpack/,
|
|
157
|
+
/@vite\//,
|
|
158
|
+
/vite\/client/,
|
|
159
|
+
/\[eval\]/,
|
|
160
|
+
/<anonymous>/
|
|
161
|
+
];
|
|
162
|
+
for (const pattern of excludePatterns) {
|
|
163
|
+
if (pattern.test(normalized)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const includeExtensions = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".cjs"];
|
|
168
|
+
return includeExtensions.some(
|
|
169
|
+
(ext) => normalized.toLowerCase().endsWith(ext)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
function getShortFileName(filePath) {
|
|
173
|
+
const normalized = normalizeFileName(filePath);
|
|
174
|
+
const parts = normalized.split("/");
|
|
175
|
+
return parts[parts.length - 1] || normalized;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/element-detector.ts
|
|
179
|
+
var detectorCleanup = null;
|
|
180
|
+
var isSetup = false;
|
|
181
|
+
function setupElementDetector(options) {
|
|
182
|
+
const { onElementSelected, modifier = "alt" } = options;
|
|
183
|
+
if (detectorCleanup) {
|
|
184
|
+
detectorCleanup();
|
|
185
|
+
}
|
|
186
|
+
isSetup = true;
|
|
187
|
+
const handleClick = async (event) => {
|
|
188
|
+
const modifierPressed = modifier === "alt" && event.altKey || modifier === "ctrl" && event.ctrlKey || modifier === "meta" && event.metaKey || modifier === "shift" && event.shiftKey;
|
|
189
|
+
if (!modifierPressed)
|
|
190
|
+
return;
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
event.stopPropagation();
|
|
193
|
+
const target = event.target;
|
|
194
|
+
try {
|
|
195
|
+
const source = await getSourceFromElement(target);
|
|
196
|
+
if (source && source.fileName && isSourceFile(source.fileName)) {
|
|
197
|
+
const fiber = getFiberFromHostInstance(target);
|
|
198
|
+
const componentName = fiber ? getComponentNameFromFiber(fiber) : "Unknown";
|
|
199
|
+
const enrichedSource = {
|
|
200
|
+
...source,
|
|
201
|
+
functionName: source.functionName || componentName
|
|
202
|
+
};
|
|
203
|
+
onElementSelected(enrichedSource, target);
|
|
204
|
+
} else {
|
|
205
|
+
console.info(
|
|
206
|
+
"[UiDog Next] Could not find source for element. Falling back to DOM snapshot (likely server component or library code)."
|
|
207
|
+
);
|
|
208
|
+
onElementSelected(null, target);
|
|
209
|
+
}
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.warn("[UiDog Next] Error detecting element source:", error);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const handleMouseMove = (event) => {
|
|
215
|
+
const modifierPressed = modifier === "alt" && event.altKey || modifier === "ctrl" && event.ctrlKey || modifier === "meta" && event.metaKey || modifier === "shift" && event.shiftKey;
|
|
216
|
+
if (!modifierPressed) {
|
|
217
|
+
removeHighlight();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const target = event.target;
|
|
221
|
+
highlightElement(target);
|
|
222
|
+
};
|
|
223
|
+
const handleKeyUp = (event) => {
|
|
224
|
+
const relevantKey = modifier === "alt" && event.key === "Alt" || modifier === "ctrl" && event.key === "Control" || modifier === "meta" && event.key === "Meta" || modifier === "shift" && event.key === "Shift";
|
|
225
|
+
if (relevantKey) {
|
|
226
|
+
removeHighlight();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
document.addEventListener("click", handleClick, true);
|
|
230
|
+
document.addEventListener("mousemove", handleMouseMove, true);
|
|
231
|
+
document.addEventListener("keyup", handleKeyUp, true);
|
|
232
|
+
detectorCleanup = () => {
|
|
233
|
+
document.removeEventListener("click", handleClick, true);
|
|
234
|
+
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
235
|
+
document.removeEventListener("keyup", handleKeyUp, true);
|
|
236
|
+
removeHighlight();
|
|
237
|
+
isSetup = false;
|
|
238
|
+
};
|
|
239
|
+
return detectorCleanup;
|
|
240
|
+
}
|
|
241
|
+
var currentHighlight = null;
|
|
242
|
+
var highlightOverlay = null;
|
|
243
|
+
function highlightElement(element) {
|
|
244
|
+
if (element === highlightOverlay || highlightOverlay?.contains(element)) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (!highlightOverlay) {
|
|
248
|
+
highlightOverlay = document.createElement("div");
|
|
249
|
+
highlightOverlay.id = "uidog-highlight-overlay";
|
|
250
|
+
highlightOverlay.style.cssText = `
|
|
251
|
+
position: fixed;
|
|
252
|
+
pointer-events: none;
|
|
253
|
+
background: rgba(59, 130, 246, 0.2);
|
|
254
|
+
border: 2px solid rgba(59, 130, 246, 0.8);
|
|
255
|
+
border-radius: 4px;
|
|
256
|
+
z-index: 999998;
|
|
257
|
+
transition: all 0.1s ease-out;
|
|
258
|
+
`;
|
|
259
|
+
document.body.appendChild(highlightOverlay);
|
|
260
|
+
}
|
|
261
|
+
const rect = element.getBoundingClientRect();
|
|
262
|
+
highlightOverlay.style.top = `${rect.top}px`;
|
|
263
|
+
highlightOverlay.style.left = `${rect.left}px`;
|
|
264
|
+
highlightOverlay.style.width = `${rect.width}px`;
|
|
265
|
+
highlightOverlay.style.height = `${rect.height}px`;
|
|
266
|
+
highlightOverlay.style.display = "block";
|
|
267
|
+
currentHighlight = element;
|
|
268
|
+
}
|
|
269
|
+
function removeHighlight() {
|
|
270
|
+
if (highlightOverlay) {
|
|
271
|
+
highlightOverlay.style.display = "none";
|
|
272
|
+
}
|
|
273
|
+
currentHighlight = null;
|
|
274
|
+
}
|
|
275
|
+
function cleanupElementDetector() {
|
|
276
|
+
if (detectorCleanup) {
|
|
277
|
+
detectorCleanup();
|
|
278
|
+
detectorCleanup = null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/sidebar-initializer.ts
|
|
283
|
+
import { createRoot } from "react-dom/client";
|
|
284
|
+
import { createElement } from "react";
|
|
285
|
+
|
|
286
|
+
// src/components/UiDogSidebarReact.tsx
|
|
287
|
+
import { useEffect as useEffect2 } from "react";
|
|
288
|
+
|
|
289
|
+
// src/components/ElementInfoDisplayReact.tsx
|
|
290
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
291
|
+
function ElementInfoDisplayReact(props) {
|
|
292
|
+
const isDomSnapshot = props.elementInfo.kind === "dom";
|
|
293
|
+
if (isDomSnapshot) {
|
|
294
|
+
const dom = props.elementInfo.domSnapshot;
|
|
295
|
+
const outerHTML = dom?.outerHTML || "No HTML available";
|
|
296
|
+
const text = dom?.text || "";
|
|
297
|
+
const attributes = dom?.attributes || {};
|
|
298
|
+
return /* @__PURE__ */ jsxs("div", { className: "uidog-element-info", children: [
|
|
299
|
+
/* @__PURE__ */ jsxs("div", { className: "uidog-element-info-content", children: [
|
|
300
|
+
/* @__PURE__ */ jsx("div", { className: "uidog-file-location", children: "Server-rendered DOM (no source available)" }),
|
|
301
|
+
/* @__PURE__ */ jsx(
|
|
302
|
+
"button",
|
|
303
|
+
{
|
|
304
|
+
className: "uidog-close-btn",
|
|
305
|
+
onClick: props.onClose,
|
|
306
|
+
title: "Close sidebar (ESC)",
|
|
307
|
+
"aria-label": "Close sidebar",
|
|
308
|
+
children: "\xD7"
|
|
309
|
+
}
|
|
310
|
+
)
|
|
311
|
+
] }),
|
|
312
|
+
/* @__PURE__ */ jsxs("div", { className: "uidog-dom-snapshot", children: [
|
|
313
|
+
/* @__PURE__ */ jsx("div", { className: "uidog-dom-label", children: "outerHTML (trimmed):" }),
|
|
314
|
+
/* @__PURE__ */ jsx("pre", { className: "uidog-dom-snippet", children: outerHTML }),
|
|
315
|
+
text && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
316
|
+
/* @__PURE__ */ jsx("div", { className: "uidog-dom-label", children: "textContent (trimmed):" }),
|
|
317
|
+
/* @__PURE__ */ jsx("pre", { className: "uidog-dom-snippet", children: text })
|
|
318
|
+
] }),
|
|
319
|
+
Object.keys(attributes).length > 0 && /* @__PURE__ */ jsxs("div", { className: "uidog-dom-attributes", children: [
|
|
320
|
+
/* @__PURE__ */ jsx("div", { className: "uidog-dom-label", children: "attributes:" }),
|
|
321
|
+
/* @__PURE__ */ jsx("ul", { children: Object.entries(attributes).map(([key, value]) => /* @__PURE__ */ jsxs("li", { children: [
|
|
322
|
+
/* @__PURE__ */ jsx("code", { children: key }),
|
|
323
|
+
"=",
|
|
324
|
+
/* @__PURE__ */ jsx("code", { children: value })
|
|
325
|
+
] }, key)) })
|
|
326
|
+
] }),
|
|
327
|
+
/* @__PURE__ */ jsx("div", { className: "uidog-dom-hint", children: "To see file/line info, render this DOM through a small client boundary." })
|
|
328
|
+
] })
|
|
329
|
+
] });
|
|
330
|
+
}
|
|
331
|
+
const fileName = props.elementInfo.filePath?.split("/").pop() || "";
|
|
332
|
+
const fileLocation = `Selected element at ${fileName}`;
|
|
333
|
+
return /* @__PURE__ */ jsx("div", { className: "uidog-element-info", children: /* @__PURE__ */ jsxs("div", { className: "uidog-element-info-content", children: [
|
|
334
|
+
/* @__PURE__ */ jsx("span", { className: "uidog-file-location", children: fileLocation }),
|
|
335
|
+
/* @__PURE__ */ jsx(
|
|
336
|
+
"button",
|
|
337
|
+
{
|
|
338
|
+
className: "uidog-close-btn",
|
|
339
|
+
onClick: props.onClose,
|
|
340
|
+
title: "Close sidebar (ESC)",
|
|
341
|
+
"aria-label": "Close sidebar",
|
|
342
|
+
children: "\xD7"
|
|
343
|
+
}
|
|
344
|
+
)
|
|
345
|
+
] }) });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/components/ConversationalInputReact.tsx
|
|
349
|
+
import { useState, useEffect, useRef } from "react";
|
|
350
|
+
|
|
351
|
+
// src/api/client.ts
|
|
352
|
+
async function sendChatPrompt(request, apiEndpoint = "http://localhost:3000") {
|
|
353
|
+
try {
|
|
354
|
+
const response = await fetch(`${apiEndpoint}/chat`, {
|
|
355
|
+
method: "POST",
|
|
356
|
+
headers: {
|
|
357
|
+
"Content-Type": "application/json"
|
|
358
|
+
},
|
|
359
|
+
body: JSON.stringify(request)
|
|
360
|
+
});
|
|
361
|
+
if (!response.ok) {
|
|
362
|
+
const errorData = await response.json().catch(() => ({ error: response.statusText }));
|
|
363
|
+
return {
|
|
364
|
+
ok: false,
|
|
365
|
+
message: "",
|
|
366
|
+
error: errorData.error || `API error (${response.status})`
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
return await response.json();
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (error instanceof Error) {
|
|
372
|
+
return {
|
|
373
|
+
ok: false,
|
|
374
|
+
message: "",
|
|
375
|
+
error: error.message
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
ok: false,
|
|
380
|
+
message: "",
|
|
381
|
+
error: "Unknown error occurred"
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
async function sendToDeveloper(request, apiEndpoint = "http://localhost:3000") {
|
|
386
|
+
try {
|
|
387
|
+
const response = await fetch(`${apiEndpoint}/send-to-dev`, {
|
|
388
|
+
method: "POST",
|
|
389
|
+
headers: {
|
|
390
|
+
"Content-Type": "application/json"
|
|
391
|
+
},
|
|
392
|
+
body: JSON.stringify(request)
|
|
393
|
+
});
|
|
394
|
+
if (!response.ok) {
|
|
395
|
+
const errorData = await response.json().catch(() => ({ error: response.statusText }));
|
|
396
|
+
return {
|
|
397
|
+
ok: false,
|
|
398
|
+
error: errorData.error || `API error (${response.status})`
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
return await response.json();
|
|
402
|
+
} catch (error) {
|
|
403
|
+
if (error instanceof Error) {
|
|
404
|
+
return {
|
|
405
|
+
ok: false,
|
|
406
|
+
error: error.message
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
ok: false,
|
|
411
|
+
error: "Unknown error occurred"
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/components/ConversationalInputReact.tsx
|
|
417
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
418
|
+
function ConversationalInputReact(props) {
|
|
419
|
+
const [userInput, setUserInput] = useState("");
|
|
420
|
+
const [messages, setMessages] = useState([]);
|
|
421
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
422
|
+
const [sessionId, setSessionId] = useState(void 0);
|
|
423
|
+
const [isCreatingPR, setIsCreatingPR] = useState(false);
|
|
424
|
+
const [prUrl, setPrUrl] = useState(null);
|
|
425
|
+
const textareaRef = useRef(null);
|
|
426
|
+
const messagesEndRef = useRef(null);
|
|
427
|
+
useEffect(() => {
|
|
428
|
+
textareaRef.current?.focus();
|
|
429
|
+
}, []);
|
|
430
|
+
useEffect(() => {
|
|
431
|
+
const textarea = textareaRef.current;
|
|
432
|
+
if (textarea) {
|
|
433
|
+
textarea.style.height = "auto";
|
|
434
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, 200)}px`;
|
|
435
|
+
}
|
|
436
|
+
}, [userInput]);
|
|
437
|
+
useEffect(() => {
|
|
438
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
439
|
+
}, [messages]);
|
|
440
|
+
const handleSubmit = async () => {
|
|
441
|
+
const input = userInput.trim();
|
|
442
|
+
if (!input || isLoading)
|
|
443
|
+
return;
|
|
444
|
+
const userMessage = {
|
|
445
|
+
id: `user-${Date.now()}`,
|
|
446
|
+
role: "user",
|
|
447
|
+
content: input,
|
|
448
|
+
timestamp: Date.now()
|
|
449
|
+
};
|
|
450
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
451
|
+
setUserInput("");
|
|
452
|
+
setIsLoading(true);
|
|
453
|
+
const loadingMessageId = `loading-${Date.now()}`;
|
|
454
|
+
const loadingMessage = {
|
|
455
|
+
id: loadingMessageId,
|
|
456
|
+
role: "assistant",
|
|
457
|
+
content: "",
|
|
458
|
+
timestamp: Date.now(),
|
|
459
|
+
isLoading: true
|
|
460
|
+
};
|
|
461
|
+
setMessages((prev) => [...prev, loadingMessage]);
|
|
462
|
+
const request = {
|
|
463
|
+
prompt: `The component selected by the user: ${props.editorUrl}
|
|
464
|
+
User request: ${input}
|
|
465
|
+
Update multiple files (if necessary) to achieve the user's request.`,
|
|
466
|
+
sessionId
|
|
467
|
+
};
|
|
468
|
+
try {
|
|
469
|
+
const result = await sendChatPrompt(
|
|
470
|
+
request,
|
|
471
|
+
props.apiEndpoint
|
|
472
|
+
);
|
|
473
|
+
if (result.sessionId && !sessionId) {
|
|
474
|
+
setSessionId(result.sessionId);
|
|
475
|
+
}
|
|
476
|
+
setMessages((prev) => {
|
|
477
|
+
const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
|
|
478
|
+
const assistantMessage = {
|
|
479
|
+
id: `assistant-${Date.now()}`,
|
|
480
|
+
role: "assistant",
|
|
481
|
+
content: result.ok ? result.message : result.error || "Request failed",
|
|
482
|
+
timestamp: Date.now(),
|
|
483
|
+
error: !result.ok ? result.error : void 0
|
|
484
|
+
};
|
|
485
|
+
return [...filtered, assistantMessage];
|
|
486
|
+
});
|
|
487
|
+
} catch (err) {
|
|
488
|
+
setMessages((prev) => {
|
|
489
|
+
const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
|
|
490
|
+
const errorMessage = {
|
|
491
|
+
id: `error-${Date.now()}`,
|
|
492
|
+
role: "assistant",
|
|
493
|
+
content: err instanceof Error ? err.message : "Unknown error occurred",
|
|
494
|
+
timestamp: Date.now(),
|
|
495
|
+
error: err instanceof Error ? err.message : "Unknown error occurred"
|
|
496
|
+
};
|
|
497
|
+
return [...filtered, errorMessage];
|
|
498
|
+
});
|
|
499
|
+
} finally {
|
|
500
|
+
setIsLoading(false);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const handleKeyDown = (e) => {
|
|
504
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
505
|
+
e.preventDefault();
|
|
506
|
+
handleSubmit();
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const handleSendToDeveloper = async () => {
|
|
510
|
+
if (!sessionId || isCreatingPR)
|
|
511
|
+
return;
|
|
512
|
+
setIsCreatingPR(true);
|
|
513
|
+
setPrUrl(null);
|
|
514
|
+
try {
|
|
515
|
+
const result = await sendToDeveloper(
|
|
516
|
+
{ sessionId },
|
|
517
|
+
props.apiEndpoint
|
|
518
|
+
);
|
|
519
|
+
if (result.ok && result.prUrl) {
|
|
520
|
+
setPrUrl(result.prUrl);
|
|
521
|
+
const successMessage = {
|
|
522
|
+
id: `pr-success-${Date.now()}`,
|
|
523
|
+
role: "assistant",
|
|
524
|
+
content: `Pull request created successfully!`,
|
|
525
|
+
timestamp: Date.now()
|
|
526
|
+
};
|
|
527
|
+
setMessages((prev) => [...prev, successMessage]);
|
|
528
|
+
} else {
|
|
529
|
+
const errorMessage = {
|
|
530
|
+
id: `pr-error-${Date.now()}`,
|
|
531
|
+
role: "assistant",
|
|
532
|
+
content: result.error || "Failed to create pull request",
|
|
533
|
+
timestamp: Date.now(),
|
|
534
|
+
error: result.error || "Failed to create pull request"
|
|
535
|
+
};
|
|
536
|
+
setMessages((prev) => [...prev, errorMessage]);
|
|
537
|
+
}
|
|
538
|
+
} catch (err) {
|
|
539
|
+
const errorMessage = {
|
|
540
|
+
id: `pr-error-${Date.now()}`,
|
|
541
|
+
role: "assistant",
|
|
542
|
+
content: err instanceof Error ? err.message : "Unknown error occurred",
|
|
543
|
+
timestamp: Date.now(),
|
|
544
|
+
error: err instanceof Error ? err.message : "Unknown error occurred"
|
|
545
|
+
};
|
|
546
|
+
setMessages((prev) => [...prev, errorMessage]);
|
|
547
|
+
} finally {
|
|
548
|
+
setIsCreatingPR(false);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
const handleRetry = async (messageId) => {
|
|
552
|
+
const errorIndex = messages.findIndex((msg) => msg.id === messageId);
|
|
553
|
+
if (errorIndex === -1)
|
|
554
|
+
return;
|
|
555
|
+
let userMessageIndex = -1;
|
|
556
|
+
for (let i = errorIndex - 1; i >= 0; i--) {
|
|
557
|
+
if (messages[i].role === "user") {
|
|
558
|
+
userMessageIndex = i;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (userMessageIndex === -1)
|
|
563
|
+
return;
|
|
564
|
+
const userMessage = messages[userMessageIndex];
|
|
565
|
+
const input = userMessage.content;
|
|
566
|
+
setMessages((prev) => prev.filter((msg) => msg.id !== messageId));
|
|
567
|
+
setIsLoading(true);
|
|
568
|
+
const loadingMessageId = `loading-${Date.now()}`;
|
|
569
|
+
const loadingMessage = {
|
|
570
|
+
id: loadingMessageId,
|
|
571
|
+
role: "assistant",
|
|
572
|
+
content: "",
|
|
573
|
+
timestamp: Date.now(),
|
|
574
|
+
isLoading: true
|
|
575
|
+
};
|
|
576
|
+
setMessages((prev) => [...prev, loadingMessage]);
|
|
577
|
+
const request = {
|
|
578
|
+
prompt: `The component selected by the user: ${props.editorUrl}
|
|
579
|
+
User request: ${input}
|
|
580
|
+
Update multiple files (if necessary) to achieve the user's request.`,
|
|
581
|
+
sessionId
|
|
582
|
+
};
|
|
583
|
+
try {
|
|
584
|
+
const result = await sendChatPrompt(
|
|
585
|
+
request,
|
|
586
|
+
props.apiEndpoint
|
|
587
|
+
);
|
|
588
|
+
if (result.sessionId && !sessionId) {
|
|
589
|
+
setSessionId(result.sessionId);
|
|
590
|
+
}
|
|
591
|
+
setMessages((prev) => {
|
|
592
|
+
const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
|
|
593
|
+
const assistantMessage = {
|
|
594
|
+
id: `assistant-${Date.now()}`,
|
|
595
|
+
role: "assistant",
|
|
596
|
+
content: result.ok ? result.message : result.error || "Request failed",
|
|
597
|
+
timestamp: Date.now(),
|
|
598
|
+
error: !result.ok ? result.error : void 0
|
|
599
|
+
};
|
|
600
|
+
return [...filtered, assistantMessage];
|
|
601
|
+
});
|
|
602
|
+
} catch (err) {
|
|
603
|
+
setMessages((prev) => {
|
|
604
|
+
const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
|
|
605
|
+
const errorMessage = {
|
|
606
|
+
id: `error-${Date.now()}`,
|
|
607
|
+
role: "assistant",
|
|
608
|
+
content: err instanceof Error ? err.message : "Unknown error occurred",
|
|
609
|
+
timestamp: Date.now(),
|
|
610
|
+
error: err instanceof Error ? err.message : "Unknown error occurred"
|
|
611
|
+
};
|
|
612
|
+
return [...filtered, errorMessage];
|
|
613
|
+
});
|
|
614
|
+
} finally {
|
|
615
|
+
setIsLoading(false);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
619
|
+
/* @__PURE__ */ jsxs2("div", { className: "uidog-messages-container", children: [
|
|
620
|
+
messages.length === 0 && /* @__PURE__ */ jsx2("div", { className: "uidog-empty-state", children: /* @__PURE__ */ jsx2("div", { className: "uidog-empty-state-text", children: "What changes would you like to make?" }) }),
|
|
621
|
+
messages.map((message) => /* @__PURE__ */ jsx2(
|
|
622
|
+
"div",
|
|
623
|
+
{
|
|
624
|
+
className: `uidog-message uidog-message-${message.role}`,
|
|
625
|
+
children: /* @__PURE__ */ jsx2("div", { className: "uidog-message-bubble", children: message.isLoading ? /* @__PURE__ */ jsxs2("div", { className: "uidog-message-loading", children: [
|
|
626
|
+
/* @__PURE__ */ jsx2("div", { className: "uidog-spinner" }),
|
|
627
|
+
/* @__PURE__ */ jsx2("span", { children: "Processing your request..." })
|
|
628
|
+
] }) : message.error ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
629
|
+
/* @__PURE__ */ jsx2("div", { className: "uidog-message-content uidog-message-error", children: message.content }),
|
|
630
|
+
/* @__PURE__ */ jsx2(
|
|
631
|
+
"button",
|
|
632
|
+
{
|
|
633
|
+
className: "uidog-retry-btn",
|
|
634
|
+
onClick: () => handleRetry(message.id),
|
|
635
|
+
children: "Retry"
|
|
636
|
+
}
|
|
637
|
+
)
|
|
638
|
+
] }) : /* @__PURE__ */ jsx2("div", { className: "uidog-message-content", children: message.content }) })
|
|
639
|
+
},
|
|
640
|
+
message.id
|
|
641
|
+
)),
|
|
642
|
+
/* @__PURE__ */ jsx2("div", { ref: messagesEndRef })
|
|
643
|
+
] }),
|
|
644
|
+
/* @__PURE__ */ jsxs2("div", { className: "uidog-input-footer-fixed", children: [
|
|
645
|
+
/* @__PURE__ */ jsxs2("div", { className: "uidog-input-wrapper", children: [
|
|
646
|
+
/* @__PURE__ */ jsx2(
|
|
647
|
+
"textarea",
|
|
648
|
+
{
|
|
649
|
+
id: "uidog-textarea",
|
|
650
|
+
ref: textareaRef,
|
|
651
|
+
className: "uidog-textarea",
|
|
652
|
+
placeholder: "Describe the changes you want...",
|
|
653
|
+
value: userInput,
|
|
654
|
+
onChange: (e) => setUserInput(e.target.value),
|
|
655
|
+
onKeyDown: handleKeyDown,
|
|
656
|
+
disabled: isLoading
|
|
657
|
+
}
|
|
658
|
+
),
|
|
659
|
+
/* @__PURE__ */ jsx2(
|
|
660
|
+
"button",
|
|
661
|
+
{
|
|
662
|
+
className: "uidog-submit-btn",
|
|
663
|
+
onClick: handleSubmit,
|
|
664
|
+
disabled: !userInput.trim() || isLoading,
|
|
665
|
+
title: "Send message (Cmd/Ctrl + Enter)",
|
|
666
|
+
children: isLoading ? /* @__PURE__ */ jsx2("div", { className: "uidog-spinner-small" }) : /* @__PURE__ */ jsx2(
|
|
667
|
+
"svg",
|
|
668
|
+
{
|
|
669
|
+
width: "16",
|
|
670
|
+
height: "16",
|
|
671
|
+
viewBox: "0 0 16 16",
|
|
672
|
+
fill: "none",
|
|
673
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
674
|
+
children: /* @__PURE__ */ jsx2(
|
|
675
|
+
"path",
|
|
676
|
+
{
|
|
677
|
+
d: "M8 2L8 14M8 2L2 8M8 2L14 8",
|
|
678
|
+
stroke: "currentColor",
|
|
679
|
+
strokeWidth: "2",
|
|
680
|
+
strokeLinecap: "round",
|
|
681
|
+
strokeLinejoin: "round"
|
|
682
|
+
}
|
|
683
|
+
)
|
|
684
|
+
}
|
|
685
|
+
)
|
|
686
|
+
}
|
|
687
|
+
)
|
|
688
|
+
] }),
|
|
689
|
+
/* @__PURE__ */ jsx2("div", { className: "uidog-input-hint", children: "Cmd/Ctrl + Enter to submit" }),
|
|
690
|
+
sessionId && /* @__PURE__ */ jsxs2("div", { className: "uidog-send-to-dev-section", children: [
|
|
691
|
+
/* @__PURE__ */ jsx2(
|
|
692
|
+
"button",
|
|
693
|
+
{
|
|
694
|
+
className: "uidog-send-to-dev-btn",
|
|
695
|
+
onClick: handleSendToDeveloper,
|
|
696
|
+
disabled: isCreatingPR || isLoading,
|
|
697
|
+
title: "Create PR with changes",
|
|
698
|
+
children: isCreatingPR ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
699
|
+
/* @__PURE__ */ jsx2("div", { className: "uidog-spinner-small" }),
|
|
700
|
+
/* @__PURE__ */ jsx2("span", { children: "Creating PR..." })
|
|
701
|
+
] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
702
|
+
/* @__PURE__ */ jsx2(
|
|
703
|
+
"svg",
|
|
704
|
+
{
|
|
705
|
+
width: "16",
|
|
706
|
+
height: "16",
|
|
707
|
+
viewBox: "0 0 16 16",
|
|
708
|
+
fill: "none",
|
|
709
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
710
|
+
children: /* @__PURE__ */ jsx2(
|
|
711
|
+
"path",
|
|
712
|
+
{
|
|
713
|
+
d: "M8 1L8 15M8 1L1 8M8 1L15 8",
|
|
714
|
+
stroke: "currentColor",
|
|
715
|
+
strokeWidth: "2",
|
|
716
|
+
strokeLinecap: "round",
|
|
717
|
+
strokeLinejoin: "round"
|
|
718
|
+
}
|
|
719
|
+
)
|
|
720
|
+
}
|
|
721
|
+
),
|
|
722
|
+
/* @__PURE__ */ jsx2("span", { children: "Submit to Developer" })
|
|
723
|
+
] })
|
|
724
|
+
}
|
|
725
|
+
),
|
|
726
|
+
prUrl && /* @__PURE__ */ jsx2(
|
|
727
|
+
"a",
|
|
728
|
+
{
|
|
729
|
+
href: prUrl,
|
|
730
|
+
target: "_blank",
|
|
731
|
+
rel: "noopener noreferrer",
|
|
732
|
+
className: "uidog-pr-link",
|
|
733
|
+
children: "View PR \u2192"
|
|
734
|
+
}
|
|
735
|
+
)
|
|
736
|
+
] })
|
|
737
|
+
] })
|
|
738
|
+
] });
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/components/UiDogSidebarReact.tsx
|
|
742
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
743
|
+
function UiDogSidebarReact(props) {
|
|
744
|
+
useEffect2(() => {
|
|
745
|
+
const handleEscapeKey = (e) => {
|
|
746
|
+
if (e.key === "Escape") {
|
|
747
|
+
props.onClose();
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
document.addEventListener("keydown", handleEscapeKey);
|
|
751
|
+
return () => {
|
|
752
|
+
document.removeEventListener("keydown", handleEscapeKey);
|
|
753
|
+
};
|
|
754
|
+
}, [props]);
|
|
755
|
+
return /* @__PURE__ */ jsx3("div", { className: "uidog-sidebar-overlay", children: /* @__PURE__ */ jsxs3("div", { className: "uidog-sidebar", children: [
|
|
756
|
+
/* @__PURE__ */ jsx3("div", { className: "uidog-element-info-section", children: /* @__PURE__ */ jsx3(
|
|
757
|
+
ElementInfoDisplayReact,
|
|
758
|
+
{
|
|
759
|
+
elementInfo: props.elementInfo,
|
|
760
|
+
onClose: props.onClose
|
|
761
|
+
}
|
|
762
|
+
) }),
|
|
763
|
+
/* @__PURE__ */ jsx3("div", { className: "uidog-chat-container", children: /* @__PURE__ */ jsx3(
|
|
764
|
+
ConversationalInputReact,
|
|
765
|
+
{
|
|
766
|
+
elementInfo: props.elementInfo,
|
|
767
|
+
editorUrl: props.editorUrl,
|
|
768
|
+
apiEndpoint: props.apiEndpoint
|
|
769
|
+
}
|
|
770
|
+
) })
|
|
771
|
+
] }) });
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/styles/sidebarStyles.ts
|
|
775
|
+
var sidebarStyles = `/* UiDog Sidebar Styles */
|
|
776
|
+
|
|
777
|
+
/* Overlay */
|
|
778
|
+
.uidog-sidebar-overlay {
|
|
779
|
+
position: fixed;
|
|
780
|
+
top: 0;
|
|
781
|
+
right: 0;
|
|
782
|
+
bottom: 0;
|
|
783
|
+
left: 0;
|
|
784
|
+
z-index: 999999;
|
|
785
|
+
pointer-events: none;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/* Main Sidebar Container */
|
|
789
|
+
.uidog-sidebar {
|
|
790
|
+
position: fixed;
|
|
791
|
+
right: 0;
|
|
792
|
+
top: 0;
|
|
793
|
+
width: 420px;
|
|
794
|
+
max-width: 100vw;
|
|
795
|
+
height: 100vh;
|
|
796
|
+
background: #13140a;
|
|
797
|
+
box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
|
|
798
|
+
display: flex;
|
|
799
|
+
flex-direction: column;
|
|
800
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
801
|
+
font-size: 14px;
|
|
802
|
+
color: #ffffff;
|
|
803
|
+
pointer-events: auto;
|
|
804
|
+
animation: uidog-slide-in 0.3s ease-out;
|
|
805
|
+
overflow: hidden;
|
|
806
|
+
border-left: 1px solid rgba(255, 255, 255, 0.1);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
@keyframes uidog-slide-in {
|
|
810
|
+
from {
|
|
811
|
+
transform: translateX(100%);
|
|
812
|
+
}
|
|
813
|
+
to {
|
|
814
|
+
transform: translateX(0);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/* Header */
|
|
819
|
+
.uidog-sidebar-header {
|
|
820
|
+
display: flex;
|
|
821
|
+
align-items: center;
|
|
822
|
+
justify-content: flex-end;
|
|
823
|
+
padding: 20px 24px;
|
|
824
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.15);
|
|
825
|
+
background: rgba(0, 0, 0, 0.3);
|
|
826
|
+
flex-shrink: 0;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
.uidog-sidebar-title {
|
|
830
|
+
margin: 0;
|
|
831
|
+
font-size: 18px;
|
|
832
|
+
font-weight: 600;
|
|
833
|
+
color: #ffffff;
|
|
834
|
+
letter-spacing: -0.01em;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
.uidog-close-btn {
|
|
838
|
+
width: 32px;
|
|
839
|
+
height: 32px;
|
|
840
|
+
border: none;
|
|
841
|
+
background: transparent;
|
|
842
|
+
font-size: 28px;
|
|
843
|
+
line-height: 1;
|
|
844
|
+
color: rgba(255, 255, 255, 0.7);
|
|
845
|
+
cursor: pointer;
|
|
846
|
+
border-radius: 4px;
|
|
847
|
+
display: flex;
|
|
848
|
+
align-items: center;
|
|
849
|
+
justify-content: center;
|
|
850
|
+
transition: all 0.2s;
|
|
851
|
+
flex-shrink: 0;
|
|
852
|
+
margin-left: 12px;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
.uidog-close-btn:hover {
|
|
856
|
+
background: rgba(255, 255, 255, 0.1);
|
|
857
|
+
color: #ffffff;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/* Content Area */
|
|
861
|
+
.uidog-sidebar-content {
|
|
862
|
+
flex: 1;
|
|
863
|
+
overflow-y: auto;
|
|
864
|
+
overflow-x: hidden;
|
|
865
|
+
padding: 24px;
|
|
866
|
+
scrollbar-width: thin;
|
|
867
|
+
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
.uidog-sidebar-content::-webkit-scrollbar {
|
|
871
|
+
width: 8px;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
.uidog-sidebar-content::-webkit-scrollbar-track {
|
|
875
|
+
background: transparent;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
.uidog-sidebar-content::-webkit-scrollbar-thumb {
|
|
879
|
+
background: rgba(255, 255, 255, 0.2);
|
|
880
|
+
border-radius: 4px;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
.uidog-sidebar-content::-webkit-scrollbar-thumb:hover {
|
|
884
|
+
background: rgba(255, 255, 255, 0.3);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/* Element Info Section */
|
|
888
|
+
.uidog-element-info-section {
|
|
889
|
+
padding: 20px 24px;
|
|
890
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.15);
|
|
891
|
+
flex-shrink: 0;
|
|
892
|
+
background: rgba(0, 0, 0, 0.2);
|
|
893
|
+
margin-top: 0;
|
|
894
|
+
padding-top: 20px;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/* Element Info Section */
|
|
898
|
+
.uidog-element-info {
|
|
899
|
+
margin-bottom: 0;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
.uidog-element-info-header {
|
|
903
|
+
display: flex;
|
|
904
|
+
align-items: center;
|
|
905
|
+
justify-content: space-between;
|
|
906
|
+
margin-bottom: 12px;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
.uidog-element-info-title {
|
|
910
|
+
margin: 0;
|
|
911
|
+
font-size: 14px;
|
|
912
|
+
font-weight: 600;
|
|
913
|
+
color: rgba(255, 255, 255, 0.9);
|
|
914
|
+
text-transform: uppercase;
|
|
915
|
+
letter-spacing: 0.05em;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
.uidog-toggle-view-btn {
|
|
919
|
+
padding: 6px 14px;
|
|
920
|
+
font-size: 12px;
|
|
921
|
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
922
|
+
background: rgba(255, 255, 255, 0.1);
|
|
923
|
+
color: #ffffff;
|
|
924
|
+
border-radius: 6px;
|
|
925
|
+
cursor: pointer;
|
|
926
|
+
transition: all 0.2s;
|
|
927
|
+
font-weight: 500;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
.uidog-toggle-view-btn:hover {
|
|
931
|
+
background: rgba(255, 255, 255, 0.2);
|
|
932
|
+
border-color: rgba(255, 255, 255, 0.3);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
.uidog-element-info-content {
|
|
936
|
+
background: rgba(0, 0, 0, 0.3);
|
|
937
|
+
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
938
|
+
border-radius: 8px;
|
|
939
|
+
padding: 16px;
|
|
940
|
+
display: flex;
|
|
941
|
+
align-items: center;
|
|
942
|
+
justify-content: space-between;
|
|
943
|
+
position: relative;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
.uidog-file-location {
|
|
947
|
+
font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
|
|
948
|
+
font-size: 13px;
|
|
949
|
+
color: #ffffff;
|
|
950
|
+
word-break: break-word;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
.uidog-info-row {
|
|
954
|
+
display: flex;
|
|
955
|
+
margin-bottom: 12px;
|
|
956
|
+
line-height: 1.6;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
.uidog-info-row:last-of-type {
|
|
960
|
+
margin-bottom: 0;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
.uidog-info-row:last-child {
|
|
964
|
+
margin-bottom: 0;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
.uidog-info-label {
|
|
968
|
+
flex-shrink: 0;
|
|
969
|
+
width: 100px;
|
|
970
|
+
font-weight: 500;
|
|
971
|
+
color: rgba(255, 255, 255, 0.75);
|
|
972
|
+
font-size: 13px;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
.uidog-info-value {
|
|
976
|
+
flex: 1;
|
|
977
|
+
color: #ffffff;
|
|
978
|
+
word-break: break-word;
|
|
979
|
+
font-size: 13px;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
.uidog-component-name {
|
|
983
|
+
font-weight: 600;
|
|
984
|
+
color: #60a5fa;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
.uidog-file-path {
|
|
988
|
+
font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
|
|
989
|
+
font-size: 12px;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
.uidog-dom-snapshot {
|
|
993
|
+
margin-top: 16px;
|
|
994
|
+
background: rgba(255, 255, 255, 0.03);
|
|
995
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
996
|
+
border-radius: 8px;
|
|
997
|
+
padding: 12px;
|
|
998
|
+
display: flex;
|
|
999
|
+
flex-direction: column;
|
|
1000
|
+
gap: 8px;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
.uidog-dom-label {
|
|
1004
|
+
color: rgba(255, 255, 255, 0.7);
|
|
1005
|
+
font-size: 12px;
|
|
1006
|
+
text-transform: uppercase;
|
|
1007
|
+
letter-spacing: 0.05em;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
.uidog-dom-snippet {
|
|
1011
|
+
margin: 0;
|
|
1012
|
+
background: rgba(0, 0, 0, 0.4);
|
|
1013
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
1014
|
+
border-radius: 6px;
|
|
1015
|
+
padding: 10px;
|
|
1016
|
+
color: rgba(255, 255, 255, 0.85);
|
|
1017
|
+
font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
|
|
1018
|
+
font-size: 12px;
|
|
1019
|
+
white-space: pre-wrap;
|
|
1020
|
+
word-break: break-word;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
.uidog-dom-attributes ul {
|
|
1024
|
+
margin: 6px 0 0 0;
|
|
1025
|
+
padding-left: 16px;
|
|
1026
|
+
color: rgba(255, 255, 255, 0.85);
|
|
1027
|
+
font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
|
|
1028
|
+
font-size: 12px;
|
|
1029
|
+
word-break: break-word;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
.uidog-dom-attributes code {
|
|
1033
|
+
background: rgba(255, 255, 255, 0.08);
|
|
1034
|
+
padding: 2px 4px;
|
|
1035
|
+
border-radius: 4px;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
.uidog-dom-hint {
|
|
1039
|
+
color: rgba(255, 255, 255, 0.6);
|
|
1040
|
+
font-size: 12px;
|
|
1041
|
+
line-height: 1.5;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
.uidog-mono {
|
|
1045
|
+
font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
|
|
1046
|
+
font-size: 12px;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
.uidog-detailed-section {
|
|
1050
|
+
margin-top: 12px;
|
|
1051
|
+
padding-top: 12px;
|
|
1052
|
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
.uidog-code-preview {
|
|
1056
|
+
flex-direction: column;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
.uidog-code-placeholder {
|
|
1060
|
+
margin-top: 6px;
|
|
1061
|
+
padding: 8px;
|
|
1062
|
+
background: rgba(0, 0, 0, 0.3);
|
|
1063
|
+
color: rgba(255, 255, 255, 0.8);
|
|
1064
|
+
border-radius: 4px;
|
|
1065
|
+
font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
|
|
1066
|
+
font-size: 12px;
|
|
1067
|
+
white-space: pre-wrap;
|
|
1068
|
+
word-break: break-word;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
/* Chat Container */
|
|
1072
|
+
.uidog-chat-container {
|
|
1073
|
+
flex: 1;
|
|
1074
|
+
display: flex;
|
|
1075
|
+
flex-direction: column;
|
|
1076
|
+
overflow: hidden;
|
|
1077
|
+
min-height: 0;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/* Messages Container */
|
|
1081
|
+
.uidog-messages-container {
|
|
1082
|
+
flex: 1;
|
|
1083
|
+
overflow-y: auto;
|
|
1084
|
+
overflow-x: hidden;
|
|
1085
|
+
padding: 20px 24px;
|
|
1086
|
+
scrollbar-width: thin;
|
|
1087
|
+
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
.uidog-dom-banner {
|
|
1091
|
+
margin-bottom: 12px;
|
|
1092
|
+
padding: 12px 14px;
|
|
1093
|
+
background: rgba(255, 255, 255, 0.08);
|
|
1094
|
+
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
1095
|
+
border-radius: 8px;
|
|
1096
|
+
color: rgba(255, 255, 255, 0.85);
|
|
1097
|
+
font-size: 13px;
|
|
1098
|
+
line-height: 1.5;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
.uidog-messages-container::-webkit-scrollbar {
|
|
1102
|
+
width: 8px;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
.uidog-messages-container::-webkit-scrollbar-track {
|
|
1106
|
+
background: transparent;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
.uidog-messages-container::-webkit-scrollbar-thumb {
|
|
1110
|
+
background: rgba(255, 255, 255, 0.2);
|
|
1111
|
+
border-radius: 4px;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
.uidog-messages-container::-webkit-scrollbar-thumb:hover {
|
|
1115
|
+
background: rgba(255, 255, 255, 0.3);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/* Empty State */
|
|
1119
|
+
.uidog-empty-state {
|
|
1120
|
+
display: flex;
|
|
1121
|
+
align-items: center;
|
|
1122
|
+
justify-content: center;
|
|
1123
|
+
height: 100%;
|
|
1124
|
+
min-height: 200px;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
.uidog-empty-state-text {
|
|
1128
|
+
color: rgba(255, 255, 255, 0.6);
|
|
1129
|
+
font-size: 14px;
|
|
1130
|
+
text-align: center;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/* Messages */
|
|
1134
|
+
.uidog-message {
|
|
1135
|
+
margin-bottom: 16px;
|
|
1136
|
+
display: flex;
|
|
1137
|
+
animation: uidog-message-fade-in 0.2s ease-out;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
@keyframes uidog-message-fade-in {
|
|
1141
|
+
from {
|
|
1142
|
+
opacity: 0;
|
|
1143
|
+
transform: translateY(4px);
|
|
1144
|
+
}
|
|
1145
|
+
to {
|
|
1146
|
+
opacity: 1;
|
|
1147
|
+
transform: translateY(0);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
.uidog-message-user {
|
|
1152
|
+
justify-content: flex-end;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
.uidog-message-assistant {
|
|
1156
|
+
justify-content: flex-start;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/* Message Bubbles */
|
|
1160
|
+
.uidog-message-bubble {
|
|
1161
|
+
max-width: 80%;
|
|
1162
|
+
padding: 12px 16px;
|
|
1163
|
+
border-radius: 12px;
|
|
1164
|
+
word-wrap: break-word;
|
|
1165
|
+
overflow-wrap: break-word;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
.uidog-message-user .uidog-message-bubble {
|
|
1169
|
+
background: rgba(59, 130, 246, 0.2);
|
|
1170
|
+
border: 1px solid rgba(59, 130, 246, 0.3);
|
|
1171
|
+
color: #93c5fd;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
.uidog-message-assistant .uidog-message-bubble {
|
|
1175
|
+
background: rgba(255, 255, 255, 0.08);
|
|
1176
|
+
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
1177
|
+
color: rgba(255, 255, 255, 0.9);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
.uidog-message-content {
|
|
1181
|
+
line-height: 1.6;
|
|
1182
|
+
white-space: pre-wrap;
|
|
1183
|
+
word-break: break-word;
|
|
1184
|
+
font-size: 14px;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
.uidog-message-content.uidog-message-error {
|
|
1188
|
+
color: #fca5a5;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
/* Loading Message */
|
|
1192
|
+
.uidog-message-loading {
|
|
1193
|
+
display: flex;
|
|
1194
|
+
align-items: center;
|
|
1195
|
+
gap: 10px;
|
|
1196
|
+
color: rgba(255, 255, 255, 0.7);
|
|
1197
|
+
font-size: 14px;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
.uidog-spinner {
|
|
1201
|
+
width: 16px;
|
|
1202
|
+
height: 16px;
|
|
1203
|
+
border: 2px solid rgba(255, 255, 255, 0.2);
|
|
1204
|
+
border-top-color: rgba(255, 255, 255, 0.8);
|
|
1205
|
+
border-radius: 50%;
|
|
1206
|
+
animation: uidog-spin 0.8s linear infinite;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
.uidog-spinner-small {
|
|
1210
|
+
width: 14px;
|
|
1211
|
+
height: 14px;
|
|
1212
|
+
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
1213
|
+
border-top-color: #ffffff;
|
|
1214
|
+
border-radius: 50%;
|
|
1215
|
+
animation: uidog-spin 0.8s linear infinite;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
@keyframes uidog-spin {
|
|
1219
|
+
to {
|
|
1220
|
+
transform: rotate(360deg);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/* Fixed Input Footer */
|
|
1225
|
+
.uidog-input-footer-fixed {
|
|
1226
|
+
flex-shrink: 0;
|
|
1227
|
+
padding: 16px 24px;
|
|
1228
|
+
border-top: 1px solid rgba(255, 255, 255, 0.15);
|
|
1229
|
+
background: rgba(0, 0, 0, 0.3);
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
.uidog-input-wrapper {
|
|
1233
|
+
position: relative;
|
|
1234
|
+
margin-bottom: 8px;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
.uidog-textarea {
|
|
1238
|
+
width: 100%;
|
|
1239
|
+
padding: 10px 60px 10px 14px;
|
|
1240
|
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
1241
|
+
border-radius: 8px;
|
|
1242
|
+
font-family: inherit;
|
|
1243
|
+
font-size: 14px;
|
|
1244
|
+
line-height: 1.5;
|
|
1245
|
+
resize: none;
|
|
1246
|
+
min-height: 44px;
|
|
1247
|
+
max-height: 200px;
|
|
1248
|
+
background: rgba(0, 0, 0, 0.4);
|
|
1249
|
+
color: #ffffff;
|
|
1250
|
+
transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
|
|
1251
|
+
box-sizing: border-box;
|
|
1252
|
+
overflow-wrap: break-word;
|
|
1253
|
+
word-wrap: break-word;
|
|
1254
|
+
overflow-y: auto;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
.uidog-textarea::placeholder {
|
|
1258
|
+
color: rgba(255, 255, 255, 0.5);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
.uidog-textarea:focus {
|
|
1262
|
+
outline: none;
|
|
1263
|
+
border-color: #60a5fa;
|
|
1264
|
+
background: rgba(0, 0, 0, 0.5);
|
|
1265
|
+
box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
.uidog-textarea:disabled {
|
|
1269
|
+
background: rgba(0, 0, 0, 0.2);
|
|
1270
|
+
color: rgba(255, 255, 255, 0.5);
|
|
1271
|
+
cursor: not-allowed;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
.uidog-submit-btn {
|
|
1275
|
+
position: absolute;
|
|
1276
|
+
bottom: 10px;
|
|
1277
|
+
right: 6px;
|
|
1278
|
+
width: 32px;
|
|
1279
|
+
height: 32px;
|
|
1280
|
+
display: flex;
|
|
1281
|
+
align-items: center;
|
|
1282
|
+
justify-content: center;
|
|
1283
|
+
padding: 0;
|
|
1284
|
+
font-size: 14px;
|
|
1285
|
+
font-weight: 500;
|
|
1286
|
+
color: #ffffff;
|
|
1287
|
+
background: #3b82f6;
|
|
1288
|
+
border: none;
|
|
1289
|
+
border-radius: 6px;
|
|
1290
|
+
cursor: pointer;
|
|
1291
|
+
transition: all 0.2s;
|
|
1292
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
.uidog-submit-btn:active {
|
|
1296
|
+
transform: translateY(1px);
|
|
1297
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
.uidog-submit-btn:hover:not(:disabled) {
|
|
1301
|
+
background: #2563eb;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
.uidog-submit-btn:disabled {
|
|
1305
|
+
background: rgba(255, 255, 255, 0.1);
|
|
1306
|
+
color: rgba(255, 255, 255, 0.3);
|
|
1307
|
+
cursor: not-allowed;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
.uidog-submit-btn svg {
|
|
1311
|
+
stroke: currentColor;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
.uidog-input-hint {
|
|
1315
|
+
font-size: 11px;
|
|
1316
|
+
color: rgba(255, 255, 255, 0.5);
|
|
1317
|
+
text-align: center;
|
|
1318
|
+
margin-top: 4px;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
.uidog-retry-btn {
|
|
1322
|
+
margin-top: 8px;
|
|
1323
|
+
padding: 6px 12px;
|
|
1324
|
+
font-size: 12px;
|
|
1325
|
+
font-weight: 500;
|
|
1326
|
+
color: #ffffff;
|
|
1327
|
+
background: #ef4444;
|
|
1328
|
+
border: none;
|
|
1329
|
+
border-radius: 6px;
|
|
1330
|
+
cursor: pointer;
|
|
1331
|
+
transition: background 0.2s;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
.uidog-retry-btn:hover {
|
|
1335
|
+
background: #dc2626;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/* Footer */
|
|
1339
|
+
.uidog-sidebar-footer {
|
|
1340
|
+
padding: 16px 24px;
|
|
1341
|
+
border-top: 1px solid rgba(255, 255, 255, 0.15);
|
|
1342
|
+
background: rgba(0, 0, 0, 0.3);
|
|
1343
|
+
text-align: center;
|
|
1344
|
+
flex-shrink: 0;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
.uidog-footer-text {
|
|
1348
|
+
font-size: 12px;
|
|
1349
|
+
color: rgba(255, 255, 255, 0.7);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
.uidog-footer-link {
|
|
1353
|
+
color: #60a5fa;
|
|
1354
|
+
text-decoration: none;
|
|
1355
|
+
font-weight: 500;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
.uidog-footer-link:hover {
|
|
1359
|
+
text-decoration: underline;
|
|
1360
|
+
color: #93c5fd;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/* Mobile Responsive */
|
|
1364
|
+
@media (max-width: 768px) {
|
|
1365
|
+
.uidog-sidebar {
|
|
1366
|
+
width: 100vw;
|
|
1367
|
+
}
|
|
1368
|
+
}`;
|
|
1369
|
+
var sidebarStyles_default = sidebarStyles;
|
|
1370
|
+
|
|
1371
|
+
// src/sidebar-initializer.ts
|
|
1372
|
+
var sidebarRoot = null;
|
|
1373
|
+
var sidebarContainer = null;
|
|
1374
|
+
var shadowRoot = null;
|
|
1375
|
+
var config = { apiEndpoint: "https://api.ui.dog" };
|
|
1376
|
+
var currentState = {
|
|
1377
|
+
isOpen: false,
|
|
1378
|
+
elementInfo: null,
|
|
1379
|
+
editorUrl: ""
|
|
1380
|
+
};
|
|
1381
|
+
function initializeSidebar(sidebarConfig) {
|
|
1382
|
+
if (typeof window === "undefined")
|
|
1383
|
+
return;
|
|
1384
|
+
config = sidebarConfig;
|
|
1385
|
+
if (document.getElementById("uidog-next-sidebar-root")) {
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
sidebarContainer = document.createElement("div");
|
|
1389
|
+
sidebarContainer.id = "uidog-next-sidebar-root";
|
|
1390
|
+
document.body.appendChild(sidebarContainer);
|
|
1391
|
+
shadowRoot = sidebarContainer.attachShadow({ mode: "open" });
|
|
1392
|
+
const styleElement = document.createElement("style");
|
|
1393
|
+
styleElement.textContent = sidebarStyles_default;
|
|
1394
|
+
shadowRoot.appendChild(styleElement);
|
|
1395
|
+
const mountPoint = document.createElement("div");
|
|
1396
|
+
mountPoint.id = "uidog-sidebar-mount";
|
|
1397
|
+
shadowRoot.appendChild(mountPoint);
|
|
1398
|
+
sidebarRoot = createRoot(mountPoint);
|
|
1399
|
+
render();
|
|
1400
|
+
}
|
|
1401
|
+
function render() {
|
|
1402
|
+
if (!sidebarRoot)
|
|
1403
|
+
return;
|
|
1404
|
+
const { isOpen, elementInfo, editorUrl } = currentState;
|
|
1405
|
+
if (!isOpen || !elementInfo) {
|
|
1406
|
+
sidebarRoot.render(null);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
sidebarRoot.render(
|
|
1410
|
+
createElement(UiDogSidebarReact, {
|
|
1411
|
+
elementInfo,
|
|
1412
|
+
editorUrl,
|
|
1413
|
+
onClose: closeSidebar,
|
|
1414
|
+
apiEndpoint: config.apiEndpoint
|
|
1415
|
+
})
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
function openSidebar(elementInfo, editorUrl) {
|
|
1419
|
+
currentState = {
|
|
1420
|
+
isOpen: true,
|
|
1421
|
+
elementInfo,
|
|
1422
|
+
editorUrl
|
|
1423
|
+
};
|
|
1424
|
+
if (typeof window !== "undefined") {
|
|
1425
|
+
window.__UIDOG_SIDEBAR__ = {
|
|
1426
|
+
isOpen: true,
|
|
1427
|
+
elementInfo,
|
|
1428
|
+
editorUrl
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
render();
|
|
1432
|
+
}
|
|
1433
|
+
function closeSidebar() {
|
|
1434
|
+
currentState = {
|
|
1435
|
+
isOpen: false,
|
|
1436
|
+
elementInfo: null,
|
|
1437
|
+
editorUrl: ""
|
|
1438
|
+
};
|
|
1439
|
+
if (typeof window !== "undefined") {
|
|
1440
|
+
window.__UIDOG_SIDEBAR__ = {
|
|
1441
|
+
isOpen: false,
|
|
1442
|
+
elementInfo: null,
|
|
1443
|
+
editorUrl: null
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
render();
|
|
1447
|
+
}
|
|
1448
|
+
function cleanupSidebar() {
|
|
1449
|
+
if (sidebarRoot) {
|
|
1450
|
+
sidebarRoot.unmount();
|
|
1451
|
+
sidebarRoot = null;
|
|
1452
|
+
}
|
|
1453
|
+
if (sidebarContainer && sidebarContainer.parentNode) {
|
|
1454
|
+
sidebarContainer.parentNode.removeChild(sidebarContainer);
|
|
1455
|
+
sidebarContainer = null;
|
|
1456
|
+
}
|
|
1457
|
+
shadowRoot = null;
|
|
1458
|
+
currentState = {
|
|
1459
|
+
isOpen: false,
|
|
1460
|
+
elementInfo: null,
|
|
1461
|
+
editorUrl: ""
|
|
1462
|
+
};
|
|
1463
|
+
if (typeof window !== "undefined") {
|
|
1464
|
+
delete window.__UIDOG_SIDEBAR__;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
// src/index.ts
|
|
1469
|
+
var isInitialized = false;
|
|
1470
|
+
function initializeUiDogNext(options = {}) {
|
|
1471
|
+
if (typeof window === "undefined")
|
|
1472
|
+
return;
|
|
1473
|
+
if (isInitialized) {
|
|
1474
|
+
console.warn("[UiDog Next] Already initialized");
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
if (process.env.NODE_ENV === "production") {
|
|
1478
|
+
console.warn(
|
|
1479
|
+
"[UiDog Next] Running in production mode. Element source detection may not work as _debugSource is stripped in production builds."
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
const {
|
|
1483
|
+
editor = "cursor",
|
|
1484
|
+
projectPath = "",
|
|
1485
|
+
modifier = "alt",
|
|
1486
|
+
enableSidebar = true,
|
|
1487
|
+
apiEndpoint = "https://api.ui.dog"
|
|
1488
|
+
} = options;
|
|
1489
|
+
isInitialized = true;
|
|
1490
|
+
window.__UIDOG_NEXT_INITIALIZED__ = true;
|
|
1491
|
+
setupBippyInstrumentation();
|
|
1492
|
+
if (enableSidebar) {
|
|
1493
|
+
initializeSidebar({ apiEndpoint });
|
|
1494
|
+
}
|
|
1495
|
+
setupElementDetector({
|
|
1496
|
+
modifier,
|
|
1497
|
+
onElementSelected: (source, element) => {
|
|
1498
|
+
const rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null;
|
|
1499
|
+
const buildDomSnapshot = () => {
|
|
1500
|
+
const outerHTML = element.outerHTML || "";
|
|
1501
|
+
const text = (element.textContent || "").trim();
|
|
1502
|
+
const attributes = {};
|
|
1503
|
+
Array.from(element.attributes || []).forEach((attr) => {
|
|
1504
|
+
attributes[attr.name] = attr.value;
|
|
1505
|
+
});
|
|
1506
|
+
return {
|
|
1507
|
+
outerHTML: outerHTML.length > 4e3 ? `${outerHTML.slice(0, 4e3)}\u2026` : outerHTML,
|
|
1508
|
+
text: text.length > 1e3 ? `${text.slice(0, 1e3)}\u2026` : text,
|
|
1509
|
+
attributes
|
|
1510
|
+
};
|
|
1511
|
+
};
|
|
1512
|
+
if (source) {
|
|
1513
|
+
const editorUrl = buildEditorUrl(source, editor, projectPath);
|
|
1514
|
+
console.info(
|
|
1515
|
+
"[UiDog Next] Source detected:",
|
|
1516
|
+
normalizeFileName(source.fileName),
|
|
1517
|
+
"line",
|
|
1518
|
+
source.lineNumber,
|
|
1519
|
+
"column",
|
|
1520
|
+
source.columnNumber
|
|
1521
|
+
);
|
|
1522
|
+
if (enableSidebar) {
|
|
1523
|
+
const elementInfo = {
|
|
1524
|
+
kind: "source",
|
|
1525
|
+
componentName: source.functionName || "Unknown",
|
|
1526
|
+
filePath: normalizeFileName(source.fileName),
|
|
1527
|
+
line: source.lineNumber,
|
|
1528
|
+
column: source.columnNumber,
|
|
1529
|
+
box: rect ? {
|
|
1530
|
+
x: rect.x,
|
|
1531
|
+
y: rect.y,
|
|
1532
|
+
width: rect.width,
|
|
1533
|
+
height: rect.height
|
|
1534
|
+
} : void 0
|
|
1535
|
+
};
|
|
1536
|
+
openSidebar(elementInfo, editorUrl);
|
|
1537
|
+
} else {
|
|
1538
|
+
console.log("[UiDog Next] Element selected:");
|
|
1539
|
+
console.log(" Component:", source.functionName || "Unknown");
|
|
1540
|
+
console.log(" File:", source.fileName);
|
|
1541
|
+
console.log(" Line:", source.lineNumber);
|
|
1542
|
+
console.log(" Column:", source.columnNumber);
|
|
1543
|
+
console.log(" Editor URL:", editorUrl);
|
|
1544
|
+
}
|
|
1545
|
+
} else {
|
|
1546
|
+
const domSnapshot = buildDomSnapshot();
|
|
1547
|
+
console.info("[UiDog Next] DOM snapshot (no source):", {
|
|
1548
|
+
outerHTML: domSnapshot.outerHTML,
|
|
1549
|
+
text: domSnapshot.text,
|
|
1550
|
+
attributes: domSnapshot.attributes,
|
|
1551
|
+
box: rect ? {
|
|
1552
|
+
x: rect.x,
|
|
1553
|
+
y: rect.y,
|
|
1554
|
+
width: rect.width,
|
|
1555
|
+
height: rect.height
|
|
1556
|
+
} : void 0
|
|
1557
|
+
});
|
|
1558
|
+
const elementInfo = {
|
|
1559
|
+
kind: "dom",
|
|
1560
|
+
componentName: "Server-rendered element",
|
|
1561
|
+
domSnapshot,
|
|
1562
|
+
box: rect ? {
|
|
1563
|
+
x: rect.x,
|
|
1564
|
+
y: rect.y,
|
|
1565
|
+
width: rect.width,
|
|
1566
|
+
height: rect.height
|
|
1567
|
+
} : void 0
|
|
1568
|
+
};
|
|
1569
|
+
if (enableSidebar) {
|
|
1570
|
+
openSidebar(elementInfo, "");
|
|
1571
|
+
} else {
|
|
1572
|
+
console.log("[UiDog Next] Element selected (DOM snapshot):");
|
|
1573
|
+
console.log(" outerHTML:", domSnapshot.outerHTML);
|
|
1574
|
+
console.log(" text:", domSnapshot.text);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
console.log(
|
|
1580
|
+
`[UiDog Next] Initialized (${modifier}+click to select elements)`
|
|
1581
|
+
);
|
|
1582
|
+
}
|
|
1583
|
+
function cleanupUiDogNext() {
|
|
1584
|
+
cleanupElementDetector();
|
|
1585
|
+
cleanupSidebar();
|
|
1586
|
+
isInitialized = false;
|
|
1587
|
+
if (typeof window !== "undefined") {
|
|
1588
|
+
window.__UIDOG_NEXT_INITIALIZED__ = false;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
function isUiDogNextInitialized() {
|
|
1592
|
+
return isInitialized;
|
|
1593
|
+
}
|
|
1594
|
+
export {
|
|
1595
|
+
buildEditorUrl,
|
|
1596
|
+
cleanupUiDogNext,
|
|
1597
|
+
closeSidebar,
|
|
1598
|
+
getComponentNameFromFiber,
|
|
1599
|
+
getShortFileName,
|
|
1600
|
+
getSourceFromElement,
|
|
1601
|
+
initializeUiDogNext,
|
|
1602
|
+
isUiDogNextInitialized,
|
|
1603
|
+
normalizeFileName,
|
|
1604
|
+
openSidebar,
|
|
1605
|
+
setupBippyInstrumentation
|
|
1606
|
+
};
|