/*!
 * 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.trackChangesAdapter=t())}(self,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>s});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 s={TrackChangesAdapter:class{trackedSuggestion;constructor(e){this.editor=e,this.storage=new i(e)}static get pluginName(){return"TrackChangesAdapter"}static get requires(){return["TrackChanges","Comments","TrackChangesAdapter"]}afterInit(){if(!this.editor.plugins.has("Comments")||!this.editor.plugins.has("TrackChanges"))return;if(this.storage.processCollaborationCommandDisable("trackChanges"))return;const e=this.editor.plugins.get("TrackChanges"),t=document.querySelector(this.storage.getSourceDataSelector("trackChanges"));if(!t||""==t.value)return;this.editor.on("ready",(()=>{let e=this.editor.sourceElement.dataset.editorActiveTextFormat,t=drupalSettings.ckeditor5Premium.tracking_changes.default_state;void 0!==t[e]&&t[e]&&this.editor.execute("trackChanges")})),this.trackedSuggestion=new Map;const i=JSON.parse(t.value);for(const t of i)e.addSuggestion(t),this.attachSuggestionEvents(e.getSuggestion(t.id));this.editor.sourceElement.closest("form").addEventListener("submit",(()=>{this.updateStorage(e,t)}))}updateStorage(e,t){var i=e.getSuggestions({skipNotAttached:!1});for(let e in i)null==i[e].head||null==i[e].next&&null==i[e].previous||i[e].setAttribute("head",i[e].head.id),this.trackedSuggestion.has(i[e].id)?1==i[e].isInContent?i[e].removeAttribute("status"):void 0===i[e].attributes.status&&this.trackedSuggestion.delete(i[e].id):0!=i[e].isInContent?this.attachSuggestionEvents(i[e]):this.editor.model.document.fire("trackchanges:change:data");t.value=JSON.stringify(Array.from(this.trackedSuggestion.values()))}attachSuggestionEvents(e){this.trackedSuggestion.set(e.id,e);var t=this,i=function(e){let i=t.trackedSuggestion.get(e.source.id);"accept"!==e.name&&"discard"!==e.name||t.updateSuggestionCommentsData(e),void 0!==i&&(void 0!==i.attributes&&void 0!==i.attributes.key?i.setAttribute("status",e.name):t.trackedSuggestion.delete(e.source.id))};e.on("accept",i,{priority:"highest"}),e.on("discard",i,{priority:"highest"})}updateSuggestionCommentsData(e){const t=this.editor.plugins.get("CommentsRepository"),i=document.querySelector(this.storage.getSourceDataSelector("resolvedSuggestionsComments"));let s=e.source.id,r=i.value;if(void 0===s||!s)return;r||(r=JSON.stringify([]));let o=Array.from(JSON.parse(r)),a=t.getCommentThread(s).toJSON();!o.some((e=>e.threadId===a.threadId))&&a.comments.length&&(o.push(a),i.value=JSON.stringify(o))}}};return t=t.default})()));
