@wordpress/editor 13.14.0 → 13.16.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 (125) hide show
  1. package/CHANGELOG.md +4 -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-comments/index.js +12 -15
  13. package/build/components/post-comments/index.js.map +1 -1
  14. package/build/components/post-excerpt/index.js +9 -20
  15. package/build/components/post-excerpt/index.js.map +1 -1
  16. package/build/components/post-pingbacks/index.js +12 -15
  17. package/build/components/post-pingbacks/index.js.map +1 -1
  18. package/build/components/post-preview-button/index.js +62 -157
  19. package/build/components/post-preview-button/index.js.map +1 -1
  20. package/build/components/post-publish-button/index.js +4 -9
  21. package/build/components/post-publish-button/index.js.map +1 -1
  22. package/build/components/post-publish-button/label.js +2 -4
  23. package/build/components/post-publish-button/label.js.map +1 -1
  24. package/build/components/post-publish-panel/index.js +1 -3
  25. package/build/components/post-publish-panel/index.js.map +1 -1
  26. package/build/components/post-saved-state/index.js +2 -5
  27. package/build/components/post-saved-state/index.js.map +1 -1
  28. package/build/components/post-schedule/label.js +4 -4
  29. package/build/components/post-schedule/label.js.map +1 -1
  30. package/build/components/post-sync-status/index.js +84 -5
  31. package/build/components/post-sync-status/index.js.map +1 -1
  32. package/build/components/post-text-editor/index.js +51 -58
  33. package/build/components/post-text-editor/index.js.map +1 -1
  34. package/build/components/post-type-support-check/index.js +10 -14
  35. package/build/components/post-type-support-check/index.js.map +1 -1
  36. package/build/hooks/custom-sources-backwards-compatibility.js +1 -24
  37. package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
  38. package/build/store/actions.js +37 -3
  39. package/build/store/actions.js.map +1 -1
  40. package/build/store/selectors.js +55 -63
  41. package/build/store/selectors.js.map +1 -1
  42. package/build-module/components/entities-saved-states/entity-record-item.js +6 -40
  43. package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
  44. package/build-module/components/entities-saved-states/entity-type-list.js +2 -4
  45. package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
  46. package/build-module/components/entities-saved-states/index.js +0 -1
  47. package/build-module/components/entities-saved-states/index.js.map +1 -1
  48. package/build-module/components/global-keyboard-shortcuts/{save-shortcut.js → index.js} +12 -23
  49. package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -0
  50. package/build-module/components/index.js +9 -4
  51. package/build-module/components/index.js.map +1 -1
  52. package/build-module/components/post-comments/index.js +13 -14
  53. package/build-module/components/post-comments/index.js.map +1 -1
  54. package/build-module/components/post-excerpt/index.js +10 -19
  55. package/build-module/components/post-excerpt/index.js.map +1 -1
  56. package/build-module/components/post-pingbacks/index.js +13 -14
  57. package/build-module/components/post-pingbacks/index.js.map +1 -1
  58. package/build-module/components/post-preview-button/index.js +63 -149
  59. package/build-module/components/post-preview-button/index.js.map +1 -1
  60. package/build-module/components/post-publish-button/index.js +4 -9
  61. package/build-module/components/post-publish-button/index.js.map +1 -1
  62. package/build-module/components/post-publish-button/label.js +2 -4
  63. package/build-module/components/post-publish-button/label.js.map +1 -1
  64. package/build-module/components/post-publish-panel/index.js +1 -3
  65. package/build-module/components/post-publish-panel/index.js.map +1 -1
  66. package/build-module/components/post-saved-state/index.js +2 -5
  67. package/build-module/components/post-saved-state/index.js.map +1 -1
  68. package/build-module/components/post-schedule/label.js +4 -4
  69. package/build-module/components/post-schedule/label.js.map +1 -1
  70. package/build-module/components/post-sync-status/index.js +84 -8
  71. package/build-module/components/post-sync-status/index.js.map +1 -1
  72. package/build-module/components/post-text-editor/index.js +48 -56
  73. package/build-module/components/post-text-editor/index.js.map +1 -1
  74. package/build-module/components/post-type-support-check/index.js +11 -14
  75. package/build-module/components/post-type-support-check/index.js.map +1 -1
  76. package/build-module/hooks/custom-sources-backwards-compatibility.js +2 -24
  77. package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
  78. package/build-module/store/actions.js +31 -1
  79. package/build-module/store/actions.js.map +1 -1
  80. package/build-module/store/selectors.js +48 -57
  81. package/build-module/store/selectors.js.map +1 -1
  82. package/build-style/style-rtl.css +0 -18
  83. package/build-style/style.css +0 -18
  84. package/package.json +30 -30
  85. package/src/components/entities-saved-states/entity-record-item.js +3 -61
  86. package/src/components/entities-saved-states/entity-type-list.js +0 -2
  87. package/src/components/entities-saved-states/index.js +0 -1
  88. package/src/components/entities-saved-states/style.scss +0 -15
  89. package/src/components/global-keyboard-shortcuts/index.js +49 -0
  90. package/src/components/index.js +12 -3
  91. package/src/components/post-author/test/check.js +18 -12
  92. package/src/components/post-comments/index.js +11 -17
  93. package/src/components/post-excerpt/index.js +10 -16
  94. package/src/components/post-pingbacks/index.js +11 -15
  95. package/src/components/post-preview-button/index.js +73 -156
  96. package/src/components/post-preview-button/test/index.js +94 -158
  97. package/src/components/post-publish-button/index.js +2 -7
  98. package/src/components/post-publish-button/label.js +2 -2
  99. package/src/components/post-publish-button/test/index.js +0 -10
  100. package/src/components/post-publish-panel/index.js +1 -3
  101. package/src/components/post-saved-state/index.js +2 -5
  102. package/src/components/post-schedule/label.js +4 -4
  103. package/src/components/post-sync-status/index.js +100 -7
  104. package/src/components/post-text-editor/index.js +34 -57
  105. package/src/components/post-title/style.native.scss +5 -5
  106. package/src/components/post-type-support-check/index.js +8 -10
  107. package/src/components/post-type-support-check/test/index.js +35 -19
  108. package/src/hooks/custom-sources-backwards-compatibility.js +1 -25
  109. package/src/store/actions.js +34 -2
  110. package/src/store/selectors.js +47 -43
  111. package/src/store/test/selectors.js +49 -38
  112. package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +0 -1
  113. package/build/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -22
  114. package/build/components/global-keyboard-shortcuts/text-editor-shortcuts.js.map +0 -1
  115. package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -45
  116. package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +0 -1
  117. package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +0 -1
  118. package/build-module/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -12
  119. package/build-module/components/global-keyboard-shortcuts/text-editor-shortcuts.js.map +0 -1
  120. package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -32
  121. package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +0 -1
  122. package/src/components/global-keyboard-shortcuts/save-shortcut.js +0 -55
  123. package/src/components/global-keyboard-shortcuts/text-editor-shortcuts.js +0 -8
  124. package/src/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -29
  125. package/src/components/post-text-editor/test/index.js +0 -156
@@ -44,14 +44,11 @@ var _store = require("../../store");
44
44
  * @param {Object} props Component props.
45
45
  * @param {?boolean} props.forceIsDirty Whether to force the post to be marked
46
46
  * as dirty.
47
- * @param {?boolean} props.forceIsSaving Whether to force the post to be marked
48
- * as being saved.
49
47
  * @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons
50
48
  * @return {import('@wordpress/element').WPComponent} The component.
51
49
  */
52
50
  function PostSavedState({
53
51
  forceIsDirty,
54
- forceIsSaving,
55
52
  showIconLabels = false
56
53
  }) {
57
54
  const [forceSavedMessage, setForceSavedMessage] = (0, _element.useState)(false);
@@ -86,12 +83,12 @@ function PostSavedState({
86
83
  isNew: isEditedPostNew(),
87
84
  isPending: 'pending' === getEditedPostAttribute('status'),
88
85
  isPublished: isCurrentPostPublished(),
89
- isSaving: forceIsSaving || isSavingPost(),
86
+ isSaving: isSavingPost(),
90
87
  isSaveable: isEditedPostSaveable(),
91
88
  isScheduled: isCurrentPostScheduled(),
92
89
  hasPublishAction: (_getCurrentPost$_link = getCurrentPost()?._links?.['wp:action-publish']) !== null && _getCurrentPost$_link !== void 0 ? _getCurrentPost$_link : false
93
90
  };
94
- }, [forceIsDirty, forceIsSaving]);
91
+ }, [forceIsDirty]);
95
92
  const {
96
93
  savePost
97
94
  } = (0, _data.useDispatch)(_store.store);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-saved-state/index.js"],"names":["PostSavedState","forceIsDirty","forceIsSaving","showIconLabels","forceSavedMessage","setForceSavedMessage","isLargeViewport","isAutosaving","isDirty","isNew","isPending","isPublished","isSaveable","isSaving","isScheduled","hasPublishAction","select","isEditedPostNew","isCurrentPostPublished","isCurrentPostScheduled","isEditedPostDirty","isSavingPost","isEditedPostSaveable","getCurrentPost","isAutosavingPost","getEditedPostAttribute","editorStore","_links","savePost","wasSaving","timeoutId","setTimeout","clearTimeout","label","shortLabel","isSaved","isSavedState","isDisabled","text","type","undefined","displayShortcut","primary","cloudUpload","check","cloud"],"mappings":";;;;;;;;;AAcA;;AAXA;;AAKA;;AAIA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AAtBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAyB;AACvCC,EAAAA,YADuC;AAEvCC,EAAAA,aAFuC;AAGvCC,EAAAA,cAAc,GAAG;AAHsB,CAAzB,EAIX;AACH,QAAM,CAAEC,iBAAF,EAAqBC,oBAArB,IAA8C,uBAAU,KAAV,CAApD;AACA,QAAMC,eAAe,GAAG,+BAAkB,OAAlB,CAAxB;AAEA,QAAM;AACLC,IAAAA,YADK;AAELC,IAAAA,OAFK;AAGLC,IAAAA,KAHK;AAILC,IAAAA,SAJK;AAKLC,IAAAA,WALK;AAMLC,IAAA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AADgB,OAArB,CAAF,GAEO1B;AARK,KAAZ,CADH,GAWG2B,SAbL;AAeC,IAAA,OAAO,EAAGH,UAAU,GAAGG,SAAH,GAAe,MAAMZ,QAAQ;AACjD;AACH;AACA;AACA;AAnBE;AAoBC,IAAA,QAAQ,EAAGS,UAAU,GAAGG,SAAH,GAAeC,0BAAgBC,OAAhB,CAAyB,GAAzB;AACpC;AACH;AACA;AACA;AACA;AACA;AA1BE;AA2BC,IAAA,WAAW,MA3BZ;AA4BC,IAAA,OAAO,EAAC,UA5BT;AA6BC,IAAA,IAAI,EAAGpC,eAAe,GAAGkC,SAAH,GAAeG,kBA7BtC,CA8BC;AA9BD;AA+BC,IAAA,KAAK,EAAGL,IAAI,IAAIL,KA/BjB;AAgCC,qBAAgBI;AAhCjB,KAkCGD,YAAY,IAAI,4BAAC,WAAD;AAAM,IAAA,IAAI,EAAGD,OAAO,GAAGS,YAAH,GAAWC;AAA/B,IAlCnB,EAmCGP,IAnCH,CADD;AAuCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__unstableGetAnimateClassName as getAnimateClassName,\n\tButton,\n} from '@wordpress/components';\nimport { usePrevious, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, check, cloud, cloudUpload } from '@wordpress/icons';\nimport { displayShortcut } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\n/**\n * Component showing whether the post is saved or not and providing save\n * buttons.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.forceIsDirty Whether to force the post to be marked\n * as dirty.\n * @param {?boolean} props.forceIsSaving Whether to force the post to be marked\n * as being saved.\n * @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons\n * @return {import('@wordpress/element').WPComponent} The component.\n */\nexport default function PostSavedState( {\n\tforceIsDirty,\n\tforceIsSaving,\n\tshowIconLabels = false,\n} ) {\n\tconst [ forceSavedMessage, setForceSavedMessage ] = useState( false );\n\tconst isLargeViewport = useViewportMatch( 'small' );\n\n\tconst {\n\t\tisAutosaving,\n\t\tisDirty,\n\t\tisNew,\n\t\tisPending,\n\t\tisPublished,\n\t\tisSaveable,\n\t\tisSaving,\n\t\tisScheduled,\n\t\thasPublishAction,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tisEditedPostNew,\n\t\t\t\tisCurrentPostPublished,\n\t\t\t\tisCurrentPostScheduled,\n\t\t\t\tisEditedPostDirty,\n\t\t\t\tisSavingPost,\n\t\t\t\tisEditedPostSaveable,\n\t\t\t\tgetCurrentPost,\n\t\t\t\tisAutosavingPost,\n\t\t\t\tgetEditedPostAttribute,\n\t\t\t} = select( editorStore );\n\n\t\t\treturn {\n\t\t\t\tisAutosaving: isAutosavingPost(),\n\t\t\t\tisDirty: forceIsDirty || isEditedPostDirty(),\n\t\t\t\tisNew: isEditedPostNew(),\n\t\t\t\tisPending: 'pending' === getEditedPostAttribute( 'status' ),\n\t\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\t\tisSaving: forceIsSaving || isSavingPost(),\n\t\t\t\tisSaveable: isEditedPostSaveable(),\n\t\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t\t\thasPublishAction:\n\t\t\t\t\tgetCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false,\n\t\t\t};\n\t\t},\n\t\t[ forceIsDirty, forceIsSaving ]\n\t);\n\n\tconst { savePost } = useDispatch( editorStore );\n\n\tconst wasSaving = usePrevious( isSaving );\n\n\tuseEffect( () => {\n\t\tlet timeoutId;\n\n\t\tif ( wasSaving && ! isSaving ) {\n\t\t\tsetForceSavedMessage( true );\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tsetForceSavedMessage( false );\n\t\t\t}, 1000 );\n\t\t}\n\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ isSaving ] );\n\n\t// Once the post has been submitted for review this button\n\t// is not needed for the contributor role.\n\tif ( ! hasPublishAction && isPending ) {\n\t\treturn null;\n\t}\n\n\tif ( isPublished || isScheduled ) {\n\t\treturn null;\n\t}\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst label = isPending ? __( 'Save as pending' ) : __( 'Save draft' );\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst shortLabel = __( 'Save' );\n\n\tconst isSaved = forceSavedMessage || ( ! isNew && ! isDirty );\n\tconst isSavedState = isSaving || isSaved;\n\tconst isDisabled = isSaving || isSaved || ! isSaveable;\n\n\tlet text;\n\n\tif ( isSaving ) {\n\t\ttext = isAutosaving ? __( 'Autosaving' ) : __( 'Saving' );\n\t} else if ( isSaved ) {\n\t\ttext = __( 'Saved' );\n\t} else if ( isLargeViewport ) {\n\t\ttext = label;\n\t} else if ( showIconLabels ) {\n\t\ttext = shortLabel;\n\t}\n\n\t// Use common Button instance for all saved states so that focus is not\n\t// lost.\n\treturn (\n\t\t<Button\n\t\t\tclassName={\n\t\t\t\tisSaveable || isSaving\n\t\t\t\t\t? classnames( {\n\t\t\t\t\t\t\t'editor-post-save-draft': ! isSavedState,\n\t\t\t\t\t\t\t'editor-post-saved-state': isSavedState,\n\t\t\t\t\t\t\t'is-saving': isSaving,\n\t\t\t\t\t\t\t'is-autosaving': isAutosaving,\n\t\t\t\t\t\t\t'is-saved': isSaved,\n\t\t\t\t\t\t\t[ getAnimateClassName( {\n\t\t\t\t\t\t\t\ttype: 'loading',\n\t\t\t\t\t\t\t} ) ]: isSaving,\n\t\t\t\t\t } )\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tonClick={ isDisabled ? undefined : () => savePost() }\n\t\t\t/*\n\t\t\t * We want the tooltip to show the keyboard shortcut only when the\n\t\t\t * button does something, i.e. when it's not disabled.\n\t\t\t */\n\t\t\tshortcut={ isDisabled ? undefined : displayShortcut.primary( 's' ) }\n\t\t\t/*\n\t\t\t * Displaying the keyboard shortcut conditionally makes the tooltip\n\t\t\t * itself show conditionally. This would trigger a full-rerendering\n\t\t\t * of the button that we want to avoid. By setting `showTooltip`,\n\t\t\t & the tooltip is always rendered even when there's no keyboard shortcut.\n\t\t\t */\n\t\t\tshowTooltip\n\t\t\tvariant=\"tertiary\"\n\t\t\ticon={ isLargeViewport ? undefined : cloudUpload }\n\t\t\t// Make sure the aria-label has always a value, as the default `text` is undefined on small screens.\n\t\t\tlabel={ text || label }\n\t\t\taria-disabled={ isDisabled }\n\t\t>\n\t\t\t{ isSavedState && <Icon icon={ isSaved ? check : cloud } /> }\n\t\t\t{ text }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-saved-state/index.js"],"names":["PostSavedState","forceIsDirty","showIconLabels","forceSavedMessage","setForceSavedMessage","isLargeViewport","isAutosaving","isDirty","isNew","isPending","isPublished","isSaveable","isSaving","isScheduled","hasPublishAction","select","isEditedPostNew","isCurrentPostPublished","isCurrentPostScheduled","isEditedPostDirty","isSavingPost","isEditedPostSaveable","getCurrentPost","isAutosavingPost","getEditedPostAttribute","editorStore","_links","savePost","wasSaving","timeoutId","setTimeout","clearTimeout","label","shortLabel","isSaved","isSavedState","isDisabled","text","type","undefined","displayShortcut","primary","cloudUpload","check","cloud"],"mappings":";;;;;;;;;AAcA;;AAXA;;AAKA;;AAIA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AAtBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAyB;AACvCC,EAAAA,YADuC;AAEvCC,EAAAA,cAAc,GAAG;AAFsB,CAAzB,EAGX;AACH,QAAM,CAAEC,iBAAF,EAAqBC,oBAArB,IAA8C,uBAAU,KAAV,CAApD;AACA,QAAMC,eAAe,GAAG,+BAAkB,OAAlB,CAAxB;AAEA,QAAM;AACLC,IAAAA,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AKZ,kBAAY4B,OALA;AAMZ,OAAE,+CAAqB;AACtBI,QAAAA,IAAI,EAAE;AADgB,OAArB,CAAF,GAEO1B;AARK,KAAZ,CADH,GAWG2B,SAbL;AAeC,IAAA,OAAO,EAAGH,UAAU,GAAGG,SAAH,GAAe,MAAMZ,QAAQ;AACjD;AACH;AACA;AACA;AAnBE;AAoBC,IAAA,QAAQ,EAAGS,UAAU,GAAGG,SAAH,GAAeC,0BAAgBC,OAAhB,CAAyB,GAAzB;AACpC;AACH;AACA;AACA;AACA;AACA;AA1BE;AA2BC,IAAA,WAAW,MA3BZ;AA4BC,IAAA,OAAO,EAAC,UA5BT;AA6BC,IAAA,IAAI,EAAGpC,eAAe,GAAGkC,SAAH,GAAeG,kBA7BtC,CA8BC;AA9BD;AA+BC,IAAA,KAAK,EAAGL,IAAI,IAAIL,KA/BjB;AAgCC,qBAAgBI;AAhCjB,KAkCGD,YAAY,IAAI,4BAAC,WAAD;AAAM,IAAA,IAAI,EAAGD,OAAO,GAAGS,YAAH,GAAWC;AAA/B,IAlCnB,EAmCGP,IAnCH,CADD;AAuCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__unstableGetAnimateClassName as getAnimateClassName,\n\tButton,\n} from '@wordpress/components';\nimport { usePrevious, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, check, cloud, cloudUpload } from '@wordpress/icons';\nimport { displayShortcut } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\n/**\n * Component showing whether the post is saved or not and providing save\n * buttons.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.forceIsDirty Whether to force the post to be marked\n * as dirty.\n * @param {?boolean} props.showIconLabels Whether interface buttons show labels instead of icons\n * @return {import('@wordpress/element').WPComponent} The component.\n */\nexport default function PostSavedState( {\n\tforceIsDirty,\n\tshowIconLabels = false,\n} ) {\n\tconst [ forceSavedMessage, setForceSavedMessage ] = useState( false );\n\tconst isLargeViewport = useViewportMatch( 'small' );\n\n\tconst {\n\t\tisAutosaving,\n\t\tisDirty,\n\t\tisNew,\n\t\tisPending,\n\t\tisPublished,\n\t\tisSaveable,\n\t\tisSaving,\n\t\tisScheduled,\n\t\thasPublishAction,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tisEditedPostNew,\n\t\t\t\tisCurrentPostPublished,\n\t\t\t\tisCurrentPostScheduled,\n\t\t\t\tisEditedPostDirty,\n\t\t\t\tisSavingPost,\n\t\t\t\tisEditedPostSaveable,\n\t\t\t\tgetCurrentPost,\n\t\t\t\tisAutosavingPost,\n\t\t\t\tgetEditedPostAttribute,\n\t\t\t} = select( editorStore );\n\n\t\t\treturn {\n\t\t\t\tisAutosaving: isAutosavingPost(),\n\t\t\t\tisDirty: forceIsDirty || isEditedPostDirty(),\n\t\t\t\tisNew: isEditedPostNew(),\n\t\t\t\tisPending: 'pending' === getEditedPostAttribute( 'status' ),\n\t\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\t\tisSaving: isSavingPost(),\n\t\t\t\tisSaveable: isEditedPostSaveable(),\n\t\t\t\tisScheduled: isCurrentPostScheduled(),\n\t\t\t\thasPublishAction:\n\t\t\t\t\tgetCurrentPost()?._links?.[ 'wp:action-publish' ] ?? false,\n\t\t\t};\n\t\t},\n\t\t[ forceIsDirty ]\n\t);\n\n\tconst { savePost } = useDispatch( editorStore );\n\n\tconst wasSaving = usePrevious( isSaving );\n\n\tuseEffect( () => {\n\t\tlet timeoutId;\n\n\t\tif ( wasSaving && ! isSaving ) {\n\t\t\tsetForceSavedMessage( true );\n\t\t\ttimeoutId = setTimeout( () => {\n\t\t\t\tsetForceSavedMessage( false );\n\t\t\t}, 1000 );\n\t\t}\n\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ isSaving ] );\n\n\t// Once the post has been submitted for review this button\n\t// is not needed for the contributor role.\n\tif ( ! hasPublishAction && isPending ) {\n\t\treturn null;\n\t}\n\n\tif ( isPublished || isScheduled ) {\n\t\treturn null;\n\t}\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst label = isPending ? __( 'Save as pending' ) : __( 'Save draft' );\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst shortLabel = __( 'Save' );\n\n\tconst isSaved = forceSavedMessage || ( ! isNew && ! isDirty );\n\tconst isSavedState = isSaving || isSaved;\n\tconst isDisabled = isSaving || isSaved || ! isSaveable;\n\n\tlet text;\n\n\tif ( isSaving ) {\n\t\ttext = isAutosaving ? __( 'Autosaving' ) : __( 'Saving' );\n\t} else if ( isSaved ) {\n\t\ttext = __( 'Saved' );\n\t} else if ( isLargeViewport ) {\n\t\ttext = label;\n\t} else if ( showIconLabels ) {\n\t\ttext = shortLabel;\n\t}\n\n\t// Use common Button instance for all saved states so that focus is not\n\t// lost.\n\treturn (\n\t\t<Button\n\t\t\tclassName={\n\t\t\t\tisSaveable || isSaving\n\t\t\t\t\t? classnames( {\n\t\t\t\t\t\t\t'editor-post-save-draft': ! isSavedState,\n\t\t\t\t\t\t\t'editor-post-saved-state': isSavedState,\n\t\t\t\t\t\t\t'is-saving': isSaving,\n\t\t\t\t\t\t\t'is-autosaving': isAutosaving,\n\t\t\t\t\t\t\t'is-saved': isSaved,\n\t\t\t\t\t\t\t[ getAnimateClassName( {\n\t\t\t\t\t\t\t\ttype: 'loading',\n\t\t\t\t\t\t\t} ) ]: isSaving,\n\t\t\t\t\t } )\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tonClick={ isDisabled ? undefined : () => savePost() }\n\t\t\t/*\n\t\t\t * We want the tooltip to show the keyboard shortcut only when the\n\t\t\t * button does something, i.e. when it's not disabled.\n\t\t\t */\n\t\t\tshortcut={ isDisabled ? undefined : displayShortcut.primary( 's' ) }\n\t\t\t/*\n\t\t\t * Displaying the keyboard shortcut conditionally makes the tooltip\n\t\t\t * itself show conditionally. This would trigger a full-rerendering\n\t\t\t * of the button that we want to avoid. By setting `showTooltip`,\n\t\t\t & the tooltip is always rendered even when there's no keyboard shortcut.\n\t\t\t */\n\t\t\tshowTooltip\n\t\t\tvariant=\"tertiary\"\n\t\t\ticon={ isLargeViewport ? undefined : cloudUpload }\n\t\t\t// Make sure the aria-label has always a value, as the default `text` is undefined on small screens.\n\t\t\tlabel={ text || label }\n\t\t\taria-disabled={ isDisabled }\n\t\t>\n\t\t\t{ isSavedState && <Icon icon={ isSaved ? check : cloud } /> }\n\t\t\t{ text }\n\t\t</Button>\n\t);\n}\n"]}
@@ -45,7 +45,7 @@ function usePostScheduleLabel({
45
45
  function getFullPostScheduleLabel(dateAttribute) {
46
46
  const date = (0, _date.getDate)(dateAttribute);
47
47
  const timezoneAbbreviation = getTimezoneAbbreviation();
48
- const formattedDate = (0, _date.dateI18n)( // translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.
48
+ const formattedDate = (0, _date.dateI18n)( // translators: If using a space between 'g:i' and 'a', use a non-breaking space.
49
49
  (0, _i18n._x)('F j, Y g:i\xa0a', 'post schedule full date format'), date);
50
50
  return (0, _i18n.isRTL)() ? `${timezoneAbbreviation} ${formattedDate}` : `${formattedDate} ${timezoneAbbreviation}`;
51
51
  }
@@ -68,7 +68,7 @@ function getPostScheduleLabel(dateAttribute, {
68
68
 
69
69
  if (isSameDay(date, now)) {
70
70
  return (0, _i18n.sprintf)( // translators: %s: Time of day the post is scheduled for.
71
- (0, _i18n.__)('Today at %s'), // translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.
71
+ (0, _i18n.__)('Today at %s'), // translators: If using a space between 'g:i' and 'a', use a non-breaking space.
72
72
  (0, _date.dateI18n)((0, _i18n._x)('g:i\xa0a', 'post schedule time format'), date));
73
73
  }
74
74
 
@@ -77,12 +77,12 @@ function getPostScheduleLabel(dateAttribute, {
77
77
 
78
78
  if (isSameDay(date, tomorrow)) {
79
79
  return (0, _i18n.sprintf)( // translators: %s: Time of day the post is scheduled for.
80
- (0, _i18n.__)('Tomorrow at %s'), // translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.
80
+ (0, _i18n.__)('Tomorrow at %s'), // translators: If using a space between 'g:i' and 'a', use a non-breaking space.
81
81
  (0, _date.dateI18n)((0, _i18n._x)('g:i\xa0a', 'post schedule time format'), date));
82
82
  }
83
83
 
84
84
  if (date.getFullYear() === now.getFullYear()) {
85
- return (0, _date.dateI18n)( // translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.
85
+ return (0, _date.dateI18n)( // translators: If using a space between 'g:i' and 'a', use a non-breaking space.
86
86
  (0, _i18n._x)('F j g:i\xa0a', 'post schedule date format without year'), date);
87
87
  }
88
88
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-schedule/label.js"],"names":["PostScheduleLabel","props","usePostScheduleLabel","full","date","isFloating","select","editorStore","getEditedPostAttribute","isEditedPostDateFloating","getFullPostScheduleLabel","getPostScheduleLabel","dateAttribute","timezoneAbbreviation","getTimezoneAbbreviation","formattedDate","now","Date","isTimezoneSameAsSiteTimezone","isSameDay","tomorrow","setDate","getDate","getFullYear","timezone","abbr","isNaN","Number","symbol","offset","siteOffset","dateOffset","getTimezoneOffset","left","right","getMonth"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGe,SAASA,iBAAT,CAA4BC,KAA5B,EAAoC;AAClD,SAAOC,oBAAoB,CAAED,KAAF,CAA3B;AACA;;AAEM,SAASC,oBAAT,CAA+B;AAAEC,EAAAA,IAAI,GAAG;AAAT,IAAmB,EAAlD,EAAuD;AAC7D,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAuB,qBAC1BC,MAAF,KAAgB;AACfF,IAAAA,IAAI,EAAEE,MAAM,CAAEC,YAAF,CAAN,CAAsBC,sBAAtB,CAA8C,MAA9C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CAACX,OAAL,OAAmBY,KAAK,CAACZ,OAAN,EAAnB,IACAW,IAAI,CAACE,QAAL,OAAoBD,KAAK,CAACC,QAAN,EADpB,IAEAF,IAAI,CAACV,WAAL,OAAuBW,KAAK,CAACX,WAAN,EAHxB;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf, isRTL } from '@wordpress/i18n';\nimport { getSettings, getDate, dateI18n } from '@wordpress/date';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostScheduleLabel( props ) {\n\treturn usePostScheduleLabel( props );\n}\n\nexport function usePostScheduleLabel( { full = false } = {} ) {\n\tconst { date, isFloating } = useSelect(\n\t\t( select ) => ( {\n\t\t\tdate: select( editorStore ).getEditedPostAttribute( 'date' ),\n\t\t\tisFloating: select( editorStore ).isEditedPostDateFloating(),\n\t\t} ),\n\t\t[]\n\t);\n\n\treturn full\n\t\t? getFullPostScheduleLabel( date )\n\t\t: getPostScheduleLabel( date, { isFloating } );\n}\n\nexport function getFullPostScheduleLabel( dateAttribute ) {\n\tconst date = getDate( dateAttribute );\n\n\tconst timezoneAbbreviation = getTimezoneAbbreviation();\n\tconst formattedDate = dateI18n(\n\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.\n\t\t_x( 'F j, Y g:i\\xa0a', 'post schedule full date format' ),\n\t\tdate\n\t);\n\treturn isRTL()\n\t\t? `${ timezoneAbbreviation } ${ formattedDate }`\n\t\t: `${ formattedDate } ${ timezoneAbbreviation }`;\n}\n\nexport function getPostScheduleLabel(\n\tdateAttribute,\n\t{ isFloating = false, now = new Date() } = {}\n) {\n\tif ( ! dateAttribute || isFloating ) {\n\t\treturn __( 'Immediately' );\n\t}\n\n\t// If the user timezone does not equal the site timezone then using words\n\t// like 'tomorrow' is confusing, so show the full date.\n\tif ( ! isTimezoneSameAsSiteTimezone( now ) ) {\n\t\treturn getFullPostScheduleLabel( dateAttribute );\n\t}\n\n\tconst date = getDate( dateAttribute );\n\n\tif ( isSameDay( date, now ) ) {\n\t\treturn sprintf(\n\t\t\t// translators: %s: Time of day the post is scheduled for.\n\t\t\t__( 'Today at %s' ),\n\t\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.\n\t\t\tdateI18n( _x( 'g:i\\xa0a', 'post schedule time format' ), date )\n\t\t);\n\t}\n\n\tconst tomorrow = new Date( now );\n\ttomorrow.setDate( tomorrow.getDate() + 1 );\n\n\tif ( isSameDay( date, tomorrow ) ) {\n\t\treturn sprintf(\n\t\t\t// translators: %s: Time of day the post is scheduled for.\n\t\t\t__( 'Tomorrow at %s' ),\n\t\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.\n\t\t\tdateI18n( _x( 'g:i\\xa0a', 'post schedule time format' ), date )\n\t\t);\n\t}\n\n\tif ( date.getFullYear() === now.getFullYear() ) {\n\t\treturn dateI18n(\n\t\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking sapce.\n\t\t\t_x( 'F j g:i\\xa0a', 'post schedule date format without year' ),\n\t\t\tdate\n\t\t);\n\t}\n\n\treturn dateI18n(\n\t\t// translators: Use a non-breaking space between 'g:i' and 'a' if appropriate.\n\t\t_x( 'F j, Y g:i\\xa0a', 'post schedule full date format' ),\n\t\tdate\n\t);\n}\n\nfunction getTimezoneAbbreviation() {\n\tconst { timezone } = getSettings();\n\n\tif ( timezone.abbr && isNaN( Number( timezone.abbr ) ) ) {\n\t\treturn timezone.abbr;\n\t}\n\n\tconst symbol = timezone.offset < 0 ? '' : '+';\n\treturn `UTC${ symbol }${ timezone.offset }`;\n}\n\nfunction isTimezoneSameAsSiteTimezone( date ) {\n\tconst { timezone } = getSettings();\n\n\tconst siteOffset = Number( timezone.offset );\n\tconst dateOffset = -1 * ( date.getTimezoneOffset() / 60 );\n\treturn siteOffset === dateOffset;\n}\n\nfunction isSameDay( left, right ) {\n\treturn (\n\t\tleft.getDate() === right.getDate() &&\n\t\tleft.getMonth() === right.getMonth() &&\n\t\tleft.getFullYear() === right.getFullYear()\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-schedule/label.js"],"names":["PostScheduleLabel","props","usePostScheduleLabel","full","date","isFloating","select","editorStore","getEditedPostAttribute","isEditedPostDateFloating","getFullPostScheduleLabel","getPostScheduleLabel","dateAttribute","timezoneAbbreviation","getTimezoneAbbreviation","formattedDate","now","Date","isTimezoneSameAsSiteTimezone","isSameDay","tomorrow","setDate","getDate","getFullYear","timezone","abbr","isNaN","Number","symbol","offset","siteOffset","dateOffset","getTimezoneOffset","left","right","getMonth"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGe,SAASA,iBAAT,CAA4BC,KAA5B,EAAoC;AAClD,SAAOC,oBAAoB,CAAED,KAAF,CAA3B;AACA;;AAEM,SAASC,oBAAT,CAA+B;AAAEC,EAAAA,IAAI,GAAG;AAAT,IAAmB,EAAlD,EAAuD;AAC7D,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAuB,qBAC1BC,MAAF,KAAgB;AACfF,IAAAA,IAAI,EAAEE,MAAM,CAAEC,YAAF,CAAN,CAAsBC,sBAAtB,CAA8C,MAA9C,CADS;AAEfH,IAAAA,UAAU,EAAEC,MAAM,CAAEC,YAAF,CAAN,CAAsBE,wBAAtB;AAFG,GAAhB,CAD4B,EAK5B,EAL4B,CAA7B;AAQA,SAAON,IAAI,GACRO,wBAAwB,CAAEN,IAAF,CADhB,GAERO,oBAAoB,CAAEP,IAAF,EAAQ;AAAEC,IAAAA;AAAF,GAAR,CAFvB;AAGA;;AAEM,SAASK,wBAAT,CAAmCE,aAAnC,EAAmD;AACzD,QAAMR,IAAI,GAAG,mBAASQ,aAAT,CAAb;AAEA,QAAMC,oBAAoB,GAAGC,uBAAuB,EAApD;AACA,QAAMC,aAAa,GAAG,qBACrB;AACA,gBAAI,iBAAJ,EAAuB,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A,gBAAI,iBAAJ,EAAuB,gCAAvB,CAFM,EAGNA,IAHM,CAAP;AAKA;;AAED,SAASU,uBAAT,GAAmC;AAClC,QAAM;AAAEU,IAAAA;AAAF,MAAe,wBAArB;;AAEA,MAAKA,QAAQ,CAACC,IAAT,IAAiBC,KAAK,CAAEC,MAAM,CAAEH,QAAQ,CAACC,IAAX,CAAR,CAA3B,EAAyD;AACxD,WAAOD,QAAQ,CAACC,IAAhB;AACA;;AAED,QAAMG,MAAM,GAAGJ,QAAQ,CAACK,MAAT,GAAkB,CAAlB,GAAsB,EAAtB,GAA2B,GAA1C;AACA,SAAQ,MAAMD,MAAQ,GAAGJ,QAAQ,CAACK,MAAQ,EAA1C;AACA;;AAED,SAASX,4BAAT,CAAuCd,IAAvC,EAA8C;AAC7C,QAAM;AAAEoB,IAAAA;AAAF,MAAe,wBAArB;AAEA,QAAMM,UAAU,GAAGH,MAAM,CAAEH,QAAQ,CAACK,MAAX,CAAzB;AACA,QAAME,UAAU,GAAG,CAAC,CAAD,IAAO3B,IAAI,CAAC4B,iBAAL,KAA2B,EAAlC,CAAnB;AACA,SAAOF,UAAU,KAAKC,UAAtB;AACA;;AAED,SAASZ,SAAT,CAAoBc,IAApB,EAA0BC,KAA1B,EAAkC;AACjC,SACCD,IAAI,CAACX,OAAL,OAAmBY,KAAK,CAACZ,OAAN,EAAnB,IACAW,IAAI,CAACE,QAAL,OAAoBD,KAAK,CAACC,QAAN,EADpB,IAEAF,IAAI,CAACV,WAAL,OAAuBW,KAAK,CAACX,WAAN,EAHxB;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf, isRTL } from '@wordpress/i18n';\nimport { getSettings, getDate, dateI18n } from '@wordpress/date';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostScheduleLabel( props ) {\n\treturn usePostScheduleLabel( props );\n}\n\nexport function usePostScheduleLabel( { full = false } = {} ) {\n\tconst { date, isFloating } = useSelect(\n\t\t( select ) => ( {\n\t\t\tdate: select( editorStore ).getEditedPostAttribute( 'date' ),\n\t\t\tisFloating: select( editorStore ).isEditedPostDateFloating(),\n\t\t} ),\n\t\t[]\n\t);\n\n\treturn full\n\t\t? getFullPostScheduleLabel( date )\n\t\t: getPostScheduleLabel( date, { isFloating } );\n}\n\nexport function getFullPostScheduleLabel( dateAttribute ) {\n\tconst date = getDate( dateAttribute );\n\n\tconst timezoneAbbreviation = getTimezoneAbbreviation();\n\tconst formattedDate = dateI18n(\n\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking space.\n\t\t_x( 'F j, Y g:i\\xa0a', 'post schedule full date format' ),\n\t\tdate\n\t);\n\treturn isRTL()\n\t\t? `${ timezoneAbbreviation } ${ formattedDate }`\n\t\t: `${ formattedDate } ${ timezoneAbbreviation }`;\n}\n\nexport function getPostScheduleLabel(\n\tdateAttribute,\n\t{ isFloating = false, now = new Date() } = {}\n) {\n\tif ( ! dateAttribute || isFloating ) {\n\t\treturn __( 'Immediately' );\n\t}\n\n\t// If the user timezone does not equal the site timezone then using words\n\t// like 'tomorrow' is confusing, so show the full date.\n\tif ( ! isTimezoneSameAsSiteTimezone( now ) ) {\n\t\treturn getFullPostScheduleLabel( dateAttribute );\n\t}\n\n\tconst date = getDate( dateAttribute );\n\n\tif ( isSameDay( date, now ) ) {\n\t\treturn sprintf(\n\t\t\t// translators: %s: Time of day the post is scheduled for.\n\t\t\t__( 'Today at %s' ),\n\t\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking space.\n\t\t\tdateI18n( _x( 'g:i\\xa0a', 'post schedule time format' ), date )\n\t\t);\n\t}\n\n\tconst tomorrow = new Date( now );\n\ttomorrow.setDate( tomorrow.getDate() + 1 );\n\n\tif ( isSameDay( date, tomorrow ) ) {\n\t\treturn sprintf(\n\t\t\t// translators: %s: Time of day the post is scheduled for.\n\t\t\t__( 'Tomorrow at %s' ),\n\t\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking space.\n\t\t\tdateI18n( _x( 'g:i\\xa0a', 'post schedule time format' ), date )\n\t\t);\n\t}\n\n\tif ( date.getFullYear() === now.getFullYear() ) {\n\t\treturn dateI18n(\n\t\t\t// translators: If using a space between 'g:i' and 'a', use a non-breaking space.\n\t\t\t_x( 'F j g:i\\xa0a', 'post schedule date format without year' ),\n\t\t\tdate\n\t\t);\n\t}\n\n\treturn dateI18n(\n\t\t// translators: Use a non-breaking space between 'g:i' and 'a' if appropriate.\n\t\t_x( 'F j, Y g:i\\xa0a', 'post schedule full date format' ),\n\t\tdate\n\t);\n}\n\nfunction getTimezoneAbbreviation() {\n\tconst { timezone } = getSettings();\n\n\tif ( timezone.abbr && isNaN( Number( timezone.abbr ) ) ) {\n\t\treturn timezone.abbr;\n\t}\n\n\tconst symbol = timezone.offset < 0 ? '' : '+';\n\treturn `UTC${ symbol }${ timezone.offset }`;\n}\n\nfunction isTimezoneSameAsSiteTimezone( date ) {\n\tconst { timezone } = getSettings();\n\n\tconst siteOffset = Number( timezone.offset );\n\tconst dateOffset = -1 * ( date.getTimezoneOffset() / 60 );\n\treturn siteOffset === dateOffset;\n}\n\nfunction isSameDay( left, right ) {\n\treturn (\n\t\tleft.getDate() === right.getDate() &&\n\t\tleft.getMonth() === right.getMonth() &&\n\t\tleft.getFullYear() === right.getFullYear()\n\t);\n}\n"]}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.PostSyncStatusModal = PostSyncStatusModal;
6
7
  exports.default = PostSyncStatus;
7
8
 
8
9
  var _element = require("@wordpress/element");
@@ -13,8 +14,12 @@ var _i18n = require("@wordpress/i18n");
13
14
 
14
15
  var _components = require("@wordpress/components");
15
16
 
17
+ var _blockEditor = require("@wordpress/block-editor");
18
+
16
19
  var _store = require("../../store");
17
20
 
21
+ var _lockUnlock = require("../../lock-unlock");
22
+
18
23
  /**
19
24
  * WordPress dependencies
20
25
  */
@@ -25,24 +30,98 @@ var _store = require("../../store");
25
30
  function PostSyncStatus() {
26
31
  const {
27
32
  syncStatus,
28
- postType
33
+ postType,
34
+ meta
29
35
  } = (0, _data.useSelect)(select => {
30
36
  const {
31
37
  getEditedPostAttribute
32
38
  } = select(_store.store);
33
39
  return {
34
40
  syncStatus: getEditedPostAttribute('wp_pattern_sync_status'),
41
+ meta: getEditedPostAttribute('meta'),
35
42
  postType: getEditedPostAttribute('type')
36
43
  };
37
- }, []);
44
+ });
38
45
 
39
46
  if (postType !== 'wp_block') {
40
47
  return null;
41
- }
48
+ } // When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
49
+
42
50
 
43
- const isFullySynced = !syncStatus;
51
+ const currentSyncStatus = meta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus;
44
52
  return (0, _element.createElement)(_components.PanelRow, {
45
53
  className: "edit-post-sync-status"
46
- }, (0, _element.createElement)("span", null, (0, _i18n.__)('Sync status')), (0, _element.createElement)("div", null, isFullySynced ? (0, _i18n.__)('Fully synced') : (0, _i18n.__)('Not synced')));
54
+ }, (0, _element.createElement)("span", null, (0, _i18n.__)('Sync status')), (0, _element.createElement)("div", null, currentSyncStatus === 'unsynced' ? (0, _i18n.__)('Not synced') : (0, _i18n.__)('Fully synced')));
55
+ }
56
+
57
+ function PostSyncStatusModal() {
58
+ const {
59
+ editPost
60
+ } = (0, _data.useDispatch)(_store.store);
61
+ const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
62
+ const [syncType, setSyncType] = (0, _element.useState)(undefined);
63
+ const {
64
+ postType,
65
+ isNewPost
66
+ } = (0, _data.useSelect)(select => {
67
+ const {
68
+ getEditedPostAttribute,
69
+ isCleanNewPost
70
+ } = select(_store.store);
71
+ return {
72
+ postType: getEditedPostAttribute('type'),
73
+ isNewPost: isCleanNewPost()
74
+ };
75
+ }, []);
76
+ (0, _element.useEffect)(() => {
77
+ if (isNewPost && postType === 'wp_block') {
78
+ setIsModalOpen(true);
79
+ } // We only want the modal to open when the page is first loaded.
80
+ // eslint-disable-next-line react-hooks/exhaustive-deps
81
+
82
+ }, []);
83
+
84
+ const setSyncStatus = () => {
85
+ editPost({
86
+ meta: {
87
+ wp_pattern_sync_status: syncType
88
+ }
89
+ });
90
+ };
91
+
92
+ if (postType !== 'wp_block' || !isNewPost) {
93
+ return null;
94
+ }
95
+
96
+ const {
97
+ ReusableBlocksRenameHint
98
+ } = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
99
+ return (0, _element.createElement)(_element.Fragment, null, isModalOpen && (0, _element.createElement)(_components.Modal, {
100
+ title: (0, _i18n.__)('Set pattern sync status'),
101
+ onRequestClose: () => {
102
+ setIsModalOpen(false);
103
+ },
104
+ overlayClassName: "reusable-blocks-menu-items__convert-modal"
105
+ }, (0, _element.createElement)("form", {
106
+ onSubmit: event => {
107
+ event.preventDefault();
108
+ setIsModalOpen(false);
109
+ setSyncStatus();
110
+ }
111
+ }, (0, _element.createElement)(_components.__experimentalVStack, {
112
+ spacing: "5"
113
+ }, (0, _element.createElement)(ReusableBlocksRenameHint, null), (0, _element.createElement)(_components.ToggleControl, {
114
+ label: (0, _i18n.__)('Synced'),
115
+ help: (0, _i18n.__)('Editing the pattern will update it anywhere it is used.'),
116
+ checked: !syncType,
117
+ onChange: () => {
118
+ setSyncType(!syncType ? 'unsynced' : undefined);
119
+ }
120
+ }), (0, _element.createElement)(_components.__experimentalHStack, {
121
+ justify: "right"
122
+ }, (0, _element.createElement)(_components.Button, {
123
+ variant: "primary",
124
+ type: "submit"
125
+ }, (0, _i18n.__)('Create')))))));
47
126
  }
48
127
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-sync-status/index.js"],"names":["PostSyncStatus","syncStatus","postType","select","getEditedPostAttribute","editorStore","isFullySynced"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA2B,qBAAaC,MAAF,IAAc;AACzD,UAAM;AAAEC,MAAAA;AAAF,QAA6BD,MAAM,CAAEE,YAAF,CAAzC;AACA,WAAO;AACNJ,MAAAA,UAAU,EAAEG,sBAAsB,CAAE,wBAAF,CAD5B;AAENF,MAAAA,QAAQ,EAAEE,sBAAsB,CAAE,MAAF;AAF1B,KAAP;AAIA,GANgC,EAM9B,EAN8B,CAAjC;;AAOA,MAAKF,QAAQ,KAAK,UAAlB,EAA+B;AAC9B,WAAO,IAAP;AACA;;AAED,QAAMI,aAAa,GAAG,CAAEL,UAAxB;AAEA,SACC,4BAAC,oBAAD;AAAU,IAAA,SAAS,EAAC;AAApB,KACC,0CAAQ,cAAI,aAAJ,CAAR,CADD,EAEC,yCACGK,aAAa,GAAG,cAAI,cAAJ,CAAH,GAA0B,cAAI,YAAJ,CAD1C,CAFD,CADD;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { PanelRow } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostSyncStatus() {\n\tconst { syncStatus, postType } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\treturn {\n\t\t\tsyncStatus: getEditedPostAttribute( 'wp_pattern_sync_status' ),\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t};\n\t}, [] );\n\tif ( postType !== 'wp_block' ) {\n\t\treturn null;\n\t}\n\n\tconst isFullySynced = ! syncStatus;\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-sync-status\">\n\t\t\t<span>{ __( 'Sync status' ) }</span>\n\t\t\t<div>\n\t\t\t\t{ isFullySynced ? __( 'Fully synced' ) : __( 'Not synced' ) }\n\t\t\t</div>\n\t\t</PanelRow>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-sync-status/index.js"],"names":["PostSyncStatus","syncStatus","postType","meta","select","getEditedPostAttribute","editorStore","currentSyncStatus","wp_pattern_sync_status","PostSyncStatusModal","editPost","isModalOpen","setIsModalOpen","syncType","setSyncType","undefined","isNewPost","isCleanNewPost","setSyncStatus","ReusableBlocksRenameHint","blockEditorPrivateApis","event","preventDefault"],"mappings":";;;;;;;;AAaA;;AAVA;;AACA;;AACA;;AASA;;AAKA;;AACA;;AApBA;AACA;AACA;;AAcA;AACA;AACA;AAIe,SAASA,cAAT,GAA0B;AACxC,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,QAAd;AAAwBC,IAAAA;AAAxB,MAAiC,qBAAaC,MAAF,IAAc;AAC/D,UAAM;AAAEC,MAAAA;AAAF,QAA6BD,MAAM,CAAEE,YAAF,CAAzC;AACA,WAAO;AACNL,MAAAA,UAAU,EAAEI,sBAAsB,CAAE,wBAAF,CAD5B;AAENF,MAAAA,IAAI,EAAEE,sBAAsB,CAAE,MAAF,CAFtB;AAGNH,MAAAA,QAAQ,EAAEG,sBAAsB,CAAE,MAAF;AAH1B,KAAP;AAKA,GAPsC,CAAvC;;AASA,MAAKH,QAAQ,KAAK,UAAlB,EAA+B;AAC9B,WAAO,IAAP;AACA,GAZuC,CAaxC;;;AACA,QAAMK,iBAAiB,GACtBJ,IAAI,EAAEK,sBAAN,KAAiC,UAAjC,GAA8C,UAA9C,GAA2DP,UAD5D;AAGA,SACC,4BAAC,oBAAD;AAAU,IAAA,SAAS,EAAC;AAApB,KACC,0CAAQ,cAAI,aAAJ,CAAR,CADD,EAEC,yCACGM,iBAAiB,KAAK,UAAtB,GACC,cAAI,YAAJ,CADD,GAEC,cAAI,cAAJ,CAHJ,CAFD,CADD;AAUA;;AAEM,SAASE,mBAAT,GAA+B;AACrC,QAAM;AAAEC,IAAAA;AAAF,MAAe,uBAAaJ,YAAb,CAArB;AACA,QAAM,CAAEK,WAAF,EAAeC,cAAf,IAAkC,uBAAU,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AAC;AAAhB,KACC,4BAAC,wBAAD,OADD,EAEC,4BAAC,yBAAD;AACC,IAAA,KAAK,EAAG,cAAI,QAAJ,CADT;AAEC,IAAA,IAAI,EAAG,cACN,yDADM,CAFR;AAKC,IAAA,OAAO,EAAG,CAAEL,QALb;AAMC,IAAA,QAAQ,EAAG,MAAM;AAChBC,MAAAA,WAAW,CACV,CAAED,QAAF,GAAa,UAAb,GAA0BE,SADhB,CAAX;AAGA;AAVF,IAFD,EAcC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAC;AAAhB,KACC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,SAAhB;AAA0B,IAAA,IAAI,EAAC;AAA/B,KACG,cAAI,QAAJ,CADH,CADD,CAdD,CAPD,CAPD,CAFF,CADD;AA0CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPanelRow,\n\tModal,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { useEffect, useState } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nexport default function PostSyncStatus() {\n\tconst { syncStatus, postType, meta } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\treturn {\n\t\t\tsyncStatus: getEditedPostAttribute( 'wp_pattern_sync_status' ),\n\t\t\tmeta: getEditedPostAttribute( 'meta' ),\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t};\n\t} );\n\n\tif ( postType !== 'wp_block' ) {\n\t\treturn null;\n\t}\n\t// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.\n\tconst currentSyncStatus =\n\t\tmeta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus;\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-sync-status\">\n\t\t\t<span>{ __( 'Sync status' ) }</span>\n\t\t\t<div>\n\t\t\t\t{ currentSyncStatus === 'unsynced'\n\t\t\t\t\t? __( 'Not synced' )\n\t\t\t\t\t: __( 'Fully synced' ) }\n\t\t\t</div>\n\t\t</PanelRow>\n\t);\n}\n\nexport function PostSyncStatusModal() {\n\tconst { editPost } = useDispatch( editorStore );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\n\tconst { postType, isNewPost } = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute, isCleanNewPost } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\tpostType: getEditedPostAttribute( 'type' ),\n\t\t\tisNewPost: isCleanNewPost(),\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isNewPost && postType === 'wp_block' ) {\n\t\t\tsetIsModalOpen( true );\n\t\t}\n\t\t// We only want the modal to open when the page is first loaded.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [] );\n\n\tconst setSyncStatus = () => {\n\t\teditPost( {\n\t\t\tmeta: {\n\t\t\t\twp_pattern_sync_status: syncType,\n\t\t\t},\n\t\t} );\n\t};\n\n\tif ( postType !== 'wp_block' || ! isNewPost ) {\n\t\treturn null;\n\t}\n\tconst { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis );\n\treturn (\n\t\t<>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Set pattern sync status' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetSyncStatus();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
@@ -13,6 +13,8 @@ var _reactAutosizeTextarea = _interopRequireDefault(require("react-autosize-text
13
13
 
14
14
  var _i18n = require("@wordpress/i18n");
15
15
 
16
+ var _coreData = require("@wordpress/core-data");
17
+
16
18
  var _blocks = require("@wordpress/blocks");
17
19
 
18
20
  var _data = require("@wordpress/data");
@@ -35,65 +37,51 @@ var _store = require("../../store");
35
37
  * Internal dependencies
36
38
  */
37
39
  function PostTextEditor() {
38
- const postContent = (0, _data.useSelect)(select => select(_store.store).getEditedPostContent(), []);
39
- const {
40
- editPost,
41
- resetEditorBlocks
42
- } = (0, _data.useDispatch)(_store.store);
43
- const [value, setValue] = (0, _element.useState)(postContent);
44
- const [isDirty, setIsDirty] = (0, _element.useState)(false);
45
40
  const instanceId = (0, _compose.useInstanceId)(PostTextEditor);
46
- const valueRef = (0, _element.useRef)();
47
-
48
- if (!isDirty && value !== postContent) {
49
- setValue(postContent);
50
- }
51
- /**
52
- * Handles a textarea change event to notify the onChange prop callback and
53
- * reflect the new value in the component's own state. This marks the start
54
- * of the user's edits, if not already changed, preventing future props
55
- * changes to value from replacing the rendered value. This is expected to
56
- * be followed by a reset to dirty state via `stopEditing`.
57
- *
58
- * @see stopEditing
59
- *
60
- * @param {Event} event Change event.
61
- */
62
-
63
-
64
- const onChange = event => {
65
- const newValue = event.target.value;
66
- editPost({
67
- content: newValue
68
- });
69
- setValue(newValue);
70
- setIsDirty(true);
71
- valueRef.current = newValue;
72
- };
73
- /**
74
- * Function called when the user has completed their edits, responsible for
75
- * ensuring that changes, if made, are surfaced to the onPersist prop
76
- * callback and resetting dirty state.
77
- */
78
-
79
-
80
- const stopEditing = () => {
81
- if (isDirty) {
82
- const blocks = (0, _blocks.parse)(value);
83
- resetEditorBlocks(blocks);
84
- setIsDirty(false);
85
- }
86
- }; // Ensure changes aren't lost when component unmounts.
87
-
88
-
89
- (0, _element.useEffect)(() => {
90
- return () => {
91
- if (valueRef.current) {
92
- const blocks = (0, _blocks.parse)(valueRef.current);
93
- resetEditorBlocks(blocks);
94
- }
41
+ const {
42
+ content,
43
+ blocks,
44
+ type,
45
+ id
46
+ } = (0, _data.useSelect)(select => {
47
+ const {
48
+ getEditedEntityRecord
49
+ } = select(_coreData.store);
50
+ const {
51
+ getCurrentPostType,
52
+ getCurrentPostId
53
+ } = select(_store.store);
54
+
55
+ const _type = getCurrentPostType();
56
+
57
+ const _id = getCurrentPostId();
58
+
59
+ const editedRecord = getEditedEntityRecord('postType', _type, _id);
60
+ return {
61
+ content: editedRecord?.content,
62
+ blocks: editedRecord?.blocks,
63
+ type: _type,
64
+ id: _id
95
65
  };
96
66
  }, []);
67
+ const {
68
+ editEntityRecord
69
+ } = (0, _data.useDispatch)(_coreData.store); // Replicates the logic found in getEditedPostContent().
70
+
71
+ const value = (0, _element.useMemo)(() => {
72
+ if (content instanceof Function) {
73
+ return content({
74
+ blocks
75
+ });
76
+ } else if (blocks) {
77
+ // If we have parsed blocks already, they should be our source of truth.
78
+ // Parsing applies block deprecations and legacy block conversions that
79
+ // unparsed content will not have.
80
+ return (0, _blocks.__unstableSerializeAndClean)(blocks);
81
+ }
82
+
83
+ return content;
84
+ }, [content, blocks]);
97
85
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.VisuallyHidden, {
98
86
  as: "label",
99
87
  htmlFor: `post-content-${instanceId}`
@@ -101,8 +89,13 @@ function PostTextEditor() {
101
89
  autoComplete: "off",
102
90
  dir: "auto",
103
91
  value: value,
104
- onChange: onChange,
105
- onBlur: stopEditing,
92
+ onChange: event => {
93
+ editEntityRecord('postType', type, id, {
94
+ content: event.target.value,
95
+ blocks: undefined,
96
+ selection: undefined
97
+ });
98
+ },
106
99
  className: "editor-post-text-editor",
107
100
  id: `post-content-${instanceId}`,
108
101
  placeholder: (0, _i18n.__)('Start writing with text or HTML')
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["PostTextEditor","postContent","select","editorStore","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","valueRef","onChange","event","newValue","target","content","current","stopEditing","blocks"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAMC,WAAW,GAAG,qBACjBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,oBAAtB,EADK,EAEnB,EAFmB,CAApB;AAKA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAkC,uBAAaH,YAAb,CAAxC;AAEA,QAAM,CAAEI,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AAI,mBAAJ,CAJH,CADD,EAOC,4BAAC,8BAAD;AACC,IAAA,YAAY,EAAC,KADd;AAEC,IAAA,GAAG,EAAC,MAFL;AAGC,IAAA,KAAK,EAAGJ,KAHT;AAIC,IAAA,QAAQ,EAAGM,QAJZ;AAKC,IAAA,MAAM,EAAGM,WALV;AAMC,IAAA,SAAS,EAAC,yBANX;AAOC,IAAA,EAAE,EAAI,gBAAgBR,UAAY,EAPnC;AAQC,IAAA,WAAW,EAAG,cAAI,iCAAJ;AARf,IAPD,CADD;AAoBA","sourcesContent":["/**\n * External dependencies\n */\nimport Textarea from 'react-autosize-textarea';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { parse } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { VisuallyHidden } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostTextEditor() {\n\tconst postContent = useSelect(\n\t\t( select ) => select( editorStore ).getEditedPostContent(),\n\t\t[]\n\t);\n\n\tconst { editPost, resetEditorBlocks } = useDispatch( editorStore );\n\n\tconst [ value, setValue ] = useState( postContent );\n\tconst [ isDirty, setIsDirty ] = useState( false );\n\tconst instanceId = useInstanceId( PostTextEditor );\n\tconst valueRef = useRef();\n\n\tif ( ! isDirty && value !== postContent ) {\n\t\tsetValue( postContent );\n\t}\n\n\t/**\n\t * Handles a textarea change event to notify the onChange prop callback and\n\t * reflect the new value in the component's own state. This marks the start\n\t * of the user's edits, if not already changed, preventing future props\n\t * changes to value from replacing the rendered value. This is expected to\n\t * be followed by a reset to dirty state via `stopEditing`.\n\t *\n\t * @see stopEditing\n\t *\n\t * @param {Event} event Change event.\n\t */\n\tconst onChange = ( event ) => {\n\t\tconst newValue = event.target.value;\n\t\teditPost( { content: newValue } );\n\t\tsetValue( newValue );\n\t\tsetIsDirty( true );\n\t\tvalueRef.current = newValue;\n\t};\n\n\t/**\n\t * Function called when the user has completed their edits, responsible for\n\t * ensuring that changes, if made, are surfaced to the onPersist prop\n\t * callback and resetting dirty state.\n\t */\n\tconst stopEditing = () => {\n\t\tif ( isDirty ) {\n\t\t\tconst blocks = parse( value );\n\t\t\tresetEditorBlocks( blocks );\n\t\t\tsetIsDirty( false );\n\t\t}\n\t};\n\n\t// Ensure changes aren't lost when component unmounts.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( valueRef.current ) {\n\t\t\t\tconst blocks = parse( valueRef.current );\n\t\t\t\tresetEditorBlocks( blocks );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<VisuallyHidden\n\t\t\t\tas=\"label\"\n\t\t\t\thtmlFor={ `post-content-${ instanceId }` }\n\t\t\t>\n\t\t\t\t{ __( 'Type text or HTML' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Textarea\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tdir=\"auto\"\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonBlur={ stopEditing }\n\t\t\t\tclassName=\"editor-post-text-editor\"\n\t\t\t\tid={ `post-content-${ instanceId }` }\n\t\t\t\tplaceholder={ __( 'Start writing with text or HTML' ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["PostTextEditor","instanceId","content","blocks","type","id","select","getEditedEntityRecord","coreStore","getCurrentPostType","getCurrentPostId","editorStore","_type","_id","editedRecord","editEntityRecord","value","Function","event","target","undefined","selection"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;AAGe,SAASA,cAAT,GAA0B;AACxC,QAAMC,UAAU,GAAG,4BAAeD,cAAf,CAAn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KADd;AAEC,IAAA,GAAG,EAAC,MAFL;AAGC,IAAA,KAAK,EAAGe,KAHT;AAIC,IAAA,QAAQ,EAAKE,KAAF,IAAa;AACvBH,MAAAA,gBAAgB,CAAE,UAAF,EAAcX,IAAd,EAAoBC,EAApB,EAAwB;AACvCH,QAAAA,OAAO,EAAEgB,KAAK,CAACC,MAAN,CAAaH,KADiB;AAEvCb,QAAAA,MAAM,EAAEiB,SAF+B;AAGvCC,QAAAA,SAAS,EAAED;AAH4B,OAAxB,CAAhB;AAKA,KAVF;AAWC,IAAA,SAAS,EAAC,yBAXX;AAYC,IAAA,EAAE,EAAI,gBAAgBnB,UAAY,EAZnC;AAaC,IAAA,WAAW,EAAG,cAAI,iCAAJ;AAbf,IAPD,CADD;AAyBA","sourcesContent":["/**\n * External dependencies\n */\nimport Textarea from 'react-autosize-textarea';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { VisuallyHidden } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostTextEditor() {\n\tconst instanceId = useInstanceId( PostTextEditor );\n\tconst { content, blocks, type, id } = useSelect( ( select ) => {\n\t\tconst { getEditedEntityRecord } = select( coreStore );\n\t\tconst { getCurrentPostType, getCurrentPostId } = select( editorStore );\n\t\tconst _type = getCurrentPostType();\n\t\tconst _id = getCurrentPostId();\n\t\tconst editedRecord = getEditedEntityRecord( 'postType', _type, _id );\n\n\t\treturn {\n\t\t\tcontent: editedRecord?.content,\n\t\t\tblocks: editedRecord?.blocks,\n\t\t\ttype: _type,\n\t\t\tid: _id,\n\t\t};\n\t}, [] );\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\t// Replicates the logic found in getEditedPostContent().\n\tconst value = useMemo( () => {\n\t\tif ( content instanceof Function ) {\n\t\t\treturn content( { blocks } );\n\t\t} else if ( blocks ) {\n\t\t\t// If we have parsed blocks already, they should be our source of truth.\n\t\t\t// Parsing applies block deprecations and legacy block conversions that\n\t\t\t// unparsed content will not have.\n\t\t\treturn __unstableSerializeAndClean( blocks );\n\t\t}\n\t\treturn content;\n\t}, [ content, blocks ] );\n\n\treturn (\n\t\t<>\n\t\t\t<VisuallyHidden\n\t\t\t\tas=\"label\"\n\t\t\t\thtmlFor={ `post-content-${ instanceId }` }\n\t\t\t>\n\t\t\t\t{ __( 'Type text or HTML' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Textarea\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tdir=\"auto\"\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ ( event ) => {\n\t\t\t\t\teditEntityRecord( 'postType', type, id, {\n\t\t\t\t\t\tcontent: event.target.value,\n\t\t\t\t\t\tblocks: undefined,\n\t\t\t\t\t\tselection: undefined,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tclassName=\"editor-post-text-editor\"\n\t\t\t\tid={ `post-content-${ instanceId }` }\n\t\t\t\tplaceholder={ __( 'Start writing with text or HTML' ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
@@ -25,7 +25,6 @@ var _store = require("../../store");
25
25
  * type supports one of the given `supportKeys` prop.
26
26
  *
27
27
  * @param {Object} props Props.
28
- * @param {string} [props.postType] Current post type.
29
28
  * @param {WPElement} props.children Children to be rendered if post
30
29
  * type supports.
31
30
  * @param {(string|string[])} props.supportKeys String or string array of keys
@@ -34,10 +33,18 @@ var _store = require("../../store");
34
33
  * @return {WPComponent} The component to be rendered.
35
34
  */
36
35
  function PostTypeSupportCheck({
37
- postType,
38
36
  children,
39
37
  supportKeys
40
38
  }) {
39
+ const postType = (0, _data.useSelect)(select => {
40
+ const {
41
+ getEditedPostAttribute
42
+ } = select(_store.store);
43
+ const {
44
+ getPostType
45
+ } = select(_coreData.store);
46
+ return getPostType(getEditedPostAttribute('type'));
47
+ }, []);
41
48
  let isSupported = true;
42
49
 
43
50
  if (postType) {
@@ -51,17 +58,6 @@ function PostTypeSupportCheck({
51
58
  return children;
52
59
  }
53
60
 
54
- var _default = (0, _data.withSelect)(select => {
55
- const {
56
- getEditedPostAttribute
57
- } = select(_store.store);
58
- const {
59
- getPostType
60
- } = select(_coreData.store);
61
- return {
62
- postType: getPostType(getEditedPostAttribute('type'))
63
- };
64
- })(PostTypeSupportCheck);
65
-
61
+ var _default = PostTypeSupportCheck;
66
62
  exports.default = _default;
67
63
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/components/post-type-support-check/index.js"],"names":["PostTypeSupportCheck","postType","children","supportKeys","isSupported","Array","isArray","some","key","supports","select","getEditedPostAttribute","editorStore","getPostType","coreStore"],"mappings":";;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAT,CAA+B;AAAEC,EAAAA,QAAF;AAAYC,EAAAA,QAAZ;AAAsBC,EAAAA;AAAtB,CAA/B,EAAqE;AAC3E,MAAIC,WAAW,GAAG,IAAlB;;AACA,MAAKH,QAAL,EAAgB;AACfG,IAAAA,WAAW,GAAG,CACbC,KAAK,CAACC,OAAN,CAAeH,WAAf,IAA+BA,WAA/B,GAA6C,CAAEA,WAAF,CADhC,EAEZI,IAFY,CAEJC,GAAF,IAAW,CAAC,CAAEP,QAAQ,CAACQ,QAAT,CAAmBD,GAAnB,CAFR,CAAd;AAGA;;AAED,MAAK,CAAEJ,WAAP,EAAqB;AACpB,WAAO,IAAP;AACA;;AAED,SAAOF,QAAP;AACA;;eAEc,sBAAcQ,MAAF,IAAc;AACxC,QAAM;AAAEC,IAAAA;AAAF,MAA6BD,MAAM,CAAEE,YAAF,CAAzC;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAkBH,MAAM,CAAEI,eAAF,CAA9B;AACA,SAAO;AACNb,IAAAA,QAAQ,EAAEY,WAAW,CAAEF,sBAAsB,CAAE,MAAF,CAAxB;AADf,GAAP;AAGA,CANc,EAMVX,oBANU,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { withSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\n/**\n * A component which renders its own children only if the current editor post\n * type supports one of the given `supportKeys` prop.\n *\n * @param {Object} props Props.\n * @param {string} [props.postType] Current post type.\n * @param {WPElement} props.children Children to be rendered if post\n * type supports.\n * @param {(string|string[])} props.supportKeys String or string array of keys\n * to test.\n *\n * @return {WPComponent} The component to be rendered.\n */\nexport function PostTypeSupportCheck( { postType, children, supportKeys } ) {\n\tlet isSupported = true;\n\tif ( postType ) {\n\t\tisSupported = (\n\t\t\tArray.isArray( supportKeys ) ? supportKeys : [ supportKeys ]\n\t\t).some( ( key ) => !! postType.supports[ key ] );\n\t}\n\n\tif ( ! isSupported ) {\n\t\treturn null;\n\t}\n\n\treturn children;\n}\n\nexport default withSelect( ( select ) => {\n\tconst { getEditedPostAttribute } = select( editorStore );\n\tconst { getPostType } = select( coreStore );\n\treturn {\n\t\tpostType: getPostType( getEditedPostAttribute( 'type' ) ),\n\t};\n} )( PostTypeSupportCheck );\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/components/post-type-support-check/index.js"],"names":["PostTypeSupportCheck","children","supportKeys","postType","select","getEditedPostAttribute","editorStore","getPostType","coreStore","isSupported","Array","isArray","some","key","supports"],"mappings":";;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAT,CAA+B;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAA/B,EAA2D;AACjE,QAAMC,QAAQ,GAAG,qBAAaC,MAAF,IAAc;AACzC,UAAM;AAAEC,MAAAA;AAAF,QAA6BD,MAAM,CAAEE,YAAF,CAAzC;AACA,UAAM;AAAEC,MAAAA;AAAF,QAAkBH,MAAM,CAAEI,eAAF,CAA9B;AACA,WAAOD,WAAW,CAAEF,sBAAsB,CAAE,MAAF,CAAxB,CAAlB;AACA,GAJgB,EAId,EAJc,CAAjB;AAKA,MAAII,WAAW,GAAG,IAAlB;;AACA,MAAKN,QAAL,EAAgB;AACfM,IAAAA,WAAW,GAAG,CACbC,KAAK,CAACC,OAAN,CAAeT,WAAf,IAA+BA,WAA/B,GAA6C,CAAEA,WAAF,CADhC,EAEZU,IAFY,CAEJC,GAAF,IAAW,CAAC,CAAEV,QAAQ,CAACW,QAAT,CAAmBD,GAAnB,CAFR,CAAd;AAGA;;AAED,MAAK,CAAEJ,WAAP,EAAqB;AACpB,WAAO,IAAP;AACA;;AAED,SAAOR,QAAP;AACA;;eAEcD,oB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\n/**\n * A component which renders its own children only if the current editor post\n * type supports one of the given `supportKeys` prop.\n *\n * @param {Object} props Props.\n * @param {WPElement} props.children Children to be rendered if post\n * type supports.\n * @param {(string|string[])} props.supportKeys String or string array of keys\n * to test.\n *\n * @return {WPComponent} The component to be rendered.\n */\nexport function PostTypeSupportCheck( { children, supportKeys } ) {\n\tconst postType = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\tconst { getPostType } = select( coreStore );\n\t\treturn getPostType( getEditedPostAttribute( 'type' ) );\n\t}, [] );\n\tlet isSupported = true;\n\tif ( postType ) {\n\t\tisSupported = (\n\t\t\tArray.isArray( supportKeys ) ? supportKeys : [ supportKeys ]\n\t\t).some( ( key ) => !! postType.supports[ key ] );\n\t}\n\n\tif ( ! isSupported ) {\n\t\treturn null;\n\t}\n\n\treturn children;\n}\n\nexport default PostTypeSupportCheck;\n"]}
@@ -2,8 +2,6 @@
2
2
 
3
3
  var _element = require("@wordpress/element");
4
4
 
5
- var _blocks = require("@wordpress/blocks");
6
-
7
5
  var _data = require("@wordpress/data");
8
6
 
9
7
  var _coreData = require("@wordpress/core-data");
@@ -99,26 +97,5 @@ function shimAttributeSource(settings) {
99
97
  return settings;
100
98
  }
101
99
 
102
- (0, _hooks.addFilter)('blocks.registerBlockType', 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', shimAttributeSource); // The above filter will only capture blocks registered after the filter was
103
- // added. There may already be blocks registered by this point, and those must
104
- // be updated to apply the shim.
105
- //
106
- // The following implementation achieves this, albeit with a couple caveats:
107
- // - Only blocks registered on the global store will be modified.
108
- // - The block settings are directly mutated, since there is currently no
109
- // mechanism to update an existing block registration. This is the reason for
110
- // `getBlockType` separate from `getBlockTypes`, since the latter returns a
111
- // _copy_ of the block registration (i.e. the mutation would not affect the
112
- // actual registered block settings).
113
- //
114
- // `getBlockTypes` or `getBlockType` implementation could change in the future
115
- // in regards to creating settings clones, but the corresponding end-to-end
116
- // tests for meta blocks should cover against any potential regressions.
117
- //
118
- // In the future, we could support updating block settings, at which point this
119
- // implementation could use that mechanism instead.
120
-
121
- (0, _data.select)(_blocks.store).getBlockTypes().map(({
122
- name
123
- }) => (0, _data.select)(_blocks.store).getBlockType(name)).forEach(shimAttributeSource);
100
+ (0, _hooks.addFilter)('blocks.registerBlockType', 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', shimAttributeSource);
124
101
  //# sourceMappingURL=custom-sources-backwards-compatibility.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/editor/src/hooks/custom-sources-backwards-compatibility.js"],"names":["createWithMetaAttributeSource","metaAttributes","BlockEdit","attributes","setAttributes","props","postType","select","editorStore","getCurrentPostType","meta","setMeta","mergedAttributes","Object","fromEntries","entries","map","attributeKey","metaKey","nextAttributes","nextMeta","filter","key","value","length","shimAttributeSource","settings","source","edit","blocksStore","getBlockTypes","name","getBlockType","forEach"],"mappings":";;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;AAbA;AACA;AACA;;AAQA;AACA;AACA;;AAGA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,6BAA6B,GAAKC,cAAF,IACrC,yCACGC,SAAF,IACC,CAAE;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,aAAd;AAA6B,KAAGC;AAAhC,CAAF,KAA+C;AAC9C,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAAsBC,kBAAtB,EADE,EAEhB,EAFgB,CAAjB;AAIA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,6BACzB,UADyB,EAEzBL,QAFyB,EAGzB,MAHyB,CAA1B;AAMA,QAAMM,gBAAgB,GAAG,sBACxB,OAAQ,EACP,GAAGT,UADI;AAEP,OAAGU,MAAM,CAACC,WAAP,CACFD,MAAM,CAACE,OAAP,CAAgBd,cAAhB,EAAiCe,GAAjC,CACC,CAAE,CAAEC,YAAF,EAAgBC,OAAhB,CAAF,KAAiC,CAChCD,YADgC,EAEhCP,IAAI,CAAEQ,OAAF,CAF4B,CADlC,CADE;AAFI,GAAR,CADwB,EAYxB,CAAEf,UAAF,EAAcO,IAAd,CAZwB,CAAzB;AAeA,SACC,4BAAC,SAAD;AACC,IAAA,UAAU,EAAGE,gBADd;AAEC,IAAA,aAAa,EAAKO,cAAF,IAAsB;AACrC,YAAMC,QAAQ,GAAGP,MAAM,CAACC,WAAP,CAChBD,MAAM,CAACE,OAAP,CAAgBI,cAAhB,aAAgBA,cAAhB,cAAgBA,cAAhB,GAAkC,EAAlC,EACEE,MADF,EAEE;AACA;AACA,OA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AAd,EACEC,aADF,GAEEd,GAFF,CAEO,CAAE;AAAEe,EAAAA;AAAF,CAAF,KAAgB,kBAAcF,aAAd,EAA4BG,YAA5B,CAA0CD,IAA1C,CAFvB,EAGEE,OAHF,CAGWR,mBAHX","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { select as globalSelect, useSelect } from '@wordpress/data';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Object whose keys are the names of block attributes, where each value\n * represents the meta key to which the block attribute is intended to save.\n *\n * @see https://developer.wordpress.org/reference/functions/register_meta/\n *\n * @typedef {Object<string,string>} WPMetaAttributeMapping\n */\n\n/**\n * Given a mapping of attribute names (meta source attributes) to their\n * associated meta key, returns a higher order component that overrides its\n * `attributes` and `setAttributes` props to sync any changes with the edited\n * post's meta keys.\n *\n * @param {WPMetaAttributeMapping} metaAttributes Meta attribute mapping.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\nconst createWithMetaAttributeSource = ( metaAttributes ) =>\n\tcreateHigherOrderComponent(\n\t\t( BlockEdit ) =>\n\t\t\t( { attributes, setAttributes, ...props } ) => {\n\t\t\t\tconst postType = useSelect(\n\t\t\t\t\t( select ) => select( editorStore ).getCurrentPostType(),\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tconst [ meta, setMeta ] = useEntityProp(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\t'meta'\n\t\t\t\t);\n\n\t\t\t\tconst mergedAttributes = useMemo(\n\t\t\t\t\t() => ( {\n\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( metaAttributes ).map(\n\t\t\t\t\t\t\t\t( [ attributeKey, metaKey ] ) => [\n\t\t\t\t\t\t\t\t\tattributeKey,\n\t\t\t\t\t\t\t\t\tmeta[ metaKey ],\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} ),\n\t\t\t\t\t[ attributes, meta ]\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<BlockEdit\n\t\t\t\t\t\tattributes={ mergedAttributes }\n\t\t\t\t\t\tsetAttributes={ ( nextAttributes ) => {\n\t\t\t\t\t\t\tconst nextMeta = Object.fromEntries(\n\t\t\t\t\t\t\t\tObject.entries( nextAttributes ?? {} )\n\t\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t\t// Filter to intersection of keys between the updated\n\t\t\t\t\t\t\t\t\t\t// attributes and those with an associated meta key.\n\t\t\t\t\t\t\t\t\t\t( [ key ] ) => key in metaAttributes\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.map( ( [ attributeKey, value ] ) => [\n\t\t\t\t\t\t\t\t\t\t// Rename the keys to the expected meta key name.\n\t\t\t\t\t\t\t\t\t\tmetaAttributes[ attributeKey ],\n\t\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( Object.entries( nextMeta ).length ) {\n\t\t\t\t\t\t\t\tsetMeta( nextMeta );\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t},\n\t\t'withMetaAttributeSource'\n\t);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade meta-sourced attributes to use the post's meta entity property.\n *\n * @param {WPBlockSettings} settings Registered block settings.\n *\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings ) {\n\t/** @type {WPMetaAttributeMapping} */\n\tconst metaAttributes = Object.fromEntries(\n\t\tObject.entries( settings.attributes ?? {} )\n\t\t\t.filter( ( [ , { source } ] ) => source === 'meta' )\n\t\t\t.map( ( [ attributeKey, { meta } ] ) => [ attributeKey, meta ] )\n\t);\n\tif ( Object.entries( metaAttributes ).length ) {\n\t\tsettings.edit = createWithMetaAttributeSource( metaAttributes )(\n\t\t\tsettings.edit\n\t\t);\n\t}\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n\n// The above filter will only capture blocks registered after the filter was\n// added. There may already be blocks registered by this point, and those must\n// be updated to apply the shim.\n//\n// The following implementation achieves this, albeit with a couple caveats:\n// - Only blocks registered on the global store will be modified.\n// - The block settings are directly mutated, since there is currently no\n// mechanism to update an existing block registration. This is the reason for\n// `getBlockType` separate from `getBlockTypes`, since the latter returns a\n// _copy_ of the block registration (i.e. the mutation would not affect the\n// actual registered block settings).\n//\n// `getBlockTypes` or `getBlockType` implementation could change in the future\n// in regards to creating settings clones, but the corresponding end-to-end\n// tests for meta blocks should cover against any potential regressions.\n//\n// In the future, we could support updating block settings, at which point this\n// implementation could use that mechanism instead.\nglobalSelect( blocksStore )\n\t.getBlockTypes()\n\t.map( ( { name } ) => globalSelect( blocksStore ).getBlockType( name ) )\n\t.forEach( shimAttributeSource );\n"]}
1
+ {"version":3,"sources":["@wordpress/editor/src/hooks/custom-sources-backwards-compatibility.js"],"names":["createWithMetaAttributeSource","metaAttributes","BlockEdit","attributes","setAttributes","props","postType","select","editorStore","getCurrentPostType","meta","setMeta","mergedAttributes","Object","fromEntries","entries","map","attributeKey","metaKey","nextAttributes","nextMeta","filter","key","value","length","shimAttributeSource","settings","source","edit"],"mappings":";;AAKA;;AAFA;;AACA;;AA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AAEgB,YAAF,CAFsB,EAGpCM,KAHoC,CANtC,CADgB,CAAjB;;AAcA,UAAKV,MAAM,CAACE,OAAP,CAAgBK,QAAhB,EAA2BI,MAAhC,EAAyC;AACxCb,QAAAA,OAAO,CAAES,QAAF,CAAP;AACA;;AAEDhB,MAAAA,aAAa,CAAEe,cAAF,CAAb;AACA,KAtBF;AAAA,OAuBMd;AAvBN,IADD;AA2BA,CAvDH,EAwDC,yBAxDD,CADD;AA4DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASoB,mBAAT,CAA8BC,QAA9B,EAAyC;AAAA;;AACxC;AACA,QAAMzB,cAAc,GAAGY,MAAM,CAACC,WAAP,CACtBD,MAAM,CAACE,OAAP,yBAAgBW,QAAQ,CAACvB,UAAzB,uEAAuC,EAAvC,EACEkB,MADF,CACU,CAAE,GAAI;AAAEM,IAAAA;AAAF,GAAJ,CAAF,KAAwBA,MAAM,KAAK,MAD7C,EAEEX,GAFF,CAEO,CAAE,CAAEC,YAAF,EAAgB;AAAEP,IAAAA;AAAF,GAAhB,CAAF,KAAkC,CAAEO,YAAF,EAAgBP,IAAhB,CAFzC,CADsB,CAAvB;;AAKA,MAAKG,MAAM,CAACE,OAAP,CAAgBd,cAAhB,EAAiCuB,MAAtC,EAA+C;AAC9CE,IAAAA,QAAQ,CAACE,IAAT,GAAgB5B,6BAA6B,CAAEC,cAAF,CAA7B,CACfyB,QAAQ,CAACE,IADM,CAAhB;AAGA;;AAED,SAAOF,QAAP;AACA;;AAED,sBACC,0BADD,EAEC,0EAFD,EAGCD,mBAHD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../store';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Object whose keys are the names of block attributes, where each value\n * represents the meta key to which the block attribute is intended to save.\n *\n * @see https://developer.wordpress.org/reference/functions/register_meta/\n *\n * @typedef {Object<string,string>} WPMetaAttributeMapping\n */\n\n/**\n * Given a mapping of attribute names (meta source attributes) to their\n * associated meta key, returns a higher order component that overrides its\n * `attributes` and `setAttributes` props to sync any changes with the edited\n * post's meta keys.\n *\n * @param {WPMetaAttributeMapping} metaAttributes Meta attribute mapping.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\nconst createWithMetaAttributeSource = ( metaAttributes ) =>\n\tcreateHigherOrderComponent(\n\t\t( BlockEdit ) =>\n\t\t\t( { attributes, setAttributes, ...props } ) => {\n\t\t\t\tconst postType = useSelect(\n\t\t\t\t\t( select ) => select( editorStore ).getCurrentPostType(),\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tconst [ meta, setMeta ] = useEntityProp(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\t'meta'\n\t\t\t\t);\n\n\t\t\t\tconst mergedAttributes = useMemo(\n\t\t\t\t\t() => ( {\n\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( metaAttributes ).map(\n\t\t\t\t\t\t\t\t( [ attributeKey, metaKey ] ) => [\n\t\t\t\t\t\t\t\t\tattributeKey,\n\t\t\t\t\t\t\t\t\tmeta[ metaKey ],\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} ),\n\t\t\t\t\t[ attributes, meta ]\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<BlockEdit\n\t\t\t\t\t\tattributes={ mergedAttributes }\n\t\t\t\t\t\tsetAttributes={ ( nextAttributes ) => {\n\t\t\t\t\t\t\tconst nextMeta = Object.fromEntries(\n\t\t\t\t\t\t\t\tObject.entries( nextAttributes ?? {} )\n\t\t\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t\t\t// Filter to intersection of keys between the updated\n\t\t\t\t\t\t\t\t\t\t// attributes and those with an associated meta key.\n\t\t\t\t\t\t\t\t\t\t( [ key ] ) => key in metaAttributes\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.map( ( [ attributeKey, value ] ) => [\n\t\t\t\t\t\t\t\t\t\t// Rename the keys to the expected meta key name.\n\t\t\t\t\t\t\t\t\t\tmetaAttributes[ attributeKey ],\n\t\t\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif ( Object.entries( nextMeta ).length ) {\n\t\t\t\t\t\t\t\tsetMeta( nextMeta );\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t},\n\t\t'withMetaAttributeSource'\n\t);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade meta-sourced attributes to use the post's meta entity property.\n *\n * @param {WPBlockSettings} settings Registered block settings.\n *\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings ) {\n\t/** @type {WPMetaAttributeMapping} */\n\tconst metaAttributes = Object.fromEntries(\n\t\tObject.entries( settings.attributes ?? {} )\n\t\t\t.filter( ( [ , { source } ] ) => source === 'meta' )\n\t\t\t.map( ( [ attributeKey, { meta } ] ) => [ attributeKey, meta ] )\n\t);\n\tif ( Object.entries( metaAttributes ).length ) {\n\t\tsettings.edit = createWithMetaAttributeSource( metaAttributes )(\n\t\t\tsettings.edit\n\t\t);\n\t}\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n"]}