@wordpress/edit-post
Version:
Edit Post module for WordPress.
82 lines (80 loc) • 3.26 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/edit-post/src/components/browser-url/use-classic-revision-redirect.js
var use_classic_revision_redirect_exports = {};
__export(use_classic_revision_redirect_exports, {
default: () => useClassicRevisionRedirect
});
module.exports = __toCommonJS(use_classic_revision_redirect_exports);
var import_data = require("@wordpress/data");
var import_core_data = require("@wordpress/core-data");
var import_editor = require("@wordpress/editor");
var import_element = require("@wordpress/element");
var import_url = require("@wordpress/url");
var import_lock_unlock = require("../../lock-unlock.cjs");
function useClassicRevisionRedirect() {
const registry = (0, import_data.useRegistry)();
const { disableVisualRevisions, currentRevisionId, postType, postId } = (0, import_data.useSelect)((select) => {
const editor = select(import_editor.store);
return {
disableVisualRevisions: !!editor.getEditorSettings().disableVisualRevisions,
currentRevisionId: (0, import_lock_unlock.unlock)(editor).getCurrentRevisionId(),
postType: editor.getCurrentPostType(),
postId: editor.getCurrentPostId()
};
}, []);
const hasClassicRevisionScreen = ![
"wp_template",
"wp_template_part"
].includes(postType);
(0, import_element.useEffect)(() => {
if (!disableVisualRevisions || !hasClassicRevisionScreen || !currentRevisionId || !postType || !postId) {
return;
}
let cancelled = false;
registry.resolveSelect(import_core_data.store).getRevision("postType", postType, postId, currentRevisionId, {
context: "edit",
_fields: "id"
}).then((revision) => {
if (cancelled || !revision) {
return;
}
const editor = registry.select(import_editor.store);
const isStillSelected = !!editor.getEditorSettings().disableVisualRevisions && editor.getCurrentPostType() === postType && String(editor.getCurrentPostId()) === String(postId) && (0, import_lock_unlock.unlock)(editor).getCurrentRevisionId() === currentRevisionId;
if (!isStillSelected) {
return;
}
window.location.replace(
(0, import_url.addQueryArgs)("revision.php", {
revision: currentRevisionId
})
);
});
return () => {
cancelled = true;
};
}, [
disableVisualRevisions,
hasClassicRevisionScreen,
currentRevisionId,
postType,
postId,
registry
]);
}
//# sourceMappingURL=use-classic-revision-redirect.cjs.map