@next-core/runtime 1.3.2 → 1.4.0

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 (52) hide show
  1. package/dist/cjs/Dialog.js +2 -3
  2. package/dist/cjs/Dialog.js.map +1 -1
  3. package/dist/cjs/Notification.js +2 -3
  4. package/dist/cjs/Notification.js.map +1 -1
  5. package/dist/cjs/createRoot.js +122 -0
  6. package/dist/cjs/createRoot.js.map +1 -0
  7. package/dist/cjs/index.js +12 -0
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/internal/Renderer.js +1 -3
  10. package/dist/cjs/internal/Renderer.js.map +1 -1
  11. package/dist/cjs/internal/RendererContext.js +13 -8
  12. package/dist/cjs/internal/RendererContext.js.map +1 -1
  13. package/dist/cjs/internal/Router.js +1 -1
  14. package/dist/cjs/internal/Router.js.map +1 -1
  15. package/dist/cjs/internal/Runtime.js +12 -4
  16. package/dist/cjs/internal/Runtime.js.map +1 -1
  17. package/dist/cjs/internal/bootstrapData.js +13 -0
  18. package/dist/cjs/internal/bootstrapData.js.map +1 -0
  19. package/dist/cjs/internal/matchStoryboard.js +6 -1
  20. package/dist/cjs/internal/matchStoryboard.js.map +1 -1
  21. package/dist/cjs/internal/secret_internals.js +6 -75
  22. package/dist/cjs/internal/secret_internals.js.map +1 -1
  23. package/dist/esm/Dialog.js +2 -2
  24. package/dist/esm/Dialog.js.map +1 -1
  25. package/dist/esm/Notification.js +2 -2
  26. package/dist/esm/Notification.js.map +1 -1
  27. package/dist/esm/createRoot.js +122 -0
  28. package/dist/esm/createRoot.js.map +1 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/internal/Renderer.js +1 -3
  32. package/dist/esm/internal/Renderer.js.map +1 -1
  33. package/dist/esm/internal/RendererContext.js +13 -8
  34. package/dist/esm/internal/RendererContext.js.map +1 -1
  35. package/dist/esm/internal/Router.js +1 -1
  36. package/dist/esm/internal/Router.js.map +1 -1
  37. package/dist/esm/internal/Runtime.js +10 -3
  38. package/dist/esm/internal/Runtime.js.map +1 -1
  39. package/dist/esm/internal/bootstrapData.js +6 -0
  40. package/dist/esm/internal/bootstrapData.js.map +1 -0
  41. package/dist/esm/internal/matchStoryboard.js +6 -1
  42. package/dist/esm/internal/matchStoryboard.js.map +1 -1
  43. package/dist/esm/internal/secret_internals.js +6 -82
  44. package/dist/esm/internal/secret_internals.js.map +1 -1
  45. package/dist/types/createRoot.d.ts +17 -0
  46. package/dist/types/index.d.ts +1 -0
  47. package/dist/types/internal/RendererContext.d.ts +6 -2
  48. package/dist/types/internal/Runtime.d.ts +2 -1
  49. package/dist/types/internal/bootstrapData.d.ts +2 -0
  50. package/dist/types/internal/matchStoryboard.d.ts +1 -0
  51. package/dist/types/internal/secret_internals.d.ts +4 -10
  52. package/package.json +3 -3
@@ -1,6 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import { i18n, initializeI18n } from "@next-core/i18n";
4
+ import { loadBricksImperatively } from "@next-core/loader";
4
5
  import moment from "moment";
5
6
  import "moment/locale/zh-cn.js";
6
7
  import { createHistory } from "../history.js";
@@ -11,8 +12,11 @@ import { loadBootstrapData } from "./loadBootstrapData.js";
11
12
  import { NS, locales } from "./i18n.js";
12
13
  import { loadNotificationService } from "../Notification.js";
13
14
  import { loadDialogService } from "../Dialog.js";
15
+ import { injectedBootstrapData } from "./bootstrapData.js";
14
16
  var runtime;
15
- var bootstrapData;
17
+
18
+ // Allow inject bootstrap data in a runtime other than Brick Next.
19
+ var bootstrapData = injectedBootstrapData;
16
20
  var router;
17
21
  export function createRuntime() {
18
22
  if (runtime) {
@@ -34,10 +38,10 @@ export class Runtime {
34
38
  bootstrap() {
35
39
  return _asyncToGenerator(function* () {
36
40
  var [, _bootstrapData] = yield Promise.all([loadCheckLogin(), loadBootstrapData()]);
41
+ bootstrapData = _bootstrapData;
37
42
  // Todo: allow configuration of notification bricks.
38
43
  loadNotificationService("shoelace.show-notification");
39
44
  loadDialogService("shoelace.show-dialog");
40
- bootstrapData = _bootstrapData;
41
45
  router = new Router(_bootstrapData.storyboards);
42
46
  yield router.bootstrap();
43
47
  })();
@@ -93,13 +97,16 @@ export class Runtime {
93
97
  return (_router5 = router) === null || _router5 === void 0 ? void 0 : _router5.getNavConfig();
94
98
  }
95
99
  }
96
- export function _internalApiSetBootstrapData(data) {
100
+ export function _test_only_setBootstrapData(data) {
97
101
  bootstrapData = data;
98
102
  }
99
103
  export function getBrickPackages() {
100
104
  var _bootstrapData$brickP, _bootstrapData8;
101
105
  return (_bootstrapData$brickP = (_bootstrapData8 = bootstrapData) === null || _bootstrapData8 === void 0 ? void 0 : _bootstrapData8.brickPackages) !== null && _bootstrapData$brickP !== void 0 ? _bootstrapData$brickP : [];
102
106
  }
107
+ export function _internalApiLoadBricks(bricks) {
108
+ return loadBricksImperatively(bricks, getBrickPackages());
109
+ }
103
110
  export function _internalApiGetRenderId() {
104
111
  var _router6;
105
112
  return (_router6 = router) === null || _router6 === void 0 ? void 0 : _router6.getRenderId();
@@ -1 +1 @@
1
- {"version":3,"file":"Runtime.js","names":["i18n","initializeI18n","moment","createHistory","matchStoryboard","Router","loadCheckLogin","loadBootstrapData","NS","locales","loadNotificationService","loadDialogService","runtime","bootstrapData","router","createRuntime","Error","locale","language","on","Runtime","getRuntime","bootstrap","_asyncToGenerator","_bootstrapData","Promise","all","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","getFeatureFlags","_bootstrapData2","_bootstrapData2$setti","_router3","_router3$getRecentApp","_router3$getRecentApp2","_router3$getRecentApp3","_objectSpread","settings","featureFlags","config","getMiscSettings","_bootstrapData3","_bootstrapData3$setti","_router4","_router4$getRecentApp","_router4$getRecentApp2","_router4$getRecentApp3","misc","getBrandSettings","_bootstrapData4","_bootstrapData4$setti","base_title","brand","getLaunchpadSettings","_bootstrapData5","_bootstrapData5$setti","columns","rows","launchpad","getDesktops","_bootstrapData$deskto","_bootstrapData6","desktops","getLaunchpadSiteMap","_bootstrapData$siteSo","_bootstrapData7","siteSort","toggleLaunchpadEffect","open","document","body","classList","toggle","applyPageTitle","pageTitle","baseTitle","title","concat","getNavConfig","_router5","_internalApiSetBootstrapData","data","getBrickPackages","_bootstrapData$brickP","_bootstrapData8","brickPackages","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData9","_internalApiGetRuntimeContext","_router7","getRuntimeContext","_internalApiGetStoryboardInBootstrapData","appId","_bootstrapData10","_bootstrapData10$stor","find","storyboard","app","id","_internalApiGetAppInBootstrapData","_internalApiGetStoryb"],"sources":["../../../src/internal/Runtime.ts"],"sourcesContent":["import type {\n RuntimeStoryboard,\n BootstrapSettings,\n FeatureFlags,\n BootstrapData,\n} from \"@next-core/types\";\nimport { i18n, initializeI18n } from \"@next-core/i18n\";\nimport moment from \"moment\";\nimport \"moment/locale/zh-cn.js\";\nimport { createHistory } from \"../history.js\";\nimport { matchStoryboard } from \"./matchStoryboard.js\";\nimport { Router } from \"./Router.js\";\nimport { loadCheckLogin } from \"./loadCheckLogin.js\";\nimport { loadBootstrapData } from \"./loadBootstrapData.js\";\nimport { NS, locales } from \"./i18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\n\nlet runtime: Runtime;\n\nlet bootstrapData: Partial<BootstrapData> | undefined;\nlet router: Router | undefined;\n\nexport function createRuntime() {\n if (runtime) {\n throw new Error(\"Cannot create multiple runtimes\");\n }\n initializeI18n(NS, locales);\n moment.locale(i18n.language);\n i18n.on(\"languageChanged\", () => {\n moment.locale(i18n.language);\n });\n createHistory();\n runtime = new Runtime();\n return runtime;\n}\n\nexport function getRuntime() {\n return runtime;\n}\n\nexport class Runtime {\n async bootstrap() {\n const [, _bootstrapData] = await Promise.all([\n loadCheckLogin(),\n loadBootstrapData(),\n ]);\n // Todo: allow configuration of notification bricks.\n loadNotificationService(\"shoelace.show-notification\");\n loadDialogService(\"shoelace.show-dialog\");\n bootstrapData = _bootstrapData;\n router = new Router(_bootstrapData.storyboards);\n await router.bootstrap();\n }\n\n getRecentApps() {\n return router?.getRecentApps() ?? {};\n }\n\n getCurrentApp() {\n return router?.getRecentApps().currentApp;\n }\n\n getFeatureFlags(): FeatureFlags {\n return {\n ...bootstrapData?.settings?.featureFlags,\n ...(\n router?.getRecentApps().currentApp?.config\n ?.settings as BootstrapSettings\n )?.featureFlags,\n \"migrate-to-brick-next-v3\": true,\n };\n }\n\n getMiscSettings() {\n return {\n ...bootstrapData?.settings?.misc,\n ...(\n router?.getRecentApps().currentApp?.config\n ?.settings as BootstrapSettings\n )?.misc,\n };\n }\n\n getBrandSettings(): Record<string, string> {\n return {\n base_title: \"DevOps 管理专家\",\n ...(bootstrapData?.settings?.brand as Record<string, string>),\n // ...(kernel.getOriginFaviconHref()\n // ? { favicon: kernel.getOriginFaviconHref() }\n // : {})\n };\n }\n\n getLaunchpadSettings() {\n return {\n columns: 7,\n rows: 4,\n ...bootstrapData?.settings?.launchpad,\n };\n }\n\n getDesktops(): unknown[] {\n return bootstrapData?.desktops ?? [];\n }\n\n getLaunchpadSiteMap(): unknown[] {\n return bootstrapData?.siteSort ?? [];\n }\n\n toggleLaunchpadEffect(open: boolean): void {\n document.body.classList.toggle(\"launchpad-open\", open);\n }\n\n applyPageTitle(pageTitle: string): void {\n const baseTitle = this.getBrandSettings().base_title;\n document.title = pageTitle ? `${pageTitle} - ${baseTitle}` : baseTitle;\n }\n\n getNavConfig() {\n return router?.getNavConfig();\n }\n}\n\nexport function _internalApiSetBootstrapData(data: Partial<BootstrapData>) {\n bootstrapData = data;\n}\n\nexport function getBrickPackages() {\n return bootstrapData?.brickPackages ?? [];\n}\n\nexport function _internalApiGetRenderId(): string | undefined {\n return router?.getRenderId();\n}\n\nexport function _internalApiMatchStoryboard(\n pathname: string\n): RuntimeStoryboard | undefined {\n return matchStoryboard(bootstrapData?.storyboards ?? [], pathname);\n}\n\nexport function _internalApiGetRuntimeContext() {\n return router?.getRuntimeContext();\n}\n\nexport function _internalApiGetStoryboardInBootstrapData(appId: string) {\n return bootstrapData?.storyboards?.find(\n (storyboard) => storyboard.app.id === appId\n );\n}\n\nexport function _internalApiGetAppInBootstrapData(appId: string) {\n return _internalApiGetStoryboardInBootstrapData(appId)?.app;\n}\n"],"mappings":";;AAMA,SAASA,IAAI,EAAEC,cAAc,QAAQ,iBAAiB;AACtD,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAO,wBAAwB;AAC/B,SAASC,aAAa,QAAQ,eAAe;AAC7C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,EAAE,EAAEC,OAAO,QAAQ,WAAW;AACvC,SAASC,uBAAuB,QAAQ,oBAAoB;AAC5D,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,IAAIC,OAAgB;AAEpB,IAAIC,aAAiD;AACrD,IAAIC,MAA0B;AAE9B,OAAO,SAASC,aAAaA,CAAA,EAAG;EAC9B,IAAIH,OAAO,EAAE;IACX,MAAM,IAAII,KAAK,CAAC,iCAAiC,CAAC;EACpD;EACAf,cAAc,CAACO,EAAE,EAAEC,OAAO,CAAC;EAC3BP,MAAM,CAACe,MAAM,CAACjB,IAAI,CAACkB,QAAQ,CAAC;EAC5BlB,IAAI,CAACmB,EAAE,CAAC,iBAAiB,EAAE,MAAM;IAC/BjB,MAAM,CAACe,MAAM,CAACjB,IAAI,CAACkB,QAAQ,CAAC;EAC9B,CAAC,CAAC;EACFf,aAAa,EAAE;EACfS,OAAO,GAAG,IAAIQ,OAAO,EAAE;EACvB,OAAOR,OAAO;AAChB;AAEA,OAAO,SAASS,UAAUA,CAAA,EAAG;EAC3B,OAA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AAA,GAAO9E,MAAM,cAAA8E,QAAA,uBAANA,QAAA,CAAQC,WAAW,EAAE;AAC9B;AAEA,OAAO,SAASC,2BAA2BA,CACzCC,QAAgB,EACe;EAAA,IAAAC,qBAAA,EAAAC,eAAA;EAC/B,OAAO7F,eAAe,EAAA4F,qBAAA,IAAAC,eAAA,GAACpF,aAAa,cAAAoF,eAAA,uBAAbA,eAAA,CAAetE,WAAW,cAAAqE,qBAAA,cAAAA,qBAAA,GAAI,EAAE,EAAED,QAAQ,CAAC;AACpE;AAEA,OAAO,SAASG,6BAA6BA,CAAA,EAAG;EAAA,IAAAC,QAAA;EAC9C,QAAAA,QAAA,GAAOrF,MAAM,cAAAqF,QAAA,uBAANA,QAAA,CAAQC,iBAAiB,EAAE;AACpC;AAEA,OAAO,SAASC,wCAAwCA,CAACC,KAAa,EAAE;EAAA,IAAAC,gBAAA,EAAAC,qBAAA;EACtE,QAAAD,gBAAA,GAAO1F,aAAa,cAAA0F,gBAAA,wBAAAC,qBAAA,GAAbD,gBAAA,CAAe5E,WAAW,cAAA6E,qBAAA,uBAA1BA,qBAAA,CAA4BC,IAAI,CACpCC,UAAU,IAAKA,UAAU,CAACC,GAAG,CAACC,EAAE,KAAKN,KAAK,CAC5C;AACH;AAEA,OAAO,SAASO,iCAAiCA,CAACP,KAAa,EAAE;EAAA,IAAAQ,qBAAA;EAC/D,QAAAA,qBAAA,GAAOT,wCAAwC,CAACC,KAAK,CAAC,cAAAQ,qBAAA,uBAA/CA,qBAAA,CAAiDH,GAAG;AAC7D"}
1
+ {"version":3,"file":"Runtime.js","names":["i18n","initializeI18n","loadBricksImperatively","moment","createHistory","matchStoryboard","Router","loadCheckLogin","loadBootstrapData","NS","locales","loadNotificationService","loadDialogService","injectedBootstrapData","runtime","bootstrapData","router","createRuntime","Error","locale","language","on","Runtime","getRuntime","bootstrap","_asyncToGenerator","_bootstrapData","Promise","all","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","getFeatureFlags","_bootstrapData2","_bootstrapData2$setti","_router3","_router3$getRecentApp","_router3$getRecentApp2","_router3$getRecentApp3","_objectSpread","settings","featureFlags","config","getMiscSettings","_bootstrapData3","_bootstrapData3$setti","_router4","_router4$getRecentApp","_router4$getRecentApp2","_router4$getRecentApp3","misc","getBrandSettings","_bootstrapData4","_bootstrapData4$setti","base_title","brand","getLaunchpadSettings","_bootstrapData5","_bootstrapData5$setti","columns","rows","launchpad","getDesktops","_bootstrapData$deskto","_bootstrapData6","desktops","getLaunchpadSiteMap","_bootstrapData$siteSo","_bootstrapData7","siteSort","toggleLaunchpadEffect","open","document","body","classList","toggle","applyPageTitle","pageTitle","baseTitle","title","concat","getNavConfig","_router5","_test_only_setBootstrapData","data","getBrickPackages","_bootstrapData$brickP","_bootstrapData8","brickPackages","_internalApiLoadBricks","bricks","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData9","_internalApiGetRuntimeContext","_router7","getRuntimeContext","_internalApiGetStoryboardInBootstrapData","appId","_bootstrapData10","_bootstrapData10$stor","find","storyboard","app","id","_internalApiGetAppInBootstrapData","_internalApiGetStoryb"],"sources":["../../../src/internal/Runtime.ts"],"sourcesContent":["import type {\n RuntimeStoryboard,\n BootstrapSettings,\n FeatureFlags,\n BootstrapData,\n} from \"@next-core/types\";\nimport { i18n, initializeI18n } from \"@next-core/i18n\";\nimport { loadBricksImperatively } from \"@next-core/loader\";\nimport moment from \"moment\";\nimport \"moment/locale/zh-cn.js\";\nimport { createHistory } from \"../history.js\";\nimport { matchStoryboard } from \"./matchStoryboard.js\";\nimport { Router } from \"./Router.js\";\nimport { loadCheckLogin } from \"./loadCheckLogin.js\";\nimport { loadBootstrapData } from \"./loadBootstrapData.js\";\nimport { NS, locales } from \"./i18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\nimport { injectedBootstrapData } from \"./bootstrapData.js\";\n\nlet runtime: Runtime;\n\n// Allow inject bootstrap data in a runtime other than Brick Next.\nlet bootstrapData = injectedBootstrapData;\nlet router: Router | undefined;\n\nexport function createRuntime() {\n if (runtime) {\n throw new Error(\"Cannot create multiple runtimes\");\n }\n initializeI18n(NS, locales);\n moment.locale(i18n.language);\n i18n.on(\"languageChanged\", () => {\n moment.locale(i18n.language);\n });\n createHistory();\n runtime = new Runtime();\n return runtime;\n}\n\nexport function getRuntime() {\n return runtime;\n}\n\nexport class Runtime {\n async bootstrap() {\n const [, _bootstrapData] = await Promise.all([\n loadCheckLogin(),\n loadBootstrapData(),\n ]);\n bootstrapData = _bootstrapData;\n // Todo: allow configuration of notification bricks.\n loadNotificationService(\"shoelace.show-notification\");\n loadDialogService(\"shoelace.show-dialog\");\n router = new Router(_bootstrapData.storyboards);\n await router.bootstrap();\n }\n\n getRecentApps() {\n return router?.getRecentApps() ?? {};\n }\n\n getCurrentApp() {\n return router?.getRecentApps().currentApp;\n }\n\n getFeatureFlags(): FeatureFlags {\n return {\n ...bootstrapData?.settings?.featureFlags,\n ...(\n router?.getRecentApps().currentApp?.config\n ?.settings as BootstrapSettings\n )?.featureFlags,\n \"migrate-to-brick-next-v3\": true,\n };\n }\n\n getMiscSettings() {\n return {\n ...bootstrapData?.settings?.misc,\n ...(\n router?.getRecentApps().currentApp?.config\n ?.settings as BootstrapSettings\n )?.misc,\n };\n }\n\n getBrandSettings(): Record<string, string> {\n return {\n base_title: \"DevOps 管理专家\",\n ...(bootstrapData?.settings?.brand as Record<string, string>),\n // ...(kernel.getOriginFaviconHref()\n // ? { favicon: kernel.getOriginFaviconHref() }\n // : {})\n };\n }\n\n getLaunchpadSettings() {\n return {\n columns: 7,\n rows: 4,\n ...bootstrapData?.settings?.launchpad,\n };\n }\n\n getDesktops(): unknown[] {\n return bootstrapData?.desktops ?? [];\n }\n\n getLaunchpadSiteMap(): unknown[] {\n return bootstrapData?.siteSort ?? [];\n }\n\n toggleLaunchpadEffect(open: boolean): void {\n document.body.classList.toggle(\"launchpad-open\", open);\n }\n\n applyPageTitle(pageTitle: string): void {\n const baseTitle = this.getBrandSettings().base_title;\n document.title = pageTitle ? `${pageTitle} - ${baseTitle}` : baseTitle;\n }\n\n getNavConfig() {\n return router?.getNavConfig();\n }\n}\n\nexport function _test_only_setBootstrapData(data: Partial<BootstrapData>) {\n bootstrapData = data;\n}\n\nexport function getBrickPackages() {\n return bootstrapData?.brickPackages ?? [];\n}\n\nexport function _internalApiLoadBricks(bricks: string[] | Set<string>) {\n return loadBricksImperatively(bricks, getBrickPackages());\n}\n\nexport function _internalApiGetRenderId(): string | undefined {\n return router?.getRenderId();\n}\n\nexport function _internalApiMatchStoryboard(\n pathname: string\n): RuntimeStoryboard | undefined {\n return matchStoryboard(bootstrapData?.storyboards ?? [], pathname);\n}\n\nexport function _internalApiGetRuntimeContext() {\n return router?.getRuntimeContext();\n}\n\nexport function _internalApiGetStoryboardInBootstrapData(appId: string) {\n return bootstrapData?.storyboards?.find(\n (storyboard) => storyboard.app.id === appId\n );\n}\n\nexport function _internalApiGetAppInBootstrapData(appId: string) {\n return _internalApiGetStoryboardInBootstrapData(appId)?.app;\n}\n"],"mappings":";;AAMA,SAASA,IAAI,EAAEC,cAAc,QAAQ,iBAAiB;AACtD,SAASC,sBAAsB,QAAQ,mBAAmB;AAC1D,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAO,wBAAwB;AAC/B,SAASC,aAAa,QAAQ,eAAe;AAC7C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,EAAE,EAAEC,OAAO,QAAQ,WAAW;AACvC,SAASC,uBAAuB,QAAQ,oBAAoB;AAC5D,SAASC,iBAAiB,QAAQ,cAAc;AAChD,SAASC,qBAAqB,QAAQ,oBAAoB;AAE1D,IAAIC,OAAgB;;AAEpB;AACA,IAAIC,aAAa,GAAGF,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AA4F,gBAAA,wBAAAC,qBAAA,GAAbD,gBAAA,CAAe9E,WAAW,cAAA+E,qBAAA,uBAA1BA,qBAAA,CAA4BC,IAAI,CACpCC,UAAU,IAAKA,UAAU,CAACC,GAAG,CAACC,EAAE,KAAKN,KAAK,CAC5C;AACH;AAEA,OAAO,SAASO,iCAAiCA,CAACP,KAAa,EAAE;EAAA,IAAAQ,qBAAA;EAC/D,QAAAA,qBAAA,GAAOT,wCAAwC,CAACC,KAAK,CAAC,cAAAQ,qBAAA,uBAA/CA,qBAAA,CAAiDH,GAAG;AAC7D"}
@@ -0,0 +1,6 @@
1
+ // Allow inject bootstrap data in a runtime other than Brick Next.
2
+ export var injectedBootstrapData =
3
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
+ // @ts-ignore
5
+ typeof BOOTSTRAP_DATA !== "undefined" ? BOOTSTRAP_DATA : undefined;
6
+ //# sourceMappingURL=bootstrapData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrapData.js","names":["injectedBootstrapData","BOOTSTRAP_DATA","undefined"],"sources":["../../../src/internal/bootstrapData.ts"],"sourcesContent":["import type { BootstrapData } from \"@next-core/types\";\n\n// Allow inject bootstrap data in a runtime other than Brick Next.\nexport const injectedBootstrapData: Partial<BootstrapData> | undefined =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n typeof BOOTSTRAP_DATA !== \"undefined\" ? BOOTSTRAP_DATA : undefined;\n"],"mappings":"AAEA;AACA,OAAO,IAAMA,qBAAyD;AACpE;AACA;AACA,OAAOC,cAAc,KAAK,WAAW,GAAGA,cAAc,GAAGC,SAAS"}
@@ -1,4 +1,5 @@
1
1
  import { orderBy } from "lodash";
2
+ import { getRuntime } from "./Runtime.js";
2
3
  export function matchStoryboard(storyboards, pathname) {
3
4
  // Put apps with longer homepage before shorter ones.
4
5
  // E.g., `/legacy/tool` will match first before `/legacy`.
@@ -20,14 +21,18 @@ export function matchStoryboard(storyboards, pathname) {
20
21
  /**
21
22
  * We say it's an outside app when at least one of the below conditions are true:
22
23
  * - target app is not found.
24
+ * - target app is not the current app.
23
25
  * - current app is non-standalone mode and target app is standalone mode.
24
26
  *
25
27
  * Note: when current app is standalone mode, other apps will not be found.
26
28
  */
27
29
  export function isOutsideApp(storyboard) {
30
+ var _getRuntime$getCurren;
28
31
  if (process.env.NODE_ENV === "test") {
29
32
  return false;
30
33
  }
31
- return !storyboard || !window.STANDALONE_MICRO_APPS && storyboard.app.standaloneMode;
34
+ return !storyboard ||
35
+ // Sometimes `storyboard.app.standaloneMode` is incorrect.
36
+ ((_getRuntime$getCurren = getRuntime().getCurrentApp()) === null || _getRuntime$getCurren === void 0 ? void 0 : _getRuntime$getCurren.id) !== storyboard.app.id && !window.STANDALONE_MICRO_APPS && storyboard.app.standaloneMode;
32
37
  }
33
38
  //# sourceMappingURL=matchStoryboard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"matchStoryboard.js","names":["orderBy","matchStoryboard","storyboards","pathname","sortedStoryboards","storyboard","_storyboard$app$homep","_storyboard$app","_storyboard$app$homep2","app","homepage","length","concat","replace","startsWith","isOutsideApp","process","env","NODE_ENV","window","STANDALONE_MICRO_APPS","standaloneMode"],"sources":["../../../src/internal/matchStoryboard.ts"],"sourcesContent":["import type { RuntimeStoryboard } from \"@next-core/types\";\nimport { orderBy } from \"lodash\";\n\nexport function matchStoryboard(\n storyboards: RuntimeStoryboard[],\n pathname: string\n): RuntimeStoryboard | undefined {\n // Put apps with longer homepage before shorter ones.\n // E.g., `/legacy/tool` will match first before `/legacy`.\n // This enables two apps with relationship of parent-child of homepage.\n const sortedStoryboards = orderBy(\n storyboards,\n (storyboard) => storyboard.app?.homepage?.length ?? 0,\n \"desc\"\n );\n for (const storyboard of sortedStoryboards) {\n const homepage = storyboard.app.homepage;\n if (typeof homepage === \"string\" && homepage[0] === \"/\") {\n if (\n homepage === \"/\"\n ? pathname === homepage\n : `${pathname.replace(/\\/+$/, \"\")}/`.startsWith(\n `${homepage.replace(/\\/+$/, \"\")}/`\n )\n ) {\n return storyboard;\n }\n }\n }\n}\n\n/**\n * We say it's an outside app when at least one of the below conditions are true:\n * - target app is not found.\n * - current app is non-standalone mode and target app is standalone mode.\n *\n * Note: when current app is standalone mode, other apps will not be found.\n */\nexport function isOutsideApp(\n storyboard: RuntimeStoryboard | undefined\n): boolean | undefined {\n if (process.env.NODE_ENV === \"test\") {\n return false;\n }\n return (\n !storyboard ||\n (!window.STANDALONE_MICRO_APPS && storyboard.app.standaloneMode)\n );\n}\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,QAAQ;AAEhC,OAAO,SAASC,eAAeA,CAC7BC,WAAgC,EAChCC,QAAgB,EACe;EAC/B;EACA;EACA;EACA,IAAMC,iBAAiB,GAAGJ,OAAO,CAC/BE,WAAW,EACVG,UAAU;IAAA,IAAAC,qBAAA,EAAAC,eAAA,EAAAC,sBAAA;IAAA,QAAAF,qBAAA,IAAAC,eAAA,GAAKF,UAAU,CAACI,GAAG,cAAAF,eAAA,wBAAAC,sBAAA,GAAdD,eAAA,CAAgBG,QAAQ,cAAAF,sBAAA,uBAAxBA,sBAAA,CAA0BG,MAAM,cAAAL,qBAAA,cAAAA,qBAAA,GAAI,CAAC;EAAA,GACrD,MAAM,CACP;EACD,KAAK,IAAMD,UAAU,IAAID,iBAAiB,EAAE;IAC1C,IAAMM,QAAQ,GAAGL,UAAU,CAACI,GAAG,CAACC,QAAQ;IACxC,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;MACvD,IACEA,QAAQ,KAAK,GAAG,GACZP,QAAQ,KAAKO,QAAQ,GACrB,GAAAE,MAAA,CAAGT,QAAQ,CAACU,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,OAAIC,UAAU,IAAAF,MAAA,CACxCF,QAAQ,CAACG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,OAChC,EACL;QACA,OAAOR,UAAU;MACnB;IACF;EACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,YAAYA,CAC1BV,UAAyC,EACpB;EACrB,IAAIW,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;IACnC,OAAO,KAAK;EACd;EACA,OACE,CAACb,UAAU,IACV,CAACc,MAAM,CAACC,qBAAqB,IAAIf,UAAU,CAACI,GAAG,CAACY,cAAe;AAEpE"}
1
+ {"version":3,"file":"matchStoryboard.js","names":["orderBy","getRuntime","matchStoryboard","storyboards","pathname","sortedStoryboards","storyboard","_storyboard$app$homep","_storyboard$app","_storyboard$app$homep2","app","homepage","length","concat","replace","startsWith","isOutsideApp","_getRuntime$getCurren","process","env","NODE_ENV","getCurrentApp","id","window","STANDALONE_MICRO_APPS","standaloneMode"],"sources":["../../../src/internal/matchStoryboard.ts"],"sourcesContent":["import type { RuntimeStoryboard } from \"@next-core/types\";\nimport { orderBy } from \"lodash\";\nimport { getRuntime } from \"./Runtime.js\";\n\nexport function matchStoryboard(\n storyboards: RuntimeStoryboard[],\n pathname: string\n): RuntimeStoryboard | undefined {\n // Put apps with longer homepage before shorter ones.\n // E.g., `/legacy/tool` will match first before `/legacy`.\n // This enables two apps with relationship of parent-child of homepage.\n const sortedStoryboards = orderBy(\n storyboards,\n (storyboard) => storyboard.app?.homepage?.length ?? 0,\n \"desc\"\n );\n for (const storyboard of sortedStoryboards) {\n const homepage = storyboard.app.homepage;\n if (typeof homepage === \"string\" && homepage[0] === \"/\") {\n if (\n homepage === \"/\"\n ? pathname === homepage\n : `${pathname.replace(/\\/+$/, \"\")}/`.startsWith(\n `${homepage.replace(/\\/+$/, \"\")}/`\n )\n ) {\n return storyboard;\n }\n }\n }\n}\n\n/**\n * We say it's an outside app when at least one of the below conditions are true:\n * - target app is not found.\n * - target app is not the current app.\n * - current app is non-standalone mode and target app is standalone mode.\n *\n * Note: when current app is standalone mode, other apps will not be found.\n */\nexport function isOutsideApp(\n storyboard: RuntimeStoryboard | undefined\n): boolean | undefined {\n if (process.env.NODE_ENV === \"test\") {\n return false;\n }\n return (\n !storyboard ||\n // Sometimes `storyboard.app.standaloneMode` is incorrect.\n (getRuntime().getCurrentApp()?.id !== storyboard.app.id &&\n !window.STANDALONE_MICRO_APPS &&\n storyboard.app.standaloneMode)\n );\n}\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,QAAQ;AAChC,SAASC,UAAU,QAAQ,cAAc;AAEzC,OAAO,SAASC,eAAeA,CAC7BC,WAAgC,EAChCC,QAAgB,EACe;EAC/B;EACA;EACA;EACA,IAAMC,iBAAiB,GAAGL,OAAO,CAC/BG,WAAW,EACVG,UAAU;IAAA,IAAAC,qBAAA,EAAAC,eAAA,EAAAC,sBAAA;IAAA,QAAAF,qBAAA,IAAAC,eAAA,GAAKF,UAAU,CAACI,GAAG,cAAAF,eAAA,wBAAAC,sBAAA,GAAdD,eAAA,CAAgBG,QAAQ,cAAAF,sBAAA,uBAAxBA,sBAAA,CAA0BG,MAAM,cAAAL,qBAAA,cAAAA,qBAAA,GAAI,CAAC;EAAA,GACrD,MAAM,CACP;EACD,KAAK,IAAMD,UAAU,IAAID,iBAAiB,EAAE;IAC1C,IAAMM,QAAQ,GAAGL,UAAU,CAACI,GAAG,CAACC,QAAQ;IACxC,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;MACvD,IACEA,QAAQ,KAAK,GAAG,GACZP,QAAQ,KAAKO,QAAQ,GACrB,GAAAE,MAAA,CAAGT,QAAQ,CAACU,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,OAAIC,UAAU,IAAAF,MAAA,CACxCF,QAAQ,CAACG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,OAChC,EACL;QACA,OAAOR,UAAU;MACnB;IACF;EACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,YAAYA,CAC1BV,UAAyC,EACpB;EAAA,IAAAW,qBAAA;EACrB,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;IACnC,OAAO,KAAK;EACd;EACA,OACE,CAACd,UAAU;EACX;EACC,EAAAW,qBAAA,GAAAhB,UAAU,EAAE,CAACoB,aAAa,EAAE,cAAAJ,qBAAA,uBAA5BA,qBAAA,CAA8BK,EAAE,MAAKhB,UAAU,CAACI,GAAG,CAACY,EAAE,IACrD,CAACC,MAAM,CAACC,qBAAqB,IAC7BlB,UAAU,CAACI,GAAG,CAACe,cAAe;AAEpC"}
@@ -1,13 +1,11 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import { flushStableLoadBricks, loadBricksImperatively } from "@next-core/loader";
3
+ import { flushStableLoadBricks } from "@next-core/loader";
4
4
  import { pick } from "lodash";
5
- import { _internalApiGetRuntimeContext, _internalApiGetStoryboardInBootstrapData, _internalApiSetBootstrapData, getBrickPackages } from "./Runtime.js";
6
- import { renderBrick, renderBricks } from "./Renderer.js";
5
+ import { _internalApiGetRuntimeContext, _internalApiGetStoryboardInBootstrapData, _internalApiLoadBricks } from "./Runtime.js";
6
+ import { renderBrick } from "./Renderer.js";
7
7
  import { RendererContext } from "./RendererContext.js";
8
8
  import { mountTree, unmountTree } from "./mount.js";
9
- import { httpErrorToString } from "../handleHttpError.js";
10
- import { applyMode, applyTheme, setMode, setTheme } from "../themeAndMode.js";
11
9
  import { RenderTag } from "./enums.js";
12
10
  import { computeRealValue } from "./compute/computeRealValue.js";
13
11
  import { isStrictMode, warnAboutStrictMode } from "../isStrictMode.js";
@@ -28,7 +26,7 @@ function _renderUseBrick() {
28
26
  tplStateStoreScope
29
27
  });
30
28
  (_runtimeContext$tplSt = runtimeContext.tplStateStoreMap) !== null && _runtimeContext$tplSt !== void 0 ? _runtimeContext$tplSt : runtimeContext.tplStateStoreMap = new Map();
31
- var rendererContext = new RendererContext("useBrick");
29
+ var rendererContext = new RendererContext("fragment");
32
30
  var renderRoot = {
33
31
  tag: RenderTag.ROOT,
34
32
  // Will set during `mountUseBrick`
@@ -93,81 +91,11 @@ export function unmountUseBrick(_ref2, mountResult) {
93
91
  rendererContext.dispatchOnUnmount();
94
92
  rendererContext.dispose();
95
93
  }
96
- var _rendererContext;
97
- export function initializePreviewBootstrap(bootstrapData) {
98
- _internalApiSetBootstrapData(bootstrapData);
94
+ export function initializePlayground() {
99
95
  // Todo: allow configuration of notification bricks.
100
96
  loadNotificationService("shoelace.show-notification");
101
97
  loadDialogService("shoelace.show-dialog");
102
98
  }
103
- export function renderPreviewBricks(_x3, _x4) {
104
- return _renderPreviewBricks.apply(this, arguments);
105
- }
106
- function _renderPreviewBricks() {
107
- _renderPreviewBricks = _asyncToGenerator(function* (bricks, mountPoints) {
108
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
109
- var runtimeContext = {
110
- pendingPermissionsPreCheck: [],
111
- tplStateStoreMap: new Map()
112
- };
113
- var previousRendererContext = _rendererContext;
114
- var rendererContext = _rendererContext = new RendererContext("router");
115
- var renderRoot = {
116
- tag: RenderTag.ROOT,
117
- container: mountPoints.main,
118
- createPortal: mountPoints.portal
119
- };
120
- var failed = false;
121
- var output;
122
- try {
123
- output = yield renderBricks(renderRoot, bricks, runtimeContext, rendererContext);
124
- output.blockingList.push(...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck);
125
- flushStableLoadBricks();
126
- yield Promise.all(output.blockingList);
127
- } catch (error) {
128
- failed = true;
129
- output = {
130
- node: {
131
- tag: RenderTag.BRICK,
132
- type: "div",
133
- properties: {
134
- textContent: httpErrorToString(error)
135
- },
136
- return: renderRoot,
137
- runtimeContext: null
138
- },
139
- blockingList: [],
140
- menuRequests: []
141
- };
142
- }
143
- renderRoot.child = output.node;
144
- previousRendererContext === null || previousRendererContext === void 0 ? void 0 : previousRendererContext.dispose();
145
- unmountTree(mountPoints.main);
146
- unmountTree(mountPoints.portal);
147
- if (options.sandbox) {
148
- var _options$theme;
149
- setTheme((_options$theme = options.theme) !== null && _options$theme !== void 0 ? _options$theme : "light");
150
- setMode("default");
151
- if (!failed) {
152
- rendererContext.dispatchBeforePageLoad();
153
- }
154
- applyTheme();
155
- applyMode();
156
- }
157
- mountTree(renderRoot);
158
- if (options.sandbox) {
159
- window.scrollTo(0, 0);
160
- }
161
- if (!failed) {
162
- rendererContext.dispatchPageLoad();
163
- // rendererContext.dispatchAnchorLoad();
164
- rendererContext.dispatchOnMount();
165
- rendererContext.initializeScrollIntoView();
166
- rendererContext.initializeMediaChange();
167
- }
168
- });
169
- return _renderPreviewBricks.apply(this, arguments);
170
- }
171
99
  export function legacyDoTransform(data, to, options) {
172
100
  if (options) {
173
101
  throw new Error("Legacy doTransform does not support options in v3");
@@ -178,11 +106,7 @@ export function legacyDoTransform(data, to, options) {
178
106
  noInject: true
179
107
  });
180
108
  }
181
-
182
- // istanbul ignore next
183
- export function loadBricks(bricks) {
184
- return loadBricksImperatively(bricks, getBrickPackages());
185
- }
109
+ export var loadBricks = _internalApiLoadBricks;
186
110
  export function updateStoryboard(appId, storyboardPatch) {
187
111
  var storyboard = _internalApiGetStoryboardInBootstrapData(appId);
188
112
  Object.assign(storyboard, _objectSpread(_objectSpread({}, storyboardPatch), {}, {
@@ -1 +1 @@
1
- {"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","loadBricksImperatively","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","_internalApiSetBootstrapData","getBrickPackages","renderBrick","renderBricks","RendererContext","mountTree","unmountTree","httpErrorToString","applyMode","applyTheme","setMode","setTheme","RenderTag","computeRealValue","isStrictMode","warnAboutStrictMode","customTemplates","registerAppI18n","loadNotificationService","loadDialogService","renderUseBrick","_x","_x2","_renderUseBrick","apply","arguments","_asyncToGenerator","useBrick","data","_runtimeContext$tplSt","_output$node","tplStateStoreScope","runtimeContext","_objectSpread","pendingPermissionsPreCheck","tplStateStoreMap","Map","rendererContext","renderRoot","tag","ROOT","createPortal","transform","strict","output","properties","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","_ref","element","portalRoot","document","querySelector","createElement","appendChild","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","_ref2","mountResult","remove","dispatchOnUnmount","dispose","_rendererContext","initializePreviewBootstrap","bootstrapData","renderPreviewBricks","_x3","_x4","_renderPreviewBricks","bricks","mountPoints","options","length","undefined","previousRendererContext","container","main","failed","push","values","error","BRICK","textContent","return","menuRequests","sandbox","_options$theme","theme","dispatchBeforePageLoad","window","scrollTo","dispatchPageLoad","legacyDoTransform","to","noInject","loadBricks","updateStoryboard","appId","storyboardPatch","storyboard","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","updateStoryboardByRoute","newRoute","match","getKey","route","concat","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","define","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BootstrapData,\n BrickConf,\n CustomTemplate,\n RouteConf,\n SiteTheme,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport {\n flushStableLoadBricks,\n loadBricksImperatively,\n} from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n _internalApiSetBootstrapData,\n getBrickPackages,\n} from \"./Runtime.js\";\nimport { RenderOutput, renderBrick, renderBricks } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { httpErrorToString } from \"../handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"../themeAndMode.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"useBrick\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...tplStateStoreScope.map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\nlet _rendererContext: RendererContext;\n\nexport function initializePreviewBootstrap(\n bootstrapData: Partial<BootstrapData>\n) {\n _internalApiSetBootstrapData(bootstrapData);\n // Todo: allow configuration of notification bricks.\n loadNotificationService(\"shoelace.show-notification\");\n loadDialogService(\"shoelace.show-dialog\");\n}\n\nexport async function renderPreviewBricks(\n bricks: BrickConf[],\n mountPoints: {\n main: HTMLElement;\n portal: HTMLElement;\n },\n options: {\n sandbox?: boolean;\n theme?: SiteTheme;\n } = {}\n) {\n const runtimeContext = {\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = _rendererContext;\n const rendererContext = (_rendererContext = new RendererContext(\"router\"));\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container: mountPoints.main,\n createPortal: mountPoints.portal,\n };\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 output.blockingList.push(\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck\n );\n\n flushStableLoadBricks();\n\n await Promise.all(output.blockingList);\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?.dispose();\n unmountTree(mountPoints.main);\n unmountTree(mountPoints.portal);\n\n if (options.sandbox) {\n setTheme(options.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 (options.sandbox) {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n}\n\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\n// istanbul ignore next\nexport function loadBricks(bricks: string[] | Set<string>) {\n return loadBricksImperatively(bricks, getBrickPackages());\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n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a,MAAA,CAC0CqB,WAAW,CAACE,SAAS,GACpE,CAAAD,mBAAA,GAAAD,WAAW,CAAC9D,MAAM,cAAA+D,mBAAA,eAAlBA,mBAAA,CAAoB5D,MAAM,GAAG2D,WAAW,CAAC9D,MAAM,GAAG,CAAC;IAAE4D,KAAK,EAAE;EAAO,CAAC,CAAC,CACtE;AACH;AAEA,OAAO,IAAMK,4BAA4B,GAAGJ,yBAAyB;AAErE,SAASF,sBAAsBA,CAC7B/B,KAAa,EACbc,IAAY,EACZ1C,MAAmB,EACnB;EACA,IAAM;IAAE6C;EAAO,CAAC,GAAGhI,wCAAwC,CAAC+G,KAAK,CAAE;EACnE,IAAMsC,iBAAiB,GAAGrB,MAAM,CAACsB,SAAS,CAAE3B,KAAK,IAAKA,KAAK,CAACE,IAAI,KAAKA,IAAI,CAAC;EAC1E,IAAM0B,eAA0B,GAAG;IACjC1B,IAAI;IACJ1C,MAAM;IACNqE,IAAI,EAAE,KAAK;IACX1B,KAAK,EAAE;EACT,CAAC;EACD,IAAIuB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BrB,MAAM,CAACG,OAAO,CAACoB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLvB,MAAM,CAACyB,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
1
+ {"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","_internalApiLoadBricks","renderBrick","RendererContext","mountTree","unmountTree","RenderTag","computeRealValue","isStrictMode","warnAboutStrictMode","customTemplates","registerAppI18n","loadNotificationService","loadDialogService","renderUseBrick","_x","_x2","_renderUseBrick","apply","arguments","_asyncToGenerator","useBrick","data","_runtimeContext$tplSt","_output$node","tplStateStoreScope","runtimeContext","_objectSpread","pendingPermissionsPreCheck","tplStateStoreMap","Map","rendererContext","renderRoot","tag","ROOT","createPortal","transform","strict","output","properties","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","_ref","element","portalRoot","document","querySelector","createElement","appendChild","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","_ref2","mountResult","remove","dispatchOnUnmount","dispose","initializePlayground","legacyDoTransform","to","options","noInject","loadBricks","updateStoryboard","appId","storyboardPatch","storyboard","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","updateStoryboardByRoute","newRoute","match","getKey","route","concat","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n _internalApiLoadBricks,\n} from \"./Runtime.js\";\nimport { renderBrick } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"fragment\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...tplStateStoreScope.map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\nexport function initializePlayground() {\n // Todo: allow configuration of notification bricks.\n loadNotificationService(\"shoelace.show-notification\");\n loadDialogService(\"shoelace.show-dialog\");\n}\n\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\nexport const loadBricks = _internalApiLoadBricks;\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;AAOA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SACEC,6BAA6B,EAC7BC,wCAAwC,EACxCC,sBAAsB,QACjB,cAAc;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,eAAe,QAAQ,sBAAsB;AAGtD,SAASC,SAAS,EAAEC,WAAW,QAAQ,YAAY;AACnD,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,oBAAoB;AACtE,SAASC,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iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
@@ -0,0 +1,17 @@
1
+ import type { BrickConf, SiteTheme } from "@next-core/types";
2
+ export interface CreateRootOptions {
3
+ portal?: HTMLElement;
4
+ /**
5
+ * Defaults to "fragment"
6
+ * - page: render as whole page, triggering page life cycles.
7
+ * - fragment: render as fragment, not triggering page life cycles.
8
+ */
9
+ scope?: "page" | "fragment";
10
+ }
11
+ export interface RenderOptions {
12
+ theme?: SiteTheme;
13
+ }
14
+ export declare function unstable_createRoot(container: HTMLElement, { portal: _portal, scope }?: CreateRootOptions): {
15
+ render(brick: BrickConf | BrickConf[], { theme }?: RenderOptions): Promise<void>;
16
+ unmount(): void;
17
+ };
@@ -6,6 +6,7 @@ export * from "./getBasePath.js";
6
6
  export * from "./getPageInfo.js";
7
7
  export * from "./handleHttpError.js";
8
8
  export * from "./history.js";
9
+ export * from "./createRoot.js";
9
10
  export { createRuntime, getRuntime } from "./internal/Runtime.js";
10
11
  import * as __secret_internals from "./internal/secret_internals.js";
11
12
  export { __secret_internals };
@@ -4,8 +4,12 @@ import { NextLocation } from "../history.js";
4
4
  import type { RenderBrick, RenderNode } from "./interfaces.js";
5
5
  export declare class RendererContext {
6
6
  #private;
7
- readonly type: "router" | "useBrick";
8
- constructor(type: "router" | "useBrick");
7
+ /**
8
+ * - page: render as whole page, triggering page life cycles.
9
+ * - fragment: render as fragment, not triggering page life cycles.
10
+ */
11
+ readonly scope: "page" | "fragment";
12
+ constructor(scope: "page" | "fragment");
9
13
  registerBrickLifeCycle(brick: RenderBrick, lifeCycle: BrickLifeCycle | UseBrickLifeCycle | undefined): void;
10
14
  memoizeControlNode(slotId: string | undefined, key: number, node: RenderBrick | undefined, returnNode: RenderNode): void;
11
15
  rerenderControlNode(slotId: string | undefined, key: number, node: RenderBrick | undefined, returnNode: RenderNode): void;
@@ -23,8 +23,9 @@ export declare class Runtime {
23
23
  breadcrumb?: import("@next-core/types").BreadcrumbItemConf[] | undefined;
24
24
  } | undefined;
25
25
  }
26
- export declare function _internalApiSetBootstrapData(data: Partial<BootstrapData>): void;
26
+ export declare function _test_only_setBootstrapData(data: Partial<BootstrapData>): void;
27
27
  export declare function getBrickPackages(): import("@next-core/types").BrickPackage[];
28
+ export declare function _internalApiLoadBricks(bricks: string[] | Set<string>): Promise<void>;
28
29
  export declare function _internalApiGetRenderId(): string | undefined;
29
30
  export declare function _internalApiMatchStoryboard(pathname: string): RuntimeStoryboard | undefined;
30
31
  export declare function _internalApiGetRuntimeContext(): import("./interfaces.js").RuntimeContext | undefined;
@@ -0,0 +1,2 @@
1
+ import type { BootstrapData } from "@next-core/types";
2
+ export declare const injectedBootstrapData: Partial<BootstrapData> | undefined;
@@ -3,6 +3,7 @@ export declare function matchStoryboard(storyboards: RuntimeStoryboard[], pathna
3
3
  /**
4
4
  * We say it's an outside app when at least one of the below conditions are true:
5
5
  * - target app is not found.
6
+ * - target app is not the current app.
6
7
  * - current app is non-standalone mode and target app is standalone mode.
7
8
  *
8
9
  * Note: when current app is standalone mode, other apps will not be found.
@@ -1,4 +1,5 @@
1
- import type { BootstrapData, BrickConf, CustomTemplate, RouteConf, SiteTheme, Storyboard, UseSingleBrickConf } from "@next-core/types";
1
+ import type { BrickConf, CustomTemplate, RouteConf, Storyboard, UseSingleBrickConf } from "@next-core/types";
2
+ import { _internalApiLoadBricks } from "./Runtime.js";
2
3
  import { RendererContext } from "./RendererContext.js";
3
4
  import type { RenderRoot } from "./interfaces.js";
4
5
  export interface RenderUseBrickResult {
@@ -12,16 +13,9 @@ export interface MountUseBrickResult {
12
13
  }
13
14
  export declare function mountUseBrick({ renderRoot, rendererContext }: RenderUseBrickResult, element: HTMLElement): MountUseBrickResult;
14
15
  export declare function unmountUseBrick({ rendererContext }: RenderUseBrickResult, mountResult: MountUseBrickResult): void;
15
- export declare function initializePreviewBootstrap(bootstrapData: Partial<BootstrapData>): void;
16
- export declare function renderPreviewBricks(bricks: BrickConf[], mountPoints: {
17
- main: HTMLElement;
18
- portal: HTMLElement;
19
- }, options?: {
20
- sandbox?: boolean;
21
- theme?: SiteTheme;
22
- }): Promise<void>;
16
+ export declare function initializePlayground(): void;
23
17
  export declare function legacyDoTransform(data: unknown, to: unknown, options?: unknown): unknown;
24
- export declare function loadBricks(bricks: string[] | Set<string>): Promise<void>;
18
+ export declare const loadBricks: typeof _internalApiLoadBricks;
25
19
  export declare function updateStoryboard(appId: string, storyboardPatch: Partial<Storyboard>): void;
26
20
  export declare function updateStoryboardByRoute(appId: string, newRoute: RouteConf): void;
27
21
  export declare function updateStoryboardByTemplate(appId: string, newTemplate: CustomTemplate, settings: unknown): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-core/runtime",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "homepage": "https://github.com/easyops-cn/next-core/tree/master/packages/runtime",
5
5
  "license": "GPL-3.0",
6
6
  "repository": {
@@ -51,7 +51,7 @@
51
51
  "@next-core/http": "^1.0.4",
52
52
  "@next-core/i18n": "^1.0.8",
53
53
  "@next-core/inject": "^1.0.6",
54
- "@next-core/loader": "^1.2.1",
54
+ "@next-core/loader": "^1.3.0",
55
55
  "@next-core/supply": "^2.0.4",
56
56
  "@next-core/types": "^1.1.0",
57
57
  "@next-core/utils": "^1.2.3",
@@ -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": "84c3c2f1f0005925fec82076bf7327e6e5e4e50e"
70
+ "gitHead": "473593617612f0f872662229410159024deff7c1"
71
71
  }