@torpor/view 0.0.4 → 0.0.5
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 +6 -0
- package/dist/compile.cjs +21 -20
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +21 -20
- package/dist/compile.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/src/compile/build/client/replaceForVarNames.ts +1 -1
- package/test/for/components/ForEscape.torp +1 -0
- package/test/for/components/output/ForEscape-client.ts +11 -2
- package/test/for/components/output/ForEscape-server.ts +1 -1
- package/test/for/components/temp/{ForEscape-client-2c881b16a6382edf074e1f151a209d60ca9b2b66.ts → ForEscape-client-80d3078cf15001f2ab37b0ec63cfce7267a8a166.ts} +11 -2
- package/test/for/components/temp/{ForEscape-server-94a1bceabed006e15326a7f635724d88c3daa8fe.ts → ForEscape-server-375744ca1e10e5c8ed7dd6420beef72107e55568.ts} +1 -1
- package/test/for/for-escape.test.ts +13 -4
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ export default function replaceForVarNames(value: string, status: BuildStatus) {
|
|
|
8
8
|
// get it from the loop data to trigger an update when it is changed
|
|
9
9
|
for (let varName of status.forVarNames) {
|
|
10
10
|
value = value.replaceAll(
|
|
11
|
-
new RegExp(`(
|
|
11
|
+
new RegExp(`(^|\\s|\\(|\\[|\\{)${varName}($|\\s|\\.|\\(|\\)|\\[|\\]|\\}|;)`, "g"),
|
|
12
12
|
`$1t_item.data.${varName}$2`,
|
|
13
13
|
);
|
|
14
14
|
}
|
|
@@ -5,6 +5,7 @@ import t_add_fragment from "../../../../src/render/addFragment";
|
|
|
5
5
|
import t_anchor from "../../../../src/render/nodeAnchor";
|
|
6
6
|
import t_attribute from "../../../../src/render/setAttribute";
|
|
7
7
|
import t_child from "../../../../src/render/nodeChild";
|
|
8
|
+
import t_event from "../../../../src/render/addEvent";
|
|
8
9
|
import t_fmt from "../../../../src/render/formatText";
|
|
9
10
|
import t_fragment from "../../../../src/render/getFragment";
|
|
10
11
|
import t_list_item from "../../../../src/render/newListItem";
|
|
@@ -54,15 +55,16 @@ export default function ForEscape(
|
|
|
54
55
|
},
|
|
55
56
|
function createListItem(t_item, t_before) {
|
|
56
57
|
let t_old_range_1 = t_push_range(t_item, true);
|
|
57
|
-
const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` <p>#</p> <div data-testid=""></div> <div data-testid=""></div> <div data-testid=""></div> `);
|
|
58
|
+
const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` <p>#</p> <div data-testid=""></div> <div data-testid=""></div> <div data-testid=""></div> <input></input> `);
|
|
58
59
|
// @ts-ignore
|
|
59
60
|
const t_root_1 = t_root(t_fragment_1);
|
|
60
61
|
const t_text_1 = t_child(t_next(t_root_1));
|
|
61
62
|
const t_div_1 = t_next(t_next(t_next(t_root_1))) as HTMLDivElement;
|
|
62
63
|
const t_div_2 = t_next(t_next(t_div_1)) as HTMLDivElement;
|
|
63
64
|
const t_div_3 = t_next(t_next(t_div_2)) as HTMLDivElement;
|
|
65
|
+
const t_input_1 = t_next(t_next(t_div_3)) as HTMLInputElement;
|
|
64
66
|
// @ts-ignore
|
|
65
|
-
const t_text_2 = t_next(
|
|
67
|
+
const t_text_2 = t_next(t_input_1);
|
|
66
68
|
$run(function setTextContent() {
|
|
67
69
|
t_text_1.textContent = t_fmt(t_item.data.i);
|
|
68
70
|
});
|
|
@@ -84,6 +86,13 @@ export default function ForEscape(
|
|
|
84
86
|
$run(function setAttribute() {
|
|
85
87
|
t_attribute(t_div_3, "name", things[t_item.data.i]);
|
|
86
88
|
});
|
|
89
|
+
$run(function setBinding() {
|
|
90
|
+
t_input_1.value = t_item.data.i || "";
|
|
91
|
+
});
|
|
92
|
+
t_event(t_input_1, "input", (e) => t_item.data.i = e.target.value);
|
|
93
|
+
$run(function setAttribute() {
|
|
94
|
+
t_attribute(t_input_1, "name", `${t_item.data.i}`);
|
|
95
|
+
});
|
|
87
96
|
t_add_fragment(t_fragment_1, t_section_1, t_before);
|
|
88
97
|
t_next(t_text_2);
|
|
89
98
|
t_pop_range(t_old_range_1);
|
|
@@ -16,7 +16,7 @@ export default function ForEscape(
|
|
|
16
16
|
let $output = "";
|
|
17
17
|
$output += `<section> <![>`;
|
|
18
18
|
for (let i = 0; i < 5; i++) {
|
|
19
|
-
$output += `<!^> <p>${t_fmt(i)}</p> <div data-testid="input1-${t_attr(i)}" ${i ? `name="${t_attr(i)}"` : ''}></div> <div data-testid="input2-${t_attr(i)}" name="${t_attr(i)}"></div> <div data-testid="input3-${t_attr(i)}" ${things[i] ? `name="${t_attr(things[i])}"` : ''}></div> `;
|
|
19
|
+
$output += `<!^> <p>${t_fmt(i)}</p> <div data-testid="input1-${t_attr(i)}" ${i ? `name="${t_attr(i)}"` : ''}></div> <div data-testid="input2-${t_attr(i)}" name="${t_attr(i)}"></div> <div data-testid="input3-${t_attr(i)}" ${things[i] ? `name="${t_attr(things[i])}"` : ''}></div> <input value="${t_attr(i) || ""}" name="${t_attr(i)}"> `;
|
|
20
20
|
}
|
|
21
21
|
$output += `<!]><!> </section>`;
|
|
22
22
|
|
|
@@ -5,6 +5,7 @@ import t_add_fragment from "../../../../src/render/addFragment";
|
|
|
5
5
|
import t_anchor from "../../../../src/render/nodeAnchor";
|
|
6
6
|
import t_attribute from "../../../../src/render/setAttribute";
|
|
7
7
|
import t_child from "../../../../src/render/nodeChild";
|
|
8
|
+
import t_event from "../../../../src/render/addEvent";
|
|
8
9
|
import t_fmt from "../../../../src/render/formatText";
|
|
9
10
|
import t_fragment from "../../../../src/render/getFragment";
|
|
10
11
|
import t_list_item from "../../../../src/render/newListItem";
|
|
@@ -54,15 +55,16 @@ export default function ForEscape(
|
|
|
54
55
|
},
|
|
55
56
|
function createListItem(t_item, t_before) {
|
|
56
57
|
let t_old_range_1 = t_push_range(t_item, true);
|
|
57
|
-
const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` <p>#</p> <div data-testid=""></div> <div data-testid=""></div> <div data-testid=""></div> `);
|
|
58
|
+
const t_fragment_1 = t_fragment($parent.ownerDocument!, t_fragments, 1, ` <p>#</p> <div data-testid=""></div> <div data-testid=""></div> <div data-testid=""></div> <input></input> `);
|
|
58
59
|
// @ts-ignore
|
|
59
60
|
const t_root_1 = t_root(t_fragment_1);
|
|
60
61
|
const t_text_1 = t_child(t_next(t_root_1));
|
|
61
62
|
const t_div_1 = t_next(t_next(t_next(t_root_1))) as HTMLDivElement;
|
|
62
63
|
const t_div_2 = t_next(t_next(t_div_1)) as HTMLDivElement;
|
|
63
64
|
const t_div_3 = t_next(t_next(t_div_2)) as HTMLDivElement;
|
|
65
|
+
const t_input_1 = t_next(t_next(t_div_3)) as HTMLInputElement;
|
|
64
66
|
// @ts-ignore
|
|
65
|
-
const t_text_2 = t_next(
|
|
67
|
+
const t_text_2 = t_next(t_input_1);
|
|
66
68
|
$run(function setTextContent() {
|
|
67
69
|
t_text_1.textContent = t_fmt(t_item.data.i);
|
|
68
70
|
});
|
|
@@ -84,6 +86,13 @@ export default function ForEscape(
|
|
|
84
86
|
$run(function setAttribute() {
|
|
85
87
|
t_attribute(t_div_3, "name", things[t_item.data.i]);
|
|
86
88
|
});
|
|
89
|
+
$run(function setBinding() {
|
|
90
|
+
t_input_1.value = t_item.data.i || "";
|
|
91
|
+
});
|
|
92
|
+
t_event(t_input_1, "input", (e) => t_item.data.i = e.target.value);
|
|
93
|
+
$run(function setAttribute() {
|
|
94
|
+
t_attribute(t_input_1, "name", `${t_item.data.i}`);
|
|
95
|
+
});
|
|
87
96
|
t_add_fragment(t_fragment_1, t_section_1, t_before);
|
|
88
97
|
t_next(t_text_2);
|
|
89
98
|
t_pop_range(t_old_range_1);
|
|
@@ -16,7 +16,7 @@ export default function ForEscape(
|
|
|
16
16
|
let $output = "";
|
|
17
17
|
$output += `<section> <![>`;
|
|
18
18
|
for (let i = 0; i < 5; i++) {
|
|
19
|
-
$output += `<!^> <p>${t_fmt(i)}</p> <div data-testid="input1-${t_attr(i)}" ${i ? `name="${t_attr(i)}"` : ''}></div> <div data-testid="input2-${t_attr(i)}" name="${t_attr(i)}"></div> <div data-testid="input3-${t_attr(i)}" ${things[i] ? `name="${t_attr(things[i])}"` : ''}></div> `;
|
|
19
|
+
$output += `<!^> <p>${t_fmt(i)}</p> <div data-testid="input1-${t_attr(i)}" ${i ? `name="${t_attr(i)}"` : ''}></div> <div data-testid="input2-${t_attr(i)}" name="${t_attr(i)}"></div> <div data-testid="input3-${t_attr(i)}" ${things[i] ? `name="${t_attr(things[i])}"` : ''}></div> <input value="${t_attr(i) || ""}" name="${t_attr(i)}"> `;
|
|
20
20
|
}
|
|
21
21
|
$output += `<!]><!> </section>`;
|
|
22
22
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { queryByTestId } from "@testing-library/dom";
|
|
1
|
+
import { queryByTestId, queryByText } from "@testing-library/dom";
|
|
2
2
|
import "@testing-library/jest-dom/vitest";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
3
4
|
import { beforeAll, expect, test } from "vitest";
|
|
4
5
|
import buildOutputFiles from "../buildOutputFiles";
|
|
5
6
|
import hydrateComponent from "../hydrateComponent";
|
|
@@ -17,7 +18,7 @@ test("for escape -- mounted", async () => {
|
|
|
17
18
|
const component = await importComponent(componentPath, "client");
|
|
18
19
|
mountComponent(container, component);
|
|
19
20
|
|
|
20
|
-
check(container);
|
|
21
|
+
await check(container);
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
test("for escape -- hydrated", async () => {
|
|
@@ -26,10 +27,10 @@ test("for escape -- hydrated", async () => {
|
|
|
26
27
|
const serverComponent = await importComponent(componentPath, "server");
|
|
27
28
|
hydrateComponent(container, clientComponent, serverComponent);
|
|
28
29
|
|
|
29
|
-
check(container);
|
|
30
|
+
await check(container);
|
|
30
31
|
});
|
|
31
32
|
|
|
32
|
-
function check(container: HTMLElement) {
|
|
33
|
+
async function check(container: HTMLElement) {
|
|
33
34
|
expect(queryByTestId(container, "input1-2")).not.toBeNull();
|
|
34
35
|
expect(queryByTestId(container, "input1-2")).toHaveAttribute("name", "2");
|
|
35
36
|
|
|
@@ -38,4 +39,12 @@ function check(container: HTMLElement) {
|
|
|
38
39
|
|
|
39
40
|
expect(queryByTestId(container, "input3-2")).not.toBeNull();
|
|
40
41
|
expect(queryByTestId(container, "input3-2")).toHaveAttribute("name", "c");
|
|
42
|
+
|
|
43
|
+
const user = userEvent.setup();
|
|
44
|
+
const input = container.getElementsByTagName("input")[0];
|
|
45
|
+
|
|
46
|
+
await user.clear(input);
|
|
47
|
+
await user.type(input, "Hello");
|
|
48
|
+
|
|
49
|
+
expect(queryByText(container, "Hello")).not.toBeNull();
|
|
41
50
|
}
|