@next-core/runtime 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createRoot.js +39 -3
- package/dist/cjs/createRoot.js.map +1 -1
- package/dist/cjs/internal/Runtime.js +2 -2
- package/dist/cjs/internal/Runtime.js.map +1 -1
- package/dist/cjs/internal/registerAppI18n.js +7 -0
- package/dist/cjs/internal/registerAppI18n.js.map +1 -1
- package/dist/cjs/internal/secret_internals.js +2 -1
- package/dist/cjs/internal/secret_internals.js.map +1 -1
- package/dist/esm/createRoot.js +39 -3
- package/dist/esm/createRoot.js.map +1 -1
- package/dist/esm/internal/Runtime.js +1 -1
- package/dist/esm/internal/Runtime.js.map +1 -1
- package/dist/esm/internal/registerAppI18n.js +7 -0
- package/dist/esm/internal/registerAppI18n.js.map +1 -1
- package/dist/esm/internal/secret_internals.js +3 -2
- package/dist/esm/internal/secret_internals.js.map +1 -1
- package/dist/types/createRoot.d.ts +9 -5
- package/dist/types/internal/Runtime.d.ts +1 -1
- package/dist/types/internal/registerAppI18n.d.ts +2 -2
- package/dist/types/internal/secret_internals.d.ts +2 -2
- package/package.json +2 -2
package/dist/cjs/createRoot.js
CHANGED
|
@@ -7,10 +7,14 @@ exports.unstable_createRoot = unstable_createRoot;
|
|
|
7
7
|
var _loader = require("@next-core/loader");
|
|
8
8
|
var _Renderer = require("./internal/Renderer.js");
|
|
9
9
|
var _RendererContext = require("./internal/RendererContext.js");
|
|
10
|
+
var _DataStore = require("./internal/data/DataStore.js");
|
|
10
11
|
var _mount = require("./internal/mount.js");
|
|
11
12
|
var _handleHttpError = require("./handleHttpError.js");
|
|
12
13
|
var _themeAndMode = require("./themeAndMode.js");
|
|
13
14
|
var _enums = require("./internal/enums.js");
|
|
15
|
+
var _StoryboardFunctions = require("./internal/compute/StoryboardFunctions.js");
|
|
16
|
+
var _registerAppI18n = require("./internal/registerAppI18n.js");
|
|
17
|
+
var _registerCustomTemplates = require("./internal/registerCustomTemplates.js");
|
|
14
18
|
function unstable_createRoot(container, {
|
|
15
19
|
portal: _portal,
|
|
16
20
|
scope = "fragment"
|
|
@@ -31,15 +35,21 @@ function unstable_createRoot(container, {
|
|
|
31
35
|
}
|
|
32
36
|
let unmounted = false;
|
|
33
37
|
let rendererContext;
|
|
38
|
+
let clearI18nBundles;
|
|
34
39
|
return {
|
|
35
40
|
async render(brick, {
|
|
36
|
-
theme
|
|
41
|
+
theme,
|
|
42
|
+
context,
|
|
43
|
+
functions,
|
|
44
|
+
templates,
|
|
45
|
+
i18n: i18nData
|
|
37
46
|
} = {}) {
|
|
38
47
|
if (unmounted) {
|
|
39
48
|
throw new Error("The root is unmounted and cannot be rendered any more");
|
|
40
49
|
}
|
|
41
50
|
const bricks = [].concat(brick);
|
|
42
51
|
const runtimeContext = {
|
|
52
|
+
ctxStore: new _DataStore.DataStore("CTX"),
|
|
43
53
|
pendingPermissionsPreCheck: [],
|
|
44
54
|
tplStateStoreMap: new Map()
|
|
45
55
|
};
|
|
@@ -50,13 +60,38 @@ function unstable_createRoot(container, {
|
|
|
50
60
|
container,
|
|
51
61
|
createPortal
|
|
52
62
|
};
|
|
63
|
+
if (scope === "page") {
|
|
64
|
+
var _clearI18nBundles;
|
|
65
|
+
const demoApp = {
|
|
66
|
+
id: "demo",
|
|
67
|
+
homepage: "/demo"
|
|
68
|
+
};
|
|
69
|
+
runtimeContext.app = demoApp;
|
|
70
|
+
const demoStoryboard = {
|
|
71
|
+
app: demoApp,
|
|
72
|
+
meta: {
|
|
73
|
+
i18n: i18nData,
|
|
74
|
+
customTemplates: templates
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Register i18n.
|
|
79
|
+
(_clearI18nBundles = clearI18nBundles) === null || _clearI18nBundles === void 0 ? void 0 : _clearI18nBundles();
|
|
80
|
+
clearI18nBundles = (0, _registerAppI18n.registerAppI18n)(demoStoryboard);
|
|
81
|
+
|
|
82
|
+
// Register custom templates.
|
|
83
|
+
(0, _registerCustomTemplates.registerCustomTemplates)(demoStoryboard);
|
|
84
|
+
|
|
85
|
+
// Register functions.
|
|
86
|
+
(0, _StoryboardFunctions.registerStoryboardFunctions)(functions, demoApp);
|
|
87
|
+
}
|
|
88
|
+
runtimeContext.ctxStore.define(context, runtimeContext);
|
|
53
89
|
let failed = false;
|
|
54
90
|
let output;
|
|
55
91
|
try {
|
|
56
92
|
output = await (0, _Renderer.renderBricks)(renderRoot, bricks, runtimeContext, rendererContext);
|
|
57
|
-
output.blockingList.push(...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck);
|
|
58
93
|
(0, _loader.flushStableLoadBricks)();
|
|
59
|
-
await Promise.all(output.blockingList);
|
|
94
|
+
await Promise.all([...output.blockingList, runtimeContext.ctxStore.waitForAll(), ...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
|
|
60
95
|
} catch (error) {
|
|
61
96
|
failed = true;
|
|
62
97
|
output = {
|
|
@@ -74,6 +109,7 @@ function unstable_createRoot(container, {
|
|
|
74
109
|
};
|
|
75
110
|
}
|
|
76
111
|
renderRoot.child = output.node;
|
|
112
|
+
previousRendererContext === null || previousRendererContext === void 0 ? void 0 : previousRendererContext.dispatchOnUnmount();
|
|
77
113
|
previousRendererContext === null || previousRendererContext === void 0 ? void 0 : previousRendererContext.dispose();
|
|
78
114
|
(0, _mount.unmountTree)(container);
|
|
79
115
|
if (portal) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoot.js","names":["_loader","require","_Renderer","_RendererContext","_mount","_handleHttpError","_themeAndMode","_enums","unstable_createRoot","container","portal","_portal","scope","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","render","brick","theme","Error","bricks","concat","runtimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","failed","output","renderBricks","blockingList","push","values","map","store","waitForAll","flushStableLoadBricks","Promise","all","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type { BrickConf, SiteTheme } from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport type { 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\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\"\n * - page: render as whole page, triggering page life cycles.\n * - fragment: render as fragment, not triggering page life cycles.\n */\n scope?: \"page\" | \"fragment\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement,\n { portal: _portal, scope = \"fragment\" }: 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\n return {\n async render(\n brick: BrickConf | BrickConf[],\n { theme }: 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 pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope);\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\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(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":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;A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KAAK,GAAI,OAAO,CAAC;QAC1B,IAAAuC,qBAAO,EAAC,SAAS,CAAC;QAElB,IAAI,CAACzB,MAAM,EAAE;UACXjB,eAAe,CAAC2C,sBAAsB,EAAE;QAC1C;QAEA,IAAAC,wBAAU,GAAE;QACZ,IAAAC,uBAAS,GAAE;MACb;MAEA,IAAAC,gBAAS,EAACjC,UAAU,CAAC;MAErB,IAAIxB,KAAK,KAAK,MAAM,EAAE;QACpB0D,MAAM,CAACC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;MACvB;MAEA,IAAI,CAAC/B,MAAM,EAAE;QACX,IAAI5B,KAAK,KAAK,MAAM,EAAE;UACpBW,eAAe,CAACiD,gBAAgB,EAAE;UAClC;QACF;;QACAjD,eAAe,CAACkD,eAAe,EAAE;QACjClD,eAAe,CAACmD,wBAAwB,EAAE;QAC1CnD,eAAe,CAACoD,qBAAqB,EAAE;MACzC;IACF,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAItD,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAAyC,kBAAW,EAACtD,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAAqD,kBAAW,EAACrD,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACmE,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","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\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\" }: 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);\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;AAoBO,SAASW,mBAAmBA,CACjCC,SAAsB,EACtB;EAAEC,MAAM,EAAEC,OAA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CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI1E,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAA6D,kBAAW,EAAC1E,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAAyE,kBAAW,EAACzE,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACuF,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
|
|
@@ -11,7 +11,7 @@ exports._internalApiGetRuntimeContext = _internalApiGetRuntimeContext;
|
|
|
11
11
|
exports._internalApiGetStoryboardInBootstrapData = _internalApiGetStoryboardInBootstrapData;
|
|
12
12
|
exports._internalApiLoadBricks = _internalApiLoadBricks;
|
|
13
13
|
exports._internalApiMatchStoryboard = _internalApiMatchStoryboard;
|
|
14
|
-
exports.
|
|
14
|
+
exports._internalApiSetBootstrapData = _internalApiSetBootstrapData;
|
|
15
15
|
exports.createRuntime = createRuntime;
|
|
16
16
|
exports.getBrickPackages = getBrickPackages;
|
|
17
17
|
exports.getRuntime = getRuntime;
|
|
@@ -122,7 +122,7 @@ class Runtime {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
exports.Runtime = Runtime;
|
|
125
|
-
function
|
|
125
|
+
function _internalApiSetBootstrapData(data) {
|
|
126
126
|
bootstrapData = data;
|
|
127
127
|
}
|
|
128
128
|
function getBrickPackages() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.js","names":["_i18n","require","_loader","_moment","_interopRequireDefault","_history","_matchStoryboard","_Router","_loadCheckLogin","_loadBootstrapData","_i18n2","_Notification","_Dialog","_bootstrapData11","runtime","bootstrapData","injectedBootstrapData","router","createRuntime","Error","initializeI18n","NS","locales","moment","locale","i18n","language","on","createHistory","Runtime","getRuntime","bootstrap","_bootstrapData","Promise","all","loadCheckLogin","loadBootstrapData","loadNotificationService","loadDialogService","Router","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","getFeatureFlags","_bootstrapData2","_bootstrapData2$setti","_router3","_router3$getRecentApp","_router3$getRecentApp2","_router3$getRecentApp3","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","getNavConfig","_router5","exports","_test_only_setBootstrapData","data","getBrickPackages","_bootstrapData$brickP","_bootstrapData8","brickPackages","_internalApiLoadBricks","bricks","loadBricksImperatively","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData9","matchStoryboard","_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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,sBAAA,CAAAH,OAAA;AACAA,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AACA,IAAAY,gBAAA,GAAAZ,OAAA;AAEA,IAAIa,OAAgB;;AAEpB;AACA,IA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,GAAOxG,aAAa,cAAAwG,gBAAA,wBAAAC,qBAAA,GAAbD,gBAAA,CAAe/E,WAAW,cAAAgF,qBAAA,uBAA1BA,qBAAA,CAA4BC,IAAI,CACpCC,UAAU,IAAKA,UAAU,CAACC,GAAG,CAACC,EAAE,KAAKN,KAAK,CAC5C;AACH;AAEO,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","require","_loader","_moment","_interopRequireDefault","_history","_matchStoryboard","_Router","_loadCheckLogin","_loadBootstrapData","_i18n2","_Notification","_Dialog","_bootstrapData11","runtime","bootstrapData","injectedBootstrapData","router","createRuntime","Error","initializeI18n","NS","locales","moment","locale","i18n","language","on","createHistory","Runtime","getRuntime","bootstrap","_bootstrapData","Promise","all","loadCheckLogin","loadBootstrapData","loadNotificationService","loadDialogService","Router","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","getFeatureFlags","_bootstrapData2","_bootstrapData2$setti","_router3","_router3$getRecentApp","_router3$getRecentApp2","_router3$getRecentApp3","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","getNavConfig","_router5","exports","_internalApiSetBootstrapData","data","getBrickPackages","_bootstrapData$brickP","_bootstrapData8","brickPackages","_internalApiLoadBricks","bricks","loadBricksImperatively","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData9","matchStoryboard","_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 _internalApiSetBootstrapData(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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,sBAAA,CAAAH,OAAA;AACAA,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AACA,IAAAY,gBAAA,GAAAZ,OAAA;AAEA,IAAIa,OAAgB;;AAEpB;AACA,IAAIC,aAAa,GAAGC,sCAAqB;AACzC,IAAIC,MAA0B;AAEvB,SAASC,aAAaA,CAAA,EAAG;EAC9B,IAAIJ,OAAO,EAAE;IACX,MAAM,IAAIK,KAAK,CAAC,iCAAiC,CAAC;EACpD;EACA,IAAAC,oBAAc,EAACC,SAAE,EAAEC,cAAO,CAAC;EAC3BC,eAAM,CAACC,MAAM,CAACC,UAAI,CAACC,QAAQ,CAAC;EAC5BD,UAAI,CAACE,EAAE,CAAC,iBAAiB,EAAE,MAAM;IAC/BJ,eAAM,CAACC,MAAM,CAACC,UAAI,CAACC,QAAQ,CAAC;EAC9B,CAAC,CAAC;EACF,IAAAE,sBAAa,GAAE;EACfd,OAAO,GAAG,IAAIe,OAAO,EAAE;EACvB,OAAOf,OAAO;AAChB;AAEO,SAASgB,UAAUA,CAAA,EAAG;EAC3B,OAAOhB,OAAO;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AAC,8BAAsB,EAACD,MAAM,EAAEL,gBAAgB,EAAE,CAAC;AAC3D;AAEO,SAASO,uBAAuBA,CAAA,EAAuB;EAAA,IAAAC,QAAA;EAC5D,QAAAA,QAAA,GAAO1F,MAAM,cAAA0F,QAAA,uBAANA,QAAA,CAAQC,WAAW,EAAE;AAC9B;AAEO,SAASC,2BAA2BA,CACzCC,QAAgB,EACe;EAAA,IAAAC,qBAAA,EAAAC,eAAA;EAC/B,OAAO,IAAAC,gCAAe,GAAAF,qBAAA,IAAAC,eAAA,GAACjG,aAAa,cAAAiG,eAAA,uBAAbA,eAAA,CAAexE,WAAW,cAAAuE,qBAAA,cAAAA,qBAAA,GAAI,EAAE,EAAED,QAAQ,CAAC;AACpE;AAEO,SAASI,6BAA6BA,CAAA,EAAG;EAAA,IAAAC,QAAA;EAC9C,QAAAA,QAAA,GAAOlG,MAAM,cAAAkG,QAAA,uBAANA,QAAA,CAAQC,iBAAiB,EAAE;AACpC;AAEO,SAASC,wCAAwCA,CAACC,KAAa,EAAE;EAAA,IAAAC,gBAAA,EAAAC,qBAAA;EACtE,QAAAD,gBAAA,GAAOxG,aAAa,cAAAwG,gBAAA,wBAAAC,qBAAA,GAAbD,gBAAA,CAAe/E,WAAW,cAAAgF,qBAAA,uBAA1BA,qBAAA,CAA4BC,IAAI,CACpCC,UAAU,IAAKA,UAAU,CAACC,GAAG,CAACC,EAAE,KAAKN,KAAK,CAC5C;AACH;AAEO,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"}
|
|
@@ -14,9 +14,16 @@ function registerAppI18n({
|
|
|
14
14
|
// Prefix to avoid conflict between brick package's i18n namespace.
|
|
15
15
|
const i18nNamespace = getI18nNamespace("app", app.id);
|
|
16
16
|
// Support any language in `meta.i18n`.
|
|
17
|
+
const languages = [];
|
|
17
18
|
Object.entries(meta.i18n).forEach(([lang, resources]) => {
|
|
18
19
|
_i18n.i18n.addResourceBundle(lang, i18nNamespace, resources);
|
|
20
|
+
languages.push(lang);
|
|
19
21
|
});
|
|
22
|
+
return () => {
|
|
23
|
+
for (const lang of languages) {
|
|
24
|
+
_i18n.i18n.removeResourceBundle(lang, i18nNamespace);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
function getI18nNamespace(type, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerAppI18n.js","names":["_i18n","require","registerAppI18n","app","meta","i18n","i18nNamespace","getI18nNamespace","id","Object","entries","forEach","lang","resources","addResourceBundle","type"],"sources":["../../../src/internal/registerAppI18n.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport {
|
|
1
|
+
{"version":3,"file":"registerAppI18n.js","names":["_i18n","require","registerAppI18n","app","meta","i18n","i18nNamespace","getI18nNamespace","id","languages","Object","entries","forEach","lang","resources","addResourceBundle","push","removeResourceBundle","type"],"sources":["../../../src/internal/registerAppI18n.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport { Storyboard } from \"@next-core/types\";\n\nexport function registerAppI18n({ app, meta }: Storyboard) {\n if (meta?.i18n) {\n // Prefix to avoid conflict between brick package's i18n namespace.\n const i18nNamespace = getI18nNamespace(\"app\", app.id);\n // Support any language in `meta.i18n`.\n const languages: string[] = [];\n Object.entries(meta.i18n).forEach(([lang, resources]) => {\n i18n.addResourceBundle(lang, i18nNamespace, resources);\n languages.push(lang);\n });\n return () => {\n for (const lang of languages) {\n i18n.removeResourceBundle(lang, i18nNamespace);\n }\n };\n }\n}\n\nexport function getI18nNamespace(\n type: \"app\" | \"widget\" | \"menu\",\n id: string\n): string {\n return `${type}/${id}`;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGO,SAASC,eAAeA,CAAC;EAAEC,GAAG;EAAEC;AAAiB,CAAC,EAAE;EACzD,IAAIA,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEC,IAAI,EAAE;IACd;IACA,MAAMC,aAAa,GAAGC,gBAAgB,CAAC,KAAK,EAAEJ,GAAG,CAACK,EAAE,CAAC;IACrD;IACA,MAAMC,SAAmB,GAAG,EAAE;IAC9BC,MAAM,CAACC,OAAO,CAACP,IAAI,CAACC,IAAI,CAAC,CAACO,OAAO,CAAC,CAAC,CAACC,IAAI,EAAEC,SAAS,CAAC,KAAK;MACvDT,UAAI,CAACU,iBAAiB,CAACF,IAAI,EAAEP,aAAa,EAAEQ,SAAS,CAAC;MACtDL,SAAS,CAACO,IAAI,CAACH,IAAI,CAAC;IACtB,CAAC,CAAC;IACF,OAAO,MAAM;MACX,KAAK,MAAMA,IAAI,IAAIJ,SAAS,EAAE;QAC5BJ,UAAI,CAACY,oBAAoB,CAACJ,IAAI,EAAEP,aAAa,CAAC;MAChD;IACF,CAAC;EACH;AACF;AAEO,SAASC,gBAAgBA,CAC9BW,IAA+B,EAC/BV,EAAU,EACF;EACR,OAAQ,GAAEU,IAAK,IAAGV,EAAG,EAAC;AACxB"}
|
|
@@ -103,7 +103,8 @@ function unmountUseBrick({
|
|
|
103
103
|
rendererContext.dispatchOnUnmount();
|
|
104
104
|
rendererContext.dispose();
|
|
105
105
|
}
|
|
106
|
-
function initializePlayground() {
|
|
106
|
+
function initializePlayground(data) {
|
|
107
|
+
(0, _Runtime._internalApiSetBootstrapData)(data);
|
|
107
108
|
// Todo: allow configuration of notification bricks.
|
|
108
109
|
(0, _Notification.loadNotificationService)("shoelace.show-notification");
|
|
109
110
|
(0, _Dialog.loadDialogService)("shoelace.show-dialog");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret_internals.js","names":["_loader","require","_lodash","_Runtime","_Renderer","_RendererContext","_mount","_enums","_computeRealValue","_isStrictMode","_CustomTemplates","_registerAppI18n","_Notification","_Dialog","renderUseBrick","useBrick","data","_runtimeContext$tplSt","_output$node","tplStateStoreScope","runtimeContext","_internalApiGetRuntimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","rendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","createPortal","transform","strict","isStrictMode","warnAboutStrictMode","output","renderBrick","properties","flushStableLoadBricks","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","element","portalRoot","document","querySelector","createElement","appendChild","mountTree","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","mountResult","unmountTree","remove","dispatchOnUnmount","dispose","initializePlayground","loadNotificationService","loadDialogService","legacyDoTransform","to","options","computeRealValue","noInject","loadBricks","_internalApiLoadBricks","exports","updateStoryboard","appId","storyboardPatch","storyboard","_internalApiGetStoryboardInBootstrapData","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","registerAppI18n","updateStoryboardByRoute","newRoute","match","getKey","route","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","customTemplates","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","pick","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,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OA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EACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"secret_internals.js","names":["_loader","require","_lodash","_Runtime","_Renderer","_RendererContext","_mount","_enums","_computeRealValue","_isStrictMode","_CustomTemplates","_registerAppI18n","_Notification","_Dialog","renderUseBrick","useBrick","data","_runtimeContext$tplSt","_output$node","tplStateStoreScope","runtimeContext","_internalApiGetRuntimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","rendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","createPortal","transform","strict","isStrictMode","warnAboutStrictMode","output","renderBrick","properties","flushStableLoadBricks","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","element","portalRoot","document","querySelector","createElement","appendChild","mountTree","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","mountResult","unmountTree","remove","dispatchOnUnmount","dispose","initializePlayground","_internalApiSetBootstrapData","loadNotificationService","loadDialogService","legacyDoTransform","to","options","computeRealValue","noInject","loadBricks","_internalApiLoadBricks","exports","updateStoryboard","appId","storyboardPatch","storyboard","_internalApiGetStoryboardInBootstrapData","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","registerAppI18n","updateStoryboardByRoute","newRoute","match","getKey","route","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","customTemplates","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","pick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BootstrapData,\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 _internalApiSetBootstrapData,\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(data: Partial<BootstrapData>) {\n _internalApiSetBootstrapData(data);\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":";;;;;;;;;;;;;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAMA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AAGA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,iBAAA,GAAAP,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AACA,IAAAU,gBAAA,GAAAV,OAAA;AACA,IAAAW,aAAA,GAAAX,OAAA;AACA,IAAAY,OAAA,GAAAZ,OAAA;AAQO,eAAea,cAAcA,CAClCC,QAA4B,EAC5BC,IAAa,EACkB;EAAA,IAAAC,qBAAA,EAAAC,YAAA;EAC/B,MAAMC,kBAAwC,GAAG,EAAE;EACnD,MAAMC,cAA8B,GAAG;IACrC,GAAG,IAAAC,sCAA6B,GAAG;IACnCL,IAAI;IACJM,0BAA0B,EAAE,EAAE;IAC9BH;EACF,CAAC;EAED,CAAAF,qBAAA,GAAAG,cAAc,CAACG,gBAAgB,cAAAN,qBAAA,cAAAA,qBAAA,GAA/BG,cAAc,CAACG,gBAAgB,GAAK,IAAIC,GAAG,EAAE;EAE7C,MAAMC,eAAe,GAAG,IAAIC,gCAAe,CAAC,UAAU,CAAC;EAEvD,MAAMC,UAAsB,GAAG;IAC7BC,GAAG,EAAEC,gBAAS,CAACC,IAAI;IACnB;IACAC,YAAY,EAAE;EAChB,CAAC;EAED,MAAMC,SAAS,GAAIjB,QAAQ,CACxBiB,SAAS;EACZ,MAAMC,MAAM,GAAG,IAAAC,0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AC1E,MAAM8B,eAA0B,GAAG;IACjC9B,IAAI;IACJc,MAAM;IACNiB,IAAI,EAAE,KAAK;IACX9B,KAAK,EAAE;EACT,CAAC;EACD,IAAI2B,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BzB,MAAM,CAACG,OAAO,CAACwB,eAAe,CAAC;EACjC,CAAC,MAAM;IACL3B,MAAM,CAAC6B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
|
package/dist/esm/createRoot.js
CHANGED
|
@@ -2,10 +2,14 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import { flushStableLoadBricks } from "@next-core/loader";
|
|
3
3
|
import { renderBricks } from "./internal/Renderer.js";
|
|
4
4
|
import { RendererContext } from "./internal/RendererContext.js";
|
|
5
|
+
import { DataStore } from "./internal/data/DataStore.js";
|
|
5
6
|
import { mountTree, unmountTree } from "./internal/mount.js";
|
|
6
7
|
import { httpErrorToString } from "./handleHttpError.js";
|
|
7
8
|
import { applyMode, applyTheme, setMode, setTheme } from "./themeAndMode.js";
|
|
8
9
|
import { RenderTag } from "./internal/enums.js";
|
|
10
|
+
import { registerStoryboardFunctions } from "./internal/compute/StoryboardFunctions.js";
|
|
11
|
+
import { registerAppI18n } from "./internal/registerAppI18n.js";
|
|
12
|
+
import { registerCustomTemplates } from "./internal/registerCustomTemplates.js";
|
|
9
13
|
export function unstable_createRoot(container) {
|
|
10
14
|
var {
|
|
11
15
|
portal: _portal,
|
|
@@ -27,18 +31,24 @@ export function unstable_createRoot(container) {
|
|
|
27
31
|
}
|
|
28
32
|
var unmounted = false;
|
|
29
33
|
var rendererContext;
|
|
34
|
+
var clearI18nBundles;
|
|
30
35
|
return {
|
|
31
36
|
render(brick) {
|
|
32
37
|
var _arguments = arguments;
|
|
33
38
|
return _asyncToGenerator(function* () {
|
|
34
39
|
var {
|
|
35
|
-
theme
|
|
40
|
+
theme,
|
|
41
|
+
context,
|
|
42
|
+
functions,
|
|
43
|
+
templates,
|
|
44
|
+
i18n: i18nData
|
|
36
45
|
} = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : {};
|
|
37
46
|
if (unmounted) {
|
|
38
47
|
throw new Error("The root is unmounted and cannot be rendered any more");
|
|
39
48
|
}
|
|
40
49
|
var bricks = [].concat(brick);
|
|
41
50
|
var runtimeContext = {
|
|
51
|
+
ctxStore: new DataStore("CTX"),
|
|
42
52
|
pendingPermissionsPreCheck: [],
|
|
43
53
|
tplStateStoreMap: new Map()
|
|
44
54
|
};
|
|
@@ -49,13 +59,38 @@ export function unstable_createRoot(container) {
|
|
|
49
59
|
container,
|
|
50
60
|
createPortal
|
|
51
61
|
};
|
|
62
|
+
if (scope === "page") {
|
|
63
|
+
var _clearI18nBundles;
|
|
64
|
+
var demoApp = {
|
|
65
|
+
id: "demo",
|
|
66
|
+
homepage: "/demo"
|
|
67
|
+
};
|
|
68
|
+
runtimeContext.app = demoApp;
|
|
69
|
+
var demoStoryboard = {
|
|
70
|
+
app: demoApp,
|
|
71
|
+
meta: {
|
|
72
|
+
i18n: i18nData,
|
|
73
|
+
customTemplates: templates
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Register i18n.
|
|
78
|
+
(_clearI18nBundles = clearI18nBundles) === null || _clearI18nBundles === void 0 ? void 0 : _clearI18nBundles();
|
|
79
|
+
clearI18nBundles = registerAppI18n(demoStoryboard);
|
|
80
|
+
|
|
81
|
+
// Register custom templates.
|
|
82
|
+
registerCustomTemplates(demoStoryboard);
|
|
83
|
+
|
|
84
|
+
// Register functions.
|
|
85
|
+
registerStoryboardFunctions(functions, demoApp);
|
|
86
|
+
}
|
|
87
|
+
runtimeContext.ctxStore.define(context, runtimeContext);
|
|
52
88
|
var failed = false;
|
|
53
89
|
var output;
|
|
54
90
|
try {
|
|
55
91
|
output = yield renderBricks(renderRoot, bricks, runtimeContext, rendererContext);
|
|
56
|
-
output.blockingList.push(...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck);
|
|
57
92
|
flushStableLoadBricks();
|
|
58
|
-
yield Promise.all(output.blockingList);
|
|
93
|
+
yield Promise.all([...output.blockingList, runtimeContext.ctxStore.waitForAll(), ...[...runtimeContext.tplStateStoreMap.values()].map(store => store.waitForAll()), ...runtimeContext.pendingPermissionsPreCheck]);
|
|
59
94
|
} catch (error) {
|
|
60
95
|
failed = true;
|
|
61
96
|
output = {
|
|
@@ -73,6 +108,7 @@ export function unstable_createRoot(container) {
|
|
|
73
108
|
};
|
|
74
109
|
}
|
|
75
110
|
renderRoot.child = output.node;
|
|
111
|
+
previousRendererContext === null || previousRendererContext === void 0 ? void 0 : previousRendererContext.dispatchOnUnmount();
|
|
76
112
|
previousRendererContext === null || previousRendererContext === void 0 ? void 0 : previousRendererContext.dispose();
|
|
77
113
|
unmountTree(container);
|
|
78
114
|
if (portal) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoot.js","names":["flushStableLoadBricks","renderBricks","RendererContext","mountTree","unmountTree","httpErrorToString","applyMode","applyTheme","setMode","setTheme","RenderTag","unstable_createRoot","container","portal","_portal","scope","arguments","length","undefined","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","render","brick","_arguments","_asyncToGenerator","theme","Error","bricks","concat","runtimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","previousRendererContext","renderRoot","tag","ROOT","failed","output","blockingList","push","values","map","store","waitForAll","Promise","all","error","node","BRICK","type","properties","textContent","return","menuRequests","child","dispose","dispatchBeforePageLoad","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type { BrickConf, SiteTheme } from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport type { 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\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\"\n * - page: render as whole page, triggering page life cycles.\n * - fragment: render as fragment, not triggering page life cycles.\n */\n scope?: \"page\" | \"fragment\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement,\n { portal: _portal, scope = \"fragment\" }: 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\n return {\n async render(\n brick: BrickConf | BrickConf[],\n { theme }: 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 pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope);\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\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(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":";AACA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAAuBC,YAAY,QAAQ,wBAAwB;AACnE,SAASC,eAAe,QAAQ,+BAA+B;AAG/D,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;AAgB/C,OAAO,SAASC,mBAAmBA,CACjCC,SAAsB,EAEtB;EAAA,IADA;IAAEC,MAAM,EAAEC,OAAO;IAAEC,KAAK,GAAG;EAA8B,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAA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S,EAAE;QACb;QAEAH,SAAS,CAACwC,UAAU,CAAC;QAErB,IAAI5B,KAAK,KAAK,MAAM,EAAE;UACpBoD,MAAM,CAACC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;QACvB;QAEA,IAAI,CAACtB,MAAM,EAAE;UACX,IAAI/B,KAAK,KAAK,MAAM,EAAE;YACpBc,eAAe,CAACwC,gBAAgB,EAAE;YAClC;UACF;;UACAxC,eAAe,CAACyC,eAAe,EAAE;UACjCzC,eAAe,CAAC0C,wBAAwB,EAAE;UAC1C1C,eAAe,CAAC2C,qBAAqB,EAAE;QACzC;MAAC;IACH,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI7C,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChBxB,WAAW,CAACQ,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACVT,WAAW,CAACS,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC6D,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","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\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\" }: 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);\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,QAAQ,uCAAuC;AAoB/E,OAAO,SAASC,mBAAmBA,CACjCC,SAAsB,EAEtB;EAAA,IADA;IAAEC,MAAM,EAAEC,OAAO;IAAEC,KAAK,GAAG;EAA8B,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAE/D,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAA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;MACF;MACAA,SAAS,GAAG,IAAI;MAChB3B,WAAW,CAACW,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACVZ,WAAW,CAACY,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC6E,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
|
|
@@ -97,7 +97,7 @@ export class Runtime {
|
|
|
97
97
|
return (_router5 = router) === null || _router5 === void 0 ? void 0 : _router5.getNavConfig();
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
export function
|
|
100
|
+
export function _internalApiSetBootstrapData(data) {
|
|
101
101
|
bootstrapData = data;
|
|
102
102
|
}
|
|
103
103
|
export function getBrickPackages() {
|
|
@@ -1 +1 @@
|
|
|
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,qBAAqB;AACzC,IAAIG,MAA0B;AAE9B,OAAO,SAASC,aAAaA,CAAA,EAAG;EAC9B,IAAIH,OAAO,EAAE;IACX,MAAM,IAAII,KAAK,CAAC,iCAAiC,CAAC;EACpD;EACAjB,cAAc,CAACQ,EAAE,EAAEC,OAAO,CAAC;EAC3BP,MAAM,CAACgB,MAAM,CAACnB,IAAI,CAACoB,QAAQ,CAAC;EAC5BpB,IAAI,CAACqB,EAAE,CAAC,iBAAiB,EAAE,MAAM;IAC/BlB,MAAM,CAACgB,MAAM,CAACnB,IAAI,CAACoB,QAAQ,CAAC;EAC9B,CAAC,CAAC;EACFhB,aAAa,EAAE;EACfU,OAAO,GAAG,IAAIQ,OAAO,EAAE;EACvB,OAAOR,OAAO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AAsBA,CAACC,MAA8B,EAAE;EACrE,OAAO5F,sBAAsB,CAAC4F,MAAM,EAAEL,gBAAgB,EAAE,CAAC;AAC3D;AAEA,OAAO,SAASM,uBAAuBA,CAAA,EAAuB;EAAA,IAAAC,QAAA;EAC5D,QAAAA,QAAA,GAAOhF,MAAM,cAAAgF,QAAA,uBAANA,QAAA,CAAQC,WAAW,EAAE;AAC9B;AAEA,OAAO,SAASC,2BAA2BA,CACzCC,QAAgB,EACe;EAAA,IAAAC,qBAAA,EAAAC,eAAA;EAC/B,OAAOhG,eAAe,EAAA+F,qBAAA,IAAAC,eAAA,GAACtF,aAAa,cAAAsF,eAAA,uBAAbA,eAAA,CAAexE,WAAW,cAAAuE,qBAAA,cAAAA,qBAAA,GAAI,EAAE,EAAED,QAAQ,CAAC;AACpE;AAEA,OAAO,SAASG,6BAA6BA,CAAA,EAAG;EAAA,IAAAC,QAAA;EAC9C,QAAAA,QAAA,GAAOvF,MAAM,cAAAuF,QAAA,uBAANA,QAAA,CAAQC,iBAAiB,EAAE;AACpC;AAEA,OAAO,SAASC,wCAAwCA,CAACC,KAAa,EAAE;EAAA,IAAAC,gBAAA,EAAAC,qBAAA;EACtE,QAAAD,gBAAA,GAAO5F,aAAa,cAAA4F,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"}
|
|
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","_internalApiSetBootstrapData","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 _internalApiSetBootstrapData(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,EAAE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OvF,MAAM,cAAAuF,QAAA,uBAANA,QAAA,CAAQC,iBAAiB,EAAE;AACpC;AAEA,OAAO,SAASC,wCAAwCA,CAACC,KAAa,EAAE;EAAA,IAAAC,gBAAA,EAAAC,qBAAA;EACtE,QAAAD,gBAAA,GAAO5F,aAAa,cAAA4F,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"}
|
|
@@ -8,10 +8,17 @@ export function registerAppI18n(_ref) {
|
|
|
8
8
|
// Prefix to avoid conflict between brick package's i18n namespace.
|
|
9
9
|
var i18nNamespace = getI18nNamespace("app", app.id);
|
|
10
10
|
// Support any language in `meta.i18n`.
|
|
11
|
+
var languages = [];
|
|
11
12
|
Object.entries(meta.i18n).forEach(_ref2 => {
|
|
12
13
|
var [lang, resources] = _ref2;
|
|
13
14
|
i18n.addResourceBundle(lang, i18nNamespace, resources);
|
|
15
|
+
languages.push(lang);
|
|
14
16
|
});
|
|
17
|
+
return () => {
|
|
18
|
+
for (var lang of languages) {
|
|
19
|
+
i18n.removeResourceBundle(lang, i18nNamespace);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
24
|
export function getI18nNamespace(type, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerAppI18n.js","names":["i18n","registerAppI18n","_ref","app","meta","i18nNamespace","getI18nNamespace","id","Object","entries","forEach","_ref2","lang","resources","addResourceBundle","type","concat"],"sources":["../../../src/internal/registerAppI18n.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport {
|
|
1
|
+
{"version":3,"file":"registerAppI18n.js","names":["i18n","registerAppI18n","_ref","app","meta","i18nNamespace","getI18nNamespace","id","languages","Object","entries","forEach","_ref2","lang","resources","addResourceBundle","push","removeResourceBundle","type","concat"],"sources":["../../../src/internal/registerAppI18n.ts"],"sourcesContent":["import { i18n } from \"@next-core/i18n\";\nimport { Storyboard } from \"@next-core/types\";\n\nexport function registerAppI18n({ app, meta }: Storyboard) {\n if (meta?.i18n) {\n // Prefix to avoid conflict between brick package's i18n namespace.\n const i18nNamespace = getI18nNamespace(\"app\", app.id);\n // Support any language in `meta.i18n`.\n const languages: string[] = [];\n Object.entries(meta.i18n).forEach(([lang, resources]) => {\n i18n.addResourceBundle(lang, i18nNamespace, resources);\n languages.push(lang);\n });\n return () => {\n for (const lang of languages) {\n i18n.removeResourceBundle(lang, i18nNamespace);\n }\n };\n }\n}\n\nexport function getI18nNamespace(\n type: \"app\" | \"widget\" | \"menu\",\n id: string\n): string {\n return `${type}/${id}`;\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,iBAAiB;AAGtC,OAAO,SAASC,eAAeA,CAAAC,IAAA,EAA4B;EAAA,IAA3B;IAAEC,GAAG;IAAEC;EAAiB,CAAC,GAAAF,IAAA;EACvD,IAAIE,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEJ,IAAI,EAAE;IACd;IACA,IAAMK,aAAa,GAAGC,gBAAgB,CAAC,KAAK,EAAEH,GAAG,CAACI,EAAE,CAAC;IACrD;IACA,IAAMC,SAAmB,GAAG,EAAE;IAC9BC,MAAM,CAACC,OAAO,CAACN,IAAI,CAACJ,IAAI,CAAC,CAACW,OAAO,CAACC,KAAA,IAAuB;MAAA,IAAtB,CAACC,IAAI,EAAEC,SAAS,CAAC,GAAAF,KAAA;MAClDZ,IAAI,CAACe,iBAAiB,CAACF,IAAI,EAAER,aAAa,EAAES,SAAS,CAAC;MACtDN,SAAS,CAACQ,IAAI,CAACH,IAAI,CAAC;IACtB,CAAC,CAAC;IACF,OAAO,MAAM;MACX,KAAK,IAAMA,IAAI,IAAIL,SAAS,EAAE;QAC5BR,IAAI,CAACiB,oBAAoB,CAACJ,IAAI,EAAER,aAAa,CAAC;MAChD;IACF,CAAC;EACH;AACF;AAEA,OAAO,SAASC,gBAAgBA,CAC9BY,IAA+B,EAC/BX,EAAU,EACF;EACR,UAAAY,MAAA,CAAUD,IAAI,OAAAC,MAAA,CAAIZ,EAAE;AACtB"}
|
|
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
import { flushStableLoadBricks } from "@next-core/loader";
|
|
4
4
|
import { pick } from "lodash";
|
|
5
|
-
import { _internalApiGetRuntimeContext, _internalApiGetStoryboardInBootstrapData, _internalApiLoadBricks } from "./Runtime.js";
|
|
5
|
+
import { _internalApiGetRuntimeContext, _internalApiGetStoryboardInBootstrapData, _internalApiLoadBricks, _internalApiSetBootstrapData } from "./Runtime.js";
|
|
6
6
|
import { renderBrick } from "./Renderer.js";
|
|
7
7
|
import { RendererContext } from "./RendererContext.js";
|
|
8
8
|
import { mountTree, unmountTree } from "./mount.js";
|
|
@@ -91,7 +91,8 @@ export function unmountUseBrick(_ref2, mountResult) {
|
|
|
91
91
|
rendererContext.dispatchOnUnmount();
|
|
92
92
|
rendererContext.dispose();
|
|
93
93
|
}
|
|
94
|
-
export function initializePlayground() {
|
|
94
|
+
export function initializePlayground(data) {
|
|
95
|
+
_internalApiSetBootstrapData(data);
|
|
95
96
|
// Todo: allow configuration of notification bricks.
|
|
96
97
|
loadNotificationService("shoelace.show-notification");
|
|
97
98
|
loadDialogService("shoelace.show-dialog");
|
|
@@ -1 +1 @@
|
|
|
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,IA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wB,SAAS,CAAE7B,KAAK,IAAKA,KAAK,CAACE,IAAI,KAAKA,IAAI,CAAC;EAC1E,IAAM4B,eAA0B,GAAG;IACjC5B,IAAI;IACJa,MAAM;IACNgB,IAAI,EAAE,KAAK;IACX5B,KAAK,EAAE;EACT,CAAC;EACD,IAAIyB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BvB,MAAM,CAACG,OAAO,CAACsB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLzB,MAAM,CAAC2B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"secret_internals.js","names":["flushStableLoadBricks","pick","_internalApiGetRuntimeContext","_internalApiGetStoryboardInBootstrapData","_internalApiLoadBricks","_internalApiSetBootstrapData","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 BootstrapData,\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 _internalApiSetBootstrapData,\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(data: Partial<BootstrapData>) {\n _internalApiSetBootstrapData(data);\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":";;AAQA,SAASA,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SACEC,6BAA6B,EAC7BC,wCAAwC,EACxCC,sBAAsB,EACtBC,4BAA4B,QACvB,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,eAAe,QAAQ,uBAAuB;AACvD,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,uBAAuB,QAAQ,oBAAoB;AAC5D,SAASC,iBAAiB,QAAQ,cAAc;AAQhD,gBAAsBC,cAAcA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,eAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAmEnC,SAAAF,gBAAA;EAAAA,eAAA,GAAAG,iBAAA,CAnEM,WACLC,QAA4B,EAC5BC,IAAa,EACkB;IAAA,IAAAC,qBAAA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AY,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAC,EAEpE,CACF;AACH;AAEA,OAAO,SAASW,yBAAyBA,CACvClC,KAAa,EACbmC,WAGC,EACK;EAAA,IAAAC,mBAAA;EACNJ,sBAAsB,CACpBhC,KAAK,gDAAAa,MAAA,CAC0CsB,WAAW,CAACE,SAAS,GACpE,CAAAD,mBAAA,GAAAD,WAAW,CAACR,MAAM,cAAAS,mBAAA,eAAlBA,mBAAA,CAAoBE,MAAM,GAAGH,WAAW,CAACR,MAAM,GAAG,CAAC;IAAEM,KAAK,EAAE;EAAO,CAAC,CAAC,CACtE;AACH;AAEA,OAAO,IAAMM,4BAA4B,GAAGL,yBAAyB;AAErE,SAASF,sBAAsBA,CAC7BhC,KAAa,EACbc,IAAY,EACZa,MAAmB,EACnB;EACA,IAAM;IAAEV;EAAO,CAAC,GAAG9F,wCAAwC,CAAC6E,KAAK,CAAE;EACnE,IAAMwC,iBAAiB,GAAGvB,MAAM,CAACwB,SAAS,CAAE7B,KAAK,IAAKA,KAAK,CAACE,IAAI,KAAKA,IAAI,CAAC;EAC1E,IAAM4B,eAA0B,GAAG;IACjC5B,IAAI;IACJa,MAAM;IACNgB,IAAI,EAAE,KAAK;IACX5B,KAAK,EAAE;EACT,CAAC;EACD,IAAIyB,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BvB,MAAM,CAACG,OAAO,CAACsB,eAAe,CAAC;EACjC,CAAC,MAAM;IACLzB,MAAM,CAAC2B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import type { BrickConf, SiteTheme } from "@next-core/types";
|
|
1
|
+
import type { BrickConf, ContextConf, CustomTemplate, MetaI18n, SiteTheme, StoryboardFunction } from "@next-core/types";
|
|
2
2
|
export interface CreateRootOptions {
|
|
3
3
|
portal?: HTMLElement;
|
|
4
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.
|
|
5
|
+
* Defaults to "fragment", only set it to "page" when the root is in a standalone iframe.
|
|
6
|
+
* - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.
|
|
7
|
+
* - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.
|
|
8
8
|
*/
|
|
9
9
|
scope?: "page" | "fragment";
|
|
10
10
|
}
|
|
11
11
|
export interface RenderOptions {
|
|
12
12
|
theme?: SiteTheme;
|
|
13
|
+
context?: ContextConf[];
|
|
14
|
+
functions?: StoryboardFunction[];
|
|
15
|
+
templates?: CustomTemplate[];
|
|
16
|
+
i18n?: MetaI18n;
|
|
13
17
|
}
|
|
14
18
|
export declare function unstable_createRoot(container: HTMLElement, { portal: _portal, scope }?: CreateRootOptions): {
|
|
15
|
-
render(brick: BrickConf | BrickConf[], { theme }?: RenderOptions): Promise<void>;
|
|
19
|
+
render(brick: BrickConf | BrickConf[], { theme, context, functions, templates, i18n: i18nData, }?: RenderOptions): Promise<void>;
|
|
16
20
|
unmount(): void;
|
|
17
21
|
};
|
|
@@ -23,7 +23,7 @@ export declare class Runtime {
|
|
|
23
23
|
breadcrumb?: import("@next-core/types").BreadcrumbItemConf[] | undefined;
|
|
24
24
|
} | undefined;
|
|
25
25
|
}
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function _internalApiSetBootstrapData(data: Partial<BootstrapData>): void;
|
|
27
27
|
export declare function getBrickPackages(): import("@next-core/types").BrickPackage[];
|
|
28
28
|
export declare function _internalApiLoadBricks(bricks: string[] | Set<string>): Promise<void>;
|
|
29
29
|
export declare function _internalApiGetRenderId(): string | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function registerAppI18n({ app, meta }:
|
|
1
|
+
import { Storyboard } from "@next-core/types";
|
|
2
|
+
export declare function registerAppI18n({ app, meta }: Storyboard): (() => void) | undefined;
|
|
3
3
|
export declare function getI18nNamespace(type: "app" | "widget" | "menu", id: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BrickConf, CustomTemplate, RouteConf, Storyboard, UseSingleBrickConf } from "@next-core/types";
|
|
1
|
+
import type { BootstrapData, BrickConf, CustomTemplate, RouteConf, Storyboard, UseSingleBrickConf } from "@next-core/types";
|
|
2
2
|
import { _internalApiLoadBricks } from "./Runtime.js";
|
|
3
3
|
import { RendererContext } from "./RendererContext.js";
|
|
4
4
|
import type { RenderRoot } from "./interfaces.js";
|
|
@@ -13,7 +13,7 @@ export interface MountUseBrickResult {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function mountUseBrick({ renderRoot, rendererContext }: RenderUseBrickResult, element: HTMLElement): MountUseBrickResult;
|
|
15
15
|
export declare function unmountUseBrick({ rendererContext }: RenderUseBrickResult, mountResult: MountUseBrickResult): void;
|
|
16
|
-
export declare function initializePlayground(): void;
|
|
16
|
+
export declare function initializePlayground(data: Partial<BootstrapData>): void;
|
|
17
17
|
export declare function legacyDoTransform(data: unknown, to: unknown, options?: unknown): unknown;
|
|
18
18
|
export declare const loadBricks: typeof _internalApiLoadBricks;
|
|
19
19
|
export declare function updateStoryboard(appId: string, storyboardPatch: Partial<Storyboard>): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/runtime",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
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": "
|
|
70
|
+
"gitHead": "eca8608572cca62c44d114a8cc05d04e8980f8ff"
|
|
71
71
|
}
|