@torpor/view 0.0.7 → 0.0.8

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,11 @@
1
1
  # @torpor/view
2
2
 
3
+ ## 0.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - a8ead36: Fix: always pass $context down
8
+
3
9
  ## 0.0.7
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/view",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Torpor's view library, for writing and mounting components",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -35,15 +35,15 @@
35
35
  "@testing-library/user-event": "^14.6.1",
36
36
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
37
37
  "@types/jsdom": "^21.1.7",
38
- "@types/node": "^22.13.4",
38
+ "@types/node": "^22.14.0",
39
39
  "fast-glob": "^3.3.3",
40
40
  "jsdom": "^26.0.0",
41
41
  "sucrase": "^3.35.0",
42
- "tinybench": "^3.1.1",
43
- "tsup": "^8.3.6",
44
- "tsx": "^4.19.2",
45
- "typescript": "^5.7.3",
46
- "vitest": "^3.0.5"
42
+ "tinybench": "^4.0.1",
43
+ "tsup": "^8.4.0",
44
+ "tsx": "^4.19.3",
45
+ "typescript": "^5.8.3",
46
+ "vitest": "^3.1.1"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsup && tsx ./scripts/copyToRepl.ts",
@@ -53,12 +53,7 @@ export default function buildSlotNode(node: ElementNode, status: BuildStatus, b:
53
53
  const slotAnchorName = node.varName!;
54
54
 
55
55
  b.append(`if ($slots && $slots["${slotName}"]) {`);
56
- let params = [
57
- slotParentName,
58
- slotAnchorName,
59
- slotHasProps ? propsName : "undefined",
60
- status.contextProps.length ? "$context" : "undefined",
61
- ];
56
+ let params = [slotParentName, slotAnchorName, slotHasProps ? propsName : "undefined", "$context"];
62
57
  b.append(`$slots["${slotName}"](${params.join(", ")})`);
63
58
 
64
59
  // TODO: Maybe not if there's only a single space node?
@@ -33,15 +33,25 @@ async function check(container: HTMLElement) {
33
33
  const user = userEvent.setup();
34
34
 
35
35
  const input = container.getElementsByTagName("input")[0];
36
+ const select = container.getElementsByTagName("select")[0];
36
37
  const para = container.getElementsByTagName("p")[0];
38
+ const para2 = container.getElementsByTagName("p")[1];
37
39
 
38
40
  expect(input).toHaveValue("Alice");
39
41
  expect(para).toHaveTextContent("Hello, Alice");
40
42
 
43
+ expect(select).toHaveValue("1");
44
+ //expect(select.childNodes[1]).toHaveAttribute("selected", true);
45
+ expect(para2).toHaveTextContent("You have selected, 1");
46
+
41
47
  // Update the input value
42
48
  await user.clear(input);
43
49
  await user.type(input, "Bob");
50
+ await user.selectOptions(select, "2");
44
51
 
45
52
  expect(input).toHaveValue("Bob");
46
53
  expect(para).toHaveTextContent("Hello, Bob");
54
+
55
+ expect(select).toHaveValue("2");
56
+ expect(para2).toHaveTextContent("You have selected, 2");
47
57
  }
@@ -1,10 +1,16 @@
1
1
  export default function BindText() {
2
- let $state = $watch({ name: "Alice" });
2
+ let $state = $watch({ name: "Alice", selected: 1 });
3
3
 
4
4
  @render {
5
5
  <div>
6
- <input :value={$state.name} />
7
- <p>Hello, {$state.name}</p>
6
+ <input :value={$state.name} />
7
+ <select :value={$state.selected}>
8
+ <option value=0>First</option>
9
+ <option value=1>Second</option>
10
+ <option value=2>Third</option>
11
+ </select>
12
+ <p>Hello, {$state.name}</p>
13
+ <p>You have selected, {$state.selected}</p>
8
14
  </div>
9
15
  }
10
16
  }
@@ -20,23 +20,32 @@ export default function BindText(
20
20
  $slots?: Record<string, SlotRender>
21
21
  ) {
22
22
 
23
- let $state = $watch({ name: "Alice" });
23
+ let $state = $watch({ name: "Alice", selected: 1 });
24
24
 
25
25
  /* User interface */
26
26
  const t_fragments: DocumentFragment[] = [];
27
27
 
28
- const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, `<div> <input></input> <p>#</p> </div>`);
28
+ const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, `<div> <input></input> <select> <option value=0>First</option> <option value=1>Second</option> <option value=2>Third</option> </select> <p>#</p> <p>#</p> </div>`);
29
29
  // @ts-ignore
30
30
  const t_div_1 = t_root(t_fragment_0) as HTMLDivElement;
31
31
  const t_input_1 = t_next(t_child(t_div_1)) as HTMLInputElement;
32
- const t_text_1 = t_child(t_next(t_next(t_input_1)));
32
+ const t_select_1 = t_next(t_next(t_input_1)) as HTMLElement;
33
+ const t_text_1 = t_child(t_next(t_next(t_select_1)));
34
+ const t_text_2 = t_child(t_next(t_next(t_next(t_next(t_select_1)))));
33
35
  $run(function setBinding() {
34
36
  t_input_1.value = $state.name || "";
35
37
  });
36
38
  t_event(t_input_1, "input", (e) => $state.name = e.target.value);
39
+ $run(function setBinding() {
40
+ t_select_1.value = $state.selected || "";
41
+ });
42
+ t_event(t_select_1, "change", (e) => $state.selected = e.target.value);
37
43
  $run(function setTextContent() {
38
44
  t_text_1.textContent = `Hello, ${t_fmt($state.name)}`;
39
45
  });
46
+ $run(function setTextContent() {
47
+ t_text_2.textContent = `You have selected, ${t_fmt($state.selected)}`;
48
+ });
40
49
  t_add_fragment(t_fragment_0, $parent, $anchor);
41
50
  t_next(t_div_1);
42
51
 
@@ -11,11 +11,11 @@ export default function BindText(
11
11
  // @ts-ignore
12
12
  $slots?: Record<string, ServerSlotRender>
13
13
  ) {
14
- let $state = $watch({ name: "Alice" });
14
+ let $state = $watch({ name: "Alice", selected: 1 });
15
15
 
16
16
  /* User interface */
17
17
  let $output = "";
18
- $output += `<div> <input value="${t_attr($state.name) || ""}"> <p>Hello, ${t_fmt($state.name)}</p> </div>`;
18
+ $output += `<div> <input value="${t_attr($state.name) || ""}"> <select value="${t_attr($state.selected) || ""}"> <option value="0">First</option> <option value="1">Second</option> <option value="2">Third</option> </select> <p>Hello, ${t_fmt($state.name)}</p> <p>You have selected, ${t_fmt($state.selected)}</p> </div>`;
19
19
 
20
20
  return $output;
21
21
  }
@@ -20,23 +20,32 @@ export default function BindText(
20
20
  $slots?: Record<string, SlotRender>
21
21
  ) {
22
22
 
23
- let $state = $watch({ name: "Alice" });
23
+ let $state = $watch({ name: "Alice", selected: 1 });
24
24
 
25
25
  /* User interface */
26
26
  const t_fragments: DocumentFragment[] = [];
27
27
 
28
- const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, `<div> <input></input> <p>#</p> </div>`);
28
+ const t_fragment_0 = t_fragment($parent.ownerDocument!, t_fragments, 0, `<div> <input></input> <select> <option value=0>First</option> <option value=1>Second</option> <option value=2>Third</option> </select> <p>#</p> <p>#</p> </div>`);
29
29
  // @ts-ignore
30
30
  const t_div_1 = t_root(t_fragment_0) as HTMLDivElement;
31
31
  const t_input_1 = t_next(t_child(t_div_1)) as HTMLInputElement;
32
- const t_text_1 = t_child(t_next(t_next(t_input_1)));
32
+ const t_select_1 = t_next(t_next(t_input_1)) as HTMLElement;
33
+ const t_text_1 = t_child(t_next(t_next(t_select_1)));
34
+ const t_text_2 = t_child(t_next(t_next(t_next(t_next(t_select_1)))));
33
35
  $run(function setBinding() {
34
36
  t_input_1.value = $state.name || "";
35
37
  });
36
38
  t_event(t_input_1, "input", (e) => $state.name = e.target.value);
39
+ $run(function setBinding() {
40
+ t_select_1.value = $state.selected || "";
41
+ });
42
+ t_event(t_select_1, "change", (e) => $state.selected = e.target.value);
37
43
  $run(function setTextContent() {
38
44
  t_text_1.textContent = `Hello, ${t_fmt($state.name)}`;
39
45
  });
46
+ $run(function setTextContent() {
47
+ t_text_2.textContent = `You have selected, ${t_fmt($state.selected)}`;
48
+ });
40
49
  t_add_fragment(t_fragment_0, $parent, $anchor);
41
50
  t_next(t_div_1);
42
51
 
@@ -11,11 +11,11 @@ export default function BindText(
11
11
  // @ts-ignore
12
12
  $slots?: Record<string, ServerSlotRender>
13
13
  ) {
14
- let $state = $watch({ name: "Alice" });
14
+ let $state = $watch({ name: "Alice", selected: 1 });
15
15
 
16
16
  /* User interface */
17
17
  let $output = "";
18
- $output += `<div> <input value="${t_attr($state.name) || ""}"> <p>Hello, ${t_fmt($state.name)}</p> </div>`;
18
+ $output += `<div> <input value="${t_attr($state.name) || ""}"> <select value="${t_attr($state.selected) || ""}"> <option value="0">First</option> <option value="1">Second</option> <option value="2">Third</option> </select> <p>Hello, ${t_fmt($state.name)}</p> <p>You have selected, ${t_fmt($state.selected)}</p> </div>`;
19
19
 
20
20
  return $output;
21
21
  }
@@ -24,7 +24,7 @@ export default function FunnyButton(
24
24
  const t_button_1 = t_root(t_fragment_0) as HTMLElement;
25
25
  const t_slot_anchor_1 = t_anchor(t_next(t_child(t_button_1))) as HTMLElement;
26
26
  if ($slots && $slots["_"]) {
27
- $slots["_"](t_button_1, t_slot_anchor_1, undefined, undefined)
27
+ $slots["_"](t_button_1, t_slot_anchor_1, undefined, $context)
28
28
  } else {
29
29
  const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` <span>No content found</span> `);
30
30
  // @ts-ignore
@@ -25,15 +25,15 @@ export default function Article(
25
25
  const t_slot_parent_1 = t_next(t_child(t_section_1)) as HTMLElement;
26
26
  const t_slot_anchor_1 = t_anchor(t_next(t_child(t_slot_parent_1))) as HTMLElement;
27
27
  if ($slots && $slots["header"]) {
28
- $slots["header"](t_slot_parent_1, t_slot_anchor_1, undefined, undefined)
28
+ $slots["header"](t_slot_parent_1, t_slot_anchor_1, undefined, $context)
29
29
  }
30
30
  const t_slot_anchor_2 = t_anchor(t_next(t_next(t_slot_parent_1))) as HTMLElement;
31
31
  if ($slots && $slots["_"]) {
32
- $slots["_"](t_section_1, t_slot_anchor_2, undefined, undefined)
32
+ $slots["_"](t_section_1, t_slot_anchor_2, undefined, $context)
33
33
  }
34
34
  const t_slot_anchor_3 = t_anchor(t_next(t_next(t_slot_anchor_2))) as HTMLElement;
35
35
  if ($slots && $slots["footer"]) {
36
- $slots["footer"](t_section_1, t_slot_anchor_3, undefined, undefined)
36
+ $slots["footer"](t_section_1, t_slot_anchor_3, undefined, $context)
37
37
  }
38
38
  t_add_fragment(t_fragment_0, $parent, $anchor);
39
39
  t_next(t_section_1);
@@ -24,7 +24,7 @@ export default function Header(
24
24
  const t_h2_1 = t_root(t_fragment_0) as HTMLElement;
25
25
  const t_slot_anchor_1 = t_anchor(t_next(t_child(t_h2_1))) as HTMLElement;
26
26
  if ($slots && $slots["_"]) {
27
- $slots["_"](t_h2_1, t_slot_anchor_1, undefined, undefined)
27
+ $slots["_"](t_h2_1, t_slot_anchor_1, undefined, $context)
28
28
  } else {
29
29
  const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` Default header... `);
30
30
  // @ts-ignore
@@ -60,7 +60,7 @@ export default function List(
60
60
  t_sprops_1["item"] = t_item.data.item;
61
61
  });
62
62
  if ($slots && $slots["_"]) {
63
- $slots["_"](t_slot_parent_1, t_slot_anchor_1, t_sprops_1, undefined)
63
+ $slots["_"](t_slot_parent_1, t_slot_anchor_1, t_sprops_1, $context)
64
64
  }
65
65
  // @ts-ignore
66
66
  const t_text_1 = t_next(t_slot_parent_1);
@@ -24,7 +24,7 @@ export default function BigTitle(
24
24
  const t_h2_1 = t_root(t_fragment_0) as HTMLElement;
25
25
  const t_slot_anchor_1 = t_anchor(t_next(t_child(t_h2_1))) as HTMLElement;
26
26
  if ($slots && $slots["_"]) {
27
- $slots["_"](t_h2_1, t_slot_anchor_1, undefined, undefined)
27
+ $slots["_"](t_h2_1, t_slot_anchor_1, undefined, $context)
28
28
  }
29
29
  t_add_fragment(t_fragment_0, $parent, $anchor);
30
30
  t_next(t_h2_1);
@@ -24,7 +24,7 @@ export default function SmallTitle(
24
24
  const t_h6_1 = t_root(t_fragment_0) as HTMLElement;
25
25
  const t_slot_anchor_1 = t_anchor(t_next(t_child(t_h6_1))) as HTMLElement;
26
26
  if ($slots && $slots["_"]) {
27
- $slots["_"](t_h6_1, t_slot_anchor_1, undefined, undefined)
27
+ $slots["_"](t_h6_1, t_slot_anchor_1, undefined, $context)
28
28
  }
29
29
  t_add_fragment(t_fragment_0, $parent, $anchor);
30
30
  t_next(t_h6_1);