/*!
 * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
 */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.revisionHistoryAdapter=t())}(self,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var r in i)e.o(i,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:i[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>r});const i=class{constructor(e){this.editor=e,this.elementId=null,void 0!==this.editor.sourceElement&&(this.elementId=this.editor.sourceElement.dataset.ckeditor5PremiumElementId)}processCollaborationCommandDisable(e){if(!this.isCollaborationDisabled())return!1;const t=this.editor.commands._commands.get(e);return void 0===t||t.forceDisabled("premium-features-module"),!0}processRevisionDisable(){return!!this.isCollaborationDisabled()&&(this.editor.plugins.has("RevisionTracker")&&(this.editor.plugins.get("RevisionTracker").isEnabled=!1),!0)}isCollaborationDisabled(){return void 0!==drupalSettings.ckeditor5Premium&&void 0!==drupalSettings.ckeditor5Premium.disableCollaboration&&!0===drupalSettings.ckeditor5Premium.disableCollaboration}getEditorParentContainer(e){let t=document.getElementById(e);for(;t&&void 0!==t&&void 0!==t.classList&&!t.classList.contains("ck-editor-container");)t=t.parentElement;return t&&void 0!==t?t.parentElement:null}getSourceDataSelector(e){return{trackChanges:".track-changes",comments:".comments",revisionHistory:".revision-history",revisionHistoryContainer:".revision-history-container",resolvedSuggestionsComments:".resolved-suggestions-comments"}[e]+"-data"+`[data-ckeditor5-premium-element-id="${this.elementId}"]`}};const r={RevisionHistoryAdapter:class{constructor(e){this.editor=e,this.storage=new i(e)}static get pluginName(){return"RevisionHistoryAdapter"}static get requires(){return["RevisionHistory","RevisionTracker"]}afterInit(){if(this.storage.processRevisionDisable())return;if(void 0===drupalSettings.ckeditor5Premium)return;const e=drupalSettings.ckeditor5Premium.addRevisionOnSubmit??!1,t=this.editor.config._config.revisionHistory;let i=document.querySelector(this.storage.getSourceDataSelector("revisionHistoryContainer"));null===i&&(i=t.viewerEditorElement.parentNode),t.viewerContainer=i,t.viewerEditorElement=i.querySelector(".revision-viewer-editor"),t.viewerSidebarContainer=i.querySelector(".revision-viewer-sidebar"),t.editorContainer=i.parentNode.querySelector(".ck-editor-premium-wrapper").parentNode;const r=this.editor.plugins.get("RevisionHistory"),o=this.editor.plugins.get("RevisionTracker"),s=document.querySelector(this.storage.getSourceDataSelector("revisionHistory")),n=JSON.parse(s.value);let a=!1;for(const e of n){e.attributes.new_draft_req&&(a=!0,delete e.attributes.new_draft_req);r.addRevisionData(e).on("change",((e,t,i,n)=>{this.updateStorage(r,o,s,!1)}))}a&&setTimeout((()=>{this.updateStorage(r,o,s,e)}),10);const d=this.editor.sourceElement.closest("form");d.addEventListener("submit",(t=>{this.updateStorage(r,o,s,e)})),d.addEventListener("click",(e=>{0===e.pointerType.length&&r.isRevisionViewerOpen&&e.preventDefault()})),this.editor.model.document.on("change:data",(()=>{this.updateStorage(r,o,s,!1)})),this.handleRevisionHistoryActiveClass(t)}async updateStorage(e,t,i,r){await t.update(),r&&await t.saveRevision({name:"Entity save"}),i.value=JSON.stringify(e.getRevisions({toJSON:!0}))}handleRevisionHistoryActiveClass(e){new IntersectionObserver((function(t){0==t[0].intersectionRatio?e.editorContainer.parentElement.classList.add("revision-history-active"):e.editorContainer.parentElement.classList.remove("revision-history-active")}),{root:document.documentElement}).observe(e.editorContainer)}}};return t=t.default})()));
