@next-core/runtime 1.21.0 → 1.21.2
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/cjs/createRoot.js +4 -6
- package/dist/cjs/createRoot.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js +1 -1
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/Renderer.js +159 -59
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/RendererContext.js +87 -11
- package/dist/cjs/internal/RendererContext.js.map +1 -1
- package/dist/cjs/internal/Router.js +109 -77
- package/dist/cjs/internal/Router.js.map +1 -1
- package/dist/cjs/internal/data/DataStore.js +53 -7
- package/dist/cjs/internal/data/DataStore.js.map +1 -1
- package/dist/cjs/internal/matchRoutes.js +9 -5
- package/dist/cjs/internal/matchRoutes.js.map +1 -1
- package/dist/cjs/internal/matchStoryboard.js +8 -3
- package/dist/cjs/internal/matchStoryboard.js.map +1 -1
- package/dist/cjs/internal/secret_internals.js +11 -18
- package/dist/cjs/internal/secret_internals.js.map +1 -1
- package/dist/esm/createRoot.js +5 -7
- package/dist/esm/createRoot.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js +1 -1
- package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/esm/internal/Renderer.js +167 -69
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/RendererContext.js +94 -11
- package/dist/esm/internal/RendererContext.js.map +1 -1
- package/dist/esm/internal/Router.js +148 -103
- package/dist/esm/internal/Router.js.map +1 -1
- package/dist/esm/internal/data/DataStore.js +51 -6
- package/dist/esm/internal/data/DataStore.js.map +1 -1
- package/dist/esm/internal/matchRoutes.js +8 -5
- package/dist/esm/internal/matchRoutes.js.map +1 -1
- package/dist/esm/internal/matchStoryboard.js +7 -3
- package/dist/esm/internal/matchStoryboard.js.map +1 -1
- package/dist/esm/internal/secret_internals.js +13 -20
- package/dist/esm/internal/secret_internals.js.map +1 -1
- package/dist/types/internal/Renderer.d.ts +12 -4
- package/dist/types/internal/RendererContext.d.ts +31 -5
- package/dist/types/internal/data/DataStore.d.ts +13 -4
- package/dist/types/internal/matchRoutes.d.ts +6 -0
- package/dist/types/internal/matchStoryboard.d.ts +1 -0
- package/package.json +3 -3
package/dist/cjs/createRoot.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.unstable_createRoot = unstable_createRoot;
|
|
7
|
-
var _loader = require("@next-core/loader");
|
|
8
7
|
var _Renderer = require("./internal/Renderer.js");
|
|
9
8
|
var _RendererContext = require("./internal/RendererContext.js");
|
|
10
9
|
var _DataStore = require("./internal/data/DataStore.js");
|
|
@@ -96,10 +95,9 @@ function unstable_createRoot(container, {
|
|
|
96
95
|
let output;
|
|
97
96
|
let stores = [];
|
|
98
97
|
try {
|
|
99
|
-
output = await (0, _Renderer.renderBricks)(renderRoot, bricks, runtimeContext, rendererContext);
|
|
100
|
-
(0,
|
|
101
|
-
|
|
102
|
-
await Promise.all([...output.blockingList, ...stores.map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
|
|
98
|
+
output = await (0, _Renderer.renderBricks)(renderRoot, bricks, runtimeContext, rendererContext, []);
|
|
99
|
+
stores = (0, _Renderer.getDataStores)(runtimeContext);
|
|
100
|
+
await (0, _Renderer.postAsyncRender)(output, runtimeContext, stores);
|
|
103
101
|
} catch (error) {
|
|
104
102
|
failed = true;
|
|
105
103
|
output = {
|
|
@@ -136,7 +134,7 @@ function unstable_createRoot(container, {
|
|
|
136
134
|
}
|
|
137
135
|
if (!failed) {
|
|
138
136
|
for (const store of stores) {
|
|
139
|
-
store.
|
|
137
|
+
store.mountAsyncData();
|
|
140
138
|
}
|
|
141
139
|
if (scope === "page") {
|
|
142
140
|
rendererContext.dispatchPageLoad();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoot.js","names":["_loader","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","previousRendererContext","RendererContext","runtimeContext","ctxStore","DataStore","undefined","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","setTheme","setMode","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","stores","renderBricks","flushStableLoadBricks","values","Promise","all","blockingList","map","store","waitForAll","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","handleAsyncAfterMount","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement | DocumentFragment,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\", undefined, rendererContext),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n let stores: DataStore<\"CTX\" | \"STATE\" | \"FORM_STATE\">[] = [];\n\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n stores = [\n runtimeContext.ctxStore,\n ...runtimeContext.tplStateStoreMap.values(),\n ...runtimeContext.formStateStoreMap.values(),\n ];\n\n await Promise.all([\n ...output.blockingList,\n ...stores.map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n for (const store of stores) {\n store.handleAsyncAfterMount();\n }\n\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,oBAAA,GAAAR,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AACA,IAAAU,wBAAA,GAAAV,OAAA;AA2BO,SAASW,mBAAmBA,CACjCC,SAAyC,EACzC;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC,MAAM;IACL;IACAG,YAAY,GAAGA,CAAA,KAAM;MACnBJ,MAAM,GAAGK,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MACtCN,MAAM,CAACO,KAAK,CAACC,QAAQ,GAAG,UAAU;MAClCR,MAAM,CAACO,KAAK,CAACE,KAAK,GAAGT,MAAM,CAACO,KAAK,CAACG,MAAM,GAAG,GAAG;MAC9CL,QAAQ,CAACM,IAAI,CAACC,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AA,EAAG;MACR,IAAI/E,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAAkE,kBAAW,EAAChF,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAA+E,kBAAW,EAAC/E,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC6F,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"createRoot.js","names":["_Renderer","require","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","previousRendererContext","RendererContext","runtimeContext","ctxStore","DataStore","undefined","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","setTheme","setMode","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","stores","renderBricks","getDataStores","postAsyncRender","error","node","BRICK","type","properties","textContent","httpErrorToString","return","blockingList","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","store","mountAsyncData","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport {\n RenderOutput,\n getDataStores,\n postAsyncRender,\n renderBricks,\n} from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement | DocumentFragment,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\", undefined, rendererContext),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n let stores: DataStore<\"CTX\" | \"STATE\" | \"FORM_STATE\">[] = [];\n\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext,\n []\n );\n\n stores = getDataStores(runtimeContext);\n await postAsyncRender(output, runtimeContext, stores);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n for (const store of stores) {\n store.mountAsyncData();\n }\n\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,SAAA,GAAAC,OAAA;AAMA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAP,OAAA;AACA,IAAAQ,gBAAA,GAAAR,OAAA;AACA,IAAAS,wBAAA,GAAAT,OAAA;AA2BO,SAASU,mBAAmBA,CACjCC,SAAyC,EACzC;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC,MAAM;IACL;IACAG,YAAY,GAAGA,CAAA,KAAM;MACnBJ,MAAM,GAAGK,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MACtCN,MAAM,CAACO,KAAK,CAACC,QAAQ,GAAG,UAAU;MAClCR,MAAM,CAACO,KAAK,CAACE,KAAK,GAAGT,MAAM,CAACO,KAAK,CAACG,MAA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AAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
|
|
@@ -54,7 +54,7 @@ function unbindTemplateProxy(brick) {
|
|
|
54
54
|
runtimeContext,
|
|
55
55
|
element
|
|
56
56
|
} = brick;
|
|
57
|
-
if (!runtimeContext.tplStateStoreId || !ref) {
|
|
57
|
+
if (!(runtimeContext !== null && runtimeContext !== void 0 && runtimeContext.tplStateStoreId) || !ref) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindTemplateProxy.js","names":["_utils","require","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","getTplStateStore","tplHostMetadata","internalBricksByRef","set","events","proxy","from","to","Object","entries","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","unbindTemplateProxy","delete","type","fn","_$$proxyListeners","removeEventListener"],"sources":["../../../../src/internal/CustomTemplates/bindTemplateProxy.ts"],"sourcesContent":["import type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"./utils.js\";\n\nexport function bindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n // Error recovering brick may have no runtimeContext.\n if (!ref || !runtimeContext.tplStateStoreId) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"bindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.set(ref, brick);\n\n const events = tplHostMetadata.proxy?.events;\n if (events) {\n for (const [from, to] of Object.entries(events)) {\n if (to.ref === ref) {\n const listener = (e: Event) => {\n if (e.bubbles) {\n e.stopPropagation();\n }\n hostBrick!.element!.dispatchEvent(\n new CustomEvent(from, {\n detail: (e as CustomEvent).detail,\n bubbles: e.bubbles,\n cancelable: e.cancelable,\n composed: e.composed,\n })\n );\n };\n const eventType = to.refEvent ?? from;\n element!.addEventListener(eventType, listener);\n element!.$$proxyListeners ??= [];\n element!.$$proxyListeners.push([eventType, listener]);\n }\n }\n }\n}\n\nexport function unbindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n if (!runtimeContext
|
|
1
|
+
{"version":3,"file":"bindTemplateProxy.js","names":["_utils","require","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","getTplStateStore","tplHostMetadata","internalBricksByRef","set","events","proxy","from","to","Object","entries","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","unbindTemplateProxy","delete","type","fn","_$$proxyListeners","removeEventListener"],"sources":["../../../../src/internal/CustomTemplates/bindTemplateProxy.ts"],"sourcesContent":["import type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"./utils.js\";\n\nexport function bindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n // Error recovering brick may have no runtimeContext.\n if (!ref || !runtimeContext.tplStateStoreId) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"bindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.set(ref, brick);\n\n const events = tplHostMetadata.proxy?.events;\n if (events) {\n for (const [from, to] of Object.entries(events)) {\n if (to.ref === ref) {\n const listener = (e: Event) => {\n if (e.bubbles) {\n e.stopPropagation();\n }\n hostBrick!.element!.dispatchEvent(\n new CustomEvent(from, {\n detail: (e as CustomEvent).detail,\n bubbles: e.bubbles,\n cancelable: e.cancelable,\n composed: e.composed,\n })\n );\n };\n const eventType = to.refEvent ?? from;\n element!.addEventListener(eventType, listener);\n element!.$$proxyListeners ??= [];\n element!.$$proxyListeners.push([eventType, listener]);\n }\n }\n }\n}\n\nexport function unbindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n if (!runtimeContext?.tplStateStoreId || !ref) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"unbindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.delete(ref);\n\n for (const [type, fn] of element!.$$proxyListeners ?? []) {\n element!.removeEventListener(type, fn);\n }\n delete element!.$$proxyListeners;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,MAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,uBAAgB,EAACJ,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,MAAMK,eAAe,GAAGF,SAAS,CAAEE,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAACC,GAAG,CAACR,GAAG,EAAEF,KAAK,CAAC;EAEnD,MAAMW,MAAM,IAAAV,qBAAA,GAAGO,eAAe,CAACI,KAAK,cAAAX,qBAAA,uBAArBA,qBAAA,CAAuBU,MAAM;EAC5C,IAAIA,MAAM,EAAE;IACV,KAAK,MAAM,CAACE,IAAI,EAAEC,EAAE,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;MAC/C,IAAIG,EAAE,CAACZ,GAAG,KAAKA,GAAG,EAAE;QAAA,IAAAe,YAAA,EAAAC,IAAA,EAAAC,qBAAA;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ACkC,IAAI,EAAEC,EAAE,CAAC,KAAAC,iBAAA,GAAIlC,OAAO,CAAE4B,gBAAgB,cAAAM,iBAAA,cAAAA,iBAAA,GAAI,EAAE,EAAE;IAAA,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE4B,gBAAgB;AAClC"}
|
|
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.childrenToSlots = childrenToSlots;
|
|
7
|
+
exports.createScopedRuntimeContext = createScopedRuntimeContext;
|
|
8
|
+
exports.getDataStores = getDataStores;
|
|
9
|
+
exports.postAsyncRender = postAsyncRender;
|
|
7
10
|
exports.renderBrick = renderBrick;
|
|
8
11
|
exports.renderBricks = renderBricks;
|
|
9
12
|
exports.renderRoutes = renderRoutes;
|
|
10
13
|
var _loader = require("@next-core/loader");
|
|
11
14
|
var _cook = require("@next-core/cook");
|
|
12
15
|
var _general = require("@next-core/utils/general");
|
|
16
|
+
var _storyboard = require("@next-core/utils/storyboard");
|
|
13
17
|
var _lodash = require("lodash");
|
|
14
18
|
var _checkIf = require("./compute/checkIf.js");
|
|
15
19
|
var _computeRealProperties = require("./compute/computeRealProperties.js");
|
|
@@ -28,8 +32,8 @@ var _isStrictMode = require("../isStrictMode.js");
|
|
|
28
32
|
var _constants2 = require("./FormRenderer/constants.js");
|
|
29
33
|
var _expandFormRenderer = require("./FormRenderer/expandFormRenderer.js");
|
|
30
34
|
var _evaluate = require("./compute/evaluate.js");
|
|
31
|
-
var
|
|
32
|
-
async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext, slotId) {
|
|
35
|
+
var _matchStoryboard = require("./matchStoryboard.js");
|
|
36
|
+
async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext, parentRoutes, slotId, isIncremental) {
|
|
33
37
|
const matched = await (0, _matchRoutes.matchRoutes)(routes, _runtimeContext);
|
|
34
38
|
const output = {
|
|
35
39
|
blockingList: [],
|
|
@@ -49,7 +53,11 @@ async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext
|
|
|
49
53
|
..._runtimeContext,
|
|
50
54
|
match: matched.match
|
|
51
55
|
};
|
|
52
|
-
|
|
56
|
+
if (isIncremental) {
|
|
57
|
+
runtimeContext.ctxStore.disposeDataInRoutes(routes);
|
|
58
|
+
}
|
|
59
|
+
const routePath = parentRoutes.concat(route);
|
|
60
|
+
runtimeContext.ctxStore.define(route.context, runtimeContext, undefined, routePath);
|
|
53
61
|
runtimeContext.pendingPermissionsPreCheck.push(_Runtime.hooks === null || _Runtime.hooks === void 0 || (_hooks$checkPermissio = _Runtime.hooks.checkPermissions) === null || _hooks$checkPermissio === void 0 ? void 0 : _hooks$checkPermissio.preCheckPermissionsForBrickOrRoute(route, value => (0, _computeRealValue.asyncComputeRealValue)(value, runtimeContext)));
|
|
54
62
|
|
|
55
63
|
// Currently, this is only used for brick size-checking: these bricks
|
|
@@ -60,65 +68,63 @@ async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext
|
|
|
60
68
|
if (Array.isArray(preLoadBricks)) {
|
|
61
69
|
output.blockingList.push((0, _loader.loadBricksImperatively)(preLoadBricks, (0, _Runtime.getBrickPackages)()));
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
mergeRenderOutput(output, newOutput);
|
|
98
|
-
}
|
|
71
|
+
if (route.type === "redirect") {
|
|
72
|
+
let redirectTo;
|
|
73
|
+
if (typeof route.redirect === "string") {
|
|
74
|
+
redirectTo = await (0, _computeRealValue.asyncComputeRealValue)(route.redirect, runtimeContext);
|
|
75
|
+
} else {
|
|
76
|
+
const resolved = await (0, _resolveData.resolveData)({
|
|
77
|
+
transform: "redirect",
|
|
78
|
+
...route.redirect
|
|
79
|
+
}, runtimeContext);
|
|
80
|
+
redirectTo = resolved.redirect;
|
|
81
|
+
}
|
|
82
|
+
if (typeof redirectTo !== "string") {
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
console.error("Unexpected redirect result:", redirectTo);
|
|
85
|
+
throw new Error(`Unexpected type of redirect result: ${typeof redirectTo}`);
|
|
86
|
+
}
|
|
87
|
+
output.redirect = {
|
|
88
|
+
path: redirectTo
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
const menuRequest = loadMenu(route.menu, runtimeContext);
|
|
92
|
+
if (menuRequest) {
|
|
93
|
+
output.menuRequests.push(menuRequest);
|
|
94
|
+
}
|
|
95
|
+
if (route.type === "routes") {
|
|
96
|
+
const newOutput = await renderRoutes(returnNode, route.routes, runtimeContext, rendererContext, routePath, slotId);
|
|
97
|
+
mergeRenderOutput(output, newOutput);
|
|
98
|
+
} else {
|
|
99
|
+
const newOutput = await renderBricks(returnNode, route.bricks, runtimeContext, rendererContext, routePath, slotId);
|
|
100
|
+
mergeRenderOutput(output, newOutput);
|
|
101
|
+
}
|
|
102
|
+
if (returnNode.tag === _enums.RenderTag.BRICK) {
|
|
103
|
+
rendererContext.memoizeMenuRequests(route, output.menuRequests);
|
|
104
|
+
}
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
return output;
|
|
103
109
|
}
|
|
104
|
-
async function renderBricks(returnNode, bricks, runtimeContext, rendererContext, slotId, tplStack, keyPath) {
|
|
110
|
+
async function renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
|
|
105
111
|
const output = {
|
|
106
112
|
blockingList: [],
|
|
107
113
|
menuRequests: []
|
|
108
114
|
};
|
|
109
115
|
const kPath = keyPath !== null && keyPath !== void 0 ? keyPath : [];
|
|
110
116
|
// 多个构件并行异步转换,但转换的结果按原顺序串行合并。
|
|
111
|
-
const rendered = await Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, slotId, kPath.concat(index), tplStack && new Map(tplStack))));
|
|
117
|
+
const rendered = await Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, parentRoutes, slotId, kPath.concat(index), tplStack && new Map(tplStack))));
|
|
112
118
|
rendered.forEach((item, index) => {
|
|
113
119
|
if (item.hasTrackingControls) {
|
|
114
120
|
// Memoize a render node before it's been merged.
|
|
115
|
-
rendererContext.
|
|
121
|
+
rendererContext.memoize(slotId, kPath.concat(index), item.node, returnNode);
|
|
116
122
|
}
|
|
117
123
|
mergeRenderOutput(output, item);
|
|
118
124
|
});
|
|
119
125
|
return output;
|
|
120
126
|
}
|
|
121
|
-
async function renderBrick(returnNode, brickConf, _runtimeContext, rendererContext, slotId, keyPath = [], tplStack = new Map()) {
|
|
127
|
+
async function renderBrick(returnNode, brickConf, _runtimeContext, rendererContext, parentRoutes, slotId, keyPath = [], tplStack = new Map()) {
|
|
122
128
|
var _hooks$checkPermissio2, _runtimeContext$app;
|
|
123
129
|
const output = {
|
|
124
130
|
blockingList: [],
|
|
@@ -159,7 +165,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
|
|
|
159
165
|
...acc,
|
|
160
166
|
[symbol]: brickConf[symbol]
|
|
161
167
|
}), {})
|
|
162
|
-
}, _runtimeContext, rendererContext, slotId, keyPath, tplStack);
|
|
168
|
+
}, _runtimeContext, rendererContext, parentRoutes, slotId, keyPath, tplStack);
|
|
163
169
|
}
|
|
164
170
|
const tplStateStoreId = brickConf[_constants.symbolForTplStateStoreId];
|
|
165
171
|
const formStateStoreId = brickConf[_constants2.symbolForFormStateStoreId];
|
|
@@ -194,7 +200,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
|
|
|
194
200
|
const {
|
|
195
201
|
dataSource
|
|
196
202
|
} = brickConf;
|
|
197
|
-
const renderControlNode = async
|
|
203
|
+
const renderControlNode = async runtimeContext => {
|
|
198
204
|
var _slots$slot;
|
|
199
205
|
// First, compute the `dataSource`
|
|
200
206
|
const computedDataSource = await (0, _computeRealValue.asyncComputeRealValue)(dataSource, runtimeContext);
|
|
@@ -216,16 +222,16 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
|
|
|
216
222
|
if (!Array.isArray(computedDataSource)) {
|
|
217
223
|
return output;
|
|
218
224
|
}
|
|
219
|
-
return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, slotId, tplStack, keyPath);
|
|
225
|
+
return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
|
|
220
226
|
}
|
|
221
227
|
case ":if":
|
|
222
228
|
case ":switch":
|
|
223
229
|
{
|
|
224
|
-
return renderBricks(returnNode, bricks, runtimeContext, rendererContext, slotId, tplStack, keyPath);
|
|
230
|
+
return renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
};
|
|
228
|
-
const controlledOutput = await renderControlNode();
|
|
234
|
+
const controlledOutput = await renderControlNode(runtimeContext);
|
|
229
235
|
const {
|
|
230
236
|
contextNames,
|
|
231
237
|
stateNames
|
|
@@ -235,12 +241,17 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
|
|
|
235
241
|
let renderId = 0;
|
|
236
242
|
const listener = async () => {
|
|
237
243
|
const currentRenderId = ++renderId;
|
|
238
|
-
const
|
|
239
|
-
controlOutput
|
|
240
|
-
|
|
244
|
+
const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(runtimeContext);
|
|
245
|
+
const controlOutput = await renderControlNode(scopedRuntimeContext);
|
|
246
|
+
const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
|
|
247
|
+
await postAsyncRender(controlOutput, scopedRuntimeContext, scopedStores);
|
|
248
|
+
|
|
241
249
|
// Ignore stale renders
|
|
242
250
|
if (renderId === currentRenderId) {
|
|
243
|
-
rendererContext.
|
|
251
|
+
rendererContext.reRender(slotId, keyPath, controlOutput.node, returnNode);
|
|
252
|
+
for (const store of scopedStores) {
|
|
253
|
+
store.mountAsyncData();
|
|
254
|
+
}
|
|
244
255
|
}
|
|
245
256
|
};
|
|
246
257
|
const debouncedListener = (0, _lodash.debounce)(listener);
|
|
@@ -373,15 +384,87 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
|
|
|
373
384
|
if (!slots) {
|
|
374
385
|
return;
|
|
375
386
|
}
|
|
376
|
-
const
|
|
387
|
+
const routeSlotIndexes = new Set();
|
|
388
|
+
const rendered = await Promise.all(Object.entries(slots).map(([childSlotId, slotConf], index) => {
|
|
389
|
+
if (slotConf.type !== "routes") {
|
|
390
|
+
return renderBricks(brick, slotConf.bricks, childRuntimeContext, rendererContext, parentRoutes, childSlotId, tplStack);
|
|
391
|
+
}
|
|
392
|
+
if (runtimeContext.flags["incremental-sub-route-rendering"]) {
|
|
393
|
+
routeSlotIndexes.add(index);
|
|
394
|
+
rendererContext.performIncrementalRender(async location => {
|
|
395
|
+
const {
|
|
396
|
+
homepage
|
|
397
|
+
} = childRuntimeContext.app;
|
|
398
|
+
const {
|
|
399
|
+
pathname
|
|
400
|
+
} = location;
|
|
401
|
+
// Ignore if any one of homepage and parent routes not matched.
|
|
402
|
+
if (!(0, _matchStoryboard.matchHomepage)(homepage, pathname) || !parentRoutes.every(route => (0, _matchRoutes.matchRoute)(route, homepage, pathname))) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext({
|
|
406
|
+
...childRuntimeContext,
|
|
407
|
+
location,
|
|
408
|
+
query: new URLSearchParams(location.search)
|
|
409
|
+
});
|
|
410
|
+
let failed = false;
|
|
411
|
+
let incrementalOutput;
|
|
412
|
+
let scopedStores = [];
|
|
413
|
+
try {
|
|
414
|
+
incrementalOutput = await renderRoutes(brick, slotConf.routes, scopedRuntimeContext, rendererContext, parentRoutes, childSlotId, true);
|
|
415
|
+
|
|
416
|
+
// If all sub-routes are missed, ignore incremental rendering
|
|
417
|
+
if (!incrementalOutput.route) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Bailout if redirect or unauthenticated is set
|
|
422
|
+
if (rendererContext.reBailout(incrementalOutput)) {
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
|
|
426
|
+
await postAsyncRender(incrementalOutput, scopedRuntimeContext, [scopedRuntimeContext.ctxStore, ...scopedStores]);
|
|
427
|
+
await rendererContext.reMergeMenuRequests(slotConf.routes, incrementalOutput.route, incrementalOutput.menuRequests);
|
|
428
|
+
} catch (error) {
|
|
429
|
+
// eslint-disable-next-line no-console
|
|
430
|
+
console.error("Incremental sub-router failed:", error);
|
|
431
|
+
const result = rendererContext.reCatch(error, brick);
|
|
432
|
+
if (!result) {
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
({
|
|
436
|
+
failed,
|
|
437
|
+
output: incrementalOutput
|
|
438
|
+
} = result);
|
|
439
|
+
|
|
440
|
+
// Assert: no errors will be throw
|
|
441
|
+
await rendererContext.reMergeMenuRequests(slotConf.routes, incrementalOutput.route, incrementalOutput.menuRequests);
|
|
442
|
+
}
|
|
443
|
+
rendererContext.reRender(childSlotId, [], incrementalOutput.node, brick);
|
|
444
|
+
if (!failed) {
|
|
445
|
+
scopedRuntimeContext.ctxStore.mountAsyncData(incrementalOutput.route);
|
|
446
|
+
for (const store of scopedStores) {
|
|
447
|
+
store.mountAsyncData();
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return true;
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
return renderRoutes(brick, slotConf.routes, childRuntimeContext, rendererContext, parentRoutes, childSlotId);
|
|
454
|
+
}));
|
|
377
455
|
const childrenOutput = {
|
|
378
456
|
...output,
|
|
379
457
|
node: undefined,
|
|
380
|
-
blockingList: []
|
|
458
|
+
blockingList: [],
|
|
459
|
+
menuRequests: []
|
|
381
460
|
};
|
|
382
|
-
|
|
461
|
+
rendered.forEach((item, index) => {
|
|
462
|
+
if (routeSlotIndexes.has(index)) {
|
|
463
|
+
// Memoize a render node before it's been merged.
|
|
464
|
+
rendererContext.memoize(slotId, [], item.node, brick);
|
|
465
|
+
}
|
|
383
466
|
mergeRenderOutput(childrenOutput, item);
|
|
384
|
-
}
|
|
467
|
+
});
|
|
385
468
|
if (childrenOutput.node) {
|
|
386
469
|
brick.child = childrenOutput.node;
|
|
387
470
|
}
|
|
@@ -404,7 +487,7 @@ function ensureValidControlBrick(brick) {
|
|
|
404
487
|
throw new Error(`Unknown storyboard control node: "${brick}"`);
|
|
405
488
|
}
|
|
406
489
|
}
|
|
407
|
-
async function renderForEach(returnNode, dataSource, bricks, runtimeContext, rendererContext, slotId, tplStack, keyPath) {
|
|
490
|
+
async function renderForEach(returnNode, dataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
|
|
408
491
|
const output = {
|
|
409
492
|
blockingList: [],
|
|
410
493
|
menuRequests: []
|
|
@@ -413,18 +496,35 @@ async function renderForEach(returnNode, dataSource, bricks, runtimeContext, ren
|
|
|
413
496
|
const rendered = await Promise.all(dataSource.map((item, i) => Promise.all(bricks.map((brickConf, j) => renderBrick(returnNode, brickConf, {
|
|
414
497
|
...runtimeContext,
|
|
415
498
|
forEachItem: item
|
|
416
|
-
}, rendererContext, slotId, keyPath.concat(i * rows + j), tplStack && new Map(tplStack))))));
|
|
499
|
+
}, rendererContext, parentRoutes, slotId, keyPath.concat(i * rows + j), tplStack && new Map(tplStack))))));
|
|
417
500
|
|
|
418
501
|
// 多层构件并行异步转换,但转换的结果按原顺序串行合并。
|
|
419
502
|
rendered.flat().forEach((item, index) => {
|
|
420
503
|
if (item.hasTrackingControls) {
|
|
421
504
|
// Memoize a render node before it's been merged.
|
|
422
|
-
rendererContext.
|
|
505
|
+
rendererContext.memoize(slotId, keyPath.concat(index), item.node, returnNode);
|
|
423
506
|
}
|
|
424
507
|
mergeRenderOutput(output, item);
|
|
425
508
|
});
|
|
426
509
|
return output;
|
|
427
510
|
}
|
|
511
|
+
function getDataStores(runtimeContext) {
|
|
512
|
+
return [runtimeContext.ctxStore, ...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()];
|
|
513
|
+
}
|
|
514
|
+
function postAsyncRender(output, runtimeContext, stores) {
|
|
515
|
+
(0, _loader.flushStableLoadBricks)();
|
|
516
|
+
return Promise.all([...output.blockingList, ...stores.map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
|
|
517
|
+
}
|
|
518
|
+
function createScopedRuntimeContext(runtimeContext) {
|
|
519
|
+
const tplStateStoreScope = [];
|
|
520
|
+
const formStateStoreScope = [];
|
|
521
|
+
const scopedRuntimeContext = {
|
|
522
|
+
...runtimeContext,
|
|
523
|
+
tplStateStoreScope,
|
|
524
|
+
formStateStoreScope
|
|
525
|
+
};
|
|
526
|
+
return [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope];
|
|
527
|
+
}
|
|
428
528
|
function loadMenu(menuConf, runtimeContext) {
|
|
429
529
|
if (!menuConf) {
|
|
430
530
|
return;
|