create-plasmic-app 0.0.92 → 0.0.94
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-loader-js/pages/[[...catchall]].jsx +68 -0
- package/cpa-out/nextjs-app-loader-js/pages/api/hello.js +5 -0
- package/cpa-out/nextjs-app-loader-js/pages/plasmic-host.jsx +7 -0
- package/cpa-out/nextjs-app-loader-ts/pages/[[...catchall]].tsx +72 -0
- package/cpa-out/nextjs-app-loader-ts/pages/api/hello.ts +13 -0
- package/cpa-out/nextjs-app-loader-ts/pages/plasmic-host.tsx +7 -0
- package/cpa-out/nextjs-pages-codegen-js/components/Button.jsx +1 -3
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.jsx +50 -98
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +36 -30
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +2 -14
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +25 -25
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +45 -59
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.jsx +2 -2
- package/cpa-out/nextjs-pages-codegen-js/package.json +9 -7
- package/cpa-out/nextjs-pages-codegen-js/pages/api/hello.js +1 -1
- package/cpa-out/nextjs-pages-codegen-js/pages/dynamic/[slug].jsx +4 -3
- package/cpa-out/nextjs-pages-codegen-js/pages/index.jsx +4 -3
- package/cpa-out/nextjs-pages-codegen-js/plasmic.json +14 -8
- package/cpa-out/nextjs-pages-codegen-ts/components/Button.tsx +4 -5
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.tsx +86 -65
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -43
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +2 -14
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +63 -37
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +84 -71
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.tsx +3 -3
- package/cpa-out/nextjs-pages-codegen-ts/package.json +13 -11
- package/cpa-out/nextjs-pages-codegen-ts/pages/api/hello.ts +5 -5
- package/cpa-out/nextjs-pages-codegen-ts/pages/dynamic/[slug].tsx +4 -4
- package/cpa-out/nextjs-pages-codegen-ts/pages/index.tsx +4 -4
- package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +14 -8
- package/cpa-out/nextjs-pages-codegen-ts/tsconfig.json +1 -3
- package/cpa-out/nextjs-pages-loader-js/package.json +8 -6
- package/cpa-out/nextjs-pages-loader-js/pages/[[...catchall]].jsx +2 -0
- package/cpa-out/nextjs-pages-loader-js/pages/api/hello.js +1 -1
- package/cpa-out/nextjs-pages-loader-ts/package.json +12 -10
- package/cpa-out/nextjs-pages-loader-ts/pages/[[...catchall]].tsx +2 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/api/hello.ts +5 -5
- package/cpa-out/nextjs-pages-loader-ts/tsconfig.json +1 -3
- package/dist/nextjs/nextjs.js +5 -23
- package/dist/nextjs/templates/pages-loader/catchall-page.js +1 -1
- package/dist/utils/npm-utils.js +1 -1
- package/package.json +2 -2
- package/src/nextjs/nextjs.ts +5 -24
- package/src/nextjs/templates/pages-loader/catchall-page.ts +1 -1
- package/src/utils/npm-utils.ts +1 -1
- package/.tool-versions +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|