create-plasmic-app 0.0.133 → 0.0.135
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/cpa-out/nextjs-app-codegen-js/app/dynamic/[slug]/page-client.jsx +7 -0
- package/cpa-out/nextjs-app-codegen-js/app/dynamic/[slug]/page.jsx +45 -0
- package/cpa-out/nextjs-app-codegen-js/app/layout.js +28 -0
- package/cpa-out/nextjs-app-codegen-js/app/layout.jsx +17 -0
- package/cpa-out/nextjs-app-codegen-js/app/page-client.jsx +7 -0
- package/cpa-out/nextjs-app-codegen-js/app/page.jsx +45 -0
- package/cpa-out/nextjs-app-codegen-js/app/plasmic-host/page.jsx +15 -0
- package/cpa-out/nextjs-app-codegen-js/components/Button.jsx +11 -0
- package/cpa-out/nextjs-app-codegen-js/components/RandomDynamicPageButton.jsx +24 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.jsx +595 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +216 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.jsx +56 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +26 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +251 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepageServer.jsx +56 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +159 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.jsx +15 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__CheckSvg.jsx +39 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.jsx +37 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/plasmic.jsx +11 -0
- package/cpa-out/nextjs-app-codegen-js/package.json +22 -0
- package/cpa-out/nextjs-app-codegen-js/plasmic.json +148 -0
- package/cpa-out/nextjs-app-codegen-ts/app/dynamic/[slug]/page-client.tsx +11 -0
- package/cpa-out/nextjs-app-codegen-ts/app/dynamic/[slug]/page.tsx +57 -0
- package/cpa-out/nextjs-app-codegen-ts/app/layout.tsx +19 -0
- package/cpa-out/nextjs-app-codegen-ts/app/page-client.tsx +11 -0
- package/cpa-out/nextjs-app-codegen-ts/app/page.tsx +54 -0
- package/cpa-out/nextjs-app-codegen-ts/app/plasmic-host/page.tsx +15 -0
- package/cpa-out/nextjs-app-codegen-ts/components/Button.tsx +35 -0
- package/cpa-out/nextjs-app-codegen-ts/components/RandomDynamicPageButton.tsx +44 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.tsx +776 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +329 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.tsx +77 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +366 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepageServer.tsx +75 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +274 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.tsx +19 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__CheckSvg.tsx +44 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.tsx +41 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/plasmic.tsx +14 -0
- package/cpa-out/nextjs-app-codegen-ts/package.json +26 -0
- package/cpa-out/nextjs-app-codegen-ts/plasmic.json +148 -0
- package/cpa-out/nextjs-app-codegen-ts/tsconfig.json +26 -0
- package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +80 -0
- package/cpa-out/nextjs-app-loader-js/app/layout.js +28 -0
- package/cpa-out/nextjs-app-loader-js/app/plasmic-host/page.jsx +6 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init-client.jsx +65 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init.js +5 -10
- package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +85 -0
- package/cpa-out/nextjs-app-loader-ts/app/layout.tsx +33 -0
- package/cpa-out/nextjs-app-loader-ts/app/plasmic-host/page.tsx +6 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init-client.tsx +65 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init.ts +5 -10
- package/cpa-out/nextjs-app-loader-ts/tsconfig.json +6 -1
- package/dist/index.js +31 -30
- package/dist/nextjs/nextjs.js +37 -11
- package/dist/nextjs/templates/app-codegen/layout.d.ts +2 -0
- package/dist/nextjs/templates/app-codegen/layout.js +27 -0
- package/dist/nextjs/templates/app-loader/catchall-page.js +63 -38
- package/dist/nextjs/templates/app-loader/plasmic-init-client.js +1 -1
- package/dist/nextjs/templates/app-loader/plasmic-init.js +4 -0
- package/package.json +2 -2
- package/run-cpa.ts +8 -9
- package/src/index.ts +31 -36
- package/src/nextjs/nextjs.ts +67 -28
- package/src/nextjs/templates/app-codegen/layout.ts +28 -0
- package/src/nextjs/templates/app-loader/catchall-page.ts +80 -43
- package/src/nextjs/templates/app-loader/plasmic-init-client.ts +1 -1
- package/src/nextjs/templates/app-loader/plasmic-init.ts +4 -0
- package/cpa-out/nextjs-app-loader-js/pages/[[...catchall]].jsx +0 -68
- package/cpa-out/nextjs-app-loader-js/pages/api/hello.js +0 -5
- package/cpa-out/nextjs-app-loader-js/pages/plasmic-host.jsx +0 -7
- package/cpa-out/nextjs-app-loader-ts/pages/[[...catchall]].tsx +0 -72
- package/cpa-out/nextjs-app-loader-ts/pages/api/hello.ts +0 -13
- package/cpa-out/nextjs-app-loader-ts/pages/plasmic-host.tsx +0 -7
package/src/nextjs/nextjs.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { ensure } from "../utils/lang-utils";
|
|
12
12
|
import { installUpgrade } from "../utils/npm-utils";
|
|
13
13
|
import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
|
|
14
|
+
import { makeLayout_app_codegen } from "./templates/app-codegen/layout";
|
|
14
15
|
import { makeCatchallPage_app_loader } from "./templates/app-loader/catchall-page";
|
|
15
16
|
import { makePlasmicHostPage_app_loader } from "./templates/app-loader/plasmic-host";
|
|
16
17
|
import { makePlasmicInit_app_loader } from "./templates/app-loader/plasmic-init";
|
|
@@ -81,39 +82,77 @@ export default nextConfig;`
|
|
|
81
82
|
};
|
|
82
83
|
|
|
83
84
|
async function generateFilesAppDir(args: GenerateFilesArgs) {
|
|
84
|
-
const { projectPath, jsOrTs, projectId, projectApiToken } = args;
|
|
85
|
+
const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
|
|
85
86
|
|
|
86
87
|
// Delete existing pages
|
|
87
88
|
deleteGlob(path.join(projectPath, "app", "page.*"));
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
if (scheme === "loader") {
|
|
91
|
+
// ./plasmic-init.ts
|
|
92
|
+
await fs.writeFile(
|
|
93
|
+
path.join(projectPath, `plasmic-init.${jsOrTs}`),
|
|
94
|
+
makePlasmicInit_app_loader(
|
|
95
|
+
projectId,
|
|
96
|
+
ensure(projectApiToken, "Missing projectApiToken")
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// ./plasmic-init-client.ts
|
|
101
|
+
await fs.writeFile(
|
|
102
|
+
path.join(projectPath, `plasmic-init-client.${jsOrTs}x`),
|
|
103
|
+
makePlasmicInitClient_app_loader(jsOrTs)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// ./app/plasmic-host/page.tsx
|
|
107
|
+
await fs.mkdir(path.join(projectPath, "app", "plasmic-host"));
|
|
108
|
+
await fs.writeFile(
|
|
109
|
+
path.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`),
|
|
110
|
+
makePlasmicHostPage_app_loader()
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// ./app/[[...catchall]]/page.tsx
|
|
114
|
+
await fs.mkdir(path.join(projectPath, "app", "[[...catchall]]"));
|
|
115
|
+
await fs.writeFile(
|
|
116
|
+
path.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`),
|
|
117
|
+
makeCatchallPage_app_loader(jsOrTs)
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
// ./app/layout.tsx
|
|
121
|
+
await fs.writeFile(
|
|
122
|
+
path.join(projectPath, "app", `layout.${jsOrTs}x`),
|
|
123
|
+
makeLayout_app_codegen(jsOrTs)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// ./app/plasmic-host/page.tsx
|
|
127
|
+
await fs.mkdir(path.join(projectPath, "app", "plasmic-host"));
|
|
128
|
+
await fs.writeFile(
|
|
129
|
+
path.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`),
|
|
130
|
+
makePlasmicHostPage_pages_codegen() // plasmic-host page contents are the same as the pages router
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// This should generate
|
|
134
|
+
// ./plasmic.json
|
|
135
|
+
// ./app/page.tsx
|
|
136
|
+
// ./components/plasmic/**
|
|
137
|
+
await runCodegenSync({
|
|
93
138
|
projectId,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// ./app/[[...catchall]]/page.tsx
|
|
112
|
-
await fs.mkdir(path.join(projectPath, "app", "[[...catchall]]"));
|
|
113
|
-
await fs.writeFile(
|
|
114
|
-
path.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`),
|
|
115
|
-
makeCatchallPage_app_loader(jsOrTs)
|
|
116
|
-
);
|
|
139
|
+
projectApiToken,
|
|
140
|
+
projectPath,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Make an index (/) page if the project didn't have one.
|
|
144
|
+
const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
|
|
145
|
+
const plasmicFiles = L.map(
|
|
146
|
+
L.flatMap(config.projects, (p) => p.components),
|
|
147
|
+
(c) => c.importSpec.modulePath
|
|
148
|
+
);
|
|
149
|
+
if (!plasmicFiles.find((f) => f.includes("app/page."))) {
|
|
150
|
+
await fs.writeFile(
|
|
151
|
+
path.join(projectPath, "app", `page.${jsOrTs}x`),
|
|
152
|
+
generateWelcomePage(config, "nextjs")
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
117
156
|
}
|
|
118
157
|
|
|
119
158
|
async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ifTs } from "../../../utils/file-utils";
|
|
2
|
+
import { JsOrTs } from "../../../utils/types";
|
|
3
|
+
|
|
4
|
+
export function makeLayout_app_codegen(jsOrTs: JsOrTs): string {
|
|
5
|
+
return `import '@/app/globals.css'
|
|
6
|
+
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
7
|
+
import Link from "next/link";
|
|
8
|
+
|
|
9
|
+
export default function RootLayout({
|
|
10
|
+
children,
|
|
11
|
+
}${ifTs(
|
|
12
|
+
jsOrTs,
|
|
13
|
+
`: Readonly<{
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}>`
|
|
16
|
+
)}) {
|
|
17
|
+
return (
|
|
18
|
+
<html lang="en">
|
|
19
|
+
<body>
|
|
20
|
+
<PlasmicRootProvider Link={Link}>
|
|
21
|
+
{children}
|
|
22
|
+
</PlasmicRootProvider>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
@@ -2,71 +2,108 @@ import { ifTs } from "../../../utils/file-utils";
|
|
|
2
2
|
import { JsOrTs } from "../../../utils/types";
|
|
3
3
|
|
|
4
4
|
export function makeCatchallPage_app_loader(jsOrTs: JsOrTs): string {
|
|
5
|
-
return `import {
|
|
6
|
-
import { notFound } from "next/navigation";
|
|
7
|
-
import { PLASMIC } from "@/plasmic-init";
|
|
5
|
+
return `import { PLASMIC } from "@/plasmic-init";
|
|
8
6
|
import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
|
|
7
|
+
import { ${ifTs(
|
|
8
|
+
jsOrTs,
|
|
9
|
+
`ComponentRenderData,`
|
|
10
|
+
)}PlasmicComponent } from "@plasmicapp/loader-nextjs";${ifTs(
|
|
11
|
+
jsOrTs,
|
|
12
|
+
`
|
|
13
|
+
import { Metadata, ResolvingMetadata } from "next";`
|
|
14
|
+
)}
|
|
15
|
+
import { notFound } from "next/navigation";
|
|
9
16
|
|
|
10
17
|
// Use revalidate if you want incremental static regeneration
|
|
11
18
|
export const revalidate = 60;
|
|
19
|
+
${ifTs(
|
|
20
|
+
jsOrTs,
|
|
21
|
+
`interface Params {
|
|
22
|
+
catchall: string[] | undefined;
|
|
23
|
+
}`
|
|
24
|
+
)}
|
|
25
|
+
export async function generateStaticParams()${ifTs(
|
|
26
|
+
jsOrTs,
|
|
27
|
+
": Promise<Params[]>"
|
|
28
|
+
)} {
|
|
29
|
+
const pageModules = await PLASMIC.fetchPages();
|
|
30
|
+
return pageModules.map((mod) => {
|
|
31
|
+
const catchall =
|
|
32
|
+
mod.path === "/" ? undefined : mod.path.substring(1).split("/");
|
|
33
|
+
return {
|
|
34
|
+
catchall,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
${ifTs(
|
|
39
|
+
jsOrTs,
|
|
40
|
+
`interface LoaderPageProps {
|
|
41
|
+
params: Promise<Params>;
|
|
42
|
+
}`
|
|
43
|
+
)}
|
|
44
|
+
export async function generateMetadata(
|
|
45
|
+
{ params }${ifTs(jsOrTs, `: LoaderPageProps`)},
|
|
46
|
+
parent${ifTs(jsOrTs, `: ResolvingMetadata`)}
|
|
47
|
+
)${ifTs(jsOrTs, `: Promise<Metadata>`)} {
|
|
48
|
+
const { componentData } = await getPlasmicData(params);
|
|
49
|
+
|
|
50
|
+
if (!componentData) {
|
|
51
|
+
return parent${ifTs(jsOrTs, ` as Promise<Metadata>`)};
|
|
52
|
+
}
|
|
53
|
+
const pageMeta = componentData.entryCompMetas[0];
|
|
54
|
+
const metadata = await PLASMIC.unstable__generateMetadata(componentData, {
|
|
55
|
+
params: pageMeta.params ?? {},
|
|
56
|
+
query: {},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return { ...(await parent), ...metadata };
|
|
60
|
+
}
|
|
12
61
|
|
|
13
62
|
export default async function PlasmicLoaderPage({
|
|
14
63
|
params,
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
jsOrTs,
|
|
18
|
-
`: {
|
|
19
|
-
params?: { catchall: string[] | undefined };
|
|
20
|
-
searchParams?: Record<string, string | string[]>;
|
|
21
|
-
}`
|
|
22
|
-
)}) {
|
|
23
|
-
const plasmicComponentData = await fetchPlasmicComponentData(params?.catchall);
|
|
24
|
-
if (!plasmicComponentData) {
|
|
25
|
-
notFound();
|
|
26
|
-
}
|
|
64
|
+
}${ifTs(jsOrTs, `: LoaderPageProps`)}) {
|
|
65
|
+
const { pagePath, componentData } = await getPlasmicData(params);
|
|
27
66
|
|
|
28
|
-
|
|
29
|
-
if (prefetchedData.entryCompMetas.length === 0) {
|
|
67
|
+
if (!componentData) {
|
|
30
68
|
notFound();
|
|
31
69
|
}
|
|
70
|
+
const pageMeta = componentData.entryCompMetas[0];
|
|
71
|
+
const prefetchedQueryData = await PLASMIC.unstable__getServerQueriesData(
|
|
72
|
+
componentData,
|
|
73
|
+
{
|
|
74
|
+
pagePath,
|
|
75
|
+
params: pageMeta.params,
|
|
76
|
+
query: {},
|
|
77
|
+
}
|
|
78
|
+
);
|
|
32
79
|
|
|
33
|
-
const pageMeta = prefetchedData.entryCompMetas[0];
|
|
34
80
|
return (
|
|
35
81
|
<ClientPlasmicRootProvider
|
|
36
|
-
prefetchedData={
|
|
37
|
-
|
|
82
|
+
prefetchedData={componentData}
|
|
83
|
+
prefetchedQueryData={prefetchedQueryData}
|
|
38
84
|
pageParams={pageMeta.params}
|
|
39
|
-
|
|
85
|
+
pageRoute={pageMeta.path}
|
|
40
86
|
>
|
|
41
|
-
<PlasmicComponent
|
|
42
|
-
component={pageMeta.displayName}
|
|
43
|
-
/>
|
|
87
|
+
<PlasmicComponent component={pageMeta.displayName} />
|
|
44
88
|
</ClientPlasmicRootProvider>
|
|
45
89
|
);
|
|
46
90
|
}
|
|
47
91
|
|
|
48
|
-
async function
|
|
92
|
+
async function getPlasmicData(
|
|
93
|
+
params${ifTs(jsOrTs, ": Promise<Params>")}
|
|
94
|
+
)${ifTs(
|
|
49
95
|
jsOrTs,
|
|
50
|
-
": string
|
|
51
|
-
)}
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
if (!prefetchedData) {
|
|
55
|
-
notFound();
|
|
56
|
-
}
|
|
96
|
+
": Promise<{ pagePath: string; componentData?: ComponentRenderData }>"
|
|
97
|
+
)} {
|
|
98
|
+
const catchall = (await params).catchall;
|
|
99
|
+
const pagePath = catchall ? \`/\${catchall.join("/")}\` : "/";
|
|
57
100
|
|
|
58
|
-
|
|
59
|
-
}
|
|
101
|
+
const componentData = await PLASMIC.maybeFetchComponentData(pagePath);
|
|
60
102
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
mod.path === "/" ? undefined : mod.path.substring(1).split("/");
|
|
66
|
-
return {
|
|
67
|
-
catchall,
|
|
68
|
-
};
|
|
69
|
-
});
|
|
103
|
+
if (!componentData || componentData.entryCompMetas.length === 0) {
|
|
104
|
+
return { pagePath };
|
|
105
|
+
}
|
|
106
|
+
return { pagePath, componentData };
|
|
70
107
|
}
|
|
71
108
|
`;
|
|
72
109
|
}
|
|
@@ -20,7 +20,7 @@ import { PLASMIC } from "@/plasmic-init";
|
|
|
20
20
|
* ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
|
|
21
21
|
*
|
|
22
22
|
* Why? Props passed from Server to Client Components must be serializable.
|
|
23
|
-
* https://
|
|
23
|
+
* https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
|
|
24
24
|
* However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
|
|
25
25
|
*
|
|
26
26
|
* In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
|
|
@@ -3,6 +3,7 @@ export function makePlasmicInit_app_loader(
|
|
|
3
3
|
projectApiToken: string
|
|
4
4
|
): string {
|
|
5
5
|
return `import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
6
|
+
import * as NextNavigation from "next/navigation";
|
|
6
7
|
|
|
7
8
|
export const PLASMIC = initPlasmicLoader({
|
|
8
9
|
projects: [
|
|
@@ -17,6 +18,9 @@ export const PLASMIC = initPlasmicLoader({
|
|
|
17
18
|
// project, allowing you to see your designs without publishing. Please
|
|
18
19
|
// only use this for development, as this is significantly slower.
|
|
19
20
|
preview: false,
|
|
21
|
+
|
|
22
|
+
// Needed for Next.js app router support.
|
|
23
|
+
nextNavigation: NextNavigation,
|
|
20
24
|
});
|
|
21
25
|
`;
|
|
22
26
|
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
PlasmicComponent,
|
|
4
|
-
extractPlasmicQueryData,
|
|
5
|
-
ComponentRenderData,
|
|
6
|
-
PlasmicRootProvider,
|
|
7
|
-
} from "@plasmicapp/loader-nextjs";
|
|
8
|
-
|
|
9
|
-
import Error from "next/error";
|
|
10
|
-
import { useRouter } from "next/router";
|
|
11
|
-
import { PLASMIC } from "@/plasmic-init";
|
|
12
|
-
|
|
13
|
-
export default function PlasmicLoaderPage(props) {
|
|
14
|
-
const { plasmicData, queryCache } = props;
|
|
15
|
-
const router = useRouter();
|
|
16
|
-
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
17
|
-
return <Error statusCode={404} />;
|
|
18
|
-
}
|
|
19
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
20
|
-
return (
|
|
21
|
-
<PlasmicRootProvider
|
|
22
|
-
loader={PLASMIC}
|
|
23
|
-
prefetchedData={plasmicData}
|
|
24
|
-
prefetchedQueryData={queryCache}
|
|
25
|
-
pageRoute={pageMeta.path}
|
|
26
|
-
pageParams={pageMeta.params}
|
|
27
|
-
pageQuery={router.query}
|
|
28
|
-
>
|
|
29
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
30
|
-
</PlasmicRootProvider>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const getStaticProps = async (context) => {
|
|
35
|
-
const { catchall } = context.params ?? {};
|
|
36
|
-
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? `/${catchall.join('/')}` : '/';
|
|
37
|
-
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
38
|
-
if (!plasmicData) {
|
|
39
|
-
// non-Plasmic catch-all
|
|
40
|
-
return { props: {} };
|
|
41
|
-
}
|
|
42
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
43
|
-
// Cache the necessary data fetched for the page
|
|
44
|
-
const queryCache = await extractPlasmicQueryData(
|
|
45
|
-
<PlasmicRootProvider
|
|
46
|
-
loader={PLASMIC}
|
|
47
|
-
prefetchedData={plasmicData}
|
|
48
|
-
pageRoute={pageMeta.path}
|
|
49
|
-
pageParams={pageMeta.params}
|
|
50
|
-
>
|
|
51
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
52
|
-
</PlasmicRootProvider>
|
|
53
|
-
);
|
|
54
|
-
// Use revalidate if you want incremental static regeneration
|
|
55
|
-
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const getStaticPaths = async () => {
|
|
59
|
-
const pageModules = await PLASMIC.fetchPages();
|
|
60
|
-
return {
|
|
61
|
-
paths: pageModules.map((mod) => ({
|
|
62
|
-
params: {
|
|
63
|
-
catchall: mod.path.substring(1).split("/"),
|
|
64
|
-
},
|
|
65
|
-
})),
|
|
66
|
-
fallback: "blocking",
|
|
67
|
-
};
|
|
68
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
PlasmicComponent,
|
|
4
|
-
extractPlasmicQueryData,
|
|
5
|
-
ComponentRenderData,
|
|
6
|
-
PlasmicRootProvider,
|
|
7
|
-
} from "@plasmicapp/loader-nextjs";
|
|
8
|
-
import type { GetStaticPaths, GetStaticProps } from "next";
|
|
9
|
-
|
|
10
|
-
import Error from "next/error";
|
|
11
|
-
import { useRouter } from "next/router";
|
|
12
|
-
import { PLASMIC } from "@/plasmic-init";
|
|
13
|
-
|
|
14
|
-
export default function PlasmicLoaderPage(props: {
|
|
15
|
-
plasmicData?: ComponentRenderData;
|
|
16
|
-
queryCache?: Record<string, unknown>;
|
|
17
|
-
}) {
|
|
18
|
-
const { plasmicData, queryCache } = props;
|
|
19
|
-
const router = useRouter();
|
|
20
|
-
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
21
|
-
return <Error statusCode={404} />;
|
|
22
|
-
}
|
|
23
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
24
|
-
return (
|
|
25
|
-
<PlasmicRootProvider
|
|
26
|
-
loader={PLASMIC}
|
|
27
|
-
prefetchedData={plasmicData}
|
|
28
|
-
prefetchedQueryData={queryCache}
|
|
29
|
-
pageRoute={pageMeta.path}
|
|
30
|
-
pageParams={pageMeta.params}
|
|
31
|
-
pageQuery={router.query}
|
|
32
|
-
>
|
|
33
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
34
|
-
</PlasmicRootProvider>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const getStaticProps: GetStaticProps = async (context) => {
|
|
39
|
-
const { catchall } = context.params ?? {};
|
|
40
|
-
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? `/${catchall.join('/')}` : '/';
|
|
41
|
-
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
42
|
-
if (!plasmicData) {
|
|
43
|
-
// non-Plasmic catch-all
|
|
44
|
-
return { props: {} };
|
|
45
|
-
}
|
|
46
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
47
|
-
// Cache the necessary data fetched for the page
|
|
48
|
-
const queryCache = await extractPlasmicQueryData(
|
|
49
|
-
<PlasmicRootProvider
|
|
50
|
-
loader={PLASMIC}
|
|
51
|
-
prefetchedData={plasmicData}
|
|
52
|
-
pageRoute={pageMeta.path}
|
|
53
|
-
pageParams={pageMeta.params}
|
|
54
|
-
>
|
|
55
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
56
|
-
</PlasmicRootProvider>
|
|
57
|
-
);
|
|
58
|
-
// Use revalidate if you want incremental static regeneration
|
|
59
|
-
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const getStaticPaths: GetStaticPaths = async () => {
|
|
63
|
-
const pageModules = await PLASMIC.fetchPages();
|
|
64
|
-
return {
|
|
65
|
-
paths: pageModules.map((mod) => ({
|
|
66
|
-
params: {
|
|
67
|
-
catchall: mod.path.substring(1).split("/"),
|
|
68
|
-
},
|
|
69
|
-
})),
|
|
70
|
-
fallback: "blocking",
|
|
71
|
-
};
|
|
72
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
2
|
-
import type { NextApiRequest, NextApiResponse } from "next";
|
|
3
|
-
|
|
4
|
-
type Data = {
|
|
5
|
-
name: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export default function handler(
|
|
9
|
-
req: NextApiRequest,
|
|
10
|
-
res: NextApiResponse<Data>,
|
|
11
|
-
) {
|
|
12
|
-
res.status(200).json({ name: "John Doe" });
|
|
13
|
-
}
|