@thestarweb/star-framework-app-web-vue 0.2.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.
@@ -0,0 +1,9 @@
1
+ import vuePlugin from "@vitejs/plugin-vue";
2
+ export function SFWebVuePlugin() {
3
+ return {
4
+ name: "sf-web-vue",
5
+ vitePlugin: vuePlugin(),
6
+ };
7
+ }
8
+ SFWebVuePlugin.__type = ['SFPluging', 'SFWebVuePlugin', 'P"w!/"'];
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,MAAM,UAAU,cAAc;IAC7B,OAAO;QACN,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,SAAS,EAAE;KACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { createSystemProvide } from "./context-helper.js";
2
+ const base = createSystemProvide("baseUrl", "/");
3
+ export const provideBaseUrl = base.provide;
4
+ export const useBaseUrl = base.use;
5
+ //# sourceMappingURL=base-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-url.js","sourceRoot":"","sources":["../../src/data-context/base-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC;AAC3C,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC"}
@@ -0,0 +1,31 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ import { SFDataContext, } from "@thestarweb/star-framework-app-web";
6
+ import { computed, inject, shallowRef, } from "vue";
7
+ const __ΩGetSFDataContextType = ['T', () => SFDataContext, 'GetSFDataContextType', 'l:e"!R#RPde#!Ph"!7"qk#\'QRb!Pde"!p)w#y'];
8
+ export { __ΩGetSFDataContextType as __ΩGetSFDataContextType };
9
+ export function sfContextToRef(context) {
10
+ const r = shallowRef(context.value);
11
+ context.watch(__assignType((newValue) => {
12
+ r.value = newValue;
13
+ }, ['newValue', '', 'P"2!"/"']));
14
+ return computed(() => r.value);
15
+ }
16
+ sfContextToRef.__type = ['context', 'ComputedRef', 'sfContextToRef', 'P"2!"w"/#'];
17
+ const __ΩGetPType = ['P', 'RenderDataContext', "system", () => SFDataContext, 'ComputedRef', "system", 'GetPType', 'l2"w%R"w".&fe#!fRb!Pd"w".#fe"!fPh"!7$qk#\'Qw\'y'];
18
+ export function createSystemProvide(path, defaultValue) {
19
+ const provideKey = Symbol();
20
+ return {
21
+ provide: __assignType(function provide(context, app) {
22
+ const value = context.system[path];
23
+ app.provide(provideKey, value instanceof SFDataContext ? sfContextToRef(value) : value);
24
+ }, ['RenderDataContext', 'context', 'App', 'app', 'provide', 'P"w!2""w#2$"/%']),
25
+ use() {
26
+ return (inject.Ω = [[() => __ΩGetPType, () => path, () => defaultValue, () => __ΩGetPType, 'Pdi"h!!qe!!!jPdi#h!!o$"qe!!!jo!"']], inject(provideKey, defaultValue));
27
+ },
28
+ };
29
+ }
30
+ createSystemProvide.__type = ['path', () => __ΩGetPType, 'defaultValue', 'createSystemProvide', 'P"2!"o""2#"/$'];
31
+ //# sourceMappingURL=context-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-helper.js","sourceRoot":"","sources":["../../src/data-context/context-helper.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAEN,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAEN,QAAQ,EAER,MAAM,EAEN,UAAU,GACV,MAAM,KAAK,CAAC;;;AAKb,MAAM,UAAU,cAAc,CAC7B,OAAU;IAEV,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,KAAK,cAAC,CAAC,QAAQ,EAAE,EAAE;QAC1B,CAAC,CAAC,KAAK,GAAG,QAAQ,CAAC;IACpB,CAAC,+BAAC,CAAC;IACH,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;;;AAKD,MAAM,UAAU,mBAAmB,CAEjC,IAAO,EAAE,YAAyB;IACnC,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO;QACN,OAAO,wBAAP,OAAO,CAAC,OAA0B,EAAE,GAAQ;YAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACnC,GAAG,CAAC,OAAO,CACV,UAAU,EACV,KAAK,YAAY,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAC9D,CAAC;QACH,CAAC;QACD,GAAG;YACF,QAAO,MAAM,mHAAN,MAAM,CAAc,UAAU,EAAE,YAAY,CAAC,EAAC;QACtD,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ import { provideRequest } from "./request.js";
6
+ import { provideRoute } from "./route.js";
7
+ export * from "./context-helper.js";
8
+ export * from "./route.js";
9
+ export * from "./request.js";
10
+ export * from "./base-url.js";
11
+ export function provideSystemContext(context, app) {
12
+ [provideRoute, provideRequest].forEach(__assignType((fn) => fn(context, app), ['fn', '', 'P"2!"/"']));
13
+ }
14
+ provideSystemContext.__type = ['RenderDataContext', 'context', 'App', 'app', 'provideSystemContext', 'P"w!2""w#2$"/%'];
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/data-context/index.ts"],"names":[],"mappings":";;;;AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAE9B,MAAM,UAAU,oBAAoB,CAAC,OAA0B,EAAE,GAAQ;IACxE,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC,OAAO,cAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,yBAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { createSystemProvide } from "./context-helper.js";
2
+ import { SFWebRequest } from "@thestarweb/star-framework-app-web";
3
+ const base = createSystemProvide("request", new SFWebRequest("/"));
4
+ export const provideRequest = base.provide;
5
+ export const useRequest = base.use;
6
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/data-context/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,MAAM,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC;AAC3C,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { computed } from "vue";
2
+ import { createSystemProvide } from "./context-helper.js";
3
+ const base = createSystemProvide("route", computed(() => ({ allRoute: [] })));
4
+ export const provideRoute = base.provide;
5
+ export const useRoute = base.use;
6
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/data-context/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,IAAI,GAAG,mBAAmB,CAC/B,OAAO,EACP,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAClC,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;AACzC,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./render.js";
2
+ // @side-only server
3
+ export * from "./cli/index.js";
4
+ export { useRoute, useRequest, useBaseUrl } from "./data-context/index.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,oBAAoB;AACpB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/render.js ADDED
@@ -0,0 +1,93 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ import { createApp, createSSRApp, defineAsyncComponent, h, onMounted, onUpdated, ref, shallowRef, } from "vue";
6
+ import { renderToString } from "vue/server-renderer";
7
+ /*@ts-ignore*/
8
+ import { __ΩLoadableType } from "@thestarweb/star-framework-utils";
9
+ import { load } from "@thestarweb/star-framework-utils";
10
+ import { provideSystemContext } from "./data-context/index.js";
11
+ export class VueRender {
12
+ compLoader;
13
+ comp;
14
+ constructor(compLoader) {
15
+ this.compLoader = compLoader;
16
+ }
17
+ async fetchResource() {
18
+ this.comp = await load(this.compLoader);
19
+ }
20
+ _makeContext(context, app) {
21
+ provideSystemContext(context, app);
22
+ }
23
+ async renderToString(context, prop, child) {
24
+ const app = createApp(this.comp, prop);
25
+ this._makeContext(context, app);
26
+ app.component("sf-route", defineAsyncComponent(async () => {
27
+ const subRender = child.render;
28
+ if (subRender instanceof VueRender) {
29
+ return h(subRender.comp, prop);
30
+ }
31
+ const str = await child.warpRenderToString({});
32
+ return h("div", {
33
+ innerHTML: str,
34
+ });
35
+ }));
36
+ const str = await renderToString(app);
37
+ // console.log(str);
38
+ return str;
39
+ }
40
+ _mount(dom, context, prop, chrild, hydrate) {
41
+ const refProp = shallowRef(prop);
42
+ const refChild = shallowRef(chrild);
43
+ const app = (hydrate ? createSSRApp : createApp)({
44
+ setup: () => {
45
+ return () => h(this.comp, refProp.value);
46
+ },
47
+ });
48
+ this._makeContext(context, app);
49
+ app.component("sf-route", {
50
+ setup: () => {
51
+ const divRef = (ref.Ω = [['!']], ref());
52
+ let ins = null;
53
+ const render = __assignType((hydrate = false) => {
54
+ ins?.unMount();
55
+ ins = null;
56
+ if (!(refChild.value.render instanceof VueRender)) {
57
+ ins = chrild[hydrate ? "hydrate" : "mount"](divRef.value, {});
58
+ }
59
+ }, ['hydrate', () => false, '', 'P)2!>""/#']);
60
+ onMounted(() => {
61
+ render(hydrate && !!divRef.value?.innerHTML);
62
+ });
63
+ onUpdated(() => {
64
+ render();
65
+ });
66
+ return () => {
67
+ if (refChild.value.render instanceof VueRender) {
68
+ return h(refChild.value.render.comp);
69
+ }
70
+ return h("div", {
71
+ ref: divRef,
72
+ });
73
+ };
74
+ },
75
+ });
76
+ app.mount(dom);
77
+ return {
78
+ unMount: () => {
79
+ app.unmount();
80
+ },
81
+ updateProp: __assignType((newProp) => (refProp.value = newProp), ['newProp', '', 'P"2!"/"']),
82
+ updateChild: __assignType((newChild) => (refChild.value = newChild), ['newChild', '', 'P"2!"/"']),
83
+ };
84
+ }
85
+ mount(dom, context, prop, chrild) {
86
+ return this._mount(dom, context, prop, chrild, false);
87
+ }
88
+ hydrate(dom, context, prop, chrild) {
89
+ return this._mount(dom, context, prop, chrild, true);
90
+ }
91
+ static __type = ['Component', 'comp', () => __ΩLoadableType, 'compLoader', 'constructor', 'fetchResource', 'RenderDataContext', 'context', 'App', 'app', '_makeContext', 'prop', 'RenderContext', 'child', 'renderToString', 'dom', 'chrild', 'hydrate', 'RenderInstance', '_mount', 'mount', 'IRender', 'VueRender', '"w!3"P"w!o#"2$;"0%P"0&P"w\'2("w)2*"0+P"w\'2("2,"w-2."0/P!20"w\'2("2,"w-21)22"w304P!20"w\'2("2,"w-21"05P!20"w\'2("2,"w-21"025"w6x"w7'];
92
+ }
93
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":";;;;AAOA,OAAO,EAGN,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,CAAC,EACD,SAAS,EACT,SAAS,EACT,GAAG,EACH,UAAU,GACV,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;;gCAClB,kCAAkC;AAArE,OAAO,EAAE,IAAI,EAAgB,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,OAAO,SAAS;IAED;IADpB,IAAI,CAAa;IACjB,YAAoB,UAAmC;QAAnC,eAAU,GAAV,UAAU,CAAyB;IAAG,CAAC;IAC3D,KAAK,CAAC,aAAa;QAClB,IAAI,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IACD,YAAY,CAAC,OAA0B,EAAE,GAAQ;QAChD,oBAAoB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC;IACD,KAAK,CAAC,cAAc,CACnB,OAA0B,EAC1B,IAAS,EACT,KAAoB;QAEpB,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,C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CAAC,CAAC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,8BAAA;SACtD,CAAC;IACH,CAAC;IACD,KAAK,CACJ,GAAgB,EAChB,OAA0B,EAC1B,IAAS,EACT,MAAqB;QAErB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,CACN,GAAgB,EAChB,OAA0B,EAC1B,IAAS,EACT,MAAqB;QAErB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@thestarweb/star-framework-app-web-vue",
3
+ "version": "0.2.0",
4
+ "description": "Star Framework Web App VUE pluging",
5
+ "main": "dist/index.js",
6
+ "types": "src/index.ts",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "scripts": {
13
+ "build": "tspc -p tsconfig.build.json",
14
+ "dev": "tspc -p tsconfig.build.json --watch",
15
+ "test": "vitest"
16
+ },
17
+ "dependencies": {
18
+ "@thestarweb/star-framework-app-web": "^0.2.0",
19
+ "@thestarweb/star-framework-utils": "^0.2.0",
20
+ "@vitejs/plugin-vue": "^6.0.8",
21
+ "tslib": "^2.8.1"
22
+ },
23
+ "peerDependencies": {
24
+ "vue": "^3.5.41"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^26.0.1",
28
+ "ts-patch": "^4.0.1",
29
+ "typescript": "^6.0.3",
30
+ "vitest": "^4.1.9"
31
+ },
32
+ "license": "ISC",
33
+ "gitHead": "8161c026c503fbe0a7a825d9c1efbd7e527705c4"
34
+ }
@@ -0,0 +1,9 @@
1
+ import type { SFPluging } from "@thestarweb/star-framework-cli";
2
+ import vuePlugin from "@vitejs/plugin-vue";
3
+
4
+ export function SFWebVuePlugin(): SFPluging {
5
+ return {
6
+ name: "sf-web-vue",
7
+ vitePlugin: vuePlugin(),
8
+ };
9
+ }
@@ -0,0 +1,5 @@
1
+ import { createSystemProvide } from "./context-helper.js";
2
+
3
+ const base = createSystemProvide("baseUrl", "/");
4
+ export const provideBaseUrl = base.provide;
5
+ export const useBaseUrl = base.use;
@@ -0,0 +1,46 @@
1
+ import {
2
+ type RenderDataContext,
3
+ SFDataContext,
4
+ } from "@thestarweb/star-framework-app-web";
5
+ import {
6
+ App,
7
+ computed,
8
+ ComputedRef,
9
+ inject,
10
+ ShallowRef,
11
+ shallowRef,
12
+ } from "vue";
13
+
14
+ export type GetSFDataContextType<T extends SFDataContext<any>> =
15
+ T extends SFDataContext<infer R> ? R : unknown;
16
+
17
+ export function sfContextToRef<T extends SFDataContext<any>>(
18
+ context: T,
19
+ ): ComputedRef<GetSFDataContextType<T>> {
20
+ const r = shallowRef(context.value);
21
+ context.watch((newValue) => {
22
+ r.value = newValue;
23
+ });
24
+ return computed(() => r.value);
25
+ }
26
+ type GetPType<P extends keyof RenderDataContext["system"]> =
27
+ RenderDataContext["system"][P] extends SFDataContext<infer TT>
28
+ ? ComputedRef<TT>
29
+ : RenderDataContext["system"][P];
30
+ export function createSystemProvide<
31
+ P extends keyof RenderDataContext["system"],
32
+ >(path: P, defaultValue: GetPType<P>) {
33
+ const provideKey = Symbol();
34
+ return {
35
+ provide(context: RenderDataContext, app: App) {
36
+ const value = context.system[path];
37
+ app.provide(
38
+ provideKey,
39
+ value instanceof SFDataContext ? sfContextToRef(value) : value,
40
+ );
41
+ },
42
+ use() {
43
+ return inject<GetPType<P>>(provideKey, defaultValue);
44
+ },
45
+ };
46
+ }
@@ -0,0 +1,13 @@
1
+ import { type RenderDataContext } from "@thestarweb/star-framework-app-web";
2
+ import { provideRequest } from "./request.js";
3
+ import { App } from "vue";
4
+ import { provideRoute } from "./route.js";
5
+
6
+ export * from "./context-helper.js";
7
+ export * from "./route.js";
8
+ export * from "./request.js";
9
+ export * from "./base-url.js";
10
+
11
+ export function provideSystemContext(context: RenderDataContext, app: App) {
12
+ [provideRoute, provideRequest].forEach((fn) => fn(context, app));
13
+ }
@@ -0,0 +1,6 @@
1
+ import { createSystemProvide } from "./context-helper.js";
2
+ import { SFWebRequest } from "@thestarweb/star-framework-app-web";
3
+
4
+ const base = createSystemProvide("request", new SFWebRequest("/"));
5
+ export const provideRequest = base.provide;
6
+ export const useRequest = base.use;
@@ -0,0 +1,9 @@
1
+ import { computed } from "vue";
2
+ import { createSystemProvide } from "./context-helper.js";
3
+
4
+ const base = createSystemProvide(
5
+ "route",
6
+ computed(() => ({ allRoute: [] })),
7
+ );
8
+ export const provideRoute = base.provide;
9
+ export const useRoute = base.use;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./render.js";
2
+ // @side-only server
3
+ export * from "./cli/index.js";
4
+ export { useRoute, useRequest, useBaseUrl } from "./data-context/index.js";
package/src/render.ts ADDED
@@ -0,0 +1,125 @@
1
+ import {
2
+ type RenderDataContext,
3
+ WarpRenderInstance,
4
+ type IRender,
5
+ type RenderContext,
6
+ type RenderInstance,
7
+ } from "@thestarweb/star-framework-app-web";
8
+ import {
9
+ App,
10
+ Component,
11
+ createApp,
12
+ createSSRApp,
13
+ defineAsyncComponent,
14
+ h,
15
+ onMounted,
16
+ onUpdated,
17
+ ref,
18
+ shallowRef,
19
+ } from "vue";
20
+ import { renderToString } from "vue/server-renderer";
21
+ import { load, LoadableType } from "@thestarweb/star-framework-utils";
22
+ import { provideSystemContext } from "./data-context/index.js";
23
+
24
+ export class VueRender implements IRender {
25
+ comp!: Component;
26
+ constructor(private compLoader: LoadableType<Component>) {}
27
+ async fetchResource() {
28
+ this.comp = await load(this.compLoader);
29
+ }
30
+ _makeContext(context: RenderDataContext, app: App) {
31
+ provideSystemContext(context, app);
32
+ }
33
+ async renderToString(
34
+ context: RenderDataContext,
35
+ prop: any,
36
+ child: RenderContext,
37
+ ) {
38
+ const app = createApp(this.comp, prop);
39
+ this._makeContext(context, app);
40
+ app.component(
41
+ "sf-route",
42
+ defineAsyncComponent(async () => {
43
+ const subRender = child.render;
44
+ if (subRender instanceof VueRender) {
45
+ return h(subRender.comp, prop);
46
+ }
47
+ const str = await child.warpRenderToString({});
48
+ return h("div", {
49
+ innerHTML: str,
50
+ });
51
+ }),
52
+ );
53
+ const str = await renderToString(app);
54
+ // console.log(str);
55
+
56
+ return str;
57
+ }
58
+ _mount(
59
+ dom: HTMLElement,
60
+ context: RenderDataContext,
61
+ prop: any,
62
+ chrild: RenderContext,
63
+ hydrate: boolean,
64
+ ): RenderInstance {
65
+ const refProp = shallowRef(prop);
66
+ const refChild = shallowRef(chrild);
67
+ const app = (hydrate ? createSSRApp : createApp)({
68
+ setup: () => {
69
+ return () => h(this.comp, refProp.value);
70
+ },
71
+ });
72
+ this._makeContext(context, app);
73
+ app.component("sf-route", {
74
+ setup: () => {
75
+ const divRef = ref<HTMLDivElement>();
76
+ let ins: WarpRenderInstance | null = null;
77
+ const render = (hydrate: boolean = false) => {
78
+ ins?.unMount();
79
+ ins = null;
80
+ if (!(refChild.value.render instanceof VueRender)) {
81
+ ins = chrild[hydrate ? "hydrate" : "mount"](divRef.value!, {});
82
+ }
83
+ };
84
+ onMounted(() => {
85
+ render(hydrate && !!divRef.value?.innerHTML);
86
+ });
87
+ onUpdated(() => {
88
+ render();
89
+ });
90
+ return () => {
91
+ if (refChild.value.render instanceof VueRender) {
92
+ return h(refChild.value.render.comp);
93
+ }
94
+ return h("div", {
95
+ ref: divRef,
96
+ });
97
+ };
98
+ },
99
+ });
100
+ app.mount(dom);
101
+ return {
102
+ unMount: () => {
103
+ app.unmount();
104
+ },
105
+ updateProp: (newProp) => (refProp.value = newProp),
106
+ updateChild: (newChild) => (refChild.value = newChild),
107
+ };
108
+ }
109
+ mount(
110
+ dom: HTMLElement,
111
+ context: RenderDataContext,
112
+ prop: any,
113
+ chrild: RenderContext,
114
+ ) {
115
+ return this._mount(dom, context, prop, chrild, false);
116
+ }
117
+ hydrate(
118
+ dom: HTMLElement,
119
+ context: RenderDataContext,
120
+ prop: any,
121
+ chrild: RenderContext,
122
+ ) {
123
+ return this._mount(dom, context, prop, chrild, true);
124
+ }
125
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./src",
4
+ "outDir": "./dist"
5
+ },
6
+ "extends": "../../tsconfig.json",
7
+ "reflection": true,
8
+ "include": ["src/**/*"]
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "noEmit": true,
4
+ "rootDir": "./"
5
+ },
6
+ "extends":"./tsconfig.build.json",
7
+ "include": ["src/**/*", "tests/**/*"]
8
+ }