-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.html
238 lines (191 loc) · 9.35 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<head>
<script title="config">
window.DEBUG = true;
</script>
<style>
body {
font-family: Helvetica;
}
.stylee {
background-color: yellow;
}
h2 {
font-size: 1rem;
}
</style>
<template id="template-0">
<p> 0 {[]} - {[.]}</p>
</template>
<template id="template-1">
<h2>template-1</h2>
<p>p <span>{[]}</span> - <span>{[.]}</span></p>
<p>p <span>{[]}</span> - <span class="leading-class {[0.value]} trailing-class">{[.]}</span><span hidden="{[0.value|not]}"> - value: {[0.value]}</span></p>
</template>
<template id="template-2">
<h2>template-2</h2>
<p fn="test">p[fn] <span>{[]}</span> - <span>{[.]}</span></p>
<p fn="test">p[fn] <span>{[]}</span> - <span class="leading-class {[0.value]} trailing-class">{[.]}</span><span hidden="{[0.value|not]}"> - value: {[0.value]}</span></p>
</template>
<template id="template-3" fn="get:1">
<p>Template 3 {[.]}</p>
</template>
<template id="template-4">
<p>Template 4 {[.]} {[id|add:9]}</p>
</template>
<template id="template-5">
<p>Template 5 {[.]}</p>
</template>
<template id="template-6">
<p>{[ NOPROP ]}</p>
</template>
</head>
<body>
<div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #d0e84a;">#d0e84a</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #b9d819;">#b9d819</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #a3b31f;">#a3b31f</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #858720;">#858720</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #d34515;">#d34515</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #915133;">#915133</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #723f24;">#723f24</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #6894ab;">#6894ab</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #4a6a7a;">#4a6a7a</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #25343c;">#25343c</div
><div style="display: inline-block; font-size: 0.75rem; text-align:center; width: 60px; height: 60px; color: white; background-color: #282a2b;">#282a2b</div>
<template is="sparky-template" fn="data">
<h2>template[fn]</h2>
<p>p 0.1 <span>{[]}</span> - <span>{[.]}</span></p>
<p>p 0.2 <span>{[]}</span> - <span class="leading-class {[0.value]} trailing-class">{[.]}</span><span hidden="{[0.value|not]}"> - value: {[0.value]}</span></p>
</template>
<template is="sparky-template" fn="data">
<h2>template[fn]</h2>
<p fn="test">p[fn] 0.1 <span>{[]}</span> - <span>{[.]}</span></p>
<p fn="test">p[fn] 0.2 <span>{[]}</span> - <span class="leading-class {[0.value]} trailing-class">{[.]}</span><span hidden="{[0.value|not]}"> - value: {[0.value]}</span></p>
</template>
<template is="sparky-template" fn="data" src="#template-1">
<p>template[fn][include] Waiting for data...</p>
</template>
<template is="sparky-template" fn="data" src="#template-2">
<p>template[fn][include] Waiting for data...</p>
</template>
<template is="sparky-template" fn="data">
<div src="#template-1">div[src="#template-1"] Waiting for data...</div>
<div src="#template-2">div[src="#template-1"] Waiting for data...</div>
</template>
<template is="sparky-template" fn="data">
<template src="#template-1">template[src="#template-1"] Waiting for data...</template>
<template src="#template-2">template[src="#template-1"] Waiting for data...</template>
</template>
<template is="sparky-template" fn="data">
<h2>table td[fn=each], tr[fn=each]</h2>
<table>
<tbody>
<tr>
<td fn="each">Table cell 1 <span class="leading-class {[value]} trailing-class">{[.]}</span><span hidden="{[value|not]}"> - value: {[value]}</span></td>
</tr>
<tr fn="each">
<td>Table cell 2 <span class="leading-class {[value]} trailing-class">{[.]}</span><span hidden="{[value|not]}"> - value: {[value]}</span></td>
</tr>
</tbody>
</table>
</template>
<template is="sparky-template" fn="data">
<h2>template[include]</h2>
<template src="#template-{[0.id]}"></template>
</template>
<template is="sparky-template" fn="data">
<h2>External templates</h2>
<template src="test-template.html#test-template-1"></template>
<template fn="get:0" src="test-template.html#test-template-2"></template>
</template>
<template is="sparky-template" fn="data">
<h2>Unrendered (should show nothing)</h2>
<p>{[POO]}</p>
<p fn="test">{[POO]}</p>
<p fn="test each">{[POO]}</p>
<p fn="test each" src="#template-6"></p>
</template>
<div class="test-block block">
<h1>Tests</h1>
</div>
<script type="module">
import { Observer, Stream, Fn } from '../fn/module.js';
import Sparky, { register } from './module.js';
const data1 = [{ id: 1 }, { id: 2 }];
const data2 = [{ id: 3 }, { id: 4 }];
// Mangle data
setTimeout(function() {
Observer(data2)[0].value = 'surprise';
Observer(data2).push({ id: 5 });
setTimeout(function() {
Observer(data2)[0].value = 'stylee';
}, 2000);
}, 4000);
register('data', function(node) {
const scopes = Stream.of();
scopes.label = 'data';
setTimeout(function() {
setTimeout(function() {
scopes.push(data1);
setTimeout(function() {
scopes.push(data2);
}, 1000);
}, 1000);
}, 1000);
return scopes;
});
register('test', function(node, stream, params) {
//console.log('node:', node, 'params:', params);
});
window.Stream = Stream;
</script>
<!-- Tests -->
<template id="range-control-template">
<link rel="stylesheet" href="../dom/elements/range-control.css" />
<input class="control-input" type="range" id="input" value="{[unitValue]}" min="0" max="1" step="any" />
<label class="control-label" for="input"><slot></slot></label>
<output class="control-output">{[prefix]}{[displayValue]}<abbr>{[displayUnit]}</abbr></output>
<template fn="get:ticks each">
<input class="tick-input" type="radio" name="tick" id="tick-{[value]}" value="{[tickValue|float-string]}" :value="{[root.unitValue|float-string]}" />
<label class="tick-label" :style="left: calc(0.5rem + (100% - 1rem) * {[tickValue]});" :for="tick-{[value]}">{[displayValue]}</label>
</template>
<slot name="plugs"></slot>
</template>
<!--template is="sparky-template" fn="thing">
<range-control min="0" max="1" :value="{[value]}" step="any"></range-control>
<input type="range" min="0" max="1" :value="{[value]}" step="any"/>
</template-->
<script type="module">
import "../dom/elements/range-control.js";
import { Observer, Stream, Fn } from '../fn/module.js';
import { register, config } from './module.js';
register('thing', function(node, stream, params) {
return Stream.of({ value: 0.4 });
});
// Let Sparky know about custom elements
Object.assign(config, {
'range-control': { attributes: [], booleans: ['disabled'], value: 'number' }
});
// Run tests
import './test/sparky.transforms-test.js';
import './test/input-text.js';
import './test/input-range.js';
import './test/input-number.js';
import './test/input-checkbox.js';
import './test/textarea.js';
import './test/select.test.js';
import './test/sparky.stop-scopes.test.js';
import './test/sparky.fn.each-test.js';
import './test/fn.entries.js';
import './test/sparky.test.js';
//import './test/sparky.parent-scope-test.js';
//import './test/token-parent-path.js';
//import './test/token-parent-each.js';
//import './test/sparky.stop-mutations.test.js';
//import './test/sparky.fn-test.js';
//import './test/fn-template.js';
//import './test/fn-template-url.js';
//import './test/sparky.fn.load-test.js';
//import './plugins/sparky.fn.clock.js';
//import './test/sparky.fn.clock-test.js';
</script>
</body>