2 lines
2.4 KiB
JavaScript
2 lines
2.4 KiB
JavaScript
|
var U=Object.defineProperty;var h=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable;var u=(a,l,e)=>l in a?U(a,l,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[l]=e,r=(a,l)=>{for(var e in l||(l={}))g.call(l,e)&&u(a,e,l[e]);if(h)for(var e of h(l))p.call(l,e)&&u(a,e,l[e]);return a};import{m as w,g as y,u as S,h as A,i as M,j as F,k as P,l as C}from"./ExampleEditor.08243b7c.js";import"./style.b4010a05.js";import{e as D,l as I,w as O,j,f as o,F as N,q as R}from"../app.d1307649.js";var _=D({name:"sb-layout-edit",model:w,props:{onUpdate:{type:null,default:()=>{}},data:{type:null,default:y}},setup(a){const{activate:l}=S(),e=I({orientation:a.data.orientation,children:[...a.data.children]});O(()=>a.data,()=>{e.orientation=a.data.orientation,e.children=[...a.data.children]});const m=j(()=>({"sb-layout":!0,[`sb-layout_${e.orientation}`]:!0})),v=()=>{a.onUpdate({orientation:e.orientation==="vertical"?"horizontal":"vertical"})},f=(t,n)=>{const c=e.children.indexOf(t);c!==-1&&a.onUpdate({children:[...e.children.slice(0,c),r(r({},t),n),...e.children.slice(c+1)]})},k=t=>{e.children=[...e.children,t],a.onUpdate({children:[...e.children]}),l(t.id)},i=(t,n)=>{e.children=[...e.children.slice(0,t+1),n,...e.children.slice(t+1)],a.onUpdate({children:[...e.children]}),l(n.id)},d=t=>{e.children=[...e.children.slice(0,t),...e.children.slice(t+1)],a.onUpdate({children:[...e.children]});const n=Math.max(t-1,0);l(e.children[n].id)},s=t=>{const n=Math.max(Math.min(e.children.length-1,t),0);l(e.children[n].id)},B=t=>{if(t===0)return;const n=e.children[t],c=e.children[t-1];e.children=[...e.children.slice(0,t-1),n,c,...e.children.slice(t+1)],a.onUpdate({children:[...e.children]})},b=t=>{if(t===e.children.length-1)return;const n=e.children[t],c=e.children[t+1];e.children=[...e.children.slice(0,t),c,n,...e.children.slice(t+2)],a.onUpdate({children:[...e.children]})};return()=>o("div",{class:m.value},[o(A,null,{default:()=>[o(M,{type:"button",onClick:v},{default:()=>[e.orientation]})]}),o(N,null,[...e.children.map((t,n)=>o(F,R({key:t.id},{"data-order":n,block:t,onUpdate:c=>f(t,c),onRemoveSelf:()=>d(n),onPrependBlock:c=>i(n-1,c),onAppendBlock:c=>i(n,c),onActivatePrevious:()=>s(n-1),onActivateNext:()=>s(n+1)}),{"context-toolbar":()=>o(P,{onMoveBackward:()=>B(n),onMoveForward:()=>b(n),onRemove:()=>d(n),orientation:e.orientation},null)}))]),o(C,{onInsertBlock:k},null)])}});export{_ as default};
|