{
  "version": 3,
  "sources": ["../../../src/list-item/hooks/use-indent-list-item.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { createBlock, cloneBlock } from '@wordpress/blocks';\n\nexport default function useIndentListItem( clientId ) {\n\tconst { replaceBlocks, selectionChange, multiSelect } =\n\t\tuseDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlock,\n\t\tgetPreviousBlockClientId,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\thasMultiSelection,\n\t\tgetMultiSelectedBlockClientIds,\n\t} = useSelect( blockEditorStore );\n\treturn useCallback( () => {\n\t\tconst _hasMultiSelection = hasMultiSelection();\n\t\tconst clientIds = _hasMultiSelection\n\t\t\t? getMultiSelectedBlockClientIds()\n\t\t\t: [ clientId ];\n\t\tconst clonedBlocks = clientIds.map( ( _clientId ) =>\n\t\t\tcloneBlock( getBlock( _clientId ) )\n\t\t);\n\t\tconst previousSiblingId = getPreviousBlockClientId( clientId );\n\t\tconst newListItem = cloneBlock( getBlock( previousSiblingId ) );\n\t\t// If the sibling has no innerBlocks, create a new `list` block.\n\t\tif ( ! newListItem.innerBlocks?.length ) {\n\t\t\tnewListItem.innerBlocks = [ createBlock( 'core/list' ) ];\n\t\t}\n\t\t// A list item usually has one `list`, but it's possible to have\n\t\t// more. So we need to preserve the previous `list` blocks and\n\t\t// merge the new blocks to the last `list`.\n\t\tnewListItem.innerBlocks[\n\t\t\tnewListItem.innerBlocks.length - 1\n\t\t].innerBlocks.push( ...clonedBlocks );\n\n\t\t// We get the selection start/end here, because when\n\t\t// we replace blocks, the selection is updated too.\n\t\tconst selectionStart = getSelectionStart();\n\t\tconst selectionEnd = getSelectionEnd();\n\t\t// Replace the previous sibling of the block being indented and the indented blocks,\n\t\t// with a new block whose attributes are equal to the ones of the previous sibling and\n\t\t// whose descendants are the children of the previous sibling, followed by the indented blocks.\n\t\treplaceBlocks( [ previousSiblingId, ...clientIds ], [ newListItem ] );\n\t\tif ( ! _hasMultiSelection ) {\n\t\t\tselectionChange(\n\t\t\t\tclonedBlocks[ 0 ].clientId,\n\t\t\t\tselectionEnd.attributeKey,\n\t\t\t\tselectionEnd.clientId === selectionStart.clientId\n\t\t\t\t\t? selectionStart.offset\n\t\t\t\t\t: selectionEnd.offset,\n\t\t\t\tselectionEnd.offset\n\t\t\t);\n\t\t} else {\n\t\t\tmultiSelect(\n\t\t\t\tclonedBlocks[ 0 ].clientId,\n\t\t\t\tclonedBlocks[ clonedBlocks.length - 1 ].clientId\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t}, [ clientId ] );\n}\n"],
  "mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,aAAa,kBAAkB;AAEzB,SAAR,kBAAoC,UAAW;AACrD,QAAM,EAAE,eAAe,iBAAiB,YAAY,IACnD,YAAa,gBAAiB;AAC/B,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,UAAW,gBAAiB;AAChC,SAAO,YAAa,MAAM;AACzB,UAAM,qBAAqB,kBAAkB;AAC7C,UAAM,YAAY,qBACf,+BAA+B,IAC/B,CAAE,QAAS;AACd,UAAM,eAAe,UAAU;AAAA,MAAK,CAAE,cACrC,WAAY,SAAU,SAAU,CAAE;AAAA,IACnC;AACA,UAAM,oBAAoB,yBAA0B,QAAS;AAC7D,UAAM,cAAc,WAAY,SAAU,iBAAkB,CAAE;AAE9D,QAAK,CAAE,YAAY,aAAa,QAAS;AACxC,kBAAY,cAAc,CAAE,YAAa,WAAY,CAAE;AAAA,IACxD;AAIA,gBAAY,YACX,YAAY,YAAY,SAAS,CAClC,EAAE,YAAY,KAAM,GAAG,YAAa;AAIpC,UAAM,iBAAiB,kBAAkB;AACz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