ripple 0.3.84 → 0.3.86

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/package.json +3 -3
  3. package/src/constants.js +4 -0
  4. package/src/runtime/internal/client/blocks.js +53 -0
  5. package/src/runtime/internal/client/component.js +3 -3
  6. package/src/runtime/internal/client/constants.js +4 -0
  7. package/src/runtime/internal/client/for.js +87 -14
  8. package/src/runtime/internal/client/if.js +18 -2
  9. package/src/runtime/internal/client/index.js +1 -0
  10. package/src/runtime/internal/client/operations.js +25 -0
  11. package/src/runtime/internal/client/runtime.js +62 -10
  12. package/src/runtime/internal/client/switch.js +33 -5
  13. package/src/runtime/internal/client/template.js +10 -2
  14. package/src/runtime/internal/client/try.js +12 -2
  15. package/src/runtime/internal/client/types.d.ts +4 -0
  16. package/tests/client/__snapshots__/for.test.tsrx.snap +0 -2
  17. package/tests/client/compiler/compiler.basic.test.tsrx +5 -2
  18. package/tests/client/composite/__snapshots__/composite.render.test.tsrx.snap +0 -4
  19. package/tests/client/for-single-root-items.test.tsrx +130 -0
  20. package/tests/client/scoped-flush.test.tsrx +105 -0
  21. package/tests/hydration/compiled/client/basic.js +198 -214
  22. package/tests/hydration/compiled/client/composite.js +23 -72
  23. package/tests/hydration/compiled/client/for.js +66 -72
  24. package/tests/hydration/compiled/client/hmr.js +2 -13
  25. package/tests/hydration/compiled/client/html.js +619 -479
  26. package/tests/hydration/compiled/client/if-children.js +72 -84
  27. package/tests/hydration/compiled/client/if-fragment-controlflow.js +463 -0
  28. package/tests/hydration/compiled/client/if.js +87 -92
  29. package/tests/hydration/compiled/client/mixed-control-flow.js +120 -160
  30. package/tests/hydration/compiled/client/nested-control-flow.js +288 -360
  31. package/tests/hydration/compiled/client/portal.js +15 -21
  32. package/tests/hydration/compiled/client/reactivity.js +7 -12
  33. package/tests/hydration/compiled/client/switch.js +113 -115
  34. package/tests/hydration/compiled/client/track-async-serialization.js +71 -122
  35. package/tests/hydration/compiled/client/try.js +26 -41
  36. package/tests/hydration/compiled/server/basic.js +295 -556
  37. package/tests/hydration/compiled/server/composite.js +31 -50
  38. package/tests/hydration/compiled/server/events.js +37 -173
  39. package/tests/hydration/compiled/server/for.js +236 -847
  40. package/tests/hydration/compiled/server/head.js +110 -241
  41. package/tests/hydration/compiled/server/hmr.js +14 -41
  42. package/tests/hydration/compiled/server/html-in-template.js +14 -38
  43. package/tests/hydration/compiled/server/html.js +951 -1176
  44. package/tests/hydration/compiled/server/if-children.js +59 -493
  45. package/tests/hydration/compiled/server/if-fragment-controlflow.js +227 -0
  46. package/tests/hydration/compiled/server/if.js +57 -209
  47. package/tests/hydration/compiled/server/mixed-control-flow.js +144 -250
  48. package/tests/hydration/compiled/server/nested-control-flow.js +309 -559
  49. package/tests/hydration/compiled/server/portal.js +94 -156
  50. package/tests/hydration/compiled/server/reactivity.js +23 -65
  51. package/tests/hydration/compiled/server/return.js +6 -16
  52. package/tests/hydration/compiled/server/switch.js +91 -219
  53. package/tests/hydration/compiled/server/track-async-serialization.js +211 -256
  54. package/tests/hydration/compiled/server/try.js +67 -126
  55. package/tests/hydration/components/html.tsrx +75 -0
  56. package/tests/hydration/components/if-fragment-controlflow.tsrx +145 -0
  57. package/tests/hydration/html.test.js +50 -0
  58. package/tests/hydration/if-fragment-controlflow.test.js +95 -0
  59. package/tests/server/compiler.test.tsrx +6 -2
@@ -0,0 +1,227 @@
1
+ // @ts-nocheck
2
+ import * as _$_ from 'ripple/internal/server';
3
+
4
+ export function IfFragmentForElement() {
5
+ return _$_.tsrx_element(() => {
6
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
7
+ const hasLoaded = true;
8
+
9
+ _$_.regular_block(() => {
10
+ let __out = '';
11
+
12
+ __out += '<div class="feed-c"><!--[-->';
13
+
14
+ if (hasLoaded) {
15
+ __out += '<!--[--><!--[-->';
16
+
17
+ for (const muze of muzes) {
18
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
19
+ }
20
+
21
+ __out += '<!--]--><span class="after">after</span><!--]-->';
22
+ }
23
+
24
+ __out += '<!--]--></div>';
25
+ _$_.output_push(__out);
26
+ });
27
+ });
28
+ }
29
+
30
+ export function IfFragmentForIfIf() {
31
+ return _$_.tsrx_element(() => {
32
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
33
+ const hasLoaded = true;
34
+
35
+ _$_.regular_block(() => {
36
+ let __out = '';
37
+
38
+ __out += '<div class="feed"><!--[-->';
39
+
40
+ if (hasLoaded) {
41
+ __out += '<!--[--><!--[-->';
42
+
43
+ for (const muze of muzes) {
44
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
45
+ }
46
+
47
+ __out += '<!--]--><!--[-->';
48
+
49
+ if (muzes.length > 0) {
50
+ __out += '<span class="has-items">has items</span>';
51
+ }
52
+
53
+ __out += '<!--]--><!--[-->';
54
+
55
+ if (muzes.length === 0) {
56
+ __out += '<span class="empty">empty</span>';
57
+ }
58
+
59
+ __out += '<!--]--><!--]-->';
60
+ }
61
+
62
+ __out += '<!--]--></div>';
63
+ _$_.output_push(__out);
64
+ });
65
+ });
66
+ }
67
+
68
+ export function IfFragmentElements() {
69
+ return _$_.tsrx_element(() => {
70
+ const hasLoaded = true;
71
+
72
+ _$_.regular_block(() => {
73
+ let __out = '';
74
+
75
+ __out += '<div class="feed-b"><!--[-->';
76
+
77
+ if (hasLoaded) {
78
+ __out += '<!--[--><p class="muze">b</p><p class="muze">c</p><!--]-->';
79
+ }
80
+
81
+ __out += '<!--]--></div>';
82
+ _$_.output_push(__out);
83
+ });
84
+ });
85
+ }
86
+
87
+ export function ComponentBodyFragmentControlFlow() {
88
+ return _$_.tsrx_element(() => {
89
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
90
+
91
+ _$_.regular_block(() => {
92
+ let __out = '';
93
+
94
+ __out += '<!--[--><!--[-->';
95
+
96
+ for (const muze of muzes) {
97
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
98
+ }
99
+
100
+ __out += '<!--]--><span class="after">after</span><!--]-->';
101
+ _$_.output_push(__out);
102
+ });
103
+ });
104
+ }
105
+
106
+ export function ComponentBodyCodeBlockControlFlow() {
107
+ return _$_.tsrx_element(() => {
108
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
109
+
110
+ _$_.regular_block(() => {
111
+ let __out = '';
112
+
113
+ __out += '<!--[-->';
114
+ _$_.output_push(__out);
115
+ __out = '';
116
+
117
+ _$_.render_expression(_$_.tsrx_element(() => {
118
+ let __out = '';
119
+ const rows = muzes;
120
+
121
+ __out += '<!--[-->';
122
+
123
+ for (const muze of rows) {
124
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
125
+ }
126
+
127
+ __out += '<!--]-->';
128
+ _$_.output_push(__out);
129
+ }));
130
+
131
+ __out += '<span class="after">after</span><!--]-->';
132
+ _$_.output_push(__out);
133
+ });
134
+ });
135
+ }
136
+
137
+ export function IfCodeBlockControlFlow() {
138
+ return _$_.tsrx_element(() => {
139
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
140
+ const hasLoaded = true;
141
+
142
+ _$_.regular_block(() => {
143
+ let __out = '';
144
+
145
+ __out += '<div class="feed-f"><!--[-->';
146
+
147
+ if (hasLoaded) {
148
+ __out += '<!--[-->';
149
+ _$_.output_push(__out);
150
+ __out = '';
151
+
152
+ _$_.render_expression(_$_.tsrx_element(() => {
153
+ let __out = '';
154
+ const rows = muzes;
155
+
156
+ __out += '<!--[-->';
157
+
158
+ for (const muze of rows) {
159
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
160
+ }
161
+
162
+ __out += '<!--]-->';
163
+ _$_.output_push(__out);
164
+ }));
165
+
166
+ __out += '<span class="after">after</span><!--]-->';
167
+ }
168
+
169
+ __out += '<!--]--></div>';
170
+ _$_.output_push(__out);
171
+ });
172
+ });
173
+ }
174
+
175
+ export function IfElseFragment() {
176
+ return _$_.tsrx_element(() => {
177
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
178
+ const hasLoaded = false;
179
+
180
+ _$_.regular_block(() => {
181
+ let __out = '';
182
+
183
+ __out += '<div class="feed-d"><!--[-->';
184
+
185
+ if (hasLoaded) {
186
+ __out += '<span class="loading">loading</span>';
187
+ } else {
188
+ __out += '<!--[--><!--[-->';
189
+
190
+ for (const muze of muzes) {
191
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
192
+ }
193
+
194
+ __out += '<!--]--><span class="after">after</span><!--]-->';
195
+ }
196
+
197
+ __out += '<!--]--></div>';
198
+ _$_.output_push(__out);
199
+ });
200
+ });
201
+ }
202
+
203
+ export function IfDivFragment() {
204
+ return _$_.tsrx_element(() => {
205
+ const muzes = [{ muzeId: 'b' }, { muzeId: 'c' }];
206
+ const hasLoaded = true;
207
+
208
+ _$_.regular_block(() => {
209
+ let __out = '';
210
+
211
+ __out += '<div class="feed-e"><!--[-->';
212
+
213
+ if (hasLoaded) {
214
+ __out += '<section><!--[--><!--[-->';
215
+
216
+ for (const muze of muzes) {
217
+ __out += '<p class="muze">' + _$_.escape(muze.muzeId) + '</p>';
218
+ }
219
+
220
+ __out += '<!--]--><span class="after">after</span><!--]--></section>';
221
+ }
222
+
223
+ __out += '<!--]--></div>';
224
+ _$_.output_push(__out);
225
+ });
226
+ });
227
+ }
@@ -8,21 +8,16 @@ export function IfTruthy() {
8
8
  const show = true;
9
9
 
10
10
  _$_.regular_block(() => {
11
- _$_.output_push('<!--[-->');
11
+ let __out = '';
12
12
 
13
- if (show) {
14
- _$_.output_push('<div');
15
- _$_.output_push(' class="shown"');
16
- _$_.output_push('>');
17
-
18
- {
19
- _$_.output_push('Visible');
20
- }
13
+ __out += '<!--[-->';
21
14
 
22
- _$_.output_push('</div>');
15
+ if (show) {
16
+ __out += '<div class="shown">Visible</div>';
23
17
  }
24
18
 
25
- _$_.output_push('<!--]-->');
19
+ __out += '<!--]-->';
20
+ _$_.output_push(__out);
26
21
  });
27
22
  });
28
23
  }
@@ -32,21 +27,16 @@ export function IfFalsy() {
32
27
  const show = false;
33
28
 
34
29
  _$_.regular_block(() => {
35
- _$_.output_push('<!--[-->');
30
+ let __out = '';
36
31
 
37
- if (show) {
38
- _$_.output_push('<div');
39
- _$_.output_push(' class="shown"');
40
- _$_.output_push('>');
41
-
42
- {
43
- _$_.output_push('Visible');
44
- }
32
+ __out += '<!--[-->';
45
33
 
46
- _$_.output_push('</div>');
34
+ if (show) {
35
+ __out += '<div class="shown">Visible</div>';
47
36
  }
48
37
 
49
- _$_.output_push('<!--]-->');
38
+ __out += '<!--]-->';
39
+ _$_.output_push(__out);
50
40
  });
51
41
  });
52
42
  }
@@ -56,31 +46,18 @@ export function IfElse() {
56
46
  const isLoggedIn = true;
57
47
 
58
48
  _$_.regular_block(() => {
59
- _$_.output_push('<!--[-->');
49
+ let __out = '';
60
50
 
61
- if (isLoggedIn) {
62
- _$_.output_push('<div');
63
- _$_.output_push(' class="logged-in"');
64
- _$_.output_push('>');
65
-
66
- {
67
- _$_.output_push('Welcome back!');
68
- }
51
+ __out += '<!--[-->';
69
52
 
70
- _$_.output_push('</div>');
53
+ if (isLoggedIn) {
54
+ __out += '<div class="logged-in">Welcome back!</div>';
71
55
  } else {
72
- _$_.output_push('<div');
73
- _$_.output_push(' class="logged-out"');
74
- _$_.output_push('>');
75
-
76
- {
77
- _$_.output_push('Please log in');
78
- }
79
-
80
- _$_.output_push('</div>');
56
+ __out += '<div class="logged-out">Please log in</div>';
81
57
  }
82
58
 
83
- _$_.output_push('<!--]-->');
59
+ __out += '<!--]-->';
60
+ _$_.output_push(__out);
84
61
  });
85
62
  });
86
63
  }
@@ -90,32 +67,16 @@ export function ReactiveIf() {
90
67
  let lazy = _$_.track(true, '19a16ff0');
91
68
 
92
69
  _$_.regular_block(() => {
93
- {
94
- _$_.output_push('<button');
95
- _$_.output_push(' class="toggle"');
96
- _$_.output_push('>');
70
+ let __out = '';
97
71
 
98
- {
99
- _$_.output_push('Toggle');
100
- }
72
+ __out += '<button class="toggle">Toggle</button><!--[-->';
101
73
 
102
- _$_.output_push('</button>');
103
- _$_.output_push('<!--[-->');
104
-
105
- if (lazy.value) {
106
- _$_.output_push('<div');
107
- _$_.output_push(' class="content"');
108
- _$_.output_push('>');
109
-
110
- {
111
- _$_.output_push('Content visible');
112
- }
113
-
114
- _$_.output_push('</div>');
115
- }
116
-
117
- _$_.output_push('<!--]-->');
74
+ if (lazy.value) {
75
+ __out += '<div class="content">Content visible</div>';
118
76
  }
77
+
78
+ __out += '<!--]-->';
79
+ _$_.output_push(__out);
119
80
  });
120
81
  });
121
82
  }
@@ -125,42 +86,18 @@ export function ReactiveIfElse() {
125
86
  let lazy_1 = _$_.track(false, '41177f39');
126
87
 
127
88
  _$_.regular_block(() => {
128
- {
129
- _$_.output_push('<button');
130
- _$_.output_push(' class="toggle"');
131
- _$_.output_push('>');
132
-
133
- {
134
- _$_.output_push('Toggle');
135
- }
89
+ let __out = '';
136
90
 
137
- _$_.output_push('</button>');
138
- _$_.output_push('<!--[-->');
139
-
140
- if (lazy_1.value) {
141
- _$_.output_push('<div');
142
- _$_.output_push(' class="on"');
143
- _$_.output_push('>');
144
-
145
- {
146
- _$_.output_push('ON');
147
- }
148
-
149
- _$_.output_push('</div>');
150
- } else {
151
- _$_.output_push('<div');
152
- _$_.output_push(' class="off"');
153
- _$_.output_push('>');
154
-
155
- {
156
- _$_.output_push('OFF');
157
- }
158
-
159
- _$_.output_push('</div>');
160
- }
91
+ __out += '<button class="toggle">Toggle</button><!--[-->';
161
92
 
162
- _$_.output_push('<!--]-->');
93
+ if (lazy_1.value) {
94
+ __out += '<div class="on">ON</div>';
95
+ } else {
96
+ __out += '<div class="off">OFF</div>';
163
97
  }
98
+
99
+ __out += '<!--]-->';
100
+ _$_.output_push(__out);
164
101
  });
165
102
  });
166
103
  }
@@ -171,56 +108,22 @@ export function NestedIf() {
171
108
  let lazy_3 = _$_.track(true, 'f21b8c26');
172
109
 
173
110
  _$_.regular_block(() => {
174
- {
175
- _$_.output_push('<button');
176
- _$_.output_push(' class="outer-toggle"');
177
- _$_.output_push('>');
111
+ let __out = '';
178
112
 
179
- {
180
- _$_.output_push('Outer');
181
- }
113
+ __out += '<button class="outer-toggle">Outer</button><button class="inner-toggle">Inner</button><!--[-->';
182
114
 
183
- _$_.output_push('</button>');
184
- _$_.output_push('<button');
185
- _$_.output_push(' class="inner-toggle"');
186
- _$_.output_push('>');
115
+ if (lazy_2.value) {
116
+ __out += '<div class="outer-content">Outer<!--[-->';
187
117
 
188
- {
189
- _$_.output_push('Inner');
118
+ if (lazy_3.value) {
119
+ __out += '<span class="inner-content">Inner</span>';
190
120
  }
191
121
 
192
- _$_.output_push('</button>');
193
- _$_.output_push('<!--[-->');
194
-
195
- if (lazy_2.value) {
196
- _$_.output_push('<div');
197
- _$_.output_push(' class="outer-content"');
198
- _$_.output_push('>');
199
-
200
- {
201
- _$_.output_push('Outer');
202
- _$_.output_push('<!--[-->');
203
-
204
- if (lazy_3.value) {
205
- _$_.output_push('<span');
206
- _$_.output_push(' class="inner-content"');
207
- _$_.output_push('>');
208
-
209
- {
210
- _$_.output_push('Inner');
211
- }
212
-
213
- _$_.output_push('</span>');
214
- }
215
-
216
- _$_.output_push('<!--]-->');
217
- }
218
-
219
- _$_.output_push('</div>');
220
- }
221
-
222
- _$_.output_push('<!--]-->');
122
+ __out += '<!--]--></div>';
223
123
  }
124
+
125
+ __out += '<!--]-->';
126
+ _$_.output_push(__out);
224
127
  });
225
128
  });
226
129
  }
@@ -230,81 +133,26 @@ export function IfElseIfChain() {
230
133
  let lazy_4 = _$_.track('loading', '4c69c94a');
231
134
 
232
135
  _$_.regular_block(() => {
233
- _$_.output_push('<div');
234
- _$_.output_push('>');
235
-
236
- {
237
- _$_.output_push('<button');
238
- _$_.output_push(' class="success"');
239
- _$_.output_push('>');
240
-
241
- {
242
- _$_.output_push('Success');
243
- }
244
-
245
- _$_.output_push('</button>');
246
- _$_.output_push('<button');
247
- _$_.output_push(' class="error"');
248
- _$_.output_push('>');
249
-
250
- {
251
- _$_.output_push('Error');
252
- }
253
-
254
- _$_.output_push('</button>');
255
- _$_.output_push('<button');
256
- _$_.output_push(' class="loading"');
257
- _$_.output_push('>');
258
-
259
- {
260
- _$_.output_push('Loading');
261
- }
262
-
263
- _$_.output_push('</button>');
264
- _$_.output_push('<!--[-->');
136
+ let __out = '';
265
137
 
266
- if (lazy_4.value === 'loading') {
267
- _$_.output_push('<div');
268
- _$_.output_push(' class="state"');
269
- _$_.output_push('>');
138
+ __out += '<div><button class="success">Success</button><button class="error">Error</button><button class="loading">Loading</button><!--[-->';
270
139
 
271
- {
272
- _$_.output_push('Loading...');
273
- }
140
+ if (lazy_4.value === 'loading') {
141
+ __out += '<div class="state">Loading...</div>';
142
+ } else {
143
+ __out += '<!--[-->';
274
144
 
275
- _$_.output_push('</div>');
145
+ if (lazy_4.value === 'success') {
146
+ __out += '<div class="state">Success!</div>';
276
147
  } else {
277
- _$_.output_push('<!--[-->');
278
-
279
- if (lazy_4.value === 'success') {
280
- _$_.output_push('<div');
281
- _$_.output_push(' class="state"');
282
- _$_.output_push('>');
283
-
284
- {
285
- _$_.output_push('Success!');
286
- }
287
-
288
- _$_.output_push('</div>');
289
- } else {
290
- _$_.output_push('<div');
291
- _$_.output_push(' class="state"');
292
- _$_.output_push('>');
293
-
294
- {
295
- _$_.output_push('Error occurred');
296
- }
297
-
298
- _$_.output_push('</div>');
299
- }
300
-
301
- _$_.output_push('<!--]-->');
148
+ __out += '<div class="state">Error occurred</div>';
302
149
  }
303
150
 
304
- _$_.output_push('<!--]-->');
151
+ __out += '<!--]-->';
305
152
  }
306
153
 
307
- _$_.output_push('</div>');
154
+ __out += '<!--]--></div>';
155
+ _$_.output_push(__out);
308
156
  });
309
157
  });
310
158
  }