@gechiui/block-editor
Version:
108 lines (100 loc) • 3.13 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* GeChiUI dependencies
*/
import { __ } from '@gechiui/i18n';
import { compose } from '@gechiui/compose';
import { getDefaultBlockName } from '@gechiui/blocks';
import { decodeEntities } from '@gechiui/html-entities';
import { withSelect, withDispatch } from '@gechiui/data';
/**
* Internal dependencies
*/
import Inserter from '../inserter';
import { store as blockEditorStore } from '../../store';
/**
* Zero width non-breaking space, used as padding for the paragraph when it is
* empty.
*/
export const ZWNBSP = '\ufeff';
export function DefaultBlockAppender(_ref) {
let {
isLocked,
isVisible,
onAppend,
showPrompt,
placeholder,
rootClientId
} = _ref;
if (isLocked || !isVisible) {
return null;
}
const value = decodeEntities(placeholder) || __('输入/来选择一个区块');
return createElement("div", {
"data-root-client-id": rootClientId || '',
className: classnames('block-editor-default-block-appender', {
'has-visible-prompt': showPrompt
})
}, createElement("p", {
tabIndex: "0" // Only necessary for `useCanvasClickRedirect` to consider it
// as a target. Ideally it should consider any tabbable target,
// but the inserter is rendered in place while it should be
// rendered in a popover, just like it does for an empty
// paragraph block.
,
contentEditable: true,
suppressContentEditableWarning: true // We want this element to be styled as a paragraph by themes.
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role
,
role: "button",
"aria-label": __('添加区块') // A wrapping container for this one already has the gc-block className.
,
className: "block-editor-default-block-appender__content",
onFocus: onAppend
}, showPrompt ? value : ZWNBSP), createElement(Inserter, {
rootClientId: rootClientId,
position: "bottom right",
isAppender: true,
__experimentalIsQuick: true
}));
}
export default compose(withSelect((select, ownProps) => {
const {
getBlockCount,
getBlockName,
isBlockValid,
getSettings,
getTemplateLock
} = select(blockEditorStore);
const isEmpty = !getBlockCount(ownProps.rootClientId);
const isLastBlockDefault = getBlockName(ownProps.lastBlockClientId) === getDefaultBlockName();
const isLastBlockValid = isBlockValid(ownProps.lastBlockClientId);
const {
bodyPlaceholder
} = getSettings();
return {
isVisible: isEmpty || !isLastBlockDefault || !isLastBlockValid,
showPrompt: isEmpty,
isLocked: !!getTemplateLock(ownProps.rootClientId),
placeholder: bodyPlaceholder
};
}), withDispatch((dispatch, ownProps) => {
const {
insertDefaultBlock,
startTyping
} = dispatch(blockEditorStore);
return {
onAppend() {
const {
rootClientId
} = ownProps;
insertDefaultBlock(undefined, rootClientId);
startTyping();
}
};
}))(DefaultBlockAppender);
//# sourceMappingURL=index.js.map