@wordpress/edit-post 4.1.19 → 4.1.22
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/README.md +50 -69
- package/build/components/layout/index.js +1 -0
- package/build/components/layout/index.js.map +1 -1
- package/build/components/meta-boxes/index.js +39 -19
- package/build/components/meta-boxes/index.js.map +1 -1
- package/build/components/visual-editor/index.js +6 -5
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/index.js +9 -12
- package/build/index.js.map +1 -1
- package/build/store/actions.js +52 -34
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +20 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +13 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/layout/index.js +2 -1
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/meta-boxes/index.js +40 -19
- package/build-module/components/meta-boxes/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +6 -5
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/index.js +2 -5
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +50 -34
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +20 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +11 -0
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +26 -26
- package/src/components/layout/index.js +2 -0
- package/src/components/meta-boxes/index.js +41 -13
- package/src/components/visual-editor/index.js +12 -15
- package/src/index.js +2 -5
- package/src/store/actions.js +70 -52
- package/src/store/reducer.js +17 -0
- package/src/store/selectors.js +11 -0
package/src/store/actions.js
CHANGED
|
@@ -9,7 +9,7 @@ import { castArray, reduce } from 'lodash';
|
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
10
|
import { apiFetch } from '@wordpress/data-controls';
|
|
11
11
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
12
|
-
import { controls,
|
|
12
|
+
import { controls, select, subscribe, dispatch } from '@wordpress/data';
|
|
13
13
|
import { speak } from '@wordpress/a11y';
|
|
14
14
|
import { store as noticesStore } from '@wordpress/notices';
|
|
15
15
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -256,8 +256,6 @@ export function showBlockTypes( blockNames ) {
|
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
let saveMetaboxUnsubscribe;
|
|
260
|
-
|
|
261
259
|
/**
|
|
262
260
|
* Returns an action object used in signaling
|
|
263
261
|
* what Meta boxes are available in which location.
|
|
@@ -271,55 +269,6 @@ export function* setAvailableMetaBoxesPerLocation( metaBoxesPerLocation ) {
|
|
|
271
269
|
type: 'SET_META_BOXES_PER_LOCATIONS',
|
|
272
270
|
metaBoxesPerLocation,
|
|
273
271
|
};
|
|
274
|
-
|
|
275
|
-
const postType = yield controls.select(
|
|
276
|
-
'core/editor',
|
|
277
|
-
'getCurrentPostType'
|
|
278
|
-
);
|
|
279
|
-
if ( window.postboxes.page !== postType ) {
|
|
280
|
-
window.postboxes.add_postbox_toggles( postType );
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
let wasSavingPost = yield controls.select( 'core/editor', 'isSavingPost' );
|
|
284
|
-
let wasAutosavingPost = yield controls.select(
|
|
285
|
-
'core/editor',
|
|
286
|
-
'isAutosavingPost'
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
// Meta boxes are initialized once at page load. It is not necessary to
|
|
290
|
-
// account for updates on each state change.
|
|
291
|
-
//
|
|
292
|
-
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
|
|
293
|
-
const hasActiveMetaBoxes = yield controls.select(
|
|
294
|
-
editPostStore.name,
|
|
295
|
-
'hasMetaBoxes'
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
// First remove any existing subscription in order to prevent multiple saves
|
|
299
|
-
if ( !! saveMetaboxUnsubscribe ) {
|
|
300
|
-
saveMetaboxUnsubscribe();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Save metaboxes when performing a full save on the post.
|
|
304
|
-
saveMetaboxUnsubscribe = subscribe( () => {
|
|
305
|
-
const isSavingPost = select( 'core/editor' ).isSavingPost();
|
|
306
|
-
const isAutosavingPost = select( 'core/editor' ).isAutosavingPost();
|
|
307
|
-
|
|
308
|
-
// Save metaboxes on save completion, except for autosaves that are not a post preview.
|
|
309
|
-
const shouldTriggerMetaboxesSave =
|
|
310
|
-
hasActiveMetaBoxes &&
|
|
311
|
-
wasSavingPost &&
|
|
312
|
-
! isSavingPost &&
|
|
313
|
-
! wasAutosavingPost;
|
|
314
|
-
|
|
315
|
-
// Save current state for next inspection.
|
|
316
|
-
wasSavingPost = isSavingPost;
|
|
317
|
-
wasAutosavingPost = isAutosavingPost;
|
|
318
|
-
|
|
319
|
-
if ( shouldTriggerMetaboxesSave ) {
|
|
320
|
-
dispatch( editPostStore.name ).requestMetaBoxUpdates();
|
|
321
|
-
}
|
|
322
|
-
} );
|
|
323
272
|
}
|
|
324
273
|
|
|
325
274
|
/**
|
|
@@ -505,3 +454,72 @@ export function* __unstableSwitchToTemplateMode( template ) {
|
|
|
505
454
|
} );
|
|
506
455
|
}
|
|
507
456
|
}
|
|
457
|
+
|
|
458
|
+
let metaBoxesInitialized = false;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Initializes WordPress `postboxes` script and the logic for saving meta boxes.
|
|
462
|
+
*/
|
|
463
|
+
export function* initializeMetaBoxes() {
|
|
464
|
+
const isEditorReady = yield controls.select(
|
|
465
|
+
'core/editor',
|
|
466
|
+
'__unstableIsEditorReady'
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
if ( ! isEditorReady ) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const postType = yield controls.select(
|
|
474
|
+
'core/editor',
|
|
475
|
+
'getCurrentPostType'
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
// Only initialize once.
|
|
479
|
+
if ( metaBoxesInitialized ) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if ( window.postboxes.page !== postType ) {
|
|
484
|
+
window.postboxes.add_postbox_toggles( postType );
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
metaBoxesInitialized = true;
|
|
488
|
+
|
|
489
|
+
let wasSavingPost = yield controls.select( 'core/editor', 'isSavingPost' );
|
|
490
|
+
let wasAutosavingPost = yield controls.select(
|
|
491
|
+
'core/editor',
|
|
492
|
+
'isAutosavingPost'
|
|
493
|
+
);
|
|
494
|
+
const hasMetaBoxes = yield controls.select( editPostStore, 'hasMetaBoxes' );
|
|
495
|
+
|
|
496
|
+
// Save metaboxes when performing a full save on the post.
|
|
497
|
+
subscribe( () => {
|
|
498
|
+
const isSavingPost = select( 'core/editor' ).isSavingPost();
|
|
499
|
+
const isAutosavingPost = select( 'core/editor' ).isAutosavingPost();
|
|
500
|
+
|
|
501
|
+
// Save metaboxes on save completion, except for autosaves that are not a post preview.
|
|
502
|
+
//
|
|
503
|
+
// Meta boxes are initialized once at page load. It is not necessary to
|
|
504
|
+
// account for updates on each state change.
|
|
505
|
+
//
|
|
506
|
+
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
|
|
507
|
+
const shouldTriggerMetaboxesSave =
|
|
508
|
+
hasMetaBoxes &&
|
|
509
|
+
wasSavingPost &&
|
|
510
|
+
! isSavingPost &&
|
|
511
|
+
! wasAutosavingPost;
|
|
512
|
+
|
|
513
|
+
// Save current state for next inspection.
|
|
514
|
+
wasSavingPost = isSavingPost;
|
|
515
|
+
wasAutosavingPost = isAutosavingPost;
|
|
516
|
+
|
|
517
|
+
if ( shouldTriggerMetaboxesSave ) {
|
|
518
|
+
dispatch( editPostStore ).requestMetaBoxUpdates();
|
|
519
|
+
}
|
|
520
|
+
} );
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
type: 'META_BOXES_INITIALIZED',
|
|
524
|
+
};
|
|
525
|
+
}
|
package/src/store/reducer.js
CHANGED
|
@@ -290,9 +290,26 @@ function isEditingTemplate( state = false, action ) {
|
|
|
290
290
|
return state;
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Reducer tracking whether meta boxes are initialized.
|
|
295
|
+
*
|
|
296
|
+
* @param {boolean} state
|
|
297
|
+
* @param {Object} action
|
|
298
|
+
*
|
|
299
|
+
* @return {boolean} Updated state.
|
|
300
|
+
*/
|
|
301
|
+
function metaBoxesInitialized( state = false, action ) {
|
|
302
|
+
switch ( action.type ) {
|
|
303
|
+
case 'META_BOXES_INITIALIZED':
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
return state;
|
|
307
|
+
}
|
|
308
|
+
|
|
293
309
|
const metaBoxes = combineReducers( {
|
|
294
310
|
isSaving: isSavingMetaBoxes,
|
|
295
311
|
locations: metaBoxLocations,
|
|
312
|
+
initialized: metaBoxesInitialized,
|
|
296
313
|
} );
|
|
297
314
|
|
|
298
315
|
export default combineReducers( {
|
package/src/store/selectors.js
CHANGED
|
@@ -361,6 +361,17 @@ export function isEditingTemplate( state ) {
|
|
|
361
361
|
return state.isEditingTemplate;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/**
|
|
365
|
+
* Returns true if meta boxes are initialized.
|
|
366
|
+
*
|
|
367
|
+
* @param {Object} state Global application state.
|
|
368
|
+
*
|
|
369
|
+
* @return {boolean} Whether meta boxes are initialized.
|
|
370
|
+
*/
|
|
371
|
+
export function areMetaBoxesInitialized( state ) {
|
|
372
|
+
return state.metaBoxes.initialized;
|
|
373
|
+
}
|
|
374
|
+
|
|
364
375
|
/**
|
|
365
376
|
* Retrieves the template of the currently edited post.
|
|
366
377
|
*
|