@next-core/runtime 1.28.1 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/CustomTemplates.js +0 -1
  2. package/dist/cjs/CustomTemplates.js.map +1 -1
  3. package/dist/cjs/createRoot.js +2 -1
  4. package/dist/cjs/createRoot.js.map +1 -1
  5. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +0 -1
  6. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  7. package/dist/cjs/internal/Runtime.js +2 -0
  8. package/dist/cjs/internal/Runtime.js.map +1 -1
  9. package/dist/cjs/internal/compute/getGeneralGlobals.js +0 -1
  10. package/dist/cjs/internal/compute/getGeneralGlobals.js.map +1 -1
  11. package/dist/cjs/internal/secret_internals.js +4 -2
  12. package/dist/cjs/internal/secret_internals.js.map +1 -1
  13. package/dist/cjs/internal/setupRootRuntimeContext.js +53 -0
  14. package/dist/cjs/internal/setupRootRuntimeContext.js.map +1 -0
  15. package/dist/esm/CustomTemplates.js +0 -1
  16. package/dist/esm/CustomTemplates.js.map +1 -1
  17. package/dist/esm/createRoot.js +2 -1
  18. package/dist/esm/createRoot.js.map +1 -1
  19. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +0 -1
  20. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  21. package/dist/esm/internal/Runtime.js +2 -0
  22. package/dist/esm/internal/Runtime.js.map +1 -1
  23. package/dist/esm/internal/compute/getGeneralGlobals.js +0 -1
  24. package/dist/esm/internal/compute/getGeneralGlobals.js.map +1 -1
  25. package/dist/esm/internal/secret_internals.js +3 -2
  26. package/dist/esm/internal/secret_internals.js.map +1 -1
  27. package/dist/esm/internal/setupRootRuntimeContext.js +47 -0
  28. package/dist/esm/internal/setupRootRuntimeContext.js.map +1 -0
  29. package/dist/types/internal/Renderer.d.ts +1 -1
  30. package/dist/types/internal/Runtime.d.ts +1 -0
  31. package/dist/types/internal/compute/WidgetI18n.d.ts +1 -1
  32. package/dist/types/internal/secret_internals.d.ts +7 -3
  33. package/dist/types/internal/setupRootRuntimeContext.d.ts +3 -0
  34. package/dist/types/tsdoc-metadata.json +1 -1
  35. package/package.json +12 -12
@@ -49,7 +49,6 @@ class CustomTemplateRegistry {
49
49
  }
50
50
  // Else: documentation only, for exposed states.
51
51
  }
52
-
53
52
  const compatibleConstructor = {
54
53
  ...constructor,
55
54
  proxy: {
@@ -1 +1 @@
1
- {"version":3,"file":"CustomTemplates.js","names":["_lodash","require","_isStrictMode","_getV2RuntimeFromDll","allowedNativeProps","Set","CustomTemplateRegistry","registry","Map","define","tagName","constructor","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","has","console","warn","customElements","get","strict","isStrictMode","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","value","Object","entries","asVariable","warnAboutStrictMode","push","mergeProperty","refTransform","error","ref","compatibleConstructor","fromEntries","state","map","item","expose","concat","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","propName","some","defineProperty","getValue","_this$$$tplStateStore2","updateValue","enumerable","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","args","_to$refMethod","refMethod","_state$filter$map","uniq","getCustomTemplatesV2","v2Kit","getV2RuntimeFromDll","freeze","getRuntime","registerCustomTemplate","customTemplates","exports"],"sources":["../../src/CustomTemplates.ts"],"sourcesContent":["import type {\n ContextConf,\n CustomTemplate,\n CustomTemplateConstructor,\n CustomTemplateProxyBasicProperty,\n} from \"@next-core/types\";\nimport { uniq } from \"lodash\";\nimport type { RuntimeBrickElement } from \"./internal/interfaces.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"./isStrictMode.js\";\nimport { getV2RuntimeFromDll } from \"./getV2RuntimeFromDll.js\";\n\n// Note: `prefix` is a native prop on Element, but it's only used in XML documents.\nconst allowedNativeProps = new Set([\"prefix\"]);\n\ninterface LegacyTplPropProxy extends CustomTemplateProxyBasicProperty {\n asVariable?: boolean;\n mergeProperty?: unknown;\n refTransform?: unknown;\n}\n\nclass CustomTemplateRegistry {\n readonly #registry = new Map<string, CustomTemplate>();\n\n define(tagName: string, constructor: CustomTemplateConstructor): void {\n let registered = this.#registry.has(tagName);\n if (registered) {\n // When open launchpad, the storyboard will be updated.\n // However, we can't *undefine* a custom element.\n // Just ignore re-registering custom templates.\n // eslint-disable-next-line no-console\n console.warn(`Custom template of \"${tagName}\" already registered.`);\n } else {\n registered = !!customElements.get(tagName);\n if (registered) {\n // eslint-disable-next-line no-console\n console.warn(\n `Custom template of \"${tagName}\" already defined by customElements.`\n );\n }\n }\n\n // Transform legacy `proxy.properties[].asVariable` as states.\n const strict = isStrictMode();\n const proxyProperties = (constructor.proxy?.properties ?? {}) as {\n [name: string]: LegacyTplPropProxy;\n };\n const validProxyProps: [string, CustomTemplateProxyBasicProperty][] = [];\n const legacyTplVariables: string[] = [];\n for (const [key, value] of Object.entries(proxyProperties)) {\n if (value.asVariable) {\n warnAboutStrictMode(strict, \"Template `asVariable`\", tagName, key);\n // istanbul ignore next\n if (!strict) {\n // For existed TPL usage, treat it as a STATE.\n legacyTplVariables.push(key);\n }\n } else if (value.mergeProperty || value.refTransform) {\n // eslint-disable-next-line no-console\n console.error(\n \"Template `mergeProperty` and `refTransform` are dropped in v3:\",\n tagName,\n key\n );\n } else if (value.ref) {\n validProxyProps.push([key, value]);\n }\n // Else: documentation only, for exposed states.\n }\n\n const compatibleConstructor = {\n ...constructor,\n proxy: {\n ...constructor.proxy,\n properties: Object.fromEntries(validProxyProps),\n },\n state: (constructor.state\n ? strict\n ? constructor.state\n : constructor.state.map((item) => ({\n // Make `expose` defaults to true in non-strict mode.\n expose: true,\n ...item,\n }))\n : []\n ).concat(legacyTplVariables.map((tpl) => ({ name: tpl, expose: true }))),\n };\n\n // Now we allow re-register custom template\n this.#registry.set(tagName, {\n ...compatibleConstructor,\n name: tagName,\n });\n\n const exposedStates = getExposedStates(compatibleConstructor.state);\n const proxyMethods = Object.entries(\n compatibleConstructor.proxy?.methods ?? {}\n );\n\n const props = exposedStates.concat(\n validProxyProps.map((entry) => entry[0])\n );\n const methods = proxyMethods.map((entry) => entry[0]);\n\n const nativeProps = props\n .concat(methods)\n .filter(\n (prop) => prop in HTMLElement.prototype && !allowedNativeProps.has(prop)\n );\n if (nativeProps.length > 0) {\n warnAboutStrictMode(\n strict,\n \"Using native HTMLElement properties as template properties or methods\",\n tagName,\n ...nativeProps\n );\n // istanbul ignore next\n if (strict) {\n throw new Error(\n `In custom template \"${tagName}\", ${nativeProps\n .map((p) => `\"${p}\"`)\n .join(\n \", \"\n )} are native HTMLElement properties, and should be avoid to be used as brick properties or methods.`\n );\n }\n }\n\n if (registered) {\n return;\n }\n\n class TplElement extends HTMLElement {\n get $$typeof() {\n return \"custom-template\" as const;\n }\n\n static get _dev_only_definedProperties(): string[] {\n return props;\n }\n\n static get _dev_only_definedMethods(): string[] {\n return methods;\n }\n\n $$getElementByRef(this: RuntimeBrickElement, ref: string) {\n return this.$$tplStateStore?.hostBrick?.tplHostMetadata?.internalBricksByRef.get(\n ref\n )?.element;\n }\n\n connectedCallback() {\n let shadowRoot = this.shadowRoot;\n if (!shadowRoot) {\n shadowRoot = this.attachShadow({ mode: \"open\" });\n }\n const fragment = document.createDocumentFragment();\n const style = document.createElement(\"style\");\n style.textContent = \":host{display:block}:host([hidden]){display:none}\";\n const slot = document.createElement(\"slot\");\n fragment.appendChild(style);\n fragment.appendChild(slot);\n shadowRoot.appendChild(fragment);\n }\n\n disconnectedCallback() {\n if (this.shadowRoot) {\n this.shadowRoot.textContent = \"\";\n }\n }\n }\n\n for (const propName of exposedStates) {\n if (validProxyProps.some((entry) => entry[0] === propName)) {\n // eslint-disable-next-line no-console\n console.error(\n `Cannot define an exposed state that is also a proxy property: \"${propName}\" in ${tagName}`\n );\n continue;\n }\n Object.defineProperty(TplElement.prototype, propName, {\n get(this: RuntimeBrickElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.$$tplStateStore!.getValue(propName);\n },\n set(this: RuntimeBrickElement, value: unknown) {\n // 在 mount 过程中,先设置属性,再设置 `$$tplStateStore`,这样,当触发属性设置时,\n // 避免初始化的一次 state update 操作及其 onChange 事件。\n this.$$tplStateStore?.updateValue(propName, value, \"replace\");\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of validProxyProps) {\n Object.defineProperty(TplElement.prototype, from, {\n get(this: TplElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n unknown\n >;\n return element[to.refProperty ?? from];\n },\n set(this: TplElement, value: unknown) {\n // 同上 exposedState.set\n const element = this.$$getElementByRef?.(to.ref) as unknown as Record<\n string,\n unknown\n >;\n if (element) {\n element[to.refProperty ?? from] = value;\n }\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of proxyMethods) {\n Object.defineProperty(TplElement.prototype, from, {\n value(this: TplElement, ...args: unknown[]) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n Function\n >;\n element[to.refMethod ?? from](...args);\n },\n enumerable: true,\n });\n }\n\n customElements.define(tagName, TplElement);\n }\n\n get(tagName: string) {\n return this.#registry.get(tagName);\n }\n}\n\nfunction getExposedStates(state: ContextConf[] | undefined): string[] {\n // Allow duplicated state names which maybe mutually exclusive.\n return uniq(\n state?.filter((item) => item.expose).map((item) => item.name) ?? []\n );\n}\n\n// istanbul ignore next\nfunction getCustomTemplatesV2() {\n const v2Kit = getV2RuntimeFromDll();\n if (v2Kit) {\n return Object.freeze({\n define(tagName: string, constructor: CustomTemplateConstructor) {\n return v2Kit.getRuntime().registerCustomTemplate(tagName, constructor);\n },\n }) as CustomTemplateRegistry;\n }\n}\n\n// istanbul ignore next\nexport const customTemplates =\n getCustomTemplatesV2() || new CustomTemplateRegistry();\n"],"mappings":";;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAEA;AACA,MAAMG,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAQ9C,MAAMC,sBAAsB,CAAC;EAClB,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAEtDC,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAQ;IAAA,IAAAC,qBAAA,EAAAC,kBAAA,EAAAC,qBAAA,EAAAC,sBAAA;IACpE,IAAIC,UAAU,GAAG,IAAI,CAAC,CAACT,QAAQ,CAACU,GAAG,CAACP,OAAO,CAAC;IAC5C,IAAIM,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAE,OAAO,CAACC,IAAI,CAAE,uBAAsBT,OAAQ,uBAAsB,CAAC;IACrE,CAAC,MAAM;MACLM,UAAU,GAAG,CAAC,CAACI,cAAc,CAACC,GAAG,CAACX,OAAO,CAAC;MAC1C,IAAIM,UAAU,EAAE;QACd;QACAE,OAAO,CAACC,IAAI,CACT,uBAAsBT,OAAQ,sCACjC,CAAC;MACH;IACF;;IAEA;IACA,MAAMY,MAAM,GAAG,IAAAC,0BAAY,EAAC,CAAC;IAC7B,MAAMC,eAAe,IAAAZ,qBAAA,IAAAC,kBAAA,GAAIF,WAAW,CAACc,KAAK,cAAAZ,kBAAA,uBAAjBA,kBAAA,CAAmBa,UAAU,cAAAd,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAE1D;IACD,MAAMe,eAA6D,GAAG,EAAE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A,CAAA,EAAG;EAC9B,MAAMC,KAAK,GAAG,IAAAC,wCAAmB,EAAC,CAAC;EACnC,IAAID,KAAK,EAAE;IACT,OAAO9E,MAAM,CAACgF,MAAM,CAAC;MACnBtG,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAE;QAC9D,OAAOkG,KAAK,CAACG,UAAU,CAAC,CAAC,CAACC,sBAAsB,CAACvG,OAAO,EAAEC,WAAW,CAAC;MACxE;IACF,CAAC,CAAC;EACJ;AACF;;AAEA;AACO,MAAMuG,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAC1BN,oBAAoB,CAAC,CAAC,IAAI,IAAItG,sBAAsB,CAAC,CAAC"}
1
+ {"version":3,"file":"CustomTemplates.js","names":["_lodash","require","_isStrictMode","_getV2RuntimeFromDll","allowedNativeProps","Set","CustomTemplateRegistry","registry","Map","define","tagName","constructor","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","has","console","warn","customElements","get","strict","isStrictMode","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","value","Object","entries","asVariable","warnAboutStrictMode","push","mergeProperty","refTransform","error","ref","compatibleConstructor","fromEntries","state","map","item","expose","concat","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","propName","some","defineProperty","getValue","_this$$$tplStateStore2","updateValue","enumerable","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","args","_to$refMethod","refMethod","_state$filter$map","uniq","getCustomTemplatesV2","v2Kit","getV2RuntimeFromDll","freeze","getRuntime","registerCustomTemplate","customTemplates","exports"],"sources":["../../src/CustomTemplates.ts"],"sourcesContent":["import type {\n ContextConf,\n CustomTemplate,\n CustomTemplateConstructor,\n CustomTemplateProxyBasicProperty,\n} from \"@next-core/types\";\nimport { uniq } from \"lodash\";\nimport type { RuntimeBrickElement } from \"./internal/interfaces.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"./isStrictMode.js\";\nimport { getV2RuntimeFromDll } from \"./getV2RuntimeFromDll.js\";\n\n// Note: `prefix` is a native prop on Element, but it's only used in XML documents.\nconst allowedNativeProps = new Set([\"prefix\"]);\n\ninterface LegacyTplPropProxy extends CustomTemplateProxyBasicProperty {\n asVariable?: boolean;\n mergeProperty?: unknown;\n refTransform?: unknown;\n}\n\nclass CustomTemplateRegistry {\n readonly #registry = new Map<string, CustomTemplate>();\n\n define(tagName: string, constructor: CustomTemplateConstructor): void {\n let registered = this.#registry.has(tagName);\n if (registered) {\n // When open launchpad, the storyboard will be updated.\n // However, we can't *undefine* a custom element.\n // Just ignore re-registering custom templates.\n // eslint-disable-next-line no-console\n console.warn(`Custom template of \"${tagName}\" already registered.`);\n } else {\n registered = !!customElements.get(tagName);\n if (registered) {\n // eslint-disable-next-line no-console\n console.warn(\n `Custom template of \"${tagName}\" already defined by customElements.`\n );\n }\n }\n\n // Transform legacy `proxy.properties[].asVariable` as states.\n const strict = isStrictMode();\n const proxyProperties = (constructor.proxy?.properties ?? {}) as {\n [name: string]: LegacyTplPropProxy;\n };\n const validProxyProps: [string, CustomTemplateProxyBasicProperty][] = [];\n const legacyTplVariables: string[] = [];\n for (const [key, value] of Object.entries(proxyProperties)) {\n if (value.asVariable) {\n warnAboutStrictMode(strict, \"Template `asVariable`\", tagName, key);\n // istanbul ignore next\n if (!strict) {\n // For existed TPL usage, treat it as a STATE.\n legacyTplVariables.push(key);\n }\n } else if (value.mergeProperty || value.refTransform) {\n // eslint-disable-next-line no-console\n console.error(\n \"Template `mergeProperty` and `refTransform` are dropped in v3:\",\n tagName,\n key\n );\n } else if (value.ref) {\n validProxyProps.push([key, value]);\n }\n // Else: documentation only, for exposed states.\n }\n\n const compatibleConstructor = {\n ...constructor,\n proxy: {\n ...constructor.proxy,\n properties: Object.fromEntries(validProxyProps),\n },\n state: (constructor.state\n ? strict\n ? constructor.state\n : constructor.state.map((item) => ({\n // Make `expose` defaults to true in non-strict mode.\n expose: true,\n ...item,\n }))\n : []\n ).concat(legacyTplVariables.map((tpl) => ({ name: tpl, expose: true }))),\n };\n\n // Now we allow re-register custom template\n this.#registry.set(tagName, {\n ...compatibleConstructor,\n name: tagName,\n });\n\n const exposedStates = getExposedStates(compatibleConstructor.state);\n const proxyMethods = Object.entries(\n compatibleConstructor.proxy?.methods ?? {}\n );\n\n const props = exposedStates.concat(\n validProxyProps.map((entry) => entry[0])\n );\n const methods = proxyMethods.map((entry) => entry[0]);\n\n const nativeProps = props\n .concat(methods)\n .filter(\n (prop) => prop in HTMLElement.prototype && !allowedNativeProps.has(prop)\n );\n if (nativeProps.length > 0) {\n warnAboutStrictMode(\n strict,\n \"Using native HTMLElement properties as template properties or methods\",\n tagName,\n ...nativeProps\n );\n // istanbul ignore next\n if (strict) {\n throw new Error(\n `In custom template \"${tagName}\", ${nativeProps\n .map((p) => `\"${p}\"`)\n .join(\n \", \"\n )} are native HTMLElement properties, and should be avoid to be used as brick properties or methods.`\n );\n }\n }\n\n if (registered) {\n return;\n }\n\n class TplElement extends HTMLElement {\n get $$typeof() {\n return \"custom-template\" as const;\n }\n\n static get _dev_only_definedProperties(): string[] {\n return props;\n }\n\n static get _dev_only_definedMethods(): string[] {\n return methods;\n }\n\n $$getElementByRef(this: RuntimeBrickElement, ref: string) {\n return this.$$tplStateStore?.hostBrick?.tplHostMetadata?.internalBricksByRef.get(\n ref\n )?.element;\n }\n\n connectedCallback() {\n let shadowRoot = this.shadowRoot;\n if (!shadowRoot) {\n shadowRoot = this.attachShadow({ mode: \"open\" });\n }\n const fragment = document.createDocumentFragment();\n const style = document.createElement(\"style\");\n style.textContent = \":host{display:block}:host([hidden]){display:none}\";\n const slot = document.createElement(\"slot\");\n fragment.appendChild(style);\n fragment.appendChild(slot);\n shadowRoot.appendChild(fragment);\n }\n\n disconnectedCallback() {\n if (this.shadowRoot) {\n this.shadowRoot.textContent = \"\";\n }\n }\n }\n\n for (const propName of exposedStates) {\n if (validProxyProps.some((entry) => entry[0] === propName)) {\n // eslint-disable-next-line no-console\n console.error(\n `Cannot define an exposed state that is also a proxy property: \"${propName}\" in ${tagName}`\n );\n continue;\n }\n Object.defineProperty(TplElement.prototype, propName, {\n get(this: RuntimeBrickElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.$$tplStateStore!.getValue(propName);\n },\n set(this: RuntimeBrickElement, value: unknown) {\n // 在 mount 过程中,先设置属性,再设置 `$$tplStateStore`,这样,当触发属性设置时,\n // 避免初始化的一次 state update 操作及其 onChange 事件。\n this.$$tplStateStore?.updateValue(propName, value, \"replace\");\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of validProxyProps) {\n Object.defineProperty(TplElement.prototype, from, {\n get(this: TplElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n unknown\n >;\n return element[to.refProperty ?? from];\n },\n set(this: TplElement, value: unknown) {\n // 同上 exposedState.set\n const element = this.$$getElementByRef?.(to.ref) as unknown as Record<\n string,\n unknown\n >;\n if (element) {\n element[to.refProperty ?? from] = value;\n }\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of proxyMethods) {\n Object.defineProperty(TplElement.prototype, from, {\n value(this: TplElement, ...args: unknown[]) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n Function\n >;\n element[to.refMethod ?? from](...args);\n },\n enumerable: true,\n });\n }\n\n customElements.define(tagName, TplElement);\n }\n\n get(tagName: string) {\n return this.#registry.get(tagName);\n }\n}\n\nfunction getExposedStates(state: ContextConf[] | undefined): string[] {\n // Allow duplicated state names which maybe mutually exclusive.\n return uniq(\n state?.filter((item) => item.expose).map((item) => item.name) ?? []\n );\n}\n\n// istanbul ignore next\nfunction getCustomTemplatesV2() {\n const v2Kit = getV2RuntimeFromDll();\n if (v2Kit) {\n return Object.freeze({\n define(tagName: string, constructor: CustomTemplateConstructor) {\n return v2Kit.getRuntime().registerCustomTemplate(tagName, constructor);\n },\n }) as CustomTemplateRegistry;\n }\n}\n\n// istanbul ignore next\nexport const customTemplates =\n getCustomTemplatesV2() || new CustomTemplateRegistry();\n"],"mappings":";;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAEA;AACA,MAAMG,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAQ9C,MAAMC,sBAAsB,CAAC;EAClB,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAEtDC,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAQ;IAAA,IAAAC,qBAAA,EAAAC,kBAAA,EAAAC,qBAAA,EAAAC,sBAAA;IACpE,IAAIC,UAAU,GAAG,IAAI,CAAC,CAACT,QAAQ,CAACU,GAAG,CAACP,OAAO,CAAC;IAC5C,IAAIM,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAE,OAAO,CAACC,IAAI,CAAE,uBAAsBT,OAAQ,uBAAsB,CAAC;IACrE,CAAC,MAAM;MACLM,UAAU,GAAG,CAAC,CAACI,cAAc,CAACC,GAAG,CAACX,OAAO,CAAC;MAC1C,IAAIM,UAAU,EAAE;QACd;QACAE,OAAO,CAACC,IAAI,CACT,uBAAsBT,OAAQ,sCACjC,CAAC;MACH;IACF;;IAEA;IACA,MAAMY,MAAM,GAAG,IAAAC,0BAAY,EAAC,CAAC;IAC7B,MAAMC,eAAe,IAAAZ,qBAAA,IAAAC,kBAAA,GAAIF,WAAW,CAACc,KAAK,cAAAZ,kBAAA,uBAAjBA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AI,CAACI,IAAI,CAAC,cAAA0D,iBAAA,cAAAA,iBAAA,GAAI,EACnE,CAAC;AACH;;AAEA;AACA,SAASE,oBAAoBA,CAAA,EAAG;EAC9B,MAAMC,KAAK,GAAG,IAAAC,wCAAmB,EAAC,CAAC;EACnC,IAAID,KAAK,EAAE;IACT,OAAO9E,MAAM,CAACgF,MAAM,CAAC;MACnBtG,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAE;QAC9D,OAAOkG,KAAK,CAACG,UAAU,CAAC,CAAC,CAACC,sBAAsB,CAACvG,OAAO,EAAEC,WAAW,CAAC;MACxE;IACF,CAAC,CAAC;EACJ;AACF;;AAEA;AACO,MAAMuG,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAC1BN,oBAAoB,CAAC,CAAC,IAAI,IAAItG,sBAAsB,CAAC,CAAC"}
@@ -16,6 +16,7 @@ var _StoryboardFunctions = require("./internal/compute/StoryboardFunctions.js");
16
16
  var _registerAppI18n = require("./internal/registerAppI18n.js");
17
17
  var _registerCustomTemplates = require("./internal/registerCustomTemplates.js");
18
18
  var _setUIVersion = require("./setUIVersion.js");
19
+ var _setupRootRuntimeContext = require("./internal/setupRootRuntimeContext.js");
19
20
  function unstable_createRoot(container, {
20
21
  portal: _portal,
21
22
  scope = "fragment",
@@ -70,6 +71,7 @@ function unstable_createRoot(container, {
70
71
  };
71
72
  if (scope === "page") {
72
73
  var _clearI18nBundles;
74
+ (0, _setupRootRuntimeContext.setupRootRuntimeContext)(bricks, runtimeContext);
73
75
  (0, _themeAndMode.setTheme)(theme !== null && theme !== void 0 ? theme : "light");
74
76
  (0, _themeAndMode.setMode)("default");
75
77
  (0, _setUIVersion.setUIVersion)(uiVersion);
@@ -146,7 +148,6 @@ function unstable_createRoot(container, {
146
148
  rendererContext.dispatchPageLoad();
147
149
  // rendererContext.dispatchAnchorLoad();
148
150
  }
149
-
150
151
  rendererContext.dispatchOnMount();
151
152
  rendererContext.initializeScrollIntoView();
152
153
  rendererContext.initializeMediaChange();
@@ -1 +1 @@
1
- {"version":3,"file":"createRoot.js","names":["_lodash","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","_setUIVersion","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","uiVersion","context","functions","templates","i18n","i18nData","Error","bricks","concat","previousRendererContext","renderId","uniqueId","RendererContext","runtimeContext","ctxStore","DataStore","undefined","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","setTheme","setMode","setUIVersion","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","stores","renderBricks","getDataStores","postAsyncRender","error","node","BRICK","type","properties","textContent","httpErrorToString","return","blockingList","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","store","mountAsyncData","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport {\n RenderOutput,\n getDataStores,\n postAsyncRender,\n renderBricks,\n} from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\nimport { setUIVersion } from \"./setUIVersion.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n uiVersion?: string;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement | DocumentFragment,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n uiVersion,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n\n const previousRendererContext = rendererContext;\n const renderId = uniqueId(\"render-id-\");\n rendererContext = new RendererContext(scope, { unknownBricks, renderId });\n\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\", undefined, rendererContext),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n setUIVersion(uiVersion);\n\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n let stores: DataStore<\"CTX\" | \"STATE\" | \"FORM_STATE\">[] = [];\n\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext,\n []\n );\n\n stores = getDataStores(runtimeContext);\n await postAsyncRender(output, runtimeContext, stores);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n for (const store of stores) {\n store.mountAsyncData();\n }\n\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAMA,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;AACA,IAAAW,aAAA,GAAAX,OAAA;AA4BO,SAASY,mBAAmBA,CACjCC,SAAyC,EACzC;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC,MAAM;IACL;IACAG,YAAY,GAAGA,CAAA,KAAM;MACnBJ,MAAM,GAAGK,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MACtCN,MAAM,CAACO,KAAK,CAACC,QAAQ,GAAG,UAAU;MAClCR,MAAM,CAACO,KAAK,CAACE,KAAK,GAAGT,MAAM,CAACO,KAAK,CAACG,MAAM,GAAG,GAAG;MAC9CL,QAAQ,CAACM,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IAAA8E,kBAAW,EAAC9E,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC6F,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"createRoot.js","names":["_lodash","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","_setUIVersion","_setupRootRuntimeContext","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","uiVersion","context","functions","templates","i18n","i18nData","Error","bricks","concat","previousRendererContext","renderId","uniqueId","RendererContext","runtimeContext","ctxStore","DataStore","undefined","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","setupRootRuntimeContext","setTheme","setMode","setUIVersion","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","stores","renderBricks","getDataStores","postAsyncRender","error","node","BRICK","type","properties","textContent","httpErrorToString","return","blockingList","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","store","mountAsyncData","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport {\n RenderOutput,\n getDataStores,\n postAsyncRender,\n renderBricks,\n} from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\nimport { setUIVersion } from \"./setUIVersion.js\";\nimport { setupRootRuntimeContext } from \"./internal/setupRootRuntimeContext.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n uiVersion?: string;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement | DocumentFragment,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n uiVersion,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n\n const previousRendererContext = rendererContext;\n const renderId = uniqueId(\"render-id-\");\n rendererContext = new RendererContext(scope, { unknownBricks, renderId });\n\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\", undefined, rendererContext),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n setupRootRuntimeContext(bricks, runtimeContext);\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n setUIVersion(uiVersion);\n\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n let stores: DataStore<\"CTX\" | \"STATE\" | \"FORM_STATE\">[] = [];\n\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext,\n []\n );\n\n stores = getDataStores(runtimeContext);\n await postAsyncRender(output, runtimeContext, stores);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n for (const store of stores) {\n store.mountAsyncData();\n }\n\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAMA,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;AACA,IAAAW,aAAA,GAAAX,OAAA;AACA,IAAAY,wBAAA,GAAAZ,OAAA;AA4BO,SAASa,mBAAmBA,CACjCC,SAAyC,EACzC;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC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Ae,CAAC,CAAC;QACjC3E,eAAe,CAAC4E,wBAAwB,CAAC,CAAC;QAC1C5E,eAAe,CAAC6E,qBAAqB,CAAC,CAAC;QACvC7E,eAAe,CAAC8E,2BAA2B,CAAC,CAAC;MAC/C;IACF,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAIhF,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAAkE,kBAAW,EAAChF,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAA+E,kBAAW,EAAC/E,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC8F,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
@@ -57,7 +57,6 @@ function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropert
57
57
  slots: new Map()
58
58
  // mergeBases: new Map(),
59
59
  };
60
-
61
60
  if (proxy !== null && proxy !== void 0 && proxy.properties) {
62
61
  for (const [from, to] of Object.entries(proxy.properties)) {
63
62
  let proxies = reversedProxies.properties.get(to.ref);
@@ -1 +1 @@
1
- {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAGO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN,SAAS,CAACM,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIC,oBAAS,CACjC,OAAO,EACPX,SAAS,EACTE,eAAe,EACfE,eACF,CAAC;EACDE,cAAc,CAACM,gBAAgB,CAACC,GAAG,CAACT,eAAe,EAAEM,aAAa,CAAC;EACnE,IAAIJ,cAAc,CAACQ,kBAAkB,EAAE;IACrCR,cAAc,CAACQ,kBAAkB,CAACC,IAAI,CAACL,aAAa,CAAC;EACvD;EAEA,MAAM;IAAEM,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAGC,gCAAe,CAACC,GAAG,CAACvB,UAAU,CAAE;EAC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eAAe,GAAI,CAAC,CAAC,CAAC,CAACR,GAAG,CAAC,CAAC,CAACU,QAAQ,EAAEC,QAAQ,CAAC;IAAA,IAAAC,gBAAA;IAAA,OAAK,CAClEF,QAAQ,EACR;MACEX,IAAI,EAAE,QAAQ;MACd/B,MAAM,EAAE,EAAA4C,gBAAA,GAACD,QAAQ,CAAC3C,MAAM,cAAA4C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEL,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
1
+ {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAGO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN,SAAS,CAACM,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIC,oBAAS,CACjC,OAAO,EACPX,SAAS,EACTE,eAAe,EACfE,eACF,CAAC;EACDE,cAAc,CAACM,gBAAgB,CAACC,GAAG,CAACT,eAAe,EAAEM,aAAa,CAAC;EACnE,IAAIJ,cAAc,CAACQ,kBAAkB,EAAE;IACrCR,cAAc,CAACQ,kBAAkB,CAACC,IAAI,CAACL,aAAa,CAAC;EACvD;EAEA,MAAM;IAAEM,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAGC,gCAAe,CAACC,GAAG,CAACvB,UAAU,CAAE;EAC5EwB,cAAK,aAALA,cAAK,gBAAAnB,cAAA,GAALmB,cAAK,CAAEC,OAAO,cAAApB,cAAA,eAAdA,cAAA,CAAgBqB,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AAA;IAAA,OAAK,CAClEF,QAAQ,EACR;MACEX,IAAI,EAAE,QAAQ;MACd/B,MAAM,EAAE,EAAA4C,gBAAA,GAACD,QAAQ,CAAC3C,MAAM,cAAA4C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEL,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
@@ -15,6 +15,7 @@ exports.createRuntime = createRuntime;
15
15
  exports.getBrickPackages = getBrickPackages;
16
16
  exports.hooks = exports.getRuntime = void 0;
17
17
  var _classPrivateMethodInitSpec2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateMethodInitSpec"));
18
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
19
  var _classPrivateFieldInitSpec2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldInitSpec"));
19
20
  var _classPrivateMethodGet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateMethodGet"));
20
21
  var _classPrivateFieldSet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldSet"));
@@ -105,6 +106,7 @@ class Runtime {
105
106
  writable: true,
106
107
  value: false
107
108
  });
109
+ (0, _defineProperty2.default)(this, "version", 3);
108
110
  }
109
111
  initialize(data) {
110
112
  var _data$settings;
@@ -1 +1 @@
1
- {"version":3,"file":"Runtime.js","names":["_i18n","require","_loader","_general","_moment","_interopRequireDefault","_history","_matchStoryboard","_Router","_i18n2","_Notification","_Dialog","_injected","_hasInstalledApp","_devtools","_getV2RuntimeFromDll","_customizeColorTheme","runtime","bootstrapData","router","hooks","exports","createRuntime","options","Error","listenDevtoolsEagerly","initializeI18n","NS","locales","moment","locale","i18n","language","on","createHistory","Runtime","getRuntimeV3","getRuntimeV2Factory","v2Kit","getV2RuntimeFromDll","getRuntimeV2","Proxy","getRuntime","get","args","key","Reflect","_initialized","WeakMap","_bootstrapped","_getPresetBricks","WeakSet","constructor","_classPrivateMethodInitSpec2","default","_classPrivateFieldInitSpec2","writable","value","initialize","data","_data$settings","_classPrivateFieldGet2","_classPrivateFieldSet2","normalizeBootstrapData","notification","dialog","_classPrivateMethodGet2","_getPresetBricks2","call","loadNotificationService","loadBricks","loadDialogService","customizeColorTheme","settings","misc","theme","bootstrap","Router","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","hasInstalledApp","appId","matchVersion","getFeatureFlags","_bootstrapData","_router3","featureFlags","config","getMiscSettings","_bootstrapData2","_router4","getBrandSettings","_bootstrapData3","base_title","brand","getLaunchpadSettings","_bootstrapData4","columns","rows","launchpad","getDesktops","_bootstrapData$deskto","_bootstrapData5","desktops","getLaunchpadSiteMap","_bootstrapData$siteSo","_bootstrapData6","siteSort","toggleLaunchpadEffect","open","document","body","classList","toggle","applyPageTitle","pageTitle","baseTitle","title","getNavConfig","_router5","bricks","loadBricksImperatively","getBrickPackages","_bootstrapData$settin","_bootstrapData10","presetBricks","Array","isArray","app","ns","id","Object","entries","forEach","lang","resources","addResourceBundle","localeName","getFixedT","name","keys","removeResourceBundle","isObject","deepFreeze","brickPackages","_ref","_ref2","_bootstrapData$brickP","_bootstrapData7","injectedBrickPackages","window","STANDALONE_BRICK_PACKAGES","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData8","matchStoryboard","_internalApiGetRuntimeContext","_router7","getRuntimeContext","_internalApiGetStoryboardInBootstrapData","_bootstrapData9","find","storyboard","_internalApiGetAppInBootstrapData","_internalApiGetStoryb","_test_only_setBootstrapData","process","env","NODE_ENV"],"sources":["../../../src/internal/Runtime.ts"],"sourcesContent":["import type {\n RuntimeStoryboard,\n BootstrapSettings,\n FeatureFlags,\n BootstrapData,\n Contract,\n Storyboard,\n BrickConf,\n RouteConf,\n ResolveConf,\n BrickPackage,\n} from \"@next-core/types\";\nimport { i18n, initializeI18n } from \"@next-core/i18n\";\nimport { loadBricksImperatively } from \"@next-core/loader\";\nimport { deepFreeze, isObject } from \"@next-core/utils/general\";\nimport type { PermissionApi_validatePermissions } from \"@next-api-sdk/micro-app-sdk\";\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 { NS, locales } from \"./i18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\nimport { injectedBrickPackages } from \"./injected.js\";\nimport { type AppForCheck, hasInstalledApp } from \"./hasInstalledApp.js\";\nimport type { RuntimeContext } from \"./interfaces.js\";\nimport { listenDevtoolsEagerly } from \"./devtools.js\";\nimport { getV2RuntimeFromDll } from \"../getV2RuntimeFromDll.js\";\nimport { ThemeSettings, customizeColorTheme } from \"./customizeColorTheme.js\";\n\nlet runtime: Runtime;\n\n// Allow inject bootstrap data in a runtime other than Brick Next.\nlet bootstrapData: BootstrapData | undefined;\nlet router: Router | undefined;\n\nexport interface RuntimeOptions {\n hooks?: RuntimeHooks;\n}\n\nexport interface ImagesFactory {\n get(name: string): string;\n}\n\nexport interface PageViewInfo {\n status: \"ok\" | \"failed\" | \"redirected\" | \"not-found\";\n path?: string;\n pageTitle?: string;\n}\n\nexport interface RuntimeHooks {\n auth?: {\n getAuth(): object;\n isLoggedIn(): boolean;\n authenticate?(...args: unknown[]): unknown;\n logout?(...args: unknown[]): unknown;\n };\n fulfilStoryboard?: (storyboard: RuntimeStoryboard) => Promise<void>;\n validatePermissions?: typeof PermissionApi_validatePermissions;\n checkPermissions?: {\n checkPermissions(...actions: string[]): boolean;\n preCheckPermissions(storyboard: Storyboard): Promise<void> | undefined;\n preCheckPermissionsForBrickOrRoute(\n container: BrickConf | RouteConf,\n asyncComputeRealValue: (value: unknown) => Promise<unknown>\n ): Promise<void> | undefined;\n };\n checkInstalledApps?: {\n preCheckInstalledApps(\n storyboard: Storyboard,\n hasAppInBootstrap: (appId: string) => boolean\n ): void;\n waitForCheckingApps(appIds: string[]): Promise<void>;\n getCheckedApp(appId: string): AppForCheck | undefined;\n };\n flowApi?: {\n FLOW_API_PROVIDER: string;\n registerFlowApiProvider(): void;\n isFlowApiProvider(provider: string): boolean;\n getArgsOfFlowApi(\n provider: string,\n originalArgs: unknown[],\n method?: string\n ): Promise<unknown[]>;\n collectContract(contracts: Contract[] | undefined): void;\n collectWidgetContract(contracts: Contract[] | undefined): void;\n clearCollectWidgetContract(): void;\n };\n menu?: {\n getMenuById(menuId: string): unknown;\n fetchMenuById(\n menuId: string,\n runtimeContext: RuntimeContext,\n runtimeHelpers: RuntimeHooksMenuHelpers\n ): Promise<unknown>;\n };\n images?: {\n imagesFactory(\n appId: string,\n isBuildPush?: boolean,\n version?: string\n ): ImagesFactory;\n widgetImagesFactory(\n widgetId: string,\n widgetVersion?: string\n ): ImagesFactory;\n };\n messageDispatcher?: {\n subscribe(...args: unknown[]): Promise<unknown>;\n unsubscribe(...args: unknown[]): Promise<unknown>;\n onMessage(channel: string, listener: (data: unknown) => void): void;\n onClose(listener: () => void): void;\n reset(): void;\n };\n pageView?: {\n create(): (info: PageViewInfo) => void;\n };\n}\n\nexport interface RuntimeHooksMenuHelpers {\n getStoryboardByAppId(appId: string): Storyboard | undefined;\n resolveData(\n resolveConf: ResolveConf,\n runtimeContext: RuntimeContext\n ): Promise<unknown>;\n asyncComputeRealValue(\n value: unknown,\n runtimeContext: RuntimeContext,\n options?: { ignoreSymbols?: boolean; noInject?: boolean }\n ): Promise<unknown>;\n}\n\nexport let hooks: RuntimeHooks | undefined;\n\nexport function createRuntime(options?: RuntimeOptions) {\n if (runtime) {\n throw new Error(\"Cannot create multiple runtimes\");\n }\n listenDevtoolsEagerly();\n hooks = options?.hooks;\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\nfunction getRuntimeV3() {\n return runtime;\n}\n\n// istanbul ignore next\nfunction getRuntimeV2Factory() {\n const v2Kit = getV2RuntimeFromDll();\n if (v2Kit) {\n return function getRuntimeV2() {\n return new Proxy(v2Kit.getRuntime(), {\n get(...args) {\n const key = args[1];\n switch (key) {\n case \"getCurrentApp\":\n case \"getRecentApps\":\n case \"hasInstalledApp\":\n case \"getDesktops\":\n case \"getLaunchpadSettings\":\n case \"getLaunchpadSiteMap\":\n case \"toggleLaunchpadEffect\":\n case \"applyPageTitle\":\n case \"getNavConfig\":\n case \"getFeatureFlags\":\n case \"getMiscSettings\":\n case \"getBrandSettings\":\n return Reflect.get(...args);\n }\n },\n }) as unknown as Runtime;\n };\n }\n}\n\n// istanbul ignore next\nexport const getRuntime = getRuntimeV2Factory() || getRuntimeV3;\n\nexport class Runtime {\n #initialized = false;\n #bootstrapped = false;\n\n initialize(data: BootstrapData) {\n if (this.#initialized) {\n throw new Error(\"The runtime cannot be initialized more than once\");\n }\n this.#initialized = true;\n normalizeBootstrapData(data);\n bootstrapData = data;\n const { notification, dialog } = this.#getPresetBricks();\n if (notification !== false) {\n loadNotificationService(\n notification ?? \"basic.show-notification\",\n this.loadBricks\n );\n }\n if (dialog !== false) {\n loadDialogService(dialog ?? \"basic.show-dialog\", this.loadBricks);\n }\n customizeColorTheme(data.settings?.misc?.theme as ThemeSettings);\n }\n\n async bootstrap(data?: BootstrapData) {\n if (data) {\n this.initialize(data);\n }\n if (this.#bootstrapped) {\n throw new Error(\"The runtime cannot be bootstrapped more than once\");\n }\n this.#bootstrapped = true;\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 hasInstalledApp(appId: string, matchVersion?: string): boolean {\n return hasInstalledApp(appId, matchVersion);\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 };\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 loadBricks(bricks: string[] | Set<string>) {\n return loadBricksImperatively(bricks, getBrickPackages());\n }\n\n #getPresetBricks() {\n return (bootstrapData?.settings?.presetBricks ?? {}) as {\n notification?: string | false;\n dialog?: string | false;\n };\n }\n}\n\nfunction normalizeBootstrapData(data: BootstrapData) {\n if (Array.isArray(data.storyboards)) {\n for (const { app } of data.storyboards) {\n if (app.locales) {\n // Prefix to avoid conflict between brick package's i18n namespace.\n const ns = `tmp/${app.id}`;\n // Support any languages in `app.locales`.\n Object.entries(app.locales).forEach(([lang, resources]) => {\n i18n.addResourceBundle(lang, ns, resources);\n });\n // Use `app.name` as the fallback `app.localeName`.\n app.localeName = i18n.getFixedT(null, ns)(\"name\", app.name) as string;\n // Remove the temporary i18n resource bundles.\n Object.keys(app.locales).forEach((lang) => {\n i18n.removeResourceBundle(lang, ns);\n });\n } else {\n app.localeName = app.name;\n }\n }\n }\n if (isObject(data.settings)) {\n deepFreeze(data.settings);\n }\n if (data.brickPackages) {\n deepFreeze(data.brickPackages);\n }\n}\n\nexport function getBrickPackages() {\n return (\n bootstrapData?.brickPackages ??\n injectedBrickPackages ??\n (window.STANDALONE_BRICK_PACKAGES as BrickPackage[]) ??\n []\n );\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\nexport let _test_only_setBootstrapData: (data: BootstrapData) => void;\n\n// istanbul ignore next\nif (process.env.NODE_ENV === \"test\") {\n _test_only_setBootstrapData = (data) => {\n bootstrapData = data as BootstrapData;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAYA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACAA,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,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AACpE;AAEO,SAASI,6BAA6BA,CAAA,EAAG;EAAA,IAAAC,QAAA;EAC9C,QAAAA,QAAA,GAAOnJ,MAAM,cAAAmJ,QAAA,uBAANA,QAAA,CAAQC,iBAAiB,CAAC,CAAC;AACpC;AAEO,SAASC,wCAAwCA,CAAClF,KAAa,EAAE;EAAA,IAAAmF,eAAA;EACtE,QAAAA,eAAA,GAAOvJ,aAAa,cAAAuJ,eAAA,gBAAAA,eAAA,GAAbA,eAAA,CAAe3F,WAAW,cAAA2F,eAAA,uBAA1BA,eAAA,CAA4BC,IAAI,CACpCC,UAAU,IAAKA,UAAU,CAACtC,GAAG,CAACE,EAAE,KAAKjD,KACxC,CAAC;AACH;AAEO,SAASsF,iCAAiCA,CAACtF,KAAa,EAAE;EAAA,IAAAuF,qBAAA;EAC/D,QAAAA,qBAAA,GAAOL,wCAAwC,CAAClF,KAAK,CAAC,cAAAuF,qBAAA,uBAA/CA,qBAAA,CAAiDxC,GAAG;AAC7D;AAEO,IAAIyC,2BAA0D,GAAAzJ,OAAA,CAAAyJ,2BAAA;;AAErE;AACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;EACnC5J,OAAA,CAAAyJ,2BAAA,GAAAA,2BAA2B,GAAInH,IAAI,IAAK;IACtCzC,aAAa,GAAGyC,IAAqB;EACvC,CAAC;AACH"}
1
+ {"version":3,"file":"Runtime.js","names":["_i18n","require","_loader","_general","_moment","_interopRequireDefault","_history","_matchStoryboard","_Router","_i18n2","_Notification","_Dialog","_injected","_hasInstalledApp","_devtools","_getV2RuntimeFromDll","_customizeColorTheme","runtime","bootstrapData","router","hooks","exports","createRuntime","options","Error","listenDevtoolsEagerly","initializeI18n","NS","locales","moment","locale","i18n","language","on","createHistory","Runtime","getRuntimeV3","getRuntimeV2Factory","v2Kit","getV2RuntimeFromDll","getRuntimeV2","Proxy","getRuntime","get","args","key","Reflect","_initialized","WeakMap","_bootstrapped","_getPresetBricks","WeakSet","constructor","_classPrivateMethodInitSpec2","default","_classPrivateFieldInitSpec2","writable","value","_defineProperty2","initialize","data","_data$settings","_classPrivateFieldGet2","_classPrivateFieldSet2","normalizeBootstrapData","notification","dialog","_classPrivateMethodGet2","_getPresetBricks2","call","loadNotificationService","loadBricks","loadDialogService","customizeColorTheme","settings","misc","theme","bootstrap","Router","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","hasInstalledApp","appId","matchVersion","getFeatureFlags","_bootstrapData","_router3","featureFlags","config","getMiscSettings","_bootstrapData2","_router4","getBrandSettings","_bootstrapData3","base_title","brand","getLaunchpadSettings","_bootstrapData4","columns","rows","launchpad","getDesktops","_bootstrapData$deskto","_bootstrapData5","desktops","getLaunchpadSiteMap","_bootstrapData$siteSo","_bootstrapData6","siteSort","toggleLaunchpadEffect","open","document","body","classList","toggle","applyPageTitle","pageTitle","baseTitle","title","getNavConfig","_router5","bricks","loadBricksImperatively","getBrickPackages","_bootstrapData$settin","_bootstrapData10","presetBricks","Array","isArray","app","ns","id","Object","entries","forEach","lang","resources","addResourceBundle","localeName","getFixedT","name","keys","removeResourceBundle","isObject","deepFreeze","brickPackages","_ref","_ref2","_bootstrapData$brickP","_bootstrapData7","injectedBrickPackages","window","STANDALONE_BRICK_PACKAGES","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData8","matchStoryboard","_internalApiGetRuntimeContext","_router7","getRuntimeContext","_internalApiGetStoryboardInBootstrapData","_bootstrapData9","find","storyboard","_internalApiGetAppInBootstrapData","_internalApiGetStoryb","_test_only_setBootstrapData","process","env","NODE_ENV"],"sources":["../../../src/internal/Runtime.ts"],"sourcesContent":["import type {\n RuntimeStoryboard,\n BootstrapSettings,\n FeatureFlags,\n BootstrapData,\n Contract,\n Storyboard,\n BrickConf,\n RouteConf,\n ResolveConf,\n BrickPackage,\n} from \"@next-core/types\";\nimport { i18n, initializeI18n } from \"@next-core/i18n\";\nimport { loadBricksImperatively } from \"@next-core/loader\";\nimport { deepFreeze, isObject } from \"@next-core/utils/general\";\nimport type { PermissionApi_validatePermissions } from \"@next-api-sdk/micro-app-sdk\";\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 { NS, locales } from \"./i18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\nimport { injectedBrickPackages } from \"./injected.js\";\nimport { type AppForCheck, hasInstalledApp } from \"./hasInstalledApp.js\";\nimport type { RuntimeContext } from \"./interfaces.js\";\nimport { listenDevtoolsEagerly } from \"./devtools.js\";\nimport { getV2RuntimeFromDll } from \"../getV2RuntimeFromDll.js\";\nimport { ThemeSettings, customizeColorTheme } from \"./customizeColorTheme.js\";\n\nlet runtime: Runtime;\n\n// Allow inject bootstrap data in a runtime other than Brick Next.\nlet bootstrapData: BootstrapData | undefined;\nlet router: Router | undefined;\n\nexport interface RuntimeOptions {\n hooks?: RuntimeHooks;\n}\n\nexport interface ImagesFactory {\n get(name: string): string;\n}\n\nexport interface PageViewInfo {\n status: \"ok\" | \"failed\" | \"redirected\" | \"not-found\";\n path?: string;\n pageTitle?: string;\n}\n\nexport interface RuntimeHooks {\n auth?: {\n getAuth(): object;\n isLoggedIn(): boolean;\n authenticate?(...args: unknown[]): unknown;\n logout?(...args: unknown[]): unknown;\n };\n fulfilStoryboard?: (storyboard: RuntimeStoryboard) => Promise<void>;\n validatePermissions?: typeof PermissionApi_validatePermissions;\n checkPermissions?: {\n checkPermissions(...actions: string[]): boolean;\n preCheckPermissions(storyboard: Storyboard): Promise<void> | undefined;\n preCheckPermissionsForBrickOrRoute(\n container: BrickConf | RouteConf,\n asyncComputeRealValue: (value: unknown) => Promise<unknown>\n ): Promise<void> | undefined;\n };\n checkInstalledApps?: {\n preCheckInstalledApps(\n storyboard: Storyboard,\n hasAppInBootstrap: (appId: string) => boolean\n ): void;\n waitForCheckingApps(appIds: string[]): Promise<void>;\n getCheckedApp(appId: string): AppForCheck | undefined;\n };\n flowApi?: {\n FLOW_API_PROVIDER: string;\n registerFlowApiProvider(): void;\n isFlowApiProvider(provider: string): boolean;\n getArgsOfFlowApi(\n provider: string,\n originalArgs: unknown[],\n method?: string\n ): Promise<unknown[]>;\n collectContract(contracts: Contract[] | undefined): void;\n collectWidgetContract(contracts: Contract[] | undefined): void;\n clearCollectWidgetContract(): void;\n };\n menu?: {\n getMenuById(menuId: string): unknown;\n fetchMenuById(\n menuId: string,\n runtimeContext: RuntimeContext,\n runtimeHelpers: RuntimeHooksMenuHelpers\n ): Promise<unknown>;\n };\n images?: {\n imagesFactory(\n appId: string,\n isBuildPush?: boolean,\n version?: string\n ): ImagesFactory;\n widgetImagesFactory(\n widgetId: string,\n widgetVersion?: string\n ): ImagesFactory;\n };\n messageDispatcher?: {\n subscribe(...args: unknown[]): Promise<unknown>;\n unsubscribe(...args: unknown[]): Promise<unknown>;\n onMessage(channel: string, listener: (data: unknown) => void): void;\n onClose(listener: () => void): void;\n reset(): void;\n };\n pageView?: {\n create(): (info: PageViewInfo) => void;\n };\n}\n\nexport interface RuntimeHooksMenuHelpers {\n getStoryboardByAppId(appId: string): Storyboard | undefined;\n resolveData(\n resolveConf: ResolveConf,\n runtimeContext: RuntimeContext\n ): Promise<unknown>;\n asyncComputeRealValue(\n value: unknown,\n runtimeContext: RuntimeContext,\n options?: { ignoreSymbols?: boolean; noInject?: boolean }\n ): Promise<unknown>;\n}\n\nexport let hooks: RuntimeHooks | undefined;\n\nexport function createRuntime(options?: RuntimeOptions) {\n if (runtime) {\n throw new Error(\"Cannot create multiple runtimes\");\n }\n listenDevtoolsEagerly();\n hooks = options?.hooks;\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\nfunction getRuntimeV3() {\n return runtime;\n}\n\n// istanbul ignore next\nfunction getRuntimeV2Factory() {\n const v2Kit = getV2RuntimeFromDll();\n if (v2Kit) {\n return function getRuntimeV2() {\n return new Proxy(v2Kit.getRuntime(), {\n get(...args) {\n const key = args[1];\n switch (key) {\n case \"getCurrentApp\":\n case \"getRecentApps\":\n case \"hasInstalledApp\":\n case \"getDesktops\":\n case \"getLaunchpadSettings\":\n case \"getLaunchpadSiteMap\":\n case \"toggleLaunchpadEffect\":\n case \"applyPageTitle\":\n case \"getNavConfig\":\n case \"getFeatureFlags\":\n case \"getMiscSettings\":\n case \"getBrandSettings\":\n return Reflect.get(...args);\n }\n },\n }) as unknown as Runtime;\n };\n }\n}\n\n// istanbul ignore next\nexport const getRuntime = getRuntimeV2Factory() || getRuntimeV3;\n\nexport class Runtime {\n #initialized = false;\n #bootstrapped = false;\n\n readonly version: number | undefined = 3;\n\n initialize(data: BootstrapData) {\n if (this.#initialized) {\n throw new Error(\"The runtime cannot be initialized more than once\");\n }\n this.#initialized = true;\n normalizeBootstrapData(data);\n bootstrapData = data;\n const { notification, dialog } = this.#getPresetBricks();\n if (notification !== false) {\n loadNotificationService(\n notification ?? \"basic.show-notification\",\n this.loadBricks\n );\n }\n if (dialog !== false) {\n loadDialogService(dialog ?? \"basic.show-dialog\", this.loadBricks);\n }\n customizeColorTheme(data.settings?.misc?.theme as ThemeSettings);\n }\n\n async bootstrap(data?: BootstrapData) {\n if (data) {\n this.initialize(data);\n }\n if (this.#bootstrapped) {\n throw new Error(\"The runtime cannot be bootstrapped more than once\");\n }\n this.#bootstrapped = true;\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 hasInstalledApp(appId: string, matchVersion?: string): boolean {\n return hasInstalledApp(appId, matchVersion);\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 };\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 loadBricks(bricks: string[] | Set<string>) {\n return loadBricksImperatively(bricks, getBrickPackages());\n }\n\n #getPresetBricks() {\n return (bootstrapData?.settings?.presetBricks ?? {}) as {\n notification?: string | false;\n dialog?: string | false;\n };\n }\n}\n\nfunction normalizeBootstrapData(data: BootstrapData) {\n if (Array.isArray(data.storyboards)) {\n for (const { app } of data.storyboards) {\n if (app.locales) {\n // Prefix to avoid conflict between brick package's i18n namespace.\n const ns = `tmp/${app.id}`;\n // Support any languages in `app.locales`.\n Object.entries(app.locales).forEach(([lang, resources]) => {\n i18n.addResourceBundle(lang, ns, resources);\n });\n // Use `app.name` as the fallback `app.localeName`.\n app.localeName = i18n.getFixedT(null, ns)(\"name\", app.name) as string;\n // Remove the temporary i18n resource bundles.\n Object.keys(app.locales).forEach((lang) => {\n i18n.removeResourceBundle(lang, ns);\n });\n } else {\n app.localeName = app.name;\n }\n }\n }\n if (isObject(data.settings)) {\n deepFreeze(data.settings);\n }\n if (data.brickPackages) {\n deepFreeze(data.brickPackages);\n }\n}\n\nexport function getBrickPackages() {\n return (\n bootstrapData?.brickPackages ??\n injectedBrickPackages ??\n (window.STANDALONE_BRICK_PACKAGES as BrickPackage[]) ??\n []\n );\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\nexport let _test_only_setBootstrapData: (data: BootstrapData) => void;\n\n// istanbul ignore next\nif (process.env.NODE_ENV === \"test\") {\n _test_only_setBootstrapData = (data) => {\n bootstrapData = data as BootstrapData;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACAA,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,aAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA;AACA,IAAAW,SAAA,GAAAX,OAAA;AACA,IAAAY,gBAAA,GAAAZ,OAAA;AAEA,IAAAa,SAAA,GAAAb,OAAA;AACA,IAAAc,oBAAA,GAAAd,OAAA;AACA,IAAAe,oBAAA,GAA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pC;AAEO,SAASC,wCAAwCA,CAAClF,KAAa,EAAE;EAAA,IAAAmF,eAAA;EACtE,QAAAA,eAAA,GAAOxJ,aAAa,cAAAwJ,eAAA,gBAAAA,eAAA,GAAbA,eAAA,CAAe3F,WAAW,cAAA2F,eAAA,uBAA1BA,eAAA,CAA4BC,IAAI,CACpCC,UAAU,IAAKA,UAAU,CAACtC,GAAG,CAACE,EAAE,KAAKjD,KACxC,CAAC;AACH;AAEO,SAASsF,iCAAiCA,CAACtF,KAAa,EAAE;EAAA,IAAAuF,qBAAA;EAC/D,QAAAA,qBAAA,GAAOL,wCAAwC,CAAClF,KAAK,CAAC,cAAAuF,qBAAA,uBAA/CA,qBAAA,CAAiDxC,GAAG;AAC7D;AAEO,IAAIyC,2BAA0D,GAAA1J,OAAA,CAAA0J,2BAAA;;AAErE;AACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;EACnC7J,OAAA,CAAA0J,2BAAA,GAAAA,2BAA2B,GAAInH,IAAI,IAAK;IACtC1C,aAAa,GAAG0C,IAAqB;EACvC,CAAC;AACH"}
@@ -54,7 +54,6 @@ function getIndividualGlobal(variableName, {
54
54
  getTheme: collectCoverage ? () => "light" : _themeAndMode.getTheme
55
55
  // getCssPropertyValue: collectCoverage ? () => "" : getCssPropertyValue,
56
56
  });
57
-
58
57
  case "console":
59
58
  return isStoryboardFunction ? (0, _proxyFactories.getReadOnlyProxy)(console) : undefined;
60
59
  case "location":
@@ -1 +1 @@
1
- {"version":3,"file":"getGeneralGlobals.js","names":["_lodash","require","_i18n","_WidgetI18n","_proxyFactories","_themeAndMode","_getBasePath","_registerAppI18n","_Runtime","getGeneralGlobals","attemptToVisitGlobals","options","globalVariables","variableName","variable","getIndividualGlobal","undefined","collectCoverage","widgetId","widgetVersion","app","appendI18nNamespace","storyboardFunctions","isStoryboardFunction","_hooks$images","_hooks$images2","_hooks$checkPermissio","getBasePath","replace","fakeImageFactory","hooks","images","widgetImagesFactory","imagesFactory","id","isBuildPush","currentVersion","identity","widgetI18nFactory","i18n","getFixedT","getI18nNamespace","filter","Boolean","fakeI18nText","i18nText","getReadOnlyProxy","check","fakeCheckPermissions","checkPermissions","getTheme","console","href","origin","host","hostname","location","data","en","get","name"],"sources":["../../../../src/internal/compute/getGeneralGlobals.ts"],"sourcesContent":["import { identity } from \"lodash\";\nimport type { MicroApp } from \"@next-core/types\";\nimport { i18n, i18nText } from \"@next-core/i18n\";\nimport { widgetI18nFactory } from \"./WidgetI18n.js\";\nimport { getReadOnlyProxy } from \"../proxyFactories.js\";\nimport { getTheme } from \"../../themeAndMode.js\";\nimport { getBasePath } from \"../../getBasePath.js\";\nimport { getI18nNamespace } from \"../registerAppI18n.js\";\nimport { ImagesFactory, hooks } from \"../Runtime.js\";\n\nexport interface GeneralGlobalsOptions {\n collectCoverage?: unknown;\n widgetId?: string;\n widgetVersion?: string;\n app?: PartialMicroApp;\n appendI18nNamespace?: string;\n storyboardFunctions?: unknown;\n isStoryboardFunction?: boolean;\n}\n\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n// `GeneralGlobals` are globals which are page-state-agnostic,\n// thus they can be used both in storyboard expressions and functions.\nexport function getGeneralGlobals(\n attemptToVisitGlobals: Set<string>,\n options: GeneralGlobalsOptions\n): Record<string, unknown> {\n const globalVariables: Record<string, unknown> = {};\n for (const variableName of attemptToVisitGlobals) {\n const variable = getIndividualGlobal(variableName, options);\n if (variable !== undefined) {\n globalVariables[variableName] = variable;\n }\n }\n return globalVariables;\n}\n\nfunction getIndividualGlobal(\n variableName: string,\n {\n collectCoverage,\n widgetId,\n widgetVersion,\n app,\n appendI18nNamespace,\n storyboardFunctions,\n isStoryboardFunction,\n }: GeneralGlobalsOptions\n): unknown {\n switch (variableName) {\n case \"BASE_URL\":\n return collectCoverage ? \"/next\" : getBasePath().replace(/\\/$/, \"\");\n case \"FN\":\n return storyboardFunctions;\n case \"IMG\":\n return collectCoverage\n ? fakeImageFactory()\n : widgetId\n ? hooks?.images?.widgetImagesFactory(widgetId, widgetVersion)\n : hooks?.images?.imagesFactory(\n app!.id,\n app!.isBuildPush,\n (app as { currentVersion?: string }).currentVersion\n );\n case \"I18N\":\n return collectCoverage\n ? identity\n : widgetId\n ? widgetI18nFactory(widgetId)\n : i18n.getFixedT(\n null,\n [appendI18nNamespace, getI18nNamespace(\"app\", app!.id)].filter(\n Boolean\n ) as string[]\n );\n case \"I18N_TEXT\":\n return collectCoverage ? fakeI18nText : i18nText;\n case \"PERMISSIONS\":\n return getReadOnlyProxy({\n check: collectCoverage\n ? fakeCheckPermissions\n : hooks?.checkPermissions?.checkPermissions,\n });\n case \"THEME\":\n return getReadOnlyProxy({\n getTheme: collectCoverage ? () => \"light\" : getTheme,\n // getCssPropertyValue: collectCoverage ? () => \"\" : getCssPropertyValue,\n });\n case \"console\":\n return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;\n case \"location\":\n return collectCoverage\n ? {\n href: \"http://localhost:3000/functions/test\",\n origin: \"http://localhost:3000\",\n host: \"localhost:3000\",\n hostname: \"localhost\",\n }\n : {\n href: location.href,\n origin: location.origin,\n host: location.host,\n hostname: location.hostname,\n };\n }\n}\n\nfunction fakeI18nText(data: Record<string, string>): string {\n return data?.en;\n}\n\nfunction fakeImageFactory(): ImagesFactory {\n return {\n get(name: string) {\n return `mock/images/${name}`;\n },\n };\n}\n\nfunction fakeCheckPermissions(): boolean {\n return true;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAcA;AACA;AACO,SAASQ,iBAAiBA,CAC/BC,qBAAkC,EAClCC,OA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EA,SAASZ,oBAAoBA,CAAA,EAAY;EACvC,OAAO,IAAI;AACb"}
1
+ {"version":3,"file":"getGeneralGlobals.js","names":["_lodash","require","_i18n","_WidgetI18n","_proxyFactories","_themeAndMode","_getBasePath","_registerAppI18n","_Runtime","getGeneralGlobals","attemptToVisitGlobals","options","globalVariables","variableName","variable","getIndividualGlobal","undefined","collectCoverage","widgetId","widgetVersion","app","appendI18nNamespace","storyboardFunctions","isStoryboardFunction","_hooks$images","_hooks$images2","_hooks$checkPermissio","getBasePath","replace","fakeImageFactory","hooks","images","widgetImagesFactory","imagesFactory","id","isBuildPush","currentVersion","identity","widgetI18nFactory","i18n","getFixedT","getI18nNamespace","filter","Boolean","fakeI18nText","i18nText","getReadOnlyProxy","check","fakeCheckPermissions","checkPermissions","getTheme","console","href","origin","host","hostname","location","data","en","get","name"],"sources":["../../../../src/internal/compute/getGeneralGlobals.ts"],"sourcesContent":["import { identity } from \"lodash\";\nimport type { MicroApp } from \"@next-core/types\";\nimport { i18n, i18nText } from \"@next-core/i18n\";\nimport { widgetI18nFactory } from \"./WidgetI18n.js\";\nimport { getReadOnlyProxy } from \"../proxyFactories.js\";\nimport { getTheme } from \"../../themeAndMode.js\";\nimport { getBasePath } from \"../../getBasePath.js\";\nimport { getI18nNamespace } from \"../registerAppI18n.js\";\nimport { ImagesFactory, hooks } from \"../Runtime.js\";\n\nexport interface GeneralGlobalsOptions {\n collectCoverage?: unknown;\n widgetId?: string;\n widgetVersion?: string;\n app?: PartialMicroApp;\n appendI18nNamespace?: string;\n storyboardFunctions?: unknown;\n isStoryboardFunction?: boolean;\n}\n\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n// `GeneralGlobals` are globals which are page-state-agnostic,\n// thus they can be used both in storyboard expressions and functions.\nexport function getGeneralGlobals(\n attemptToVisitGlobals: Set<string>,\n options: GeneralGlobalsOptions\n): Record<string, unknown> {\n const globalVariables: Record<string, unknown> = {};\n for (const variableName of attemptToVisitGlobals) {\n const variable = getIndividualGlobal(variableName, options);\n if (variable !== undefined) {\n globalVariables[variableName] = variable;\n }\n }\n return globalVariables;\n}\n\nfunction getIndividualGlobal(\n variableName: string,\n {\n collectCoverage,\n widgetId,\n widgetVersion,\n app,\n appendI18nNamespace,\n storyboardFunctions,\n isStoryboardFunction,\n }: GeneralGlobalsOptions\n): unknown {\n switch (variableName) {\n case \"BASE_URL\":\n return collectCoverage ? \"/next\" : getBasePath().replace(/\\/$/, \"\");\n case \"FN\":\n return storyboardFunctions;\n case \"IMG\":\n return collectCoverage\n ? fakeImageFactory()\n : widgetId\n ? hooks?.images?.widgetImagesFactory(widgetId, widgetVersion)\n : hooks?.images?.imagesFactory(\n app!.id,\n app!.isBuildPush,\n (app as { currentVersion?: string }).currentVersion\n );\n case \"I18N\":\n return collectCoverage\n ? identity\n : widgetId\n ? widgetI18nFactory(widgetId)\n : i18n.getFixedT(\n null,\n [appendI18nNamespace, getI18nNamespace(\"app\", app!.id)].filter(\n Boolean\n ) as string[]\n );\n case \"I18N_TEXT\":\n return collectCoverage ? fakeI18nText : i18nText;\n case \"PERMISSIONS\":\n return getReadOnlyProxy({\n check: collectCoverage\n ? fakeCheckPermissions\n : hooks?.checkPermissions?.checkPermissions,\n });\n case \"THEME\":\n return getReadOnlyProxy({\n getTheme: collectCoverage ? () => \"light\" : getTheme,\n // getCssPropertyValue: collectCoverage ? () => \"\" : getCssPropertyValue,\n });\n case \"console\":\n return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;\n case \"location\":\n return collectCoverage\n ? {\n href: \"http://localhost:3000/functions/test\",\n origin: \"http://localhost:3000\",\n host: \"localhost:3000\",\n hostname: \"localhost\",\n }\n : {\n href: location.href,\n origin: location.origin,\n host: location.host,\n hostname: location.hostname,\n };\n }\n}\n\nfunction fakeI18nText(data: Record<string, string>): string {\n return data?.en;\n}\n\nfunction fakeImageFactory(): ImagesFactory {\n return {\n get(name: string) {\n return `mock/images/${name}`;\n },\n };\n}\n\nfunction fak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Q,CAACH,MAAM;QACvBC,IAAI,EAAEE,QAAQ,CAACF,IAAI;QACnBC,QAAQ,EAAEC,QAAQ,CAACD;MACrB,CAAC;EACT;AACF;AAEA,SAASX,YAAYA,CAACa,IAA4B,EAAU;EAC1D,OAAOA,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEC,EAAE;AACjB;AAEA,SAAS7B,gBAAgBA,CAAA,EAAkB;EACzC,OAAO;IACL8B,GAAGA,CAACC,IAAY,EAAE;MAChB,OAAQ,eAAcA,IAAK,EAAC;IAC9B;EACF,CAAC;AACH;AAEA,SAASZ,oBAAoBA,CAAA,EAAY;EACvC,OAAO,IAAI;AACb"}
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "setRealTimeDataInspectRoot", {
23
23
  return _realTimeDataInspect.setRealTimeDataInspectRoot;
24
24
  }
25
25
  });
26
+ exports.symbolForRootRuntimeContext = void 0;
26
27
  exports.unmountUseBrick = unmountUseBrick;
27
28
  exports.updateSnippetPreviewSettings = void 0;
28
29
  exports.updateStoryboard = updateStoryboard;
@@ -42,10 +43,11 @@ var _CustomTemplates = require("../CustomTemplates.js");
42
43
  var _registerAppI18n = require("./registerAppI18n.js");
43
44
  var _utils = require("./CustomTemplates/utils.js");
44
45
  var _realTimeDataInspect = require("./data/realTimeDataInspect.js");
46
+ const symbolForRootRuntimeContext = exports.symbolForRootRuntimeContext = Symbol.for("root.runtimeContext");
45
47
  async function renderUseBrick(useBrick, data) {
46
- var _scopedRuntimeContext, _scopedRuntimeContext2, _output$node, _output$node2;
48
+ var _useBrick$symbolForRo, _scopedRuntimeContext, _scopedRuntimeContext2, _output$node, _output$node2;
47
49
  const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = (0, _Renderer.createScopedRuntimeContext)({
48
- ...(0, _Runtime._internalApiGetRuntimeContext)(),
50
+ ...((_useBrick$symbolForRo = useBrick[symbolForRootRuntimeContext]) !== null && _useBrick$symbolForRo !== void 0 ? _useBrick$symbolForRo : (0, _Runtime._internalApiGetRuntimeContext)()),
49
51
  data,
50
52
  pendingPermissionsPreCheck: []
51
53
  });
@@ -1 +1 @@
1
- {"version":3,"file":"secret_internals.js","names":["_lodash","require","_Runtime","_Renderer","_RendererContext","_mount","_enums","_computeRealValue","_isStrictMode","_CustomTemplates","_registerAppI18n","_utils","_realTimeDataInspect","renderUseBrick","useBrick","data","_scopedRuntimeContext","_scopedRuntimeContext2","_output$node","_output$node2","scopedRuntimeContext","tplStateStoreScope","formStateStoreScope","createScopedRuntimeContext","_internalApiGetRuntimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","rendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","createPortal","transform","strict","isStrictMode","warnAboutStrictMode","output","renderBrick","properties","scopedStores","postAsyncRender","node","PLACEHOLDER","Error","portal","child","tagName","type","mountUseBrick","element","portalRoot","document","querySelector","createElement","appendChild","mountTree","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","store","mountAsyncData","unmountUseBrick","mountResult","unmountTree","remove","dispatchOnUnmount","dispose","legacyDoTransform","to","options","computeRealValue","noInject","updateStoryboard","appId","storyboardPatch","storyboard","_internalApiGetStoryboardInBootstrapData","Object","assign","meta","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","registerAppI18n","updateStoryboardByRoute","newRoute","match","getKey","route","path","exact","replaceRoute","routes","key","map","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","customTemplates","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","pick","getSnippetPreviewPath","snippetId","updateStoryboardBySnippet","snippetData","_snippetData$bricks","length","context","updateSnippetPreviewSettings","exports","previewRouteIndex","findIndex","newPreviewRoute","menu","splice","getContextValue","tplStateStoreId","runtimeContext","tplStateStore","getTplStateStore","getValue","ctxStore","getAllContextValues","getAllValues","getBrickPackagesById","id","getBrickPackages","find","pkg","filePath","startsWith","getRenderId","_internalApiGetRenderId","getAddedContracts","updateStoryboardType","collectUsedContracts","updatedStoryboard","_storyboard$routes","snippetPreviewPath","currentRoute","addedContracts","contractApis","forEach","api","_storyboard$meta","_","namespaceId","contracts","some","contract","push"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n RuntimeSnippet,\n ContextConf,\n} from \"@next-core/types\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRenderId,\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n getBrickPackages,\n} from \"./Runtime.js\";\nimport {\n createScopedRuntimeContext,\n postAsyncRender,\n renderBrick,\n} from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type {\n DataValueOption,\n PreviewOption,\n PreviewStoryboardPatch,\n RenderRoot,\n} 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 { getTplStateStore } from \"./CustomTemplates/utils.js\";\n\nexport type { DataValueOption, RuntimeContext } from \"./interfaces.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n scopedStores: DataStore<\"STATE\" | \"FORM_STATE\">[];\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] =\n createScopedRuntimeContext({\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n });\n\n scopedRuntimeContext.tplStateStoreMap ??= new Map();\n scopedRuntimeContext.formStateStoreMap ??= 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 scopedRuntimeContext,\n rendererContext,\n []\n );\n\n const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];\n\n await postAsyncRender(output, scopedRuntimeContext, scopedStores);\n\n if (output.node?.tag === RenderTag.PLACEHOLDER) {\n throw new Error(\n \"The root brick of useBrick cannot be an ignored control node\"\n );\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, scopedStores };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext, scopedStores }: 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 rendererContext.initializeMessageDispatcher();\n\n for (const store of scopedStores) {\n store.mountAsyncData();\n }\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\n/** For v2 compatibility of `doTransform` from brick-kit. */\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 function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n meta: {\n // Keep runtime fields such as `injectMenus`\n ...storyboard.meta,\n ...storyboardPatch.meta,\n },\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(\n settings,\n \"properties\",\n \"events\",\n \"lifeCycle\",\n \"context\",\n \"slots\",\n \"children\"\n ),\n },\n ]\n );\n}\n\nfunction getSnippetPreviewPath(snippetId: string): string {\n return `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetId}`;\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n context?: ContextConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n getSnippetPreviewPath(snippetData.snippetId),\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }],\n snippetData.context\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[],\n context?: ContextConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n context,\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\nexport function getContextValue(\n name: string,\n { tplStateStoreId }: DataValueOption\n): unknown {\n const runtimeContext = _internalApiGetRuntimeContext()!;\n\n if (tplStateStoreId) {\n const tplStateStore = getTplStateStore(\n {\n ...runtimeContext,\n tplStateStoreId,\n },\n \"STATE\"\n );\n return tplStateStore.getValue(name);\n }\n\n return runtimeContext.ctxStore.getValue(name);\n}\n\nexport function getAllContextValues({\n tplStateStoreId,\n}: DataValueOption): Record<string, unknown> {\n const runtimeContext = _internalApiGetRuntimeContext()!;\n\n if (tplStateStoreId) {\n const tplStateStore = getTplStateStore(\n {\n ...runtimeContext,\n tplStateStoreId,\n },\n \"STATE\"\n );\n return tplStateStore.getAllValues();\n }\n\n return runtimeContext.ctxStore.getAllValues();\n}\n\nexport function getBrickPackagesById(id: string) {\n return getBrickPackages().find((pkg) =>\n pkg.id ? pkg.id === id : pkg.filePath.startsWith(id)\n );\n}\n\nexport function getRenderId() {\n return _internalApiGetRenderId();\n}\n\nexport async function getAddedContracts(\n storyboardPatch: PreviewStoryboardPatch,\n { appId, updateStoryboardType, collectUsedContracts }: PreviewOption\n): Promise<string[]> {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId);\n let updatedStoryboard;\n\n // 拿到更新部分的 storyboard 配置,然后扫描一遍,找到新增的 contracts\n if (updateStoryboardType === \"route\") {\n updatedStoryboard = {\n routes: [storyboardPatch as RouteConf],\n } as Storyboard;\n } else if (updateStoryboardType === \"template\") {\n updatedStoryboard = {\n meta: {\n customTemplates: [storyboardPatch as CustomTemplate],\n },\n } as Storyboard;\n } else if (updateStoryboardType === \"snippet\") {\n // snippet 是放在挂载 route 里预览,通过 previewPath 拿到当前修改 route\n const snippetPreviewPath = getSnippetPreviewPath(\n (storyboardPatch as RuntimeSnippet).snippetId\n );\n const currentRoute = storyboard?.routes?.find(\n (route) => route.path === snippetPreviewPath\n );\n\n updatedStoryboard = {\n routes: [currentRoute],\n } as Storyboard;\n }\n\n const addedContracts: string[] = [];\n\n if (updatedStoryboard && collectUsedContracts) {\n const contractApis = await collectUsedContracts(updatedStoryboard);\n\n contractApis.forEach((api: string) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [_, namespaceId, name] = api.match(\n /(.*)@(.*):\\d\\.\\d\\.\\d/\n ) as string[];\n\n if (\n !storyboard?.meta?.contracts?.some(\n (contract) =>\n contract.namespaceId === namespaceId && contract.name === name\n )\n ) {\n addedContracts.push(api);\n }\n });\n }\n\n return addedContracts;\n}\n\nexport {\n setRealTimeDataInspectRoot,\n addRealTimeDataInspectHook,\n} from \"./data/realTimeDataInspect.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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BvD,MAAM,EAAE,CAAC0D,YAAY;IACvB,CAAe;EACjB;EAEA,MAAMC,cAAwB,GAAG,EAAE;EAEnC,IAAIJ,iBAAiB,IAAID,oBAAoB,EAAE;IAC7C,MAAMM,YAAY,GAAG,MAAMN,oBAAoB,CAACC,iBAAiB,CAAC;IAElEK,YAAY,CAACC,OAAO,CAAEC,GAAW,IAAK;MAAA,IAAAC,gBAAA;MACpC;MACA,MAAM,CAACC,CAAC,EAAEC,WAAW,EAAExD,IAAI,CAAC,GAAGqD,GAAG,CAACpE,KAAK,CACtC,sBACF,CAAa;MAEb,IACE,EAACX,UAAU,aAAVA,UAAU,gBAAAgF,gBAAA,GAAVhF,UAAU,CAAEI,IAAI,cAAA4E,gBAAA,gBAAAA,gBAAA,GAAhBA,gBAAA,CAAkBG,SAAS,cAAAH,gBAAA,eAA3BA,gBAAA,CAA6BI,IAAI,CAC/BC,QAAQ,IACPA,QAAQ,CAACH,WAAW,KAAKA,WAAW,IAAIG,QAAQ,CAAC3D,IAAI,KAAKA,IAC9D,CAAC,GACD;QACAkD,cAAc,CAACU,IAAI,CAACP,GAAG,CAAC;MAC1B;IACF,CAAC,CAAC;EACJ;EAEA,OAAOH,cAAc;AACvB"}
1
+ {"version":3,"file":"secret_internals.js","names":["_lodash","require","_Runtime","_Renderer","_RendererContext","_mount","_enums","_computeRealValue","_isStrictMode","_CustomTemplates","_registerAppI18n","_utils","_realTimeDataInspect","symbolForRootRuntimeContext","exports","Symbol","for","renderUseBrick","useBrick","data","_useBrick$symbolForRo","_scopedRuntimeContext","_scopedRuntimeContext2","_output$node","_output$node2","scopedRuntimeContext","tplStateStoreScope","formStateStoreScope","createScopedRuntimeContext","_internalApiGetRuntimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","rendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","createPortal","transform","strict","isStrictMode","warnAboutStrictMode","output","renderBrick","properties","scopedStores","postAsyncRender","node","PLACEHOLDER","Error","portal","child","tagName","type","mountUseBrick","element","portalRoot","document","querySelector","createElement","appendChild","mountTree","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","store","mountAsyncData","unmountUseBrick","mountResult","unmountTree","remove","dispatchOnUnmount","dispose","legacyDoTransform","to","options","computeRealValue","noInject","updateStoryboard","appId","storyboardPatch","storyboard","_internalApiGetStoryboardInBootstrapData","Object","assign","meta","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","registerAppI18n","updateStoryboardByRoute","newRoute","match","getKey","route","path","exact","replaceRoute","routes","key","map","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","customTemplates","define","bricks","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","pick","getSnippetPreviewPath","snippetId","updateStoryboardBySnippet","snippetData","_snippetData$bricks","length","context","updateSnippetPreviewSettings","previewRouteIndex","findIndex","newPreviewRoute","menu","splice","getContextValue","tplStateStoreId","runtimeContext","tplStateStore","getTplStateStore","getValue","ctxStore","getAllContextValues","getAllValues","getBrickPackagesById","id","getBrickPackages","find","pkg","filePath","startsWith","getRenderId","_internalApiGetRenderId","getAddedContracts","updateStoryboardType","collectUsedContracts","updatedStoryboard","_storyboard$routes","snippetPreviewPath","currentRoute","addedContracts","contractApis","forEach","api","_storyboard$meta","_","namespaceId","contracts","some","contract","push"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BrickConf,\n CustomTemplate,\n RouteConf,\n Storyboard,\n UseSingleBrickConf,\n RuntimeSnippet,\n ContextConf,\n} from \"@next-core/types\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRenderId,\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n getBrickPackages,\n} from \"./Runtime.js\";\nimport {\n createScopedRuntimeContext,\n postAsyncRender,\n renderBrick,\n} from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type {\n DataValueOption,\n PreviewOption,\n PreviewStoryboardPatch,\n RenderRoot,\n RuntimeContext,\n} 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 { getTplStateStore } from \"./CustomTemplates/utils.js\";\n\nexport type { DataValueOption, RuntimeContext };\n\nexport const symbolForRootRuntimeContext = Symbol.for(\"root.runtimeContext\");\n\nexport interface RuntimeUseBrickConfWithRootSymbols extends UseSingleBrickConf {\n [symbolForRootRuntimeContext]?: RuntimeContext;\n}\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n scopedStores: DataStore<\"STATE\" | \"FORM_STATE\">[];\n}\n\nexport async function renderUseBrick(\n useBrick: RuntimeUseBrickConfWithRootSymbols,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] =\n createScopedRuntimeContext({\n ...(useBrick[symbolForRootRuntimeContext] ??\n _internalApiGetRuntimeContext()!),\n data,\n pendingPermissionsPreCheck: [],\n });\n\n scopedRuntimeContext.tplStateStoreMap ??= new Map();\n scopedRuntimeContext.formStateStoreMap ??= 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 scopedRuntimeContext,\n rendererContext,\n []\n );\n\n const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];\n\n await postAsyncRender(output, scopedRuntimeContext, scopedStores);\n\n if (output.node?.tag === RenderTag.PLACEHOLDER) {\n throw new Error(\n \"The root brick of useBrick cannot be an ignored control node\"\n );\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, scopedStores };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext, scopedStores }: 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 rendererContext.initializeMessageDispatcher();\n\n for (const store of scopedStores) {\n store.mountAsyncData();\n }\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\n/** For v2 compatibility of `doTransform` from brick-kit. */\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 function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n meta: {\n // Keep runtime fields such as `injectMenus`\n ...storyboard.meta,\n ...storyboardPatch.meta,\n },\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(\n settings,\n \"properties\",\n \"events\",\n \"lifeCycle\",\n \"context\",\n \"slots\",\n \"children\"\n ),\n },\n ]\n );\n}\n\nfunction getSnippetPreviewPath(snippetId: string): string {\n return `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetId}`;\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n context?: ContextConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n getSnippetPreviewPath(snippetData.snippetId),\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }],\n snippetData.context\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[],\n context?: ContextConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n context,\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\nexport function getContextValue(\n name: string,\n { tplStateStoreId }: DataValueOption\n): unknown {\n const runtimeContext = _internalApiGetRuntimeContext()!;\n\n if (tplStateStoreId) {\n const tplStateStore = getTplStateStore(\n {\n ...runtimeContext,\n tplStateStoreId,\n },\n \"STATE\"\n );\n return tplStateStore.getValue(name);\n }\n\n return runtimeContext.ctxStore.getValue(name);\n}\n\nexport function getAllContextValues({\n tplStateStoreId,\n}: DataValueOption): Record<string, unknown> {\n const runtimeContext = _internalApiGetRuntimeContext()!;\n\n if (tplStateStoreId) {\n const tplStateStore = getTplStateStore(\n {\n ...runtimeContext,\n tplStateStoreId,\n },\n \"STATE\"\n );\n return tplStateStore.getAllValues();\n }\n\n return runtimeContext.ctxStore.getAllValues();\n}\n\nexport function getBrickPackagesById(id: string) {\n return getBrickPackages().find((pkg) =>\n pkg.id ? pkg.id === id : pkg.filePath.startsWith(id)\n );\n}\n\nexport function getRenderId() {\n return _internalApiGetRenderId();\n}\n\nexport async function getAddedContracts(\n storyboardPatch: PreviewStoryboardPatch,\n { appId, updateStoryboardType, collectUsedContracts }: PreviewOption\n): Promise<string[]> {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId);\n let updatedStoryboard;\n\n // 拿到更新部分的 storyboard 配置,然后扫描一遍,找到新增的 contracts\n if (updateStoryboardType === \"route\") {\n updatedStoryboard = {\n routes: [storyboardPatch as RouteConf],\n } as Storyboard;\n } else if (updateStoryboardType === \"template\") {\n updatedStoryboard = {\n meta: {\n customTemplates: [storyboardPatch as CustomTemplate],\n },\n } as Storyboard;\n } else if (updateStoryboardType === \"snippet\") {\n // snippet 是放在挂载 route 里预览,通过 previewPath 拿到当前修改 route\n const snippetPreviewPath = getSnippetPreviewPath(\n (storyboardPatch as RuntimeSnippet).snippetId\n );\n const currentRoute = storyboard?.routes?.find(\n (route) => route.path === snippetPreviewPath\n );\n\n updatedStoryboard = {\n routes: [currentRoute],\n } as Storyboard;\n }\n\n const addedContracts: string[] = [];\n\n if (updatedStoryboard && collectUsedContracts) {\n const contractApis = await collectUsedContracts(updatedStoryboard);\n\n contractApis.forEach((api: string) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [_, namespaceId, name] = api.match(\n /(.*)@(.*):\\d\\.\\d\\.\\d/\n ) as string[];\n\n if (\n !storyboard?.meta?.contracts?.some(\n (contract) =>\n contract.namespaceId === namespaceId && contract.name === name\n )\n ) {\n addedContracts.push(api);\n }\n });\n }\n\n return addedContracts;\n}\n\nexport {\n setRealTimeDataInspectRoot,\n addRealTimeDataInspectHook,\n} from \"./data/realTimeDataInspect.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAMA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,gBAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,gBAAA,GAAAR,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AACA,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