@chaibuilder/pages 0.13.1 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{2AITGKQY-DULB7thn.cjs → 2AITGKQY-DpAgk_u8.cjs} +1 -1
- package/dist/{2AITGKQY-CENX4_xF.js → 2AITGKQY-Dx_Cte-P.js} +2 -2
- package/dist/{NCMVHL6D-CqalO-g8.cjs → NCMVHL6D-B6lv7Umq.cjs} +1 -1
- package/dist/{NCMVHL6D-C876JEj5.js → NCMVHL6D-CT2qHOTS.js} +2 -2
- package/dist/{ZDWCUMSJ-B7wBWmr3.cjs → ZDWCUMSJ-C1vrgsti.cjs} +1 -1
- package/dist/{ZDWCUMSJ-BTetztmo.js → ZDWCUMSJ-W9xywtZH.js} +1 -1
- package/dist/index-C4j31Yhz.js +11471 -0
- package/dist/index-DnjETHks.cjs +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -3
- package/dist/page-revisions-content-Gx-Qf_91.cjs +8 -0
- package/dist/page-revisions-content-_-Nd4U11.js +712 -0
- package/package.json +3 -3
- package/dist/index-DxMxs0cm.cjs +0 -13
- package/dist/index-IB36s074.js +0 -12159
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-DnjETHks.cjs"),s=require("@chaibuilder/sdk");exports.ChaiBuilderPagesRealtime=e.ChaiBuilderPagesRealtime;exports.ChaiJsonInput=e.SmartJsonInput;exports.ImagePicker=e.ImagePicker;exports.LanguageSwitcher=e.LanguageSwitcher;exports.NestedPathSelector=e.NestedPathSelector;exports.PermissionChecker=e.PermissionChecker;exports.default=e.ChaiBuilderPages;exports.registerChaiLoginComponent=e.registerLoginComponent;exports.registerChaiSiteSetting=e.registerChaiSiteSetting;exports.useActivePage=e.useActivePage;exports.useBuilderPageData=e.useBuilderPageData;exports.useChaiAuth=e.useChaiAuth;exports.useChaiCurrentPage=e.useCurrentPage;exports.useChaiFetch=e.useChaiFetch;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useClearAll=e.useClearAll;exports.useFallbackLang=e.useFallbackLang;exports.useFetch=e.useFetch;exports.useGotoPage=e.useGotoPage;exports.useLanguagePages=e.useLanguagePages;exports.usePageTypes=e.usePageTypes;exports.useReloadPage=e.useReloadPage;exports.useUpdateActivePageMetadata=e.useUpdateActivePageMetadata;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;Object.keys(s).forEach(a=>{a!=="default"&&!Object.prototype.hasOwnProperty.call(exports,a)&&Object.defineProperty(exports,a,{enumerable:!0,get:()=>s[a]})});
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,10 @@ declare type ChaiBuilderPagesProps = {
|
|
|
23
23
|
onLogout?: () => void;
|
|
24
24
|
getAccessToken?: () => Promise<string>;
|
|
25
25
|
supabaseInstance?: SupabaseClient;
|
|
26
|
-
features?:
|
|
26
|
+
features?: {
|
|
27
|
+
sharedJsonLD?: boolean;
|
|
28
|
+
canResetSeoToDefault?: boolean;
|
|
29
|
+
} & Record<string, boolean>;
|
|
27
30
|
} & Pick<ChaiBuilderEditorProps, "onError" | "translations" | "locale" | "htmlDir" | "autoSave" | "autoSaveInterval" | "fallbackLang" | "languages" | "themePresets">;
|
|
28
31
|
|
|
29
32
|
export declare class ChaiBuilderPagesRealtime implements ChaiBuilderPagesRealtimeInterface {
|
|
@@ -142,6 +145,8 @@ declare interface SmartJsonInputProps {
|
|
|
142
145
|
id?: string;
|
|
143
146
|
pageData?: Record<string, any>;
|
|
144
147
|
handleFieldInsert?: (field: string, inputId: string) => void;
|
|
148
|
+
hasJsonLdForSelectedLang?: boolean;
|
|
149
|
+
copyJsonLDFromDefaultPage?: () => void;
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
export declare const useActivePage: () => {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { aq as s, ah as t, ag as i, af as u, a6 as g, a3 as r, a5 as o, ai as h, ap as n, a7 as P, a8 as l, am as C, a0 as c, ao as d, _ as m, a9 as p, aa as f, Y as S, ab as b, aj as k, ac as A, ad as L, ae as F, an as I, ak as U, al as v } from "./index-C4j31Yhz.js";
|
|
2
2
|
export * from "@chaibuilder/sdk";
|
|
3
3
|
export {
|
|
4
4
|
s as ChaiBuilderPagesRealtime,
|
|
@@ -7,8 +7,8 @@ export {
|
|
|
7
7
|
u as LanguageSwitcher,
|
|
8
8
|
g as NestedPathSelector,
|
|
9
9
|
r as PermissionChecker,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
o as default,
|
|
11
|
+
h as registerChaiLoginComponent,
|
|
12
12
|
n as registerChaiSiteSetting,
|
|
13
13
|
P as useActivePage,
|
|
14
14
|
l as useBuilderPageData,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("@chaibuilder/sdk/ui"),_=require("date-fns"),S=require("lodash-es"),j=require("lucide-react"),y=require("react"),B=require("react-diff-view"),x=require("./index-DnjETHks.cjs"),A=require("@tanstack/react-query"),V=require("@chaibuilder/sdk");function K(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>s[n]})}}return t.default=s,Object.freeze(t)}const J=K(y);function Q(s,t){const n=x.useApiUrl(),a=x.useFetch();return A.useQuery({queryKey:["revision-comparison",s.uid,t.uid],queryFn:async()=>{if(!s.uid||!t.uid)throw new Error("Both revision IDs are required for comparison");const i=d=>d==="draft"||d==="live"?d:"revision",o=d=>S.replace(d.uid,`${d.label}:`,"");return await a(n,{action:x.ACTIONS.GET_COMPARE_DATA,data:{versions:{version1:{type:i(s.label),id:o(s)},version2:{type:i(t.label),id:o(t)}}}})},enabled:!!s.uid&&!!t.uid,gcTime:0,staleTime:0})}const W=({version:s})=>{const t=s==null?void 0:s.item,{data:n}=x.useChaiUserInfo(t==null?void 0:t.currentEditor),a=s.label==="live",i=s.label==="draft";return e.jsxs("span",{className:`flex items-center gap-x-2 rounded border bg-white px-2 text-xs shadow-lg ${a?"border-green-500/30":i?"border-amber-500/30":"border-purple-500/30"}`,children:[e.jsx("div",{className:"h-full items-center rounded px-1.5 py-0.5 font-medium capitalize"+(a?" bg-green-500 text-green-50":i?" bg-amber-500 text-amber-50":" bg-purple-500 text-purple-50"),children:s.label}),e.jsxs("div",{className:"py-1 text-xs font-light leading-none text-gray-800",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-light opacity-90",children:i?"Currently editing":"Published by"}),!i&&e.jsx("span",{className:"pl-1 font-medium",children:(n==null?void 0:n.name)||"Unknown"})]}),e.jsx("div",{className:"text-[10px] leading-tight",children:_.formatDate(t.createdAt,"dd MMM yyyy, h:mm a")})]})]})},z=({version:s})=>e.jsx(W,{version:s});function Y(s,t,n="data.json"){const a=JSON.stringify(s,null,2),i=JSON.stringify(t,null,2),o=a.split(`
|
|
2
|
+
`),l=i.split(`
|
|
3
|
+
`);let d=`--- a/${n}
|
|
4
|
+
`;d+=`+++ b/${n}
|
|
5
|
+
`;const m=[];let r=0,f=0;for(;r<o.length||f<l.length;){const N=o[r]||"",C=l[f]||"";if(N===C)m.push(` ${N}`),r++,f++;else{let u=-1,b=-1;for(let h=r+1;h<o.length;h++)if(l[f]===o[h]){u=h;break}for(let h=f+1;h<l.length;h++)if(o[r]===l[h]){b=h;break}if(u!==-1&&(b===-1||u-r<=b-f)){for(let h=r;h<u;h++)m.push(`-${o[h]}`);r=u}else if(b!==-1){for(let h=f;h<b;h++)m.push(`+${l[h]}`);f=b}else N&&m.push(`-${N}`),C&&m.push(`+${C}`),r++,f++}}const w=o.length,R=l.length;return d+=`@@ -1,${w} +1,${R} @@
|
|
6
|
+
`,d+=m.join(`
|
|
7
|
+
`)+`
|
|
8
|
+
`,d}function $(s,t=!0,n=!1){if(S.isString(s)){const a=S.trim(s);if(S.startsWith(a,"{")||S.startsWith(a,"[")||t&&(a==="true"||a==="false"||a==="null"||/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(a)))try{const o=JSON.parse(a);return $(o,t,n)}catch{if(n)throw new Error(`Invalid JSON string: ${a}`);return{}}return s}return S.isArray(s)?S.map(s,a=>$(a,t,n)):S.isPlainObject(s)?S.mapValues(s,a=>$(a,t,n)):s}const X=s=>{switch(s){case"blocks":return"Blocks";case"seo":return"SEO";case"tracking":return"Tracking";default:return s}},Z=(s,t)=>{if(!s||!t)return[{key:"blocks",label:"Blocks"}];const n=Object.keys(s),a=Object.keys(t);return n.filter(l=>a.includes(l)).map(l=>({key:l,label:X(l)})).filter(l=>l.key.length>0)},ee=(s,t=3)=>{const n=new Set;s.map((l,d)=>({change:l,index:d})).filter(({change:l})=>l.type!=="normal").map(({index:l})=>l).forEach(l=>{const d=Math.max(0,l-t),m=Math.min(s.length-1,l+t);for(let r=d;r<=m;r++)n.add(r)});const i=[];let o=-1;return s.forEach((l,d)=>{if(n.has(d)){if(o!==-1&&d-o>1){const m=s[o].lineNumber!=null?s[o].lineNumber+1:o+2,r=s[d].lineNumber!=null?s[d].lineNumber-1:d;i.push({content:e.jsx(c.Badge,{className:"pointer-events-none w-60 -translate-x-1/2 cursor-default border-none bg-transparent py-1 shadow-none",children:e.jsxs("span",{className:"rounded border border-border bg-muted px-3 py-1 text-xs font-light leading-none text-muted-foreground",children:["No changes from ",m," to ",r," line"]})})})}i.push(l),o=d}}),i};function se({open:s,compare:t,onOpenChange:n}){const a=t[0],i=t[1],[o,l]=y.useState(null),[d,m]=y.useState("split"),[r,f]=y.useState(!1),[w,R]=y.useState(!1),[N,C]=y.useState("blocks"),{data:u,isLoading:b}=Q(a,i),{leftData:h,rightData:O,options:q}=y.useMemo(()=>{var v,g;const p=(v=u==null?void 0:u.version1)==null?void 0:v[N],k=(g=u==null?void 0:u.version2)==null?void 0:g[N],E=$(p),T=$(k),F=Z(u==null?void 0:u.version1,u==null?void 0:u.version2);return{leftData:E,rightData:T,options:F}},[u,N]),D=y.useMemo(()=>!h||!O?"":Y(h,O),[h,O]),P=y.useMemo(()=>{if(!D)return[];try{return B.parseDiff(D)}catch(p){return console.error("Failed to parse diff:",p),[]}},[D]),U=async(p,k)=>{try{await navigator.clipboard.writeText(JSON.stringify(p,null,2)),l(k),setTimeout(()=>l(null),2e3)}catch(E){console.error("Failed to copy:",E)}},M=p=>JSON.stringify(p,null,2);return e.jsx(c.Dialog,{open:s,onOpenChange:n,children:e.jsxs(c.DialogContent,{className:"flex h-[90vh] w-[95vw] max-w-[1900px] flex-col p-6",children:[e.jsx(c.DialogHeader,{className:"pb-4 pt-0",children:e.jsxs(c.DialogTitle,{className:"flex items-center justify-between gap-2 leading-none",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j.FileJson,{className:"h-5 w-5"}),"Compare","",q.map(p=>e.jsx("div",{className:`cursor-pointer rounded-full border px-2.5 py-1 text-xs leading-none ${N===p.key?"border-blue-500 bg-blue-500 text-white":"border-gray-600 text-gray-600 hover:bg-gray-200"}`,onClick:()=>C(p.key),children:p.label},p.key))]}),e.jsx("div",{className:"flex flex-1 items-center justify-end pr-8",children:e.jsxs("div",{className:"flex w-max items-center justify-end gap-2 rounded-md border px-1.5 py-1",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[e.jsx(c.Switch,{disabled:r,checked:r?!0:d==="split",onCheckedChange:p=>m(p?"split":"unified")}),e.jsx("label",{className:"text-sm",children:"Split View"})]}),e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[e.jsx(c.Switch,{checked:r,onCheckedChange:p=>f(p)}),e.jsx("label",{className:"text-sm",children:"Show Raw Data"})]}),e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[e.jsx(c.Switch,{checked:w,onCheckedChange:p=>R(p)}),e.jsx("label",{className:"text-sm",children:"Hide Common Data"})]})]})})]})}),b?e.jsx("div",{className:"flex h-full w-full items-center justify-center",children:e.jsx(j.Loader,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:e.jsxs("div",{className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"absolute -top-5 z-50 mt-0.5 flex w-full items-center justify-between gap-2",children:[e.jsx("div",{className:"flex w-1/2 items-center justify-center gap-2",children:e.jsx(z,{version:a})}),e.jsx("div",{className:"flex w-1/2 items-center justify-center gap-2",children:e.jsx(z,{version:i})})]}),r?e.jsxs("div",{className:"grid h-full grid-cols-2 gap-3 rounded-lg border",children:[e.jsxs("div",{className:"relative flex min-h-0 flex-col border-r",children:[e.jsx("div",{className:"absolute -top-4 right-4 z-50",children:e.jsxs(c.Button,{variant:"outline",size:"sm",onClick:()=>U(h,"left"),children:[o==="left"?e.jsx(j.Check,{className:"text-green-500"}):e.jsx(j.Copy,{}),"Copy"]})}),e.jsx(c.ScrollArea,{className:"flex-1 rounded-lg bg-slate-50 p-3 dark:bg-slate-900",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs",children:M(h)})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-col",children:[e.jsx("div",{className:"absolute -top-4 right-4 z-50",children:e.jsxs(c.Button,{variant:"outline",size:"sm",onClick:()=>U(O,"right"),children:[o==="right"?e.jsx(j.Check,{className:"text-green-500"}):e.jsx(j.Copy,{}),"Copy"]})}),e.jsx(c.ScrollArea,{className:"flex-1 rounded-lg bg-slate-50 p-3 dark:bg-slate-900",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs",children:M(O)})})]})]}):e.jsx(c.ScrollArea,{className:"h-full overflow-y-auto rounded-lg border bg-slate-50 text-xs dark:bg-slate-900",children:P.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6",children:e.jsxs("div",{className:"text-center text-muted-foreground",children:[e.jsx(j.FileJson,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{children:"No differences found or unable to parse diff"})]})}):e.jsx("div",{children:P.map((p,k)=>e.jsx("div",{className:"relative mb-4",children:e.jsx(B.Diff,{viewType:d,diffType:p.type,hunks:p.hunks,className:"rounded-lg text-xs",children:E=>E.map((T,F)=>{const v=w?ee(T.changes):T.changes;return(v==null?void 0:v.length)===0?e.jsx("div",{className:"absolute h-full w-full border-l pt-64 text-center font-sans text-sm",children:e.jsx("span",{children:"No difference found"})}):e.jsx(B.Hunk,{hunk:{...T,changes:v}},F)})},w?"hide-common-data":"show-common-data")},k))})})]})})]})})}function te(s){const t=x.useApiUrl(),n=x.useFetch();return A.useQuery({queryKey:["revisions",s],queryFn:async()=>await n(t,{action:x.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,gcTime:0,refetchOnMount:!0})}const ne=()=>{const s=x.useApiUrl(),t=x.useFetch(),n=A.useQueryClient();return A.useMutation({mutationFn:async a=>await t(s,{action:x.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:a}}),onSuccess:()=>{n.invalidateQueries({queryKey:["revisions"]})}})},ae=()=>{const s=x.useApiUrl(),t=x.useFetch(),n=A.useQueryClient();return A.useMutation({mutationFn:async({revisionId:a,discardCurrent:i})=>await t(s,{action:x.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:a,discardCurrent:i}}),onSuccess:()=>{n.invalidateQueries({queryKey:["revisions"]})}})},I=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(j.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(j.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function re({compare:s,setCompare:t,isComparisonEnabled:n}){const{data:a}=x.useCurrentPage(),{saveState:i}=V.useSavePage(),[o]=x.usePageEditInfo();if(!a)return null;const l=!!s.find(r=>{var f;return(f=r==null?void 0:r.uid)==null?void 0:f.startsWith("draft:")}),d=s.length>=2&&!l,m=i==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(I,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!S.isEmpty(o.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",_.formatDistanceToNow(new Date(o.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(I,{tag:"unsaved"}):null})]}),n&&e.jsx(H,{checked:l,disabled:d,onChange:()=>{t(l?s.filter(r=>r.uid!==`draft:${a==null?void 0:a.id}`):[...s,{uid:`draft:${a==null?void 0:a.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function le(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,t)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(c.Skeleton,{className:"h-4 w-3/4"}),e.jsx(c.Skeleton,{className:"h-3 w-1/2"}),e.jsx(c.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(c.Skeleton,{className:"h-8 w-8 rounded-full"})]},t))})}function G({revision:s,isLatest:t,onRestore:n,onDelete:a,revisionNumber:i,compare:o,setCompare:l,pageId:d,pageLiveFullSlug:m,isComparisonEnabled:r,lang:f}){const{data:w}=x.useChaiUserInfo(s.currentEditor),R=(w==null?void 0:w.name)||"Unknown",N=!!o.find(u=>{var b;return t?(b=u==null?void 0:u.uid)==null?void 0:b.startsWith("live"):(u==null?void 0:u.uid)===s.uid}),C=o.length>=2&&!N;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[r&&e.jsx(I,{tag:t?"live":`#${i}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:R}),!r&&t&&e.jsx(I,{tag:"live"})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(I,{tag:"published"}):e.jsx(I,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:_.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.type!=="draft"&&r&&e.jsx("a",{target:"_blank",href:t?m:`/revision/revision:${s.uid}:${i}?lang=${f}`,children:e.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-4 w-4 hover:text-blue-500",children:[e.jsx(j.Eye,{className:"h-3 w-3"}),e.jsx("span",{className:"sr-only",children:"View this version"})]})}),e.jsx(x.PermissionChecker,{permissions:[x.PAGES_PERMISSIONS.RESTORE_REVISION,x.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(ce,{revision:s,onRestore:n,onDelete:a})})]}),r&&e.jsx(H,{checked:N,disabled:C,onChange:()=>{l(N?o.filter(u=>t?u.uid!==`live:${d}`:u.uid!==s.uid):[...o,{uid:t?`live:${d}`:s.uid,label:t?"live":`#${i}`,item:s}].sort((u,b)=>new Date(u.item.createdAt).getTime()-new Date(b.item.createdAt).getTime()))}})]})}function ie({compare:s,setCompare:t,pageId:n}){const[a,i]=y.useState(!1),[o,l]=s;if(s.length===0)return null;const d=({tab:m})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(I,{tag:m.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>t(s.filter(r=>r.uid!==m.uid)),"aria-label":"Remove selection 1",children:e.jsx(j.X,{className:"h-3 w-3"})})]});return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),o&&e.jsx(d,{tab:o}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),l?e.jsx(d,{tab:l}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(c.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>t([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(c.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>i(!0),disabled:s.length<2,children:[e.jsx(j.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),a&&(s==null?void 0:s.length)>1&&n&&e.jsx(se,{open:a,onOpenChange:i,compare:s})]})}function H({checked:s,disabled:t,onChange:n,label:a="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${t?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:t,onChange:n}),e.jsx("span",{className:"select-none leading-tight",children:a})]})})}function ce({revision:s,onRestore:t,onDelete:n}){return e.jsxs(c.DropdownMenu,{children:[e.jsx(c.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(c.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(j.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(c.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(x.PermissionChecker,{permission:x.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(c.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-sm",children:[e.jsx(j.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(x.PermissionChecker,{permission:x.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(c.DropdownMenuSeparator,{}),e.jsxs(c.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-destructive",children:[e.jsx(j.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function oe({open:s,onOpenChange:t,revision:n,onRestore:a,isRestoring:i}){const{data:o}=x.useChaiUserInfo((n==null?void 0:n.currentEditor)||""),l=(o==null?void 0:o.name)||"Unknown";return n?e.jsx(c.Dialog,{open:s,onOpenChange:d=>{i||t(d)},children:e.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(c.DialogHeader,{children:[e.jsx(c.DialogTitle,{children:"Restore Revision"}),e.jsxs(c.DialogDescription,{children:["You are about to restore to revision ",n.uid.substring(0,8)," from"," ",_.format(n.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",l]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(c.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>a(!1),disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(j.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(c.Button,{variant:"default",className:"sm:flex-1",onClick:()=>a(!0),disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(j.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function de({open:s,onOpenChange:t,revision:n,onDelete:a,isDeleting:i}){const{data:o}=x.useChaiUserInfo((n==null?void 0:n.currentEditor)||""),l=(o==null?void 0:o.name)||"Unknown";return n?e.jsx(c.Dialog,{open:s,onOpenChange:d=>{i||t(d)},children:e.jsxs(c.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(c.DialogHeader,{children:[e.jsx(c.DialogTitle,{children:"Delete Revision"}),e.jsxs(c.DialogDescription,{children:["You are about to delete revision ",n.uid.substring(0,8)," from"," ",_.format(n.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",l]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(c.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(c.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>t(!1),disabled:i,children:"Cancel"}),e.jsx(c.Button,{variant:"destructive",className:"sm:flex-1",onClick:a,disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(j.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ue({isOpen:s}){var F,v;const[t,n]=J.useState([]),[a,i]=J.useState(null),[o,l]=J.useState(!1),[d,m]=J.useState(!1),{data:r}=x.useCurrentPage(),{data:f,isFetching:w,error:R,refetch:N}=te(r==null?void 0:r.id),{mutate:C,isPending:u}=ne(),{mutate:b,isPending:h}=ae(),O=A.useQueryClient(),q=x.useGetPageFullSlug(),D=V.useChaiFeatureFlag("enable-page-revisions-compare"),{selectedLang:P,fallbackLang:U}=V.useLanguages(),M=P||U;y.useEffect(()=>n([]),[r==null?void 0:r.id]);const p=g=>{a&&b({revisionId:a.uid,discardCurrent:g},{onSuccess:()=>{l(!1),i(null),O.invalidateQueries({queryKey:[x.ACTIONS.GET_DRAFT_PAGE]})}})},k=g=>{i(g),l(!0)},E=g=>{i(g),m(!0)},T=()=>{a&&C(a.uid,{onSuccess:()=>{m(!1),i(null)}})};return y.useEffect(()=>{s&&N()},[s,N]),e.jsxs(e.Fragment,{children:[e.jsxs(c.SheetHeader,{children:[e.jsx(c.SheetTitle,{children:"Revision History"}),(r==null?void 0:r.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",_.format(new Date(r.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),w?e.jsx(le,{}):R?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[D&&e.jsx(ie,{lang:M,compare:t,setCompare:n,pageId:r==null?void 0:r.id}),e.jsx(re,{compare:t,setCompare:n,isComparisonEnabled:D}),(F=f==null?void 0:f.filter(g=>g.uid==="current"))==null?void 0:F.map((g,L)=>e.jsx(G,{lang:M,pageId:r==null?void 0:r.id,revision:g,isLatest:!0,onRestore:()=>k(g),onDelete:()=>E(g),revisionNumber:L,compare:t,setCompare:n,pageLiveFullSlug:q,isComparisonEnabled:D},g.uid)),e.jsx(c.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(v=f==null?void 0:f.filter(g=>g.uid!=="current"))==null?void 0:v.map((g,L)=>e.jsx(G,{lang:M,pageId:r==null?void 0:r.id,revision:g,isLatest:g.uid==="current",onRestore:()=>k(g),onDelete:()=>E(g),revisionNumber:L+1,compare:t,setCompare:n,pageLiveFullSlug:q,isComparisonEnabled:D},g.uid))})})]}),e.jsx(oe,{open:o,onOpenChange:l,revision:a,onRestore:p,isRestoring:h}),e.jsx(de,{open:d,onOpenChange:m,revision:a,onDelete:T,isDeleting:u})]})}exports.default=ue;
|