@base44-preview/vite-plugin 0.2.27-pr.43.93e5e43 → 0.2.27-pr.44.b37fb09
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/capabilities/inline-edit/controller.d.ts.map +1 -1
- package/dist/capabilities/inline-edit/controller.js +9 -3
- package/dist/capabilities/inline-edit/controller.js.map +1 -1
- package/dist/capabilities/inline-edit/dom-utils.d.ts +1 -0
- package/dist/capabilities/inline-edit/dom-utils.d.ts.map +1 -1
- package/dist/capabilities/inline-edit/dom-utils.js +17 -7
- package/dist/capabilities/inline-edit/dom-utils.js.map +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +14 -4
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/jsx-processor.d.ts +1 -4
- package/dist/jsx-processor.d.ts.map +1 -1
- package/dist/jsx-processor.js +6 -33
- package/dist/jsx-processor.js.map +1 -1
- package/dist/jsx-utils.d.ts +0 -9
- package/dist/jsx-utils.d.ts.map +1 -1
- package/dist/jsx-utils.js +0 -86
- package/dist/jsx-utils.js.map +1 -1
- package/dist/processors/shared-utils.d.ts +0 -77
- package/dist/processors/shared-utils.d.ts.map +1 -1
- package/dist/processors/shared-utils.js +0 -525
- package/dist/processors/shared-utils.js.map +1 -1
- package/dist/processors/static-array-processor.d.ts +3 -2
- package/dist/processors/static-array-processor.d.ts.map +1 -1
- package/dist/processors/static-array-processor.js +3 -2
- package/dist/processors/static-array-processor.js.map +1 -1
- package/dist/statics/index.mjs +2 -2
- package/dist/statics/index.mjs.map +1 -1
- package/dist/visual-edit-plugin.d.ts +1 -0
- package/dist/visual-edit-plugin.d.ts.map +1 -1
- package/dist/visual-edit-plugin.js +178 -29
- package/dist/visual-edit-plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/inline-edit/controller.ts +35 -29
- package/src/capabilities/inline-edit/dom-utils.ts +14 -4
- package/src/injections/visual-edit-agent.ts +20 -4
- package/src/jsx-processor.ts +14 -41
- package/src/jsx-utils.ts +0 -116
- package/src/processors/shared-utils.ts +0 -671
- package/src/processors/static-array-processor.ts +3 -6
- package/src/visual-edit-plugin.ts +215 -34
- package/dist/consts.d.ts +0 -12
- package/dist/consts.d.ts.map +0 -1
- package/dist/consts.js +0 -12
- package/dist/consts.js.map +0 -1
- package/dist/processors/collection-id-processor.d.ts +0 -20
- package/dist/processors/collection-id-processor.d.ts.map +0 -1
- package/dist/processors/collection-id-processor.js +0 -182
- package/dist/processors/collection-id-processor.js.map +0 -1
- package/dist/processors/collection-item-field-processor.d.ts +0 -39
- package/dist/processors/collection-item-field-processor.d.ts.map +0 -1
- package/dist/processors/collection-item-field-processor.js +0 -281
- package/dist/processors/collection-item-field-processor.js.map +0 -1
- package/dist/processors/collection-item-id-processor.d.ts +0 -12
- package/dist/processors/collection-item-id-processor.d.ts.map +0 -1
- package/dist/processors/collection-item-id-processor.js +0 -50
- package/dist/processors/collection-item-id-processor.js.map +0 -1
- package/dist/processors/collection-reference-field-processor.d.ts +0 -31
- package/dist/processors/collection-reference-field-processor.d.ts.map +0 -1
- package/dist/processors/collection-reference-field-processor.js +0 -174
- package/dist/processors/collection-reference-field-processor.js.map +0 -1
- package/dist/processors/collection-tracing-utils.d.ts +0 -36
- package/dist/processors/collection-tracing-utils.d.ts.map +0 -1
- package/dist/processors/collection-tracing-utils.js +0 -390
- package/dist/processors/collection-tracing-utils.js.map +0 -1
- package/dist/types.d.ts +0 -5
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/consts.ts +0 -12
- package/src/processors/collection-id-processor.ts +0 -261
- package/src/processors/collection-item-field-processor.ts +0 -433
- package/src/processors/collection-item-id-processor.ts +0 -69
- package/src/processors/collection-reference-field-processor.ts +0 -225
- package/src/processors/collection-tracing-utils.ts +0 -507
- package/src/types.ts +0 -4
|
@@ -2,27 +2,175 @@ import { parse } from "@babel/parser";
|
|
|
2
2
|
import { default as traverse } from "@babel/traverse";
|
|
3
3
|
import { default as generate } from "@babel/generator";
|
|
4
4
|
import * as t from "@babel/types";
|
|
5
|
-
import {
|
|
5
|
+
import { StaticArrayProcessor } from "./processors/static-array-processor.js";
|
|
6
6
|
import { JSXUtils } from "./jsx-utils.js";
|
|
7
|
+
// Helper function to check if JSX element contains dynamic content
|
|
8
|
+
export function checkIfElementHasDynamicContent(jsxElement) {
|
|
9
|
+
let hasDynamicContent = false;
|
|
10
|
+
// Helper function to check if any node contains dynamic patterns
|
|
11
|
+
function checkNodeForDynamicContent(node) {
|
|
12
|
+
// JSX expressions like {variable}, {func()}, {obj.prop}
|
|
13
|
+
if (t.isJSXExpressionContainer(node)) {
|
|
14
|
+
const expression = node.expression;
|
|
15
|
+
// Skip empty expressions {}
|
|
16
|
+
if (t.isJSXEmptyExpression(expression)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
// Any non-literal expression is considered dynamic
|
|
20
|
+
if (!t.isLiteral(expression)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Template literals with expressions `Hello ${name}`
|
|
25
|
+
if (t.isTemplateLiteral(node) && node.expressions.length > 0) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
// Member expressions like props.title, state.value
|
|
29
|
+
if (t.isMemberExpression(node)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
// Function calls like getData(), format()
|
|
33
|
+
if (t.isCallExpression(node)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
// Conditional expressions like condition ? "yes" : "no"
|
|
37
|
+
if (t.isConditionalExpression(node)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
// Identifier references (could be props, state, variables)
|
|
41
|
+
if (t.isIdentifier(node)) {
|
|
42
|
+
// Common dynamic identifiers
|
|
43
|
+
const dynamicNames = [
|
|
44
|
+
"props",
|
|
45
|
+
"state",
|
|
46
|
+
"data",
|
|
47
|
+
"item",
|
|
48
|
+
"value",
|
|
49
|
+
"text",
|
|
50
|
+
"content",
|
|
51
|
+
];
|
|
52
|
+
if (dynamicNames.some((name) => node.name.includes(name))) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// Recursively traverse all child nodes
|
|
59
|
+
function traverseNode(node) {
|
|
60
|
+
if (checkNodeForDynamicContent(node)) {
|
|
61
|
+
hasDynamicContent = true;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Recursively check child nodes
|
|
65
|
+
Object.keys(node).forEach((key) => {
|
|
66
|
+
const value = node[key];
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
value.forEach((child) => {
|
|
69
|
+
if (child && typeof child === "object" && child.type) {
|
|
70
|
+
traverseNode(child);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else if (value && typeof value === "object" && value.type) {
|
|
75
|
+
traverseNode(value);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// Check the element's own attributes for dynamic content
|
|
80
|
+
const attributes = jsxElement.openingElement?.attributes || [];
|
|
81
|
+
attributes.forEach((attr) => {
|
|
82
|
+
if (hasDynamicContent)
|
|
83
|
+
return; // Early exit if already found dynamic content
|
|
84
|
+
// Spread attributes like {...props} are always dynamic
|
|
85
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
86
|
+
hasDynamicContent = true;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// Check attribute values for dynamic expressions
|
|
90
|
+
if (t.isJSXAttribute(attr) && attr.value) {
|
|
91
|
+
traverseNode(attr.value);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
// Check all children of the JSX element
|
|
95
|
+
jsxElement.children.forEach((child) => {
|
|
96
|
+
if (hasDynamicContent)
|
|
97
|
+
return; // Early exit if already found dynamic content
|
|
98
|
+
traverseNode(child);
|
|
99
|
+
});
|
|
100
|
+
return hasDynamicContent;
|
|
101
|
+
}
|
|
7
102
|
export function visualEditPlugin() {
|
|
8
103
|
return {
|
|
9
104
|
name: "visual-edit-transform",
|
|
10
105
|
apply: (config) => config.mode === "development",
|
|
11
106
|
enforce: "pre",
|
|
12
107
|
order: "pre",
|
|
108
|
+
// Inject Tailwind CDN for visual editing capabilities
|
|
13
109
|
transformIndexHtml(html) {
|
|
110
|
+
// Inject the Tailwind CSS CDN script right before the closing </head> tag
|
|
14
111
|
const tailwindScript = ` <!-- Tailwind CSS CDN for visual editing -->\n <script src="https://cdn.tailwindcss.com"></script>\n `;
|
|
15
112
|
return html.replace("</head>", tailwindScript + "</head>");
|
|
16
113
|
},
|
|
17
114
|
transform(code, id) {
|
|
115
|
+
// Skip node_modules and visual-edit-agent itself
|
|
18
116
|
if (id.includes("node_modules") || id.includes("visual-edit-agent")) {
|
|
19
117
|
return null;
|
|
20
118
|
}
|
|
119
|
+
// Process JS/JSX/TS/TSX files
|
|
21
120
|
if (!id.match(/\.(jsx?|tsx?)$/)) {
|
|
22
121
|
return null;
|
|
23
122
|
}
|
|
24
|
-
|
|
123
|
+
// Extract filename from path, preserving pages/ or components/ structure
|
|
124
|
+
const pathParts = id.split("/");
|
|
125
|
+
let filename;
|
|
126
|
+
// Check if this is a pages or components file
|
|
127
|
+
if (id.includes("/pages/")) {
|
|
128
|
+
const pagesIndex = pathParts.findIndex((part) => part === "pages");
|
|
129
|
+
if (pagesIndex >= 0 && pagesIndex < pathParts.length - 1) {
|
|
130
|
+
// Get all parts from 'pages' to the file, preserving nested structure
|
|
131
|
+
const relevantParts = pathParts.slice(pagesIndex, pathParts.length);
|
|
132
|
+
const lastPart = relevantParts[relevantParts.length - 1];
|
|
133
|
+
// Remove file extension from the last part
|
|
134
|
+
relevantParts[relevantParts.length - 1] = lastPart.includes(".")
|
|
135
|
+
? lastPart.split(".")[0]
|
|
136
|
+
: lastPart;
|
|
137
|
+
filename = relevantParts.join("/");
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
filename = pathParts[pathParts.length - 1];
|
|
141
|
+
if (filename.includes(".")) {
|
|
142
|
+
filename = filename.split(".")[0];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (id.includes("/components/")) {
|
|
147
|
+
const componentsIndex = pathParts.findIndex((part) => part === "components");
|
|
148
|
+
if (componentsIndex >= 0 && componentsIndex < pathParts.length - 1) {
|
|
149
|
+
// Get all parts from 'components' to the file, preserving nested structure
|
|
150
|
+
const relevantParts = pathParts.slice(componentsIndex, pathParts.length);
|
|
151
|
+
const lastPart = relevantParts[relevantParts.length - 1];
|
|
152
|
+
// Remove file extension from the last part
|
|
153
|
+
relevantParts[relevantParts.length - 1] = lastPart.includes(".")
|
|
154
|
+
? lastPart.split(".")[0]
|
|
155
|
+
: lastPart;
|
|
156
|
+
filename = relevantParts.join("/");
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
filename = pathParts[pathParts.length - 1];
|
|
160
|
+
if (filename.includes(".")) {
|
|
161
|
+
filename = filename.split(".")[0];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// For other files (like layout), just use the filename
|
|
167
|
+
filename = pathParts[pathParts.length - 1];
|
|
168
|
+
if (filename.includes(".")) {
|
|
169
|
+
filename = filename.split(".")[0];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
25
172
|
try {
|
|
173
|
+
// Parse the code into an AST
|
|
26
174
|
const ast = parse(code, {
|
|
27
175
|
sourceType: "module",
|
|
28
176
|
plugins: [
|
|
@@ -43,16 +191,41 @@ export function visualEditPlugin() {
|
|
|
43
191
|
"throwExpressions",
|
|
44
192
|
],
|
|
45
193
|
});
|
|
194
|
+
// Traverse the AST and add source location and dynamic content attributes to JSX elements
|
|
46
195
|
JSXUtils.init(t);
|
|
47
|
-
const
|
|
196
|
+
const staticArrayProcessor = new StaticArrayProcessor(t);
|
|
197
|
+
let elementsProcessed = 0;
|
|
48
198
|
traverse.default(ast, {
|
|
49
199
|
JSXElement(path) {
|
|
50
200
|
const jsxElement = path.node;
|
|
201
|
+
const openingElement = jsxElement.openingElement;
|
|
202
|
+
// Skip fragments
|
|
51
203
|
if (t.isJSXFragment(jsxElement))
|
|
52
204
|
return;
|
|
53
|
-
|
|
205
|
+
// Skip if already has source location attribute
|
|
206
|
+
const hasSourceLocation = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
|
|
207
|
+
t.isJSXIdentifier(attr.name) &&
|
|
208
|
+
attr.name.name === "data-source-location");
|
|
209
|
+
if (hasSourceLocation)
|
|
210
|
+
return;
|
|
211
|
+
// Get line and column from AST node location
|
|
212
|
+
const { line, column } = openingElement.loc?.start || {
|
|
213
|
+
line: 1,
|
|
214
|
+
column: 0,
|
|
215
|
+
};
|
|
216
|
+
// Create the source location attribute
|
|
217
|
+
const sourceLocationAttr = t.jsxAttribute(t.jsxIdentifier("data-source-location"), t.stringLiteral(`${filename}:${line}:${column}`));
|
|
218
|
+
// Check if element has dynamic content
|
|
219
|
+
const isDynamic = checkIfElementHasDynamicContent(jsxElement);
|
|
220
|
+
// Create the dynamic content attribute
|
|
221
|
+
const dynamicContentAttr = t.jsxAttribute(t.jsxIdentifier("data-dynamic-content"), t.stringLiteral(isDynamic ? "true" : "false"));
|
|
222
|
+
// Add both attributes to the beginning of the attributes array
|
|
223
|
+
openingElement.attributes.unshift(sourceLocationAttr, dynamicContentAttr);
|
|
224
|
+
staticArrayProcessor.process(path.get("openingElement"));
|
|
225
|
+
elementsProcessed++;
|
|
54
226
|
},
|
|
55
227
|
});
|
|
228
|
+
// Generate the code back from the AST
|
|
56
229
|
const result = generate.default(ast, {
|
|
57
230
|
compact: false,
|
|
58
231
|
concise: false,
|
|
@@ -66,35 +239,11 @@ export function visualEditPlugin() {
|
|
|
66
239
|
catch (error) {
|
|
67
240
|
console.error("Failed to add source location to JSX:", error);
|
|
68
241
|
return {
|
|
69
|
-
code: code,
|
|
242
|
+
code: code, // Return original code on failure
|
|
70
243
|
map: null,
|
|
71
244
|
};
|
|
72
245
|
}
|
|
73
246
|
},
|
|
74
247
|
};
|
|
75
248
|
}
|
|
76
|
-
function extractFilename(id) {
|
|
77
|
-
const pathParts = id.split("/");
|
|
78
|
-
const segmentIndex = findSegmentIndex(pathParts, ["pages", "components"]);
|
|
79
|
-
if (segmentIndex >= 0 && segmentIndex < pathParts.length - 1) {
|
|
80
|
-
const relevantParts = pathParts.slice(segmentIndex);
|
|
81
|
-
const last = relevantParts[relevantParts.length - 1];
|
|
82
|
-
relevantParts[relevantParts.length - 1] = stripExtension(last ?? "");
|
|
83
|
-
return relevantParts.join("/");
|
|
84
|
-
}
|
|
85
|
-
const lastPart = pathParts[pathParts.length - 1] ?? "";
|
|
86
|
-
return stripExtension(lastPart);
|
|
87
|
-
}
|
|
88
|
-
function findSegmentIndex(parts, segments) {
|
|
89
|
-
for (const segment of segments) {
|
|
90
|
-
const idx = parts.findIndex((part) => part === segment);
|
|
91
|
-
if (idx >= 0)
|
|
92
|
-
return idx;
|
|
93
|
-
}
|
|
94
|
-
return -1;
|
|
95
|
-
}
|
|
96
|
-
function stripExtension(filename) {
|
|
97
|
-
const dotIndex = filename.indexOf(".");
|
|
98
|
-
return dotIndex >= 0 ? filename.substring(0, dotIndex) : filename;
|
|
99
|
-
}
|
|
100
249
|
//# sourceMappingURL=visual-edit-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visual-edit-plugin.js","sourceRoot":"","sources":["../src/visual-edit-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KA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WAAW,EAAE,IAAI;iBAClB,CAAC,CAAC;gBAEH,OAAO;oBACL,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,GAAG,EAAE,IAAI;iBACV,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;gBAC9D,OAAO;oBACL,IAAI,EAAE,IAAI,EAAE,kCAAkC;oBAC9C,GAAG,EAAE,IAAI;iBACV,CAAC;YACJ,CAAC;QACH,CAAC;KACQ,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
removeFocusOutlineCSS,
|
|
5
5
|
selectText,
|
|
6
6
|
shouldEnterInlineEditingMode,
|
|
7
|
+
isStaticArrayTextElement,
|
|
7
8
|
} from "./dom-utils.js";
|
|
8
9
|
|
|
9
10
|
const DEBOUNCE_MS = 500;
|
|
@@ -37,37 +38,42 @@ export function createInlineEditController(
|
|
|
37
38
|
const svgElement = element as unknown as SVGElement;
|
|
38
39
|
const rect = element.getBoundingClientRect();
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
centerY: rect.top + rect.height / 2,
|
|
64
|
-
},
|
|
41
|
+
const message: Record<string, unknown> = {
|
|
42
|
+
type: "inline-edit",
|
|
43
|
+
elementInfo: {
|
|
44
|
+
tagName: element.tagName,
|
|
45
|
+
classes:
|
|
46
|
+
(svgElement.className as unknown as SVGAnimatedString)?.baseVal ||
|
|
47
|
+
element.className ||
|
|
48
|
+
"",
|
|
49
|
+
visualSelectorId: host.getSelectedElementId(),
|
|
50
|
+
content: newContent,
|
|
51
|
+
dataSourceLocation: element.dataset.sourceLocation,
|
|
52
|
+
isDynamicContent: element.dataset.dynamicContent === "true",
|
|
53
|
+
linenumber: element.dataset.linenumber,
|
|
54
|
+
filename: element.dataset.filename,
|
|
55
|
+
position: {
|
|
56
|
+
top: rect.top,
|
|
57
|
+
left: rect.left,
|
|
58
|
+
right: rect.right,
|
|
59
|
+
bottom: rect.bottom,
|
|
60
|
+
width: rect.width,
|
|
61
|
+
height: rect.height,
|
|
62
|
+
centerX: rect.left + rect.width / 2,
|
|
63
|
+
centerY: rect.top + rect.height / 2,
|
|
65
64
|
},
|
|
66
|
-
originalContent,
|
|
67
|
-
newContent,
|
|
68
65
|
},
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
originalContent,
|
|
67
|
+
newContent,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (isStaticArrayTextElement(element)) {
|
|
71
|
+
message.arrIndex = element.dataset.arrIndex;
|
|
72
|
+
message.arrVariableName = element.dataset.arrVariableName;
|
|
73
|
+
message.arrField = element.dataset.arrField;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
window.parent.postMessage(message, "*");
|
|
71
77
|
|
|
72
78
|
element.dataset.originalTextContent = newContent || "";
|
|
73
79
|
};
|
|
@@ -5,6 +5,18 @@ const EDITABLE_TAGS = [
|
|
|
5
5
|
"span", "li", "td", "a", "button", "label",
|
|
6
6
|
];
|
|
7
7
|
|
|
8
|
+
export const isStaticArrayTextElement = (element: HTMLElement): boolean => {
|
|
9
|
+
return !!element.dataset.arrField;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const passesStructuralChecks = (element: HTMLElement): boolean => {
|
|
13
|
+
if (!EDITABLE_TAGS.includes(element.tagName.toLowerCase())) return false;
|
|
14
|
+
if (!element.textContent?.trim()) return false;
|
|
15
|
+
if (element.querySelector("img, video, canvas, svg")) return false;
|
|
16
|
+
if (element.children?.length > 0) return false;
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
|
|
8
20
|
export const injectFocusOutlineCSS = () => {
|
|
9
21
|
if (document.getElementById(FOCUS_STYLE_ID)) return;
|
|
10
22
|
|
|
@@ -32,10 +44,8 @@ export const selectText = (element: HTMLElement) => {
|
|
|
32
44
|
|
|
33
45
|
export const isEditableTextElement = (element: Element): boolean => {
|
|
34
46
|
if (!(element instanceof HTMLElement)) return false;
|
|
35
|
-
if (!
|
|
36
|
-
if (
|
|
37
|
-
if (element.querySelector("img, video, canvas, svg")) return false;
|
|
38
|
-
if (element.children?.length > 0) return false;
|
|
47
|
+
if (!passesStructuralChecks(element)) return false;
|
|
48
|
+
if (isStaticArrayTextElement(element)) return true;
|
|
39
49
|
if (element.dataset.dynamicContent === "true") return false;
|
|
40
50
|
return true;
|
|
41
51
|
};
|
|
@@ -127,6 +127,13 @@ export function setupVisualEditAgent() {
|
|
|
127
127
|
const rect = element.getBoundingClientRect();
|
|
128
128
|
const svgElement = element as SVGElement;
|
|
129
129
|
const isTextElement = TEXT_TAGS.includes(element.tagName?.toLowerCase());
|
|
130
|
+
|
|
131
|
+
const arrEl = htmlElement.closest("[data-arr-variable-name]") as HTMLElement | null;
|
|
132
|
+
const staticArrayName = arrEl?.dataset?.arrVariableName || null;
|
|
133
|
+
const rawIdx = arrEl?.dataset?.arrIndex;
|
|
134
|
+
const staticArrayIndex = rawIdx != null ? parseInt(rawIdx, 10) : null;
|
|
135
|
+
const staticArrayField = htmlElement.dataset?.arrField || null;
|
|
136
|
+
|
|
130
137
|
window.parent.postMessage({
|
|
131
138
|
type: "element-selected",
|
|
132
139
|
tagName: element.tagName,
|
|
@@ -152,6 +159,9 @@ export function setupVisualEditAgent() {
|
|
|
152
159
|
},
|
|
153
160
|
attributes: collectAllowedAttributes(element, ALLOWED_ATTRIBUTES),
|
|
154
161
|
isTextElement,
|
|
162
|
+
staticArrayName,
|
|
163
|
+
staticArrayIndex,
|
|
164
|
+
staticArrayField,
|
|
155
165
|
}, "*");
|
|
156
166
|
};
|
|
157
167
|
|
|
@@ -378,14 +388,19 @@ export function setupVisualEditAgent() {
|
|
|
378
388
|
}, REPOSITION_DELAY_MS);
|
|
379
389
|
};
|
|
380
390
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const elements = findElementsById(visualSelectorId);
|
|
391
|
+
const updateElementContent = (visualSelectorId: string, content: string, arrIndex?: number) => {
|
|
392
|
+
let elements = findElementsById(visualSelectorId);
|
|
384
393
|
|
|
385
394
|
if (elements.length === 0) {
|
|
386
395
|
return;
|
|
387
396
|
}
|
|
388
397
|
|
|
398
|
+
if (arrIndex != null) {
|
|
399
|
+
elements = elements.filter(
|
|
400
|
+
(el) => (el as HTMLElement).dataset.arrIndex === String(arrIndex)
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
389
404
|
elements.forEach((element) => {
|
|
390
405
|
(element as HTMLElement).innerText = content;
|
|
391
406
|
});
|
|
@@ -537,7 +552,8 @@ export function setupVisualEditAgent() {
|
|
|
537
552
|
if (message.data && message.data.content !== undefined) {
|
|
538
553
|
updateElementContent(
|
|
539
554
|
message.data.visualSelectorId,
|
|
540
|
-
message.data.content
|
|
555
|
+
message.data.content,
|
|
556
|
+
message.data.arrIndex
|
|
541
557
|
);
|
|
542
558
|
} else {
|
|
543
559
|
console.warn(
|
package/src/jsx-processor.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
import type { NodePath } from "@babel/traverse";
|
|
2
2
|
import type * as t from "@babel/types";
|
|
3
|
-
import { CollectionIdProcessor } from "./processors/collection-id-processor.js";
|
|
4
|
-
import { ReferenceFieldProcessor } from "./processors/collection-reference-field-processor.js";
|
|
5
|
-
import { DataItemIdProcessor } from "./processors/collection-item-id-processor.js";
|
|
6
|
-
import { DataItemFieldProcessor } from "./processors/collection-item-field-processor.js";
|
|
7
3
|
import { StaticArrayProcessor } from "./processors/static-array-processor.js";
|
|
8
4
|
|
|
9
5
|
export class JSXProcessor {
|
|
10
|
-
private collectionIdProcessor: CollectionIdProcessor;
|
|
11
|
-
private referenceFieldProcessor: ReferenceFieldProcessor;
|
|
12
|
-
private dataItemIdProcessor: DataItemIdProcessor;
|
|
13
|
-
private dataItemFieldProcessor: DataItemFieldProcessor;
|
|
14
6
|
private staticArrayProcessor: StaticArrayProcessor;
|
|
15
7
|
|
|
16
8
|
constructor(
|
|
17
9
|
private types: typeof t,
|
|
18
10
|
private filename: string
|
|
19
11
|
) {
|
|
20
|
-
this.collectionIdProcessor = new CollectionIdProcessor(types);
|
|
21
|
-
this.referenceFieldProcessor = new ReferenceFieldProcessor(types);
|
|
22
|
-
this.dataItemIdProcessor = new DataItemIdProcessor(types);
|
|
23
|
-
this.dataItemFieldProcessor = new DataItemFieldProcessor(types);
|
|
24
12
|
this.staticArrayProcessor = new StaticArrayProcessor(types);
|
|
25
13
|
}
|
|
26
14
|
|
|
@@ -29,13 +17,8 @@ export class JSXProcessor {
|
|
|
29
17
|
|
|
30
18
|
this.addSourceLocationAttribute(path);
|
|
31
19
|
this.addDynamicContentAttribute(path);
|
|
32
|
-
|
|
33
|
-
this.collectionIdProcessor.process(path);
|
|
34
|
-
this.referenceFieldProcessor.process(path);
|
|
35
|
-
this.dataItemIdProcessor.process(path);
|
|
36
|
-
this.dataItemFieldProcessor.process(path);
|
|
20
|
+
this.addContentEditableAttribute(path);
|
|
37
21
|
this.staticArrayProcessor.process(path);
|
|
38
|
-
|
|
39
22
|
}
|
|
40
23
|
|
|
41
24
|
private addSourceLocationAttribute(
|
|
@@ -44,7 +27,7 @@ export class JSXProcessor {
|
|
|
44
27
|
const { line, column } = path.node.loc?.start || { line: 1, column: 0 };
|
|
45
28
|
const value = `${this.filename}:${line}:${column}`;
|
|
46
29
|
|
|
47
|
-
path.node.attributes.
|
|
30
|
+
path.node.attributes.push(
|
|
48
31
|
this.types.jsxAttribute(
|
|
49
32
|
this.types.jsxIdentifier("data-source-location"),
|
|
50
33
|
this.types.stringLiteral(value)
|
|
@@ -62,16 +45,7 @@ export class JSXProcessor {
|
|
|
62
45
|
parentElement.node as t.JSXElement
|
|
63
46
|
);
|
|
64
47
|
|
|
65
|
-
|
|
66
|
-
(attr) =>
|
|
67
|
-
this.types.isJSXAttribute(attr) &&
|
|
68
|
-
this.types.isJSXIdentifier(attr.name) &&
|
|
69
|
-
attr.name.name === "data-source-location"
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
path.node.attributes.splice(
|
|
73
|
-
sourceLocIdx + 1,
|
|
74
|
-
0,
|
|
48
|
+
path.node.attributes.push(
|
|
75
49
|
this.types.jsxAttribute(
|
|
76
50
|
this.types.jsxIdentifier("data-dynamic-content"),
|
|
77
51
|
this.types.stringLiteral(isDynamic ? "true" : "false")
|
|
@@ -79,6 +53,17 @@ export class JSXProcessor {
|
|
|
79
53
|
);
|
|
80
54
|
}
|
|
81
55
|
|
|
56
|
+
private addContentEditableAttribute(
|
|
57
|
+
path: NodePath<t.JSXOpeningElement>
|
|
58
|
+
): void {
|
|
59
|
+
path.node.attributes.push(
|
|
60
|
+
this.types.jsxAttribute(
|
|
61
|
+
this.types.jsxIdentifier("content-editable"),
|
|
62
|
+
this.types.stringLiteral("true")
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
82
67
|
private hasAttribute(
|
|
83
68
|
path: NodePath<t.JSXOpeningElement>,
|
|
84
69
|
name: string
|
|
@@ -152,18 +137,6 @@ export class JSXProcessor {
|
|
|
152
137
|
}
|
|
153
138
|
};
|
|
154
139
|
|
|
155
|
-
const attributes = jsxElement.openingElement?.attributes || [];
|
|
156
|
-
for (const attr of attributes) {
|
|
157
|
-
if (hasDynamicContent) break;
|
|
158
|
-
if (this.types.isJSXSpreadAttribute(attr)) {
|
|
159
|
-
hasDynamicContent = true;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
if (this.types.isJSXAttribute(attr) && attr.value) {
|
|
163
|
-
traverseNode(attr.value as unknown as Record<string, unknown>);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
140
|
for (const child of jsxElement.children) {
|
|
168
141
|
if (hasDynamicContent) break;
|
|
169
142
|
traverseNode(child as unknown as Record<string, unknown>);
|