PageSourceSearch

https://stepily.com/assets/WorkbookEditor-Dhsda2oS.js

js stepily.com collected 2026-09-24 14:53:15 UTC 9,909 bytes, 1 lines download raw bytes

1import{h as Z,ap as X,k as ee,m as oe,n as re,p as se,r as m,s as h,Z as c,j as e,x as v,ae as te,J as ie,K as ae,af as ne,N as le,O as _,ag as de,L as ce,ah as ke,ac as ue,i as be,q as O,t as me,v as pe,H as he,R as A,I as we,a9 as xe,Q as fe,aC as ge}from"./index-BIfQh25H.js";import{T as je}from"./textarea-b6ezai6C.js";import{L as ve}from"./label-Cwl4lV9w.js";import{A as Ee,G as Ne}from"./AppSelector-Cj-jLxPG.js";import{M as _e}from"./MoveWorkbookToTeamDialog-BlasIvgk.js";import"./useCustomApps-v6IUgQBM.js";import"./select-opNpb1aA.js";import"./index-0mvnqb_O.js";import"./triangle-alert-hShPxpNF.js";const Oe=()=>{const{t:r}=Z(),{id:w}=X(),x=ee(),{user:k}=oe(),{canPublishPublicly:W}=re(),{publishableTeams:I,publishWorkbookToTeam:F}=se(),u=!w,[t,p]=m.useState(null),[b,E]=m.useState([]),[G,N]=m.useState(!u),[y,f]=m.useState(!1),[j,T]=m.useState(null),[R,P]=m.useState(!1),[q,S]=m.useState(!1),M=u?"/dashboard":`/workbook/${w}`;m.useEffect(()=>{if(k){if(u){p(o=>o??{id:"",title:"",description:null,user_id:k.id,app:null,is_published:!1,visibility:"private",link_sharing_enabled:!1});return}$()}},[w,u,k]);const $=async()=>{if(!w||!k)return;N(!0);const{data:o,error:s}=await h.from("workbooks").select("id, title, description, user_id, app, is_published, visibility, link_sharing_enabled, workspace_id").eq("id",w).single();if(s){console.error("Error fetching workbook:",s),c.error(r("common.toasts.loadWorkbookFailed")),x("/dashboard");return}if(o.user_id!==k.id){c.error(r("workbookEditor.toasts.noPermission")),x("/dashboard");return}p(o);const{data:i,error:d}=await h.from("workbook_tutorials").select("tutorial_id, order_index").eq("workbook_id",w).order("order_index",{ascending:!0});if(d){console.error("Error fetching workbook tutorials:",d),c.error(r("common.toasts.loadTutorialsFailed")),N(!1);return}const n=i.map(g=>g.tutorial_id),{data:a,error:l}=await h.from("tutorials").select("id, title, description, workspace_id").in("id",n).eq("is_trashed",!1);if(l){console.error("Error fetching tutorial data:",l),c.error(r("common.toasts.loadTutorialDetailsFailed")),N(!1);return}const V=i.map(g=>{const L=a==null?void 0:a.find(Y=>Y.id===g.tutorial_id);return L?{...L,order_index:g.order_index}:null}).filter(g=>g!==null);E(V),N(!1)},z=o=>{T(o)},B=(o,s)=>{if(o.preventDefault(),j===null||j===s)return;const i=[...b],d=i[j];i.splice(j,1),i.splice(s,0,d),E(i),T(s)},H=()=>{T(null)},J=o=>{E(s=>{const i=new Set(s.map(n=>n.id)),d=o.filter(n=>!i.has(n.id)).map((n,a)=>{var l;return{id:n.id,title:n.title,description:n.description,order_index:s.length+a,workspace_id:((l=n.workspace)==null?void 0:l.id)??null}});return d.length===0?s:[...s,...d]})},K=o=>{E(s=>s.filter(i=>i.id!==o))},C=async o=>{var n;if(!t||!k)return null;if(!t.title.trim())return c.error(r("workbookEditor.toasts.titleRequired")),null;if(o==="public"&&!W)return c.error(r("workbookEditor.toasts.publicPublishingRestricted")),null;const s=o?{is_published:!0,visibility:o==="public"?"public":"private",link_sharing_enabled:o==="anyoneWithLink"}:{is_published:t.is_published,visibility:t.visibility,link_sharing_enabled:t.link_sharing_enabled};f(!0);let i=t.id;if(u){const{data:a,error:l}=await h.from("workbooks").insert({user_id:k.id,title:t.title.trim(),description:((n=t.description)==null?void 0:n.trim())||null,app:t.app,...s}).select("id").single();if(l||!a)return console.error("Error creating workbook:",l),c.error(r("workbookEditor.toasts.saveWorkbookFailed")),f(!1),null;i=a.id}else{const{error:a}=await h.from("workbooks").update({title:t.title,description:t.description,app:t.app,...s,updated_at:new Date().toISOString()}).eq("id",t.id);if(a)return console.error("Error updating workbook:",a),c.error(r("workbookEditor.toasts.saveWorkbookFailed")),f(!1),null;const{error:l}=await h.from("workbook_tutorials").delete().eq("workbook_id",t.id);if(l)return console.error("Error deleting workbook tutorials:",l),c.error(r("workbookEditor.toasts.updateOrderFailed")),f(!1),null}const d=b.map((a,l)=>({workbook_id:i,tutorial_id:a.id,order_index:l}));if(d.length>0){const{error:a}=await h.from("workbook_tutorials").insert(d);if(a)return console.error("Error inserting workbook tutorials:",a),c.error(r("workbookEditor.toasts.updateOrderFailed")),f(!1),null}return p({...t,id:i,...s}),f(!1),i},Q=async()=>{const o=await C();
1o&&(c.success(r(u?"workbookEditor.toasts.workbookCreated":"workbookEditor.toasts.workbookSaved")),x(`/workbook/${o}`))},D=async o=>{const s=await C(o);s&&(c.success(r(`workbookEditor.toasts.published.${o}`)),x(`/workbook/${s}`))},U=async o=>{const s=await C("private");if(!s)return;const i=await F(s,b.map(d=>d.id),o);S(!1),i&&x(`/workbook/${s}`)};return G||u&&!t?e.jsx("div",{className:"min-h-screen bg-background",children:e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsx("p",{className:"text-muted-foreground",children:r("workbookEditor.loading")})})}):t?e.jsxs("div",{className:"workbook-editor-page min-h-screen bg-background",children:[e.jsx("header",{className:"workbook-editor-topbar sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:e.jsxs("div",{className:"workbook-editor-topbar__inner container flex h-16 items-center gap-4 px-4 md:px-8 max-w-[88rem] mx-auto",children:[e.jsx(v,{variant:"ghost",size:"icon","aria-label":r(u?"workbookEditor.backToDashboard":"workbookEditor.backToWorkbook"),onClick:()=>x(M),className:"shrink-0",children:e.jsx(te,{className:"w-4 h-4"})}),e.jsx("div",{className:"flex-1 min-w-0 px-2",children:e.jsx("h1",{className:"text-lg font-bold truncate leading-tight",children:t.title||r("workbookEditor.defaultTitle")})}),e.jsxs("div",{className:"workbook-editor-topbar__actions flex items-center gap-2 shrink-0",children:[e.jsx(v,{variant:"outline",onClick:Q,disabled:y,children:r(y?"workbookEditor.saving":"workbookEditor.done")}),e.jsxs(ie,{children:[e.jsx(ae,{asChild:!0,children:e.jsxs(v,{disabled:y,children:[r("workbookEditor.publish"),e.jsx(ne,{className:"w-4 h-4 ml-1"})]})}),e.jsxs(le,{align:"end",className:"bg-background",children:[W&&e.jsxs(_,{onSelect:()=>void D("public"),children:[e.jsx(de,{className:"w-4 h-4 mr-2"}),r("workbookEditor.publishPublic")]}),e.jsxs(_,{onSelect:()=>void D("private"),children:[e.jsx(ce,{className:"w-4 h-4 mr-2"}),r("workbookEditor.publishPrivate")]}),e.jsxs(_,{onSelect:()=>void D("anyoneWithLink"),children:[e.jsx(ke,{className:"w-4 h-4 mr-2"}),r("workbookEditor.publishAnyoneWithLink")]}),I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ue,{}),e.jsxs(_,{onSelect:()=>S(!0),children:[e.jsx(be,{className:"w-4 h-4 mr-2"}),r("workbookEditor.publishToTeam")]})]})]})]})]})]})}),e.jsx("div",{className:"container mx-auto px-4 py-8 max-w-4xl",children:e.jsxs(O,{children:[e.jsx(me,{children:e.jsxs(pe,{className:"flex items-center gap-2",children:[e.jsx(he,{children:r("workbookEditor.workbookBadge")}),r(u?"workbookEditor.createWorkbook":"workbookEditor.editWorkbook")]})}),e.jsxs(A,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:r("workbookEditor.titleLabel")}),e.jsx(we,{value:t.title,onChange:o=>p({...t,title:o.target.value}),placeholder:r("workbookEditor.titlePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:r("workbookEditor.descriptionLabel")}),e.jsx(je,{value:t.description||"",onChange:o=>p({...t,description:o.target.value}),placeholder:r("workbookEditor.descriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ve,{className:"text-sm font-medium",children:r("workbookEditor.appLabel")}),e.jsx(Ee,{selectedApps:t.app?[t.app]:[],onAddApp:o=>p({...t,app:o}),onRemoveApp:()=>p({...t,app:null}),userId:k==null?void 0:k.id,workspaceId:t.workspace_id})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("label",{className:"text-sm font-medium",children:r("workbookEditor.tutorialsLabel",{count:b.length})}),e.jsxs(v,{type:"button",variant:"outline",size:"sm",onClick:()=>P(!0),children:[e.jsx(xe,{className:"w-4 h-4 mr-2"}),r("workbookEditor.addGuides")]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:r("workbookEditor.dragToReorder")}),b.length===0&&e.jsx("p",{className:"rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground",children:r("workbookEditor.noGuidesYet")}),e.jsx("div",{className:"space-y-2",children:b.map((o,s)=>e.jsx(O,{draggable:!0,onDragStart:()=>z(s),onDragOver:i=>
1B(i,s),onDragEnd:H,className:`cursor-move transition-all ${j===s?"opacity-50":""}`,children:e.jsxs(A,{className:"p-4 flex items-center gap-3",children:[e.jsx(Ne,{className:"w-5 h-5 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-primary text-primary-foreground font-semibold text-sm flex-shrink-0",children:s+1}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:o.title}),o.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:o.description})]}),e.jsx(v,{variant:"ghost",size:"icon",onClick:()=>K(o.id),className:"flex-shrink-0 text-destructive hover:text-destructive",children:e.jsx(fe,{className:"w-4 h-4"})})]})},o.id))})]})]})]})}),e.jsx(ge,{open:R,onOpenChange:P,mode:"select",documentType:"tutorial",disabledIds:b.map(o=>o.id),onConfirmSelection:J}),e.jsx(_e,{open:q,onOpenChange:S,workbookTitle:t.title||r("workbookEditor.defaultTitle"),guides:b,teams:I.map(o=>({id:o.workspace.id,name:o.workspace.name})),onConfirm:U})]}):e.jsx("div",{className:"min-h-screen bg-background",children:e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsx("p",{className:"text-muted-foreground",children:r("workbookEditor.notFound")})})})};export{Oe as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.