@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 1.8 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/navigation/edit/use-navigation-notice.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { 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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAoC;AACpC,kBAA4B;AAC5B,qBAAqC;AAErC,SAAS,oBAAqB,EAAE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAI;AAC3D,QAAM,gBAAY,uBAAO;AAEzB,QAAM,EAAE,qBAAqB,aAAa,QAAI,yBAAa,eAAAA,KAAY;AAEvE,QAAM,iBAAa;AAAA,IAClB,CAAE,cAAe;AAChB,UAAK,UAAU,SAAU;AACxB;AAAA,MACD;AAEA,gBAAU,UAAU;AAEpB,0BAAqB,aAAa,SAAS;AAAA,QAC1C,IAAI,UAAU;AAAA,QACd,MAAM;AAAA,MACP,CAAE;AAAA,IACH;AAAA,IACA,CAAE,WAAW,qBAAqB,SAAS,IAAK;AAAA,EACjD;AAEA,QAAM,iBAAa,4BAAa,MAAM;AACrC,QAAK,CAAE,UAAU,SAAU;AAC1B;AAAA,IACD;AACA,iBAAc,UAAU,OAAQ;AAChC,cAAU,UAAU;AAAA,EACrB,GAAG,CAAE,WAAW,YAAa,CAAE;AAE/B,SAAO,CAAE,YAAY,UAAW;AACjC;AAEA,IAAO,gCAAQ;",
"names": ["noticeStore"]
}