@next-core/runtime 1.56.2 → 1.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +15 -5
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/replaceSlotWithSlottedBricks.js +42 -0
- package/dist/cjs/internal/CustomTemplates/replaceSlotWithSlottedBricks.js.map +1 -0
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +5 -1
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupUseBrickInTemplate.js +13 -4
- package/dist/cjs/internal/CustomTemplates/setupUseBrickInTemplate.js.map +1 -1
- package/dist/cjs/internal/Renderer.js +28 -8
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/data/DataStore.js +0 -1
- package/dist/cjs/internal/data/DataStore.js.map +1 -1
- package/dist/cjs/internal/interfaces.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +15 -5
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/replaceSlotWithSlottedBricks.js +36 -0
- package/dist/esm/internal/CustomTemplates/replaceSlotWithSlottedBricks.js.map +1 -0
- package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +5 -2
- package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/setupUseBrickInTemplate.js +13 -4
- package/dist/esm/internal/CustomTemplates/setupUseBrickInTemplate.js.map +1 -1
- package/dist/esm/internal/Renderer.js +33 -12
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/data/DataStore.js +0 -1
- package/dist/esm/internal/data/DataStore.js.map +1 -1
- package/dist/esm/internal/interfaces.js.map +1 -1
- package/dist/types/internal/CustomTemplates/replaceSlotWithSlottedBricks.d.ts +3 -0
- package/dist/types/internal/CustomTemplates/setupTemplateProxy.d.ts +3 -2
- package/dist/types/internal/interfaces.d.ts +1 -0
- package/package.json +2 -2
|
@@ -5,6 +5,7 @@ import { setupTemplateProxy } from "./setupTemplateProxy.js";
|
|
|
5
5
|
import { setupUseBrickInTemplate } from "./setupUseBrickInTemplate.js";
|
|
6
6
|
import { childrenToSlots } from "../Renderer.js";
|
|
7
7
|
import { hooks } from "../Runtime.js";
|
|
8
|
+
import { replaceSlotWithSlottedBricks } from "./replaceSlotWithSlottedBricks.js";
|
|
8
9
|
export function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
|
|
9
10
|
var _hooks$flowApi;
|
|
10
11
|
const tplStateStoreId = uniqueId("tpl-state-");
|
|
@@ -83,21 +84,26 @@ export function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHost
|
|
|
83
84
|
asyncHostPropertyEntries,
|
|
84
85
|
externalSlots: childrenToSlots(externalChildren, originalExternalSlots),
|
|
85
86
|
tplStateStoreId,
|
|
86
|
-
hostBrick: hostBrick
|
|
87
|
+
hostBrick: hostBrick,
|
|
88
|
+
usedSlots: new Set()
|
|
87
89
|
};
|
|
88
90
|
newBrickConf.slots = {
|
|
89
91
|
"": {
|
|
90
92
|
type: "bricks",
|
|
91
|
-
bricks: bricks.
|
|
93
|
+
bricks: bricks.flatMap(item => expandBrickInTemplate(item, hostContext))
|
|
92
94
|
}
|
|
93
95
|
};
|
|
94
96
|
return newBrickConf;
|
|
95
97
|
}
|
|
96
|
-
function expandBrickInTemplate(brickConfInTemplate, hostContext) {
|
|
98
|
+
function expandBrickInTemplate(brickConfInTemplate, hostContext, markSlotted) {
|
|
97
99
|
// Ignore `if: null` to make `looseCheckIf` working.
|
|
98
100
|
if (brickConfInTemplate.if === null) {
|
|
99
101
|
delete brickConfInTemplate.if;
|
|
100
102
|
}
|
|
103
|
+
if (brickConfInTemplate.brick === "slot") {
|
|
104
|
+
markSlotted === null || markSlotted === void 0 || markSlotted();
|
|
105
|
+
return replaceSlotWithSlottedBricks(brickConfInTemplate, hostContext, expandBrickInTemplate);
|
|
106
|
+
}
|
|
101
107
|
const {
|
|
102
108
|
properties,
|
|
103
109
|
slots: slotsInTemplate,
|
|
@@ -105,18 +111,22 @@ function expandBrickInTemplate(brickConfInTemplate, hostContext) {
|
|
|
105
111
|
...restBrickConfInTemplate
|
|
106
112
|
} = brickConfInTemplate;
|
|
107
113
|
const transpiledSlots = childrenToSlots(childrenInTemplate, slotsInTemplate);
|
|
114
|
+
let slotted = false;
|
|
115
|
+
const markChild = () => {
|
|
116
|
+
slotted = true;
|
|
117
|
+
};
|
|
108
118
|
const slots = Object.fromEntries(Object.entries(transpiledSlots ?? {}).map(_ref => {
|
|
109
119
|
let [slotName, slotConf] = _ref;
|
|
110
120
|
return [slotName, {
|
|
111
121
|
type: "bricks",
|
|
112
|
-
bricks: (slotConf.bricks ?? []).
|
|
122
|
+
bricks: (slotConf.bricks ?? []).flatMap(item => expandBrickInTemplate(item, hostContext, markChild))
|
|
113
123
|
}];
|
|
114
124
|
}));
|
|
115
125
|
return {
|
|
116
126
|
...restBrickConfInTemplate,
|
|
117
127
|
properties: setupUseBrickInTemplate(properties, hostContext),
|
|
118
128
|
slots,
|
|
119
|
-
...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots)
|
|
129
|
+
...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots, slotted)
|
|
120
130
|
};
|
|
121
131
|
}
|
|
122
132
|
//# sourceMappingURL=expandCustomTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandCustomTemplate.js","names":["uniqueId","customTemplates","DataStore","setupTemplateProxy","setupUseBrickInTemplate","childrenToSlots","hooks","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","runtimeContext","forEachItem","forEachIndex","forEachSize","formStateStoreId","tplStateStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","get","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","_ref","slotName","slotConf"],"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"],"mappings":"AAOA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAEhD,SAASC,kBAAkB,QAAQ,yBAAyB;AAO5D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,KAAK,QAAQ,eAAe;AAGrC,OAAO,SAASC,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAGd,QAAQ,CAAC,YAAY,CAAC;EAC9C,MAAMe,cAAc,GAAG;IACrB,GAAGL,SAAS,CAACK,cAAc;IAC3BD;EACF,CAAC;;EAED;EACA,OAAOC,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,WAAW;EACjC,OAAOH,cAAc,CAACI,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIlB,SAAS,CACjC,OAAO,EACPQ,SAAS,EACTE,eAA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C/B;EACA,MAAM;IACJd,UAAU;IACVX,KAAK,EAAE0B,eAAe;IACtBxB,QAAQ,EAAEyB,kBAAkB;IAC5B,GAAGC;EACL,CAAC,GAAGJ,mBAAmB;EAEvB,MAAMK,eAAe,GAAGzD,eAAe,CACrCuD,kBAAkB,EAClBD,eACF,CAAoC;EAEpC,MAAM1B,KAAwB,GAAGc,MAAM,CAACgB,WAAW,CACjDhB,MAAM,CAACC,OAAO,CAACc,eAAe,IAAI,CAAC,CAAC,CAAC,CAACR,GAAG,CAACU,IAAA;IAAA,IAAC,CAACC,QAAQ,EAAEC,QAAQ,CAAC,GAAAF,IAAA;IAAA,OAAK,CAClEC,QAAQ,EACR;MACEZ,IAAI,EAAE,QAAQ;MACd5B,MAAM,EAAE,CAACyC,QAAQ,CAACzC,MAAM,IAAI,EAAE,EAAE6B,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEJ,WAAW,CACzC;IACF,CAAC,CACF;EAAA,EACH,CAAC;EAED,OAAO;IACL,GAAGU,uBAAuB;IAC1BjB,UAAU,EAAExC,uBAAuB,CAACwC,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG9B,kBAAkB,CAACgD,WAAW,EAAEU,uBAAuB,CAACX,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"expandCustomTemplate.js","names":["uniqueId","customTemplates","DataStore","setupTemplateProxy","setupUseBrickInTemplate","childrenToSlots","hooks","replaceSlotWithSlottedBricks","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hooks$flowApi","tplStateStoreId","runtimeContext","forEachItem","forEachIndex","forEachSize","formStateStoreId","tplStateStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","get","flowApi","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","usedSlots","Set","type","flatMap","item","expandBrickInTemplate","brickConfInTemplate","markSlotted","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","slotted","markChild","fromEntries","map","_ref","slotName","slotConf"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotConfOfBricks,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncPropertyEntry,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { hooks } from \"../Runtime.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\nimport { replaceSlotWithSlottedBricks } from \"./replaceSlotWithSlottedBricks.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEach*` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.forEachSize;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\n \"STATE\",\n hostBrick,\n rendererContext,\n tplStateStoreId\n );\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n hooks?.flowApi?.collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostPropertyEntries);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n usedSlots: new Set(),\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.flatMap((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConf,\n hostContext: TemplateHostContext,\n markSlotted?: () => void\n): BrickConf | BrickConf[] {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n\n if (brickConfInTemplate.brick === \"slot\") {\n markSlotted?.();\n return replaceSlotWithSlottedBricks(\n brickConfInTemplate,\n hostContext,\n expandBrickInTemplate\n );\n }\n\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate as BrickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n let slotted = false;\n const markChild = () => {\n slotted = true;\n };\n const slots = Object.fromEntries<SlotConfOfBricks>(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).flatMap((item) =>\n expandBrickInTemplate(item, hostContext, markChild)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(\n hostContext,\n restBrickConfInTemplate.ref,\n slots,\n slotted\n ),\n };\n}\n"],"mappings":"AAQA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAChD,SAASC,kBAAkB,QAAQ,yBAAyB;AAO5D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,KAAK,QAAQ,eAAe;AAErC,SAASC,4BAA4B,QAAQ,mCAAmC;AAEhF,OAAO,SAASC,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EAC7B;EAAA,IAAAC,cAAA;EACH,MAAMC,eAAe,GAAGf,QAAQ,CAAC,YAAY,CAAC;EAC9C,MAAMgB,cAAc,GAAG;IACrB,GAAGL,SAAS,CAACK,cAAc;IAC3BD;EACF,CAAC;;EAED;EACA,OAAOC,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,C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AC5DlB,KAAK;IACL,GAAG/B,kBAAkB,CACnBiD,WAAW,EACXa,uBAAuB,CAACd,GAAG,EAC3BjB,KAAK,EACLiC,OACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { hasOwnProperty } from "@next-core/utils/general";
|
|
2
|
+
import { isEvaluable } from "@next-core/cook";
|
|
3
|
+
import { setupTemplateExternalBricksWithForEach } from "./setupTemplateProxy.js";
|
|
4
|
+
import { childrenToSlots } from "../Renderer.js";
|
|
5
|
+
export function replaceSlotWithSlottedBricks(brickConf, hostContext, expand) {
|
|
6
|
+
var _brickConf$properties, _defaultSlots$;
|
|
7
|
+
// Currently, no support for `if` in a slot.
|
|
8
|
+
if (brickConf.if != null && !brickConf.if || typeof brickConf.if === "string") {
|
|
9
|
+
throw new Error(`Can not use "if" in a slot currently, check your template "${hostContext.hostBrick.type}"`);
|
|
10
|
+
}
|
|
11
|
+
const slot = String(((_brickConf$properties = brickConf.properties) === null || _brickConf$properties === void 0 ? void 0 : _brickConf$properties.name) ?? "");
|
|
12
|
+
|
|
13
|
+
// Currently, no support for expression as slot name.
|
|
14
|
+
if (isEvaluable(slot)) {
|
|
15
|
+
throw new Error(`Can not use an expression as slot name "${slot}" currently, check your template "${hostContext.hostBrick.type}"`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Do not repeat the same slot name in a template.
|
|
19
|
+
if (hostContext.usedSlots.has(slot)) {
|
|
20
|
+
throw new Error(`Can not have multiple slots with the same name "${slot}", check your template "${hostContext.hostBrick.type}"`);
|
|
21
|
+
}
|
|
22
|
+
hostContext.usedSlots.add(slot);
|
|
23
|
+
if (hostContext.externalSlots && hasOwnProperty(hostContext.externalSlots, slot)) {
|
|
24
|
+
const insertBricks = hostContext.externalSlots[slot].bricks ?? [];
|
|
25
|
+
if (insertBricks.length > 0) {
|
|
26
|
+
const hostCtx = hostContext.hostBrick.runtimeContext;
|
|
27
|
+
// External bricks of a template, should not access the template internal forEach `ITEM`.
|
|
28
|
+
// For some existing templates who is *USING* this bug, we keep the old behavior.
|
|
29
|
+
const hostHasForEach = hasOwnProperty(hostCtx, "forEachItem");
|
|
30
|
+
return hostHasForEach ? setupTemplateExternalBricksWithForEach(insertBricks, hostCtx.forEachItem, hostCtx.forEachIndex, hostCtx.forEachSize) : insertBricks;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const defaultSlots = childrenToSlots(brickConf.children, brickConf.slots);
|
|
34
|
+
return ((defaultSlots === null || defaultSlots === void 0 || (_defaultSlots$ = defaultSlots[""]) === null || _defaultSlots$ === void 0 ? void 0 : _defaultSlots$.bricks) ?? []).flatMap(item => expand(item, hostContext));
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=replaceSlotWithSlottedBricks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaceSlotWithSlottedBricks.js","names":["hasOwnProperty","isEvaluable","setupTemplateExternalBricksWithForEach","childrenToSlots","replaceSlotWithSlottedBricks","brickConf","hostContext","expand","_brickConf$properties","_defaultSlots$","if","Error","hostBrick","type","slot","String","properties","name","usedSlots","has","add","externalSlots","insertBricks","bricks","length","hostCtx","runtimeContext","hostHasForEach","forEachItem","forEachIndex","forEachSize","defaultSlots","children","slots","flatMap","item"],"sources":["../../../../src/internal/CustomTemplates/replaceSlotWithSlottedBricks.ts"],"sourcesContent":["import type {\n BrickConf,\n SlotsConfInTemplate,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { isEvaluable } from \"@next-core/cook\";\nimport type { TemplateHostContext } from \"../interfaces.js\";\nimport { setupTemplateExternalBricksWithForEach } from \"./setupTemplateProxy.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function replaceSlotWithSlottedBricks<\n T extends BrickConf | UseSingleBrickConf,\n>(\n brickConf: T,\n hostContext: TemplateHostContext,\n expand: (item: T, hostContext: TemplateHostContext) => T | T[]\n): T[] {\n // Currently, no support for `if` in a slot.\n if (\n (brickConf.if != null && !brickConf.if) ||\n typeof brickConf.if === \"string\"\n ) {\n throw new Error(\n `Can not use \"if\" in a slot currently, check your template \"${hostContext.hostBrick.type}\"`\n );\n }\n\n const slot = String(brickConf.properties?.name ?? \"\");\n\n // Currently, no support for expression as slot name.\n if (isEvaluable(slot)) {\n throw new Error(\n `Can not use an expression as slot name \"${slot}\" currently, check your template \"${hostContext.hostBrick.type}\"`\n );\n }\n\n // Do not repeat the same slot name in a template.\n if (hostContext.usedSlots.has(slot)) {\n throw new Error(\n `Can not have multiple slots with the same name \"${slot}\", check your template \"${hostContext.hostBrick.type}\"`\n );\n }\n hostContext.usedSlots.add(slot);\n\n if (\n hostContext.externalSlots &&\n hasOwnProperty(hostContext.externalSlots, slot)\n ) {\n const insertBricks = hostContext.externalSlots[slot].bricks ?? [];\n if (insertBricks.length > 0) {\n const hostCtx = hostContext.hostBrick.runtimeContext;\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(hostCtx, \"forEachItem\");\n return (\n hostHasForEach\n ? setupTemplateExternalBricksWithForEach(\n insertBricks,\n hostCtx.forEachItem,\n hostCtx.forEachIndex!,\n hostCtx.forEachSize!\n )\n : insertBricks\n ) as T[];\n }\n }\n\n const defaultSlots = childrenToSlots(brickConf.children, brickConf.slots) as\n | SlotsConfInTemplate\n | undefined;\n return (defaultSlots?.[\"\"]?.bricks ?? []).flatMap((item) =>\n expand(item as T, hostContext)\n );\n}\n"],"mappings":"AAKA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,WAAW,QAAQ,iBAAiB;AAE7C,SAASC,sCAAsC,QAAQ,yBAAyB;AAChF,SAASC,eAAe,QAAQ,gBAAgB;AAEhD,OAAO,SAASC,4BAA4BA,CAG1CC,SAAY,EACZC,WAAgC,EAChCC,MAA8D,EACzD;EAAA,IAAAC,qBAAA,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ACK,WACV,CAAC,GACDR,YAAY;IAEpB;EACF;EAEA,MAAMS,YAAY,GAAG5B,eAAe,CAACE,SAAS,CAAC2B,QAAQ,EAAE3B,SAAS,CAAC4B,KAAK,CAE3D;EACb,OAAO,CAAC,CAAAF,YAAY,aAAZA,YAAY,gBAAAtB,cAAA,GAAZsB,YAAY,CAAG,EAAE,CAAC,cAAAtB,cAAA,uBAAlBA,cAAA,CAAoBc,MAAM,KAAI,EAAE,EAAEW,OAAO,CAAEC,IAAI,IACrD5B,MAAM,CAAC4B,IAAI,EAAO7B,WAAW,CAC/B,CAAC;AACH","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import { clamp } from "lodash";
|
|
|
3
3
|
import { symbolForAsyncComputedPropsFromHost, symbolForTPlExternalForEachIndex, symbolForTPlExternalForEachItem, symbolForTPlExternalForEachSize, symbolForTplStateStoreId } from "./constants.js";
|
|
4
4
|
import { computePropertyValue } from "../compute/computeRealProperties.js";
|
|
5
5
|
import { childrenToSlots } from "../Renderer.js";
|
|
6
|
-
export function setupTemplateProxy(hostContext, ref, slots) {
|
|
6
|
+
export function setupTemplateProxy(hostContext, ref, slots, slotted) {
|
|
7
7
|
const {
|
|
8
8
|
reversedProxies,
|
|
9
9
|
asyncHostPropertyEntries,
|
|
@@ -30,6 +30,9 @@ export function setupTemplateProxy(hostContext, ref, slots) {
|
|
|
30
30
|
asyncComputedProps = getComputedProps(asyncHostPropertyEntries);
|
|
31
31
|
}
|
|
32
32
|
const slotProxies = reversedProxies.slots.get(ref);
|
|
33
|
+
if (slotProxies && slotted) {
|
|
34
|
+
throw new Error(`Can not have proxied slot ref when the ref target has a slot element child, check your template "${hostBrick.type}" and ref "${ref}"`);
|
|
35
|
+
}
|
|
33
36
|
if (slotProxies && externalSlots) {
|
|
34
37
|
// Use an approach like template-literal's quasis:
|
|
35
38
|
// `quasi0${0}quais1${1}quasi2...`
|
|
@@ -83,7 +86,7 @@ export function setupTemplateProxy(hostContext, ref, slots) {
|
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
// External bricks of a template, have the same forEachItem context as their host.
|
|
86
|
-
function setupTemplateExternalBricksWithForEach(bricks, forEachItem, forEachIndex, forEachSize) {
|
|
89
|
+
export function setupTemplateExternalBricksWithForEach(bricks, forEachItem, forEachIndex, forEachSize) {
|
|
87
90
|
return bricks.map(_ref2 => {
|
|
88
91
|
let {
|
|
89
92
|
children,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachSize","symbolForTplStateStoreId","computePropertyValue","childrenToSlots","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","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","hostHasForEach","runtimeContext","setupTemplateExternalBricksWithForEach","forEachItem","forEachIndex","forEachSize","slotName","quasis","entries","type","slotConf","flatMap","index","concat","_ref2","children","brick","Object","fromEntries","_ref3","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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,gCAAgC,EAChCC,+BAA+B,EAC/BC,+BAA+B,EAC/BC,wBAAwB,QAEnB,gBAAgB;AAEvB,SAASC,oBAAoB,QAAQ,qCAAqC;AAC1E,SAASC,eAAe,QAAQ,gBAAgB;AAEhD,OAAO,SAASC,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,CAACC,IAAA,IAAkB;UAAA,IAAjB;YAAEC,IAAI;YAAEC;UAAG,CAAC,GAAAF,IAAA;UAChB,MAAMG,QAAQ,GAAGL,cAAc,CAACM,MAAM,CACnCC,KAAK,IAAKA,KAAK,CAAC,CAAC,CAAC,KAAKJ,IAC1B,CAAC;UACD,IAAI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,MAAmB,EACnBjB,WAAoB,EACpBC,YAAoB,EACpBC,WAAmB,EACN;EACb,OAAOe,MAAM,CAAC5C,GAAG,CAAE8C,KAAK,IACtBA,KAAK,CAACb,IAAI,KAAK,QAAQ,GACnB;IACE,GAAGa,KAAK;IACRF,MAAM,EAAEC,sCAAsC,CAC5CC,KAAK,CAACF,MAAM,EACZjB,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CAAC,GACDiB,KAAK,CAACb,IAAI,KAAK,UAAU,GACvBa,KAAK,GACL;IACE,GAAGA,KAAK;IACR/B,MAAM,EAAEW,sCAAsC,CAC5CoB,KAAK,CAAC/B,MAAM,EACZY,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachItem","symbolForTPlExternalForEachSize","symbolForTplStateStoreId","computePropertyValue","childrenToSlots","setupTemplateProxy","hostContext","ref","slots","slotted","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","_ref","from","to","filtered","filter","entry","length","refProperty","Boolean","slotProxies","Error","type","quasisMap","Map","_externalSlots$from","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","hostHasForEach","runtimeContext","setupTemplateExternalBricksWithForEach","forEachItem","forEachIndex","forEachSize","slotName","quasis","entries","slotConf","flatMap","index","concat","_ref2","children","brick","Object","fromEntries","_ref3","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 slotted: boolean\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\n if (slotProxies && slotted) {\n throw new Error(\n `Can not have proxied slot ref when the ref target has a slot element child, check your template \"${hostBrick.type}\" and ref \"${ref}\"`\n );\n }\n\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.\nexport function 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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,gCAAgC,EAChCC,+BAA+B,EAC/BC,+BAA+B,EAC/BC,wBAAwB,QAEnB,gBAAgB;AAEvB,SAASC,oBAAoB,QAAQ,qCAAqC;AAC1E,SAASC,eAAe,QAAQ,gBAAgB;AAEhD,OAAO,SAASC,kBAAkBA,CAChCC,WAAgC,EAChCC,GAAuB,EACvBC,KAAwB,EACxBC,OAAgB,EAChB;EACA,MAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGR,WAAW;EAEf,IAAIS,kBAAoD;EAExD,IAAIR,GAAG,IAAIG,eAAe,EAAE;IAC1B,MAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,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AAA,IAAC,CAACZ,QAAQ,EAAEG,QAAQ,CAAC,GAAAS,KAAA;QAAA,OAAK,CACxBZ,QAAQ,EACRG,QAAQ,CAACvB,IAAI,KAAK,QAAQ,GACtB;UACEA,IAAI,EAAE,QAAQ;UACdiC,MAAM,EAAEC,sCAAsC,CAC5CX,QAAQ,CAACU,MAAM,EACfhB,WAAW,EACXC,YAAY,EACZC,WACF;QACF,CAAC,GACD;UACEnB,IAAI,EAAE,QAAQ;UACdK,MAAM,EAAEW,sCAAsC,CAC5CO,QAAQ,CAAClB,MAAM,EACfY,WAAW,EACXC,YAAY,EACZC,WACF;QACF,CAAC,CACN;MAAA,CACH,CACF;IACR,CAAC;EAAA,CACH,CAAC;AACH;AAEA,SAASe,sCAAsCA,CAC7CD,MAAmB,EACnBhB,WAAoB,EACpBC,YAAoB,EACpBC,WAAmB,EACN;EACb,OAAOc,MAAM,CAAC7C,GAAG,CAAE+C,KAAK,IACtBA,KAAK,CAACnC,IAAI,KAAK,QAAQ,GACnB;IACE,GAAGmC,KAAK;IACRF,MAAM,EAAEC,sCAAsC,CAC5CC,KAAK,CAACF,MAAM,EACZhB,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CAAC,GACDgB,KAAK,CAACnC,IAAI,KAAK,UAAU,GACvBmC,KAAK,GACL;IACE,GAAGA,KAAK;IACR9B,MAAM,EAAEW,sCAAsC,CAC5CmB,KAAK,CAAC9B,MAAM,EACZY,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isObject } from "@next-core/utils/general";
|
|
2
2
|
import { setupTemplateProxy } from "./setupTemplateProxy.js";
|
|
3
3
|
import { childrenToSlots } from "../Renderer.js";
|
|
4
|
+
import { replaceSlotWithSlottedBricks } from "./replaceSlotWithSlottedBricks.js";
|
|
4
5
|
export function setupUseBrickInTemplate(props, hostContext) {
|
|
5
6
|
function walk(props) {
|
|
6
7
|
if (!isObject(props) || typeof props === "function") {
|
|
@@ -11,10 +12,14 @@ export function setupUseBrickInTemplate(props, hostContext) {
|
|
|
11
12
|
}
|
|
12
13
|
return Object.fromEntries(Object.entries(props).map(_ref => {
|
|
13
14
|
let [key, value] = _ref;
|
|
14
|
-
return isObject(value) && key === "useBrick" ? Array.isArray(value) ? [key, value.
|
|
15
|
+
return isObject(value) && key === "useBrick" ? Array.isArray(value) ? [key, value.flatMap(v => setup(v))] : [key, setup(value)] : [key, walk(value)];
|
|
15
16
|
}).concat(Object.getOwnPropertySymbols(props).map(k => [k, props[k]])));
|
|
16
17
|
}
|
|
17
|
-
function setup(item) {
|
|
18
|
+
function setup(item, markSlotted) {
|
|
19
|
+
if (item.brick === "slot") {
|
|
20
|
+
markSlotted === null || markSlotted === void 0 || markSlotted();
|
|
21
|
+
return replaceSlotWithSlottedBricks(item, hostContext, it => setup(it));
|
|
22
|
+
}
|
|
18
23
|
const {
|
|
19
24
|
properties,
|
|
20
25
|
slots: originalSlots,
|
|
@@ -22,18 +27,22 @@ export function setupUseBrickInTemplate(props, hostContext) {
|
|
|
22
27
|
...restConf
|
|
23
28
|
} = item;
|
|
24
29
|
const transpiledSlots = childrenToSlots(children, originalSlots);
|
|
30
|
+
let slotted = false;
|
|
31
|
+
const markChild = () => {
|
|
32
|
+
slotted = true;
|
|
33
|
+
};
|
|
25
34
|
const slots = Object.fromEntries(Object.entries(transpiledSlots ?? {}).map(_ref2 => {
|
|
26
35
|
let [slotName, slotConf] = _ref2;
|
|
27
36
|
return [slotName, {
|
|
28
37
|
type: "bricks",
|
|
29
|
-
bricks: (slotConf.bricks ?? []).
|
|
38
|
+
bricks: (slotConf.bricks ?? []).flatMap(it => setup(it, markChild))
|
|
30
39
|
}];
|
|
31
40
|
}));
|
|
32
41
|
return {
|
|
33
42
|
...restConf,
|
|
34
43
|
properties: walk(properties),
|
|
35
44
|
slots,
|
|
36
|
-
...setupTemplateProxy(hostContext, restConf.ref, slots)
|
|
45
|
+
...setupTemplateProxy(hostContext, restConf.ref, slots, slotted)
|
|
37
46
|
};
|
|
38
47
|
}
|
|
39
48
|
return walk(props);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupUseBrickInTemplate.js","names":["isObject","setupTemplateProxy","childrenToSlots","setupUseBrickInTemplate","props","hostContext","walk","Array","isArray","map","Object","fromEntries","entries","_ref","key","value","setup","concat","getOwnPropertySymbols","k","item","properties","slots","originalSlots","children","restConf","transpiledSlots","_ref2","slotName","slotConf","type","bricks","ref"],"sources":["../../../../src/internal/CustomTemplates/setupUseBrickInTemplate.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"setupUseBrickInTemplate.js","names":["isObject","setupTemplateProxy","childrenToSlots","replaceSlotWithSlottedBricks","setupUseBrickInTemplate","props","hostContext","walk","Array","isArray","map","Object","fromEntries","entries","_ref","key","value","flatMap","v","setup","concat","getOwnPropertySymbols","k","item","markSlotted","brick","it","properties","slots","originalSlots","children","restConf","transpiledSlots","slotted","markChild","_ref2","slotName","slotConf","type","bricks","ref"],"sources":["../../../../src/internal/CustomTemplates/setupUseBrickInTemplate.ts"],"sourcesContent":["import type {\n UseBrickSlotConf,\n UseBrickSlotsConf,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { isObject } from \"@next-core/utils/general\";\nimport type { TemplateHostContext } from \"../interfaces.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { replaceSlotWithSlottedBricks } from \"./replaceSlotWithSlottedBricks.js\";\n\nexport function setupUseBrickInTemplate<T>(\n props: T,\n hostContext: TemplateHostContext\n): T {\n function walk<P>(props: P): P {\n if (!isObject(props) || typeof props === \"function\") {\n return props;\n }\n\n if (Array.isArray(props)) {\n return props.map(walk) as P;\n }\n\n return Object.fromEntries(\n Object.entries(props)\n .map(([key, value]) =>\n isObject(value) && key === \"useBrick\"\n ? Array.isArray(value)\n ? [key, value.flatMap((v) => setup(v))]\n : [key, setup(value as UseSingleBrickConf)]\n : [key, walk(value)]\n )\n .concat(\n Object.getOwnPropertySymbols(props).map((k) => [\n k,\n (props as Record<string | symbol, unknown>)[k],\n ])\n )\n ) as P;\n }\n\n function setup(\n item: UseSingleBrickConf,\n markSlotted?: () => void\n ): UseSingleBrickConf | UseSingleBrickConf[] {\n if (item.brick === \"slot\") {\n markSlotted?.();\n return replaceSlotWithSlottedBricks(item, hostContext, (it) => setup(it));\n }\n\n const { properties, slots: originalSlots, children, ...restConf } = item;\n\n const transpiledSlots = childrenToSlots(children, originalSlots) as\n | UseBrickSlotsConf\n | undefined;\n\n let slotted = false;\n const markChild = () => {\n slotted = true;\n };\n const slots = Object.fromEntries<UseBrickSlotConf>(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).flatMap((it) => setup(it, markChild)),\n },\n ])\n );\n\n return {\n ...restConf,\n properties: walk(properties),\n slots,\n ...setupTemplateProxy(hostContext, restConf.ref, slots, slotted),\n };\n }\n\n return walk(props);\n}\n"],"mappings":"AAKA,SAASA,QAAQ,QAAQ,0BAA0B;AAEnD,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,4BAA4B,QAAQ,mCAAmC;AAEhF,OAAO,SAASC,uBAAuBA,CACrCC,KAAQ,EACRC,WAAgC,EAC7B;EACH,SAASC,IAAIA,CAAIF,KAAQ,EAAK;IAC5B,IAAI,CAACL,QAAQ,CAACK,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MACnD,OAAOA,KAAK;IACd;IAEA,IAAIG,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;MACxB,OAAOA,KAAK,CAACK,GAAG,CAACH,IAAI,CAAC;IACxB;IAEA,OAAOI,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACR,KAAK,CAAC,CACl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ACtB,GAAG,CAACyB,KAAA;MAAA,IAAC,CAACC,QAAQ,EAAEC,QAAQ,CAAC,GAAAF,KAAA;MAAA,OAAK,CAClEC,QAAQ,EACR;QACEE,IAAI,EAAE,QAAQ;QACdC,MAAM,EAAE,CAACF,QAAQ,CAACE,MAAM,IAAI,EAAE,EAAEtB,OAAO,CAAES,EAAE,IAAKP,KAAK,CAACO,EAAE,EAAEQ,SAAS,CAAC;MACtE,CAAC,CACF;IAAA,EACH,CAAC;IAED,OAAO;MACL,GAAGH,QAAQ;MACXJ,UAAU,EAAEpB,IAAI,CAACoB,UAAU,CAAC;MAC5BC,KAAK;MACL,GAAG3B,kBAAkB,CAACK,WAAW,EAAEyB,QAAQ,CAACS,GAAG,EAAEZ,KAAK,EAAEK,OAAO;IACjE,CAAC;EACH;EAEA,OAAO1B,IAAI,CAACF,KAAK,CAAC;AACpB","ignoreList":[]}
|
|
@@ -256,8 +256,14 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
|
-
const renderControlNode = async
|
|
260
|
-
var
|
|
259
|
+
const renderControlNode = async _ref => {
|
|
260
|
+
var _ref2;
|
|
261
|
+
let {
|
|
262
|
+
type,
|
|
263
|
+
runtimeContext,
|
|
264
|
+
tplStateStoreScope,
|
|
265
|
+
formStateStoreScope
|
|
266
|
+
} = _ref;
|
|
261
267
|
let changedAfterInitial = false;
|
|
262
268
|
const tracker = {
|
|
263
269
|
disposes: [],
|
|
@@ -278,6 +284,12 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
278
284
|
while (uninitialized || changedAfterInitial) {
|
|
279
285
|
changedAfterInitial = false;
|
|
280
286
|
rawOutput = await lowerLevelRenderControlNode(runtimeContext, tracker, uninitialized && type === "initial");
|
|
287
|
+
|
|
288
|
+
// Changes may happen during `postAsyncRender`.
|
|
289
|
+
if (!changedAfterInitial && type === "rerender") {
|
|
290
|
+
const scopedStores = [...tplStateStoreScope, ...formStateStoreScope];
|
|
291
|
+
await postAsyncRender(rawOutput, runtimeContext, [runtimeContext.ctxStore, ...scopedStores]);
|
|
292
|
+
}
|
|
281
293
|
tracker.disposes.forEach(dispose => dispose());
|
|
282
294
|
tracker.disposes.length = 0;
|
|
283
295
|
uninitialized = false;
|
|
@@ -286,13 +298,16 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
286
298
|
throw new Error(`Maximum rerender stack overflowed (iid: ${brickConf.iid})`);
|
|
287
299
|
}
|
|
288
300
|
}
|
|
289
|
-
(
|
|
301
|
+
(_ref2 = rawOutput).node ?? (_ref2.node = {
|
|
290
302
|
tag: RenderTag.PLACEHOLDER,
|
|
291
303
|
return: returnNode
|
|
292
304
|
});
|
|
293
305
|
return rawOutput;
|
|
294
306
|
};
|
|
295
|
-
const controlledOutput = await renderControlNode(
|
|
307
|
+
const controlledOutput = await renderControlNode({
|
|
308
|
+
type: "initial",
|
|
309
|
+
runtimeContext
|
|
310
|
+
});
|
|
296
311
|
const {
|
|
297
312
|
onMount,
|
|
298
313
|
onUnmount
|
|
@@ -303,9 +318,12 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
303
318
|
const listener = async () => {
|
|
304
319
|
const currentRenderId = ++renderId;
|
|
305
320
|
const [scopedRuntimeContext, tplStateStoreScope, formStateStoreScope] = createScopedRuntimeContext(runtimeContext);
|
|
306
|
-
const reControlledOutput = await renderControlNode(
|
|
307
|
-
|
|
308
|
-
|
|
321
|
+
const reControlledOutput = await renderControlNode({
|
|
322
|
+
type: "rerender",
|
|
323
|
+
runtimeContext: scopedRuntimeContext,
|
|
324
|
+
tplStateStoreScope,
|
|
325
|
+
formStateStoreScope
|
|
326
|
+
});
|
|
309
327
|
|
|
310
328
|
// Ignore stale renders
|
|
311
329
|
if (renderId === currentRenderId) {
|
|
@@ -324,7 +342,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
324
342
|
}
|
|
325
343
|
}));
|
|
326
344
|
}
|
|
327
|
-
for (const store of
|
|
345
|
+
for (const store of [...tplStateStoreScope, ...formStateStoreScope]) {
|
|
328
346
|
store.mountAsyncData();
|
|
329
347
|
}
|
|
330
348
|
}
|
|
@@ -486,8 +504,8 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
486
504
|
return;
|
|
487
505
|
}
|
|
488
506
|
const routeSlotFromIndexToSlotId = new Map();
|
|
489
|
-
const rendered = await Promise.all(Object.entries(slots).map((
|
|
490
|
-
let [childSlotId, slotConf] =
|
|
507
|
+
const rendered = await Promise.all(Object.entries(slots).map((_ref3, index) => {
|
|
508
|
+
let [childSlotId, slotConf] = _ref3;
|
|
491
509
|
if (slotConf.type !== "routes") {
|
|
492
510
|
return renderBricks(brick, slotConf.bricks, childRuntimeContext, rendererContext, parentRoutes, menuRequestReturnNode, childSlotId, tplStack, undefined, initialTracker);
|
|
493
511
|
}
|
|
@@ -719,8 +737,11 @@ export function childrenToSlots(children, originalSlots) {
|
|
|
719
737
|
}
|
|
720
738
|
if (Array.isArray(children) && !newSlots) {
|
|
721
739
|
newSlots = {};
|
|
722
|
-
for (const
|
|
723
|
-
|
|
740
|
+
for (const {
|
|
741
|
+
slot: sl,
|
|
742
|
+
...child
|
|
743
|
+
} of children) {
|
|
744
|
+
const slot = sl ?? "";
|
|
724
745
|
if (!hasOwnProperty(newSlots, slot)) {
|
|
725
746
|
newSlots[slot] = {
|
|
726
747
|
type: "bricks",
|