@gechiui/block-editor
Version:
130 lines (109 loc) • 3.58 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DefaultBlockAppender = DefaultBlockAppender;
exports.default = exports.ZWNBSP = void 0;
var _element = require("@gechiui/element");
var _classnames = _interopRequireDefault(require("classnames"));
var _i18n = require("@gechiui/i18n");
var _compose = require("@gechiui/compose");
var _blocks = require("@gechiui/blocks");
var _htmlEntities = require("@gechiui/html-entities");
var _data = require("@gechiui/data");
var _inserter = _interopRequireDefault(require("../inserter"));
var _store = require("../../store");
/**
* External dependencies
*/
/**
* GeChiUI dependencies
*/
/**
* Internal dependencies
*/
/**
* Zero width non-breaking space, used as padding for the paragraph when it is
* empty.
*/
const ZWNBSP = '\ufeff';
exports.ZWNBSP = ZWNBSP;
function DefaultBlockAppender(_ref) {
let {
isLocked,
isVisible,
onAppend,
showPrompt,
placeholder,
rootClientId
} = _ref;
if (isLocked || !isVisible) {
return null;
}
const value = (0, _htmlEntities.decodeEntities)(placeholder) || (0, _i18n.__)('输入/来选择一个区块');
return (0, _element.createElement)("div", {
"data-root-client-id": rootClientId || '',
className: (0, _classnames.default)('block-editor-default-block-appender', {
'has-visible-prompt': showPrompt
})
}, (0, _element.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": (0, _i18n.__)('添加区块') // A wrapping container for this one already has the gc-block className.
,
className: "block-editor-default-block-appender__content",
onFocus: onAppend
}, showPrompt ? value : ZWNBSP), (0, _element.createElement)(_inserter.default, {
rootClientId: rootClientId,
position: "bottom right",
isAppender: true,
__experimentalIsQuick: true
}));
}
var _default = (0, _compose.compose)((0, _data.withSelect)((select, ownProps) => {
const {
getBlockCount,
getBlockName,
isBlockValid,
getSettings,
getTemplateLock
} = select(_store.store);
const isEmpty = !getBlockCount(ownProps.rootClientId);
const isLastBlockDefault = getBlockName(ownProps.lastBlockClientId) === (0, _blocks.getDefaultBlockName)();
const isLastBlockValid = isBlockValid(ownProps.lastBlockClientId);
const {
bodyPlaceholder
} = getSettings();
return {
isVisible: isEmpty || !isLastBlockDefault || !isLastBlockValid,
showPrompt: isEmpty,
isLocked: !!getTemplateLock(ownProps.rootClientId),
placeholder: bodyPlaceholder
};
}), (0, _data.withDispatch)((dispatch, ownProps) => {
const {
insertDefaultBlock,
startTyping
} = dispatch(_store.store);
return {
onAppend() {
const {
rootClientId
} = ownProps;
insertDefaultBlock(undefined, rootClientId);
startTyping();
}
};
}))(DefaultBlockAppender);
exports.default = _default;
//# sourceMappingURL=index.js.map