@webjourney/vite-plugins 1.2.17-0 → 1.2.18

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":"AA0GA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EAqYrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAoBlC;AAED,wBAAgB,iBAAiB;;;oBAlab,MAAM,MAAM,MAAM;;;;;;;6BA4YT,MAAM;KA0BlC"}
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"}
package/dist/index.js CHANGED
@@ -2,70 +2,12 @@ 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';
6
5
  import path from 'path';
7
6
  // Handle CommonJS default exports
8
7
  const traverse = _traverse.default || _traverse;
9
8
  const generate = _generate.default || _generate;
10
9
  // Use local plugin for development, production URL for deployed sites
11
10
  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
- }
69
11
  // Plugin to inject source mapping attributes for WYSIWYG editing
70
12
  export function webjourneyElementTagger() {
71
13
  return {
@@ -88,9 +30,6 @@ export function webjourneyElementTagger() {
88
30
  plugins: ['typescript', 'jsx'],
89
31
  });
90
32
  let modified = false;
91
- // Arrays to collect node information for documentation
92
- const docTextNodes = [];
93
- const docImageNodes = [];
94
33
  // Traverse the AST
95
34
  traverse(ast, {
96
35
  JSXElement(path) {
@@ -135,27 +74,11 @@ export function webjourneyElementTagger() {
135
74
  const elementId = `${relativePath}:${lineNumber}`;
136
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)));
137
76
  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
- });
150
77
  }
151
78
  // Case 2: Mixed children (text nodes + other elements)
152
79
  else if (nonTextChildren.length > 0) {
153
80
  // Wrap each text node in a span with data-wj-* attributes
154
81
  const newChildren = [];
155
- // Extract href if parent is a link element
156
- const parentHref = (tagName === 'a' || tagName === 'Link')
157
- ? extractHrefValue(openingElement.attributes)
158
- : undefined;
159
82
  for (const child of path.node.children) {
160
83
  if (t.isJSXText(child) && child.value.trim() !== '') {
161
84
  // Generate unique ID for this text segment
@@ -169,15 +92,6 @@ export function webjourneyElementTagger() {
169
92
  t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
170
93
  ], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
171
94
  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
- });
181
95
  }
182
96
  else {
183
97
  // Keep whitespace text nodes, elements, etc. as-is
@@ -200,13 +114,6 @@ export function webjourneyElementTagger() {
200
114
  const elementId = `${relativePath}:${lineNumber}`;
201
115
  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)));
202
116
  modified = true;
203
- // Collect image information for documentation
204
- docImageNodes.push({
205
- line: lineNumber,
206
- tag: tagName,
207
- id: elementId,
208
- type: 'image'
209
- });
210
117
  }
211
118
  }
212
119
  // Handle elements with bg-[url(...)] className pattern
@@ -237,15 +144,6 @@ export function webjourneyElementTagger() {
237
144
  const elementId = `${relativePath}:${lineNumber}`;
238
145
  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)));
239
146
  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
- });
249
147
  }
250
148
  }
251
149
  // Handle anchor elements and Link components
@@ -278,18 +176,6 @@ export function webjourneyElementTagger() {
278
176
  }
279
177
  });
280
178
  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
- }
293
179
  // Generate code from the modified AST
294
180
  const output = generate(ast, {
295
181
  retainLines: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.17-0",
3
+ "version": "1.2.18",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",