2 lines
1.9 KiB
JavaScript
2 lines
1.9 KiB
JavaScript
|
import{m as x,q as g,u as N,h as S,o as B,p as T}from"./ExampleEditor.08243b7c.js";import"./style.b4010a053.js";import{e as D,l as I,r as K,h as U,w as p,j as M,f as l,d as s}from"../app.d1307649.js";var q=D({name:"sb-paragraph-edit",model:x,props:{blockId:{type:String,required:!0},data:{type:null,default:g},onUpdate:{type:null,default:()=>{}},onAppendBlock:{type:null,default:()=>{}},onRemoveSelf:{type:null,default:()=>{}},onActivateNext:{type:null,default:()=>{}},onActivatePrevious:{type:null,default:()=>{}}},setup(a){const e=I({value:a.data.value,align:a.data.align,focused:!1}),t=K(null),{isActive:c,activate:d}=N(a.blockId),i=()=>{t.value&&c.value&&t.value.focus()};U(()=>{i(),t.value&&(t.value.innerHTML=e.value)}),p(c,i),p(()=>a.data,()=>{e.value=a.data.value,e.align=a.data.align,t.value&&(t.value.innerHTML=e.value)});const h=n=>{e.value=n.target.innerHTML},y=M(()=>({"sb-paragraph":!0,"sb-paragraph_focused":e.focused,[`sb-paragraph_align-${e.align}`]:!0})),m=n=>{a.onUpdate({value:e.value,align:n.target.value})},b=()=>{e.focused=!0,d()},A=()=>{e.focused=!1,a.onUpdate({value:e.value,align:e.align})},k=n=>{if(n.key==="Enter"&&!n.shiftKey){const o=T();a.onAppendBlock({id:o,name:"sb-paragraph",data:g()}),d(o),n.preventDefault()}},w=n=>{var v;n.key==="Backspace"&&e.value===""&&a.onRemoveSelf();const o=window.getSelection(),u=o==null?void 0:o.focusNode,r=Array.from(((v=t==null?void 0:t.value)==null?void 0:v.childNodes)||[]),f=u?r.indexOf(u):-1;if(u===t.value||f===0||f===r.length-1)switch(n.key){case"ArrowDown":a.onActivateNext();break;case"ArrowUp":a.onActivatePrevious();break}};return()=>l("div",{class:y.value},[l(S,null,{default:()=>[l(B,{value:e.align,onChange:m},{default:()=>[l("option",null,[s("left")]),l("option",null,[s("center")]),l("option",null,[s("right")])]})]}),l("p",{class:"sb-paragraph__input",ref:t,contenteditable:!0,onInput:h,onFocus:b,onBlur:A,onKeydown:k,onKeyup:w},null)])}});export{q as default};
|