solarite 0.2.0 → 0.2.2
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 +6 -5
- package/benchmarks/naive/Solarite.min.js +0 -4
- package/benchmarks/naive/index.html +0 -14
- package/benchmarks/naive/main.js +0 -339
- package/benchmarks/naive/package-lock.json +0 -13
- package/benchmarks/naive/package.json +0 -23
- package/benchmarks/readme.md +0 -48
- package/build/build.bat +0 -4
- package/build/build.js +0 -139
- package/build/lib/rollup.min.js +0 -11
- package/build/lib/source-map.min.js +0 -1
- package/build/lib/terser.min.js +0 -1
- package/docs/index.md +0 -883
- package/docs/js/Playground.js +0 -184
- package/docs/js/codemirror/codemirror6.js +0 -32513
- package/docs/js/codemirror/themeSolarIce.js +0 -312
- package/docs/js/documentation.js +0 -32
- package/docs/js/ui/CodeEditor.js +0 -978
- package/docs/js/ui/DarkToggle.js +0 -52
- package/docs/js/ui/FlexResizer.js +0 -152
- package/docs/js/util/Draggable2.js +0 -151
- package/docs/js/util/Errors.js +0 -20
- package/docs/js/util/Html.js +0 -147
- package/docs/js/util/Icons.js +0 -623
- package/docs/js/util/Input.js +0 -253
- package/docs/js/util/Util.js +0 -88
- package/docs/js/util/delve.js +0 -43
- package/docs/media/FiraCode400.woff2 +0 -0
- package/docs/media/cabin-latin-700.woff2 +0 -0
- package/docs/media/documentation.css +0 -96
- package/docs/media/eternium.css +0 -1123
- package/docs/media/solarite-machine.webp +0 -0
- package/index.html +0 -761
- package/tests/Benchmark.test.js +0 -319
- package/tests/Solarite.test.js +0 -3838
- package/tests/Testimony.js +0 -809
- package/tests/index.html +0 -46
- package/tests/run.bat +0 -2
package/tests/Solarite.test.js
DELETED
|
@@ -1,3838 +0,0 @@
|
|
|
1
|
-
// noinspection DuplicatedCode
|
|
2
|
-
|
|
3
|
-
// Broken tests will be annotated with FIXME
|
|
4
|
-
|
|
5
|
-
import {camelToDashes, htmlContext} from "../src/solarite/Util.js";
|
|
6
|
-
//import {watchGet, watchSet} from "../src/solarite/watch.js";
|
|
7
|
-
|
|
8
|
-
import {Solarite, r, getArg} from '../src/solarite/Solarite.js';
|
|
9
|
-
//import {Solarite, r, getArg} from '../dist/Solarite.min.js'; // This will help the Benchmark test warm up.
|
|
10
|
-
//import {watch} from "../src/solarite/watch2.js";
|
|
11
|
-
import watch3 from "../src/solarite/watch3.js";
|
|
12
|
-
//import NodeGroupManager from "../src/solarite/NodeGroupManager.js";
|
|
13
|
-
import NodeGroup from "../src/solarite/NodeGroup.js";
|
|
14
|
-
import Template from "../src/solarite/Template.js";
|
|
15
|
-
import Shell from "../src/solarite/Shell.js";
|
|
16
|
-
|
|
17
|
-
import Testimony, {assert} from './Testimony.js';
|
|
18
|
-
|
|
19
|
-
// This function is used by the various tests.
|
|
20
|
-
window.getHtml = (item, includeComments=false) => {
|
|
21
|
-
if (!item)
|
|
22
|
-
return item;
|
|
23
|
-
|
|
24
|
-
if (item.fragment)
|
|
25
|
-
item = item.fragment; // Shell
|
|
26
|
-
if (item instanceof DocumentFragment)
|
|
27
|
-
item = [...item.childNodes]
|
|
28
|
-
|
|
29
|
-
else if (item.getNodes)
|
|
30
|
-
item = item.getNodes()
|
|
31
|
-
|
|
32
|
-
let result;
|
|
33
|
-
if (Array.isArray(item)) {
|
|
34
|
-
if (!includeComments)
|
|
35
|
-
item = item.filter(n => n.nodeType !==8)
|
|
36
|
-
|
|
37
|
-
result = item.map(n => n.nodeType === 8 ? `<!--${n.textContent}-->` : n.outerHTML || n.textContent).join('|');
|
|
38
|
-
}
|
|
39
|
-
else
|
|
40
|
-
result = item.outerHTML || item.textContent
|
|
41
|
-
|
|
42
|
-
if (!includeComments)
|
|
43
|
-
result = result.replace(/(<)!--(.*?)-->/g, '')
|
|
44
|
-
|
|
45
|
-
// Remove whitespace between tags, so we can write simpler tests.
|
|
46
|
-
return result.replace(/^\s+</g, '<').replace(/>\s+</g, '><').replace(/>\s+$/g, '>');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//<editor-fold desc="shell">
|
|
52
|
-
/* ┌─────────────────╮
|
|
53
|
-
* | Shell |
|
|
54
|
-
* └─────────────────╯*/
|
|
55
|
-
Testimony.test('Solarite.Shell.empty', () => {
|
|
56
|
-
let shell = new Shell(['', ''])
|
|
57
|
-
assert.eq(getHtml(shell, true), '<!--ExprPath:0-->|<!--ExprPathEnd:0-->')
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
Testimony.test('Solarite.Shell.paragraph', () => {
|
|
61
|
-
let shell = new Shell(['<p>', '</p>'])
|
|
62
|
-
assert.eq(getHtml(shell, true), '<p><!--ExprPath:0--><!--ExprPathEnd:0--></p>')
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
Testimony.test('Solarite.Shell.nodeBefore', () => {
|
|
66
|
-
let shell = new Shell(['a', ''])
|
|
67
|
-
assert.eq(getHtml(shell, true), 'a|<!--ExprPathEnd:0-->')
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
Testimony.test('Solarite.Shell.nodeAfter', () => {
|
|
71
|
-
let shell = new Shell(['', 'b'])
|
|
72
|
-
assert.eq(getHtml(shell, true), '<!--ExprPath:0-->|b')
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
Testimony.test('Solarite.Shell.nodeBeforeAfter', () => {
|
|
76
|
-
let shell = new Shell(['a', 'b'])
|
|
77
|
-
assert.eq(getHtml(shell, true), 'a|b')
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
Testimony.test('Solarite.Shell.emptyTwoPaths', () => {
|
|
81
|
-
let shell = new Shell(['', '', ''])
|
|
82
|
-
assert.eq(getHtml(shell, true), '<!--ExprPath:0-->|<!--ExprPathEnd:0-->|<!--ExprPathEnd:1-->')
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
Testimony.test('Solarite.Shell.nodeBetweenPaths', () => {
|
|
86
|
-
let shell = new Shell(['', 'a', ''])
|
|
87
|
-
assert.eq(getHtml(shell, true), '<!--ExprPath:0-->|a|<!--ExprPathEnd:1-->')
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
Testimony.test('Solarite.Shell.nodesAroundPaths', () => {
|
|
91
|
-
let shell = new Shell(['a', 'b', 'c'])
|
|
92
|
-
assert.eq(getHtml(shell, true), 'a|b|c')
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
Testimony.test('Solarite.Shell.emptyTwoPathsNested', () => {
|
|
96
|
-
let shell = new Shell(['<p>', '', '</p>'])
|
|
97
|
-
assert.eq(getHtml(shell, true), '<p><!--ExprPath:0--><!--ExprPathEnd:0--><!--ExprPathEnd:1--></p>')
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
Testimony.test('Solarite.Shell.nodesAroundPathsNested', () => {
|
|
101
|
-
let shell = new Shell(['<p>a', 'b', 'c</p>'])
|
|
102
|
-
assert.eq(getHtml(shell, true), '<p>abc</p>')
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Testimony.test('Shell.emptySpacer', () => {
|
|
107
|
-
// let expr = 1;
|
|
108
|
-
// let shell = new Shell(['<input ', '', 'onclick=','>'])
|
|
109
|
-
// console.log(getHtml(shell, true))
|
|
110
|
-
// });
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//</editor-fold>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//<editor-fold desc="nodegroup">
|
|
119
|
-
/* ┌─────────────────╮
|
|
120
|
-
* | NodeGroup |
|
|
121
|
-
* └─────────────────╯*/
|
|
122
|
-
Testimony.test('Solarite.NodeGroup.empty', () => {
|
|
123
|
-
|
|
124
|
-
let ng = new NodeGroup(new Template([``], []))
|
|
125
|
-
assert.eq(getHtml(ng), '')
|
|
126
|
-
|
|
127
|
-
ng.applyExprs([])
|
|
128
|
-
assert.eq(getHtml(ng), '')
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Testimony.test('Solarite.NodeGroup.oneExpr', () => {
|
|
133
|
-
|
|
134
|
-
let ng = new NodeGroup(new Template([``, ``], ['1']))
|
|
135
|
-
assert.eq(getHtml(ng), '1')
|
|
136
|
-
|
|
137
|
-
ng.applyExprs([2])
|
|
138
|
-
assert.eq(getHtml(ng), '2')
|
|
139
|
-
|
|
140
|
-
ng.applyExprs([[3, 4, 5]])
|
|
141
|
-
assert.eq(getHtml(ng), '3|4|5')
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
Testimony.test('Solarite.NodeGroup.emptyAdjacent', () => {
|
|
145
|
-
let ng = new NodeGroup(new Template([``, ``, ``], ['1', '2']))
|
|
146
|
-
ng.verify();
|
|
147
|
-
|
|
148
|
-
assert.eq(getHtml(ng), '1|2')
|
|
149
|
-
|
|
150
|
-
ng.applyExprs([3, 4])
|
|
151
|
-
assert.eq(getHtml(ng), '3|4')
|
|
152
|
-
|
|
153
|
-
ng.applyExprs([[1, 2, 3], [4, 5, 6]])
|
|
154
|
-
assert.eq(getHtml(ng), '1|2|3|4|5|6')
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
Testimony.test('Solarite.NodeGroup.paragraph', () => {
|
|
159
|
-
let ng = new NodeGroup(new Template(['<p>', '</p>'], ['1']))
|
|
160
|
-
assert.eq(getHtml(ng), '<p>1</p>')
|
|
161
|
-
|
|
162
|
-
ng.applyExprs([2])
|
|
163
|
-
assert.eq(getHtml(ng), '<p>2</p>')
|
|
164
|
-
|
|
165
|
-
ng.applyExprs([[3, 4, 5]])
|
|
166
|
-
assert.eq(getHtml(ng), '<p>345</p>')
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
Testimony.test('Solarite.NodeGroup.node', () => {
|
|
170
|
-
let a = r('<p>a</p>')
|
|
171
|
-
let b = r('<p>b</p>')
|
|
172
|
-
let ng = new NodeGroup(new Template(['<div>', '</div>'], [a]))
|
|
173
|
-
|
|
174
|
-
assert.eq(getHtml(ng), '<div><p>a</p></div>')
|
|
175
|
-
|
|
176
|
-
ng.applyExprs([b]);
|
|
177
|
-
assert.eq(getHtml(ng), '<div><p>b</p></div>')
|
|
178
|
-
|
|
179
|
-
ng.applyExprs([1]);
|
|
180
|
-
assert.eq(getHtml(ng), '<div>1</div>')
|
|
181
|
-
|
|
182
|
-
ng.applyExprs([a]);
|
|
183
|
-
assert.eq(getHtml(ng), '<div><p>a</p></div>')
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
Testimony.test('Solarite.NodeGroup._nodeSwap', () => {
|
|
187
|
-
let a = r('<p>a</p>')
|
|
188
|
-
let b = r('<p>b</p>')
|
|
189
|
-
let ng = new NodeGroup(new Template(['<div>', '', '</div>'], [a, b]))
|
|
190
|
-
document.body.append(ng.startNode)
|
|
191
|
-
|
|
192
|
-
assert.eq(getHtml(ng), '<div><p>a</p><p>b</p></div>')
|
|
193
|
-
|
|
194
|
-
ng.applyExprs([b, a]);
|
|
195
|
-
assert.eq(getHtml(ng), '<div><p>b</p><p>a</p></div>');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
Testimony.test('Solarite.NodeGroup.arrayReverse', () => {
|
|
200
|
-
let list = [r('a'), r('b')];
|
|
201
|
-
|
|
202
|
-
let ng = new NodeGroup(new Template(['<div>', '</div>'], [list]))
|
|
203
|
-
ng.verify();
|
|
204
|
-
assert(getHtml(ng), '<div>ab</div')
|
|
205
|
-
|
|
206
|
-
list.reverse();
|
|
207
|
-
ng.applyExprs([list])
|
|
208
|
-
assert(getHtml(ng), '<div>ba</div')
|
|
209
|
-
});
|
|
210
|
-
//</editor-fold>
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
//<editor-fold desc="util">
|
|
215
|
-
/* ┌─────────────────╮
|
|
216
|
-
* | Util |
|
|
217
|
-
* └─────────────────╯*/
|
|
218
|
-
|
|
219
|
-
Testimony.test('Solarite.Util.htmlContext', () => {
|
|
220
|
-
assert.eq(htmlContext('<div class="test'), htmlContext.Attribute)
|
|
221
|
-
assert.eq(htmlContext('">hello '), htmlContext.Text);
|
|
222
|
-
assert.eq(htmlContext('<span data-attr="hi > there"'), htmlContext.Tag);
|
|
223
|
-
assert.eq(htmlContext(` attr='`), htmlContext.Attribute);
|
|
224
|
-
assert.eq(htmlContext(`'`), htmlContext.Tag);
|
|
225
|
-
assert.eq(htmlContext(' attr='), htmlContext.Attribute);
|
|
226
|
-
assert.eq(htmlContext('a'), htmlContext.Attribute);
|
|
227
|
-
assert.eq(htmlContext(' '), htmlContext.Tag);
|
|
228
|
-
assert.eq(htmlContext(' attr='), htmlContext.Attribute);
|
|
229
|
-
assert.eq(htmlContext('>'), htmlContext.Text);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
Testimony.test('Solarite.Util.camelToDashes', () => {
|
|
233
|
-
assert.eq(camelToDashes('ProperName'), 'proper-name');
|
|
234
|
-
assert.eq(camelToDashes('HTMLElement'), 'html-element');
|
|
235
|
-
assert.eq(camelToDashes('BigUI'), 'big-ui');
|
|
236
|
-
assert.eq(camelToDashes('UIForm'), 'ui-form');
|
|
237
|
-
assert.eq(camelToDashes('A100'), 'a-100');
|
|
238
|
-
});
|
|
239
|
-
//</editor-fold>
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
//<editor-fold desc="basic">
|
|
244
|
-
/* ┌─────────────────╮
|
|
245
|
-
* | Basic |
|
|
246
|
-
* └─────────────────╯*/
|
|
247
|
-
Testimony.test('Solarite.basic.empty', () => {
|
|
248
|
-
class A extends HTMLElement {
|
|
249
|
-
constructor() {
|
|
250
|
-
super();
|
|
251
|
-
this.render();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
render() {
|
|
255
|
-
r(this)``
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
customElements.define('r-10', A);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
let a = new A();
|
|
262
|
-
assert.eq(getHtml(a), '<r-10></r-10>');
|
|
263
|
-
assert.eq(a.childNodes.length, 0);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
Testimony.test('Solarite.basic.empty2', () => {
|
|
268
|
-
|
|
269
|
-
class R11 extends Solarite {
|
|
270
|
-
constructor(args) {
|
|
271
|
-
super();
|
|
272
|
-
// console.log(args)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
render() {
|
|
276
|
-
this.html = r`<r-11></r-11>`
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
R11.define();
|
|
280
|
-
|
|
281
|
-
let a = r(`<r-11 title="Hello"></r-11>`);
|
|
282
|
-
assert.eq(a.outerHTML, `<r-11 title="Hello"></r-11>`);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
Testimony.test('Solarite.basic.text', () => {
|
|
288
|
-
class A extends Solarite {
|
|
289
|
-
render() {
|
|
290
|
-
r(this)`Here's Solarite <Component>` // apostophe, <>, and and unicode.
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
customElements.define('r-15', A);
|
|
294
|
-
|
|
295
|
-
let a = new A();
|
|
296
|
-
document.body.append(a); // Calls render()
|
|
297
|
-
|
|
298
|
-
assert.eq(getHtml(a), '<r-15>Here\'s Solarite <Component></r-15>');
|
|
299
|
-
assert.eq(a.childNodes.length, 1);
|
|
300
|
-
|
|
301
|
-
a.remove();
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
Testimony.test('Solarite.basic.manualRender', () => {
|
|
306
|
-
|
|
307
|
-
let children1, children2;
|
|
308
|
-
|
|
309
|
-
class A extends Solarite {
|
|
310
|
-
constructor() {
|
|
311
|
-
super();
|
|
312
|
-
children1 = [...this.childNodes]
|
|
313
|
-
this.render();
|
|
314
|
-
children2 = [...this.childNodes]
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
render() {
|
|
318
|
-
r(this)`Solarite Component`
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
customElements.define('r-20', A);
|
|
322
|
-
|
|
323
|
-
let a = new A();
|
|
324
|
-
|
|
325
|
-
assert.eq(children1.length, 0);
|
|
326
|
-
assert.eq(children2.length, 1);
|
|
327
|
-
assert.eq(children2[0].textContent, 'Solarite Component');
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
Testimony.test('Solarite.basic.pseudoRoot', () => {
|
|
333
|
-
class R30 extends Solarite {
|
|
334
|
-
render() {
|
|
335
|
-
this.html = r`<r-30 title="Hello">World</r-30>`
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
let a = new R30();
|
|
340
|
-
a.render();
|
|
341
|
-
|
|
342
|
-
assert.eq(getHtml(a), `<r-30 title="Hello">World</r-30>`)
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
Testimony.test('Solarite.basic.createElement', () => {
|
|
347
|
-
class R35 extends Solarite {
|
|
348
|
-
constructor() {
|
|
349
|
-
super();
|
|
350
|
-
//this.render(); // If uncommented, we get browser error:
|
|
351
|
-
// "Uncaught DOMException: Failed to construct 'CustomElement': The result must not have children"
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
render() {
|
|
355
|
-
this.html = r`<div>Hello!</div>`
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
R35.define();
|
|
359
|
-
|
|
360
|
-
let a = document.createElement('r-35');
|
|
361
|
-
|
|
362
|
-
assert.eq(getHtml(a), `<r-35></r-35>`); // Not rendered yet.
|
|
363
|
-
assert(a instanceof Solarite);
|
|
364
|
-
|
|
365
|
-
a.render();
|
|
366
|
-
assert.eq(getHtml(a), `<r-35><div>Hello!</div></r-35>`);
|
|
367
|
-
});
|
|
368
|
-
//</editor-fold>
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
//<editor-fold desc="expr">
|
|
373
|
-
/* ┌─────────────────╮
|
|
374
|
-
* | Expr |
|
|
375
|
-
* └─────────────────╯*/
|
|
376
|
-
Testimony.test('Solarite.expr.staticString', () => {
|
|
377
|
-
class R40 extends HTMLElement {
|
|
378
|
-
render() {
|
|
379
|
-
r(this)`Solarite ${'Test'} Component`
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
customElements.define('r-40', R40);
|
|
383
|
-
|
|
384
|
-
let a = new R40();
|
|
385
|
-
a.render();
|
|
386
|
-
document.body.append(a);
|
|
387
|
-
|
|
388
|
-
assert.eq(getHtml(a), '<r-40>Solarite Test Component</r-40>');
|
|
389
|
-
|
|
390
|
-
a.remove();
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
Testimony.test('Solarite.expr.htmlString', () => {
|
|
395
|
-
|
|
396
|
-
class A extends Solarite {
|
|
397
|
-
constructor() {
|
|
398
|
-
super();
|
|
399
|
-
this.render();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
render() {
|
|
403
|
-
r(this)`This text is ${r(`<b>Bold</b>`)}!`
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
A.define('r-42');
|
|
407
|
-
|
|
408
|
-
let a = new A();
|
|
409
|
-
assert.eq(getHtml(a), '<r-42>This text is <b>Bold</b>!</r-42>');
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
Testimony.test('Solarite.expr.table', () => {
|
|
413
|
-
|
|
414
|
-
class R43 extends Solarite {
|
|
415
|
-
constructor() {
|
|
416
|
-
super();
|
|
417
|
-
this.render();
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
render() {
|
|
421
|
-
r(this)`<table><tr>${r(`<td>Table Cell</td>`)}</tr></table>`
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
let a = new R43();
|
|
425
|
-
|
|
426
|
-
assert.eq(getHtml(a), `<r-43><table><tbody><tr><td>Table Cell</td></tr></tbody></table></r-43>`)
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
Testimony.test('Solarite.expr.documentFragment', () => {
|
|
431
|
-
|
|
432
|
-
class R44 extends Solarite {
|
|
433
|
-
render() {
|
|
434
|
-
r(this)`This text is ${r(`<b>Bold</b><i>Italic</i>`)}!`
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
let a = new R44(); // auto render on construct.
|
|
439
|
-
|
|
440
|
-
a.render();
|
|
441
|
-
assert.eq(getHtml(a), '<r-44>This text is <b>Bold</b><i>Italic</i>!</r-44>');
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
a.render();
|
|
445
|
-
assert.eq(getHtml(a), '<r-44>This text is <b>Bold</b><i>Italic</i>!</r-44>');
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
Testimony.test('Solarite.expr.undefined', () => {
|
|
449
|
-
class A extends Solarite {
|
|
450
|
-
constructor() {
|
|
451
|
-
super();
|
|
452
|
-
this.render();
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
render() {
|
|
456
|
-
r(this)`${this.valueless}` // Make sure it renders undefined as ''
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
customElements.define('r-80', A);
|
|
460
|
-
|
|
461
|
-
let a = new A();
|
|
462
|
-
assert.eq(getHtml(a), '<r-80></r-80>');
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
Testimony.test('Solarite.expr.staticNumber', () => {
|
|
466
|
-
class A extends Solarite {
|
|
467
|
-
constructor() {
|
|
468
|
-
super();
|
|
469
|
-
this.render();
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
render() {
|
|
473
|
-
r(this)`Solarite ${123} Component`
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
customElements.define('r-46', A);
|
|
477
|
-
|
|
478
|
-
let a = new A();
|
|
479
|
-
assert.eq(getHtml(a), '<r-46>Solarite 123 Component</r-46>');
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
Testimony.test('Solarite.expr.staticDate', () => {
|
|
484
|
-
class A extends Solarite {
|
|
485
|
-
constructor() {
|
|
486
|
-
super();
|
|
487
|
-
this.render();
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
render() {
|
|
491
|
-
r(this)`${new Date('2010-02-01 00:00:00').getUTCFullYear()}`
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
customElements.define('r-50', A);
|
|
495
|
-
|
|
496
|
-
let a = new A();
|
|
497
|
-
assert.eq(getHtml(a), '<r-50>2010</r-50>');
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
Testimony.test('Solarite.expr.staticArray', () => {
|
|
501
|
-
class A extends Solarite {
|
|
502
|
-
constructor() {
|
|
503
|
-
super();
|
|
504
|
-
this.render();
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
render() {
|
|
508
|
-
r(this)`Items: ${[1, 2, 3]}`
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
customElements.define('r-52', A);
|
|
512
|
-
|
|
513
|
-
let a = new A();
|
|
514
|
-
assert.eq(getHtml(a), '<r-52>Items: 123</r-52>');
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
Testimony.test('Solarite.expr.array', () => {
|
|
519
|
-
class A extends Solarite {
|
|
520
|
-
fruits = ['Apple', 'Banana'];
|
|
521
|
-
|
|
522
|
-
render() {
|
|
523
|
-
r(this)`${this.fruits}`
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
customElements.define('r-60', A);
|
|
527
|
-
let a = new A();
|
|
528
|
-
|
|
529
|
-
document.body.append(a);
|
|
530
|
-
assert.eq(getHtml(a), '<r-60>AppleBanana</r-60>');
|
|
531
|
-
|
|
532
|
-
a.fruits.push('Cherry');
|
|
533
|
-
a.render();
|
|
534
|
-
assert.eq(getHtml(a), '<r-60>AppleBananaCherry</r-60>');
|
|
535
|
-
|
|
536
|
-
a.fruits.pop();
|
|
537
|
-
a.render();
|
|
538
|
-
assert.eq(getHtml(a), '<r-60>AppleBanana</r-60>');
|
|
539
|
-
|
|
540
|
-
a.fruits.shift();
|
|
541
|
-
a.render();
|
|
542
|
-
assert.eq(getHtml(a), '<r-60>Banana</r-60>');
|
|
543
|
-
|
|
544
|
-
a.remove();
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
Testimony.test('Solarite.expr.arrayReverse', () => {
|
|
549
|
-
class A extends Solarite {
|
|
550
|
-
fruits = ['Apple', 'Banana', 'Cherry', 'Dragonfruit'];
|
|
551
|
-
|
|
552
|
-
render() {
|
|
553
|
-
r(this)`${this.fruits}`
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
customElements.define('r-62', A);
|
|
557
|
-
let a = new A();
|
|
558
|
-
|
|
559
|
-
a.render();
|
|
560
|
-
assert.eq(getHtml(a), '<r-62>AppleBananaCherryDragonfruit</r-62>');
|
|
561
|
-
|
|
562
|
-
a.fruits.reverse();
|
|
563
|
-
a.render();
|
|
564
|
-
assert.eq(getHtml(a), '<r-62>DragonfruitCherryBananaApple</r-62>');
|
|
565
|
-
|
|
566
|
-
a.fruits.reverse();
|
|
567
|
-
a.render();
|
|
568
|
-
assert.eq(getHtml(a), '<r-62>AppleBananaCherryDragonfruit</r-62>');
|
|
569
|
-
|
|
570
|
-
a.fruits.shift();
|
|
571
|
-
a.render();
|
|
572
|
-
assert.eq(getHtml(a), '<r-62>BananaCherryDragonfruit</r-62>');
|
|
573
|
-
|
|
574
|
-
a.fruits.reverse();
|
|
575
|
-
a.render();
|
|
576
|
-
assert.eq(getHtml(a), '<r-62>DragonfruitCherryBanana</r-62>');
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
Testimony.test('Solarite.expr.twoArrays', () => {
|
|
582
|
-
class A extends Solarite {
|
|
583
|
-
fruits = ['Apple'];
|
|
584
|
-
pets = ['Cat'];
|
|
585
|
-
|
|
586
|
-
render() {
|
|
587
|
-
r(this)`${this.fruits}${this.pets}`
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
customElements.define('r-65', A);
|
|
591
|
-
let a = new A();
|
|
592
|
-
|
|
593
|
-
a.render();
|
|
594
|
-
assert.eq(getHtml(a), '<r-65>AppleCat</r-65>');
|
|
595
|
-
|
|
596
|
-
a.fruits.push('Banana');
|
|
597
|
-
a.render();
|
|
598
|
-
assert.eq(getHtml(a), '<r-65>AppleBananaCat</r-65>');
|
|
599
|
-
|
|
600
|
-
a.pets.push('Dog');
|
|
601
|
-
a.render();
|
|
602
|
-
assert.eq(getHtml(a), '<r-65>AppleBananaCatDog</r-65>');
|
|
603
|
-
|
|
604
|
-
a.pets.reverse();
|
|
605
|
-
a.fruits.reverse();
|
|
606
|
-
a.render();
|
|
607
|
-
assert.eq(getHtml(a), '<r-65>BananaAppleDogCat</r-65>');
|
|
608
|
-
|
|
609
|
-
a.pets.reverse();
|
|
610
|
-
a.fruits.reverse();
|
|
611
|
-
a.render();
|
|
612
|
-
assert.eq(getHtml(a), '<r-65>AppleBananaCatDog</r-65>');
|
|
613
|
-
|
|
614
|
-
a.fruits.shift();
|
|
615
|
-
a.render();
|
|
616
|
-
assert.eq(getHtml(a), '<r-65>BananaCatDog</r-65>');
|
|
617
|
-
|
|
618
|
-
a.fruits.shift();
|
|
619
|
-
a.render();
|
|
620
|
-
assert.eq(getHtml(a), '<r-65>CatDog</r-65>');
|
|
621
|
-
|
|
622
|
-
a.pets.shift();
|
|
623
|
-
a.render();
|
|
624
|
-
assert.eq(getHtml(a), '<r-65>Dog</r-65>');
|
|
625
|
-
|
|
626
|
-
a.pets.shift();
|
|
627
|
-
a.render();
|
|
628
|
-
assert.eq(getHtml(a), '<r-65></r-65>');
|
|
629
|
-
|
|
630
|
-
a.fruits.push('Apple');
|
|
631
|
-
a.render();
|
|
632
|
-
assert.eq(getHtml(a), '<r-65>Apple</r-65>');
|
|
633
|
-
|
|
634
|
-
a.pets.push('Cat');
|
|
635
|
-
a.render();
|
|
636
|
-
assert.eq(getHtml(a), '<r-65>AppleCat</r-65>');
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
Testimony.test('Solarite.expr.staticFunction', () => {
|
|
640
|
-
class A extends Solarite {
|
|
641
|
-
constructor() {
|
|
642
|
-
super();
|
|
643
|
-
this.render();
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
render() {
|
|
647
|
-
r(this)`Items: ${() => [1, 2, 3]}`
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
customElements.define('r-70', A);
|
|
651
|
-
|
|
652
|
-
let a = new A();
|
|
653
|
-
assert.eq(getHtml(a), '<r-70>Items: 123</r-70>');
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
Testimony.test('Solarite.expr.staticElement', () => {
|
|
657
|
-
class A extends Solarite {
|
|
658
|
-
constructor() {
|
|
659
|
-
super();
|
|
660
|
-
this.render();
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
render() {
|
|
664
|
-
r(this)`Field: ${document.createElement('input')}`
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
customElements.define('r-74', A);
|
|
668
|
-
|
|
669
|
-
let a = new A();
|
|
670
|
-
assert.eq(getHtml(a), '<r-74>Field: <input></r-74>');
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
Testimony.test('Solarite.expr.varText', () => {
|
|
674
|
-
class A extends Solarite {
|
|
675
|
-
value = 'Apple';
|
|
676
|
-
|
|
677
|
-
render() { r(this)`The fruit is ${this.value}!` }
|
|
678
|
-
}
|
|
679
|
-
customElements.define('r-90', A);
|
|
680
|
-
|
|
681
|
-
let a = new A();
|
|
682
|
-
a.render();
|
|
683
|
-
|
|
684
|
-
assert.eq(getHtml(a), '<r-90>The fruit is Apple!</r-90>');
|
|
685
|
-
assert.eq(a.childNodes.length, 3);
|
|
686
|
-
|
|
687
|
-
a.value = 'Banana';
|
|
688
|
-
a.render();
|
|
689
|
-
assert.eq(getHtml(a), '<r-90>The fruit is Banana!</r-90>');
|
|
690
|
-
assert.eq(a.childNodes.length, 3);
|
|
691
|
-
|
|
692
|
-
a.value = 'Cherry';
|
|
693
|
-
a.render();
|
|
694
|
-
assert.eq(getHtml(a), '<r-90>The fruit is Cherry!</r-90>');
|
|
695
|
-
assert.eq(a.childNodes.length, 3);
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
Testimony.test('Solarite.expr.cyclicRef', () => {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
class R100 extends Solarite {
|
|
702
|
-
value = { name: 'Apple', self: null };
|
|
703
|
-
|
|
704
|
-
render() {
|
|
705
|
-
this.html = r`The fruit is ${this.value.name}!`
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
let a = new R100();
|
|
710
|
-
a.value.self = a; // cyclic reference.
|
|
711
|
-
a.render();
|
|
712
|
-
|
|
713
|
-
assert.eq(getHtml(a), '<r-100>The fruit is Apple!</r-100>');
|
|
714
|
-
|
|
715
|
-
a.value.name = 'Banana';
|
|
716
|
-
a.render();
|
|
717
|
-
assert.eq(getHtml(a), '<r-100>The fruit is Banana!</r-100>');
|
|
718
|
-
|
|
719
|
-
a.value.name = 'Cherry';
|
|
720
|
-
a.render();
|
|
721
|
-
assert.eq(getHtml(a), '<r-100>The fruit is Cherry!</r-100>');
|
|
722
|
-
});
|
|
723
|
-
//</editor-fold>
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
//<editor-fold desc="loop">
|
|
728
|
-
/* ┌─────────────────╮
|
|
729
|
-
* | Loop |
|
|
730
|
-
* └─────────────────╯*/
|
|
731
|
-
Testimony.test('Solarite.loop.strings', () => {
|
|
732
|
-
class A extends Solarite {
|
|
733
|
-
fruits = ['Apple', 'Banana'];
|
|
734
|
-
|
|
735
|
-
render() {
|
|
736
|
-
r(this)`${this.fruits.map(fruit => fruit)}`
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
customElements.define('r-200', A);
|
|
740
|
-
let a = new A();
|
|
741
|
-
|
|
742
|
-
a.render();
|
|
743
|
-
assert.eq(getHtml(a), '<r-200>AppleBanana</r-200>');
|
|
744
|
-
|
|
745
|
-
a.fruits.push('Cherry');
|
|
746
|
-
a.render();
|
|
747
|
-
assert.eq(getHtml(a), '<r-200>AppleBananaCherry</r-200>');
|
|
748
|
-
|
|
749
|
-
a.fruits.pop();
|
|
750
|
-
a.render();
|
|
751
|
-
assert.eq(getHtml(a), '<r-200>AppleBanana</r-200>');
|
|
752
|
-
|
|
753
|
-
a.fruits.shift();
|
|
754
|
-
a.render();
|
|
755
|
-
assert.eq(getHtml(a), '<r-200>Banana</r-200>');
|
|
756
|
-
|
|
757
|
-
a.fruits.shift();
|
|
758
|
-
a.render();
|
|
759
|
-
assert.eq(getHtml(a), '<r-200></r-200>');
|
|
760
|
-
|
|
761
|
-
a.fruits.push('Apple');
|
|
762
|
-
a.render();
|
|
763
|
-
assert.eq(getHtml(a), '<r-200>Apple</r-200>');
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
Testimony.test('Solarite.loop.paragraphs', () => {
|
|
767
|
-
class A extends Solarite {
|
|
768
|
-
fruits = ['Apple', 'Banana'];
|
|
769
|
-
|
|
770
|
-
render() {
|
|
771
|
-
r(this)`${this.fruits.map(fruit => r`<p>${fruit}</p>`)}`
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
customElements.define('r-210', A);
|
|
775
|
-
let a = new A();
|
|
776
|
-
|
|
777
|
-
a.render();
|
|
778
|
-
|
|
779
|
-
assert.eq(getHtml(a), '<r-210><p>Apple</p><p>Banana</p></r-210>');
|
|
780
|
-
|
|
781
|
-
a.fruits.push('Cherry');
|
|
782
|
-
a.render();
|
|
783
|
-
assert.eq(getHtml(a), '<r-210><p>Apple</p><p>Banana</p><p>Cherry</p></r-210>');
|
|
784
|
-
|
|
785
|
-
a.fruits.pop();
|
|
786
|
-
window.debug = true;
|
|
787
|
-
a.render();
|
|
788
|
-
assert.eq(getHtml(a), '<r-210><p>Apple</p><p>Banana</p></r-210>');
|
|
789
|
-
|
|
790
|
-
a.fruits.shift();
|
|
791
|
-
a.render();
|
|
792
|
-
assert.eq(getHtml(a), '<r-210><p>Banana</p></r-210>');
|
|
793
|
-
|
|
794
|
-
a.fruits.shift();
|
|
795
|
-
a.render();
|
|
796
|
-
assert.eq(getHtml(a), '<r-210></r-210>');
|
|
797
|
-
|
|
798
|
-
a.fruits.push('Apple');
|
|
799
|
-
a.render();
|
|
800
|
-
assert.eq(getHtml(a), '<r-210><p>Apple</p></r-210>');
|
|
801
|
-
|
|
802
|
-
a.remove();
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
Testimony.test('Solarite.loop.paragraphsBefore', `Same as above, but with another element afterward.`, () => {
|
|
806
|
-
class A extends Solarite {
|
|
807
|
-
fruits = ['Apple', 'Banana'];
|
|
808
|
-
|
|
809
|
-
render() {
|
|
810
|
-
r(this)`${this.fruits.map(fruit => r`<p>${fruit}</p>`)}<hr>`
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
customElements.define('r-212', A);
|
|
814
|
-
let a = new A();
|
|
815
|
-
document.body.append(a);
|
|
816
|
-
|
|
817
|
-
assert.eq(getHtml(a), '<r-212><p>Apple</p><p>Banana</p><hr></r-212>');
|
|
818
|
-
|
|
819
|
-
a.fruits.push('Cherry');
|
|
820
|
-
a.render();
|
|
821
|
-
assert.eq(getHtml(a), '<r-212><p>Apple</p><p>Banana</p><p>Cherry</p><hr></r-212>');
|
|
822
|
-
|
|
823
|
-
a.fruits.pop();
|
|
824
|
-
a.render();
|
|
825
|
-
assert.eq(getHtml(a), '<r-212><p>Apple</p><p>Banana</p><hr></r-212>');
|
|
826
|
-
|
|
827
|
-
a.fruits.shift();
|
|
828
|
-
a.render();
|
|
829
|
-
assert.eq(getHtml(a), '<r-212><p>Banana</p><hr></r-212>');
|
|
830
|
-
|
|
831
|
-
a.fruits.shift();
|
|
832
|
-
a.render();
|
|
833
|
-
assert.eq(getHtml(a), '<r-212><hr></r-212>');
|
|
834
|
-
|
|
835
|
-
a.fruits.push('Apple');
|
|
836
|
-
a.render();
|
|
837
|
-
assert.eq(getHtml(a), '<r-212><p>Apple</p><hr></r-212>');
|
|
838
|
-
|
|
839
|
-
a.remove();
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
Testimony.test('Solarite.loop.continuity', `Make sure elements are reused in a consistent way.`, () => {
|
|
843
|
-
class A extends Solarite {
|
|
844
|
-
fruits = ['Apple', 'Banana'];
|
|
845
|
-
|
|
846
|
-
render() {
|
|
847
|
-
r(this)`${this.fruits.map(fruit => r`<p>${fruit}</p>`)}`
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
customElements.define('a-213', A);
|
|
851
|
-
let a = new A();
|
|
852
|
-
document.body.append(a);
|
|
853
|
-
a.render();
|
|
854
|
-
assert.eq(getHtml(a), '<a-213><p>Apple</p><p>Banana</p></a-213>');
|
|
855
|
-
|
|
856
|
-
let apple = a.children[0];
|
|
857
|
-
let banana = a.children[1];
|
|
858
|
-
a.fruits.shift();
|
|
859
|
-
a.render();
|
|
860
|
-
assert.eq(getHtml(a), '<a-213><p>Banana</p></a-213>');
|
|
861
|
-
assert.eq(a.children[0], banana);
|
|
862
|
-
|
|
863
|
-
a.fruits.pop();
|
|
864
|
-
a.render();
|
|
865
|
-
assert.eq(getHtml(a), '<a-213></a-213>');
|
|
866
|
-
|
|
867
|
-
// We get back the same element.
|
|
868
|
-
a.fruits.push('Apple');
|
|
869
|
-
a.render();
|
|
870
|
-
assert.eq(getHtml(a), '<a-213><p>Apple</p></a-213>');
|
|
871
|
-
assert.eq(a.children[0], apple);
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
a.fruits.push('Banana');
|
|
875
|
-
a.render();
|
|
876
|
-
assert.eq(getHtml(a), '<a-213><p>Apple</p><p>Banana</p></a-213>');
|
|
877
|
-
assert.eq(a.children[0], apple);
|
|
878
|
-
assert.eq(a.children[1], banana);
|
|
879
|
-
|
|
880
|
-
// Make sure we maintain continuity after adding to the beginning.
|
|
881
|
-
a.fruits.unshift('Cherry');
|
|
882
|
-
a.render();
|
|
883
|
-
assert.eq(getHtml(a), '<a-213><p>Cherry</p><p>Apple</p><p>Banana</p></a-213>');
|
|
884
|
-
assert.eq(a.children[1], apple);
|
|
885
|
-
assert.eq(a.children[2], banana);
|
|
886
|
-
|
|
887
|
-
a.remove();
|
|
888
|
-
});
|
|
889
|
-
|
|
890
|
-
Testimony.test('Solarite.loop.eventBindings', async () => {
|
|
891
|
-
await new Promise((resolve, reject) => {
|
|
892
|
-
let callCount = 0;
|
|
893
|
-
|
|
894
|
-
class R215 extends Solarite {
|
|
895
|
-
fruits = ['Apple', 'Banana'];
|
|
896
|
-
|
|
897
|
-
checkFruit(fruit, i) {
|
|
898
|
-
assert.eq(i, 0)
|
|
899
|
-
|
|
900
|
-
callCount++;
|
|
901
|
-
if (callCount===2)
|
|
902
|
-
resolve();
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
render() {
|
|
906
|
-
this.html = r`${this.fruits.map((fruit, i) => r`<p onclick="${() => this.checkFruit(fruit, i)}">${fruit}</p>`)}`
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
let a = new R215();
|
|
911
|
-
document.body.append(a);
|
|
912
|
-
a.firstElementChild.dispatchEvent(new MouseEvent('click'))
|
|
913
|
-
|
|
914
|
-
a.fruits.shift();
|
|
915
|
-
a.render();
|
|
916
|
-
a.firstElementChild.dispatchEvent(new MouseEvent('click'))
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
a.remove();
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
});
|
|
923
|
-
|
|
924
|
-
// TODO: Why is this called pathCache? What does it test?
|
|
925
|
-
Testimony.test('Solarite.loop.pathCache', () => {
|
|
926
|
-
|
|
927
|
-
class R216 extends Solarite {
|
|
928
|
-
pets = ['Cat'];
|
|
929
|
-
fruits = ['Apple', 'Banana'];
|
|
930
|
-
|
|
931
|
-
render() {
|
|
932
|
-
r(this)`${this.pets.map(pet =>
|
|
933
|
-
r`${this.fruits.map(fruit =>
|
|
934
|
-
r`<p>Item</p>`
|
|
935
|
-
)}`
|
|
936
|
-
)}`
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
let a = new R216();
|
|
941
|
-
a.render();
|
|
942
|
-
assert.eq(getHtml(a), `<r-216><p>Item</p><p>Item</p></r-216>`);
|
|
943
|
-
|
|
944
|
-
a.fruits.shift();
|
|
945
|
-
window.debug = true;
|
|
946
|
-
a.render();
|
|
947
|
-
assert.eq(getHtml(a), `<r-216><p>Item</p></r-216>`);
|
|
948
|
-
});
|
|
949
|
-
|
|
950
|
-
Testimony.test('Solarite.loop.nested', () => {
|
|
951
|
-
|
|
952
|
-
class A extends Solarite {
|
|
953
|
-
pets = ['Cat', 'Dog'];
|
|
954
|
-
fruits = ['Apple', 'Banana'];
|
|
955
|
-
|
|
956
|
-
render() {
|
|
957
|
-
r(this)`${this.pets.map(pet =>
|
|
958
|
-
r`${this.fruits.map(fruit =>
|
|
959
|
-
r`<p>${pet} eats ${fruit}</p>`
|
|
960
|
-
)}`
|
|
961
|
-
)}`
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
customElements.define('r-220', A);
|
|
965
|
-
|
|
966
|
-
let a = new A();
|
|
967
|
-
document.body.append(a);
|
|
968
|
-
a.render();
|
|
969
|
-
assert.eq(getHtml(a), `<r-220><p>Cat eats Apple</p><p>Cat eats Banana</p><p>Dog eats Apple</p><p>Dog eats Banana</p></r-220>`);
|
|
970
|
-
|
|
971
|
-
a.fruits.shift();
|
|
972
|
-
a.render();
|
|
973
|
-
assert.eq(getHtml(a), `<r-220><p>Cat eats Banana</p><p>Dog eats Banana</p></r-220>`);
|
|
974
|
-
|
|
975
|
-
a.fruits.unshift('Apricot');
|
|
976
|
-
a.render();
|
|
977
|
-
assert.eq(getHtml(a), `<r-220><p>Cat eats Apricot</p><p>Cat eats Banana</p><p>Dog eats Apricot</p><p>Dog eats Banana</p></r-220>`);
|
|
978
|
-
|
|
979
|
-
a.pets.pop();
|
|
980
|
-
a.render();
|
|
981
|
-
assert.eq(getHtml(a), `<r-220><p>Cat eats Apricot</p><p>Cat eats Banana</p></r-220>`);
|
|
982
|
-
|
|
983
|
-
a.pets.unshift('Bird');
|
|
984
|
-
a.render();
|
|
985
|
-
assert.eq(getHtml(a), `<r-220><p>Bird eats Apricot</p><p>Bird eats Banana</p><p>Cat eats Apricot</p><p>Cat eats Banana</p></r-220>`);
|
|
986
|
-
|
|
987
|
-
a.pets.reverse();
|
|
988
|
-
a.render();
|
|
989
|
-
assert.eq(getHtml(a), `<r-220><p>Cat eats Apricot</p><p>Cat eats Banana</p><p>Bird eats Apricot</p><p>Bird eats Banana</p></r-220>`);
|
|
990
|
-
|
|
991
|
-
a.fruits.reverse();
|
|
992
|
-
a.render();
|
|
993
|
-
assert.eq(getHtml(a), `<r-220><p>Cat eats Banana</p><p>Cat eats Apricot</p><p>Bird eats Banana</p><p>Bird eats Apricot</p></r-220>`);
|
|
994
|
-
|
|
995
|
-
a.pets.reverse();
|
|
996
|
-
a.fruits.reverse();
|
|
997
|
-
window.debug = true;
|
|
998
|
-
a.render();
|
|
999
|
-
assert.eq(getHtml(a), `<r-220><p>Bird eats Apricot</p><p>Bird eats Banana</p><p>Cat eats Apricot</p><p>Cat eats Banana</p></r-220>`);
|
|
1000
|
-
|
|
1001
|
-
a.pets.pop();
|
|
1002
|
-
a.render();
|
|
1003
|
-
assert.eq(getHtml(a), `<r-220><p>Bird eats Apricot</p><p>Bird eats Banana</p></r-220>`);
|
|
1004
|
-
|
|
1005
|
-
a.pets.pop();
|
|
1006
|
-
a.render();
|
|
1007
|
-
assert.eq(getHtml(a), `<r-220></r-220>`);
|
|
1008
|
-
|
|
1009
|
-
a.remove();
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
|
-
Testimony.test('Solarite.loop.nested2', () => {
|
|
1013
|
-
|
|
1014
|
-
class A extends Solarite {
|
|
1015
|
-
fruits = ['Apple', 'Banana'];
|
|
1016
|
-
pets = ['Cat', 'Dog'];
|
|
1017
|
-
|
|
1018
|
-
render() {
|
|
1019
|
-
r(this)`${this.pets.map(pet =>
|
|
1020
|
-
r`<div>${this.fruits.map(fruit =>
|
|
1021
|
-
r`<p>${pet} eats ${fruit}</p>`
|
|
1022
|
-
)}</div>`
|
|
1023
|
-
)}`
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
customElements.define('r-224', A);
|
|
1027
|
-
|
|
1028
|
-
let a = new A();
|
|
1029
|
-
document.body.append(a);
|
|
1030
|
-
a.render();
|
|
1031
|
-
assert.eq(getHtml(a), `<r-224><div><p>Cat eats Apple</p><p>Cat eats Banana</p></div><div><p>Dog eats Apple</p><p>Dog eats Banana</p></div></r-224>`);
|
|
1032
|
-
|
|
1033
|
-
a.fruits.shift();
|
|
1034
|
-
a.render();
|
|
1035
|
-
assert.eq(getHtml(a), `<r-224><div><p>Cat eats Banana</p></div><div><p>Dog eats Banana</p></div></r-224>`);
|
|
1036
|
-
|
|
1037
|
-
a.fruits.unshift('Apricot');
|
|
1038
|
-
a.render();
|
|
1039
|
-
assert.eq(getHtml(a), `<r-224><div><p>Cat eats Apricot</p><p>Cat eats Banana</p></div><div><p>Dog eats Apricot</p><p>Dog eats Banana</p></div></r-224>`);
|
|
1040
|
-
|
|
1041
|
-
a.pets.pop(); // remove Dog.
|
|
1042
|
-
a.render();
|
|
1043
|
-
assert.eq(getHtml(a), `<r-224><div><p>Cat eats Apricot</p><p>Cat eats Banana</p></div></r-224>`);
|
|
1044
|
-
|
|
1045
|
-
a.pets.unshift('Bird');
|
|
1046
|
-
a.render();
|
|
1047
|
-
assert.eq(getHtml(a), `<r-224><div><p>Bird eats Apricot</p><p>Bird eats Banana</p></div><div><p>Cat eats Apricot</p><p>Cat eats Banana</p></div></r-224>`);
|
|
1048
|
-
|
|
1049
|
-
a.pets.reverse();
|
|
1050
|
-
a.render();
|
|
1051
|
-
assert.eq(getHtml(a), `<r-224><div><p>Cat eats Apricot</p><p>Cat eats Banana</p></div><div><p>Bird eats Apricot</p><p>Bird eats Banana</p></div></r-224>`);
|
|
1052
|
-
|
|
1053
|
-
a.fruits.reverse();
|
|
1054
|
-
a.render();
|
|
1055
|
-
assert.eq(getHtml(a), `<r-224><div><p>Cat eats Banana</p><p>Cat eats Apricot</p></div><div><p>Bird eats Banana</p><p>Bird eats Apricot</p></div></r-224>`);
|
|
1056
|
-
|
|
1057
|
-
a.pets.reverse();
|
|
1058
|
-
a.fruits.reverse();
|
|
1059
|
-
a.render();
|
|
1060
|
-
assert.eq(getHtml(a), `<r-224><div><p>Bird eats Apricot</p><p>Bird eats Banana</p></div><div><p>Cat eats Apricot</p><p>Cat eats Banana</p></div></r-224>`);
|
|
1061
|
-
|
|
1062
|
-
a.pets.pop();
|
|
1063
|
-
a.render();
|
|
1064
|
-
assert.eq(getHtml(a), `<r-224><div><p>Bird eats Apricot</p><p>Bird eats Banana</p></div></r-224>`);
|
|
1065
|
-
|
|
1066
|
-
a.pets.pop();
|
|
1067
|
-
a.render();
|
|
1068
|
-
assert.eq(getHtml(a), `<r-224></r-224>`);
|
|
1069
|
-
|
|
1070
|
-
a.remove();
|
|
1071
|
-
});
|
|
1072
|
-
|
|
1073
|
-
Testimony.test('Solarite.loop.nested3', `Move items from one sublist to another.`, () => {
|
|
1074
|
-
|
|
1075
|
-
class A225 extends Solarite {
|
|
1076
|
-
fruitGroups = [
|
|
1077
|
-
['Apple'],
|
|
1078
|
-
['Banana', 'Cherry']
|
|
1079
|
-
];
|
|
1080
|
-
|
|
1081
|
-
render() {
|
|
1082
|
-
r(this)`${this.fruitGroups.map(fruitGroup =>
|
|
1083
|
-
r`<div>${fruitGroup.map(fruit =>
|
|
1084
|
-
r`<span>${fruit}</span>`
|
|
1085
|
-
)}</div>`
|
|
1086
|
-
)}`
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
A225.define();
|
|
1090
|
-
window.verify = true;
|
|
1091
|
-
|
|
1092
|
-
let a = new A225();
|
|
1093
|
-
document.body.append(a);
|
|
1094
|
-
window.debug = true;
|
|
1095
|
-
a.render();
|
|
1096
|
-
|
|
1097
|
-
let cherry = a.fruitGroups[1].pop();
|
|
1098
|
-
a.fruitGroups[0].push(cherry);
|
|
1099
|
-
a.render();
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
let banana = a.fruitGroups[1].pop();
|
|
1103
|
-
a.fruitGroups[0].push(banana);
|
|
1104
|
-
a.render();
|
|
1105
|
-
|
|
1106
|
-
window.verify = false;
|
|
1107
|
-
a.remove();
|
|
1108
|
-
});
|
|
1109
|
-
|
|
1110
|
-
// Tried to make a simpler version of nested3, but it works fine:
|
|
1111
|
-
Testimony.test('Solarite.loop.nested4', () => {
|
|
1112
|
-
|
|
1113
|
-
class A226 extends Solarite {
|
|
1114
|
-
fruits1 = ['Apple']
|
|
1115
|
-
fruits2 = ['Banana', 'Cherry']
|
|
1116
|
-
|
|
1117
|
-
render() {
|
|
1118
|
-
this.html = r`
|
|
1119
|
-
<div>${this.fruits1.map(fruit => r`<span>${fruit}</span>`)}</div>
|
|
1120
|
-
<div>${this.fruits2.map(fruit => r`<span>${fruit}</span>`)}</div>`
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
A226.define();
|
|
1124
|
-
window.verify = true;
|
|
1125
|
-
|
|
1126
|
-
let a = new A226();
|
|
1127
|
-
document.body.append(a);
|
|
1128
|
-
a.render();
|
|
1129
|
-
|
|
1130
|
-
let cherry = a.fruits2.pop();
|
|
1131
|
-
a.fruits1.push(cherry);
|
|
1132
|
-
a.render();
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
let banana = a.fruits2.pop();
|
|
1136
|
-
a.fruits1.push(banana);
|
|
1137
|
-
//window.debug = true;
|
|
1138
|
-
a.render();
|
|
1139
|
-
|
|
1140
|
-
window.verify = false;
|
|
1141
|
-
a.remove();
|
|
1142
|
-
});
|
|
1143
|
-
|
|
1144
|
-
Testimony.test('Solarite.loop.nested5', () => {
|
|
1145
|
-
|
|
1146
|
-
// This test was originally created by reducing a failure in production code
|
|
1147
|
-
// to the simplest version.
|
|
1148
|
-
// The problem was that NodeGroupManager.findAndDeleteClose() was trying to
|
|
1149
|
-
// delete the old exactKey, but it didn't exist because it had already been assigned.
|
|
1150
|
-
// Commenting out the assert() fixed the problem.
|
|
1151
|
-
|
|
1152
|
-
// v could also be a function to trigger this same test.
|
|
1153
|
-
// Since functions are new on each render().
|
|
1154
|
-
let v = 'F1';
|
|
1155
|
-
|
|
1156
|
-
class A227 extends Solarite {
|
|
1157
|
-
boxes = [
|
|
1158
|
-
["A"],
|
|
1159
|
-
["A", "B"]
|
|
1160
|
-
]
|
|
1161
|
-
|
|
1162
|
-
render() {
|
|
1163
|
-
r(this)`
|
|
1164
|
-
<a-227>${this.boxes.map(item =>
|
|
1165
|
-
r`${item.map(item2 =>
|
|
1166
|
-
r`<div title=${v}>${item2}</div>`
|
|
1167
|
-
)}`
|
|
1168
|
-
)}</a-227>`;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
A227.define();
|
|
1172
|
-
|
|
1173
|
-
//window.verify = true;
|
|
1174
|
-
|
|
1175
|
-
let a = new A227();
|
|
1176
|
-
document.body.append(a); // calls render()
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
v = 'F2';
|
|
1182
|
-
a.boxes = [
|
|
1183
|
-
["A", "B"],
|
|
1184
|
-
['A']
|
|
1185
|
-
]
|
|
1186
|
-
a.render();
|
|
1187
|
-
|
|
1188
|
-
assert.eq(a.outerHTML, `<a-227><!--ExprPath:0--><!--ExprPath:0--><div title="F2"><!--ExprPath:1-->A<!--ExprPathEnd:1--></div><div title="F2"><!--ExprPath:1-->B<!--ExprPathEnd:1--></div><!--ExprPathEnd:0--><!--ExprPath:0--><div title="F2"><!--ExprPath:1-->A<!--ExprPathEnd:1--></div><!--ExprPathEnd:0--><!--ExprPathEnd:0--></a-227>`);
|
|
1189
|
-
|
|
1190
|
-
window.verify = false;
|
|
1191
|
-
a.remove();
|
|
1192
|
-
});
|
|
1193
|
-
|
|
1194
|
-
Testimony.test('Solarite.loop.nestedConditional', () => {
|
|
1195
|
-
|
|
1196
|
-
let isGoodBoy = true;
|
|
1197
|
-
|
|
1198
|
-
class R227 extends Solarite {
|
|
1199
|
-
pets = ['Cat', 'Dog'];
|
|
1200
|
-
fruits = ['Apple', 'Banana'];
|
|
1201
|
-
|
|
1202
|
-
render() {
|
|
1203
|
-
r(this)`${this.pets.map(pet =>
|
|
1204
|
-
r`${this.fruits.map(fruit =>
|
|
1205
|
-
isGoodBoy
|
|
1206
|
-
? r`<p>${pet} prepares ${fruit}</p>`
|
|
1207
|
-
: r`<p>${pet} eats ${fruit}</p>`
|
|
1208
|
-
)}`
|
|
1209
|
-
)}`
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
let a = new R227;
|
|
1213
|
-
|
|
1214
|
-
document.body.append(a);
|
|
1215
|
-
assert.eq(getHtml(a), `<r-227><p>Cat prepares Apple</p><p>Cat prepares Banana</p><p>Dog prepares Apple</p><p>Dog prepares Banana</p></r-227>`);
|
|
1216
|
-
|
|
1217
|
-
isGoodBoy = false;
|
|
1218
|
-
a.render();
|
|
1219
|
-
assert.eq(getHtml(a), `<r-227><p>Cat eats Apple</p><p>Cat eats Banana</p><p>Dog eats Apple</p><p>Dog eats Banana</p></r-227>`);
|
|
1220
|
-
|
|
1221
|
-
isGoodBoy = true;
|
|
1222
|
-
a.render();
|
|
1223
|
-
assert.eq(getHtml(a), `<r-227><p>Cat prepares Apple</p><p>Cat prepares Banana</p><p>Dog prepares Apple</p><p>Dog prepares Banana</p></r-227>`);
|
|
1224
|
-
|
|
1225
|
-
a.fruits.pop();
|
|
1226
|
-
isGoodBoy = false;
|
|
1227
|
-
a.render();
|
|
1228
|
-
assert.eq(getHtml(a), `<r-227><p>Cat eats Apple</p><p>Dog eats Apple</p></r-227>`);
|
|
1229
|
-
|
|
1230
|
-
a.remove();
|
|
1231
|
-
});
|
|
1232
|
-
|
|
1233
|
-
Testimony.test('Solarite.loop.conditionalNested', () => {
|
|
1234
|
-
|
|
1235
|
-
class R240 extends Solarite {
|
|
1236
|
-
pets = [
|
|
1237
|
-
{
|
|
1238
|
-
name: 'Cat',
|
|
1239
|
-
activities: ['Sleep', 'Eat', 'Pur']
|
|
1240
|
-
},
|
|
1241
|
-
{
|
|
1242
|
-
name: 'Dog',
|
|
1243
|
-
activities: ['Frolic', 'Fetch']
|
|
1244
|
-
}
|
|
1245
|
-
];
|
|
1246
|
-
|
|
1247
|
-
render() {
|
|
1248
|
-
this.html =
|
|
1249
|
-
r`${this.pets.map(pet =>
|
|
1250
|
-
pet.activities.map(activity =>
|
|
1251
|
-
activity.length >= 5
|
|
1252
|
-
? r`<p>${pet.name} will ${activity}.</p>`
|
|
1253
|
-
: ``
|
|
1254
|
-
)
|
|
1255
|
-
)}`
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
let a = new R240();
|
|
1259
|
-
document.body.append(a);
|
|
1260
|
-
|
|
1261
|
-
assert.eq(getHtml(a), `<r-240><p>Cat will Sleep.</p><p>Dog will Frolic.</p><p>Dog will Fetch.</p></r-240>`);
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
a.pets[0].activities[0] = 'Doze'; // Less than 5 characters.
|
|
1265
|
-
a.render()
|
|
1266
|
-
assert.eq(getHtml(a), `<r-240><p>Dog will Frolic.</p><p>Dog will Fetch.</p></r-240>`);
|
|
1267
|
-
//assert.eq(Refract.elsCreated, []);
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
a.pets[0].activities[0] = 'Slumber';
|
|
1271
|
-
a.render()
|
|
1272
|
-
assert.eq(getHtml(a), `<r-240><p>Cat will Slumber.</p><p>Dog will Frolic.</p><p>Dog will Fetch.</p></r-240>`);
|
|
1273
|
-
//assert.eq(Refract.elsCreated, ["<p>", "Cat", " will ", "Slumber", "."]);
|
|
1274
|
-
|
|
1275
|
-
a.remove();
|
|
1276
|
-
});
|
|
1277
|
-
|
|
1278
|
-
Testimony.test('Solarite.loop.tripleNested', 'Triple nested grid', () => {
|
|
1279
|
-
|
|
1280
|
-
class R250 extends Solarite {
|
|
1281
|
-
rows = [[[0]]];
|
|
1282
|
-
|
|
1283
|
-
render() {
|
|
1284
|
-
this.html = r`${this.rows.map(row =>
|
|
1285
|
-
r`${row.map(items =>
|
|
1286
|
-
r`${items.map(item =>
|
|
1287
|
-
r`${item}`
|
|
1288
|
-
)}`
|
|
1289
|
-
)}`
|
|
1290
|
-
)}`
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
let a = new R250();
|
|
1295
|
-
document.body.append(a);
|
|
1296
|
-
assert.eq(getHtml(a), `<r-250>0</r-250>`);
|
|
1297
|
-
|
|
1298
|
-
a.rows[0][0][0] = 4;
|
|
1299
|
-
a.render();
|
|
1300
|
-
assert.eq(getHtml(a), `<r-250>4</r-250>`);
|
|
1301
|
-
|
|
1302
|
-
a.rows = [];
|
|
1303
|
-
a.render();
|
|
1304
|
-
assert.eq(getHtml(a), `<r-250></r-250>`);
|
|
1305
|
-
|
|
1306
|
-
a.rows = [
|
|
1307
|
-
[[1,2],[3,4]],
|
|
1308
|
-
[[5,6],[7,8]]
|
|
1309
|
-
];
|
|
1310
|
-
a.render()
|
|
1311
|
-
assert.eq(getHtml(a), `<r-250>12345678</r-250>`);
|
|
1312
|
-
|
|
1313
|
-
let p1 = r('<p>1</p')
|
|
1314
|
-
let p2 = r('<p>2</p')
|
|
1315
|
-
let p3 = r('<p>3</p')
|
|
1316
|
-
let p4 = r('<p>4</p')
|
|
1317
|
-
let p5 = r('<p>5</p')
|
|
1318
|
-
let p6 = r('<p>6</p')
|
|
1319
|
-
let p7 = r('<p>7</p')
|
|
1320
|
-
let p8 = r('<p>8</p')
|
|
1321
|
-
|
|
1322
|
-
a.rows = [
|
|
1323
|
-
[[p1,p2],[p3,p4]],
|
|
1324
|
-
[[p5,p6],[p7,p8]]
|
|
1325
|
-
];
|
|
1326
|
-
a.render()
|
|
1327
|
-
assert.eq(getHtml(a), `<r-250><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>6</p><p>7</p><p>8</p></r-250>`);
|
|
1328
|
-
|
|
1329
|
-
a.rows = [
|
|
1330
|
-
[[p8,p7],[p6,p5]],
|
|
1331
|
-
[[p4,p3],[p2,p1]]
|
|
1332
|
-
];
|
|
1333
|
-
a.render()
|
|
1334
|
-
assert.eq(getHtml(a), `<r-250><p>8</p><p>7</p><p>6</p><p>5</p><p>4</p><p>3</p><p>2</p><p>1</p></r-250>`);
|
|
1335
|
-
|
|
1336
|
-
a.rows = [];
|
|
1337
|
-
a.render();
|
|
1338
|
-
assert.eq(getHtml(a), `<r-250></r-250>`);
|
|
1339
|
-
|
|
1340
|
-
a.remove();
|
|
1341
|
-
});
|
|
1342
|
-
|
|
1343
|
-
//</editor-fold>
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
//<editor-fold desc="embed">
|
|
1349
|
-
/* ┌─────────────────╮
|
|
1350
|
-
* | Embed |
|
|
1351
|
-
* └─────────────────╯*/
|
|
1352
|
-
|
|
1353
|
-
Testimony.test('Solarite.embed.styleStatic', () => {
|
|
1354
|
-
let count = 0;
|
|
1355
|
-
|
|
1356
|
-
class R300 extends Solarite {
|
|
1357
|
-
render() {
|
|
1358
|
-
this.html = r`
|
|
1359
|
-
<style>
|
|
1360
|
-
:host { color: blue }
|
|
1361
|
-
</style>
|
|
1362
|
-
Text that should be blue.
|
|
1363
|
-
${count}
|
|
1364
|
-
`;
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
let a = new R300();
|
|
1369
|
-
document.body.append(a);
|
|
1370
|
-
|
|
1371
|
-
assert.eq(a.querySelector('style').textContent.trim(), `r-300[data-style="1"] { color: blue }`)
|
|
1372
|
-
|
|
1373
|
-
// Make sure styleid isn't incremented on render.
|
|
1374
|
-
count++;
|
|
1375
|
-
a.render();
|
|
1376
|
-
assert.eq(a.querySelector('style').textContent.trim(), `r-300[data-style="1"] { color: blue }`)
|
|
1377
|
-
|
|
1378
|
-
a.remove();
|
|
1379
|
-
});
|
|
1380
|
-
|
|
1381
|
-
Testimony.test('Solarite.embed.optionsNoStyles', () => {
|
|
1382
|
-
let count = 0;
|
|
1383
|
-
|
|
1384
|
-
class R310 extends Solarite {
|
|
1385
|
-
render() {
|
|
1386
|
-
let options = {styles: false};
|
|
1387
|
-
r(this, options)`
|
|
1388
|
-
<style>
|
|
1389
|
-
:host { color: blue }
|
|
1390
|
-
</style>
|
|
1391
|
-
Text that should be blue.
|
|
1392
|
-
${count}
|
|
1393
|
-
`;
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
let a = new R310();
|
|
1398
|
-
document.body.append(a);
|
|
1399
|
-
assert.eq(a.querySelector('style').textContent.trim(), `:host { color: blue }`)
|
|
1400
|
-
|
|
1401
|
-
a.remove();
|
|
1402
|
-
});
|
|
1403
|
-
|
|
1404
|
-
Testimony.test('Solarite.embed.styleDynamic', () => {
|
|
1405
|
-
let style1 = `:host { color: red }`
|
|
1406
|
-
let style2 = `:host { font-weight: bold }`
|
|
1407
|
-
|
|
1408
|
-
class R320 extends Solarite {
|
|
1409
|
-
render() {
|
|
1410
|
-
this.html = r`
|
|
1411
|
-
<style>
|
|
1412
|
-
${style1} ${style2}
|
|
1413
|
-
</style>
|
|
1414
|
-
Text that should be bold and red.
|
|
1415
|
-
`;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
let a = new R320();
|
|
1420
|
-
document.body.append(a);
|
|
1421
|
-
|
|
1422
|
-
assert.eq(a.querySelector('style').textContent.trim(), `r-320[data-style="1"] { color: red } r-320[data-style="1"] { font-weight: bold }`)
|
|
1423
|
-
|
|
1424
|
-
style1 = `:host { color: gold }`
|
|
1425
|
-
a.render();
|
|
1426
|
-
assert.eq(a.querySelector('style').textContent.trim(), `r-320[data-style="1"] { color: gold } r-320[data-style="1"] { font-weight: bold }`)
|
|
1427
|
-
|
|
1428
|
-
a.remove();
|
|
1429
|
-
});
|
|
1430
|
-
|
|
1431
|
-
Testimony.test('Solarite.embed.styleDynamicNoSpaces', () => {
|
|
1432
|
-
let style1 = `:host { color: red }`
|
|
1433
|
-
let style2 = `:host { font-weight: bold }`
|
|
1434
|
-
|
|
1435
|
-
class R322 extends Solarite {
|
|
1436
|
-
render() {
|
|
1437
|
-
this.html = r`
|
|
1438
|
-
<style>${style1}${style2}</style>
|
|
1439
|
-
Text that should be bold and red.
|
|
1440
|
-
`;
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
let a = new R322();
|
|
1445
|
-
document.body.append(a);
|
|
1446
|
-
|
|
1447
|
-
assert.eq(a.querySelector('style').childNodes.length, 5) // includes zero-length text node placeholders inserted.
|
|
1448
|
-
assert.eq(a.querySelector('style').textContent, `r-322[data-style="1"] { color: red }r-322[data-style="1"] { font-weight: bold }`)
|
|
1449
|
-
|
|
1450
|
-
style1 = `:host { color: gold }`
|
|
1451
|
-
a.render();
|
|
1452
|
-
assert.eq(a.querySelector('style').textContent.trim(), `r-322[data-style="1"] { color: gold }r-322[data-style="1"] { font-weight: bold }`)
|
|
1453
|
-
|
|
1454
|
-
a.remove();
|
|
1455
|
-
});
|
|
1456
|
-
|
|
1457
|
-
Testimony.test('Solarite.embed.styleDynamicTag', () => {
|
|
1458
|
-
let style1 = r`<style>:host { color: green }</style>`
|
|
1459
|
-
|
|
1460
|
-
class R325 extends Solarite {
|
|
1461
|
-
render() {
|
|
1462
|
-
this.html = r`${style1}Text.`;
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
let a = new R325();
|
|
1467
|
-
document.body.append(a);
|
|
1468
|
-
assert.eq(getHtml(a), `<r-325 data-style="1"><style>r-325[data-style="1"] { color: green }</style>Text.</r-325>`)
|
|
1469
|
-
|
|
1470
|
-
style1 = r`<style>:host { color: orangered }</style>`
|
|
1471
|
-
a.render();
|
|
1472
|
-
assert.eq(getHtml(a), `<r-325 data-style="1"><style>r-325[data-style="1"] { color: orangered }</style>Text.</r-325>`)
|
|
1473
|
-
|
|
1474
|
-
a.remove();
|
|
1475
|
-
});
|
|
1476
|
-
|
|
1477
|
-
Testimony.test('Solarite.embed.svg', () => {
|
|
1478
|
-
class R330 extends Solarite {
|
|
1479
|
-
render() {
|
|
1480
|
-
this.html = r`
|
|
1481
|
-
<div>
|
|
1482
|
-
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
|
|
1483
|
-
<circle cx="25" cy="25" r="25" fill="blue" />
|
|
1484
|
-
<rect x="50" y="50" width="50" height="100" fill="green" />
|
|
1485
|
-
</svg>
|
|
1486
|
-
</div>
|
|
1487
|
-
`;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
let a = new R330();
|
|
1492
|
-
document.body.append(a);
|
|
1493
|
-
|
|
1494
|
-
// Not sure how to test this, but it looks good visually.
|
|
1495
|
-
a.remove();
|
|
1496
|
-
});
|
|
1497
|
-
|
|
1498
|
-
Testimony.test('Solarite.embed.scriptStatic', () => {
|
|
1499
|
-
window.scriptStaticCount = 1;
|
|
1500
|
-
class R340 extends Solarite {
|
|
1501
|
-
render() {
|
|
1502
|
-
this.html = r`
|
|
1503
|
-
<div>
|
|
1504
|
-
<script>
|
|
1505
|
-
window.scriptStaticCount = 1;
|
|
1506
|
-
</script>
|
|
1507
|
-
</div>
|
|
1508
|
-
`;
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
let a = new R340();
|
|
1513
|
-
a.render();
|
|
1514
|
-
assert.eq(window.scriptStaticCount, 1);
|
|
1515
|
-
|
|
1516
|
-
// Hasn't changed. Make sure it's nto re-run.
|
|
1517
|
-
a.render();
|
|
1518
|
-
assert.eq(window.scriptStaticCount, 1);
|
|
1519
|
-
|
|
1520
|
-
delete window.scriptStaticCount;
|
|
1521
|
-
});
|
|
1522
|
-
|
|
1523
|
-
// This feature is disabled because it doesn't seem useful.
|
|
1524
|
-
Testimony.test('Solarite.embed._scriptDynamic', () => {
|
|
1525
|
-
|
|
1526
|
-
let val = 1;
|
|
1527
|
-
class R350 extends Solarite {
|
|
1528
|
-
render() {
|
|
1529
|
-
this.html = r`
|
|
1530
|
-
<div>
|
|
1531
|
-
<script>
|
|
1532
|
-
window.scriptStaticCount = ${val};
|
|
1533
|
-
</script>
|
|
1534
|
-
</div>
|
|
1535
|
-
`;
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
let a = new R350();
|
|
1540
|
-
a.render();
|
|
1541
|
-
assert.eq(window.scriptStaticCount, 1);
|
|
1542
|
-
|
|
1543
|
-
// Hasn't changed. Make sure it's not re-run.
|
|
1544
|
-
a.render();
|
|
1545
|
-
assert.eq(window.scriptStaticCount, 1);
|
|
1546
|
-
|
|
1547
|
-
val = 2;
|
|
1548
|
-
a.render();
|
|
1549
|
-
assert.eq(window.scriptStaticCount, 2);
|
|
1550
|
-
|
|
1551
|
-
delete window.scriptStaticCount;
|
|
1552
|
-
});
|
|
1553
|
-
|
|
1554
|
-
//</editor-fold>
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
//<editor-fold desc="attrib">
|
|
1560
|
-
/* ┌─────────────────╮
|
|
1561
|
-
* | Attrib |
|
|
1562
|
-
* └─────────────────╯*/
|
|
1563
|
-
|
|
1564
|
-
Testimony.test('Solarite.attrib.single', () => {
|
|
1565
|
-
|
|
1566
|
-
let val = 'one';
|
|
1567
|
-
|
|
1568
|
-
class R400 extends Solarite {
|
|
1569
|
-
render() {
|
|
1570
|
-
this.html = r`<div class="${val}">${val}</div>`;
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
|
-
let a = new R400();
|
|
1575
|
-
a.render();
|
|
1576
|
-
|
|
1577
|
-
assert.eq(getHtml(a), `<r-400><div class="one">one</div></r-400>`)
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
val = 'two';
|
|
1581
|
-
a.render();
|
|
1582
|
-
assert.eq(getHtml(a), `<r-400><div class="two">two</div></r-400>`)
|
|
1583
|
-
});
|
|
1584
|
-
|
|
1585
|
-
Testimony.test('Solarite.attrib.singleAndText', () => {
|
|
1586
|
-
|
|
1587
|
-
let val = 'one';
|
|
1588
|
-
|
|
1589
|
-
class R410 extends Solarite {
|
|
1590
|
-
render() {
|
|
1591
|
-
this.html = r`<div class="before ${val} after">${val}</div>`;
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
let a = new R410();
|
|
1596
|
-
a.render();
|
|
1597
|
-
|
|
1598
|
-
assert.eq(getHtml(a), `<r-410><div class="before one after">one</div></r-410>`);
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
val = 'two';
|
|
1602
|
-
a.render();
|
|
1603
|
-
assert.eq(getHtml(a), `<r-410><div class="before two after">two</div></r-410>`);
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
val = false;
|
|
1607
|
-
a.render();
|
|
1608
|
-
assert.eq(getHtml(a), `<r-410><div class="before after"></div></r-410>`);
|
|
1609
|
-
});
|
|
1610
|
-
|
|
1611
|
-
Testimony.test('Solarite.attrib.double', () => {
|
|
1612
|
-
|
|
1613
|
-
let val1 = 'one';
|
|
1614
|
-
let val2 = 'two';
|
|
1615
|
-
|
|
1616
|
-
class R420 extends Solarite {
|
|
1617
|
-
render() {
|
|
1618
|
-
this.html = r`<div class="${val1}${val2}">${val1}</div>`;
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
let a = new R420();
|
|
1623
|
-
a.render();
|
|
1624
|
-
|
|
1625
|
-
assert.eq(getHtml(a), `<r-420><div class="onetwo">one</div></r-420>`)
|
|
1626
|
-
|
|
1627
|
-
val1 = 'oneB';
|
|
1628
|
-
val2 = 'twoB';
|
|
1629
|
-
a.render();
|
|
1630
|
-
assert.eq(getHtml(a), `<r-420><div class="oneBtwoB">oneB</div></r-420>`)
|
|
1631
|
-
});
|
|
1632
|
-
|
|
1633
|
-
Testimony.test('Solarite.attrib.doubleAndText', () => {
|
|
1634
|
-
|
|
1635
|
-
let val1 = 'one';
|
|
1636
|
-
let val2 = 'two';
|
|
1637
|
-
|
|
1638
|
-
class R430 extends Solarite {
|
|
1639
|
-
render() {
|
|
1640
|
-
this.html = r`<div class="a ${val1} b ${val2} c">${val1}</div>`;
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
let a = new R430();
|
|
1645
|
-
a.render();
|
|
1646
|
-
|
|
1647
|
-
assert.eq(getHtml(a), `<r-430><div class="a one b two c">one</div></r-430>`)
|
|
1648
|
-
|
|
1649
|
-
val1 = 'oneB';
|
|
1650
|
-
val2 = 'twoB';
|
|
1651
|
-
a.render();
|
|
1652
|
-
assert.eq(getHtml(a), `<r-430><div class="a oneB b twoB c">oneB</div></r-430>`)
|
|
1653
|
-
});
|
|
1654
|
-
|
|
1655
|
-
Testimony.test('Solarite.attrib.doubleAndText', () => {
|
|
1656
|
-
|
|
1657
|
-
let val1 = 'one';
|
|
1658
|
-
let val2 = 'two';
|
|
1659
|
-
|
|
1660
|
-
class R430 extends Solarite {
|
|
1661
|
-
render() {
|
|
1662
|
-
this.html = r`<div class="a ${val1} b ${val2} c">${val1}</div>`;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
let a = new R430();
|
|
1667
|
-
a.render();
|
|
1668
|
-
|
|
1669
|
-
assert.eq(getHtml(a), `<r-430><div class="a one b two c">one</div></r-430>`)
|
|
1670
|
-
|
|
1671
|
-
val1 = 'oneB';
|
|
1672
|
-
val2 = 'twoB';
|
|
1673
|
-
a.render();
|
|
1674
|
-
assert.eq(getHtml(a), `<r-430><div class="a oneB b twoB c">oneB</div></r-430>`)
|
|
1675
|
-
});
|
|
1676
|
-
|
|
1677
|
-
Testimony.test('Solarite.attrib.sparse', () => {
|
|
1678
|
-
|
|
1679
|
-
let isEdit = false;
|
|
1680
|
-
|
|
1681
|
-
class R440 extends Solarite {
|
|
1682
|
-
render() {
|
|
1683
|
-
this.html = r`<div ${isEdit && 'contenteditable'}>${isEdit && 'Editable!'}</div>`;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
let a = new R440();
|
|
1688
|
-
a.render();
|
|
1689
|
-
assert.eq(getHtml(a), `<r-440><div></div></r-440>`)
|
|
1690
|
-
|
|
1691
|
-
isEdit = true
|
|
1692
|
-
a.render();
|
|
1693
|
-
assert.eq(getHtml(a), `<r-440><div contenteditable="">Editable!</div></r-440>`)
|
|
1694
|
-
|
|
1695
|
-
isEdit = false
|
|
1696
|
-
a.render();
|
|
1697
|
-
assert.eq(getHtml(a), `<r-440><div></div></r-440>`)
|
|
1698
|
-
});
|
|
1699
|
-
|
|
1700
|
-
Testimony.test('Solarite.attrib.doubleSparse', () => {
|
|
1701
|
-
|
|
1702
|
-
let isEdit = false;
|
|
1703
|
-
|
|
1704
|
-
class R450 extends Solarite {
|
|
1705
|
-
render() {
|
|
1706
|
-
this.html = r`<div ${isEdit && 'contenteditable spellcheck="false"'}>${isEdit && 'Editable!'}</div>`;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
let a = new R450();
|
|
1711
|
-
a.render();
|
|
1712
|
-
assert.eq(getHtml(a), `<r-450><div></div></r-450>`)
|
|
1713
|
-
|
|
1714
|
-
isEdit = true
|
|
1715
|
-
a.render();
|
|
1716
|
-
assert.eq(getHtml(a), `<r-450><div contenteditable="" spellcheck="false">Editable!</div></r-450>`)
|
|
1717
|
-
|
|
1718
|
-
isEdit = false
|
|
1719
|
-
a.render();
|
|
1720
|
-
assert.eq(getHtml(a), `<r-450><div></div></r-450>`)
|
|
1721
|
-
});
|
|
1722
|
-
|
|
1723
|
-
Testimony.test('Solarite.attrib.toggle', () => {
|
|
1724
|
-
|
|
1725
|
-
let isEdit = false;
|
|
1726
|
-
|
|
1727
|
-
class R460 extends Solarite {
|
|
1728
|
-
render() {
|
|
1729
|
-
this.html = r`<div contenteditable=${isEdit}>${isEdit && 'Editable!'}</div>`;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
let a = new R460();
|
|
1734
|
-
a.render();
|
|
1735
|
-
assert.eq(getHtml(a), `<r-460><div></div></r-460>`)
|
|
1736
|
-
|
|
1737
|
-
isEdit = true
|
|
1738
|
-
a.render();
|
|
1739
|
-
assert.eq(getHtml(a), `<r-460><div contenteditable="">Editable!</div></r-460>`)
|
|
1740
|
-
|
|
1741
|
-
isEdit = false
|
|
1742
|
-
a.render();
|
|
1743
|
-
assert.eq(getHtml(a), `<r-460><div></div></r-460>`)
|
|
1744
|
-
});
|
|
1745
|
-
|
|
1746
|
-
Testimony.test('Solarite.attrib.pseudoRoot', () => {
|
|
1747
|
-
let title = 'Hello'
|
|
1748
|
-
class R470 extends Solarite {
|
|
1749
|
-
render() {
|
|
1750
|
-
r(this)`<r-470 title="${title}">World</r-470>`
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
let a = new R470();
|
|
1755
|
-
a.render();
|
|
1756
|
-
assert.eq(getHtml(a), `<r-470 title="Hello">World</r-470>`)
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
title = 'Goodbye'
|
|
1760
|
-
a.render();
|
|
1761
|
-
assert.eq(a.outerHTML, `<r-470 title="Goodbye">World</r-470>`)
|
|
1762
|
-
|
|
1763
|
-
title = false
|
|
1764
|
-
a.render();
|
|
1765
|
-
assert.eq(a.outerHTML, `<r-470>World</r-470>`)
|
|
1766
|
-
});
|
|
1767
|
-
|
|
1768
|
-
Testimony.test('Solarite.attrib.pseudoRoot2', 'Static attribute overrides.', () => {
|
|
1769
|
-
let title = 'Hello'
|
|
1770
|
-
class R472 extends Solarite {
|
|
1771
|
-
render() {
|
|
1772
|
-
this.html = r`<r-472 title="${title}" style="color: red">World</r-472>`
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
R472.define();
|
|
1776
|
-
|
|
1777
|
-
let b = r(`<r-472 style="color: green"></r-472>`);
|
|
1778
|
-
document.body.append(b);
|
|
1779
|
-
assert.eq(b.outerHTML, `<r-472 style="color: green" title="Hello">World</r-472>`);
|
|
1780
|
-
b.remove();
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
});
|
|
1784
|
-
|
|
1785
|
-
Testimony.test('Solarite.attrib.pseudoRoot3', 'Dynamic attribute overrides.', () => {
|
|
1786
|
-
let title = 'Hello'
|
|
1787
|
-
class R473 extends Solarite {
|
|
1788
|
-
render() {
|
|
1789
|
-
this.html = r`<r-473 title="${title}" style="color: red">World</r-473>`
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
R473.define();
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
let a = r(`<r-473 title="Goodbye"></r-473>`);
|
|
1796
|
-
document.body.append(a);
|
|
1797
|
-
|
|
1798
|
-
// Dynamic attributes take precedence
|
|
1799
|
-
assert.eq(a.outerHTML, `<r-473 title="Hello" style="color: red">World</r-473>`);
|
|
1800
|
-
|
|
1801
|
-
a.render();
|
|
1802
|
-
assert.eq(a.outerHTML, `<r-473 title="Hello" style="color: red">World</r-473>`);
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
title = 'Blue';
|
|
1806
|
-
a.setAttribute('style', 'color: blue');
|
|
1807
|
-
|
|
1808
|
-
a.render();
|
|
1809
|
-
assert.eq(a.outerHTML, `<r-473 title="Blue" style="color: blue">World</r-473>`);
|
|
1810
|
-
|
|
1811
|
-
a.remove();
|
|
1812
|
-
});
|
|
1813
|
-
|
|
1814
|
-
Testimony.test('Solarite.attrib.multiple', '', () => {
|
|
1815
|
-
let button = 'Hello'
|
|
1816
|
-
class R474 extends Solarite {
|
|
1817
|
-
render() {
|
|
1818
|
-
this.html = r`
|
|
1819
|
-
<r-474><button ${'class="primary"'} onclick=${e => {}}>${button}</button></r-474>`
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
let a = new R474();
|
|
1824
|
-
a.render();
|
|
1825
|
-
|
|
1826
|
-
assert.eq(getHtml(a), `<r-474><button onclick="" class="primary">Hello</button></r-474>`);
|
|
1827
|
-
});
|
|
1828
|
-
|
|
1829
|
-
Testimony.test('Solarite.attrib.ids1', () => {
|
|
1830
|
-
class R500 extends Solarite {
|
|
1831
|
-
one;
|
|
1832
|
-
render() {
|
|
1833
|
-
r(this)`<div data-id="one"></div>`;
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
let a = new R500();
|
|
1838
|
-
a.render();
|
|
1839
|
-
|
|
1840
|
-
assert(a.one.tagName === 'DIV')
|
|
1841
|
-
});
|
|
1842
|
-
|
|
1843
|
-
Testimony.test('Solarite.attrib.ids2', () => {
|
|
1844
|
-
class R510 extends Solarite {
|
|
1845
|
-
one;
|
|
1846
|
-
render() {
|
|
1847
|
-
r(this)`<div data-id="one"><p id="two"></p></div>`;
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
let a = new R510();
|
|
1852
|
-
a.render();
|
|
1853
|
-
|
|
1854
|
-
assert(a.one.tagName === 'DIV')
|
|
1855
|
-
assert(a.two.tagName === 'P')
|
|
1856
|
-
});
|
|
1857
|
-
|
|
1858
|
-
Testimony.test('Solarite.attrib.idsDelve', () => {
|
|
1859
|
-
class R520 extends Solarite {
|
|
1860
|
-
one;
|
|
1861
|
-
render() {
|
|
1862
|
-
r(this)`<div data-id="one"><p id="path.to.p"></p></div>`;
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
|
-
let a = new R520();
|
|
1867
|
-
a.render();
|
|
1868
|
-
|
|
1869
|
-
assert(a.one.tagName === 'DIV')
|
|
1870
|
-
assert(a.path.to.p.tagName === 'P')
|
|
1871
|
-
});
|
|
1872
|
-
//</editor-fold>
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
//<editor-fold desc="comments">
|
|
1878
|
-
/* ┌─────────────────╮
|
|
1879
|
-
* | comments |
|
|
1880
|
-
* └─────────────────╯*/
|
|
1881
|
-
Testimony.test('Solarite.comments.one', () => {
|
|
1882
|
-
|
|
1883
|
-
class A480 extends Solarite {
|
|
1884
|
-
render() {
|
|
1885
|
-
this.html = r`
|
|
1886
|
-
<!--a-->
|
|
1887
|
-
<div></div>`
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
let a = new A480();
|
|
1891
|
-
document.body.append(a);
|
|
1892
|
-
assert.eq(getHtml(a), `<a-480><div></div></a-480>`);
|
|
1893
|
-
a.remove();
|
|
1894
|
-
});
|
|
1895
|
-
|
|
1896
|
-
Testimony.test('Solarite.comments.two', () => {
|
|
1897
|
-
|
|
1898
|
-
class A482 extends Solarite {
|
|
1899
|
-
render() {
|
|
1900
|
-
this.html = r`<div><!--${1} ${2}-->${3}</div>`
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
let a = new A482();
|
|
1904
|
-
|
|
1905
|
-
a.render();
|
|
1906
|
-
assert.eq(getHtml(a), `<a-482><div>3</div></a-482>`)
|
|
1907
|
-
a.remove();
|
|
1908
|
-
});
|
|
1909
|
-
//</editor-fold>
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
//<editor-fold desc="r">
|
|
1915
|
-
/* ┌─────────────────╮
|
|
1916
|
-
* | r |
|
|
1917
|
-
* └─────────────────╯*/
|
|
1918
|
-
Testimony.test('Solarite.r.staticElement', () => {
|
|
1919
|
-
let button = r(`<button>hi</button>`);
|
|
1920
|
-
assert(button instanceof HTMLElement); // Not a DocumentFragment
|
|
1921
|
-
assert.eq(getHtml(button), `<button>hi</button>`)
|
|
1922
|
-
})
|
|
1923
|
-
|
|
1924
|
-
Testimony.test('Solarite.r.staticElement2', () => {
|
|
1925
|
-
let button = r(`
|
|
1926
|
-
<button>hi</button>`);
|
|
1927
|
-
assert(button instanceof HTMLElement); // Not a DocumentFragment
|
|
1928
|
-
assert.eq(getHtml(button), `<button>hi</button>`)
|
|
1929
|
-
})
|
|
1930
|
-
|
|
1931
|
-
Testimony.test('Solarite.r.staticElement3', () => {
|
|
1932
|
-
let button = r(` <!-- comment -->
|
|
1933
|
-
<button>hi</button>`);
|
|
1934
|
-
assert(button instanceof HTMLElement); // Not a DocumentFragment
|
|
1935
|
-
assert.eq(getHtml(button), `<button>hi</button>`)
|
|
1936
|
-
})
|
|
1937
|
-
|
|
1938
|
-
Testimony.test('Solarite.r.staticElement4', () => {
|
|
1939
|
-
let button = r(` Hello`);
|
|
1940
|
-
assert(button instanceof Text);
|
|
1941
|
-
assert.eq(getHtml(button), ` Hello`)
|
|
1942
|
-
})
|
|
1943
|
-
|
|
1944
|
-
Testimony.test('Solarite.r.staticElement5', () => {
|
|
1945
|
-
let button = r(` <!--comment--> Hello`);
|
|
1946
|
-
assert(button instanceof Text);
|
|
1947
|
-
assert.eq(getHtml(button), ` Hello`)
|
|
1948
|
-
})
|
|
1949
|
-
|
|
1950
|
-
Testimony.test('Solarite.r.fragment', () => {
|
|
1951
|
-
let fragment = r(`Hello <button>hi</button>`);
|
|
1952
|
-
assert(fragment instanceof DocumentFragment);
|
|
1953
|
-
assert.eq(getHtml(fragment), `Hello |<button>hi</button>`)
|
|
1954
|
-
});
|
|
1955
|
-
|
|
1956
|
-
Testimony.test('Solarite.r.fragment2', () => {
|
|
1957
|
-
let fragment = r()`Hello <button>hi</button>`;
|
|
1958
|
-
assert(fragment instanceof DocumentFragment);
|
|
1959
|
-
assert.eq(getHtml(fragment), `Hello |<button>hi</button>`)
|
|
1960
|
-
});
|
|
1961
|
-
|
|
1962
|
-
Testimony.test('Solarite.r.staticElement3', () => {
|
|
1963
|
-
let button = r()`<button>hi</button>`;
|
|
1964
|
-
assert(button instanceof HTMLElement);
|
|
1965
|
-
assert.eq(getHtml(button), `<button>hi</button>`)
|
|
1966
|
-
});
|
|
1967
|
-
|
|
1968
|
-
Testimony.test('Solarite.r.staticElement4', () => {
|
|
1969
|
-
// with line return
|
|
1970
|
-
let button = r()`
|
|
1971
|
-
<button>hi</button>`;
|
|
1972
|
-
assert(button instanceof HTMLElement);
|
|
1973
|
-
assert.eq(getHtml(button), `<button>hi</button>`)
|
|
1974
|
-
})
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
Testimony.test('Solarite.r.element', () => {
|
|
1979
|
-
let adjective = 'better'
|
|
1980
|
-
let button = r()`<button>I'm a <b>${adjective}</b> button</button>`;
|
|
1981
|
-
|
|
1982
|
-
assert.eq(getHtml(button), `<button>I'm a <b>better</b> button</button>`)
|
|
1983
|
-
})
|
|
1984
|
-
|
|
1985
|
-
Testimony.test('Solarite.r.standalone1', () => {
|
|
1986
|
-
let button = r({
|
|
1987
|
-
count: 0,
|
|
1988
|
-
|
|
1989
|
-
inc() {
|
|
1990
|
-
this.count++;
|
|
1991
|
-
this.render();
|
|
1992
|
-
},
|
|
1993
|
-
|
|
1994
|
-
render() {
|
|
1995
|
-
r(this)`<button onclick=${this.inc}>I've been clicked ${this.count} times.</button>`
|
|
1996
|
-
}
|
|
1997
|
-
});
|
|
1998
|
-
//document.body.append(button);
|
|
1999
|
-
|
|
2000
|
-
assert.eq(getHtml(button), `<button onclick="">I've been clicked 0 times.</button>`)
|
|
2001
|
-
|
|
2002
|
-
button.inc();
|
|
2003
|
-
assert.eq(getHtml(button), `<button onclick="">I've been clicked 1 times.</button>`);
|
|
2004
|
-
|
|
2005
|
-
button.dispatchEvent(new MouseEvent('click'));
|
|
2006
|
-
assert.eq(getHtml(button), `<button onclick="">I've been clicked 2 times.</button>`);
|
|
2007
|
-
|
|
2008
|
-
//button.remove();
|
|
2009
|
-
});
|
|
2010
|
-
|
|
2011
|
-
Testimony.test('Solarite.r.standalone2', () => {
|
|
2012
|
-
let list = r({
|
|
2013
|
-
items: [],
|
|
2014
|
-
|
|
2015
|
-
add() {
|
|
2016
|
-
this.items.push('Item ' + this.items.length);
|
|
2017
|
-
this.render();
|
|
2018
|
-
},
|
|
2019
|
-
|
|
2020
|
-
render() {
|
|
2021
|
-
r(this)`
|
|
2022
|
-
<div>
|
|
2023
|
-
<button onclick=${this.add}>Add Item</button>
|
|
2024
|
-
<hr>
|
|
2025
|
-
${this.items.map(item => r`
|
|
2026
|
-
<p>${item}</p>
|
|
2027
|
-
`)}
|
|
2028
|
-
</div>`
|
|
2029
|
-
}
|
|
2030
|
-
});
|
|
2031
|
-
|
|
2032
|
-
//document.body.append(list);
|
|
2033
|
-
|
|
2034
|
-
assert.eq(getHtml(list), `<div><button onclick="">Add Item</button><hr></div>`);
|
|
2035
|
-
|
|
2036
|
-
// At one point, rendering a standalone component the first time would re-render everything.
|
|
2037
|
-
// Here we make sure the hr element doesn't come back.
|
|
2038
|
-
list.querySelector('hr').remove();
|
|
2039
|
-
list.render();
|
|
2040
|
-
|
|
2041
|
-
assert.eq(getHtml(list), `<div><button onclick="">Add Item</button></div>`);
|
|
2042
|
-
|
|
2043
|
-
list.add();
|
|
2044
|
-
assert.eq(getHtml(list), `<div><button onclick="">Add Item</button><p>Item 0</p></div>`);
|
|
2045
|
-
|
|
2046
|
-
list.querySelector('button').dispatchEvent(new MouseEvent('click'));
|
|
2047
|
-
assert.eq(getHtml(list), `<div><button onclick="">Add Item</button><p>Item 0</p><p>Item 1</p></div>`);
|
|
2048
|
-
|
|
2049
|
-
//button.remove();
|
|
2050
|
-
});
|
|
2051
|
-
|
|
2052
|
-
Testimony.test('Solarite.r.standaloneId', "Test id's on standalone elmenets.", () => {
|
|
2053
|
-
let list = r({
|
|
2054
|
-
items: [],
|
|
2055
|
-
|
|
2056
|
-
add() {
|
|
2057
|
-
this.items.push('Item ' + this.items.length);
|
|
2058
|
-
this.render();
|
|
2059
|
-
},
|
|
2060
|
-
|
|
2061
|
-
render() {
|
|
2062
|
-
r(this)`
|
|
2063
|
-
<div>
|
|
2064
|
-
<button data-id="button" onclick=${this.add}>Add Item</button>
|
|
2065
|
-
</div>`
|
|
2066
|
-
}
|
|
2067
|
-
});
|
|
2068
|
-
|
|
2069
|
-
assert.eq(list.button.tagName, 'BUTTON');
|
|
2070
|
-
});
|
|
2071
|
-
|
|
2072
|
-
Testimony.test('Solarite.r.standaloneStyle', "Test id's on standalone elmenets.", () => {
|
|
2073
|
-
let box = r({
|
|
2074
|
-
render() {
|
|
2075
|
-
r(this)`
|
|
2076
|
-
<div>
|
|
2077
|
-
<style>:host { display: block; background: red; width: 20px; height: 20px }</style>
|
|
2078
|
-
</div>`
|
|
2079
|
-
}
|
|
2080
|
-
});
|
|
2081
|
-
|
|
2082
|
-
let styleId = box.getAttribute('data-style');
|
|
2083
|
-
assert.eq(box.firstElementChild.textContent, `div[data-style="${styleId}"] { display: block; background: red; width: 20px; height: 20px }`);
|
|
2084
|
-
});
|
|
2085
|
-
|
|
2086
|
-
Testimony.test('Solarite.r.standalone3', () => {
|
|
2087
|
-
|
|
2088
|
-
// Make sure a div inside a div doesn't replace the parent div.
|
|
2089
|
-
let list = r({
|
|
2090
|
-
items: [],
|
|
2091
|
-
|
|
2092
|
-
render() {
|
|
2093
|
-
r(this)`
|
|
2094
|
-
<div>
|
|
2095
|
-
${this.items.map(item => r`
|
|
2096
|
-
<div>
|
|
2097
|
-
<input placeholder="Name" value=${item.name}>
|
|
2098
|
-
<input type="number" value=${item.qty}>
|
|
2099
|
-
<button onclick=${()=>this.removeItem(item)}>x</button>
|
|
2100
|
-
</div>
|
|
2101
|
-
`)}
|
|
2102
|
-
</div>`
|
|
2103
|
-
}
|
|
2104
|
-
});
|
|
2105
|
-
|
|
2106
|
-
list.items.push({name: 'name', qty: 2});
|
|
2107
|
-
list.render();
|
|
2108
|
-
|
|
2109
|
-
assert.eq(getHtml(list), `<div><div><input placeholder="Name" value="name"><input type="number" value="2"><button onclick="">x</button></div></div>`);
|
|
2110
|
-
});
|
|
2111
|
-
|
|
2112
|
-
Testimony.test('Solarite.r.standaloneChild', () => {
|
|
2113
|
-
|
|
2114
|
-
function createItem(item) {
|
|
2115
|
-
return r({
|
|
2116
|
-
item: item,
|
|
2117
|
-
render(attribs = null) {
|
|
2118
|
-
// If attributes passed to constructor have changed.
|
|
2119
|
-
if (attribs)
|
|
2120
|
-
this.item = attribs.item;
|
|
2121
|
-
r(this)`
|
|
2122
|
-
<div>
|
|
2123
|
-
<b>${this.item.name}</b> - ${this.item.description}<br>
|
|
2124
|
-
</div>`
|
|
2125
|
-
}
|
|
2126
|
-
});
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
function createList(items) {
|
|
2130
|
-
return r({
|
|
2131
|
-
items: items,
|
|
2132
|
-
render() {
|
|
2133
|
-
r(this)`
|
|
2134
|
-
<div>
|
|
2135
|
-
${this.items.map(item =>
|
|
2136
|
-
createItem(item)
|
|
2137
|
-
)}
|
|
2138
|
-
</div>`
|
|
2139
|
-
}
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
let list = createList([
|
|
2144
|
-
{
|
|
2145
|
-
name: 'English',
|
|
2146
|
-
description: 'See spot run.'
|
|
2147
|
-
},
|
|
2148
|
-
|
|
2149
|
-
{
|
|
2150
|
-
name: 'Science',
|
|
2151
|
-
description: 'Snails are mollusks.'
|
|
2152
|
-
}
|
|
2153
|
-
]);
|
|
2154
|
-
document.body.append(list);
|
|
2155
|
-
|
|
2156
|
-
list.items[0].name = 'PhysEd';
|
|
2157
|
-
list.render(); // calls NotesItem.render() with the new item.
|
|
2158
|
-
|
|
2159
|
-
assert.eq(getHtml(list), `<div><div><b>PhysEd</b> - See spot run.<br></div><div><b>Science</b> - Snails are mollusks.<br></div></div>`);
|
|
2160
|
-
|
|
2161
|
-
list.remove();
|
|
2162
|
-
});
|
|
2163
|
-
//</editor-fold>
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
//<editor-fold desc="component">
|
|
2169
|
-
/* ┌─────────────────╮
|
|
2170
|
-
* | Component |
|
|
2171
|
-
* └─────────────────╯*/
|
|
2172
|
-
Testimony.test('Solarite.component.tr', () => {
|
|
2173
|
-
|
|
2174
|
-
class TR510 extends Solarite('tr') {
|
|
2175
|
-
render() {
|
|
2176
|
-
this.html = r`<td>hello</td>`
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
let table = document.createElement('table')
|
|
2181
|
-
|
|
2182
|
-
table.append(new TR510())
|
|
2183
|
-
document.body.append(table)
|
|
2184
|
-
|
|
2185
|
-
assert.eq(table.outerHTML, `<table><tr is="tr-510"><td>hello</td></tr></table>`)
|
|
2186
|
-
|
|
2187
|
-
table.remove();
|
|
2188
|
-
|
|
2189
|
-
});
|
|
2190
|
-
|
|
2191
|
-
Testimony.test('Solarite.component.staticAttribs', () => {
|
|
2192
|
-
// Note that all attribs become lowercase.
|
|
2193
|
-
// Not sure how to prevent this w/o using an xml doctype.
|
|
2194
|
-
class B512 extends Solarite {
|
|
2195
|
-
constructor({name, userid}={}) {
|
|
2196
|
-
super();
|
|
2197
|
-
this.name = name;
|
|
2198
|
-
this.userId = userid;
|
|
2199
|
-
}
|
|
2200
|
-
|
|
2201
|
-
render() {
|
|
2202
|
-
this.html = r`<b-512>${this.name} | ${this.userId}</b-512>`
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
B512.define();
|
|
2206
|
-
|
|
2207
|
-
class A512 extends Solarite {
|
|
2208
|
-
render() {
|
|
2209
|
-
this.html = r`<div><b-512 name="User" userId="2"></b-512></div>`;
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
A512.define();
|
|
2213
|
-
|
|
2214
|
-
let a = new A512();
|
|
2215
|
-
a.render();
|
|
2216
|
-
|
|
2217
|
-
assert.eq(a.outerHTML, `<a-512><div><b-512 name="User" userid="2"><!--ExprPath:0-->User | 2<!--ExprPathEnd:1--></b-512></div></a-512>`);
|
|
2218
|
-
});
|
|
2219
|
-
|
|
2220
|
-
Testimony.test('Solarite.component.dynamicAttribs', 'Attribs specified via ${...}', () => {
|
|
2221
|
-
|
|
2222
|
-
class B513 extends Solarite {
|
|
2223
|
-
constructor({name, userid}={}) {
|
|
2224
|
-
super();
|
|
2225
|
-
this.name = name;
|
|
2226
|
-
this.userId = userid;
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
render() {
|
|
2230
|
-
this.html = r`<b-513>${this.name} | ${this.userId}</b-513>`
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
B513.define();
|
|
2234
|
-
|
|
2235
|
-
class A513 extends Solarite {
|
|
2236
|
-
render() {
|
|
2237
|
-
this.html = r`<div><b-513 name="${'User'}" userId="${2}"></b-513></div>`;
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
|
-
A513.define();
|
|
2241
|
-
|
|
2242
|
-
let a = new A513();
|
|
2243
|
-
a.render();
|
|
2244
|
-
|
|
2245
|
-
assert.eq(a.outerHTML, `<a-513><div><b-513 name="User" userid="2"><!--ExprPath:0-->User | 2<!--ExprPathEnd:1--></b-513></div></a-513>`);
|
|
2246
|
-
});
|
|
2247
|
-
|
|
2248
|
-
Testimony.test('Solarite.component.getArg', 'Attribs specified html when not nested in another Solarite component.', () => {
|
|
2249
|
-
|
|
2250
|
-
class B514 extends Solarite {
|
|
2251
|
-
constructor({name, userid}={}) {
|
|
2252
|
-
super();
|
|
2253
|
-
|
|
2254
|
-
this.name = getArg(this, 'name', name);
|
|
2255
|
-
this.userId = getArg(this, 'userid', userid);
|
|
2256
|
-
this.render();
|
|
2257
|
-
}
|
|
2258
|
-
|
|
2259
|
-
render() {
|
|
2260
|
-
this.html = r`<b-514>${this.name} | ${this.userId}</b-514>`
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
B514.define();
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
let div = document.createElement('div');
|
|
2267
|
-
div.innerHTML = `<b-514 name="User" userid="2"></b-514>`
|
|
2268
|
-
|
|
2269
|
-
assert.eq(div.outerHTML, `<div><b-514 name="User" userid="2"><!--ExprPath:0-->User | 2<!--ExprPathEnd:1--></b-514></div>`)
|
|
2270
|
-
|
|
2271
|
-
});
|
|
2272
|
-
|
|
2273
|
-
Testimony.test('Solarite.component.nested', () => {
|
|
2274
|
-
|
|
2275
|
-
let bRenderCount = 0;
|
|
2276
|
-
|
|
2277
|
-
class B515 extends Solarite {
|
|
2278
|
-
render() {
|
|
2279
|
-
this.html = r`<div>B</div>`;
|
|
2280
|
-
bRenderCount++;
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
B515.define();
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
class A515 extends Solarite {
|
|
2287
|
-
render() {
|
|
2288
|
-
this.html =
|
|
2289
|
-
r`<b-515></b-515>`
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
let a = new A515();
|
|
2294
|
-
assert(!(a.firstChild instanceof B515))
|
|
2295
|
-
|
|
2296
|
-
a.render();
|
|
2297
|
-
assert(a.firstChild instanceof B515);
|
|
2298
|
-
assert.eq(getHtml(a), `<a-515><b-515><div>B</div></b-515></a-515>`);
|
|
2299
|
-
})
|
|
2300
|
-
|
|
2301
|
-
// Pass an object to the child.
|
|
2302
|
-
Testimony.test('Solarite.component.nested2', () => {
|
|
2303
|
-
|
|
2304
|
-
let bRenderCount = 0;
|
|
2305
|
-
class B520 extends Solarite {
|
|
2306
|
-
|
|
2307
|
-
constructor({user}={}) {
|
|
2308
|
-
super();
|
|
2309
|
-
this.user = user;
|
|
2310
|
-
}
|
|
2311
|
-
|
|
2312
|
-
render(props={}) {
|
|
2313
|
-
if (props.user)
|
|
2314
|
-
this.user = props.user;
|
|
2315
|
-
this.html = r`<div>Name:</div><div>${this.user.name}</div><div>Email:</div><div>${this.user.email}</div>`;
|
|
2316
|
-
bRenderCount++;
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
}
|
|
2320
|
-
B520.define();
|
|
2321
|
-
|
|
2322
|
-
class A520 extends Solarite {
|
|
2323
|
-
title = 'Users'
|
|
2324
|
-
user = {name: 'John', email: 'john@example.com'};
|
|
2325
|
-
render() {
|
|
2326
|
-
r(this)`${this.title}<b-520 user="${this.user}"></b-520>`
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
let a = new A520();
|
|
2331
|
-
document.body.append(a);
|
|
2332
|
-
assert.eq(getHtml(a), `<a-520>Users<b-520 user=""><div>Name:</div><div>John</div><div>Email:</div><div>john@example.com</div></b-520></a-520>`)
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
a.user = {name: 'Fred', email: 'fred@example.com'};
|
|
2336
|
-
a.render();
|
|
2337
|
-
assert.eq(getHtml(a), `<a-520>Users<b-520 user=""><div>Name:</div><div>Fred</div><div>Email:</div><div>fred@example.com</div></b-520></a-520>`)
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
a.user.name = 'Barry'
|
|
2341
|
-
a.render();
|
|
2342
|
-
assert.eq(getHtml(a), `<a-520>Users<b-520 user=""><div>Name:</div><div>Barry</div><div>Email:</div><div>fred@example.com</div></b-520></a-520>`)
|
|
2343
|
-
|
|
2344
|
-
bRenderCount = 0
|
|
2345
|
-
a.render();
|
|
2346
|
-
assert.eq(bRenderCount, 0)
|
|
2347
|
-
|
|
2348
|
-
a.title = 'Users2'
|
|
2349
|
-
a.render();
|
|
2350
|
-
assert.eq(getHtml(a), `<a-520>Users2<b-520 user=""><div>Name:</div><div>Barry</div><div>Email:</div><div>fred@example.com</div></b-520></a-520>`)
|
|
2351
|
-
assert.eq(bRenderCount, 0); // Value passed to b didn't change, so it shouldn't re-render.
|
|
2352
|
-
|
|
2353
|
-
a.remove();
|
|
2354
|
-
});
|
|
2355
|
-
|
|
2356
|
-
// Pass an object to the child.
|
|
2357
|
-
Testimony.test('Solarite.component.nestedNonSolarite', () => {
|
|
2358
|
-
|
|
2359
|
-
let bRenderCount = 0;
|
|
2360
|
-
class B530 extends HTMLElement {
|
|
2361
|
-
|
|
2362
|
-
constructor({user}={}) {
|
|
2363
|
-
super();
|
|
2364
|
-
this.user = user;
|
|
2365
|
-
this.render();
|
|
2366
|
-
}
|
|
2367
|
-
|
|
2368
|
-
render(props={}) {
|
|
2369
|
-
if (props.user)
|
|
2370
|
-
this.user = props.user;
|
|
2371
|
-
r(this)`<div>Name:</div><div>${this.user.name}</div><div>Email:</div><div>${this.user.email}</div>`;
|
|
2372
|
-
bRenderCount++;
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
2375
|
-
customElements.define('b-530', B530);
|
|
2376
|
-
|
|
2377
|
-
class A530 extends HTMLElement {
|
|
2378
|
-
title = 'Users'
|
|
2379
|
-
user = {name: 'John', email: 'john@example.com'};
|
|
2380
|
-
render() {
|
|
2381
|
-
r(this)`${this.title}<b-530 user="${this.user}"></b-530>`
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
customElements.define('a-530', A530);
|
|
2385
|
-
|
|
2386
|
-
let a = new A530();
|
|
2387
|
-
a.render();
|
|
2388
|
-
document.body.append(a);
|
|
2389
|
-
assert.eq(getHtml(a), `<a-530>Users<b-530 user=""><div>Name:</div><div>John</div><div>Email:</div><div>john@example.com</div></b-530></a-530>`)
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
a.user = {name: 'Fred', email: 'fred@example.com'};
|
|
2393
|
-
a.render();
|
|
2394
|
-
assert.eq(getHtml(a), `<a-530>Users<b-530 user=""><div>Name:</div><div>Fred</div><div>Email:</div><div>fred@example.com</div></b-530></a-530>`)
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
a.user.name = 'Barry'
|
|
2398
|
-
a.render();
|
|
2399
|
-
assert.eq(getHtml(a), `<a-530>Users<b-530 user=""><div>Name:</div><div>Barry</div><div>Email:</div><div>fred@example.com</div></b-530></a-530>`)
|
|
2400
|
-
|
|
2401
|
-
bRenderCount = 0
|
|
2402
|
-
a.render();
|
|
2403
|
-
assert.eq(bRenderCount, 0)
|
|
2404
|
-
|
|
2405
|
-
a.title = 'Users2'
|
|
2406
|
-
a.render();
|
|
2407
|
-
assert.eq(getHtml(a), `<a-530>Users2<b-530 user=""><div>Name:</div><div>Barry</div><div>Email:</div><div>fred@example.com</div></b-530></a-530>`)
|
|
2408
|
-
assert.eq(bRenderCount, 0) // Value passed to b didn't change, so it shouldn't re-render.
|
|
2409
|
-
|
|
2410
|
-
a.remove();
|
|
2411
|
-
});
|
|
2412
|
-
|
|
2413
|
-
// TODO: This redraws every tr on every update.
|
|
2414
|
-
// Maybe that can be fixed when keying is supported?
|
|
2415
|
-
Testimony.test('Solarite.component.nestedTrLoop', () => {
|
|
2416
|
-
|
|
2417
|
-
function tableRow(user) {
|
|
2418
|
-
let tr = r({
|
|
2419
|
-
render() {
|
|
2420
|
-
r(this)`<tr><td>${user.name}</td><td>${user.email}</td></tr>`
|
|
2421
|
-
}
|
|
2422
|
-
})
|
|
2423
|
-
return tr;
|
|
2424
|
-
}
|
|
2425
|
-
|
|
2426
|
-
class MyTable extends Solarite {
|
|
2427
|
-
users = [
|
|
2428
|
-
{name: 'John', email: 'john@example.com'},
|
|
2429
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
2430
|
-
]
|
|
2431
|
-
render() {
|
|
2432
|
-
this.html = r`<table><tbody>${this.users.map(user => tableRow(user))}</tbody></table>`
|
|
2433
|
-
}
|
|
2434
|
-
}
|
|
2435
|
-
let table = new MyTable
|
|
2436
|
-
document.body.append(table)
|
|
2437
|
-
assert.eq(getHtml(table),
|
|
2438
|
-
`<my-table><table><tbody>`+
|
|
2439
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
2440
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
2441
|
-
`</tbody></table></my-table>`)
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
table.users[1].name = 'Barry'
|
|
2445
|
-
|
|
2446
|
-
table.render();
|
|
2447
|
-
assert.eq(getHtml(table),
|
|
2448
|
-
`<my-table><table><tbody>` +
|
|
2449
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
2450
|
-
`<tr><td>Barry</td><td>fred@example.com</td></tr>` +
|
|
2451
|
-
`</tbody></table></my-table>`)
|
|
2452
|
-
|
|
2453
|
-
table.remove();
|
|
2454
|
-
});
|
|
2455
|
-
|
|
2456
|
-
Testimony.test('Solarite.component.nestedComponentTrLoop', () => {
|
|
2457
|
-
|
|
2458
|
-
class TR540 extends Solarite('tr') {
|
|
2459
|
-
constructor({user}={}) {
|
|
2460
|
-
super();
|
|
2461
|
-
this.user = user;
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
render() {
|
|
2465
|
-
this.html = r`<td>${this.user.name}</td><td>${this.user.email}</td>`
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
TR540.define('tr-540');
|
|
2469
|
-
|
|
2470
|
-
class Table540 extends Solarite {
|
|
2471
|
-
|
|
2472
|
-
users = [
|
|
2473
|
-
{name: 'John', email: 'john@example.com'},
|
|
2474
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
2475
|
-
]
|
|
2476
|
-
render() {
|
|
2477
|
-
this.html = r`<table><tbody>${this.users.map(user => r`<tr is="tr-540" user="${user}"></tr>`)}</tbody></table>`
|
|
2478
|
-
}
|
|
2479
|
-
}
|
|
2480
|
-
let table = new Table540
|
|
2481
|
-
document.body.append(table)
|
|
2482
|
-
assert.eq(getHtml(table),
|
|
2483
|
-
`<table-540><table><tbody>`+
|
|
2484
|
-
`<tr is="tr-540" user=""><td>John</td><td>john@example.com</td></tr>` +
|
|
2485
|
-
`<tr is="tr-540" user=""><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
2486
|
-
`</tbody></table></table-540>`)
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
table.users[1].name = 'Barry'
|
|
2490
|
-
table.render();
|
|
2491
|
-
assert.eq(getHtml(table),
|
|
2492
|
-
`<table-540><table><tbody>` +
|
|
2493
|
-
`<tr is="tr-540" user=""><td>John</td><td>john@example.com</td></tr>` +
|
|
2494
|
-
`<tr is="tr-540" user=""><td>Barry</td><td>fred@example.com</td></tr>` +
|
|
2495
|
-
`</tbody></table></table-540>`)
|
|
2496
|
-
|
|
2497
|
-
table.remove();
|
|
2498
|
-
});
|
|
2499
|
-
//</editor-fold>
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
//<editor-fold desc="slots">
|
|
2505
|
-
/* ┌─────────────────╮
|
|
2506
|
-
* | Slots |
|
|
2507
|
-
* └─────────────────╯*/
|
|
2508
|
-
Testimony.test('Solarite.slots.basic', () => {
|
|
2509
|
-
|
|
2510
|
-
class S10 extends Solarite {
|
|
2511
|
-
render() {
|
|
2512
|
-
r(this)`<div>slot content:<slot></slot></div>`
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
S10.define();
|
|
2516
|
-
|
|
2517
|
-
let div = r('<div><s-10>test</s-10></div>')
|
|
2518
|
-
document.body.append(div);
|
|
2519
|
-
|
|
2520
|
-
assert.eq(div.outerHTML, `<div><s-10><div>slot content:<slot>test</slot></div></s-10></div>`)
|
|
2521
|
-
|
|
2522
|
-
div.remove();
|
|
2523
|
-
});
|
|
2524
|
-
|
|
2525
|
-
Testimony.test('Solarite.slots.named', () => {
|
|
2526
|
-
|
|
2527
|
-
class S20 extends Solarite {
|
|
2528
|
-
render() {
|
|
2529
|
-
this.html = r`<div>slot content:<slot name="one"></slot><slot></slot><slot name="two"></slot></div>`
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
S20.define();
|
|
2533
|
-
|
|
2534
|
-
let div = r('<div><s-20>zero<div slot="one">One</div><div slot="one">One Again</div><div slot="two">Two</div>Three</s-20></div>')
|
|
2535
|
-
document.body.append(div);
|
|
2536
|
-
|
|
2537
|
-
assert.eq(div.outerHTML, `<div><s-20><div>slot content:<slot name="one"><div slot="one">One</div><div slot="one">One Again</div></slot><slot>zeroThree</slot><slot name="two"><div slot="two">Two</div></slot></div></s-20></div>`)
|
|
2538
|
-
|
|
2539
|
-
div.remove();
|
|
2540
|
-
});
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
Testimony.test('Solarite.slots.slotless', `Add children even when no slots present.`, () => {
|
|
2544
|
-
|
|
2545
|
-
class S30 extends Solarite {
|
|
2546
|
-
render() {
|
|
2547
|
-
r(this)`<div>child1</div>`
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
S30.define();
|
|
2551
|
-
|
|
2552
|
-
let div = r('<div><s-30>child2<br>child4</s-30></div>')
|
|
2553
|
-
document.body.append(div);
|
|
2554
|
-
|
|
2555
|
-
assert.eq(div.outerHTML, `<div><s-30><div>child1</div>child2<br>child4</s-30></div>`)
|
|
2556
|
-
|
|
2557
|
-
div.remove();
|
|
2558
|
-
});
|
|
2559
|
-
//</editor-fold>
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
//<editor-fold desc="events">
|
|
2565
|
-
/* ┌─────────────────╮
|
|
2566
|
-
* | Events |
|
|
2567
|
-
* └─────────────────╯*/
|
|
2568
|
-
Testimony.test('Solarite.events.classic', () => {
|
|
2569
|
-
|
|
2570
|
-
class Ev10 extends Solarite {
|
|
2571
|
-
count = 1
|
|
2572
|
-
|
|
2573
|
-
render() {
|
|
2574
|
-
this.html = r`<input data-id="input" value=${this.count} oninput="this.count=el.count">`
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
|
|
2578
|
-
let a = new Ev10();
|
|
2579
|
-
document.body.append(a);
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
a.remove();
|
|
2583
|
-
});
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
Testimony.test('Solarite.events.rebind', 'Ensure function is unbound/rebound on render', () => {
|
|
2587
|
-
|
|
2588
|
-
let assignCalls = 0;
|
|
2589
|
-
|
|
2590
|
-
class Ev20 extends Solarite {
|
|
2591
|
-
count = 1
|
|
2592
|
-
|
|
2593
|
-
assign(val) {
|
|
2594
|
-
this.count = val;
|
|
2595
|
-
assignCalls++;
|
|
2596
|
-
}
|
|
2597
|
-
|
|
2598
|
-
render() {
|
|
2599
|
-
this.html = r`<input data-id="input" value=${this.count} oninput="${(e, el) => this.assign(el.value)}">`
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
Ev20.define();
|
|
2603
|
-
|
|
2604
|
-
let a = new Ev20();
|
|
2605
|
-
a.render();
|
|
2606
|
-
assert.eq(assignCalls, 0);
|
|
2607
|
-
a.firstChild.dispatchEvent(new Event('input'));
|
|
2608
|
-
assert.eq(assignCalls, 1);
|
|
2609
|
-
|
|
2610
|
-
a.render();
|
|
2611
|
-
a.firstChild.dispatchEvent(new Event('input'));
|
|
2612
|
-
assert.eq(assignCalls, 2);
|
|
2613
|
-
});
|
|
2614
|
-
|
|
2615
|
-
Testimony.test('Solarite.events.args', 'Ensure event function args are received', () => {
|
|
2616
|
-
|
|
2617
|
-
class Ev30 extends Solarite {
|
|
2618
|
-
count = 0
|
|
2619
|
-
|
|
2620
|
-
assign(val) {
|
|
2621
|
-
this.count = val;
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
render() {
|
|
2625
|
-
this.html = r`<input data-id="input" value='1' oninput="${(e, el) => this.assign(el.value)}">`
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
Ev30.define();
|
|
2629
|
-
|
|
2630
|
-
let a = new Ev30();
|
|
2631
|
-
a.render();
|
|
2632
|
-
a.firstChild.dispatchEvent(new Event('input'));
|
|
2633
|
-
assert.eq(a.count, '1');
|
|
2634
|
-
|
|
2635
|
-
a.firstChild.value = '2';
|
|
2636
|
-
a.firstChild.dispatchEvent(new Event('input'));
|
|
2637
|
-
assert.eq(a.count, '2');
|
|
2638
|
-
});
|
|
2639
|
-
|
|
2640
|
-
Testimony.test('Solarite.events.onComponent', 'Event attrib on root component', () => {
|
|
2641
|
-
|
|
2642
|
-
class Ev40 extends Solarite {
|
|
2643
|
-
count = 0
|
|
2644
|
-
|
|
2645
|
-
assign(val) {
|
|
2646
|
-
this.count = val;
|
|
2647
|
-
}
|
|
2648
|
-
|
|
2649
|
-
render() {
|
|
2650
|
-
this.html = r`<ev-40 oninput="${(e, el) => this.assign(el.firstChild.value)}"><input data-id="input" value='1'></ev-40>`
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
Ev40.define();
|
|
2654
|
-
|
|
2655
|
-
let a = new Ev40();
|
|
2656
|
-
a.render();
|
|
2657
|
-
a.firstChild.dispatchEvent(new Event('input', {bubbles: true}));
|
|
2658
|
-
assert.eq(a.count, '1');
|
|
2659
|
-
|
|
2660
|
-
a.firstChild.value = '2';
|
|
2661
|
-
a.firstChild.dispatchEvent(new Event('input', {bubbles: true}));
|
|
2662
|
-
assert.eq(a.count, '2');
|
|
2663
|
-
});
|
|
2664
|
-
|
|
2665
|
-
Testimony.test('Solarite.events.onChild', () => {
|
|
2666
|
-
|
|
2667
|
-
class E50 extends HTMLElement {
|
|
2668
|
-
constructor() {
|
|
2669
|
-
super();
|
|
2670
|
-
this.items = [];
|
|
2671
|
-
this.render();
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
addItem() {
|
|
2675
|
-
this.items.push(1);
|
|
2676
|
-
this.render();
|
|
2677
|
-
}
|
|
2678
|
-
|
|
2679
|
-
render() {
|
|
2680
|
-
r(this)`
|
|
2681
|
-
<e-50>
|
|
2682
|
-
<button onclick=${this.addItem}>Add Item</button>
|
|
2683
|
-
</e-50>`
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
customElements.define('e-50', E50);
|
|
2687
|
-
|
|
2688
|
-
let e = new E50();
|
|
2689
|
-
e.querySelector('button').dispatchEvent(new MouseEvent('click'));
|
|
2690
|
-
assert.eq(e.items.length, 1);
|
|
2691
|
-
});
|
|
2692
|
-
|
|
2693
|
-
Testimony.test('Solarite.events.onExprChild', () => {
|
|
2694
|
-
|
|
2695
|
-
class E60 extends HTMLElement {
|
|
2696
|
-
constructor() {
|
|
2697
|
-
super();
|
|
2698
|
-
this.items = [];
|
|
2699
|
-
this.render();
|
|
2700
|
-
}
|
|
2701
|
-
|
|
2702
|
-
addItem() {
|
|
2703
|
-
this.items.push(1);
|
|
2704
|
-
this.render();
|
|
2705
|
-
}
|
|
2706
|
-
|
|
2707
|
-
render() {
|
|
2708
|
-
r(this)`
|
|
2709
|
-
<e-60>
|
|
2710
|
-
${r`<button onclick=${this.addItem}>Add Item</button>`}
|
|
2711
|
-
</e-60>`
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
customElements.define('e-60', E60);
|
|
2715
|
-
|
|
2716
|
-
let e = new E60();
|
|
2717
|
-
e.querySelector('button').dispatchEvent(new MouseEvent('click'));
|
|
2718
|
-
assert.eq(e.items.length, 1);
|
|
2719
|
-
});
|
|
2720
|
-
|
|
2721
|
-
Testimony.test('Solarite.events.loop', () => {
|
|
2722
|
-
|
|
2723
|
-
let lastButtonId = null;
|
|
2724
|
-
|
|
2725
|
-
class V70 extends Solarite {
|
|
2726
|
-
items = [{id: 1}, {id: 2}];
|
|
2727
|
-
|
|
2728
|
-
log(id) {
|
|
2729
|
-
lastButtonId = id;
|
|
2730
|
-
//console.log(id);
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
render() {
|
|
2734
|
-
r(this)`
|
|
2735
|
-
<v-70>
|
|
2736
|
-
${this.items.map(item => r`
|
|
2737
|
-
<button onclick=${[this.log, item.id]}>${item.id}</button>
|
|
2738
|
-
`)}
|
|
2739
|
-
</v-70>`
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
|
|
2743
|
-
let v = new V70();
|
|
2744
|
-
document.body.append(v);
|
|
2745
|
-
|
|
2746
|
-
v.children[1].dispatchEvent(new MouseEvent('click'));
|
|
2747
|
-
assert.eq(lastButtonId, 2);
|
|
2748
|
-
|
|
2749
|
-
// This doesn't update the bound function to use 3.
|
|
2750
|
-
v.items.splice(1, 1); // remove 2.
|
|
2751
|
-
v.items.push({id: 3});
|
|
2752
|
-
window.debug = true;
|
|
2753
|
-
v.render();
|
|
2754
|
-
v.children[1].dispatchEvent(new MouseEvent('click'));
|
|
2755
|
-
assert.eq(lastButtonId, 3);
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
//v.remove();
|
|
2759
|
-
});
|
|
2760
|
-
//</editor-fold>
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
//<editor-fold desc="binding">
|
|
2766
|
-
/* ┌─────────────────╮
|
|
2767
|
-
* | Binding |
|
|
2768
|
-
* └─────────────────╯*/
|
|
2769
|
-
Testimony.test('Solarite.binding.input', () => {
|
|
2770
|
-
|
|
2771
|
-
class B10 extends Solarite {
|
|
2772
|
-
count = 1
|
|
2773
|
-
|
|
2774
|
-
render() {
|
|
2775
|
-
this.html = r`<input data-id="input" value=${this.count} oninput=${[this, 'count']}>`
|
|
2776
|
-
|
|
2777
|
-
// Alternate syntax:
|
|
2778
|
-
// this.html = r`<input data-bind=${this.$.value}>`
|
|
2779
|
-
// this.html = r`<input value=${this.value} oninput=${el => this.value = el.value}>`
|
|
2780
|
-
// this.html = r`<input data-bind=${[this, 'value']}>`
|
|
2781
|
-
//you havethis.html = r`<input data-id="input" value=${this.count} oninput=${this.count}>` // requires this.render = this.render.bind(Proxy(this). Won't hash properly.
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
let b = new B10();
|
|
2786
|
-
document.body.append(b);
|
|
2787
|
-
assert.eq(b.input.value, '1')
|
|
2788
|
-
|
|
2789
|
-
b.count = 2
|
|
2790
|
-
b.render()
|
|
2791
|
-
assert.eq(b.input.value, '2')
|
|
2792
|
-
|
|
2793
|
-
b.input.value = 3;
|
|
2794
|
-
b.input.dispatchEvent(new Event('input', {
|
|
2795
|
-
bubbles: true,
|
|
2796
|
-
cancelable: true,
|
|
2797
|
-
}));
|
|
2798
|
-
assert.eq(b.count, '3')
|
|
2799
|
-
|
|
2800
|
-
b.remove();
|
|
2801
|
-
});
|
|
2802
|
-
|
|
2803
|
-
Testimony.test('Solarite.binding.inputReuse', () => {
|
|
2804
|
-
|
|
2805
|
-
class B12 extends Solarite {
|
|
2806
|
-
items = [1, 2, 3]
|
|
2807
|
-
|
|
2808
|
-
render() {
|
|
2809
|
-
this.html = r`${this.items.map(item => r`<input data-id="input" value=${item}>`)}`;
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
let b = new B12();
|
|
2814
|
-
document.body.append(b);
|
|
2815
|
-
|
|
2816
|
-
// Remove and re-add the input with a new value.
|
|
2817
|
-
b.items = [];
|
|
2818
|
-
b.render();
|
|
2819
|
-
|
|
2820
|
-
b.items = [4];
|
|
2821
|
-
b.render();
|
|
2822
|
-
|
|
2823
|
-
// Make sure it takes the new value.
|
|
2824
|
-
assert.eq(b.firstElementChild.value, '4');
|
|
2825
|
-
|
|
2826
|
-
b.remove();
|
|
2827
|
-
});
|
|
2828
|
-
|
|
2829
|
-
Testimony.test('Solarite.binding.textarea', () => {
|
|
2830
|
-
|
|
2831
|
-
class B20 extends Solarite {
|
|
2832
|
-
text = 1
|
|
2833
|
-
|
|
2834
|
-
render() {
|
|
2835
|
-
this.html = r`<textarea data-id="input" value=${this.text} oninput=${[this, 'text']}></textarea>`
|
|
2836
|
-
}
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
let b = new B20();
|
|
2840
|
-
document.body.append(b);
|
|
2841
|
-
assert.eq(b.input.value, '1')
|
|
2842
|
-
|
|
2843
|
-
b.text = 2
|
|
2844
|
-
b.render()
|
|
2845
|
-
assert.eq(b.input.value, '2')
|
|
2846
|
-
|
|
2847
|
-
b.input.value = 3;
|
|
2848
|
-
b.input.dispatchEvent(new Event('input', {
|
|
2849
|
-
bubbles: true,
|
|
2850
|
-
cancelable: true,
|
|
2851
|
-
}));
|
|
2852
|
-
assert.eq(b.text, '3')
|
|
2853
|
-
|
|
2854
|
-
b.remove();
|
|
2855
|
-
});
|
|
2856
|
-
|
|
2857
|
-
// TODO: Set select.value when option children are rendered and don't exist when the value attrib is evaluated by ExprPath.applyValueAttrib()
|
|
2858
|
-
Testimony.test('Solarite.binding.select', () => {
|
|
2859
|
-
|
|
2860
|
-
class B30 extends Solarite {
|
|
2861
|
-
count = 1
|
|
2862
|
-
|
|
2863
|
-
render() {
|
|
2864
|
-
this.html = r`<select data-id="input" value=${this.count} onchange=${[this, 'count']}><option>1</option><option>2</option><option>3</option></select>`
|
|
2865
|
-
}
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
let b = new B30();
|
|
2869
|
-
document.body.append(b);
|
|
2870
|
-
assert.eq(b.input.value, '1')
|
|
2871
|
-
|
|
2872
|
-
b.count = 2
|
|
2873
|
-
b.render()
|
|
2874
|
-
assert.eq(b.input.value, '2');
|
|
2875
|
-
|
|
2876
|
-
b.input.value = 3;
|
|
2877
|
-
b.input.dispatchEvent(new Event('change', {
|
|
2878
|
-
bubbles: true,
|
|
2879
|
-
cancelable: true,
|
|
2880
|
-
}));
|
|
2881
|
-
assert.eq(b.count, '3')
|
|
2882
|
-
|
|
2883
|
-
b.remove();
|
|
2884
|
-
});
|
|
2885
|
-
|
|
2886
|
-
Testimony.test('Solarite.binding.selectDynamic', () => {
|
|
2887
|
-
|
|
2888
|
-
class B32 extends Solarite {
|
|
2889
|
-
count = 1
|
|
2890
|
-
|
|
2891
|
-
render() {
|
|
2892
|
-
this.html = r`<select data-id="input" value=${this.count} onchange=${[this, 'count']}>${[1, 2, 3].map(item => r`<option>${item}</option>`)}</select>`
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2895
|
-
|
|
2896
|
-
let b = new B32();
|
|
2897
|
-
document.body.append(b);
|
|
2898
|
-
assert.eq(b.input.value, '1')
|
|
2899
|
-
assert.eq(b.input.selectedIndex, 0);
|
|
2900
|
-
|
|
2901
|
-
b.count = 2
|
|
2902
|
-
b.render()
|
|
2903
|
-
assert.eq(b.input.value, '2');
|
|
2904
|
-
assert.eq(b.input.selectedIndex, 1);
|
|
2905
|
-
|
|
2906
|
-
b.input.value = 3;
|
|
2907
|
-
b.input.dispatchEvent(new Event('change', {
|
|
2908
|
-
bubbles: true,
|
|
2909
|
-
cancelable: true,
|
|
2910
|
-
}));
|
|
2911
|
-
assert.eq(b.count, '3')
|
|
2912
|
-
assert.eq(b.input.selectedIndex, 2);
|
|
2913
|
-
|
|
2914
|
-
b.remove();
|
|
2915
|
-
});
|
|
2916
|
-
|
|
2917
|
-
Testimony.test('Solarite.binding.number', () => {
|
|
2918
|
-
|
|
2919
|
-
class B40 extends Solarite {
|
|
2920
|
-
count = 1
|
|
2921
|
-
|
|
2922
|
-
render() {
|
|
2923
|
-
this.html = r`<input type="number" data-id="input" value=${this.count} oninput=${[this, 'count']}>`
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
|
-
|
|
2927
|
-
let b = new B40();
|
|
2928
|
-
document.body.append(b);
|
|
2929
|
-
assert.eq(b.input.value, '1')
|
|
2930
|
-
|
|
2931
|
-
b.count = 2
|
|
2932
|
-
b.render()
|
|
2933
|
-
assert.eq(b.input.value, '2')
|
|
2934
|
-
|
|
2935
|
-
b.input.value = 3;
|
|
2936
|
-
b.input.dispatchEvent(new Event('input', {
|
|
2937
|
-
bubbles: true,
|
|
2938
|
-
cancelable: true,
|
|
2939
|
-
}));
|
|
2940
|
-
assert.eq(b.count, 3)
|
|
2941
|
-
|
|
2942
|
-
b.remove();
|
|
2943
|
-
});
|
|
2944
|
-
|
|
2945
|
-
// FIXME
|
|
2946
|
-
Testimony.test('Solarite.binding.number2', () => {
|
|
2947
|
-
|
|
2948
|
-
class B50 extends Solarite {
|
|
2949
|
-
count = 1
|
|
2950
|
-
|
|
2951
|
-
render() {
|
|
2952
|
-
r(this)`<input type="number" data-id="input" value=${[this, 'count']}>`
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
|
|
2956
|
-
let b = new B50();
|
|
2957
|
-
document.body.append(b);
|
|
2958
|
-
assert.eq(b.input.value, '1')
|
|
2959
|
-
|
|
2960
|
-
b.count = 2;
|
|
2961
|
-
b.render();
|
|
2962
|
-
assert.eq(b.input.value, '2')
|
|
2963
|
-
|
|
2964
|
-
b.input.value = 3;
|
|
2965
|
-
b.input.dispatchEvent(new Event('input', {
|
|
2966
|
-
bubbles: true,
|
|
2967
|
-
cancelable: true,
|
|
2968
|
-
}));
|
|
2969
|
-
assert.eq(b.count, 3)
|
|
2970
|
-
|
|
2971
|
-
b.remove();
|
|
2972
|
-
});
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
//</editor-fold>
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
//<editor-fold desc="watch">
|
|
2981
|
-
/* ┌─────────────────╮
|
|
2982
|
-
* | Watch |
|
|
2983
|
-
* └─────────────────╯*/
|
|
2984
|
-
/*
|
|
2985
|
-
Testimony.test('Solarite.watched.watchSet', () => {
|
|
2986
|
-
|
|
2987
|
-
class W10 extends Solarite {
|
|
2988
|
-
user = {
|
|
2989
|
-
name: 'John',
|
|
2990
|
-
email: 'john@example.com'
|
|
2991
|
-
}
|
|
2992
|
-
render() {
|
|
2993
|
-
this.html = r`
|
|
2994
|
-
<w-10>
|
|
2995
|
-
<div>${watchGet([this, 'user'], user => user.name + ' (user)')}</div>
|
|
2996
|
-
<div>${watchGet([this, 'user', 'email'])}</div>
|
|
2997
|
-
</w-10>`
|
|
2998
|
-
}
|
|
2999
|
-
}
|
|
3000
|
-
|
|
3001
|
-
let a = new W10();
|
|
3002
|
-
document.body.append(a);
|
|
3003
|
-
|
|
3004
|
-
// swap property on user.
|
|
3005
|
-
watchSet(a).user.name = 'Fred';
|
|
3006
|
-
a.renderWatched();
|
|
3007
|
-
//console.log(getHtml(a))
|
|
3008
|
-
assert.eq(getHtml(a), `<w-10><div>Fred (user)</div><div>john@example.com</div></w-10>`)
|
|
3009
|
-
|
|
3010
|
-
// Swap whole user.
|
|
3011
|
-
watchSet(a).user = {name: 'Fred', email: 'fred@example.com'};
|
|
3012
|
-
a.renderWatched();
|
|
3013
|
-
//console.log(getHtml(a))
|
|
3014
|
-
assert.eq(getHtml(a), `<w-10><div>Fred (user)</div><div>fred@example.com</div></w-10>`)
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
a.remove();
|
|
3018
|
-
});
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
Testimony.test('Solarite.watched.forEach', () => {
|
|
3026
|
-
|
|
3027
|
-
class Table650 extends Solarite {
|
|
3028
|
-
users = [
|
|
3029
|
-
{name: 'John', email: 'john@example.com'},
|
|
3030
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
3031
|
-
]
|
|
3032
|
-
render() {
|
|
3033
|
-
this.html = r`
|
|
3034
|
-
<table style="table-layout: fixed; width: 150px">
|
|
3035
|
-
<tbody>${
|
|
3036
|
-
forEach([this, 'users'], user =>
|
|
3037
|
-
r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`
|
|
3038
|
-
)}
|
|
3039
|
-
</tbody>
|
|
3040
|
-
</table>`
|
|
3041
|
-
}
|
|
3042
|
-
}
|
|
3043
|
-
let table = new Table650
|
|
3044
|
-
document.body.append(table)
|
|
3045
|
-
|
|
3046
|
-
assert.eq(getHtml(table),
|
|
3047
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3048
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3049
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3050
|
-
`</tbody></table></table-650>`)
|
|
3051
|
-
|
|
3052
|
-
// Watch one row, set property
|
|
3053
|
-
watchSet(table).users[1].name = 'Barry'
|
|
3054
|
-
|
|
3055
|
-
table.renderWatched();
|
|
3056
|
-
assert.eq(getHtml(table),
|
|
3057
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3058
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3059
|
-
`<tr><td>Barry</td><td>fred@example.com</td></tr>` +
|
|
3060
|
-
`</tbody></table></table-650>`)
|
|
3061
|
-
|
|
3062
|
-
// Watch one row, set property twice
|
|
3063
|
-
watchSet(table).users[1].name = 'Bob'
|
|
3064
|
-
watchSet(table).users[1].name = 'Rob'
|
|
3065
|
-
table.renderWatched();
|
|
3066
|
-
assert.eq(getHtml(table),
|
|
3067
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3068
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3069
|
-
`<tr><td>Rob</td><td>fred@example.com</td></tr>` +
|
|
3070
|
-
`</tbody></table></table-650>`)
|
|
3071
|
-
|
|
3072
|
-
// Watch all rows, set property of one.
|
|
3073
|
-
watchSet(table).users[1].name = 'George'
|
|
3074
|
-
table.renderWatched();
|
|
3075
|
-
assert.eq(getHtml(table),
|
|
3076
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3077
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3078
|
-
`<tr><td>George</td><td>fred@example.com</td></tr>` +
|
|
3079
|
-
`</tbody></table></table-650>`)
|
|
3080
|
-
|
|
3081
|
-
// Watch whole object, set property of one.
|
|
3082
|
-
watchSet(table).users[1].name = 'Jim'
|
|
3083
|
-
table.renderWatched();
|
|
3084
|
-
assert.eq(getHtml(table),
|
|
3085
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3086
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3087
|
-
`<tr><td>Jim</td><td>fred@example.com</td></tr>` +
|
|
3088
|
-
`</tbody></table></table-650>`)
|
|
3089
|
-
|
|
3090
|
-
// Update entire row object
|
|
3091
|
-
watchSet(table).users[1] = {name: 'Ned', email: 'ned@example.com'}
|
|
3092
|
-
table.renderWatched();
|
|
3093
|
-
assert.eq(getHtml(table),
|
|
3094
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3095
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3096
|
-
`<tr><td>Ned</td><td>ned@example.com</td></tr>` +
|
|
3097
|
-
`</tbody></table></table-650>`)
|
|
3098
|
-
|
|
3099
|
-
table.remove();
|
|
3100
|
-
|
|
3101
|
-
});
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
Testimony.test('Solarite.watched.forEachSpliceDelete', () => {
|
|
3105
|
-
|
|
3106
|
-
class W50 extends Solarite {
|
|
3107
|
-
users = [
|
|
3108
|
-
{name: 'John', email: 'john@example.com'},
|
|
3109
|
-
{name: 'Fred', email: 'fred@example.com'},
|
|
3110
|
-
{name: 'George', email: 'george@example.com'},
|
|
3111
|
-
{name: 'Bill', email: 'bill@example.com'}
|
|
3112
|
-
]
|
|
3113
|
-
render() {
|
|
3114
|
-
this.html = r`<table style="table-layout: fixed; width: 150px"><tbody>${forEach([this, 'users'], user => r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`)}</tbody></table>`
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
let table = new W50
|
|
3118
|
-
document.body.append(table)
|
|
3119
|
-
|
|
3120
|
-
assert.eq(getHtml(table),
|
|
3121
|
-
`<w-50><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3122
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3123
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3124
|
-
`<tr><td>George</td><td>george@example.com</td></tr>` +
|
|
3125
|
-
`<tr><td>Bill</td><td>bill@example.com</td></tr>` +
|
|
3126
|
-
`</tbody></table></w-50>`)
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
// Splice
|
|
3130
|
-
watchSet(table).users.splice(1, 2)
|
|
3131
|
-
table.renderWatched();
|
|
3132
|
-
assert.eq(getHtml(table),
|
|
3133
|
-
`<w-50><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3134
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3135
|
-
`<tr><td>Bill</td><td>bill@example.com</td></tr>` +
|
|
3136
|
-
`</tbody></table></w-50>`)
|
|
3137
|
-
|
|
3138
|
-
table.remove();
|
|
3139
|
-
});
|
|
3140
|
-
|
|
3141
|
-
Testimony.test('Solarite.watched.forEachSpliceInsert', () => {
|
|
3142
|
-
|
|
3143
|
-
class W60 extends Solarite {
|
|
3144
|
-
users = [
|
|
3145
|
-
{name: 'John', email: 'john@example.com'},
|
|
3146
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
3147
|
-
]
|
|
3148
|
-
render() {
|
|
3149
|
-
this.html = r`
|
|
3150
|
-
<table style="table-layout: fixed; width: 150px">
|
|
3151
|
-
<tbody>${forEach([this, 'users'], user =>
|
|
3152
|
-
r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`
|
|
3153
|
-
)}
|
|
3154
|
-
</tbody>
|
|
3155
|
-
</table>`
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3158
|
-
let table = new W60
|
|
3159
|
-
document.body.append(table)
|
|
3160
|
-
|
|
3161
|
-
assert.eq(getHtml(table),
|
|
3162
|
-
`<w-60><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3163
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3164
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3165
|
-
`</tbody></table></w-60>`)
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
// Splice
|
|
3169
|
-
watchSet(table).users.splice(1, 0, {name: 'George', email: 'george@example.com'})
|
|
3170
|
-
table.renderWatched();
|
|
3171
|
-
assert.eq(getHtml(table),
|
|
3172
|
-
`<w-60><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3173
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3174
|
-
`<tr><td>George</td><td>george@example.com</td></tr>` +
|
|
3175
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3176
|
-
`</tbody></table></w-60>`)
|
|
3177
|
-
|
|
3178
|
-
table.remove();
|
|
3179
|
-
});
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
// Experiment with a new syntax for watching.
|
|
3186
|
-
Testimony.test('Solarite.watched._$', () => {
|
|
3187
|
-
|
|
3188
|
-
class Table670 extends Solarite {
|
|
3189
|
-
title = 'Title';
|
|
3190
|
-
users = [
|
|
3191
|
-
{name: 'John', email: 'john@example.com'},
|
|
3192
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
3193
|
-
]
|
|
3194
|
-
render() {
|
|
3195
|
-
this.html = // r() can check for instanceof Proxy and convert it to something?
|
|
3196
|
-
r`${this.$.title}
|
|
3197
|
-
<table style="table-layout: fixed; width: 150px">
|
|
3198
|
-
<tbody>${this.$.users.map(user =>
|
|
3199
|
-
r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`)}
|
|
3200
|
-
</tbody>
|
|
3201
|
-
</table>`
|
|
3202
|
-
}
|
|
3203
|
-
}
|
|
3204
|
-
let table = new Table670
|
|
3205
|
-
document.body.append(table)
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
table.$.title = 'test';
|
|
3209
|
-
table.$.users[1].name = 'Jim';
|
|
3210
|
-
|
|
3211
|
-
//table.remove();
|
|
3212
|
-
});
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
Testimony.test('Solarite.watch2.set', () => {
|
|
3219
|
-
|
|
3220
|
-
class W10 extends Solarite {
|
|
3221
|
-
user = {
|
|
3222
|
-
name: 'John',
|
|
3223
|
-
email: 'john@example.com'
|
|
3224
|
-
}
|
|
3225
|
-
render() {
|
|
3226
|
-
this.html = r`
|
|
3227
|
-
<w-10>
|
|
3228
|
-
<div>${() => watch(this).user.name + ' (user)'}</div>
|
|
3229
|
-
<div>${() => watch(this).user.email}</div>
|
|
3230
|
-
</w-10>`
|
|
3231
|
-
}
|
|
3232
|
-
}
|
|
3233
|
-
|
|
3234
|
-
let a = new W10();
|
|
3235
|
-
document.body.append(a);
|
|
3236
|
-
|
|
3237
|
-
// swap property on user.
|
|
3238
|
-
watch(a).user.name = 'Fred';
|
|
3239
|
-
//console.log(getHtml(a))
|
|
3240
|
-
assert.eq(getHtml(a), `<w-10><div>Fred (user)</div><div>john@example.com</div></w-10>`)
|
|
3241
|
-
|
|
3242
|
-
// Swap whole user.
|
|
3243
|
-
watch(a).user = {name: 'Fred', email: 'fred@example.com'};
|
|
3244
|
-
//console.log(getHtml(a))
|
|
3245
|
-
assert.eq(getHtml(a), `<w-10><div>Fred (user)</div><div>fred@example.com</div></w-10>`)
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
a.remove();
|
|
3249
|
-
});
|
|
3250
|
-
|
|
3251
|
-
*/
|
|
3252
|
-
|
|
3253
|
-
Testimony.test('Solarite.watch2._forEach', () => {
|
|
3254
|
-
|
|
3255
|
-
class Table650 extends Solarite {
|
|
3256
|
-
users = [
|
|
3257
|
-
{name: 'John', email: 'john@example.com'},
|
|
3258
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
3259
|
-
]
|
|
3260
|
-
render() {
|
|
3261
|
-
this.html = r`
|
|
3262
|
-
<table style="table-layout: fixed; width: 150px">
|
|
3263
|
-
<tbody>${
|
|
3264
|
-
watch(this).users.map(user =>
|
|
3265
|
-
r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`
|
|
3266
|
-
)}
|
|
3267
|
-
</tbody>
|
|
3268
|
-
</table>`
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
let table = new Table650
|
|
3272
|
-
document.body.append(table)
|
|
3273
|
-
|
|
3274
|
-
assert.eq(getHtml(table),
|
|
3275
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3276
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3277
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3278
|
-
`</tbody></table></table-650>`)
|
|
3279
|
-
|
|
3280
|
-
// Watch one row, set property
|
|
3281
|
-
watch(table).users[1].name = 'Barry'
|
|
3282
|
-
|
|
3283
|
-
assert.eq(getHtml(table),
|
|
3284
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3285
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3286
|
-
`<tr><td>Barry</td><td>fred@example.com</td></tr>` +
|
|
3287
|
-
`</tbody></table></table-650>`)
|
|
3288
|
-
|
|
3289
|
-
// Watch one row, set property twice
|
|
3290
|
-
watch(table).users[1].name = 'Bob'
|
|
3291
|
-
watch(table).users[1].name = 'Rob'
|
|
3292
|
-
assert.eq(getHtml(table),
|
|
3293
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3294
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3295
|
-
`<tr><td>Rob</td><td>fred@example.com</td></tr>` +
|
|
3296
|
-
`</tbody></table></table-650>`)
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
// Watch whole object, set property of one.
|
|
3300
|
-
watch(table).users[1].name = 'Jim'
|
|
3301
|
-
assert.eq(getHtml(table),
|
|
3302
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3303
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3304
|
-
`<tr><td>Jim</td><td>fred@example.com</td></tr>` +
|
|
3305
|
-
`</tbody></table></table-650>`)
|
|
3306
|
-
|
|
3307
|
-
// Update entire row object
|
|
3308
|
-
watch(table).users[1] = {name: 'Ned', email: 'ned@example.com'}
|
|
3309
|
-
assert.eq(getHtml(table),
|
|
3310
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3311
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3312
|
-
`<tr><td>Ned</td><td>ned@example.com</td></tr>` +
|
|
3313
|
-
`</tbody></table></table-650>`)
|
|
3314
|
-
|
|
3315
|
-
// Clear
|
|
3316
|
-
watch(table).users = [];
|
|
3317
|
-
assert.eq(getHtml(table),
|
|
3318
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3319
|
-
`</tbody></table></table-650>`)
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
// This gets the wrong value via NodeGroupManager b/c we never update exactKeys.
|
|
3323
|
-
watch(table).users = [
|
|
3324
|
-
{name: 'John', email: 'john@example.com'},
|
|
3325
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
3326
|
-
];
|
|
3327
|
-
assert.eq(getHtml(table),
|
|
3328
|
-
`<table-650><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3329
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3330
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3331
|
-
`</tbody></table></table-650>`)
|
|
3332
|
-
|
|
3333
|
-
table.remove();
|
|
3334
|
-
|
|
3335
|
-
});
|
|
3336
|
-
|
|
3337
|
-
Testimony.test('Solarite.watch2._forEachSpliceDelete', () => {
|
|
3338
|
-
|
|
3339
|
-
class W50 extends Solarite {
|
|
3340
|
-
users = [
|
|
3341
|
-
{name: 'John', email: 'john@example.com'},
|
|
3342
|
-
{name: 'Fred', email: 'fred@example.com'},
|
|
3343
|
-
{name: 'George', email: 'george@example.com'},
|
|
3344
|
-
{name: 'Bill', email: 'bill@example.com'}
|
|
3345
|
-
]
|
|
3346
|
-
render() {
|
|
3347
|
-
this.html = r`<table style="table-layout: fixed; width: 150px"><tbody>${watch(this).users.map(user => r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`)}</tbody></table>`
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
let table = new W50
|
|
3351
|
-
document.body.append(table)
|
|
3352
|
-
|
|
3353
|
-
assert.eq(getHtml(table),
|
|
3354
|
-
`<w-50><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3355
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3356
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3357
|
-
`<tr><td>George</td><td>george@example.com</td></tr>` +
|
|
3358
|
-
`<tr><td>Bill</td><td>bill@example.com</td></tr>` +
|
|
3359
|
-
`</tbody></table></w-50>`)
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
// Splice middle.
|
|
3363
|
-
watch(table).users.splice(1, 2)
|
|
3364
|
-
assert.eq(getHtml(table),
|
|
3365
|
-
`<w-50><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3366
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3367
|
-
`<tr><td>Bill</td><td>bill@example.com</td></tr>` +
|
|
3368
|
-
`</tbody></table></w-50>`)
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
// Splice to remove all.
|
|
3372
|
-
watch(table).users.splice(0, 2);
|
|
3373
|
-
assert.eq(getHtml(table),
|
|
3374
|
-
`<w-50><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3375
|
-
`</tbody></table></w-50>`)
|
|
3376
|
-
|
|
3377
|
-
table.remove();
|
|
3378
|
-
});
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
Testimony.test('Solarite.watch2._forEachSpliceDeleteStart', () => {
|
|
3382
|
-
|
|
3383
|
-
class W55 extends Solarite {
|
|
3384
|
-
users = [
|
|
3385
|
-
{name: 'John', email: 'john@example.com'},
|
|
3386
|
-
{name: 'Fred', email: 'fred@example.com'},
|
|
3387
|
-
{name: 'George', email: 'george@example.com'},
|
|
3388
|
-
{name: 'Bill', email: 'bill@example.com'}
|
|
3389
|
-
]
|
|
3390
|
-
render() {
|
|
3391
|
-
this.html = r`${watch(this).users.map(user => r`<div>${user.name}|${user.email}</div>`)}`
|
|
3392
|
-
}
|
|
3393
|
-
}
|
|
3394
|
-
let table = new W55
|
|
3395
|
-
document.body.append(table)
|
|
3396
|
-
|
|
3397
|
-
assert.eq(getHtml(table),
|
|
3398
|
-
`<w-55>`+
|
|
3399
|
-
`<div>John|john@example.com</div>` +
|
|
3400
|
-
`<div>Fred|fred@example.com</div>` +
|
|
3401
|
-
`<div>George|george@example.com</div>` +
|
|
3402
|
-
`<div>Bill|bill@example.com</div>` +
|
|
3403
|
-
`</w-55>`)
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
// Splice start.
|
|
3407
|
-
watch(table).users.splice(0, 1)
|
|
3408
|
-
assert.eq(getHtml(table),
|
|
3409
|
-
`<w-55>`+
|
|
3410
|
-
`<div>Fred|fred@example.com</div>` +
|
|
3411
|
-
`<div>George|george@example.com</div>` +
|
|
3412
|
-
`<div>Bill|bill@example.com</div>` +
|
|
3413
|
-
`</w-55>`)
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
// Splice start.
|
|
3417
|
-
watch(table).users.splice(0, 1)
|
|
3418
|
-
assert.eq(getHtml(table),
|
|
3419
|
-
`<w-55>`+
|
|
3420
|
-
`<div>George|george@example.com</div>` +
|
|
3421
|
-
`<div>Bill|bill@example.com</div>` +
|
|
3422
|
-
`</w-55>`)
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
watch(table).users.splice(0, 1)
|
|
3426
|
-
assert.eq(getHtml(table),
|
|
3427
|
-
`<w-55>`+
|
|
3428
|
-
`<div>Bill|bill@example.com</div>` +
|
|
3429
|
-
`</w-55>`)
|
|
3430
|
-
|
|
3431
|
-
table.remove();
|
|
3432
|
-
});
|
|
3433
|
-
|
|
3434
|
-
Testimony.test('Solarite.watch2._forEachSpliceDeleteEvent', () => {
|
|
3435
|
-
|
|
3436
|
-
class W57 extends Solarite {
|
|
3437
|
-
users = [
|
|
3438
|
-
{name: 'John', email: 'john@example.com'},
|
|
3439
|
-
{name: 'Fred', email: 'fred@example.com'},
|
|
3440
|
-
{name: 'George', email: 'george@example.com'},
|
|
3441
|
-
{name: 'Bill', email: 'bill@example.com'}
|
|
3442
|
-
]
|
|
3443
|
-
|
|
3444
|
-
delete(user) {
|
|
3445
|
-
let idx = this.users.indexOf(user);
|
|
3446
|
-
assert(idx > 0)
|
|
3447
|
-
this.users.splice(idx, 1);
|
|
3448
|
-
}
|
|
3449
|
-
|
|
3450
|
-
render() {
|
|
3451
|
-
this.html = r`${watch(this).users.map(user => r`<div onclick="${()=>this.delete(user)}">${user.name}|${user.email}</div>`)}`
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
let table = new W57
|
|
3455
|
-
document.body.append(table)
|
|
3456
|
-
|
|
3457
|
-
assert.eq(getHtml(table),
|
|
3458
|
-
`<w-57>`+
|
|
3459
|
-
`<div onclick="">John|john@example.com</div>` +
|
|
3460
|
-
`<div onclick="">Fred|fred@example.com</div>` +
|
|
3461
|
-
`<div onclick="">George|george@example.com</div>` +
|
|
3462
|
-
`<div onclick="">Bill|bill@example.com</div>` +
|
|
3463
|
-
`</w-57>`);
|
|
3464
|
-
|
|
3465
|
-
table.remove();
|
|
3466
|
-
});
|
|
3467
|
-
|
|
3468
|
-
Testimony.test('Solarite.watch2._forEachSpliceInsert', () => {
|
|
3469
|
-
|
|
3470
|
-
class W60 extends Solarite {
|
|
3471
|
-
users = [
|
|
3472
|
-
{name: 'John', email: 'john@example.com'},
|
|
3473
|
-
{name: 'Fred', email: 'fred@example.com'}
|
|
3474
|
-
]
|
|
3475
|
-
render() {
|
|
3476
|
-
this.html = r`
|
|
3477
|
-
<table style="table-layout: fixed; width: 150px">
|
|
3478
|
-
<tbody>${watch(this).users.map(user =>
|
|
3479
|
-
r`<tr><td>${user.name}</td><td>${user.email}</td></tr>`
|
|
3480
|
-
)}
|
|
3481
|
-
</tbody>
|
|
3482
|
-
</table>`
|
|
3483
|
-
}
|
|
3484
|
-
}
|
|
3485
|
-
let table = new W60
|
|
3486
|
-
document.body.append(table)
|
|
3487
|
-
|
|
3488
|
-
assert.eq(getHtml(table),
|
|
3489
|
-
`<w-60><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3490
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3491
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3492
|
-
`</tbody></table></w-60>`)
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
// Splice
|
|
3496
|
-
watch(table).users.splice(1, 0, {name: 'George', email: 'george@example.com'})
|
|
3497
|
-
assert.eq(getHtml(table),
|
|
3498
|
-
`<w-60><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3499
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3500
|
-
`<tr><td>George</td><td>george@example.com</td></tr>` +
|
|
3501
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3502
|
-
`</tbody></table></w-60>`)
|
|
3503
|
-
|
|
3504
|
-
// Splice to insert at end.
|
|
3505
|
-
watch(table).users.splice(3, 0, {name: 'Bill', email: 'bill@example.com'})
|
|
3506
|
-
assert.eq(getHtml(table),
|
|
3507
|
-
`<w-60><table style="table-layout: fixed; width: 150px"><tbody>`+
|
|
3508
|
-
`<tr><td>John</td><td>john@example.com</td></tr>` +
|
|
3509
|
-
`<tr><td>George</td><td>george@example.com</td></tr>` +
|
|
3510
|
-
`<tr><td>Fred</td><td>fred@example.com</td></tr>` +
|
|
3511
|
-
`<tr><td>Bill</td><td>bill@example.com</td></tr>` +
|
|
3512
|
-
`</tbody></table></w-60>`)
|
|
3513
|
-
|
|
3514
|
-
table.remove();
|
|
3515
|
-
});
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
Testimony.test('Solarite.watch3.primitive', () => {
|
|
3525
|
-
|
|
3526
|
-
class W100 extends HTMLElement {
|
|
3527
|
-
|
|
3528
|
-
constructor() {
|
|
3529
|
-
super();
|
|
3530
|
-
watch3(this, 'name', 'Fred');
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
this.render();
|
|
3534
|
-
}
|
|
3535
|
-
|
|
3536
|
-
render() {
|
|
3537
|
-
r(this)`<w-100>${this.name + '!'}</w-100>`;
|
|
3538
|
-
}
|
|
3539
|
-
}
|
|
3540
|
-
customElements.define('w-100', W100);
|
|
3541
|
-
|
|
3542
|
-
let a = new W100();
|
|
3543
|
-
document.body.append(a);
|
|
3544
|
-
assert(a.outerHTML, `<w-100>Fred!</w-100>`);
|
|
3545
|
-
|
|
3546
|
-
a.name = 'Jim';
|
|
3547
|
-
assert(a.outerHTML, `<w-100>Jim!</w-100>`);
|
|
3548
|
-
|
|
3549
|
-
a.remove();
|
|
3550
|
-
});
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
Testimony.test('Solarite.watch3._nodes', () => {
|
|
3554
|
-
|
|
3555
|
-
class W110 extends HTMLElement {
|
|
3556
|
-
name = 'Fred';
|
|
3557
|
-
name2 = 'White';
|
|
3558
|
-
|
|
3559
|
-
constructor() {
|
|
3560
|
-
super();
|
|
3561
|
-
watch3(this, 'name');
|
|
3562
|
-
this.render();
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
|
-
render() {
|
|
3566
|
-
r(this)`<w-110>${() => r`<div>${this.name + '!'}</div>`} ${this.name2}</w-110>`;
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
customElements.define('w-110', W110);
|
|
3570
|
-
|
|
3571
|
-
let a = new W110();
|
|
3572
|
-
document.body.append(a);
|
|
3573
|
-
assert(a.outerHTML, `<w-110><div>Fred!</div> White</w-110>`);
|
|
3574
|
-
|
|
3575
|
-
a.name = 'Jim';
|
|
3576
|
-
assert(a.outerHTML, `<w-110><div>Jim!</div> White</w-110>`);
|
|
3577
|
-
|
|
3578
|
-
a.name2 = 'Brown'
|
|
3579
|
-
a.render();
|
|
3580
|
-
assert(a.outerHTML, `<w-110><div>Jim!</div> Brown</w-110>`);
|
|
3581
|
-
|
|
3582
|
-
a.remove();
|
|
3583
|
-
});
|
|
3584
|
-
//</editor-fold>
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
//<editor-fold desc="full">
|
|
3590
|
-
/* ┌─────────────────╮
|
|
3591
|
-
* | Full |
|
|
3592
|
-
* └─────────────────╯*/
|
|
3593
|
-
|
|
3594
|
-
Testimony.test('Solarite.full._todoList', () => {
|
|
3595
|
-
class ShoppingList extends HTMLElement {
|
|
3596
|
-
constructor(items=[]) {
|
|
3597
|
-
super();
|
|
3598
|
-
this.items = items;
|
|
3599
|
-
this.render();
|
|
3600
|
-
}
|
|
3601
|
-
|
|
3602
|
-
addItem() {
|
|
3603
|
-
this.items.push({name: '', qty: 0});
|
|
3604
|
-
this.render();
|
|
3605
|
-
}
|
|
3606
|
-
|
|
3607
|
-
removeItem(item) {
|
|
3608
|
-
this.items.splice(this.items.indexOf(item), 1);
|
|
3609
|
-
this.render();
|
|
3610
|
-
}
|
|
3611
|
-
|
|
3612
|
-
render() {
|
|
3613
|
-
r(this)`
|
|
3614
|
-
<shopping-list>
|
|
3615
|
-
<style>:host input { width: 80px }</style>
|
|
3616
|
-
|
|
3617
|
-
<button onclick=${this.addItem}>Add Item</button>
|
|
3618
|
-
|
|
3619
|
-
${this.items.map(item => r`
|
|
3620
|
-
<div>
|
|
3621
|
-
<input placeholder="Item" value=${item.name}
|
|
3622
|
-
oninput=${e => { // two-way binding
|
|
3623
|
-
item.name = e.target.value;
|
|
3624
|
-
this.render()
|
|
3625
|
-
}}>
|
|
3626
|
-
</div>
|
|
3627
|
-
`)}
|
|
3628
|
-
</shopping-list>`
|
|
3629
|
-
}
|
|
3630
|
-
}
|
|
3631
|
-
|
|
3632
|
-
customElements.define('shopping-list', ShoppingList);
|
|
3633
|
-
document.body.append(new ShoppingList()); // add <shopping-list> element
|
|
3634
|
-
});
|
|
3635
|
-
|
|
3636
|
-
Testimony.test('Solarite.full._treeItems', () => {
|
|
3637
|
-
|
|
3638
|
-
//import '../src/Solarite.js'
|
|
3639
|
-
|
|
3640
|
-
class TreeItem extends Solarite {
|
|
3641
|
-
|
|
3642
|
-
constructor(title, children=[]) {
|
|
3643
|
-
super();
|
|
3644
|
-
this.childItems = children;
|
|
3645
|
-
this.titleText = title;
|
|
3646
|
-
this.showChildren = true;
|
|
3647
|
-
}
|
|
3648
|
-
|
|
3649
|
-
toggleChildren() {
|
|
3650
|
-
this.showChildren = !this.showChildren
|
|
3651
|
-
this.render();
|
|
3652
|
-
}
|
|
3653
|
-
|
|
3654
|
-
render() {
|
|
3655
|
-
r(this)`
|
|
3656
|
-
<tree-item>
|
|
3657
|
-
<style>
|
|
3658
|
-
:host #childItems { padding-left: 20px }
|
|
3659
|
-
</style>
|
|
3660
|
-
<div onclick="${this.toggleChildren}">${this.titleText}</div>
|
|
3661
|
-
<div hidden="${!this.showChildren}">
|
|
3662
|
-
${this.childItems}
|
|
3663
|
-
</div>
|
|
3664
|
-
</tree-item>`;
|
|
3665
|
-
}
|
|
3666
|
-
}
|
|
3667
|
-
TreeItem.define();
|
|
3668
|
-
|
|
3669
|
-
let root = new TreeItem('Root', [
|
|
3670
|
-
new TreeItem('Folder 1', [
|
|
3671
|
-
new TreeItem('File 1'),
|
|
3672
|
-
new TreeItem('File 2'),
|
|
3673
|
-
new TreeItem('File 3')
|
|
3674
|
-
]),
|
|
3675
|
-
new TreeItem('Folder 2')
|
|
3676
|
-
])
|
|
3677
|
-
|
|
3678
|
-
document.body.append(root);
|
|
3679
|
-
root.remove();
|
|
3680
|
-
});
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
// An attempt to create a simpler version that reproduces the same bug as full.misc.
|
|
3687
|
-
// but this version always works, and doesn't reproduce the issue.
|
|
3688
|
-
Testimony.test('Solarite.full._isc2', () => {
|
|
3689
|
-
let items = [
|
|
3690
|
-
{name: 'Apples', qty: 1},
|
|
3691
|
-
{name: 'Banans', qty: 2},
|
|
3692
|
-
{name: 'Cherries', qty: 3}
|
|
3693
|
-
]
|
|
3694
|
-
let toggle = false;
|
|
3695
|
-
|
|
3696
|
-
class Misc2 extends HTMLElement {
|
|
3697
|
-
render() {
|
|
3698
|
-
r(this)`
|
|
3699
|
-
<misc-2>
|
|
3700
|
-
${items.map(item => r`
|
|
3701
|
-
<div>
|
|
3702
|
-
${r`<span>${item.name}</span>`}
|
|
3703
|
-
${r`<span>${item.qty}</span>`}
|
|
3704
|
-
</div>`
|
|
3705
|
-
)}
|
|
3706
|
-
|
|
3707
|
-
</misc-2>`;
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
|
|
3711
|
-
customElements.define('misc-2', Misc2);
|
|
3712
|
-
|
|
3713
|
-
let m = new Misc2();
|
|
3714
|
-
document.body.append(m);
|
|
3715
|
-
m.render();
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
// let temp = items[0];
|
|
3719
|
-
// items[0] = items[1];
|
|
3720
|
-
// items[1] = temp;
|
|
3721
|
-
|
|
3722
|
-
// items[0].name = 'Bananas';
|
|
3723
|
-
// items[0].qty = 3;
|
|
3724
|
-
|
|
3725
|
-
//items[0] = items[1];
|
|
3726
|
-
|
|
3727
|
-
toggle = !toggle;
|
|
3728
|
-
|
|
3729
|
-
m.render();
|
|
3730
|
-
|
|
3731
|
-
toggle = !toggle;
|
|
3732
|
-
|
|
3733
|
-
m.render();
|
|
3734
|
-
|
|
3735
|
-
toggle = !toggle;
|
|
3736
|
-
|
|
3737
|
-
m.render();
|
|
3738
|
-
|
|
3739
|
-
});
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
Testimony.test('Solarite.full._misc', () => {
|
|
3745
|
-
|
|
3746
|
-
class Misc1 extends HTMLElement {
|
|
3747
|
-
|
|
3748
|
-
items = [];
|
|
3749
|
-
options = [];
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
constructor(options) {
|
|
3754
|
-
super();
|
|
3755
|
-
this.options = options;
|
|
3756
|
-
this.items = items;
|
|
3757
|
-
|
|
3758
|
-
for (let product of this.items)
|
|
3759
|
-
for (let option of this.options)
|
|
3760
|
-
option[product.id + '_showOther'] = !!(product[option.name] && option.name !== product[option.name]);
|
|
3761
|
-
|
|
3762
|
-
this.render();
|
|
3763
|
-
}
|
|
3764
|
-
|
|
3765
|
-
async setValue(product, option, field, value) {
|
|
3766
|
-
product[field] = value;
|
|
3767
|
-
option[product.id + '_showOther'] = !!(value && option.name !== value);
|
|
3768
|
-
this.render();
|
|
3769
|
-
}
|
|
3770
|
-
|
|
3771
|
-
render() {
|
|
3772
|
-
r(this)`
|
|
3773
|
-
<misc-1>
|
|
3774
|
-
${this.items.map(item => r`
|
|
3775
|
-
<p>
|
|
3776
|
-
${this.options.map(option => r`
|
|
3777
|
-
<div style="display: flex">
|
|
3778
|
-
${r`<button onclick=${() => this.setValue(item, option, option.name, '')}>${option.name}</button>`}
|
|
3779
|
-
|
|
3780
|
-
${option[item.id + '_showOther'] && r`<input>`}
|
|
3781
|
-
</div>`
|
|
3782
|
-
)}
|
|
3783
|
-
</p>
|
|
3784
|
-
<br><br>
|
|
3785
|
-
`)}
|
|
3786
|
-
</misc-1>`;
|
|
3787
|
-
}
|
|
3788
|
-
}
|
|
3789
|
-
customElements.define('misc-1', Misc1);
|
|
3790
|
-
|
|
3791
|
-
let options = [
|
|
3792
|
-
{
|
|
3793
|
-
name: "a"
|
|
3794
|
-
},
|
|
3795
|
-
{
|
|
3796
|
-
name: "b"
|
|
3797
|
-
},
|
|
3798
|
-
{
|
|
3799
|
-
name: "c"
|
|
3800
|
-
}
|
|
3801
|
-
];
|
|
3802
|
-
let items = [
|
|
3803
|
-
{
|
|
3804
|
-
"id": 1,
|
|
3805
|
-
"a": 1,
|
|
3806
|
-
"b": 2,
|
|
3807
|
-
"c": 3
|
|
3808
|
-
},
|
|
3809
|
-
{
|
|
3810
|
-
"id": 2,
|
|
3811
|
-
"a": 1,
|
|
3812
|
-
"b": 2,
|
|
3813
|
-
"c": null
|
|
3814
|
-
}
|
|
3815
|
-
];
|
|
3816
|
-
let sp = new Misc1(options, items);
|
|
3817
|
-
document.body.append(sp);
|
|
3818
|
-
|
|
3819
|
-
sp.children[0].setAttribute('style', 'border: 1px solid red');
|
|
3820
|
-
|
|
3821
|
-
sp.children[0].children[0].querySelector('input').setAttribute('style', 'border: 3px solid #f80');
|
|
3822
|
-
sp.children[0].children[1].querySelector('input').setAttribute('style', 'border: 3px solid #fc0');
|
|
3823
|
-
sp.children[0].children[2].querySelector('input').setAttribute('style', 'border: 3px solid #660');
|
|
3824
|
-
|
|
3825
|
-
sp.children[1].setAttribute('style', 'border: 1px solid blue');
|
|
3826
|
-
|
|
3827
|
-
sp.children[3].children[0].setAttribute('style', 'border: 3px solid #0f8');
|
|
3828
|
-
sp.children[3].children[1].setAttribute('style', 'border: 3px solid #0fc');
|
|
3829
|
-
sp.children[3].children[2].setAttribute('style', 'border: 3px solid #0cf');
|
|
3830
|
-
|
|
3831
|
-
// Trigger bug:
|
|
3832
|
-
//sp.setValue(products[0], 'b', '');
|
|
3833
|
-
//sp.setValue(products[0], 'c', '');
|
|
3834
|
-
});
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
//<editor-fold desc="full">
|
|
3838
|
-
|