@webjourney/vite-plugins 1.2.6-2 → 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;;;;EAyJrC;AAED,wBAAgB,sBAAsB;;;6BAKT,MAAM;EAIlC;AAED,wBAAgB,iBAAiB;;;oBAtKb,MAAM,MAAM,MAAM;;;;;;;6BAgKT,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,56 +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
- // Convert elementName AST node to code string
39
- const elementNameCode = generate(elementName, {}).code;
40
- openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier('data-debug'), t.stringLiteral(elementNameCode)));
41
- modified = true;
42
- // Extract tag name - handle both regular tags and motion.* tags
43
- let tagName;
70
+ let tagName = '';
44
71
  if (t.isJSXIdentifier(elementName)) {
45
72
  tagName = elementName.name;
46
73
  }
47
74
  else if (t.isJSXMemberExpression(elementName)) {
48
- // Handle motion.div, motion.h1, etc.
75
+ // Handle motion.img
49
76
  if (t.isJSXIdentifier(elementName.object) &&
50
77
  elementName.object.name === 'motion' &&
51
78
  t.isJSXIdentifier(elementName.property)) {
52
79
  tagName = elementName.property.name;
53
80
  }
54
- else {
55
- return;
56
- }
57
- }
58
- else {
59
- return;
60
- }
61
- // Check if already has data-wj-file attribute
62
- const hasDataWj = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
63
- t.isJSXIdentifier(attr.name) &&
64
- attr.name.name === 'data-wj-file');
65
- if (hasDataWj)
66
- return;
67
- const lineNumber = openingElement.loc?.start.line ?? 0;
68
- // Handle text elements
69
- if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div', 'button', 'a', 'label', 'li'].includes(tagName)) {
70
- // Check if element has text content
71
- const hasTextContent = path.node.children.some((child) => t.isJSXText(child) && child.value.trim() !== '');
72
- if (hasTextContent) {
73
- // Generate unique ID: filename:line
74
- const elementId = `${relativePath}:${lineNumber}`;
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)));
76
- modified = true;
77
- }
78
81
  }
79
- // Handle img elements
80
82
  if (tagName === 'img') {
81
- // Check if img has src attribute
83
+ // Check if img has src attribute and doesn't already have data-wj-file
82
84
  const hasSrc = openingElement.attributes.some((attr) => t.isJSXAttribute(attr) &&
83
85
  t.isJSXIdentifier(attr.name) &&
84
86
  attr.name.name === 'src');
85
- if (hasSrc) {
86
- // 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) {
87
91
  const elementId = `${relativePath}:${lineNumber}`;
88
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)));
89
93
  modified = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.6-2",
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",