@webjourney/vite-plugins 1.2.17-0 → 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":"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":"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
@@ -32,39 +32,31 @@ function extractHrefValue(attributes) {
32
32
  }
33
33
  return undefined;
34
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';
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;
50
43
  }
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';
44
+ else if (t.isJSXExpressionContainer(srcAttr.value) && t.isStringLiteral(srcAttr.value.expression)) {
45
+ return srcAttr.value.expression.value;
62
46
  }
63
47
  }
64
- if (textNodes.length === 0 && imageNodes.length === 0) {
65
- md += `No text or image nodes found.\n`;
66
- }
67
- return md;
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);
68
60
  }
69
61
  // Plugin to inject source mapping attributes for WYSIWYG editing
70
62
  export function webjourneyElementTagger() {
@@ -201,11 +193,13 @@ export function webjourneyElementTagger() {
201
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)));
202
194
  modified = true;
203
195
  // Collect image information for documentation
196
+ const srcValue = extractSrcValue(openingElement.attributes);
204
197
  docImageNodes.push({
205
198
  line: lineNumber,
206
199
  tag: tagName,
207
200
  id: elementId,
208
- type: 'image'
201
+ type: 'image',
202
+ src: srcValue
209
203
  });
210
204
  }
211
205
  }
@@ -278,12 +272,12 @@ export function webjourneyElementTagger() {
278
272
  }
279
273
  });
280
274
  if (modified) {
281
- // Generate markdown documentation
275
+ // Generate JSON documentation
282
276
  if (docTextNodes.length > 0 || docImageNodes.length > 0) {
283
- const markdownContent = generateMarkdownDocs(relativePath, docTextNodes, docImageNodes);
284
- const markdownPath = `${id}.nodes.md`;
277
+ const jsonContent = generateJsonDocs(relativePath, docTextNodes, docImageNodes);
278
+ const jsonPath = `${id}.nodes.json`;
285
279
  try {
286
- fs.writeFileSync(markdownPath, markdownContent, 'utf-8');
280
+ fs.writeFileSync(jsonPath, jsonContent, 'utf-8');
287
281
  }
288
282
  catch (error) {
289
283
  console.error(`Error writing documentation for ${id}:`, error);
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.17-1",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",