UNPKG

@wordpress/editor

Version:
103 lines (101 loc) 3.94 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/editor/src/components/provider/use-autosave-notice.js var use_autosave_notice_exports = {}; __export(use_autosave_notice_exports, { default: () => useAutosaveNotice }); module.exports = __toCommonJS(use_autosave_notice_exports); var import_element = require("@wordpress/element"); var import_data = require("@wordpress/data"); var import_i18n = require("@wordpress/i18n"); var import_notices = require("@wordpress/notices"); var import_url = require("@wordpress/url"); var import_store = require("../../store/index.cjs"); var import_lock_unlock = require("../../lock-unlock.cjs"); var import_use_entity_contains_snapshot = __toESM(require("./use-entity-contains-snapshot.cjs")); function showAutosaveExistsNotice({ autosave, createWarningNotice, registry, setCurrentRevisionId }) { const autosaveId = Number((0, import_url.getQueryArg)(autosave.editLink, "revision")); createWarningNotice( (0, import_i18n.__)( "There is an autosave of this post that is more recent than the version below." ), { id: "autosave-exists", actions: [ { label: (0, import_i18n.__)("View the autosave"), ...autosaveId ? { onClick: () => { const { disableVisualRevisions } = registry.select(import_store.store).getEditorSettings(); if (disableVisualRevisions) { window.location.href = autosave.editLink; return; } setCurrentRevisionId(autosaveId); } } : { url: autosave.editLink } } ] } ); } function useAutosaveNotice({ post, recovery, settings }) { const registry = (0, import_data.useRegistry)(); const { createWarningNotice } = (0, import_data.useDispatch)(import_notices.store); const { setCurrentRevisionId } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store)); const snapshotStatus = (0, import_use_entity_contains_snapshot.default)({ postType: post.type, postId: post.id, snapshot: recovery ? void 0 : settings.autosave?.crdtSnapshot }); (0, import_element.useLayoutEffect)(() => { if (recovery || !settings.autosave) { return; } if ("present" === snapshotStatus) { return; } if ("pending" === snapshotStatus) { return; } showAutosaveExistsNotice({ autosave: settings.autosave, createWarningNotice, registry, setCurrentRevisionId }); }, [snapshotStatus]); } //# sourceMappingURL=use-autosave-notice.cjs.map