import{l as e,n as t,t as n}from"./hooks.module-BrXTvcfS.js";import{p as r}from"./compat.module-C8KToj4y.js";import{t as i}from"./jsxRuntime.module-Cao1NCKs.js";r();function a({apiRef:r,currentValue:a,editor:s,config:c,disableNewlines:l,disableSpellcheck:u,onChange:d,onClick:f,onInitialized:p,...m}){let h=n(null),g=n(null);return t(r,()=>({focus(){g.current?.editing.view.focus(),g.current?.model.change(e=>{let t=g.current?.editing.model.document.getRoot();t&&e.setSelection(e.createPositionAt(t,`end`))})},setText(e){g.current?.setData(e)},appendBlockQuote(e){let t=g.current;if(!t)return;let n=e.split(`
`).map(e=>e.replace(/^\s*>\s?/,``));t.model.change(e=>{let r=t.model.document.getRoot();if(!r)return;let i=r.childCount===1?r.getChild(0):null;i?.is(`element`,`paragraph`)&&i.isEmpty&&e.remove(i);let a=e.createElement(`blockQuote`);for(let t of o(n)){let n=e.createElement(`paragraph`);e.append(n,a),t.forEach((t,r)=>{r>0&&e.appendElement(`softBreak`,n),e.appendText(t,n)})}a.isEmpty&&e.append(e.createElement(`paragraph`),a),e.insert(a,e.createPositionAt(r,`end`));let s=e.createElement(`paragraph`);e.insert(s,e.createPositionAfter(a)),e.setSelection(s,`in`)}),t.editing.view.focus()}}),[h]),e(()=>{h.current&&s.create(h.current,c).then(e=>{if(g.current=e,l&&e.editing.view.document.on(`enter`,(e,t)=>{t.preventDefault(),e.stop()},{priority:`high`}),u){let t=e.editing.view.document.getRoot();t&&e.editing.view.change(e=>e.setAttribute(`spellcheck`,`false`,t))}d&&e.model.document.on(`change:data`,()=>{d(e.getData())}),a&&e.setData(a),p?.(e)})},[]),e(()=>{g.current&&g.current.setData(a??``)},[a]),i(`div`,{ref:h,onClick:e=>{if(f){let t=g.current?.model.document.selection.getFirstPosition();f(e,t)}},...m})}function o(e){let t=[],n=null;for(let r of e){if(r.length===0){n=null;continue}n||(n=[],t.push(n)),n.push(r)}return t}export{a as t};