UNPKG

@wordpress/block-library

Version:
87 lines (84 loc) 2.76 kB
import { createElement, Fragment } from "@wordpress/element"; /** * WordPress dependencies */ import { RichText, useBlockProps, useInnerBlocksProps, BlockControls } from '@wordpress/block-editor'; import { isRTL, __ } from '@wordpress/i18n'; import { ToolbarButton } from '@wordpress/components'; import { formatOutdent, formatOutdentRTL, formatIndentRTL, formatIndent } from '@wordpress/icons'; import { useMergeRefs } from '@wordpress/compose'; /** * Internal dependencies */ import { useEnter, useSpace, useIndentListItem, useOutdentListItem, useSplit, useMerge, useCopy } from './hooks'; import { convertToListItems } from './utils'; export function IndentUI(_ref) { let { clientId } = _ref; const [canIndent, indentListItem] = useIndentListItem(clientId); const [canOutdent, outdentListItem] = useOutdentListItem(clientId); return createElement(Fragment, null, createElement(ToolbarButton, { icon: isRTL() ? formatOutdentRTL : formatOutdent, title: __('Outdent'), describedBy: __('Outdent list item'), disabled: !canOutdent, onClick: () => outdentListItem() }), createElement(ToolbarButton, { icon: isRTL() ? formatIndentRTL : formatIndent, title: __('Indent'), describedBy: __('Indent list item'), isDisabled: !canIndent, onClick: () => indentListItem() })); } export default function ListItemEdit(_ref2) { let { attributes, setAttributes, onReplace, clientId } = _ref2; const { placeholder, content } = attributes; const blockProps = useBlockProps({ ref: useCopy(clientId) }); const innerBlocksProps = useInnerBlocksProps(blockProps, { allowedBlocks: ['core/list'], renderAppender: false }); const useEnterRef = useEnter({ content, clientId }); const useSpaceRef = useSpace(clientId); const onSplit = useSplit(clientId); const onMerge = useMerge(clientId); return createElement(Fragment, null, createElement("li", innerBlocksProps, createElement(RichText, { ref: useMergeRefs([useEnterRef, useSpaceRef]), identifier: "content", tagName: "div", onChange: nextContent => setAttributes({ content: nextContent }), value: content, "aria-label": __('List text'), placeholder: placeholder || __('List'), onSplit: onSplit, onMerge: onMerge, onReplace: function (blocks) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } onReplace(convertToListItems(blocks), ...args); } }), innerBlocksProps.children), createElement(BlockControls, { group: "block" }, createElement(IndentUI, { clientId: clientId }))); } //# sourceMappingURL=edit.js.map