@monkeyplus/flow 5.0.0-rc.228 → 5.0.0-rc.23
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/entry.d.ts +2 -2
- package/dist/app/entry.mjs +2 -3
- package/dist/app/flow.d.ts +3 -12
- package/dist/app/flow.mjs +0 -3
- package/dist/core/runtime/nitro/flow.d.ts +1 -2
- package/dist/core/runtime/nitro/flow.mjs +14 -8
- package/dist/core/runtime/nitro/renderer.d.ts +1 -1
- package/dist/core/runtime/nitro/renderer.mjs +14 -68
- package/dist/head/runtime/plugin.mjs +1 -0
- package/dist/index.mjs +767 -528
- package/dist/pages/runtime/helpers/index.d.ts +1 -1
- package/dist/pages/runtime/helpers/index.mjs +3 -14
- package/dist/pages/runtime/index.d.ts +3 -10
- package/dist/pages/runtime/index.mjs +1 -5
- package/dist/pages/runtime/plugin.mjs +71 -0
- package/dist/vite-client/runtime/injectManifest.d.ts +26 -0
- package/dist/vite-client/runtime/injectManifest.mjs +104 -0
- package/dist/vite-client/runtime/plugin.d.ts +2 -0
- package/dist/vite-client/runtime/plugin.mjs +26 -0
- package/package.json +36 -40
- package/dist/app/entry.async.d.ts +0 -3
- package/dist/app/entry.async.mjs +0 -1
- package/dist/chunks/dev-bundler.mjs +0 -277
- 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 -41
- package/dist/pages/runtime/pages.mjs +0 -134
- /package/dist/pages/runtime/{pages.d.ts → plugin.d.ts} +0 -0
package/dist/app/entry.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RuntimeConfig } from '@monkeyplus/flow-schema';
|
|
2
|
-
|
|
3
|
-
export default
|
|
2
|
+
declare const _default: (runtimeConfig: RuntimeConfig) => Promise<import("./flow").FlowApp>;
|
|
3
|
+
export default _default;
|
package/dist/app/entry.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { config, configure, render } from "eta";
|
|
2
2
|
import { applyPlugins, createFlowApp } from "./flow.mjs";
|
|
3
3
|
import plugins from "#build/plugins";
|
|
4
|
-
export
|
|
4
|
+
export default async (runtimeConfig) => {
|
|
5
5
|
const flow = createFlowApp({ runtimeConfig });
|
|
6
6
|
try {
|
|
7
7
|
await applyPlugins(flow, plugins);
|
|
@@ -17,8 +17,7 @@ export const entry = async (runtimeConfig) => {
|
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
} catch (err) {
|
|
20
|
-
console.
|
|
20
|
+
console.log(err);
|
|
21
21
|
}
|
|
22
22
|
return flow;
|
|
23
23
|
};
|
|
24
|
-
export default entry;
|
package/dist/app/flow.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RadixRouter } from 'radix3';
|
|
2
2
|
import type { Hookable } from 'hookable';
|
|
3
|
-
import type {
|
|
4
|
-
type HookResult = Promise<void> | void;
|
|
3
|
+
import type { FlowPage, RuntimeConfig } from '@monkeyplus/flow-schema';
|
|
4
|
+
declare type HookResult = Promise<void> | void;
|
|
5
5
|
export interface FlowAppHooks {
|
|
6
6
|
'flow:pages': (page: FlowPage[]) => HookResult;
|
|
7
7
|
'eta:plugin': (options: any) => HookResult;
|
|
@@ -11,11 +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
|
-
ctx: any;
|
|
18
|
-
}, utils: any, data: Record<string, any>) => HookResult;
|
|
19
14
|
'page:chunks': (bundle: string, scripts: {
|
|
20
15
|
head: string[];
|
|
21
16
|
body: string[];
|
|
@@ -32,20 +27,16 @@ export interface FlowApp {
|
|
|
32
27
|
callHook: FlowApp['hooks']['callHook'];
|
|
33
28
|
eta: any;
|
|
34
29
|
app: {
|
|
35
|
-
utils:
|
|
30
|
+
utils: Record<string, any>;
|
|
36
31
|
plugins: Record<string, any>;
|
|
37
32
|
globals: Record<string, any>;
|
|
38
33
|
};
|
|
39
34
|
engine: string;
|
|
40
|
-
site: {
|
|
41
|
-
origin: string;
|
|
42
|
-
};
|
|
43
35
|
engines: Record<string, (template: string) => string>;
|
|
44
36
|
generate: boolean;
|
|
45
37
|
render: (view: Record<string, string>, data: any) => Promise<string> | void | string;
|
|
46
38
|
provide: (name: string, value: any) => void;
|
|
47
39
|
setUtil: (name: string, value: any) => void;
|
|
48
|
-
$config: RuntimeConfig;
|
|
49
40
|
[key: string]: any;
|
|
50
41
|
}
|
|
51
42
|
export declare const FlowPluginIndicator = "__flow_plugin";
|
package/dist/app/flow.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import 'node-fetch-native/polyfill';
|
|
2
|
-
|
|
3
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
|
|
2
|
+
declare const _default: import("h3").EventHandler<void>;
|
|
4
3
|
export default _default;
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import "node-fetch-native/polyfill";
|
|
2
|
-
import {
|
|
2
|
+
import { defineEventHandler } from "h3";
|
|
3
3
|
import { defineCachedFunction, useRuntimeConfig } from "#internal/nitro";
|
|
4
|
-
const getServerApp = () => import("#server")
|
|
5
|
-
|
|
4
|
+
const getServerApp = cachedImport(() => import("#server"));
|
|
5
|
+
const getFlowRenderer = cachedResult(async () => {
|
|
6
6
|
const createFlowApp = await getServerApp();
|
|
7
7
|
if (!createFlowApp)
|
|
8
8
|
throw new Error("Server bundle is not available");
|
|
9
9
|
return createFlowApp(useRuntimeConfig());
|
|
10
10
|
});
|
|
11
|
-
export default
|
|
11
|
+
export default defineEventHandler(async ({ context }) => {
|
|
12
12
|
const flow = await getFlowRenderer();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
context.flow = flow;
|
|
14
|
+
context.render = flow.render;
|
|
15
|
+
context.defineCachedFunction = defineCachedFunction;
|
|
16
16
|
});
|
|
17
|
-
function
|
|
17
|
+
function _interopDefault(e) {
|
|
18
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
19
|
+
}
|
|
20
|
+
function cachedImport(importer) {
|
|
21
|
+
return cachedResult(() => importer().then(_interopDefault).then(_interopDefault));
|
|
22
|
+
}
|
|
23
|
+
function cachedResult(fn) {
|
|
18
24
|
let res = null;
|
|
19
25
|
return () => {
|
|
20
26
|
if (res === null)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<
|
|
1
|
+
declare const _default: import("h3").EventHandler<any>;
|
|
2
2
|
export default _default;
|
|
@@ -1,100 +1,46 @@
|
|
|
1
|
-
import { eventHandler,
|
|
2
|
-
import { joinURL } from "ufo";
|
|
3
|
-
import { getFlowRenderer } from "./flow.mjs";
|
|
4
|
-
const normalizeCall = async (seo, ctx) => {
|
|
5
|
-
if (typeof seo === "function")
|
|
6
|
-
return await seo(ctx);
|
|
7
|
-
return seo || {};
|
|
8
|
-
};
|
|
9
|
-
function replacePath(_path, url) {
|
|
10
|
-
if (typeof url === "string") {
|
|
11
|
-
_path = joinURL(_path.replace("/**", ""), url);
|
|
12
|
-
} else {
|
|
13
|
-
Object.entries(url).forEach(([key, value]) => {
|
|
14
|
-
_path = _path.replace(`:${key}`, value);
|
|
15
|
-
});
|
|
16
|
-
if (url._ && _path.endsWith("**"))
|
|
17
|
-
_path = joinURL(_path.replace("/**", ""), url._);
|
|
18
|
-
}
|
|
19
|
-
return _path;
|
|
20
|
-
}
|
|
1
|
+
import { eventHandler, useQuery } from "h3";
|
|
21
2
|
export default eventHandler(async (event) => {
|
|
22
3
|
const url = event.req.url?.split("?")[0];
|
|
23
|
-
const flow =
|
|
4
|
+
const flow = event.context.flow;
|
|
24
5
|
if (url.includes("_urls")) {
|
|
25
|
-
const urls = await flow.app.utils.getUrls(
|
|
6
|
+
const urls = await flow.app.utils.getUrls();
|
|
26
7
|
return urls;
|
|
27
8
|
}
|
|
28
9
|
const scripts = { head: [], bodyStart: [], bodyEnd: [] };
|
|
29
10
|
const chunks = { head: [], body: [] };
|
|
30
11
|
const generate = {};
|
|
31
|
-
const { page, locale, params, view
|
|
12
|
+
const { page, locale, params, view } = flow.router.byUrl.lookup(url) || {};
|
|
32
13
|
if (!page)
|
|
33
14
|
return;
|
|
15
|
+
await flow.callHook("page:scripts", scripts);
|
|
34
16
|
if (view.bundle)
|
|
35
17
|
await flow.callHook("page:chunks", view.bundle, chunks);
|
|
36
18
|
const templateContext = {};
|
|
37
|
-
const
|
|
38
|
-
const contextPage = {
|
|
39
|
-
chunks,
|
|
40
|
-
locale,
|
|
41
|
-
_post: {}
|
|
42
|
-
};
|
|
19
|
+
const dynamic = params?._;
|
|
20
|
+
const contextPage = {};
|
|
43
21
|
const contextInject = {};
|
|
44
22
|
const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value, defineCachedFunction: event.context.defineCachedFunction }, flow.app.utils);
|
|
45
|
-
const contextHooks = {};
|
|
46
|
-
if (event.node.req.method.toLowerCase() === "post") {
|
|
47
|
-
const body = await readBody(event);
|
|
48
|
-
contextPage._post = body;
|
|
49
|
-
}
|
|
50
23
|
templateContext.url = url;
|
|
51
|
-
templateContext.baseURL = flow.$config.app.baseURL;
|
|
52
|
-
const pageObject = {
|
|
53
|
-
name: pageName,
|
|
54
|
-
pathname: url,
|
|
55
|
-
url: joinURL(flow.site.origin, templateContext.baseURL, `${url}`),
|
|
56
|
-
origin: flow.site.origin,
|
|
57
|
-
joinOrigin: (_url, includeBase) => joinURL(flow.site.origin, includeBase ? templateContext.baseURL : "/", _url)
|
|
58
|
-
};
|
|
59
|
-
templateContext.page = pageObject;
|
|
60
|
-
contextPage.page = pageObject;
|
|
61
24
|
templateContext.locale = locale;
|
|
62
25
|
templateContext.view = view;
|
|
63
|
-
if (
|
|
26
|
+
if (dynamic && page.dynamic) {
|
|
64
27
|
const pages = await page.dynamic.method({ locale, utils });
|
|
65
|
-
const dynamicPage = pages.find((_page) =>
|
|
66
|
-
const aUrl = replacePath(pagePath, _page.url);
|
|
67
|
-
const bUrl = replacePath(pagePath, params);
|
|
68
|
-
return aUrl === bUrl;
|
|
69
|
-
});
|
|
28
|
+
const dynamicPage = pages.find((_page) => _page.url === dynamic);
|
|
70
29
|
if (!dynamicPage)
|
|
71
30
|
return;
|
|
72
31
|
if (page.dynamic.assign)
|
|
73
32
|
templateContext[page.dynamic.assign] = dynamicPage.context;
|
|
74
33
|
contextPage.dynamic = dynamicPage;
|
|
75
34
|
}
|
|
76
|
-
await flow.callHook("page:context", { localeCode: locale.code, page: pageName, ctx: contextPage }, utils, contextHooks);
|
|
77
35
|
templateContext.seo = {};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
...contextPage,
|
|
81
|
-
utils
|
|
82
|
-
});
|
|
83
|
-
templateContext.sharedContext = sharedContext || {};
|
|
36
|
+
templateContext.context = {};
|
|
37
|
+
templateContext.sharedContext = {};
|
|
84
38
|
templateContext.utils = utils;
|
|
85
|
-
templateContext.seo = await
|
|
86
|
-
|
|
87
|
-
templateContext.context = {
|
|
88
|
-
...contextHooks,
|
|
89
|
-
...contexData
|
|
90
|
-
};
|
|
91
|
-
await flow.callHook("page:scripts", scripts, templateContext);
|
|
39
|
+
templateContext.seo = await page.seo?.({ ...contextPage, utils }) || {};
|
|
40
|
+
templateContext.context = await page.context?.({ ...contextPage, utils }) || {};
|
|
92
41
|
templateContext.getHeadScripts = () => {
|
|
93
42
|
return scripts.head.join("\n");
|
|
94
43
|
};
|
|
95
|
-
templateContext.getBodyEndScripts = () => {
|
|
96
|
-
return scripts.bodyEnd.join("\n");
|
|
97
|
-
};
|
|
98
44
|
templateContext.getHeadChunks = () => {
|
|
99
45
|
return chunks.head.join("\n");
|
|
100
46
|
};
|
|
@@ -104,7 +50,7 @@ export default eventHandler(async (event) => {
|
|
|
104
50
|
templateContext.getInjectContext = () => {
|
|
105
51
|
return `<script id="__FLOW_DATA__" type="application/json">${JSON.stringify(contextInject)}<\/script>`;
|
|
106
52
|
};
|
|
107
|
-
const query =
|
|
53
|
+
const query = useQuery(event);
|
|
108
54
|
if (query?.context)
|
|
109
55
|
return { ...templateContext, utils: Object.keys(utils) };
|
|
110
56
|
let html;
|