@githumbi/grabby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +22 -0
- package/README.md +262 -0
- package/builders.json +14 -0
- package/dist/angular/index.d.ts +279 -0
- package/dist/angular/index.js +5145 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/babel-plugin/index.cjs +95 -0
- package/dist/babel-plugin/index.cjs.map +1 -0
- package/dist/babel-plugin/index.d.cts +28 -0
- package/dist/babel-plugin/index.d.ts +28 -0
- package/dist/babel-plugin/index.js +60 -0
- package/dist/babel-plugin/index.js.map +1 -0
- package/dist/builder/builders/application/index.js +141 -0
- package/dist/builder/builders/application/index.js.map +1 -0
- package/dist/builder/builders/application/schema.json +7 -0
- package/dist/builder/builders/dev-server/index.js +137 -0
- package/dist/builder/builders/dev-server/index.js.map +1 -0
- package/dist/builder/builders/dev-server/schema.json +26 -0
- package/dist/builder/index.js +2 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/package.json +1 -0
- package/dist/chunk-6CBIOKZV.cjs +45 -0
- package/dist/chunk-6CBIOKZV.cjs.map +1 -0
- package/dist/chunk-M3DOFJA7.js +45 -0
- package/dist/chunk-M3DOFJA7.js.map +1 -0
- package/dist/cli/index.js +406 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/index.cjs +5081 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +96 -0
- package/dist/core/index.d.ts +96 -0
- package/dist/core/index.js +5081 -0
- package/dist/core/index.js.map +1 -0
- package/dist/esbuild-plugin/index.cjs +134 -0
- package/dist/esbuild-plugin/index.cjs.map +1 -0
- package/dist/esbuild-plugin/index.d.cts +21 -0
- package/dist/esbuild-plugin/index.d.ts +21 -0
- package/dist/esbuild-plugin/index.js +96 -0
- package/dist/esbuild-plugin/index.js.map +1 -0
- package/dist/export/index.cjs +166 -0
- package/dist/export/index.cjs.map +1 -0
- package/dist/export/index.d.cts +86 -0
- package/dist/export/index.d.ts +86 -0
- package/dist/export/index.js +137 -0
- package/dist/export/index.js.map +1 -0
- package/dist/grabby.global.js +635 -0
- package/dist/live/index.cjs +30 -0
- package/dist/live/index.cjs.map +1 -0
- package/dist/live/index.d.cts +20 -0
- package/dist/live/index.d.ts +20 -0
- package/dist/live/index.js +30 -0
- package/dist/live/index.js.map +1 -0
- package/dist/loader.global.js +1 -0
- package/dist/plugin/index.cjs +229 -0
- package/dist/plugin/index.cjs.map +1 -0
- package/dist/plugin/index.d.cts +76 -0
- package/dist/plugin/index.d.ts +76 -0
- package/dist/plugin/index.js +186 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/react/index.d.ts +290 -0
- package/dist/react/index.js +5110 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-CMgpkvBz.d.cts +265 -0
- package/dist/types-CMgpkvBz.d.ts +265 -0
- package/package.json +191 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/plugin/index.ts
|
|
2
|
+
import path2 from "path";
|
|
3
|
+
import { createUnplugin } from "unplugin";
|
|
4
|
+
|
|
5
|
+
// src/babel-plugin/index.ts
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
// src/core/adapters/stamp.ts
|
|
9
|
+
var SOURCE_ATTRIBUTE = "data-grabby-loc";
|
|
10
|
+
|
|
11
|
+
// src/babel-plugin/index.ts
|
|
12
|
+
var SKIP = /* @__PURE__ */ new Set(["Fragment", "StrictMode", "Suspense", "SuspenseList", "Profiler"]);
|
|
13
|
+
function grabbyBabelPlugin(options = {}) {
|
|
14
|
+
const attribute = options.attribute ?? SOURCE_ATTRIBUTE;
|
|
15
|
+
const rootDir = options.rootDir ?? process.cwd();
|
|
16
|
+
return function grabbyReactSource({ types: t }) {
|
|
17
|
+
return {
|
|
18
|
+
name: "grabby-react-source",
|
|
19
|
+
visitor: {
|
|
20
|
+
JSXOpeningElement(nodePath, state) {
|
|
21
|
+
const filename = state.filename ?? state.file?.opts?.filename;
|
|
22
|
+
if (!filename || filename.includes("node_modules")) return;
|
|
23
|
+
const node = nodePath.node;
|
|
24
|
+
if (node.name?.type === "JSXNamespacedName") return;
|
|
25
|
+
const name = elementName(node.name);
|
|
26
|
+
if (name && SKIP.has(name)) return;
|
|
27
|
+
const already = node.attributes.some(
|
|
28
|
+
(attr) => attr.type === "JSXAttribute" && attr.name?.name === attribute
|
|
29
|
+
);
|
|
30
|
+
if (already) return;
|
|
31
|
+
const loc = node.loc?.start;
|
|
32
|
+
if (!loc) return;
|
|
33
|
+
const relative = path.relative(rootDir, filename).split(path.sep).join("/");
|
|
34
|
+
const component = componentName(node.name);
|
|
35
|
+
const value = `${relative}:${loc.line}:${loc.column + 1}${component ? `:${component}` : ""}`;
|
|
36
|
+
node.attributes.unshift(
|
|
37
|
+
t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(value))
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function componentName(name) {
|
|
45
|
+
if (!name) return null;
|
|
46
|
+
if (name.type === "JSXIdentifier") return /^[A-Z]/.test(name.name) ? name.name : null;
|
|
47
|
+
if (name.type === "JSXMemberExpression") {
|
|
48
|
+
const object = name.object?.type === "JSXIdentifier" ? name.object.name : componentName(name.object);
|
|
49
|
+
return object && name.property?.name ? `${object}.${name.property.name}` : null;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function elementName(name) {
|
|
54
|
+
if (!name) return null;
|
|
55
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
56
|
+
if (name.type === "JSXMemberExpression") return elementName(name.property);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/plugin/jsx.ts
|
|
61
|
+
var babel = null;
|
|
62
|
+
async function stampJsx(code, file, rootDir, attribute) {
|
|
63
|
+
if (!code.includes("<")) return null;
|
|
64
|
+
babel ??= await import("@babel/core");
|
|
65
|
+
const typescript = /\.tsx?$/.test(file);
|
|
66
|
+
const result = await babel.transformAsync(code, {
|
|
67
|
+
filename: file,
|
|
68
|
+
babelrc: false,
|
|
69
|
+
configFile: false,
|
|
70
|
+
sourceMaps: true,
|
|
71
|
+
compact: false,
|
|
72
|
+
parserOpts: { plugins: typescript ? ["jsx", "typescript", "decorators-legacy"] : ["jsx"] },
|
|
73
|
+
plugins: [grabbyBabelPlugin({ rootDir, attribute })]
|
|
74
|
+
});
|
|
75
|
+
if (!result?.code) return null;
|
|
76
|
+
return { code: result.code, map: result.map };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/plugin/vue.ts
|
|
80
|
+
var NODE_ELEMENT = 1;
|
|
81
|
+
var TAG_ELEMENT = 0;
|
|
82
|
+
var compiler;
|
|
83
|
+
async function loadCompiler() {
|
|
84
|
+
if (compiler !== void 0) return compiler;
|
|
85
|
+
try {
|
|
86
|
+
compiler = await import("vue/compiler-sfc");
|
|
87
|
+
} catch {
|
|
88
|
+
compiler = null;
|
|
89
|
+
}
|
|
90
|
+
return compiler;
|
|
91
|
+
}
|
|
92
|
+
async function stampVue(code, relativePath, attribute = SOURCE_ATTRIBUTE) {
|
|
93
|
+
if (!code.includes("<template")) return null;
|
|
94
|
+
const sfc = await loadCompiler();
|
|
95
|
+
if (!sfc) return null;
|
|
96
|
+
let template;
|
|
97
|
+
try {
|
|
98
|
+
template = sfc.parse(code, { filename: relativePath }).descriptor.template;
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (!template?.ast || template.lang && template.lang !== "html") return null;
|
|
103
|
+
const inserts = [];
|
|
104
|
+
const visit = (node) => {
|
|
105
|
+
if (node.type === NODE_ELEMENT && node.tagType === TAG_ELEMENT && node.tag) {
|
|
106
|
+
const at = node.loc.start.offset + 1 + node.tag.length;
|
|
107
|
+
const alreadyStamped = node.props?.some((p) => p.name === attribute);
|
|
108
|
+
if (!alreadyStamped && code.slice(node.loc.start.offset, at) === `<${node.tag}`) {
|
|
109
|
+
const { line, column } = node.loc.start;
|
|
110
|
+
inserts.push({ at, text: ` ${attribute}="${relativePath}:${line}:${column}"` });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
node.children?.forEach(visit);
|
|
114
|
+
};
|
|
115
|
+
visit(template.ast);
|
|
116
|
+
if (inserts.length === 0) return null;
|
|
117
|
+
let out = code;
|
|
118
|
+
for (const { at, text } of inserts.sort((a, b) => b.at - a.at)) {
|
|
119
|
+
out = out.slice(0, at) + text + out.slice(at);
|
|
120
|
+
}
|
|
121
|
+
return { code: out, map: null };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/plugin/index.ts
|
|
125
|
+
var DEFAULT_INCLUDE = /\.(jsx|tsx|vue)$/;
|
|
126
|
+
var DEFAULT_EXCLUDE = /[\\/]node_modules[\\/]/;
|
|
127
|
+
function isProduction() {
|
|
128
|
+
return typeof process !== "undefined" && process.env.NODE_ENV === "production";
|
|
129
|
+
}
|
|
130
|
+
var unplugin = createUnplugin((options = {}) => {
|
|
131
|
+
let rootDir = options.rootDir ?? process.cwd();
|
|
132
|
+
const include = options.include ?? DEFAULT_INCLUDE;
|
|
133
|
+
const exclude = options.exclude ?? DEFAULT_EXCLUDE;
|
|
134
|
+
let enabled = options.includeSourceInBuild === true || !isProduction();
|
|
135
|
+
const relative = (file) => path2.relative(rootDir, file).split(path2.sep).join("/");
|
|
136
|
+
return {
|
|
137
|
+
name: "grabby-source",
|
|
138
|
+
enforce: "pre",
|
|
139
|
+
transformInclude(id) {
|
|
140
|
+
if (!enabled) return false;
|
|
141
|
+
const [file, query] = id.split("?");
|
|
142
|
+
if (!include.test(file) || exclude.test(file)) return false;
|
|
143
|
+
if (file.endsWith(".vue") && query) return false;
|
|
144
|
+
return true;
|
|
145
|
+
},
|
|
146
|
+
async transform(code, id) {
|
|
147
|
+
const file = id.split("?")[0];
|
|
148
|
+
if (file.endsWith(".vue")) return stampVue(code, relative(file), options.attribute);
|
|
149
|
+
return stampJsx(code, file, rootDir, options.attribute);
|
|
150
|
+
},
|
|
151
|
+
vite: {
|
|
152
|
+
configResolved(config) {
|
|
153
|
+
enabled = options.includeSourceInBuild === true || config.command === "serve";
|
|
154
|
+
if (!options.rootDir) rootDir = config.root;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
webpack(compiler2) {
|
|
158
|
+
enabled = options.includeSourceInBuild === true || compiler2.options.mode !== "production";
|
|
159
|
+
if (!options.rootDir && compiler2.context) rootDir = compiler2.context;
|
|
160
|
+
},
|
|
161
|
+
rspack(compiler2) {
|
|
162
|
+
enabled = options.includeSourceInBuild === true || compiler2.options.mode !== "production";
|
|
163
|
+
if (!options.rootDir && compiler2.context) rootDir = compiler2.context;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
var vite = unplugin.vite;
|
|
168
|
+
var webpack = unplugin.webpack;
|
|
169
|
+
var rspack = unplugin.rspack;
|
|
170
|
+
var rollup = unplugin.rollup;
|
|
171
|
+
var rolldown = unplugin.rolldown;
|
|
172
|
+
var esbuild = unplugin.esbuild;
|
|
173
|
+
var plugin_default = { vite, webpack, rspack, rollup, rolldown, esbuild };
|
|
174
|
+
export {
|
|
175
|
+
plugin_default as default,
|
|
176
|
+
esbuild,
|
|
177
|
+
rolldown,
|
|
178
|
+
rollup,
|
|
179
|
+
rspack,
|
|
180
|
+
stampJsx,
|
|
181
|
+
stampVue,
|
|
182
|
+
unplugin,
|
|
183
|
+
vite,
|
|
184
|
+
webpack
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/index.ts","../../src/babel-plugin/index.ts","../../src/core/adapters/stamp.ts","../../src/plugin/jsx.ts","../../src/plugin/vue.ts"],"sourcesContent":["import path from 'node:path';\nimport { createUnplugin } from 'unplugin';\nimport { stampJsx } from './jsx';\nimport { stampVue } from './vue';\n\nexport interface GrabbyPluginOptions {\n /** Paths are stamped relative to this. Default: the bundler's project root */\n rootDir?: string;\n /** Files to stamp. Default: .jsx, .tsx and .vue */\n include?: RegExp;\n /** Files to leave alone. Default: /node_modules/ */\n exclude?: RegExp;\n /** Attribute to stamp. Default: \"data-grabby-loc\" */\n attribute?: string;\n /**\n * Also stamp production builds. Off by default, since stamps expose source\n * paths in the page; turn it on when collecting feedback on a deployed\n * site and you want comments to carry file:line.\n */\n includeSourceInBuild?: boolean;\n}\n\nconst DEFAULT_INCLUDE = /\\.(jsx|tsx|vue)$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n\nfunction isProduction(): boolean {\n return typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n}\n\n/**\n * Adds a `data-grabby-loc=\"file:line:col\"` attribute to every element in\n * JSX/TSX and Vue templates so Grabby can say exactly where an element was\n * written. Svelte needs nothing (its dev build carries locations already)\n * and Angular uses the Grabby builders instead.\n */\nexport const unplugin = createUnplugin<GrabbyPluginOptions | undefined>((options = {}) => {\n // The bundler's own root beats cwd: dev servers are often started from\n // elsewhere (a monorepo root, an IDE), which would give ../../ paths.\n let rootDir = options.rootDir ?? process.cwd();\n const include = options.include ?? DEFAULT_INCLUDE;\n const exclude = options.exclude ?? DEFAULT_EXCLUDE;\n let enabled = options.includeSourceInBuild === true || !isProduction();\n\n const relative = (file: string) => path.relative(rootDir, file).split(path.sep).join('/');\n\n return {\n name: 'grabby-source',\n enforce: 'pre',\n\n transformInclude(id) {\n if (!enabled) return false;\n const [file, query] = id.split('?');\n if (!include.test(file) || exclude.test(file)) return false;\n // Vue sub-requests (?vue&type=style…) are blocks of a file we've already stamped.\n if (file.endsWith('.vue') && query) return false;\n return true;\n },\n\n async transform(code, id) {\n const file = id.split('?')[0];\n if (file.endsWith('.vue')) return stampVue(code, relative(file), options.attribute);\n return stampJsx(code, file, rootDir, options.attribute);\n },\n\n vite: {\n configResolved(config) {\n enabled = options.includeSourceInBuild === true || config.command === 'serve';\n if (!options.rootDir) rootDir = config.root;\n },\n },\n webpack(compiler) {\n enabled = options.includeSourceInBuild === true || compiler.options.mode !== 'production';\n if (!options.rootDir && compiler.context) rootDir = compiler.context;\n },\n rspack(compiler) {\n enabled = options.includeSourceInBuild === true || compiler.options.mode !== 'production';\n if (!options.rootDir && compiler.context) rootDir = compiler.context;\n },\n };\n});\n\n/** `plugins: [grabby.vite(), react()]` */\nexport const vite = unplugin.vite;\n/** `plugins: [grabby.webpack()]` (Next.js: in `next.config.js` → webpack) */\nexport const webpack = unplugin.webpack;\nexport const rspack = unplugin.rspack;\nexport const rollup = unplugin.rollup;\nexport const rolldown = unplugin.rolldown;\nexport const esbuild = unplugin.esbuild;\n\nexport { stampJsx } from './jsx';\nexport { stampVue } from './vue';\n\nexport default { vite, webpack, rspack, rollup, rolldown, esbuild };\n","import path from 'node:path';\nimport { SOURCE_ATTRIBUTE } from '../core/adapters/stamp';\n\nexport interface GrabbyBabelOptions {\n /** Paths are stamped relative to this. Default: process.cwd() */\n rootDir?: string;\n /** Attribute to stamp. Default: \"data-grabby-loc\" */\n attribute?: string;\n}\n\n/** React built-ins that take no DOM props, so stamping them does nothing useful. */\nconst SKIP = new Set(['Fragment', 'StrictMode', 'Suspense', 'SuspenseList', 'Profiler']);\n\n/**\n * Stamps every JSX element with its `file:line:column` so grabby can\n * report where a grabbed element was written.\n *\n * Wire it through @vitejs/plugin-react:\n *\n * react({ babel: { plugins: [grabbyBabelPlugin()] } })\n *\n * The attribute is prepended, so a `{...props}` spread still wins. That's\n * deliberate: for `<Button />` the stamp travels with the props onto the\n * rendered DOM node, and the grab points at the page rather than the library.\n */\nexport function grabbyBabelPlugin(options: GrabbyBabelOptions = {}) {\n const attribute = options.attribute ?? SOURCE_ATTRIBUTE;\n const rootDir = options.rootDir ?? process.cwd();\n\n return function grabbyReactSource({ types: t }: { types: any }) {\n return {\n name: 'grabby-react-source',\n visitor: {\n JSXOpeningElement(nodePath: any, state: any) {\n const filename: string | undefined = state.filename ?? state.file?.opts?.filename;\n if (!filename || filename.includes('node_modules')) return;\n\n const node = nodePath.node;\n if (node.name?.type === 'JSXNamespacedName') return;\n\n const name = elementName(node.name);\n if (name && SKIP.has(name)) return;\n\n const already = node.attributes.some(\n (attr: any) => attr.type === 'JSXAttribute' && attr.name?.name === attribute,\n );\n if (already) return;\n\n const loc = node.loc?.start;\n if (!loc) return;\n\n const relative = path.relative(rootDir, filename).split(path.sep).join('/');\n // Components also record their name: production builds minify\n // function names, so the fiber would only say \"vu\" or \"M\".\n const component = componentName(node.name);\n const value = `${relative}:${loc.line}:${loc.column + 1}${component ? `:${component}` : ''}`;\n\n node.attributes.unshift(\n t.jsxAttribute(t.jsxIdentifier(attribute), t.stringLiteral(value)),\n );\n },\n },\n };\n };\n}\n\n/** `Card`, `Table.Row`: capitalised or member JSX names; native tags return null. */\nfunction componentName(name: any): string | null {\n if (!name) return null;\n if (name.type === 'JSXIdentifier') return /^[A-Z]/.test(name.name) ? name.name : null;\n if (name.type === 'JSXMemberExpression') {\n const object = name.object?.type === 'JSXIdentifier' ? name.object.name : componentName(name.object);\n return object && name.property?.name ? `${object}.${name.property.name}` : null;\n }\n return null;\n}\n\nfunction elementName(name: any): string | null {\n if (!name) return null;\n if (name.type === 'JSXIdentifier') return name.name;\n if (name.type === 'JSXMemberExpression') return elementName(name.property);\n return null;\n}\n\nexport default grabbyBabelPlugin;\n","export const SOURCE_ATTRIBUTE = 'data-grabby-loc';\n\nconst LOCATION = /^(.*?):(\\d+):(\\d+)(?::([A-Za-z_$][\\w$.]*))?$/;\n\n/**\n * Reads the `file:line:column` stamp the Grabby build plugin puts on elements\n * (JSX and Vue templates), walking up to the nearest ancestor that has one.\n */\nexport function resolveSource(element: Element): {\n filePath: string | null;\n line: number | null;\n column: number | null;\n} {\n let current: Element | null = element;\n while (current) {\n const raw = current.getAttribute?.(SOURCE_ATTRIBUTE);\n if (raw) return parseLocation(raw);\n current = current.parentElement;\n }\n return { filePath: null, line: null, column: null };\n}\n\nfunction parseLocation(raw: string): {\n filePath: string | null;\n line: number | null;\n column: number | null;\n} {\n const match = LOCATION.exec(raw);\n if (!match) return { filePath: raw, line: null, column: null };\n return { filePath: match[1], line: Number(match[2]), column: Number(match[3]) };\n}\n\nexport interface Stamp {\n file: string;\n line: number | null;\n column: number | null;\n /** The component written at that spot (`<Card …>`), when it was a component. */\n name: string | null;\n}\n\n/** The stamp on this exact element (not an ancestor's), if it has one. */\nexport function ownStamp(element: Element | null): Stamp | null {\n const raw = element?.getAttribute?.(SOURCE_ATTRIBUTE);\n if (!raw) return null;\n const match = LOCATION.exec(raw);\n if (!match) return { file: raw, line: null, column: null, name: null };\n return { file: match[1], line: Number(match[2]), column: Number(match[3]), name: match[4] ?? null };\n}\n\n/** True when the page was built with the Grabby source plugin. */\nexport function hasSourceStamps(): boolean {\n try {\n return document.querySelector(`[${SOURCE_ATTRIBUTE}]`) !== null;\n } catch {\n return false;\n }\n}\n","import { grabbyBabelPlugin } from '../babel-plugin';\n\nlet babel: typeof import('@babel/core') | null = null;\n\n/**\n * Re-emits JSX with a `data-grabby-loc` stamp on every element. It runs its\n * own Babel pass and leaves the JSX in place, so whatever compiles JSX next\n * (Babel, SWC, Oxc, esbuild, Solid's compiler) is unaffected.\n */\nexport async function stampJsx(code: string, file: string, rootDir: string, attribute?: string) {\n if (!code.includes('<')) return null;\n babel ??= await import('@babel/core');\n const typescript = /\\.tsx?$/.test(file);\n const result = await babel.transformAsync(code, {\n filename: file,\n babelrc: false,\n configFile: false,\n sourceMaps: true,\n compact: false,\n parserOpts: { plugins: typescript ? ['jsx', 'typescript', 'decorators-legacy'] : ['jsx'] },\n plugins: [grabbyBabelPlugin({ rootDir, attribute })],\n });\n if (!result?.code) return null;\n return { code: result.code, map: result.map };\n}\n","import { SOURCE_ATTRIBUTE } from '../core/adapters/stamp';\n\ninterface TemplateNode {\n type: number;\n tag?: string;\n tagType?: number;\n loc: { start: { offset: number; line: number; column: number } };\n props?: Array<{ type: number; name: string }>;\n children?: TemplateNode[];\n}\n\nconst NODE_ELEMENT = 1;\nconst TAG_ELEMENT = 0;\n\ntype SfcCompiler = { parse: (code: string, opts: { filename: string }) => { descriptor: { template: { lang?: string; ast?: TemplateNode } | null } } };\nlet compiler: SfcCompiler | null | undefined;\n\nasync function loadCompiler(): Promise<SfcCompiler | null> {\n if (compiler !== undefined) return compiler;\n try {\n compiler = (await import('vue/compiler-sfc')) as unknown as SfcCompiler;\n } catch {\n compiler = null;\n }\n return compiler;\n}\n\n/**\n * Stamps every native element in a Vue SFC template with `file:line:col`.\n * Component tags are left alone: their attributes fall through onto the\n * child's root element and would overwrite the child's own, more precise\n * stamp. Uses the app's own `vue/compiler-sfc`, so it always matches the\n * installed Vue version.\n */\nexport async function stampVue(code: string, relativePath: string, attribute = SOURCE_ATTRIBUTE) {\n if (!code.includes('<template')) return null;\n const sfc = await loadCompiler();\n if (!sfc) return null;\n\n let template;\n try {\n template = sfc.parse(code, { filename: relativePath }).descriptor.template;\n } catch {\n return null;\n }\n // Pug and other template languages have no HTML AST to stamp.\n if (!template?.ast || (template.lang && template.lang !== 'html')) return null;\n\n const inserts: Array<{ at: number; text: string }> = [];\n const visit = (node: TemplateNode) => {\n if (node.type === NODE_ELEMENT && node.tagType === TAG_ELEMENT && node.tag) {\n const at = node.loc.start.offset + 1 + node.tag.length;\n const alreadyStamped = node.props?.some((p) => p.name === attribute);\n // Guard against offsets that don't line up with the source.\n if (!alreadyStamped && code.slice(node.loc.start.offset, at) === `<${node.tag}`) {\n const { line, column } = node.loc.start;\n inserts.push({ at, text: ` ${attribute}=\"${relativePath}:${line}:${column}\"` });\n }\n }\n node.children?.forEach(visit);\n };\n visit(template.ast);\n if (inserts.length === 0) return null;\n\n let out = code;\n for (const { at, text } of inserts.sort((a, b) => b.at - a.at)) {\n out = out.slice(0, at) + text + out.slice(at);\n }\n return { code: out, map: null };\n}\n"],"mappings":";AAAA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,QAAQ,yBAAyB,QAAQA,UAAS,QAAQ,SAAS;AAC7E,UAAI,CAAC,QAAQ,WAAWA,UAAS,QAAS,WAAUA,UAAS;AAAA,IAC/D;AAAA,IACA,OAAOA,WAAU;AACf,gBAAU,QAAQ,yBAAyB,QAAQA,UAAS,QAAQ,SAAS;AAC7E,UAAI,CAAC,QAAQ,WAAWA,UAAS,QAAS,WAAUA,UAAS;AAAA,IAC/D;AAAA,EACF;AACF,CAAC;AAGM,IAAM,OAAO,SAAS;AAEtB,IAAM,UAAU,SAAS;AACzB,IAAM,SAAS,SAAS;AACxB,IAAM,SAAS,SAAS;AACxB,IAAM,WAAW,SAAS;AAC1B,IAAM,UAAU,SAAS;AAKhC,IAAO,iBAAQ,EAAE,MAAM,SAAS,QAAQ,QAAQ,UAAU,QAAQ;","names":["path","path","compiler"]}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teaches Grabby about one UI framework: how to name the component that owns
|
|
3
|
+
* an element, and where that element was written. Adapters only read what the
|
|
4
|
+
* framework already leaves on DOM nodes in development builds, so none of
|
|
5
|
+
* them import the framework itself.
|
|
6
|
+
*/
|
|
7
|
+
interface FrameworkAdapter {
|
|
8
|
+
/** Shown in exports, e.g. "React", "Vue". */
|
|
9
|
+
name: string;
|
|
10
|
+
resolveComponent: ComponentResolver;
|
|
11
|
+
resolveSource?: SourceResolver;
|
|
12
|
+
/** Drops framework-generated classes (scoping hashes and the like). */
|
|
13
|
+
cleanClasses?: (classes: string[]) => string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type ThemeMode = 'light';
|
|
17
|
+
/** What kind of UI the comment is about; decides which facts get captured. */
|
|
18
|
+
type TargetKind = 'action' | 'field' | 'text' | 'media' | 'container' | 'section';
|
|
19
|
+
/** How much context the export includes. */
|
|
20
|
+
type DetailLevel = 'compact' | 'standard' | 'detailed';
|
|
21
|
+
interface SourceLocation {
|
|
22
|
+
file: string;
|
|
23
|
+
line: number | null;
|
|
24
|
+
column: number | null;
|
|
25
|
+
}
|
|
26
|
+
interface StackFrame {
|
|
27
|
+
name: string;
|
|
28
|
+
file: string | null;
|
|
29
|
+
line: number | null;
|
|
30
|
+
}
|
|
31
|
+
/** The compact, serialisable description of the element a comment is about. */
|
|
32
|
+
interface GrabbyTarget {
|
|
33
|
+
kind: TargetKind;
|
|
34
|
+
tag: string;
|
|
35
|
+
component: string | null;
|
|
36
|
+
source: SourceLocation | null;
|
|
37
|
+
/** Up to 3 of the app's own component frames, innermost first. */
|
|
38
|
+
stack: StackFrame[];
|
|
39
|
+
/** Unique CSS selector. Exported only when there is no source location. */
|
|
40
|
+
selector: string;
|
|
41
|
+
/** Trimmed opening tag plus a text excerpt, at most ~300 characters. */
|
|
42
|
+
preview: string;
|
|
43
|
+
/** Kind-specific facts for the standard export, in display order. */
|
|
44
|
+
facts: Record<string, string>;
|
|
45
|
+
/** Extra facts only shown at the detailed level. */
|
|
46
|
+
extra: Record<string, string>;
|
|
47
|
+
}
|
|
48
|
+
interface CommentAuthor {
|
|
49
|
+
name: string | null;
|
|
50
|
+
anonymous: boolean;
|
|
51
|
+
/** Stable random id per browser, so anonymous commenters stay distinguishable. */
|
|
52
|
+
sessionId: string;
|
|
53
|
+
/** The host app's own user id, when it called `identify()`. */
|
|
54
|
+
userId?: string;
|
|
55
|
+
}
|
|
56
|
+
interface PageInfo {
|
|
57
|
+
/** Pathname only; query strings are dropped unless allowlisted. */
|
|
58
|
+
route: string;
|
|
59
|
+
title: string;
|
|
60
|
+
viewport: [number, number];
|
|
61
|
+
}
|
|
62
|
+
interface ScreenshotRef {
|
|
63
|
+
/** Key of the image in this browser's IndexedDB. */
|
|
64
|
+
localId?: string;
|
|
65
|
+
/** Where a server stored it, once uploaded. */
|
|
66
|
+
url?: string;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
interface GrabbyComment {
|
|
71
|
+
id: string;
|
|
72
|
+
createdAt: number;
|
|
73
|
+
updatedAt: number;
|
|
74
|
+
status: 'open' | 'resolved';
|
|
75
|
+
comment: string;
|
|
76
|
+
author: CommentAuthor;
|
|
77
|
+
page: PageInfo;
|
|
78
|
+
target: GrabbyTarget;
|
|
79
|
+
screenshot: ScreenshotRef | null;
|
|
80
|
+
framework: string;
|
|
81
|
+
/** Delivery to a Grabby server, when one is configured. Browser-only. */
|
|
82
|
+
sync?: 'pending' | 'sent' | 'failed';
|
|
83
|
+
}
|
|
84
|
+
interface GrabbyOptions {
|
|
85
|
+
/** Keyboard shortcut to activate. Default: "Alt+G" (Option+G on Mac) */
|
|
86
|
+
activationKey: string;
|
|
87
|
+
/** Whether activation requires hold or toggle. Default: 'toggle' */
|
|
88
|
+
activationMode: 'hold' | 'toggle';
|
|
89
|
+
/** Milliseconds to hold before activating in hold mode. Default: 0 */
|
|
90
|
+
keyHoldDuration: number;
|
|
91
|
+
/** Master on/off switch. Default: true */
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
/** Allow activation while focused in input/textarea. Default: false */
|
|
94
|
+
enableInInputs: boolean;
|
|
95
|
+
/** Only activate in dev mode. Default: true */
|
|
96
|
+
devOnly: boolean;
|
|
97
|
+
/** Show the floating mini toolbar. Default: true */
|
|
98
|
+
showToolbar: boolean;
|
|
99
|
+
/** Theme mode for all UI. Default: 'light' */
|
|
100
|
+
themeMode: ThemeMode;
|
|
101
|
+
/**
|
|
102
|
+
* 'local' (default): for developers on their own machine; dev builds only.
|
|
103
|
+
* 'live': for collecting feedback on a deployed site. Grabby stays hidden
|
|
104
|
+
* until someone opens a feedback link (?grabby=<projectKey>), and works in
|
|
105
|
+
* production builds.
|
|
106
|
+
*/
|
|
107
|
+
mode: 'local' | 'live';
|
|
108
|
+
/**
|
|
109
|
+
* A grabby-server URL. Comments are saved in the browser and delivered
|
|
110
|
+
* there (with retries), where you pull them or your agent reads them over
|
|
111
|
+
* MCP. Locally: 'http://localhost:3456'.
|
|
112
|
+
*/
|
|
113
|
+
server?: string;
|
|
114
|
+
/** The project's public key from `grabby-server init`. Required for a public server. */
|
|
115
|
+
projectKey?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Who a comment is from. 'ask' prompts for a name (or anonymous) on the
|
|
118
|
+
* first comment; 'anonymous' never asks; 'none' skips identity entirely.
|
|
119
|
+
* Default: 'ask' in live mode, 'none' locally.
|
|
120
|
+
*/
|
|
121
|
+
identity?: 'ask' | 'anonymous' | 'none';
|
|
122
|
+
/** Also POST each comment as JSON to this URL (https, or http://localhost). */
|
|
123
|
+
webhookUrl?: string;
|
|
124
|
+
/** Persist comments across page refresh via localStorage. Default: true */
|
|
125
|
+
persistHistory: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Also copy each comment to the clipboard as soon as it's saved. Default:
|
|
128
|
+
* false: comments collect until you use Copy all.
|
|
129
|
+
*/
|
|
130
|
+
copyOnComment: boolean;
|
|
131
|
+
/** Default detail level for exports. Default: 'standard' */
|
|
132
|
+
detailLevel: DetailLevel;
|
|
133
|
+
/** Capture a screenshot of the commented element. Default: true */
|
|
134
|
+
screenshots: boolean;
|
|
135
|
+
/** Query parameters worth keeping in the recorded route, e.g. ['tab']. Default: [] */
|
|
136
|
+
captureQueryParams: string[];
|
|
137
|
+
/**
|
|
138
|
+
* Framework adapters to try, in order. Default: every built-in adapter
|
|
139
|
+
* (Angular, React, Vue, Svelte, then plain HTML), detected per element.
|
|
140
|
+
*/
|
|
141
|
+
adapters?: FrameworkAdapter[];
|
|
142
|
+
/**
|
|
143
|
+
* CSP nonce for Grabby's `<style>` elements. Only used in browsers without
|
|
144
|
+
* constructable stylesheets; elsewhere styles need no CSP allowance.
|
|
145
|
+
*/
|
|
146
|
+
styleNonce?: string;
|
|
147
|
+
}
|
|
148
|
+
interface PluginHooks {
|
|
149
|
+
onActivate?: () => void;
|
|
150
|
+
onDeactivate?: () => void;
|
|
151
|
+
onElementHover?: (element: Element) => void;
|
|
152
|
+
onElementSelect?: (element: Element) => void;
|
|
153
|
+
/**
|
|
154
|
+
* A comment was saved. Fires whether or not anything reached the clipboard,
|
|
155
|
+
* so use this to persist or forward comments.
|
|
156
|
+
*/
|
|
157
|
+
onComment?: (comment: GrabbyComment, element: Element | null) => void;
|
|
158
|
+
/** A saved comment gained its screenshot (it's captured asynchronously). */
|
|
159
|
+
onScreenshot?: (comment: GrabbyComment, image: Blob) => void;
|
|
160
|
+
onCopySuccess?: (text: string, comments: GrabbyComment[]) => void;
|
|
161
|
+
onCopyError?: (error: Error) => void;
|
|
162
|
+
/** Rewrite exported text before it reaches the clipboard. */
|
|
163
|
+
transformCopyContent?: (text: string, comments: GrabbyComment[]) => string;
|
|
164
|
+
}
|
|
165
|
+
interface Theme {
|
|
166
|
+
overlayBorderColor: string;
|
|
167
|
+
overlayBgColor: string;
|
|
168
|
+
labelBgColor: string;
|
|
169
|
+
labelTextColor: string;
|
|
170
|
+
toastBgColor: string;
|
|
171
|
+
toastTextColor: string;
|
|
172
|
+
toolbarBgColor: string;
|
|
173
|
+
toolbarTextColor: string;
|
|
174
|
+
toolbarAccentColor: string;
|
|
175
|
+
popoverBgColor: string;
|
|
176
|
+
popoverTextColor: string;
|
|
177
|
+
popoverBorderColor: string;
|
|
178
|
+
}
|
|
179
|
+
interface Plugin {
|
|
180
|
+
name: string;
|
|
181
|
+
hooks?: PluginHooks;
|
|
182
|
+
theme?: Partial<Theme>;
|
|
183
|
+
options?: Partial<GrabbyOptions>;
|
|
184
|
+
setup?: (api: GrabbyAPI) => PluginCleanup | void;
|
|
185
|
+
}
|
|
186
|
+
type PluginCleanup = () => void;
|
|
187
|
+
type ComponentResolver = (element: Element) => {
|
|
188
|
+
name: string | null;
|
|
189
|
+
hostElement: Element | null;
|
|
190
|
+
/**
|
|
191
|
+
* Owning components, innermost first. An entry can carry its own location
|
|
192
|
+
* when the framework knows it; otherwise it's resolved from `hostElement`.
|
|
193
|
+
*/
|
|
194
|
+
stack?: Array<{
|
|
195
|
+
name: string;
|
|
196
|
+
hostElement: Element | null;
|
|
197
|
+
filePath?: string | null;
|
|
198
|
+
line?: number | null;
|
|
199
|
+
}>;
|
|
200
|
+
} | null;
|
|
201
|
+
type SourceResolver = (element: Element) => {
|
|
202
|
+
filePath: string | null;
|
|
203
|
+
line: number | null;
|
|
204
|
+
column: number | null;
|
|
205
|
+
} | null;
|
|
206
|
+
interface GrabbyAPI {
|
|
207
|
+
activate(): void;
|
|
208
|
+
deactivate(): void;
|
|
209
|
+
toggle(): void;
|
|
210
|
+
isActive(): boolean;
|
|
211
|
+
setOptions(opts: Partial<GrabbyOptions>): void;
|
|
212
|
+
registerPlugin(plugin: Plugin): void;
|
|
213
|
+
unregisterPlugin(name: string): void;
|
|
214
|
+
setComponentResolver(resolver: ComponentResolver): void;
|
|
215
|
+
setSourceResolver(resolver: SourceResolver): void;
|
|
216
|
+
showToolbar(): void;
|
|
217
|
+
hideToolbar(): void;
|
|
218
|
+
setThemeMode(mode: ThemeMode): void;
|
|
219
|
+
/** Open comments, newest first. */
|
|
220
|
+
getComments(): GrabbyComment[];
|
|
221
|
+
/** Export text for the given (default: all) comments at a detail level. */
|
|
222
|
+
exportComments(options?: {
|
|
223
|
+
level?: DetailLevel;
|
|
224
|
+
ids?: string[];
|
|
225
|
+
}): string;
|
|
226
|
+
deleteComment(id: string): void;
|
|
227
|
+
clearComments(): void;
|
|
228
|
+
/**
|
|
229
|
+
* Tell Grabby who is signed in, so commenters aren't asked for a name.
|
|
230
|
+
* Pass null on sign-out.
|
|
231
|
+
*/
|
|
232
|
+
identify(user: {
|
|
233
|
+
id?: string;
|
|
234
|
+
name: string;
|
|
235
|
+
} | null): void;
|
|
236
|
+
/** Show Grabby. In live mode this starts a feedback session for this tab. */
|
|
237
|
+
show(): void;
|
|
238
|
+
/** Hide Grabby. In live mode this ends the feedback session. */
|
|
239
|
+
hide(): void;
|
|
240
|
+
dispose(): void;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Names come from the React fiber; locations come from build-time stamps. */
|
|
244
|
+
declare const reactAdapter: FrameworkAdapter;
|
|
245
|
+
|
|
246
|
+
declare const SOURCE_ATTRIBUTE = "data-grabby-loc";
|
|
247
|
+
/**
|
|
248
|
+
* Reads the `file:line:column` stamp the Grabby build plugin puts on elements
|
|
249
|
+
* (JSX and Vue templates), walking up to the nearest ancestor that has one.
|
|
250
|
+
*/
|
|
251
|
+
declare function resolveSource(element: Element): {
|
|
252
|
+
filePath: string | null;
|
|
253
|
+
line: number | null;
|
|
254
|
+
column: number | null;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
declare function resolveComponent(element: Element): {
|
|
258
|
+
name: string | null;
|
|
259
|
+
hostElement: Element | null;
|
|
260
|
+
stack: Array<{
|
|
261
|
+
name: string;
|
|
262
|
+
hostElement: Element | null;
|
|
263
|
+
}>;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
interface FiberNode {
|
|
267
|
+
type: unknown;
|
|
268
|
+
stateNode: unknown;
|
|
269
|
+
return: FiberNode | null;
|
|
270
|
+
child: FiberNode | null;
|
|
271
|
+
sibling: FiberNode | null;
|
|
272
|
+
memoizedProps: Record<string, unknown> | null;
|
|
273
|
+
}
|
|
274
|
+
/** React attaches the fiber to the DOM node under a randomised key. */
|
|
275
|
+
declare function getFiber(element: Element): FiberNode | null;
|
|
276
|
+
/** Unwraps memo, forwardRef and lazy to reach the component's display name. */
|
|
277
|
+
declare function getComponentName(type: unknown, depth?: number): string | null;
|
|
278
|
+
/** The nearest DOM node a component fiber rendered, used to resolve its source. */
|
|
279
|
+
declare function findHostElement(fiber: FiberNode, depth?: number): Element | null;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Starts Grabby in a React app. Component names come from the React fiber;
|
|
283
|
+
* file:line comes from the stamps `@githumbi/grabby/plugin` adds at build time.
|
|
284
|
+
*
|
|
285
|
+
* Same as `initGrabby` from the package root, which detects React on its own;
|
|
286
|
+
* kept so existing `@githumbi/grabby/react` imports keep working.
|
|
287
|
+
*/
|
|
288
|
+
declare function initGrabby(options?: Partial<GrabbyOptions>): GrabbyAPI;
|
|
289
|
+
|
|
290
|
+
export { type FiberNode, type GrabbyAPI, type GrabbyOptions, SOURCE_ATTRIBUTE, findHostElement, getComponentName, getFiber, initGrabby, reactAdapter, resolveComponent, resolveSource };
|