UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 3.28 kB
{ "version": 3, "sources": ["../../../src/components/content-lock/modify-content-lock-menu-item.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n// The implementation of content locking is mainly in this file, although the mechanism\n// to stop editing a content only section when an outside block is selected is in the component\n// `StopEditingContentOnlySectionOnOutsideSelect` at block-editor/src/components/block-list/index.js.\n// Besides the components on this file and the file referenced above the implementation\n// also includes artifacts on the store (actions, reducers, and selector).\n\nexport function ModifyContentOnlySectionMenuItem( { clientId, onClose } ) {\n\tconst { templateLock, isLockedByParent, isEditingContentOnlySection } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetContentLockingParent,\n\t\t\t\t\tgetTemplateLock,\n\t\t\t\t\tgetEditedContentOnlySection,\n\t\t\t\t} = unlock( select( blockEditorStore ) );\n\t\t\t\treturn {\n\t\t\t\t\ttemplateLock: getTemplateLock( clientId ),\n\t\t\t\t\tisLockedByParent: !! getContentLockingParent( clientId ),\n\t\t\t\t\tisEditingContentOnlySection:\n\t\t\t\t\t\tgetEditedContentOnlySection() === clientId,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ clientId ]\n\t\t);\n\tconst blockEditorActions = useDispatch( blockEditorStore );\n\tconst isContentLocked =\n\t\t! isLockedByParent && templateLock === 'contentOnly';\n\n\t// Hide the Modify button when the content only pattern insertion experiment is active.\n\t// This is replaced by an alternative UI in the experiment.\n\tif (\n\t\twindow?.__experimentalContentOnlyPatternInsertion ||\n\t\t( ! isContentLocked && ! isEditingContentOnlySection )\n\t) {\n\t\treturn null;\n\t}\n\n\tconst { editContentOnlySection } = unlock( blockEditorActions );\n\tconst showContentOnlyModifyButton =\n\t\t! isEditingContentOnlySection && isContentLocked;\n\n\treturn (\n\t\tshowContentOnlyModifyButton && (\n\t\t\t<MenuItem\n\t\t\t\tonClick={ () => {\n\t\t\t\t\teditContentOnlySection( clientId );\n\t\t\t\t\tonClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ _x( 'Modify', 'Unlock content locked blocks' ) }\n\t\t\t</MenuItem>\n\t\t)\n\t);\n}\n"], "mappings": ";AAGA,SAAS,gBAAgB;AACzB,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AAKnB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AA6CpB;AArCI,SAAS,iCAAkC,EAAE,UAAU,QAAQ,GAAI;AACzE,QAAM,EAAE,cAAc,kBAAkB,4BAA4B,IACnE;AAAA,IACC,CAAE,WAAY;AACb,YAAM;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD,IAAI,OAAQ,OAAQ,gBAAiB,CAAE;AACvC,aAAO;AAAA,QACN,cAAc,gBAAiB,QAAS;AAAA,QACxC,kBAAkB,CAAC,CAAE,wBAAyB,QAAS;AAAA,QACvD,6BACC,4BAA4B,MAAM;AAAA,MACpC;AAAA,IACD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AACD,QAAM,qBAAqB,YAAa,gBAAiB;AACzD,QAAM,kBACL,CAAE,oBAAoB,iBAAiB;AAIxC,MACC,QAAQ,6CACN,CAAE,mBAAmB,CAAE,6BACxB;AACD,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,uBAAuB,IAAI,OAAQ,kBAAmB;AAC9D,QAAM,8BACL,CAAE,+BAA+B;AAElC,SACC,+BACC;AAAA,IAAC;AAAA;AAAA,MACA,SAAU,MAAM;AACf,+BAAwB,QAAS;AACjC,gBAAQ;AAAA,MACT;AAAA,MAEE,aAAI,UAAU,8BAA+B;AAAA;AAAA,EAChD;AAGH;", "names": [] }