@next-core/runtime 1.20.4 → 1.21.1

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.
Files changed (42) hide show
  1. package/dist/cjs/createRoot.js +4 -6
  2. package/dist/cjs/createRoot.js.map +1 -1
  3. package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js +1 -1
  4. package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
  5. package/dist/cjs/internal/Renderer.js +175 -69
  6. package/dist/cjs/internal/Renderer.js.map +1 -1
  7. package/dist/cjs/internal/RendererContext.js +89 -13
  8. package/dist/cjs/internal/RendererContext.js.map +1 -1
  9. package/dist/cjs/internal/Router.js +116 -77
  10. package/dist/cjs/internal/Router.js.map +1 -1
  11. package/dist/cjs/internal/data/DataStore.js +53 -7
  12. package/dist/cjs/internal/data/DataStore.js.map +1 -1
  13. package/dist/cjs/internal/matchRoutes.js +9 -5
  14. package/dist/cjs/internal/matchRoutes.js.map +1 -1
  15. package/dist/cjs/internal/matchStoryboard.js +8 -3
  16. package/dist/cjs/internal/matchStoryboard.js.map +1 -1
  17. package/dist/cjs/internal/secret_internals.js +11 -18
  18. package/dist/cjs/internal/secret_internals.js.map +1 -1
  19. package/dist/esm/createRoot.js +5 -7
  20. package/dist/esm/createRoot.js.map +1 -1
  21. package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js +1 -1
  22. package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
  23. package/dist/esm/internal/Renderer.js +183 -78
  24. package/dist/esm/internal/Renderer.js.map +1 -1
  25. package/dist/esm/internal/RendererContext.js +96 -13
  26. package/dist/esm/internal/RendererContext.js.map +1 -1
  27. package/dist/esm/internal/Router.js +155 -103
  28. package/dist/esm/internal/Router.js.map +1 -1
  29. package/dist/esm/internal/data/DataStore.js +51 -6
  30. package/dist/esm/internal/data/DataStore.js.map +1 -1
  31. package/dist/esm/internal/matchRoutes.js +8 -5
  32. package/dist/esm/internal/matchRoutes.js.map +1 -1
  33. package/dist/esm/internal/matchStoryboard.js +7 -3
  34. package/dist/esm/internal/matchStoryboard.js.map +1 -1
  35. package/dist/esm/internal/secret_internals.js +13 -20
  36. package/dist/esm/internal/secret_internals.js.map +1 -1
  37. package/dist/types/internal/Renderer.d.ts +12 -4
  38. package/dist/types/internal/RendererContext.d.ts +31 -5
  39. package/dist/types/internal/data/DataStore.d.ts +13 -4
  40. package/dist/types/internal/matchRoutes.d.ts +6 -0
  41. package/dist/types/internal/matchStoryboard.d.ts +1 -0
  42. package/package.json +2 -2
@@ -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, _loader.flushStableLoadBricks)();
101
- stores = [runtimeContext.ctxStore, ...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()];
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.handleAsyncAfterMount();
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,MAAM,CAACZ,MAAM,CAAC;MA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,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,MAAM,GAAG,GAAG;MAC9CL,QAAQ,CAACM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C;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.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;QAClB,MAAMC,QAAQ,GAAIC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AAO,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"}
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;QAClB,MAAMC,QAAQ,GAAIC,CAAQ,IAAK;UAC7B,I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lC,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 _storyboard = require("@next-core/utils/storyboard");
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
- runtimeContext.ctxStore.define(route.context, runtimeContext);
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,64 +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
- switch (route.type) {
64
- case "redirect":
65
- {
66
- let redirectTo;
67
- if (typeof route.redirect === "string") {
68
- redirectTo = await (0, _computeRealValue.asyncComputeRealValue)(route.redirect, runtimeContext);
69
- } else {
70
- const resolved = await (0, _resolveData.resolveData)({
71
- transform: "redirect",
72
- ...route.redirect
73
- }, runtimeContext);
74
- redirectTo = resolved.redirect;
75
- }
76
- if (typeof redirectTo !== "string") {
77
- // eslint-disable-next-line no-console
78
- console.error("Unexpected redirect result:", redirectTo);
79
- throw new Error(`Unexpected type of redirect result: ${typeof redirectTo}`);
80
- }
81
- output.redirect = {
82
- path: redirectTo
83
- };
84
- break;
85
- }
86
- case "routes":
87
- {
88
- output.menuRequests.push(loadMenu(route.menu, runtimeContext));
89
- const newOutput = await renderRoutes(returnNode, route.routes, runtimeContext, rendererContext, slotId);
90
- mergeRenderOutput(output, newOutput);
91
- break;
92
- }
93
- default:
94
- {
95
- output.menuRequests.push(loadMenu(route.menu, runtimeContext));
96
- const newOutput = await renderBricks(returnNode, route.bricks, runtimeContext, rendererContext, slotId);
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, noMemoize) {
110
+ async function renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
105
111
  const output = {
106
112
  blockingList: [],
107
113
  menuRequests: []
108
114
  };
115
+ const kPath = keyPath !== null && keyPath !== void 0 ? keyPath : [];
109
116
  // 多个构件并行异步转换,但转换的结果按原顺序串行合并。
110
- const rendered = await Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, slotId, 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))));
111
118
  rendered.forEach((item, index) => {
112
- if (!noMemoize && item.hasTrackingControls) {
119
+ if (item.hasTrackingControls) {
113
120
  // Memoize a render node before it's been merged.
114
- rendererContext.memoizeControlNode(slotId, index, item.node, returnNode);
121
+ rendererContext.memoize(slotId, kPath.concat(index), item.node, returnNode);
115
122
  }
116
123
  mergeRenderOutput(output, item);
117
124
  });
118
125
  return output;
119
126
  }
120
- async function renderBrick(returnNode, brickConf, _runtimeContext, rendererContext, slotId, key, tplStack = new Map()) {
127
+ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererContext, parentRoutes, slotId, keyPath = [], tplStack = new Map()) {
121
128
  var _hooks$checkPermissio2, _runtimeContext$app;
122
129
  const output = {
123
130
  blockingList: [],
@@ -158,7 +165,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
158
165
  ...acc,
159
166
  [symbol]: brickConf[symbol]
160
167
  }), {})
161
- }, _runtimeContext, rendererContext, slotId, key, tplStack);
168
+ }, _runtimeContext, rendererContext, parentRoutes, slotId, keyPath, tplStack);
162
169
  }
163
170
  const tplStateStoreId = brickConf[_constants.symbolForTplStateStoreId];
164
171
  const formStateStoreId = brickConf[_constants2.symbolForFormStateStoreId];
@@ -193,7 +200,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
193
200
  const {
194
201
  dataSource
195
202
  } = brickConf;
196
- const renderControlNode = async () => {
203
+ const renderControlNode = async runtimeContext => {
197
204
  var _slots$slot;
198
205
  // First, compute the `dataSource`
199
206
  const computedDataSource = await (0, _computeRealValue.asyncComputeRealValue)(dataSource, runtimeContext);
@@ -215,16 +222,16 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
215
222
  if (!Array.isArray(computedDataSource)) {
216
223
  return output;
217
224
  }
218
- return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, slotId, tplStack);
225
+ return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
219
226
  }
220
227
  case ":if":
221
228
  case ":switch":
222
229
  {
223
- return renderBricks(returnNode, bricks, runtimeContext, rendererContext, slotId, tplStack, true);
230
+ return renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
224
231
  }
225
232
  }
226
233
  };
227
- const controlledOutput = await renderControlNode();
234
+ const controlledOutput = await renderControlNode(runtimeContext);
228
235
  const {
229
236
  contextNames,
230
237
  stateNames
@@ -234,12 +241,17 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
234
241
  let renderId = 0;
235
242
  const listener = async () => {
236
243
  const currentRenderId = ++renderId;
237
- const controlOutput = await renderControlNode();
238
- controlOutput.blockingList.push(...[...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck);
239
- await Promise.all(controlOutput.blockingList);
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
+
240
249
  // Ignore stale renders
241
250
  if (renderId === currentRenderId) {
242
- rendererContext.rerenderControlNode(slotId, key, controlOutput.node, returnNode);
251
+ rendererContext.reRender(slotId, keyPath, controlOutput.node, returnNode);
252
+ for (const store of scopedStores) {
253
+ store.mountAsyncData();
254
+ }
243
255
  }
244
256
  };
245
257
  const debouncedListener = (0, _lodash.debounce)(listener);
@@ -260,7 +272,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
260
272
 
261
273
  // Widgets need to be defined before rendering.
262
274
  if (/\.tpl-/.test(brickName) && !_CustomTemplates.customTemplates.get(brickName)) {
263
- await catchLoadBrick((0, _loader.loadBricksImperatively)([brickName], (0, _Runtime.getBrickPackages)()), brickName, rendererContext.unknownBricks);
275
+ await catchLoad((0, _loader.loadBricksImperatively)([brickName], (0, _Runtime.getBrickPackages)()), "brick", brickName, rendererContext.unknownBricks);
264
276
  }
265
277
  const tplTagName = (0, _utils.getTagNameOfCustomTemplate)(brickName, (_runtimeContext$app = runtimeContext.app) === null || _runtimeContext$app === void 0 ? void 0 : _runtimeContext$app.id);
266
278
  if (tplTagName) {
@@ -278,7 +290,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
278
290
  }
279
291
  });
280
292
  } else {
281
- output.blockingList.push(catchLoadBrick((0, _loader.enqueueStableLoadBricks)([brickName], (0, _Runtime.getBrickPackages)()), brickName, rendererContext.unknownBricks));
293
+ output.blockingList.push(catchLoad((0, _loader.enqueueStableLoadBricks)([brickName], (0, _Runtime.getBrickPackages)()), "brick", brickName, rendererContext.unknownBricks));
282
294
  }
283
295
  }
284
296
  let formData;
@@ -309,13 +321,13 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
309
321
  src,
310
322
  ...attrs
311
323
  } = props;
312
- await (0, _loader.loadScript)(src, prefix, attrs);
324
+ await catchLoad((0, _loader.loadScript)(src, prefix, attrs), "script", src, "silent");
313
325
  } else {
314
326
  const {
315
327
  href,
316
328
  ...attrs
317
329
  } = props;
318
- await (0, _loader.loadStyle)(href, prefix, attrs);
330
+ await catchLoad((0, _loader.loadStyle)(href, prefix, attrs), "stylesheet", href, "silent");
319
331
  }
320
332
  return output;
321
333
  }
@@ -336,7 +348,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
336
348
  // 在最终挂载前,先加载所有可能用到的 processors。
337
349
  const usedProcessors = (0, _storyboard.strictCollectMemberUsage)([brickConf.events, brickConf.lifeCycle], "PROCESSORS", 2);
338
350
  if (usedProcessors.size > 0) {
339
- output.blockingList.push((0, _loader.loadProcessorsImperatively)(usedProcessors, (0, _Runtime.getBrickPackages)()));
351
+ output.blockingList.push(catchLoad((0, _loader.loadProcessorsImperatively)(usedProcessors, (0, _Runtime.getBrickPackages)()), "processors", [...usedProcessors].join(", "), rendererContext.unknownBricks));
340
352
  }
341
353
 
342
354
  // 加载构件属性和加载子构件等任务,可以并行。
@@ -372,15 +384,87 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
372
384
  if (!slots) {
373
385
  return;
374
386
  }
375
- const rendered = await Promise.all(Object.entries(slots).map(([childSlotId, slotConf]) => slotConf.type !== "routes" ? renderBricks(brick, slotConf.bricks, childRuntimeContext, rendererContext, childSlotId, tplStack) : renderRoutes(brick, slotConf.routes, childRuntimeContext, rendererContext, childSlotId)));
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
+ }));
376
455
  const childrenOutput = {
377
456
  ...output,
378
457
  node: undefined,
379
- blockingList: []
458
+ blockingList: [],
459
+ menuRequests: []
380
460
  };
381
- for (const item of rendered) {
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
+ }
382
466
  mergeRenderOutput(childrenOutput, item);
383
- }
467
+ });
384
468
  if (childrenOutput.node) {
385
469
  brick.child = childrenOutput.node;
386
470
  }
@@ -403,22 +487,44 @@ function ensureValidControlBrick(brick) {
403
487
  throw new Error(`Unknown storyboard control node: "${brick}"`);
404
488
  }
405
489
  }
406
- async function renderForEach(returnNode, dataSource, bricks, runtimeContext, rendererContext, slotId, tplStack) {
490
+ async function renderForEach(returnNode, dataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
407
491
  const output = {
408
492
  blockingList: [],
409
493
  menuRequests: []
410
494
  };
495
+ const rows = dataSource.length;
411
496
  const rendered = await Promise.all(dataSource.map((item, i) => Promise.all(bricks.map((brickConf, j) => renderBrick(returnNode, brickConf, {
412
497
  ...runtimeContext,
413
498
  forEachItem: item
414
- }, rendererContext, slotId, i * j, tplStack && new Map(tplStack))))));
499
+ }, rendererContext, parentRoutes, slotId, keyPath.concat(i * rows + j), tplStack && new Map(tplStack))))));
415
500
 
416
501
  // 多层构件并行异步转换,但转换的结果按原顺序串行合并。
417
- for (const item of rendered.flat()) {
502
+ rendered.flat().forEach((item, index) => {
503
+ if (item.hasTrackingControls) {
504
+ // Memoize a render node before it's been merged.
505
+ rendererContext.memoize(slotId, keyPath.concat(index), item.node, returnNode);
506
+ }
418
507
  mergeRenderOutput(output, item);
419
- }
508
+ });
420
509
  return output;
421
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
+ }
422
528
  function loadMenu(menuConf, runtimeContext) {
423
529
  if (!menuConf) {
424
530
  return;
@@ -486,10 +592,10 @@ function childrenToSlots(children, originalSlots) {
486
592
  }
487
593
  return newSlots;
488
594
  }
489
- function catchLoadBrick(promise, brickName, unknownBricks) {
490
- return unknownBricks === "silent" ? promise.catch(e => {
595
+ function catchLoad(promise, type, name, unknownPolicy) {
596
+ return unknownPolicy === "silent" ? promise.catch(e => {
491
597
  // eslint-disable-next-line no-console
492
- console.error(`Load brick "${brickName}" failed:`, e);
598
+ console.error(`Load ${type} "${name}" failed:`, e);
493
599
  }) : promise;
494
600
  }
495
601
  //# sourceMappingURL=Renderer.js.map