@torpor/view 0.1.2 → 0.1.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @torpor/view
2
2
 
3
+ ## 0.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - daba2ad: Fix: passing `:class` and `:style` to components
8
+
9
+ ## 0.1.3
10
+
11
+ ### Patch Changes
12
+
13
+ - de51225: Fix: passing `:class` and `:style` to components
14
+
3
15
  ## 0.1.2
4
16
 
5
17
  ### Patch Changes
package/dist/compile.cjs CHANGED
@@ -930,6 +930,17 @@ function buildComponentNode(node, status, b, root = false) {
930
930
  value = value.substring(1, value.length - 1);
931
931
  buildRun("setProp", `${propsName}["${name}"] = ${value};`, status, b);
932
932
  buildRun("setBinding", `${value} = ${propsName}["${name}"];`, status, b);
933
+ } else if (name === ":class" && value != null && isFullyReactive(value)) {
934
+ status.imports.add("t_class");
935
+ value = value.substring(1, value.length - 1);
936
+ if (node.scopeStyles) {
937
+ value += `, "torp-${status.styleHash}"`;
938
+ }
939
+ buildRun("setClasses", `${propsName}["class"] = t_class(${value});`, status, b);
940
+ } else if (name === ":style" && value != null && isFullyReactive(value)) {
941
+ status.imports.add("t_style");
942
+ value = value.substring(1, value.length - 1);
943
+ buildRun("setStyles", `${propsName}["style"] = t_style(${value});`, status, b);
933
944
  } else if (value != null) {
934
945
  let fullyReactive = isFullyReactive(value);
935
946
  let partlyReactive = isReactive(value);
@@ -2109,6 +2120,17 @@ function buildServerComponentNode(node, status, b) {
2109
2120
  name = name.substring(1, name.length - 1);
2110
2121
  const propName = name.split(".").at(-1);
2111
2122
  b.append(`${propsName}["${propName}"] = ${name};`);
2123
+ } else if (name === ":class" && value != null && isFullyReactive(value)) {
2124
+ status.imports.add("t_class");
2125
+ value = value.substring(1, value.length - 1);
2126
+ if (node.scopeStyles) {
2127
+ value += `, "torp-${status.styleHash}"`;
2128
+ }
2129
+ b.append(`${propsName}["class"] = t_class(${value});`);
2130
+ } else if (name === ":style" && value != null && isFullyReactive(value)) {
2131
+ status.imports.add("t_style");
2132
+ value = value.substring(1, value.length - 1);
2133
+ b.append(`${propsName}["style"] = t_style(${value});`);
2112
2134
  } else if (value != null) {
2113
2135
  let fullyReactive = isFullyReactive(value);
2114
2136
  let partlyReactive = isReactive(value);
@@ -3644,6 +3666,11 @@ function parseStyleAttribute(status) {
3644
3666
  };
3645
3667
  }
3646
3668
 
3669
+ // src/compile/types/nodes/isComponentNode.ts
3670
+ function isComponentNode(node) {
3671
+ return node.type === "component";
3672
+ }
3673
+
3647
3674
  // src/compile/types/nodes/isParentNode.ts
3648
3675
  function isParentNode(node) {
3649
3676
  return "children" in node;
@@ -3662,7 +3689,7 @@ function scopeStyles(status) {
3662
3689
  }
3663
3690
  }
3664
3691
  function scopeStylesOnNode(node, selectors) {
3665
- if (isElementNode(node)) {
3692
+ if (isElementNode(node) || isComponentNode(node)) {
3666
3693
  let scopeStyles2 = selectors.includes(node.tagName);
3667
3694
  if (!scopeStyles2) {
3668
3695
  for (let a of node.attributes) {