@next-core/runtime 1.22.3 → 1.22.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cjs/internal/CustomTemplates/constants.js +3 -1
  2. package/dist/cjs/internal/CustomTemplates/constants.js.map +1 -1
  3. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +1 -0
  4. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  5. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +7 -6
  6. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  7. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js +1 -0
  8. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -1
  9. package/dist/cjs/internal/Renderer.js +31 -25
  10. package/dist/cjs/internal/Renderer.js.map +1 -1
  11. package/dist/cjs/internal/RendererContext.js +36 -7
  12. package/dist/cjs/internal/RendererContext.js.map +1 -1
  13. package/dist/cjs/internal/compute/evaluate.js +10 -6
  14. package/dist/cjs/internal/compute/evaluate.js.map +1 -1
  15. package/dist/cjs/internal/enums.js +1 -0
  16. package/dist/cjs/internal/enums.js.map +1 -1
  17. package/dist/cjs/internal/interfaces.js.map +1 -1
  18. package/dist/cjs/internal/mount.js +41 -39
  19. package/dist/cjs/internal/mount.js.map +1 -1
  20. package/dist/cjs/internal/secret_internals.js +5 -2
  21. package/dist/cjs/internal/secret_internals.js.map +1 -1
  22. package/dist/esm/internal/CustomTemplates/constants.js +1 -0
  23. package/dist/esm/internal/CustomTemplates/constants.js.map +1 -1
  24. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +1 -0
  25. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  26. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +8 -7
  27. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  28. package/dist/esm/internal/FormRenderer/expandFormRenderer.js +1 -0
  29. package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -1
  30. package/dist/esm/internal/Renderer.js +53 -42
  31. package/dist/esm/internal/Renderer.js.map +1 -1
  32. package/dist/esm/internal/RendererContext.js +36 -7
  33. package/dist/esm/internal/RendererContext.js.map +1 -1
  34. package/dist/esm/internal/compute/evaluate.js +10 -6
  35. package/dist/esm/internal/compute/evaluate.js.map +1 -1
  36. package/dist/esm/internal/enums.js +1 -0
  37. package/dist/esm/internal/enums.js.map +1 -1
  38. package/dist/esm/internal/interfaces.js.map +1 -1
  39. package/dist/esm/internal/mount.js +41 -39
  40. package/dist/esm/internal/mount.js.map +1 -1
  41. package/dist/esm/internal/secret_internals.js +5 -2
  42. package/dist/esm/internal/secret_internals.js.map +1 -1
  43. package/dist/types/internal/CustomTemplates/constants.d.ts +2 -0
  44. package/dist/types/internal/Renderer.d.ts +5 -5
  45. package/dist/types/internal/RendererContext.d.ts +5 -5
  46. package/dist/types/internal/enums.d.ts +2 -1
  47. package/dist/types/internal/interfaces.d.ts +12 -5
  48. package/package.json +2 -2
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.symbolForTplStateStoreId = exports.symbolForTPlExternalForEachItem = exports.symbolForAsyncComputedPropsFromHost = void 0;
6
+ exports.symbolForTplStateStoreId = exports.symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachIndex = exports.symbolForAsyncComputedPropsFromHost = void 0;
7
7
  const symbolForAsyncComputedPropsFromHost = Symbol.for("tpl.asyncComputedPropsFromHost");
8
8
  exports.symbolForAsyncComputedPropsFromHost = symbolForAsyncComputedPropsFromHost;
9
9
  const symbolForTplStateStoreId = Symbol.for("tpl.stateStoreId");
10
10
  exports.symbolForTplStateStoreId = symbolForTplStateStoreId;
11
11
  const symbolForTPlExternalForEachItem = Symbol.for("tpl.externalForEachItem");
12
12
  exports.symbolForTPlExternalForEachItem = symbolForTPlExternalForEachItem;
13
+ const symbolForTPlExternalForEachIndex = Symbol.for("tpl.externalForEachIndex");
14
+ exports.symbolForTPlExternalForEachIndex = symbolForTPlExternalForEachIndex;
13
15
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","Symbol","for","exports","symbolForTplStateStoreId","symbolForTPlExternalForEachItem"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { 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);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAGC,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AAACC,OAAA,CAAAH,mCAAA,GAAAA,mCAAA;AACK,MAAMI,wBAAwB,GAAGH,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAACC,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAChE,MAAMC,+BAA+B,GAAGJ,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AAACC,OAAA,CAAAE,+BAAA,GAAAA,+BAAA"}
1
+ {"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","Symbol","for","exports","symbolForTplStateStoreId","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex"],"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);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n [symbolForTPlExternalForEachIndex]?: number;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAGC,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AAACC,OAAA,CAAAH,mCAAA,GAAAA,mCAAA;AACK,MAAMI,wBAAwB,GAAGH,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAACC,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAChE,MAAMC,+BAA+B,GAAGJ,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AAACC,OAAA,CAAAE,+BAAA,GAAAA,+BAAA;AACK,MAAMC,gCAAgC,GAAGL,MAAM,CAACC,GAAG,CACxD,0BACF,CAAC;AAACC,OAAA,CAAAG,gCAAA,GAAAA,gCAAA"}
@@ -21,6 +21,7 @@ function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropert
21
21
 
22
22
  // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.
23
23
  delete runtimeContext.forEachItem;
24
+ delete runtimeContext.forEachIndex;
24
25
  delete runtimeContext.formStateStoreId;
25
26
  const tplStateStore = new _DataStore.DataStore("STATE", hostBrick, rendererContext);
26
27
  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","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick, rendererContext);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAGO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN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AED,OAAOb,YAAY;AACrB;AAEA,SAASmB,qBAAqBA,CAC5BC,mBAAwC,EACxCP,WAAgC,EACA;EAChC;EACA,IAAIO,mBAAmB,CAACC,EAAE,KAAK,IAAI,EAAE;IACnC,OAAOD,mBAAmB,CAACC,EAAE;EAC/B;EACA,MAAM;IACJf,UAAU;IACVX,KAAK,EAAE2B,eAAe;IACtBzB,QAAQ,EAAE0B,kBAAkB;IAC5B,GAAGC;EACL,CAAC,GAAGJ,mBAAmB;EAEvB,MAAMK,eAAe,GAAG,IAAAV,yBAAe,EACrCQ,kBAAkB,EAClBD,eACF,CAAoC;EAEpC,MAAM3B,KAAwB,GAAGc,MAAM,CAACiB,WAAW,CACjDjB,MAAM,CAACC,OAAO,CAACe,eAAe,aAAfA,eAAe,cAAfA,eAAe,GAAI,CAAC,CAAC,CAAC,CAACR,GAAG,CAAC,CAAC,CAACU,QAAQ,EAAEC,QAAQ,CAAC;IAAA,IAAAC,gBAAA;IAAA,OAAK,CAClEF,QAAQ,EACR;MACEX,IAAI,EAAE,QAAQ;MACd/B,MAAM,EAAE,EAAA4C,gBAAA,GAACD,QAAQ,CAAC3C,MAAM,cAAA4C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEL,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
1
+ {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick, rendererContext);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAGO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN,SAAS,CAACM,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,I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EAAE;IACnC,OAAOD,mBAAmB,CAACC,EAAE;EAC/B;EACA,MAAM;IACJf,UAAU;IACVX,KAAK,EAAE2B,eAAe;IACtBzB,QAAQ,EAAE0B,kBAAkB;IAC5B,GAAGC;EACL,CAAC,GAAGJ,mBAAmB;EAEvB,MAAMK,eAAe,GAAG,IAAAV,yBAAe,EACrCQ,kBAAkB,EAClBD,eACF,CAAoC;EAEpC,MAAM3B,KAAwB,GAAGc,MAAM,CAACiB,WAAW,CACjDjB,MAAM,CAACC,OAAO,CAACe,eAAe,aAAfA,eAAe,cAAfA,eAAe,GAAI,CAAC,CAAC,CAAC,CAACR,GAAG,CAAC,CAAC,CAACU,QAAQ,EAAEC,QAAQ,CAAC;IAAA,IAAAC,gBAAA;IAAA,OAAK,CAClEF,QAAQ,EACR;MACEX,IAAI,EAAE,QAAQ;MACd/B,MAAM,EAAE,EAAA4C,gBAAA,GAACD,QAAQ,CAAC3C,MAAM,cAAA4C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEL,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
@@ -60,7 +60,7 @@ function setupTemplateProxy(hostContext, ref, slots) {
60
60
  quasisMap.set(refToSlot, expandableSlot);
61
61
  }
62
62
  const refPosition = (_to$refPosition = to.refPosition) !== null && _to$refPosition !== void 0 ? _to$refPosition : -1;
63
- expandableSlot[(0, _lodash.clamp)(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((0, _general.hasOwnProperty)(hostBrick.runtimeContext, "forEachItem") ? setupTemplateExternalBricks(insertBricks, hostBrick.runtimeContext.forEachItem) : insertBricks));
63
+ expandableSlot[(0, _lodash.clamp)(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((0, _general.hasOwnProperty)(hostBrick.runtimeContext, "forEachItem") ? setupTemplateExternalBricks(insertBricks, hostBrick.runtimeContext.forEachItem, hostBrick.runtimeContext.forEachIndex) : insertBricks));
64
64
  }
65
65
  for (const [slotName, quasis] of quasisMap.entries()) {
66
66
  if (!(0, _general.hasOwnProperty)(slots, slotName)) {
@@ -84,29 +84,30 @@ function setupTemplateProxy(hostContext, ref, slots) {
84
84
  }
85
85
 
86
86
  // External bricks of a template, have the same forEachItem context as their host.
87
- function setupTemplateExternalBricks(bricks, forEachItem) {
87
+ function setupTemplateExternalBricks(bricks, forEachItem, forEachIndex) {
88
88
  return bricks.map(brick => {
89
89
  var _brick$slots;
90
90
  return {
91
91
  ...brick,
92
92
  [_constants.symbolForTPlExternalForEachItem]: forEachItem,
93
+ [_constants.symbolForTPlExternalForEachIndex]: forEachIndex,
93
94
  slots: Object.fromEntries(Object.entries((_brick$slots = brick.slots) !== null && _brick$slots !== void 0 ? _brick$slots : {}).map(([slotName, slotConf]) => {
94
95
  var _slotConf$bricks;
95
96
  return [slotName, slotConf.type === "routes" ? {
96
97
  type: "routes",
97
- routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem)
98
+ routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem, forEachIndex)
98
99
  } : {
99
100
  type: "bricks",
100
- bricks: setupTemplateExternalBricks((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : [], forEachItem)
101
+ bricks: setupTemplateExternalBricks((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : [], forEachItem, forEachIndex)
101
102
  }];
102
103
  }))
103
104
  };
104
105
  });
105
106
  }
106
- function setupTemplateExternalRoutes(routes, forEachItem) {
107
+ function setupTemplateExternalRoutes(routes, forEachItem, forEachIndex) {
107
108
  return routes.map(route => route.type && route.type !== "bricks" ? route : {
108
109
  ...route,
109
- bricks: setupTemplateExternalBricks(route.bricks, forEachItem)
110
+ bricks: setupTemplateExternalBricks(route.bricks, forEachItem, forEachIndex)
110
111
  });
111
112
  }
112
113
  //# sourceMappingURL=setupTemplateProxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","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$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","clamp","runtimeContext","setupTemplateExternalBricks","forEachItem","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","brick","_brick$slots","symbolForTPlExternalForEachItem","Object","fromEntries","_slotConf$bricks","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachItem,\n symbolForTplStateStoreId,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.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 expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(hasOwnProperty(hostBrick.runtimeContext, \"forEachItem\")\n ? setupTemplateExternalBricks(\n insertBricks,\n hostBrick.runtimeContext.forEachItem\n )\n : insertBricks)\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n forEachItem: unknown\n): BrickConf[] {\n return bricks.map((brick) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n slots: Object.fromEntries(\n Object.entries(brick.slots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks ?? [],\n forEachItem\n ),\n },\n ])\n ),\n }));\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n forEachItem: unknown\n): RouteConf[] {\n return routes.map((route) =>\n route.type && route.type !== \"bricks\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(route.bricks, forEachItem),\n }\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAMA,IAAAG,sBAAA,GAAAH,OAAA;AAEO,SAASI,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,e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ACjCX,QAAQ,CAAClB,MAAM,cAAA6B,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EACrBhB,WACF;QACF,CAAC,CACN;MAAA,EACH;IACF,CAAC;EAAA,CAAC,CAAC;AACL;AAEA,SAASkB,2BAA2BA,CAClCD,MAAmB,EACnBjB,WAAoB,EACP;EACb,OAAOiB,MAAM,CAAChD,GAAG,CAAEkD,KAAK,IACtBA,KAAK,CAACf,IAAI,IAAIe,KAAK,CAACf,IAAI,KAAK,QAAQ,GACjCe,KAAK,GACL;IACE,GAAGA,KAAK;IACRhC,MAAM,EAAEY,2BAA2B,CAACoB,KAAK,CAAChC,MAAM,EAAEa,WAAW;EAC/D,CACN,CAAC;AACH"}
1
+ {"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","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$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","clamp","runtimeContext","setupTemplateExternalBricks","forEachItem","forEachIndex","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","brick","_brick$slots","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex","Object","fromEntries","_slotConf$bricks","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTplStateStoreId,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.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 expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(hasOwnProperty(hostBrick.runtimeContext, \"forEachItem\")\n ? setupTemplateExternalBricks(\n insertBricks,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!\n )\n : insertBricks)\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n forEachItem: unknown,\n forEachIndex: number\n): BrickConf[] {\n return bricks.map((brick) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n slots: Object.fromEntries(\n Object.entries(brick.slots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(\n slotConf.routes,\n forEachItem,\n forEachIndex\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks ?? [],\n forEachItem,\n forEachIndex\n ),\n },\n ])\n ),\n }));\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n forEachItem: unknown,\n forEachIndex: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type && route.type !== \"bricks\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(\n route.bricks,\n forEachItem,\n forEachIndex\n ),\n }\n );\n}\n"],"mappings":";;;;;;AACA,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AAW,CACvBD,MAAM,CAACZ,OAAO,EAAAS,YAAA,GAACD,KAAK,CAACvD,KAAK,cAAAwD,YAAA,cAAAA,YAAA,GAAI,CAAC,CAAC,CAAC,CAAC5C,GAAG,CAAC,CAAC,CAACiC,QAAQ,EAAEI,QAAQ,CAAC;QAAA,IAAAY,gBAAA;QAAA,OAAK,CAC9DhB,QAAQ,EACRI,QAAQ,CAACD,IAAI,KAAK,QAAQ,GACtB;UACEA,IAAI,EAAE,QAAQ;UACdc,MAAM,EAAEC,2BAA2B,CACjCd,QAAQ,CAACa,MAAM,EACfnB,WAAW,EACXC,YACF;QACF,CAAC,GACD;UACEI,IAAI,EAAE,QAAQ;UACdlB,MAAM,EAAEY,2BAA2B,EAAAmB,gBAAA,GACjCZ,QAAQ,CAACnB,MAAM,cAAA+B,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EACrBlB,WAAW,EACXC,YACF;QACF,CAAC,CACN;MAAA,EACH;IACF,CAAC;EAAA,CAAC,CAAC;AACL;AAEA,SAASmB,2BAA2BA,CAClCD,MAAmB,EACnBnB,WAAoB,EACpBC,YAAoB,EACP;EACb,OAAOkB,MAAM,CAAClD,GAAG,CAAEoD,KAAK,IACtBA,KAAK,CAAChB,IAAI,IAAIgB,KAAK,CAAChB,IAAI,KAAK,QAAQ,GACjCgB,KAAK,GACL;IACE,GAAGA,KAAK;IACRlC,MAAM,EAAEY,2BAA2B,CACjCsB,KAAK,CAAClC,MAAM,EACZa,WAAW,EACXC,YACF;EACF,CACN,CAAC;AACH"}
@@ -21,6 +21,7 @@ function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropert
21
21
 
22
22
  // There is a boundary for `forEachItem` and `STATE` between form internals and externals.
23
23
  delete runtimeContext.forEachItem;
24
+ delete runtimeContext.forEachIndex;
24
25
  delete runtimeContext.tplStateStoreId;
25
26
  const formStateStore = new _DataStore.DataStore("FORM_STATE", undefined, rendererContext);
26
27
  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","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","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 `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext\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,EAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAOP,QAAQ,KAAK,QAAQ,GAAGQ,IAAI,CAACC,KAAK,CAACT,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMU,gBAAgB,GAAG,IAAAC,gBAAQ,EAAC,aAAa,CAAC;EAChD,MAAMC,cAAc,GAAG;IACrB,GAAGV,SAAS,CAACU,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,eAAe;EAErC,MAAMC,cAAc,GAAG,IAAIC,oBAAS,CAClC,YAAY,EACZC,SAAS,EACTb,eACF,CAAC;EACDQ,cAAc,CAACM,iBAAiB,CAACC,GA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IkD,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAAE;IAC1B,OAAOA,OAAO,CAACG,GAAG,CAAErB,MAAM,IACxBb,iBAAiB,CAACa,MAAM,EAAEX,MAAM,EAAEpB,gBAAgB,CACpD,CAAC;EACH;AACF;AAEA,SAASwB,WAAWA,CAClB6B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,MAAM/B,MAAM,GAAG8B,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,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"}
1
+ {"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_normalizedFormData$c","_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 `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext\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,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AAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAOjC,MAAM;AACf"}
@@ -36,10 +36,7 @@ var _matchStoryboard = require("./matchStoryboard.js");
36
36
  var _bindListeners = require("./bindListeners.js");
37
37
  async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext, parentRoutes, slotId, isIncremental) {
38
38
  const matched = await (0, _matchRoutes.matchRoutes)(routes, _runtimeContext);
39
- const output = {
40
- blockingList: [],
41
- menuRequests: []
42
- };
39
+ const output = getEmptyRenderOutput();
43
40
  switch (matched) {
44
41
  case "missed":
45
42
  break;
@@ -109,10 +106,7 @@ async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext
109
106
  return output;
110
107
  }
111
108
  async function renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
112
- const output = {
113
- blockingList: [],
114
- menuRequests: []
115
- };
109
+ const output = getEmptyRenderOutput();
116
110
  const kPath = keyPath !== null && keyPath !== void 0 ? keyPath : [];
117
111
  // 多个构件并行异步转换,但转换的结果按原顺序串行合并。
118
112
  const rendered = await Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, parentRoutes, slotId, kPath.concat(index), tplStack && new Map(tplStack))));
@@ -127,10 +121,7 @@ async function renderBricks(returnNode, bricks, runtimeContext, rendererContext,
127
121
  }
128
122
  async function renderBrick(returnNode, brickConf, _runtimeContext, rendererContext, parentRoutes, slotId, keyPath = [], tplStack = new Map()) {
129
123
  var _hooks$checkPermissio2, _runtimeContext$app;
130
- const output = {
131
- blockingList: [],
132
- menuRequests: []
133
- };
124
+ const output = getEmptyRenderOutput();
134
125
  if (!brickConf.brick) {
135
126
  if (brickConf.template) {
136
127
  // eslint-disable-next-line no-console
@@ -176,9 +167,10 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
176
167
  formStateStoreId
177
168
  };
178
169
  if ((0, _general.hasOwnProperty)(brickConf, _constants.symbolForTPlExternalForEachItem)) {
179
- // The external bricks of a template should restore their `forEachItem`
180
- // from their host.
170
+ // The external bricks of a template should restore their `forEachItem` and
171
+ // `forEachIndex` from their host.
181
172
  runtimeContext.forEachItem = brickConf[_constants.symbolForTPlExternalForEachItem];
173
+ runtimeContext.forEachIndex = brickConf[_constants.symbolForTPlExternalForEachIndex];
182
174
  }
183
175
  const {
184
176
  context
@@ -202,7 +194,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
202
194
  const {
203
195
  dataSource
204
196
  } = brickConf;
205
- const renderControlNode = async runtimeContext => {
197
+ const lowerLevelRenderControlNode = async runtimeContext => {
206
198
  var _slots$slot;
207
199
  // First, compute the `dataSource`
208
200
  const computedDataSource = await (0, _computeRealValue.asyncComputeRealValue)(dataSource, runtimeContext);
@@ -216,13 +208,13 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
216
208
  // Then, get the bricks in that matched slot.
217
209
  const bricks = slots && (0, _general.hasOwnProperty)(slots, slot) && ((_slots$slot = slots[slot]) === null || _slots$slot === void 0 ? void 0 : _slots$slot.bricks);
218
210
  if (!Array.isArray(bricks)) {
219
- return output;
211
+ return getEmptyRenderOutput();
220
212
  }
221
213
  switch (brickName) {
222
214
  case ":forEach":
223
215
  {
224
216
  if (!Array.isArray(computedDataSource)) {
225
- return output;
217
+ return getEmptyRenderOutput();
226
218
  }
227
219
  return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
228
220
  }
@@ -233,6 +225,15 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
233
225
  }
234
226
  }
235
227
  };
228
+ const renderControlNode = async runtimeContext => {
229
+ var _rawOutput$node;
230
+ const rawOutput = await lowerLevelRenderControlNode(runtimeContext);
231
+ (_rawOutput$node = rawOutput.node) !== null && _rawOutput$node !== void 0 ? _rawOutput$node : rawOutput.node = {
232
+ tag: _enums.RenderTag.PLACEHOLDER,
233
+ return: returnNode
234
+ };
235
+ return rawOutput;
236
+ };
236
237
  const controlledOutput = await renderControlNode(runtimeContext);
237
238
  const {
238
239
  onMount,
@@ -248,9 +249,9 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
248
249
  const listener = async () => {
249
250
  const currentRenderId = ++renderId;
250
251
  const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(runtimeContext);
251
- const controlOutput = await renderControlNode(scopedRuntimeContext);
252
+ const reControlledOutput = await renderControlNode(scopedRuntimeContext);
252
253
  const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
253
- await postAsyncRender(controlOutput, scopedRuntimeContext, scopedStores);
254
+ await postAsyncRender(reControlledOutput, scopedRuntimeContext, scopedStores);
254
255
 
255
256
  // Ignore stale renders
256
257
  if (renderId === currentRenderId) {
@@ -261,7 +262,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
261
262
  }
262
263
  }));
263
264
  }
264
- rendererContext.reRender(slotId, keyPath, controlOutput.node, returnNode);
265
+ rendererContext.reRender(slotId, keyPath, reControlledOutput.node, returnNode);
265
266
  if (onMount) {
266
267
  (0, _bindListeners.listenerFactory)(onMount, scopedRuntimeContext)(new CustomEvent("mount", {
267
268
  detail: {
@@ -414,6 +415,7 @@ async function renderBrick(returnNode, brickConf, _runtimeContext, rendererConte
414
415
  ...runtimeContext
415
416
  };
416
417
  delete childRuntimeContext.forEachItem;
418
+ delete childRuntimeContext.forEachIndex;
417
419
  } else {
418
420
  childRuntimeContext = runtimeContext;
419
421
  }
@@ -526,14 +528,12 @@ function ensureValidControlBrick(brick) {
526
528
  }
527
529
  }
528
530
  async function renderForEach(returnNode, dataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
529
- const output = {
530
- blockingList: [],
531
- menuRequests: []
532
- };
531
+ const output = getEmptyRenderOutput();
533
532
  const rows = dataSource.length;
534
533
  const rendered = await Promise.all(dataSource.map((item, i) => Promise.all(bricks.map((brickConf, j) => renderBrick(returnNode, brickConf, {
535
534
  ...runtimeContext,
536
- forEachItem: item
535
+ forEachItem: item,
536
+ forEachIndex: i
537
537
  }, rendererContext, parentRoutes, slotId, keyPath.concat(i * rows + j), tplStack && new Map(tplStack))))));
538
538
 
539
539
  // 多层构件并行异步转换,但转换的结果按原顺序串行合并。
@@ -607,6 +607,12 @@ function mergeRenderOutput(output, newOutput) {
607
607
  }
608
608
  Object.assign(output, rest);
609
609
  }
610
+ function getEmptyRenderOutput() {
611
+ return {
612
+ blockingList: [],
613
+ menuRequests: []
614
+ };
615
+ }
610
616
  function childrenToSlots(children, originalSlots) {
611
617
  let newSlots = originalSlots;
612
618
  // istanbul ignore next