@strapi/content-manager 5.15.1 → 5.16.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.
- package/dist/admin/hooks/useDocumentActions.js +7 -3
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs +7 -3
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +12 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +12 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +54 -14
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +55 -15
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.js +4 -2
- package/dist/admin/pages/EditView/components/FormInputs/UID.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs +4 -2
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.js +1 -0
- package/dist/admin/pages/ListView/components/Filters.js.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.mjs +1 -0
- package/dist/admin/pages/ListView/components/Filters.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/TableActions.js +13 -3
- package/dist/admin/pages/ListView/components/TableActions.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableActions.mjs +13 -3
- package/dist/admin/pages/ListView/components/TableActions.mjs.map +1 -1
- package/dist/admin/services/documents.js +2 -2
- package/dist/admin/services/documents.js.map +1 -1
- package/dist/admin/services/documents.mjs +2 -2
- package/dist/admin/services/documents.mjs.map +1 -1
- package/dist/admin/src/hooks/useDocumentActions.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/UID.d.ts +1 -0
- package/dist/admin/src/services/documents.d.ts +7 -1
- package/dist/admin/utils/validation.js +1 -1
- package/dist/admin/utils/validation.js.map +1 -1
- package/dist/admin/utils/validation.mjs +1 -1
- package/dist/admin/utils/validation.mjs.map +1 -1
- package/dist/server/controllers/content-types.js +11 -1
- package/dist/server/controllers/content-types.js.map +1 -1
- package/dist/server/controllers/content-types.mjs +11 -1
- package/dist/server/controllers/content-types.mjs.map +1 -1
- package/dist/server/controllers/validation/index.js +14 -2
- package/dist/server/controllers/validation/index.js.map +1 -1
- package/dist/server/controllers/validation/index.mjs +14 -2
- package/dist/server/controllers/validation/index.mjs.map +1 -1
- package/dist/server/services/data-mapper.js +4 -1
- package/dist/server/services/data-mapper.js.map +1 -1
- package/dist/server/services/data-mapper.mjs +4 -1
- package/dist/server/services/data-mapper.mjs.map +1 -1
- package/dist/server/services/document-manager.js +8 -1
- package/dist/server/services/document-manager.js.map +1 -1
- package/dist/server/services/document-manager.mjs +8 -1
- package/dist/server/services/document-manager.mjs.map +1 -1
- package/dist/server/services/document-metadata.js +2 -0
- package/dist/server/services/document-metadata.js.map +1 -1
- package/dist/server/services/document-metadata.mjs +2 -0
- package/dist/server/services/document-metadata.mjs.map +1 -1
- package/dist/server/services/utils/configuration/attributes.js +1 -1
- package/dist/server/services/utils/configuration/attributes.js.map +1 -1
- package/dist/server/services/utils/configuration/attributes.mjs +1 -1
- package/dist/server/services/utils/configuration/attributes.mjs.map +1 -1
- package/dist/server/services/utils/configuration/layouts.js +1 -1
- package/dist/server/services/utils/configuration/layouts.js.map +1 -1
- package/dist/server/services/utils/configuration/layouts.mjs +1 -1
- package/dist/server/services/utils/configuration/layouts.mjs.map +1 -1
- package/dist/server/services/utils/configuration/metadatas.js +8 -0
- package/dist/server/services/utils/configuration/metadatas.js.map +1 -1
- package/dist/server/services/utils/configuration/metadatas.mjs +8 -0
- package/dist/server/services/utils/configuration/metadatas.mjs.map +1 -1
- package/dist/server/services/utils/populate.js +11 -0
- package/dist/server/services/utils/populate.js.map +1 -1
- package/dist/server/services/utils/populate.mjs +11 -0
- package/dist/server/services/utils/populate.mjs.map +1 -1
- package/dist/server/src/controllers/content-types.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/index.d.ts +6 -1
- package/dist/server/src/controllers/validation/index.d.ts.map +1 -1
- package/dist/server/src/services/data-mapper.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/metadatas.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +0 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlocksEditor.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n return { key, incrementSlateUpdatesCount: () => (slateUpdatesCount.current += 1) };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, handleToggleExpand] = React.useReducer((prev) => !prev, false);\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const handleSlateChange = (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n incrementSlateUpdatesCount();\n\n onChange(name, state as Schema.Attribute.BlocksValue);\n }\n };\n\n const blocks: BlocksStore = {\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n };\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onToggleExpand={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </IconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","handleToggleExpand","useReducer","useImperativeHandle","focus","ReactEditor","handleSlateChange","isAstChange","operations","some","op","type","blocks","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","children","text","modifiers","EditorLayout","onToggleExpand","BlocksToolbar","width","BlocksContent","IconButton","position","bottom","right","shadow","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD,CAAA;AAID,MAAMC,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,OAAO,OAAOA,GAAAA,KAAQ,QAAYF,IAAAA,iBAAAA,CAAkBG,QAAQ,CAACD,GAAAA,CAAAA;AAC/D;AAiBA,MAAM,CAACE,oBAAAA,EAAsBC,6BAA8B,CAAA,GACzDC,yBAAwC,CAAA,cAAA;AAE1C,SAASC,uBACPC,YAAoB,EAAA;AAEpB,IAAA,MAAMC,OAAUJ,GAAAA,6BAAAA,CAA8BG,YAAc,EAAA,CAACE,KAAUA,GAAAA,KAAAA,CAAAA;AACvE,IAAA,MAAMC,MAASC,GAAAA,mBAAAA,EAAAA;IAEf,OAAO;AACL,QAAA,GAAGH,OAAO;AACVE,QAAAA;AACF,KAAA;AACF;AAEA;;AAEkG,qGAElG,MAAME,aAAAA,GAAgBC,uBAAOC,CAA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CAEnBwB,cAACa,CAAAA,2BAAAA,EAAAA,EAAAA,CAAAA;0CACDb,cAACjE,CAAAA,aAAAA,EAAAA;gCAAc+E,KAAM,EAAA;;0CACrBd,cAACe,CAAAA,2BAAAA,EAAAA;AAAe,gCAAA,GAAGnD;;AAClB,4BAAA,CAACc,gCACAsB,cAACgB,CAAAA,uBAAAA,EAAAA;gCACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAOvD,aAAc,CAAA;AACnBoC,oCAAAA,EAAAA,EAAIC,2BAAe,CAAA,0BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAkB,OAAS3C,EAAAA,kBAAAA;AAET,gCAAA,QAAA,gBAAAqB,cAACuB,CAAAA,YAAAA,EAAAA,EAAAA;;;;;AA/BJnG,aAAAA,EAAAA,GAAAA;;;AAuCb,CAAA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"BlocksEditor.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor, Transforms } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n const incrementSlateUpdatesCount = React.useCallback(() => {\n slateUpdatesCount.current += 1;\n }, []);\n\n return { key, incrementSlateUpdatesCount };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, handleToggleExpand] = React.useReducer((prev) => !prev, false);\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const debounceTimeout = React.useRef<NodeJS.Timeout | null>(null);\n\n const handleSlateChange = React.useCallback(\n (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n /**\n * Slate handles the state of the editor internally. We just need to keep Strapi's form\n * state in sync with it in order to make sure that things like the \"modified\" state\n * isn't broken. Updating the whole state on every change is very expensive however,\n * so we debounce calls to onChange to mitigate input lag.\n */\n if (debounceTimeout.current) {\n clearTimeout(debounceTimeout.current);\n }\n\n // Set a new debounce timeout\n debounceTimeout.current = setTimeout(() => {\n incrementSlateUpdatesCount();\n onChange(name, state as Schema.Attribute.BlocksValue);\n debounceTimeout.current = null;\n }, 300);\n }\n },\n [editor.operations, incrementSlateUpdatesCount, name, onChange]\n );\n\n // Clean up the timeout on unmount\n React.useEffect(() => {\n return () => {\n if (debounceTimeout.current) {\n clearTimeout(debounceTimeout.current);\n }\n };\n }, []);\n\n // Ensure the editor is in sync after discard\n React.useEffect(() => {\n // Compare the field value with the editor state to check for a stale selection\n if (value && JSON.stringify(editor.children) !== JSON.stringify(value)) {\n // When there is a diff, unset selection to avoid an invalid state\n Transforms.deselect(editor);\n }\n }, [editor, value]);\n\n const blocks = React.useMemo(\n () => ({\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n }),\n []\n ) satisfies BlocksStore;\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onToggleExpand={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </IconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","useCallback","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","handleToggleExpand","useReducer","useImperativeHandle","focus","ReactEditor","debounceTimeout","handleSlateChange","isAstChange","operations","some","op","type","clearTimeout","setTimeout","JSON","stringify","children","Transforms","deselect","blocks","useMemo","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","text","modifiers","EditorLayout","onToggleExpand","BlocksToolbar","width","BlocksContent","IconButton","position","bottom","right","shadow","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD,CAAA;AAID,MAAMC,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,OAAO,OAAOA,GAAAA,KAAQ,QAAYF,IAAAA,iBAAAA,CAAkBG,QAAQ,CAACD,GAAAA,CAAAA;AAC/D;AAiBA,MAAM,CAACE,oBAAAA,EAAsBC,6BAA8B,CAAA,GACzDC,yBAAwC,CAAA,cAAA;AAE1C,SAASC,uBACPC,Y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AAgBA,EAAAA,cAAAA;AAEhB,oBAAA,QAAA,gBAAA6B,eAACY,CAAAA,yBAAAA,EAAAA;wBACCxD,KAAOA,EAAAA,KAAAA;wBACPH,QAAUA,EAAAA,QAAAA;wBACV4D,cAAgBzC,EAAAA,kBAAAA;wBAChBH,iBAAmBA,EAAAA,iBAAAA;;0CAEnBiC,cAACY,CAAAA,2BAAAA,EAAAA,EAAAA,CAAAA;0CACDZ,cAAC3E,CAAAA,aAAAA,EAAAA;gCAAcwF,KAAM,EAAA;;0CACrBb,cAACc,CAAAA,2BAAAA,EAAAA;AAAe,gCAAA,GAAG3D;;AAClB,4BAAA,CAACc,gCACA+B,cAACe,CAAAA,uBAAAA,EAAAA;gCACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAO/D,aAAc,CAAA;AACnB6C,oCAAAA,EAAAA,EAAIC,2BAAe,CAAA,0BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAiB,OAASnD,EAAAA,kBAAAA;AAET,gCAAA,QAAA,gBAAA8B,cAACsB,CAAAA,YAAAA,EAAAA,EAAAA;;;;;AA/BJ5G,aAAAA,EAAAA,GAAAA;;;AAuCb,CAAA;;;;;;;"}
|
|
@@ -4,7 +4,7 @@ import { createContext } from '@strapi/admin/strapi-admin';
|
|
|
4
4
|
import { Divider, VisuallyHidden, IconButton } from '@strapi/design-system';
|
|
5
5
|
import { Expand } from '@strapi/icons';
|
|
6
6
|
import { useIntl } from 'react-intl';
|
|
7
|
-
import { createEditor } from 'slate';
|
|
7
|
+
import { createEditor, Transforms } from 'slate';
|
|
8
8
|
import { withHistory } from 'slate-history';
|
|
9
9
|
import { ReactEditor, Slate, useSlate, withReact } from 'slate-react';
|
|
10
10
|
import { styled } from 'styled-components';
|
|
@@ -82,9 +82,12 @@ function useBlocksEditorContext(consumerName) {
|
|
|
82
82
|
}, [
|
|
83
83
|
value
|
|
84
84
|
]);
|
|
85
|
+
const incrementSlateUpdatesCount = React.useCallback(()=>{
|
|
86
|
+
slateUpdatesCount.current += 1;
|
|
87
|
+
}, []);
|
|
85
88
|
return {
|
|
86
89
|
key,
|
|
87
|
-
incrementSlateUpdatesCount
|
|
90
|
+
incrementSlateUpdatesCount
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
93
|
const pipe = (...fns)=>(value)=>fns.reduce((prev, fn)=>fn(prev), value);
|
|
@@ -106,22 +109,59 @@ const BlocksEditor = /*#__PURE__*/ React.forwardRef(({ disabled = false, name, o
|
|
|
106
109
|
editor
|
|
107
110
|
]);
|
|
108
111
|
const { key, incrementSlateUpdatesCount } = useResetKey(value);
|
|
109
|
-
const
|
|
112
|
+
const debounceTimeout = React.useRef(null);
|
|
113
|
+
const handleSlateChange = React.useCallback((state)=>{
|
|
110
114
|
const isAstChange = editor.operations.some((op)=>op.type !== 'set_selection');
|
|
111
115
|
if (isAstChange) {
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Slate handles the state of the editor internally. We just need to keep Strapi's form
|
|
118
|
+
* state in sync with it in order to make sure that things like the "modified" state
|
|
119
|
+
* isn't broken. Updating the whole state on every change is very expensive however,
|
|
120
|
+
* so we debounce calls to onChange to mitigate input lag.
|
|
121
|
+
*/ if (debounceTimeout.current) {
|
|
122
|
+
clearTimeout(debounceTimeout.current);
|
|
123
|
+
}
|
|
124
|
+
// Set a new debounce timeout
|
|
125
|
+
debounceTimeout.current = setTimeout(()=>{
|
|
126
|
+
incrementSlateUpdatesCount();
|
|
127
|
+
onChange(name, state);
|
|
128
|
+
debounceTimeout.current = null;
|
|
129
|
+
}, 300);
|
|
114
130
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
}, [
|
|
132
|
+
editor.operations,
|
|
133
|
+
incrementSlateUpdatesCount,
|
|
134
|
+
name,
|
|
135
|
+
onChange
|
|
136
|
+
]);
|
|
137
|
+
// Clean up the timeout on unmount
|
|
138
|
+
React.useEffect(()=>{
|
|
139
|
+
return ()=>{
|
|
140
|
+
if (debounceTimeout.current) {
|
|
141
|
+
clearTimeout(debounceTimeout.current);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}, []);
|
|
145
|
+
// Ensure the editor is in sync after discard
|
|
146
|
+
React.useEffect(()=>{
|
|
147
|
+
// Compare the field value with the editor state to check for a stale selection
|
|
148
|
+
if (value && JSON.stringify(editor.children) !== JSON.stringify(value)) {
|
|
149
|
+
// When there is a diff, unset selection to avoid an invalid state
|
|
150
|
+
Transforms.deselect(editor);
|
|
151
|
+
}
|
|
152
|
+
}, [
|
|
153
|
+
editor,
|
|
154
|
+
value
|
|
155
|
+
]);
|
|
156
|
+
const blocks = React.useMemo(()=>({
|
|
157
|
+
...paragraphBlocks,
|
|
158
|
+
...headingBlocks,
|
|
159
|
+
...listBlocks,
|
|
160
|
+
...linkBlocks,
|
|
161
|
+
...imageBlocks,
|
|
162
|
+
...quoteBlocks,
|
|
163
|
+
...codeBlocks
|
|
164
|
+
}), []);
|
|
125
165
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
126
166
|
children: [
|
|
127
167
|
/*#__PURE__*/ jsx(VisuallyHidden, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlocksEditor.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n return { key, incrementSlateUpdatesCount: () => (slateUpdatesCount.current += 1) };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, handleToggleExpand] = React.useReducer((prev) => !prev, false);\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const handleSlateChange = (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n incrementSlateUpdatesCount();\n\n onChange(name, state as Schema.Attribute.BlocksValue);\n }\n };\n\n const blocks: BlocksStore = {\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n };\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onToggleExpand={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </IconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","handleToggleExpand","useReducer","useImperativeHandle","focus","ReactEditor","handleSlateChange","isAstChange","operations","some","op","type","blocks","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","children","text","modifiers","EditorLayout","onToggleExpand","BlocksToolbar","width","BlocksContent","IconButton","position","bottom","right","shadow","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD,CAAA;AAID,MAAMC,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,OAAO,OAAOA,GAAAA,KAAQ,QAAYF,IAAAA,iBAAAA,CAAkBG,QAAQ,CAACD,GAAAA,CAAAA;AAC/D;AAiBA,MAAM,CAACE,oBAAAA,EAAsBC,6BAA8B,CAAA,GACzDC,aAAwC,CAAA,cAAA;AAE1C,SAASC,uBACPC,YAAoB,EAAA;AAEpB,IAAA,MAAMC,OAAUJ,GAAAA,6BAAAA,CAA8BG,YAAc,EAAA,CAACE,KAAUA,GAAAA,KAAAA,CAAAA;AACvE,IAAA,MAAMC,MAASC,GAAAA,QAAAA,EAAAA;IAEf,OAAO;AACL,QAAA,GAAGH,OAAO;AACVE,QAAAA;AACF,KAAA;AACF;AAEA;;AAEkG,qGAElG,MAAME,aAAAA,GAAgBC,MAAOC,CAAAA,OAAAA,CAAQ;cACvB,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACC,UAAU,CAAC;AACvD,CAAC;AAED;;;;;;;IAQA,SAASC,YAAYC,KAAoC,EAAA;;IAKvD,MAAMC,iBAAAA,GAAoBC,KA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CACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAOvD,aAAc,CAAA;AACnBoC,oCAAAA,EAAAA,EAAIC,cAAe,CAAA,0BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAkB,OAAS3C,EAAAA,kBAAAA;AAET,gCAAA,QAAA,gBAAAqB,GAACuB,CAAAA,MAAAA,EAAAA,EAAAA;;;;;AA/BJnG,aAAAA,EAAAA,GAAAA;;;AAuCb,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"BlocksEditor.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor, Transforms } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n const incrementSlateUpdatesCount = React.useCallback(() => {\n slateUpdatesCount.current += 1;\n }, []);\n\n return { key, incrementSlateUpdatesCount };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, handleToggleExpand] = React.useReducer((prev) => !prev, false);\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const debounceTimeout = React.useRef<NodeJS.Timeout | null>(null);\n\n const handleSlateChange = React.useCallback(\n (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n /**\n * Slate handles the state of the editor internally. We just need to keep Strapi's form\n * state in sync with it in order to make sure that things like the \"modified\" state\n * isn't broken. Updating the whole state on every change is very expensive however,\n * so we debounce calls to onChange to mitigate input lag.\n */\n if (debounceTimeout.current) {\n clearTimeout(debounceTimeout.current);\n }\n\n // Set a new debounce timeout\n debounceTimeout.current = setTimeout(() => {\n incrementSlateUpdatesCount();\n onChange(name, state as Schema.Attribute.BlocksValue);\n debounceTimeout.current = null;\n }, 300);\n }\n },\n [editor.operations, incrementSlateUpdatesCount, name, onChange]\n );\n\n // Clean up the timeout on unmount\n React.useEffect(() => {\n return () => {\n if (debounceTimeout.current) {\n clearTimeout(debounceTimeout.current);\n }\n };\n }, []);\n\n // Ensure the editor is in sync after discard\n React.useEffect(() => {\n // Compare the field value with the editor state to check for a stale selection\n if (value && JSON.stringify(editor.children) !== JSON.stringify(value)) {\n // When there is a diff, unset selection to avoid an invalid state\n Transforms.deselect(editor);\n }\n }, [editor, value]);\n\n const blocks = React.useMemo(\n () => ({\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n }),\n []\n ) satisfies BlocksStore;\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onToggleExpand={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </IconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","useCallback","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","handleToggleExpand","useReducer","useImperativeHandle","focus","ReactEditor","debounceTimeout","handleSlateChange","isAstChange","operations","some","op","type","clearTimeout","setTimeout","JSON","stringify","children","Transforms","deselect","blocks","useMemo","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","text","modifiers","EditorLayout","onToggleExpand","BlocksToolbar","width","BlocksContent","IconButton","position","bottom","right","shadow","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD,CAAA;AAID,MAAMC,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,OAAO,OAAOA,GAAAA,KAAQ,QAAYF,IAAAA,iBAAAA,CAAkBG,QAAQ,CAACD,GAAAA,CAAAA;AAC/D;AAiBA,MAAM,CAACE,oBAAAA,EAAsBC,6BAA8B,CAAA,GACzDC,aAAwC,CAAA,cAAA;AAE1C,SAASC,uBACPC,YAAoB,EAAA;AAEpB,IAAA,MAAMC,OAAUJ,GAAAA,6BAAAA,CAA8BG,YAAc,EAAA,CAACE,KAAUA,GAAAA,KAAAA,CAAAA;AACvE,IAAA,MAAMC,MAASC,GAAAA,QAAAA,EAAAA;IAEf,OAAO;AACL,QAAA,GAAGH,OAAO;AACVE,QAAAA;AACF,KAAA;AACF;AAEA;;AAEkG,qGAElG,MAAME,aAAAA,G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wF,KAAM,EAAA;;0CACrBb,GAACc,CAAAA,aAAAA,EAAAA;AAAe,gCAAA,GAAG3D;;AAClB,4BAAA,CAACc,gCACA+B,GAACe,CAAAA,UAAAA,EAAAA;gCACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAO/D,aAAc,CAAA;AACnB6C,oCAAAA,EAAAA,EAAIC,cAAe,CAAA,0BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAiB,OAASnD,EAAAA,kBAAAA;AAET,gCAAA,QAAA,gBAAA8B,GAACsB,CAAAA,MAAAA,EAAAA,EAAAA;;;;;AA/BJ5G,aAAAA,EAAAA,GAAAA;;;AAuCb,CAAA;;;;"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var Toolbar = require('@radix-ui/react-toolbar');
|
|
6
|
-
require('@strapi/admin/strapi-admin');
|
|
7
6
|
var designSystem = require('@strapi/design-system');
|
|
8
7
|
var Icons = require('@strapi/icons');
|
|
9
8
|
var reactIntl = require('react-intl');
|
|
@@ -306,8 +305,8 @@ const isListNode = (node)=>{
|
|
|
306
305
|
return slate.Node.isNode(node) && !slate.Editor.isEditor(node) && node.type === 'list';
|
|
307
306
|
};
|
|
308
307
|
const ListButton = ({ block, format, location = 'toolbar' })=>{
|
|
309
|
-
const { editor, disabled, blocks } = BlocksEditor.useBlocksEditorContext('ListButton');
|
|
310
308
|
const { formatMessage } = reactIntl.useIntl();
|
|
309
|
+
const { editor, disabled, blocks } = BlocksEditor.useBlocksEditorContext('ListButton');
|
|
311
310
|
const isListActive = ()=>{
|
|
312
311
|
if (!editor.selection) return false;
|
|
313
312
|
// Get the parent list at selection anchor node
|
|
@@ -491,6 +490,7 @@ const BlocksToolbar = ()=>{
|
|
|
491
490
|
return false;
|
|
492
491
|
}
|
|
493
492
|
const selectedNode = editor.children[editor.selection.anchor.path[0]];
|
|
493
|
+
if (!selectedNode) return true;
|
|
494
494
|
if ([
|
|
495
495
|
'image',
|
|
496
496
|
'code'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlocksToolbar.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport * as Toolbar from '@radix-ui/react-toolbar';\nimport { useElementOnScreen } from '@strapi/admin/strapi-admin';\nimport {\n Flex,\n Tooltip,\n SingleSelect,\n SingleSelectOption,\n Box,\n FlexComponent,\n BoxComponent,\n Menu,\n IconButton,\n} from '@strapi/design-system';\nimport { Link, More } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, Transforms, Element as SlateElement, Node, type Ancestor } from 'slate';\nimport { ReactEditor } from 'slate-react';\nimport { css, styled } from 'styled-components';\n\nimport { EditorToolbarObserver } from '../../EditorToolbarObserver';\n\nimport {\n type BlocksStore,\n type SelectorBlockKey,\n isSelectorBlockKey,\n useBlocksEditorContext,\n} from './BlocksEditor';\nimport { insertLink } from './utils/links';\nimport { type Block, getEntries, getKeys } from './utils/types';\n\nconst ToolbarWrapper = styled<FlexComponent>(Flex)`\n &[aria-disabled='true'] {\n cursor: not-allowed;\n background: ${({ theme }) => theme.colors.neutral150};\n }\n`;\n\nconst ToolbarSeparator = styled(Toolbar.Separator)`\n background: ${({ theme }) => theme.colors.neutral150};\n width: 1px;\n height: 2.4rem;\n margin-left: 0.8rem;\n margin-right: 0.8rem;\n`;\n\nconst FlexButton = styled<FlexComponent<'button'>>(Flex)`\n // Inherit the not-allowed cursor from ToolbarWrapper when disabled\n &[aria-disabled] {\n cursor: not-allowed;\n }\n\n &[aria-disabled='false'] {\n cursor: pointer;\n\n // Only apply hover styles if the button is enabled\n &:hover {\n background: ${({ theme }) => theme.colors.primary100};\n }\n }\n`;\n\nconst SelectWrapper = styled<BoxComponent>(Box)`\n // Styling changes to SingleSelect component don't work, so adding wrapper to target SingleSelect\n div[role='combobox'] {\n border: none;\n cursor: pointer;\n min-height: unset;\n padding-top: 6px;\n padding-bottom: 6px;\n\n &[aria-disabled='false']:hover {\n cursor: pointer;\n background: ${({ theme }) => theme.colors.primary100};\n }\n\n &[aria-disabled] {\n background: transparent;\n cursor: inherit;\n\n // Select text and icons should also have disabled color\n span {\n color: ${({ theme }) => theme.colors.neutral600};\n }\n }\n }\n`;\n\n/**\n * Handles the modal component that may be returned by a block when converting it\n */\nfunction useConversionModal() {\n const [modalElement, setModalComponent] = React.useState<React.JSX.Element | null>(null);\n\n const handleConversionResult = (renderModal: void | (() => React.JSX.Element) | undefined) => {\n // Not all blocks return a modal\n if (renderModal) {\n // Use cloneElement to apply a key because to create a new instance of the component\n // Without the new key, the state is kept from previous times that option was picked\n setModalComponent(React.cloneElement(renderModal(), { key: Date.now() }));\n }\n };\n\n return { modalElement, handleConversionResult };\n}\n\ninterface ToolbarButtonProps {\n icon: React.ComponentType<React.SVGProps<SVGSVGElement>>;\n name: string;\n label: MessageDescriptor;\n isActive: boolean;\n disabled: boolean;\n handleClick: () => void;\n}\n\nconst ToolbarButton = ({\n icon: Icon,\n name,\n label,\n isActive,\n disabled,\n handleClick,\n}: ToolbarButtonProps) => {\n const { editor } = useBlocksEditorContext('ToolbarButton');\n const { formatMessage } = useIntl();\n const labelMessage = formatMessage(label);\n\n const enabledColor = isActive ? 'primary600' : 'neutral600';\n\n return (\n <Tooltip label={labelMessage}>\n <Toolbar.ToggleItem\n value={name}\n data-state={isActive ? 'on' : 'off'}\n onMouseDown={(e) => {\n e.preventDefault();\n handleClick();\n ReactEditor.focus(editor);\n }}\n aria-disabled={disabled}\n disabled={disabled}\n aria-label={labelMessage}\n asChild\n >\n <FlexButton\n tag=\"button\"\n background={isActive ? 'primary100' : ''}\n alignItems=\"center\"\n justifyContent=\"center\"\n width={7}\n height={7}\n hasRadius\n >\n <Icon fill={disabled ? 'neutral300' : enabledColor} />\n </FlexButton>\n </Toolbar.ToggleItem>\n </Tooltip>\n );\n};\n\nconst BlocksDropdown = () => {\n const { editor, blocks, disabled } = useBlocksEditorContext('BlocksDropdown');\n const { formatMessage } = useIntl();\n const { modalElement, handleConversionResult } = useConversionModal();\n\n const blockKeysToInclude: SelectorBlockKey[] = getEntries(blocks).reduce<\n ReturnType<typeof getEntries>\n >((currentKeys, entry) => {\n const [key, block] = entry;\n\n return block.isInBlocksSelector ? [...currentKeys, key] : currentKeys;\n }, []);\n\n const [blockSelected, setBlockSelected] = React.useState<SelectorBlockKey>('paragraph');\n\n const handleSelect = (optionKey: unknown) => {\n if (!isSelectorBlockKey(optionKey)) {\n return;\n }\n\n const editorIsEmpty =\n editor.children.length === 1 && Editor.isEmpty(editor, editor.children[0]);\n\n if (!editor.selection && !editorIsEmpty) {\n // When there is no selection, create an empty block at the end of the editor\n // so that it can be converted to the selected block\n Transforms.insertNodes(\n editor,\n {\n type: 'quote',\n children: [{ type: 'text', text: '' }],\n },\n {\n select: true,\n // Since there's no selection, Slate will automatically insert the node at the end\n }\n );\n } else if (!editor.selection && editorIsEmpty) {\n // When there is no selection and the editor is empty,\n // select the empty paragraph from Slate's initialValue so it gets converted\n Transforms.select(editor, Editor.start(editor, [0, 0]));\n }\n\n // If selection is already a list block, toggle its format\n const currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n });\n\n if (currentListEntry && ['list-ordered', 'list-unordered'].includes(optionKey)) {\n const [currentList, currentListPath] = currentListEntry;\n const format = optionKey === 'list-ordered' ? 'ordered' : 'unordered';\n\n if (!Editor.isEditor(currentList) && isListNode(currentList)) {\n // Format is different, toggle list format\n if (currentList.format !== format) {\n Transforms.setNodes(editor, { format }, { at: currentListPath });\n }\n }\n return;\n }\n\n // Let the block handle the Slate conversion logic\n const maybeRenderModal = blocks[optionKey].handleConvert?.(editor);\n handleConversionResult(maybeRenderModal);\n\n setBlockSelected(optionKey);\n\n ReactEditor.focus(editor);\n };\n\n /**\n * Prevent the select from focusing itself so ReactEditor.focus(editor) can focus the editor instead.\n *\n * The editor first loses focus to a blur event when clicking the select button. However,\n * refocusing the editor is not enough since the select's default behavior is to refocus itself\n * after an option is selected.\n *\n */\n const preventSelectFocus = (e: Event) => e.preventDefault();\n\n // Listen to the selection change and update the selected block in the dropdown\n React.useEffect(() => {\n if (editor.selection) {\n let selectedNode: Ancestor;\n\n // If selection anchor is a list-item, get its parent\n const currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n at: editor.selection.anchor,\n });\n\n if (currentListEntry) {\n const [currentList] = currentListEntry;\n selectedNode = currentList;\n } else {\n // Get the parent node of the anchor other than list-item\n const [anchorNode] = Editor.parent(editor, editor.selection.anchor, {\n edge: 'start',\n depth: 2,\n });\n\n // @ts-expect-error slate's delete behaviour creates an exceptional type\n if (anchorNode.type === 'list-item') {\n // When the last node in the selection is a list item,\n // slate's default delete operation leaves an empty list-item instead of converting it into a paragraph.\n // Issue: https://github.com/ianstormtaylor/slate/issues/2500\n\n Transforms.setNodes(editor, { type: 'paragraph' });\n // @ts-expect-error convert explicitly type to paragraph\n selectedNode = { ...anchorNode, type: 'paragraph' };\n } else {\n selectedNode = anchorNode;\n }\n }\n\n // Find the block key that matches the anchor node\n const anchorBlockKey = getKeys(blocks).find(\n (blockKey) => !Editor.isEditor(selectedNode) && blocks[blockKey].matchNode(selectedNode)\n );\n\n // Change the value selected in the dropdown if it doesn't match the anchor block key\n if (anchorBlockKey && anchorBlockKey !== blockSelected) {\n setBlockSelected(anchorBlockKey as SelectorBlockKey);\n }\n }\n }, [editor.selection, editor, blocks, blockSelected]);\n\n const Icon = blocks[blockSelected].icon;\n\n return (\n <>\n <SelectWrapper>\n <SingleSelect\n startIcon={<Icon />}\n onChange={handleSelect}\n placeholder={formatMessage(blocks[blockSelected].label)}\n value={blockSelected}\n onCloseAutoFocus={preventSelectFocus}\n aria-label={formatMessage({\n id: 'components.Blocks.blocks.selectBlock',\n defaultMessage: 'Select a block',\n })}\n disabled={disabled}\n >\n {blockKeysToInclude.map((key) => (\n <BlockOption\n key={key}\n value={key}\n label={blocks[key].label}\n icon={blocks[key].icon}\n blockSelected={blockSelected}\n />\n ))}\n </SingleSelect>\n </SelectWrapper>\n {modalElement}\n </>\n );\n};\n\ninterface BlockOptionProps {\n value: string;\n icon: React.ComponentType<React.SVGProps<SVGElement>>;\n label: MessageDescriptor;\n blockSelected: string;\n}\n\nconst BlockOption = ({ value, icon: Icon, label, blockSelected }: BlockOptionProps) => {\n const { formatMessage } = useIntl();\n\n const isSelected = value === blockSelected;\n\n return (\n <SingleSelectOption\n startIcon={<Icon fill={isSelected ? 'primary600' : 'neutral500'} />}\n value={value}\n >\n {formatMessage(label)}\n </SingleSelectOption>\n );\n};\n\nconst isListNode = (node: unknown): node is Block<'list'> => {\n return Node.isNode(node) && !Editor.isEditor(node) && node.type === 'list';\n};\n\ninterface ListButtonProps {\n block: BlocksStore['list-ordered'] | BlocksStore['list-unordered'];\n format: Block<'list'>['format'];\n location?: 'toolbar' | 'menu';\n}\n\nconst ListButton = ({ block, format, location = 'toolbar' }: ListButtonProps) => {\n const { editor, disabled, blocks } = useBlocksEditorContext('ListButton');\n const { formatMessage } = useIntl();\n\n const isListActive = () => {\n if (!editor.selection) return false;\n\n // Get the parent list at selection anchor node\n const currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n at: editor.selection.anchor,\n });\n\n if (currentListEntry) {\n const [currentList] = currentListEntry;\n if (!Editor.isEditor(currentList) && isListNode(currentList) && currentList.format === format)\n return true;\n }\n return false;\n };\n\n /**\n * @TODO: Currently, applying list while multiple blocks are selected is not supported.\n * We should implement this feature in the future.\n */\n const isListDisabled = () => {\n // Always disabled when the whole editor is disabled\n if (disabled) {\n return true;\n }\n\n // Always enabled when there's no selection\n if (!editor.selection) {\n return false;\n }\n\n // Get the block node closest to the anchor and focus\n const anchorNodeEntry = Editor.above(editor, {\n at: editor.selection.anchor,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n const focusNodeEntry = Editor.above(editor, {\n at: editor.selection.focus,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n\n if (!anchorNodeEntry || !focusNodeEntry) {\n return false;\n }\n\n // Disabled if the anchor and focus are not in the same block\n return anchorNodeEntry[0] !== focusNodeEntry[0];\n };\n\n const toggleList = (format: Block<'list'>['format']) => {\n let currentListEntry;\n if (editor.selection) {\n currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n });\n } else {\n // If no selection, toggle last inserted node\n const [_, lastNodePath] = Editor.last(editor, []);\n currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n at: lastNodePath,\n });\n }\n\n if (!currentListEntry) {\n // If selection is not a list then convert it to list\n blocks[`list-${format}`].handleConvert!(editor);\n return;\n }\n\n // If selection is already a list then toggle format\n const [currentList, currentListPath] = currentListEntry;\n\n if (!Editor.isEditor(currentList) && isListNode(currentList)) {\n if (currentList.format !== format) {\n // Format is different, toggle list format\n Transforms.setNodes(editor, { format }, { at: currentListPath });\n } else {\n // Format is same, convert selected list-item to paragraph\n blocks['paragraph'].handleConvert!(editor);\n }\n }\n };\n\n if (location === 'menu') {\n const Icon = block.icon;\n\n return (\n <StyledMenuItem\n startIcon={<Icon />}\n onSelect={() => toggleList(format)}\n isActive={isListActive()}\n disabled={isListDisabled()}\n >\n {formatMessage(block.label)}\n </StyledMenuItem>\n );\n }\n\n return (\n <ToolbarButton\n icon={block.icon}\n name={format}\n label={block.label}\n isActive={isListActive()}\n disabled={isListDisabled()}\n handleClick={() => toggleList(format)}\n />\n );\n};\n\nconst LinkButton = ({\n disabled,\n location = 'toolbar',\n}: {\n disabled: boolean;\n location?: 'toolbar' | 'menu';\n}) => {\n const { editor } = useBlocksEditorContext('LinkButton');\n const { formatMessage } = useIntl();\n\n const isLinkActive = () => {\n const { selection } = editor;\n\n if (!selection) return false;\n\n const [match] = Array.from(\n Editor.nodes(editor, {\n at: Editor.unhangRange(editor, selection),\n match: (node) => SlateElement.isElement(node) && node.type === 'link',\n })\n );\n\n return Boolean(match);\n };\n\n const isLinkDisabled = () => {\n // Always disabled when the whole editor is disabled\n if (disabled) {\n return true;\n }\n\n // Always enabled when there's no selection\n if (!editor.selection) {\n return false;\n }\n\n // Get the block node closest to the anchor and focus\n const anchorNodeEntry = Editor.above(editor, {\n at: editor.selection.anchor,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n const focusNodeEntry = Editor.above(editor, {\n at: editor.selection.focus,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n\n if (!anchorNodeEntry || !focusNodeEntry) {\n return false;\n }\n\n // Disabled if the anchor and focus are not in the same block\n return anchorNodeEntry[0] !== focusNodeEntry[0];\n };\n\n const addLink = () => {\n editor.shouldSaveLinkPath = true;\n // We insert an empty anchor, so we split the DOM to have a element we can use as reference for the popover\n insertLink(editor, { url: '' });\n };\n\n const label = {\n id: 'components.Blocks.link',\n defaultMessage: 'Link',\n } as MessageDescriptor;\n\n if (location === 'menu') {\n return (\n <StyledMenuItem\n startIcon={<Link />}\n onSelect={addLink}\n isActive={isLinkActive()}\n disabled={isLinkDisabled()}\n >\n {formatMessage(label)}\n </StyledMenuItem>\n );\n }\n\n return (\n <ToolbarButton\n icon={Link}\n name=\"link\"\n label={label}\n isActive={isLinkActive()}\n handleClick={addLink}\n disabled={isLinkDisabled()}\n />\n );\n};\n\ninterface ObservedToolbarComponentProps {\n index: number;\n lastVisibleIndex: number;\n setLastVisibleIndex: React.Dispatch<React.SetStateAction<number>>;\n rootRef: React.RefObject<HTMLElement>;\n children: React.ReactNode;\n}\n\nconst ObservedToolbarComponent = ({\n index,\n lastVisibleIndex,\n setLastVisibleIndex,\n rootRef,\n children,\n}: ObservedToolbarComponentProps) => {\n const isVisible = index <= lastVisibleIndex;\n\n const containerRef = useElementOnScreen<HTMLDivElement>(\n (isVisible) => {\n /**\n * It's the MoreMenu's job to make an item not visible when there's not room for it.\n * But we need to react here to the element becoming visible again.\n */\n if (isVisible) {\n setLastVisibleIndex((prev) => Math.max(prev, index));\n }\n },\n { threshold: 1, root: rootRef.current }\n );\n\n return (\n <div\n ref={containerRef}\n style={{\n /**\n * Use visibility so that the element occupies the space if requires even when there's not\n * enough room for it to be visible. The empty reserved space will be clipped by the\n * overflow:hidden rule on the parent, so it doesn't affect the UI.\n * This way we can keep observing its visiblity and react to browser resize events.\n */\n visibility: isVisible ? 'visible' : 'hidden',\n }}\n >\n {children}\n </div>\n );\n};\n\ninterface ObservedComponent {\n toolbar: React.ReactNode;\n menu: React.ReactNode;\n key: string;\n}\n\ninterface MoreMenuProps {\n setLastVisibleIndex: React.Dispatch<React.SetStateAction<number>>;\n hasHiddenItems: boolean;\n rootRef: React.RefObject<HTMLElement>;\n children: React.ReactNode;\n}\n\nconst MoreMenu = ({ setLastVisibleIndex, hasHiddenItems, rootRef, children }: MoreMenuProps) => {\n const { formatMessage } = useIntl();\n const containerRef = useElementOnScreen<HTMLButtonElement>(\n (isVisible) => {\n // We only react to the menu becoming invisible. When that happens, we hide the last item.\n if (!isVisible) {\n /**\n * If there's no room for any item, the index can be -1.\n * This is intentional, in that case only the more menu will be visible.\n **/\n setLastVisibleIndex((prev) => prev - 1);\n }\n },\n { threshold: 1, root: rootRef.current }\n );\n\n return (\n <Menu.Root defaultOpen={false}>\n <Menu.Trigger\n endIcon={null}\n paddingLeft={0}\n paddingRight={0}\n ref={containerRef}\n style={{ visibility: hasHiddenItems ? 'visible' : 'hidden' }}\n >\n <IconButton\n variant=\"ghost\"\n label={formatMessage({ id: 'global.more', defaultMessage: 'More' })}\n tag=\"span\"\n >\n <More aria-hidden focusable={false} />\n </IconButton>\n </Menu.Trigger>\n <Menu.Content onCloseAutoFocus={(e) => e.preventDefault()}>{children}</Menu.Content>\n </Menu.Root>\n );\n};\n\nconst StyledMenuItem = styled(Menu.Item)<{ isActive: boolean }>`\n ${(props) =>\n props.isActive &&\n css`\n color: ${({ theme }) => theme.colors.primary600};\n font-weight: 600;\n `}\n\n svg {\n fill: ${({ theme, isActive }) =>\n isActive ? theme.colors.primary600 : theme.colors.neutral500};\n }\n`;\n\nconst BlocksToolbar = () => {\n const { editor, blocks, modifiers, disabled } = useBlocksEditorContext('BlocksToolbar');\n const { formatMessage } = useIntl();\n\n /**\n * The modifier buttons are disabled when an image is selected.\n */\n const checkButtonDisabled = () => {\n // Always disabled when the whole editor is disabled\n if (disabled) {\n return true;\n }\n\n if (!editor.selection) {\n return false;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n\n if (['image', 'code'].includes(selectedNode.type)) {\n return true;\n }\n\n return false;\n };\n\n const isButtonDisabled = checkButtonDisabled();\n\n /**\n * Observed components are ones that may or may not be visible in the toolbar, depending on the\n * available space. They provide two render props:\n * - renderInToolbar: for when we try to render the component in the toolbar (may be hidden)\n * - renderInMenu: for when the component didn't fit in the toolbar and is relegated\n * to the \"more\" menu\n */\n const observedComponents: ObservedComponent[] = [\n ...Object.entries(modifiers).map(([name, modifier]) => {\n const Icon = modifier.icon;\n const isActive = modifier.checkIsActive(editor);\n const handleSelect = () => modifier.handleToggle(editor);\n\n return {\n toolbar: (\n <ToolbarButton\n key={name}\n name={name}\n icon={modifier.icon}\n label={modifier.label}\n isActive={modifier.checkIsActive(editor)}\n handleClick={handleSelect}\n disabled={isButtonDisabled}\n />\n ),\n menu: (\n <StyledMenuItem startIcon={<Icon />} onSelect={handleSelect} isActive={isActive}>\n {formatMessage(modifier.label)}\n </StyledMenuItem>\n ),\n key: `modifier.${name}`,\n };\n }),\n {\n toolbar: <LinkButton disabled={isButtonDisabled} location=\"toolbar\" />,\n menu: <LinkButton disabled={isButtonDisabled} location=\"menu\" />,\n key: 'block.link',\n },\n {\n // List buttons can only be rendered together when in the toolbar\n toolbar: (\n <Flex direction=\"row\">\n <ToolbarSeparator style={{ marginLeft: '0.4rem' }} />\n <Toolbar.ToggleGroup type=\"single\" asChild>\n <Flex gap={1}>\n <ListButton block={blocks['list-unordered']} format=\"unordered\" location=\"toolbar\" />\n <ListButton block={blocks['list-ordered']} format=\"ordered\" location=\"toolbar\" />\n </Flex>\n </Toolbar.ToggleGroup>\n </Flex>\n ),\n menu: (\n <>\n <Menu.Separator />\n <ListButton block={blocks['list-unordered']} format=\"unordered\" location=\"menu\" />\n <ListButton block={blocks['list-ordered']} format=\"ordered\" location=\"menu\" />\n </>\n ),\n key: 'block.list',\n },\n ];\n\n return (\n <Toolbar.Root aria-disabled={disabled} asChild>\n <ToolbarWrapper padding={2} width=\"100%\">\n <BlocksDropdown />\n <ToolbarSeparator />\n <Toolbar.ToggleGroup type=\"multiple\" asChild>\n <Flex direction=\"row\" gap={1} grow={1} overflow=\"hidden\">\n <EditorToolbarObserver observedComponents={observedComponents} />\n </Flex>\n </Toolbar.ToggleGroup>\n </ToolbarWrapper>\n </Toolbar.Root>\n );\n};\n\nexport { BlocksToolbar, useConversionModal };\n"],"names":["ToolbarWrapper","styled","Flex","theme","colors","neutral150","ToolbarSeparator","Toolbar","Separator","FlexButton","primary100","SelectWrapper","Box","neutral600","useConversionModal","modalElement","setModalComponent","React","useState","handleConversionResult","renderModal","cloneElement","key","Date","now","ToolbarButton","icon","Icon","name","label","isActive","disabled","handleClick","editor","useBlocksEditorContext","formatMessage","useIntl","labelMessage","enabledColor","_jsx","Tooltip","ToggleItem","value","data-state","onMouseDown","e","preventDefault","ReactEditor","focus","aria-disabled","aria-label","asChild","tag","background","alignItems","justifyContent","width","height","hasRadius","fill","BlocksDropdown","blocks","blockKeysToInclude","getEntries","reduce","currentKeys","entry","block","isInBlocksSelector","blockSelected","setBlockSelected","handleSelect","optionKey","isSelectorBlockKey","editorIsEmpty","children","length","Editor","isEmpty","selection","Transforms","insertNodes","type","text","select","start","currentListEntry","above","match","node","isEditor","includes","currentList","currentListPath","format","isListNode","setNodes","at","maybeRenderModal","handleConvert","preventSelectFocus","useEffect","selectedNode","anchor","anchorNode","parent","edge","depth","anchorBlockKey","getKeys","find","blockKey","matchNode","_jsxs","_Fragment","SingleSelect","startIcon","onChange","placeholder","onCloseAutoFocus","id","defaultMessage","map","BlockOption","isSelected","SingleSelectOption","Node","isNode","ListButton","location","isListActive","isListDisabled","anchorNodeEntry","focusNodeEntry","toggleList","_","lastNodePath","last","StyledMenuItem","onSelect","LinkButton","isLinkActive","Array","from","nodes","unhangRange","SlateElement","isElement","Boolean","isLinkDisabled","addLink","shouldSaveLinkPath","insertLink","url","Link","Menu","Item","props","css","primary600","neutral500","BlocksToolbar","modifiers","checkButtonDisabled","path","isButtonDisabled","observedComponents","Object","entries","modifier","checkIsActive","handleToggle","toolbar","menu","direction","style","marginLeft","ToggleGroup","gap","Root","padding","grow","overflow","EditorToolbarObserver"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAMA,cAAAA,GAAiBC,uBAAsBC,CAAAA,iBAAAA,CAAK;;;gBAGlC,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACC,UAAU,CAAC;;AAEzD,CAAC;AAED,MAAMC,gBAAmBL,GAAAA,uBAAAA,CAAOM,kBAAQC,CAAAA,SAAS,CAAC;cACpC,EAAE,CAAC,EAAEL,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACC,UAAU,CAAC;;;;;AAKvD,CAAC;AAED,MAAMI,UAAAA,GAAaR,uBAAgCC,CAAAA,iBAAAA,CAAK;;;;;;;;;;;kBAWtC,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACM,UAAU,CAAC;;;AAG3D,CAAC;AAED,MAAMC,aAAAA,GAAgBV,uBAAqBW,CAAAA,gBAAAA,CAAI;;;;;;;;;;;kBAW7B,EAAE,CAAC,EAAET,KAAK,EAAE,GAAKA,KAA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AM,CAAC,cAAe,CAAA;wBAAEiC,MAAO,EAAA,SAAA;wBAAUmC,QAAS,EAAA;;;;YAGzE3G,GAAK,EAAA;AACP;AACD,KAAA;IAED,qBACEiB,cAAA,CAAChC,mBAAQ4K,IAAI,EAAA;QAAClI,eAAelB,EAAAA,QAAAA;QAAUoB,OAAO,EAAA,IAAA;AAC5C,QAAA,QAAA,gBAAA8D,eAACjH,CAAAA,cAAAA,EAAAA;YAAeoL,OAAS,EAAA,CAAA;YAAG5H,KAAM,EAAA,MAAA;;8BAChCjB,cAACqB,CAAAA,cAAAA,EAAAA,EAAAA,CAAAA;8BACDrB,cAACjC,CAAAA,gBAAAA,EAAAA,EAAAA,CAAAA;AACD,8BAAAiC,cAAA,CAAChC,mBAAQ0K,WAAW,EAAA;oBAAC/F,IAAK,EAAA,UAAA;oBAAW/B,OAAO,EAAA,IAAA;AAC1C,oBAAA,QAAA,gBAAAZ,cAACrC,CAAAA,iBAAAA,EAAAA;wBAAK4K,SAAU,EAAA,KAAA;wBAAMI,GAAK,EAAA,CAAA;wBAAGG,IAAM,EAAA,CAAA;wBAAGC,QAAS,EAAA,QAAA;AAC9C,wBAAA,QAAA,gBAAA/I,cAACgJ,CAAAA,2CAAAA,EAAAA;4BAAsBjB,kBAAoBA,EAAAA;;;;;;;AAMvD;;;;;"}
|
|
1
|
+
{"version":3,"file":"BlocksToolbar.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport * as Toolbar from '@radix-ui/react-toolbar';\nimport {\n Flex,\n Tooltip,\n SingleSelect,\n SingleSelectOption,\n Box,\n FlexComponent,\n BoxComponent,\n Menu,\n} from '@strapi/design-system';\nimport { Link } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, Transforms, Element as SlateElement, Node, type Ancestor } from 'slate';\nimport { ReactEditor } from 'slate-react';\nimport { css, styled } from 'styled-components';\n\nimport { EditorToolbarObserver, type ObservedComponent } from '../../EditorToolbarObserver';\n\nimport {\n type BlocksStore,\n type SelectorBlockKey,\n isSelectorBlockKey,\n useBlocksEditorContext,\n} from './BlocksEditor';\nimport { insertLink } from './utils/links';\nimport { type Block, getEntries, getKeys } from './utils/types';\n\nconst ToolbarWrapper = styled<FlexComponent>(Flex)`\n &[aria-disabled='true'] {\n cursor: not-allowed;\n background: ${({ theme }) => theme.colors.neutral150};\n }\n`;\n\nconst ToolbarSeparator = styled(Toolbar.Separator)`\n background: ${({ theme }) => theme.colors.neutral150};\n width: 1px;\n height: 2.4rem;\n margin-left: 0.8rem;\n margin-right: 0.8rem;\n`;\n\nconst FlexButton = styled<FlexComponent<'button'>>(Flex)`\n // Inherit the not-allowed cursor from ToolbarWrapper when disabled\n &[aria-disabled] {\n cursor: not-allowed;\n }\n\n &[aria-disabled='false'] {\n cursor: pointer;\n\n // Only apply hover styles if the button is enabled\n &:hover {\n background: ${({ theme }) => theme.colors.primary100};\n }\n }\n`;\n\nconst SelectWrapper = styled<BoxComponent>(Box)`\n // Styling changes to SingleSelect component don't work, so adding wrapper to target SingleSelect\n div[role='combobox'] {\n border: none;\n cursor: pointer;\n min-height: unset;\n padding-top: 6px;\n padding-bottom: 6px;\n\n &[aria-disabled='false']:hover {\n cursor: pointer;\n background: ${({ theme }) => theme.colors.primary100};\n }\n\n &[aria-disabled] {\n background: transparent;\n cursor: inherit;\n\n // Select text and icons should also have disabled color\n span {\n color: ${({ theme }) => theme.colors.neutral600};\n }\n }\n }\n`;\n\n/**\n * Handles the modal component that may be returned by a block when converting it\n */\nfunction useConversionModal() {\n const [modalElement, setModalComponent] = React.useState<React.JSX.Element | null>(null);\n\n const handleConversionResult = (renderModal: void | (() => React.JSX.Element) | undefined) => {\n // Not all blocks return a modal\n if (renderModal) {\n // Use cloneElement to apply a key because to create a new instance of the component\n // Without the new key, the state is kept from previous times that option was picked\n setModalComponent(React.cloneElement(renderModal(), { key: Date.now() }));\n }\n };\n\n return { modalElement, handleConversionResult };\n}\n\ninterface ToolbarButtonProps {\n icon: React.ComponentType<React.SVGProps<SVGSVGElement>>;\n name: string;\n label: MessageDescriptor;\n isActive: boolean;\n disabled: boolean;\n handleClick: () => void;\n}\n\nconst ToolbarButton = ({\n icon: Icon,\n name,\n label,\n isActive,\n disabled,\n handleClick,\n}: ToolbarButtonProps) => {\n const { editor } = useBlocksEditorContext('ToolbarButton');\n const { formatMessage } = useIntl();\n const labelMessage = formatMessage(label);\n\n const enabledColor = isActive ? 'primary600' : 'neutral600';\n\n return (\n <Tooltip label={labelMessage}>\n <Toolbar.ToggleItem\n value={name}\n data-state={isActive ? 'on' : 'off'}\n onMouseDown={(e) => {\n e.preventDefault();\n handleClick();\n ReactEditor.focus(editor);\n }}\n aria-disabled={disabled}\n disabled={disabled}\n aria-label={labelMessage}\n asChild\n >\n <FlexButton\n tag=\"button\"\n background={isActive ? 'primary100' : ''}\n alignItems=\"center\"\n justifyContent=\"center\"\n width={7}\n height={7}\n hasRadius\n >\n <Icon fill={disabled ? 'neutral300' : enabledColor} />\n </FlexButton>\n </Toolbar.ToggleItem>\n </Tooltip>\n );\n};\n\nconst BlocksDropdown = () => {\n const { editor, blocks, disabled } = useBlocksEditorContext('BlocksDropdown');\n const { formatMessage } = useIntl();\n const { modalElement, handleConversionResult } = useConversionModal();\n\n const blockKeysToInclude: SelectorBlockKey[] = getEntries(blocks).reduce<\n ReturnType<typeof getEntries>\n >((currentKeys, entry) => {\n const [key, block] = entry;\n\n return block.isInBlocksSelector ? [...currentKeys, key] : currentKeys;\n }, []);\n\n const [blockSelected, setBlockSelected] = React.useState<SelectorBlockKey>('paragraph');\n\n const handleSelect = (optionKey: unknown) => {\n if (!isSelectorBlockKey(optionKey)) {\n return;\n }\n\n const editorIsEmpty =\n editor.children.length === 1 && Editor.isEmpty(editor, editor.children[0]);\n\n if (!editor.selection && !editorIsEmpty) {\n // When there is no selection, create an empty block at the end of the editor\n // so that it can be converted to the selected block\n Transforms.insertNodes(\n editor,\n {\n type: 'quote',\n children: [{ type: 'text', text: '' }],\n },\n {\n select: true,\n // Since there's no selection, Slate will automatically insert the node at the end\n }\n );\n } else if (!editor.selection && editorIsEmpty) {\n // When there is no selection and the editor is empty,\n // select the empty paragraph from Slate's initialValue so it gets converted\n Transforms.select(editor, Editor.start(editor, [0, 0]));\n }\n\n // If selection is already a list block, toggle its format\n const currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n });\n\n if (currentListEntry && ['list-ordered', 'list-unordered'].includes(optionKey)) {\n const [currentList, currentListPath] = currentListEntry;\n const format = optionKey === 'list-ordered' ? 'ordered' : 'unordered';\n\n if (!Editor.isEditor(currentList) && isListNode(currentList)) {\n // Format is different, toggle list format\n if (currentList.format !== format) {\n Transforms.setNodes(editor, { format }, { at: currentListPath });\n }\n }\n return;\n }\n\n // Let the block handle the Slate conversion logic\n const maybeRenderModal = blocks[optionKey].handleConvert?.(editor);\n handleConversionResult(maybeRenderModal);\n\n setBlockSelected(optionKey);\n\n ReactEditor.focus(editor);\n };\n\n /**\n * Prevent the select from focusing itself so ReactEditor.focus(editor) can focus the editor instead.\n *\n * The editor first loses focus to a blur event when clicking the select button. However,\n * refocusing the editor is not enough since the select's default behavior is to refocus itself\n * after an option is selected.\n *\n */\n const preventSelectFocus = (e: Event) => e.preventDefault();\n\n // Listen to the selection change and update the selected block in the dropdown\n React.useEffect(() => {\n if (editor.selection) {\n let selectedNode: Ancestor;\n\n // If selection anchor is a list-item, get its parent\n const currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n at: editor.selection.anchor,\n });\n\n if (currentListEntry) {\n const [currentList] = currentListEntry;\n selectedNode = currentList;\n } else {\n // Get the parent node of the anchor other than list-item\n const [anchorNode] = Editor.parent(editor, editor.selection.anchor, {\n edge: 'start',\n depth: 2,\n });\n\n // @ts-expect-error slate's delete behaviour creates an exceptional type\n if (anchorNode.type === 'list-item') {\n // When the last node in the selection is a list item,\n // slate's default delete operation leaves an empty list-item instead of converting it into a paragraph.\n // Issue: https://github.com/ianstormtaylor/slate/issues/2500\n\n Transforms.setNodes(editor, { type: 'paragraph' });\n // @ts-expect-error convert explicitly type to paragraph\n selectedNode = { ...anchorNode, type: 'paragraph' };\n } else {\n selectedNode = anchorNode;\n }\n }\n\n // Find the block key that matches the anchor node\n const anchorBlockKey = getKeys(blocks).find(\n (blockKey) => !Editor.isEditor(selectedNode) && blocks[blockKey].matchNode(selectedNode)\n );\n\n // Change the value selected in the dropdown if it doesn't match the anchor block key\n if (anchorBlockKey && anchorBlockKey !== blockSelected) {\n setBlockSelected(anchorBlockKey as SelectorBlockKey);\n }\n }\n }, [editor.selection, editor, blocks, blockSelected]);\n\n const Icon = blocks[blockSelected].icon;\n\n return (\n <>\n <SelectWrapper>\n <SingleSelect\n startIcon={<Icon />}\n onChange={handleSelect}\n placeholder={formatMessage(blocks[blockSelected].label)}\n value={blockSelected}\n onCloseAutoFocus={preventSelectFocus}\n aria-label={formatMessage({\n id: 'components.Blocks.blocks.selectBlock',\n defaultMessage: 'Select a block',\n })}\n disabled={disabled}\n >\n {blockKeysToInclude.map((key) => (\n <BlockOption\n key={key}\n value={key}\n label={blocks[key].label}\n icon={blocks[key].icon}\n blockSelected={blockSelected}\n />\n ))}\n </SingleSelect>\n </SelectWrapper>\n {modalElement}\n </>\n );\n};\n\ninterface BlockOptionProps {\n value: string;\n icon: React.ComponentType<React.SVGProps<SVGElement>>;\n label: MessageDescriptor;\n blockSelected: string;\n}\n\nconst BlockOption = ({ value, icon: Icon, label, blockSelected }: BlockOptionProps) => {\n const { formatMessage } = useIntl();\n\n const isSelected = value === blockSelected;\n\n return (\n <SingleSelectOption\n startIcon={<Icon fill={isSelected ? 'primary600' : 'neutral500'} />}\n value={value}\n >\n {formatMessage(label)}\n </SingleSelectOption>\n );\n};\n\nconst isListNode = (node: unknown): node is Block<'list'> => {\n return Node.isNode(node) && !Editor.isEditor(node) && node.type === 'list';\n};\n\ninterface ListButtonProps {\n block: BlocksStore['list-ordered'] | BlocksStore['list-unordered'];\n format: Block<'list'>['format'];\n location?: 'toolbar' | 'menu';\n}\n\nconst ListButton = ({ block, format, location = 'toolbar' }: ListButtonProps) => {\n const { formatMessage } = useIntl();\n const { editor, disabled, blocks } = useBlocksEditorContext('ListButton');\n\n const isListActive = () => {\n if (!editor.selection) return false;\n\n // Get the parent list at selection anchor node\n const currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n at: editor.selection.anchor,\n });\n\n if (currentListEntry) {\n const [currentList] = currentListEntry;\n if (!Editor.isEditor(currentList) && isListNode(currentList) && currentList.format === format)\n return true;\n }\n\n return false;\n };\n\n /**\n * @TODO: Currently, applying list while multiple blocks are selected is not supported.\n * We should implement this feature in the future.\n */\n const isListDisabled = () => {\n // Always disabled when the whole editor is disabled\n if (disabled) {\n return true;\n }\n\n // Always enabled when there's no selection\n if (!editor.selection) {\n return false;\n }\n\n // Get the block node closest to the anchor and focus\n const anchorNodeEntry = Editor.above(editor, {\n at: editor.selection.anchor,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n const focusNodeEntry = Editor.above(editor, {\n at: editor.selection.focus,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n\n if (!anchorNodeEntry || !focusNodeEntry) {\n return false;\n }\n\n // Disabled if the anchor and focus are not in the same block\n return anchorNodeEntry[0] !== focusNodeEntry[0];\n };\n\n const toggleList = (format: Block<'list'>['format']) => {\n let currentListEntry;\n if (editor.selection) {\n currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n });\n } else {\n // If no selection, toggle last inserted node\n const [_, lastNodePath] = Editor.last(editor, []);\n currentListEntry = Editor.above(editor, {\n match: (node) => !Editor.isEditor(node) && node.type === 'list',\n at: lastNodePath,\n });\n }\n\n if (!currentListEntry) {\n // If selection is not a list then convert it to list\n blocks[`list-${format}`].handleConvert!(editor);\n return;\n }\n\n // If selection is already a list then toggle format\n const [currentList, currentListPath] = currentListEntry;\n\n if (!Editor.isEditor(currentList) && isListNode(currentList)) {\n if (currentList.format !== format) {\n // Format is different, toggle list format\n Transforms.setNodes(editor, { format }, { at: currentListPath });\n } else {\n // Format is same, convert selected list-item to paragraph\n blocks['paragraph'].handleConvert!(editor);\n }\n }\n };\n\n if (location === 'menu') {\n const Icon = block.icon;\n\n return (\n <StyledMenuItem\n startIcon={<Icon />}\n onSelect={() => toggleList(format)}\n isActive={isListActive()}\n disabled={isListDisabled()}\n >\n {formatMessage(block.label)}\n </StyledMenuItem>\n );\n }\n\n return (\n <ToolbarButton\n icon={block.icon}\n name={format}\n label={block.label}\n isActive={isListActive()}\n disabled={isListDisabled()}\n handleClick={() => toggleList(format)}\n />\n );\n};\n\nconst LinkButton = ({\n disabled,\n location = 'toolbar',\n}: {\n disabled: boolean;\n location?: 'toolbar' | 'menu';\n}) => {\n const { editor } = useBlocksEditorContext('LinkButton');\n const { formatMessage } = useIntl();\n\n const isLinkActive = () => {\n const { selection } = editor;\n\n if (!selection) return false;\n\n const [match] = Array.from(\n Editor.nodes(editor, {\n at: Editor.unhangRange(editor, selection),\n match: (node) => SlateElement.isElement(node) && node.type === 'link',\n })\n );\n\n return Boolean(match);\n };\n\n const isLinkDisabled = () => {\n // Always disabled when the whole editor is disabled\n if (disabled) {\n return true;\n }\n\n // Always enabled when there's no selection\n if (!editor.selection) {\n return false;\n }\n\n // Get the block node closest to the anchor and focus\n const anchorNodeEntry = Editor.above(editor, {\n at: editor.selection.anchor,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n const focusNodeEntry = Editor.above(editor, {\n at: editor.selection.focus,\n match: (node) => !Editor.isEditor(node) && node.type !== 'text',\n });\n\n if (!anchorNodeEntry || !focusNodeEntry) {\n return false;\n }\n\n // Disabled if the anchor and focus are not in the same block\n return anchorNodeEntry[0] !== focusNodeEntry[0];\n };\n\n const addLink = () => {\n editor.shouldSaveLinkPath = true;\n // We insert an empty anchor, so we split the DOM to have a element we can use as reference for the popover\n insertLink(editor, { url: '' });\n };\n\n const label = {\n id: 'components.Blocks.link',\n defaultMessage: 'Link',\n } as MessageDescriptor;\n\n if (location === 'menu') {\n return (\n <StyledMenuItem\n startIcon={<Link />}\n onSelect={addLink}\n isActive={isLinkActive()}\n disabled={isLinkDisabled()}\n >\n {formatMessage(label)}\n </StyledMenuItem>\n );\n }\n\n return (\n <ToolbarButton\n icon={Link}\n name=\"link\"\n label={label}\n isActive={isLinkActive()}\n handleClick={addLink}\n disabled={isLinkDisabled()}\n />\n );\n};\n\nconst StyledMenuItem = styled(Menu.Item)<{ isActive: boolean }>`\n ${(props) =>\n props.isActive &&\n css`\n color: ${({ theme }) => theme.colors.primary600};\n font-weight: 600;\n `}\n\n svg {\n fill: ${({ theme, isActive }) =>\n isActive ? theme.colors.primary600 : theme.colors.neutral500};\n }\n`;\n\nconst BlocksToolbar = () => {\n const { editor, blocks, modifiers, disabled } = useBlocksEditorContext('BlocksToolbar');\n const { formatMessage } = useIntl();\n\n /**\n * The modifier buttons are disabled when an image is selected.\n */\n const checkButtonDisabled = () => {\n // Always disabled when the whole editor is disabled\n if (disabled) {\n return true;\n }\n\n if (!editor.selection) {\n return false;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n if (!selectedNode) return true;\n\n if (['image', 'code'].includes(selectedNode.type)) {\n return true;\n }\n\n return false;\n };\n\n const isButtonDisabled = checkButtonDisabled();\n\n /**\n * Observed components are ones that may or may not be visible in the toolbar, depending on the\n * available space. They provide two render props:\n * - renderInToolbar: for when we try to render the component in the toolbar (may be hidden)\n * - renderInMenu: for when the component didn't fit in the toolbar and is relegated\n * to the \"more\" menu\n */\n const observedComponents: ObservedComponent[] = [\n ...Object.entries(modifiers).map(([name, modifier]) => {\n const Icon = modifier.icon;\n const isActive = modifier.checkIsActive(editor);\n const handleSelect = () => modifier.handleToggle(editor);\n\n return {\n toolbar: (\n <ToolbarButton\n key={name}\n name={name}\n icon={modifier.icon}\n label={modifier.label}\n isActive={modifier.checkIsActive(editor)}\n handleClick={handleSelect}\n disabled={isButtonDisabled}\n />\n ),\n menu: (\n <StyledMenuItem startIcon={<Icon />} onSelect={handleSelect} isActive={isActive}>\n {formatMessage(modifier.label)}\n </StyledMenuItem>\n ),\n key: `modifier.${name}`,\n };\n }),\n {\n toolbar: <LinkButton disabled={isButtonDisabled} location=\"toolbar\" />,\n menu: <LinkButton disabled={isButtonDisabled} location=\"menu\" />,\n key: 'block.link',\n },\n {\n // List buttons can only be rendered together when in the toolbar\n toolbar: (\n <Flex direction=\"row\">\n <ToolbarSeparator style={{ marginLeft: '0.4rem' }} />\n <Toolbar.ToggleGroup type=\"single\" asChild>\n <Flex gap={1}>\n <ListButton block={blocks['list-unordered']} format=\"unordered\" location=\"toolbar\" />\n <ListButton block={blocks['list-ordered']} format=\"ordered\" location=\"toolbar\" />\n </Flex>\n </Toolbar.ToggleGroup>\n </Flex>\n ),\n menu: (\n <>\n <Menu.Separator />\n <ListButton block={blocks['list-unordered']} format=\"unordered\" location=\"menu\" />\n <ListButton block={blocks['list-ordered']} format=\"ordered\" location=\"menu\" />\n </>\n ),\n key: 'block.list',\n },\n ];\n\n return (\n <Toolbar.Root aria-disabled={disabled} asChild>\n <ToolbarWrapper padding={2} width=\"100%\">\n <BlocksDropdown />\n <ToolbarSeparator />\n <Toolbar.ToggleGroup type=\"multiple\" asChild>\n <Flex direction=\"row\" gap={1} grow={1} overflow=\"hidden\">\n <EditorToolbarObserver observedComponents={observedComponents} />\n </Flex>\n </Toolbar.ToggleGroup>\n </ToolbarWrapper>\n </Toolbar.Root>\n );\n};\n\nexport { BlocksToolbar, useConversionModal };\n"],"names":["ToolbarWrapper","styled","Flex","theme","colors","neutral150","ToolbarSeparator","Toolbar","Separator","FlexButton","primary100","SelectWrapper","Box","neutral600","useConversionModal","modalElement","setModalComponent","React","useState","handleConversionResult","renderModal","cloneElement","key","Date","now","ToolbarButton","icon","Icon","name","label","isActive","disabled","handleClick","editor","useBlocksEditorContext","formatMessage","useIntl","labelMessage","enabledColor","_jsx","Tooltip","ToggleItem","value","data-state","onMouseDown","e","preventDefault","ReactEditor","focus","aria-disabled","aria-label","asChild","tag","background","alignItems","justifyContent","width","height","hasRadius","fill","BlocksDropdown","blocks","blockKeysToInclude","getEntries","reduce","currentKeys","entry","block","isInBlocksSelector","blockSelected","setBlockSelected","handleSelect","optionKey","isSelectorBlockKey","editorIsEmpty","children","length","Editor","isEmpty","selection","Transforms","insertNodes","type","text","select","start","currentListEntry","above","match","node","isEditor","includes","currentList","currentListPath","format","isListNode","setNodes","at","maybeRenderModal","handleConvert","preventSelectFocus","useEffect","selectedNode","anchor","anchorNode","parent","edge","depth","anchorBlockKey","getKeys","find","blockKey","matchNode","_jsxs","_Fragment","SingleSelect","startIcon","onChange","placeholder","onCloseAutoFocus","id","defaultMessage","map","BlockOption","isSelected","SingleSelectOption","Node","isNode","ListButton","location","isListActive","isListDisabled","anchorNodeEntry","focusNodeEntry","toggleList","_","lastNodePath","last","StyledMenuItem","onSelect","LinkButton","isLinkActive","Array","from","nodes","unhangRange","SlateElement","isElement","Boolean","isLinkDisabled","addLink","shouldSaveLinkPath","insertLink","url","Link","Menu","Item","props","css","primary600","neutral500","BlocksToolbar","modifiers","checkButtonDisabled","path","isButtonDisabled","observedComponents","Object","entries","modifier","checkIsActive","handleToggle","toolbar","menu","direction","style","marginLeft","ToggleGroup","gap","Root","padding","grow","overflow","EditorToolbarObserver"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,cAAAA,GAAiBC,uBAAsBC,CAAAA,iBAAAA,CAAK;;;gBAGlC,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACC,UAAU,CAAC;;AAEzD,CAAC;AAED,MAAMC,gBAAmBL,GAAAA,uBAAAA,CAAOM,kBAAQC,CAAAA,SAAS,CAAC;cACpC,EAAE,CAAC,E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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import * as Toolbar from '@radix-ui/react-toolbar';
|
|
4
|
-
import '@strapi/admin/strapi-admin';
|
|
5
4
|
import { Flex, Box, Menu, Tooltip, SingleSelect, SingleSelectOption } from '@strapi/design-system';
|
|
6
5
|
import { Link } from '@strapi/icons';
|
|
7
6
|
import { useIntl } from 'react-intl';
|
|
@@ -284,8 +283,8 @@ const isListNode = (node)=>{
|
|
|
284
283
|
return Node.isNode(node) && !Editor.isEditor(node) && node.type === 'list';
|
|
285
284
|
};
|
|
286
285
|
const ListButton = ({ block, format, location = 'toolbar' })=>{
|
|
287
|
-
const { editor, disabled, blocks } = useBlocksEditorContext('ListButton');
|
|
288
286
|
const { formatMessage } = useIntl();
|
|
287
|
+
const { editor, disabled, blocks } = useBlocksEditorContext('ListButton');
|
|
289
288
|
const isListActive = ()=>{
|
|
290
289
|
if (!editor.selection) return false;
|
|
291
290
|
// Get the parent list at selection anchor node
|
|
@@ -469,6 +468,7 @@ const BlocksToolbar = ()=>{
|
|
|
469
468
|
return false;
|
|
470
469
|
}
|
|
471
470
|
const selectedNode = editor.children[editor.selection.anchor.path[0]];
|
|
471
|
+
if (!selectedNode) return true;
|
|
472
472
|
if ([
|
|
473
473
|
'image',
|
|
474
474
|
'code'
|