@chaibuilder/sdk 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AddBlocks-5cb44efb.cjs → AddBlocks-48294c91.cjs} +1 -1
- package/dist/{AddBlocks-c47af38f.js → AddBlocks-a2677462.js} +1 -1
- package/dist/{BrandingOptions-52b2de6f.js → BrandingOptions-a95cba65.js} +1 -1
- package/dist/{BrandingOptions-4f3e3a8d.cjs → BrandingOptions-c2922757.cjs} +1 -1
- package/dist/{CanvasArea-90a395c1.js → CanvasArea-ab550e9c.js} +2 -2
- package/dist/{CanvasArea-aef3fa5e.cjs → CanvasArea-f1083634.cjs} +2 -2
- package/dist/{CurrentPage-2721bc7b.js → CurrentPage-12828412.js} +1 -1
- package/dist/{CurrentPage-d1ec06db.cjs → CurrentPage-4d4a026f.cjs} +1 -1
- package/dist/{Layers-d0edf1a8.cjs → Layers-7d1616f9.cjs} +1 -1
- package/dist/{Layers-a9cf4d7c.js → Layers-c429fafe.js} +2 -2
- package/dist/{MarkAsGlobalBlock-c43c3b2c.cjs → MarkAsGlobalBlock-43d26539.cjs} +1 -1
- package/dist/{MarkAsGlobalBlock-0cf6e5a2.js → MarkAsGlobalBlock-e49bcdc9.js} +1 -1
- package/dist/{PagesPanel-589544c2.js → PagesPanel-2435351c.js} +2 -2
- package/dist/{PagesPanel-22050a98.cjs → PagesPanel-e89d30f7.cjs} +1 -1
- package/dist/{ProjectPanel-215ba7f1.cjs → ProjectPanel-b110dffd.cjs} +1 -1
- package/dist/{ProjectPanel-dbea8af1.js → ProjectPanel-e2860893.js} +2 -2
- package/dist/{Settings-c347533e.js → Settings-17279d90.js} +1 -1
- package/dist/{Settings-71c0312b.cjs → Settings-632f6372.cjs} +1 -1
- package/dist/SidePanels-95d3316d.js +243 -0
- package/dist/SidePanels-b8fe9623.cjs +1 -0
- package/dist/{Topbar-1dd5c34e.js → Topbar-8d1f6f53.js} +1 -1
- package/dist/{Topbar-4fa3ab61.cjs → Topbar-e7e27347.cjs} +1 -1
- package/dist/{add-page-modal-05c947fb.cjs → add-page-modal-79f99652.cjs} +1 -1
- package/dist/{add-page-modal-5cc1393d.js → add-page-modal-b3c84063.js} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/{delete-page-modal-859c3a09.cjs → delete-page-modal-bfe98708.cjs} +1 -1
- package/dist/{delete-page-modal-a79bfc45.js → delete-page-modal-f9e9eb48.js} +1 -1
- package/dist/{index-dfeadcce.cjs → index-2bda0975.cjs} +18 -18
- package/dist/{index-f8a2f8ef.js → index-397e45a0.js} +3 -3
- package/dist/lib.d.ts +1 -1
- package/dist/{page-viewer-aac7b439.cjs → page-viewer-1763df5e.cjs} +1 -1
- package/dist/{page-viewer-c6421156.js → page-viewer-9c46bbbf.js} +2 -2
- package/dist/{project-general-setting-ce814ecf.cjs → project-general-setting-08e5996d.cjs} +1 -1
- package/dist/{project-general-setting-f9fd21cc.js → project-general-setting-a925e417.js} +1 -1
- package/dist/render.cjs +2 -2
- package/dist/render.d.ts +11 -1
- package/dist/render.js +119 -108
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +21 -1
- package/dist/server.js +47 -35
- package/dist/{single-page-detail-dcbb3cab.cjs → single-page-detail-23bfb732.cjs} +1 -1
- package/dist/{single-page-detail-2ac00c2e.js → single-page-detail-60eae215.js} +2 -2
- package/package.json +1 -1
- package/dist/SidePanels-214fef72.js +0 -2999
- package/dist/SidePanels-3844d8b5.cjs +0 -13
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var g=(n,t,e)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var i=(n,t,e)=>(g(n,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash"),p=require("@chaibuilder/blocks"),h="https://api.chaibuilder.com";class l{constructor(t,e){i(this,"authSecret");i(this,"appKey");if(!t)throw"Please provide valid auth secret.";if(!e)throw"Please provide valid project key.";this.authSecret=t,this.appKey=e}async getPageData(t){const e=this.getHeaders(),s=this.getURL("page-data",c.isEmpty(t)?{}:{slug:t}),o={method:"GET",headers:e,next:{tags:["everything",c.isEmpty(t)?"_homepage":t]}};return this.fetchAPI(s,o)}async getPage(t){if(!t)return Promise.reject({data:null,error:{message:"Invalid page uuid"},result:"error"});const e=this.getHeaders(),s=this.getURL("page",{uuid:t}),o={method:"GET",headers:e};return this.fetchAPI(s,o)}async getPages(){const t=this.getHeaders(),e=this.getURL("pages"),r={method:"GET",headers:t};return this.fetchAPI(e,r)}async addPage(t){const e=JSON.stringify(t),s=this.getHeaders(),r=this.getURL("page"),a={method:"POST",headers:s,body:e};return this.fetchAPI(r,a)}async deletePage(t){if(!t)return Promise.reject({data:null,error:{message:"Invalid page uuid"},result:"error"});const e=this.getHeaders(),s=this.getURL("page",{uuid:t}),o={method:"DELETE",headers:e};return this.fetchAPI(s,o)}async updatePage(t){const e=JSON.stringify(t),s=this.getHeaders(),r=this.getURL("page"),a={method:"PUT",headers:s,body:e};return this.fetchAPI(r,a)}async getProject(){const t=this.getHeaders(),e=this.getURL("project"),r={method:"GET",headers:t};return this.fetchAPI(e,r)}async updateProject(t){const e=JSON.stringify(t),s=this.getHeaders(),r=this.getURL("project"),a={method:"PUT",headers:s,body:e};return this.fetchAPI(r,a)}async uploadAsset(t){const e=this.getHeaders(),s=this.getURL("asset"),r="POST",o=await t.get("file"),a=new FormData;a.append("file",o);const d={method:r,headers:e,body:a};return this.fetchAPI(s,d)}async getAssets(t,e){const s=this.getHeaders(),r=this.getURL("asset");t&&r.concat(`?limit=${t}`),e&&r.concat(`&offset=${e}`);const a={method:"GET",headers:s};return this.fetchAPI(r,a)}async authenticate({password:t}){const e=JSON.stringify({password:t}),s=this.getHeaders(),r=this.getURL("authenticate"),a={method:"POST",headers:s,body:e};return this.fetchAPI(r,a)}async verify(t){const e=JSON.stringify({token:t}),s=this.getHeaders(),r=this.getURL("verify"),a={method:"POST",headers:s,body:e};return this.fetchAPI(r,a)}getURL(t,e){const s=new URLSearchParams(e).toString();return c.isEmpty(e)?`${h}/v1/${t}`:`${h}/v1/${t}?${s}`}getHeaders(){const t=new Headers;return t.append("x-chai-app-key",this.appKey),t.append("x-chai-auth-secret",this.authSecret),t}async fetchAPI(t,e){try{const s=await fetch(t,e).then(r=>r.json());if((s==null?void 0:s.result)==="success")return{data:s==null?void 0:s.data,error:null,result:"success"};throw s==null?void 0:s.error}catch(s){return{data:null,error:s,result:"error"}}}}const y=async n=>{const t=p.getChaiDataProviders(),e=c.filter(t,o=>c.map(n,"providerKey").includes(o.providerKey)),s={},r=[];for(const o of e)try{s[o.providerKey]=await o.dataFn()}catch(a){r.push(a)}return{data:s,errors:r}};exports.ChaibuilderBackend=l;exports.prepareExternalData=y;
|
package/dist/server.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ declare type ChaiBlock = {
|
|
|
16
16
|
_parent?: string | null | undefined;
|
|
17
17
|
_bindings?: Record<string, string>;
|
|
18
18
|
readonly _type: string;
|
|
19
|
-
} & Record<string,
|
|
19
|
+
} & Record<string, any>;
|
|
20
20
|
|
|
21
21
|
export declare class ChaibuilderBackend implements ChaibuilderBackendInterface {
|
|
22
22
|
private authSecret;
|
|
@@ -188,6 +188,10 @@ export declare class ChaibuilderBackend implements ChaibuilderBackendInterface {
|
|
|
188
188
|
slug: string;
|
|
189
189
|
blocks: ChaiBlock[];
|
|
190
190
|
seoData: object;
|
|
191
|
+
providers: {
|
|
192
|
+
providerKey: string;
|
|
193
|
+
args: Record<string, unknown>;
|
|
194
|
+
}[];
|
|
191
195
|
type: "STATIC" | "DYNAMIC" | "SUBPAGE";
|
|
192
196
|
project: string;
|
|
193
197
|
};
|
|
@@ -199,9 +203,17 @@ export declare class ChaibuilderBackend implements ChaibuilderBackendInterface {
|
|
|
199
203
|
slug?: string;
|
|
200
204
|
name: string;
|
|
201
205
|
};
|
|
206
|
+
providers?: {
|
|
207
|
+
providerKey: string;
|
|
208
|
+
args: Record<string, unknown>;
|
|
209
|
+
}[];
|
|
202
210
|
subPages?: {
|
|
203
211
|
uuid: string;
|
|
204
212
|
blocks: ChaiBlock[];
|
|
213
|
+
providers?: {
|
|
214
|
+
providerKey: string;
|
|
215
|
+
args: Record<string, unknown>;
|
|
216
|
+
}[];
|
|
205
217
|
}[];
|
|
206
218
|
project: {
|
|
207
219
|
name: string;
|
|
@@ -230,4 +242,12 @@ export declare class ChaibuilderBackend implements ChaibuilderBackendInterface {
|
|
|
230
242
|
|
|
231
243
|
declare type ChaiSubPage = Pick<ChaiPage, "uuid" | "name" | "blocks" | "type" | "project">;
|
|
232
244
|
|
|
245
|
+
export declare const prepareExternalData: (providers: {
|
|
246
|
+
providerKey: string;
|
|
247
|
+
args: Record<string, unknown>;
|
|
248
|
+
}[]) => Promise<{
|
|
249
|
+
data: {};
|
|
250
|
+
errors: any[];
|
|
251
|
+
}>;
|
|
252
|
+
|
|
233
253
|
export { }
|
package/dist/server.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
var g = Object.defineProperty;
|
|
2
|
-
var u = (
|
|
3
|
-
var
|
|
4
|
-
import { isEmpty as h } from "lodash";
|
|
2
|
+
var u = (n, t, e) => t in n ? g(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var c = (n, t, e) => (u(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { isEmpty as h, filter as p, map as l } from "lodash";
|
|
5
|
+
import { getChaiDataProviders as y } from "@chaibuilder/blocks";
|
|
5
6
|
const i = "https://api.chaibuilder.com";
|
|
6
|
-
class
|
|
7
|
+
class v {
|
|
7
8
|
constructor(t, e) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
c(this, "authSecret");
|
|
10
|
+
c(this, "appKey");
|
|
10
11
|
if (!t)
|
|
11
12
|
throw "Please provide valid auth secret.";
|
|
12
13
|
if (!e)
|
|
@@ -14,12 +15,12 @@ class m {
|
|
|
14
15
|
this.authSecret = t, this.appKey = e;
|
|
15
16
|
}
|
|
16
17
|
async getPageData(t) {
|
|
17
|
-
const e = this.getHeaders(), s = this.getURL("page-data", h(t) ? {} : { slug: t }),
|
|
18
|
+
const e = this.getHeaders(), s = this.getURL("page-data", h(t) ? {} : { slug: t }), o = {
|
|
18
19
|
method: "GET",
|
|
19
20
|
headers: e,
|
|
20
21
|
next: { tags: ["everything", h(t) ? "_homepage" : t] }
|
|
21
22
|
};
|
|
22
|
-
return this.fetchAPI(s,
|
|
23
|
+
return this.fetchAPI(s, o);
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
*
|
|
@@ -33,8 +34,8 @@ class m {
|
|
|
33
34
|
error: { message: "Invalid page uuid" },
|
|
34
35
|
result: "error"
|
|
35
36
|
});
|
|
36
|
-
const e = this.getHeaders(), s = this.getURL("page", { uuid: t }),
|
|
37
|
-
return this.fetchAPI(s,
|
|
37
|
+
const e = this.getHeaders(), s = this.getURL("page", { uuid: t }), o = { method: "GET", headers: e };
|
|
38
|
+
return this.fetchAPI(s, o);
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
*
|
|
@@ -42,8 +43,8 @@ class m {
|
|
|
42
43
|
*/
|
|
43
44
|
// @ts-ignore
|
|
44
45
|
async getPages() {
|
|
45
|
-
const t = this.getHeaders(), e = this.getURL("pages"),
|
|
46
|
-
return this.fetchAPI(e,
|
|
46
|
+
const t = this.getHeaders(), e = this.getURL("pages"), r = { method: "GET", headers: t };
|
|
47
|
+
return this.fetchAPI(e, r);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
*
|
|
@@ -51,8 +52,8 @@ class m {
|
|
|
51
52
|
* @returns Detail of new page
|
|
52
53
|
*/
|
|
53
54
|
async addPage(t) {
|
|
54
|
-
const e = JSON.stringify(t), s = this.getHeaders(),
|
|
55
|
-
return this.fetchAPI(
|
|
55
|
+
const e = JSON.stringify(t), s = this.getHeaders(), r = this.getURL("page"), a = { method: "POST", headers: s, body: e };
|
|
56
|
+
return this.fetchAPI(r, a);
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
*
|
|
@@ -66,8 +67,8 @@ class m {
|
|
|
66
67
|
error: { message: "Invalid page uuid" },
|
|
67
68
|
result: "error"
|
|
68
69
|
});
|
|
69
|
-
const e = this.getHeaders(), s = this.getURL("page", { uuid: t }),
|
|
70
|
-
return this.fetchAPI(s,
|
|
70
|
+
const e = this.getHeaders(), s = this.getURL("page", { uuid: t }), o = { method: "DELETE", headers: e };
|
|
71
|
+
return this.fetchAPI(s, o);
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
*
|
|
@@ -75,16 +76,16 @@ class m {
|
|
|
75
76
|
* @returns Update page information or Error response
|
|
76
77
|
*/
|
|
77
78
|
async updatePage(t) {
|
|
78
|
-
const e = JSON.stringify(t), s = this.getHeaders(),
|
|
79
|
-
return this.fetchAPI(
|
|
79
|
+
const e = JSON.stringify(t), s = this.getHeaders(), r = this.getURL("page"), a = { method: "PUT", headers: s, body: e };
|
|
80
|
+
return this.fetchAPI(r, a);
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
83
|
*
|
|
83
84
|
* @returns Project detail
|
|
84
85
|
*/
|
|
85
86
|
async getProject() {
|
|
86
|
-
const t = this.getHeaders(), e = this.getURL("project"),
|
|
87
|
-
return this.fetchAPI(e,
|
|
87
|
+
const t = this.getHeaders(), e = this.getURL("project"), r = { method: "GET", headers: t };
|
|
88
|
+
return this.fetchAPI(e, r);
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
91
|
*
|
|
@@ -92,8 +93,8 @@ class m {
|
|
|
92
93
|
* @returns Updated project detail
|
|
93
94
|
*/
|
|
94
95
|
async updateProject(t) {
|
|
95
|
-
const e = JSON.stringify(t), s = this.getHeaders(),
|
|
96
|
-
return this.fetchAPI(
|
|
96
|
+
const e = JSON.stringify(t), s = this.getHeaders(), r = this.getURL("project"), a = { method: "PUT", headers: s, body: e };
|
|
97
|
+
return this.fetchAPI(r, a);
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
100
|
*
|
|
@@ -102,9 +103,9 @@ class m {
|
|
|
102
103
|
* @param req
|
|
103
104
|
*/
|
|
104
105
|
async uploadAsset(t) {
|
|
105
|
-
const e = this.getHeaders(), s = this.getURL("asset"),
|
|
106
|
-
|
|
107
|
-
const d = { method:
|
|
106
|
+
const e = this.getHeaders(), s = this.getURL("asset"), r = "POST", o = await t.get("file"), a = new FormData();
|
|
107
|
+
a.append("file", o);
|
|
108
|
+
const d = { method: r, headers: e, body: a };
|
|
108
109
|
return this.fetchAPI(s, d);
|
|
109
110
|
}
|
|
110
111
|
/**
|
|
@@ -114,10 +115,10 @@ class m {
|
|
|
114
115
|
* @param offset
|
|
115
116
|
*/
|
|
116
117
|
async getAssets(t, e) {
|
|
117
|
-
const s = this.getHeaders(),
|
|
118
|
-
t &&
|
|
119
|
-
const
|
|
120
|
-
return this.fetchAPI(
|
|
118
|
+
const s = this.getHeaders(), r = this.getURL("asset");
|
|
119
|
+
t && r.concat(`?limit=${t}`), e && r.concat(`&offset=${e}`);
|
|
120
|
+
const a = { method: "GET", headers: s };
|
|
121
|
+
return this.fetchAPI(r, a);
|
|
121
122
|
}
|
|
122
123
|
/**
|
|
123
124
|
*
|
|
@@ -125,8 +126,8 @@ class m {
|
|
|
125
126
|
* @returns { token }
|
|
126
127
|
*/
|
|
127
128
|
async authenticate({ password: t }) {
|
|
128
|
-
const e = JSON.stringify({ password: t }), s = this.getHeaders(),
|
|
129
|
-
return this.fetchAPI(
|
|
129
|
+
const e = JSON.stringify({ password: t }), s = this.getHeaders(), r = this.getURL("authenticate"), a = { method: "POST", headers: s, body: e };
|
|
130
|
+
return this.fetchAPI(r, a);
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
132
133
|
*
|
|
@@ -134,8 +135,8 @@ class m {
|
|
|
134
135
|
* @returns { result: 'success' | 'error' }
|
|
135
136
|
*/
|
|
136
137
|
async verify(t) {
|
|
137
|
-
const e = JSON.stringify({ token: t }), s = this.getHeaders(),
|
|
138
|
-
return this.fetchAPI(
|
|
138
|
+
const e = JSON.stringify({ token: t }), s = this.getHeaders(), r = this.getURL("verify"), a = { method: "POST", headers: s, body: e };
|
|
139
|
+
return this.fetchAPI(r, a);
|
|
139
140
|
}
|
|
140
141
|
/**
|
|
141
142
|
*
|
|
@@ -161,7 +162,7 @@ class m {
|
|
|
161
162
|
*/
|
|
162
163
|
async fetchAPI(t, e) {
|
|
163
164
|
try {
|
|
164
|
-
const s = await fetch(t, e).then((
|
|
165
|
+
const s = await fetch(t, e).then((r) => r.json());
|
|
165
166
|
if ((s == null ? void 0 : s.result) === "success")
|
|
166
167
|
return { data: s == null ? void 0 : s.data, error: null, result: "success" };
|
|
167
168
|
throw s == null ? void 0 : s.error;
|
|
@@ -170,6 +171,17 @@ class m {
|
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
173
|
}
|
|
174
|
+
const U = async (n) => {
|
|
175
|
+
const t = y(), e = p(t, (o) => l(n, "providerKey").includes(o.providerKey)), s = {}, r = [];
|
|
176
|
+
for (const o of e)
|
|
177
|
+
try {
|
|
178
|
+
s[o.providerKey] = await o.dataFn();
|
|
179
|
+
} catch (a) {
|
|
180
|
+
r.push(a);
|
|
181
|
+
}
|
|
182
|
+
return { data: s, errors: r };
|
|
183
|
+
};
|
|
173
184
|
export {
|
|
174
|
-
|
|
185
|
+
v as ChaibuilderBackend,
|
|
186
|
+
U as prepareExternalData
|
|
175
187
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-5c3ac4f7.cjs"),g=require("react"),c=require("lodash"),M=require("@radix-ui/react-icons"),H=require("./useBuilderProp-5e57d0c8.cjs"),w=require("./scroll-area-bb343b86.cjs"),d=require("@chaibuilder/blocks"),L=require("sonner"),p=require("./form-99b51245.cjs"),P=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-5c3ac4f7.cjs"),g=require("react"),c=require("lodash"),M=require("@radix-ui/react-icons"),H=require("./useBuilderProp-5e57d0c8.cjs"),w=require("./scroll-area-bb343b86.cjs"),d=require("@chaibuilder/blocks"),L=require("sonner"),p=require("./form-99b51245.cjs"),P=require("./index-2bda0975.cjs");require("@radix-ui/react-slot");require("class-variance-authority");require("./utils-3c452dd0.cjs");require("clsx");require("tailwind-merge");require("@radix-ui/react-tooltip");require("@radix-ui/react-toast");require("jotai");require("@radix-ui/react-scroll-area");require("@rjsf/core");require("@rjsf/validator-ajv8");require("./link-86ac8848.cjs");require("react-icons-picker");require("react-dom");require("./dialog-170eaad9.cjs");require("@radix-ui/react-dialog");require("./ImagesPanel-0db5c72f.cjs");require("./tabs-860e37aa.cjs");require("@radix-ui/react-tabs");require("react-quill");require("react-i18next");require("./_commonjsHelpers-87b0abe8.cjs");require("@floating-ui/react-dom");require("i18next");require("flagged");require("react-dnd");require("@minoru/react-dnd-treeview");require("react-hotkeys-hook");require("flat-to-nested");require("./html-to-json-78bfa1f3.cjs");require("./MODIFIERS-70fef873.cjs");require("himalaya");require("redux-undo");require("@react-hookz/web");require("lucide-react");const z=g.lazy(()=>Promise.resolve().then(()=>require("./delete-page-modal-bfe98708.cjs"))),B=g.lazy(()=>Promise.resolve().then(()=>require("./confirm-alert-4f50caa7.cjs"))),E=n=>{if(!c.isString(n)||!(n.includes("/[")&&n.includes("]")))return!1;const s=/^\[((?:\.{3})?[a-zA-Z0-9_-]+)\]$/,q=/^[a-zA-Z0-9_-]+$/;let e=!0;return n.split("/").forEach(u=>{e&&(u.includes("[[")&&u.includes("]]")?e=/^\[\[\.{3}[a-zA-Z0-9_-]+\]\]$/.test(u):u.includes("[")&&u.includes("]")?e=s.test(u):e=q.test(u))}),e},h=n=>n&&c.isEmpty(n.seoData)?{...n,seoData:{title:"",description:"",image:""}}:n,G=(n,o)=>{const s=!c.isEqual(c.omit(n,["seoData"]),c.omit(o,["seoData"])),q=!c.isEqual(h(o).seoData,h(n).seoData);return s||q},Y=({open:n,setOpen:o,pageData:s})=>{const q=P.useQueryClient(),{data:e}=P.useProject(),u=P.useUpdatePage(),m=P.useUpdateProject("Homepage updated successfully."),[i,b]=g.useState(h(s)),[a,y]=g.useState({isHomePage:(e==null?void 0:e.homepage)===s.uuid}),j=G(i,s);g.useEffect(()=>{const l=!c.isEqual(h(s),i),r=(e==null?void 0:e.homepage)!==s.uuid&&a.isHomePage;o(l||r?"PENDING":"OPEN")},[e,s,i,a,o]);const S=()=>{if(j){if(s.type==="DYNAMIC"&&!E((i==null?void 0:i.slug)||"")){n==="ALERT"&&o("PENDING");return}u.mutate(i,{onSuccess:()=>{q.invalidateQueries({refetchType:"active",queryKey:["pages",e==null?void 0:e.uuid]}),o("CLOSE"),L.toast.success("Page updated successfully.")}})}a.isHomePage&&(e==null?void 0:e.homepage)!==s.uuid&&m.mutate({...e,homepage:s==null?void 0:s.uuid},{onSuccess:()=>o("CLOSE")})},C=({formData:l},r)=>{b(f=>{var R,N;if(!r)return f;const x={[r]:l[r]};return r==="name"?x.slug=c.kebabCase((R=l[r])==null?void 0:R.replace(/\d/g,"")):r==="slug"?x.slug=(N=l[r])==null?void 0:N.replace(/\d/g,"").replace(/\s+/g,"").replace("--","-").replace("__","_"):r==="seoData"&&(x.seoData={title:l[r].title||"",description:l[r].description||"",image:l[r].image||""}),{...f,...x}})},A=({formData:l},r)=>{y(f=>{const x={[r]:l[r]};return{...f,...x}})},I={name:d.SingleLineText({title:"Page Name",default:i.name}),slug:d.SingleLineText({title:"Page Slug",default:i.slug})},T={seoData:d.Model({title:"",description:"",default:{title:"",description:"",image:""},properties:{title:d.SingleLineText({title:"Meta Title",default:i.name}),description:d.MultilineText({title:"Meta Description",default:i.slug}),image:d.Image({title:"Social Media Image",default:""})}})},v={isHomePage:d.Checkbox({title:"Set as homepage",default:a.isHomePage})};return t.jsxRuntimeExports.jsxs(w.ScrollArea,{className:"flex h-full select-none flex-col",children:[t.jsxRuntimeExports.jsx(B,{open:n==="ALERT",title:"Do yo want to save changes?",onCancel:()=>o("CLOSE"),onConfirm:S,disabled:m.isPending||u.isPending}),t.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-background/30 px-2.5 py-1",children:t.jsxRuntimeExports.jsx("h1",{className:"px-1 font-semibold",children:"Page Details"})}),t.jsxRuntimeExports.jsx("div",{className:"px-2.5 pt-2",children:t.jsxRuntimeExports.jsxs("div",{className:"flex flex-col space-y-2",children:[t.jsxRuntimeExports.jsx(p.Form,{title:"Basic Details",formData:i,properties:I,onChange:C,disabled:u.isPending||m.isPending}),t.jsxRuntimeExports.jsx("div",{className:"h-2 w-full"}),t.jsxRuntimeExports.jsx(p.Form,{title:"SEO Details",formData:i,properties:T,onChange:C,disabled:u.isPending||m.isPending}),(e==null?void 0:e.homepage)!==s.uuid&&s.type==="STATIC"?t.jsxRuntimeExports.jsx(p.Form,{formData:a,properties:v,onChange:A,disabled:u.isPending||m.isPending}):s.type==="STATIC"&&t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-x-1 px-1 pt-2 text-xs font-medium text-gray-500",children:[t.jsxRuntimeExports.jsx(M.HomeIcon,{})," This is homepage"," "]}),i.type==="DYNAMIC"&&!E((i==null?void 0:i.slug)||"")&&t.jsxRuntimeExports.jsxs("small",{className:"px-1 text-red-400",children:["Add dynamic ID in page slug Eg: ",t.jsxRuntimeExports.jsx("i",{className:"underline",children:"some-url/[some-id]"})]}),t.jsxRuntimeExports.jsxs("div",{className:"my-2 flex w-full items-center justify-between gap-x-2 px-1",children:[t.jsxRuntimeExports.jsx(H.Button,{className:"w-full",type:"submit",onClick:S,disabled:(e==null?void 0:e.homepage)!==s.uuid&&a.isHomePage?!1:c.isEmpty(i.name)||c.isEmpty(i.slug)||!j||u.isPending||m.isPending||i.type==="DYNAMIC"&&!E((i==null?void 0:i.slug)||""),children:"Save"}),t.jsxRuntimeExports.jsx(z,{pageData:s,projectData:e})]})]})})]})};exports.default=Y;
|
|
@@ -7,7 +7,7 @@ import { S as q } from "./scroll-area-83bd9e8f.js";
|
|
|
7
7
|
import { SingleLineText as g, Model as Z, MultilineText as $, Image as F, Checkbox as Q } from "@chaibuilder/blocks";
|
|
8
8
|
import { toast as U } from "sonner";
|
|
9
9
|
import { F as h } from "./form-725e3191.js";
|
|
10
|
-
import { a2 as V, R as X, a3 as _, S as K } from "./index-
|
|
10
|
+
import { a2 as V, R as X, a3 as _, S as K } from "./index-397e45a0.js";
|
|
11
11
|
import "@radix-ui/react-slot";
|
|
12
12
|
import "class-variance-authority";
|
|
13
13
|
import "./utils-ac68b2c8.js";
|
|
@@ -43,7 +43,7 @@ import "himalaya";
|
|
|
43
43
|
import "redux-undo";
|
|
44
44
|
import "@react-hookz/web";
|
|
45
45
|
import "lucide-react";
|
|
46
|
-
const O = y.lazy(() => import("./delete-page-modal-
|
|
46
|
+
const O = y.lazy(() => import("./delete-page-modal-f9e9eb48.js")), J = y.lazy(() => import("./confirm-alert-f2a47cc7.js")), x = (n) => {
|
|
47
47
|
if (!z(n) || !(n.includes("/[") && n.includes("]")))
|
|
48
48
|
return !1;
|
|
49
49
|
const s = /^\[((?:\.{3})?[a-zA-Z0-9_-]+)\]$/, u = /^[a-zA-Z0-9_-]+$/;
|