@next-core/runtime 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/cjs/CustomTemplates.js +7 -3
  2. package/dist/cjs/CustomTemplates.js.map +1 -1
  3. package/dist/cjs/StoryboardFunctionRegistry.js +14 -0
  4. package/dist/cjs/StoryboardFunctionRegistry.js.map +1 -1
  5. package/dist/cjs/index.js +2 -2
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/internal/Runtime.js +14 -10
  8. package/dist/cjs/internal/Runtime.js.map +1 -1
  9. package/dist/cjs/internal/compute/checkIf.js +4 -0
  10. package/dist/cjs/internal/compute/checkIf.js.map +1 -1
  11. package/dist/cjs/internal/compute/getNextStateOfUseBrick.js +4 -4
  12. package/dist/cjs/internal/compute/getNextStateOfUseBrick.js.map +1 -1
  13. package/dist/cjs/internal/enums.js +4 -4
  14. package/dist/cjs/internal/enums.js.map +1 -1
  15. package/dist/cjs/internal/historyExtended.js +21 -0
  16. package/dist/cjs/internal/historyExtended.js.map +1 -1
  17. package/dist/cjs/internal/mediaQuery.js +4 -4
  18. package/dist/cjs/internal/mediaQuery.js.map +1 -1
  19. package/dist/esm/CustomTemplates.js +7 -3
  20. package/dist/esm/CustomTemplates.js.map +1 -1
  21. package/dist/esm/StoryboardFunctionRegistry.js +12 -0
  22. package/dist/esm/StoryboardFunctionRegistry.js.map +1 -1
  23. package/dist/esm/index.js +2 -2
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js +2 -2
  26. package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
  27. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +2 -2
  28. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  29. package/dist/esm/internal/Runtime.js +14 -10
  30. package/dist/esm/internal/Runtime.js.map +1 -1
  31. package/dist/esm/internal/checkInstalledApps.js.map +1 -1
  32. package/dist/esm/internal/compute/checkIf.js +5 -0
  33. package/dist/esm/internal/compute/checkIf.js.map +1 -1
  34. package/dist/esm/internal/compute/getNextStateOfUseBrick.js +3 -3
  35. package/dist/esm/internal/compute/getNextStateOfUseBrick.js.map +1 -1
  36. package/dist/esm/internal/compute/listenOnTrackingContext.js.map +1 -1
  37. package/dist/esm/internal/data/DataStore.js.map +1 -1
  38. package/dist/esm/internal/data/FlowApiProvider.js +6 -6
  39. package/dist/esm/internal/data/FlowApiProvider.js.map +1 -1
  40. package/dist/esm/internal/enums.js +3 -3
  41. package/dist/esm/internal/enums.js.map +1 -1
  42. package/dist/esm/internal/historyExtended.js +21 -0
  43. package/dist/esm/internal/historyExtended.js.map +1 -1
  44. package/dist/esm/internal/loadBootstrapData.js +19 -18
  45. package/dist/esm/internal/loadBootstrapData.js.map +1 -1
  46. package/dist/esm/internal/mediaQuery.js +3 -3
  47. package/dist/esm/internal/mediaQuery.js.map +1 -1
  48. package/dist/esm/internal/menu/interfaces.js +4 -0
  49. package/dist/esm/internal/menu/interfaces.js.map +1 -1
  50. package/dist/esm/internal/menu/mergeMenu.js +11 -10
  51. package/dist/esm/internal/menu/mergeMenu.js.map +1 -1
  52. package/dist/types/index.d.ts +2 -1
  53. package/dist/types/internal/Runtime.d.ts +1 -4
  54. package/dist/types/tsdoc-metadata.json +11 -0
  55. package/package.json +16 -12
@@ -74,9 +74,13 @@ class CustomTemplateRegistry {
74
74
  var proxyMethods = Object.entries((_compatibleConstructo = (_compatibleConstructo2 = compatibleConstructor.proxy) === null || _compatibleConstructo2 === void 0 ? void 0 : _compatibleConstructo2.methods) !== null && _compatibleConstructo !== void 0 ? _compatibleConstructo : {});
75
75
  var props = exposedStates.concat(validProxyProps.map(entry => entry[0]));
76
76
  var methods = proxyMethods.map(entry => entry[0]);
77
- var nativeProp = props.concat(methods).find(prop => prop in HTMLElement.prototype && !allowedNativeProps.has(prop));
78
- if (nativeProp !== undefined) {
79
- throw new Error("In custom template \"".concat(tagName, "\", \"").concat(nativeProp, "\" is a native HTMLElement property, and should be avoid to be used as a brick property or method."));
77
+ var nativeProps = props.concat(methods).filter(prop => prop in HTMLElement.prototype && !allowedNativeProps.has(prop));
78
+ if (nativeProps.length > 0) {
79
+ warnAboutStrictMode(strict, "Using native HTMLElement properties as template properties or methods", tagName, ...nativeProps);
80
+ // istanbul ignore next
81
+ if (strict) {
82
+ throw new Error("In custom template \"".concat(tagName, "\", ").concat(nativeProps.map(p => "\"".concat(p, "\"")).join(", "), " are native HTMLElement properties, and should be avoid to be used as brick properties or methods."));
83
+ }
80
84
  }
81
85
  if (registered) {
82
86
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"CustomTemplates.js","names":["uniq","isStrictMode","warnAboutStrictMode","allowedNativeProps","Set","_registry","WeakMap","CustomTemplateRegistry","constructor","_classPrivateFieldInitSpec","writable","value","Map","define","tagName","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","_classPrivateFieldGet","has","console","warn","concat","customElements","get","strict","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","Object","entries","asVariable","push","mergeProperty","refTransform","error","ref","compatibleConstructor","_objectSpread","fromEntries","state","map","item","expose","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProp","find","prop","HTMLElement","prototype","undefined","Error","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","_this$$$tplStateStore2","_this$$$tplStateStore3","_this$$$tplStateStore4","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","_loop","propName","some","defineProperty","getValue","_this$$$tplStateStore5","updateValue","enumerable","_ret","_loop2","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","_loop3","_to$refMethod","refMethod","arguments","customTemplates","_state$filter$map","filter"],"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\";\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 nativeProp = props\n .concat(methods)\n .find(\n (prop) => prop in HTMLElement.prototype && !allowedNativeProps.has(prop)\n );\n if (nativeProp !== undefined) {\n throw new Error(\n `In custom template \"${tagName}\", \"${nativeProp}\" is a native HTMLElement property, and should be avoid to be used as a brick property or method.`\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\nexport const customTemplates = new CustomTemplateRegistry();\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"],"mappings":";;;AAMA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,SAAS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cAAAA,iBAAA,GAAI,EAAE,CACpE;AACH"}
1
+ {"version":3,"file":"CustomTemplates.js","names":["uniq","isStrictMode","warnAboutStrictMode","allowedNativeProps","Set","_registry","WeakMap","CustomTemplateRegistry","constructor","_classPrivateFieldInitSpec","writable","value","Map","define","tagName","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","_classPrivateFieldGet","has","console","warn","concat","customElements","get","strict","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","Object","entries","asVariable","push","mergeProperty","refTransform","error","ref","compatibleConstructor","_objectSpread","fromEntries","state","map","item","expose","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","_this$$$tplStateStore2","_this$$$tplStateStore3","_this$$$tplStateStore4","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","_loop","propName","some","defineProperty","getValue","_this$$$tplStateStore5","updateValue","enumerable","_ret","_loop2","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","_loop3","_from","_to","_to$refMethod","refMethod","arguments","customTemplates","_state$filter$map"],"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\";\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\nexport const customTemplates = new CustomTemplateRegistry();\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"],"mappings":";;;AAMA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,mBAAmB;;AAErE;AACA,IAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAAC,IAAAC,SAAA,oBAAAC,OAAA;AAQ/C,MAAMC,sBAAsB,CAAC;EAAAC,YAAA;IAAAC,0BAAA,OAAAJ,SAAA;MAAAK,QAAA;MAAAC,KAAA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BAAA,GAAI,EAAE,CACpE;AACH"}
@@ -6,6 +6,18 @@ import { getGeneralGlobals } from "./internal/compute/getGeneralGlobals.js";
6
6
 
7
7
  /** @internal */
8
8
 
9
+ /** @internal */
10
+
11
+ /** @internal */
12
+
13
+ /** @internal */
14
+
15
+ /** @internal */
16
+
17
+ /** @internal */
18
+
19
+ /** @internal */
20
+
9
21
  /** @internal */
10
22
  export function StoryboardFunctionRegistryFactory() {
11
23
  var {
@@ -1 +1 @@
1
- {"version":3,"file":"StoryboardFunctionRegistry.js","names":["cook","precookFunction","supply","strictCollectMemberUsageInFunction","getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","arguments","length","undefined","registeredFunctions","Map","storyboardFunctions","Proxy","Object","freeze","get","target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","hasPermissionsCheck","has","set","name","source","typescript","processed","cooked","collector","createCollector","precooked","hooks","beforeVisit","function","rules","noVar","globalVariables","attemptToVisitGlobals","isStoryboardFunction","beforeEvaluate","beforeCall","beforeBranch","updateStoryboardFunction","data","newFn","_objectSpread","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type { MicroApp, StoryboardFunction } from \"@next-core/types\";\nimport { cook, precookFunction, EstreeNode } from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { strictCollectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { getGeneralGlobals } from \"./internal/compute/getGeneralGlobals.js\";\n\n/** @internal */\nexport type ReadonlyStoryboardFunctions = Readonly<Record<string, Function>>;\n\n/** @internal */\nexport type StoryboardFunctionPatch = Pick<\n StoryboardFunction,\n \"source\" | \"typescript\"\n>;\n\n/** @internal */\nexport interface StoryboardFunctionRegistry {\n /** A readonly proxy for accessing cooked storyboard functions. */\n storyboardFunctions: ReadonlyStoryboardFunctions;\n\n /** Register storyboard functions. */\n registerStoryboardFunctions(\n functions: StoryboardFunction[] | undefined,\n app?: PartialMicroApp\n ): void;\n\n /** Update a storyboard function during debugging. */\n updateStoryboardFunction(name: string, data: StoryboardFunctionPatch): void;\n\n checkPermissionsUsage(functionNames: string[]): boolean;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string>;\n hasPermissionsCheck: boolean;\n}\n\n/** @internal */\nexport interface FunctionCoverageCollector {\n beforeVisit(node: EstreeNode): void;\n beforeEvaluate(node: EstreeNode): void;\n beforeCall(node: EstreeNode): void;\n beforeBranch(node: EstreeNode, branch: string): void;\n}\n\n/** @internal */\nexport interface FunctionCoverageSettings {\n createCollector(name: string): FunctionCoverageCollector;\n}\n\n/** @internal */\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n collectCoverage,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n collectCoverage?: FunctionCoverageSettings;\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n // Use `Proxy` with a frozen target, to make a readonly function registry.\n const storyboardFunctions = new Proxy(Object.freeze({}), {\n get(target, key) {\n return getStoryboardFunction(key as string);\n },\n }) as ReadonlyStoryboardFunctions;\n\n let currentApp: PartialMicroApp | undefined;\n\n function registerStoryboardFunctions(\n functions: StoryboardFunction[],\n app?: PartialMicroApp\n ): void {\n if (app) {\n currentApp = app;\n }\n registeredFunctions.clear();\n if (Array.isArray(functions)) {\n for (const fn of functions) {\n const deps = strictCollectMemberUsageInFunction(fn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getStoryboardFunction(name: string): Function | undefined {\n const fn = registeredFunctions.get(name);\n if (!fn) {\n return undefined;\n }\n if (fn.processed) {\n return fn.cooked;\n }\n let collector: FunctionCoverageCollector | undefined;\n if (collectCoverage) {\n collector = collectCoverage.createCollector(name);\n }\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n });\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: supply(\n precooked.attemptToVisitGlobals,\n getGeneralGlobals(precooked.attemptToVisitGlobals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\n ),\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n }) as Function;\n fn.processed = true;\n return fn.cooked;\n }\n\n return {\n storyboardFunctions,\n registerStoryboardFunctions,\n updateStoryboardFunction(\n name: string,\n data: StoryboardFunctionPatch\n ): void {\n const newFn = {\n ...data,\n name,\n };\n const deps = strictCollectMemberUsageInFunction(newFn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n deps,\n hasPermissionsCheck,\n });\n },\n /**\n * Check whether listed functions attempt to call `PERMISSIONS.check()`,\n * includes in nested `FN.*()` calls.\n */\n checkPermissionsUsage(functionNames) {\n const checkedFunctions = new Set<string>();\n const hasPermissionsCheck = (name: string): boolean => {\n if (!checkedFunctions.has(name)) {\n checkedFunctions.add(name);\n const fn = registeredFunctions.get(name);\n return (\n !!fn &&\n (fn.hasPermissionsCheck || [...fn.deps].some(hasPermissionsCheck))\n );\n }\n return false;\n };\n return functionNames.some(hasPermissionsCheck);\n },\n };\n}\n"],"mappings":";AACA,SAASA,IAAI,EAAEC,eAAe,QAA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IAAY,EACZoB,IAA6B,EACvB;MACN,IAAMC,KAAK,GAAAC,aAAA,CAAAA,aAAA,KACNF,IAAI;QACPpB;MAAI,EACL;MACD,IAAMJ,IAAI,GAAG3B,kCAAkC,CAACoD,KAAK,EAAE,IAAI,CAAC;MAC5D,IAAMxB,mBAAmB,GAAG5B,kCAAkC,CAC5DoD,KAAK,EACL,aAAa,CACd,CAACvB,GAAG,CAAC,OAAO,CAAC;MACdpB,mBAAmB,CAACqB,GAAG,CAACC,IAAI,EAAE;QAC5BC,MAAM,EAAEmB,IAAI,CAACnB,MAAM;QACnBC,UAAU,EAAEkB,IAAI,CAAClB,UAAU;QAC3BN,IAAI;QACJC;MACF,CAAC,CAAC;IACJ,CAAC;IACD;AACJ;AACA;AACA;IACI0B,qBAAqBA,CAACC,aAAa,EAAE;MACnC,IAAMC,gBAAgB,GAAG,IAAIC,GAAG,EAAU;MAC1C,IAAM7B,mBAAmB,GAAIG,IAAY,IAAc;QACrD,IAAI,CAACyB,gBAAgB,CAAC3B,GAAG,CAACE,IAAI,CAAC,EAAE;UAC/ByB,gBAAgB,CAACE,GAAG,CAAC3B,IAAI,CAAC;UAC1B,IAAML,EAAE,GAAGjB,mBAAmB,CAACM,GAAG,CAACgB,IAAI,CAAC;UACxC,OACE,CAAC,CAACL,EAAE,KACHA,EAAE,CAACE,mBAAmB,IAAI,CAAC,GAAGF,EAAE,CAACC,IAAI,CAAC,CAACgC,IAAI,CAAC/B,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAO2B,aAAa,CAACI,IAAI,CAAC/B,mBAAmB,CAAC;IAChD;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"StoryboardFunctionRegistry.js","names":["cook","precookFunction","supply","strictCollectMemberUsageInFunction","getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","arguments","length","undefined","registeredFunctions","Map","storyboardFunctions","Proxy","Object","freeze","get","target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","hasPermissionsCheck","has","set","name","source","typescript","processed","cooked","collector","createCollector","precooked","hooks","beforeVisit","function","rules","noVar","globalVariables","attemptToVisitGlobals","isStoryboardFunction","beforeEvaluate","beforeCall","beforeBranch","updateStoryboardFunction","data","newFn","_objectSpread","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type { MicroApp, StoryboardFunction } from \"@next-core/types\";\nimport { cook, precookFunction, EstreeNode } from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { strictCollectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { getGeneralGlobals } from \"./internal/compute/getGeneralGlobals.js\";\n\n/** @internal */\nexport type ReadonlyStoryboardFunctions = Readonly<Record<string, Function>>;\n\n/** @internal */\nexport type StoryboardFunctionPatch = Pick<\n StoryboardFunction,\n \"source\" | \"typescript\"\n>;\n\n/** @internal */\nexport interface StoryboardFunctionRegistry {\n /** A readonly proxy for accessing cooked storyboard functions. */\n storyboardFunctions: ReadonlyStoryboardFunctions;\n\n /** Register storyboard functions. */\n registerStoryboardFunctions(\n functions: StoryboardFunction[] | undefined,\n app?: PartialMicroApp\n ): void;\n\n /** Update a storyboard function during debugging. */\n updateStoryboardFunction(name: string, data: StoryboardFunctionPatch): void;\n\n checkPermissionsUsage(functionNames: string[]): boolean;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string>;\n hasPermissionsCheck: boolean;\n}\n\n/** @internal */\nexport interface FunctionCoverageCollector {\n beforeVisit(node: EstreeNode): void;\n beforeEvaluate(node: EstreeNode): void;\n beforeCall(node: EstreeNode): void;\n beforeBranch(node: EstreeNode, branch: string): void;\n}\n\n/** @internal */\nexport interface FunctionCoverageSettings {\n createCollector(name: string): FunctionCoverageCollector;\n}\n\n/** @internal */\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n collectCoverage,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n collectCoverage?: FunctionCoverageSettings;\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n // Use `Proxy` with a frozen target, to make a readonly function registry.\n const storyboardFunctions = new Proxy(Object.freeze({}), {\n get(target, key) {\n return getStoryboardFunction(key as string);\n },\n }) as ReadonlyStoryboardFunctions;\n\n let currentApp: PartialMicroApp | undefined;\n\n function registerStoryboardFunctions(\n functions: StoryboardFunction[],\n app?: PartialMicroApp\n ): void {\n if (app) {\n currentApp = app;\n }\n registeredFunctions.clear();\n if (Array.isArray(functions)) {\n for (const fn of functions) {\n const deps = strictCollectMemberUsageInFunction(fn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getStoryboardFunction(name: string): Function | undefined {\n const fn = registeredFunctions.get(name);\n if (!fn) {\n return undefined;\n }\n if (fn.processed) {\n return fn.cooked;\n }\n let collector: FunctionCoverageCollector | undefined;\n if (collectCoverage) {\n collector = collectCoverage.createCollector(name);\n }\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n });\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: supply(\n precooked.attemptToVisitGlobals,\n getGeneralGlobals(precooked.attemptToVisitGlobals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\n ),\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n }) as Function;\n fn.processed = true;\n return fn.cooked;\n }\n\n return {\n storyboardFunctions,\n registerStoryboardFunctions,\n updateStoryboardFunction(\n name: string,\n data: StoryboardFunctionPatch\n ): void {\n const newFn = {\n ...data,\n name,\n };\n const deps = strictCollectMemberUsageInFunction(newFn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n deps,\n hasPermissionsCheck,\n });\n },\n /**\n * Check whether listed functions attempt to call `PERMISSIONS.check()`,\n * includes in nested `FN.*()` calls.\n */\n checkPermissionsUsage(functionNames) {\n const checkedFunctions = new Set<string>();\n const hasPermissionsCheck = (name: string): boolean => {\n if (!checkedFunctions.has(name)) {\n checkedFunctions.add(name);\n const fn = registeredFunctions.get(name);\n return (\n !!fn &&\n (fn.hasPermissionsCheck || [...fn.deps].some(hasPermissionsCheck))\n );\n }\n return false;\n };\n return functionNames.some(hasPermissionsCheck);\n },\n };\n}\n"],"mappings":";AACA,SAASA,IAAI,EAAEC,eAAe,QAAoB,iBAAiB;AACnE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,kCAAkC,QAAQ,6BAA6B;AAChF,SAASC,iBAAiB,QAAQ,yCAAyC;;AAE3E;;AAGA;;AAMA;;AAiBA;;AAUA;;AAQA;;AAKA;;AAGA;AACA,OAAO,SAASC,iCAAiCA,CAAA,EAQb;EAAA,IARc;IAChDC,QAAQ;IACRC,aAAa;IACbC;EAKF,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACJ,IAAMG,mBAAmB,GAAG,IAAIC,GAAG,EAAqC;;EAExE;EACA,IAAMC,mBAAmB,GAAG,IAAIC,KAAK,CAACC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,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IACD;AACJ;AACA;AACA;IACI0B,qBAAqBA,CAACC,aAAa,EAAE;MACnC,IAAMC,gBAAgB,GAAG,IAAIC,GAAG,EAAU;MAC1C,IAAM7B,mBAAmB,GAAIG,IAAY,IAAc;QACrD,IAAI,CAACyB,gBAAgB,CAAC3B,GAAG,CAACE,IAAI,CAAC,EAAE;UAC/ByB,gBAAgB,CAACE,GAAG,CAAC3B,IAAI,CAAC;UAC1B,IAAML,EAAE,GAAGjB,mBAAmB,CAACM,GAAG,CAACgB,IAAI,CAAC;UACxC,OACE,CAAC,CAACL,EAAE,KACHA,EAAE,CAACE,mBAAmB,IAAI,CAAC,GAAGF,EAAE,CAACC,IAAI,CAAC,CAACgC,IAAI,CAAC/B,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAO2B,aAAa,CAACI,IAAI,CAAC/B,mBAAmB,CAAC;IAChD;EACF,CAAC;AACH"}
package/dist/esm/index.js CHANGED
@@ -7,8 +7,8 @@ export * from "./getPageInfo.js";
7
7
  export * from "./handleHttpError.js";
8
8
  export * from "./history.js";
9
9
  export { createRuntime, getRuntime } from "./internal/Runtime.js";
10
- import * as _secret_internals from "./internal/secret_internals.js";
11
- export { _secret_internals as __secret_internals };
10
+ import * as __secret_internals from "./internal/secret_internals.js";
11
+ export { __secret_internals };
12
12
  export { getCssPropertyValue, getCurrentTheme, getCurrentMode, batchSetAppsLocalTheme, applyTheme } from "./themeAndMode.js";
13
13
  export { checkIfOfComputed, checkIfByTransform } from "./internal/compute/checkIf.js";
14
14
  export { registerWidgetFunctions } from "./internal/compute/WidgetFunctions.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["createRuntime","getRuntime","_secret_internals","__secret_internals","getCssPropertyValue","getCurrentTheme","getCurrentMode","batchSetAppsLocalTheme","applyTheme","checkIfOfComputed","checkIfByTransform","registerWidgetFunctions","registerWidgetI18n","StoryboardFunctionRegistryFactory","matchPath"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./auth.js\";\nexport * from \"./CustomProcessors.js\";\nexport * from \"./CustomTemplates.js\";\nexport * from \"./fetchByProvider.js\";\nexport * from \"./getBasePath.js\";\nexport * from \"./getPageInfo.js\";\nexport * from \"./handleHttpError.js\";\nexport * from \"./history.js\";\nexport { createRuntime, getRuntime } from \"./internal/Runtime.js\";\nexport * as __secret_internals from \"./internal/secret_internals.js\";\nexport {\n getCssPropertyValue,\n getCurrentTheme,\n getCurrentMode,\n batchSetAppsLocalTheme,\n applyTheme,\n} from \"./themeAndMode.js\";\nexport {\n checkIfOfComputed,\n checkIfByTransform,\n} from \"./internal/compute/checkIf.js\";\nexport { registerWidgetFunctions } from \"./internal/compute/WidgetFunctions.js\";\nexport { registerWidgetI18n } from \"./internal/compute/WidgetI18n.js\";\nexport { StoryboardFunctionRegistryFactory } from \"./StoryboardFunctionRegistry.js\";\nexport { matchPath } from \"./internal/matchPath.js\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,kBAAkB;AAChC,cAAc,sBAAsB;AACpC,cAAc,cAAc;AAC5B,SAASA,aAAa,EAAEC,UAAU,QAAQ,uBAAuB;AAAC,YAAAC,iBAAA,MAC9B,gCAAgC;AAAA,SAAAA,iBAAA,IAAxDC,kBAAkB;AAC9B,SACEC,mBAAmB,EACnBC,eAAe,EACfC,cAAc,EACdC,sBAAsB,EACtBC,UAAU,QACL,mBAAmB;AAC1B,SACEC,iBAAiB,EACjBC,kBAAkB,QACb,+BAA+B;AACtC,SAASC,uBAAuB,QAAQ,uCAAuC;AAC/E,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,iCAAiC,QAAQ,iCAAiC;AACnF,SAASC,SAAS,QAAQ,yBAAyB"}
1
+ {"version":3,"file":"index.js","names":["createRuntime","getRuntime","__secret_internals","getCssPropertyValue","getCurrentTheme","getCurrentMode","batchSetAppsLocalTheme","applyTheme","checkIfOfComputed","checkIfByTransform","registerWidgetFunctions","registerWidgetI18n","StoryboardFunctionRegistryFactory","matchPath"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./auth.js\";\nexport * from \"./CustomProcessors.js\";\nexport * from \"./CustomTemplates.js\";\nexport * from \"./fetchByProvider.js\";\nexport * from \"./getBasePath.js\";\nexport * from \"./getPageInfo.js\";\nexport * from \"./handleHttpError.js\";\nexport * from \"./history.js\";\nexport { createRuntime, getRuntime } from \"./internal/Runtime.js\";\nimport * as __secret_internals from \"./internal/secret_internals.js\";\nexport { __secret_internals };\nexport {\n getCssPropertyValue,\n getCurrentTheme,\n getCurrentMode,\n batchSetAppsLocalTheme,\n applyTheme,\n} from \"./themeAndMode.js\";\nexport {\n checkIfOfComputed,\n checkIfByTransform,\n} from \"./internal/compute/checkIf.js\";\nexport { registerWidgetFunctions } from \"./internal/compute/WidgetFunctions.js\";\nexport { registerWidgetI18n } from \"./internal/compute/WidgetI18n.js\";\nexport { StoryboardFunctionRegistryFactory } from \"./StoryboardFunctionRegistry.js\";\nexport { matchPath } from \"./internal/matchPath.js\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,kBAAkB;AAChC,cAAc,sBAAsB;AACpC,cAAc,cAAc;AAC5B,SAASA,aAAa,EAAEC,UAAU,QAAQ,uBAAuB;AACjE,OAAO,KAAKC,kBAAkB,MAAM,gCAAgC;AACpE,SAASA,kBAAkB;AAC3B,SACEC,mBAAmB,EACnBC,eAAe,EACfC,cAAc,EACdC,sBAAsB,EACtBC,UAAU,QACL,mBAAmB;AAC1B,SACEC,iBAAiB,EACjBC,kBAAkB,QACb,+BAA+B;AACtC,SAASC,uBAAuB,QAAQ,uCAAuC;AAC/E,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,iCAAiC,QAAQ,iCAAiC;AACnF,SAASC,SAAS,QAAQ,yBAAyB"}
@@ -19,7 +19,7 @@ export function bindTemplateProxy(brick) {
19
19
  tplHostMetadata.internalBricksByRef.set(ref, brick);
20
20
  var events = (_tplHostMetadata$prox = tplHostMetadata.proxy) === null || _tplHostMetadata$prox === void 0 ? void 0 : _tplHostMetadata$prox.events;
21
21
  if (events) {
22
- var _loop = function (from, to) {
22
+ var _loop = function (from) {
23
23
  if (to.ref === ref) {
24
24
  var _to$refEvent, _ref, _ref$$$proxyListeners;
25
25
  var listener = e => {
@@ -40,7 +40,7 @@ export function bindTemplateProxy(brick) {
40
40
  }
41
41
  };
42
42
  for (var [from, to] of Object.entries(events)) {
43
- _loop(from, to);
43
+ _loop(from);
44
44
  }
45
45
  }
46
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bindTemplateProxy.js","names":["getTplStateStore","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","tplHostMetadata","internalBricksByRef","set","events","proxy","_loop","from","to","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","Object","entries","unbindTemplateProxy","delete","type","fn","_$$proxyListeners","removeEventListener"],"sources":["../../../../src/internal/CustomTemplates/bindTemplateProxy.ts"],"sourcesContent":["import type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"./utils.js\";\n\nexport function bindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n // Error recovering brick may have no runtimeContext.\n if (!ref || !runtimeContext.tplStateStoreId) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"bindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.set(ref, brick);\n\n const events = tplHostMetadata.proxy?.events;\n if (events) {\n for (const [from, to] of Object.entries(events)) {\n if (to.ref === ref) {\n const listener = (e: Event) => {\n if (e.bubbles) {\n e.stopPropagation();\n }\n hostBrick!.element!.dispatchEvent(\n new CustomEvent(from, {\n detail: (e as CustomEvent).detail,\n bubbles: e.bubbles,\n cancelable: e.cancelable,\n composed: e.composed,\n })\n );\n };\n const eventType = to.refEvent ?? from;\n element!.addEventListener(eventType, listener);\n element!.$$proxyListeners ??= [];\n element!.$$proxyListeners.push([eventType, listener]);\n }\n }\n }\n}\n\nexport function unbindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n if (!runtimeContext.tplStateStoreId || !ref) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"unbindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.delete(ref);\n\n for (const [type, fn] of element!.$$proxyListeners ?? []) {\n element!.removeEventListener(type, fn);\n }\n delete element!.$$proxyListeners;\n}\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,IAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEC;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAACC,GAAG,CAACP,GAAG,EAAEF,KAAK,CAAC;EAEnD,IAAMU,MAAM,IAAAT,qBAAA,GAAGM,eAAe,CAACI,KAAK,cAAAV,qBAAA,uBAArBA,qBAAA,CAA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AGJ,KAAK;EAE9C,IAAI,CAACG,cAAc,CAACE,eAAe,IAAI,CAACH,GAAG,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEI;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,qBAAqB,CAAC;EAC7E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAAC2B,MAAM,CAACjC,GAAG,CAAC;EAE/C,KAAK,IAAM,CAACkC,IAAI,EAAEC,EAAE,CAAC,KAAAC,iBAAA,GAAIlC,OAAO,CAAE0B,gBAAgB,cAAAQ,iBAAA,cAAAA,iBAAA,GAAI,EAAE,EAAE;IAAA,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE0B,gBAAgB;AAClC"}
1
+ {"version":3,"file":"bindTemplateProxy.js","names":["getTplStateStore","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","tplHostMetadata","internalBricksByRef","set","events","proxy","_loop","from","to","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","Object","entries","unbindTemplateProxy","delete","type","fn","_$$proxyListeners","removeEventListener"],"sources":["../../../../src/internal/CustomTemplates/bindTemplateProxy.ts"],"sourcesContent":["import type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"./utils.js\";\n\nexport function bindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n // Error recovering brick may have no runtimeContext.\n if (!ref || !runtimeContext.tplStateStoreId) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"bindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.set(ref, brick);\n\n const events = tplHostMetadata.proxy?.events;\n if (events) {\n for (const [from, to] of Object.entries(events)) {\n if (to.ref === ref) {\n const listener = (e: Event) => {\n if (e.bubbles) {\n e.stopPropagation();\n }\n hostBrick!.element!.dispatchEvent(\n new CustomEvent(from, {\n detail: (e as CustomEvent).detail,\n bubbles: e.bubbles,\n cancelable: e.cancelable,\n composed: e.composed,\n })\n );\n };\n const eventType = to.refEvent ?? from;\n element!.addEventListener(eventType, listener);\n element!.$$proxyListeners ??= [];\n element!.$$proxyListeners.push([eventType, listener]);\n }\n }\n }\n}\n\nexport function unbindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n if (!runtimeContext.tplStateStoreId || !ref) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"unbindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.delete(ref);\n\n for (const [type, fn] of element!.$$proxyListeners ?? []) {\n element!.removeEventListener(type, fn);\n }\n delete element!.$$proxyListeners;\n}\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,IAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEC;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAACC,GAAG,CAACP,GAAG,EAAEF,KAAK,CAAC;EAEnD,IAAMU,MAAM,IAAAT,qB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E,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;EAE9C,IAAI,CAACG,cAAc,CAACE,eAAe,IAAI,CAACH,GAAG,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEI;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,qBAAqB,CAAC;EAC7E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAAC2B,MAAM,CAACjC,GAAG,CAAC;EAE/C,KAAK,IAAM,CAACkC,IAAI,EAAEC,EAAE,CAAC,KAAAC,iBAAA,GAAIlC,OAAO,CAAE0B,gBAAgB,cAAAQ,iBAAA,cAAAA,iBAAA,GAAI,EAAE,EAAE;IAAA,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE0B,gBAAgB;AAClC"}
@@ -58,7 +58,7 @@ export function setupTemplateProxy(hostContext, ref, slots) {
58
58
  var refPosition = (_to$refPosition = to.refPosition) !== null && _to$refPosition !== void 0 ? _to$refPosition : -1;
59
59
  expandableSlot[clamp(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...(hasOwnProperty(hostBrick.runtimeContext, "forEachItem") ? setupTemplateExternalBricks(insertBricks, hostBrick.runtimeContext.forEachItem) : insertBricks));
60
60
  }
61
- var _loop = function (slotName, quasis) {
61
+ var _loop = function () {
62
62
  if (!hasOwnProperty(slots, slotName)) {
63
63
  slots[slotName] = {
64
64
  type: "bricks",
@@ -72,7 +72,7 @@ export function setupTemplateProxy(hostContext, ref, slots) {
72
72
  }
73
73
  };
74
74
  for (var [slotName, quasis] of quasisMap.entries()) {
75
- _loop(slotName, quasis);
75
+ _loop();
76
76
  }
77
77
  }
78
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachItem","symbolForTplStateStoreId","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostProperties","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","hostProps","props","from","to","propValue","undefined","refProperty","then","slotProxies","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","length","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","runtimeContext","setupTemplateExternalBricks","forEachItem","_loop","slotName","quasis","type","slotConf","flatMap","index","concat","entries","map","brick","_brick$slots","_objectSpread","Object","fromEntries","_ref","_slotConf$bricks","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachItem,\n symbolForTplStateStoreId,\n} from \"./constants.js\";\nimport type { AsyncProperties, TemplateHostContext } from \"../interfaces.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostProperties,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncProperties | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (hostProps: Record<string, unknown>) => {\n const props: Record<string, unknown> = {};\n for (const { from, to } of propertyProxies) {\n const propValue = hostProps[from];\n if (propValue !== undefined && to.refProperty) {\n props[to.refProperty] = propValue;\n }\n }\n return props;\n };\n\n asyncComputedProps = (asyncHostProperties as AsyncProperties).then(\n getComputedProps\n );\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(hasOwnProperty(hostBrick.runtimeContext, \"forEachItem\")\n ? setupTemplateExternalBricks(\n insertBricks,\n hostBrick.runtimeContext.forEachItem\n )\n : insertBricks)\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n forEachItem: unknown\n): BrickConf[] {\n return bricks.map((brick) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n slots: Object.fromEntries(\n Object.entries(brick.slots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks ?? [],\n forEachItem\n ),\n },\n ])\n ),\n }));\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n forEachItem: unknown\n): RouteConf[] {\n return routes.map((route) =>\n route.type && route.type !== \"bricks\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(route.bricks, forEachItem),\n }\n );\n}\n"],"mappings":";AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,+BAA+B,EAC/BC,wBAAwB,QACnB,gBAAgB;AAGvB,OAAO,SAASC,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,IAAM;IACJC,eAAe;IACfC,mBAAmB;IACnBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAA+C;EAEnD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,IAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,IAAMG,gBAAgB,GAAIC,SAAkC,IAAK;QAC/D,IAAMC,KAA8B,GAAG,CAAC,CAAC;QACzC,KAAK,IAAM;UAAEC,IAAI;UAAEC;QAAG,CAAC,IAAIP,eAAe,EAAE;UAC1C,IAAMQ,SAAS,GAAGJ,SAAS,CAACE,IAAI,CAAC;UACjC,IAAIE,SAAS,KAAKC,SAAS,IAAIF,EAAE,CAACG,WAAW,EAAE;YAC7CL,KAAK,CAACE,EAAE,CAACG,WAAW,CAAC,GAAGF,SAAS;UACnC;QACF;QACA,OAAOH,KAAK;MACd,CAAC;MAEDN,kBAAkB,GAA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xy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachItem","symbolForTplStateStoreId","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostProperties","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","hostProps","props","from","to","propValue","undefined","refProperty","then","slotProxies","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","length","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","runtimeContext","setupTemplateExternalBricks","forEachItem","_loop","slotName","type","slotConf","quasis","flatMap","index","concat","entries","map","brick","_brick$slots","_objectSpread","Object","fromEntries","_ref","_slotConf$bricks","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachItem,\n symbolForTplStateStoreId,\n} from \"./constants.js\";\nimport type { AsyncProperties, TemplateHostContext } from \"../interfaces.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostProperties,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncProperties | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (hostProps: Record<string, unknown>) => {\n const props: Record<string, unknown> = {};\n for (const { from, to } of propertyProxies) {\n const propValue = hostProps[from];\n if (propValue !== undefined && to.refProperty) {\n props[to.refProperty] = propValue;\n }\n }\n return props;\n };\n\n asyncComputedProps = (asyncHostProperties as AsyncProperties).then(\n getComputedProps\n );\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(hasOwnProperty(hostBrick.runtimeContext, \"forEachItem\")\n ? setupTemplateExternalBricks(\n insertBricks,\n hostBrick.runtimeContext.forEachItem\n )\n : insertBricks)\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n forEachItem: unknown\n): BrickConf[] {\n return bricks.map((brick) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n slots: Object.fromEntries(\n Object.entries(brick.slots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks ?? [],\n forEachItem\n ),\n },\n ])\n ),\n }));\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n forEachItem: unknown\n): RouteConf[] {\n return routes.map((route) =>\n route.type && route.type !== \"bricks\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(route.bricks, forEachItem),\n }\n );\n}\n"],"mappings":";AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,+BAA+B,EAC/BC,wBAAwB,QACnB,gBAAgB;AAGvB,OAAO,SAASC,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,IAAM;IACJC,eAAe;IACfC,mBAAmB;IACnBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAA+C;EAEnD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,IAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,IAAMG,gBAAgB,GAAIC,SAAkC,IAAK;QAC/D,IAAMC,KAA8B,GAAG,CAAC,CAAC;QACzC,KAAK,IAAM;UAAEC,IAAI;UAAEC;QAAG,CAAC,IAAIP,eAAe,EAAE;UAC1C,IAAMQ,SAAS,GAAGJ,SAAS,CAACE,IAAI,CAAC;UACjC,IAAIE,SAAS,KAAKC,SAAS,IAAIF,EAAE,CAACG,WAAW,EAAE;YAC7CL,KAAK,CAACE,EAAE,CAACG,WAAW,CAAC,GAAGF,SAAS;UACnC;QACF;QACA,OAAOH,KAAK;MAC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
  }
39
39
  getRecentApps() {
40
- return router.getRecentApps();
40
+ var _router$getRecentApps, _router;
41
+ return (_router$getRecentApps = (_router = router) === null || _router === void 0 ? void 0 : _router.getRecentApps()) !== null && _router$getRecentApps !== void 0 ? _router$getRecentApps : {};
41
42
  }
42
43
  getCurrentApp() {
43
- return router.getRecentApps().currentApp;
44
+ var _router2;
45
+ return (_router2 = router) === null || _router2 === void 0 ? void 0 : _router2.getRecentApps().currentApp;
44
46
  }
45
47
  getFeatureFlags() {
46
- var _bootstrapData2, _bootstrapData2$setti, _router$getRecentApps, _router$getRecentApps2, _router$getRecentApps3;
47
- return _objectSpread(_objectSpread(_objectSpread({}, (_bootstrapData2 = bootstrapData) === null || _bootstrapData2 === void 0 ? void 0 : (_bootstrapData2$setti = _bootstrapData2.settings) === null || _bootstrapData2$setti === void 0 ? void 0 : _bootstrapData2$setti.featureFlags), (_router$getRecentApps = router.getRecentApps().currentApp) === null || _router$getRecentApps === void 0 ? void 0 : (_router$getRecentApps2 = _router$getRecentApps.config) === null || _router$getRecentApps2 === void 0 ? void 0 : (_router$getRecentApps3 = _router$getRecentApps2.settings) === null || _router$getRecentApps3 === void 0 ? void 0 : _router$getRecentApps3.featureFlags), {}, {
48
+ var _bootstrapData2, _bootstrapData2$setti, _router3, _router3$getRecentApp, _router3$getRecentApp2, _router3$getRecentApp3;
49
+ return _objectSpread(_objectSpread(_objectSpread({}, (_bootstrapData2 = bootstrapData) === null || _bootstrapData2 === void 0 ? void 0 : (_bootstrapData2$setti = _bootstrapData2.settings) === null || _bootstrapData2$setti === void 0 ? void 0 : _bootstrapData2$setti.featureFlags), (_router3 = router) === null || _router3 === void 0 ? void 0 : (_router3$getRecentApp = _router3.getRecentApps().currentApp) === null || _router3$getRecentApp === void 0 ? void 0 : (_router3$getRecentApp2 = _router3$getRecentApp.config) === null || _router3$getRecentApp2 === void 0 ? void 0 : (_router3$getRecentApp3 = _router3$getRecentApp2.settings) === null || _router3$getRecentApp3 === void 0 ? void 0 : _router3$getRecentApp3.featureFlags), {}, {
48
50
  "migrate-to-brick-next-v3": true
49
51
  });
50
52
  }
51
53
  getMiscSettings() {
52
- var _bootstrapData3, _bootstrapData3$setti, _router$getRecentApps4, _router$getRecentApps5, _router$getRecentApps6;
53
- return _objectSpread(_objectSpread({}, (_bootstrapData3 = bootstrapData) === null || _bootstrapData3 === void 0 ? void 0 : (_bootstrapData3$setti = _bootstrapData3.settings) === null || _bootstrapData3$setti === void 0 ? void 0 : _bootstrapData3$setti.misc), (_router$getRecentApps4 = router.getRecentApps().currentApp) === null || _router$getRecentApps4 === void 0 ? void 0 : (_router$getRecentApps5 = _router$getRecentApps4.config) === null || _router$getRecentApps5 === void 0 ? void 0 : (_router$getRecentApps6 = _router$getRecentApps5.settings) === null || _router$getRecentApps6 === void 0 ? void 0 : _router$getRecentApps6.misc);
54
+ var _bootstrapData3, _bootstrapData3$setti, _router4, _router4$getRecentApp, _router4$getRecentApp2, _router4$getRecentApp3;
55
+ return _objectSpread(_objectSpread({}, (_bootstrapData3 = bootstrapData) === null || _bootstrapData3 === void 0 ? void 0 : (_bootstrapData3$setti = _bootstrapData3.settings) === null || _bootstrapData3$setti === void 0 ? void 0 : _bootstrapData3$setti.misc), (_router4 = router) === null || _router4 === void 0 ? void 0 : (_router4$getRecentApp = _router4.getRecentApps().currentApp) === null || _router4$getRecentApp === void 0 ? void 0 : (_router4$getRecentApp2 = _router4$getRecentApp.config) === null || _router4$getRecentApp2 === void 0 ? void 0 : (_router4$getRecentApp3 = _router4$getRecentApp2.settings) === null || _router4$getRecentApp3 === void 0 ? void 0 : _router4$getRecentApp3.misc);
54
56
  }
55
57
  getBrandSettings() {
56
58
  var _bootstrapData4, _bootstrapData4$setti;
@@ -81,7 +83,8 @@ export class Runtime {
81
83
  document.title = pageTitle ? "".concat(pageTitle, " - ").concat(baseTitle) : baseTitle;
82
84
  }
83
85
  getNavConfig() {
84
- return router.getNavConfig();
86
+ var _router5;
87
+ return (_router5 = router) === null || _router5 === void 0 ? void 0 : _router5.getNavConfig();
85
88
  }
86
89
  }
87
90
  export function _internalApiSetBootstrapData(data) {
@@ -92,15 +95,16 @@ export function getBrickPackages() {
92
95
  return (_bootstrapData$brickP = (_bootstrapData8 = bootstrapData) === null || _bootstrapData8 === void 0 ? void 0 : _bootstrapData8.brickPackages) !== null && _bootstrapData$brickP !== void 0 ? _bootstrapData$brickP : [];
93
96
  }
94
97
  export function _internalApiGetRenderId() {
95
- return router.getRenderId();
98
+ var _router6;
99
+ return (_router6 = router) === null || _router6 === void 0 ? void 0 : _router6.getRenderId();
96
100
  }
97
101
  export function _internalApiMatchStoryboard(pathname) {
98
102
  var _bootstrapData$storyb, _bootstrapData9;
99
103
  return matchStoryboard((_bootstrapData$storyb = (_bootstrapData9 = bootstrapData) === null || _bootstrapData9 === void 0 ? void 0 : _bootstrapData9.storyboards) !== null && _bootstrapData$storyb !== void 0 ? _bootstrapData$storyb : [], pathname);
100
104
  }
101
105
  export function _internalApiGetRuntimeContext() {
102
- var _router;
103
- return (_router = router) === null || _router === void 0 ? void 0 : _router.getRuntimeContext();
106
+ var _router7;
107
+ return (_router7 = router) === null || _router7 === void 0 ? void 0 : _router7.getRuntimeContext();
104
108
  }
105
109
  export function _internalApiGetStoryboardInBootstrapData(appId) {
106
110
  var _bootstrapData10, _bootstrapData10$stor;
@@ -1 +1 @@
1
- {"version":3,"file":"Runtime.js","names":["i18n","initializeI18n","moment","createHistory","matchStoryboard","Router","loadCheckLogin","loadBootstrapData","runtime","bootstrapData","router","createRuntime","Error","locale","language","on","Runtime","getRuntime","bootstrap","_asyncToGenerator","_bootstrapData","Promise","all","storyboards","getRecentApps","getCurrentApp","currentApp","getFeatureFlags","_bootstrapData2","_bootstrapData2$setti","_router$getRecentApps","_router$getRecentApps2","_router$getRecentApps3","_objectSpread","settings","featureFlags","config","getMiscSettings","_bootstrapData3","_bootstrapData3$setti","_router$getRecentApps4","_router$getRecentApps5","_router$getRecentApps6","misc","getBrandSettings","_bootstrapData4","_bootstrapData4$setti","base_title","brand","getLaunchpadSettings","_bootstrapData5","_bootstrapData5$setti","columns","rows","launchpad","getDesktops","_bootstrapData$deskto","_bootstrapData6","desktops","getLaunchpadSiteMap","_bootstrapData$siteSo","_bootstrapData7","siteSort","toggleLaunchpadEffect","open","document","body","classList","toggle","applyPageTitle","pageTitle","baseTitle","title","concat","getNavConfig","_internalApiSetBootstrapData","data","getBrickPackages","_bootstrapData$brickP","_bootstrapData8","brickPackages","_internalApiGetRenderId","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData9","_internalApiGetRuntimeContext","_router","getRuntimeContext","_internalApiGetStoryboardInBootstrapData","appId","_bootstrapData10","_bootstrapData10$stor","find","storyboard","app","id","_internalApiGetAppInBootstrapData","_internalApiGetStoryb"],"sources":["../../../src/internal/Runtime.ts"],"sourcesContent":["import type {\n RuntimeStoryboard,\n BootstrapSettings,\n FeatureFlags,\n BootstrapData,\n} from \"@next-core/types\";\nimport { i18n, initializeI18n } from \"@next-core/i18n\";\nimport moment from \"moment\";\nimport \"moment/locale/zh-cn.js\";\nimport { createHistory } from \"../history.js\";\nimport { matchStoryboard } from \"./matchStoryboard.js\";\nimport { Router } from \"./Router.js\";\nimport { loadCheckLogin } from \"./loadCheckLogin.js\";\nimport { loadBootstrapData } from \"./loadBootstrapData.js\";\n\nlet runtime: Runtime;\n\nlet bootstrapData: Partial<BootstrapData> | undefined;\nlet router!: Router;\n\nexport function createRuntime() {\n if (runtime) {\n throw new Error(\"Cannot create multiple runtimes\");\n }\n initializeI18n();\n moment.locale(i18n.language);\n i18n.on(\"languageChanged\", () => {\n moment.locale(i18n.language);\n });\n createHistory();\n runtime = new Runtime();\n return runtime;\n}\n\nexport function getRuntime() {\n return runtime;\n}\n\nexport class Runtime {\n async bootstrap() {\n const [, _bootstrapData] = await Promise.all([\n loadCheckLogin(),\n loadBootstrapData(),\n ]);\n bootstrapData = _bootstrapData;\n router = new Router(_bootstrapData.storyboards);\n await router.bootstrap();\n }\n\n getRecentApps() {\n return router.getRecentApps();\n }\n\n getCurrentApp() {\n return router.getRecentApps().currentApp;\n }\n\n getFeatureFlags(): FeatureFlags {\n return {\n ...bootstrapData?.settings?.featureFlags,\n ...(\n router.getRecentApps().currentApp?.config?.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?.settings as BootstrapSettings\n )?.misc,\n };\n }\n\n getBrandSettings(): Record<string, string> {\n return {\n base_title: \"DevOps 管理专家\",\n ...(bootstrapData?.settings?.brand as Record<string, string>),\n // ...(kernel.getOriginFaviconHref()\n // ? { favicon: kernel.getOriginFaviconHref() }\n // : {})\n };\n }\n\n getLaunchpadSettings() {\n return {\n columns: 7,\n rows: 4,\n ...bootstrapData?.settings?.launchpad,\n };\n }\n\n getDesktops(): unknown[] {\n return bootstrapData?.desktops ?? [];\n }\n\n getLaunchpadSiteMap(): unknown[] {\n return bootstrapData?.siteSort ?? [];\n }\n\n toggleLaunchpadEffect(open: boolean): void {\n document.body.classList.toggle(\"launchpad-open\", open);\n }\n\n applyPageTitle(pageTitle: string): void {\n const baseTitle = this.getBrandSettings().base_title;\n document.title = pageTitle ? `${pageTitle} - ${baseTitle}` : baseTitle;\n }\n\n getNavConfig() {\n return router.getNavConfig();\n }\n}\n\nexport function _internalApiSetBootstrapData(data: Partial<BootstrapData>) {\n bootstrapData = data;\n}\n\nexport function getBrickPackages() {\n return bootstrapData?.brickPackages ?? [];\n}\n\nexport function _internalApiGetRenderId(): string | undefined {\n return router.getRenderId();\n}\n\nexport function _internalApiMatchStoryboard(\n pathname: string\n): RuntimeStoryboard | undefined {\n return matchStoryboard(bootstrapData?.storyboards ?? [], pathname);\n}\n\nexport function _internalApiGetRuntimeContext() {\n return router?.getRuntimeContext();\n}\n\nexport function _internalApiGetStoryboardInBootstrapData(appId: string) {\n return bootstrapData?.storyboards?.find(\n (storyboard) => storyboard.app.id === appId\n );\n}\n\nexport function _internalApiGetAppInBootstrapData(appId: string) {\n return _internalApiGetStoryboardInBootstrapData(appId)?.app;\n}\n"],"mappings":";;AAMA,SAASA,IAAI,EAAEC,cAAc,QAAQ,iBAAiB;AACtD,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAO,wBAAwB;AAC/B,SAASC,aAAa,QAAQ,eAAe;AAC7C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,iBAAiB,QAAQ,wBAAwB;AAE1D,IAAIC,OAAgB;AAEpB,IAAIC,aAAiD;AACrD,IAAIC,MAAe;AAEnB,OAAO,SAASC,aAAaA,CAAA,EAAG;EAC9B,IAAIH,OAAO,EAAE;IACX,MAAM,IAAII,KAAK,CAAC,iCAAiC,CAAC;EACpD;EACAX,cAAc,EAAE;EAChBC,MAAM,CAACW,MAAM,CAACb,IAAI,CAACc,QAAQ,CAAC;EAC5Bd,IAAI,CAACe,EAAE,CAAC,iBAAiB,EAAE,MAAM;IAC/Bb,MAAM,CAACW,MAAM,CAACb,IAAI,CAACc,QAAQ,CAAC;EAC9B,CAAC,CAAC;EACFX,aAAa,EAAE;EACfK,OAAO,GAAG,IAAIQ,OAAO,EAAE;EACvB,OAAOR,OAAO;AAChB;AAEA,OAAO,SAASS,UAAUA,CAAA,EAAG;EAC3B,OAAOT,OAAO;AAChB;AAEA,OAAO,MAAMQ,OAAO,CAAC;EACbE,SAASA,CAAA,EAAG;IAAA,OAAAC,iBAAA;MAChB,IAAM,GAAGC,cAAc,CAAC,SAASC,OAAO,CAACC,GAAG,CAAC,CAC3ChB,cAAc,EAAE,EAChBC,iBAAiB,EAAE,CACpB,CAAC;MACFE,aAAa,GAAGW,cAAc;MAC9BV,MAAM,GAAG,IAAIL,MAAM,CAACe,cAAc,CAACG,WAAW,CAAC;MAC/C,MAAMb,MAAM,CAAC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AQ,qBAAA;EAC/D,QAAAA,qBAAA,GAAOT,wCAAwC,CAACC,KAAK,CAAC,cAAAQ,qBAAA,uBAA/CA,qBAAA,CAAiDH,GAAG;AAC7D"}
1
+ {"version":3,"file":"Runtime.js","names":["i18n","initializeI18n","moment","createHistory","matchStoryboard","Router","loadCheckLogin","loadBootstrapData","runtime","bootstrapData","router","createRuntime","Error","locale","language","on","Runtime","getRuntime","bootstrap","_asyncToGenerator","_bootstrapData","Promise","all","storyboards","getRecentApps","_router$getRecentApps","_router","getCurrentApp","_router2","currentApp","getFeatureFlags","_bootstrapData2","_bootstrapData2$setti","_router3","_router3$getRecentApp","_router3$getRecentApp2","_router3$getRecentApp3","_objectSpread","settings","featureFlags","config","getMiscSettings","_bootstrapData3","_bootstrapData3$setti","_router4","_router4$getRecentApp","_router4$getRecentApp2","_router4$getRecentApp3","misc","getBrandSettings","_bootstrapData4","_bootstrapData4$setti","base_title","brand","getLaunchpadSettings","_bootstrapData5","_bootstrapData5$setti","columns","rows","launchpad","getDesktops","_bootstrapData$deskto","_bootstrapData6","desktops","getLaunchpadSiteMap","_bootstrapData$siteSo","_bootstrapData7","siteSort","toggleLaunchpadEffect","open","document","body","classList","toggle","applyPageTitle","pageTitle","baseTitle","title","concat","getNavConfig","_router5","_internalApiSetBootstrapData","data","getBrickPackages","_bootstrapData$brickP","_bootstrapData8","brickPackages","_internalApiGetRenderId","_router6","getRenderId","_internalApiMatchStoryboard","pathname","_bootstrapData$storyb","_bootstrapData9","_internalApiGetRuntimeContext","_router7","getRuntimeContext","_internalApiGetStoryboardInBootstrapData","appId","_bootstrapData10","_bootstrapData10$stor","find","storyboard","app","id","_internalApiGetAppInBootstrapData","_internalApiGetStoryb"],"sources":["../../../src/internal/Runtime.ts"],"sourcesContent":["import type {\n RuntimeStoryboard,\n BootstrapSettings,\n FeatureFlags,\n BootstrapData,\n} from \"@next-core/types\";\nimport { i18n, initializeI18n } from \"@next-core/i18n\";\nimport moment from \"moment\";\nimport \"moment/locale/zh-cn.js\";\nimport { createHistory } from \"../history.js\";\nimport { matchStoryboard } from \"./matchStoryboard.js\";\nimport { Router } from \"./Router.js\";\nimport { loadCheckLogin } from \"./loadCheckLogin.js\";\nimport { loadBootstrapData } from \"./loadBootstrapData.js\";\n\nlet runtime: Runtime;\n\nlet bootstrapData: Partial<BootstrapData> | undefined;\nlet router: Router | undefined;\n\nexport function createRuntime() {\n if (runtime) {\n throw new Error(\"Cannot create multiple runtimes\");\n }\n initializeI18n();\n moment.locale(i18n.language);\n i18n.on(\"languageChanged\", () => {\n moment.locale(i18n.language);\n });\n createHistory();\n runtime = new Runtime();\n return runtime;\n}\n\nexport function getRuntime() {\n return runtime;\n}\n\nexport class Runtime {\n async bootstrap() {\n const [, _bootstrapData] = await Promise.all([\n loadCheckLogin(),\n loadBootstrapData(),\n ]);\n bootstrapData = _bootstrapData;\n router = new Router(_bootstrapData.storyboards);\n await router.bootstrap();\n }\n\n getRecentApps() {\n return router?.getRecentApps() ?? {};\n }\n\n getCurrentApp() {\n return router?.getRecentApps().currentApp;\n }\n\n getFeatureFlags(): FeatureFlags {\n return {\n ...bootstrapData?.settings?.featureFlags,\n ...(\n router?.getRecentApps().currentApp?.config\n ?.settings as BootstrapSettings\n )?.featureFlags,\n \"migrate-to-brick-next-v3\": true,\n };\n }\n\n getMiscSettings() {\n return {\n ...bootstrapData?.settings?.misc,\n ...(\n router?.getRecentApps().currentApp?.config\n ?.settings as BootstrapSettings\n )?.misc,\n };\n }\n\n getBrandSettings(): Record<string, string> {\n return {\n base_title: \"DevOps 管理专家\",\n ...(bootstrapData?.settings?.brand as Record<string, string>),\n // ...(kernel.getOriginFaviconHref()\n // ? { favicon: kernel.getOriginFaviconHref() }\n // : {})\n };\n }\n\n getLaunchpadSettings() {\n return {\n columns: 7,\n rows: 4,\n ...bootstrapData?.settings?.launchpad,\n };\n }\n\n getDesktops(): unknown[] {\n return bootstrapData?.desktops ?? [];\n }\n\n getLaunchpadSiteMap(): unknown[] {\n return bootstrapData?.siteSort ?? [];\n }\n\n toggleLaunchpadEffect(open: boolean): void {\n document.body.classList.toggle(\"launchpad-open\", open);\n }\n\n applyPageTitle(pageTitle: string): void {\n const baseTitle = this.getBrandSettings().base_title;\n document.title = pageTitle ? `${pageTitle} - ${baseTitle}` : baseTitle;\n }\n\n getNavConfig() {\n return router?.getNavConfig();\n }\n}\n\nexport function _internalApiSetBootstrapData(data: Partial<BootstrapData>) {\n bootstrapData = data;\n}\n\nexport function getBrickPackages() {\n return bootstrapData?.brickPackages ?? [];\n}\n\nexport function _internalApiGetRenderId(): string | undefined {\n return router?.getRenderId();\n}\n\nexport function _internalApiMatchStoryboard(\n pathname: string\n): RuntimeStoryboard | undefined {\n return matchStoryboard(bootstrapData?.storyboards ?? [], pathname);\n}\n\nexport function _internalApiGetRuntimeContext() {\n return router?.getRuntimeContext();\n}\n\nexport function _internalApiGetStoryboardInBootstrapData(appId: string) {\n return bootstrapData?.storyboards?.find(\n (storyboard) => storyboard.app.id === appId\n );\n}\n\nexport function _internalApiGetAppInBootstrapData(appId: string) {\n return _internalApiGetStoryboardInBootstrapData(appId)?.app;\n}\n"],"mappings":";;AAMA,SAASA,IAAI,EAAEC,cAAc,QAAQ,iBAAiB;AACtD,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAO,wBAAwB;AAC/B,SAASC,aAAa,QAAQ,eAAe;AAC7C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,iBAAiB,QAAQ,wBAAwB;AAE1D,IAAIC,OAAgB;AAEpB,IAAIC,aAAiD;AACrD,IAAIC,MAA0B;AAE9B,OAAO,SAASC,aAAaA,CAAA,EAAG;EAC9B,IAAIH,OAAO,EAAE;IACX,MAAM,IAAII,KAAK,CAAC,iCAAiC,CAAC;EACpD;EACAX,cAAc,EAAE;EAChBC,MAAM,CAACW,MAAM,CAACb,IAAI,CAACc,QAAQ,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are","collectInstalledAppsHasUsage","_internalApiGetAppInBootstrapData","checkingApps","Map","checkedApps","preCheckInstalledApps","storyboard","window","STANDALONE_MICRO_APPS","NO_AUTH_GUARD","appIds","scanInstalledAppsUsage","searchIds","appId","has","push","length","promise","query","$in","fields","catch","error","console","_loop","set","then","result","_result$list","app","list","find","item","checkedApp","_objectSpread","id","undefined","waitForCheckingApps","Promise","all","map","get","hasInstalledApp","matchVersion","installStatus","currentVersion","matches","match","TypeError","concat","_storyboard$meta","usage","usedArgs","Set","customTemplates","menus","meta","routes","node","parent"],"sources":["../../../src/internal/checkInstalledApps.ts"],"sourcesContent":["import type { MicroApp, Storyboard } from \"@next-core/types\";\nimport { traverseStoryboardExpressions } from \"@next-core/utils/storyboard\";\nimport { RuntimeApi_searchMicroAppStandalone } from \"@next-api-sdk/micro-app-standalone-sdk\";\nimport { type CompareOperator, compare } from \"compare-versions\";\nimport {\n MemberCallUsage,\n collectInstalledAppsHasUsage,\n} from \"./compute/collectMemberCallUsage.js\";\nimport { _internalApiGetAppInBootstrapData } from \"./Runtime.js\";\n\ntype AppForCheck = Pick<MicroApp, \"id\" | \"currentVersion\" | \"installStatus\">;\n\nconst checkingApps = new Map<string, Promise<AppForCheck | undefined>>();\nconst checkedApps = new Map<string, AppForCheck | undefined>();\n\nexport function preCheckInstalledApps(storyboard: Storyboard) {\n if (window.STANDALONE_MICRO_APPS && !window.NO_AUTH_GUARD) {\n const appIds = scanInstalledAppsUsage(storyboard);\n const searchIds: string[] = [];\n for (const appId of appIds) {\n // Do not check these apps already checking or in bootstrap.\n if (\n !checkingApps.has(appId) &&\n !_internalApiGetAppInBootstrapData(appId)\n ) {\n searchIds.push(appId);\n }\n }\n if (searchIds.length === 0) {\n return;\n }\n const promise = RuntimeApi_searchMicroAppStandalone({\n query: { appId: { $in: searchIds } },\n fields: [\"appId\", \"currentVersion\", \"installStatus\"],\n }).catch((error) => {\n // Allow search micro app to fail, and\n // make it not crash when the backend service is not updated.\n // eslint-disable-next-line no-console\n console.error(\"Get off site standalone micro-apps failed\", error);\n });\n for (const appId of searchIds) {\n checkingApps.set(\n appId,\n promise.then((result) => {\n const app = result?.list?.find((item) => item.appId === appId);\n const checkedApp = app\n ? {\n ...app,\n id: appId,\n }\n : undefined;\n checkedApps.set(appId, checkedApp);\n return checkedApp;\n })\n );\n }\n }\n}\n\nexport function waitForCheckingApps(appIds: string[]) {\n return Promise.all(appIds.map((appId) => checkingApps.get(appId)));\n}\n\nexport function hasInstalledApp(appId: string, matchVersion?: string): boolean {\n // First, check whether the app is in bootstrap already.\n let app = _internalApiGetAppInBootstrapData(appId) as AppForCheck | undefined;\n if (!app && window.STANDALONE_MICRO_APPS) {\n app = checkedApps.get(appId);\n }\n if (!app || app.installStatus === \"running\") {\n return false;\n }\n // Todo: `currentVersion` maybe `\"\"`\n if (!matchVersion || !app.currentVersion) {\n return true;\n }\n // Valid `matchVersion`:\n // >=1.2.3\n // >1.2.3\n // =1.2.3\n // <=1.2.3\n // <1.2.3\n const matches = matchVersion.match(/^([><]=?|=)(.*)$/);\n try {\n if (!matches) {\n throw new TypeError(`Invalid match version: ${matchVersion}`);\n }\n return compare(\n app.currentVersion,\n matches[2],\n matches[1] as CompareOperator\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n return false;\n}\n\nfunction scanInstalledAppsUsage(storyboard: Storyboard) {\n const usage: MemberCallUsage = {\n usedArgs: new Set(),\n };\n // `INSTALLED_APPS.has(...)` is not available in storyboard functions\n const { customTemplates, menus } = storyboard.meta ?? {};\n traverseStoryboardExpressions(\n [storyboard.routes, customTemplates, menus],\n (node, parent) => {\n collectInstalledAppsHasUsage(usage, node, parent);\n },\n \"INSTALLED_APPS\"\n );\n return [...usage.usedArgs];\n}\n"],"mappings":";AACA,SAASA,6BAA6B,QAAQ,6BAA6B;AAC3E,SAASC,mCAAmC,QAAQ,wCAAwC;AAC5F,SAA+BC,OAAO,QAAQ,kBAAkB;AAChE,SAEEC,4BAA4B,QACvB,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A,OAAO,CAAC,CAAC,CAAC,CACX;EACH,CAAC,CAAC,OAAOxB,KAAK,EAAE;IACd;IACAC,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC;EACtB;EACA,OAAO,KAAK;AACd;AAEA,SAASX,sBAAsBA,CAACL,UAAsB,EAAE;EAAA,IAAA4C,gBAAA;EACtD,IAAMC,KAAsB,GAAG;IAC7BC,QAAQ,EAAE,IAAIC,GAAG;EACnB,CAAC;EACD;EACA,IAAM;IAAEC,eAAe;IAAEC;EAAM,CAAC,IAAAL,gBAAA,GAAG5C,UAAU,CAACkD,IAAI,cAAAN,gBAAA,cAAAA,gBAAA,GAAI,CAAC,CAAC;EACxDrD,6BAA6B,CAC3B,CAACS,UAAU,CAACmD,MAAM,EAAEH,eAAe,EAAEC,KAAK,CAAC,EAC3C,CAACG,IAAI,EAAEC,MAAM,KAAK;IAChB3D,4BAA4B,CAACmD,KAAK,EAAEO,IAAI,EAAEC,MAAM,CAAC;EACnD,CAAC,EACD,gBAAgB,CACjB;EACD,OAAO,CAAC,GAAGR,KAAK,CAACC,QAAQ,CAAC;AAC5B"}
1
+ {"version":3,"file":"checkInstalledApps.js","names":["traverseStoryboardExpressions","RuntimeApi_searchMicroAppStandalone","compare","collectInstalledAppsHasUsage","_internalApiGetAppInBootstrapData","checkingApps","Map","checkedApps","preCheckInstalledApps","storyboard","window","STANDALONE_MICRO_APPS","NO_AUTH_GUARD","appIds","scanInstalledAppsUsage","searchIds","appId","has","push","length","promise","query","$in","fields","catch","error","console","_loop","_appId","set","then","result","_result$list","app","list","find","item","checkedApp","_objectSpread","id","undefined","waitForCheckingApps","Promise","all","map","get","hasInstalledApp","matchVersion","installStatus","currentVersion","matches","match","TypeError","concat","_storyboard$meta","usage","usedArgs","Set","customTemplates","menus","meta","routes","node","parent"],"sources":["../../../src/internal/checkInstalledApps.ts"],"sourcesContent":["import type { MicroApp, Storyboard } from \"@next-core/types\";\nimport { traverseStoryboardExpressions } from \"@next-core/utils/storyboard\";\nimport { RuntimeApi_searchMicroAppStandalone } from \"@next-api-sdk/micro-app-standalone-sdk\";\nimport { type CompareOperator, compare } from \"compare-versions\";\nimport {\n MemberCallUsage,\n collectInstalledAppsHasUsage,\n} from \"./compute/collectMemberCallUsage.js\";\nimport { _internalApiGetAppInBootstrapData } from \"./Runtime.js\";\n\ntype AppForCheck = Pick<MicroApp, \"id\" | \"currentVersion\" | \"installStatus\">;\n\nconst checkingApps = new Map<string, Promise<AppForCheck | undefined>>();\nconst checkedApps = new Map<string, AppForCheck | undefined>();\n\nexport function preCheckInstalledApps(storyboard: Storyboard) {\n if (window.STANDALONE_MICRO_APPS && !window.NO_AUTH_GUARD) {\n const appIds = scanInstalledAppsUsage(storyboard);\n const searchIds: string[] = [];\n for (const appId of appIds) {\n // Do not check these apps already checking or in bootstrap.\n if (\n !checkingApps.has(appId) &&\n !_internalApiGetAppInBootstrapData(appId)\n ) {\n searchIds.push(appId);\n }\n }\n if (searchIds.length === 0) {\n return;\n }\n const promise = RuntimeApi_searchMicroAppStandalone({\n query: { appId: { $in: searchIds } },\n fields: [\"appId\", \"currentVersion\", \"installStatus\"],\n }).catch((error) => {\n // Allow search micro app to fail, and\n // make it not crash when the backend service is not updated.\n // eslint-disable-next-line no-console\n console.error(\"Get off site standalone micro-apps failed\", error);\n });\n for (const appId of searchIds) {\n checkingApps.set(\n appId,\n promise.then((result) => {\n const app = result?.list?.find((item) => item.appId === appId);\n const checkedApp = app\n ? {\n ...app,\n id: appId,\n }\n : undefined;\n checkedApps.set(appId, checkedApp);\n return checkedApp;\n })\n );\n }\n }\n}\n\nexport function waitForCheckingApps(appIds: string[]) {\n return Promise.all(appIds.map((appId) => checkingApps.get(appId)));\n}\n\nexport function hasInstalledApp(appId: string, matchVersion?: string): boolean {\n // First, check whether the app is in bootstrap already.\n let app = _internalApiGetAppInBootstrapData(appId) as AppForCheck | undefined;\n if (!app && window.STANDALONE_MICRO_APPS) {\n app = checkedApps.get(appId);\n }\n if (!app || app.installStatus === \"running\") {\n return false;\n }\n // Todo: `currentVersion` maybe `\"\"`\n if (!matchVersion || !app.currentVersion) {\n return true;\n }\n // Valid `matchVersion`:\n // >=1.2.3\n // >1.2.3\n // =1.2.3\n // <=1.2.3\n // <1.2.3\n const matches = matchVersion.match(/^([><]=?|=)(.*)$/);\n try {\n if (!matches) {\n throw new TypeError(`Invalid match version: ${matchVersion}`);\n }\n return compare(\n app.currentVersion,\n matches[2],\n matches[1] as CompareOperator\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n return false;\n}\n\nfunction scanInstalledAppsUsage(storyboard: Storyboard) {\n const usage: MemberCallUsage = {\n usedArgs: new Set(),\n };\n // `INSTALLED_APPS.has(...)` is not available in storyboard functions\n const { customTemplates, menus } = storyboard.meta ?? {};\n traverseStoryboardExpressions(\n [storyboard.routes, customTemplates, menus],\n (node, parent) => {\n collectInstalledAppsHasUsage(usage, node, parent);\n },\n \"INSTALLED_APPS\"\n );\n return [...usage.usedArgs];\n}\n"],"mappings":";AACA,SAASA,6BAA6B,QAAQ,6BAA6B;AAC3E,SAASC,mCAAmC,QAAQ,wCAAwC;AAC5F,SAA+BC,OAAO,QAAQ,kBAAkB;AAChE,SAEEC,4BAA4B,QACvB,qCAAqC;AAC5C,SAASC,iCAAiC,QAAQ,cAAc;AAIhE,IAAMC,YAAY,GAAG,IAAIC,GAAG,EAA4C;AACxE,IAAMC,WAAW,GAAG,IAAID,GAAG,EAAmC;AAE9D,OAAO,SAASE,qBAAqBA,CAACC,UAAsB,EAAE;EAC5D,IAAIC,MAAM,CAACC,qBAAqB,IAAI,CAACD,MAAM,CAACE,aAAa,EAAE;IACzD,IAAMC,MAAM,GAAGC,sBAAsB,CAACL,UAAU,CAAC;IACjD,IAAMM,SAAmB,GAAG,EAAE;IAC9B,KAAK,IAAMC,KAAK,IAAIH,MAAM,EAAE;MAC1B;MACA,IACE,CAACR,YAAY,CAACY,GAAG,CAACD,KAAK,CAAC,IACxB,CAACZ,iCAAi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CAACoD,MAAM,EAAEH,eAAe,EAAEC,KAAK,CAAC,EAC3C,CAACG,IAAI,EAAEC,MAAM,KAAK;IAChB5D,4BAA4B,CAACoD,KAAK,EAAEO,IAAI,EAAEC,MAAM,CAAC;EACnD,CAAC,EACD,gBAAgB,CACjB;EACD,OAAO,CAAC,GAAGR,KAAK,CAACC,QAAQ,CAAC;AAC5B"}
@@ -3,6 +3,11 @@ import { hasOwnProperty, isObject } from "@next-core/utils/general";
3
3
  import { asyncComputeRealValue, computeRealValue } from "./computeRealValue.js";
4
4
  import { isPreEvaluated } from "./evaluate.js";
5
5
  import { resolveData } from "../data/resolveData.js";
6
+
7
+ /**
8
+ * 包含 `if` 条件判断的对象。
9
+ */
10
+
6
11
  export function asyncCheckIf(_x, _x2) {
7
12
  return _asyncCheckIf.apply(this, arguments);
8
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"checkIf.js","names":["hasOwnProperty","isObject","asyncComputeRealValue","computeRealValue","isPreEvaluated","resolveData","asyncCheckIf","_x","_x2","_asyncCheckIf","apply","arguments","_asyncToGenerator","ifContainer","runtimeContext","if","checkIf","checkIfOfComputed","asyncCheckBrickIf","_x3","_x4","_asyncCheckBrickIf","brickConf","resolved","checkIfByTransform","data"],"sources":["../../../../src/internal/compute/checkIf.ts"],"sourcesContent":["import { hasOwnProperty, isObject } from \"@next-core/utils/general\";\nimport type { BrickConf, ResolveConf } from \"@next-core/types\";\nimport { asyncComputeRealValue, computeRealValue } from \"./computeRealValue.js\";\nimport { isPreEvaluated } from \"./evaluate.js\";\nimport { resolveData } from \"../data/resolveData.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\n\n/**\n * 包含 `if` 条件判断的对象。\n */\nexport interface IfContainer {\n /**\n * 条件判断,可以为表达式字符串。\n *\n * @example\n *\n * ```yaml\n * - brick: your.any-brick\n * if: '<% FLAGS[\"your-feature-flag\"] %>'\n * ```\n */\n if?: unknown;\n}\n\nexport async function asyncCheckIf(\n ifContainer: IfContainer,\n runtimeContext: RuntimeContext\n): Promise<boolean> {\n return (\n !hasOwnProperty(ifContainer, \"if\") ||\n !!(typeof ifContainer.if === \"string\" || isPreEvaluated(ifContainer.if)\n ? await asyncComputeRealValue(ifContainer.if, runtimeContext)\n : ifContainer.if)\n );\n}\n\nexport function checkIf(\n ifContainer: IfContainer,\n runtimeContext: RuntimeContext\n): boolean {\n return (\n !hasOwnProperty(ifContainer, \"if\") ||\n !!(typeof ifContainer.if === \"string\" || isPreEvaluated(ifContainer.if)\n ? computeRealValue(ifContainer.if, runtimeContext)\n : ifContainer.if)\n );\n}\n\nexport function checkIfOfComputed(ifContainer: IfContainer): boolean {\n return !hasOwnProperty(ifContainer, \"if\") || !!ifContainer.if;\n}\n\nexport async function asyncCheckBrickIf(\n brickConf: BrickConf,\n runtimeContext: RuntimeContext\n): Promise<boolean> {\n if (isObject(brickConf.if) && !isPreEvaluated(brickConf.if)) {\n const resolved = (await resolveData(\n brickConf.if as ResolveConf,\n runtimeContext\n )) as { if?: unknown };\n return checkIfOfComputed(resolved);\n }\n return asyncCheckIf(brickConf, runtimeContext);\n}\n\nexport function checkIfByTransform(ifContainer: IfContainer, data: unknown) {\n return checkIf(ifContainer, { data } as RuntimeContext);\n}\n"],"mappings":";AAAA,SAASA,cAAc,EAAEC,QAAQ,QAAQ,0BAA0B;AAEnE,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,uBAAuB;AAC/E,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,wBAAwB;AAoBpD,gBAAsBC,YAAYA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,aAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAUjC,SAAAF,cAAA;EAAAA,aAAA,GAAAG,iBAAA,CAVM,WACLC,WAAwB,EACxBC,cAA8B,EACZ;IAClB,OACE,CAACd,cAAc,CAACa,WAAW,EAAE,IAAI,CAAC,IAClC,CAAC,EAAE,OAAOA,WAAW,CAACE,EAAE,KAAK,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CAACX,WAAwB,EAAEY,IAAa,EAAE;EAC1E,OAAOT,OAAO,CAACH,WAAW,EAAE;IAAEY;EAAK,CAAC,CAAmB;AACzD"}
1
+ {"version":3,"file":"checkIf.js","names":["hasOwnProperty","isObject","asyncComputeRealValue","computeRealValue","isPreEvaluated","resolveData","asyncCheckIf","_x","_x2","_asyncCheckIf","apply","arguments","_asyncToGenerator","ifContainer","runtimeContext","if","checkIf","checkIfOfComputed","asyncCheckBrickIf","_x3","_x4","_asyncCheckBrickIf","brickConf","resolved","checkIfByTransform","data"],"sources":["../../../../src/internal/compute/checkIf.ts"],"sourcesContent":["import { hasOwnProperty, isObject } from \"@next-core/utils/general\";\nimport type { BrickConf, ResolveConf } from \"@next-core/types\";\nimport { asyncComputeRealValue, computeRealValue } from \"./computeRealValue.js\";\nimport { isPreEvaluated } from \"./evaluate.js\";\nimport { resolveData } from \"../data/resolveData.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\n\n/**\n * 包含 `if` 条件判断的对象。\n */\nexport interface IfContainer {\n /**\n * 条件判断,可以为表达式字符串。\n *\n * @example\n *\n * ```yaml\n * - brick: your.any-brick\n * if: '<% FLAGS[\"your-feature-flag\"] %>'\n * ```\n */\n if?: unknown;\n}\n\nexport async function asyncCheckIf(\n ifContainer: IfContainer,\n runtimeContext: RuntimeContext\n): Promise<boolean> {\n return (\n !hasOwnProperty(ifContainer, \"if\") ||\n !!(typeof ifContainer.if === \"string\" || isPreEvaluated(ifContainer.if)\n ? await asyncComputeRealValue(ifContainer.if, runtimeContext)\n : ifContainer.if)\n );\n}\n\nexport function checkIf(\n ifContainer: IfContainer,\n runtimeContext: RuntimeContext\n): boolean {\n return (\n !hasOwnProperty(ifContainer, \"if\") ||\n !!(typeof ifContainer.if === \"string\" || isPreEvaluated(ifContainer.if)\n ? computeRealValue(ifContainer.if, runtimeContext)\n : ifContainer.if)\n );\n}\n\nexport function checkIfOfComputed(ifContainer: IfContainer): boolean {\n return !hasOwnProperty(ifContainer, \"if\") || !!ifContainer.if;\n}\n\nexport async function asyncCheckBrickIf(\n brickConf: BrickConf,\n runtimeContext: RuntimeContext\n): Promise<boolean> {\n if (isObject(brickConf.if) && !isPreEvaluated(brickConf.if)) {\n const resolved = (await resolveData(\n brickConf.if as ResolveConf,\n runtimeContext\n )) as { if?: unknown };\n return checkIfOfComputed(resolved);\n }\n return asyncCheckIf(brickConf, runtimeContext);\n}\n\nexport function checkIfByTransform(ifContainer: IfContainer, data: unknown) {\n return checkIf(ifContainer, { data } as RuntimeContext);\n}\n"],"mappings":";AAAA,SAASA,cAAc,EAAEC,QAAQ,QAAQ,0BAA0B;AAEnE,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,uBAAuB;AAC/E,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,wBAAwB;;AAGpD;AACA;AACA;;AAeA,gBAAsBC,YAAYA,CAAAC,EAAA,EAAAC,GAAA;EAAA,OAAAC,aAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAUjC,SAAAF,cAAA;EAAAA,aAAA,GAAAG,iBAAA,CAVM,WACLC,WAAwB,EACxBC,cAA8B,EACZ;IAClB,OACE,CAACd,cAAc,CAACa,WAAW,EAAE,IAAI,CAAC,IAClC,CAAC,EAAE,OAAOA,WAAW,CAACE,EAAE,KAAK,QAAQ,IAAIX,cAAc,CAACS,WAAW,CAACE,EAAE,CAAC,SAC7Db,qBAAqB,CAACW,WAAW,CAACE,EAAE,EAAED,cAAc,CAAC,GAC3DD,WAAW,CAACE,EAAE,CAAC;EAEvB,CAAC;EAAA,OAAAN,aAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAED,OAAO,SAASK,OAAOA,CACrBH,WAAwB,EACxBC,cAA8B,EACrB;EACT,OACE,CAACd,cAAc,CAACa,WAAW,EAAE,IAAI,CAAC,IAClC,CAAC,EAAE,OAAOA,WAAW,CAACE,EAAE,KAAK,QAAQ,IAAIX,cAAc,CAACS,WAAW,CAACE,EAAE,CAAC,GACnEZ,gBAAgB,CAACU,WAAW,CAACE,EAAE,EAAED,cAAc,CAAC,GAChDD,WAAW,CAACE,EAAE,CAAC;AAEvB;AAEA,OAAO,SAASE,iBAAiBA,CAACJ,WAAwB,EAAW;EACnE,OAAO,CAACb,cAAc,CAACa,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,CAACA,WAAW,CAACE,EAAE;AAC/D;AAEA,gBAAsBG,iBAAiBA,CAAAC,GAAA,EAAAC,GAAA;EAAA,OAAAC,kBAAA,CAAAX,KAAA,OAAAC,SAAA;AAAA;AAYtC,SAAAU,mBAAA;EAAAA,kBAAA,GAAAT,iBAAA,CAZM,WACLU,SAAoB,EACpBR,cAA8B,EACZ;IAClB,IAAIb,QAAQ,CAACqB,SAAS,CAACP,EAAE,CAAC,IAAI,CAACX,cAAc,CAACkB,SAAS,CAACP,EAAE,CAAC,EAAE;MAC3D,IAAMQ,QAAQ,SAAUlB,WAAW,CACjCiB,SAAS,CAACP,EAAE,EACZD,cAAc,CACM;MACtB,OAAOG,iBAAiB,CAACM,QAAQ,CAAC;IACpC;IACA,OAAOjB,YAAY,CAACgB,SAAS,EAAER,cAAc,CAAC;EAChD,CAAC;EAAA,OAAAO,kBAAA,CAAAX,KAAA,OAAAC,SAAA;AAAA;AAED,OAAO,SAASa,kBAAkBA,CAACX,WAAwB,EAAEY,IAAa,EAAE;EAC1E,OAAOT,OAAO,CAACH,WAAW,EAAE;IAAEY;EAAK,CAAC,CAAmB;AACzD"}
@@ -1,5 +1,4 @@
1
- export var StateOfUseBrick;
2
- (function (StateOfUseBrick) {
1
+ export var StateOfUseBrick = /*#__PURE__*/function (StateOfUseBrick) {
3
2
  StateOfUseBrick[StateOfUseBrick["INITIAL"] = 0] = "INITIAL";
4
3
  StateOfUseBrick[StateOfUseBrick["USE_BRICK"] = 1] = "USE_BRICK";
5
4
  StateOfUseBrick[StateOfUseBrick["USE_BRICK_ITEM"] = 2] = "USE_BRICK_ITEM";
@@ -13,7 +12,8 @@ export var StateOfUseBrick;
13
12
  StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM_BRICKS_ITEM"] = 10] = "USE_BRICK_SLOTS_ITEM_BRICKS_ITEM";
14
13
  StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE"] = 11] = "USE_BRICK_LIFECYCLE";
15
14
  StateOfUseBrick[StateOfUseBrick["USE_BRICK_DATA_SOURCE"] = 12] = "USE_BRICK_DATA_SOURCE";
16
- })(StateOfUseBrick || (StateOfUseBrick = {}));
15
+ return StateOfUseBrick;
16
+ }({});
17
17
  export function isLazyContentInUseBrick(state) {
18
18
  switch (state) {
19
19
  case StateOfUseBrick.USE_BRICK_PROPERTIES:
@@ -1 +1 @@
1
- {"version":3,"file":"getNextStateOfUseBrick.js","names":["StateOfUseBrick","isLazyContentInUseBrick","state","USE_BRICK_PROPERTIES","USE_BRICK_TRANSFORM","USE_BRICK_EVENTS","USE_BRICK_IF","USE_BRICK_LIFECYCLE","USE_BRICK_DATA_SOURCE","getNextStateOfUseBrick","isArray","key","USE_BRICK","USE_BRICK_ITEM","USE_BRICK_SLOTS_ITEM_BRICKS","USE_BRICK_SLOTS_ITEM_BRICKS_ITEM","INITIAL","USE_BRICK_SLOTS","USE_BRICK_SLOTS_ITEM"],"sources":["../../../../src/internal/compute/getNextStateOfUseBrick.ts"],"sourcesContent":["export enum StateOfUseBrick {\n INITIAL,\n USE_BRICK,\n USE_BRICK_ITEM,\n USE_BRICK_PROPERTIES,\n // Compatible mode\n USE_BRICK_TRANSFORM,\n USE_BRICK_EVENTS,\n USE_BRICK_IF,\n USE_BRICK_SLOTS,\n USE_BRICK_SLOTS_ITEM,\n USE_BRICK_SLOTS_ITEM_BRICKS,\n USE_BRICK_SLOTS_ITEM_BRICKS_ITEM,\n USE_BRICK_LIFECYCLE,\n USE_BRICK_DATA_SOURCE,\n}\n\nexport function isLazyContentInUseBrick(\n state: StateOfUseBrick | undefined\n): boolean {\n switch (state) {\n case StateOfUseBrick.USE_BRICK_PROPERTIES:\n case StateOfUseBrick.USE_BRICK_TRANSFORM:\n case StateOfUseBrick.USE_BRICK_EVENTS:\n case StateOfUseBrick.USE_BRICK_IF:\n case StateOfUseBrick.USE_BRICK_LIFECYCLE:\n case StateOfUseBrick.USE_BRICK_DATA_SOURCE:\n return true;\n }\n return false;\n}\n\nexport function getNextStateOfUseBrick(\n state: StateOfUseBrick | undefined,\n isArray?: boolean,\n key?: string\n): StateOfUseBrick | undefined {\n if (isLazyContentInUseBrick(state)) {\n return state;\n }\n if (isArray) {\n switch (state) {\n case StateOfUseBrick.USE_BRICK:\n return StateOfUseBrick.USE_BRICK_ITEM;\n case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS:\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM;\n }\n } else {\n switch (state) {\n case StateOfUseBrick.INITIAL:\n if (key === \"useBrick\") {\n return StateOfUseBrick.USE_BRICK;\n }\n break;\n case StateOfUseBrick.USE_BRICK:\n case StateOfUseBrick.USE_BRICK_ITEM:\n case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM: {\n switch (key) {\n case \"properties\":\n return StateOfUseBrick.USE_BRICK_PROPERTIES;\n case \"transform\":\n return StateOfUseBrick.USE_BRICK_TRANSFORM;\n case \"dataSource\":\n return StateOfUseBrick.USE_BRICK_DATA_SOURCE;\n case \"events\":\n return StateOfUseBrick.USE_BRICK_EVENTS;\n case \"slots\":\n return StateOfUseBrick.USE_BRICK_SLOTS;\n case \"children\":\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS;\n case \"if\":\n return StateOfUseBrick.USE_BRICK_IF;\n case \"lifeCycle\":\n return StateOfUseBrick.USE_BRICK_LIFECYCLE;\n }\n break;\n }\n case StateOfUseBrick.USE_BRICK_SLOTS:\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM;\n case StateOfUseBrick.USE_BRICK_SLOTS_ITEM:\n if (key === \"b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OAAO;QAC1B,IAAIL,GAAG,KAAK,UAAU,EAAE;UACtB,OAAOX,eAAe,CAACY,SAAS;QAClC;QACA;MACF,KAAKZ,eAAe,CAACY,SAAS;MAC9B,KAAKZ,eAAe,CAACa,cAAc;MACnC,KAAKb,eAAe,CAACe,gCAAgC;QAAE;UACrD,QAAQJ,GAAG;YACT,KAAK,YAAY;cACf,OAAOX,eAAe,CAACG,oBAAoB;YAC7C,KAAK,WAAW;cACd,OAAOH,eAAe,CAACI,mBAAmB;YAC5C,KAAK,YAAY;cACf,OAAOJ,eAAe,CAACQ,qBAAqB;YAC9C,KAAK,QAAQ;cACX,OAAOR,eAAe,CAACK,gBAAgB;YACzC,KAAK,OAAO;cACV,OAAOL,eAAe,CAACiB,eAAe;YACxC,KAAK,UAAU;cACb,OAAOjB,eAAe,CAACc,2BAA2B;YACpD,KAAK,IAAI;cACP,OAAOd,eAAe,CAACM,YAAY;YACrC,KAAK,WAAW;cACd,OAAON,eAAe,CAACO,mBAAmB;UAAC;UAE/C;QACF;MACA,KAAKP,eAAe,CAACiB,eAAe;QAClC,OAAOjB,eAAe,CAACkB,oBAAoB;MAC7C,KAAKlB,eAAe,CAACkB,oBAAoB;QACvC,IAAIP,GAAG,KAAK,QAAQ,EAAE;UACpB,OAAOX,eAAe,CAACc,2BAA2B;QACpD;QACA;IAAM;EAEZ;EACA,OAAOd,eAAe,CAACgB,OAAO;AAChC"}
1
+ {"version":3,"file":"getNextStateOfUseBrick.js","names":["StateOfUseBrick","isLazyContentInUseBrick","state","USE_BRICK_PROPERTIES","USE_BRICK_TRANSFORM","USE_BRICK_EVENTS","USE_BRICK_IF","USE_BRICK_LIFECYCLE","USE_BRICK_DATA_SOURCE","getNextStateOfUseBrick","isArray","key","USE_BRICK","USE_BRICK_ITEM","USE_BRICK_SLOTS_ITEM_BRICKS","USE_BRICK_SLOTS_ITEM_BRICKS_ITEM","INITIAL","USE_BRICK_SLOTS","USE_BRICK_SLOTS_ITEM"],"sources":["../../../../src/internal/compute/getNextStateOfUseBrick.ts"],"sourcesContent":["export enum StateOfUseBrick {\n INITIAL,\n USE_BRICK,\n USE_BRICK_ITEM,\n USE_BRICK_PROPERTIES,\n // Compatible mode\n USE_BRICK_TRANSFORM,\n USE_BRICK_EVENTS,\n USE_BRICK_IF,\n USE_BRICK_SLOTS,\n USE_BRICK_SLOTS_ITEM,\n USE_BRICK_SLOTS_ITEM_BRICKS,\n USE_BRICK_SLOTS_ITEM_BRICKS_ITEM,\n USE_BRICK_LIFECYCLE,\n USE_BRICK_DATA_SOURCE,\n}\n\nexport function isLazyContentInUseBrick(\n state: StateOfUseBrick | undefined\n): boolean {\n switch (state) {\n case StateOfUseBrick.USE_BRICK_PROPERTIES:\n case StateOfUseBrick.USE_BRICK_TRANSFORM:\n case StateOfUseBrick.USE_BRICK_EVENTS:\n case StateOfUseBrick.USE_BRICK_IF:\n case StateOfUseBrick.USE_BRICK_LIFECYCLE:\n case StateOfUseBrick.USE_BRICK_DATA_SOURCE:\n return true;\n }\n return false;\n}\n\nexport function getNextStateOfUseBrick(\n state: StateOfUseBrick | undefined,\n isArray?: boolean,\n key?: string\n): StateOfUseBrick | undefined {\n if (isLazyContentInUseBrick(state)) {\n return state;\n }\n if (isArray) {\n switch (state) {\n case StateOfUseBrick.USE_BRICK:\n return StateOfUseBrick.USE_BRICK_ITEM;\n case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS:\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM;\n }\n } else {\n switch (state) {\n case StateOfUseBrick.INITIAL:\n if (key === \"useBrick\") {\n return StateOfUseBrick.USE_BRICK;\n }\n break;\n case StateOfUseBrick.USE_BRICK:\n case StateOfUseBrick.USE_BRICK_ITEM:\n case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM: {\n switch (key) {\n case \"properties\":\n return StateOfUseBrick.USE_BRICK_PROPERTIES;\n case \"transform\":\n return StateOfUseBrick.USE_BRICK_TRANSFORM;\n case \"dataSource\":\n return StateOfUseBrick.USE_BRICK_DATA_SOURCE;\n case \"events\":\n return StateOfUseBrick.USE_BRICK_EVENTS;\n case \"slots\":\n return StateOfUseBrick.USE_BRICK_SLOTS;\n case \"children\":\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS;\n case \"if\":\n return StateOfUseBrick.USE_BRICK_IF;\n case \"lifeCycle\":\n return StateOfUseBrick.USE_BRICK_LIFECYCLE;\n }\n break;\n }\n case StateOfUseBrick.USE_BRICK_SLOTS:\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM;\n case StateOfUseBrick.USE_BRICK_SLOTS_ITEM:\n if (key === \"bricks\") {\n return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS;\n }\n break;\n }\n }\n return StateOfUseBrick.INITIAL;\n}\n"],"mappings":"AAAA,WAAYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AAiB3B,OAAO,SAASC,uBAAuBA,CACrCC,KAAkC,EACzB;EACT,QAAQA,KAAK;IACX,KAAKF,eAAe,CAACG,oBAAoB;IACzC,KAAKH,eAAe,CAACI,mBAAmB;IACxC,KAAKJ,eAAe,CAACK,gBAAgB;IACrC,KAAKL,eAAe,CAACM,YAAY;IACjC,KAAKN,eAAe,CAACO,mBAAmB;IACxC,KAAKP,eAAe,CAACQ,qBAAqB;MACxC,OAAO,IAAI;EAAC;EAEhB,OAAO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M;EAEZ;EACA,OAAOd,eAAe,CAACgB,OAAO;AAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"listenOnTrackingContext.js","names":["setProperties","getTplStateStore","listenOnTrackingContext","brick","trackingContextList","_loop","track","listener","element","propName","propValue","runtimeContext","contextNames","contextName","ctxStore","onChange","stateNames","tplStateStore","concat","stateName"],"sources":["../../../../src/internal/compute/listenOnTrackingContext.ts"],"sourcesContent":["import { setProperties } from \"./setProperties.js\";\nimport type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"../CustomTemplates/utils.js\";\n\nexport interface TrackingContextItem {\n contextNames: string[] | Set<string> | false;\n stateNames: string[] | Set<string> | false;\n formStateNames: string[] | Set<string> | false;\n propName: string;\n propValue: unknown;\n}\n\nexport function listenOnTrackingContext(\n brick: RuntimeBrick,\n trackingContextList: TrackingContextItem[]\n): void {\n for (const track of trackingContextList) {\n const listener = (): void => {\n if (brick.element) {\n setProperties(\n brick.element,\n { [track.propName]: track.propValue },\n brick.runtimeContext\n );\n }\n };\n if (track.contextNames) {\n for (const contextName of track.contextNames) {\n brick.runtimeContext.ctxStore.onChange(contextName, listener);\n }\n }\n if (track.stateNames) {\n const tplStateStore = getTplStateStore(\n brick.runtimeContext,\n \"STATE\",\n `: \"${track.propValue}\"`\n );\n for (const stateName of track.stateNames) {\n tplStateStore.onChange(stateName, listener);\n }\n }\n // if (track.formStateNames) {\n // const formContext = getCustomFormContext(context.formContextId);\n // for (const stateName of track.formStateNames) {\n // const ctx = formContext.formState.get().get(stateName);\n // (\n // ctx as StoryboardContextItemFreeVariable\n // )?.eventTarget?.addEventListener(\"formstate.change\", listener);\n // }\n // }\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,oBAAoB;AAElD,SAASC,gBAAgB,QAAQ,6BAA6B;AAU9D,OAAO,SAASC,uBAAuBA,CACrCC,KAAmB,EACnBC,mBAA0C,EACpC;EAAA,IAAAC,KAAA,YAAAA,CACKC,KAAK;IACd,IAAMC,QAAQ,GAAGA,CAAA,KAAY;MAC3B,IAAIJ,KAAK,CAACK,OAAO,EAAE;QACjBR,aAAa,CACXG,KAAK,CAACK,OAAO,EACb;UAAE,CAACF,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI;QAAU,CAAC,EACrCP,KAAK,CAACQ,cAAc,CACrB;MACH;IACF,CAAC;IACD,IAAIL,KAAK,CAACM,YAAY,EAAE;MACtB,KAAK,IAAMC,WAAW,IAAIP,KAAK,CAACM,YAAY,EAAE;QAC5CT,KAAK,CAACQ,cAAc,CAACG,QAAQ,CAACC,QAAQ,CAACF,WAAW,EAAEN,QAAQ,CAAC;MAC/D;IACF;IACA,IAAID,KAAK,CAACU,UAAU,EAAE;MACpB,IAAMC,aAAa,GAAGhB,gBAAgB,CACpCE,KAAK,CAACQ,cAAc,EACpB,OAAO,SAAAO,MAAA,CACDZ,KAAK,CAACI,SAAS,QACtB;MACD,KAAK,IAAMS,SAAS,IAAIb,KAAK,CAACU,UAAU,EAAE;QACxCC,aAAa,CAACF,QAAQ,CAACI,SAAS,EAAEZ,QAAQ,CAAC;MAC7C;IACF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;EAAA;EAjCF,KAAK,IAAMD,KAAK,IAAIF,mBAAmB,EAAE;IAAAC,KAAA,CAA9BC,KAAK;EAkChB;AACF"}
1
+ {"version":3,"file":"listenOnTrackingContext.js","names":["setProperties","getTplStateStore","listenOnTrackingContext","brick","trackingContextList","_loop","track","listener","element","propName","propValue","runtimeContext","contextNames","contextName","ctxStore","onChange","stateNames","tplStateStore","concat","stateName"],"sources":["../../../../src/internal/compute/listenOnTrackingContext.ts"],"sourcesContent":["import { setProperties } from \"./setProperties.js\";\nimport type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"../CustomTemplates/utils.js\";\n\nexport interface TrackingContextItem {\n contextNames: string[] | Set<string> | false;\n stateNames: string[] | Set<string> | false;\n formStateNames: string[] | Set<string> | false;\n propName: string;\n propValue: unknown;\n}\n\nexport function listenOnTrackingContext(\n brick: RuntimeBrick,\n trackingContextList: TrackingContextItem[]\n): void {\n for (const track of trackingContextList) {\n const listener = (): void => {\n if (brick.element) {\n setProperties(\n brick.element,\n { [track.propName]: track.propValue },\n brick.runtimeContext\n );\n }\n };\n if (track.contextNames) {\n for (const contextName of track.contextNames) {\n brick.runtimeContext.ctxStore.onChange(contextName, listener);\n }\n }\n if (track.stateNames) {\n const tplStateStore = getTplStateStore(\n brick.runtimeContext,\n \"STATE\",\n `: \"${track.propValue}\"`\n );\n for (const stateName of track.stateNames) {\n tplStateStore.onChange(stateName, listener);\n }\n }\n // if (track.formStateNames) {\n // const formContext = getCustomFormContext(context.formContextId);\n // for (const stateName of track.formStateNames) {\n // const ctx = formContext.formState.get().get(stateName);\n // (\n // ctx as StoryboardContextItemFreeVariable\n // )?.eventTarget?.addEventListener(\"formstate.change\", listener);\n // }\n // }\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,oBAAoB;AAElD,SAASC,gBAAgB,QAAQ,6BAA6B;AAU9D,OAAO,SAASC,uBAAuBA,CACrCC,KAAmB,EACnBC,mBAA0C,EACpC;EAAA,IAAAC,KAAA,YAAAA,CAAAC,KAAA,EACmC;IACvC,IAAMC,QAAQ,GAAGA,CAAA,KAAY;MAC3B,IAAIJ,KAAK,CAACK,OAAO,EAAE;QACjBR,aAAa,CACXG,KAAK,CAACK,OAAO,EACb;UAAE,CAACF,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI;QAAU,CAAC,EACrCP,KAAK,CAACQ,cAAc,CACrB;MACH;IACF,CAAC;IACD,IAAIL,KAAK,CAACM,YAAY,EAAE;MACtB,KAAK,IAAMC,WAAW,IAAIP,KAAK,CAACM,YAAY,EAAE;QAC5CT,KAAK,CAACQ,cAAc,CAACG,QAAQ,CAACC,QAAQ,CAACF,WAAW,EAAEN,QAAQ,CAAC;MAC/D;IACF;IACA,IAAID,KAAK,CAACU,UAAU,EAAE;MACpB,IAAMC,aAAa,GAAGhB,gBAAgB,CACpCE,KAAK,CAACQ,cAAc,EACpB,OAAO,SAAAO,MAAA,CACDZ,KAAK,CAACI,SAAS,QACtB;MACD,KAAK,IAAMS,SAAS,IAAIb,KAAK,CAACU,UAAU,EAAE;QACxCC,aAAa,CAACF,QAAQ,CAACI,SAAS,EAAEZ,QAAQ,CAAC;MAC7C;IACF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;EACF,CAAC;EAlCD,KAAK,IAAMD,KAAK,IAAIF,mBAAmB;IAAAC,KAAA,CAAAC,KAAA;EAAA;AAmCzC"}