@alloy-js/core 0.22.0-dev.1 → 0.22.0-dev.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/dist/src/components/Block.d.ts.map +1 -1
- package/dist/src/components/Block.js +24 -7
- package/dist/src/components/Block.js.map +1 -1
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/Indent.js +2 -1
- package/dist/src/components/Indent.js.map +1 -1
- package/dist/src/components/Prose.d.ts.map +1 -1
- package/dist/src/components/Prose.js +2 -1
- package/dist/src/components/Prose.js.map +1 -1
- package/dist/src/content-slot.d.ts +51 -0
- package/dist/src/content-slot.d.ts.map +1 -0
- package/dist/src/content-slot.js +69 -0
- package/dist/src/content-slot.js.map +1 -0
- package/dist/src/content-slot.test.d.ts +2 -0
- package/dist/src/content-slot.test.d.ts.map +1 -0
- package/dist/src/content-slot.test.js +57 -0
- package/dist/src/content-slot.test.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/reactivity.d.ts +15 -1
- package/dist/src/reactivity.d.ts.map +1 -1
- package/dist/src/reactivity.js +20 -8
- package/dist/src/reactivity.js.map +1 -1
- package/dist/src/render.d.ts +24 -0
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +98 -2
- package/dist/src/render.js.map +1 -1
- package/dist/src/symbols/decl.d.ts +8 -0
- package/dist/src/symbols/decl.d.ts.map +1 -0
- package/dist/src/symbols/decl.js +22 -0
- package/dist/src/symbols/decl.js.map +1 -0
- package/dist/src/symbols/index.d.ts +1 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +1 -0
- package/dist/src/symbols/index.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +212 -15
- package/dist/src/utils.js.map +1 -1
- package/dist/test/components/block.test.d.ts.map +1 -1
- package/dist/test/components/block.test.js +18 -1
- package/dist/test/components/block.test.js.map +1 -1
- package/dist/test/components/list.test.d.ts.map +1 -1
- package/dist/test/components/list.test.js +80 -1
- package/dist/test/components/list.test.js.map +1 -1
- package/dist/test/control-flow/for.test.js +32 -2
- package/dist/test/control-flow/for.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/Block.tsx +18 -6
- package/src/components/Indent.tsx +4 -2
- package/src/components/Prose.tsx +2 -1
- package/src/content-slot.test.tsx +65 -0
- package/src/content-slot.tsx +91 -0
- package/src/index.ts +1 -0
- package/src/reactivity.ts +38 -5
- package/src/render.ts +112 -3
- package/src/symbols/decl.ts +25 -0
- package/src/symbols/index.ts +1 -0
- package/src/utils.tsx +240 -16
- package/temp/api.json +550 -4
- package/test/components/block.test.tsx +21 -1
- package/test/components/list.test.tsx +76 -1
- package/test/control-flow/for.test.tsx +43 -2
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { expect, it } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createContentSlot,
|
|
4
|
+
List,
|
|
5
|
+
printTree,
|
|
6
|
+
ref,
|
|
7
|
+
renderTree,
|
|
8
|
+
Show,
|
|
9
|
+
} from "../../src/index.js";
|
|
3
10
|
import "../../testing/extend-expect.js";
|
|
4
11
|
import { d } from "../../testing/render.js";
|
|
5
12
|
|
|
@@ -88,3 +95,71 @@ it("is useful for statements", () => {
|
|
|
88
95
|
|
|
89
96
|
`);
|
|
90
97
|
});
|
|
98
|
+
|
|
99
|
+
it("doesn't add joiners when items are empty", () => {
|
|
100
|
+
expect(
|
|
101
|
+
<group>
|
|
102
|
+
<List comma line>
|
|
103
|
+
<></>
|
|
104
|
+
<></>
|
|
105
|
+
<></>
|
|
106
|
+
</List>
|
|
107
|
+
</group>,
|
|
108
|
+
).toRenderTo(``);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("It add joiners when items are become non-empty", () => {
|
|
112
|
+
const item1 = ref("");
|
|
113
|
+
const item2 = ref("");
|
|
114
|
+
const item3 = ref("");
|
|
115
|
+
|
|
116
|
+
const tree = renderTree(
|
|
117
|
+
<group>
|
|
118
|
+
<List comma line ender=";">
|
|
119
|
+
<>{item1}</>
|
|
120
|
+
<>{item2}</>
|
|
121
|
+
<>{item3}</>
|
|
122
|
+
</List>
|
|
123
|
+
</group>,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(printTree(tree)).toBe(``);
|
|
127
|
+
item1.value = "hi";
|
|
128
|
+
expect(printTree(tree)).toBe(`hi;`);
|
|
129
|
+
item2.value = "there";
|
|
130
|
+
expect(printTree(tree)).toBe(`hi, there;`);
|
|
131
|
+
item3.value = "friend";
|
|
132
|
+
expect(printTree(tree)).toBe(`hi, there, friend;`);
|
|
133
|
+
|
|
134
|
+
item1.value = "";
|
|
135
|
+
expect(printTree(tree)).toBe(`there, friend;`);
|
|
136
|
+
item3.value = "";
|
|
137
|
+
expect(printTree(tree)).toBe(`there;`);
|
|
138
|
+
item2.value = "";
|
|
139
|
+
expect(printTree(tree)).toBe(``);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("works with show", () => {
|
|
143
|
+
const ContentSlot = createContentSlot();
|
|
144
|
+
const showFirst = ref(false);
|
|
145
|
+
const showSecond = ref(false);
|
|
146
|
+
const tree = renderTree(
|
|
147
|
+
<>
|
|
148
|
+
<ContentSlot.WhenEmpty>Empty list!</ContentSlot.WhenEmpty>
|
|
149
|
+
<ContentSlot>
|
|
150
|
+
<List comma space>
|
|
151
|
+
<Show when={showFirst.value}>One</Show>
|
|
152
|
+
<Show when={showSecond.value}>Two</Show>
|
|
153
|
+
</List>
|
|
154
|
+
</ContentSlot>
|
|
155
|
+
</>,
|
|
156
|
+
);
|
|
157
|
+
expect(printTree(tree)).toBe(`Empty list!`);
|
|
158
|
+
showFirst.value = true;
|
|
159
|
+
expect(printTree(tree)).toBe(`One`);
|
|
160
|
+
showSecond.value = true;
|
|
161
|
+
expect(printTree(tree)).toBe(`One, Two`);
|
|
162
|
+
showFirst.value = false;
|
|
163
|
+
showSecond.value = false;
|
|
164
|
+
expect(printTree(tree)).toBe(`Empty list!`);
|
|
165
|
+
});
|
|
@@ -2,7 +2,13 @@ import "@alloy-js/core/testing";
|
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { For } from "../../src/components/For.jsx";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
onCleanup,
|
|
7
|
+
printTree,
|
|
8
|
+
reactive,
|
|
9
|
+
ref,
|
|
10
|
+
renderTree,
|
|
11
|
+
} from "../../src/index.js";
|
|
6
12
|
import { flushJobs } from "../../src/scheduler.js";
|
|
7
13
|
|
|
8
14
|
it("works", () => {
|
|
@@ -154,7 +160,13 @@ it("doesn't rerender mappers with maps", () => {
|
|
|
154
160
|
it("doesn't rerender mappers (with splice)", () => {
|
|
155
161
|
const messages = reactive(["hi", "maybe", "bye"]);
|
|
156
162
|
let count = 0;
|
|
157
|
-
const template =
|
|
163
|
+
const template = (
|
|
164
|
+
<For each={messages}>
|
|
165
|
+
{(msg) => {
|
|
166
|
+
return <>item {count++}</>;
|
|
167
|
+
}}
|
|
168
|
+
</For>
|
|
169
|
+
);
|
|
158
170
|
const tree = renderTree(template);
|
|
159
171
|
expect(count).toBe(3);
|
|
160
172
|
messages.splice(1, 1);
|
|
@@ -239,3 +251,32 @@ it("cleans up things which end up removed (with splice)", () => {
|
|
|
239
251
|
Letter c
|
|
240
252
|
`);
|
|
241
253
|
});
|
|
254
|
+
|
|
255
|
+
it("doesn't render empty content", () => {
|
|
256
|
+
const items = [1, 2, 3];
|
|
257
|
+
const tree = renderTree(
|
|
258
|
+
<For each={items}>{(item) => (item > 2 ? item : null)}</For>,
|
|
259
|
+
);
|
|
260
|
+
expect(printTree(tree)).toBe(`3`);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("updates joiners appropriately when items get/lose content", () => {
|
|
264
|
+
const items = [
|
|
265
|
+
{ content: ref("") },
|
|
266
|
+
{ content: ref("") },
|
|
267
|
+
{ content: ref("hello") },
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
const tree = renderTree(
|
|
271
|
+
<For each={items} joiner=", ">
|
|
272
|
+
{(item) => {
|
|
273
|
+
return item.content;
|
|
274
|
+
}}
|
|
275
|
+
</For>,
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
expect(printTree(tree)).toBe(`hello`);
|
|
279
|
+
items[1].content.value = "hi";
|
|
280
|
+
flushJobs();
|
|
281
|
+
expect(printTree(tree)).toBe(`hi, hello`);
|
|
282
|
+
});
|