UNPKG

edit-on-slate

Version:

Slate 기반의 직관적이고 강력한 리액트 텍스트 에디터 라이브러리

307 lines (285 loc) 19.1 kB
import{jsx as e,jsxs as t}from"@emotion/react/jsx-runtime";import n,{useState as o,useRef as i,useEffect as r,useMemo as a,useCallback as s}from"react";import{Transforms as l,Text as A,Editor as d,Element as c,Range as g,Point as p,createEditor as m}from"slate";export{Node,Path,Point,Range,Editor as SlateEditor,Element as SlateElement,Text,Transforms,createEditor}from"slate";import{useSlate as h,withReact as u,Slate as f,Editable as b}from"slate-react";export{Editable,ReactEditor,Slate,useFocused,useSelected,useSlate,useSlateStatic,withReact}from"slate-react";import{withHistory as x}from"slate-history";export{HistoryEditor,withHistory}from"slate-history";import w from"@emotion/styled";import{createPortal as B}from"react-dom";import{CacheProvider as y}from"@emotion/react";import C from"@emotion/cache";const v=e=>`\n text-align: ${e||"left"};\n transition: text-align 0.2s ease;\n`,E=w.p` margin: 0.5em 0; line-height: 1.6; ${e=>v(e.textAlign)} `,U=w.h1` font-size: 2em; margin-top: 1em; margin-bottom: 0.5em; font-weight: bold; ${e=>v(e.textAlign)} `,S=w.h2` font-size: 1.5em; margin-top: 0.8em; margin-bottom: 0.4em; font-weight: bold; ${e=>v(e.textAlign)} `,I=w.h3` font-size: 1.2em; margin-top: 0.6em; margin-bottom: 0.3em; font-weight: bold; ${e=>v(e.textAlign)} `,k=w.blockquote` border-left: 2px solid #ddd; margin-left: 0; margin-right: 0; padding-left: 10px; color: #666; font-style: italic; ${e=>v(e.textAlign)} `,j=w.ul` margin: 0.5em 0; padding-left: 1.5em; ${e=>v(e.textAlign)} `,R=w.ol` margin: 0.5em 0; padding-left: 1.5em; ${e=>v(e.textAlign)} `,Y=w.li` margin: 0.2em 0; ${e=>v(e.textAlign)} `,O=t=>{const{attributes:n,children:o,element:i}=t,r=i.textAlign;switch(i.type){case"paragraph":default:return e(E,Object.assign({textAlign:r},n,{children:o}));case"heading-one":return e(U,Object.assign({textAlign:r},n,{children:o}));case"heading-two":return e(S,Object.assign({textAlign:r},n,{children:o}));case"heading-three":return e(I,Object.assign({textAlign:r},n,{children:o}));case"block-quote":return e(k,Object.assign({textAlign:r},n,{children:o}));case"bulleted-list":return e(j,Object.assign({textAlign:r},n,{children:o}));case"numbered-list":return e(R,Object.assign({textAlign:r},n,{children:o}));case"list-item":return e(Y,Object.assign({textAlign:r},n,{children:o}))}},Q=t=>e(O,Object.assign({},t)),F=w.span` font-family: ${e=>e.fontFamily||"inherit"}; color: ${e=>e.color||"inherit"}; font-weight: ${e=>e.isBold?"bold":"normal"}; font-style: ${e=>e.isItalic?"italic":"normal"}; text-decoration: ${e=>e.isUnderline?"underline":"none"}; ${e=>e.isCode&&"\n background-color: #f0f0f0;\n padding: 0.2em 0.4em;\n border-radius: 3px;\n font-family: var(--font-code, monospace);\n font-size: 0.9em;\n "} transition: all 0.2s ease; `,N=({attributes:t,children:n,leaf:o})=>{const i=o;return e(F,Object.assign({},t,{fontFamily:i.fontFamily,color:i.color,isBold:o.bold,isItalic:o.italic,isUnderline:o.underline,isCode:o.code},{children:n}))},D=t=>e(N,Object.assign({},t)),V=(e,t)=>{const n=T(e,t);l.setNodes(e,{[t]:!n||null},{match:e=>A.isText(e),split:!0})},T=(e,t)=>{const n=d.marks(e);return!!n&&!0===n[t]},X=(e,t)=>{const n=K(e,t),o=["numbered-list","bulleted-list"].includes(t);let i;if(l.unwrapNodes(e,{match:e=>!d.isEditor(e)&&c.isElement(e)&&["numbered-list","bulleted-list"].includes(e.type),split:!0}),i=n?{type:"paragraph"}:{type:o?"list-item":t},l.setNodes(e,i),!n&&o){const n={type:t,children:[]};l.wrapNodes(e,n)}},K=(e,t)=>{const{selection:n}=e;if(!n)return!1;const[o]=Array.from(d.nodes(e,{at:d.unhangRange(e,n),match:e=>!d.isEditor(e)&&c.isElement(e)&&e.type===t}));return!!o},M=(e,t)=>{const{selection:n}=e;if(!n)return!1;const[o]=Array.from(d.nodes(e,{at:d.unhangRange(e,n),match:e=>!d.isEditor(e)&&c.isElement(e)&&e.textAlign===t}));return!!o},z=(e,t)=>{l.setNodes(e,{color:t},{match:e=>A.isText(e),split:!0})};const L=["#FF0000","#FF7F00","#FFFF00","#00FF00","#0000FF","#4B0082","#9400D3","#FF1493","#00FFFF","#FFD700","#C0C0C0","#000000","#FFFFFF"],H=w.div` display: flex; flex-wrap: wrap; padding: 8px; margin-bottom: 10px; border-bottom: 1px solid #ddd; background-color: #f8f8f8; `,G=w.button` all: unset; -webkit-appearance: none; -moz-appearance: none; appearance: none; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; margin: 0; padding: 6px; width: 32px; height: 32px; border: 1px solid ${e=>e.active?"#666":"#ccc"}; border-radius: 4px; background-color: ${e=>e.active?"#e6e6e6":"white"}; cursor: pointer; transition: all 0.2s ease; &:hover { background-color: #e6e6e6; } &:focus { outline: none; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1); } &:active { transform: translateY(1px); } `,Z=w.div` width: 1px; height: 24px; background-color: #ddd; margin: 0 10px; `,P=w.img` width: 16px; height: 16px; display: block; `,W=w.select` margin-right: 5px; margin-bottom: 5px; padding: 6px 10px; border: 1px solid #ccc; border-radius: 3px; background-color: white; font-size: 14px; cursor: pointer; &:focus { outline: none; } `,J=w.input` width: 30px; height: 30px; padding: 0; border: none; background: none; cursor: pointer; &::-webkit-color-swatch-wrapper { padding: 0; } &::-webkit-color-swatch { border: 1px solid #ccc; border-radius: 3px; } `,q=w.div` position: relative; display: inline-block; `,$=w.div` position: absolute; top: 100%; left: 0; z-index: 10; display: ${e=>e.visible?"block":"none"}; padding: 10px; background-color: white; border: 1px solid #ccc; border-radius: 3px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); width: 200px; `,_=w.div` display: flex; flex-wrap: wrap; margin-top: 8px; `,ee=w.button` width: 24px; height: 24px; margin: 2px; padding: 0; border: 1px solid #ccc; background-color: ${e=>e.color}; border-radius: 3px; cursor: pointer; &:hover { transform: scale(1.1); } &:focus { outline: none; } `,te=w.div` display: flex; align-items: center; gap: 4px; `,ne=({format:t,icon:n})=>{const o=h(),i=T(o,t);return e(G,Object.assign({active:i,onMouseDown:e=>{e.preventDefault(),V(o,t)},title:t},{children:n}))},oe=({format:t,icon:n})=>{const o=h(),i=K(o,t);return e(G,Object.assign({active:i,onMouseDown:e=>{e.preventDefault(),X(o,t)},title:t},{children:n}))},ie=({align:t,icon:n})=>{const o=h();return e(G,Object.assign({active:!1,onMouseDown:e=>{e.preventDefault(),((e,t)=>{const{selection:n}=e;if(!n)return;const o=M(e,t);l.setNodes(e,{textAlign:o?void 0:t},{match:t=>c.isElement(t)&&d.isBlock(e,t)})})(o,t)},title:`${t} Align`},{children:n}))},re=({editor:n})=>{const[i,r]=o(!1);return t(H,{children:[t(te,{children:[e(ne,{format:"bold",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAC5SURBVHgB7ZRhDcIwEIUfBAGTUAuTgAKCAqzgAAugAAkMBeBgczAcjLtwBFLa4+Ag2Y9+yUu33nJvbV8KFMbOkFFL2lgaTPDegOmi+SBjQ5rDwf2PQ8Kgl9pCazDFd3SknTzX+IMBU8nYah/NYCNE77wtK9xWcoSDQVGfMH7BmqIz6fI0H0QNaRnVPiKXImYrtTUcaAYBj63K8osUVXCQWwE3PUntoDXwXhV8uHWibkaL6B6GmBYKfq79OjoFZRx41QAAAABJRU5ErkJggg==",alt:"Bold"})}),e(ne,{format:"italic",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACBSURBVHgB7dTtCYAgEAbgl2iARrhNapMapU1yExuhDVyhDUroQv+YFh0o+MCh3g8VPw6oSqBsHJEIapCBzgZxzLh2bLwc4UeaF1gggODOnCBA8eQaQgwvMELABHe5r6Q+03vXKwQQcr7cNpAfvH7P7ebldx5/Fqs9yR8ti1pUVc9OqjQoxqfV1cIAAAAASUVORK5CYII=",alt:"Italic"})}),e(ne,{format:"underline",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACNSURBVHgB7ZPtDUAwEIZfFmCEjmAEG7CBFWyESdiADYzABnXifkn1IyUR+iTPj17f9NJLCwTeiiAl2WgyLWeEJoMYDxMa/LjBCjOJQ1ZJTy5Qv/O9tv+BER7kfMhMVlxLuT7zXglPahy3kCcX3jMSWWQEWZAZryeyg8fsb+XqBjncGODYQMINm1EHvsoGDegZ70jEgwoAAAAASUVORK5CYII=",alt:"Underline"})}),e(ne,{format:"code",icon:"</>"})]}),e(Z,{}),t(te,{children:[e(oe,{format:"heading-one",icon:"H1"}),e(oe,{format:"heading-two",icon:"H2"}),e(oe,{format:"block-quote",icon:'"'})]}),e(Z,{}),t(te,{children:[e(oe,{format:"bulleted-list",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACHSURBVHgB7ZTNCYAwDEY/fw4eHcFuoCN0I0dwFSdwBEexG+gIJtqT2BqoUoQ+eJcQEkLSAonYZI74QhpSkzXZQ8YgbbCSG6nIhpwhQwnzjqItEh5qazC+K+Ild7bRBBn6GsjxzCuT3BX9pPD/KBxxfmQVzkUH4bsiJvirKB2JxsrwFCMSiWjs60UQJ+UU5ZcAAAAASUVORK5CYII=",alt:"Bullet List"})}),e(oe,{format:"numbered-list",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACfSURBVHgB7ZThDUYwEIbffJ8BjMAGRmADG2ACMYFR2IAN2IQV/POPk1YipFxSCZI+yZP07s81vd4Bhqf5K/IN6ZItNPkp8sku7siJ4QELPBLcjE16+DKF1IEmqh5kZLUr6OCagFsgh2hsL+Nhc76F9Yne32jVJMcQt+/JERqcDZovC7RkCDEbV5TcAjUZbeIUvF9Ugsmy7Jb948NgeJwZb/EedhQbiekAAAAASUVORK5CYII=",alt:"Number List"})})]}),e(Z,{}),t(te,{children:[e(ie,{align:"center",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACBSURBVHgB7ZTdCYAwDISv4gCOoBO4giPoCG7kBq7QURyhI7iBxjcRroZaKYV+cC/5aSA9AhRSY0j8QKT3alLYIReMomYR9SS3iyZPL13RHSvaPAPSwla0Ioz5GaiQOxoXjaKG5K5Ptr5mjYsGcJu6twG/w1bUIgynHRDt2BUK3zkBCfsMpS/i8k4AAAAASUVORK5CYII=",alt:"Center Align"})}),e(ie,{align:"right",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAABsSURBVHgB7dTbCYAwDIXhv9IBHKGO0g1cwcnUCVzJTdTnQiDGohbyQV/CoaEXAu5rQagfVNovCsGBVgRlrr/WpsjlshDRW/kj6YpmbKay0NG6O79oVOQWa4OE7l0yb5NOkLDZtQ2qDTvnnjsBroAH1Omb/jAAAAAASUVORK5CYII=",alt:"Right Align"})}),e(ie,{align:"justify",icon:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAABhSURBVHgB7dTRCYAwDIThX3EQHcVNdDJ1EldxE30vHJSYUgL5Ho/S0KMEUm+DyF+c7pvEwYUoVEU3NmsZqIouolAVHdjsZTASnapow+asHeD2TZtTL5ixeWoHuC27lP77AN9sB9Q2IFqfAAAAAElFTkSuQmCC",alt:"Justify"})})]}),e(Z,{}),e(te,{children:t(W,Object.assign({onChange:e=>{((e,t)=>{l.setNodes(e,{fontFamily:t},{match:e=>A.isText(e),split:!0})})(n,e.target.value)},title:"Font Family"},{children:[e("option",Object.assign({value:"Pretendard"},{children:"Pretendard"})),e("option",Object.assign({value:"Nanum Gothic"},{children:"나눔고딕"})),e("option",Object.assign({value:"sans-serif"},{children:"Sans-serif"})),e("option",Object.assign({value:"serif"},{children:"Serif"})),e("option",Object.assign({value:"monospace"},{children:"Monospace"}))]}))}),e(Z,{}),e(te,{children:t(q,{children:[e(G,Object.assign({active:!1,onMouseDown:e=>{e.preventDefault(),r(!i)},title:"Font Color"},{children:e(P,{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACxSURBVHgB7ZK9DcIwEIVfgJ6UlB4hI6SkZISMwAZ4A0aAFdgASqqMYDZgBHhWHCmK8nNKLkWUfNInWWf7LN8dsDIHUnrDQDaCM08a0Qsm5jvkka3wnC/Rmx7pgb6gyJXasI5pTs9QwpfkXosZ6ugJAqKefZ/o0xA39AGFnyQomvur6cIj/hcxRpK1JEdYWyiQNSRPQiyHEmkleYmFsNnzpWtMHeS0juyu45KBnD1Wlssf+cgh3sQW0TwAAAAASUVORK5CYII=",alt:"Font Color"})})),t($,Object.assign({visible:i},{children:[e(J,{type:"color",onChange:e=>{z(n,e.target.value),r(!1)},title:"Choose Color"}),e(_,{children:L.map((t=>e(ee,{color:t,onClick:()=>(e=>{z(n,e),r(!1)})(t)},t)))})]}))]})})]})},ae=e=>{const{deleteBackward:t,insertText:n}=e;return e.insertText=t=>{const{selection:o}=e;if(o&&g.isCollapsed(o)&&" "===t){const{anchor:t}=o,n=d.above(e,{match:t=>c.isElement(t)&&d.isBlock(e,t)}),i=n?n[1]:[],r={anchor:t,focus:d.start(e,i)},a={"*":"bulleted-list","-":"bulleted-list","+":"bulleted-list","1.":"numbered-list",">":"block-quote","#":"heading-one","##":"heading-two","###":"heading-three"}[d.string(e,r)];if(a){if(l.select(e,r),l.delete(e),l.setNodes(e,{type:a},{match:t=>c.isElement(t)&&d.isBlock(e,t)}),["bulleted-list","numbered-list"].includes(a)){const t={type:a,children:[{type:"list-item",children:[{text:""}]}]};return void l.wrapNodes(e,t)}return}}n(t)},e.deleteBackward=(...n)=>{const{selection:o}=e;if(console.log("deleteBackward called",{selection:o,args:n}),o&&g.isCollapsed(o)){const t=d.above(e,{match:t=>c.isElement(t)&&d.isBlock(e,t)});if(t){const[n,i]=t,r=d.start(e,i);if(p.equals(o.anchor,r)&&"paragraph"!==n.type)return void l.setNodes(e,{type:"paragraph"})}}t(...n)},e},se=({children:t})=>{const o=i(null),a=i(null),s=i(null),[,l]=n.useState({});return r((()=>{if(o.current&&!a.current){a.current=o.current.attachShadow({mode:"open"});const e=document.createElement("div");a.current.appendChild(e),s.current=C({key:"edit-on-slate",container:a.current,prepend:!0,stylisPlugins:[]});document.querySelectorAll('link[rel="stylesheet"][href*="fonts.googleapis.com"]').forEach((e=>{var t;const n=e.cloneNode(!0);null===(t=a.current)||void 0===t||t.appendChild(n)})),l({})}}),[]),e("div",Object.assign({ref:o},{children:a.current&&s.current&&B(e(y,Object.assign({value:s.current},{children:t})),a.current)}))};w.div` ${'\n --font-primary: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n --font-code: "JetBrains Mono", "Fira Code", monospace;\n --font-family-sans: "Nanum Gothic", "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", sans-serif;\n --font-family-serif: "Noto Serif KR", Georgia, "Times New Roman", serif;\n --font-family-mono: "JetBrains Mono", "D2Coding", Consolas, monospace;\n'} width: 100%; max-width: 800px; margin: 0 auto; background: #fff; `;const le=w.div` border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); background: #fff; height: ${e=>e.height||"500px"}; display: flex; flex-direction: column; `,Ae=w.div` font-family: var(--font-primary); line-height: 1.5; padding: 1rem; flex: 1; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); &:focus { outline: none; border-color: #0077ff; box-shadow: 0 0 0 2px rgba(0, 119, 255, 0.1); } p { margin: 0 0 1em 0; &:last-child { margin-bottom: 0; } } h1 { font-size: 2em; margin: 1em 0 0.5em; } h2 { font-size: 1.5em; margin: 1em 0 0.5em; } h3 { font-size: 1.17em; margin: 1em 0 0.5em; } blockquote { border-left: 2px solid #ddd; margin: 1em 0; padding-left: 1em; color: #666; } code { font-family: var(--font-code); background: #f5f5f5; padding: 0.2em 0.4em; border-radius: 3px; font-size: 0.9em; } ul, ol { margin: 1em 0; padding-left: 2em; } li { margin: 0.5em 0; } `;w.div` padding: 8px; border: 1px solid #ddd; border-bottom: none; border-radius: 4px 4px 0 0; background: #f8f9fa; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; `,w.div` display: flex; gap: 4px; align-items: center; `,w.button` min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid #ddd; border-radius: 4px; background: #fff; cursor: pointer; font-size: 14px; font-weight: 500; color: #333; display: inline-flex; align-items: center; justify-content: center; transition: all 0.2s ease; &:hover { background: #f0f0f0; border-color: #ccc; } &.active { background: #e9ecef; border-color: #adb5bd; color: #000; } img { width: 16px; height: 16px; opacity: 0.7; &:hover { opacity: 1; } } `,w.select` height: 32px; padding: 0 24px 0 8px; border: 1px solid #ddd; border-radius: 4px; background: #fff url('data:image/svg+xml;utf8,<svg fill="%23333" height="16" viewBox="0 0 24 24" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>') no-repeat right 4px center; cursor: pointer; font-size: 14px; color: #333; appearance: none; min-width: 120px; &:hover { background-color: #f0f0f0; border-color: #ccc; } &:focus { outline: none; border-color: #0077ff; box-shadow: 0 0 0 2px rgba(0, 119, 255, 0.1); } `,w.div` width: 1px; height: 24px; margin: 0; background: #ddd; flex-shrink: 0; `;const de=({value:t,style:n,containerStyle:o,editorStyle:i})=>{const r=a((()=>u(m())),[]);return e("div",Object.assign({style:n},{children:e(f,Object.assign({editor:r,initialValue:t},{children:e(le,Object.assign({style:o},{children:e(Ae,Object.assign({style:i},{children:e(b,{renderElement:Q,renderLeaf:D,readOnly:!0})}))}))}))}))},ce=(e,t="a")=>!("undefined"==typeof document||!document.fonts)&&document.fonts.check(`12px '${e}'`,t),ge=(e,t=5e3)=>"undefined"!=typeof document&&document.fonts?new Promise((n=>{if(ce(e))return void n(!0);const o=()=>{ce(e)&&(n(!0),document.removeEventListener("fontload",o),clearTimeout(i))},i=setTimeout((()=>{document.removeEventListener("fontload",o),n(!1)}),t);document.addEventListener("fontload",o),document.fonts.load&&document.fonts.load(`12px '${e}'`).then(o)})):Promise.resolve(!1),pe=e=>{if("undefined"==typeof document)return;const t=document.createElement("link");t.rel="preconnect",t.href=new URL(e).origin,t.crossOrigin="anonymous",document.head.appendChild(t);const n=document.createElement("link");n.rel="preload",n.as="style",n.href=e,document.head.appendChild(n);const o=document.createElement("link");o.rel="stylesheet",o.href=e,o.media="print",o.onload=()=>{o.media="all"},document.head.appendChild(o);const i=document.createElement("noscript"),r=document.createElement("link");r.rel="stylesheet",r.href=e,i.appendChild(r),document.head.appendChild(i)},me=()=>{pe("https://fonts.googleapis.com/css2?family=Nanum+Gothic:wght@400;700;800&display=swap"),pe("https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css")},he=[{type:"paragraph",children:[{text:""}]}],ue=({value:n=he,onChange:i,placeholder:l="내용을 입력하세요...",readOnly:A=!1,containerStyle:d,editorStyle:c})=>{const[g,p]=o(!1);r((()=>{me(),Promise.all([ge("Nanum Gothic"),ge("Pretendard"),ge("Inter")]).then((()=>{p(!0),document.documentElement.classList.add("fonts-loaded")}))}),[]);const h=a((()=>ae(x(u(m())))),[]),w=s((t=>e(O,Object.assign({},t))),[]),B=s((t=>e(N,Object.assign({},t))),[]),y=A?e(de,{value:n,placeholder:l,containerStyle:d,editorStyle:c}):e(f,Object.assign({editor:h,initialValue:n,onChange:i},{children:t(le,Object.assign({style:d},{children:[e(re,{editor:h}),e(Ae,Object.assign({style:c},{children:e(b,{renderElement:w,renderLeaf:B,placeholder:l,spellCheck:!0,autoFocus:!0})}))]}))}));return e(se,{children:e("div",Object.assign({className:g?"fonts-loaded":""},{children:y}))})};export{ue as Editor,de as ReadOnlyEditor,re as Toolbar,K as isBlockActive,ce as isFontLoaded,T as isMarkActive,me as loadDefaultFonts,pe as loadFontStylesheet,X as toggleBlock,V as toggleMark,ge as waitForFont,ae as withShortcuts}; //# sourceMappingURL=index.esm.js.map