@webjourney/vite-plugins 1.2.16 → 1.2.17-1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAsUrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAnWb,MAAM,MAAM,MAAM;;;;;;;6BA6UT,MAAM;KA0BlC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqGA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAuYrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBApab,MAAM,MAAM,MAAM;;;;;;;6BA8YT,MAAM;KA0BlC"}
package/dist/index.js CHANGED
@@ -2,12 +2,62 @@ import _generate from '@babel/generator';
2
2
  import { parse } from '@babel/parser';
3
3
  import _traverse from '@babel/traverse';
4
4
  import * as t from '@babel/types';
5
+ import * as fs from 'fs';
5
6
  import path from 'path';
6
7
  // Handle CommonJS default exports
7
8
  const traverse = _traverse.default || _traverse;
8
9
  const generate = _generate.default || _generate;
9
10
  // Use local plugin for development, production URL for deployed sites
10
11
  const webjourneyPluginScriptHost = process.env.WEBJOURNEY_PLUGIN_SCRIPT_HOST || 'https://app.webjourney.pro';
12
+ // Helper function to extract text content from JSX children
13
+ function extractTextContent(children) {
14
+ return children
15
+ .filter(child => t.isJSXText(child))
16
+ .map(child => child.value.trim())
17
+ .filter(text => text !== '')
18
+ .join(' ');
19
+ }
20
+ // Helper function to extract href or to attribute value
21
+ function extractHrefValue(attributes) {
22
+ const hrefAttr = attributes.find((attr) => t.isJSXAttribute(attr) &&
23
+ t.isJSXIdentifier(attr.name) &&
24
+ (attr.name.name === 'href' || attr.name.name === 'to'));
25
+ if (hrefAttr && t.isJSXAttribute(hrefAttr)) {
26
+ if (t.isStringLiteral(hrefAttr.value)) {
27
+ return hrefAttr.value.value;
28
+ }
29
+ else if (t.isJSXExpressionContainer(hrefAttr.value) && t.isStringLiteral(hrefAttr.value.expression)) {
30
+ return hrefAttr.value.expression.value;
31
+ }
32
+ }
33
+ return undefined;
34
+ }
35
+ // Helper function to extract src attribute value
36
+ function extractSrcValue(attributes) {
37
+ const srcAttr = attributes.find((attr) => t.isJSXAttribute(attr) &&
38
+ t.isJSXIdentifier(attr.name) &&
39
+ attr.name.name === 'src');
40
+ if (srcAttr && t.isJSXAttribute(srcAttr)) {
41
+ if (t.isStringLiteral(srcAttr.value)) {
42
+ return srcAttr.value.value;
43
+ }
44
+ else if (t.isJSXExpressionContainer(srcAttr.value) && t.isStringLiteral(srcAttr.value.expression)) {
45
+ return srcAttr.value.expression.value;
46
+ }
47
+ }
48
+ return undefined;
49
+ }
50
+ // Helper function to generate JSON documentation
51
+ function generateJsonDocs(relativePath, textNodes, imageNodes) {
52
+ const timestamp = new Date().toISOString();
53
+ const data = {
54
+ file: relativePath,
55
+ generatedAt: timestamp,
56
+ textNodes: textNodes,
57
+ imageNodes: imageNodes
58
+ };
59
+ return JSON.stringify(data, null, 2);
60
+ }
11
61
  // Plugin to inject source mapping attributes for WYSIWYG editing
12
62
  export function webjourneyElementTagger() {
13
63
  return {
@@ -30,6 +80,9 @@ export function webjourneyElementTagger() {
30
80
  plugins: ['typescript', 'jsx'],
31
81
  });
32
82
  let modified = false;
83
+ // Arrays to collect node information for documentation
84
+ const docTextNodes = [];
85
+ const docImageNodes = [];
33
86
  // Traverse the AST
34
87
  traverse(ast, {
35
88
  JSXElement(path) {
@@ -74,11 +127,27 @@ export function webjourneyElementTagger() {
74
127
  const elementId = `${relativePath}:${lineNumber}`;
75
128
  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
129
  modified = true;
130
+ // Collect text content for documentation
131
+ const textContent = extractTextContent(path.node.children);
132
+ const hrefValue = (tagName === 'a' || tagName === 'Link')
133
+ ? extractHrefValue(openingElement.attributes)
134
+ : undefined;
135
+ docTextNodes.push({
136
+ line: lineNumber,
137
+ tag: tagName,
138
+ id: elementId,
139
+ content: textContent,
140
+ href: hrefValue
141
+ });
77
142
  }
78
143
  // Case 2: Mixed children (text nodes + other elements)
79
144
  else if (nonTextChildren.length > 0) {
80
145
  // Wrap each text node in a span with data-wj-* attributes
81
146
  const newChildren = [];
147
+ // Extract href if parent is a link element
148
+ const parentHref = (tagName === 'a' || tagName === 'Link')
149
+ ? extractHrefValue(openingElement.attributes)
150
+ : undefined;
82
151
  for (const child of path.node.children) {
83
152
  if (t.isJSXText(child) && child.value.trim() !== '') {
84
153
  // Generate unique ID for this text segment
@@ -92,6 +161,15 @@ export function webjourneyElementTagger() {
92
161
  t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
93
162
  ], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
94
163
  newChildren.push(wrapper);
164
+ // Collect text content for documentation
165
+ const textContent = child.value.trim();
166
+ docTextNodes.push({
167
+ line: textLineNumber,
168
+ tag: 'span',
169
+ id: elementId,
170
+ content: textContent,
171
+ href: parentHref
172
+ });
95
173
  }
96
174
  else {
97
175
  // Keep whitespace text nodes, elements, etc. as-is
@@ -114,6 +192,15 @@ export function webjourneyElementTagger() {
114
192
  const elementId = `${relativePath}:${lineNumber}`;
115
193
  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('image')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
116
194
  modified = true;
195
+ // Collect image information for documentation
196
+ const srcValue = extractSrcValue(openingElement.attributes);
197
+ docImageNodes.push({
198
+ line: lineNumber,
199
+ tag: tagName,
200
+ id: elementId,
201
+ type: 'image',
202
+ src: srcValue
203
+ });
117
204
  }
118
205
  }
119
206
  // Handle elements with bg-[url(...)] className pattern
@@ -144,6 +231,15 @@ export function webjourneyElementTagger() {
144
231
  const elementId = `${relativePath}:${lineNumber}`;
145
232
  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('background-image')), t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId)));
146
233
  modified = true;
234
+ // Collect background image information for documentation
235
+ const bgMatch = classNameValue.match(/bg-\[url\([^\)]+\)\]/);
236
+ docImageNodes.push({
237
+ line: lineNumber,
238
+ tag: tagName,
239
+ id: elementId,
240
+ type: 'background-image',
241
+ bgPattern: bgMatch ? bgMatch[0] : undefined
242
+ });
147
243
  }
148
244
  }
149
245
  // Handle anchor elements and Link components
@@ -176,6 +272,18 @@ export function webjourneyElementTagger() {
176
272
  }
177
273
  });
178
274
  if (modified) {
275
+ // Generate JSON documentation
276
+ if (docTextNodes.length > 0 || docImageNodes.length > 0) {
277
+ const jsonContent = generateJsonDocs(relativePath, docTextNodes, docImageNodes);
278
+ const jsonPath = `${id}.nodes.json`;
279
+ try {
280
+ fs.writeFileSync(jsonPath, jsonContent, 'utf-8');
281
+ }
282
+ catch (error) {
283
+ console.error(`Error writing documentation for ${id}:`, error);
284
+ // Don't fail the build if documentation generation fails
285
+ }
286
+ }
179
287
  // Generate code from the modified AST
180
288
  const output = generate(ast, {
181
289
  retainLines: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.16",
3
+ "version": "1.2.17-1",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",