/
vnode.ts
42 lines (35 loc) · 1.3 KB
/
vnode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { SetupContext } from 'vue';
type HTMLElementWithValueBinding = HTMLElement & { _value: unknown };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const normalizeChildren = (
tag: string | Record<string, unknown> | undefined,
context: SetupContext<any>,
slotProps: () => Record<string, unknown>
) => {
if (!context.slots.default) {
return context.slots.default;
}
if (typeof tag === 'string' || !tag) {
return context.slots.default(slotProps());
}
return {
default: () => context.slots.default?.(slotProps()),
};
};
/**
* Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
* as they do not get casted to strings unlike `el.value` which preserves user-code behavior
*/
export function getBoundValue(el: HTMLElement): unknown {
if (hasValueBinding(el)) {
return el._value;
}
return undefined;
}
/**
* Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
* as they do not get casted to strings unlike `el.value` which preserves user-code behavior
*/
export function hasValueBinding(el: HTMLElement): el is HTMLElementWithValueBinding {
return '_value' in el;
}