@webjourney/vite-plugins 1.2.19 → 1.2.20
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/build.js +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -39
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -247,9 +247,7 @@ async function prerender(projectRoot) {
|
|
|
247
247
|
// Write the pre-rendered HTML
|
|
248
248
|
const filePath = route === '/'
|
|
249
249
|
? toAbsolute('dist/index.html')
|
|
250
|
-
: route.
|
|
251
|
-
? toAbsolute(`dist${route}`)
|
|
252
|
-
: toAbsolute(`dist${route}/index.html`);
|
|
250
|
+
: toAbsolute(`dist${route}/index.html`);
|
|
253
251
|
// Ensure directory exists
|
|
254
252
|
const dir = path.dirname(filePath);
|
|
255
253
|
await fs.mkdir(dir, { recursive: true });
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4EA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAqPrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAlRb,MAAM,MAAM,MAAM;;;;;;;6BA4PT,MAAM;KA0BlC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,39 @@ const traverse = _traverse.default || _traverse;
|
|
|
8
8
|
const generate = _generate.default || _generate;
|
|
9
9
|
// Use local plugin for development, production URL for deployed sites
|
|
10
10
|
const webjourneyPluginScriptHost = process.env.WEBJOURNEY_PLUGIN_SCRIPT_HOST || 'https://app.webjourney.pro';
|
|
11
|
+
// Helper to handle text element tagging (text-only or mixed content with span wrapping)
|
|
12
|
+
function handleTextElement(node, openingElement, relativePath, lineNumber) {
|
|
13
|
+
const textNodes = node.children.filter((child) => t.isJSXText(child) && child.value.trim() !== '');
|
|
14
|
+
const nonTextChildren = node.children.filter((child) => !t.isJSXText(child) || (t.isJSXText(child) && child.value.trim() === ''));
|
|
15
|
+
if (textNodes.length === 0)
|
|
16
|
+
return false;
|
|
17
|
+
// Case 1: Text-only element (no other children)
|
|
18
|
+
if (nonTextChildren.length === 0) {
|
|
19
|
+
const elementId = `${relativePath}:${lineNumber}`;
|
|
20
|
+
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// Case 2: Mixed children (text nodes + other elements) - wrap text in spans
|
|
24
|
+
const newChildren = [];
|
|
25
|
+
for (const child of node.children) {
|
|
26
|
+
if (t.isJSXText(child) && child.value.trim() !== '') {
|
|
27
|
+
const textLineNumber = child.loc?.start.line ?? lineNumber;
|
|
28
|
+
const elementId = `${relativePath}:${textLineNumber}`;
|
|
29
|
+
const wrapper = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('span'), [
|
|
30
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)),
|
|
31
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(textLineNumber))),
|
|
32
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')),
|
|
33
|
+
t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
|
|
34
|
+
], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
|
|
35
|
+
newChildren.push(wrapper);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
newChildren.push(child);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
node.children = newChildren;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
11
44
|
// Plugin to inject source mapping attributes for WYSIWYG editing
|
|
12
45
|
export function webjourneyElementTagger() {
|
|
13
46
|
return {
|
|
@@ -62,45 +95,9 @@ export function webjourneyElementTagger() {
|
|
|
62
95
|
return;
|
|
63
96
|
const lineNumber = openingElement.loc?.start.line ?? 0;
|
|
64
97
|
// Handle text elements
|
|
65
|
-
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div', 'button', '
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Get all non-text children (elements, expressions, etc.)
|
|
69
|
-
const nonTextChildren = path.node.children.filter((child) => !t.isJSXText(child) || (t.isJSXText(child) && child.value.trim() === ''));
|
|
70
|
-
if (textNodes.length > 0) {
|
|
71
|
-
// Case 1: Single text node child (no other elements)
|
|
72
|
-
if (nonTextChildren.length === 0) {
|
|
73
|
-
// Add data-wj-* attributes to the current element
|
|
74
|
-
const elementId = `${relativePath}:${lineNumber}`;
|
|
75
|
-
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
76
|
-
modified = true;
|
|
77
|
-
}
|
|
78
|
-
// Case 2: Mixed children (text nodes + other elements)
|
|
79
|
-
else if (nonTextChildren.length > 0) {
|
|
80
|
-
// Wrap each text node in a span with data-wj-* attributes
|
|
81
|
-
const newChildren = [];
|
|
82
|
-
for (const child of path.node.children) {
|
|
83
|
-
if (t.isJSXText(child) && child.value.trim() !== '') {
|
|
84
|
-
// Generate unique ID for this text segment
|
|
85
|
-
const textLineNumber = child.loc?.start.line ?? lineNumber;
|
|
86
|
-
const elementId = `${relativePath}:${textLineNumber}`;
|
|
87
|
-
// Create a span wrapper
|
|
88
|
-
const wrapper = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('span'), [
|
|
89
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)),
|
|
90
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(textLineNumber))),
|
|
91
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')),
|
|
92
|
-
t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
|
|
93
|
-
], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
|
|
94
|
-
newChildren.push(wrapper);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// Keep whitespace text nodes, elements, etc. as-is
|
|
98
|
-
newChildren.push(child);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
path.node.children = newChildren;
|
|
102
|
-
modified = true;
|
|
103
|
-
}
|
|
98
|
+
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div', 'button', 'label', 'li'].includes(tagName)) {
|
|
99
|
+
if (handleTextElement(path.node, openingElement, relativePath, lineNumber)) {
|
|
100
|
+
modified = true;
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
// Handle img elements
|
|
@@ -158,6 +155,12 @@ export function webjourneyElementTagger() {
|
|
|
158
155
|
openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)), t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(lineNumber))), t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('link')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
|
|
159
156
|
modified = true;
|
|
160
157
|
}
|
|
158
|
+
else {
|
|
159
|
+
// Anchors without href/to are treated as text elements (button-like anchors)
|
|
160
|
+
if (handleTextElement(path.node, openingElement, relativePath, lineNumber)) {
|
|
161
|
+
modified = true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
161
164
|
}
|
|
162
165
|
// Handle all remaining div elements as 'frame' type
|
|
163
166
|
// This catches divs that weren't marked by other conditions
|