@next-core/runtime 1.6.0 → 1.6.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.
@@ -52,7 +52,8 @@ function unstable_createRoot(container, {
52
52
  const runtimeContext = {
53
53
  ctxStore: new _DataStore.DataStore("CTX"),
54
54
  pendingPermissionsPreCheck: [],
55
- tplStateStoreMap: new Map()
55
+ tplStateStoreMap: new Map(),
56
+ formStateStoreMap: new Map()
56
57
  };
57
58
  const previousRendererContext = rendererContext;
58
59
  rendererContext = new _RendererContext.RendererContext(scope, {
@@ -94,7 +95,7 @@ function unstable_createRoot(container, {
94
95
  try {
95
96
  output = await (0, _Renderer.renderBricks)(renderRoot, bricks, runtimeContext, rendererContext);
96
97
  (0, _loader.flushStableLoadBricks)();
97
- await Promise.all([...output.blockingList, runtimeContext.ctxStore.waitForAll(), ...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
98
+ await Promise.all([...output.blockingList, runtimeContext.ctxStore.waitForAll(), ...[...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
98
99
  } catch (error) {
99
100
  failed = true;
100
101
  output = {
@@ -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","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","renderBricks","flushStableLoadBricks","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","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,\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 const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\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 try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\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 setTheme(theme ?? \"light\");\n setMode(\"default\");\n\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 if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\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,m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AAe,EAAE;QACjCtE,eAAe,CAACuE,wBAAwB,EAAE;QAC1CvE,eAAe,CAACwE,qBAAqB,EAAE;MACzC;IACF,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI1E,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAA6D,kBAAW,EAAC3E,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAA0E,kBAAW,EAAC1E,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACwF,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
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","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","renderBricks","flushStableLoadBricks","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","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,\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 const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\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 previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\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 try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[\n ...runtimeContext.tplStateStoreMap.values(),\n ...runtimeContext.formStateStoreMap.values(),\n ].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 setTheme(theme ?? \"light\");\n setMode(\"default\");\n\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 if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\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,SAAsB,EACtB;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,CAA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MAAM,EAAE;QACV,IAAA2E,kBAAW,EAAC3E,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACyF,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
@@ -51,7 +51,8 @@ export function unstable_createRoot(container) {
51
51
  var runtimeContext = {
52
52
  ctxStore: new DataStore("CTX"),
53
53
  pendingPermissionsPreCheck: [],
54
- tplStateStoreMap: new Map()
54
+ tplStateStoreMap: new Map(),
55
+ formStateStoreMap: new Map()
55
56
  };
56
57
  var previousRendererContext = rendererContext;
57
58
  rendererContext = new RendererContext(scope, {
@@ -93,7 +94,7 @@ export function unstable_createRoot(container) {
93
94
  try {
94
95
  output = yield renderBricks(renderRoot, bricks, runtimeContext, rendererContext);
95
96
  flushStableLoadBricks();
96
- yield Promise.all([...output.blockingList, runtimeContext.ctxStore.waitForAll(), ...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
97
+ yield Promise.all([...output.blockingList, runtimeContext.ctxStore.waitForAll(), ...[...runtimeContext.tplStateStoreMap.values(), ...runtimeContext.formStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
97
98
  } catch (error) {
98
99
  failed = true;
99
100
  output = {
@@ -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","runtimeContext","ctxStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","previousRendererContext","renderRoot","tag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","define","failed","output","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","return","menuRequests","child","dispatchOnUnmount","dispose","dispatchBeforePageLoad","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","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,\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 const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\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 try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\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 setTheme(theme ?? \"light\");\n setMode(\"default\");\n\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 if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\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,QAA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;QACvB;QAEA,IAAI,CAACtB,MAAM,EAAE;UACX,IAAIhD,KAAK,KAAK,MAAM,EAAE;YACpBe,eAAe,CAACwD,gBAAgB,EAAE;YAClC;UACF;;UACAxD,eAAe,CAACyD,eAAe,EAAE;UACjCzD,eAAe,CAAC0D,wBAAwB,EAAE;UAC1C1D,eAAe,CAAC2D,qBAAqB,EAAE;QACzC;MAAC;IACH,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI7D,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,CAAC8E,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
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","runtimeContext","ctxStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","previousRendererContext","renderRoot","tag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","define","failed","output","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","return","menuRequests","child","dispatchOnUnmount","dispose","dispatchBeforePageLoad","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","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,\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 const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\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 previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\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 try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[\n ...runtimeContext.tplStateStoreMap.values(),\n ...runtimeContext.formStateStoreMap.values(),\n ].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 setTheme(theme ?? \"light\");\n setMode(\"default\");\n\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 if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\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,SAAsB,EAEtB;EAAA,IADA;IAAEC,MAAM,EAAEC,OAAO;IAAEC,KAAK,GAAG,UAAU;IAAEC;EAAiC,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAA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UACAzD,eAAe,CAAC0D,eAAe,EAAE;UACjC1D,eAAe,CAAC2D,wBAAwB,EAAE;UAC1C3D,eAAe,CAAC4D,qBAAqB,EAAE;QACzC;MAAC;IACH,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI9D,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,CAAC+E,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-core/runtime",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "homepage": "https://github.com/easyops-cn/next-core/tree/master/packages/runtime",
5
5
  "license": "GPL-3.0",
6
6
  "repository": {
@@ -67,5 +67,5 @@
67
67
  "@next-core/build-next-libs": "^1.0.3",
68
68
  "@next-core/test-next": "^1.0.4"
69
69
  },
70
- "gitHead": "125aede7b3cf5fdbb8040326dea72a25cdabc3aa"
70
+ "gitHead": "b468a8b859293919526fd631c3a76b1e6cf51fe6"
71
71
  }