@wordpress/edit-widgets 5.11.0 → 5.12.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 +2 -0
- package/build/blocks/widget-area/edit/index.js +24 -29
- package/build/blocks/widget-area/edit/index.js.map +1 -1
- package/build/blocks/widget-area/edit/inner-blocks.js +3 -4
- package/build/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build/blocks/widget-area/index.js +3 -6
- package/build/blocks/widget-area/index.js.map +1 -1
- package/build/components/error-boundary/index.js +8 -10
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +3 -4
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +41 -50
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +10 -12
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/layout/index.js +3 -4
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/interface.js +3 -4
- package/build/components/layout/interface.js.map +1 -1
- package/build/components/layout/unsaved-changes-warning.js +1 -1
- package/build/components/layout/unsaved-changes-warning.js.map +1 -1
- package/build/components/more-menu/tools-more-menu-group.js +5 -8
- package/build/components/more-menu/tools-more-menu-group.js.map +1 -1
- package/build/components/notices/index.js +11 -20
- package/build/components/notices/index.js.map +1 -1
- package/build/components/save-button/index.js +1 -3
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +8 -3
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/index.js +7 -8
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/widget-areas.js +5 -6
- package/build/components/sidebar/widget-areas.js.map +1 -1
- package/build/components/welcome-guide/index.js +6 -7
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-content/index.js +3 -4
- package/build/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-provider/index.js +12 -17
- package/build/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build/filters/move-to-widget-area.js +2 -4
- package/build/filters/move-to-widget-area.js.map +1 -1
- package/build/hooks/use-last-selected-widget-area.js +2 -4
- package/build/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build/hooks/use-widget-library-insertion-point.js +1 -3
- package/build/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build/store/actions.js +49 -74
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +1 -3
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +3 -11
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +8 -10
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +15 -32
- package/build/store/selectors.js.map +1 -1
- package/build/store/transformers.js +1 -2
- package/build/store/transformers.js.map +1 -1
- package/build-module/blocks/widget-area/edit/index.js +24 -29
- package/build-module/blocks/widget-area/edit/index.js.map +1 -1
- package/build-module/blocks/widget-area/edit/inner-blocks.js +3 -4
- package/build-module/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build-module/blocks/widget-area/index.js +3 -6
- package/build-module/blocks/widget-area/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +8 -10
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +3 -4
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +39 -48
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +10 -12
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/layout/index.js +3 -4
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/interface.js +3 -4
- package/build-module/components/layout/interface.js.map +1 -1
- package/build-module/components/layout/unsaved-changes-warning.js +1 -1
- package/build-module/components/layout/unsaved-changes-warning.js.map +1 -1
- package/build-module/components/more-menu/tools-more-menu-group.js +5 -8
- package/build-module/components/more-menu/tools-more-menu-group.js.map +1 -1
- package/build-module/components/notices/index.js +11 -20
- package/build-module/components/notices/index.js.map +1 -1
- package/build-module/components/save-button/index.js +1 -3
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +9 -3
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/index.js +9 -10
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/widget-areas.js +5 -6
- package/build-module/components/sidebar/widget-areas.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +6 -7
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-content/index.js +3 -4
- package/build-module/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-provider/index.js +12 -17
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build-module/filters/move-to-widget-area.js +2 -4
- package/build-module/filters/move-to-widget-area.js.map +1 -1
- package/build-module/hooks/use-last-selected-widget-area.js +2 -4
- package/build-module/hooks/use-last-selected-widget-area.js.map +1 -1
- package/build-module/hooks/use-widget-library-insertion-point.js +1 -3
- package/build-module/hooks/use-widget-library-insertion-point.js.map +1 -1
- package/build-module/store/actions.js +49 -74
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +1 -3
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +3 -11
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +8 -10
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +15 -32
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/transformers.js +1 -2
- package/build-module/store/transformers.js.map +1 -1
- package/package.json +27 -27
- package/src/components/secondary-sidebar/list-view-sidebar.js +8 -1
- package/src/components/sidebar/index.js +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/components/widget-areas-block-editor-provider/index.js"],"names":["SlotFillProvider","uploadMedia","useDispatch","useSelect","useEntityBlockEditor","store","coreStore","useResourcePermissions","useMemo","BlockEditorKeyboardShortcuts","CopyHandler","privateApis","blockEditorPrivateApis","ReusableBlocksMenuItems","ShortcutProvider","preferencesStore","KeyboardShortcuts","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","editWidgetsStore","ALLOW_REUSABLE_BLOCKS","unlock","ExperimentalBlockEditorProvider","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","mediaPermissions","reusableBlocks","isFixedToolbarActive","keepCaretInsideBlock","select","widgetAreas","getWidgetAreas","widgets","getWidgets","getEntityRecords","get","setIsInserterOpened","settings","mediaUploadBlockEditor","canCreate","onError","argumentsObject","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalReusableBlocks","hasFixedToolbar","mediaUpload","templateLock","__experimentalSetIsInserterOpened","widgetAreaId","blocks","onInput","onChange","id"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,uBAAjC;AACA,SAASC,WAAT,QAA4B,wBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,oBADD,EAECC,KAAK,IAAIC,SAFV,EAGCC,sBAHD,QAIO,sBAJP;AAKA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SACCC,4BADD,EAECC,WAFD,EAGCC,WAAW,IAAIC,sBAHhB,QAIO,yBAJP;AAKA,SAASC,uBAAT,QAAwC,4BAAxC;AACA,SAASC,gBAAT,QAAiC,+BAAjC;AACA,SAAST,KAAK,IAAIU,gBAAlB,QAA0C,wBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,SAASC,sBAAT,EAAiCC,IAAjC,EAAuCC,SAAvC,QAAwD,mBAAxD;AACA,OAAOC,yBAAP,MAAsC,2CAAtC;AACA,SAASf,KAAK,IAAIgB,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAT,QAAsC,iBAAtC;AACA,SAASC,MAAT,QAAuB,oBAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAsCD,MAAM,CAAEX,sBAAF,CAAlD;AAEA,eAAe,SAASa,8BAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/components/widget-areas-block-editor-provider/index.js"],"names":["SlotFillProvider","uploadMedia","useDispatch","useSelect","useEntityBlockEditor","store","coreStore","useResourcePermissions","useMemo","BlockEditorKeyboardShortcuts","CopyHandler","privateApis","blockEditorPrivateApis","ReusableBlocksMenuItems","ShortcutProvider","preferencesStore","KeyboardShortcuts","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","editWidgetsStore","ALLOW_REUSABLE_BLOCKS","unlock","ExperimentalBlockEditorProvider","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","mediaPermissions","reusableBlocks","isFixedToolbarActive","keepCaretInsideBlock","select","widgetAreas","getWidgetAreas","widgets","getWidgets","getEntityRecords","get","setIsInserterOpened","settings","mediaUploadBlockEditor","canCreate","onError","argumentsObject","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalReusableBlocks","hasFixedToolbar","mediaUpload","templateLock","__experimentalSetIsInserterOpened","widgetAreaId","blocks","onInput","onChange","id"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,uBAAjC;AACA,SAASC,WAAT,QAA4B,wBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,oBADD,EAECC,KAAK,IAAIC,SAFV,EAGCC,sBAHD,QAIO,sBAJP;AAKA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SACCC,4BADD,E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A9B,OADD,EAEC,cAAC,iBAAD,CAAmB,QAAnB,OAFD,EAGC,cAAC,gBAAD,QACC,cAAC,+BAAD;AACC,IAAA,KAAK,EAAGsC,MADT;AAEC,IAAA,OAAO,EAAGC,OAFX;AAGC,IAAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,QAAQ,EAAGhB,QAJZ;AAKC,IAAA,cAAc,EAAG;AALlB,KAMMb,KANN,GAQC,cAAC,WAAD,QAAeD,QAAf,CARD,EASC,cAAC,uBAAD;AAAyB,IAAA,YAAY,EAAG2B;AAAxC,IATD,CADD,CAHD,CADD;AAmBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SlotFillProvider } from '@wordpress/components';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tuseEntityBlockEditor,\n\tstore as coreStore,\n\tuseResourcePermissions,\n} from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport {\n\tBlockEditorKeyboardShortcuts,\n\tCopyHandler,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as preferencesStore } from '@wordpress/preferences';\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 '../../private-apis';\n\nconst { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );\n\nexport default function WidgetAreasBlockEditorProvider( {\n\tblockEditorSettings,\n\tchildren,\n\t...props\n} ) {\n\tconst mediaPermissions = useResourcePermissions( 'media' );\n\tconst { reusableBlocks, isFixedToolbarActive, keepCaretInsideBlock } =\n\t\tuseSelect(\n\t\t\t( select ) => ( {\n\t\t\t\twidgetAreas: select( editWidgetsStore ).getWidgetAreas(),\n\t\t\t\twidgets: select( editWidgetsStore ).getWidgets(),\n\t\t\t\treusableBlocks: ALLOW_REUSABLE_BLOCKS\n\t\t\t\t\t? select( coreStore ).getEntityRecords(\n\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t'wp_block'\n\t\t\t\t\t )\n\t\t\t\t\t: [],\n\t\t\t\tisFixedToolbarActive: !! select( preferencesStore ).get(\n\t\t\t\t\t'core/edit-widgets',\n\t\t\t\t\t'fixedToolbar'\n\t\t\t\t),\n\t\t\t\tkeepCaretInsideBlock: !! select( preferencesStore ).get(\n\t\t\t\t\t'core/edit-widgets',\n\t\t\t\t\t'keepCaretInsideBlock'\n\t\t\t\t),\n\t\t\t} ),\n\t\t\t[]\n\t\t);\n\tconst { setIsInserterOpened } = useDispatch( editWidgetsStore );\n\n\tconst settings = useMemo( () => {\n\t\tlet mediaUploadBlockEditor;\n\t\tif ( mediaPermissions.canCreate ) {\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,\n\t\t\tkeepCaretInsideBlock,\n\t\t\tmediaUpload: mediaUploadBlockEditor,\n\t\t\ttemplateLock: 'all',\n\t\t\t__experimentalSetIsInserterOpened: setIsInserterOpened,\n\t\t};\n\t}, [\n\t\tblockEditorSettings,\n\t\tisFixedToolbarActive,\n\t\tkeepCaretInsideBlock,\n\t\tmediaPermissions.canCreate,\n\t\treusableBlocks,\n\t\tsetIsInserterOpened,\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<ShortcutProvider>\n\t\t\t<BlockEditorKeyboardShortcuts.Register />\n\t\t\t<KeyboardShortcuts.Register />\n\t\t\t<SlotFillProvider>\n\t\t\t\t<ExperimentalBlockEditorProvider\n\t\t\t\t\tvalue={ blocks }\n\t\t\t\t\tonInput={ onInput }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tsettings={ settings }\n\t\t\t\t\tuseSubRegistry={ false }\n\t\t\t\t\t{ ...props }\n\t\t\t\t>\n\t\t\t\t\t<CopyHandler>{ children }</CopyHandler>\n\t\t\t\t\t<ReusableBlocksMenuItems rootClientId={ widgetAreaId } />\n\t\t\t\t</ExperimentalBlockEditorProvider>\n\t\t\t</SlotFillProvider>\n\t\t</ShortcutProvider>\n\t);\n}\n"]}
|
|
@@ -23,8 +23,6 @@ const withMoveToWidgetAreaToolbarItem = createHigherOrderComponent(BlockEdit =>
|
|
|
23
23
|
currentWidgetAreaId,
|
|
24
24
|
canInsertBlockInWidgetArea
|
|
25
25
|
} = useSelect(select => {
|
|
26
|
-
var _widgetAreaBlock$attr;
|
|
27
|
-
|
|
28
26
|
// Component won't display for a widget area, so don't run selectors.
|
|
29
27
|
if (blockName === 'core/widget-area') {
|
|
30
28
|
return {};
|
|
@@ -34,14 +32,14 @@ const withMoveToWidgetAreaToolbarItem = createHigherOrderComponent(BlockEdit =>
|
|
|
34
32
|
const widgetAreaBlock = selectors.getParentWidgetAreaBlock(clientId);
|
|
35
33
|
return {
|
|
36
34
|
widgetAreas: selectors.getWidgetAreas(),
|
|
37
|
-
currentWidgetAreaId: widgetAreaBlock
|
|
35
|
+
currentWidgetAreaId: widgetAreaBlock?.attributes?.id,
|
|
38
36
|
canInsertBlockInWidgetArea: selectors.canInsertBlockInWidgetArea(blockName)
|
|
39
37
|
};
|
|
40
38
|
}, [clientId, blockName]);
|
|
41
39
|
const {
|
|
42
40
|
moveBlockToWidgetArea
|
|
43
41
|
} = useDispatch(editWidgetsStore);
|
|
44
|
-
const hasMultipleWidgetAreas =
|
|
42
|
+
const hasMultipleWidgetAreas = widgetAreas?.length > 1;
|
|
45
43
|
const isMoveToWidgetAreaVisible = blockName !== 'core/widget-area' && hasMultipleWidgetAreas && canInsertBlockInWidgetArea;
|
|
46
44
|
return createElement(Fragment, null, createElement(BlockEdit, props), isMoveToWidgetAreaVisible && createElement(BlockControls, null, createElement(MoveToWidgetArea, {
|
|
47
45
|
widgetAreas: widgetAreas,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/filters/move-to-widget-area.js"],"names":["BlockControls","createHigherOrderComponent","useDispatch","useSelect","addFilter","MoveToWidgetArea","store","editWidgetsStore","withMoveToWidgetAreaToolbarItem","BlockEdit","props","clientId","name","blockName","widgetAreas","currentWidgetAreaId","canInsertBlockInWidgetArea","select","selectors","widgetAreaBlock","getParentWidgetAreaBlock","getWidgetAreas","attributes","id","moveBlockToWidgetArea","hasMultipleWidgetAreas","length","isMoveToWidgetAreaVisible","widgetAreaId"],"mappings":";;AAAA;AACA;AACA;AAEA,SAASA,aAAT,QAA8B,yBAA9B;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,UAA1C;AAEA,MAAMC,+BAA+B,GAAGP,0BAA0B,CAC/DQ,SAAF,IAAmBC,KAAF,IAAa;AAC7B,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,IAAI,EAAEC;AAAlB,MAAgCH,KAAtC;AACA,QAAM;AAAEI,IAAAA,WAAF;AAAeC,IAAAA,mBAAf;AAAoCC,IAAAA;AAApC,MACLb,SAAS,CACNc,MAAF,IAAc;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/filters/move-to-widget-area.js"],"names":["BlockControls","createHigherOrderComponent","useDispatch","useSelect","addFilter","MoveToWidgetArea","store","editWidgetsStore","withMoveToWidgetAreaToolbarItem","BlockEdit","props","clientId","name","blockName","widgetAreas","currentWidgetAreaId","canInsertBlockInWidgetArea","select","selectors","widgetAreaBlock","getParentWidgetAreaBlock","getWidgetAreas","attributes","id","moveBlockToWidgetArea","hasMultipleWidgetAreas","length","isMoveToWidgetAreaVisible","widgetAreaId"],"mappings":";;AAAA;AACA;AACA;AAEA,SAASA,aAAT,QAA8B,yBAA9B;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,UAA1C;AAEA,MAAMC,+BAA+B,GAAGP,0BAA0B,CAC/DQ,SAAF,IAAmBC,KAAF,IAAa;AAC7B,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,IAAI,EAAEC;AAAlB,MAAgCH,KAAtC;AACA,QAAM;AAAEI,IAAAA,WAAF;AAAeC,IAAAA,mBAAf;AAAoCC,IAAAA;AAApC,MACLb,SAAS,CACNc,MAAF,IAAc;AACb;AACA,QAAKJ,SAAS,KAAK,kBAAnB,EAAwC;AACvC,aAAO,EAAP;AACA;;AAED,UAAMK,SAAS,GAAGD,MAAM,CAAEV,gBAAF,CAAxB;AAEA,UAAMY,eAAe,GACpBD,SAAS,CAACE,wBAAV,CAAoCT,QAApC,CADD;AAGA,WAAO;AACNG,MAAAA,WAAW,EAAEI,SAAS,CAACG,cAAV,EADP;AAENN,MAAAA,mBAAmB,EAAEI,eAAe,EAAEG,UAAjB,EAA6BC,EAF5C;AAGNP,MAAAA,0BAA0B,EACzBE,SAAS,CAACF,0BAAV,CAAsCH,SAAtC;AAJK,KAAP;AAMA,GAlBO,EAmBR,CAAEF,QAAF,EAAYE,SAAZ,CAnBQ,CADV;AAuBA,QAAM;AAAEW,IAAAA;AAAF,MAA4BtB,WAAW,CAAEK,gBAAF,CAA7C;AACA,QAAMkB,sBAAsB,GAAGX,WAAW,EAAEY,MAAb,GAAsB,CAArD;AACA,QAAMC,yBAAyB,GAC9Bd,SAAS,KAAK,kBAAd,IACAY,sBADA,IAEAT,0BAHD;AAKA,SACC,8BACC,cAAC,SAAD,EAAgBN,KAAhB,CADD,EAEGiB,yBAAyB,IAC1B,cAAC,aAAD,QACC,cAAC,gBAAD;AACC,IAAA,WAAW,EAAGb,WADf;AAEC,IAAA,mBAAmB,EAAGC,mBAFvB;AAGC,IAAA,QAAQ,EAAKa,YAAF,IAAoB;AAC9BJ,MAAAA,qBAAqB,CACpBd,KAAK,CAACC,QADc,EAEpBiB,YAFoB,CAArB;AAIA;AARF,IADD,CAHF,CADD;AAmBA,CApDgE,EAqDjE,iCArDiE,CAAlE;AAwDAxB,SAAS,CACR,kBADQ,EAER,8BAFQ,EAGRI,+BAHQ,CAAT","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"]}
|
|
@@ -18,8 +18,6 @@ import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
const useLastSelectedWidgetArea = () => useSelect(select => {
|
|
21
|
-
var _widgetAreasPost$bloc;
|
|
22
|
-
|
|
23
21
|
const {
|
|
24
22
|
getBlockSelectionEnd,
|
|
25
23
|
getBlockName
|
|
@@ -34,7 +32,7 @@ const useLastSelectedWidgetArea = () => useSelect(select => {
|
|
|
34
32
|
getParentWidgetAreaBlock
|
|
35
33
|
} = select(widgetsEditorStore);
|
|
36
34
|
const widgetAreaBlock = getParentWidgetAreaBlock(selectionEndClientId);
|
|
37
|
-
const widgetAreaBlockClientId = widgetAreaBlock
|
|
35
|
+
const widgetAreaBlockClientId = widgetAreaBlock?.clientId;
|
|
38
36
|
|
|
39
37
|
if (widgetAreaBlockClientId) {
|
|
40
38
|
return widgetAreaBlockClientId;
|
|
@@ -46,7 +44,7 @@ const useLastSelectedWidgetArea = () => useSelect(select => {
|
|
|
46
44
|
getEntityRecord
|
|
47
45
|
} = select(coreStore);
|
|
48
46
|
const widgetAreasPost = getEntityRecord(KIND, POST_TYPE, buildWidgetAreasPostId());
|
|
49
|
-
return widgetAreasPost
|
|
47
|
+
return widgetAreasPost?.blocks[0]?.clientId;
|
|
50
48
|
}, []);
|
|
51
49
|
|
|
52
50
|
export default useLastSelectedWidgetArea;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/hooks/use-last-selected-widget-area.js"],"names":["useSelect","store","blockEditorStore","coreStore","widgetsEditorStore","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","select","getBlockSelectionEnd","getBlockName","selectionEndClientId","getParentWidgetAreaBlock","widgetAreaBlock","widgetAreaBlockClientId","clientId","getEntityRecord","widgetAreasPost","blocks"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,kBAAlB,QAA4C,UAA5C;AACA,SAASC,sBAAT,EAAiCC,IAAjC,EAAuCC,SAAvC,QAAwD,gBAAxD;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,yBAAyB,GAAG,MACjCR,SAAS,CAAIS,MAAF,IAAc;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/hooks/use-last-selected-widget-area.js"],"names":["useSelect","store","blockEditorStore","coreStore","widgetsEditorStore","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","select","getBlockSelectionEnd","getBlockName","selectionEndClientId","getParentWidgetAreaBlock","widgetAreaBlock","widgetAreaBlockClientId","clientId","getEntityRecord","widgetAreasPost","blocks"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,kBAAlB,QAA4C,UAA5C;AACA,SAASC,sBAAT,EAAiCC,IAAjC,EAAuCC,SAAvC,QAAwD,gBAAxD;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,yBAAyB,GAAG,MACjCR,SAAS,CAAIS,MAAF,IAAc;AACxB,QAAM;AAAEC,IAAAA,oBAAF;AAAwBC,IAAAA;AAAxB,MACLF,MAAM,CAAEP,gBAAF,CADP;AAEA,QAAMU,oBAAoB,GAAGF,oBAAoB,EAAjD,CAHwB,CAKxB;;AACA,MAAKC,YAAY,CAAEC,oBAAF,CAAZ,KAAyC,kBAA9C,EAAmE;AAClE,WAAOA,oBAAP;AACA;;AAED,QAAM;AAAEC,IAAAA;AAAF,MAA+BJ,MAAM,CAAEL,kBAAF,CAA3C;AACA,QAAMU,eAAe,GACpBD,wBAAwB,CAAED,oBAAF,CADzB;AAEA,QAAMG,uBAAuB,GAAGD,eAAe,EAAEE,QAAjD;;AAEA,MAAKD,uBAAL,EAA+B;AAC9B,WAAOA,uBAAP;AACA,GAjBuB,CAmBxB;AACA;;;AACA,QAAM;AAAEE,IAAAA;AAAF,MAAsBR,MAAM,CAAEN,SAAF,CAAlC;AACA,QAAMe,eAAe,GAAGD,eAAe,CACtCX,IADsC,EAEtCC,SAFsC,EAGtCF,sBAAsB,EAHgB,CAAvC;AAKA,SAAOa,eAAe,EAAEC,MAAjB,CAAyB,CAAzB,GAA8BH,QAArC;AACA,CA5BQ,EA4BN,EA5BM,CADV;;AA+BA,eAAeR,yBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as widgetsEditorStore } from '../store';\nimport { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';\n\n/**\n * A react hook that returns the client id of the last widget area to have\n * been selected, or to have a selected block within it.\n *\n * @return {string} clientId of the widget area last selected.\n */\nconst useLastSelectedWidgetArea = () =>\n\tuseSelect( ( select ) => {\n\t\tconst { getBlockSelectionEnd, getBlockName } =\n\t\t\tselect( blockEditorStore );\n\t\tconst selectionEndClientId = getBlockSelectionEnd();\n\n\t\t// If the selected block is a widget area, return its clientId.\n\t\tif ( getBlockName( selectionEndClientId ) === 'core/widget-area' ) {\n\t\t\treturn selectionEndClientId;\n\t\t}\n\n\t\tconst { getParentWidgetAreaBlock } = select( widgetsEditorStore );\n\t\tconst widgetAreaBlock =\n\t\t\tgetParentWidgetAreaBlock( selectionEndClientId );\n\t\tconst widgetAreaBlockClientId = widgetAreaBlock?.clientId;\n\n\t\tif ( widgetAreaBlockClientId ) {\n\t\t\treturn widgetAreaBlockClientId;\n\t\t}\n\n\t\t// If no widget area has been selected, return the clientId of the first\n\t\t// area.\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst widgetAreasPost = getEntityRecord(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tbuildWidgetAreasPostId()\n\t\t);\n\t\treturn widgetAreasPost?.blocks[ 0 ]?.clientId;\n\t}, [] );\n\nexport default useLastSelectedWidgetArea;\n"]}
|
|
@@ -13,14 +13,12 @@ import { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';
|
|
|
13
13
|
|
|
14
14
|
const useWidgetLibraryInsertionPoint = () => {
|
|
15
15
|
const firstRootId = useSelect(select => {
|
|
16
|
-
var _widgetAreasPost$bloc;
|
|
17
|
-
|
|
18
16
|
// Default to the first widget area
|
|
19
17
|
const {
|
|
20
18
|
getEntityRecord
|
|
21
19
|
} = select(coreStore);
|
|
22
20
|
const widgetAreasPost = getEntityRecord(KIND, POST_TYPE, buildWidgetAreasPostId());
|
|
23
|
-
return widgetAreasPost
|
|
21
|
+
return widgetAreasPost?.blocks[0]?.clientId;
|
|
24
22
|
}, []);
|
|
25
23
|
return useSelect(select => {
|
|
26
24
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/hooks/use-widget-library-insertion-point.js"],"names":["useSelect","store","blockEditorStore","coreStore","editWidgetsStore","buildWidgetAreasPostId","KIND","POST_TYPE","useWidgetLibraryInsertionPoint","firstRootId","select","getEntityRecord","widgetAreasPost","blocks","clientId","getBlockRootClientId","getBlockSelectionEnd","getBlockOrder","getBlockIndex","insertionPoint","__experimentalGetInsertionPoint","rootClientId","insertionIndex","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,gBAAlB,QAA0C,UAA1C;AACA,SAASC,sBAAT,EAAiCC,IAAjC,EAAuCC,SAAvC,QAAwD,gBAAxD;;AAEA,MAAMC,8BAA8B,GAAG,MAAM;AAC5C,QAAMC,WAAW,GAAGT,SAAS,CAAIU,MAAF,IAAc;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/hooks/use-widget-library-insertion-point.js"],"names":["useSelect","store","blockEditorStore","coreStore","editWidgetsStore","buildWidgetAreasPostId","KIND","POST_TYPE","useWidgetLibraryInsertionPoint","firstRootId","select","getEntityRecord","widgetAreasPost","blocks","clientId","getBlockRootClientId","getBlockSelectionEnd","getBlockOrder","getBlockIndex","insertionPoint","__experimentalGetInsertionPoint","rootClientId","insertionIndex","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,gBAAlB,QAA0C,UAA1C;AACA,SAASC,sBAAT,EAAiCC,IAAjC,EAAuCC,SAAvC,QAAwD,gBAAxD;;AAEA,MAAMC,8BAA8B,GAAG,MAAM;AAC5C,QAAMC,WAAW,GAAGT,SAAS,CAAIU,MAAF,IAAc;AAC5C;AACA,UAAM;AAAEC,MAAAA;AAAF,QAAsBD,MAAM,CAAEP,SAAF,CAAlC;AACA,UAAMS,eAAe,GAAGD,eAAe,CACtCL,IADsC,EAEtCC,SAFsC,EAGtCF,sBAAsB,EAHgB,CAAvC;AAKA,WAAOO,eAAe,EAAEC,MAAjB,CAAyB,CAAzB,GAA8BC,QAArC;AACA,GAT4B,EAS1B,EAT0B,CAA7B;AAWA,SAAOd,SAAS,CACbU,MAAF,IAAc;AACb,UAAM;AACLK,MAAAA,oBADK;AAELC,MAAAA,oBAFK;AAGLC,MAAAA,aAHK;AAILC,MAAAA;AAJK,QAKFR,MAAM,CAAER,gBAAF,CALV;;AAOA,UAAMiB,cAAc,GACnBT,MAAM,CAAEN,gBAAF,CAAN,CAA2BgB,+BAA3B,EADD,CARa,CAWb;AACA;;;AACA,QAAKD,cAAc,CAACE,YAApB,EAAmC;AAClC,aAAOF,cAAP;AACA;;AAED,UAAML,QAAQ,GAAGE,oBAAoB,MAAMP,WAA3C;AACA,UAAMY,YAAY,GAAGN,oBAAoB,CAAED,QAAF,CAAzC,CAlBa,CAoBb;AACA;AACA;;AACA,QAAKA,QAAQ,IAAIO,YAAY,KAAK,EAAlC,EAAuC;AACtC,aAAO;AACNA,QAAAA,YAAY,EAAEP,QADR;AAENQ,QAAAA,cAAc,EAAEL,aAAa,CAAEH,QAAF,CAAb,CAA0BS;AAFpC,OAAP;AAIA;;AAED,WAAO;AACNF,MAAAA,YADM;AAENC,MAAAA,cAAc,EAAEJ,aAAa,CAAEJ,QAAF,CAAb,GAA4B;AAFtC,KAAP;AAIA,GAnCc,EAoCf,CAAEL,WAAF,CApCe,CAAhB;AAsCA,CAlDD;;AAoDA,eAAeD,8BAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editWidgetsStore } from '../store';\nimport { buildWidgetAreasPostId, KIND, POST_TYPE } from '../store/utils';\n\nconst useWidgetLibraryInsertionPoint = () => {\n\tconst firstRootId = useSelect( ( select ) => {\n\t\t// Default to the first widget area\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst widgetAreasPost = getEntityRecord(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tbuildWidgetAreasPostId()\n\t\t);\n\t\treturn widgetAreasPost?.blocks[ 0 ]?.clientId;\n\t}, [] );\n\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetBlockSelectionEnd,\n\t\t\t\tgetBlockOrder,\n\t\t\t\tgetBlockIndex,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst insertionPoint =\n\t\t\t\tselect( editWidgetsStore ).__experimentalGetInsertionPoint();\n\n\t\t\t// \"Browse all\" in the quick inserter will set the rootClientId to the current block.\n\t\t\t// Otherwise, it will just be undefined, and we'll have to handle it differently below.\n\t\t\tif ( insertionPoint.rootClientId ) {\n\t\t\t\treturn insertionPoint;\n\t\t\t}\n\n\t\t\tconst clientId = getBlockSelectionEnd() || firstRootId;\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t// If the selected block is at the root level, it's a widget area and\n\t\t\t// blocks can't be inserted here. Return this block as the root and the\n\t\t\t// last child clientId indicating insertion at the end.\n\t\t\tif ( clientId && rootClientId === '' ) {\n\t\t\t\treturn {\n\t\t\t\t\trootClientId: clientId,\n\t\t\t\t\tinsertionIndex: getBlockOrder( clientId ).length,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\trootClientId,\n\t\t\t\tinsertionIndex: getBlockIndex( clientId ) + 1,\n\t\t\t};\n\t\t},\n\t\t[ firstRootId ]\n\t);\n};\n\nexport default useWidgetLibraryInsertionPoint;\n"]}
|
|
@@ -23,10 +23,9 @@ import { STORE_NAME as editWidgetsStoreName } from './constants';
|
|
|
23
23
|
* @return {Object} The post object.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
export const persistStubPost = (id, blocks) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} = _ref;
|
|
26
|
+
export const persistStubPost = (id, blocks) => ({
|
|
27
|
+
registry
|
|
28
|
+
}) => {
|
|
30
29
|
const stubPost = createStubPost(id, blocks);
|
|
31
30
|
registry.dispatch(coreStore).receiveEntityRecords(KIND, POST_TYPE, stubPost, {
|
|
32
31
|
id: stubPost.id
|
|
@@ -42,15 +41,14 @@ export const persistStubPost = (id, blocks) => _ref => {
|
|
|
42
41
|
* @return {Function} An action creator.
|
|
43
42
|
*/
|
|
44
43
|
|
|
45
|
-
export const saveEditedWidgetAreas = () => async
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = _ref2;
|
|
44
|
+
export const saveEditedWidgetAreas = () => async ({
|
|
45
|
+
select,
|
|
46
|
+
dispatch,
|
|
47
|
+
registry
|
|
48
|
+
}) => {
|
|
51
49
|
const editedWidgetAreas = select.getEditedWidgetAreas();
|
|
52
50
|
|
|
53
|
-
if (!
|
|
51
|
+
if (!editedWidgetAreas?.length) {
|
|
54
52
|
return;
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -75,12 +73,10 @@ export const saveEditedWidgetAreas = () => async _ref2 => {
|
|
|
75
73
|
* @return {Function} An action creator.
|
|
76
74
|
*/
|
|
77
75
|
|
|
78
|
-
export const saveWidgetAreas = widgetAreas => async
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} = _ref3;
|
|
83
|
-
|
|
76
|
+
export const saveWidgetAreas = widgetAreas => async ({
|
|
77
|
+
dispatch,
|
|
78
|
+
registry
|
|
79
|
+
}) => {
|
|
84
80
|
try {
|
|
85
81
|
for (const widgetArea of widgetAreas) {
|
|
86
82
|
await dispatch.saveWidgetArea(widgetArea.id);
|
|
@@ -98,21 +94,17 @@ export const saveWidgetAreas = widgetAreas => async _ref3 => {
|
|
|
98
94
|
* @return {Function} An action creator.
|
|
99
95
|
*/
|
|
100
96
|
|
|
101
|
-
export const saveWidgetArea = widgetAreaId => async
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} = _ref4;
|
|
97
|
+
export const saveWidgetArea = widgetAreaId => async ({
|
|
98
|
+
dispatch,
|
|
99
|
+
select,
|
|
100
|
+
registry
|
|
101
|
+
}) => {
|
|
107
102
|
const widgets = select.getWidgets();
|
|
108
103
|
const post = registry.select(coreStore).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(widgetAreaId)); // Get all widgets from this area
|
|
109
104
|
|
|
110
|
-
const areaWidgets = Object.values(widgets).filter(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} = _ref5;
|
|
114
|
-
return sidebar === widgetAreaId;
|
|
115
|
-
}); // Remove all duplicate reference widget instances for legacy widgets.
|
|
105
|
+
const areaWidgets = Object.values(widgets).filter(({
|
|
106
|
+
sidebar
|
|
107
|
+
}) => sidebar === widgetAreaId); // Remove all duplicate reference widget instances for legacy widgets.
|
|
116
108
|
// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget
|
|
117
109
|
// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to
|
|
118
110
|
// save multiple instances of these in different sidebars you will run into undefined behaviors.
|
|
@@ -173,22 +165,16 @@ export const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
173
165
|
continue;
|
|
174
166
|
}
|
|
175
167
|
|
|
176
|
-
batchTasks.push(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} = _ref6;
|
|
180
|
-
return saveEditedEntityRecord('root', 'widget', widgetId);
|
|
181
|
-
});
|
|
168
|
+
batchTasks.push(({
|
|
169
|
+
saveEditedEntityRecord
|
|
170
|
+
}) => saveEditedEntityRecord('root', 'widget', widgetId));
|
|
182
171
|
} else {
|
|
183
172
|
// Create a new widget.
|
|
184
|
-
batchTasks.push(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
sidebar: widgetAreaId
|
|
190
|
-
});
|
|
191
|
-
});
|
|
173
|
+
batchTasks.push(({
|
|
174
|
+
saveEntityRecord
|
|
175
|
+
}) => saveEntityRecord('root', 'widget', { ...widget,
|
|
176
|
+
sidebar: widgetAreaId
|
|
177
|
+
}));
|
|
192
178
|
}
|
|
193
179
|
|
|
194
180
|
batchMeta.push({
|
|
@@ -199,14 +185,11 @@ export const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
199
185
|
}
|
|
200
186
|
|
|
201
187
|
for (const widget of deletedWidgets) {
|
|
202
|
-
batchTasks.push(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
force: true
|
|
208
|
-
});
|
|
209
|
-
});
|
|
188
|
+
batchTasks.push(({
|
|
189
|
+
deleteEntityRecord
|
|
190
|
+
}) => deleteEntityRecord('root', 'widget', widget.id, {
|
|
191
|
+
force: true
|
|
192
|
+
}));
|
|
210
193
|
}
|
|
211
194
|
|
|
212
195
|
const records = await registry.dispatch(coreStore).__experimentalBatch(batchTasks);
|
|
@@ -225,9 +208,7 @@ export const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
225
208
|
const error = registry.select(coreStore).getLastEntitySaveError('root', 'widget', widget.id);
|
|
226
209
|
|
|
227
210
|
if (error) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
failedWidgetNames.push(((_block$attributes = block.attributes) === null || _block$attributes === void 0 ? void 0 : _block$attributes.name) || (block === null || block === void 0 ? void 0 : block.name));
|
|
211
|
+
failedWidgetNames.push(block.attributes?.name || block?.name);
|
|
231
212
|
}
|
|
232
213
|
|
|
233
214
|
if (!sidebarWidgetsIds[position]) {
|
|
@@ -250,10 +231,9 @@ export const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
|
250
231
|
registry.dispatch(coreStore).receiveEntityRecords(KIND, POST_TYPE, post, undefined);
|
|
251
232
|
};
|
|
252
233
|
|
|
253
|
-
const trySaveWidgetArea = widgetAreaId =>
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
} = _ref9;
|
|
234
|
+
const trySaveWidgetArea = widgetAreaId => ({
|
|
235
|
+
registry
|
|
236
|
+
}) => {
|
|
257
237
|
registry.dispatch(coreStore).saveEditedEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId, {
|
|
258
238
|
throwOnError: true
|
|
259
239
|
});
|
|
@@ -343,10 +323,9 @@ export function setIsListViewOpened(isOpen) {
|
|
|
343
323
|
* @return {Object} Action creator.
|
|
344
324
|
*/
|
|
345
325
|
|
|
346
|
-
export const closeGeneralSidebar = () =>
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
} = _ref10;
|
|
326
|
+
export const closeGeneralSidebar = () => ({
|
|
327
|
+
registry
|
|
328
|
+
}) => {
|
|
350
329
|
registry.dispatch(interfaceStore).disableComplementaryArea(editWidgetsStoreName);
|
|
351
330
|
};
|
|
352
331
|
/**
|
|
@@ -356,23 +335,19 @@ export const closeGeneralSidebar = () => _ref10 => {
|
|
|
356
335
|
* @param {string} widgetAreaId The id of the widget area to move the block to.
|
|
357
336
|
*/
|
|
358
337
|
|
|
359
|
-
export const moveBlockToWidgetArea = (clientId, widgetAreaId) => async
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
} = _ref11;
|
|
338
|
+
export const moveBlockToWidgetArea = (clientId, widgetAreaId) => async ({
|
|
339
|
+
dispatch,
|
|
340
|
+
select,
|
|
341
|
+
registry
|
|
342
|
+
}) => {
|
|
365
343
|
const sourceRootClientId = registry.select(blockEditorStore).getBlockRootClientId(clientId); // Search the top level blocks (widget areas) for the one with the matching
|
|
366
344
|
// id attribute. Makes the assumption that all top-level blocks are widget
|
|
367
345
|
// areas.
|
|
368
346
|
|
|
369
347
|
const widgetAreas = registry.select(blockEditorStore).getBlocks();
|
|
370
|
-
const destinationWidgetAreaBlock = widgetAreas.find(
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
} = _ref12;
|
|
374
|
-
return attributes.id === widgetAreaId;
|
|
375
|
-
});
|
|
348
|
+
const destinationWidgetAreaBlock = widgetAreas.find(({
|
|
349
|
+
attributes
|
|
350
|
+
}) => attributes.id === widgetAreaId);
|
|
376
351
|
const destinationRootClientId = destinationWidgetAreaBlock.clientId; // Get the index for moving to the end of the destination widget area.
|
|
377
352
|
|
|
378
353
|
const destinationInnerBlocksClientIds = registry.select(blockEditorStore).getBlockOrder(destinationRootClientId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/actions.js"],"names":["__","sprintf","store","noticesStore","interfaceStore","getWidgetIdFromBlock","coreStore","blockEditorStore","transformBlockToWidget","buildWidgetAreaPostId","buildWidgetAreasQuery","createStubPost","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","persistStubPost","id","blocks","registry","stubPost","dispatch","receiveEntityRecords","saveEditedWidgetAreas","select","editedWidgetAreas","getEditedWidgetAreas","length","saveWidgetAreas","createSuccessNotice","type","e","createErrorNotice","message","widgetAreas","widgetArea","saveWidgetArea","finishResolution","widgetAreaId","widgets","getWidgets","post","getEditedEntityRecord","areaWidgets","Object","values","filter","sidebar","usedReferenceWidgets","widgetsBlocks","block","attributes","name","includes","push","deletedWidgets","widget","widgetsNewArea","getWidgetAreaForWidgetId","batchMeta","batchTasks","sidebarWidgetsIds","i","widgetId","oldWidget","editEntityRecord","undoIgnore","hasEdits","hasEditsForEntityRecord","saveEditedEntityRecord","saveEntityRecord","position","clientId","deleteEntityRecord","force","records","__experimentalBatch","preservedRecords","record","hasOwnProperty","failedWidgetNames","__internalWidgetId","error","getLastEntitySaveError","Error","join","trySaveWidgetArea","undefined","throwOnError","setWidgetIdForClientId","setWidgetAreasOpenState","widgetAreasOpenState","setIsWidgetAreaOpen","isOpen","setIsInserterOpened","value","setIsListViewOpened","closeGeneralSidebar","disableComplementaryArea","moveBlockToWidgetArea","sourceRootClientId","getBlockRootClientId","getBlocks","destinationWidgetAreaBlock","find","destinationRootClientId","destinationInnerBlocksClientIds","getBlockOrder","destinationIndex","isDestinationWidgetAreaOpen","getIsWidgetAreaOpen","moveBlocksToPosition"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AACA,SAASD,KAAK,IAAIE,cAAlB,QA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AClC;AAAA,QAAE;AAAErD,MAAAA;AAAF,KAAF;AAAA,WAAsBA,UAAU,CAAClC,EAAX,KAAkBqB,YAAxC;AAAA,GADkC,CAAnC;AAGA,QAAMmE,uBAAuB,GAAGF,0BAA0B,CAAC/B,QAA3D,CAZ2C,CAc3C;;AACA,QAAMkC,+BAA+B,GAAGvF,QAAQ,CAC9CK,MADsC,CAC9BlB,gBAD8B,EAEtCqG,aAFsC,CAEvBF,uBAFuB,CAAxC;AAGA,QAAMG,gBAAgB,GAAGF,+BAA+B,CAAC/E,MAAzD,CAlB2C,CAoB3C;;AACA,QAAMkF,2BAA2B,GAAGrF,MAAM,CAACsF,mBAAP,CACnCL,uBADmC,CAApC;;AAIA,MAAK,CAAEI,2BAAP,EAAqC;AACpCxF,IAAAA,QAAQ,CAACuE,mBAAT,CAA8Ba,uBAA9B,EAAuD,IAAvD;AACA,GA3B0C,CA6B3C;;;AACAtF,EAAAA,QAAQ,CACNE,QADF,CACYf,gBADZ,EAEEyG,oBAFF,CAGE,CAAEvC,QAAF,CAHF,EAIE4B,kBAJF,EAKEK,uBALF,EAMEG,gBANF;AAQA,CAxCK","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as interfaceStore } from '@wordpress/interface';\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 { transformBlockToWidget } from './transformers';\nimport {\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasQuery,\n\tcreateStubPost,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\n/**\n * Persists a stub post with given ID to core data store. The post is meant to be in-memory only and\n * shouldn't be saved via the API.\n *\n * @param {string} id Post ID.\n * @param {Array} blocks Blocks the post should consist of.\n * @return {Object} The post object.\n */\nexport const persistStubPost =\n\t( id, blocks ) =>\n\t( { registry } ) => {\n\t\tconst stubPost = createStubPost( id, blocks );\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tstubPost,\n\t\t\t\t{ id: stubPost.id },\n\t\t\t\tfalse\n\t\t\t);\n\t\treturn stubPost;\n\t};\n\n/**\n * Converts all the blocks from edited widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * Creates a snackbar notice on either success or error.\n *\n * @return {Function} An action creator.\n */\nexport const saveEditedWidgetAreas =\n\t() =>\n\tasync ( { select, dispatch, registry } ) => {\n\t\tconst editedWidgetAreas = select.getEditedWidgetAreas();\n\t\tif ( ! editedWidgetAreas?.length ) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tawait dispatch.saveWidgetAreas( editedWidgetAreas );\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createSuccessNotice( __( 'Widgets saved.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t} catch ( e ) {\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice(\n\t\t\t\t/* translators: %s: The error message. */\n\t\t\t\tsprintf( __( 'There was an error. %s' ), e.message ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from specified widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {Object[]} widgetAreas Widget areas to save.\n * @return {Function} An action creator.\n */\nexport const saveWidgetAreas =\n\t( widgetAreas ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\ttry {\n\t\t\tfor ( const widgetArea of widgetAreas ) {\n\t\t\t\tawait dispatch.saveWidgetArea( widgetArea.id );\n\t\t\t}\n\t\t} finally {\n\t\t\t// saveEditedEntityRecord resets the resolution status, let's fix it manually.\n\t\t\tawait registry\n\t\t\t\t.dispatch( coreStore )\n\t\t\t\t.finishResolution(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tbuildWidgetAreasQuery()\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from a widget area specified by ID into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {string} widgetAreaId ID of the widget area to process.\n * @return {Function} An action creator.\n */\nexport const saveWidgetArea =\n\t( widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst widgets = select.getWidgets();\n\n\t\tconst post = registry\n\t\t\t.select( coreStore )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetAreaId )\n\t\t\t);\n\n\t\t// Get all widgets from this area\n\t\tconst areaWidgets = Object.values( widgets ).filter(\n\t\t\t( { sidebar } ) => sidebar === widgetAreaId\n\t\t);\n\n\t\t// Remove all duplicate reference widget instances for legacy widgets.\n\t\t// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget\n\t\t// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to\n\t\t// save multiple instances of these in different sidebars you will run into undefined behaviors.\n\t\tconst usedReferenceWidgets = [];\n\t\tconst widgetsBlocks = post.blocks.filter( ( block ) => {\n\t\t\tconst { id } = block.attributes;\n\n\t\t\tif ( block.name === 'core/legacy-widget' && id ) {\n\t\t\t\tif ( usedReferenceWidgets.includes( id ) ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tusedReferenceWidgets.push( id );\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\n\t\t// Determine which widgets have been deleted. We can tell if a widget is\n\t\t// deleted and not just moved to a different area by looking to see if\n\t\t// getWidgetAreaForWidgetId() finds something.\n\t\tconst deletedWidgets = [];\n\t\tfor ( const widget of areaWidgets ) {\n\t\t\tconst widgetsNewArea = select.getWidgetAreaForWidgetId( widget.id );\n\t\t\tif ( ! widgetsNewArea ) {\n\t\t\t\tdeletedWidgets.push( widget );\n\t\t\t}\n\t\t}\n\n\t\tconst batchMeta = [];\n\t\tconst batchTasks = [];\n\t\tconst sidebarWidgetsIds = [];\n\t\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\t\tconst block = widgetsBlocks[ i ];\n\t\t\tconst widgetId = getWidgetIdFromBlock( block );\n\t\t\tconst oldWidget = widgets[ widgetId ];\n\t\t\tconst widget = transformBlockToWidget( block, oldWidget );\n\n\t\t\t// We'll replace the null widgetId after save, but we track it here\n\t\t\t// since order is important.\n\t\t\tsidebarWidgetsIds.push( widgetId );\n\n\t\t\t// Check oldWidget as widgetId might refer to an ID which has been\n\t\t\t// deleted, e.g. if a deleted block is restored via undo after saving.\n\t\t\tif ( oldWidget ) {\n\t\t\t\t// Update an existing widget.\n\t\t\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'widget',\n\t\t\t\t\twidgetId,\n\t\t\t\t\t{\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t},\n\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t);\n\n\t\t\t\tconst hasEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord( 'root', 'widget', widgetId );\n\n\t\t\t\tif ( ! hasEdits ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tbatchTasks.push( ( { saveEditedEntityRecord } ) =>\n\t\t\t\t\tsaveEditedEntityRecord( 'root', 'widget', widgetId )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Create a new widget.\n\t\t\t\tbatchTasks.push( ( { saveEntityRecord } ) =>\n\t\t\t\t\tsaveEntityRecord( 'root', 'widget', {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tbatchMeta.push( {\n\t\t\t\tblock,\n\t\t\t\tposition: i,\n\t\t\t\tclientId: block.clientId,\n\t\t\t} );\n\t\t}\n\t\tfor ( const widget of deletedWidgets ) {\n\t\t\tbatchTasks.push( ( { deleteEntityRecord } ) =>\n\t\t\t\tdeleteEntityRecord( 'root', 'widget', widget.id, {\n\t\t\t\t\tforce: true,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tconst records = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.__experimentalBatch( batchTasks );\n\t\tconst preservedRecords = records.filter(\n\t\t\t( record ) => ! record.hasOwnProperty( 'deleted' )\n\t\t);\n\n\t\tconst failedWidgetNames = [];\n\n\t\tfor ( let i = 0; i < preservedRecords.length; i++ ) {\n\t\t\tconst widget = preservedRecords[ i ];\n\t\t\tconst { block, position } = batchMeta[ i ];\n\n\t\t\t// Set __internalWidgetId on the block. This will be persisted to the\n\t\t\t// store when we dispatch receiveEntityRecords( post ) below.\n\t\t\tpost.blocks[ position ].attributes.__internalWidgetId = widget.id;\n\n\t\t\tconst error = registry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getLastEntitySaveError( 'root', 'widget', widget.id );\n\t\t\tif ( error ) {\n\t\t\t\tfailedWidgetNames.push( block.attributes?.name || block?.name );\n\t\t\t}\n\n\t\t\tif ( ! sidebarWidgetsIds[ position ] ) {\n\t\t\t\tsidebarWidgetsIds[ position ] = widget.id;\n\t\t\t}\n\t\t}\n\n\t\tif ( failedWidgetNames.length ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: List of widget names */\n\t\t\t\t\t__( 'Could not save the following widgets: %s.' ),\n\t\t\t\t\tfailedWidgetNames.join( ', ' )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\twidgetAreaId,\n\t\t\t{\n\t\t\t\twidgets: sidebarWidgetsIds,\n\t\t\t},\n\t\t\t{ undoIgnore: true }\n\t\t);\n\n\t\tdispatch( trySaveWidgetArea( widgetAreaId ) );\n\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords( KIND, POST_TYPE, post, undefined );\n\t};\n\nconst trySaveWidgetArea =\n\t( widgetAreaId ) =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\twidgetAreaId,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t};\n\n/**\n * Sets the clientId stored for a particular widgetId.\n *\n * @param {number} clientId Client id.\n * @param {number} widgetId Widget id.\n *\n * @return {Object} Action.\n */\nexport function setWidgetIdForClientId( clientId, widgetId ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_ID_FOR_CLIENT_ID',\n\t\tclientId,\n\t\twidgetId,\n\t};\n}\n\n/**\n * Sets the open state of all the widget areas.\n *\n * @param {Object} widgetAreasOpenState The open states of all the widget areas.\n *\n * @return {Object} Action.\n */\nexport function setWidgetAreasOpenState( widgetAreasOpenState ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_AREAS_OPEN_STATE',\n\t\twidgetAreasOpenState,\n\t};\n}\n\n/**\n * Sets the open state of the widget area.\n *\n * @param {string} clientId The clientId of the widget area.\n * @param {boolean} isOpen Whether the widget area should be opened.\n *\n * @return {Object} Action.\n */\nexport function setIsWidgetAreaOpen( clientId, isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_WIDGET_AREA_OPEN',\n\t\tclientId,\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the list view.\n *\n * @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.\n * @return {Object} Action object.\n */\nexport function setIsListViewOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_LIST_VIEW_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object signalling that the user closed the sidebar.\n *\n * @return {Object} Action creator.\n */\nexport const closeGeneralSidebar =\n\t() =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( interfaceStore )\n\t\t\t.disableComplementaryArea( editWidgetsStoreName );\n\t};\n\n/**\n * Action that handles moving a block between widget areas\n *\n * @param {string} clientId The clientId of the block to move.\n * @param {string} widgetAreaId The id of the widget area to move the block to.\n */\nexport const moveBlockToWidgetArea =\n\t( clientId, widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst sourceRootClientId = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockRootClientId( clientId );\n\n\t\t// Search the top level blocks (widget areas) for the one with the matching\n\t\t// id attribute. Makes the assumption that all top-level blocks are widget\n\t\t// areas.\n\t\tconst widgetAreas = registry.select( blockEditorStore ).getBlocks();\n\t\tconst destinationWidgetAreaBlock = widgetAreas.find(\n\t\t\t( { attributes } ) => attributes.id === widgetAreaId\n\t\t);\n\t\tconst destinationRootClientId = destinationWidgetAreaBlock.clientId;\n\n\t\t// Get the index for moving to the end of the destination widget area.\n\t\tconst destinationInnerBlocksClientIds = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockOrder( destinationRootClientId );\n\t\tconst destinationIndex = destinationInnerBlocksClientIds.length;\n\n\t\t// Reveal the widget area, if it's not open.\n\t\tconst isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(\n\t\t\tdestinationRootClientId\n\t\t);\n\n\t\tif ( ! isDestinationWidgetAreaOpen ) {\n\t\t\tdispatch.setIsWidgetAreaOpen( destinationRootClientId, true );\n\t\t}\n\n\t\t// Move the block.\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.moveBlocksToPosition(\n\t\t\t\t[ clientId ],\n\t\t\t\tsourceRootClientId,\n\t\t\t\tdestinationRootClientId,\n\t\t\t\tdestinationIndex\n\t\t\t);\n\t};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/actions.js"],"names":["__","sprintf","store","noticesStore","interfaceStore","getWidgetIdFromBlock","coreStore","blockEditorStore","transformBlockToWidget","buildWidgetAreaPostId","buildWidgetAreasQuery","createStubPost","KIND","POST_TYPE","WIDGET_AREA_ENTITY_TYPE","STORE_NAME","editWidgetsStoreName","persistStubPost","id","blocks","registry","stubPost","dispatch","receiveEntityRecords","saveEditedWidgetAreas","select","editedWidgetAreas","getEditedWidgetAreas","length","saveWidgetAreas","createSuccessNotice","type","e","createErrorNotice","message","widgetAreas","widgetArea","saveWidgetArea","finishResolution","widgetAreaId","widgets","getWidgets","post","getEditedEntityRecord","areaWidgets","Object","values","filter","sidebar","usedReferenceWidgets","widgetsBlocks","block","attributes","name","includes","push","deletedWidgets","widget","widgetsNewArea","getWidgetAreaForWidgetId","batchMeta","batchTasks","sidebarWidgetsIds","i","widgetId","oldWidget","editEntityRecord","undoIgnore","hasEdits","hasEditsForEntityRecord","saveEditedEntityRecord","saveEntityRecord","position","clientId","deleteEntityRecord","force","records","__experimentalBatch","preservedRecords","record","hasOwnProperty","failedWidgetNames","__internalWidgetId","error","getLastEntitySaveError","Error","join","trySaveWidgetArea","undefined","throwOnError","setWidgetIdForClientId","setWidgetAreasOpenState","widgetAreasOpenState","setIsWidgetAreaOpen","isOpen","setIsInserterOpened","value","setIsListViewOpened","closeGeneralSidebar","disableComplementaryArea","moveBlockToWidgetArea","sourceRootClientId","getBlockRootClientId","getBlocks","destinationWidgetAreaBlock","find","destinationRootClientId","destinationInnerBlocksClientIds","getBlockOrder","destinationIndex","isDestinationWidgetAreaOpen","getIsWidgetAreaOpen","moveBlocksToPosition"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AACA,SAASD,KAAK,IAAIE,cAAlB,QAAwC,sBAAxC;AACA,SAASC,oBAAT,QAAqC,oBAArC;AACA,SAASH,KAAK,IAAII,SAAlB,QAAmC,sBAAnC;AACA,SAASJ,KAAK,IAAIK,gBAAlB,QAA0C,yBAA1C;AAEA;AACA;AACA;;AACA,SAASC,sBAAT,QAAuC,gBAAvC;AACA,SACCC,qBADD,EAECC,qBAFD,EAGCC,cAHD,EAICC,IAJD,EAKCC,SALD,EAMCC,uBAND,QAOO,SAPP;AAQA,SAASC,UAAU,IAAIC,oBAAvB,QAAmD,aAAnD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,eAAe,GAC3B,CAAEC,EAAF,EAAMC,MAAN,KACA,CAAE;AAAEC,EAAAA;AAAF,CAAF,KAAoB;AACnB,QAAMC,QAAQ,GAAGV,cAAc,CAAEO,EAAF,EAAMC,MAAN,CAA/B;AACAC,EAAAA,QAAQ,CACNE,QADF,CACYhB,SADZ,EAEEiB,oBAFF,CAGEX,IAHF,EAIEC,SAJF,EAKEQ,QALF,EAME;AAAEH,IAAAA,EAAE,EAAEG,QAAQ,CAACH;AAAf,GANF,EAOE,KAPF;AASA,SAAOG,QAAP;AACA,CAdK;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,qBAAqB,GACjC,MACA,OAAQ;AAAEC,EAAAA,MAAF;AAAUH,EAAAA,QAA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MtC,WAAW,GAAGf,QAAQ,CAACK,MAAT,CAAiBlB,gBAAjB,EAAoCgG,SAApC,EAApB;AACA,QAAMC,0BAA0B,GAAGrE,WAAW,CAACsE,IAAZ,CAClC,CAAE;AAAErD,IAAAA;AAAF,GAAF,KAAsBA,UAAU,CAAClC,EAAX,KAAkBqB,YADN,CAAnC;AAGA,QAAMmE,uBAAuB,GAAGF,0BAA0B,CAAC/B,QAA3D,CAZ2C,CAc3C;;AACA,QAAMkC,+BAA+B,GAAGvF,QAAQ,CAC9CK,MADsC,CAC9BlB,gBAD8B,EAEtCqG,aAFsC,CAEvBF,uBAFuB,CAAxC;AAGA,QAAMG,gBAAgB,GAAGF,+BAA+B,CAAC/E,MAAzD,CAlB2C,CAoB3C;;AACA,QAAMkF,2BAA2B,GAAGrF,MAAM,CAACsF,mBAAP,CACnCL,uBADmC,CAApC;;AAIA,MAAK,CAAEI,2BAAP,EAAqC;AACpCxF,IAAAA,QAAQ,CAACuE,mBAAT,CAA8Ba,uBAA9B,EAAuD,IAAvD;AACA,GA3B0C,CA6B3C;;;AACAtF,EAAAA,QAAQ,CACNE,QADF,CACYf,gBADZ,EAEEyG,oBAFF,CAGE,CAAEvC,QAAF,CAHF,EAIE4B,kBAJF,EAKEK,uBALF,EAMEG,gBANF;AAQA,CAxCK","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as interfaceStore } from '@wordpress/interface';\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 { transformBlockToWidget } from './transformers';\nimport {\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasQuery,\n\tcreateStubPost,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\n/**\n * Persists a stub post with given ID to core data store. The post is meant to be in-memory only and\n * shouldn't be saved via the API.\n *\n * @param {string} id Post ID.\n * @param {Array} blocks Blocks the post should consist of.\n * @return {Object} The post object.\n */\nexport const persistStubPost =\n\t( id, blocks ) =>\n\t( { registry } ) => {\n\t\tconst stubPost = createStubPost( id, blocks );\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tstubPost,\n\t\t\t\t{ id: stubPost.id },\n\t\t\t\tfalse\n\t\t\t);\n\t\treturn stubPost;\n\t};\n\n/**\n * Converts all the blocks from edited widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * Creates a snackbar notice on either success or error.\n *\n * @return {Function} An action creator.\n */\nexport const saveEditedWidgetAreas =\n\t() =>\n\tasync ( { select, dispatch, registry } ) => {\n\t\tconst editedWidgetAreas = select.getEditedWidgetAreas();\n\t\tif ( ! editedWidgetAreas?.length ) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tawait dispatch.saveWidgetAreas( editedWidgetAreas );\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createSuccessNotice( __( 'Widgets saved.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t} catch ( e ) {\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice(\n\t\t\t\t/* translators: %s: The error message. */\n\t\t\t\tsprintf( __( 'There was an error. %s' ), e.message ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from specified widget areas into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {Object[]} widgetAreas Widget areas to save.\n * @return {Function} An action creator.\n */\nexport const saveWidgetAreas =\n\t( widgetAreas ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\ttry {\n\t\t\tfor ( const widgetArea of widgetAreas ) {\n\t\t\t\tawait dispatch.saveWidgetArea( widgetArea.id );\n\t\t\t}\n\t\t} finally {\n\t\t\t// saveEditedEntityRecord resets the resolution status, let's fix it manually.\n\t\t\tawait registry\n\t\t\t\t.dispatch( coreStore )\n\t\t\t\t.finishResolution(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tbuildWidgetAreasQuery()\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Converts all the blocks from a widget area specified by ID into widgets,\n * and submits a batch request to save everything at once.\n *\n * @param {string} widgetAreaId ID of the widget area to process.\n * @return {Function} An action creator.\n */\nexport const saveWidgetArea =\n\t( widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst widgets = select.getWidgets();\n\n\t\tconst post = registry\n\t\t\t.select( coreStore )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetAreaId )\n\t\t\t);\n\n\t\t// Get all widgets from this area\n\t\tconst areaWidgets = Object.values( widgets ).filter(\n\t\t\t( { sidebar } ) => sidebar === widgetAreaId\n\t\t);\n\n\t\t// Remove all duplicate reference widget instances for legacy widgets.\n\t\t// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget\n\t\t// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to\n\t\t// save multiple instances of these in different sidebars you will run into undefined behaviors.\n\t\tconst usedReferenceWidgets = [];\n\t\tconst widgetsBlocks = post.blocks.filter( ( block ) => {\n\t\t\tconst { id } = block.attributes;\n\n\t\t\tif ( block.name === 'core/legacy-widget' && id ) {\n\t\t\t\tif ( usedReferenceWidgets.includes( id ) ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tusedReferenceWidgets.push( id );\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\n\t\t// Determine which widgets have been deleted. We can tell if a widget is\n\t\t// deleted and not just moved to a different area by looking to see if\n\t\t// getWidgetAreaForWidgetId() finds something.\n\t\tconst deletedWidgets = [];\n\t\tfor ( const widget of areaWidgets ) {\n\t\t\tconst widgetsNewArea = select.getWidgetAreaForWidgetId( widget.id );\n\t\t\tif ( ! widgetsNewArea ) {\n\t\t\t\tdeletedWidgets.push( widget );\n\t\t\t}\n\t\t}\n\n\t\tconst batchMeta = [];\n\t\tconst batchTasks = [];\n\t\tconst sidebarWidgetsIds = [];\n\t\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\t\tconst block = widgetsBlocks[ i ];\n\t\t\tconst widgetId = getWidgetIdFromBlock( block );\n\t\t\tconst oldWidget = widgets[ widgetId ];\n\t\t\tconst widget = transformBlockToWidget( block, oldWidget );\n\n\t\t\t// We'll replace the null widgetId after save, but we track it here\n\t\t\t// since order is important.\n\t\t\tsidebarWidgetsIds.push( widgetId );\n\n\t\t\t// Check oldWidget as widgetId might refer to an ID which has been\n\t\t\t// deleted, e.g. if a deleted block is restored via undo after saving.\n\t\t\tif ( oldWidget ) {\n\t\t\t\t// Update an existing widget.\n\t\t\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'widget',\n\t\t\t\t\twidgetId,\n\t\t\t\t\t{\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t},\n\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t);\n\n\t\t\t\tconst hasEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord( 'root', 'widget', widgetId );\n\n\t\t\t\tif ( ! hasEdits ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tbatchTasks.push( ( { saveEditedEntityRecord } ) =>\n\t\t\t\t\tsaveEditedEntityRecord( 'root', 'widget', widgetId )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Create a new widget.\n\t\t\t\tbatchTasks.push( ( { saveEntityRecord } ) =>\n\t\t\t\t\tsaveEntityRecord( 'root', 'widget', {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tbatchMeta.push( {\n\t\t\t\tblock,\n\t\t\t\tposition: i,\n\t\t\t\tclientId: block.clientId,\n\t\t\t} );\n\t\t}\n\t\tfor ( const widget of deletedWidgets ) {\n\t\t\tbatchTasks.push( ( { deleteEntityRecord } ) =>\n\t\t\t\tdeleteEntityRecord( 'root', 'widget', widget.id, {\n\t\t\t\t\tforce: true,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tconst records = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.__experimentalBatch( batchTasks );\n\t\tconst preservedRecords = records.filter(\n\t\t\t( record ) => ! record.hasOwnProperty( 'deleted' )\n\t\t);\n\n\t\tconst failedWidgetNames = [];\n\n\t\tfor ( let i = 0; i < preservedRecords.length; i++ ) {\n\t\t\tconst widget = preservedRecords[ i ];\n\t\t\tconst { block, position } = batchMeta[ i ];\n\n\t\t\t// Set __internalWidgetId on the block. This will be persisted to the\n\t\t\t// store when we dispatch receiveEntityRecords( post ) below.\n\t\t\tpost.blocks[ position ].attributes.__internalWidgetId = widget.id;\n\n\t\t\tconst error = registry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getLastEntitySaveError( 'root', 'widget', widget.id );\n\t\t\tif ( error ) {\n\t\t\t\tfailedWidgetNames.push( block.attributes?.name || block?.name );\n\t\t\t}\n\n\t\t\tif ( ! sidebarWidgetsIds[ position ] ) {\n\t\t\t\tsidebarWidgetsIds[ position ] = widget.id;\n\t\t\t}\n\t\t}\n\n\t\tif ( failedWidgetNames.length ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: List of widget names */\n\t\t\t\t\t__( 'Could not save the following widgets: %s.' ),\n\t\t\t\t\tfailedWidgetNames.join( ', ' )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\twidgetAreaId,\n\t\t\t{\n\t\t\t\twidgets: sidebarWidgetsIds,\n\t\t\t},\n\t\t\t{ undoIgnore: true }\n\t\t);\n\n\t\tdispatch( trySaveWidgetArea( widgetAreaId ) );\n\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.receiveEntityRecords( KIND, POST_TYPE, post, undefined );\n\t};\n\nconst trySaveWidgetArea =\n\t( widgetAreaId ) =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\twidgetAreaId,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t};\n\n/**\n * Sets the clientId stored for a particular widgetId.\n *\n * @param {number} clientId Client id.\n * @param {number} widgetId Widget id.\n *\n * @return {Object} Action.\n */\nexport function setWidgetIdForClientId( clientId, widgetId ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_ID_FOR_CLIENT_ID',\n\t\tclientId,\n\t\twidgetId,\n\t};\n}\n\n/**\n * Sets the open state of all the widget areas.\n *\n * @param {Object} widgetAreasOpenState The open states of all the widget areas.\n *\n * @return {Object} Action.\n */\nexport function setWidgetAreasOpenState( widgetAreasOpenState ) {\n\treturn {\n\t\ttype: 'SET_WIDGET_AREAS_OPEN_STATE',\n\t\twidgetAreasOpenState,\n\t};\n}\n\n/**\n * Sets the open state of the widget area.\n *\n * @param {string} clientId The clientId of the widget area.\n * @param {boolean} isOpen Whether the widget area should be opened.\n *\n * @return {Object} Action.\n */\nexport function setIsWidgetAreaOpen( clientId, isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_WIDGET_AREA_OPEN',\n\t\tclientId,\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the list view.\n *\n * @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.\n * @return {Object} Action object.\n */\nexport function setIsListViewOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_LIST_VIEW_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object signalling that the user closed the sidebar.\n *\n * @return {Object} Action creator.\n */\nexport const closeGeneralSidebar =\n\t() =>\n\t( { registry } ) => {\n\t\tregistry\n\t\t\t.dispatch( interfaceStore )\n\t\t\t.disableComplementaryArea( editWidgetsStoreName );\n\t};\n\n/**\n * Action that handles moving a block between widget areas\n *\n * @param {string} clientId The clientId of the block to move.\n * @param {string} widgetAreaId The id of the widget area to move the block to.\n */\nexport const moveBlockToWidgetArea =\n\t( clientId, widgetAreaId ) =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst sourceRootClientId = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockRootClientId( clientId );\n\n\t\t// Search the top level blocks (widget areas) for the one with the matching\n\t\t// id attribute. Makes the assumption that all top-level blocks are widget\n\t\t// areas.\n\t\tconst widgetAreas = registry.select( blockEditorStore ).getBlocks();\n\t\tconst destinationWidgetAreaBlock = widgetAreas.find(\n\t\t\t( { attributes } ) => attributes.id === widgetAreaId\n\t\t);\n\t\tconst destinationRootClientId = destinationWidgetAreaBlock.clientId;\n\n\t\t// Get the index for moving to the end of the destination widget area.\n\t\tconst destinationInnerBlocksClientIds = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlockOrder( destinationRootClientId );\n\t\tconst destinationIndex = destinationInnerBlocksClientIds.length;\n\n\t\t// Reveal the widget area, if it's not open.\n\t\tconst isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(\n\t\t\tdestinationRootClientId\n\t\t);\n\n\t\tif ( ! isDestinationWidgetAreaOpen ) {\n\t\t\tdispatch.setIsWidgetAreaOpen( destinationRootClientId, true );\n\t\t}\n\n\t\t// Move the block.\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.moveBlocksToPosition(\n\t\t\t\t[ clientId ],\n\t\t\t\tsourceRootClientId,\n\t\t\t\tdestinationRootClientId,\n\t\t\t\tdestinationIndex\n\t\t\t);\n\t};\n"]}
|
|
@@ -40,9 +40,7 @@ register(store); // This package uses a few in-memory post types as wrappers for
|
|
|
40
40
|
// bound to fail anyway.
|
|
41
41
|
|
|
42
42
|
apiFetch.use(function (options, next) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (((_options$path = options.path) === null || _options$path === void 0 ? void 0 : _options$path.indexOf('/wp/v2/types/widget-area')) === 0) {
|
|
43
|
+
if (options.path?.indexOf('/wp/v2/types/widget-area') === 0) {
|
|
46
44
|
return Promise.resolve({});
|
|
47
45
|
}
|
|
48
46
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/index.js"],"names":["apiFetch","createReduxStore","register","reducer","resolvers","selectors","actions","STORE_NAME","storeConfig","store","use","options","next","path","indexOf","Promise","resolve"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,SAASC,UAAT,QAA2B,aAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG;AACnBL,EAAAA,OADmB;AAEnBE,EAAAA,SAFmB;AAGnBD,EAAAA,SAHmB;AAInBE,EAAAA;AAJmB,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,KAAK,GAAGR,gBAAgB,CAAEM,UAAF,EAAcC,WAAd,CAA9B;AACPN,QAAQ,CAAEO,KAAF,CAAR,C,CAEA;AACA;AACA;;AACAT,QAAQ,CAACU,GAAT,CAAc,UAAWC,OAAX,EAAoBC,IAApB,EAA2B;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/index.js"],"names":["apiFetch","createReduxStore","register","reducer","resolvers","selectors","actions","STORE_NAME","storeConfig","store","use","options","next","path","indexOf","Promise","resolve"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,SAASC,UAAT,QAA2B,aAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG;AACnBL,EAAAA,OADmB;AAEnBE,EAAAA,SAFmB;AAGnBD,EAAAA,SAHmB;AAInBE,EAAAA;AAJmB,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,KAAK,GAAGR,gBAAgB,CAAEM,UAAF,EAAcC,WAAd,CAA9B;AACPN,QAAQ,CAAEO,KAAF,CAAR,C,CAEA;AACA;AACA;;AACAT,QAAQ,CAACU,GAAT,CAAc,UAAWC,OAAX,EAAoBC,IAApB,EAA2B;AACxC,MAAKD,OAAO,CAACE,IAAR,EAAcC,OAAd,CAAuB,0BAAvB,MAAwD,CAA7D,EAAiE;AAChE,WAAOC,OAAO,CAACC,OAAR,CAAiB,EAAjB,CAAP;AACA;;AAED,SAAOJ,IAAI,CAAED,OAAF,CAAX;AACA,CAND","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as resolvers from './resolvers';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport { STORE_NAME } from './constants';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#register\n *\n * @type {Object}\n */\nconst storeConfig = {\n\treducer,\n\tselectors,\n\tresolvers,\n\tactions,\n};\n\n/**\n * Store definition for the edit widgets namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\nregister( store );\n\n// This package uses a few in-memory post types as wrappers for convenience.\n// This middleware prevents any network requests related to these types as they are\n// bound to fail anyway.\napiFetch.use( function ( options, next ) {\n\tif ( options.path?.indexOf( '/wp/v2/types/widget-area' ) === 0 ) {\n\t\treturn Promise.resolve( {} );\n\t}\n\n\treturn next( options );\n} );\n"]}
|
|
@@ -11,9 +11,7 @@ import { combineReducers } from '@wordpress/data';
|
|
|
11
11
|
* @return {Array} Updated state.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export function widgetAreasOpenState() {
|
|
15
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
14
|
+
export function widgetAreasOpenState(state = {}, action) {
|
|
17
15
|
const {
|
|
18
16
|
type
|
|
19
17
|
} = action;
|
|
@@ -51,10 +49,7 @@ export function widgetAreasOpenState() {
|
|
|
51
49
|
* @param {Object} action Dispatched action.
|
|
52
50
|
*/
|
|
53
51
|
|
|
54
|
-
export function blockInserterPanel() {
|
|
55
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
56
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
57
|
-
|
|
52
|
+
export function blockInserterPanel(state = false, action) {
|
|
58
53
|
switch (action.type) {
|
|
59
54
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
60
55
|
return action.isOpen ? false : state;
|
|
@@ -75,10 +70,7 @@ export function blockInserterPanel() {
|
|
|
75
70
|
* @param {Object} action Dispatched action.
|
|
76
71
|
*/
|
|
77
72
|
|
|
78
|
-
export function listViewPanel() {
|
|
79
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
80
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
81
|
-
|
|
73
|
+
export function listViewPanel(state = false, action) {
|
|
82
74
|
switch (action.type) {
|
|
83
75
|
case 'SET_IS_INSERTER_OPENED':
|
|
84
76
|
return action.value ? false : state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/reducer.js"],"names":["combineReducers","widgetAreasOpenState","state","action","type","clientId","isOpen","blockInserterPanel","value","listViewPanel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/reducer.js"],"names":["combineReducers","widgetAreasOpenState","state","action","type","clientId","isOpen","blockInserterPanel","value","listViewPanel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CAA+BC,KAAK,GAAG,EAAvC,EAA2CC,MAA3C,EAAoD;AAC1D,QAAM;AAAEC,IAAAA;AAAF,MAAWD,MAAjB;;AACA,UAASC,IAAT;AACC,SAAK,6BAAL;AAAoC;AACnC,eAAOD,MAAM,CAACF,oBAAd;AACA;;AACD,SAAK,yBAAL;AAAgC;AAC/B,cAAM;AAAEI,UAAAA,QAAF;AAAYC,UAAAA;AAAZ,YAAuBH,MAA7B;AACA,eAAO,EACN,GAAGD,KADG;AAEN,WAAEG,QAAF,GAAcC;AAFR,SAAP;AAIA;;AACD;AAAS;AACR,eAAOJ,KAAP;AACA;AAbF;AAeA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,kBAAT,CAA6BL,KAAK,GAAG,KAArC,EAA4CC,MAA5C,EAAqD;AAC3D,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,yBAAL;AACC,aAAOD,MAAM,CAACG,MAAP,GAAgB,KAAhB,GAAwBJ,KAA/B;;AACD,SAAK,wBAAL;AACC,aAAOC,MAAM,CAACK,KAAd;AAJF;;AAMA,SAAON,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASO,aAAT,CAAwBP,KAAK,GAAG,KAAhC,EAAuCC,MAAvC,EAAgD;AACtD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,wBAAL;AACC,aAAOD,MAAM,CAACK,KAAP,GAAe,KAAf,GAAuBN,KAA9B;;AACD,SAAK,yBAAL;AACC,aAAOC,MAAM,CAACG,MAAd;AAJF;;AAMA,SAAOJ,KAAP;AACA;AAED,eAAeF,eAAe,CAAE;AAC/BO,EAAAA,kBAD+B;AAE/BE,EAAAA,aAF+B;AAG/BR,EAAAA;AAH+B,CAAF,CAA9B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Controls the open state of the widget areas.\n *\n * @param {Object} state Redux state.\n * @param {Object} action Redux action.\n *\n * @return {Array} Updated state.\n */\nexport function widgetAreasOpenState( state = {}, action ) {\n\tconst { type } = action;\n\tswitch ( type ) {\n\t\tcase 'SET_WIDGET_AREAS_OPEN_STATE': {\n\t\t\treturn action.widgetAreasOpenState;\n\t\t}\n\t\tcase 'SET_IS_WIDGET_AREA_OPEN': {\n\t\t\tconst { clientId, isOpen } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ clientId ]: isOpen,\n\t\t\t};\n\t\t}\n\t\tdefault: {\n\t\t\treturn state;\n\t\t}\n\t}\n}\n\n/**\n * Reducer to set the block inserter panel open or closed.\n *\n * Note: this reducer interacts with the list view panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function blockInserterPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen ? false : state;\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value;\n\t}\n\treturn state;\n}\n\n/**\n * Reducer to set the list view panel open or closed.\n *\n * Note: this reducer interacts with the inserter panel reducer\n * to make sure that only one of the two panels is open at the same time.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n */\nexport function listViewPanel( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IS_INSERTER_OPENED':\n\t\t\treturn action.value ? false : state;\n\t\tcase 'SET_IS_LIST_VIEW_OPENED':\n\t\t\treturn action.isOpen;\n\t}\n\treturn state;\n}\n\nexport default combineReducers( {\n\tblockInserterPanel,\n\tlistViewPanel,\n\twidgetAreasOpenState,\n} );\n"]}
|
|
@@ -20,11 +20,10 @@ import { transformWidgetToBlock } from './transformers';
|
|
|
20
20
|
* @return {Function} An action creator.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
export const getWidgetAreas = () => async
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} = _ref;
|
|
23
|
+
export const getWidgetAreas = () => async ({
|
|
24
|
+
dispatch,
|
|
25
|
+
registry
|
|
26
|
+
}) => {
|
|
28
27
|
const query = buildWidgetAreasQuery();
|
|
29
28
|
const widgetAreas = await registry.resolveSelect(coreStore).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
|
|
30
29
|
const widgetAreaBlocks = [];
|
|
@@ -67,11 +66,10 @@ export const getWidgetAreas = () => async _ref => {
|
|
|
67
66
|
* @return {Function} An action creator.
|
|
68
67
|
*/
|
|
69
68
|
|
|
70
|
-
export const getWidgets = () => async
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} = _ref2;
|
|
69
|
+
export const getWidgets = () => async ({
|
|
70
|
+
dispatch,
|
|
71
|
+
registry
|
|
72
|
+
}) => {
|
|
75
73
|
const query = buildWidgetsQuery();
|
|
76
74
|
const widgets = await registry.resolveSelect(coreStore).getEntityRecords('root', 'widget', query);
|
|
77
75
|
const groupedBySidebar = {};
|