@wordpress/edit-widgets 7.1.0 → 7.2.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/build/components/error-boundary/index.cjs +1 -1
- package/build/components/error-boundary/index.cjs.map +1 -1
- package/build/components/header/index.cjs +7 -2
- package/build/components/header/index.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +1 -0
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -1
- package/build/components/layout/unsaved-changes-warning.cjs +3 -6
- package/build/components/layout/unsaved-changes-warning.cjs.map +1 -1
- package/build/components/more-menu/index.cjs +0 -1
- package/build/components/more-menu/index.cjs.map +1 -1
- package/build/store/actions.cjs +9 -2
- package/build/store/actions.cjs.map +1 -1
- package/build-module/components/error-boundary/index.mjs +2 -2
- package/build-module/components/error-boundary/index.mjs.map +1 -1
- package/build-module/components/header/index.mjs +6 -2
- package/build-module/components/header/index.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +1 -0
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -1
- package/build-module/components/layout/unsaved-changes-warning.mjs +3 -6
- package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -1
- package/build-module/components/more-menu/index.mjs +0 -1
- package/build-module/components/more-menu/index.mjs.map +1 -1
- package/build-module/store/actions.mjs +9 -2
- package/build-module/store/actions.mjs.map +1 -1
- package/build-style/style-rtl.css +32 -11
- package/build-style/style.css +32 -11
- package/package.json +33 -33
- package/src/components/error-boundary/index.jsx +2 -2
- package/src/components/header/index.jsx +11 -2
- package/src/components/header/style.scss +30 -3
- package/src/components/keyboard-shortcut-help-modal/shortcut.jsx +1 -0
- package/src/components/keyboard-shortcut-help-modal/style.scss +1 -1
- package/src/components/layout/style.scss +5 -9
- package/src/components/layout/unsaved-changes-warning.js +4 -9
- package/src/components/more-menu/index.jsx +0 -1
- package/src/store/actions.js +25 -2
- package/src/store/test/actions.jsdom.test.js +230 -0
|
@@ -78,9 +78,16 @@ const saveWidgetArea = (widgetAreaId) => async ({ dispatch, select, registry })
|
|
|
78
78
|
const batchMeta = [];
|
|
79
79
|
const batchTasks = [];
|
|
80
80
|
const sidebarWidgetsIds = [];
|
|
81
|
+
const claimedWidgetIds = /* @__PURE__ */ new Set();
|
|
81
82
|
for (let i = 0; i < widgetsBlocks.length; i++) {
|
|
82
83
|
const block = widgetsBlocks[i];
|
|
83
|
-
|
|
84
|
+
let widgetId = getWidgetIdFromBlock(block);
|
|
85
|
+
if (widgetId) {
|
|
86
|
+
if (claimedWidgetIds.has(widgetId) || select.getWidgetAreaForWidgetId(widgetId)?.id !== widgetAreaId) {
|
|
87
|
+
widgetId = void 0;
|
|
88
|
+
delete block.attributes.__internalWidgetId;
|
|
89
|
+
} else claimedWidgetIds.add(widgetId);
|
|
90
|
+
}
|
|
84
91
|
const oldWidget = widgets[widgetId];
|
|
85
92
|
const widget = transformBlockToWidget(block, oldWidget);
|
|
86
93
|
sidebarWidgetsIds.push(widgetId);
|
|
@@ -107,7 +114,7 @@ const saveWidgetArea = (widgetAreaId) => async ({ dispatch, select, registry })
|
|
|
107
114
|
for (let i = 0; i < preservedRecords.length; i++) {
|
|
108
115
|
const widget = preservedRecords[i];
|
|
109
116
|
const { block, position } = batchMeta[i];
|
|
110
|
-
|
|
117
|
+
block.attributes.__internalWidgetId = widget.id;
|
|
111
118
|
if (registry.select(store$2).getLastEntitySaveError("root", "widget", widget.id)) failedWidgetNames.push(block.attributes?.name || block?.name);
|
|
112
119
|
if (!sidebarWidgetsIds[position]) sidebarWidgetsIds[position] = widget.id;
|
|
113
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.mjs","names":["coreStore","noticesStore","interfaceStore","editWidgetsStoreName","blockEditorStore"],"sources":["../../src/store/actions.js"],"sourcesContent":["import { __, 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';\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\n/**\n * Returns an action object used to signal that widget saving is unlocked.\n *\n * @param {string} lockName The lock name.\n *\n * @example\n * ```js\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useDispatch } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst { unlockWidgetSaving } = useDispatch( widgetStore );\n * \treturn (\n * \t\t<Button onClick={ () => unlockWidgetSaving( 'lockName' ) }>\n * \t\t\t{ __( 'Unlock Widget Saving' ) }\n * \t\t</Button>\n * \t);\n * };\n * ```\n *\n * @return {Object} Action object\n */\nexport function unlockWidgetSaving( lockName ) {\n\treturn {\n\t\ttype: 'UNLOCK_WIDGET_SAVING',\n\t\tlockName,\n\t};\n}\n\n/**\n * Returns an action object used to signal that widget saving is locked.\n *\n * @param {string} lockName The lock name.\n *\n * @example\n * ```js\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useDispatch } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst { lockWidgetSaving } = useDispatch( widgetStore );\n * \treturn (\n * \t\t<Button onClick={ () => lockWidgetSaving( 'lockName' ) }>\n * \t\t\t{ __( 'Lock Widget Saving' ) }\n * \t\t</Button>\n * \t);\n * };\n * ```\n *\n * @return {Object} Action object\n */\nexport function lockWidgetSaving( lockName ) {\n\treturn {\n\t\ttype: 'LOCK_WIDGET_SAVING',\n\t\tlockName,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAa,mBACV,IAAI,YACJ,EAAE,eAAgB;CACnB,MAAM,WAAW,eAAgB,IAAI,MAAO;CAC5C,SACE,SAAUA,OAAU,CAAC,CACrB,qBACA,MACA,WACA,UACA,EAAE,IAAI,SAAS,GAAG,GAClB,KACD;CACD,OAAO;AACR;;;;;;;;;AAUD,MAAa,8BAEZ,OAAQ,EAAE,QAAQ,UAAU,eAAgB;CAC3C,MAAM,oBAAoB,OAAO,qBAAqB;CACtD,IAAK,CAAE,mBAAmB,QACzB;CAED,IAAI;EACH,MAAM,SAAS,gBAAiB,iBAAkB;EAClD,SACE,SAAUC,KAAa,CAAC,CACxB,oBAAqB,GAAI,gBAAiB,GAAG,EAC7C,MAAM,WACP,CAAE;CACJ,SAAU,GAAI;EACb,SAAS,SAAUA,KAAa,CAAC,CAAC,kBAEjC,QAAS,GAAI,wBAAyB,GAAG,EAAE,OAAQ,GACnD,EACC,MAAM,WACP,CACD;CACD;AACD;;;;;;;;AASD,MAAa,mBACV,gBACF,OAAQ,EAAE,UAAU,eAAgB;CACnC,IAAI;EACH,KAAM,MAAM,cAAc,aACzB,MAAM,SAAS,eAAgB,WAAW,EAAG;CAE/C,UAAU;EAET,MAAM,SACJ,SAAUD,OAAU,CAAC,CACrB,iBACA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3,"file":"actions.mjs","names":["coreStore","noticesStore","interfaceStore","editWidgetsStoreName","blockEditorStore"],"sources":["../../src/store/actions.js"],"sourcesContent":["import { __, 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';\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\tconst claimedWidgetIds = new Set();\n\t\tfor ( let i = 0; i < widgetsBlocks.length; i++ ) {\n\t\t\tconst block = widgetsBlocks[ i ];\n\t\t\tlet widgetId = getWidgetIdFromBlock( block );\n\n\t\t\t// Splitting a block, e.g. pressing Enter in the middle of a\n\t\t\t// paragraph, copies all of its attributes to the new block,\n\t\t\t// including the widget ID, and the new block can then be moved to\n\t\t\t// another widget area. Only the first block with a given ID, in the\n\t\t\t// first widget area that holds it, updates that widget. Any other\n\t\t\t// block with the same ID is saved as a new widget.\n\t\t\tif ( widgetId ) {\n\t\t\t\tif (\n\t\t\t\t\tclaimedWidgetIds.has( widgetId ) ||\n\t\t\t\t\tselect.getWidgetAreaForWidgetId( widgetId )?.id !==\n\t\t\t\t\t\twidgetAreaId\n\t\t\t\t) {\n\t\t\t\t\twidgetId = undefined;\n\t\t\t\t\t// Drop the duplicate ID now, so nothing reads it before the\n\t\t\t\t\t// new widget's ID is written back after the batch.\n\t\t\t\t\tdelete block.attributes.__internalWidgetId;\n\t\t\t\t} else {\n\t\t\t\t\tclaimedWidgetIds.add( widgetId );\n\t\t\t\t}\n\t\t\t}\n\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\tblock.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\n/**\n * Returns an action object used to signal that widget saving is unlocked.\n *\n * @param {string} lockName The lock name.\n *\n * @example\n * ```js\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useDispatch } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst { unlockWidgetSaving } = useDispatch( widgetStore );\n * \treturn (\n * \t\t<Button onClick={ () => unlockWidgetSaving( 'lockName' ) }>\n * \t\t\t{ __( 'Unlock Widget Saving' ) }\n * \t\t</Button>\n * \t);\n * };\n * ```\n *\n * @return {Object} Action object\n */\nexport function unlockWidgetSaving( lockName ) {\n\treturn {\n\t\ttype: 'UNLOCK_WIDGET_SAVING',\n\t\tlockName,\n\t};\n}\n\n/**\n * Returns an action object used to signal that widget saving is locked.\n *\n * @param {string} lockName The lock name.\n *\n * @example\n * ```js\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useDispatch } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst { lockWidgetSaving } = useDispatch( widgetStore );\n * \treturn (\n * \t\t<Button onClick={ () => lockWidgetSaving( 'lockName' ) }>\n * \t\t\t{ __( 'Lock Widget Saving' ) }\n * \t\t</Button>\n * \t);\n * };\n * ```\n *\n * @return {Object} Action object\n */\nexport function lockWidgetSaving( lockName ) {\n\treturn {\n\t\ttype: 'LOCK_WIDGET_SAVING',\n\t\tlockName,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAa,mBACV,IAAI,YACJ,EAA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,oBAAqB,OAAQ;CAC5C,OAAO;EACN,MAAM;EACN;CACD;AACD;;;;;;;AAQA,SAAgB,oBAAqB,QAAS;CAC7C,OAAO;EACN,MAAM;EACN;CACD;AACD;;;;;;AAOA,MAAa,6BAEV,EAAE,eAAgB;CACnB,SACE,SAAUE,OAAe,CAAC,CAC1B,yBAA0BC,UAAqB;AAClD;;;;;;;AAQD,MAAa,yBACV,UAAU,iBACZ,OAAQ,EAAE,UAAU,QAAQ,eAAgB;CAC3C,MAAM,qBAAqB,SACzB,OAAQC,OAAiB,CAAC,CAC1B,qBAAsB,QAAS;CASjC,MAAM,0BAJc,SAAS,OAAQA,OAAiB,CAAC,CAAC,UACX,CAAC,CAAC,MAC5C,EAAE,iBAAkB,WAAW,OAAO,YAEgB,CAAC,CAAC;CAM3D,MAAM,mBAHkC,SACtC,OAAQA,OAAiB,CAAC,CAC1B,cAAe,uBACsC,CAAC,CAAC;CAOzD,IAAK,CAJ+B,OAAO,oBAC1C,uBAGgC,GAChC,SAAS,oBAAqB,yBAAyB,IAAK;CAI7D,SACE,SAAUA,OAAiB,CAAC,CAC5B,qBACA,CAAE,QAAS,GACX,oBACA,yBACA,gBACD;AACF;;;;;;;;;;;;;;;;;;;;;;;AAwBD,SAAgB,mBAAoB,UAAW;CAC9C,OAAO;EACN,MAAM;EACN;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAkB,UAAW;CAC5C,OAAO;EACN,MAAM;EACN;CACD;AACD"}
|
|
@@ -621,7 +621,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
621
621
|
justify-content: space-between;
|
|
622
622
|
height: 64px;
|
|
623
623
|
overflow: auto;
|
|
624
|
-
background: #fff;
|
|
624
|
+
background: var(--wpds-color-background-surface-neutral-strong, #fff);
|
|
625
625
|
}
|
|
626
626
|
@media (min-width: 600px) {
|
|
627
627
|
.edit-widgets-header {
|
|
@@ -654,7 +654,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
654
654
|
content: "";
|
|
655
655
|
width: 1px;
|
|
656
656
|
height: 24px;
|
|
657
|
-
background-color: #
|
|
657
|
+
background-color: var(--wpds-color-stroke-surface-neutral, #dbdbdb);
|
|
658
658
|
margin-top: 4px;
|
|
659
659
|
margin-right: 8px;
|
|
660
660
|
}
|
|
@@ -704,6 +704,17 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
704
704
|
gap: 8px;
|
|
705
705
|
}
|
|
706
706
|
|
|
707
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon {
|
|
708
|
+
padding: 0 12px;
|
|
709
|
+
}
|
|
710
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon svg {
|
|
711
|
+
display: none;
|
|
712
|
+
}
|
|
713
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon::after {
|
|
714
|
+
content: attr(aria-label);
|
|
715
|
+
white-space: nowrap;
|
|
716
|
+
}
|
|
717
|
+
|
|
707
718
|
.edit-widgets-header-toolbar {
|
|
708
719
|
gap: 8px;
|
|
709
720
|
margin-left: 8px;
|
|
@@ -716,7 +727,22 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
716
727
|
}
|
|
717
728
|
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed,
|
|
718
729
|
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed {
|
|
719
|
-
background: #1e1e1e;
|
|
730
|
+
background: var(--wpds-color-background-interactive-neutral-strong-active, #1e1e1e);
|
|
731
|
+
}
|
|
732
|
+
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed:is(:disabled, [aria-disabled=true]),
|
|
733
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed:is(:disabled, [aria-disabled=true]) {
|
|
734
|
+
background: var(--wpds-color-background-interactive-neutral-strong-disabled, #e5e5e5);
|
|
735
|
+
}
|
|
736
|
+
@media (forced-colors: active) {
|
|
737
|
+
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed,
|
|
738
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed {
|
|
739
|
+
background: SelectedItem !important;
|
|
740
|
+
}
|
|
741
|
+
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed:disabled, .edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed[aria-disabled=true],
|
|
742
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed:disabled,
|
|
743
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed[aria-disabled=true] {
|
|
744
|
+
background: GrayText !important;
|
|
745
|
+
}
|
|
720
746
|
}
|
|
721
747
|
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon:focus:not(:active),
|
|
722
748
|
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon:focus:not(:active) {
|
|
@@ -794,7 +820,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
794
820
|
margin: 0 0.2rem 0 0.2rem;
|
|
795
821
|
}
|
|
796
822
|
.edit-widgets-keyboard-shortcut-help-modal__shortcut-key:last-child {
|
|
797
|
-
margin: 0
|
|
823
|
+
margin-inline-end: 0;
|
|
798
824
|
}
|
|
799
825
|
|
|
800
826
|
.components-panel__header.edit-widgets-sidebar__panel-tabs {
|
|
@@ -854,16 +880,11 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
854
880
|
}
|
|
855
881
|
|
|
856
882
|
.edit-widgets-layout__inserter-panel-content {
|
|
857
|
-
height:
|
|
883
|
+
height: 100%;
|
|
858
884
|
}
|
|
859
|
-
.edit-widgets-layout__inserter-panel-content .block-editor-
|
|
885
|
+
.edit-widgets-layout__inserter-panel-content .block-editor-inserter__menu.has-single-tab .block-editor-tabbed-sidebar__tablist-and-close-button {
|
|
860
886
|
display: none;
|
|
861
887
|
}
|
|
862
|
-
@media (min-width: 782px) {
|
|
863
|
-
.edit-widgets-layout__inserter-panel-content {
|
|
864
|
-
height: 100%;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
888
|
|
|
868
889
|
.components-popover.more-menu-dropdown__content {
|
|
869
890
|
z-index: 99998;
|
package/build-style/style.css
CHANGED
|
@@ -621,7 +621,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
621
621
|
justify-content: space-between;
|
|
622
622
|
height: 64px;
|
|
623
623
|
overflow: auto;
|
|
624
|
-
background: #fff;
|
|
624
|
+
background: var(--wpds-color-background-surface-neutral-strong, #fff);
|
|
625
625
|
}
|
|
626
626
|
@media (min-width: 600px) {
|
|
627
627
|
.edit-widgets-header {
|
|
@@ -654,7 +654,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
654
654
|
content: "";
|
|
655
655
|
width: 1px;
|
|
656
656
|
height: 24px;
|
|
657
|
-
background-color: #
|
|
657
|
+
background-color: var(--wpds-color-stroke-surface-neutral, #dbdbdb);
|
|
658
658
|
margin-top: 4px;
|
|
659
659
|
margin-left: 8px;
|
|
660
660
|
}
|
|
@@ -704,6 +704,17 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
704
704
|
gap: 8px;
|
|
705
705
|
}
|
|
706
706
|
|
|
707
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon {
|
|
708
|
+
padding: 0 12px;
|
|
709
|
+
}
|
|
710
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon svg {
|
|
711
|
+
display: none;
|
|
712
|
+
}
|
|
713
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon::after {
|
|
714
|
+
content: attr(aria-label);
|
|
715
|
+
white-space: nowrap;
|
|
716
|
+
}
|
|
717
|
+
|
|
707
718
|
.edit-widgets-header-toolbar {
|
|
708
719
|
gap: 8px;
|
|
709
720
|
margin-right: 8px;
|
|
@@ -716,7 +727,22 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
716
727
|
}
|
|
717
728
|
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed,
|
|
718
729
|
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed {
|
|
719
|
-
background: #1e1e1e;
|
|
730
|
+
background: var(--wpds-color-background-interactive-neutral-strong-active, #1e1e1e);
|
|
731
|
+
}
|
|
732
|
+
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed:is(:disabled, [aria-disabled=true]),
|
|
733
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed:is(:disabled, [aria-disabled=true]) {
|
|
734
|
+
background: var(--wpds-color-background-interactive-neutral-strong-disabled, #e5e5e5);
|
|
735
|
+
}
|
|
736
|
+
@media (forced-colors: active) {
|
|
737
|
+
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed,
|
|
738
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed {
|
|
739
|
+
background: SelectedItem !important;
|
|
740
|
+
}
|
|
741
|
+
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed:disabled, .edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon.is-pressed[aria-disabled=true],
|
|
742
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed:disabled,
|
|
743
|
+
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon.is-pressed[aria-disabled=true] {
|
|
744
|
+
background: GrayText !important;
|
|
745
|
+
}
|
|
720
746
|
}
|
|
721
747
|
.edit-widgets-header-toolbar > .components-button.has-icon.has-icon.has-icon:focus:not(:active),
|
|
722
748
|
.edit-widgets-header-toolbar > .components-dropdown > .components-button.has-icon.has-icon:focus:not(:active) {
|
|
@@ -794,7 +820,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
794
820
|
margin: 0 0.2rem 0 0.2rem;
|
|
795
821
|
}
|
|
796
822
|
.edit-widgets-keyboard-shortcut-help-modal__shortcut-key:last-child {
|
|
797
|
-
margin: 0
|
|
823
|
+
margin-inline-end: 0;
|
|
798
824
|
}
|
|
799
825
|
|
|
800
826
|
.components-panel__header.edit-widgets-sidebar__panel-tabs {
|
|
@@ -854,16 +880,11 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
|
|
|
854
880
|
}
|
|
855
881
|
|
|
856
882
|
.edit-widgets-layout__inserter-panel-content {
|
|
857
|
-
height:
|
|
883
|
+
height: 100%;
|
|
858
884
|
}
|
|
859
|
-
.edit-widgets-layout__inserter-panel-content .block-editor-
|
|
885
|
+
.edit-widgets-layout__inserter-panel-content .block-editor-inserter__menu.has-single-tab .block-editor-tabbed-sidebar__tablist-and-close-button {
|
|
860
886
|
display: none;
|
|
861
887
|
}
|
|
862
|
-
@media (min-width: 782px) {
|
|
863
|
-
.edit-widgets-layout__inserter-panel-content {
|
|
864
|
-
height: 100%;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
888
|
|
|
868
889
|
.components-popover.more-menu-dropdown__content {
|
|
869
890
|
z-index: 99998;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-widgets",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "Widgets Page module for WordPress..",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -45,43 +45,43 @@
|
|
|
45
45
|
]
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@wordpress/a11y": "^5.
|
|
49
|
-
"@wordpress/admin-ui": "^3.
|
|
50
|
-
"@wordpress/api-fetch": "^8.
|
|
51
|
-
"@wordpress/base-styles": "^15.
|
|
52
|
-
"@wordpress/block-editor": "^20.
|
|
53
|
-
"@wordpress/block-library": "^12.
|
|
54
|
-
"@wordpress/blocks": "^17.
|
|
55
|
-
"@wordpress/components": "^
|
|
56
|
-
"@wordpress/compose": "^9.
|
|
57
|
-
"@wordpress/core-data": "^9.
|
|
58
|
-
"@wordpress/data": "^11.
|
|
59
|
-
"@wordpress/deprecated": "^5.
|
|
60
|
-
"@wordpress/dom": "^5.
|
|
61
|
-
"@wordpress/element": "^10.
|
|
62
|
-
"@wordpress/hooks": "^5.
|
|
63
|
-
"@wordpress/i18n": "^7.
|
|
64
|
-
"@wordpress/icons": "^
|
|
65
|
-
"@wordpress/interface": "^11.
|
|
66
|
-
"@wordpress/keyboard-shortcuts": "^6.
|
|
67
|
-
"@wordpress/keycodes": "^5.
|
|
68
|
-
"@wordpress/media-utils": "^6.
|
|
69
|
-
"@wordpress/notices": "^6.
|
|
70
|
-
"@wordpress/patterns": "^3.
|
|
71
|
-
"@wordpress/plugins": "^8.
|
|
72
|
-
"@wordpress/preferences": "^5.
|
|
73
|
-
"@wordpress/private-apis": "^3.
|
|
74
|
-
"@wordpress/theme": "^
|
|
75
|
-
"@wordpress/ui": "^0.
|
|
76
|
-
"@wordpress/url": "^5.
|
|
77
|
-
"@wordpress/widgets": "^5.
|
|
48
|
+
"@wordpress/a11y": "^5.2.0",
|
|
49
|
+
"@wordpress/admin-ui": "^3.2.0",
|
|
50
|
+
"@wordpress/api-fetch": "^8.2.0",
|
|
51
|
+
"@wordpress/base-styles": "^15.1.0",
|
|
52
|
+
"@wordpress/block-editor": "^20.1.0",
|
|
53
|
+
"@wordpress/block-library": "^12.2.0",
|
|
54
|
+
"@wordpress/blocks": "^17.2.0",
|
|
55
|
+
"@wordpress/components": "^45.0.0",
|
|
56
|
+
"@wordpress/compose": "^9.2.0",
|
|
57
|
+
"@wordpress/core-data": "^9.2.0",
|
|
58
|
+
"@wordpress/data": "^11.2.0",
|
|
59
|
+
"@wordpress/deprecated": "^5.2.0",
|
|
60
|
+
"@wordpress/dom": "^5.2.0",
|
|
61
|
+
"@wordpress/element": "^10.2.0",
|
|
62
|
+
"@wordpress/hooks": "^5.2.0",
|
|
63
|
+
"@wordpress/i18n": "^7.2.0",
|
|
64
|
+
"@wordpress/icons": "^21.0.0",
|
|
65
|
+
"@wordpress/interface": "^11.2.0",
|
|
66
|
+
"@wordpress/keyboard-shortcuts": "^6.2.0",
|
|
67
|
+
"@wordpress/keycodes": "^5.2.0",
|
|
68
|
+
"@wordpress/media-utils": "^6.2.0",
|
|
69
|
+
"@wordpress/notices": "^6.2.0",
|
|
70
|
+
"@wordpress/patterns": "^3.2.0",
|
|
71
|
+
"@wordpress/plugins": "^8.2.0",
|
|
72
|
+
"@wordpress/preferences": "^5.2.0",
|
|
73
|
+
"@wordpress/private-apis": "^3.2.0",
|
|
74
|
+
"@wordpress/theme": "^5.0.0",
|
|
75
|
+
"@wordpress/ui": "^0.27.0",
|
|
76
|
+
"@wordpress/url": "^5.2.0",
|
|
77
|
+
"@wordpress/widgets": "^5.2.0",
|
|
78
78
|
"clsx": "^2.1.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@testing-library/dom": "^10.4.2",
|
|
82
82
|
"@testing-library/react": "^16.3.3",
|
|
83
83
|
"deep-freeze": "^0.0.1",
|
|
84
|
-
"vitest": "^5.0
|
|
84
|
+
"vitest": "^5.1.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"react": "^18 || ^19",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"publishConfig": {
|
|
91
91
|
"access": "public"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
|
|
94
94
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component } from '@wordpress/element';
|
|
2
2
|
import { speak } from '@wordpress/a11y';
|
|
3
|
-
import { __ } from '@wordpress/i18n';
|
|
3
|
+
import { __, _x } from '@wordpress/i18n';
|
|
4
4
|
import { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';
|
|
5
5
|
import { useCopyToClipboard } from '@wordpress/compose';
|
|
6
6
|
import { doAction } from '@wordpress/hooks';
|
|
@@ -168,7 +168,7 @@ export default class ErrorBoundary extends Component {
|
|
|
168
168
|
getErrorReport( error, componentStack )
|
|
169
169
|
}
|
|
170
170
|
>
|
|
171
|
-
{
|
|
171
|
+
{ _x( 'Copy error', 'button label' ) }
|
|
172
172
|
</CopyButton>
|
|
173
173
|
</Notice.Actions>
|
|
174
174
|
</Notice.Root>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
1
2
|
import { BlockToolbar } from '@wordpress/block-editor';
|
|
2
3
|
import { useSelect } from '@wordpress/data';
|
|
3
4
|
import { useRef } from '@wordpress/element';
|
|
@@ -14,19 +15,27 @@ import MoreMenu from '../more-menu';
|
|
|
14
15
|
function Header() {
|
|
15
16
|
const isLargeViewport = useViewportMatch( 'medium' );
|
|
16
17
|
const blockToolbarRef = useRef();
|
|
17
|
-
const { hasFixedToolbar } = useSelect(
|
|
18
|
+
const { hasFixedToolbar, showIconLabels } = useSelect(
|
|
18
19
|
( select ) => ( {
|
|
19
20
|
hasFixedToolbar: !! select( preferencesStore ).get(
|
|
20
21
|
'core/edit-widgets',
|
|
21
22
|
'fixedToolbar'
|
|
22
23
|
),
|
|
24
|
+
showIconLabels: select( preferencesStore ).get(
|
|
25
|
+
'core',
|
|
26
|
+
'showIconLabels'
|
|
27
|
+
),
|
|
23
28
|
} ),
|
|
24
29
|
[]
|
|
25
30
|
);
|
|
26
31
|
|
|
27
32
|
return (
|
|
28
33
|
<>
|
|
29
|
-
<div
|
|
34
|
+
<div
|
|
35
|
+
className={ clsx( 'edit-widgets-header', {
|
|
36
|
+
'has-icon-labels': showIconLabels,
|
|
37
|
+
} ) }
|
|
38
|
+
>
|
|
30
39
|
<div className="edit-widgets-header__navigable-toolbar-wrapper">
|
|
31
40
|
{ isLargeViewport && (
|
|
32
41
|
<h1 className="edit-widgets-header__title">
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
justify-content: space-between;
|
|
10
10
|
height: $header-height;
|
|
11
11
|
overflow: auto;
|
|
12
|
-
background:
|
|
12
|
+
background: var(--wpds-color-background-surface-neutral-strong);
|
|
13
13
|
|
|
14
14
|
@include break-small {
|
|
15
15
|
overflow: visible;
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
content: "";
|
|
50
50
|
width: $border-width;
|
|
51
51
|
height: $grid-unit-30;
|
|
52
|
-
background-color:
|
|
52
|
+
background-color: var(--wpds-color-stroke-surface-neutral);
|
|
53
53
|
margin-top: $grid-unit-05;
|
|
54
54
|
margin-left: $grid-unit;
|
|
55
55
|
}
|
|
@@ -108,6 +108,20 @@
|
|
|
108
108
|
gap: $grid-unit-10;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
// With "Show button text labels" on, pinned items show their label (the aria-label) in place of the icon.
|
|
112
|
+
.edit-widgets-header.has-icon-labels .interface-pinned-items .components-button.has-icon {
|
|
113
|
+
padding: 0 $grid-unit-15;
|
|
114
|
+
|
|
115
|
+
svg {
|
|
116
|
+
display: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
&::after {
|
|
120
|
+
content: attr(aria-label);
|
|
121
|
+
white-space: nowrap;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
111
125
|
.edit-widgets-header-toolbar {
|
|
112
126
|
gap: $grid-unit-10;
|
|
113
127
|
// Some plugins add buttons here despite best practices.
|
|
@@ -124,7 +138,20 @@
|
|
|
124
138
|
padding: 4px;
|
|
125
139
|
|
|
126
140
|
&.is-pressed {
|
|
127
|
-
background:
|
|
141
|
+
background: var(--wpds-color-background-interactive-neutral-strong-active);
|
|
142
|
+
|
|
143
|
+
&:is(:disabled, [aria-disabled="true"]) {
|
|
144
|
+
background: var(--wpds-color-background-interactive-neutral-strong-disabled);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@media (forced-colors: active) {
|
|
148
|
+
background: SelectedItem !important;
|
|
149
|
+
|
|
150
|
+
&:disabled,
|
|
151
|
+
&[aria-disabled="true"] {
|
|
152
|
+
background: GrayText !important;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
128
155
|
}
|
|
129
156
|
|
|
130
157
|
&:focus:not(:active) {
|
|
@@ -17,6 +17,7 @@ function KeyCombination( { keyCombination, forceAriaLabel } ) {
|
|
|
17
17
|
return (
|
|
18
18
|
<kbd
|
|
19
19
|
className="edit-widgets-keyboard-shortcut-help-modal__shortcut-key-combination"
|
|
20
|
+
dir="ltr"
|
|
20
21
|
aria-label={ forceAriaLabel || ariaLabel }
|
|
21
22
|
>
|
|
22
23
|
{ shortcuts.map( ( character, index ) => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
@use "@wordpress/base-styles/mixins" as *;
|
|
2
1
|
@use "@wordpress/base-styles/variables" as *;
|
|
3
2
|
|
|
4
3
|
.edit-widgets-layout__footer {
|
|
@@ -22,14 +21,11 @@
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
.edit-widgets-layout__inserter-panel-content {
|
|
25
|
-
|
|
26
|
-
height: calc(100% - #{$button-size} - #{$grid-unit-10});
|
|
27
|
-
|
|
28
|
-
.block-editor-inserter__tablist-and-close {
|
|
29
|
-
display: none;
|
|
30
|
-
}
|
|
24
|
+
height: 100%;
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
.block-editor-inserter__menu.has-single-tab {
|
|
27
|
+
.block-editor-tabbed-sidebar__tablist-and-close-button {
|
|
28
|
+
display: none;
|
|
29
|
+
}
|
|
34
30
|
}
|
|
35
31
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __ } from '@wordpress/i18n';
|
|
2
1
|
import { useEffect } from '@wordpress/element';
|
|
3
2
|
import { useSelect } from '@wordpress/data';
|
|
4
3
|
import { store as editWidgetsStore } from '../../store';
|
|
@@ -23,21 +22,17 @@ export default function UnsavedChangesWarning() {
|
|
|
23
22
|
/**
|
|
24
23
|
* Warns the user if there are unsaved changes before leaving the editor.
|
|
25
24
|
*
|
|
26
|
-
* @param {
|
|
27
|
-
*
|
|
28
|
-
* @return {string | undefined} Warning prompt message, if unsaved changes exist.
|
|
25
|
+
* @param {BeforeUnloadEvent} event `beforeunload` event.
|
|
29
26
|
*/
|
|
30
27
|
const warnIfUnsavedChanges = ( event ) => {
|
|
31
28
|
if ( isDirty ) {
|
|
32
|
-
event.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return event.returnValue;
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
// Chrome before 119 ignores `preventDefault()`.
|
|
31
|
+
event.returnValue = true;
|
|
36
32
|
}
|
|
37
33
|
};
|
|
38
34
|
|
|
39
35
|
window.addEventListener( 'beforeunload', warnIfUnsavedChanges );
|
|
40
|
-
|
|
41
36
|
return () => {
|
|
42
37
|
window.removeEventListener( 'beforeunload', warnIfUnsavedChanges );
|
|
43
38
|
};
|
package/src/store/actions.js
CHANGED
|
@@ -155,9 +155,32 @@ export const saveWidgetArea =
|
|
|
155
155
|
const batchMeta = [];
|
|
156
156
|
const batchTasks = [];
|
|
157
157
|
const sidebarWidgetsIds = [];
|
|
158
|
+
const claimedWidgetIds = new Set();
|
|
158
159
|
for ( let i = 0; i < widgetsBlocks.length; i++ ) {
|
|
159
160
|
const block = widgetsBlocks[ i ];
|
|
160
|
-
|
|
161
|
+
let widgetId = getWidgetIdFromBlock( block );
|
|
162
|
+
|
|
163
|
+
// Splitting a block, e.g. pressing Enter in the middle of a
|
|
164
|
+
// paragraph, copies all of its attributes to the new block,
|
|
165
|
+
// including the widget ID, and the new block can then be moved to
|
|
166
|
+
// another widget area. Only the first block with a given ID, in the
|
|
167
|
+
// first widget area that holds it, updates that widget. Any other
|
|
168
|
+
// block with the same ID is saved as a new widget.
|
|
169
|
+
if ( widgetId ) {
|
|
170
|
+
if (
|
|
171
|
+
claimedWidgetIds.has( widgetId ) ||
|
|
172
|
+
select.getWidgetAreaForWidgetId( widgetId )?.id !==
|
|
173
|
+
widgetAreaId
|
|
174
|
+
) {
|
|
175
|
+
widgetId = undefined;
|
|
176
|
+
// Drop the duplicate ID now, so nothing reads it before the
|
|
177
|
+
// new widget's ID is written back after the batch.
|
|
178
|
+
delete block.attributes.__internalWidgetId;
|
|
179
|
+
} else {
|
|
180
|
+
claimedWidgetIds.add( widgetId );
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
161
184
|
const oldWidget = widgets[ widgetId ];
|
|
162
185
|
const widget = transformBlockToWidget( block, oldWidget );
|
|
163
186
|
|
|
@@ -230,7 +253,7 @@ export const saveWidgetArea =
|
|
|
230
253
|
|
|
231
254
|
// Set __internalWidgetId on the block. This will be persisted to the
|
|
232
255
|
// store when we dispatch receiveEntityRecords( post ) below.
|
|
233
|
-
|
|
256
|
+
block.attributes.__internalWidgetId = widget.id;
|
|
234
257
|
|
|
235
258
|
const error = registry
|
|
236
259
|
.select( coreStore )
|