PageSourceSearch

https://lemma.pub/assets/edit-CfEvyMWb.js

js lemma.pub collected 2026-10-10 00:09:16 UTC 7,847 bytes, 1 lines download raw bytes

1import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,I as n,M as r,k as i,r as a,t as o}from"./jsx-runtime-DRaGzAQL.js";import{H as s,I as c,R as ee,_ as l,l as u,p as d,t as f,v as te,z as p}from"./api-client-Cgc0O-n9.js";import{n as m}from"./auth-context-B_9-wBpr.js";import{n as h}from"./data-context-Cigx_UvB.js";import{t as ne}from"./ArrowLongLeftIcon-8_zn3Pwg.js";import{t as g}from"./ArrowTopRightOnSquareIcon-FjBgqdbk.js";import{_ as re}from"./CodeMirrorMarkdownEditor-BIcgT4o8.js";import{t as _}from"./CenteredMessage-D392zyrY.js";import{t as v}from"./Spinner-DGmTPX7Y.js";import{n as y,t as b}from"./CoverImagePicker-B20W5CsG.js";import{t as x}from"./ConfirmDeleteButton-DHWKkGGQ.js";var S=e(n(),1),C=o(),w=r(function(){let{session:e,loading:t}=m(),n=i();return(0,S.useEffect)(()=>{!t&&!e&&n(`/`)},[t,e,n]),t||!e?(0,C.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,C.jsx)(v,{})}):(0,C.jsx)(T,{session:e})});function T({session:e}){let n=i(),{invalidatePosts:r,removePost:o}=h(),{userId:m,pubRkey:w,rkey:T}=t(),[E,D]=(0,S.useState)(null),[O,k]=(0,S.useState)(``),[A,j]=(0,S.useState)(``),M=(0,S.useRef)(null),[N,P]=(0,S.useState)(`published`),[F,I]=(0,S.useState)(!1),[L,R]=(0,S.useState)(null),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(null),[U,W]=(0,S.useState)(null),[G,K]=(0,S.useState)(!1),[q,J]=(0,S.useState)(null),[Y,X]=(0,S.useState)(``),[Z,Q]=(0,S.useState)(``),$=(0,S.useRef)(null);(0,S.useEffect)(()=>{if(!m||!T)return;let t=!1;async function n(){try{let n=await s(m);if(t)return;if(n!==e.sub){D(`not-owner`);return}let r=await l(e,T);if(t)return;D(r),k(r.title),j(r.content??``),P(r.visibility),Q(r.license??``);let i=await te(e,T,r.visibility);if(t)return;i.coverImage&&H(i.coverImage),i.license!==void 0&&Q(i.license);let a=i.bskyPostRef??r.bskyPostRef;if(i.bskyPostRef&&!r.bskyPostRef&&D(e=>e&&e!==`not-owner`?{...e,bskyPostRef:i.bskyPostRef}:e),a){let n=await d(e,a.uri);t||X(n)}}catch(e){t||R(e instanceof Error?e.message:`Failed to load post`)}}return n(),()=>{t=!0}},[m,T,e]);async function ie(t){J(null),K(!0);try{let n=await re(t),r=URL.createObjectURL(n);$.current&&URL.revokeObjectURL($.current),$.current=r,W(r);let i=await ee(e,n);H(i)}catch(e){J(e instanceof Error?e.message:`Upload failed`),H(null)}finally{K(!1)}}function ae(){$.current&&=(URL.revokeObjectURL($.current),null),W(null),H(null),J(null)}async function oe(t){if(t.preventDefault(),!(!E||E===`not-owner`||!O.trim())){I(!0),R(null),B(!1);try{let t=M.current?.getMarkdown()??A,{content:i,imageBlobs:a}=await p(e,t),o=N===`published`&&E.resolvedUrl?{text:Y.trim(),pubUrl:E.resolvedUrl}:void 0,s=await c(e,T,O.trim(),i,N,E,V,o,a.length>0?a:void 0,Z||void 0);if(N===`published`){r();let e=s.atUri.split(`/`).pop();M.current?.detach(),n(`/${m}/pub/${w}/${e}`)}else B(!0),I(!1)}catch(e){R(e instanceof Error?e.message:`Failed to save`),I(!1)}}}async function se(){if(!(!E||E===`not-owner`||!T))try{await u(e,T,E.bskyPostRef??void 0,E.visibility),o(T),M.current?.detach(),n(`/`)}catch(e){R(e instanceof Error?e.message:`Failed to delete`)}}return E===`not-owner`?(0,C.jsx)(_,{message:`You can only edit your own articles.`,action:{label:`View post`,to:`/${m}/pub/${w}/${T}`}}):L&&!E?(0,C.jsx)(_,{message:L,error:!0,action:{label:`Back to profile`,to:`/${m}`}}):E?(0,C.jsx)(`div`,{className:`flex-1 flex flex-col p-4 md:p-8`,children:(0,C.jsxs)(`div`,{className:`w-full max-w-sm mx-auto md:max-w-none space-y-6`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsx)(a,{to:N===`draft`?`/`:`/${m}/pub/${w}/${T}`,children:(0,C.jsx)(ne,{className:`size-9`})}),(0,C.jsx)(`h1`,{className:`font-display text-xl font-semibold text-stone-900 dark:text-white`,children:`Edit article`})]}),(0,C.jsx)(x,{onDelete:se,disabled:F})]}),(0,C.jsxs)(`form`,{onSubmit:oe,className:`space-y-3`,children:[(0,C.jsxs)(`div`,{className:`flex gap-3 flex-wrap`,children:[(0,C.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`Title`,autoFocus:!0,disabled:F,className:`flex-1 min-w-0 rounded-lg border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-800 px-4 py-3 text-sm text-stone-900 dark:text-white placeholder-stone-400 focus:outline-none focus:ring-2 focus:ring-stone-900 dark:focus:ring-stone-100 disabled:opacity-50`}),(0,C.jsx)(`div`,{className:`flex rounded-lg border border-stone-300 dark:border-stone-600 overflow-hidden text-sm font-medium`,children:[`draft`,`published`].map(e=>{let t=F||e===`draft`&&E.visibility===`published`;return(0,C.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>P(e),title:e===`draft`&&E.visibility===`published`?`Published articles cannot be reverted to draft`:void 0,className:N===e?`px-4 py-3 bg-stone-900 dark:bg-stone-100 text-white dark:text-stone-900 transition-colors`:`px-4 py-3 bg-white dark:bg-stone-800 text-stone-500 dark:text-stone-400 hover:bg-stone-50 dark:hover:bg-stone-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e.charAt(0).toUpperCase()+e.slice(1)},e)})}),(0,C.jsx)(`button`,{type:`submit`,disabled:F||!O.trim(),className:`rounded-lg bg-stone-900 dark:bg-stone-100 hover:bg-stone-700 dark:hover:bg-stone-200 disabled:opacity-50 disabled:cursor-not-allowed px-6 py-3 text-sm font-semibold text-white dark:text-stone-900 transition-colors whitespace-nowrap`,children:F?`Saving…`:`Save`})]}),L&&(0,C.jsx)(`p`,{className:`text-sm text-red-500`,children:L}),z&&(0,C.jsx)(`p`,{className:`text-sm text-green-600 dark:text-green-400`,children:`Draft saved.`}),(0,C.jsx)(b,{previewUrl:U,imageDid:V&&!U?e.sub:void 0,imageCid:V&&!U?V.ref.$link:void 0,uploading:G,error:q,onSelect:ie,onRemove:ae}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsxs)(`label`,{className:`text-sm font-medium text-stone-500 dark:text-stone-400`,children:[`License `,(0,C.jsx)(`span`,{className:`font-normal text-stone-400 dark:text-stone-500`,children:`(optional)`}),` · `,(0,C.jsxs)(`a`,{href:`https://creativecommons.org/cc-licenses/`,target:`_blank`,rel:`noopener noreferrer`,className:`font-normal underline underline-offset-2 hover:text-stone-700 dark:hover:text-stone-200 transition-colors`,children:[`about CC licenses `,(0,C.jsx)(g,{className:`inline-block w-4 h-4 mb-0.5`})]})]}),(0,C.jsxs)(`select`,{value:Z,onChange:e=>Q(e.target.value),disabled:F,className:`w-full rounded-lg border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-800 px-4 py-3 text-sm text-stone-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-stone-900 dark:focus:ring-stone-100 disabled:opacity-50`,children:[(0,C.jsx)(`option`,{value:``,children:`No license specified`}),f.map(e=>(0,C.jsx)(`option`,{value:e,children:e},e))]})]}),N===`published`&&(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsxs)(`label`,{className:`text-sm font-medium text-stone-500 dark:text-stone-400`,children:[`Bluesky post`,` `,(0,C.jsx)(`span`,{className:`font-normal text-stone-400 dark:text-stone-500`,children:`(a Bluesky post links Comments and Likes across platforms)`})]}),(0,C.jsx)(`textarea`,{value:Y,onChange:e=>X(e.target.value),placeholder:`Add text to your Bluesky post… (optional)`,rows:3,maxLength:300,disabled:F,className:`w-full rounded-lg border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-800 px-4 py-3 text-sm text-stone-900 dark:text-white placeholder-stone-400 focus:outline-none focus:ring-2 focus:ring-stone-900 dark:focus:ring-stone-100 disabled:opacity-50 resize-none`}),(0,C.jsxs)(`p`,{className:`text-sm text-stone-400 dark:text-stone-500 text-right`,children:[Y.length,`/300`]})]}),(0,C.jsx)(y,{initialValue:A,onChange:j,apiRef:M})]})]})}):(0,C.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,C.jsx)(v,{})})}
1export{w 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.