/** * Native WordPress post-lock coordinator for live FrontEdit sessions. * * Reads: SFE.Api.apiCall, SFE.ManagerData.postId * Exposes: SFE.PostLockManager { beginLockClaim, ensureLock, handleLockedError } */ (function() { 'use strict'; window.MWP = window.MWP || {}; window.MWP.SFE = window.MWP.SFE || {}; const SFE = window.MWP.SFE; let ownsLock = false; let refreshTimer = null; let pendingClaim = null; /** * Prevent editor and draft-preview Escape handlers from closing an active * editing session while the post-lock decision is on screen. * * Window capture runs before the document-level editor lifecycle handlers. * * @param {KeyboardEvent} event Keyboard event. * @returns {void} */ window.addEventListener('keydown', (event) => { if ( event.key === 'Escape' && document.querySelector('.mwp-sfe-post-lock-modal.is-open') ) { event.preventDefault(); event.stopImmediatePropagation(); } }, true); function escapeHtml(value) { return String(value).replace(/[&<>"']/g, (char) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]); } function showLockModal(owner = {}) { return new Promise((resolve) => { const modal = document.createElement('div'); modal.className = 'mwp-sfe-post-lock-modal is-open'; modal.setAttribute('data-mwp-sfe-control', 'post-lock-modal'); modal.innerHTML = `
${escapeHtml(owner.name || 'Another user')} is currently working on this post, which means you cannot make changes, unless you take over.
If you take over, the other user will lose editing control to the post, but their changes will be saved.