@wordpress/block-editor
Version:
8 lines (7 loc) • 2.13 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/use-list-view-panel-state/index.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Custom hook for managing List View panel state.\n *\n * Returns the panel's open/closed state and a counter (expandRevision) used to force\n * ListView remounting. The expandRevision is included in the ListView component's key\n * prop. When it changes, the component will remount with fresh isExpanded=true state.\n *\n * @param {string} clientId Block client ID.\n * @return {Object} Panel state and handlers with isOpened (boolean), expandRevision (number), and handleToggle (function).\n */\nexport default function useListViewPanelState( clientId ) {\n\tconst { isOpened, expandRevision } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isListViewPanelOpened, getListViewExpandRevision } = unlock(\n\t\t\t\tselect( blockEditorStore )\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tisOpened: isListViewPanelOpened( clientId ),\n\t\t\t\texpandRevision: getListViewExpandRevision(),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __unstableToggleListViewPanel: toggleListViewPanel } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst handleToggle = ( opened ) => {\n\t\ttoggleListViewPanel( clientId, opened );\n\t};\n\n\treturn {\n\t\tisOpened,\n\t\texpandRevision,\n\t\thandleToggle,\n\t};\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuC;AAKvC,mBAA0C;AAC1C,yBAAuB;AAYR,SAAR,sBAAwC,UAAW;AACzD,QAAM,EAAE,UAAU,eAAe,QAAI;AAAA,IACpC,CAAE,WAAY;AACb,YAAM,EAAE,uBAAuB,0BAA0B,QAAI;AAAA,QAC5D,OAAQ,aAAAA,KAAiB;AAAA,MAC1B;AACA,aAAO;AAAA,QACN,UAAU,sBAAuB,QAAS;AAAA,QAC1C,gBAAgB,0BAA0B;AAAA,MAC3C;AAAA,IACD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,QAAM,EAAE,+BAA+B,oBAAoB,QAC1D,yBAAa,aAAAA,KAAiB;AAE/B,QAAM,eAAe,CAAE,WAAY;AAClC,wBAAqB,UAAU,MAAO;AAAA,EACvC;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
"names": ["blockEditorStore"]
}