@strapi/content-manager 5.33.0 → 5.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/admin/pages/EditView/components/DocumentActions.js +8 -6
  2. package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
  3. package/dist/admin/pages/EditView/components/DocumentActions.mjs +8 -6
  4. package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
  5. package/dist/admin/pages/EditView/components/FormLayout.js +1 -23
  6. package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
  7. package/dist/admin/pages/EditView/components/FormLayout.mjs +1 -23
  8. package/dist/admin/pages/EditView/components/FormLayout.mjs.map +1 -1
  9. package/dist/admin/pages/EditView/components/InputRenderer.js +35 -3
  10. package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
  11. package/dist/admin/pages/EditView/components/InputRenderer.mjs +39 -7
  12. package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
  13. package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +9 -1
  14. package/dist/admin/utils/validation.js +2 -1
  15. package/dist/admin/utils/validation.js.map +1 -1
  16. package/dist/admin/utils/validation.mjs +2 -1
  17. package/dist/admin/utils/validation.mjs.map +1 -1
  18. package/dist/server/preview/controllers/preview.js +1 -1
  19. package/dist/server/preview/controllers/preview.js.map +1 -1
  20. package/dist/server/preview/controllers/preview.mjs +1 -1
  21. package/dist/server/preview/controllers/preview.mjs.map +1 -1
  22. package/dist/server/preview/services/preview-config.js.map +1 -1
  23. package/dist/server/preview/services/preview-config.mjs.map +1 -1
  24. package/dist/server/src/preview/services/index.d.ts +2 -2
  25. package/dist/server/src/preview/services/preview-config.d.ts +7 -9
  26. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -1
  27. package/dist/server/src/preview/services/preview.d.ts +1 -1
  28. package/dist/server/src/preview/utils.d.ts +2 -2
  29. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"FormLayout.mjs","sources":["../../../../../admin/src/pages/EditView/components/FormLayout.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { useForm, createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { Box, BoxProps, Flex, Grid } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { styled } from 'styled-components';\n\nimport { EditLayout } from '../../../hooks/useDocumentLayout';\n\nimport { InputRenderer } from './InputRenderer';\n\nimport type { UseDocument } from '../../../hooks/useDocument';\n\nexport const ResponsiveGridRoot = styled(Grid.Root)`\n container-type: inline-size;\n`;\n\nexport const ResponsiveGridItem =\n /**\n * TODO:\n * JSDOM cannot handle container queries.\n * This is a temporary workaround so that tests do not fail in the CI when jestdom throws an error\n * for failing to parse the stylesheet.\n */\n process.env.NODE_ENV !== 'test'\n ? styled(Grid.Item)<{ col: number }>`\n grid-column: span 12;\n ${({ theme }) => theme.breakpoints.medium} {\n ${({ col }) => col && `grid-column: span ${col};`}\n }\n `\n : styled(Grid.Item)<{ col: number }>`\n grid-column: span 12;\n `;\n\nconst panelStyles = {\n padding: {\n initial: 4,\n medium: 6,\n },\n borderColor: 'neutral150',\n background: 'neutral0',\n hasRadius: true,\n shadow: 'tableShadow',\n} satisfies BoxProps;\n\ninterface FormLayoutProps extends Pick<EditLayout, 'layout'> {\n hasBackground?: boolean;\n document: ReturnType<UseDocument>;\n}\n\nconst FormLayout = ({ layout, document, hasBackground = true }: FormLayoutProps) => {\n const { formatMessage } = useIntl();\n const modelUid = document.schema?.uid;\n const fieldValues = useForm('Fields', (state) => state.values);\n const rulesEngine = createRulesEngine();\n\n const getLabel = (name: string, label: string) => {\n return formatMessage({\n id: `content-manager.content-types.${modelUid}.${name}`,\n defaultMessage: label,\n });\n };\n\n return (\n <Flex\n direction=\"column\"\n alignItems=\"stretch\"\n gap={{\n initial: 4,\n large: 6,\n }}\n >\n {layout.map((panel, index) => {\n if (panel.some((row) => row.some((field) => field.type === 'dynamiczone'))) {\n const [row] = panel;\n const [field] = row;\n const attribute = document.schema?.attributes[field.name];\n const condition = attribute?.conditions?.visible;\n\n if (condition) {\n const isVisible = rulesEngine.evaluate(condition, fieldValues);\n if (!isVisible) {\n return null; // Skip rendering the dynamic zone if the condition is not met\n }\n }\n\n return (\n <Grid.Root key={field.name} gap={4}>\n <Grid.Item col={12} s={12} xs={12} direction=\"column\" alignItems=\"stretch\">\n <InputRenderer\n {...field}\n label={getLabel(field.name, field.label)}\n document={document}\n />\n </Grid.Item>\n </Grid.Root>\n );\n }\n\n return (\n <Box key={index} {...(hasBackground && panelStyles)}>\n <Flex\n direction=\"column\"\n alignItems=\"stretch\"\n gap={{\n initial: 4,\n large: 6,\n }}\n >\n {panel.map((row, gridRowIndex) => {\n const visibleFields = row.filter(({ name }) => {\n const attribute = document.schema?.attributes[name];\n const condition = attribute?.conditions?.visible;\n\n if (condition) {\n return rulesEngine.evaluate(condition, fieldValues);\n }\n\n return true;\n });\n\n if (visibleFields.length === 0) {\n return null; // Skip rendering the entire grid row\n }\n\n return (\n <ResponsiveGridRoot key={gridRowIndex} gap={4}>\n {visibleFields.map(({ size, ...field }) => {\n return (\n <ResponsiveGridItem\n col={size}\n key={field.name}\n s={12}\n xs={12}\n direction=\"column\"\n alignItems=\"stretch\"\n >\n <InputRenderer\n {...field}\n label={getLabel(field.name, field.label)}\n document={document}\n />\n </ResponsiveGridItem>\n );\n })}\n </ResponsiveGridRoot>\n );\n })}\n </Flex>\n </Box>\n );\n })}\n </Flex>\n );\n};\n\nexport { FormLayout, FormLayoutProps };\n"],"names":["ResponsiveGridRoot","styled","Grid","Root","ResponsiveGridItem","process","env","NODE_ENV","Item","theme","breakpoints","medium","col","panelStyles","padding","initial","borderColor","background","hasRadius","shadow","FormLayout","layout","document","hasBackground","formatMessage","useIntl","modelUid","schema","uid","fieldValues","useForm","state","values","rulesEngine","createRulesEngine","getLabel","name","label","id","defaultMessage","_jsx","Flex","direction","alignItems","gap","large","map","panel","index","some","row","field","type","attribute","attributes","condition","conditions","visible","isVisible","evaluate","s","xs","InputRenderer","Box","gridRowIndex","visibleFields","filter","length","size"],"mappings":";;;;;;;;MAaaA,kBAAqBC,GAAAA,MAAAA,CAAOC,IAAKC,CAAAA,IAAI,CAAC;;AAEnD;MAEaC,kBACX;;;;;MAMAC,OAAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,SACrBN,MAAOC,CAAAA,IAAAA,CAAKM,IAAI,CAAkB;;QAEhC,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,WAAW,CAACC,MAAM,CAAC;AACxC,UAAA,EAAE,CAAC,EAAEC,GAAG,EAAE,GAAKA,GAAAA,IAAO,CAAC,kBAAkB,EAAEA,GAAAA,CAAI,CAAC,CAAC;;AAErD,MAAA,CAAC,GACDX,MAAAA,CAAOC,IAAKM,CAAAA,IAAI,CAAkB;;AAElC,MAAA;AAEN,MAAMK,WAAc,GAAA;IAClBC,OAAS,EAAA;QACPC,OAAS,EAAA,CAAA;QACTJ,MAAQ,EAAA;AACV,KAAA;IACAK,WAAa,EAAA,YAAA;IACbC,UAAY,EAAA,UAAA;IACZC,SAAW,EAAA,IAAA;IACXC,MAAQ,EAAA;AACV,CAAA;AAOMC,MAAAA,UAAAA,GAAa,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,aAAgB,GAAA,IAAI,EAAmB,GAAA;IAC7E,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,MAAMC,QAAAA,GAAWJ,QAASK,CAAAA,MAAM,EAAEC,GAAAA;AAClC,IAAA,MAAMC,cAAcC,OAAQ,CAAA,QAAA,EAAU,CAACC,KAAAA,GAAUA,MAAMC,MAAM,CAAA;AAC7D,IAAA,MAAMC,WAAcC,GAAAA,iBAAAA,EAAAA;IAEpB,MAAMC,QAAAA,GAAW,CAACC,IAAcC,EAAAA,KAAAA,GAAAA;AAC9B,QAAA,OAAOb,aAAc,CAAA;AACnBc,YAAAA,E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AA,qBACEX,GAACpC,CAAAA,kBAAAA,EAAAA;oCACCQ,GAAKwD,EAAAA,IAAAA;oCAELR,CAAG,EAAA,EAAA;oCACHC,EAAI,EAAA,EAAA;oCACJnB,SAAU,EAAA,QAAA;oCACVC,UAAW,EAAA,SAAA;AAEX,oCAAA,QAAA,gBAAAH,GAACsB,CAAAA,qBAAAA,EAAAA;AACE,wCAAA,GAAGX,KAAK;AACTd,wCAAAA,KAAAA,EAAOF,QAASgB,CAAAA,KAAAA,CAAMf,IAAI,EAAEe,MAAMd,KAAK,CAAA;wCACvCf,QAAUA,EAAAA;;AATP6B,iCAAAA,EAAAA,KAAAA,CAAMf,IAAI,CAAA;AAarB,6BAAA;AAlBuB4B,yBAAAA,EAAAA,YAAAA,CAAAA;AAqB7B,qBAAA;;AA/CMhB,aAAAA,EAAAA,KAAAA,CAAAA;AAmDd,SAAA;;AAGN;;;;"}
1
+ {"version":3,"file":"FormLayout.mjs","sources":["../../../../../admin/src/pages/EditView/components/FormLayout.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, BoxProps, Flex, Grid } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { styled } from 'styled-components';\n\nimport { EditLayout } from '../../../hooks/useDocumentLayout';\n\nimport { InputRenderer } from './InputRenderer';\n\nimport type { UseDocument } from '../../../hooks/useDocument';\n\nexport const ResponsiveGridRoot = styled(Grid.Root)`\n container-type: inline-size;\n`;\n\nexport const ResponsiveGridItem =\n /**\n * TODO:\n * JSDOM cannot handle container queries.\n * This is a temporary workaround so that tests do not fail in the CI when jestdom throws an error\n * for failing to parse the stylesheet.\n */\n process.env.NODE_ENV !== 'test'\n ? styled(Grid.Item)<{ col: number }>`\n grid-column: span 12;\n ${({ theme }) => theme.breakpoints.medium} {\n ${({ col }) => col && `grid-column: span ${col};`}\n }\n `\n : styled(Grid.Item)<{ col: number }>`\n grid-column: span 12;\n `;\n\nconst panelStyles = {\n padding: {\n initial: 4,\n medium: 6,\n },\n borderColor: 'neutral150',\n background: 'neutral0',\n hasRadius: true,\n shadow: 'tableShadow',\n} satisfies BoxProps;\n\ninterface FormLayoutProps extends Pick<EditLayout, 'layout'> {\n hasBackground?: boolean;\n document: ReturnType<UseDocument>;\n}\n\nconst FormLayout = ({ layout, document, hasBackground = true }: FormLayoutProps) => {\n const { formatMessage } = useIntl();\n const modelUid = document.schema?.uid;\n\n const getLabel = (name: string, label: string) => {\n return formatMessage({\n id: `content-manager.content-types.${modelUid}.${name}`,\n defaultMessage: label,\n });\n };\n\n return (\n <Flex\n direction=\"column\"\n alignItems=\"stretch\"\n gap={{\n initial: 4,\n large: 6,\n }}\n >\n {layout.map((panel, index) => {\n if (panel.some((row) => row.some((field) => field.type === 'dynamiczone'))) {\n const [row] = panel;\n const [field] = row;\n\n return (\n <Grid.Root key={field.name} gap={4}>\n <Grid.Item col={12} s={12} xs={12} direction=\"column\" alignItems=\"stretch\">\n <InputRenderer\n {...field}\n label={getLabel(field.name, field.label)}\n document={document}\n />\n </Grid.Item>\n </Grid.Root>\n );\n }\n\n return (\n <Box key={index} {...(hasBackground && panelStyles)}>\n <Flex\n direction=\"column\"\n alignItems=\"stretch\"\n gap={{\n initial: 4,\n large: 6,\n }}\n >\n {panel.map((row, gridRowIndex) => {\n return (\n <ResponsiveGridRoot key={gridRowIndex} gap={4}>\n {row.map(({ size, ...field }) => {\n return (\n <ResponsiveGridItem\n col={size}\n key={field.name}\n s={12}\n xs={12}\n direction=\"column\"\n alignItems=\"stretch\"\n >\n <InputRenderer\n {...field}\n label={getLabel(field.name, field.label)}\n document={document}\n />\n </ResponsiveGridItem>\n );\n })}\n </ResponsiveGridRoot>\n );\n })}\n </Flex>\n </Box>\n );\n })}\n </Flex>\n );\n};\n\nexport { FormLayout, FormLayoutProps };\n"],"names":["ResponsiveGridRoot","styled","Grid","Root","ResponsiveGridItem","process","env","NODE_ENV","Item","theme","breakpoints","medium","col","panelStyles","padding","initial","borderColor","background","hasRadius","shadow","FormLayout","layout","document","hasBackground","formatMessage","useIntl","modelUid","schema","uid","getLabel","name","label","id","defaultMessage","_jsx","Flex","direction","alignItems","gap","large","map","panel","index","some","row","field","type","s","xs","InputRenderer","Box","gridRowIndex","size"],"mappings":";;;;;;;MAYaA,kBAAqBC,GAAAA,MAAAA,CAAOC,IAAKC,CAAAA,IAAI,CAAC;;AAEnD;MAEaC,kBACX;;;;;MAMAC,OAAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,SACrBN,MAAOC,CAAAA,IAAAA,CAAKM,IAAI,CAAkB;;QAEhC,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,WAAW,CAACC,MAAM,CAAC;AACxC,UAAA,EAAE,CAAC,EAAEC,GAAG,EAAE,GAAKA,GAAAA,IAAO,CAAC,kBAAkB,EAAEA,GAAAA,CAAI,CAAC,CAAC;;AAErD,MAAA,CAAC,GACDX,MAAAA,CAAOC,IAAKM,CAAAA,IAAI,CAAkB;;AAElC,MAAA;AAEN,MAAMK,WAAc,GAAA;IAClBC,OAAS,EAAA;QACPC,OAAS,EAAA,CAAA;QACTJ,MAAQ,EAAA;AACV,KAAA;IACAK,WAAa,EAAA,YAAA;IACbC,UAAY,EAAA,UAAA;IACZC,SAAW,EAAA,IAAA;IACXC,MAAQ,EAAA;AACV,CAAA;AAOMC,MAAAA,UAAAA,GAAa,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,aAAgB,GAAA,IAAI,EAAmB,GAAA;IAC7E,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,MAAMC,QAAAA,GAAWJ,QAASK,CAAAA,MAAM,EAAEC,GAAAA;IAElC,MAAMC,QAAAA,GAAW,CAACC,IAAcC,EAAAA,KAAAA,GAAAA;AAC9B,QAAA,OAAOP,aAAc,CAAA;AACnBQ,YAAAA,EAAAA,EAAI,CAAC,8BAA8B,EAAEN,QAAS,CAAA,CAAC,EAAEI,IAAM,CAAA,CAAA;YACvDG,cAAgBF,E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AA;wBACHvB,OAAS,EAAA,CAAA;wBACTwB,KAAO,EAAA;AACT,qBAAA;8BAECE,KAAMD,CAAAA,GAAG,CAAC,CAACI,GAAKO,EAAAA,YAAAA,GAAAA;AACf,wBAAA,qBACEjB,GAAClC,CAAAA,kBAAAA,EAAAA;4BAAsCsC,GAAK,EAAA,CAAA;AACzCM,4BAAAA,QAAAA,EAAAA,GAAAA,CAAIJ,GAAG,CAAC,CAAC,EAAEY,IAAI,EAAE,GAAGP,KAAO,EAAA,GAAA;AAC1B,gCAAA,qBACEX,GAAC9B,CAAAA,kBAAAA,EAAAA;oCACCQ,GAAKwC,EAAAA,IAAAA;oCAELL,CAAG,EAAA,EAAA;oCACHC,EAAI,EAAA,EAAA;oCACJZ,SAAU,EAAA,QAAA;oCACVC,UAAW,EAAA,SAAA;AAEX,oCAAA,QAAA,gBAAAH,GAACe,CAAAA,qBAAAA,EAAAA;AACE,wCAAA,GAAGJ,KAAK;AACTd,wCAAAA,KAAAA,EAAOF,QAASgB,CAAAA,KAAAA,CAAMf,IAAI,EAAEe,MAAMd,KAAK,CAAA;wCACvCT,QAAUA,EAAAA;;AATPuB,iCAAAA,EAAAA,KAAAA,CAAMf,IAAI,CAAA;AAarB,6BAAA;AAlBuBqB,yBAAAA,EAAAA,YAAAA,CAAAA;AAqB7B,qBAAA;;AAhCMT,aAAAA,EAAAA,KAAAA,CAAAA;AAoCd,SAAA;;AAGN;;;;"}
@@ -45,7 +45,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
45
45
  * specifically to be used in the EditView of the content-manager this understands
46
46
  * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific
47
47
  * components such as Blocks / Relations.
48
- */ const InputRenderer = ({ visible, hint: providedHint, document, ...inputProps })=>{
48
+ */ const BaseInputRenderer = ({ visible, hint: providedHint, document, ...inputProps })=>{
49
49
  const localeKey = document?.document?.locale || 'default';
50
50
  const { currentDocumentMeta } = useDocumentContext.useDocumentContext('DynamicComponent');
51
51
  const { edit: { components } } = useDocumentLayout.useDocumentLayout(currentDocumentMeta.model);
@@ -146,7 +146,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
146
146
  hint: hint,
147
147
  layout: components[props.attribute.component].layout,
148
148
  disabled: fieldIsDisabled,
149
- children: (componentInputProps)=>/*#__PURE__*/ jsxRuntime.jsx(InputRenderer, {
149
+ children: (componentInputProps)=>/*#__PURE__*/ jsxRuntime.jsx(BaseInputRenderer, {
150
150
  ...componentInputProps
151
151
  }, `input-${componentInputProps.name}-${localeKey}`)
152
152
  }, `input-${props.name}-${localeKey}`);
@@ -205,6 +205,20 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
205
205
  }, `input-${props.name}-${localeKey}`);
206
206
  }
207
207
  };
208
+ const rulesEngine = strapiAdmin.createRulesEngine();
209
+ /**
210
+ * A wrapper around BaseInputRenderer that conditionally renders it depending on the attribute's condition.
211
+ */ const ConditionAwareInputRenderer = ({ condition, ...props })=>{
212
+ // Note: this selector causes a re-render every time any form value on the page changes
213
+ const fieldValues = strapiAdmin.useForm('ConditionalInputRenderer', (state)=>state.values);
214
+ const isVisible = rulesEngine.evaluate(condition, fieldValues);
215
+ if (!isVisible) {
216
+ return null;
217
+ }
218
+ return /*#__PURE__*/ jsxRuntime.jsx(BaseInputRenderer, {
219
+ ...props
220
+ });
221
+ };
208
222
  const attributeHasCustomFieldProperty = (attribute)=>'customField' in attribute && typeof attribute.customField === 'string';
209
223
  const useFieldHint = (hint = undefined, attribute)=>{
210
224
  const { formatMessage } = reactIntl.useIntl();
@@ -259,7 +273,25 @@ const getMinMax = (attribute)=>{
259
273
  };
260
274
  }
261
275
  };
262
- const MemoizedInputRenderer = /*#__PURE__*/ React__namespace.memo(InputRenderer);
276
+ /**
277
+ * Conditionally routes the exported InputRender component towards ConditionalInputRenderer
278
+ * (when there's a JSON logic condition on the attribute, or BaseInputRenderer otherwise.
279
+ * We do this because rendering a conditional field requires access to the values of
280
+ * other form fields, which causes many re-renders and performance issues on complex content
281
+ * types. By splitting the component into two, we isolate the performance issue to
282
+ * conditional fields only, not all edit view fields.
283
+ */ const MemoizedInputRenderer = /*#__PURE__*/ React__namespace.memo((props)=>{
284
+ const condition = props.attribute.conditions?.visible;
285
+ if (condition) {
286
+ return /*#__PURE__*/ jsxRuntime.jsx(ConditionAwareInputRenderer, {
287
+ ...props,
288
+ condition: condition
289
+ });
290
+ }
291
+ return /*#__PURE__*/ jsxRuntime.jsx(BaseInputRenderer, {
292
+ ...props
293
+ });
294
+ });
263
295
 
264
296
  exports.InputRenderer = MemoizedInputRenderer;
265
297
  exports.useFieldHint = useFieldHint;
@@ -1 +1 @@
1
- {"version":3,"file":"InputRenderer.js","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\nimport { useHasInputPopoverParent } from '../../../preview/components/InputPopover';\nimport { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst InputRenderer = ({\n visible,\n hint: providedHint,\n document,\n ...inputProps\n}: InputRendererProps) => {\n const localeKey = document?.document?.locale || 'default';\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n const isInPreviewPopover = useHasInputPopoverParent();\n const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n // Everything preview related\n const previewProps = usePreviewInputManager(inputProps.name, inputProps.attribute);\n const props = { ...inputProps, ...previewProps };\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !shouldIgnorePermissions) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !shouldIgnorePermissions) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n return (\n <CustomInput\n {...props}\n {...field}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n return (\n <CustomInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return (\n <BlocksInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'component':\n return (\n <ComponentInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(componentInputProps) => (\n <InputRenderer\n key={`input-${componentInputProps.name}-${localeKey}`}\n {...componentInputProps}\n />\n )}\n </ComponentInput>\n );\n case 'dynamiczone':\n return (\n <DynamicZone\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'relation':\n return (\n <RelationsInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'richtext':\n return (\n <Wysiwyg\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'uid':\n // These props are not needed for the generic form input renderer.\n const { unique: _uniqueUID, ...restUIDProps } = props;\n return (\n <UIDInput\n key={`input-${props.name}-${localeKey}`}\n {...restUIDProps}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...restProps}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = ['string', 'uid', 'richtext', 'email', 'password', 'text'].includes(attribute.type)\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\nconst MemoizedInputRenderer = React.memo(InputRenderer);\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["InputRenderer","visible","hint","providedHint","document","inputProps","localeKey","locale","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isInPreviewPopover","useHasInputPopoverParent","shouldIgnorePermissions","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","previewProps","usePreviewInputManager","name","attribute","props","canUserReadField","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","componentInputProps","DynamicZone","RelationsInput","Wysiwyg","unique","_uniqueUID","restUIDProps","UIDInput","options","enum","map","value","_unique","mainField","_mainField","restProps","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;AAOC,IACD,MAAMA,aAAAA,GAAgB,CAAC,EACrBC,OAAO,EACPC,IAAMC,EAAAA,YAAY,EAClBC,QAAQ,EACR,GAAGC,UACgB,EAAA,GAAA;IACnB,MAAMC,SAAAA,GAAYF,QAAUA,EAAAA,QAAAA,EAAUG,MAAU,IAAA,SAAA;AAChD,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAAGC,qCAAmB,CAAA,kBAAA,CAAA;IACnD,MAAM,EACJC,MAAM,EAAEC,UAAU,EAAE,EACrB,GAAGC,mCAAkBJ,CAAAA,mBAAAA,CAAoBK,KAAK,CAAA;AAE/C,IAAA,MAAMC,iBACJV,QAASW,CAAAA,MAAM,EAAEC,IAAAA,KAAS,mBAAmB,kBAAqB,GAAA,cAAA;AAEpE,IAAA,MAAMC,kBAAkBC,oBAAe,CAAA,iBAAA,EAAmB,CAACC,KAAAA,GAAUA,MAAMF,eAAe,CAAA;AAC1F,IAAA,MAAMG,kBAAqBC,GAAAA,qCAAAA,EAAAA;AAC3B,IAAA,MAAMC,0BAA0BL,eAAmBG,IAAAA,kBAAAA;AAEnD,IAA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C,CAAAA,IAAAA,EAAAA,EAAAA;AACP,KAAA,CAAA;AAEJ;AAEA,MAAMZ,YAAY,CAACjD,SAAAA,GAAAA;IACjB,IAAI,KAAA,IAASA,SAAa,IAAA,KAAA,IAASA,SAAW,EAAA;QAC5C,OAAO;YACL+C,OAAS,EAAA,CAACe,MAAOC,CAAAA,KAAK,CAACD,MAAAA,CAAO9D,SAAUuD,CAAAA,GAAG,CAAKO,CAAAA,GAAAA,MAAAA,CAAO9D,SAAUuD,CAAAA,GAAG,CAAI3C,GAAAA,SAAAA;YACxEoC,OAAS,EAAA,CAACc,MAAOC,CAAAA,KAAK,CAACD,MAAAA,CAAO9D,SAAUyD,CAAAA,GAAG,CAAKK,CAAAA,GAAAA,MAAAA,CAAO9D,SAAUyD,CAAAA,GAAG,CAAI7C,GAAAA;AAC1E,SAAA;AACF,KAAA,MAAO,IAAI,WAAA,IAAeZ,SAAa,IAAA,WAAA,IAAeA,SAAW,EAAA;QAC/D,OAAO;AAAE+C,YAAAA,OAAAA,EAAS/C,UAAUgE,SAAS;AAAEhB,YAAAA,OAAAA,EAAShD,UAAUiE;AAAU,SAAA;KAC/D,MAAA;QACL,OAAO;YAAElB,OAASnC,EAAAA,SAAAA;YAAWoC,OAASpC,EAAAA;AAAU,SAAA;AAClD;AACF,CAAA;AAEMsD,MAAAA,qBAAAA,iBAAwBC,gBAAMC,CAAAA,IAAI,CAAC5G,aAAAA;;;;;"}
1
+ {"version":3,"file":"InputRenderer.js","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n createRulesEngine,\n type JsonLogicCondition,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\nimport { useHasInputPopoverParent } from '../../../preview/components/InputPopover';\nimport { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst BaseInputRenderer = ({\n visible,\n hint: providedHint,\n document,\n ...inputProps\n}: InputRendererProps) => {\n const localeKey = document?.document?.locale || 'default';\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n const isInPreviewPopover = useHasInputPopoverParent();\n const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n // Everything preview related\n const previewProps = usePreviewInputManager(inputProps.name, inputProps.attribute);\n const props = { ...inputProps, ...previewProps };\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !shouldIgnorePermissions) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !shouldIgnorePermissions) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n return (\n <CustomInput\n {...props}\n {...field}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n return (\n <CustomInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return (\n <BlocksInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'component':\n return (\n <ComponentInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(componentInputProps) => (\n <BaseInputRenderer\n key={`input-${componentInputProps.name}-${localeKey}`}\n {...componentInputProps}\n />\n )}\n </ComponentInput>\n );\n case 'dynamiczone':\n return (\n <DynamicZone\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'relation':\n return (\n <RelationsInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'richtext':\n return (\n <Wysiwyg\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'uid':\n // These props are not needed for the generic form input renderer.\n const { unique: _uniqueUID, ...restUIDProps } = props;\n return (\n <UIDInput\n key={`input-${props.name}-${localeKey}`}\n {...restUIDProps}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...restProps}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst rulesEngine = createRulesEngine();\n\n/**\n * A wrapper around BaseInputRenderer that conditionally renders it depending on the attribute's condition.\n */\nconst ConditionAwareInputRenderer = ({\n condition,\n ...props\n}: InputRendererProps & { condition: JsonLogicCondition }) => {\n // Note: this selector causes a re-render every time any form value on the page changes\n const fieldValues = useForm('ConditionalInputRenderer', (state) => state.values);\n const isVisible = rulesEngine.evaluate(condition, fieldValues);\n\n if (!isVisible) {\n return null;\n }\n\n return <BaseInputRenderer {...props} />;\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = ['string', 'uid', 'richtext', 'email', 'password', 'text'].includes(attribute.type)\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\n/**\n * Conditionally routes the exported InputRender component towards ConditionalInputRenderer\n * (when there's a JSON logic condition on the attribute, or BaseInputRenderer otherwise.\n * We do this because rendering a conditional field requires access to the values of\n * other form fields, which causes many re-renders and performance issues on complex content\n * types. By splitting the component into two, we isolate the performance issue to\n * conditional fields only, not all edit view fields.\n */\nconst MemoizedInputRenderer = React.memo((props: InputRendererProps) => {\n const condition = props.attribute.conditions?.visible;\n if (condition) {\n return <ConditionAwareInputRenderer {...props} condition={condition} />;\n }\n\n return <BaseInputRenderer {...props} />;\n});\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["BaseInputRenderer","visible","hint","providedHint","document","inputProps","localeKey","locale","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isInPreviewPopover","useHasInputPopoverParent","shouldIgnorePermissions","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","previewProps","usePreviewInputManager","name","attribute","props","canUserReadField","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","componentInputProps","DynamicZone","RelationsInput","Wysiwyg","unique","_uniqueUID","restUIDProps","UIDInput","options","enum","map","value","_unique","mainField","_mainField","restProps","rulesEngine","createRulesEngine","ConditionAwareInputRenderer","condition","fieldValues","values","isVisible","evaluate","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo","conditions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;AAOC,IACD,MAAMA,iBAAAA,GAAoB,CAAC,EACzBC,OAAO,EACPC,IAAMC,EAAAA,YAAY,EAClBC,QAAQ,EACR,GAAGC,UACgB,EAAA,GAAA;IACnB,MAAMC,SAAAA,GAAYF,QAAUA,EAAAA,QAAAA,EAAUG,MAAU,IAAA,SAAA;AAChD,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAAGC,qCAAmB,CAAA,kBAAA,CAAA;IACnD,MAAM,EACJC,MAAM,EAAEC,UAAU,EAAE,EACrB,GAAGC,mCAAkBJ,CAAAA,mBAAAA,CAAoBK,KAAK,CAAA;AAE/C,IAAA,MAAMC,iBACJV,QAASW,CAAAA,MAAM,EAAEC,IAAAA,KAAS,mBAAmB,kBAAqB,GAAA,cAAA;AAEpE,IAAA,MAAMC,kBAAkBC,oBAAe,CAAA,iBAAA,EAAmB,CAACC,KAAAA,GAAUA,MAAMF,eAAe,CAAA;AAC1F,IAAA,MAAMG,kBAAqBC,GAAAA,qCAAAA,EAAAA;AAC3B,IAAA,MAAMC,0BAA0BL,eAAmBG,IAAAA,kBAAAA;AAEnD,IAAA,MAAMG,iBAAiBC,mBAAQ,CAAA,eAAA,EA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CAAA;AAEA;;;;;;;AAOC,IACK8D,MAAAA,qBAAAA,iBAAwBC,gBAAMC,CAAAA,IAAI,CAAC,CAAC3E,KAAAA,GAAAA;AACxC,IAAA,MAAM+C,SAAY/C,GAAAA,KAAAA,CAAMD,SAAS,CAAC6E,UAAU,EAAEpH,OAAAA;AAC9C,IAAA,IAAIuF,SAAW,EAAA;AACb,QAAA,qBAAOhC,cAAC+B,CAAAA,2BAAAA,EAAAA;AAA6B,YAAA,GAAG9C,KAAK;YAAE+C,SAAWA,EAAAA;;AAC5D;AAEA,IAAA,qBAAOhC,cAACxD,CAAAA,iBAAAA,EAAAA;AAAmB,QAAA,GAAGyC;;AAChC,CAAA;;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import { useForm, useStrapiApp, useField, InputRenderer as InputRenderer$1 } from '@strapi/admin/strapi-admin';
3
+ import { createRulesEngine, useForm, useStrapiApp, useField, InputRenderer } from '@strapi/admin/strapi-admin';
4
4
  import { useIntl } from 'react-intl';
5
5
  import { SINGLE_TYPES } from '../../../constants/collections.mjs';
6
6
  import { useDocumentRBAC } from '../../../features/DocumentRBAC.mjs';
@@ -24,7 +24,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
24
24
  * specifically to be used in the EditView of the content-manager this understands
25
25
  * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific
26
26
  * components such as Blocks / Relations.
27
- */ const InputRenderer = ({ visible, hint: providedHint, document, ...inputProps })=>{
27
+ */ const BaseInputRenderer = ({ visible, hint: providedHint, document, ...inputProps })=>{
28
28
  const localeKey = document?.document?.locale || 'default';
29
29
  const { currentDocumentMeta } = useDocumentContext('DynamicComponent');
30
30
  const { edit: { components } } = useDocumentLayout(currentDocumentMeta.model);
@@ -87,7 +87,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
87
87
  disabled: fieldIsDisabled
88
88
  });
89
89
  }
90
- return /*#__PURE__*/ jsx(InputRenderer$1, {
90
+ return /*#__PURE__*/ jsx(InputRenderer, {
91
91
  ...props,
92
92
  ...previewProps,
93
93
  hint: hint,
@@ -125,7 +125,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
125
125
  hint: hint,
126
126
  layout: components[props.attribute.component].layout,
127
127
  disabled: fieldIsDisabled,
128
- children: (componentInputProps)=>/*#__PURE__*/ jsx(InputRenderer, {
128
+ children: (componentInputProps)=>/*#__PURE__*/ jsx(BaseInputRenderer, {
129
129
  ...componentInputProps
130
130
  }, `input-${componentInputProps.name}-${localeKey}`)
131
131
  }, `input-${props.name}-${localeKey}`);
@@ -160,7 +160,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
160
160
  /**
161
161
  * Enumerations are a special case because they require options.
162
162
  */ case 'enumeration':
163
- return /*#__PURE__*/ jsx(InputRenderer$1, {
163
+ return /*#__PURE__*/ jsx(InputRenderer, {
164
164
  ...props,
165
165
  ...previewProps,
166
166
  hint: hint,
@@ -174,7 +174,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
174
174
  default:
175
175
  // These props are not needed for the generic form input renderer.
176
176
  const { unique: _unique, mainField: _mainField, ...restProps } = props;
177
- return /*#__PURE__*/ jsx(InputRenderer$1, {
177
+ return /*#__PURE__*/ jsx(InputRenderer, {
178
178
  ...restProps,
179
179
  ...previewProps,
180
180
  hint: hint,
@@ -184,6 +184,20 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
184
184
  }, `input-${props.name}-${localeKey}`);
185
185
  }
186
186
  };
187
+ const rulesEngine = createRulesEngine();
188
+ /**
189
+ * A wrapper around BaseInputRenderer that conditionally renders it depending on the attribute's condition.
190
+ */ const ConditionAwareInputRenderer = ({ condition, ...props })=>{
191
+ // Note: this selector causes a re-render every time any form value on the page changes
192
+ const fieldValues = useForm('ConditionalInputRenderer', (state)=>state.values);
193
+ const isVisible = rulesEngine.evaluate(condition, fieldValues);
194
+ if (!isVisible) {
195
+ return null;
196
+ }
197
+ return /*#__PURE__*/ jsx(BaseInputRenderer, {
198
+ ...props
199
+ });
200
+ };
187
201
  const attributeHasCustomFieldProperty = (attribute)=>'customField' in attribute && typeof attribute.customField === 'string';
188
202
  const useFieldHint = (hint = undefined, attribute)=>{
189
203
  const { formatMessage } = useIntl();
@@ -238,7 +252,25 @@ const getMinMax = (attribute)=>{
238
252
  };
239
253
  }
240
254
  };
241
- const MemoizedInputRenderer = /*#__PURE__*/ React.memo(InputRenderer);
255
+ /**
256
+ * Conditionally routes the exported InputRender component towards ConditionalInputRenderer
257
+ * (when there's a JSON logic condition on the attribute, or BaseInputRenderer otherwise.
258
+ * We do this because rendering a conditional field requires access to the values of
259
+ * other form fields, which causes many re-renders and performance issues on complex content
260
+ * types. By splitting the component into two, we isolate the performance issue to
261
+ * conditional fields only, not all edit view fields.
262
+ */ const MemoizedInputRenderer = /*#__PURE__*/ React.memo((props)=>{
263
+ const condition = props.attribute.conditions?.visible;
264
+ if (condition) {
265
+ return /*#__PURE__*/ jsx(ConditionAwareInputRenderer, {
266
+ ...props,
267
+ condition: condition
268
+ });
269
+ }
270
+ return /*#__PURE__*/ jsx(BaseInputRenderer, {
271
+ ...props
272
+ });
273
+ });
242
274
 
243
275
  export { MemoizedInputRenderer as InputRenderer, useFieldHint };
244
276
  //# sourceMappingURL=InputRenderer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"InputRenderer.mjs","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\nimport { useHasInputPopoverParent } from '../../../preview/components/InputPopover';\nimport { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst InputRenderer = ({\n visible,\n hint: providedHint,\n document,\n ...inputProps\n}: InputRendererProps) => {\n const localeKey = document?.document?.locale || 'default';\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n const isInPreviewPopover = useHasInputPopoverParent();\n const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n // Everything preview related\n const previewProps = usePreviewInputManager(inputProps.name, inputProps.attribute);\n const props = { ...inputProps, ...previewProps };\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !shouldIgnorePermissions) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !shouldIgnorePermissions) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n return (\n <CustomInput\n {...props}\n {...field}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n return (\n <CustomInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return (\n <BlocksInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'component':\n return (\n <ComponentInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(componentInputProps) => (\n <InputRenderer\n key={`input-${componentInputProps.name}-${localeKey}`}\n {...componentInputProps}\n />\n )}\n </ComponentInput>\n );\n case 'dynamiczone':\n return (\n <DynamicZone\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'relation':\n return (\n <RelationsInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'richtext':\n return (\n <Wysiwyg\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'uid':\n // These props are not needed for the generic form input renderer.\n const { unique: _uniqueUID, ...restUIDProps } = props;\n return (\n <UIDInput\n key={`input-${props.name}-${localeKey}`}\n {...restUIDProps}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...restProps}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = ['string', 'uid', 'richtext', 'email', 'password', 'text'].includes(attribute.type)\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\nconst MemoizedInputRenderer = React.memo(InputRenderer);\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["InputRenderer","visible","hint","providedHint","document","inputProps","localeKey","locale","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isInPreviewPopover","useHasInputPopoverParent","shouldIgnorePermissions","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","previewProps","usePreviewInputManager","name","attribute","props","canUserReadField","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","componentInputProps","DynamicZone","RelationsInput","Wysiwyg","unique","_uniqueUID","restUIDProps","UIDInput","options","enum","map","value","_unique","mainField","_mainField","restProps","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;AAOC,IACD,MAAMA,aAAAA,GAAgB,CAAC,EACrBC,OAAO,EACPC,IAAMC,EAAAA,YAAY,EAClBC,QAAQ,EACR,GAAGC,UACgB,EAAA,GAAA;IACnB,MAAMC,SAAAA,GAAYF,QAAUA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ACL,OAAO;YAAElB,OAASnC,EAAAA,SAAAA;YAAWoC,OAASpC,EAAAA;AAAU,SAAA;AAClD;AACF,CAAA;AAEMsD,MAAAA,qBAAAA,iBAAwBC,KAAMC,CAAAA,IAAI,CAAC5G,aAAAA;;;;"}
1
+ {"version":3,"file":"InputRenderer.mjs","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n createRulesEngine,\n type JsonLogicCondition,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\nimport { useHasInputPopoverParent } from '../../../preview/components/InputPopover';\nimport { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst BaseInputRenderer = ({\n visible,\n hint: providedHint,\n document,\n ...inputProps\n}: InputRendererProps) => {\n const localeKey = document?.document?.locale || 'default';\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n const isInPreviewPopover = useHasInputPopoverParent();\n const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n // Everything preview related\n const previewProps = usePreviewInputManager(inputProps.name, inputProps.attribute);\n const props = { ...inputProps, ...previewProps };\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !shouldIgnorePermissions) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !shouldIgnorePermissions) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n return (\n <CustomInput\n {...props}\n {...field}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n return (\n <CustomInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return (\n <BlocksInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'component':\n return (\n <ComponentInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(componentInputProps) => (\n <BaseInputRenderer\n key={`input-${componentInputProps.name}-${localeKey}`}\n {...componentInputProps}\n />\n )}\n </ComponentInput>\n );\n case 'dynamiczone':\n return (\n <DynamicZone\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'relation':\n return (\n <RelationsInput\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n case 'richtext':\n return (\n <Wysiwyg\n key={`input-${props.name}-${localeKey}`}\n {...props}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n case 'uid':\n // These props are not needed for the generic form input renderer.\n const { unique: _uniqueUID, ...restUIDProps } = props;\n return (\n <UIDInput\n key={`input-${props.name}-${localeKey}`}\n {...restUIDProps}\n hint={hint}\n type={props.type}\n disabled={fieldIsDisabled}\n />\n );\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...props}\n {...previewProps}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n key={`input-${props.name}-${localeKey}`}\n {...restProps}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst rulesEngine = createRulesEngine();\n\n/**\n * A wrapper around BaseInputRenderer that conditionally renders it depending on the attribute's condition.\n */\nconst ConditionAwareInputRenderer = ({\n condition,\n ...props\n}: InputRendererProps & { condition: JsonLogicCondition }) => {\n // Note: this selector causes a re-render every time any form value on the page changes\n const fieldValues = useForm('ConditionalInputRenderer', (state) => state.values);\n const isVisible = rulesEngine.evaluate(condition, fieldValues);\n\n if (!isVisible) {\n return null;\n }\n\n return <BaseInputRenderer {...props} />;\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = ['string', 'uid', 'richtext', 'email', 'password', 'text'].includes(attribute.type)\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\n/**\n * Conditionally routes the exported InputRender component towards ConditionalInputRenderer\n * (when there's a JSON logic condition on the attribute, or BaseInputRenderer otherwise.\n * We do this because rendering a conditional field requires access to the values of\n * other form fields, which causes many re-renders and performance issues on complex content\n * types. By splitting the component into two, we isolate the performance issue to\n * conditional fields only, not all edit view fields.\n */\nconst MemoizedInputRenderer = React.memo((props: InputRendererProps) => {\n const condition = props.attribute.conditions?.visible;\n if (condition) {\n return <ConditionAwareInputRenderer {...props} condition={condition} />;\n }\n\n return <BaseInputRenderer {...props} />;\n});\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["BaseInputRenderer","visible","hint","providedHint","document","inputProps","localeKey","locale","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isInPreviewPopover","useHasInputPopoverParent","shouldIgnorePermissions","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","previewProps","usePreviewInputManager","name","attribute","props","canUserReadField","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","componentInputProps","DynamicZone","RelationsInput","Wysiwyg","unique","_uniqueUID","restUIDProps","UIDInput","options","enum","map","value","_unique","mainField","_mainField","restProps","rulesEngine","createRulesEngine","ConditionAwareInputRenderer","condition","fieldValues","values","isVisible","evaluate","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo","conditions"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;AAOC,IACD,MAAMA,iBAAAA,GAAoB,CAAC,EACzBC,OAAO,EACPC,IAAMC,EAAAA,YAAY,EAClBC,QAAQ,EACR,GAAGC,UACgB,EAAA,GAAA;IACnB,MAAMC,SAAAA,GAAYF,QAAUA,EAAAA,QAAAA,EAAUG,MAAU,IAAA,SAAA;AAChD,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAA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,SAAAA;YACxE4C,OAAS,EAAA,CAACc,MAAOC,CAAAA,KAAK,CAACD,MAAAA,CAAOtE,SAAUiE,CAAAA,GAAG,CAAKK,CAAAA,GAAAA,MAAAA,CAAOtE,SAAUiE,CAAAA,GAAG,CAAIrD,GAAAA;AAC1E,SAAA;AACF,KAAA,MAAO,IAAI,WAAA,IAAeZ,SAAa,IAAA,WAAA,IAAeA,SAAW,EAAA;QAC/D,OAAO;AAAEuD,YAAAA,OAAAA,EAASvD,UAAUwE,SAAS;AAAEhB,YAAAA,OAAAA,EAASxD,UAAUyE;AAAU,SAAA;KAC/D,MAAA;QACL,OAAO;YAAElB,OAAS3C,EAAAA,SAAAA;YAAW4C,OAAS5C,EAAAA;AAAU,SAAA;AAClD;AACF,CAAA;AAEA;;;;;;;AAOC,IACK8D,MAAAA,qBAAAA,iBAAwBC,KAAMC,CAAAA,IAAI,CAAC,CAAC3E,KAAAA,GAAAA;AACxC,IAAA,MAAM+C,SAAY/C,GAAAA,KAAAA,CAAMD,SAAS,CAAC6E,UAAU,EAAEpH,OAAAA;AAC9C,IAAA,IAAIuF,SAAW,EAAA;AACb,QAAA,qBAAOhC,GAAC+B,CAAAA,2BAAAA,EAAAA;AAA6B,YAAA,GAAG9C,KAAK;YAAE+C,SAAWA,EAAAA;;AAC5D;AAEA,IAAA,qBAAOhC,GAACxD,CAAAA,iBAAAA,EAAAA;AAAmB,QAAA,GAAGyC;;AAChC,CAAA;;;;"}
@@ -7,6 +7,14 @@ type InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {
7
7
  document: ReturnType<UseDocument>;
8
8
  };
9
9
  declare const useFieldHint: (hint: React.ReactNode, attribute: Schema.Attribute.AnyAttribute) => string | number | boolean | import("react/jsx-runtime").JSX.Element | Iterable<React.ReactNode> | (string | import("react/jsx-runtime").JSX.Element | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal)[] | null | undefined;
10
- declare const MemoizedInputRenderer: React.MemoExoticComponent<({ visible, hint: providedHint, document, ...inputProps }: InputRendererProps) => import("react/jsx-runtime").JSX.Element | null>;
10
+ /**
11
+ * Conditionally routes the exported InputRender component towards ConditionalInputRenderer
12
+ * (when there's a JSON logic condition on the attribute, or BaseInputRenderer otherwise.
13
+ * We do this because rendering a conditional field requires access to the values of
14
+ * other form fields, which causes many re-renders and performance issues on complex content
15
+ * types. By splitting the component into two, we isolate the performance issue to
16
+ * conditional fields only, not all edit view fields.
17
+ */
18
+ declare const MemoizedInputRenderer: React.MemoExoticComponent<(props: InputRendererProps) => import("react/jsx-runtime").JSX.Element>;
11
19
  export type { InputRendererProps };
12
20
  export { MemoizedInputRenderer as InputRenderer, useFieldHint };
@@ -51,7 +51,8 @@ const escapeRegex = (str)=>str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
51
51
  const createModelSchema = (attributes$1, removedAttributes = [])=>yup__namespace.object().shape(Object.entries(attributes$1).reduce((acc, [name, attribute])=>{
52
52
  const getNestedPathsForAttribute = (removed, attrName)=>{
53
53
  const prefix = `${attrName}.`;
54
- const bracketRegex = new RegExp(`^${escapeRegex(attrName)}\\[\\d+\\]\\.`);
54
+ // Match both numeric indices [0] and __temp_key__ values [some_key]
55
+ const bracketRegex = new RegExp(`^${escapeRegex(attrName)}\\[[^\\]]+\\]\\.`);
55
56
  return removed.filter((p)=>p.startsWith(prefix) || bracketRegex.test(p)).map((p)=>p.startsWith(prefix) ? p.slice(prefix.length) : p.replace(bracketRegex, ''));
56
57
  };
57
58
  if (attributes.DOCUMENT_META_FIELDS.includes(name)) {
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sources":["../../../admin/src/utils/validation.ts"],"sourcesContent":["import { translatedErrors } from '@strapi/admin/strapi-admin';\nimport pipe from 'lodash/fp/pipe';\nimport * as yup from 'yup';\n\nimport { DOCUMENT_META_FIELDS } from '../constants/attributes';\n\nimport type { ComponentsDictionary, Schema } from '../hooks/useDocument';\nimport type { Schema as SchemaUtils } from '@strapi/types';\nimport type { ObjectShape } from 'yup/lib/object';\n\ntype AnySchema =\n | yup.StringSchema\n | yup.NumberSchema\n | yup.BooleanSchema\n | yup.DateSchema\n | yup.ArraySchema<any>\n | yup.ObjectSchema<any>;\n\n/* -------------------------------------------------------------------------------------------------\n * createYupSchema\n * -----------------------------------------------------------------------------------------------*/\n\ninterface ValidationOptions {\n status: 'draft' | 'published' | null;\n removedAttributes?: string[];\n}\n\nconst arrayValidator = (attribute: Schema['attributes'][string], options: ValidationOptions) => ({\n message: translatedErrors.required,\n test(value: unknown) {\n if (options.status === 'draft') {\n return true;\n }\n\n if (!attribute.required) {\n return true;\n }\n\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value) && value.length === 0) {\n return false;\n }\n\n return true;\n },\n});\nconst escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n/**\n * TODO: should we create a Map to store these based on the hash of the schema?\n */\nconst createYupSchema = (\n attributes: Schema['attributes'] = {},\n components: ComponentsDictionary = {},\n options: ValidationOptions = { status: null }\n): yup.ObjectSchema<any> => {\n const createModelSchema = (\n attributes: Schema['attributes'],\n removedAttributes: string[] = []\n ): yup.ObjectSchema<any> =>\n yup\n .object()\n .shape(\n Object.entries(attributes).reduce<ObjectShape>((acc, [name, attribute]) => {\n const getNestedPathsForAttribute = (removed: string[], attrName: string): string[] => {\n const prefix = `${attrName}.`;\n const bracketRegex = new RegExp(`^${escapeRegex(attrName)}\\\\[\\\\d+\\\\]\\\\.`);\n\n return removed\n .filter((p) => p.startsWith(prefix) || bracketRegex.test(p))\n .map((p) =>\n p.startsWith(prefix) ? p.slice(prefix.length) : p.replace(bracketRegex, '')\n );\n };\n\n if (DOCUMENT_META_FIELDS.includes(name)) {\n return acc;\n }\n\n if (removedAttributes?.includes(name)) {\n // If the attribute is not visible, we don't want to validate it\n return acc;\n }\n\n const nestedRemoved = getNestedPathsForAttribute(removedAttributes, name);\n\n /**\n * These validations won't apply to every attribute\n * and that's okay, in that case we just return the\n * schema as it was passed.\n */\n const validations = [\n addNullableValidation,\n addRequiredValidation,\n addMinLengthValidation,\n addMaxLengthValidation,\n addMinValidation,\n addMaxValidation,\n addRegexValidation,\n ].map((fn) => fn(attribute, options));\n\n const transformSchema = pipe(...validations);\n\n switch (attribute.type) {\n case 'component': {\n const { attributes } = components[attribute.component];\n\n if (attribute.repeatable) {\n return {\n ...acc,\n [name]: transformSchema(\n yup.array().of(createModelSchema(attributes, nestedRemoved).nullable(false))\n ).test(arrayValidator(attribute, options)),\n };\n } else {\n return {\n ...acc,\n [name]: transformSchema(createModelSchema(attributes, nestedRemoved).nullable()),\n };\n }\n }\n case 'dynamiczone':\n return {\n ...acc,\n [name]: transformSchema(\n yup.array().of(\n yup.lazy(\n (\n data: SchemaUtils.Attribute.Value<SchemaUtils.Attribute.DynamicZone>[number]\n ) => {\n const attributes = components?.[data?.__component]?.attributes;\n\n const validation = yup\n .object()\n .shape({\n __component: yup.string().required().oneOf(Object.keys(components)),\n })\n .nullable(false);\n if (!attributes) {\n return validation;\n }\n\n return validation.concat(createModelSchema(attributes, nestedRemoved));\n }\n ) as unknown as yup.ObjectSchema<any>\n )\n ).test(arrayValidator(attribute, options)),\n };\n case 'relation':\n return {\n ...acc,\n [name]: transformSchema(\n yup.lazy((value) => {\n if (!value) {\n return yup.mixed().nullable(true);\n } else if (Array.isArray(value)) {\n // If a relation value is an array, we expect\n // an array of objects with {id} properties, representing the related entities.\n return yup.array().of(\n yup.object().shape({\n id: yup.number().required(),\n })\n );\n } else if (typeof value === 'object') {\n // A realtion value can also be an object. Some API\n // repsonses return the number of entities in the relation\n // as { count: x }\n return yup.object();\n } else {\n return yup\n .mixed()\n .test(\n 'type-error',\n 'Relation values must be either null, an array of objects with {id} or an object.',\n () => false\n );\n }\n })\n ),\n };\n default:\n return {\n ...acc,\n [name]: transformSchema(createAttributeSchema(attribute)),\n };\n }\n }, {})\n )\n /**\n * TODO: investigate why an undefined object fails a check of `nullable`.\n */\n .default(null);\n\n return createModelSchema(attributes, options.removedAttributes);\n};\n\nconst createAttributeSchema = (\n attribute: Exclude<\n SchemaUtils.Attribute.AnyAttribute,\n { type: 'dynamiczone' } | { type: 'component' } | { type: 'relation' }\n >\n) => {\n switch (attribute.type) {\n case 'biginteger':\n return yup.string().matches(/^-?\\d*$/);\n case 'boolean':\n return yup.boolean().nullable();\n case 'blocks':\n return yup.mixed().test('isBlocks', translatedErrors.json, (value) => {\n if (!value || Array.isArray(value)) {\n return true;\n } else {\n return false;\n }\n });\n case 'decimal':\n case 'float':\n case 'integer':\n return yup.number();\n case 'email':\n return yup.string().email(translatedErrors.email);\n case 'enumeration':\n return yup.string().oneOf([...attribute.enum, null]);\n case 'json':\n return yup.mixed().test('isJSON', translatedErrors.json, (value) => {\n /**\n * We don't want to validate the JSON field if it's empty.\n */\n if (!value || (typeof value === 'string' && value.length === 0)) {\n return true;\n }\n\n // If the value was created via content API and wasn't changed, then it's still an object\n if (typeof value === 'object') {\n try {\n JSON.stringify(value);\n return true;\n } catch (err) {\n return false;\n }\n }\n\n try {\n JSON.parse(value);\n\n return true;\n } catch (err) {\n return false;\n }\n });\n case 'password':\n return yup.string().nullable();\n case 'richtext':\n case 'string':\n case 'text':\n return yup.string();\n case 'uid':\n return yup\n .string()\n .matches(attribute.regex ? new RegExp(attribute.regex) : /^[A-Za-z0-9-_.~]*$/);\n default:\n /**\n * This allows any value.\n */\n return yup.mixed();\n }\n};\n\n// Helper function to return schema.nullable() if it exists, otherwise return schema\nconst nullableSchema = <TSchema extends AnySchema>(schema: TSchema) => {\n return schema?.nullable\n ? schema.nullable()\n : // In some cases '.nullable' will not be available on the schema.\n // e.g. when the schema has been built using yup.lazy (e.g. for relations).\n // In these cases we should just return the schema as it is.\n schema;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Validators\n * -----------------------------------------------------------------------------------------------*/\n/**\n * Our validator functions can be preped with the\n * attribute and then have the schema piped through them.\n */\ntype ValidationFn = (\n attribute: Schema['attributes'][string],\n options: ValidationOptions\n) => <TSchema extends AnySchema>(schema: TSchema) => TSchema;\n\nconst addNullableValidation: ValidationFn = () => (schema) => {\n return nullableSchema(schema);\n};\n\nconst addRequiredValidation: ValidationFn = (attribute, options) => (schema) => {\n if (options.status === 'draft' || !attribute.required || attribute.type === 'password') {\n return schema;\n }\n\n if (attribute.required && 'required' in schema) {\n return schema.required(translatedErrors.required);\n }\n\n return schema;\n};\n\nconst addMinLengthValidation: ValidationFn =\n (attribute, options) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n // Skip minLength validation for draft\n if (options.status === 'draft') {\n return schema;\n }\n\n if (\n 'minLength' in attribute &&\n attribute.minLength &&\n Number.isInteger(attribute.minLength) &&\n 'min' in schema\n ) {\n return schema.min(attribute.minLength, {\n ...translatedErrors.minLength,\n values: {\n min: attribute.minLength,\n },\n }) as TSchema;\n }\n\n return schema;\n };\n\nconst addMaxLengthValidation: ValidationFn =\n (attribute) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n if (\n 'maxLength' in attribute &&\n attribute.maxLength &&\n Number.isInteger(attribute.maxLength) &&\n 'max' in schema\n ) {\n return schema.max(attribute.maxLength, {\n ...translatedErrors.maxLength,\n values: {\n max: attribute.maxLength,\n },\n }) as TSchema;\n }\n\n return schema;\n };\n\nconst addMinValidation: ValidationFn =\n (attribute, options) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n // do not validate min for draft\n if (options.status === 'draft') {\n return schema;\n }\n\n if ('min' in attribute && 'min' in schema) {\n const min = toInteger(attribute.min);\n\n if (min) {\n return schema.min(min, {\n ...translatedErrors.min,\n values: {\n min,\n },\n }) as TSchema;\n }\n }\n\n return schema;\n };\n\nconst addMaxValidation: ValidationFn =\n (attribute) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n if ('max' in attribute) {\n const max = toInteger(attribute.max);\n\n if ('max' in schema && max) {\n return schema.max(max, {\n ...translatedErrors.max,\n values: {\n max,\n },\n }) as TSchema;\n }\n }\n\n return schema;\n };\n\nconst toInteger = (val?: string | number): number | undefined => {\n if (typeof val === 'number' || val === undefined) {\n return val;\n } else {\n const num = Number(val);\n return isNaN(num) ? undefined : num;\n }\n};\n\nconst addRegexValidation: ValidationFn =\n (attribute) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n if ('regex' in attribute && attribute.regex && 'matches' in schema) {\n return schema.matches(new RegExp(attribute.regex), {\n message: {\n id: translatedErrors.regex.id,\n defaultMessage: 'The value does not match the defined pattern.',\n },\n\n excludeEmptyString: !attribute.required,\n }) as TSchema;\n }\n\n return schema;\n };\n\nexport { createYupSchema };\n"],"names":["arrayValidator","attribute","options","message","translatedErrors","required","test","value","status","Array","isArray","length","escapeRegex","str","replace","createYupSchema","attributes","components","createModelSchema","removedAttributes","yup","object","shape","Object","entries","reduce","acc","name","getNestedPathsForAttribute","removed","attrName","prefix","bracketRegex","RegExp","filter","p","startsWith","map","slice","DOCUMENT_META_FIELDS","includes","nestedRemoved","validations","addNullableValidation","addRequiredValidation","addMinLengthValidation","addMaxLengthValidation","addMinValidation","addMaxValidation","addRegexValidation","fn","transformSchema","pipe","type","component","repeatable","array","of","nullable","lazy","data","__component","validation","string","oneOf","keys","concat","mixed","id","number","createAttributeSchema","default","matches","boolean","json","email","enum","JSON","stringify","err","parse","regex","nullableSchema","schema","minLength","Number","isInteger","min","values","maxLength","max","toInteger","val","undefined","num","isNaN","defaultMessage","excludeEmptyString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAMA,cAAiB,GAAA,CAACC,SAAyCC,EAAAA,OAAAA,IAAgC;AAC/FC,QAAAA,OAAAA,EAASC,6BAAiBC,QAAQ;AAClCC,QAAAA,IAAAA,CAAAA,CAAKC,KAAc,EAAA;YACjB,IAAIL,OAAAA,CAAQM,MAAM,KAAK,OAAS,EAAA;gBAC9B,OAAO,IAAA;AACT;YAEA,IAAI,CAACP,SAAUI,CAAAA,QAAQ,EAAE;gBACvB,OAAO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KAAA;;;;"}
1
+ {"version":3,"file":"validation.js","sources":["../../../admin/src/utils/validation.ts"],"sourcesContent":["import { translatedErrors } from '@strapi/admin/strapi-admin';\nimport pipe from 'lodash/fp/pipe';\nimport * as yup from 'yup';\n\nimport { DOCUMENT_META_FIELDS } from '../constants/attributes';\n\nimport type { ComponentsDictionary, Schema } from '../hooks/useDocument';\nimport type { Schema as SchemaUtils } from '@strapi/types';\nimport type { ObjectShape } from 'yup/lib/object';\n\ntype AnySchema =\n | yup.StringSchema\n | yup.NumberSchema\n | yup.BooleanSchema\n | yup.DateSchema\n | yup.ArraySchema<any>\n | yup.ObjectSchema<any>;\n\n/* -------------------------------------------------------------------------------------------------\n * createYupSchema\n * -----------------------------------------------------------------------------------------------*/\n\ninterface ValidationOptions {\n status: 'draft' | 'published' | null;\n removedAttributes?: string[];\n}\n\nconst arrayValidator = (attribute: Schema['attributes'][string], options: ValidationOptions) => ({\n message: translatedErrors.required,\n test(value: unknown) {\n if (options.status === 'draft') {\n return true;\n }\n\n if (!attribute.required) {\n return true;\n }\n\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value) && value.length === 0) {\n return false;\n }\n\n return true;\n },\n});\nconst escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n/**\n * TODO: should we create a Map to store these based on the hash of the schema?\n */\nconst createYupSchema = (\n attributes: Schema['attributes'] = {},\n components: ComponentsDictionary = {},\n options: ValidationOptions = { status: null }\n): yup.ObjectSchema<any> => {\n const createModelSchema = (\n attributes: Schema['attributes'],\n removedAttributes: string[] = []\n ): yup.ObjectSchema<any> =>\n yup\n .object()\n .shape(\n Object.entries(attributes).reduce<ObjectShape>((acc, [name, attribute]) => {\n const getNestedPathsForAttribute = (removed: string[], attrName: string): string[] => {\n const prefix = `${attrName}.`;\n // Match both numeric indices [0] and __temp_key__ values [some_key]\n const bracketRegex = new RegExp(`^${escapeRegex(attrName)}\\\\[[^\\\\]]+\\\\]\\\\.`);\n\n return removed\n .filter((p) => p.startsWith(prefix) || bracketRegex.test(p))\n .map((p) =>\n p.startsWith(prefix) ? p.slice(prefix.length) : p.replace(bracketRegex, '')\n );\n };\n\n if (DOCUMENT_META_FIELDS.includes(name)) {\n return acc;\n }\n\n if (removedAttributes?.includes(name)) {\n // If the attribute is not visible, we don't want to validate it\n return acc;\n }\n\n const nestedRemoved = getNestedPathsForAttribute(removedAttributes, name);\n\n /**\n * These validations won't apply to every attribute\n * and that's okay, in that case we just return the\n * schema as it was passed.\n */\n const validations = [\n addNullableValidation,\n addRequiredValidation,\n addMinLengthValidation,\n addMaxLengthValidation,\n addMinValidation,\n addMaxValidation,\n addRegexValidation,\n ].map((fn) => fn(attribute, options));\n\n const transformSchema = pipe(...validations);\n\n switch (attribute.type) {\n case 'component': {\n const { attributes } = components[attribute.component];\n\n if (attribute.repeatable) {\n return {\n ...acc,\n [name]: transformSchema(\n yup.array().of(createModelSchema(attributes, nestedRemoved).nullable(false))\n ).test(arrayValidator(attribute, options)),\n };\n } else {\n return {\n ...acc,\n [name]: transformSchema(createModelSchema(attributes, nestedRemoved).nullable()),\n };\n }\n }\n case 'dynamiczone':\n return {\n ...acc,\n [name]: transformSchema(\n yup.array().of(\n yup.lazy(\n (\n data: SchemaUtils.Attribute.Value<SchemaUtils.Attribute.DynamicZone>[number]\n ) => {\n const attributes = components?.[data?.__component]?.attributes;\n\n const validation = yup\n .object()\n .shape({\n __component: yup.string().required().oneOf(Object.keys(components)),\n })\n .nullable(false);\n if (!attributes) {\n return validation;\n }\n\n return validation.concat(createModelSchema(attributes, nestedRemoved));\n }\n ) as unknown as yup.ObjectSchema<any>\n )\n ).test(arrayValidator(attribute, options)),\n };\n case 'relation':\n return {\n ...acc,\n [name]: transformSchema(\n yup.lazy((value) => {\n if (!value) {\n return yup.mixed().nullable(true);\n } else if (Array.isArray(value)) {\n // If a relation value is an array, we expect\n // an array of objects with {id} properties, representing the related entities.\n return yup.array().of(\n yup.object().shape({\n id: yup.number().required(),\n })\n );\n } else if (typeof value === 'object') {\n // A realtion value can also be an object. Some API\n // repsonses return the number of entities in the relation\n // as { count: x }\n return yup.object();\n } else {\n return yup\n .mixed()\n .test(\n 'type-error',\n 'Relation values must be either null, an array of objects with {id} or an object.',\n () => false\n );\n }\n })\n ),\n };\n default:\n return {\n ...acc,\n [name]: transformSchema(createAttributeSchema(attribute)),\n };\n }\n }, {})\n )\n /**\n * TODO: investigate why an undefined object fails a check of `nullable`.\n */\n .default(null);\n\n return createModelSchema(attributes, options.removedAttributes);\n};\n\nconst createAttributeSchema = (\n attribute: Exclude<\n SchemaUtils.Attribute.AnyAttribute,\n { type: 'dynamiczone' } | { type: 'component' } | { type: 'relation' }\n >\n) => {\n switch (attribute.type) {\n case 'biginteger':\n return yup.string().matches(/^-?\\d*$/);\n case 'boolean':\n return yup.boolean().nullable();\n case 'blocks':\n return yup.mixed().test('isBlocks', translatedErrors.json, (value) => {\n if (!value || Array.isArray(value)) {\n return true;\n } else {\n return false;\n }\n });\n case 'decimal':\n case 'float':\n case 'integer':\n return yup.number();\n case 'email':\n return yup.string().email(translatedErrors.email);\n case 'enumeration':\n return yup.string().oneOf([...attribute.enum, null]);\n case 'json':\n return yup.mixed().test('isJSON', translatedErrors.json, (value) => {\n /**\n * We don't want to validate the JSON field if it's empty.\n */\n if (!value || (typeof value === 'string' && value.length === 0)) {\n return true;\n }\n\n // If the value was created via content API and wasn't changed, then it's still an object\n if (typeof value === 'object') {\n try {\n JSON.stringify(value);\n return true;\n } catch (err) {\n return false;\n }\n }\n\n try {\n JSON.parse(value);\n\n return true;\n } catch (err) {\n return false;\n }\n });\n case 'password':\n return yup.string().nullable();\n case 'richtext':\n case 'string':\n case 'text':\n return yup.string();\n case 'uid':\n return yup\n .string()\n .matches(attribute.regex ? new RegExp(attribute.regex) : /^[A-Za-z0-9-_.~]*$/);\n default:\n /**\n * This allows any value.\n */\n return yup.mixed();\n }\n};\n\n// Helper function to return schema.nullable() if it exists, otherwise return schema\nconst nullableSchema = <TSchema extends AnySchema>(schema: TSchema) => {\n return schema?.nullable\n ? schema.nullable()\n : // In some cases '.nullable' will not be available on the schema.\n // e.g. when the schema has been built using yup.lazy (e.g. for relations).\n // In these cases we should just return the schema as it is.\n schema;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Validators\n * -----------------------------------------------------------------------------------------------*/\n/**\n * Our validator functions can be preped with the\n * attribute and then have the schema piped through them.\n */\ntype ValidationFn = (\n attribute: Schema['attributes'][string],\n options: ValidationOptions\n) => <TSchema extends AnySchema>(schema: TSchema) => TSchema;\n\nconst addNullableValidation: ValidationFn = () => (schema) => {\n return nullableSchema(schema);\n};\n\nconst addRequiredValidation: ValidationFn = (attribute, options) => (schema) => {\n if (options.status === 'draft' || !attribute.required || attribute.type === 'password') {\n return schema;\n }\n\n if (attribute.required && 'required' in schema) {\n return schema.required(translatedErrors.required);\n }\n\n return schema;\n};\n\nconst addMinLengthValidation: ValidationFn =\n (attribute, options) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n // Skip minLength validation for draft\n if (options.status === 'draft') {\n return schema;\n }\n\n if (\n 'minLength' in attribute &&\n attribute.minLength &&\n Number.isInteger(attribute.minLength) &&\n 'min' in schema\n ) {\n return schema.min(attribute.minLength, {\n ...translatedErrors.minLength,\n values: {\n min: attribute.minLength,\n },\n }) as TSchema;\n }\n\n return schema;\n };\n\nconst addMaxLengthValidation: ValidationFn =\n (attribute) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n if (\n 'maxLength' in attribute &&\n attribute.maxLength &&\n Number.isInteger(attribute.maxLength) &&\n 'max' in schema\n ) {\n return schema.max(attribute.maxLength, {\n ...translatedErrors.maxLength,\n values: {\n max: attribute.maxLength,\n },\n }) as TSchema;\n }\n\n return schema;\n };\n\nconst addMinValidation: ValidationFn =\n (attribute, options) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n // do not validate min for draft\n if (options.status === 'draft') {\n return schema;\n }\n\n if ('min' in attribute && 'min' in schema) {\n const min = toInteger(attribute.min);\n\n if (min) {\n return schema.min(min, {\n ...translatedErrors.min,\n values: {\n min,\n },\n }) as TSchema;\n }\n }\n\n return schema;\n };\n\nconst addMaxValidation: ValidationFn =\n (attribute) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n if ('max' in attribute) {\n const max = toInteger(attribute.max);\n\n if ('max' in schema && max) {\n return schema.max(max, {\n ...translatedErrors.max,\n values: {\n max,\n },\n }) as TSchema;\n }\n }\n\n return schema;\n };\n\nconst toInteger = (val?: string | number): number | undefined => {\n if (typeof val === 'number' || val === undefined) {\n return val;\n } else {\n const num = Number(val);\n return isNaN(num) ? undefined : num;\n }\n};\n\nconst addRegexValidation: ValidationFn =\n (attribute) =>\n <TSchema extends AnySchema>(schema: TSchema): TSchema => {\n if ('regex' in attribute && attribute.regex && 'matches' in schema) {\n return schema.matches(new RegExp(attribute.regex), {\n message: {\n id: translatedErrors.regex.id,\n defaultMessage: 'The value does not match the defined pattern.',\n },\n\n excludeEmptyString: !attribute.required,\n }) as TSchema;\n }\n\n return schema;\n };\n\nexport { createYupSchema };\n"],"names":["arrayValidator","attribute","options","message","translatedErrors","required","test","value","status","Array","isArray","length","escapeRegex","str","replace","createYupSchema","attributes","components","createModelSchema","removedAttributes","yup","object","shape","Object","entries","reduce","acc","name","getNestedPathsForAttribute","removed","attrName","prefix","bracketRegex","RegExp","filter","p","startsWith","map","slice","DOCUMENT_META_FIELDS","includes","nestedRemoved","validations","addNullableValidation","addRequiredValidation","addMinLengthValidation","addMaxLengthValidation","addMinValidation","addMaxValidation","addRegexValidation","fn","transformSchema","pipe","type","component","repeatable","array","of","nullable","lazy","data","__component","validation","string","oneOf","keys","concat","mixed","id","number","createAttributeSchema","default","matches","boolean","json","email","enum","JSON","stringify","err","parse","regex","nullableSchema","schema","minLength","Number","isInteger","min","values","maxLength","max","toInteger","val","undefined","num","isNaN","defaultMessage","excludeEmptyString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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ClE,YAAA,OAAOA,OAAOX,OAAO,CAAC,IAAIvC,MAAOhC,CAAAA,SAAAA,CAAUgF,KAAK,CAAG,EAAA;gBACjD9E,OAAS,EAAA;oBACPiE,EAAIhE,EAAAA,4BAAAA,CAAiB6E,KAAK,CAACb,EAAE;oBAC7B4B,cAAgB,EAAA;AAClB,iBAAA;gBAEAC,kBAAoB,EAAA,CAAChG,UAAUI;AACjC,aAAA,CAAA;AACF;QAEA,OAAO8E,MAAAA;AACT,KAAA;;;;"}
@@ -30,7 +30,8 @@ const escapeRegex = (str)=>str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
30
30
  const createModelSchema = (attributes, removedAttributes = [])=>yup.object().shape(Object.entries(attributes).reduce((acc, [name, attribute])=>{
31
31
  const getNestedPathsForAttribute = (removed, attrName)=>{
32
32
  const prefix = `${attrName}.`;
33
- const bracketRegex = new RegExp(`^${escapeRegex(attrName)}\\[\\d+\\]\\.`);
33
+ // Match both numeric indices [0] and __temp_key__ values [some_key]
34
+ const bracketRegex = new RegExp(`^${escapeRegex(attrName)}\\[[^\\]]+\\]\\.`);
34
35
  return removed.filter((p)=>p.startsWith(prefix) || bracketRegex.test(p)).map((p)=>p.startsWith(prefix) ? p.slice(prefix.length) : p.replace(bracketRegex, ''));
35
36
  };
36
37
  if (DOCUMENT_META_FIELDS.includes(name)) {