@wordpress/edit-widgets 3.1.2 → 3.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/blocks/widget-area/edit/index.js +29 -24
- package/build/blocks/widget-area/edit/index.js.map +1 -1
- package/build/blocks/widget-area/edit/inner-blocks.js +4 -3
- package/build/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build/blocks/widget-area/index.js +6 -3
- package/build/blocks/widget-area/index.js.map +1 -1
- package/build/components/error-boundary/index.js +5 -4
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +4 -3
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +50 -41
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +12 -10
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/layout/index.js +5 -4
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/interface.js +4 -3
- package/build/components/layout/interface.js.map +1 -1
- package/build/components/sidebar/index.js +6 -5
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/widget-areas.js +4 -3
- package/build/components/sidebar/widget-areas.js.map +1 -1
- package/build/components/welcome-guide/index.js +5 -4
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-content/index.js +4 -3
- package/build/components/widget-areas-block-editor-content/index.js.map +1 -1
- package/build/components/widget-areas-block-editor-provider/index.js +17 -12
- package/build/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build/index.js +5 -3
- package/build/index.js.map +1 -1
- package/build/store/actions.js +74 -51
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +4 -2
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +13 -5
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +10 -8
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +28 -14
- package/build/store/selectors.js.map +1 -1
- package/build/store/transformers.js +3 -2
- package/build/store/transformers.js.map +1 -1
- package/build/store/utils.js +2 -1
- package/build/store/utils.js.map +1 -1
- package/build-module/blocks/widget-area/edit/index.js +29 -24
- package/build-module/blocks/widget-area/edit/index.js.map +1 -1
- package/build-module/blocks/widget-area/edit/inner-blocks.js +4 -3
- package/build-module/blocks/widget-area/edit/inner-blocks.js.map +1 -1
- package/build-module/blocks/widget-area/index.js +6 -3
- package/build-module/blocks/widget-area/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +5 -4
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +4 -3
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +48 -39
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +12 -10
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/layout/index.js +5 -4
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/interface.js +4 -3
- package/build-module/components/layout/interface.js.map +1 -1
- package/build-module/components/sidebar/index.js +6 -5
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/widget-areas.js +4 -3
- package/build-module/components/sidebar/widget-areas.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +5 -4
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/components/widget-areas-block-editor-content/index.js +4 -3
- 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 +17 -12
- package/build-module/components/widget-areas-block-editor-provider/index.js.map +1 -1
- package/build-module/index.js +2 -2
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +70 -47
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +11 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +10 -8
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +25 -12
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/transformers.js +2 -1
- package/build-module/store/transformers.js.map +1 -1
- package/package.json +27 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/components/widget-areas-block-editor-provider/index.js"],"names":["defaultTo","SlotFillProvider","uploadMedia","useDispatch","useSelect","useMemo","BlockEditorProvider","BlockEditorKeyboardShortcuts","CopyHandler","ReusableBlocksMenuItems","store","interfaceStore","ShortcutProvider","KeyboardShortcuts","useEntityBlockEditor","coreStore","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","editWidgetsStore","ALLOW_REUSABLE_BLOCKS","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","hasUploadPermissions","reusableBlocks","isFixedToolbarActive","keepCaretInsideBlock","select","canUser","widgetAreas","getWidgetAreas","widgets","getWidgets","getEntityRecords","isFeatureActive","setIsInserterOpened","settings","mediaUploadBlockEditor","onError","argumentsObject","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalReusableBlocks","hasFixedToolbar","mediaUpload","templateLock","__experimentalSetIsInserterOpened","widgetAreaId","blocks","onInput","onChange","id"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,uBAAjC;AACA,SAASC,WAAT,QAA4B,wBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SACCC,mBADD,EAECC,4BAFD,EAGCC,WAHD,QAIO,yBAJP;AAKA,SAASC,uBAAT,QAAwC,4BAAxC;AACA,SAASC,KAAK,IAAIC,cAAlB,QAAwC,sBAAxC;AACA,SAASC,gBAAT,QAAiC,+BAAjC;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,SAASC,oBAAT,EAA+BJ,KAAK,IAAIK,SAAxC,QAAyD,sBAAzD;AACA,SAASC,sBAAT,EAAiCC,IAAjC,EAAuCC,SAAvC,QAAwD,mBAAxD;AACA,OAAOC,yBAAP,MAAsC,2CAAtC;AACA,SAAST,KAAK,IAAIU,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAT,QAAsC,iBAAtC;AAEA,eAAe,SAASC,8BAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/components/widget-areas-block-editor-provider/index.js"],"names":["defaultTo","SlotFillProvider","uploadMedia","useDispatch","useSelect","useMemo","BlockEditorProvider","BlockEditorKeyboardShortcuts","CopyHandler","ReusableBlocksMenuItems","store","interfaceStore","ShortcutProvider","KeyboardShortcuts","useEntityBlockEditor","coreStore","buildWidgetAreasPostId","KIND","POST_TYPE","useLastSelectedWidgetArea","editWidgetsStore","ALLOW_REUSABLE_BLOCKS","WidgetAreasBlockEditorProvider","blockEditorSettings","children","props","hasUploadPermissions","reusableBlocks","isFixedToolbarActive","keepCaretInsideBlock","select","canUser","widgetAreas","getWidgetAreas","widgets","getWidgets","getEntityRecords","isFeatureActive","setIsInserterOpened","settings","mediaUploadBlockEditor","onError","argumentsObject","wpAllowedMimeTypes","allowedMimeTypes","message","__experimentalReusableBlocks","hasFixedToolbar","mediaUpload","templateLock","__experimentalSetIsInserterOpened","widgetAreaId","blocks","onInput","onChange","id"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,uBAAjC;AACA,SAASC,WAAT,QAA4B,wBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SACCC,mBADD,EAECC,4BAFD,EAGC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,cAAC,4BAAD,CAA8B,QAA9B,OADD,EAEC,cAAC,iBAAD,CAAmB,QAAnB,OAFD,EAGC,cAAC,gBAAD,QACC,cAAC,mBAAD;AACC,IAAA,KAAK,EAAGoC,MADT;AAEC,IAAA,OAAO,EAAGC,OAFX;AAGC,IAAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,QAAQ,EAAGf,QAJZ;AAKC,IAAA,cAAc,EAAG;AALlB,KAMMd,KANN,GAQC,cAAC,WAAD,QAAeD,QAAf,CARD,EASC,cAAC,uBAAD;AAAyB,IAAA,YAAY,EAAG2B;AAAxC,IATD,CADD,CAHD,CADD;AAmBA","sourcesContent":["/**\n * External dependencies\n */\nimport { defaultTo } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { SlotFillProvider } from '@wordpress/components';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport {\n\tBlockEditorProvider,\n\tBlockEditorKeyboardShortcuts,\n\tCopyHandler,\n} from '@wordpress/block-editor';\nimport { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\nimport KeyboardShortcuts from '../keyboard-shortcuts';\nimport { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';\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';\n\nexport default function WidgetAreasBlockEditorProvider( {\n\tblockEditorSettings,\n\tchildren,\n\t...props\n} ) {\n\tconst {\n\t\thasUploadPermissions,\n\t\treusableBlocks,\n\t\tisFixedToolbarActive,\n\t\tkeepCaretInsideBlock,\n\t} = useSelect(\n\t\t( select ) => ( {\n\t\t\thasUploadPermissions: defaultTo(\n\t\t\t\tselect( coreStore ).canUser( 'create', 'media' ),\n\t\t\t\ttrue\n\t\t\t),\n\t\t\twidgetAreas: select( editWidgetsStore ).getWidgetAreas(),\n\t\t\twidgets: select( editWidgetsStore ).getWidgets(),\n\t\t\treusableBlocks: ALLOW_REUSABLE_BLOCKS\n\t\t\t\t? select( coreStore ).getEntityRecords( 'postType', 'wp_block' )\n\t\t\t\t: [],\n\t\t\tisFixedToolbarActive: select( interfaceStore ).isFeatureActive(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'fixedToolbar'\n\t\t\t),\n\t\t\tkeepCaretInsideBlock: select( interfaceStore ).isFeatureActive(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'keepCaretInsideBlock'\n\t\t\t),\n\t\t} ),\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,\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\thasUploadPermissions,\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<BlockEditorProvider\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</BlockEditorProvider>\n\t\t\t</SlotFillProvider>\n\t\t</ShortcutProvider>\n\t);\n}\n"]}
|
package/build-module/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { createElement } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { registerBlockType, unstable__bootstrapServerSideBlockDefinitions // eslint-disable-line camelcase
|
|
7
|
-
|
|
6
|
+
import { registerBlockType, unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
|
|
7
|
+
setFreeformContentHandlerName, store as blocksStore } from '@wordpress/blocks';
|
|
8
8
|
import { dispatch } from '@wordpress/data';
|
|
9
9
|
import { render, unmountComponentAtNode } from '@wordpress/element';
|
|
10
10
|
import { registerCoreBlocks, __experimentalGetCoreBlocks, __experimentalRegisterExperimentalCoreBlocks } from '@wordpress/block-library';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/index.js"],"names":["registerBlockType","unstable__bootstrapServerSideBlockDefinitions","setFreeformContentHandlerName","store","blocksStore","dispatch","render","unmountComponentAtNode","registerCoreBlocks","__experimentalGetCoreBlocks","__experimentalRegisterExperimentalCoreBlocks","__experimentalFetchLinkSuggestions","fetchLinkSuggestions","registerLegacyWidgetBlock","registerLegacyWidgetVariations","registerWidgetGroupBlock","interfaceStore","widgetArea","Layout","ALLOW_REUSABLE_BLOCKS","ENABLE_EXPERIMENTAL_FSE_BLOCKS","disabledBlocks","reinitializeEditor","target","settings","reboot","bind","initialize","id","document","getElementById","coreBlocks","filter","block","includes","name","startsWith","setFeatureDefaults","fixedToolbar","welcomeGuide","showBlockBreadcrumbs","themeStyles","__experimentalReapplyBlockTypeFilters","process","env","GUTENBERG_PHASE","enableFSEBlocks","registerBlock","search","searchOptions","metadata"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,iBADD,EAECC,6CAFD,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/index.js"],"names":["registerBlockType","unstable__bootstrapServerSideBlockDefinitions","setFreeformContentHandlerName","store","blocksStore","dispatch","render","unmountComponentAtNode","registerCoreBlocks","__experimentalGetCoreBlocks","__experimentalRegisterExperimentalCoreBlocks","__experimentalFetchLinkSuggestions","fetchLinkSuggestions","registerLegacyWidgetBlock","registerLegacyWidgetVariations","registerWidgetGroupBlock","interfaceStore","widgetArea","Layout","ALLOW_REUSABLE_BLOCKS","ENABLE_EXPERIMENTAL_FSE_BLOCKS","disabledBlocks","reinitializeEditor","target","settings","reboot","bind","initialize","id","document","getElementById","coreBlocks","filter","block","includes","name","startsWith","setFeatureDefaults","fixedToolbar","welcomeGuide","showBlockBreadcrumbs","themeStyles","__experimentalReapplyBlockTypeFilters","process","env","GUTENBERG_PHASE","enableFSEBlocks","registerBlock","search","searchOptions","metadata"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,iBADD,EAECC,6CAFD,EAEgD;AAC/CC,6BAHD,EAICC,KAAK,IAAIC,WAJV,QAKO,mBALP;AAMA,SAASC,QAAT,QAAyB,iBAAzB;AACA,SAASC,MAAT,EAAiBC,sBAAjB,QAA+C,oBAA/C;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QAA9B;AAAyC,IAAA,OAAO,EAAGC;AAAnD,IADK,EAELF,MAFK,CAAN;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMwB,aAAa,GAAKd,KAAF,IAAa;AAClC,MAAK,CAAEA,KAAP,EAAe;AACd;AACA;;AACD,QAAM;AAAEiB,IAAAA,QAAF;AAAY1B,IAAAA,QAAZ;AAAsBW,IAAAA;AAAtB,MAA+BF,KAArC;;AACA,MAAKiB,QAAL,EAAgB;AACfjD,IAAAA,6CAA6C,CAAE;AAAE,OAAEkC,IAAF,GAAUe;AAAZ,KAAF,CAA7C;AACA;;AACDlD,EAAAA,iBAAiB,CAAEmC,IAAF,EAAQX,QAAR,CAAjB;AACA,CATD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tregisterBlockType,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n\tsetFreeformContentHandlerName,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { dispatch } from '@wordpress/data';\nimport { render, unmountComponentAtNode } from '@wordpress/element';\nimport {\n\tregisterCoreBlocks,\n\t__experimentalGetCoreBlocks,\n\t__experimentalRegisterExperimentalCoreBlocks,\n} from '@wordpress/block-library';\nimport { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';\nimport {\n\tregisterLegacyWidgetBlock,\n\tregisterLegacyWidgetVariations,\n\tregisterWidgetGroupBlock,\n} from '@wordpress/widgets';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport './store';\nimport './filters';\nimport * as widgetArea from './blocks/widget-area';\n\nimport Layout from './components/layout';\nimport {\n\tALLOW_REUSABLE_BLOCKS,\n\tENABLE_EXPERIMENTAL_FSE_BLOCKS,\n} from './constants';\n\nconst disabledBlocks = [\n\t'core/more',\n\t'core/freeform',\n\t'core/template-part',\n\t...( ALLOW_REUSABLE_BLOCKS ? [] : [ 'core/block' ] ),\n];\n\n/**\n * Reinitializes the editor after the user chooses to reboot the editor after\n * an unhandled error occurs, replacing previously mounted editor element using\n * an initial state from prior to the crash.\n *\n * @param {Element} target DOM node in which editor is rendered.\n * @param {?Object} settings Editor settings object.\n */\nexport function reinitializeEditor( target, settings ) {\n\tunmountComponentAtNode( target );\n\tconst reboot = reinitializeEditor.bind( null, target, settings );\n\trender(\n\t\t<Layout blockEditorSettings={ settings } onError={ reboot } />,\n\t\ttarget\n\t);\n}\n\n/**\n * Initializes the block editor in the widgets screen.\n *\n * @param {string} id ID of the root element to render the screen in.\n * @param {Object} settings Block editor settings.\n */\nexport function initialize( id, settings ) {\n\tconst target = document.getElementById( id );\n\tconst reboot = reinitializeEditor.bind( null, target, settings );\n\tconst coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => {\n\t\treturn ! (\n\t\t\tdisabledBlocks.includes( block.name ) ||\n\t\t\tblock.name.startsWith( 'core/post' ) ||\n\t\t\tblock.name.startsWith( 'core/query' ) ||\n\t\t\tblock.name.startsWith( 'core/site' ) ||\n\t\t\tblock.name.startsWith( 'core/navigation' )\n\t\t);\n\t} );\n\n\tdispatch( interfaceStore ).setFeatureDefaults( 'core/edit-widgets', {\n\t\tfixedToolbar: false,\n\t\twelcomeGuide: true,\n\t\tshowBlockBreadcrumbs: true,\n\t\tthemeStyles: true,\n\t} );\n\n\tdispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();\n\tregisterCoreBlocks( coreBlocks );\n\tregisterLegacyWidgetBlock();\n\tif ( process.env.GUTENBERG_PHASE === 2 ) {\n\t\t__experimentalRegisterExperimentalCoreBlocks( {\n\t\t\tenableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS,\n\t\t} );\n\t}\n\tregisterLegacyWidgetVariations( settings );\n\tregisterBlock( widgetArea );\n\tregisterWidgetGroupBlock();\n\n\tsettings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) =>\n\t\tfetchLinkSuggestions( search, searchOptions, settings );\n\n\t// As we are unregistering `core/freeform` to avoid the Classic block, we must\n\t// replace it with something as the default freeform content handler. Failure to\n\t// do this will result in errors in the default block parser.\n\t// see: https://github.com/WordPress/gutenberg/issues/33097\n\tsetFreeformContentHandlerName( 'core/html' );\n\trender(\n\t\t<Layout blockEditorSettings={ settings } onError={ reboot } />,\n\t\ttarget\n\t);\n}\n\n/**\n * Function to register an individual block.\n *\n * @param {Object} block The block to be registered.\n *\n */\nconst registerBlock = ( block ) => {\n\tif ( ! block ) {\n\t\treturn;\n\t}\n\tconst { metadata, settings, name } = block;\n\tif ( metadata ) {\n\t\tunstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } );\n\t}\n\tregisterBlockType( name, settings );\n};\n"]}
|
|
@@ -23,9 +23,10 @@ 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
|
-
|
|
26
|
+
export const persistStubPost = (id, blocks) => _ref => {
|
|
27
|
+
let {
|
|
28
|
+
registry
|
|
29
|
+
} = _ref;
|
|
29
30
|
const stubPost = createStubPost(id, blocks);
|
|
30
31
|
registry.dispatch(coreStore).receiveEntityRecords(KIND, POST_TYPE, stubPost, {
|
|
31
32
|
id: stubPost.id
|
|
@@ -41,11 +42,12 @@ export const persistStubPost = (id, blocks) => ({
|
|
|
41
42
|
* @return {Function} An action creator.
|
|
42
43
|
*/
|
|
43
44
|
|
|
44
|
-
export const saveEditedWidgetAreas = () => async
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
export const saveEditedWidgetAreas = () => async _ref2 => {
|
|
46
|
+
let {
|
|
47
|
+
select,
|
|
48
|
+
dispatch,
|
|
49
|
+
registry
|
|
50
|
+
} = _ref2;
|
|
49
51
|
const editedWidgetAreas = select.getEditedWidgetAreas();
|
|
50
52
|
|
|
51
53
|
if (!(editedWidgetAreas !== null && editedWidgetAreas !== void 0 && editedWidgetAreas.length)) {
|
|
@@ -73,10 +75,12 @@ export const saveEditedWidgetAreas = () => async ({
|
|
|
73
75
|
* @return {Function} An action creator.
|
|
74
76
|
*/
|
|
75
77
|
|
|
76
|
-
export const saveWidgetAreas = widgetAreas => async
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
export const saveWidgetAreas = widgetAreas => async _ref3 => {
|
|
79
|
+
let {
|
|
80
|
+
dispatch,
|
|
81
|
+
registry
|
|
82
|
+
} = _ref3;
|
|
83
|
+
|
|
80
84
|
try {
|
|
81
85
|
for (const widgetArea of widgetAreas) {
|
|
82
86
|
await dispatch.saveWidgetArea(widgetArea.id);
|
|
@@ -94,17 +98,21 @@ export const saveWidgetAreas = widgetAreas => async ({
|
|
|
94
98
|
* @return {Function} An action creator.
|
|
95
99
|
*/
|
|
96
100
|
|
|
97
|
-
export const saveWidgetArea = widgetAreaId => async
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
export const saveWidgetArea = widgetAreaId => async _ref4 => {
|
|
102
|
+
let {
|
|
103
|
+
dispatch,
|
|
104
|
+
select,
|
|
105
|
+
registry
|
|
106
|
+
} = _ref4;
|
|
102
107
|
const widgets = select.getWidgets();
|
|
103
108
|
const post = registry.select(coreStore).getEditedEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(widgetAreaId)); // Get all widgets from this area
|
|
104
109
|
|
|
105
|
-
const areaWidgets = Object.values(widgets).filter(
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
const areaWidgets = Object.values(widgets).filter(_ref5 => {
|
|
111
|
+
let {
|
|
112
|
+
sidebar
|
|
113
|
+
} = _ref5;
|
|
114
|
+
return sidebar === widgetAreaId;
|
|
115
|
+
}); // Remove all duplicate reference widget instances for legacy widgets.
|
|
108
116
|
// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget
|
|
109
117
|
// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to
|
|
110
118
|
// save multiple instances of these in different sidebars you will run into undefined behaviors.
|
|
@@ -165,16 +173,22 @@ export const saveWidgetArea = widgetAreaId => async ({
|
|
|
165
173
|
continue;
|
|
166
174
|
}
|
|
167
175
|
|
|
168
|
-
batchTasks.push(
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
batchTasks.push(_ref6 => {
|
|
177
|
+
let {
|
|
178
|
+
saveEditedEntityRecord
|
|
179
|
+
} = _ref6;
|
|
180
|
+
return saveEditedEntityRecord('root', 'widget', widgetId);
|
|
181
|
+
});
|
|
171
182
|
} else {
|
|
172
183
|
// Create a new widget.
|
|
173
|
-
batchTasks.push(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
184
|
+
batchTasks.push(_ref7 => {
|
|
185
|
+
let {
|
|
186
|
+
saveEntityRecord
|
|
187
|
+
} = _ref7;
|
|
188
|
+
return saveEntityRecord('root', 'widget', { ...widget,
|
|
189
|
+
sidebar: widgetAreaId
|
|
190
|
+
});
|
|
191
|
+
});
|
|
178
192
|
}
|
|
179
193
|
|
|
180
194
|
batchMeta.push({
|
|
@@ -185,11 +199,14 @@ export const saveWidgetArea = widgetAreaId => async ({
|
|
|
185
199
|
}
|
|
186
200
|
|
|
187
201
|
for (const widget of deletedWidgets) {
|
|
188
|
-
batchTasks.push(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
202
|
+
batchTasks.push(_ref8 => {
|
|
203
|
+
let {
|
|
204
|
+
deleteEntityRecord
|
|
205
|
+
} = _ref8;
|
|
206
|
+
return deleteEntityRecord('root', 'widget', widget.id, {
|
|
207
|
+
force: true
|
|
208
|
+
});
|
|
209
|
+
});
|
|
193
210
|
}
|
|
194
211
|
|
|
195
212
|
const records = await registry.dispatch(coreStore).__experimentalBatch(batchTasks);
|
|
@@ -233,9 +250,10 @@ export const saveWidgetArea = widgetAreaId => async ({
|
|
|
233
250
|
registry.dispatch(coreStore).receiveEntityRecords(KIND, POST_TYPE, post, undefined);
|
|
234
251
|
};
|
|
235
252
|
|
|
236
|
-
const trySaveWidgetArea = widgetAreaId =>
|
|
237
|
-
|
|
238
|
-
|
|
253
|
+
const trySaveWidgetArea = widgetAreaId => _ref9 => {
|
|
254
|
+
let {
|
|
255
|
+
registry
|
|
256
|
+
} = _ref9;
|
|
239
257
|
const saveErrorBefore = registry.select(coreStore).getLastEntitySaveError(KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId);
|
|
240
258
|
registry.dispatch(coreStore).saveEditedEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId);
|
|
241
259
|
const saveErrorAfter = registry.select(coreStore).getLastEntitySaveError(KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId);
|
|
@@ -329,9 +347,10 @@ export function setIsListViewOpened(isOpen) {
|
|
|
329
347
|
* @return {Object} Action creator.
|
|
330
348
|
*/
|
|
331
349
|
|
|
332
|
-
export const closeGeneralSidebar = () =>
|
|
333
|
-
|
|
334
|
-
|
|
350
|
+
export const closeGeneralSidebar = () => _ref10 => {
|
|
351
|
+
let {
|
|
352
|
+
registry
|
|
353
|
+
} = _ref10;
|
|
335
354
|
registry.dispatch(interfaceStore).disableComplementaryArea(editWidgetsStoreName);
|
|
336
355
|
};
|
|
337
356
|
/**
|
|
@@ -341,19 +360,23 @@ export const closeGeneralSidebar = () => ({
|
|
|
341
360
|
* @param {string} widgetAreaId The id of the widget area to move the block to.
|
|
342
361
|
*/
|
|
343
362
|
|
|
344
|
-
export const moveBlockToWidgetArea = (clientId, widgetAreaId) => async
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
363
|
+
export const moveBlockToWidgetArea = (clientId, widgetAreaId) => async _ref11 => {
|
|
364
|
+
let {
|
|
365
|
+
dispatch,
|
|
366
|
+
select,
|
|
367
|
+
registry
|
|
368
|
+
} = _ref11;
|
|
349
369
|
const sourceRootClientId = registry.select(blockEditorStore).getBlockRootClientId([clientId]); // Search the top level blocks (widget areas) for the one with the matching
|
|
350
370
|
// id attribute. Makes the assumption that all top-level blocks are widget
|
|
351
371
|
// areas.
|
|
352
372
|
|
|
353
373
|
const widgetAreas = registry.select(blockEditorStore).getBlocks();
|
|
354
|
-
const destinationWidgetAreaBlock = widgetAreas.find(
|
|
355
|
-
|
|
356
|
-
|
|
374
|
+
const destinationWidgetAreaBlock = widgetAreas.find(_ref12 => {
|
|
375
|
+
let {
|
|
376
|
+
attributes
|
|
377
|
+
} = _ref12;
|
|
378
|
+
return attributes.id === widgetAreaId;
|
|
379
|
+
});
|
|
357
380
|
const destinationRootClientId = destinationWidgetAreaBlock.clientId; // Get the index for moving to the end of the the destination widget area.
|
|
358
381
|
|
|
359
382
|
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","saveErrorBefore","saveErrorAfter","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,GAAG,CAAEC,EAAF,EAAMC,MAAN,KAAkB,CAAE;AAAEC,EAAAA;AAAF,CAAF,KAAoB;AACpE,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,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N;;;AACAvF,EAAAA,QAAQ,CACNE,QADF,CACYf,gBADZ,EAEE0G,oBAFF,CAGE,CAAExC,QAAF,CAHF,EAIE6B,kBAJF,EAKEK,uBALF,EAMEG,gBANF;AAQA,CA1CM","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 = ( id, blocks ) => ( { registry } ) => {\n\tconst stubPost = createStubPost( id, blocks );\n\tregistry\n\t\t.dispatch( coreStore )\n\t\t.receiveEntityRecords(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tstubPost,\n\t\t\t{ id: stubPost.id },\n\t\t\tfalse\n\t\t);\n\treturn stubPost;\n};\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 = () => async ( {\n\tselect,\n\tdispatch,\n\tregistry,\n} ) => {\n\tconst editedWidgetAreas = select.getEditedWidgetAreas();\n\tif ( ! editedWidgetAreas?.length ) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait dispatch.saveWidgetAreas( editedWidgetAreas );\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createSuccessNotice( __( 'Widgets saved.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t} catch ( e ) {\n\t\tregistry.dispatch( noticesStore ).createErrorNotice(\n\t\t\t/* translators: %s: The error message. */\n\t\t\tsprintf( __( 'There was an error. %s' ), e.message ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t}\n};\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 = ( widgetAreas ) => async ( {\n\tdispatch,\n\tregistry,\n} ) => {\n\ttry {\n\t\tfor ( const widgetArea of widgetAreas ) {\n\t\t\tawait dispatch.saveWidgetArea( widgetArea.id );\n\t\t}\n\t} finally {\n\t\t// saveEditedEntityRecord resets the resolution status, let's fix it manually\n\t\tawait registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.finishResolution(\n\t\t\t\t'getEntityRecord',\n\t\t\t\tKIND,\n\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\tbuildWidgetAreasQuery()\n\t\t\t);\n\t}\n};\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 = ( widgetAreaId ) => async ( {\n\tdispatch,\n\tselect,\n\tregistry,\n} ) => {\n\tconst widgets = select.getWidgets();\n\n\tconst post = registry\n\t\t.select( coreStore )\n\t\t.getEditedEntityRecord(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tbuildWidgetAreaPostId( widgetAreaId )\n\t\t);\n\n\t// Get all widgets from this area\n\tconst areaWidgets = Object.values( widgets ).filter(\n\t\t( { sidebar } ) => sidebar === widgetAreaId\n\t);\n\n\t// Remove all duplicate reference widget instances for legacy widgets.\n\t// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget\n\t// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to\n\t// save multiple instances of these in different sidebars you will run into undefined behaviors.\n\tconst usedReferenceWidgets = [];\n\tconst widgetsBlocks = post.blocks.filter( ( block ) => {\n\t\tconst { id } = block.attributes;\n\n\t\tif ( block.name === 'core/legacy-widget' && id ) {\n\t\t\tif ( usedReferenceWidgets.includes( id ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tusedReferenceWidgets.push( id );\n\t\t}\n\t\treturn true;\n\t} );\n\n\t// Determine which widgets have been deleted. We can tell if a widget is\n\t// deleted and not just moved to a different area by looking to see if\n\t// getWidgetAreaForWidgetId() finds something.\n\tconst deletedWidgets = [];\n\tfor ( const widget of areaWidgets ) {\n\t\tconst widgetsNewArea = select.getWidgetAreaForWidgetId( widget.id );\n\t\tif ( ! widgetsNewArea ) {\n\t\t\tdeletedWidgets.push( widget );\n\t\t}\n\t}\n\n\tconst batchMeta = [];\n\tconst batchTasks = [];\n\tconst sidebarWidgetsIds = [];\n\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\tconst block = widgetsBlocks[ i ];\n\t\tconst widgetId = getWidgetIdFromBlock( block );\n\t\tconst oldWidget = widgets[ widgetId ];\n\t\tconst widget = transformBlockToWidget( block, oldWidget );\n\n\t\t// We'll replace the null widgetId after save, but we track it here\n\t\t// since order is important.\n\t\tsidebarWidgetsIds.push( widgetId );\n\n\t\t// Check oldWidget as widgetId might refer to an ID which has been\n\t\t// deleted, e.g. if a deleted block is restored via undo after saving.\n\t\tif ( oldWidget ) {\n\t\t\t// Update an existing widget.\n\t\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\twidgetId,\n\t\t\t\t{\n\t\t\t\t\t...widget,\n\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\n\t\t\tconst hasEdits = registry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.hasEditsForEntityRecord( 'root', 'widget', widgetId );\n\n\t\t\tif ( ! hasEdits ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbatchTasks.push( ( { saveEditedEntityRecord } ) =>\n\t\t\t\tsaveEditedEntityRecord( 'root', 'widget', widgetId )\n\t\t\t);\n\t\t} else {\n\t\t\t// Create a new widget.\n\t\t\tbatchTasks.push( ( { saveEntityRecord } ) =>\n\t\t\t\tsaveEntityRecord( 'root', 'widget', {\n\t\t\t\t\t...widget,\n\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tbatchMeta.push( {\n\t\t\tblock,\n\t\t\tposition: i,\n\t\t\tclientId: block.clientId,\n\t\t} );\n\t}\n\tfor ( const widget of deletedWidgets ) {\n\t\tbatchTasks.push( ( { deleteEntityRecord } ) =>\n\t\t\tdeleteEntityRecord( 'root', 'widget', widget.id, {\n\t\t\t\tforce: true,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst records = await registry\n\t\t.dispatch( coreStore )\n\t\t.__experimentalBatch( batchTasks );\n\tconst preservedRecords = records.filter(\n\t\t( record ) => ! record.hasOwnProperty( 'deleted' )\n\t);\n\n\tconst failedWidgetNames = [];\n\n\tfor ( let i = 0; i < preservedRecords.length; i++ ) {\n\t\tconst widget = preservedRecords[ i ];\n\t\tconst { block, position } = batchMeta[ i ];\n\n\t\t// Set __internalWidgetId on the block. This will be persisted to the\n\t\t// store when we dispatch receiveEntityRecords( post ) below.\n\t\tpost.blocks[ position ].attributes.__internalWidgetId = widget.id;\n\n\t\tconst error = registry\n\t\t\t.select( coreStore )\n\t\t\t.getLastEntitySaveError( 'root', 'widget', widget.id );\n\t\tif ( error ) {\n\t\t\tfailedWidgetNames.push( block.attributes?.name || block?.name );\n\t\t}\n\n\t\tif ( ! sidebarWidgetsIds[ position ] ) {\n\t\t\tsidebarWidgetsIds[ position ] = widget.id;\n\t\t}\n\t}\n\n\tif ( failedWidgetNames.length ) {\n\t\tthrow new Error(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: List of widget names */\n\t\t\t\t__( 'Could not save the following widgets: %s.' ),\n\t\t\t\tfailedWidgetNames.join( ', ' )\n\t\t\t)\n\t\t);\n\t}\n\n\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\twidgetAreaId,\n\t\t{\n\t\t\twidgets: sidebarWidgetsIds,\n\t\t},\n\t\t{ undoIgnore: true }\n\t);\n\n\tdispatch( trySaveWidgetArea( widgetAreaId ) );\n\n\tregistry\n\t\t.dispatch( coreStore )\n\t\t.receiveEntityRecords( KIND, POST_TYPE, post, undefined );\n};\n\nconst trySaveWidgetArea = ( widgetAreaId ) => ( { registry } ) => {\n\tconst saveErrorBefore = registry\n\t\t.select( coreStore )\n\t\t.getLastEntitySaveError( KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId );\n\tregistry\n\t\t.dispatch( coreStore )\n\t\t.saveEditedEntityRecord( KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId );\n\tconst saveErrorAfter = registry\n\t\t.select( coreStore )\n\t\t.getLastEntitySaveError( KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId );\n\tif ( saveErrorAfter && saveErrorBefore !== saveErrorAfter ) {\n\t\tthrow new Error( saveErrorAfter );\n\t}\n};\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 = () => ( { registry } ) => {\n\tregistry\n\t\t.dispatch( interfaceStore )\n\t\t.disableComplementaryArea( editWidgetsStoreName );\n};\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 = ( clientId, widgetAreaId ) => async ( {\n\tdispatch,\n\tselect,\n\tregistry,\n} ) => {\n\tconst sourceRootClientId = registry\n\t\t.select( blockEditorStore )\n\t\t.getBlockRootClientId( [ clientId ] );\n\n\t// Search the top level blocks (widget areas) for the one with the matching\n\t// id attribute. Makes the assumption that all top-level blocks are widget\n\t// areas.\n\tconst widgetAreas = registry.select( blockEditorStore ).getBlocks();\n\tconst destinationWidgetAreaBlock = widgetAreas.find(\n\t\t( { attributes } ) => attributes.id === widgetAreaId\n\t);\n\tconst destinationRootClientId = destinationWidgetAreaBlock.clientId;\n\n\t// Get the index for moving to the end of the the destination widget area.\n\tconst destinationInnerBlocksClientIds = registry\n\t\t.select( blockEditorStore )\n\t\t.getBlockOrder( destinationRootClientId );\n\tconst destinationIndex = destinationInnerBlocksClientIds.length;\n\n\t// Reveal the widget area, if it's not open.\n\tconst isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(\n\t\tdestinationRootClientId\n\t);\n\n\tif ( ! isDestinationWidgetAreaOpen ) {\n\t\tdispatch.setIsWidgetAreaOpen( destinationRootClientId, true );\n\t}\n\n\t// Move the block.\n\tregistry\n\t\t.dispatch( blockEditorStore )\n\t\t.moveBlocksToPosition(\n\t\t\t[ clientId ],\n\t\t\tsourceRootClientId,\n\t\t\tdestinationRootClientId,\n\t\t\tdestinationIndex\n\t\t);\n};\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","saveErrorBefore","saveErrorAfter","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,GAAG,CAAEC,EAAF,EAAMC,MAAN,KAAkB,QAAoB;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AACpE,QAAMC,QAAQ,GAAGV,cAAc,CAAEO,EAAF,EAAMC,MAAN,C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,+BAA+B,GAAGxF,QAAQ,CAC9CK,MADsC,CAC9BlB,gBAD8B,EAEtCsG,aAFsC,CAEvBF,uBAFuB,CAAxC;AAGA,QAAMG,gBAAgB,GAAGF,+BAA+B,CAAChF,MAAzD,CAlBM,CAoBN;;AACA,QAAMmF,2BAA2B,GAAGtF,MAAM,CAACuF,mBAAP,CACnCL,uBADmC,CAApC;;AAIA,MAAK,CAAEI,2BAAP,EAAqC;AACpCzF,IAAAA,QAAQ,CAACwE,mBAAT,CAA8Ba,uBAA9B,EAAuD,IAAvD;AACA,GA3BK,CA6BN;;;AACAvF,EAAAA,QAAQ,CACNE,QADF,CACYf,gBADZ,EAEE0G,oBAFF,CAGE,CAAExC,QAAF,CAHF,EAIE6B,kBAJF,EAKEK,uBALF,EAMEG,gBANF;AAQA,CA1CM","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 = ( id, blocks ) => ( { registry } ) => {\n\tconst stubPost = createStubPost( id, blocks );\n\tregistry\n\t\t.dispatch( coreStore )\n\t\t.receiveEntityRecords(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tstubPost,\n\t\t\t{ id: stubPost.id },\n\t\t\tfalse\n\t\t);\n\treturn stubPost;\n};\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 = () => async ( {\n\tselect,\n\tdispatch,\n\tregistry,\n} ) => {\n\tconst editedWidgetAreas = select.getEditedWidgetAreas();\n\tif ( ! editedWidgetAreas?.length ) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait dispatch.saveWidgetAreas( editedWidgetAreas );\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createSuccessNotice( __( 'Widgets saved.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t} catch ( e ) {\n\t\tregistry.dispatch( noticesStore ).createErrorNotice(\n\t\t\t/* translators: %s: The error message. */\n\t\t\tsprintf( __( 'There was an error. %s' ), e.message ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t}\n};\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 = ( widgetAreas ) => async ( {\n\tdispatch,\n\tregistry,\n} ) => {\n\ttry {\n\t\tfor ( const widgetArea of widgetAreas ) {\n\t\t\tawait dispatch.saveWidgetArea( widgetArea.id );\n\t\t}\n\t} finally {\n\t\t// saveEditedEntityRecord resets the resolution status, let's fix it manually\n\t\tawait registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.finishResolution(\n\t\t\t\t'getEntityRecord',\n\t\t\t\tKIND,\n\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\tbuildWidgetAreasQuery()\n\t\t\t);\n\t}\n};\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 = ( widgetAreaId ) => async ( {\n\tdispatch,\n\tselect,\n\tregistry,\n} ) => {\n\tconst widgets = select.getWidgets();\n\n\tconst post = registry\n\t\t.select( coreStore )\n\t\t.getEditedEntityRecord(\n\t\t\tKIND,\n\t\t\tPOST_TYPE,\n\t\t\tbuildWidgetAreaPostId( widgetAreaId )\n\t\t);\n\n\t// Get all widgets from this area\n\tconst areaWidgets = Object.values( widgets ).filter(\n\t\t( { sidebar } ) => sidebar === widgetAreaId\n\t);\n\n\t// Remove all duplicate reference widget instances for legacy widgets.\n\t// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget\n\t// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to\n\t// save multiple instances of these in different sidebars you will run into undefined behaviors.\n\tconst usedReferenceWidgets = [];\n\tconst widgetsBlocks = post.blocks.filter( ( block ) => {\n\t\tconst { id } = block.attributes;\n\n\t\tif ( block.name === 'core/legacy-widget' && id ) {\n\t\t\tif ( usedReferenceWidgets.includes( id ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tusedReferenceWidgets.push( id );\n\t\t}\n\t\treturn true;\n\t} );\n\n\t// Determine which widgets have been deleted. We can tell if a widget is\n\t// deleted and not just moved to a different area by looking to see if\n\t// getWidgetAreaForWidgetId() finds something.\n\tconst deletedWidgets = [];\n\tfor ( const widget of areaWidgets ) {\n\t\tconst widgetsNewArea = select.getWidgetAreaForWidgetId( widget.id );\n\t\tif ( ! widgetsNewArea ) {\n\t\t\tdeletedWidgets.push( widget );\n\t\t}\n\t}\n\n\tconst batchMeta = [];\n\tconst batchTasks = [];\n\tconst sidebarWidgetsIds = [];\n\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\tconst block = widgetsBlocks[ i ];\n\t\tconst widgetId = getWidgetIdFromBlock( block );\n\t\tconst oldWidget = widgets[ widgetId ];\n\t\tconst widget = transformBlockToWidget( block, oldWidget );\n\n\t\t// We'll replace the null widgetId after save, but we track it here\n\t\t// since order is important.\n\t\tsidebarWidgetsIds.push( widgetId );\n\n\t\t// Check oldWidget as widgetId might refer to an ID which has been\n\t\t// deleted, e.g. if a deleted block is restored via undo after saving.\n\t\tif ( oldWidget ) {\n\t\t\t// Update an existing widget.\n\t\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\twidgetId,\n\t\t\t\t{\n\t\t\t\t\t...widget,\n\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\n\t\t\tconst hasEdits = registry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.hasEditsForEntityRecord( 'root', 'widget', widgetId );\n\n\t\t\tif ( ! hasEdits ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbatchTasks.push( ( { saveEditedEntityRecord } ) =>\n\t\t\t\tsaveEditedEntityRecord( 'root', 'widget', widgetId )\n\t\t\t);\n\t\t} else {\n\t\t\t// Create a new widget.\n\t\t\tbatchTasks.push( ( { saveEntityRecord } ) =>\n\t\t\t\tsaveEntityRecord( 'root', 'widget', {\n\t\t\t\t\t...widget,\n\t\t\t\t\tsidebar: widgetAreaId,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tbatchMeta.push( {\n\t\t\tblock,\n\t\t\tposition: i,\n\t\t\tclientId: block.clientId,\n\t\t} );\n\t}\n\tfor ( const widget of deletedWidgets ) {\n\t\tbatchTasks.push( ( { deleteEntityRecord } ) =>\n\t\t\tdeleteEntityRecord( 'root', 'widget', widget.id, {\n\t\t\t\tforce: true,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst records = await registry\n\t\t.dispatch( coreStore )\n\t\t.__experimentalBatch( batchTasks );\n\tconst preservedRecords = records.filter(\n\t\t( record ) => ! record.hasOwnProperty( 'deleted' )\n\t);\n\n\tconst failedWidgetNames = [];\n\n\tfor ( let i = 0; i < preservedRecords.length; i++ ) {\n\t\tconst widget = preservedRecords[ i ];\n\t\tconst { block, position } = batchMeta[ i ];\n\n\t\t// Set __internalWidgetId on the block. This will be persisted to the\n\t\t// store when we dispatch receiveEntityRecords( post ) below.\n\t\tpost.blocks[ position ].attributes.__internalWidgetId = widget.id;\n\n\t\tconst error = registry\n\t\t\t.select( coreStore )\n\t\t\t.getLastEntitySaveError( 'root', 'widget', widget.id );\n\t\tif ( error ) {\n\t\t\tfailedWidgetNames.push( block.attributes?.name || block?.name );\n\t\t}\n\n\t\tif ( ! sidebarWidgetsIds[ position ] ) {\n\t\t\tsidebarWidgetsIds[ position ] = widget.id;\n\t\t}\n\t}\n\n\tif ( failedWidgetNames.length ) {\n\t\tthrow new Error(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: List of widget names */\n\t\t\t\t__( 'Could not save the following widgets: %s.' ),\n\t\t\t\tfailedWidgetNames.join( ', ' )\n\t\t\t)\n\t\t);\n\t}\n\n\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\twidgetAreaId,\n\t\t{\n\t\t\twidgets: sidebarWidgetsIds,\n\t\t},\n\t\t{ undoIgnore: true }\n\t);\n\n\tdispatch( trySaveWidgetArea( widgetAreaId ) );\n\n\tregistry\n\t\t.dispatch( coreStore )\n\t\t.receiveEntityRecords( KIND, POST_TYPE, post, undefined );\n};\n\nconst trySaveWidgetArea = ( widgetAreaId ) => ( { registry } ) => {\n\tconst saveErrorBefore = registry\n\t\t.select( coreStore )\n\t\t.getLastEntitySaveError( KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId );\n\tregistry\n\t\t.dispatch( coreStore )\n\t\t.saveEditedEntityRecord( KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId );\n\tconst saveErrorAfter = registry\n\t\t.select( coreStore )\n\t\t.getLastEntitySaveError( KIND, WIDGET_AREA_ENTITY_TYPE, widgetAreaId );\n\tif ( saveErrorAfter && saveErrorBefore !== saveErrorAfter ) {\n\t\tthrow new Error( saveErrorAfter );\n\t}\n};\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 = () => ( { registry } ) => {\n\tregistry\n\t\t.dispatch( interfaceStore )\n\t\t.disableComplementaryArea( editWidgetsStoreName );\n};\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 = ( clientId, widgetAreaId ) => async ( {\n\tdispatch,\n\tselect,\n\tregistry,\n} ) => {\n\tconst sourceRootClientId = registry\n\t\t.select( blockEditorStore )\n\t\t.getBlockRootClientId( [ clientId ] );\n\n\t// Search the top level blocks (widget areas) for the one with the matching\n\t// id attribute. Makes the assumption that all top-level blocks are widget\n\t// areas.\n\tconst widgetAreas = registry.select( blockEditorStore ).getBlocks();\n\tconst destinationWidgetAreaBlock = widgetAreas.find(\n\t\t( { attributes } ) => attributes.id === widgetAreaId\n\t);\n\tconst destinationRootClientId = destinationWidgetAreaBlock.clientId;\n\n\t// Get the index for moving to the end of the the destination widget area.\n\tconst destinationInnerBlocksClientIds = registry\n\t\t.select( blockEditorStore )\n\t\t.getBlockOrder( destinationRootClientId );\n\tconst destinationIndex = destinationInnerBlocksClientIds.length;\n\n\t// Reveal the widget area, if it's not open.\n\tconst isDestinationWidgetAreaOpen = select.getIsWidgetAreaOpen(\n\t\tdestinationRootClientId\n\t);\n\n\tif ( ! isDestinationWidgetAreaOpen ) {\n\t\tdispatch.setIsWidgetAreaOpen( destinationRootClientId, true );\n\t}\n\n\t// Move the block.\n\tregistry\n\t\t.dispatch( blockEditorStore )\n\t\t.moveBlocksToPosition(\n\t\t\t[ clientId ],\n\t\t\tsourceRootClientId,\n\t\t\tdestinationRootClientId,\n\t\t\tdestinationIndex\n\t\t);\n};\n"]}
|
|
@@ -11,7 +11,9 @@ import { combineReducers } from '@wordpress/data';
|
|
|
11
11
|
* @return {Array} Updated state.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export function widgetAreasOpenState(
|
|
14
|
+
export function widgetAreasOpenState() {
|
|
15
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
15
17
|
const {
|
|
16
18
|
type
|
|
17
19
|
} = action;
|
|
@@ -49,7 +51,10 @@ export function widgetAreasOpenState(state = {}, action) {
|
|
|
49
51
|
* @param {Object} action Dispatched action.
|
|
50
52
|
*/
|
|
51
53
|
|
|
52
|
-
export function blockInserterPanel(
|
|
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
|
+
|
|
53
58
|
switch (action.type) {
|
|
54
59
|
case 'SET_IS_LIST_VIEW_OPENED':
|
|
55
60
|
return action.isOpen ? false : state;
|
|
@@ -70,7 +75,10 @@ export function blockInserterPanel(state = false, action) {
|
|
|
70
75
|
* @param {Object} action Dispatched action.
|
|
71
76
|
*/
|
|
72
77
|
|
|
73
|
-
export function listViewPanel(
|
|
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
|
+
|
|
74
82
|
switch (action.type) {
|
|
75
83
|
case 'SET_IS_INSERTER_OPENED':
|
|
76
84
|
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","blockInserterPan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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,10 +20,11 @@ import { transformWidgetToBlock } from './transformers';
|
|
|
20
20
|
* @return {Function} An action creator.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
export const getWidgetAreas = () => async
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
export const getWidgetAreas = () => async _ref => {
|
|
24
|
+
let {
|
|
25
|
+
dispatch,
|
|
26
|
+
registry
|
|
27
|
+
} = _ref;
|
|
27
28
|
const query = buildWidgetAreasQuery();
|
|
28
29
|
const widgetAreas = await registry.resolveSelect(coreStore).getEntityRecords(KIND, WIDGET_AREA_ENTITY_TYPE, query);
|
|
29
30
|
const widgetAreaBlocks = [];
|
|
@@ -66,10 +67,11 @@ export const getWidgetAreas = () => async ({
|
|
|
66
67
|
* @return {Function} An action creator.
|
|
67
68
|
*/
|
|
68
69
|
|
|
69
|
-
export const getWidgets = () => async
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
export const getWidgets = () => async _ref2 => {
|
|
71
|
+
let {
|
|
72
|
+
dispatch,
|
|
73
|
+
registry
|
|
74
|
+
} = _ref2;
|
|
73
75
|
const query = buildWidgetsQuery();
|
|
74
76
|
const widgets = await registry.resolveSelect(coreStore).getEntityRecords('root', 'widget', query);
|
|
75
77
|
const groupedBySidebar = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-widgets/src/store/resolvers.js"],"names":["createBlock","store","coreStore","persistStubPost","setWidgetAreasOpenState","KIND","WIDGET_AREA_ENTITY_TYPE","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","buildWidgetAreasPostId","transformWidgetToBlock","getWidgetAreas","dispatch","registry","query","widgetAreas","resolveSelect","getEntityRecords","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","name","widgets","length","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","getWidgets","groupedBySidebar","widget","block","sidebar","sidebarId","hasOwnProperty"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,mBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASC,eAAT,EAA0BC,uBAA1B,QAAyD,WAAzD;AACA,SACCC,IADD,EAECC,uBAFD,EAGCC,iBAHD,EAICC,qBAJD,EAKCC,qBALD,EAMCC,sBAND,QAOO,SAPP;AAQA,SAASC,sBAAT,QAAuC,gBAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,cAAc,GAAG,MAAM,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-widgets/src/store/resolvers.js"],"names":["createBlock","store","coreStore","persistStubPost","setWidgetAreasOpenState","KIND","WIDGET_AREA_ENTITY_TYPE","buildWidgetsQuery","buildWidgetAreasQuery","buildWidgetAreaPostId","buildWidgetAreasPostId","transformWidgetToBlock","getWidgetAreas","dispatch","registry","query","widgetAreas","resolveSelect","getEntityRecords","widgetAreaBlocks","sortedWidgetAreas","sort","a","b","id","widgetArea","push","name","widgets","length","widgetAreasOpenState","forEach","widgetAreaBlock","index","clientId","getWidgets","groupedBySidebar","widget","block","sidebar","sidebarId","hasOwnProperty"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,mBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASC,eAAT,EAA0BC,uBAA1B,QAAyD,WAAzD;AACA,SACCC,IADD,EAECC,uBAFD,EAGCC,iBAHD,EAICC,qBAJD,EAKCC,qBALD,EAMCC,sBAND,QAOO,SAPP;AAQA,SAASC,sBAAT,QAAuC,gBAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,cAAc,GAAG,MAAM,cAAoC;AAAA,MAA5B;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACvE,QAAMC,KAAK,GA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A5B,CAAjB,CAAR;AACA,CAzCM;AA2CP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMgB,UAAU,GAAG,MAAM,eAAoC;AAAA,MAA5B;AAAEtB,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACnE,QAAMC,KAAK,GAAGR,iBAAiB,EAA/B;AACA,QAAMqB,OAAO,GAAG,MAAMd,QAAQ,CAC5BG,aADoB,CACLf,SADK,EAEpBgB,gBAFoB,CAEF,MAFE,EAEM,QAFN,EAEgBH,KAFhB,CAAtB;AAIA,QAAMqB,gBAAgB,GAAG,EAAzB;;AAEA,OAAM,MAAMC,MAAZ,IAAsBT,OAAtB,EAAgC;AAC/B,UAAMU,KAAK,GAAG3B,sBAAsB,CAAE0B,MAAF,CAApC;AACAD,IAAAA,gBAAgB,CAAEC,MAAM,CAACE,OAAT,CAAhB,GACCH,gBAAgB,CAAEC,MAAM,CAACE,OAAT,CAAhB,IAAsC,EADvC;AAEAH,IAAAA,gBAAgB,CAAEC,MAAM,CAACE,OAAT,CAAhB,CAAmCb,IAAnC,CAAyCY,KAAzC;AACA;;AAED,OAAM,MAAME,SAAZ,IAAyBJ,gBAAzB,EAA4C;AAC3C,QAAKA,gBAAgB,CAACK,cAAjB,CAAiCD,SAAjC,CAAL,EAAoD;AACnD;AACA3B,MAAAA,QAAQ,CACPV,eAAe,CACdM,qBAAqB,CAAE+B,SAAF,CADP,EAEdJ,gBAAgB,CAAEI,SAAF,CAFF,CADR,CAAR;AAMA;AACD;AACD,CA1BM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { persistStubPost, setWidgetAreasOpenState } from './actions';\nimport {\n\tKIND,\n\tWIDGET_AREA_ENTITY_TYPE,\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tbuildWidgetAreasPostId,\n} from './utils';\nimport { transformWidgetToBlock } from './transformers';\n\n/**\n * Creates a \"stub\" widgets post reflecting all available widget areas. The\n * post is meant as a convenient to only exists in runtime and should never be saved. It\n * enables a convenient way of editing the widgets by using a regular post editor.\n *\n * Fetches all widgets from all widgets aras, converts them into blocks, and hydrates a new post with them.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgetAreas = () => async ( { dispatch, registry } ) => {\n\tconst query = buildWidgetAreasQuery();\n\tconst widgetAreas = await registry\n\t\t.resolveSelect( coreStore )\n\t\t.getEntityRecords( KIND, WIDGET_AREA_ENTITY_TYPE, query );\n\n\tconst widgetAreaBlocks = [];\n\tconst sortedWidgetAreas = widgetAreas.sort( ( a, b ) => {\n\t\tif ( a.id === 'wp_inactive_widgets' ) {\n\t\t\treturn 1;\n\t\t}\n\t\tif ( b.id === 'wp_inactive_widgets' ) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn 0;\n\t} );\n\tfor ( const widgetArea of sortedWidgetAreas ) {\n\t\twidgetAreaBlocks.push(\n\t\t\tcreateBlock( 'core/widget-area', {\n\t\t\t\tid: widgetArea.id,\n\t\t\t\tname: widgetArea.name,\n\t\t\t} )\n\t\t);\n\n\t\tif ( ! widgetArea.widgets.length ) {\n\t\t\t// If this widget area has no widgets, it won't get a post setup by\n\t\t\t// the getWidgets resolver.\n\t\t\tdispatch(\n\t\t\t\tpersistStubPost( buildWidgetAreaPostId( widgetArea.id ), [] )\n\t\t\t);\n\t\t}\n\t}\n\n\tconst widgetAreasOpenState = {};\n\twidgetAreaBlocks.forEach( ( widgetAreaBlock, index ) => {\n\t\t// Defaults to open the first widget area.\n\t\twidgetAreasOpenState[ widgetAreaBlock.clientId ] = index === 0;\n\t} );\n\tdispatch( setWidgetAreasOpenState( widgetAreasOpenState ) );\n\n\tdispatch( persistStubPost( buildWidgetAreasPostId(), widgetAreaBlocks ) );\n};\n\n/**\n * Fetches all widgets from all widgets ares, and groups them by widget area Id.\n *\n * @return {Function} An action creator.\n */\nexport const getWidgets = () => async ( { dispatch, registry } ) => {\n\tconst query = buildWidgetsQuery();\n\tconst widgets = await registry\n\t\t.resolveSelect( coreStore )\n\t\t.getEntityRecords( 'root', 'widget', query );\n\n\tconst groupedBySidebar = {};\n\n\tfor ( const widget of widgets ) {\n\t\tconst block = transformWidgetToBlock( widget );\n\t\tgroupedBySidebar[ widget.sidebar ] =\n\t\t\tgroupedBySidebar[ widget.sidebar ] || [];\n\t\tgroupedBySidebar[ widget.sidebar ].push( block );\n\t}\n\n\tfor ( const sidebarId in groupedBySidebar ) {\n\t\tif ( groupedBySidebar.hasOwnProperty( sidebarId ) ) {\n\t\t\t// Persist the actual post containing the widget block\n\t\t\tdispatch(\n\t\t\t\tpersistStubPost(\n\t\t\t\t\tbuildWidgetAreaPostId( sidebarId ),\n\t\t\t\t\tgroupedBySidebar[ sidebarId ]\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n};\n"]}
|
|
@@ -95,16 +95,25 @@ export const getEditedWidgetAreas = createRegistrySelector(select => (state, ids
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
if (ids) {
|
|
98
|
-
widgetAreas = widgetAreas.filter(
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
widgetAreas = widgetAreas.filter(_ref => {
|
|
99
|
+
let {
|
|
100
|
+
id
|
|
101
|
+
} = _ref;
|
|
102
|
+
return ids.includes(id);
|
|
103
|
+
});
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
return widgetAreas.filter(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
return widgetAreas.filter(_ref2 => {
|
|
107
|
+
let {
|
|
108
|
+
id
|
|
109
|
+
} = _ref2;
|
|
110
|
+
return select(coreStore).hasEditsForEntityRecord(KIND, POST_TYPE, buildWidgetAreaPostId(id));
|
|
111
|
+
}).map(_ref3 => {
|
|
112
|
+
let {
|
|
113
|
+
id
|
|
114
|
+
} = _ref3;
|
|
115
|
+
return select(coreStore).getEditedEntityRecord(KIND, WIDGET_AREA_ENTITY_TYPE, id);
|
|
116
|
+
});
|
|
108
117
|
});
|
|
109
118
|
/**
|
|
110
119
|
* Returns all blocks representing reference widgets.
|
|
@@ -113,7 +122,8 @@ export const getEditedWidgetAreas = createRegistrySelector(select => (state, ids
|
|
|
113
122
|
* @return {Array} List of all blocks representing reference widgets
|
|
114
123
|
*/
|
|
115
124
|
|
|
116
|
-
export const getReferenceWidgetBlocks = createRegistrySelector(select => (state
|
|
125
|
+
export const getReferenceWidgetBlocks = createRegistrySelector(select => function (state) {
|
|
126
|
+
let referenceWidgetName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
117
127
|
const results = [];
|
|
118
128
|
const widgetAreas = select(editWidgetsStoreName).getWidgetAreas();
|
|
119
129
|
|
|
@@ -140,9 +150,12 @@ export const getReferenceWidgetBlocks = createRegistrySelector(select => (state,
|
|
|
140
150
|
export const isSavingWidgetAreas = createRegistrySelector(select => () => {
|
|
141
151
|
var _select$getWidgetArea;
|
|
142
152
|
|
|
143
|
-
const widgetAreasIds = (_select$getWidgetArea = select(editWidgetsStoreName).getWidgetAreas()) === null || _select$getWidgetArea === void 0 ? void 0 : _select$getWidgetArea.map(
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
const widgetAreasIds = (_select$getWidgetArea = select(editWidgetsStoreName).getWidgetAreas()) === null || _select$getWidgetArea === void 0 ? void 0 : _select$getWidgetArea.map(_ref4 => {
|
|
154
|
+
let {
|
|
155
|
+
id
|
|
156
|
+
} = _ref4;
|
|
157
|
+
return id;
|
|
158
|
+
});
|
|
146
159
|
|
|
147
160
|
if (!widgetAreasIds) {
|
|
148
161
|
return false;
|