@next-core/runtime 1.12.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CustomProcessors.js.map +1 -1
- package/dist/cjs/CustomTemplates.js.map +1 -1
- package/dist/cjs/Dialog.js.map +1 -1
- package/dist/cjs/Notification.js.map +1 -1
- package/dist/cjs/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/cjs/auth.js.map +1 -1
- package/dist/cjs/createRoot.js.map +1 -1
- package/dist/cjs/getPageInfo.js.map +1 -1
- package/dist/cjs/handleHttpError.js.map +1 -1
- package/dist/cjs/history.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/constants.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupUseBrickInTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/utils.js.map +1 -1
- package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -1
- package/dist/cjs/internal/FormRenderer/getDefaultProperties.js.map +1 -1
- package/dist/cjs/internal/FormRenderer/utils.js.map +1 -1
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/RendererContext.js.map +1 -1
- package/dist/cjs/internal/Router.js.map +1 -1
- package/dist/cjs/internal/Runtime.js.map +1 -1
- package/dist/cjs/internal/abortController.js.map +1 -1
- package/dist/cjs/internal/bindListeners.js.map +1 -1
- package/dist/cjs/internal/compute/StoryboardFunctions.js.map +1 -1
- package/dist/cjs/internal/compute/WidgetFunctions.js.map +1 -1
- package/dist/cjs/internal/compute/checkIf.js.map +1 -1
- package/dist/cjs/internal/compute/computeRealProperties.js.map +1 -1
- package/dist/cjs/internal/compute/computeRealValue.js.map +1 -1
- package/dist/cjs/internal/compute/evaluate.js.map +1 -1
- package/dist/cjs/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/cjs/internal/compute/getNextStateOfUseBrick.js.map +1 -1
- package/dist/cjs/internal/compute/getTracks.js.map +1 -1
- package/dist/cjs/internal/compute/images.js.map +1 -1
- package/dist/cjs/internal/compute/listenOnTrackingContext.js.map +1 -1
- package/dist/cjs/internal/compute/markAsComputed.js.map +1 -1
- package/dist/cjs/internal/compute/setRealProperties.js.map +1 -1
- package/dist/cjs/internal/data/DataStore.js.map +1 -1
- package/dist/cjs/internal/data/getProviderBrick.js.map +1 -1
- package/dist/cjs/internal/data/resolveData.js.map +1 -1
- package/dist/cjs/internal/data/resolveDataStore.js.map +1 -1
- package/dist/cjs/internal/hasInstalledApp.js.map +1 -1
- package/dist/cjs/internal/historyExtended.js.map +1 -1
- package/dist/cjs/internal/insertPreviewRoutes.js.map +1 -1
- package/dist/cjs/internal/matchPath.js.map +1 -1
- package/dist/cjs/internal/matchRoutes.js.map +1 -1
- package/dist/cjs/internal/matchStoryboard.js.map +1 -1
- package/dist/cjs/internal/mediaQuery.js.map +1 -1
- package/dist/cjs/internal/mount.js.map +1 -1
- package/dist/cjs/internal/poll.js.map +1 -1
- package/dist/cjs/internal/proxyFactories.js.map +1 -1
- package/dist/cjs/internal/secret_internals.js.map +1 -1
- package/dist/cjs/isStrictMode.js.map +1 -1
- package/dist/cjs/themeAndMode.js.map +1 -1
- package/dist/esm/CustomProcessors.js.map +1 -1
- package/dist/esm/CustomTemplates.js.map +1 -1
- package/dist/esm/Dialog.js.map +1 -1
- package/dist/esm/Notification.js.map +1 -1
- package/dist/esm/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/esm/auth.js.map +1 -1
- package/dist/esm/createRoot.js.map +1 -1
- package/dist/esm/getPageInfo.js.map +1 -1
- package/dist/esm/handleHttpError.js.map +1 -1
- package/dist/esm/history.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/constants.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/setupUseBrickInTemplate.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/utils.js.map +1 -1
- package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -1
- package/dist/esm/internal/FormRenderer/getDefaultProperties.js.map +1 -1
- package/dist/esm/internal/FormRenderer/utils.js.map +1 -1
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/RendererContext.js.map +1 -1
- package/dist/esm/internal/Router.js.map +1 -1
- package/dist/esm/internal/Runtime.js.map +1 -1
- package/dist/esm/internal/abortController.js.map +1 -1
- package/dist/esm/internal/bindListeners.js.map +1 -1
- package/dist/esm/internal/compute/StoryboardFunctions.js.map +1 -1
- package/dist/esm/internal/compute/WidgetFunctions.js.map +1 -1
- package/dist/esm/internal/compute/checkIf.js.map +1 -1
- package/dist/esm/internal/compute/computeRealProperties.js.map +1 -1
- package/dist/esm/internal/compute/computeRealValue.js.map +1 -1
- package/dist/esm/internal/compute/evaluate.js.map +1 -1
- package/dist/esm/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/esm/internal/compute/getNextStateOfUseBrick.js.map +1 -1
- package/dist/esm/internal/compute/getTracks.js.map +1 -1
- package/dist/esm/internal/compute/images.js.map +1 -1
- package/dist/esm/internal/compute/listenOnTrackingContext.js.map +1 -1
- package/dist/esm/internal/compute/markAsComputed.js.map +1 -1
- package/dist/esm/internal/compute/setRealProperties.js.map +1 -1
- package/dist/esm/internal/data/DataStore.js.map +1 -1
- package/dist/esm/internal/data/getProviderBrick.js.map +1 -1
- package/dist/esm/internal/data/resolveData.js.map +1 -1
- package/dist/esm/internal/data/resolveDataStore.js.map +1 -1
- package/dist/esm/internal/hasInstalledApp.js.map +1 -1
- package/dist/esm/internal/historyExtended.js.map +1 -1
- package/dist/esm/internal/insertPreviewRoutes.js.map +1 -1
- package/dist/esm/internal/matchPath.js.map +1 -1
- package/dist/esm/internal/matchRoutes.js.map +1 -1
- package/dist/esm/internal/matchStoryboard.js.map +1 -1
- package/dist/esm/internal/mediaQuery.js.map +1 -1
- package/dist/esm/internal/mount.js.map +1 -1
- package/dist/esm/internal/poll.js.map +1 -1
- package/dist/esm/internal/proxyFactories.js.map +1 -1
- package/dist/esm/internal/secret_internals.js.map +1 -1
- package/dist/esm/isStrictMode.js.map +1 -1
- package/dist/esm/themeAndMode.js.map +1 -1
- package/dist/types/tsdoc-metadata.json +1 -1
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomProcessors.js","names":["CustomProcessorRegistry","registry","Map","define","processorFullName","processorFunc","namespace","processorName","split","pkg","get","set","has","Error","customProcessors","exports"],"sources":["../../src/CustomProcessors.ts"],"sourcesContent":["class CustomProcessorRegistry {\n readonly #registry = new Map<string, Map<string, Function>>();\n\n define(processorFullName: string, processorFunc: Function) {\n // `namespace` should be the camelCase of the package name.\n const [namespace, processorName] = processorFullName.split(\".\");\n let pkg = this.#registry.get(namespace);\n if (!pkg) {\n pkg = new Map();\n this.#registry.set(namespace, pkg);\n }\n if (pkg.has(processorName)) {\n // eslint-disable-next-line no-console\n throw new Error(\n `Custom processor of \"${processorFullName}\" already registered`\n );\n }\n pkg.set(processorName, processorFunc);\n }\n\n get(namespace: string) {\n return this.#registry.get(namespace);\n }\n}\n\nexport const customProcessors = new CustomProcessorRegistry();\n"],"mappings":";;;;;;AAAA,MAAMA,uBAAuB,CAAC;EACnB,CAACC,QAAQ,GAAG,IAAIC,GAAG,
|
|
1
|
+
{"version":3,"file":"CustomProcessors.js","names":["CustomProcessorRegistry","registry","Map","define","processorFullName","processorFunc","namespace","processorName","split","pkg","get","set","has","Error","customProcessors","exports"],"sources":["../../src/CustomProcessors.ts"],"sourcesContent":["class CustomProcessorRegistry {\n readonly #registry = new Map<string, Map<string, Function>>();\n\n define(processorFullName: string, processorFunc: Function) {\n // `namespace` should be the camelCase of the package name.\n const [namespace, processorName] = processorFullName.split(\".\");\n let pkg = this.#registry.get(namespace);\n if (!pkg) {\n pkg = new Map();\n this.#registry.set(namespace, pkg);\n }\n if (pkg.has(processorName)) {\n // eslint-disable-next-line no-console\n throw new Error(\n `Custom processor of \"${processorFullName}\" already registered`\n );\n }\n pkg.set(processorName, processorFunc);\n }\n\n get(namespace: string) {\n return this.#registry.get(namespace);\n }\n}\n\nexport const customProcessors = new CustomProcessorRegistry();\n"],"mappings":";;;;;;AAAA,MAAMA,uBAAuB,CAAC;EACnB,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAgC,CAAC;EAE7DC,MAAMA,CAACC,iBAAyB,EAAEC,aAAuB,EAAE;IACzD;IACA,MAAM,CAACC,SAAS,EAAEC,aAAa,CAAC,GAAGH,iBAAiB,CAACI,KAAK,CAAC,GAAG,CAAC;IAC/D,IAAIC,GAAG,GAAG,IAAI,CAAC,CAACR,QAAQ,CAACS,GAAG,CAACJ,SAAS,CAAC;IACvC,IAAI,CAACG,GAAG,EAAE;MACRA,GAAG,GAAG,IAAIP,GAAG,CAAC,CAAC;MACf,IAAI,CAAC,CAACD,QAAQ,CAACU,GAAG,CAACL,SAAS,EAAEG,GAAG,CAAC;IACpC;IACA,IAAIA,GAAG,CAACG,GAAG,CAACL,aAAa,CAAC,EAAE;MAC1B;MACA,MAAM,IAAIM,KAAK,CACZ,wBAAuBT,iBAAkB,sBAC5C,CAAC;IACH;IACAK,GAAG,CAACE,GAAG,CAACJ,aAAa,EAAEF,aAAa,CAAC;EACvC;EAEAK,GAAGA,CAACJ,SAAiB,EAAE;IACrB,OAAO,IAAI,CAAC,CAACL,QAAQ,CAACS,GAAG,CAACJ,SAAS,CAAC;EACtC;AACF;AAEO,MAAMQ,gBAAgB,GAAG,IAAId,uBAAuB,CAAC,CAAC;AAACe,OAAA,CAAAD,gBAAA,GAAAA,gBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomTemplates.js","names":["_lodash","require","_isStrictMode","allowedNativeProps","Set","CustomTemplateRegistry","registry","Map","define","tagName","constructor","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","has","console","warn","customElements","get","strict","isStrictMode","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","value","Object","entries","asVariable","warnAboutStrictMode","push","mergeProperty","refTransform","error","ref","compatibleConstructor","fromEntries","state","map","item","expose","concat","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","_this$$$tplStateStore2","_this$$$tplStateStore3","_this$$$tplStateStore4","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","propName","some","defineProperty","getValue","_this$$$tplStateStore5","updateValue","enumerable","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","args","_to$refMethod","refMethod","customTemplates","exports","_state$filter$map","uniq"],"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,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA;AACA,MAAME,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAQ9C,MAAMC,sBAAsB,CAAC;EAClB,CAACC,QAAQ,GAAG,IAAIC,GAAG,EAA0B;EAEtDC,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAQ;IAAA,IAAAC,qBAAA,EAAAC,kBAAA,EAAAC,qBAAA,EAAAC,sBAAA;IACpE,IAAIC,UAAU,GAAG,IAAI,CAAC,CAACT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AA,cAAAA,aAAA,GAAIR,IAAI,CAAC,CAAC,GAAGO,IAAI,CAAC;QACxC,CAAC;QACDR,UAAU,EAAE;MACd,CAAC,CAAC;IACJ;IAEA9E,cAAc,CAACX,MAAM,CAACC,OAAO,EAAEuD,UAAU,CAAC;EAC5C;EAEA5C,GAAGA,CAACX,OAAe,EAAE;IACnB,OAAO,IAAI,CAAC,CAACH,QAAQ,CAACc,GAAG,CAACX,OAAO,CAAC;EACpC;AACF;AAEO,MAAMmG,eAAe,GAAG,IAAIvG,sBAAsB,EAAE;AAACwG,OAAA,CAAAD,eAAA,GAAAA,eAAA;AAE5D,SAAS1D,gBAAgBA,CAACT,KAAgC,EAAY;EAAA,IAAAqE,iBAAA;EACpE;EACA,OAAO,IAAAC,YAAI,GAAAD,iBAAA,GACTrE,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEe,MAAM,CAAEb,IAAI,IAAKA,IAAI,CAACC,MAAM,CAAC,CAACF,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACI,IAAI,CAAC,cAAA+D,iBAAA,cAAAA,iBAAA,GAAI,EAAE,CACpE;AACH"}
|
|
1
|
+
{"version":3,"file":"CustomTemplates.js","names":["_lodash","require","_isStrictMode","allowedNativeProps","Set","CustomTemplateRegistry","registry","Map","define","tagName","constructor","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","has","console","warn","customElements","get","strict","isStrictMode","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","value","Object","entries","asVariable","warnAboutStrictMode","push","mergeProperty","refTransform","error","ref","compatibleConstructor","fromEntries","state","map","item","expose","concat","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","_this$$$tplStateStore2","_this$$$tplStateStore3","_this$$$tplStateStore4","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","propName","some","defineProperty","getValue","_this$$$tplStateStore5","updateValue","enumerable","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","args","_to$refMethod","refMethod","customTemplates","exports","_state$filter$map","uniq"],"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,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA;AACA,MAAME,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAQ9C,MAAMC,sBAAsB,CAAC;EAClB,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAEtDC,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAQ;IAAA,IAAAC,qBAAA,EAAAC,kBAAA,EAAAC,qBAAA,EAAAC,sBAAA;IACpE,IAAIC,UAAU,GAAG,IAAI,CAAC,CAACT,QAAQ,CAACU,GAAG,CAACP,OAAO,CAAC;IAC5C,IAAIM,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAE,OAAO,CAACC,IAAI,CAAE,uBAAsBT,OAAQ,uBAAsB,CAAC;IACrE,CAAC,MAAM;MACLM,UAAU,GAAG,CAAC,CAACI,cAAc,CAACC,GAAG,CAACX,OAAO,CAAC;MAC1C,IAAIM,UAAU,EAAE;QACd;QACAE,OAAO,CAACC,IAAI,CACT,uBAAsBT,OAAQ,sCACjC,CAAC;MACH;IACF;;IAEA;IACA,MAAMY,MAAM,GAAG,IAAAC,0BAAY,EAAC,CAAC;IAC7B,MAAMC,eAAe,IAAAZ,qBAAA,IAAAC,kBAAA,GAAIF,WAAW,CAACc,KAAK,cAAAZ,kBAAA,uBAAjBA,kBAAA,CAAmBa,UAAU,cAAAd,qBAAA,cAAAA,qBAAA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AK,CAAEe,MAAM,CAAEb,IAAI,IAAKA,IAAI,CAACC,MAAM,CAAC,CAACF,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACI,IAAI,CAAC,cAAA+D,iBAAA,cAAAA,iBAAA,GAAI,EACnE,CAAC;AACH"}
|
package/dist/cjs/Dialog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","names":["brick","show","options","resolve","type","confirm","content","Promise","setTimeout","reject","alert","loadDialogService","tagName","loader","then","document","createElement","error","console","Dialog","Object","freeze","exports"],"sources":["../../src/Dialog.ts"],"sourcesContent":["let brick: {\n resolve(options: DialogOptions): Promise<void>;\n};\n\nfunction show(options: DialogOptions): Promise<void> {\n if (brick) {\n return brick.resolve(options);\n } else {\n if (options.type === \"confirm\") {\n if (confirm(options.content)) {\n return new Promise((resolve) =>\n setTimeout(() => {\n resolve();\n }, 1)\n );\n } else {\n return new Promise((resolve, reject) =>\n setTimeout(() => {\n reject();\n }, 1)\n );\n }\n } else {\n alert(options.content);\n return new Promise((resolve) =>\n setTimeout(() => {\n resolve();\n }, 1000)\n );\n }\n }\n}\n\nexport function loadDialogService(\n tagName: string,\n loader: (bricks: string[]) => Promise<void>\n) {\n loader([tagName]).then(\n () => {\n brick = document.createElement(tagName) as any;\n },\n (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Load dialog service failed:\", error);\n }\n );\n}\n\nexport interface DialogOptions {\n type?: \"success\" | \"error\" | \"warn\" | \"info\" | \"confirm\";\n title?: string | null;\n content: string;\n contentStyle?: object;\n}\n\nexport const Dialog = Object.freeze({\n show,\n});\n"],"mappings":";;;;;;;AAAA,IAAIA,KAEH;AAED,SAASC,IAAIA,CAACC,OAAsB,EAAiB;EACnD,IAAIF,KAAK,EAAE;IACT,OAAOA,KAAK,CAACG,OAAO,CAACD,OAAO,CAAC;EAC/B,CAAC,MAAM;IACL,IAAIA,OAAO,CAACE,IAAI,KAAK,SAAS,EAAE;MAC9B,IAAIC,OAAO,CAACH,OAAO,CAACI,OAAO,CAAC,EAAE;QAC5B,OAAO,IAAIC,OAAO,CAAEJ,OAAO,IACzBK,UAAU,CAAC,MAAM;UACfL,OAAO,
|
|
1
|
+
{"version":3,"file":"Dialog.js","names":["brick","show","options","resolve","type","confirm","content","Promise","setTimeout","reject","alert","loadDialogService","tagName","loader","then","document","createElement","error","console","Dialog","Object","freeze","exports"],"sources":["../../src/Dialog.ts"],"sourcesContent":["let brick: {\n resolve(options: DialogOptions): Promise<void>;\n};\n\nfunction show(options: DialogOptions): Promise<void> {\n if (brick) {\n return brick.resolve(options);\n } else {\n if (options.type === \"confirm\") {\n if (confirm(options.content)) {\n return new Promise((resolve) =>\n setTimeout(() => {\n resolve();\n }, 1)\n );\n } else {\n return new Promise((resolve, reject) =>\n setTimeout(() => {\n reject();\n }, 1)\n );\n }\n } else {\n alert(options.content);\n return new Promise((resolve) =>\n setTimeout(() => {\n resolve();\n }, 1000)\n );\n }\n }\n}\n\nexport function loadDialogService(\n tagName: string,\n loader: (bricks: string[]) => Promise<void>\n) {\n loader([tagName]).then(\n () => {\n brick = document.createElement(tagName) as any;\n },\n (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Load dialog service failed:\", error);\n }\n );\n}\n\nexport interface DialogOptions {\n type?: \"success\" | \"error\" | \"warn\" | \"info\" | \"confirm\";\n title?: string | null;\n content: string;\n contentStyle?: object;\n}\n\nexport const Dialog = Object.freeze({\n show,\n});\n"],"mappings":";;;;;;;AAAA,IAAIA,KAEH;AAED,SAASC,IAAIA,CAACC,OAAsB,EAAiB;EACnD,IAAIF,KAAK,EAAE;IACT,OAAOA,KAAK,CAACG,OAAO,CAACD,OAAO,CAAC;EAC/B,CAAC,MAAM;IACL,IAAIA,OAAO,CAACE,IAAI,KAAK,SAAS,EAAE;MAC9B,IAAIC,OAAO,CAACH,OAAO,CAACI,OAAO,CAAC,EAAE;QAC5B,OAAO,IAAIC,OAAO,CAAEJ,OAAO,IACzBK,UAAU,CAAC,MAAM;UACfL,OAAO,CAAC,CAAC;QACX,CAAC,EAAE,CAAC,CACN,CAAC;MACH,CAAC,MAAM;QACL,OAAO,IAAII,OAAO,CAAC,CAACJ,OAAO,EAAEM,MAAM,KACjCD,UAAU,CAAC,MAAM;UACfC,MAAM,CAAC,CAAC;QACV,CAAC,EAAE,CAAC,CACN,CAAC;MACH;IACF,CAAC,MAAM;MACLC,KAAK,CAACR,OAAO,CAACI,OAAO,CAAC;MACtB,OAAO,IAAIC,OAAO,CAAEJ,OAAO,IACzBK,UAAU,CAAC,MAAM;QACfL,OAAO,CAAC,CAAC;MACX,CAAC,EAAE,IAAI,CACT,CAAC;IACH;EACF;AACF;AAEO,SAASQ,iBAAiBA,CAC/BC,OAAe,EACfC,MAA2C,EAC3C;EACAA,MAAM,CAAC,CAACD,OAAO,CAAC,CAAC,CAACE,IAAI,CACpB,MAAM;IACJd,KAAK,GAAGe,QAAQ,CAACC,aAAa,CAACJ,OAAO,CAAQ;EAChD,CAAC,EACAK,KAAc,IAAK;IAClB;IACAC,OAAO,CAACD,KAAK,CAAC,6BAA6B,EAAEA,KAAK,CAAC;EACrD,CACF,CAAC;AACH;AASO,MAAME,MAAM,GAAGC,MAAM,CAACC,MAAM,CAAC;EAClCpB;AACF,CAAC,CAAC;AAACqB,OAAA,CAAAH,MAAA,GAAAA,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Notification.js","names":["brick","show","options","resolve","alert","message","loadNotificationService","tagName","loader","then","document","createElement","error","console","Notification","Object","freeze","exports"],"sources":["../../src/Notification.ts"],"sourcesContent":["let brick: {\n resolve(options: NotificationOptions): void;\n};\n\nfunction show(options: NotificationOptions) {\n if (brick) {\n brick.resolve(options);\n } else {\n alert(options.message);\n }\n}\n\nexport function loadNotificationService(\n tagName: string,\n loader: (bricks: string[]) => Promise<void>\n) {\n loader([tagName]).then(\n () => {\n brick = document.createElement(tagName) as any;\n },\n (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Load notification service failed:\", error);\n }\n );\n}\n\nexport interface NotificationOptions {\n type?: \"success\" | \"error\" | \"warn\" | \"info\";\n message: string;\n}\n\nexport const Notification = Object.freeze({\n show,\n});\n"],"mappings":";;;;;;;AAAA,IAAIA,KAEH;AAED,SAASC,IAAIA,CAACC,OAA4B,EAAE;EAC1C,IAAIF,KAAK,EAAE;IACTA,KAAK,CAACG,OAAO,CAACD,OAAO,CAAC;EACxB,CAAC,MAAM;IACLE,KAAK,CAACF,OAAO,CAACG,OAAO,CAAC;EACxB;AACF;AAEO,SAASC,uBAAuBA,CACrCC,OAAe,EACfC,MAA2C,EAC3C;EACAA,MAAM,CAAC,CAACD,OAAO,CAAC,CAAC,CAACE,IAAI,CACpB,MAAM;IACJT,KAAK,GAAGU,QAAQ,CAACC,aAAa,CAACJ,OAAO,CAAQ;EAChD,CAAC,EACAK,KAAc,IAAK;IAClB;IACAC,OAAO,CAACD,KAAK,CAAC,mCAAmC,EAAEA,KAAK,CAAC;EAC3D,CAAC
|
|
1
|
+
{"version":3,"file":"Notification.js","names":["brick","show","options","resolve","alert","message","loadNotificationService","tagName","loader","then","document","createElement","error","console","Notification","Object","freeze","exports"],"sources":["../../src/Notification.ts"],"sourcesContent":["let brick: {\n resolve(options: NotificationOptions): void;\n};\n\nfunction show(options: NotificationOptions) {\n if (brick) {\n brick.resolve(options);\n } else {\n alert(options.message);\n }\n}\n\nexport function loadNotificationService(\n tagName: string,\n loader: (bricks: string[]) => Promise<void>\n) {\n loader([tagName]).then(\n () => {\n brick = document.createElement(tagName) as any;\n },\n (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Load notification service failed:\", error);\n }\n );\n}\n\nexport interface NotificationOptions {\n type?: \"success\" | \"error\" | \"warn\" | \"info\";\n message: string;\n}\n\nexport const Notification = Object.freeze({\n show,\n});\n"],"mappings":";;;;;;;AAAA,IAAIA,KAEH;AAED,SAASC,IAAIA,CAACC,OAA4B,EAAE;EAC1C,IAAIF,KAAK,EAAE;IACTA,KAAK,CAACG,OAAO,CAACD,OAAO,CAAC;EACxB,CAAC,MAAM;IACLE,KAAK,CAACF,OAAO,CAACG,OAAO,CAAC;EACxB;AACF;AAEO,SAASC,uBAAuBA,CACrCC,OAAe,EACfC,MAA2C,EAC3C;EACAA,MAAM,CAAC,CAACD,OAAO,CAAC,CAAC,CAACE,IAAI,CACpB,MAAM;IACJT,KAAK,GAAGU,QAAQ,CAACC,aAAa,CAACJ,OAAO,CAAQ;EAChD,CAAC,EACAK,KAAc,IAAK;IAClB;IACAC,OAAO,CAACD,KAAK,CAAC,mCAAmC,EAAEA,KAAK,CAAC;EAC3D,CACF,CAAC;AACH;AAOO,MAAME,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC;EACxCf;AACF,CAAC,CAAC;AAACgB,OAAA,CAAAH,YAAA,GAAAA,YAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoryboardFunctionRegistry.js","names":["_cook","require","_supply","_storyboard","_getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","registeredFunctions","Map","storyboardFunctions","Proxy","Object","freeze","get","target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","strictCollectMemberUsageInFunction","hasPermissionsCheck","has","set","name","source","typescript","undefined","processed","cooked","collector","createCollector","precooked","precookFunction","hooks","beforeVisit","cook","function","rules","noVar","globalVariables","supply","attemptToVisitGlobals","getGeneralGlobals","isStoryboardFunction","beforeEvaluate","beforeCall","beforeBranch","updateStoryboardFunction","data","newFn","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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AAEA;;AAGA;;AAMA;;AAiBA;;AAUA;;AAQA;;AAKA;;AAGA;AACO,SAASI,iCAAiCA,CAAC;EAChDC,QAAQ;EACRC,aAAa;EACbC;AAKF,CAAC,GAAG,CAAC,CAAC,EAA8B;EAClC,MAAMC,mBAAmB,GAAG,IAAIC,GAAG,
|
|
1
|
+
{"version":3,"file":"StoryboardFunctionRegistry.js","names":["_cook","require","_supply","_storyboard","_getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","registeredFunctions","Map","storyboardFunctions","Proxy","Object","freeze","get","target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","strictCollectMemberUsageInFunction","hasPermissionsCheck","has","set","name","source","typescript","undefined","processed","cooked","collector","createCollector","precooked","precookFunction","hooks","beforeVisit","cook","function","rules","noVar","globalVariables","supply","attemptToVisitGlobals","getGeneralGlobals","isStoryboardFunction","beforeEvaluate","beforeCall","beforeBranch","updateStoryboardFunction","data","newFn","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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AAEA;;AAGA;;AAMA;;AAiBA;;AAUA;;AAQA;;AAKA;;AAGA;AACO,SAASI,iCAAiCA,CAAC;EAChDC,QAAQ;EACRC,aAAa;EACbC;AAKF,CAAC,GAAG,CAAC,CAAC,EAA8B;EAClC,MAAMC,mBAAmB,GAAG,IAAIC,GAAG,CAAoC,CAAC;;EAExE;EACA,MAAMC,mBAAmB,GAAG,IAAIC,KAAK,CAACC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;IACvDC,GAAGA,CAACC,MAAM,EAAEC,GAAG,EAAE;MACf,OAAOC,qBAAqB,CAACD,GAAa,CAAC;IAC7C;EACF,CAAC,CAAgC;EAEjC,IAAIE,UAAuC;EAE3C,SAASC,2BAA2BA,CAClCC,SAA+B,EAC/BC,GAAqB,EACf;IACN,IAAIA,GAAG,EAAE;MACPH,UAAU,GAAGG,GAAG;IAClB;IACAb,mBAAmB,CAACc,KAAK,CAAC,CAAC;IAC3B,IAAIC,KAAK,CAACC,OAAO,CAACJ,SAAS,CAAC,EAAE;MAC5B,KAAK,MAAMK,EAAE,IAAIL,SAAS,EAAE;QAC1B,MAAMM,IAAI,GAAG,IAAAC,8CAAkC,EAACF,EAAE,EAAE,IAAI,CAAC;QACzD,MAAMG,mBAAmB,GAAG,IAAAD,8CAAkC,EAC5DF,E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AO,KAAK;MACd,CAAC;MACD,OAAO+B,aAAa,CAACI,IAAI,CAACnC,mBAAmB,CAAC;IAChD;EACF,CAAC;AACH"}
|
package/dist/cjs/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","names":["_Runtime","require","authenticate","args","_hooks$auth","_hooks$auth$authentic","hooks","auth","call","getAuth","_hooks$auth2","logout","_hooks$auth3","_hooks$auth3$logout","isLoggedIn","_hooks$auth4"],"sources":["../../src/auth.ts"],"sourcesContent":["// istanbul ignore file\n// Todo(steve): This file will be removed in the future.\nimport { hooks } from \"./internal/Runtime.js\";\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function authenticate(...args: unknown[]): void {\n hooks?.auth?.authenticate?.(...args);\n}\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function getAuth() {\n return hooks?.auth?.getAuth();\n}\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function logout() {\n return hooks?.auth?.logout?.();\n}\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function isLoggedIn() {\n return hooks?.auth?.isLoggedIn();\n}\n"],"mappings":";;;;;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAFA;AACA;;AAGA;AACO,SAASC,YAAYA,CAAC,GAAGC,IAAe,EAAQ;EAAA,IAAAC,WAAA,EAAAC,qBAAA;EACrDC,cAAK,aAALA,cAAK,wBAAAF,WAAA,GAALE,cAAK,CAAEC,IAAI,cAAAH,WAAA,wBAAAC,qBAAA,GAAXD,WAAA,CAAaF,YAAY,cAAAG,qBAAA,uBAAzBA,qBAAA,CAAAG,IAAA,CAAAJ,WAAA,EAA4B,GAAGD,IAAI,CAAC;AACtC;;AAEA;AACO,SAASM,OAAOA,CAAA,EAAG;EAAA,IAAAC,YAAA;EACxB,OAAOJ,cAAK,aAALA,cAAK,wBAAAI,YAAA,GAALJ,cAAK,CAAEC,IAAI,cAAAG,YAAA,uBAAXA,YAAA,CAAaD,OAAO,
|
|
1
|
+
{"version":3,"file":"auth.js","names":["_Runtime","require","authenticate","args","_hooks$auth","_hooks$auth$authentic","hooks","auth","call","getAuth","_hooks$auth2","logout","_hooks$auth3","_hooks$auth3$logout","isLoggedIn","_hooks$auth4"],"sources":["../../src/auth.ts"],"sourcesContent":["// istanbul ignore file\n// Todo(steve): This file will be removed in the future.\nimport { hooks } from \"./internal/Runtime.js\";\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function authenticate(...args: unknown[]): void {\n hooks?.auth?.authenticate?.(...args);\n}\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function getAuth() {\n return hooks?.auth?.getAuth();\n}\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function logout() {\n return hooks?.auth?.logout?.();\n}\n\n/** @deprecated import it from \"@next-core/easyops-runtime\" instead */\nexport function isLoggedIn() {\n return hooks?.auth?.isLoggedIn();\n}\n"],"mappings":";;;;;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAFA;AACA;;AAGA;AACO,SAASC,YAAYA,CAAC,GAAGC,IAAe,EAAQ;EAAA,IAAAC,WAAA,EAAAC,qBAAA;EACrDC,cAAK,aAALA,cAAK,wBAAAF,WAAA,GAALE,cAAK,CAAEC,IAAI,cAAAH,WAAA,wBAAAC,qBAAA,GAAXD,WAAA,CAAaF,YAAY,cAAAG,qBAAA,uBAAzBA,qBAAA,CAAAG,IAAA,CAAAJ,WAAA,EAA4B,GAAGD,IAAI,CAAC;AACtC;;AAEA;AACO,SAASM,OAAOA,CAAA,EAAG;EAAA,IAAAC,YAAA;EACxB,OAAOJ,cAAK,aAALA,cAAK,wBAAAI,YAAA,GAALJ,cAAK,CAAEC,IAAI,cAAAG,YAAA,uBAAXA,YAAA,CAAaD,OAAO,CAAC,CAAC;AAC/B;;AAEA;AACO,SAASE,MAAMA,CAAA,EAAG;EAAA,IAAAC,YAAA,EAAAC,mBAAA;EACvB,OAAOP,cAAK,aAALA,cAAK,wBAAAM,YAAA,GAALN,cAAK,CAAEC,IAAI,cAAAK,YAAA,wBAAAC,mBAAA,GAAXD,YAAA,CAAaD,MAAM,cAAAE,mBAAA,uBAAnBA,mBAAA,CAAAL,IAAA,CAAAI,YAAsB,CAAC;AAChC;;AAEA;AACO,SAASE,UAAUA,CAAA,EAAG;EAAA,IAAAC,YAAA;EAC3B,OAAOT,cAAK,aAALA,cAAK,wBAAAS,YAAA,GAALT,cAAK,CAAEC,IAAI,cAAAQ,YAAA,uBAAXA,YAAA,CAAaD,UAAU,CAAC,CAAC;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoot.js","names":["_loader","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","renderBricks","flushStableLoadBricks","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[\n ...runtimeContext.tplStateStoreMap.values(),\n ...runtimeContext.formStateStoreMap.values(),\n ].map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,oBAAA,GAAAR,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AACA,IAAAU,wBAAA,GAAAV,OAAA;AA2BO,SAASW,mBAAmBA,CACjCC,SAAsB,EACtB;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC,MAAM;IACL;IACAG,YAAY,GAAGA,CAAA,KAAM;MACnBJ,MAAM,GAAGK,QAAQ,CAACC,aAA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AAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAA2E,kBAAW,EAAC3E,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACyF,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"createRoot.js","names":["_loader","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","renderBricks","flushStableLoadBricks","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[\n ...runtimeContext.tplStateStoreMap.values(),\n ...runtimeContext.formStateStoreMap.values(),\n ].map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,oBAAA,GAAAR,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AACA,IAAAU,wBAAA,GAAAV,OAAA;AA2BO,SAASW,mBAAmBA,CACjCC,SAAsB,EACtB;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC,MAAM;IACL;IACAG,YAAY,GAAGA,CAAA,KAAM;MACnBJ,MAAM,GAAGK,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MACtCN,MAAM,CAACO,KAAK,CAACC,QAAQ,GAAG,UAAU;MAClCR,MAAM,CAACO,KAAK,CAACE,KAAK,GAAGT,MAAM,CAACO,KAAK,CAACG,MAAM,GAAG,GAAG;MAC9CL,QAAQ,CAACM,IAAI,CAACC,MAAM,CAACZ,MAAM,CAAC;MAC5B,OAAOA,MA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AC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPageInfo.js","names":["_getBasePath","require","misc","getPageInfo","isInIframe","isInIframeOfSameSite","isInIframeOfNext","isInIframeOfVisualBuilder","isInIframeOfLegacyConsole","window","parent","origin","selfIsNext","getBasePath","parentPathname","location","pathname","parentIsNext","startsWith","Number","e","Object","freeze"],"sources":["../../src/getPageInfo.ts"],"sourcesContent":["import { getBasePath } from \"./getBasePath.js\";\n\nlet misc: PageInfo;\n\n/** 运行时页面信息。*/\nexport interface PageInfo {\n /** 当前是否处于 iframe 模式。 */\n isInIframe: boolean;\n\n /** 当前是否处于同域的 iframe 模式。 */\n isInIframeOfSameSite: boolean;\n\n /** 当前是否处于新框架下的 iframe 模式。 */\n isInIframeOfNext: boolean;\n\n /** 当前是否处于 Visual Builder 预览的 iframe 模式。 */\n isInIframeOfVisualBuilder: boolean;\n\n /** 当前是否处于老 console 下的 iframe 模式。 */\n isInIframeOfLegacyConsole: boolean;\n}\n\nexport function getPageInfo(): PageInfo {\n if (!misc) {\n misc = {\n isInIframe: false,\n isInIframeOfSameSite: false,\n isInIframeOfNext: false,\n isInIframeOfVisualBuilder: false,\n isInIframeOfLegacyConsole: false,\n };\n\n if (window !== window.parent) {\n misc.isInIframe = true;\n try {\n // Handle:\n // - Previewing in visual builder by iframe.\n // - Nesting next in next.\n // - Nesting console in next.\n if (window.origin === window.parent.origin) {\n misc.isInIframeOfSameSite = true;\n const selfIsNext = getBasePath() === \"/next/\";\n const parentPathname = window.parent.location.pathname;\n const parentIsNext = parentPathname.startsWith(\"/next/\");\n misc.isInIframeOfNext =\n (Number(selfIsNext) ^ Number(parentIsNext)) === 0;\n misc.isInIframeOfVisualBuilder = parentPathname.startsWith(\n `${parentIsNext ? \"/next\" : \"\"}/visual-builder/`\n );\n misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;\n }\n } catch (e) {\n // do nothing\n }\n }\n\n Object.freeze(misc);\n }\n\n return misc;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAIC,IAAc;;AAElB;;AAkBO,SAASC,WAAWA,CAAA,EAAa;EACtC,IAAI,CAACD,IAAI,EAAE;IACTA,IAAI,GAAG;MACLE,UAAU,EAAE,KAAK;MACjBC,oBAAoB,EAAE,KAAK;MAC3BC,gBAAgB,EAAE,KAAK;MACvBC,yBAAyB,EAAE,KAAK;MAChCC,yBAAyB,EAAE;IAC7B,CAAC;IAED,IAAIC,MAAM,KAAKA,MAAM,CAACC,MAAM,EAAE;MAC5BR,IAAI,CAACE,UAAU,GAAG,IAAI;MACtB,IAAI;QACF;QACA;QACA;QACA;QACA,IAAIK,MAAM,CAACE,MAAM,KAAKF,MAAM,CAACC,MAAM,CAACC,MAAM,EAAE;UAC1CT,IAAI,CAACG,oBAAoB,GAAG,IAAI;UAChC,MAAMO,UAAU,GAAG,IAAAC,wBAAW,
|
|
1
|
+
{"version":3,"file":"getPageInfo.js","names":["_getBasePath","require","misc","getPageInfo","isInIframe","isInIframeOfSameSite","isInIframeOfNext","isInIframeOfVisualBuilder","isInIframeOfLegacyConsole","window","parent","origin","selfIsNext","getBasePath","parentPathname","location","pathname","parentIsNext","startsWith","Number","e","Object","freeze"],"sources":["../../src/getPageInfo.ts"],"sourcesContent":["import { getBasePath } from \"./getBasePath.js\";\n\nlet misc: PageInfo;\n\n/** 运行时页面信息。*/\nexport interface PageInfo {\n /** 当前是否处于 iframe 模式。 */\n isInIframe: boolean;\n\n /** 当前是否处于同域的 iframe 模式。 */\n isInIframeOfSameSite: boolean;\n\n /** 当前是否处于新框架下的 iframe 模式。 */\n isInIframeOfNext: boolean;\n\n /** 当前是否处于 Visual Builder 预览的 iframe 模式。 */\n isInIframeOfVisualBuilder: boolean;\n\n /** 当前是否处于老 console 下的 iframe 模式。 */\n isInIframeOfLegacyConsole: boolean;\n}\n\nexport function getPageInfo(): PageInfo {\n if (!misc) {\n misc = {\n isInIframe: false,\n isInIframeOfSameSite: false,\n isInIframeOfNext: false,\n isInIframeOfVisualBuilder: false,\n isInIframeOfLegacyConsole: false,\n };\n\n if (window !== window.parent) {\n misc.isInIframe = true;\n try {\n // Handle:\n // - Previewing in visual builder by iframe.\n // - Nesting next in next.\n // - Nesting console in next.\n if (window.origin === window.parent.origin) {\n misc.isInIframeOfSameSite = true;\n const selfIsNext = getBasePath() === \"/next/\";\n const parentPathname = window.parent.location.pathname;\n const parentIsNext = parentPathname.startsWith(\"/next/\");\n misc.isInIframeOfNext =\n (Number(selfIsNext) ^ Number(parentIsNext)) === 0;\n misc.isInIframeOfVisualBuilder = parentPathname.startsWith(\n `${parentIsNext ? \"/next\" : \"\"}/visual-builder/`\n );\n misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;\n }\n } catch (e) {\n // do nothing\n }\n }\n\n Object.freeze(misc);\n }\n\n return misc;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAIC,IAAc;;AAElB;;AAkBO,SAASC,WAAWA,CAAA,EAAa;EACtC,IAAI,CAACD,IAAI,EAAE;IACTA,IAAI,GAAG;MACLE,UAAU,EAAE,KAAK;MACjBC,oBAAoB,EAAE,KAAK;MAC3BC,gBAAgB,EAAE,KAAK;MACvBC,yBAAyB,EAAE,KAAK;MAChCC,yBAAyB,EAAE;IAC7B,CAAC;IAED,IAAIC,MAAM,KAAKA,MAAM,CAACC,MAAM,EAAE;MAC5BR,IAAI,CAACE,UAAU,GAAG,IAAI;MACtB,IAAI;QACF;QACA;QACA;QACA;QACA,IAAIK,MAAM,CAACE,MAAM,KAAKF,MAAM,CAACC,MAAM,CAACC,MAAM,EAAE;UAC1CT,IAAI,CAACG,oBAAoB,GAAG,IAAI;UAChC,MAAMO,UAAU,GAAG,IAAAC,wBAAW,EAAC,CAAC,KAAK,QAAQ;UAC7C,MAAMC,cAAc,GAAGL,MAAM,CAACC,MAAM,CAACK,QAAQ,CAACC,QAAQ;UACtD,MAAMC,YAAY,GAAGH,cAAc,CAACI,UAAU,CAAC,QAAQ,CAAC;UACxDhB,IAAI,CAACI,gBAAgB,GACnB,CAACa,MAAM,CAACP,UAAU,CAAC,GAAGO,MAAM,CAACF,YAAY,CAAC,MAAM,CAAC;UACnDf,IAAI,CAACK,yBAAyB,GAAGO,cAAc,CAACI,UAAU,CACvD,GAAED,YAAY,GAAG,OAAO,GAAG,EAAG,kBACjC,CAAC;UACDf,IAAI,CAACM,yBAAyB,GAAGI,UAAU,IAAI,CAACK,YAAY;QAC9D;MACF,CAAC,CAAC,OAAOG,CAAC,EAAE;QACV;MAAA;IAEJ;IAEAC,MAAM,CAACC,MAAM,CAACpB,IAAI,CAAC;EACrB;EAEA,OAAOA,IAAI;AACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleHttpError.js","names":["_http","require","_i18n","_Runtime","_history","_i18n2","_Dialog","httpErrorToString","error","Event","target","HTMLScriptElement","src","HttpFetchError","i18n","t","NS","K","NETWORK_ERROR","HttpResponseError","responseJson","msg","toString","isUnauthenticatedError","response","status","code","unauthenticatedConfirming","lastErrorMessage","handleHttpError","HttpAbortError","window","NO_AUTH_GUARD","Dialog","show","type","content","LOGIN_TIMEOUT_MESSAGE","then","redirectToLogin","console","message","title","REQUEST_FAILED","contentStyle","whiteSpace","undefined","ssoEnabled","getRuntime","getFeatureFlags","history","getHistory","push","from","location","state"],"sources":["../../src/handleHttpError.ts"],"sourcesContent":["import {\n HttpAbortError,\n HttpFetchError,\n HttpResponseError,\n} from \"@next-core/http\";\nimport { i18n } from \"@next-core/i18n\";\nimport { getRuntime } from \"./internal/Runtime.js\";\nimport { getHistory } from \"./history.js\";\nimport { K, NS } from \"./internal/i18n.js\";\nimport { Dialog } from \"./Dialog.js\";\n\n/**\n * 将 http 请求错误转换为可读的字符串。\n *\n * @remarks\n *\n * 将依次尝试读取返回的 JSON 格式数据的字符串类型的 `error` 和 `msg` 字段,如果没有找到则返回 `error.toString()` 的结果。\n *\n * @param error - 错误对象。\n *\n * @returns 转换为字符串的错误信息。\n */\nexport function httpErrorToString(error: unknown): string {\n if (error instanceof Event && error.target instanceof HTMLScriptElement) {\n return error.target.src;\n }\n if (error instanceof HttpFetchError) {\n return i18n.t(`${NS}:${K.NETWORK_ERROR}`);\n }\n if (error instanceof HttpResponseError) {\n if (error.responseJson) {\n if (typeof error.responseJson.error === \"string\") {\n return error.responseJson.error;\n } else if (typeof error.responseJson.msg === \"string\") {\n return error.responseJson.msg;\n }\n }\n }\n if (error == null) {\n return \"Unknown error\";\n }\n return error.toString();\n}\n\nexport function isUnauthenticatedError(error: unknown): boolean {\n return (\n error instanceof HttpResponseError &&\n error.response.status === 401 &&\n !!error.responseJson &&\n error.responseJson.code === 100003\n );\n}\n\nlet unauthenticatedConfirming = false;\n\nlet lastErrorMessage: string | undefined;\n\n/**\n * 处理 http 请求错误(使用 AntDesign 模态框弹出错误信息)。\n *\n * @param error - 错误对象。\n */\nexport function handleHttpError(error: unknown) {\n // Do nothing if aborted http requests\n if (error instanceof HttpAbortError) {\n return;\n }\n\n // Redirect to login page if not logged in.\n if (isUnauthenticatedError(error) && !window.NO_AUTH_GUARD) {\n if (unauthenticatedConfirming) {\n return;\n }\n unauthenticatedConfirming = true;\n Dialog.show({\n type: \"confirm\",\n content: i18n.t(`${NS}:${K.LOGIN_TIMEOUT_MESSAGE}`),\n }).then(\n () => {\n redirectToLogin();\n unauthenticatedConfirming = false;\n },\n () => {\n unauthenticatedConfirming = false;\n }\n );\n return;\n }\n\n // eslint-disable-next-line no-console\n console.error(error);\n\n const message = httpErrorToString(error);\n if (message !== lastErrorMessage) {\n lastErrorMessage = message;\n Dialog.show({\n type: \"error\",\n title: i18n.t(`${NS}:${K.REQUEST_FAILED}`),\n content: message,\n contentStyle: {\n whiteSpace: \"pre-wrap\",\n },\n }).then(() => {\n lastErrorMessage = undefined;\n });\n }\n return;\n}\n\nfunction redirectToLogin() {\n const ssoEnabled = getRuntime().getFeatureFlags()[\"sso-enabled\"];\n const history = getHistory();\n history.push(ssoEnabled ? \"/sso-auth/login\" : \"/auth/login\", {\n from: {\n ...history.location,\n state: undefined,\n },\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASM,iBAAiBA,CAACC,KAAc,EAAU;EACxD,IAAIA,KAAK,YAAYC,KAAK,IAAID,KAAK,CAACE,MAAM,YAAYC,iBAAiB,EAAE;IACvE,OAAOH,KAAK,CAACE,MAAM,CAACE,GAAG;EACzB;EACA,IAAIJ,KAAK,YAAYK,oBAAc,EAAE;IACnC,OAAOC,UAAI,CAACC,CAAC,CAAE,GAAEC,SAAG,IAAGC,QAAC,CAACC,aAAc,EAAC,CAAC;EAC3C;EACA,IAAIV,KAAK,YAAYW,uBAAiB,EAAE;IACtC,IAAIX,KAAK,CAACY,YAAY,EAAE;MACtB,IAAI,OAAOZ,KAAK,CAACY,YAAY,CAACZ,KAAK,KAAK,QAAQ,EAAE;QAChD,OAAOA,KAAK,CAACY,YAAY,CAACZ,KAAK;MACjC,CAAC,MAAM,IAAI,OAAOA,KAAK,CAACY,YAAY,CAACC,GAAG,KAAK,QAAQ,EAAE;QACrD,OAAOb,KAAK,CAACY,YAAY,CAACC,GAAG;MAC/B;IACF;EACF;EACA,IAAIb,KAAK,IAAI,IAAI,EAAE;IACjB,OAAO,eAAe;EACxB;EACA,OAAOA,KAAK,CAACc,QAAQ,
|
|
1
|
+
{"version":3,"file":"handleHttpError.js","names":["_http","require","_i18n","_Runtime","_history","_i18n2","_Dialog","httpErrorToString","error","Event","target","HTMLScriptElement","src","HttpFetchError","i18n","t","NS","K","NETWORK_ERROR","HttpResponseError","responseJson","msg","toString","isUnauthenticatedError","response","status","code","unauthenticatedConfirming","lastErrorMessage","handleHttpError","HttpAbortError","window","NO_AUTH_GUARD","Dialog","show","type","content","LOGIN_TIMEOUT_MESSAGE","then","redirectToLogin","console","message","title","REQUEST_FAILED","contentStyle","whiteSpace","undefined","ssoEnabled","getRuntime","getFeatureFlags","history","getHistory","push","from","location","state"],"sources":["../../src/handleHttpError.ts"],"sourcesContent":["import {\n HttpAbortError,\n HttpFetchError,\n HttpResponseError,\n} from \"@next-core/http\";\nimport { i18n } from \"@next-core/i18n\";\nimport { getRuntime } from \"./internal/Runtime.js\";\nimport { getHistory } from \"./history.js\";\nimport { K, NS } from \"./internal/i18n.js\";\nimport { Dialog } from \"./Dialog.js\";\n\n/**\n * 将 http 请求错误转换为可读的字符串。\n *\n * @remarks\n *\n * 将依次尝试读取返回的 JSON 格式数据的字符串类型的 `error` 和 `msg` 字段,如果没有找到则返回 `error.toString()` 的结果。\n *\n * @param error - 错误对象。\n *\n * @returns 转换为字符串的错误信息。\n */\nexport function httpErrorToString(error: unknown): string {\n if (error instanceof Event && error.target instanceof HTMLScriptElement) {\n return error.target.src;\n }\n if (error instanceof HttpFetchError) {\n return i18n.t(`${NS}:${K.NETWORK_ERROR}`);\n }\n if (error instanceof HttpResponseError) {\n if (error.responseJson) {\n if (typeof error.responseJson.error === \"string\") {\n return error.responseJson.error;\n } else if (typeof error.responseJson.msg === \"string\") {\n return error.responseJson.msg;\n }\n }\n }\n if (error == null) {\n return \"Unknown error\";\n }\n return error.toString();\n}\n\nexport function isUnauthenticatedError(error: unknown): boolean {\n return (\n error instanceof HttpResponseError &&\n error.response.status === 401 &&\n !!error.responseJson &&\n error.responseJson.code === 100003\n );\n}\n\nlet unauthenticatedConfirming = false;\n\nlet lastErrorMessage: string | undefined;\n\n/**\n * 处理 http 请求错误(使用 AntDesign 模态框弹出错误信息)。\n *\n * @param error - 错误对象。\n */\nexport function handleHttpError(error: unknown) {\n // Do nothing if aborted http requests\n if (error instanceof HttpAbortError) {\n return;\n }\n\n // Redirect to login page if not logged in.\n if (isUnauthenticatedError(error) && !window.NO_AUTH_GUARD) {\n if (unauthenticatedConfirming) {\n return;\n }\n unauthenticatedConfirming = true;\n Dialog.show({\n type: \"confirm\",\n content: i18n.t(`${NS}:${K.LOGIN_TIMEOUT_MESSAGE}`),\n }).then(\n () => {\n redirectToLogin();\n unauthenticatedConfirming = false;\n },\n () => {\n unauthenticatedConfirming = false;\n }\n );\n return;\n }\n\n // eslint-disable-next-line no-console\n console.error(error);\n\n const message = httpErrorToString(error);\n if (message !== lastErrorMessage) {\n lastErrorMessage = message;\n Dialog.show({\n type: \"error\",\n title: i18n.t(`${NS}:${K.REQUEST_FAILED}`),\n content: message,\n contentStyle: {\n whiteSpace: \"pre-wrap\",\n },\n }).then(() => {\n lastErrorMessage = undefined;\n });\n }\n return;\n}\n\nfunction redirectToLogin() {\n const ssoEnabled = getRuntime().getFeatureFlags()[\"sso-enabled\"];\n const history = getHistory();\n history.push(ssoEnabled ? \"/sso-auth/login\" : \"/auth/login\", {\n from: {\n ...history.location,\n state: undefined,\n },\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASM,iBAAiBA,CAACC,KAAc,EAAU;EACxD,IAAIA,KAAK,YAAYC,KAAK,IAAID,KAAK,CAACE,MAAM,YAAYC,iBAAiB,EAAE;IACvE,OAAOH,KAAK,CAACE,MAAM,CAACE,GAAG;EACzB;EACA,IAAIJ,KAAK,YAAYK,oBAAc,EAAE;IACnC,OAAOC,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C,CAAC,CAACC,IAAI,CACL,MAAM;MACJC,eAAe,CAAC,CAAC;MACjBZ,yBAAyB,GAAG,KAAK;IACnC,CAAC,EACD,MAAM;MACJA,yBAAyB,GAAG,KAAK;IACnC,CACF,CAAC;IACD;EACF;;EAEA;EACAa,OAAO,CAAChC,KAAK,CAACA,KAAK,CAAC;EAEpB,MAAMiC,OAAO,GAAGlC,iBAAiB,CAACC,KAAK,CAAC;EACxC,IAAIiC,OAAO,KAAKb,gBAAgB,EAAE;IAChCA,gBAAgB,GAAGa,OAAO;IAC1BR,cAAM,CAACC,IAAI,CAAC;MACVC,IAAI,EAAE,OAAO;MACbO,KAAK,EAAE5B,UAAI,CAACC,CAAC,CAAE,GAAEC,SAAG,IAAGC,QAAC,CAAC0B,cAAe,EAAC,CAAC;MAC1CP,OAAO,EAAEK,OAAO;MAChBG,YAAY,EAAE;QACZC,UAAU,EAAE;MACd;IACF,CAAC,CAAC,CAACP,IAAI,CAAC,MAAM;MACZV,gBAAgB,GAAGkB,SAAS;IAC9B,CAAC,CAAC;EACJ;EACA;AACF;AAEA,SAASP,eAAeA,CAAA,EAAG;EACzB,MAAMQ,UAAU,GAAG,IAAAC,mBAAU,EAAC,CAAC,CAACC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC;EAChE,MAAMC,OAAO,GAAG,IAAAC,mBAAU,EAAC,CAAC;EAC5BD,OAAO,CAACE,IAAI,CAACL,UAAU,GAAG,iBAAiB,GAAG,aAAa,EAAE;IAC3DM,IAAI,EAAE;MACJ,GAAGH,OAAO,CAACI,QAAQ;MACnBC,KAAK,EAAET;IACT;EACF,CAAC,CAAC;AACJ"}
|
package/dist/cjs/history.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","names":["_history","require","_getBasePath","_historyExtended","history","createHistory","browserHistory","createBrowserHistory","basename","getBasePath","replace","getUserConfirmation","Object","assign","historyExtended","getHistory"],"sources":["../../src/history.ts"],"sourcesContent":["import { History, Location, createBrowserHistory } from \"history\";\nimport { getBasePath } from \"./getBasePath.js\";\nimport {\n type ExtendedHistory,\n getUserConfirmation,\n historyExtended,\n NextHistoryState,\n} from \"./internal/historyExtended.js\";\n\nexport type NextHistory = History<NextHistoryState> & ExtendedHistory;\n\nlet history: NextHistory;\n\nexport function createHistory(): NextHistory {\n if (!history) {\n // https://github.com/remix-run/history/issues/810\n const browserHistory = createBrowserHistory<NextHistoryState>({\n basename: getBasePath().replace(/\\/$/, \"\"),\n getUserConfirmation,\n });\n Object.assign(browserHistory, historyExtended(browserHistory));\n history = browserHistory as NextHistory;\n }\n return history;\n}\n\nexport function getHistory(): NextHistory {\n return history;\n}\n\nexport type NextLocation = Location<NextHistoryState>;\n\nexport type { NextHistoryState };\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AASA,IAAIG,OAAoB;AAEjB,SAASC,aAAaA,CAAA,EAAgB;EAC3C,IAAI,CAACD,OAAO,EAAE;IACZ;IACA,MAAME,cAAc,GAAG,IAAAC,6BAAoB,EAAmB;MAC5DC,QAAQ,EAAE,IAAAC,wBAAW,
|
|
1
|
+
{"version":3,"file":"history.js","names":["_history","require","_getBasePath","_historyExtended","history","createHistory","browserHistory","createBrowserHistory","basename","getBasePath","replace","getUserConfirmation","Object","assign","historyExtended","getHistory"],"sources":["../../src/history.ts"],"sourcesContent":["import { History, Location, createBrowserHistory } from \"history\";\nimport { getBasePath } from \"./getBasePath.js\";\nimport {\n type ExtendedHistory,\n getUserConfirmation,\n historyExtended,\n NextHistoryState,\n} from \"./internal/historyExtended.js\";\n\nexport type NextHistory = History<NextHistoryState> & ExtendedHistory;\n\nlet history: NextHistory;\n\nexport function createHistory(): NextHistory {\n if (!history) {\n // https://github.com/remix-run/history/issues/810\n const browserHistory = createBrowserHistory<NextHistoryState>({\n basename: getBasePath().replace(/\\/$/, \"\"),\n getUserConfirmation,\n });\n Object.assign(browserHistory, historyExtended(browserHistory));\n history = browserHistory as NextHistory;\n }\n return history;\n}\n\nexport function getHistory(): NextHistory {\n return history;\n}\n\nexport type NextLocation = Location<NextHistoryState>;\n\nexport type { NextHistoryState };\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AASA,IAAIG,OAAoB;AAEjB,SAASC,aAAaA,CAAA,EAAgB;EAC3C,IAAI,CAACD,OAAO,EAAE;IACZ;IACA,MAAME,cAAc,GAAG,IAAAC,6BAAoB,EAAmB;MAC5DC,QAAQ,EAAE,IAAAC,wBAAW,EAAC,CAAC,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;MAC1CC,mBAAmB,EAAnBA;IACF,CAAC,CAAC;IACFC,MAAM,CAACC,MAAM,CAACP,cAAc,EAAE,IAAAQ,gCAAe,EAACR,cAAc,CAAC,CAAC;IAC9DF,OAAO,GAAGE,cAA6B;EACzC;EACA,OAAOF,OAAO;AAChB;AAEO,SAASW,UAAUA,CAAA,EAAgB;EACxC,OAAOX,OAAO;AAChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindTemplateProxy.js","names":["_utils","require","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","getTplStateStore","tplHostMetadata","internalBricksByRef","set","events","proxy","from","to","Object","entries","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","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,IAAAA,MAAA,GAAAC,OAAA;AAEO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,MAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,uBAAgB,EAACJ,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,MAAMK,eAAe,GAAGF,SAAS,CAAEE,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAACC,GAAG,CAACR,GAAG,EAAEF,KAAK,CAAC;EAEnD,MAAMW,MAAM,IAAAV,qBAAA,GAAGO,eAAe,CAACI,KAAK,cAAAX,qBAAA,uBAArBA,qBAAA,CAAuBU,MAAM;EAC5C,IAAIA,MAAM,EAAE;IACV,KAAK,MAAM,CAACE,IAAI,EAAEC,EAAE,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;MAC/C,IAAIG,EAAE,CAACZ,GAAG,KAAKA,GAAG,EAAE;QAAA,IAAAe,YAAA,EAAAC,IAAA,EAAAC,qBAAA;QAClB,MAAMC,QAAQ,GAAIC,CAAQ,IAAK;UAC7B,IAAIA,CAAC,CAACC,OAAO,EAAE;YACbD,CAAC,CAACE,eAAe,
|
|
1
|
+
{"version":3,"file":"bindTemplateProxy.js","names":["_utils","require","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","getTplStateStore","tplHostMetadata","internalBricksByRef","set","events","proxy","from","to","Object","entries","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","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,IAAAA,MAAA,GAAAC,OAAA;AAEO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,MAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,uBAAgB,EAACJ,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,MAAMK,eAAe,GAAGF,SAAS,CAAEE,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,C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AEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;EAE9C,IAAI,CAACG,cAAc,CAACE,eAAe,IAAI,CAACH,GAAG,EAAE;IAC3C;EACF;EAEA,MAAM;IAAEI;EAAU,CAAC,GAAG,IAAAC,uBAAgB,EAACJ,cAAc,EAAE,qBAAqB,CAAC;EAC7E;EACA,MAAMK,eAAe,GAAGF,SAAS,CAAEE,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAAC0B,MAAM,CAACjC,GAAG,CAAC;EAE/C,KAAK,MAAM,CAACkC,IAAI,EAAEC,EAAE,CAAC,KAAAC,iBAAA,GAAIlC,OAAO,CAAE4B,gBAAgB,cAAAM,iBAAA,cAAAA,iBAAA,GAAI,EAAE,EAAE;IAAA,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE4B,gBAAgB;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","Symbol","for","exports","symbolForTplStateStoreId","symbolForTPlExternalForEachItem"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncProperties } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncProperties;\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAGC,MAAM,CAACC,GAAG,CAC3D,
|
|
1
|
+
{"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","Symbol","for","exports","symbolForTplStateStoreId","symbolForTPlExternalForEachItem"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncProperties } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncProperties;\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAGC,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AAACC,OAAA,CAAAH,mCAAA,GAAAA,mCAAA;AACK,MAAMI,wBAAwB,GAAGH,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAACC,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAChE,MAAMC,+BAA+B,GAAGJ,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AAACC,OAAA,CAAAE,+BAAA,GAAAA,+BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostProperties","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostProperties);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostProperties,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAEO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,mBAAoC,EACjC;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGL,SAAS,CAACK,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIC,oBAAS,CAAC,OAAO,EAAET,SAAS,CAAC;EACvDK,cAAc,CAACK,gBAAgB,CAACC,GAAG,CAACR,eAAe,EAAEK,aAAa,CAAC;EACnE,IAAIH,cAAc,CAACO,kBAAkB,EAAE;IACrCP,cAAc,CAACO,kBAAkB,CAACC,IAAI,CAACL,aAAa,CAAC;EACvD;EAEA,MAAM;IAAEM,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAGC,gCAAe,CAACC,GAAG,CAACrB,UAAU,CAAE;EAC5EsB,cAAK,aAALA,cAAK,wBAAAlB,cAAA,GAALkB,cAAK,CAAEC,OAAO,cAAAnB,cAAA,uBAAdA,cAAA,CAAgBoB,qBAAqB,CAACL,SAAS,CAAC;EAChDT,aAAa,CAACe,MAAM,CAACP,KAAK,EAAEX,cAAc,EAAEJ,mBAAmB,CAAC;EAEhE,MAAM;IACJuB,KAAK,EAAEC,qBAAqB;IAC5BC,QAAQ,EAAEC,gBAAgB;IAC1B,GAAGC;EACL,CAAC,GAAG7B,SAAS;EAEb,MAAM8B,YAAY,GAAG;IACnB,GAAGD,aAAa;IAChBE,KAAK,EAAEhC;EACT,CAAM;EAENE,SAAS,CAAC+B,eAAe,GAAG;IAC1BC,mBAAmB,EAAE,IAAIC,GAAG,
|
|
1
|
+
{"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostProperties","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostProperties);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostProperties,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,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AED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","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","hasOwnProperty","i","push","set","refPosition","clamp","runtimeContext","setupTemplateExternalBricks","forEachItem","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","map","brick","_brick$slots","symbolForTPlExternalForEachItem","Object","fromEntries","_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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOO,SAASG,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,MAAM;IACJC,eAAe;IACfC,mBAAmB;IACnBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAA+C;EAEnD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,MAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,MAAMG,gBAAgB,GAAIC,SAAkC,IAAK;QAC/D,MAAMC,KAA8B,GAAG,CAAC,CAAC;QACzC,KAAK,MAAM;UAAEC,IAAI;UAAEC;QAAG,CAAC,IAAIP,eAAe,EAAE;UAC1C,MAAMQ,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,GAAIJ,mBAAmB,CAAqBgB,IAAI,CAChER,
|
|
1
|
+
{"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","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","hasOwnProperty","i","push","set","refPosition","clamp","runtimeContext","setupTemplateExternalBricks","forEachItem","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","map","brick","_brick$slots","symbolForTPlExternalForEachItem","Object","fromEntries","_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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOO,SAASG,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,MAAM;IACJC,eAAe;IACfC,mBAAmB;IACnBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAA+C;EAEnD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,MAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,MAAMG,gBAAgB,GAAIC,SAAkC,IAAK;QAC/D,MAAMC,KAA8B,GAAG,CA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IAAIgB,KAAK,CAAChB,IAAI,KAAK,QAAQ,GACjCgB,KAAK,GACL;IACE,GAAGA,KAAK;IACRlC,MAAM,EAAEa,2BAA2B,CAACqB,KAAK,CAAClC,MAAM,EAAEc,WAAW;EAC/D,CACN,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupUseBrickInTemplate.js","names":["_general","require","_setupTemplateProxy","_Renderer","setupUseBrickInTemplate","props","hostContext","walk","isObject","Array","isArray","map","Object","fromEntries","entries","key","value","setup","concat","getOwnPropertySymbols","k","item","properties","slots","originalSlots","children","restConf","transpiledSlots","childrenToSlots","slotName","slotConf","_slotConf$bricks","type","bricks","setupTemplateProxy","ref"],"sources":["../../../../src/internal/CustomTemplates/setupUseBrickInTemplate.ts"],"sourcesContent":["import type { UseBrickSlotsConf, UseSingleBrickConf } from \"@next-core/types\";\nimport { isObject } from \"@next-core/utils/general\";\nimport type { TemplateHostContext } from \"../interfaces.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupUseBrickInTemplate<T>(\n props: T,\n hostContext: TemplateHostContext\n): T {\n function walk<P>(props: P): P {\n if (!isObject(props)) {\n return props;\n }\n\n if (Array.isArray(props)) {\n return props.map(walk) as P;\n }\n\n return Object.fromEntries(\n Object.entries(props)\n .map(([key, value]) =>\n isObject(value) && key === \"useBrick\"\n ? Array.isArray(value)\n ? [key, value.map(setup)]\n : [key, setup(value as UseSingleBrickConf)]\n : [key, walk(value)]\n )\n .concat(\n Object.getOwnPropertySymbols(props).map((k) => [\n k,\n (props as Record<string | symbol, unknown>)[k],\n ])\n )\n ) as P;\n }\n\n function setup(item: UseSingleBrickConf): UseSingleBrickConf {\n const { properties, slots: originalSlots, children, ...restConf } = item;\n\n const transpiledSlots = childrenToSlots(children, originalSlots) as\n | UseBrickSlotsConf\n | undefined;\n\n const slots = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map(setup),\n },\n ])\n ) as UseBrickSlotsConf;\n\n return {\n ...restConf,\n properties: walk(properties),\n slots,\n ...setupTemplateProxy(hostContext, restConf.ref, slots),\n };\n }\n\n return walk(props);\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEO,SAASG,uBAAuBA,CACrCC,KAAQ,EACRC,WAAgC,EAC7B;EACH,SAASC,IAAIA,CAAIF,KAAQ,EAAK;IAC5B,IAAI,CAAC,IAAAG,iBAAQ,EAACH,KAAK,CAAC,EAAE;MACpB,OAAOA,KAAK;IACd;IAEA,IAAII,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;MACxB,OAAOA,KAAK,CAACM,GAAG,CAACJ,IAAI,CAAC;IACxB;IAEA,OAAOK,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACT,KAAK,CAAC,CAClBM,GAAG,CAAC,CAAC,CAACI,GAAG,EAAEC,KAAK,CAAC,KAChB,IAAAR,iBAAQ,EAACQ,KAAK,CAAC,IAAID,GAAG,KAAK,UAAU,GACjCN,KAAK,CAACC,OAAO,CAACM,KAAK,CAAC,GAClB,CAACD,GAAG,EAAEC,KAAK,CAACL,GAAG,CAACM,KAAK,CAAC,CAAC,GACvB,CAACF,GAAG,EAAEE,KAAK,CAACD,
|
|
1
|
+
{"version":3,"file":"setupUseBrickInTemplate.js","names":["_general","require","_setupTemplateProxy","_Renderer","setupUseBrickInTemplate","props","hostContext","walk","isObject","Array","isArray","map","Object","fromEntries","entries","key","value","setup","concat","getOwnPropertySymbols","k","item","properties","slots","originalSlots","children","restConf","transpiledSlots","childrenToSlots","slotName","slotConf","_slotConf$bricks","type","bricks","setupTemplateProxy","ref"],"sources":["../../../../src/internal/CustomTemplates/setupUseBrickInTemplate.ts"],"sourcesContent":["import type { UseBrickSlotsConf, UseSingleBrickConf } from \"@next-core/types\";\nimport { isObject } from \"@next-core/utils/general\";\nimport type { TemplateHostContext } from \"../interfaces.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupUseBrickInTemplate<T>(\n props: T,\n hostContext: TemplateHostContext\n): T {\n function walk<P>(props: P): P {\n if (!isObject(props)) {\n return props;\n }\n\n if (Array.isArray(props)) {\n return props.map(walk) as P;\n }\n\n return Object.fromEntries(\n Object.entries(props)\n .map(([key, value]) =>\n isObject(value) && key === \"useBrick\"\n ? Array.isArray(value)\n ? [key, value.map(setup)]\n : [key, setup(value as UseSingleBrickConf)]\n : [key, walk(value)]\n )\n .concat(\n Object.getOwnPropertySymbols(props).map((k) => [\n k,\n (props as Record<string | symbol, unknown>)[k],\n ])\n )\n ) as P;\n }\n\n function setup(item: UseSingleBrickConf): UseSingleBrickConf {\n const { properties, slots: originalSlots, children, ...restConf } = item;\n\n const transpiledSlots = childrenToSlots(children, originalSlots) as\n | UseBrickSlotsConf\n | undefined;\n\n const slots = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map(setup),\n },\n ])\n ) as UseBrickSlotsConf;\n\n return {\n ...restConf,\n properties: walk(properties),\n slots,\n ...setupTemplateProxy(hostContext, restConf.ref, slots),\n };\n }\n\n return walk(props);\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEO,SAASG,uBAAuBA,CACrCC,KAAQ,EACRC,WAAgC,EAC7B;EACH,SAASC,IAAIA,CAAIF,KAAQ,EAAK;IAC5B,IAAI,CAAC,IAAAG,iBAAQ,EAACH,KAAK,CAAC,EAAE;MACpB,OAAOA,KAAK;IACd;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AACG,MAAM,cAAAF,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEpB,GAAG,CAACM,KAAK;MAC3C,CAAC,CACF;IAAA,EACH,CAAsB;IAEtB,OAAO;MACL,GAAGS,QAAQ;MACXJ,UAAU,EAAEf,IAAI,CAACe,UAAU,CAAC;MAC5BC,KAAK;MACL,GAAG,IAAAW,sCAAkB,EAAC5B,WAAW,EAAEoB,QAAQ,CAACS,GAAG,EAAEZ,KAAK;IACxD,CAAC;EACH;EAEA,OAAOhB,IAAI,CAACF,KAAK,CAAC;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_CustomTemplates","require","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName","customTemplates"],"sources":["../../../../src/internal/CustomTemplates/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeBrickElement, RuntimeContext } from \"../interfaces.js\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"tplStateStoreId\" | \"tplStateStoreMap\"\n>;\n\nexport function getTplStateStore(\n { tplStateStoreId, tplStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"STATE\"> {\n if (!tplStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of a custom template${extraInfo ?? \"\"}`\n );\n }\n const store = tplStateStoreMap.get(tplStateStoreId);\n if (!store) {\n throw new Error(\n `Template state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n\nexport function getTplHostElement(\n runtimeContext: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): RuntimeBrickElement {\n const store = getTplStateStore(runtimeContext, using, extraInfo);\n const hostElement = store.hostBrick!.element;\n if (!hostElement) {\n throw new Error(\n `Template host element is gone when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return hostElement;\n}\n\nexport function getTagNameOfCustomTemplate(\n brick: string,\n appId?: string\n): false | string {\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && appId) {\n const tagName = `${appId}.${brick}`;\n if (customTemplates.get(tagName)) {\n return tagName;\n }\n }\n if (customTemplates.get(brick)) {\n return brick;\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAOO,SAASC,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACZ,UAASF,KAAM,iCAAgCC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAG,
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_CustomTemplates","require","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName","customTemplates"],"sources":["../../../../src/internal/CustomTemplates/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeBrickElement, RuntimeContext } from \"../interfaces.js\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"tplStateStoreId\" | \"tplStateStoreMap\"\n>;\n\nexport function getTplStateStore(\n { tplStateStoreId, tplStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"STATE\"> {\n if (!tplStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of a custom template${extraInfo ?? \"\"}`\n );\n }\n const store = tplStateStoreMap.get(tplStateStoreId);\n if (!store) {\n throw new Error(\n `Template state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n\nexport function getTplHostElement(\n runtimeContext: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): RuntimeBrickElement {\n const store = getTplStateStore(runtimeContext, using, extraInfo);\n const hostElement = store.hostBrick!.element;\n if (!hostElement) {\n throw new Error(\n `Template host element is gone when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return hostElement;\n}\n\nexport function getTagNameOfCustomTemplate(\n brick: string,\n appId?: string\n): false | string {\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && appId) {\n const tagName = `${appId}.${brick}`;\n if (customTemplates.get(tagName)) {\n return tagName;\n }\n }\n if (customTemplates.get(brick)) {\n return brick;\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAOO,SAASC,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACZ,UAASF,KAAM,iCAAgCC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAG,EAClE,CAAC;EACH;EACA,MAAME,KAAK,GAAGJ,gBAAgB,CAACK,GAAG,CAACN,eAAe,CAAC;EACnD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACZ,iDAAgDF,KAAM,IACrDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDACH,CAAC;EACH;EACA,OAAOE,KAAK;AACd;AAEO,SAASE,iBAAiBA,CAC/BC,cAA2C,EAC3CN,KAAa,EACbC,SAAkB,EACG;EACrB,MAAME,KAAK,GAAGN,gBAAgB,CAACS,cAAc,EAAEN,KAAK,EAAEC,SAAS,CAAC;EAChE,MAAMM,WAAW,GAAGJ,KAAK,CAACK,SAAS,CAAEC,OAAO;EAC5C,IAAI,CAACF,WAAW,EAAE;IAChB,MAAM,IAAIL,KAAK,CACZ,6CAA4CF,KAAM,IACjDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDACH,CAAC;EACH;EACA,OAAOM,WAAW;AACpB;AAEO,SAASG,0BAA0BA,CACxCC,KAAa,EACbC,KAAc,EACE;EAChB;EACA,IAAI,CAACD,KAAK,CAACE,QAAQ,CAAC,GAAG,CAAC,IAAIF,KAAK,CAACG,UAAU,CAAC,MAAM,CAAC,IAAIF,KAAK,EAAE;IAC7D,MAAMG,OAAO,GAAI,GAAEH,KAAM,IAAGD,KAAM,EAAC;IACnC,IAAIK,gCAAe,CAACZ,GAAG,CAACW,OAAO,CAAC,EAAE;MAChC,OAAOA,OAAO;IAChB;EACF;EACA,IAAIC,gCAAe,CAACZ,GAAG,CAACO,KAAK,CAAC,EAAE;IAC9B,OAAOA,KAAK;EACd;EACA,OAAO,KAAK;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostProperties","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","tplStateStoreId","formStateStore","DataStore","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","brick","events","mergeEvents","renderRoot","properties","slots","undefined","children","style","padding","content","bricks","type","schema","id","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncProperties, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\"FORM_STATE\");\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostProperties);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formConf.brick === \"forms.general-form\" && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"basic-bricks.micro-view\",\n properties: { style: { padding: \"12px\" } },\n slots: {\n content: { bricks: [formConf], type: \"bricks\" },\n },\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,mBAAoC,EACzB;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAON,QAAQ,KAAK,QAAQ,GAAGO,IAAI,CAACC,KAAK,CAACR,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMS,gBAAgB,GAAG,IAAAC,gBAAQ,EAAC,aAAa,CAAC;EAChD,MAAMC,cAAc,GAAG;IACrB,GAAGT,SAAS,CAACS,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,eAAe;EAErC,MAAMC,cAAc,GAAG,IAAIC,oBAAS,CAAC,YAAY,CAAC;EAClDJ,cAAc,CAACK,iBAAiB,CAACC,GAAG,CAACR,gBAAgB,EAAEK,cAAc,CAAC;EACtE,IAAIH,cAAc,CAACO,mBAAmB,EAAE;IACtCP,cAAc,CAACO,mBAAmB,CAACC,IAAI,CAACL,cAAc,CAAC;EACzD;;EAEA;EACA,MAAMM,OAAO,IAAAhB,qBAAA,GAAGE,kBAAkB,CAACc,OAAO,cAAAhB,qBAAA,cAAAA,qBAAA,GAAI,EAAE;EAChD,IAAI,CAACgB,OAAO,CAACC,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,KAAK,QAAQ,CAAC,EAAE;IACjDH,OAAO,CAACD,IAAI,CAAC;MAAEI,IAAI,EAAE;IAAS,CAAC,CAAC;EAClC;EAEAT,cAAc,CAACU,MAAM,CAACJ,OAAO,EAAET,cAAc,EAAER,mBAAmB,CAAC;EAEnE,MAAMsB,QAAQ,GAAGC,iBAAiB,CAChCpB,kBAAkB,CAACqB,UAAU,EAC7BrB,kBAAkB,CAACsB,MAAM,EACzBnB,
|
|
1
|
+
{"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostProperties","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","tplStateStoreId","formStateStore","DataStore","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","brick","events","mergeEvents","renderRoot","properties","slots","undefined","children","style","padding","content","bricks","type","schema","id","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncProperties, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\"FORM_STATE\");\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostProperties);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formConf.brick === \"forms.general-form\" && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"basic-bricks.micro-view\",\n properties: { style: { padding: \"12px\" } },\n slots: {\n content: { bricks: [formConf], type: \"bricks\" },\n },\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,mBAAoC,EACzB;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAON,QAAQ,KAAK,QAAQ,GAAGO,IAAI,CAACC,KAAK,CAACR,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMS,gBAAgB,GAAG,IAAAC,gBAAQ,EAAC,aAAa,CAAC;EAChD,MAAMC,cAAc,GAAG;IACrB,GAAGT,SAAS,CAACS,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,eAAe;EAErC,MAAMC,cAAc,GAAG,IAAIC,oBAAS,CAAC,YAAY,CAAC;EAClDJ,cAAc,CAACK,iBAAiB,CAACC,GAAG,CAACR,gBAAgB,EAAEK,cAAc,CAAC;EACtE,IAAIH,cAAc,CAACO,mBAAmB,EAAE;IACtCP,cAAc,CAACO,mBAAmB,CAACC,IAAI,CAACL,cAAc,CAAC;EACzD;;EAEA;EACA,MAAMM,OAAO,IAAAhB,qBAAA,GAAGE,kBAAkB,CAACc,OAAO,cAAAhB,qBAAA,cAAAA,qBAAA,GAAI,EAAE;EAChD,IAAI,CAACgB,OAAO,CAACC,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,KAAK,QAAQ,CAAC,EAAE;IACjDH,OAAO,CAACD,IAAI,CAAC;MAAEI,IAAI,EAAE;IAAS,CAA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