@strapi/content-manager 0.0.0-next.daa3d4c4db6322f58233f0ccb757d80dbd1b48e9 → 0.0.0-next.df0d99415fc543d9747f3946fd7d1a4c39052b95
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/components/ConfigurationForm/Fields.js +300 -204
- package/dist/admin/components/ConfigurationForm/Fields.js.map +1 -1
- package/dist/admin/components/ConfigurationForm/Fields.mjs +304 -209
- package/dist/admin/components/ConfigurationForm/Fields.mjs.map +1 -1
- package/dist/admin/components/LeftMenu.js +34 -30
- package/dist/admin/components/LeftMenu.js.map +1 -1
- package/dist/admin/components/LeftMenu.mjs +36 -32
- package/dist/admin/components/LeftMenu.mjs.map +1 -1
- package/dist/admin/components/Widgets.js +253 -0
- package/dist/admin/components/Widgets.js.map +1 -1
- package/dist/admin/components/Widgets.mjs +236 -3
- package/dist/admin/components/Widgets.mjs.map +1 -1
- package/dist/admin/history/components/VersionContent.js +24 -3
- package/dist/admin/history/components/VersionContent.js.map +1 -1
- package/dist/admin/history/components/VersionContent.mjs +25 -4
- package/dist/admin/history/components/VersionContent.mjs.map +1 -1
- package/dist/admin/history/components/VersionHeader.js +6 -0
- package/dist/admin/history/components/VersionHeader.js.map +1 -1
- package/dist/admin/history/components/VersionHeader.mjs +7 -1
- package/dist/admin/history/components/VersionHeader.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentActions.js +7 -6
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs +8 -7
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/index.js +47 -8
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +47 -9
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/layout.js +1 -27
- package/dist/admin/layout.js.map +1 -1
- package/dist/admin/layout.mjs +2 -9
- package/dist/admin/layout.mjs.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.js +99 -75
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +101 -77
- package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js +83 -70
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +85 -72
- package/dist/admin/pages/EditView/components/DocumentActions.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 +21 -35
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs +21 -35
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js +12 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs +13 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +13 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +14 -3
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +18 -5
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +20 -7
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +158 -106
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +161 -109
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.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/EditView/components/FormInputs/Wysiwyg/WysiwygNav.js +86 -118
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.mjs +86 -118
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/WysiwygNav.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.js +47 -27
- package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.mjs +47 -27
- package/dist/admin/pages/EditView/components/FormLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +103 -0
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +103 -1
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +227 -132
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs +229 -134
- package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.js +2 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.mjs +2 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.js +4 -1
- package/dist/admin/pages/ListView/components/Filters.js.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.mjs +4 -1
- 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/preview/components/PreviewSidePanel.js +31 -4
- package/dist/admin/preview/components/PreviewSidePanel.js.map +1 -1
- package/dist/admin/preview/components/PreviewSidePanel.mjs +32 -5
- package/dist/admin/preview/components/PreviewSidePanel.mjs.map +1 -1
- package/dist/admin/preview/pages/Preview.js +101 -35
- package/dist/admin/preview/pages/Preview.js.map +1 -1
- package/dist/admin/preview/pages/Preview.mjs +102 -36
- package/dist/admin/preview/pages/Preview.mjs.map +1 -1
- package/dist/admin/services/api.js +3 -1
- package/dist/admin/services/api.js.map +1 -1
- package/dist/admin/services/api.mjs +3 -1
- package/dist/admin/services/api.mjs.map +1 -1
- package/dist/admin/services/documents.js +32 -16
- package/dist/admin/services/documents.js.map +1 -1
- package/dist/admin/services/documents.mjs +32 -16
- package/dist/admin/services/documents.mjs.map +1 -1
- package/dist/admin/services/homepage.js +11 -2
- package/dist/admin/services/homepage.js.map +1 -1
- package/dist/admin/services/homepage.mjs +11 -3
- package/dist/admin/services/homepage.mjs.map +1 -1
- package/dist/admin/src/components/ConfigurationForm/Fields.d.ts +6 -4
- package/dist/admin/src/components/Widgets.d.ts +2 -1
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +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/pages/EditView/components/FormLayout.d.ts +7 -8
- package/dist/admin/src/pages/EditView/utils/data.d.ts +19 -1
- package/dist/admin/src/preview/services/preview.d.ts +1 -1
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +23 -17
- package/dist/admin/src/services/homepage.d.ts +6 -2
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +1 -0
- package/dist/admin/translations/en.json.js +7 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +7 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/translations/es.json.js +5 -2
- package/dist/admin/translations/es.json.js.map +1 -1
- package/dist/admin/translations/es.json.mjs +5 -2
- package/dist/admin/translations/es.json.mjs.map +1 -1
- package/dist/admin/translations/fr.json.js +10 -2
- package/dist/admin/translations/fr.json.js.map +1 -1
- package/dist/admin/translations/fr.json.mjs +10 -2
- package/dist/admin/translations/fr.json.mjs.map +1 -1
- package/dist/admin/utils/validation.js +19 -7
- package/dist/admin/utils/validation.js.map +1 -1
- package/dist/admin/utils/validation.mjs +19 -7
- 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/relations.js +2 -2
- package/dist/server/controllers/relations.js.map +1 -1
- package/dist/server/controllers/relations.mjs +2 -2
- package/dist/server/controllers/relations.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/history/services/lifecycles.js +23 -19
- package/dist/server/history/services/lifecycles.js.map +1 -1
- package/dist/server/history/services/lifecycles.mjs +23 -19
- package/dist/server/history/services/lifecycles.mjs.map +1 -1
- package/dist/server/homepage/controllers/homepage.js +5 -0
- package/dist/server/homepage/controllers/homepage.js.map +1 -1
- package/dist/server/homepage/controllers/homepage.mjs +5 -0
- package/dist/server/homepage/controllers/homepage.mjs.map +1 -1
- package/dist/server/homepage/routes/homepage.js +11 -0
- package/dist/server/homepage/routes/homepage.js.map +1 -1
- package/dist/server/homepage/routes/homepage.mjs +11 -0
- package/dist/server/homepage/routes/homepage.mjs.map +1 -1
- package/dist/server/homepage/services/homepage.js +86 -46
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +86 -46
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/preview/services/preview-config.js +5 -1
- package/dist/server/preview/services/preview-config.js.map +1 -1
- package/dist/server/preview/services/preview-config.mjs +5 -1
- package/dist/server/preview/services/preview-config.mjs.map +1 -1
- package/dist/server/preview/services/preview.js +4 -0
- package/dist/server/preview/services/preview.js.map +1 -1
- package/dist/server/preview/services/preview.mjs +4 -0
- package/dist/server/preview/services/preview.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 +3 -1
- package/dist/server/services/document-metadata.js.map +1 -1
- package/dist/server/services/document-metadata.mjs +3 -1
- 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/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts +2 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -1
- package/dist/server/src/homepage/index.d.ts +7 -0
- package/dist/server/src/homepage/index.d.ts.map +1 -1
- package/dist/server/src/homepage/routes/homepage.d.ts.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts +4 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/dist/server/src/homepage/services/index.d.ts +7 -0
- package/dist/server/src/homepage/services/index.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +8 -0
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/index.d.ts +1 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview-config.d.ts +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview.d.ts.map +1 -1
- package/dist/server/src/preview/utils.d.ts +1 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -1
- package/dist/server/src/services/data-mapper.d.ts +1 -0
- 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/index.d.ts +8 -0
- package/dist/server/src/services/index.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/dist/shared/contracts/homepage.d.ts +13 -0
- package/dist/shared/contracts/homepage.d.ts.map +1 -1
- package/package.json +11 -9
|
@@ -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,CA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EAAAA,cAAAA;AAEhB,oBAAA,QAAA,gBAAAoB,eAACa,CAAAA,yBAAAA,EAAAA;wBACChD,KAAOA,EAAAA,KAAAA;wBACPH,QAAUA,EAAAA,QAAAA;wBACVoD,cAAgBjC,EAAAA,kBAAAA;wBAChBH,iBAAmBA,EAAAA,iBAAAA;;0CAEnBwB,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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AA,gBAAAwB,cAACpF,CAAAA,oBAAAA,EAAAA;oBACCyE,MAAQA,EAAAA,MAAAA;oBACRoB,SAAWA,EAAAA,mBAAAA;oBACX1D,QAAUA,EAAAA,QAAAA;oBACVC,IAAMA,EAAAA,IAAAA;oBACNc,WAAaA,EAAAA,WAAAA;oBACbG,cAAgBA,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,MA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AA,EAAAA,EAAAA,CAAAA;0CACDb,GAACjE,CAAAA,aAAAA,EAAAA;gCAAc+E,KAAM,EAAA;;0CACrBd,GAACe,CAAAA,aAAAA,EAAAA;AAAe,gCAAA,GAAGnD;;AAClB,4BAAA,CAACc,gCACAsB,GAACgB,CAAAA,UAAAA,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,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,CA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AAAA;wBACPH,QAAUA,EAAAA,QAAAA;wBACV4D,cAAgBzC,EAAAA,kBAAAA;wBAChBH,iBAAmBA,EAAAA,iBAAAA;;0CAEnBiC,GAACY,CAAAA,aAAAA,EAAAA,EAAAA,CAAAA;0CACDZ,GAAC3E,CAAAA,aAAAA,EAAAA;gCAAcwF,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');
|
|
@@ -45,6 +44,8 @@ const ToolbarSeparator = styledComponents.styled(Toolbar__namespace.Separator)`
|
|
|
45
44
|
background: ${({ theme })=>theme.colors.neutral150};
|
|
46
45
|
width: 1px;
|
|
47
46
|
height: 2.4rem;
|
|
47
|
+
margin-left: 0.8rem;
|
|
48
|
+
margin-right: 0.8rem;
|
|
48
49
|
`;
|
|
49
50
|
const FlexButton = styledComponents.styled(designSystem.Flex)`
|
|
50
51
|
// Inherit the not-allowed cursor from ToolbarWrapper when disabled
|
|
@@ -294,7 +295,7 @@ const BlockOption = ({ value, icon: Icon, label, blockSelected })=>{
|
|
|
294
295
|
const isSelected = value === blockSelected;
|
|
295
296
|
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
|
|
296
297
|
startIcon: /*#__PURE__*/ jsxRuntime.jsx(Icon, {
|
|
297
|
-
fill: isSelected ? 'primary600' : '
|
|
298
|
+
fill: isSelected ? 'primary600' : 'neutral500'
|
|
298
299
|
}),
|
|
299
300
|
value: value,
|
|
300
301
|
children: formatMessage(label)
|
|
@@ -304,8 +305,8 @@ const isListNode = (node)=>{
|
|
|
304
305
|
return slate.Node.isNode(node) && !slate.Editor.isEditor(node) && node.type === 'list';
|
|
305
306
|
};
|
|
306
307
|
const ListButton = ({ block, format, location = 'toolbar' })=>{
|
|
307
|
-
const { editor, disabled, blocks } = BlocksEditor.useBlocksEditorContext('ListButton');
|
|
308
308
|
const { formatMessage } = reactIntl.useIntl();
|
|
309
|
+
const { editor, disabled, blocks } = BlocksEditor.useBlocksEditorContext('ListButton');
|
|
309
310
|
const isListActive = ()=>{
|
|
310
311
|
if (!editor.selection) return false;
|
|
311
312
|
// Get the parent list at selection anchor node
|
|
@@ -383,14 +384,12 @@ const ListButton = ({ block, format, location = 'toolbar' })=>{
|
|
|
383
384
|
};
|
|
384
385
|
if (location === 'menu') {
|
|
385
386
|
const Icon = block.icon;
|
|
386
|
-
return /*#__PURE__*/ jsxRuntime.
|
|
387
|
+
return /*#__PURE__*/ jsxRuntime.jsx(StyledMenuItem, {
|
|
388
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(Icon, {}),
|
|
387
389
|
onSelect: ()=>toggleList(format),
|
|
388
390
|
isActive: isListActive(),
|
|
389
391
|
disabled: isListDisabled(),
|
|
390
|
-
children:
|
|
391
|
-
/*#__PURE__*/ jsxRuntime.jsx(Icon, {}),
|
|
392
|
-
formatMessage(block.label)
|
|
393
|
-
]
|
|
392
|
+
children: formatMessage(block.label)
|
|
394
393
|
});
|
|
395
394
|
}
|
|
396
395
|
return /*#__PURE__*/ jsxRuntime.jsx(ToolbarButton, {
|
|
@@ -450,14 +449,12 @@ const LinkButton = ({ disabled, location = 'toolbar' })=>{
|
|
|
450
449
|
defaultMessage: 'Link'
|
|
451
450
|
};
|
|
452
451
|
if (location === 'menu') {
|
|
453
|
-
return /*#__PURE__*/ jsxRuntime.
|
|
452
|
+
return /*#__PURE__*/ jsxRuntime.jsx(StyledMenuItem, {
|
|
453
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(Icons.Link, {}),
|
|
454
454
|
onSelect: addLink,
|
|
455
455
|
isActive: isLinkActive(),
|
|
456
456
|
disabled: isLinkDisabled(),
|
|
457
|
-
children:
|
|
458
|
-
/*#__PURE__*/ jsxRuntime.jsx(Icons.Link, {}),
|
|
459
|
-
formatMessage(label)
|
|
460
|
-
]
|
|
457
|
+
children: formatMessage(label)
|
|
461
458
|
});
|
|
462
459
|
}
|
|
463
460
|
return /*#__PURE__*/ jsxRuntime.jsx(ToolbarButton, {
|
|
@@ -470,25 +467,13 @@ const LinkButton = ({ disabled, location = 'toolbar' })=>{
|
|
|
470
467
|
});
|
|
471
468
|
};
|
|
472
469
|
const StyledMenuItem = styledComponents.styled(designSystem.Menu.Item)`
|
|
473
|
-
&:hover {
|
|
474
|
-
background-color: ${({ theme })=>theme.colors.primary100};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
470
|
${(props)=>props.isActive && styledComponents.css`
|
|
478
|
-
font-weight: bold;
|
|
479
|
-
background-color: ${({ theme })=>theme.colors.primary100};
|
|
480
471
|
color: ${({ theme })=>theme.colors.primary600};
|
|
481
|
-
font-weight:
|
|
472
|
+
font-weight: 600;
|
|
482
473
|
`}
|
|
483
474
|
|
|
484
|
-
> span {
|
|
485
|
-
display: inline-flex;
|
|
486
|
-
gap: ${({ theme })=>theme.spaces[2]};
|
|
487
|
-
align-items: center;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
475
|
svg {
|
|
491
|
-
fill: ${({ theme, isActive })=>isActive ? theme.colors.primary600 : theme.colors.
|
|
476
|
+
fill: ${({ theme, isActive })=>isActive ? theme.colors.primary600 : theme.colors.neutral500};
|
|
492
477
|
}
|
|
493
478
|
`;
|
|
494
479
|
const BlocksToolbar = ()=>{
|
|
@@ -505,6 +490,7 @@ const BlocksToolbar = ()=>{
|
|
|
505
490
|
return false;
|
|
506
491
|
}
|
|
507
492
|
const selectedNode = editor.children[editor.selection.anchor.path[0]];
|
|
493
|
+
if (!selectedNode) return true;
|
|
508
494
|
if ([
|
|
509
495
|
'image',
|
|
510
496
|
'code'
|
|
@@ -534,13 +520,11 @@ const BlocksToolbar = ()=>{
|
|
|
534
520
|
handleClick: handleSelect,
|
|
535
521
|
disabled: isButtonDisabled
|
|
536
522
|
}, name),
|
|
537
|
-
menu: /*#__PURE__*/ jsxRuntime.
|
|
523
|
+
menu: /*#__PURE__*/ jsxRuntime.jsx(StyledMenuItem, {
|
|
524
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(Icon, {}),
|
|
538
525
|
onSelect: handleSelect,
|
|
539
526
|
isActive: isActive,
|
|
540
|
-
children:
|
|
541
|
-
/*#__PURE__*/ jsxRuntime.jsx(Icon, {}),
|
|
542
|
-
formatMessage(modifier.label)
|
|
543
|
-
]
|
|
527
|
+
children: formatMessage(modifier.label)
|
|
544
528
|
}),
|
|
545
529
|
key: `modifier.${name}`
|
|
546
530
|
};
|
|
@@ -560,9 +544,12 @@ const BlocksToolbar = ()=>{
|
|
|
560
544
|
// List buttons can only be rendered together when in the toolbar
|
|
561
545
|
toolbar: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
|
562
546
|
direction: "row",
|
|
563
|
-
gap: 1,
|
|
564
547
|
children: [
|
|
565
|
-
/*#__PURE__*/ jsxRuntime.jsx(ToolbarSeparator, {
|
|
548
|
+
/*#__PURE__*/ jsxRuntime.jsx(ToolbarSeparator, {
|
|
549
|
+
style: {
|
|
550
|
+
marginLeft: '0.4rem'
|
|
551
|
+
}
|
|
552
|
+
}),
|
|
566
553
|
/*#__PURE__*/ jsxRuntime.jsx(Toolbar__namespace.ToggleGroup, {
|
|
567
554
|
type: "single",
|
|
568
555
|
asChild: true,
|
|
@@ -606,7 +593,6 @@ const BlocksToolbar = ()=>{
|
|
|
606
593
|
"aria-disabled": disabled,
|
|
607
594
|
asChild: true,
|
|
608
595
|
children: /*#__PURE__*/ jsxRuntime.jsxs(ToolbarWrapper, {
|
|
609
|
-
gap: 2,
|
|
610
596
|
padding: 2,
|
|
611
597
|
width: "100%",
|
|
612
598
|
children: [
|