@wordpress/edit-widgets 6.3.0 → 6.5.0
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/CHANGELOG.md +4 -0
- package/build/components/widget-areas-block-editor-provider/index.js +14 -7
- package/build/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build/filters/move-to-widget-area.js +1 -1
- package/build/filters/move-to-widget-area.js.map +1 -1
- package/build/store/selectors.js +6 -6
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-provider/index.js +15 -8
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build-module/filters/move-to-widget-area.js +1 -1
- package/build-module/filters/move-to-widget-area.js.map +1 -1
- package/build-module/store/selectors.js +7 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +4 -1
- package/build-style/style.css +4 -1
- package/package.json +28 -28
- package/src/components/widget-areas-block-editor-provider/index.js +16 -12
- package/src/filters/move-to-widget-area.js +1 -1
- package/src/store/selectors.js +29 -18
package/CHANGELOG.md
CHANGED
|
@@ -39,30 +39,37 @@ const {
|
|
|
39
39
|
const {
|
|
40
40
|
BlockKeyboardShortcuts
|
|
41
41
|
} = (0, _lockUnlock.unlock)(_blockLibrary.privateApis);
|
|
42
|
+
const EMPTY_ARRAY = [];
|
|
42
43
|
function WidgetAreasBlockEditorProvider({
|
|
43
44
|
blockEditorSettings,
|
|
44
45
|
children,
|
|
45
46
|
...props
|
|
46
47
|
}) {
|
|
47
|
-
const mediaPermissions = (0, _coreData.useResourcePermissions)('media');
|
|
48
48
|
const isLargeViewport = (0, _compose.useViewportMatch)('medium');
|
|
49
49
|
const {
|
|
50
|
+
hasUploadPermissions,
|
|
50
51
|
reusableBlocks,
|
|
51
52
|
isFixedToolbarActive,
|
|
52
53
|
keepCaretInsideBlock,
|
|
53
54
|
pageOnFront,
|
|
54
55
|
pageForPosts
|
|
55
56
|
} = (0, _data.useSelect)(select => {
|
|
57
|
+
var _canUser;
|
|
56
58
|
const {
|
|
57
59
|
canUser,
|
|
58
60
|
getEntityRecord,
|
|
59
61
|
getEntityRecords
|
|
60
62
|
} = select(_coreData.store);
|
|
61
|
-
const siteSettings = canUser('read',
|
|
63
|
+
const siteSettings = canUser('read', {
|
|
64
|
+
kind: 'root',
|
|
65
|
+
name: 'site'
|
|
66
|
+
}) ? getEntityRecord('root', 'site') : undefined;
|
|
62
67
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
hasUploadPermissions: (_canUser = canUser('create', {
|
|
69
|
+
kind: 'root',
|
|
70
|
+
name: 'media'
|
|
71
|
+
})) !== null && _canUser !== void 0 ? _canUser : true,
|
|
72
|
+
reusableBlocks: _constants.ALLOW_REUSABLE_BLOCKS ? getEntityRecords('postType', 'wp_block') : EMPTY_ARRAY,
|
|
66
73
|
isFixedToolbarActive: !!select(_preferences.store).get('core/edit-widgets', 'fixedToolbar'),
|
|
67
74
|
keepCaretInsideBlock: !!select(_preferences.store).get('core/edit-widgets', 'keepCaretInsideBlock'),
|
|
68
75
|
pageOnFront: siteSettings?.page_on_front,
|
|
@@ -74,7 +81,7 @@ function WidgetAreasBlockEditorProvider({
|
|
|
74
81
|
} = (0, _data.useDispatch)(_store.store);
|
|
75
82
|
const settings = (0, _element.useMemo)(() => {
|
|
76
83
|
let mediaUploadBlockEditor;
|
|
77
|
-
if (
|
|
84
|
+
if (hasUploadPermissions) {
|
|
78
85
|
mediaUploadBlockEditor = ({
|
|
79
86
|
onError,
|
|
80
87
|
...argumentsObject
|
|
@@ -99,7 +106,7 @@ function WidgetAreasBlockEditorProvider({
|
|
|
99
106
|
pageOnFront,
|
|
100
107
|
pageForPosts
|
|
101
108
|
};
|
|
102
|
-
}, [blockEditorSettings, isFixedToolbarActive, isLargeViewport, keepCaretInsideBlock,
|
|
109
|
+
}, [hasUploadPermissions, blockEditorSettings, isFixedToolbarActive, isLargeViewport, keepCaretInsideBlock, reusableBlocks, setIsInserterOpened, pageOnFront, pageForPosts]);
|
|
103
110
|
const widgetAreaId = (0, _useLastSelectedWidgetArea.default)();
|
|
104
111
|
const [blocks, onInput, onChange] = (0, _coreData.useEntityBlockEditor)(_utils.KIND, _utils.POST_TYPE, {
|
|
105
112
|
id: (0, _utils.buildWidgetAreasPostId)()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_compose","_mediaUtils","_data","_coreData","_element","_blockEditor","_patterns","_preferences","_blockLibrary","_keyboardShortcuts","_interopRequireDefault","_utils","_useLastSelectedWidgetArea","_store","_constants","_lockUnlock","_jsxRuntime","ExperimentalBlockEditorProvider","unlock","blockEditorPrivateApis","PatternsMenuItems","editPatternsPrivateApis","BlockKeyboardShortcuts","blockLibraryPrivateApis","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","
|
|
1
|
+
{"version":3,"names":["_components","require","_compose","_mediaUtils","_data","_coreData","_element","_blockEditor","_patterns","_preferences","_blockLibrary","_keyboardShortcuts","_interopRequireDefault","_utils","_useLastSelectedWidgetArea","_store","_constants","_lockUnlock","_jsxRuntime","ExperimentalBlockEditorProvider","unlock","blockEditorPrivateApis","PatternsMenuItems","editPatternsPrivateApis","BlockKeyboardShortcuts","blockLibraryPrivateApis","EMPTY_ARRAY","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","isLargeViewport","useViewportMatch","hasUploadPermissions","reusableBlocks","isFixedToolbarActive","keepCaretInsideBlock","pageOnFront","pageForPosts","useSelect","select","_canUser","canUser","getEntityRecord","getEntityRecords","coreStore","siteSettings","kind","name","undefined","ALLOW_REUSABLE_BLOCKS","preferencesStore","get","page_on_front","page_for_posts","setIsInserterOpened","useDispatch","editWidgetsStore","settings","useMemo","mediaUploadBlockEditor","onError","argumentsObject","uploadMedia","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalReusableBlocks","hasFixedToolbar","mediaUpload","templateLock","__experimentalSetIsInserterOpened","widgetAreaId","useLastSelectedWidgetArea","blocks","onInput","onChange","useEntityBlockEditor","KIND","POST_TYPE","id","buildWidgetAreasPostId","jsxs","SlotFillProvider","jsx","default","Register","value","useSubRegistry","rootClientId"],"sources":["@wordpress/edit-widgets/src/components/widget-areas-block-editor-provider/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SlotFillProvider } from '@wordpress/components';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library';\n\n/**\n * Internal dependencies\n */\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport { buildWidgetAreasPostId, KIND, POST_TYPE } from '../../store/utils';\nimport useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area';\nimport { store as editWidgetsStore } from '../../store';\nimport { ALLOW_REUSABLE_BLOCKS } from '../../constants';\nimport { unlock } from '../../lock-unlock';\n\nconst { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );\nconst { PatternsMenuItems } = unlock( editPatternsPrivateApis );\nconst { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nexport default function WidgetAreasBlockEditorProvider( {\n\tblockEditorSettings,\n\tchildren,\n\t...props\n} ) {\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst {\n\t\thasUploadPermissions,\n\t\treusableBlocks,\n\t\tisFixedToolbarActive,\n\t\tkeepCaretInsideBlock,\n\t\tpageOnFront,\n\t\tpageForPosts,\n\t} = useSelect( ( select ) => {\n\t\tconst { canUser, getEntityRecord, getEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst siteSettings = canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} )\n\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t: undefined;\n\t\treturn {\n\t\t\thasUploadPermissions:\n\t\t\t\tcanUser( 'create', {\n\t\t\t\t\tkind: 'root',\n\t\t\t\t\tname: 'media',\n\t\t\t\t} ) ?? true,\n\t\t\treusableBlocks: ALLOW_REUSABLE_BLOCKS\n\t\t\t\t? getEntityRecords( 'postType', 'wp_block' )\n\t\t\t\t: EMPTY_ARRAY,\n\t\t\tisFixedToolbarActive: !! select( preferencesStore ).get(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'fixedToolbar'\n\t\t\t),\n\t\t\tkeepCaretInsideBlock: !! select( preferencesStore ).get(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'keepCaretInsideBlock'\n\t\t\t),\n\t\t\tpageOnFront: siteSettings?.page_on_front,\n\t\t\tpageForPosts: siteSettings?.page_for_posts,\n\t\t};\n\t}, [] );\n\tconst { setIsInserterOpened } = useDispatch( editWidgetsStore );\n\n\tconst settings = useMemo( () => {\n\t\tlet mediaUploadBlockEditor;\n\t\tif ( hasUploadPermissions ) {\n\t\t\tmediaUploadBlockEditor = ( { onError, ...argumentsObject } ) => {\n\t\t\t\tuploadMedia( {\n\t\t\t\t\twpAllowedMimeTypes: blockEditorSettings.allowedMimeTypes,\n\t\t\t\t\tonError: ( { message } ) => onError( message ),\n\t\t\t\t\t...argumentsObject,\n\t\t\t\t} );\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t...blockEditorSettings,\n\t\t\t__experimentalReusableBlocks: reusableBlocks,\n\t\t\thasFixedToolbar: isFixedToolbarActive || ! isLargeViewport,\n\t\t\tkeepCaretInsideBlock,\n\t\t\tmediaUpload: mediaUploadBlockEditor,\n\t\t\ttemplateLock: 'all',\n\t\t\t__experimentalSetIsInserterOpened: setIsInserterOpened,\n\t\t\tpageOnFront,\n\t\t\tpageForPosts,\n\t\t};\n\t}, [\n\t\thasUploadPermissions,\n\t\tblockEditorSettings,\n\t\tisFixedToolbarActive,\n\t\tisLargeViewport,\n\t\tkeepCaretInsideBlock,\n\t\treusableBlocks,\n\t\tsetIsInserterOpened,\n\t\tpageOnFront,\n\t\tpageForPosts,\n\t] );\n\n\tconst widgetAreaId = useLastSelectedWidgetArea();\n\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\tKIND,\n\t\tPOST_TYPE,\n\t\t{ id: buildWidgetAreasPostId() }\n\t);\n\n\treturn (\n\t\t<SlotFillProvider>\n\t\t\t<KeyboardShortcuts.Register />\n\t\t\t<BlockKeyboardShortcuts />\n\t\t\t<ExperimentalBlockEditorProvider\n\t\t\t\tvalue={ blocks }\n\t\t\t\tonInput={ onInput }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tsettings={ settings }\n\t\t\t\tuseSubRegistry={ false }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t\t<PatternsMenuItems rootClientId={ widgetAreaId } />\n\t\t\t</ExperimentalBlockEditorProvider>\n\t\t</SlotFillProvider>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,aAAA,GAAAT,OAAA;AAKA,IAAAU,kBAAA,GAAAC,sBAAA,CAAAX,OAAA;AACA,IAAAY,MAAA,GAAAZ,OAAA;AACA,IAAAa,0BAAA,GAAAF,sBAAA,CAAAX,OAAA;AACA,IAAAc,MAAA,GAAAd,OAAA;AACA,IAAAe,UAAA,GAAAf,OAAA;AACA,IA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M,EAAEC,OAAO,EAAEC,QAAQ,CAAE,GAAG,IAAAC,8BAAoB,EACzDC,WAAI,EACJC,gBAAS,EACT;IAAEC,EAAE,EAAE,IAAAC,6BAAsB,EAAC;EAAE,CAChC,CAAC;EAED,oBACC,IAAA/D,WAAA,CAAAgE,IAAA,EAAClF,WAAA,CAAAmF,gBAAgB;IAAAtD,QAAA,gBAChB,IAAAX,WAAA,CAAAkE,GAAA,EAACzE,kBAAA,CAAA0E,OAAiB,CAACC,QAAQ,IAAE,CAAC,eAC9B,IAAApE,WAAA,CAAAkE,GAAA,EAAC5D,sBAAsB,IAAE,CAAC,eAC1B,IAAAN,WAAA,CAAAgE,IAAA,EAAC/D,+BAA+B;MAC/BoE,KAAK,EAAGb,MAAQ;MAChBC,OAAO,EAAGA,OAAS;MACnBC,QAAQ,EAAGA,QAAU;MACrBlB,QAAQ,EAAGA,QAAU;MACrB8B,cAAc,EAAG,KAAO;MAAA,GACnB1D,KAAK;MAAAD,QAAA,GAERA,QAAQ,eACV,IAAAX,WAAA,CAAAkE,GAAA,EAAC9D,iBAAiB;QAACmE,YAAY,EAAGjB;MAAc,CAAE,CAAC;IAAA,CACnB,CAAC;EAAA,CACjB,CAAC;AAErB","ignoreList":[]}
|
|
@@ -45,7 +45,7 @@ const withMoveToWidgetAreaToolbarItem = (0, _compose.createHigherOrderComponent)
|
|
|
45
45
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
46
46
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(BlockEdit, {
|
|
47
47
|
...props
|
|
48
|
-
}), isMoveToWidgetAreaVisible && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, {
|
|
48
|
+
}, "edit"), isMoveToWidgetAreaVisible && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, {
|
|
49
49
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_widgets.MoveToWidgetArea, {
|
|
50
50
|
widgetAreas: widgetAreas,
|
|
51
51
|
currentWidgetAreaId: currentWidgetAreaId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_compose","_data","_hooks","_widgets","_store","_jsxRuntime","withMoveToWidgetAreaToolbarItem","createHigherOrderComponent","BlockEdit","props","clientId","name","blockName","widgetAreas","currentWidgetAreaId","canInsertBlockInWidgetArea","useSelect","select","selectors","editWidgetsStore","widgetAreaBlock","getParentWidgetAreaBlock","getWidgetAreas","attributes","id","moveBlockToWidgetArea","useDispatch","hasMultipleWidgetAreas","length","isMoveToWidgetAreaVisible","jsxs","Fragment","children","jsx","BlockControls","MoveToWidgetArea","onSelect","widgetAreaId","addFilter"],"sources":["@wordpress/edit-widgets/src/filters/move-to-widget-area.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { BlockControls } from '@wordpress/block-editor';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\nimport { MoveToWidgetArea } from '@wordpress/widgets';\n\n/**\n * Internal dependencies\n */\nimport { store as editWidgetsStore } from '../store';\n\nconst withMoveToWidgetAreaToolbarItem = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name: blockName } = props;\n\t\tconst { widgetAreas, currentWidgetAreaId, canInsertBlockInWidgetArea } =\n\t\t\tuseSelect(\n\t\t\t\t( select ) => {\n\t\t\t\t\t// Component won't display for a widget area, so don't run selectors.\n\t\t\t\t\tif ( blockName === 'core/widget-area' ) {\n\t\t\t\t\t\treturn {};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst selectors = select( editWidgetsStore );\n\n\t\t\t\t\tconst widgetAreaBlock =\n\t\t\t\t\t\tselectors.getParentWidgetAreaBlock( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twidgetAreas: selectors.getWidgetAreas(),\n\t\t\t\t\t\tcurrentWidgetAreaId: widgetAreaBlock?.attributes?.id,\n\t\t\t\t\t\tcanInsertBlockInWidgetArea:\n\t\t\t\t\t\t\tselectors.canInsertBlockInWidgetArea( blockName ),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ clientId, blockName ]\n\t\t\t);\n\n\t\tconst { moveBlockToWidgetArea } = useDispatch( editWidgetsStore );\n\t\tconst hasMultipleWidgetAreas = widgetAreas?.length > 1;\n\t\tconst isMoveToWidgetAreaVisible =\n\t\t\tblockName !== 'core/widget-area' &&\n\t\t\thasMultipleWidgetAreas &&\n\t\t\tcanInsertBlockInWidgetArea;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ isMoveToWidgetAreaVisible && (\n\t\t\t\t\t<BlockControls>\n\t\t\t\t\t\t<MoveToWidgetArea\n\t\t\t\t\t\t\twidgetAreas={ widgetAreas }\n\t\t\t\t\t\t\tcurrentWidgetAreaId={ currentWidgetAreaId }\n\t\t\t\t\t\t\tonSelect={ ( widgetAreaId ) => {\n\t\t\t\t\t\t\t\tmoveBlockToWidgetArea(\n\t\t\t\t\t\t\t\t\tprops.clientId,\n\t\t\t\t\t\t\t\t\twidgetAreaId\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withMoveToWidgetAreaToolbarItem'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-widgets/block-edit',\n\twithMoveToWidgetAreaToolbarItem\n);\n"],"mappings":";;AAIA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AAAqD,IAAAM,WAAA,GAAAN,OAAA;AAbrD;AACA;AACA;;AAQA;AACA;AACA;;AAGA,MAAMO,+BAA+B,GAAG,IAAAC,mCAA0B,EAC/DC,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAM;IAAEC,QAAQ;IAAEC,IAAI,EAAEC;EAAU,CAAC,GAAGH,KAAK;EAC3C,MAAM;IAAEI,WAAW;IAAEC,mBAAmB;IAAEC;EAA2B,CAAC,GACrE,IAAAC,eAAS,EACNC,MAAM,IAAM;IACb;IACA,IAAKL,SAAS,KAAK,kBAAkB,EAAG;MACvC,OAAO,CAAC,CAAC;IACV;IAEA,MAAMM,SAAS,GAAGD,MAAM,CAAEE,YAAiB,CAAC;IAE5C,MAAMC,eAAe,GACpBF,SAAS,CAACG,wBAAwB,CAAEX,QAAS,CAAC;IAE/C,OAAO;MACNG,WAAW,EAAEK,SAAS,CAACI,cAAc,CAAC,CAAC;MACvCR,mBAAmB,EAAEM,eAAe,EAAEG,UAAU,EAAEC,EAAE;MACpDT,0BAA0B,EACzBG,SAAS,CAACH,0BAA0B,CAAEH,SAAU;IAClD,CAAC;EACF,CAAC,EACD,CAAEF,QAAQ,EAAEE,SAAS,CACtB,CAAC;EAEF,MAAM;IAAEa;EAAsB,CAAC,GAAG,IAAAC,iBAAW,EAAEP,YAAiB,CAAC;EACjE,MAAMQ,sBAAsB,GAAGd,WAAW,EAAEe,MAAM,GAAG,CAAC;EACtD,MAAMC,yBAAyB,GAC9BjB,SAAS,KAAK,kBAAkB,IAChCe,sBAAsB,IACtBZ,0BAA0B;EAE3B,oBACC,IAAAV,WAAA,CAAAyB,IAAA,EAAAzB,WAAA,CAAA0B,QAAA;IAAAC,QAAA,gBACC,IAAA3B,WAAA,CAAA4B,GAAA,EAACzB,SAAS;MAAA,
|
|
1
|
+
{"version":3,"names":["_blockEditor","require","_compose","_data","_hooks","_widgets","_store","_jsxRuntime","withMoveToWidgetAreaToolbarItem","createHigherOrderComponent","BlockEdit","props","clientId","name","blockName","widgetAreas","currentWidgetAreaId","canInsertBlockInWidgetArea","useSelect","select","selectors","editWidgetsStore","widgetAreaBlock","getParentWidgetAreaBlock","getWidgetAreas","attributes","id","moveBlockToWidgetArea","useDispatch","hasMultipleWidgetAreas","length","isMoveToWidgetAreaVisible","jsxs","Fragment","children","jsx","BlockControls","MoveToWidgetArea","onSelect","widgetAreaId","addFilter"],"sources":["@wordpress/edit-widgets/src/filters/move-to-widget-area.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { BlockControls } from '@wordpress/block-editor';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\nimport { MoveToWidgetArea } from '@wordpress/widgets';\n\n/**\n * Internal dependencies\n */\nimport { store as editWidgetsStore } from '../store';\n\nconst withMoveToWidgetAreaToolbarItem = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name: blockName } = props;\n\t\tconst { widgetAreas, currentWidgetAreaId, canInsertBlockInWidgetArea } =\n\t\t\tuseSelect(\n\t\t\t\t( select ) => {\n\t\t\t\t\t// Component won't display for a widget area, so don't run selectors.\n\t\t\t\t\tif ( blockName === 'core/widget-area' ) {\n\t\t\t\t\t\treturn {};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst selectors = select( editWidgetsStore );\n\n\t\t\t\t\tconst widgetAreaBlock =\n\t\t\t\t\t\tselectors.getParentWidgetAreaBlock( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twidgetAreas: selectors.getWidgetAreas(),\n\t\t\t\t\t\tcurrentWidgetAreaId: widgetAreaBlock?.attributes?.id,\n\t\t\t\t\t\tcanInsertBlockInWidgetArea:\n\t\t\t\t\t\t\tselectors.canInsertBlockInWidgetArea( blockName ),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ clientId, blockName ]\n\t\t\t);\n\n\t\tconst { moveBlockToWidgetArea } = useDispatch( editWidgetsStore );\n\t\tconst hasMultipleWidgetAreas = widgetAreas?.length > 1;\n\t\tconst isMoveToWidgetAreaVisible =\n\t\t\tblockName !== 'core/widget-area' &&\n\t\t\thasMultipleWidgetAreas &&\n\t\t\tcanInsertBlockInWidgetArea;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{ isMoveToWidgetAreaVisible && (\n\t\t\t\t\t<BlockControls>\n\t\t\t\t\t\t<MoveToWidgetArea\n\t\t\t\t\t\t\twidgetAreas={ widgetAreas }\n\t\t\t\t\t\t\tcurrentWidgetAreaId={ currentWidgetAreaId }\n\t\t\t\t\t\t\tonSelect={ ( widgetAreaId ) => {\n\t\t\t\t\t\t\t\tmoveBlockToWidgetArea(\n\t\t\t\t\t\t\t\t\tprops.clientId,\n\t\t\t\t\t\t\t\t\twidgetAreaId\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withMoveToWidgetAreaToolbarItem'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-widgets/block-edit',\n\twithMoveToWidgetAreaToolbarItem\n);\n"],"mappings":";;AAIA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AAAqD,IAAAM,WAAA,GAAAN,OAAA;AAbrD;AACA;AACA;;AAQA;AACA;AACA;;AAGA,MAAMO,+BAA+B,GAAG,IAAAC,mCAA0B,EAC/DC,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAM;IAAEC,QAAQ;IAAEC,IAAI,EAAEC;EAAU,CAAC,GAAGH,KAAK;EAC3C,MAAM;IAAEI,WAAW;IAAEC,mBAAmB;IAAEC;EAA2B,CAAC,GACr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,CAAC,EACD,iCACD,CAAC;AAED,IAAAC,gBAAS,EACR,kBAAkB,EAClB,8BAA8B,EAC9BhC,+BACD,CAAC","ignoreList":[]}
|
package/build/store/selectors.js
CHANGED
|
@@ -32,16 +32,16 @@ const EMPTY_INSERTION_POINT = {
|
|
|
32
32
|
*
|
|
33
33
|
* @return {Object[]} API List of widgets.
|
|
34
34
|
*/
|
|
35
|
-
const getWidgets = exports.getWidgets = (0, _data.createRegistrySelector)(select => () => {
|
|
35
|
+
const getWidgets = exports.getWidgets = (0, _data.createRegistrySelector)(select => (0, _data.createSelector)(() => {
|
|
36
|
+
var _widgets$reduce;
|
|
36
37
|
const widgets = select(_coreData.store).getEntityRecords('root', 'widget', (0, _utils.buildWidgetsQuery)());
|
|
37
|
-
return (
|
|
38
|
-
|
|
39
|
-
widgets?.reduce((allWidgets, widget) => ({
|
|
38
|
+
return (// Key widgets by their ID.
|
|
39
|
+
(_widgets$reduce = widgets?.reduce((allWidgets, widget) => ({
|
|
40
40
|
...allWidgets,
|
|
41
41
|
[widget.id]: widget
|
|
42
|
-
}), {})
|
|
42
|
+
}), {})) !== null && _widgets$reduce !== void 0 ? _widgets$reduce : {}
|
|
43
43
|
);
|
|
44
|
-
});
|
|
44
|
+
}, () => [select(_coreData.store).getEntityRecords('root', 'widget', (0, _utils.buildWidgetsQuery)())]));
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Returns API widget data for a particular widget ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_widgets","_coreData","_blockEditor","_utils","_constants","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","exports","createRegistrySelector","select","widgets","coreStore","getEntityRecords","buildWidgetsQuery","reduce","allWidgets","widget","id","getWidget","state","editWidgetsStoreName","getWidgetAreas","query","buildWidgetAreasQuery","KIND","WIDGET_AREA_ENTITY_TYPE","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","POST_TYPE","buildWidgetAreaPostId","blockWidgetIds","blocks","map","block","getWidgetIdFromBlock","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockEditorStore","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel"],"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) => () => {\n\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t'root',\n\t\t'widget',\n\t\tbuildWidgetsQuery()\n\t);\n\n\treturn (\n\t\t// Key widgets by their ID.\n\t\twidgets?.reduce(\n\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t...allWidgets,\n\t\t\t\t[ widget.id ]: widget,\n\t\t\t} ),\n\t\t\t{}\n\t\t) || {}\n\t);\n} );\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AAQA,IAAAK,UAAA,GAAAL,OAAA;AAnBA;AACA;AACA;;AAMA;AACA;AACA;;AAWA,MAAMM,qBAAqB,GAAG;EAC7BC,YAAY,EAAEC,SAAS;EACvBC,cAAc,EAAED;AACjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACO,MAAME,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAAE,4BAAsB,EAAIC,MAAM,IAAM,MAAM;EACrE,MAAMC,OAAO,GAAGD,MAAM,CAAEE,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ACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,+BAA+BA,CAAErD,KAAK,EAAG;EACxD,IAAK,OAAOA,KAAK,CAACoD,kBAAkB,KAAK,SAAS,EAAG;IACpD,OAAOrE,qBAAqB;EAC7B;EAEA,OAAOiB,KAAK,CAACoD,kBAAkB;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,GAAAlE,OAAA,CAAAkE,0BAAA,GAAG,IAAAjE,4BAAsB,EAC7DC,MAAM,IAAM,CAAEU,KAAK,EAAEuD,SAAS,KAAM;EACrC;EACA,MAAM9C,WAAW,GAAGnB,MAAM,CAAEqC,kBAAiB,CAAC,CAAC6B,SAAS,CAAC,CAAC;;EAE1D;EACA;EACA;EACA,MAAM,CAAEC,eAAe,CAAE,GAAGhD,WAAW;EACvC,OAAOnB,MAAM,CAAEqC,kBAAiB,CAAC,CAAC+B,kBAAkB,CACnDH,SAAS,EACTE,eAAe,CAAClC,QACjB,CAAC;AACF,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASoC,gBAAgBA,CAAE3D,KAAK,EAAG;EACzC,OAAOA,KAAK,CAAC4D,aAAa;AAC3B","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_data","require","_widgets","_coreData","_blockEditor","_utils","_constants","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","exports","createRegistrySelector","select","createSelector","_widgets$reduce","widgets","coreStore","getEntityRecords","buildWidgetsQuery","reduce","allWidgets","widget","id","getWidget","state","editWidgetsStoreName","getWidgetAreas","query","buildWidgetAreasQuery","KIND","WIDGET_AREA_ENTITY_TYPE","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","POST_TYPE","buildWidgetAreaPostId","blockWidgetIds","blocks","map","block","getWidgetIdFromBlock","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockEditorStore","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel"],"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AAQA,IAAAK,UAAA,GAAAL,OAAA;AAnBA;AACA;AACA;;AAMA;AACA;AACA;;AAWA,MAAMM,qBAAqB,GAAG;EAC7BC,YAAY,EAAEC,SAAS;EACvBC,cAAc,EAAED;AACjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACO,MAAME,UAAU,GAAAC,OA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,EAAEuB,QAAQ,KAAM;EACzD,MAAM;IAAE2B;EAAqB,CAAC,GAAGlD,KAAK;EACtC,OAAO,CAAC,CAAEkD,oBAAoB,CAAE3B,QAAQ,CAAE;AAC3C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANArC,OAAA,CAAA+D,mBAAA,GAAAA,mBAAA;AAOO,SAASE,gBAAgBA,CAAEnD,KAAK,EAAG;EACzC,OAAO,CAAC,CAAEA,KAAK,CAACoD,kBAAkB;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,+BAA+BA,CAAErD,KAAK,EAAG;EACxD,IAAK,OAAOA,KAAK,CAACoD,kBAAkB,KAAK,SAAS,EAAG;IACpD,OAAOvE,qBAAqB;EAC7B;EAEA,OAAOmB,KAAK,CAACoD,kBAAkB;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,GAAApE,OAAA,CAAAoE,0BAAA,GAAG,IAAAnE,4BAAsB,EAC7DC,MAAM,IAAM,CAAEY,KAAK,EAAEuD,SAAS,KAAM;EACrC;EACA,MAAM9C,WAAW,GAAGrB,MAAM,CAAEuC,kBAAiB,CAAC,CAAC6B,SAAS,CAAC,CAAC;;EAE1D;EACA;EACA;EACA,MAAM,CAAEC,eAAe,CAAE,GAAGhD,WAAW;EACvC,OAAOrB,MAAM,CAAEuC,kBAAiB,CAAC,CAAC+B,kBAAkB,CACnDH,SAAS,EACTE,eAAe,CAAClC,QACjB,CAAC;AACF,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASoC,gBAAgBA,CAAE3D,KAAK,EAAG;EACzC,OAAOA,KAAK,CAAC4D,aAAa;AAC3B","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import { SlotFillProvider } from '@wordpress/components';
|
|
|
5
5
|
import { useViewportMatch } from '@wordpress/compose';
|
|
6
6
|
import { uploadMedia } from '@wordpress/media-utils';
|
|
7
7
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
8
|
-
import { useEntityBlockEditor, store as coreStore
|
|
8
|
+
import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';
|
|
9
9
|
import { useMemo } from '@wordpress/element';
|
|
10
10
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
11
11
|
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
|
|
@@ -32,30 +32,37 @@ const {
|
|
|
32
32
|
const {
|
|
33
33
|
BlockKeyboardShortcuts
|
|
34
34
|
} = unlock(blockLibraryPrivateApis);
|
|
35
|
+
const EMPTY_ARRAY = [];
|
|
35
36
|
export default function WidgetAreasBlockEditorProvider({
|
|
36
37
|
blockEditorSettings,
|
|
37
38
|
children,
|
|
38
39
|
...props
|
|
39
40
|
}) {
|
|
40
|
-
const mediaPermissions = useResourcePermissions('media');
|
|
41
41
|
const isLargeViewport = useViewportMatch('medium');
|
|
42
42
|
const {
|
|
43
|
+
hasUploadPermissions,
|
|
43
44
|
reusableBlocks,
|
|
44
45
|
isFixedToolbarActive,
|
|
45
46
|
keepCaretInsideBlock,
|
|
46
47
|
pageOnFront,
|
|
47
48
|
pageForPosts
|
|
48
49
|
} = useSelect(select => {
|
|
50
|
+
var _canUser;
|
|
49
51
|
const {
|
|
50
52
|
canUser,
|
|
51
53
|
getEntityRecord,
|
|
52
54
|
getEntityRecords
|
|
53
55
|
} = select(coreStore);
|
|
54
|
-
const siteSettings = canUser('read',
|
|
56
|
+
const siteSettings = canUser('read', {
|
|
57
|
+
kind: 'root',
|
|
58
|
+
name: 'site'
|
|
59
|
+
}) ? getEntityRecord('root', 'site') : undefined;
|
|
55
60
|
return {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
hasUploadPermissions: (_canUser = canUser('create', {
|
|
62
|
+
kind: 'root',
|
|
63
|
+
name: 'media'
|
|
64
|
+
})) !== null && _canUser !== void 0 ? _canUser : true,
|
|
65
|
+
reusableBlocks: ALLOW_REUSABLE_BLOCKS ? getEntityRecords('postType', 'wp_block') : EMPTY_ARRAY,
|
|
59
66
|
isFixedToolbarActive: !!select(preferencesStore).get('core/edit-widgets', 'fixedToolbar'),
|
|
60
67
|
keepCaretInsideBlock: !!select(preferencesStore).get('core/edit-widgets', 'keepCaretInsideBlock'),
|
|
61
68
|
pageOnFront: siteSettings?.page_on_front,
|
|
@@ -67,7 +74,7 @@ export default function WidgetAreasBlockEditorProvider({
|
|
|
67
74
|
} = useDispatch(editWidgetsStore);
|
|
68
75
|
const settings = useMemo(() => {
|
|
69
76
|
let mediaUploadBlockEditor;
|
|
70
|
-
if (
|
|
77
|
+
if (hasUploadPermissions) {
|
|
71
78
|
mediaUploadBlockEditor = ({
|
|
72
79
|
onError,
|
|
73
80
|
...argumentsObject
|
|
@@ -92,7 +99,7 @@ export default function WidgetAreasBlockEditorProvider({
|
|
|
92
99
|
pageOnFront,
|
|
93
100
|
pageForPosts
|
|
94
101
|
};
|
|
95
|
-
}, [blockEditorSettings, isFixedToolbarActive, isLargeViewport, keepCaretInsideBlock,
|
|
102
|
+
}, [hasUploadPermissions, blockEditorSettings, isFixedToolbarActive, isLargeViewport, keepCaretInsideBlock, reusableBlocks, setIsInserterOpened, pageOnFront, pageForPosts]);
|
|
96
103
|
const widgetAreaId = useLastSelectedWidgetArea();
|
|
97
104
|
const [blocks, onInput, onChange] = useEntityBlockEditor(KIND, POST_TYPE, {
|
|
98
105
|
id: buildWidgetAreasPostId()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SlotFillProvider","useViewportMatch","uploadMedia","useDispatch","useSelect","useEntityBlockEditor","store","coreStore","
|
|
1
|
+
{"version":3,"names":["SlotFillProvider","useViewportMatch","uploadMedia","useDispatch","useSelect","useEntityBlockEditor","store","coreStore","useMemo","privateApis","blockEditorPrivateApis","editPatternsPrivateApis","preferencesStore","blockLibraryPrivateApis","KeyboardShortcuts","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","editWidgetsStore","ALLOW_REUSABLE_BLOCKS","unlock","jsx","_jsx","jsxs","_jsxs","ExperimentalBlockEditorProvider","PatternsMenuItems","BlockKeyboardShortcuts","EMPTY_ARRAY","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","isLargeViewport","hasUploadPermissions","reusableBlocks","isFixedToolbarActive","keepCaretInsideBlock","pageOnFront","pageForPosts","select","_canUser","canUser","getEntityRecord","getEntityRecords","siteSettings","kind","name","undefined","get","page_on_front","page_for_posts","setIsInserterOpened","settings","mediaUploadBlockEditor","onError","argumentsObject","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalReusableBlocks","hasFixedToolbar","mediaUpload","templateLock","__experimentalSetIsInserterOpened","widgetAreaId","blocks","onInput","onChange","id","Register","value","useSubRegistry","rootClientId"],"sources":["@wordpress/edit-widgets/src/components/widget-areas-block-editor-provider/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SlotFillProvider } from '@wordpress/components';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { privateApis as blockLibraryPrivateApis } from '@wordpress/block-library';\n\n/**\n * Internal dependencies\n */\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport { buildWidgetAreasPostId, KIND, POST_TYPE } from '../../store/utils';\nimport useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area';\nimport { store as editWidgetsStore } from '../../store';\nimport { ALLOW_REUSABLE_BLOCKS } from '../../constants';\nimport { unlock } from '../../lock-unlock';\n\nconst { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );\nconst { PatternsMenuItems } = unlock( editPatternsPrivateApis );\nconst { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );\n\nconst EMPTY_ARRAY = [];\n\nexport default function WidgetAreasBlockEditorProvider( {\n\tblockEditorSettings,\n\tchildren,\n\t...props\n} ) {\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst {\n\t\thasUploadPermissions,\n\t\treusableBlocks,\n\t\tisFixedToolbarActive,\n\t\tkeepCaretInsideBlock,\n\t\tpageOnFront,\n\t\tpageForPosts,\n\t} = useSelect( ( select ) => {\n\t\tconst { canUser, getEntityRecord, getEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst siteSettings = canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} )\n\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t: undefined;\n\t\treturn {\n\t\t\thasUploadPermissions:\n\t\t\t\tcanUser( 'create', {\n\t\t\t\t\tkind: 'root',\n\t\t\t\t\tname: 'media',\n\t\t\t\t} ) ?? true,\n\t\t\treusableBlocks: ALLOW_REUSABLE_BLOCKS\n\t\t\t\t? getEntityRecords( 'postType', 'wp_block' )\n\t\t\t\t: EMPTY_ARRAY,\n\t\t\tisFixedToolbarActive: !! select( preferencesStore ).get(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'fixedToolbar'\n\t\t\t),\n\t\t\tkeepCaretInsideBlock: !! select( preferencesStore ).get(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'keepCaretInsideBlock'\n\t\t\t),\n\t\t\tpageOnFront: siteSettings?.page_on_front,\n\t\t\tpageForPosts: siteSettings?.page_for_posts,\n\t\t};\n\t}, [] );\n\tconst { setIsInserterOpened } = useDispatch( editWidgetsStore );\n\n\tconst settings = useMemo( () => {\n\t\tlet mediaUploadBlockEditor;\n\t\tif ( hasUploadPermissions ) {\n\t\t\tmediaUploadBlockEditor = ( { onError, ...argumentsObject } ) => {\n\t\t\t\tuploadMedia( {\n\t\t\t\t\twpAllowedMimeTypes: blockEditorSettings.allowedMimeTypes,\n\t\t\t\t\tonError: ( { message } ) => onError( message ),\n\t\t\t\t\t...argumentsObject,\n\t\t\t\t} );\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t...blockEditorSettings,\n\t\t\t__experimentalReusableBlocks: reusableBlocks,\n\t\t\thasFixedToolbar: isFixedToolbarActive || ! isLargeViewport,\n\t\t\tkeepCaretInsideBlock,\n\t\t\tmediaUpload: mediaUploadBlockEditor,\n\t\t\ttemplateLock: 'all',\n\t\t\t__experimentalSetIsInserterOpened: setIsInserterOpened,\n\t\t\tpageOnFront,\n\t\t\tpageForPosts,\n\t\t};\n\t}, [\n\t\thasUploadPermissions,\n\t\tblockEditorSettings,\n\t\tisFixedToolbarActive,\n\t\tisLargeViewport,\n\t\tkeepCaretInsideBlock,\n\t\treusableBlocks,\n\t\tsetIsInserterOpened,\n\t\tpageOnFront,\n\t\tpageForPosts,\n\t] );\n\n\tconst widgetAreaId = useLastSelectedWidgetArea();\n\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\tKIND,\n\t\tPOST_TYPE,\n\t\t{ id: buildWidgetAreasPostId() }\n\t);\n\n\treturn (\n\t\t<SlotFillProvider>\n\t\t\t<KeyboardShortcuts.Register />\n\t\t\t<BlockKeyboardShortcuts />\n\t\t\t<ExperimentalBlockEditorProvider\n\t\t\t\tvalue={ blocks }\n\t\t\t\tonInput={ onInput }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tsettings={ settings }\n\t\t\t\tuseSubRegistry={ false }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t\t<PatternsMenuItems rootClientId={ widgetAreaId } />\n\t\t\t</ExperimentalBlockEditorProvider>\n\t\t</SlotFillProvider>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,uBAAuB;AACxD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,WAAW,QAAQ,wBAAwB;AACpD,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
|
|
45
45
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
46
46
|
children: [/*#__PURE__*/_jsx(BlockEdit, {
|
|
47
47
|
...props
|
|
48
|
-
}), isMoveToWidgetAreaVisible && /*#__PURE__*/_jsx(BlockControls, {
|
|
48
|
+
}, "edit"), isMoveToWidgetAreaVisible && /*#__PURE__*/_jsx(BlockControls, {
|
|
49
49
|
children: /*#__PURE__*/_jsx(MoveToWidgetArea, {
|
|
50
50
|
widgetAreas: widgetAreas,
|
|
51
51
|
currentWidgetAreaId: currentWidgetAreaId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BlockControls","createHigherOrderComponent","useDispatch","useSelect","addFilter","MoveToWidgetArea","store","editWidgetsStore","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","withMoveToWidgetAreaToolbarItem","BlockEdit","props","clientId","name","blockName","widgetAreas","currentWidgetAreaId","canInsertBlockInWidgetArea","select","selectors","widgetAreaBlock","getParentWidgetAreaBlock","getWidgetAreas","attributes","id","moveBlockToWidgetArea","hasMultipleWidgetAreas","length","isMoveToWidgetAreaVisible","children","onSelect","widgetAreaId"],"sources":["@wordpress/edit-widgets/src/filters/move-to-widget-area.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { BlockControls } from '@wordpress/block-editor';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\nimport { MoveToWidgetArea } from '@wordpress/widgets';\n\n/**\n * Internal dependencies\n */\nimport { store as editWidgetsStore } from '../store';\n\nconst withMoveToWidgetAreaToolbarItem = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name: blockName } = props;\n\t\tconst { widgetAreas, currentWidgetAreaId, canInsertBlockInWidgetArea } =\n\t\t\tuseSelect(\n\t\t\t\t( select ) => {\n\t\t\t\t\t// Component won't display for a widget area, so don't run selectors.\n\t\t\t\t\tif ( blockName === 'core/widget-area' ) {\n\t\t\t\t\t\treturn {};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst selectors = select( editWidgetsStore );\n\n\t\t\t\t\tconst widgetAreaBlock =\n\t\t\t\t\t\tselectors.getParentWidgetAreaBlock( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twidgetAreas: selectors.getWidgetAreas(),\n\t\t\t\t\t\tcurrentWidgetAreaId: widgetAreaBlock?.attributes?.id,\n\t\t\t\t\t\tcanInsertBlockInWidgetArea:\n\t\t\t\t\t\t\tselectors.canInsertBlockInWidgetArea( blockName ),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ clientId, blockName ]\n\t\t\t);\n\n\t\tconst { moveBlockToWidgetArea } = useDispatch( editWidgetsStore );\n\t\tconst hasMultipleWidgetAreas = widgetAreas?.length > 1;\n\t\tconst isMoveToWidgetAreaVisible =\n\t\t\tblockName !== 'core/widget-area' &&\n\t\t\thasMultipleWidgetAreas &&\n\t\t\tcanInsertBlockInWidgetArea;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ isMoveToWidgetAreaVisible && (\n\t\t\t\t\t<BlockControls>\n\t\t\t\t\t\t<MoveToWidgetArea\n\t\t\t\t\t\t\twidgetAreas={ widgetAreas }\n\t\t\t\t\t\t\tcurrentWidgetAreaId={ currentWidgetAreaId }\n\t\t\t\t\t\t\tonSelect={ ( widgetAreaId ) => {\n\t\t\t\t\t\t\t\tmoveBlockToWidgetArea(\n\t\t\t\t\t\t\t\t\tprops.clientId,\n\t\t\t\t\t\t\t\t\twidgetAreaId\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withMoveToWidgetAreaToolbarItem'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-widgets/block-edit',\n\twithMoveToWidg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d,SAAS,KAAK,kBAAkB,IAChCY,sBAAsB,IACtBT,0BAA0B;EAE3B,oBACCT,KAAA,CAAAF,SAAA;IAAAuB,QAAA,gBACCzB,IAAA,CAACM,SAAS;MAAA,
|
|
1
|
+
{"version":3,"names":["BlockControls","createHigherOrderComponent","useDispatch","useSelect","addFilter","MoveToWidgetArea","store","editWidgetsStore","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","withMoveToWidgetAreaToolbarItem","BlockEdit","props","clientId","name","blockName","widgetAreas","currentWidgetAreaId","canInsertBlockInWidgetArea","select","selectors","widgetAreaBlock","getParentWidgetAreaBlock","getWidgetAreas","attributes","id","moveBlockToWidgetArea","hasMultipleWidgetAreas","length","isMoveToWidgetAreaVisible","children","onSelect","widgetAreaId"],"sources":["@wordpress/edit-widgets/src/filters/move-to-widget-area.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { BlockControls } from '@wordpress/block-editor';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\nimport { MoveToWidgetArea } from '@wordpress/widgets';\n\n/**\n * Internal dependencies\n */\nimport { store as editWidgetsStore } from '../store';\n\nconst withMoveToWidgetAreaToolbarItem = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name: blockName } = props;\n\t\tconst { widgetAreas, currentWidgetAreaId, canInsertBlockInWidgetArea } =\n\t\t\tuseSelect(\n\t\t\t\t( select ) => {\n\t\t\t\t\t// Component won't display for a widget area, so don't run selectors.\n\t\t\t\t\tif ( blockName === 'core/widget-area' ) {\n\t\t\t\t\t\treturn {};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst selectors = select( editWidgetsStore );\n\n\t\t\t\t\tconst widgetAreaBlock =\n\t\t\t\t\t\tselectors.getParentWidgetAreaBlock( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twidgetAreas: selectors.getWidgetAreas(),\n\t\t\t\t\t\tcurrentWidgetAreaId: widgetAreaBlock?.attributes?.id,\n\t\t\t\t\t\tcanInsertBlockInWidgetArea:\n\t\t\t\t\t\t\tselectors.canInsertBlockInWidgetArea( blockName ),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ clientId, blockName ]\n\t\t\t);\n\n\t\tconst { moveBlockToWidgetArea } = useDispatch( editWidgetsStore );\n\t\tconst hasMultipleWidgetAreas = widgetAreas?.length > 1;\n\t\tconst isMoveToWidgetAreaVisible =\n\t\t\tblockName !== 'core/widget-area' &&\n\t\t\thasMultipleWidgetAreas &&\n\t\t\tcanInsertBlockInWidgetArea;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{ isMoveToWidgetAreaVisible && (\n\t\t\t\t\t<BlockControls>\n\t\t\t\t\t\t<MoveToWidgetArea\n\t\t\t\t\t\t\twidgetAreas={ widgetAreas }\n\t\t\t\t\t\t\tcurrentWidgetAreaId={ currentWidgetAreaId }\n\t\t\t\t\t\t\tonSelect={ ( widgetAreaId ) => {\n\t\t\t\t\t\t\t\tmoveBlockToWidgetArea(\n\t\t\t\t\t\t\t\t\tprops.clientId,\n\t\t\t\t\t\t\t\t\twidgetAreaId\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withMoveToWidgetAreaToolbarItem'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-widgets/block-edit',\n\twithMoveToWidgetAreaToolbarItem\n);\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,yBAAyB;AACvD,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,gBAAgB,QAAQ,o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AA,eACbzB,IAAA,CAACJ,gBAAgB;QAChBe,WAAW,EAAGA,WAAa;QAC3BC,mBAAmB,EAAGA,mBAAqB;QAC3Cc,QAAQ,EAAKC,YAAY,IAAM;UAC9BN,qBAAqB,CACpBd,KAAK,CAACC,QAAQ,EACdmB,YACD,CAAC;QACF;MAAG,CACH;IAAC,CACY,CACf;EAAA,CACA,CAAC;AAEL,CAAC,EACD,iCACD,CAAC;AAEDhC,SAAS,CACR,kBAAkB,EAClB,8BAA8B,EAC9BU,+BACD,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createRegistrySelector } from '@wordpress/data';
|
|
4
|
+
import { createSelector, createRegistrySelector } from '@wordpress/data';
|
|
5
5
|
import { getWidgetIdFromBlock } from '@wordpress/widgets';
|
|
6
6
|
import { store as coreStore } from '@wordpress/core-data';
|
|
7
7
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
@@ -21,16 +21,16 @@ const EMPTY_INSERTION_POINT = {
|
|
|
21
21
|
*
|
|
22
22
|
* @return {Object[]} API List of widgets.
|
|
23
23
|
*/
|
|
24
|
-
export const getWidgets = createRegistrySelector(select => () => {
|
|
24
|
+
export const getWidgets = createRegistrySelector(select => createSelector(() => {
|
|
25
|
+
var _widgets$reduce;
|
|
25
26
|
const widgets = select(coreStore).getEntityRecords('root', 'widget', buildWidgetsQuery());
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
widgets?.reduce((allWidgets, widget) => ({
|
|
27
|
+
return (// Key widgets by their ID.
|
|
28
|
+
(_widgets$reduce = widgets?.reduce((allWidgets, widget) => ({
|
|
29
29
|
...allWidgets,
|
|
30
30
|
[widget.id]: widget
|
|
31
|
-
}), {})
|
|
31
|
+
}), {})) !== null && _widgets$reduce !== void 0 ? _widgets$reduce : {}
|
|
32
32
|
);
|
|
33
|
-
});
|
|
33
|
+
}, () => [select(coreStore).getEntityRecords('root', 'widget', buildWidgetsQuery())]));
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Returns API widget data for a particular widget ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createRegistrySelector","getWidgetIdFromBlock","store","coreStore","blockEditorStore","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","select","widgets","getEntityRecords","reduce","allWidgets","widget","id","getWidget","state","getWidgetAreas","query","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","blockWidgetIds","blocks","map","block","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel"],"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) => () => {\n\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t'root',\n\t\t'widget',\n\t\tbuildWidgetsQuery()\n\t);\n\n\treturn (\n\t\t// Key widgets by their ID.\n\t\twidgets?.reduce(\n\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t...allWidgets,\n\t\t\t\t[ widget.id ]: widget,\n\t\t\t} ),\n\t\t\t{}\n\t\t) || {}\n\t);\n} );\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,oBAAoB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EAAqB,CAAC,GAAG1C,KAAK;EACtC,OAAO,CAAC,CAAE0C,oBAAoB,CAAE1B,QAAQ,CAAE;AAC3C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS2B,gBAAgBA,CAAE3C,KAAK,EAAG;EACzC,OAAO,CAAC,CAAEA,KAAK,CAAC4C,kBAAkB;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,+BAA+BA,CAAE7C,KAAK,EAAG;EACxD,IAAK,OAAOA,KAAK,CAAC4C,kBAAkB,KAAK,SAAS,EAAG;IACpD,OAAOzD,qBAAqB;EAC7B;EAEA,OAAOa,KAAK,CAAC4C,kBAAkB;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,0BAA0B,GAAGxE,sBAAsB,CAC7DkB,MAAM,IAAM,CAAEQ,KAAK,EAAE+C,SAAS,KAAM;EACrC;EACA,MAAM1C,WAAW,GAAGb,MAAM,CAAEd,gBAAiB,CAAC,CAACsE,SAAS,CAAC,CAAC;;EAE1D;EACA;EACA;EACA,MAAM,CAAEC,eAAe,CAAE,GAAG5C,WAAW;EACvC,OAAOb,MAAM,CAAEd,gBAAiB,CAAC,CAACwE,kBAAkB,CACnDH,SAAS,EACTE,eAAe,CAACjC,QACjB,CAAC;AACF,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASmC,gBAAgBA,CAAEnD,KAAK,EAAG;EACzC,OAAOA,KAAK,CAACoD,aAAa;AAC3B","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createSelector","createRegistrySelector","getWidgetIdFromBlock","store","coreStore","blockEditorStore","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","EMPTY_INSERTION_POINT","rootClientId","undefined","insertionIndex","getWidgets","select","_widgets$reduce","widgets","getEntityRecords","reduce","allWidgets","widget","id","getWidget","state","getWidgetAreas","query","getWidgetAreaForWidgetId","widgetId","widgetAreas","find","widgetArea","post","getEditedEntityRecord","blockWidgetIds","blocks","map","block","includes","getParentWidgetAreaBlock","clientId","getBlock","getBlockName","getBlockParents","blockParents","widgetAreaClientId","parentClientId","getEditedWidgetAreas","ids","filter","hasEditsForEntityRecord","getReferenceWidgetBlocks","referenceWidgetName","results","_widgetArea","name","attributes","push","isSavingWidgetAreas","widgetAreasIds","isSaving","isSavingEntityRecord","widgetIds","Object","keys","getIsWidgetAreaOpen","widgetAreasOpenState","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","canInsertBlockInWidgetArea","blockName","getBlocks","firstWidgetArea","canInsertBlockType","isListViewOpened","listViewPanel"],"sources":["@wordpress/edit-widgets/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;AACxE,SAASC,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,Q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;AACA;AACA;AACA,OAAO,MAAMK,mBAAmB,GAAGA,CAAEzC,KAAK,EAAEgB,QAAQ,KAAM;EACzD,MAAM;IAAE0B;EAAqB,CAAC,GAAG1C,KAAK;EACtC,OAAO,CAAC,CAAE0C,oBAAoB,CAAE1B,QAAQ,CAAE;AAC3C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS2B,gBAAgBA,CAAE3C,KAAK,EAAG;EACzC,OAAO,CAAC,CAAEA,KAAK,CAAC4C,kBAAkB;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,+BAA+BA,CAAE7C,KAAK,EAAG;EACxD,IAAK,OAAOA,KAAK,CAAC4C,kBAAkB,KAAK,SAAS,EAAG;IACpD,OAAO1D,qBAAqB;EAC7B;EAEA,OAAOc,KAAK,CAAC4C,kBAAkB;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,0BAA0B,GAAGzE,sBAAsB,CAC7DkB,MAAM,IAAM,CAAES,KAAK,EAAE+C,SAAS,KAAM;EACrC;EACA,MAAM1C,WAAW,GAAGd,MAAM,CAAEd,gBAAiB,CAAC,CAACuE,SAAS,CAAC,CAAC;;EAE1D;EACA;EACA;EACA,MAAM,CAAEC,eAAe,CAAE,GAAG5C,WAAW;EACvC,OAAOd,MAAM,CAAEd,gBAAiB,CAAC,CAACyE,kBAAkB,CACnDH,SAAS,EACTE,eAAe,CAACjC,QACjB,CAAC;AACF,CACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASmC,gBAAgBA,CAAEnD,KAAK,EAAG;EACzC,OAAOA,KAAK,CAACoD,aAAa;AAC3B","ignoreList":[]}
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
* Grid System.
|
|
34
34
|
* https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
|
|
35
35
|
*/
|
|
36
|
+
/**
|
|
37
|
+
* Radius scale.
|
|
38
|
+
*/
|
|
36
39
|
/**
|
|
37
40
|
* Dimensions.
|
|
38
41
|
*/
|
|
@@ -176,7 +179,7 @@
|
|
|
176
179
|
top: 0;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
|
-
.interface-complementary-area p:not(.components-base-control__help) {
|
|
182
|
+
.interface-complementary-area p:not(.components-base-control__help, .components-form-token-field__help) {
|
|
180
183
|
margin-top: 0;
|
|
181
184
|
}
|
|
182
185
|
.interface-complementary-area h2 {
|
package/build-style/style.css
CHANGED
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
* Grid System.
|
|
34
34
|
* https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
|
|
35
35
|
*/
|
|
36
|
+
/**
|
|
37
|
+
* Radius scale.
|
|
38
|
+
*/
|
|
36
39
|
/**
|
|
37
40
|
* Dimensions.
|
|
38
41
|
*/
|
|
@@ -176,7 +179,7 @@
|
|
|
176
179
|
top: 0;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
|
-
.interface-complementary-area p:not(.components-base-control__help) {
|
|
182
|
+
.interface-complementary-area p:not(.components-base-control__help, .components-form-token-field__help) {
|
|
180
183
|
margin-top: 0;
|
|
181
184
|
}
|
|
182
185
|
.interface-complementary-area h2 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-widgets",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "Widgets Page module for WordPress..",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -28,32 +28,32 @@
|
|
|
28
28
|
"react-native": "src/index",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime": "^7.16.0",
|
|
31
|
-
"@wordpress/api-fetch": "^7.
|
|
32
|
-
"@wordpress/block-editor": "^
|
|
33
|
-
"@wordpress/block-library": "^9.
|
|
34
|
-
"@wordpress/blocks": "^13.
|
|
35
|
-
"@wordpress/components": "^28.
|
|
36
|
-
"@wordpress/compose": "^7.
|
|
37
|
-
"@wordpress/core-data": "^7.
|
|
38
|
-
"@wordpress/data": "^10.
|
|
39
|
-
"@wordpress/deprecated": "^4.
|
|
40
|
-
"@wordpress/dom": "^4.
|
|
41
|
-
"@wordpress/element": "^6.
|
|
42
|
-
"@wordpress/hooks": "^4.
|
|
43
|
-
"@wordpress/i18n": "^5.
|
|
44
|
-
"@wordpress/icons": "^10.
|
|
45
|
-
"@wordpress/interface": "^6.
|
|
46
|
-
"@wordpress/keyboard-shortcuts": "^5.
|
|
47
|
-
"@wordpress/keycodes": "^4.
|
|
48
|
-
"@wordpress/media-utils": "^5.
|
|
49
|
-
"@wordpress/notices": "^5.
|
|
50
|
-
"@wordpress/patterns": "^2.
|
|
51
|
-
"@wordpress/plugins": "^7.
|
|
52
|
-
"@wordpress/preferences": "^4.
|
|
53
|
-
"@wordpress/private-apis": "^1.
|
|
54
|
-
"@wordpress/reusable-blocks": "^5.
|
|
55
|
-
"@wordpress/url": "^4.
|
|
56
|
-
"@wordpress/widgets": "^4.
|
|
31
|
+
"@wordpress/api-fetch": "^7.5.0",
|
|
32
|
+
"@wordpress/block-editor": "^14.0.0",
|
|
33
|
+
"@wordpress/block-library": "^9.5.0",
|
|
34
|
+
"@wordpress/blocks": "^13.5.0",
|
|
35
|
+
"@wordpress/components": "^28.5.0",
|
|
36
|
+
"@wordpress/compose": "^7.5.0",
|
|
37
|
+
"@wordpress/core-data": "^7.5.0",
|
|
38
|
+
"@wordpress/data": "^10.5.0",
|
|
39
|
+
"@wordpress/deprecated": "^4.5.0",
|
|
40
|
+
"@wordpress/dom": "^4.5.0",
|
|
41
|
+
"@wordpress/element": "^6.5.0",
|
|
42
|
+
"@wordpress/hooks": "^4.5.0",
|
|
43
|
+
"@wordpress/i18n": "^5.5.0",
|
|
44
|
+
"@wordpress/icons": "^10.5.0",
|
|
45
|
+
"@wordpress/interface": "^6.5.0",
|
|
46
|
+
"@wordpress/keyboard-shortcuts": "^5.5.0",
|
|
47
|
+
"@wordpress/keycodes": "^4.5.0",
|
|
48
|
+
"@wordpress/media-utils": "^5.5.0",
|
|
49
|
+
"@wordpress/notices": "^5.5.0",
|
|
50
|
+
"@wordpress/patterns": "^2.5.0",
|
|
51
|
+
"@wordpress/plugins": "^7.5.0",
|
|
52
|
+
"@wordpress/preferences": "^4.5.0",
|
|
53
|
+
"@wordpress/private-apis": "^1.5.0",
|
|
54
|
+
"@wordpress/reusable-blocks": "^5.5.0",
|
|
55
|
+
"@wordpress/url": "^4.5.0",
|
|
56
|
+
"@wordpress/widgets": "^4.5.0",
|
|
57
57
|
"clsx": "^2.1.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "c3101ab024e2bfc85d525c6d247e0d57cafc9fd9"
|
|
67
67
|
}
|
|
@@ -5,11 +5,7 @@ import { SlotFillProvider } from '@wordpress/components';
|
|
|
5
5
|
import { useViewportMatch } from '@wordpress/compose';
|
|
6
6
|
import { uploadMedia } from '@wordpress/media-utils';
|
|
7
7
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
8
|
-
import {
|
|
9
|
-
useEntityBlockEditor,
|
|
10
|
-
store as coreStore,
|
|
11
|
-
useResourcePermissions,
|
|
12
|
-
} from '@wordpress/core-data';
|
|
8
|
+
import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';
|
|
13
9
|
import { useMemo } from '@wordpress/element';
|
|
14
10
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
15
11
|
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
|
|
@@ -30,14 +26,16 @@ const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );
|
|
|
30
26
|
const { PatternsMenuItems } = unlock( editPatternsPrivateApis );
|
|
31
27
|
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis );
|
|
32
28
|
|
|
29
|
+
const EMPTY_ARRAY = [];
|
|
30
|
+
|
|
33
31
|
export default function WidgetAreasBlockEditorProvider( {
|
|
34
32
|
blockEditorSettings,
|
|
35
33
|
children,
|
|
36
34
|
...props
|
|
37
35
|
} ) {
|
|
38
|
-
const mediaPermissions = useResourcePermissions( 'media' );
|
|
39
36
|
const isLargeViewport = useViewportMatch( 'medium' );
|
|
40
37
|
const {
|
|
38
|
+
hasUploadPermissions,
|
|
41
39
|
reusableBlocks,
|
|
42
40
|
isFixedToolbarActive,
|
|
43
41
|
keepCaretInsideBlock,
|
|
@@ -46,15 +44,21 @@ export default function WidgetAreasBlockEditorProvider( {
|
|
|
46
44
|
} = useSelect( ( select ) => {
|
|
47
45
|
const { canUser, getEntityRecord, getEntityRecords } =
|
|
48
46
|
select( coreStore );
|
|
49
|
-
const siteSettings = canUser( 'read',
|
|
47
|
+
const siteSettings = canUser( 'read', {
|
|
48
|
+
kind: 'root',
|
|
49
|
+
name: 'site',
|
|
50
|
+
} )
|
|
50
51
|
? getEntityRecord( 'root', 'site' )
|
|
51
52
|
: undefined;
|
|
52
53
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
hasUploadPermissions:
|
|
55
|
+
canUser( 'create', {
|
|
56
|
+
kind: 'root',
|
|
57
|
+
name: 'media',
|
|
58
|
+
} ) ?? true,
|
|
55
59
|
reusableBlocks: ALLOW_REUSABLE_BLOCKS
|
|
56
60
|
? getEntityRecords( 'postType', 'wp_block' )
|
|
57
|
-
:
|
|
61
|
+
: EMPTY_ARRAY,
|
|
58
62
|
isFixedToolbarActive: !! select( preferencesStore ).get(
|
|
59
63
|
'core/edit-widgets',
|
|
60
64
|
'fixedToolbar'
|
|
@@ -71,7 +75,7 @@ export default function WidgetAreasBlockEditorProvider( {
|
|
|
71
75
|
|
|
72
76
|
const settings = useMemo( () => {
|
|
73
77
|
let mediaUploadBlockEditor;
|
|
74
|
-
if (
|
|
78
|
+
if ( hasUploadPermissions ) {
|
|
75
79
|
mediaUploadBlockEditor = ( { onError, ...argumentsObject } ) => {
|
|
76
80
|
uploadMedia( {
|
|
77
81
|
wpAllowedMimeTypes: blockEditorSettings.allowedMimeTypes,
|
|
@@ -92,11 +96,11 @@ export default function WidgetAreasBlockEditorProvider( {
|
|
|
92
96
|
pageForPosts,
|
|
93
97
|
};
|
|
94
98
|
}, [
|
|
99
|
+
hasUploadPermissions,
|
|
95
100
|
blockEditorSettings,
|
|
96
101
|
isFixedToolbarActive,
|
|
97
102
|
isLargeViewport,
|
|
98
103
|
keepCaretInsideBlock,
|
|
99
|
-
mediaPermissions.canCreate,
|
|
100
104
|
reusableBlocks,
|
|
101
105
|
setIsInserterOpened,
|
|
102
106
|
pageOnFront,
|
package/src/store/selectors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createRegistrySelector } from '@wordpress/data';
|
|
4
|
+
import { createSelector, createRegistrySelector } from '@wordpress/data';
|
|
5
5
|
import { getWidgetIdFromBlock } from '@wordpress/widgets';
|
|
6
6
|
import { store as coreStore } from '@wordpress/core-data';
|
|
7
7
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
@@ -29,24 +29,35 @@ const EMPTY_INSERTION_POINT = {
|
|
|
29
29
|
*
|
|
30
30
|
* @return {Object[]} API List of widgets.
|
|
31
31
|
*/
|
|
32
|
-
export const getWidgets = createRegistrySelector( ( select ) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
export const getWidgets = createRegistrySelector( ( select ) =>
|
|
33
|
+
createSelector(
|
|
34
|
+
() => {
|
|
35
|
+
const widgets = select( coreStore ).getEntityRecords(
|
|
36
|
+
'root',
|
|
37
|
+
'widget',
|
|
38
|
+
buildWidgetsQuery()
|
|
39
|
+
);
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
41
|
+
return (
|
|
42
|
+
// Key widgets by their ID.
|
|
43
|
+
widgets?.reduce(
|
|
44
|
+
( allWidgets, widget ) => ( {
|
|
45
|
+
...allWidgets,
|
|
46
|
+
[ widget.id ]: widget,
|
|
47
|
+
} ),
|
|
48
|
+
{}
|
|
49
|
+
) ?? {}
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
() => [
|
|
53
|
+
select( coreStore ).getEntityRecords(
|
|
54
|
+
'root',
|
|
55
|
+
'widget',
|
|
56
|
+
buildWidgetsQuery()
|
|
57
|
+
),
|
|
58
|
+
]
|
|
59
|
+
)
|
|
60
|
+
);
|
|
50
61
|
|
|
51
62
|
/**
|
|
52
63
|
* Returns API widget data for a particular widget ID.
|