@chaibuilder/pages 0.14.4 → 0.15.1

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.
Files changed (69) hide show
  1. package/dist/{2AITGKQY-DWDDkd18.cjs → 2AITGKQY-GcbF_G3s.cjs} +1 -1
  2. package/dist/{2AITGKQY-DtQPkxBe.js → 2AITGKQY-a-BJOrVj.js} +2 -2
  3. package/dist/{NCMVHL6D-CksZXXOw.js → NCMVHL6D-CCFQEIik.js} +4 -4
  4. package/dist/{NCMVHL6D-6CkVnw0a.cjs → NCMVHL6D-fz7uxKMS.cjs} +1 -1
  5. package/dist/{ZDWCUMSJ-BXQ01VPt.js → ZDWCUMSJ-B87y4E-s.js} +1 -1
  6. package/dist/{ZDWCUMSJ-DoM-AA0C.cjs → ZDWCUMSJ-D40Aht5l.cjs} +1 -1
  7. package/dist/{add-new-language-page-D8iXtyLA.js → add-new-language-page-CxNpkd0L.js} +2 -2
  8. package/dist/{add-new-language-page-BA73lQnm.cjs → add-new-language-page-Dyh26P7i.cjs} +1 -1
  9. package/dist/{add-new-page-DESlqvED.js → add-new-page-DGQqN1GO.js} +1 -1
  10. package/dist/{add-new-page-EOMgMSeq.cjs → add-new-page-jWn3_pZ4.cjs} +1 -1
  11. package/dist/{delete-page-ZvnuEow6.cjs → delete-page-Bxl1t_Ue.cjs} +1 -1
  12. package/dist/{delete-page-BP1Df8QL.js → delete-page-WnsCggnJ.js} +1 -1
  13. package/dist/{digital-asset-manager-Bb81T3mS.js → digital-asset-manager-ClyooOJY.js} +135 -135
  14. package/dist/{digital-asset-manager-BxWb1j_y.cjs → digital-asset-manager-DrXotZ_n.cjs} +1 -1
  15. package/dist/{duplicate-page-W5xbmPSC.cjs → duplicate-page-CDtfdgyJ.cjs} +1 -1
  16. package/dist/{duplicate-page-B1j0H7gP.js → duplicate-page-DOloolXy.js} +8 -8
  17. package/dist/{dynamic-page-selector-Crjyco6l.js → dynamic-page-selector-B-8TUdTG.js} +1 -1
  18. package/dist/{dynamic-page-selector-BZKJmSx5.cjs → dynamic-page-selector-CcYIfKlO.cjs} +1 -1
  19. package/dist/index-CffopOpP.cjs +5 -0
  20. package/dist/{index-DFvsMFVH.js → index-CguzNa4U.js} +1710 -1938
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.ts +10 -14
  23. package/dist/index.js +12 -13
  24. package/dist/{json-diff-viewer-BGGSLqtx.js → json-diff-viewer-CxFGgqa_.js} +6 -6
  25. package/dist/{json-diff-viewer-DRkE-x_z.cjs → json-diff-viewer-DcR1gbkd.cjs} +1 -1
  26. package/dist/{lang-panel-B3tr2uhr.js → lang-panel-Bi427DLp.js} +2 -2
  27. package/dist/{lang-panel-9T8dIx2p.cjs → lang-panel-XonHaLBn.cjs} +1 -1
  28. package/dist/{mark-as-template-DPVPRgbi.cjs → mark-as-template-BtI1QfuI.cjs} +1 -1
  29. package/dist/{mark-as-template-L9cHzL84.js → mark-as-template-CS68JVP8.js} +1 -1
  30. package/dist/{no-language-page-content-DP7gmy0s.js → no-language-page-content-C5t9cDI4.js} +1 -1
  31. package/dist/{no-language-page-content-Cy_D-3jE.cjs → no-language-page-content-DMqw1cTK.cjs} +1 -1
  32. package/dist/{page-creator-Ctn5ixJE.js → page-creator-BY2w99Ez.js} +2 -2
  33. package/dist/{page-creator-DDaI1HYj.cjs → page-creator-BkKT_Xy1.cjs} +1 -1
  34. package/dist/{page-lock-request-BKrxnEtQ.cjs → page-lock-request-CIRTswpw.cjs} +1 -1
  35. package/dist/{page-lock-request-CjJFJKL2.js → page-lock-request-Z1sTGi6N.js} +10 -10
  36. package/dist/{page-locked-by-dialog-DmsSmAY2.js → page-locked-by-dialog-B2C1M_bK.js} +1 -1
  37. package/dist/{page-locked-by-dialog-b25_rn2m.cjs → page-locked-by-dialog-DpBpQ0oI.cjs} +1 -1
  38. package/dist/{page-manager-new-EsIg6iQn.js → page-manager-new-CSqFLJBd.js} +46 -46
  39. package/dist/{page-manager-new-DiZVY7Me.cjs → page-manager-new-tWV46glN.cjs} +1 -1
  40. package/dist/{page-manager-search-and-filter-Bt4T_dnB.js → page-manager-search-and-filter-B9VZzJQd.js} +2 -2
  41. package/dist/{page-manager-search-and-filter-CgY2qiXU.cjs → page-manager-search-and-filter-CwuukvKn.cjs} +1 -1
  42. package/dist/{page-revisions-content-DtI8CmtR.cjs → page-revisions-content-BWhJz0_7.cjs} +1 -1
  43. package/dist/{page-revisions-content-CsT6aF2I.js → page-revisions-content-WoIu0uan.js} +18 -18
  44. package/dist/{publish-pages-content-DpC7RcTw.cjs → publish-pages-content-BHDTLdGv.cjs} +1 -1
  45. package/dist/{publish-pages-content-KAuhOPv0.js → publish-pages-content-CkWvQGbm.js} +12 -12
  46. package/dist/{save-to-lib-CeWaSQdB.js → save-to-lib-AkbnWUxR.js} +13 -13
  47. package/dist/{save-to-lib-BGpWGHJo.cjs → save-to-lib-C0ZfwiAE.cjs} +1 -1
  48. package/dist/{seo-panel-JDQ_7bOx.cjs → seo-panel-CiKkn5Jp.cjs} +1 -1
  49. package/dist/{seo-panel-Dhhpe_7z.js → seo-panel-Gu3HZveQ.js} +34 -34
  50. package/dist/shared-json-ld-BPaeG1gf.cjs +1 -0
  51. package/dist/shared-json-ld-CsyZjZdT.js +557 -0
  52. package/dist/{slug-input-QxBMijHP.cjs → slug-input-B4w0Ihxn.cjs} +1 -1
  53. package/dist/{slug-input-hJdU8DaF.js → slug-input-BXNj3cZf.js} +1 -1
  54. package/dist/{theme-panel-footer-D2B7iYW2.js → theme-panel-footer-68bQaQeh.js} +1 -1
  55. package/dist/{theme-panel-footer-BZnPvTkM.cjs → theme-panel-footer-DnZs9SzB.cjs} +1 -1
  56. package/dist/{unmark-as-template-Byn2RRAp.cjs → unmark-as-template-DFxmzyx4.cjs} +1 -1
  57. package/dist/{unmark-as-template-Dcpkj7EZ.js → unmark-as-template-MpXMyb0Q.js} +1 -1
  58. package/dist/{unpublish-page-CPLlsfm4.js → unpublish-page-Bzouoco9.js} +1 -1
  59. package/dist/{unpublish-page-5Fi1wKXb.cjs → unpublish-page-CCPyMoaC.cjs} +1 -1
  60. package/dist/use-page-expand-manager-2KjeYfVS.cjs +1 -0
  61. package/dist/use-page-expand-manager-D6T75I11.js +184 -0
  62. package/dist/{web-preview-CVvxe5Ll.cjs → web-preview-B3-o8BoT.cjs} +1 -1
  63. package/dist/{web-preview-YuuoRaZn.js → web-preview-D9PcexXy.js} +1 -1
  64. package/package.json +1 -1
  65. package/dist/index-Qnh8Lkr0.cjs +0 -5
  66. package/dist/shared-json-ld-BYbdMttx.cjs +0 -1
  67. package/dist/shared-json-ld-BliIbNv9.js +0 -337
  68. package/dist/use-page-expand-manager-DkyBiNpx.js +0 -85
  69. package/dist/use-page-expand-manager-To-SsGy3.cjs +0 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-Qnh8Lkr0.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.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]})});
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-CffopOpP.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.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
@@ -1,9 +1,7 @@
1
1
  import { ChaiBuilderEditorProps } from '@chaibuilder/sdk';
2
- import { ComponentType } from 'react';
3
2
  import { default as default_2 } from 'react';
4
3
  import { JSX } from 'react/jsx-runtime';
5
4
  import { ReactNode } from 'react';
6
- import { RESET } from 'jotai/utils';
7
5
  import { SupabaseClient } from '@supabase/supabase-js';
8
6
  import { UseMutationResult } from '@tanstack/react-query';
9
7
  import { UseQueryResult } from '@tanstack/react-query';
@@ -20,8 +18,9 @@ declare type ChaiBuilderPagesProps = {
20
18
  getPreviewUrl?: (slug: string) => string;
21
19
  getLiveUrl?: (slug: string) => string;
22
20
  onLogout?: () => void;
23
- getAccessToken?: () => Promise<string>;
24
- supabaseInstance?: SupabaseClient;
21
+ getAccessToken: () => Promise<string>;
22
+ currentUser: LoggedInUser | null;
23
+ websocket?: ChaiWebSocketClient;
25
24
  features?: {
26
25
  sharedJsonLD?: boolean;
27
26
  canResetSeoToDefault?: boolean;
@@ -30,13 +29,13 @@ declare type ChaiBuilderPagesProps = {
30
29
 
31
30
  export declare class ChaiBuilderPagesRealtime implements ChaiBuilderPagesRealtimeInterface {
32
31
  private channelId;
33
- private supabase;
32
+ private websocket;
34
33
  private channel;
35
34
  private userId;
36
35
  private clientId;
37
36
  private pageId;
38
37
  private callback;
39
- constructor(supabase: SupabaseClient, websiteId: string, userId: string, cb: (event: string, payload?: any) => void);
38
+ constructor(websocket: SupabaseClient, websiteId: string, userId: string, cb: (event: string, payload?: any) => void);
40
39
  private getClientId;
41
40
  private getOnlineUsers;
42
41
  private getPageOwner;
@@ -62,6 +61,8 @@ declare type ChaiWebsiteSetting = {
62
61
  theme: Record<"fontFamily" | "borderRadius" | "colors", any>;
63
62
  };
64
63
 
64
+ declare type ChaiWebSocketClient = SupabaseClient;
65
+
65
66
  declare type EVENT_PAYLOAD = {
66
67
  senderClientId?: string;
67
68
  targetClientId?: string;
@@ -90,13 +91,11 @@ export declare const LanguageSwitcher: ({ showAdd, variant, }: {
90
91
  declare type LISTEN_EVENTS = "PAGE_LOCKED" | "USER_JOINED" | "TAKE_OVER_REQUESTED" | "UPDATE_ONLINE_USERS" | "TAKE_OVER_REQUEST_ACCEPTED" | "TAKE_OVER_REQUEST_REJECTED";
91
92
 
92
93
  declare type LoggedInUser = {
93
- accessToken: string;
94
- refreshToken: string;
95
94
  id: string;
96
95
  email: string;
97
96
  name: string;
98
97
  avatar?: string;
99
- expiresAt: number;
98
+ metadata?: Record<string, any>;
100
99
  };
101
100
 
102
101
  export declare function NestedPathSelector({ data, onSelect, dataType, disabled }: NestedPathSelectorProps): JSX.Element;
@@ -115,8 +114,6 @@ export declare const PermissionChecker: ({ permission, permissions, children, fa
115
114
  children: React.ReactNode;
116
115
  }) => ReactNode;
117
116
 
118
- export declare const registerChaiLoginComponent: (component: ComponentType) => void;
119
-
120
117
  declare interface SmartJsonInputProps {
121
118
  value: string;
122
119
  onChange: (value: string) => void;
@@ -140,9 +137,8 @@ export declare const useBuilderPageData: () => UseQueryResult<any, Error>;
140
137
 
141
138
  export declare const useChaiAuth: () => {
142
139
  readonly isLoggedIn: boolean;
143
- readonly user: LoggedInUser | null;
144
- readonly setUser: (args_0: LoggedInUser | RESET | ((prev: LoggedInUser | null) => LoggedInUser | RESET | null) | null) => void;
145
- readonly logout: () => void;
140
+ readonly user: any;
141
+ readonly logout: any;
146
142
  };
147
143
 
148
144
  export declare const useChaiCurrentPage: () => {
package/dist/index.js CHANGED
@@ -1,29 +1,28 @@
1
- import { aT as s, aI as t, aH as u, aF as i, aG as g, av as r, aK as o, aP as P, aL as h, aC as n, aQ as l, am as C, aS as c, aq as m, aM as d, f as p, al as f, aN as L, g as b, h as A, aO as F, an as I, aR as S, b as k, e as v } from "./index-DFvsMFVH.js";
1
+ import { aW as s, aL as u, aK as t, aI as i, aJ as g, ar as r, aN as P, aO as h, aF as o, aT as l, aq as n, aV as c, aj as C, aP as d, f as m, am as f, aQ as p, g as b, h as A, aR as F, aS as I, aU as L, b as S, e as U } from "./index-CguzNa4U.js";
2
2
  export * from "@chaibuilder/sdk";
3
3
  export {
4
4
  s as ChaiBuilderPagesRealtime,
5
- t as ChaiJsonInput,
6
- u as ImagePicker,
5
+ u as ChaiJsonInput,
6
+ t as ImagePicker,
7
7
  i as LanguageSwitcher,
8
8
  g as NestedPathSelector,
9
9
  r as PermissionChecker,
10
- o as default,
11
- P as registerChaiLoginComponent,
10
+ P as default,
12
11
  h as useActivePage,
13
- n as useBuilderPageData,
12
+ o as useBuilderPageData,
14
13
  l as useChaiAuth,
15
- C as useChaiCurrentPage,
14
+ n as useChaiCurrentPage,
16
15
  c as useChaiFetch,
17
- m as useChaiUserInfo,
16
+ C as useChaiUserInfo,
18
17
  d as useClearAll,
19
- p as useFallbackLang,
18
+ m as useFallbackLang,
20
19
  f as useFetch,
21
- L as useGotoPage,
20
+ p as useGotoPage,
22
21
  b as useLanguagePages,
23
22
  A as usePageTypes,
24
23
  F as useReloadPage,
25
24
  I as useUpdateActivePageMetadata,
26
- S as useUserPermissions,
27
- k as useWebsitePages,
28
- v as useWebsiteSetting
25
+ L as useUserPermissions,
26
+ S as useWebsitePages,
27
+ U as useWebsiteSetting
29
28
  };
@@ -1,11 +1,11 @@
1
1
  import { jsx as e, jsxs as h } from "react/jsx-runtime";
2
- import { Dialog as U, DialogContent as V, DialogHeader as _, DialogTitle as G, Switch as $, ScrollArea as I, Button as z, Badge as P } from "@chaibuilder/sdk/ui";
2
+ import { Dialog as V, DialogContent as _, DialogHeader as q, DialogTitle as G, Switch as $, ScrollArea as I, Button as z, Badge as P } from "@chaibuilder/sdk/ui";
3
3
  import { formatDate as Q } from "date-fns";
4
4
  import { startsWith as T, replace as W, isString as X, trim as Y, isArray as Z, map as ee, isPlainObject as te, mapValues as re } from "lodash-es";
5
5
  import { FileJson as F, Loader as ne, Check as B, Copy as H } from "lucide-react";
6
6
  import { useState as D, useMemo as A } from "react";
7
7
  import { parseDiff as se, Diff as le, Hunk as ae } from "react-diff-view";
8
- import { ak as ie, al as oe, A as ce, aq as de } from "./index-DFvsMFVH.js";
8
+ import { al as ie, am as oe, A as ce, aj as de } from "./index-CguzNa4U.js";
9
9
  import { useQuery as fe } from "@tanstack/react-query";
10
10
  function me(t, n) {
11
11
  const o = ie(), s = oe(), u = T(t.uid, "draft:") || T(n.uid, "live:");
@@ -157,7 +157,7 @@ const pe = (t) => {
157
157
  }), u;
158
158
  };
159
159
  function Te({ open: t, compare: n, onOpenChange: o }) {
160
- const s = n[0], u = n[1], [l, r] = D(null), [d, f] = D("split"), [c, p] = D(!1), [y, j] = D(!0), [g, N] = D("blocks"), { data: m, isLoading: x } = me(s, u), { leftData: a, rightData: w, options: q } = A(() => {
160
+ const s = n[0], u = n[1], [l, r] = D(null), [d, f] = D("split"), [c, p] = D(!1), [y, j] = D(!0), [g, N] = D("blocks"), { data: m, isLoading: x } = me(s, u), { leftData: a, rightData: w, options: U } = A(() => {
161
161
  var b, R;
162
162
  const i = (b = m == null ? void 0 : m.version1) == null ? void 0 : b[g], v = (R = m == null ? void 0 : m.version2) == null ? void 0 : R[g], k = S(i), C = S(v), J = ge(m == null ? void 0 : m.version1, m == null ? void 0 : m.version2);
163
163
  return { leftData: k, rightData: C, options: J };
@@ -175,13 +175,13 @@ function Te({ open: t, compare: n, onOpenChange: o }) {
175
175
  console.error("Failed to copy:", k);
176
176
  }
177
177
  }, M = (i) => JSON.stringify(i, null, 2);
178
- return /* @__PURE__ */ e(U, { open: t, onOpenChange: o, children: /* @__PURE__ */ h(V, { className: "flex h-[90vh] w-[95vw] max-w-[1900px] flex-col p-6", children: [
179
- /* @__PURE__ */ e(_, { className: "pb-4 pt-0", children: /* @__PURE__ */ h(G, { className: "flex items-center justify-between gap-2 leading-none", children: [
178
+ return /* @__PURE__ */ e(V, { open: t, onOpenChange: o, children: /* @__PURE__ */ h(_, { className: "flex h-[90vh] w-[95vw] max-w-[1900px] flex-col p-6", children: [
179
+ /* @__PURE__ */ e(q, { className: "pb-4 pt-0", children: /* @__PURE__ */ h(G, { className: "flex items-center justify-between gap-2 leading-none", children: [
180
180
  /* @__PURE__ */ h("div", { className: "flex items-center gap-2", children: [
181
181
  /* @__PURE__ */ e(F, { className: "h-5 w-5" }),
182
182
  "Compare",
183
183
  "",
184
- q.map((i) => /* @__PURE__ */ e(
184
+ U.map((i) => /* @__PURE__ */ e(
185
185
  "div",
186
186
  {
187
187
  className: `cursor-pointer rounded-full border px-2.5 py-1 text-xs leading-none ${g === i.key ? "border-blue-500 bg-blue-500 text-white" : "border-gray-600 text-gray-600 hover:bg-gray-200"}`,
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk/ui"),z=require("date-fns"),p=require("lodash-es"),N=require("lucide-react"),b=require("react"),M=require("react-diff-view"),O=require("./index-Qnh8Lkr0.cjs"),B=require("@tanstack/react-query");function H(t,r){const o=O.useApiUrl(),n=O.useFetch(),f=p.startsWith(t.uid,"draft:")||p.startsWith(r.uid,"live:");return B.useQuery({queryKey:["revision-comparison",t.uid,r.uid],queryFn:async()=>{if(!t.uid||!r.uid)throw new Error("Both revision IDs are required for comparison");const l=u=>u==="draft"||u==="live"?u:"revision",s=u=>p.replace(u.uid,`${u.label}:`,"");return await n(o,{action:O.ACTIONS.GET_COMPARE_DATA,data:{versions:{version1:{type:l(t.label),id:s(t)},version2:{type:l(r.label),id:s(r)}}}})},enabled:!!t.uid&&!!r.uid,staleTime:f?0:1/0})}const K=({version:t})=>{const r=t==null?void 0:t.item,{data:o}=O.useChaiUserInfo(r==null?void 0:r.currentEditor),n=t.label==="live",f=t.label==="draft";return e.jsxs("span",{className:`flex items-center gap-x-2 rounded border bg-white px-2 text-xs shadow-lg ${n?"border-green-500/30":f?"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"+(n?" bg-green-500 text-green-50":f?" bg-amber-500 text-amber-50":" bg-purple-500 text-purple-50"),children:t.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:f?"Currently editing":"Published by"}),!f&&e.jsx("span",{className:"pl-1 font-medium",children:(o==null?void 0:o.name)||"Unknown"})]}),e.jsx("div",{className:"text-[10px] leading-tight",children:z.formatDate(r.createdAt,"dd MMM yyyy, h:mm a")})]})]})},L=({version:t})=>e.jsx(K,{version:t});function V(t,r,o="data.json"){const n=JSON.stringify(t,null,2),f=JSON.stringify(r,null,2),l=n.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk/ui"),z=require("date-fns"),p=require("lodash-es"),N=require("lucide-react"),b=require("react"),M=require("react-diff-view"),O=require("./index-CffopOpP.cjs"),B=require("@tanstack/react-query");function H(t,r){const o=O.useApiUrl(),n=O.useFetch(),f=p.startsWith(t.uid,"draft:")||p.startsWith(r.uid,"live:");return B.useQuery({queryKey:["revision-comparison",t.uid,r.uid],queryFn:async()=>{if(!t.uid||!r.uid)throw new Error("Both revision IDs are required for comparison");const l=u=>u==="draft"||u==="live"?u:"revision",s=u=>p.replace(u.uid,`${u.label}:`,"");return await n(o,{action:O.ACTIONS.GET_COMPARE_DATA,data:{versions:{version1:{type:l(t.label),id:s(t)},version2:{type:l(r.label),id:s(r)}}}})},enabled:!!t.uid&&!!r.uid,staleTime:f?0:1/0})}const K=({version:t})=>{const r=t==null?void 0:t.item,{data:o}=O.useChaiUserInfo(r==null?void 0:r.currentEditor),n=t.label==="live",f=t.label==="draft";return e.jsxs("span",{className:`flex items-center gap-x-2 rounded border bg-white px-2 text-xs shadow-lg ${n?"border-green-500/30":f?"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"+(n?" bg-green-500 text-green-50":f?" bg-amber-500 text-amber-50":" bg-purple-500 text-purple-50"),children:t.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:f?"Currently editing":"Published by"}),!f&&e.jsx("span",{className:"pl-1 font-medium",children:(o==null?void 0:o.name)||"Unknown"})]}),e.jsx("div",{className:"text-[10px] leading-tight",children:z.formatDate(r.createdAt,"dd MMM yyyy, h:mm a")})]})]})},L=({version:t})=>e.jsx(K,{version:t});function V(t,r,o="data.json"){const n=JSON.stringify(t,null,2),f=JSON.stringify(r,null,2),l=n.split(`
2
2
  `),s=f.split(`
3
3
  `);let d=`--- a/${o}
4
4
  `;d+=`+++ b/${o}
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as s, Fragment as $ } from "react/jsx-runtime";
2
- import { at as M, h as k, L as I, au as j, g as F, am as H, e as O, av as g, aw as c, C as x } from "./index-DFvsMFVH.js";
2
+ import { ao as M, h as k, L as I, ap as j, g as F, aq as H, e as O, ar as g, as as c, C as x } from "./index-CguzNa4U.js";
3
3
  import { Dialog as W, DialogContent as B, DialogHeader as q, DialogTitle as R, DialogDescription as J, Alert as K, Label as Q, Input as V, DialogFooter as X, Button as A, DropdownMenu as Y, DropdownMenuTrigger as Z, DropdownMenuContent as ee, DropdownMenuItem as b } from "@chaibuilder/sdk/ui";
4
4
  import { find as G, startsWith as w, isEqual as se, filter as ae, get as D, map as le, isEmpty as ne } from "lodash-es";
5
5
  import { AlertCircle as te, StarIcon as ie, MoreHorizontal as re, PencilIcon as ce, Power as oe, TrashIcon as de } from "lucide-react";
@@ -83,7 +83,7 @@ const pe = ({
83
83
  ) })
84
84
  ] })
85
85
  ] }) });
86
- }, Ne = U(() => import("./delete-page-BP1Df8QL.js")), fe = U(() => import("./unpublish-page-CPLlsfm4.js")), Ae = () => {
86
+ }, Ne = U(() => import("./delete-page-WnsCggnJ.js")), fe = U(() => import("./unpublish-page-Bzouoco9.js")), Ae = () => {
87
87
  const [, a] = ge(j), { selectedLang: p, fallbackLang: t, setSelectedLang: v } = he(), { data: N, isFetching: f } = F(), { data: n } = H(), { data: i } = k(), y = me(() => {
88
88
  const l = i == null ? void 0 : i.find((u) => u.key === (n == null ? void 0 : n.pageType));
89
89
  return n != null && n.dynamic ? l == null ? void 0 : l.dynamicSlug : "";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-Qnh8Lkr0.cjs"),i=require("@chaibuilder/sdk/ui"),a=require("lodash-es"),g=require("lucide-react"),r=require("react"),w=require("sonner"),D=require("@chaibuilder/sdk"),T=require("jotai"),L=({page:n,onClose:S})=>{const[c,y]=r.useState(n.slug||""),{mutate:N,isPending:p}=s.useChangeSlug(),{data:l}=s.usePageTypes(),o=a.find(l,{key:n==null?void 0:n.pageType}),E=m=>{if(m.preventDefault(),!(n!=null&&n.primaryPage)&&Object.keys(s.LANGUAGES).some(j=>c===`/${j}`||a.startsWith(c,`/${j}/`))){w.toast.error("Error",{description:"Slugs cannot start with a language code for primary page"});return}N({...n,slug:c},{onSuccess:S})},u=(n==null?void 0:n.lang)||"";return e.jsx(i.Dialog,{open:!!n,onOpenChange:S,children:e.jsxs(i.DialogContent,{children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Change Slug"}),e.jsx(i.DialogDescription,{className:"text-xs",children:e.jsxs(i.Alert,{variant:"destructive",className:"mt-2",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),"Changing the slug may have impact on your SEO. Please proceed with caution."]})})]}),e.jsxs("form",{onSubmit:E,children:[e.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Type:"}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(o==null?void 0:o.name)||(n==null?void 0:n.pageType)]})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Name:"}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",n.name]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(i.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",e.jsxs("small",{className:"font-light text-gray-500",children:["Slug should start with /",u]})]}),e.jsx(i.Input,{id:"slug",value:c,onChange:m=>{const h=m.target.value;a.startsWith(h,`/${u}`)&&y(h)},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),e.jsx(i.DialogFooter,{children:e.jsx(i.Button,{type:"submit",disabled:p||!a.startsWith(c,`/${u}`)||a.isEqual(n==null?void 0:n.slug,c),children:p?"Changing...":"Change Slug"})})]})]})})},G=r.lazy(()=>Promise.resolve().then(()=>require("./delete-page-ZvnuEow6.cjs"))),k=r.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-5Fi1wKXb.cjs"))),M=()=>{const[,n]=T.useAtom(s.addNewLangAtom),{selectedLang:S,fallbackLang:c,setSelectedLang:y}=D.useLanguages(),{data:N,isFetching:p}=s.useLanguagePages(),{data:l}=s.useCurrentPage(),{data:o}=s.usePageTypes(),E=r.useMemo(()=>{const t=o==null?void 0:o.find(x=>x.key===(l==null?void 0:l.pageType));return l!=null&&l.dynamic?t==null?void 0:t.dynamicSlug:""},[o,l==null?void 0:l.pageType,l==null?void 0:l.dynamic]),[u,m]=r.useState(null),[h,f]=r.useState(null),[j,b]=r.useState(null),{data:C}=s.useWebsiteSetting(),A=a.filter(a.get(C,"languages")||["en"],t=>!a.find(N,{lang:t})&&t!==a.get(C,"fallbackLang"));return e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-2",children:p?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"})]}):a.map(N,t=>{const x=t.lang,P=t.slug,v=!t.primaryPage,I=x===S;return e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${I?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>y(x),children:[e.jsxs("div",{className:"flex-1 gap-x-3",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-[13px] text-slate-800",children:[e.jsx("div",{className:`h-2.5 w-2.5 rounded-full ${t.online?"bg-green-300":"bg-gray-300"}`}),a.get(s.LANGUAGES,v?c:x,x)]}),e.jsxs("div",{children:[P&&e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Slug: ",e.jsx("b",{className:"font-mono font-medium",children:E?`${P}/${E}`:P})]}),e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Name:",e.jsxs("b",{className:"font-medium",children:[" ",t.name," "]})]})]})]}),v?e.jsxs("div",{className:"flex items-center gap-x-1 text-[11px] text-orange-500",children:[e.jsx(g.StarIcon,{fill:"orange",className:"h-3 w-3"}),e.jsx("b",{children:" Primary"})]}):e.jsx("div",{className:"flex items-center gap-x-3",children:e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.EDIT_PAGE,s.PAGES_PERMISSIONS.DELETE_PAGE,s.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:e.jsxs(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,onClick:d=>d.stopPropagation(),children:e.jsx(i.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:e.jsx(g.MoreHorizontal,{className:"h-4 w-4"})})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"z-[9999] text-sm",children:[e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.EDIT_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),n({edit:!0,id:t.id,primaryPage:t.primaryPage})},children:[e.jsx(g.PencilIcon,{className:"size-3"}),s.CONTENT.EDIT]})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:(t==null?void 0:t.online)&&e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),f(t)},children:[e.jsx(g.Power,{className:"size-3"}),s.CONTENT.UNPUBLISH]})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.DELETE_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),m(t)},children:[e.jsx(g.TrashIcon,{className:"size-3"}),s.CONTENT.DELETE]})})]})]})})})]},t.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.ADD_PAGE],children:e.jsx("div",{className:"flex w-full justify-center",children:e.jsx(i.Button,{variant:"default",size:"sm",disabled:a.isEmpty(A),onClick:()=>{n({primaryPage:l==null?void 0:l.id,edit:!1})},children:s.CONTENT.ADD_NEW_LANGUAGE})})}),u&&e.jsx(r.Suspense,{children:e.jsx(G,{page:u,onClose:()=>m(null)})}),h&&e.jsx(r.Suspense,{children:e.jsx(k,{page:h,onClose:()=>f(null)})}),j&&e.jsx(r.Suspense,{children:e.jsx(L,{page:j,onClose:()=>b(null)})})]})};exports.default=M;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-CffopOpP.cjs"),i=require("@chaibuilder/sdk/ui"),a=require("lodash-es"),g=require("lucide-react"),r=require("react"),w=require("sonner"),D=require("@chaibuilder/sdk"),T=require("jotai"),L=({page:n,onClose:S})=>{const[c,y]=r.useState(n.slug||""),{mutate:N,isPending:p}=s.useChangeSlug(),{data:l}=s.usePageTypes(),o=a.find(l,{key:n==null?void 0:n.pageType}),E=m=>{if(m.preventDefault(),!(n!=null&&n.primaryPage)&&Object.keys(s.LANGUAGES).some(j=>c===`/${j}`||a.startsWith(c,`/${j}/`))){w.toast.error("Error",{description:"Slugs cannot start with a language code for primary page"});return}N({...n,slug:c},{onSuccess:S})},u=(n==null?void 0:n.lang)||"";return e.jsx(i.Dialog,{open:!!n,onOpenChange:S,children:e.jsxs(i.DialogContent,{children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Change Slug"}),e.jsx(i.DialogDescription,{className:"text-xs",children:e.jsxs(i.Alert,{variant:"destructive",className:"mt-2",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),"Changing the slug may have impact on your SEO. Please proceed with caution."]})})]}),e.jsxs("form",{onSubmit:E,children:[e.jsxs("div",{className:"space-y-4 py-4 text-sm ",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Type:"}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",(o==null?void 0:o.name)||(n==null?void 0:n.pageType)]})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Name:"}),e.jsxs("span",{className:"font-medium text-gray-600",children:[" ",n.name]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(i.Label,{htmlFor:"slug",className:"text-right",children:["Slug"," ",e.jsxs("small",{className:"font-light text-gray-500",children:["Slug should start with /",u]})]}),e.jsx(i.Input,{id:"slug",value:c,onChange:m=>{const h=m.target.value;a.startsWith(h,`/${u}`)&&y(h)},className:"col-span-3",required:!0,pattern:"^/.*",title:"Slug must start with /",placeholder:"Enter page slug"})]})]}),e.jsx(i.DialogFooter,{children:e.jsx(i.Button,{type:"submit",disabled:p||!a.startsWith(c,`/${u}`)||a.isEqual(n==null?void 0:n.slug,c),children:p?"Changing...":"Change Slug"})})]})]})})},G=r.lazy(()=>Promise.resolve().then(()=>require("./delete-page-Bxl1t_Ue.cjs"))),k=r.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-CCPyMoaC.cjs"))),M=()=>{const[,n]=T.useAtom(s.addNewLangAtom),{selectedLang:S,fallbackLang:c,setSelectedLang:y}=D.useLanguages(),{data:N,isFetching:p}=s.useLanguagePages(),{data:l}=s.useCurrentPage(),{data:o}=s.usePageTypes(),E=r.useMemo(()=>{const t=o==null?void 0:o.find(x=>x.key===(l==null?void 0:l.pageType));return l!=null&&l.dynamic?t==null?void 0:t.dynamicSlug:""},[o,l==null?void 0:l.pageType,l==null?void 0:l.dynamic]),[u,m]=r.useState(null),[h,f]=r.useState(null),[j,b]=r.useState(null),{data:C}=s.useWebsiteSetting(),A=a.filter(a.get(C,"languages")||["en"],t=>!a.find(N,{lang:t})&&t!==a.get(C,"fallbackLang"));return e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-2",children:p?e.jsxs("div",{className:"w-full space-y-3 py-4",children:[e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"}),e.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-gray-300"})]}):a.map(N,t=>{const x=t.lang,P=t.slug,v=!t.primaryPage,I=x===S;return e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:`flex w-full cursor-pointer items-center justify-between rounded p-2 text-slate-500 ${I?"bg-gray-200":"hover:bg-gray-100"}`,onClick:()=>y(x),children:[e.jsxs("div",{className:"flex-1 gap-x-3",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-[13px] text-slate-800",children:[e.jsx("div",{className:`h-2.5 w-2.5 rounded-full ${t.online?"bg-green-300":"bg-gray-300"}`}),a.get(s.LANGUAGES,v?c:x,x)]}),e.jsxs("div",{children:[P&&e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Slug: ",e.jsx("b",{className:"font-mono font-medium",children:E?`${P}/${E}`:P})]}),e.jsxs("div",{className:"text-[11px] font-light text-slate-600",children:["Name:",e.jsxs("b",{className:"font-medium",children:[" ",t.name," "]})]})]})]}),v?e.jsxs("div",{className:"flex items-center gap-x-1 text-[11px] text-orange-500",children:[e.jsx(g.StarIcon,{fill:"orange",className:"h-3 w-3"}),e.jsx("b",{children:" Primary"})]}):e.jsx("div",{className:"flex items-center gap-x-3",children:e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.EDIT_PAGE,s.PAGES_PERMISSIONS.DELETE_PAGE,s.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:e.jsxs(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,onClick:d=>d.stopPropagation(),children:e.jsx(i.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:e.jsx(g.MoreHorizontal,{className:"h-4 w-4"})})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"z-[9999] text-sm",children:[e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.EDIT_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),n({edit:!0,id:t.id,primaryPage:t.primaryPage})},children:[e.jsx(g.PencilIcon,{className:"size-3"}),s.CONTENT.EDIT]})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.UNPUBLISH_PAGE],children:(t==null?void 0:t.online)&&e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),f(t)},children:[e.jsx(g.Power,{className:"size-3"}),s.CONTENT.UNPUBLISH]})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.DELETE_PAGE],children:e.jsxs(i.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:d=>{d.stopPropagation(),m(t)},children:[e.jsx(g.TrashIcon,{className:"size-3"}),s.CONTENT.DELETE]})})]})]})})})]},t.id),e.jsx("div",{className:"h-1 w-full border-b"})]})})}),e.jsx(s.PermissionChecker,{permissions:[s.PAGES_PERMISSIONS.ADD_PAGE],children:e.jsx("div",{className:"flex w-full justify-center",children:e.jsx(i.Button,{variant:"default",size:"sm",disabled:a.isEmpty(A),onClick:()=>{n({primaryPage:l==null?void 0:l.id,edit:!1})},children:s.CONTENT.ADD_NEW_LANGUAGE})})}),u&&e.jsx(r.Suspense,{children:e.jsx(G,{page:u,onClose:()=>m(null)})}),h&&e.jsx(r.Suspense,{children:e.jsx(k,{page:h,onClose:()=>f(null)})}),j&&e.jsx(r.Suspense,{children:e.jsx(L,{page:j,onClose:()=>b(null)})})]})};exports.default=M;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./index-Qnh8Lkr0.cjs"),s=require("@chaibuilder/sdk/ui"),b=require("lodash-es"),o=require("lucide-react"),i=require("react"),y=require("sonner"),S=1*1024*1024,M=({page:n,onClose:d})=>{const[h,m]=i.useState(!1),[g,w]=i.useState(""),[l,f]=i.useState(""),[j,u]=i.useState(!1),r=i.useRef(null),k=v.useMarkAsTemplate(),{data:p}=v.usePageTypes(),x=p==null?void 0:p.find(a=>a.key===n.pageType),C=(x==null?void 0:x.name)||b.startCase(n.pageType),I=i.useCallback(a=>{var N;const c=(N=a.target.files)==null?void 0:N[0];if(c){if(c.size>S){y.toast.error("File too large",{description:`Maximum file size is 1MB. Selected file is ${(c.size/1024).toFixed(2)}KB.`}),r.current&&(r.current.value="");return}try{u(!0);const t=new FileReader;t.onloadend=()=>{f(t.result),u(!1)},t.readAsDataURL(c)}catch(t){console.error("Error reading file:",t),u(!1),y.toast.error("Failed to process image",{description:t instanceof Error?t.message:"Unknown error"})}}},[]),T=()=>{f(""),r.current&&(r.current.value="")},D=()=>{var a;(a=r.current)==null||a.click()},F=()=>{m(!0),k.mutate({page:n,name:n.name,description:g.trim()||void 0,pageType:n.pageType,...l?{previewImage:l}:{}},{onSuccess:()=>{m(!1),d()},onError:()=>{m(!1)}})};return e.jsx(s.Dialog,{open:!0,onOpenChange:d,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Mark as template"}),e.jsxs(s.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:["Are you sure you want to mark this page as a template?",e.jsx("br",{}),"Templates can be used to create new pages with the same content."]})]}),e.jsxs("div",{className:"mb-4 space-y-4 text-xs",children:[e.jsxs("div",{className:"space-y-3 rounded border bg-slate-50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.Tag,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Page Name:"}),e.jsx("span",{className:"font-semibold",children:b.startCase(n.name)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.File,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Type:"}),e.jsx("span",{className:"font-semibold",children:C})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"description",className:"text-xs font-medium",children:"Description (Optional)"}),e.jsx(s.Textarea,{id:"description",placeholder:"Describe this template's purpose",className:"mt-1 h-24 resize-none text-xs",value:g,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:"Preview Image (Optional)"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input,{type:"file",id:"previewImage",ref:r,onChange:I,accept:"image/*",className:"hidden"}),e.jsx(s.Button,{type:"button",variant:"outline",onClick:D,disabled:j,className:"w-full",children:j?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(o.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),l&&e.jsx(s.Button,{type:"button",variant:"outline",size:"icon",onClick:T,children:e.jsx(o.X,{className:"h-4 w-4"})})]}),l&&e.jsx("div",{className:"aspect-video overflow-hidden rounded-md border",children:e.jsx("img",{src:l,alt:"Preview",className:"h-full max-h-[200px] w-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]})]})]}),e.jsxs(s.DialogFooter,{className:h?"pointer-events-none opacity-75":"",children:[e.jsx(s.Button,{variant:"outline",onClick:a=>{a.stopPropagation(),d()},children:"Cancel"}),e.jsx(s.Button,{variant:"default",disabled:h,onClick:F,children:"Mark as template"})]})]})})};exports.default=M;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./index-CffopOpP.cjs"),s=require("@chaibuilder/sdk/ui"),b=require("lodash-es"),o=require("lucide-react"),i=require("react"),y=require("sonner"),S=1*1024*1024,M=({page:n,onClose:d})=>{const[h,m]=i.useState(!1),[g,w]=i.useState(""),[l,f]=i.useState(""),[j,u]=i.useState(!1),r=i.useRef(null),k=v.useMarkAsTemplate(),{data:p}=v.usePageTypes(),x=p==null?void 0:p.find(a=>a.key===n.pageType),C=(x==null?void 0:x.name)||b.startCase(n.pageType),I=i.useCallback(a=>{var N;const c=(N=a.target.files)==null?void 0:N[0];if(c){if(c.size>S){y.toast.error("File too large",{description:`Maximum file size is 1MB. Selected file is ${(c.size/1024).toFixed(2)}KB.`}),r.current&&(r.current.value="");return}try{u(!0);const t=new FileReader;t.onloadend=()=>{f(t.result),u(!1)},t.readAsDataURL(c)}catch(t){console.error("Error reading file:",t),u(!1),y.toast.error("Failed to process image",{description:t instanceof Error?t.message:"Unknown error"})}}},[]),T=()=>{f(""),r.current&&(r.current.value="")},D=()=>{var a;(a=r.current)==null||a.click()},F=()=>{m(!0),k.mutate({page:n,name:n.name,description:g.trim()||void 0,pageType:n.pageType,...l?{previewImage:l}:{}},{onSuccess:()=>{m(!1),d()},onError:()=>{m(!1)}})};return e.jsx(s.Dialog,{open:!0,onOpenChange:d,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Mark as template"}),e.jsxs(s.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:["Are you sure you want to mark this page as a template?",e.jsx("br",{}),"Templates can be used to create new pages with the same content."]})]}),e.jsxs("div",{className:"mb-4 space-y-4 text-xs",children:[e.jsxs("div",{className:"space-y-3 rounded border bg-slate-50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.Tag,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Page Name:"}),e.jsx("span",{className:"font-semibold",children:b.startCase(n.name)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.File,{className:"h-4 w-4 text-slate-500"}),e.jsx("span",{className:"font-medium text-slate-500",children:"Type:"}),e.jsx("span",{className:"font-semibold",children:C})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"description",className:"text-xs font-medium",children:"Description (Optional)"}),e.jsx(s.Textarea,{id:"description",placeholder:"Describe this template's purpose",className:"mt-1 h-24 resize-none text-xs",value:g,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"previewImage",className:"text-xs font-medium",children:"Preview Image (Optional)"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input,{type:"file",id:"previewImage",ref:r,onChange:I,accept:"image/*",className:"hidden"}),e.jsx(s.Button,{type:"button",variant:"outline",onClick:D,disabled:j,className:"w-full",children:j?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(o.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),l&&e.jsx(s.Button,{type:"button",variant:"outline",size:"icon",onClick:T,children:e.jsx(o.X,{className:"h-4 w-4"})})]}),l&&e.jsx("div",{className:"aspect-video overflow-hidden rounded-md border",children:e.jsx("img",{src:l,alt:"Preview",className:"h-full max-h-[200px] w-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"max 1mb"})]})]})]}),e.jsxs(s.DialogFooter,{className:h?"pointer-events-none opacity-75":"",children:[e.jsx(s.Button,{variant:"outline",onClick:a=>{a.stopPropagation(),d()},children:"Cancel"}),e.jsx(s.Button,{variant:"default",disabled:h,onClick:F,children:"Mark as template"})]})]})})};exports.default=M;
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as a } from "react/jsx-runtime";
2
- import { n as A, h as P } from "./index-DFvsMFVH.js";
2
+ import { n as A, h as P } from "./index-CguzNa4U.js";
3
3
  import { Dialog as z, DialogContent as E, DialogHeader as L, DialogTitle as S, DialogDescription as U, Label as b, Textarea as B, Input as R, Button as o, DialogFooter as j } from "@chaibuilder/sdk/ui";
4
4
  import { startCase as w } from "lodash-es";
5
5
  import { Tag as O, File as X, ImageIcon as _, X as H } from "lucide-react";
@@ -1,5 +1,5 @@
1
1
  import { jsx as a, jsxs as n } from "react/jsx-runtime";
2
- import { i as m, j as h, L as u, B as w } from "./index-DFvsMFVH.js";
2
+ import { i as m, j as h, L as u, B as w } from "./index-CguzNa4U.js";
3
3
  import { useLanguages as p } from "@chaibuilder/sdk";
4
4
  import { Card as f, CardHeader as P, CardTitle as C, CardContent as S, CardFooter as L, Button as x } from "@chaibuilder/sdk/ui";
5
5
  import { get as N } from "lodash-es";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-Qnh8Lkr0.cjs"),h=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),m=require("lodash-es"),w=require("lucide-react"),x=()=>{const[o,i]=t.useSearchParams(),r=o.get("lang"),l=t.useIsLanguagePageCreated(r),{setSelectedLang:g}=h.useLanguages(),u=()=>{const s=new URLSearchParams(window.location.search);s.delete("lang");const c=s.toString(),d=`${window.location.pathname}${c?`?${c}`:""}`;window.history.pushState({},"",d),i(s),g(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(l)return null;const n=m.get(t.LANGUAGES,r);return e.jsx(t.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[e.jsx(w.LockIcon,{className:"h-6 w-6 text-yellow-500"}),'Page missing for "',n,'" language.']})}),e.jsx(a.CardContent,{className:"grid gap-4",children:e.jsxs("div",{children:['Page is not available in the "',n,'" language. Either create the page in the "',n,'" language or switch to the base language.']})}),e.jsx(a.CardFooter,{children:e.jsx(a.Button,{onClick:u,className:"w-full",variant:"destructive",children:"Switch to default language"})})]})})};exports.default=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-CffopOpP.cjs"),h=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),m=require("lodash-es"),w=require("lucide-react"),x=()=>{const[o,i]=t.useSearchParams(),r=o.get("lang"),l=t.useIsLanguagePageCreated(r),{setSelectedLang:g}=h.useLanguages(),u=()=>{const s=new URLSearchParams(window.location.search);s.delete("lang");const c=s.toString(),d=`${window.location.pathname}${c?`?${c}`:""}`;window.history.pushState({},"",d),i(s),g(""),window.dispatchEvent(new PopStateEvent("popstate"))};if(l)return null;const n=m.get(t.LANGUAGES,r);return e.jsx(t.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-2xl",children:[e.jsx(w.LockIcon,{className:"h-6 w-6 text-yellow-500"}),'Page missing for "',n,'" language.']})}),e.jsx(a.CardContent,{className:"grid gap-4",children:e.jsxs("div",{children:['Page is not available in the "',n,'" language. Either create the page in the "',n,'" language or switch to the base language.']})}),e.jsx(a.CardFooter,{children:e.jsx(a.Button,{onClick:u,className:"w-full",variant:"destructive",children:"Switch to default language"})})]})})};exports.default=x;
@@ -1,11 +1,11 @@
1
1
  import { jsx as s, jsxs as n, Fragment as We } from "react/jsx-runtime";
2
2
  import { Input as M, CommandList as is, Label as I, Popover as ee, PopoverTrigger as se, Button as W, PopoverContent as le, Command as ne, CommandEmpty as ae, CommandGroup as G, CommandItem as R } from "@chaibuilder/sdk/ui";
3
3
  import { useState as y, useRef as os, useEffect as Be, useMemo as $ } from "react";
4
- import { r as te, S as cs, c as Oe } from "./slug-input-hJdU8DaF.js";
4
+ import { r as te, S as cs, c as Oe } from "./slug-input-BXNj3cZf.js";
5
5
  import { useChaiFeatureFlag as ye, usePermissions as us, useLanguages as ms } from "@chaibuilder/sdk";
6
6
  import { isEmpty as Ie, startCase as de, filter as hs, find as ge, groupBy as ps, pick as ds, set as P } from "lodash-es";
7
7
  import { ChevronDown as re, Search as ie, Check as U } from "lucide-react";
8
- import { ak as Re, al as Ue, A as oe, h as fs, as as gs, b as ys, c as vs, d as Ns, aw as bs, L as Ss } from "./index-DFvsMFVH.js";
8
+ import { al as Re, am as Ue, A as oe, h as fs, an as gs, b as ys, c as vs, d as Ns, as as bs, L as Ss } from "./index-CguzNa4U.js";
9
9
  import { useQuery as ze } from "@tanstack/react-query";
10
10
  import { toast as E } from "sonner";
11
11
  import { g as $e } from "./get-seo-defaults-9zHebckY.js";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-QxBMijHP.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-Qnh8Lkr0.cjs"),je=require("@tanstack/react-query"),J=require("sonner"),fe=require("./get-seo-defaults-Cw7vFt-B.cjs");function Ue({value:t,onChange:c,placeholder:j="Enter custom slug part",dynamicPattern:p,onValidationChange:o}){const[f,m]=i.useState(null),h=i.useRef(null),[g,L]=i.useState(p+t);i.useEffect(()=>{L(p+t)},[t,p]);const B=v=>{const S=v.target.value;if(!S.startsWith(p)){const O=S.replace(p,""),R=p+O;L(R),c(O);return}const l=S.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),a=(l.match(/\./g)||[]).length,x=a<=1;a>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),o&&o(x);const y=p+l;L(y),c(l)},N=()=>{if(h.current){const v=h.current;setTimeout(()=>{const S=p.length;v.setSelectionRange(S,S)},0)}},W=v=>{const S=v.currentTarget;(S.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;S.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(n.Input,{ref:h,value:g,onChange:B,onFocus:N,onClick:W,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"text-red-500 text-xs mt-1",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=o=>{try{o.preventDefault();const f=o.currentTarget;f.scrollTop+=o.deltaY}catch{o.preventDefault()}c&&c(o)};return e.jsx(n.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function $e({pages:t,selectedParentId:c,onChange:j,className:p,id:o="parentPage",currentPage:f}){const[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");B||(p="w-full rounded-md border border-gray-300 px-3 py-2");const N=i.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!b.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),W=i.useMemo(()=>{if(!g.trim())return N;const a=g.toLowerCase();return N.filter(x=>x.name.toLowerCase().includes(a)||x.slug.toLowerCase().includes(a))},[N,g]),v=a=>Math.max(0,(a.match(/\//g)||[]).length-1),S=a=>"    ".repeat(a),d=a=>{if(a==="/")return"/";const x=a.split("/").filter(Boolean);if(x.length<=1){const y=x[0]||"";return`/${$.removeSlugExtension(y)}`}return`/${$.removeSlugExtension(x[x.length-1])}`},l=()=>{if(!c||c==="none")return"None";const a=N.find(x=>x.id===c);return a?`${a.name} (${d(a.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:o,className:"text-sm",children:"Parent"}),B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{id:o,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"relative border-none py-2",children:e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:a=>L(a.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No pages found."}),e.jsxs(n.CommandGroup,{children:[e.jsxs(n.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),W.map(a=>{const x=S(v(a.slug)),y=d(a.slug),O=e.jsxs("span",{className:"flex items-center text-sm",children:[x,a.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:O}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===a.id?"opacity-100":"opacity-0")})]},a.id)})]})]})]})})]}):e.jsxs("select",{id:o,value:c||"none",onChange:a=>j(a.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),N.map(a=>{const x=v(a.slug),y=x>0?S(x):"",O=d(a.slug);return(f==null?void 0:f.id)===a.id||a.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:a.id,children:[y,a.name," (",O,")"]},a.id)})]})]})}const ze=(...t)=>t.filter(Boolean).join(" "),_e=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[o,f]=i.useState(""),[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");if(i.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);f((d==null?void 0:d.preview)||"")}else f("")},[c,t]),p)return e.jsx("div",{className:"flex h-fit items-center justify-center text-sm text-gray-500",children:"Loading templates..."});if(t.length===0)return null;const N={};t.forEach(d=>{const l=d.libraryName;N[l]||(N[l]=[]),N[l].push(d)});const W=Object.entries(N).reduce((d,[l,a])=>{const x=a.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),v=t.find(d=>d.id===c),S=v?b.startCase(v.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[S,e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>L(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No templates found."}),Object.entries(W).map(([d,l])=>e.jsx(n.CommandGroup,{heading:d,children:l.map(a=>e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[b.startCase(a.name),e.jsx(C.Check,{className:ze("mr-2 h-4 w-4",c===a.id?"opacity-100":"opacity-0")})]},a.id))},d))]})]})})]}):e.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:c,onChange:d=>j(d.target.value),children:[e.jsx("option",{value:"",children:"No Template"}),Object.entries(N).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(a=>e.jsx("option",{value:a.id,children:b.startCase(a.name)},a.id))},d))]}),o&&e.jsxs("div",{className:"mt-3 overflow-hidden rounded border",children:[e.jsx("div",{className:"max-h-[200px] overflow-auto",children:e.jsx("img",{src:o,alt:"Template Preview",className:"w-full object-contain"})}),e.jsx("div",{className:"border-t bg-gray-50 p-2 text-xs text-gray-500",children:"Template preview"})]})]})},Ve=()=>{const t=w.useApiUrl(),c=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:w.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=w.useApiUrl(),j=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:w.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?b.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:o}=Ve(),f=i.useMemo(()=>j||o?[]:c.map(h=>{const g=b.find(p,{id:h.library});return{...h,libraryName:(g==null?void 0:g.type)!=="shared"?"Site Library":(g==null?void 0:g.name)+" Library",libraryType:g==null?void 0:g.type}}),[c,p,j,o]),m=i.useMemo(()=>b.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||o}},U=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=w.usePageTypes(),o=i.useMemo(()=>p??[],[p]),f=w.useChangePage(),m=!!(t!=null&&t.id),{data:h}=w.useWebsitePages(),{mutate:g,isPending:L}=w.useCreatePage(),{mutate:B,isPending:N}=w.useUpdatePage(),[W,v]=i.useState(null),[S,d]=i.useState(!0),[l,a]=i.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=Y.usePermissions(),y=x(w.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[O,R]=i.useState(!1),[ye,ve]=i.useState(""),{selectedLang:Se,fallbackLang:Ce}=Y.useLanguages(),ne=Se||Ce,[z,H]=i.useState(""),[ae,V]=i.useState(!1),le=i.useMemo(()=>{const s=o.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,o]),[T,Ne]=i.useState((t==null?void 0:t.parent)??""),[G,re]=i.useState((t==null?void 0:t.name)??""),[I,oe]=i.useState((t==null?void 0:t.dynamic)??!1),[F,Q]=i.useState(I?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=i.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=i.useState(!0),[we,P]=i.useState(!1),[E,ke]=i.useState(""),{data:me,isLoading:Le}=Ye(l),_=L||N,he=Y.useChaiFeatureFlag("enable-add-page-dropdown"),ee=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?null:h.find(s=>s.id===t.id),[m,t==null?void 0:t.id,h]),Te=(ee==null?void 0:ee.online)||!1,De=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=o.find(s=>s.key===l),M=s=>{if(m&&l!==s){ve(s),R(!0),H(""),V(!1);return}a(s),H(""),V(!1)},pe=()=>{a(ye),R(!1),oe(!1)},Ie=s=>{oe(s),s?Q(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(k=>k.id===s),q=(u==null?void 0:u.slug)||"";if(F.startsWith(q)){const k=F.slice(q.length).replace(/^\/+/,"");Q(k)}else Q(F.replace(/^\/+/,""))}else Q(F?`${F}`:"")},qe=s=>{ke(s)},Ae=()=>G.trim()?I&&!b.isEmpty(F)?(v("Slug must be empty when using dynamic slug"),!1):I&&!ue?(v("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Be=()=>{const s={pageType:r==null?void 0:r.key,name:G,slug:"",hasSlug:!1};m?B({id:t==null?void 0:t.id,name:G},{onSuccess:()=>{J.toast.success((r==null?void 0:r.name)+" updated successfully"),c()}}):g(s,{onSuccess:u=>{c(),f(u.page.id,j)}})},Oe=(s,u)=>{if(!s.trim()&&!I)return v("Child page slug is required"),!1;const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s);return Object.keys(w.LANGUAGES).some(Z=>k===`/${Z}`||(k==null?void 0:k.startsWith(`/${Z}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s),D={pageType:l,name:G,slug:k.replace(/\/$/,""),parent:T,dynamic:I,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(I&&(D.dynamicSlugCustom=ie),m){const A=b.pick(D,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);B({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=b.find(o,{key:l});A!=null&&A.trackingDefault&&(D.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);b.set(D,"seo",Z),b.set(D,"jsonLD",Ge),g(D,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:G,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)B({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=b.find(o,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:k}=fe.getSeoDefaults(u,ne);b.set(s,"seo",q),b.set(s,"jsonLD",k),g(s,{onSuccess:D=>{var A;(A=D==null?void 0:D.page)!=null&&A.id&&f(D.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),v(null),!!Ae()){if(!(r!=null&&r.hasSlug)){Be();return}if(T&&T!=="none"){const u=h==null?void 0:h.find(k=>k.id===T),q=(u==null?void 0:u.slug)||"";if(!Oe(F,q))return;We(F,q)}else Re()}},{pagesType:se,partialsType:K}=i.useMemo(()=>{const s=u=>z?u.name.toLowerCase().includes(z.toLowerCase())||u.key.toLowerCase().includes(z.toLowerCase()):!0;return{pagesType:o.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:o.filter(u=>u.hasSlug===!1&&s(u))}},[o,z]);return r!=null&&r.hasSlug?e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:m?le?e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]})]}),!m&&(r==null?void 0:r.hasSlug)&&me.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(n.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(_e,{templates:me,selectedTemplateId:E,onSelectTemplate:qe,isLoading:Le})]}),e.jsx($e,{pages:h,selectedParentId:T,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&T&&T!=="none"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:I,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(n.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),I&&e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"space-y-0.5",children:e.jsx(Ue,{value:ie,onChange:ce,dynamicPattern:(r==null?void 0:r.dynamicSlug)||"{{id}}",placeholder:"Enter custom slug part (optional)",onValidationChange:be})})})]}),(!(r!=null&&r.dynamicSegments)||!I)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx($.SlugInput,{value:F,onChange:s=>{var u;Q(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:T&&T!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:T&&T!=="none"?(ge=h==null?void 0:h.find(s=>s.id===T))==null?void 0:ge.slug:void 0,onValidationChange:d}),W&&e.jsx("p",{className:"text-xs text-red-500",children:W}),we&&e.jsx("div",{className:"mt-4 rounded-md border border-amber-200 bg-amber-50 p-3",children:e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-amber-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-800",children:"Slug Change Warning"}),e.jsx("div",{className:"mt-1 text-sm text-amber-700",children:e.jsx("p",{children:"The previous URL and any child pages will become inaccessible. You may want to set up a redirect to avoid broken links."})})]})]})})]}),e.jsx(n.Button,{disabled:_||!S&&(!(r!=null&&r.dynamicSegments)||!I)||I&&!ue,type:"submit",className:"w-full",children:m?_?"Updating...":"Update page":_?"Creating...":"Create Page"})]}):e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>{M(s.key),V(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=o.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(n.Button,{disabled:_,type:"submit",className:"w-full",children:m?_?"Updating...":"Update "+(r==null?void 0:r.name):_?"Creating...":"Create "+(r==null?void 0:r.name)})]})}exports.default=He;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-B4w0Ihxn.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-CffopOpP.cjs"),je=require("@tanstack/react-query"),J=require("sonner"),fe=require("./get-seo-defaults-Cw7vFt-B.cjs");function Ue({value:t,onChange:c,placeholder:j="Enter custom slug part",dynamicPattern:p,onValidationChange:o}){const[f,m]=i.useState(null),h=i.useRef(null),[g,L]=i.useState(p+t);i.useEffect(()=>{L(p+t)},[t,p]);const B=v=>{const S=v.target.value;if(!S.startsWith(p)){const O=S.replace(p,""),R=p+O;L(R),c(O);return}const l=S.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),a=(l.match(/\./g)||[]).length,x=a<=1;a>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),o&&o(x);const y=p+l;L(y),c(l)},N=()=>{if(h.current){const v=h.current;setTimeout(()=>{const S=p.length;v.setSelectionRange(S,S)},0)}},W=v=>{const S=v.currentTarget;(S.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;S.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(n.Input,{ref:h,value:g,onChange:B,onFocus:N,onClick:W,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"text-red-500 text-xs mt-1",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=o=>{try{o.preventDefault();const f=o.currentTarget;f.scrollTop+=o.deltaY}catch{o.preventDefault()}c&&c(o)};return e.jsx(n.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function $e({pages:t,selectedParentId:c,onChange:j,className:p,id:o="parentPage",currentPage:f}){const[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");B||(p="w-full rounded-md border border-gray-300 px-3 py-2");const N=i.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!b.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),W=i.useMemo(()=>{if(!g.trim())return N;const a=g.toLowerCase();return N.filter(x=>x.name.toLowerCase().includes(a)||x.slug.toLowerCase().includes(a))},[N,g]),v=a=>Math.max(0,(a.match(/\//g)||[]).length-1),S=a=>"    ".repeat(a),d=a=>{if(a==="/")return"/";const x=a.split("/").filter(Boolean);if(x.length<=1){const y=x[0]||"";return`/${$.removeSlugExtension(y)}`}return`/${$.removeSlugExtension(x[x.length-1])}`},l=()=>{if(!c||c==="none")return"None";const a=N.find(x=>x.id===c);return a?`${a.name} (${d(a.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:o,className:"text-sm",children:"Parent"}),B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{id:o,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"relative border-none py-2",children:e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:a=>L(a.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No pages found."}),e.jsxs(n.CommandGroup,{children:[e.jsxs(n.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),W.map(a=>{const x=S(v(a.slug)),y=d(a.slug),O=e.jsxs("span",{className:"flex items-center text-sm",children:[x,a.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:O}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===a.id?"opacity-100":"opacity-0")})]},a.id)})]})]})]})})]}):e.jsxs("select",{id:o,value:c||"none",onChange:a=>j(a.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),N.map(a=>{const x=v(a.slug),y=x>0?S(x):"",O=d(a.slug);return(f==null?void 0:f.id)===a.id||a.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:a.id,children:[y,a.name," (",O,")"]},a.id)})]})]})}const ze=(...t)=>t.filter(Boolean).join(" "),_e=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[o,f]=i.useState(""),[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");if(i.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);f((d==null?void 0:d.preview)||"")}else f("")},[c,t]),p)return e.jsx("div",{className:"flex h-fit items-center justify-center text-sm text-gray-500",children:"Loading templates..."});if(t.length===0)return null;const N={};t.forEach(d=>{const l=d.libraryName;N[l]||(N[l]=[]),N[l].push(d)});const W=Object.entries(N).reduce((d,[l,a])=>{const x=a.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),v=t.find(d=>d.id===c),S=v?b.startCase(v.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[S,e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>L(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No templates found."}),Object.entries(W).map(([d,l])=>e.jsx(n.CommandGroup,{heading:d,children:l.map(a=>e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[b.startCase(a.name),e.jsx(C.Check,{className:ze("mr-2 h-4 w-4",c===a.id?"opacity-100":"opacity-0")})]},a.id))},d))]})]})})]}):e.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:c,onChange:d=>j(d.target.value),children:[e.jsx("option",{value:"",children:"No Template"}),Object.entries(N).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(a=>e.jsx("option",{value:a.id,children:b.startCase(a.name)},a.id))},d))]}),o&&e.jsxs("div",{className:"mt-3 overflow-hidden rounded border",children:[e.jsx("div",{className:"max-h-[200px] overflow-auto",children:e.jsx("img",{src:o,alt:"Template Preview",className:"w-full object-contain"})}),e.jsx("div",{className:"border-t bg-gray-50 p-2 text-xs text-gray-500",children:"Template preview"})]})]})},Ve=()=>{const t=w.useApiUrl(),c=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:w.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=w.useApiUrl(),j=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:w.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?b.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:o}=Ve(),f=i.useMemo(()=>j||o?[]:c.map(h=>{const g=b.find(p,{id:h.library});return{...h,libraryName:(g==null?void 0:g.type)!=="shared"?"Site Library":(g==null?void 0:g.name)+" Library",libraryType:g==null?void 0:g.type}}),[c,p,j,o]),m=i.useMemo(()=>b.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||o}},U=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=w.usePageTypes(),o=i.useMemo(()=>p??[],[p]),f=w.useChangePage(),m=!!(t!=null&&t.id),{data:h}=w.useWebsitePages(),{mutate:g,isPending:L}=w.useCreatePage(),{mutate:B,isPending:N}=w.useUpdatePage(),[W,v]=i.useState(null),[S,d]=i.useState(!0),[l,a]=i.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=Y.usePermissions(),y=x(w.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[O,R]=i.useState(!1),[ye,ve]=i.useState(""),{selectedLang:Se,fallbackLang:Ce}=Y.useLanguages(),ne=Se||Ce,[z,H]=i.useState(""),[ae,V]=i.useState(!1),le=i.useMemo(()=>{const s=o.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,o]),[T,Ne]=i.useState((t==null?void 0:t.parent)??""),[G,re]=i.useState((t==null?void 0:t.name)??""),[I,oe]=i.useState((t==null?void 0:t.dynamic)??!1),[F,Q]=i.useState(I?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=i.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=i.useState(!0),[we,P]=i.useState(!1),[E,ke]=i.useState(""),{data:me,isLoading:Le}=Ye(l),_=L||N,he=Y.useChaiFeatureFlag("enable-add-page-dropdown"),ee=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?null:h.find(s=>s.id===t.id),[m,t==null?void 0:t.id,h]),Te=(ee==null?void 0:ee.online)||!1,De=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=o.find(s=>s.key===l),M=s=>{if(m&&l!==s){ve(s),R(!0),H(""),V(!1);return}a(s),H(""),V(!1)},pe=()=>{a(ye),R(!1),oe(!1)},Ie=s=>{oe(s),s?Q(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(k=>k.id===s),q=(u==null?void 0:u.slug)||"";if(F.startsWith(q)){const k=F.slice(q.length).replace(/^\/+/,"");Q(k)}else Q(F.replace(/^\/+/,""))}else Q(F?`${F}`:"")},qe=s=>{ke(s)},Ae=()=>G.trim()?I&&!b.isEmpty(F)?(v("Slug must be empty when using dynamic slug"),!1):I&&!ue?(v("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Be=()=>{const s={pageType:r==null?void 0:r.key,name:G,slug:"",hasSlug:!1};m?B({id:t==null?void 0:t.id,name:G},{onSuccess:()=>{J.toast.success((r==null?void 0:r.name)+" updated successfully"),c()}}):g(s,{onSuccess:u=>{c(),f(u.page.id,j)}})},Oe=(s,u)=>{if(!s.trim()&&!I)return v("Child page slug is required"),!1;const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s);return Object.keys(w.LANGUAGES).some(Z=>k===`/${Z}`||(k==null?void 0:k.startsWith(`/${Z}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s),D={pageType:l,name:G,slug:k.replace(/\/$/,""),parent:T,dynamic:I,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(I&&(D.dynamicSlugCustom=ie),m){const A=b.pick(D,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);B({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=b.find(o,{key:l});A!=null&&A.trackingDefault&&(D.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);b.set(D,"seo",Z),b.set(D,"jsonLD",Ge),g(D,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:G,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)B({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=b.find(o,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:k}=fe.getSeoDefaults(u,ne);b.set(s,"seo",q),b.set(s,"jsonLD",k),g(s,{onSuccess:D=>{var A;(A=D==null?void 0:D.page)!=null&&A.id&&f(D.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),v(null),!!Ae()){if(!(r!=null&&r.hasSlug)){Be();return}if(T&&T!=="none"){const u=h==null?void 0:h.find(k=>k.id===T),q=(u==null?void 0:u.slug)||"";if(!Oe(F,q))return;We(F,q)}else Re()}},{pagesType:se,partialsType:K}=i.useMemo(()=>{const s=u=>z?u.name.toLowerCase().includes(z.toLowerCase())||u.key.toLowerCase().includes(z.toLowerCase()):!0;return{pagesType:o.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:o.filter(u=>u.hasSlug===!1&&s(u))}},[o,z]);return r!=null&&r.hasSlug?e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:m?le?e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Pages",children:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]})]}),!m&&(r==null?void 0:r.hasSlug)&&me.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(n.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(_e,{templates:me,selectedTemplateId:E,onSelectTemplate:qe,isLoading:Le})]}),e.jsx($e,{pages:h,selectedParentId:T,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&T&&T!=="none"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:I,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(n.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),I&&e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"space-y-0.5",children:e.jsx(Ue,{value:ie,onChange:ce,dynamicPattern:(r==null?void 0:r.dynamicSlug)||"{{id}}",placeholder:"Enter custom slug part (optional)",onValidationChange:be})})})]}),(!(r!=null&&r.dynamicSegments)||!I)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx($.SlugInput,{value:F,onChange:s=>{var u;Q(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:T&&T!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:T&&T!=="none"?(ge=h==null?void 0:h.find(s=>s.id===T))==null?void 0:ge.slug:void 0,onValidationChange:d}),W&&e.jsx("p",{className:"text-xs text-red-500",children:W}),we&&e.jsx("div",{className:"mt-4 rounded-md border border-amber-200 bg-amber-50 p-3",children:e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-amber-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-800",children:"Slug Change Warning"}),e.jsx("div",{className:"mt-1 text-sm text-amber-700",children:e.jsx("p",{children:"The previous URL and any child pages will become inaccessible. You may want to set up a redirect to avoid broken links."})})]})]})})]}),e.jsx(n.Button,{disabled:_||!S&&(!(r!=null&&r.dynamicSegments)||!I)||I&&!ue,type:"submit",className:"w-full",children:m?_?"Updating...":"Update page":_?"Creating...":"Create Page"})]}):e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>{M(s.key),V(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>M(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),O&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=o.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(n.Button,{disabled:_,type:"submit",className:"w-full",children:m?_?"Updating...":"Update "+(r==null?void 0:r.name):_?"Creating...":"Create "+(r==null?void 0:r.name)})]})}exports.default=He;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./index-Qnh8Lkr0.cjs"),a=require("@chaibuilder/sdk/ui"),t=require("lucide-react"),h=require("react"),g=({userId:l})=>{const{data:n}=c.useChaiUserInfo(l);return(n==null?void 0:n.name)||"Unknown"},C=({isChecking:l,lockingStatus:n,onContinue:x})=>{const[o,u]=h.useState(!1),i=n==="page_is_active_in_other_tab",r=(n==null?void 0:n.length)>0,{pageLock:s,acceptTakeOver:d,rejectTakeOver:j}=c.usePageLockRequestTakeOver(),m=()=>{u(!0),r||i?x():d(),setTimeout(()=>{u(!1)},3e3)};return h.useEffect(()=>{(s==null?void 0:s.requestedBy)==="ANOTHER_TAB"&&d()},[s,d]),(s==null?void 0:s.requestedBy)==="ANOTHER_TAB"?null:l?e.jsx(c.BlurContainer,{children:e.jsx(t.Loader,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsx(c.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-xl font-medium",children:[o?e.jsx(t.Loader,{className:"h-6 w-6 animate-spin text-gray-500"}):i?e.jsx(t.TableIcon,{className:"h-6 w-6 text-green-500"}):r?e.jsx(t.CheckCircle,{className:"h-6 w-6 text-green-500"}):e.jsx(t.Target,{className:"h-6 w-6 text-green-500"}),i?"Page is active in other tab":r?"You can edit the page now.":"Page take over request"]})}),e.jsx(a.CardContent,{className:"grid gap-4",children:e.jsx("div",{children:i?e.jsx("p",{children:'You are already editing this page in another tab. To continue editing here, click on "Continue editing here".'}):r?e.jsx("p",{children:"This page is released by other user you can continue editing now."}):e.jsxs("p",{children:[e.jsxs("b",{children:[" ",e.jsx(g,{userId:s==null?void 0:s.requestedBy})]})," ","has requested to take over this page.",e.jsx("br",{})," If you accept, your unsaved changes will be saved."]})})}),e.jsxs(a.CardFooter,{className:"flex items-center justify-end gap-2",children:[e.jsx(a.Button,{disabled:o,onClick:m,className:r?"":"bg-green-500 hover:bg-green-600",children:i?e.jsxs(e.Fragment,{children:[e.jsx(t.Edit,{className:"h-5 w-5"})," Continue editing here"]}):r?e.jsxs(e.Fragment,{children:[e.jsx(t.Edit,{className:"h-5 w-5"})," Continue to edit"]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Check,{className:"h-5 w-5"})," Accept"]})}),!r&&e.jsxs(a.Button,{variant:"outline",onClick:j,children:[e.jsx(t.X,{className:"h-5 w-5"})," Reject"]})]})]})})};exports.default=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./index-CffopOpP.cjs"),a=require("@chaibuilder/sdk/ui"),t=require("lucide-react"),h=require("react"),g=({userId:l})=>{const{data:n}=c.useChaiUserInfo(l);return(n==null?void 0:n.name)||"Unknown"},C=({isChecking:l,lockingStatus:n,onContinue:x})=>{const[o,u]=h.useState(!1),i=n==="page_is_active_in_other_tab",r=(n==null?void 0:n.length)>0,{pageLock:s,acceptTakeOver:d,rejectTakeOver:j}=c.usePageLockRequestTakeOver(),m=()=>{u(!0),r||i?x():d(),setTimeout(()=>{u(!1)},3e3)};return h.useEffect(()=>{(s==null?void 0:s.requestedBy)==="ANOTHER_TAB"&&d()},[s,d]),(s==null?void 0:s.requestedBy)==="ANOTHER_TAB"?null:l?e.jsx(c.BlurContainer,{children:e.jsx(t.Loader,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsx(c.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-xl font-medium",children:[o?e.jsx(t.Loader,{className:"h-6 w-6 animate-spin text-gray-500"}):i?e.jsx(t.TableIcon,{className:"h-6 w-6 text-green-500"}):r?e.jsx(t.CheckCircle,{className:"h-6 w-6 text-green-500"}):e.jsx(t.Target,{className:"h-6 w-6 text-green-500"}),i?"Page is active in other tab":r?"You can edit the page now.":"Page take over request"]})}),e.jsx(a.CardContent,{className:"grid gap-4",children:e.jsx("div",{children:i?e.jsx("p",{children:'You are already editing this page in another tab. To continue editing here, click on "Continue editing here".'}):r?e.jsx("p",{children:"This page is released by other user you can continue editing now."}):e.jsxs("p",{children:[e.jsxs("b",{children:[" ",e.jsx(g,{userId:s==null?void 0:s.requestedBy})]})," ","has requested to take over this page.",e.jsx("br",{})," If you accept, your unsaved changes will be saved."]})})}),e.jsxs(a.CardFooter,{className:"flex items-center justify-end gap-2",children:[e.jsx(a.Button,{disabled:o,onClick:m,className:r?"":"bg-green-500 hover:bg-green-600",children:i?e.jsxs(e.Fragment,{children:[e.jsx(t.Edit,{className:"h-5 w-5"})," Continue editing here"]}):r?e.jsxs(e.Fragment,{children:[e.jsx(t.Edit,{className:"h-5 w-5"})," Continue to edit"]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Check,{className:"h-5 w-5"})," Accept"]})}),!r&&e.jsxs(a.Button,{variant:"outline",onClick:j,children:[e.jsx(t.X,{className:"h-5 w-5"})," Reject"]})]})]})})};exports.default=C;
@@ -1,9 +1,9 @@
1
1
  import { jsx as e, jsxs as a, Fragment as l } from "react/jsx-runtime";
2
- import { aq as N, ar as w, B as h } from "./index-DFvsMFVH.js";
2
+ import { aj as N, ak as w, B as h } from "./index-CguzNa4U.js";
3
3
  import { Card as x, CardHeader as T, CardTitle as b, CardContent as v, CardFooter as y, Button as m } from "@chaibuilder/sdk/ui";
4
- import { Loader as u, TableIcon as q, CheckCircle as B, Target as _, Edit as f, Check as A, X as I } from "lucide-react";
5
- import { useState as O, useEffect as j } from "react";
6
- const E = ({ userId: i }) => {
4
+ import { Loader as u, TableIcon as B, CheckCircle as q, Target as _, Edit as f, Check as j, X as A } from "lucide-react";
5
+ import { useState as I, useEffect as O } from "react";
6
+ const k = ({ userId: i }) => {
7
7
  const { data: r } = N(i);
8
8
  return (r == null ? void 0 : r.name) || "Unknown";
9
9
  }, F = ({
@@ -11,22 +11,22 @@ const E = ({ userId: i }) => {
11
11
  lockingStatus: r,
12
12
  onContinue: g
13
13
  }) => {
14
- const [d, o] = O(!1), s = r === "page_is_active_in_other_tab", n = (r == null ? void 0 : r.length) > 0, { pageLock: t, acceptTakeOver: c, rejectTakeOver: p } = w(), C = () => {
14
+ const [d, o] = I(!1), s = r === "page_is_active_in_other_tab", n = (r == null ? void 0 : r.length) > 0, { pageLock: t, acceptTakeOver: c, rejectTakeOver: p } = w(), C = () => {
15
15
  o(!0), n || s ? g() : c(), setTimeout(() => {
16
16
  o(!1);
17
17
  }, 3e3);
18
18
  };
19
- return j(() => {
19
+ return O(() => {
20
20
  (t == null ? void 0 : t.requestedBy) === "ANOTHER_TAB" && c();
21
21
  }, [t, c]), (t == null ? void 0 : t.requestedBy) === "ANOTHER_TAB" ? null : i ? /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(u, { className: "h-5 w-5 animate-spin text-primary" }) }) : /* @__PURE__ */ e(h, { children: /* @__PURE__ */ a(x, { className: "mx-auto w-full max-w-md", children: [
22
22
  /* @__PURE__ */ e(T, { className: "space-y-1", children: /* @__PURE__ */ a(b, { className: "flex items-center gap-2 text-xl font-medium", children: [
23
- d ? /* @__PURE__ */ e(u, { className: "h-6 w-6 animate-spin text-gray-500" }) : s ? /* @__PURE__ */ e(q, { className: "h-6 w-6 text-green-500" }) : n ? /* @__PURE__ */ e(B, { className: "h-6 w-6 text-green-500" }) : /* @__PURE__ */ e(_, { className: "h-6 w-6 text-green-500" }),
23
+ d ? /* @__PURE__ */ e(u, { className: "h-6 w-6 animate-spin text-gray-500" }) : s ? /* @__PURE__ */ e(B, { className: "h-6 w-6 text-green-500" }) : n ? /* @__PURE__ */ e(q, { className: "h-6 w-6 text-green-500" }) : /* @__PURE__ */ e(_, { className: "h-6 w-6 text-green-500" }),
24
24
  s ? "Page is active in other tab" : n ? "You can edit the page now." : "Page take over request"
25
25
  ] }) }),
26
26
  /* @__PURE__ */ e(v, { className: "grid gap-4", children: /* @__PURE__ */ e("div", { children: s ? /* @__PURE__ */ e("p", { children: 'You are already editing this page in another tab. To continue editing here, click on "Continue editing here".' }) : n ? /* @__PURE__ */ e("p", { children: "This page is released by other user you can continue editing now." }) : /* @__PURE__ */ a("p", { children: [
27
27
  /* @__PURE__ */ a("b", { children: [
28
28
  " ",
29
- /* @__PURE__ */ e(E, { userId: t == null ? void 0 : t.requestedBy })
29
+ /* @__PURE__ */ e(k, { userId: t == null ? void 0 : t.requestedBy })
30
30
  ] }),
31
31
  " ",
32
32
  "has requested to take over this page.",
@@ -47,13 +47,13 @@ const E = ({ userId: i }) => {
47
47
  /* @__PURE__ */ e(f, { className: "h-5 w-5" }),
48
48
  " Continue to edit"
49
49
  ] }) : /* @__PURE__ */ a(l, { children: [
50
- /* @__PURE__ */ e(A, { className: "h-5 w-5" }),
50
+ /* @__PURE__ */ e(j, { className: "h-5 w-5" }),
51
51
  " Accept"
52
52
  ] })
53
53
  }
54
54
  ),
55
55
  !n && /* @__PURE__ */ a(m, { variant: "outline", onClick: p, children: [
56
- /* @__PURE__ */ e(I, { className: "h-5 w-5" }),
56
+ /* @__PURE__ */ e(A, { className: "h-5 w-5" }),
57
57
  " Reject"
58
58
  ] })
59
59
  ] })
@@ -3,7 +3,7 @@ import { Card as p, CardHeader as x, CardTitle as f, CardContent as h, Skeleton
3
3
  import { formatDistanceToNow as b } from "date-fns";
4
4
  import { LockKeyhole as w, UserIcon as k, Info as y, KeyIcon as v } from "lucide-react";
5
5
  import { useState as C } from "react";
6
- import { B } from "./index-DFvsMFVH.js";
6
+ import { B } from "./index-CguzNa4U.js";
7
7
  function K({
8
8
  avatar: s,
9
9
  name: a,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("@chaibuilder/sdk/ui"),m=require("date-fns"),r=require("lucide-react"),h=require("react"),j=require("./index-Qnh8Lkr0.cjs");function p({avatar:d,name:a,email:l,lastSaved:n,onTakeOver:u,isRequestRejected:c,isFetchingUserInfo:t}){const[i,o]=h.useState(!1),x=()=>{o(!0),setTimeout(()=>{o(!1)},15e3),u()};return e.jsx(j.BlurContainer,{children:e.jsxs(s.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(s.CardHeader,{className:"space-y-1",children:e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(r.LockKeyhole,{className:"h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500"}),"Page is locked for editing"]})}),e.jsx(s.CardContent,{className:"w-md grid w-full pt-2",children:e.jsxs("div",{children:[e.jsxs("div",{className:"relative mx-auto flex w-96 items-center space-x-4 rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Locked By"}),d&&!t?e.jsx("img",{src:d,alt:a,className:"h-14 w-14 rounded-full border border-gray-300"}):e.jsx(r.UserIcon,{className:"h-14 w-14 flex-shrink-0 rounded-full bg-gradient-to-br from-purple-400 to-pink-500 p-2 text-white"}),e.jsxs("div",{className:t?"space-y-1.5":"space-y-0",children:[t?e.jsx(s.Skeleton,{className:"h-4 w-40 rounded"}):e.jsx("span",{className:"truncate font-medium text-black",children:a}),l&&!t?e.jsx("p",{className:"truncate text-sm text-muted-foreground",children:l}):e.jsx(s.Skeleton,{className:"h-4 w-60 rounded"}),n&&!t?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Last saved:"," ",m.formatDistanceToNow(new Date(n),{addSuffix:!0})]}):e.jsx(s.Skeleton,{className:"h-4 w-40 rounded"})]})]}),e.jsx("div",{className:"mt-4 text-sm",children:e.jsxs("p",{className:"py-4 text-center text-gray-600",children:["This page is currently being edited by ",e.jsx("span",{className:"font-bold",children:a}),".",e.jsx("br",{}),e.jsx("br",{})," You can either wait until they finish editing or request to take over the page."]})}),c&&e.jsxs("div",{className:"mt-4 flex w-full items-center justify-center gap-x-2 rounded border border-red-500 bg-red-50 p-2 text-center font-medium text-red-500",children:[e.jsx(r.Info,{className:"h-5 w-5"})," Page take over request is rejected"]})]})}),e.jsx(s.CardFooter,{children:e.jsxs(s.Button,{disabled:i,onClick:x,className:"w-full",variant:"destructive",children:[e.jsx(r.KeyIcon,{className:"h-5 w-5"}),i?"Page take is requested.":c?"Request take over again":"Request take over"]})})]})})}exports.default=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("@chaibuilder/sdk/ui"),m=require("date-fns"),r=require("lucide-react"),h=require("react"),j=require("./index-CffopOpP.cjs");function p({avatar:d,name:a,email:l,lastSaved:n,onTakeOver:u,isRequestRejected:c,isFetchingUserInfo:t}){const[i,o]=h.useState(!1),x=()=>{o(!0),setTimeout(()=>{o(!1)},15e3),u()};return e.jsx(j.BlurContainer,{children:e.jsxs(s.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(s.CardHeader,{className:"space-y-1",children:e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(r.LockKeyhole,{className:"h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500"}),"Page is locked for editing"]})}),e.jsx(s.CardContent,{className:"w-md grid w-full pt-2",children:e.jsxs("div",{children:[e.jsxs("div",{className:"relative mx-auto flex w-96 items-center space-x-4 rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Locked By"}),d&&!t?e.jsx("img",{src:d,alt:a,className:"h-14 w-14 rounded-full border border-gray-300"}):e.jsx(r.UserIcon,{className:"h-14 w-14 flex-shrink-0 rounded-full bg-gradient-to-br from-purple-400 to-pink-500 p-2 text-white"}),e.jsxs("div",{className:t?"space-y-1.5":"space-y-0",children:[t?e.jsx(s.Skeleton,{className:"h-4 w-40 rounded"}):e.jsx("span",{className:"truncate font-medium text-black",children:a}),l&&!t?e.jsx("p",{className:"truncate text-sm text-muted-foreground",children:l}):e.jsx(s.Skeleton,{className:"h-4 w-60 rounded"}),n&&!t?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Last saved:"," ",m.formatDistanceToNow(new Date(n),{addSuffix:!0})]}):e.jsx(s.Skeleton,{className:"h-4 w-40 rounded"})]})]}),e.jsx("div",{className:"mt-4 text-sm",children:e.jsxs("p",{className:"py-4 text-center text-gray-600",children:["This page is currently being edited by ",e.jsx("span",{className:"font-bold",children:a}),".",e.jsx("br",{}),e.jsx("br",{})," You can either wait until they finish editing or request to take over the page."]})}),c&&e.jsxs("div",{className:"mt-4 flex w-full items-center justify-center gap-x-2 rounded border border-red-500 bg-red-50 p-2 text-center font-medium text-red-500",children:[e.jsx(r.Info,{className:"h-5 w-5"})," Page take over request is rejected"]})]})}),e.jsx(s.CardFooter,{children:e.jsxs(s.Button,{disabled:i,onClick:x,className:"w-full",variant:"destructive",children:[e.jsx(r.KeyIcon,{className:"h-5 w-5"}),i?"Page take is requested.":c?"Request take over again":"Request take over"]})})]})})}exports.default=p;