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