@stagewise-plugins/react
Version:
> [!CAUTION] > This package is deprecated. > > There thus will be no further support or assistance with this version. > > Follow the guide in [the stagewise documentation](https://stagewise.io) to upgrade.
89 lines (87 loc) • 2.88 kB
JavaScript
import { jsxs as l, jsx as a } from "react/jsx-runtime";
function u() {
return /* @__PURE__ */ l(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
viewBox: "-11.5 -10.23174 23 20.46348",
children: [
/* @__PURE__ */ a("title", { children: "React Logo" }),
/* @__PURE__ */ a("circle", { cx: "0", cy: "0", r: "2.05", fill: "currentColor" }),
/* @__PURE__ */ l("g", { stroke: "currentColor", strokeWidth: "1", fill: "none", children: [
/* @__PURE__ */ a("ellipse", { rx: "11", ry: "4.2" }),
/* @__PURE__ */ a("ellipse", { rx: "11", ry: "4.2", transform: "rotate(60)" }),
/* @__PURE__ */ a("ellipse", { rx: "11", ry: "4.2", transform: "rotate(120)" })
] })
]
}
);
}
const d = 0, f = 1, g = 5;
function h(o) {
return p(o.ownProperties);
}
function p(o) {
if (!o)
return null;
const e = [], r = 3, s = Object.keys(o).find(
(n) => n.startsWith("__reactFiber$") || n.startsWith("__reactInternalInstance$")
);
if (!s)
return null;
let t = o[s];
if (!t)
return null;
for (; t && e.length < r; ) {
let n = null;
if (t.tag === f || t.tag === d) {
const i = t.type;
i && (n = { name: i.displayName || i.name || t._debugOwner?.name || // Check direct name on fiber
"AnonymousComponent", type: "regular" });
} else t.tag === g && t._debugOwner && t._debugOwner.env?.toLowerCase().includes("server") && (n = { name: t._debugOwner.name, type: "rsc" });
n && (e.some(
(c) => c.name === n.name && c.type === n.type
) || e.push(n)), t = t.return;
}
return e.length > 0 ? e : null;
}
function m(o) {
const e = p(o);
return e?.[0] ? {
annotation: `${e[0].name}${e[0].type === "rsc" ? " (RSC)" : ""}`
} : { annotation: null };
}
function y(o) {
const e = o.map(
(r) => h(r)
);
return e.some((r) => r && r.length > 0) ? `This is additional information on the elements that the user selected. Use this information to find the correct element in the codebase.
${e.map((s, t) => `
<element index="${t + 1}">
${s.length === 0 ? "No React component as parent detected" : `React component tree (from closest to farthest, 3 closest elements): ${s.map((n) => `{name: ${n.name}, type: ${n.type}}`).join(" child of ")}`}
</element>
`)}
` : null;
}
const C = {
displayName: "React",
description: "This plugin adds additional information and metadata for apps using React as a UI framework",
iconSvg: /* @__PURE__ */ a(u, {}),
pluginName: "react",
onContextElementHover: m,
onContextElementSelect: m,
onPromptSend: (o) => {
const e = y(o.metadata.selectedElements);
return e ? {
contextSnippets: [
{
promptContextName: "elements-react-component-info",
content: e
}
]
} : { contextSnippets: [] };
}
};
export {
C as default
};