@webjourney/vite-plugins 1.2.6 → 1.2.7-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;;;;EA8IrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAIlC;AAED,wBAAgB,iBAAiB;;;oBA3Jb,MAAM,MAAM,MAAM;;;;;;;6BAqJT,MAAM;KAUlC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,wBAAgB,uBAAuB;;;oBAKnB,MAAM,MAAM,MAAM;;;;EA8JrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAIlC;AAED,wBAAgB,iBAAiB;;;oBA3Kb,MAAM,MAAM,MAAM;;;;;;;6BAqKT,MAAM;KAUlC"}
package/dist/index.js CHANGED
@@ -34,52 +34,60 @@ export function webjourneyElementTagger() {
34
34
  traverse(ast, {
35
35
  JSXElement(path) {
36
36
  const openingElement = path.node.openingElement;
37
+ const lineNumber = openingElement.loc?.start.line ?? 0;
38
+ // Process children to wrap text nodes
39
+ const newChildren = [];
40
+ let hasWrappedText = false;
41
+ for (const child of path.node.children) {
42
+ // Only wrap JSXText nodes that have non-whitespace content
43
+ if (t.isJSXText(child) && child.value.trim() !== '') {
44
+ // Generate unique ID for this text segment
45
+ const textLineNumber = child.loc?.start.line ?? lineNumber;
46
+ const elementId = `${relativePath}:${textLineNumber}`;
47
+ // Create a span wrapper for the text node
48
+ const wrapper = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('span'), [
49
+ t.jsxAttribute(t.jsxIdentifier('data-wj-text'), null),
50
+ t.jsxAttribute(t.jsxIdentifier('data-wj-file'), t.stringLiteral(relativePath)),
51
+ t.jsxAttribute(t.jsxIdentifier('data-wj-line'), t.stringLiteral(String(textLineNumber))),
52
+ t.jsxAttribute(t.jsxIdentifier('data-wj-type'), t.stringLiteral('text')),
53
+ t.jsxAttribute(t.jsxIdentifier('data-wj-id'), t.stringLiteral(elementId))
54
+ ], false), t.jsxClosingElement(t.jsxIdentifier('span')), [child], false);
55
+ newChildren.push(wrapper);
56
+ hasWrappedText = true;
57
+ modified = true;
58
+ }
59
+ else {
60
+ // Keep other nodes as-is (elements, whitespace-only text, expressions, etc.)
61
+ newChildren.push(child);
62
+ }
63
+ }
64
+ // Replace children if we wrapped any text
65
+ if (hasWrappedText) {
66
+ path.node.children = newChildren;
67
+ }
68
+ // Handle img elements - add attributes to the img tag itself
37
69
  const elementName = openingElement.name;
38
- // Extract tag name - handle both regular tags and motion.* tags
39
- let tagName;
70
+ let tagName = '';
40
71
  if (t.isJSXIdentifier(elementName)) {
41
72
  tagName = elementName.name;
42
73
  }
43
74
  else if (t.isJSXMemberExpression(elementName)) {
44
- // Handle motion.div, motion.h1, etc.
75
+ // Handle motion.img
45
76
  if (t.isJSXIdentifier(elementName.object) &&
46
77
  elementName.object.name === 'motion' &&
47
78
  t.isJSXIdentifier(elementName.property)) {
48
79
  tagName = elementName.property.name;
49
80
  }
50
- else {
51
- return;
52
- }
53
- }
54
- else {
55
- return;
56
- }
57
- // Check if already has data-wj-file attribute
58
- const hasDataWj = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
59
- t.isJSXIdentifier(attr.name) &&
60
- attr.name.name === 'data-wj-file');
61
- if (hasDataWj)
62
- return;
63
- const lineNumber = openingElement.loc?.start.line ?? 0;
64
- // Handle text elements
65
- if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div', 'button', 'a', 'label', 'li'].includes(tagName)) {
66
- // Check if element has text content
67
- const hasTextContent = path.node.children.some((child) => t.isJSXText(child) && child.value.trim() !== '');
68
- if (hasTextContent) {
69
- // Generate unique ID: filename:line
70
- const elementId = `${relativePath}:${lineNumber}`;
71
- 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)));
72
- modified = true;
73
- }
74
81
  }
75
- // Handle img elements
76
82
  if (tagName === 'img') {
77
- // Check if img has src attribute
83
+ // Check if img has src attribute and doesn't already have data-wj-file
78
84
  const hasSrc = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
79
85
  t.isJSXIdentifier(attr.name) &&
80
86
  attr.name.name === 'src');
81
- if (hasSrc) {
82
- // Generate unique ID: filename:line
87
+ const hasDataWj = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
88
+ t.isJSXIdentifier(attr.name) &&
89
+ attr.name.name === 'data-wj-file');
90
+ if (hasSrc && !hasDataWj) {
83
91
  const elementId = `${relativePath}:${lineNumber}`;
84
92
  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)));
85
93
  modified = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.6",
3
+ "version": "1.2.7-0",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",