@wordpress/editor 14.0.1 → 14.0.3
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/components/document-tools/index.js +12 -3
- package/build/components/document-tools/index.js.map +1 -1
- package/build/components/editor-interface/index.js +2 -2
- package/build/components/editor-interface/index.js.map +1 -1
- package/build/components/entities-saved-states/entity-record-item.js +4 -12
- package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build/components/global-styles-provider/index.js +15 -67
- package/build/components/global-styles-provider/index.js.map +1 -1
- package/build/components/post-actions/actions.js +62 -13
- package/build/components/post-actions/actions.js.map +1 -1
- package/build/components/post-actions/index.js +4 -1
- package/build/components/post-actions/index.js.map +1 -1
- package/build/components/post-excerpt/index.js +2 -1
- package/build/components/post-excerpt/index.js.map +1 -1
- package/build/components/post-excerpt/panel.js +2 -1
- package/build/components/post-excerpt/panel.js.map +1 -1
- package/build/components/post-trash/index.js +1 -0
- package/build/components/post-trash/index.js.map +1 -1
- package/build/components/post-visibility/index.js +1 -0
- package/build/components/post-visibility/index.js.map +1 -1
- package/build/components/template-validation-notice/index.js +1 -0
- package/build/components/template-validation-notice/index.js.map +1 -1
- package/build/components/visual-editor/edit-template-blocks-notification.js +1 -0
- package/build/components/visual-editor/edit-template-blocks-notification.js.map +1 -1
- package/build/hooks/pattern-overrides.js +3 -2
- package/build/hooks/pattern-overrides.js.map +1 -1
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/store/private-actions.js +9 -5
- package/build/store/private-actions.js.map +1 -1
- package/build-module/components/document-tools/index.js +12 -3
- package/build-module/components/document-tools/index.js.map +1 -1
- package/build-module/components/editor-interface/index.js +2 -2
- package/build-module/components/editor-interface/index.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-record-item.js +6 -14
- package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build-module/components/global-styles-provider/index.js +16 -68
- package/build-module/components/global-styles-provider/index.js.map +1 -1
- package/build-module/components/post-actions/actions.js +63 -14
- package/build-module/components/post-actions/actions.js.map +1 -1
- package/build-module/components/post-actions/index.js +4 -1
- package/build-module/components/post-actions/index.js.map +1 -1
- package/build-module/components/post-excerpt/index.js +2 -1
- package/build-module/components/post-excerpt/index.js.map +1 -1
- package/build-module/components/post-excerpt/panel.js +2 -1
- package/build-module/components/post-excerpt/panel.js.map +1 -1
- package/build-module/components/post-trash/index.js +1 -0
- package/build-module/components/post-trash/index.js.map +1 -1
- package/build-module/components/post-visibility/index.js +1 -0
- package/build-module/components/post-visibility/index.js.map +1 -1
- package/build-module/components/template-validation-notice/index.js +1 -0
- package/build-module/components/template-validation-notice/index.js.map +1 -1
- package/build-module/components/visual-editor/edit-template-blocks-notification.js +1 -0
- package/build-module/components/visual-editor/edit-template-blocks-notification.js.map +1 -1
- package/build-module/hooks/pattern-overrides.js +3 -2
- package/build-module/hooks/pattern-overrides.js.map +1 -1
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/store/private-actions.js +9 -5
- package/build-module/store/private-actions.js.map +1 -1
- package/build-style/style-rtl.css +8 -16
- package/build-style/style.css +8 -16
- package/package.json +19 -19
- package/src/components/document-tools/index.js +13 -4
- package/src/components/editor-interface/index.js +12 -8
- package/src/components/entities-saved-states/entity-record-item.js +4 -14
- package/src/components/entities-saved-states/style.scss +0 -13
- package/src/components/global-styles-provider/index.js +19 -92
- package/src/components/post-actions/actions.js +105 -21
- package/src/components/post-actions/index.js +1 -1
- package/src/components/post-card-panel/style.scss +1 -0
- package/src/components/post-excerpt/index.js +4 -1
- package/src/components/post-excerpt/panel.js +2 -1
- package/src/components/post-publish-panel/style.scss +1 -1
- package/src/components/post-trash/index.js +1 -0
- package/src/components/post-url/style.scss +4 -0
- package/src/components/post-visibility/index.js +1 -0
- package/src/components/template-validation-notice/index.js +1 -0
- package/src/components/visual-editor/edit-template-blocks-notification.js +1 -0
- package/src/components/visual-editor/style.scss +2 -0
- package/src/hooks/pattern-overrides.js +4 -3
- package/src/lock-unlock.js +1 -1
- package/src/store/private-actions.js +54 -21
|
@@ -212,14 +212,18 @@ export default function EditorInterface( {
|
|
|
212
212
|
)
|
|
213
213
|
}
|
|
214
214
|
actions={
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
215
|
+
! isPreviewMode ? (
|
|
216
|
+
<SavePublishPanels
|
|
217
|
+
closeEntitiesSavedStates={ closeEntitiesSavedStates }
|
|
218
|
+
isEntitiesSavedStatesOpen={
|
|
219
|
+
entitiesSavedStatesCallback
|
|
220
|
+
}
|
|
221
|
+
setEntitiesSavedStatesCallback={
|
|
222
|
+
setEntitiesSavedStatesCallback
|
|
223
|
+
}
|
|
224
|
+
forceIsDirtyPublishPanel={ forceIsDirty }
|
|
225
|
+
/>
|
|
226
|
+
) : undefined
|
|
223
227
|
}
|
|
224
228
|
shortcuts={ {
|
|
225
229
|
previous: previousShortcut,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { CheckboxControl, PanelRow } from '@wordpress/components';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useSelect } from '@wordpress/data';
|
|
7
7
|
import { store as coreStore } from '@wordpress/core-data';
|
|
8
8
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
9
|
-
import { connection } from '@wordpress/icons';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Internal dependencies
|
|
@@ -60,18 +59,9 @@ export default function EntityRecordItem( { record, checked, onChange } ) {
|
|
|
60
59
|
/>
|
|
61
60
|
</PanelRow>
|
|
62
61
|
{ hasPostMetaChanges && (
|
|
63
|
-
<
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
className="entities-saved-states__connections-icon"
|
|
67
|
-
icon={ connection }
|
|
68
|
-
size={ 24 }
|
|
69
|
-
/>
|
|
70
|
-
<span className="entities-saved-states__bindings-text">
|
|
71
|
-
{ __( 'Post Meta.' ) }
|
|
72
|
-
</span>
|
|
73
|
-
</Flex>
|
|
74
|
-
</PanelRow>
|
|
62
|
+
<ul className="entities-saved-states__changes">
|
|
63
|
+
<li>{ __( 'Post Meta.' ) }</li>
|
|
64
|
+
</ul>
|
|
75
65
|
) }
|
|
76
66
|
</>
|
|
77
67
|
);
|
|
@@ -30,16 +30,3 @@
|
|
|
30
30
|
margin-bottom: $grid-unit-05;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
.entities-saved-states__post-meta {
|
|
35
|
-
margin-left: $grid-unit-30;
|
|
36
|
-
align-items: center;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.entities-saved-states__connections-icon {
|
|
40
|
-
flex-grow: 0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.entities-saved-states__bindings-text {
|
|
44
|
-
flex-grow: 1;
|
|
45
|
-
}
|
|
@@ -7,17 +7,15 @@ import { isPlainObject } from 'is-plain-object';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
import { registerBlockStyle, store as blocksStore } from '@wordpress/blocks';
|
|
11
10
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
12
11
|
import { store as coreStore } from '@wordpress/core-data';
|
|
13
12
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
14
|
-
import {
|
|
13
|
+
import { useMemo, useCallback } from '@wordpress/element';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Internal dependencies
|
|
18
17
|
*/
|
|
19
18
|
import { unlock } from '../../lock-unlock';
|
|
20
|
-
import setNestedValue from '../../utils/set-nested-value';
|
|
21
19
|
|
|
22
20
|
const { GlobalStylesContext, cleanEmptyObject } = unlock(
|
|
23
21
|
blockEditorPrivateApis
|
|
@@ -32,85 +30,6 @@ export function mergeBaseAndUserConfigs( base, user ) {
|
|
|
32
30
|
} );
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
/**
|
|
36
|
-
* Resolves shared block style variation definitions from the user origin
|
|
37
|
-
* under their respective block types and registers the block style if required.
|
|
38
|
-
*
|
|
39
|
-
* @param {Object} userConfig Current user origin global styles data.
|
|
40
|
-
* @return {Object} Updated global styles data.
|
|
41
|
-
*/
|
|
42
|
-
function useResolvedBlockStyleVariationsConfig( userConfig ) {
|
|
43
|
-
const { getBlockStyles } = useSelect( blocksStore );
|
|
44
|
-
const sharedVariations = userConfig?.styles?.blocks?.variations;
|
|
45
|
-
|
|
46
|
-
// Collect block style variation definitions to merge and unregistered
|
|
47
|
-
// block styles for automatic registration.
|
|
48
|
-
const [ userConfigToMerge, unregisteredStyles ] = useMemo( () => {
|
|
49
|
-
if ( ! sharedVariations ) {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const variationsConfigToMerge = {};
|
|
54
|
-
const unregisteredBlockStyles = [];
|
|
55
|
-
|
|
56
|
-
Object.entries( sharedVariations ).forEach(
|
|
57
|
-
( [ variationName, variation ] ) => {
|
|
58
|
-
if ( ! variation?.blockTypes?.length ) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
variation.blockTypes.forEach( ( blockName ) => {
|
|
63
|
-
const blockStyles = getBlockStyles( blockName );
|
|
64
|
-
const registeredBlockStyle = blockStyles.find(
|
|
65
|
-
( { name } ) => name === variationName
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
if ( ! registeredBlockStyle ) {
|
|
69
|
-
unregisteredBlockStyles.push( [
|
|
70
|
-
blockName,
|
|
71
|
-
{
|
|
72
|
-
name: variationName,
|
|
73
|
-
label: variationName,
|
|
74
|
-
},
|
|
75
|
-
] );
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const path = [
|
|
79
|
-
'styles',
|
|
80
|
-
'blocks',
|
|
81
|
-
blockName,
|
|
82
|
-
'variations',
|
|
83
|
-
variationName,
|
|
84
|
-
];
|
|
85
|
-
setNestedValue( variationsConfigToMerge, path, variation );
|
|
86
|
-
} );
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return [ variationsConfigToMerge, unregisteredBlockStyles ];
|
|
91
|
-
}, [ sharedVariations, getBlockStyles ] );
|
|
92
|
-
|
|
93
|
-
// Automatically register missing block styles from variations.
|
|
94
|
-
useEffect(
|
|
95
|
-
() =>
|
|
96
|
-
unregisteredStyles?.forEach( ( unregisteredStyle ) =>
|
|
97
|
-
registerBlockStyle( ...unregisteredStyle )
|
|
98
|
-
),
|
|
99
|
-
[ unregisteredStyles ]
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// Merge shared block style variation definitions into overall user config.
|
|
103
|
-
const updatedConfig = useMemo( () => {
|
|
104
|
-
if ( ! userConfigToMerge ) {
|
|
105
|
-
return userConfig;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return deepmerge( userConfigToMerge, userConfig );
|
|
109
|
-
}, [ userConfigToMerge, userConfig ] );
|
|
110
|
-
|
|
111
|
-
return updatedConfig;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
33
|
function useGlobalStylesUserConfig() {
|
|
115
34
|
const { globalStylesId, isReady, settings, styles, _links } = useSelect(
|
|
116
35
|
( select ) => {
|
|
@@ -163,7 +82,13 @@ function useGlobalStylesUserConfig() {
|
|
|
163
82
|
}, [ settings, styles, _links ] );
|
|
164
83
|
|
|
165
84
|
const setConfig = useCallback(
|
|
166
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Set the global styles config.
|
|
87
|
+
* @param {Function|Object} callbackOrObject If the callbackOrObject is a function, pass the current config to the callback so the consumer can merge values.
|
|
88
|
+
* Otherwise, overwrite the current config with the incoming object.
|
|
89
|
+
* @param {Object} options Options for editEntityRecord Core selector.
|
|
90
|
+
*/
|
|
91
|
+
( callbackOrObject, options = {} ) => {
|
|
167
92
|
const record = getEditedEntityRecord(
|
|
168
93
|
'root',
|
|
169
94
|
'globalStyles',
|
|
@@ -175,7 +100,11 @@ function useGlobalStylesUserConfig() {
|
|
|
175
100
|
settings: record?.settings ?? {},
|
|
176
101
|
_links: record?._links ?? {},
|
|
177
102
|
};
|
|
178
|
-
|
|
103
|
+
|
|
104
|
+
const updatedConfig =
|
|
105
|
+
typeof callbackOrObject === 'function'
|
|
106
|
+
? callbackOrObject( currentConfig )
|
|
107
|
+
: callbackOrObject;
|
|
179
108
|
|
|
180
109
|
editEntityRecord(
|
|
181
110
|
'root',
|
|
@@ -189,7 +118,7 @@ function useGlobalStylesUserConfig() {
|
|
|
189
118
|
options
|
|
190
119
|
);
|
|
191
120
|
},
|
|
192
|
-
[ globalStylesId ]
|
|
121
|
+
[ globalStylesId, editEntityRecord, getEditedEntityRecord ]
|
|
193
122
|
);
|
|
194
123
|
|
|
195
124
|
return [ isReady, config, setConfig ];
|
|
@@ -209,28 +138,26 @@ export function useGlobalStylesContext() {
|
|
|
209
138
|
const [ isUserConfigReady, userConfig, setUserConfig ] =
|
|
210
139
|
useGlobalStylesUserConfig();
|
|
211
140
|
const [ isBaseConfigReady, baseConfig ] = useGlobalStylesBaseConfig();
|
|
212
|
-
const userConfigWithVariations =
|
|
213
|
-
useResolvedBlockStyleVariationsConfig( userConfig );
|
|
214
141
|
|
|
215
142
|
const mergedConfig = useMemo( () => {
|
|
216
|
-
if ( ! baseConfig || !
|
|
143
|
+
if ( ! baseConfig || ! userConfig ) {
|
|
217
144
|
return {};
|
|
218
145
|
}
|
|
219
146
|
|
|
220
|
-
return mergeBaseAndUserConfigs( baseConfig,
|
|
221
|
-
}, [
|
|
147
|
+
return mergeBaseAndUserConfigs( baseConfig, userConfig );
|
|
148
|
+
}, [ userConfig, baseConfig ] );
|
|
222
149
|
|
|
223
150
|
const context = useMemo( () => {
|
|
224
151
|
return {
|
|
225
152
|
isReady: isUserConfigReady && isBaseConfigReady,
|
|
226
|
-
user:
|
|
153
|
+
user: userConfig,
|
|
227
154
|
base: baseConfig,
|
|
228
155
|
merged: mergedConfig,
|
|
229
156
|
setUserConfig,
|
|
230
157
|
};
|
|
231
158
|
}, [
|
|
232
159
|
mergedConfig,
|
|
233
|
-
|
|
160
|
+
userConfig,
|
|
234
161
|
baseConfig,
|
|
235
162
|
setUserConfig,
|
|
236
163
|
isUserConfigReady,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { external, trash, backup } from '@wordpress/icons';
|
|
5
5
|
import { addQueryArgs } from '@wordpress/url';
|
|
6
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
+
import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
|
|
7
7
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
8
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
9
|
import { __, _n, sprintf, _x } from '@wordpress/i18n';
|
|
@@ -155,6 +155,24 @@ const deletePostAction = {
|
|
|
155
155
|
},
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
function useCanUserEligibilityCheckPostType( capability, resource, action ) {
|
|
159
|
+
const registry = useRegistry();
|
|
160
|
+
return useMemo(
|
|
161
|
+
() => ( {
|
|
162
|
+
...action,
|
|
163
|
+
isEligible( item ) {
|
|
164
|
+
return (
|
|
165
|
+
action.isEligible( item ) &&
|
|
166
|
+
registry
|
|
167
|
+
.select( coreStore )
|
|
168
|
+
.canUser( capability, resource, item.id )
|
|
169
|
+
);
|
|
170
|
+
},
|
|
171
|
+
} ),
|
|
172
|
+
[ action, registry, capability, resource ]
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
158
176
|
const trashPostAction = {
|
|
159
177
|
id: 'move-to-trash',
|
|
160
178
|
label: __( 'Move to Trash' ),
|
|
@@ -323,12 +341,20 @@ const trashPostAction = {
|
|
|
323
341
|
},
|
|
324
342
|
};
|
|
325
343
|
|
|
326
|
-
function
|
|
344
|
+
function useTrashPostAction( resource ) {
|
|
345
|
+
return useCanUserEligibilityCheckPostType(
|
|
346
|
+
'delete',
|
|
347
|
+
resource,
|
|
348
|
+
trashPostAction
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function usePermanentlyDeletePostAction( resource ) {
|
|
327
353
|
const { createSuccessNotice, createErrorNotice } =
|
|
328
354
|
useDispatch( noticesStore );
|
|
329
355
|
const { deleteEntityRecord } = useDispatch( coreStore );
|
|
330
356
|
|
|
331
|
-
|
|
357
|
+
const permanentlyDeletePostAction = useMemo(
|
|
332
358
|
() => ( {
|
|
333
359
|
id: 'permanently-delete',
|
|
334
360
|
label: __( 'Permanently delete' ),
|
|
@@ -428,15 +454,20 @@ function usePermanentlyDeletePostAction() {
|
|
|
428
454
|
} ),
|
|
429
455
|
[ createSuccessNotice, createErrorNotice, deleteEntityRecord ]
|
|
430
456
|
);
|
|
457
|
+
return useCanUserEligibilityCheckPostType(
|
|
458
|
+
'delete',
|
|
459
|
+
resource,
|
|
460
|
+
permanentlyDeletePostAction
|
|
461
|
+
);
|
|
431
462
|
}
|
|
432
463
|
|
|
433
|
-
function useRestorePostAction() {
|
|
464
|
+
function useRestorePostAction( resource ) {
|
|
434
465
|
const { createSuccessNotice, createErrorNotice } =
|
|
435
466
|
useDispatch( noticesStore );
|
|
436
467
|
const { editEntityRecord, saveEditedEntityRecord } =
|
|
437
468
|
useDispatch( coreStore );
|
|
438
469
|
|
|
439
|
-
|
|
470
|
+
const restorePostAction = useMemo(
|
|
440
471
|
() => ( {
|
|
441
472
|
id: 'restore',
|
|
442
473
|
label: __( 'Restore' ),
|
|
@@ -562,6 +593,11 @@ function useRestorePostAction() {
|
|
|
562
593
|
saveEditedEntityRecord,
|
|
563
594
|
]
|
|
564
595
|
);
|
|
596
|
+
return useCanUserEligibilityCheckPostType(
|
|
597
|
+
'update',
|
|
598
|
+
resource,
|
|
599
|
+
restorePostAction
|
|
600
|
+
);
|
|
565
601
|
}
|
|
566
602
|
|
|
567
603
|
const viewPostAction = {
|
|
@@ -583,6 +619,7 @@ const viewPostAction = {
|
|
|
583
619
|
|
|
584
620
|
const postRevisionsAction = {
|
|
585
621
|
id: 'view-post-revisions',
|
|
622
|
+
context: 'list',
|
|
586
623
|
label( items ) {
|
|
587
624
|
const revisionsCount =
|
|
588
625
|
items[ 0 ]._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
|
|
@@ -722,6 +759,14 @@ const renamePostAction = {
|
|
|
722
759
|
},
|
|
723
760
|
};
|
|
724
761
|
|
|
762
|
+
function useRenamePostAction( resource ) {
|
|
763
|
+
return useCanUserEligibilityCheckPostType(
|
|
764
|
+
'update',
|
|
765
|
+
resource,
|
|
766
|
+
renamePostAction
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
725
770
|
const duplicatePostAction = {
|
|
726
771
|
id: 'duplicate-post',
|
|
727
772
|
label: _x( 'Duplicate', 'action label' ),
|
|
@@ -783,7 +828,7 @@ const duplicatePostAction = {
|
|
|
783
828
|
sprintf(
|
|
784
829
|
// translators: %s: Title of the created template e.g: "Category".
|
|
785
830
|
__( '"%s" successfully created.' ),
|
|
786
|
-
newItem.title?.rendered || title
|
|
831
|
+
decodeEntities( newItem.title?.rendered || title )
|
|
787
832
|
),
|
|
788
833
|
{
|
|
789
834
|
id: 'duplicate-post-action',
|
|
@@ -1029,19 +1074,33 @@ export const duplicateTemplatePartAction = {
|
|
|
1029
1074
|
},
|
|
1030
1075
|
};
|
|
1031
1076
|
|
|
1032
|
-
export function usePostActions( postType, onActionPerformed ) {
|
|
1033
|
-
const {
|
|
1077
|
+
export function usePostActions( { postType, onActionPerformed, context } ) {
|
|
1078
|
+
const {
|
|
1079
|
+
postTypeObject,
|
|
1080
|
+
resource,
|
|
1081
|
+
cachedCanUserResolvers,
|
|
1082
|
+
userCanCreatePostType,
|
|
1083
|
+
} = useSelect(
|
|
1034
1084
|
( select ) => {
|
|
1035
|
-
const { getPostType } =
|
|
1085
|
+
const { getPostType, getCachedResolvers, canUser } =
|
|
1086
|
+
select( coreStore );
|
|
1087
|
+
const _postTypeObject = getPostType( postType );
|
|
1088
|
+
const _resource = _postTypeObject?.rest_base || '';
|
|
1036
1089
|
return {
|
|
1037
|
-
postTypeObject:
|
|
1090
|
+
postTypeObject: _postTypeObject,
|
|
1091
|
+
resource: _resource,
|
|
1092
|
+
cachedCanUserResolvers: getCachedResolvers()?.canUser,
|
|
1093
|
+
userCanCreatePostType: canUser( 'create', _resource ),
|
|
1038
1094
|
};
|
|
1039
1095
|
},
|
|
1040
1096
|
[ postType ]
|
|
1041
1097
|
);
|
|
1042
1098
|
|
|
1043
|
-
const
|
|
1044
|
-
const
|
|
1099
|
+
const trashPostActionForPostType = useTrashPostAction( resource );
|
|
1100
|
+
const permanentlyDeletePostActionForPostType =
|
|
1101
|
+
usePermanentlyDeletePostAction( resource );
|
|
1102
|
+
const renamePostActionForPostType = useRenamePostAction( resource );
|
|
1103
|
+
const restorePostActionForPostType = useRestorePostAction( resource );
|
|
1045
1104
|
const isTemplateOrTemplatePart = [
|
|
1046
1105
|
TEMPLATE_POST_TYPE,
|
|
1047
1106
|
TEMPLATE_PART_POST_TYPE,
|
|
@@ -1055,7 +1114,7 @@ export function usePostActions( postType, onActionPerformed ) {
|
|
|
1055
1114
|
return [];
|
|
1056
1115
|
}
|
|
1057
1116
|
|
|
1058
|
-
|
|
1117
|
+
let actions = [
|
|
1059
1118
|
postTypeObject?.viewable && viewPostAction,
|
|
1060
1119
|
supportsRevisions && postRevisionsAction,
|
|
1061
1120
|
globalThis.IS_GUTENBERG_PLUGIN
|
|
@@ -1063,16 +1122,33 @@ export function usePostActions( postType, onActionPerformed ) {
|
|
|
1063
1122
|
! isPattern &&
|
|
1064
1123
|
duplicatePostAction
|
|
1065
1124
|
: false,
|
|
1066
|
-
isTemplateOrTemplatePart &&
|
|
1067
|
-
|
|
1068
|
-
|
|
1125
|
+
isTemplateOrTemplatePart &&
|
|
1126
|
+
userCanCreatePostType &&
|
|
1127
|
+
duplicateTemplatePartAction,
|
|
1128
|
+
isPattern && userCanCreatePostType && duplicatePatternAction,
|
|
1129
|
+
supportsTitle && renamePostActionForPostType,
|
|
1069
1130
|
isPattern && exportPatternAsJSONAction,
|
|
1070
|
-
isTemplateOrTemplatePart
|
|
1131
|
+
isTemplateOrTemplatePart
|
|
1132
|
+
? resetTemplateAction
|
|
1133
|
+
: restorePostActionForPostType,
|
|
1071
1134
|
isTemplateOrTemplatePart || isPattern
|
|
1072
1135
|
? deletePostAction
|
|
1073
|
-
:
|
|
1074
|
-
! isTemplateOrTemplatePart &&
|
|
1136
|
+
: trashPostActionForPostType,
|
|
1137
|
+
! isTemplateOrTemplatePart &&
|
|
1138
|
+
permanentlyDeletePostActionForPostType,
|
|
1075
1139
|
].filter( Boolean );
|
|
1140
|
+
// Filter actions based on provided context. If not provided
|
|
1141
|
+
// all actions are returned. We'll have a single entry for getting the actions
|
|
1142
|
+
// and the consumer should provide the context to filter the actions, if needed.
|
|
1143
|
+
// Actions should also provide the `context` they support, if it's specific, to
|
|
1144
|
+
// compare with the provided context to get all the actions.
|
|
1145
|
+
// Right now the only supported context is `list`.
|
|
1146
|
+
actions = actions.filter( ( action ) => {
|
|
1147
|
+
if ( ! action.context ) {
|
|
1148
|
+
return true;
|
|
1149
|
+
}
|
|
1150
|
+
return action.context === context;
|
|
1151
|
+
} );
|
|
1076
1152
|
|
|
1077
1153
|
if ( onActionPerformed ) {
|
|
1078
1154
|
for ( let i = 0; i < actions.length; ++i ) {
|
|
@@ -1116,15 +1192,23 @@ export function usePostActions( postType, onActionPerformed ) {
|
|
|
1116
1192
|
}
|
|
1117
1193
|
|
|
1118
1194
|
return actions;
|
|
1195
|
+
// We are making this use memo depend on cachedCanUserResolvers as a way to make the component using this hook re-render
|
|
1196
|
+
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
|
|
1197
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1119
1198
|
}, [
|
|
1120
1199
|
isTemplateOrTemplatePart,
|
|
1121
1200
|
isPattern,
|
|
1122
1201
|
postTypeObject?.viewable,
|
|
1123
|
-
|
|
1124
|
-
|
|
1202
|
+
permanentlyDeletePostActionForPostType,
|
|
1203
|
+
restorePostActionForPostType,
|
|
1204
|
+
renamePostActionForPostType,
|
|
1205
|
+
trashPostActionForPostType,
|
|
1125
1206
|
onActionPerformed,
|
|
1126
1207
|
isLoaded,
|
|
1127
1208
|
supportsRevisions,
|
|
1128
1209
|
supportsTitle,
|
|
1210
|
+
context,
|
|
1211
|
+
userCanCreatePostType,
|
|
1212
|
+
cachedCanUserResolvers,
|
|
1129
1213
|
] );
|
|
1130
1214
|
}
|
|
@@ -42,7 +42,7 @@ export default function PostActions( { onActionPerformed, buttonProps } ) {
|
|
|
42
42
|
postType: _postType,
|
|
43
43
|
};
|
|
44
44
|
}, [] );
|
|
45
|
-
const allActions = usePostActions( postType, onActionPerformed );
|
|
45
|
+
const allActions = usePostActions( { postType, onActionPerformed } );
|
|
46
46
|
|
|
47
47
|
const actions = useMemo( () => {
|
|
48
48
|
return allActions.filter( ( action ) => {
|
|
@@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
5
5
|
import { ExternalLink, TextareaControl } from '@wordpress/components';
|
|
6
6
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
7
|
import { useState } from '@wordpress/element';
|
|
8
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
@@ -52,7 +53,9 @@ export default function PostExcerpt( {
|
|
|
52
53
|
[]
|
|
53
54
|
);
|
|
54
55
|
const { editPost } = useDispatch( editorStore );
|
|
55
|
-
const [ localExcerpt, setLocalExcerpt ] = useState(
|
|
56
|
+
const [ localExcerpt, setLocalExcerpt ] = useState(
|
|
57
|
+
decodeEntities( excerpt )
|
|
58
|
+
);
|
|
56
59
|
const updatePost = ( value ) => {
|
|
57
60
|
editPost( { [ usedAttribute ]: value } );
|
|
58
61
|
};
|
|
@@ -13,6 +13,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
13
13
|
import { useMemo, useState } from '@wordpress/element';
|
|
14
14
|
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
|
|
15
15
|
import { store as coreStore } from '@wordpress/core-data';
|
|
16
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Internal dependencies
|
|
@@ -173,7 +174,7 @@ function PrivateExcerpt() {
|
|
|
173
174
|
}
|
|
174
175
|
const excerptText = !! excerpt && (
|
|
175
176
|
<Text align="left" numberOfLines={ 4 } truncate>
|
|
176
|
-
{ excerpt }
|
|
177
|
+
{ decodeEntities( excerpt ) }
|
|
177
178
|
</Text>
|
|
178
179
|
);
|
|
179
180
|
if ( ! allowEditing ) {
|
|
@@ -133,6 +133,7 @@ export default function PostVisibility( { onClose } ) {
|
|
|
133
133
|
onConfirm={ confirmPrivate }
|
|
134
134
|
onCancel={ handleDialogCancel }
|
|
135
135
|
confirmButtonText={ __( 'Publish' ) }
|
|
136
|
+
size="medium"
|
|
136
137
|
>
|
|
137
138
|
{ __( 'Would you like to privately publish this post now?' ) }
|
|
138
139
|
</ConfirmDialog>
|
|
@@ -80,6 +80,7 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
|
|
|
80
80
|
} );
|
|
81
81
|
} }
|
|
82
82
|
onCancel={ () => setIsDialogOpen( false ) }
|
|
83
|
+
size="medium"
|
|
83
84
|
>
|
|
84
85
|
{ __(
|
|
85
86
|
'You’ve tried to select a block that is part of a template, which may be used on other posts and pages. Would you like to edit the template?'
|
|
@@ -17,6 +17,7 @@ import { unlock } from '../lock-unlock';
|
|
|
17
17
|
const {
|
|
18
18
|
PatternOverridesControls,
|
|
19
19
|
ResetOverridesControl,
|
|
20
|
+
PatternOverridesBlockControls,
|
|
20
21
|
PATTERN_TYPES,
|
|
21
22
|
PARTIAL_SYNCING_SUPPORTED_BLOCKS,
|
|
22
23
|
PATTERN_SYNC_TYPES,
|
|
@@ -33,9 +34,8 @@ const {
|
|
|
33
34
|
*/
|
|
34
35
|
const withPatternOverrideControls = createHigherOrderComponent(
|
|
35
36
|
( BlockEdit ) => ( props ) => {
|
|
36
|
-
const isSupportedBlock =
|
|
37
|
-
PARTIAL_SYNCING_SUPPORTED_BLOCKS
|
|
38
|
-
).includes( props.name );
|
|
37
|
+
const isSupportedBlock =
|
|
38
|
+
!! PARTIAL_SYNCING_SUPPORTED_BLOCKS[ props.name ];
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
41
|
<>
|
|
@@ -43,6 +43,7 @@ const withPatternOverrideControls = createHigherOrderComponent(
|
|
|
43
43
|
{ props.isSelected && isSupportedBlock && (
|
|
44
44
|
<ControlsWithStoreSubscription { ...props } />
|
|
45
45
|
) }
|
|
46
|
+
{ isSupportedBlock && <PatternOverridesBlockControls /> }
|
|
46
47
|
</>
|
|
47
48
|
);
|
|
48
49
|
}
|
package/src/lock-unlock.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
5
|
export const { lock, unlock } =
|
|
6
6
|
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
7
|
-
'I
|
|
7
|
+
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
|
|
8
8
|
'@wordpress/editor'
|
|
9
9
|
);
|