@strapi/content-manager 5.15.0 → 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/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/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/EditViewPage.js +81 -74
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +82 -75
- package/dist/admin/pages/EditView/EditViewPage.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/Relations/Relations.js +2 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +2 -1
- 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/FormLayout.js +19 -23
- package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.mjs +19 -23
- package/dist/admin/pages/EditView/components/FormLayout.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/components/ConfigurationForm/Fields.d.ts +6 -4
- 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 -7
- 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 +10 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlocksContent.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Box,\n BoxComponent,\n Flex,\n FlexComponent,\n IconButton,\n IconButtonComponent,\n useComposedRefs,\n} from '@strapi/design-system';\nimport { Drag } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { Editor, Range, Transforms } from 'slate';\nimport { ReactEditor, type RenderElementProps, type RenderLeafProps, Editable } from 'slate-react';\nimport { styled, CSSProperties, css } from 'styled-components';\n\nimport { ItemTypes } from '../../../../../constants/dragAndDrop';\nimport { useDragAndDrop, DIRECTIONS } from '../../../../../hooks/useDragAndDrop';\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { decorateCode } from './Blocks/Code';\nimport { type BlocksStore, useBlocksEditorContext } from './BlocksEditor';\nimport { useConversionModal } from './BlocksToolbar';\nimport { type ModifiersStore } from './Modifiers';\nimport { getEntries, isLinkNode, isListNode } from './utils/types';\n\nconst StyledEditable = styled(Editable)<{ isExpandedMode: boolean }>`\n // The outline style is set on the wrapper with :focus-within\n outline: none;\n display: flex;\n flex-direction: column;\n gap: ${({ theme }) => theme.spaces[3]};\n height: 100%;\n // For fullscreen align input in the center with fixed width\n width: ${(props) => (props.isExpandedMode ? '512px' : '100%')};\n margin: auto;\n\n > *:last-child {\n padding-bottom: ${({ theme }) => theme.spaces[3]};\n }\n`;\n\nconst Wrapper = styled<BoxComponent>(Box)<{ isOverDropTarget: boolean }>`\n position: ${({ isOverDropTarget }) => isOverDropTarget && 'relative'};\n`;\n\ntype DragDirection = (typeof DIRECTIONS)[keyof typeof DIRECTIONS];\n\nconst DropPlaceholder = styled<BoxComponent>(Box)<{\n dragDirection: DragDirection | null;\n placeholderMargin: 1 | 2;\n}>`\n position: absolute;\n right: 0;\n\n // Show drop placeholder 8px above or below the drop target\n ${({ dragDirection, theme, placeholderMargin }) => css`\n top: ${dragDirection === DIRECTIONS.UPWARD && `-${theme.spaces[placeholderMargin]}`};\n bottom: ${dragDirection === DIRECTIONS.DOWNWARD && `-${theme.spaces[placeholderMargin]}`};\n `}\n`;\n\nconst DragItem = styled<FlexComponent>(Flex)<{ $dragVisibility: CSSProperties['visibility'] }>`\n // Style each block rendered using renderElement()\n & > [data-slate-node='element'] {\n width: 100%;\n opacity: inherit;\n }\n\n // Set the visibility of drag button\n [role='button'] {\n visibility: ${(props) => props.$dragVisibility};\n opacity: inherit;\n }\n &[aria-disabled='true'] {\n user-drag: none;\n }\n`;\n\nconst DragIconButton = styled<IconButtonComponent<'div'>>(IconButton)<{\n $dragHandleTopMargin?: CSSProperties['marginTop'];\n}>`\n user-select: none;\n display: flex;\n align-items: center;\n justify-content: center;\n border: none;\n border-radius: ${({ theme }) => theme.borderRadius};\n padding-left: ${({ theme }) => theme.spaces[0]};\n padding-right: ${({ theme }) => theme.spaces[0]};\n padding-top: ${({ theme }) => theme.spaces[1]};\n padding-bottom: ${({ theme }) => theme.spaces[1]};\n visibility: hidden;\n cursor: grab;\n opacity: inherit;\n margin-top: ${(props) => props.$dragHandleTopMargin ?? 0};\n\n &:hover {\n background: ${({ theme }) => theme.colors.neutral100};\n }\n &:active {\n cursor: grabbing;\n background: ${({ theme }) => theme.colors.neutral150};\n }\n &[aria-disabled='true'] {\n visibility: hidden;\n }\n svg {\n min-width: ${({ theme }) => theme.spaces[3]};\n\n path {\n fill: ${({ theme }) => theme.colors.neutral500};\n }\n }\n`;\n\ntype Direction = {\n setDragDirection: (direction: DragDirection) => void;\n dragDirection: DragDirection | null;\n};\n\ntype DragAndDropElementProps = Direction & {\n children: RenderElementProps['children'];\n index: Array<number>;\n dragHandleTopMargin?: CSSProperties['marginTop'];\n};\n\nconst DragAndDropElement = ({\n children,\n index,\n setDragDirection,\n dragDirection,\n dragHandleTopMargin,\n}: DragAndDropElementProps) => {\n const { editor, disabled, name, setLiveText } = useBlocksEditorContext('drag-and-drop');\n const { formatMessage } = useIntl();\n const [dragVisibility, setDragVisibility] = React.useState<CSSProperties['visibility']>('hidden');\n\n const handleMoveBlock = React.useCallback(\n (newIndex: Array<number>, currentIndex: Array<number>) => {\n Transforms.moveNodes(editor, {\n at: currentIndex,\n to: newIndex,\n });\n\n // Add 1 to the index for the live text message\n const currentIndexPosition = [currentIndex[0] + 1, ...currentIndex.slice(1)];\n const newIndexPosition = [newIndex[0] + 1, ...newIndex.slice(1)];\n\n setLiveText(\n formatMessage(\n {\n id: getTranslation('components.Blocks.dnd.reorder'),\n defaultMessage: '{item}, moved. New position in the editor: {position}.',\n },\n {\n item: `${name}.${currentIndexPosition.join(',')}`,\n position: `${newIndexPosition.join(',')} of ${editor.children.length}`,\n }\n )\n );\n },\n [editor, formatMessage, name, setLiveText]\n );\n\n const [{ handlerId, isDragging, isOverDropTarget, direction }, blockRef, dropRef, dragRef] =\n useDragAndDrop(!disabled, {\n type: `${ItemTypes.BLOCKS}_${name}`,\n index,\n item: {\n index,\n displayedValue: children,\n },\n onDropItem(currentIndex, newIndex) {\n if (newIndex) handleMoveBlock(newIndex, currentIndex);\n },\n });\n\n const composedBoxRefs = useComposedRefs(blockRef, dropRef);\n\n // Set Drag direction before loosing state while dragging\n React.useEffect(() => {\n if (direction) {\n setDragDirection(direction);\n }\n }, [direction, setDragDirection]);\n\n // On selection change hide drag handle\n React.useEffect(() => {\n setDragVisibility('hidden');\n }, [editor.selection]);\n\n return (\n <Wrapper ref={composedBoxRefs} isOverDropTarget={isOverDropTarget}>\n {isOverDropTarget && (\n <DropPlaceholder\n borderStyle=\"solid\"\n borderColor=\"secondary200\"\n borderWidth=\"2px\"\n width=\"calc(100% - 24px)\"\n marginLeft=\"auto\"\n dragDirection={dragDirection}\n // For list items placeholder reduce the margin around\n placeholderMargin={children.props.as && children.props.as === 'li' ? 1 : 2}\n />\n )}\n {isDragging ? (\n <CloneDragItem dragHandleTopMargin={dragHandleTopMargin}>{children}</CloneDragItem>\n ) : (\n <DragItem\n ref={dragRef}\n data-handler-id={handlerId}\n gap={2}\n paddingLeft={2}\n alignItems=\"start\"\n onDragStart={(event) => {\n const target = event.target as HTMLElement;\n const currentTarget = event.currentTarget as HTMLElement;\n\n // Dragging action should only trigger drag event when button is dragged, however update styles on the whole dragItem.\n if (target.getAttribute('role') !== 'button') {\n event.preventDefault();\n } else {\n // Setting styles using dragging state is not working, so set it on current target element as nodes get dragged\n currentTarget.style.opacity = '0.5';\n }\n }}\n onDragEnd={(event) => {\n const currentTarget = event.currentTarget as HTMLElement;\n currentTarget.style.opacity = '1';\n }}\n onMouseMove={() => setDragVisibility('visible')}\n onSelect={() => setDragVisibility('visible')}\n onMouseLeave={() => setDragVisibility('hidden')}\n aria-disabled={disabled}\n $dragVisibility={dragVisibility}\n >\n <DragIconButton\n tag=\"div\"\n contentEditable={false}\n role=\"button\"\n tabIndex={0}\n withTooltip={false}\n label={formatMessage({\n id: getTranslation('components.DragHandle-label'),\n defaultMessage: 'Drag',\n })}\n onClick={(e) => e.stopPropagation()}\n aria-disabled={disabled}\n disabled={disabled}\n draggable\n // For some blocks top margin added to drag handle to align at the text level\n $dragHandleTopMargin={dragHandleTopMargin}\n >\n <Drag color=\"primary500\" />\n </DragIconButton>\n {children}\n </DragItem>\n )}\n </Wrapper>\n );\n};\n\ninterface CloneDragItemProps {\n children: RenderElementProps['children'];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\n// To prevent applying opacity to the original item being dragged, display a cloned element without opacity.\nconst CloneDragItem = ({ children, dragHandleTopMargin }: CloneDragItemProps) => {\n const { formatMessage } = useIntl();\n\n return (\n <DragItem gap={2} paddingLeft={2} alignItems=\"start\" $dragVisibility=\"visible\">\n <DragIconButton\n tag=\"div\"\n role=\"button\"\n withTooltip={false}\n label={formatMessage({\n id: getTranslation('components.DragHandle-label'),\n defaultMessage: 'Drag',\n })}\n $dragHandleTopMargin={dragHandleTopMargin}\n >\n <Drag color=\"neutral600\" />\n </DragIconButton>\n {children}\n </DragItem>\n );\n};\n\ninterface ExtendedRenderLeafProps extends RenderLeafProps {\n leaf: RenderLeafProps['leaf'] & { className?: string };\n}\n\nconst baseRenderLeaf = (props: ExtendedRenderLeafProps, modifiers: ModifiersStore) => {\n // Recursively wrap the children for each active modifier\n const wrappedChildren = getEntries(modifiers).reduce((currentChildren, modifierEntry) => {\n const [name, modifier] = modifierEntry;\n\n if (props.leaf[name]) {\n return modifier.renderLeaf(currentChildren);\n }\n\n return currentChildren;\n }, props.children);\n\n return (\n <span {...props.attributes} className={props.leaf.className}>\n {wrappedChildren}\n </span>\n );\n};\n\ntype BaseRenderElementProps = Direction & {\n props: RenderElementProps['children'];\n blocks: BlocksStore;\n editor: Editor;\n};\n\nconst baseRenderElement = ({\n props,\n blocks,\n editor,\n setDragDirection,\n dragDirection,\n}: BaseRenderElementProps) => {\n const { element } = props;\n\n const blockMatch = Object.values(blocks).find((block) => block.matchNode(element));\n const block = blockMatch || blocks.paragraph;\n const nodePath = ReactEditor.findPath(editor, element);\n\n // Link is inline block so it cannot be dragged\n // List items and nested list blocks i.e. lists with indent level higher than 0 are skipped from dragged items\n if (\n isLinkNode(element) ||\n (isListNode(element) && element.indentLevel && element.indentLevel > 0) ||\n element.type === 'list-item'\n ) {\n return block.renderElement(props);\n }\n\n return (\n <DragAndDropElement\n index={nodePath}\n setDragDirection={setDragDirection}\n dragDirection={dragDirection}\n dragHandleTopMargin={block.dragHandleTopMargin}\n >\n {block.renderElement(props)}\n </DragAndDropElement>\n );\n};\n\ninterface BlocksContentProps {\n placeholder?: string;\n ariaLabelId: string;\n}\n\nconst BlocksContent = ({ placeholder, ariaLabelId }: BlocksContentProps) => {\n const { editor, disabled, blocks, modifiers, setLiveText, isExpandedMode } =\n useBlocksEditorContext('BlocksContent');\n const blocksRef = React.useRef<HTMLDivElement>(null);\n const { formatMessage } = useIntl();\n const [dragDirection, setDragDirection] = React.useState<DragDirection | null>(null);\n const { modalElement, handleConversionResult } = useConversionModal();\n\n // Create renderLeaf function based on the modifiers store\n const renderLeaf = React.useCallback(\n (props: ExtendedRenderLeafProps) => baseRenderLeaf(props, modifiers),\n [modifiers]\n );\n\n const handleMoveBlocks = (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) return;\n\n const start = Range.start(editor.selection);\n const currentIndex = [start.path[0]];\n let newIndexPosition = 0;\n\n if (event.key === 'ArrowUp') {\n newIndexPosition = currentIndex[0] > 0 ? currentIndex[0] - 1 : currentIndex[0];\n } else {\n newIndexPosition =\n currentIndex[0] < editor.children.length - 1 ? currentIndex[0] + 1 : currentIndex[0];\n }\n\n const newIndex = [newIndexPosition];\n\n if (newIndexPosition !== currentIndex[0]) {\n Transforms.moveNodes(editor, {\n at: currentIndex,\n to: newIndex,\n });\n\n setLiveText(\n formatMessage(\n {\n id: getTranslation('components.Blocks.dnd.reorder'),\n defaultMessage: '{item}, moved. New position in the editor: {position}.',\n },\n {\n item: `${name}.${currentIndex[0] + 1}`,\n position: `${newIndex[0] + 1} of ${editor.children.length}`,\n }\n )\n );\n\n event.preventDefault();\n }\n };\n\n // Create renderElement function base on the blocks store\n const renderElement = React.useCallback(\n (props: RenderElementProps) =>\n baseRenderElement({ props, blocks, editor, dragDirection, setDragDirection }),\n [blocks, editor, dragDirection, setDragDirection]\n );\n\n const checkSnippet = (event: React.KeyboardEvent<HTMLElement>) => {\n // Get current text block\n if (!editor.selection) {\n return;\n }\n\n const [textNode, textNodePath] = Editor.node(editor, editor.selection.anchor.path);\n\n // Narrow the type to a text node\n if (Editor.isEditor(textNode) || textNode.type !== 'text') {\n return;\n }\n\n // Don't check for snippets if we're not at the start of a block\n if (textNodePath.at(-1) !== 0) {\n return;\n }\n\n // Check if the text node starts with a known snippet\n const blockMatchingSnippet = Object.values(blocks).find((block) => {\n return block.snippets?.includes(textNode.text);\n });\n\n if (blockMatchingSnippet?.handleConvert) {\n // Prevent the space from being created and delete the snippet\n event.preventDefault();\n Transforms.delete(editor, {\n distance: textNode.text.length,\n unit: 'character',\n reverse: true,\n });\n\n // Convert the selected block\n const maybeRenderModal = blockMatchingSnippet.handleConvert(editor);\n handleConversionResult(maybeRenderModal);\n }\n };\n\n const handleEnter = (event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) {\n return;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));\n if (!selectedBlock) {\n return;\n }\n\n // Allow forced line breaks when shift is pressed\n if (event.shiftKey && selectedNode.type !== 'image') {\n Transforms.insertText(editor, '\\n');\n return;\n }\n\n // Check if there's an enter handler for the selected block\n if (selectedBlock.handleEnterKey) {\n selectedBlock.handleEnterKey(editor);\n } else {\n blocks.paragraph.handleEnterKey!(editor);\n }\n };\n\n const handleBackspaceEvent = (event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) {\n return;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));\n\n if (!selectedBlock) {\n return;\n }\n\n if (selectedBlock.handleBackspaceKey) {\n selectedBlock.handleBackspaceKey(editor, event);\n }\n };\n\n const handleTab = (event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) {\n return;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));\n if (!selectedBlock) {\n return;\n }\n\n if (selectedBlock.handleTab) {\n event.preventDefault();\n selectedBlock.handleTab(editor);\n }\n };\n\n const handleKeyboardShortcuts = (event: React.KeyboardEvent<HTMLElement>) => {\n const isCtrlOrCmd = event.metaKey || event.ctrlKey;\n\n if (isCtrlOrCmd) {\n // Check if there's a modifier to toggle\n Object.values(modifiers).forEach((value) => {\n if (value.isValidEventKey(event)) {\n value.handleToggle(editor);\n return;\n }\n });\n if (event.shiftKey && ['ArrowUp', 'ArrowDown'].includes(event.key)) {\n handleMoveBlocks(editor, event);\n }\n }\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLElement> = (event) => {\n // Find the right block-specific handlers for enter and backspace key presses\n switch (event.key) {\n case 'Enter':\n event.preventDefault();\n return handleEnter(event);\n case 'Backspace':\n return handleBackspaceEvent(event);\n case 'Tab':\n return handleTab(event);\n case 'Escape':\n return ReactEditor.blur(editor);\n }\n\n handleKeyboardShortcuts(event);\n\n // Check if a snippet was triggered\n if (event.key === ' ') {\n checkSnippet(event);\n }\n };\n\n /**\n * scrollSelectionIntoView : Slate's default method to scroll a DOM selection into the view,\n * thats shifting layout for us when there is a overflowY:scroll on the viewport.\n * We are overriding it to check if the selection is not fully within the visible area of the editor,\n * we use scrollBy one line to the bottom\n */\n const handleScrollSelectionIntoView = () => {\n if (!editor.selection) return;\n const domRange = ReactEditor.toDOMRange(editor, editor.selection);\n const domRect = domRange.getBoundingClientRect();\n const blocksInput = blocksRef.current;\n\n if (!blocksInput) {\n return;\n }\n\n const editorRect = blocksInput.getBoundingClientRect();\n\n // Check if the selection is not fully within the visible area of the editor\n if (domRect.top < editorRect.top || domRect.bottom > editorRect.bottom) {\n // Scroll by one line to the bottom\n blocksInput.scrollBy({\n top: 28, // 20px is the line-height + 8px line gap\n behavior: 'smooth',\n });\n }\n };\n\n return (\n <Box\n ref={blocksRef}\n grow={1}\n width=\"100%\"\n overflow=\"auto\"\n fontSize={2}\n background=\"neutral0\"\n color=\"neutral800\"\n lineHeight={6}\n paddingRight={7}\n paddingTop={6}\n paddingBottom={3}\n >\n <StyledEditable\n aria-labelledby={ariaLabelId}\n readOnly={disabled}\n placeholder={placeholder}\n isExpandedMode={isExpandedMode}\n decorate={decorateCode}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n onKeyDown={handleKeyDown}\n scrollSelectionIntoView={handleScrollSelectionIntoView}\n // As we have our own handler to drag and drop the elements returing true will skip slate's own event handler\n onDrop={() => {\n return true;\n }}\n onDragStart={() => {\n return true;\n }}\n />\n {modalElement}\n </Box>\n );\n};\n\nexport { BlocksContent, BlocksContentProps };\n"],"names":["StyledEditable","styled","Editable","theme","spaces","props","isExpandedMode","Wrapper","Box","isOverDropTarget","DropPlaceholder","dragDirection","placeholderMargin","css","DIRECTIONS","UPWARD","DOWNWARD","DragItem","Flex","$dragVisibility","DragIconButton","IconButton","borderRadius","$dragHandleTopMargin","colors","neutral100","neutral150","neutral500","DragAndDropElement","children","index","setDragDirection","dragHandleTopMargin","editor","disabled","name","setLiveText","useBlocksEditorContext","formatMessage","useIntl","dragVisibility","setDragVisibility","React","useState","handleMoveBlock","useCallback","newIndex","currentIndex","Transforms","moveNodes","at","to","currentIndexPosition","slice","newIndexPosition","id","getTranslation","defaultMessage","item","join","position","length","handlerId","isDragging","direction","blockRef","dropRef","dragRef","useDragAndDrop","type","ItemTypes","BLOCKS","displayedValue","onDropItem","composedBoxRefs","useComposedRefs","useEffect","selection","_jsxs","ref","_jsx","borderStyle","borderColor","borderWidth","width","marginLeft","as","CloneDragItem","data-handler-id","gap","paddingLeft","alignItems","onDragStart","event","target","currentTarget","getAttribute","preventDefault","style","opacity","onDragEnd","onMouseMove","onSelect","onMouseLeave","aria-disabled","tag","contentEditable","role","tabIndex","withTooltip","label","onClick","e","stopPropagation","draggable","Drag","color","baseRenderLeaf","modifiers","wrappedChildren","getEntries","reduce","currentChildren","modifierEntry","modifier","leaf","renderLeaf","span","attributes","className","baseRenderElement","blocks","element","blockMatch","Object","values","find","block","matchNode","paragraph","nodePath","ReactEditor","findPath","isLinkNode","isListNode","indentLevel","renderElement","BlocksContent","placeholder","ariaLabelId","blocksRef","useRef","modalElement","handleConversionResult","useConversionModal","handleMoveBlocks","start","Range","path","key","checkSnippet","textNode","textNodePath","Editor","node","anchor","isEditor","blockMatchingSnippet","snippets","includes","text","handleConvert","delete","distance","unit","reverse","maybeRenderModal","handleEnter","selectedNode","selectedBlock","shiftKey","insertText","handleEnterKey","handleBackspaceEvent","handleBackspaceKey","handleTab","handleKeyboardShortcuts","isCtrlOrCmd","metaKey","ctrlKey","forEach","value","isValidEventKey","handleToggle","handleKeyDown","blur","handleScrollSelectionIntoView","domRange","toDOMRange","domRect","getBoundingClientRect","blocksInput","current","editorRect","top","bottom","scrollBy","behavior","grow","overflow","fontSize","background","lineHeight","paddingRight","paddingTop","paddingBottom","aria-labelledby","readOnly","decorate","decorateCode","onKeyDown","scrollSelectionIntoView","onDrop"],"mappings":";;;;;;;;;;;;;;;;AA2BA,MAAMA,cAAAA,GAAiBC,MAAOC,CAAAA,QAAAA,CAAsC;;;;;OAK7D,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAAC,CAAA,CAAE,CAAC;;;AAG/B,SAAA,EAAE,CAACC,KAAWA,GAAAA,KAAAA,CAAMC,cAAc,GAAG,UAAU,MAAQ,CAAA;;;;oBAI5C,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAAC,CAAA,CAAE,CAAC;;AAErD,CAAC;AAED,MAAMG,OAAAA,GAAUN,MAAqBO,CAAAA,GAAA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AA;QACTC,QAAU,EAAA,CAAA;QACVC,UAAW,EAAA,UAAA;QACX/F,KAAM,EAAA,YAAA;QACNgG,UAAY,EAAA,CAAA;QACZC,YAAc,EAAA,CAAA;QACdC,UAAY,EAAA,CAAA;QACZC,aAAe,EAAA,CAAA;;0BAEfvI,GAAChF,CAAAA,cAAAA,EAAAA;gBACCwN,iBAAiBnE,EAAAA,WAAAA;gBACjBoE,QAAUvL,EAAAA,QAAAA;gBACVkH,WAAaA,EAAAA,WAAAA;gBACb9I,cAAgBA,EAAAA,cAAAA;gBAChBoN,QAAUC,EAAAA,YAAAA;gBACVzE,aAAeA,EAAAA,aAAAA;gBACfpB,UAAYA,EAAAA,UAAAA;gBACZ8F,SAAW1B,EAAAA,aAAAA;gBACX2B,uBAAyBzB,EAAAA,6BAAAA;;gBAEzB0B,MAAQ,EAAA,IAAA;oBACN,OAAO,IAAA;AACT,iBAAA;gBACAlI,WAAa,EAAA,IAAA;oBACX,OAAO,IAAA;AACT;;AAED4D,YAAAA;;;AAGP;;;;"}
|
|
1
|
+
{"version":3,"file":"BlocksContent.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Box,\n BoxComponent,\n Flex,\n FlexComponent,\n IconButton,\n IconButtonComponent,\n useComposedRefs,\n} from '@strapi/design-system';\nimport { Drag } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { Editor, Range, Transforms } from 'slate';\nimport { ReactEditor, type RenderElementProps, type RenderLeafProps, Editable } from 'slate-react';\nimport { styled, CSSProperties, css } from 'styled-components';\n\nimport { ItemTypes } from '../../../../../constants/dragAndDrop';\nimport { useDragAndDrop, DIRECTIONS } from '../../../../../hooks/useDragAndDrop';\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { decorateCode } from './Blocks/Code';\nimport { type BlocksStore, useBlocksEditorContext } from './BlocksEditor';\nimport { useConversionModal } from './BlocksToolbar';\nimport { type ModifiersStore } from './Modifiers';\nimport { getEntries, isLinkNode, isListNode } from './utils/types';\n\nconst StyledEditable = styled(Editable)<{ isExpandedMode: boolean }>`\n // The outline style is set on the wrapper with :focus-within\n outline: none;\n display: flex;\n flex-direction: column;\n gap: ${({ theme }) => theme.spaces[3]};\n height: 100%;\n // For fullscreen align input in the center with fixed width\n width: ${(props) => (props.isExpandedMode ? '512px' : '100%')};\n margin: auto;\n\n > *:last-child {\n padding-bottom: ${({ theme }) => theme.spaces[3]};\n }\n`;\n\nconst Wrapper = styled<BoxComponent>(Box)<{ isOverDropTarget: boolean }>`\n position: ${({ isOverDropTarget }) => isOverDropTarget && 'relative'};\n`;\n\ntype DragDirection = (typeof DIRECTIONS)[keyof typeof DIRECTIONS];\n\nconst DropPlaceholder = styled<BoxComponent>(Box)<{\n dragDirection: DragDirection | null;\n placeholderMargin: 1 | 2;\n}>`\n position: absolute;\n right: 0;\n\n // Show drop placeholder 8px above or below the drop target\n ${({ dragDirection, theme, placeholderMargin }) => css`\n top: ${dragDirection === DIRECTIONS.UPWARD && `-${theme.spaces[placeholderMargin]}`};\n bottom: ${dragDirection === DIRECTIONS.DOWNWARD && `-${theme.spaces[placeholderMargin]}`};\n `}\n`;\n\nconst DragItem = styled<FlexComponent>(Flex)<{ $dragVisibility: CSSProperties['visibility'] }>`\n // Style each block rendered using renderElement()\n & > [data-slate-node='element'] {\n width: 100%;\n opacity: inherit;\n }\n\n // Set the visibility of drag button\n [role='button'] {\n visibility: ${(props) => props.$dragVisibility};\n opacity: inherit;\n }\n &[aria-disabled='true'] {\n user-drag: none;\n }\n`;\n\nconst DragIconButton = styled<IconButtonComponent<'div'>>(IconButton)<{\n $dragHandleTopMargin?: CSSProperties['marginTop'];\n}>`\n user-select: none;\n display: flex;\n align-items: center;\n justify-content: center;\n border: none;\n border-radius: ${({ theme }) => theme.borderRadius};\n padding-left: ${({ theme }) => theme.spaces[0]};\n padding-right: ${({ theme }) => theme.spaces[0]};\n padding-top: ${({ theme }) => theme.spaces[1]};\n padding-bottom: ${({ theme }) => theme.spaces[1]};\n visibility: hidden;\n cursor: grab;\n opacity: inherit;\n margin-top: ${(props) => props.$dragHandleTopMargin ?? 0};\n\n &:hover {\n background: ${({ theme }) => theme.colors.neutral100};\n }\n &:active {\n cursor: grabbing;\n background: ${({ theme }) => theme.colors.neutral150};\n }\n &[aria-disabled='true'] {\n visibility: hidden;\n }\n svg {\n min-width: ${({ theme }) => theme.spaces[3]};\n\n path {\n fill: ${({ theme }) => theme.colors.neutral500};\n }\n }\n`;\n\ntype Direction = {\n setDragDirection: (direction: DragDirection) => void;\n dragDirection: DragDirection | null;\n};\n\ntype DragAndDropElementProps = Direction & {\n children: RenderElementProps['children'];\n index: Array<number>;\n dragHandleTopMargin?: CSSProperties['marginTop'];\n};\n\nconst DragAndDropElement = ({\n children,\n index,\n setDragDirection,\n dragDirection,\n dragHandleTopMargin,\n}: DragAndDropElementProps) => {\n const { editor, disabled, name, setLiveText } = useBlocksEditorContext('drag-and-drop');\n const { formatMessage } = useIntl();\n const [dragVisibility, setDragVisibility] = React.useState<CSSProperties['visibility']>('hidden');\n\n const handleMoveBlock = React.useCallback(\n (newIndex: Array<number>, currentIndex: Array<number>) => {\n Transforms.moveNodes(editor, {\n at: currentIndex,\n to: newIndex,\n });\n\n // Add 1 to the index for the live text message\n const currentIndexPosition = [currentIndex[0] + 1, ...currentIndex.slice(1)];\n const newIndexPosition = [newIndex[0] + 1, ...newIndex.slice(1)];\n\n setLiveText(\n formatMessage(\n {\n id: getTranslation('components.Blocks.dnd.reorder'),\n defaultMessage: '{item}, moved. New position in the editor: {position}.',\n },\n {\n item: `${name}.${currentIndexPosition.join(',')}`,\n position: `${newIndexPosition.join(',')} of ${editor.children.length}`,\n }\n )\n );\n },\n [editor, formatMessage, name, setLiveText]\n );\n\n const [{ handlerId, isDragging, isOverDropTarget, direction }, blockRef, dropRef, dragRef] =\n useDragAndDrop(!disabled, {\n type: `${ItemTypes.BLOCKS}_${name}`,\n index,\n item: {\n index,\n displayedValue: children,\n },\n onDropItem(currentIndex, newIndex) {\n if (newIndex) handleMoveBlock(newIndex, currentIndex);\n },\n });\n\n const composedBoxRefs = useComposedRefs(blockRef, dropRef);\n\n // Set Drag direction before loosing state while dragging\n React.useEffect(() => {\n if (direction) {\n setDragDirection(direction);\n }\n }, [direction, setDragDirection]);\n\n // On selection change hide drag handle\n React.useEffect(() => {\n setDragVisibility('hidden');\n }, [editor.selection]);\n\n return (\n <Wrapper ref={composedBoxRefs} isOverDropTarget={isOverDropTarget}>\n {isOverDropTarget && (\n <DropPlaceholder\n borderStyle=\"solid\"\n borderColor=\"secondary200\"\n borderWidth=\"2px\"\n width=\"calc(100% - 24px)\"\n marginLeft=\"auto\"\n dragDirection={dragDirection}\n // For list items placeholder reduce the margin around\n placeholderMargin={children.props.as && children.props.as === 'li' ? 1 : 2}\n />\n )}\n {isDragging ? (\n <CloneDragItem dragHandleTopMargin={dragHandleTopMargin}>{children}</CloneDragItem>\n ) : (\n <DragItem\n ref={dragRef}\n data-handler-id={handlerId}\n gap={2}\n paddingLeft={2}\n alignItems=\"start\"\n onDragStart={(event) => {\n const target = event.target as HTMLElement;\n const currentTarget = event.currentTarget as HTMLElement;\n\n // Dragging action should only trigger drag event when button is dragged, however update styles on the whole dragItem.\n if (target.getAttribute('role') !== 'button') {\n event.preventDefault();\n } else {\n // Setting styles using dragging state is not working, so set it on current target element as nodes get dragged\n currentTarget.style.opacity = '0.5';\n }\n }}\n onDragEnd={(event) => {\n const currentTarget = event.currentTarget as HTMLElement;\n currentTarget.style.opacity = '1';\n }}\n onMouseMove={() => setDragVisibility('visible')}\n onSelect={() => setDragVisibility('visible')}\n onMouseLeave={() => setDragVisibility('hidden')}\n aria-disabled={disabled}\n $dragVisibility={dragVisibility}\n >\n <DragIconButton\n tag=\"div\"\n contentEditable={false}\n role=\"button\"\n tabIndex={0}\n withTooltip={false}\n label={formatMessage({\n id: getTranslation('components.DragHandle-label'),\n defaultMessage: 'Drag',\n })}\n onClick={(e) => e.stopPropagation()}\n aria-disabled={disabled}\n disabled={disabled}\n draggable\n // For some blocks top margin added to drag handle to align at the text level\n $dragHandleTopMargin={dragHandleTopMargin}\n >\n <Drag color=\"primary500\" />\n </DragIconButton>\n {children}\n </DragItem>\n )}\n </Wrapper>\n );\n};\n\ninterface CloneDragItemProps {\n children: RenderElementProps['children'];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\n// To prevent applying opacity to the original item being dragged, display a cloned element without opacity.\nconst CloneDragItem = ({ children, dragHandleTopMargin }: CloneDragItemProps) => {\n const { formatMessage } = useIntl();\n\n return (\n <DragItem gap={2} paddingLeft={2} alignItems=\"start\" $dragVisibility=\"visible\">\n <DragIconButton\n tag=\"div\"\n role=\"button\"\n withTooltip={false}\n label={formatMessage({\n id: getTranslation('components.DragHandle-label'),\n defaultMessage: 'Drag',\n })}\n $dragHandleTopMargin={dragHandleTopMargin}\n >\n <Drag color=\"neutral600\" />\n </DragIconButton>\n {children}\n </DragItem>\n );\n};\n\ninterface ExtendedRenderLeafProps extends RenderLeafProps {\n leaf: RenderLeafProps['leaf'] & { className?: string };\n}\n\nconst baseRenderLeaf = (props: ExtendedRenderLeafProps, modifiers: ModifiersStore) => {\n // Recursively wrap the children for each active modifier\n const wrappedChildren = getEntries(modifiers).reduce((currentChildren, modifierEntry) => {\n const [name, modifier] = modifierEntry;\n\n if (props.leaf[name]) {\n return modifier.renderLeaf(currentChildren);\n }\n\n return currentChildren;\n }, props.children);\n\n return (\n <span {...props.attributes} className={props.leaf.className}>\n {wrappedChildren}\n </span>\n );\n};\n\ntype BaseRenderElementProps = Direction & {\n props: RenderElementProps['children'];\n blocks: BlocksStore;\n editor: Editor;\n};\n\nconst baseRenderElement = ({\n props,\n blocks,\n editor,\n setDragDirection,\n dragDirection,\n}: BaseRenderElementProps) => {\n const { element } = props;\n\n const blockMatch = Object.values(blocks).find((block) => block.matchNode(element));\n const block = blockMatch || blocks.paragraph;\n const nodePath = ReactEditor.findPath(editor, element);\n\n // Link is inline block so it cannot be dragged\n // List items and nested list blocks i.e. lists with indent level higher than 0 are skipped from dragged items\n if (\n isLinkNode(element) ||\n (isListNode(element) && element.indentLevel && element.indentLevel > 0) ||\n element.type === 'list-item'\n ) {\n return block.renderElement(props);\n }\n\n return (\n <DragAndDropElement\n index={nodePath}\n setDragDirection={setDragDirection}\n dragDirection={dragDirection}\n dragHandleTopMargin={block.dragHandleTopMargin}\n >\n {block.renderElement(props)}\n </DragAndDropElement>\n );\n};\n\nconst dragNoop = () => true;\n\ninterface BlocksContentProps {\n placeholder?: string;\n ariaLabelId: string;\n}\n\nconst BlocksContent = ({ placeholder, ariaLabelId }: BlocksContentProps) => {\n const { editor, disabled, blocks, modifiers, setLiveText, isExpandedMode } =\n useBlocksEditorContext('BlocksContent');\n const blocksRef = React.useRef<HTMLDivElement>(null);\n const { formatMessage } = useIntl();\n const [dragDirection, setDragDirection] = React.useState<DragDirection | null>(null);\n const { modalElement, handleConversionResult } = useConversionModal();\n\n // Create renderLeaf function based on the modifiers store\n const renderLeaf = React.useCallback(\n (props: ExtendedRenderLeafProps) => baseRenderLeaf(props, modifiers),\n [modifiers]\n );\n\n const handleMoveBlocks = (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) return;\n\n const start = Range.start(editor.selection);\n const currentIndex = [start.path[0]];\n let newIndexPosition = 0;\n\n if (event.key === 'ArrowUp') {\n newIndexPosition = currentIndex[0] > 0 ? currentIndex[0] - 1 : currentIndex[0];\n } else {\n newIndexPosition =\n currentIndex[0] < editor.children.length - 1 ? currentIndex[0] + 1 : currentIndex[0];\n }\n\n const newIndex = [newIndexPosition];\n\n if (newIndexPosition !== currentIndex[0]) {\n Transforms.moveNodes(editor, {\n at: currentIndex,\n to: newIndex,\n });\n\n setLiveText(\n formatMessage(\n {\n id: getTranslation('components.Blocks.dnd.reorder'),\n defaultMessage: '{item}, moved. New position in the editor: {position}.',\n },\n {\n item: `${name}.${currentIndex[0] + 1}`,\n position: `${newIndex[0] + 1} of ${editor.children.length}`,\n }\n )\n );\n\n event.preventDefault();\n }\n };\n\n // Create renderElement function base on the blocks store\n const renderElement = React.useCallback(\n (props: RenderElementProps) =>\n baseRenderElement({ props, blocks, editor, dragDirection, setDragDirection }),\n [blocks, editor, dragDirection, setDragDirection]\n );\n\n const checkSnippet = (event: React.KeyboardEvent<HTMLElement>) => {\n // Get current text block\n if (!editor.selection) {\n return;\n }\n\n const [textNode, textNodePath] = Editor.node(editor, editor.selection.anchor.path);\n\n // Narrow the type to a text node\n if (Editor.isEditor(textNode) || textNode.type !== 'text') {\n return;\n }\n\n // Don't check for snippets if we're not at the start of a block\n if (textNodePath.at(-1) !== 0) {\n return;\n }\n\n // Check if the text node starts with a known snippet\n const blockMatchingSnippet = Object.values(blocks).find((block) => {\n return block.snippets?.includes(textNode.text);\n });\n\n if (blockMatchingSnippet?.handleConvert) {\n // Prevent the space from being created and delete the snippet\n event.preventDefault();\n Transforms.delete(editor, {\n distance: textNode.text.length,\n unit: 'character',\n reverse: true,\n });\n\n // Convert the selected block\n const maybeRenderModal = blockMatchingSnippet.handleConvert(editor);\n handleConversionResult(maybeRenderModal);\n }\n };\n\n const handleEnter = (event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) {\n return;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));\n if (!selectedBlock) {\n return;\n }\n\n // Allow forced line breaks when shift is pressed\n if (event.shiftKey && selectedNode.type !== 'image') {\n Transforms.insertText(editor, '\\n');\n return;\n }\n\n // Check if there's an enter handler for the selected block\n if (selectedBlock.handleEnterKey) {\n selectedBlock.handleEnterKey(editor);\n } else {\n blocks.paragraph.handleEnterKey!(editor);\n }\n };\n\n const handleBackspaceEvent = (event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) {\n return;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));\n\n if (!selectedBlock) {\n return;\n }\n\n if (selectedBlock.handleBackspaceKey) {\n selectedBlock.handleBackspaceKey(editor, event);\n }\n };\n\n const handleTab = (event: React.KeyboardEvent<HTMLElement>) => {\n if (!editor.selection) {\n return;\n }\n\n const selectedNode = editor.children[editor.selection.anchor.path[0]];\n const selectedBlock = Object.values(blocks).find((block) => block.matchNode(selectedNode));\n if (!selectedBlock) {\n return;\n }\n\n if (selectedBlock.handleTab) {\n event.preventDefault();\n selectedBlock.handleTab(editor);\n }\n };\n\n const handleKeyboardShortcuts = (event: React.KeyboardEvent<HTMLElement>) => {\n const isCtrlOrCmd = event.metaKey || event.ctrlKey;\n\n if (isCtrlOrCmd) {\n // Check if there's a modifier to toggle\n Object.values(modifiers).forEach((value) => {\n if (value.isValidEventKey(event)) {\n value.handleToggle(editor);\n return;\n }\n });\n if (event.shiftKey && ['ArrowUp', 'ArrowDown'].includes(event.key)) {\n handleMoveBlocks(editor, event);\n }\n }\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLElement> = (event) => {\n // Find the right block-specific handlers for enter and backspace key presses\n switch (event.key) {\n case 'Enter':\n event.preventDefault();\n return handleEnter(event);\n case 'Backspace':\n return handleBackspaceEvent(event);\n case 'Tab':\n return handleTab(event);\n case 'Escape':\n return ReactEditor.blur(editor);\n }\n handleKeyboardShortcuts(event);\n // Check if a snippet was triggered\n if (event.key === ' ') {\n checkSnippet(event);\n }\n };\n\n /**\n * scrollSelectionIntoView : Slate's default method to scroll a DOM selection into the view,\n * thats shifting layout for us when there is a overflowY:scroll on the viewport.\n * We are overriding it to check if the selection is not fully within the visible area of the editor,\n * we use scrollBy one line to the bottom\n */\n\n const handleScrollSelectionIntoView = React.useCallback(() => {\n if (!editor.selection || !blocksRef.current) {\n return;\n }\n\n const domRange = ReactEditor.toDOMRange(editor, editor.selection);\n const domRect = domRange.getBoundingClientRect();\n\n const editorRect = blocksRef.current.getBoundingClientRect();\n\n // Check if the selection is not fully within the visible area of the editor\n if (domRect.top < editorRect.top || domRect.bottom > editorRect.bottom) {\n // Scroll by one line to the bottom\n blocksRef.current.scrollBy({\n top: 28, // 20px is the line-height + 8px line gap\n behavior: 'smooth',\n });\n }\n }, [editor]);\n\n return (\n <Box\n ref={blocksRef}\n grow={1}\n width=\"100%\"\n overflow=\"auto\"\n fontSize={2}\n background=\"neutral0\"\n color=\"neutral800\"\n lineHeight={6}\n paddingRight={7}\n paddingTop={6}\n paddingBottom={3}\n >\n <StyledEditable\n aria-labelledby={ariaLabelId}\n readOnly={disabled}\n placeholder={placeholder}\n isExpandedMode={isExpandedMode}\n decorate={decorateCode}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n onKeyDown={handleKeyDown}\n scrollSelectionIntoView={handleScrollSelectionIntoView}\n // As we have our own handler to drag and drop the elements returing true will skip slate's own event handler\n onDrop={dragNoop}\n onDragStart={dragNoop}\n />\n {modalElement}\n </Box>\n );\n};\n\nexport { BlocksContent, BlocksContentProps };\n"],"names":["StyledEditable","styled","Editable","theme","spaces","props","isExpandedMode","Wrapper","Box","isOverDropTarget","DropPlaceholder","dragDirection","placeholderMargin","css","DIRECTIONS","UPWARD","DOWNWARD","DragItem","Flex","$dragVisibility","DragIconButton","IconButton","borderRadius","$dragHandleTopMargin","colors","neutral100","neutral150","neutral500","DragAndDropElement","children","index","setDragDirection","dragHandleTopMargin","editor","disabled","name","setLiveText","useBlocksEditorContext","formatMessage","useIntl","dragVisibility","setDragVisibility","React","useState","handleMoveBlock","useCallback","newIndex","currentIndex","Transforms","moveNodes","at","to","currentIndexPosition","slice","newIndexPosition","id","getTranslation","defaultMessage","item","join","position","length","handlerId","isDragging","direction","blockRef","dropRef","dragRef","useDragAndDrop","type","ItemTypes","BLOCKS","displayedValue","onDropItem","composedBoxRefs","useComposedRefs","useEffect","selection","_jsxs","ref","_jsx","borderStyle","borderColor","borderWidth","width","marginLeft","as","CloneDragItem","data-handler-id","gap","paddingLeft","alignItems","onDragStart","event","target","currentTarget","getAttribute","preventDefault","style","opacity","onDragEnd","onMouseMove","onSelect","onMouseLeave","aria-disabled","tag","contentEditable","role","tabIndex","withTooltip","label","onClick","e","stopPropagation","draggable","Drag","color","baseRenderLeaf","modifiers","wrappedChildren","getEntries","reduce","currentChildren","modifierEntry","modifier","leaf","renderLeaf","span","attributes","className","baseRenderElement","blocks","element","blockMatch","Object","values","find","block","matchNode","paragraph","nodePath","ReactEditor","findPath","isLinkNode","isListNode","indentLevel","renderElement","dragNoop","BlocksContent","placeholder","ariaLabelId","blocksRef","useRef","modalElement","handleConversionResult","useConversionModal","handleMoveBlocks","start","Range","path","key","checkSnippet","textNode","textNodePath","Editor","node","anchor","isEditor","blockMatchingSnippet","snippets","includes","text","handleConvert","delete","distance","unit","reverse","maybeRenderModal","handleEnter","selectedNode","selectedBlock","shiftKey","insertText","handleEnterKey","handleBackspaceEvent","handleBackspaceKey","handleTab","handleKeyboardShortcuts","isCtrlOrCmd","metaKey","ctrlKey","forEach","value","isValidEventKey","handleToggle","handleKeyDown","blur","handleScrollSelectionIntoView","current","domRange","toDOMRange","domRect","getBoundingClientRect","editorRect","top","bottom","scrollBy","behavior","grow","overflow","fontSize","background","lineHeight","paddingRight","paddingTop","paddingBottom","aria-labelledby","readOnly","decorate","decorateCode","onKeyDown","scrollSelectionIntoView","onDrop"],"mappings":";;;;;;;;;;;;;;;;AA2BA,MAAMA,cAAAA,GAAiBC,MAAOC,CAAAA,QAAAA,CAAsC;;;;;OAK7D,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAAC,CAAA,CAAE,CAAC;;;AAG/B,SAAA,EAAE,CAACC,KAAWA,GAAAA,KAAAA,CAAMC,cAAc,GAAG,UAAU,MAAQ,CAAA;;;;oBAI5C,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAAC,CAAA,CAAE,CAAC;;AAErD,CAAC;AAED,MAAMG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AAAA,GAAAA,EAAAA;QACCuE,GAAKwE,EAAAA,SAAAA;QACLyD,IAAM,EAAA,CAAA;QACN5H,KAAM,EAAA,MAAA;QACN6H,QAAS,EAAA,MAAA;QACTC,QAAU,EAAA,CAAA;QACVC,UAAW,EAAA,UAAA;QACX/F,KAAM,EAAA,YAAA;QACNgG,UAAY,EAAA,CAAA;QACZC,YAAc,EAAA,CAAA;QACdC,UAAY,EAAA,CAAA;QACZC,aAAe,EAAA,CAAA;;0BAEfvI,GAAChF,CAAAA,cAAAA,EAAAA;gBACCwN,iBAAiBlE,EAAAA,WAAAA;gBACjBmE,QAAUvL,EAAAA,QAAAA;gBACVmH,WAAaA,EAAAA,WAAAA;gBACb/I,cAAgBA,EAAAA,cAAAA;gBAChBoN,QAAUC,EAAAA,YAAAA;gBACVzE,aAAeA,EAAAA,aAAAA;gBACfpB,UAAYA,EAAAA,UAAAA;gBACZ8F,SAAWzB,EAAAA,aAAAA;gBACX0B,uBAAyBxB,EAAAA,6BAAAA;;gBAEzByB,MAAQ3E,EAAAA,QAAAA;gBACRvD,WAAauD,EAAAA;;AAEdM,YAAAA;;;AAGP;;;;"}
|
|
@@ -103,9 +103,12 @@ function useBlocksEditorContext(consumerName) {
|
|
|
103
103
|
}, [
|
|
104
104
|
value
|
|
105
105
|
]);
|
|
106
|
+
const incrementSlateUpdatesCount = React__namespace.useCallback(()=>{
|
|
107
|
+
slateUpdatesCount.current += 1;
|
|
108
|
+
}, []);
|
|
106
109
|
return {
|
|
107
110
|
key,
|
|
108
|
-
incrementSlateUpdatesCount
|
|
111
|
+
incrementSlateUpdatesCount
|
|
109
112
|
};
|
|
110
113
|
}
|
|
111
114
|
const pipe = (...fns)=>(value)=>fns.reduce((prev, fn)=>fn(prev), value);
|
|
@@ -127,22 +130,59 @@ const BlocksEditor = /*#__PURE__*/ React__namespace.forwardRef(({ disabled = fal
|
|
|
127
130
|
editor
|
|
128
131
|
]);
|
|
129
132
|
const { key, incrementSlateUpdatesCount } = useResetKey(value);
|
|
130
|
-
const
|
|
133
|
+
const debounceTimeout = React__namespace.useRef(null);
|
|
134
|
+
const handleSlateChange = React__namespace.useCallback((state)=>{
|
|
131
135
|
const isAstChange = editor.operations.some((op)=>op.type !== 'set_selection');
|
|
132
136
|
if (isAstChange) {
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Slate handles the state of the editor internally. We just need to keep Strapi's form
|
|
139
|
+
* state in sync with it in order to make sure that things like the "modified" state
|
|
140
|
+
* isn't broken. Updating the whole state on every change is very expensive however,
|
|
141
|
+
* so we debounce calls to onChange to mitigate input lag.
|
|
142
|
+
*/ if (debounceTimeout.current) {
|
|
143
|
+
clearTimeout(debounceTimeout.current);
|
|
144
|
+
}
|
|
145
|
+
// Set a new debounce timeout
|
|
146
|
+
debounceTimeout.current = setTimeout(()=>{
|
|
147
|
+
incrementSlateUpdatesCount();
|
|
148
|
+
onChange(name, state);
|
|
149
|
+
debounceTimeout.current = null;
|
|
150
|
+
}, 300);
|
|
135
151
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
}, [
|
|
153
|
+
editor.operations,
|
|
154
|
+
incrementSlateUpdatesCount,
|
|
155
|
+
name,
|
|
156
|
+
onChange
|
|
157
|
+
]);
|
|
158
|
+
// Clean up the timeout on unmount
|
|
159
|
+
React__namespace.useEffect(()=>{
|
|
160
|
+
return ()=>{
|
|
161
|
+
if (debounceTimeout.current) {
|
|
162
|
+
clearTimeout(debounceTimeout.current);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}, []);
|
|
166
|
+
// Ensure the editor is in sync after discard
|
|
167
|
+
React__namespace.useEffect(()=>{
|
|
168
|
+
// Compare the field value with the editor state to check for a stale selection
|
|
169
|
+
if (value && JSON.stringify(editor.children) !== JSON.stringify(value)) {
|
|
170
|
+
// When there is a diff, unset selection to avoid an invalid state
|
|
171
|
+
slate.Transforms.deselect(editor);
|
|
172
|
+
}
|
|
173
|
+
}, [
|
|
174
|
+
editor,
|
|
175
|
+
value
|
|
176
|
+
]);
|
|
177
|
+
const blocks = React__namespace.useMemo(()=>({
|
|
178
|
+
...Paragraph.paragraphBlocks,
|
|
179
|
+
...Heading.headingBlocks,
|
|
180
|
+
...List.listBlocks,
|
|
181
|
+
...Link.linkBlocks,
|
|
182
|
+
...Image.imageBlocks,
|
|
183
|
+
...Quote.quoteBlocks,
|
|
184
|
+
...Code.codeBlocks
|
|
185
|
+
}), []);
|
|
146
186
|
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
147
187
|
children: [
|
|
148
188
|
/*#__PURE__*/ jsxRuntime.jsx(designSystem.VisuallyHidden, {
|
|
@@ -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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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,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,CAAAA,oBAAAA,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,gBAAMC,CAAAA,MAAM,CAAC,CAAA,CAAA;;IAEvC,MAAMC,iBAAAA,GAA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A;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,CAAC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,iBAAA;gBACtF/C,QAAUsB,EAAAA,iBAAAA;AAGV,gBAAA,QAAA,gBAAAgB,GAAC1E,CAAAA,oBAAAA,EAAAA;oBACCgE,MAAQA,EAAAA,MAAAA;oBACRoB,SAAWA,EAAAA,SAAAA;oBACXlD,QAAUA,EAAAA,QAAAA;oBACVC,IAAMA,EAAAA,IAAAA;oBACNc,WAAaA,EAAAA,WAAAA;oBACbG,cAAgBA,EAAAA,cAAAA;AAEhB,oBAAA,QAAA,gBAAAoB,IAACa,CAAAA,YAAAA,EAAAA;wBACChD,KAAOA,EAAAA,KAAAA;wBACPH,QAAUA,EAAAA,QAAAA;wBACVoD,cAAgBjC,EAAAA,kBAAAA;wBAChBH,iBAAmBA,EAAAA,iBAAAA;;0CAEnBwB,GAACa,CAAAA,aAAAA,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,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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'
|