zitejs 0.9.71 → 0.9.73
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/cjs/vite/index.d.ts +2 -0
- package/dist/cjs/vite/index.js +88 -0
- package/dist/esm/vite/index.d.ts +2 -0
- package/dist/esm/vite/index.js +82 -0
- package/package.json +17 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ziteId = ziteId;
|
|
7
|
+
const parser_1 = require("@babel/parser");
|
|
8
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const estree_walker_1 = require("estree-walker");
|
|
11
|
+
const validExtensions = new Set([".jsx", ".tsx"]);
|
|
12
|
+
function getComponentName(elementName) {
|
|
13
|
+
if (elementName.type === "JSXIdentifier") {
|
|
14
|
+
return elementName.name;
|
|
15
|
+
}
|
|
16
|
+
if (elementName.type === "JSXMemberExpression") {
|
|
17
|
+
const object = getComponentName(elementName.object);
|
|
18
|
+
const property = elementName.property.name;
|
|
19
|
+
return object ? `${object}.${property}` : property;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function isNativeElement(name) {
|
|
24
|
+
return /^[a-z]/.test(name) && !name.includes(".");
|
|
25
|
+
}
|
|
26
|
+
function ziteId() {
|
|
27
|
+
const cwd = process.cwd();
|
|
28
|
+
return {
|
|
29
|
+
name: "vite-plugin-zite-id",
|
|
30
|
+
enforce: "pre",
|
|
31
|
+
async transform(code, id) {
|
|
32
|
+
if (!validExtensions.has(path_1.default.extname(id)) ||
|
|
33
|
+
id.includes("node_modules")) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const relativePath = path_1.default.relative(cwd, id);
|
|
37
|
+
try {
|
|
38
|
+
const ast = (0, parser_1.parse)(code, {
|
|
39
|
+
sourceType: "module",
|
|
40
|
+
plugins: ["jsx", "typescript"],
|
|
41
|
+
});
|
|
42
|
+
const magicString = new magic_string_1.default(code);
|
|
43
|
+
(0, estree_walker_1.walk)(ast, {
|
|
44
|
+
enter(_node) {
|
|
45
|
+
const node = _node;
|
|
46
|
+
if (node.type === "JSXElement") {
|
|
47
|
+
const openingElement = node.openingElement;
|
|
48
|
+
const children = node.children;
|
|
49
|
+
const elementName = openingElement.name;
|
|
50
|
+
const isFragment = (elementName.type === "JSXMemberExpression" &&
|
|
51
|
+
elementName.object.name === "React" &&
|
|
52
|
+
elementName.property.name === "Fragment") ||
|
|
53
|
+
(elementName.type === "JSXIdentifier" &&
|
|
54
|
+
elementName.name === "Fragment");
|
|
55
|
+
if (isFragment) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const line = openingElement.loc?.start?.line ?? 0;
|
|
59
|
+
const col = openingElement.loc?.start?.column ?? 0;
|
|
60
|
+
const dataComponentId = `${relativePath}|${line}|${col}`;
|
|
61
|
+
let attributes = ` data-zite-id="${dataComponentId}"`;
|
|
62
|
+
const componentName = getComponentName(openingElement.name);
|
|
63
|
+
if (componentName && !isNativeElement(componentName)) {
|
|
64
|
+
attributes += ` data-zite-component="${componentName}"`;
|
|
65
|
+
}
|
|
66
|
+
if (children.length === 1 &&
|
|
67
|
+
(children[0].type === "JSXText" ||
|
|
68
|
+
children[0].type === "StringLiteral" ||
|
|
69
|
+
(children[0].type === "JSXExpressionContainer" &&
|
|
70
|
+
children[0].expression.type === "StringLiteral"))) {
|
|
71
|
+
attributes += ` data-zite-editable="true"`;
|
|
72
|
+
}
|
|
73
|
+
magicString.appendLeft(openingElement.name.end ?? 0, attributes);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
code: magicString.toString(),
|
|
79
|
+
map: magicString.generateMap({ hires: true }),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(`Error processing file ${relativePath}:`, error);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { walk } from "estree-walker";
|
|
5
|
+
const validExtensions = new Set([".jsx", ".tsx"]);
|
|
6
|
+
function getComponentName(elementName) {
|
|
7
|
+
if (elementName.type === "JSXIdentifier") {
|
|
8
|
+
return elementName.name;
|
|
9
|
+
}
|
|
10
|
+
if (elementName.type === "JSXMemberExpression") {
|
|
11
|
+
const object = getComponentName(elementName.object);
|
|
12
|
+
const property = elementName.property.name;
|
|
13
|
+
return object ? `${object}.${property}` : property;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function isNativeElement(name) {
|
|
18
|
+
return /^[a-z]/.test(name) && !name.includes(".");
|
|
19
|
+
}
|
|
20
|
+
export function ziteId() {
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
return {
|
|
23
|
+
name: "vite-plugin-zite-id",
|
|
24
|
+
enforce: "pre",
|
|
25
|
+
async transform(code, id) {
|
|
26
|
+
if (!validExtensions.has(path.extname(id)) ||
|
|
27
|
+
id.includes("node_modules")) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const relativePath = path.relative(cwd, id);
|
|
31
|
+
try {
|
|
32
|
+
const ast = parse(code, {
|
|
33
|
+
sourceType: "module",
|
|
34
|
+
plugins: ["jsx", "typescript"],
|
|
35
|
+
});
|
|
36
|
+
const magicString = new MagicString(code);
|
|
37
|
+
walk(ast, {
|
|
38
|
+
enter(_node) {
|
|
39
|
+
const node = _node;
|
|
40
|
+
if (node.type === "JSXElement") {
|
|
41
|
+
const openingElement = node.openingElement;
|
|
42
|
+
const children = node.children;
|
|
43
|
+
const elementName = openingElement.name;
|
|
44
|
+
const isFragment = (elementName.type === "JSXMemberExpression" &&
|
|
45
|
+
elementName.object.name === "React" &&
|
|
46
|
+
elementName.property.name === "Fragment") ||
|
|
47
|
+
(elementName.type === "JSXIdentifier" &&
|
|
48
|
+
elementName.name === "Fragment");
|
|
49
|
+
if (isFragment) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const line = openingElement.loc?.start?.line ?? 0;
|
|
53
|
+
const col = openingElement.loc?.start?.column ?? 0;
|
|
54
|
+
const dataComponentId = `${relativePath}|${line}|${col}`;
|
|
55
|
+
let attributes = ` data-zite-id="${dataComponentId}"`;
|
|
56
|
+
const componentName = getComponentName(openingElement.name);
|
|
57
|
+
if (componentName && !isNativeElement(componentName)) {
|
|
58
|
+
attributes += ` data-zite-component="${componentName}"`;
|
|
59
|
+
}
|
|
60
|
+
if (children.length === 1 &&
|
|
61
|
+
(children[0].type === "JSXText" ||
|
|
62
|
+
children[0].type === "StringLiteral" ||
|
|
63
|
+
(children[0].type === "JSXExpressionContainer" &&
|
|
64
|
+
children[0].expression.type === "StringLiteral"))) {
|
|
65
|
+
attributes += ` data-zite-editable="true"`;
|
|
66
|
+
}
|
|
67
|
+
magicString.appendLeft(openingElement.name.end ?? 0, attributes);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
code: magicString.toString(),
|
|
73
|
+
map: magicString.generateMap({ hires: true }),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(`Error processing file ${relativePath}:`, error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.73",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -76,6 +76,12 @@
|
|
|
76
76
|
"types": "./dist/esm/sync/index.d.ts",
|
|
77
77
|
"import": "./dist/esm/sync/index.js",
|
|
78
78
|
"require": "./dist/cjs/sync/index.js"
|
|
79
|
+
},
|
|
80
|
+
"./vite-plugin": {
|
|
81
|
+
"types": "./dist/esm/vite/index.d.ts",
|
|
82
|
+
"import": "./dist/esm/vite/index.js",
|
|
83
|
+
"require": "./dist/cjs/vite/index.js",
|
|
84
|
+
"default": "./dist/esm/vite/index.js"
|
|
79
85
|
}
|
|
80
86
|
},
|
|
81
87
|
"scripts": {
|
|
@@ -125,12 +131,16 @@
|
|
|
125
131
|
],
|
|
126
132
|
"meta": [
|
|
127
133
|
"dist/esm/meta/index.d.ts"
|
|
134
|
+
],
|
|
135
|
+
"vite-plugin": [
|
|
136
|
+
"dist/esm/vite/index.d.ts"
|
|
128
137
|
]
|
|
129
138
|
}
|
|
130
139
|
},
|
|
131
140
|
"peerDependencies": {
|
|
132
141
|
"@tanstack/react-query": ">=5",
|
|
133
|
-
"react": ">=18"
|
|
142
|
+
"react": ">=18",
|
|
143
|
+
"vite": ">=5"
|
|
134
144
|
},
|
|
135
145
|
"peerDependenciesMeta": {
|
|
136
146
|
"react": {
|
|
@@ -138,6 +148,9 @@
|
|
|
138
148
|
},
|
|
139
149
|
"@tanstack/react-query": {
|
|
140
150
|
"optional": true
|
|
151
|
+
},
|
|
152
|
+
"vite": {
|
|
153
|
+
"optional": true
|
|
141
154
|
}
|
|
142
155
|
},
|
|
143
156
|
"devDependencies": {
|
|
@@ -164,6 +177,8 @@
|
|
|
164
177
|
"@babel/parser": "^7.29.7",
|
|
165
178
|
"dotenv": "^17.4.2",
|
|
166
179
|
"esbuild": "^0.28.0",
|
|
180
|
+
"estree-walker": "^3.0.3",
|
|
181
|
+
"magic-string": "^0.30.17",
|
|
167
182
|
"zod": "^4.1.12"
|
|
168
183
|
}
|
|
169
184
|
}
|