svelte 5.47.0 → 5.47.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "svelte",
3
3
  "description": "Cybernetically enhanced web apps",
4
4
  "license": "MIT",
5
- "version": "5.47.0",
5
+ "version": "5.47.1",
6
6
  "type": "module",
7
7
  "types": "./types/index.d.ts",
8
8
  "engines": {
@@ -80,7 +80,7 @@ export function RegularElement(node, context) {
80
80
 
81
81
  // Special case: <select>, <option> or <optgroup> with rich content needs special hydration handling
82
82
  // We mark the subtree as dynamic so parent elements properly include the child init code
83
- if (is_customizable_select_element(node)) {
83
+ if (is_customizable_select_element(node) || node.name === 'selectedcontent') {
84
84
  // Mark the element's own fragment as dynamic so it's not treated as static
85
85
  node.fragment.metadata.dynamic = true;
86
86
  // Also mark ancestor fragments so parents properly include the child init code
@@ -457,6 +457,18 @@ export function RegularElement(node, context) {
457
457
  context.state.after_update.push(...element_state.after_update);
458
458
  }
459
459
 
460
+ if (node.name === 'selectedcontent') {
461
+ context.state.init.push(
462
+ b.stmt(
463
+ b.call(
464
+ '$.selectedcontent',
465
+ context.state.node,
466
+ b.arrow([b.id('$$element')], b.assignment('=', context.state.node, b.id('$$element')))
467
+ )
468
+ )
469
+ );
470
+ }
471
+
460
472
  if (lookup.has('dir')) {
461
473
  // This fixes an issue with Chromium where updates to text content within an element
462
474
  // does not update the direction when set to auto. If we just re-assign the dir, this fixes it.
@@ -1,5 +1,6 @@
1
1
  import { hydrating, reset, set_hydrate_node, set_hydrating } from '../hydration.js';
2
2
  import { create_comment } from '../operations.js';
3
+ import { attach } from './attachments.js';
3
4
 
4
5
  /** @type {boolean | null} */
5
6
  let supported = null;
@@ -20,6 +21,52 @@ function is_supported() {
20
21
  return supported;
21
22
  }
22
23
 
24
+ /**
25
+ *
26
+ * @param {HTMLElement} element
27
+ * @param {(new_element: HTMLElement) => void} update_element
28
+ */
29
+ export function selectedcontent(element, update_element) {
30
+ // if it's not supported no need for special logic
31
+ if (!is_supported()) return;
32
+
33
+ // we use the attach function directly just to make sure is executed when is mounted to the dom
34
+ attach(element, () => () => {
35
+ const select = element.closest('select');
36
+ if (!select) return;
37
+
38
+ const observer = new MutationObserver((entries) => {
39
+ var selected = false;
40
+
41
+ for (const entry of entries) {
42
+ if (entry.target === element) {
43
+ // the `<selectedcontent>` already changed, no need to replace it
44
+ return;
45
+ }
46
+
47
+ // if the changes doesn't include the selected `<option>` we don't need to do anything
48
+ selected ||= !!entry.target.parentElement?.closest('option')?.selected;
49
+ }
50
+
51
+ if (selected) {
52
+ // replace the `<selectedcontent>` with a clone
53
+ element.replaceWith((element = /** @type {HTMLElement} */ (element.cloneNode(true))));
54
+ update_element(element);
55
+ }
56
+ });
57
+
58
+ observer.observe(select, {
59
+ childList: true,
60
+ characterData: true,
61
+ subtree: true
62
+ });
63
+
64
+ return () => {
65
+ observer.disconnect();
66
+ };
67
+ });
68
+ }
69
+
23
70
  /**
24
71
  * Handles rich HTML content inside `<option>`, `<optgroup>`, or `<select>` elements with browser-specific branching.
25
72
  * Modern browsers preserve HTML inside options, while older browsers strip it to text only.
@@ -42,7 +42,7 @@ export {
42
42
  export { set_class } from './dom/elements/class.js';
43
43
  export { apply, event, delegate, replay_events } from './dom/elements/events.js';
44
44
  export { autofocus, remove_textarea_child } from './dom/elements/misc.js';
45
- export { customizable_select } from './dom/elements/customizable-select.js';
45
+ export { customizable_select, selectedcontent } from './dom/elements/customizable-select.js';
46
46
  export { set_style } from './dom/elements/style.js';
47
47
  export { animation, transition } from './dom/elements/transitions.js';
48
48
  export { bind_active_element } from './dom/elements/bindings/document.js';
package/src/version.js CHANGED
@@ -4,5 +4,5 @@
4
4
  * The current version, as set in package.json.
5
5
  * @type {string}
6
6
  */
7
- export const VERSION = '5.47.0';
7
+ export const VERSION = '5.47.1';
8
8
  export const PUBLIC_VERSION = '5';