meowjsx 0.3.0-alpha.3 → 0.3.0-alpha.4
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/dist/web/render.js +23 -2
- package/package.json +1 -1
package/dist/web/render.js
CHANGED
|
@@ -11,8 +11,12 @@ export function createWebRenderer(runtime = defaultRuntime, options = {}) {
|
|
|
11
11
|
onMount(vnode, node) {
|
|
12
12
|
// A native select cannot resolve its value until its options exist.
|
|
13
13
|
// The normal property subscription still handles subsequent Signal updates.
|
|
14
|
-
if (vnode.type === "select"
|
|
15
|
-
|
|
14
|
+
if (vnode.type === "select") {
|
|
15
|
+
// An explicit `value={undefined}` means no value, like an absent prop: select the first option.
|
|
16
|
+
if (Object.hasOwn(vnode.props, "value") && vnode.props.value !== undefined)
|
|
17
|
+
setDOMProperty(node, "value", vnode.props.value);
|
|
18
|
+
else
|
|
19
|
+
resetSelectedness(node);
|
|
16
20
|
}
|
|
17
21
|
return runShadows(runtime, vnode, node);
|
|
18
22
|
},
|
|
@@ -58,6 +62,23 @@ export function createWebRenderer(runtime = defaultRuntime, options = {}) {
|
|
|
58
62
|
renderToHtml: (node) => renderToHtmlWithRuntime(runtime, node),
|
|
59
63
|
};
|
|
60
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Siblings mount last to first, so the browser selects a single-choice select's first inserted
|
|
67
|
+
* option, which is its last one. Without a host value, restore what parsing the same markup
|
|
68
|
+
* would select: the last `selected` option, otherwise the first enabled one.
|
|
69
|
+
*/
|
|
70
|
+
function resetSelectedness(select) {
|
|
71
|
+
const options = Array.from(select.options ?? []);
|
|
72
|
+
if (select.multiple || select.size > 1) {
|
|
73
|
+
for (const option of options)
|
|
74
|
+
option.selected = option.defaultSelected;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const chosen = options.filter((option) => option.defaultSelected).pop() ??
|
|
78
|
+
options.find((option) => !option.disabled);
|
|
79
|
+
if (chosen)
|
|
80
|
+
chosen.selected = true;
|
|
81
|
+
}
|
|
61
82
|
/** The default runtime's Web renderer; apps that install into it use this one. */
|
|
62
83
|
export const defaultWebRenderer = /* @__PURE__ */ createWebRenderer();
|
|
63
84
|
// A pure read lets bundlers drop the default renderer when none of these members is used.
|