@torpor/view 0.0.12 → 0.0.14

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,18 @@
1
1
  # @torpor/view
2
2
 
3
+ ## 0.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - fb896c6: Fix: make sure we've got $props on the server
8
+ - 85bccf6: Fix: apply scope to elements without a class
9
+
10
+ ## 0.0.13
11
+
12
+ ### Patch Changes
13
+
14
+ - ed4a6db: Fix: include quoted content in styles
15
+
3
16
  ## 0.0.12
4
17
 
5
18
  ### Patch Changes
package/dist/compile.cjs CHANGED
@@ -203,6 +203,7 @@ function buildComponentFragmentText(node, status, fragments, currentFragment) {
203
203
  }
204
204
  }
205
205
  function buildElementFragmentText(node, status, fragments, currentFragment) {
206
+ let needsClass = node.scopeStyles;
206
207
  currentFragment.text += `<${node.tagName}`;
207
208
  let attributesText = node.attributes.filter((a) => !a.name.startsWith("on") && !a.name.includes(":")).map((a) => {
208
209
  if (a.value && isReactive(a.value) && !a.name.includes(":")) {
@@ -210,6 +211,7 @@ function buildElementFragmentText(node, status, fragments, currentFragment) {
210
211
  return `${a.name}=""`;
211
212
  }
212
213
  } else if (a.name === "class" && node.scopeStyles) {
214
+ needsClass = false;
213
215
  let value = a.value ? `"${trimQuotes(a.value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
214
216
  return `${a.name}=${value}`;
215
217
  } else {
@@ -219,6 +221,9 @@ function buildElementFragmentText(node, status, fragments, currentFragment) {
219
221
  if (attributesText) {
220
222
  currentFragment.text += " " + attributesText;
221
223
  }
224
+ if (needsClass) {
225
+ currentFragment.text += ` class="torp-${status.styleHash}"`;
226
+ }
222
227
  currentFragment.text += ">";
223
228
  for (let child of node.children) {
224
229
  buildNodeFragmentText(child, status, fragments, currentFragment);
@@ -2412,6 +2417,7 @@ function buildServerElementNode(node, status, b) {
2412
2417
  }
2413
2418
  }
2414
2419
  function buildElementAttributes2(node, status) {
2420
+ let needsClass = node.scopeStyles;
2415
2421
  let attributes = [];
2416
2422
  for (let { name, value } of node.attributes) {
2417
2423
  if (name === "self" && node.tagName === ":element") {
@@ -2460,6 +2466,7 @@ function buildElementAttributes2(node, status) {
2460
2466
  status.imports.add("t_class");
2461
2467
  if (node.scopeStyles) {
2462
2468
  value += `, "torp-${status.styleHash}"`;
2469
+ needsClass = false;
2463
2470
  }
2464
2471
  attributes.push(`class="\${t_class(${value})}"`);
2465
2472
  } else if (name === ":style") {
@@ -2477,12 +2484,16 @@ function buildElementAttributes2(node, status) {
2477
2484
  } else if (name === "class" && node.scopeStyles) {
2478
2485
  value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
2479
2486
  attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
2487
+ needsClass = false;
2480
2488
  } else if (value != null) {
2481
2489
  attributes.push(`${name}="${trimQuotes(value).replaceAll('"', "&quot;")}"`);
2482
2490
  } else {
2483
2491
  attributes.push(`${name}`);
2484
2492
  }
2485
2493
  }
2494
+ if (needsClass) {
2495
+ attributes.push(`class="torp-${status.styleHash}"`);
2496
+ }
2486
2497
  return attributes.join(" ");
2487
2498
  }
2488
2499
 
@@ -2719,6 +2730,9 @@ function buildServerTemplate(template, imports, b, options) {
2719
2730
  marker = i + "/* @params */".length;
2720
2731
  } else if (script.substring(i, i + "/* @start */".length) === "/* @start */") {
2721
2732
  b.append(script.substring(marker, i));
2733
+ if (current.props?.length) {
2734
+ b.append(`$props ??= {};`);
2735
+ }
2722
2736
  if (current.contextProps?.length) {
2723
2737
  b.append(`$context = Object.assign({}, $context);`);
2724
2738
  }
@@ -3805,15 +3819,19 @@ function parseComponentStyle(status) {
3805
3819
  } else if (char === "/" && nextChar === "*") {
3806
3820
  status.i = status.source.indexOf("*/", status.i) + 1;
3807
3821
  } else if (char === '"' || char === "'") {
3822
+ styleSource += char;
3808
3823
  for (let j = status.i + 1; j < status.source.length; j++) {
3824
+ styleSource += status.source[j];
3809
3825
  if (status.source[j] === char && status.source[j - 1] !== "\\") {
3810
3826
  status.i = j;
3811
3827
  break;
3812
3828
  }
3813
3829
  }
3814
3830
  } else if (char === "`") {
3831
+ styleSource += char;
3815
3832
  let level2 = 0;
3816
3833
  for (let j = status.i + 1; j < status.source.length; j++) {
3834
+ styleSource += status.source[j];
3817
3835
  if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
3818
3836
  status.i = j;
3819
3837
  break;