@ibealec/create-zed-bridge 1.0.5 → 1.0.6
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/package.json +1 -1
- package/templates/@zed-controller/react-bridge/dist/index.cjs +26 -9
- package/templates/@zed-controller/react-bridge/dist/index.cjs.map +1 -1
- package/templates/@zed-controller/react-bridge/dist/index.js +26 -9
- package/templates/@zed-controller/react-bridge/dist/index.js.map +1 -1
|
@@ -165,7 +165,7 @@ function captureContext(element) {
|
|
|
165
165
|
selectedText: getSelectedText(),
|
|
166
166
|
selectedElement: {
|
|
167
167
|
tagName: element.tagName.toLowerCase(),
|
|
168
|
-
className: element
|
|
168
|
+
className: getClassNameString(element),
|
|
169
169
|
id: element.id || void 0,
|
|
170
170
|
innerText: truncateText(element.innerText, 200)
|
|
171
171
|
},
|
|
@@ -187,12 +187,22 @@ function getSelectedText() {
|
|
|
187
187
|
return void 0;
|
|
188
188
|
}
|
|
189
189
|
function truncateText(text, maxLength) {
|
|
190
|
+
if (!text) return "";
|
|
190
191
|
const cleaned = text.replace(/\s+/g, " ").trim();
|
|
191
192
|
if (cleaned.length <= maxLength) {
|
|
192
193
|
return cleaned;
|
|
193
194
|
}
|
|
194
195
|
return cleaned.slice(0, maxLength) + "...";
|
|
195
196
|
}
|
|
197
|
+
function getClassNameString(element) {
|
|
198
|
+
if (typeof element.className === "string") {
|
|
199
|
+
return element.className;
|
|
200
|
+
}
|
|
201
|
+
if (element.className && typeof element.className.baseVal === "string") {
|
|
202
|
+
return element.className.baseVal;
|
|
203
|
+
}
|
|
204
|
+
return "";
|
|
205
|
+
}
|
|
196
206
|
function getSourceFile(element) {
|
|
197
207
|
let current = element;
|
|
198
208
|
while (current) {
|
|
@@ -295,10 +305,13 @@ function getDomPath(element) {
|
|
|
295
305
|
let selector = current.tagName.toLowerCase();
|
|
296
306
|
if (current.id) {
|
|
297
307
|
selector += `#${current.id}`;
|
|
298
|
-
} else
|
|
299
|
-
const
|
|
300
|
-
if (
|
|
301
|
-
|
|
308
|
+
} else {
|
|
309
|
+
const classNameStr = getClassNameString(current);
|
|
310
|
+
if (classNameStr) {
|
|
311
|
+
const classes = classNameStr.split(/\s+/).filter((c) => c && !c.startsWith("__")).slice(0, 2).join(".");
|
|
312
|
+
if (classes) {
|
|
313
|
+
selector += `.${classes}`;
|
|
314
|
+
}
|
|
302
315
|
}
|
|
303
316
|
}
|
|
304
317
|
path.unshift(selector);
|
|
@@ -475,10 +488,14 @@ function createHighlightOverlay() {
|
|
|
475
488
|
let labelText = element.tagName.toLowerCase();
|
|
476
489
|
if (element.id) {
|
|
477
490
|
labelText += `#${element.id}`;
|
|
478
|
-
} else
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
491
|
+
} else {
|
|
492
|
+
const className = element.className;
|
|
493
|
+
const classNameStr = typeof className === "string" ? className : className?.baseVal || "";
|
|
494
|
+
if (classNameStr) {
|
|
495
|
+
const firstClass = classNameStr.split(/\s+/)[0];
|
|
496
|
+
if (firstClass && !firstClass.startsWith("__")) {
|
|
497
|
+
labelText += `.${firstClass}`;
|
|
498
|
+
}
|
|
482
499
|
}
|
|
483
500
|
}
|
|
484
501
|
label.textContent = labelText;
|