UNPKG

@wordpress/editor

Version:
70 lines (59 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts"); var _data = require("@wordpress/data"); var _blocks = require("@wordpress/blocks"); /** * WordPress dependencies */ function SaveShortcut({ resetBlocksOnSave }) { const { resetEditorBlocks, savePost } = (0, _data.useDispatch)('core/editor'); const { isEditedPostDirty, getPostEdits } = (0, _data.useSelect)(select => { const { isEditedPostDirty: _isEditedPostDirty, getPostEdits: _getPostEdits } = select('core/editor'); return { isEditedPostDirty: _isEditedPostDirty, getPostEdits: _getPostEdits }; }, []); (0, _keyboardShortcuts.useShortcut)('core/editor/save', event => { event.preventDefault(); // TODO: This should be handled in the `savePost` effect in // considering `isSaveable`. See note on `isEditedPostSaveable` // selector about dirtiness and meta-boxes. // // See: `isEditedPostSaveable` if (!isEditedPostDirty()) { return; } // The text editor requires that editor blocks are updated for a // save to work correctly. Usually this happens when the textarea // for the code editors blurs, but the shortcut can be used without // blurring the textarea. if (resetBlocksOnSave) { const postEdits = getPostEdits(); if (postEdits.content && typeof postEdits.content === 'string') { const blocks = (0, _blocks.parse)(postEdits.content); resetEditorBlocks(blocks); } } savePost(); }, { bindGlobal: true }); return null; } var _default = SaveShortcut; exports.default = _default; //# sourceMappingURL=save-shortcut.js.map