@strapi/content-manager 5.51.2 → 5.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -144,8 +144,8 @@ const CodeBlock = styledComponents.styled.pre`
144
144
  flex-shrink: 1;
145
145
 
146
146
  & > code {
147
- font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,
148
- monospace;
147
+ font-family:
148
+ 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;
149
149
  color: ${({ theme })=>theme.colors.neutral800};
150
150
  overflow: auto;
151
151
  max-width: 100%;
@@ -1 +1 @@
1
- {"version":3,"file":"Code.js","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, SingleSelect, SingleSelectOption } from '@strapi/design-system';\nimport { CodeBlock as CodeBlockIcon } from '@strapi/icons';\nimport * as PrismModule from 'prismjs';\nimport { useIntl } from 'react-intl';\nimport { BaseRange, Element, Editor, Node, NodeEntry, Transforms } from 'slate';\nimport { useSelected, type RenderElementProps, useFocused, ReactEditor } from 'slate-react';\nimport { styled } from 'styled-components';\n\nimport { useBlocksEditorContext, type BlocksStore } from '../BlocksEditor';\nimport { codeLanguages } from '../utils/constants';\nimport { baseHandleConvert } from '../utils/conversions';\nimport { pressEnterTwiceToExit } from '../utils/enterKey';\nimport { type Block } from '../utils/types';\n\nimport 'prismjs/themes/prism-solarizedlight.css';\nimport 'prismjs/components/prism-asmatmel';\nimport 'prismjs/components/prism-bash';\nimport 'prismjs/components/prism-basic';\nimport 'prismjs/components/prism-c';\nimport 'prismjs/components/prism-clojure';\nimport 'prismjs/components/prism-cobol';\nimport 'prismjs/components/prism-cpp';\nimport 'prismjs/components/prism-csharp';\nimport 'prismjs/components/prism-dart';\nimport 'prismjs/components/prism-docker';\nimport 'prismjs/components/prism-elixir';\nimport 'prismjs/components/prism-erlang';\nimport 'prismjs/components/prism-fortran';\nimport 'prismjs/components/prism-fsharp';\nimport 'prismjs/components/prism-go';\nimport 'prismjs/components/prism-graphql';\nimport 'prismjs/components/prism-groovy';\nimport 'prismjs/components/prism-haskell';\nimport 'prismjs/components/prism-haxe';\nimport 'prismjs/components/prism-ini';\nimport 'prismjs/components/prism-java';\nimport 'prismjs/components/prism-javascript';\nimport 'prismjs/components/prism-jsx';\nimport 'prismjs/components/prism-json';\nimport 'prismjs/components/prism-julia';\nimport 'prismjs/components/prism-kotlin';\nimport 'prismjs/components/prism-latex';\nimport 'prismjs/components/prism-lua';\nimport 'prismjs/components/prism-markdown';\nimport 'prismjs/components/prism-matlab';\nimport 'prismjs/components/prism-makefile';\nimport 'prismjs/components/prism-objectivec';\nimport 'prismjs/components/prism-perl';\nimport 'prismjs/components/prism-php';\nimport 'prismjs/components/prism-powershell';\nimport 'prismjs/components/prism-python';\nimport 'prismjs/components/prism-r';\nimport 'prismjs/components/prism-ruby';\nimport 'prismjs/components/prism-rust';\nimport 'prismjs/components/prism-sas';\nimport 'prismjs/components/prism-scala';\nimport 'prismjs/components/prism-scheme';\nimport 'prismjs/components/prism-sql';\nimport 'prismjs/components/prism-stata';\nimport 'prismjs/components/prism-swift';\nimport 'prismjs/components/prism-typescript';\nimport 'prismjs/components/prism-tsx';\nimport 'prismjs/components/prism-vbnet';\nimport 'prismjs/components/prism-yaml';\n\n/**\n * prismjs is UMD and may not expose a namespace when bundled by Vite; the content-manager\n * index preloads it so `window.Prism` is set. Use that when the module import is empty.\n */\nfunction resolvePrism(): typeof PrismModule | undefined {\n if (typeof PrismModule !== 'undefined' && PrismModule?.languages) {\n return PrismModule;\n }\n\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const globalPrism = (window as Window & { Prism?: typeof PrismModule }).Prism;\n return globalPrism;\n}\n\nconst Prism = resolvePrism();\n\ntype BaseRangeCustom = BaseRange & { className: string };\n\nexport const decorateCode = ([node, path]: NodeEntry) => {\n const ranges: BaseRangeCustom[] = [];\n\n // Prism can be undefined when the UMD bundle doesn't expose a namespace and window.Prism\n // isn't set yet (e.g. this chunk ran before the content-manager preload). Skip decoration.\n if (!Prism?.languages) return ranges;\n\n // make sure it is an Slate Element\n if (!Element.isElement(node) || node.type !== 'code') return ranges;\n // transform the Element into a string\n const text = Node.string(node);\n const language = codeLanguages.find((lang) => lang.value === node.language);\n const decorateKey = language?.decorate ?? language?.value;\n\n const selectedLanguage = Prism.languages[decorateKey || 'plaintext'];\n\n // create \"tokens\" with \"prismjs\" and put them in \"ranges\"\n const tokens = Prism.tokenize(text, selectedLanguage);\n let start = 0;\n for (const token of tokens) {\n const length = token.length;\n const end = start + length;\n if (typeof token !== 'string') {\n ranges.push({\n anchor: { path, offset: start },\n focus: { path, offset: end },\n className: `token ${token.type}`,\n });\n }\n start = end;\n }\n\n // these will be found in \"renderLeaf\" in \"leaf\" and their \"className\" will be applied\n return ranges;\n};\n\nconst CodeBlock = styled.pre`\n border-radius: ${({ theme }) => theme.borderRadius};\n background-color: ${({ theme }) => theme.colors.neutral100};\n max-width: 100%;\n overflow: auto;\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n flex-shrink: 1;\n\n & > code {\n font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,\n monospace;\n color: ${({ theme }) => theme.colors.neutral800};\n overflow: auto;\n max-width: 100%;\n }\n`;\n\nconst CodeEditor = (props: RenderElementProps) => {\n const { editor } = useBlocksEditorContext('ImageDialog');\n const editorIsFocused = useFocused();\n const imageIsSelected = useSelected();\n const { formatMessage } = useIntl();\n const [isSelectOpen, setIsSelectOpen] = React.useState(false);\n const shouldDisplayLanguageSelect = (editorIsFocused && imageIsSelected) || isSelectOpen;\n\n return (\n <Box position=\"relative\" width=\"100%\">\n <CodeBlock {...props.attributes}>\n <code>{props.children}</code>\n </CodeBlock>\n {shouldDisplayLanguageSelect && (\n <Box\n position=\"absolute\"\n background=\"neutral0\"\n borderColor=\"neutral150\"\n borderStyle=\"solid\"\n borderWidth=\"0.5px\"\n shadow=\"tableShadow\"\n top=\"100%\"\n marginTop={1}\n right={0}\n padding={1}\n hasRadius\n zIndex={1}\n >\n <SingleSelect\n onChange={(open) => {\n Transforms.setNodes(\n editor,\n { language: open.toString() },\n { match: (node) => !Editor.isEditor(node) && node.type === 'code' }\n );\n }}\n value={(props.element.type === 'code' && props.element.language) || 'plaintext'}\n onOpenChange={(open) => {\n setIsSelectOpen(open);\n\n // Focus the editor again when closing the select so the user can continue typing\n if (!open) {\n ReactEditor.focus(editor);\n }\n }}\n onCloseAutoFocus={(e) => e.preventDefault()}\n aria-label={formatMessage({\n id: 'components.Blocks.blocks.code.languageLabel',\n defaultMessage: 'Select a language',\n })}\n >\n {codeLanguages.map(({ value, label }) => (\n <SingleSelectOption value={value} key={value}>\n {label}\n </SingleSelectOption>\n ))}\n </SingleSelect>\n </Box>\n )}\n </Box>\n );\n};\n\nconst withCode = (editor: Editor) => {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n const pastedText = data.getData('text/plain');\n\n if (pastedText && editor.selection) {\n // Check if we're currently inside a code block\n const codeBlockEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'code',\n });\n\n if (codeBlockEntry) {\n // We're inside a code block, handle the paste specially\n // Replace the selected content with the pasted text, preserving newlines\n Transforms.insertText(editor, pastedText);\n return;\n }\n }\n\n // For non-code blocks, use the default behavior\n insertData(data);\n };\n\n return editor;\n};\n\nconst codeBlocks: Pick<BlocksStore, 'code'> = {\n code: {\n renderElement: (props) => <CodeEditor {...props} />,\n icon: CodeBlockIcon,\n label: {\n id: 'components.Blocks.blocks.code',\n defaultMessage: 'Code block',\n },\n matchNode: (node) => node.type === 'code',\n isInBlocksSelector: true,\n handleConvert(editor) {\n baseHandleConvert<Block<'code'>>(editor, { type: 'code', language: 'plaintext' });\n },\n handleEnterKey(editor) {\n pressEnterTwiceToExit(editor);\n },\n snippets: ['```'],\n plugin: withCode,\n },\n};\n\nexport { codeBlocks };\n"],"names":["resolvePrism","PrismModule","languages","window","undefined","globalPrism","Prism","decorateCode","node","path","ranges","Element","isElement","type","text","Node","string","language","codeLanguages","find","lang","value","decorateKey","decorate","selectedLanguage","tokens","tokenize","start","token","length","end","push","anchor","offset","focus","className","CodeBlock","styled","pre","theme","borderRadius","colors","neutral100","spaces","neutral800","CodeEditor","props","editor","useBlocksEditorContext","editorIsFocused","useFocused","imageIsSelected","useSelected","formatMessage","useIntl","isSelectOpen","setIsSelectOpen","React","useState","shouldDisplayLanguageSelect","_jsxs","Box","position","width","_jsx","attributes","code","children","background","borderColor","borderStyle","borderWidth","shadow","top","marginTop","right","padding","hasRadius","zIndex","SingleSelect","onChange","open","Transforms","setNodes","toString","match","Editor","isEditor","element","onOpenChange","ReactEditor","onCloseAutoFocus","e","preventDefault","aria-label","id","defaultMessage","map","label","SingleSelectOption","withCode","insertData","data","pastedText","getData","selection","codeBlockEntry","above","insertText","codeBlocks","renderElement","icon","CodeBlockIcon","matchNode","isInBlocksSelector","handleConvert","baseHandleConvert","handleEnterKey","pressEnterTwiceToExit","snippets","plugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA;;;AAGC,IACD,SAASA,YAAAA,GAAAA;AACP,IAAA,IAAI,OAAOC,sBAAAA,KAAgB,WAAA,IAAeA,sBAAAA,EAAaC,SAAAA,EAAW;QAChE,OAAOD,sBAAAA;AACT,IAAA;IAEA,IAAI,OAAOE,WAAW,WAAA,EAAa;QACjC,OAAOC,SAAAA;AACT,IAAA;IAEA,MAAMC,WAAAA,GAAc,MAACF,CAAmDG,KAAK;IAC7E,OAAOD,WAAAA;AACT;AAEA,MAAMC,KAAAA,GAAQN,YAAAA,EAAAA;AAIP,MAAMO,YAAAA,GAAe,CAAC,CAACC,MAAMC,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A;YACJC,cAAAA,EAAgB;AAClB,SAAA;AACAiB,QAAAA,SAAAA,EAAW,CAACzG,IAAAA,GAASA,IAAAA,CAAKK,IAAI,KAAK,MAAA;QACnCqG,kBAAAA,EAAoB,IAAA;AACpBC,QAAAA,aAAAA,CAAAA,CAAcpE,MAAM,EAAA;AAClBqE,YAAAA,6BAAAA,CAAiCrE,MAAAA,EAAQ;gBAAElC,IAAAA,EAAM,MAAA;gBAAQI,QAAAA,EAAU;AAAY,aAAA,CAAA;AACjF,QAAA,CAAA;AACAoG,QAAAA,cAAAA,CAAAA,CAAetE,MAAM,EAAA;YACnBuE,8BAAAA,CAAsBvE,MAAAA,CAAAA;AACxB,QAAA,CAAA;QACAwE,QAAAA,EAAU;AAAC,YAAA;AAAM,SAAA;QACjBC,MAAAA,EAAQpB;AACV;AACF;;;;;"}
1
+ {"version":3,"file":"Code.js","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, SingleSelect, SingleSelectOption } from '@strapi/design-system';\nimport { CodeBlock as CodeBlockIcon } from '@strapi/icons';\nimport * as PrismModule from 'prismjs';\nimport { useIntl } from 'react-intl';\nimport { BaseRange, Element, Editor, Node, NodeEntry, Transforms } from 'slate';\nimport { useSelected, type RenderElementProps, useFocused, ReactEditor } from 'slate-react';\nimport { styled } from 'styled-components';\n\nimport { useBlocksEditorContext, type BlocksStore } from '../BlocksEditor';\nimport { codeLanguages } from '../utils/constants';\nimport { baseHandleConvert } from '../utils/conversions';\nimport { pressEnterTwiceToExit } from '../utils/enterKey';\nimport { type Block } from '../utils/types';\n\nimport 'prismjs/themes/prism-solarizedlight.css';\nimport 'prismjs/components/prism-asmatmel';\nimport 'prismjs/components/prism-bash';\nimport 'prismjs/components/prism-basic';\nimport 'prismjs/components/prism-c';\nimport 'prismjs/components/prism-clojure';\nimport 'prismjs/components/prism-cobol';\nimport 'prismjs/components/prism-cpp';\nimport 'prismjs/components/prism-csharp';\nimport 'prismjs/components/prism-dart';\nimport 'prismjs/components/prism-docker';\nimport 'prismjs/components/prism-elixir';\nimport 'prismjs/components/prism-erlang';\nimport 'prismjs/components/prism-fortran';\nimport 'prismjs/components/prism-fsharp';\nimport 'prismjs/components/prism-go';\nimport 'prismjs/components/prism-graphql';\nimport 'prismjs/components/prism-groovy';\nimport 'prismjs/components/prism-haskell';\nimport 'prismjs/components/prism-haxe';\nimport 'prismjs/components/prism-ini';\nimport 'prismjs/components/prism-java';\nimport 'prismjs/components/prism-javascript';\nimport 'prismjs/components/prism-jsx';\nimport 'prismjs/components/prism-json';\nimport 'prismjs/components/prism-julia';\nimport 'prismjs/components/prism-kotlin';\nimport 'prismjs/components/prism-latex';\nimport 'prismjs/components/prism-lua';\nimport 'prismjs/components/prism-markdown';\nimport 'prismjs/components/prism-matlab';\nimport 'prismjs/components/prism-makefile';\nimport 'prismjs/components/prism-objectivec';\nimport 'prismjs/components/prism-perl';\nimport 'prismjs/components/prism-php';\nimport 'prismjs/components/prism-powershell';\nimport 'prismjs/components/prism-python';\nimport 'prismjs/components/prism-r';\nimport 'prismjs/components/prism-ruby';\nimport 'prismjs/components/prism-rust';\nimport 'prismjs/components/prism-sas';\nimport 'prismjs/components/prism-scala';\nimport 'prismjs/components/prism-scheme';\nimport 'prismjs/components/prism-sql';\nimport 'prismjs/components/prism-stata';\nimport 'prismjs/components/prism-swift';\nimport 'prismjs/components/prism-typescript';\nimport 'prismjs/components/prism-tsx';\nimport 'prismjs/components/prism-vbnet';\nimport 'prismjs/components/prism-yaml';\n\n/**\n * prismjs is UMD and may not expose a namespace when bundled by Vite; the content-manager\n * index preloads it so `window.Prism` is set. Use that when the module import is empty.\n */\nfunction resolvePrism(): typeof PrismModule | undefined {\n if (typeof PrismModule !== 'undefined' && PrismModule?.languages) {\n return PrismModule;\n }\n\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const globalPrism = (window as Window & { Prism?: typeof PrismModule }).Prism;\n return globalPrism;\n}\n\nconst Prism = resolvePrism();\n\ntype BaseRangeCustom = BaseRange & { className: string };\n\nexport const decorateCode = ([node, path]: NodeEntry) => {\n const ranges: BaseRangeCustom[] = [];\n\n // Prism can be undefined when the UMD bundle doesn't expose a namespace and window.Prism\n // isn't set yet (e.g. this chunk ran before the content-manager preload). Skip decoration.\n if (!Prism?.languages) return ranges;\n\n // make sure it is an Slate Element\n if (!Element.isElement(node) || node.type !== 'code') return ranges;\n // transform the Element into a string\n const text = Node.string(node);\n const language = codeLanguages.find((lang) => lang.value === node.language);\n const decorateKey = language?.decorate ?? language?.value;\n\n const selectedLanguage = Prism.languages[decorateKey || 'plaintext'];\n\n // create \"tokens\" with \"prismjs\" and put them in \"ranges\"\n const tokens = Prism.tokenize(text, selectedLanguage);\n let start = 0;\n for (const token of tokens) {\n const length = token.length;\n const end = start + length;\n if (typeof token !== 'string') {\n ranges.push({\n anchor: { path, offset: start },\n focus: { path, offset: end },\n className: `token ${token.type}`,\n });\n }\n start = end;\n }\n\n // these will be found in \"renderLeaf\" in \"leaf\" and their \"className\" will be applied\n return ranges;\n};\n\nconst CodeBlock = styled.pre`\n border-radius: ${({ theme }) => theme.borderRadius};\n background-color: ${({ theme }) => theme.colors.neutral100};\n max-width: 100%;\n overflow: auto;\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n flex-shrink: 1;\n\n & > code {\n font-family:\n 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;\n color: ${({ theme }) => theme.colors.neutral800};\n overflow: auto;\n max-width: 100%;\n }\n`;\n\nconst CodeEditor = (props: RenderElementProps) => {\n const { editor } = useBlocksEditorContext('ImageDialog');\n const editorIsFocused = useFocused();\n const imageIsSelected = useSelected();\n const { formatMessage } = useIntl();\n const [isSelectOpen, setIsSelectOpen] = React.useState(false);\n const shouldDisplayLanguageSelect = (editorIsFocused && imageIsSelected) || isSelectOpen;\n\n return (\n <Box position=\"relative\" width=\"100%\">\n <CodeBlock {...props.attributes}>\n <code>{props.children}</code>\n </CodeBlock>\n {shouldDisplayLanguageSelect && (\n <Box\n position=\"absolute\"\n background=\"neutral0\"\n borderColor=\"neutral150\"\n borderStyle=\"solid\"\n borderWidth=\"0.5px\"\n shadow=\"tableShadow\"\n top=\"100%\"\n marginTop={1}\n right={0}\n padding={1}\n hasRadius\n zIndex={1}\n >\n <SingleSelect\n onChange={(open) => {\n Transforms.setNodes(\n editor,\n { language: open.toString() },\n { match: (node) => !Editor.isEditor(node) && node.type === 'code' }\n );\n }}\n value={(props.element.type === 'code' && props.element.language) || 'plaintext'}\n onOpenChange={(open) => {\n setIsSelectOpen(open);\n\n // Focus the editor again when closing the select so the user can continue typing\n if (!open) {\n ReactEditor.focus(editor);\n }\n }}\n onCloseAutoFocus={(e) => e.preventDefault()}\n aria-label={formatMessage({\n id: 'components.Blocks.blocks.code.languageLabel',\n defaultMessage: 'Select a language',\n })}\n >\n {codeLanguages.map(({ value, label }) => (\n <SingleSelectOption value={value} key={value}>\n {label}\n </SingleSelectOption>\n ))}\n </SingleSelect>\n </Box>\n )}\n </Box>\n );\n};\n\nconst withCode = (editor: Editor) => {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n const pastedText = data.getData('text/plain');\n\n if (pastedText && editor.selection) {\n // Check if we're currently inside a code block\n const codeBlockEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'code',\n });\n\n if (codeBlockEntry) {\n // We're inside a code block, handle the paste specially\n // Replace the selected content with the pasted text, preserving newlines\n Transforms.insertText(editor, pastedText);\n return;\n }\n }\n\n // For non-code blocks, use the default behavior\n insertData(data);\n };\n\n return editor;\n};\n\nconst codeBlocks: Pick<BlocksStore, 'code'> = {\n code: {\n renderElement: (props) => <CodeEditor {...props} />,\n icon: CodeBlockIcon,\n label: {\n id: 'components.Blocks.blocks.code',\n defaultMessage: 'Code block',\n },\n matchNode: (node) => node.type === 'code',\n isInBlocksSelector: true,\n handleConvert(editor) {\n baseHandleConvert<Block<'code'>>(editor, { type: 'code', language: 'plaintext' });\n },\n handleEnterKey(editor) {\n pressEnterTwiceToExit(editor);\n },\n snippets: ['```'],\n plugin: withCode,\n },\n};\n\nexport { codeBlocks };\n"],"names":["resolvePrism","PrismModule","languages","window","undefined","globalPrism","Prism","decorateCode","node","path","ranges","Element","isElement","type","text","Node","string","language","codeLanguages","find","lang","value","decorateKey","decorate","selectedLanguage","tokens","tokenize","start","token","length","end","push","anchor","offset","focus","className","CodeBlock","styled","pre","theme","borderRadius","colors","neutral100","spaces","neutral800","CodeEditor","props","editor","useBlocksEditorContext","editorIsFocused","useFocused","imageIsSelected","useSelected","formatMessage","useIntl","isSelectOpen","setIsSelectOpen","React","useState","shouldDisplayLanguageSelect","_jsxs","Box","position","width","_jsx","attributes","code","children","background","borderColor","borderStyle","borderWidth","shadow","top","marginTop","right","padding","hasRadius","zIndex","SingleSelect","onChange","open","Transforms","setNodes","toString","match","Editor","isEditor","element","onOpenChange","ReactEditor","onCloseAutoFocus","e","preventDefault","aria-label","id","defaultMessage","map","label","SingleSelectOption","withCode","insertData","data","pastedText","getData","selection","codeBlockEntry","above","insertText","codeBlocks","renderElement","icon","CodeBlockIcon","matchNode","isInBlocksSelector","handleConvert","baseHandleConvert","handleEnterKey","pressEnterTwiceToExit","snippets","plugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA;;;AAGC,IACD,SAASA,YAAAA,GAAAA;AACP,IAAA,IAAI,OAAOC,sBAAAA,KAAgB,WAAA,IAAeA,sBAAAA,EAAaC,SAAAA,EAAW;QAChE,OAAOD,sBAAAA;AACT,IAAA;IAEA,IAAI,OAAOE,WAAW,WAAA,EAAa;QACjC,OAAOC,SAAAA;AACT,IAAA;IAEA,MAAMC,WAAAA,GAAc,MAACF,CAAmDG,KAAK;IAC7E,OAAOD,WAAAA;AAC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gBAAA,GAAGC;;QAC1CiE,IAAAA,EAAMC,eAAAA;QACNd,KAAAA,EAAO;YACLH,EAAAA,EAAI,+BAAA;YACJC,cAAAA,EAAgB;AAClB,SAAA;AACAiB,QAAAA,SAAAA,EAAW,CAACzG,IAAAA,GAASA,IAAAA,CAAKK,IAAI,KAAK,MAAA;QACnCqG,kBAAAA,EAAoB,IAAA;AACpBC,QAAAA,aAAAA,CAAAA,CAAcpE,MAAM,EAAA;AAClBqE,YAAAA,6BAAAA,CAAiCrE,MAAAA,EAAQ;gBAAElC,IAAAA,EAAM,MAAA;gBAAQI,QAAAA,EAAU;AAAY,aAAA,CAAA;AACjF,QAAA,CAAA;AACAoG,QAAAA,cAAAA,CAAAA,CAAetE,MAAM,EAAA;YACnBuE,8BAAAA,CAAsBvE,MAAAA,CAAAA;AACxB,QAAA,CAAA;QACAwE,QAAAA,EAAU;AAAC,YAAA;AAAM,SAAA;QACjBC,MAAAA,EAAQpB;AACV;AACF;;;;;"}
@@ -121,8 +121,8 @@ const CodeBlock = styled.pre`
121
121
  flex-shrink: 1;
122
122
 
123
123
  & > code {
124
- font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,
125
- monospace;
124
+ font-family:
125
+ 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;
126
126
  color: ${({ theme })=>theme.colors.neutral800};
127
127
  overflow: auto;
128
128
  max-width: 100%;
@@ -1 +1 @@
1
- {"version":3,"file":"Code.mjs","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, SingleSelect, SingleSelectOption } from '@strapi/design-system';\nimport { CodeBlock as CodeBlockIcon } from '@strapi/icons';\nimport * as PrismModule from 'prismjs';\nimport { useIntl } from 'react-intl';\nimport { BaseRange, Element, Editor, Node, NodeEntry, Transforms } from 'slate';\nimport { useSelected, type RenderElementProps, useFocused, ReactEditor } from 'slate-react';\nimport { styled } from 'styled-components';\n\nimport { useBlocksEditorContext, type BlocksStore } from '../BlocksEditor';\nimport { codeLanguages } from '../utils/constants';\nimport { baseHandleConvert } from '../utils/conversions';\nimport { pressEnterTwiceToExit } from '../utils/enterKey';\nimport { type Block } from '../utils/types';\n\nimport 'prismjs/themes/prism-solarizedlight.css';\nimport 'prismjs/components/prism-asmatmel';\nimport 'prismjs/components/prism-bash';\nimport 'prismjs/components/prism-basic';\nimport 'prismjs/components/prism-c';\nimport 'prismjs/components/prism-clojure';\nimport 'prismjs/components/prism-cobol';\nimport 'prismjs/components/prism-cpp';\nimport 'prismjs/components/prism-csharp';\nimport 'prismjs/components/prism-dart';\nimport 'prismjs/components/prism-docker';\nimport 'prismjs/components/prism-elixir';\nimport 'prismjs/components/prism-erlang';\nimport 'prismjs/components/prism-fortran';\nimport 'prismjs/components/prism-fsharp';\nimport 'prismjs/components/prism-go';\nimport 'prismjs/components/prism-graphql';\nimport 'prismjs/components/prism-groovy';\nimport 'prismjs/components/prism-haskell';\nimport 'prismjs/components/prism-haxe';\nimport 'prismjs/components/prism-ini';\nimport 'prismjs/components/prism-java';\nimport 'prismjs/components/prism-javascript';\nimport 'prismjs/components/prism-jsx';\nimport 'prismjs/components/prism-json';\nimport 'prismjs/components/prism-julia';\nimport 'prismjs/components/prism-kotlin';\nimport 'prismjs/components/prism-latex';\nimport 'prismjs/components/prism-lua';\nimport 'prismjs/components/prism-markdown';\nimport 'prismjs/components/prism-matlab';\nimport 'prismjs/components/prism-makefile';\nimport 'prismjs/components/prism-objectivec';\nimport 'prismjs/components/prism-perl';\nimport 'prismjs/components/prism-php';\nimport 'prismjs/components/prism-powershell';\nimport 'prismjs/components/prism-python';\nimport 'prismjs/components/prism-r';\nimport 'prismjs/components/prism-ruby';\nimport 'prismjs/components/prism-rust';\nimport 'prismjs/components/prism-sas';\nimport 'prismjs/components/prism-scala';\nimport 'prismjs/components/prism-scheme';\nimport 'prismjs/components/prism-sql';\nimport 'prismjs/components/prism-stata';\nimport 'prismjs/components/prism-swift';\nimport 'prismjs/components/prism-typescript';\nimport 'prismjs/components/prism-tsx';\nimport 'prismjs/components/prism-vbnet';\nimport 'prismjs/components/prism-yaml';\n\n/**\n * prismjs is UMD and may not expose a namespace when bundled by Vite; the content-manager\n * index preloads it so `window.Prism` is set. Use that when the module import is empty.\n */\nfunction resolvePrism(): typeof PrismModule | undefined {\n if (typeof PrismModule !== 'undefined' && PrismModule?.languages) {\n return PrismModule;\n }\n\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const globalPrism = (window as Window & { Prism?: typeof PrismModule }).Prism;\n return globalPrism;\n}\n\nconst Prism = resolvePrism();\n\ntype BaseRangeCustom = BaseRange & { className: string };\n\nexport const decorateCode = ([node, path]: NodeEntry) => {\n const ranges: BaseRangeCustom[] = [];\n\n // Prism can be undefined when the UMD bundle doesn't expose a namespace and window.Prism\n // isn't set yet (e.g. this chunk ran before the content-manager preload). Skip decoration.\n if (!Prism?.languages) return ranges;\n\n // make sure it is an Slate Element\n if (!Element.isElement(node) || node.type !== 'code') return ranges;\n // transform the Element into a string\n const text = Node.string(node);\n const language = codeLanguages.find((lang) => lang.value === node.language);\n const decorateKey = language?.decorate ?? language?.value;\n\n const selectedLanguage = Prism.languages[decorateKey || 'plaintext'];\n\n // create \"tokens\" with \"prismjs\" and put them in \"ranges\"\n const tokens = Prism.tokenize(text, selectedLanguage);\n let start = 0;\n for (const token of tokens) {\n const length = token.length;\n const end = start + length;\n if (typeof token !== 'string') {\n ranges.push({\n anchor: { path, offset: start },\n focus: { path, offset: end },\n className: `token ${token.type}`,\n });\n }\n start = end;\n }\n\n // these will be found in \"renderLeaf\" in \"leaf\" and their \"className\" will be applied\n return ranges;\n};\n\nconst CodeBlock = styled.pre`\n border-radius: ${({ theme }) => theme.borderRadius};\n background-color: ${({ theme }) => theme.colors.neutral100};\n max-width: 100%;\n overflow: auto;\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n flex-shrink: 1;\n\n & > code {\n font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,\n monospace;\n color: ${({ theme }) => theme.colors.neutral800};\n overflow: auto;\n max-width: 100%;\n }\n`;\n\nconst CodeEditor = (props: RenderElementProps) => {\n const { editor } = useBlocksEditorContext('ImageDialog');\n const editorIsFocused = useFocused();\n const imageIsSelected = useSelected();\n const { formatMessage } = useIntl();\n const [isSelectOpen, setIsSelectOpen] = React.useState(false);\n const shouldDisplayLanguageSelect = (editorIsFocused && imageIsSelected) || isSelectOpen;\n\n return (\n <Box position=\"relative\" width=\"100%\">\n <CodeBlock {...props.attributes}>\n <code>{props.children}</code>\n </CodeBlock>\n {shouldDisplayLanguageSelect && (\n <Box\n position=\"absolute\"\n background=\"neutral0\"\n borderColor=\"neutral150\"\n borderStyle=\"solid\"\n borderWidth=\"0.5px\"\n shadow=\"tableShadow\"\n top=\"100%\"\n marginTop={1}\n right={0}\n padding={1}\n hasRadius\n zIndex={1}\n >\n <SingleSelect\n onChange={(open) => {\n Transforms.setNodes(\n editor,\n { language: open.toString() },\n { match: (node) => !Editor.isEditor(node) && node.type === 'code' }\n );\n }}\n value={(props.element.type === 'code' && props.element.language) || 'plaintext'}\n onOpenChange={(open) => {\n setIsSelectOpen(open);\n\n // Focus the editor again when closing the select so the user can continue typing\n if (!open) {\n ReactEditor.focus(editor);\n }\n }}\n onCloseAutoFocus={(e) => e.preventDefault()}\n aria-label={formatMessage({\n id: 'components.Blocks.blocks.code.languageLabel',\n defaultMessage: 'Select a language',\n })}\n >\n {codeLanguages.map(({ value, label }) => (\n <SingleSelectOption value={value} key={value}>\n {label}\n </SingleSelectOption>\n ))}\n </SingleSelect>\n </Box>\n )}\n </Box>\n );\n};\n\nconst withCode = (editor: Editor) => {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n const pastedText = data.getData('text/plain');\n\n if (pastedText && editor.selection) {\n // Check if we're currently inside a code block\n const codeBlockEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'code',\n });\n\n if (codeBlockEntry) {\n // We're inside a code block, handle the paste specially\n // Replace the selected content with the pasted text, preserving newlines\n Transforms.insertText(editor, pastedText);\n return;\n }\n }\n\n // For non-code blocks, use the default behavior\n insertData(data);\n };\n\n return editor;\n};\n\nconst codeBlocks: Pick<BlocksStore, 'code'> = {\n code: {\n renderElement: (props) => <CodeEditor {...props} />,\n icon: CodeBlockIcon,\n label: {\n id: 'components.Blocks.blocks.code',\n defaultMessage: 'Code block',\n },\n matchNode: (node) => node.type === 'code',\n isInBlocksSelector: true,\n handleConvert(editor) {\n baseHandleConvert<Block<'code'>>(editor, { type: 'code', language: 'plaintext' });\n },\n handleEnterKey(editor) {\n pressEnterTwiceToExit(editor);\n },\n snippets: ['```'],\n plugin: withCode,\n },\n};\n\nexport { codeBlocks };\n"],"names":["resolvePrism","PrismModule","languages","window","undefined","globalPrism","Prism","decorateCode","node","path","ranges","Element","isElement","type","text","Node","string","language","codeLanguages","find","lang","value","decorateKey","decorate","selectedLanguage","tokens","tokenize","start","token","length","end","push","anchor","offset","focus","className","CodeBlock","styled","pre","theme","borderRadius","colors","neutral100","spaces","neutral800","CodeEditor","props","editor","useBlocksEditorContext","editorIsFocused","useFocused","imageIsSelected","useSelected","formatMessage","useIntl","isSelectOpen","setIsSelectOpen","React","useState","shouldDisplayLanguageSelect","_jsxs","Box","position","width","_jsx","attributes","code","children","background","borderColor","borderStyle","borderWidth","shadow","top","marginTop","right","padding","hasRadius","zIndex","SingleSelect","onChange","open","Transforms","setNodes","toString","match","Editor","isEditor","element","onOpenChange","ReactEditor","onCloseAutoFocus","e","preventDefault","aria-label","id","defaultMessage","map","label","SingleSelectOption","withCode","insertData","data","pastedText","getData","selection","codeBlockEntry","above","insertText","codeBlocks","renderElement","icon","CodeBlockIcon","matchNode","isInBlocksSelector","handleConvert","baseHandleConvert","handleEnterKey","pressEnterTwiceToExit","snippets","plugin"],"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A;AAEA,YAAA,IAAI6F,cAAAA,EAAgB;;;gBAGlBxB,UAAAA,CAAW0B,UAAU,CAAC7D,MAAAA,EAAQwD,UAAAA,CAAAA;AAC9B,gBAAA;AACF,YAAA;AACF,QAAA;;QAGAF,UAAAA,CAAWC,IAAAA,CAAAA;AACb,IAAA,CAAA;IAEA,OAAOvD,MAAAA;AACT,CAAA;AAEA,MAAM8D,UAAAA,GAAwC;IAC5C3C,IAAAA,EAAM;QACJ4C,aAAAA,EAAe,CAAChE,sBAAUkB,GAAA,CAACnB,UAAAA,EAAAA;AAAY,gBAAA,GAAGC;;QAC1CiE,IAAAA,EAAMC,WAAAA;QACNd,KAAAA,EAAO;YACLH,EAAAA,EAAI,+BAAA;YACJC,cAAAA,EAAgB;AAClB,SAAA;AACAiB,QAAAA,SAAAA,EAAW,CAACzG,IAAAA,GAASA,IAAAA,CAAKK,IAAI,KAAK,MAAA;QACnCqG,kBAAAA,EAAoB,IAAA;AACpBC,QAAAA,aAAAA,CAAAA,CAAcpE,MAAM,EAAA;AAClBqE,YAAAA,iBAAAA,CAAiCrE,MAAAA,EAAQ;gBAAElC,IAAAA,EAAM,MAAA;gBAAQI,QAAAA,EAAU;AAAY,aAAA,CAAA;AACjF,QAAA,CAAA;AACAoG,QAAAA,cAAAA,CAAAA,CAAetE,MAAM,EAAA;YACnBuE,qBAAAA,CAAsBvE,MAAAA,CAAAA;AACxB,QAAA,CAAA;QACAwE,QAAAA,EAAU;AAAC,YAAA;AAAM,SAAA;QACjBC,MAAAA,EAAQpB;AACV;AACF;;;;"}
1
+ {"version":3,"file":"Code.mjs","sources":["../../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box, SingleSelect, SingleSelectOption } from '@strapi/design-system';\nimport { CodeBlock as CodeBlockIcon } from '@strapi/icons';\nimport * as PrismModule from 'prismjs';\nimport { useIntl } from 'react-intl';\nimport { BaseRange, Element, Editor, Node, NodeEntry, Transforms } from 'slate';\nimport { useSelected, type RenderElementProps, useFocused, ReactEditor } from 'slate-react';\nimport { styled } from 'styled-components';\n\nimport { useBlocksEditorContext, type BlocksStore } from '../BlocksEditor';\nimport { codeLanguages } from '../utils/constants';\nimport { baseHandleConvert } from '../utils/conversions';\nimport { pressEnterTwiceToExit } from '../utils/enterKey';\nimport { type Block } from '../utils/types';\n\nimport 'prismjs/themes/prism-solarizedlight.css';\nimport 'prismjs/components/prism-asmatmel';\nimport 'prismjs/components/prism-bash';\nimport 'prismjs/components/prism-basic';\nimport 'prismjs/components/prism-c';\nimport 'prismjs/components/prism-clojure';\nimport 'prismjs/components/prism-cobol';\nimport 'prismjs/components/prism-cpp';\nimport 'prismjs/components/prism-csharp';\nimport 'prismjs/components/prism-dart';\nimport 'prismjs/components/prism-docker';\nimport 'prismjs/components/prism-elixir';\nimport 'prismjs/components/prism-erlang';\nimport 'prismjs/components/prism-fortran';\nimport 'prismjs/components/prism-fsharp';\nimport 'prismjs/components/prism-go';\nimport 'prismjs/components/prism-graphql';\nimport 'prismjs/components/prism-groovy';\nimport 'prismjs/components/prism-haskell';\nimport 'prismjs/components/prism-haxe';\nimport 'prismjs/components/prism-ini';\nimport 'prismjs/components/prism-java';\nimport 'prismjs/components/prism-javascript';\nimport 'prismjs/components/prism-jsx';\nimport 'prismjs/components/prism-json';\nimport 'prismjs/components/prism-julia';\nimport 'prismjs/components/prism-kotlin';\nimport 'prismjs/components/prism-latex';\nimport 'prismjs/components/prism-lua';\nimport 'prismjs/components/prism-markdown';\nimport 'prismjs/components/prism-matlab';\nimport 'prismjs/components/prism-makefile';\nimport 'prismjs/components/prism-objectivec';\nimport 'prismjs/components/prism-perl';\nimport 'prismjs/components/prism-php';\nimport 'prismjs/components/prism-powershell';\nimport 'prismjs/components/prism-python';\nimport 'prismjs/components/prism-r';\nimport 'prismjs/components/prism-ruby';\nimport 'prismjs/components/prism-rust';\nimport 'prismjs/components/prism-sas';\nimport 'prismjs/components/prism-scala';\nimport 'prismjs/components/prism-scheme';\nimport 'prismjs/components/prism-sql';\nimport 'prismjs/components/prism-stata';\nimport 'prismjs/components/prism-swift';\nimport 'prismjs/components/prism-typescript';\nimport 'prismjs/components/prism-tsx';\nimport 'prismjs/components/prism-vbnet';\nimport 'prismjs/components/prism-yaml';\n\n/**\n * prismjs is UMD and may not expose a namespace when bundled by Vite; the content-manager\n * index preloads it so `window.Prism` is set. Use that when the module import is empty.\n */\nfunction resolvePrism(): typeof PrismModule | undefined {\n if (typeof PrismModule !== 'undefined' && PrismModule?.languages) {\n return PrismModule;\n }\n\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const globalPrism = (window as Window & { Prism?: typeof PrismModule }).Prism;\n return globalPrism;\n}\n\nconst Prism = resolvePrism();\n\ntype BaseRangeCustom = BaseRange & { className: string };\n\nexport const decorateCode = ([node, path]: NodeEntry) => {\n const ranges: BaseRangeCustom[] = [];\n\n // Prism can be undefined when the UMD bundle doesn't expose a namespace and window.Prism\n // isn't set yet (e.g. this chunk ran before the content-manager preload). Skip decoration.\n if (!Prism?.languages) return ranges;\n\n // make sure it is an Slate Element\n if (!Element.isElement(node) || node.type !== 'code') return ranges;\n // transform the Element into a string\n const text = Node.string(node);\n const language = codeLanguages.find((lang) => lang.value === node.language);\n const decorateKey = language?.decorate ?? language?.value;\n\n const selectedLanguage = Prism.languages[decorateKey || 'plaintext'];\n\n // create \"tokens\" with \"prismjs\" and put them in \"ranges\"\n const tokens = Prism.tokenize(text, selectedLanguage);\n let start = 0;\n for (const token of tokens) {\n const length = token.length;\n const end = start + length;\n if (typeof token !== 'string') {\n ranges.push({\n anchor: { path, offset: start },\n focus: { path, offset: end },\n className: `token ${token.type}`,\n });\n }\n start = end;\n }\n\n // these will be found in \"renderLeaf\" in \"leaf\" and their \"className\" will be applied\n return ranges;\n};\n\nconst CodeBlock = styled.pre`\n border-radius: ${({ theme }) => theme.borderRadius};\n background-color: ${({ theme }) => theme.colors.neutral100};\n max-width: 100%;\n overflow: auto;\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n flex-shrink: 1;\n\n & > code {\n font-family:\n 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;\n color: ${({ theme }) => theme.colors.neutral800};\n overflow: auto;\n max-width: 100%;\n }\n`;\n\nconst CodeEditor = (props: RenderElementProps) => {\n const { editor } = useBlocksEditorContext('ImageDialog');\n const editorIsFocused = useFocused();\n const imageIsSelected = useSelected();\n const { formatMessage } = useIntl();\n const [isSelectOpen, setIsSelectOpen] = React.useState(false);\n const shouldDisplayLanguageSelect = (editorIsFocused && imageIsSelected) || isSelectOpen;\n\n return (\n <Box position=\"relative\" width=\"100%\">\n <CodeBlock {...props.attributes}>\n <code>{props.children}</code>\n </CodeBlock>\n {shouldDisplayLanguageSelect && (\n <Box\n position=\"absolute\"\n background=\"neutral0\"\n borderColor=\"neutral150\"\n borderStyle=\"solid\"\n borderWidth=\"0.5px\"\n shadow=\"tableShadow\"\n top=\"100%\"\n marginTop={1}\n right={0}\n padding={1}\n hasRadius\n zIndex={1}\n >\n <SingleSelect\n onChange={(open) => {\n Transforms.setNodes(\n editor,\n { language: open.toString() },\n { match: (node) => !Editor.isEditor(node) && node.type === 'code' }\n );\n }}\n value={(props.element.type === 'code' && props.element.language) || 'plaintext'}\n onOpenChange={(open) => {\n setIsSelectOpen(open);\n\n // Focus the editor again when closing the select so the user can continue typing\n if (!open) {\n ReactEditor.focus(editor);\n }\n }}\n onCloseAutoFocus={(e) => e.preventDefault()}\n aria-label={formatMessage({\n id: 'components.Blocks.blocks.code.languageLabel',\n defaultMessage: 'Select a language',\n })}\n >\n {codeLanguages.map(({ value, label }) => (\n <SingleSelectOption value={value} key={value}>\n {label}\n </SingleSelectOption>\n ))}\n </SingleSelect>\n </Box>\n )}\n </Box>\n );\n};\n\nconst withCode = (editor: Editor) => {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n const pastedText = data.getData('text/plain');\n\n if (pastedText && editor.selection) {\n // Check if we're currently inside a code block\n const codeBlockEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'code',\n });\n\n if (codeBlockEntry) {\n // We're inside a code block, handle the paste specially\n // Replace the selected content with the pasted text, preserving newlines\n Transforms.insertText(editor, pastedText);\n return;\n }\n }\n\n // For non-code blocks, use the default behavior\n insertData(data);\n };\n\n return editor;\n};\n\nconst codeBlocks: Pick<BlocksStore, 'code'> = {\n code: {\n renderElement: (props) => <CodeEditor {...props} />,\n icon: CodeBlockIcon,\n label: {\n id: 'components.Blocks.blocks.code',\n defaultMessage: 'Code block',\n },\n matchNode: (node) => node.type === 'code',\n isInBlocksSelector: true,\n handleConvert(editor) {\n baseHandleConvert<Block<'code'>>(editor, { type: 'code', language: 'plaintext' });\n },\n handleEnterKey(editor) {\n pressEnterTwiceToExit(editor);\n },\n snippets: ['```'],\n plugin: withCode,\n },\n};\n\nexport { codeBlocks };\n"],"names":["resolvePrism","PrismModule","languages","window","undefined","globalPrism","Prism","decorateCode","node","path","ranges","Element","isElement","type","text","Node","string","language","codeLanguages","find","lang","value","decorateKey","decorate","selectedLanguage","tokens","tokenize","start","token","length","end","push","anchor","offset","focus","className","CodeBlock","styled","pre","theme","borderRadius","colors","neutral100","spaces","neutral800","CodeEditor","props","editor","useBlocksEditorContext","editorIsFocused","useFocused","imageIsSelected","useSelected","formatMessage","useIntl","isSelectOpen","setIsSelectOpen","React","useState","shouldDisplayLanguageSelect","_jsxs","Box","position","width","_jsx","attributes","code","children","background","borderColor","borderStyle","borderWidth","shadow","top","marginTop","right","padding","hasRadius","zIndex","SingleSelect","onChange","open","Transforms","setNodes","toString","match","Editor","isEditor","element","onOpenChange","ReactEditor","onCloseAutoFocus","e","preventDefault","aria-label","id","defaultMessage","map","label","SingleSelectOption","withCode","insertData","data","pastedText","getData","selection","codeBlockEntry","above","insertText","codeBlocks","renderElement","icon","CodeBlockIcon","matchNode","isInBlocksSelector","handleConvert","baseH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,IAAAA,CAAKK,IAAI,KAAK;AAC3D,aAAA,CAAA;AAEA,YAAA,IAAI6F,cAAAA,EAAgB;;;gBAGlBxB,UAAAA,CAAW0B,UAAU,CAAC7D,MAAAA,EAAQwD,UAAAA,CAAAA;AAC9B,gBAAA;AACF,YAAA;AACF,QAAA;;QAGAF,UAAAA,CAAWC,IAAAA,CAAAA;AACb,IAAA,CAAA;IAEA,OAAOvD,MAAAA;AACT,CAAA;AAEA,MAAM8D,UAAAA,GAAwC;IAC5C3C,IAAAA,EAAM;QACJ4C,aAAAA,EAAe,CAAChE,sBAAUkB,GAAA,CAACnB,UAAAA,EAAAA;AAAY,gBAAA,GAAGC;;QAC1CiE,IAAAA,EAAMC,WAAAA;QACNd,KAAAA,EAAO;YACLH,EAAAA,EAAI,+BAAA;YACJC,cAAAA,EAAgB;AAClB,SAAA;AACAiB,QAAAA,SAAAA,EAAW,CAACzG,IAAAA,GAASA,IAAAA,CAAKK,IAAI,KAAK,MAAA;QACnCqG,kBAAAA,EAAoB,IAAA;AACpBC,QAAAA,aAAAA,CAAAA,CAAcpE,MAAM,EAAA;AAClBqE,YAAAA,iBAAAA,CAAiCrE,MAAAA,EAAQ;gBAAElC,IAAAA,EAAM,MAAA;gBAAQI,QAAAA,EAAU;AAAY,aAAA,CAAA;AACjF,QAAA,CAAA;AACAoG,QAAAA,cAAAA,CAAAA,CAAetE,MAAM,EAAA;YACnBuE,qBAAAA,CAAsBvE,MAAAA,CAAAA;AACxB,QAAA,CAAA;QACAwE,QAAAA,EAAU;AAAC,YAAA;AAAM,SAAA;QACjBC,MAAAA,EAAQpB;AACV;AACF;;;;"}
@@ -35,8 +35,8 @@ const InlineCode = styledComponents.styled.code`
35
35
  background-color: ${({ theme })=>theme.colors.neutral150};
36
36
  border-radius: ${({ theme })=>theme.borderRadius};
37
37
  padding: ${({ theme })=>`0 ${theme.spaces[2]}`};
38
- font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,
39
- monospace;
38
+ font-family:
39
+ 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;
40
40
  color: inherit;
41
41
  `;
42
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Modifiers.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Modifiers.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Typography, TypographyComponent } from '@strapi/design-system';\nimport { Bold, Italic, Underline, StrikeThrough, Code } from '@strapi/icons';\nimport { type MessageDescriptor } from 'react-intl';\nimport { Editor, type NodeEntry, Range, Text, Transforms } from 'slate';\nimport { styled, css } from 'styled-components';\n\nconst stylesToInherit = css`\n font-size: inherit;\n color: inherit;\n line-height: inherit;\n`;\n\nconst BoldText = styled<TypographyComponent>(Typography).attrs({ fontWeight: 'bold' })`\n ${stylesToInherit}\n`;\n\nconst ItalicText = styled<TypographyComponent>(Typography)`\n font-style: italic;\n ${stylesToInherit}\n`;\n\nconst UnderlineText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'underline',\n})`\n ${stylesToInherit}\n`;\n\nconst StrikeThroughText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'line-through',\n})`\n ${stylesToInherit}\n`;\n\nconst InlineCode = styled.code`\n background-color: ${({ theme }) => theme.colors.neutral150};\n border-radius: ${({ theme }) => theme.borderRadius};\n padding: ${({ theme }) => `0 ${theme.spaces[2]}`};\n font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,\n monospace;\n color: inherit;\n`;\n\ntype ModifierKey = Exclude<keyof Text, 'type' | 'text'>;\n\ntype ModifiersStore = {\n [K in ModifierKey]: {\n icon: React.ComponentType;\n isValidEventKey: (event: React.KeyboardEvent<HTMLElement>) => boolean;\n label: MessageDescriptor;\n checkIsActive: (editor: Editor) => boolean;\n handleToggle: (editor: Editor) => void;\n renderLeaf: (children: React.JSX.Element | string) => React.JSX.Element;\n };\n};\n\n/**\n * The default handler for checking if a modifier is active\n */\nconst baseCheckIsActive = (editor: Editor, name: ModifierKey) => {\n const { selection } = editor;\n\n // If there's no selection, fall back to Slate's current marks.\n // (This is what will be applied to newly inserted text.)\n if (!selection) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n // Collapsed selection (caret): current marks are reliable.\n if (Range.isCollapsed(selection)) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n /**\n * Expanded selection: derive \"active\" state from the selected text nodes.\n *\n * This avoids a common mobile edge case where the selection focus can sit just\n * outside the formatted span (so relying on caret/focus marks would be wrong).\n *\n * Additionally, mobile selection often includes an extra whitespace character at\n * the edge (e.g. the trailing space after a word). We ignore whitespace-only\n * portions when computing active state so the toolbar reflects the intended\n * formatted text.\n */\n const range = Editor.unhangRange(editor, selection);\n const selectedTextEntries = Array.from(\n Editor.nodes(editor, { at: range, match: Text.isText, mode: 'all' })\n ) as NodeEntry<Text>[];\n\n if (selectedTextEntries.length === 0) return false;\n\n const summary = selectedTextEntries.reduce(\n (acc, [node, path]) => {\n const nodeRange = Editor.range(editor, path);\n const intersection = Range.intersection(range, nodeRange);\n\n if (!intersection) {\n return acc;\n }\n\n const start = Math.min(intersection.anchor.offset, intersection.focus.offset);\n const end = Math.max(intersection.anchor.offset, intersection.focus.offset);\n const selectedSlice = node.text.slice(start, end);\n\n // Ignore whitespace-only slices (common in mobile selection boundaries).\n if (selectedSlice.trim().length === 0) {\n return acc;\n }\n\n return {\n hasNonWhitespaceSelection: true,\n isEveryRelevantNodeMarked: acc.isEveryRelevantNodeMarked && Boolean(node[name]),\n };\n },\n { hasNonWhitespaceSelection: false, isEveryRelevantNodeMarked: true }\n );\n\n return summary.hasNonWhitespaceSelection && summary.isEveryRelevantNodeMarked;\n};\n\n/**\n * The default handler for toggling a modifier\n */\nconst baseHandleToggle = (editor: Editor, name: ModifierKey) => {\n // If there is no selection, set selection to the end of line\n if (!editor.selection) {\n const endOfEditor = Editor.end(editor, []);\n Transforms.select(editor, endOfEditor);\n }\n\n // Toggle the modifier\n if (baseCheckIsActive(editor, name)) {\n Editor.removeMark(editor, name);\n } else {\n Editor.addMark(editor, name, true);\n }\n};\n\nconst modifiers: ModifiersStore = {\n bold: {\n icon: Bold,\n isValidEventKey: (event) => event.key === 'b',\n label: { id: 'components.Blocks.modifiers.bold', defaultMessage: 'Bold' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'bold'),\n handleToggle: (editor) => baseHandleToggle(editor, 'bold'),\n renderLeaf: (children) => <BoldText>{children}</BoldText>,\n },\n italic: {\n icon: Italic,\n isValidEventKey: (event) => event.key === 'i',\n label: { id: 'components.Blocks.modifiers.italic', defaultMessage: 'Italic' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'italic'),\n handleToggle: (editor) => baseHandleToggle(editor, 'italic'),\n renderLeaf: (children) => <ItalicText>{children}</ItalicText>,\n },\n underline: {\n icon: Underline,\n isValidEventKey: (event) => event.key === 'u',\n label: { id: 'components.Blocks.modifiers.underline', defaultMessage: 'Underline' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'underline'),\n handleToggle: (editor) => baseHandleToggle(editor, 'underline'),\n renderLeaf: (children) => <UnderlineText>{children}</UnderlineText>,\n },\n strikethrough: {\n icon: StrikeThrough,\n isValidEventKey: (event) => event.key === 'S' && event.shiftKey,\n label: { id: 'components.Blocks.modifiers.strikethrough', defaultMessage: 'Strikethrough' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'strikethrough'),\n handleToggle: (editor) => baseHandleToggle(editor, 'strikethrough'),\n renderLeaf: (children) => <StrikeThroughText>{children}</StrikeThroughText>,\n },\n code: {\n icon: Code,\n isValidEventKey: (event) => event.key === 'e',\n label: { id: 'components.Blocks.modifiers.code', defaultMessage: 'Inline code' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'code'),\n handleToggle: (editor) => baseHandleToggle(editor, 'code'),\n renderLeaf: (children) => <InlineCode>{children}</InlineCode>,\n },\n};\n\nexport { type ModifiersStore, modifiers };\n"],"names":["stylesToInherit","css","BoldText","styled","Typography","attrs","fontWeight","ItalicText","UnderlineText","textDecoration","StrikeThroughText","InlineCode","code","theme","colors","neutral150","borderRadius","spaces","baseCheckIsActive","editor","name","selection","marks","Editor","Boolean","Range","isCollapsed","range","unhangRange","selectedTextEntries","Array","from","nodes","at","match","Text","isText","mode","length","summary","reduce","acc","node","path","nodeRange","intersection","start","Math","min","anchor","offset","focus","end","max","selectedSlice","text","slice","trim","hasNonWhitespaceSelection","isEveryRelevantNodeMarked","baseHandleToggle","endOfEditor","Transforms","select","removeMark","addMark","modifiers","bold","icon","Bold","isValidEventKey","event","key","label","id","defaultMessage","checkIsActive","handleToggle","renderLeaf","children","_jsx","italic","Italic","underline","Underline","strikethrough","StrikeThrough","shiftKey","Code"],"mappings":";;;;;;;;;AAQA,MAAMA,eAAAA,GAAkBC,oBAAG;;;;AAI3B,CAAC;AAED,MAAMC,QAAAA,GAAWC,uBAAAA,CAA4BC,uBAAAA,CAAAA,CAAYC,KAAK,CAAC;IAAEC,UAAAA,EAAY;AAAO,CAAA,CAAE;AACpF,EAAA,EAAEN,eAAAA;AACJ,CAAC;AAED,MAAMO,UAAAA,GAAaJ,uBAAAA,CAA4BC,uBAAAA,CAAW;;AAExD,EAAA,EAAEJ,eAAAA;AACJ,CAAC;AAED,MAAMQ,aAAAA,GAAgBL,uBAAAA,CAA4BC,uBAAAA,CAAAA,CAAYC,KAAK,CAAC;IAClEI,cAAAA,EAAgB;AAClB,CAAA,CAAE;AACA,EAAA,EAAET,eAAAA;AACJ,CAAC;AAED,MAAMU,iBAAAA,GAAoBP,uBAAAA,CAA4BC,uBAAAA,CAAAA,CAAYC,KAAK,CAAC;IACtEI,cAAAA,EAAgB;AAClB,CAAA,CAAE;AACA,EAAA,EAAET,eAAAA;AACJ,CAAC;AAED,MAAMW,UAAAA,GAAaR,uBAAAA,CAAOS,IAAI;oBACV,EAAE,CAAC,EAAEC,KAAK,EA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AAAA,EAAM;QACJwD,IAAAA,EAAMoB,UAAAA;AACNlB,QAAAA,eAAAA,EAAiB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,GAAG,KAAK,GAAA;QAC1CC,KAAAA,EAAO;YAAEC,EAAAA,EAAI,kCAAA;YAAoCC,cAAAA,EAAgB;AAAc,SAAA;QAC/EC,aAAAA,EAAe,CAACzD,MAAAA,GAAWD,iBAAAA,CAAkBC,MAAAA,EAAQ,MAAA,CAAA;QACrD0D,YAAAA,EAAc,CAAC1D,MAAAA,GAAWyC,gBAAAA,CAAiBzC,MAAAA,EAAQ,MAAA,CAAA;QACnD2D,UAAAA,EAAY,CAACC,yBAAaC,cAAA,CAACrE,UAAAA,EAAAA;AAAYoE,gBAAAA,QAAAA,EAAAA;;AACzC;AACF;;;;"}
1
+ {"version":3,"file":"Modifiers.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Modifiers.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Typography, TypographyComponent } from '@strapi/design-system';\nimport { Bold, Italic, Underline, StrikeThrough, Code } from '@strapi/icons';\nimport { type MessageDescriptor } from 'react-intl';\nimport { Editor, type NodeEntry, Range, Text, Transforms } from 'slate';\nimport { styled, css } from 'styled-components';\n\nconst stylesToInherit = css`\n font-size: inherit;\n color: inherit;\n line-height: inherit;\n`;\n\nconst BoldText = styled<TypographyComponent>(Typography).attrs({ fontWeight: 'bold' })`\n ${stylesToInherit}\n`;\n\nconst ItalicText = styled<TypographyComponent>(Typography)`\n font-style: italic;\n ${stylesToInherit}\n`;\n\nconst UnderlineText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'underline',\n})`\n ${stylesToInherit}\n`;\n\nconst StrikeThroughText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'line-through',\n})`\n ${stylesToInherit}\n`;\n\nconst InlineCode = styled.code`\n background-color: ${({ theme }) => theme.colors.neutral150};\n border-radius: ${({ theme }) => theme.borderRadius};\n padding: ${({ theme }) => `0 ${theme.spaces[2]}`};\n font-family:\n 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;\n color: inherit;\n`;\n\ntype ModifierKey = Exclude<keyof Text, 'type' | 'text'>;\n\ntype ModifiersStore = {\n [K in ModifierKey]: {\n icon: React.ComponentType;\n isValidEventKey: (event: React.KeyboardEvent<HTMLElement>) => boolean;\n label: MessageDescriptor;\n checkIsActive: (editor: Editor) => boolean;\n handleToggle: (editor: Editor) => void;\n renderLeaf: (children: React.JSX.Element | string) => React.JSX.Element;\n };\n};\n\n/**\n * The default handler for checking if a modifier is active\n */\nconst baseCheckIsActive = (editor: Editor, name: ModifierKey) => {\n const { selection } = editor;\n\n // If there's no selection, fall back to Slate's current marks.\n // (This is what will be applied to newly inserted text.)\n if (!selection) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n // Collapsed selection (caret): current marks are reliable.\n if (Range.isCollapsed(selection)) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n /**\n * Expanded selection: derive \"active\" state from the selected text nodes.\n *\n * This avoids a common mobile edge case where the selection focus can sit just\n * outside the formatted span (so relying on caret/focus marks would be wrong).\n *\n * Additionally, mobile selection often includes an extra whitespace character at\n * the edge (e.g. the trailing space after a word). We ignore whitespace-only\n * portions when computing active state so the toolbar reflects the intended\n * formatted text.\n */\n const range = Editor.unhangRange(editor, selection);\n const selectedTextEntries = Array.from(\n Editor.nodes(editor, { at: range, match: Text.isText, mode: 'all' })\n ) as NodeEntry<Text>[];\n\n if (selectedTextEntries.length === 0) return false;\n\n const summary = selectedTextEntries.reduce(\n (acc, [node, path]) => {\n const nodeRange = Editor.range(editor, path);\n const intersection = Range.intersection(range, nodeRange);\n\n if (!intersection) {\n return acc;\n }\n\n const start = Math.min(intersection.anchor.offset, intersection.focus.offset);\n const end = Math.max(intersection.anchor.offset, intersection.focus.offset);\n const selectedSlice = node.text.slice(start, end);\n\n // Ignore whitespace-only slices (common in mobile selection boundaries).\n if (selectedSlice.trim().length === 0) {\n return acc;\n }\n\n return {\n hasNonWhitespaceSelection: true,\n isEveryRelevantNodeMarked: acc.isEveryRelevantNodeMarked && Boolean(node[name]),\n };\n },\n { hasNonWhitespaceSelection: false, isEveryRelevantNodeMarked: true }\n );\n\n return summary.hasNonWhitespaceSelection && summary.isEveryRelevantNodeMarked;\n};\n\n/**\n * The default handler for toggling a modifier\n */\nconst baseHandleToggle = (editor: Editor, name: ModifierKey) => {\n // If there is no selection, set selection to the end of line\n if (!editor.selection) {\n const endOfEditor = Editor.end(editor, []);\n Transforms.select(editor, endOfEditor);\n }\n\n // Toggle the modifier\n if (baseCheckIsActive(editor, name)) {\n Editor.removeMark(editor, name);\n } else {\n Editor.addMark(editor, name, true);\n }\n};\n\nconst modifiers: ModifiersStore = {\n bold: {\n icon: Bold,\n isValidEventKey: (event) => event.key === 'b',\n label: { id: 'components.Blocks.modifiers.bold', defaultMessage: 'Bold' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'bold'),\n handleToggle: (editor) => baseHandleToggle(editor, 'bold'),\n renderLeaf: (children) => <BoldText>{children}</BoldText>,\n },\n italic: {\n icon: Italic,\n isValidEventKey: (event) => event.key === 'i',\n label: { id: 'components.Blocks.modifiers.italic', defaultMessage: 'Italic' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'italic'),\n handleToggle: (editor) => baseHandleToggle(editor, 'italic'),\n renderLeaf: (children) => <ItalicText>{children}</ItalicText>,\n },\n underline: {\n icon: Underline,\n isValidEventKey: (event) => event.key === 'u',\n label: { id: 'components.Blocks.modifiers.underline', defaultMessage: 'Underline' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'underline'),\n handleToggle: (editor) => baseHandleToggle(editor, 'underline'),\n renderLeaf: (children) => <UnderlineText>{children}</UnderlineText>,\n },\n strikethrough: {\n icon: StrikeThrough,\n isValidEventKey: (event) => event.key === 'S' && event.shiftKey,\n label: { id: 'components.Blocks.modifiers.strikethrough', defaultMessage: 'Strikethrough' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'strikethrough'),\n handleToggle: (editor) => baseHandleToggle(editor, 'strikethrough'),\n renderLeaf: (children) => <StrikeThroughText>{children}</StrikeThroughText>,\n },\n code: {\n icon: Code,\n isValidEventKey: (event) => event.key === 'e',\n label: { id: 'components.Blocks.modifiers.code', defaultMessage: 'Inline code' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'code'),\n handleToggle: (editor) => baseHandleToggle(editor, 'code'),\n renderLeaf: (children) => <InlineCode>{children}</InlineCode>,\n },\n};\n\nexport { type ModifiersStore, modifiers };\n"],"names":["stylesToInherit","css","BoldText","styled","Typography","attrs","fontWeight","ItalicText","UnderlineText","textDecoration","StrikeThroughText","InlineCode","code","theme","colors","neutral150","borderRadius","spaces","baseCheckIsActive","editor","name","selection","marks","Editor","Boolean","Range","isCollapsed","range","unhangRange","selectedTextEntries","Array","from","nodes","at","match","Text","isText","mode","length","summary","reduce","acc","node","path","nodeRange","intersection","start","Math","min","anchor","offset","focus","end","max","selectedSlice","text","slice","trim","hasNonWhitespaceSelection","isEveryRelevantNodeMarked","baseHandleToggle","endOfEditor","Transforms","select","removeMark","addMark","modifiers","bold","icon","Bold","isValidEventKey","event","key","label","id","defaultMessage","checkIsActive","handleToggle","renderLeaf","children","_jsx","italic","Italic","underline","Underline","strikethrough","StrikeThrough","shiftKey","Code"],"mappings":";;;;;;;;;AAQA,MAAMA,eAAAA,GAAkBC,oBAAG;;;;AAI3B,CAAC;AAED,MAAMC,QAAAA,GAAWC,uBAAAA,CAA4BC,uBAAAA,CAAAA,CAAYC,KAAK,CAAC;IAAEC,UAAAA,EAAY;AAAO,CAAA,CAAE;AACpF,EAAA,EAAEN,eAAAA;AACJ,CAAC;AAED,MAAMO,UAAAA,GAAaJ,uBAAAA,CAA4BC,uBAAAA,CAAW;;AAExD,EAAA,EAAEJ,eAAAA;AACJ,CAAC;AAED,MAAMQ,aAAAA,GAAgBL,uBAA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;YAAEC,EAAAA,EAAI,2CAAA;YAA6CC,cAAAA,EAAgB;AAAgB,SAAA;QAC1FC,aAAAA,EAAe,CAACzD,MAAAA,GAAWD,iBAAAA,CAAkBC,MAAAA,EAAQ,eAAA,CAAA;QACrD0D,YAAAA,EAAc,CAAC1D,MAAAA,GAAWyC,gBAAAA,CAAiBzC,MAAAA,EAAQ,eAAA,CAAA;QACnD2D,UAAAA,EAAY,CAACC,yBAAaC,cAAA,CAACtE,iBAAAA,EAAAA;AAAmBqE,gBAAAA,QAAAA,EAAAA;;AAChD,KAAA;IACAnE,IAAAA,EAAM;QACJwD,IAAAA,EAAMoB,UAAAA;AACNlB,QAAAA,eAAAA,EAAiB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,GAAG,KAAK,GAAA;QAC1CC,KAAAA,EAAO;YAAEC,EAAAA,EAAI,kCAAA;YAAoCC,cAAAA,EAAgB;AAAc,SAAA;QAC/EC,aAAAA,EAAe,CAACzD,MAAAA,GAAWD,iBAAAA,CAAkBC,MAAAA,EAAQ,MAAA,CAAA;QACrD0D,YAAAA,EAAc,CAAC1D,MAAAA,GAAWyC,gBAAAA,CAAiBzC,MAAAA,EAAQ,MAAA,CAAA;QACnD2D,UAAAA,EAAY,CAACC,yBAAaC,cAAA,CAACrE,UAAAA,EAAAA;AAAYoE,gBAAAA,QAAAA,EAAAA;;AACzC;AACF;;;;"}
@@ -33,8 +33,8 @@ const InlineCode = styled.code`
33
33
  background-color: ${({ theme })=>theme.colors.neutral150};
34
34
  border-radius: ${({ theme })=>theme.borderRadius};
35
35
  padding: ${({ theme })=>`0 ${theme.spaces[2]}`};
36
- font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,
37
- monospace;
36
+ font-family:
37
+ 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;
38
38
  color: inherit;
39
39
  `;
40
40
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Modifiers.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Modifiers.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Typography, TypographyComponent } from '@strapi/design-system';\nimport { Bold, Italic, Underline, StrikeThrough, Code } from '@strapi/icons';\nimport { type MessageDescriptor } from 'react-intl';\nimport { Editor, type NodeEntry, Range, Text, Transforms } from 'slate';\nimport { styled, css } from 'styled-components';\n\nconst stylesToInherit = css`\n font-size: inherit;\n color: inherit;\n line-height: inherit;\n`;\n\nconst BoldText = styled<TypographyComponent>(Typography).attrs({ fontWeight: 'bold' })`\n ${stylesToInherit}\n`;\n\nconst ItalicText = styled<TypographyComponent>(Typography)`\n font-style: italic;\n ${stylesToInherit}\n`;\n\nconst UnderlineText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'underline',\n})`\n ${stylesToInherit}\n`;\n\nconst StrikeThroughText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'line-through',\n})`\n ${stylesToInherit}\n`;\n\nconst InlineCode = styled.code`\n background-color: ${({ theme }) => theme.colors.neutral150};\n border-radius: ${({ theme }) => theme.borderRadius};\n padding: ${({ theme }) => `0 ${theme.spaces[2]}`};\n font-family: 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas,\n monospace;\n color: inherit;\n`;\n\ntype ModifierKey = Exclude<keyof Text, 'type' | 'text'>;\n\ntype ModifiersStore = {\n [K in ModifierKey]: {\n icon: React.ComponentType;\n isValidEventKey: (event: React.KeyboardEvent<HTMLElement>) => boolean;\n label: MessageDescriptor;\n checkIsActive: (editor: Editor) => boolean;\n handleToggle: (editor: Editor) => void;\n renderLeaf: (children: React.JSX.Element | string) => React.JSX.Element;\n };\n};\n\n/**\n * The default handler for checking if a modifier is active\n */\nconst baseCheckIsActive = (editor: Editor, name: ModifierKey) => {\n const { selection } = editor;\n\n // If there's no selection, fall back to Slate's current marks.\n // (This is what will be applied to newly inserted text.)\n if (!selection) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n // Collapsed selection (caret): current marks are reliable.\n if (Range.isCollapsed(selection)) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n /**\n * Expanded selection: derive \"active\" state from the selected text nodes.\n *\n * This avoids a common mobile edge case where the selection focus can sit just\n * outside the formatted span (so relying on caret/focus marks would be wrong).\n *\n * Additionally, mobile selection often includes an extra whitespace character at\n * the edge (e.g. the trailing space after a word). We ignore whitespace-only\n * portions when computing active state so the toolbar reflects the intended\n * formatted text.\n */\n const range = Editor.unhangRange(editor, selection);\n const selectedTextEntries = Array.from(\n Editor.nodes(editor, { at: range, match: Text.isText, mode: 'all' })\n ) as NodeEntry<Text>[];\n\n if (selectedTextEntries.length === 0) return false;\n\n const summary = selectedTextEntries.reduce(\n (acc, [node, path]) => {\n const nodeRange = Editor.range(editor, path);\n const intersection = Range.intersection(range, nodeRange);\n\n if (!intersection) {\n return acc;\n }\n\n const start = Math.min(intersection.anchor.offset, intersection.focus.offset);\n const end = Math.max(intersection.anchor.offset, intersection.focus.offset);\n const selectedSlice = node.text.slice(start, end);\n\n // Ignore whitespace-only slices (common in mobile selection boundaries).\n if (selectedSlice.trim().length === 0) {\n return acc;\n }\n\n return {\n hasNonWhitespaceSelection: true,\n isEveryRelevantNodeMarked: acc.isEveryRelevantNodeMarked && Boolean(node[name]),\n };\n },\n { hasNonWhitespaceSelection: false, isEveryRelevantNodeMarked: true }\n );\n\n return summary.hasNonWhitespaceSelection && summary.isEveryRelevantNodeMarked;\n};\n\n/**\n * The default handler for toggling a modifier\n */\nconst baseHandleToggle = (editor: Editor, name: ModifierKey) => {\n // If there is no selection, set selection to the end of line\n if (!editor.selection) {\n const endOfEditor = Editor.end(editor, []);\n Transforms.select(editor, endOfEditor);\n }\n\n // Toggle the modifier\n if (baseCheckIsActive(editor, name)) {\n Editor.removeMark(editor, name);\n } else {\n Editor.addMark(editor, name, true);\n }\n};\n\nconst modifiers: ModifiersStore = {\n bold: {\n icon: Bold,\n isValidEventKey: (event) => event.key === 'b',\n label: { id: 'components.Blocks.modifiers.bold', defaultMessage: 'Bold' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'bold'),\n handleToggle: (editor) => baseHandleToggle(editor, 'bold'),\n renderLeaf: (children) => <BoldText>{children}</BoldText>,\n },\n italic: {\n icon: Italic,\n isValidEventKey: (event) => event.key === 'i',\n label: { id: 'components.Blocks.modifiers.italic', defaultMessage: 'Italic' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'italic'),\n handleToggle: (editor) => baseHandleToggle(editor, 'italic'),\n renderLeaf: (children) => <ItalicText>{children}</ItalicText>,\n },\n underline: {\n icon: Underline,\n isValidEventKey: (event) => event.key === 'u',\n label: { id: 'components.Blocks.modifiers.underline', defaultMessage: 'Underline' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'underline'),\n handleToggle: (editor) => baseHandleToggle(editor, 'underline'),\n renderLeaf: (children) => <UnderlineText>{children}</UnderlineText>,\n },\n strikethrough: {\n icon: StrikeThrough,\n isValidEventKey: (event) => event.key === 'S' && event.shiftKey,\n label: { id: 'components.Blocks.modifiers.strikethrough', defaultMessage: 'Strikethrough' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'strikethrough'),\n handleToggle: (editor) => baseHandleToggle(editor, 'strikethrough'),\n renderLeaf: (children) => <StrikeThroughText>{children}</StrikeThroughText>,\n },\n code: {\n icon: Code,\n isValidEventKey: (event) => event.key === 'e',\n label: { id: 'components.Blocks.modifiers.code', defaultMessage: 'Inline code' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'code'),\n handleToggle: (editor) => baseHandleToggle(editor, 'code'),\n renderLeaf: (children) => <InlineCode>{children}</InlineCode>,\n },\n};\n\nexport { type ModifiersStore, modifiers };\n"],"names":["stylesToInherit","css","BoldText","styled","Typography","attrs","fontWeight","ItalicText","UnderlineText","textDecoration","StrikeThroughText","InlineCode","code","theme","colors","neutral150","borderRadius","spaces","baseCheckIsActive","editor","name","selection","marks","Editor","Boolean","Range","isCollapsed","range","unhangRange","selectedTextEntries","Array","from","nodes","at","match","Text","isText","mode","length","summary","reduce","acc","node","path","nodeRange","intersection","start","Math","min","anchor","offset","focus","end","max","selectedSlice","text","slice","trim","hasNonWhitespaceSelection","isEveryRelevantNodeMarked","baseHandleToggle","endOfEditor","Transforms","select","removeMark","addMark","modifiers","bold","icon","Bold","isValidEventKey","event","key","label","id","defaultMessage","checkIsActive","handleToggle","renderLeaf","children","_jsx","italic","Italic","underline","Underline","strikethrough","StrikeThrough","shiftKey","Code"],"mappings":";;;;;;;AAQA,MAAMA,eAAAA,GAAkBC,GAAG;;;;AAI3B,CAAC;AAED,MAAMC,QAAAA,GAAWC,MAAAA,CAA4BC,UAAAA,CAAAA,CAAYC,KAAK,CAAC;IAAEC,UAAAA,EAAY;AAAO,CAAA,CAAE;AACpF,EAAA,EAAEN,eAAAA;AACJ,CAAC;AAED,MAAMO,UAAAA,GAAaJ,MAAAA,CAA4BC,UAAAA,CAAW;;AAExD,EAAA,EAAEJ,eAAAA;AACJ,CAAC;AAED,MAAMQ,aAAAA,GAAgBL,MAAAA,CAA4BC,UAAAA,CAAAA,CAAYC,KAAK,CAAC;IAClEI,cAAAA,EAAgB;AAClB,CAAA,CAAE;AACA,EAAA,EAAET,eAAAA;AACJ,CAAC;AAED,MAAMU,iBAAAA,GAAoBP,MAAAA,CAA4BC,UAAAA,CAAAA,CAAYC,KAAK,CAAC;IACtEI,cAAAA,EAAgB;AAClB,CAAA,CAAE;AACA,EAAA,EAAET,eAAAA;AACJ,CAAC;AAED,MAAMW,UAAAA,GAAaR,MAAAA,CAAOS,IAAI;oBACV,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAACC,UAAU,CAAC;AAC5C,iBAAA,EAAE,CAAC,EAAEF,KAAK,EAAE,GAAKA,KAAAA,CAAMG,YAAY,CAAC;AAC1C,WAAA,EAAE,CAAC,EAAEH,KAAK,EAA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YAAoCC,cAAAA,EAAgB;AAAc,SAAA;QAC/EC,aAAAA,EAAe,CAACzD,MAAAA,GAAWD,iBAAAA,CAAkBC,MAAAA,EAAQ,MAAA,CAAA;QACrD0D,YAAAA,EAAc,CAAC1D,MAAAA,GAAWyC,gBAAAA,CAAiBzC,MAAAA,EAAQ,MAAA,CAAA;QACnD2D,UAAAA,EAAY,CAACC,yBAAaC,GAAA,CAACrE,UAAAA,EAAAA;AAAYoE,gBAAAA,QAAAA,EAAAA;;AACzC;AACF;;;;"}
1
+ {"version":3,"file":"Modifiers.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/Modifiers.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Typography, TypographyComponent } from '@strapi/design-system';\nimport { Bold, Italic, Underline, StrikeThrough, Code } from '@strapi/icons';\nimport { type MessageDescriptor } from 'react-intl';\nimport { Editor, type NodeEntry, Range, Text, Transforms } from 'slate';\nimport { styled, css } from 'styled-components';\n\nconst stylesToInherit = css`\n font-size: inherit;\n color: inherit;\n line-height: inherit;\n`;\n\nconst BoldText = styled<TypographyComponent>(Typography).attrs({ fontWeight: 'bold' })`\n ${stylesToInherit}\n`;\n\nconst ItalicText = styled<TypographyComponent>(Typography)`\n font-style: italic;\n ${stylesToInherit}\n`;\n\nconst UnderlineText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'underline',\n})`\n ${stylesToInherit}\n`;\n\nconst StrikeThroughText = styled<TypographyComponent>(Typography).attrs({\n textDecoration: 'line-through',\n})`\n ${stylesToInherit}\n`;\n\nconst InlineCode = styled.code`\n background-color: ${({ theme }) => theme.colors.neutral150};\n border-radius: ${({ theme }) => theme.borderRadius};\n padding: ${({ theme }) => `0 ${theme.spaces[2]}`};\n font-family:\n 'SF Mono', SFMono-Regular, ui-monospace, 'DejaVu Sans Mono', Menlo, Consolas, monospace;\n color: inherit;\n`;\n\ntype ModifierKey = Exclude<keyof Text, 'type' | 'text'>;\n\ntype ModifiersStore = {\n [K in ModifierKey]: {\n icon: React.ComponentType;\n isValidEventKey: (event: React.KeyboardEvent<HTMLElement>) => boolean;\n label: MessageDescriptor;\n checkIsActive: (editor: Editor) => boolean;\n handleToggle: (editor: Editor) => void;\n renderLeaf: (children: React.JSX.Element | string) => React.JSX.Element;\n };\n};\n\n/**\n * The default handler for checking if a modifier is active\n */\nconst baseCheckIsActive = (editor: Editor, name: ModifierKey) => {\n const { selection } = editor;\n\n // If there's no selection, fall back to Slate's current marks.\n // (This is what will be applied to newly inserted text.)\n if (!selection) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n // Collapsed selection (caret): current marks are reliable.\n if (Range.isCollapsed(selection)) {\n const marks = Editor.marks(editor);\n return Boolean(marks?.[name]);\n }\n\n /**\n * Expanded selection: derive \"active\" state from the selected text nodes.\n *\n * This avoids a common mobile edge case where the selection focus can sit just\n * outside the formatted span (so relying on caret/focus marks would be wrong).\n *\n * Additionally, mobile selection often includes an extra whitespace character at\n * the edge (e.g. the trailing space after a word). We ignore whitespace-only\n * portions when computing active state so the toolbar reflects the intended\n * formatted text.\n */\n const range = Editor.unhangRange(editor, selection);\n const selectedTextEntries = Array.from(\n Editor.nodes(editor, { at: range, match: Text.isText, mode: 'all' })\n ) as NodeEntry<Text>[];\n\n if (selectedTextEntries.length === 0) return false;\n\n const summary = selectedTextEntries.reduce(\n (acc, [node, path]) => {\n const nodeRange = Editor.range(editor, path);\n const intersection = Range.intersection(range, nodeRange);\n\n if (!intersection) {\n return acc;\n }\n\n const start = Math.min(intersection.anchor.offset, intersection.focus.offset);\n const end = Math.max(intersection.anchor.offset, intersection.focus.offset);\n const selectedSlice = node.text.slice(start, end);\n\n // Ignore whitespace-only slices (common in mobile selection boundaries).\n if (selectedSlice.trim().length === 0) {\n return acc;\n }\n\n return {\n hasNonWhitespaceSelection: true,\n isEveryRelevantNodeMarked: acc.isEveryRelevantNodeMarked && Boolean(node[name]),\n };\n },\n { hasNonWhitespaceSelection: false, isEveryRelevantNodeMarked: true }\n );\n\n return summary.hasNonWhitespaceSelection && summary.isEveryRelevantNodeMarked;\n};\n\n/**\n * The default handler for toggling a modifier\n */\nconst baseHandleToggle = (editor: Editor, name: ModifierKey) => {\n // If there is no selection, set selection to the end of line\n if (!editor.selection) {\n const endOfEditor = Editor.end(editor, []);\n Transforms.select(editor, endOfEditor);\n }\n\n // Toggle the modifier\n if (baseCheckIsActive(editor, name)) {\n Editor.removeMark(editor, name);\n } else {\n Editor.addMark(editor, name, true);\n }\n};\n\nconst modifiers: ModifiersStore = {\n bold: {\n icon: Bold,\n isValidEventKey: (event) => event.key === 'b',\n label: { id: 'components.Blocks.modifiers.bold', defaultMessage: 'Bold' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'bold'),\n handleToggle: (editor) => baseHandleToggle(editor, 'bold'),\n renderLeaf: (children) => <BoldText>{children}</BoldText>,\n },\n italic: {\n icon: Italic,\n isValidEventKey: (event) => event.key === 'i',\n label: { id: 'components.Blocks.modifiers.italic', defaultMessage: 'Italic' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'italic'),\n handleToggle: (editor) => baseHandleToggle(editor, 'italic'),\n renderLeaf: (children) => <ItalicText>{children}</ItalicText>,\n },\n underline: {\n icon: Underline,\n isValidEventKey: (event) => event.key === 'u',\n label: { id: 'components.Blocks.modifiers.underline', defaultMessage: 'Underline' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'underline'),\n handleToggle: (editor) => baseHandleToggle(editor, 'underline'),\n renderLeaf: (children) => <UnderlineText>{children}</UnderlineText>,\n },\n strikethrough: {\n icon: StrikeThrough,\n isValidEventKey: (event) => event.key === 'S' && event.shiftKey,\n label: { id: 'components.Blocks.modifiers.strikethrough', defaultMessage: 'Strikethrough' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'strikethrough'),\n handleToggle: (editor) => baseHandleToggle(editor, 'strikethrough'),\n renderLeaf: (children) => <StrikeThroughText>{children}</StrikeThroughText>,\n },\n code: {\n icon: Code,\n isValidEventKey: (event) => event.key === 'e',\n label: { id: 'components.Blocks.modifiers.code', defaultMessage: 'Inline code' },\n checkIsActive: (editor) => baseCheckIsActive(editor, 'code'),\n handleToggle: (editor) => baseHandleToggle(editor, 'code'),\n renderLeaf: (children) => <InlineCode>{children}</InlineCode>,\n },\n};\n\nexport { type ModifiersStore, modifiers };\n"],"names":["stylesToInherit","css","BoldText","styled","Typography","attrs","fontWeight","ItalicText","UnderlineText","textDecoration","StrikeThroughText","InlineCode","code","theme","colors","neutral150","borderRadius","spaces","baseCheckIsActive","editor","name","selection","marks","Editor","Boolean","Range","isCollapsed","range","unhangRange","selectedTextEntries","Array","from","nodes","at","match","Text","isText","mode","length","summary","reduce","acc","node","path","nodeRange","intersection","start","Math","min","anchor","offset","focus","end","max","selectedSlice","text","slice","trim","hasNonWhitespaceSelection","isEveryRelevantNodeMarked","baseHandleToggle","endOfEditor","Transforms","select","removeMark","addMark","modifiers","bold","icon","Bold","isValidEventKey","event","key","label","id","defaultMessage","checkIsActive","handleToggle","renderLeaf","children","_jsx","italic","Italic","underline","Underline","strikethrough","StrikeThrough","shiftKey","Code"],"mappings":";;;;;;;AAQA,MAAMA,eAAAA,GAAkBC,GAAG;;;;AAI3B,CAAC;AAED,MAAMC,QAAAA,GAAWC,MAAAA,CAA4BC,UAAAA,CAAAA,CAAYC,KAAK,CAAC;IAAEC,UAAAA,EAAY;AAAO,CAAA,CAAE;AACpF,EAAA,EAAEN,eAAAA;AACJ,CAAC;AAED,MAAMO,UAAAA,GAAaJ,MAAAA,CAA4BC,UAAAA,CAAW;;AAExD,EAAA,EAAEJ,eAAAA;AACJ,CAAC;AAED,MAAMQ,aAAAA,GAAgBL,MAAAA,CAA4BC,UAAAA,CAAAA,CAAYC,KAAK,CAAC;IAClEI,cAAAA,EAAgB;AAClB,CAAA,CAAE;AACA,EAAA,EAAET,eAAAA;AACJ,CAAC;AAED,MAAMU,iBAAAA,GAAoBP,MAAAA,CAA4BC,UAAAA,CAAAA,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,GAAWyC,gBAAAA,CAAiBzC,MAAAA,EAAQ,eAAA,CAAA;QACnD2D,UAAAA,EAAY,CAACC,yBAAaC,GAAA,CAACtE,iBAAAA,EAAAA;AAAmBqE,gBAAAA,QAAAA,EAAAA;;AAChD,KAAA;IACAnE,IAAAA,EAAM;QACJwD,IAAAA,EAAMoB,IAAAA;AACNlB,QAAAA,eAAAA,EAAiB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,GAAG,KAAK,GAAA;QAC1CC,KAAAA,EAAO;YAAEC,EAAAA,EAAI,kCAAA;YAAoCC,cAAAA,EAAgB;AAAc,SAAA;QAC/EC,aAAAA,EAAe,CAACzD,MAAAA,GAAWD,iBAAAA,CAAkBC,MAAAA,EAAQ,MAAA,CAAA;QACrD0D,YAAAA,EAAc,CAAC1D,MAAAA,GAAWyC,gBAAAA,CAAiBzC,MAAAA,EAAQ,MAAA,CAAA;QACnD2D,UAAAA,EAAY,CAACC,yBAAaC,GAAA,CAACrE,UAAAA,EAAAA;AAAYoE,gBAAAA,QAAAA,EAAAA;;AACzC;AACF;;;;"}
@@ -153,8 +153,9 @@ const EditorStylesContainer = styledComponents.styled.div`
153
153
  height: ${({ $isExpandMode })=>$isExpandMode ? '100%' : '410px'}; // 512px(total height) - 48px (header) - 52px(footer) - 2px border
154
154
  color: ${({ theme })=>theme.colors.neutral800};
155
155
  direction: ltr;
156
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
157
- 'Open Sans', 'Helvetica Neue', sans-serif;
156
+ font-family:
157
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
158
+ 'Helvetica Neue', sans-serif;
158
159
 
159
160
  ${({ theme })=>theme.breakpoints.medium} {
160
161
  font-size: 1.4rem;
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/Wysiwyg/Editor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport CodeMirror, { EditorFromTextArea } from 'codemirror5';\nimport { styled } from 'styled-components';\n\nimport { PreviewWysiwyg } from './PreviewWysiwyg';\nimport { newlineAndIndentContinueMarkdownList } from './utils/continueList';\n\nimport type { FieldValue, InputProps } from '@strapi/admin/strapi-admin';\n\nimport 'codemirror5/addon/display/placeholder';\n\ninterface EditorApi {\n focus: () => void;\n scrollIntoView: (args?: Parameters<HTMLElement['scrollIntoView']>[0]) => void;\n}\n\ninterface EditorProps\n extends Omit<FieldValue<string>, 'initialValue'>,\n Omit<InputProps, 'type' | 'label'> {\n editorRef: React.MutableRefObject<EditorFromTextArea>;\n isPreviewMode?: boolean;\n isExpandMode?: boolean;\n textareaRef: React.RefObject<HTMLTextAreaElement>;\n}\n\nconst Editor = React.forwardRef<EditorApi, EditorProps>(\n (\n {\n disabled,\n editorRef,\n error,\n isPreviewMode,\n isExpandMode,\n name,\n onChange,\n placeholder,\n textareaRef,\n value,\n },\n forwardedRef\n ) => {\n const onChangeRef = React.useRef(onChange);\n\n React.useEffect(() => {\n onChangeRef.current = onChange;\n }, [onChange]);\n\n React.useEffect(() => {\n if (editorRef.current) {\n // Ensure the editor and its wrapper are cleaned up whenever this view is re-rendered\n // e.g. in case of re-ordering wysiwyg components in a DynamicZone\n editorRef.current.toTextArea();\n }\n editorRef.current = CodeMirror.fromTextArea(textareaRef.current!, {\n lineWrapping: true,\n extraKeys: {\n Enter: 'newlineAndIndentContinueMarkdownList',\n Tab: false,\n 'Shift-Tab': false,\n },\n readOnly: false,\n smartIndent: false,\n placeholder,\n spellcheck: true,\n inputStyle: 'contenteditable',\n });\n\n // @ts-expect-error – doesn't think command exists?\n CodeMirror.commands.newlineAndIndentContinueMarkdownList =\n newlineAndIndentContinueMarkdownList;\n editorRef.current.on('change', (cm, change) => {\n // setValue (prop sync) must not notify the form — parent already has the value.\n if (change.origin === 'setValue') {\n return;\n }\n onChangeRef.current(name, cm.getValue());\n });\n }, [editorRef, textareaRef, name, placeholder]);\n\n React.useEffect(() => {\n if (editorRef.current.hasFocus()) {\n return;\n }\n const nextValue = value ?? '';\n if (editorRef.current.getValue() !== nextValue) {\n editorRef.current.setValue(nextValue);\n }\n }, [editorRef, value]);\n\n React.useEffect(() => {\n if (isPreviewMode || disabled) {\n editorRef.current.setOption('readOnly', 'nocursor');\n } else {\n editorRef.current.setOption('readOnly', false);\n }\n }, [disabled, isPreviewMode, editorRef]);\n\n React.useEffect(() => {\n if (error) {\n editorRef.current.setOption('screenReaderLabel', error);\n } else {\n // to replace with translation\n editorRef.current.setOption('screenReaderLabel', 'Editor');\n }\n }, [editorRef, error]);\n\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n editorRef.current.getInputField().focus();\n },\n scrollIntoView(args?: Parameters<HTMLElement['scrollIntoView']>[0]) {\n editorRef.current.getInputField().scrollIntoView(args);\n },\n }),\n [editorRef]\n );\n\n return (\n <EditorAndPreviewWrapper>\n <EditorStylesContainer $isExpandMode={isExpandMode} $disabled={disabled || isPreviewMode}>\n <textarea ref={textareaRef} />\n </EditorStylesContainer>\n {isPreviewMode && <PreviewWysiwyg data={value} />}\n </EditorAndPreviewWrapper>\n );\n }\n);\n\nconst EditorAndPreviewWrapper = styled.div`\n position: relative;\n height: calc(100%);\n\n ${({ theme }) => theme.breakpoints.medium} {\n height: calc(100% - 48px);\n }\n`;\n\nconst EditorStylesContainer = styled.div<{ $disabled?: boolean; $isExpandMode?: boolean }>`\n cursor: ${({ $disabled }) => ($disabled ? 'not-allowed !important' : 'auto')};\n height: 100%;\n /* BASICS */\n .CodeMirror-placeholder {\n color: ${({ theme }) => theme.colors.neutral600} !important;\n }\n\n .CodeMirror {\n /* Set height, width, borders, and global font properties here */\n font-size: 1.6rem;\n height: ${({ $isExpandMode }) =>\n $isExpandMode\n ? '100%'\n : '410px'}; // 512px(total height) - 48px (header) - 52px(footer) - 2px border\n color: ${({ theme }) => theme.colors.neutral800};\n direction: ltr;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,\n 'Open Sans', 'Helvetica Neue', sans-serif;\n\n ${({ theme }) => theme.breakpoints.medium} {\n font-size: 1.4rem;\n }\n }\n\n /* PADDING */\n\n .CodeMirror-lines {\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n /* Vertical padding around content */\n }\n\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n /* The little square between H and V scrollbars */\n background-color: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n /* GUTTER */\n\n .CodeMirror-gutters {\n border-right: 1px solid #ddd;\n background-color: #f7f7f7;\n white-space: nowrap;\n }\n .CodeMirror-linenumbers {\n }\n .CodeMirror-linenumber {\n padding: 0 3px 0 5px;\n min-width: 20px;\n text-align: right;\n color: #999;\n white-space: nowrap;\n }\n\n .CodeMirror-guttermarker {\n color: black;\n }\n .CodeMirror-guttermarker-subtle {\n color: #999;\n }\n\n /* CURSOR */\n\n .CodeMirror-cursor {\n border-left: 1px solid black;\n border-right: none;\n width: 0;\n }\n /* Shown when moving in bi-directional text */\n .CodeMirror div.CodeMirror-secondarycursor {\n border-left: 1px solid silver;\n }\n .cm-fat-cursor .CodeMirror-cursor {\n width: auto;\n border: 0 !important;\n background: #7e7;\n }\n .cm-fat-cursor div.CodeMirror-cursors {\n /* z-index: 1; */\n }\n\n .cm-fat-cursor-mark {\n background-color: rgba(20, 255, 20, 0.5);\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n }\n .cm-animate-fat-cursor {\n width: auto;\n border: 0;\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n background-color: #7e7;\n }\n\n /* Can style cursor different in overwrite (non-insert) mode */\n .CodeMirror-overwrite .CodeMirror-cursor {\n }\n\n .cm-tab {\n display: inline-block;\n text-decoration: inherit;\n }\n\n .CodeMirror-rulers {\n position: absolute;\n left: 0;\n right: 0;\n top: -50px;\n bottom: 0;\n overflow: hidden;\n }\n .CodeMirror-ruler {\n border-left: 1px solid #ccc;\n top: 0;\n bottom: 0;\n position: absolute;\n }\n\n /* DEFAULT THEME */\n\n .cm-header,\n .cm-strong {\n font-weight: bold;\n }\n .cm-em {\n font-style: italic;\n }\n .cm-link {\n text-decoration: underline;\n }\n .cm-strikethrough {\n text-decoration: line-through;\n }\n\n .CodeMirror-composing {\n border-bottom: 2px solid;\n }\n\n /* Default styles for common addons */\n\n div.CodeMirror span.CodeMirror-matchingbracket {\n color: #0b0;\n }\n div.CodeMirror span.CodeMirror-nonmatchingbracket {\n color: #a22;\n }\n .CodeMirror-matchingtag {\n background: rgba(255, 150, 0, 0.3);\n }\n .CodeMirror-activeline-background {\n background: #e8f2ff;\n }\n\n /* STOP */\n\n /* The rest of this file contains styles related to the mechanics of\n the editor. You probably shouldn't touch them. */\n\n .CodeMirror {\n position: relative;\n overflow: hidden;\n border-radius: ${({ theme }) => theme.borderRadius};\n background: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n .CodeMirror-scroll {\n overflow: scroll !important; /* Things will break if this is overridden */\n /* 50px is the magic margin used to hide the element's real scrollbars */\n /* See overflow: hidden in .CodeMirror */\n margin-bottom: -50px;\n margin-right: -50px;\n padding-bottom: 50px;\n height: 100%;\n outline: none; /* Prevent dragging from highlighting the element */\n position: relative;\n }\n .CodeMirror-sizer {\n position: relative;\n border-right: 50px solid transparent;\n }\n\n /* The fake, visible scrollbars. Used to force redraw during scrolling\n before actual scrolling happens, thus preventing shaking and\n flickering artifacts. */\n .CodeMirror-vscrollbar,\n .CodeMirror-hscrollbar,\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n position: absolute;\n z-index: 1;\n display: none;\n outline: none;\n }\n\n .CodeMirror-vscrollbar {\n right: 0;\n top: 0;\n overflow-x: hidden;\n overflow-y: scroll;\n }\n .CodeMirror-hscrollbar {\n bottom: 0;\n left: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n }\n .CodeMirror-scrollbar-filler {\n right: 0;\n bottom: 0;\n }\n\n .CodeMirror-lines {\n cursor: text;\n min-height: 1px; /* prevents collapsing before first draw */\n }\n /* Reset some styles that the rest of the page might have set */\n .CodeMirror pre.CodeMirror-line,\n .CodeMirror pre.CodeMirror-line-like {\n -moz-border-radius: 0;\n -webkit-border-radius: 0;\n border-radius: 0;\n border-width: 0;\n background: transparent;\n font-family: inherit;\n font-size: inherit;\n margin: 0;\n white-space: pre;\n word-wrap: normal;\n line-height: 1.5;\n color: inherit;\n /* z-index: 2; */\n position: relative;\n overflow: visible;\n -webkit-tap-highlight-color: transparent;\n -webkit-font-variant-ligatures: contextual;\n font-variant-ligatures: contextual;\n }\n\n .CodeMirror pre.CodeMirror-line-like {\n z-index: 2;\n }\n\n .CodeMirror-wrap pre.CodeMirror-line,\n .CodeMirror-wrap pre.CodeMirror-line-like {\n word-wrap: break-word;\n white-space: pre-wrap;\n word-break: break-word;\n }\n\n .CodeMirror-linebackground {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n z-index: 0;\n }\n\n .CodeMirror-linewidget {\n position: relative;\n /* z-index: 2; */\n padding: 0.1px; /* Force widget margins to stay inside of the container */\n }\n\n .CodeMirror-widget {\n }\n\n .CodeMirror-rtl pre {\n direction: rtl;\n }\n\n .CodeMirror-code {\n outline: none;\n }\n\n /* Force content-box sizing for the elements where we expect it */\n .CodeMirror-scroll,\n .CodeMirror-sizer,\n .CodeMirror-gutter,\n .CodeMirror-gutters,\n .CodeMirror-linenumber {\n -moz-box-sizing: content-box;\n box-sizing: content-box;\n }\n\n .CodeMirror-measure {\n position: absolute;\n width: 100%;\n height: 0;\n overflow: hidden;\n visibility: hidden;\n }\n\n .CodeMirror-cursor {\n position: absolute;\n pointer-events: none;\n border-color: ${({ theme }) => `${theme.colors.neutral800}`};\n }\n .CodeMirror-measure pre {\n position: static;\n }\n\n div.CodeMirror-cursors {\n visibility: hidden;\n position: relative;\n + div {\n z-index: 0 !important;\n }\n }\n\n div.CodeMirror-dragcursors {\n visibility: visible;\n }\n\n .CodeMirror-focused div.CodeMirror-cursors {\n visibility: visible;\n }\n\n .CodeMirror-selected {\n background: ${({ theme }) => theme.colors.neutral200};\n /* z-index: -10; */\n }\n .CodeMirror-crosshair {\n cursor: crosshair;\n }\n\n /* Used to force a border model for a node */\n .cm-force-border {\n padding-right: 0.1px;\n }\n\n /* See issue #2901 */\n .cm-tab-wrap-hack:after {\n content: '';\n }\n\n /* Help users use markselection to safely style text background */\n span.CodeMirror-selectedtext {\n background: none;\n }\n\n span {\n color: ${({ theme }) => theme.colors.neutral800} !important;\n }\n`;\n\nexport { Editor };\nexport type { EditorProps, EditorApi };\n"],"names":["Editor","React","forwardRef","disabled","editorRef","error","isPreviewMode","isExpandMode","name","onChange","placeholder","textareaRef","value","forwardedRef","onChangeRef","useRef","useEffect","current","toTextArea","CodeMirror","fromTextArea","lineWrapping","extraKeys","Enter","Tab","readOnly","smartIndent","spellcheck","inputStyle","commands","newlineAndIndentContinueMarkdownList","on","cm","change","origin","getValue","hasFocus","nextValue","setValue","setOption","useImperativeHandle","focus","getInputField","scrollIntoView","args","_jsxs","EditorAndPreviewWrapper","_jsx","EditorStylesContainer","$isExpandMode","$disabled","textarea","ref","PreviewWysiwyg","data","styled","div","theme","breakpoints","medium","colors","neutral600","neutral800","spaces","neutral0","borderRadius","neutral200"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAMA,MAAAA,iBAASC,gBAAAA,CAAMC,UAAU,CAC7B,CACE,EACEC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACLC,aAAa,EACbC,YAAY,EACZC,IAAI,EACJC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,KAAK,EACN,EACDC,YAAAA,GAAAA;IAEA,MAAMC,WAAAA,GAAcb,gBAAAA,CA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react';\n\nimport CodeMirror, { EditorFromTextArea } from 'codemirror5';\nimport { styled } from 'styled-components';\n\nimport { PreviewWysiwyg } from './PreviewWysiwyg';\nimport { newlineAndIndentContinueMarkdownList } from './utils/continueList';\n\nimport type { FieldValue, InputProps } from '@strapi/admin/strapi-admin';\n\nimport 'codemirror5/addon/display/placeholder';\n\ninterface EditorApi {\n focus: () => void;\n scrollIntoView: (args?: Parameters<HTMLElement['scrollIntoView']>[0]) => void;\n}\n\ninterface EditorProps\n extends Omit<FieldValue<string>, 'initialValue'>,\n Omit<InputProps, 'type' | 'label'> {\n editorRef: React.MutableRefObject<EditorFromTextArea>;\n isPreviewMode?: boolean;\n isExpandMode?: boolean;\n textareaRef: React.RefObject<HTMLTextAreaElement>;\n}\n\nconst Editor = React.forwardRef<EditorApi, EditorProps>(\n (\n {\n disabled,\n editorRef,\n error,\n isPreviewMode,\n isExpandMode,\n name,\n onChange,\n placeholder,\n textareaRef,\n value,\n },\n forwardedRef\n ) => {\n const onChangeRef = React.useRef(onChange);\n\n React.useEffect(() => {\n onChangeRef.current = onChange;\n }, [onChange]);\n\n React.useEffect(() => {\n if (editorRef.current) {\n // Ensure the editor and its wrapper are cleaned up whenever this view is re-rendered\n // e.g. in case of re-ordering wysiwyg components in a DynamicZone\n editorRef.current.toTextArea();\n }\n editorRef.current = CodeMirror.fromTextArea(textareaRef.current!, {\n lineWrapping: true,\n extraKeys: {\n Enter: 'newlineAndIndentContinueMarkdownList',\n Tab: false,\n 'Shift-Tab': false,\n },\n readOnly: false,\n smartIndent: false,\n placeholder,\n spellcheck: true,\n inputStyle: 'contenteditable',\n });\n\n // @ts-expect-error – doesn't think command exists?\n CodeMirror.commands.newlineAndIndentContinueMarkdownList =\n newlineAndIndentContinueMarkdownList;\n editorRef.current.on('change', (cm, change) => {\n // setValue (prop sync) must not notify the form — parent already has the value.\n if (change.origin === 'setValue') {\n return;\n }\n onChangeRef.current(name, cm.getValue());\n });\n }, [editorRef, textareaRef, name, placeholder]);\n\n React.useEffect(() => {\n if (editorRef.current.hasFocus()) {\n return;\n }\n const nextValue = value ?? '';\n if (editorRef.current.getValue() !== nextValue) {\n editorRef.current.setValue(nextValue);\n }\n }, [editorRef, value]);\n\n React.useEffect(() => {\n if (isPreviewMode || disabled) {\n editorRef.current.setOption('readOnly', 'nocursor');\n } else {\n editorRef.current.setOption('readOnly', false);\n }\n }, [disabled, isPreviewMode, editorRef]);\n\n React.useEffect(() => {\n if (error) {\n editorRef.current.setOption('screenReaderLabel', error);\n } else {\n // to replace with translation\n editorRef.current.setOption('screenReaderLabel', 'Editor');\n }\n }, [editorRef, error]);\n\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n editorRef.current.getInputField().focus();\n },\n scrollIntoView(args?: Parameters<HTMLElement['scrollIntoView']>[0]) {\n editorRef.current.getInputField().scrollIntoView(args);\n },\n }),\n [editorRef]\n );\n\n return (\n <EditorAndPreviewWrapper>\n <EditorStylesContainer $isExpandMode={isExpandMode} $disabled={disabled || isPreviewMode}>\n <textarea ref={textareaRef} />\n </EditorStylesContainer>\n {isPreviewMode && <PreviewWysiwyg data={value} />}\n </EditorAndPreviewWrapper>\n );\n }\n);\n\nconst EditorAndPreviewWrapper = styled.div`\n position: relative;\n height: calc(100%);\n\n ${({ theme }) => theme.breakpoints.medium} {\n height: calc(100% - 48px);\n }\n`;\n\nconst EditorStylesContainer = styled.div<{ $disabled?: boolean; $isExpandMode?: boolean }>`\n cursor: ${({ $disabled }) => ($disabled ? 'not-allowed !important' : 'auto')};\n height: 100%;\n /* BASICS */\n .CodeMirror-placeholder {\n color: ${({ theme }) => theme.colors.neutral600} !important;\n }\n\n .CodeMirror {\n /* Set height, width, borders, and global font properties here */\n font-size: 1.6rem;\n height: ${({ $isExpandMode }) =>\n $isExpandMode\n ? '100%'\n : '410px'}; // 512px(total height) - 48px (header) - 52px(footer) - 2px border\n color: ${({ theme }) => theme.colors.neutral800};\n direction: ltr;\n font-family:\n -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',\n 'Helvetica Neue', sans-serif;\n\n ${({ theme }) => theme.breakpoints.medium} {\n font-size: 1.4rem;\n }\n }\n\n /* PADDING */\n\n .CodeMirror-lines {\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n /* Vertical padding around content */\n }\n\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n /* The little square between H and V scrollbars */\n background-color: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n /* GUTTER */\n\n .CodeMirror-gutters {\n border-right: 1px solid #ddd;\n background-color: #f7f7f7;\n white-space: nowrap;\n }\n .CodeMirror-linenumbers {\n }\n .CodeMirror-linenumber {\n padding: 0 3px 0 5px;\n min-width: 20px;\n text-align: right;\n color: #999;\n white-space: nowrap;\n }\n\n .CodeMirror-guttermarker {\n color: black;\n }\n .CodeMirror-guttermarker-subtle {\n color: #999;\n }\n\n /* CURSOR */\n\n .CodeMirror-cursor {\n border-left: 1px solid black;\n border-right: none;\n width: 0;\n }\n /* Shown when moving in bi-directional text */\n .CodeMirror div.CodeMirror-secondarycursor {\n border-left: 1px solid silver;\n }\n .cm-fat-cursor .CodeMirror-cursor {\n width: auto;\n border: 0 !important;\n background: #7e7;\n }\n .cm-fat-cursor div.CodeMirror-cursors {\n /* z-index: 1; */\n }\n\n .cm-fat-cursor-mark {\n background-color: rgba(20, 255, 20, 0.5);\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n }\n .cm-animate-fat-cursor {\n width: auto;\n border: 0;\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n background-color: #7e7;\n }\n\n /* Can style cursor different in overwrite (non-insert) mode */\n .CodeMirror-overwrite .CodeMirror-cursor {\n }\n\n .cm-tab {\n display: inline-block;\n text-decoration: inherit;\n }\n\n .CodeMirror-rulers {\n position: absolute;\n left: 0;\n right: 0;\n top: -50px;\n bottom: 0;\n overflow: hidden;\n }\n .CodeMirror-ruler {\n border-left: 1px solid #ccc;\n top: 0;\n bottom: 0;\n position: absolute;\n }\n\n /* DEFAULT THEME */\n\n .cm-header,\n .cm-strong {\n font-weight: bold;\n }\n .cm-em {\n font-style: italic;\n }\n .cm-link {\n text-decoration: underline;\n }\n .cm-strikethrough {\n text-decoration: line-through;\n }\n\n .CodeMirror-composing {\n border-bottom: 2px solid;\n }\n\n /* Default styles for common addons */\n\n div.CodeMirror span.CodeMirror-matchingbracket {\n color: #0b0;\n }\n div.CodeMirror span.CodeMirror-nonmatchingbracket {\n color: #a22;\n }\n .CodeMirror-matchingtag {\n background: rgba(255, 150, 0, 0.3);\n }\n .CodeMirror-activeline-background {\n background: #e8f2ff;\n }\n\n /* STOP */\n\n /* The rest of this file contains styles related to the mechanics of\n the editor. You probably shouldn't touch them. */\n\n .CodeMirror {\n position: relative;\n overflow: hidden;\n border-radius: ${({ theme }) => theme.borderRadius};\n background: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n .CodeMirror-scroll {\n overflow: scroll !important; /* Things will break if this is overridden */\n /* 50px is the magic margin used to hide the element's real scrollbars */\n /* See overflow: hidden in .CodeMirror */\n margin-bottom: -50px;\n margin-right: -50px;\n padding-bottom: 50px;\n height: 100%;\n outline: none; /* Prevent dragging from highlighting the element */\n position: relative;\n }\n .CodeMirror-sizer {\n position: relative;\n border-right: 50px solid transparent;\n }\n\n /* The fake, visible scrollbars. Used to force redraw during scrolling\n before actual scrolling happens, thus preventing shaking and\n flickering artifacts. */\n .CodeMirror-vscrollbar,\n .CodeMirror-hscrollbar,\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n position: absolute;\n z-index: 1;\n display: none;\n outline: none;\n }\n\n .CodeMirror-vscrollbar {\n right: 0;\n top: 0;\n overflow-x: hidden;\n overflow-y: scroll;\n }\n .CodeMirror-hscrollbar {\n bottom: 0;\n left: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n }\n .CodeMirror-scrollbar-filler {\n right: 0;\n bottom: 0;\n }\n\n .CodeMirror-lines {\n cursor: text;\n min-height: 1px; /* prevents collapsing before first draw */\n }\n /* Reset some styles that the rest of the page might have set */\n .CodeMirror pre.CodeMirror-line,\n .CodeMirror pre.CodeMirror-line-like {\n -moz-border-radius: 0;\n -webkit-border-radius: 0;\n border-radius: 0;\n border-width: 0;\n background: transparent;\n font-family: inherit;\n font-size: inherit;\n margin: 0;\n white-space: pre;\n word-wrap: normal;\n line-height: 1.5;\n color: inherit;\n /* z-index: 2; */\n position: relative;\n overflow: visible;\n -webkit-tap-highlight-color: transparent;\n -webkit-font-variant-ligatures: contextual;\n font-variant-ligatures: contextual;\n }\n\n .CodeMirror pre.CodeMirror-line-like {\n z-index: 2;\n }\n\n .CodeMirror-wrap pre.CodeMirror-line,\n .CodeMirror-wrap pre.CodeMirror-line-like {\n word-wrap: break-word;\n white-space: pre-wrap;\n word-break: break-word;\n }\n\n .CodeMirror-linebackground {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n z-index: 0;\n }\n\n .CodeMirror-linewidget {\n position: relative;\n /* z-index: 2; */\n padding: 0.1px; /* Force widget margins to stay inside of the container */\n }\n\n .CodeMirror-widget {\n }\n\n .CodeMirror-rtl pre {\n direction: rtl;\n }\n\n .CodeMirror-code {\n outline: none;\n }\n\n /* Force content-box sizing for the elements where we expect it */\n .CodeMirror-scroll,\n .CodeMirror-sizer,\n .CodeMirror-gutter,\n .CodeMirror-gutters,\n .CodeMirror-linenumber {\n -moz-box-sizing: content-box;\n box-sizing: content-box;\n }\n\n .CodeMirror-measure {\n position: absolute;\n width: 100%;\n height: 0;\n overflow: hidden;\n visibility: hidden;\n }\n\n .CodeMirror-cursor {\n position: absolute;\n pointer-events: none;\n border-color: ${({ theme }) => `${theme.colors.neutral800}`};\n }\n .CodeMirror-measure pre {\n position: static;\n }\n\n div.CodeMirror-cursors {\n visibility: hidden;\n position: relative;\n + div {\n z-index: 0 !important;\n }\n }\n\n div.CodeMirror-dragcursors {\n visibility: visible;\n }\n\n .CodeMirror-focused div.CodeMirror-cursors {\n visibility: visible;\n }\n\n .CodeMirror-selected {\n background: ${({ theme }) => theme.colors.neutral200};\n /* z-index: -10; */\n }\n .CodeMirror-crosshair {\n cursor: crosshair;\n }\n\n /* Used to force a border model for a node */\n .cm-force-border {\n padding-right: 0.1px;\n }\n\n /* See issue #2901 */\n .cm-tab-wrap-hack:after {\n content: '';\n }\n\n /* Help users use markselection to safely style text background */\n span.CodeMirror-selectedtext {\n background: none;\n }\n\n span {\n color: ${({ theme }) => theme.colors.neutral800} !important;\n }\n`;\n\nexport { Editor };\nexport type { EditorProps, EditorApi };\n"],"names":["Editor","React","forwardRef","disabled","editorRef","error","isPreviewMode","isExpandMode","name","onChange","placeholder","textareaRef","value","forwardedRef","onChangeRef","useRef","useEffect","current","toTextArea","CodeMirror","fromTextArea","lineWrapping","extraKeys","Enter","Tab","readOnly","smartIndent","spellcheck","inputStyle","commands","newlineAndIndentContinueMarkdownList","on","cm","change","origin","getValue","hasFocus","nextValue","setValue","setOption","useImperativeHandle","focus","getInputField","scrollIntoView","args","_jsxs","EditorAndPreviewWrapper","_jsx","EditorStylesContainer","$isExpandMode","$disabled","textarea","ref","PreviewWysiwyg","data","styled","div","theme","breakpoints","medium","colors","neutral600","neutral800","spaces","neutral0","borderRadius","neutral200"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAMA,MAAAA,iBAASC,gBAAAA,CAAMC,UAAU,CAC7B,CACE,EACEC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACLC,aAAa,EACbC,YAAY,EACZC,IAAI,EACJC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,KAAK,EACN,EACDC,YAAAA,GAAAA;IAEA,MAAMC,WAAAA,GAAcb,gBAAAA,CAAMc,MAAM,CAAC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er) - 2px border
129
129
  color: ${({ theme })=>theme.colors.neutral800};
130
130
  direction: ltr;
131
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
132
- 'Open Sans', 'Helvetica Neue', sans-serif;
131
+ font-family:
132
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
133
+ 'Helvetica Neue', sans-serif;
133
134
 
134
135
  ${({ theme })=>theme.breakpoints.medium} {
135
136
  font-size: 1.4rem;
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/Wysiwyg/Editor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport CodeMirror, { EditorFromTextArea } from 'codemirror5';\nimport { styled } from 'styled-components';\n\nimport { PreviewWysiwyg } from './PreviewWysiwyg';\nimport { newlineAndIndentContinueMarkdownList } from './utils/continueList';\n\nimport type { FieldValue, InputProps } from '@strapi/admin/strapi-admin';\n\nimport 'codemirror5/addon/display/placeholder';\n\ninterface EditorApi {\n focus: () => void;\n scrollIntoView: (args?: Parameters<HTMLElement['scrollIntoView']>[0]) => void;\n}\n\ninterface EditorProps\n extends Omit<FieldValue<string>, 'initialValue'>,\n Omit<InputProps, 'type' | 'label'> {\n editorRef: React.MutableRefObject<EditorFromTextArea>;\n isPreviewMode?: boolean;\n isExpandMode?: boolean;\n textareaRef: React.RefObject<HTMLTextAreaElement>;\n}\n\nconst Editor = React.forwardRef<EditorApi, EditorProps>(\n (\n {\n disabled,\n editorRef,\n error,\n isPreviewMode,\n isExpandMode,\n name,\n onChange,\n placeholder,\n textareaRef,\n value,\n },\n forwardedRef\n ) => {\n const onChangeRef = React.useRef(onChange);\n\n React.useEffect(() => {\n onChangeRef.current = onChange;\n }, [onChange]);\n\n React.useEffect(() => {\n if (editorRef.current) {\n // Ensure the editor and its wrapper are cleaned up whenever this view is re-rendered\n // e.g. in case of re-ordering wysiwyg components in a DynamicZone\n editorRef.current.toTextArea();\n }\n editorRef.current = CodeMirror.fromTextArea(textareaRef.current!, {\n lineWrapping: true,\n extraKeys: {\n Enter: 'newlineAndIndentContinueMarkdownList',\n Tab: false,\n 'Shift-Tab': false,\n },\n readOnly: false,\n smartIndent: false,\n placeholder,\n spellcheck: true,\n inputStyle: 'contenteditable',\n });\n\n // @ts-expect-error – doesn't think command exists?\n CodeMirror.commands.newlineAndIndentContinueMarkdownList =\n newlineAndIndentContinueMarkdownList;\n editorRef.current.on('change', (cm, change) => {\n // setValue (prop sync) must not notify the form — parent already has the value.\n if (change.origin === 'setValue') {\n return;\n }\n onChangeRef.current(name, cm.getValue());\n });\n }, [editorRef, textareaRef, name, placeholder]);\n\n React.useEffect(() => {\n if (editorRef.current.hasFocus()) {\n return;\n }\n const nextValue = value ?? '';\n if (editorRef.current.getValue() !== nextValue) {\n editorRef.current.setValue(nextValue);\n }\n }, [editorRef, value]);\n\n React.useEffect(() => {\n if (isPreviewMode || disabled) {\n editorRef.current.setOption('readOnly', 'nocursor');\n } else {\n editorRef.current.setOption('readOnly', false);\n }\n }, [disabled, isPreviewMode, editorRef]);\n\n React.useEffect(() => {\n if (error) {\n editorRef.current.setOption('screenReaderLabel', error);\n } else {\n // to replace with translation\n editorRef.current.setOption('screenReaderLabel', 'Editor');\n }\n }, [editorRef, error]);\n\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n editorRef.current.getInputField().focus();\n },\n scrollIntoView(args?: Parameters<HTMLElement['scrollIntoView']>[0]) {\n editorRef.current.getInputField().scrollIntoView(args);\n },\n }),\n [editorRef]\n );\n\n return (\n <EditorAndPreviewWrapper>\n <EditorStylesContainer $isExpandMode={isExpandMode} $disabled={disabled || isPreviewMode}>\n <textarea ref={textareaRef} />\n </EditorStylesContainer>\n {isPreviewMode && <PreviewWysiwyg data={value} />}\n </EditorAndPreviewWrapper>\n );\n }\n);\n\nconst EditorAndPreviewWrapper = styled.div`\n position: relative;\n height: calc(100%);\n\n ${({ theme }) => theme.breakpoints.medium} {\n height: calc(100% - 48px);\n }\n`;\n\nconst EditorStylesContainer = styled.div<{ $disabled?: boolean; $isExpandMode?: boolean }>`\n cursor: ${({ $disabled }) => ($disabled ? 'not-allowed !important' : 'auto')};\n height: 100%;\n /* BASICS */\n .CodeMirror-placeholder {\n color: ${({ theme }) => theme.colors.neutral600} !important;\n }\n\n .CodeMirror {\n /* Set height, width, borders, and global font properties here */\n font-size: 1.6rem;\n height: ${({ $isExpandMode }) =>\n $isExpandMode\n ? '100%'\n : '410px'}; // 512px(total height) - 48px (header) - 52px(footer) - 2px border\n color: ${({ theme }) => theme.colors.neutral800};\n direction: ltr;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,\n 'Open Sans', 'Helvetica Neue', sans-serif;\n\n ${({ theme }) => theme.breakpoints.medium} {\n font-size: 1.4rem;\n }\n }\n\n /* PADDING */\n\n .CodeMirror-lines {\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n /* Vertical padding around content */\n }\n\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n /* The little square between H and V scrollbars */\n background-color: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n /* GUTTER */\n\n .CodeMirror-gutters {\n border-right: 1px solid #ddd;\n background-color: #f7f7f7;\n white-space: nowrap;\n }\n .CodeMirror-linenumbers {\n }\n .CodeMirror-linenumber {\n padding: 0 3px 0 5px;\n min-width: 20px;\n text-align: right;\n color: #999;\n white-space: nowrap;\n }\n\n .CodeMirror-guttermarker {\n color: black;\n }\n .CodeMirror-guttermarker-subtle {\n color: #999;\n }\n\n /* CURSOR */\n\n .CodeMirror-cursor {\n border-left: 1px solid black;\n border-right: none;\n width: 0;\n }\n /* Shown when moving in bi-directional text */\n .CodeMirror div.CodeMirror-secondarycursor {\n border-left: 1px solid silver;\n }\n .cm-fat-cursor .CodeMirror-cursor {\n width: auto;\n border: 0 !important;\n background: #7e7;\n }\n .cm-fat-cursor div.CodeMirror-cursors {\n /* z-index: 1; */\n }\n\n .cm-fat-cursor-mark {\n background-color: rgba(20, 255, 20, 0.5);\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n }\n .cm-animate-fat-cursor {\n width: auto;\n border: 0;\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n background-color: #7e7;\n }\n\n /* Can style cursor different in overwrite (non-insert) mode */\n .CodeMirror-overwrite .CodeMirror-cursor {\n }\n\n .cm-tab {\n display: inline-block;\n text-decoration: inherit;\n }\n\n .CodeMirror-rulers {\n position: absolute;\n left: 0;\n right: 0;\n top: -50px;\n bottom: 0;\n overflow: hidden;\n }\n .CodeMirror-ruler {\n border-left: 1px solid #ccc;\n top: 0;\n bottom: 0;\n position: absolute;\n }\n\n /* DEFAULT THEME */\n\n .cm-header,\n .cm-strong {\n font-weight: bold;\n }\n .cm-em {\n font-style: italic;\n }\n .cm-link {\n text-decoration: underline;\n }\n .cm-strikethrough {\n text-decoration: line-through;\n }\n\n .CodeMirror-composing {\n border-bottom: 2px solid;\n }\n\n /* Default styles for common addons */\n\n div.CodeMirror span.CodeMirror-matchingbracket {\n color: #0b0;\n }\n div.CodeMirror span.CodeMirror-nonmatchingbracket {\n color: #a22;\n }\n .CodeMirror-matchingtag {\n background: rgba(255, 150, 0, 0.3);\n }\n .CodeMirror-activeline-background {\n background: #e8f2ff;\n }\n\n /* STOP */\n\n /* The rest of this file contains styles related to the mechanics of\n the editor. You probably shouldn't touch them. */\n\n .CodeMirror {\n position: relative;\n overflow: hidden;\n border-radius: ${({ theme }) => theme.borderRadius};\n background: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n .CodeMirror-scroll {\n overflow: scroll !important; /* Things will break if this is overridden */\n /* 50px is the magic margin used to hide the element's real scrollbars */\n /* See overflow: hidden in .CodeMirror */\n margin-bottom: -50px;\n margin-right: -50px;\n padding-bottom: 50px;\n height: 100%;\n outline: none; /* Prevent dragging from highlighting the element */\n position: relative;\n }\n .CodeMirror-sizer {\n position: relative;\n border-right: 50px solid transparent;\n }\n\n /* The fake, visible scrollbars. Used to force redraw during scrolling\n before actual scrolling happens, thus preventing shaking and\n flickering artifacts. */\n .CodeMirror-vscrollbar,\n .CodeMirror-hscrollbar,\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n position: absolute;\n z-index: 1;\n display: none;\n outline: none;\n }\n\n .CodeMirror-vscrollbar {\n right: 0;\n top: 0;\n overflow-x: hidden;\n overflow-y: scroll;\n }\n .CodeMirror-hscrollbar {\n bottom: 0;\n left: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n }\n .CodeMirror-scrollbar-filler {\n right: 0;\n bottom: 0;\n }\n\n .CodeMirror-lines {\n cursor: text;\n min-height: 1px; /* prevents collapsing before first draw */\n }\n /* Reset some styles that the rest of the page might have set */\n .CodeMirror pre.CodeMirror-line,\n .CodeMirror pre.CodeMirror-line-like {\n -moz-border-radius: 0;\n -webkit-border-radius: 0;\n border-radius: 0;\n border-width: 0;\n background: transparent;\n font-family: inherit;\n font-size: inherit;\n margin: 0;\n white-space: pre;\n word-wrap: normal;\n line-height: 1.5;\n color: inherit;\n /* z-index: 2; */\n position: relative;\n overflow: visible;\n -webkit-tap-highlight-color: transparent;\n -webkit-font-variant-ligatures: contextual;\n font-variant-ligatures: contextual;\n }\n\n .CodeMirror pre.CodeMirror-line-like {\n z-index: 2;\n }\n\n .CodeMirror-wrap pre.CodeMirror-line,\n .CodeMirror-wrap pre.CodeMirror-line-like {\n word-wrap: break-word;\n white-space: pre-wrap;\n word-break: break-word;\n }\n\n .CodeMirror-linebackground {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n z-index: 0;\n }\n\n .CodeMirror-linewidget {\n position: relative;\n /* z-index: 2; */\n padding: 0.1px; /* Force widget margins to stay inside of the container */\n }\n\n .CodeMirror-widget {\n }\n\n .CodeMirror-rtl pre {\n direction: rtl;\n }\n\n .CodeMirror-code {\n outline: none;\n }\n\n /* Force content-box sizing for the elements where we expect it */\n .CodeMirror-scroll,\n .CodeMirror-sizer,\n .CodeMirror-gutter,\n .CodeMirror-gutters,\n .CodeMirror-linenumber {\n -moz-box-sizing: content-box;\n box-sizing: content-box;\n }\n\n .CodeMirror-measure {\n position: absolute;\n width: 100%;\n height: 0;\n overflow: hidden;\n visibility: hidden;\n }\n\n .CodeMirror-cursor {\n position: absolute;\n pointer-events: none;\n border-color: ${({ theme }) => `${theme.colors.neutral800}`};\n }\n .CodeMirror-measure pre {\n position: static;\n }\n\n div.CodeMirror-cursors {\n visibility: hidden;\n position: relative;\n + div {\n z-index: 0 !important;\n }\n }\n\n div.CodeMirror-dragcursors {\n visibility: visible;\n }\n\n .CodeMirror-focused div.CodeMirror-cursors {\n visibility: visible;\n }\n\n .CodeMirror-selected {\n background: ${({ theme }) => theme.colors.neutral200};\n /* z-index: -10; */\n }\n .CodeMirror-crosshair {\n cursor: crosshair;\n }\n\n /* Used to force a border model for a node */\n .cm-force-border {\n padding-right: 0.1px;\n }\n\n /* See issue #2901 */\n .cm-tab-wrap-hack:after {\n content: '';\n }\n\n /* Help users use markselection to safely style text background */\n span.CodeMirror-selectedtext {\n background: none;\n }\n\n span {\n color: ${({ theme }) => theme.colors.neutral800} !important;\n }\n`;\n\nexport { Editor };\nexport type { EditorProps, EditorApi };\n"],"names":["Editor","React","forwardRef","disabled","editorRef","error","isPreviewMode","isExpandMode","name","onChange","placeholder","textareaRef","value","forwardedRef","onChangeRef","useRef","useEffect","current","toTextArea","CodeMirror","fromTextArea","lineWrapping","extraKeys","Enter","Tab","readOnly","smartIndent","spellcheck","inputStyle","commands","newlineAndIndentContinueMarkdownList","on","cm","change","origin","getValue","hasFocus","nextValue","setValue","setOption","useImperativeHandle","focus","getInputField","scrollIntoView","args","_jsxs","EditorAndPreviewWrapper","_jsx","EditorStylesContainer","$isExpandMode","$disabled","textarea","ref","PreviewWysiwyg","data","styled","div","theme","breakpoints","medium","colors","neutral600","neutral800","spaces","neutral0","borderRadius","neutral200"],"mappings":";;;;;;;;AA0BA,MAAMA,MAAAA,iBAASC,KAAAA,CAAMC,UAAU,CAC7B,CACE,EACEC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACLC,aAAa,EACbC,YAAY,EACZC,IAAI,EACJC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,KAAK,EACN,EACDC,YAAAA,GAAAA;IAEA,MAAMC,WAAAA,GAAcb,KAAAA,CAAMc,MAAM,CAACN,QAAAA,CAAAA;AAEjCR,IAAAA,KAAAA,CAAMe,SAAS,CAAC,IAAA;AACdF,QAAAA,WAAAA,CAAYG,OAAO,GAAGR,QAAAA;IACxB,CAAA,EAAG;AAACA,QAAAA;AAAS,KAAA,CAAA;AAEbR,IAAAA,KAAAA,CAAMe,SAAS,CAAC,IAAA;QACd,IAAIZ,SAAAA,CAAUa,OAAO,EAAE;;;YAGrBb,SAAAA,CAAUa,OAAO,CAACC,UAAU,EAAA;AAC9B,QAAA;AACAd,QAAAA,SAAAA,CAAUa,OAAO,GAAGE,UAAAA,CAAWC,YAAY,CAACT,WAAAA,CAAYM,OAAO,EAAG;YAChEI,YAAAA,EAAc,IAAA;YACdC,SAAAA,EAAW;gBACTC,KAAAA,EAAO,sCAAA;gBACPC,GAAAA,EAAK,KAAA;gBACL,WAAA,EAAa;AACf,aAAA;YACAC,QAAAA,EAAU,KAAA;YACVC,WAAAA,EAAa,KAAA;AACbhB,YAAAA,WAAAA;YACAiB,UAAAA,EAAY,IAAA;YACZC,UAAAA,EAAY;AACd,SAAA,CAAA;;QAGAT,UAAAA,CAAWU,QAAQ,CAACC,oCAAoC,GACtDA,oCAAAA;AACF1B,QAAAA,SAAAA,CAAUa,OAAO,CAACc,EAAE,CAAC,QAAA,EAAU,CAACC,EAAAA,EA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AAA,CAAMG,MAAM,CAACE,UAAU,CAAA,CAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;gBAuBhD,EAAE,CAAC,EAAEL,KAAK,EAAE,GAAKA,KAAAA,CAAMG,MAAM,CAACM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;WAuB9C,EAAE,CAAC,EAAET,KAAK,EAAE,GAAKA,KAAAA,CAAMG,MAAM,CAACE,UAAU,CAAC;;AAEpD,CAAC;;;;"}
1
+ {"version":3,"file":"Editor.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/Wysiwyg/Editor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport CodeMirror, { EditorFromTextArea } from 'codemirror5';\nimport { styled } from 'styled-components';\n\nimport { PreviewWysiwyg } from './PreviewWysiwyg';\nimport { newlineAndIndentContinueMarkdownList } from './utils/continueList';\n\nimport type { FieldValue, InputProps } from '@strapi/admin/strapi-admin';\n\nimport 'codemirror5/addon/display/placeholder';\n\ninterface EditorApi {\n focus: () => void;\n scrollIntoView: (args?: Parameters<HTMLElement['scrollIntoView']>[0]) => void;\n}\n\ninterface EditorProps\n extends Omit<FieldValue<string>, 'initialValue'>,\n Omit<InputProps, 'type' | 'label'> {\n editorRef: React.MutableRefObject<EditorFromTextArea>;\n isPreviewMode?: boolean;\n isExpandMode?: boolean;\n textareaRef: React.RefObject<HTMLTextAreaElement>;\n}\n\nconst Editor = React.forwardRef<EditorApi, EditorProps>(\n (\n {\n disabled,\n editorRef,\n error,\n isPreviewMode,\n isExpandMode,\n name,\n onChange,\n placeholder,\n textareaRef,\n value,\n },\n forwardedRef\n ) => {\n const onChangeRef = React.useRef(onChange);\n\n React.useEffect(() => {\n onChangeRef.current = onChange;\n }, [onChange]);\n\n React.useEffect(() => {\n if (editorRef.current) {\n // Ensure the editor and its wrapper are cleaned up whenever this view is re-rendered\n // e.g. in case of re-ordering wysiwyg components in a DynamicZone\n editorRef.current.toTextArea();\n }\n editorRef.current = CodeMirror.fromTextArea(textareaRef.current!, {\n lineWrapping: true,\n extraKeys: {\n Enter: 'newlineAndIndentContinueMarkdownList',\n Tab: false,\n 'Shift-Tab': false,\n },\n readOnly: false,\n smartIndent: false,\n placeholder,\n spellcheck: true,\n inputStyle: 'contenteditable',\n });\n\n // @ts-expect-error – doesn't think command exists?\n CodeMirror.commands.newlineAndIndentContinueMarkdownList =\n newlineAndIndentContinueMarkdownList;\n editorRef.current.on('change', (cm, change) => {\n // setValue (prop sync) must not notify the form — parent already has the value.\n if (change.origin === 'setValue') {\n return;\n }\n onChangeRef.current(name, cm.getValue());\n });\n }, [editorRef, textareaRef, name, placeholder]);\n\n React.useEffect(() => {\n if (editorRef.current.hasFocus()) {\n return;\n }\n const nextValue = value ?? '';\n if (editorRef.current.getValue() !== nextValue) {\n editorRef.current.setValue(nextValue);\n }\n }, [editorRef, value]);\n\n React.useEffect(() => {\n if (isPreviewMode || disabled) {\n editorRef.current.setOption('readOnly', 'nocursor');\n } else {\n editorRef.current.setOption('readOnly', false);\n }\n }, [disabled, isPreviewMode, editorRef]);\n\n React.useEffect(() => {\n if (error) {\n editorRef.current.setOption('screenReaderLabel', error);\n } else {\n // to replace with translation\n editorRef.current.setOption('screenReaderLabel', 'Editor');\n }\n }, [editorRef, error]);\n\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n editorRef.current.getInputField().focus();\n },\n scrollIntoView(args?: Parameters<HTMLElement['scrollIntoView']>[0]) {\n editorRef.current.getInputField().scrollIntoView(args);\n },\n }),\n [editorRef]\n );\n\n return (\n <EditorAndPreviewWrapper>\n <EditorStylesContainer $isExpandMode={isExpandMode} $disabled={disabled || isPreviewMode}>\n <textarea ref={textareaRef} />\n </EditorStylesContainer>\n {isPreviewMode && <PreviewWysiwyg data={value} />}\n </EditorAndPreviewWrapper>\n );\n }\n);\n\nconst EditorAndPreviewWrapper = styled.div`\n position: relative;\n height: calc(100%);\n\n ${({ theme }) => theme.breakpoints.medium} {\n height: calc(100% - 48px);\n }\n`;\n\nconst EditorStylesContainer = styled.div<{ $disabled?: boolean; $isExpandMode?: boolean }>`\n cursor: ${({ $disabled }) => ($disabled ? 'not-allowed !important' : 'auto')};\n height: 100%;\n /* BASICS */\n .CodeMirror-placeholder {\n color: ${({ theme }) => theme.colors.neutral600} !important;\n }\n\n .CodeMirror {\n /* Set height, width, borders, and global font properties here */\n font-size: 1.6rem;\n height: ${({ $isExpandMode }) =>\n $isExpandMode\n ? '100%'\n : '410px'}; // 512px(total height) - 48px (header) - 52px(footer) - 2px border\n color: ${({ theme }) => theme.colors.neutral800};\n direction: ltr;\n font-family:\n -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',\n 'Helvetica Neue', sans-serif;\n\n ${({ theme }) => theme.breakpoints.medium} {\n font-size: 1.4rem;\n }\n }\n\n /* PADDING */\n\n .CodeMirror-lines {\n padding: ${({ theme }) => `${theme.spaces[3]} ${theme.spaces[4]}`};\n /* Vertical padding around content */\n }\n\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n /* The little square between H and V scrollbars */\n background-color: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n /* GUTTER */\n\n .CodeMirror-gutters {\n border-right: 1px solid #ddd;\n background-color: #f7f7f7;\n white-space: nowrap;\n }\n .CodeMirror-linenumbers {\n }\n .CodeMirror-linenumber {\n padding: 0 3px 0 5px;\n min-width: 20px;\n text-align: right;\n color: #999;\n white-space: nowrap;\n }\n\n .CodeMirror-guttermarker {\n color: black;\n }\n .CodeMirror-guttermarker-subtle {\n color: #999;\n }\n\n /* CURSOR */\n\n .CodeMirror-cursor {\n border-left: 1px solid black;\n border-right: none;\n width: 0;\n }\n /* Shown when moving in bi-directional text */\n .CodeMirror div.CodeMirror-secondarycursor {\n border-left: 1px solid silver;\n }\n .cm-fat-cursor .CodeMirror-cursor {\n width: auto;\n border: 0 !important;\n background: #7e7;\n }\n .cm-fat-cursor div.CodeMirror-cursors {\n /* z-index: 1; */\n }\n\n .cm-fat-cursor-mark {\n background-color: rgba(20, 255, 20, 0.5);\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n }\n .cm-animate-fat-cursor {\n width: auto;\n border: 0;\n -webkit-animation: blink 1.06s steps(1) infinite;\n -moz-animation: blink 1.06s steps(1) infinite;\n animation: blink 1.06s steps(1) infinite;\n background-color: #7e7;\n }\n\n /* Can style cursor different in overwrite (non-insert) mode */\n .CodeMirror-overwrite .CodeMirror-cursor {\n }\n\n .cm-tab {\n display: inline-block;\n text-decoration: inherit;\n }\n\n .CodeMirror-rulers {\n position: absolute;\n left: 0;\n right: 0;\n top: -50px;\n bottom: 0;\n overflow: hidden;\n }\n .CodeMirror-ruler {\n border-left: 1px solid #ccc;\n top: 0;\n bottom: 0;\n position: absolute;\n }\n\n /* DEFAULT THEME */\n\n .cm-header,\n .cm-strong {\n font-weight: bold;\n }\n .cm-em {\n font-style: italic;\n }\n .cm-link {\n text-decoration: underline;\n }\n .cm-strikethrough {\n text-decoration: line-through;\n }\n\n .CodeMirror-composing {\n border-bottom: 2px solid;\n }\n\n /* Default styles for common addons */\n\n div.CodeMirror span.CodeMirror-matchingbracket {\n color: #0b0;\n }\n div.CodeMirror span.CodeMirror-nonmatchingbracket {\n color: #a22;\n }\n .CodeMirror-matchingtag {\n background: rgba(255, 150, 0, 0.3);\n }\n .CodeMirror-activeline-background {\n background: #e8f2ff;\n }\n\n /* STOP */\n\n /* The rest of this file contains styles related to the mechanics of\n the editor. You probably shouldn't touch them. */\n\n .CodeMirror {\n position: relative;\n overflow: hidden;\n border-radius: ${({ theme }) => theme.borderRadius};\n background: ${({ theme }) => `${theme.colors.neutral0}`};\n }\n\n .CodeMirror-scroll {\n overflow: scroll !important; /* Things will break if this is overridden */\n /* 50px is the magic margin used to hide the element's real scrollbars */\n /* See overflow: hidden in .CodeMirror */\n margin-bottom: -50px;\n margin-right: -50px;\n padding-bottom: 50px;\n height: 100%;\n outline: none; /* Prevent dragging from highlighting the element */\n position: relative;\n }\n .CodeMirror-sizer {\n position: relative;\n border-right: 50px solid transparent;\n }\n\n /* The fake, visible scrollbars. Used to force redraw during scrolling\n before actual scrolling happens, thus preventing shaking and\n flickering artifacts. */\n .CodeMirror-vscrollbar,\n .CodeMirror-hscrollbar,\n .CodeMirror-scrollbar-filler,\n .CodeMirror-gutter-filler {\n position: absolute;\n z-index: 1;\n display: none;\n outline: none;\n }\n\n .CodeMirror-vscrollbar {\n right: 0;\n top: 0;\n overflow-x: hidden;\n overflow-y: scroll;\n }\n .CodeMirror-hscrollbar {\n bottom: 0;\n left: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n }\n .CodeMirror-scrollbar-filler {\n right: 0;\n bottom: 0;\n }\n\n .CodeMirror-lines {\n cursor: text;\n min-height: 1px; /* prevents collapsing before first draw */\n }\n /* Reset some styles that the rest of the page might have set */\n .CodeMirror pre.CodeMirror-line,\n .CodeMirror pre.CodeMirror-line-like {\n -moz-border-radius: 0;\n -webkit-border-radius: 0;\n border-radius: 0;\n border-width: 0;\n background: transparent;\n font-family: inherit;\n font-size: inherit;\n margin: 0;\n white-space: pre;\n word-wrap: normal;\n line-height: 1.5;\n color: inherit;\n /* z-index: 2; */\n position: relative;\n overflow: visible;\n -webkit-tap-highlight-color: transparent;\n -webkit-font-variant-ligatures: contextual;\n font-variant-ligatures: contextual;\n }\n\n .CodeMirror pre.CodeMirror-line-like {\n z-index: 2;\n }\n\n .CodeMirror-wrap pre.CodeMirror-line,\n .CodeMirror-wrap pre.CodeMirror-line-like {\n word-wrap: break-word;\n white-space: pre-wrap;\n word-break: break-word;\n }\n\n .CodeMirror-linebackground {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n z-index: 0;\n }\n\n .CodeMirror-linewidget {\n position: relative;\n /* z-index: 2; */\n padding: 0.1px; /* Force widget margins to stay inside of the container */\n }\n\n .CodeMirror-widget {\n }\n\n .CodeMirror-rtl pre {\n direction: rtl;\n }\n\n .CodeMirror-code {\n outline: none;\n }\n\n /* Force content-box sizing for the elements where we expect it */\n .CodeMirror-scroll,\n .CodeMirror-sizer,\n .CodeMirror-gutter,\n .CodeMirror-gutters,\n .CodeMirror-linenumber {\n -moz-box-sizing: content-box;\n box-sizing: content-box;\n }\n\n .CodeMirror-measure {\n position: absolute;\n width: 100%;\n height: 0;\n overflow: hidden;\n visibility: hidden;\n }\n\n .CodeMirror-cursor {\n position: absolute;\n pointer-events: none;\n border-color: ${({ theme }) => `${theme.colors.neutral800}`};\n }\n .CodeMirror-measure pre {\n position: static;\n }\n\n div.CodeMirror-cursors {\n visibility: hidden;\n position: relative;\n + div {\n z-index: 0 !important;\n }\n }\n\n div.CodeMirror-dragcursors {\n visibility: visible;\n }\n\n .CodeMirror-focused div.CodeMirror-cursors {\n visibility: visible;\n }\n\n .CodeMirror-selected {\n background: ${({ theme }) => theme.colors.neutral200};\n /* z-index: -10; */\n }\n .CodeMirror-crosshair {\n cursor: crosshair;\n }\n\n /* Used to force a border model for a node */\n .cm-force-border {\n padding-right: 0.1px;\n }\n\n /* See issue #2901 */\n .cm-tab-wrap-hack:after {\n content: '';\n }\n\n /* Help users use markselection to safely style text background */\n span.CodeMirror-selectedtext {\n background: none;\n }\n\n span {\n color: ${({ theme }) => theme.colors.neutral800} !important;\n }\n`;\n\nexport { Editor };\nexport type { EditorProps, EditorApi };\n"],"names":["Editor","React","forwardRef","disabled","editorRef","error","isPreviewMode","isExpandMode","name","onChange","placeholder","textareaRef","value","forwardedRef","onChangeRef","useRef","useEffect","current","toTextArea","CodeMirror","fromTextArea","lineWrapping","extraKeys","Enter","Tab","readOnly","smartIndent","spellcheck","inputStyle","commands","newlineAndIndentContinueMarkdownList","on","cm","change","origin","getValue","hasFocus","nextValue","setValue","setOption","useImperativeHandle","focus","getInputField","scrollIntoView","args","_jsxs","EditorAndPreviewWrapper","_jsx","EditorStylesContainer","$isExpandMode","$disabled","textarea","ref","PreviewWysiwyg","data","styled","div","theme","breakpoints","medium","colors","neutral600","neutral800","spaces","neutral0","borderRadius","neutral200"],"mappings":";;;;;;;;AA0BA,MAAMA,MAAAA,iBAASC,KAAAA,CAAMC,UAAU,CAC7B,CACE,EACEC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACLC,aAAa,EACbC,YAAY,EACZC,IAAI,EACJC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,KAAK,EACN,EACDC,YAAAA,GAAAA;IAEA,MAAMC,WAAAA,GAAcb,KAAAA,CAAMc,MAAM,CAACN,QAAAA,CAAAA;AAEjCR,IAAAA,KAAAA,CAAMe,SAAS,CAAC,IAAA;AACdF,QAAAA,WAAAA,CAAYG,OAAO,GAAGR,QAAAA;IACxB,CAAA,EAAG;AAACA,QAAAA;AAAS,KAAA,CAAA;AAEbR,IAAAA,KAAAA,CAAMe,SAAS,CAAC,IAAA;QACd,IAAIZ,SAAAA,CAAUa,OAAO,EAAE;;;YAGrBb,SAAAA,CAAUa,OAAO,CAACC,UAAU,EAAA;AAC9B,QAAA;AACAd,QAAAA,SAAAA,CAAUa,OAAO,GAAGE,UAAAA,CAAWC,YAAY,CAACT,WAAAA,CAAYM,OAAO,EAAG;YAChEI,YAAAA,EAAc,IAAA;YACdC,SAAAA,EAAW;gBACTC,KAAAA,EAAO,sCAAA;gBACPC,GAAAA,EAAK,KAAA;gBACL,WAAA,EAAa;AACf,aAAA;YACAC,QAAAA,EAAU,KAAA;YACVC,WAAAA,EAAa,KAAA;AACbhB,YAAAA,WAAAA;YACAiB,UAAAA,EAAY,IAAA;YACZC,UAAAA,EAAY;AACd,SAAA,CAAA;;QAGAT,UAAAA,CAAWU,QAAQ,CAACC,oCAAoC,GACtDA,oCAAAA;AACF1B,QAAAA,SAAAA,CAAUa,OAAO,CAACc,EAAE,CAAC,QAAA,EAAU,CAACC,EAAAA,EAAIC,MAAAA,GAAAA;;YAElC,IAAIA,MAAAA,CAAOC,MAAM,KAA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;;;;;;;;;;;;;;;gBAuBhD,EAAE,CAAC,EAAEL,KAAK,EAAE,GAAKA,KAAAA,CAAMG,MAAM,CAACM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;WAuB9C,EAAE,CAAC,EAAET,KAAK,EAAE,GAAKA,KAAAA,CAAMG,MAAM,CAACE,UAAU,CAAC;;AAEpD,CAAC;;;;"}
@@ -343,8 +343,7 @@ const getDeepPopulateDraftCount = (uid)=>{
343
343
  // Populate all relations, components and media
344
344
  if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {
345
345
  const populatePath = path.attribute.replace(/\./g, '.populate.');
346
- // @ts-expect-error - lodash doesn't resolve the Populate type correctly
347
- populateQuery = fp.set(populatePath, {}, populateQuery);
346
+ populateQuery = fp.merge(populateQuery, fp.set(populatePath, {}, {}));
348
347
  }
349
348
  }, {
350
349
  schema: strapi.getModel(uid),
@@ -1 +1 @@
1
- {"version":3,"file":"populate.js","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport * as strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n): { on: { [key: string]: { populate: { [key: string]: boolean | object } } } } {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n): { [key: string]: boolean | object } => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema): { populate: any; hasRelations: boolean } => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n // Self-referential relations are preserved on publish (see self-referential-relations.ts).\n if (attribute.target === uid) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n // Draft entries link to draft rows of related documents. Populate documentId/locale\n // so we can distinguish truly unpublished targets from published documents that\n // still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).\n const fields: string[] = ['documentId'];\n if (isLocalizedContentType(targetModel)) {\n fields.push('locale');\n }\n populateAcc[attributeName] = {\n fields,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n // @ts-expect-error - lodash doesn't resolve the Populate type correctly\n populateQuery = set(populatePath, {}, populateQuery);\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isLocalizedContentType","model","pluginOptions","i18n","localized","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","localizations"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,uBAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,uBAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,sBAAAA,CAAYC,YAAY,CAACI,SAAS;AAErE,MAAMC,sBAAAA,GAAyB,CAACC,KAAAA,GAC7BA,MAAMC,aAAa,EAAqDC,MAAMC,SAAAA,KAAc,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B,MAAAA,EAAQ;QACV,OAAOA,MAAAA;AACT,IAAA;IAEA,MAAME,MAAAA,GAAS,MAAMmC,gBAAAA,CAAW,kBAAA,CAAA,CAAoBjE,GAAAA,CAAAA,CACjDkE,YAAY,CAAC/C,QAAAA,CAAAA,CACbgD,cAAc,EAAA,CACdC,KAAK,EAAA;IAERL,iBAAAA,CAAkB1B,GAAG,CAACrC,GAAAA,EAAK8B,MAAAA,CAAAA;IAE3B,OAAOA,MAAAA;AACT;AAEA;;;;;;;;;;;IAYA,MAAMuC,8BAA8B,CAAC3F,KAAAA,GAAAA;IACnC,MAAM4F,WAAAA,GAAclD,MAAAA,CAAOC,QAAQ,CAAC3C,KAAAA,CAAAA;AACpC,IAAA,IACE,WAAC4F,CAAgF3F,aAAa,EAC1FC,MAAMC,SAAAA,EACV;QACA,OAAO;YAAE0F,aAAAA,EAAe;gBAAEvC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA,YAAA;AAAc,oBAAA,aAAA;AAAe,oBAAA;AAAY;AAAC;AAAE,SAAA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;;;;;;"}
1
+ {"version":3,"file":"populate.js","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport * as strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n): { on: { [key: string]: { populate: { [key: string]: boolean | object } } } } {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n): { [key: string]: boolean | object } => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema): { populate: any; hasRelations: boolean } => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n // Self-referential relations are preserved on publish (see self-referential-relations.ts).\n if (attribute.target === uid) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n // Draft entries link to draft rows of related documents. Populate documentId/locale\n // so we can distinguish truly unpublished targets from published documents that\n // still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).\n const fields: string[] = ['documentId'];\n if (isLocalizedContentType(targetModel)) {\n fields.push('locale');\n }\n populateAcc[attributeName] = {\n fields,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n populateQuery = merge(populateQuery, set(populatePath, {}, {}));\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isLocalizedContentType","model","pluginOptions","i18n","localized","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","localizations"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,uBAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,uBAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,sBAAAA,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AAE9B,MAAMqC,oBAAoB,OAAOhE,GAAAA,GAAAA;IAC/B,MAAM4B,MAAAA,GAASmC,iBAAAA,CAAkBlC,GAAG,CAAC7B,GAAAA,CAAAA;AACrC,IAAA,IAAI4B,MAAAA,EAAQ;QACV,OAAOA,MAAAA;AACT,IAAA;IAEA,MAAME,MAAAA,GAAS,MAAMmC,gBAAAA,CAAW,kBAAA,CAAA,CAAoBjE,GAAAA,CAAAA,CACjDkE,YAAY,CAAC/C,QAAAA,CAAAA,CACbgD,cAAc,EAAA,CACdC,KAAK,EAAA;IAERL,iBAAAA,CAAkB1B,GAAG,CAACrC,GAAAA,EAAK8B,MAAAA,CAAAA;IAE3B,OAAOA,MAAAA;AACT;AAEA;;;;;;;;;;;IAYA,MAAMuC,8BAA8B,CAAC3F,KAAAA,GAAAA;IACnC,MAAM4F,WAAAA,GAAclD,MAAAA,CAAOC,QAAQ,CAAC3C,KAAAA,CAAAA;AACpC,IAAA,IACE,WAAC4F,CAAgF3F,aAAa,EAC1FC,MAAMC,SAAAA,EACV;QACA,OAAO;YAAE0F,aAAAA,EAAe;gBAAEvC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA,YAAA;AAAc,oBAAA,aAAA;AAAe,oBAAA;AAAY;AAAC;AAAE,SAAA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;;;;;;"}
@@ -321,8 +321,7 @@ const getDeepPopulateDraftCount = (uid)=>{
321
321
  // Populate all relations, components and media
322
322
  if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {
323
323
  const populatePath = path.attribute.replace(/\./g, '.populate.');
324
- // @ts-expect-error - lodash doesn't resolve the Populate type correctly
325
- populateQuery = set(populatePath, {}, populateQuery);
324
+ populateQuery = merge(populateQuery, set(populatePath, {}, {}));
326
325
  }
327
326
  }, {
328
327
  schema: strapi.getModel(uid),
@@ -1 +1 @@
1
- {"version":3,"file":"populate.mjs","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport * as strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n): { on: { [key: string]: { populate: { [key: string]: boolean | object } } } } {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n): { [key: string]: boolean | object } => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema): { populate: any; hasRelations: boolean } => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n // Self-referential relations are preserved on publish (see self-referential-relations.ts).\n if (attribute.target === uid) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n // Draft entries link to draft rows of related documents. Populate documentId/locale\n // so we can distinguish truly unpublished targets from published documents that\n // still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).\n const fields: string[] = ['documentId'];\n if (isLocalizedContentType(targetModel)) {\n fields.push('locale');\n }\n populateAcc[attributeName] = {\n fields,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n // @ts-expect-error - lodash doesn't resolve the Populate type correctly\n populateQuery = set(populatePath, {}, populateQuery);\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isLocalizedContentType","model","pluginOptions","i18n","localized","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","localizations"],"mappings":";;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,YAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,YAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,WAAAA,CAAYC,YAAY,CAACI,SAAS;AAErE,MAAMC,sBAAAA,GAAyB,CAACC,KAAAA,GAC7BA,MAAMC,aAAa,EAAqDC,MAAMC,SAAAA,KAAc,IAAA;AAE/F,MAAMC,iBAAAA,GAAoB,CAACC,SAAAA,GACzBC,UAAAA,CAAWD,cAAcA,SAAAA,CAAUE,QAAQ,CAACC,QAAQ,CAAC,SAAA,CAAA;AACvD,MAAMC,OAAAA,GAAUC,OAAO,MAAA,EAAQ,OAAA,CAAA;AAC/B,MAAMJ,UAAAA,GAAaI,OAAO,MAAA,EAAQ,UAAA,CAAA;AAClC,MAAMC,WAAAA,GAAcD,OAAO,MAAA,EAAQ,WAAA,CAAA;AACnC,MAAME,aAAAA,GAAgBF,OAAO,MAAA,EAAQ,aAAA,CAAA;AAarC;;;;;;;AAOC,IACD,SAASG,sBAAAA,CACPR,SAAwC,EACxCL,KAAY,EACZc,aAAqB,EACrB,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,eAAe,EAAmB,EAAA;AAEzD,IAAA,MAAMC,iBAAiBvB,WAAAA,CAAYU,SAAAA,CAAAA;;AAGnC,IAAA,IAAIY,oBAAoBE,SAAAA,EAAW;QACjC,OAAOF,eAAAA;AACT,IAAA;;;AAIA,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AA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;"}
1
+ {"version":3,"file":"populate.mjs","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport * as strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n): { on: { [key: string]: { populate: { [key: string]: boolean | object } } } } {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n): { [key: string]: boolean | object } => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema): { populate: any; hasRelations: boolean } => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n // Self-referential relations are preserved on publish (see self-referential-relations.ts).\n if (attribute.target === uid) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n // Draft entries link to draft rows of related documents. Populate documentId/locale\n // so we can distinguish truly unpublished targets from published documents that\n // still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).\n const fields: string[] = ['documentId'];\n if (isLocalizedContentType(targetModel)) {\n fields.push('locale');\n }\n populateAcc[attributeName] = {\n fields,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n populateQuery = merge(populateQuery, set(populatePath, {}, {}));\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isLocalizedContentType","model","pluginOptions","i18n","localized","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","localizations"],"mappings":";;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,YAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,YAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,WAAAA,CAAYC,YAAY,CAACI,SAAS;AAErE,MAAMC,sBAAAA,GAAyB,CAACC,KAAAA,GAC7BA,MAAMC,aAAa,EAAqDC,MAAMC,SAAAA,KAAc,IAAA;AAE/F,MAAMC,iBAAAA,GAAoB,CAACC,SAAAA,GACzBC,UAAAA,CAAWD,cAAcA,SAAAA,CAAUE,QAAQ,CAACC,QAAQ,CAAC,SAAA,CAAA;AACvD,MAAMC,OAAAA,GAAUC,OAAO,MAAA,EAAQ,OAAA,CAAA;AAC/B,MAAMJ,UAAAA,GAAaI,OAAO,MAAA,EAAQ,UAAA,CAAA;AAClC,MAAMC,WAAAA,GAAcD,OAAO,MAAA,EAAQ,WAAA,CAAA;AACnC,MAAME,aAAAA,GAAgBF,OAAO,MAAA,EAAQ,aAAA,CAAA;AAarC;;;;;;;AAOC,IACD,SAASG,sBAAAA,CACPR,SAAwC,EACxCL,KAAY,EACZc,aAAqB,EACrB,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,eAAe,EAAmB,EAAA;AAEzD,IAAA,MAAMC,iBAAiBvB,WAAAA,CAAYU,SAAAA,CAAAA;;A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BhF,CAAC;AAIF,QAAA,MAAM,iBAAiB,GAAU,KAAK,GAAG,CAAC,cAAc,iBAcvD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,2BAA2B,GAAI,OAAO,GAAG,CAAC,MAAM;;;;;;CAUrD,CAAC;AAEF,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,2BAA2B,GAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/content-manager",
3
- "version": "5.51.2",
3
+ "version": "5.52.0",
4
4
  "description": "A powerful UI to easily manage your data.",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -73,19 +73,19 @@
73
73
  "@radix-ui/react-toolbar": "1.1.11",
74
74
  "@reduxjs/toolkit": "1.9.7",
75
75
  "@sindresorhus/slugify": "1.1.0",
76
- "@strapi/design-system": "2.2.3",
77
- "@strapi/icons": "2.2.3",
78
- "@strapi/types": "5.51.2",
79
- "@strapi/utils": "5.51.2",
76
+ "@strapi/design-system": "2.2.4",
77
+ "@strapi/icons": "2.2.4",
78
+ "@strapi/types": "5.52.0",
79
+ "@strapi/utils": "5.52.0",
80
80
  "codemirror5": "npm:codemirror@^5.65.11",
81
81
  "date-fns": "2.30.0",
82
- "dompurify": "3.4.12",
82
+ "dompurify": "3.4.13",
83
83
  "fractional-indexing": "3.2.0",
84
84
  "highlight.js": "^10.4.1",
85
85
  "immer": "9.0.21",
86
86
  "koa": "2.16.4",
87
87
  "lodash": "4.18.1",
88
- "markdown-it": "14.2.0",
88
+ "markdown-it": "14.3.0",
89
89
  "markdown-it-abbr": "^1.0.4",
90
90
  "markdown-it-container": "^3.0.0",
91
91
  "markdown-it-deflist": "^2.1.0",
@@ -111,8 +111,8 @@
111
111
  "zod": "3.25.76"
112
112
  },
113
113
  "devDependencies": {
114
- "@strapi/admin": "5.51.2",
115
- "@strapi/database": "5.51.2",
114
+ "@strapi/admin": "5.52.0",
115
+ "@strapi/database": "5.52.0",
116
116
  "@testing-library/dom": "10.4.1",
117
117
  "@testing-library/jest-dom": "6.9.1",
118
118
  "@testing-library/react": "16.3.2",