@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
@@ -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,IAAAA,UANK;AAOLC,IAAAA,QAPK;AAQLC,IAAAA,WARK;AASLC,IAAAA;AATK,MAUF,qBACDC,MAAF,IAAc;AAAA;;AACb,UAAM;AACLC,MAAAA,eADK;AAELC,MAAAA,sBAFK;AAGLC,MAAAA,sBAHK;AAILC,MAAAA,iBAJK;AAKLC,MAAAA,YALK;AAMLC,MAAAA,oBANK;AAOLC,MAAAA,cAPK;AAQLC,MAAAA,gBARK;AASLC,MAAAA;AATK,QAUFT,MAAM,CAAEU,YAAF,CAVV;AAYA,WAAO;AACNnB,MAAAA,YAAY,EAAEiB,gBAAgB,EADxB;AAENhB,MAAAA,OAAO,EAAEP,YAAY,IAAImB,iBAAiB,EAFpC;AAGNX,MAAAA,KAAK,EAAEQ,eAAe,EAHhB;AAINP,MAAAA,SAAS,EAA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AAY,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,YADK;AAELC,IAAAA,OAFK;AAGLC,IAAAA,KAHK;AAILC,IAAAA,SAJK;AAKLC,IAAAA,WALK;AAMLC,IAAAA,UANK;AAOLC,IAAAA,QAPK;AAQLC,IAAAA,WARK;AASLC,IAAAA;AATK,MAUF,qBACDC,MAAF,IAAc;AAAA;;AACb,UAAM;AACLC,MAAAA,eADK;AAELC,MAAAA,sBAFK;AAGLC,MAAAA,sBAHK;AAILC,MAAAA,iBAJK;AAKLC,MAAAA,YALK;AAMLC,MAAAA,oBANK;AAOLC,MAAAA,cAPK;AAQLC,MAAAA,gBARK;AASLC,MAAAA;AATK,QAUFT,MAAM,CAAEU,YAAF,CAVV;AAYA,WAAO;AACNnB,MAAAA,YAAY,EAAEiB,gBAAgB,EADxB;AAENhB,MAAAA,OAAO,EAAEN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AAK,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,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,gCAAvB,CAFqB,EAGrBX,IAHqB,CAAtB;AAKA,SAAO,qBACH,GAAG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KA;;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 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,E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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,MAA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cesContent":["/**\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,KAAF,EAASC,QAAT,IAAsB,uBAAUP,WAAV,CAA5B;AACA,QAAM,CAAEQ,OAAF,EAAWC,UAAX,IAA0B,uBAAU,KAAV,CAAhC;AACA,QAAMC,UAAU,GAAG,4BAAeX,cAAf,CAAnB;AACA,QAAMY,QAAQ,GAAG,sBAAjB;;AAEA,MAAK,CAAEH,OAAF,IAAaF,KAAK,KAAKN,WAA5B,EAA0C;AACzCO,IAAAA,QAAQ,CAAEP,WAAF,CAAR;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMY,QAAQ,GAAKC,KAAF,IAAa;AAC7B,UAAMC,QAAQ,GAAGD,KAAK,CAACE,MAAN,CAAaT,KAA9B;AACAF,IAAAA,QAAQ,CAAE;AAAEY,MAAAA,OAAO,EAAEF;AAAX,KAAF,CAAR;AACAP,IAAAA,QAAQ,CAAEO,QAAF,CAAR;AACAL,IAAAA,UAAU,CAAE,IAAF,CAAV;AACAE,IAAAA,QAAQ,CAACM,OAAT,GAAmBH,QAAnB;AACA,GAND;AAQA;AACD;AACA;AACA;AACA;;;AACC,QAAMI,WAAW,GAAG,MAAM;AACzB,QAAKV,OAAL,EAAe;AACd,YAAMW,MAAM,GAAG,mBAAOb,KAAP,CAAf;AACAD,MAAAA,iBAAiB,CAAEc,MAAF,CAAjB;AACAV,MAAAA,UAAU,CAAE,KAAF,CAAV;AACA;AACD,GAND,CAzCwC,CAiDxC;;;AACA,0BAAW,MAAM;AAChB,WAAO,MAAM;AACZ,UAAKE,QAAQ,CAACM,OAAd,EAAwB;AACvB,cAAME,MAAM,GAAG,mBAAOR,QAAQ,CAACM,OAAhB,CAAf;AACAZ,QAAAA,iBAAiB,CAAEc,MAAF,CAAjB;AACA;AACD,KALD;AAMA,GAPD,EAOG,EAPH;AASA,SACC,qDACC,4BAAC,0BAAD;AACC,IAAA,EAAE,EAAC,OADJ;AAEC,IAAA,OAAO,EAAI,gBAAgBT,UAAY;AAFxC,KAIG,cAAI,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,CAAnB;AACA,QAAM;AAAEE,IAAAA,OAAF;AAAWC,IAAAA,MAAX;AAAmBC,IAAAA,IAAnB;AAAyBC,IAAAA;AAAzB,MAAgC,qBAAaC,MAAF,IAAc;AAC9D,UAAM;AAAEC,MAAAA;AAAF,QAA4BD,MAAM,CAAEE,eAAF,CAAxC;AACA,UAAM;AAAEC,MAAAA,kBAAF;AAAsBC,MAAAA;AAAtB,QAA2CJ,MAAM,CAAEK,YAAF,CAAvD;;AACA,UAAMC,KAAK,GAAGH,kBAAkB,EAAhC;;AACA,UAAMI,GAAG,GAAGH,gBAAgB,EAA5B;;AACA,UAAMI,YAAY,GAAGP,qBAAqB,CAAE,UAAF,EAAcK,KAAd,EAAqBC,GAArB,CAA1C;AAEA,WAAO;AACNX,MAAAA,OAAO,EAAEY,YAAY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\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"]}
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.__experimentalTearDownEditor = __experimentalTearDownEditor;
9
- exports.clearSelectedBlock = exports.autosave = void 0;
9
+ exports.clearSelectedBlock = exports.autosave = exports.__unstableSaveForPreview = void 0;
10
10
  exports.createUndoLevel = createUndoLevel;
11
11
  exports.insertDefaultBlock = exports.insertBlocks = exports.insertBlock = exports.hideInsertionPoint = exports.exitFormattedText = exports.enterFormattedText = exports.enablePublishSidebar = exports.editPost = exports.disablePublishSidebar = void 0;
12
12
  exports.lockPostAutosaving = lockPostAutosaving;
@@ -37,6 +37,8 @@ var _coreData = require("@wordpress/core-data");
37
37
 
38
38
  var _blockEditor = require("@wordpress/block-editor");
39
39
 
40
+ var _hooks = require("@wordpress/hooks");
41
+
40
42
  var _preferences = require("@wordpress/preferences");
41
43
 
42
44
  var _constants = require("./constants");
@@ -220,11 +222,18 @@ const savePost = (options = {}) => async ({
220
222
  options
221
223
  });
222
224
  await registry.dispatch(_coreData.store).saveEntityRecord('postType', previousRecord.type, edits, options);
225
+ let error = registry.select(_coreData.store).getLastEntitySaveError('postType', previousRecord.type, previousRecord.id);
226
+
227
+ if (!error) {
228
+ await (0, _hooks.applyFilters)('editor.__unstableSavePost', Promise.resolve(), options).catch(err => {
229
+ error = err;
230
+ });
231
+ }
232
+
223
233
  dispatch({
224
234
  type: 'REQUEST_POST_UPDATE_FINISH',
225
235
  options
226
236
  });
227
- const error = registry.select(_coreData.store).getLastEntitySaveError('postType', previousRecord.type, previousRecord.id);
228
237
 
229
238
  if (error) {
230
239
  const args = (0, _noticeBuilder.getNotificationArgumentsForSaveFail)({
@@ -346,12 +355,37 @@ const autosave = ({
346
355
  });
347
356
  }
348
357
  };
358
+
359
+ exports.autosave = autosave;
360
+
361
+ const __unstableSaveForPreview = ({
362
+ forceIsAutosaveable
363
+ }) => async ({
364
+ select,
365
+ dispatch
366
+ }) => {
367
+ if ((forceIsAutosaveable || select.isEditedPostAutosaveable()) && !select.isPostLocked()) {
368
+ const isDraft = ['draft', 'auto-draft'].includes(select.getEditedPostAttribute('status'));
369
+
370
+ if (isDraft) {
371
+ await dispatch.savePost({
372
+ isPreview: true
373
+ });
374
+ } else {
375
+ await dispatch.autosave({
376
+ isPreview: true
377
+ });
378
+ }
379
+ }
380
+
381
+ return select.getEditedPostPreviewLink();
382
+ };
349
383
  /**
350
384
  * Action that restores last popped state in undo history.
351
385
  */
352
386
 
353
387
 
354
- exports.autosave = autosave;
388
+ exports.__unstableSaveForPreview = __unstableSaveForPreview;
355
389
 
356
390
  const redo = () => ({
357
391
  registry