@torpor/view 0.0.3 → 0.0.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,12 @@
1
1
  # @torpor/view
2
2
 
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 76dd6ea: Fix: return on invalid style
8
+ - 8f0a0a1: Fix: replace @for vars in more places
9
+
3
10
  ## 0.0.3
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/view",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Torpor's view library, for writing and mounting components",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -13,6 +13,7 @@ import buildFragment from "./buildFragment";
13
13
  import buildMount from "./buildMount";
14
14
  import buildNode from "./buildNode";
15
15
  import buildRun from "./buildRun";
16
+ import replaceForVarNames from "./replaceForVarNames";
16
17
 
17
18
  export default function buildElementNode(
18
19
  node: ElementNode,
@@ -230,6 +231,8 @@ function buildBindGroupAttribute(
230
231
  status: BuildStatus,
231
232
  b: Builder,
232
233
  ) {
234
+ value = replaceForVarNames(value, status);
235
+
233
236
  // Automatically add an event to bind the value
234
237
  // TODO: Only tested this with radio buttons
235
238
  let eventName = "change";
@@ -253,6 +256,8 @@ function buildBindAttribute(
253
256
  status: BuildStatus,
254
257
  b: Builder,
255
258
  ) {
259
+ value = replaceForVarNames(value, status);
260
+
256
261
  // Automatically add an event to bind the value
257
262
  // TODO: Need to check the element to find out what type of event to add
258
263
  let eventName = "input";
@@ -298,14 +303,7 @@ function buildEventAttribute(
298
303
  status: BuildStatus,
299
304
  b: Builder,
300
305
  ) {
301
- // HACK: If a value from a for loop is used in the function body,
302
- // get it from the loop data to trigger an update when it is changed
303
- for (let varName of status.forVarNames) {
304
- value = value.replaceAll(
305
- new RegExp(`([\\s\\(\\[])${varName}([\\s\\.\\(\\)\\[\\];])`, "g"),
306
- `$1t_item.data.${varName}$2`,
307
- );
308
- }
306
+ value = replaceForVarNames(value, status);
309
307
 
310
308
  // Add an event listener, after the fragment has been added
311
309
  const eventName = name.substring(2);
@@ -321,6 +319,8 @@ function buildTransitionAttribute(
321
319
  status: BuildStatus,
322
320
  b: Builder,
323
321
  ) {
322
+ value = replaceForVarNames(value, status);
323
+
324
324
  status.imports.add("t_animate");
325
325
 
326
326
  // Add an in and out transition, after the fragment has been added
@@ -1,22 +1,17 @@
1
1
  import Builder from "../../utils/Builder";
2
2
  import { type BuildStatus } from "./BuildStatus";
3
+ import replaceForVarNames from "./replaceForVarNames";
3
4
 
4
- export default function buildRun(
5
+ export default function buildMount(
5
6
  functionName: string,
6
7
  functionBody: string,
7
8
  status: BuildStatus,
8
9
  b: Builder,
9
10
  ) {
11
+ functionBody = replaceForVarNames(functionBody, status);
12
+
10
13
  status.imports.add("$mount");
11
14
  b.append(`$mount(function ${functionName}() {`);
12
- // HACK: If a value from a for loop is used in the function body,
13
- // get it from the loop data to trigger an update when it is changed
14
- for (let varName of status.forVarNames) {
15
- functionBody = functionBody.replaceAll(
16
- new RegExp(`([\\s\\(\\[])${varName}([\\s\\.\\(\\)\\[\\];])`, "g"),
17
- `$1t_item.data.${varName}$2`,
18
- );
19
- }
20
15
  b.append(functionBody);
21
16
  b.append("});");
22
17
  }
@@ -1,5 +1,6 @@
1
1
  import Builder from "../../utils/Builder";
2
2
  import { type BuildStatus } from "./BuildStatus";
3
+ import replaceForVarNames from "./replaceForVarNames";
3
4
 
4
5
  export default function buildRun(
5
6
  functionName: string,
@@ -7,16 +8,10 @@ export default function buildRun(
7
8
  status: BuildStatus,
8
9
  b: Builder,
9
10
  ) {
11
+ functionBody = replaceForVarNames(functionBody, status);
12
+
10
13
  status.imports.add("$run");
11
14
  b.append(`$run(function ${functionName}() {`);
12
- // HACK: If a value from a for loop is used in the function body,
13
- // get it from the loop data to trigger an update when it is changed
14
- for (let varName of status.forVarNames) {
15
- functionBody = functionBody.replaceAll(
16
- new RegExp(`([\\s\\(\\[\\{])${varName}([\\s\\.\\(\\)\\[\\]\\};])`, "g"),
17
- `$1t_item.data.${varName}$2`,
18
- );
19
- }
20
15
  b.append(functionBody);
21
16
  b.append("});");
22
17
  }
@@ -0,0 +1,16 @@
1
+ import type { BuildStatus } from "./BuildStatus";
2
+
3
+ /**
4
+ * Variables used within a for loop need to be retrieved from the loop data.
5
+ */
6
+ export default function replaceForVarNames(value: string, status: BuildStatus) {
7
+ // HACK: If a value from a for loop is used in the function body,
8
+ // get it from the loop data to trigger an update when it is changed
9
+ for (let varName of status.forVarNames) {
10
+ value = value.replaceAll(
11
+ new RegExp(`([\\s\\(\\[\\{])${varName}([\\s\\.\\(\\)\\[\\]\\};])`, "g"),
12
+ `$1t_item.data.${varName}$2`,
13
+ );
14
+ }
15
+ return value;
16
+ }
@@ -70,6 +70,8 @@ function parseStyleBlock(status: ParseStatus): StyleBlock | undefined {
70
70
  } else {
71
71
  break;
72
72
  }
73
+ } else {
74
+ return block;
73
75
  }
74
76
  consumeSpace(status);
75
77
  }