@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
@@ -1 +1 @@
1
- {"version":3,"file":"createRoot.js","names":["flushStableLoadBricks","renderBricks","RendererContext","DataStore","mountTree","unmountTree","httpErrorToString","applyMode","applyTheme","setMode","setTheme","RenderTag","registerStoryboardFunctions","registerAppI18n","registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","arguments","length","undefined","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","_arguments","_asyncToGenerator","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","previousRendererContext","runtimeContext","ctxStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","renderRoot","tag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","define","failed","output","stores","values","Promise","all","blockingList","map","store","waitForAll","error","node","BRICK","type","properties","textContent","return","menuRequests","child","dispatchOnUnmount","dispose","dispatchBeforePageLoad","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,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAAuBC,YAAY,QAAQ,wBAAwB;AACnE,SAASC,eAAe,QAAQ,+BAA+B;AAC/D,SAASC,SAAS,QAAQ,8BAA8B;AAExD,SAASC,SAAS,EAAEC,WAAW,QAAQ,qBAAqB;AAC5D,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,mBAAmB;AAC5E,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,2BAA2B,QAAQ,2CAA2C;AACvF,SAASC,eAAe,QAAQ,+BAA+B;AAC/D,SAASC,uBAAuB,QAAQ,uCAAuC;AA2B/E,OAAO,SAASC,mBAAmBA,CACjCC,SAAyC,EAEzC;EAAA,IADA;IAAEC,MAAM,EAAEC,OAAO;IAAEC,KAAK,GAAG,UAAU;IAAEC;EAAiC,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SA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AACC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;QACvB;QAEA,IAAI,CAACvB,MAAM,EAAE;UACX,KAAK,IAAMQ,KAAK,IAAIN,MAAM,EAAE;YAC1BM,KAAK,CAACgB,qBAAqB,CAAC,CAAC;UAC/B;UAEA,IAAIzE,KAAK,KAAK,MAAM,EAAE;YACpBe,eAAe,CAAC2D,gBAAgB,CAAC,CAAC;YAClC;UACF;;UACA3D,eAAe,CAAC4D,eAAe,CAAC,CAAC;UACjC5D,eAAe,CAAC6D,wBAAwB,CAAC,CAAC;UAC1C7D,eAAe,CAAC8D,qBAAqB,CAAC,CAAC;UACvC9D,eAAe,CAAC+D,2BAA2B,CAAC,CAAC;QAC/C;MAAC;IACH,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAIjE,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB5B,WAAW,CAACW,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACVZ,WAAW,CAACY,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACkF,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"createRoot.js","names":["getDataStores","postAsyncRender","renderBricks","RendererContext","DataStore","mountTree","unmountTree","httpErrorToString","applyMode","applyTheme","setMode","setTheme","RenderTag","registerStoryboardFunctions","registerAppI18n","registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","arguments","length","undefined","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","_arguments","_asyncToGenerator","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","previousRendererContext","runtimeContext","ctxStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","renderRoot","tag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","define","failed","output","stores","error","node","BRICK","type","properties","textContent","return","blockingList","menuRequests","child","dispatchOnUnmount","dispose","dispatchBeforePageLoad","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,SAEEA,aAAa,EACbC,eAAe,EACfC,YAAY,QACP,wBAAwB;AAC/B,SAASC,eAAe,QAAQ,+BAA+B;AAC/D,SAASC,SAAS,QAAQ,8BAA8B;AAExD,SAASC,SAAS,EAAEC,WAAW,QAAQ,qBAAqB;AAC5D,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,mBAAmB;AAC5E,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,2BAA2B,QAAQ,2CAA2C;AACvF,SAASC,eAAe,QAAQ,+BAA+B;AAC/D,SAASC,uBAAuB,QAAQ,uCAAuC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,IAAIhB,MAAM,EAAE;YAC1BgB,KAAK,CAACC,cAAc,CAAC,CAAC;UACxB;UAEA,IAAIpE,KAAK,KAAK,MAAM,EAAE;YACpBe,eAAe,CAACsD,gBAAgB,CAAC,CAAC;YAClC;UACF;;UACAtD,eAAe,CAACuD,eAAe,CAAC,CAAC;UACjCvD,eAAe,CAACwD,wBAAwB,CAAC,CAAC;UAC1CxD,eAAe,CAACyD,qBAAqB,CAAC,CAAC;UACvCzD,eAAe,CAAC0D,2BAA2B,CAAC,CAAC;QAC/C;MAAC;IACH,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI5D,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB5B,WAAW,CAACW,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACVZ,WAAW,CAACY,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC6E,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
@@ -50,7 +50,7 @@ export function unbindTemplateProxy(brick) {
50
50
  runtimeContext,
51
51
  element
52
52
  } = brick;
53
- if (!runtimeContext.tplStateStoreId || !ref) {
53
+ if (!(runtimeContext !== null && runtimeContext !== void 0 && runtimeContext.tplStateStoreId) || !ref) {
54
54
  return;
55
55
  }
56
56
  var {
@@ -1 +1 @@
1
- {"version":3,"file":"bindTemplateProxy.js","names":["getTplStateStore","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","tplHostMetadata","internalBricksByRef","set","events","proxy","_loop","from","to","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","Object","entries","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,SAASA,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,IAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,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AE0B,gBAAgB,CAACC,IAAI,CAAC,CAACJ,SAAS,EAAET,QAAQ,CAAC,CAAC;MACvD;IACF,CAAC;IApBD,KAAK,IAAM,CAACL,IAAI,EAAEC,EAAE,CAAC,IAAIkB,MAAM,CAACC,OAAO,CAACvB,MAAM,CAAC;MAAAE,KAAA,CAAAC,IAAA;IAAA;EAqBjD;AACF;AAEA,OAAO,SAASqB,mBAAmBA,CAAClC,KAAmB,EAAE;EACvD,IAAM;IAAEE,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;EAE9C,IAAI,CAACG,cAAc,CAACE,eAAe,IAAI,CAACH,GAAG,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEI;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,qBAAqB,CAAC;EAC7E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAAC2B,MAAM,CAACjC,GAAG,CAAC;EAE/C,KAAK,IAAM,CAACkC,IAAI,EAAEC,EAAE,CAAC,KAAAC,iBAAA,GAAIlC,OAAO,CAAE0B,gBAAgB,cAAAQ,iBAAA,cAAAA,iBAAA,GAAI,EAAE,EAAE;IAAA,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE0B,gBAAgB;AAClC"}
1
+ {"version":3,"file":"bindTemplateProxy.js","names":["getTplStateStore","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","tplHostMetadata","internalBricksByRef","set","events","proxy","_loop","from","to","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","Object","entries","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,SAASA,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,IAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;E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D,IAAA,CAASc,gBAAgB,GAAK,EAAE;QAChC1B,OAAO,CAAE0B,gBAAgB,CAACC,IAAI,CAAC,CAACJ,SAAS,EAAET,QAAQ,CAAC,CAAC;MACvD;IACF,CAAC;IApBD,KAAK,IAAM,CAACL,IAAI,EAAEC,EAAE,CAAC,IAAIkB,MAAM,CAACC,OAAO,CAACvB,MAAM,CAAC;MAAAE,KAAA,CAAAC,IAAA;IAAA;EAqBjD;AACF;AAEA,OAAO,SAASqB,mBAAmBA,CAAClC,KAAmB,EAAE;EACvD,IAAM;IAAEE,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;EAE9C,IAAI,EAACG,cAAc,aAAdA,cAAc,eAAdA,cAAc,CAAEE,eAAe,KAAI,CAACH,GAAG,EAAE;IAC5C;EACF;EAEA,IAAM;IAAEI;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,qBAAqB,CAAC;EAC7E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAAC2B,MAAM,CAACjC,GAAG,CAAC;EAE/C,KAAK,IAAM,CAACkC,IAAI,EAAEC,EAAE,CAAC,KAAAC,iBAAA,GAAIlC,OAAO,CAAE0B,gBAAgB,cAAAQ,iBAAA,cAAAA,iBAAA,GAAI,EAAE,EAAE;IAAA,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE0B,gBAAgB;AAClC"}
@@ -1,21 +1,22 @@
1
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
4
  var _excluded = ["blockingList", "node", "menuRequests", "hasTrackingControls"],
5
5
  _excluded2 = ["if", "permissionsPreCheck"],
6
6
  _excluded3 = ["formData"],
7
7
  _excluded4 = ["src"],
8
8
  _excluded5 = ["href"];
9
- import { enqueueStableLoadBricks, loadBricksImperatively, loadProcessorsImperatively, loadScript, loadStyle } from "@next-core/loader";
9
+ import { enqueueStableLoadBricks, flushStableLoadBricks, loadBricksImperatively, loadProcessorsImperatively, loadScript, loadStyle } from "@next-core/loader";
10
10
  import { isTrackAll } from "@next-core/cook";
11
11
  import { hasOwnProperty } from "@next-core/utils/general";
12
+ import { strictCollectMemberUsage } from "@next-core/utils/storyboard";
12
13
  import { debounce } from "lodash";
13
14
  import { asyncCheckBrickIf } from "./compute/checkIf.js";
14
15
  import { asyncComputeRealPropertyEntries, constructAsyncProperties } from "./compute/computeRealProperties.js";
15
16
  import { resolveData } from "./data/resolveData.js";
16
17
  import { asyncComputeRealValue } from "./compute/computeRealValue.js";
17
18
  import { listenOnTrackingContext } from "./compute/listenOnTrackingContext.js";
18
- import { matchRoutes } from "./matchRoutes.js";
19
+ import { matchRoute, matchRoutes } from "./matchRoutes.js";
19
20
  import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachItem, symbolForTplStateStoreId } from "./CustomTemplates/constants.js";
20
21
  import { expandCustomTemplate } from "./CustomTemplates/expandCustomTemplate.js";
21
22
  import { getTagNameOfCustomTemplate, getTplStateStore } from "./CustomTemplates/utils.js";
@@ -28,12 +29,12 @@ import { FORM_RENDERER, symbolForFormStateStoreId } from "./FormRenderer/constan
28
29
  import { expandFormRenderer } from "./FormRenderer/expandFormRenderer.js";
29
30
  import { isPreEvaluated } from "./compute/evaluate.js";
30
31
  import { getPreEvaluatedRaw } from "./compute/evaluate.js";
31
- import { strictCollectMemberUsage } from "@next-core/utils/storyboard";
32
- export function renderRoutes(_x, _x2, _x3, _x4, _x5) {
32
+ import { matchHomepage } from "./matchStoryboard.js";
33
+ export function renderRoutes(_x, _x2, _x3, _x4, _x5, _x6, _x7) {
33
34
  return _renderRoutes.apply(this, arguments);
34
35
  }
35
36
  function _renderRoutes() {
36
- _renderRoutes = _asyncToGenerator(function* (returnNode, routes, _runtimeContext, rendererContext, slotId) {
37
+ _renderRoutes = _asyncToGenerator(function* (returnNode, routes, _runtimeContext, rendererContext, parentRoutes, slotId, isIncremental) {
37
38
  var matched = yield matchRoutes(routes, _runtimeContext);
38
39
  var output = {
39
40
  blockingList: [],
@@ -52,7 +53,11 @@ function _renderRoutes() {
52
53
  var runtimeContext = _objectSpread(_objectSpread({}, _runtimeContext), {}, {
53
54
  match: matched.match
54
55
  });
55
- runtimeContext.ctxStore.define(route.context, runtimeContext);
56
+ if (isIncremental) {
57
+ runtimeContext.ctxStore.disposeDataInRoutes(routes);
58
+ }
59
+ var routePath = parentRoutes.concat(route);
60
+ runtimeContext.ctxStore.define(route.context, runtimeContext, undefined, routePath);
56
61
  runtimeContext.pendingPermissionsPreCheck.push(hooks === null || hooks === void 0 || (_hooks$checkPermissio = hooks.checkPermissions) === null || _hooks$checkPermissio === void 0 ? void 0 : _hooks$checkPermissio.preCheckPermissionsForBrickOrRoute(route, value => asyncComputeRealValue(value, runtimeContext)));
57
62
 
58
63
  // Currently, this is only used for brick size-checking: these bricks
@@ -63,41 +68,39 @@ function _renderRoutes() {
63
68
  if (Array.isArray(preLoadBricks)) {
64
69
  output.blockingList.push(loadBricksImperatively(preLoadBricks, getBrickPackages()));
65
70
  }
66
- switch (route.type) {
67
- case "redirect":
68
- {
69
- var redirectTo;
70
- if (typeof route.redirect === "string") {
71
- redirectTo = yield asyncComputeRealValue(route.redirect, runtimeContext);
72
- } else {
73
- var resolved = yield resolveData(_objectSpread({
74
- transform: "redirect"
75
- }, route.redirect), runtimeContext);
76
- redirectTo = resolved.redirect;
77
- }
78
- if (typeof redirectTo !== "string") {
79
- // eslint-disable-next-line no-console
80
- console.error("Unexpected redirect result:", redirectTo);
81
- throw new Error("Unexpected type of redirect result: ".concat(typeof redirectTo));
82
- }
83
- output.redirect = {
84
- path: redirectTo
85
- };
86
- break;
87
- }
88
- case "routes":
89
- {
90
- output.menuRequests.push(loadMenu(route.menu, runtimeContext));
91
- var newOutput = yield renderRoutes(returnNode, route.routes, runtimeContext, rendererContext, slotId);
92
- mergeRenderOutput(output, newOutput);
93
- break;
94
- }
95
- default:
96
- {
97
- output.menuRequests.push(loadMenu(route.menu, runtimeContext));
98
- var _newOutput = yield renderBricks(returnNode, route.bricks, runtimeContext, rendererContext, slotId);
99
- mergeRenderOutput(output, _newOutput);
100
- }
71
+ if (route.type === "redirect") {
72
+ var redirectTo;
73
+ if (typeof route.redirect === "string") {
74
+ redirectTo = yield asyncComputeRealValue(route.redirect, runtimeContext);
75
+ } else {
76
+ var resolved = yield resolveData(_objectSpread({
77
+ transform: "redirect"
78
+ }, route.redirect), runtimeContext);
79
+ redirectTo = resolved.redirect;
80
+ }
81
+ if (typeof redirectTo !== "string") {
82
+ // eslint-disable-next-line no-console
83
+ console.error("Unexpected redirect result:", redirectTo);
84
+ throw new Error("Unexpected type of redirect result: ".concat(typeof redirectTo));
85
+ }
86
+ output.redirect = {
87
+ path: redirectTo
88
+ };
89
+ } else {
90
+ var menuRequest = loadMenu(route.menu, runtimeContext);
91
+ if (menuRequest) {
92
+ output.menuRequests.push(menuRequest);
93
+ }
94
+ if (route.type === "routes") {
95
+ var newOutput = yield renderRoutes(returnNode, route.routes, runtimeContext, rendererContext, routePath, slotId);
96
+ mergeRenderOutput(output, newOutput);
97
+ } else {
98
+ var _newOutput = yield renderBricks(returnNode, route.bricks, runtimeContext, rendererContext, routePath, slotId);
99
+ mergeRenderOutput(output, _newOutput);
100
+ }
101
+ if (returnNode.tag === RenderTag.BRICK) {
102
+ rendererContext.memoizeMenuRequests(route, output.menuRequests);
103
+ }
101
104
  }
102
105
  }
103
106
  }
@@ -105,21 +108,22 @@ function _renderRoutes() {
105
108
  });
106
109
  return _renderRoutes.apply(this, arguments);
107
110
  }
108
- export function renderBricks(_x6, _x7, _x8, _x9, _x10, _x11, _x12) {
111
+ export function renderBricks(_x8, _x9, _x10, _x11, _x12, _x13, _x14, _x15) {
109
112
  return _renderBricks.apply(this, arguments);
110
113
  }
111
114
  function _renderBricks() {
112
- _renderBricks = _asyncToGenerator(function* (returnNode, bricks, runtimeContext, rendererContext, slotId, tplStack, noMemoize) {
115
+ _renderBricks = _asyncToGenerator(function* (returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
113
116
  var output = {
114
117
  blockingList: [],
115
118
  menuRequests: []
116
119
  };
120
+ var kPath = keyPath !== null && keyPath !== void 0 ? keyPath : [];
117
121
  // 多个构件并行异步转换,但转换的结果按原顺序串行合并。
118
- var rendered = yield Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, slotId, index, tplStack && new Map(tplStack))));
122
+ var rendered = yield Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, parentRoutes, slotId, kPath.concat(index), tplStack && new Map(tplStack))));
119
123
  rendered.forEach((item, index) => {
120
- if (!noMemoize && item.hasTrackingControls) {
124
+ if (item.hasTrackingControls) {
121
125
  // Memoize a render node before it's been merged.
122
- rendererContext.memoizeControlNode(slotId, index, item.node, returnNode);
126
+ rendererContext.memoize(slotId, kPath.concat(index), item.node, returnNode);
123
127
  }
124
128
  mergeRenderOutput(output, item);
125
129
  });
@@ -127,13 +131,14 @@ function _renderBricks() {
127
131
  });
128
132
  return _renderBricks.apply(this, arguments);
129
133
  }
130
- export function renderBrick(_x13, _x14, _x15, _x16, _x17, _x18) {
134
+ export function renderBrick(_x16, _x17, _x18, _x19, _x20, _x21) {
131
135
  return _renderBrick.apply(this, arguments);
132
136
  }
133
137
  function _renderBrick() {
134
- _renderBrick = _asyncToGenerator(function* (returnNode, brickConf, _runtimeContext, rendererContext, slotId, key) {
138
+ _renderBrick = _asyncToGenerator(function* (returnNode, brickConf, _runtimeContext, rendererContext, parentRoutes, slotId) {
135
139
  var _hooks$checkPermissio2, _runtimeContext$app;
136
- var tplStack = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Map();
140
+ var keyPath = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : [];
141
+ var tplStack = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : new Map();
137
142
  var output = {
138
143
  blockingList: [],
139
144
  menuRequests: []
@@ -170,7 +175,7 @@ function _renderBrick() {
170
175
  }
171
176
  }, Object.getOwnPropertySymbols(brickConf).reduce((acc, symbol) => _objectSpread(_objectSpread({}, acc), {}, {
172
177
  [symbol]: brickConf[symbol]
173
- }), {})), _runtimeContext, rendererContext, slotId, key, tplStack);
178
+ }), {})), _runtimeContext, rendererContext, parentRoutes, slotId, keyPath, tplStack);
174
179
  }
175
180
  var tplStateStoreId = brickConf[symbolForTplStateStoreId];
176
181
  var formStateStoreId = brickConf[symbolForFormStateStoreId];
@@ -205,7 +210,7 @@ function _renderBrick() {
205
210
  dataSource
206
211
  } = brickConf;
207
212
  var renderControlNode = /*#__PURE__*/function () {
208
- var _ref = _asyncToGenerator(function* () {
213
+ var _ref = _asyncToGenerator(function* (runtimeContext) {
209
214
  var _slots$slot;
210
215
  // First, compute the `dataSource`
211
216
  var computedDataSource = yield asyncComputeRealValue(dataSource, runtimeContext);
@@ -227,20 +232,20 @@ function _renderBrick() {
227
232
  if (!Array.isArray(computedDataSource)) {
228
233
  return output;
229
234
  }
230
- return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, slotId, tplStack);
235
+ return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
231
236
  }
232
237
  case ":if":
233
238
  case ":switch":
234
239
  {
235
- return renderBricks(returnNode, bricks, runtimeContext, rendererContext, slotId, tplStack, true);
240
+ return renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
236
241
  }
237
242
  }
238
243
  });
239
- return function renderControlNode() {
244
+ return function renderControlNode(_x31) {
240
245
  return _ref.apply(this, arguments);
241
246
  };
242
247
  }();
243
- var controlledOutput = yield renderControlNode();
248
+ var controlledOutput = yield renderControlNode(runtimeContext);
244
249
  var {
245
250
  contextNames,
246
251
  stateNames
@@ -251,12 +256,17 @@ function _renderBrick() {
251
256
  var listener = /*#__PURE__*/function () {
252
257
  var _ref2 = _asyncToGenerator(function* () {
253
258
  var currentRenderId = ++renderId;
254
- var controlOutput = yield renderControlNode();
255
- controlOutput.blockingList.push(...[...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck);
256
- yield Promise.all(controlOutput.blockingList);
259
+ var [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(runtimeContext);
260
+ var controlOutput = yield renderControlNode(scopedRuntimeContext);
261
+ var scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
262
+ yield postAsyncRender(controlOutput, scopedRuntimeContext, scopedStores);
263
+
257
264
  // Ignore stale renders
258
265
  if (renderId === currentRenderId) {
259
- rendererContext.rerenderControlNode(slotId, key, controlOutput.node, returnNode);
266
+ rendererContext.reRender(slotId, keyPath, controlOutput.node, returnNode);
267
+ for (var store of scopedStores) {
268
+ store.mountAsyncData();
269
+ }
260
270
  }
261
271
  });
262
272
  return function listener() {
@@ -281,7 +291,7 @@ function _renderBrick() {
281
291
 
282
292
  // Widgets need to be defined before rendering.
283
293
  if (/\.tpl-/.test(brickName) && !customTemplates.get(brickName)) {
284
- yield catchLoadBrick(loadBricksImperatively([brickName], getBrickPackages()), brickName, rendererContext.unknownBricks);
294
+ yield catchLoad(loadBricksImperatively([brickName], getBrickPackages()), "brick", brickName, rendererContext.unknownBricks);
285
295
  }
286
296
  var tplTagName = getTagNameOfCustomTemplate(brickName, (_runtimeContext$app = runtimeContext.app) === null || _runtimeContext$app === void 0 ? void 0 : _runtimeContext$app.id);
287
297
  if (tplTagName) {
@@ -299,7 +309,7 @@ function _renderBrick() {
299
309
  }
300
310
  });
301
311
  } else {
302
- output.blockingList.push(catchLoadBrick(enqueueStableLoadBricks([brickName], getBrickPackages()), brickName, rendererContext.unknownBricks));
312
+ output.blockingList.push(catchLoad(enqueueStableLoadBricks([brickName], getBrickPackages()), "brick", brickName, rendererContext.unknownBricks));
303
313
  }
304
314
  }
305
315
  var formData;
@@ -332,13 +342,13 @@ function _renderBrick() {
332
342
  src
333
343
  } = props,
334
344
  attrs = _objectWithoutProperties(props, _excluded4);
335
- yield loadScript(src, prefix, attrs);
345
+ yield catchLoad(loadScript(src, prefix, attrs), "script", src, "silent");
336
346
  } else {
337
347
  var {
338
348
  href
339
349
  } = props,
340
350
  attrs = _objectWithoutProperties(props, _excluded5);
341
- yield loadStyle(href, prefix, attrs);
351
+ yield catchLoad(loadStyle(href, prefix, attrs), "stylesheet", href, "silent");
342
352
  }
343
353
  return output;
344
354
  }
@@ -359,7 +369,7 @@ function _renderBrick() {
359
369
  // 在最终挂载前,先加载所有可能用到的 processors。
360
370
  var usedProcessors = strictCollectMemberUsage([brickConf.events, brickConf.lifeCycle], "PROCESSORS", 2);
361
371
  if (usedProcessors.size > 0) {
362
- output.blockingList.push(loadProcessorsImperatively(usedProcessors, getBrickPackages()));
372
+ output.blockingList.push(catchLoad(loadProcessorsImperatively(usedProcessors, getBrickPackages()), "processors", [...usedProcessors].join(", "), rendererContext.unknownBricks));
363
373
  }
364
374
 
365
375
  // 加载构件属性和加载子构件等任务,可以并行。
@@ -399,17 +409,91 @@ function _renderBrick() {
399
409
  if (!slots) {
400
410
  return;
401
411
  }
402
- var rendered = yield Promise.all(Object.entries(slots).map(_ref6 => {
412
+ var routeSlotIndexes = new Set();
413
+ var rendered = yield Promise.all(Object.entries(slots).map((_ref6, index) => {
403
414
  var [childSlotId, slotConf] = _ref6;
404
- return slotConf.type !== "routes" ? renderBricks(brick, slotConf.bricks, childRuntimeContext, rendererContext, childSlotId, tplStack) : renderRoutes(brick, slotConf.routes, childRuntimeContext, rendererContext, childSlotId);
415
+ if (slotConf.type !== "routes") {
416
+ return renderBricks(brick, slotConf.bricks, childRuntimeContext, rendererContext, parentRoutes, childSlotId, tplStack);
417
+ }
418
+ if (runtimeContext.flags["incremental-sub-route-rendering"]) {
419
+ routeSlotIndexes.add(index);
420
+ rendererContext.performIncrementalRender( /*#__PURE__*/function () {
421
+ var _ref7 = _asyncToGenerator(function* (location) {
422
+ var {
423
+ homepage
424
+ } = childRuntimeContext.app;
425
+ var {
426
+ pathname
427
+ } = location;
428
+ // Ignore if any one of homepage and parent routes not matched.
429
+ if (!matchHomepage(homepage, pathname) || !parentRoutes.every(route => matchRoute(route, homepage, pathname))) {
430
+ return false;
431
+ }
432
+ var [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(_objectSpread(_objectSpread({}, childRuntimeContext), {}, {
433
+ location,
434
+ query: new URLSearchParams(location.search)
435
+ }));
436
+ var failed = false;
437
+ var incrementalOutput;
438
+ var scopedStores = [];
439
+ try {
440
+ incrementalOutput = yield renderRoutes(brick, slotConf.routes, scopedRuntimeContext, rendererContext, parentRoutes, childSlotId, true);
441
+
442
+ // If all sub-routes are missed, ignore incremental rendering
443
+ if (!incrementalOutput.route) {
444
+ return false;
445
+ }
446
+
447
+ // Bailout if redirect or unauthenticated is set
448
+ if (rendererContext.reBailout(incrementalOutput)) {
449
+ return true;
450
+ }
451
+ scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
452
+ yield postAsyncRender(incrementalOutput, scopedRuntimeContext, [scopedRuntimeContext.ctxStore, ...scopedStores]);
453
+ yield rendererContext.reMergeMenuRequests(slotConf.routes, incrementalOutput.route, incrementalOutput.menuRequests);
454
+ } catch (error) {
455
+ // eslint-disable-next-line no-console
456
+ console.error("Incremental sub-router failed:", error);
457
+ var result = rendererContext.reCatch(error, brick);
458
+ if (!result) {
459
+ return true;
460
+ }
461
+ ({
462
+ failed,
463
+ output: incrementalOutput
464
+ } = result);
465
+
466
+ // Assert: no errors will be throw
467
+ yield rendererContext.reMergeMenuRequests(slotConf.routes, incrementalOutput.route, incrementalOutput.menuRequests);
468
+ }
469
+ rendererContext.reRender(childSlotId, [], incrementalOutput.node, brick);
470
+ if (!failed) {
471
+ scopedRuntimeContext.ctxStore.mountAsyncData(incrementalOutput.route);
472
+ for (var store of scopedStores) {
473
+ store.mountAsyncData();
474
+ }
475
+ }
476
+ return true;
477
+ });
478
+ return function (_x32) {
479
+ return _ref7.apply(this, arguments);
480
+ };
481
+ }());
482
+ }
483
+ return renderRoutes(brick, slotConf.routes, childRuntimeContext, rendererContext, parentRoutes, childSlotId);
405
484
  }));
406
485
  var childrenOutput = _objectSpread(_objectSpread({}, output), {}, {
407
486
  node: undefined,
408
- blockingList: []
487
+ blockingList: [],
488
+ menuRequests: []
409
489
  });
410
- for (var item of rendered) {
490
+ rendered.forEach((item, index) => {
491
+ if (routeSlotIndexes.has(index)) {
492
+ // Memoize a render node before it's been merged.
493
+ rendererContext.memoize(slotId, [], item.node, brick);
494
+ }
411
495
  mergeRenderOutput(childrenOutput, item);
412
- }
496
+ });
413
497
  if (childrenOutput.node) {
414
498
  brick.child = childrenOutput.node;
415
499
  }
@@ -437,27 +521,48 @@ function ensureValidControlBrick(brick) {
437
521
  throw new Error("Unknown storyboard control node: \"".concat(brick, "\""));
438
522
  }
439
523
  }
440
- function renderForEach(_x19, _x20, _x21, _x22, _x23, _x24, _x25) {
524
+ function renderForEach(_x22, _x23, _x24, _x25, _x26, _x27, _x28, _x29, _x30) {
441
525
  return _renderForEach.apply(this, arguments);
442
526
  }
443
527
  function _renderForEach() {
444
- _renderForEach = _asyncToGenerator(function* (returnNode, dataSource, bricks, runtimeContext, rendererContext, slotId, tplStack) {
528
+ _renderForEach = _asyncToGenerator(function* (returnNode, dataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
445
529
  var output = {
446
530
  blockingList: [],
447
531
  menuRequests: []
448
532
  };
533
+ var rows = dataSource.length;
449
534
  var rendered = yield Promise.all(dataSource.map((item, i) => Promise.all(bricks.map((brickConf, j) => renderBrick(returnNode, brickConf, _objectSpread(_objectSpread({}, runtimeContext), {}, {
450
535
  forEachItem: item
451
- }), rendererContext, slotId, i * j, tplStack && new Map(tplStack))))));
536
+ }), rendererContext, parentRoutes, slotId, keyPath.concat(i * rows + j), tplStack && new Map(tplStack))))));
452
537
 
453
538
  // 多层构件并行异步转换,但转换的结果按原顺序串行合并。
454
- for (var item of rendered.flat()) {
539
+ rendered.flat().forEach((item, index) => {
540
+ if (item.hasTrackingControls) {
541
+ // Memoize a render node before it's been merged.
542
+ rendererContext.memoize(slotId, keyPath.concat(index), item.node, returnNode);
543
+ }
455
544
  mergeRenderOutput(output, item);
456
- }
545
+ });
457
546
  return output;
458
547
  });
459
548
  return _renderForEach.apply(this, arguments);
460
549
  }
550
+ export function getDataStores(runtimeContext) {
551
+ return [runtimeContext.ctxStore, ...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()];
552
+ }
553
+ export function postAsyncRender(output, runtimeContext, stores) {
554
+ flushStableLoadBricks();
555
+ return Promise.all([...output.blockingList, ...stores.map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
556
+ }
557
+ export function createScopedRuntimeContext(runtimeContext) {
558
+ var tplStateStoreScope = [];
559
+ var formStateStoreScope = [];
560
+ var scopedRuntimeContext = _objectSpread(_objectSpread({}, runtimeContext), {}, {
561
+ tplStateStoreScope,
562
+ formStateStoreScope
563
+ });
564
+ return [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope];
565
+ }
461
566
  function loadMenu(menuConf, runtimeContext) {
462
567
  if (!menuConf) {
463
568
  return;
@@ -525,10 +630,10 @@ export function childrenToSlots(children, originalSlots) {
525
630
  }
526
631
  return newSlots;
527
632
  }
528
- function catchLoadBrick(promise, brickName, unknownBricks) {
529
- return unknownBricks === "silent" ? promise.catch(e => {
633
+ function catchLoad(promise, type, name, unknownPolicy) {
634
+ return unknownPolicy === "silent" ? promise.catch(e => {
530
635
  // eslint-disable-next-line no-console
531
- console.error("Load brick \"".concat(brickName, "\" failed:"), e);
636
+ console.error("Load ".concat(type, " \"").concat(name, "\" failed:"), e);
532
637
  }) : promise;
533
638
  }
534
639
  //# sourceMappingURL=Renderer.js.map