-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathmover-label.js
109 lines (97 loc) · 3.42 KB
/
mover-label.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Wordpress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
/**
* Return a label for the block movement controls depending on block position.
*
* @param {number} selectedCount Number of blocks selected.
* @param {string} type Block type - in the case of a single block, should
* define its 'type'. I.e. 'Text', 'Heading', 'Image' etc.
* @param {number} firstIndex The index (position - 1) of the first block selected.
* @param {boolean} isFirst This is the first block.
* @param {boolean} isLast This is the last block.
* @param {number} dir Direction of movement (> 0 is considered to be going
* down, < 0 is up).
* @return {string} Label for the block movement controls.
*/
export function getBlockMoverLabel( selectedCount, type, firstIndex, isFirst, isLast, dir ) {
const position = ( firstIndex + 1 );
if ( selectedCount > 1 ) {
return getMultiBlockMoverLabel( selectedCount, firstIndex, isFirst, isLast, dir );
}
if ( isFirst && isLast ) {
// translators: %s: Type of block (i.e. Text, Image etc)
return sprintf( __( 'Block "%s" is the only block, and cannot be moved' ), type );
}
if ( dir > 0 && ! isLast ) {
// moving down
return sprintf(
__( 'Move "%(type)s" block from position %(position)d down to position %(newPosition)d' ),
{
type,
position,
newPosition: ( position + 1 ),
}
);
}
if ( dir > 0 && isLast ) {
// moving down, and is the last item
// translators: %s: Type of block (i.e. Text, Image etc)
return sprintf( __( 'Block "%s" is at the end of the content and can’t be moved down' ), type );
}
if ( dir < 0 && ! isFirst ) {
// moving up
return sprintf(
__( 'Move "%(type)s" block from position %(position)d up to position %(newPosition)d' ),
{
type,
position,
newPosition: ( position - 1 ),
}
);
}
if ( dir < 0 && isFirst ) {
// moving up, and is the first item
// translators: %s: Type of block (i.e. Text, Image etc)
return sprintf( __( 'Block "%s" is at the beginning of the content and can’t be moved up' ), type );
}
}
/**
* Return a label for the block movement controls depending on block position.
*
* @param {number} selectedCount Number of blocks selected.
* @param {number} firstIndex The index (position - 1) of the first block selected.
* @param {boolean} isFirst This is the first block.
* @param {boolean} isLast This is the last block.
* @param {number} dir Direction of movement (> 0 is considered to be going
* down, < 0 is up).
* @return {string} Label for the block movement controls.
*/
export function getMultiBlockMoverLabel( selectedCount, firstIndex, isFirst, isLast, dir ) {
const position = ( firstIndex + 1 );
if ( dir < 0 && isFirst ) {
return __( 'Blocks cannot be moved up as they are already at the top' );
}
if ( dir > 0 && isLast ) {
return __( 'Blocks cannot be moved down as they are already at the bottom' );
}
if ( dir < 0 && ! isFirst ) {
return sprintf(
__( 'Move %(selectedCount)d blocks from position %(position)d up by one place' ),
{
selectedCount,
position,
}
);
}
if ( dir > 0 && ! isLast ) {
return sprintf(
__( 'Move %(selectedCount)d blocks from position %(position)s down by one place' ),
{
selectedCount,
position,
}
);
}
}