@wordpress/block-editor
Version:
268 lines (267 loc) • 8.29 kB
JavaScript
// packages/block-editor/src/components/block-mover/mover-description.js
import { __, sprintf, isRTL } from "@wordpress/i18n";
var getMovementDirection = (moveDirection, orientation) => {
if (moveDirection === "up") {
if (orientation === "horizontal") {
return isRTL() ? "right" : "left";
}
return "up";
} else if (moveDirection === "down") {
if (orientation === "horizontal") {
return isRTL() ? "left" : "right";
}
return "down";
}
return null;
};
function getBlockMoverDescription(selectedCount, type, firstIndex, isFirst, isLast, dir, orientation) {
const position = firstIndex + 1;
if (selectedCount > 1) {
return getMultiBlockMoverDescription(
selectedCount,
firstIndex,
isFirst,
isLast,
dir,
orientation
);
}
if (isFirst && isLast) {
return sprintf(
// translators: %s: Type of block (i.e. Text, Image etc)
__("Block %s is the only block, and cannot be moved"),
type
);
}
if (dir > 0 && !isLast) {
const movementDirection = getMovementDirection("down", orientation);
if (movementDirection === "down") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position
__(
"Move %1$s block from position %2$d down to position %3$d"
),
type,
position,
position + 1
);
}
if (movementDirection === "left") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position
__(
"Move %1$s block from position %2$d left to position %3$d"
),
type,
position,
position + 1
);
}
if (movementDirection === "right") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position
__(
"Move %1$s block from position %2$d right to position %3$d"
),
type,
position,
position + 1
);
}
}
if (dir > 0 && isLast) {
const movementDirection = getMovementDirection("down", orientation);
if (movementDirection === "down") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc)
__(
"Block %1$s is at the end of the content and can\u2019t be moved down"
),
type
);
}
if (movementDirection === "left") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc)
__(
"Block %1$s is at the end of the content and can\u2019t be moved left"
),
type
);
}
if (movementDirection === "right") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc)
__(
"Block %1$s is at the end of the content and can\u2019t be moved right"
),
type
);
}
}
if (dir < 0 && !isFirst) {
const movementDirection = getMovementDirection("up", orientation);
if (movementDirection === "up") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position
__("Move %1$s block from position %2$d up to position %3$d"),
type,
position,
position - 1
);
}
if (movementDirection === "left") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position
__(
"Move %1$s block from position %2$d left to position %3$d"
),
type,
position,
position - 1
);
}
if (movementDirection === "right") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position
__(
"Move %1$s block from position %2$d right to position %3$d"
),
type,
position,
position - 1
);
}
}
if (dir < 0 && isFirst) {
const movementDirection = getMovementDirection("up", orientation);
if (movementDirection === "up") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc)
__(
"Block %1$s is at the beginning of the content and can\u2019t be moved up"
),
type
);
}
if (movementDirection === "left") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc)
__(
"Block %1$s is at the beginning of the content and can\u2019t be moved left"
),
type
);
}
if (movementDirection === "right") {
return sprintf(
// translators: 1: Type of block (i.e. Text, Image etc)
__(
"Block %1$s is at the beginning of the content and can\u2019t be moved right"
),
type
);
}
}
}
function getMultiBlockMoverDescription(selectedCount, firstIndex, isFirst, isLast, dir, orientation) {
const position = firstIndex + 1;
if (isFirst && isLast) {
return __("All blocks are selected, and cannot be moved");
}
if (dir > 0 && !isLast) {
const movementDirection = getMovementDirection("down", orientation);
if (movementDirection === "down") {
return sprintf(
// translators: 1: Number of selected blocks, 2: Position of selected blocks
__("Move %1$d blocks from position %2$d down by one place"),
selectedCount,
position
);
}
if (movementDirection === "left") {
return sprintf(
// translators: 1: Number of selected blocks, 2: Position of selected blocks
__("Move %1$d blocks from position %2$d left by one place"),
selectedCount,
position
);
}
if (movementDirection === "right") {
return sprintf(
// translators: 1: Number of selected blocks, 2: Position of selected blocks
__("Move %1$d blocks from position %2$d right by one place"),
selectedCount,
position
);
}
}
if (dir > 0 && isLast) {
const movementDirection = getMovementDirection("down", orientation);
if (movementDirection === "down") {
return __(
"Blocks cannot be moved down as they are already at the bottom"
);
}
if (movementDirection === "left") {
return __(
"Blocks cannot be moved left as they are already are at the leftmost position"
);
}
if (movementDirection === "right") {
return __(
"Blocks cannot be moved right as they are already are at the rightmost position"
);
}
}
if (dir < 0 && !isFirst) {
const movementDirection = getMovementDirection("up", orientation);
if (movementDirection === "up") {
return sprintf(
// translators: 1: Number of selected blocks, 2: Position of selected blocks
__("Move %1$d blocks from position %2$d up by one place"),
selectedCount,
position
);
}
if (movementDirection === "left") {
return sprintf(
// translators: 1: Number of selected blocks, 2: Position of selected blocks
__("Move %1$d blocks from position %2$d left by one place"),
selectedCount,
position
);
}
if (movementDirection === "right") {
return sprintf(
// translators: 1: Number of selected blocks, 2: Position of selected blocks
__("Move %1$d blocks from position %2$d right by one place"),
selectedCount,
position
);
}
}
if (dir < 0 && isFirst) {
const movementDirection = getMovementDirection("up", orientation);
if (movementDirection === "up") {
return __(
"Blocks cannot be moved up as they are already at the top"
);
}
if (movementDirection === "left") {
return __(
"Blocks cannot be moved left as they are already are at the leftmost position"
);
}
if (movementDirection === "right") {
return __(
"Blocks cannot be moved right as they are already are at the rightmost position"
);
}
}
}
export {
getBlockMoverDescription,
getMultiBlockMoverDescription
};
//# sourceMappingURL=mover-description.js.map