@joist/templating 4.2.4-next.16 → 4.2.4-next.18
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/package.json +1 -1
- package/src/lib/define.ts +1 -3
- package/src/lib/elements/bind.element.test.ts +4 -4
- package/src/lib/elements/bind.element.ts +15 -13
- package/src/lib/elements/for.element.test.ts +12 -7
- package/src/lib/elements/for.element.ts +78 -30
- package/src/lib/elements/if.element.ts +8 -6
- package/src/lib/events.ts +1 -1
- package/target/lib/define.d.ts +1 -2
- package/target/lib/define.js +1 -2
- package/target/lib/define.js.map +1 -1
- package/target/lib/elements/bind.element.js +16 -14
- package/target/lib/elements/bind.element.js.map +1 -1
- package/target/lib/elements/bind.element.test.js +4 -4
- package/target/lib/elements/for.element.d.ts +0 -4
- package/target/lib/elements/for.element.js +64 -48
- package/target/lib/elements/for.element.js.map +1 -1
- package/target/lib/elements/for.element.test.js +6 -3
- package/target/lib/elements/for.element.test.js.map +1 -1
- package/target/lib/elements/if.element.js +8 -6
- package/target/lib/elements/if.element.js.map +1 -1
- package/target/lib/events.d.ts +1 -1
package/package.json
CHANGED
package/src/lib/define.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { define } from "@joist/element/define.js";
|
|
2
2
|
|
|
3
3
|
import { JoistAsyncElement } from "./elements/async.element.js";
|
|
4
|
-
import {
|
|
4
|
+
import { JoistForElement } from "./elements/for.element.js";
|
|
5
5
|
import { JoistIfElement } from "./elements/if.element.js";
|
|
6
6
|
import { JoistBindElement } from "./elements/bind.element.js";
|
|
7
7
|
import { JoistValueElement } from "./elements/value.element.js";
|
|
@@ -11,7 +11,6 @@ declare global {
|
|
|
11
11
|
interface HTMLElementTagNameMap {
|
|
12
12
|
"j-async": JoistAsyncElement;
|
|
13
13
|
"j-for": JoistForElement;
|
|
14
|
-
"j-for-scope": JForScope;
|
|
15
14
|
"j-if": JoistIfElement;
|
|
16
15
|
"j-bind": JoistBindElement;
|
|
17
16
|
"j-val": JoistValueElement;
|
|
@@ -21,7 +20,6 @@ declare global {
|
|
|
21
20
|
|
|
22
21
|
define({ tagName: "j-async" }, JoistAsyncElement);
|
|
23
22
|
define({ tagName: "j-for" }, JoistForElement);
|
|
24
|
-
define({ tagName: "j-for-scope", dependsOn: ["j-for"] }, JForScope);
|
|
25
23
|
define({ tagName: "j-if" }, JoistIfElement);
|
|
26
24
|
define({ tagName: "j-bind" }, JoistBindElement);
|
|
27
25
|
define({ tagName: "j-val" }, JoistValueElement);
|
|
@@ -48,10 +48,10 @@ it("should pass props to specified child", () => {
|
|
|
48
48
|
});
|
|
49
49
|
}}
|
|
50
50
|
>
|
|
51
|
-
<j-bind attrs="href:href" target="#test">
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
</
|
|
51
|
+
<j-bind attrs="href:href" target="#test"></j-bind>
|
|
52
|
+
|
|
53
|
+
<a>Default</a>
|
|
54
|
+
<a id="test">Target</a>
|
|
55
55
|
</div>
|
|
56
56
|
`);
|
|
57
57
|
|
|
@@ -33,26 +33,26 @@ export class JoistBindElement extends HTMLElement {
|
|
|
33
33
|
const attrBindings = this.#parseBinding(this.attrs);
|
|
34
34
|
const propBindings = this.#parseBinding(this.props);
|
|
35
35
|
|
|
36
|
-
let
|
|
36
|
+
let children: Iterable<Element> = this.children;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
child = this.querySelector(this.target);
|
|
40
|
-
}
|
|
38
|
+
const root = this.getRootNode() as Document | ShadowRoot;
|
|
41
39
|
|
|
42
|
-
if (
|
|
43
|
-
|
|
40
|
+
if (this.target) {
|
|
41
|
+
children = root.querySelectorAll(this.target);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
for (const attrValue of attrBindings) {
|
|
47
45
|
const token = new JAttrToken(attrValue);
|
|
48
46
|
|
|
49
47
|
this.#dispatch(token, (value) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
for (const child of children) {
|
|
49
|
+
if (value === true) {
|
|
50
|
+
child.setAttribute(token.mapTo, "");
|
|
51
|
+
} else if (value === false) {
|
|
52
|
+
child.removeAttribute(token.mapTo);
|
|
53
|
+
} else {
|
|
54
|
+
child.setAttribute(token.mapTo, String(value));
|
|
55
|
+
}
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
}
|
|
@@ -61,7 +61,9 @@ export class JoistBindElement extends HTMLElement {
|
|
|
61
61
|
const token = new JAttrToken(propValue);
|
|
62
62
|
|
|
63
63
|
this.#dispatch(token, (value) => {
|
|
64
|
-
|
|
64
|
+
for (const child of children) {
|
|
65
|
+
Reflect.set(child, token.mapTo, value);
|
|
66
|
+
}
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -117,14 +117,17 @@ it("should provide index and position information", () => {
|
|
|
117
117
|
>
|
|
118
118
|
<j-for bind="items">
|
|
119
119
|
<template>
|
|
120
|
-
<
|
|
121
|
-
|
|
120
|
+
<div class="item">
|
|
121
|
+
<j-val bind="each.value"></j-val>
|
|
122
|
+
(index: <j-val bind="each.index"></j-val>, position:
|
|
123
|
+
<j-val bind="each.position"></j-val>)
|
|
124
|
+
</div>
|
|
122
125
|
</template>
|
|
123
126
|
</j-for>
|
|
124
127
|
</div>
|
|
125
128
|
`);
|
|
126
129
|
|
|
127
|
-
const items = element.querySelectorAll("
|
|
130
|
+
const items = element.querySelectorAll(".item");
|
|
128
131
|
assert.equal(items.length, 3);
|
|
129
132
|
assert.equal(
|
|
130
133
|
items[0].textContent?.trim().replaceAll("\n", "").replaceAll(" ", ""),
|
|
@@ -170,12 +173,14 @@ it("should provide index and position information", () => {
|
|
|
170
173
|
// const groups = element.querySelectorAll(".group");
|
|
171
174
|
// assert.equal(groups.length, 2);
|
|
172
175
|
|
|
176
|
+
// console.log(groups);
|
|
177
|
+
|
|
173
178
|
// const items = element.querySelectorAll(".child");
|
|
174
179
|
// assert.equal(items.length, 4);
|
|
175
|
-
// assert.equal(items[0].textContent?.trim(), "A");
|
|
176
|
-
// assert.equal(items[1].textContent?.trim(), "B");
|
|
177
|
-
// assert.equal(items[2].textContent?.trim(), "C");
|
|
178
|
-
// assert.equal(items[3].textContent?.trim(), "D");
|
|
180
|
+
// // assert.equal(items[0].textContent?.trim(), "A");
|
|
181
|
+
// // assert.equal(items[1].textContent?.trim(), "B");
|
|
182
|
+
// // assert.equal(items[2].textContent?.trim(), "C");
|
|
183
|
+
// // assert.equal(items[3].textContent?.trim(), "D");
|
|
179
184
|
// });
|
|
180
185
|
|
|
181
186
|
it("should maintain DOM order when items are reordered", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { attr, element, query, css, html } from "@joist/element";
|
|
2
|
+
import { Change, Changes, effect, observe } from "@joist/observable";
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import { JoistValueEvent } from "../events.js";
|
|
4
|
+
import { BindChange, JoistValueEvent } from "../events.js";
|
|
5
5
|
import { JExpression } from "../expression.js";
|
|
6
6
|
|
|
7
7
|
export interface EachCtx<T> {
|
|
@@ -10,20 +10,56 @@ export interface EachCtx<T> {
|
|
|
10
10
|
position: number | null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
class JoistForScopeContainer<T = unknown> {
|
|
14
|
+
host: Element;
|
|
15
|
+
|
|
16
|
+
get key(): string | null {
|
|
17
|
+
return this.host.getAttribute("key");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#callbacks: Array<(val: BindChange<EachCtx<T>>) => void> = [];
|
|
21
|
+
|
|
22
|
+
@observe()
|
|
19
23
|
accessor each: EachCtx<T> = {
|
|
20
24
|
value: null,
|
|
21
25
|
index: null,
|
|
22
26
|
position: null,
|
|
23
27
|
};
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
constructor(host: Element | null) {
|
|
30
|
+
if (host == null) {
|
|
31
|
+
throw new Error("JForScope required a host element");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.host = host;
|
|
35
|
+
|
|
36
|
+
this.host.addEventListener("joist::value", (e) => {
|
|
37
|
+
if (e.expression.bindTo === "each") {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
|
|
40
|
+
this.#callbacks.push(e.update);
|
|
41
|
+
|
|
42
|
+
e.update({
|
|
43
|
+
oldValue: null,
|
|
44
|
+
newValue: this.each,
|
|
45
|
+
firstChange: true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@effect()
|
|
52
|
+
onChange(changes: Changes<this>): void {
|
|
53
|
+
const change = changes.get("each") as Change<EachCtx<T>>;
|
|
54
|
+
|
|
55
|
+
for (let cb of this.#callbacks) {
|
|
56
|
+
cb({
|
|
57
|
+
oldValue: change.oldValue,
|
|
58
|
+
newValue: change.newValue,
|
|
59
|
+
firstChange: false,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
27
63
|
}
|
|
28
64
|
|
|
29
65
|
@element({
|
|
@@ -39,7 +75,7 @@ export class JoistForElement extends HTMLElement {
|
|
|
39
75
|
|
|
40
76
|
#template = query("template", this);
|
|
41
77
|
#items: Iterable<unknown> = [];
|
|
42
|
-
#scopes = new Map<
|
|
78
|
+
#scopes = new Map<string, JoistForScopeContainer>();
|
|
43
79
|
|
|
44
80
|
connectedCallback(): void {
|
|
45
81
|
const template = this.#template();
|
|
@@ -50,8 +86,8 @@ export class JoistForElement extends HTMLElement {
|
|
|
50
86
|
|
|
51
87
|
// collect all scopes from the template to be matched against later
|
|
52
88
|
let currentScope = template.nextElementSibling;
|
|
53
|
-
while (currentScope instanceof
|
|
54
|
-
this.#scopes.set(currentScope.key, currentScope);
|
|
89
|
+
while (currentScope instanceof JoistForScopeContainer) {
|
|
90
|
+
this.#scopes.set(String(currentScope.key), currentScope);
|
|
55
91
|
currentScope = currentScope.nextElementSibling;
|
|
56
92
|
}
|
|
57
93
|
|
|
@@ -82,8 +118,6 @@ export class JoistForElement extends HTMLElement {
|
|
|
82
118
|
// Updates the DOM by either inserting new scopes or moving existing ones
|
|
83
119
|
// to their correct positions based on the current iteration order
|
|
84
120
|
createFromEmpty(): void {
|
|
85
|
-
const template = this.#template();
|
|
86
|
-
const templateContent = template.content;
|
|
87
121
|
const keyProperty = this.key;
|
|
88
122
|
const fragment = document.createDocumentFragment();
|
|
89
123
|
|
|
@@ -95,13 +129,15 @@ export class JoistForElement extends HTMLElement {
|
|
|
95
129
|
key = value[keyProperty];
|
|
96
130
|
}
|
|
97
131
|
|
|
98
|
-
const scope =
|
|
99
|
-
|
|
100
|
-
scope.key
|
|
132
|
+
const scope = this.#createScopeContainer();
|
|
133
|
+
|
|
134
|
+
scope.host.setAttribute("key", String(key));
|
|
101
135
|
scope.each = { position: index + 1, index, value };
|
|
102
136
|
|
|
103
|
-
fragment.appendChild(scope);
|
|
104
|
-
|
|
137
|
+
fragment.appendChild(scope.host);
|
|
138
|
+
|
|
139
|
+
this.#scopes.set(String(key), scope);
|
|
140
|
+
|
|
105
141
|
index++;
|
|
106
142
|
}
|
|
107
143
|
|
|
@@ -111,8 +147,7 @@ export class JoistForElement extends HTMLElement {
|
|
|
111
147
|
// Updates the DOM by either inserting new scopes or moving existing ones
|
|
112
148
|
// to their correct positions based on the current iteration order
|
|
113
149
|
updateItems(): void {
|
|
114
|
-
const
|
|
115
|
-
const leftoverScopes = new Map<unknown, JForScope>(this.#scopes);
|
|
150
|
+
const leftoverScopes = new Map<unknown, JoistForScopeContainer>(this.#scopes);
|
|
116
151
|
const keyProperty = this.key;
|
|
117
152
|
|
|
118
153
|
let index = 0;
|
|
@@ -127,23 +162,23 @@ export class JoistForElement extends HTMLElement {
|
|
|
127
162
|
let scope = leftoverScopes.get(key);
|
|
128
163
|
|
|
129
164
|
if (!scope) {
|
|
130
|
-
scope =
|
|
131
|
-
|
|
132
|
-
this.#scopes.set(key, scope);
|
|
165
|
+
scope = scope = this.#createScopeContainer();
|
|
166
|
+
|
|
167
|
+
this.#scopes.set(String(key), scope);
|
|
133
168
|
} else {
|
|
134
169
|
leftoverScopes.delete(key); // Remove from map to track unused scopes
|
|
135
170
|
}
|
|
136
171
|
|
|
137
172
|
// Only update if values have changed
|
|
138
173
|
if (scope.key !== key || scope.each.value !== value) {
|
|
139
|
-
scope.key
|
|
174
|
+
scope.host.setAttribute("key", String(key));
|
|
140
175
|
scope.each = { position: index + 1, index, value };
|
|
141
176
|
}
|
|
142
177
|
|
|
143
178
|
const child = this.children[index + 1];
|
|
144
179
|
|
|
145
|
-
if (child !== scope) {
|
|
146
|
-
this.insertBefore(scope, child);
|
|
180
|
+
if (child !== scope.host) {
|
|
181
|
+
this.insertBefore(scope.host, child);
|
|
147
182
|
}
|
|
148
183
|
|
|
149
184
|
index++;
|
|
@@ -151,18 +186,31 @@ export class JoistForElement extends HTMLElement {
|
|
|
151
186
|
|
|
152
187
|
// Remove unused scopes
|
|
153
188
|
for (const scope of leftoverScopes.values()) {
|
|
154
|
-
scope.remove();
|
|
189
|
+
scope.host.remove();
|
|
155
190
|
}
|
|
156
191
|
}
|
|
157
192
|
|
|
158
193
|
disconnectedCallback(): void {
|
|
159
194
|
for (const scope of this.#scopes.values()) {
|
|
160
|
-
scope.remove();
|
|
195
|
+
scope.host.remove();
|
|
161
196
|
}
|
|
162
197
|
|
|
163
198
|
this.#scopes.clear();
|
|
164
199
|
this.#items = [];
|
|
165
200
|
}
|
|
201
|
+
|
|
202
|
+
#createScopeContainer() {
|
|
203
|
+
const template = this.#template();
|
|
204
|
+
const content = template.content.firstElementChild;
|
|
205
|
+
|
|
206
|
+
if (content === null) {
|
|
207
|
+
throw new Error("template must contain a single parent element");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const fragment = document.importNode(content, true);
|
|
211
|
+
|
|
212
|
+
return new JoistForScopeContainer(fragment);
|
|
213
|
+
}
|
|
166
214
|
}
|
|
167
215
|
|
|
168
216
|
function isIterable<T = unknown>(obj: any): obj is Iterable<T> {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { attr, element, queryAll, css
|
|
1
|
+
import { attr, element, queryAll, css } from "@joist/element";
|
|
2
2
|
|
|
3
3
|
import { JoistValueEvent } from "../events.js";
|
|
4
4
|
import { JExpression } from "../expression.js";
|
|
5
5
|
|
|
6
6
|
@element({
|
|
7
7
|
// prettier-ignore
|
|
8
|
-
shadowDom: [css`:host{display:
|
|
8
|
+
shadowDom: [css`:host{display: none;}`],
|
|
9
9
|
})
|
|
10
10
|
export class JoistIfElement extends HTMLElement {
|
|
11
11
|
@attr()
|
|
12
12
|
accessor bind = "";
|
|
13
13
|
|
|
14
|
+
#endMarker = document.createComment("joist::endif");
|
|
14
15
|
#templates = queryAll<HTMLTemplateElement>("template", this);
|
|
15
|
-
|
|
16
16
|
#shouldShowIf: boolean | null = null;
|
|
17
17
|
|
|
18
18
|
connectedCallback(): void {
|
|
@@ -35,6 +35,8 @@ export class JoistIfElement extends HTMLElement {
|
|
|
35
35
|
[templates[0], templates[1]] = [templates[1], templates[0]];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
this.after(this.#endMarker);
|
|
39
|
+
|
|
38
40
|
// make sure there are no other nodes after the template
|
|
39
41
|
this.#clean();
|
|
40
42
|
|
|
@@ -67,13 +69,13 @@ export class JoistIfElement extends HTMLElement {
|
|
|
67
69
|
if (templateToUse) {
|
|
68
70
|
const content = document.importNode(templateToUse.content, true);
|
|
69
71
|
|
|
70
|
-
this.
|
|
72
|
+
this.after(content);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
#clean(): void {
|
|
75
|
-
while (
|
|
76
|
-
this.
|
|
77
|
+
while (this.nextSibling !== this.#endMarker) {
|
|
78
|
+
this.nextSibling?.remove();
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
|
package/src/lib/events.ts
CHANGED
package/target/lib/define.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JoistAsyncElement } from "./elements/async.element.js";
|
|
2
|
-
import {
|
|
2
|
+
import { JoistForElement } from "./elements/for.element.js";
|
|
3
3
|
import { JoistIfElement } from "./elements/if.element.js";
|
|
4
4
|
import { JoistBindElement } from "./elements/bind.element.js";
|
|
5
5
|
import { JoistValueElement } from "./elements/value.element.js";
|
|
@@ -8,7 +8,6 @@ declare global {
|
|
|
8
8
|
interface HTMLElementTagNameMap {
|
|
9
9
|
"j-async": JoistAsyncElement;
|
|
10
10
|
"j-for": JoistForElement;
|
|
11
|
-
"j-for-scope": JForScope;
|
|
12
11
|
"j-if": JoistIfElement;
|
|
13
12
|
"j-bind": JoistBindElement;
|
|
14
13
|
"j-val": JoistValueElement;
|
package/target/lib/define.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { define } from "@joist/element/define.js";
|
|
2
2
|
import { JoistAsyncElement } from "./elements/async.element.js";
|
|
3
|
-
import {
|
|
3
|
+
import { JoistForElement } from "./elements/for.element.js";
|
|
4
4
|
import { JoistIfElement } from "./elements/if.element.js";
|
|
5
5
|
import { JoistBindElement } from "./elements/bind.element.js";
|
|
6
6
|
import { JoistValueElement } from "./elements/value.element.js";
|
|
7
7
|
import { JoistScopeElement } from "./elements/scope.element.js";
|
|
8
8
|
define({ tagName: "j-async" }, JoistAsyncElement);
|
|
9
9
|
define({ tagName: "j-for" }, JoistForElement);
|
|
10
|
-
define({ tagName: "j-for-scope", dependsOn: ["j-for"] }, JForScope);
|
|
11
10
|
define({ tagName: "j-if" }, JoistIfElement);
|
|
12
11
|
define({ tagName: "j-bind" }, JoistBindElement);
|
|
13
12
|
define({ tagName: "j-val" }, JoistValueElement);
|
package/target/lib/define.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/lib/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/lib/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAahE,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAClD,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,eAAe,CAAC,CAAC;AAC9C,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,CAAC;AAC5C,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAC;AAChD,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAChD,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,iBAAiB,CAAC,CAAC"}
|
|
@@ -54,31 +54,33 @@ let JoistBindElement = (() => {
|
|
|
54
54
|
connectedCallback() {
|
|
55
55
|
const attrBindings = this.#parseBinding(this.attrs);
|
|
56
56
|
const propBindings = this.#parseBinding(this.props);
|
|
57
|
-
let
|
|
57
|
+
let children = this.children;
|
|
58
|
+
const root = this.getRootNode();
|
|
58
59
|
if (this.target) {
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
if (!child) {
|
|
62
|
-
throw new Error("j-bind must have a child element or defined target");
|
|
60
|
+
children = root.querySelectorAll(this.target);
|
|
63
61
|
}
|
|
64
62
|
for (const attrValue of attrBindings) {
|
|
65
63
|
const token = new JAttrToken(attrValue);
|
|
66
64
|
this.#dispatch(token, (value) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
for (const child of children) {
|
|
66
|
+
if (value === true) {
|
|
67
|
+
child.setAttribute(token.mapTo, "");
|
|
68
|
+
}
|
|
69
|
+
else if (value === false) {
|
|
70
|
+
child.removeAttribute(token.mapTo);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
child.setAttribute(token.mapTo, String(value));
|
|
74
|
+
}
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
for (const propValue of propBindings) {
|
|
79
79
|
const token = new JAttrToken(propValue);
|
|
80
80
|
this.#dispatch(token, (value) => {
|
|
81
|
-
|
|
81
|
+
for (const child of children) {
|
|
82
|
+
Reflect.set(child, token.mapTo, value);
|
|
83
|
+
}
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.element.js","sourceRoot":"","sources":["../../../src/lib/elements/bind.element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,OAAO,UAAW,SAAQ,WAAW;IACzC,KAAK,CAAS;IAEd,YAAY,OAAe;QACzB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAA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AAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAE/C,IAAI,eAAe,KAAK,YAAY,EAAE,CAAC;oBACrC,OAAO;gBACT,CAAC;gBAED,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;oBACpB,YAAY,GAAG,CAAC,YAAY,CAAC;gBAC/B,CAAC;gBAED,KAAK,CAAC,YAAY,CAAC,CAAC;YACtB,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;;;;;;;;SA7EU,gBAAgB"}
|
|
@@ -40,10 +40,10 @@ it("should pass props to specified child", () => {
|
|
|
40
40
|
});
|
|
41
41
|
}}
|
|
42
42
|
>
|
|
43
|
-
<j-bind attrs="href:href" target="#test">
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</
|
|
43
|
+
<j-bind attrs="href:href" target="#test"></j-bind>
|
|
44
|
+
|
|
45
|
+
<a>Default</a>
|
|
46
|
+
<a id="test">Target</a>
|
|
47
47
|
</div>
|
|
48
48
|
`);
|
|
49
49
|
const anchor = element.querySelectorAll("a");
|
|
@@ -3,10 +3,6 @@ export interface EachCtx<T> {
|
|
|
3
3
|
index: number | null;
|
|
4
4
|
position: number | null;
|
|
5
5
|
}
|
|
6
|
-
export declare class JForScope<T = unknown> extends HTMLElement {
|
|
7
|
-
accessor each: EachCtx<T>;
|
|
8
|
-
accessor key: unknown;
|
|
9
|
-
}
|
|
10
6
|
export declare class JoistForElement extends HTMLElement {
|
|
11
7
|
#private;
|
|
12
8
|
accessor bind: string;
|
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
2
|
import { attr, element, query, css, html } from "@joist/element";
|
|
3
|
-
import {
|
|
3
|
+
import { effect, observe } from "@joist/observable";
|
|
4
4
|
import { JoistValueEvent } from "../events.js";
|
|
5
5
|
import { JExpression } from "../expression.js";
|
|
6
|
-
let
|
|
7
|
-
let
|
|
8
|
-
shadowDom: [css `:host{display:contents;}`, html `<slot></slot>`],
|
|
9
|
-
})];
|
|
10
|
-
let _classDescriptor;
|
|
11
|
-
let _classExtraInitializers = [];
|
|
12
|
-
let _classThis;
|
|
13
|
-
let _classSuper = HTMLElement;
|
|
6
|
+
let JoistForScopeContainer = (() => {
|
|
7
|
+
let _instanceExtraInitializers = [];
|
|
14
8
|
let _each_decorators;
|
|
15
9
|
let _each_initializers = [];
|
|
16
10
|
let _each_extraInitializers = [];
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
let _key_extraInitializers = [];
|
|
20
|
-
var JForScope = class extends _classSuper {
|
|
21
|
-
static { _classThis = this; }
|
|
11
|
+
let _onChange_decorators;
|
|
12
|
+
return class JoistForScopeContainer {
|
|
22
13
|
static {
|
|
23
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(
|
|
24
|
-
_each_decorators = [
|
|
25
|
-
|
|
14
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
15
|
+
_each_decorators = [observe()];
|
|
16
|
+
_onChange_decorators = [effect()];
|
|
26
17
|
__esDecorate(this, null, _each_decorators, { kind: "accessor", name: "each", static: false, private: false, access: { has: obj => "each" in obj, get: obj => obj.each, set: (obj, value) => { obj.each = value; } }, metadata: _metadata }, _each_initializers, _each_extraInitializers);
|
|
27
|
-
__esDecorate(this, null,
|
|
28
|
-
|
|
29
|
-
JForScope = _classThis = _classDescriptor.value;
|
|
30
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
31
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
18
|
+
__esDecorate(this, null, _onChange_decorators, { kind: "method", name: "onChange", static: false, private: false, access: { has: obj => "onChange" in obj, get: obj => obj.onChange }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
19
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
32
20
|
}
|
|
21
|
+
host = __runInitializers(this, _instanceExtraInitializers);
|
|
22
|
+
get key() {
|
|
23
|
+
return this.host.getAttribute("key");
|
|
24
|
+
}
|
|
25
|
+
#callbacks = [];
|
|
33
26
|
#each_accessor_storage = __runInitializers(this, _each_initializers, {
|
|
34
27
|
value: null,
|
|
35
28
|
index: null,
|
|
@@ -37,17 +30,36 @@ let JForScope = (() => {
|
|
|
37
30
|
});
|
|
38
31
|
get each() { return this.#each_accessor_storage; }
|
|
39
32
|
set each(value) { this.#each_accessor_storage = value; }
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
constructor(host) {
|
|
34
|
+
__runInitializers(this, _each_extraInitializers);
|
|
35
|
+
if (host == null) {
|
|
36
|
+
throw new Error("JForScope required a host element");
|
|
37
|
+
}
|
|
38
|
+
this.host = host;
|
|
39
|
+
this.host.addEventListener("joist::value", (e) => {
|
|
40
|
+
if (e.expression.bindTo === "each") {
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
this.#callbacks.push(e.update);
|
|
43
|
+
e.update({
|
|
44
|
+
oldValue: null,
|
|
45
|
+
newValue: this.each,
|
|
46
|
+
firstChange: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
onChange(changes) {
|
|
52
|
+
const change = changes.get("each");
|
|
53
|
+
for (let cb of this.#callbacks) {
|
|
54
|
+
cb({
|
|
55
|
+
oldValue: change.oldValue,
|
|
56
|
+
newValue: change.newValue,
|
|
57
|
+
firstChange: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
46
60
|
}
|
|
47
61
|
};
|
|
48
|
-
return JForScope = _classThis;
|
|
49
62
|
})();
|
|
50
|
-
export { JForScope };
|
|
51
63
|
let JoistForElement = (() => {
|
|
52
64
|
let _classDecorators = [element({
|
|
53
65
|
shadowDom: [css `:host{display:contents;}`, html `<slot></slot>`],
|
|
@@ -90,8 +102,8 @@ let JoistForElement = (() => {
|
|
|
90
102
|
throw new Error("The first Node in j-for needs to be a template");
|
|
91
103
|
}
|
|
92
104
|
let currentScope = template.nextElementSibling;
|
|
93
|
-
while (currentScope instanceof
|
|
94
|
-
this.#scopes.set(currentScope.key, currentScope);
|
|
105
|
+
while (currentScope instanceof JoistForScopeContainer) {
|
|
106
|
+
this.#scopes.set(String(currentScope.key), currentScope);
|
|
95
107
|
currentScope = currentScope.nextElementSibling;
|
|
96
108
|
}
|
|
97
109
|
const token = new JExpression(this.bind);
|
|
@@ -113,8 +125,6 @@ let JoistForElement = (() => {
|
|
|
113
125
|
}));
|
|
114
126
|
}
|
|
115
127
|
createFromEmpty() {
|
|
116
|
-
const template = this.#template();
|
|
117
|
-
const templateContent = template.content;
|
|
118
128
|
const keyProperty = this.key;
|
|
119
129
|
const fragment = document.createDocumentFragment();
|
|
120
130
|
let index = 0;
|
|
@@ -123,18 +133,16 @@ let JoistForElement = (() => {
|
|
|
123
133
|
if (keyProperty && hasProperty(value, keyProperty)) {
|
|
124
134
|
key = value[keyProperty];
|
|
125
135
|
}
|
|
126
|
-
const scope =
|
|
127
|
-
scope.
|
|
128
|
-
scope.key = key;
|
|
136
|
+
const scope = this.#createScopeContainer();
|
|
137
|
+
scope.host.setAttribute("key", String(key));
|
|
129
138
|
scope.each = { position: index + 1, index, value };
|
|
130
|
-
fragment.appendChild(scope);
|
|
131
|
-
this.#scopes.set(key, scope);
|
|
139
|
+
fragment.appendChild(scope.host);
|
|
140
|
+
this.#scopes.set(String(key), scope);
|
|
132
141
|
index++;
|
|
133
142
|
}
|
|
134
143
|
this.append(fragment);
|
|
135
144
|
}
|
|
136
145
|
updateItems() {
|
|
137
|
-
const template = this.#template();
|
|
138
146
|
const leftoverScopes = new Map(this.#scopes);
|
|
139
147
|
const keyProperty = this.key;
|
|
140
148
|
let index = 0;
|
|
@@ -145,34 +153,42 @@ let JoistForElement = (() => {
|
|
|
145
153
|
}
|
|
146
154
|
let scope = leftoverScopes.get(key);
|
|
147
155
|
if (!scope) {
|
|
148
|
-
scope =
|
|
149
|
-
|
|
150
|
-
this.#scopes.set(key, scope);
|
|
156
|
+
scope = scope = this.#createScopeContainer();
|
|
157
|
+
this.#scopes.set(String(key), scope);
|
|
151
158
|
}
|
|
152
159
|
else {
|
|
153
160
|
leftoverScopes.delete(key);
|
|
154
161
|
}
|
|
155
162
|
if (scope.key !== key || scope.each.value !== value) {
|
|
156
|
-
scope.key
|
|
163
|
+
scope.host.setAttribute("key", String(key));
|
|
157
164
|
scope.each = { position: index + 1, index, value };
|
|
158
165
|
}
|
|
159
166
|
const child = this.children[index + 1];
|
|
160
|
-
if (child !== scope) {
|
|
161
|
-
this.insertBefore(scope, child);
|
|
167
|
+
if (child !== scope.host) {
|
|
168
|
+
this.insertBefore(scope.host, child);
|
|
162
169
|
}
|
|
163
170
|
index++;
|
|
164
171
|
}
|
|
165
172
|
for (const scope of leftoverScopes.values()) {
|
|
166
|
-
scope.remove();
|
|
173
|
+
scope.host.remove();
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
176
|
disconnectedCallback() {
|
|
170
177
|
for (const scope of this.#scopes.values()) {
|
|
171
|
-
scope.remove();
|
|
178
|
+
scope.host.remove();
|
|
172
179
|
}
|
|
173
180
|
this.#scopes.clear();
|
|
174
181
|
this.#items = [];
|
|
175
182
|
}
|
|
183
|
+
#createScopeContainer() {
|
|
184
|
+
const template = this.#template();
|
|
185
|
+
const content = template.content.firstElementChild;
|
|
186
|
+
if (content === null) {
|
|
187
|
+
throw new Error("template must contain a single parent element");
|
|
188
|
+
}
|
|
189
|
+
const fragment = document.importNode(content, true);
|
|
190
|
+
return new JoistForScopeContainer(fragment);
|
|
191
|
+
}
|
|
176
192
|
};
|
|
177
193
|
return JoistForElement = _classThis;
|
|
178
194
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"for.element.js","sourceRoot":"","sources":["../../../src/lib/elements/for.element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO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,IAAI,CAAC,SAAS,EAAE,CAAC;YAClC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC;YAEnD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,CAAC;YAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAEpD,OAAO,IAAI,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;;;;SAhJU,eAAe;AAmJ5B,SAAS,UAAU,CAAc,GAAQ;IACvC,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC;AACnE,CAAC;AAED,SAAS,WAAW,CAAC,IAAa,EAAE,GAAW;IAC7C,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -101,13 +101,16 @@ it("should provide index and position information", () => {
|
|
|
101
101
|
>
|
|
102
102
|
<j-for bind="items">
|
|
103
103
|
<template>
|
|
104
|
-
<
|
|
105
|
-
|
|
104
|
+
<div class="item">
|
|
105
|
+
<j-val bind="each.value"></j-val>
|
|
106
|
+
(index: <j-val bind="each.index"></j-val>, position:
|
|
107
|
+
<j-val bind="each.position"></j-val>)
|
|
108
|
+
</div>
|
|
106
109
|
</template>
|
|
107
110
|
</j-for>
|
|
108
111
|
</div>
|
|
109
112
|
`);
|
|
110
|
-
const items = element.querySelectorAll("
|
|
113
|
+
const items = element.querySelectorAll(".item");
|
|
111
114
|
assert.equal(items.length, 3);
|
|
112
115
|
assert.equal(items[0].textContent?.trim().replaceAll("\n", "").replaceAll(" ", ""), "A(index:0,position:1)");
|
|
113
116
|
assert.equal(items[1].textContent?.trim().replaceAll("\n", "").replaceAll(" ", ""), "B(index:1,position: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C5B;SACF,CAAC,CAAC;IACL,CAAC;;;;;;;;GAQJ,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC9B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
|
-
import { attr, element, queryAll, css
|
|
2
|
+
import { attr, element, queryAll, css } from "@joist/element";
|
|
3
3
|
import { JoistValueEvent } from "../events.js";
|
|
4
4
|
import { JExpression } from "../expression.js";
|
|
5
5
|
let JoistIfElement = (() => {
|
|
6
6
|
let _classDecorators = [element({
|
|
7
|
-
shadowDom: [css `:host{display:
|
|
7
|
+
shadowDom: [css `:host{display: none;}`],
|
|
8
8
|
})];
|
|
9
9
|
let _classDescriptor;
|
|
10
10
|
let _classExtraInitializers = [];
|
|
@@ -27,7 +27,8 @@ let JoistIfElement = (() => {
|
|
|
27
27
|
#bind_accessor_storage = __runInitializers(this, _bind_initializers, "");
|
|
28
28
|
get bind() { return this.#bind_accessor_storage; }
|
|
29
29
|
set bind(value) { this.#bind_accessor_storage = value; }
|
|
30
|
-
#
|
|
30
|
+
#endMarker = (__runInitializers(this, _bind_extraInitializers), document.createComment("joist::endif"));
|
|
31
|
+
#templates = queryAll("template", this);
|
|
31
32
|
#shouldShowIf = null;
|
|
32
33
|
connectedCallback() {
|
|
33
34
|
const templates = Array.from(this.#templates());
|
|
@@ -43,6 +44,7 @@ let JoistIfElement = (() => {
|
|
|
43
44
|
if (templates.length === 2 && templates[0].hasAttribute("else")) {
|
|
44
45
|
[templates[0], templates[1]] = [templates[1], templates[0]];
|
|
45
46
|
}
|
|
47
|
+
this.after(this.#endMarker);
|
|
46
48
|
this.#clean();
|
|
47
49
|
const token = new JExpression(this.bind);
|
|
48
50
|
this.dispatchEvent(new JoistValueEvent(token, ({ newValue, oldValue, firstChange }) => {
|
|
@@ -62,12 +64,12 @@ let JoistIfElement = (() => {
|
|
|
62
64
|
const templateToUse = this.#shouldShowIf ? templates[0] : templates[1];
|
|
63
65
|
if (templateToUse) {
|
|
64
66
|
const content = document.importNode(templateToUse.content, true);
|
|
65
|
-
this.
|
|
67
|
+
this.after(content);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
#clean() {
|
|
69
|
-
while (
|
|
70
|
-
this.
|
|
71
|
+
while (this.nextSibling !== this.#endMarker) {
|
|
72
|
+
this.nextSibling?.remove();
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
disconnectedCallback() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"if.element.js","sourceRoot":"","sources":["../../../src/lib/elements/if.element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"if.element.js","sourceRoot":"","sources":["../../../src/lib/elements/if.element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;IAMlC,cAAc;4BAJ1B,OAAO,CAAC;YAEP,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