@next-core/runtime 1.44.2 → 1.44.4
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/CustomProcessors.js.map +1 -1
- package/dist/cjs/CustomTemplates.js +7 -11
- package/dist/cjs/CustomTemplates.js.map +1 -1
- package/dist/cjs/createRoot.js +4 -4
- package/dist/cjs/createRoot.js.map +1 -1
- package/dist/cjs/getPageInfo.js.map +1 -1
- package/dist/cjs/handleHttpError.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js +4 -5
- package/dist/cjs/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +4 -7
- package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js +21 -24
- package/dist/cjs/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/cjs/internal/CustomTemplates/setupUseBrickInTemplate.js +4 -7
- 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/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 +8 -14
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/RendererContext.js +8 -10
- package/dist/cjs/internal/RendererContext.js.map +1 -1
- package/dist/cjs/internal/Router.js.map +1 -1
- package/dist/cjs/internal/Runtime.js +19 -16
- package/dist/cjs/internal/Runtime.js.map +1 -1
- package/dist/cjs/internal/bindListeners.js +2 -3
- package/dist/cjs/internal/bindListeners.js.map +1 -1
- package/dist/cjs/internal/compute/WidgetFunctions.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/getGeneralGlobals.js.map +1 -1
- package/dist/cjs/internal/compute/getStorageItem.js +1 -2
- package/dist/cjs/internal/compute/getStorageItem.js.map +1 -1
- package/dist/cjs/internal/compute/listenOnTrackingContext.js.map +1 -1
- package/dist/cjs/internal/compute/setRealProperties.js.map +1 -1
- package/dist/cjs/internal/data/DataStore.js.map +1 -1
- package/dist/cjs/internal/data/getProviderBrick.js.map +1 -1
- package/dist/cjs/internal/data/realTimeDataInspect.js.map +1 -1
- package/dist/cjs/internal/data/resolveData.js.map +1 -1
- package/dist/cjs/internal/data/resolveDataStore.js +2 -4
- package/dist/cjs/internal/data/resolveDataStore.js.map +1 -1
- package/dist/cjs/internal/hasInstalledApp.js.map +1 -1
- package/dist/cjs/internal/historyExtended.js.map +1 -1
- package/dist/cjs/internal/matchPath.js.map +1 -1
- package/dist/cjs/internal/matchRoutes.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/mediaQuery.js.map +1 -1
- package/dist/cjs/internal/mount.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/registerAppI18n.js.map +1 -1
- package/dist/cjs/internal/registerCustomTemplates.js.map +1 -1
- package/dist/cjs/internal/secret_internals.js +4 -4
- package/dist/cjs/internal/secret_internals.js.map +1 -1
- package/dist/cjs/internal/setupRootRuntimeContext.js +2 -3
- package/dist/cjs/internal/setupRootRuntimeContext.js.map +1 -1
- package/dist/cjs/isStrictMode.js.map +1 -1
- package/dist/cjs/setLoginStateCookie.js.map +1 -1
- package/dist/cjs/setWatermark.js +4 -4
- package/dist/cjs/setWatermark.js.map +1 -1
- package/dist/cjs/themeAndMode.js +1 -2
- package/dist/cjs/themeAndMode.js.map +1 -1
- package/dist/esm/CustomProcessors.js +5 -5
- package/dist/esm/CustomProcessors.js.map +1 -1
- package/dist/esm/CustomTemplates.js +48 -58
- package/dist/esm/CustomTemplates.js.map +1 -1
- package/dist/esm/Dialog.js +3 -3
- package/dist/esm/Dialog.js.map +1 -1
- package/dist/esm/Notification.js +2 -2
- package/dist/esm/Notification.js.map +1 -1
- package/dist/esm/StoryboardFunctionRegistry.js +18 -18
- package/dist/esm/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/esm/createRoot.js +125 -129
- package/dist/esm/createRoot.js.map +1 -1
- package/dist/esm/fetchByProvider.js +3 -10
- package/dist/esm/fetchByProvider.js.map +1 -1
- package/dist/esm/getBasePath.js +2 -2
- package/dist/esm/getBasePath.js.map +1 -1
- package/dist/esm/getPageInfo.js +5 -5
- package/dist/esm/getPageInfo.js.map +1 -1
- package/dist/esm/getRealValue.js +7 -6
- package/dist/esm/getRealValue.js.map +1 -1
- package/dist/esm/getV2RuntimeFromDll.js +1 -1
- package/dist/esm/getV2RuntimeFromDll.js.map +1 -1
- package/dist/esm/handleHttpError.js +11 -11
- package/dist/esm/handleHttpError.js.map +1 -1
- package/dist/esm/history.js +4 -4
- package/dist/esm/history.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js +13 -17
- package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/constants.js +5 -5
- package/dist/esm/internal/CustomTemplates/constants.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +41 -42
- package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +43 -46
- package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/setupUseBrickInTemplate.js +16 -18
- package/dist/esm/internal/CustomTemplates/setupUseBrickInTemplate.js.map +1 -1
- package/dist/esm/internal/CustomTemplates/utils.js +8 -8
- package/dist/esm/internal/CustomTemplates/utils.js.map +1 -1
- package/dist/esm/internal/FormRenderer/constants.js +2 -2
- package/dist/esm/internal/FormRenderer/constants.js.map +1 -1
- package/dist/esm/internal/FormRenderer/expandFormRenderer.js +28 -23
- package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -1
- package/dist/esm/internal/FormRenderer/getDefaultProperties.js +45 -22
- package/dist/esm/internal/FormRenderer/getDefaultProperties.js.map +1 -1
- package/dist/esm/internal/FormRenderer/utils.js +4 -4
- package/dist/esm/internal/FormRenderer/utils.js.map +1 -1
- package/dist/esm/internal/Renderer.js +517 -580
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/RendererContext.js +132 -148
- package/dist/esm/internal/RendererContext.js.map +1 -1
- package/dist/esm/internal/Router.js +325 -346
- package/dist/esm/internal/Router.js.map +1 -1
- package/dist/esm/internal/Runtime.js +58 -53
- package/dist/esm/internal/Runtime.js.map +1 -1
- package/dist/esm/internal/abortController.js +7 -6
- package/dist/esm/internal/abortController.js.map +1 -1
- package/dist/esm/internal/bindListeners.js +136 -156
- package/dist/esm/internal/bindListeners.js.map +1 -1
- package/dist/esm/internal/compute/StoryboardFunctions.js +1 -1
- package/dist/esm/internal/compute/StoryboardFunctions.js.map +1 -1
- package/dist/esm/internal/compute/WidgetFunctions.js +6 -6
- package/dist/esm/internal/compute/WidgetFunctions.js.map +1 -1
- package/dist/esm/internal/compute/WidgetI18n.js +4 -4
- package/dist/esm/internal/compute/WidgetI18n.js.map +1 -1
- package/dist/esm/internal/compute/checkIf.js +10 -23
- package/dist/esm/internal/compute/checkIf.js.map +1 -1
- package/dist/esm/internal/compute/computeRealProperties.js +22 -35
- package/dist/esm/internal/compute/computeRealProperties.js.map +1 -1
- package/dist/esm/internal/compute/computeRealValue.js +42 -49
- package/dist/esm/internal/compute/computeRealValue.js.map +1 -1
- package/dist/esm/internal/compute/evaluate.js +71 -75
- package/dist/esm/internal/compute/evaluate.js.map +1 -1
- package/dist/esm/internal/compute/getGeneralGlobals.js +5 -5
- package/dist/esm/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/esm/internal/compute/getNextStateOfUseBrick.js +1 -1
- package/dist/esm/internal/compute/getStorageItem.js +2 -3
- package/dist/esm/internal/compute/getStorageItem.js.map +1 -1
- package/dist/esm/internal/compute/getTracks.js +5 -5
- package/dist/esm/internal/compute/getTracks.js.map +1 -1
- package/dist/esm/internal/compute/listenOnTrackingContext.js +8 -11
- package/dist/esm/internal/compute/listenOnTrackingContext.js.map +1 -1
- package/dist/esm/internal/compute/markAsComputed.js +2 -2
- package/dist/esm/internal/compute/markAsComputed.js.map +1 -1
- package/dist/esm/internal/compute/setProperties.js +1 -1
- package/dist/esm/internal/compute/setProperties.js.map +1 -1
- package/dist/esm/internal/compute/setRealProperties.js +3 -3
- package/dist/esm/internal/compute/setRealProperties.js.map +1 -1
- package/dist/esm/internal/customizeColorTheme.js +15 -13
- package/dist/esm/internal/customizeColorTheme.js.map +1 -1
- package/dist/esm/internal/data/DataStore.js +161 -177
- package/dist/esm/internal/data/DataStore.js.map +1 -1
- package/dist/esm/internal/data/getProviderBrick.js +21 -28
- package/dist/esm/internal/data/getProviderBrick.js.map +1 -1
- package/dist/esm/internal/data/realTimeDataInspect.js +5 -5
- package/dist/esm/internal/data/realTimeDataInspect.js.map +1 -1
- package/dist/esm/internal/data/resolveData.js +89 -103
- package/dist/esm/internal/data/resolveData.js.map +1 -1
- package/dist/esm/internal/data/resolveDataStore.js +53 -67
- package/dist/esm/internal/data/resolveDataStore.js.map +1 -1
- package/dist/esm/internal/devtools.js +9 -9
- package/dist/esm/internal/devtools.js.map +1 -1
- package/dist/esm/internal/enums.js +1 -1
- package/dist/esm/internal/fulfilStoryboard.js +15 -28
- package/dist/esm/internal/fulfilStoryboard.js.map +1 -1
- package/dist/esm/internal/hasInstalledApp.js +3 -3
- package/dist/esm/internal/hasInstalledApp.js.map +1 -1
- package/dist/esm/internal/historyExtended.js +40 -37
- package/dist/esm/internal/historyExtended.js.map +1 -1
- package/dist/esm/internal/i18n.js +5 -5
- package/dist/esm/internal/i18n.js.map +1 -1
- package/dist/esm/internal/injected.js +1 -1
- package/dist/esm/internal/injected.js.map +1 -1
- package/dist/esm/internal/insertPreviewRoutes.js +3 -3
- package/dist/esm/internal/insertPreviewRoutes.js.map +1 -1
- package/dist/esm/internal/matchPath.js +17 -17
- package/dist/esm/internal/matchPath.js.map +1 -1
- package/dist/esm/internal/matchRoutes.js +18 -25
- package/dist/esm/internal/matchRoutes.js.map +1 -1
- package/dist/esm/internal/matchStoryboard.js +6 -6
- package/dist/esm/internal/matchStoryboard.js.map +1 -1
- package/dist/esm/internal/mediaQuery.js +11 -11
- package/dist/esm/internal/mediaQuery.js.map +1 -1
- package/dist/esm/internal/mount.js +7 -7
- package/dist/esm/internal/mount.js.map +1 -1
- package/dist/esm/internal/poll.js +53 -60
- package/dist/esm/internal/poll.js.map +1 -1
- package/dist/esm/internal/proxyFactories.js +4 -4
- package/dist/esm/internal/proxyFactories.js.map +1 -1
- package/dist/esm/internal/registerAppI18n.js +6 -6
- package/dist/esm/internal/registerAppI18n.js.map +1 -1
- package/dist/esm/internal/registerCustomTemplates.js +3 -3
- package/dist/esm/internal/registerCustomTemplates.js.map +1 -1
- package/dist/esm/internal/secret_internals.js +140 -146
- package/dist/esm/internal/secret_internals.js.map +1 -1
- package/dist/esm/internal/setupRootRuntimeContext.js +6 -7
- package/dist/esm/internal/setupRootRuntimeContext.js.map +1 -1
- package/dist/esm/internal/sse.js +24 -53
- package/dist/esm/internal/sse.js.map +1 -1
- package/dist/esm/internal/test_only.js +1 -1
- package/dist/esm/isStrictMode.js +3 -3
- package/dist/esm/isStrictMode.js.map +1 -1
- package/dist/esm/setAppVariable.js +1 -1
- package/dist/esm/setAppVariable.js.map +1 -1
- package/dist/esm/setLoginStateCookie.js +5 -5
- package/dist/esm/setLoginStateCookie.js.map +1 -1
- package/dist/esm/setUIVersion.js +1 -1
- package/dist/esm/setWatermark.js +13 -13
- package/dist/esm/setWatermark.js.map +1 -1
- package/dist/esm/themeAndMode.js +14 -13
- package/dist/esm/themeAndMode.js.map +1 -1
- package/dist/types/tsdoc-metadata.json +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachItem","symbolForTPlExternalNoForEach","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$b","_externalSlots$from","_to$refSlot","_to$refPosition","insertBricks","bricks","refToSlot","refSlot","expandableSlot","size","i","push","set","refPosition","hostHasForEach","runtimeContext","__temporary_tpl_tag_name","setupTemplateExternalBricks","forEachItem","forEachIndex","_loop","slotName","type","slotConf","quasis","flatMap","index","concat","entries","hasForEach","_ref2","_childrenToSlots","children","a","b","c","brick","_objectWithoutProperties","_toPropertyKey","_objectSpread","Object","fromEntries","_ref3","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTPlExternalNoForEach,\n symbolForTplStateStoreId,\n type RuntimeBrickConfWithTplSymbols,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n // External bricks of a template, should not access the template internal forEach `ITEM`.\n // For some existing templates who is *USING* this bug, we keep the old behavior.\n const hostHasForEach = hasOwnProperty(\n hostBrick.runtimeContext,\n \"forEachItem\"\n );\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...((hostContext.__temporary_tpl_tag_name ===\n \"base-layout-v3.tpl-scroll-load-list\" ||\n hostContext.__temporary_tpl_tag_name ===\n \"shrcb-homepage.tpl-custom-scroll-load-list\") &&\n !hostHasForEach\n ? insertBricks\n : setupTemplateExternalBricks(\n insertBricks,\n hostHasForEach,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!\n ))\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number\n): BrickConf[] {\n return (bricks as RuntimeBrickConfWithTplSymbols[]).map(\n ({\n children,\n slots,\n [symbolForTPlExternalForEachItem]: a,\n [symbolForTPlExternalForEachIndex]: b,\n [symbolForTPlExternalNoForEach]: c,\n ...brick\n }) => ({\n ...brick,\n ...(hasForEach\n ? {\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n }\n : {\n [symbolForTPlExternalNoForEach]: true,\n }),\n // Keep `:forEach` bricks as original, since they have their own forEachItem context.\n slots:\n brick.brick === \":forEach\"\n ? childrenToSlots(children, slots)\n : Object.fromEntries(\n Object.entries(childrenToSlots(children, slots) ?? {}).map(\n ([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(\n slotConf.routes,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n },\n ]\n )\n ),\n })\n );\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type === \"routes\"\n ? {\n ...route,\n routes: setupTemplateExternalRoutes(\n route.routes,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n : route.type === \"redirect\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(\n route.bricks,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n );\n}\n"],"mappings":";;;AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,gCAAgC,EAChCC,+BAA+B,EAC/BC,6BAA6B,EAC7BC,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,IAAM;IACJC,eAAe;IACfC,wBAAwB;IACxBC,aAAa;IACbC,eAAe;IACfC;EACF,CAAC,GAAGP,WAAW;EAEf,IAAIQ,kBAAoD;EAExD,IAAIP,GAAG,IAAIE,eAAe,EAAE;IAC1B,IAAMM,eAAe,GAAGN,eAAe,CAACO,UAAU,CAACC,GAAG,CAACV,GAAG,CAAC;IAC3D,IAAIQ,eAAe,EAAE;MACnB,IAAMG,gBAAgB,GACpBC,cAAoC,IACX;QACzB,OAAOJ,eAAe,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,2BAA2B,CACjC4B,KAAK,CAACxC,MAAM,EACZwB,UAAU,EACVX,WAAW,EACXC,YACF;EAAC,EAEX,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"setupTemplateProxy.js","names":["hasOwnProperty","clamp","symbolForAsyncComputedPropsFromHost","symbolForTPlExternalForEachIndex","symbolForTPlExternalForEachItem","symbolForTPlExternalNoForEach","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","__temporary_tpl_tag_name","setupTemplateExternalBricks","forEachItem","forEachIndex","slotName","quasis","entries","type","slotConf","flatMap","index","concat","hasForEach","_ref2","children","a","b","c","brick","Object","fromEntries","_ref3","routes","setupTemplateExternalRoutes","route"],"sources":["../../../../src/internal/CustomTemplates/setupTemplateProxy.ts"],"sourcesContent":["import type { BrickConf, RouteConf, SlotsConfOfBricks } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { clamp } from \"lodash\";\nimport {\n symbolForAsyncComputedPropsFromHost,\n symbolForTPlExternalForEachIndex,\n symbolForTPlExternalForEachItem,\n symbolForTPlExternalNoForEach,\n symbolForTplStateStoreId,\n type RuntimeBrickConfWithTplSymbols,\n} from \"./constants.js\";\nimport type { AsyncPropertyEntry, TemplateHostContext } from \"../interfaces.js\";\nimport { computePropertyValue } from \"../compute/computeRealProperties.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\n\nexport function setupTemplateProxy(\n hostContext: TemplateHostContext,\n ref: string | undefined,\n slots: SlotsConfOfBricks\n) {\n const {\n reversedProxies,\n asyncHostPropertyEntries,\n externalSlots,\n tplStateStoreId,\n hostBrick,\n } = hostContext;\n\n let asyncComputedProps: AsyncPropertyEntry[] | undefined;\n\n if (ref && reversedProxies) {\n const propertyProxies = reversedProxies.properties.get(ref);\n if (propertyProxies) {\n const getComputedProps = (\n asyncHostProps: AsyncPropertyEntry[]\n ): AsyncPropertyEntry[] => {\n return propertyProxies!\n .map(({ from, to }) => {\n const filtered = asyncHostProps.filter(\n (entry) => entry[0] === from\n );\n if (filtered.length > 0 && to.refProperty) {\n return [\n to.refProperty,\n computePropertyValue(filtered, from),\n true,\n ];\n }\n })\n .filter(Boolean) as [string, Promise<unknown>][];\n };\n\n asyncComputedProps = getComputedProps(asyncHostPropertyEntries);\n }\n\n const slotProxies = reversedProxies.slots.get(ref);\n if (slotProxies && externalSlots) {\n // Use an approach like template-literal's quasis:\n // `quasi0${0}quais1${1}quasi2...`\n // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.\n const quasisMap = new Map<string, BrickConf[][]>();\n\n for (const { from, to } of slotProxies) {\n const insertBricks = externalSlots[from]?.bricks ?? [];\n if (!insertBricks.length) {\n continue;\n }\n const refToSlot = to.refSlot ?? from;\n let expandableSlot = quasisMap.get(refToSlot);\n if (!expandableSlot) {\n expandableSlot = [];\n // The size of quasis should be the existed slotted bricks' size plus one.\n const size = hasOwnProperty(slots, refToSlot)\n ? slots[refToSlot].bricks.length + 1\n : 1;\n for (let i = 0; i < size; i += 1) {\n expandableSlot.push([]);\n }\n quasisMap.set(refToSlot, expandableSlot);\n }\n const refPosition = to.refPosition ?? -1;\n // External bricks of a template, should not access the template internal forEach `ITEM`.\n // For some existing templates who is *USING* this bug, we keep the old behavior.\n const hostHasForEach = hasOwnProperty(\n hostBrick.runtimeContext,\n \"forEachItem\"\n );\n expandableSlot[\n clamp(\n refPosition < 0 ? expandableSlot.length + refPosition : refPosition,\n 0,\n expandableSlot.length - 1\n )\n ].push(\n ...((hostContext.__temporary_tpl_tag_name ===\n \"base-layout-v3.tpl-scroll-load-list\" ||\n hostContext.__temporary_tpl_tag_name ===\n \"shrcb-homepage.tpl-custom-scroll-load-list\") &&\n !hostHasForEach\n ? insertBricks\n : setupTemplateExternalBricks(\n insertBricks,\n hostHasForEach,\n hostBrick.runtimeContext.forEachItem,\n hostBrick.runtimeContext.forEachIndex!\n ))\n );\n }\n\n for (const [slotName, quasis] of quasisMap.entries()) {\n if (!hasOwnProperty(slots, slotName)) {\n slots[slotName] = {\n type: \"bricks\",\n bricks: [],\n };\n }\n const slotConf = slots[slotName];\n slotConf.bricks = quasis.flatMap((bricks, index) =>\n index < slotConf.bricks.length\n ? bricks.concat(slotConf.bricks[index])\n : bricks\n );\n\n if (slotConf.bricks.length === 0) {\n delete slots[slotName];\n }\n }\n }\n }\n\n return {\n [symbolForAsyncComputedPropsFromHost]: asyncComputedProps,\n [symbolForTplStateStoreId]: tplStateStoreId,\n };\n}\n\n// External bricks of a template, have the same forEachItem context as their host.\nfunction setupTemplateExternalBricks(\n bricks: BrickConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number\n): BrickConf[] {\n return (bricks as RuntimeBrickConfWithTplSymbols[]).map(\n ({\n children,\n slots,\n [symbolForTPlExternalForEachItem]: a,\n [symbolForTPlExternalForEachIndex]: b,\n [symbolForTPlExternalNoForEach]: c,\n ...brick\n }) => ({\n ...brick,\n ...(hasForEach\n ? {\n [symbolForTPlExternalForEachItem]: forEachItem,\n [symbolForTPlExternalForEachIndex]: forEachIndex,\n }\n : {\n [symbolForTPlExternalNoForEach]: true,\n }),\n // Keep `:forEach` bricks as original, since they have their own forEachItem context.\n slots:\n brick.brick === \":forEach\"\n ? childrenToSlots(children, slots)\n : Object.fromEntries(\n Object.entries(childrenToSlots(children, slots) ?? {}).map(\n ([slotName, slotConf]) => [\n slotName,\n slotConf.type === \"routes\"\n ? {\n type: \"routes\",\n routes: setupTemplateExternalRoutes(\n slotConf.routes,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n : {\n type: \"bricks\",\n bricks: setupTemplateExternalBricks(\n slotConf.bricks,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n },\n ]\n )\n ),\n })\n );\n}\n\nfunction setupTemplateExternalRoutes(\n routes: RouteConf[],\n hasForEach: boolean,\n forEachItem: unknown,\n forEachIndex: number\n): RouteConf[] {\n return routes.map((route) =>\n route.type === \"routes\"\n ? {\n ...route,\n routes: setupTemplateExternalRoutes(\n route.routes,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n : route.type === \"redirect\"\n ? route\n : {\n ...route,\n bricks: setupTemplateExternalBricks(\n route.bricks,\n hasForEach,\n forEachItem,\n forEachIndex\n ),\n }\n );\n}\n"],"mappings":"AACA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SACEC,mCAAmC,EACnCC,gCAAgC,EAChCC,+BAA+B,EAC/BC,6BAA6B,EAC7BC,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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ACXC,YACF;QACF,CAAC,GACD;UACEI,IAAI,EAAE,QAAQ;UACdlB,MAAM,EAAEY,2BAA2B,CACjCO,QAAQ,CAACnB,MAAM,EACfuB,UAAU,EACVV,WAAW,EACXC,YACF;QACF,CAAC,CACN;MAAA,CACH,CACF;IACR,CAAC;EAAA,CACH,CAAC;AACH;AAEA,SAASoB,2BAA2BA,CAClCD,MAAmB,EACnBV,UAAmB,EACnBV,WAAoB,EACpBC,YAAoB,EACP;EACb,OAAOmB,MAAM,CAAChD,GAAG,CAAEkD,KAAK,IACtBA,KAAK,CAACjB,IAAI,KAAK,QAAQ,GACnB;IACE,GAAGiB,KAAK;IACRF,MAAM,EAAEC,2BAA2B,CACjCC,KAAK,CAACF,MAAM,EACZV,UAAU,EACVV,WAAW,EACXC,YACF;EACF,CAAC,GACDqB,KAAK,CAACjB,IAAI,KAAK,UAAU,GACvBiB,KAAK,GACL;IACE,GAAGA,KAAK;IACRnC,MAAM,EAAEY,2BAA2B,CACjCuB,KAAK,CAACnC,MAAM,EACZuB,UAAU,EACVV,WAAW,EACXC,YACF;EACF,CACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["properties", "slots", "children"];
|
|
4
1
|
import { isObject } from "@next-core/utils/general";
|
|
5
2
|
import { setupTemplateProxy } from "./setupTemplateProxy.js";
|
|
6
3
|
import { childrenToSlots } from "../Renderer.js";
|
|
@@ -13,30 +10,31 @@ export function setupUseBrickInTemplate(props, hostContext) {
|
|
|
13
10
|
return props.map(walk);
|
|
14
11
|
}
|
|
15
12
|
return Object.fromEntries(Object.entries(props).map(_ref => {
|
|
16
|
-
|
|
13
|
+
let [key, value] = _ref;
|
|
17
14
|
return isObject(value) && key === "useBrick" ? Array.isArray(value) ? [key, value.map(setup)] : [key, setup(value)] : [key, walk(value)];
|
|
18
15
|
}).concat(Object.getOwnPropertySymbols(props).map(k => [k, props[k]])));
|
|
19
16
|
}
|
|
20
17
|
function setup(item) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var [slotName, slotConf] = _ref2;
|
|
18
|
+
const {
|
|
19
|
+
properties,
|
|
20
|
+
slots: originalSlots,
|
|
21
|
+
children,
|
|
22
|
+
...restConf
|
|
23
|
+
} = item;
|
|
24
|
+
const transpiledSlots = childrenToSlots(children, originalSlots);
|
|
25
|
+
const slots = Object.fromEntries(Object.entries(transpiledSlots ?? {}).map(_ref2 => {
|
|
26
|
+
let [slotName, slotConf] = _ref2;
|
|
31
27
|
return [slotName, {
|
|
32
28
|
type: "bricks",
|
|
33
|
-
bricks: (
|
|
29
|
+
bricks: (slotConf.bricks ?? []).map(setup)
|
|
34
30
|
}];
|
|
35
31
|
}));
|
|
36
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
...restConf,
|
|
37
34
|
properties: walk(properties),
|
|
38
|
-
slots
|
|
39
|
-
|
|
35
|
+
slots,
|
|
36
|
+
...setupTemplateProxy(hostContext, restConf.ref, slots)
|
|
37
|
+
};
|
|
40
38
|
}
|
|
41
39
|
return walk(props);
|
|
42
40
|
}
|
|
@@ -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","
|
|
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 { UseBrickSlotsConf, UseSingleBrickConf } 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\";\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.map(setup)]\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(item: UseSingleBrickConf): UseSingleBrickConf {\n const { properties, slots: originalSlots, children, ...restConf } = item;\n\n const transpiledSlots = childrenToSlots(children, originalSlots) as\n | UseBrickSlotsConf\n | undefined;\n\n const slots = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map(setup),\n },\n ])\n ) as UseBrickSlotsConf;\n\n return {\n ...restConf,\n properties: walk(properties),\n slots,\n ...setupTemplateProxy(hostContext, restConf.ref, slots),\n };\n }\n\n return walk(props);\n}\n"],"mappings":"AACA,SAASA,QAAQ,QAAQ,0BAA0B;AAEnD,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,eAAe,QAAQ,gBAAgB;AAEhD,OAAO,SAASC,uBAAuBA,CACrCC,KAAQ,EACRC,WAAgC,EAC7B;EACH,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AC,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,GAAG,CAACO,KAAK;MAC3C,CAAC,CACF;IAAA,EACH,CAAsB;IAEtB,OAAO;MACL,GAAGS,QAAQ;MACXJ,UAAU,EAAEf,IAAI,CAACe,UAAU,CAAC;MAC5BC,KAAK;MACL,GAAGrB,kBAAkB,CAACI,WAAW,EAAEoB,QAAQ,CAACO,GAAG,EAAEV,KAAK;IACxD,CAAC;EACH;EAEA,OAAOhB,IAAI,CAACF,KAAK,CAAC;AACpB","ignoreList":[]}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { customTemplates } from "../../CustomTemplates.js";
|
|
2
2
|
export function getTplStateStore(_ref, using, extraInfo) {
|
|
3
|
-
|
|
3
|
+
let {
|
|
4
4
|
tplStateStoreId,
|
|
5
5
|
tplStateStoreMap
|
|
6
6
|
} = _ref;
|
|
7
7
|
if (!tplStateStoreId) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error(`Using "${using}" outside of a custom template${extraInfo ?? ""}`);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const store = tplStateStoreMap.get(tplStateStoreId);
|
|
11
11
|
if (!store) {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error(`Template state store is not found when using "${using}"${extraInfo ?? ""}.\nThis is a bug of Brick Next, please report it.`);
|
|
13
13
|
}
|
|
14
14
|
return store;
|
|
15
15
|
}
|
|
16
16
|
export function getTplHostElement(runtimeContext, using, extraInfo) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const store = getTplStateStore(runtimeContext, using, extraInfo);
|
|
18
|
+
const hostElement = store.hostBrick.element;
|
|
19
19
|
if (!hostElement) {
|
|
20
|
-
throw new Error(
|
|
20
|
+
throw new Error(`Template host element is gone when using "${using}"${extraInfo ?? ""}.\nThis is a bug of Brick Next, please report it.`);
|
|
21
21
|
}
|
|
22
22
|
return hostElement;
|
|
23
23
|
}
|
|
24
24
|
export function getTagNameOfCustomTemplate(brick, appId) {
|
|
25
25
|
// When a template is registered by an app, it's namespace maybe missed.
|
|
26
26
|
if (!brick.includes(".") && brick.startsWith("tpl-") && appId) {
|
|
27
|
-
|
|
27
|
+
const tagName = `${appId}.${brick}`;
|
|
28
28
|
if (customTemplates.get(tagName)) {
|
|
29
29
|
return tagName;
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["customTemplates","getTplStateStore","_ref","using","extraInfo","tplStateStoreId","tplStateStoreMap","Error","
|
|
1
|
+
{"version":3,"file":"utils.js","names":["customTemplates","getTplStateStore","_ref","using","extraInfo","tplStateStoreId","tplStateStoreMap","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName"],"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,SAASA,eAAe,QAAQ,0BAA0B;AAO1D,OAAO,SAASC,gBAAgBA,CAAAC,IAAA,EAE9BC,KAAa,EACbC,SAAkB,EACE;EAAA,IAHpB;IAAEC,eAAe;IAAEC;EAA8C,CAAC,GAAAJ,IAAA;EAIlE,IAAI,CAACG,eAAe,EAAE;IACpB,MAAM,IAAIE,KAAK,CACb,UAAUJ,KAAK,iCAAiCC,SAAS,IAAI,EAAE,EACjE,CAAC;EACH;EACA,MAAMI,KAAK,GAAGF,gBAAgB,CAACG,GAAG,CAACJ,eAAe,CAAC;EACnD,IAAI,CAACG,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACb,iDAAiDJ,KAAK,IACpDC,SAAS,IAAI,EAAE,mDAEnB,CAAC;EACH;EACA,OAAOI,KAAK;AACd;AAEA,OAAO,SAASE,iBAAiBA,CAC/BC,cAA2C,EAC3CR,KAAa,EACbC,SAAkB,EACG;EACrB,MAAMI,KAAK,GAAGP,gBAAgB,CAACU,cAAc,EAAER,KAAK,EAAEC,SAAS,CAAC;EAChE,MAAMQ,WAAW,GAAGJ,KAAK,CAACK,SAAS,CAAEC,OAAO;EAC5C,IAAI,CAACF,WAAW,EAAE;IAChB,MAAM,IAAIL,KAAK,CACb,6CAA6CJ,KAAK,IAChDC,SAAS,IAAI,EAAE,mDAEnB,CAAC;EACH;EACA,OAAOQ,WAAW;AACpB;AAEA,OAAO,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,IAAIhB,eAAe,CAACS,GAAG,CAACW,OAAO,CAAC,EAAE;MAChC,OAAOA,OAAO;IAChB;EACF;EACA,IAAIpB,eAAe,CAACS,GAAG,CAACO,KAAK,CAAC,EAAE;IAC9B,OAAOA,KAAK;EACd;EACA,OAAO,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export const FORM_RENDERER = "form-renderer.form-renderer";
|
|
2
|
+
export const symbolForFormStateStoreId = Symbol.for("form.stateStoreId");
|
|
3
3
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["FORM_RENDERER","symbolForFormStateStoreId","Symbol","for"],"sources":["../../../../src/internal/FormRenderer/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\n\nexport const FORM_RENDERER = \"form-renderer.form-renderer\";\nexport const symbolForFormStateStoreId = Symbol.for(\"form.stateStoreId\");\n\nexport type RuntimeBrickConfWithFormSymbols = BrickConf &\n RuntimeBrickConfOfFormSymbols;\n\nexport interface RuntimeBrickConfOfFormSymbols {\n [symbolForFormStateStoreId]?: string;\n}\n"],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"constants.js","names":["FORM_RENDERER","symbolForFormStateStoreId","Symbol","for"],"sources":["../../../../src/internal/FormRenderer/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\n\nexport const FORM_RENDERER = \"form-renderer.form-renderer\";\nexport const symbolForFormStateStoreId = Symbol.for(\"form.stateStoreId\");\n\nexport type RuntimeBrickConfWithFormSymbols = BrickConf &\n RuntimeBrickConfOfFormSymbols;\n\nexport interface RuntimeBrickConfOfFormSymbols {\n [symbolForFormStateStoreId]?: string;\n}\n"],"mappings":"AAEA,OAAO,MAAMA,aAAa,GAAG,6BAA6B;AAC1D,OAAO,MAAMC,yBAAyB,GAAGC,MAAM,CAACC,GAAG,CAAC,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
1
|
import { hasOwnProperty } from "@next-core/utils/general";
|
|
3
2
|
import { uniqueId } from "lodash";
|
|
4
3
|
import { DataStore } from "../data/DataStore.js";
|
|
5
4
|
import { getDefaultProperties } from "./getDefaultProperties.js";
|
|
6
5
|
import { symbolForFormStateStoreId } from "./constants.js";
|
|
7
|
-
|
|
6
|
+
const formContainers = ["forms.general-form", "form.general-form", "eo-form"];
|
|
8
7
|
export function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostPropertyEntries, rendererContext) {
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var _hostBrickConf$proper;
|
|
9
|
+
const normalizedFormData = typeof formData === "string" ? JSON.parse(formData) : formData;
|
|
10
|
+
const formStateStoreId = uniqueId("form-state-");
|
|
11
|
+
const runtimeContext = {
|
|
12
|
+
...hostBrick.runtimeContext,
|
|
13
13
|
formStateStoreId
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
|
|
16
16
|
// There is a boundary for `forEachItem` and `STATE` between form internals and externals.
|
|
17
17
|
delete runtimeContext.forEachItem;
|
|
18
18
|
delete runtimeContext.forEachIndex;
|
|
19
19
|
delete runtimeContext.tplStateStoreId;
|
|
20
|
-
|
|
20
|
+
const formStateStore = new DataStore("FORM_STATE", undefined, rendererContext, formStateStoreId);
|
|
21
21
|
runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);
|
|
22
22
|
if (runtimeContext.formStateStoreScope) {
|
|
23
23
|
runtimeContext.formStateStoreScope.push(formStateStore);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Always add a state of `params`.
|
|
27
|
-
|
|
27
|
+
const context = normalizedFormData.context ?? [];
|
|
28
28
|
if (!context.some(ctx => ctx.name === "params")) {
|
|
29
29
|
context.push({
|
|
30
30
|
name: "params"
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
formStateStore.define(context, runtimeContext, asyncHostPropertyEntries);
|
|
34
|
-
|
|
34
|
+
const formConf = formSchemaToBrick(normalizedFormData.formSchema, normalizedFormData.fields, formStateStoreId);
|
|
35
35
|
if (formContainers.includes(formConf.brick) && hostBrickConf.events) {
|
|
36
36
|
formConf.events = mergeEvents(formConf.events, hostBrickConf.events);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
const renderRoot = typeof ((_hostBrickConf$proper = hostBrickConf.properties) === null || _hostBrickConf$proper === void 0 ? void 0 : _hostBrickConf$proper.renderRoot) !== "boolean" || hostBrickConf.properties.renderRoot;
|
|
39
39
|
if (renderRoot) {
|
|
40
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
...hostBrickConf,
|
|
41
42
|
slots: undefined,
|
|
42
43
|
children: [{
|
|
43
44
|
brick: "eo-micro-view",
|
|
@@ -48,15 +49,16 @@ export function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHost
|
|
|
48
49
|
},
|
|
49
50
|
children: [formConf]
|
|
50
51
|
}]
|
|
51
|
-
}
|
|
52
|
+
};
|
|
52
53
|
}
|
|
53
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
...hostBrickConf,
|
|
54
56
|
slots: undefined,
|
|
55
57
|
children: [formConf]
|
|
56
|
-
}
|
|
58
|
+
};
|
|
57
59
|
}
|
|
58
60
|
function formSchemaToBrick(schema, fields, formStateStoreId) {
|
|
59
|
-
|
|
61
|
+
const {
|
|
60
62
|
id,
|
|
61
63
|
bricks,
|
|
62
64
|
events,
|
|
@@ -64,21 +66,24 @@ function formSchemaToBrick(schema, fields, formStateStoreId) {
|
|
|
64
66
|
mountPoint,
|
|
65
67
|
instanceId: iid
|
|
66
68
|
} = schema;
|
|
67
|
-
|
|
69
|
+
let {
|
|
68
70
|
brick,
|
|
69
71
|
properties
|
|
70
72
|
} = schema;
|
|
71
73
|
|
|
72
74
|
// 根据字段类型获取默认配置
|
|
73
|
-
|
|
75
|
+
const field = fields.find(item => item.fieldId === id);
|
|
74
76
|
if (field) {
|
|
75
|
-
|
|
77
|
+
const defaults = getDefaultProperties(field);
|
|
76
78
|
if (!brick) {
|
|
77
79
|
brick = defaults.brick;
|
|
78
80
|
}
|
|
79
|
-
properties =
|
|
81
|
+
properties = {
|
|
82
|
+
...defaults.properties,
|
|
83
|
+
...properties
|
|
84
|
+
};
|
|
80
85
|
}
|
|
81
|
-
|
|
86
|
+
const brickConf = {
|
|
82
87
|
brick,
|
|
83
88
|
properties,
|
|
84
89
|
iid,
|
|
@@ -99,8 +104,8 @@ function formSchemasToBricks(schemas, fields, formStateStoreId) {
|
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
function mergeEvents(targetEvents, sourceEvents) {
|
|
102
|
-
|
|
103
|
-
for (
|
|
107
|
+
const events = targetEvents ?? {};
|
|
108
|
+
for (const [eventType, handlers] of Object.entries(sourceEvents)) {
|
|
104
109
|
events[eventType] = hasOwnProperty(events, eventType) ? [events[eventType], handlers].flat() : handlers;
|
|
105
110
|
}
|
|
106
111
|
return events;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandFormRenderer.js","names":["hasOwnProperty","uniqueId","DataStore","getDefaultProperties","symbolForFormStateStoreId","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","
|
|
1
|
+
{"version":3,"file":"expandFormRenderer.js","names":["hasOwnProperty","uniqueId","DataStore","getDefaultProperties","symbolForFormStateStoreId","formContainers","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostPropertyEntries","rendererContext","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","runtimeContext","forEachItem","forEachIndex","tplStateStoreId","formStateStore","undefined","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","includes","brick","events","mergeEvents","renderRoot","properties","slots","children","style","padding","schema","id","bricks","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","brickConf","slot","formSchemasToBricks","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncPropertyEntry, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\nimport type { RendererContext } from \"../RendererContext.js\";\n\nconst formContainers = [\"forms.general-form\", \"form.general-form\", \"eo-form\"];\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostPropertyEntries: AsyncPropertyEntry[],\n rendererContext: RendererContext\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.forEachIndex;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\n \"FORM_STATE\",\n undefined,\n rendererContext,\n 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,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,QAAQ,QAAQ,QAAQ;AACjC,SAASC,SAAS,QAAQ,sBAAsB;AAOhD,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,yBAAyB,QAAQ,gBAAgB;AAG1D,MAAMC,cAAc,GAAG,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,SAAS,CAAC;AAE7E,OAAO,SAASC,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,wBAA8C,EAC9CC,eAAgC,EACrB;EAAA,IAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAON,QAAQ,KAAK,QAAQ,GAAGO,IAAI,CAACC,KAAK,CAACR,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMS,gBAAgB,GAAGf,QAAQ,CAAC,aAAa,CAAC;EAChD,MAAMgB,cAAc,GAAG;IACrB,GAAGR,SAAS,CAACQ,cAAc;IAC3BD;EACF,CAAC;;EAED;EACA,OAAOC,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,YAAY;EAClC,OAAOF,cAAc,CAACG,eAAe;EAErC,MAAMC,cAAc,GAAG,IAAInB,SAAS,CAClC,YAAY,EACZoB,SAAS,EACTX,eAAe,EACfK,gBACF,CAAC;EACDC,cAAc,CAACM,iBAAiB,CAACC,GAAG,CAACR,gBAAgB,EAAEK,cAAc,CAAC;EACtE,IAAIJ,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ACa,MAAM,EAAEX,MAAM,EAAEnB,gBAAgB,CACpD,CAAC;EACH;AACF;AAEA,SAASuB,WAAWA,CAClB0B,YAAwC,EACxCC,YAA4B,EACZ;EAChB,MAAM5B,MAAM,GAAG2B,YAAY,IAAI,CAAC,CAAC;EAEjC,KAAK,MAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChE5B,MAAM,CAAC6B,SAAS,CAAC,GAAGnE,cAAc,CAACsC,MAAM,EAAE6B,SAAS,CAAC,GACjD,CAAC7B,MAAM,CAAC6B,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,CAAC,CAAC,GACpCH,QAAQ;EACd;EAEA,OAAO9B,MAAM;AACf","ignoreList":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
1
|
export function getDefaultProperties(field) {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
let defaultValue;
|
|
3
|
+
const commonProps = {
|
|
5
4
|
id: field.fieldId,
|
|
6
5
|
name: field.fieldId,
|
|
7
6
|
label: field.name,
|
|
@@ -9,7 +8,7 @@ export function getDefaultProperties(field) {
|
|
|
9
8
|
testid: field.fieldId
|
|
10
9
|
}
|
|
11
10
|
};
|
|
12
|
-
|
|
11
|
+
const getReadOnlyAndRequired = () => {
|
|
13
12
|
var _field$limit, _field$limit2;
|
|
14
13
|
return {
|
|
15
14
|
readOnly: (_field$limit = field.limit) === null || _field$limit === void 0 ? void 0 : _field$limit.includes("READONLY"),
|
|
@@ -20,36 +19,45 @@ export function getDefaultProperties(field) {
|
|
|
20
19
|
case "INT":
|
|
21
20
|
defaultValue = {
|
|
22
21
|
brick: "forms.general-input-number",
|
|
23
|
-
properties:
|
|
22
|
+
properties: {
|
|
23
|
+
...commonProps,
|
|
24
|
+
...getReadOnlyAndRequired(),
|
|
24
25
|
placeholder: field.description,
|
|
25
26
|
precision: 0,
|
|
26
27
|
inputBoxStyle: {
|
|
27
28
|
width: "100%"
|
|
28
29
|
}
|
|
29
|
-
}
|
|
30
|
+
}
|
|
30
31
|
};
|
|
31
32
|
break;
|
|
32
33
|
case "BOOLEAN":
|
|
33
34
|
defaultValue = {
|
|
34
35
|
brick: "forms.general-switch",
|
|
35
|
-
properties:
|
|
36
|
+
properties: {
|
|
37
|
+
...commonProps,
|
|
38
|
+
...getReadOnlyAndRequired()
|
|
39
|
+
}
|
|
36
40
|
};
|
|
37
41
|
break;
|
|
38
42
|
case "FLOAT":
|
|
39
43
|
defaultValue = {
|
|
40
44
|
brick: "forms.general-input-number",
|
|
41
|
-
properties:
|
|
45
|
+
properties: {
|
|
46
|
+
...commonProps,
|
|
47
|
+
...getReadOnlyAndRequired(),
|
|
42
48
|
placeholder: field.description,
|
|
43
49
|
inputBoxStyle: {
|
|
44
50
|
width: "100%"
|
|
45
51
|
}
|
|
46
|
-
}
|
|
52
|
+
}
|
|
47
53
|
};
|
|
48
54
|
break;
|
|
49
55
|
case "ENUM":
|
|
50
56
|
defaultValue = {
|
|
51
57
|
brick: "forms.general-select",
|
|
52
|
-
properties:
|
|
58
|
+
properties: {
|
|
59
|
+
...commonProps,
|
|
60
|
+
...getReadOnlyAndRequired(),
|
|
53
61
|
options: [{
|
|
54
62
|
label: "选项一",
|
|
55
63
|
value: 1
|
|
@@ -61,13 +69,15 @@ export function getDefaultProperties(field) {
|
|
|
61
69
|
inputBoxStyle: {
|
|
62
70
|
width: "100%"
|
|
63
71
|
}
|
|
64
|
-
}
|
|
72
|
+
}
|
|
65
73
|
};
|
|
66
74
|
break;
|
|
67
75
|
case "ENUMS":
|
|
68
76
|
defaultValue = {
|
|
69
77
|
brick: "forms.general-select",
|
|
70
|
-
properties:
|
|
78
|
+
properties: {
|
|
79
|
+
...commonProps,
|
|
80
|
+
...getReadOnlyAndRequired(),
|
|
71
81
|
mode: "multiple",
|
|
72
82
|
options: [{
|
|
73
83
|
label: "选项一",
|
|
@@ -80,55 +90,68 @@ export function getDefaultProperties(field) {
|
|
|
80
90
|
inputBoxStyle: {
|
|
81
91
|
width: "100%"
|
|
82
92
|
}
|
|
83
|
-
}
|
|
93
|
+
}
|
|
84
94
|
};
|
|
85
95
|
break;
|
|
86
96
|
case "DATE":
|
|
87
97
|
case "TIME":
|
|
88
98
|
defaultValue = {
|
|
89
99
|
brick: "forms.general-date-picker",
|
|
90
|
-
properties:
|
|
100
|
+
properties: {
|
|
101
|
+
...commonProps,
|
|
102
|
+
...getReadOnlyAndRequired(),
|
|
91
103
|
placeholder: field.description
|
|
92
|
-
}
|
|
104
|
+
}
|
|
93
105
|
};
|
|
94
106
|
break;
|
|
95
107
|
case "IP":
|
|
96
108
|
defaultValue = {
|
|
97
109
|
brick: "forms.general-input",
|
|
98
|
-
properties:
|
|
110
|
+
properties: {
|
|
111
|
+
...commonProps,
|
|
112
|
+
...getReadOnlyAndRequired(),
|
|
99
113
|
placeholder: field.description,
|
|
100
114
|
pattern: "((^s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))s*$)|(^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*$))",
|
|
101
115
|
message: {
|
|
102
116
|
pattern: "输入字符不匹配IP格式"
|
|
103
117
|
}
|
|
104
|
-
}
|
|
118
|
+
}
|
|
105
119
|
};
|
|
106
120
|
break;
|
|
107
121
|
case "JSON":
|
|
108
122
|
defaultValue = {
|
|
109
123
|
brick: "forms.general-textarea",
|
|
110
|
-
properties:
|
|
124
|
+
properties: {
|
|
125
|
+
...commonProps
|
|
126
|
+
}
|
|
111
127
|
};
|
|
112
128
|
break;
|
|
113
129
|
case "ARRAY":
|
|
114
130
|
defaultValue = {
|
|
115
131
|
brick: "forms.general-select",
|
|
116
|
-
properties:
|
|
132
|
+
properties: {
|
|
133
|
+
...commonProps
|
|
134
|
+
}
|
|
117
135
|
};
|
|
118
136
|
break;
|
|
119
137
|
case "STRUCTURE":
|
|
120
138
|
case "STRUCTURE_ARRAY":
|
|
121
139
|
defaultValue = {
|
|
122
140
|
brick: "forms.cmdb-instance-select-panel",
|
|
123
|
-
properties:
|
|
141
|
+
properties: {
|
|
142
|
+
...commonProps,
|
|
143
|
+
...getReadOnlyAndRequired()
|
|
144
|
+
}
|
|
124
145
|
};
|
|
125
146
|
break;
|
|
126
147
|
default:
|
|
127
148
|
defaultValue = {
|
|
128
149
|
brick: "forms.general-input",
|
|
129
|
-
properties:
|
|
150
|
+
properties: {
|
|
151
|
+
...commonProps,
|
|
152
|
+
...getReadOnlyAndRequired(),
|
|
130
153
|
placeholder: field.description
|
|
131
|
-
}
|
|
154
|
+
}
|
|
132
155
|
};
|
|
133
156
|
}
|
|
134
157
|
return defaultValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultProperties.js","names":["getDefaultProperties","field","defaultValue","commonProps","id","fieldId","name","label","dataset","testid","getReadOnlyAndRequired","_field$limit","_field$limit2","readOnly","limit","includes","required","fieldType","brick","properties","
|
|
1
|
+
{"version":3,"file":"getDefaultProperties.js","names":["getDefaultProperties","field","defaultValue","commonProps","id","fieldId","name","label","dataset","testid","getReadOnlyAndRequired","_field$limit","_field$limit2","readOnly","limit","includes","required","fieldType","brick","properties","placeholder","description","precision","inputBoxStyle","width","options","value","mode","pattern","message"],"sources":["../../../../src/internal/FormRenderer/getDefaultProperties.ts"],"sourcesContent":["import type { DefaultFieldProperties, FieldProperties } from \"./interfaces.js\";\n\nexport function getDefaultProperties(\n field: FieldProperties\n): DefaultFieldProperties {\n let defaultValue: DefaultFieldProperties;\n const commonProps = {\n id: field.fieldId,\n name: field.fieldId,\n label: field.name,\n dataset: {\n testid: field.fieldId,\n },\n };\n const getReadOnlyAndRequired = () => ({\n readOnly: field.limit?.includes(\"READONLY\"),\n required: field.limit?.includes(\"REQUIRED\"),\n });\n switch (field.fieldType) {\n case \"INT\":\n defaultValue = {\n brick: \"forms.general-input-number\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n precision: 0,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"BOOLEAN\":\n defaultValue = {\n brick: \"forms.general-switch\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n },\n };\n break;\n case \"FLOAT\":\n defaultValue = {\n brick: \"forms.general-input-number\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"ENUM\":\n defaultValue = {\n brick: \"forms.general-select\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n options: [\n { label: \"选项一\", value: 1 },\n { label: \"选项二\", value: 2 },\n ],\n placeholder: field.description,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"ENUMS\":\n defaultValue = {\n brick: \"forms.general-select\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n mode: \"multiple\",\n options: [\n { label: \"选项一\", value: 1 },\n { label: \"选项二\", value: 2 },\n ],\n placeholder: field.description,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"DATE\":\n case \"TIME\":\n defaultValue = {\n brick: \"forms.general-date-picker\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n },\n };\n break;\n case \"IP\":\n defaultValue = {\n brick: \"forms.general-input\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n pattern:\n \"((^s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))s*$)|(^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*$))\",\n message: {\n pattern: \"输入字符不匹配IP格式\",\n },\n },\n };\n break;\n case \"JSON\":\n defaultValue = {\n brick: \"forms.general-textarea\",\n properties: {\n ...commonProps,\n },\n };\n break;\n case \"ARRAY\":\n defaultValue = {\n brick: \"forms.general-select\",\n properties: {\n ...commonProps,\n },\n };\n break;\n case \"STRUCTURE\":\n case \"STRUCTURE_ARRAY\":\n defaultValue = {\n brick: \"forms.cmdb-instance-select-panel\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n },\n };\n break;\n default:\n defaultValue = {\n brick: \"forms.general-input\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n },\n };\n }\n return defaultValue;\n}\n"],"mappings":"AAEA,OAAO,SAASA,oBAAoBA,CAClCC,KAAsB,EACE;EACxB,IAAIC,YAAoC;EACxC,MAAMC,WAAW,GAAG;IAClBC,EAAE,EAAEH,KAAK,CAACI,OAAO;IACjBC,IAAI,EAAEL,KAAK,CAACI,OAAO;IACnBE,KAAK,EAAEN,KAAK,CAACK,IAAI;IACjBE,OAAO,EAAE;MACPC,MAAM,EAAER,KAAK,CAACI;IAChB;EACF,CAAC;EACD,MAAMK,sBAAsB,GAAGA,CAAA;IAAA,IAAAC,YAAA,EAAAC,aAAA;IAAA,OAAO;MACpCC,QAAQ,GAAAF,YAAA,GAAEV,KAAK,CAACa,KAAK,cAAAH,YAAA,uBAAXA,YAAA,CAAaI,QAAQ,CAAC,UAAU,CAAC;MAC3CC,QAAQ,GAAAJ,aAAA,GAAEX,KAAK,CAACa,KAAK,cAAAF,aAAA,uBAAXA,aAAA,CAAaG,QAAQ,CAAC,UAAU;IAC5C,CAAC;EAAA,CAAC;EACF,QAAQd,KAAK,CAACgB,SAAS;IACrB,KAAK,KAAK;MACRf,YAAY,GAAG;QACbgB,KAAK,EAAE,4BAA4B;QACnCC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB,CAAC,CAAC;UAC3BU,WAAW,EAAEnB,KAAK,CAACoB,WAAW;UAC9BC,SAAS,EAAE,CAAC;UACZC,aAAa,EAAE;YAAEC,KAAK,EAAE;UAAO;QACjC;MACF,CAAC;MACD;IACF,KAAK,SAAS;MACZtB,YAAY,GAAG;QACbgB,KAAK,EAAE,sBAAsB;QAC7BC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB,CAAC;QAC5B;MACF,CAAC;MACD;IACF,KAAK,OAAO;MACVR,YAAY,GAAG;QACbgB,KAAK,EAAE,4BAA4B;QACn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