@gechiui/block-editor
Version:
137 lines (112 loc) • 4.27 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _element = require("@gechiui/element");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _lodash = require("lodash");
var _classnames = _interopRequireDefault(require("classnames"));
var _icons = require("@gechiui/icons");
var _components = require("@gechiui/components");
var _blocks = require("@gechiui/blocks");
var _data = require("@gechiui/data");
var _i18n = require("@gechiui/i18n");
var _blockDraggable = _interopRequireDefault(require("../block-draggable"));
var _button = require("./button");
var _store = require("../../store");
/**
* External dependencies
*/
/**
* GeChiUI dependencies
*/
/**
* Internal dependencies
*/
function BlockMover(_ref) {
let {
isFirst,
isLast,
clientIds,
canMove,
isHidden,
rootClientId,
orientation,
hideDragHandle
} = _ref;
const [isFocused, setIsFocused] = (0, _element.useState)(false);
const onFocus = () => setIsFocused(true);
const onBlur = () => setIsFocused(false);
if (!canMove || isFirst && isLast && !rootClientId) {
return null;
}
const dragHandleLabel = (0, _i18n.__)('拖动'); // We emulate a disabled state because forcefully applying the `disabled`
// attribute on the buttons while it has focus causes the screen to change
// to an unfocused state (body as active element) without firing blur on,
// the rendering parent, leaving it unable to react to focus out.
return (0, _element.createElement)("div", {
className: (0, _classnames.default)('block-editor-block-mover', {
'is-visible': isFocused || !isHidden,
'is-horizontal': orientation === 'horizontal'
})
}, !hideDragHandle && (0, _element.createElement)(_blockDraggable.default, {
clientIds: clientIds,
cloneClassname: "block-editor-block-mover__drag-clone"
}, draggableProps => (0, _element.createElement)(_components.Button, (0, _extends2.default)({
icon: _icons.dragHandle,
className: "block-editor-block-mover__drag-handle",
"aria-hidden": "true",
label: dragHandleLabel // Should not be able to tab to drag handle as this
// button can only be used with a pointer device.
,
tabIndex: "-1"
}, draggableProps))), (0, _element.createElement)(_components.ToolbarGroup, {
className: "block-editor-block-mover__move-button-container"
}, (0, _element.createElement)(_components.ToolbarItem, {
onFocus: onFocus,
onBlur: onBlur
}, itemProps => (0, _element.createElement)(_button.BlockMoverUpButton, (0, _extends2.default)({
clientIds: clientIds
}, itemProps))), (0, _element.createElement)(_components.ToolbarItem, {
onFocus: onFocus,
onBlur: onBlur
}, itemProps => (0, _element.createElement)(_button.BlockMoverDownButton, (0, _extends2.default)({
clientIds: clientIds
}, itemProps)))));
}
var _default = (0, _data.withSelect)((select, _ref2) => {
var _getBlockListSettings;
let {
clientIds
} = _ref2;
const {
getBlock,
getBlockIndex,
getBlockListSettings,
canMoveBlocks,
getBlockOrder,
getBlockRootClientId
} = select(_store.store);
const normalizedClientIds = (0, _lodash.castArray)(clientIds);
const firstClientId = (0, _lodash.first)(normalizedClientIds);
const block = getBlock(firstClientId);
const rootClientId = getBlockRootClientId((0, _lodash.first)(normalizedClientIds));
const firstIndex = getBlockIndex(firstClientId);
const lastIndex = getBlockIndex((0, _lodash.last)(normalizedClientIds));
const blockOrder = getBlockOrder(rootClientId);
const isFirst = firstIndex === 0;
const isLast = lastIndex === blockOrder.length - 1;
return {
blockType: block ? (0, _blocks.getBlockType)(block.name) : null,
canMove: canMoveBlocks(clientIds, rootClientId),
rootClientId,
firstIndex,
isFirst,
isLast,
orientation: (_getBlockListSettings = getBlockListSettings(rootClientId)) === null || _getBlockListSettings === void 0 ? void 0 : _getBlockListSettings.orientation
};
})(BlockMover);
exports.default = _default;
//# sourceMappingURL=index.js.map