@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 1.68 kB
Source Map (JSON)
{"version":3,"file":"use-navigation-notice.cjs","names":["useRef","useDispatch","noticeStore","useCallback"],"sources":["../../../src/navigation/edit/use-navigation-notice.js"],"sourcesContent":["import { useCallback, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticeStore } from '@wordpress/notices';\n\nfunction useNavigationNotice( { name, message = '' } = {} ) {\n\tconst noticeRef = useRef();\n\n\tconst { createWarningNotice, removeNotice } = useDispatch( noticeStore );\n\n\tconst showNotice = useCallback(\n\t\t( customMsg ) => {\n\t\t\tif ( noticeRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tnoticeRef.current = name;\n\n\t\t\tcreateWarningNotice( customMsg || message, {\n\t\t\t\tid: noticeRef.current,\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t},\n\t\t[ noticeRef, createWarningNotice, message, name ]\n\t);\n\n\tconst hideNotice = useCallback( () => {\n\t\tif ( ! noticeRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tremoveNotice( noticeRef.current );\n\t\tnoticeRef.current = null;\n\t}, [ noticeRef, removeNotice ] );\n\n\treturn [ showNotice, hideNotice ];\n}\n\nexport default useNavigationNotice;\n"],"mappings":";;;;;;;;;AAIA,SAAS,oBAAqB,EAAE,MAAM,UAAU,OAAO,CAAC,GAAI;CAC3D,MAAM,aAAA,GAAYA,mBAAAA,OAAAA,CAAO;CAEzB,MAAM,EAAE,qBAAqB,kBAAA,GAAiBC,gBAAAA,YAAAA,CAAaC,mBAAAA,KAAY;CA0BvE,OAAO,EAAA,GAxBYC,mBAAAA,YAAAA,EAChB,cAAe;EAChB,IAAK,UAAU,SACd;EAGD,UAAU,UAAU;EAEpB,oBAAqB,aAAa,SAAS;GAC1C,IAAI,UAAU;GACd,MAAM;EACP,CAAE;CACH,GACA;EAAE;EAAW;EAAqB;EAAS;CAAK,CAW/B,IAAA,GARCA,mBAAAA,YAAAA,OAAmB;EACrC,IAAK,CAAE,UAAU,SAChB;EAED,aAAc,UAAU,OAAQ;EAChC,UAAU,UAAU;CACrB,GAAG,CAAE,WAAW,YAAa,CAEC,CAAE;AACjC"}