potatejs 0.12.2 → 0.13.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.
package/README.md CHANGED
@@ -76,7 +76,7 @@ const App = props => {
76
76
  }
77
77
 
78
78
  const root = Potate.createRoot(document.querySelector('#app'))
79
- root.render(Potate.createElement(App)) // ✖ root.render(<App/>) Please avoid JSX at the root
79
+ root.render(<App/>)
80
80
 
81
81
  ```
82
82
 
@@ -130,7 +130,7 @@ export default function App(props) {
130
130
  }
131
131
 
132
132
  const root = Potate.createRoot(document.querySelector('#app'))
133
- root.render(Potate.createElement(App)) // ✖ root.render(<App/>) Please avoid JSX at the root
133
+ root.render(<App/>)
134
134
 
135
135
  ```
136
136
 
@@ -285,6 +285,7 @@ For the above example, the Brahmos output is 685 bytes, compared to 824 bytes fr
285
285
  - [x] `use(resource)` API
286
286
  - [x] [watch(resource) API](docs/API.md)
287
287
  - [x] React 19 style root management
288
+ - [x] Allow using class instead of className
288
289
  - [ ] `use(context)` API
289
290
  - [ ] [use(store) API](https://react.dev/blog/2025/04/23/react-labs-view-transitions-activity-and-more#concurrent-stores)
290
291
  - [ ] [ref as a prop](https://react.dev/blog/2024/12/05/react-19#ref-as-a-prop)
@@ -13394,6 +13394,54 @@ function getLiteralParts(rootPath) {
13394
13394
  stringPart.push(`</${tagName}>`);
13395
13395
  }
13396
13396
  return;
13397
+ } else {
13398
+ const propsProperties = [];
13399
+ openingElement.attributes.forEach((attr) => {
13400
+ if (t.isJSXAttribute(attr)) {
13401
+ let attrName = attr.name.name;
13402
+ const value = attr.value;
13403
+ let valNode;
13404
+ attrName = PROPERTY_ATTRIBUTE_MAP[attrName] || attrName;
13405
+ if (!value) {
13406
+ valNode = { type: "Literal", value: true };
13407
+ } else if (t.isJSXExpressionContainer(value)) {
13408
+ valNode = value.expression;
13409
+ } else {
13410
+ valNode = { type: "Literal", value: value.value };
13411
+ }
13412
+ propsProperties.push({
13413
+ type: "Property",
13414
+ key: { type: "Identifier", name: attrName },
13415
+ value: valNode,
13416
+ kind: "init"
13417
+ });
13418
+ } else if (t.isJSXSpreadAttribute(attr)) {
13419
+ propsProperties.push({
13420
+ type: "SpreadElement",
13421
+ argument: attr.argument
13422
+ });
13423
+ }
13424
+ });
13425
+ let extractedText = "";
13426
+ const children2 = path.get("children");
13427
+ if (Array.isArray(children2)) {
13428
+ children2.forEach((cp) => {
13429
+ if (t.isJSXText(cp.node)) {
13430
+ extractedText += cleanStringForHtml(cp.node.value);
13431
+ }
13432
+ });
13433
+ }
13434
+ const callExpr = {
13435
+ type: "CallExpression",
13436
+ callee: { type: "Identifier", name: "jsx" },
13437
+ arguments: [
13438
+ { type: "Identifier", name: tagName },
13439
+ { type: "ObjectExpression", properties: propsProperties },
13440
+ { type: "Literal", value: extractedText }
13441
+ ]
13442
+ };
13443
+ pushToExpressions(callExpr, path, false);
13444
+ return;
13397
13445
  }
13398
13446
  }
13399
13447
  const children = path.get("children");
@@ -13424,7 +13472,10 @@ function getTaggedTemplate(node) {
13424
13472
  return {
13425
13473
  type: "TaggedTemplateExpression",
13426
13474
  tag: "html",
13427
- template: { strings, expressions },
13475
+ template: {
13476
+ strings,
13477
+ expressions
13478
+ },
13428
13479
  meta: metaStr
13429
13480
  };
13430
13481
  }
@@ -13391,6 +13391,54 @@ function getLiteralParts(rootPath) {
13391
13391
  stringPart.push(`</${tagName}>`);
13392
13392
  }
13393
13393
  return;
13394
+ } else {
13395
+ const propsProperties = [];
13396
+ openingElement.attributes.forEach((attr) => {
13397
+ if (t.isJSXAttribute(attr)) {
13398
+ let attrName = attr.name.name;
13399
+ const value = attr.value;
13400
+ let valNode;
13401
+ attrName = PROPERTY_ATTRIBUTE_MAP[attrName] || attrName;
13402
+ if (!value) {
13403
+ valNode = { type: "Literal", value: true };
13404
+ } else if (t.isJSXExpressionContainer(value)) {
13405
+ valNode = value.expression;
13406
+ } else {
13407
+ valNode = { type: "Literal", value: value.value };
13408
+ }
13409
+ propsProperties.push({
13410
+ type: "Property",
13411
+ key: { type: "Identifier", name: attrName },
13412
+ value: valNode,
13413
+ kind: "init"
13414
+ });
13415
+ } else if (t.isJSXSpreadAttribute(attr)) {
13416
+ propsProperties.push({
13417
+ type: "SpreadElement",
13418
+ argument: attr.argument
13419
+ });
13420
+ }
13421
+ });
13422
+ let extractedText = "";
13423
+ const children2 = path.get("children");
13424
+ if (Array.isArray(children2)) {
13425
+ children2.forEach((cp) => {
13426
+ if (t.isJSXText(cp.node)) {
13427
+ extractedText += cleanStringForHtml(cp.node.value);
13428
+ }
13429
+ });
13430
+ }
13431
+ const callExpr = {
13432
+ type: "CallExpression",
13433
+ callee: { type: "Identifier", name: "jsx" },
13434
+ arguments: [
13435
+ { type: "Identifier", name: tagName },
13436
+ { type: "ObjectExpression", properties: propsProperties },
13437
+ { type: "Literal", value: extractedText }
13438
+ ]
13439
+ };
13440
+ pushToExpressions(callExpr, path, false);
13441
+ return;
13394
13442
  }
13395
13443
  }
13396
13444
  const children = path.get("children");
@@ -13421,7 +13469,10 @@ function getTaggedTemplate(node) {
13421
13469
  return {
13422
13470
  type: "TaggedTemplateExpression",
13423
13471
  tag: "html",
13424
- template: { strings, expressions },
13472
+ template: {
13473
+ strings,
13474
+ expressions
13475
+ },
13425
13476
  meta: metaStr
13426
13477
  };
13427
13478
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "potatejs",
3
- "version": "0.12.2",
3
+ "version": "0.13.0",
4
4
  "description": "Super charged UI library with modern React API and native templates.",
5
5
  "author": "uniho",
6
6
  "license": "MIT",