@lego-build/plugins 0.0.2 → 0.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/dist/auto.js +3 -10
- package/dist/babel-plugin.d.ts +18 -0
- package/dist/babel-plugin.js +43 -0
- package/dist/{chunk-MZJDRENL.js → chunk-2R3NUXAB.js} +13 -9
- package/dist/chunk-3TRIUWCT.js +539 -0
- package/dist/chunk-42QHGI4F.js +512 -0
- package/dist/chunk-4EX2R46A.js +528 -0
- package/dist/{chunk-RM4HZDF3.js → chunk-6EMRLRSE.js} +12 -5
- package/dist/chunk-6MOTW5WZ.js +505 -0
- package/dist/chunk-J6RRTMEB.js +553 -0
- package/dist/chunk-NYSOJK4V.js +436 -0
- package/dist/chunk-ONSLHF7O.js +553 -0
- package/dist/chunk-QMPWAJBL.js +539 -0
- package/dist/chunk-RG2IIZUF.js +560 -0
- package/dist/chunk-SQ3BWA54.js +307 -0
- package/dist/chunk-URUG7I3S.js +539 -0
- package/dist/chunk-V3KCJYHC.js +468 -0
- package/dist/chunk-XZZFN45X.js +539 -0
- package/dist/index.d.ts +4 -28
- package/dist/index.js +8 -736
- package/dist/react.d.ts +7 -0
- package/dist/react.js +18 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +103 -0
- package/package.json +30 -21
package/dist/react.d.ts
ADDED
package/dist/react.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
initIframeBridge
|
|
4
|
+
} from "./chunk-4ILDPPTG.js";
|
|
5
|
+
|
|
6
|
+
// src/react.tsx
|
|
7
|
+
import { useEffect } from "react";
|
|
8
|
+
function IframeBridge() {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
initIframeBridge();
|
|
11
|
+
}, []);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
var react_default = IframeBridge;
|
|
15
|
+
export {
|
|
16
|
+
IframeBridge,
|
|
17
|
+
react_default as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface SourceLocatorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Patterns to exclude from source location injection
|
|
6
|
+
* @default ['node_modules', 'dist', 'build']
|
|
7
|
+
*/
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Vite plugin that adds data-locator-path and data-locator-line attributes
|
|
12
|
+
* to JSX elements for inline editing support.
|
|
13
|
+
*/
|
|
14
|
+
declare function sourceLocator(options?: SourceLocatorOptions): Plugin;
|
|
15
|
+
|
|
16
|
+
export { type SourceLocatorOptions, sourceLocator as default, sourceLocator };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/vite-plugin.ts
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import path from "path";
|
|
4
|
+
function sourceLocator(options = {}) {
|
|
5
|
+
const { exclude = ["node_modules", "dist", "build"] } = options;
|
|
6
|
+
let root = "";
|
|
7
|
+
return {
|
|
8
|
+
name: "lego-source-locator",
|
|
9
|
+
enforce: "pre",
|
|
10
|
+
configResolved(config) {
|
|
11
|
+
root = config.root;
|
|
12
|
+
},
|
|
13
|
+
transform(code, id) {
|
|
14
|
+
if (!id.match(/\.[tj]sx$/)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
for (const pattern of exclude) {
|
|
18
|
+
if (id.includes(pattern)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const relativePath = path.relative(root, id);
|
|
23
|
+
const s = new MagicString(code);
|
|
24
|
+
let hasChanges = false;
|
|
25
|
+
const jsxOpeningTagRegex = /<([A-Z][a-zA-Z0-9]*|[a-z][a-z0-9-]*)\s*(?=[^>]*>)/g;
|
|
26
|
+
const lines = code.split("\n");
|
|
27
|
+
const lineStarts = [0];
|
|
28
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
29
|
+
lineStarts.push(lineStarts[i] + lines[i].length + 1);
|
|
30
|
+
}
|
|
31
|
+
const getLineNumber = (index) => {
|
|
32
|
+
for (let i = lineStarts.length - 1; i >= 0; i--) {
|
|
33
|
+
if (lineStarts[i] <= index) {
|
|
34
|
+
return i + 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return 1;
|
|
38
|
+
};
|
|
39
|
+
let match;
|
|
40
|
+
while ((match = jsxOpeningTagRegex.exec(code)) !== null) {
|
|
41
|
+
const tagStart = match.index;
|
|
42
|
+
const tagName = match[1];
|
|
43
|
+
if (!tagName || tagName === "Fragment") {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
let depth = 1;
|
|
47
|
+
let i = tagStart + match[0].length;
|
|
48
|
+
let inString = null;
|
|
49
|
+
let inExpression = 0;
|
|
50
|
+
while (i < code.length && depth > 0) {
|
|
51
|
+
const char = code[i];
|
|
52
|
+
if (inString) {
|
|
53
|
+
if (char === inString && code[i - 1] !== "\\") {
|
|
54
|
+
inString = null;
|
|
55
|
+
}
|
|
56
|
+
} else if (inExpression > 0) {
|
|
57
|
+
if (char === "{") {
|
|
58
|
+
inExpression++;
|
|
59
|
+
} else if (char === "}") {
|
|
60
|
+
inExpression--;
|
|
61
|
+
} else if (char === '"' || char === "'" || char === "`") {
|
|
62
|
+
inString = char;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (char === "{") {
|
|
66
|
+
inExpression++;
|
|
67
|
+
} else if (char === '"' || char === "'" || char === "`") {
|
|
68
|
+
inString = char;
|
|
69
|
+
} else if (char === ">") {
|
|
70
|
+
depth = 0;
|
|
71
|
+
} else if (char === "/" && code[i + 1] === ">") {
|
|
72
|
+
depth = 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
if (depth === 0) {
|
|
78
|
+
const insertPos = code[i - 2] === "/" ? i - 2 : i - 1;
|
|
79
|
+
const lineNum = getLineNumber(tagStart);
|
|
80
|
+
const tagContent = code.slice(tagStart, i);
|
|
81
|
+
if (tagContent.includes("data-locator-path")) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const attrs = ` data-locator-path="${relativePath}" data-locator-line="${lineNum}"`;
|
|
85
|
+
s.appendLeft(insertPos, attrs);
|
|
86
|
+
hasChanges = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!hasChanges) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
code: s.toString(),
|
|
94
|
+
map: s.generateMap({ hires: true })
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
var vite_plugin_default = sourceLocator;
|
|
100
|
+
export {
|
|
101
|
+
vite_plugin_default as default,
|
|
102
|
+
sourceLocator
|
|
103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lego-build/plugins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,36 +8,45 @@
|
|
|
8
8
|
".": {
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./auto": {
|
|
13
|
+
"import": "./dist/auto.js"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./dist/react.d.ts",
|
|
17
|
+
"import": "./dist/react.js"
|
|
18
|
+
},
|
|
19
|
+
"./vite-plugin": {
|
|
20
|
+
"types": "./dist/vite-plugin.d.ts",
|
|
21
|
+
"import": "./dist/vite-plugin.js"
|
|
22
|
+
},
|
|
23
|
+
"./babel-plugin": {
|
|
24
|
+
"types": "./dist/babel-plugin.d.ts",
|
|
25
|
+
"import": "./dist/babel-plugin.js"
|
|
11
26
|
}
|
|
12
27
|
},
|
|
13
|
-
"files": [
|
|
14
|
-
"dist"
|
|
15
|
-
],
|
|
16
28
|
"scripts": {
|
|
17
|
-
"build": "tsup src/index.ts --format esm --dts",
|
|
18
|
-
"dev": "tsup src/index.ts --format esm --dts --watch"
|
|
29
|
+
"build": "tsup src/index.ts src/auto.ts src/react.tsx src/vite-plugin.ts src/babel-plugin.ts --format esm --dts --external react",
|
|
30
|
+
"dev": "tsup src/index.ts src/auto.ts src/react.tsx src/vite-plugin.ts src/babel-plugin.ts --format esm --dts --external react --watch"
|
|
19
31
|
},
|
|
20
32
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"@babel/parser": "^7.27.0",
|
|
23
|
-
"@babel/traverse": "^7.27.0",
|
|
24
|
-
"@babel/types": "^7.27.0",
|
|
25
|
-
"micromatch": "^4.0.5"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@types/babel__generator": "^7.27.0",
|
|
29
|
-
"@types/babel__traverse": "^7.20.7",
|
|
30
|
-
"@types/micromatch": "^4.0.9",
|
|
31
|
-
"@types/node": "^22",
|
|
32
|
-
"tsup": "^8.0.0",
|
|
33
|
-
"typescript": "^5.0.0"
|
|
33
|
+
"magic-string": "^0.30.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"
|
|
36
|
+
"react": ">=18"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
|
-
"
|
|
39
|
+
"react": {
|
|
40
40
|
"optional": true
|
|
41
41
|
}
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@babel/core": "^7.24.0",
|
|
45
|
+
"@types/babel__core": "^7.20.0",
|
|
46
|
+
"@types/react": "^18",
|
|
47
|
+
"react": "^18",
|
|
48
|
+
"tsup": "^8.0.0",
|
|
49
|
+
"typescript": "^5.0.0",
|
|
50
|
+
"vite": "^5.0.0"
|
|
42
51
|
}
|
|
43
52
|
}
|