Files
intotheeast-com-content/plugins/admin2/app/_app/immutable/nodes/10.Cu8psC2s.js
T

2 lines
4.9 KiB
JavaScript

import"../chunks/DsnmJJEf.js";import{p as ve,i as g,m as J,u as ue,g as e,a as _,b as me,h as D,j as l,k as pe,o as _e,c as x,s as j,f as ge,t as S,d as n,$ as xe,r as d,n as M,l as he}from"../chunks/krC2xWPP.js";import{d as ye,e as be,a as $e,s as A}from"../chunks/CddAxf8c.js";import{i as L}from"../chunks/DjsWWzyL.js";import{h as je,s as P}from"../chunks/j_DJpx8B.js";import{i as W}from"../chunks/Cu5ilWky.js";import{p as ke}from"../chunks/euuZp6ft.js";import{g as B}from"../chunks/BVTiZ3e2.js";import{b as T}from"../chunks/BSopV7IU.js";import{b as we,g as Ee,c as De}from"../chunks/BXL-vMzI.js";import{c as Be,s as Te,h as Oe,B as ze,v as Ce}from"../chunks/D7PIEGLR.js";import{B as G,t as H}from"../chunks/Lvd_r9sp.js";import{S as Fe}from"../chunks/K87jKp17.js";import{D as Ne}from"../chunks/nlum2O0L.js";import{L as Q}from"../chunks/C_E2vM9U.js";import{S as Se}from"../chunks/CV_JZMCk.js";import{P as Ae}from"../chunks/C1jLV8_5.js";var Le=x('<div class="flex h-8 w-8 items-center justify-center rounded-lg bg-primary/10 text-primary"><!></div>'),Pe=x("<!> Create",1),Ie=x('<div><div><div class="flex items-center gap-3"><button type="button" class="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"><!></button> <!> <h1> </h1></div> <!></div></div>'),Ke=x('<div class="flex flex-1 items-center justify-center"><!></div>'),Re=x('<div class="flex flex-1 items-center justify-center"><div class="text-center"><p class="text-sm text-destructive"> </p> <!></div></div>'),Xe=x('<div class="flex-1 overflow-y-auto"><div class="space-y-6 px-6 py-6"><!></div></div>'),qe=x('<div class="flex h-full flex-col"><!> <!></div>');function lt(U,V){ve(V,!0);const c=D(()=>ke.params.type??"");let O=g(null),f=g(null),z=g(!0),y=g(!1),k=g(""),u=g(J({})),m=g(J({})),Y=D(()=>!e(f)||!Oe(e(f).fields,e(u)));const I=D(()=>e(u)._post_entries_save??"edit");function C(t){const s={};for(const r of t){if(r.default!==void 0){const a=r.name.includes(".")?r.name.split(".").pop():r.name;s[a]=r.default}r.fields&&Object.assign(s,C(r.fields))}return s}async function Z(){l(z,!0),l(k,"");try{const[t,s]=await Promise.all([we(e(c)),Ee().catch(()=>[])]);l(f,t,!0),l(O,s.find(r=>r.type===e(c))??null,!0),l(u,C(t.fields),!0)}catch{l(k,`Failed to load blueprint for '${e(c)}'.`)}finally{l(z,!1)}}function ee(t,s){const r=t.split("."),a={...e(u)};let i=a;for(let v=0;v<r.length-1;v++){const o=r[v];typeof i[o]!="object"||i[o]===null?i[o]={}:i[o]={...i[o]},i=i[o]}i[r[r.length-1]]=s,l(u,a,!0);const p=e(f)?Ce(e(f).fields,t,a):null;if(p)l(m,{...e(m),[t]:p},!0);else if(e(m)[t]){const{[t]:v,...o}=e(m);l(m,o,!0)}}async function K(){if(l(m,e(f)?Be(e(f).fields,e(u)):{},!0),Object.keys(e(m)).length>0){Te();return}l(y,!0);try{const{_post_entries_save:t,...s}=e(u),r=await De(e(c),s);H.success(W.t("ADMIN_NEXT.FLEX_OBJECTS.NEW.OBJECT_CREATED")),e(I)==="create-new"?l(u,e(f)?C(e(f).fields):{},!0):e(I)==="list"?B(`${T}/flex-objects/${e(c)}`):B(`${T}/flex-objects/${e(c)}/${r.key}`)}catch(t){const s=t&&typeof t=="object"&&"message"in t?t.message:"Failed to create object";H.error(s)}finally{l(y,!1)}}function te(t){(t.metaKey||t.ctrlKey)&&t.key==="s"&&(t.preventDefault(),e(y)||K())}ue(()=>{e(c),Z()});var F=qe();je("fhxi7h",t=>{pe(()=>{xe.title=`New ${e(O)?.title??e(c)??""} — Grav Admin`})}),be("keydown",_e,te);var R=n(F);Fe(R,{children:(s,r)=>{let a=()=>r?.().scrolled;var i=Ie(),p=n(i),v=n(p),o=n(v),w=n(o);Ne(w,{name:"arrow-back",size:16}),d(o);var E=j(o,2);{var oe=b=>{var $=Le(),X=n($);Ae(X,{size:16}),d($),_(b,$)};L(E,b=>{a()||b(oe)})}var N=j(E,2),le=n(N);d(N),d(v);var ne=j(v,2);{let b=D(()=>e(y)||!e(Y));G(ne,{size:"sm",onclick:K,get disabled(){return e(b)},children:($,X)=>{var q=Pe(),de=ge(q);{var ce=h=>{Q(h,{size:14,class:"me-1.5 animate-spin"})},fe=h=>{Se(h,{size:14,class:"me-1.5"})};L(de,h=>{e(y)?h(ce):h(fe,-1)})}M(),_($,q)},$$slots:{default:!0}})}d(p),d(i),S(()=>{P(i,1,`px-6 transition-[padding] duration-200 ${a()?"py-2":"pt-6 pb-3"}`),P(p,1,`flex items-center justify-between gap-4 ${a()?"min-h-6":"min-h-8"}`),P(N,1,`font-semibold text-foreground transition-[font-size] duration-200 ${a()?"text-sm":"text-lg"}`),A(le,`New ${e(O)?.title??e(c)??""}`)}),$e("click",o,()=>B(`${T}/flex-objects/${e(c)}`)),_(s,i)},$$slots:{default:!0}});var re=j(R,2);{var se=t=>{var s=Ke(),r=n(s);Q(r,{size:24,class:"animate-spin text-muted-foreground"}),d(s),_(t,s)},ae=t=>{var s=Re(),r=n(s),a=n(r),i=n(a,!0);d(a);var p=j(a,2);G(p,{variant:"outline",size:"sm",class:"mt-3",onclick:()=>B(`${T}/flex-objects/${e(c)}`),children:(v,o)=>{M();var w=he();S(E=>A(w,E),[()=>W.t("ADMIN_NEXT.FLEX_OBJECTS.NEW.BACK_TO_LIST")]),_(v,w)},$$slots:{default:!0}}),d(r),d(s),S(()=>A(i,e(k))),_(t,s)},ie=t=>{var s=Xe(),r=n(s),a=n(r);ze(a,{get fields(){return e(f).fields},get data(){return e(u)},onchange:ee,get errors(){return e(m)}}),d(r),d(s),_(t,s)};L(re,t=>{e(z)?t(se):e(k)?t(ae,1):e(f)&&t(ie,2)})}d(F),_(U,F),me()}ye(["click"]);export{lt as component};