vdc-editor 0.1.308 → 0.1.309

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { A as i, b as o, a as t, D as r, c as E, E as d, R as p, S, g as u, d as n, S as C, j as H, i as L, k as l, n as T, u as _, e as f, h as g, f as m } from "./index-Chb9-Wmq.mjs";
1
+ import { A as i, b as o, a as t, D as r, c as E, E as d, R as p, S, g as u, d as n, S as C, j as H, i as L, k as l, n as T, u as _, e as f, h as g, f as m } from "./index-ChtHL5W7.mjs";
2
2
  import "@vueuse/core";
3
3
  export {
4
4
  i as ArticleCompareEditor,
@@ -336,7 +336,7 @@ ${c}`:u)}else throw a},onCacheKey:a=>fz(e,n,a)}}function nW(t){if(Oe(t))return t
336
336
  `+s):r.stack=s}catch{}}throw r}}_request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=Aa(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&Ch.assertOptions(r,{silentJSONParsing:qo.transitional(qo.boolean),forcedJSONParsing:qo.transitional(qo.boolean),clarifyTimeoutError:qo.transitional(qo.boolean)},!1),i!=null&&(de.isFunction(i)?n.paramsSerializer={serialize:i}:Ch.assertOptions(i,{encode:qo.function,serialize:qo.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Ch.assertOptions(n,{baseUrl:qo.spelling("baseURL"),withXsrfToken:qo.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let a=s&&de.merge(s.common,s[n.method]);s&&de.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=lr.concat(a,s);const l=[];let u=!0;this.interceptors.request.forEach(function(b){typeof b.runWhen=="function"&&b.runWhen(n)===!1||(u=u&&b.synchronous,l.unshift(b.fulfilled,b.rejected))});const c=[];this.interceptors.response.forEach(function(b){c.push(b.fulfilled,b.rejected)});let f,p=0,m;if(!u){const v=[oE.bind(this),void 0];for(v.unshift.apply(v,l),v.push.apply(v,c),m=v.length,f=Promise.resolve(n);p<m;)f=f.then(v[p++],v[p++]);return f}m=l.length;let g=n;for(p=0;p<m;){const v=l[p++],b=l[p++];try{g=v(g)}catch(w){b.call(this,w);break}}try{f=oE.call(this,g)}catch(v){return Promise.reject(v)}for(p=0,m=c.length;p<m;)f=f.then(c[p++],c[p++]);return f}getUri(e){e=Aa(this.defaults,e);const n=Yk(e.baseURL,e.url,e.allowAbsoluteUrls);return Hk(n,e.params,e.paramsSerializer)}};de.forEach(["delete","get","head","options"],function(e){Ma.prototype[e]=function(n,r){return this.request(Aa(r||{},{method:e,url:n,data:(r||{}).data}))}}),de.forEach(["post","put","patch"],function(e){function n(r){return function(s,a,l){return this.request(Aa(l||{},{method:e,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}Ma.prototype[e]=n(),Ma.prototype[e+"Form"]=n(!0)});let RJ=class mT{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const a=new Promise(l=>{r.subscribe(l),s=l}).then(i);return a.cancel=function(){r.unsubscribe(s)},a},e(function(s,a,l){r.reason||(r.reason=new jl(s,a,l),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const e=new AbortController,n=r=>{e.abort(r)};return this.subscribe(n),e.signal.unsubscribe=()=>this.unsubscribe(n),e.signal}static source(){let e;return{token:new mT(function(i){e=i}),cancel:e}}};function DJ(t){return function(n){return t.apply(null,n)}}function PJ(t){return de.isObject(t)&&t.isAxiosError===!0}const Sb={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Sb).forEach(([t,e])=>{Sb[e]=t});function aE(t){const e=new Ma(t),n=_k(Ma.prototype.request,e);return de.extend(n,Ma.prototype,e,{allOwnKeys:!0}),de.extend(n,e,null,{allOwnKeys:!0}),n.create=function(i){return aE(Aa(t,i))},n}const sn=aE(Fc);sn.Axios=Ma,sn.CanceledError=jl,sn.CancelToken=RJ,sn.isCancel=qk,sn.VERSION=iE,sn.toFormData=gh,sn.AxiosError=ut,sn.Cancel=sn.CanceledError,sn.all=function(e){return Promise.all(e)},sn.spread=DJ,sn.isAxiosError=PJ,sn.mergeConfig=Aa,sn.AxiosHeaders=lr,sn.formToJSON=t=>Wk(de.isHTMLForm(t)?new FormData(t):t),sn.getAdapter=rE.getAdapter,sn.HttpStatusCode=Sb,sn.default=sn;const{Axios:wde,AxiosError:xde,CanceledError:Cde,isCancel:kde,CancelToken:Ede,VERSION:Sde,all:_de,Cancel:Tde,isAxiosError:Ade,spread:Mde,toFormData:Ode,AxiosHeaders:Bde,HttpStatusCode:Ide,formToJSON:Lde,getAdapter:Rde,mergeConfig:Dde}=sn;function VJ(t){let e=t;for(;e&&e!==document.body;){if(e.nodeType===1){const n=e;if(n.id==="editor-panel")return n}e=e.parentNode}return null}const Hc=t=>{if(!t)return!0;const e=document.createElement("div");return e.innerHTML=t,e?.textContent?.trim()===""},FJ=t=>{if(!t)return"";const{from:e,to:n}=t.state.selection,r=t.state.doc.cut(e,n),s=Ir.fromSchema(t.schema).serializeFragment(r.content),a=document.createElement("div");return a.appendChild(s),a.innerHTML},$J=t=>/<\/?[a-z][\s\S]*>/i.test(t);var ur=(t=>(t.TOGGLE_SUPER_TEXT="toggle-super-text",t.SUPER_TEXT_UPDATE_POSITION="SUPER_TEXT_UPDATE_POSITION",t.RENDER_SUPER_TEXT="RENDER_SUPER_TEXT",t.SUPER_VIEW_PAGE="SUPER_VIEW_PAGE",t.INCREASE_DECREASE_FONTSIZE="increase-decrease-fontsize",t))(ur||{});const lE=8;function HJ(t,e){const n=o.ref(!1);let r=!1,i=null,s=null,a=null,l=null,u=0,c=0;function f(C){const E=C.cloneNode(!0);return E.style.position="fixed",E.style.pointerEvents="none",E.style.opacity="0.9",E.style.zIndex="9999",E.style.transform="translate(-50%, -50%)",E.style.left="0px",E.style.top="0px",document.body.appendChild(E),E}function p(){s&&s.parentElement&&s.parentElement.removeChild(s),s=null}function m(){try{if(typeof t.getPos=="function"){const C=t.getPos();if(typeof C=="number"&&C>=0)return C}}catch{}return null}function g(C,E){n.value||(l=m(),document.body.style.userSelect="none",document.body.style.touchAction="none",E&&(s=f(E),s.style.left=`${C.clientX}px`,s.style.top=`${C.clientY}px`),n.value=!0,r=!1,a=null)}function v(){i=null,l=null,a=null,r=!1,n.value=!1,p(),document.body.style.userSelect="",document.body.style.touchAction=""}function b(C){if(o.unref(e)||n.value)return;const E=C.changedTouches[0];i=E.identifier,u=E.clientX,c=E.clientY,r=!0,l=null,a=null}function w(C){if(!r&&!n.value||i===null)return;const E=Array.from(C.changedTouches).find(A=>A.identifier===i);if(!E)return;const k=E.clientX-u,T=E.clientY-c,S=k*k+T*T;if(!n.value&&r&&S>=lE*lE){const A=C.currentTarget||C.target||null;g(E,A)}if(n.value){s&&(s.style.left=`${E.clientX}px`,s.style.top=`${E.clientY}px`);try{const A=t.editor?.view;if(!A){a=null;return}const V=A.posAtCoords({left:E.clientX,top:E.clientY});V&&typeof V.pos=="number"?a=V.pos:a=null}catch{a=null}}}async function x(C){if(n.value){if(document.body.style.userSelect="",document.body.style.touchAction="",p(),n.value=!1,l===null||a===null){v();return}const E=t.editor?.view;if(!E){v();return}const k=E.state.doc.nodeAt(l);if(!k){v();return}const T=k.nodeSize,S=l,A=S+T,V=a;if(V>=S&&V<=A){v();return}let O=V;V>S&&(O=V-T);const B=E.state.doc.content.size;O<0&&(O=0),O>B&&(O=B);const F=k.type.create(k.attrs),j=E.state.tr;j.delete(S,A),j.insert(O,F),E.dispatch(j),v();return}if(r){v();return}}return{onTouchStart:b,onTouchMove:w,onTouchEnd:x}}function zJ(...t){return xy(Rm(t))}const UJ=["innerHTML"],WJ=["book-mark-node-id","book-mark-content","node-id","element-id","line-id"],jJ=o.defineComponent({__name:"SuperText",props:ta,setup(t){const e=t,n=o.ref(!1),r=o.inject("isMobile",!1),i=o.inject("showSuperElementIdColor",!1),s=o.computed(()=>!!e.node.attrs[Ne.ELEMENT_ID]),a=o.computed(()=>o.unref(i)?s.value?"":"text-red-500":""),l=o.computed(()=>e.editor.storage.superText.enable),u=ct.useEventBus(ur.RENDER_SUPER_TEXT),{onTouchStart:c,onTouchMove:f,onTouchEnd:p}=HJ(e,l),m=o.ref(null),g=o.ref(!1),v=()=>{g.value=!0},b=()=>{g.value=!1};o.watch(g,()=>{g.value&&V(m.value)});const w={mouseenter:A,mouseleave:V,dragstart:v,dragend:b},x={touchstart:c,touchmove:f,touchend:p,touchcancel:p},C=o.computed(()=>r?x:w),E=o.computed(()=>{const Y=e.getPos(),N=e.editor.state.doc.resolve(Y);for(let H=N.depth;H>0;H--){const D=N.node(H);if(D.type.name==="paragraph")return D}return null}),k=o.computed(()=>E.value?.attrs.id||""),T=o.inject("canEditSuper",o.ref(!0));function S(Y){if(Hc(Y)){O();return}const N=e.getPos(),H=e.editor?.state.doc.nodeAt(N),D=Y.trim(),{[Ne.ELEMENT_ID]:L,...W}=H?.attrs||{};e.editor?.view.dispatch(e.editor.state.tr.setNodeMarkup(N,void 0,{...W,[Ne.TEXT]:D})),requestAnimationFrame(()=>{e.editor.commands.setTextSelection(N+1),e.editor.view.focus()})}function A(Y){m.value=Y;const N=e.node.attrs[Ne.TEXT],H=e.node.attrs[Ne.ID],D=e.node.attrs[Ne.ELEMENT_ID]??null,W={lineId:Y.target.querySelector(`[node-id="${H}"]`).getAttribute("line-id"),dataId:H,text:N,elementId:D};u.emit({action:"hover",payload:W})}function V(Y){const N=e.node.attrs[Ne.ID],H=e.node.attrs[Ne.ELEMENT_ID]??null,L={lineId:Y?.target.querySelector(`[node-id="${N}"]`).getAttribute("line-id"),dataId:N,text:"",elementId:H};u.emit({action:"hover",payload:L}),m.value=null}function O(){const{getPos:Y,node:N,editor:H}=e,D=Y(),L=D+1;H.commands.deleteRange({from:D,to:L})}function B(){if(!T.value)return;const{attributes:Y}=e.editor.options.editorProps;Y&&Y.id===ir.COMMENT&&document.getElementById(ir.COMMENT)?.getAttribute(ir.DISABLE_SUPER_INPUT)==="true"||(e.editor.view.dom.blur(),n.value=!0)}function F(){e.editor.commands.setSuperTextContent(e.node.attrs[Ne.TEXT],e.node.attrs[Ne.POSITION]),e.editor.commands.toggleSuperInputMoblie()}o.watch(l,Y=>{r&&(e.editor.setEditable(!Y),Y?e.editor.view.dom.classList.add("super-text-view-mode"):e.editor.view.dom.classList.remove("super-text-view-mode"))});const j=o.computed(()=>e.node.attrs[Ne.TEXT].replace(/<p><\/p>\s*$/,"<p>&nbsp;</p>"));return(Y,N)=>{const H=mn,D=lb,L=ab,W=sb,P=ib,q=Uc;return o.openBlock(),o.createBlock(o.unref(ea),o.mergeProps({as:"span",class:o.unref(zJ)("text-inherit super-text shrink-0 inline-flex items-center justify-center",o.unref(r)&&l.value&&"block"),"data-drag-handle":"",draggable:o.unref(T)},o.toHandlers(C.value)),{default:o.withCtx(()=>[o.unref(r)&&!l.value?(o.openBlock(),o.createElementBlock("button",{key:0,class:"w-6 inline-flex justify-center rounded text-ed-red-500 active:bg-ed-accent",onClick:o.withModifiers(F,["stop"])},[o.createVNode(o.unref(Ot),{name:"fileEdit2",class:"w-5 h-5"})])):o.createCommentVNode("",!0),o.unref(r)&&l.value?(o.openBlock(),o.createElementBlock("div",{key:1,class:"super-text-view-mode-item whitespace-break-spaces wrap-anywhere",onClick:o.withModifiers(F,["stop"]),innerHTML:j.value},null,8,UJ)):o.createCommentVNode("",!0),o.unref(r)?o.createCommentVNode("",!0):(o.openBlock(),o.createBlock(P,{key:2},{default:o.withCtx(()=>[o.createVNode(D,{as:"template",class:"relative",disabled:!o.unref(T)},{default:o.withCtx(()=>[o.createVNode(H,{class:o.normalizeClass([{"pointer-events-none":!o.unref(T)},"!p-0 !m-0 !h-fit"]),variant:"ghost",onDblclick:o.withModifiers(B,["stop"])},{default:o.withCtx(()=>[o.createVNode(o.unref(Ot),{name:"fileEdit",class:o.normalizeClass(a.value)},null,8,["class"]),o.createElementVNode("div",{ref:"bookMarkRef","book-mark-node-id":e.node.attrs[o.unref(Ne).ID],"book-mark-content":e.node.attrs[o.unref(Ne).TEXT],"node-id":e.node.attrs[o.unref(Ne).ID],"element-id":e.node.attrs[o.unref(Ne).ELEMENT_ID],"line-id":k.value},null,8,WJ)]),_:1},8,["class"])]),_:1},8,["disabled"]),o.createVNode(W,null,{default:o.withCtx(()=>[o.createVNode(L,{onSelect:N[0]||(N[0]=G=>n.value=!0)},{default:o.withCtx(()=>[o.createTextVNode(o.toDisplayString(Y.$t("editor.super.edit")),1)]),_:1}),o.createVNode(L,{onSelect:O},{default:o.withCtx(()=>[o.createTextVNode(o.toDisplayString(Y.$t("editor.super.delete")),1)]),_:1})]),_:1})]),_:1})),o.unref(r)?o.createCommentVNode("",!0):(o.openBlock(),o.createBlock(q,{key:3,open:n.value,editor:e.editor,"super-text-init":e.node.attrs[o.unref(Ne).TEXT],"super-text-element-id":e.node.attrs[o.unref(Ne).ELEMENT_ID],onClose:N[1]||(N[1]=G=>n.value=!1),onSave:S},null,8,["open","editor","super-text-init","super-text-element-id"]))]),_:1},16,["class","draggable"])}}}),qJ=new ot({props:{handleKeyDown(t,e){if(e.key==="Backspace"){const{state:n,dispatch:r}=t,{$from:i}=n.selection;if(i.parentOffset===1){const l=i.nodeAfter;if(l&&l.type.name==="superText"){const u=n.tr;return u.delete(i.pos-1,i.pos),u.setSelection(Ie.create(u.doc,i.pos-1)),r(u),e.preventDefault(),!0}}const s=i.nodeBefore,a=i.nodeAfter;if(s&&s.isText&&s.text?.length===1&&a&&a.type.name==="superText"){const l=i.parent.childBefore(i.parentOffset-1).node;if(l&&l.type.name==="superText"){const u=n.tr;return u.delete(i.pos-1,i.pos),u.setSelection(Ie.create(u.doc,i.pos-1)),r(u),e.preventDefault(),!0}}}return!1}}}),KJ=new ot({appendTransaction(t,e,n){const r=new Set;let i=n.tr,s=!1;return n.doc.descendants((a,l)=>{if(a.type.name===zc){const u=a.attrs[Ne.ID];if(!u||r.has(u)){const c=$r();i=i.setNodeMarkup(l,void 0,{...a.attrs,[Ne.ID]:c}),s=!0,r.add(c)}else r.add(u)}}),s?i:null}}),zc="superText",uE={UPDATE:"superTextUpdate"},cE=Lt.create({name:"superText",inline:!0,group:"inline",selectable:!1,defining:!0,draggable:!0,addStorage(){return{enable:!0,isShowSuperInputMoblie:!1,view:!0,items:[],superInputModal:this.options.superInputModal,toggleSuperViewMobileCallBack:this.options.toggleSuperViewMobileCallBack,bottomSheetComponent:this.options.bottomSheetComponent,addToast:this.options.addToast,superTextContent:"",superTextPosition:""}},addOptions(){return{specialCharModal:null,button:({editor:t,t:e,isMobile:n})=>n?[{component:Ge,componentProps:{action:()=>{t.commands.toggleSuperInputMoblie()},isActive:()=>{},icon:"fileEdit",title:e("editor.menubar.menu.insertSuper"),tooltip:e("editor.menubar.menu.insertSuper"),customClass:"whitespace-nowrap !bg-ed-blue active:!bg-ed-blue/90 !transition-none !text-white !font-normal rounded-[3px] h-[26px] ml-auto",customClassTooltip:"ml-auto"}}]:[{component:Ge,componentProps:{action:()=>t.commands.toggleSuperTextView(),isActive:()=>t.storage.superText.enable,title:e("editor.menubar.menu.superView"),customClass:`whitespace-nowrap !text-white !font-normal rounded-[3px] h-[26px]
337
337
  ${t.storage.superText.enable?"!bg-blue-500":"!bg-gray-600"}
338
338
  `,tooltip:"수퍼 보기",customClassTooltip:"flex items-center justify-center"}}]}},addAttributes(){return{[Ne.ID]:{default:null},[Ne.TEXT]:{default:""},[Ne.POSITION]:{default:"0"},[Ne.ELEMENT_ID]:{default:""}}},addCommands(){return{toggleSuperTextView:()=>({editor:t})=>t.storage.superText.enable=!t.storage.superText.enable,toggleSuperInputMoblie:()=>({editor:t})=>t.storage.superText.bottomSheetComponent?t.storage.superText.isShowSuperInputMoblie=!t.storage.superText.isShowSuperInputMoblie:(console.error("Please configure bottomSheetComponent!"),!1),setSuperTextContent:(t,e)=>({editor:n})=>(n.storage.superText.superTextContent=t,n.storage.superText.superTextPosition=e,!!t)}},parseHTML(){return[{tag:"button.super-text"}]},renderHTML({HTMLAttributes:t}){return["button",wt(t,{class:"super-text"})]},addNodeView(){return na(jJ)},addProseMirrorPlugins(){return[new ot({appendTransaction(t,e,n){let r=n.tr,i=!1;return n.doc.descendants((s,a)=>{if(s.type.name==="superText"){const l=s.attrs[Ne.POSITION],u=String(a);l!==u&&(r=r.setNodeMarkup(a,void 0,{...s.attrs,[Ne.POSITION]:u}),i=!0)}}),i?r:null}}),new ot({filterTransaction(t,e){return t.steps.some(r=>{if(r.toJSON&&r.toJSON().stepType==="replace"){const i=r.toJSON();return i.slice&&i.slice.content&&i.slice.content.some(s=>s.type===zc)}return!1})&&t.setMeta(uE.UPDATE,!0),!0}}),qJ,KJ]}}),_b="spell-check";class GJ{get completeProofreadingDone(){return this.isInitialProofreadingDone}debouncedGetMatchAndSetDecorations=St.debounce(this.getMatchAndSetDecorations.bind(this),300);debouncedGetMatchAndSetDecorationsList=St.debounce(this.getMatchAndSetDecorationsList.bind(this),300);debouncedClickEventsListener=this.clickEventsListener.bind(this);debouncedAcceptSuggestionEventsListener=this.acceptSuggestionListener.bind(this);debouncedProofreadChangedNodes=St.debounce(this.proofreadChangedNodes.bind(this),300);proofreader;uiStrings;showSuggestionsEvent;decorationSet;editorView;isInitialProofreadingDone=!1;lastOriginalFrom=0;lastClickedDecoration=null;suggestionBox;isEnableSuggestion;isMobile;limit=1e3;docLimit;spellcheckHighlightMode;spellcheckHighlightColor;_debouncedProofreadDoc=St.debounce((e,n)=>{this.proofreadDoc(e),n&&n()},500);_debouncedHandleEnterKey=St.debounce((e,n,r)=>{this.handleEnterKey(e,n),r&&r()},500);constructor(e,n,r,i=1e3,s=Io.ERROR_TYPE,a=Qi,l){this.proofreader=e,this.uiStrings=n,this.showSuggestionsEvent=r,this.decorationSet=lt.empty,this.limit=i,this.docLimit=l,this.spellcheckHighlightMode=s,this.spellcheckHighlightColor=a,this.suggestionBox=document.createElement("div"),this.suggestionBox.id="suggestions-box",this.suggestionBox.tabIndex=0,this.isEnableSuggestion=!0,this.isMobile=!1,this.hideSuggestionBox()}getProofreader(){return this.proofreader}toggleIsEnabledSpellCheck(){this.proofreader.toggleIsEnabled()}setEnabledProofreadText(e){this.proofreader.setEnabled(e)}getIsEnabledSpellCheck(){return this.proofreader.getIsEnabled()}setDecorationSet(e){this.decorationSet=e}getDecorationSet(){return this.decorationSet}setEditorView(e){this.editorView=e}getEditorView(){return this.editorView}getSuggestionBox(){return this.suggestionBox}hideSuggestionBox(){this.suggestionBox.textContent="",this.suggestionBox.style.display="none"}setIsEnableSuggestion(e){if(this.isEnableSuggestion=e,this.isEnableSuggestion){this.addEventListenersToDecorations();return}this.hideSuggestionBox(),this.removeEventListenersFromDecorations()}setIsMobile(e){this.isMobile=e}getChangedNodesFromTransaction(e,n=!1,r=!1){const i=[],s=new Set;let a=!1;return e.steps.forEach(l=>{const u=l;if(u.from===void 0||u.to===void 0||n&&u.structure)return;u.slice?.content[0]?.type.name===zc&&(a=!0);const c=u.from-(r?1:0);let f=Math.max(u.to,u.from+(u.slice?.size||0))-(r?1:0);f>e.doc.content.size&&(f=e.doc.content.size),e.doc.nodesBetween(c,f,(p,m)=>{p&&(p.isText&&!s.has(m)&&(i.push({node:p,pos:m}),s.add(m)),p.type.name===zc&&(a=!0))})}),{changedNodes:i,isChangedSuperText:a}}debouncedProofreadDoc(e,n){this._debouncedProofreadDoc(e,n)}isSuperTextAlone(e,n){let r=!1;return e.descendants((i,s,a)=>i===n?(a&&a.type.name==="paragraph"&&a.childCount===1&&a.firstChild===n&&(r=!0),!1):!0),r}isDocExceedLimit(e){return!!(this.docLimit&&e.textContent.length>this.docLimit)}proofreadDoc(e){if(this.isDocExceedLimit(e))return;let n=[],r=0;e?.descendants((u,c)=>{if(u.isText){const f={text:u.text??"",from:c,to:c+u.nodeSize};return n[r]&&(f.text=n[r].text+f.text,f.from=n[r].from),n[r]=f,r+=1,!1}return u.type.name!==zc}),n=n.filter(Boolean);let i="",s=1;for(const{text:u,from:c,to:f}of n){const p=c-s;p>0&&(i+=Array(p+1).join(`
339
- `)),s=f,i+=u}const a=bx(i,this.limit),l=this.getMatchAndSetDecorationsList(a.map(u=>({text:u.text,originalFrom:u.offset+1})));this.editorView&&this.dispatch(this.editorView.state.tr.setMeta(Un.LOADING_TRANSACTION,!0)),l.then(()=>{this.editorView&&this.dispatch(this.editorView.state.tr.setMeta(Un.LOADING_TRANSACTION,!1))}),this.isInitialProofreadingDone=!0}async proofreadChangedNodes(e){if(this.editorView&&this.isDocExceedLimit(this.editorView.state.doc))return;const n=this.isMobile?1:2,i=e.reduce((s,a)=>{if(s.length===0)return s.push({changedNode:a,time:1}),s;const l=s[s.length-1];return a.pos===l.changedNode.pos+l.changedNode.node.nodeSize+n*(l.time-1)?(l.changedNode.node.text+=a.node.text,l.time+=1):s.push({changedNode:a,time:1}),s},[]).map(({changedNode:s})=>{const a=s.node?.textContent||"",l=s.pos;return bx(a,this.limit).map(c=>({text:c.text,originalFrom:l+c.offset}))});this.debouncedGetMatchAndSetDecorationsList(i.flat())}async getMatchAndSetDecorationsList(e){const n=e.map(r=>this.getMatchAndSetDecorations(r.text,r.originalFrom));await Promise.all(n)}async getMatchAndSetDecorations(e,n){const r=await this.proofreader.proofreadText(this.proofreader.normalizeTextForLanguage(e)),i=[];for(const l of r){const u=l.startIndex+n,c=u+l.length,f=await this.proofreader.getSuggestions(l.wrongWord),p={length:l.length,wrongWord:l.wrongWord,suggestions:f};let m="spell-error",g="";this.spellcheckHighlightMode===Io.SINGLE?g=`border-bottom: 2px solid ${this.spellcheckHighlightColor};`:m=`spell-error ${ax[l.errorType??-1]??lx}`,i.push(jt.inline(u,c,{class:m,nodeName:"span",style:g,[_b]:JSON.stringify(p)}))}const s=this.decorationSet.find(n,n+e.length);let a=this.decorationSet.remove(s);this.editorView&&(a=a.add(this.editorView.state.doc,i)),this.setDecorationSet(a),this.editorView&&this.dispatch(this.editorView.state.tr.setMeta(Un.SPELLCHECKER_TRANSACTION,!0)),this.addEventListenersToDecorations()}removeEventListenersFromDecorations(){const n=this.editorView?.domAtPos(this.lastOriginalFrom).node?.querySelectorAll("span.spell-error")||[];n.length&&n.forEach(r=>{r.removeEventListener("click",this.debouncedClickEventsListener)})}addEventListenersToDecorations(){if(this.isEnableSuggestion)try{const n=this.editorView?.domAtPos(this.lastOriginalFrom).node?.querySelectorAll("span.spell-error")||[];if(!n.length)return;n.forEach(r=>{r.addEventListener("click",this.debouncedClickEventsListener)})}catch{}}addEventListenersToSuggestionBox(){const e=this.suggestionBox.querySelectorAll("li");e.length&&e.forEach(n=>{n.addEventListener("mousedown",this.debouncedAcceptSuggestionEventsListener)})}dispatch(e){this.editorView&&this.editorView.dispatch(e)}findChangedTextNodes(e,n,r,i){if(!e.isBlock)return!1;if(!e.isTextblock)return e.descendants((u,c)=>{this.findChangedTextNodes(u,c,r,i)}),!1;const[s,a]=[n,n+e.nodeSize];if(!(s<=r&&i<=a))return;const l={node:e,pos:n};this.onNodeChanged(l.node.textContent,l.pos+1)}onNodeChanged(e,n){n!==this.lastOriginalFrom?this.getMatchAndSetDecorations(e,n):this.debouncedGetMatchAndSetDecorations(e,n),this.lastOriginalFrom=n}async clickEventsListener(e){if(!e.target)return;let n=e.target;for(;n&&!n.classList.contains("spell-error");)n=n.parentElement;if(!n||!n.classList.contains("spell-error"))return;this.lastClickedDecoration=n;const r=n.getAttribute(_b)?.trim();if(!r){console.error("No match string provided",{spellCheckerAttributes:r});return}const{length:i,wrongWord:s,suggestions:a}=JSON.parse(r),l=this.editorView?.posAtDOM(n,0)??0,u=l+i;if(this.editorView){this.addSuggestionsList(a,l,u),this.suggestionBox.style.display="";const c=VJ(n);if(!c)return;const f=n.getBoundingClientRect(),p=c.getBoundingClientRect(),m=window.getComputedStyle(c).padding,g=f.left-p.left+3-parseInt(m);let v=f.top-p.top+30-parseInt(m);this.suggestionBox.style.left=g+"px",this.suggestionBox.style.top=v+"px";const b=this.suggestionBox.getBoundingClientRect();b.bottom>p.bottom&&(v=f.top-p.top-b.height-7-parseInt(m),this.suggestionBox.style.top=v+"px"),this.showSuggestionsEvent&&this.showSuggestionsEvent(this.proofreader.normalizeTextForLanguage(s)),setTimeout(()=>{n.scrollIntoView({behavior:"smooth",block:"center"})},100)}return this.addEventListenersToSuggestionBox(),!1}acceptSuggestionListener(e){if(!e||!e.target)return;e.preventDefault(),e.stopPropagation();const n=e.target;let r=0,i=0;if(this.lastClickedDecoration&&this.editorView){const s=this.lastClickedDecoration.getAttribute(_b)?.trim();if(s){const{length:a}=JSON.parse(s);r=this.editorView.posAtDOM(this.lastClickedDecoration,0),i=r+a}}if(this.editorView&&r>=0&&i>r){this.dispatch(this.editorView.state.tr.setMeta(Un.ACCEPT_SUGGESTION,!0));const s=n.textContent||"",a=this.editorView.state.tr.insertText(s,r,i),l=r+s.length,u=Ie.create(a.doc,l);a.setSelection(u),this.dispatch(a),this.editorView.focus()}this.hideSuggestionBox(),this.lastClickedDecoration&&(this.lastClickedDecoration.removeEventListener("click",this.debouncedClickEventsListener),this.lastClickedDecoration=null)}addSuggestionsList(e,n,r){if(this.suggestionBox.textContent="",e.length>0){const i=document.createElement("ul");i.className="suggestion-list",e.forEach(s=>{const a=document.createElement("li");a.innerText=s,a.dataset.from=n+"",a.dataset.to=r+"",i.appendChild(a)}),this.suggestionBox.appendChild(i)}if(e.length===0){const i=document.createElement("b"),s=this.uiStrings&&this.uiStrings.noSuggestions?this.uiStrings.noSuggestions:"No suggestions found";i.textContent=s,this.suggestionBox.appendChild(i)}}isUndoRedo(e,n){return e.getMeta(K5.ADD_TO_HISTORY_TRANSACTION)===!1||e.getMeta(Un.APPENDED)===!0||n.isUndoRedoOperation}handleUndoRedo(e,n){const r=e.getMeta(K5.HISTORY_TRANSACTION)?.redo;if(n.isUndoRedoOperation=!1,r)return this.debouncedProofreadDoc(e.doc),this.getDecorationSet();const{changedNodes:i}=this.getChangedNodesFromTransaction(e,!0);return i.length===0?this.getDecorationSet():i.length===1?(this.debouncedProofreadChangedNodes(i),this.getDecorationSet()):(this.debouncedProofreadDoc(e.doc),this.getDecorationSet())}isTextContentChangedOrDeleted(e){let n=!1;return{isTextContentChanged:e.steps.some(i=>{const s=i.toJSON?.();return s?.stepType==="replace"&&s?.slice?.content?s.slice.content.some(a=>a.type==="paragraph"&&a.content&&a.content.length>0):s?.stepType==="replace"&&(!s.slice||!s.slice.content||s.slice.content.length===0)?(n=!0,s.from!==s.to):!1}),isDeleteAction:n}}handleEnterKey(e,n){if(n)return this.debouncedProofreadDoc(e.doc),this.getDecorationSet();const r=e.getMeta(Un.APPENDED_TRANSACTION);if(!r)return this.getDecorationSet();const s=r.steps[0].to,a=r.before.nodeAt(s-1);if(!a?.isText)return this.getDecorationSet();let l=0;return r.before.descendants((c,f)=>{c.textContent===a?.textContent&&(l=f)}),l+(a?.nodeSize||0)===s?this.getDecorationSet():(this.debouncedProofreadDoc(e.doc),this.getDecorationSet())}handleEnterKeyDebounced(e,n,r){this._debouncedHandleEnterKey(e,n,r)}}const dE=t=>{if(!t)return-1;const{from:e}=t.state.selection;let n=0;return t.state.doc.descendants((r,i)=>{r.type.name===Np&&i<e&&n++}),n},fE=t=>{const e=t.view?.dom;if(!e)return!1;const n=window.getSelection?.();if(n&&n.rangeCount){const r=n.anchorNode;if(r&&e.contains(r))return!0}return!1},pE=(t,e)=>t.map((r,i)=>({ext:r,name:r.name,originalIndex:i,order:e[r.name]})).sort((r,i)=>{const s=r.order===-1,a=i.order===-1;if(s&&!a)return 1;if(!s&&a)return-1;if(s&&a)return r.originalIndex-i.originalIndex;const l=typeof r.order=="number",u=typeof i.order=="number";return l&&u?r.order-i.order:l?-1:u?1:r.originalIndex-i.originalIndex}).map(r=>r.ext),Tb=(t,e)=>t?!!t.extensionManager.extensions.find(n=>n.name===e):!1;function hE(t,e){return e.characterCountLimit===void 0?t:t.map(n=>n.name==="base-kit"?n.configure({...n.options,characterCount:{...n.options.characterCount,limit:e.characterCountLimit}}):n)}const mE=bn(),Un={SPELLCHECKER_TRANSACTION:"spellcheckerTransaction",IS_ACTIVE_SPELLCHECK:"isActiveSpellCheck",LOADING_TRANSACTION:"loading",PREVENT_UPDATE:"preventUpdate",APPENDED:"appended",APPENDED_TRANSACTION:"appendedTransaction",ACCEPT_SUGGESTION:"acceptSuggestion",SKIP_SPELLCHECK:"skipSpellcheck",UI_EVENT:"uiEvent"},XJ={DROP:"drop"},gE=Qe.create({name:"spellchecker",addOptions(){return{proofreader:void 0,uiStrings:{noSuggestions:""},spellcheckHighlightMode:Io.ERROR_TYPE,spellcheckHighlightColor:Qi,button:({editor:t,t:e,isMobile:n})=>({component:Ge,componentProps:{action:()=>t.commands.handleActiveSpellCheck(),isActive:()=>t?.extensionStorage?.spellchecker?.spellchecker?.proofreader?.enabled||!1,icon:"SpellCheck",tooltip:"맞춤법 검사",title:n?e("editor.menubar.menu.spelling"):"",customClassTooltip:"flex items-center justify-center"}})}},addStorage(){return{didPaste:!1,spellchecker:void 0,isUndoRedoOperation:!1,pendingSpellCheck:!1,enterKeyPressed:!1}},addCommands(){return{checkSpelling:()=>({tr:t})=>(this.storage.spellchecker.proofreadDoc(t.doc),!0),selectAll:()=>({state:t,dispatch:e})=>(HM(t,e),!0),copy:()=>()=>(document.execCommand("copy"),!0),handleActiveSpellCheck:(t=!0)=>({editor:e})=>{const n=e.extensionStorage.spellchecker.spellchecker;return n.toggleIsEnabledSpellCheck(),e.view.dispatch(e.state.tr.setMeta(Un.IS_ACTIVE_SPELLCHECK,n.getIsEnabledSpellCheck())),t&&mE.setSpellCheck(n.getIsEnabledSpellCheck()),n.hideSuggestionBox(),fE(e)&&e.commands.focus(),!0},setIsEnableSuggestion:t=>()=>(this.storage.spellchecker.setIsEnableSuggestion(t),!0)}},addProseMirrorPlugins(){return[new ot({key:new Et("skipMarkPlugin"),view:e=>{const n=e.dispatch;return e.dispatch=r=>(r.steps.some(s=>s instanceof ti||s instanceof ro)&&r.setMeta(Un.SKIP_SPELLCHECK,!0),n.call(e,r)),{}}}),new ot({key:new Et("spellcheckerPlugin"),props:{decorations(e){return this.getState(e)},handlePaste:()=>{this.storage.didPaste=!0},handleClick:()=>{this.storage.spellchecker.hideSuggestionBox()},handleKeyDown:(e,n)=>((n.ctrlKey||n.metaKey)&&(n.key==="z"||n.key==="y")&&(this.storage.isUndoRedoOperation=!0,this.storage.pendingSpellCheck=!0),this.storage.enterKeyPressed&&(this.storage.pendingSpellCheck=!0),n.key==="Enter"&&(this.storage.enterKeyPressed=!0),!1)},state:{init:(e,n)=>{const r=new GJ(this.options.proofreader,this.options.uiStrings,this.options.onShowSuggestionsEvent,this.options.proofreader?.limit,this.options.spellcheckHighlightMode??Io.ERROR_TYPE,this.options.spellcheckHighlightColor??Qi,this.options.docLimit);return this.storage.spellchecker=r,r.setDecorationSet(lt.create(n.doc,[])),mE.setSpellCheck(r.getIsEnabledSpellCheck()),this.options.proofreader?.enabled&&r.proofreadDoc(n.doc),r.getDecorationSet()},apply:(e,n)=>{if(e.getMeta(Un.SKIP_SPELLCHECK))return n;const r=this.storage.spellchecker,i=e.getMeta(Un.IS_ACTIVE_SPELLCHECK);if(i!==void 0)return i?r.proofreadDoc(e.doc):r.setDecorationSet(lt.empty),r.getDecorationSet();if(e.getMeta(Un.SPELLCHECKER_TRANSACTION))return r.getDecorationSet();if(e.docChanged&&e.doc.nodeSize){const a=r.getDecorationSet().map(e.mapping,e.doc);if(r.setDecorationSet(a),e.getMeta(Un.UI_EVENT)===XJ.DROP)return r.debouncedProofreadDoc(e.doc),r.getDecorationSet();if(r.isUndoRedo(e,this.storage))return r.handleUndoRedo(e,this.storage);const{isTextContentChanged:l,isDeleteAction:u}=r.isTextContentChangedOrDeleted(e);if(u){const{changedNodes:m}=r.getChangedNodesFromTransaction(e,!1,!0);return m.length>0&&r.debouncedProofreadChangedNodes([m[0]]),r.getDecorationSet()}if(this.storage.enterKeyPressed)return r.handleEnterKeyDebounced(e,this.storage.pendingSpellCheck,()=>{this.storage.enterKeyPressed=!1,this.storage.pendingSpellCheck=!1}),r.getDecorationSet();if(this.storage.pendingSpellCheck||l)return r.debouncedProofreadDoc(e.doc,()=>{this.storage.pendingSpellCheck=!1}),r.getDecorationSet();if(e.getMeta(uE.UPDATE)||e.updated===0&&e.steps[0]?.structure===!0)return r.getDecorationSet();if(e.getMeta(Un.PREVENT_UPDATE)===!0&&e.before.textContent.length===0)return r.debouncedProofreadDoc(e.doc),r.getDecorationSet();this.storage.didPaste&&(this.storage.didPaste=!1);const{changedNodes:f,isChangedSuperText:p}=r.getChangedNodesFromTransaction(e);if(p)return r.debouncedProofreadDoc(e.doc),r.getDecorationSet();f.length>0&&r.debouncedProofreadChangedNodes(f)}return r.getDecorationSet()}},view:()=>({update:e=>{const n=this.storage.spellchecker;n.setEditorView(e),e?.dom?.parentNode?.appendChild(n.getSuggestionBox())}})})]}}),YJ=()=>{const t=o.reactive({[Bo.EDITOR_COMMENT]:{editor:null,wrongWords:[]},[Bo.EDITOR_CONTENT]:{editor:null,wrongWords:[]}});function e(x,C){t[x].editor=C}const n=o.ref(io.NO_ERROR);function r(){Object.values(t).forEach(x=>{x.wrongWords=[]})}function i(x,C){return x?io.FAIL:C?io.HAS_ERROR:io.NO_ERROR}async function s(){n.value=io.LOADING;let x=!1,C=!1;for(const[E,{editor:k}]of Object.entries(t)){if(!k)continue;const T=k?.extensionManager.extensions.find(A=>A.name==="spellchecker")?.options.proofreader.api,S=k.getText({blockSeparator:`
339
+ `)),s=f,i+=u}const a=bx(i,this.limit),l=this.getMatchAndSetDecorationsList(a.map(u=>({text:u.text,originalFrom:u.offset+1})));this.editorView&&this.dispatch(this.editorView.state.tr.setMeta(Un.LOADING_TRANSACTION,!0)),l.then(()=>{this.editorView&&this.dispatch(this.editorView.state.tr.setMeta(Un.LOADING_TRANSACTION,!1))}),this.isInitialProofreadingDone=!0}async proofreadChangedNodes(e){if(this.editorView&&this.isDocExceedLimit(this.editorView.state.doc))return;const n=[];for(const{node:i,pos:s}of e){const a=i.text??"",l=n[n.length-1];l&&s===l.endPos?(l.text+=a,l.endPos=s+a.length):n.push({pos:s,text:a,endPos:s+a.length})}const r=n.flatMap(({pos:i,text:s})=>bx(s,this.limit).map(l=>({text:l.text,originalFrom:i+l.offset})));this.debouncedGetMatchAndSetDecorationsList(r)}async getMatchAndSetDecorationsList(e){const n=e.map(r=>this.getMatchAndSetDecorations(r.text,r.originalFrom));await Promise.all(n)}async getMatchAndSetDecorations(e,n){const r=await this.proofreader.proofreadText(this.proofreader.normalizeTextForLanguage(e)),i=[];for(const l of r){const u=l.startIndex+n,c=u+l.length,f=await this.proofreader.getSuggestions(l.wrongWord),p={length:l.length,wrongWord:l.wrongWord,suggestions:f};let m="spell-error",g="";this.spellcheckHighlightMode===Io.SINGLE?g=`border-bottom: 2px solid ${this.spellcheckHighlightColor};`:m=`spell-error ${ax[l.errorType??-1]??lx}`,i.push(jt.inline(u,c,{class:m,nodeName:"span",style:g,[_b]:JSON.stringify(p)}))}const s=this.decorationSet.find(n,n+e.length);let a=this.decorationSet.remove(s);this.editorView&&(a=a.add(this.editorView.state.doc,i)),this.setDecorationSet(a),this.editorView&&this.dispatch(this.editorView.state.tr.setMeta(Un.SPELLCHECKER_TRANSACTION,!0)),this.addEventListenersToDecorations()}removeEventListenersFromDecorations(){const n=this.editorView?.domAtPos(this.lastOriginalFrom).node?.querySelectorAll("span.spell-error")||[];n.length&&n.forEach(r=>{r.removeEventListener("click",this.debouncedClickEventsListener)})}addEventListenersToDecorations(){if(this.isEnableSuggestion)try{const n=this.editorView?.domAtPos(this.lastOriginalFrom).node?.querySelectorAll("span.spell-error")||[];if(!n.length)return;n.forEach(r=>{r.addEventListener("click",this.debouncedClickEventsListener)})}catch{}}addEventListenersToSuggestionBox(){const e=this.suggestionBox.querySelectorAll("li");e.length&&e.forEach(n=>{n.addEventListener("mousedown",this.debouncedAcceptSuggestionEventsListener)})}dispatch(e){this.editorView&&this.editorView.dispatch(e)}findChangedTextNodes(e,n,r,i){if(!e.isBlock)return!1;if(!e.isTextblock)return e.descendants((u,c)=>{this.findChangedTextNodes(u,c,r,i)}),!1;const[s,a]=[n,n+e.nodeSize];if(!(s<=r&&i<=a))return;const l={node:e,pos:n};this.onNodeChanged(l.node.textContent,l.pos+1)}onNodeChanged(e,n){n!==this.lastOriginalFrom?this.getMatchAndSetDecorations(e,n):this.debouncedGetMatchAndSetDecorations(e,n),this.lastOriginalFrom=n}async clickEventsListener(e){if(!e.target)return;let n=e.target;for(;n&&!n.classList.contains("spell-error");)n=n.parentElement;if(!n||!n.classList.contains("spell-error"))return;this.lastClickedDecoration=n;const r=n.getAttribute(_b)?.trim();if(!r){console.error("No match string provided",{spellCheckerAttributes:r});return}const{length:i,wrongWord:s,suggestions:a}=JSON.parse(r),l=this.editorView?.posAtDOM(n,0)??0,u=l+i;if(this.editorView){this.addSuggestionsList(a,l,u),this.suggestionBox.style.display="";const c=VJ(n);if(!c)return;const f=n.getBoundingClientRect(),p=c.getBoundingClientRect(),m=window.getComputedStyle(c).padding,g=f.left-p.left+3-parseInt(m);let v=f.top-p.top+30-parseInt(m);this.suggestionBox.style.left=g+"px",this.suggestionBox.style.top=v+"px";const b=this.suggestionBox.getBoundingClientRect();b.bottom>p.bottom&&(v=f.top-p.top-b.height-7-parseInt(m),this.suggestionBox.style.top=v+"px"),this.showSuggestionsEvent&&this.showSuggestionsEvent(this.proofreader.normalizeTextForLanguage(s)),setTimeout(()=>{n.scrollIntoView({behavior:"smooth",block:"center"})},100)}return this.addEventListenersToSuggestionBox(),!1}acceptSuggestionListener(e){if(!e||!e.target)return;e.preventDefault(),e.stopPropagation();const n=e.target;let r=0,i=0;if(this.lastClickedDecoration&&this.editorView){const s=this.lastClickedDecoration.getAttribute(_b)?.trim();if(s){const{length:a}=JSON.parse(s);r=this.editorView.posAtDOM(this.lastClickedDecoration,0),i=r+a}}if(this.editorView&&r>=0&&i>r){this.dispatch(this.editorView.state.tr.setMeta(Un.ACCEPT_SUGGESTION,!0));const s=n.textContent||"",a=this.editorView.state.tr.insertText(s,r,i),l=r+s.length,u=Ie.create(a.doc,l);a.setSelection(u),this.dispatch(a),this.editorView.focus()}this.hideSuggestionBox(),this.lastClickedDecoration&&(this.lastClickedDecoration.removeEventListener("click",this.debouncedClickEventsListener),this.lastClickedDecoration=null)}addSuggestionsList(e,n,r){if(this.suggestionBox.textContent="",e.length>0){const i=document.createElement("ul");i.className="suggestion-list",e.forEach(s=>{const a=document.createElement("li");a.innerText=s,a.dataset.from=n+"",a.dataset.to=r+"",i.appendChild(a)}),this.suggestionBox.appendChild(i)}if(e.length===0){const i=document.createElement("b"),s=this.uiStrings&&this.uiStrings.noSuggestions?this.uiStrings.noSuggestions:"No suggestions found";i.textContent=s,this.suggestionBox.appendChild(i)}}isUndoRedo(e,n){return e.getMeta(K5.ADD_TO_HISTORY_TRANSACTION)===!1||e.getMeta(Un.APPENDED)===!0||n.isUndoRedoOperation}handleUndoRedo(e,n){const r=e.getMeta(K5.HISTORY_TRANSACTION)?.redo;if(n.isUndoRedoOperation=!1,r)return this.debouncedProofreadDoc(e.doc),this.getDecorationSet();const{changedNodes:i}=this.getChangedNodesFromTransaction(e,!0);return i.length===0?this.getDecorationSet():i.length===1?(this.debouncedProofreadChangedNodes(i),this.getDecorationSet()):(this.debouncedProofreadDoc(e.doc),this.getDecorationSet())}isTextContentChangedOrDeleted(e){let n=!1;return{isTextContentChanged:e.steps.some(i=>{const s=i.toJSON?.();return s?.stepType==="replace"&&s?.slice?.content?s.slice.content.some(a=>a.type==="paragraph"&&a.content&&a.content.length>0):s?.stepType==="replace"&&(!s.slice||!s.slice.content||s.slice.content.length===0)?(n=!0,s.from!==s.to):!1}),isDeleteAction:n}}handleEnterKey(e,n){if(n)return this.debouncedProofreadDoc(e.doc),this.getDecorationSet();const r=e.getMeta(Un.APPENDED_TRANSACTION);if(!r)return this.getDecorationSet();const s=r.steps[0].to,a=r.before.nodeAt(s-1);if(!a?.isText)return this.getDecorationSet();let l=0;return r.before.descendants((c,f)=>{c.textContent===a?.textContent&&(l=f)}),l+(a?.nodeSize||0)===s?this.getDecorationSet():(this.debouncedProofreadDoc(e.doc),this.getDecorationSet())}handleEnterKeyDebounced(e,n,r){this._debouncedHandleEnterKey(e,n,r)}}const dE=t=>{if(!t)return-1;const{from:e}=t.state.selection;let n=0;return t.state.doc.descendants((r,i)=>{r.type.name===Np&&i<e&&n++}),n},fE=t=>{const e=t.view?.dom;if(!e)return!1;const n=window.getSelection?.();if(n&&n.rangeCount){const r=n.anchorNode;if(r&&e.contains(r))return!0}return!1},pE=(t,e)=>t.map((r,i)=>({ext:r,name:r.name,originalIndex:i,order:e[r.name]})).sort((r,i)=>{const s=r.order===-1,a=i.order===-1;if(s&&!a)return 1;if(!s&&a)return-1;if(s&&a)return r.originalIndex-i.originalIndex;const l=typeof r.order=="number",u=typeof i.order=="number";return l&&u?r.order-i.order:l?-1:u?1:r.originalIndex-i.originalIndex}).map(r=>r.ext),Tb=(t,e)=>t?!!t.extensionManager.extensions.find(n=>n.name===e):!1;function hE(t,e){return e.characterCountLimit===void 0?t:t.map(n=>n.name==="base-kit"?n.configure({...n.options,characterCount:{...n.options.characterCount,limit:e.characterCountLimit}}):n)}const mE=bn(),Un={SPELLCHECKER_TRANSACTION:"spellcheckerTransaction",IS_ACTIVE_SPELLCHECK:"isActiveSpellCheck",LOADING_TRANSACTION:"loading",PREVENT_UPDATE:"preventUpdate",APPENDED:"appended",APPENDED_TRANSACTION:"appendedTransaction",ACCEPT_SUGGESTION:"acceptSuggestion",SKIP_SPELLCHECK:"skipSpellcheck",UI_EVENT:"uiEvent"},XJ={DROP:"drop"},gE=Qe.create({name:"spellchecker",addOptions(){return{proofreader:void 0,uiStrings:{noSuggestions:""},spellcheckHighlightMode:Io.ERROR_TYPE,spellcheckHighlightColor:Qi,button:({editor:t,t:e,isMobile:n})=>({component:Ge,componentProps:{action:()=>t.commands.handleActiveSpellCheck(),isActive:()=>t?.extensionStorage?.spellchecker?.spellchecker?.proofreader?.enabled||!1,icon:"SpellCheck",tooltip:"맞춤법 검사",title:n?e("editor.menubar.menu.spelling"):"",customClassTooltip:"flex items-center justify-center"}})}},addStorage(){return{didPaste:!1,spellchecker:void 0,isUndoRedoOperation:!1,pendingSpellCheck:!1,enterKeyPressed:!1}},addCommands(){return{checkSpelling:()=>({tr:t})=>(this.storage.spellchecker.proofreadDoc(t.doc),!0),selectAll:()=>({state:t,dispatch:e})=>(HM(t,e),!0),copy:()=>()=>(document.execCommand("copy"),!0),handleActiveSpellCheck:(t=!0)=>({editor:e})=>{const n=e.extensionStorage.spellchecker.spellchecker;return n.toggleIsEnabledSpellCheck(),e.view.dispatch(e.state.tr.setMeta(Un.IS_ACTIVE_SPELLCHECK,n.getIsEnabledSpellCheck())),t&&mE.setSpellCheck(n.getIsEnabledSpellCheck()),n.hideSuggestionBox(),fE(e)&&e.commands.focus(),!0},setIsEnableSuggestion:t=>()=>(this.storage.spellchecker.setIsEnableSuggestion(t),!0)}},addProseMirrorPlugins(){return[new ot({key:new Et("skipMarkPlugin"),view:e=>{const n=e.dispatch;return e.dispatch=r=>(r.steps.some(s=>s instanceof ti||s instanceof ro)&&r.setMeta(Un.SKIP_SPELLCHECK,!0),n.call(e,r)),{}}}),new ot({key:new Et("spellcheckerPlugin"),props:{decorations(e){return this.getState(e)},handlePaste:()=>{this.storage.didPaste=!0},handleClick:()=>{this.storage.spellchecker.hideSuggestionBox()},handleKeyDown:(e,n)=>((n.ctrlKey||n.metaKey)&&(n.key==="z"||n.key==="y")&&(this.storage.isUndoRedoOperation=!0,this.storage.pendingSpellCheck=!0),this.storage.enterKeyPressed&&(this.storage.pendingSpellCheck=!0),n.key==="Enter"&&(this.storage.enterKeyPressed=!0),!1)},state:{init:(e,n)=>{const r=new GJ(this.options.proofreader,this.options.uiStrings,this.options.onShowSuggestionsEvent,this.options.proofreader?.limit,this.options.spellcheckHighlightMode??Io.ERROR_TYPE,this.options.spellcheckHighlightColor??Qi,this.options.docLimit);return this.storage.spellchecker=r,r.setDecorationSet(lt.create(n.doc,[])),mE.setSpellCheck(r.getIsEnabledSpellCheck()),this.options.proofreader?.enabled&&r.proofreadDoc(n.doc),r.getDecorationSet()},apply:(e,n)=>{if(e.getMeta(Un.SKIP_SPELLCHECK))return n;const r=this.storage.spellchecker,i=e.getMeta(Un.IS_ACTIVE_SPELLCHECK);if(i!==void 0)return i?r.proofreadDoc(e.doc):r.setDecorationSet(lt.empty),r.getDecorationSet();if(e.getMeta(Un.SPELLCHECKER_TRANSACTION))return r.getDecorationSet();if(e.docChanged&&e.doc.nodeSize){const a=r.getDecorationSet().map(e.mapping,e.doc);if(r.setDecorationSet(a),e.getMeta(Un.UI_EVENT)===XJ.DROP)return r.debouncedProofreadDoc(e.doc),r.getDecorationSet();if(r.isUndoRedo(e,this.storage))return r.handleUndoRedo(e,this.storage);const{isTextContentChanged:l,isDeleteAction:u}=r.isTextContentChangedOrDeleted(e);if(u){const{changedNodes:m}=r.getChangedNodesFromTransaction(e,!1,!0);return m.length>0&&r.debouncedProofreadChangedNodes([m[0]]),r.getDecorationSet()}if(this.storage.enterKeyPressed)return r.handleEnterKeyDebounced(e,this.storage.pendingSpellCheck,()=>{this.storage.enterKeyPressed=!1,this.storage.pendingSpellCheck=!1}),r.getDecorationSet();if(this.storage.pendingSpellCheck||l)return r.debouncedProofreadDoc(e.doc,()=>{this.storage.pendingSpellCheck=!1}),r.getDecorationSet();if(e.getMeta(uE.UPDATE)||e.updated===0&&e.steps[0]?.structure===!0)return r.getDecorationSet();if(e.getMeta(Un.PREVENT_UPDATE)===!0&&e.before.textContent.length===0)return r.debouncedProofreadDoc(e.doc),r.getDecorationSet();this.storage.didPaste&&(this.storage.didPaste=!1);const{changedNodes:f,isChangedSuperText:p}=r.getChangedNodesFromTransaction(e);if(p)return r.debouncedProofreadDoc(e.doc),r.getDecorationSet();f.length>0&&r.debouncedProofreadChangedNodes(f)}return r.getDecorationSet()}},view:()=>({update:e=>{const n=this.storage.spellchecker;n.setEditorView(e),e?.dom?.parentNode?.appendChild(n.getSuggestionBox())}})})]}}),YJ=()=>{const t=o.reactive({[Bo.EDITOR_COMMENT]:{editor:null,wrongWords:[]},[Bo.EDITOR_CONTENT]:{editor:null,wrongWords:[]}});function e(x,C){t[x].editor=C}const n=o.ref(io.NO_ERROR);function r(){Object.values(t).forEach(x=>{x.wrongWords=[]})}function i(x,C){return x?io.FAIL:C?io.HAS_ERROR:io.NO_ERROR}async function s(){n.value=io.LOADING;let x=!1,C=!1;for(const[E,{editor:k}]of Object.entries(t)){if(!k)continue;const T=k?.extensionManager.extensions.find(A=>A.name==="spellchecker")?.options.proofreader.api,S=k.getText({blockSeparator:`
340
340
  `});if(!(!T||!S))try{const{data:A}=await sn.post(T,{value:S});if(!A.success&&A.code!==pL.NOTHING_TO_CHANGE){C=!0,t[E].wrongWords=[];continue}if(A.data?.wrongWordResponseDto){x=!0,t[E].wrongWords=A.data.wrongWordResponseDto;continue}t[E].wrongWords=[]}catch(A){console.error("handleRunSpellCheck error: ",A),C=!0}}n.value=i(C,x)}const a=o.computed(()=>Object.values(t).reduce((x,{wrongWords:C})=>x+C.length,0));o.watch(a,x=>{x===0&&(n.value=i(!1,!1))});const l=o.computed(()=>{const x=Object.values(t).flatMap(C=>C.wrongWords);return x.length===0?!1:x.every(C=>!Array.isArray(C.correctWord)||C.correctWord.length===0)});function u(x){const C=x.extensionManager.extensions.find(E=>E.name==="spellchecker")?.options;return{mode:C?.spellcheckHighlightMode??Io.ERROR_TYPE,color:C?.spellcheckHighlightColor??Qi}}function c(){for(const[x,{editor:C,wrongWords:E}]of Object.entries(t)){if(!C)continue;const{mode:k,color:T}=u(C);db(C,E,k,T)}}function f(){for(const[x,{editor:C}]of Object.entries(t))C&&WX(C)}async function p(){await s(),c()}let m=!0;function g(x){if(m=x,!!x)for(const[C,{editor:E}]of Object.entries(t))E&&(E.extensionStorage.spellchecker.spellchecker.setEnabledProofreadText(!1),E.view.dispatch(E.state.tr.setMeta(Un.IS_ACTIVE_SPELLCHECK,!1)))}function v(){if(m)for(const[x,{editor:C}]of Object.entries(t))C&&(C.extensionStorage.spellchecker.spellchecker.setEnabledProofreadText(!0),C.view.dispatch(C.state.tr.setMeta(Un.IS_ACTIVE_SPELLCHECK,!0)))}function b(x,C,E=`
341
341
  `){if(!x||!C.length)return;const k=Sk(x,E);function T(F){if(F<0&&(F=0),F>=k.length)return x.state.doc.content.size;if(k[F]!=null)return k[F];for(let j=F;j<k.length;j++)if(k[j]!=null)return k[j];for(let j=F-1;j>=0;j--)if(k[j]!=null)return k[j];return x.state.doc.content.size}const A=C.map(F=>{const j=T(F.startIndex),Y=T(Math.max(0,F.endIndex-1))+1,N=F.correctWord?.[0]??F.wrongWord;return{item:F,from:j,to:Y,replacement:N}}).filter(F=>typeof F.from=="number"&&typeof F.to=="number"&&F.from<F.to);if(!A.length)return;A.sort((F,j)=>j.from-F.from);const V=x.state.tr;let O=Number.POSITIVE_INFINITY;const B=new Set;for(const F of A)F.to>O||(V.insertText(F.replacement,F.from,F.to),B.add(F.item),O=F.from);B.size>0&&(x.view.dispatch(V),x.view.focus()),B.size>0&&(C=C.filter(F=>![...B].some(j=>j===F))),db(x,C)}function w(){for(const[x,{editor:C,wrongWords:E}]of Object.entries(t))C&&b(C,E)}return{editorsState:t,spellCheckStatus:n,countTotalWrongWords:a,allWrongWordsMissSuggestions:l,setEditor:e,resetAllEditorWrongWords:r,disableSpellCheckRealTime:g,resetEnableSpellCheckRealTime:v,applyAllEditorHighlightErrors:c,clearAllEditorHighlightErrors:f,reRunSpellCheckAndHighlight:p,handleRunSpellCheck:s,replaceAllEditorErrors:w}},JJ=o.defineComponent({__name:"DialogTrigger",props:{asChild:{type:Boolean},as:{}},setup(t){const e=t;return(n,r)=>(o.openBlock(),o.createBlock(o.unref(ID),o.normalizeProps(o.guardReactiveProps(e)),{default:o.withCtx(()=>[o.renderSlot(n.$slots,"default")]),_:3},16))}}),ZJ={key:0,class:"border-blue-500 text-white text-xs text-nowrap px-3 py-2 h-auto bg-blue-500 hover:bg-blue-500/80 flex items-center rounded"},vE=o.defineComponent({__name:"BulkSpellChecker",props:{editor:{},editorComment:{},isEnableSpellCheckRealTime:{type:Boolean},align:{default:"right"}},setup(t){const e=t,{editorsState:n,countTotalWrongWords:r,spellCheckStatus:i,allWrongWordsMissSuggestions:s,setEditor:a,disableSpellCheckRealTime:l,resetEnableSpellCheckRealTime:u,handleRunSpellCheck:c,resetAllEditorWrongWords:f,applyAllEditorHighlightErrors:p,clearAllEditorHighlightErrors:m,reRunSpellCheckAndHighlight:g,replaceAllEditorErrors:v}=YJ(),b=o.ref(!1),w=o.reactive({x:0,y:0}),x=o.ref(!1),C={x:0,y:0},E=B=>{x.value=!0,C.x=B.clientX-w.x,C.y=B.clientY-w.y,document.addEventListener("mousemove",k),document.addEventListener("mouseup",T)},k=B=>{x.value&&(w.x=B.clientX-C.x,w.y=B.clientY-C.y)},T=()=>{x.value=!1,document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",T)};o.onUnmounted(()=>{document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",T)});const S=o.ref(null),A=o.ref({top:0,right:0,left:0}),V=()=>{if(S.value){const B=S.value.$el.getBoundingClientRect();A.value={top:B.bottom+window.scrollY+5,right:window.innerWidth-B.right-window.scrollX,left:B.left+window.scrollX},w.x=0,w.y=0}};o.onMounted(async()=>{e.editorComment&&a(Bo.EDITOR_COMMENT,e.editorComment),a(Bo.EDITOR_CONTENT,e.editor)}),o.onUnmounted(()=>{a(Bo.EDITOR_COMMENT,null),a(Bo.EDITOR_CONTENT,null)}),o.watch(b,async B=>{B?(await o.nextTick(),V(),l(e.isEnableSpellCheckRealTime),await c(),p()):(f(),u(),m())});const O=e.editor?.extensionManager.extensions.find(B=>B.name==="spellchecker")?.options.bulkSpellCheckerButton;return(B,F)=>{const j=Ot,Y=pb,N=dh,H=ch,D=uh,L=lh,W=fY,P=Dc,q=Rc;return o.openBlock(),o.createBlock(q,{open:o.unref(b)},{default:o.withCtx(()=>[o.createVNode(o.unref(JJ),{"as-child":"",ref_key:"triggerRef",ref:S,onClick:F[0]||(F[0]=G=>b.value=!o.unref(b))},{default:o.withCtx(()=>[o.unref(O)?(o.openBlock(),o.createBlock(o.resolveDynamicComponent(o.unref(O).component),{key:1,buttonName:o.unref(O).props.buttonName,icon:o.unref(O).props.icon,type:o.unref(O).props.type,disabled:o.unref(O).props.disabled,iconPosition:o.unref(O).props.iconPosition,buttonSize:o.unref(O).props.buttonSize,iconClass:o.unref(O).props.iconClass},null,8,["buttonName","icon","type","disabled","iconPosition","buttonSize","iconClass"])):(o.openBlock(),o.createElementBlock("button",ZJ,[o.createVNode(j,{name:"checkUnderline"}),F[4]||(F[4]=o.createTextVNode("맞춤법 일괄 교정 "))]))]),_:1},512),o.createVNode(P,{"is-overlay-transparent":"",class:"p-0 gap-0 !animate-none !transition-none dark:border-ed-muted","as-child":""},{default:o.withCtx(()=>[o.createElementVNode("div",{class:"z-[70]",style:o.normalizeStyle({transform:`translate(${o.unref(w).x}px, ${o.unref(w).y}px)`,top:`${o.unref(A).top}px`,right:B.align==="left"?"auto":`${o.unref(A).right}px`,left:B.align==="left"?`${o.unref(A).left}px`:"auto"})},[o.createVNode(D,{class:"bg-ed-blue-light py-3.5 px-6 rounded-t-[5px] cursor-move text-blue-500 dark:text-dark-blue-100 flex-row items-center justify-between",onMousedown:o.withModifiers(E,["prevent"])},{default:o.withCtx(()=>[o.createVNode(N,{class:"text-base space-x-2"},{default:o.withCtx(()=>[F[5]||(F[5]=o.createElementVNode("span",null,"맞춤법/문법 오류",-1)),o.createVNode(Y,{class:"text-sm bg-blue-500 hover:bg-blue-500 dark:bg-dark-blue-100 px-2"},{default:o.withCtx(()=>[o.createTextVNode(o.toDisplayString(o.unref(r))+"개",1)]),_:1})]),_:1}),o.createVNode(H,{onClick:F[1]||(F[1]=G=>b.value=!1),class:"text-xs flex items-center gap-x-1"},{default:o.withCtx(()=>[o.createVNode(j,{name:"Close",class:"w-4 h-4"}),o.createTextVNode(o.toDisplayString(B.$t("editor.close")),1)]),_:1})]),_:1}),o.createVNode(L),o.createVNode(W,{editorsState:o.unref(n),spellCheckStatus:o.unref(i),allWrongWordsMissSuggestions:o.unref(s),onCloseModal:F[2]||(F[2]=G=>b.value=!1),onRunSpellcheck:o.unref(g),onReplaceAllEditorErrors:F[3]||(F[3]=G=>(o.unref(v)(),b.value=!1))},null,8,["editorsState","spellCheckStatus","allWrongWordsMissSuggestions","onRunSpellcheck"])],4)]),_:1})]),_:1},8,["open"])}}}),QJ=Object.freeze(Object.defineProperty({__proto__:null,default:vE},Symbol.toStringTag,{value:"Module"})),bE=Qe.create({name:"invalidCharFocus",addOptions(){return{invalidChars:["{","}"]}},addCommands(){return{focusInvalidChar:()=>({state:t,dispatch:e,view:n})=>{let r=null;if(t.doc.descendants((s,a)=>{if(!s.isText)return!0;const l=s.text??"";for(let u=0;u<l.length;u++)if(this.options.invalidChars.includes(l[u])){const c=a+u+1;(r==null||c<r)&&(r=c)}return!0}),r==null)return!1;const i=t.tr.setSelection(Ie.create(t.doc,r));return e&&e(i.scrollIntoView()),n&&n.focus(),!0},hasInvalidChar:()=>({state:t})=>{let e=!1;return t.doc.descendants(n=>{if(!n.isText)return!0;const r=n.text??"";return this.options.invalidChars.some(i=>r.includes(i))?(e=!0,!1):!0}),e}}}}),Ab=o.defineComponent({__name:"SimpleEditor",props:{modelValue:{default:""},parentEditor:{default:null},isReadOnly:{type:Boolean},autofocus:{type:[String,Number,Boolean,null],default:"start"},spellcheckEnabled:{type:Boolean,default:!0}},emits:["update:modelValue"],setup(t,{expose:e,emit:n}){const r=t,i=n,s=o.inject("isMobile",!1),a=o.inject("minCharSuperInput",0),l=[Z5,X5,J5,G5,Y5.configure({placeholder:"수퍼를 입력하세요"}),bE,N5],u=o.ref(r.spellcheckEnabled),c=o.computed(()=>r.parentEditor?.extensionManager.extensions.find(Y=>Y.name==="spellchecker")),f=o.computed(()=>gE.configure({proofreader:new dS({api:c.value?.options.proofreader?.api,limit:c.value?.options.proofreader?.limit,transfer:c.value?.options.proofreader?.transfer,enabled:u.value}),uiStrings:c.value?.options.uiStrings,bulkSpellCheckerButton:c.value?.options.bulkSpellCheckerButton,spellcheckHighlightMode:c.value?.options.spellcheckHighlightMode,spellcheckHighlightColor:c.value?.options.spellcheckHighlightColor})),p=new Oo({enablePasteRules:!1,enableInputRules:!1,content:r.modelValue,extensions:l.concat(f.value),editable:!r.isReadOnly,autofocus:r.autofocus,onUpdate:({editor:Y})=>{i("update:modelValue",Y.getHTML())},parseOptions:{preserveWhitespace:"full"}});o.watch(()=>r.isReadOnly,Y=>{p.setEditable(!Y),p?.commands?.setIsEnableSuggestion&&p.commands.setIsEnableSuggestion(!Y)},{immediate:!0});function m(Y){const{view:N}=p,{from:H}=N.state.selection;p.commands.insertContentAt(H,Y),p.commands.focus()}function g(){u.value=!u.value,p.commands.handleActiveSpellCheck(u.value),p?.commands?.setIsEnableSuggestion&&p.commands.setIsEnableSuggestion(u.value)}const{contentInner:v,measuredMinWidth:b,measure:w}=pf({minChars:a,fontSize:"",editor:p});o.watch(()=>r.modelValue,()=>{w(),p&&p.getHTML()!==r.modelValue&&p.commands.setContent(r.modelValue??"",!1,{preserveWhitespace:"full"})});const x=o.inject("fontSize",""),C=o.inject("fontFamily",""),E=o.inject("fontWeight",""),k=o.inject("letterSpacing",""),T=o.computed(()=>s?{fontSize:o.unref(x),fontFamily:o.unref(C),fontWeight:o.unref(E),letterSpacing:o.unref(k)}:{}),S=o.computed(()=>s?{paddingLeft:"7px",paddingRight:"7px"}:{width:`${b.value}px`}),V=document.createElement("canvas").getContext("2d");function O(){if(!b.value||!(v.value instanceof Element)||!V)return;const Y=p.getText({blockSeparator:`
342
342
  `}),N=getComputedStyle(v.value);V.font=N.font;const H=20,D=()=>Math.max(0,(b.value||0)-H);function L(G,se){let fe=1,Ee=G.length,ae=0;for(;fe<=Ee;){const me=Math.floor((fe+Ee)/2);V.measureText(G.slice(0,me)).width<=se?(ae=me,fe=me+1):Ee=me-1}return ae}let W="";const P=[];for(const G of Y){if(G===`