@next-core/runtime 1.67.0 → 1.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CustomTemplates.js +11 -4
- package/dist/cjs/CustomTemplates.js.map +1 -1
- package/dist/cjs/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/cjs/createRoot.js +4 -1
- package/dist/cjs/createRoot.js.map +1 -1
- package/dist/cjs/index.js +7 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +2 -1
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/utils.js +12 -3
- package/dist/cjs/internal/CustomTemplates/utils.js.map +1 -1
- package/dist/cjs/internal/IsolatedTemplates.js +23 -0
- package/dist/cjs/internal/IsolatedTemplates.js.map +1 -0
- package/dist/cjs/internal/Renderer.js +2 -2
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/compute/IsolatedFunctions.js.map +1 -1
- package/dist/esm/CustomTemplates.js +11 -5
- package/dist/esm/CustomTemplates.js.map +1 -1
- package/dist/esm/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/esm/createRoot.js +4 -1
- package/dist/esm/createRoot.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +2 -1
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/utils.js +12 -3
- package/dist/esm/internal/CustomTemplates/utils.js.map +1 -1
- package/dist/esm/internal/IsolatedTemplates.js +16 -0
- package/dist/esm/internal/IsolatedTemplates.js.map +1 -0
- package/dist/esm/internal/Renderer.js +2 -2
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/compute/IsolatedFunctions.js.map +1 -1
- package/dist/types/CustomTemplates.d.ts +3 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/CustomTemplates/utils.d.ts +1 -1
- package/dist/types/internal/IsolatedTemplates.d.ts +4 -0
- package/dist/types/internal/compute/IsolatedFunctions.d.ts +2 -2
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.customTemplates = void 0;
|
|
6
|
+
exports.customTemplates = exports.CustomTemplateRegistry = void 0;
|
|
7
7
|
var _lodash = require("lodash");
|
|
8
8
|
var _isStrictMode = require("./isStrictMode.js");
|
|
9
9
|
var _getV2RuntimeFromDll = require("./getV2RuntimeFromDll.js");
|
|
@@ -11,6 +11,10 @@ var _getV2RuntimeFromDll = require("./getV2RuntimeFromDll.js");
|
|
|
11
11
|
const allowedNativeProps = new Set(["prefix"]);
|
|
12
12
|
class CustomTemplateRegistry {
|
|
13
13
|
#registry = new Map();
|
|
14
|
+
#isolated;
|
|
15
|
+
constructor(isolated) {
|
|
16
|
+
this.#isolated = isolated;
|
|
17
|
+
}
|
|
14
18
|
define(tagName, constructor) {
|
|
15
19
|
var _constructor$proxy, _compatibleConstructo;
|
|
16
20
|
let registered = this.#registry.has(tagName);
|
|
@@ -128,7 +132,6 @@ class CustomTemplateRegistry {
|
|
|
128
132
|
}
|
|
129
133
|
Object.defineProperty(TplElement.prototype, propName, {
|
|
130
134
|
get() {
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
132
135
|
return this.$$tplStateStore.getValue(propName);
|
|
133
136
|
},
|
|
134
137
|
set(value) {
|
|
@@ -143,7 +146,6 @@ class CustomTemplateRegistry {
|
|
|
143
146
|
for (const [from, to] of validProxyProps) {
|
|
144
147
|
Object.defineProperty(TplElement.prototype, from, {
|
|
145
148
|
get() {
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
147
149
|
const element = this.$$getElementByRef(to.ref);
|
|
148
150
|
return element[to.refProperty ?? from];
|
|
149
151
|
},
|
|
@@ -161,7 +163,6 @@ class CustomTemplateRegistry {
|
|
|
161
163
|
for (const [from, to] of proxyMethods) {
|
|
162
164
|
Object.defineProperty(TplElement.prototype, from, {
|
|
163
165
|
value(...args) {
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
165
166
|
const element = this.$$getElementByRef(to.ref);
|
|
166
167
|
return element[to.refMethod ?? from](...args);
|
|
167
168
|
},
|
|
@@ -173,7 +174,13 @@ class CustomTemplateRegistry {
|
|
|
173
174
|
get(tagName) {
|
|
174
175
|
return this.#registry.get(tagName);
|
|
175
176
|
}
|
|
177
|
+
clearIsolatedRegistry() {
|
|
178
|
+
if (this.#isolated) {
|
|
179
|
+
this.#registry.clear();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
176
182
|
}
|
|
183
|
+
exports.CustomTemplateRegistry = CustomTemplateRegistry;
|
|
177
184
|
function getExposedStates(state) {
|
|
178
185
|
// Allow duplicated state names which maybe mutually exclusive.
|
|
179
186
|
return (0, _lodash.uniq)((state === null || state === void 0 ? void 0 : state.filter(item => item.expose).map(item => item.name)) ?? []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomTemplates.js","names":["_lodash","require","_isStrictMode","_getV2RuntimeFromDll","allowedNativeProps","Set","CustomTemplateRegistry","registry","Map","define","tagName","constructor","_constructor$proxy","_compatibleConstructo","registered","has","console","warn","customElements","get","strict","isStrictMode","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","value","Object","entries","asVariable","warnAboutStrictMode","push","mergeProperty","refTransform","error","ref","compatibleConstructor","fromEntries","state","map","item","expose","concat","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","propName","some","defineProperty","getValue","_this$$$tplStateStore2","updateValue","enumerable","from","to","refProperty","_this$$$getElementByR","call","args","refMethod","uniq","getCustomTemplatesV2","v2Kit","getV2RuntimeFromDll","freeze","getRuntime","registerCustomTemplate","customTemplates","exports"],"sources":["../../src/CustomTemplates.ts"],"sourcesContent":["import type {\n ContextConf,\n CustomTemplate,\n CustomTemplateConstructor,\n CustomTemplateProxyBasicProperty,\n} from \"@next-core/types\";\nimport { uniq } from \"lodash\";\nimport type { RuntimeBrickElement } from \"./internal/interfaces.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"./isStrictMode.js\";\nimport { getV2RuntimeFromDll } from \"./getV2RuntimeFromDll.js\";\n\n// Note: `prefix` is a native prop on Element, but it's only used in XML documents.\nconst allowedNativeProps = new Set([\"prefix\"]);\n\ninterface LegacyTplPropProxy extends CustomTemplateProxyBasicProperty {\n asVariable?: boolean;\n mergeProperty?: unknown;\n refTransform?: unknown;\n}\n\nclass CustomTemplateRegistry {\n readonly #registry = new Map<string, CustomTemplate>();\n\n define(tagName: string, constructor: CustomTemplateConstructor): void {\n let registered = this.#registry.has(tagName);\n if (registered) {\n // When open launchpad, the storyboard will be updated.\n // However, we can't *undefine* a custom element.\n // Just ignore re-registering custom templates.\n // eslint-disable-next-line no-console\n console.warn(`Custom template of \"${tagName}\" already registered.`);\n } else {\n registered = !!customElements.get(tagName);\n if (registered) {\n // eslint-disable-next-line no-console\n console.warn(\n `Custom template of \"${tagName}\" already defined by customElements.`\n );\n }\n }\n\n // Transform legacy `proxy.properties[].asVariable` as states.\n const strict = isStrictMode();\n const proxyProperties = (constructor.proxy?.properties ?? {}) as {\n [name: string]: LegacyTplPropProxy;\n };\n const validProxyProps: [string, CustomTemplateProxyBasicProperty][] = [];\n const legacyTplVariables: string[] = [];\n for (const [key, value] of Object.entries(proxyProperties)) {\n if (value.asVariable) {\n warnAboutStrictMode(strict, \"Template `asVariable`\", tagName, key);\n // istanbul ignore next\n if (!strict) {\n // For existed TPL usage, treat it as a STATE.\n legacyTplVariables.push(key);\n }\n } else if (value.mergeProperty || value.refTransform) {\n // eslint-disable-next-line no-console\n console.error(\n \"Template `mergeProperty` and `refTransform` are dropped in v3:\",\n tagName,\n key\n );\n } else if (value.ref) {\n validProxyProps.push([key, value]);\n }\n // Else: documentation only, for exposed states.\n }\n\n const compatibleConstructor = {\n ...constructor,\n proxy: {\n ...constructor.proxy,\n properties: Object.fromEntries(validProxyProps),\n },\n state: (constructor.state\n ? strict\n ? constructor.state\n : constructor.state.map((item) => ({\n // Make `expose` defaults to true in non-strict mode.\n expose: true,\n ...item,\n }))\n : []\n ).concat(legacyTplVariables.map((tpl) => ({ name: tpl, expose: true }))),\n };\n\n // Now we allow re-register custom template\n this.#registry.set(tagName, {\n ...compatibleConstructor,\n name: tagName,\n });\n\n const exposedStates = getExposedStates(compatibleConstructor.state);\n const proxyMethods = Object.entries(\n compatibleConstructor.proxy?.methods ?? {}\n );\n\n const props = exposedStates.concat(\n validProxyProps.map((entry) => entry[0])\n );\n const methods = proxyMethods.map((entry) => entry[0]);\n\n const nativeProps = props\n .concat(methods)\n .filter(\n (prop) => prop in HTMLElement.prototype && !allowedNativeProps.has(prop)\n );\n if (nativeProps.length > 0) {\n warnAboutStrictMode(\n strict,\n \"Using native HTMLElement properties as template properties or methods\",\n tagName,\n ...nativeProps\n );\n // istanbul ignore next\n if (strict) {\n throw new Error(\n `In custom template \"${tagName}\", ${nativeProps\n .map((p) => `\"${p}\"`)\n .join(\n \", \"\n )} are native HTMLElement properties, and should be avoid to be used as brick properties or methods.`\n );\n }\n }\n\n if (registered) {\n return;\n }\n\n class TplElement extends HTMLElement {\n get $$typeof() {\n return \"custom-template\" as const;\n }\n\n static get _dev_only_definedProperties(): string[] {\n return props;\n }\n\n static get _dev_only_definedMethods(): string[] {\n return methods;\n }\n\n $$getElementByRef(this: RuntimeBrickElement, ref: string) {\n return this.$$tplStateStore?.hostBrick?.tplHostMetadata?.internalBricksByRef.get(\n ref\n )?.element;\n }\n\n connectedCallback() {\n let shadowRoot = this.shadowRoot;\n if (!shadowRoot) {\n shadowRoot = this.attachShadow({ mode: \"open\" });\n }\n const fragment = document.createDocumentFragment();\n const style = document.createElement(\"style\");\n style.textContent = \":host{display:block}:host([hidden]){display:none}\";\n const slot = document.createElement(\"slot\");\n fragment.appendChild(style);\n fragment.appendChild(slot);\n shadowRoot.appendChild(fragment);\n }\n\n disconnectedCallback() {\n if (this.shadowRoot) {\n this.shadowRoot.textContent = \"\";\n }\n }\n }\n\n for (const propName of exposedStates) {\n if (validProxyProps.some((entry) => entry[0] === propName)) {\n // eslint-disable-next-line no-console\n console.error(\n `Cannot define an exposed state that is also a proxy property: \"${propName}\" in ${tagName}`\n );\n continue;\n }\n Object.defineProperty(TplElement.prototype, propName, {\n get(this: RuntimeBrickElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.$$tplStateStore!.getValue(propName);\n },\n set(this: RuntimeBrickElement, value: unknown) {\n // 在 mount 过程中,先设置属性,再设置 `$$tplStateStore`,这样,当触发属性设置时,\n // 避免初始化的一次 state update 操作及其 onChange 事件。\n this.$$tplStateStore?.updateValue(propName, value, \"replace\");\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of validProxyProps) {\n Object.defineProperty(TplElement.prototype, from, {\n get(this: TplElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n unknown\n >;\n return element[to.refProperty ?? from];\n },\n set(this: TplElement, value: unknown) {\n // 同上 exposedState.set\n const element = this.$$getElementByRef?.(to.ref) as unknown as Record<\n string,\n unknown\n >;\n if (element) {\n element[to.refProperty ?? from] = value;\n }\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of proxyMethods) {\n Object.defineProperty(TplElement.prototype, from, {\n value(this: TplElement, ...args: unknown[]) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n Function\n >;\n return element[to.refMethod ?? from](...args);\n },\n enumerable: true,\n });\n }\n\n customElements.define(tagName, TplElement);\n }\n\n get(tagName: string) {\n return this.#registry.get(tagName);\n }\n}\n\nfunction getExposedStates(state: ContextConf[] | undefined): string[] {\n // Allow duplicated state names which maybe mutually exclusive.\n return uniq(\n state?.filter((item) => item.expose).map((item) => item.name) ?? []\n );\n}\n\n// istanbul ignore next\nfunction getCustomTemplatesV2() {\n const v2Kit = getV2RuntimeFromDll();\n if (v2Kit) {\n return Object.freeze({\n define(tagName: string, constructor: CustomTemplateConstructor) {\n return v2Kit.getRuntime().registerCustomTemplate(tagName, constructor);\n },\n }) as CustomTemplateRegistry;\n }\n}\n\n// istanbul ignore next\nexport const customTemplates =\n getCustomTemplatesV2() || new CustomTemplateRegistry();\n"],"mappings":";;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAEA;AACA,MAAMG,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAQ9C,MAAMC,sBAAsB,CAAC;EAClB,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAEtDC,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAQ;IAAA,IAAAC,kBAAA,EAAAC,qBAAA;IACpE,IAAIC,UAAU,GAAG,IAAI,CAAC,CAACP,QAAQ,CAACQ,GAAG,CAACL,OAAO,CAAC;IAC5C,IAAII,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAE,OAAO,CAACC,IAAI,CAAC,uBAAuBP,OAAO,uBAAuB,CAAC;IACrE,CAAC,MAAM;MACLI,UAAU,GAAG,CAAC,CAACI,cAAc,CAACC,GAAG,CAACT,OAAO,CAAC;MAC1C,IAAII,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A;AACA,SAASwD,oBAAoBA,CAAA,EAAG;EAC9B,MAAMC,KAAK,GAAG,IAAAC,wCAAmB,EAAC,CAAC;EACnC,IAAID,KAAK,EAAE;IACT,OAAO1E,MAAM,CAAC4E,MAAM,CAAC;MACnBhG,MAAMA,CAACC,OAAe,EAAEC,WAAsC,EAAE;QAC9D,OAAO4F,KAAK,CAACG,UAAU,CAAC,CAAC,CAACC,sBAAsB,CAACjG,OAAO,EAAEC,WAAW,CAAC;MACxE;IACF,CAAC,CAAC;EACJ;AACF;;AAEA;AACO,MAAMiG,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAC1BN,oBAAoB,CAAC,CAAC,IAAI,IAAIhG,sBAAsB,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"CustomTemplates.js","names":["_lodash","require","_isStrictMode","_getV2RuntimeFromDll","allowedNativeProps","Set","CustomTemplateRegistry","registry","Map","isolated","constructor","define","tagName","_constructor$proxy","_compatibleConstructo","registered","has","console","warn","customElements","get","strict","isStrictMode","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","value","Object","entries","asVariable","warnAboutStrictMode","push","mergeProperty","refTransform","error","ref","compatibleConstructor","fromEntries","state","map","item","expose","concat","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","propName","some","defineProperty","getValue","_this$$$tplStateStore2","updateValue","enumerable","from","to","refProperty","_this$$$getElementByR","call","args","refMethod","clearIsolatedRegistry","clear","exports","uniq","getCustomTemplatesV2","v2Kit","getV2RuntimeFromDll","freeze","getRuntime","registerCustomTemplate","customTemplates"],"sources":["../../src/CustomTemplates.ts"],"sourcesContent":["import type {\n ContextConf,\n CustomTemplate,\n CustomTemplateConstructor,\n CustomTemplateProxyBasicProperty,\n} from \"@next-core/types\";\nimport { uniq } from \"lodash\";\nimport type { RuntimeBrickElement } from \"./internal/interfaces.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"./isStrictMode.js\";\nimport { getV2RuntimeFromDll } from \"./getV2RuntimeFromDll.js\";\n\n// Note: `prefix` is a native prop on Element, but it's only used in XML documents.\nconst allowedNativeProps = new Set([\"prefix\"]);\n\ninterface LegacyTplPropProxy extends CustomTemplateProxyBasicProperty {\n asVariable?: boolean;\n mergeProperty?: unknown;\n refTransform?: unknown;\n}\n\nexport class CustomTemplateRegistry {\n readonly #registry = new Map<string, CustomTemplate>();\n readonly #isolated: boolean | undefined;\n\n constructor(isolated?: boolean) {\n this.#isolated = isolated;\n }\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 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 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 const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n Function\n >;\n return 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 clearIsolatedRegistry() {\n if (this.#isolated) {\n this.#registry.clear();\n }\n }\n}\n\nfunction getExposedStates(state: ContextConf[] | undefined): string[] {\n // Allow duplicated state names which maybe mutually exclusive.\n return uniq(\n state?.filter((item) => item.expose).map((item) => item.name) ?? []\n );\n}\n\n// istanbul ignore next\nfunction getCustomTemplatesV2() {\n const v2Kit = getV2RuntimeFromDll();\n if (v2Kit) {\n return Object.freeze({\n define(tagName: string, constructor: CustomTemplateConstructor) {\n return v2Kit.getRuntime().registerCustomTemplate(tagName, constructor);\n },\n }) as CustomTemplateRegistry;\n }\n}\n\n// istanbul ignore next\nexport const customTemplates =\n getCustomTemplatesV2() || new CustomTemplateRegistry();\n"],"mappings":";;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAEA;AACA,MAAMG,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAQvC,MAAMC,sBAAsB,CAAC;EACzB,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAyB,CAAC;EAC7C,CAACC,QAAQ;EAElBC,WAAWA,CAACD,QAAkB,EAAE;IAC9B,IAAI,CAAC,CAACA,QAAQ,GAAGA,QAAQ;EAC3B;EAEAE,MAAMA,CAACC,OAAe,EAAEF,WAAsC,EAAQ;IAAA,IAAAG,kBAAA,EAAAC,qBAAA;IACpE,IAAIC,UAAU,GAAG,IAAI,CAAC,CAACR,QAAQ,CAACS,GAAG,CAACJ,OAAO,CAAC;IAC5C,IAAIG,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAE,OAAO,CAACC,IAAI,CAAC,uBAAuBN,OAAO,uBAAuB,CAAC;IACrE,CAAC,MAAM;MACLG,UAAU,GAAG,CAAC,CAACI,cAAc,CAACC,GAAG,CAACR,OAAO,CAAC;MAC1C,IAAIG,UAAU,EAAE;QACd;QACAE,OAAO,CAACC,IAAI,CACV,uBAAuBN,OAAO,sCAChC,CAAC;MACH;IACF;;IAEA;IACA,MAAMS,MAAM,GAAG,IAAAC,0BAAY,EAAC,CAAC;IAC7B,MAAMC,eAAe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;;AAEA;AACA,SAAS2D,oBAAoBA,CAAA,EAAG;EAC9B,MAAMC,KAAK,GAAG,IAAAC,wCAAmB,EAAC,CAAC;EACnC,IAAID,KAAK,EAAE;IACT,OAAO7E,MAAM,CAAC+E,MAAM,CAAC;MACnBlG,MAAMA,CAACC,OAAe,EAAEF,WAAsC,EAAE;QAC9D,OAAOiG,KAAK,CAACG,UAAU,CAAC,CAAC,CAACC,sBAAsB,CAACnG,OAAO,EAAEF,WAAW,CAAC;MACxE;IACF,CAAC,CAAC;EACJ;AACF;;AAEA;AACO,MAAMsG,eAAe,GAAAR,OAAA,CAAAQ,eAAA,GAC1BN,oBAAoB,CAAC,CAAC,IAAI,IAAIpG,sBAAsB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoryboardFunctionRegistry.js","names":["_cook","require","_supply","_storyboard","_general","_getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","isolatedRoot","collectCoverage","debuggerOverrides","registeredFunctions","Map","overrides","precookFunction","cook","supply","storyboardFunctions","Proxy","Object","freeze","get","_target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","collectMemberUsageInFunction","delete","name","hasPermissionsCheck","perm","has","set","source","typescript","transformed","getGlobalVariables","globals","getGeneralGlobals","isStoryboardFunction","undefined","processed","cooked","collector","createCollector","globalVariables","Function","map","hasOwnProperty","precooked","hooks","beforeVisit","cacheKey","attemptToVisitGlobals","function","rules","noVar","LodashWithStaticFields","_","ArrayConstructor","ObjectWithStaticFields","beforeEvaluate","beforeCall","beforeBranch","debug","updateStoryboardFunction","data","newFn","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some","clearGlobalExecutionContextStack","__dev_only_clearGlobalExecutionContextStack","getGlobalExecutionContextStack","__dev_only_getGlobalExecutionContextStack"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type {\n MicroApp,\n StoryboardFunction,\n TransformedFunction,\n} from \"@next-core/types\";\nimport {\n cook,\n precookFunction,\n EstreeNode,\n __dev_only_clearGlobalExecutionContextStack,\n __dev_only_getGlobalExecutionContextStack,\n} from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { collectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport type _ from \"lodash\";\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\" | \"transformed\"\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 clearGlobalExecutionContextStack(): void;\n getGlobalExecutionContextStack(): ReturnType<\n typeof __dev_only_getGlobalExecutionContextStack\n >;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string> | string[];\n hasPermissionsCheck: boolean;\n transformed?: TransformedFunction;\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\" | \"config\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n isolatedRoot,\n collectCoverage,\n debuggerOverrides,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n isolatedRoot?: symbol;\n collectCoverage?: FunctionCoverageSettings;\n debuggerOverrides?: (ctx: {\n precookFunction: typeof precookFunction;\n cook: typeof cook;\n supply: typeof supply;\n }) => {\n LodashWithStaticFields?: Partial<typeof _>;\n ArrayConstructor?: typeof Array;\n ObjectWithStaticFields?: Partial<typeof Object>;\n };\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n const overrides = debuggerOverrides?.({\n precookFunction,\n cook,\n supply,\n });\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 let deps: Set<string> | string[] | undefined = fn.deps;\n if (deps == null) {\n deps = collectMemberUsageInFunction(fn, \"FN\", !!collectCoverage);\n (deps as Set<string>).delete(fn.name);\n }\n const hasPermissionsCheck =\n fn.perm ??\n collectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\",\n !!collectCoverage\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n transformed: fn.transformed,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getGlobalVariables(globals: Set<string> | string[]) {\n return supply(\n globals,\n getGeneralGlobals(globals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n isolatedRoot,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\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\n // Do not use transformed functions when debugging.\n const transformed = !overrides && !collector && fn.transformed;\n if (transformed) {\n const globalVariables = getGlobalVariables(transformed.globals);\n // Spread globals as params to prevent accessing forbidden globals.\n // NOTE: in native mode, forbidden globals are declared as `undefined`,\n // thus accessing them will not throw a ReferenceError.\n fn.cooked = new Function(\n ...transformed.globals,\n `\"use strict\";return (${transformed.source})`\n )(\n ...transformed.globals.map((key) =>\n hasOwnProperty(globalVariables, key)\n ? globalVariables[key]\n : undefined\n )\n );\n } else {\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n cacheKey: fn,\n });\n const globalVariables = getGlobalVariables(\n precooked.attemptToVisitGlobals\n );\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: overrides\n ? {\n ...globalVariables,\n ...(overrides?.LodashWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"_\")\n ? {\n _: {\n ...(globalVariables._ as typeof _),\n ...overrides.LodashWithStaticFields,\n },\n }\n : null),\n ...(overrides?.ArrayConstructor &&\n precooked.attemptToVisitGlobals.has(\"Array\")\n ? {\n Array: overrides.ArrayConstructor,\n }\n : null),\n ...(overrides?.ObjectWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"Object\")\n ? {\n Object: {\n ...(globalVariables.Object as typeof Object),\n ...overrides.ObjectWithStaticFields,\n },\n }\n : null),\n }\n : globalVariables,\n ArrayConstructor: overrides?.ArrayConstructor,\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n debug: !!debuggerOverrides,\n }) as Function;\n }\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 = collectMemberUsageInFunction(newFn, \"FN\", true);\n const hasPermissionsCheck = collectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\",\n true\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n transformed: data.transformed,\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 clearGlobalExecutionContextStack() {\n __dev_only_clearGlobalExecutionContextStack();\n },\n getGlobalExecutionContextStack() {\n return __dev_only_getGlobalExecutionContextStack();\n },\n };\n}\n"],"mappings":";;;;;;AAKA,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,kBAAA,GAAAJ,OAAA;AAEA;;AAGA;;AAMA;;AAsBA;;AAWA;;AAQA;;AAKA;;AAGA;AACO,SAASK,iCAAiCA,CAAC;EAChDC,QAAQ;EACRC,aAAa;EACbC,YAAY;EACZC,eAAe;EACfC;AAeF,CAAC,GAAG,CAAC,CAAC,EAA8B;EAClC,MAAMC,mBAAmB,GAAG,IAAIC,GAAG,CAAoC,CAAC;EAExE,MAAMC,SAAS,GAAGH,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAG;IACpCI,eAAe,EAA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AAC5C,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAOwC,aAAa,CAACI,IAAI,CAAC5C,mBAAmB,CAAC;IAChD,CAAC;IACD6C,gCAAgCA,CAAA,EAAG;MACjC,IAAAC,iDAA2C,EAAC,CAAC;IAC/C,CAAC;IACDC,8BAA8BA,CAAA,EAAG;MAC/B,OAAO,IAAAC,+CAAyC,EAAC,CAAC;IACpD;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"StoryboardFunctionRegistry.js","names":["_cook","require","_supply","_storyboard","_general","_getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","isolatedRoot","collectCoverage","debuggerOverrides","registeredFunctions","Map","overrides","precookFunction","cook","supply","storyboardFunctions","Proxy","Object","freeze","get","_target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","collectMemberUsageInFunction","delete","name","hasPermissionsCheck","perm","has","set","source","typescript","transformed","getGlobalVariables","globals","getGeneralGlobals","isStoryboardFunction","undefined","processed","cooked","collector","createCollector","globalVariables","Function","map","hasOwnProperty","precooked","hooks","beforeVisit","cacheKey","attemptToVisitGlobals","function","rules","noVar","LodashWithStaticFields","_","ArrayConstructor","ObjectWithStaticFields","beforeEvaluate","beforeCall","beforeBranch","debug","updateStoryboardFunction","data","newFn","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some","clearGlobalExecutionContextStack","__dev_only_clearGlobalExecutionContextStack","getGlobalExecutionContextStack","__dev_only_getGlobalExecutionContextStack"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type {\n MicroApp,\n StoryboardFunction,\n TransformedFunction,\n} from \"@next-core/types\";\nimport {\n cook,\n precookFunction,\n EstreeNode,\n __dev_only_clearGlobalExecutionContextStack,\n __dev_only_getGlobalExecutionContextStack,\n} from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { collectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport type _ from \"lodash\";\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\" | \"transformed\"\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 clearGlobalExecutionContextStack(): void;\n getGlobalExecutionContextStack(): ReturnType<\n typeof __dev_only_getGlobalExecutionContextStack\n >;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string> | string[];\n hasPermissionsCheck: boolean;\n transformed?: TransformedFunction;\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\" | \"config\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n isolatedRoot,\n collectCoverage,\n debuggerOverrides,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n isolatedRoot?: symbol;\n collectCoverage?: FunctionCoverageSettings;\n debuggerOverrides?: (ctx: {\n precookFunction: typeof precookFunction;\n cook: typeof cook;\n supply: typeof supply;\n }) => {\n LodashWithStaticFields?: Partial<typeof _>;\n ArrayConstructor?: typeof Array;\n ObjectWithStaticFields?: Partial<typeof Object>;\n };\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n const overrides = debuggerOverrides?.({\n precookFunction,\n cook,\n supply,\n });\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[] | undefined,\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 let deps: Set<string> | string[] | undefined = fn.deps;\n if (deps == null) {\n deps = collectMemberUsageInFunction(fn, \"FN\", !!collectCoverage);\n (deps as Set<string>).delete(fn.name);\n }\n const hasPermissionsCheck =\n fn.perm ??\n collectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\",\n !!collectCoverage\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n transformed: fn.transformed,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getGlobalVariables(globals: Set<string> | string[]) {\n return supply(\n globals,\n getGeneralGlobals(globals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n isolatedRoot,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\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\n // Do not use transformed functions when debugging.\n const transformed = !overrides && !collector && fn.transformed;\n if (transformed) {\n const globalVariables = getGlobalVariables(transformed.globals);\n // Spread globals as params to prevent accessing forbidden globals.\n // NOTE: in native mode, forbidden globals are declared as `undefined`,\n // thus accessing them will not throw a ReferenceError.\n fn.cooked = new Function(\n ...transformed.globals,\n `\"use strict\";return (${transformed.source})`\n )(\n ...transformed.globals.map((key) =>\n hasOwnProperty(globalVariables, key)\n ? globalVariables[key]\n : undefined\n )\n );\n } else {\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n cacheKey: fn,\n });\n const globalVariables = getGlobalVariables(\n precooked.attemptToVisitGlobals\n );\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: overrides\n ? {\n ...globalVariables,\n ...(overrides?.LodashWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"_\")\n ? {\n _: {\n ...(globalVariables._ as typeof _),\n ...overrides.LodashWithStaticFields,\n },\n }\n : null),\n ...(overrides?.ArrayConstructor &&\n precooked.attemptToVisitGlobals.has(\"Array\")\n ? {\n Array: overrides.ArrayConstructor,\n }\n : null),\n ...(overrides?.ObjectWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"Object\")\n ? {\n Object: {\n ...(globalVariables.Object as typeof Object),\n ...overrides.ObjectWithStaticFields,\n },\n }\n : null),\n }\n : globalVariables,\n ArrayConstructor: overrides?.ArrayConstructor,\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n debug: !!debuggerOverrides,\n }) as Function;\n }\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 = collectMemberUsageInFunction(newFn, \"FN\", true);\n const hasPermissionsCheck = collectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\",\n true\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n transformed: data.transformed,\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 clearGlobalExecutionContextStack() {\n __dev_only_clearGlobalExecutionContextStack();\n },\n getGlobalExecutionContextStack() {\n return __dev_only_getGlobalExecutionContextStack();\n },\n };\n}\n"],"mappings":";;;;;;AAKA,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,kBAAA,GAAAJ,OAAA;AAEA;;AAGA;;AAMA;;AAsBA;;AAWA;;AAQA;;AAKA;;AAGA;AACO,SAASK,iCAAiCA,CAAC;EAChDC,QAAQ;EACRC,aAAa;EACbC,YAAY;EACZC,eAAe;EACfC;AAeF,CAAC,GAAG,CAAC,CAAC,EAA8B;EAClC,MAAMC,mBAAmB,GAAG,IAAIC,GAAG,CAAoC,CAAC;EAExE,MAAMC,SAAS,GAAGH,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAG;IACpCI,eAAe,EAAfA,qBAAe;IACfC,IAAI,EAAJA,UAAI;IACJC,MAAM,EAANA;EACF,CAAC,CAAC;;EAEF;EACA,MAAMC,mBAAmB,GAAG,IAAIC,KAAK,CAACC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;IAC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A2C,EAAC,CAAC;IAC/C,CAAC;IACDC,8BAA8BA,CAAA,EAAG;MAC/B,OAAO,IAAAC,+CAAyC,EAAC,CAAC;IACpD;EACF,CAAC;AACH","ignoreList":[]}
|
package/dist/cjs/createRoot.js
CHANGED
|
@@ -19,6 +19,7 @@ var _registerCustomTemplates = require("./internal/registerCustomTemplates.js");
|
|
|
19
19
|
var _setUIVersion = require("./setUIVersion.js");
|
|
20
20
|
var _ErrorNode = require("./internal/ErrorNode.js");
|
|
21
21
|
var _IsolatedFunctions = require("./internal/compute/IsolatedFunctions.js");
|
|
22
|
+
var _IsolatedTemplates = require("./internal/IsolatedTemplates.js");
|
|
22
23
|
function unstable_createRoot(container, {
|
|
23
24
|
portal: _portal,
|
|
24
25
|
scope = "fragment",
|
|
@@ -128,7 +129,8 @@ function unstable_createRoot(container, {
|
|
|
128
129
|
// Register functions.
|
|
129
130
|
(0, _StoryboardFunctions.registerStoryboardFunctions)(functions, app);
|
|
130
131
|
} else {
|
|
131
|
-
(0,
|
|
132
|
+
(0, _IsolatedTemplates.registerIsolatedTemplates)(isolatedRoot, templates);
|
|
133
|
+
(0, _IsolatedFunctions.registerIsolatedFunctions)(isolatedRoot, functions);
|
|
132
134
|
}
|
|
133
135
|
runtimeContext.ctxStore.define(context, runtimeContext);
|
|
134
136
|
let failed = false;
|
|
@@ -184,6 +186,7 @@ function unstable_createRoot(container, {
|
|
|
184
186
|
unmounted = true;
|
|
185
187
|
if (isolatedRoot) {
|
|
186
188
|
_IsolatedFunctions.isolatedFunctionRegistry.delete(isolatedRoot);
|
|
189
|
+
_IsolatedTemplates.isolatedTemplateRegistryMap.delete(isolatedRoot);
|
|
187
190
|
}
|
|
188
191
|
(0, _mount.unmountTree)(container);
|
|
189
192
|
if (portal) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoot.js","names":["_i18n","require","_storyboard","_lodash","_Renderer","_RendererContext","_DataStore","_mount","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","_setUIVersion","_ErrorNode","_IsolatedFunctions","unstable_createRoot","container","portal","_portal","scope","unknownBricks","supportsUseChildren","unsafe_penetrate","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","isolatedRoot","undefined","Symbol","render","brick","theme","uiVersion","language","context","functions","templates","i18n","i18nData","url","app","Error","bricks","concat","replaceUseChildren","template","Array","isArray","previousRendererContext","renderId","uniqueId","RendererContext","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","urlObj","URL","query","searchParams","location","pathname","search","hash","state","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","setTheme","setMode","setUIVersion","changeLanguage","id","homepage","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","registerIsolatedFunctions","define","failed","output","stores","renderBricks","getDataStores","postAsyncRender","error","node","ErrorNode","blockingList","child","dispatchOnUnmount","dispose","unmountTree","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","store","mountAsyncData","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmount","isolatedFunctionRegistry","delete","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 { i18n } from \"@next-core/i18n\";\nimport { replaceUseChildren } from \"@next-core/utils/storyboard\";\nimport { uniqueId } from \"lodash\";\nimport {\n RenderOutput,\n getDataStores,\n postAsyncRender,\n renderBricks,\n} from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\nimport { setUIVersion } from \"./setUIVersion.js\";\nimport { ErrorNode } from \"./internal/ErrorNode.js\";\nimport {\n isolatedFunctionRegistry,\n registerIsolatedFunctions,\n} from \"./internal/compute/IsolatedFunctions.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 /**\n * Whether the root supports `useChildren`.\n */\n supportsUseChildren?: boolean;\n\n /**\n * Set unsafe_penetrate to true to allow accessing global variables\n * from an isolated root.\n *\n * It is unsafe, use it at your own risk.\n */\n unsafe_penetrate?: boolean;\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n uiVersion?: string;\n language?: string;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n url?: string;\n app?: MicroApp;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement | DocumentFragment,\n {\n portal: _portal,\n scope = \"fragment\",\n unknownBricks,\n supportsUseChildren,\n unsafe_penetrate,\n }: 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 const isolatedRoot = scope === \"page\" ? undefined : Symbol(\"IsolatedRoot\");\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n uiVersion,\n language,\n context,\n functions,\n templates,\n i18n: i18nData,\n url,\n app,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n\n if (supportsUseChildren) {\n replaceUseChildren(bricks);\n\n for (const template of templates ?? []) {\n if (Array.isArray(template.bricks)) {\n replaceUseChildren(template.bricks);\n }\n }\n }\n\n const previousRendererContext = rendererContext;\n const renderId = uniqueId(\"render-id-\");\n rendererContext = new RendererContext(scope, { unknownBricks, renderId });\n\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\", undefined, rendererContext),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n isolatedRoot,\n unsafe_penetrate,\n } as Partial<RuntimeContext> as RuntimeContext;\n\n if (url) {\n const urlObj = new URL(url);\n runtimeContext.query = urlObj.searchParams;\n runtimeContext.location = {\n pathname: urlObj.pathname,\n search: urlObj.search,\n hash: urlObj.hash,\n state: undefined,\n };\n }\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n setUIVersion(uiVersion);\n if (language) {\n await i18n.changeLanguage(language);\n }\n\n app ??= {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = app;\n const demoStoryboard = {\n app,\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, app);\n } else {\n registerIsolatedFunctions(isolatedRoot!, functions ?? []);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n let stores: DataStore<\"CTX\" | \"STATE\" | \"FORM_STATE\">[] = [];\n\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext,\n [],\n {}\n );\n\n stores = getDataStores(runtimeContext);\n await postAsyncRender(output, runtimeContext, stores);\n } catch (error) {\n failed = true;\n output = {\n node: await ErrorNode(error, renderRoot, scope === \"page\"),\n blockingList: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n for (const store of stores) {\n store.mountAsyncData();\n }\n\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n if (isolatedRoot) {\n isolatedFunctionRegistry.delete(isolatedRoot);\n }\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,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAMA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAA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UACpBc,eAAe,CAACqF,gBAAgB,CAAC,CAAC;UAClC;QACF;QACArF,eAAe,CAACsF,eAAe,CAAC,CAAC;QACjCtF,eAAe,CAACuF,wBAAwB,CAAC,CAAC;QAC1CvF,eAAe,CAACwF,qBAAqB,CAAC,CAAC;QACvCxF,eAAe,CAACyF,2BAA2B,CAAC,CAAC;MAC/C;IACF,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI3F,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAIG,YAAY,EAAE;QAChByF,2CAAwB,CAACC,MAAM,CAAC1F,YAAY,CAAC;MAC/C;MACA,IAAA0E,kBAAW,EAAC7F,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAA4F,kBAAW,EAAC5F,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC6G,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"createRoot.js","names":["_i18n","require","_storyboard","_lodash","_Renderer","_RendererContext","_DataStore","_mount","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","_setUIVersion","_ErrorNode","_IsolatedFunctions","_IsolatedTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","supportsUseChildren","unsafe_penetrate","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","isolatedRoot","undefined","Symbol","render","brick","theme","uiVersion","language","context","functions","templates","i18n","i18nData","url","app","Error","bricks","concat","replaceUseChildren","template","Array","isArray","previousRendererContext","renderId","uniqueId","RendererContext","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","formStateStoreMap","urlObj","URL","query","searchParams","location","pathname","search","hash","state","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","setTheme","setMode","setUIVersion","changeLanguage","id","homepage","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","registerIsolatedTemplates","registerIsolatedFunctions","define","failed","output","stores","renderBricks","getDataStores","postAsyncRender","error","node","ErrorNode","blockingList","child","dispatchOnUnmount","dispose","unmountTree","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","store","mountAsyncData","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","initializeMessageDispatcher","unmount","isolatedFunctionRegistry","delete","isolatedTemplateRegistryMap","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 { i18n } from \"@next-core/i18n\";\nimport { replaceUseChildren } from \"@next-core/utils/storyboard\";\nimport { uniqueId } from \"lodash\";\nimport {\n RenderOutput,\n getDataStores,\n postAsyncRender,\n renderBricks,\n} from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\nimport { setUIVersion } from \"./setUIVersion.js\";\nimport { ErrorNode } from \"./internal/ErrorNode.js\";\nimport {\n isolatedFunctionRegistry,\n registerIsolatedFunctions,\n} from \"./internal/compute/IsolatedFunctions.js\";\nimport {\n isolatedTemplateRegistryMap,\n registerIsolatedTemplates,\n} from \"./internal/IsolatedTemplates.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 /**\n * Whether the root supports `useChildren`.\n */\n supportsUseChildren?: boolean;\n\n /**\n * Set unsafe_penetrate to true to allow accessing global variables\n * from an isolated root.\n *\n * It is unsafe, use it at your own risk.\n */\n unsafe_penetrate?: boolean;\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n uiVersion?: string;\n language?: string;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n url?: string;\n app?: MicroApp;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement | DocumentFragment,\n {\n portal: _portal,\n scope = \"fragment\",\n unknownBricks,\n supportsUseChildren,\n unsafe_penetrate,\n }: 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 const isolatedRoot = scope === \"page\" ? undefined : Symbol(\"IsolatedRoot\");\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n uiVersion,\n language,\n context,\n functions,\n templates,\n i18n: i18nData,\n url,\n app,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n\n if (supportsUseChildren) {\n replaceUseChildren(bricks);\n\n for (const template of templates ?? []) {\n if (Array.isArray(template.bricks)) {\n replaceUseChildren(template.bricks);\n }\n }\n }\n\n const previousRendererContext = rendererContext;\n const renderId = uniqueId(\"render-id-\");\n rendererContext = new RendererContext(scope, { unknownBricks, renderId });\n\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\", undefined, rendererContext),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n formStateStoreMap: new Map<string, DataStore<\"FORM_STATE\">>(),\n isolatedRoot,\n unsafe_penetrate,\n } as Partial<RuntimeContext> as RuntimeContext;\n\n if (url) {\n const urlObj = new URL(url);\n runtimeContext.query = urlObj.searchParams;\n runtimeContext.location = {\n pathname: urlObj.pathname,\n search: urlObj.search,\n hash: urlObj.hash,\n state: undefined,\n };\n }\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n setTheme(theme ?? \"light\");\n setMode(\"default\");\n setUIVersion(uiVersion);\n if (language) {\n await i18n.changeLanguage(language);\n }\n\n app ??= {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = app;\n const demoStoryboard = {\n app,\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, app);\n } else {\n registerIsolatedTemplates(isolatedRoot!, templates);\n registerIsolatedFunctions(isolatedRoot!, functions);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\n\n let failed = false;\n let output: RenderOutput;\n let stores: DataStore<\"CTX\" | \"STATE\" | \"FORM_STATE\">[] = [];\n\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext,\n [],\n {}\n );\n\n stores = getDataStores(runtimeContext);\n await postAsyncRender(output, runtimeContext, stores);\n } catch (error) {\n failed = true;\n output = {\n node: await ErrorNode(error, renderRoot, scope === \"page\"),\n blockingList: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n for (const store of stores) {\n store.mountAsyncData();\n }\n\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n rendererContext.initializeMessageDispatcher();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n if (isolatedRoot) {\n isolatedFunctionRegistry.delete(isolatedRoot);\n isolatedTemplateRegistryMap.delete(isolatedRoot);\n }\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,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAMA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,oBAAA,GAAAT,OAAA;AACA,IAAAU,gBAAA,GAAAV,OAAA;AACA,IAAAW,wBAAA,GAAAX,OAAA;AACA,IAAAY,aAAA,GAAAZ,OAAA;AACA,IAAAa,UAAA,GAAAb,OAAA;AACA,IAAAc,kBAAA,GAAAd,OAAA;AAI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DC,OAAOA,CAAA,EAAG;MACR,IAAI5F,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAIG,YAAY,EAAE;QAChB0F,2CAAwB,CAACC,MAAM,CAAC3F,YAAY,CAAC;QAC7C4F,8CAA2B,CAACD,MAAM,CAAC3F,YAAY,CAAC;MAClD;MACA,IAAA2E,kBAAW,EAAC9F,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAA6F,kBAAW,EAAC7F,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAAC+G,MAAM,CAAC,CAAC;QACjB;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
var _exportNames = {
|
|
8
|
+
customTemplates: true,
|
|
8
9
|
createRuntime: true,
|
|
9
10
|
getRuntime: true,
|
|
10
11
|
__secret_internals: true,
|
|
@@ -80,6 +81,12 @@ Object.defineProperty(exports, "createRuntime", {
|
|
|
80
81
|
return _Runtime.createRuntime;
|
|
81
82
|
}
|
|
82
83
|
});
|
|
84
|
+
Object.defineProperty(exports, "customTemplates", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _CustomTemplates.customTemplates;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
83
90
|
Object.defineProperty(exports, "getCssPropertyValue", {
|
|
84
91
|
enumerable: true,
|
|
85
92
|
get: function () {
|
|
@@ -171,17 +178,6 @@ Object.keys(_CustomProcessors).forEach(function (key) {
|
|
|
171
178
|
});
|
|
172
179
|
});
|
|
173
180
|
var _CustomTemplates = require("./CustomTemplates.js");
|
|
174
|
-
Object.keys(_CustomTemplates).forEach(function (key) {
|
|
175
|
-
if (key === "default" || key === "__esModule") return;
|
|
176
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
177
|
-
if (key in exports && exports[key] === _CustomTemplates[key]) return;
|
|
178
|
-
Object.defineProperty(exports, key, {
|
|
179
|
-
enumerable: true,
|
|
180
|
-
get: function () {
|
|
181
|
-
return _CustomTemplates[key];
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
181
|
var _fetchByProvider = require("./fetchByProvider.js");
|
|
186
182
|
Object.keys(_fetchByProvider).forEach(function (key) {
|
|
187
183
|
if (key === "default" || key === "__esModule") return;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_auth","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_CustomEditors","_CustomProcessors","_CustomTemplates","_fetchByProvider","_getBasePath","_getPageInfo","_handleHttpError","_history","_createRoot","_getRealValue","_Runtime","__secret_internals","_interopRequireWildcard","_test_only","_themeAndMode","_checkIf","_WidgetFunctions","_WidgetI18n","_StoryboardFunctionRegistry","_matchPath","_Notification","_Dialog","_getV2RuntimeFromDll","_setUIVersion","_ModalStack","_isNetworkError","_shouldReloadForError"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./auth.js\";\nexport * from \"./CustomEditors.js\";\nexport * from \"./CustomProcessors.js\";\nexport
|
|
1
|
+
{"version":3,"file":"index.js","names":["_auth","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_CustomEditors","_CustomProcessors","_CustomTemplates","_fetchByProvider","_getBasePath","_getPageInfo","_handleHttpError","_history","_createRoot","_getRealValue","_Runtime","__secret_internals","_interopRequireWildcard","_test_only","_themeAndMode","_checkIf","_WidgetFunctions","_WidgetI18n","_StoryboardFunctionRegistry","_matchPath","_Notification","_Dialog","_getV2RuntimeFromDll","_setUIVersion","_ModalStack","_isNetworkError","_shouldReloadForError"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./auth.js\";\nexport * from \"./CustomEditors.js\";\nexport * from \"./CustomProcessors.js\";\nexport { customTemplates } from \"./CustomTemplates.js\";\nexport * from \"./fetchByProvider.js\";\nexport * from \"./getBasePath.js\";\nexport * from \"./getPageInfo.js\";\nexport * from \"./handleHttpError.js\";\nexport * from \"./history.js\";\nexport * from \"./createRoot.js\";\nexport * from \"./getRealValue.js\";\nexport {\n createRuntime,\n getRuntime,\n type RuntimeOptions,\n type RuntimeHooks,\n type RuntimeHooksMenuHelpers,\n type ImagesFactory,\n type PageViewInfo,\n} from \"./internal/Runtime.js\";\nimport * as __secret_internals from \"./internal/secret_internals.js\";\nexport { __secret_internals };\nexport { __test_only } from \"./internal/test_only.js\";\nexport {\n getCssPropertyValue,\n getCurrentTheme,\n getCurrentMode,\n getThemeVariant,\n batchSetAppsLocalTheme,\n applyTheme,\n} from \"./themeAndMode.js\";\nexport {\n checkIfOfComputed,\n checkIfByTransform,\n} from \"./internal/compute/checkIf.js\";\nexport { registerWidgetFunctions } from \"./internal/compute/WidgetFunctions.js\";\nexport { registerWidgetI18n } from \"./internal/compute/WidgetI18n.js\";\nexport { StoryboardFunctionRegistryFactory } from \"./StoryboardFunctionRegistry.js\";\nexport { matchPath, type MatchOptions } from \"./internal/matchPath.js\";\nexport { Notification, type NotificationOptions } from \"./Notification.js\";\nexport { Dialog, type DialogOptions } from \"./Dialog.js\";\nexport * from \"./getV2RuntimeFromDll.js\";\nexport { setUIVersion } from \"./setUIVersion.js\";\nexport * from \"./ModalStack.js\";\nexport * from \"./isNetworkError.js\";\nexport * from \"./shouldReloadForError.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,O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AAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAA0B,eAAA,CAAAlC,GAAA;IAAA;EAAA;AAAA;AACA,IAAAmC,qBAAA,GAAAvC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAqC,qBAAA,EAAApC,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAmC,qBAAA,CAAAnC,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAA2B,qBAAA,CAAAnC,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -12,6 +12,7 @@ var _setupUseBrickInTemplate = require("./setupUseBrickInTemplate.js");
|
|
|
12
12
|
var _Renderer = require("../Renderer.js");
|
|
13
13
|
var _Runtime = require("../Runtime.js");
|
|
14
14
|
var _replaceSlotWithSlottedBricks = require("./replaceSlotWithSlottedBricks.js");
|
|
15
|
+
var _IsolatedTemplates = require("../IsolatedTemplates.js");
|
|
15
16
|
function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
|
|
16
17
|
var _hooks$flowApi;
|
|
17
18
|
const tplStateStoreId = (0, _lodash.uniqueId)("tpl-state-");
|
|
@@ -35,7 +36,7 @@ function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropert
|
|
|
35
36
|
proxy,
|
|
36
37
|
state,
|
|
37
38
|
contracts
|
|
38
|
-
} = _CustomTemplates.customTemplates.get(tplTagName);
|
|
39
|
+
} = hostBrick.runtimeContext.isolatedRoot ? _IsolatedTemplates.isolatedTemplateRegistryMap.get(hostBrick.runtimeContext.isolatedRoot).get(tplTagName) : _CustomTemplates.customTemplates.get(tplTagName);
|
|
39
40
|
_Runtime.hooks === null || _Runtime.hooks === void 0 || (_hooks$flowApi = _Runtime.hooks.flowApi) === null || _hooks$flowApi === void 0 || _hooks$flowApi.collectWidgetContract(contracts);
|
|
40
41
|
tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);
|
|
41
42
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","_replaceSlotWithSlottedBricks","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","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","usedSlots","Set","type","flatMap","item","expandBrickInTemplate","brickConfInTemplate","markSlotted","if","replaceSlotWithSlottedBricks","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","slotted","markChild","fromEntries","map","slotName","slotConf","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotConfOfBricks,\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 { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\nimport { replaceSlotWithSlottedBricks } from \"./replaceSlotWithSlottedBricks.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n usedSlots: new Set(),\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.flatMap((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConf,\n hostContext: TemplateHostContext,\n markSlotted?: () => void\n): BrickConf | BrickConf[] {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n\n if (brickConfInTemplate.brick === \"slot\") {\n markSlotted?.();\n return replaceSlotWithSlottedBricks(\n brickConfInTemplate,\n hostContext,\n expandBrickInTemplate\n );\n }\n\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate as BrickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n let slotted = false;\n const markChild = () => {\n slotted = true;\n };\n const slots = Object.fromEntries<SlotConfOfBricks>(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).flatMap((item) =>\n expandBrickInTemplate(item, hostContext, markChild)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(\n hostContext,\n restBrickConfInTemplate.ref,\n slots,\n slotted\n ),\n };\n}\n"],"mappings":";;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAEA,IAAAO,6BAAA,GAAAP,OAAA;AAEO,SAASQ,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN,SAAS,CAACM,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,WAAW;EACjC,OAAOH,cAAc,CAACI,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIC,oBAAS,CACjC,OAAO,EACPZ,SAAS,EACTE,eAAe,EACfE,eACF,CAAC;EACDE,cAAc,CAACO,gBAAgB,CAACC,GAAG,CAACV,eAAe,EAAEO,aAAa,CAAC;EACnE,IAAIL,cAAc,CAACS,kBAAkB,EAAE;IACrCT,cAAc,CAACS,kBAAkB,CAACC,IAAI,CAACL,aAAa,CAAC;EACvD;EAEA,MAAM;IAAEM,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAGC,gCAAe,CAACC,GAAG,CAACxB,UAAU,CAAE;EAC5Ey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,EAAE8B,kBAAkB;IAC5B,GAAGC;EACL,CAAC,GAAGN,mBAA0C;EAE9C,MAAMO,eAAe,GAAG,IAAAd,yBAAe,EACrCY,kBAAkB,EAClBD,eACF,CAAoC;EAEpC,IAAII,OAAO,GAAG,KAAK;EACnB,MAAMC,SAAS,GAAGA,CAAA,KAAM;IACtBD,OAAO,GAAG,IAAI;EAChB,CAAC;EACD,MAAMnC,KAAK,GAAGc,MAAM,CAACuB,WAAW,CAC9BvB,MAAM,CAACC,OAAO,CAACmB,eAAe,IAAI,CAAC,CAAC,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,QAAQ,EAAEC,QAAQ,CAAC,KAAK,CAClED,QAAQ,EACR;IACEhB,IAAI,EAAE,QAAQ;IACdjC,MAAM,EAAE,CAACkD,QAAQ,CAAClD,MAAM,IAAI,EAAE,EAAEkC,OAAO,CAAEC,IAAI,IAC3CC,qBAAqB,CAACD,IAAI,EAAEP,WAAW,EAAEkB,SAAS,CACpD;EACF,CAAC,CACF,CACH,CAAC;EAED,OAAO;IACL,GAAGH,uBAAuB;IAC1BtB,UAAU,EAAE,IAAA8B,gDAAuB,EAAC9B,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAA0C,sCAAkB,EACnBxB,WAAW,EACXe,uBAAuB,CAAChB,GAAG,EAC3BjB,KAAK,EACLmC,OACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","_replaceSlotWithSlottedBricks","_IsolatedTemplates","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","isolatedRoot","isolatedTemplateRegistryMap","get","customTemplates","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","usedSlots","Set","type","flatMap","item","expandBrickInTemplate","brickConfInTemplate","markSlotted","if","replaceSlotWithSlottedBricks","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","slotted","markChild","fromEntries","map","slotName","slotConf","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotConfOfBricks,\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 { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\nimport { replaceSlotWithSlottedBricks } from \"./replaceSlotWithSlottedBricks.js\";\nimport { isolatedTemplateRegistryMap } from \"../IsolatedTemplates.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = hostBrick.runtimeContext\n .isolatedRoot\n ? isolatedTemplateRegistryMap\n .get(hostBrick.runtimeContext.isolatedRoot)!\n .get(tplTagName)!\n : customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n usedSlots: new Set(),\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.flatMap((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConf,\n hostContext: TemplateHostContext,\n markSlotted?: () => void\n): BrickConf | BrickConf[] {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n\n if (brickConfInTemplate.brick === \"slot\") {\n markSlotted?.();\n return replaceSlotWithSlottedBricks(\n brickConfInTemplate,\n hostContext,\n expandBrickInTemplate\n );\n }\n\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate as BrickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n let slotted = false;\n const markChild = () => {\n slotted = true;\n };\n const slots = Object.fromEntries<SlotConfOfBricks>(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).flatMap((item) =>\n expandBrickInTemplate(item, hostContext, markChild)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(\n hostContext,\n restBrickConfInTemplate.ref,\n slots,\n slotted\n ),\n };\n}\n"],"mappings":";;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAEA,IAAAO,6BAAA,GAAAP,OAAA;AACA,IAA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AACuB,WAAW,CAC9BvB,MAAM,CAACC,OAAO,CAACmB,eAAe,IAAI,CAAC,CAAC,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,QAAQ,EAAEC,QAAQ,CAAC,KAAK,CAClED,QAAQ,EACR;IACEhB,IAAI,EAAE,QAAQ;IACdnC,MAAM,EAAE,CAACoD,QAAQ,CAACpD,MAAM,IAAI,EAAE,EAAEoC,OAAO,CAAEC,IAAI,IAC3CC,qBAAqB,CAACD,IAAI,EAAEP,WAAW,EAAEkB,SAAS,CACpD;EACF,CAAC,CACF,CACH,CAAC;EAED,OAAO;IACL,GAAGH,uBAAuB;IAC1BtB,UAAU,EAAE,IAAA8B,gDAAuB,EAAC9B,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAA0C,sCAAkB,EACnBxB,WAAW,EACXe,uBAAuB,CAAChB,GAAG,EAC3BjB,KAAK,EACLmC,OACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ exports.getTagNameOfCustomTemplate = getTagNameOfCustomTemplate;
|
|
|
7
7
|
exports.getTplHostElement = getTplHostElement;
|
|
8
8
|
exports.getTplStateStore = getTplStateStore;
|
|
9
9
|
var _CustomTemplates = require("../../CustomTemplates.js");
|
|
10
|
+
var _IsolatedTemplates = require("../IsolatedTemplates.js");
|
|
10
11
|
function getTplStateStore({
|
|
11
12
|
tplStateStoreId,
|
|
12
13
|
tplStateStoreMap
|
|
@@ -28,10 +29,18 @@ function getTplHostElement(runtimeContext, using, extraInfo) {
|
|
|
28
29
|
}
|
|
29
30
|
return hostElement;
|
|
30
31
|
}
|
|
31
|
-
function getTagNameOfCustomTemplate(brick,
|
|
32
|
+
function getTagNameOfCustomTemplate(brick, runtimeContext) {
|
|
33
|
+
if (runtimeContext.isolatedRoot) {
|
|
34
|
+
const registry = _IsolatedTemplates.isolatedTemplateRegistryMap.get(runtimeContext.isolatedRoot);
|
|
35
|
+
if (registry !== null && registry !== void 0 && registry.get(brick)) {
|
|
36
|
+
return brick;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
// When a template is registered by an app, it's namespace maybe missed.
|
|
33
|
-
if (!brick.includes(".") && brick.startsWith("tpl-") &&
|
|
34
|
-
const tagName = `${
|
|
42
|
+
if (!brick.includes(".") && brick.startsWith("tpl-") && runtimeContext.app) {
|
|
43
|
+
const tagName = `${runtimeContext.app.id}.${brick}`;
|
|
35
44
|
if (_CustomTemplates.customTemplates.get(tagName)) {
|
|
36
45
|
return tagName;
|
|
37
46
|
}
|
|
@@ -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","
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_CustomTemplates","require","_IsolatedTemplates","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","isolatedRoot","registry","isolatedTemplateRegistryMap","includes","startsWith","app","tagName","id","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\";\nimport { isolatedTemplateRegistryMap } from \"../IsolatedTemplates.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 runtimeContext: Pick<RuntimeContext, \"app\" | \"isolatedRoot\">\n): false | string {\n if (runtimeContext.isolatedRoot) {\n const registry = isolatedTemplateRegistryMap.get(\n runtimeContext.isolatedRoot\n );\n if (registry?.get(brick)) {\n return brick;\n }\n return false;\n }\n\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && runtimeContext.app) {\n const tagName = `${runtimeContext.app.id}.${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;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAOO,SAASE,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACb,UAAUF,KAAK,iCAAiCC,SAAS,IAAI,EAAE,EACjE,CAAC;EACH;EACA,MAAME,KAAK,GAAGJ,gBAAgB,CAACK,GAAG,CAACN,eAAe,CAAC;EACnD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACb,iDAAiDF,KAAK,IACpDC,SAAS,IAAI,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
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isolatedTemplateRegistryMap = void 0;
|
|
7
|
+
exports.registerIsolatedTemplates = registerIsolatedTemplates;
|
|
8
|
+
var _CustomTemplates = require("../CustomTemplates.js");
|
|
9
|
+
const isolatedTemplateRegistryMap = exports.isolatedTemplateRegistryMap = new Map();
|
|
10
|
+
function registerIsolatedTemplates(isolatedRoot, templates) {
|
|
11
|
+
let registry = isolatedTemplateRegistryMap.get(isolatedRoot);
|
|
12
|
+
if (!registry) {
|
|
13
|
+
registry = new _CustomTemplates.CustomTemplateRegistry(true);
|
|
14
|
+
isolatedTemplateRegistryMap.set(isolatedRoot, registry);
|
|
15
|
+
}
|
|
16
|
+
registry.clearIsolatedRegistry();
|
|
17
|
+
if (Array.isArray(templates)) {
|
|
18
|
+
for (const tpl of templates) {
|
|
19
|
+
registry.define(tpl.name, tpl);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=IsolatedTemplates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsolatedTemplates.js","names":["_CustomTemplates","require","isolatedTemplateRegistryMap","exports","Map","registerIsolatedTemplates","isolatedRoot","templates","registry","get","CustomTemplateRegistry","set","clearIsolatedRegistry","Array","isArray","tpl","define","name"],"sources":["../../../src/internal/IsolatedTemplates.ts"],"sourcesContent":["import type { CustomTemplate } from \"@next-core/types\";\nimport { CustomTemplateRegistry } from \"../CustomTemplates.js\";\n\nexport const isolatedTemplateRegistryMap = new Map<\n symbol,\n CustomTemplateRegistry\n>();\n\nexport function registerIsolatedTemplates(\n isolatedRoot: symbol,\n templates: CustomTemplate[] | undefined\n) {\n let registry = isolatedTemplateRegistryMap.get(isolatedRoot);\n if (!registry) {\n registry = new CustomTemplateRegistry(true);\n isolatedTemplateRegistryMap.set(isolatedRoot, registry);\n }\n registry.clearIsolatedRegistry();\n if (Array.isArray(templates)) {\n for (const tpl of templates) {\n registry.define(tpl.name, tpl);\n }\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,gBAAA,GAAAC,OAAA;AAEO,MAAMC,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,IAAIE,GAAG,CAGhD,CAAC;AAEI,SAASC,yBAAyBA,CACvCC,YAAoB,EACpBC,SAAuC,EACvC;EACA,IAAIC,QAAQ,GAAGN,2BAA2B,CAACO,GAAG,CAACH,YAAY,CAAC;EAC5D,IAAI,CAACE,QAAQ,EAAE;IACbA,QAAQ,GAAG,IAAIE,uCAAsB,CAAC,IAAI,CAAC;IAC3CR,2BAA2B,CAACS,GAAG,CAACL,YAAY,EAAEE,QAAQ,CAAC;EACzD;EACAA,QAAQ,CAACI,qBAAqB,CAAC,CAAC;EAChC,IAAIC,KAAK,CAACC,OAAO,CAACP,SAAS,CAAC,EAAE;IAC5B,KAAK,MAAMQ,GAAG,IAAIR,SAAS,EAAE;MAC3BC,QAAQ,CAACQ,MAAM,CAACD,GAAG,CAACE,IAAI,EAAEF,GAAG,CAAC;IAChC;EACF;AACF","ignoreList":[]}
|
|
@@ -148,7 +148,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendererContext, parentRoutes, menuRequestReturnNode, slotId, tplStack, initialTracker) {
|
|
151
|
-
var _hooks$checkPermissio2
|
|
151
|
+
var _hooks$checkPermissio2;
|
|
152
152
|
const output = getEmptyRenderOutput();
|
|
153
153
|
if (!brickConf.brick) {
|
|
154
154
|
if (brickConf.template) {
|
|
@@ -415,7 +415,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
415
415
|
if (/\.tpl-/.test(brickName) && !_CustomTemplates.customTemplates.get(brickName)) {
|
|
416
416
|
await catchLoad((0, _loader.loadBricksImperatively)([brickName], (0, _Runtime.getBrickPackages)()), "brick", brickName, rendererContext.unknownBricks);
|
|
417
417
|
}
|
|
418
|
-
const tplTagName = (0, _utils.getTagNameOfCustomTemplate)(brickName,
|
|
418
|
+
const tplTagName = (0, _utils.getTagNameOfCustomTemplate)(brickName, runtimeContext);
|
|
419
419
|
if (tplTagName) {
|
|
420
420
|
const tplCount = tplStack.get(tplTagName) ?? 0;
|
|
421
421
|
if (tplCount >= 10) {
|