@wordpress/edit-post
Version:
Edit Post module for WordPress.
8 lines (7 loc) • 2.34 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/meta-boxes/use-meta-box-initialization.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Initializes WordPress `postboxes` script and the logic for saving meta boxes.\n *\n * @param { boolean } enabled\n */\nexport const useMetaBoxInitialization = ( enabled ) => {\n\tconst { isEnabledAndEditorReady, isCollaborationEnabled } = useSelect(\n\t\t( select ) => ( {\n\t\t\tisEnabledAndEditorReady:\n\t\t\t\tenabled && select( editorStore ).__unstableIsEditorReady(),\n\t\t\tisCollaborationEnabled:\n\t\t\t\tselect( editorStore ).isCollaborationEnabledForCurrentPost(),\n\t\t} ),\n\t\t[ enabled ]\n\t);\n\tconst { setCollaborationSupported } = unlock( useDispatch( coreStore ) );\n\n\tconst { initializeMetaBoxes } = useDispatch( editPostStore );\n\t// The effect has to rerun when the editor is ready because initializeMetaBoxes\n\t// will noop until then.\n\tuseEffect( () => {\n\t\tif ( isEnabledAndEditorReady ) {\n\t\t\tinitializeMetaBoxes();\n\n\t\t\t// Disable real-time collaboration when legacy meta boxes are detected.\n\t\t\tif ( isCollaborationEnabled ) {\n\t\t\t\tsetCollaborationSupported( false );\n\t\t\t}\n\t\t}\n\t}, [\n\t\tisEnabledAndEditorReady,\n\t\tinitializeMetaBoxes,\n\t\tisCollaborationEnabled,\n\t\tsetCollaborationSupported,\n\t] );\n};\n"],
"mappings": ";AAGA,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,mBAAmB;AACrC,SAAS,SAAS,iBAAiB;AACnC,SAAS,iBAAiB;AAK1B,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AAOhB,IAAM,2BAA2B,CAAE,YAAa;AACtD,QAAM,EAAE,yBAAyB,uBAAuB,IAAI;AAAA,IAC3D,CAAE,YAAc;AAAA,MACf,yBACC,WAAW,OAAQ,WAAY,EAAE,wBAAwB;AAAA,MAC1D,wBACC,OAAQ,WAAY,EAAE,qCAAqC;AAAA,IAC7D;AAAA,IACA,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,EAAE,0BAA0B,IAAI,OAAQ,YAAa,SAAU,CAAE;AAEvE,QAAM,EAAE,oBAAoB,IAAI,YAAa,aAAc;AAG3D,YAAW,MAAM;AAChB,QAAK,yBAA0B;AAC9B,0BAAoB;AAGpB,UAAK,wBAAyB;AAC7B,kCAA2B,KAAM;AAAA,MAClC;AAAA,IACD;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACH;",
"names": []
}