|
3 | 3 | */
|
4 | 4 | import classnames from 'classnames';
|
5 | 5 |
|
6 |
| -import { get, isEqual } from 'lodash'; |
| 6 | +import { debounce, get, isEqual } from 'lodash'; |
7 | 7 |
|
8 | 8 | import hash from 'object-hash';
|
9 | 9 |
|
@@ -53,7 +53,6 @@ import Inspector from './inspector.js';
|
53 | 53 | import Placeholder from './placeholder.js';
|
54 | 54 | import { useResponsiveAttributes } from '../../helpers/utility-hooks';
|
55 | 55 | import { renderBoxOrNumWithUnit, _cssBlock, _px, findInnerBlocks } from '../../helpers/helper-functions';
|
56 |
| -import { Notice } from '@wordpress/components'; |
57 | 56 |
|
58 | 57 | const { attributes: defaultAttributes } = metadata;
|
59 | 58 |
|
@@ -107,7 +106,7 @@ const Edit = ({
|
107 | 106 | * @param {import('../../common').SyncAttrs<import('./type').FormAttrs>} field
|
108 | 107 | * @returns
|
109 | 108 | */
|
110 |
| - const getSyncValue = field =>{ |
| 109 | + const getSyncValue = field => { |
111 | 110 | if ( attributes?.isSynced?.includes( field ) ) {
|
112 | 111 | return getDefaultValueByField({ name, field, defaultAttributes, attributes });
|
113 | 112 | }
|
@@ -143,17 +142,24 @@ const Edit = ({
|
143 | 142 | moveBlockToPosition
|
144 | 143 | } = useDispatch( 'core/block-editor' );
|
145 | 144 |
|
146 |
| - const { |
147 |
| - unlockPostSaving |
148 |
| - } = useDispatch( 'core/editor' ); |
149 |
| - |
150 | 145 | const setFormOption = option => {
|
151 | 146 | setFormOptions( options => ({ ...options, ...option }) );
|
152 | 147 | };
|
153 | 148 |
|
| 149 | + /** |
| 150 | + * This mark the block as dirty which allow us to use the save button to trigger the update of the form options tied to WP Options. |
| 151 | + * |
| 152 | + * @type {DebouncedFunc<(function(): void)|*>} |
| 153 | + */ |
| 154 | + const enableSaveBtn = debounce( () => { |
| 155 | + const dummyBlock = createBlock( 'core/spacer', { height: '0px' }); |
| 156 | + insertBlock( dummyBlock, 0, clientId, false ); |
| 157 | + removeBlock( dummyBlock.clientId, false ); |
| 158 | + }, 3000 ); |
| 159 | + |
154 | 160 | const setFormOptionAndSaveUnlock = option => {
|
155 | 161 | setFormOption( option );
|
156 |
| - unlockPostSaving?.(); |
| 162 | + enableSaveBtn(); |
157 | 163 | };
|
158 | 164 |
|
159 | 165 | const [ savedFormOptions, setSavedFormOptions ] = useState( true );
|
@@ -204,9 +210,10 @@ const Edit = ({
|
204 | 210 | const isPublishingPost = select( 'core/editor' )?.isPublishingPost();
|
205 | 211 | const isAutosaving = select( 'core/editor' )?.isAutosavingPost();
|
206 | 212 | const widgetSaving = select( 'core/edit-widgets' )?.isSavingWidgetAreas();
|
| 213 | + const nonPostEntitySaving = select( 'core/editor' )?.isSavingNonPostEntityChanges(); |
207 | 214 |
|
208 | 215 | return {
|
209 |
| - canSaveData: ( ! isAutosaving && ( isSavingPost || isPublishingPost ) ) || widgetSaving |
| 216 | + canSaveData: ( ! isAutosaving && ( isSavingPost || isPublishingPost || nonPostEntitySaving ) ) || widgetSaving |
210 | 217 | };
|
211 | 218 | });
|
212 | 219 |
|
|
0 commit comments