nexa-runtime 0.1.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/dist/component/asyncComponent.d.ts +10 -0
- package/dist/component/asyncComponent.d.ts.map +1 -0
- package/dist/component/asyncComponent.js +70 -0
- package/dist/component/asyncComponent.js.map +1 -0
- package/dist/component/defineComponent.d.ts +3 -0
- package/dist/component/defineComponent.d.ts.map +1 -0
- package/dist/component/defineComponent.js +4 -0
- package/dist/component/defineComponent.js.map +1 -0
- package/dist/component/errorBoundary.d.ts +7 -0
- package/dist/component/errorBoundary.d.ts.map +1 -0
- package/dist/component/errorBoundary.js +33 -0
- package/dist/component/errorBoundary.js.map +1 -0
- package/dist/component/index.d.ts +6 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component/index.js +6 -0
- package/dist/component/index.js.map +1 -0
- package/dist/component/lifecycle.d.ts +14 -0
- package/dist/component/lifecycle.d.ts.map +1 -0
- package/dist/component/lifecycle.js +32 -0
- package/dist/component/lifecycle.js.map +1 -0
- package/dist/component/suspense.d.ts +9 -0
- package/dist/component/suspense.d.ts.map +1 -0
- package/dist/component/suspense.js +41 -0
- package/dist/component/suspense.js.map +1 -0
- package/dist/directives/index.d.ts +7 -0
- package/dist/directives/index.d.ts.map +1 -0
- package/dist/directives/index.js +27 -0
- package/dist/directives/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/scheduler.d.ts +2 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +18 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +3 -0
- package/dist/ssr/hydrate.d.ts.map +1 -0
- package/dist/ssr/hydrate.js +149 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/renderToStream.d.ts +3 -0
- package/dist/ssr/renderToStream.d.ts.map +1 -0
- package/dist/ssr/renderToStream.js +138 -0
- package/dist/ssr/renderToStream.js.map +1 -0
- package/dist/ssr/renderToString.d.ts +3 -0
- package/dist/ssr/renderToString.d.ts.map +1 -0
- package/dist/ssr/renderToString.js +129 -0
- package/dist/ssr/renderToString.js.map +1 -0
- package/dist/vdom/diff.d.ts +10 -0
- package/dist/vdom/diff.d.ts.map +1 -0
- package/dist/vdom/diff.js +127 -0
- package/dist/vdom/diff.js.map +1 -0
- package/dist/vdom/h.d.ts +4 -0
- package/dist/vdom/h.d.ts.map +1 -0
- package/dist/vdom/h.js +62 -0
- package/dist/vdom/h.js.map +1 -0
- package/dist/vdom/index.d.ts +6 -0
- package/dist/vdom/index.d.ts.map +1 -0
- package/dist/vdom/index.js +5 -0
- package/dist/vdom/index.js.map +1 -0
- package/dist/vdom/patch.d.ts +4 -0
- package/dist/vdom/patch.d.ts.map +1 -0
- package/dist/vdom/patch.js +324 -0
- package/dist/vdom/patch.js.map +1 -0
- package/dist/vdom/transition.d.ts +9 -0
- package/dist/vdom/transition.d.ts.map +1 -0
- package/dist/vdom/transition.js +53 -0
- package/dist/vdom/transition.js.map +1 -0
- package/dist/vdom/types.d.ts +47 -0
- package/dist/vdom/types.d.ts.map +1 -0
- package/dist/vdom/types.js +2 -0
- package/dist/vdom/types.js.map +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Component } from '../vdom/types';
|
|
2
|
+
export type AsyncComponentOptions = {
|
|
3
|
+
loader: () => Promise<Component>;
|
|
4
|
+
loadingComponent?: Component;
|
|
5
|
+
errorComponent?: Component;
|
|
6
|
+
delay?: number;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function defineAsyncComponent(options: AsyncComponentOptions): Component;
|
|
10
|
+
//# sourceMappingURL=asyncComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncComponent.d.ts","sourceRoot":"","sources":["../../src/component/asyncComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAA;AAI1D,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;IAChC,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAC5B,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAwE9E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { signal } from 'nexa-reactivity';
|
|
2
|
+
import { h } from '../vdom/h';
|
|
3
|
+
import { getCurrentBoundary } from './suspense';
|
|
4
|
+
export function defineAsyncComponent(options) {
|
|
5
|
+
let loadedComponent = null;
|
|
6
|
+
let loadingError = null;
|
|
7
|
+
let loadPromise = null;
|
|
8
|
+
function load() {
|
|
9
|
+
if (!loadPromise) {
|
|
10
|
+
loadPromise = options.loader().then(comp => { loadedComponent = comp; }, err => { loadingError = err; });
|
|
11
|
+
}
|
|
12
|
+
return loadPromise;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
setup(props) {
|
|
16
|
+
const resolved = signal(null);
|
|
17
|
+
const error = signal(null);
|
|
18
|
+
const showLoading = signal(false);
|
|
19
|
+
const boundary = getCurrentBoundary();
|
|
20
|
+
if (boundary)
|
|
21
|
+
boundary.pending++;
|
|
22
|
+
load().then(() => {
|
|
23
|
+
if (loadedComponent) {
|
|
24
|
+
resolved.value = loadedComponent;
|
|
25
|
+
}
|
|
26
|
+
if (loadingError) {
|
|
27
|
+
error.value = loadingError;
|
|
28
|
+
}
|
|
29
|
+
if (boundary) {
|
|
30
|
+
boundary.pending--;
|
|
31
|
+
if (boundary.pending <= 0)
|
|
32
|
+
boundary.ready.value = true;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (options.delay && options.delay > 0) {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
showLoading.value = true;
|
|
38
|
+
}, options.delay);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
showLoading.value = true;
|
|
42
|
+
}
|
|
43
|
+
if (options.timeout && options.timeout > 0) {
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
if (!resolved.value && !error.value) {
|
|
46
|
+
error.value = new Error(`Async component timed out after ${options.timeout}ms`);
|
|
47
|
+
}
|
|
48
|
+
}, options.timeout);
|
|
49
|
+
}
|
|
50
|
+
return { resolved, error, showLoading, props };
|
|
51
|
+
},
|
|
52
|
+
render(ctx) {
|
|
53
|
+
if (ctx.error.value) {
|
|
54
|
+
if (options.errorComponent) {
|
|
55
|
+
return h(options.errorComponent, ctx.props, []);
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (ctx.resolved.value) {
|
|
60
|
+
const Comp = ctx.resolved.value;
|
|
61
|
+
return h(Comp, ctx.props, []);
|
|
62
|
+
}
|
|
63
|
+
if (ctx.showLoading.value && options.loadingComponent) {
|
|
64
|
+
return h(options.loadingComponent, ctx.props, []);
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=asyncComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncComponent.js","sourceRoot":"","sources":["../../src/component/asyncComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAU/C,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,IAAI,eAAe,GAAqB,IAAI,CAAA;IAC5C,IAAI,YAAY,GAAiB,IAAI,CAAA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O,IAAI,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineComponent.d.ts","sourceRoot":"","sources":["../../src/component/defineComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAE/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineComponent.js","sourceRoot":"","sources":["../../src/component/defineComponent.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,SAAoB;IAClD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Component } from '../vdom/types';
|
|
2
|
+
export type ErrorBoundaryHandler = {
|
|
3
|
+
handleError: (err: Error) => void;
|
|
4
|
+
};
|
|
5
|
+
export declare function getCurrentErrorBoundary(): ErrorBoundaryHandler | undefined;
|
|
6
|
+
export declare const ErrorBoundary: Component;
|
|
7
|
+
//# sourceMappingURL=errorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorBoundary.d.ts","sourceRoot":"","sources":["../../src/component/errorBoundary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAA;AAG1D,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;CAClC,CAAA;AAID,wBAAgB,uBAAuB,IAAI,oBAAoB,GAAG,SAAS,CAE1E;AAED,eAAO,MAAM,aAAa,EAAE,SAwB3B,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { signal } from 'nexa-reactivity';
|
|
2
|
+
import { h } from '../vdom/h';
|
|
3
|
+
const errorBoundaryStack = [];
|
|
4
|
+
export function getCurrentErrorBoundary() {
|
|
5
|
+
return errorBoundaryStack[errorBoundaryStack.length - 1];
|
|
6
|
+
}
|
|
7
|
+
export const ErrorBoundary = {
|
|
8
|
+
setup(_props) {
|
|
9
|
+
const error = signal(null);
|
|
10
|
+
const handler = {
|
|
11
|
+
handleError: (err) => { error.value = err; },
|
|
12
|
+
};
|
|
13
|
+
errorBoundaryStack.push(handler);
|
|
14
|
+
return { error, _handler: handler };
|
|
15
|
+
},
|
|
16
|
+
render(ctx) {
|
|
17
|
+
const err = ctx.error.value;
|
|
18
|
+
if (err) {
|
|
19
|
+
const fallback = ctx.props?.fallback;
|
|
20
|
+
return fallback ? fallback(err) : h('div', null, ['Error: ' + err.message]);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const content = ctx.$slots.default();
|
|
24
|
+
return content;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
ctx.error.value = e instanceof Error ? e : new Error(String(e));
|
|
28
|
+
const fallback = ctx.props?.fallback;
|
|
29
|
+
return fallback ? fallback(ctx.error.value) : h('div', null, ['Error: ' + ctx.error.value.message]);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=errorBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorBoundary.js","sourceRoot":"","sources":["../../src/component/errorBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAA;AAM7B,MAAM,kBAAkB,GAA2B,EAAE,CAAA;AAErD,MAAM,UAAU,uBAAuB;IACrC,OAAO,kBAAkB,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,KAAK,CAAC,MAA2B;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAe,IA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H,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { defineComponent } from './defineComponent';
|
|
2
|
+
export { defineAsyncComponent } from './asyncComponent';
|
|
3
|
+
export { Suspense, getCurrentBoundary } from './suspense';
|
|
4
|
+
export { ErrorBoundary } from './errorBoundary';
|
|
5
|
+
export { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, setCurrentInstance, getCurrentInstance, } from './lifecycle';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EACL,aAAa,EACb,SAAS,EACT,cAAc,EACd,SAAS,EACT,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { defineComponent } from './defineComponent';
|
|
2
|
+
export { defineAsyncComponent } from './asyncComponent';
|
|
3
|
+
export { Suspense, getCurrentBoundary } from './suspense';
|
|
4
|
+
export { ErrorBoundary } from './errorBoundary';
|
|
5
|
+
export { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, setCurrentInstance, getCurrentInstance, } from './lifecycle';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EACL,aAAa,EACb,SAAS,EACT,cAAc,EACd,SAAS,EACT,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type LifecycleHooks } from '../vdom/types';
|
|
2
|
+
export declare function setCurrentInstance(instance: {
|
|
3
|
+
lifecycle: LifecycleHooks;
|
|
4
|
+
} | null): void;
|
|
5
|
+
export declare function getCurrentInstance(): {
|
|
6
|
+
lifecycle: LifecycleHooks;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare function onBeforeMount(fn: () => void): void;
|
|
9
|
+
export declare function onMounted(fn: () => void): void;
|
|
10
|
+
export declare function onBeforeUpdate(fn: () => void): void;
|
|
11
|
+
export declare function onUpdated(fn: () => void): void;
|
|
12
|
+
export declare function onBeforeUnmount(fn: () => void): void;
|
|
13
|
+
export declare function onUnmounted(fn: () => void): void;
|
|
14
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/component/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE;IAAE,SAAS,EAAE,cAAc,CAAA;CAAE,GAAG,IAAI,GAAG,IAAI,CAEvF;AAED,wBAAgB,kBAAkB,IAAI;IAAE,SAAS,EAAE,cAAc,CAAA;CAAE,GAAG,IAAI,CAEzE;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAElD;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAE9C;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAEnD;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAE9C;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAEpD;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAEhD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
let currentInstance = null;
|
|
2
|
+
export function setCurrentInstance(instance) {
|
|
3
|
+
currentInstance = instance;
|
|
4
|
+
}
|
|
5
|
+
export function getCurrentInstance() {
|
|
6
|
+
return currentInstance;
|
|
7
|
+
}
|
|
8
|
+
export function onBeforeMount(fn) {
|
|
9
|
+
if (currentInstance)
|
|
10
|
+
currentInstance.lifecycle.beforeMount.push(fn);
|
|
11
|
+
}
|
|
12
|
+
export function onMounted(fn) {
|
|
13
|
+
if (currentInstance)
|
|
14
|
+
currentInstance.lifecycle.mounted.push(fn);
|
|
15
|
+
}
|
|
16
|
+
export function onBeforeUpdate(fn) {
|
|
17
|
+
if (currentInstance)
|
|
18
|
+
currentInstance.lifecycle.beforeUpdate.push(fn);
|
|
19
|
+
}
|
|
20
|
+
export function onUpdated(fn) {
|
|
21
|
+
if (currentInstance)
|
|
22
|
+
currentInstance.lifecycle.updated.push(fn);
|
|
23
|
+
}
|
|
24
|
+
export function onBeforeUnmount(fn) {
|
|
25
|
+
if (currentInstance)
|
|
26
|
+
currentInstance.lifecycle.beforeUnmount.push(fn);
|
|
27
|
+
}
|
|
28
|
+
export function onUnmounted(fn) {
|
|
29
|
+
if (currentInstance)
|
|
30
|
+
currentInstance.lifecycle.unmounted.push(fn);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/component/lifecycle.ts"],"names":[],"mappings":"AAEA,IAAI,eAAe,GAAyC,IAAI,CAAA;AAEhE,MAAM,UAAU,kBAAkB,CAAC,QAA8C;IAC/E,eAAe,GAAG,QAAQ,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,eAAe,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAAc;IAC1C,IAAI,eAAe;QAAE,eAAe,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACrE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAc;IACtC,IAAI,eAAe;QAAE,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACjE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAc;IAC3C,IAAI,eAAe;QAAE,eAAe,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAc;IACtC,IAAI,eAAe;QAAE,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACjE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,EAAc;IAC5C,IAAI,eAAe;QAAE,eAAe,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACvE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAc;IACxC,IAAI,eAAe;QAAE,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACnE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { signal } from 'nexa-reactivity';
|
|
2
|
+
import { type Component } from '../vdom/types';
|
|
3
|
+
export type SuspenseBoundary = {
|
|
4
|
+
pending: number;
|
|
5
|
+
ready: ReturnType<typeof signal<boolean>>;
|
|
6
|
+
};
|
|
7
|
+
export declare function getCurrentBoundary(): SuspenseBoundary | undefined;
|
|
8
|
+
export declare const Suspense: Component;
|
|
9
|
+
//# sourceMappingURL=suspense.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/component/suspense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,eAAe,CAAA;AAI1D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;CAC1C,CAAA;AAID,wBAAgB,kBAAkB,IAAI,gBAAgB,GAAG,SAAS,CAEjE;AAED,eAAO,MAAM,QAAQ,EAAE,SA+BtB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { signal } from 'nexa-reactivity';
|
|
2
|
+
import { h } from '../vdom/h';
|
|
3
|
+
import { onMounted } from './lifecycle';
|
|
4
|
+
const suspenseStack = [];
|
|
5
|
+
export function getCurrentBoundary() {
|
|
6
|
+
return suspenseStack[suspenseStack.length - 1];
|
|
7
|
+
}
|
|
8
|
+
export const Suspense = {
|
|
9
|
+
setup(_props) {
|
|
10
|
+
const ready = signal(false);
|
|
11
|
+
const boundary = { pending: 0, ready };
|
|
12
|
+
suspenseStack.push(boundary);
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
if (boundary.pending <= 0) {
|
|
15
|
+
ready.value = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return { ready };
|
|
19
|
+
},
|
|
20
|
+
render(ctx) {
|
|
21
|
+
const content = ctx.$slots.default();
|
|
22
|
+
const fallbackFn = ctx.props?.fallback;
|
|
23
|
+
if (!content) {
|
|
24
|
+
return fallbackFn ? fallbackFn() : null;
|
|
25
|
+
}
|
|
26
|
+
const pieces = [];
|
|
27
|
+
const fb = fallbackFn ? fallbackFn() : null;
|
|
28
|
+
if (ctx.ready.value) {
|
|
29
|
+
if (fb)
|
|
30
|
+
pieces.push(h('div', { key: 's-fb', style: 'display:none' }, [fb]));
|
|
31
|
+
pieces.push(h('div', { key: 's-content', style: '' }, [content]));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (fb)
|
|
35
|
+
pieces.push(fb);
|
|
36
|
+
pieces.push(h('div', { key: 's-content', style: 'display:none' }, [content]));
|
|
37
|
+
}
|
|
38
|
+
return h('div', { key: 'suspense-wrap', style: '' }, pieces);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=suspense.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.js","sourceRoot":"","sources":["../../src/component/suspense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAOvC,MAAM,aAAa,GAAuB,EAAE,CAAA;AAE5C,MAAM,UAAU,kBAAkB;IAChC,OAAO,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAChD,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAc;IACjC,KAAK,CAAC,MAA2B;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3B,MAAM,QAAQ,GAAqB,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAA;QACxD,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAE5B,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,QAAQ,CAAC,OAAO,IAAI,CAAC,EAAE,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AAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IAC9D,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Signal } from 'nexa-reactivity';
|
|
2
|
+
import type { VNode } from '../vdom';
|
|
3
|
+
export declare function vIf(condition: boolean, thenVNode: () => VNode | null, elseVNode?: () => VNode | null): VNode | null;
|
|
4
|
+
export declare function vFor<T>(items: T[], render: (item: T, index: number) => VNode | null): (VNode | null)[];
|
|
5
|
+
export declare function vShow(el: HTMLElement, signal: Signal<boolean>): () => void;
|
|
6
|
+
export declare function vModel(el: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, signal: Signal<string>): () => void;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,wBAAgB,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,GAAG,IAAI,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAEnH;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,CAEtG;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,CAK1E;AAED,wBAAgB,MAAM,CACpB,EAAE,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,mBAAmB,EAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GACrB,MAAM,IAAI,CAeZ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { effect } from 'nexa-reactivity';
|
|
2
|
+
export function vIf(condition, thenVNode, elseVNode) {
|
|
3
|
+
return condition ? thenVNode() : (elseVNode ? elseVNode() : null);
|
|
4
|
+
}
|
|
5
|
+
export function vFor(items, render) {
|
|
6
|
+
return items.map((item, index) => render(item, index));
|
|
7
|
+
}
|
|
8
|
+
export function vShow(el, signal) {
|
|
9
|
+
const dispose = effect(() => {
|
|
10
|
+
el.style.display = signal.value ? '' : 'none';
|
|
11
|
+
});
|
|
12
|
+
return dispose;
|
|
13
|
+
}
|
|
14
|
+
export function vModel(el, signal) {
|
|
15
|
+
const onInput = () => {
|
|
16
|
+
signal.value = el.value;
|
|
17
|
+
};
|
|
18
|
+
el.addEventListener('input', onInput);
|
|
19
|
+
const dispose = effect(() => {
|
|
20
|
+
el.value = signal.value;
|
|
21
|
+
});
|
|
22
|
+
return () => {
|
|
23
|
+
el.removeEventListener('input', onInput);
|
|
24
|
+
dispose();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,iBAAiB,CAAA;AAGrD,MAAM,UAAU,GAAG,CAAC,SAAkB,EAAE,SAA6B,EAAE,SAA8B;IACnG,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,IAAI,CAAI,KAAU,EAAE,MAAgD;IAClF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAAe,EAAE,MAAuB;IAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,EAAE;QAC1B,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAA;IAC/C,CAAC,CAAC,CAAA;IACF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,UAAU,MAAM,CACpB,EAA8D,EAC9D,MAAsB;IAEtB,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,KAAK,CAAA;IACzB,CAAC,CAAA;IAED,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAErC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,EAAE;QAC1B,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,EAAE;QACV,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACxC,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { h, hText, diff, mount, applyPatches, Fragment, } from './vdom';
|
|
2
|
+
export type { VNode, Component, ComponentInstance } from './vdom';
|
|
3
|
+
export { defineComponent, defineAsyncComponent, Suspense, ErrorBoundary, onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, } from './component';
|
|
4
|
+
export { vShow, vModel, vIf, vFor } from './directives';
|
|
5
|
+
export { queueJob } from './scheduler';
|
|
6
|
+
export { renderToString } from './ssr/renderToString';
|
|
7
|
+
export { renderToStream } from './ssr/renderToStream';
|
|
8
|
+
export { hydrate } from './ssr/hydrate';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,CAAC,EACD,KAAK,EACL,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,QAAQ,GACT,MAAM,QAAQ,CAAA;AACf,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAEjE,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,QAAQ,EACR,aAAa,EACb,aAAa,EACb,SAAS,EACT,cAAc,EACd,SAAS,EACT,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { h, hText, diff, mount, applyPatches, Fragment, } from './vdom';
|
|
2
|
+
export { defineComponent, defineAsyncComponent, Suspense, ErrorBoundary, onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, } from './component';
|
|
3
|
+
export { vShow, vModel, vIf, vFor } from './directives';
|
|
4
|
+
export { queueJob } from './scheduler';
|
|
5
|
+
export { renderToString } from './ssr/renderToString';
|
|
6
|
+
export { renderToStream } from './ssr/renderToStream';
|
|
7
|
+
export { hydrate } from './ssr/hydrate';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,CAAC,EACD,KAAK,EACL,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,QAAQ,GACT,MAAM,QAAQ,CAAA;AAGf,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,QAAQ,EACR,aAAa,EACb,aAAa,EACb,SAAS,EACT,cAAc,EACd,SAAS,EACT,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,IAAI,GAAG,IAAI,CAM9C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const pendingJobs = new Set();
|
|
2
|
+
let isFlushing = false;
|
|
3
|
+
export function queueJob(job) {
|
|
4
|
+
pendingJobs.add(job);
|
|
5
|
+
if (!isFlushing) {
|
|
6
|
+
isFlushing = true;
|
|
7
|
+
queueMicrotask(flushJobs);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function flushJobs() {
|
|
11
|
+
isFlushing = false;
|
|
12
|
+
const jobs = new Set(pendingJobs);
|
|
13
|
+
pendingJobs.clear();
|
|
14
|
+
for (const job of jobs) {
|
|
15
|
+
job();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,IAAI,GAAG,EAAc,CAAA;AACzC,IAAI,UAAU,GAAG,KAAK,CAAA;AAEtB,MAAM,UAAU,QAAQ,CAAC,GAAe;IACtC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACpB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,IAAI,CAAA;QACjB,cAAc,CAAC,SAAS,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC;AAED,SAAS,SAAS;IAChB,UAAU,GAAG,KAAK,CAAA;IAClB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAA;IACjC,WAAW,CAAC,KAAK,EAAE,CAAA;IACnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,GAAG,EAAE,CAAA;IACP,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../../src/ssr/hydrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAoC,MAAM,eAAe,CAAA;AAM5E,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAW9D"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { effect } from 'nexa-reactivity';
|
|
2
|
+
import { Fragment } from '../vdom/types';
|
|
3
|
+
import { setCurrentInstance } from '../component/lifecycle';
|
|
4
|
+
import { mount } from '../vdom/patch';
|
|
5
|
+
import { diff } from '../vdom/diff';
|
|
6
|
+
import { applyPatches } from '../vdom/patch';
|
|
7
|
+
export function hydrate(vnode, container) {
|
|
8
|
+
const firstChild = container.firstChild;
|
|
9
|
+
if (firstChild) {
|
|
10
|
+
const result = hydrateNode(vnode, container, firstChild);
|
|
11
|
+
if (!result) {
|
|
12
|
+
container.innerHTML = '';
|
|
13
|
+
mount(vnode, container);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
mount(vnode, container);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function hydrateNode(vnode, parent, anchor) {
|
|
21
|
+
switch (vnode._type) {
|
|
22
|
+
case 'text': {
|
|
23
|
+
if (anchor?.nodeType === Node.TEXT_NODE) {
|
|
24
|
+
vnode.el = anchor;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
case 'element': {
|
|
30
|
+
if (anchor instanceof HTMLElement && anchor.tagName.toLowerCase() === vnode.tag) {
|
|
31
|
+
vnode.el = anchor;
|
|
32
|
+
attachEvents(anchor, vnode.props);
|
|
33
|
+
const childNodes = Array.from(anchor.childNodes);
|
|
34
|
+
const children = vnode.children ?? [];
|
|
35
|
+
for (let i = 0; i < children.length; i++) {
|
|
36
|
+
if (i < childNodes.length) {
|
|
37
|
+
hydrateNode(children[i], anchor, childNodes[i]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
case 'component': {
|
|
45
|
+
hydrateComponent(vnode, parent, anchor);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
case 'fragment': {
|
|
49
|
+
const children = vnode.children ?? [];
|
|
50
|
+
let currentChild = anchor;
|
|
51
|
+
for (const child of children) {
|
|
52
|
+
if (currentChild) {
|
|
53
|
+
hydrateNode(child, parent, currentChild);
|
|
54
|
+
currentChild = currentChild.nextSibling;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function hydrateComponent(vnode, parent, anchor) {
|
|
62
|
+
if (vnode.tag === Fragment) {
|
|
63
|
+
const children = vnode.children ?? [];
|
|
64
|
+
let currentChild = anchor;
|
|
65
|
+
for (const child of children) {
|
|
66
|
+
if (currentChild) {
|
|
67
|
+
hydrateNode(child, parent, currentChild);
|
|
68
|
+
currentChild = currentChild.nextSibling;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const comp = vnode.tag;
|
|
74
|
+
const instance = {
|
|
75
|
+
component: comp,
|
|
76
|
+
props: vnode.props ?? {},
|
|
77
|
+
setupState: {},
|
|
78
|
+
vnode: null,
|
|
79
|
+
mounted: false,
|
|
80
|
+
lifecycle: {
|
|
81
|
+
beforeMount: [],
|
|
82
|
+
mounted: [],
|
|
83
|
+
beforeUpdate: [],
|
|
84
|
+
updated: [],
|
|
85
|
+
beforeUnmount: [],
|
|
86
|
+
unmounted: [],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
vnode.component = instance;
|
|
90
|
+
setCurrentInstance(instance);
|
|
91
|
+
const setupCtx = {
|
|
92
|
+
emit: (event, ...args) => {
|
|
93
|
+
const handler = vnode.props?.[`on${event[0].toUpperCase()}${event.slice(1)}`];
|
|
94
|
+
if (handler)
|
|
95
|
+
handler(...args);
|
|
96
|
+
},
|
|
97
|
+
slots: {
|
|
98
|
+
default: () => {
|
|
99
|
+
const children = vnode.children ?? [];
|
|
100
|
+
return children.length > 0 ? children[0] : null;
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
let setupState = {};
|
|
105
|
+
if (comp.setup) {
|
|
106
|
+
setupState = comp.setup(vnode.props ?? {}, setupCtx);
|
|
107
|
+
}
|
|
108
|
+
instance.setupState = setupState;
|
|
109
|
+
setCurrentInstance(null);
|
|
110
|
+
if (comp.render) {
|
|
111
|
+
const ctx = { ...setupState, props: vnode.props, $slots: setupCtx.slots };
|
|
112
|
+
let oldVNode = null;
|
|
113
|
+
let isFirstRender = true;
|
|
114
|
+
effect(() => {
|
|
115
|
+
const newVNode = comp.render(ctx);
|
|
116
|
+
if (!newVNode)
|
|
117
|
+
return;
|
|
118
|
+
if (isFirstRender) {
|
|
119
|
+
instance.vnode = newVNode;
|
|
120
|
+
if (anchor instanceof Element || anchor instanceof Text) {
|
|
121
|
+
hydrateNode(newVNode, parent, anchor);
|
|
122
|
+
}
|
|
123
|
+
instance.mounted = true;
|
|
124
|
+
isFirstRender = false;
|
|
125
|
+
instance.mounted = true;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const patches = diff(oldVNode, newVNode, parent);
|
|
129
|
+
applyPatches(patches);
|
|
130
|
+
instance.vnode = newVNode;
|
|
131
|
+
}
|
|
132
|
+
oldVNode = newVNode;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function attachEvents(el, props) {
|
|
137
|
+
if (!props)
|
|
138
|
+
return;
|
|
139
|
+
for (const key of Object.keys(props)) {
|
|
140
|
+
if (key.startsWith('on')) {
|
|
141
|
+
const event = key.slice(2).toLowerCase();
|
|
142
|
+
const handler = props[key];
|
|
143
|
+
if (typeof handler === 'function') {
|
|
144
|
+
el.addEventListener(event, handler);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=hydrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../../src/ssr/hydrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAc,QAAQ,EAA0B,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,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