@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
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import { hasOwnProperty } from "@next-core/utils/general";
3
3
  import { clamp } from "lodash";
4
- import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachItem, symbolForTplStateStoreId } from "./constants.js";
4
+ import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachIndex, symbolForTPlExternalForEachItem, symbolForTplStateStoreId } from "./constants.js";
5
5
  import { computePropertyValue } from "../compute/computeRealProperties.js";
6
6
  export function setupTemplateProxy(hostContext, ref, slots) {
7
7
  var {
@@ -56,7 +56,7 @@ export function setupTemplateProxy(hostContext, ref, slots) {
56
56
  quasisMap.set(refToSlot, expandableSlot);
57
57
  }
58
58
  var refPosition = (_to$refPosition = to.refPosition) !== null && _to$refPosition !== void 0 ? _to$refPosition : -1;
59
- expandableSlot[clamp(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...(hasOwnProperty(hostBrick.runtimeContext, "forEachItem") ? setupTemplateExternalBricks(insertBricks, hostBrick.runtimeContext.forEachItem) : insertBricks));
59
+ expandableSlot[clamp(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...(hasOwnProperty(hostBrick.runtimeContext, "forEachItem") ? setupTemplateExternalBricks(insertBricks, hostBrick.runtimeContext.forEachItem, hostBrick.runtimeContext.forEachIndex) : insertBricks));
60
60
  }
61
61
  var _loop = function () {
62
62
  if (!hasOwnProperty(slots, slotName)) {
@@ -83,28 +83,29 @@ export function setupTemplateProxy(hostContext, ref, slots) {
83
83
  }
84
84
 
85
85
  // External bricks of a template, have the same forEachItem context as their host.
86
- function setupTemplateExternalBricks(bricks, forEachItem) {
86
+ function setupTemplateExternalBricks(bricks, forEachItem, forEachIndex) {
87
87
  return bricks.map(brick => {
88
88
  var _brick$slots;
89
89
  return _objectSpread(_objectSpread({}, brick), {}, {
90
90
  [symbolForTPlExternalForEachItem]: forEachItem,
91
+ [symbolForTPlExternalForEachIndex]: forEachIndex,
91
92
  slots: Object.fromEntries(Object.entries((_brick$slots = brick.slots) !== null && _brick$slots !== void 0 ? _brick$slots : {}).map(_ref2 => {
92
93
  var _slotConf$bricks;
93
94
  var [slotName, slotConf] = _ref2;
94
95
  return [slotName, slotConf.type === "routes" ? {
95
96
  type: "routes",
96
- routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem)
97
+ routes: setupTemplateExternalRoutes(slotConf.routes, forEachItem, forEachIndex)
97
98
  } : {
98
99
  type: "bricks",
99
- bricks: setupTemplateExternalBricks((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : [], forEachItem)
100
+ bricks: setupTemplateExternalBricks((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : [], forEachItem, forEachIndex)
100
101
  }];
101
102
  }))
102
103
  });
103
104
  });
104
105
  }
105
- function setupTemplateExternalRoutes(routes, forEachItem) {
106
+ function setupTemplateExternalRoutes(routes, forEachItem, forEachIndex) {
106
107
  return routes.map(route => route.type && route.type !== "bricks" ? route : _objectSpread(_objectSpread({}, route), {}, {
107
- bricks: setupTemplateExternalBricks(route.bricks, forEachItem)
108
+ bricks: setupTemplateExternalBricks(route.bricks, forEachItem, forEachIndex)
108
109
  }));
109
110
  }
110
111
  //# sourceMappingURL=setupTemplateProxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachItem","symbolForTplStateStoreId","computePropertyValue","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","_ref","from","to","filtered","filter","entry","length","refProperty","Boolean","slotProxies","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","runtimeContext","setupTemplateExternalBricks","forEachItem","_loop","slotName","type","slotConf","quasis","flatMap","index","concat","entries","brick","_brick$slots","_objectSpread","Object","fromEntries","_ref2","_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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,+BAA+B,EAC/BC,wBAAwB,QACnB,gBAAgB;AAEvB,SAASC,oBAAoB,QAAQ,qCAAqC;AAE1E,OAAO,SAASC,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,IAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aA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AACD,IAAI,KAAK,QAAQ,GACtB;UACEA,IAAI,EAAE,QAAQ;UACdc,MAAM,EAAEC,2BAA2B,CAACd,QAAQ,CAACa,MAAM,EAAEjB,WAAW;QAClE,CAAC,GACD;UACEG,IAAI,EAAE,QAAQ;UACdd,MAAM,EAAEU,2BAA2B,EAAAiB,gBAAA,GACjCZ,QAAQ,CAACf,MAAM,cAAA2B,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EACrBhB,WACF;QACF,CAAC,CACN;MAAA,EACH;IAAC;EAAA,CACD,CAAC;AACL;AAEA,SAASkB,2BAA2BA,CAClCD,MAAmB,EACnBjB,WAAoB,EACP;EACb,OAAOiB,MAAM,CAAC9C,GAAG,CAAEgD,KAAK,IACtBA,KAAK,CAAChB,IAAI,IAAIgB,KAAK,CAAChB,IAAI,KAAK,QAAQ,GACjCgB,KAAK,GAAAP,aAAA,CAAAA,aAAA,KAEAO,KAAK;IACR9B,MAAM,EAAEU,2BAA2B,CAACoB,KAAK,CAAC9B,MAAM,EAAEW,WAAW;EAAC,EAEtE,CAAC;AACH"}
1
+ {"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachItem","symbolForTplStateStoreId","computePropertyValue","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","_ref","from","to","filtered","filter","entry","length","refProperty","Boolean","slotProxies","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","runtimeContext","setupTemplateExternalBricks","forEachItem","forEachIndex","_loop","slotName","type","slotConf","quasis","flatMap","index","concat","entries","brick","_brick$slots","_objectSpread","Object","fromEntries","_ref2","_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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,gCAAgC,EAChCC,+BAA+B,EAC/BC,wBAAwB,QACnB,gBAAgB;AAEvB,SAASC,oBAAoB,QAAQ,qCAAqC;AAE1E,OAAO,SAASC,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,IAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAAoD;EAExD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,IAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,IAAMG,gBAAgB,GACpBC,cAAoC,IACX;QACzB,OAAOJ,eAAe,CACnBK,GAAG,CAACC,IAAA,IAAkB;UAAA,IAAjB;YAAEC,IAAI;YAAEC;UAAG,CAAC,GAAAF,IAAA;UAChB,IAAMG,QAAQ,GAAGL,cAAc,CAACM,MAAM,CACnCC,KAAK,IAAKA,KAAK,CAAC,CAAC,CAAC,KAAKJ,IAC1B,CAAC;UACD,IAAIE,QAAQ,CAACG,MAAM,GAAG,CAAC,IAAIJ,EAAE,CAACK,WAAW,EAAE;YACzC,OAAO,CACLL,EAAE,CAACK,WAAW,EACdxB,oBAAoB,CAACoB,QAAQ,EAAEF,IAAI,CAAC,EACpC,IAAI,CACL;UACH;QACF,CAAC,CAAC,CACDG,MAAM,CAACI,OAAO,CAAC;M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AK;IACR/B,MAAM,EAAEU,2BAA2B,CACjCqB,KAAK,CAAC/B,MAAM,EACZW,WAAW,EACXC,YACF;EAAC,EAET,CAAC;AACH"}
@@ -15,6 +15,7 @@ export function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHost
15
15
 
16
16
  // There is a boundary for `forEachItem` and `STATE` between form internals and externals.
17
17
  delete runtimeContext.forEachItem;
18
+ delete runtimeContext.forEachIndex;
18
19
  delete runtimeContext.tplStateStoreId;
19
20
  var formStateStore = new DataStore("FORM_STATE", undefined, rendererContext);
20
21
  runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);
@@ -1 +1 @@
1
- {"version":3,"file":"expandFormRenderer.js","names":["hasOwnProperty","uniqueId","DataStore","getDefaultProperties","symbolForFormStateStoreId","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","runtimeContext","_objectSpread","forEachItem","tplStateStoreId","formStateStore","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","brickConf","slot","formSchemasToBricks","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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,SAAS,QAAQ,sBAAsB;AAOhD,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,yBAAyB,QAAQ,gBAAgB;AAG1D,IAAMC,cAAc,GAAG,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,SAAS,CAAC;AAE7E,OAAO,SAASC,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EACrB;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EACX,IAAMC,kBAAkB,GACtB,OAAOP,QAAQ,KAAK,QAAQ,GAAGQ,IAA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,IAAI,EAAET,UAAU;IAChBX,MAAM;IACNX,OAAO;IACPgB,QAAQ,EAAEgB,mBAAmB,CAACX,MAAM,EAAEb,MAAM,EAAEnB,gBAAgB,CAAC;IAC/D,CAACb,yBAAyB,GAAGa;EAC/B,CAAc;EAEd,IAAIjB,cAAc,CAAC+C,MAAM,EAAE,IAAI,CAAC,EAAE;IAChCW,SAAS,CAACG,EAAE,GAAGd,MAAM,CAACc,EAAE;EAC1B;EAEA,OAAOH,SAAS;AAClB;AAEA,SAASE,mBAAmBA,CAC1BE,OAA2C,EAC3C1B,MAAyB,EACzBnB,gBAAwB,EACC;EACzB,IAAI8C,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAAE;IAC1B,OAAOA,OAAO,CAACG,GAAG,CAAElB,MAAM,IACxBb,iBAAiB,CAACa,MAAM,EAAEX,MAAM,EAAEnB,gBAAgB,CACpD,CAAC;EACH;AACF;AAEA,SAASuB,WAAWA,CAClB0B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,IAAM5B,MAAM,GAAG2B,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,CAAC,CAAC;EAEjC,KAAK,IAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChE5B,MAAM,CAAC6B,SAAS,CAAC,GAAGpE,cAAc,CAACuC,MAAM,EAAE6B,SAAS,CAAC,GACjD,CAAC7B,MAAM,CAAC6B,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAO9B,MAAM;AACf"}
1
+ {"version":3,"file":"expandFormRenderer.js","names":["hasOwnProperty","uniqueId","DataStore","getDefaultProperties","symbolForFormStateStoreId","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","runtimeContext","_objectSpread","forEachItem","forEachIndex","tplStateStoreId","formStateStore","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","brickConf","slot","formSchemasToBricks","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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,SAAS,QAAQ,sBAAsB;AAOhD,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,yBAAyB,QAAQ,gBAAgB;AAG1D,IAAMC,cAAc,GAAG,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,SAAS,CAAC;AAE7E,OAAO,SAASC,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EACrB;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EACX,IAAMC,kBAAkB,GACtB,OAAOP,QAAQ,KAAK,QAAQ,GAAGQ,IAAI,CAACC,KAAK,CAACT,QAAQ,CAAC,GAAGA,QACjC;EAEvB,IAAMU,gBAAgB,GAAGhB,QAAQ,CAAC,aAAa,CAAC;EAChD,IAAMiB,cAAc,GAAAC,aAAA,CAAAA,aAAA,KACfV,SAAS,CAACS,cAAc;IAC3BD;EAAgB,EACjB;;EAED;EACA,OAAOC,cAAc,CAACE,WAAW;EACjC,OAAOF,cAAc,CAACG,YAAY;EAClC,OAAOH,cAAc,CAACI,eAAe;EAErC,IAAMC,cAAc,GAAG,IAAIrB,SAAS,CAClC,YAAY,EACZsB,SAAS,EACTb,eACF,CAAC;EACDO,cAAc,CAACO,iBAAiB,CAACC,GAAG,CAACT,gBAAgB,EAAEM,cAAc,CAAC;EACtE,IAAIL,cAAc,CAACS,mBAAmB,EAAE;IACtCT,cAAc,CAACS,mBAAmB,CAACC,IAAI,CAACL,cAAc,CAAC;EACzD;;EAEA;EACA,IAAMM,OAAO,IAAAj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AACF;AAEA,SAASwB,WAAWA,CAClB0B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,IAAM5B,MAAM,GAAG2B,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,CAAC,CAAC;EAEjC,KAAK,IAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChE5B,MAAM,CAAC6B,SAAS,CAAC,GAAGrE,cAAc,CAACwC,MAAM,EAAE6B,SAAS,CAAC,GACjD,CAAC7B,MAAM,CAAC6B,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAO9B,MAAM;AACf"}
@@ -17,7 +17,7 @@ import { resolveData } from "./data/resolveData.js";
17
17
  import { asyncComputeRealValue } from "./compute/computeRealValue.js";
18
18
  import { listenOnTrackingContext } from "./compute/listenOnTrackingContext.js";
19
19
  import { matchRoute, matchRoutes } from "./matchRoutes.js";
20
- import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachItem, symbolForTplStateStoreId } from "./CustomTemplates/constants.js";
20
+ import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachIndex, symbolForTPlExternalForEachItem, symbolForTplStateStoreId } from "./CustomTemplates/constants.js";
21
21
  import { expandCustomTemplate } from "./CustomTemplates/expandCustomTemplate.js";
22
22
  import { getTagNameOfCustomTemplate, getTplStateStore } from "./CustomTemplates/utils.js";
23
23
  import { customTemplates } from "../CustomTemplates.js";
@@ -37,10 +37,7 @@ export function renderRoutes(_x, _x2, _x3, _x4, _x5, _x6, _x7) {
37
37
  function _renderRoutes() {
38
38
  _renderRoutes = _asyncToGenerator(function* (returnNode, routes, _runtimeContext, rendererContext, parentRoutes, slotId, isIncremental) {
39
39
  var matched = yield matchRoutes(routes, _runtimeContext);
40
- var output = {
41
- blockingList: [],
42
- menuRequests: []
43
- };
40
+ var output = getEmptyRenderOutput();
44
41
  switch (matched) {
45
42
  case "missed":
46
43
  break;
@@ -114,10 +111,7 @@ export function renderBricks(_x8, _x9, _x10, _x11, _x12, _x13, _x14, _x15) {
114
111
  }
115
112
  function _renderBricks() {
116
113
  _renderBricks = _asyncToGenerator(function* (returnNode, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
117
- var output = {
118
- blockingList: [],
119
- menuRequests: []
120
- };
114
+ var output = getEmptyRenderOutput();
121
115
  var kPath = keyPath !== null && keyPath !== void 0 ? keyPath : [];
122
116
  // 多个构件并行异步转换,但转换的结果按原顺序串行合并。
123
117
  var rendered = yield Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, parentRoutes, slotId, kPath.concat(index), tplStack && new Map(tplStack))));
@@ -140,10 +134,7 @@ function _renderBrick() {
140
134
  var _hooks$checkPermissio2, _runtimeContext$app;
141
135
  var keyPath = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : [];
142
136
  var tplStack = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : new Map();
143
- var output = {
144
- blockingList: [],
145
- menuRequests: []
146
- };
137
+ var output = getEmptyRenderOutput();
147
138
  if (!brickConf.brick) {
148
139
  if (brickConf.template) {
149
140
  // eslint-disable-next-line no-console
@@ -185,9 +176,10 @@ function _renderBrick() {
185
176
  formStateStoreId
186
177
  });
187
178
  if (hasOwnProperty(brickConf, symbolForTPlExternalForEachItem)) {
188
- // The external bricks of a template should restore their `forEachItem`
189
- // from their host.
179
+ // The external bricks of a template should restore their `forEachItem` and
180
+ // `forEachIndex` from their host.
190
181
  runtimeContext.forEachItem = brickConf[symbolForTPlExternalForEachItem];
182
+ runtimeContext.forEachIndex = brickConf[symbolForTPlExternalForEachIndex];
191
183
  }
192
184
  var {
193
185
  context
@@ -211,7 +203,7 @@ function _renderBrick() {
211
203
  var {
212
204
  dataSource
213
205
  } = brickConf;
214
- var renderControlNode = /*#__PURE__*/function () {
206
+ var lowerLevelRenderControlNode = /*#__PURE__*/function () {
215
207
  var _ref = _asyncToGenerator(function* (runtimeContext) {
216
208
  var _slots$slot;
217
209
  // First, compute the `dataSource`
@@ -226,13 +218,13 @@ function _renderBrick() {
226
218
  // Then, get the bricks in that matched slot.
227
219
  var bricks = slots && hasOwnProperty(slots, slot) && ((_slots$slot = slots[slot]) === null || _slots$slot === void 0 ? void 0 : _slots$slot.bricks);
228
220
  if (!Array.isArray(bricks)) {
229
- return output;
221
+ return getEmptyRenderOutput();
230
222
  }
231
223
  switch (brickName) {
232
224
  case ":forEach":
233
225
  {
234
226
  if (!Array.isArray(computedDataSource)) {
235
- return output;
227
+ return getEmptyRenderOutput();
236
228
  }
237
229
  return renderForEach(returnNode, computedDataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath);
238
230
  }
@@ -243,10 +235,24 @@ function _renderBrick() {
243
235
  }
244
236
  }
245
237
  });
246
- return function renderControlNode(_x31) {
238
+ return function lowerLevelRenderControlNode(_x31) {
247
239
  return _ref.apply(this, arguments);
248
240
  };
249
241
  }();
242
+ var renderControlNode = /*#__PURE__*/function () {
243
+ var _ref2 = _asyncToGenerator(function* (runtimeContext) {
244
+ var _rawOutput$node;
245
+ var rawOutput = yield lowerLevelRenderControlNode(runtimeContext);
246
+ (_rawOutput$node = rawOutput.node) !== null && _rawOutput$node !== void 0 ? _rawOutput$node : rawOutput.node = {
247
+ tag: RenderTag.PLACEHOLDER,
248
+ return: returnNode
249
+ };
250
+ return rawOutput;
251
+ });
252
+ return function renderControlNode(_x32) {
253
+ return _ref2.apply(this, arguments);
254
+ };
255
+ }();
250
256
  var controlledOutput = yield renderControlNode(runtimeContext);
251
257
  var {
252
258
  onMount,
@@ -260,12 +266,12 @@ function _renderBrick() {
260
266
  controlledOutput.hasTrackingControls = true;
261
267
  var renderId = 0;
262
268
  var listener = /*#__PURE__*/function () {
263
- var _ref2 = _asyncToGenerator(function* () {
269
+ var _ref3 = _asyncToGenerator(function* () {
264
270
  var currentRenderId = ++renderId;
265
271
  var [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(runtimeContext);
266
- var controlOutput = yield renderControlNode(scopedRuntimeContext);
272
+ var reControlledOutput = yield renderControlNode(scopedRuntimeContext);
267
273
  var scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
268
- yield postAsyncRender(controlOutput, scopedRuntimeContext, scopedStores);
274
+ yield postAsyncRender(reControlledOutput, scopedRuntimeContext, scopedStores);
269
275
 
270
276
  // Ignore stale renders
271
277
  if (renderId === currentRenderId) {
@@ -276,7 +282,7 @@ function _renderBrick() {
276
282
  }
277
283
  }));
278
284
  }
279
- rendererContext.reRender(slotId, keyPath, controlOutput.node, returnNode);
285
+ rendererContext.reRender(slotId, keyPath, reControlledOutput.node, returnNode);
280
286
  if (onMount) {
281
287
  listenerFactory(onMount, scopedRuntimeContext)(new CustomEvent("mount", {
282
288
  detail: {
@@ -290,7 +296,7 @@ function _renderBrick() {
290
296
  }
291
297
  });
292
298
  return function listener() {
293
- return _ref2.apply(this, arguments);
299
+ return _ref3.apply(this, arguments);
294
300
  };
295
301
  }();
296
302
  var debouncedListener = debounce(listener);
@@ -354,12 +360,12 @@ function _renderBrick() {
354
360
  var confProps;
355
361
  if (brickName === FORM_RENDERER) {
356
362
  var _brickConf$properties;
357
- var _ref3 = (_brickConf$properties = brickConf.properties) !== null && _brickConf$properties !== void 0 ? _brickConf$properties : {};
363
+ var _ref4 = (_brickConf$properties = brickConf.properties) !== null && _brickConf$properties !== void 0 ? _brickConf$properties : {};
358
364
  ({
359
365
  formData
360
- } = _ref3);
361
- confProps = _objectWithoutProperties(_ref3, _excluded3);
362
- _ref3;
366
+ } = _ref4);
367
+ confProps = _objectWithoutProperties(_ref4, _excluded3);
368
+ _ref4;
363
369
  } else {
364
370
  confProps = brickConf.properties;
365
371
  }
@@ -413,12 +419,12 @@ function _renderBrick() {
413
419
  // 加载构件属性和加载子构件等任务,可以并行。
414
420
  var blockingList = [];
415
421
  var loadProperties = /*#__PURE__*/function () {
416
- var _ref4 = _asyncToGenerator(function* () {
422
+ var _ref5 = _asyncToGenerator(function* () {
417
423
  brick.properties = yield constructAsyncProperties(asyncPropertyEntries);
418
424
  listenOnTrackingContext(brick, trackingContextList);
419
425
  });
420
426
  return function loadProperties() {
421
- return _ref4.apply(this, arguments);
427
+ return _ref5.apply(this, arguments);
422
428
  };
423
429
  }();
424
430
  blockingList.push(loadProperties());
@@ -438,25 +444,26 @@ function _renderBrick() {
438
444
  // There is a boundary for `forEachItem` between template internals and externals.
439
445
  childRuntimeContext = _objectSpread({}, runtimeContext);
440
446
  delete childRuntimeContext.forEachItem;
447
+ delete childRuntimeContext.forEachIndex;
441
448
  } else {
442
449
  childRuntimeContext = runtimeContext;
443
450
  }
444
451
  var loadChildren = /*#__PURE__*/function () {
445
- var _ref5 = _asyncToGenerator(function* () {
452
+ var _ref6 = _asyncToGenerator(function* () {
446
453
  var slots = childrenToSlots(expandedBrickConf.children, expandedBrickConf.slots);
447
454
  if (!slots) {
448
455
  return;
449
456
  }
450
457
  var routeSlotIndexes = new Set();
451
- var rendered = yield Promise.all(Object.entries(slots).map((_ref6, index) => {
452
- var [childSlotId, slotConf] = _ref6;
458
+ var rendered = yield Promise.all(Object.entries(slots).map((_ref7, index) => {
459
+ var [childSlotId, slotConf] = _ref7;
453
460
  if (slotConf.type !== "routes") {
454
461
  return renderBricks(brick, slotConf.bricks, childRuntimeContext, rendererContext, parentRoutes, childSlotId, tplStack);
455
462
  }
456
463
  if (runtimeContext.flags["incremental-sub-route-rendering"]) {
457
464
  routeSlotIndexes.add(index);
458
465
  rendererContext.performIncrementalRender( /*#__PURE__*/function () {
459
- var _ref7 = _asyncToGenerator(function* (location) {
466
+ var _ref8 = _asyncToGenerator(function* (location) {
460
467
  var {
461
468
  homepage
462
469
  } = childRuntimeContext.app;
@@ -513,8 +520,8 @@ function _renderBrick() {
513
520
  }
514
521
  return true;
515
522
  });
516
- return function (_x32) {
517
- return _ref7.apply(this, arguments);
523
+ return function (_x33) {
524
+ return _ref8.apply(this, arguments);
518
525
  };
519
526
  }());
520
527
  }
@@ -540,7 +547,7 @@ function _renderBrick() {
540
547
  }));
541
548
  });
542
549
  return function loadChildren() {
543
- return _ref5.apply(this, arguments);
550
+ return _ref6.apply(this, arguments);
544
551
  };
545
552
  }();
546
553
  blockingList.push(loadChildren());
@@ -564,13 +571,11 @@ function renderForEach(_x22, _x23, _x24, _x25, _x26, _x27, _x28, _x29, _x30) {
564
571
  }
565
572
  function _renderForEach() {
566
573
  _renderForEach = _asyncToGenerator(function* (returnNode, dataSource, bricks, runtimeContext, rendererContext, parentRoutes, slotId, tplStack, keyPath) {
567
- var output = {
568
- blockingList: [],
569
- menuRequests: []
570
- };
574
+ var output = getEmptyRenderOutput();
571
575
  var rows = dataSource.length;
572
576
  var rendered = yield Promise.all(dataSource.map((item, i) => Promise.all(bricks.map((brickConf, j) => renderBrick(returnNode, brickConf, _objectSpread(_objectSpread({}, runtimeContext), {}, {
573
- forEachItem: item
577
+ forEachItem: item,
578
+ forEachIndex: i
574
579
  }), rendererContext, parentRoutes, slotId, keyPath.concat(i * rows + j), tplStack && new Map(tplStack))))));
575
580
 
576
581
  // 多层构件并行异步转换,但转换的结果按原顺序串行合并。
@@ -645,6 +650,12 @@ function mergeRenderOutput(output, newOutput) {
645
650
  }
646
651
  Object.assign(output, rest);
647
652
  }
653
+ function getEmptyRenderOutput() {
654
+ return {
655
+ blockingList: [],
656
+ menuRequests: []
657
+ };
658
+ }
648
659
  export function childrenToSlots(children, originalSlots) {
649
660
  var newSlots = originalSlots;
650
661
  // istanbul ignore next