@monkeyplus/flow 5.0.0-rc.87 → 5.0.0-rc.9
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/app/flow.d.ts +2 -9
- package/dist/app/flow.mjs +0 -3
- package/dist/core/runtime/nitro/flow.mjs +2 -3
- package/dist/core/runtime/nitro/renderer.mjs +14 -52
- package/dist/head/runtime/plugin.mjs +1 -0
- package/dist/index.mjs +1393 -27
- package/dist/pages/runtime/helpers/index.mjs +2 -5
- package/dist/pages/runtime/index.d.ts +3 -10
- package/dist/pages/runtime/index.mjs +4 -11
- package/dist/pages/runtime/plugin.mjs +56 -0
- package/dist/vite-client/runtime/injectManifest.mjs +3 -4
- package/dist/vite-client/runtime/plugin.mjs +2 -3
- package/package.json +26 -31
- package/dist/app/entry.async.d.ts +0 -3
- package/dist/app/entry.async.mjs +0 -1
- package/dist/chunks/dev-bundler.mjs +0 -245
- package/dist/chunks/external.mjs +0 -37
- package/dist/chunks/index.mjs +0 -1136
- package/dist/chunks/vite-node.mjs +0 -149
- package/dist/core/runtime/client.manifest.d.mts +0 -2
- package/dist/core/runtime/client.manifest.mjs +0 -6
- package/dist/core/runtime/vite-node-shared.d.mts +0 -1
- package/dist/core/runtime/vite-node-shared.d.ts +0 -8
- package/dist/core/runtime/vite-node-shared.mjs +0 -3
- package/dist/core/runtime/vite-node.d.mts +0 -2
- package/dist/core/runtime/vite-node.mjs +0 -42
- package/dist/pages/runtime/pages.mjs +0 -96
- /package/dist/pages/runtime/{pages.d.ts → plugin.d.ts} +0 -0
package/dist/app/flow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RadixRouter } from 'radix3';
|
|
2
2
|
import type { Hookable } from 'hookable';
|
|
3
|
-
import type {
|
|
3
|
+
import type { FlowPage, RuntimeConfig } from '@monkeyplus/flow-schema';
|
|
4
4
|
declare type HookResult = Promise<void> | void;
|
|
5
5
|
export interface FlowAppHooks {
|
|
6
6
|
'flow:pages': (page: FlowPage[]) => HookResult;
|
|
@@ -11,10 +11,6 @@ export interface FlowAppHooks {
|
|
|
11
11
|
bodyStart: string[];
|
|
12
12
|
}) => HookResult;
|
|
13
13
|
'page:links': (links: string[]) => HookResult;
|
|
14
|
-
'page:context': (ctx: {
|
|
15
|
-
page: string;
|
|
16
|
-
localeCode: string;
|
|
17
|
-
}, utils: any, data: Record<string, any>) => HookResult;
|
|
18
14
|
'page:chunks': (bundle: string, scripts: {
|
|
19
15
|
head: string[];
|
|
20
16
|
body: string[];
|
|
@@ -31,14 +27,11 @@ export interface FlowApp {
|
|
|
31
27
|
callHook: FlowApp['hooks']['callHook'];
|
|
32
28
|
eta: any;
|
|
33
29
|
app: {
|
|
34
|
-
utils:
|
|
30
|
+
utils: Record<string, any>;
|
|
35
31
|
plugins: Record<string, any>;
|
|
36
32
|
globals: Record<string, any>;
|
|
37
33
|
};
|
|
38
34
|
engine: string;
|
|
39
|
-
site: {
|
|
40
|
-
origin: string;
|
|
41
|
-
};
|
|
42
35
|
engines: Record<string, (template: string) => string>;
|
|
43
36
|
generate: boolean;
|
|
44
37
|
render: (view: Record<string, string>, data: any) => Promise<string> | void | string;
|
package/dist/app/flow.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "node-fetch-native/polyfill";
|
|
2
1
|
import { defineEventHandler } from "h3";
|
|
3
|
-
import
|
|
2
|
+
import "node-fetch-native/polyfill";
|
|
3
|
+
import { useRuntimeConfig } from "#internal/nitro";
|
|
4
4
|
const getServerApp = cachedImport(() => import("#server"));
|
|
5
5
|
const getFlowRenderer = cachedResult(async () => {
|
|
6
6
|
const createFlowApp = await getServerApp();
|
|
@@ -12,7 +12,6 @@ export default defineEventHandler(async ({ context }) => {
|
|
|
12
12
|
const flow = await getFlowRenderer();
|
|
13
13
|
context.flow = flow;
|
|
14
14
|
context.render = flow.render;
|
|
15
|
-
context.defineCachedFunction = defineCachedFunction;
|
|
16
15
|
});
|
|
17
16
|
function _interopDefault(e) {
|
|
18
17
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { eventHandler, useQuery } from "h3";
|
|
2
|
-
import { joinURL } from "ufo";
|
|
3
|
-
const normalizeCall = async (seo, ctx) => {
|
|
4
|
-
if (typeof seo === "function")
|
|
5
|
-
return await seo(ctx);
|
|
6
|
-
return seo || {};
|
|
7
|
-
};
|
|
8
2
|
export default eventHandler(async (event) => {
|
|
9
3
|
const url = event.req.url?.split("?")[0];
|
|
10
4
|
const flow = event.context.flow;
|
|
@@ -15,64 +9,38 @@ export default eventHandler(async (event) => {
|
|
|
15
9
|
const scripts = { head: [], bodyStart: [], bodyEnd: [] };
|
|
16
10
|
const chunks = { head: [], body: [] };
|
|
17
11
|
const generate = {};
|
|
18
|
-
const { page, locale, params, view
|
|
12
|
+
const { page, locale, params, view } = flow.router.byUrl.lookup(url) || {};
|
|
19
13
|
if (!page)
|
|
20
14
|
return;
|
|
15
|
+
await flow.callHook("page:scripts", scripts);
|
|
21
16
|
if (view.bundle)
|
|
22
17
|
await flow.callHook("page:chunks", view.bundle, chunks);
|
|
23
18
|
const templateContext = {};
|
|
24
|
-
const
|
|
25
|
-
const contextPage = {
|
|
26
|
-
chunks,
|
|
27
|
-
locale
|
|
28
|
-
};
|
|
19
|
+
const dynamyc = params?._;
|
|
20
|
+
const contextPage = {};
|
|
29
21
|
const contextInject = {};
|
|
30
|
-
const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value
|
|
31
|
-
const contextHooks = {};
|
|
32
|
-
await flow.callHook("page:context", { localeCode: locale.code, page: pageName }, utils, contextHooks);
|
|
22
|
+
const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value }, flow.app.utils);
|
|
33
23
|
templateContext.url = url;
|
|
34
|
-
templateContext.baseURL = flow.$config.app.baseURL;
|
|
35
|
-
const pageObject = {
|
|
36
|
-
name: pageName,
|
|
37
|
-
pathname: url,
|
|
38
|
-
url: joinURL(flow.site.origin, templateContext.baseURL, `${url}`),
|
|
39
|
-
origin: flow.site.origin,
|
|
40
|
-
joinOrigin: (_url, includeBase) => joinURL(flow.site.origin, includeBase ? templateContext.baseURL : "/", _url)
|
|
41
|
-
};
|
|
42
|
-
templateContext.page = pageObject;
|
|
43
|
-
contextPage.page = pageObject;
|
|
44
24
|
templateContext.locale = locale;
|
|
45
25
|
templateContext.view = view;
|
|
46
|
-
if (
|
|
26
|
+
if (dynamyc && page.dynamic) {
|
|
47
27
|
const pages = await page.dynamic.method({ locale, utils });
|
|
48
|
-
const dynamicPage = pages.find((_page) => _page.url ===
|
|
28
|
+
const dynamicPage = pages.find((_page) => _page.url === dynamyc);
|
|
49
29
|
if (!dynamicPage)
|
|
50
30
|
return;
|
|
51
31
|
if (page.dynamic.assign)
|
|
52
32
|
templateContext[page.dynamic.assign] = dynamicPage.context;
|
|
53
|
-
contextPage.
|
|
33
|
+
contextPage.dynamyc = dynamicPage;
|
|
54
34
|
}
|
|
55
35
|
templateContext.seo = {};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
...contextPage,
|
|
59
|
-
utils
|
|
60
|
-
});
|
|
61
|
-
templateContext.sharedContext = sharedContext || {};
|
|
36
|
+
templateContext.context = {};
|
|
37
|
+
templateContext.sharedContext = {};
|
|
62
38
|
templateContext.utils = utils;
|
|
63
|
-
templateContext.seo = await
|
|
64
|
-
|
|
65
|
-
templateContext.context = {
|
|
66
|
-
...contextHooks,
|
|
67
|
-
...contexData
|
|
68
|
-
};
|
|
69
|
-
await flow.callHook("page:scripts", scripts, templateContext);
|
|
39
|
+
templateContext.seo = await page.seo?.({ ...contextPage, utils }) || {};
|
|
40
|
+
templateContext.context = await page.context?.({ ...contextPage, utils }) || {};
|
|
70
41
|
templateContext.getHeadScripts = () => {
|
|
71
42
|
return scripts.head.join("\n");
|
|
72
43
|
};
|
|
73
|
-
templateContext.getBodyEndScripts = () => {
|
|
74
|
-
return scripts.bodyEnd.join("\n");
|
|
75
|
-
};
|
|
76
44
|
templateContext.getHeadChunks = () => {
|
|
77
45
|
return chunks.head.join("\n");
|
|
78
46
|
};
|
|
@@ -85,14 +53,8 @@ export default eventHandler(async (event) => {
|
|
|
85
53
|
const query = useQuery(event);
|
|
86
54
|
if (query?.context)
|
|
87
55
|
return { ...templateContext, utils: Object.keys(utils) };
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
html = await view.render(templateContext, event);
|
|
91
|
-
else
|
|
92
|
-
html = await flow.render(view, templateContext);
|
|
93
|
-
event.res.setHeader("Content-Type", view.contentType || "text/html;charset=UTF-8");
|
|
94
|
-
if (view.postRender)
|
|
95
|
-
html = await view.postRender(html, event);
|
|
56
|
+
const html = await flow.render(view, templateContext);
|
|
57
|
+
event.res.setHeader("Content-Type", "text/html;charset=UTF-8");
|
|
96
58
|
if (flow.generate) {
|
|
97
59
|
await flow.callHook("page:generate", generate);
|
|
98
60
|
globalThis.generate = generate;
|