@base44/vite-plugin 1.0.19 → 1.0.21
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/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/injections/utils.d.ts +1 -1
- package/dist/injections/utils.d.ts.map +1 -1
- package/dist/injections/utils.js +6 -2
- package/dist/injections/utils.js.map +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +7 -3
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/processors/static-array-processor.d.ts +1 -0
- package/dist/processors/static-array-processor.d.ts.map +1 -1
- package/dist/processors/static-array-processor.js +28 -2
- package/dist/processors/static-array-processor.js.map +1 -1
- package/dist/statics/index.mjs +3 -3
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/injections/utils.ts +8 -2
- package/src/injections/visual-edit-agent.ts +11 -3
- package/src/processors/static-array-processor.ts +34 -2
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -57,6 +57,13 @@ export default function vitePlugin(
|
|
|
57
57
|
strictPort: true,
|
|
58
58
|
// Allow all hosts - essential for Modal tunnel URLs
|
|
59
59
|
allowedHosts: true,
|
|
60
|
+
// Route the HMR WebSocket through the preview proxy instead of
|
|
61
|
+
// the sandbox origin. When BASE44_HMR_HOST is unset (e.g. before
|
|
62
|
+
// the proxy is deployed), fall back to Vite's default behavior
|
|
63
|
+
// and connect to window.location.host.
|
|
64
|
+
...(process.env.BASE44_HMR_HOST
|
|
65
|
+
? { hmr: { host: process.env.BASE44_HMR_HOST } }
|
|
66
|
+
: {}),
|
|
60
67
|
watch: {
|
|
61
68
|
// Enable polling for better file change detection in containers
|
|
62
69
|
usePolling: true,
|
package/src/injections/utils.ts
CHANGED
|
@@ -82,13 +82,19 @@ export function updateElementClasses(elements: Element[], classes: string): void
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/** Set a single attribute on all provided elements. */
|
|
85
|
-
export function updateElementAttribute(elements: Element[], attribute: string, value: string): void {
|
|
85
|
+
export function updateElementAttribute(elements: Element[], attribute: string, value: string, arrIndex?: number | string): void {
|
|
86
86
|
if (!ALLOWED_ATTRIBUTES.includes(attribute)) {
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
const targetArrIndex = arrIndex != null ? String(arrIndex) : null;
|
|
90
91
|
elements.forEach((element) => {
|
|
91
|
-
|
|
92
|
+
if (
|
|
93
|
+
targetArrIndex === null ||
|
|
94
|
+
(element as HTMLElement).dataset.arrIndex === targetArrIndex
|
|
95
|
+
) {
|
|
96
|
+
element.setAttribute(attribute, value);
|
|
97
|
+
}
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
100
|
|
|
@@ -368,12 +368,19 @@ export function setupVisualEditAgent() {
|
|
|
368
368
|
const updateElementAttributeAndReposition = (
|
|
369
369
|
visualSelectorId: string,
|
|
370
370
|
attribute: string,
|
|
371
|
-
value: string
|
|
371
|
+
value: string,
|
|
372
|
+
arrIndex?: number | string
|
|
372
373
|
) => {
|
|
373
374
|
const elements = findElementsById(visualSelectorId);
|
|
374
375
|
if (elements.length === 0) return;
|
|
375
376
|
|
|
376
|
-
|
|
377
|
+
const targetArrIndex =
|
|
378
|
+
arrIndex ??
|
|
379
|
+
(selectedElementId === visualSelectorId
|
|
380
|
+
? (selectedElement as HTMLElement | null)?.dataset.arrIndex
|
|
381
|
+
: undefined);
|
|
382
|
+
|
|
383
|
+
updateElementAttribute(elements, attribute, value, targetArrIndex);
|
|
377
384
|
|
|
378
385
|
// Reposition overlays after attribute change (e.g. image src swap can affect layout)
|
|
379
386
|
setTimeout(() => {
|
|
@@ -529,7 +536,8 @@ export function setupVisualEditAgent() {
|
|
|
529
536
|
updateElementAttributeAndReposition(
|
|
530
537
|
message.data.visualSelectorId,
|
|
531
538
|
message.data.attribute,
|
|
532
|
-
message.data.value
|
|
539
|
+
message.data.value,
|
|
540
|
+
message.data.arrIndex
|
|
533
541
|
);
|
|
534
542
|
} else {
|
|
535
543
|
console.warn(
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
DATA_ARR_INDEX,
|
|
5
5
|
DATA_ARR_VARIABLE_NAME,
|
|
6
6
|
DATA_ARR_FIELD,
|
|
7
|
+
MAX_JSX_DEPTH,
|
|
7
8
|
} from "../consts.js";
|
|
8
9
|
import { JSXAttributeUtils, StaticValueUtils } from "./utils/shared-utils.js";
|
|
9
10
|
|
|
10
|
-
|
|
11
11
|
const GENERATED_INDEX_PARAM = "__arrIdx__";
|
|
12
12
|
|
|
13
13
|
interface ArrayMapInfo {
|
|
@@ -69,6 +69,9 @@ export class StaticArrayProcessor {
|
|
|
69
69
|
path: NodePath<t.JSXOpeningElement>,
|
|
70
70
|
callbackParam: string
|
|
71
71
|
): string | null {
|
|
72
|
+
const imageSrcFieldPath = this.findImageSrcFieldPath(path, callbackParam);
|
|
73
|
+
if (imageSrcFieldPath) return imageSrcFieldPath;
|
|
74
|
+
|
|
72
75
|
const parentElement = path.parentPath;
|
|
73
76
|
if (!parentElement?.isJSXElement()) return null;
|
|
74
77
|
|
|
@@ -80,6 +83,35 @@ export class StaticArrayProcessor {
|
|
|
80
83
|
return null;
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
private findImageSrcFieldPath(
|
|
87
|
+
path: NodePath<t.JSXOpeningElement>,
|
|
88
|
+
callbackParam: string
|
|
89
|
+
): string | null {
|
|
90
|
+
const elementName = this.types.isJSXIdentifier(path.node.name)
|
|
91
|
+
? path.node.name.name
|
|
92
|
+
: null;
|
|
93
|
+
if (elementName !== "img" && elementName !== "Image") return null;
|
|
94
|
+
|
|
95
|
+
for (const attr of path.get("attributes")) {
|
|
96
|
+
if (!attr.isJSXAttribute()) continue;
|
|
97
|
+
|
|
98
|
+
const attrName = attr.get("name");
|
|
99
|
+
if (!attrName.isJSXIdentifier() || attrName.node.name !== "src") {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const value = attr.get("value");
|
|
104
|
+
if (!value.isJSXExpressionContainer()) return null;
|
|
105
|
+
|
|
106
|
+
const expression = value.get("expression");
|
|
107
|
+
if (!expression.isMemberExpression()) return null;
|
|
108
|
+
|
|
109
|
+
return this.extractFieldPath(expression, callbackParam);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
83
115
|
private extractFieldPathFromChild(
|
|
84
116
|
child: NodePath<t.JSXElement["children"][number]>,
|
|
85
117
|
callbackParam: string
|
|
@@ -156,7 +188,7 @@ export class StaticArrayProcessor {
|
|
|
156
188
|
|
|
157
189
|
private findParentArrayMap(
|
|
158
190
|
path: NodePath<t.JSXOpeningElement>,
|
|
159
|
-
maxDepth: number =
|
|
191
|
+
maxDepth: number = MAX_JSX_DEPTH
|
|
160
192
|
): ArrayMapInfo | null {
|
|
161
193
|
let currentPath: NodePath = path;
|
|
162
194
|
let depth = 0;
|