@wordpress/editor 13.14.0 → 13.15.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/entities-saved-states/entity-record-item.js +3 -37
  3. package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
  4. package/build/components/entities-saved-states/entity-type-list.js +2 -4
  5. package/build/components/entities-saved-states/entity-type-list.js.map +1 -1
  6. package/build/components/entities-saved-states/index.js +0 -1
  7. package/build/components/entities-saved-states/index.js.map +1 -1
  8. package/build/components/global-keyboard-shortcuts/{save-shortcut.js → index.js} +13 -25
  9. package/build/components/global-keyboard-shortcuts/index.js.map +1 -0
  10. package/build/components/index.js +32 -19
  11. package/build/components/index.js.map +1 -1
  12. package/build/components/post-preview-button/index.js +62 -157
  13. package/build/components/post-preview-button/index.js.map +1 -1
  14. package/build/components/post-publish-button/index.js +4 -9
  15. package/build/components/post-publish-button/index.js.map +1 -1
  16. package/build/components/post-publish-button/label.js +2 -4
  17. package/build/components/post-publish-button/label.js.map +1 -1
  18. package/build/components/post-publish-panel/index.js +1 -3
  19. package/build/components/post-publish-panel/index.js.map +1 -1
  20. package/build/components/post-saved-state/index.js +2 -5
  21. package/build/components/post-saved-state/index.js.map +1 -1
  22. package/build/components/post-schedule/label.js +4 -4
  23. package/build/components/post-schedule/label.js.map +1 -1
  24. package/build/components/post-sync-status/index.js +84 -5
  25. package/build/components/post-sync-status/index.js.map +1 -1
  26. package/build/components/post-text-editor/index.js +51 -58
  27. package/build/components/post-text-editor/index.js.map +1 -1
  28. package/build/store/actions.js +37 -3
  29. package/build/store/actions.js.map +1 -1
  30. package/build/store/selectors.js +53 -61
  31. package/build/store/selectors.js.map +1 -1
  32. package/build-module/components/entities-saved-states/entity-record-item.js +6 -40
  33. package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
  34. package/build-module/components/entities-saved-states/entity-type-list.js +2 -4
  35. package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
  36. package/build-module/components/entities-saved-states/index.js +0 -1
  37. package/build-module/components/entities-saved-states/index.js.map +1 -1
  38. package/build-module/components/global-keyboard-shortcuts/{save-shortcut.js → index.js} +12 -23
  39. package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -0
  40. package/build-module/components/index.js +9 -4
  41. package/build-module/components/index.js.map +1 -1
  42. package/build-module/components/post-preview-button/index.js +63 -149
  43. package/build-module/components/post-preview-button/index.js.map +1 -1
  44. package/build-module/components/post-publish-button/index.js +4 -9
  45. package/build-module/components/post-publish-button/index.js.map +1 -1
  46. package/build-module/components/post-publish-button/label.js +2 -4
  47. package/build-module/components/post-publish-button/label.js.map +1 -1
  48. package/build-module/components/post-publish-panel/index.js +1 -3
  49. package/build-module/components/post-publish-panel/index.js.map +1 -1
  50. package/build-module/components/post-saved-state/index.js +2 -5
  51. package/build-module/components/post-saved-state/index.js.map +1 -1
  52. package/build-module/components/post-schedule/label.js +4 -4
  53. package/build-module/components/post-schedule/label.js.map +1 -1
  54. package/build-module/components/post-sync-status/index.js +84 -8
  55. package/build-module/components/post-sync-status/index.js.map +1 -1
  56. package/build-module/components/post-text-editor/index.js +48 -56
  57. package/build-module/components/post-text-editor/index.js.map +1 -1
  58. package/build-module/store/actions.js +31 -1
  59. package/build-module/store/actions.js.map +1 -1
  60. package/build-module/store/selectors.js +46 -55
  61. package/build-module/store/selectors.js.map +1 -1
  62. package/build-style/style-rtl.css +0 -18
  63. package/build-style/style.css +0 -18
  64. package/package.json +30 -30
  65. package/src/components/entities-saved-states/entity-record-item.js +3 -61
  66. package/src/components/entities-saved-states/entity-type-list.js +0 -2
  67. package/src/components/entities-saved-states/index.js +0 -1
  68. package/src/components/entities-saved-states/style.scss +0 -15
  69. package/src/components/global-keyboard-shortcuts/index.js +49 -0
  70. package/src/components/index.js +12 -3
  71. package/src/components/post-preview-button/index.js +73 -156
  72. package/src/components/post-preview-button/test/index.js +94 -158
  73. package/src/components/post-publish-button/index.js +2 -7
  74. package/src/components/post-publish-button/label.js +2 -2
  75. package/src/components/post-publish-button/test/index.js +0 -10
  76. package/src/components/post-publish-panel/index.js +1 -3
  77. package/src/components/post-saved-state/index.js +2 -5
  78. package/src/components/post-schedule/label.js +4 -4
  79. package/src/components/post-sync-status/index.js +100 -7
  80. package/src/components/post-text-editor/index.js +34 -57
  81. package/src/components/post-title/style.native.scss +5 -5
  82. package/src/store/actions.js +34 -2
  83. package/src/store/selectors.js +45 -41
  84. package/src/store/test/selectors.js +36 -25
  85. package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +0 -1
  86. package/build/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -22
  87. package/build/components/global-keyboard-shortcuts/text-editor-shortcuts.js.map +0 -1
  88. package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -45
  89. package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +0 -1
  90. package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +0 -1
  91. package/build-module/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -12
  92. package/build-module/components/global-keyboard-shortcuts/text-editor-shortcuts.js.map +0 -1
  93. package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -32
  94. package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +0 -1
  95. package/src/components/global-keyboard-shortcuts/save-shortcut.js +0 -55
  96. package/src/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -8
  97. package/src/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -29
  98. package/src/components/post-text-editor/test/index.js +0 -156
@@ -7,8 +7,9 @@ import Textarea from 'react-autosize-textarea';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { __ } from '@wordpress/i18n';
10
- import { useEffect, useState, useRef } from '@wordpress/element';
11
- import { parse } from '@wordpress/blocks';
10
+ import { store as coreStore } from '@wordpress/core-data';
11
+ import { useMemo } from '@wordpress/element';
12
+ import { __unstableSerializeAndClean } from '@wordpress/blocks';
12
13
  import { useDispatch, useSelect } from '@wordpress/data';
13
14
  import { useInstanceId } from '@wordpress/compose';
14
15
  import { VisuallyHidden } from '@wordpress/components';
@@ -19,63 +20,34 @@ import { VisuallyHidden } from '@wordpress/components';
19
20
  import { store as editorStore } from '../../store';
20
21
 
21
22
  export default function PostTextEditor() {
22
- const postContent = useSelect(
23
- ( select ) => select( editorStore ).getEditedPostContent(),
24
- []
25
- );
26
-
27
- const { editPost, resetEditorBlocks } = useDispatch( editorStore );
28
-
29
- const [ value, setValue ] = useState( postContent );
30
- const [ isDirty, setIsDirty ] = useState( false );
31
23
  const instanceId = useInstanceId( PostTextEditor );
32
- const valueRef = useRef();
33
-
34
- if ( ! isDirty && value !== postContent ) {
35
- setValue( postContent );
36
- }
24
+ const { content, blocks, type, id } = useSelect( ( select ) => {
25
+ const { getEditedEntityRecord } = select( coreStore );
26
+ const { getCurrentPostType, getCurrentPostId } = select( editorStore );
27
+ const _type = getCurrentPostType();
28
+ const _id = getCurrentPostId();
29
+ const editedRecord = getEditedEntityRecord( 'postType', _type, _id );
37
30
 
38
- /**
39
- * Handles a textarea change event to notify the onChange prop callback and
40
- * reflect the new value in the component's own state. This marks the start
41
- * of the user's edits, if not already changed, preventing future props
42
- * changes to value from replacing the rendered value. This is expected to
43
- * be followed by a reset to dirty state via `stopEditing`.
44
- *
45
- * @see stopEditing
46
- *
47
- * @param {Event} event Change event.
48
- */
49
- const onChange = ( event ) => {
50
- const newValue = event.target.value;
51
- editPost( { content: newValue } );
52
- setValue( newValue );
53
- setIsDirty( true );
54
- valueRef.current = newValue;
55
- };
56
-
57
- /**
58
- * Function called when the user has completed their edits, responsible for
59
- * ensuring that changes, if made, are surfaced to the onPersist prop
60
- * callback and resetting dirty state.
61
- */
62
- const stopEditing = () => {
63
- if ( isDirty ) {
64
- const blocks = parse( value );
65
- resetEditorBlocks( blocks );
66
- setIsDirty( false );
67
- }
68
- };
69
-
70
- // Ensure changes aren't lost when component unmounts.
71
- useEffect( () => {
72
- return () => {
73
- if ( valueRef.current ) {
74
- const blocks = parse( valueRef.current );
75
- resetEditorBlocks( blocks );
76
- }
31
+ return {
32
+ content: editedRecord?.content,
33
+ blocks: editedRecord?.blocks,
34
+ type: _type,
35
+ id: _id,
77
36
  };
78
37
  }, [] );
38
+ const { editEntityRecord } = useDispatch( coreStore );
39
+ // Replicates the logic found in getEditedPostContent().
40
+ const value = useMemo( () => {
41
+ if ( content instanceof Function ) {
42
+ return content( { blocks } );
43
+ } else if ( blocks ) {
44
+ // If we have parsed blocks already, they should be our source of truth.
45
+ // Parsing applies block deprecations and legacy block conversions that
46
+ // unparsed content will not have.
47
+ return __unstableSerializeAndClean( blocks );
48
+ }
49
+ return content;
50
+ }, [ content, blocks ] );
79
51
 
80
52
  return (
81
53
  <>
@@ -89,8 +61,13 @@ export default function PostTextEditor() {
89
61
  autoComplete="off"
90
62
  dir="auto"
91
63
  value={ value }
92
- onChange={ onChange }
93
- onBlur={ stopEditing }
64
+ onChange={ ( event ) => {
65
+ editEntityRecord( 'postType', type, id, {
66
+ content: event.target.value,
67
+ blocks: undefined,
68
+ selection: undefined,
69
+ } );
70
+ } }
94
71
  className="editor-post-text-editor"
95
72
  id={ `post-content-${ instanceId }` }
96
73
  placeholder={ __( 'Start writing with text or HTML' ) }
@@ -1,10 +1,10 @@
1
1
 
2
2
  .titleContainer {
3
- padding-left: 12;
4
- padding-right: 16;
5
- padding-top: 12;
6
- padding-bottom: 12;
7
- margin-top: 24;
3
+ padding-left: $block-edge-to-content;
4
+ padding-right: $block-edge-to-content;
5
+ padding-top: 6;
6
+ padding-bottom: 6;
7
+ margin-top: 12;
8
8
  }
9
9
 
10
10
  .dimmed {
@@ -11,6 +11,7 @@ import {
11
11
  import { store as noticesStore } from '@wordpress/notices';
12
12
  import { store as coreStore } from '@wordpress/core-data';
13
13
  import { store as blockEditorStore } from '@wordpress/block-editor';
14
+ import { applyFilters } from '@wordpress/hooks';
14
15
  import { store as preferencesStore } from '@wordpress/preferences';
15
16
 
16
17
  /**
@@ -177,15 +178,26 @@ export const savePost =
177
178
  edits,
178
179
  options
179
180
  );
180
- dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );
181
181
 
182
- const error = registry
182
+ let error = registry
183
183
  .select( coreStore )
184
184
  .getLastEntitySaveError(
185
185
  'postType',
186
186
  previousRecord.type,
187
187
  previousRecord.id
188
188
  );
189
+
190
+ if ( ! error ) {
191
+ await applyFilters(
192
+ 'editor.__unstableSavePost',
193
+ Promise.resolve(),
194
+ options
195
+ ).catch( ( err ) => {
196
+ error = err;
197
+ } );
198
+ }
199
+ dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );
200
+
189
201
  if ( error ) {
190
202
  const args = getNotificationArgumentsForSaveFail( {
191
203
  post: previousRecord,
@@ -289,6 +301,26 @@ export const autosave =
289
301
  }
290
302
  };
291
303
 
304
+ export const __unstableSaveForPreview =
305
+ ( { forceIsAutosaveable } ) =>
306
+ async ( { select, dispatch } ) => {
307
+ if (
308
+ ( forceIsAutosaveable || select.isEditedPostAutosaveable() ) &&
309
+ ! select.isPostLocked()
310
+ ) {
311
+ const isDraft = [ 'draft', 'auto-draft' ].includes(
312
+ select.getEditedPostAttribute( 'status' )
313
+ );
314
+ if ( isDraft ) {
315
+ await dispatch.savePost( { isPreview: true } );
316
+ } else {
317
+ await dispatch.autosave( { isPreview: true } );
318
+ }
319
+ }
320
+
321
+ return select.getEditedPostPreviewLink();
322
+ };
323
+
292
324
  /**
293
325
  * Action that restores last popped state in undo history.
294
326
  */
@@ -10,6 +10,7 @@ import {
10
10
  getFreeformContentHandlerName,
11
11
  getDefaultBlockName,
12
12
  __unstableSerializeAndClean,
13
+ parse,
13
14
  } from '@wordpress/blocks';
14
15
  import { isInTheFuture, getDate } from '@wordpress/date';
15
16
  import { addQueryArgs, cleanForSlug } from '@wordpress/url';
@@ -42,15 +43,6 @@ import { getTemplatePartIcon } from '../utils/get-template-part-icon';
42
43
  */
43
44
  const EMPTY_OBJECT = {};
44
45
 
45
- /**
46
- * Shared reference to an empty array for cases where it is important to avoid
47
- * returning a new array reference on every invocation, as in a connected or
48
- * other pure component which performs `shouldComponentUpdate` check on props.
49
- * This should be used as a last resort, since the normalized data should be
50
- * maintained by the reducer result in state.
51
- */
52
- const EMPTY_ARRAY = [];
53
-
54
46
  /**
55
47
  * Returns true if any past editor history snapshots exist, or false otherwise.
56
48
  *
@@ -507,16 +499,31 @@ export function isEditedPostSaveable( state ) {
507
499
  *
508
500
  * @return {boolean} Whether post has content.
509
501
  */
510
- export function isEditedPostEmpty( state ) {
511
- // While the condition of truthy content string is sufficient to determine
512
- // emptiness, testing saveable blocks length is a trivial operation. Since
513
- // this function can be called frequently, optimize for the fast case as a
514
- // condition of the mere existence of blocks. Note that the value of edited
515
- // content takes precedent over block content, and must fall through to the
516
- // default logic.
517
- const blocks = getEditorBlocks( state );
502
+ export const isEditedPostEmpty = createRegistrySelector(
503
+ ( select ) => ( state ) => {
504
+ // While the condition of truthy content string is sufficient to determine
505
+ // emptiness, testing saveable blocks length is a trivial operation. Since
506
+ // this function can be called frequently, optimize for the fast case as a
507
+ // condition of the mere existence of blocks. Note that the value of edited
508
+ // content takes precedent over block content, and must fall through to the
509
+ // default logic.
510
+ const postId = getCurrentPostId( state );
511
+ const postType = getCurrentPostType( state );
512
+ const record = select( coreStore ).getEditedEntityRecord(
513
+ 'postType',
514
+ postType,
515
+ postId
516
+ );
517
+ if ( typeof record.content !== 'function' ) {
518
+ return ! record.content;
519
+ }
520
+
521
+ const blocks = getEditedPostAttribute( state, 'blocks' );
522
+
523
+ if ( blocks.length === 0 ) {
524
+ return true;
525
+ }
518
526
 
519
- if ( blocks.length ) {
520
527
  // Pierce the abstraction of the serializer in knowing that blocks are
521
528
  // joined with newlines such that even if every individual block
522
529
  // produces an empty save result, the serialized content is non-empty.
@@ -542,10 +549,10 @@ export function isEditedPostEmpty( state ) {
542
549
  ) {
543
550
  return false;
544
551
  }
545
- }
546
552
 
547
- return ! getEditedPostContent( state );
548
- }
553
+ return ! getEditedPostContent( state );
554
+ }
555
+ );
549
556
 
550
557
  /**
551
558
  * Returns true if the post can be autosaved, or false otherwise.
@@ -681,15 +688,9 @@ export function isDeletingPost( state ) {
681
688
  *
682
689
  * @return {boolean} Whether post is being saved.
683
690
  */
684
- export const isSavingPost = createRegistrySelector( ( select ) => ( state ) => {
685
- const postType = getCurrentPostType( state );
686
- const postId = getCurrentPostId( state );
687
- return select( coreStore ).isSavingEntityRecord(
688
- 'postType',
689
- postType,
690
- postId
691
- );
692
- } );
691
+ export function isSavingPost( state ) {
692
+ return !! state.saving.pending;
693
+ }
693
694
 
694
695
  /**
695
696
  * Returns true if non-post entities are currently being saved, or false otherwise.
@@ -760,10 +761,7 @@ export const didPostSaveRequestFail = createRegistrySelector(
760
761
  * @return {boolean} Whether the post is autosaving.
761
762
  */
762
763
  export function isAutosavingPost( state ) {
763
- if ( ! isSavingPost( state ) ) {
764
- return false;
765
- }
766
- return Boolean( state.saving.options?.isAutosave );
764
+ return isSavingPost( state ) && Boolean( state.saving.options?.isAutosave );
767
765
  }
768
766
 
769
767
  /**
@@ -774,10 +772,7 @@ export function isAutosavingPost( state ) {
774
772
  * @return {boolean} Whether the post is being previewed.
775
773
  */
776
774
  export function isPreviewingPost( state ) {
777
- if ( ! isSavingPost( state ) ) {
778
- return false;
779
- }
780
- return Boolean( state.saving.options?.isPreview );
775
+ return isSavingPost( state ) && Boolean( state.saving.options?.isPreview );
781
776
  }
782
777
 
783
778
  /**
@@ -1100,9 +1095,18 @@ export const isPublishSidebarEnabled = createRegistrySelector(
1100
1095
  * @param {Object} state
1101
1096
  * @return {Array} Block list.
1102
1097
  */
1103
- export function getEditorBlocks( state ) {
1104
- return getEditedPostAttribute( state, 'blocks' ) || EMPTY_ARRAY;
1105
- }
1098
+ export const getEditorBlocks = createSelector(
1099
+ ( state ) => {
1100
+ return (
1101
+ getEditedPostAttribute( state, 'blocks' ) ||
1102
+ parse( getEditedPostContent( state ) )
1103
+ );
1104
+ },
1105
+ ( state ) => [
1106
+ getEditedPostAttribute( state, 'blocks' ),
1107
+ getEditedPostContent( state ),
1108
+ ]
1109
+ );
1106
1110
 
1107
1111
  /**
1108
1112
  * A block selection object.
@@ -75,10 +75,6 @@ selectorNames.forEach( ( name ) => {
75
75
  };
76
76
  },
77
77
 
78
- isSavingEntityRecord() {
79
- return state.saving && state.saving.requesting;
80
- },
81
-
82
78
  getLastEntitySaveError() {
83
79
  const saving = state.saving;
84
80
  const successful = saving && saving.successful;
@@ -1254,7 +1250,7 @@ describe( 'selectors', () => {
1254
1250
  title: 'sassel',
1255
1251
  },
1256
1252
  saving: {
1257
- requesting: true,
1253
+ pending: true,
1258
1254
  },
1259
1255
  };
1260
1256
 
@@ -1320,7 +1316,9 @@ describe( 'selectors', () => {
1320
1316
  },
1321
1317
  ],
1322
1318
  },
1323
- edits: {},
1319
+ edits: {
1320
+ content: () => {},
1321
+ },
1324
1322
  },
1325
1323
  },
1326
1324
  initialEdits: {},
@@ -1403,9 +1401,8 @@ describe( 'selectors', () => {
1403
1401
  currentPost: {
1404
1402
  title: 'sassel',
1405
1403
  },
1406
- saving: {
1407
- requesting: true,
1408
- },
1404
+ postAutosavingLock: {},
1405
+ saving: {},
1409
1406
  getCurrentUser() {},
1410
1407
  hasFetchedAutosaves() {
1411
1408
  return false;
@@ -1434,9 +1431,8 @@ describe( 'selectors', () => {
1434
1431
  currentPost: {
1435
1432
  title: 'sassel',
1436
1433
  },
1437
- saving: {
1438
- requesting: true,
1439
- },
1434
+ postAutosavingLock: {},
1435
+ saving: {},
1440
1436
  getCurrentUser() {},
1441
1437
  hasFetchedAutosaves() {
1442
1438
  return true;
@@ -1597,14 +1593,13 @@ describe( 'selectors', () => {
1597
1593
  const state = {
1598
1594
  editor: {
1599
1595
  present: {
1600
- blocks: {
1601
- value: [],
1602
- },
1603
1596
  edits: {},
1604
1597
  },
1605
1598
  },
1606
1599
  initialEdits: {},
1607
- currentPost: {},
1600
+ currentPost: {
1601
+ content: '',
1602
+ },
1608
1603
  };
1609
1604
 
1610
1605
  expect( isEditedPostEmpty( state ) ).toBe( true );
@@ -1626,7 +1621,9 @@ describe( 'selectors', () => {
1626
1621
  },
1627
1622
  ],
1628
1623
  },
1629
- edits: {},
1624
+ edits: {
1625
+ content: () => {},
1626
+ },
1630
1627
  },
1631
1628
  },
1632
1629
  initialEdits: {},
@@ -1656,7 +1653,9 @@ describe( 'selectors', () => {
1656
1653
  },
1657
1654
  ],
1658
1655
  },
1659
- edits: {},
1656
+ edits: {
1657
+ content: () => {},
1658
+ },
1660
1659
  },
1661
1660
  },
1662
1661
  initialEdits: {},
@@ -1666,7 +1665,7 @@ describe( 'selectors', () => {
1666
1665
  expect( isEditedPostEmpty( state ) ).toBe( true );
1667
1666
  } );
1668
1667
 
1669
- it( 'should return false if blocks, but empty content edit', () => {
1668
+ it( 'should return true if blocks, but empty content edit', () => {
1670
1669
  const state = {
1671
1670
  editor: {
1672
1671
  present: {
@@ -1693,7 +1692,7 @@ describe( 'selectors', () => {
1693
1692
  },
1694
1693
  };
1695
1694
 
1696
- expect( isEditedPostEmpty( state ) ).toBe( false );
1695
+ expect( isEditedPostEmpty( state ) ).toBe( true );
1697
1696
  } );
1698
1697
 
1699
1698
  it( 'should return true if the post has an empty content property', () => {
@@ -1715,7 +1714,7 @@ describe( 'selectors', () => {
1715
1714
  expect( isEditedPostEmpty( state ) ).toBe( true );
1716
1715
  } );
1717
1716
 
1718
- it( 'should return true if edits include a non-empty content property, but blocks are empty', () => {
1717
+ it( 'should return false if edits include a non-empty content property', () => {
1719
1718
  const state = {
1720
1719
  editor: {
1721
1720
  present: {
@@ -1731,7 +1730,7 @@ describe( 'selectors', () => {
1731
1730
  currentPost: {},
1732
1731
  };
1733
1732
 
1734
- expect( isEditedPostEmpty( state ) ).toBe( true );
1733
+ expect( isEditedPostEmpty( state ) ).toBe( false );
1735
1734
  } );
1736
1735
 
1737
1736
  it( 'should return true if empty classic block', () => {
@@ -1750,7 +1749,9 @@ describe( 'selectors', () => {
1750
1749
  },
1751
1750
  ],
1752
1751
  },
1753
- edits: {},
1752
+ edits: {
1753
+ content: () => {},
1754
+ },
1754
1755
  },
1755
1756
  },
1756
1757
  initialEdits: {},
@@ -2017,7 +2018,7 @@ describe( 'selectors', () => {
2017
2018
  it( 'should return true if the post is currently being saved', () => {
2018
2019
  const state = {
2019
2020
  saving: {
2020
- requesting: true,
2021
+ pending: true,
2021
2022
  },
2022
2023
  };
2023
2024
 
@@ -2027,7 +2028,7 @@ describe( 'selectors', () => {
2027
2028
  it( 'should return false if the post is not currently being saved', () => {
2028
2029
  const state = {
2029
2030
  saving: {
2030
- requesting: false,
2031
+ pending: false,
2031
2032
  },
2032
2033
  };
2033
2034
 
@@ -2156,6 +2157,7 @@ describe( 'selectors', () => {
2156
2157
  attributes: {
2157
2158
  providerNameSlug: 'instagram',
2158
2159
  },
2160
+ innerBlocks: [],
2159
2161
  },
2160
2162
  ],
2161
2163
  },
@@ -2178,6 +2180,7 @@ describe( 'selectors', () => {
2178
2180
  clientId: 567,
2179
2181
  name: 'core/embed',
2180
2182
  attributes: {},
2183
+ innerBlocks: [],
2181
2184
  },
2182
2185
  ],
2183
2186
  },
@@ -2200,11 +2203,13 @@ describe( 'selectors', () => {
2200
2203
  clientId: 123,
2201
2204
  name: 'core/image',
2202
2205
  attributes: {},
2206
+ innerBlocks: [],
2203
2207
  },
2204
2208
  {
2205
2209
  clientId: 456,
2206
2210
  name: 'core/quote',
2207
2211
  attributes: {},
2212
+ innerBlocks: [],
2208
2213
  },
2209
2214
  ],
2210
2215
  },
@@ -2228,6 +2233,7 @@ describe( 'selectors', () => {
2228
2233
  clientId: 123,
2229
2234
  name: 'core/image',
2230
2235
  attributes: {},
2236
+ innerBlocks: [],
2231
2237
  },
2232
2238
  ],
2233
2239
  },
@@ -2251,6 +2257,7 @@ describe( 'selectors', () => {
2251
2257
  clientId: 456,
2252
2258
  name: 'core/quote',
2253
2259
  attributes: {},
2260
+ innerBlocks: [],
2254
2261
  },
2255
2262
  ],
2256
2263
  },
@@ -2276,6 +2283,7 @@ describe( 'selectors', () => {
2276
2283
  attributes: {
2277
2284
  providerNameSlug: 'youtube',
2278
2285
  },
2286
+ innerBlocks: [],
2279
2287
  },
2280
2288
  ],
2281
2289
  },
@@ -2301,6 +2309,7 @@ describe( 'selectors', () => {
2301
2309
  attributes: {
2302
2310
  providerNameSlug: 'soundcloud',
2303
2311
  },
2312
+ innerBlocks: [],
2304
2313
  },
2305
2314
  ],
2306
2315
  },
@@ -2324,11 +2333,13 @@ describe( 'selectors', () => {
2324
2333
  clientId: 456,
2325
2334
  name: 'core/quote',
2326
2335
  attributes: {},
2336
+ innerBlocks: [],
2327
2337
  },
2328
2338
  {
2329
2339
  clientId: 789,
2330
2340
  name: 'core/paragraph',
2331
2341
  attributes: {},
2342
+ innerBlocks: [],
2332
2343
  },
2333
2344
  ],
2334
2345
  },
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/global-keyboard-shortcuts/save-shortcut.js"],"names":["SaveShortcut","resetBlocksOnSave","resetEditorBlocks","savePost","editorStore","isEditedPostDirty","getPostEdits","isPostSavingLocked","event","preventDefault","postEdits","content","blocks"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,SAASA,YAAT,CAAuB;AAAEC,EAAAA;AAAF,CAAvB,EAA+C;AAC9C,QAAM;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAAkC,uBAAaC,YAAb,CAAxC;AACA,QAAM;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA,YAArB;AAAmCC,IAAAA;AAAnC,MACL,qBAAWH,YAAX,CADD;AAGA,sCAAa,kBAAb,EAAmCI,KAAF,IAAa;AAC7CA,IAAAA,KAAK,CAACC,cAAN;AAEA;AACF;AACA;;AACE,QAAKF,kBAAkB,EAAvB,EAA4B;AAC3B;AACA,KAR4C,CAU7C;AACA;AACA;AACA;AACA;;;AACA,QAAK,CAAEF,iBAAiB,EAAxB,EAA6B;AAC5B;AACA,KAjB4C,CAmB7C;AACA;AACA;AACA;;;AACA,QAAKJ,iBAAL,EAAyB;AACxB,YAAMS,SAAS,GAAGJ,YAAY,EAA9B;;AACA,UAAKI,SAAS,CAACC,OAAV,IAAqB,OAAOD,SAAS,CAACC,OAAjB,KAA6B,QAAvD,EAAkE;AACjE,cAAMC,MAAM,GAAG,mBAAOF,SAAS,CAACC,OAAjB,CAAf;AACAT,QAAAA,iBAAiB,CAAEU,MAAF,CAAjB;AACA;AACD;;AAEDT,IAAAA,QAAQ;AACR,GAhCD;AAkCA,SAAO,IAAP;AACA;;eAEcH,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nfunction SaveShortcut( { resetBlocksOnSave } ) {\n\tconst { resetEditorBlocks, savePost } = useDispatch( editorStore );\n\tconst { isEditedPostDirty, getPostEdits, isPostSavingLocked } =\n\t\tuseSelect( editorStore );\n\n\tuseShortcut( 'core/editor/save', ( event ) => {\n\t\tevent.preventDefault();\n\n\t\t/**\n\t\t * Do not save the post if post saving is locked.\n\t\t */\n\t\tif ( isPostSavingLocked() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// TODO: This should be handled in the `savePost` effect in\n\t\t// considering `isSaveable`. See note on `isEditedPostSaveable`\n\t\t// selector about dirtiness and meta-boxes.\n\t\t//\n\t\t// See: `isEditedPostSaveable`\n\t\tif ( ! isEditedPostDirty() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The text editor requires that editor blocks are updated for a\n\t\t// save to work correctly. Usually this happens when the textarea\n\t\t// for the code editors blurs, but the shortcut can be used without\n\t\t// blurring the textarea.\n\t\tif ( resetBlocksOnSave ) {\n\t\t\tconst postEdits = getPostEdits();\n\t\t\tif ( postEdits.content && typeof postEdits.content === 'string' ) {\n\t\t\t\tconst blocks = parse( postEdits.content );\n\t\t\t\tresetEditorBlocks( blocks );\n\t\t\t}\n\t\t}\n\n\t\tsavePost();\n\t} );\n\n\treturn null;\n}\n\nexport default SaveShortcut;\n"]}
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = TextEditorGlobalKeyboardShortcuts;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _saveShortcut = _interopRequireDefault(require("./save-shortcut"));
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- function TextEditorGlobalKeyboardShortcuts() {
18
- return (0, _element.createElement)(_saveShortcut.default, {
19
- resetBlocksOnSave: true
20
- });
21
- }
22
- //# sourceMappingURL=text-editor-shortcuts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/global-keyboard-shortcuts/text-editor-shortcuts.js"],"names":["TextEditorGlobalKeyboardShortcuts"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,iCAAT,GAA6C;AAC3D,SAAO,4BAAC,qBAAD;AAAc,IAAA,iBAAiB;AAA/B,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SaveShortcut from './save-shortcut';\n\nexport default function TextEditorGlobalKeyboardShortcuts() {\n\treturn <SaveShortcut resetBlocksOnSave />;\n}\n"]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
13
-
14
- var _data = require("@wordpress/data");
15
-
16
- var _saveShortcut = _interopRequireDefault(require("./save-shortcut"));
17
-
18
- var _store = require("../../store");
19
-
20
- /**
21
- * WordPress dependencies
22
- */
23
-
24
- /**
25
- * Internal dependencies
26
- */
27
- function VisualEditorGlobalKeyboardShortcuts() {
28
- const {
29
- redo,
30
- undo
31
- } = (0, _data.useDispatch)(_store.store);
32
- (0, _keyboardShortcuts.useShortcut)('core/editor/undo', event => {
33
- undo();
34
- event.preventDefault();
35
- });
36
- (0, _keyboardShortcuts.useShortcut)('core/editor/redo', event => {
37
- redo();
38
- event.preventDefault();
39
- });
40
- return (0, _element.createElement)(_saveShortcut.default, null);
41
- }
42
-
43
- var _default = VisualEditorGlobalKeyboardShortcuts;
44
- exports.default = _default;
45
- //# sourceMappingURL=visual-editor-shortcuts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/global-keyboard-shortcuts/visual-editor-shortcuts.js"],"names":["VisualEditorGlobalKeyboardShortcuts","redo","undo","editorStore","event","preventDefault"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIA,SAASA,mCAAT,GAA+C;AAC9C,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiB,uBAAaC,YAAb,CAAvB;AAEA,sCAAa,kBAAb,EAAmCC,KAAF,IAAa;AAC7CF,IAAAA,IAAI;AACJE,IAAAA,KAAK,CAACC,cAAN;AACA,GAHD;AAKA,sCAAa,kBAAb,EAAmCD,KAAF,IAAa;AAC7CH,IAAAA,IAAI;AACJG,IAAAA,KAAK,CAACC,cAAN;AACA,GAHD;AAKA,SAAO,4BAAC,qBAAD,OAAP;AACA;;eAEcL,mC","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport SaveShortcut from './save-shortcut';\nimport { store as editorStore } from '../../store';\n\nfunction VisualEditorGlobalKeyboardShortcuts() {\n\tconst { redo, undo } = useDispatch( editorStore );\n\n\tuseShortcut( 'core/editor/undo', ( event ) => {\n\t\tundo();\n\t\tevent.preventDefault();\n\t} );\n\n\tuseShortcut( 'core/editor/redo', ( event ) => {\n\t\tredo();\n\t\tevent.preventDefault();\n\t} );\n\n\treturn <SaveShortcut />;\n}\n\nexport default VisualEditorGlobalKeyboardShortcuts;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/global-keyboard-shortcuts/save-shortcut.js"],"names":["useShortcut","useDispatch","useSelect","parse","store","editorStore","SaveShortcut","resetBlocksOnSave","resetEditorBlocks","savePost","isEditedPostDirty","getPostEdits","isPostSavingLocked","event","preventDefault","postEdits","content","blocks"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,+BAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,KAAT,QAAsB,mBAAtB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,aAArC;;AAEA,SAASC,YAAT,CAAuB;AAAEC,EAAAA;AAAF,CAAvB,EAA+C;AAC9C,QAAM;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAAkCR,WAAW,CAAEI,WAAF,CAAnD;AACA,QAAM;AAAEK,IAAAA,iBAAF;AAAqBC,IAAAA,YAArB;AAAmCC,IAAAA;AAAnC,MACLV,SAAS,CAAEG,WAAF,CADV;AAGAL,EAAAA,WAAW,CAAE,kBAAF,EAAwBa,KAAF,IAAa;AAC7CA,IAAAA,KAAK,CAACC,cAAN;AAEA;AACF;AACA;;AACE,QAAKF,kBAAkB,EAAvB,EAA4B;AAC3B;AACA,KAR4C,CAU7C;AACA;AACA;AACA;AACA;;;AACA,QAAK,CAAEF,iBAAiB,EAAxB,EAA6B;AAC5B;AACA,KAjB4C,CAmB7C;AACA;AACA;AACA;;;AACA,QAAKH,iBAAL,EAAyB;AACxB,YAAMQ,SAAS,GAAGJ,YAAY,EAA9B;;AACA,UAAKI,SAAS,CAACC,OAAV,IAAqB,OAAOD,SAAS,CAACC,OAAjB,KAA6B,QAAvD,EAAkE;AACjE,cAAMC,MAAM,GAAGd,KAAK,CAAEY,SAAS,CAACC,OAAZ,CAApB;AACAR,QAAAA,iBAAiB,CAAES,MAAF,CAAjB;AACA;AACD;;AAEDR,IAAAA,QAAQ;AACR,GAhCU,CAAX;AAkCA,SAAO,IAAP;AACA;;AAED,eAAeH,YAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nfunction SaveShortcut( { resetBlocksOnSave } ) {\n\tconst { resetEditorBlocks, savePost } = useDispatch( editorStore );\n\tconst { isEditedPostDirty, getPostEdits, isPostSavingLocked } =\n\t\tuseSelect( editorStore );\n\n\tuseShortcut( 'core/editor/save', ( event ) => {\n\t\tevent.preventDefault();\n\n\t\t/**\n\t\t * Do not save the post if post saving is locked.\n\t\t */\n\t\tif ( isPostSavingLocked() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// TODO: This should be handled in the `savePost` effect in\n\t\t// considering `isSaveable`. See note on `isEditedPostSaveable`\n\t\t// selector about dirtiness and meta-boxes.\n\t\t//\n\t\t// See: `isEditedPostSaveable`\n\t\tif ( ! isEditedPostDirty() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The text editor requires that editor blocks are updated for a\n\t\t// save to work correctly. Usually this happens when the textarea\n\t\t// for the code editors blurs, but the shortcut can be used without\n\t\t// blurring the textarea.\n\t\tif ( resetBlocksOnSave ) {\n\t\t\tconst postEdits = getPostEdits();\n\t\t\tif ( postEdits.content && typeof postEdits.content === 'string' ) {\n\t\t\t\tconst blocks = parse( postEdits.content );\n\t\t\t\tresetEditorBlocks( blocks );\n\t\t\t}\n\t\t}\n\n\t\tsavePost();\n\t} );\n\n\treturn null;\n}\n\nexport default SaveShortcut;\n"]}
@@ -1,12 +0,0 @@
1
- import { createElement } from "@wordpress/element";
2
-
3
- /**
4
- * Internal dependencies
5
- */
6
- import SaveShortcut from './save-shortcut';
7
- export default function TextEditorGlobalKeyboardShortcuts() {
8
- return createElement(SaveShortcut, {
9
- resetBlocksOnSave: true
10
- });
11
- }
12
- //# sourceMappingURL=text-editor-shortcuts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/global-keyboard-shortcuts/text-editor-shortcuts.js"],"names":["SaveShortcut","TextEditorGlobalKeyboardShortcuts"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,YAAP,MAAyB,iBAAzB;AAEA,eAAe,SAASC,iCAAT,GAA6C;AAC3D,SAAO,cAAC,YAAD;AAAc,IAAA,iBAAiB;AAA/B,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SaveShortcut from './save-shortcut';\n\nexport default function TextEditorGlobalKeyboardShortcuts() {\n\treturn <SaveShortcut resetBlocksOnSave />;\n}\n"]}