@next-core/runtime 1.52.1 → 1.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/internal/CustomTemplates/constants.js +1 -2
  2. package/dist/cjs/internal/CustomTemplates/constants.js.map +1 -1
  3. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +1 -2
  4. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  5. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +10 -18
  6. package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  7. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js +2 -1
  8. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -1
  9. package/dist/cjs/internal/FormRenderer/registerFormRenderer.js +47 -0
  10. package/dist/cjs/internal/FormRenderer/registerFormRenderer.js.map +1 -0
  11. package/dist/cjs/internal/Renderer.js +2 -9
  12. package/dist/cjs/internal/Renderer.js.map +1 -1
  13. package/dist/cjs/internal/Runtime.js +8 -7
  14. package/dist/cjs/internal/Runtime.js.map +1 -1
  15. package/dist/cjs/internal/interfaces.js.map +1 -1
  16. package/dist/esm/internal/CustomTemplates/constants.js +0 -1
  17. package/dist/esm/internal/CustomTemplates/constants.js.map +1 -1
  18. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +1 -2
  19. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  20. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +11 -19
  21. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  22. package/dist/esm/internal/FormRenderer/expandFormRenderer.js +1 -1
  23. package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -1
  24. package/dist/esm/internal/FormRenderer/registerFormRenderer.js +47 -0
  25. package/dist/esm/internal/FormRenderer/registerFormRenderer.js.map +1 -0
  26. package/dist/esm/internal/Renderer.js +3 -10
  27. package/dist/esm/internal/Renderer.js.map +1 -1
  28. package/dist/esm/internal/Runtime.js +8 -7
  29. package/dist/esm/internal/Runtime.js.map +1 -1
  30. package/dist/esm/internal/interfaces.js.map +1 -1
  31. package/dist/types/internal/CustomTemplates/constants.d.ts +0 -2
  32. package/dist/types/internal/FormRenderer/expandFormRenderer.d.ts +1 -0
  33. package/dist/types/internal/FormRenderer/registerFormRenderer.d.ts +1 -0
  34. package/dist/types/internal/interfaces.d.ts +0 -1
  35. package/package.json +6 -6
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.symbolForTplStateStoreId = exports.symbolForTPlExternalNoForEach = exports.symbolForTPlExternalForEachSize = exports.symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachIndex = exports.symbolForAsyncComputedPropsFromHost = void 0;
6
+ exports.symbolForTplStateStoreId = exports.symbolForTPlExternalForEachSize = exports.symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachIndex = exports.symbolForAsyncComputedPropsFromHost = void 0;
7
7
  const symbolForAsyncComputedPropsFromHost = exports.symbolForAsyncComputedPropsFromHost = Symbol.for("tpl.asyncComputedPropsFromHost");
8
8
  const symbolForTplStateStoreId = exports.symbolForTplStateStoreId = Symbol.for("tpl.stateStoreId");
9
9
  const symbolForTPlExternalForEachItem = exports.symbolForTPlExternalForEachItem = Symbol.for("tpl.externalForEachItem");
10
10
  const symbolForTPlExternalForEachIndex = exports.symbolForTPlExternalForEachIndex = Symbol.for("tpl.externalForEachIndex");
11
11
  const symbolForTPlExternalForEachSize = exports.symbolForTPlExternalForEachSize = Symbol.for("tpl.externalForEachSize");
12
- const symbolForTPlExternalNoForEach = exports.symbolForTPlExternalNoForEach = Symbol.for("tpl.externalNoForEach");
13
12
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","exports","Symbol","for","symbolForTplStateStoreId","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachSize","symbolForTPlExternalNoForEach"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncPropertyEntry } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\nexport const symbolForTPlExternalForEachIndex = Symbol.for(\n \"tpl.externalForEachIndex\"\n);\nexport const symbolForTPlExternalForEachSize = Symbol.for(\n \"tpl.externalForEachSize\"\n);\nexport const symbolForTPlExternalNoForEach = Symbol.for(\n \"tpl.externalNoForEach\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n [symbolForTPlExternalForEachIndex]?: number;\n [symbolForTPlExternalForEachSize]?: number;\n [symbolForTPlExternalNoForEach]?: boolean;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAAC,OAAA,CAAAD,mCAAA,GAAGE,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AACM,MAAMC,wBAAwB,GAAAH,OAAA,CAAAG,wBAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAC/D,MAAME,+BAA+B,GAAAJ,OAAA,CAAAI,+BAAA,GAAGH,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AACM,MAAMG,gCAAgC,GAAAL,OAAA,CAAAK,gCAAA,GAAGJ,MAAM,CAACC,GAAG,CACxD,0BACF,CAAC;AACM,MAAMI,+BAA+B,GAAAN,OAAA,CAAAM,+BAAA,GAAGL,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AACM,MAAMK,6BAA6B,GAAAP,OAAA,CAAAO,6BAAA,GAAGN,MAAM,CAACC,GAAG,CACrD,uBACF,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","names":["symbolForAsyncComputedPropsFromHost","exports","Symbol","for","symbolForTplStateStoreId","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachSize"],"sources":["../../../../src/internal/CustomTemplates/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\nimport type { AsyncPropertyEntry } from \"../interfaces.js\";\n\nexport const symbolForAsyncComputedPropsFromHost = Symbol.for(\n \"tpl.asyncComputedPropsFromHost\"\n);\nexport const symbolForTplStateStoreId = Symbol.for(\"tpl.stateStoreId\");\nexport const symbolForTPlExternalForEachItem = Symbol.for(\n \"tpl.externalForEachItem\"\n);\nexport const symbolForTPlExternalForEachIndex = Symbol.for(\n \"tpl.externalForEachIndex\"\n);\nexport const symbolForTPlExternalForEachSize = Symbol.for(\n \"tpl.externalForEachSize\"\n);\n\nexport type RuntimeBrickConfWithTplSymbols = BrickConf &\n RuntimeBrickConfOfTplSymbols;\n\nexport interface RuntimeBrickConfOfTplSymbols {\n [symbolForAsyncComputedPropsFromHost]?: AsyncPropertyEntry[];\n [symbolForTplStateStoreId]?: string;\n [symbolForTPlExternalForEachItem]?: unknown;\n [symbolForTPlExternalForEachIndex]?: number;\n [symbolForTPlExternalForEachSize]?: number;\n}\n"],"mappings":";;;;;;AAGO,MAAMA,mCAAmC,GAAAC,OAAA,CAAAD,mCAAA,GAAGE,MAAM,CAACC,GAAG,CAC3D,gCACF,CAAC;AACM,MAAMC,wBAAwB,GAAAH,OAAA,CAAAG,wBAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,kBAAkB,CAAC;AAC/D,MAAME,+BAA+B,GAAAJ,OAAA,CAAAI,+BAAA,GAAGH,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC;AACM,MAAMG,gCAAgC,GAAAL,OAAA,CAAAK,gCAAA,GAAGJ,MAAM,CAACC,GAAG,CACxD,0BACF,CAAC;AACM,MAAMI,+BAA+B,GAAAN,OAAA,CAAAM,+BAAA,GAAGL,MAAM,CAACC,GAAG,CACvD,yBACF,CAAC","ignoreList":[]}
@@ -89,8 +89,7 @@ function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropert
89
89
  asyncHostPropertyEntries,
90
90
  externalSlots: (0, _Renderer.childrenToSlots)(externalChildren, originalExternalSlots),
91
91
  tplStateStoreId,
92
- hostBrick: hostBrick,
93
- __temporary_tpl_tag_name: tplTagName
92
+ hostBrick: hostBrick
94
93
  };
95
94
  newBrickConf.slots = {
96
95
  "": {
@@ -1 +1 @@
1
- {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","__temporary_tpl_tag_name","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n __temporary_tpl_tag_name: tplTagName,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAGO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGN,SAAS,CAACM,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,WAAW;EACjC,OAAOH,cAAc,CAACI,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIC,oBAAS,CACjC,OAAO,EACPZ,SAAS,EACTE,eAAe,EACfE,eACF,CAAC;EACDE,cAAc,CAACO,gBAAgB,CAACC,GAAG,CAACV,eAAe,EAAEO,aAAa,CAAC;EACnE,IAAIL,cAAc,CAACS,kBAAkB,EAAE;IACrCT,cAAc,CAACS,kBAAkB,CAACC,IAAI,CAACL,aAAa,CAAC;EACvD;EAEA,MAAM;IAAEM,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAGC,gCAAe,CAACC,GAAG,CAACxB,UAAU,CAAE;EAC5EyB,cAAK,aAALA,cAAK,gBAAApB,cAAA,GAALoB,cAAK,CAAEC,OAAO,cAAArB,cAAA,eAAdA,cAAA,CAA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C,KAAK,CAClED,QAAQ,EACR;IACEX,IAAI,EAAE,QAAQ;IACdhC,MAAM,EAAE,CAAC4C,QAAQ,CAAC5C,MAAM,IAAI,EAAE,EAAEiC,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEN,WAAW,CACzC;EACF,CAAC,CACF,CACH,CAAC;EAED,OAAO;IACL,GAAGY,uBAAuB;IAC1BnB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEY,uBAAuB,CAACb,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_Runtime","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","hooks","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\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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B,CAACD,IAAI,EAAEL,WAAW,CACzC;EACF,CAAC,CACF,CACH,CAAC;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAuB,gDAAuB,EAACvB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAmC,sCAAkB,EAACjB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH","ignoreList":[]}
@@ -64,7 +64,7 @@ function setupTemplateProxy(hostContext, ref, slots) {
64
64
  // External bricks of a template, should not access the template internal forEach `ITEM`.
65
65
  // For some existing templates who is *USING* this bug, we keep the old behavior.
66
66
  const hostHasForEach = (0, _general.hasOwnProperty)(hostBrick.runtimeContext, "forEachItem");
67
- expandableSlot[(0, _lodash.clamp)(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((hostContext.__temporary_tpl_tag_name === "base-layout-v3.tpl-scroll-load-list" || hostContext.__temporary_tpl_tag_name === "shrcb-homepage.tpl-custom-scroll-load-list") && !hostHasForEach ? insertBricks : setupTemplateExternalBricks(insertBricks, hostHasForEach, hostBrick.runtimeContext.forEachItem, hostBrick.runtimeContext.forEachIndex, hostBrick.runtimeContext.forEachSize)));
67
+ expandableSlot[(0, _lodash.clamp)(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...(!hostHasForEach ? insertBricks : setupTemplateExternalBricksWithForEach(insertBricks, hostBrick.runtimeContext.forEachItem, hostBrick.runtimeContext.forEachIndex, hostBrick.runtimeContext.forEachSize)));
68
68
  }
69
69
  for (const [slotName, quasis] of quasisMap.entries()) {
70
70
  if (!(0, _general.hasOwnProperty)(slots, slotName)) {
@@ -88,41 +88,33 @@ function setupTemplateProxy(hostContext, ref, slots) {
88
88
  }
89
89
 
90
90
  // External bricks of a template, have the same forEachItem context as their host.
91
- function setupTemplateExternalBricks(bricks, hasForEach, forEachItem, forEachIndex, forEachSize) {
91
+ function setupTemplateExternalBricksWithForEach(bricks, forEachItem, forEachIndex, forEachSize) {
92
92
  return bricks.map(({
93
93
  children,
94
94
  slots,
95
- [_constants.symbolForTPlExternalForEachItem]: a,
96
- [_constants.symbolForTPlExternalForEachIndex]: b,
97
- [_constants.symbolForTPlExternalForEachSize]: c,
98
- [_constants.symbolForTPlExternalNoForEach]: d,
99
95
  ...brick
100
96
  }) => ({
101
97
  ...brick,
102
- ...(hasForEach ? {
103
- [_constants.symbolForTPlExternalForEachItem]: forEachItem,
104
- [_constants.symbolForTPlExternalForEachIndex]: forEachIndex,
105
- [_constants.symbolForTPlExternalForEachSize]: forEachSize
106
- } : {
107
- [_constants.symbolForTPlExternalNoForEach]: true
108
- }),
98
+ [_constants.symbolForTPlExternalForEachItem]: forEachItem,
99
+ [_constants.symbolForTPlExternalForEachIndex]: forEachIndex,
100
+ [_constants.symbolForTPlExternalForEachSize]: forEachSize,
109
101
  // Keep `:forEach` bricks as original, since they have their own forEachItem context.
110
102
  slots: brick.brick === ":forEach" ? (0, _Renderer.childrenToSlots)(children, slots) : Object.fromEntries(Object.entries((0, _Renderer.childrenToSlots)(children, slots) ?? {}).map(([slotName, slotConf]) => [slotName, slotConf.type === "routes" ? {
111
103
  type: "routes",
112
- routes: setupTemplateExternalRoutes(slotConf.routes, hasForEach, forEachItem, forEachIndex, forEachSize)
104
+ routes: setupTemplateExternalRoutesWithForEach(slotConf.routes, forEachItem, forEachIndex, forEachSize)
113
105
  } : {
114
106
  type: "bricks",
115
- bricks: setupTemplateExternalBricks(slotConf.bricks, hasForEach, forEachItem, forEachIndex, forEachSize)
107
+ bricks: setupTemplateExternalBricksWithForEach(slotConf.bricks, forEachItem, forEachIndex, forEachSize)
116
108
  }]))
117
109
  }));
118
110
  }
119
- function setupTemplateExternalRoutes(routes, hasForEach, forEachItem, forEachIndex, forEachSize) {
111
+ function setupTemplateExternalRoutesWithForEach(routes, forEachItem, forEachIndex, forEachSize) {
120
112
  return routes.map(route => route.type === "routes" ? {
121
113
  ...route,
122
- routes: setupTemplateExternalRoutes(route.routes, hasForEach, forEachItem, forEachIndex, forEachSize)
114
+ routes: setupTemplateExternalRoutesWithForEach(route.routes, forEachItem, forEachIndex, forEachSize)
123
115
  } : route.type === "redirect" ? route : {
124
116
  ...route,
125
- bricks: setupTemplateExternalBricks(route.bricks, hasForEach, forEachItem, forEachIndex, forEachSize)
117
+ bricks: setupTemplateExternalBricksWithForEach(route.bricks, forEachItem, forEachIndex, forEachSize)
126
118
  });
127
119
  }
128
120
  //# sourceMappingURL=setupTemplateProxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","_Renderer","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","from","to","filtered","filter","entry","length","refProperty","computePropertyValue","Boolean","slotProxies","quasisMap","Map","_externalSlots$from","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","hostHasForEach","runtimeContext","clamp","__temporary_tpl_tag_name","setupTemplateExternalBricks","forEachItem","forEachIndex","forEachSize","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","hasForEach","children","symbolForTPlExternalForEachItem","a","symbolForTPlExternalForEachIndex","b","symbolForTPlExternalForEachSize","c","symbolForTPlExternalNoForEach","d","brick","childrenToSlots","Object","fromEntries","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTPlExternalForEachSize,\n symbolForTPlExternalNoForEach,\n symbolForTplStateStoreId,\n type RuntimeBrickConfWithTplSymbols,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n // External bricks of a template, should not access the template internal forEach `ITEM`.\n // For some existing templates who is *USING* this bug, we keep the old behavior.\n const hostHasForEach = hasOwnProperty(\n hostBrick.runtimeContext,\n \"forEachItem\"\n );\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...((hostContext.__temporary_tpl_tag_name ===\n \"base-layout-v3.tpl-scroll-load-list\" ||\n hostContext.__temporary_tpl_tag_name ===\n \"shrcb-homepage.tpl-custom-scroll-load-list\") &&\n !hostHasForEach\n ? insertBricks\n : setupTemplateExternalBricks(\n insertBricks,\n hostHasForEach,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!,\n hostBrick.runtimeContext.forEachSize!\n ))\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number,\n forEachSize: number\n): BrickConf[] {\n return (bricks as RuntimeBrickConfWithTplSymbols[]).map(\n ({\n children,\n slots,\n [symbolForTPlExternalForEachItem]: a,\n [symbolForTPlExternalForEachIndex]: b,\n [symbolForTPlExternalForEachSize]: c,\n [symbolForTPlExternalNoForEach]: d,\n ...brick\n }) => ({\n ...brick,\n ...(hasForEach\n ? {\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n [symbolForTPlExternalForEachSize]: forEachSize,\n }\n : {\n [symbolForTPlExternalNoForEach]: true,\n }),\n // Keep `:forEach` bricks as original, since they have their own forEachItem context.\n slots:\n brick.brick === \":forEach\"\n ? childrenToSlots(children, slots)\n : Object.fromEntries(\n Object.entries(childrenToSlots(children, slots) ?? {}).map(\n ([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(\n slotConf.routes,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n },\n ]\n )\n ),\n })\n );\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number,\n forEachSize: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type === \"routes\"\n ? {\n ...route,\n routes: setupTemplateExternalRoutes(\n route.routes,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n : route.type === \"redirect\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(\n route.bricks,\n hasForEach,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAUA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,MAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,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1
+ {"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","_Renderer","setupTemplateProxy","hostContext","ref","slots","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","from","to","filtered","filter","entry","length","refProperty","computePropertyValue","Boolean","slotProxies","quasisMap","Map","_externalSlots$from","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","hostHasForEach","runtimeContext","clamp","setupTemplateExternalBricksWithForEach","forEachItem","forEachIndex","forEachSize","slotName","quasis","entries","type","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","children","brick","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachSize","childrenToSlots","Object","fromEntries","routes","setupTemplateExternalRoutesWithForEach","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTPlExternalForEachSize,\n symbolForTplStateStoreId,\n type RuntimeBrickConfWithTplSymbols,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n // External bricks of a template, should not access the template internal forEach `ITEM`.\n // For some existing templates who is *USING* this bug, we keep the old behavior.\n const hostHasForEach = hasOwnProperty(\n hostBrick.runtimeContext,\n \"forEachItem\"\n );\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...(!hostHasForEach\n ? insertBricks\n : setupTemplateExternalBricksWithForEach(\n insertBricks,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!,\n hostBrick.runtimeContext.forEachSize!\n ))\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricksWithForEach(\n bricks: BrickConf[],\n forEachItem: unknown,\n forEachIndex: number,\n forEachSize: number\n): BrickConf[] {\n return (bricks as RuntimeBrickConfWithTplSymbols[]).map(\n ({ children, slots, ...brick }) => ({\n ...brick,\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n [symbolForTPlExternalForEachSize]: forEachSize,\n // Keep `:forEach` bricks as original, since they have their own forEachItem context.\n slots:\n brick.brick === \":forEach\"\n ? childrenToSlots(children, slots)\n : Object.fromEntries(\n Object.entries(childrenToSlots(children, slots) ?? {}).map(\n ([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutesWithForEach(\n slotConf.routes,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricksWithForEach(\n slotConf.bricks,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n },\n ]\n )\n ),\n })\n );\n}\n\nfunction setupTemplateExternalRoutesWithForEach(\n routes: RouteConf[],\n forEachItem: unknown,\n forEachIndex: number,\n forEachSize: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type === \"routes\"\n ? {\n ...route,\n routes: setupTemplateExternalRoutesWithForEach(\n route.routes,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n : route.type === \"redirect\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricksWithForEach(\n route.bricks,\n forEachItem,\n forEachIndex,\n forEachSize\n ),\n }\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AASA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxB;EACA,MAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAAoD;EAExD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,MAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,MAAMG,gBAAgB,GACpBC,cAAoC,IACX;QACzB,OAAOJ,eAAe,CACnBK,GAAG,CAAC,CAAC;UAAEC,IAAI;UAAEC;QAAG,CAAC,KAAK;UACrB,MAAMC,QAAQ,GAAGJ,cAAc,CAACK,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,EACd,IAAAC,2CAAoB,EAACL,QAAQ,EAAEF,IAAI,CAAC,EACpC,IAAI,CACL;UACH;QACF,CAAC,CAAC,CACDG,MAAM,CAACK,OAAO,CAAC;MACpB,CAAC;MAEDf,kBAAkB,GAAGI,gBAAgB,CAACR,wBAAwB,CAAC;IACjE;IAEA,MAAMoB,WAAW,GAAGrB,eAAe,CAACD,KAAK,CAACS,GAAG,CAACV,GAAG,CAAC;I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,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
@@ -4,12 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.expandFormRenderer = expandFormRenderer;
7
+ exports.formContainers = void 0;
7
8
  var _general = require("@next-core/utils/general");
8
9
  var _lodash = require("lodash");
9
10
  var _DataStore = require("../data/DataStore.js");
10
11
  var _getDefaultProperties = require("./getDefaultProperties.js");
11
12
  var _constants = require("./constants.js");
12
- const formContainers = ["forms.general-form", "form.general-form", "eo-form"];
13
+ const formContainers = exports.formContainers = ["forms.general-form", "form.general-form", "eo-form"];
13
14
  function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
14
15
  var _hostBrickConf$proper;
15
16
  const normalizedFormData = typeof formData === "string" ? JSON.parse(formData) : formData;
@@ -1 +1 @@
1
- {"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","tplStateStoreId","formStateStore","DataStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncPropertyEntry, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst formContainers = [\"forms.general-form\", \"form.general-form\", \"eo-form\"];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext,\n formStateStoreId\n );\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostPropertyEntries);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formContainers.includes(formConf.brick) && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"eo-micro-view\",\n properties: { style: { padding: \"12px\" } },\n children: [formConf],\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAGA,MAAMK,cAAc,GAAG,CAAC,oBAAoB,EAAE,mBAAmB,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"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","formContainers","exports","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","forEachIndex","forEachSize","tplStateStoreId","formStateStore","DataStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncPropertyEntry, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nexport const formContainers = [\n \"forms.general-form\",\n \"form.general-form\",\n \"eo-form\",\n];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext,\n formStateStoreId\n );\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostPropertyEntries);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formContainers.includes(formConf.brick) && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"eo-micro-view\",\n properties: { style: { padding: \"12px\" } },\n children: [formConf],\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAGO,MAAMK,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,CAC5B,oBAAoB,EACpB,mBAAmB,EACnB,SAAS,CACV;AAEM,SAASE,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EACrB;EAAA,IAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAON,QAAQ,KAAK,QAAQ,GAAGO,IAAI,CAACC,KAAK,CAACR,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMS,gBAAgB,GAAG,IAAAC,gBAAQ,EAAC,aAAa,CAAC;EAChD,MAAMC,cAAc,GAAG;IACrB,GAAGT,SAAS,CAACS,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,WAAW;EACjC,OAAOH,cAAc,CAACI,eAAe;EAErC,MA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E,mBAAmBA,CAC1BI,OAA2C,EAC3C7B,MAAyB,EACzBtB,gBAAwB,EACC;EACzB,IAAIoD,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAAE;IAC1B,OAAOA,OAAO,CAACG,GAAG,CAAErB,MAAM,IACxBb,iBAAiB,CAACa,MAAM,EAAEX,MAAM,EAAEtB,gBAAgB,CACpD,CAAC;EACH;AACF;AAEA,SAAS0B,WAAWA,CAClB6B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,MAAM/B,MAAM,GAAG8B,YAAY,IAAI,CAAC,CAAC;EAEjC,KAAK,MAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChE/B,MAAM,CAACgC,SAAS,CAAC,GAAG,IAAAR,uBAAc,EAACxB,MAAM,EAAEgC,SAAS,CAAC,GACjD,CAAChC,MAAM,CAACgC,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAOjC,MAAM;AACf","ignoreList":[]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.registerFormRenderer = registerFormRenderer;
8
+ var _classPrivateMethodInitSpec2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateMethodInitSpec"));
9
+ var _assertClassBrand2 = _interopRequireDefault(require("@babel/runtime/helpers/assertClassBrand"));
10
+ var _constants = require("./constants.js");
11
+ var _expandFormRenderer = require("./expandFormRenderer.js");
12
+ var _FormElement_brand = /*#__PURE__*/new WeakSet();
13
+ class FormElement extends HTMLElement {
14
+ constructor(..._args) {
15
+ super(..._args);
16
+ (0, _classPrivateMethodInitSpec2.default)(this, _FormElement_brand);
17
+ }
18
+ get $$typeof() {
19
+ return "formRenderer";
20
+ }
21
+ validate() {
22
+ (0, _assertClassBrand2.default)(_FormElement_brand, this, _proxyFormMethod).call(this, "validate");
23
+ }
24
+ setInitValue(...args) {
25
+ (0, _assertClassBrand2.default)(_FormElement_brand, this, _proxyFormMethod).call(this, "setInitValue", args);
26
+ }
27
+ resetFields(...args) {
28
+ (0, _assertClassBrand2.default)(_FormElement_brand, this, _proxyFormMethod).call(this, "resetFields", args);
29
+ }
30
+ }
31
+ function _proxyFormMethod(method, args = []) {
32
+ var _containerElement$tag;
33
+ const containerElement = this.firstElementChild;
34
+ const tagName = containerElement === null || containerElement === void 0 || (_containerElement$tag = containerElement.tagName) === null || _containerElement$tag === void 0 ? void 0 : _containerElement$tag.toLowerCase();
35
+ if (_expandFormRenderer.formContainers.includes(tagName)) {
36
+ containerElement[method](...args);
37
+ } else {
38
+ // eslint-disable-next-line no-console
39
+ console.error(`no ${method} method in the container element`, {
40
+ container: tagName
41
+ });
42
+ }
43
+ }
44
+ function registerFormRenderer() {
45
+ customElements.get(_constants.FORM_RENDERER) || customElements.define(_constants.FORM_RENDERER, FormElement);
46
+ }
47
+ //# sourceMappingURL=registerFormRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerFormRenderer.js","names":["_constants","require","_expandFormRenderer","_FormElement_brand","WeakSet","FormElement","HTMLElement","constructor","_args","_classPrivateMethodInitSpec2","default","$$typeof","validate","_assertClassBrand2","_proxyFormMethod","call","setInitValue","args","resetFields","method","_containerElement$tag","containerElement","firstElementChild","tagName","toLowerCase","formContainers","includes","console","error","container","registerFormRenderer","customElements","get","FORM_RENDERER","define"],"sources":["../../../../src/internal/FormRenderer/registerFormRenderer.ts"],"sourcesContent":["import { FORM_RENDERER } from \"./constants.js\";\nimport { formContainers } from \"./expandFormRenderer.js\";\n\nclass FormElement extends HTMLElement {\n get $$typeof(): string {\n return \"formRenderer\";\n }\n\n #proxyFormMethod(method: string, args: unknown[] = []): void {\n const containerElement = this.firstElementChild;\n\n const tagName = containerElement?.tagName?.toLowerCase();\n\n if (formContainers.includes(tagName as string)) {\n (containerElement as any)[method](...args);\n } else {\n // eslint-disable-next-line no-console\n console.error(`no ${method} method in the container element`, {\n container: tagName,\n });\n }\n }\n\n validate(): void {\n this.#proxyFormMethod(\"validate\");\n }\n\n setInitValue(...args: unknown[]): void {\n this.#proxyFormMethod(\"setInitValue\", args);\n }\n\n resetFields(...args: unknown[]): void {\n this.#proxyFormMethod(\"resetFields\", args);\n }\n}\n\nexport function registerFormRenderer(): void {\n customElements.get(FORM_RENDERER) ||\n customElements.define(FORM_RENDERER, FormElement);\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AAAyD,IAAAE,kBAAA,oBAAAC,OAAA;AAEzD,MAAMC,WAAW,SAASC,WAAW,CAAC;EAAAC,YAAA,GAAAC,KAAA;IAAA,SAAAA,KAAA;IAAA,IAAAC,4BAAA,CAAAC,OAAA,QAAAP,kBAAA;EAAA;EACpC,IAAIQ,QAAQA,CAAA,EAAW;IACrB,OAAO,cAAc;EACvB;EAiBAC,QAAQA,CAAA,EAAS;IACf,IAAAC,kBAAA,CAAAH,OAAA,EAAAP,kBAAA,MAAI,EAACW,gBAAe,CAAC,CAAAC,IAAA,CAArB,IAAI,EAAkB,UAAU;EAClC;EAEAC,YAAYA,CAAC,GAAGC,IAAe,EAAQ;IACrC,IAAAJ,kBAAA,CAAAH,OAAA,EAAAP,kBAAA,MAAI,EAACW,gBAAe,CAAC,CAAAC,IAAA,CAArB,IAAI,EAAkB,cAAc,EAAEE,IAAI;EAC5C;EAEAC,WAAWA,CAAC,GAAGD,IAAe,EAAQ;IACpC,IAAAJ,kBAAA,CAAAH,OAAA,EAAAP,kBAAA,MAAI,EAACW,gBAAe,CAAC,CAAAC,IAAA,CAArB,IAAI,EAAkB,aAAa,EAAEE,IAAI;EAC3C;AACF;AAAC,SAAAH,iBA1BkBK,MAAc,EAAEF,IAAe,GAAG,EAAE,EAAQ;EAAA,IAAAG,qBAAA;EAC3D,MAAMC,gBAAgB,GAAG,IAAI,CAACC,iBAAiB;EAE/C,MAAMC,OAAO,GAAGF,gBAAgB,aAAhBA,gBAAgB,gBAAAD,qBAAA,GAAhBC,gBAAgB,CAAEE,OAAO,cAAAH,qBAAA,uBAAzBA,qBAAA,CAA2BI,WAAW,CAAC,CAAC;EAExD,IAAIC,kCAAc,CAACC,QAAQ,CAACH,OAAiB,CAAC,EAAE;IAC7CF,gBAAgB,CAASF,MAAM,CAAC,CAAC,GAAGF,IAAI,CAAC;EAC5C,CAAC,MAAM;IACL;IACAU,OAAO,CAACC,KAAK,CAAC,MAAMT,MAAM,kCAAkC,EAAE;MAC5DU,SAAS,EAAEN;IACb,CAAC,CAAC;EACJ;AACF;AAeK,SAASO,oBAAoBA,CAAA,EAAS;EAC3CC,cAAc,CAACC,GAAG,CAACC,wBAAa,CAAC,IAC/BF,cAAc,CAACG,MAAM,CAACD,wBAAa,EAAE5B,WAAW,CAAC;AACrD","ignoreList":[]}
@@ -31,6 +31,7 @@ var _getTracks = require("./compute/getTracks.js");
31
31
  var _isStrictMode = require("../isStrictMode.js");
32
32
  var _constants2 = require("./FormRenderer/constants.js");
33
33
  var _expandFormRenderer = require("./FormRenderer/expandFormRenderer.js");
34
+ var _registerFormRenderer = require("./FormRenderer/registerFormRenderer.js");
34
35
  var _evaluate = require("./compute/evaluate.js");
35
36
  var _matchStoryboard = require("./matchStoryboard.js");
36
37
  var _bindListeners = require("./bindListeners.js");
@@ -213,10 +214,6 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
213
214
  runtimeContext.forEachItem = brickConf[_constants.symbolForTPlExternalForEachItem];
214
215
  runtimeContext.forEachIndex = brickConf[_constants.symbolForTPlExternalForEachIndex];
215
216
  runtimeContext.forEachSize = brickConf[_constants.symbolForTPlExternalForEachSize];
216
- } else if (brickConf[_constants.symbolForTPlExternalNoForEach]) {
217
- delete runtimeContext.forEachItem;
218
- delete runtimeContext.forEachIndex;
219
- delete runtimeContext.forEachSize;
220
217
  }
221
218
  const {
222
219
  context
@@ -366,11 +363,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
366
363
  tplStack.set(tplTagName, tplCount + 1);
367
364
  } else if (brickName.includes("-") && !customElements.get(brickName)) {
368
365
  if (brickName === _constants2.FORM_RENDERER) {
369
- customElements.define(_constants2.FORM_RENDERER, class FormRendererElement extends HTMLElement {
370
- get $$typeof() {
371
- return "form-renderer";
372
- }
373
- });
366
+ (0, _registerFormRenderer.registerFormRenderer)();
374
367
  } else {
375
368
  output.blockingList.push(catchLoad((0, _loader.enqueueStableLoadBricks)([brickName], (0, _Runtime.getBrickPackages)()), "brick", brickName, rendererContext.unknownBricks));
376
369
  }