create-plasmic-app 0.0.99 → 0.0.101

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 (111) hide show
  1. package/cpa-out/gatsby-codegen-js/gatsby-browser.jsx +2 -1
  2. package/cpa-out/gatsby-codegen-js/gatsby-ssr.jsx +2 -1
  3. package/cpa-out/gatsby-codegen-js/package.json +4 -4
  4. package/cpa-out/gatsby-codegen-js/plasmic.json +14 -8
  5. package/cpa-out/gatsby-codegen-js/src/components/Button.jsx +1 -3
  6. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.jsx +53 -100
  7. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +36 -30
  8. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +3 -15
  9. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +25 -25
  10. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +45 -59
  11. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.jsx +3 -3
  12. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.jsx +1 -1
  13. package/cpa-out/gatsby-codegen-js/src/pages/dynamic/[slug].jsx +5 -4
  14. package/cpa-out/gatsby-codegen-js/src/pages/index.jsx +5 -4
  15. package/cpa-out/gatsby-codegen-ts/gatsby-browser.tsx +2 -1
  16. package/cpa-out/gatsby-codegen-ts/gatsby-ssr.tsx +2 -1
  17. package/cpa-out/gatsby-codegen-ts/package.json +9 -9
  18. package/cpa-out/gatsby-codegen-ts/plasmic.json +14 -8
  19. package/cpa-out/gatsby-codegen-ts/src/components/Button.tsx +4 -5
  20. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.tsx +99 -75
  21. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +80 -49
  22. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +3 -15
  23. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +69 -43
  24. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +90 -77
  25. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.tsx +4 -4
  26. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.tsx +1 -1
  27. package/cpa-out/gatsby-codegen-ts/src/pages/dynamic/[slug].tsx +6 -5
  28. package/cpa-out/gatsby-codegen-ts/src/pages/index.tsx +6 -5
  29. package/cpa-out/gatsby-loader-js/package.json +3 -3
  30. package/cpa-out/gatsby-loader-js/src/templates/defaultPlasmicPage.jsx +1 -0
  31. package/cpa-out/gatsby-loader-ts/package.json +8 -8
  32. package/cpa-out/gatsby-loader-ts/src/templates/defaultPlasmicPage.tsx +1 -0
  33. package/cpa-out/nextjs-app-loader-js/package.json +8 -6
  34. package/cpa-out/nextjs-app-loader-js/plasmic-init.js +10 -1
  35. package/cpa-out/nextjs-app-loader-ts/package.json +12 -10
  36. package/cpa-out/nextjs-app-loader-ts/plasmic-init.ts +10 -1
  37. package/cpa-out/nextjs-app-loader-ts/tsconfig.json +2 -9
  38. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.jsx +6 -5
  39. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +1 -1
  40. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +1 -1
  41. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +1 -1
  42. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +1 -1
  43. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.jsx +1 -1
  44. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.jsx +1 -1
  45. package/cpa-out/nextjs-pages-codegen-js/package.json +4 -4
  46. package/cpa-out/nextjs-pages-codegen-js/pages/_app.jsx +2 -1
  47. package/cpa-out/nextjs-pages-codegen-js/plasmic.json +2 -2
  48. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.tsx +17 -14
  49. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +7 -7
  50. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +1 -1
  51. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +7 -7
  52. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +7 -7
  53. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.tsx +1 -1
  54. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.tsx +1 -1
  55. package/cpa-out/nextjs-pages-codegen-ts/package.json +4 -4
  56. package/cpa-out/nextjs-pages-codegen-ts/pages/_app.tsx +2 -1
  57. package/cpa-out/nextjs-pages-codegen-ts/pages/dynamic/[slug].tsx +1 -0
  58. package/cpa-out/nextjs-pages-codegen-ts/pages/index.tsx +1 -0
  59. package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +2 -2
  60. package/cpa-out/nextjs-pages-loader-js/package.json +3 -3
  61. package/cpa-out/nextjs-pages-loader-ts/package.json +3 -3
  62. package/cpa-out/react-codegen-js/eslint.config.js +1 -6
  63. package/cpa-out/react-codegen-js/package.json +10 -11
  64. package/cpa-out/react-codegen-js/plasmic.json +2 -2
  65. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.jsx +6 -5
  66. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +1 -1
  67. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +1 -1
  68. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +1 -1
  69. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +1 -1
  70. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.jsx +1 -1
  71. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.jsx +1 -1
  72. package/cpa-out/react-codegen-ts/package.json +11 -11
  73. package/cpa-out/react-codegen-ts/plasmic.json +2 -2
  74. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.tsx +17 -14
  75. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +7 -7
  76. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +1 -1
  77. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +7 -7
  78. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +7 -7
  79. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Checksvg.tsx +1 -1
  80. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.tsx +1 -1
  81. package/dist/index.js +6 -1
  82. package/dist/lib.js +3 -1
  83. package/dist/tanstack/tanstack.d.ts +2 -0
  84. package/dist/tanstack/tanstack.js +79 -0
  85. package/dist/tanstack/templates/file-router/config.d.ts +1 -0
  86. package/dist/tanstack/templates/file-router/config.js +33 -0
  87. package/dist/tanstack/templates/file-router/plasmic-host.d.ts +1 -0
  88. package/dist/tanstack/templates/file-router/plasmic-host.js +27 -0
  89. package/dist/tanstack/templates/file-router/root.d.ts +2 -0
  90. package/dist/tanstack/templates/file-router/root.js +44 -0
  91. package/dist/utils/types.d.ts +1 -1
  92. package/dist/utils/types.js +7 -1
  93. package/package.json +2 -2
  94. package/run-cpa.ts +14 -6
  95. package/src/index.ts +6 -1
  96. package/src/lib.ts +3 -1
  97. package/src/tanstack/tanstack.ts +82 -0
  98. package/src/tanstack/templates/file-router/config.ts +29 -0
  99. package/src/tanstack/templates/file-router/plasmic-host.ts +23 -0
  100. package/src/tanstack/templates/file-router/root.ts +42 -0
  101. package/src/utils/types.ts +8 -2
  102. package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +0 -56
  103. package/cpa-out/nextjs-app-loader-js/app/api/hello/route.js +0 -3
  104. package/cpa-out/nextjs-app-loader-js/app/layout.js +0 -14
  105. package/cpa-out/nextjs-app-loader-js/app/plasmic-host/page.jsx +0 -6
  106. package/cpa-out/nextjs-app-loader-js/plasmic-init-client.jsx +0 -65
  107. package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +0 -59
  108. package/cpa-out/nextjs-app-loader-ts/app/api/hello/route.ts +0 -3
  109. package/cpa-out/nextjs-app-loader-ts/app/layout.tsx +0 -18
  110. package/cpa-out/nextjs-app-loader-ts/app/plasmic-host/page.tsx +0 -6
  111. package/cpa-out/nextjs-app-loader-ts/plasmic-init-client.tsx +0 -65
@@ -0,0 +1,82 @@
1
+ import { promises as fs } from "fs";
2
+ import path from "path";
3
+ import { spawnOrFail } from "../utils/cmd-utils";
4
+ import { installCodegenDeps, runCodegenSync } from "../utils/codegen";
5
+ import { deleteGlob } from "../utils/file-utils";
6
+ import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
7
+ import { makeCustomAppConfig_file_router_codegen } from "./templates/file-router/config";
8
+ import { makePlasmicHostPage_fileRouter_codegen } from "./templates/file-router/plasmic-host";
9
+ import { makeCustomRoot_file_router_codegen } from "./templates/file-router/root";
10
+
11
+ export const tanstackStrategy: CPAStrategy = {
12
+ create: async (args) => {
13
+ const { projectPath } = args;
14
+ const createCommand = `npx create-tsrouter-app@latest ${projectPath} --template file-router --add-ons start`;
15
+
16
+ await spawnOrFail(createCommand);
17
+ },
18
+ installDeps: async ({ scheme, projectPath }) => {
19
+ if (scheme === "loader") {
20
+ throw new Error(
21
+ "Plasmic loader scheme is not supported for TanStack platform. Please use the codegen scheme instead."
22
+ );
23
+ } else {
24
+ return await installCodegenDeps({ projectPath });
25
+ }
26
+ },
27
+ overwriteConfig: async (args) => {
28
+ const { projectPath, jsOrTs } = args;
29
+
30
+ /* We need to provide @plasmicapp/* packages in noExternal ssr packages for
31
+ * them to work properly during ssr phase.
32
+ */
33
+ if (jsOrTs === "ts") {
34
+ await fs.writeFile(
35
+ path.join(projectPath, "app.config.ts"),
36
+ makeCustomAppConfig_file_router_codegen()
37
+ );
38
+ }
39
+ },
40
+ generateFiles: (args) => {
41
+ return generateFilesFileRouterTemplate(args);
42
+ },
43
+ build: async (args) => {
44
+ const { npmRunCmd, projectPath } = args;
45
+ await spawnOrFail(`${npmRunCmd} build`, projectPath);
46
+ },
47
+ };
48
+
49
+ async function generateFilesFileRouterTemplate(args: GenerateFilesArgs) {
50
+ const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
51
+
52
+ // Delete existing pages
53
+ deleteGlob(path.join(projectPath, "src/routes", "*.*"));
54
+
55
+ if (scheme === "loader") {
56
+ throw new Error(
57
+ "Plasmic loader scheme is not supported for TanStack platform. Please use the codegen scheme instead."
58
+ );
59
+ } else {
60
+ // ./src/routes/__root.tsx
61
+ await fs.writeFile(
62
+ path.join(projectPath, "src/routes", `__root.${jsOrTs}x`),
63
+ makeCustomRoot_file_router_codegen(jsOrTs)
64
+ );
65
+
66
+ // ./src/routes/plasmic-host.tsx
67
+ await fs.writeFile(
68
+ path.join(projectPath, "src/routes", `plasmic-host.${jsOrTs}x`),
69
+ makePlasmicHostPage_fileRouter_codegen()
70
+ );
71
+
72
+ // This should generate
73
+ // ./plasmic.json
74
+ // ./routes/index.tsx
75
+ // ./components/plasmic/**
76
+ await runCodegenSync({
77
+ projectId,
78
+ projectApiToken,
79
+ projectPath,
80
+ });
81
+ }
82
+ }
@@ -0,0 +1,29 @@
1
+ export function makeCustomAppConfig_file_router_codegen(): string {
2
+ return `import { defineConfig } from "@tanstack/react-start/config";
3
+ import viteTsConfigPaths from "vite-tsconfig-paths";
4
+ import tailwindcss from "@tailwindcss/vite";
5
+
6
+ export default defineConfig({
7
+ tsr: {
8
+ appDirectory: "src",
9
+ },
10
+ vite: {
11
+ plugins: [
12
+ // this is the plugin that enables path aliases
13
+ viteTsConfigPaths({
14
+ projects: ["./tsconfig.json"],
15
+ }),
16
+ tailwindcss(),
17
+ ],
18
+ ssr: {
19
+ noExternal: [
20
+ "@plasmicapp/data-sources",
21
+ "@plasmicapp/data-sources-context",
22
+ "@plasmicapp/prepass",
23
+ "@plasmicapp/query",
24
+ "@plasmicapp/react-web",
25
+ ],
26
+ },
27
+ },
28
+ })`;
29
+ }
@@ -0,0 +1,23 @@
1
+ export function makePlasmicHostPage_fileRouter_codegen(): string {
2
+ return `import { createFileRoute } from '@tanstack/react-router'
3
+ import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/react-web/lib/host';
4
+
5
+ export const Route = createFileRoute('/plasmic-host')({
6
+ component: PlasmicHostRouteComponent,
7
+ })
8
+
9
+
10
+ // You can register any code components that you want to use here; see
11
+ // https://docs.plasmic.app/learn/code-components-ref/
12
+ // And configure your Plasmic project to use the host url pointing at
13
+ // the /plasmic-host page of your nextjs app (for example,
14
+ // http://localhost:3000/plasmic-host). See
15
+ // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
16
+
17
+ // registerComponent(...)
18
+
19
+ function PlasmicHostRouteComponent() {
20
+ return <PlasmicCanvasHost />
21
+ }
22
+ `;
23
+ }
@@ -0,0 +1,42 @@
1
+ import { JsOrTs } from "../../../utils/types";
2
+
3
+ export function makeCustomRoot_file_router_codegen(_jsOrTs: JsOrTs): string {
4
+ return `import { createRootRoute, HeadContent, Outlet, Scripts, Link } from '@tanstack/react-router'
5
+ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
6
+ import { PlasmicRootProvider } from "@plasmicapp/react-web"
7
+ import appCss from "../styles.css?url";
8
+
9
+ export const Route = createRootRoute({
10
+ head: () => ({
11
+ links: [
12
+ {
13
+ rel: 'stylesheet',
14
+ href: appCss,
15
+ },
16
+ ],
17
+ }),
18
+ component: () => (
19
+ <RootDocument>
20
+ <PlasmicRootProvider Link={Link}>
21
+ <Outlet />
22
+ <TanStackRouterDevtools />
23
+ </PlasmicRootProvider>
24
+ </RootDocument>
25
+ ),
26
+ })
27
+
28
+ function RootDocument({ children }: { children: React.ReactNode }) {
29
+ return (
30
+ <html lang="en">
31
+ <head>
32
+ <HeadContent />
33
+ </head>
34
+ <body>
35
+ {children}
36
+ <Scripts />
37
+ </body>
38
+ </html>
39
+ )
40
+ }
41
+ `;
42
+ }
@@ -1,5 +1,5 @@
1
1
  export type JsOrTs = "js" | "ts";
2
- export type PlatformType = "nextjs" | "gatsby" | "react";
2
+ export type PlatformType = "nextjs" | "gatsby" | "react" | "tanstack";
3
3
  export type PlatformOptions = {
4
4
  nextjs?: {
5
5
  appDir: boolean;
@@ -8,5 +8,11 @@ export type PlatformOptions = {
8
8
  export type SchemeType = "codegen" | "loader";
9
9
 
10
10
  export function platformTypeToString(s: PlatformType): string {
11
- return s === "nextjs" ? "Next.js" : s === "gatsby" ? "Gatsby" : "React";
11
+ return s === "nextjs"
12
+ ? "Next.js"
13
+ : s === "gatsby"
14
+ ? "Gatsby"
15
+ : s === "tanstack"
16
+ ? "TanStack"
17
+ : "React";
12
18
  }
@@ -1,56 +0,0 @@
1
- import { PlasmicComponent } from "@plasmicapp/loader-nextjs";
2
- import { notFound } from "next/navigation";
3
- import { PLASMIC } from "@/plasmic-init";
4
- import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
5
-
6
- // Use revalidate if you want incremental static regeneration
7
- export const revalidate = 60;
8
-
9
- export default async function PlasmicLoaderPage({
10
- params,
11
- searchParams,
12
- }) {
13
- const plasmicComponentData = await fetchPlasmicComponentData(params?.catchall);
14
- if (!plasmicComponentData) {
15
- notFound();
16
- }
17
-
18
- const { prefetchedData } = plasmicComponentData;
19
- if (prefetchedData.entryCompMetas.length === 0) {
20
- notFound();
21
- }
22
-
23
- const pageMeta = prefetchedData.entryCompMetas[0];
24
- return (
25
- <ClientPlasmicRootProvider
26
- prefetchedData={prefetchedData}
27
- pageParams={pageMeta.params}
28
- pageQuery={searchParams}
29
- >
30
- <PlasmicComponent
31
- component={pageMeta.displayName}
32
- />
33
- </ClientPlasmicRootProvider>
34
- );
35
- }
36
-
37
- async function fetchPlasmicComponentData(catchall) {
38
- const plasmicPath = "/" + (catchall ? catchall.join("/") : "");
39
- const prefetchedData = await PLASMIC.maybeFetchComponentData(plasmicPath);
40
- if (!prefetchedData) {
41
- notFound();
42
- }
43
-
44
- return { prefetchedData };
45
- }
46
-
47
- export async function generateStaticParams() {
48
- const pageModules = await PLASMIC.fetchPages();
49
- return pageModules.map((mod) => {
50
- const catchall =
51
- mod.path === "/" ? undefined : mod.path.substring(1).split("/");
52
- return {
53
- catchall,
54
- };
55
- });
56
- }
@@ -1,3 +0,0 @@
1
- export async function GET(request) {
2
- return new Response('Hello, Next.js!')
3
- }
@@ -1,14 +0,0 @@
1
- import './globals.css'
2
-
3
- export const metadata = {
4
- title: 'Create Next App',
5
- description: 'Generated by create next app',
6
- }
7
-
8
- export default function RootLayout({ children }) {
9
- return (
10
- <html lang="en">
11
- <body>{children}</body>
12
- </html>
13
- )
14
- }
@@ -1,6 +0,0 @@
1
- import { PlasmicCanvasHost } from "@plasmicapp/loader-nextjs";
2
- import "@/plasmic-init-client";
3
-
4
- export default function PlasmicHost() {
5
- return <PlasmicCanvasHost />;
6
- }
@@ -1,65 +0,0 @@
1
- "use client";
2
-
3
- import { PlasmicRootProvider } from "@plasmicapp/loader-nextjs";
4
- import { PLASMIC } from "@/plasmic-init";
5
-
6
- // You can register any code components that you want to use here; see
7
- // https://docs.plasmic.app/learn/code-components-ref/
8
- // And configure your Plasmic project to use the host url pointing at
9
- // the /plasmic-host page of your nextjs app (for example,
10
- // http://localhost:3000/plasmic-host). See
11
- // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
12
-
13
- // PLASMIC.registerComponent(...);
14
-
15
- /**
16
- * ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
17
- *
18
- * Why? Props passed from Server to Client Components must be serializable.
19
- * https://beta.nextjs.org/docs/rendering/server-and-client-components#passing-props-from-server-to-client-components-serialization
20
- * However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
21
- *
22
- * In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
23
- *
24
- * ```tsx
25
- * import { PLASMIC } from "@/plasmic-init";
26
- * import { PlasmicRootProvider } from "plasmicapp/loader-nextjs";
27
- * export default function MyPage() {
28
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
29
- * return (
30
- * <PlasmicRootProvider
31
- * loader={PLASMIC} // ERROR: loader is not serializable
32
- * prefetchedData={prefetchedData}
33
- * >
34
- * {yourContent()}
35
- * </PlasmicRootProvider>;
36
- * );
37
- * }
38
- * ```
39
- *
40
- * Therefore, we define ClientPlasmicRootProvider as a Client Component (this file is marked "use client").
41
- * ClientPlasmicRootProvider wraps the PlasmicRootProvider and passes in the loader for you,
42
- * while allowing your Server Component to pass in prefetched data and other serializable props:
43
- *
44
- * ```tsx
45
- * import { PLASMIC } from "@/plasmic-init";
46
- * import { ClientPlasmicRootProvider } from "@/plasmic-init-client"; // changed
47
- * export default function MyPage() {
48
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
49
- * return (
50
- * <ClientPlasmicRootProvider // don't pass in loader
51
- * prefetchedData={prefetchedData}
52
- * >
53
- * {yourContent()}
54
- * </ClientPlasmicRootProvider>;
55
- * );
56
- * }
57
- * ```
58
- */
59
- export function ClientPlasmicRootProvider(
60
- props
61
- ) {
62
- return (
63
- <PlasmicRootProvider loader={PLASMIC} {...props}></PlasmicRootProvider>
64
- );
65
- }
@@ -1,59 +0,0 @@
1
- import { PlasmicComponent } from "@plasmicapp/loader-nextjs";
2
- import { notFound } from "next/navigation";
3
- import { PLASMIC } from "@/plasmic-init";
4
- import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
5
-
6
- // Use revalidate if you want incremental static regeneration
7
- export const revalidate = 60;
8
-
9
- export default async function PlasmicLoaderPage({
10
- params,
11
- searchParams,
12
- }: {
13
- params?: { catchall: string[] | undefined };
14
- searchParams?: Record<string, string | string[]>;
15
- }) {
16
- const plasmicComponentData = await fetchPlasmicComponentData(params?.catchall);
17
- if (!plasmicComponentData) {
18
- notFound();
19
- }
20
-
21
- const { prefetchedData } = plasmicComponentData;
22
- if (prefetchedData.entryCompMetas.length === 0) {
23
- notFound();
24
- }
25
-
26
- const pageMeta = prefetchedData.entryCompMetas[0];
27
- return (
28
- <ClientPlasmicRootProvider
29
- prefetchedData={prefetchedData}
30
- pageParams={pageMeta.params}
31
- pageQuery={searchParams}
32
- >
33
- <PlasmicComponent
34
- component={pageMeta.displayName}
35
- />
36
- </ClientPlasmicRootProvider>
37
- );
38
- }
39
-
40
- async function fetchPlasmicComponentData(catchall: string[] | undefined) {
41
- const plasmicPath = "/" + (catchall ? catchall.join("/") : "");
42
- const prefetchedData = await PLASMIC.maybeFetchComponentData(plasmicPath);
43
- if (!prefetchedData) {
44
- notFound();
45
- }
46
-
47
- return { prefetchedData };
48
- }
49
-
50
- export async function generateStaticParams() {
51
- const pageModules = await PLASMIC.fetchPages();
52
- return pageModules.map((mod) => {
53
- const catchall =
54
- mod.path === "/" ? undefined : mod.path.substring(1).split("/");
55
- return {
56
- catchall,
57
- };
58
- });
59
- }
@@ -1,3 +0,0 @@
1
- export async function GET(request: Request) {
2
- return new Response('Hello, Next.js!')
3
- }
@@ -1,18 +0,0 @@
1
- import './globals.css'
2
-
3
- export const metadata = {
4
- title: 'Create Next App',
5
- description: 'Generated by create next app',
6
- }
7
-
8
- export default function RootLayout({
9
- children,
10
- }: {
11
- children: React.ReactNode
12
- }) {
13
- return (
14
- <html lang="en">
15
- <body>{children}</body>
16
- </html>
17
- )
18
- }
@@ -1,6 +0,0 @@
1
- import { PlasmicCanvasHost } from "@plasmicapp/loader-nextjs";
2
- import "@/plasmic-init-client";
3
-
4
- export default function PlasmicHost() {
5
- return <PlasmicCanvasHost />;
6
- }
@@ -1,65 +0,0 @@
1
- "use client";
2
-
3
- import { PlasmicRootProvider } from "@plasmicapp/loader-nextjs";
4
- import { PLASMIC } from "@/plasmic-init";
5
-
6
- // You can register any code components that you want to use here; see
7
- // https://docs.plasmic.app/learn/code-components-ref/
8
- // And configure your Plasmic project to use the host url pointing at
9
- // the /plasmic-host page of your nextjs app (for example,
10
- // http://localhost:3000/plasmic-host). See
11
- // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
12
-
13
- // PLASMIC.registerComponent(...);
14
-
15
- /**
16
- * ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
17
- *
18
- * Why? Props passed from Server to Client Components must be serializable.
19
- * https://beta.nextjs.org/docs/rendering/server-and-client-components#passing-props-from-server-to-client-components-serialization
20
- * However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
21
- *
22
- * In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
23
- *
24
- * ```tsx
25
- * import { PLASMIC } from "@/plasmic-init";
26
- * import { PlasmicRootProvider } from "plasmicapp/loader-nextjs";
27
- * export default function MyPage() {
28
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
29
- * return (
30
- * <PlasmicRootProvider
31
- * loader={PLASMIC} // ERROR: loader is not serializable
32
- * prefetchedData={prefetchedData}
33
- * >
34
- * {yourContent()}
35
- * </PlasmicRootProvider>;
36
- * );
37
- * }
38
- * ```
39
- *
40
- * Therefore, we define ClientPlasmicRootProvider as a Client Component (this file is marked "use client").
41
- * ClientPlasmicRootProvider wraps the PlasmicRootProvider and passes in the loader for you,
42
- * while allowing your Server Component to pass in prefetched data and other serializable props:
43
- *
44
- * ```tsx
45
- * import { PLASMIC } from "@/plasmic-init";
46
- * import { ClientPlasmicRootProvider } from "@/plasmic-init-client"; // changed
47
- * export default function MyPage() {
48
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
49
- * return (
50
- * <ClientPlasmicRootProvider // don't pass in loader
51
- * prefetchedData={prefetchedData}
52
- * >
53
- * {yourContent()}
54
- * </ClientPlasmicRootProvider>;
55
- * );
56
- * }
57
- * ```
58
- */
59
- export function ClientPlasmicRootProvider(
60
- props: Omit<React.ComponentProps<typeof PlasmicRootProvider>, "loader">
61
- ) {
62
- return (
63
- <PlasmicRootProvider loader={PLASMIC} {...props}></PlasmicRootProvider>
64
- );
65
- }