@wordpress/block-editor
Version:
8 lines (7 loc) • 14.4 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/block-mover/mover-description.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf, isRTL } from '@wordpress/i18n';\n\nconst getMovementDirection = ( moveDirection, orientation ) => {\n\tif ( moveDirection === 'up' ) {\n\t\tif ( orientation === 'horizontal' ) {\n\t\t\treturn isRTL() ? 'right' : 'left';\n\t\t}\n\t\treturn 'up';\n\t} else if ( moveDirection === 'down' ) {\n\t\tif ( orientation === 'horizontal' ) {\n\t\t\treturn isRTL() ? 'left' : 'right';\n\t\t}\n\t\treturn 'down';\n\t}\n\treturn null;\n};\n\n/**\n * Return a label for the block movement controls depending on block position.\n *\n * @param {number} selectedCount Number of blocks selected.\n * @param {string} type Block type - in the case of a single block, should\n * define its 'type'. I.e. 'Text', 'Heading', 'Image' etc.\n * @param {number} firstIndex The index (position - 1) of the first block selected.\n * @param {boolean} isFirst This is the first block.\n * @param {boolean} isLast This is the last block.\n * @param {number} dir Direction of movement (> 0 is considered to be going\n * down, < 0 is up).\n * @param {string} orientation The orientation of the block movers, vertical or\n * horizontal.\n *\n * @return {string | undefined} Label for the block movement controls.\n */\nexport function getBlockMoverDescription(\n\tselectedCount,\n\ttype,\n\tfirstIndex,\n\tisFirst,\n\tisLast,\n\tdir,\n\torientation\n) {\n\tconst position = firstIndex + 1;\n\n\tif ( selectedCount > 1 ) {\n\t\treturn getMultiBlockMoverDescription(\n\t\t\tselectedCount,\n\t\t\tfirstIndex,\n\t\t\tisFirst,\n\t\t\tisLast,\n\t\t\tdir,\n\t\t\torientation\n\t\t);\n\t}\n\n\tif ( isFirst && isLast ) {\n\t\treturn sprintf(\n\t\t\t// translators: %s: Type of block (i.e. Text, Image etc)\n\t\t\t__( 'Block %s is the only block, and cannot be moved' ),\n\t\t\ttype\n\t\t);\n\t}\n\n\tif ( dir > 0 && ! isLast ) {\n\t\t// Moving down.\n\t\tconst movementDirection = getMovementDirection( 'down', orientation );\n\n\t\tif ( movementDirection === 'down' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position\n\t\t\t\t__(\n\t\t\t\t\t'Move %1$s block from position %2$d down to position %3$d'\n\t\t\t\t),\n\t\t\t\ttype,\n\t\t\t\tposition,\n\t\t\t\tposition + 1\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position\n\t\t\t\t__(\n\t\t\t\t\t'Move %1$s block from position %2$d left to position %3$d'\n\t\t\t\t),\n\t\t\t\ttype,\n\t\t\t\tposition,\n\t\t\t\tposition + 1\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position\n\t\t\t\t__(\n\t\t\t\t\t'Move %1$s block from position %2$d right to position %3$d'\n\t\t\t\t),\n\t\t\t\ttype,\n\t\t\t\tposition,\n\t\t\t\tposition + 1\n\t\t\t);\n\t\t}\n\t}\n\n\tif ( dir > 0 && isLast ) {\n\t\t// Moving down, and is the last item.\n\t\tconst movementDirection = getMovementDirection( 'down', orientation );\n\n\t\tif ( movementDirection === 'down' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc)\n\t\t\t\t__(\n\t\t\t\t\t'Block %1$s is at the end of the content and can\u2019t be moved down'\n\t\t\t\t),\n\t\t\t\ttype\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc)\n\t\t\t\t__(\n\t\t\t\t\t'Block %1$s is at the end of the content and can\u2019t be moved left'\n\t\t\t\t),\n\t\t\t\ttype\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc)\n\t\t\t\t__(\n\t\t\t\t\t'Block %1$s is at the end of the content and can\u2019t be moved right'\n\t\t\t\t),\n\t\t\t\ttype\n\t\t\t);\n\t\t}\n\t}\n\n\tif ( dir < 0 && ! isFirst ) {\n\t\t// Moving up.\n\t\tconst movementDirection = getMovementDirection( 'up', orientation );\n\n\t\tif ( movementDirection === 'up' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position\n\t\t\t\t__( 'Move %1$s block from position %2$d up to position %3$d' ),\n\t\t\t\ttype,\n\t\t\t\tposition,\n\t\t\t\tposition - 1\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position\n\t\t\t\t__(\n\t\t\t\t\t'Move %1$s block from position %2$d left to position %3$d'\n\t\t\t\t),\n\t\t\t\ttype,\n\t\t\t\tposition,\n\t\t\t\tposition - 1\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc), 2: Position of selected block, 3: New position\n\t\t\t\t__(\n\t\t\t\t\t'Move %1$s block from position %2$d right to position %3$d'\n\t\t\t\t),\n\t\t\t\ttype,\n\t\t\t\tposition,\n\t\t\t\tposition - 1\n\t\t\t);\n\t\t}\n\t}\n\n\tif ( dir < 0 && isFirst ) {\n\t\t// Moving up, and is the first item.\n\t\tconst movementDirection = getMovementDirection( 'up', orientation );\n\n\t\tif ( movementDirection === 'up' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc)\n\t\t\t\t__(\n\t\t\t\t\t'Block %1$s is at the beginning of the content and can\u2019t be moved up'\n\t\t\t\t),\n\t\t\t\ttype\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc)\n\t\t\t\t__(\n\t\t\t\t\t'Block %1$s is at the beginning of the content and can\u2019t be moved left'\n\t\t\t\t),\n\t\t\t\ttype\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Type of block (i.e. Text, Image etc)\n\t\t\t\t__(\n\t\t\t\t\t'Block %1$s is at the beginning of the content and can\u2019t be moved right'\n\t\t\t\t),\n\t\t\t\ttype\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Return a label for the block movement controls depending on block position.\n *\n * @param {number} selectedCount Number of blocks selected.\n * @param {number} firstIndex The index (position - 1) of the first block selected.\n * @param {boolean} isFirst This is the first block.\n * @param {boolean} isLast This is the last block.\n * @param {number} dir Direction of movement (> 0 is considered to be going\n * down, < 0 is up).\n * @param {string} orientation The orientation of the block movers, vertical or\n * horizontal.\n *\n * @return {string | undefined} Label for the block movement controls.\n */\nexport function getMultiBlockMoverDescription(\n\tselectedCount,\n\tfirstIndex,\n\tisFirst,\n\tisLast,\n\tdir,\n\torientation\n) {\n\tconst position = firstIndex + 1;\n\n\tif ( isFirst && isLast ) {\n\t\t// All blocks are selected\n\t\treturn __( 'All blocks are selected, and cannot be moved' );\n\t}\n\n\tif ( dir > 0 && ! isLast ) {\n\t\t// moving down\n\t\tconst movementDirection = getMovementDirection( 'down', orientation );\n\n\t\tif ( movementDirection === 'down' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Number of selected blocks, 2: Position of selected blocks\n\t\t\t\t__( 'Move %1$d blocks from position %2$d down by one place' ),\n\t\t\t\tselectedCount,\n\t\t\t\tposition\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Number of selected blocks, 2: Position of selected blocks\n\t\t\t\t__( 'Move %1$d blocks from position %2$d left by one place' ),\n\t\t\t\tselectedCount,\n\t\t\t\tposition\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Number of selected blocks, 2: Position of selected blocks\n\t\t\t\t__( 'Move %1$d blocks from position %2$d right by one place' ),\n\t\t\t\tselectedCount,\n\t\t\t\tposition\n\t\t\t);\n\t\t}\n\t}\n\n\tif ( dir > 0 && isLast ) {\n\t\t// moving down, and the selected blocks are the last item\n\t\tconst movementDirection = getMovementDirection( 'down', orientation );\n\n\t\tif ( movementDirection === 'down' ) {\n\t\t\treturn __(\n\t\t\t\t'Blocks cannot be moved down as they are already at the bottom'\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn __(\n\t\t\t\t'Blocks cannot be moved left as they are already are at the leftmost position'\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn __(\n\t\t\t\t'Blocks cannot be moved right as they are already are at the rightmost position'\n\t\t\t);\n\t\t}\n\t}\n\n\tif ( dir < 0 && ! isFirst ) {\n\t\t// moving up\n\t\tconst movementDirection = getMovementDirection( 'up', orientation );\n\n\t\tif ( movementDirection === 'up' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Number of selected blocks, 2: Position of selected blocks\n\t\t\t\t__( 'Move %1$d blocks from position %2$d up by one place' ),\n\t\t\t\tselectedCount,\n\t\t\t\tposition\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Number of selected blocks, 2: Position of selected blocks\n\t\t\t\t__( 'Move %1$d blocks from position %2$d left by one place' ),\n\t\t\t\tselectedCount,\n\t\t\t\tposition\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn sprintf(\n\t\t\t\t// translators: 1: Number of selected blocks, 2: Position of selected blocks\n\t\t\t\t__( 'Move %1$d blocks from position %2$d right by one place' ),\n\t\t\t\tselectedCount,\n\t\t\t\tposition\n\t\t\t);\n\t\t}\n\t}\n\n\tif ( dir < 0 && isFirst ) {\n\t\t// moving up, and the selected blocks are the first item\n\t\tconst movementDirection = getMovementDirection( 'up', orientation );\n\n\t\tif ( movementDirection === 'up' ) {\n\t\t\treturn __(\n\t\t\t\t'Blocks cannot be moved up as they are already at the top'\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'left' ) {\n\t\t\treturn __(\n\t\t\t\t'Blocks cannot be moved left as they are already are at the leftmost position'\n\t\t\t);\n\t\t}\n\n\t\tif ( movementDirection === 'right' ) {\n\t\t\treturn __(\n\t\t\t\t'Blocks cannot be moved right as they are already are at the rightmost position'\n\t\t\t);\n\t\t}\n\t}\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmC;AAEnC,IAAM,uBAAuB,CAAE,eAAe,gBAAiB;AAC9D,MAAK,kBAAkB,MAAO;AAC7B,QAAK,gBAAgB,cAAe;AACnC,iBAAO,mBAAM,IAAI,UAAU;AAAA,IAC5B;AACA,WAAO;AAAA,EACR,WAAY,kBAAkB,QAAS;AACtC,QAAK,gBAAgB,cAAe;AACnC,iBAAO,mBAAM,IAAI,SAAS;AAAA,IAC3B;AACA,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAkBO,SAAS,yBACf,eACA,MACA,YACA,SACA,QACA,KACA,aACC;AACD,QAAM,WAAW,aAAa;AAE9B,MAAK,gBAAgB,GAAI;AACxB,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,MAAK,WAAW,QAAS;AACxB,eAAO;AAAA;AAAA,UAEN,gBAAI,iDAAkD;AAAA,MACtD;AAAA,IACD;AAAA,EACD;AAE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