"use strict";(self.webpackChunkcollab_learning_extension=self.webpackChunkcollab_learning_extension||[]).push([[988],{4988:(t,e,s)=>{s.r(e),s.d(e,{Maintainer:()=>a,RootObserver:()=>l});var i=s(2206),r=Object.defineProperty,h=(t,e,s)=>(((t,e,s)=>{e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s);class a{constructor(t,e){h(this,"_transact"),h(this,"_objects"),this._transact=e,this._objects=t}addObject(t){this._transact((()=>{this.byId.set(t.id,new i.Map(Object.entries(t))),this.allIds.push([t.id])}))}deleteObject(t,e){this._transact((()=>{const s=this.getObjectAsJson(t);void 0!==s&&(this.byId.has(t)&&(this.byId.delete(t),this.allIds.delete(this.getArrayIndex(t),1)),void 0!==e&&Object.entries(s).forEach((([t,s])=>{Array.isArray(s)?s.forEach((s=>{e(t,s)})):e(t,s)})))}))}changeObject(t){const e=this.getObject(t.id);void 0!==e&&this._transact((()=>{Object.entries(t).forEach((([t,s])=>{e.get(t)!==s&&e.set(t,s)}))}))}swapObjectPosition(t,e){if(t===e||e<0||e>this.allIds.length-1)return;const s=this.allIds.toArray(),i=s[t];s.splice(t,1),s.splice(e,0,i),this._transact((()=>{this.allIds.delete(0,this.allIds.length),this.allIds.push(s)}))}addToPropertyArray(t,e,s){const i=this.getObject(t);void 0!==i&&i.set(e,[...i.get(e),s])}removeFromPropertyArray(t,e,s,i){const r=this.getObject(t);void 0!==r&&this._transact((()=>{r.set(e,r.get(e).filter((t=>t!==s))),null==i||i()}))}swapInPropertyArray(t,e,s,i){const r=this.getObject(t);if(void 0===r)return;const h=structuredClone(r.get(e));if(s===i||i<0||i>h.length-1)return;const a=h[s];h.splice(s,1),h.splice(i,0,a),r.set(e,h)}getObject(t){return this.byId.get(t)}getObjectAsJson(t){var e;return structuredClone(null==(e=this.getObject(t))?void 0:e.toJSON())}get byId(){return this._objects.get("byId")}get allIds(){return this._objects.get("allIds")}getArrayIndex(t){return this._objects.get("allIds").toArray().indexOf(t)}}class d{constructor(t){h(this,"documentIdentifier"),h(this,"_unobserve",(()=>{})),this.documentIdentifier=t}}class c extends d{constructor(t,e,s){super(s),h(this,"dispose",(()=>{this._unobserve()})),h(this,"dispatch",(t=>{0===t.path.length&&t.keys.size>0&&t.keys.forEach(((e,s)=>{"update"===e.action&&this._updatePropertyDispatcher({id:t.target.get("id"),key:s,value:t.target.get(s)})}))})),h(this,"_updatePropertyDispatcher"),t.observe(this.dispatch.bind(this)),this._unobserve=()=>{t.unobserve(this.dispatch)},this._updatePropertyDispatcher=e}}class n extends d{constructor(t,e,s,i){super(),h(this,"dispose",(()=>{this._unobserve(),this._objectObservers.forEach((t=>{t.dispose()}))})),h(this,"dispatch",(t=>{0===t.path.length&&t.keys.size>0&&t.keys.forEach(((e,s)=>{"add"===e.action?(this._addDispatcher(structuredClone(t.target.get(s).toJSON())),this._objectObservers.set(s,new c(t.target.get(s),this._updatePropertyDispatcher))):"delete"===e.action&&(this._deleteDispatcher(s),this._objectObservers.delete(s))}))})),h(this,"_addDispatcher"),h(this,"_deleteDispatcher"),h(this,"_updatePropertyDispatcher"),h(this,"_objectObservers",new Map),t.observe(this.dispatch.bind(this)),this._unobserve=()=>{t.unobserve(this.dispatch)},this._addDispatcher=e,this._deleteDispatcher=s,this._updatePropertyDispatcher=i,t.forEach(((t,e)=>{this._objectObservers.set(e,new c(t,this._updatePropertyDispatcher))}))}}class o{constructor(t,e){h(this,"dispatch",(t=>{t.delta[0].delete===t.target.length&&Array.isArray(t.delta[1].insert)&&t.delta[1].insert.length===t.target.length&&(console.log("Swap occurred"),this._allIdsDispatcher(t.target.toArray()))})),h(this,"dispose",(()=>{this._unobserve()})),h(this,"_unobserve"),h(this,"_allIdsDispatcher"),this._allIdsDispatcher=e,t.observe(this.dispatch.bind(this)),this._unobserve=()=>{t.unobserve(this.dispatch)}}}class l extends d{constructor(t,e){super(e),h(this,"dispose",(()=>{var t;this._unobserve(),null==(t=this._byIdObserver)||t.dispose()})),h(this,"dispatch",(t=>{0===t.path.length&&(t.target.get("byId")&&void 0===this._byIdObserver&&(this._byIdObserver=new n(t.target.get("byId"),(t=>{this.addDispatcher({item:t,documentIdentifier:this.documentIdentifier})}),(t=>{this.deleteDispatcher({id:t,documentIdentifier:this.documentIdentifier})}),(t=>{this.updatePropertyDispatcher({...t,documentIdentifier:this.documentIdentifier})}))),t.target.get("allIds")&&void 0===this._allIdsObserver&&(this._allIdsObserver=new o(t.target.get("allIds"),(t=>{this.allIdsDispatcher({ids:t,documentIdentifier:this.documentIdentifier})}))),this.rootDispatcher({state:structuredClone(t.target.toJSON()),documentIdentifier:this.documentIdentifier}))})),h(this,"_byIdObserver"),h(this,"_allIdsObserver"),t.observe(this.dispatch.bind(this)),this._unobserve=()=>{t.unobserve(this.dispatch)}}}}}]);