@lytjs/component 5.0.1 → 6.4.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/README.md +509 -288
- package/dist/index.cjs +1945 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +812 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.mjs +1865 -1
- package/dist/index.mjs.map +1 -0
- package/package.json +27 -38
- package/dist/builtins-entry.cjs +0 -1
- package/dist/builtins-entry.mjs +0 -1
- package/dist/types/builtins/async-component.d.ts +0 -61
- package/dist/types/builtins/async-component.d.ts.map +0 -1
- package/dist/types/builtins/error-boundary.d.ts +0 -28
- package/dist/types/builtins/error-boundary.d.ts.map +0 -1
- package/dist/types/builtins/index.d.ts +0 -19
- package/dist/types/builtins/index.d.ts.map +0 -1
- package/dist/types/builtins/keep-alive.d.ts +0 -118
- package/dist/types/builtins/keep-alive.d.ts.map +0 -1
- package/dist/types/builtins/suspense.d.ts +0 -51
- package/dist/types/builtins/suspense.d.ts.map +0 -1
- package/dist/types/builtins/transition-group.d.ts +0 -40
- package/dist/types/builtins/transition-group.d.ts.map +0 -1
- package/dist/types/builtins/transition.d.ts +0 -136
- package/dist/types/builtins/transition.d.ts.map +0 -1
- package/dist/types/builtins-entry.d.ts +0 -9
- package/dist/types/builtins-entry.d.ts.map +0 -1
- package/dist/types/composition-api.d.ts +0 -116
- package/dist/types/composition-api.d.ts.map +0 -1
- package/dist/types/define-component.d.ts +0 -281
- package/dist/types/define-component.d.ts.map +0 -1
- package/dist/types/emit.d.ts +0 -92
- package/dist/types/emit.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -21
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/lifecycle.d.ts +0 -92
- package/dist/types/lifecycle.d.ts.map +0 -1
- package/dist/types/props.d.ts +0 -85
- package/dist/types/props.d.ts.map +0 -1
- package/dist/types/signal-state.d.ts +0 -58
- package/dist/types/signal-state.d.ts.map +0 -1
- package/dist/types/slots.d.ts +0 -80
- package/dist/types/slots.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1,1865 @@
|
|
|
1
|
-
import{shallowReactive as Ce,computed as B,watch as Pe}from"@lytjs/reactivity";import{computed as he,effect as Ee}from"@lytjs/reactivity/signal";import{signal as W}from"@lytjs/reactivity/signal";function U(e){let t={},o=Object.keys(e);for(let n=0;n<o.length;n++){let r=o[n];t[r]=W(e[r])}return t}function S(e){return typeof e=="function"&&e!==null&&"set"in e}function T(e){return new Proxy(e,{get(t,o){if(typeof o=="symbol")return t[o];let n=t[o];return S(n)?n():t[o]},set(t,o,n){if(typeof o=="symbol")return t[o]=n,!0;let r=t[o];return S(r)?r.set(n):t[o]=n,!0},has(t,o){return o in t},ownKeys(t){return Object.keys(t)},getOwnPropertyDescriptor(t,o){if(typeof o=="string"&&o in t)return{configurable:!0,enumerable:!0,get:()=>{let n=t[o];return S(n)?n():n},set:n=>{let r=t[o];S(r)?r.set(n):t[o]=n}}}})}function q(e){let t={},o=Object.keys(e);for(let n=0;n<o.length;n++){let r=o[n],l=e[r];t[r]=S(l)?l():l}return t}function H(e,t){let o=Object.keys(t);for(let n=0;n<o.length;n++){let r=o[n],l=e[r];S(l)&&l.set(t[r])}}function Z(e){if(!e)return;let t=Object.keys(e);for(let o=0;o<t.length;o++){let n=t[o],r=e[n];if(r&&typeof r=="function"&&"dispose"in r)try{r.dispose()}catch(l){}delete e[n]}}import{isPlainObject as G,isFunction as R,isString as J,isBoolean as Q,isNumber as X,isArray as x,isObject as Y}from"@lytjs/common";function ee(e){return e===String?"String":e===Number?"Number":e===Boolean?"Boolean":e===Array?"Array":e===Object?"Object":e===Function?"Function":"unknown"}function L(e){if(!e)return{options:{},keys:[]};if(x(e)){let r={},l=[];for(let s=0;s<e.length;s++){let i=e[s];r[i]={type:null},l.push(i)}return{options:r,keys:l}}let t={},o=[],n=Object.keys(e);for(let r=0;r<n.length;r++){let l=n[r],s=e[l];s==null?t[l]={type:null}:s===String||s===Number||s===Boolean||s===Array||s===Object||s===Function?t[l]={type:s}:G(s)?t[l]={...s}:x(s)?t[l]={type:s}:t[l]={type:null},o.push(l)}return{options:t,keys:o}}function $(e,t,o){let{type:n,required:r,validator:l}=t;if(o==null)return!r;if(n!=null){let s=x(n)?n:[n],i=!1;for(let p=0;p<s.length;p++){let a=s[p],c=!1;if(a===String?c=J(o):a===Number?c=X(o):a===Boolean?c=Q(o):a===Function?c=R(o):a===Array?c=x(o):a===Object&&(c=Y(o)),c){i=!0;break}}if(!i){let p=s.map(ee).join(" | ");return!1}}if(l&&R(l))try{if(!l(o))return!1}catch(s){return!1}return!0}function z(e,t){let{default:o}=e;if(o!==void 0){if(R(o)){let n=e.type;if(!(n===Function||x(n)&&n.indexOf(Function)!==-1))return o()}return o}}function C(e,t){let{options:o,keys:n}=e.propsOptions,r={};for(let l=0;l<n.length;l++){let s=n[l],i=o[s],p=t?t[s]:void 0;p===void 0&&(p=z(i,s)),i.type!==null&&i.type!==void 0&&(x(i.type)?i.type:[i.type]).indexOf(Boolean)!==-1&&p===void 0&&(p=!1),$(s,i,p),r[s]=p}return e.props=r,r}import{isFunction as F,isArray as te}from"@lytjs/common";function oe(e){return e}function P(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}function ne(e){return e.replace(/-(\w)/g,(t,o)=>o.toUpperCase())}function v(e){if(!e)return{keys:[],validators:{}};let t=[],o={};if(te(e)){for(let r=0;r<e.length;r++){let l=P(e[r]);t.push(l),o[l]=null}return{keys:t,validators:o}}let n=Object.keys(e);for(let r=0;r<n.length;r++){let l=n[r],s=P(l),i=e[l];t.push(s),F(i)?o[s]=i:o[s]=null}return{keys:t,validators:o}}function M(e,t,...o){let n=P(t),r=e.emitsOptions;if(r&&r.keys.length>0){let a=r.keys.indexOf(n)!==-1,c=r.validators[n];if(F(c))try{if(!c(...o))return!1}catch(f){return!1}}let l="on"+n.charAt(0).toUpperCase()+n.slice(1),s=l.replace(/-([a-z])/g,(a,c)=>c.toUpperCase()),i=e.props||{},p=i[s]||i[l];return F(p)?(p(...o),!0):!1}var w=(s=>(s.INIT="init",s.MOUNTED="mounted",s.BEFORE_UPDATE="beforeUpdate",s.UPDATED="updated",s.BEFORE_UNMOUNT="beforeUnmount",s.UNMOUNTED="unmounted",s))(w||{}),h=null;function re(e){return typeof e=="function"}function E(e){let t=h;return h=e,t}function g(e){return function(o,n){if(!re(o))return;let r=n||h;r&&(r[e]||(r[e]=[]),r[e].push(o))}}function d(e,t,...o){let n=e[t];if(!(!n||n.length===0))for(let r=0;r<n.length;r++)try{n[r](...o)}catch(l){}}var se=g("init"),ie=g("mounted"),le=g("beforeUpdate"),pe=g("updated"),ae=g("beforeUnmount"),ce=g("unmounted");import{isFunction as j,isPlainObject as ue}from"@lytjs/common";function k(e){return e==null?null:j(e)?e:Array.isArray(e)?e.length>0?e:null:e}function D(e,t){let o={};if(t==null)return e.slots=o,o;if(j(t)||Array.isArray(t))return o.default=k(t),e.slots=o,o;if(ue(t)){let n=Object.keys(t);for(let r=0;r<n.length;r++){let l=n[r],s=t[l];s!==void 0&&(o[l]=k(s))}return e.slots=o,o}return o.default=k(t),e.slots=o,o}function fe(e,t="default",o){let n=e[t];return n==null?null:j(n)?n(o):n}function ye(e,t="default"){let o=e[t];return o!=null}var u=null;function de(e){if(u){let t=u._lifecycleHooks||(u._lifecycleHooks={});(t.mounted||(t.mounted=[])).push(e)}}function me(e){if(u){let t=u._lifecycleHooks||(u._lifecycleHooks={});(t.unmounted||(t.unmounted=[])).push(e)}}function ge(e){if(u){let t=u._lifecycleHooks||(u._lifecycleHooks={});(t.updated||(t.updated=[])).push(e)}}function Se(e){if(u){let t=u._lifecycleHooks||(u._lifecycleHooks={});(t.beforeMount||(t.beforeMount=[])).push(e)}}function xe(e){if(u){let t=u._lifecycleHooks||(u._lifecycleHooks={});(t.beforeUnmount||(t.beforeUnmount=[])).push(e)}}var I=new WeakMap;function be(e,t){if(u){let o=I.get(u);o||(o=new Map,I.set(u,o)),o.set(e,t)}}function ke(e,t){if(u){let o=u;for(;o;){let n=I.get(o);if(n&&n.has(e))return n.get(e);o=o._parent}}return t}function _(e,t,o,n){u=t;try{return e(o,n)}finally{let r=t._lifecycleHooks||(t._lifecycleHooks={});(r.unmounted||(r.unmounted=[])).push(()=>{I.delete(t)}),u=null}}function Oe(){return u}import{isFunction as m,isPlainObject as N,mergeObjects as Ie}from"@lytjs/common";function Ne(e){return{name:e.name,options:e,_isComponentDefine:!0}}function Ue(e){return{options:e,_isComponentDefine:!0}}function Te(e){let t=e.options,o=L(t.props),n=v(t.emits),r={_isComponent:!0,type:t,name:e.name||t.name,propsOptions:o,emitsOptions:n,props:{},state:{},setupState:{},computedRefs:{},subTree:null,isMounted:!1,isUnmounted:!1,slots:{},watchStopHandles:[],renderProxy:null,emit:null};return r.emit=(l,...s)=>M(r,l,...s),r.renderProxy=He(r),r}function He(e){return{get $name(){return e.name},get $props(){return e.props},get $state(){return e.state},get $slots(){return e.slots},get $isMounted(){return e.isMounted},$emit:e.emit,$forceUpdate(){e.update&&e.update()},$unmount(){K(e)},$setState(o){e._signalState?H(e._signalState,o):Ie(e.state,o),e.update&&e.update()}}}function Re(e,t,o){C(e,t||null),D(e,o||null);let n=e.type;m(n)&&!n._isComponentDefine?V(e):A(e)}function A(e){let{type:t}=e,o=t.reactivityMode==="signal",n=E(e);try{if(m(t.setup)){let s={attrs:e.props,slots:e.slots,emit:e.emit},i=_(t.setup,e,e.props,s);if(m(i))t.render=i;else if(N(i)){e.setupState={...i};let p=Object.keys(i);for(let a=0;a<p.length;a++)Object.defineProperty(e.renderProxy,p[a],{get(){return e.setupState[p[a]]},set(c){e.setupState[p[a]]=c},enumerable:!0})}}if(m(t.state)){let s=t.state();if(N(s))if(o){let i=U(s);e._signalState=i,e.state=T(i)}else e.state=Ce({...s})}if(t.computed){let s=Object.keys(t.computed);for(let i=0;i<s.length;i++){let p=s[i],a=t.computed[p],c=typeof a=="function"?()=>a.call(e.renderProxy):()=>a.get.call(e.renderProxy),f=typeof a=="function"?void 0:b=>a.set.call(e.renderProxy,b),y;o?y=he(c):f?y=B({get:c,set:f}):y=B(c),e.computedRefs[p]=y}}let r=t.methods;if(N(r)){let s=Object.keys(r);for(let i=0;i<s.length;i++){let p=s[i],a=r[p];m(a)&&(e.renderProxy[p]=a.bind(e.renderProxy))}}if(m(t.init)){let s=t.init.call(e.renderProxy,e.props,e.state);if(N(s)){e.setupState={...e.setupState,...s};let i=Object.keys(s);for(let p=0;p<i.length;p++)Object.defineProperty(e.renderProxy,i[p],{get(){return e.setupState[i[p]]},set(a){e.setupState[i[p]]=a},enumerable:!0})}}let l=Object.keys(e.state);for(let s=0;s<l.length;s++){let i=l[s];Object.defineProperty(e.renderProxy,i,{get(){return e.state[i]},set(p){e.state[i]=p},enumerable:!0})}if(t.computed){let s=Object.keys(t.computed);for(let i=0;i<s.length;i++){let p=s[i],a=e.computedRefs[p];o?Object.defineProperty(e.renderProxy,p,{get(){return a()},enumerable:!0}):Object.defineProperty(e.renderProxy,p,{get(){return a.value},set(c){a.value=c},enumerable:!0})}}if(t.watch){let s=Object.keys(t.watch);for(let i=0;i<s.length;i++){let p=s[i],a=t.watch[p],c=()=>{let f=e.state[p];if(f!==void 0)return f;let y=e.props[p];return y!==void 0?y:e.renderProxy[p]};if(o){let f=Ee(y=>{let b=c();a.handler.call(e.renderProxy,b,void 0)});e.watchStopHandles.push(f)}else{let f=Pe(c,(y,b)=>{a.handler.call(e.renderProxy,y,b)},{immediate:!!a.immediate,deep:!!a.deep});e.watchStopHandles.push(f)}}}d(e,"init")}finally{E(n)}}function V(e){let t=e.type,o={slots:e.slots,emit:e.emit},n=t(e.props,o);e.subTree=n}function O(e,t){let o=e._lifecycleHooks;if(!o||!o[t])return;let n=o[t];for(let r=0;r<n.length;r++)try{n[r]()}catch(l){}}function Le(e,t){if(e.isMounted)return;O(e,"beforeMount");let{type:o}=e;m(o.render)&&t&&(e.subTree=o.render.call(e.renderProxy,t,e)),e.isMounted=!0,d(e,"mounted"),O(e,"mounted")}function Fe(e,t,o){if(e.isUnmounted)return;o&&C(e,o),d(e,"beforeUpdate");let{type:n}=e;m(n.render)&&t&&(e.subTree=n.render.call(e.renderProxy,t,e)),d(e,"updated"),O(e,"updated")}function K(e){if(e.isUnmounted)return;d(e,"beforeUnmount"),O(e,"beforeUnmount"),e.isUnmounted=!0,e.isMounted=!1,e.subTree=null;for(let o of e.watchStopHandles)o();e.watchStopHandles=[],d(e,"unmounted"),O(e,"unmounted");let t=["init","mounted","beforeUpdate","updated","beforeUnmount","unmounted"];for(let o=0;o<t.length;o++)e[t[o]]=void 0;e._lifecycleHooks=void 0}export{w as LifecycleHook,d as callLifecycleHook,P as camelizeToHyphen,Se as compositionOnBeforeMount,xe as compositionOnBeforeUnmount,de as compositionOnMounted,me as compositionOnUnmounted,ge as compositionOnUpdated,Te as createComponentInstance,g as createLifecycleHook,U as createSignalState,T as createSignalStateProxy,h as currentInstance,Ne as defineComponent,oe as defineEmits,Ue as defineFunctionalComponent,Z as disposeSignalState,M as emit,Oe as getCurrentInstance,z as getPropDefaultValue,q as getSignalStateSnapshot,ye as hasSlot,ne as hyphenToCamel,C as initProps,D as initSlots,ke as inject,Le as mountComponent,v as normalizeEmits,L as normalizePropsOptions,k as normalizeSlotValue,ae as onBeforeUnmount,le as onBeforeUpdate,se as onInit,ie as onMounted,ce as onUnmounted,pe as onUpdated,H as patchSignalState,be as provide,fe as renderSlot,_ as runSetup,E as setCurrentInstance,Re as setupComponent,V as setupFunctionComponent,A as setupStatefulComponent,K as unmountComponent,Fe as updateComponent,$ as validateProp};
|
|
1
|
+
import { EMPTY_OBJ, isArray, hasOwn, isFunction, isString, isNumber, isBoolean, isObject, isNullish, NOOP, isPromise } from '@lytjs/common-is';
|
|
2
|
+
import { warn, error } from '@lytjs/common-error';
|
|
3
|
+
import { kebabToCamel } from '@lytjs/common-string';
|
|
4
|
+
import { reactive, computed, watch, ref, signal, computedSignal, effectScope } from '@lytjs/reactivity';
|
|
5
|
+
import { nextTick } from '@lytjs/common-scheduler';
|
|
6
|
+
import { createCommentVNode, ShapeFlags, createVNode, registerSuspenseLinker } from '@lytjs/vdom';
|
|
7
|
+
import { createBaseVNode, ShapeFlags as ShapeFlags$1, Fragment, Text } from '@lytjs/common-vnode';
|
|
8
|
+
|
|
9
|
+
// src/component-setup.ts
|
|
10
|
+
function normalizePropsOptions(rawProps) {
|
|
11
|
+
if (!rawProps) return EMPTY_OBJ;
|
|
12
|
+
if (isArray(rawProps)) {
|
|
13
|
+
const result2 = {};
|
|
14
|
+
for (let i = 0; i < rawProps.length; i++) {
|
|
15
|
+
const key = rawProps[i];
|
|
16
|
+
result2[key] = {};
|
|
17
|
+
}
|
|
18
|
+
return result2;
|
|
19
|
+
}
|
|
20
|
+
const result = {};
|
|
21
|
+
for (const key in rawProps) {
|
|
22
|
+
if (hasOwn(rawProps, key)) {
|
|
23
|
+
const value = rawProps[key];
|
|
24
|
+
result[key] = isFunction(value) || isArray(value) ? { type: value } : value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function resolvePropValue(propOptions, value, _instance, key) {
|
|
30
|
+
const { type, default: defaultValue, required, validator } = propOptions;
|
|
31
|
+
if (value === void 0) {
|
|
32
|
+
if (defaultValue !== void 0) {
|
|
33
|
+
let def;
|
|
34
|
+
if (isFunction(defaultValue)) {
|
|
35
|
+
try {
|
|
36
|
+
def = defaultValue();
|
|
37
|
+
} catch (e) {
|
|
38
|
+
def = void 0;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
def = defaultValue;
|
|
42
|
+
}
|
|
43
|
+
return def;
|
|
44
|
+
}
|
|
45
|
+
if (type === Boolean || isArray(type) && type.includes(Boolean)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function validateType(value, type, key) {
|
|
53
|
+
if (type === null || type === void 0) return true;
|
|
54
|
+
getTypeName(value);
|
|
55
|
+
if (isArray(type)) {
|
|
56
|
+
for (let i = 0; i < type.length; i++) {
|
|
57
|
+
if (checkType(value, type[i])) return true;
|
|
58
|
+
}
|
|
59
|
+
type.map((t) => getTypeName(t)).join(" | ");
|
|
60
|
+
} else {
|
|
61
|
+
if (checkType(value, type)) return true;
|
|
62
|
+
getTypeName(type);
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
function checkType(value, type) {
|
|
67
|
+
if (type === String) return isString(value);
|
|
68
|
+
if (type === Number) return isNumber(value);
|
|
69
|
+
if (type === Boolean) return isBoolean(value);
|
|
70
|
+
if (type === Object) return isObject(value) && !isArray(value);
|
|
71
|
+
if (type === Array) return isArray(value);
|
|
72
|
+
if (type === Function) return isFunction(value);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
function getTypeName(value) {
|
|
76
|
+
if (value === null) return "null";
|
|
77
|
+
if (value === void 0) return "undefined";
|
|
78
|
+
if (isArray(value)) return "Array";
|
|
79
|
+
if (isString(value)) return "String";
|
|
80
|
+
if (isNumber(value)) return "Number";
|
|
81
|
+
if (isBoolean(value)) return "Boolean";
|
|
82
|
+
if (isFunction(value)) return "Function";
|
|
83
|
+
if (isObject(value)) return "Object";
|
|
84
|
+
return String(value);
|
|
85
|
+
}
|
|
86
|
+
var currentInstance = null;
|
|
87
|
+
function setCurrentInstance(instance) {
|
|
88
|
+
currentInstance = instance;
|
|
89
|
+
}
|
|
90
|
+
function getCurrentInstance() {
|
|
91
|
+
return currentInstance;
|
|
92
|
+
}
|
|
93
|
+
function registerLifecycleHook(instance, hookName, fn) {
|
|
94
|
+
if (instance) {
|
|
95
|
+
instance.lifecycle[hookName].add(fn);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function onMounted(fn) {
|
|
99
|
+
if (currentInstance) {
|
|
100
|
+
registerLifecycleHook(currentInstance, "mounted", fn);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function onUpdated(fn) {
|
|
104
|
+
if (currentInstance) {
|
|
105
|
+
registerLifecycleHook(currentInstance, "updated", fn);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function onUnmounted(fn) {
|
|
109
|
+
if (currentInstance) {
|
|
110
|
+
registerLifecycleHook(currentInstance, "unmounted", fn);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function onBeforeMount(fn) {
|
|
114
|
+
if (currentInstance) {
|
|
115
|
+
registerLifecycleHook(currentInstance, "beforeMount", fn);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function onBeforeUpdate(fn) {
|
|
119
|
+
if (currentInstance) {
|
|
120
|
+
registerLifecycleHook(currentInstance, "beforeUpdate", fn);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function onBeforeUnmount(fn) {
|
|
124
|
+
if (currentInstance) {
|
|
125
|
+
registerLifecycleHook(currentInstance, "beforeUnmount", fn);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function onErrorCaptured(fn) {
|
|
129
|
+
if (currentInstance) {
|
|
130
|
+
if (!currentInstance.errorCapturedHooks) {
|
|
131
|
+
currentInstance.errorCapturedHooks = [];
|
|
132
|
+
}
|
|
133
|
+
currentInstance.errorCapturedHooks.push(fn);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function onActivated(fn) {
|
|
137
|
+
if (currentInstance) {
|
|
138
|
+
if (!currentInstance.activatedHooks) {
|
|
139
|
+
currentInstance.activatedHooks = [];
|
|
140
|
+
}
|
|
141
|
+
currentInstance.activatedHooks.push(fn);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function onDeactivated(fn) {
|
|
145
|
+
if (currentInstance) {
|
|
146
|
+
if (!currentInstance.deactivatedHooks) {
|
|
147
|
+
currentInstance.deactivatedHooks = [];
|
|
148
|
+
}
|
|
149
|
+
currentInstance.deactivatedHooks.push(fn);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function onRenderTracked(fn) {
|
|
153
|
+
}
|
|
154
|
+
function onRenderTriggered(fn) {
|
|
155
|
+
}
|
|
156
|
+
function callOptionsHook(instance, hook, name) {
|
|
157
|
+
if (hook) {
|
|
158
|
+
try {
|
|
159
|
+
hook.call(instance.ctx);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
handleError(err, instance, `${name} hook`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function callLifecycleHook(instance, hookName) {
|
|
166
|
+
const hooks = instance.lifecycle[hookName];
|
|
167
|
+
if (hooks.size > 0) {
|
|
168
|
+
for (const hook of hooks) {
|
|
169
|
+
try {
|
|
170
|
+
hook();
|
|
171
|
+
} catch (err) {
|
|
172
|
+
handleError(err, instance, hookName);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function callCreatedHook(instance) {
|
|
178
|
+
const { beforeCreate, created } = instance.type;
|
|
179
|
+
callOptionsHook(instance, beforeCreate, "beforeCreate");
|
|
180
|
+
callOptionsHook(instance, created, "created");
|
|
181
|
+
}
|
|
182
|
+
function callMountedHook(instance) {
|
|
183
|
+
const { beforeMount, mounted } = instance.type;
|
|
184
|
+
callLifecycleHook(instance, "beforeMount");
|
|
185
|
+
callOptionsHook(instance, beforeMount, "beforeMount");
|
|
186
|
+
callLifecycleHook(instance, "mounted");
|
|
187
|
+
callOptionsHook(instance, mounted, "mounted");
|
|
188
|
+
instance.isMounted = true;
|
|
189
|
+
}
|
|
190
|
+
function callUpdatedHook(instance) {
|
|
191
|
+
const { beforeUpdate, updated } = instance.type;
|
|
192
|
+
callLifecycleHook(instance, "beforeUpdate");
|
|
193
|
+
callOptionsHook(instance, beforeUpdate, "beforeUpdate");
|
|
194
|
+
callLifecycleHook(instance, "updated");
|
|
195
|
+
callOptionsHook(instance, updated, "updated");
|
|
196
|
+
}
|
|
197
|
+
function callUnmountedHook(instance) {
|
|
198
|
+
const { beforeUnmount, unmounted } = instance.type;
|
|
199
|
+
callLifecycleHook(instance, "beforeUnmount");
|
|
200
|
+
callOptionsHook(instance, beforeUnmount, "beforeUnmount");
|
|
201
|
+
callLifecycleHook(instance, "unmounted");
|
|
202
|
+
callOptionsHook(instance, unmounted, "unmounted");
|
|
203
|
+
instance.isUnmounted = true;
|
|
204
|
+
}
|
|
205
|
+
function handleError(err, instance, info) {
|
|
206
|
+
let current = instance;
|
|
207
|
+
while (current) {
|
|
208
|
+
const hooks = current.errorCapturedHooks;
|
|
209
|
+
if (hooks && hooks.length > 0) {
|
|
210
|
+
for (const hook of hooks) {
|
|
211
|
+
const result = hook(err, current, info);
|
|
212
|
+
if (result === false) return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const errorHandler = current.type.errorCaptured;
|
|
216
|
+
if (errorHandler) {
|
|
217
|
+
const result = errorHandler.call(
|
|
218
|
+
current.ctx,
|
|
219
|
+
err,
|
|
220
|
+
current,
|
|
221
|
+
info
|
|
222
|
+
);
|
|
223
|
+
if (result === false) return true;
|
|
224
|
+
}
|
|
225
|
+
current = current.parent;
|
|
226
|
+
}
|
|
227
|
+
if (instance) {
|
|
228
|
+
const appErrorHandler = instance.root.appContext?.config?.errorHandler;
|
|
229
|
+
if (typeof appErrorHandler === "function") {
|
|
230
|
+
const publicInstance = instance.ctx ? instance.ctx : null;
|
|
231
|
+
appErrorHandler(err, publicInstance, info);
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/emit.ts
|
|
239
|
+
function normalizeEmitsOptions(emits) {
|
|
240
|
+
if (!emits) return null;
|
|
241
|
+
if (isArray(emits)) {
|
|
242
|
+
const result = {};
|
|
243
|
+
for (let i = 0; i < emits.length; i++) {
|
|
244
|
+
const key = emits[i];
|
|
245
|
+
result[key] = null;
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
return emits;
|
|
250
|
+
}
|
|
251
|
+
function normalizeEventName(event) {
|
|
252
|
+
return kebabToCamel(event);
|
|
253
|
+
}
|
|
254
|
+
function toHandlerKey(event) {
|
|
255
|
+
if (!event) return "";
|
|
256
|
+
const camelized = normalizeEventName(event);
|
|
257
|
+
return `on${camelized[0].toUpperCase()}${camelized.slice(1)}`;
|
|
258
|
+
}
|
|
259
|
+
function emit(instance, event, ...args) {
|
|
260
|
+
if (instance.isUnmounted) return;
|
|
261
|
+
const handlerName = toHandlerKey(event);
|
|
262
|
+
const handler = instance.props[handlerName] ?? instance.attrs[handlerName];
|
|
263
|
+
if (isFunction(handler)) {
|
|
264
|
+
try {
|
|
265
|
+
handler(...args);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
handleError(err, instance, `event handler for "${event}"`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function isEmitValid(instance, event) {
|
|
272
|
+
if (!instance.emitsOptions) return true;
|
|
273
|
+
const normalized = normalizeEventName(event);
|
|
274
|
+
return hasOwn(instance.emitsOptions, normalized) || hasOwn(instance.emitsOptions, event);
|
|
275
|
+
}
|
|
276
|
+
function initSlots(instance, children) {
|
|
277
|
+
if (isNullish(children)) {
|
|
278
|
+
instance.slots = {};
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const slots = {};
|
|
282
|
+
if (isFunction(children)) {
|
|
283
|
+
slots.default = children;
|
|
284
|
+
} else if (isObject(children) && !isArray(children)) {
|
|
285
|
+
const slotObj = children;
|
|
286
|
+
for (const key in slotObj) {
|
|
287
|
+
if (isFunction(slotObj[key])) {
|
|
288
|
+
slots[key] = slotObj[key];
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
instance.slots = slots;
|
|
293
|
+
}
|
|
294
|
+
function normalizeSlotValue(value) {
|
|
295
|
+
if (isNullish(value)) return [];
|
|
296
|
+
if (isArray(value)) return value;
|
|
297
|
+
if (value.__v_isVNode === true) {
|
|
298
|
+
return [value];
|
|
299
|
+
}
|
|
300
|
+
return [value];
|
|
301
|
+
}
|
|
302
|
+
function defineComponent(options) {
|
|
303
|
+
return options;
|
|
304
|
+
}
|
|
305
|
+
function defineFunctionalComponent(render, props) {
|
|
306
|
+
return {
|
|
307
|
+
name: "FunctionalComponent",
|
|
308
|
+
props: props ?? {},
|
|
309
|
+
setup(_props) {
|
|
310
|
+
return render;
|
|
311
|
+
},
|
|
312
|
+
// 标记为函数式组件
|
|
313
|
+
__isFunctional: true
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function mergeOptions(options, seen = /* @__PURE__ */ new WeakSet(), path = [], pathLength = 0) {
|
|
317
|
+
if (seen.has(options)) {
|
|
318
|
+
return { ...options };
|
|
319
|
+
}
|
|
320
|
+
seen.add(options);
|
|
321
|
+
path[pathLength] = options;
|
|
322
|
+
let merged = { ...options };
|
|
323
|
+
if (options.extends) {
|
|
324
|
+
merged = mergeOptionsPair(mergeOptions(options.extends, seen, path, pathLength + 1), merged);
|
|
325
|
+
}
|
|
326
|
+
if (options.mixins) {
|
|
327
|
+
for (const mixin of options.mixins) {
|
|
328
|
+
merged = mergeOptionsPair(merged, mergeOptions(mixin, seen, path, pathLength + 1));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return merged;
|
|
332
|
+
}
|
|
333
|
+
function mergeOptionsPair(parent, child) {
|
|
334
|
+
const merged = { ...parent };
|
|
335
|
+
for (const key in child) {
|
|
336
|
+
if (key === "props" || key === "emits" || key === "inject") {
|
|
337
|
+
const parentVal = parent[key];
|
|
338
|
+
const childVal = child[key];
|
|
339
|
+
if (parentVal && childVal) {
|
|
340
|
+
merged[key] = { ...parentVal, ...childVal };
|
|
341
|
+
} else if (childVal) {
|
|
342
|
+
merged[key] = childVal;
|
|
343
|
+
}
|
|
344
|
+
} else if (key === "data" || key === "provide") {
|
|
345
|
+
const parentVal = parent[key];
|
|
346
|
+
const childVal = child[key];
|
|
347
|
+
if (parentVal && childVal) {
|
|
348
|
+
merged[key] = function() {
|
|
349
|
+
const parentData = isFunction(parentVal) ? parentVal.call(this) : parentVal;
|
|
350
|
+
const childData = isFunction(childVal) ? childVal.call(this) : childVal;
|
|
351
|
+
return {
|
|
352
|
+
...parentData,
|
|
353
|
+
...childData
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
} else if (childVal) {
|
|
357
|
+
merged[key] = childVal;
|
|
358
|
+
}
|
|
359
|
+
} else if (key === "computed" || key === "methods" || key === "watch") {
|
|
360
|
+
const parentVal = parent[key];
|
|
361
|
+
const childVal = child[key];
|
|
362
|
+
if (parentVal && childVal) {
|
|
363
|
+
merged[key] = { ...parentVal, ...childVal };
|
|
364
|
+
} else if (childVal) {
|
|
365
|
+
merged[key] = childVal;
|
|
366
|
+
}
|
|
367
|
+
} else if (key === "beforeCreate" || key === "created" || key === "beforeMount" || key === "mounted" || key === "beforeUpdate" || key === "updated" || key === "beforeUnmount" || key === "unmounted") {
|
|
368
|
+
const parentVal = parent[key];
|
|
369
|
+
const childVal = child[key];
|
|
370
|
+
if (parentVal && childVal) {
|
|
371
|
+
merged[key] = function() {
|
|
372
|
+
parentVal.call(this);
|
|
373
|
+
childVal.call(this);
|
|
374
|
+
};
|
|
375
|
+
} else if (childVal) {
|
|
376
|
+
merged[key] = childVal;
|
|
377
|
+
}
|
|
378
|
+
} else if (key === "mixins" || key === "extends") ; else if (hasOwn(child, key)) {
|
|
379
|
+
merged[key] = child[key];
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return merged;
|
|
383
|
+
}
|
|
384
|
+
function createAppContext() {
|
|
385
|
+
return {
|
|
386
|
+
config: {},
|
|
387
|
+
components: {},
|
|
388
|
+
directives: {},
|
|
389
|
+
mixins: [],
|
|
390
|
+
provides: /* @__PURE__ */ Object.create(null)
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
var PUBLIC_PROPERTIES_MAP = {
|
|
394
|
+
$: 1,
|
|
395
|
+
$el: 2,
|
|
396
|
+
$data: 4,
|
|
397
|
+
$props: 8,
|
|
398
|
+
$attrs: 16,
|
|
399
|
+
$slots: 32,
|
|
400
|
+
$refs: 64,
|
|
401
|
+
$parent: 128,
|
|
402
|
+
$root: 256,
|
|
403
|
+
$emit: 512,
|
|
404
|
+
$options: 1024,
|
|
405
|
+
$forceUpdate: 2048,
|
|
406
|
+
$nextTick: 4096,
|
|
407
|
+
$watch: 8192
|
|
408
|
+
};
|
|
409
|
+
function createComponentPublicInstance(instance) {
|
|
410
|
+
if (!instance.accessCache) {
|
|
411
|
+
instance.accessCache = /* @__PURE__ */ Object.create(null);
|
|
412
|
+
}
|
|
413
|
+
const PublicInstanceProxyHandlers = {
|
|
414
|
+
get(target, key) {
|
|
415
|
+
if (typeof key === "symbol") {
|
|
416
|
+
if (key in target) {
|
|
417
|
+
const res = target[key];
|
|
418
|
+
if (typeof res === "function" && key !== Symbol.toPrimitive && key !== Symbol.iterator) {
|
|
419
|
+
return res.bind(target);
|
|
420
|
+
}
|
|
421
|
+
return res;
|
|
422
|
+
}
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
const cachedValue = instance.accessCache[key];
|
|
426
|
+
if (cachedValue !== void 0) {
|
|
427
|
+
switch (cachedValue) {
|
|
428
|
+
case 32 /* CONTEXT */: {
|
|
429
|
+
const res = target[key];
|
|
430
|
+
if (typeof res === "function" && key !== "$emit") {
|
|
431
|
+
return res.bind(target);
|
|
432
|
+
}
|
|
433
|
+
return res;
|
|
434
|
+
}
|
|
435
|
+
case 1 /* OTHER */:
|
|
436
|
+
return void 0;
|
|
437
|
+
case 2 /* SETUP_STATE */:
|
|
438
|
+
return instance.setupState[key];
|
|
439
|
+
case 4 /* DATA */:
|
|
440
|
+
return instance.data[key];
|
|
441
|
+
case 8 /* PROPS */:
|
|
442
|
+
return instance.props[key];
|
|
443
|
+
case 16 /* GLOBAL_PROPERTIES */: {
|
|
444
|
+
const globalProperties2 = instance.appContext?.config?.globalProperties;
|
|
445
|
+
return globalProperties2 ? globalProperties2[key] : void 0;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (key in target) {
|
|
450
|
+
const res = target[key];
|
|
451
|
+
if (typeof res === "function" && key !== "$emit") {
|
|
452
|
+
return res.bind(target);
|
|
453
|
+
}
|
|
454
|
+
instance.accessCache[key] = 32 /* CONTEXT */;
|
|
455
|
+
return res;
|
|
456
|
+
}
|
|
457
|
+
const globalProperties = instance.appContext?.config?.globalProperties;
|
|
458
|
+
if (globalProperties && hasOwn(globalProperties, key)) {
|
|
459
|
+
instance.accessCache[key] = 16 /* GLOBAL_PROPERTIES */;
|
|
460
|
+
return globalProperties[key];
|
|
461
|
+
}
|
|
462
|
+
if (hasOwn(instance.setupState, key)) {
|
|
463
|
+
instance.accessCache[key] = 2 /* SETUP_STATE */;
|
|
464
|
+
return instance.setupState[key];
|
|
465
|
+
}
|
|
466
|
+
if (hasOwn(instance.data, key)) {
|
|
467
|
+
instance.accessCache[key] = 4 /* DATA */;
|
|
468
|
+
return instance.data[key];
|
|
469
|
+
}
|
|
470
|
+
if (hasOwn(instance.props, key)) {
|
|
471
|
+
instance.accessCache[key] = 8 /* PROPS */;
|
|
472
|
+
return instance.props[key];
|
|
473
|
+
}
|
|
474
|
+
instance.accessCache[key] = 1 /* OTHER */;
|
|
475
|
+
return void 0;
|
|
476
|
+
},
|
|
477
|
+
set(_target, key, value) {
|
|
478
|
+
if (typeof key === "symbol") {
|
|
479
|
+
if (key === Symbol.toPrimitive || key === Symbol.iterator) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
_target[key] = value;
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
if (hasOwn(instance.setupState, key)) {
|
|
486
|
+
instance.setupState[key] = value;
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
if (hasOwn(instance.data, key)) {
|
|
490
|
+
instance.data[key] = value;
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
return false;
|
|
494
|
+
},
|
|
495
|
+
has(_target, key) {
|
|
496
|
+
if (typeof key === "symbol") {
|
|
497
|
+
return key in instance.setupState || key in instance.data || key in instance.props || key in _target;
|
|
498
|
+
}
|
|
499
|
+
const cachedValue = instance.accessCache[key];
|
|
500
|
+
if (cachedValue !== void 0) {
|
|
501
|
+
return cachedValue !== 1 /* OTHER */;
|
|
502
|
+
}
|
|
503
|
+
const globalProperties = instance.appContext?.config?.globalProperties;
|
|
504
|
+
const found = key in instance.setupState || key in instance.data || key in instance.props || (globalProperties ? key in globalProperties : false) || key in _target;
|
|
505
|
+
instance.accessCache[key] = found ? 32 /* CONTEXT */ : 1 /* OTHER */;
|
|
506
|
+
return found;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const ctx = {
|
|
510
|
+
get $data() {
|
|
511
|
+
return instance.data;
|
|
512
|
+
},
|
|
513
|
+
get $props() {
|
|
514
|
+
return instance.props;
|
|
515
|
+
},
|
|
516
|
+
get $el() {
|
|
517
|
+
return instance.vnode?.el ?? null;
|
|
518
|
+
},
|
|
519
|
+
get $options() {
|
|
520
|
+
return instance.type;
|
|
521
|
+
},
|
|
522
|
+
get $refs() {
|
|
523
|
+
return instance.refs;
|
|
524
|
+
},
|
|
525
|
+
get $slots() {
|
|
526
|
+
return instance.slots;
|
|
527
|
+
},
|
|
528
|
+
$emit: instance.emit,
|
|
529
|
+
$forceUpdate: () => {
|
|
530
|
+
if (instance.update) {
|
|
531
|
+
instance.update();
|
|
532
|
+
} else if (instance.isMounted && instance.render && !instance.isUnmounted) {
|
|
533
|
+
nextTick(() => {
|
|
534
|
+
if (instance.isUnmounted) return;
|
|
535
|
+
const prevTree = instance.subTree;
|
|
536
|
+
const nextTree = instance.render(instance.ctx);
|
|
537
|
+
if (nextTree) {
|
|
538
|
+
instance.subTree = nextTree;
|
|
539
|
+
nextTree.el = prevTree?.el ?? null;
|
|
540
|
+
if (prevTree && "anchor" in prevTree) {
|
|
541
|
+
nextTree.anchor = prevTree.anchor;
|
|
542
|
+
}
|
|
543
|
+
if (prevTree && "ref" in prevTree) {
|
|
544
|
+
nextTree.ref = prevTree.ref;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
$nextTick: () => nextTick()
|
|
551
|
+
};
|
|
552
|
+
return new Proxy(ctx, PublicInstanceProxyHandlers);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/component-init.ts
|
|
556
|
+
function normalizeWatchHandler(raw, methods, proxy) {
|
|
557
|
+
if (typeof raw === "function") {
|
|
558
|
+
return raw.bind(proxy);
|
|
559
|
+
}
|
|
560
|
+
if (typeof raw === "string") {
|
|
561
|
+
if (methods && hasOwn(methods, raw)) {
|
|
562
|
+
return methods[raw].bind(proxy);
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
if (raw !== null && typeof raw === "object" && typeof raw.handler !== "undefined") {
|
|
567
|
+
return normalizeWatchHandler(raw.handler, methods, proxy);
|
|
568
|
+
}
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
function finishComponentSetup(instance) {
|
|
572
|
+
const { type } = instance;
|
|
573
|
+
try {
|
|
574
|
+
instance.ctx = createComponentPublicInstance(instance);
|
|
575
|
+
} catch (err) {
|
|
576
|
+
handleError(err, instance, "finishComponentSetup (createComponentPublicInstance)");
|
|
577
|
+
instance.render = () => null;
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
try {
|
|
581
|
+
if (type.data) {
|
|
582
|
+
const data = type.data.call(instance.ctx) ?? {};
|
|
583
|
+
instance.data = reactive(data);
|
|
584
|
+
}
|
|
585
|
+
} catch (err) {
|
|
586
|
+
handleError(err, instance, "finishComponentSetup (data initialization)");
|
|
587
|
+
instance.render = () => null;
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const devPropsKeys = null;
|
|
591
|
+
const proxy = instance.ctx;
|
|
592
|
+
try {
|
|
593
|
+
if (type.methods) {
|
|
594
|
+
for (const key in type.methods) {
|
|
595
|
+
if (hasOwn(type.methods, key)) {
|
|
596
|
+
const method = type.methods[key];
|
|
597
|
+
if (false) ;
|
|
598
|
+
instance.ctx[key] = method.bind(proxy);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (devPropsKeys) ;
|
|
602
|
+
}
|
|
603
|
+
} catch (err) {
|
|
604
|
+
handleError(err, instance, "finishComponentSetup (methods initialization)");
|
|
605
|
+
instance.render = () => null;
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
if (type.computed) {
|
|
610
|
+
for (const key in type.computed) {
|
|
611
|
+
if (hasOwn(type.computed, key)) {
|
|
612
|
+
const opt = type.computed[key];
|
|
613
|
+
let c;
|
|
614
|
+
if (typeof opt === "function") {
|
|
615
|
+
c = computed(() => opt.call(proxy));
|
|
616
|
+
} else if (opt && typeof opt === "object") {
|
|
617
|
+
const { get, set } = opt;
|
|
618
|
+
if (false) ;
|
|
619
|
+
c = computed({
|
|
620
|
+
get: get ? () => get.call(proxy) : () => void 0,
|
|
621
|
+
set: set ? (v) => set.call(proxy, v) : void 0
|
|
622
|
+
});
|
|
623
|
+
} else if (false) ;
|
|
624
|
+
if (false) ;
|
|
625
|
+
instance.ctx[key] = c;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (devPropsKeys) ;
|
|
629
|
+
}
|
|
630
|
+
} catch (err) {
|
|
631
|
+
handleError(err, instance, "finishComponentSetup (computed initialization)");
|
|
632
|
+
instance.render = () => null;
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
try {
|
|
636
|
+
if (type.watch) {
|
|
637
|
+
for (const key in type.watch) {
|
|
638
|
+
if (hasOwn(type.watch, key)) {
|
|
639
|
+
const raw = type.watch[key];
|
|
640
|
+
const handlers = [];
|
|
641
|
+
if (Array.isArray(raw)) {
|
|
642
|
+
for (const h of raw) {
|
|
643
|
+
const normalized = normalizeWatchHandler(h, type.methods, proxy);
|
|
644
|
+
if (normalized) handlers.push(normalized);
|
|
645
|
+
}
|
|
646
|
+
} else {
|
|
647
|
+
const h = normalizeWatchHandler(raw, type.methods, proxy);
|
|
648
|
+
if (h) handlers.push(h);
|
|
649
|
+
}
|
|
650
|
+
const options = {};
|
|
651
|
+
if (!Array.isArray(raw) && raw !== null && typeof raw === "object" && typeof raw.handler !== "undefined") {
|
|
652
|
+
const watchObj = raw;
|
|
653
|
+
if (typeof watchObj.immediate === "boolean") options.immediate = watchObj.immediate;
|
|
654
|
+
if (typeof watchObj.deep === "boolean") options.deep = watchObj.deep;
|
|
655
|
+
if (typeof watchObj.flush === "string")
|
|
656
|
+
options.flush = watchObj.flush;
|
|
657
|
+
}
|
|
658
|
+
for (const handler of handlers) {
|
|
659
|
+
watch(
|
|
660
|
+
() => proxy[key],
|
|
661
|
+
handler,
|
|
662
|
+
options
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
} catch (err) {
|
|
669
|
+
handleError(err, instance, "finishComponentSetup (watch initialization)");
|
|
670
|
+
instance.render = () => null;
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
try {
|
|
674
|
+
callCreatedHook(instance);
|
|
675
|
+
if (type.renderTracked) {
|
|
676
|
+
if (!instance.renderTrackedHooks) {
|
|
677
|
+
instance.renderTrackedHooks = [];
|
|
678
|
+
}
|
|
679
|
+
instance.renderTrackedHooks.push(type.renderTracked.bind(proxy));
|
|
680
|
+
}
|
|
681
|
+
if (type.renderTriggered) {
|
|
682
|
+
if (!instance.renderTriggeredHooks) {
|
|
683
|
+
instance.renderTriggeredHooks = [];
|
|
684
|
+
}
|
|
685
|
+
instance.renderTriggeredHooks.push(type.renderTriggered.bind(proxy));
|
|
686
|
+
}
|
|
687
|
+
} catch (err) {
|
|
688
|
+
handleError(err, instance, "finishComponentSetup (lifecycle hooks)");
|
|
689
|
+
instance.render = () => null;
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
try {
|
|
693
|
+
if (!instance.render) {
|
|
694
|
+
if (type.render) {
|
|
695
|
+
instance.render = type.render.bind(instance.ctx);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
} catch (err) {
|
|
699
|
+
handleError(err, instance, "finishComponentSetup (render setup)");
|
|
700
|
+
instance.render = () => null;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/component-setup.ts
|
|
705
|
+
var ASYNC_SETUP_TIMEOUT = 3e4;
|
|
706
|
+
var uid = 0;
|
|
707
|
+
var setupContextCache = /* @__PURE__ */ new WeakMap();
|
|
708
|
+
function createComponentInstance(vnode, parent) {
|
|
709
|
+
const rawType = vnode.type;
|
|
710
|
+
if (rawType === null || rawType === void 0 || typeof rawType === "string" || typeof rawType === "number" || typeof rawType === "boolean" || typeof rawType === "symbol") {
|
|
711
|
+
throw new Error(
|
|
712
|
+
`[lytjs/component] createComponentInstance: invalid vnode.type "${String(rawType)}". Expected a component options object or function.`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
const type = vnode.type;
|
|
716
|
+
try {
|
|
717
|
+
const mergedOptions = mergeOptions(type);
|
|
718
|
+
const appContext = parent ? parent.appContext : createAppContext();
|
|
719
|
+
const instance = {
|
|
720
|
+
uid: uid++,
|
|
721
|
+
type: mergedOptions,
|
|
722
|
+
vnode,
|
|
723
|
+
subTree: null,
|
|
724
|
+
props: EMPTY_OBJ,
|
|
725
|
+
slots: {},
|
|
726
|
+
ctx: {},
|
|
727
|
+
setupState: {},
|
|
728
|
+
data: {},
|
|
729
|
+
propsOptions: normalizePropsOptions(mergedOptions.props),
|
|
730
|
+
emitsOptions: normalizeEmitsOptions(mergedOptions.emits),
|
|
731
|
+
emit: NOOP,
|
|
732
|
+
isMounted: false,
|
|
733
|
+
isUnmounted: false,
|
|
734
|
+
isDeactivated: false,
|
|
735
|
+
isKeepingAlive: false,
|
|
736
|
+
refs: {},
|
|
737
|
+
lifecycle: {
|
|
738
|
+
beforeMount: /* @__PURE__ */ new Set(),
|
|
739
|
+
mounted: /* @__PURE__ */ new Set(),
|
|
740
|
+
beforeUpdate: /* @__PURE__ */ new Set(),
|
|
741
|
+
updated: /* @__PURE__ */ new Set(),
|
|
742
|
+
beforeUnmount: /* @__PURE__ */ new Set(),
|
|
743
|
+
unmounted: /* @__PURE__ */ new Set()
|
|
744
|
+
},
|
|
745
|
+
provides: parent ? parent.provides : /* @__PURE__ */ Object.create(null),
|
|
746
|
+
parent,
|
|
747
|
+
root: null,
|
|
748
|
+
appContext,
|
|
749
|
+
attrs: {},
|
|
750
|
+
accessCache: null
|
|
751
|
+
};
|
|
752
|
+
instance.emit = (event, ...args) => emit(instance, event, ...args);
|
|
753
|
+
instance.root = parent ? parent.root : instance;
|
|
754
|
+
return instance;
|
|
755
|
+
} catch (err) {
|
|
756
|
+
handleError(err, parent, "createComponentInstance");
|
|
757
|
+
throw err;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function setupComponent(instance) {
|
|
761
|
+
const vnode = instance.vnode;
|
|
762
|
+
if (!vnode) return;
|
|
763
|
+
const { children } = vnode;
|
|
764
|
+
const props = vnode.props ?? null;
|
|
765
|
+
initProps(instance, props);
|
|
766
|
+
initSlots(instance, children);
|
|
767
|
+
const setupResult = runSetup(instance);
|
|
768
|
+
if (isPromise(setupResult)) {
|
|
769
|
+
vnode.isAsyncPlaceholder = true;
|
|
770
|
+
let timeoutId;
|
|
771
|
+
const timedSetupResult = Promise.race([
|
|
772
|
+
setupResult,
|
|
773
|
+
new Promise((_, reject) => {
|
|
774
|
+
timeoutId = setTimeout(
|
|
775
|
+
() => reject(new Error("Async component setup timed out")),
|
|
776
|
+
ASYNC_SETUP_TIMEOUT
|
|
777
|
+
);
|
|
778
|
+
})
|
|
779
|
+
]);
|
|
780
|
+
timedSetupResult.then((resolvedResult) => {
|
|
781
|
+
if (timeoutId !== void 0) {
|
|
782
|
+
clearTimeout(timeoutId);
|
|
783
|
+
timeoutId = void 0;
|
|
784
|
+
}
|
|
785
|
+
if (instance.isUnmounted) return;
|
|
786
|
+
handleSetupResult(instance, resolvedResult);
|
|
787
|
+
vnode.isAsyncPlaceholder = false;
|
|
788
|
+
}).catch((err) => {
|
|
789
|
+
if (timeoutId !== void 0) {
|
|
790
|
+
clearTimeout(timeoutId);
|
|
791
|
+
timeoutId = void 0;
|
|
792
|
+
}
|
|
793
|
+
vnode.isAsyncPlaceholder = false;
|
|
794
|
+
handleError(err, instance, "setup function");
|
|
795
|
+
});
|
|
796
|
+
} else {
|
|
797
|
+
handleSetupResult(instance, setupResult);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function runSetup(instance) {
|
|
801
|
+
const { setup } = instance.type;
|
|
802
|
+
if (!setup) return void 0;
|
|
803
|
+
setCurrentInstance(instance);
|
|
804
|
+
try {
|
|
805
|
+
const setupContext = createSetupContext(instance);
|
|
806
|
+
const result = setup(instance.props, setupContext);
|
|
807
|
+
return result;
|
|
808
|
+
} catch (err) {
|
|
809
|
+
handleError(err, instance, "setup function");
|
|
810
|
+
instance.render = () => null;
|
|
811
|
+
return void 0;
|
|
812
|
+
} finally {
|
|
813
|
+
setCurrentInstance(null);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
function handleSetupResult(instance, setupResult) {
|
|
817
|
+
if (isFunction(setupResult)) {
|
|
818
|
+
instance.render = setupResult;
|
|
819
|
+
} else if (isObject(setupResult) && setupResult !== null) {
|
|
820
|
+
instance.setupState = setupResult;
|
|
821
|
+
}
|
|
822
|
+
finishComponentSetup(instance);
|
|
823
|
+
}
|
|
824
|
+
function initProps(instance, rawProps) {
|
|
825
|
+
const propsOptions = instance.propsOptions;
|
|
826
|
+
const props = {};
|
|
827
|
+
if (!rawProps) {
|
|
828
|
+
instance.props = props;
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
for (const key in propsOptions) {
|
|
832
|
+
if (hasOwn(propsOptions, key)) {
|
|
833
|
+
const value = rawProps[key];
|
|
834
|
+
props[key] = resolvePropValue(propsOptions[key], value);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const attrs = {};
|
|
838
|
+
for (const key in rawProps) {
|
|
839
|
+
if (hasOwn(rawProps, key) && !hasOwn(propsOptions, key)) {
|
|
840
|
+
attrs[key] = rawProps[key];
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
instance.props = props;
|
|
844
|
+
instance.attrs = attrs;
|
|
845
|
+
}
|
|
846
|
+
function createSetupContext(instance) {
|
|
847
|
+
const cached = setupContextCache.get(instance);
|
|
848
|
+
if (cached) {
|
|
849
|
+
return cached;
|
|
850
|
+
}
|
|
851
|
+
const context = {
|
|
852
|
+
attrs: instance.attrs,
|
|
853
|
+
slots: instance.slots,
|
|
854
|
+
emit: instance.emit,
|
|
855
|
+
expose(exposed) {
|
|
856
|
+
if (!exposed) {
|
|
857
|
+
instance.exposed = null;
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const publicApiKeys = /* @__PURE__ */ new Set([
|
|
861
|
+
"$data",
|
|
862
|
+
"$props",
|
|
863
|
+
"$el",
|
|
864
|
+
"$emit",
|
|
865
|
+
"$forceUpdate",
|
|
866
|
+
"$nextTick",
|
|
867
|
+
"$slots",
|
|
868
|
+
"$refs",
|
|
869
|
+
"$options"
|
|
870
|
+
]);
|
|
871
|
+
const safeExposed = {};
|
|
872
|
+
for (const key of Object.keys(exposed)) {
|
|
873
|
+
if (key !== "__proto__" && key !== "constructor" && !publicApiKeys.has(key)) {
|
|
874
|
+
safeExposed[key] = exposed[key];
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
instance.exposed = safeExposed;
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
setupContextCache.set(instance, context);
|
|
881
|
+
return context;
|
|
882
|
+
}
|
|
883
|
+
function provide(key, value) {
|
|
884
|
+
const instance = getCurrentInstance();
|
|
885
|
+
if (instance) {
|
|
886
|
+
if (instance.provides === (instance.parent?.provides ?? null)) {
|
|
887
|
+
instance.provides = Object.create(
|
|
888
|
+
instance.provides
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
instance.provides[key] = value;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function inject(key, defaultValue, options) {
|
|
895
|
+
const instance = getCurrentInstance();
|
|
896
|
+
if (!instance) {
|
|
897
|
+
return resolveDefault(defaultValue, options);
|
|
898
|
+
}
|
|
899
|
+
const lookupKey = options?.from ?? key;
|
|
900
|
+
if (options?.local) {
|
|
901
|
+
const provides = instance.provides;
|
|
902
|
+
const hasOwnProvides = instance.parent ? provides !== instance.parent.provides : true;
|
|
903
|
+
if (hasOwnProvides && hasOwn(provides, lookupKey)) {
|
|
904
|
+
return provides[lookupKey];
|
|
905
|
+
}
|
|
906
|
+
return resolveDefault(defaultValue, options);
|
|
907
|
+
}
|
|
908
|
+
let current = instance.parent;
|
|
909
|
+
while (current) {
|
|
910
|
+
const provides = current.provides;
|
|
911
|
+
if (lookupKey in provides) {
|
|
912
|
+
return provides[lookupKey];
|
|
913
|
+
}
|
|
914
|
+
current = current.parent;
|
|
915
|
+
}
|
|
916
|
+
return resolveDefault(defaultValue, options);
|
|
917
|
+
}
|
|
918
|
+
function resolveDefault(defaultValue, options) {
|
|
919
|
+
if (defaultValue === void 0) return void 0;
|
|
920
|
+
if (options?.factory && typeof defaultValue === "function") {
|
|
921
|
+
return defaultValue();
|
|
922
|
+
}
|
|
923
|
+
return defaultValue;
|
|
924
|
+
}
|
|
925
|
+
var LRUCache = class {
|
|
926
|
+
constructor(maxSize = 10) {
|
|
927
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
928
|
+
this.maxSize = maxSize;
|
|
929
|
+
}
|
|
930
|
+
get(key) {
|
|
931
|
+
const instance = this.cache.get(key);
|
|
932
|
+
if (instance !== void 0) {
|
|
933
|
+
this.cache.delete(key);
|
|
934
|
+
this.cache.set(key, instance);
|
|
935
|
+
}
|
|
936
|
+
return instance;
|
|
937
|
+
}
|
|
938
|
+
set(key, instance) {
|
|
939
|
+
if (this.cache.has(key)) {
|
|
940
|
+
this.cache.delete(key);
|
|
941
|
+
}
|
|
942
|
+
if (this.cache.size >= this.maxSize) {
|
|
943
|
+
const oldestKey = this.cache.keys().next().value;
|
|
944
|
+
if (oldestKey !== void 0) {
|
|
945
|
+
const oldestInstance = this.cache.get(oldestKey);
|
|
946
|
+
if (oldestInstance) {
|
|
947
|
+
deactivateInstance(oldestInstance);
|
|
948
|
+
oldestInstance.effects?.forEach((effect) => {
|
|
949
|
+
effect.stop();
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
this.cache.delete(oldestKey);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
this.cache.set(key, instance);
|
|
956
|
+
}
|
|
957
|
+
delete(key) {
|
|
958
|
+
return this.cache.delete(key);
|
|
959
|
+
}
|
|
960
|
+
has(key) {
|
|
961
|
+
return this.cache.has(key);
|
|
962
|
+
}
|
|
963
|
+
forEach(callback) {
|
|
964
|
+
this.cache.forEach(callback);
|
|
965
|
+
}
|
|
966
|
+
get size() {
|
|
967
|
+
return this.cache.size;
|
|
968
|
+
}
|
|
969
|
+
keys() {
|
|
970
|
+
return this.cache.keys();
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* 更新缓存的最大容量
|
|
974
|
+
*/
|
|
975
|
+
setMaxSize(newMaxSize) {
|
|
976
|
+
this.maxSize = newMaxSize;
|
|
977
|
+
while (this.cache.size > this.maxSize) {
|
|
978
|
+
const oldestKey = this.cache.keys().next().value;
|
|
979
|
+
if (oldestKey !== void 0) {
|
|
980
|
+
const oldestInstance = this.cache.get(oldestKey);
|
|
981
|
+
if (oldestInstance) {
|
|
982
|
+
deactivateInstance(oldestInstance);
|
|
983
|
+
oldestInstance.effects?.forEach((effect) => {
|
|
984
|
+
effect.stop();
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
this.cache.delete(oldestKey);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
var KeepAlive = {
|
|
993
|
+
name: "KeepAlive",
|
|
994
|
+
props: {
|
|
995
|
+
include: {},
|
|
996
|
+
exclude: {},
|
|
997
|
+
max: { type: Number },
|
|
998
|
+
onCacheKey: { type: Function }
|
|
999
|
+
},
|
|
1000
|
+
setup(_props, _ctx) {
|
|
1001
|
+
const props = _props;
|
|
1002
|
+
const maxCacheSize = props.max ?? 10;
|
|
1003
|
+
const cache = new LRUCache(maxCacheSize);
|
|
1004
|
+
const _currentVNode = null;
|
|
1005
|
+
watch(
|
|
1006
|
+
() => _props.max,
|
|
1007
|
+
(newMax) => {
|
|
1008
|
+
if (newMax !== void 0 && typeof newMax === "number" && newMax > 0) {
|
|
1009
|
+
cache.setMaxSize(newMax);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
);
|
|
1013
|
+
return {
|
|
1014
|
+
cache,
|
|
1015
|
+
_currentVNode
|
|
1016
|
+
};
|
|
1017
|
+
},
|
|
1018
|
+
render(ctx) {
|
|
1019
|
+
const instance = ctx;
|
|
1020
|
+
const props = instance.props;
|
|
1021
|
+
const defaultSlot = instance.slots?.default;
|
|
1022
|
+
if (!defaultSlot) return createCommentVNode("keep-alive");
|
|
1023
|
+
const children = defaultSlot();
|
|
1024
|
+
if (!children || children.length === 0) return createCommentVNode("keep-alive");
|
|
1025
|
+
const rawVNode = children[0];
|
|
1026
|
+
if (rawVNode == null) return createCommentVNode("keep-alive");
|
|
1027
|
+
if (typeof rawVNode.type === "string" || rawVNode.type === globalThis.__LYTJS_FRAGMENT__ || rawVNode.type === globalThis.__LYTJS_TEXT__ || rawVNode.type === globalThis.__LYTJS_COMMENT__) {
|
|
1028
|
+
return rawVNode;
|
|
1029
|
+
}
|
|
1030
|
+
const compType = rawVNode.type;
|
|
1031
|
+
const compName = typeof compType === "object" && compType !== null && "name" in compType ? compType.name : typeof compType === "function" ? compType.name : void 0;
|
|
1032
|
+
const isIncluded = props.include === void 0 || matchesPattern(compName, props.include);
|
|
1033
|
+
const isExcluded = props.exclude !== void 0 && matchesPattern(compName, props.exclude);
|
|
1034
|
+
if (!isIncluded || isExcluded) {
|
|
1035
|
+
return rawVNode;
|
|
1036
|
+
}
|
|
1037
|
+
const cacheKey = getCacheKey(instance, rawVNode);
|
|
1038
|
+
const cachedInstance = getCachedInstance(instance, cacheKey);
|
|
1039
|
+
if (cachedInstance) {
|
|
1040
|
+
cacheInstance(instance, cacheKey, cachedInstance);
|
|
1041
|
+
rawVNode.component = cachedInstance;
|
|
1042
|
+
rawVNode.shapeFlag |= ShapeFlags.COMPONENT_KEPT_ALIVE;
|
|
1043
|
+
activateInstance(cachedInstance);
|
|
1044
|
+
return rawVNode;
|
|
1045
|
+
}
|
|
1046
|
+
instance.setupState._currentVNode = rawVNode;
|
|
1047
|
+
return rawVNode;
|
|
1048
|
+
},
|
|
1049
|
+
created() {
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
function createKeepAliveInstance(props = {}, parent = null) {
|
|
1053
|
+
const vnode = createVNode(
|
|
1054
|
+
KeepAlive,
|
|
1055
|
+
{
|
|
1056
|
+
...props,
|
|
1057
|
+
include: props.include,
|
|
1058
|
+
exclude: props.exclude,
|
|
1059
|
+
max: props.max,
|
|
1060
|
+
onCacheKey: props.onCacheKey
|
|
1061
|
+
},
|
|
1062
|
+
null,
|
|
1063
|
+
ShapeFlags.STATEFUL_COMPONENT
|
|
1064
|
+
);
|
|
1065
|
+
const instance = createComponentInstance(vnode, parent);
|
|
1066
|
+
setupComponent(instance);
|
|
1067
|
+
return instance;
|
|
1068
|
+
}
|
|
1069
|
+
function matchesPattern(name, pattern) {
|
|
1070
|
+
if (!pattern) return true;
|
|
1071
|
+
if (name === void 0) return false;
|
|
1072
|
+
if (isString(pattern)) {
|
|
1073
|
+
return name === pattern;
|
|
1074
|
+
}
|
|
1075
|
+
if (pattern instanceof RegExp) {
|
|
1076
|
+
return pattern.test(name);
|
|
1077
|
+
}
|
|
1078
|
+
if (isArray(pattern)) {
|
|
1079
|
+
return pattern.some((p) => matchesPattern(name, p));
|
|
1080
|
+
}
|
|
1081
|
+
return true;
|
|
1082
|
+
}
|
|
1083
|
+
function getCacheKey(keepAlive, vnode) {
|
|
1084
|
+
const onCacheKey = keepAlive.props.onCacheKey;
|
|
1085
|
+
if (isFunction(onCacheKey)) {
|
|
1086
|
+
try {
|
|
1087
|
+
return String(onCacheKey(vnode));
|
|
1088
|
+
} catch (e) {
|
|
1089
|
+
handleError(e, keepAlive, "onCacheKey");
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
const type = vnode.type;
|
|
1093
|
+
if (typeof type === "string") {
|
|
1094
|
+
return type;
|
|
1095
|
+
}
|
|
1096
|
+
if (type && typeof type === "object" && "name" in type) {
|
|
1097
|
+
return String(type.name) || String(type);
|
|
1098
|
+
}
|
|
1099
|
+
if (typeof type === "function" && "name" in type) {
|
|
1100
|
+
return type.name || String(type);
|
|
1101
|
+
}
|
|
1102
|
+
return String(type);
|
|
1103
|
+
}
|
|
1104
|
+
function cacheInstance(keepAlive, key, instance) {
|
|
1105
|
+
const cache = keepAlive.setupState.cache;
|
|
1106
|
+
if (cache.has(key)) {
|
|
1107
|
+
cache.delete(key);
|
|
1108
|
+
}
|
|
1109
|
+
cache.set(key, instance);
|
|
1110
|
+
}
|
|
1111
|
+
function getCachedInstance(keepAlive, key) {
|
|
1112
|
+
const cache = keepAlive.setupState.cache;
|
|
1113
|
+
return cache.get(key);
|
|
1114
|
+
}
|
|
1115
|
+
function removeCachedInstance(keepAlive, key) {
|
|
1116
|
+
const cache = keepAlive.setupState.cache;
|
|
1117
|
+
return cache.delete(key);
|
|
1118
|
+
}
|
|
1119
|
+
function activateInstance(instance) {
|
|
1120
|
+
instance.isDeactivated = false;
|
|
1121
|
+
if (instance.type.activated) {
|
|
1122
|
+
instance.type.activated.call(instance.ctx);
|
|
1123
|
+
}
|
|
1124
|
+
if (instance.activatedHooks) {
|
|
1125
|
+
for (const hook of instance.activatedHooks) {
|
|
1126
|
+
try {
|
|
1127
|
+
hook();
|
|
1128
|
+
} catch (e) {
|
|
1129
|
+
handleError(e, instance, "activated hook");
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function deactivateInstance(instance) {
|
|
1135
|
+
instance.isDeactivated = true;
|
|
1136
|
+
if (instance.type.deactivated) {
|
|
1137
|
+
instance.type.deactivated.call(instance.ctx);
|
|
1138
|
+
}
|
|
1139
|
+
if (instance.deactivatedHooks) {
|
|
1140
|
+
for (const hook of instance.deactivatedHooks) {
|
|
1141
|
+
try {
|
|
1142
|
+
hook();
|
|
1143
|
+
} catch (e) {
|
|
1144
|
+
handleError(e, instance, "deactivated hook");
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
var _linkerRegistered = false;
|
|
1150
|
+
function ensureLinkerRegistered() {
|
|
1151
|
+
if (_linkerRegistered) return;
|
|
1152
|
+
_linkerRegistered = true;
|
|
1153
|
+
registerSuspenseLinker(((asyncState, vnodeBoundary, domSwitch) => {
|
|
1154
|
+
linkSuspenseBoundary(asyncState, vnodeBoundary, domSwitch);
|
|
1155
|
+
}));
|
|
1156
|
+
}
|
|
1157
|
+
var SuspenseAbortedError = class extends Error {
|
|
1158
|
+
constructor(pendingId) {
|
|
1159
|
+
super(`Suspense boundary (id: ${pendingId}) was aborted`);
|
|
1160
|
+
this.pendingId = pendingId;
|
|
1161
|
+
this.name = "SuspenseAbortedError";
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
var Suspense = {
|
|
1165
|
+
name: "Suspense",
|
|
1166
|
+
props: {
|
|
1167
|
+
timeout: { type: Number, default: void 0 }
|
|
1168
|
+
},
|
|
1169
|
+
setup(_props, _ctx) {
|
|
1170
|
+
ensureLinkerRegistered();
|
|
1171
|
+
const boundary = {
|
|
1172
|
+
isPending: false,
|
|
1173
|
+
error: null,
|
|
1174
|
+
promise: null,
|
|
1175
|
+
pendingPromises: /* @__PURE__ */ new Set(),
|
|
1176
|
+
onResolve: [],
|
|
1177
|
+
onPending: [],
|
|
1178
|
+
onError: [],
|
|
1179
|
+
aborted: false
|
|
1180
|
+
};
|
|
1181
|
+
const props = _props;
|
|
1182
|
+
if (props.onResolve) boundary.onResolve.push(props.onResolve);
|
|
1183
|
+
if (props.onPending) boundary.onPending.push(props.onPending);
|
|
1184
|
+
if (props.onError) boundary.onError.push(props.onError);
|
|
1185
|
+
return {
|
|
1186
|
+
boundary
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
function createSuspenseInstance(props = {}, parent = null) {
|
|
1191
|
+
const vnode = createBaseVNode({
|
|
1192
|
+
type: Suspense,
|
|
1193
|
+
props: {
|
|
1194
|
+
timeout: props.timeout,
|
|
1195
|
+
onResolve: props.onResolve,
|
|
1196
|
+
onPending: props.onPending,
|
|
1197
|
+
onError: props.onError
|
|
1198
|
+
},
|
|
1199
|
+
shapeFlag: ShapeFlags$1.SUSPENSE | ShapeFlags$1.STATEFUL_COMPONENT
|
|
1200
|
+
});
|
|
1201
|
+
const instance = createComponentInstance(vnode, parent);
|
|
1202
|
+
setupComponent(instance);
|
|
1203
|
+
return instance;
|
|
1204
|
+
}
|
|
1205
|
+
function createSuspenseBoundary() {
|
|
1206
|
+
return {
|
|
1207
|
+
isPending: false,
|
|
1208
|
+
error: null,
|
|
1209
|
+
promise: null,
|
|
1210
|
+
pendingPromises: /* @__PURE__ */ new Set(),
|
|
1211
|
+
onResolve: [],
|
|
1212
|
+
onPending: [],
|
|
1213
|
+
onError: [],
|
|
1214
|
+
aborted: false
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
function registerAsyncChild(boundary, promise) {
|
|
1218
|
+
if (boundary.aborted) return false;
|
|
1219
|
+
const wasPending = boundary.isPending;
|
|
1220
|
+
boundary.isPending = true;
|
|
1221
|
+
boundary.error = null;
|
|
1222
|
+
boundary.pendingPromises.add(promise);
|
|
1223
|
+
if (!wasPending) {
|
|
1224
|
+
for (const cb of boundary.onPending) {
|
|
1225
|
+
cb();
|
|
1226
|
+
}
|
|
1227
|
+
if (boundary.domSwitch) {
|
|
1228
|
+
const switchFn = boundary.domSwitch;
|
|
1229
|
+
nextTick(() => {
|
|
1230
|
+
if (!boundary.aborted) {
|
|
1231
|
+
switchFn(boundary, true);
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
promise.then((result) => {
|
|
1237
|
+
if (boundary.aborted) return;
|
|
1238
|
+
boundary.pendingPromises.delete(promise);
|
|
1239
|
+
if (boundary.pendingPromises.size === 0) {
|
|
1240
|
+
boundary.isPending = false;
|
|
1241
|
+
boundary.promise = null;
|
|
1242
|
+
for (const cb of boundary.onResolve) {
|
|
1243
|
+
try {
|
|
1244
|
+
cb();
|
|
1245
|
+
} catch (e) {
|
|
1246
|
+
error(`Error in suspense resolve callback: ${String(e)}`);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
if (boundary.domSwitch) {
|
|
1250
|
+
const switchFn = boundary.domSwitch;
|
|
1251
|
+
nextTick(() => {
|
|
1252
|
+
if (!boundary.aborted) {
|
|
1253
|
+
switchFn(boundary, false);
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
return result;
|
|
1259
|
+
}).catch((err) => {
|
|
1260
|
+
if (boundary.aborted) return;
|
|
1261
|
+
boundary.pendingPromises.delete(promise);
|
|
1262
|
+
const caughtError = err instanceof Error ? err : new Error(String(err));
|
|
1263
|
+
boundary.error = caughtError;
|
|
1264
|
+
if (boundary.pendingPromises.size === 0) {
|
|
1265
|
+
boundary.isPending = false;
|
|
1266
|
+
boundary.promise = null;
|
|
1267
|
+
for (const cb of boundary.onError) {
|
|
1268
|
+
try {
|
|
1269
|
+
cb(caughtError);
|
|
1270
|
+
} catch (e) {
|
|
1271
|
+
error(`Error in suspense error callback: ${String(e)}`);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
return !wasPending;
|
|
1277
|
+
}
|
|
1278
|
+
function isSuspensePending(boundary) {
|
|
1279
|
+
return boundary.isPending;
|
|
1280
|
+
}
|
|
1281
|
+
function getSuspenseError(boundary) {
|
|
1282
|
+
return boundary.error;
|
|
1283
|
+
}
|
|
1284
|
+
function linkSuspenseBoundary(asyncState, vnodeBoundary, domSwitch) {
|
|
1285
|
+
asyncState.vnodeBoundary = vnodeBoundary;
|
|
1286
|
+
asyncState.domSwitch = domSwitch;
|
|
1287
|
+
}
|
|
1288
|
+
function resolveSuspense(boundary) {
|
|
1289
|
+
boundary.isPending = false;
|
|
1290
|
+
boundary.aborted = true;
|
|
1291
|
+
boundary.promise = null;
|
|
1292
|
+
boundary.error = null;
|
|
1293
|
+
boundary.pendingPromises.clear();
|
|
1294
|
+
for (const cb of boundary.onResolve) {
|
|
1295
|
+
try {
|
|
1296
|
+
cb();
|
|
1297
|
+
} catch (e) {
|
|
1298
|
+
error(`Error in suspense resolve callback: ${String(e)}`);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function abortSuspense(boundary) {
|
|
1303
|
+
boundary.aborted = true;
|
|
1304
|
+
boundary.isPending = false;
|
|
1305
|
+
boundary.promise = null;
|
|
1306
|
+
if (boundary.pendingPromises.size > 0) {
|
|
1307
|
+
const abortError = new SuspenseAbortedError(boundary.pendingPromises.size);
|
|
1308
|
+
boundary.pendingPromises.forEach((promise) => {
|
|
1309
|
+
try {
|
|
1310
|
+
const p = promise;
|
|
1311
|
+
if (typeof p.abort === "function") {
|
|
1312
|
+
p.abort(abortError);
|
|
1313
|
+
}
|
|
1314
|
+
} catch {
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
boundary.pendingPromises.clear();
|
|
1318
|
+
}
|
|
1319
|
+
boundary.onResolve.length = 0;
|
|
1320
|
+
boundary.onPending.length = 0;
|
|
1321
|
+
boundary.onError.length = 0;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// src/transition.ts
|
|
1325
|
+
var Transition = {
|
|
1326
|
+
name: "Transition",
|
|
1327
|
+
props: {
|
|
1328
|
+
name: { type: String },
|
|
1329
|
+
appear: { type: Boolean, default: false },
|
|
1330
|
+
mode: { type: String, default: "default" },
|
|
1331
|
+
enterFromClass: { type: String },
|
|
1332
|
+
enterActiveClass: { type: String },
|
|
1333
|
+
enterToClass: { type: String },
|
|
1334
|
+
leaveFromClass: { type: String },
|
|
1335
|
+
leaveActiveClass: { type: String },
|
|
1336
|
+
leaveToClass: { type: String },
|
|
1337
|
+
onBeforeEnter: { type: Function },
|
|
1338
|
+
onEnter: { type: Function },
|
|
1339
|
+
onAfterEnter: { type: Function },
|
|
1340
|
+
onEnterCancelled: { type: Function },
|
|
1341
|
+
onBeforeLeave: { type: Function },
|
|
1342
|
+
onLeave: { type: Function },
|
|
1343
|
+
onAfterLeave: { type: Function },
|
|
1344
|
+
onLeaveCancelled: { type: Function }
|
|
1345
|
+
},
|
|
1346
|
+
// FIX: P0-06 移除多余的 IIFE 包装和 as unknown as void 类型欺骗,
|
|
1347
|
+
// 直接返回渲染函数,让组件系统正确识别 setup 返回的渲染函数
|
|
1348
|
+
// FIX: DTS build error - 添加类型断言
|
|
1349
|
+
setup(_props, { slots }) {
|
|
1350
|
+
return (() => slots.default?.());
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
|
|
1354
|
+
// src/transition-group.ts
|
|
1355
|
+
var TransitionGroup = {
|
|
1356
|
+
name: "TransitionGroup",
|
|
1357
|
+
props: {
|
|
1358
|
+
name: { type: String },
|
|
1359
|
+
appear: { type: Boolean, default: false },
|
|
1360
|
+
tag: { type: [String, Boolean] },
|
|
1361
|
+
moveClass: { type: String },
|
|
1362
|
+
enterFromClass: { type: String },
|
|
1363
|
+
enterActiveClass: { type: String },
|
|
1364
|
+
enterToClass: { type: String },
|
|
1365
|
+
leaveFromClass: { type: String },
|
|
1366
|
+
leaveActiveClass: { type: String },
|
|
1367
|
+
leaveToClass: { type: String },
|
|
1368
|
+
onBeforeEnter: { type: Function },
|
|
1369
|
+
onEnter: { type: Function },
|
|
1370
|
+
onAfterEnter: { type: Function },
|
|
1371
|
+
onEnterCancelled: { type: Function },
|
|
1372
|
+
onBeforeLeave: { type: Function },
|
|
1373
|
+
onLeave: { type: Function },
|
|
1374
|
+
onAfterLeave: { type: Function },
|
|
1375
|
+
onLeaveCancelled: { type: Function }
|
|
1376
|
+
},
|
|
1377
|
+
// FIX: DTS build error - 添加类型断言
|
|
1378
|
+
setup(_props, { slots }) {
|
|
1379
|
+
return (() => slots.default?.());
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
// src/teleport.ts
|
|
1384
|
+
var Teleport = {
|
|
1385
|
+
name: "Teleport",
|
|
1386
|
+
// FIX: P1-21 定义正确的 props 类型替代 as any
|
|
1387
|
+
// FIX: DTS build error - 使用 any 避免 PropConstructor 类型不兼容
|
|
1388
|
+
// FIX: DTS build error - props 使用 any 类型
|
|
1389
|
+
props: {
|
|
1390
|
+
to: { type: [String, Object], required: true },
|
|
1391
|
+
disabled: { type: Boolean, default: false }
|
|
1392
|
+
},
|
|
1393
|
+
setup() {
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
var activeErrorBoundaries = /* @__PURE__ */ new Set();
|
|
1397
|
+
var globalHandlerInstalled = false;
|
|
1398
|
+
function globalUnhandledRejectionHandler(event) {
|
|
1399
|
+
for (const eb of activeErrorBoundaries) {
|
|
1400
|
+
eb.handler(event);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
function isErrorBoundaryProps(props) {
|
|
1404
|
+
return props !== null && typeof props === "object";
|
|
1405
|
+
}
|
|
1406
|
+
var ErrorBoundary = {
|
|
1407
|
+
name: "ErrorBoundary",
|
|
1408
|
+
props: {
|
|
1409
|
+
onError: { type: Function },
|
|
1410
|
+
fallback: { type: Object },
|
|
1411
|
+
/** 是否捕获异步 Promise 错误 */
|
|
1412
|
+
capturePromiseRejections: { type: Boolean, default: false }
|
|
1413
|
+
},
|
|
1414
|
+
setup(props) {
|
|
1415
|
+
const error2 = ref(null);
|
|
1416
|
+
const hasError = ref(false);
|
|
1417
|
+
const typedProps = isErrorBoundaryProps(props) ? props : {};
|
|
1418
|
+
onErrorCaptured((err, _instance, info) => {
|
|
1419
|
+
error2.value = err;
|
|
1420
|
+
hasError.value = true;
|
|
1421
|
+
typedProps.onError?.(err, info);
|
|
1422
|
+
return false;
|
|
1423
|
+
});
|
|
1424
|
+
let currentBoundary = null;
|
|
1425
|
+
onMounted(() => {
|
|
1426
|
+
if (typedProps.capturePromiseRejections && typeof window !== "undefined") {
|
|
1427
|
+
currentBoundary = {
|
|
1428
|
+
handler: (event) => {
|
|
1429
|
+
const err = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
1430
|
+
error2.value = err;
|
|
1431
|
+
hasError.value = true;
|
|
1432
|
+
typedProps.onError?.(
|
|
1433
|
+
err,
|
|
1434
|
+
"unhandledrejection"
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
activeErrorBoundaries.add(currentBoundary);
|
|
1439
|
+
if (!globalHandlerInstalled) {
|
|
1440
|
+
globalHandlerInstalled = true;
|
|
1441
|
+
window.addEventListener("unhandledrejection", globalUnhandledRejectionHandler);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
onUnmounted(() => {
|
|
1446
|
+
if (currentBoundary) {
|
|
1447
|
+
activeErrorBoundaries.delete(currentBoundary);
|
|
1448
|
+
currentBoundary = null;
|
|
1449
|
+
if (activeErrorBoundaries.size === 0 && globalHandlerInstalled) {
|
|
1450
|
+
globalHandlerInstalled = false;
|
|
1451
|
+
window.removeEventListener("unhandledrejection", globalUnhandledRejectionHandler);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
const render = (ctx) => {
|
|
1456
|
+
if (hasError.value) {
|
|
1457
|
+
const fallbackSlot = ctx.$slots.fallback;
|
|
1458
|
+
if (fallbackSlot) {
|
|
1459
|
+
const result = fallbackSlot({ error: error2.value });
|
|
1460
|
+
if (!Array.isArray(result)) {
|
|
1461
|
+
return result;
|
|
1462
|
+
}
|
|
1463
|
+
if (result.length > 0) {
|
|
1464
|
+
if (result.length === 1) {
|
|
1465
|
+
return result[0];
|
|
1466
|
+
}
|
|
1467
|
+
return createVNode(Fragment, null, result);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
return createVNode(
|
|
1471
|
+
Text,
|
|
1472
|
+
null,
|
|
1473
|
+
error2.value ? `Error: ${error2.value.message}` : "An error occurred"
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
const defaultSlot = ctx.$slots.default;
|
|
1477
|
+
if (defaultSlot) {
|
|
1478
|
+
const result = defaultSlot();
|
|
1479
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
1480
|
+
if (result.length === 1) {
|
|
1481
|
+
return result[0];
|
|
1482
|
+
}
|
|
1483
|
+
return createVNode(Fragment, null, result);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return createVNode(Text, null, "");
|
|
1487
|
+
};
|
|
1488
|
+
return { error: error2, hasError, render };
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
function createSignalState(initialValue) {
|
|
1492
|
+
return signal(initialValue);
|
|
1493
|
+
}
|
|
1494
|
+
function createComputedState(getter) {
|
|
1495
|
+
return computedSignal(getter);
|
|
1496
|
+
}
|
|
1497
|
+
var preloadedComponents = /* @__PURE__ */ new WeakMap();
|
|
1498
|
+
var asyncComponentStates = /* @__PURE__ */ new WeakMap();
|
|
1499
|
+
function defineAsyncComponent(options) {
|
|
1500
|
+
const normalizedOptions = isFunction(options) ? { loader: options } : options;
|
|
1501
|
+
const {
|
|
1502
|
+
loader,
|
|
1503
|
+
loadingComponent,
|
|
1504
|
+
errorComponent,
|
|
1505
|
+
delay = 200,
|
|
1506
|
+
timeout,
|
|
1507
|
+
// FIX: DTS build error - suspensible 未使�
|
|
1508
|
+
// suspensible = false,
|
|
1509
|
+
onError
|
|
1510
|
+
} = normalizedOptions;
|
|
1511
|
+
let loadPromise = null;
|
|
1512
|
+
function load() {
|
|
1513
|
+
if (preloadedComponents.has(loader)) {
|
|
1514
|
+
return preloadedComponents.get(loader);
|
|
1515
|
+
}
|
|
1516
|
+
if (loadPromise) {
|
|
1517
|
+
return loadPromise;
|
|
1518
|
+
}
|
|
1519
|
+
loadPromise = loader().then((comp) => {
|
|
1520
|
+
const resolvedComponent = comp.default || comp;
|
|
1521
|
+
preloadedComponents.set(loader, Promise.resolve(resolvedComponent));
|
|
1522
|
+
return resolvedComponent;
|
|
1523
|
+
}).catch((err) => {
|
|
1524
|
+
loadPromise = null;
|
|
1525
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
1526
|
+
if (onError) {
|
|
1527
|
+
onError(error2);
|
|
1528
|
+
}
|
|
1529
|
+
throw error2;
|
|
1530
|
+
});
|
|
1531
|
+
return loadPromise;
|
|
1532
|
+
}
|
|
1533
|
+
function preload() {
|
|
1534
|
+
if (preloadedComponents.has(loader)) {
|
|
1535
|
+
return Promise.resolve();
|
|
1536
|
+
}
|
|
1537
|
+
return load().then(() => {
|
|
1538
|
+
}).catch(() => {
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
const AsyncComponentWrapper = {
|
|
1542
|
+
name: "AsyncComponentWrapper",
|
|
1543
|
+
setup(_props, { slots }) {
|
|
1544
|
+
const instance = getCurrentInstance();
|
|
1545
|
+
let state;
|
|
1546
|
+
if (instance && asyncComponentStates.has(instance)) {
|
|
1547
|
+
state = asyncComponentStates.get(instance);
|
|
1548
|
+
} else {
|
|
1549
|
+
state = {
|
|
1550
|
+
loadedComponent: null,
|
|
1551
|
+
error: null,
|
|
1552
|
+
isLoading: false,
|
|
1553
|
+
isLoaded: false,
|
|
1554
|
+
isError: false,
|
|
1555
|
+
loadingPromise: null
|
|
1556
|
+
};
|
|
1557
|
+
if (instance) {
|
|
1558
|
+
asyncComponentStates.set(instance, state);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
if (state.isLoaded && state.loadedComponent) {
|
|
1562
|
+
return () => renderLoadedComponent(state.loadedComponent, slots);
|
|
1563
|
+
}
|
|
1564
|
+
if (state.isError) {
|
|
1565
|
+
return () => errorComponent ? createComponentVNode(errorComponent, { error: state.error }) : createAsyncCommentVNode(" Async component error ");
|
|
1566
|
+
}
|
|
1567
|
+
if (!state.isLoading) {
|
|
1568
|
+
state.isLoading = true;
|
|
1569
|
+
state.loadingPromise = load().then((comp) => {
|
|
1570
|
+
state.loadedComponent = comp;
|
|
1571
|
+
state.isLoaded = true;
|
|
1572
|
+
state.isLoading = false;
|
|
1573
|
+
if (instance) {
|
|
1574
|
+
triggerComponentUpdate(instance);
|
|
1575
|
+
}
|
|
1576
|
+
}).catch((err) => {
|
|
1577
|
+
state.error = err instanceof Error ? err : new Error(String(err));
|
|
1578
|
+
state.isError = true;
|
|
1579
|
+
state.isLoading = false;
|
|
1580
|
+
if (instance) {
|
|
1581
|
+
triggerComponentUpdate(instance);
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
if (timeout !== void 0 && timeout > 0) {
|
|
1585
|
+
const timeoutId = setTimeout(() => {
|
|
1586
|
+
if (!state.isLoaded && !state.isError) {
|
|
1587
|
+
state.error = new Error(`Async component loading timed out after ${timeout}ms`);
|
|
1588
|
+
state.isError = true;
|
|
1589
|
+
state.isLoading = false;
|
|
1590
|
+
if (instance) {
|
|
1591
|
+
triggerComponentUpdate(instance);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}, timeout);
|
|
1595
|
+
onBeforeUnmount(() => {
|
|
1596
|
+
clearTimeout(timeoutId);
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
return () => {
|
|
1601
|
+
if (delay === 0 && state.isLoading && !state.loadedComponent) {
|
|
1602
|
+
return createAsyncCommentVNode(" Async component loading ");
|
|
1603
|
+
}
|
|
1604
|
+
if (loadingComponent) {
|
|
1605
|
+
return createComponentVNode(loadingComponent, {});
|
|
1606
|
+
}
|
|
1607
|
+
return createAsyncCommentVNode(" Async component loading ");
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
return Object.assign(AsyncComponentWrapper, { preload });
|
|
1612
|
+
}
|
|
1613
|
+
function triggerComponentUpdate(instance) {
|
|
1614
|
+
if (instance.update) {
|
|
1615
|
+
instance.update();
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
function createComponentVNode(component, props) {
|
|
1619
|
+
return createVNode(component, props, null, ShapeFlags.STATEFUL_COMPONENT);
|
|
1620
|
+
}
|
|
1621
|
+
function createAsyncCommentVNode(text) {
|
|
1622
|
+
return createCommentVNode(text);
|
|
1623
|
+
}
|
|
1624
|
+
function renderLoadedComponent(component, slots) {
|
|
1625
|
+
return createVNode(component, {}, slots, ShapeFlags.STATEFUL_COMPONENT);
|
|
1626
|
+
}
|
|
1627
|
+
function preloadComponents(loaders) {
|
|
1628
|
+
return Promise.all(loaders.map((loader) => preloadComponent(loader))).then(() => {
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
function preloadComponent(loader) {
|
|
1632
|
+
if (preloadedComponents.has(loader)) {
|
|
1633
|
+
return Promise.resolve();
|
|
1634
|
+
}
|
|
1635
|
+
return loader().then((comp) => {
|
|
1636
|
+
const resolvedComponent = comp.default || comp;
|
|
1637
|
+
preloadedComponents.set(loader, Promise.resolve(resolvedComponent));
|
|
1638
|
+
}).catch(() => {
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
function isComponentPreloaded(loader) {
|
|
1642
|
+
return preloadedComponents.has(loader);
|
|
1643
|
+
}
|
|
1644
|
+
function clearPreloadCache(loader) {
|
|
1645
|
+
if (loader) {
|
|
1646
|
+
preloadedComponents.delete(loader);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
var InjectionToken = class {
|
|
1650
|
+
constructor(description, options) {
|
|
1651
|
+
this.description = description;
|
|
1652
|
+
this.__token = Symbol(description);
|
|
1653
|
+
this.factory = options?.factory;
|
|
1654
|
+
this.lifecycle = options?.lifecycle;
|
|
1655
|
+
}
|
|
1656
|
+
toString() {
|
|
1657
|
+
return `InjectionToken(${this.description})`;
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
function isInjectionToken(value) {
|
|
1661
|
+
return value instanceof InjectionToken;
|
|
1662
|
+
}
|
|
1663
|
+
var globalProviderRoot = null;
|
|
1664
|
+
var currentProviderNode = null;
|
|
1665
|
+
function createProviderNode(parent = null) {
|
|
1666
|
+
const node = {
|
|
1667
|
+
id: /* @__PURE__ */ Symbol("provider-node"),
|
|
1668
|
+
parent,
|
|
1669
|
+
children: /* @__PURE__ */ new Set(),
|
|
1670
|
+
providers: /* @__PURE__ */ new Map(),
|
|
1671
|
+
scope: effectScope()
|
|
1672
|
+
};
|
|
1673
|
+
if (parent) {
|
|
1674
|
+
parent.children.add(node);
|
|
1675
|
+
}
|
|
1676
|
+
return node;
|
|
1677
|
+
}
|
|
1678
|
+
function getProviderRoot() {
|
|
1679
|
+
if (!globalProviderRoot) {
|
|
1680
|
+
globalProviderRoot = createProviderNode();
|
|
1681
|
+
}
|
|
1682
|
+
return globalProviderRoot;
|
|
1683
|
+
}
|
|
1684
|
+
function enterProviderScope() {
|
|
1685
|
+
const parent = currentProviderNode || getProviderRoot();
|
|
1686
|
+
currentProviderNode = createProviderNode(parent);
|
|
1687
|
+
return currentProviderNode;
|
|
1688
|
+
}
|
|
1689
|
+
function exitProviderScope() {
|
|
1690
|
+
if (currentProviderNode && currentProviderNode.parent) {
|
|
1691
|
+
currentProviderNode.scope.stop();
|
|
1692
|
+
currentProviderNode.parent.children.delete(currentProviderNode);
|
|
1693
|
+
currentProviderNode = currentProviderNode.parent;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
function getCurrentProviderNode() {
|
|
1697
|
+
return currentProviderNode;
|
|
1698
|
+
}
|
|
1699
|
+
var InjectionError = class extends Error {
|
|
1700
|
+
constructor(token, message) {
|
|
1701
|
+
super(`Injection error for token "${String(token)}": ${message}`);
|
|
1702
|
+
this.token = token;
|
|
1703
|
+
this.name = "InjectionError";
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
function provide2(key, valueOrConfig) {
|
|
1707
|
+
const instance = getCurrentInstance();
|
|
1708
|
+
const providerNode = currentProviderNode || (instance ? null : getProviderRoot());
|
|
1709
|
+
const actualKey = isInjectionToken(key) ? key.__token : key;
|
|
1710
|
+
let record;
|
|
1711
|
+
if (isProviderConfig(valueOrConfig)) {
|
|
1712
|
+
const config = valueOrConfig;
|
|
1713
|
+
const lifecycle = config.lifecycle || "singleton";
|
|
1714
|
+
if (config.provide !== void 0) {
|
|
1715
|
+
record = {
|
|
1716
|
+
value: config.provide,
|
|
1717
|
+
lifecycle
|
|
1718
|
+
};
|
|
1719
|
+
} else if (config.useFactory) {
|
|
1720
|
+
record = {
|
|
1721
|
+
value: config.useFactory(),
|
|
1722
|
+
lifecycle
|
|
1723
|
+
};
|
|
1724
|
+
} else if (config.useExisting) {
|
|
1725
|
+
record = {
|
|
1726
|
+
value: () => inject2(config.useExisting),
|
|
1727
|
+
lifecycle
|
|
1728
|
+
};
|
|
1729
|
+
} else {
|
|
1730
|
+
throw new InjectionError(
|
|
1731
|
+
actualKey,
|
|
1732
|
+
"ProviderConfig must have provide, useFactory, or useExisting"
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1735
|
+
} else {
|
|
1736
|
+
record = {
|
|
1737
|
+
value: valueOrConfig,
|
|
1738
|
+
lifecycle: "singleton"
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
if (instance) {
|
|
1742
|
+
if (instance.provides === (instance.parent?.provides ?? null)) {
|
|
1743
|
+
instance.provides = Object.create(
|
|
1744
|
+
instance.provides
|
|
1745
|
+
);
|
|
1746
|
+
}
|
|
1747
|
+
instance.provides[actualKey] = record.value;
|
|
1748
|
+
} else if (providerNode) {
|
|
1749
|
+
providerNode.providers.set(actualKey, record);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
function inject2(key, options) {
|
|
1753
|
+
const instance = getCurrentInstance();
|
|
1754
|
+
const providerNode = currentProviderNode;
|
|
1755
|
+
const actualKey = isInjectionToken(key) ? key.__token : key;
|
|
1756
|
+
const lookupKey = actualKey;
|
|
1757
|
+
if (instance) {
|
|
1758
|
+
const result = injectFromInstance(instance, lookupKey, options);
|
|
1759
|
+
if (result !== void 0) {
|
|
1760
|
+
return result;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
if (providerNode) {
|
|
1764
|
+
const result = injectFromProviderNode(providerNode, lookupKey);
|
|
1765
|
+
if (result !== void 0) {
|
|
1766
|
+
return result;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
if (globalProviderRoot) {
|
|
1770
|
+
const result = injectFromProviderNode(globalProviderRoot, lookupKey);
|
|
1771
|
+
if (result !== void 0) {
|
|
1772
|
+
return result;
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
if (isInjectionToken(key) && key.factory) {
|
|
1776
|
+
return key.factory();
|
|
1777
|
+
}
|
|
1778
|
+
{
|
|
1779
|
+
throw new InjectionError(actualKey, "No provider found");
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
function injectFromInstance(instance, key, options) {
|
|
1783
|
+
{
|
|
1784
|
+
const provides = instance.provides;
|
|
1785
|
+
if (key in provides) {
|
|
1786
|
+
return provides[key];
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
let current = options?.skipSelf ? instance.parent : instance.parent;
|
|
1790
|
+
while (current) {
|
|
1791
|
+
const provides = current.provides;
|
|
1792
|
+
if (key in provides) {
|
|
1793
|
+
return provides[key];
|
|
1794
|
+
}
|
|
1795
|
+
current = current.parent;
|
|
1796
|
+
}
|
|
1797
|
+
return void 0;
|
|
1798
|
+
}
|
|
1799
|
+
function injectFromProviderNode(node, key, options) {
|
|
1800
|
+
{
|
|
1801
|
+
const record = node.providers.get(key);
|
|
1802
|
+
if (record) {
|
|
1803
|
+
if (typeof record.value === "function" && record.lifecycle === "transient") {
|
|
1804
|
+
return record.value();
|
|
1805
|
+
}
|
|
1806
|
+
return record.value;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
let current = node.parent;
|
|
1810
|
+
while (current) {
|
|
1811
|
+
const record = current.providers.get(key);
|
|
1812
|
+
if (record) {
|
|
1813
|
+
if (typeof record.value === "function" && record.lifecycle === "transient") {
|
|
1814
|
+
return record.value();
|
|
1815
|
+
}
|
|
1816
|
+
return record.value;
|
|
1817
|
+
}
|
|
1818
|
+
current = current.parent;
|
|
1819
|
+
}
|
|
1820
|
+
return void 0;
|
|
1821
|
+
}
|
|
1822
|
+
function isProviderConfig(value) {
|
|
1823
|
+
return typeof value === "object" && value !== null && ("provide" in value || "useFactory" in value || "useExisting" in value || "lifecycle" in value);
|
|
1824
|
+
}
|
|
1825
|
+
function provideSingleton(key, factory) {
|
|
1826
|
+
provide2(key, {
|
|
1827
|
+
useFactory: factory,
|
|
1828
|
+
lifecycle: "singleton"
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
function provideScoped(key, factory) {
|
|
1832
|
+
provide2(key, {
|
|
1833
|
+
useFactory: factory,
|
|
1834
|
+
lifecycle: "scoped"
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
function provideTransient(key, factory) {
|
|
1838
|
+
provide2(key, {
|
|
1839
|
+
useFactory: factory,
|
|
1840
|
+
lifecycle: "transient"
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
function provideAll(providers) {
|
|
1844
|
+
for (const provider of providers) {
|
|
1845
|
+
const { provide: key, useValue, useFactory, useExisting, lifecycle } = provider;
|
|
1846
|
+
provide2(key, {
|
|
1847
|
+
provide: useValue,
|
|
1848
|
+
useFactory,
|
|
1849
|
+
useExisting,
|
|
1850
|
+
lifecycle
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
function withProviderScope(fn) {
|
|
1855
|
+
const node = enterProviderScope();
|
|
1856
|
+
try {
|
|
1857
|
+
return node.scope.run(fn);
|
|
1858
|
+
} finally {
|
|
1859
|
+
exitProviderScope();
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
export { ErrorBoundary, InjectionError, InjectionToken, KeepAlive, PUBLIC_PROPERTIES_MAP, Suspense, Teleport, Transition, TransitionGroup, abortSuspense, activateInstance, cacheInstance, callCreatedHook, callLifecycleHook, callMountedHook, callUnmountedHook, callUpdatedHook, clearPreloadCache, createAppContext, createComponentInstance, createComponentPublicInstance, createComputedState, createKeepAliveInstance, createSignalState, createSuspenseBoundary, createSuspenseInstance, deactivateInstance, defineAsyncComponent, defineComponent, defineFunctionalComponent, emit, enterProviderScope, exitProviderScope, finishComponentSetup, getCacheKey, getCachedInstance, getCurrentInstance, getCurrentProviderNode, getProviderRoot, getSuspenseError, handleError, initProps, initSlots, inject, isComponentPreloaded, isEmitValid, isInjectionToken, isSuspensePending, linkSuspenseBoundary, matchesPattern, normalizeEmitsOptions, normalizePropsOptions, normalizeSlotValue, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, preloadComponent, preloadComponents, provide, provideAll, provideScoped, provideSingleton, provideTransient, registerAsyncChild, removeCachedInstance, resolvePropValue, resolveSuspense, setCurrentInstance, setupComponent, validateType, withProviderScope };
|
|
1864
|
+
//# sourceMappingURL=index.mjs.map
|
|
1865
|
+
//# sourceMappingURL=index.mjs.map
|