@wordpress/edit-post
Version:
Edit Post module for WordPress.
8 lines (7 loc) • 3.85 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../../src/components/meta-boxes/meta-boxes-area/index.jsx"],
"sourcesContent": ["import clsx from 'clsx';\nimport { useRef, useLayoutEffect } from '@wordpress/element';\nimport { Spinner } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { store as editPostStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nconst { useNativeUndo } = unlock( blockEditorPrivateApis );\n\n/**\n * Moves `node` to the end of `parent`.\n *\n * `moveBefore` keeps the subtree's state, where `appendChild` reloads any\n * iframe in it. That reload breaks a classic editor rendered by a meta box.\n * `moveBefore` only works between connected nodes.\n *\n * @param {Element} parent Element to move into.\n * @param {Element} node Element to move.\n */\nfunction move( parent, node ) {\n\tif ( parent.moveBefore && parent.isConnected && node.isConnected ) {\n\t\tparent.moveBefore( node, null );\n\t} else {\n\t\tparent.appendChild( node );\n\t}\n}\n\n/**\n * Render metabox area.\n *\n * @param {Object} props Component props.\n * @param {string} props.location metabox location.\n * @return {Component} The component to be rendered.\n */\nfunction MetaBoxesArea( { location } ) {\n\tconst container = useRef( null );\n\tconst formRef = useRef( null );\n\n\t// A layout effect because the cleanup has to run before React detaches the\n\t// meta boxes: `moveBefore` needs them connected.\n\tuseLayoutEffect( () => {\n\t\tformRef.current = document.querySelector(\n\t\t\t'.metabox-location-' + location\n\t\t);\n\n\t\tif ( formRef.current ) {\n\t\t\tmove( container.current, formRef.current );\n\t\t}\n\n\t\treturn () => {\n\t\t\tif ( formRef.current ) {\n\t\t\t\tmove( document.querySelector( '#metaboxes' ), formRef.current );\n\t\t\t}\n\t\t};\n\t}, [ location ] );\n\n\tconst isSaving = useSelect( ( select ) => {\n\t\treturn select( editPostStore ).isSavingMetaBoxes();\n\t}, [] );\n\n\tconst classes = clsx( 'edit-post-meta-boxes-area', `is-${ location }`, {\n\t\t'is-loading': isSaving,\n\t} );\n\n\t// Meta box fields are not part of the editor history, so undo and redo\n\t// within them must remain the browser's own.\n\tconst nativeUndoRef = useNativeUndo();\n\n\treturn (\n\t\t<div className={ classes } ref={ nativeUndoRef }>\n\t\t\t{ isSaving && (\n\t\t\t\t<Spinner className=\"edit-post-meta-boxes-area__spinner\" />\n\t\t\t) }\n\t\t\t<div\n\t\t\t\tclassName=\"edit-post-meta-boxes-area__container\"\n\t\t\t\tref={ container }\n\t\t\t/>\n\t\t\t<div className=\"edit-post-meta-boxes-area__clear\" />\n\t\t</div>\n\t);\n}\n\nexport default MetaBoxesArea;\n"],
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,QAAQ,uBAAuB;AACxC,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,eAAe,8BAA8B;AACtD,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AAgErB,SAEE,KAFF;AA9DF,IAAM,EAAE,cAAc,IAAI,OAAQ,sBAAuB;AAYzD,SAAS,KAAM,QAAQ,MAAO;AAC7B,MAAK,OAAO,cAAc,OAAO,eAAe,KAAK,aAAc;AAClE,WAAO,WAAY,MAAM,IAAK;AAAA,EAC/B,OAAO;AACN,WAAO,YAAa,IAAK;AAAA,EAC1B;AACD;AASA,SAAS,cAAe,EAAE,SAAS,GAAI;AACtC,QAAM,YAAY,OAAQ,IAAK;AAC/B,QAAM,UAAU,OAAQ,IAAK;AAI7B,kBAAiB,MAAM;AACtB,YAAQ,UAAU,SAAS;AAAA,MAC1B,uBAAuB;AAAA,IACxB;AAEA,QAAK,QAAQ,SAAU;AACtB,WAAM,UAAU,SAAS,QAAQ,OAAQ;AAAA,IAC1C;AAEA,WAAO,MAAM;AACZ,UAAK,QAAQ,SAAU;AACtB,aAAM,SAAS,cAAe,YAAa,GAAG,QAAQ,OAAQ;AAAA,MAC/D;AAAA,IACD;AAAA,EACD,GAAG,CAAE,QAAS,CAAE;AAEhB,QAAM,WAAW,UAA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