@wordpress/editor 13.28.3 → 13.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bindings/index.js +2 -2
- package/build/bindings/index.js.map +1 -1
- package/build/bindings/post-meta.js +2 -1
- package/build/bindings/post-meta.js.map +1 -1
- package/build/components/provider/disable-non-page-content-blocks.js +23 -30
- package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build/hooks/index.js +1 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/{pattern-partial-syncing.js → pattern-overrides.js} +13 -9
- package/build/hooks/pattern-overrides.js.map +1 -0
- package/build-module/bindings/index.js +2 -2
- package/build-module/bindings/index.js.map +1 -1
- package/build-module/bindings/post-meta.js +2 -1
- package/build-module/bindings/post-meta.js.map +1 -1
- package/build-module/components/provider/disable-non-page-content-blocks.js +24 -31
- package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build-module/hooks/index.js +1 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/{pattern-partial-syncing.js → pattern-overrides.js} +13 -9
- package/build-module/hooks/pattern-overrides.js.map +1 -0
- package/build-style/style-rtl.css +1 -0
- package/build-style/style.css +1 -0
- package/package.json +13 -13
- package/src/bindings/index.js +2 -2
- package/src/bindings/post-meta.js +4 -1
- package/src/components/provider/disable-non-page-content-blocks.js +34 -36
- package/src/components/provider/test/disable-non-page-content-blocks.js +90 -0
- package/src/hooks/index.js +1 -1
- package/src/hooks/{pattern-partial-syncing.js → pattern-overrides.js} +16 -10
- package/build/components/provider/constants.js +0 -8
- package/build/components/provider/constants.js.map +0 -1
- package/build/hooks/pattern-partial-syncing.js.map +0 -1
- package/build-module/components/provider/constants.js +0 -2
- package/build-module/components/provider/constants.js.map +0 -1
- package/build-module/hooks/pattern-partial-syncing.js.map +0 -1
- package/src/components/provider/constants.js +0 -5
package/build/bindings/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var
|
|
4
|
+
var _blocks = require("@wordpress/blocks");
|
|
5
5
|
var _data = require("@wordpress/data");
|
|
6
6
|
var _lockUnlock = require("../lock-unlock");
|
|
7
7
|
var _patternOverrides = _interopRequireDefault(require("./pattern-overrides"));
|
|
@@ -16,7 +16,7 @@ var _postMeta = _interopRequireDefault(require("./post-meta"));
|
|
|
16
16
|
|
|
17
17
|
const {
|
|
18
18
|
registerBlockBindingsSource
|
|
19
|
-
} = (0, _lockUnlock.unlock)((0, _data.dispatch)(
|
|
19
|
+
} = (0, _lockUnlock.unlock)((0, _data.dispatch)(_blocks.store));
|
|
20
20
|
registerBlockBindingsSource(_patternOverrides.default);
|
|
21
21
|
registerBlockBindingsSource(_postMeta.default);
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_blocks","require","_data","_lockUnlock","_patternOverrides","_interopRequireDefault","_postMeta","registerBlockBindingsSource","unlock","dispatch","blocksStore","patternOverrides","postMeta"],"sources":["@wordpress/editor/src/bindings/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { dispatch } from '@wordpress/data';\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport patternOverrides from './pattern-overrides';\nimport postMeta from './post-meta';\n\nconst { registerBlockBindingsSource } = unlock( dispatch( blocksStore ) );\nregisterBlockBindingsSource( patternOverrides );\nregisterBlockBindingsSource( postMeta );\n"],"mappings":";;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAIA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAD,sBAAA,CAAAJ,OAAA;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAKA,MAAM;EAAEM;AAA4B,CAAC,GAAG,IAAAC,kBAAM,EAAE,IAAAC,cAAQ,EAAEC,aAAY,CAAE,CAAC;AACzEH,2BAA2B,CAAEI,yBAAiB,CAAC;AAC/CJ,2BAA2B,CAAEK,iBAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_data","_i18n","_store","_default","exports","default","name","label","_x","useSource","props","sourceAttributes","getCurrentPostType","useSelect","editorStore","context","key","metaKey","postType","meta","setMeta","useEntityProp","postId","placeholder","metaValue","updateMetaValue","newValue","
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","_i18n","_store","_default","exports","default","name","label","_x","useSource","props","sourceAttributes","getCurrentPostType","useSelect","editorStore","context","key","metaKey","postType","meta","setMeta","useEntityProp","postId","placeholder","metaValue","updateMetaValue","newValue","value","updateValue"],"sources":["@wordpress/editor/src/bindings/post-meta.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { _x } from '@wordpress/i18n';\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\n\nexport default {\n\tname: 'core/post-meta',\n\tlabel: _x( 'Post Meta', 'block bindings source' ),\n\tuseSource( props, sourceAttributes ) {\n\t\tconst { getCurrentPostType } = useSelect( editorStore );\n\t\tconst { context } = props;\n\t\tconst { key: metaKey } = sourceAttributes;\n\t\tconst postType = context.postType\n\t\t\t? context.postType\n\t\t\t: getCurrentPostType();\n\n\t\tconst [ meta, setMeta ] = useEntityProp(\n\t\t\t'postType',\n\t\t\tcontext.postType,\n\t\t\t'meta',\n\t\t\tcontext.postId\n\t\t);\n\n\t\tif ( postType === 'wp_template' ) {\n\t\t\treturn { placeholder: metaKey };\n\t\t}\n\t\tconst metaValue = meta[ metaKey ];\n\t\tconst updateMetaValue = ( newValue ) => {\n\t\t\tsetM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AEN,OAAO;MACpBU,KAAK,EAAEH,SAAS;MAChBI,WAAW,EAAEH;IACd,CAAC;EACF;AACD,CAAC"}
|
|
@@ -4,41 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = DisableNonPageContentBlocks;
|
|
7
|
-
var _react = require("react");
|
|
8
7
|
var _data = require("@wordpress/data");
|
|
9
8
|
var _blockEditor = require("@wordpress/block-editor");
|
|
10
9
|
var _element = require("@wordpress/element");
|
|
11
|
-
var _constants = require("./constants");
|
|
12
10
|
/**
|
|
13
11
|
* WordPress dependencies
|
|
14
12
|
*/
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function DisableBlock({
|
|
21
|
-
clientId
|
|
22
|
-
}) {
|
|
23
|
-
const isDescendentOfQueryLoop = (0, _data.useSelect)(select => {
|
|
14
|
+
const PAGE_CONTENT_BLOCKS = ['core/post-title', 'core/post-featured-image', 'core/post-content'];
|
|
15
|
+
function useDisableNonPageContentBlocks() {
|
|
16
|
+
const contentIds = (0, _data.useSelect)(select => {
|
|
24
17
|
const {
|
|
25
|
-
|
|
18
|
+
getBlocksByName,
|
|
19
|
+
getBlockParents,
|
|
20
|
+
getBlockName
|
|
26
21
|
} = select(_blockEditor.store);
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
return getBlocksByName(PAGE_CONTENT_BLOCKS).filter(clientId => getBlockParents(clientId).every(parentClientId => {
|
|
23
|
+
const parentBlockName = getBlockName(parentClientId);
|
|
24
|
+
return parentBlockName !== 'core/query' && !PAGE_CONTENT_BLOCKS.includes(parentBlockName);
|
|
25
|
+
}));
|
|
26
|
+
}, []);
|
|
30
27
|
const {
|
|
31
28
|
setBlockEditingMode,
|
|
32
29
|
unsetBlockEditingMode
|
|
33
30
|
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
34
31
|
(0, _element.useEffect)(() => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
32
|
+
setBlockEditingMode('', 'disabled'); // Disable editing at the root level.
|
|
33
|
+
|
|
34
|
+
for (const contentId of contentIds) {
|
|
35
|
+
setBlockEditingMode(contentId, 'contentOnly'); // Re-enable each content block.
|
|
40
36
|
}
|
|
41
|
-
|
|
37
|
+
return () => {
|
|
38
|
+
unsetBlockEditingMode('');
|
|
39
|
+
for (const contentId of contentIds) {
|
|
40
|
+
unsetBlockEditingMode(contentId);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}, [contentIds, setBlockEditingMode, unsetBlockEditingMode]);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -46,15 +48,6 @@ function DisableBlock({
|
|
|
46
48
|
* page content to be edited.
|
|
47
49
|
*/
|
|
48
50
|
function DisableNonPageContentBlocks() {
|
|
49
|
-
(
|
|
50
|
-
const clientIds = (0, _data.useSelect)(select => {
|
|
51
|
-
return select(_blockEditor.store).getBlocksByName(_constants.PAGE_CONTENT_BLOCK_TYPES);
|
|
52
|
-
}, []);
|
|
53
|
-
return clientIds.map(clientId => {
|
|
54
|
-
return (0, _react.createElement)(DisableBlock, {
|
|
55
|
-
key: clientId,
|
|
56
|
-
clientId: clientId
|
|
57
|
-
});
|
|
58
|
-
});
|
|
51
|
+
useDisableNonPageContentBlocks();
|
|
59
52
|
}
|
|
60
53
|
//# sourceMappingURL=disable-non-page-content-blocks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_blockEditor","_element","
|
|
1
|
+
{"version":3,"names":["_data","require","_blockEditor","_element","PAGE_CONTENT_BLOCKS","useDisableNonPageContentBlocks","contentIds","useSelect","select","getBlocksByName","getBlockParents","getBlockName","blockEditorStore","filter","clientId","every","parentClientId","parentBlockName","includes","setBlockEditingMode","unsetBlockEditingMode","useDispatch","useEffect","contentId","DisableNonPageContentBlocks"],"sources":["@wordpress/editor/src/components/provider/disable-non-page-content-blocks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\n\nconst PAGE_CONTENT_BLOCKS = [\n\t'core/post-title',\n\t'core/post-featured-image',\n\t'core/post-content',\n];\n\nfunction useDisableNonPageContentBlocks() {\n\tconst contentIds = useSelect( ( select ) => {\n\t\tconst { getBlocksByName, getBlockParents, getBlockName } =\n\t\t\tselect( blockEditorStore );\n\t\treturn getBlocksByName( PAGE_CONTENT_BLOCKS ).filter( ( clientId ) =>\n\t\t\tgetBlockParents( clientId ).every( ( parentClientId ) => {\n\t\t\t\tconst parentBlockName = getBlockName( parentClientId );\n\t\t\t\treturn (\n\t\t\t\t\tparentBlockName !== 'core/query' &&\n\t\t\t\t\t! PAGE_CONTENT_BLOCKS.includes( parentBlockName )\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t}, [] );\n\n\tconst { setBlockEditingMode, unsetBlockEditingMode } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tsetBlockEditingMode( '', 'disabled' ); // Disable editing at the root level.\n\n\t\tfor ( const contentId of contentIds ) {\n\t\t\tsetBlockEditingMode( contentId, 'contentOnly' ); // Re-enable each content block.\n\t\t}\n\t\treturn () => {\n\t\t\tunsetBlockEditingMode( '' );\n\t\t\tfor ( const contentId of contentIds ) {\n\t\t\t\tunsetBlockEditingMode( contentId );\n\t\t\t}\n\t\t};\n\t}, [ contentIds, setBlockEditingMode, unsetBlockEditingMode ] );\n}\n\n/**\n * Component that when rendered, makes it so that the site editor allows only\n * page content to be edited.\n */\nexport default function DisableNonPageContentBlocks() {\n\tuseDisableNonPageContentBlocks();\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAL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HANGED
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sources":["@wordpress/editor/src/hooks/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './custom-sources-backwards-compatibility';\nimport './default-autocompleters';\nimport './pattern-
|
|
1
|
+
{"version":3,"names":["require"],"sources":["@wordpress/editor/src/hooks/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './custom-sources-backwards-compatibility';\nimport './default-autocompleters';\nimport './pattern-overrides';\n"],"mappings":";;AAGAA,OAAA;AACAA,OAAA;AACAA,OAAA"}
|
|
@@ -17,7 +17,7 @@ var _lockUnlock = require("../lock-unlock");
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
const {
|
|
20
|
-
|
|
20
|
+
useSetPatternBindings,
|
|
21
21
|
ResetOverridesControl,
|
|
22
22
|
PATTERN_TYPES,
|
|
23
23
|
PARTIAL_SYNCING_SUPPORTED_BLOCKS
|
|
@@ -32,14 +32,21 @@ const {
|
|
|
32
32
|
*
|
|
33
33
|
* @return {Component} Wrapped component.
|
|
34
34
|
*/
|
|
35
|
-
const
|
|
35
|
+
const withPatternOverrideControls = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
|
|
36
36
|
const isSupportedBlock = Object.keys(PARTIAL_SYNCING_SUPPORTED_BLOCKS).includes(props.name);
|
|
37
37
|
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(BlockEdit, {
|
|
38
38
|
...props
|
|
39
|
+
}), isSupportedBlock && (0, _react.createElement)(BindingUpdater, {
|
|
40
|
+
...props
|
|
39
41
|
}), props.isSelected && isSupportedBlock && (0, _react.createElement)(ControlsWithStoreSubscription, {
|
|
40
42
|
...props
|
|
41
43
|
}));
|
|
42
44
|
});
|
|
45
|
+
function BindingUpdater(props) {
|
|
46
|
+
const postType = (0, _data.useSelect)(select => select(_store.store).getCurrentPostType(), []);
|
|
47
|
+
useSetPatternBindings(props, postType);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
43
50
|
|
|
44
51
|
// Split into a separate component to avoid a store subscription
|
|
45
52
|
// on every block.
|
|
@@ -48,13 +55,10 @@ function ControlsWithStoreSubscription(props) {
|
|
|
48
55
|
const isEditingPattern = (0, _data.useSelect)(select => select(_store.store).getCurrentPostType() === PATTERN_TYPES.user, []);
|
|
49
56
|
const bindings = props.attributes.metadata?.bindings;
|
|
50
57
|
const hasPatternBindings = !!bindings && Object.values(bindings).some(binding => binding.source === 'core/pattern-overrides');
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
return (0, _react.createElement)(_react.Fragment, null, shouldShowPartialSyncingControls && (0, _react.createElement)(PartialSyncingControls, {
|
|
54
|
-
...props
|
|
55
|
-
}), shouldShowResetOverridesControl && (0, _react.createElement)(ResetOverridesControl, {
|
|
58
|
+
const shouldShowResetOverridesControl = !isEditingPattern && !!props.attributes.metadata?.name && blockEditingMode !== 'disabled' && hasPatternBindings;
|
|
59
|
+
return (0, _react.createElement)(_react.Fragment, null, shouldShowResetOverridesControl && (0, _react.createElement)(ResetOverridesControl, {
|
|
56
60
|
...props
|
|
57
61
|
}));
|
|
58
62
|
}
|
|
59
|
-
(0, _hooks.addFilter)('editor.BlockEdit', 'core/editor/with-
|
|
60
|
-
//# sourceMappingURL=pattern-
|
|
63
|
+
(0, _hooks.addFilter)('editor.BlockEdit', 'core/editor/with-pattern-override-controls', withPatternOverrideControls);
|
|
64
|
+
//# sourceMappingURL=pattern-overrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_hooks","require","_patterns","_compose","_blockEditor","_data","_store","_lockUnlock","useSetPatternBindings","ResetOverridesControl","PATTERN_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","unlock","patternsPrivateApis","withPatternOverrideControls","createHigherOrderComponent","BlockEdit","props","isSupportedBlock","Object","keys","includes","name","_react","createElement","Fragment","BindingUpdater","isSelected","ControlsWithStoreSubscription","postType","useSelect","select","editorStore","getCurrentPostType","blockEditingMode","useBlockEditingMode","isEditingPattern","user","bindings","attributes","metadata","hasPatternBindings","values","some","binding","source","shouldShowResetOverridesControl","addFilter"],"sources":["@wordpress/editor/src/hooks/pattern-overrides.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useBlockEditingMode } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nconst {\n\tuseSetPatternBindings,\n\tResetOverridesControl,\n\tPATTERN_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} = unlock( patternsPrivateApis );\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning a partial syncing controls to supported blocks in the pattern editor.\n * Currently, only the `core/paragraph` block is supported.\n *\n * @param {Component} BlockEdit Original component.\n *\n * @return {Component} Wrapped component.\n */\nconst withPatternOverrideControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst isSupportedBlock = Object.keys(\n\t\t\tPARTIAL_SYNCING_SUPPORTED_BLOCKS\n\t\t).includes( props.name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ isSupportedBlock && <BindingUpdater { ...props } /> }\n\t\t\t\t{ props.isSelected && isSupportedBlock && (\n\t\t\t\t\t<ControlsWithStoreSubscription { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\nfunction BindingUpdater( props ) {\n\tconst postType = useSelect(\n\t\t( select ) => select( editorStore ).getCurrentPostType(),\n\t\t[]\n\t);\n\tuseSetPatternBindings( props, postType );\n\treturn null;\n}\n\n// Split into a separate component to avoid a store subscription\n// on every block.\nfunction ControlsWithStoreSubscription( props ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isEditingPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getCurrentPostType() === PATTERN_TYPES.user,\n\t\t[]\n\t);\n\n\tconst bindings = props.attributes.metadata?.bindings;\n\tconst hasPatternBindings =\n\t\t!! bindings &&\n\t\tObject.values( bindings ).some(\n\t\t\t( binding ) => binding.source === 'core/pattern-overrides'\n\t\t);\n\n\tconst shouldShowResetOverridesControl =\n\t\t! isEditingPattern &&\n\t\t!! props.attributes.metadata?.name &&\n\t\tblockEditingMode !== 'disabled' &&\n\t\thasPatternBindings;\n\n\treturn (\n\t\t<>\n\t\t\t{ shouldShowResetOverridesControl && (\n\t\t\t\t<ResetOverridesControl { ...props } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/with-pattern-override-controls',\n\twithPatternOverrideControls\n);\n"],"mappings":";;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAbA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,MAAM;EACLO,qBAAqB;EACrBC,qBAAqB;EACrBC,aAAa;EACbC;AACD,CAAC,GAAG,IAAAC,kBAAM,EAAEC,qBAAoB,CAAC;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,2BAA2B,GAAG,IAAAC,mCAA0B,EAC3DC,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAMC,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CACnCT,gCACD,CAAC,CAACU,QAAQ,CAAEJ,KAAK,CAACK,IAAK,CAAC;EAExB,OACC,IAAAC,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA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AAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACGqB,+BAA+B,IAChC,IAAAvB,MAAA,CAAAC,aAAA,EAACf,qBAAqB;IAAA,GAAMQ;EAAK,CAAI,CAErC,CAAC;AAEL;AAEA,IAAA8B,gBAAS,EACR,kBAAkB,EAClB,4CAA4C,EAC5CjC,2BACD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store as
|
|
4
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
5
5
|
import { dispatch } from '@wordpress/data';
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -11,7 +11,7 @@ import patternOverrides from './pattern-overrides';
|
|
|
11
11
|
import postMeta from './post-meta';
|
|
12
12
|
const {
|
|
13
13
|
registerBlockBindingsSource
|
|
14
|
-
} = unlock(dispatch(
|
|
14
|
+
} = unlock(dispatch(blocksStore));
|
|
15
15
|
registerBlockBindingsSource(patternOverrides);
|
|
16
16
|
registerBlockBindingsSource(postMeta);
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","
|
|
1
|
+
{"version":3,"names":["store","blocksStore","dispatch","unlock","patternOverrides","postMeta","registerBlockBindingsSource"],"sources":["@wordpress/editor/src/bindings/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { dispatch } from '@wordpress/data';\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport patternOverrides from './pattern-overrides';\nimport postMeta from './post-meta';\n\nconst { registerBlockBindingsSource } = unlock( dispatch( blocksStore ) );\nregisterBlockBindingsSource( patternOverrides );\nregisterBlockBindingsSource( postMeta );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;AACvC,OAAOC,gBAAgB,MAAM,qBAAqB;AAClD,OAAOC,QAAQ,MAAM,aAAa;AAElC,MAAM;EAAEC;AAA4B,CAAC,GAAGH,MAAM,CAAED,QAAQ,CAAED,WAAY,CAAE,CAAC;AACzEK,2BAA2B,CAAEF,gBAAiB,CAAC;AAC/CE,2BAA2B,CAAED,QAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEntityProp","useSelect","_x","store","editorStore","name","label","useSource","props","sourceAttributes","getCurrentPostType","context","key","metaKey","postType","meta","setMeta","postId","placeholder","metaValue","updateMetaValue","newValue","
|
|
1
|
+
{"version":3,"names":["useEntityProp","useSelect","_x","store","editorStore","name","label","useSource","props","sourceAttributes","getCurrentPostType","context","key","metaKey","postType","meta","setMeta","postId","placeholder","metaValue","updateMetaValue","newValue","value","updateValue"],"sources":["@wordpress/editor/src/bindings/post-meta.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { _x } from '@wordpress/i18n';\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\n\nexport default {\n\tname: 'core/post-meta',\n\tlabel: _x( 'Post Meta', 'block bindings source' ),\n\tuseSource( props, sourceAttributes ) {\n\t\tconst { getCurrentPostType } = useSelect( editorStore );\n\t\tconst { context } = props;\n\t\tconst { key: metaKey } = sourceAttributes;\n\t\tconst postType = context.postType\n\t\t\t? context.postType\n\t\t\t: getCurrentPostType();\n\n\t\tconst [ meta, setMeta ] = useEntityProp(\n\t\t\t'postType',\n\t\t\tcontext.postType,\n\t\t\t'meta',\n\t\t\tcontext.postId\n\t\t);\n\n\t\tif ( postType === 'wp_template' ) {\n\t\t\treturn { placeholder: metaKey };\n\t\t}\n\t\tconst metaValue = meta[ metaKey ];\n\t\tconst updateMetaValue = ( newValue ) => {\n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,SAAS;MAChBI,WAAW,EAAEH;IACd,CAAC;EACF;AACD,CAAC"}
|
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* WordPress dependencies
|
|
4
3
|
*/
|
|
5
4
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
-
import {
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
6
|
import { useEffect } from '@wordpress/element';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
import { PAGE_CONTENT_BLOCK_TYPES } from './constants';
|
|
13
|
-
function DisableBlock({
|
|
14
|
-
clientId
|
|
15
|
-
}) {
|
|
16
|
-
const isDescendentOfQueryLoop = useSelect(select => {
|
|
7
|
+
const PAGE_CONTENT_BLOCKS = ['core/post-title', 'core/post-featured-image', 'core/post-content'];
|
|
8
|
+
function useDisableNonPageContentBlocks() {
|
|
9
|
+
const contentIds = useSelect(select => {
|
|
17
10
|
const {
|
|
18
|
-
|
|
11
|
+
getBlocksByName,
|
|
12
|
+
getBlockParents,
|
|
13
|
+
getBlockName
|
|
19
14
|
} = select(blockEditorStore);
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
return getBlocksByName(PAGE_CONTENT_BLOCKS).filter(clientId => getBlockParents(clientId).every(parentClientId => {
|
|
16
|
+
const parentBlockName = getBlockName(parentClientId);
|
|
17
|
+
return parentBlockName !== 'core/query' && !PAGE_CONTENT_BLOCKS.includes(parentBlockName);
|
|
18
|
+
}));
|
|
19
|
+
}, []);
|
|
23
20
|
const {
|
|
24
21
|
setBlockEditingMode,
|
|
25
22
|
unsetBlockEditingMode
|
|
26
23
|
} = useDispatch(blockEditorStore);
|
|
27
24
|
useEffect(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
25
|
+
setBlockEditingMode('', 'disabled'); // Disable editing at the root level.
|
|
26
|
+
|
|
27
|
+
for (const contentId of contentIds) {
|
|
28
|
+
setBlockEditingMode(contentId, 'contentOnly'); // Re-enable each content block.
|
|
33
29
|
}
|
|
34
|
-
|
|
30
|
+
return () => {
|
|
31
|
+
unsetBlockEditingMode('');
|
|
32
|
+
for (const contentId of contentIds) {
|
|
33
|
+
unsetBlockEditingMode(contentId);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, [contentIds, setBlockEditingMode, unsetBlockEditingMode]);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/**
|
|
@@ -39,15 +41,6 @@ function DisableBlock({
|
|
|
39
41
|
* page content to be edited.
|
|
40
42
|
*/
|
|
41
43
|
export default function DisableNonPageContentBlocks() {
|
|
42
|
-
|
|
43
|
-
const clientIds = useSelect(select => {
|
|
44
|
-
return select(blockEditorStore).getBlocksByName(PAGE_CONTENT_BLOCK_TYPES);
|
|
45
|
-
}, []);
|
|
46
|
-
return clientIds.map(clientId => {
|
|
47
|
-
return createElement(DisableBlock, {
|
|
48
|
-
key: clientId,
|
|
49
|
-
clientId: clientId
|
|
50
|
-
});
|
|
51
|
-
});
|
|
44
|
+
useDisableNonPageContentBlocks();
|
|
52
45
|
}
|
|
53
46
|
//# sourceMappingURL=disable-non-page-content-blocks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","useDispatch","
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","store","blockEditorStore","useEffect","PAGE_CONTENT_BLOCKS","useDisableNonPageContentBlocks","contentIds","select","getBlocksByName","getBlockParents","getBlockName","filter","clientId","every","parentClientId","parentBlockName","includes","setBlockEditingMode","unsetBlockEditingMode","contentId","DisableNonPageContentBlocks"],"sources":["@wordpress/editor/src/components/provider/disable-non-page-content-blocks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\n\nconst PAGE_CONTENT_BLOCKS = [\n\t'core/post-title',\n\t'core/post-featured-image',\n\t'core/post-content',\n];\n\nfunction useDisableNonPageContentBlocks() {\n\tconst contentIds = useSelect( ( select ) => {\n\t\tconst { getBlocksByName, getBlockParents, getBlockName } =\n\t\t\tselect( blockEditorStore );\n\t\treturn getBlocksByName( PAGE_CONTENT_BLOCKS ).filter( ( clientId ) =>\n\t\t\tgetBlockParents( clientId ).every( ( parentClientId ) => {\n\t\t\t\tconst parentBlockName = getBlockName( parentClientId );\n\t\t\t\treturn (\n\t\t\t\t\tparentBlockName !== 'core/query' &&\n\t\t\t\t\t! PAGE_CONTENT_BLOCKS.includes( parentBlockName )\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t}, [] );\n\n\tconst { setBlockEditingMode, unsetBlockEditingMode } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tsetBlockEditingMode( '', 'disabled' ); // Disable editing at the root level.\n\n\t\tfor ( const contentId of contentIds ) {\n\t\t\tsetBlockEditingMode( contentId, 'contentOnly' ); // Re-enable each content block.\n\t\t}\n\t\treturn () => {\n\t\t\tunsetBlockEditingMode( '' );\n\t\t\tfor ( const contentId of contentIds ) {\n\t\t\t\tunsetBlockEditingMode( contentId );\n\t\t\t}\n\t\t};\n\t}, [ contentIds, setBlockEditingMode, unsetBlockEditingMode ] );\n}\n\n/**\n * Component that when rendered, makes it so that the site editor allows only\n * page content to be edited.\n */\nexport default function DisableNonPageContentBlocks() {\n\tuseDisableNonPageContentBlocks();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,SAAS,QAAQ,oBAAoB;AAE9C,MAAMC,mBAAmB,GAAG,CAC3B,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,CACnB;AAED,SAASC,8BAA8BA,CAAA,EAAG;EACzC,MAAMC,UAAU,GAAGP,SAAS,CAAIQ,MAAM,IAAM;IAC3C,MAAM;MAAEC,eAAe;MAAEC,eAAe;MAAEC;IAAa,CAAC,GACvDH,MAAM,CAAEL,gBAAiB,CAAC;IAC3B,OAAOM,eAAe,CAAEJ,mBAAoB,CAAC,CAACO,MAAM,CAAIC,QAAQ,IAC/DH,eAAe,CAAEG,QAAS,CAAC,CAACC,KAAK,CAAIC,cAAc,IAAM;MACxD,MAAMC,eAAe,GAAGL,YAAY,CAAEI,cAAe,CAAC;MACtD,OACCC,eAAe,KAAK,YAAY,IAChC,CAAEX,mBAAmB,CAACY,QAAQ,CAAED,eAAgB,CAAC;IAEnD,CAAE,CACH,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAM;IAAEE,mBAAmB;IAAEC;EAAsB,CAAC,GACnDlB,WAAW,CAAEE,gBAAiB,CAAC;EAEhCC,SAAS,CAAE,MAAM;IAChBc,mBAAmB,CAAE,EAAE,EAAE,UAAW,CAAC,CAAC,CAAC;;IAEvC,KAAM,MAAME,SAAS,IAAIb,UAAU,EAAG;MACrCW,mBAAmB,CAAEE,SAAS,EAAE,aAAc,CAAC,CAAC,CAAC;IAClD;IACA,OAAO,MAAM;MACZD,qBAAqB,CAAE,EAAG,CAAC;MAC3B,KAAM,MAAMC,SAAS,IAAIb,UAAU,EAAG;QACrCY,qBAAqB,CAAEC,SAAU,CAAC;MACnC;IACD,CAAC;EACF,CAAC,EAAE,CAAEb,UAAU,EAAEW,mBAAmB,EAAEC,qBAAqB,CAAG,CAAC;AAChE;;AAEA;AACA;AACA;AACA;AACA,eAAe,SAASE,2BAA2BA,CAAA,EAAG;EACrDf,8BAA8B,CAAC,CAAC;AACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/editor/src/hooks/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './custom-sources-backwards-compatibility';\nimport './default-autocompleters';\nimport './pattern-
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/editor/src/hooks/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './custom-sources-backwards-compatibility';\nimport './default-autocompleters';\nimport './pattern-overrides';\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,0CAA0C;AACjD,OAAO,0BAA0B;AACjC,OAAO,qBAAqB"}
|
|
@@ -14,7 +14,7 @@ import { useSelect } from '@wordpress/data';
|
|
|
14
14
|
import { store as editorStore } from '../store';
|
|
15
15
|
import { unlock } from '../lock-unlock';
|
|
16
16
|
const {
|
|
17
|
-
|
|
17
|
+
useSetPatternBindings,
|
|
18
18
|
ResetOverridesControl,
|
|
19
19
|
PATTERN_TYPES,
|
|
20
20
|
PARTIAL_SYNCING_SUPPORTED_BLOCKS
|
|
@@ -29,14 +29,21 @@ const {
|
|
|
29
29
|
*
|
|
30
30
|
* @return {Component} Wrapped component.
|
|
31
31
|
*/
|
|
32
|
-
const
|
|
32
|
+
const withPatternOverrideControls = createHigherOrderComponent(BlockEdit => props => {
|
|
33
33
|
const isSupportedBlock = Object.keys(PARTIAL_SYNCING_SUPPORTED_BLOCKS).includes(props.name);
|
|
34
34
|
return createElement(Fragment, null, createElement(BlockEdit, {
|
|
35
35
|
...props
|
|
36
|
+
}), isSupportedBlock && createElement(BindingUpdater, {
|
|
37
|
+
...props
|
|
36
38
|
}), props.isSelected && isSupportedBlock && createElement(ControlsWithStoreSubscription, {
|
|
37
39
|
...props
|
|
38
40
|
}));
|
|
39
41
|
});
|
|
42
|
+
function BindingUpdater(props) {
|
|
43
|
+
const postType = useSelect(select => select(editorStore).getCurrentPostType(), []);
|
|
44
|
+
useSetPatternBindings(props, postType);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
40
47
|
|
|
41
48
|
// Split into a separate component to avoid a store subscription
|
|
42
49
|
// on every block.
|
|
@@ -45,13 +52,10 @@ function ControlsWithStoreSubscription(props) {
|
|
|
45
52
|
const isEditingPattern = useSelect(select => select(editorStore).getCurrentPostType() === PATTERN_TYPES.user, []);
|
|
46
53
|
const bindings = props.attributes.metadata?.bindings;
|
|
47
54
|
const hasPatternBindings = !!bindings && Object.values(bindings).some(binding => binding.source === 'core/pattern-overrides');
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
return createElement(Fragment, null, shouldShowPartialSyncingControls && createElement(PartialSyncingControls, {
|
|
51
|
-
...props
|
|
52
|
-
}), shouldShowResetOverridesControl && createElement(ResetOverridesControl, {
|
|
55
|
+
const shouldShowResetOverridesControl = !isEditingPattern && !!props.attributes.metadata?.name && blockEditingMode !== 'disabled' && hasPatternBindings;
|
|
56
|
+
return createElement(Fragment, null, shouldShowResetOverridesControl && createElement(ResetOverridesControl, {
|
|
53
57
|
...props
|
|
54
58
|
}));
|
|
55
59
|
}
|
|
56
|
-
addFilter('editor.BlockEdit', 'core/editor/with-
|
|
57
|
-
//# sourceMappingURL=pattern-
|
|
60
|
+
addFilter('editor.BlockEdit', 'core/editor/with-pattern-override-controls', withPatternOverrideControls);
|
|
61
|
+
//# sourceMappingURL=pattern-overrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["addFilter","privateApis","patternsPrivateApis","createHigherOrderComponent","useBlockEditingMode","useSelect","store","editorStore","unlock","useSetPatternBindings","ResetOverridesControl","PATTERN_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","withPatternOverrideControls","BlockEdit","props","isSupportedBlock","Object","keys","includes","name","createElement","Fragment","BindingUpdater","isSelected","ControlsWithStoreSubscription","postType","select","getCurrentPostType","blockEditingMode","isEditingPattern","user","bindings","attributes","metadata","hasPatternBindings","values","some","binding","source","shouldShowResetOverridesControl"],"sources":["@wordpress/editor/src/hooks/pattern-overrides.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useBlockEditingMode } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nconst {\n\tuseSetPatternBindings,\n\tResetOverridesControl,\n\tPATTERN_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} = unlock( patternsPrivateApis );\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning a partial syncing controls to supported blocks in the pattern editor.\n * Currently, only the `core/paragraph` block is supported.\n *\n * @param {Component} BlockEdit Original component.\n *\n * @return {Component} Wrapped component.\n */\nconst withPatternOverrideControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst isSupportedBlock = Object.keys(\n\t\t\tPARTIAL_SYNCING_SUPPORTED_BLOCKS\n\t\t).includes( props.name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ isSupportedBlock && <BindingUpdater { ...props } /> }\n\t\t\t\t{ props.isSelected && isSupportedBlock && (\n\t\t\t\t\t<ControlsWithStoreSubscription { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\nfunction BindingUpdater( props ) {\n\tconst postType = useSelect(\n\t\t( select ) => select( editorStore ).getCurrentPostType(),\n\t\t[]\n\t);\n\tuseSetPatternBindings( props, postType );\n\treturn null;\n}\n\n// Split into a separate component to avoid a store subscription\n// on every block.\nfunction ControlsWithStoreSubscription( props ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isEditingPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getCurrentPostType() === PATTERN_TYPES.user,\n\t\t[]\n\t);\n\n\tconst bindings = props.attributes.metadata?.bindings;\n\tconst hasPatternBindings =\n\t\t!! bindings &&\n\t\tObject.values( bindings ).some(\n\t\t\t( binding ) => binding.source === 'core/pattern-overrides'\n\t\t);\n\n\tconst shouldShowResetOverridesControl =\n\t\t! isEditingPattern &&\n\t\t!! props.attributes.metadata?.name &&\n\t\tblockEditingMode !== 'disabled' &&\n\t\thasPatternBindings;\n\n\treturn (\n\t\t<>\n\t\t\t{ shouldShowResetOverridesControl && (\n\t\t\t\t<ResetOverridesControl { ...props } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/with-pattern-override-controls',\n\twithPatternOverrideControls\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;AACxE,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,WAAW,QAAQ,UAAU;AAC/C,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,MAAM;EACLC,qBAAqB;EACrBC,qBAAqB;EACrBC,aAAa;EACbC;AACD,CAAC,GAAGJ,MAAM,CAAEN,mBAAoB,CAAC;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMW,2BAA2B,GAAGV,0BAA0B,CAC3DW,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAMC,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CACnCN,gCACD,CAAC,CAACO,QAAQ,CAAEJ,KAAK,CAACK,IAAK,CAAC;EAExB,OACCC,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACP,SAAS;IAAA,GAAMC;EAAK,CAAI,CAAC,EACxBC,gBAAgB,IAAIK,aAAA,CAACE,cAAc;IAAA,GAAMR;EAAK,CAAI,CAAC,EACnDA,KAAK,CAACS,UAAU,IAAIR,gBAAgB,IACrCK,aAAA,CAACI,6BAA6B;IAAA,GAAMV;EAAK,CAAI,CAE7C,CAAC;AAEL,CACD,CAAC;AAED,SAASQ,cAAcA,CAAER,KAAK,EAAG;EAChC,MAAMW,QAAQ,GAAGrB,SAAS,CACvBsB,MAAM,IAAMA,MAAM,CAAEpB,WAAY,CAAC,CAACqB,kBAAkB,CAAC,CAAC,EACxD,EACD,CAAC;EACDnB,qBAAqB,CAAEM,KAAK,EAAEW,QAAS,CAAC;EACxC,OAAO,IAAI;AACZ;;AAEA;AACA;AACA,SAASD,6BAA6BA,CAAEV,KAAK,EAAG;EAC/C,MAAMc,gBAAgB,GAAGzB,mBAAmB,CAAC,CAAC;EAC9C,MAAM0B,gBAAgB,GAAGzB,SAAS,CAC/BsB,MAAM,IACPA,MAAM,CAAEpB,WAAY,CAAC,CAACqB,kBAAkB,CAAC,CAAC,KAAKjB,aAAa,CAACoB,IAAI,EAClE,EACD,CAAC;EAED,MAAMC,QAAQ,GAAGjB,KAAK,CAACkB,UAAU,CAACC,QAAQ,EAAEF,QAAQ;EACpD,MAAMG,kBAAkB,GACvB,CAAC,CAAEH,QAAQ,IACXf,MAAM,CAACmB,MAAM,CAAEJ,QAAS,CAAC,CAACK,IAAI,CAC3BC,OAAO,IAAMA,OAAO,CAACC,MAAM,KAAK,wBACnC,CAAC;EAEF,MAAMC,+BAA+B,GACpC,CAAEV,gBAAgB,IAClB,CAAC,CAAEf,KAAK,CAACkB,UAAU,CAACC,QAAQ,EAAEd,IAAI,IAClCS,gBAAgB,KAAK,UAAU,IAC/BM,kBAAkB;EAEnB,OACCd,aAAA,CAAAC,QAAA,QACGkB,+BAA+B,IAChCnB,aAAA,CAACX,qBAAqB;IAAA,GAAMK;EAAK,CAAI,CAErC,CAAC;AAEL;AAEAf,SAAS,CACR,kBAAkB,EAClB,4CAA4C,EAC5Ca,2BACD,CAAC"}
|
package/build-style/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/editor",
|
|
3
|
-
"version": "13.28.
|
|
3
|
+
"version": "13.28.5",
|
|
4
4
|
"description": "Enhanced block editor for WordPress posts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"@wordpress/a11y": "^3.51.1",
|
|
35
35
|
"@wordpress/api-fetch": "^6.48.1",
|
|
36
36
|
"@wordpress/blob": "^3.51.1",
|
|
37
|
-
"@wordpress/block-editor": "^12.19.
|
|
38
|
-
"@wordpress/blocks": "^12.28.
|
|
39
|
-
"@wordpress/commands": "^0.22.
|
|
40
|
-
"@wordpress/components": "^26.0.
|
|
37
|
+
"@wordpress/block-editor": "^12.19.5",
|
|
38
|
+
"@wordpress/blocks": "^12.28.5",
|
|
39
|
+
"@wordpress/commands": "^0.22.4",
|
|
40
|
+
"@wordpress/components": "^26.0.4",
|
|
41
41
|
"@wordpress/compose": "^6.28.1",
|
|
42
|
-
"@wordpress/core-data": "^6.28.
|
|
42
|
+
"@wordpress/core-data": "^6.28.5",
|
|
43
43
|
"@wordpress/data": "^9.21.1",
|
|
44
44
|
"@wordpress/date": "^4.51.1",
|
|
45
45
|
"@wordpress/deprecated": "^3.51.1",
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
"@wordpress/hooks": "^3.51.1",
|
|
49
49
|
"@wordpress/html-entities": "^3.51.1",
|
|
50
50
|
"@wordpress/i18n": "^4.51.1",
|
|
51
|
-
"@wordpress/icons": "^9.42.
|
|
51
|
+
"@wordpress/icons": "^9.42.3",
|
|
52
52
|
"@wordpress/keyboard-shortcuts": "^4.28.1",
|
|
53
53
|
"@wordpress/keycodes": "^3.51.1",
|
|
54
54
|
"@wordpress/media-utils": "^4.42.1",
|
|
55
55
|
"@wordpress/notices": "^4.19.1",
|
|
56
|
-
"@wordpress/patterns": "^1.12.
|
|
57
|
-
"@wordpress/preferences": "^3.28.
|
|
56
|
+
"@wordpress/patterns": "^1.12.5",
|
|
57
|
+
"@wordpress/preferences": "^3.28.4",
|
|
58
58
|
"@wordpress/private-apis": "^0.33.1",
|
|
59
|
-
"@wordpress/reusable-blocks": "^4.28.
|
|
60
|
-
"@wordpress/rich-text": "^6.28.
|
|
61
|
-
"@wordpress/server-side-render": "^4.28.
|
|
59
|
+
"@wordpress/reusable-blocks": "^4.28.5",
|
|
60
|
+
"@wordpress/rich-text": "^6.28.3",
|
|
61
|
+
"@wordpress/server-side-render": "^4.28.5",
|
|
62
62
|
"@wordpress/url": "^3.52.1",
|
|
63
63
|
"@wordpress/wordcount": "^3.51.1",
|
|
64
64
|
"classnames": "^2.3.1",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "4927ea437069f9aed12f696df294a79bd8e12fd5"
|
|
79
79
|
}
|
package/src/bindings/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store as
|
|
4
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
5
5
|
import { dispatch } from '@wordpress/data';
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
@@ -10,6 +10,6 @@ import { unlock } from '../lock-unlock';
|
|
|
10
10
|
import patternOverrides from './pattern-overrides';
|
|
11
11
|
import postMeta from './post-meta';
|
|
12
12
|
|
|
13
|
-
const { registerBlockBindingsSource } = unlock( dispatch(
|
|
13
|
+
const { registerBlockBindingsSource } = unlock( dispatch( blocksStore ) );
|
|
14
14
|
registerBlockBindingsSource( patternOverrides );
|
|
15
15
|
registerBlockBindingsSource( postMeta );
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
const postType = context.postType
|
|
20
20
|
? context.postType
|
|
21
21
|
: getCurrentPostType();
|
|
22
|
+
|
|
22
23
|
const [ meta, setMeta ] = useEntityProp(
|
|
23
24
|
'postType',
|
|
24
25
|
context.postType,
|
|
@@ -33,9 +34,11 @@ export default {
|
|
|
33
34
|
const updateMetaValue = ( newValue ) => {
|
|
34
35
|
setMeta( { ...meta, [ metaKey ]: newValue } );
|
|
35
36
|
};
|
|
37
|
+
|
|
36
38
|
return {
|
|
37
39
|
placeholder: metaKey,
|
|
38
|
-
|
|
40
|
+
value: metaValue,
|
|
41
|
+
updateValue: updateMetaValue,
|
|
39
42
|
};
|
|
40
43
|
},
|
|
41
44
|
};
|
|
@@ -2,39 +2,46 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
useBlockEditingMode,
|
|
7
|
-
store as blockEditorStore,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
6
|
import { useEffect } from '@wordpress/element';
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const PAGE_CONTENT_BLOCKS = [
|
|
9
|
+
'core/post-title',
|
|
10
|
+
'core/post-featured-image',
|
|
11
|
+
'core/post-content',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
function useDisableNonPageContentBlocks() {
|
|
15
|
+
const contentIds = useSelect( ( select ) => {
|
|
16
|
+
const { getBlocksByName, getBlockParents, getBlockName } =
|
|
17
|
+
select( blockEditorStore );
|
|
18
|
+
return getBlocksByName( PAGE_CONTENT_BLOCKS ).filter( ( clientId ) =>
|
|
19
|
+
getBlockParents( clientId ).every( ( parentClientId ) => {
|
|
20
|
+
const parentBlockName = getBlockName( parentClientId );
|
|
21
|
+
return (
|
|
22
|
+
parentBlockName !== 'core/query' &&
|
|
23
|
+
! PAGE_CONTENT_BLOCKS.includes( parentBlockName )
|
|
24
|
+
);
|
|
25
|
+
} )
|
|
26
|
+
);
|
|
27
|
+
}, [] );
|
|
15
28
|
|
|
16
|
-
function DisableBlock( { clientId } ) {
|
|
17
|
-
const isDescendentOfQueryLoop = useSelect(
|
|
18
|
-
( select ) => {
|
|
19
|
-
const { getBlockParentsByBlockName } = select( blockEditorStore );
|
|
20
|
-
return (
|
|
21
|
-
getBlockParentsByBlockName( clientId, 'core/query' ).length !==
|
|
22
|
-
0
|
|
23
|
-
);
|
|
24
|
-
},
|
|
25
|
-
[ clientId ]
|
|
26
|
-
);
|
|
27
|
-
const mode = isDescendentOfQueryLoop ? undefined : 'contentOnly';
|
|
28
29
|
const { setBlockEditingMode, unsetBlockEditingMode } =
|
|
29
30
|
useDispatch( blockEditorStore );
|
|
31
|
+
|
|
30
32
|
useEffect( () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
33
|
+
setBlockEditingMode( '', 'disabled' ); // Disable editing at the root level.
|
|
34
|
+
|
|
35
|
+
for ( const contentId of contentIds ) {
|
|
36
|
+
setBlockEditingMode( contentId, 'contentOnly' ); // Re-enable each content block.
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
return () => {
|
|
39
|
+
unsetBlockEditingMode( '' );
|
|
40
|
+
for ( const contentId of contentIds ) {
|
|
41
|
+
unsetBlockEditingMode( contentId );
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [ contentIds, setBlockEditingMode, unsetBlockEditingMode ] );
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
/**
|
|
@@ -42,14 +49,5 @@ function DisableBlock( { clientId } ) {
|
|
|
42
49
|
* page content to be edited.
|
|
43
50
|
*/
|
|
44
51
|
export default function DisableNonPageContentBlocks() {
|
|
45
|
-
|
|
46
|
-
const clientIds = useSelect( ( select ) => {
|
|
47
|
-
return select( blockEditorStore ).getBlocksByName(
|
|
48
|
-
PAGE_CONTENT_BLOCK_TYPES
|
|
49
|
-
);
|
|
50
|
-
}, [] );
|
|
51
|
-
|
|
52
|
-
return clientIds.map( ( clientId ) => {
|
|
53
|
-
return <DisableBlock key={ clientId } clientId={ clientId } />;
|
|
54
|
-
} );
|
|
52
|
+
useDisableNonPageContentBlocks();
|
|
55
53
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { createRegistry, RegistryProvider } from '@wordpress/data';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import DisableNonPageContentBlocks from '../disable-non-page-content-blocks';
|
|
15
|
+
|
|
16
|
+
describe( 'DisableNonPageContentBlocks', () => {
|
|
17
|
+
it( 'disables page content blocks', () => {
|
|
18
|
+
const testBlocks = {
|
|
19
|
+
0: 'core/template-part',
|
|
20
|
+
/**/ '00': 'core/site-title',
|
|
21
|
+
/**/ '01': 'core/navigation',
|
|
22
|
+
1: 'core/group',
|
|
23
|
+
/**/ 10: 'core/post-title',
|
|
24
|
+
/**/ 11: 'core/post-featured-image',
|
|
25
|
+
/**/ 12: 'core/post-content',
|
|
26
|
+
/**/ /**/ 120: 'core/paragraph',
|
|
27
|
+
/**/ /**/ 121: 'core/post-featured-image',
|
|
28
|
+
2: 'core/query',
|
|
29
|
+
/**/ 20: 'core/post-title',
|
|
30
|
+
/**/ 21: 'core/post-featured-image',
|
|
31
|
+
/**/ 22: 'core/post-content',
|
|
32
|
+
3: 'core/template-part',
|
|
33
|
+
/**/ 30: 'core/paragraph',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const setBlockEditingMode = jest.fn( () => ( {
|
|
37
|
+
type: 'SET_BLOCK_EDITING_MODE',
|
|
38
|
+
} ) );
|
|
39
|
+
const unsetBlockEditingMode = jest.fn( () => ( {
|
|
40
|
+
type: 'UNSET_BLOCK_EDITING_MODE',
|
|
41
|
+
} ) );
|
|
42
|
+
|
|
43
|
+
const registry = createRegistry( {
|
|
44
|
+
'core/block-editor': {
|
|
45
|
+
reducer: () => {},
|
|
46
|
+
selectors: {
|
|
47
|
+
getBlocksByName( state, blockNames ) {
|
|
48
|
+
return Object.keys( testBlocks ).filter( ( clientId ) =>
|
|
49
|
+
blockNames.includes( testBlocks[ clientId ] )
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
getBlockParents( state, clientId ) {
|
|
53
|
+
return clientId.slice( 0, -1 ).split( '' );
|
|
54
|
+
},
|
|
55
|
+
getBlockName( state, clientId ) {
|
|
56
|
+
return testBlocks[ clientId ];
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
actions: {
|
|
60
|
+
setBlockEditingMode,
|
|
61
|
+
unsetBlockEditingMode,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
const { unmount } = render(
|
|
67
|
+
<RegistryProvider value={ registry }>
|
|
68
|
+
<DisableNonPageContentBlocks />
|
|
69
|
+
</RegistryProvider>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect( setBlockEditingMode.mock.calls ).toEqual( [
|
|
73
|
+
[ '', 'disabled' ], // root
|
|
74
|
+
[ '10', 'contentOnly' ], // post-title
|
|
75
|
+
[ '11', 'contentOnly' ], // post-featured-image
|
|
76
|
+
[ '12', 'contentOnly' ], // post-content
|
|
77
|
+
// NOT the post-featured-image nested within post-content
|
|
78
|
+
// NOT any of the content blocks within query
|
|
79
|
+
] );
|
|
80
|
+
|
|
81
|
+
unmount();
|
|
82
|
+
|
|
83
|
+
expect( unsetBlockEditingMode.mock.calls ).toEqual( [
|
|
84
|
+
[ '' ], // root
|
|
85
|
+
[ '10' ], // post-title
|
|
86
|
+
[ '11' ], // post-featured-image
|
|
87
|
+
[ '12' ], // post-content
|
|
88
|
+
] );
|
|
89
|
+
} );
|
|
90
|
+
} );
|
package/src/hooks/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { store as editorStore } from '../store';
|
|
|
14
14
|
import { unlock } from '../lock-unlock';
|
|
15
15
|
|
|
16
16
|
const {
|
|
17
|
-
|
|
17
|
+
useSetPatternBindings,
|
|
18
18
|
ResetOverridesControl,
|
|
19
19
|
PATTERN_TYPES,
|
|
20
20
|
PARTIAL_SYNCING_SUPPORTED_BLOCKS,
|
|
@@ -29,7 +29,7 @@ const {
|
|
|
29
29
|
*
|
|
30
30
|
* @return {Component} Wrapped component.
|
|
31
31
|
*/
|
|
32
|
-
const
|
|
32
|
+
const withPatternOverrideControls = createHigherOrderComponent(
|
|
33
33
|
( BlockEdit ) => ( props ) => {
|
|
34
34
|
const isSupportedBlock = Object.keys(
|
|
35
35
|
PARTIAL_SYNCING_SUPPORTED_BLOCKS
|
|
@@ -38,6 +38,7 @@ const withPartialSyncingControls = createHigherOrderComponent(
|
|
|
38
38
|
return (
|
|
39
39
|
<>
|
|
40
40
|
<BlockEdit { ...props } />
|
|
41
|
+
{ isSupportedBlock && <BindingUpdater { ...props } /> }
|
|
41
42
|
{ props.isSelected && isSupportedBlock && (
|
|
42
43
|
<ControlsWithStoreSubscription { ...props } />
|
|
43
44
|
) }
|
|
@@ -46,6 +47,15 @@ const withPartialSyncingControls = createHigherOrderComponent(
|
|
|
46
47
|
}
|
|
47
48
|
);
|
|
48
49
|
|
|
50
|
+
function BindingUpdater( props ) {
|
|
51
|
+
const postType = useSelect(
|
|
52
|
+
( select ) => select( editorStore ).getCurrentPostType(),
|
|
53
|
+
[]
|
|
54
|
+
);
|
|
55
|
+
useSetPatternBindings( props, postType );
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
// Split into a separate component to avoid a store subscription
|
|
50
60
|
// on every block.
|
|
51
61
|
function ControlsWithStoreSubscription( props ) {
|
|
@@ -55,6 +65,7 @@ function ControlsWithStoreSubscription( props ) {
|
|
|
55
65
|
select( editorStore ).getCurrentPostType() === PATTERN_TYPES.user,
|
|
56
66
|
[]
|
|
57
67
|
);
|
|
68
|
+
|
|
58
69
|
const bindings = props.attributes.metadata?.bindings;
|
|
59
70
|
const hasPatternBindings =
|
|
60
71
|
!! bindings &&
|
|
@@ -62,19 +73,14 @@ function ControlsWithStoreSubscription( props ) {
|
|
|
62
73
|
( binding ) => binding.source === 'core/pattern-overrides'
|
|
63
74
|
);
|
|
64
75
|
|
|
65
|
-
const shouldShowPartialSyncingControls =
|
|
66
|
-
isEditingPattern && blockEditingMode === 'default';
|
|
67
76
|
const shouldShowResetOverridesControl =
|
|
68
77
|
! isEditingPattern &&
|
|
69
|
-
!! props.attributes.metadata?.
|
|
78
|
+
!! props.attributes.metadata?.name &&
|
|
70
79
|
blockEditingMode !== 'disabled' &&
|
|
71
80
|
hasPatternBindings;
|
|
72
81
|
|
|
73
82
|
return (
|
|
74
83
|
<>
|
|
75
|
-
{ shouldShowPartialSyncingControls && (
|
|
76
|
-
<PartialSyncingControls { ...props } />
|
|
77
|
-
) }
|
|
78
84
|
{ shouldShowResetOverridesControl && (
|
|
79
85
|
<ResetOverridesControl { ...props } />
|
|
80
86
|
) }
|
|
@@ -84,6 +90,6 @@ function ControlsWithStoreSubscription( props ) {
|
|
|
84
90
|
|
|
85
91
|
addFilter(
|
|
86
92
|
'editor.BlockEdit',
|
|
87
|
-
'core/editor/with-
|
|
88
|
-
|
|
93
|
+
'core/editor/with-pattern-override-controls',
|
|
94
|
+
withPatternOverrideControls
|
|
89
95
|
);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PAGE_CONTENT_BLOCK_TYPES = void 0;
|
|
7
|
-
const PAGE_CONTENT_BLOCK_TYPES = exports.PAGE_CONTENT_BLOCK_TYPES = ['core/post-title', 'core/post-featured-image', 'core/post-content'];
|
|
8
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["PAGE_CONTENT_BLOCK_TYPES","exports"],"sources":["@wordpress/editor/src/components/provider/constants.js"],"sourcesContent":["export const PAGE_CONTENT_BLOCK_TYPES = [\n\t'core/post-title',\n\t'core/post-featured-image',\n\t'core/post-content',\n];\n"],"mappings":";;;;;;AAAO,MAAMA,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GAAG,CACvC,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,CACnB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_hooks","require","_patterns","_compose","_blockEditor","_data","_store","_lockUnlock","PartialSyncingControls","ResetOverridesControl","PATTERN_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","unlock","patternsPrivateApis","withPartialSyncingControls","createHigherOrderComponent","BlockEdit","props","isSupportedBlock","Object","keys","includes","name","_react","createElement","Fragment","isSelected","ControlsWithStoreSubscription","blockEditingMode","useBlockEditingMode","isEditingPattern","useSelect","select","editorStore","getCurrentPostType","user","bindings","attributes","metadata","hasPatternBindings","values","some","binding","source","shouldShowPartialSyncingControls","shouldShowResetOverridesControl","id","addFilter"],"sources":["@wordpress/editor/src/hooks/pattern-partial-syncing.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useBlockEditingMode } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nconst {\n\tPartialSyncingControls,\n\tResetOverridesControl,\n\tPATTERN_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} = unlock( patternsPrivateApis );\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning a partial syncing controls to supported blocks in the pattern editor.\n * Currently, only the `core/paragraph` block is supported.\n *\n * @param {Component} BlockEdit Original component.\n *\n * @return {Component} Wrapped component.\n */\nconst withPartialSyncingControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst isSupportedBlock = Object.keys(\n\t\t\tPARTIAL_SYNCING_SUPPORTED_BLOCKS\n\t\t).includes( props.name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ props.isSelected && isSupportedBlock && (\n\t\t\t\t\t<ControlsWithStoreSubscription { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\n// Split into a separate component to avoid a store subscription\n// on every block.\nfunction ControlsWithStoreSubscription( props ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isEditingPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getCurrentPostType() === PATTERN_TYPES.user,\n\t\t[]\n\t);\n\tconst bindings = props.attributes.metadata?.bindings;\n\tconst hasPatternBindings =\n\t\t!! bindings &&\n\t\tObject.values( bindings ).some(\n\t\t\t( binding ) => binding.source === 'core/pattern-overrides'\n\t\t);\n\n\tconst shouldShowPartialSyncingControls =\n\t\tisEditingPattern && blockEditingMode === 'default';\n\tconst shouldShowResetOverridesControl =\n\t\t! isEditingPattern &&\n\t\t!! props.attributes.metadata?.id &&\n\t\tblockEditingMode !== 'disabled' &&\n\t\thasPatternBindings;\n\n\treturn (\n\t\t<>\n\t\t\t{ shouldShowPartialSyncingControls && (\n\t\t\t\t<PartialSyncingControls { ...props } />\n\t\t\t) }\n\t\t\t{ shouldShowResetOverridesControl && (\n\t\t\t\t<ResetOverridesControl { ...props } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/with-partial-syncing-controls',\n\twithPartialSyncingControls\n);\n"],"mappings":";;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAA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MAAMC,gCAAgC,GACrCd,gBAAgB,IAAIF,gBAAgB,KAAK,SAAS;EACnD,MAAMiB,+BAA+B,GACpC,CAAEf,gBAAgB,IAClB,CAAC,CAAEb,KAAK,CAACoB,UAAU,CAACC,QAAQ,EAAEQ,EAAE,IAChClB,gBAAgB,KAAK,UAAU,IAC/BW,kBAAkB;EAEnB,OACC,IAAAhB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACGmB,gCAAgC,IACjC,IAAArB,MAAA,CAAAC,aAAA,EAAChB,sBAAsB;IAAA,GAAMS;EAAK,CAAI,CACtC,EACC4B,+BAA+B,IAChC,IAAAtB,MAAA,CAAAC,aAAA,EAACf,qBAAqB;IAAA,GAAMQ;EAAK,CAAI,CAErC,CAAC;AAEL;AAEA,IAAA8B,gBAAS,EACR,kBAAkB,EAClB,2CAA2C,EAC3CjC,0BACD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["PAGE_CONTENT_BLOCK_TYPES"],"sources":["@wordpress/editor/src/components/provider/constants.js"],"sourcesContent":["export const PAGE_CONTENT_BLOCK_TYPES = [\n\t'core/post-title',\n\t'core/post-featured-image',\n\t'core/post-content',\n];\n"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,GAAG,CACvC,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,CACnB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["addFilter","privateApis","patternsPrivateApis","createHigherOrderComponent","useBlockEditingMode","useSelect","store","editorStore","unlock","PartialSyncingControls","ResetOverridesControl","PATTERN_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","withPartialSyncingControls","BlockEdit","props","isSupportedBlock","Object","keys","includes","name","createElement","Fragment","isSelected","ControlsWithStoreSubscription","blockEditingMode","isEditingPattern","select","getCurrentPostType","user","bindings","attributes","metadata","hasPatternBindings","values","some","binding","source","shouldShowPartialSyncingControls","shouldShowResetOverridesControl","id"],"sources":["@wordpress/editor/src/hooks/pattern-partial-syncing.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useBlockEditingMode } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nconst {\n\tPartialSyncingControls,\n\tResetOverridesControl,\n\tPATTERN_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} = unlock( patternsPrivateApis );\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning a partial syncing controls to supported blocks in the pattern editor.\n * Currently, only the `core/paragraph` block is supported.\n *\n * @param {Component} BlockEdit Original component.\n *\n * @return {Component} Wrapped component.\n */\nconst withPartialSyncingControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst isSupportedBlock = Object.keys(\n\t\t\tPARTIAL_SYNCING_SUPPORTED_BLOCKS\n\t\t).includes( props.name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ props.isSelected && isSupportedBlock && (\n\t\t\t\t\t<ControlsWithStoreSubscription { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\n// Split into a separate component to avoid a store subscription\n// on every block.\nfunction ControlsWithStoreSubscription( props ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isEditingPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getCurrentPostType() === PATTERN_TYPES.user,\n\t\t[]\n\t);\n\tconst bindings = props.attributes.metadata?.bindings;\n\tconst hasPatternBindings =\n\t\t!! bindings &&\n\t\tObject.values( bindings ).some(\n\t\t\t( binding ) => binding.source === 'core/pattern-overrides'\n\t\t);\n\n\tconst shouldShowPartialSyncingControls =\n\t\tisEditingPattern && blockEditingMode === 'default';\n\tconst shouldShowResetOverridesControl =\n\t\t! isEditingPattern &&\n\t\t!! props.attributes.metadata?.id &&\n\t\tblockEditingMode !== 'disabled' &&\n\t\thasPatternBindings;\n\n\treturn (\n\t\t<>\n\t\t\t{ shouldShowPartialSyncingControls && (\n\t\t\t\t<PartialSyncingControls { ...props } />\n\t\t\t) }\n\t\t\t{ shouldShowResetOverridesControl && (\n\t\t\t\t<ResetOverridesControl { ...props } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/with-partial-syncing-controls',\n\twithPartialSyncingControls\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;AACxE,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,WAAW,QAAQ,UAAU;AAC/C,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,MAAM;EACLC,sBAAsB;EACtBC,qBAAqB;EACrBC,aAAa;EACbC;AACD,CAAC,GAAGJ,MAAM,CAAEN,mBAAoB,CAAC;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMW,0BAA0B,GAAGV,0BAA0B,CAC1DW,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAMC,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CACnCN,gCACD,CAAC,CAACO,QAAQ,CAAEJ,KAAK,CAACK,IAAK,CAAC;EAExB,OACCC,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACP,SAAS;IAAA,GAAMC;EAAK,CAAI,CAAC,EACxBA,KAAK,CAACQ,UAAU,IAAIP,gBAAgB,IACrCK,aAAA,CAACG,6BAA6B;IAAA,GAAMT;EAAK,CAAI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