UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 3.49 kB
{ "version": 3, "sources": ["../../src/hooks/content-lock-ui.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { ToolbarButton } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { BlockControls } from '../components';\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\nfunction ContentLockControlsPure( { clientId } ) {\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\n\tconst { stopEditingContentOnlySection } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tconst isContentLocked =\n\t\t! isLockedByParent && templateLock === 'contentOnly';\n\n\tconst stopEditingAsBlockCallback = useCallback( () => {\n\t\tstopEditingContentOnlySection();\n\t}, [ stopEditingContentOnlySection ] );\n\n\t// Hide the Done 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\treturn (\n\t\tisEditingContentOnlySection && (\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<ToolbarButton onClick={ stopEditingAsBlockCallback }>\n\t\t\t\t\t{ __( 'Done' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</BlockControls>\n\t\t)\n\t);\n}\n\nexport default {\n\tedit: ContentLockControlsPure,\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"], "mappings": ";AAGA,SAAS,qBAAqB;AAC9B,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAK5B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AAiDnB;AAzCJ,SAAS,wBAAyB,EAAE,SAAS,GAAI;AAChD,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;AAED,QAAM,EAAE,8BAA8B,IAAI;AAAA,IACzC,YAAa,gBAAiB;AAAA,EAC/B;AACA,QAAM,kBACL,CAAE,oBAAoB,iBAAiB;AAExC,QAAM,6BAA6B,YAAa,MAAM;AACrD,kCAA8B;AAAA,EAC/B,GAAG,CAAE,6BAA8B,CAAE;AAIrC,MACC,QAAQ,6CACN,CAAE,mBAAmB,CAAE,6BACxB;AACD,WAAO;AAAA,EACR;AAEA,SACC,+BACC,oBAAC,iBAAc,OAAM,SACpB,8BAAC,iBAAc,SAAU,4BACtB,aAAI,MAAO,GACd,GACD;AAGH;AAEA,IAAO,0BAAQ;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AACZ,WAAO;AAAA,EACR;AACD;", "names": [] }