svelte 5.58.1 → 5.59.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/compiler/index.js +1 -1
- package/package.json +19 -1
- package/renderer.d.ts +1 -0
- package/src/compiler/errors.js +19 -0
- package/src/compiler/index.js +37 -2
- package/src/compiler/migrate/index.js +2 -1
- package/src/compiler/phases/1-parse/read/options.js +20 -0
- package/src/compiler/phases/2-analyze/index.js +21 -2
- package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/Attribute.js +6 -2
- package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -0
- package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +2 -1
- package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/OnDirective.js +6 -0
- package/src/compiler/phases/2-analyze/visitors/RegularElement.js +13 -6
- package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +5 -1
- package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/Text.js +3 -1
- package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +6 -0
- package/src/compiler/phases/2-analyze/visitors/shared/element.js +3 -2
- package/src/compiler/phases/3-transform/client/transform-client.js +68 -1
- package/src/compiler/phases/3-transform/client/transform-template/index.js +4 -3
- package/src/compiler/phases/3-transform/client/transform-template/template.js +1 -1
- package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +23 -13
- package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +13 -1
- package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +11 -1
- package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +8 -5
- package/src/compiler/phases/3-transform/client/visitors/shared/component.js +17 -8
- package/src/compiler/phases/3-transform/client/visitors/shared/element.js +4 -3
- package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +7 -1
- package/src/compiler/phases/3-transform/server/transform-server.js +14 -1
- package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +8 -4
- package/src/compiler/state.js +12 -0
- package/src/compiler/utils/builders.js +2 -2
- package/src/compiler/validate-options.js +47 -1
- package/src/internal/client/constants.js +7 -0
- package/src/internal/client/custom-renderer/containers.js +213 -0
- package/src/internal/client/custom-renderer/cross.js +145 -0
- package/src/internal/client/custom-renderer/index.js +28 -0
- package/src/internal/client/custom-renderer/state.js +59 -0
- package/src/internal/client/dev/css.js +3 -1
- package/src/internal/client/dev/elements.js +9 -7
- package/src/internal/client/dev/validation.js +2 -1
- package/src/internal/client/dom/blocks/await.js +3 -2
- package/src/internal/client/dom/blocks/boundary.js +41 -24
- package/src/internal/client/dom/blocks/branches.js +83 -57
- package/src/internal/client/dom/blocks/css-props.js +31 -3
- package/src/internal/client/dom/blocks/each.js +78 -32
- package/src/internal/client/dom/blocks/html.js +19 -13
- package/src/internal/client/dom/blocks/slot.js +3 -3
- package/src/internal/client/dom/blocks/snippet.js +52 -3
- package/src/internal/client/dom/blocks/svelte-element.js +17 -6
- package/src/internal/client/dom/blocks/svelte-head.js +13 -4
- package/src/internal/client/dom/css.js +4 -4
- package/src/internal/client/dom/elements/attributes.js +89 -50
- package/src/internal/client/dom/elements/bindings/select.js +11 -2
- package/src/internal/client/dom/elements/class.js +16 -5
- package/src/internal/client/dom/elements/events.js +126 -19
- package/src/internal/client/dom/elements/misc.js +3 -2
- package/src/internal/client/dom/elements/style.js +17 -6
- package/src/internal/client/dom/hydration.js +6 -6
- package/src/internal/client/dom/operations.js +433 -11
- package/src/internal/client/dom/reconciler.js +2 -2
- package/src/internal/client/dom/template.js +94 -66
- package/src/internal/client/errors.js +67 -0
- package/src/internal/client/index.js +9 -1
- package/src/internal/client/reactivity/async.js +10 -0
- package/src/internal/client/reactivity/batch.js +22 -1
- package/src/internal/client/reactivity/effects.js +44 -27
- package/src/internal/client/render.js +50 -88
- package/src/internal/client/runtime.js +6 -1
- package/src/internal/disclose-version.js +1 -1
- package/src/internal/flags/custom-renderer-server.js +10 -0
- package/src/internal/flags/custom-renderer.js +3 -0
- package/src/internal/flags/index.js +6 -0
- package/src/internal/init-operations.js +3 -0
- package/src/internal/shared/errors.js +20 -0
- package/src/legacy/legacy-client.js +6 -2
- package/src/renderer/index-server.js +18 -0
- package/src/renderer/index.js +2 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +244 -24
- package/types/index.d.ts.map +10 -1
|
@@ -7,7 +7,16 @@ import {
|
|
|
7
7
|
set_hydrate_node,
|
|
8
8
|
set_hydrating
|
|
9
9
|
} from '../hydration.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
create_element,
|
|
12
|
+
create_text,
|
|
13
|
+
get_first_child,
|
|
14
|
+
append_child,
|
|
15
|
+
create_comment,
|
|
16
|
+
insert_before,
|
|
17
|
+
node_type,
|
|
18
|
+
remove_child
|
|
19
|
+
} from '../operations.js';
|
|
11
20
|
import { block, teardown } from '../../reactivity/effects.js';
|
|
12
21
|
import { set_should_intro } from '../../render.js';
|
|
13
22
|
import { active_effect } from '../../runtime.js';
|
|
@@ -40,7 +49,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
|
|
|
40
49
|
/** @type {null | Element} */
|
|
41
50
|
var element = null;
|
|
42
51
|
|
|
43
|
-
if (hydrating && hydrate_node
|
|
52
|
+
if (hydrating && node_type(hydrate_node) === ELEMENT_NODE) {
|
|
44
53
|
element = /** @type {Element} */ (hydrate_node);
|
|
45
54
|
hydrate_next();
|
|
46
55
|
}
|
|
@@ -94,14 +103,14 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
|
|
|
94
103
|
|
|
95
104
|
if (hydrating && is_raw_text_element(next_tag)) {
|
|
96
105
|
// prevent hydration glitches (code just below expects an anchor)
|
|
97
|
-
element
|
|
106
|
+
append_child(element, (tmp_comment = create_comment('')));
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
// If hydrating, use the existing ssr comment as the anchor so that the
|
|
101
110
|
// inner open and close methods can pick up the existing nodes correctly
|
|
102
111
|
var child_anchor = hydrating
|
|
103
112
|
? get_first_child(element)
|
|
104
|
-
: element
|
|
113
|
+
: /** @type {Text} */ (append_child(element, create_text()));
|
|
105
114
|
|
|
106
115
|
if (hydrating) {
|
|
107
116
|
if (child_anchor === null) {
|
|
@@ -118,7 +127,9 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
|
|
|
118
127
|
// contains children, it's a user error (which is warned on elsewhere)
|
|
119
128
|
// and the DOM will be silently discarded
|
|
120
129
|
render_fn(element, child_anchor);
|
|
121
|
-
tmp_comment
|
|
130
|
+
if (tmp_comment) {
|
|
131
|
+
remove_child(element, tmp_comment);
|
|
132
|
+
}
|
|
122
133
|
set_animation_effect_override(null);
|
|
123
134
|
}
|
|
124
135
|
|
|
@@ -126,7 +137,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
|
|
|
126
137
|
/** @type {Effect & { nodes: EffectNodes }} */ (active_effect).nodes.end = element;
|
|
127
138
|
|
|
128
139
|
// we only move the node if we are not hydrating since a claimed element is already in place
|
|
129
|
-
if (!is_hydrating) anchor
|
|
140
|
+
if (!is_hydrating) insert_before(anchor, element);
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
if (hydrating) {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/** @import { TemplateNode } from '#client' */
|
|
2
2
|
import { hydrate_node, hydrating, set_hydrate_node, set_hydrating } from '../hydration.js';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
create_text,
|
|
6
|
+
get_first_child,
|
|
7
|
+
get_next_sibling,
|
|
8
|
+
remove_node,
|
|
9
|
+
append_child,
|
|
10
|
+
node_type,
|
|
11
|
+
get_node_value
|
|
12
|
+
} from '../operations.js';
|
|
4
13
|
import { block, branch } from '../../reactivity/effects.js';
|
|
5
14
|
import { COMMENT_NODE, HEAD_EFFECT } from '#client/constants';
|
|
6
15
|
|
|
@@ -27,7 +36,7 @@ export function head(hash, render_fn) {
|
|
|
27
36
|
// rendered in an arbitrary order — find one corresponding to this component
|
|
28
37
|
while (
|
|
29
38
|
head_anchor !== null &&
|
|
30
|
-
(head_anchor
|
|
39
|
+
(node_type(head_anchor) !== COMMENT_NODE || get_node_value(head_anchor) !== hash)
|
|
31
40
|
) {
|
|
32
41
|
head_anchor = get_next_sibling(head_anchor);
|
|
33
42
|
}
|
|
@@ -38,14 +47,14 @@ export function head(hash, render_fn) {
|
|
|
38
47
|
set_hydrating(false);
|
|
39
48
|
} else {
|
|
40
49
|
var start = /** @type {TemplateNode} */ (get_next_sibling(head_anchor));
|
|
41
|
-
head_anchor
|
|
50
|
+
remove_node(/** @type {ChildNode} */ (head_anchor)); // in case this component is repeated
|
|
42
51
|
|
|
43
52
|
set_hydrate_node(start);
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
if (!hydrating) {
|
|
48
|
-
anchor = document.head
|
|
57
|
+
anchor = /** @type {Comment | Text} */ (append_child(document.head, create_text()));
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
try {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
2
|
import { register_style } from '../dev/css.js';
|
|
3
3
|
import { effect } from '../reactivity/effects.js';
|
|
4
|
-
import { create_element } from './operations.js';
|
|
4
|
+
import { create_element, append_child, set_text_content } from './operations.js';
|
|
5
5
|
import { active_effect } from '../runtime.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -23,12 +23,12 @@ export function append_styles(anchor, css) {
|
|
|
23
23
|
|
|
24
24
|
// Always querying the DOM is roughly the same perf as additionally checking for presence in a map first assuming
|
|
25
25
|
// that you'll get cache hits half of the time, so we just always query the dom for simplicity and code savings.
|
|
26
|
-
if (!target.querySelector('#' + css.hash)) {
|
|
26
|
+
if (!(/** @type {Element} */ (target).querySelector('#' + css.hash))) {
|
|
27
27
|
const style = create_element('style');
|
|
28
28
|
style.id = css.hash;
|
|
29
|
-
style
|
|
29
|
+
set_text_content(style, css.code);
|
|
30
30
|
|
|
31
|
-
target
|
|
31
|
+
append_child(target, style);
|
|
32
32
|
|
|
33
33
|
if (DEV) {
|
|
34
34
|
register_style(css.hash, style);
|
|
@@ -34,6 +34,19 @@ import {
|
|
|
34
34
|
set_selected
|
|
35
35
|
} from './bindings/select.js';
|
|
36
36
|
import { flatten } from '../../reactivity/async.js';
|
|
37
|
+
import {
|
|
38
|
+
has_attribute,
|
|
39
|
+
get_attribute,
|
|
40
|
+
remove_attribute,
|
|
41
|
+
set_attribute as set_attribute_op,
|
|
42
|
+
remove_event_listener,
|
|
43
|
+
node_name,
|
|
44
|
+
set_element_value,
|
|
45
|
+
set_element_checked,
|
|
46
|
+
set_element_default_value,
|
|
47
|
+
set_element_default_checked
|
|
48
|
+
} from '../operations.js';
|
|
49
|
+
import { current_renderer } from '../../custom-renderer/state.js';
|
|
37
50
|
|
|
38
51
|
export const CLASS = Symbol('class');
|
|
39
52
|
export const STYLE = Symbol('style');
|
|
@@ -56,6 +69,8 @@ const PROGRESS_TAG = IS_XHTML ? 'progress' : 'PROGRESS';
|
|
|
56
69
|
export function remove_input_defaults(input) {
|
|
57
70
|
if (!hydrating) return;
|
|
58
71
|
|
|
72
|
+
// we should be safe here from custom renderers as this only run during hydration
|
|
73
|
+
|
|
59
74
|
var already_removed = false;
|
|
60
75
|
|
|
61
76
|
// We try and remove the default attributes later, rather than sync during hydration.
|
|
@@ -67,13 +82,13 @@ export function remove_input_defaults(input) {
|
|
|
67
82
|
already_removed = true;
|
|
68
83
|
|
|
69
84
|
// Remove the attributes but preserve the values
|
|
70
|
-
if (input
|
|
85
|
+
if (has_attribute(input, 'value')) {
|
|
71
86
|
var value = input.value;
|
|
72
87
|
set_attribute(input, 'value', null);
|
|
73
88
|
input.value = value;
|
|
74
89
|
}
|
|
75
90
|
|
|
76
|
-
if (input
|
|
91
|
+
if (has_attribute(input, 'checked')) {
|
|
77
92
|
var checked = input.checked;
|
|
78
93
|
set_attribute(input, 'checked', null);
|
|
79
94
|
input.checked = checked;
|
|
@@ -97,15 +112,15 @@ export function set_value(element, value) {
|
|
|
97
112
|
(attributes.value =
|
|
98
113
|
// treat null and undefined the same for the initial value
|
|
99
114
|
value ?? undefined) ||
|
|
100
|
-
// @ts-expect-error
|
|
101
115
|
// `progress` elements always need their value set when it's `0`
|
|
102
|
-
(
|
|
116
|
+
(current_renderer == null &&
|
|
117
|
+
/** @type {any} */ (element).value === value &&
|
|
118
|
+
(value !== 0 || node_name(element) !== PROGRESS_TAG))
|
|
103
119
|
) {
|
|
104
120
|
return;
|
|
105
121
|
}
|
|
106
122
|
|
|
107
|
-
|
|
108
|
-
element.value = value ?? '';
|
|
123
|
+
set_element_value(element, value);
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
/**
|
|
@@ -124,8 +139,7 @@ export function set_checked(element, checked) {
|
|
|
124
139
|
return;
|
|
125
140
|
}
|
|
126
141
|
|
|
127
|
-
|
|
128
|
-
element.checked = checked;
|
|
142
|
+
set_element_checked(element, checked);
|
|
129
143
|
}
|
|
130
144
|
|
|
131
145
|
/**
|
|
@@ -134,9 +148,7 @@ export function set_checked(element, checked) {
|
|
|
134
148
|
* @param {boolean} checked
|
|
135
149
|
*/
|
|
136
150
|
export function set_default_checked(element, checked) {
|
|
137
|
-
|
|
138
|
-
element.defaultChecked = checked;
|
|
139
|
-
element.checked = existing_value;
|
|
151
|
+
set_element_default_checked(element, checked);
|
|
140
152
|
}
|
|
141
153
|
|
|
142
154
|
/**
|
|
@@ -145,9 +157,7 @@ export function set_default_checked(element, checked) {
|
|
|
145
157
|
* @param {string} value
|
|
146
158
|
*/
|
|
147
159
|
export function set_default_value(element, value) {
|
|
148
|
-
|
|
149
|
-
element.defaultValue = value;
|
|
150
|
-
element.value = existing_value;
|
|
160
|
+
set_element_default_value(element, value);
|
|
151
161
|
}
|
|
152
162
|
|
|
153
163
|
/**
|
|
@@ -160,12 +170,12 @@ export function set_attribute(element, attribute, value, skip_warning) {
|
|
|
160
170
|
var attributes = get_attributes(element);
|
|
161
171
|
|
|
162
172
|
if (hydrating) {
|
|
163
|
-
attributes[attribute] = element
|
|
173
|
+
attributes[attribute] = get_attribute(element, attribute);
|
|
164
174
|
|
|
165
175
|
if (
|
|
166
176
|
attribute === 'src' ||
|
|
167
177
|
attribute === 'srcset' ||
|
|
168
|
-
(attribute === 'href' && element
|
|
178
|
+
(attribute === 'href' && node_name(element) === LINK_TAG)
|
|
169
179
|
) {
|
|
170
180
|
if (!skip_warning) {
|
|
171
181
|
check_src_in_dev_hydration(element, attribute, value ?? '');
|
|
@@ -188,7 +198,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
|
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
if (value == null) {
|
|
191
|
-
element
|
|
201
|
+
remove_attribute(element, attribute);
|
|
192
202
|
} else if (typeof value !== 'string' && get_setters(element).has(attribute)) {
|
|
193
203
|
// @ts-ignore
|
|
194
204
|
element[attribute] = value;
|
|
@@ -200,7 +210,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
|
|
|
200
210
|
previous === String(value)
|
|
201
211
|
)
|
|
202
212
|
) {
|
|
203
|
-
element
|
|
213
|
+
set_attribute_op(element, attribute, value);
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
216
|
|
|
@@ -210,6 +220,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
|
|
|
210
220
|
* @param {string} value
|
|
211
221
|
*/
|
|
212
222
|
export function set_xlink_attribute(dom, attribute, value) {
|
|
223
|
+
// custom renderer safe since we never emit this
|
|
213
224
|
dom.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);
|
|
214
225
|
}
|
|
215
226
|
|
|
@@ -219,6 +230,7 @@ export function set_xlink_attribute(dom, attribute, value) {
|
|
|
219
230
|
* @param {any} value
|
|
220
231
|
*/
|
|
221
232
|
export function set_custom_element_data(node, prop, value) {
|
|
233
|
+
// custom renderer safe since we never emit this
|
|
222
234
|
// We need to ensure that setting custom element props, which can
|
|
223
235
|
// invoke lifecycle methods on other custom elements, does not also
|
|
224
236
|
// associate those lifecycle methods with the current active reaction
|
|
@@ -243,10 +255,10 @@ export function set_custom_element_data(node, prop, value) {
|
|
|
243
255
|
// Don't compute setters for custom elements while they aren't registered yet,
|
|
244
256
|
// because during their upgrade/instantiation they might add more setters.
|
|
245
257
|
// Instead, fall back to a simple "an object, then set as property" heuristic.
|
|
246
|
-
(setters_cache.has(node
|
|
258
|
+
(setters_cache.has(get_attribute(node, 'is') || node_name(node)) ||
|
|
247
259
|
// customElements may not be available in browser extension contexts
|
|
248
260
|
!customElements ||
|
|
249
|
-
customElements.get(node
|
|
261
|
+
customElements.get(get_attribute(node, 'is') || node_name(node).toLowerCase())
|
|
250
262
|
? get_setters(node).has(prop)
|
|
251
263
|
: value && typeof value === 'object')
|
|
252
264
|
) {
|
|
@@ -285,7 +297,7 @@ function set_attributes(
|
|
|
285
297
|
should_remove_defaults = false,
|
|
286
298
|
skip_warning = false
|
|
287
299
|
) {
|
|
288
|
-
if (hydrating && should_remove_defaults && element
|
|
300
|
+
if (hydrating && should_remove_defaults && node_name(element) === INPUT_TAG) {
|
|
289
301
|
if (!('defaultValue' in next || 'defaultChecked' in next)) {
|
|
290
302
|
remove_input_defaults(/** @type {HTMLInputElement} */ (element));
|
|
291
303
|
}
|
|
@@ -304,8 +316,8 @@ function set_attributes(
|
|
|
304
316
|
}
|
|
305
317
|
|
|
306
318
|
var current = prev || {};
|
|
307
|
-
var is_option_element = element
|
|
308
|
-
var is_select_element = element
|
|
319
|
+
var is_option_element = node_name(element) === OPTION_TAG;
|
|
320
|
+
var is_select_element = node_name(element) === SELECT_TAG;
|
|
309
321
|
|
|
310
322
|
try {
|
|
311
323
|
for (var key in prev) {
|
|
@@ -328,7 +340,9 @@ function set_attributes(
|
|
|
328
340
|
var setters = get_setters(element);
|
|
329
341
|
|
|
330
342
|
if (
|
|
331
|
-
|
|
343
|
+
// the following logic only makes sense in a DOM environment
|
|
344
|
+
current_renderer == null &&
|
|
345
|
+
node_name(element) === INPUT_TAG &&
|
|
332
346
|
'type' in next &&
|
|
333
347
|
('value' in next || '__value' in next)
|
|
334
348
|
) {
|
|
@@ -365,7 +379,7 @@ function set_attributes(
|
|
|
365
379
|
}
|
|
366
380
|
|
|
367
381
|
if (key === 'class') {
|
|
368
|
-
var is_html = element.namespaceURI ===
|
|
382
|
+
var is_html = current_renderer == null && element.namespaceURI === NAMESPACE_HTML;
|
|
369
383
|
set_class(element, is_html, value, css_hash, prev?.[CLASS], next[CLASS]);
|
|
370
384
|
current[key] = value;
|
|
371
385
|
current[CLASS] = next[CLASS];
|
|
@@ -382,7 +396,7 @@ function set_attributes(
|
|
|
382
396
|
var prev_value = current[key];
|
|
383
397
|
|
|
384
398
|
// Skip if value is unchanged, unless it's `undefined` and the element still has the attribute
|
|
385
|
-
if (value === prev_value && !(value === undefined && element
|
|
399
|
+
if (value === prev_value && !(value === undefined && has_attribute(element, key))) {
|
|
386
400
|
continue;
|
|
387
401
|
}
|
|
388
402
|
|
|
@@ -396,7 +410,7 @@ function set_attributes(
|
|
|
396
410
|
const opts = {};
|
|
397
411
|
const event_handle_key = '$$' + key;
|
|
398
412
|
let event_name = key.slice(2);
|
|
399
|
-
var is_delegated = can_delegate_event(event_name);
|
|
413
|
+
var is_delegated = current_renderer == null && can_delegate_event(event_name);
|
|
400
414
|
|
|
401
415
|
if (is_capture_event(event_name)) {
|
|
402
416
|
event_name = event_name.slice(0, -7);
|
|
@@ -410,7 +424,7 @@ function set_attributes(
|
|
|
410
424
|
// https://github.com/sveltejs/svelte/issues/11903
|
|
411
425
|
if (value != null) continue;
|
|
412
426
|
|
|
413
|
-
element
|
|
427
|
+
remove_event_listener(element, event_name, current[event_handle_key], opts);
|
|
414
428
|
current[event_handle_key] = null;
|
|
415
429
|
}
|
|
416
430
|
|
|
@@ -420,10 +434,10 @@ function set_attributes(
|
|
|
420
434
|
} else if (value != null) {
|
|
421
435
|
/**
|
|
422
436
|
* @this {any}
|
|
423
|
-
* @param {
|
|
437
|
+
* @param {...any} args
|
|
424
438
|
*/
|
|
425
|
-
function handle(
|
|
426
|
-
current[key].
|
|
439
|
+
function handle(...args) {
|
|
440
|
+
current[key].apply(this, args);
|
|
427
441
|
}
|
|
428
442
|
|
|
429
443
|
current[event_handle_key] = create_event(event_name, element, handle, opts);
|
|
@@ -432,7 +446,16 @@ function set_attributes(
|
|
|
432
446
|
// avoid using the setter
|
|
433
447
|
set_attribute(element, key, value);
|
|
434
448
|
} else if (key === 'autofocus') {
|
|
435
|
-
|
|
449
|
+
if (current_renderer == null) {
|
|
450
|
+
autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
|
|
451
|
+
} else {
|
|
452
|
+
// In custom renderer mode, just set autofocus as a regular attribute
|
|
453
|
+
if (value) {
|
|
454
|
+
set_attribute_op(element, key, value);
|
|
455
|
+
} else {
|
|
456
|
+
remove_attribute(element, key);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
436
459
|
} else if (!is_custom_element && (key === '__value' || (key === 'value' && value != null))) {
|
|
437
460
|
// @ts-ignore We're not running this for custom elements because __value is actually
|
|
438
461
|
// how Lit stores the current value on the element, and messing with that would break things.
|
|
@@ -448,8 +471,7 @@ function set_attributes(
|
|
|
448
471
|
element.value !== value ||
|
|
449
472
|
(value === 0 && element.nodeName === PROGRESS_TAG)
|
|
450
473
|
) {
|
|
451
|
-
|
|
452
|
-
element.value = value;
|
|
474
|
+
set_element_value(element, value);
|
|
453
475
|
}
|
|
454
476
|
} else if (key === 'selected' && is_option_element) {
|
|
455
477
|
set_selected(/** @type {HTMLOptionElement} */ (element), value);
|
|
@@ -466,26 +488,39 @@ function set_attributes(
|
|
|
466
488
|
|
|
467
489
|
if (value == null && !is_custom_element && !is_default) {
|
|
468
490
|
attributes[key] = null;
|
|
469
|
-
|
|
470
|
-
if (name === 'value' || name === 'checked') {
|
|
491
|
+
if ((name === 'value' || name === 'checked') && current_renderer == null) {
|
|
471
492
|
// removing value/checked also removes defaultValue/defaultChecked — preserve
|
|
472
493
|
let input = /** @type {HTMLInputElement} */ (element);
|
|
473
494
|
const use_default = prev === undefined;
|
|
474
495
|
if (name === 'value') {
|
|
475
496
|
let previous = input.defaultValue;
|
|
476
|
-
input
|
|
477
|
-
input
|
|
497
|
+
remove_attribute(input, name);
|
|
498
|
+
set_element_default_value(input, previous);
|
|
478
499
|
// @ts-ignore
|
|
479
|
-
input
|
|
500
|
+
set_element_value(input, (input.__value = use_default ? previous : null));
|
|
480
501
|
} else {
|
|
481
502
|
let previous = input.defaultChecked;
|
|
482
|
-
input
|
|
483
|
-
input
|
|
484
|
-
input
|
|
503
|
+
remove_attribute(input, name);
|
|
504
|
+
set_element_default_checked(input, previous);
|
|
505
|
+
set_element_checked(input, use_default ? previous : false);
|
|
485
506
|
}
|
|
486
507
|
} else {
|
|
487
|
-
element
|
|
508
|
+
remove_attribute(element, key);
|
|
509
|
+
if (name === 'value') {
|
|
510
|
+
// @ts-ignore
|
|
511
|
+
element.__value = null;
|
|
512
|
+
}
|
|
488
513
|
}
|
|
514
|
+
} else if (is_default && current_renderer != null) {
|
|
515
|
+
// Route through the renderer-aware abstraction so custom renderers
|
|
516
|
+
// see defaultValue/defaultChecked as proper attributes
|
|
517
|
+
if (name === 'defaultValue') {
|
|
518
|
+
set_element_default_value(element, value);
|
|
519
|
+
} else {
|
|
520
|
+
set_element_default_checked(element, value);
|
|
521
|
+
}
|
|
522
|
+
// remove it from attributes's cache
|
|
523
|
+
if (name in attributes) attributes[name] = UNINITIALIZED;
|
|
489
524
|
} else if (
|
|
490
525
|
is_default ||
|
|
491
526
|
((is_custom_element || typeof value !== 'string') && setters.has(name))
|
|
@@ -535,7 +570,7 @@ export function attribute_effect(
|
|
|
535
570
|
/** @type {Record<symbol, Effect>} */
|
|
536
571
|
var effects = {};
|
|
537
572
|
|
|
538
|
-
var is_select = element
|
|
573
|
+
var is_select = node_name(element) === SELECT_TAG;
|
|
539
574
|
var inited = false;
|
|
540
575
|
|
|
541
576
|
managed(() => {
|
|
@@ -606,18 +641,21 @@ export function attribute_effect(
|
|
|
606
641
|
function get_attributes(element) {
|
|
607
642
|
return /** @type {Record<string | symbol, unknown>} **/ (
|
|
608
643
|
/** @type {any} */ (element)[ATTRIBUTES_CACHE] ??= {
|
|
609
|
-
[IS_CUSTOM_ELEMENT]: element.
|
|
610
|
-
[IS_HTML]: element.namespaceURI === NAMESPACE_HTML
|
|
644
|
+
[IS_CUSTOM_ELEMENT]: node_name(element).includes('-'),
|
|
645
|
+
[IS_HTML]: current_renderer == null && element.namespaceURI === NAMESPACE_HTML
|
|
611
646
|
}
|
|
612
647
|
);
|
|
613
648
|
}
|
|
614
649
|
|
|
615
650
|
/** @type {Map<string, Set<string>>} */
|
|
616
651
|
var setters_cache = new Map();
|
|
652
|
+
var empty_setters = new Set();
|
|
617
653
|
|
|
618
654
|
/** @param {Element} element */
|
|
619
655
|
function get_setters(element) {
|
|
620
|
-
|
|
656
|
+
// if we have a custom renderer we just skip the check all together
|
|
657
|
+
if (current_renderer) return empty_setters;
|
|
658
|
+
var cache_key = get_attribute(element, 'is') || node_name(element);
|
|
621
659
|
var setters = setters_cache.get(cache_key);
|
|
622
660
|
if (setters) return setters;
|
|
623
661
|
setters_cache.set(cache_key, (setters = new Set()));
|
|
@@ -655,9 +693,9 @@ function get_setters(element) {
|
|
|
655
693
|
* @param {string} value
|
|
656
694
|
*/
|
|
657
695
|
function check_src_in_dev_hydration(element, attribute, value) {
|
|
658
|
-
if (!DEV) return;
|
|
696
|
+
if (!DEV || current_renderer != null) return;
|
|
659
697
|
if (attribute === 'srcset' && srcset_url_equal(element, value)) return;
|
|
660
|
-
if (src_url_equal(element
|
|
698
|
+
if (src_url_equal(get_attribute(element, attribute) ?? '', value)) return;
|
|
661
699
|
|
|
662
700
|
w.hydration_attribute_changed(
|
|
663
701
|
attribute,
|
|
@@ -672,7 +710,7 @@ function check_src_in_dev_hydration(element, attribute, value) {
|
|
|
672
710
|
* @returns {boolean}
|
|
673
711
|
*/
|
|
674
712
|
function src_url_equal(element_src, url) {
|
|
675
|
-
if (element_src === url) return true;
|
|
713
|
+
if (element_src === url || current_renderer != null) return true;
|
|
676
714
|
return new URL(element_src, document.baseURI).href === new URL(url, document.baseURI).href;
|
|
677
715
|
}
|
|
678
716
|
|
|
@@ -687,6 +725,7 @@ function split_srcset(srcset) {
|
|
|
687
725
|
* @returns {boolean}
|
|
688
726
|
*/
|
|
689
727
|
function srcset_url_equal(element, srcset) {
|
|
728
|
+
if (current_renderer != null) return true;
|
|
690
729
|
var element_urls = split_srcset(element.srcset);
|
|
691
730
|
var urls = split_srcset(srcset);
|
|
692
731
|
|
|
@@ -5,6 +5,11 @@ import { is } from '../../../proxy.js';
|
|
|
5
5
|
import { is_array } from '../../../../shared/utils.js';
|
|
6
6
|
import * as w from '../../../warnings.js';
|
|
7
7
|
import { current_batch, view_batch } from '../../../reactivity/batch.js';
|
|
8
|
+
import {
|
|
9
|
+
has_attribute,
|
|
10
|
+
remove_attribute,
|
|
11
|
+
set_attribute as set_attribute_op
|
|
12
|
+
} from '../../operations.js';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Sets the `selected` attribute on an option so form reset can restore it.
|
|
@@ -13,9 +18,13 @@ import { current_batch, view_batch } from '../../../reactivity/batch.js';
|
|
|
13
18
|
*/
|
|
14
19
|
export function set_selected(option, selected) {
|
|
15
20
|
if (selected) {
|
|
16
|
-
|
|
21
|
+
// The selected option could've changed via user selection, and
|
|
22
|
+
// setting the value without this check would set it back.
|
|
23
|
+
if (!has_attribute(option, 'selected')) {
|
|
24
|
+
set_attribute_op(option, 'selected', '');
|
|
25
|
+
}
|
|
17
26
|
} else {
|
|
18
|
-
option
|
|
27
|
+
remove_attribute(option, 'selected');
|
|
19
28
|
}
|
|
20
29
|
}
|
|
21
30
|
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { to_class } from '../../../shared/attributes.js';
|
|
2
|
+
import { custom_renderers_flag } from '../../../flags/index.js';
|
|
3
|
+
import { current_renderer } from '../../custom-renderer/state.js';
|
|
2
4
|
import { CLASS_CACHE } from '../../constants.js';
|
|
3
5
|
import { hydrating } from '../hydration.js';
|
|
6
|
+
import {
|
|
7
|
+
class_list_toggle,
|
|
8
|
+
get_attribute,
|
|
9
|
+
remove_attribute,
|
|
10
|
+
set_attribute
|
|
11
|
+
} from '../operations.js';
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* @param {Element} dom
|
|
@@ -17,21 +25,24 @@ export function set_class(dom, is_html, value, hash, prev_classes, next_classes)
|
|
|
17
25
|
if (
|
|
18
26
|
hydrating ||
|
|
19
27
|
prev !== value ||
|
|
20
|
-
prev === undefined // for edge case of `class={undefined}`
|
|
28
|
+
prev === undefined || // for edge case of `class={undefined}`
|
|
29
|
+
// custom renderers only deal in attributes, so rather than toggling individual classes
|
|
30
|
+
// (which would mean editing the `class` attribute), always set the whole thing
|
|
31
|
+
(custom_renderers_flag && current_renderer !== null)
|
|
21
32
|
) {
|
|
22
33
|
var next_class_name = to_class(value, hash, next_classes);
|
|
23
34
|
|
|
24
|
-
if (!hydrating || next_class_name !== dom
|
|
35
|
+
if (!hydrating || next_class_name !== get_attribute(dom, 'class')) {
|
|
25
36
|
// Removing the attribute when the value is only an empty string causes
|
|
26
37
|
// performance issues vs simply making the className an empty string. So
|
|
27
38
|
// we should only remove the class if the value is nullish
|
|
28
39
|
// and there no hash/directives :
|
|
29
40
|
if (next_class_name == null) {
|
|
30
|
-
dom
|
|
41
|
+
remove_attribute(dom, 'class');
|
|
31
42
|
} else if (is_html) {
|
|
32
43
|
dom.className = next_class_name;
|
|
33
44
|
} else {
|
|
34
|
-
dom
|
|
45
|
+
set_attribute(dom, 'class', next_class_name);
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
|
|
@@ -41,7 +52,7 @@ export function set_class(dom, is_html, value, hash, prev_classes, next_classes)
|
|
|
41
52
|
var is_present = !!next_classes[key];
|
|
42
53
|
|
|
43
54
|
if (prev_classes == null || is_present !== !!prev_classes[key]) {
|
|
44
|
-
dom
|
|
55
|
+
class_list_toggle(/** @type {HTMLElement} */ (dom), key, is_present);
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
}
|