@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
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from "@babel/traverse";
|
|
2
|
-
import type * as t from "@babel/types";
|
|
3
|
-
import { DATA_COLLECTION_ITEM_ID } from "../consts.js";
|
|
4
|
-
import {
|
|
5
|
-
JSXAttributeUtils,
|
|
6
|
-
ExpressionAnalysisUtils,
|
|
7
|
-
} from "./shared-utils.js";
|
|
8
|
-
|
|
9
|
-
export class DataItemIdProcessor {
|
|
10
|
-
private attributeUtils: JSXAttributeUtils;
|
|
11
|
-
private expressionUtils: ExpressionAnalysisUtils;
|
|
12
|
-
|
|
13
|
-
constructor(private types: typeof t) {
|
|
14
|
-
this.attributeUtils = new JSXAttributeUtils(types);
|
|
15
|
-
this.expressionUtils = new ExpressionAnalysisUtils(types);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
process(path: NodePath<t.JSXOpeningElement>): void {
|
|
19
|
-
if (this.attributeUtils.hasAttribute(path, DATA_COLLECTION_ITEM_ID)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const keyAttr = this.findKeyAttribute(path);
|
|
24
|
-
if (!keyAttr) return;
|
|
25
|
-
|
|
26
|
-
const expression = this.extractKeyExpression(keyAttr);
|
|
27
|
-
if (!expression) return;
|
|
28
|
-
|
|
29
|
-
if (!this.expressionUtils.isIdAccess(expression)) return;
|
|
30
|
-
|
|
31
|
-
const optionalExpr = this.types.isMemberExpression(expression)
|
|
32
|
-
? this.expressionUtils.createOptionalChainExpression(expression)
|
|
33
|
-
: expression;
|
|
34
|
-
|
|
35
|
-
this.attributeUtils.addExpressionAttribute(
|
|
36
|
-
path,
|
|
37
|
-
DATA_COLLECTION_ITEM_ID,
|
|
38
|
-
optionalExpr
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private findKeyAttribute(
|
|
43
|
-
path: NodePath<t.JSXOpeningElement>
|
|
44
|
-
): t.JSXAttribute | null {
|
|
45
|
-
for (const attr of path.node.attributes) {
|
|
46
|
-
if (
|
|
47
|
-
this.types.isJSXAttribute(attr) &&
|
|
48
|
-
this.types.isJSXIdentifier(attr.name) &&
|
|
49
|
-
attr.name.name === "key"
|
|
50
|
-
) {
|
|
51
|
-
return attr;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private extractKeyExpression(
|
|
58
|
-
attr: t.JSXAttribute
|
|
59
|
-
): t.Expression | null {
|
|
60
|
-
if (!attr.value) return null;
|
|
61
|
-
|
|
62
|
-
if (this.types.isJSXExpressionContainer(attr.value)) {
|
|
63
|
-
const expr = attr.value.expression;
|
|
64
|
-
if (this.types.isExpression(expr)) return expr;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from "@babel/traverse";
|
|
2
|
-
import type * as t from "@babel/types";
|
|
3
|
-
import {
|
|
4
|
-
DATA_COLLECTION_FIELD_REFERENCE,
|
|
5
|
-
DATA_COLLECTION_REFERENCE,
|
|
6
|
-
} from "../consts.js";
|
|
7
|
-
import {
|
|
8
|
-
JSXAttributeUtils,
|
|
9
|
-
ExpressionAnalysisUtils,
|
|
10
|
-
TypeCheckUtils,
|
|
11
|
-
} from "./shared-utils.js";
|
|
12
|
-
|
|
13
|
-
export class ReferenceFieldProcessor {
|
|
14
|
-
private attributeUtils: JSXAttributeUtils;
|
|
15
|
-
private expressionUtils: ExpressionAnalysisUtils;
|
|
16
|
-
private typeCheckUtils: TypeCheckUtils;
|
|
17
|
-
|
|
18
|
-
constructor(private types: typeof t) {
|
|
19
|
-
this.attributeUtils = new JSXAttributeUtils(types);
|
|
20
|
-
this.expressionUtils = new ExpressionAnalysisUtils(types);
|
|
21
|
-
this.typeCheckUtils = new TypeCheckUtils(types);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
process(path: NodePath<t.JSXOpeningElement>): void {
|
|
25
|
-
if (
|
|
26
|
-
this.attributeUtils.hasAttribute(path, DATA_COLLECTION_FIELD_REFERENCE)
|
|
27
|
-
) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
this.isReturnedFromReferenceMap(path) ||
|
|
33
|
-
this.isInsideReferenceLogicalExpression(path) ||
|
|
34
|
-
this.isInReferencePropertyMapChain(path)
|
|
35
|
-
) {
|
|
36
|
-
this.attributeUtils.addStringAttribute(
|
|
37
|
-
path,
|
|
38
|
-
DATA_COLLECTION_FIELD_REFERENCE,
|
|
39
|
-
"true"
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Strategy A: Element is the direct return of a .map() callback
|
|
46
|
-
* whose array is a reference variable (initialized via type-check pattern).
|
|
47
|
-
*/
|
|
48
|
-
private isReturnedFromReferenceMap(
|
|
49
|
-
path: NodePath<t.JSXOpeningElement>
|
|
50
|
-
): boolean {
|
|
51
|
-
const jsxElement = path.parentPath;
|
|
52
|
-
if (!jsxElement?.isJSXElement()) return false;
|
|
53
|
-
|
|
54
|
-
const parent = jsxElement.parentPath;
|
|
55
|
-
if (!parent) return false;
|
|
56
|
-
|
|
57
|
-
const callbackFn = this.findEnclosingMapCallback(parent);
|
|
58
|
-
if (!callbackFn) return false;
|
|
59
|
-
|
|
60
|
-
const mapCall = callbackFn.parentPath;
|
|
61
|
-
if (!mapCall?.isCallExpression()) return false;
|
|
62
|
-
|
|
63
|
-
const callee = mapCall.get("callee");
|
|
64
|
-
if (!callee.isMemberExpression()) return false;
|
|
65
|
-
|
|
66
|
-
const arrayObj = callee.get("object") as NodePath<t.Expression>;
|
|
67
|
-
return this.isReferenceArray(arrayObj);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Strategy B: Element is inside a && expression where the left operand
|
|
72
|
-
* references a field name that appears in an ancestor's data-collection-reference.
|
|
73
|
-
*/
|
|
74
|
-
private isInsideReferenceLogicalExpression(
|
|
75
|
-
path: NodePath<t.JSXOpeningElement>
|
|
76
|
-
): boolean {
|
|
77
|
-
const jsxElement = path.parentPath;
|
|
78
|
-
if (!jsxElement?.isJSXElement()) return false;
|
|
79
|
-
|
|
80
|
-
const logicalParent = jsxElement.parentPath;
|
|
81
|
-
if (!logicalParent?.isLogicalExpression()) return false;
|
|
82
|
-
if (logicalParent.node.operator !== "&&") return false;
|
|
83
|
-
|
|
84
|
-
const left = logicalParent.node.left;
|
|
85
|
-
const fieldName = this.extractFieldNameFromExpression(left as t.Expression);
|
|
86
|
-
if (!fieldName) return false;
|
|
87
|
-
|
|
88
|
-
return this.isFieldInAncestorReference(path, fieldName);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Strategy C: Element is inside a .map() chain on a reference property.
|
|
93
|
-
* e.g. item.relatedProducts.map(...) or item.relatedProducts.filter(...).map(...)
|
|
94
|
-
*/
|
|
95
|
-
private isInReferencePropertyMapChain(
|
|
96
|
-
path: NodePath<t.JSXOpeningElement>
|
|
97
|
-
): boolean {
|
|
98
|
-
const jsxElement = path.parentPath;
|
|
99
|
-
if (!jsxElement?.isJSXElement()) return false;
|
|
100
|
-
|
|
101
|
-
let current: NodePath | null = jsxElement;
|
|
102
|
-
while (current) {
|
|
103
|
-
if (current.isCallExpression()) {
|
|
104
|
-
const callee = current.get("callee");
|
|
105
|
-
if (callee.isMemberExpression()) {
|
|
106
|
-
const fieldName = this.extractReferenceFieldFromMapChain(callee);
|
|
107
|
-
if (fieldName && this.isFieldInAncestorReference(path, fieldName)) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
current = current.parentPath;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private findEnclosingMapCallback(
|
|
119
|
-
path: NodePath
|
|
120
|
-
): NodePath<t.Function> | null {
|
|
121
|
-
let current: NodePath | null = path;
|
|
122
|
-
while (current) {
|
|
123
|
-
if (current.isArrowFunctionExpression() || current.isFunctionExpression()) {
|
|
124
|
-
const parent = current.parentPath;
|
|
125
|
-
if (parent?.isCallExpression()) {
|
|
126
|
-
const callee = parent.get("callee");
|
|
127
|
-
if (callee.isMemberExpression()) {
|
|
128
|
-
const prop = callee.get("property") as NodePath;
|
|
129
|
-
if (
|
|
130
|
-
prop.isIdentifier() &&
|
|
131
|
-
(prop.node.name === "map" || prop.node.name === "flatMap")
|
|
132
|
-
) {
|
|
133
|
-
return current as NodePath<t.Function>;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
current = current.parentPath;
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private isReferenceArray(path: NodePath<t.Expression>): boolean {
|
|
144
|
-
if (!path.isIdentifier()) return false;
|
|
145
|
-
|
|
146
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
147
|
-
if (!binding?.path.isVariableDeclarator()) return false;
|
|
148
|
-
|
|
149
|
-
const init = binding.path.get("init");
|
|
150
|
-
if (!init.isConditionalExpression()) return false;
|
|
151
|
-
|
|
152
|
-
const test = init.node.test;
|
|
153
|
-
return this.typeCheckUtils.isReferenceTypeCheck(test as t.Expression);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private extractFieldNameFromExpression(
|
|
157
|
-
node: t.Expression
|
|
158
|
-
): string | null {
|
|
159
|
-
if (this.types.isMemberExpression(node)) {
|
|
160
|
-
const prop = node.property;
|
|
161
|
-
if (this.types.isIdentifier(prop)) return prop.name;
|
|
162
|
-
}
|
|
163
|
-
if (this.types.isOptionalMemberExpression(node)) {
|
|
164
|
-
const prop = node.property;
|
|
165
|
-
if (this.types.isIdentifier(prop)) return prop.name;
|
|
166
|
-
}
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private isFieldInAncestorReference(
|
|
171
|
-
path: NodePath,
|
|
172
|
-
fieldName: string
|
|
173
|
-
): boolean {
|
|
174
|
-
const ancestor = this.attributeUtils.findAncestorWithAttribute(
|
|
175
|
-
path,
|
|
176
|
-
DATA_COLLECTION_REFERENCE
|
|
177
|
-
);
|
|
178
|
-
if (!ancestor) return false;
|
|
179
|
-
|
|
180
|
-
const refValue = this.attributeUtils.getAttributeStringValue(
|
|
181
|
-
ancestor,
|
|
182
|
-
DATA_COLLECTION_REFERENCE
|
|
183
|
-
);
|
|
184
|
-
if (!refValue) return false;
|
|
185
|
-
|
|
186
|
-
const references = refValue.split(",").map((r) => r.trim());
|
|
187
|
-
return references.includes(fieldName);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
private extractReferenceFieldFromMapChain(
|
|
191
|
-
callee: NodePath<t.MemberExpression>
|
|
192
|
-
): string | null {
|
|
193
|
-
const prop = callee.get("property") as NodePath;
|
|
194
|
-
if (!prop.isIdentifier()) return null;
|
|
195
|
-
|
|
196
|
-
const methodName = prop.node.name;
|
|
197
|
-
const obj = callee.get("object") as NodePath<t.Expression>;
|
|
198
|
-
|
|
199
|
-
if (methodName === "map" || methodName === "flatMap") {
|
|
200
|
-
if (obj.isMemberExpression()) {
|
|
201
|
-
const fieldProp = obj.get("property") as NodePath;
|
|
202
|
-
if (fieldProp.isIdentifier()) return fieldProp.node.name;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (methodName === "map" || methodName === "flatMap") {
|
|
207
|
-
if (obj.isCallExpression()) {
|
|
208
|
-
const innerCallee = obj.get("callee");
|
|
209
|
-
if (innerCallee.isMemberExpression()) {
|
|
210
|
-
return this.extractReferenceFieldFromMapChain(innerCallee);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
["filter", "sort", "slice"].includes(methodName) &&
|
|
217
|
-
obj.isMemberExpression()
|
|
218
|
-
) {
|
|
219
|
-
const fieldProp = obj.get("property") as NodePath;
|
|
220
|
-
if (fieldProp.isIdentifier()) return fieldProp.node.name;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
}
|