@vue-jsx/runtime 3.3.0-beta.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/LICENSE +21 -0
- package/dist/h.d.ts +22 -0
- package/dist/h.js +33 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/jsx.d.ts +1173 -0
- package/dist/jsx.js +1 -0
- package/dist/props.d.ts +34 -0
- package/dist/props.js +70 -0
- package/dist/raw.d.ts +11 -0
- package/dist/raw.js +23 -0
- package/dist/ssr.d.ts +6 -0
- package/dist/ssr.js +18 -0
- package/dist/types.d.ts +34 -0
- package/dist/types.js +1 -0
- package/dist/vapor.d.ts +111 -0
- package/dist/vapor.js +154 -0
- package/dist/vdom.d.ts +77 -0
- package/dist/vdom.js +46 -0
- package/package.json +40 -0
package/dist/jsx.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as _$vue from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/props.d.ts
|
|
4
|
+
declare function getCurrentInstance(): _$vue.GenericComponentInstance | null;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the props of the current component instance.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { useProps } from 'vue-jsx-vapor'
|
|
11
|
+
*
|
|
12
|
+
* defineComponent(({ foo = '' })=>{
|
|
13
|
+
* const props = useProps() // { foo: '' }
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function useProps(): {
|
|
18
|
+
[x: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Returns the merged props and attrs of the current component.\
|
|
22
|
+
* Equivalent to `useProps()` + `useAttrs()`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { useFullProps } from 'vue-jsx-vapor'
|
|
27
|
+
*
|
|
28
|
+
* defineComponent((props) => {
|
|
29
|
+
* const fullProps = useFullProps() // = useAttrs() + useProps()
|
|
30
|
+
* })
|
|
31
|
+
*/
|
|
32
|
+
declare function useFullProps(): {};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { getCurrentInstance, useFullProps, useProps };
|
package/dist/props.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Vue from "vue";
|
|
2
|
+
import { computed, useAttrs } from "vue";
|
|
3
|
+
//#region src/props.ts
|
|
4
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
5
|
+
function getCurrentInstance() {
|
|
6
|
+
return Vue.currentInstance || Vue.getCurrentInstance();
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns the props of the current component instance.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useProps } from 'vue-jsx-vapor'
|
|
14
|
+
*
|
|
15
|
+
* defineComponent(({ foo = '' })=>{
|
|
16
|
+
* const props = useProps() // { foo: '' }
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
21
|
+
function useProps() {
|
|
22
|
+
return (/* @__PURE__ */ getCurrentInstance()).props;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the merged props and attrs of the current component.\
|
|
26
|
+
* Equivalent to `useProps()` + `useAttrs()`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { useFullProps } from 'vue-jsx-vapor'
|
|
31
|
+
*
|
|
32
|
+
* defineComponent((props) => {
|
|
33
|
+
* const fullProps = useFullProps() // = useAttrs() + useProps()
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
37
|
+
function useFullProps() {
|
|
38
|
+
const attrs = useAttrs();
|
|
39
|
+
if (!(/* @__PURE__ */ getCurrentInstance()).type.props) return attrs;
|
|
40
|
+
const props = /* @__PURE__ */ useProps();
|
|
41
|
+
const fullProps = computed(() => ({
|
|
42
|
+
...props,
|
|
43
|
+
...attrs
|
|
44
|
+
}));
|
|
45
|
+
return new Proxy({}, {
|
|
46
|
+
get(_, p, receiver) {
|
|
47
|
+
return Reflect.get(fullProps.value, p, receiver);
|
|
48
|
+
},
|
|
49
|
+
set(_, p, v, r) {
|
|
50
|
+
return Reflect.set(fullProps.value, p, v, r);
|
|
51
|
+
},
|
|
52
|
+
deleteProperty(_, p) {
|
|
53
|
+
return Reflect.deleteProperty(fullProps.value, p);
|
|
54
|
+
},
|
|
55
|
+
has(_, p) {
|
|
56
|
+
return Reflect.has(fullProps.value, p);
|
|
57
|
+
},
|
|
58
|
+
ownKeys() {
|
|
59
|
+
return Object.keys(fullProps.value);
|
|
60
|
+
},
|
|
61
|
+
getOwnPropertyDescriptor() {
|
|
62
|
+
return {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { getCurrentInstance, useFullProps, useProps };
|
package/dist/raw.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/raw.d.ts
|
|
2
|
+
declare const propsHelperCode: string;
|
|
3
|
+
declare const vdomHelperCode: string;
|
|
4
|
+
declare const vaporHelperCode: string;
|
|
5
|
+
declare const ssrHelperCode: string;
|
|
6
|
+
declare const propsHelperId = "/vue-jsx-vapor/props";
|
|
7
|
+
declare const vdomHelperId = "/vue-jsx-vapor/vdom";
|
|
8
|
+
declare const vaporHelperId = "/vue-jsx-vapor/vapor";
|
|
9
|
+
declare const ssrHelperId = "/vue-jsx-vapor/ssr";
|
|
10
|
+
//#endregion
|
|
11
|
+
export { propsHelperCode, propsHelperId, ssrHelperCode, ssrHelperId, vaporHelperCode, vaporHelperId, vdomHelperCode, vdomHelperId };
|
package/dist/raw.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/props.ts?raw
|
|
2
|
+
var props_default = "import { computed, useAttrs } from \"vue\";\nimport * as Vue from \"vue\";\n// @__NO_SIDE_EFFECTS__\nexport function getCurrentInstance() {\n return Vue.currentInstance || Vue.getCurrentInstance();\n}\n// @__NO_SIDE_EFFECTS__\nexport function useProps() {\n const i = /* @__PURE__ */ getCurrentInstance();\n return i.props;\n}\n// @__NO_SIDE_EFFECTS__\nexport function useFullProps() {\n const attrs = useAttrs();\n const i = /* @__PURE__ */ getCurrentInstance();\n if (!i.type.props) {\n return attrs;\n }\n const props = /* @__PURE__ */ useProps();\n const fullProps = computed(() => ({ ...props, ...attrs }));\n return new Proxy(\n {},\n {\n get(_, p, receiver) {\n return Reflect.get(fullProps.value, p, receiver);\n },\n set(_, p, v, r) {\n return Reflect.set(fullProps.value, p, v, r);\n },\n deleteProperty(_, p) {\n return Reflect.deleteProperty(fullProps.value, p);\n },\n has(_, p) {\n return Reflect.has(fullProps.value, p);\n },\n ownKeys() {\n return Object.keys(fullProps.value);\n },\n getOwnPropertyDescriptor() {\n return {\n enumerable: true,\n configurable: true\n };\n }\n }\n );\n}\n";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/ssr.ts?raw
|
|
5
|
+
var ssr_default = "import { useSSRContext } from \"vue\";\nexport function ssrRegisterHelper(comp, filename) {\n if (typeof comp === \"function\") {\n comp.__setup = () => {\n const ssrContext = useSSRContext();\n (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add(filename);\n };\n } else {\n const setup = comp.setup;\n comp.setup = (props, ctx) => {\n const ssrContext = useSSRContext();\n (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add(filename);\n if (setup) {\n return setup(props, ctx);\n }\n };\n }\n}\n";
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/vapor.ts?raw
|
|
8
|
+
var vapor_default = "import {\n EffectScope,\n Fragment,\n getCurrentInstance\n} from \"vue\";\nimport * as Vue from \"vue\";\n// @__NO_SIDE_EFFECTS__\nexport function defineVaporSSRComponent(comp, extraOptions) {\n if (typeof comp === \"function\") {\n return Object.assign({ name: comp.name }, extraOptions, {\n setup(props, ctx) {\n const result = comp(props, ctx);\n return () => result;\n },\n __vapor: true\n });\n }\n const setup = comp.setup;\n if (setup) {\n comp.setup = (props, ctx) => {\n const result = setup(props, ctx);\n return () => result;\n };\n }\n comp.__vapor = true;\n return comp;\n}\nexport const createComponent = (type, ...args) => {\n if (type === Fragment) {\n const slots = args[1];\n return slots ? typeof slots === \"function\" ? slots() : typeof slots.default === \"function\" ? slots.default() : [] : [];\n }\n return Vue.createComponentWithFallback(\n createProxyComponent(Vue.resolveDynamicComponent(type)),\n ...args\n );\n};\nconst proxyCache = /* @__PURE__ */ new WeakMap();\nexport function createProxyComponent(type, normalizeNode2) {\n if (typeof type === \"function\") {\n const existing = proxyCache.get(type);\n if (existing) return existing;\n const i = Vue.currentInstance || getCurrentInstance();\n const proxy = new Proxy(type, {\n apply(target, ctx, args) {\n if (typeof target.__setup === \"function\") {\n target.__setup.apply(ctx, args);\n }\n const node = Reflect.apply(target, ctx, args);\n return normalizeNode2 ? normalizeNode2(node) : node;\n },\n get(target, p, receiver) {\n if (i && i.appContext.vapor && p === \"__vapor\") {\n return true;\n }\n return Reflect.get(target, p, receiver);\n }\n });\n proxyCache.set(type, proxy);\n return proxy;\n }\n return type;\n}\nexport function normalizeNode(node) {\n if (node == null || typeof node === \"boolean\") {\n return document.createComment(\"\");\n } else if (Array.isArray(node) && node.length) {\n return node.map(normalizeNode);\n } else if (isBlock(node)) {\n return node;\n } else if (typeof node === \"function\") {\n return resolveValues([node], void 0, true)[0];\n } else {\n return document.createTextNode(String(node));\n }\n}\nexport function isBlock(val) {\n return val instanceof Node || Array.isArray(val) || Vue.isVaporComponent(val) || Vue.isFragment(val);\n}\nfunction createFragment(nodes, anchor = document.createTextNode(\"\")) {\n const frag = new Vue.VaporFragment(nodes);\n frag.anchor = anchor;\n return frag;\n}\nfunction normalizeBlock(node, anchor, processFunction = false) {\n if (node instanceof Node || Vue.isFragment(node)) {\n return node;\n } else if (Vue.isVaporComponent(node)) {\n return createFragment(node, anchor);\n } else if (Array.isArray(node)) {\n return createFragment(\n node.map((i) => normalizeBlock(i, void 0, processFunction)),\n anchor\n );\n } else if (processFunction && typeof node === \"function\") {\n return resolveValues([node], anchor, true)[0];\n } else {\n const result = node == null || typeof node === \"boolean\" ? \"\" : String(node);\n if (anchor) {\n anchor.textContent = result;\n return anchor;\n } else {\n return document.createTextNode(result);\n }\n }\n}\nfunction resolveValue(current, value, anchor, processFunction = false) {\n anchor = anchor || (current instanceof Node && current.nodeType === 3 ? current : void 0);\n const node = normalizeBlock(value, anchor, processFunction);\n if (current) {\n if (Vue.isFragment(current)) {\n if (current.anchor && current.anchor.parentNode) {\n Vue.remove(current.nodes, current.anchor.parentNode);\n Vue.insert(node, current.anchor.parentNode, current.anchor);\n if (!anchor) current.anchor.parentNode.removeChild(current.anchor);\n if (current.scope) current.scope.stop();\n }\n } else if (current instanceof Node) {\n if (current.nodeType === 3 && (!(node instanceof Node) || node.nodeType !== 3)) {\n current.textContent = \"\";\n }\n if (Vue.isFragment(node) && current.parentNode) {\n Vue.insert(node, current.parentNode, current);\n if (!anchor || current.nodeType !== 3) {\n current.parentNode.removeChild(current);\n }\n } else if (node instanceof Node) {\n if (current.nodeType === 3 && node.nodeType === 3) {\n current.textContent = node.textContent;\n return current;\n } else if (current.parentNode) {\n current.parentNode.replaceChild(node, current);\n }\n }\n }\n }\n return node;\n}\nfunction resolveValues(values = [], _anchor, processFunction = false) {\n const nodes = [];\n const scopes = [];\n for (const [index, value] of values.entries()) {\n const anchor = index === values.length - 1 ? _anchor : void 0;\n if (typeof value === \"function\") {\n Vue.renderEffect(() => {\n if (scopes[index]) scopes[index].stop();\n scopes[index] = new EffectScope();\n nodes[index] = scopes[index].run(\n () => resolveValue(nodes[index], value(), anchor, processFunction)\n );\n });\n } else {\n nodes[index] = resolveValue(nodes[index], value, anchor, processFunction);\n }\n }\n return nodes;\n}\nexport function setNodes(anchor, ...values) {\n const resolvedValues = resolveValues(values, anchor);\n if (anchor.parentNode) Vue.insert(resolvedValues, anchor.parentNode, anchor);\n}\nexport function createNodes(...values) {\n return resolveValues(values);\n}\nexport function normalizeVaporSlots(slots) {\n if (typeof slots === \"function\") {\n return { name: \"default\", fn: slots };\n } else if (Object.prototype.toString.call(slots) === \"[object Object]\" && !isBlock(slots)) {\n return Object.entries(slots).map(([name, fn]) => ({ name, fn }));\n } else {\n return {\n name: \"default\",\n fn: () => createNodes(slots)\n };\n }\n}\n// @__NO_SIDE_EFFECTS__\nexport function defineVaporComponent(comp, extraOptions) {\n if (typeof comp === \"function\") {\n return Object.assign({ name: comp.name }, extraOptions, {\n setup: comp,\n __vapor: true\n });\n }\n comp.__vapor = true;\n return comp;\n}\nexport const VaporFor = /* @__PURE__ */ defineVaporComponent(\n (props, {\n slots\n }) => {\n return Vue.createFor(\n () => props.in,\n (item, key, index) => {\n return slots.default ? slots.default(\n // @ts-ignore\n props.getKey === void 0 ? item.value : item,\n key,\n index\n ) : [];\n },\n props.getKey === void 0 ? (item) => item : props.getKey\n );\n },\n { props: [\"in\", \"getKey\"] }\n);\n";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/vdom.ts?raw
|
|
11
|
+
var vdom_default = "import {\n defineComponent as __defineComponent,\n normalizeClass as _normalizeClass,\n cloneVNode,\n Comment,\n createBlock,\n createElementBlock,\n createElementVNode,\n createVNode,\n Fragment,\n getCurrentInstance,\n isVNode,\n openBlock,\n renderList,\n Text,\n withCtx\n} from \"vue\";\nconst cacheMap = /* @__PURE__ */ new WeakMap();\nexport function createVNodeCache(key) {\n const i = getCurrentInstance();\n if (i) {\n if (!cacheMap.has(i)) cacheMap.set(i, {});\n const caches = cacheMap.get(i);\n return caches[key] || (caches[key] = []);\n } else {\n return [];\n }\n}\nexport function normalizeVNode(value, flag = 1) {\n let create = createVNode;\n let isBlock = false;\n if (typeof value === \"function\") {\n isBlock = true;\n openBlock();\n create = createBlock;\n value = value();\n }\n return isVNode(value) ? isBlock ? createBlock(cloneIfMounted(value)) : cloneIfMounted(value) : Array.isArray(value) ? isBlock ? createElementBlock(\n Fragment,\n null,\n value.map((n) => normalizeVNode(() => n)),\n -2\n ) : createElementVNode(Fragment, null, value.slice()) : value == null || typeof value === \"boolean\" ? create(Comment) : create(Text, null, String(value), flag);\n}\nfunction cloneIfMounted(child) {\n return child.el === null && child.patchFlag !== -1 || // @ts-ignore\n child.memo ? child : cloneVNode(child);\n}\nconst normalizeSlotValue = (value) => Array.isArray(value) ? value.map((n) => normalizeVNode(n)) : [normalizeVNode(value)];\nexport const normalizeSlot = (rawSlot) => {\n if (rawSlot._n) {\n return rawSlot;\n }\n return withCtx((...args) => {\n return normalizeSlotValue(rawSlot(...args));\n });\n};\nexport const normalizeSlots = (slots) => {\n return typeof slots === \"function\" || Object.prototype.toString.call(slots) === \"[object Object]\" && !isVNode(slots) ? slots : {\n default: withCtx(() => [normalizeVNode(() => slots)])\n };\n};\nexport const normalizeClass = (value) => _normalizeClass(value) || null;\nexport const defineComponent = __defineComponent;\nexport const For = defineComponent(\n (props, {\n slots\n }) => {\n const defaultSlot = slots.default;\n return () => (openBlock(true), createElementBlock(\n Fragment,\n null,\n renderList(props.in, (item, key, index) => {\n const result = defaultSlot(item, key, index);\n return Array.isArray(result) ? result.length === 1 ? result[0] : normalizeVNode(result) : result;\n }),\n 128\n ));\n },\n { props: [\"in\"] }\n);\n";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/raw.ts
|
|
14
|
+
const propsHelperCode = props_default;
|
|
15
|
+
const vdomHelperCode = vdom_default;
|
|
16
|
+
const vaporHelperCode = vapor_default;
|
|
17
|
+
const ssrHelperCode = ssr_default;
|
|
18
|
+
const propsHelperId = "/vue-jsx-vapor/props";
|
|
19
|
+
const vdomHelperId = "/vue-jsx-vapor/vdom";
|
|
20
|
+
const vaporHelperId = "/vue-jsx-vapor/vapor";
|
|
21
|
+
const ssrHelperId = "/vue-jsx-vapor/ssr";
|
|
22
|
+
//#endregion
|
|
23
|
+
export { propsHelperCode, propsHelperId, ssrHelperCode, ssrHelperId, vaporHelperCode, vaporHelperId, vdomHelperCode, vdomHelperId };
|
package/dist/ssr.d.ts
ADDED
package/dist/ssr.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useSSRContext } from "vue";
|
|
2
|
+
//#region src/ssr.ts
|
|
3
|
+
function ssrRegisterHelper(comp, filename) {
|
|
4
|
+
if (typeof comp === "function") comp.__setup = () => {
|
|
5
|
+
const ssrContext = useSSRContext();
|
|
6
|
+
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add(filename);
|
|
7
|
+
};
|
|
8
|
+
else {
|
|
9
|
+
const setup = comp.setup;
|
|
10
|
+
comp.setup = (props, ctx) => {
|
|
11
|
+
const ssrContext = useSSRContext();
|
|
12
|
+
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add(filename);
|
|
13
|
+
if (setup) return setup(props, ctx);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ssrRegisterHelper };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Directive, EmitsOptions, EmitsToProps, Ref, SetupContext, SlotsType, VNode, VaporComponentInstance } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare module 'vue' {
|
|
5
|
+
interface VaporComponentInstance {
|
|
6
|
+
block: never;
|
|
7
|
+
}
|
|
8
|
+
interface RenderResultExtensions {
|
|
9
|
+
render: RenderResult;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type RenderResult<T = VaporComponentInstance['block']> = T | VNode | RenderResult[];
|
|
13
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
14
|
+
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
15
|
+
type IsKeyValues<T, K = string> = IfAny<T, false, T extends object ? (keyof T extends K ? true : false) : false>;
|
|
16
|
+
type DirectiveArgs<T extends Directive> = T extends Directive<any, infer Value, infer Modifiers, infer Argument> ? Value | [Value] | [Value, Argument] | [Value, Array<Modifiers>] | [Value, Argument, Array<Modifiers>] : unknown;
|
|
17
|
+
type NodeChildAtom<T> = T | VNode | string | number | boolean | null | undefined | void;
|
|
18
|
+
type NodeArrayChildren<T> = Array<NodeArrayChildren<T> | NodeChildAtom<T>>;
|
|
19
|
+
type NodeChild<T = VaporComponentInstance['block']> = NodeChildAtom<T> | NodeArrayChildren<T>;
|
|
20
|
+
type NodeRef<T> = ((ref: T | null, refs: Record<string, any>) => void) | Ref | string;
|
|
21
|
+
type ResolveSlots<Slots> = { readonly [Key in keyof Slots]?: Slots[Key] extends ((...args: infer Args) => VNode | VNode[]) ? (...args: Args) => NodeChild : Slots[Key] };
|
|
22
|
+
type SlotsToProps<RawSlots extends SlotsType | Record<string, any> = Record<string, any>, Slots = ResolveSlots<RawSlots extends SlotsType ? SetupContext<EmitsOptions, RawSlots>['slots'] : RawSlots>> = string extends keyof Slots ? {} : [keyof Slots] extends [never] ? {} : {
|
|
23
|
+
readonly 'v-slots'?: ('default' extends keyof Slots ? Slots['default'] | Slots : Slots) | NoInfer<NodeChild>;
|
|
24
|
+
};
|
|
25
|
+
declare const exposedType: unique symbol;
|
|
26
|
+
type ExtractExposed<Props, Default = never> = typeof exposedType extends keyof Props ? Exclude<Props[typeof exposedType], undefined> : Default;
|
|
27
|
+
type ExposedToProps<T extends Record<string, any>> = string extends keyof T ? {} : [keyof T] extends [never] ? {} : {
|
|
28
|
+
readonly [exposedType]?: T;
|
|
29
|
+
readonly ref?: NodeRef<T>;
|
|
30
|
+
};
|
|
31
|
+
type EmitFnToProps<T, ExcludeKeys extends PropertyKey = ''> = T extends ((event: infer Event extends string, ...args: infer Args) => any) ? string extends Event ? {} : { readonly [K in Event as `on${Capitalize<K>}` extends ExcludeKeys ? never : `on${Capitalize<K>}`]?: (...args: Args) => any } : {};
|
|
32
|
+
type SetupContextToProps<Emits extends EmitsOptions = {}, Slots extends SlotsType | Record<string, any> = {}, Exposed extends Record<string, any> = {}> = EmitsToProps<Emits> & SlotsToProps<Slots> & ExposedToProps<Exposed>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { DirectiveArgs, EmitFnToProps, ExposedToProps, ExtractExposed, IfAny, IsKeyValues, NodeArrayChildren, NodeChild, NodeRef, Prettify, RenderResult, SetupContextToProps, SlotsToProps };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vapor.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { EmitFnToProps, IsKeyValues, NodeChild, Prettify, SetupContextToProps } from "./types.js";
|
|
2
|
+
import * as Vue from "vue";
|
|
3
|
+
import { Block, ComponentObjectPropsOptions, ComponentTypeEmits, EmitFn, EmitsOptions, EmitsToProps, ExtractDefaultPropTypes, ExtractPropTypes, Fragment, ShallowRef, TypeEmitsToOptions, VaporComponent, VaporComponentInstance, VaporComponentOptions, VaporPublicProps, VaporRenderResult } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/vapor.d.ts
|
|
6
|
+
declare function defineVaporSSRComponent(comp: VaporComponent, extraOptions: VaporComponent): VaporComponent;
|
|
7
|
+
declare const createComponent: (type: VaporComponent | typeof Fragment | string, rawProps?: (Record<string, unknown> & {
|
|
8
|
+
$?: (Record<string, unknown> | (() => Record<string, unknown>))[];
|
|
9
|
+
}) | null | undefined, rawSlots?: (Vue.VaporSlot | (Record<string, ((() => {
|
|
10
|
+
name: string;
|
|
11
|
+
fn: Vue.VaporSlot;
|
|
12
|
+
key?: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
name: string;
|
|
15
|
+
fn: Vue.VaporSlot;
|
|
16
|
+
key?: unknown;
|
|
17
|
+
}[]) | {
|
|
18
|
+
[x: string]: Vue.VaporSlot;
|
|
19
|
+
})[] | Vue.VaporSlot> & {
|
|
20
|
+
$?: ((() => {
|
|
21
|
+
name: string;
|
|
22
|
+
fn: Vue.VaporSlot;
|
|
23
|
+
key?: unknown;
|
|
24
|
+
} | {
|
|
25
|
+
name: string;
|
|
26
|
+
fn: Vue.VaporSlot;
|
|
27
|
+
key?: unknown;
|
|
28
|
+
}[]) | {
|
|
29
|
+
[x: string]: Vue.VaporSlot;
|
|
30
|
+
})[];
|
|
31
|
+
})) | null | undefined, isSingleRoot?: boolean | undefined, once?: boolean | undefined, appContext?: Vue.GenericAppContext | undefined) => Block;
|
|
32
|
+
declare function createProxyComponent(type: VaporComponent, normalizeNode?: (node: any) => Block): any;
|
|
33
|
+
declare function normalizeNode(node: NodeChild): Block;
|
|
34
|
+
declare function isBlock(val: NonNullable<unknown>): val is Block;
|
|
35
|
+
declare function setNodes(anchor: Node, ...values: any[]): void;
|
|
36
|
+
declare function createNodes(...values: any[]): Block[];
|
|
37
|
+
declare function normalizeVaporSlots(slots: any): {
|
|
38
|
+
name: string;
|
|
39
|
+
fn: unknown;
|
|
40
|
+
}[] | {
|
|
41
|
+
name: string;
|
|
42
|
+
fn: any;
|
|
43
|
+
};
|
|
44
|
+
type VaporComponentInstanceConstructor<T extends VaporComponentInstance> = {
|
|
45
|
+
__isFragment?: never;
|
|
46
|
+
__isTeleport?: never;
|
|
47
|
+
__isSuspense?: never;
|
|
48
|
+
new (...args: any[]): T;
|
|
49
|
+
};
|
|
50
|
+
type DefineVaporComponent<RuntimePropsOptions = {}, RuntimePropsKeys extends string = string, InferredProps = (string extends RuntimePropsKeys ? ComponentObjectPropsOptions extends RuntimePropsOptions ? {} : ExtractPropTypes<RuntimePropsOptions> : { [key in RuntimePropsKeys]?: any }), Emits extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Slots extends Record<string, any> = Record<string, any>, Exposed extends Record<string, any> = Record<string, any>, TypeBlock extends Block = Block, TypeRefs extends Record<string, unknown> = {}, MakeDefaultsOptional extends boolean = true, PublicProps = VaporPublicProps, ResolvedProps = Readonly<InferredProps> & EmitsToProps<Emits>, Defaults = ExtractDefaultPropTypes<RuntimePropsOptions>> = VaporComponentInstanceConstructor<VaporComponentInstance<MakeDefaultsOptional extends true ? keyof Defaults extends never ? Prettify<ResolvedProps> & PublicProps : Partial<Defaults> & Omit<Prettify<ResolvedProps> & PublicProps, keyof Defaults> : Prettify<ResolvedProps> & PublicProps, Emits, Slots, Exposed, TypeBlock, TypeRefs>> & VaporComponentOptions<RuntimePropsOptions | RuntimePropsKeys[], Emits, RuntimeEmitsKeys, Slots, Exposed>;
|
|
51
|
+
type DefineVaporSetupFnComponent<Props extends Record<string, any> = {}, Emits extends EmitsOptions = {}, Slots extends Record<string, any> = Record<string, any>, Exposed extends Record<string, any> = Record<string, any>, TypeBlock extends Block = Block, ResolvedProps extends Record<string, any> = Readonly<Props & VaporPublicProps> & SetupContextToProps<Emits, Slots, Exposed>> = new () => VaporComponentInstance<ResolvedProps, Emits, Slots, Exposed, TypeBlock>;
|
|
52
|
+
declare function defineVaporComponent<Props extends Record<string, any>, Emits extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Slots extends Record<string, any> = Record<string, any>, Exposed extends Record<string, any> = Record<string, any>, TypeBlock extends Block = Block, Emit = EmitFn<Emits>>(setup: (this: void, props: Props, ctx: {
|
|
53
|
+
emit: Emit;
|
|
54
|
+
slots: Slots;
|
|
55
|
+
attrs: Record<string, any>;
|
|
56
|
+
expose: (exposed?: Exposed) => void;
|
|
57
|
+
}) => VaporRenderResult<TypeBlock> | void, extraOptions?: VaporComponentOptions<(keyof NoInfer<Props>)[], Emits, RuntimeEmitsKeys, Slots, Exposed> & ThisType<void>): DefineVaporSetupFnComponent<Props & ([keyof Emits] extends [never] ? EmitFnToProps<Emit> : {}), Emits, Slots, Exposed, TypeBlock>;
|
|
58
|
+
declare function defineVaporComponent<Props extends Record<string, any>, Emits extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Slots extends Record<string, any> = Record<string, any>, Exposed extends Record<string, any> = Record<string, any>, TypeBlock extends Block = Block, Emit = EmitFn<Emits>>(this: void, setup: (props: Props, ctx: {
|
|
59
|
+
emit: Emit;
|
|
60
|
+
slots: Slots;
|
|
61
|
+
attrs: Record<string, any>;
|
|
62
|
+
expose: (exposed?: Exposed) => void;
|
|
63
|
+
}) => VaporRenderResult<TypeBlock> | void, extraOptions?: VaporComponentOptions<ComponentObjectPropsOptions<Props>, Emits, RuntimeEmitsKeys, Slots, Exposed> & ThisType<void>): DefineVaporSetupFnComponent<Props & ([keyof Emits] extends [never] ? EmitFnToProps<Emit> : {}), Emits, Slots, Exposed, TypeBlock>;
|
|
64
|
+
declare function defineVaporComponent<TypeProps, RuntimePropsOptions extends ComponentObjectPropsOptions = ComponentObjectPropsOptions, RuntimePropsKeys extends string = string, TypeEmits extends ComponentTypeEmits = {}, RuntimeEmitsOptions extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Slots extends Record<string, any> = Record<string, any>, Exposed extends Record<string, any> = Record<string, any>, ResolvedEmits extends EmitsOptions = ({} extends RuntimeEmitsOptions ? TypeEmitsToOptions<TypeEmits> : RuntimeEmitsOptions), InferredProps = (IsKeyValues<TypeProps> extends true ? TypeProps : string extends RuntimePropsKeys ? ComponentObjectPropsOptions extends RuntimePropsOptions ? {} : ExtractPropTypes<RuntimePropsOptions> : { [key in RuntimePropsKeys]?: any }), TypeRefs extends Record<string, unknown> = {}, TypeBlock extends Block = Block>(options: VaporComponentOptions<RuntimePropsOptions | RuntimePropsKeys[], ResolvedEmits, RuntimeEmitsKeys, Slots, Exposed, TypeBlock, InferredProps> & {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
/**
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
__typeProps?: TypeProps;
|
|
70
|
+
/**
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
__typeEmits?: TypeEmits;
|
|
74
|
+
/**
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
__typeRefs?: TypeRefs;
|
|
78
|
+
/**
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
__typeEl?: TypeBlock;
|
|
82
|
+
} & ThisType<void>): DefineVaporComponent<RuntimePropsOptions, RuntimePropsKeys, InferredProps, ResolvedEmits, RuntimeEmitsKeys, Slots, Block extends Exposed ? Record<string, any> : Exposed, TypeBlock, TypeRefs, unknown extends TypeProps ? true : false>;
|
|
83
|
+
type ResolveItem<Item, GetKey> = GetKey extends undefined ? Item : ShallowRef<Item>;
|
|
84
|
+
declare const VaporFor: new <T extends any[] | Record<any, any> | number | string | Set<any> | Map<any, any>, Item = (T extends number ? number : T extends string ? string : T extends any[] ? T[number] : T extends Iterable<infer T1> ? T1 : Record<any, any>), GetKeyDefault = (...args: string extends keyof Item ? [item: T[keyof T], key: keyof T, index: number] : [item: Item, index: number]) => any, GetKey extends GetKeyDefault | null | undefined = undefined>() => VaporComponentInstance<Readonly<{
|
|
85
|
+
in: T;
|
|
86
|
+
getKey?: GetKey extends undefined ? GetKeyDefault : GetKey;
|
|
87
|
+
} & Vue.ReservedProps & Vue.AllowedComponentProps & Vue.ComponentCustomProps> & {} & {
|
|
88
|
+
readonly 'v-slots'?: {
|
|
89
|
+
readonly default?: ((...args: string extends keyof Item ? [item: ResolveItem<T[keyof T], GetKey>, key: ShallowRef<keyof T>, index: ShallowRef<number>] : [item: ResolveItem<Item, GetKey>, index: ShallowRef<number>]) => NodeChild) | undefined;
|
|
90
|
+
} | ((...args: string extends keyof Item ? [item: ResolveItem<T[keyof T], GetKey>, key: ShallowRef<keyof T>, index: ShallowRef<number>] : [item: ResolveItem<Item, GetKey>, index: ShallowRef<number>]) => NodeChild) | NoInfer<NodeChild<Block>> | undefined;
|
|
91
|
+
}, {}, {
|
|
92
|
+
default: (...args: string extends keyof Item ? [item: ResolveItem<T[keyof T], GetKey>, key: ShallowRef<keyof T>, index: ShallowRef<number>] : [item: ResolveItem<Item, GetKey>, index: ShallowRef<number>]) => any;
|
|
93
|
+
}, Record<string, any>, {
|
|
94
|
+
resetListeners?: (() => void)[];
|
|
95
|
+
onReset(fn: () => void): void;
|
|
96
|
+
$key?: any;
|
|
97
|
+
$transition?: Vue.VaporTransitionHooks | undefined;
|
|
98
|
+
nodes: Block[];
|
|
99
|
+
vnode?: Vue.VNode | null;
|
|
100
|
+
anchor?: Node;
|
|
101
|
+
isBlockValid?: (componentAsValid?: boolean) => boolean;
|
|
102
|
+
insert?: (parent: ParentNode, anchor: Node | null, parentSuspense?: Vue.SuspenseBoundary | null, transitionHooks?: Vue.TransitionHooks, moveType?: Vue.MoveType) => void;
|
|
103
|
+
remove?: (parent?: ParentNode, transitionHooks?: Vue.TransitionHooks) => void;
|
|
104
|
+
hydrate?(...args: any[]): void;
|
|
105
|
+
setRef?: (instance: VaporComponentInstance, ref: string | Vue.Ref<any, any> | ((ref: Element | VaporComponentInstance, refs: Record<string, any>) => void), refFor: boolean, refKey: string | undefined) => void;
|
|
106
|
+
onRemove?: (() => void)[];
|
|
107
|
+
onBeforeUpdate?: (() => void)[];
|
|
108
|
+
onUpdated?: ((nodes?: Block) => void)[];
|
|
109
|
+
}, Record<string, any>>;
|
|
110
|
+
//#endregion
|
|
111
|
+
export { DefineVaporComponent, DefineVaporSetupFnComponent, VaporFor, createComponent, createNodes, createProxyComponent, defineVaporComponent, defineVaporSSRComponent, isBlock, normalizeNode, normalizeVaporSlots, setNodes };
|
package/dist/vapor.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as Vue from "vue";
|
|
2
|
+
import { EffectScope, Fragment, getCurrentInstance } from "vue";
|
|
3
|
+
//#region src/vapor.ts
|
|
4
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
5
|
+
function defineVaporSSRComponent(comp, extraOptions) {
|
|
6
|
+
if (typeof comp === "function") return Object.assign({ name: comp.name }, extraOptions, {
|
|
7
|
+
setup(props, ctx) {
|
|
8
|
+
const result = comp(props, ctx);
|
|
9
|
+
return () => result;
|
|
10
|
+
},
|
|
11
|
+
__vapor: true
|
|
12
|
+
});
|
|
13
|
+
const setup = comp.setup;
|
|
14
|
+
if (setup) comp.setup = (props, ctx) => {
|
|
15
|
+
const result = setup(props, ctx);
|
|
16
|
+
return () => result;
|
|
17
|
+
};
|
|
18
|
+
comp.__vapor = true;
|
|
19
|
+
return comp;
|
|
20
|
+
}
|
|
21
|
+
const createComponent = (type, ...args) => {
|
|
22
|
+
if (type === Fragment) {
|
|
23
|
+
const slots = args[1];
|
|
24
|
+
return slots ? typeof slots === "function" ? slots() : typeof slots.default === "function" ? slots.default() : [] : [];
|
|
25
|
+
}
|
|
26
|
+
return Vue.createComponentWithFallback(createProxyComponent(Vue.resolveDynamicComponent(type)), ...args);
|
|
27
|
+
};
|
|
28
|
+
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
function createProxyComponent(type, normalizeNode) {
|
|
30
|
+
if (typeof type === "function") {
|
|
31
|
+
const existing = proxyCache.get(type);
|
|
32
|
+
if (existing) return existing;
|
|
33
|
+
const i = Vue.currentInstance || getCurrentInstance();
|
|
34
|
+
const proxy = new Proxy(type, {
|
|
35
|
+
apply(target, ctx, args) {
|
|
36
|
+
if (typeof target.__setup === "function") target.__setup.apply(ctx, args);
|
|
37
|
+
const node = Reflect.apply(target, ctx, args);
|
|
38
|
+
return normalizeNode ? normalizeNode(node) : node;
|
|
39
|
+
},
|
|
40
|
+
get(target, p, receiver) {
|
|
41
|
+
if (i && i.appContext.vapor && p === "__vapor") return true;
|
|
42
|
+
return Reflect.get(target, p, receiver);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
proxyCache.set(type, proxy);
|
|
46
|
+
return proxy;
|
|
47
|
+
}
|
|
48
|
+
return type;
|
|
49
|
+
}
|
|
50
|
+
function normalizeNode(node) {
|
|
51
|
+
if (node == null || typeof node === "boolean") return document.createComment("");
|
|
52
|
+
else if (Array.isArray(node) && node.length) return node.map(normalizeNode);
|
|
53
|
+
else if (isBlock(node)) return node;
|
|
54
|
+
else if (typeof node === "function") return resolveValues([node], void 0, true)[0];
|
|
55
|
+
else return document.createTextNode(String(node));
|
|
56
|
+
}
|
|
57
|
+
function isBlock(val) {
|
|
58
|
+
return val instanceof Node || Array.isArray(val) || Vue.isVaporComponent(val) || Vue.isFragment(val);
|
|
59
|
+
}
|
|
60
|
+
function createFragment(nodes, anchor = document.createTextNode("")) {
|
|
61
|
+
const frag = new Vue.VaporFragment(nodes);
|
|
62
|
+
frag.anchor = anchor;
|
|
63
|
+
return frag;
|
|
64
|
+
}
|
|
65
|
+
function normalizeBlock(node, anchor, processFunction = false) {
|
|
66
|
+
if (node instanceof Node || Vue.isFragment(node)) return node;
|
|
67
|
+
else if (Vue.isVaporComponent(node)) return createFragment(node, anchor);
|
|
68
|
+
else if (Array.isArray(node)) return createFragment(node.map((i) => normalizeBlock(i, void 0, processFunction)), anchor);
|
|
69
|
+
else if (processFunction && typeof node === "function") return resolveValues([node], anchor, true)[0];
|
|
70
|
+
else {
|
|
71
|
+
const result = node == null || typeof node === "boolean" ? "" : String(node);
|
|
72
|
+
if (anchor) {
|
|
73
|
+
anchor.textContent = result;
|
|
74
|
+
return anchor;
|
|
75
|
+
} else return document.createTextNode(result);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function resolveValue(current, value, anchor, processFunction = false) {
|
|
79
|
+
anchor = anchor || (current instanceof Node && current.nodeType === 3 ? current : void 0);
|
|
80
|
+
const node = normalizeBlock(value, anchor, processFunction);
|
|
81
|
+
if (current) {
|
|
82
|
+
if (Vue.isFragment(current)) {
|
|
83
|
+
if (current.anchor && current.anchor.parentNode) {
|
|
84
|
+
Vue.remove(current.nodes, current.anchor.parentNode);
|
|
85
|
+
Vue.insert(node, current.anchor.parentNode, current.anchor);
|
|
86
|
+
if (!anchor) current.anchor.parentNode.removeChild(current.anchor);
|
|
87
|
+
if (current.scope) current.scope.stop();
|
|
88
|
+
}
|
|
89
|
+
} else if (current instanceof Node) {
|
|
90
|
+
if (current.nodeType === 3 && (!(node instanceof Node) || node.nodeType !== 3)) current.textContent = "";
|
|
91
|
+
if (Vue.isFragment(node) && current.parentNode) {
|
|
92
|
+
Vue.insert(node, current.parentNode, current);
|
|
93
|
+
if (!anchor || current.nodeType !== 3) current.parentNode.removeChild(current);
|
|
94
|
+
} else if (node instanceof Node) {
|
|
95
|
+
if (current.nodeType === 3 && node.nodeType === 3) {
|
|
96
|
+
current.textContent = node.textContent;
|
|
97
|
+
return current;
|
|
98
|
+
} else if (current.parentNode) current.parentNode.replaceChild(node, current);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
function resolveValues(values = [], _anchor, processFunction = false) {
|
|
105
|
+
const nodes = [];
|
|
106
|
+
const scopes = [];
|
|
107
|
+
for (const [index, value] of values.entries()) {
|
|
108
|
+
const anchor = index === values.length - 1 ? _anchor : void 0;
|
|
109
|
+
if (typeof value === "function") Vue.renderEffect(() => {
|
|
110
|
+
if (scopes[index]) scopes[index].stop();
|
|
111
|
+
scopes[index] = new EffectScope();
|
|
112
|
+
nodes[index] = scopes[index].run(() => resolveValue(nodes[index], value(), anchor, processFunction));
|
|
113
|
+
});
|
|
114
|
+
else nodes[index] = resolveValue(nodes[index], value, anchor, processFunction);
|
|
115
|
+
}
|
|
116
|
+
return nodes;
|
|
117
|
+
}
|
|
118
|
+
function setNodes(anchor, ...values) {
|
|
119
|
+
const resolvedValues = resolveValues(values, anchor);
|
|
120
|
+
if (anchor.parentNode) Vue.insert(resolvedValues, anchor.parentNode, anchor);
|
|
121
|
+
}
|
|
122
|
+
function createNodes(...values) {
|
|
123
|
+
return resolveValues(values);
|
|
124
|
+
}
|
|
125
|
+
function normalizeVaporSlots(slots) {
|
|
126
|
+
if (typeof slots === "function") return {
|
|
127
|
+
name: "default",
|
|
128
|
+
fn: slots
|
|
129
|
+
};
|
|
130
|
+
else if (Object.prototype.toString.call(slots) === "[object Object]" && !isBlock(slots)) return Object.entries(slots).map(([name, fn]) => ({
|
|
131
|
+
name,
|
|
132
|
+
fn
|
|
133
|
+
}));
|
|
134
|
+
else return {
|
|
135
|
+
name: "default",
|
|
136
|
+
fn: () => createNodes(slots)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
140
|
+
function defineVaporComponent(comp, extraOptions) {
|
|
141
|
+
if (typeof comp === "function") return Object.assign({ name: comp.name }, extraOptions, {
|
|
142
|
+
setup: comp,
|
|
143
|
+
__vapor: true
|
|
144
|
+
});
|
|
145
|
+
comp.__vapor = true;
|
|
146
|
+
return comp;
|
|
147
|
+
}
|
|
148
|
+
const VaporFor = /* @__PURE__ */ defineVaporComponent((props, { slots }) => {
|
|
149
|
+
return Vue.createFor(() => props.in, (item, key, index) => {
|
|
150
|
+
return slots.default ? slots.default(props.getKey === void 0 ? item.value : item, key, index) : [];
|
|
151
|
+
}, props.getKey === void 0 ? (item) => item : props.getKey);
|
|
152
|
+
}, { props: ["in", "getKey"] });
|
|
153
|
+
//#endregion
|
|
154
|
+
export { VaporFor, createComponent, createNodes, createProxyComponent, defineVaporComponent, defineVaporSSRComponent, isBlock, normalizeNode, normalizeVaporSlots, setNodes };
|
package/dist/vdom.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { EmitFnToProps, IsKeyValues, NodeChild, RenderResult, SetupContextToProps } from "./types.js";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { Component, ComponentInjectOptions, ComponentObjectPropsOptions, ComponentOptions, ComponentOptionsBase, ComponentOptionsMixin, ComponentPropsOptions, ComponentProvideOptions, ComponentPublicInstance, ComponentTypeEmits, ComputedOptions, CreateComponentPublicInstanceWithMixins, Directive, EmitFn, EmitsOptions, EmitsToProps, ExtractDefaultPropTypes, ExtractPropTypes, GlobalComponents, GlobalDirectives, MethodOptions, PublicProps, Slot, SlotsType, TypeEmitsToOptions, VNode, VNodeChild } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/vdom.d.ts
|
|
6
|
+
declare function createVNodeCache(key: string): any;
|
|
7
|
+
declare function normalizeVNode(value: VNodeChild | (() => VNodeChild), flag?: number): VNode;
|
|
8
|
+
declare const normalizeSlot: (rawSlot: Function) => Slot;
|
|
9
|
+
declare const normalizeSlots: (slots: any) => Record<string, any> | Function;
|
|
10
|
+
declare const normalizeClass: (value: unknown) => string | null;
|
|
11
|
+
type RenderFunction = () => RenderResult;
|
|
12
|
+
type ComponentPublicInstanceConstructor<T extends ComponentPublicInstance<Props, RawBindings, D, C, M> = ComponentPublicInstance<any>, Props = any, RawBindings = any, D = any, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions> = {
|
|
13
|
+
__isFragment?: never;
|
|
14
|
+
__isTeleport?: never;
|
|
15
|
+
__isSuspense?: never;
|
|
16
|
+
new (...args: any[]): T;
|
|
17
|
+
};
|
|
18
|
+
type DefineComponent<PropsOrPropOptions = {}, RawBindings = {}, D = {}, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, PP = PublicProps, Props = Readonly<PropsOrPropOptions extends ComponentPropsOptions ? ExtractPropTypes<PropsOrPropOptions> : PropsOrPropOptions> & EmitsToProps<E>, Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>, S extends SlotsType = {}, LC extends Record<string, Component> = {}, Directives extends Record<string, Directive> = {}, Exposed extends string = string, Provide extends ComponentProvideOptions = ComponentProvideOptions, MakeDefaultsOptional extends boolean = true, TypeRefs extends Record<string, unknown> = {}, TypeEl extends Element = any> = ComponentPublicInstanceConstructor<CreateComponentPublicInstanceWithMixins<Props, RawBindings, D, C, M, Mixin, Extends, E, PP, Defaults, MakeDefaultsOptional, {}, S, LC & GlobalComponents, Directives & GlobalDirectives, Exposed, TypeRefs, TypeEl>> & ComponentOptionsBase<Props, RawBindings, D, C, M, Mixin, Extends, E, EE, Defaults, {}, string, S, LC & GlobalComponents, Directives & GlobalDirectives, Exposed, Provide> & PP;
|
|
19
|
+
type DefineSetupFnComponent<P extends Record<string, any>, E extends EmitsOptions = {}, S extends SlotsType = SlotsType, Exposed extends Record<string, any> = {}, Props = Readonly<P> & SetupContextToProps<E, S, Exposed>, PP = PublicProps> = new (props: Props & PP) => CreateComponentPublicInstanceWithMixins<Props, Exposed, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, E, PP, {}, false, {}, S, {}, {}, keyof Exposed & string>;
|
|
20
|
+
declare function _defineComponent<Props extends Record<string, any>, Emits extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Slots extends SlotsType | Record<string, any> = {}, Exposed extends Record<string, any> = {}, Emit = EmitFn<Emits>>(setup: (this: void, props: Props, ctx: {
|
|
21
|
+
emit: Emit;
|
|
22
|
+
slots: Slots;
|
|
23
|
+
attrs: Record<string, any>;
|
|
24
|
+
expose: (exposed?: Exposed) => void;
|
|
25
|
+
}) => RenderFunction | Promise<RenderFunction>, options?: Omit<ComponentOptions, 'props' | 'emits' | 'slots'> & {
|
|
26
|
+
props?: (keyof NoInfer<Props>)[];
|
|
27
|
+
emits?: Emits | RuntimeEmitsKeys[];
|
|
28
|
+
slots?: Slots;
|
|
29
|
+
}): DefineSetupFnComponent<Props & ([keyof Emits] extends [never] ? EmitFnToProps<Emit> : {}), Emits, Slots extends SlotsType ? Slots : SlotsType<Slots>, Exposed>;
|
|
30
|
+
declare function _defineComponent<Props extends Record<string, any>, Emits extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Slots extends SlotsType | Record<string, any> = {}, Exposed extends Record<string, any> = {}, Emit = EmitFn<Emits>>(setup: (this: void, props: Props, ctx: {
|
|
31
|
+
emit: Emit;
|
|
32
|
+
slots: Slots;
|
|
33
|
+
attrs: Record<string, any>;
|
|
34
|
+
expose: (exposed?: Exposed) => void;
|
|
35
|
+
}) => RenderFunction | Promise<RenderFunction>, options?: Omit<ComponentOptions, 'props' | 'emits' | 'slots'> & {
|
|
36
|
+
props?: ComponentObjectPropsOptions<Props>;
|
|
37
|
+
emits?: Emits | RuntimeEmitsKeys[];
|
|
38
|
+
slots?: Slots;
|
|
39
|
+
}): DefineSetupFnComponent<Props & ([keyof Emits] extends [never] ? EmitFnToProps<Emit> : {}), Emits, Slots extends SlotsType ? Slots : SlotsType<Slots>, Exposed>;
|
|
40
|
+
declare function _defineComponent<TypeProps, RuntimePropsOptions extends ComponentObjectPropsOptions = ComponentObjectPropsOptions, RuntimePropsKeys extends string = string, TypeEmits extends ComponentTypeEmits = {}, RuntimeEmitsOptions extends EmitsOptions = {}, RuntimeEmitsKeys extends string = string, Data = {}, SetupBindings = {}, Computed extends ComputedOptions = {}, Methods extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, InjectOptions extends ComponentInjectOptions = {}, InjectKeys extends string = string, Slots extends SlotsType = {}, LocalComponents extends Record<string, Component> = {}, Directives extends Record<string, Directive> = {}, Exposed extends string = string, Provide extends ComponentProvideOptions = ComponentProvideOptions, ResolvedEmits extends EmitsOptions = ({} extends RuntimeEmitsOptions ? TypeEmitsToOptions<TypeEmits> : RuntimeEmitsOptions), InferredProps = (IsKeyValues<TypeProps> extends true ? TypeProps : string extends RuntimePropsKeys ? ComponentObjectPropsOptions extends RuntimePropsOptions ? {} : ExtractPropTypes<RuntimePropsOptions> : { [key in RuntimePropsKeys]?: any }), TypeRefs extends Record<string, unknown> = {}, TypeEl extends Element = any>(options: {
|
|
41
|
+
props?: (RuntimePropsOptions & ThisType<void>) | RuntimePropsKeys[];
|
|
42
|
+
/**
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
__typeProps?: TypeProps;
|
|
46
|
+
/**
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
__typeEmits?: TypeEmits;
|
|
50
|
+
/**
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
__typeRefs?: TypeRefs;
|
|
54
|
+
/**
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
__typeEl?: TypeEl;
|
|
58
|
+
} & ComponentOptionsBase<Readonly<InferredProps> & EmitsToProps<ResolvedEmits>, SetupBindings, Data, Computed, Methods, Mixin, Extends, RuntimeEmitsOptions, RuntimeEmitsKeys, {}, // Defaults
|
|
59
|
+
InjectOptions, InjectKeys, Slots, LocalComponents, Directives, Exposed, Provide> & ThisType<CreateComponentPublicInstanceWithMixins<Readonly<InferredProps> & EmitsToProps<ResolvedEmits>, SetupBindings, Data, Computed, Methods, Mixin, Extends, ResolvedEmits, {}, {}, false, InjectOptions, Slots, LocalComponents, Directives, string>>): DefineComponent<InferredProps, SetupBindings, Data, Computed, Methods, Mixin, Extends, ResolvedEmits, RuntimeEmitsKeys, PublicProps, Readonly<InferredProps> & EmitsToProps<ResolvedEmits>, ExtractDefaultPropTypes<RuntimePropsOptions>, Slots, LocalComponents, Directives, Exposed, Provide, unknown extends TypeProps ? true : false, TypeRefs, TypeEl>;
|
|
60
|
+
declare const defineComponent: typeof _defineComponent;
|
|
61
|
+
declare const For: new <T extends any[] | Record<any, any> | number | string | Set<any> | Map<any, any>, Item = (T extends number ? number : T extends string ? string : T extends any[] ? T[number] : T extends Iterable<infer T1> ? T1 : Record<any, any>)>(props: Readonly<{
|
|
62
|
+
in: T;
|
|
63
|
+
}> & {} & {
|
|
64
|
+
readonly 'v-slots'?: {
|
|
65
|
+
readonly default?: ((...args: string extends keyof Item ? [item: T[keyof T], key: keyof T, index: number] : [item: Item, index: number]) => NodeChild) | undefined;
|
|
66
|
+
} | ((...args: string extends keyof Item ? [item: T[keyof T], key: keyof T, index: number] : [item: Item, index: number]) => NodeChild) | NoInfer<NodeChild<_$vue.Block>> | undefined;
|
|
67
|
+
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps) => CreateComponentPublicInstanceWithMixins<Readonly<{
|
|
68
|
+
in: T;
|
|
69
|
+
}> & {} & {
|
|
70
|
+
readonly 'v-slots'?: {
|
|
71
|
+
readonly default?: ((...args: string extends keyof Item ? [item: T[keyof T], key: keyof T, index: number] : [item: Item, index: number]) => NodeChild) | undefined;
|
|
72
|
+
} | ((...args: string extends keyof Item ? [item: T[keyof T], key: keyof T, index: number] : [item: Item, index: number]) => NodeChild) | NoInfer<NodeChild<_$vue.Block>> | undefined;
|
|
73
|
+
}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, PublicProps, {}, false, {}, SlotsType<{
|
|
74
|
+
default: (...args: string extends keyof Item ? [item: T[keyof T], key: keyof T, index: number] : [item: Item, index: number]) => any;
|
|
75
|
+
}>, {}, {}, never>;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { DefineComponent, DefineSetupFnComponent, For, createVNodeCache, defineComponent, normalizeClass, normalizeSlot, normalizeSlots, normalizeVNode };
|
package/dist/vdom.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Comment, Fragment, Text, cloneVNode, createBlock, createElementBlock, createElementVNode, createVNode, defineComponent as defineComponent$1, getCurrentInstance, isVNode, normalizeClass as normalizeClass$1, openBlock, renderList, withCtx } from "vue";
|
|
2
|
+
//#region src/vdom.ts
|
|
3
|
+
const cacheMap = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function createVNodeCache(key) {
|
|
5
|
+
const i = getCurrentInstance();
|
|
6
|
+
if (i) {
|
|
7
|
+
if (!cacheMap.has(i)) cacheMap.set(i, {});
|
|
8
|
+
const caches = cacheMap.get(i);
|
|
9
|
+
return caches[key] || (caches[key] = []);
|
|
10
|
+
} else return [];
|
|
11
|
+
}
|
|
12
|
+
function normalizeVNode(value, flag = 1) {
|
|
13
|
+
let create = createVNode;
|
|
14
|
+
let isBlock = false;
|
|
15
|
+
if (typeof value === "function") {
|
|
16
|
+
isBlock = true;
|
|
17
|
+
openBlock();
|
|
18
|
+
create = createBlock;
|
|
19
|
+
value = value();
|
|
20
|
+
}
|
|
21
|
+
return isVNode(value) ? isBlock ? createBlock(cloneIfMounted(value)) : cloneIfMounted(value) : Array.isArray(value) ? isBlock ? createElementBlock(Fragment, null, value.map((n) => normalizeVNode(() => n)), -2) : createElementVNode(Fragment, null, value.slice()) : value == null || typeof value === "boolean" ? create(Comment) : create(Text, null, String(value), flag);
|
|
22
|
+
}
|
|
23
|
+
function cloneIfMounted(child) {
|
|
24
|
+
return child.el === null && child.patchFlag !== -1 || child.memo ? child : cloneVNode(child);
|
|
25
|
+
}
|
|
26
|
+
const normalizeSlotValue = (value) => Array.isArray(value) ? value.map((n) => normalizeVNode(n)) : [normalizeVNode(value)];
|
|
27
|
+
const normalizeSlot = (rawSlot) => {
|
|
28
|
+
if (rawSlot._n) return rawSlot;
|
|
29
|
+
return withCtx((...args) => {
|
|
30
|
+
return normalizeSlotValue(rawSlot(...args));
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const normalizeSlots = (slots) => {
|
|
34
|
+
return typeof slots === "function" || Object.prototype.toString.call(slots) === "[object Object]" && !isVNode(slots) ? slots : { default: withCtx(() => [normalizeVNode(() => slots)]) };
|
|
35
|
+
};
|
|
36
|
+
const normalizeClass = (value) => normalizeClass$1(value) || null;
|
|
37
|
+
const defineComponent = defineComponent$1;
|
|
38
|
+
const For = defineComponent((props, { slots }) => {
|
|
39
|
+
const defaultSlot = slots.default;
|
|
40
|
+
return () => (openBlock(true), createElementBlock(Fragment, null, renderList(props.in, (item, key, index) => {
|
|
41
|
+
const result = defaultSlot(item, key, index);
|
|
42
|
+
return Array.isArray(result) ? result.length === 1 ? result[0] : normalizeVNode(result) : result;
|
|
43
|
+
}), 128));
|
|
44
|
+
}, { props: ["in"] });
|
|
45
|
+
//#endregion
|
|
46
|
+
export { For, createVNodeCache, defineComponent, normalizeClass, normalizeSlot, normalizeSlots, normalizeVNode };
|