rankrunners-cms 0.0.10 → 0.0.12
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/package.json +1 -1
- package/src/editor/index.tsx +1 -0
- package/src/editor/render/PageRendererContent.tsx +88 -0
- package/src/editor/render/index.ts +2 -0
- package/src/next/editor/Editor.tsx +1 -1
- package/src/next/editor/PageRenderer.tsx +30 -0
- package/src/next/editor/index.ts +1 -0
- package/src/tanstack/editor/Editor.tsx +1 -1
- /package/src/editor/{preview → render}/Preview.tsx +0 -0
package/package.json
CHANGED
package/src/editor/index.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import type { CategoriesType, CMSUserConfig, ComponentsType } from "./types";
|
|
|
15
15
|
import type { RootConfig } from "@puckeditor/core";
|
|
16
16
|
|
|
17
17
|
export * from "./types";
|
|
18
|
+
export * from "./render";
|
|
18
19
|
|
|
19
20
|
export const defaultCategories: CategoriesType<
|
|
20
21
|
["layout", "typography", "interactive", "other"]
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { CMSUserData } from "../types";
|
|
3
|
+
import { Render, type Config } from "@puckeditor/core";
|
|
4
|
+
import { CMS_BASE_URL, SITE_ID } from "../../api";
|
|
5
|
+
import { fetchWithCache } from "../../libs";
|
|
6
|
+
|
|
7
|
+
const getPageContents = async (
|
|
8
|
+
pathname: string,
|
|
9
|
+
allPageData: Record<string, CMSUserData<any>>
|
|
10
|
+
) => {
|
|
11
|
+
// remove trailing (left and right) slashes
|
|
12
|
+
pathname = pathname.replace(/^\/+|\/+$/g, "");
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetchWithCache(
|
|
16
|
+
`${CMS_BASE_URL}/public/seo/${SITE_ID}/pages/${pathname}`,
|
|
17
|
+
{
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (res.ok) {
|
|
25
|
+
// console.error("Failed to fetch page data from CMS");
|
|
26
|
+
// throw new Error("Failed to fetch page data from CMS");
|
|
27
|
+
//}
|
|
28
|
+
const json = (await res.json()) as { content?: string };
|
|
29
|
+
|
|
30
|
+
if (json.content) {
|
|
31
|
+
const content = JSON.parse(json.content) as CMSUserData<any>;
|
|
32
|
+
|
|
33
|
+
if (content.root && content.content) {
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const actualData = allPageData[pathname as keyof typeof allPageData];
|
|
40
|
+
|
|
41
|
+
if (actualData) {
|
|
42
|
+
// Starting new page from existing published data
|
|
43
|
+
return actualData as CMSUserData<any>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Starting new blank page
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("Error fetching page data:", error);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
content: [],
|
|
53
|
+
root: { props: { title: "New Page" } },
|
|
54
|
+
zones: {},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type PageRendererContentProps = {
|
|
59
|
+
pathname: string;
|
|
60
|
+
config: Config;
|
|
61
|
+
allPageData: Record<string, CMSUserData<any>>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const PageRendererContent = ({
|
|
65
|
+
config,
|
|
66
|
+
pathname,
|
|
67
|
+
allPageData,
|
|
68
|
+
}: PageRendererContentProps) => {
|
|
69
|
+
const [data, setData] = useState<CMSUserData<any> | null>(null);
|
|
70
|
+
|
|
71
|
+
useState(() => {
|
|
72
|
+
const fetchData = async () => {
|
|
73
|
+
const pageData = await getPageContents(pathname, allPageData);
|
|
74
|
+
setData(pageData);
|
|
75
|
+
};
|
|
76
|
+
fetchData();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (!data) {
|
|
80
|
+
return (
|
|
81
|
+
<div className="flex items-center justify-center h-screen">
|
|
82
|
+
<p>Loading page...</p>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return <Render config={config} data={data} />;
|
|
88
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Config } from "@puckeditor/core";
|
|
2
|
+
import { usePathnameNext, useSearchParamsNext } from "../hooks";
|
|
3
|
+
import type { CMSUserData } from "../../editor/types";
|
|
4
|
+
import { EditorNext } from "./Editor";
|
|
5
|
+
import { PageRendererContent } from "../../editor/render";
|
|
6
|
+
|
|
7
|
+
export type PageRendererNextInitializerProps = {
|
|
8
|
+
config: Config;
|
|
9
|
+
allPageData: Record<string, CMSUserData<any>>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const PageRendererNext =
|
|
13
|
+
({ config, allPageData }: PageRendererNextInitializerProps) =>
|
|
14
|
+
() => {
|
|
15
|
+
const pathname = usePathnameNext();
|
|
16
|
+
const searchParams = useSearchParamsNext();
|
|
17
|
+
const previewToken = searchParams.get("preview");
|
|
18
|
+
|
|
19
|
+
if (previewToken) {
|
|
20
|
+
return <EditorNext config={config} allPageData={allPageData} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<PageRendererContent
|
|
25
|
+
config={config}
|
|
26
|
+
allPageData={allPageData}
|
|
27
|
+
pathname={pathname}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|
package/src/next/editor/index.ts
CHANGED
|
File without changes
|