@next-core/runtime 1.58.2 → 1.58.3
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/CustomTemplates.js +11 -7
- package/dist/cjs/CustomTemplates.js.map +1 -1
- package/dist/cjs/ModalStack.js +2 -1
- package/dist/cjs/ModalStack.js.map +1 -1
- package/dist/cjs/StoryboardFunctionRegistry.js +2 -1
- package/dist/cjs/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/cjs/createRoot.js +4 -4
- package/dist/cjs/createRoot.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js +5 -4
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +7 -4
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/replaceSlotWithSlottedBricks.js +5 -4
- package/dist/cjs/internal/CustomTemplates/replaceSlotWithSlottedBricks.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +21 -18
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupUseBrickInTemplate.js +7 -4
- package/dist/cjs/internal/CustomTemplates/setupUseBrickInTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/utils.js +3 -3
- package/dist/cjs/internal/CustomTemplates/utils.js.map +1 -1
- package/dist/cjs/internal/ErrorNode.js +2 -1
- package/dist/cjs/internal/ErrorNode.js.map +1 -1
- package/dist/cjs/internal/FormRenderer/expandFormRenderer.js +3 -3
- package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -1
- package/dist/cjs/internal/FormRenderer/utils.js +2 -2
- package/dist/cjs/internal/FormRenderer/utils.js.map +1 -1
- package/dist/cjs/internal/Renderer.js +18 -13
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/RendererContext.js +10 -8
- package/dist/cjs/internal/RendererContext.js.map +1 -1
- package/dist/cjs/internal/Runtime.js +15 -16
- package/dist/cjs/internal/Runtime.js.map +1 -1
- package/dist/cjs/internal/bindListeners.js +3 -2
- package/dist/cjs/internal/bindListeners.js.map +1 -1
- package/dist/cjs/internal/compute/evaluate.js +4 -4
- package/dist/cjs/internal/compute/evaluate.js.map +1 -1
- package/dist/cjs/internal/compute/getStorageItem.js +2 -1
- package/dist/cjs/internal/compute/getStorageItem.js.map +1 -1
- package/dist/cjs/internal/compute/listenOnTrackingContext.js +2 -1
- package/dist/cjs/internal/compute/listenOnTrackingContext.js.map +1 -1
- package/dist/cjs/internal/data/resolveDataStore.js +4 -2
- package/dist/cjs/internal/data/resolveDataStore.js.map +1 -1
- package/dist/cjs/internal/matchStoryboard.js +2 -2
- package/dist/cjs/internal/matchStoryboard.js.map +1 -1
- package/dist/cjs/internal/poll.js +3 -3
- package/dist/cjs/internal/poll.js.map +1 -1
- package/dist/cjs/internal/secret_internals.js +7 -6
- package/dist/cjs/internal/secret_internals.js.map +1 -1
- package/dist/cjs/internal/setupRootRuntimeContext.js +3 -2
- package/dist/cjs/internal/setupRootRuntimeContext.js.map +1 -1
- package/dist/cjs/setWatermark.js +4 -4
- package/dist/cjs/setWatermark.js.map +1 -1
- package/dist/cjs/themeAndMode.js +2 -1
- package/dist/cjs/themeAndMode.js.map +1 -1
- package/package.json +9 -9
|
@@ -48,12 +48,12 @@ function setupTemplateProxy(hostContext, ref, slots, slotted) {
|
|
|
48
48
|
from,
|
|
49
49
|
to
|
|
50
50
|
} of slotProxies) {
|
|
51
|
-
var _externalSlots$from;
|
|
52
|
-
const insertBricks = ((_externalSlots$from = externalSlots[from]) === null || _externalSlots$from === void 0 ? void 0 : _externalSlots$from.bricks)
|
|
51
|
+
var _externalSlots$from$b, _externalSlots$from, _to$refSlot, _to$refPosition;
|
|
52
|
+
const insertBricks = (_externalSlots$from$b = (_externalSlots$from = externalSlots[from]) === null || _externalSlots$from === void 0 ? void 0 : _externalSlots$from.bricks) !== null && _externalSlots$from$b !== void 0 ? _externalSlots$from$b : [];
|
|
53
53
|
if (!insertBricks.length) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
const refToSlot = to.refSlot
|
|
56
|
+
const refToSlot = (_to$refSlot = to.refSlot) !== null && _to$refSlot !== void 0 ? _to$refSlot : from;
|
|
57
57
|
let expandableSlot = quasisMap.get(refToSlot);
|
|
58
58
|
if (!expandableSlot) {
|
|
59
59
|
expandableSlot = [];
|
|
@@ -64,7 +64,7 @@ function setupTemplateProxy(hostContext, ref, slots, slotted) {
|
|
|
64
64
|
}
|
|
65
65
|
quasisMap.set(refToSlot, expandableSlot);
|
|
66
66
|
}
|
|
67
|
-
const refPosition = to.refPosition
|
|
67
|
+
const refPosition = (_to$refPosition = to.refPosition) !== null && _to$refPosition !== void 0 ? _to$refPosition : -1;
|
|
68
68
|
// External bricks of a template, should not access the template internal forEach `ITEM`.
|
|
69
69
|
// For some existing templates who is *USING* this bug, we keep the old behavior.
|
|
70
70
|
const hostHasForEach = (0, _general.hasOwnProperty)(hostBrick.runtimeContext, "forEachItem");
|
|
@@ -97,20 +97,23 @@ function setupTemplateExternalBricksWithForEach(bricks, forEachItem, forEachInde
|
|
|
97
97
|
children,
|
|
98
98
|
slots,
|
|
99
99
|
...brick
|
|
100
|
-
}) =>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
}) => {
|
|
101
|
+
var _childrenToSlots;
|
|
102
|
+
return {
|
|
103
|
+
...brick,
|
|
104
|
+
[_constants.symbolForTPlExternalForEachItem]: forEachItem,
|
|
105
|
+
[_constants.symbolForTPlExternalForEachIndex]: forEachIndex,
|
|
106
|
+
[_constants.symbolForTPlExternalForEachSize]: forEachSize,
|
|
107
|
+
// Keep `:forEach` bricks as original, since they have their own forEachItem context.
|
|
108
|
+
slots: brick.brick === ":forEach" ? (0, _Renderer.childrenToSlots)(children, slots) : Object.fromEntries(Object.entries((_childrenToSlots = (0, _Renderer.childrenToSlots)(children, slots)) !== null && _childrenToSlots !== void 0 ? _childrenToSlots : {}).map(([slotName, slotConf]) => [slotName, slotConf.type === "routes" ? {
|
|
109
|
+
type: "routes",
|
|
110
|
+
routes: setupTemplateExternalRoutesWithForEach(slotConf.routes, forEachItem, forEachIndex, forEachSize)
|
|
111
|
+
} : {
|
|
112
|
+
type: "bricks",
|
|
113
|
+
bricks: setupTemplateExternalBricksWithForEach(slotConf.bricks, forEachItem, forEachIndex, forEachSize)
|
|
114
|
+
}]))
|
|
115
|
+
};
|
|
116
|
+
});
|
|
114
117
|
}
|
|
115
118
|
function setupTemplateExternalRoutesWithForEach(routes, forEachItem, forEachIndex, forEachSize) {
|
|
116
119
|
return routes.map(route => route.type === "routes" ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","_Renderer","setupTemplateProxy","hostContext","ref","slots","slotted","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","from","to","filtered","filter","entry","length","refProperty","computePropertyValue","Boolean","slotProxies","Error","type","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","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 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<AsyncPropertyEntry | undefined>(({ 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 AsyncPropertyEntry[];\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,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,EACxBC,OAAgB,EAChB;EACA,MAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IAC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C,IAAAY,yBAAe,EAACL,QAAQ,EAAExD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAACa,GAAG,CACxD,CAAC,CAACkC,QAAQ,EAAEG,QAAQ,CAAC,KAAK,CACxBH,QAAQ,EACRG,QAAQ,CAACzB,IAAI,KAAK,QAAQ,GACtB;MACEA,IAAI,EAAE,QAAQ;MACduC,MAAM,EAAEC,sCAAsC,CAC5Cf,QAAQ,CAACc,MAAM,EACfpB,WAAW,EACXC,YAAY,EACZC,WACF;IACF,CAAC,GACD;MACErB,IAAI,EAAE,QAAQ;MACdK,MAAM,EAAEa,sCAAsC,CAC5CO,QAAQ,CAACpB,MAAM,EACfc,WAAW,EACXC,YAAY,EACZC,WACF;IACF,CAAC,CAET,CACF;EACR,CAAC,CACH,CAAC;AACH;AAEA,SAASmB,sCAAsCA,CAC7CD,MAAmB,EACnBpB,WAAoB,EACpBC,YAAoB,EACpBC,WAAmB,EACN;EACb,OAAOkB,MAAM,CAACnD,GAAG,CAAEqD,KAAK,IACtBA,KAAK,CAACzC,IAAI,KAAK,QAAQ,GACnB;IACE,GAAGyC,KAAK;IACRF,MAAM,EAAEC,sCAAsC,CAC5CC,KAAK,CAACF,MAAM,EACZpB,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CAAC,GACDoB,KAAK,CAACzC,IAAI,KAAK,UAAU,GACvByC,KAAK,GACL;IACE,GAAGA,KAAK;IACRpC,MAAM,EAAEa,sCAAsC,CAC5CuB,KAAK,CAACpC,MAAM,EACZc,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"setupTemplateProxy.js","names":["_general","require","_lodash","_constants","_computeRealProperties","_Renderer","setupTemplateProxy","hostContext","ref","slots","slotted","reversedProxies","asyncHostPropertyEntries","externalSlots","tplStateStoreId","hostBrick","asyncComputedProps","propertyProxies","properties","get","getComputedProps","asyncHostProps","map","from","to","filtered","filter","entry","length","refProperty","computePropertyValue","Boolean","slotProxies","Error","type","quasisMap","Map","_externalSlots$from$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","hasOwnProperty","i","push","set","refPosition","hostHasForEach","runtimeContext","clamp","setupTemplateExternalBricksWithForEach","forEachItem","forEachIndex","forEachSize","slotName","quasis","entries","slotConf","flatMap","index","concat","symbolForAsyncComputedPropsFromHost","symbolForTplStateStoreId","children","brick","_childrenToSlots","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 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<AsyncPropertyEntry | undefined>(({ 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 AsyncPropertyEntry[];\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: setupTemplateEx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,OAAOmB,MAAM,CAACvD,GAAG,CAAEyD,KAAK,IACtBA,KAAK,CAAC7C,IAAI,KAAK,QAAQ,GACnB;IACE,GAAG6C,KAAK;IACRF,MAAM,EAAEC,sCAAsC,CAC5CC,KAAK,CAACF,MAAM,EACZrB,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CAAC,GACDqB,KAAK,CAAC7C,IAAI,KAAK,UAAU,GACvB6C,KAAK,GACL;IACE,GAAGA,KAAK;IACRrC,MAAM,EAAEa,sCAAsC,CAC5CwB,KAAK,CAACrC,MAAM,EACZc,WAAW,EACXC,YAAY,EACZC,WACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -34,10 +34,13 @@ function setupUseBrickInTemplate(props, hostContext) {
|
|
|
34
34
|
const markChild = () => {
|
|
35
35
|
slotted = true;
|
|
36
36
|
};
|
|
37
|
-
const slots = Object.fromEntries(Object.entries(transpiledSlots
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const slots = Object.fromEntries(Object.entries(transpiledSlots !== null && transpiledSlots !== void 0 ? transpiledSlots : {}).map(([slotName, slotConf]) => {
|
|
38
|
+
var _slotConf$bricks;
|
|
39
|
+
return [slotName, {
|
|
40
|
+
type: "bricks",
|
|
41
|
+
bricks: ((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : []).flatMap(it => setup(it, markChild))
|
|
42
|
+
}];
|
|
43
|
+
}));
|
|
41
44
|
return {
|
|
42
45
|
...restConf,
|
|
43
46
|
properties: walk(properties),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupUseBrickInTemplate.js","names":["_general","require","_setupTemplateProxy","_Renderer","_replaceSlotWithSlottedBricks","setupUseBrickInTemplate","props","hostContext","walk","isObject","Array","isArray","map","Object","fromEntries","entries","key","value","flatMap","v","setup","concat","getOwnPropertySymbols","k","item","markSlotted","brick","replaceSlotWithSlottedBricks","it","properties","slots","originalSlots","children","restConf","transpiledSlots","childrenToSlots","slotted","markChild","slotName","slotConf","type","bricks","setupTemplateProxy","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,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,6BAAA,GAAAH,OAAA;AAEO,SAASI,uBAAuBA,CACrCC,KAAQ,EACRC,WAAgC,EAC7B;EACH,SAASC,IAAIA,CAAIF,KAAQ,EAAK;IAC5B,IAAI,CAAC,IAAAG,iBAAQ,EAACH,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MACnD,OAAOA,KAAK;IACd;IAEA,IAAII,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;MACxB,OAAOA,KAAK,CAACM,GAAG,CAACJ,IAAI,CAAC;IACxB;IAEA,OAAOK,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACT,KAAK,CAAC,CAClBM,GAAG,CAAC,CAAC,CAACI,GAAG,EAAEC,KAAK,CAAC,KAChB,IAAAR,iBAAQ,EAACQ,KAAK,CAAC,IAAID,GAAG,KAAK,UAAU,GACjCN,KAAK,CAACC,OAAO,CAACM,KAAK,CAAC,GAClB,CAACD,GAAG,EAAEC,KAAK,CAACC,OAAO,CAAEC,CAAC,IAAKC,KAAK,CAACD,CAAC,CAAC,CAAC,CAAC,GACrC,CAACH,GAAG,EAAEI,KAAK,CAACH,KAA2B,CAAC,CAAC,GAC3C,CAACD,GAAG,EAAER,IAAI,CAACS,KAAK,CAAC,CACvB,CAAC,CACAI,MAAM,CACLR,MAAM,CAACS,qBAAqB,CAAChB,KAAK,CAAC,CAACM,GAAG,CAAEW,CAAC,IAAK,CAC7CA,CAAC,EACAjB,KAAK,CAAsCiB,CAAC,CAAC,CAC/C,CACH,CACJ,CAAC;EACH;EAEA,SAASH,KAAKA,CACZI,IAAwB,EACxBC,WAAwB,EACmB;IAC3C,IAAID,IAAI,CAACE,KAAK,KAAK,MAAM,EAAE;MACzBD,WAAW,aAAXA,WAAW,eAAXA,WAAW,CAAG,CAAC;MACf,OAAO,IAAAE,0DAA4B,EAACH,IAAI,EAAEjB,WAAW,EAAGqB,EAAE,IAAKR,KAAK,CAACQ,EAAE,CAAC,CAAC;IAC3E;IAEA,MAAM;MAAEC,UAAU;MAAEC,KAAK,EAAEC,aAAa;MAAEC,QAAQ;MAAE,GAAGC;IAAS,CAAC,GAAGT,IAAI;IAExE,MAAMU,eAAe,GAAG,IAAAC,yBAAe,EAACH,QAAQ,EAAED,aAAa,CAElD;IAEb,IAAIK,OAAO,GAAG,KAAK;IACnB,MAAMC,SAAS,GAAGA,CAAA,KAAM;MACtBD,OAAO,GAAG,IAAI;IAChB,CAAC;IACD,MAAMN,KAAK,GAAGjB,MAAM,CAACC,WAAW,CAC9BD,MAAM,CAACE,OAAO,CAACmB,eAAe,
|
|
1
|
+
{"version":3,"file":"setupUseBrickInTemplate.js","names":["_general","require","_setupTemplateProxy","_Renderer","_replaceSlotWithSlottedBricks","setupUseBrickInTemplate","props","hostContext","walk","isObject","Array","isArray","map","Object","fromEntries","entries","key","value","flatMap","v","setup","concat","getOwnPropertySymbols","k","item","markSlotted","brick","replaceSlotWithSlottedBricks","it","properties","slots","originalSlots","children","restConf","transpiledSlots","childrenToSlots","slotted","markChild","slotName","slotConf","_slotConf$bricks","type","bricks","setupTemplateProxy","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,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,6BAAA,GAAAH,OAAA;AAEO,SAASI,uBAAuBA,CACrCC,KAAQ,EACRC,WAAgC,EAC7B;EACH,SAASC,IAAIA,CAAIF,KAAQ,EAAK;IAC5B,IAAI,CAAC,IAAAG,iBAAQ,EAACH,KAAK,CAAC,IAAI,OAAOA,KAAK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K,OAAO,GAAG,KAAK;IACnB,MAAMC,SAAS,GAAGA,CAAA,KAAM;MACtBD,OAAO,GAAG,IAAI;IAChB,CAAC;IACD,MAAMN,KAAK,GAAGjB,MAAM,CAACC,WAAW,CAC9BD,MAAM,CAACE,OAAO,CAACmB,eAAe,aAAfA,eAAe,cAAfA,eAAe,GAAI,CAAC,CAAC,CAAC,CAACtB,GAAG,CAAC,CAAC,CAAC0B,QAAQ,EAAEC,QAAQ,CAAC;MAAA,IAAAC,gBAAA;MAAA,OAAK,CAClEF,QAAQ,EACR;QACEG,IAAI,EAAE,QAAQ;QACdC,MAAM,EAAE,EAAAF,gBAAA,GAACD,QAAQ,CAACG,MAAM,cAAAF,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEtB,OAAO,CAAEU,EAAE,IAAKR,KAAK,CAACQ,EAAE,EAAES,SAAS,CAAC;MACtE,CAAC,CACF;IAAA,EACH,CAAC;IAED,OAAO;MACL,GAAGJ,QAAQ;MACXJ,UAAU,EAAErB,IAAI,CAACqB,UAAU,CAAC;MAC5BC,KAAK;MACL,GAAG,IAAAa,sCAAkB,EAACpC,WAAW,EAAE0B,QAAQ,CAACW,GAAG,EAAEd,KAAK,EAAEM,OAAO;IACjE,CAAC;EACH;EAEA,OAAO5B,IAAI,CAACF,KAAK,CAAC;AACpB","ignoreList":[]}
|
|
@@ -12,11 +12,11 @@ function getTplStateStore({
|
|
|
12
12
|
tplStateStoreMap
|
|
13
13
|
}, using, extraInfo) {
|
|
14
14
|
if (!tplStateStoreId) {
|
|
15
|
-
throw new Error(`Using "${using}" outside of a custom template${extraInfo
|
|
15
|
+
throw new Error(`Using "${using}" outside of a custom template${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}`);
|
|
16
16
|
}
|
|
17
17
|
const store = tplStateStoreMap.get(tplStateStoreId);
|
|
18
18
|
if (!store) {
|
|
19
|
-
throw new Error(`Template state store is not found when using "${using}"${extraInfo
|
|
19
|
+
throw new Error(`Template state store is not found when using "${using}"${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}.\nThis is a bug of Brick Next, please report it.`);
|
|
20
20
|
}
|
|
21
21
|
return store;
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ function getTplHostElement(runtimeContext, using, extraInfo) {
|
|
|
24
24
|
const store = getTplStateStore(runtimeContext, using, extraInfo);
|
|
25
25
|
const hostElement = store.hostBrick.element;
|
|
26
26
|
if (!hostElement) {
|
|
27
|
-
throw new Error(`Template host element is gone when using "${using}"${extraInfo
|
|
27
|
+
throw new Error(`Template host element is gone when using "${using}"${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}.\nThis is a bug of Brick Next, please report it.`);
|
|
28
28
|
}
|
|
29
29
|
return hostElement;
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_CustomTemplates","require","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName","customTemplates"],"sources":["../../../../src/internal/CustomTemplates/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeBrickElement, RuntimeContext } from \"../interfaces.js\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"tplStateStoreId\" | \"tplStateStoreMap\"\n>;\n\nexport function getTplStateStore(\n { tplStateStoreId, tplStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"STATE\"> {\n if (!tplStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of a custom template${extraInfo ?? \"\"}`\n );\n }\n const store = tplStateStoreMap.get(tplStateStoreId);\n if (!store) {\n throw new Error(\n `Template state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n\nexport function getTplHostElement(\n runtimeContext: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): RuntimeBrickElement {\n const store = getTplStateStore(runtimeContext, using, extraInfo);\n const hostElement = store.hostBrick!.element;\n if (!hostElement) {\n throw new Error(\n `Template host element is gone when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return hostElement;\n}\n\nexport function getTagNameOfCustomTemplate(\n brick: string,\n appId?: string\n): false | string {\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && appId) {\n const tagName = `${appId}.${brick}`;\n if (customTemplates.get(tagName)) {\n return tagName;\n }\n }\n if (customTemplates.get(brick)) {\n return brick;\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAOO,SAASC,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACb,UAAUF,KAAK,iCAAiCC,SAAS,
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_CustomTemplates","require","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName","customTemplates"],"sources":["../../../../src/internal/CustomTemplates/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeBrickElement, RuntimeContext } from \"../interfaces.js\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"tplStateStoreId\" | \"tplStateStoreMap\"\n>;\n\nexport function getTplStateStore(\n { tplStateStoreId, tplStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"STATE\"> {\n if (!tplStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of a custom template${extraInfo ?? \"\"}`\n );\n }\n const store = tplStateStoreMap.get(tplStateStoreId);\n if (!store) {\n throw new Error(\n `Template state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n\nexport function getTplHostElement(\n runtimeContext: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): RuntimeBrickElement {\n const store = getTplStateStore(runtimeContext, using, extraInfo);\n const hostElement = store.hostBrick!.element;\n if (!hostElement) {\n throw new Error(\n `Template host element is gone when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return hostElement;\n}\n\nexport function getTagNameOfCustomTemplate(\n brick: string,\n appId?: string\n): false | string {\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && appId) {\n const tagName = `${appId}.${brick}`;\n if (customTemplates.get(tagName)) {\n return tagName;\n }\n }\n if (customTemplates.get(brick)) {\n return brick;\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAOO,SAASC,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACb,UAAUF,KAAK,iCAAiCC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAE,EACjE,CAAC;EACH;EACA,MAAME,KAAK,GAAGJ,gBAAgB,CAACK,GAAG,CAACN,eAAe,CAAC;EACnD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACb,iDAAiDF,KAAK,IACpDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAE,mDAEnB,CAAC;EACH;EACA,OAAOE,KAAK;AACd;AAEO,SAASE,iBAAiBA,CAC/BC,cAA2C,EAC3CN,KAAa,EACbC,SAAkB,EACG;EACrB,MAAME,KAAK,GAAGN,gBAAgB,CAACS,cAAc,EAAEN,KAAK,EAAEC,SAAS,CAAC;EAChE,MAAMM,WAAW,GAAGJ,KAAK,CAACK,SAAS,CAAEC,OAAO;EAC5C,IAAI,CAACF,WAAW,EAAE;IAChB,MAAM,IAAIL,KAAK,CACb,6CAA6CF,KAAK,IAChDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAE,mDAEnB,CAAC;EACH;EACA,OAAOM,WAAW;AACpB;AAEO,SAASG,0BAA0BA,CACxCC,KAAa,EACbC,KAAc,EACE;EAChB;EACA,IAAI,CAACD,KAAK,CAACE,QAAQ,CAAC,GAAG,CAAC,IAAIF,KAAK,CAACG,UAAU,CAAC,MAAM,CAAC,IAAIF,KAAK,EAAE;IAC7D,MAAMG,OAAO,GAAG,GAAGH,KAAK,IAAID,KAAK,EAAE;IACnC,IAAIK,gCAAe,CAACZ,GAAG,CAACW,OAAO,CAAC,EAAE;MAChC,OAAOA,OAAO;IAChB;EACF;EACA,IAAIC,gCAAe,CAACZ,GAAG,CAACO,KAAK,CAAC,EAAE;IAC9B,OAAOA,KAAK;EACd;EACA,OAAO,KAAK;AACd","ignoreList":[]}
|
|
@@ -39,8 +39,9 @@ async function ErrorNode(error, returnNode, pageLevel) {
|
|
|
39
39
|
showDescription
|
|
40
40
|
} = getRefinedErrorConf(error);
|
|
41
41
|
if (pageLevel) {
|
|
42
|
+
var _presetBricks$error;
|
|
42
43
|
const presetBricks = (0, _Runtime._internalApiGetPresetBricks)();
|
|
43
|
-
const errorBrick = presetBricks.error
|
|
44
|
+
const errorBrick = (_presetBricks$error = presetBricks.error) !== null && _presetBricks$error !== void 0 ? _presetBricks$error : "illustrations.error-message";
|
|
44
45
|
if (errorBrick !== false) {
|
|
45
46
|
const linkBrick = "eo-link";
|
|
46
47
|
const bricks = (showLink ? [errorBrick, linkBrick] : [errorBrick]).filter(brick => !customElements.get(brick));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorNode.js","names":["_loader","require","_http","_i18n","_handleHttpError","_enums","_Runtime","_i18n2","_getBasePath","PageNotFoundError","Error","constructor","message","name","captureStackTrace","BrickLoadError","exports","ErrorNode","error","returnNode","pageLevel","title","variant","showLink","showDescription","getRefinedErrorConf","presetBricks","_internalApiGetPresetBricks","errorBrick","linkBrick","bricks","filter","brick","customElements","get","Promise","race","loadBricksImperatively","getBrickPackages","_resolve","reject","setTimeout","node","tag","RenderTag","BRICK","type","properties","errorTitle","description","httpErrorToString","undefined","dataset","errorBoundary","runtimeContext","return","child","getLinkNode","e","console","join","useDefaultError","style","color","descriptionNode","textContent","sibling","parent","slotId","i18n","t","NS","K","GO_BACK_HOME","RELOAD","GO_BACK_TO_PREVIOUS_PAGE","href","getBasePath","location","events","click","action","_error$response","_error$responseJson","APP_NOT_FOUND","PAGE_NOT_FOUND","Event","target","HTMLScriptElement","NETWORK_ERROR","HttpResponseError","response","status","NO_PERMISSION","responseJson","code","LICENSE_EXPIRED","UNKNOWN_ERROR"],"sources":["../../../src/internal/ErrorNode.ts"],"sourcesContent":["import { loadBricksImperatively, BrickLoadError } from \"@next-core/loader\";\nimport { HttpResponseError } from \"@next-core/http\";\nimport { i18n } from \"@next-core/i18n\";\nimport { httpErrorToString } from \"../handleHttpError.js\";\nimport { RenderTag } from \"./enums.js\";\nimport type { RenderChildNode, RenderReturnNode } from \"./interfaces.js\";\nimport { _internalApiGetPresetBricks, getBrickPackages } from \"./Runtime.js\";\nimport { K, NS } from \"./i18n.js\";\nimport { getBasePath } from \"../getBasePath.js\";\n\ntype ErrorMessageVariant =\n | \"internet-disconnected\"\n | \"no-permission\"\n | \"license-expired\"\n | \"not-found\"\n | \"unknown-error\";\n\ninterface ErrorMessageConfig {\n title: string;\n variant: ErrorMessageVariant;\n showLink?: LinkType;\n showDescription?: boolean;\n}\n\ntype LinkType = \"home\" | \"previous\" | \"reload\";\n\nexport class PageNotFoundError extends Error {\n constructor(message: \"page not found\" | \"app not found\") {\n // Pass remaining arguments (including vendor specific ones) to parent constructor\n super(message);\n\n this.name = \"PageNotFoundError\";\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n // istanbul ignore else\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, BrickLoadError);\n }\n }\n}\n\n/**\n * Will always resolve\n */\nexport async function ErrorNode(\n error: unknown,\n returnNode: RenderReturnNode,\n pageLevel?: boolean\n): Promise<RenderChildNode> {\n const { title, variant, showLink, showDescription } =\n getRefinedErrorConf(error);\n\n if (pageLevel) {\n const presetBricks = _internalApiGetPresetBricks();\n const errorBrick = presetBricks.error ?? \"illustrations.error-message\";\n if (errorBrick !== false) {\n const linkBrick = \"eo-link\";\n const bricks = (showLink ? [errorBrick, linkBrick] : [errorBrick]).filter(\n (brick) => !customElements.get(brick)\n );\n try {\n await Promise.race([\n loadBricksImperatively(bricks, getBrickPackages()),\n // Timeout after 3 seconds\n new Promise<void>((_resolve, reject) =>\n setTimeout(() => {\n reject(new Error(\"timeout\"));\n }, 3e3)\n ),\n ]);\n const node: RenderChildNode = {\n tag: RenderTag.BRICK,\n type: errorBrick,\n properties: {\n errorTitle: title,\n description: showDescription ? httpErrorToString(error) : undefined,\n variant,\n dataset: {\n errorBoundary: \"\",\n },\n },\n runtimeContext: null!,\n return: returnNode,\n };\n\n if (showLink) {\n node.child = getLinkNode(showLink, linkBrick, node, \"\");\n }\n\n return node;\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Failed to load brick:\", bricks.join(\", \"), e);\n }\n }\n }\n\n const useDefaultError =\n pageLevel && !!customElements.get(\"easyops-default-error\");\n\n const node: RenderChildNode = {\n tag: RenderTag.BRICK,\n type: useDefaultError ? \"easyops-default-error\" : \"div\",\n properties: {\n errorTitle: title,\n dataset: {\n errorBoundary: \"\",\n },\n style: {\n color: \"var(--color-error)\",\n },\n },\n runtimeContext: null!,\n return: returnNode,\n };\n\n const descriptionNode: RenderChildNode = {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: useDefaultError\n ? showDescription\n ? httpErrorToString(error)\n : \"\"\n : showDescription\n ? `${title}: ${httpErrorToString(error)}`\n : title,\n },\n runtimeContext: null!,\n return: node,\n };\n\n node.child = descriptionNode;\n\n if (pageLevel && showLink) {\n descriptionNode.sibling = getLinkNode(\n showLink,\n \"a\",\n node,\n useDefaultError ? \"link\" : \"\"\n );\n }\n\n return node;\n}\n\nfunction getLinkNode(\n showLink: LinkType | undefined,\n brick: string,\n parent: RenderReturnNode,\n slotId: string\n): RenderChildNode {\n return {\n tag: RenderTag.BRICK,\n type: brick,\n slotId,\n properties: {\n textContent:\n showLink === \"home\"\n ? i18n.t(`${NS}:${K.GO_BACK_HOME}`)\n : showLink === \"reload\"\n ? i18n.t(`${NS}:${K.RELOAD}`)\n : i18n.t(`${NS}:${K.GO_BACK_TO_PREVIOUS_PAGE}`),\n href:\n showLink === \"home\"\n ? getBasePath()\n : showLink === \"reload\"\n ? location.href\n : undefined,\n },\n events:\n showLink === \"previous\"\n ? {\n click: {\n action: \"history.goBack\",\n },\n }\n : undefined,\n runtimeContext: null!,\n return: parent,\n };\n}\n\nfunction getRefinedErrorConf(error: unknown): ErrorMessageConfig {\n if (error instanceof PageNotFoundError) {\n return error.message === \"app not found\"\n ? {\n showLink: \"home\",\n title: i18n.t(`${NS}:${K.APP_NOT_FOUND}`),\n variant: \"no-permission\",\n }\n : {\n showLink: \"home\",\n variant: \"not-found\",\n title: i18n.t(`${NS}:${K.PAGE_NOT_FOUND}`),\n };\n }\n\n if (\n error instanceof BrickLoadError ||\n (error instanceof Error && error.name === \"ChunkLoadError\") ||\n (error instanceof Event &&\n error.type === \"error\" &&\n error.target instanceof HTMLScriptElement)\n ) {\n return {\n showDescription: true,\n title: i18n.t(`${NS}:${K.NETWORK_ERROR}`),\n variant: \"internet-disconnected\",\n showLink: \"reload\",\n };\n }\n\n if (error instanceof HttpResponseError && error.response?.status === 403) {\n return {\n showLink: \"previous\",\n showDescription: true,\n title: i18n.t(`${NS}:${K.NO_PERMISSION}`),\n variant: \"no-permission\",\n };\n }\n\n if (\n error instanceof HttpResponseError &&\n error.responseJson?.code === \"200000\"\n ) {\n return {\n showDescription: true,\n title: i18n.t(`${NS}:${K.LICENSE_EXPIRED}`),\n variant: \"license-expired\",\n };\n }\n\n return {\n showLink: \"previous\",\n showDescription: true,\n title: i18n.t(`${NS}:${K.UNKNOWN_ERROR}`),\n variant: \"unknown-error\",\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAkBO,MAAMQ,iBAAiB,SAASC,KAAK,CAAC;EAC3CC,WAAWA,CAACC,OAA2C,EAAE;IACvD;IACA,KAAK,CAACA,OAAO,CAAC;IAEd,IAAI,CAACC,IAAI,GAAG,mBAAmB;;IAE/B;IACA;IACA,IAAIH,KAAK,CAACI,iBAAiB,EAAE;MAC3BJ,KAAK,CAACI,iBAAiB,CAAC,IAAI,EAAEC,sBAAc,CAAC;IAC/C;EACF;AACF;;AAEA;AACA;AACA;AAFAC,OAAA,CAAAP,iBAAA,GAAAA,iBAAA;AAGO,eAAeQ,SAASA,CAC7BC,KAAc,EACdC,UAA4B,EAC5BC,SAAmB,EACO;EAC1B,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,QAAQ;IAAEC;EAAgB,CAAC,GACjDC,mBAAmB,CAACP,KAAK,CAAC;EAE5B,IAAIE,SAAS,EAAE;IACb,MAAMM,YAAY,GAAG,IAAAC,oCAA2B,EAAC,CAAC;IAClD,MAAMC,UAAU,GAAGF,YAAY,CAACR,KAAK,IAAI,6BA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AC4B,IAAI,KAAK,OAAO,IACtB5B,KAAK,CAACqE,MAAM,YAAYC,iBAAkB,EAC5C;IACA,OAAO;MACLhE,eAAe,EAAE,IAAI;MACrBH,KAAK,EAAEgD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACiB,aAAa,EAAE,CAAC;MACzCnE,OAAO,EAAE,uBAAuB;MAChCC,QAAQ,EAAE;IACZ,CAAC;EACH;EAEA,IAAIL,KAAK,YAAYwE,uBAAiB,IAAI,EAAAR,eAAA,GAAAhE,KAAK,CAACyE,QAAQ,cAAAT,eAAA,uBAAdA,eAAA,CAAgBU,MAAM,MAAK,GAAG,EAAE;IACxE,OAAO;MACLrE,QAAQ,EAAE,UAAU;MACpBC,eAAe,EAAE,IAAI;MACrBH,KAAK,EAAEgD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACqB,aAAa,EAAE,CAAC;MACzCvE,OAAO,EAAE;IACX,CAAC;EACH;EAEA,IACEJ,KAAK,YAAYwE,uBAAiB,IAClC,EAAAP,mBAAA,GAAAjE,KAAK,CAAC4E,YAAY,cAAAX,mBAAA,uBAAlBA,mBAAA,CAAoBY,IAAI,MAAK,QAAQ,EACrC;IACA,OAAO;MACLvE,eAAe,EAAE,IAAI;MACrBH,KAAK,EAAEgD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACwB,eAAe,EAAE,CAAC;MAC3C1E,OAAO,EAAE;IACX,CAAC;EACH;EAEA,OAAO;IACLC,QAAQ,EAAE,UAAU;IACpBC,eAAe,EAAE,IAAI;IACrBH,KAAK,EAAEgD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACyB,aAAa,EAAE,CAAC;IACzC3E,OAAO,EAAE;EACX,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ErrorNode.js","names":["_loader","require","_http","_i18n","_handleHttpError","_enums","_Runtime","_i18n2","_getBasePath","PageNotFoundError","Error","constructor","message","name","captureStackTrace","BrickLoadError","exports","ErrorNode","error","returnNode","pageLevel","title","variant","showLink","showDescription","getRefinedErrorConf","_presetBricks$error","presetBricks","_internalApiGetPresetBricks","errorBrick","linkBrick","bricks","filter","brick","customElements","get","Promise","race","loadBricksImperatively","getBrickPackages","_resolve","reject","setTimeout","node","tag","RenderTag","BRICK","type","properties","errorTitle","description","httpErrorToString","undefined","dataset","errorBoundary","runtimeContext","return","child","getLinkNode","e","console","join","useDefaultError","style","color","descriptionNode","textContent","sibling","parent","slotId","i18n","t","NS","K","GO_BACK_HOME","RELOAD","GO_BACK_TO_PREVIOUS_PAGE","href","getBasePath","location","events","click","action","_error$response","_error$responseJson","APP_NOT_FOUND","PAGE_NOT_FOUND","Event","target","HTMLScriptElement","NETWORK_ERROR","HttpResponseError","response","status","NO_PERMISSION","responseJson","code","LICENSE_EXPIRED","UNKNOWN_ERROR"],"sources":["../../../src/internal/ErrorNode.ts"],"sourcesContent":["import { loadBricksImperatively, BrickLoadError } from \"@next-core/loader\";\nimport { HttpResponseError } from \"@next-core/http\";\nimport { i18n } from \"@next-core/i18n\";\nimport { httpErrorToString } from \"../handleHttpError.js\";\nimport { RenderTag } from \"./enums.js\";\nimport type { RenderChildNode, RenderReturnNode } from \"./interfaces.js\";\nimport { _internalApiGetPresetBricks, getBrickPackages } from \"./Runtime.js\";\nimport { K, NS } from \"./i18n.js\";\nimport { getBasePath } from \"../getBasePath.js\";\n\ntype ErrorMessageVariant =\n | \"internet-disconnected\"\n | \"no-permission\"\n | \"license-expired\"\n | \"not-found\"\n | \"unknown-error\";\n\ninterface ErrorMessageConfig {\n title: string;\n variant: ErrorMessageVariant;\n showLink?: LinkType;\n showDescription?: boolean;\n}\n\ntype LinkType = \"home\" | \"previous\" | \"reload\";\n\nexport class PageNotFoundError extends Error {\n constructor(message: \"page not found\" | \"app not found\") {\n // Pass remaining arguments (including vendor specific ones) to parent constructor\n super(message);\n\n this.name = \"PageNotFoundError\";\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n // istanbul ignore else\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, BrickLoadError);\n }\n }\n}\n\n/**\n * Will always resolve\n */\nexport async function ErrorNode(\n error: unknown,\n returnNode: RenderReturnNode,\n pageLevel?: boolean\n): Promise<RenderChildNode> {\n const { title, variant, showLink, showDescription } =\n getRefinedErrorConf(error);\n\n if (pageLevel) {\n const presetBricks = _internalApiGetPresetBricks();\n const errorBrick = presetBricks.error ?? \"illustrations.error-message\";\n if (errorBrick !== false) {\n const linkBrick = \"eo-link\";\n const bricks = (showLink ? [errorBrick, linkBrick] : [errorBrick]).filter(\n (brick) => !customElements.get(brick)\n );\n try {\n await Promise.race([\n loadBricksImperatively(bricks, getBrickPackages()),\n // Timeout after 3 seconds\n new Promise<void>((_resolve, reject) =>\n setTimeout(() => {\n reject(new Error(\"timeout\"));\n }, 3e3)\n ),\n ]);\n const node: RenderChildNode = {\n tag: RenderTag.BRICK,\n type: errorBrick,\n properties: {\n errorTitle: title,\n description: showDescription ? httpErrorToString(error) : undefined,\n variant,\n dataset: {\n errorBoundary: \"\",\n },\n },\n runtimeContext: null!,\n return: returnNode,\n };\n\n if (showLink) {\n node.child = getLinkNode(showLink, linkBrick, node, \"\");\n }\n\n return node;\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Failed to load brick:\", bricks.join(\", \"), e);\n }\n }\n }\n\n const useDefaultError =\n pageLevel && !!customElements.get(\"easyops-default-error\");\n\n const node: RenderChildNode = {\n tag: RenderTag.BRICK,\n type: useDefaultError ? \"easyops-default-error\" : \"div\",\n properties: {\n errorTitle: title,\n dataset: {\n errorBoundary: \"\",\n },\n style: {\n color: \"var(--color-error)\",\n },\n },\n runtimeContext: null!,\n return: returnNode,\n };\n\n const descriptionNode: RenderChildNode = {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: useDefaultError\n ? showDescription\n ? httpErrorToString(error)\n : \"\"\n : showDescription\n ? `${title}: ${httpErrorToString(error)}`\n : title,\n },\n runtimeContext: null!,\n return: node,\n };\n\n node.child = descriptionNode;\n\n if (pageLevel && showLink) {\n descriptionNode.sibling = getLinkNode(\n showLink,\n \"a\",\n node,\n useDefaultError ? \"link\" : \"\"\n );\n }\n\n return node;\n}\n\nfunction getLinkNode(\n showLink: LinkType | undefined,\n brick: string,\n parent: RenderReturnNode,\n slotId: string\n): RenderChildNode {\n return {\n tag: RenderTag.BRICK,\n type: brick,\n slotId,\n properties: {\n textContent:\n showLink === \"home\"\n ? i18n.t(`${NS}:${K.GO_BACK_HOME}`)\n : showLink === \"reload\"\n ? i18n.t(`${NS}:${K.RELOAD}`)\n : i18n.t(`${NS}:${K.GO_BACK_TO_PREVIOUS_PAGE}`),\n href:\n showLink === \"home\"\n ? getBasePath()\n : showLink === \"reload\"\n ? location.href\n : undefined,\n },\n events:\n showLink === \"previous\"\n ? {\n click: {\n action: \"history.goBack\",\n },\n }\n : undefined,\n runtimeContext: null!,\n return: parent,\n };\n}\n\nfunction getRefinedErrorConf(error: unknown): ErrorMessageConfig {\n if (error instanceof PageNotFoundError) {\n return error.message === \"app not found\"\n ? {\n showLink: \"home\",\n title: i18n.t(`${NS}:${K.APP_NOT_FOUND}`),\n variant: \"no-permission\",\n }\n : {\n showLink: \"home\",\n variant: \"not-found\",\n title: i18n.t(`${NS}:${K.PAGE_NOT_FOUND}`),\n };\n }\n\n if (\n error instanceof BrickLoadError ||\n (error instanceof Error && error.name === \"ChunkLoadError\") ||\n (error instanceof Event &&\n error.type === \"error\" &&\n error.target instanceof HTMLScriptElement)\n ) {\n return {\n showDescription: true,\n title: i18n.t(`${NS}:${K.NETWORK_ERROR}`),\n variant: \"internet-disconnected\",\n showLink: \"reload\",\n };\n }\n\n if (error instanceof HttpResponseError && error.response?.status === 403) {\n return {\n showLink: \"previous\",\n showDescription: true,\n title: i18n.t(`${NS}:${K.NO_PERMISSION}`),\n variant: \"no-permission\",\n };\n }\n\n if (\n error instanceof HttpResponseError &&\n error.responseJson?.code === \"200000\"\n ) {\n return {\n showDescription: true,\n title: i18n.t(`${NS}:${K.LICENSE_EXPIRED}`),\n variant: \"license-expired\",\n };\n }\n\n return {\n showLink: \"previous\",\n showDescription: true,\n title: i18n.t(`${NS}:${K.UNKNOWN_ERROR}`),\n variant: \"unknown-error\",\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAkBO,MAAMQ,iBAAiB,SAASC,KAAK,CAAC;EAC3CC,WAAWA,CAACC,OAA2C,EAAE;IACvD;IACA,KAAK,CAACA,OAAO,CAAC;IAEd,IAAI,CAACC,IAAI,GAAG,mBAAmB;;IAE/B;IACA;IACA,IAAIH,KAAK,CAACI,iBAAiB,EAAE;MAC3BJ,KAAK,CAACI,iBAAiB,CAAC,IAAI,EAAEC,sBAAc,CAAC;IAC/C;EACF;AACF;;AAEA;AACA;AACA;AAFAC,OAAA,CAAAP,iBAAA,GAAAA,iBAAA;AAGO,eAAeQ,SAASA,CAC7BC,KAAc,EACdC,UAA4B,EAC5BC,SAAmB,EACO;EAC1B,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,QAAQ;IAAEC;EAAgB,CAAC,GACjDC,mBAAmB,CAACP,KAAK,CAAC;EAE5B,IAAIE,SAAS,EAAE;IAAA,IAAAM,mBAAA;IACb,MAAMC,YAAY,GAAG,IAAAC,oCAA2B,EAAC,CAAC;IAClD,MAAMC,UAAU,IAAAH,mBAAA,GAAGC,YAAY,CAACT,KAAK,cAAAQ,mBAAA,cAAAA,mBAAA,GAAI,6BAA6B;IACtE,IAAIG,UAAU,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O,IACtB7B,KAAK,CAACsE,MAAM,YAAYC,iBAAkB,EAC5C;IACA,OAAO;MACLjE,eAAe,EAAE,IAAI;MACrBH,KAAK,EAAEiD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACiB,aAAa,EAAE,CAAC;MACzCpE,OAAO,EAAE,uBAAuB;MAChCC,QAAQ,EAAE;IACZ,CAAC;EACH;EAEA,IAAIL,KAAK,YAAYyE,uBAAiB,IAAI,EAAAR,eAAA,GAAAjE,KAAK,CAAC0E,QAAQ,cAAAT,eAAA,uBAAdA,eAAA,CAAgBU,MAAM,MAAK,GAAG,EAAE;IACxE,OAAO;MACLtE,QAAQ,EAAE,UAAU;MACpBC,eAAe,EAAE,IAAI;MACrBH,KAAK,EAAEiD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACqB,aAAa,EAAE,CAAC;MACzCxE,OAAO,EAAE;IACX,CAAC;EACH;EAEA,IACEJ,KAAK,YAAYyE,uBAAiB,IAClC,EAAAP,mBAAA,GAAAlE,KAAK,CAAC6E,YAAY,cAAAX,mBAAA,uBAAlBA,mBAAA,CAAoBY,IAAI,MAAK,QAAQ,EACrC;IACA,OAAO;MACLxE,eAAe,EAAE,IAAI;MACrBH,KAAK,EAAEiD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACwB,eAAe,EAAE,CAAC;MAC3C3E,OAAO,EAAE;IACX,CAAC;EACH;EAEA,OAAO;IACLC,QAAQ,EAAE,UAAU;IACpBC,eAAe,EAAE,IAAI;IACrBH,KAAK,EAAEiD,UAAI,CAACC,CAAC,CAAC,GAAGC,SAAE,IAAIC,QAAC,CAACyB,aAAa,EAAE,CAAC;IACzC5E,OAAO,EAAE;EACX,CAAC;AACH","ignoreList":[]}
|
|
@@ -12,7 +12,7 @@ var _getDefaultProperties = require("./getDefaultProperties.js");
|
|
|
12
12
|
var _constants = require("./constants.js");
|
|
13
13
|
const formContainers = exports.formContainers = ["forms.general-form", "form.general-form", "eo-form"];
|
|
14
14
|
function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
|
|
15
|
-
var _hostBrickConf$proper;
|
|
15
|
+
var _normalizedFormData$c, _hostBrickConf$proper;
|
|
16
16
|
const normalizedFormData = typeof formData === "string" ? JSON.parse(formData) : formData;
|
|
17
17
|
const formStateStoreId = (0, _lodash.uniqueId)("form-state-");
|
|
18
18
|
const runtimeContext = {
|
|
@@ -32,7 +32,7 @@ function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropert
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Always add a state of `params`.
|
|
35
|
-
const context = normalizedFormData.context
|
|
35
|
+
const context = (_normalizedFormData$c = normalizedFormData.context) !== null && _normalizedFormData$c !== void 0 ? _normalizedFormData$c : [];
|
|
36
36
|
if (!context.some(ctx => ctx.name === "params")) {
|
|
37
37
|
context.push({
|
|
38
38
|
name: "params"
|
|
@@ -112,7 +112,7 @@ function formSchemasToBricks(schemas, fields, formStateStoreId) {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
function mergeEvents(targetEvents, sourceEvents) {
|
|
115
|
-
const events = targetEvents
|
|
115
|
+
const events = targetEvents !== null && targetEvents !== void 0 ? targetEvents : {};
|
|
116
116
|
for (const [eventType, handlers] of Object.entries(sourceEvents)) {
|
|
117
117
|
events[eventType] = (0, _general.hasOwnProperty)(events, eventType) ? [events[eventType], handlers].flat() : handlers;
|
|
118
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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,
|
|
1
|
+
{"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","formContainers","exports","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_normalizedFormData$c","_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,OAA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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":[]}
|
|
@@ -9,11 +9,11 @@ function getFormStateStore({
|
|
|
9
9
|
formStateStoreMap
|
|
10
10
|
}, using, extraInfo) {
|
|
11
11
|
if (!formStateStoreId) {
|
|
12
|
-
throw new Error(`Using "${using}" outside of form renderer${extraInfo
|
|
12
|
+
throw new Error(`Using "${using}" outside of form renderer${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}`);
|
|
13
13
|
}
|
|
14
14
|
const store = formStateStoreMap.get(formStateStoreId);
|
|
15
15
|
if (!store) {
|
|
16
|
-
throw new Error(`Form state store is not found when using "${using}"${extraInfo
|
|
16
|
+
throw new Error(`Form state store is not found when using "${using}"${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}.\nThis is a bug of Brick Next, please report it.`);
|
|
17
17
|
}
|
|
18
18
|
return store;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getFormStateStore","formStateStoreId","formStateStoreMap","using","extraInfo","Error","store","get"],"sources":["../../../../src/internal/FormRenderer/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"formStateStoreId\" | \"formStateStoreMap\"\n>;\n\nexport function getFormStateStore(\n { formStateStoreId, formStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"FORM_STATE\"> {\n if (!formStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of form renderer${extraInfo ?? \"\"}`\n );\n }\n const store = formStateStoreMap.get(formStateStoreId);\n if (!store) {\n throw new Error(\n `Form state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n"],"mappings":";;;;;;AAQO,SAASA,iBAAiBA,CAC/B;EAAEC,gBAAgB;EAAEC;AAA+C,CAAC,EACpEC,KAAa,EACbC,SAAkB,EACO;EACzB,IAAI,CAACH,gBAAgB,EAAE;IACrB,MAAM,IAAII,KAAK,CACb,UAAUF,KAAK,6BAA6BC,SAAS,
|
|
1
|
+
{"version":3,"file":"utils.js","names":["getFormStateStore","formStateStoreId","formStateStoreMap","using","extraInfo","Error","store","get"],"sources":["../../../../src/internal/FormRenderer/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"formStateStoreId\" | \"formStateStoreMap\"\n>;\n\nexport function getFormStateStore(\n { formStateStoreId, formStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"FORM_STATE\"> {\n if (!formStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of form renderer${extraInfo ?? \"\"}`\n );\n }\n const store = formStateStoreMap.get(formStateStoreId);\n if (!store) {\n throw new Error(\n `Form state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n"],"mappings":";;;;;;AAQO,SAASA,iBAAiBA,CAC/B;EAAEC,gBAAgB;EAAEC;AAA+C,CAAC,EACpEC,KAAa,EACbC,SAAkB,EACO;EACzB,IAAI,CAACH,gBAAgB,EAAE;IACrB,MAAM,IAAII,KAAK,CACb,UAAUF,KAAK,6BAA6BC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAE,EAC7D,CAAC;EACH;EACA,MAAME,KAAK,GAAGJ,iBAAiB,CAACK,GAAG,CAACN,gBAAgB,CAAC;EACrD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACb,6CAA6CF,KAAK,IAChDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAE,mDAEnB,CAAC;EACH;EACA,OAAOE,KAAK;AACd","ignoreList":[]}
|
|
@@ -124,7 +124,7 @@ async function renderRoutes(returnNode, routes, _runtimeContext, rendererContext
|
|
|
124
124
|
async function renderBricks(returnNode, bricks, runtimeContext, rendererContext, parentRoutes, menuRequestReturnNode, slotId, tplStack, keyPath, initialTracker) {
|
|
125
125
|
(0, _setupRootRuntimeContext.setupRootRuntimeContext)(bricks, runtimeContext, true);
|
|
126
126
|
const output = getEmptyRenderOutput();
|
|
127
|
-
const kPath = keyPath
|
|
127
|
+
const kPath = keyPath !== null && keyPath !== void 0 ? keyPath : [];
|
|
128
128
|
// 多个构件并行异步转换,但转换的结果按原顺序串行合并。
|
|
129
129
|
const rendered = await Promise.all(bricks.map((brickConf, index) => renderBrick(returnNode, brickConf, runtimeContext, rendererContext, parentRoutes, menuRequestReturnNode, slotId, kPath.concat(index), tplStack && new Map(tplStack), initialTracker)));
|
|
130
130
|
rendered.forEach((item, index) => {
|
|
@@ -222,6 +222,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
222
222
|
}
|
|
223
223
|
const brickName = brickConf.brick;
|
|
224
224
|
if (brickName.startsWith(":")) {
|
|
225
|
+
var _brickConf$lifeCycle;
|
|
225
226
|
ensureValidControlBrick(brickName);
|
|
226
227
|
const {
|
|
227
228
|
dataSource
|
|
@@ -275,7 +276,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
275
276
|
tplStateStoreScope,
|
|
276
277
|
formStateStoreScope
|
|
277
278
|
}) => {
|
|
278
|
-
var _ref;
|
|
279
|
+
var _ref, _ref$node;
|
|
279
280
|
let changedAfterInitial = false;
|
|
280
281
|
const tracker = {
|
|
281
282
|
disposes: [],
|
|
@@ -310,11 +311,11 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
310
311
|
throw new Error(`Maximum rerender stack overflowed (iid: ${brickConf.iid})`);
|
|
311
312
|
}
|
|
312
313
|
}
|
|
313
|
-
(_ref = rawOutput).node
|
|
314
|
+
(_ref$node = (_ref = rawOutput).node) !== null && _ref$node !== void 0 ? _ref$node : _ref.node = {
|
|
314
315
|
tag: _enums.RenderTag.PLACEHOLDER,
|
|
315
316
|
return: returnNode,
|
|
316
317
|
tracking
|
|
317
|
-
}
|
|
318
|
+
};
|
|
318
319
|
return rawOutput;
|
|
319
320
|
};
|
|
320
321
|
const controlledOutput = await renderControlNode({
|
|
@@ -324,8 +325,9 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
324
325
|
const {
|
|
325
326
|
onMount,
|
|
326
327
|
onUnmount
|
|
327
|
-
} = brickConf.lifeCycle
|
|
328
|
+
} = (_brickConf$lifeCycle = brickConf.lifeCycle) !== null && _brickConf$lifeCycle !== void 0 ? _brickConf$lifeCycle : {};
|
|
328
329
|
if (tracking) {
|
|
330
|
+
var _runtimeBrick$dispose;
|
|
329
331
|
controlledOutput.hasTrackingControls = true;
|
|
330
332
|
let renderId = 0;
|
|
331
333
|
const listener = async () => {
|
|
@@ -366,7 +368,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
366
368
|
trailing: true
|
|
367
369
|
});
|
|
368
370
|
const runtimeBrick = returnNode.tag === _enums.RenderTag.BRICK ? returnNode : null;
|
|
369
|
-
const disposes = runtimeBrick ? runtimeBrick.disposes
|
|
371
|
+
const disposes = runtimeBrick ? (_runtimeBrick$dispose = runtimeBrick.disposes) !== null && _runtimeBrick$dispose !== void 0 ? _runtimeBrick$dispose : runtimeBrick.disposes = [] : [];
|
|
370
372
|
if (contextNames) {
|
|
371
373
|
for (const contextName of contextNames) {
|
|
372
374
|
disposes.push(runtimeContext.ctxStore.onChange(contextName, debouncedListener));
|
|
@@ -406,7 +408,8 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
406
408
|
}
|
|
407
409
|
const tplTagName = (0, _utils.getTagNameOfCustomTemplate)(brickName, (_runtimeContext$app = runtimeContext.app) === null || _runtimeContext$app === void 0 ? void 0 : _runtimeContext$app.id);
|
|
408
410
|
if (tplTagName) {
|
|
409
|
-
|
|
411
|
+
var _tplStack$get;
|
|
412
|
+
const tplCount = (_tplStack$get = tplStack.get(tplTagName)) !== null && _tplStack$get !== void 0 ? _tplStack$get : 0;
|
|
410
413
|
if (tplCount >= 10) {
|
|
411
414
|
throw new Error(`Maximum custom template stack overflowed: "${tplTagName}"`);
|
|
412
415
|
}
|
|
@@ -421,15 +424,16 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
421
424
|
let formData;
|
|
422
425
|
let confProps;
|
|
423
426
|
if (brickName === _constants2.FORM_RENDERER) {
|
|
424
|
-
var _brickConf$properties;
|
|
427
|
+
var _brickConf$properties, _brickConf$properties2;
|
|
425
428
|
({
|
|
426
429
|
formData,
|
|
427
430
|
...confProps
|
|
428
|
-
} = brickConf.properties
|
|
429
|
-
if ((_brickConf$
|
|
431
|
+
} = (_brickConf$properties = brickConf.properties) !== null && _brickConf$properties !== void 0 ? _brickConf$properties : {});
|
|
432
|
+
if ((_brickConf$properties2 = brickConf.properties) !== null && _brickConf$properties2 !== void 0 && _brickConf$properties2.compute) {
|
|
430
433
|
formData = await (0, _computeRealValue.asyncComputeRealValue)(formData, runtimeContext);
|
|
431
434
|
}
|
|
432
435
|
} else {
|
|
436
|
+
var _confProps;
|
|
433
437
|
if (runtimeContext.inUseBrick) {
|
|
434
438
|
// Keep v2 behavior for `useBrick`: treat `transform` as `properties`.
|
|
435
439
|
const transform = brickConf.transform;
|
|
@@ -443,7 +447,7 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
443
447
|
}
|
|
444
448
|
}
|
|
445
449
|
}
|
|
446
|
-
confProps
|
|
450
|
+
(_confProps = confProps) !== null && _confProps !== void 0 ? _confProps : confProps = brickConf.properties;
|
|
447
451
|
}
|
|
448
452
|
const trackingContextList = [];
|
|
449
453
|
const asyncPropertyEntries = (0, _computeRealProperties.asyncComputeRealPropertyEntries)(confProps, runtimeContext, trackingContextList);
|
|
@@ -455,7 +459,8 @@ async function legacyRenderBrick(returnNode, brickConf, _runtimeContext, rendere
|
|
|
455
459
|
if (isScript || brickName === "link") {
|
|
456
460
|
const props = await (0, _computeRealProperties.constructAsyncProperties)(asyncPropertyEntries);
|
|
457
461
|
if (isScript ? props.src : props.rel === "stylesheet" && props.href) {
|
|
458
|
-
|
|
462
|
+
var _window$PUBLIC_ROOT;
|
|
463
|
+
const prefix = (_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "";
|
|
459
464
|
if (isScript) {
|
|
460
465
|
const {
|
|
461
466
|
src,
|
|
@@ -766,7 +771,7 @@ function childrenToSlots(children, originalSlots) {
|
|
|
766
771
|
slot: sl,
|
|
767
772
|
...child
|
|
768
773
|
} of children) {
|
|
769
|
-
const slot = sl
|
|
774
|
+
const slot = sl !== null && sl !== void 0 ? sl : "";
|
|
770
775
|
if (!(0, _general.hasOwnProperty)(newSlots, slot)) {
|
|
771
776
|
newSlots[slot] = {
|
|
772
777
|
type: "bricks",
|