@wordpress/editor 14.0.2 → 14.0.4
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/pattern-overrides.js +8 -5
- package/build/bindings/pattern-overrides.js.map +1 -1
- package/build/components/editor/index.js +5 -0
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor-interface/index.js +3 -2
- package/build/components/editor-interface/index.js.map +1 -1
- package/build/components/global-styles-provider/index.js +6 -65
- 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/save-publish-panels/index.js +30 -16
- package/build/components/save-publish-panels/index.js.map +1 -1
- package/build/hooks/pattern-overrides.js +3 -3
- package/build/hooks/pattern-overrides.js.map +1 -1
- package/build/store/private-actions.js +9 -5
- package/build/store/private-actions.js.map +1 -1
- package/build-module/bindings/pattern-overrides.js +8 -5
- package/build-module/bindings/pattern-overrides.js.map +1 -1
- package/build-module/components/editor/index.js +5 -0
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor-interface/index.js +3 -2
- package/build-module/components/editor-interface/index.js.map +1 -1
- package/build-module/components/global-styles-provider/index.js +7 -66
- 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/save-publish-panels/index.js +30 -16
- package/build-module/components/save-publish-panels/index.js.map +1 -1
- package/build-module/hooks/pattern-overrides.js +4 -2
- package/build-module/hooks/pattern-overrides.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 +19 -2
- package/build-style/style.css +19 -2
- package/package.json +14 -14
- package/src/bindings/pattern-overrides.js +9 -10
- package/src/components/editor/index.js +6 -0
- package/src/components/editor-interface/index.js +17 -8
- package/src/components/global-styles-provider/index.js +7 -90
- package/src/components/post-actions/actions.js +109 -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-featured-image/style.scss +15 -0
- package/src/components/post-publish-panel/style.scss +1 -1
- package/src/components/post-url/style.scss +4 -0
- package/src/components/save-publish-panels/index.js +33 -23
- package/src/components/visual-editor/style.scss +3 -1
- package/src/hooks/pattern-overrides.js +6 -4
- package/src/store/private-actions.js +54 -21
|
@@ -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
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
20
|
const {
|
|
23
21
|
GlobalStylesContext,
|
|
@@ -31,62 +29,6 @@ export function mergeBaseAndUserConfigs(base, user) {
|
|
|
31
29
|
isMergeableObject: isPlainObject
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
|
-
|
|
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 {
|
|
44
|
-
getBlockStyles
|
|
45
|
-
} = useSelect(blocksStore);
|
|
46
|
-
const sharedVariations = userConfig?.styles?.blocks?.variations;
|
|
47
|
-
|
|
48
|
-
// Collect block style variation definitions to merge and unregistered
|
|
49
|
-
// block styles for automatic registration.
|
|
50
|
-
const [userConfigToMerge, unregisteredStyles] = useMemo(() => {
|
|
51
|
-
if (!sharedVariations) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
const variationsConfigToMerge = {};
|
|
55
|
-
const unregisteredBlockStyles = [];
|
|
56
|
-
Object.entries(sharedVariations).forEach(([variationName, variation]) => {
|
|
57
|
-
if (!variation?.blockTypes?.length) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
variation.blockTypes.forEach(blockName => {
|
|
61
|
-
const blockStyles = getBlockStyles(blockName);
|
|
62
|
-
const registeredBlockStyle = blockStyles.find(({
|
|
63
|
-
name
|
|
64
|
-
}) => name === variationName);
|
|
65
|
-
if (!registeredBlockStyle) {
|
|
66
|
-
unregisteredBlockStyles.push([blockName, {
|
|
67
|
-
name: variationName,
|
|
68
|
-
label: variationName
|
|
69
|
-
}]);
|
|
70
|
-
}
|
|
71
|
-
const path = ['styles', 'blocks', blockName, 'variations', variationName];
|
|
72
|
-
setNestedValue(variationsConfigToMerge, path, variation);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
return [variationsConfigToMerge, unregisteredBlockStyles];
|
|
76
|
-
}, [sharedVariations, getBlockStyles]);
|
|
77
|
-
|
|
78
|
-
// Automatically register missing block styles from variations.
|
|
79
|
-
useEffect(() => unregisteredStyles?.forEach(unregisteredStyle => registerBlockStyle(...unregisteredStyle)), [unregisteredStyles]);
|
|
80
|
-
|
|
81
|
-
// Merge shared block style variation definitions into overall user config.
|
|
82
|
-
const updatedConfig = useMemo(() => {
|
|
83
|
-
if (!userConfigToMerge) {
|
|
84
|
-
return userConfig;
|
|
85
|
-
}
|
|
86
|
-
return deepmerge(userConfigToMerge, userConfig);
|
|
87
|
-
}, [userConfigToMerge, userConfig]);
|
|
88
|
-
return updatedConfig;
|
|
89
|
-
}
|
|
90
32
|
function useGlobalStylesUserConfig() {
|
|
91
33
|
const {
|
|
92
34
|
globalStylesId,
|
|
@@ -147,7 +89,7 @@ function useGlobalStylesUserConfig() {
|
|
|
147
89
|
settings: cleanEmptyObject(updatedConfig.settings) || {},
|
|
148
90
|
_links: cleanEmptyObject(updatedConfig._links) || {}
|
|
149
91
|
}, options);
|
|
150
|
-
}, [globalStylesId]);
|
|
92
|
+
}, [globalStylesId, editEntityRecord, getEditedEntityRecord]);
|
|
151
93
|
return [isReady, config, setConfig];
|
|
152
94
|
}
|
|
153
95
|
function useGlobalStylesBaseConfig() {
|
|
@@ -159,22 +101,21 @@ function useGlobalStylesBaseConfig() {
|
|
|
159
101
|
export function useGlobalStylesContext() {
|
|
160
102
|
const [isUserConfigReady, userConfig, setUserConfig] = useGlobalStylesUserConfig();
|
|
161
103
|
const [isBaseConfigReady, baseConfig] = useGlobalStylesBaseConfig();
|
|
162
|
-
const userConfigWithVariations = useResolvedBlockStyleVariationsConfig(userConfig);
|
|
163
104
|
const mergedConfig = useMemo(() => {
|
|
164
|
-
if (!baseConfig || !
|
|
105
|
+
if (!baseConfig || !userConfig) {
|
|
165
106
|
return {};
|
|
166
107
|
}
|
|
167
|
-
return mergeBaseAndUserConfigs(baseConfig,
|
|
168
|
-
}, [
|
|
108
|
+
return mergeBaseAndUserConfigs(baseConfig, userConfig);
|
|
109
|
+
}, [userConfig, baseConfig]);
|
|
169
110
|
const context = useMemo(() => {
|
|
170
111
|
return {
|
|
171
112
|
isReady: isUserConfigReady && isBaseConfigReady,
|
|
172
|
-
user:
|
|
113
|
+
user: userConfig,
|
|
173
114
|
base: baseConfig,
|
|
174
115
|
merged: mergedConfig,
|
|
175
116
|
setUserConfig
|
|
176
117
|
};
|
|
177
|
-
}, [mergedConfig,
|
|
118
|
+
}, [mergedConfig, userConfig, baseConfig, setUserConfig, isUserConfigReady, isBaseConfigReady]);
|
|
178
119
|
return context;
|
|
179
120
|
}
|
|
180
121
|
export function GlobalStylesProvider({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["deepmerge","isPlainObject","registerBlockStyle","store","blocksStore","privateApis","blockEditorPrivateApis","coreStore","useSelect","useDispatch","useEffect","useMemo","useCallback","unlock","setNestedValue","jsx","_jsx","GlobalStylesContext","cleanEmptyObject","mergeBaseAndUserConfigs","base","user","isMergeableObject","useResolvedBlockStyleVariationsConfig","userConfig","getBlockStyles","sharedVariations","styles","blocks","variations","userConfigToMerge","unregisteredStyles","variationsConfigToMerge","unregisteredBlockStyles","Object","entries","forEach","variationName","variation","blockTypes","length","blockName","blockStyles","registeredBlockStyle","find","name","push","label","path","unregisteredStyle","updatedConfig","useGlobalStylesUserConfig","globalStylesId","isReady","settings","_links","select","getEditedEntityRecord","hasFinishedResolution","_globalStylesId","__experimentalGetCurrentGlobalStylesId","record","undefined","hasResolved","editEntityRecord","config","setConfig","callbackOrObject","options","_record$styles","_record$settings","_record$_links","currentConfig","useGlobalStylesBaseConfig","baseConfig","__experimentalGetCurrentThemeBaseGlobalStyles","useGlobalStylesContext","isUserConfigReady","setUserConfig","isBaseConfigReady","userConfigWithVariations","mergedConfig","context","merged","GlobalStylesProvider","children","Provider","value"],"sources":["@wordpress/editor/src/components/global-styles-provider/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepmerge from 'deepmerge';\nimport { isPlainObject } from 'is-plain-object';\n\n/**\n * WordPress dependencies\n */\nimport { registerBlockStyle, store as blocksStore } from '@wordpress/blocks';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useMemo, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport setNestedValue from '../../utils/set-nested-value';\n\nconst { GlobalStylesContext, cleanEmptyObject } = unlock(\n\tblockEditorPrivateApis\n);\n\nexport function mergeBaseAndUserConfigs( base, user ) {\n\treturn deepmerge( base, user, {\n\t\t// We only pass as arrays the presets,\n\t\t// in which case we want the new array of values\n\t\t// to override the old array (no merging).\n\t\tisMergeableObject: isPlainObject,\n\t} );\n}\n\n/**\n * Resolves shared block style variation definitions from the user origin\n * under their respective block types and registers the block style if required.\n *\n * @param {Object} userConfig Current user origin global styles data.\n * @return {Object} Updated global styles data.\n */\nfunction useResolvedBlockStyleVariationsConfig( userConfig ) {\n\tconst { getBlockStyles } = useSelect( blocksStore );\n\tconst sharedVariations = userConfig?.styles?.blocks?.variations;\n\n\t// Collect block style variation definitions to merge and unregistered\n\t// block styles for automatic registration.\n\tconst [ userConfigToMerge, unregisteredStyles ] = useMemo( () => {\n\t\tif ( ! sharedVariations ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst variationsConfigToMerge = {};\n\t\tconst unregisteredBlockStyles = [];\n\n\t\tObject.entries( sharedVariations ).forEach(\n\t\t\t( [ variationName, variation ] ) => {\n\t\t\t\tif ( ! variation?.blockTypes?.length ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tvariation.blockTypes.forEach( ( blockName ) => {\n\t\t\t\t\tconst blockStyles = getBlockStyles( blockName );\n\t\t\t\t\tconst registeredBlockStyle = blockStyles.find(\n\t\t\t\t\t\t( { name } ) => name === variationName\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( ! registeredBlockStyle ) {\n\t\t\t\t\t\tunregisteredBlockStyles.push( [\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: variationName,\n\t\t\t\t\t\t\t\tlabel: variationName,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t] );\n\t\t\t\t\t}\n\n\t\t\t\t\tconst path = [\n\t\t\t\t\t\t'styles',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t'variations',\n\t\t\t\t\t\tvariationName,\n\t\t\t\t\t];\n\t\t\t\t\tsetNestedValue( variationsConfigToMerge, path, variation );\n\t\t\t\t} );\n\t\t\t}\n\t\t);\n\n\t\treturn [ variationsConfigToMerge, unregisteredBlockStyles ];\n\t}, [ sharedVariations, getBlockStyles ] );\n\n\t// Automatically register missing block styles from variations.\n\tuseEffect(\n\t\t() =>\n\t\t\tunregisteredStyles?.forEach( ( unregisteredStyle ) =>\n\t\t\t\tregisterBlockStyle( ...unregisteredStyle )\n\t\t\t),\n\t\t[ unregisteredStyles ]\n\t);\n\n\t// Merge shared block style variation definitions into overall user config.\n\tconst updatedConfig = useMemo( () => {\n\t\tif ( ! userConfigToMerge ) {\n\t\t\treturn userConfig;\n\t\t}\n\n\t\treturn deepmerge( userConfigToMerge, userConfig );\n\t}, [ userConfigToMerge, userConfig ] );\n\n\treturn updatedConfig;\n}\n\nfunction useGlobalStylesUserConfig() {\n\tconst { globalStylesId, isReady, settings, styles, _links } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst _globalStylesId =\n\t\t\t\tselect( coreStore ).__experimentalGetCurrentGlobalStylesId();\n\t\t\tconst record = _globalStylesId\n\t\t\t\t? getEditedEntityRecord(\n\t\t\t\t\t\t'root',\n\t\t\t\t\t\t'globalStyles',\n\t\t\t\t\t\t_globalStylesId\n\t\t\t\t )\n\t\t\t\t: undefined;\n\n\t\t\tlet hasResolved = false;\n\t\t\tif (\n\t\t\t\thasFinishedResolution(\n\t\t\t\t\t'__experimentalGetCurrentGlobalStylesId'\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\thasResolved = _globalStylesId\n\t\t\t\t\t? hasFinishedResolution( 'getEditedEntityRecord', [\n\t\t\t\t\t\t\t'root',\n\t\t\t\t\t\t\t'globalStyles',\n\t\t\t\t\t\t\t_globalStylesId,\n\t\t\t\t\t ] )\n\t\t\t\t\t: true;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tglobalStylesId: _globalStylesId,\n\t\t\t\tisReady: hasResolved,\n\t\t\t\tsettings: record?.settings,\n\t\t\t\tstyles: record?.styles,\n\t\t\t\t_links: record?._links,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { getEditedEntityRecord } = useSelect( coreStore );\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\tconst config = useMemo( () => {\n\t\treturn {\n\t\t\tsettings: settings ?? {},\n\t\t\tstyles: styles ?? {},\n\t\t\t_links: _links ?? {},\n\t\t};\n\t}, [ settings, styles, _links ] );\n\n\tconst setConfig = useCallback(\n\t\t/**\n\t\t * Set the global styles config.\n\t\t * @param {Function|Object} callbackOrObject If the callbackOrObject is a function, pass the current config to the callback so the consumer can merge values.\n\t\t * Otherwise, overwrite the current config with the incoming object.\n\t\t * @param {Object} options Options for editEntityRecord Core selector.\n\t\t */\n\t\t( callbackOrObject, options = {} ) => {\n\t\t\tconst record = getEditedEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'globalStyles',\n\t\t\t\tglobalStylesId\n\t\t\t);\n\n\t\t\tconst currentConfig = {\n\t\t\t\tstyles: record?.styles ?? {},\n\t\t\t\tsettings: record?.settings ?? {},\n\t\t\t\t_links: record?._links ?? {},\n\t\t\t};\n\n\t\t\tconst updatedConfig =\n\t\t\t\ttypeof callbackOrObject === 'function'\n\t\t\t\t\t? callbackOrObject( currentConfig )\n\t\t\t\t\t: callbackOrObject;\n\n\t\t\teditEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'globalStyles',\n\t\t\t\tglobalStylesId,\n\t\t\t\t{\n\t\t\t\t\tstyles: cleanEmptyObject( updatedConfig.styles ) || {},\n\t\t\t\t\tsettings: cleanEmptyObject( updatedConfig.settings ) || {},\n\t\t\t\t\t_links: cleanEmptyObject( updatedConfig._links ) || {},\n\t\t\t\t},\n\t\t\t\toptions\n\t\t\t);\n\t\t},\n\t\t[ globalStylesId ]\n\t);\n\n\treturn [ isReady, config, setConfig ];\n}\n\nfunction useGlobalStylesBaseConfig() {\n\tconst baseConfig = useSelect( ( select ) => {\n\t\treturn select(\n\t\t\tcoreStore\n\t\t).__experimentalGetCurrentThemeBaseGlobalStyles();\n\t}, [] );\n\n\treturn [ !! baseConfig, baseConfig ];\n}\n\nexport function useGlobalStylesContext() {\n\tconst [ isUserConfigReady, userConfig, setUserConfig ] =\n\t\tuseGlobalStylesUserConfig();\n\tconst [ isBaseConfigReady, baseConfig ] = useGlobalStylesBaseConfig();\n\tconst userConfigWithVariations =\n\t\tuseResolvedBlockStyleVariationsConfig( userConfig );\n\n\tconst mergedConfig = useMemo( () => {\n\t\tif ( ! baseConfig || ! userConfigWithVariations ) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn mergeBaseAndUserConfigs( baseConfig, userConfigWithVariations );\n\t}, [ userConfigWithVariations, baseConfig ] );\n\n\tconst context = useMemo( () => {\n\t\treturn {\n\t\t\tisReady: isUserConfigReady && isBaseConfigReady,\n\t\t\tuser: userConfigWithVariations,\n\t\t\tbase: baseConfig,\n\t\t\tmerged: mergedConfig,\n\t\t\tsetUserConfig,\n\t\t};\n\t}, [\n\t\tmergedConfig,\n\t\tuserConfigWithVariations,\n\t\tbaseConfig,\n\t\tsetUserConfig,\n\t\tisUserConfigReady,\n\t\tisBaseConfigReady,\n\t] );\n\n\treturn context;\n}\n\nexport function GlobalStylesProvider( { children } ) {\n\tconst context = useGlobalStylesContext();\n\tif ( ! context.isReady ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<GlobalStylesContext.Provider value={ context }>\n\t\t\t{ children }\n\t\t</GlobalStylesContext.Provider>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;AACjC,SAASC,aAAa,QAAQ,iBAAiB;;AAE/C;AACA;AACA;AACA,SAASC,kBAAkB,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AAC5E,SAASC,WAAW,IAAIC,sBAAsB,QAAQ,yBAAyB;AAC/E,SAASH,KAAK,IAAII,SAAS,QAAQ,sBAAsB;AACzD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,SAAS,EAAEC,OAAO,EAAEC,WAAW,QAAQ,oBAAoB;;AAEpE;AACA;AACA;AACA,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,cAAc,MAAM,8BAA8B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE1D,MAAM;EAAEC,mBAAmB;EAAEC;AAAiB,CAAC,GAAGL,MAAM,CACvDP,sBACD,CAAC;AAED,OAAO,SAASa,uBAAuBA,CAAEC,IAAI,EAAEC,IAAI,EAAG;EACrD,OAAOrB,SAAS,CAAEoB,IAAI,EAAEC,IAAI,EAAE;IAC7B;IACA;IACA;IACAC,iBAAiB,EAAErB;EACpB,CAAE,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASsB,qCAAqCA,CAAEC,UAAU,EAAG;EAC5D,MAAM;IAAEC;EAAe,CAAC,GAAGjB,SAAS,CAAEJ,WAAY,CAAC;EACnD,MAAMsB,gBAAgB,GAAGF,UAAU,EAAEG,MAAM,EAAEC,MAAM,EAAEC,UAAU;;EAE/D;EACA;EACA,MAAM,CAAEC,iBAAiB,EAAEC,kBAAkB,CAAE,GAAGpB,OAAO,CAAE,MAAM;I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C;EAEH,OAAOG,OAAO;AACf;AAEA,OAAO,SAASE,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACpD,MAAMH,OAAO,GAAGN,sBAAsB,CAAC,CAAC;EACxC,IAAK,CAAEM,OAAO,CAAC7B,OAAO,EAAG;IACxB,OAAO,IAAI;EACZ;EAEA,oBACCrC,IAAA,CAACC,mBAAmB,CAACqE,QAAQ;IAACC,KAAK,EAAGL,OAAS;IAAAG,QAAA,EAC5CA;EAAQ,CACmB,CAAC;AAEjC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["deepmerge","isPlainObject","privateApis","blockEditorPrivateApis","store","coreStore","useSelect","useDispatch","useMemo","useCallback","unlock","jsx","_jsx","GlobalStylesContext","cleanEmptyObject","mergeBaseAndUserConfigs","base","user","isMergeableObject","useGlobalStylesUserConfig","globalStylesId","isReady","settings","styles","_links","select","getEditedEntityRecord","hasFinishedResolution","_globalStylesId","__experimentalGetCurrentGlobalStylesId","record","undefined","hasResolved","editEntityRecord","config","setConfig","callbackOrObject","options","_record$styles","_record$settings","_record$_links","currentConfig","updatedConfig","useGlobalStylesBaseConfig","baseConfig","__experimentalGetCurrentThemeBaseGlobalStyles","useGlobalStylesContext","isUserConfigReady","userConfig","setUserConfig","isBaseConfigReady","mergedConfig","context","merged","GlobalStylesProvider","children","Provider","value"],"sources":["@wordpress/editor/src/components/global-styles-provider/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepmerge from 'deepmerge';\nimport { isPlainObject } from 'is-plain-object';\n\n/**\n * WordPress dependencies\n */\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useMemo, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { GlobalStylesContext, cleanEmptyObject } = unlock(\n\tblockEditorPrivateApis\n);\n\nexport function mergeBaseAndUserConfigs( base, user ) {\n\treturn deepmerge( base, user, {\n\t\t// We only pass as arrays the presets,\n\t\t// in which case we want the new array of values\n\t\t// to override the old array (no merging).\n\t\tisMergeableObject: isPlainObject,\n\t} );\n}\n\nfunction useGlobalStylesUserConfig() {\n\tconst { globalStylesId, isReady, settings, styles, _links } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst _globalStylesId =\n\t\t\t\tselect( coreStore ).__experimentalGetCurrentGlobalStylesId();\n\t\t\tconst record = _globalStylesId\n\t\t\t\t? getEditedEntityRecord(\n\t\t\t\t\t\t'root',\n\t\t\t\t\t\t'globalStyles',\n\t\t\t\t\t\t_globalStylesId\n\t\t\t\t )\n\t\t\t\t: undefined;\n\n\t\t\tlet hasResolved = false;\n\t\t\tif (\n\t\t\t\thasFinishedResolution(\n\t\t\t\t\t'__experimentalGetCurrentGlobalStylesId'\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\thasResolved = _globalStylesId\n\t\t\t\t\t? hasFinishedResolution( 'getEditedEntityRecord', [\n\t\t\t\t\t\t\t'root',\n\t\t\t\t\t\t\t'globalStyles',\n\t\t\t\t\t\t\t_globalStylesId,\n\t\t\t\t\t ] )\n\t\t\t\t\t: true;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tglobalStylesId: _globalStylesId,\n\t\t\t\tisReady: hasResolved,\n\t\t\t\tsettings: record?.settings,\n\t\t\t\tstyles: record?.styles,\n\t\t\t\t_links: record?._links,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { getEditedEntityRecord } = useSelect( coreStore );\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\tconst config = useMemo( () => {\n\t\treturn {\n\t\t\tsettings: settings ?? {},\n\t\t\tstyles: styles ?? {},\n\t\t\t_links: _links ?? {},\n\t\t};\n\t}, [ settings, styles, _links ] );\n\n\tconst setConfig = useCallback(\n\t\t/**\n\t\t * Set the global styles config.\n\t\t * @param {Function|Object} callbackOrObject If the callbackOrObject is a function, pass the current config to the callback so the consumer can merge values.\n\t\t * Otherwise, overwrite the current config with the incoming object.\n\t\t * @param {Object} options Options for editEntityRecord Core selector.\n\t\t */\n\t\t( callbackOrObject, options = {} ) => {\n\t\t\tconst record = getEditedEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'globalStyles',\n\t\t\t\tglobalStylesId\n\t\t\t);\n\n\t\t\tconst currentConfig = {\n\t\t\t\tstyles: record?.styles ?? {},\n\t\t\t\tsettings: record?.settings ?? {},\n\t\t\t\t_links: record?._links ?? {},\n\t\t\t};\n\n\t\t\tconst updatedConfig =\n\t\t\t\ttypeof callbackOrObject === 'function'\n\t\t\t\t\t? callbackOrObject( currentConfig )\n\t\t\t\t\t: callbackOrObject;\n\n\t\t\teditEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'globalStyles',\n\t\t\t\tglobalStylesId,\n\t\t\t\t{\n\t\t\t\t\tstyles: cleanEmptyObject( updatedConfig.styles ) || {},\n\t\t\t\t\tsettings: cleanEmptyObject( updatedConfig.settings ) || {},\n\t\t\t\t\t_links: cleanEmptyObject( updatedConfig._links ) || {},\n\t\t\t\t},\n\t\t\t\toptions\n\t\t\t);\n\t\t},\n\t\t[ globalStylesId, editEntityRecord, getEditedEntityRecord ]\n\t);\n\n\treturn [ isReady, config, setConfig ];\n}\n\nfunction useGlobalStylesBaseConfig() {\n\tconst baseConfig = useSelect( ( select ) => {\n\t\treturn select(\n\t\t\tcoreStore\n\t\t).__experimentalGetCurrentThemeBaseGlobalStyles();\n\t}, [] );\n\n\treturn [ !! baseConfig, baseConfig ];\n}\n\nexport function useGlobalStylesContext() {\n\tconst [ isUserConfigReady, userConfig, setUserConfig ] =\n\t\tuseGlobalStylesUserConfig();\n\tconst [ isBaseConfigReady, baseConfig ] = useGlobalStylesBaseConfig();\n\n\tconst mergedConfig = useMemo( () => {\n\t\tif ( ! baseConfig || ! userConfig ) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn mergeBaseAndUserConfigs( baseConfig, userConfig );\n\t}, [ userConfig, baseConfig ] );\n\n\tconst context = useMemo( () => {\n\t\treturn {\n\t\t\tisReady: isUserConfigReady && isBaseConfigReady,\n\t\t\tuser: userConfig,\n\t\t\tbase: baseConfig,\n\t\t\tmerged: mergedConfig,\n\t\t\tsetUserConfig,\n\t\t};\n\t}, [\n\t\tmergedConfig,\n\t\tuserConfig,\n\t\tbaseConfig,\n\t\tsetUserConfig,\n\t\tisUserConfigReady,\n\t\tisBaseConfigReady,\n\t] );\n\n\treturn context;\n}\n\nexport function GlobalStylesProvider( { children } ) {\n\tconst context = useGlobalStylesContext();\n\tif ( ! context.isReady ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<GlobalStylesContext.Provider value={ context }>\n\t\t\t{ children }\n\t\t</GlobalStylesContext.Provider>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;AACjC,SAASC,aAAa,QAAQ,iBAAiB;;AAE/C;AACA;AACA;AACA,SAASC,WAAW,IAAIC,sBAAsB,QAAQ,yBAAyB;AAC/E,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,OAAO,EAAEC,WAAW,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AACA,SAASC,MAAM,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3C,MAAM;EAAEC,mBAAmB;EAAEC;AAAiB,CAAC,GAAGJ,MAAM,CACvDP,sBACD,CAAC;AAED,OAAO,SAASY,uBAAuBA,CAAEC,IAAI,EAAEC,IAAI,EAAG;EACrD,OAAOjB,SAAS,CAAEgB,IAAI,EAAEC,IAAI,EAAE;IAC7B;IACA;IACA;IACAC,iBAAiB,EAAEjB;EACpB,CAAE,CAAC;AACJ;AAEA,SAASkB,yBAAyBA,CAAA,EAAG;EACp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L,OAAS;IAAAG,QAAA,EAC5CA;EAAQ,CACmB,CAAC;AAEjC","ignoreList":[]}
|
|
@@ -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';
|
|
@@ -124,6 +124,15 @@ const deletePostAction = {
|
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
+
function useCanUserEligibilityCheckPostType(capability, resource, action) {
|
|
128
|
+
const registry = useRegistry();
|
|
129
|
+
return useMemo(() => ({
|
|
130
|
+
...action,
|
|
131
|
+
isEligible(item) {
|
|
132
|
+
return action.isEligible(item) && registry.select(coreStore).canUser(capability, resource, item.id);
|
|
133
|
+
}
|
|
134
|
+
}), [action, registry, capability, resource]);
|
|
135
|
+
}
|
|
127
136
|
const trashPostAction = {
|
|
128
137
|
id: 'move-to-trash',
|
|
129
138
|
label: __('Move to Trash'),
|
|
@@ -184,7 +193,7 @@ const trashPostAction = {
|
|
|
184
193
|
__('"%s" moved to trash.'), getItemTitle(items[0]));
|
|
185
194
|
} else if (items[0].type === 'page') {
|
|
186
195
|
successMessage = sprintf( /* translators: The number of items. */
|
|
187
|
-
|
|
196
|
+
_n('%s item moved to trash.', '%s items moved to trash.', items.length), items.length);
|
|
188
197
|
} else {
|
|
189
198
|
successMessage = sprintf( /* translators: The number of posts. */
|
|
190
199
|
__('%s items move to trash.'), items.length);
|
|
@@ -243,7 +252,10 @@ const trashPostAction = {
|
|
|
243
252
|
});
|
|
244
253
|
}
|
|
245
254
|
};
|
|
246
|
-
function
|
|
255
|
+
function useTrashPostAction(resource) {
|
|
256
|
+
return useCanUserEligibilityCheckPostType('delete', resource, trashPostAction);
|
|
257
|
+
}
|
|
258
|
+
function usePermanentlyDeletePostAction(resource) {
|
|
247
259
|
const {
|
|
248
260
|
createSuccessNotice,
|
|
249
261
|
createErrorNotice
|
|
@@ -251,7 +263,7 @@ function usePermanentlyDeletePostAction() {
|
|
|
251
263
|
const {
|
|
252
264
|
deleteEntityRecord
|
|
253
265
|
} = useDispatch(coreStore);
|
|
254
|
-
|
|
266
|
+
const permanentlyDeletePostAction = useMemo(() => ({
|
|
255
267
|
id: 'permanently-delete',
|
|
256
268
|
label: __('Permanently delete'),
|
|
257
269
|
supportsBulk: true,
|
|
@@ -323,8 +335,9 @@ function usePermanentlyDeletePostAction() {
|
|
|
323
335
|
}
|
|
324
336
|
}
|
|
325
337
|
}), [createSuccessNotice, createErrorNotice, deleteEntityRecord]);
|
|
338
|
+
return useCanUserEligibilityCheckPostType('delete', resource, permanentlyDeletePostAction);
|
|
326
339
|
}
|
|
327
|
-
function useRestorePostAction() {
|
|
340
|
+
function useRestorePostAction(resource) {
|
|
328
341
|
const {
|
|
329
342
|
createSuccessNotice,
|
|
330
343
|
createErrorNotice
|
|
@@ -333,7 +346,7 @@ function useRestorePostAction() {
|
|
|
333
346
|
editEntityRecord,
|
|
334
347
|
saveEditedEntityRecord
|
|
335
348
|
} = useDispatch(coreStore);
|
|
336
|
-
|
|
349
|
+
const restorePostAction = useMemo(() => ({
|
|
337
350
|
id: 'restore',
|
|
338
351
|
label: __('Restore'),
|
|
339
352
|
isPrimary: true,
|
|
@@ -413,6 +426,7 @@ function useRestorePostAction() {
|
|
|
413
426
|
}
|
|
414
427
|
}
|
|
415
428
|
}), [createSuccessNotice, createErrorNotice, editEntityRecord, saveEditedEntityRecord]);
|
|
429
|
+
return useCanUserEligibilityCheckPostType('update', resource, restorePostAction);
|
|
416
430
|
}
|
|
417
431
|
const viewPostAction = {
|
|
418
432
|
id: 'view-post',
|
|
@@ -432,6 +446,7 @@ const viewPostAction = {
|
|
|
432
446
|
};
|
|
433
447
|
const postRevisionsAction = {
|
|
434
448
|
id: 'view-post-revisions',
|
|
449
|
+
context: 'list',
|
|
435
450
|
label(items) {
|
|
436
451
|
var _items$0$_links$versi;
|
|
437
452
|
const revisionsCount = (_items$0$_links$versi = items[0]._links?.['version-history']?.[0]?.count) !== null && _items$0$_links$versi !== void 0 ? _items$0$_links$versi : 0;
|
|
@@ -554,6 +569,9 @@ const renamePostAction = {
|
|
|
554
569
|
});
|
|
555
570
|
}
|
|
556
571
|
};
|
|
572
|
+
function useRenamePostAction(resource) {
|
|
573
|
+
return useCanUserEligibilityCheckPostType('update', resource, renamePostAction);
|
|
574
|
+
}
|
|
557
575
|
const duplicatePostAction = {
|
|
558
576
|
id: 'duplicate-post',
|
|
559
577
|
label: _x('Duplicate', 'action label'),
|
|
@@ -808,19 +826,35 @@ export const duplicateTemplatePartAction = {
|
|
|
808
826
|
});
|
|
809
827
|
}
|
|
810
828
|
};
|
|
811
|
-
export function usePostActions(
|
|
829
|
+
export function usePostActions({
|
|
830
|
+
postType,
|
|
831
|
+
onActionPerformed,
|
|
832
|
+
context
|
|
833
|
+
}) {
|
|
812
834
|
const {
|
|
813
|
-
postTypeObject
|
|
835
|
+
postTypeObject,
|
|
836
|
+
resource,
|
|
837
|
+
cachedCanUserResolvers,
|
|
838
|
+
userCanCreatePostType
|
|
814
839
|
} = useSelect(select => {
|
|
815
840
|
const {
|
|
816
|
-
getPostType
|
|
841
|
+
getPostType,
|
|
842
|
+
getCachedResolvers,
|
|
843
|
+
canUser
|
|
817
844
|
} = select(coreStore);
|
|
845
|
+
const _postTypeObject = getPostType(postType);
|
|
846
|
+
const _resource = _postTypeObject?.rest_base || '';
|
|
818
847
|
return {
|
|
819
|
-
postTypeObject:
|
|
848
|
+
postTypeObject: _postTypeObject,
|
|
849
|
+
resource: _resource,
|
|
850
|
+
cachedCanUserResolvers: getCachedResolvers()?.canUser,
|
|
851
|
+
userCanCreatePostType: canUser('create', _resource)
|
|
820
852
|
};
|
|
821
853
|
}, [postType]);
|
|
822
|
-
const
|
|
823
|
-
const
|
|
854
|
+
const trashPostActionForPostType = useTrashPostAction(resource);
|
|
855
|
+
const permanentlyDeletePostActionForPostType = usePermanentlyDeletePostAction(resource);
|
|
856
|
+
const renamePostActionForPostType = useRenamePostAction(resource);
|
|
857
|
+
const restorePostActionForPostType = useRestorePostAction(resource);
|
|
824
858
|
const isTemplateOrTemplatePart = [TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE].includes(postType);
|
|
825
859
|
const isPattern = postType === PATTERN_POST_TYPE;
|
|
826
860
|
const isLoaded = !!postTypeObject;
|
|
@@ -830,7 +864,19 @@ export function usePostActions(postType, onActionPerformed) {
|
|
|
830
864
|
if (!isLoaded) {
|
|
831
865
|
return [];
|
|
832
866
|
}
|
|
833
|
-
|
|
867
|
+
let actions = [postTypeObject?.viewable && viewPostAction, supportsRevisions && postRevisionsAction, globalThis.IS_GUTENBERG_PLUGIN ? !isTemplateOrTemplatePart && !isPattern && duplicatePostAction : false, isTemplateOrTemplatePart && userCanCreatePostType && duplicateTemplatePartAction, isPattern && userCanCreatePostType && duplicatePatternAction, supportsTitle && renamePostActionForPostType, isPattern && exportPatternAsJSONAction, isTemplateOrTemplatePart ? resetTemplateAction : restorePostActionForPostType, isTemplateOrTemplatePart || isPattern ? deletePostAction : trashPostActionForPostType, !isTemplateOrTemplatePart && permanentlyDeletePostActionForPostType].filter(Boolean);
|
|
868
|
+
// Filter actions based on provided context. If not provided
|
|
869
|
+
// all actions are returned. We'll have a single entry for getting the actions
|
|
870
|
+
// and the consumer should provide the context to filter the actions, if needed.
|
|
871
|
+
// Actions should also provide the `context` they support, if it's specific, to
|
|
872
|
+
// compare with the provided context to get all the actions.
|
|
873
|
+
// Right now the only supported context is `list`.
|
|
874
|
+
actions = actions.filter(action => {
|
|
875
|
+
if (!action.context) {
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
878
|
+
return action.context === context;
|
|
879
|
+
});
|
|
834
880
|
if (onActionPerformed) {
|
|
835
881
|
for (let i = 0; i < actions.length; ++i) {
|
|
836
882
|
if (actions[i].callback) {
|
|
@@ -867,6 +913,9 @@ export function usePostActions(postType, onActionPerformed) {
|
|
|
867
913
|
}
|
|
868
914
|
}
|
|
869
915
|
return actions;
|
|
870
|
-
|
|
916
|
+
// We are making this use memo depend on cachedCanUserResolvers as a way to make the component using this hook re-render
|
|
917
|
+
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
|
|
918
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
919
|
+
}, [isTemplateOrTemplatePart, isPattern, postTypeObject?.viewable, permanentlyDeletePostActionForPostType, restorePostActionForPostType, renamePostActionForPostType, trashPostActionForPostType, onActionPerformed, isLoaded, supportsRevisions, supportsTitle, context, userCanCreatePostType, cachedCanUserResolvers]);
|
|
871
920
|
}
|
|
872
921
|
//# sourceMappingURL=actions.js.map
|