@next-core/runtime 1.49.12 → 1.50.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/internal/CustomTemplates/constants.js +2 -1
- package/dist/cjs/internal/CustomTemplates/constants.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/setupTemplateProxy.js +11 -9
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/FormRenderer/expandFormRenderer.js +2 -1
- package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -1
- package/dist/cjs/internal/Renderer.js +8 -5
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/compute/evaluate.js +2 -1
- package/dist/cjs/internal/compute/evaluate.js.map +1 -1
- package/dist/cjs/internal/interfaces.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/constants.js +1 -0
- package/dist/esm/internal/CustomTemplates/constants.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/setupTemplateProxy.js +12 -10
- package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/esm/internal/FormRenderer/expandFormRenderer.js +2 -1
- package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -1
- package/dist/esm/internal/Renderer.js +9 -6
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/compute/evaluate.js +2 -1
- package/dist/esm/internal/compute/evaluate.js.map +1 -1
- package/dist/esm/internal/interfaces.js.map +1 -1
- package/dist/types/internal/CustomTemplates/constants.d.ts +2 -0
- package/dist/types/internal/interfaces.d.ts +1 -0
- package/package.json +10 -10
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.symbolForTplStateStoreId = exports.symbolForTPlExternalNoForEach = exports.symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachIndex = exports.symbolForAsyncComputedPropsFromHost = void 0;
|
|
6
|
+
exports.symbolForTplStateStoreId = exports.symbolForTPlExternalNoForEach = exports.symbolForTPlExternalForEachSize = exports.symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachIndex = exports.symbolForAsyncComputedPropsFromHost = void 0;
|
|
7
7
|
const symbolForAsyncComputedPropsFromHost = exports.symbolForAsyncComputedPropsFromHost = Symbol.for("tpl.asyncComputedPropsFromHost");
|
|
8
8
|
const symbolForTplStateStoreId = exports.symbolForTplStateStoreId = Symbol.for("tpl.stateStoreId");
|
|
9
9
|
const symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachItem = Symbol.for("tpl.externalForEachItem");
|
|
10
10
|
const symbolForTPlExternalForEachIndex = exports.symbolForTPlExternalForEachIndex = Symbol.for("tpl.externalForEachIndex");
|
|
11
|
+
const symbolForTPlExternalForEachSize = exports.symbolForTPlExternalForEachSize = Symbol.for("tpl.externalForEachSize");
|
|
11
12
|
const symbolForTPlExternalNoForEach = exports.symbolForTPlExternalNoForEach = Symbol.for("tpl.externalNoForEach");
|
|
12
13
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","exports","Symbol","for","symbolForTplStateStoreId","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex","symbolForTPlExternalNoForEach"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncPropertyEntry } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\nexport const symbolForTPlExternalForEachIndex = Symbol.for(\n \"tpl.externalForEachIndex\"\n);\nexport const symbolForTPlExternalNoForEach = Symbol.for(\n \"tpl.externalNoForEach\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n [symbolForTPlExternalForEachIndex]?: number;\n [symbolForTPlExternalNoForEach]?: boolean;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAAC,OAAA,CAAAD,mCAAA,GAAGE,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AACM,MAAMC,wBAAwB,GAAAH,OAAA,CAAAG,wBAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAC/D,MAAME,+BAA+B,GAAAJ,OAAA,CAAAI,+BAAA,GAAGH,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AACM,MAAMG,gCAAgC,GAAAL,OAAA,CAAAK,gCAAA,GAAGJ,MAAM,CAACC,GAAG,CACxD,0BACF,CAAC;AACM,MAAMI,
|
|
1
|
+
{"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","exports","Symbol","for","symbolForTplStateStoreId","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachSize","symbolForTPlExternalNoForEach"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncPropertyEntry } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\nexport const symbolForTPlExternalForEachIndex = Symbol.for(\n \"tpl.externalForEachIndex\"\n);\nexport const symbolForTPlExternalForEachSize = Symbol.for(\n \"tpl.externalForEachSize\"\n);\nexport const symbolForTPlExternalNoForEach = Symbol.for(\n \"tpl.externalNoForEach\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n [symbolForTPlExternalForEachIndex]?: number;\n [symbolForTPlExternalForEachSize]?: number;\n [symbolForTPlExternalNoForEach]?: boolean;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAAC,OAAA,CAAAD,mCAAA,GAAGE,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AACM,MAAMC,wBAAwB,GAAAH,OAAA,CAAAG,wBAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAC/D,MAAME,+BAA+B,GAAAJ,OAAA,CAAAI,+BAAA,GAAGH,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AACM,MAAMG,gCAAgC,GAAAL,OAAA,CAAAK,gCAAA,GAAGJ,MAAM,CAACC,GAAG,CACxD,0BACF,CAAC;AACM,MAAMI,+BAA+B,GAAAN,OAAA,CAAAM,+BAAA,GAAGL,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AACM,MAAMK,6BAA6B,GAAAP,OAAA,CAAAO,6BAAA,GAAGN,MAAM,CAACC,GAAG,CACrD,uBACF,CAAC","ignoreList":[]}
|
|
@@ -19,9 +19,10 @@ function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropert
|
|
|
19
19
|
tplStateStoreId
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// There is a boundary for `
|
|
22
|
+
// There is a boundary for `forEach*` and `FORM_STATE` between template internals and externals.
|
|
23
23
|
delete runtimeContext.forEachItem;
|
|
24
24
|
delete runtimeContext.forEachIndex;
|
|
25
|
+
delete runtimeContext.forEachSize;
|
|
25
26
|
delete runtimeContext.formStateStoreId;
|
|
26
27
|
const tplStateStore = new _DataStore.DataStore("STATE", hostBrick, rendererContext, tplStateStoreId);
|
|
27
28
|
runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","__temporary_tpl_tag_name","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `
|
|
1
|
+
{"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","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","__temporary_tpl_tag_name","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `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 __temporary_tpl_tag_name: tplTagName,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAGO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN,SAAS,CAACM,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,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;EAC5EyB,cAAK,aAALA,cAAK,gBAAApB,cAAA,GAALoB,cAAK,CAAEC,OAAO,cAAArB,cAAA,eAAdA,cAAA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,CAAC,KAAK,CAClED,QAAQ,EACR;IACEX,IAAI,EAAE,QAAQ;IACdhC,MAAM,EAAE,CAAC4C,QAAQ,CAAC5C,MAAM,IAAI,EAAE,EAAEiC,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEN,WAAW,CACzC;EACF,CAAC,CACF,CACH,CAAC;EAED,OAAO;IACL,GAAGY,uBAAuB;IAC1BnB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEY,uBAAuB,CAACb,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH","ignoreList":[]}
|
|
@@ -64,7 +64,7 @@ function setupTemplateProxy(hostContext, ref, slots) {
|
|
|
64
64
|
// External bricks of a template, should not access the template internal forEach `ITEM`.
|
|
65
65
|
// For some existing templates who is *USING* this bug, we keep the old behavior.
|
|
66
66
|
const hostHasForEach = (0, _general.hasOwnProperty)(hostBrick.runtimeContext, "forEachItem");
|
|
67
|
-
expandableSlot[(0, _lodash.clamp)(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((hostContext.__temporary_tpl_tag_name === "base-layout-v3.tpl-scroll-load-list" || hostContext.__temporary_tpl_tag_name === "shrcb-homepage.tpl-custom-scroll-load-list") && !hostHasForEach ? insertBricks : setupTemplateExternalBricks(insertBricks, hostHasForEach, hostBrick.runtimeContext.forEachItem, hostBrick.runtimeContext.forEachIndex)));
|
|
67
|
+
expandableSlot[(0, _lodash.clamp)(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((hostContext.__temporary_tpl_tag_name === "base-layout-v3.tpl-scroll-load-list" || hostContext.__temporary_tpl_tag_name === "shrcb-homepage.tpl-custom-scroll-load-list") && !hostHasForEach ? insertBricks : setupTemplateExternalBricks(insertBricks, hostHasForEach, hostBrick.runtimeContext.forEachItem, hostBrick.runtimeContext.forEachIndex, hostBrick.runtimeContext.forEachSize)));
|
|
68
68
|
}
|
|
69
69
|
for (const [slotName, quasis] of quasisMap.entries()) {
|
|
70
70
|
if (!(0, _general.hasOwnProperty)(slots, slotName)) {
|
|
@@ -88,39 +88,41 @@ function setupTemplateProxy(hostContext, ref, slots) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// External bricks of a template, have the same forEachItem context as their host.
|
|
91
|
-
function setupTemplateExternalBricks(bricks, hasForEach, forEachItem, forEachIndex) {
|
|
91
|
+
function setupTemplateExternalBricks(bricks, hasForEach, forEachItem, forEachIndex, forEachSize) {
|
|
92
92
|
return bricks.map(({
|
|
93
93
|
children,
|
|
94
94
|
slots,
|
|
95
95
|
[_constants.symbolForTPlExternalForEachItem]: a,
|
|
96
96
|
[_constants.symbolForTPlExternalForEachIndex]: b,
|
|
97
|
-
[_constants.
|
|
97
|
+
[_constants.symbolForTPlExternalForEachSize]: c,
|
|
98
|
+
[_constants.symbolForTPlExternalNoForEach]: d,
|
|
98
99
|
...brick
|
|
99
100
|
}) => ({
|
|
100
101
|
...brick,
|
|
101
102
|
...(hasForEach ? {
|
|
102
103
|
[_constants.symbolForTPlExternalForEachItem]: forEachItem,
|
|
103
|
-
[_constants.symbolForTPlExternalForEachIndex]: forEachIndex
|
|
104
|
+
[_constants.symbolForTPlExternalForEachIndex]: forEachIndex,
|
|
105
|
+
[_constants.symbolForTPlExternalForEachSize]: forEachSize
|
|
104
106
|
} : {
|
|
105
107
|
[_constants.symbolForTPlExternalNoForEach]: true
|
|
106
108
|
}),
|
|
107
109
|
// Keep `:forEach` bricks as original, since they have their own forEachItem context.
|
|
108
110
|
slots: brick.brick === ":forEach" ? (0, _Renderer.childrenToSlots)(children, slots) : Object.fromEntries(Object.entries((0, _Renderer.childrenToSlots)(children, slots) ?? {}).map(([slotName, slotConf]) => [slotName, slotConf.type === "routes" ? {
|
|
109
111
|
type: "routes",
|
|
110
|
-
routes: setupTemplateExternalRoutes(slotConf.routes, hasForEach, forEachItem, forEachIndex)
|
|
112
|
+
routes: setupTemplateExternalRoutes(slotConf.routes, hasForEach, forEachItem, forEachIndex, forEachSize)
|
|
111
113
|
} : {
|
|
112
114
|
type: "bricks",
|
|
113
|
-
bricks: setupTemplateExternalBricks(slotConf.bricks, hasForEach, forEachItem, forEachIndex)
|
|
115
|
+
bricks: setupTemplateExternalBricks(slotConf.bricks, hasForEach, forEachItem, forEachIndex, forEachSize)
|
|
114
116
|
}]))
|
|
115
117
|
}));
|
|
116
118
|
}
|
|
117
|
-
function setupTemplateExternalRoutes(routes, hasForEach, forEachItem, forEachIndex) {
|
|
119
|
+
function setupTemplateExternalRoutes(routes, hasForEach, forEachItem, forEachIndex, forEachSize) {
|
|
118
120
|
return routes.map(route => route.type === "routes" ? {
|
|
119
121
|
...route,
|
|
120
|
-
routes: setupTemplateExternalRoutes(route.routes, hasForEach, forEachItem, forEachIndex)
|
|
122
|
+
routes: setupTemplateExternalRoutes(route.routes, hasForEach, forEachItem, forEachIndex, forEachSize)
|
|
121
123
|
} : route.type === "redirect" ? route : {
|
|
122
124
|
...route,
|
|
123
|
-
bricks: setupTemplateExternalBricks(route.bricks, hasForEach, forEachItem, forEachIndex)
|
|
125
|
+
bricks: setupTemplateExternalBricks(route.bricks, hasForEach, forEachItem, forEachIndex, forEachSize)
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
128
|
//# sourceMappingURL=setupTemplateProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","_Renderer","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","from","to","filtered","filter","entry","length","refProperty","computePropertyValue","Boolean","slotProxies","quasisMap","Map","_externalSlots$from","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","hostHasForEach","runtimeContext","clamp","__temporary_tpl_tag_name","setupTemplateExternalBricks","forEachItem","forEachIndex","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","hasForEach","children","symbolForTPlExternalForEachItem","a","symbolForTPlExternalForEachIndex","b","symbolForTPlExternalNoForEach","c","brick","childrenToSlots","Object","fromEntries","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTPlExternalNoForEach,\n symbolForTplStateStoreId,\n type RuntimeBrickConfWithTplSymbols,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n // External bricks of a template, should not access the template internal forEach `ITEM`.\n // For some existing templates who is *USING* this bug, we keep the old behavior.\n const hostHasForEach = hasOwnProperty(\n hostBrick.runtimeContext,\n \"forEachItem\"\n );\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...((hostContext.__temporary_tpl_tag_name ===\n \"base-layout-v3.tpl-scroll-load-list\" ||\n hostContext.__temporary_tpl_tag_name ===\n \"shrcb-homepage.tpl-custom-scroll-load-list\") &&\n !hostHasForEach\n ? insertBricks\n : setupTemplateExternalBricks(\n insertBricks,\n hostHasForEach,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!\n ))\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number\n): BrickConf[] {\n return (bricks as RuntimeBrickConfWithTplSymbols[]).map(\n ({\n children,\n slots,\n [symbolForTPlExternalForEachItem]: a,\n [symbolForTPlExternalForEachIndex]: b,\n [symbolForTPlExternalNoForEach]: c,\n ...brick\n }) => ({\n ...brick,\n ...(hasForEach\n ? {\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n }\n : {\n [symbolForTPlExternalNoForEach]: true,\n }),\n // Keep `:forEach` bricks as original, since they have their own forEachItem context.\n slots:\n brick.brick === \":forEach\"\n ? childrenToSlots(children, slots)\n : Object.fromEntries(\n Object.entries(childrenToSlots(children, slots) ?? {}).map(\n ([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(\n slotConf.routes,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n },\n ]\n )\n ),\n })\n );\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type === \"routes\"\n ? {\n ...route,\n routes: setupTemplateExternalRoutes(\n route.routes,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n : route.type === \"redirect\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(\n route.bricks,\n hasForEach,\n forEachItem,\n forEachIndex\n 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AI,KAAK,UAAU,GACvBqB,KAAK,GACL;IACE,GAAGA,KAAK;IACRzC,MAAM,EAAEc,2BAA2B,CACjC2B,KAAK,CAACzC,MAAM,EACZ2B,UAAU,EACVZ,WAAW,EACXC,YACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","_Renderer","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","from","to","filtered","filter","entry","length","refProperty","computePropertyValue","Boolean","slotProxies","quasisMap","Map","_externalSlots$from","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","hostHasForEach","runtimeContext","clamp","__temporary_tpl_tag_name","setupTemplateExternalBricks","forEachItem","forEachIndex","forEachSize","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","hasForEach","children","symbolForTPlExternalForEachItem","a","symbolForTPlExternalForEachIndex","b","symbolForTPlExternalForEachSize","c","symbolForTPlExternalNoForEach","d","brick","childrenToSlots","Object","fromEntries","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTPlExternalForEachSize,\n symbolForTPlExternalNoForEach,\n symbolForTplStateStoreId,\n type RuntimeBrickConfWithTplSymbols,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n // External bricks of a template, should not access the template internal forEach `ITEM`.\n // For some existing templates who is *USING* this bug, we keep the old behavior.\n const hostHasForEach = hasOwnProperty(\n hostBrick.runtimeContext,\n \"forEachItem\"\n );\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...((hostContext.__temporary_tpl_tag_name ===\n \"base-layout-v3.tpl-scroll-load-list\" ||\n hostContext.__temporary_tpl_tag_name ===\n \"shrcb-homepage.tpl-custom-scroll-load-list\") &&\n !hostHasForEach\n ? insertBricks\n : setupTemplateExternalBricks(\n insertBricks,\n hostHasForEach,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!,\n hostBrick.runtimeContext.forEachSize!\n ))\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number,\n forEachSize: number\n): BrickConf[] {\n return (bricks as RuntimeBrickConfWithTplSymbols[]).map(\n ({\n children,\n slots,\n [symbolForTPlExternalForEachItem]: a,\n [symbolForTPlExternalForEachIndex]: b,\n [symbolForTPlExternalForEachSize]: c,\n [symbolForTPlExternalNoForEach]: d,\n ...brick\n }) => ({\n ...brick,\n ...(hasForEach\n ? {\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n [symbolForTPlExternalForEachSize]: forEachSize,\n }\n : {\n [symbolForTPlExternalNoForEach]: true,\n }),\n // Keep `:forEach` bricks as original, since they have their own forEachItem context.\n slots:\n brick.brick === \":forEach\"\n ? childrenToSlots(children, slots)\n : Object.fromEntries(\n Object.entries(childrenToSlots(children, slots) ?? {}).map(\n ([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(\n slotConf.routes,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n },\n ]\n )\n ),\n })\n );\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number,\n forEachSize: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type === \"routes\"\n ? {\n ...route,\n routes: setupTemplateExternalRoutes(\n route.routes,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n : route.type === \"redirect\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(\n route.bricks,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAUA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,MAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAAoD;EAExD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,MAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,MAAMG,gBAAgB,GACpBC,cAAoC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QAAQ,EAAExD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAACY,GAAG,CACxD,CAAC,CAACiC,QAAQ,EAAEI,QAAQ,CAAC,KAAK,CACxBJ,QAAQ,EACRI,QAAQ,CAACD,IAAI,KAAK,QAAQ,GACtB;MACEA,IAAI,EAAE,QAAQ;MACdqB,MAAM,EAAEC,2BAA2B,CACjCrB,QAAQ,CAACoB,MAAM,EACfd,UAAU,EACVb,WAAW,EACXC,YAAY,EACZC,WACF;IACF,CAAC,GACD;MACEI,IAAI,EAAE,QAAQ;MACdrB,MAAM,EAAEc,2BAA2B,CACjCQ,QAAQ,CAACtB,MAAM,EACf4B,UAAU,EACVb,WAAW,EACXC,YAAY,EACZC,WACF;IACF,CAAC,CAET,CACF;EACR,CAAC,CACH,CAAC;AACH;AAEA,SAAS0B,2BAA2BA,CAClCD,MAAmB,EACnBd,UAAmB,EACnBb,WAAoB,EACpBC,YAAoB,EACpBC,WAAmB,EACN;EACb,OAAOyB,MAAM,CAACzD,GAAG,CAAE2D,KAAK,IACtBA,KAAK,CAACvB,IAAI,KAAK,QAAQ,GACnB;IACE,GAAGuB,KAAK;IACRF,MAAM,EAAEC,2BAA2B,CACjCC,KAAK,CAACF,MAAM,EACZd,UAAU,EACVb,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CAAC,GACD2B,KAAK,CAACvB,IAAI,KAAK,UAAU,GACvBuB,KAAK,GACL;IACE,GAAGA,KAAK;IACR5C,MAAM,EAAEc,2BAA2B,CACjC8B,KAAK,CAAC5C,MAAM,EACZ4B,UAAU,EACVb,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -19,9 +19,10 @@ function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropert
|
|
|
19
19
|
formStateStoreId
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// There is a boundary for `
|
|
22
|
+
// There is a boundary for `forEach*` and `STATE` between form internals and externals.
|
|
23
23
|
delete runtimeContext.forEachItem;
|
|
24
24
|
delete runtimeContext.forEachIndex;
|
|
25
|
+
delete runtimeContext.forEachSize;
|
|
25
26
|
delete runtimeContext.tplStateStoreId;
|
|
26
27
|
const formStateStore = new _DataStore.DataStore("FORM_STATE", undefined, rendererContext, formStateStoreId);
|
|
27
28
|
runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","tplStateStoreId","formStateStore","DataStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncPropertyEntry, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst formContainers = [\"forms.general-form\", \"form.general-form\", \"eo-form\"];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `
|
|
1
|
+
{"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","tplStateStoreId","formStateStore","DataStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncPropertyEntry, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst formContainers = [\"forms.general-form\", \"form.general-form\", \"eo-form\"];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext,\n formStateStoreId\n );\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostPropertyEntries);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formContainers.includes(formConf.brick) && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"eo-micro-view\",\n properties: { style: { padding: \"12px\" } },\n children: [formConf],\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAGA,MAAMK,cAAc,GAAG,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,SAAS,CAAC;AAEtE,SAASC,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EACrB;EAAA,IAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAON,QAAQ,KAAK,QAAQ,GAAGO,IAAI,CAACC,KAAK,CAACR,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMS,gBAAgB,GAAG,IA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AM,EAAEb,MAAM,EAAEtB,gBAAgB,CAAC;IAC/D,CAACgD,oCAAyB,GAAGhD;EAC/B,CAAc;EAEd,IAAI,IAAAiD,uBAAc,EAAChB,MAAM,EAAE,IAAI,CAAC,EAAE;IAChCY,SAAS,CAACK,EAAE,GAAGjB,MAAM,CAACiB,EAAE;EAC1B;EAEA,OAAOL,SAAS;AAClB;AAEA,SAASE,mBAAmBA,CAC1BI,OAA2C,EAC3C7B,MAAyB,EACzBtB,gBAAwB,EACC;EACzB,IAAIoD,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAAE;IAC1B,OAAOA,OAAO,CAACG,GAAG,CAAErB,MAAM,IACxBb,iBAAiB,CAACa,MAAM,EAAEX,MAAM,EAAEtB,gBAAgB,CACpD,CAAC;EACH;AACF;AAEA,SAAS0B,WAAWA,CAClB6B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,MAAM/B,MAAM,GAAG8B,YAAY,IAAI,CAAC,CAAC;EAEjC,KAAK,MAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChE/B,MAAM,CAACgC,SAAS,CAAC,GAAG,IAAAR,uBAAc,EAACxB,MAAM,EAAEgC,SAAS,CAAC,GACjD,CAAChC,MAAM,CAACgC,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAOjC,MAAM;AACf","ignoreList":[]}
|
|
@@ -209,13 +209,14 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
209
209
|
formStateStoreId
|
|
210
210
|
};
|
|
211
211
|
if ((0, _general.hasOwnProperty)(brickConf, _constants.symbolForTPlExternalForEachItem)) {
|
|
212
|
-
// The external bricks of a template should restore their `
|
|
213
|
-
// `forEachIndex` from their host.
|
|
212
|
+
// The external bricks of a template should restore their `forEach*` from their host.
|
|
214
213
|
runtimeContext.forEachItem = brickConf[_constants.symbolForTPlExternalForEachItem];
|
|
215
214
|
runtimeContext.forEachIndex = brickConf[_constants.symbolForTPlExternalForEachIndex];
|
|
215
|
+
runtimeContext.forEachSize = brickConf[_constants.symbolForTPlExternalForEachSize];
|
|
216
216
|
} else if (brickConf[_constants.symbolForTPlExternalNoForEach]) {
|
|
217
217
|
delete runtimeContext.forEachItem;
|
|
218
218
|
delete runtimeContext.forEachIndex;
|
|
219
|
+
delete runtimeContext.forEachSize;
|
|
219
220
|
}
|
|
220
221
|
const {
|
|
221
222
|
context
|
|
@@ -456,6 +457,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
456
457
|
};
|
|
457
458
|
delete childRuntimeContext.forEachItem;
|
|
458
459
|
delete childRuntimeContext.forEachIndex;
|
|
460
|
+
delete childRuntimeContext.forEachSize;
|
|
459
461
|
} else {
|
|
460
462
|
childRuntimeContext = runtimeContext;
|
|
461
463
|
}
|
|
@@ -578,12 +580,13 @@ function ensureValidControlBrick(brick) {
|
|
|
578
580
|
}
|
|
579
581
|
async function renderForEach(returnNode, dataSource, bricks, runtimeContext, rendererContext, parentRoutes, menuRequestReturnNode, slotId, tplStack, keyPath) {
|
|
580
582
|
const output = getEmptyRenderOutput();
|
|
581
|
-
const
|
|
583
|
+
const size = dataSource.length;
|
|
582
584
|
const rendered = await Promise.all(dataSource.map((item, i) => Promise.all(bricks.map((brickConf, j) => renderBrick(returnNode, brickConf, {
|
|
583
585
|
...runtimeContext,
|
|
584
586
|
forEachItem: item,
|
|
585
|
-
forEachIndex: i
|
|
586
|
-
|
|
587
|
+
forEachIndex: i,
|
|
588
|
+
forEachSize: size
|
|
589
|
+
}, rendererContext, parentRoutes, menuRequestReturnNode, slotId, keyPath.concat(i * size + j), tplStack && new Map(tplStack))))));
|
|
587
590
|
|
|
588
591
|
// 多层构件并行异步转换,但转换的结果按原顺序串行合并。
|
|
589
592
|
rendered.flat().forEach((item, index) => {
|