{"version":3,"file":"use-multi-select-tab.mjs","names":["blockEditorStore"],"sources":["../../../src/list-item/hooks/use-multi-select-tab.js"],"sourcesContent":["import { useRefEffect } from '@wordpress/compose';\nimport { TAB } from '@wordpress/keycodes';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useSelect, useRegistry } from '@wordpress/data';\nimport { indentListItems, outdentListItems } from '../utils';\n\nexport default function useMultiSelectTab( clientId ) {\n\tconst registry = useRegistry();\n\t// Only the first item of an all-list-item multi selection attaches the\n\t// listener, so there is a single handler regardless of how many list items\n\t// are rendered, and only while such a selection exists.\n\tconst isActive = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\thasMultiSelection,\n\t\t\t\tgetMultiSelectedBlockClientIds,\n\t\t\t\tgetBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst clientIds = getMultiSelectedBlockClientIds();\n\t\t\treturn (\n\t\t\t\tclientIds[ 0 ] === clientId &&\n\t\t\t\tclientIds.every(\n\t\t\t\t\t( id ) => getBlockName( id ) === 'core/list-item'\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\treturn useRefEffect(\n\t\t( element ) => {\n\t\t\tif ( ! isActive ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfunction onKeyDown( event ) {\n\t\t\t\tconst { keyCode, shiftKey, altKey, metaKey, ctrlKey } = event;\n\n\t\t\t\tif (\n\t\t\t\t\tkeyCode !== TAB ||\n\t\t\t\t\tevent.defaultPrevented ||\n\t\t\t\t\taltKey ||\n\t\t\t\t\tmetaKey ||\n\t\t\t\t\tctrlKey\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// The listener is on the document, so it also sees a Tab from\n\t\t\t\t// other editor UI while the multi selection lingers (moving\n\t\t\t\t// focus does not clear it). A multi selection keeps focus on the\n\t\t\t\t// canvas host that wraps the blocks, so only act when the key\n\t\t\t\t// comes from an ancestor of them, not from a toolbar or panel.\n\t\t\t\tif ( ! event.target.contains( element ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\tif ( outdentListItems( registry ) ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t} else if ( indentListItems( registry ) ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// During a multi selection focus sits on the writing flow\n\t\t\t// container, not inside any item, so an element listener never sees\n\t\t\t// the key. Listen on the document. Capture phase so we run before\n\t\t\t// writing-flow's keydown handlers, which gate on\n\t\t\t// `event.defaultPrevented`.\n\t\t\tconst { ownerDocument } = element;\n\t\t\townerDocument.addEventListener( 'keydown', onKeyDown, true );\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener( 'keydown', onKeyDown, true );\n\t\t\t};\n\t\t},\n\t\t[ isActive, registry ]\n\t);\n}\n"],"mappings":";;;;;;AAMA,SAAwB,kBAAmB,UAAW;CACrD,MAAM,WAAW,YAAY;CAI7B,MAAM,WAAW,WACd,WAAY;EACb,MAAM,EACL,mBACA,gCACA,iBACG,OAAQA,KAAiB;EAC7B,IAAK,CAAE,kBAAkB,GACxB,OAAO;EAER,MAAM,YAAY,+BAA+B;EACjD,OACC,UAAW,OAAQ,YACnB,UAAU,OACP,OAAQ,aAAc,EAAG,MAAM,gBAClC;CAEF,GACA,CAAE,QAAS,CACZ;CAEA,OAAO,cACJ,YAAa;EACd,IAAK,CAAE,UACN;EAGD,SAAS,UAAW,OAAQ;GAC3B,MAAM,EAAE,SAAS,UAAU,QAAQ,SAAS,YAAY;GAExD,IACC,YAAY,OACZ,MAAM,oBACN,UACA,WACA,SAEA;GAQD,IAAK,CAAE,MAAM,OAAO,SAAU,OAAQ,GACrC;GAGD,IAAK,UACC;QAAA,iBAAkB,QAAS,GAC/B,MAAM,eAAe;GAAA,OAEhB,IAAK,gBAAiB,QAAS,GACrC,MAAM,eAAe;EAEvB;EAOA,MAAM,EAAE,kBAAkB;EAC1B,cAAc,iBAAkB,WAAW,WAAW,IAAK;EAC3D,aAAa;GACZ,cAAc,oBAAqB,WAAW,WAAW,IAAK;EAC/D;CACD,GACA,CAAE,UAAU,QAAS,CACtB;AACD"}