@webjourney/vite-plugins 1.2.16 → 1.2.17-0

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":"AA0GA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAqYrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAlab,MAAM,MAAM,MAAM;;;;;;;6BA4YT,MAAM;KA0BlC"}
package/dist/index.js CHANGED
@@ -2,12 +2,70 @@ 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 generate markdown documentation
36
+ function generateMarkdownDocs(relativePath, textNodes, imageNodes) {
37
+ const timestamp = new Date().toISOString().replace('T', ' ').split('.')[0];
38
+ let md = `# Text and Image Nodes: ${relativePath}\n\n`;
39
+ md += `Generated: ${timestamp}\n\n`;
40
+ if (textNodes.length > 0) {
41
+ md += `## Text Nodes\n\n`;
42
+ for (const node of textNodes) {
43
+ md += `### Line ${node.line}: ${node.tag}\n`;
44
+ md += `**ID**: \`${node.id}\`\n`;
45
+ md += `**Content**: \`${node.content}\`\n`;
46
+ if (node.href) {
47
+ md += `**Link**: \`${node.href}\`\n`;
48
+ }
49
+ md += '\n';
50
+ }
51
+ }
52
+ if (imageNodes.length > 0) {
53
+ md += `## Image Nodes\n\n`;
54
+ for (const node of imageNodes) {
55
+ md += `### Line ${node.line}: ${node.tag}\n`;
56
+ md += `**ID**: \`${node.id}\`\n`;
57
+ md += `**Type**: ${node.type}\n`;
58
+ if (node.bgPattern) {
59
+ md += `**Pattern**: \`${node.bgPattern}\`\n`;
60
+ }
61
+ md += '\n';
62
+ }
63
+ }
64
+ if (textNodes.length === 0 && imageNodes.length === 0) {
65
+ md += `No text or image nodes found.\n`;
66
+ }
67
+ return md;
68
+ }
11
69
  // Plugin to inject source mapping attributes for WYSIWYG editing
12
70
  export function webjourneyElementTagger() {
13
71
  return {
@@ -30,6 +88,9 @@ export function webjourneyElementTagger() {
30
88
  plugins: ['typescript', 'jsx'],
31
89
  });
32
90
  let modified = false;
91
+ // Arrays to collect node information for documentation
92
+ const docTextNodes = [];
93
+ const docImageNodes = [];
33
94
  // Traverse the AST
34
95
  traverse(ast, {
35
96
  JSXElement(path) {
@@ -74,11 +135,27 @@ export function webjourneyElementTagger() {
74
135
  const elementId = `${relativePath}:${lineNumber}`;
75
136
  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
137
  modified = true;
138
+ // Collect text content for documentation
139
+ const textContent = extractTextContent(path.node.children);
140
+ const hrefValue = (tagName === 'a' || tagName === 'Link')
141
+ ? extractHrefValue(openingElement.attributes)
142
+ : undefined;
143
+ docTextNodes.push({
144
+ line: lineNumber,
145
+ tag: tagName,
146
+ id: elementId,
147
+ content: textContent,
148
+ href: hrefValue
149
+ });
77
150
  }
78
151
  // Case 2: Mixed children (text nodes + other elements)
79
152
  else if (nonTextChildren.length > 0) {
80
153
  // Wrap each text node in a span with data-wj-* attributes
81
154
  const newChildren = [];
155
+ // Extract href if parent is a link element
156
+ const parentHref = (tagName === 'a' || tagName === 'Link')
157
+ ? extractHrefValue(openingElement.attributes)
158
+ : undefined;
82
159
  for (const child of path.node.children) {
83
160
  if (t.isJSXText(child) && child.value.trim() !== '') {
84
161
  // Generate unique ID for this text segment
@@ -92,6 +169,15 @@ export function webjourneyElementTagger() {
92
169
  t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
93
170
  ], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
94
171
  newChildren.push(wrapper);
172
+ // Collect text content for documentation
173
+ const textContent = child.value.trim();
174
+ docTextNodes.push({
175
+ line: textLineNumber,
176
+ tag: 'span',
177
+ id: elementId,
178
+ content: textContent,
179
+ href: parentHref
180
+ });
95
181
  }
96
182
  else {
97
183
  // Keep whitespace text nodes, elements, etc. as-is
@@ -114,6 +200,13 @@ export function webjourneyElementTagger() {
114
200
  const elementId = `${relativePath}:${lineNumber}`;
115
201
  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
202
  modified = true;
203
+ // Collect image information for documentation
204
+ docImageNodes.push({
205
+ line: lineNumber,
206
+ tag: tagName,
207
+ id: elementId,
208
+ type: 'image'
209
+ });
117
210
  }
118
211
  }
119
212
  // Handle elements with bg-[url(...)] className pattern
@@ -144,6 +237,15 @@ export function webjourneyElementTagger() {
144
237
  const elementId = `${relativePath}:${lineNumber}`;
145
238
  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
239
  modified = true;
240
+ // Collect background image information for documentation
241
+ const bgMatch = classNameValue.match(/bg-\[url\([^\)]+\)\]/);
242
+ docImageNodes.push({
243
+ line: lineNumber,
244
+ tag: tagName,
245
+ id: elementId,
246
+ type: 'background-image',
247
+ bgPattern: bgMatch ? bgMatch[0] : undefined
248
+ });
147
249
  }
148
250
  }
149
251
  // Handle anchor elements and Link components
@@ -176,6 +278,18 @@ export function webjourneyElementTagger() {
176
278
  }
177
279
  });
178
280
  if (modified) {
281
+ // Generate markdown documentation
282
+ if (docTextNodes.length > 0 || docImageNodes.length > 0) {
283
+ const markdownContent = generateMarkdownDocs(relativePath, docTextNodes, docImageNodes);
284
+ const markdownPath = `${id}.nodes.md`;
285
+ try {
286
+ fs.writeFileSync(markdownPath, markdownContent, 'utf-8');
287
+ }
288
+ catch (error) {
289
+ console.error(`Error writing documentation for ${id}:`, error);
290
+ // Don't fail the build if documentation generation fails
291
+ }
292
+ }
179
293
  // Generate code from the modified AST
180
294
  const output = generate(ast, {
181
295
  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-0",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",