ripple 0.2.216 → 0.3.0
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/CHANGELOG.md +39 -0
- package/package.json +16 -7
- package/src/compiler/errors.js +1 -1
- package/src/compiler/identifier-utils.js +2 -0
- package/src/compiler/index.d.ts +2 -6
- package/src/compiler/phases/1-parse/index.js +171 -233
- package/src/compiler/phases/2-analyze/index.js +192 -16
- package/src/compiler/phases/2-analyze/prune.js +2 -2
- package/src/compiler/phases/3-transform/client/index.js +308 -91
- package/src/compiler/phases/3-transform/segments.js +43 -15
- package/src/compiler/phases/3-transform/server/index.js +71 -21
- package/src/compiler/scope.js +31 -12
- package/src/compiler/source-map-utils.js +4 -6
- package/src/compiler/types/acorn.d.ts +11 -0
- package/src/compiler/types/estree-jsx.d.ts +11 -0
- package/src/compiler/types/estree.d.ts +11 -0
- package/src/compiler/types/import.d.ts +32 -18
- package/src/compiler/types/index.d.ts +75 -23
- package/src/compiler/types/parse.d.ts +7 -10
- package/src/compiler/utils.js +48 -0
- package/src/runtime/array.js +53 -22
- package/src/runtime/date.js +15 -5
- package/src/runtime/index-client.js +41 -7
- package/src/runtime/index-server.js +7 -7
- package/src/runtime/internal/client/bindings.js +2 -2
- package/src/runtime/internal/client/blocks.js +40 -1
- package/src/runtime/internal/client/context.js +8 -0
- package/src/runtime/internal/client/for.js +3 -3
- package/src/runtime/internal/client/index.js +32 -5
- package/src/runtime/internal/client/render.js +20 -8
- package/src/runtime/internal/client/runtime.js +9 -7
- package/src/runtime/internal/client/try.js +15 -22
- package/src/runtime/internal/client/utils.js +1 -1
- package/src/runtime/internal/server/context.js +8 -0
- package/src/runtime/internal/server/index.js +99 -6
- package/src/runtime/map.js +7 -7
- package/src/runtime/media-query.js +10 -1
- package/src/runtime/object.js +6 -6
- package/src/runtime/proxy.js +6 -6
- package/src/runtime/set.js +11 -11
- package/src/runtime/url-search-params.js +13 -2
- package/src/runtime/url.js +15 -5
- package/src/utils/builders.js +13 -3
- package/tests/client/array/array.copy-within.test.ripple +11 -11
- package/tests/client/array/array.derived.test.ripple +42 -42
- package/tests/client/array/array.iteration.test.ripple +12 -12
- package/tests/client/array/array.mutations.test.ripple +25 -25
- package/tests/client/array/array.static.test.ripple +103 -106
- package/tests/client/array/array.to-methods.test.ripple +8 -8
- package/tests/client/async-suspend.test.ripple +94 -0
- package/tests/client/basic/basic.attributes.test.ripple +31 -31
- package/tests/client/basic/basic.collections.test.ripple +7 -7
- package/tests/client/basic/basic.components.test.ripple +48 -10
- package/tests/client/basic/basic.errors.test.ripple +46 -31
- package/tests/client/basic/basic.events.test.ripple +11 -11
- package/tests/client/basic/basic.get-set.test.ripple +18 -18
- package/tests/client/basic/basic.reactivity.test.ripple +47 -42
- package/tests/client/basic/basic.rendering.test.ripple +7 -7
- package/tests/client/basic/basic.utilities.test.ripple +4 -4
- package/tests/client/boundaries.test.ripple +7 -7
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.ripple.snap +2 -2
- package/tests/client/compiler/compiler.assignments.test.ripple +21 -21
- package/tests/client/compiler/compiler.basic.test.ripple +223 -82
- package/tests/client/compiler/compiler.tracked-access.test.ripple +8 -9
- package/tests/client/composite/composite.dynamic-components.test.ripple +8 -8
- package/tests/client/composite/composite.generics.test.ripple +4 -4
- package/tests/client/composite/composite.props.test.ripple +9 -9
- package/tests/client/composite/composite.reactivity.test.ripple +32 -26
- package/tests/client/composite/composite.render.test.ripple +13 -4
- package/tests/client/computed-properties.test.ripple +3 -3
- package/tests/client/context.test.ripple +3 -3
- package/tests/client/css/global-additional-cases.test.ripple +4 -4
- package/tests/client/css/style-identifier.test.ripple +49 -41
- package/tests/client/date.test.ripple +40 -40
- package/tests/client/dynamic-elements.test.ripple +165 -30
- package/tests/client/events.test.ripple +25 -25
- package/tests/client/for.test.ripple +76 -8
- package/tests/client/function-overload.test.ripple +0 -1
- package/tests/client/head.test.ripple +7 -7
- package/tests/client/html.test.ripple +2 -2
- package/tests/client/input-value.test.ripple +174 -176
- package/tests/client/map.test.ripple +21 -21
- package/tests/client/media-query.test.ripple +4 -4
- package/tests/client/object.test.ripple +12 -12
- package/tests/client/portal.test.ripple +4 -4
- package/tests/client/ref.test.ripple +5 -5
- package/tests/client/return.test.ripple +17 -17
- package/tests/client/set.test.ripple +16 -16
- package/tests/client/svg.test.ripple +6 -7
- package/tests/client/switch.test.ripple +10 -10
- package/tests/client/tracked-expression.test.ripple +1 -3
- package/tests/client/try.test.ripple +33 -4
- package/tests/client/url/url.derived.test.ripple +10 -9
- package/tests/client/url/url.parsing.test.ripple +10 -10
- package/tests/client/url/url.partial-removal.test.ripple +10 -10
- package/tests/client/url/url.reactivity.test.ripple +17 -17
- package/tests/client/url/url.serialization.test.ripple +4 -4
- package/tests/client/url-search-params/url-search-params.derived.test.ripple +11 -10
- package/tests/client/url-search-params/url-search-params.initialization.test.ripple +5 -7
- package/tests/client/url-search-params/url-search-params.iteration.test.ripple +13 -13
- package/tests/client/url-search-params/url-search-params.mutation.test.ripple +19 -19
- package/tests/client/url-search-params/url-search-params.retrieval.test.ripple +17 -17
- package/tests/client/url-search-params/url-search-params.serialization.test.ripple +5 -5
- package/tests/client/url-search-params/url-search-params.tracked-url.test.ripple +5 -5
- package/tests/hydration/compiled/client/events.js +8 -11
- package/tests/hydration/compiled/client/for.js +20 -23
- package/tests/hydration/compiled/client/head.js +17 -19
- package/tests/hydration/compiled/client/hmr.js +1 -3
- package/tests/hydration/compiled/client/html.js +1 -15
- package/tests/hydration/compiled/client/if-children.js +7 -9
- package/tests/hydration/compiled/client/if.js +5 -7
- package/tests/hydration/compiled/client/mixed-control-flow.js +3 -5
- package/tests/hydration/compiled/client/portal.js +1 -1
- package/tests/hydration/compiled/client/reactivity.js +9 -11
- package/tests/hydration/compiled/client/return.js +11 -13
- package/tests/hydration/compiled/client/switch.js +4 -6
- package/tests/hydration/compiled/server/basic.js +0 -1
- package/tests/hydration/compiled/server/composite.js +0 -3
- package/tests/hydration/compiled/server/events.js +8 -12
- package/tests/hydration/compiled/server/for.js +20 -23
- package/tests/hydration/compiled/server/head.js +17 -19
- package/tests/hydration/compiled/server/hmr.js +1 -4
- package/tests/hydration/compiled/server/html.js +1 -35
- package/tests/hydration/compiled/server/if-children.js +7 -11
- package/tests/hydration/compiled/server/if.js +5 -7
- package/tests/hydration/compiled/server/mixed-control-flow.js +3 -5
- package/tests/hydration/compiled/server/portal.js +1 -9
- package/tests/hydration/compiled/server/reactivity.js +9 -11
- package/tests/hydration/compiled/server/return.js +11 -13
- package/tests/hydration/compiled/server/switch.js +4 -6
- package/tests/hydration/components/events.ripple +8 -9
- package/tests/hydration/components/for.ripple +20 -21
- package/tests/hydration/components/head.ripple +6 -8
- package/tests/hydration/components/hmr.ripple +1 -2
- package/tests/hydration/components/html.ripple +1 -3
- package/tests/hydration/components/if-children.ripple +7 -8
- package/tests/hydration/components/if.ripple +5 -6
- package/tests/hydration/components/mixed-control-flow.ripple +4 -6
- package/tests/hydration/components/portal.ripple +1 -1
- package/tests/hydration/components/reactivity.ripple +9 -10
- package/tests/hydration/components/return.ripple +11 -12
- package/tests/hydration/components/switch.ripple +6 -8
- package/tests/server/await.test.ripple +2 -2
- package/tests/server/basic.attributes.test.ripple +19 -21
- package/tests/server/basic.components.test.ripple +13 -7
- package/tests/server/basic.test.ripple +20 -21
- package/tests/server/compiler.test.ripple +5 -5
- package/tests/server/composite.props.test.ripple +6 -7
- package/tests/server/composite.test.ripple +4 -4
- package/tests/server/context.test.ripple +1 -3
- package/tests/server/dynamic-elements.test.ripple +24 -24
- package/tests/server/head.test.ripple +5 -7
- package/tests/server/style-identifier.test.ripple +16 -17
- package/types/index.d.ts +266 -62
- package/types/server.d.ts +6 -6
|
@@ -17,7 +17,17 @@ export {
|
|
|
17
17
|
set_selected,
|
|
18
18
|
} from './render.js';
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export {
|
|
21
|
+
render,
|
|
22
|
+
render_spread,
|
|
23
|
+
async,
|
|
24
|
+
ref,
|
|
25
|
+
branch,
|
|
26
|
+
destroy_block,
|
|
27
|
+
move_block,
|
|
28
|
+
root,
|
|
29
|
+
user_effect as effect,
|
|
30
|
+
} from './blocks.js';
|
|
21
31
|
|
|
22
32
|
export { event, render_event, delegate } from './events.js';
|
|
23
33
|
|
|
@@ -41,6 +51,8 @@ export {
|
|
|
41
51
|
update_pre,
|
|
42
52
|
update_property,
|
|
43
53
|
update_pre_property,
|
|
54
|
+
track,
|
|
55
|
+
track_split,
|
|
44
56
|
push_component,
|
|
45
57
|
pop_component,
|
|
46
58
|
untrack,
|
|
@@ -68,13 +80,28 @@ export { switch_block as switch } from './switch.js';
|
|
|
68
80
|
|
|
69
81
|
export { template, append, text } from './template.js';
|
|
70
82
|
|
|
71
|
-
export {
|
|
83
|
+
export {
|
|
84
|
+
ripple_array,
|
|
85
|
+
ripple_array_from,
|
|
86
|
+
ripple_array_of,
|
|
87
|
+
ripple_array_from_async,
|
|
88
|
+
} from '../../array.js';
|
|
89
|
+
|
|
90
|
+
export { ripple_object } from '../../object.js';
|
|
91
|
+
|
|
92
|
+
export { ripple_map } from '../../map.js';
|
|
93
|
+
|
|
94
|
+
export { ripple_set } from '../../set.js';
|
|
95
|
+
|
|
96
|
+
export { ripple_date } from '../../date.js';
|
|
97
|
+
|
|
98
|
+
export { ripple_url } from '../../url.js';
|
|
72
99
|
|
|
73
|
-
export {
|
|
100
|
+
export { ripple_url_search_params } from '../../url-search-params.js';
|
|
74
101
|
|
|
75
|
-
export {
|
|
102
|
+
export { media_query } from '../../media-query.js';
|
|
76
103
|
|
|
77
|
-
export {
|
|
104
|
+
export { context } from './context.js';
|
|
78
105
|
|
|
79
106
|
export { head } from './head.js';
|
|
80
107
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** @import { Block } from '#client' */
|
|
2
2
|
|
|
3
3
|
import { destroy_block, ref } from './blocks.js';
|
|
4
|
-
import { REF_PROP } from './constants.js';
|
|
4
|
+
import { DESTROYED, REF_PROP } from './constants.js';
|
|
5
5
|
import {
|
|
6
6
|
get_descriptors,
|
|
7
7
|
get_own_property_symbols,
|
|
8
8
|
get_prototype_of,
|
|
9
|
-
|
|
9
|
+
is_ripple_object,
|
|
10
10
|
} from './utils.js';
|
|
11
11
|
import { event } from './events.js';
|
|
12
12
|
import { get_attribute_event_name, is_event_attribute } from '../../../utils/events.js';
|
|
@@ -252,6 +252,9 @@ export function apply_element_spread(element, fn) {
|
|
|
252
252
|
/** @type {Record<string | symbol, (() => void) | undefined>} */
|
|
253
253
|
var remove_listeners = {};
|
|
254
254
|
|
|
255
|
+
/** @type {Record<symbol, any>} */
|
|
256
|
+
var prev_symbols = {};
|
|
257
|
+
|
|
255
258
|
return () => {
|
|
256
259
|
var next = fn();
|
|
257
260
|
|
|
@@ -262,19 +265,28 @@ export function apply_element_spread(element, fn) {
|
|
|
262
265
|
}
|
|
263
266
|
}
|
|
264
267
|
|
|
268
|
+
/** @type {Record<symbol, any>} */
|
|
269
|
+
var current_symbols = {};
|
|
270
|
+
|
|
265
271
|
for (const symbol of get_own_property_symbols(next)) {
|
|
266
272
|
var ref_fn = next[symbol];
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
current_symbols[symbol] = ref_fn;
|
|
274
|
+
|
|
275
|
+
if (
|
|
276
|
+
symbol.description === REF_PROP &&
|
|
277
|
+
(!(symbol in prev_symbols) ||
|
|
278
|
+
ref_fn !== prev_symbols[symbol] ||
|
|
279
|
+
(effects[symbol] && (effects[symbol].f & DESTROYED) !== 0))
|
|
280
|
+
) {
|
|
281
|
+
if (effects[symbol] && (effects[symbol].f & DESTROYED) === 0) {
|
|
270
282
|
destroy_block(effects[symbol]);
|
|
271
283
|
}
|
|
272
284
|
effects[symbol] = ref(element, () => ref_fn);
|
|
273
285
|
}
|
|
274
|
-
|
|
275
|
-
next[symbol] = ref_fn;
|
|
276
286
|
}
|
|
277
287
|
|
|
288
|
+
prev_symbols = current_symbols;
|
|
289
|
+
|
|
278
290
|
for (let key in remove_listeners) {
|
|
279
291
|
// Remove event listeners that are no longer present
|
|
280
292
|
if (!(key in next) && remove_listeners[key]) {
|
|
@@ -298,7 +310,7 @@ export function apply_element_spread(element, fn) {
|
|
|
298
310
|
if (key === 'children') continue;
|
|
299
311
|
|
|
300
312
|
let value = next[key];
|
|
301
|
-
if (
|
|
313
|
+
if (is_ripple_object(value)) {
|
|
302
314
|
value = get(value);
|
|
303
315
|
}
|
|
304
316
|
current[key] = value;
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
get_descriptor,
|
|
36
36
|
get_own_property_symbols,
|
|
37
37
|
is_array,
|
|
38
|
-
|
|
38
|
+
is_ripple_object,
|
|
39
39
|
object_keys,
|
|
40
40
|
} from './utils.js';
|
|
41
41
|
|
|
@@ -363,7 +363,7 @@ export function derived(fn, block, get, set) {
|
|
|
363
363
|
* @returns {Tracked | Derived}
|
|
364
364
|
*/
|
|
365
365
|
export function track(v, get, set, b) {
|
|
366
|
-
if (
|
|
366
|
+
if (is_ripple_object(v)) {
|
|
367
367
|
return v;
|
|
368
368
|
}
|
|
369
369
|
if (b === null) {
|
|
@@ -383,7 +383,7 @@ export function track(v, get, set, b) {
|
|
|
383
383
|
* @returns {Tracked[]}
|
|
384
384
|
*/
|
|
385
385
|
export function track_split(v, l, b) {
|
|
386
|
-
var is_tracked =
|
|
386
|
+
var is_tracked = is_ripple_object(v);
|
|
387
387
|
|
|
388
388
|
if (is_tracked || typeof v !== 'object' || v === null || is_array(v)) {
|
|
389
389
|
throw new TypeError('Invalid value: expected a non-tracked object');
|
|
@@ -401,7 +401,7 @@ export function track_split(v, l, b) {
|
|
|
401
401
|
key = l[i];
|
|
402
402
|
|
|
403
403
|
if (props.includes(key)) {
|
|
404
|
-
if (
|
|
404
|
+
if (is_ripple_object(v[key])) {
|
|
405
405
|
t = v[key];
|
|
406
406
|
} else {
|
|
407
407
|
t = tracked(undefined, b);
|
|
@@ -702,7 +702,9 @@ function flush_microtasks() {
|
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
|
|
705
|
+
flush_count++;
|
|
705
706
|
if (flush_count > 1001) {
|
|
707
|
+
flush_count = 0;
|
|
706
708
|
return;
|
|
707
709
|
}
|
|
708
710
|
var previous_queued_root_blocks = queued_root_blocks;
|
|
@@ -800,7 +802,7 @@ export function get_derived(computed) {
|
|
|
800
802
|
*/
|
|
801
803
|
export function get(tracked) {
|
|
802
804
|
// reflect back the value if it's not boxed
|
|
803
|
-
if (!
|
|
805
|
+
if (!is_ripple_object(tracked)) {
|
|
804
806
|
return tracked;
|
|
805
807
|
}
|
|
806
808
|
|
|
@@ -844,7 +846,7 @@ export function public_set(tracked, value) {
|
|
|
844
846
|
export function set(tracked, value) {
|
|
845
847
|
if (!is_mutating_allowed) {
|
|
846
848
|
throw new Error(
|
|
847
|
-
'Assignments or updates to tracked values are not allowed during computed "track(() => ...)" evaluation',
|
|
849
|
+
'Assignments or updates to tracked values are not allowed during computed "#ripple.track(() => ...)" evaluation',
|
|
848
850
|
);
|
|
849
851
|
}
|
|
850
852
|
|
|
@@ -1313,7 +1315,7 @@ export async function maybe_tracked(v) {
|
|
|
1313
1315
|
var restore = capture();
|
|
1314
1316
|
let value;
|
|
1315
1317
|
|
|
1316
|
-
if (
|
|
1318
|
+
if (is_ripple_object(v)) {
|
|
1317
1319
|
if ((v.f & DERIVED) !== 0) {
|
|
1318
1320
|
value = await async_computed(v.fn, v.b);
|
|
1319
1321
|
} else {
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/** @import { Block } from '#client' */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
branch,
|
|
5
|
+
create_try_block,
|
|
6
|
+
destroy_block,
|
|
7
|
+
is_destroyed,
|
|
8
|
+
move_block,
|
|
9
|
+
resume_block,
|
|
10
|
+
} from './blocks.js';
|
|
4
11
|
import { TRY_BLOCK } from './constants.js';
|
|
5
12
|
import {
|
|
6
13
|
hydrate_next,
|
|
@@ -10,7 +17,7 @@ import {
|
|
|
10
17
|
set_hydrating,
|
|
11
18
|
skip_to_hydration_end,
|
|
12
19
|
} from './hydration.js';
|
|
13
|
-
import { get_next_sibling
|
|
20
|
+
import { get_next_sibling } from './operations.js';
|
|
14
21
|
import {
|
|
15
22
|
active_block,
|
|
16
23
|
active_component,
|
|
@@ -39,25 +46,7 @@ export function try_block(node, fn, catch_fn, pending_fn = null) {
|
|
|
39
46
|
var pending_count = 0;
|
|
40
47
|
/** @type {DocumentFragment | null} */
|
|
41
48
|
var offscreen_fragment = null;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {Block} block
|
|
45
|
-
* @param {DocumentFragment} fragment
|
|
46
|
-
* @returns {void}
|
|
47
|
-
*/
|
|
48
|
-
function move_block(block, fragment) {
|
|
49
|
-
var state = block.s;
|
|
50
|
-
if (state === null) return;
|
|
51
|
-
var node = state.start;
|
|
52
|
-
var end = state.end;
|
|
53
|
-
|
|
54
|
-
while (node !== null) {
|
|
55
|
-
var next = node === end ? null : next_sibling(node);
|
|
56
|
-
|
|
57
|
-
fragment.append(node);
|
|
58
|
-
node = next;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
49
|
+
var has_resolved = false;
|
|
61
50
|
|
|
62
51
|
function handle_await() {
|
|
63
52
|
if (pending_count++ === 0) {
|
|
@@ -65,7 +54,10 @@ export function try_block(node, fn, catch_fn, pending_fn = null) {
|
|
|
65
54
|
if (b !== null && suspended === null) {
|
|
66
55
|
suspended = b;
|
|
67
56
|
offscreen_fragment = document.createDocumentFragment();
|
|
68
|
-
|
|
57
|
+
// Only move content if promise has resolved before (re-suspension)
|
|
58
|
+
if (has_resolved) {
|
|
59
|
+
move_block(b, offscreen_fragment);
|
|
60
|
+
}
|
|
69
61
|
|
|
70
62
|
b = branch(() => {
|
|
71
63
|
/** @type {(anchor: Node) => void} */ (pending_fn)(anchor);
|
|
@@ -76,6 +68,7 @@ export function try_block(node, fn, catch_fn, pending_fn = null) {
|
|
|
76
68
|
|
|
77
69
|
return () => {
|
|
78
70
|
if (--pending_count === 0) {
|
|
71
|
+
has_resolved = true;
|
|
79
72
|
if (b !== null) {
|
|
80
73
|
destroy_block(b);
|
|
81
74
|
}
|
|
@@ -42,7 +42,7 @@ export function create_anchor() {
|
|
|
42
42
|
* @param {any} v - The object to check.
|
|
43
43
|
* @returns {boolean}
|
|
44
44
|
*/
|
|
45
|
-
export function
|
|
45
|
+
export function is_ripple_object(v) {
|
|
46
46
|
return typeof v === 'object' && v !== null && typeof (/** @type {any} */ (v).f) === 'number';
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { Readable } from 'stream';
|
|
7
7
|
import { DERIVED, UNINITIALIZED, TRACKED } from '../client/constants.js';
|
|
8
|
-
import {
|
|
8
|
+
import { is_ripple_object, get_descriptor, define_property, is_array } from '../client/utils.js';
|
|
9
9
|
import { escape } from '../../../utils/escaping.js';
|
|
10
10
|
import { is_boolean_attribute } from '../../../compiler/utils.js';
|
|
11
11
|
import { clsx } from 'clsx';
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
export { escape };
|
|
20
20
|
export { register_component_css as register_css } from './css-registry.js';
|
|
21
21
|
export { hash } from '../../../utils/hashing.js';
|
|
22
|
+
export { context } from './context.js';
|
|
22
23
|
|
|
23
24
|
/** @type {null | Component} */
|
|
24
25
|
export let active_component = null;
|
|
@@ -427,7 +428,7 @@ export function aborted() {
|
|
|
427
428
|
* @returns {any}
|
|
428
429
|
*/
|
|
429
430
|
export function get(tracked) {
|
|
430
|
-
if (!
|
|
431
|
+
if (!is_ripple_object(tracked)) {
|
|
431
432
|
return tracked;
|
|
432
433
|
}
|
|
433
434
|
|
|
@@ -590,7 +591,7 @@ export function spread_attrs(attrs, css_hash) {
|
|
|
590
591
|
|
|
591
592
|
if (typeof value === 'function') continue;
|
|
592
593
|
|
|
593
|
-
if (
|
|
594
|
+
if (is_ripple_object(value)) {
|
|
594
595
|
value = get(value);
|
|
595
596
|
}
|
|
596
597
|
|
|
@@ -628,7 +629,7 @@ function tracked(v, get, set) {
|
|
|
628
629
|
* @returns {Tracked | Derived}
|
|
629
630
|
*/
|
|
630
631
|
export function track(v, get, set) {
|
|
631
|
-
var is_tracked =
|
|
632
|
+
var is_tracked = is_ripple_object(v);
|
|
632
633
|
|
|
633
634
|
if (is_tracked) {
|
|
634
635
|
return v;
|
|
@@ -655,7 +656,7 @@ export function track(v, get, set) {
|
|
|
655
656
|
* @returns {Tracked[]}
|
|
656
657
|
*/
|
|
657
658
|
export function track_split(v, l) {
|
|
658
|
-
var is_tracked =
|
|
659
|
+
var is_tracked = is_ripple_object(v);
|
|
659
660
|
|
|
660
661
|
if (is_tracked || typeof v !== 'object' || v === null || is_array(v)) {
|
|
661
662
|
throw new TypeError('Invalid value: expected a non-tracked object');
|
|
@@ -673,7 +674,7 @@ export function track_split(v, l) {
|
|
|
673
674
|
key = l[i];
|
|
674
675
|
|
|
675
676
|
if (props.includes(key)) {
|
|
676
|
-
if (
|
|
677
|
+
if (is_ripple_object(v[key])) {
|
|
677
678
|
t = v[key];
|
|
678
679
|
} else {
|
|
679
680
|
t = tracked(undefined);
|
|
@@ -699,3 +700,95 @@ export function track_split(v, l) {
|
|
|
699
700
|
|
|
700
701
|
return out;
|
|
701
702
|
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* @param {any} _
|
|
706
|
+
* @param {ConstructorParameters<typeof URL>} params
|
|
707
|
+
* @returns {URL}
|
|
708
|
+
*/
|
|
709
|
+
export function ripple_url(_, ...params) {
|
|
710
|
+
return new URL(...params);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* @param {any} _
|
|
715
|
+
* @param {ConstructorParameters<typeof URLSearchParams>} params
|
|
716
|
+
* @returns {URLSearchParams}
|
|
717
|
+
*/
|
|
718
|
+
export function ripple_url_search_params(_, ...params) {
|
|
719
|
+
return new URLSearchParams(...params);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* @param {ConstructorParameters<typeof Date>} params
|
|
724
|
+
* @returns {Date}
|
|
725
|
+
*/
|
|
726
|
+
export function ripple_date(...params) {
|
|
727
|
+
return new Date(...params);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* @param {string} query
|
|
732
|
+
* @param {boolean} [matches]
|
|
733
|
+
* @returns {boolean}
|
|
734
|
+
*/
|
|
735
|
+
export function media_query(query, matches = false) {
|
|
736
|
+
void query;
|
|
737
|
+
return matches;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* @param {() => void} _fn
|
|
742
|
+
* @returns {void}
|
|
743
|
+
*/
|
|
744
|
+
export function effect(_fn) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @template T
|
|
750
|
+
* @param {...T} elements
|
|
751
|
+
* @returns {T[]}
|
|
752
|
+
*/
|
|
753
|
+
export function ripple_array(...elements) {
|
|
754
|
+
return new Array(...elements);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* @template T
|
|
759
|
+
* @param {ArrayLike<T> | Iterable<T>} arrayLike
|
|
760
|
+
* @param {(v: T, k: number) => any | undefined} [map_fn]
|
|
761
|
+
* @param {any} [thisArg]
|
|
762
|
+
* @returns {T[]}
|
|
763
|
+
*/
|
|
764
|
+
ripple_array.from = function (arrayLike, map_fn, thisArg) {
|
|
765
|
+
return map_fn ? Array.from(arrayLike, map_fn, thisArg) : Array.from(arrayLike);
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* @template T
|
|
770
|
+
* @param {...T} items
|
|
771
|
+
* @returns {T[]}
|
|
772
|
+
*/
|
|
773
|
+
ripple_array.of = function (...items) {
|
|
774
|
+
return Array.of(...items);
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* @template T
|
|
779
|
+
* @param {ArrayLike<T> | Iterable<T>} arrayLike
|
|
780
|
+
* @param {(v: T, k: number) => any | undefined} [map_fn]
|
|
781
|
+
* @param {any} [thisArg]
|
|
782
|
+
* @returns {Promise<T[]>}
|
|
783
|
+
*/
|
|
784
|
+
ripple_array.from_async = async function (arrayLike, map_fn, thisArg) {
|
|
785
|
+
return map_fn ? Array.fromAsync(arrayLike, map_fn, thisArg) : Array.fromAsync(arrayLike);
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* @param {object} obj
|
|
790
|
+
* @returns {object}
|
|
791
|
+
*/
|
|
792
|
+
export function ripple_object(obj) {
|
|
793
|
+
return obj;
|
|
794
|
+
}
|
package/src/runtime/map.js
CHANGED
|
@@ -8,9 +8,9 @@ let init = false;
|
|
|
8
8
|
/**
|
|
9
9
|
* @template K, V
|
|
10
10
|
* @extends {Map<K, V>}
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {RippleMap<K, V>}
|
|
12
12
|
*/
|
|
13
|
-
export class
|
|
13
|
+
export class RippleMap extends Map {
|
|
14
14
|
/** @type {Tracked} */
|
|
15
15
|
#tracked_size;
|
|
16
16
|
/** @type {Map<K, Tracked>} */
|
|
@@ -45,7 +45,7 @@ export class TrackedMap extends Map {
|
|
|
45
45
|
* @returns {void}
|
|
46
46
|
*/
|
|
47
47
|
#init() {
|
|
48
|
-
var proto =
|
|
48
|
+
var proto = RippleMap.prototype;
|
|
49
49
|
var map_proto = Map.prototype;
|
|
50
50
|
|
|
51
51
|
for (const method of introspect_methods) {
|
|
@@ -197,9 +197,9 @@ export class TrackedMap extends Map {
|
|
|
197
197
|
/**
|
|
198
198
|
* @template K, V
|
|
199
199
|
* @param {Block} block
|
|
200
|
-
* @param {
|
|
201
|
-
* @returns {
|
|
200
|
+
* @param {Iterable<readonly [K, V]>} [iterable]
|
|
201
|
+
* @returns {RippleMap<K, V>}
|
|
202
202
|
*/
|
|
203
|
-
export function
|
|
204
|
-
return with_scope(block, () => new
|
|
203
|
+
export function ripple_map(block, iterable) {
|
|
204
|
+
return with_scope(block, () => new RippleMap(iterable));
|
|
205
205
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { on } from './internal/client/events.js';
|
|
2
|
-
import { get, safe_scope, set, tracked } from './internal/client/index.js';
|
|
2
|
+
import { get, safe_scope, set, tracked, with_scope } from './internal/client/index.js';
|
|
3
3
|
import { ReactiveValue } from './reactive-value.js';
|
|
4
4
|
|
|
5
5
|
const parenthesis_regex = /\(.+\)/;
|
|
@@ -43,3 +43,12 @@ export function MediaQuery(query, fallback) {
|
|
|
43
43
|
),
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {import('#client').Block} block
|
|
49
|
+
* @param {string} query
|
|
50
|
+
* @param {boolean | undefined} [fallback]
|
|
51
|
+
*/
|
|
52
|
+
export function media_query(block, query, fallback) {
|
|
53
|
+
return with_scope(block, () => new MediaQuery(query, fallback));
|
|
54
|
+
}
|
package/src/runtime/object.js
CHANGED
|
@@ -6,24 +6,24 @@ import { object_proxy } from './proxy.js';
|
|
|
6
6
|
* @template {object} T
|
|
7
7
|
* @constructor
|
|
8
8
|
* @param {T} obj
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {RippleObject<T>}
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
11
|
+
export function RippleObject(obj) {
|
|
12
12
|
if (!new.target) {
|
|
13
|
-
throw new Error("
|
|
13
|
+
throw new Error("RippleObject must be called with 'new'");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
var block = safe_scope();
|
|
17
17
|
|
|
18
|
-
return
|
|
18
|
+
return ripple_object(block, obj);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @template {object} T
|
|
23
23
|
* @param {T} obj
|
|
24
24
|
* @param {Block} block
|
|
25
|
-
* @returns {
|
|
25
|
+
* @returns {RippleObject<T>}
|
|
26
26
|
*/
|
|
27
|
-
export function
|
|
27
|
+
export function ripple_object(block, obj) {
|
|
28
28
|
return object_proxy(obj, block);
|
|
29
29
|
}
|
package/src/runtime/proxy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @import { Block, Tracked } from '#client' */
|
|
2
|
-
/** @import {
|
|
3
|
-
/** @import {
|
|
2
|
+
/** @import { RippleArray } from './array.js' */
|
|
3
|
+
/** @import { RippleObject } from './object.js' */
|
|
4
4
|
|
|
5
5
|
import { get, set, tracked } from './internal/client/runtime.js';
|
|
6
6
|
import {
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
* @template T
|
|
22
22
|
* @param {T[] | Record<PropertyKey, any>} value
|
|
23
23
|
* @param {Block} block
|
|
24
|
-
* @returns {
|
|
24
|
+
* @returns {RippleArray<T> | RippleObject<T>}
|
|
25
25
|
*/
|
|
26
26
|
export function proxy(value, block) {
|
|
27
27
|
// if non-proxyable, or is already a proxy, return `value`
|
|
@@ -154,7 +154,7 @@ export function proxy(value, block) {
|
|
|
154
154
|
|
|
155
155
|
setPrototypeOf() {
|
|
156
156
|
throw new Error(
|
|
157
|
-
`Cannot set prototype of ${is_proxied_array ? '\`
|
|
157
|
+
`Cannot set prototype of ${is_proxied_array ? '\`RippleArray\`' : '\`RippleObject\`'}`,
|
|
158
158
|
);
|
|
159
159
|
},
|
|
160
160
|
|
|
@@ -277,7 +277,7 @@ export function proxy(value, block) {
|
|
|
277
277
|
* from_static?: boolean,
|
|
278
278
|
* use_array?: boolean
|
|
279
279
|
* }} params
|
|
280
|
-
* @returns {
|
|
280
|
+
* @returns {RippleArray<T>}
|
|
281
281
|
*/
|
|
282
282
|
export function array_proxy({ elements, block, from_static = false, use_array = false }) {
|
|
283
283
|
var arr;
|
|
@@ -302,7 +302,7 @@ export function array_proxy({ elements, block, from_static = false, use_array =
|
|
|
302
302
|
* @template {object} T
|
|
303
303
|
* @param {T} obj
|
|
304
304
|
* @param {Block} block
|
|
305
|
-
* @returns {
|
|
305
|
+
* @returns {RippleObject<T>}
|
|
306
306
|
*/
|
|
307
307
|
export function object_proxy(obj, block) {
|
|
308
308
|
return proxy(obj, block);
|
package/src/runtime/set.js
CHANGED
|
@@ -12,9 +12,9 @@ let init = false;
|
|
|
12
12
|
/**
|
|
13
13
|
* @template T
|
|
14
14
|
* @extends {Set<T>}
|
|
15
|
-
* @returns {
|
|
15
|
+
* @returns {RippleSet<T>}
|
|
16
16
|
*/
|
|
17
|
-
export class
|
|
17
|
+
export class RippleSet extends Set {
|
|
18
18
|
/** @type {Tracked} */
|
|
19
19
|
#tracked_size;
|
|
20
20
|
/** @type {Map<T, Tracked>} */
|
|
@@ -49,7 +49,7 @@ export class TrackedSet extends Set {
|
|
|
49
49
|
* @returns {void}
|
|
50
50
|
*/
|
|
51
51
|
#init() {
|
|
52
|
-
var proto =
|
|
52
|
+
var proto = RippleSet.prototype;
|
|
53
53
|
var set_proto = Set.prototype;
|
|
54
54
|
|
|
55
55
|
for (const method of introspect_methods) {
|
|
@@ -75,7 +75,7 @@ export class TrackedSet extends Set {
|
|
|
75
75
|
) {
|
|
76
76
|
this.size;
|
|
77
77
|
|
|
78
|
-
if (other instanceof
|
|
78
|
+
if (other instanceof RippleSet) {
|
|
79
79
|
other.size;
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -94,11 +94,11 @@ export class TrackedSet extends Set {
|
|
|
94
94
|
) {
|
|
95
95
|
this.size;
|
|
96
96
|
|
|
97
|
-
if (other instanceof
|
|
97
|
+
if (other instanceof RippleSet) {
|
|
98
98
|
other.size;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
return new
|
|
101
|
+
return new RippleSet(/** @type {any} */ (set_proto)[method].apply(this, [other, ...v]));
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -200,11 +200,11 @@ export class TrackedSet extends Set {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
|
-
* @template
|
|
203
|
+
* @template T
|
|
204
204
|
* @param {Block} block
|
|
205
|
-
* @param {
|
|
206
|
-
* @returns {
|
|
205
|
+
* @param {Iterable<T>} [iterable]
|
|
206
|
+
* @returns {RippleSet<T>}
|
|
207
207
|
*/
|
|
208
|
-
export function
|
|
209
|
-
return with_scope(block, () => new
|
|
208
|
+
export function ripple_set(block, iterable) {
|
|
209
|
+
return with_scope(block, () => new RippleSet(iterable));
|
|
210
210
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { get, increment, safe_scope, tracked } from './internal/client/runtime.js';
|
|
1
|
+
import { get, increment, safe_scope, tracked, with_scope } from './internal/client/runtime.js';
|
|
2
2
|
import { get_current_url } from './url.js';
|
|
3
3
|
|
|
4
4
|
export const REPLACE = Symbol();
|
|
5
5
|
|
|
6
|
-
export class
|
|
6
|
+
export class RippleURLSearchParams extends URLSearchParams {
|
|
7
7
|
#block = safe_scope();
|
|
8
8
|
#version = tracked(0, this.#block);
|
|
9
9
|
#url = get_current_url();
|
|
@@ -144,3 +144,14 @@ export class TrackedURLSearchParams extends URLSearchParams {
|
|
|
144
144
|
return super.size;
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {import('#client').Block} block
|
|
150
|
+
* @param {ConstructorParameters<typeof URLSearchParams>} params
|
|
151
|
+
* @returns {RippleURLSearchParams}
|
|
152
|
+
*/
|
|
153
|
+
export function ripple_url_search_params(block, ...params) {
|
|
154
|
+
return with_scope(block, () => {
|
|
155
|
+
return new RippleURLSearchParams(...params);
|
|
156
|
+
});
|
|
157
|
+
}
|