@plasmicapp/loader-nextjs 2.0.0-test.0 → 2.0.0
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/index.d.ts +4 -31
- package/dist/index.esm.js +33 -62
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +15 -43
- package/dist/index.js.map +3 -3
- package/dist/react-server.d.ts +1 -28
- package/dist/react-server.esm.js +8 -22
- package/dist/react-server.esm.js.map +3 -3
- package/dist/react-server.js +9 -23
- package/dist/react-server.js.map +3 -3
- package/package.json +7 -7
- package/react-server-conditional.d.ts +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { DataProvider } from '@plasmicapp/loader-react';
|
|
|
10
10
|
import { FetchComponentDataOpts as FetchComponentDataOpts_2 } from '@plasmicapp/loader-react';
|
|
11
11
|
import { GlobalActionsContext } from '@plasmicapp/loader-react';
|
|
12
12
|
import { GlobalActionsProvider } from '@plasmicapp/loader-react';
|
|
13
|
+
import { GlobalContextMeta } from '@plasmicapp/loader-react';
|
|
13
14
|
import { IncomingMessage } from 'http';
|
|
14
15
|
import { InitOptions } from '@plasmicapp/loader-react/react-server-conditional';
|
|
15
16
|
import { InternalPlasmicComponentLoader } from '@plasmicapp/loader-react';
|
|
@@ -20,7 +21,6 @@ import { PlasmicCanvasContext } from '@plasmicapp/loader-react';
|
|
|
20
21
|
import { PlasmicCanvasHost } from '@plasmicapp/loader-react';
|
|
21
22
|
import { PlasmicComponent } from '@plasmicapp/loader-react';
|
|
22
23
|
import { PlasmicComponentLoader } from '@plasmicapp/loader-react';
|
|
23
|
-
import { plasmicPrepass } from '@plasmicapp/loader-react';
|
|
24
24
|
import { PlasmicRootProvider as PlasmicRootProvider_2 } from '@plasmicapp/loader-react';
|
|
25
25
|
import { PlasmicTranslator } from '@plasmicapp/loader-react';
|
|
26
26
|
import { PlasmicTranslatorContext } from '@plasmicapp/loader-react';
|
|
@@ -98,36 +98,11 @@ export { GlobalActionsContext }
|
|
|
98
98
|
|
|
99
99
|
export { GlobalActionsProvider }
|
|
100
100
|
|
|
101
|
-
export {
|
|
101
|
+
export { GlobalContextMeta }
|
|
102
102
|
|
|
103
|
-
export
|
|
103
|
+
export { InitOptions }
|
|
104
104
|
|
|
105
|
-
export declare
|
|
106
|
-
/**
|
|
107
|
-
* next/navigation doesn't exist prior to Next.js 13, so Plasmic can't assume the dependency exists.
|
|
108
|
-
* If you use the App Router (which depends on next/navigation), you'll need to pass the module here.
|
|
109
|
-
*
|
|
110
|
-
* ```tsx
|
|
111
|
-
* import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
112
|
-
* import * as NextNavigation from "next/navigation";
|
|
113
|
-
*
|
|
114
|
-
* export const PLASMIC = initPlasmicLoader({
|
|
115
|
-
* nextNavigation: NextNavigation,
|
|
116
|
-
* projects: [
|
|
117
|
-
* // your projects
|
|
118
|
-
* ],
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
nextNavigation?: {
|
|
123
|
-
notFound: unknown;
|
|
124
|
-
redirect: unknown;
|
|
125
|
-
useParams: unknown;
|
|
126
|
-
usePathname: unknown;
|
|
127
|
-
useRouter: unknown;
|
|
128
|
-
useSearchParams: unknown;
|
|
129
|
-
};
|
|
130
|
-
}
|
|
105
|
+
export declare function initPlasmicLoader(opts: InitOptions): NextJsPlasmicComponentLoader;
|
|
131
106
|
|
|
132
107
|
export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {
|
|
133
108
|
constructor(internal: InternalPlasmicComponentLoader);
|
|
@@ -155,8 +130,6 @@ export { PlasmicCanvasHost }
|
|
|
155
130
|
|
|
156
131
|
export { PlasmicComponent }
|
|
157
132
|
|
|
158
|
-
export { plasmicPrepass }
|
|
159
|
-
|
|
160
133
|
export declare function PlasmicRootProvider(props: Omit<React_2.ComponentProps<typeof PlasmicRootProvider_2>, "Head"> & {
|
|
161
134
|
skipChunks?: boolean;
|
|
162
135
|
}): React_2.JSX.Element;
|
package/dist/index.esm.js
CHANGED
|
@@ -61,28 +61,9 @@ import {
|
|
|
61
61
|
PlasmicComponentLoader,
|
|
62
62
|
extractPlasmicQueryData as internalExtractPlasmicQueryData
|
|
63
63
|
} from "@plasmicapp/loader-react";
|
|
64
|
-
import {
|
|
65
|
-
DataCtxReader,
|
|
66
|
-
DataProvider,
|
|
67
|
-
GlobalActionsContext,
|
|
68
|
-
GlobalActionsProvider,
|
|
69
|
-
PageParamsProvider,
|
|
70
|
-
PlasmicCanvasContext,
|
|
71
|
-
PlasmicCanvasHost,
|
|
72
|
-
PlasmicComponent,
|
|
73
|
-
PlasmicTranslatorContext,
|
|
74
|
-
plasmicPrepass,
|
|
75
|
-
repeatedElement,
|
|
76
|
-
useDataEnv,
|
|
77
|
-
usePlasmicCanvasComponentInfo,
|
|
78
|
-
usePlasmicCanvasContext,
|
|
79
|
-
usePlasmicComponent,
|
|
80
|
-
usePlasmicQueryData,
|
|
81
|
-
useSelector,
|
|
82
|
-
useSelectors
|
|
83
|
-
} from "@plasmicapp/loader-react";
|
|
84
64
|
import NextHead from "next/head.js";
|
|
85
65
|
import NextLink from "next/link.js";
|
|
66
|
+
import * as NextNavigation from "next/navigation.js";
|
|
86
67
|
import * as NextRouter from "next/router.js";
|
|
87
68
|
import Script from "next/script";
|
|
88
69
|
import * as React2 from "react";
|
|
@@ -178,8 +159,9 @@ var FileCache = class {
|
|
|
178
159
|
};
|
|
179
160
|
function hashString(str) {
|
|
180
161
|
let h = 0, i = 0;
|
|
181
|
-
for (; i < str.length; h &= h)
|
|
162
|
+
for (; i < str.length; h &= h) {
|
|
182
163
|
h = 31 * h + str.charCodeAt(i++);
|
|
164
|
+
}
|
|
183
165
|
return Math.abs(h);
|
|
184
166
|
}
|
|
185
167
|
function makeCache(opts) {
|
|
@@ -195,8 +177,8 @@ function makeCache(opts) {
|
|
|
195
177
|
);
|
|
196
178
|
return new FileCache(cachePath);
|
|
197
179
|
}
|
|
198
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
199
|
-
var
|
|
180
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
181
|
+
var _a, _b, _c;
|
|
200
182
|
const isBrowser = typeof window !== "undefined";
|
|
201
183
|
const isProd = process.env.NODE_ENV === "production";
|
|
202
184
|
const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;
|
|
@@ -208,13 +190,10 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
208
190
|
platform: "nextjs",
|
|
209
191
|
platformOptions: {
|
|
210
192
|
nextjs: {
|
|
211
|
-
appDir:
|
|
193
|
+
appDir: (_c = (_b = (_a = opts.platformOptions) == null ? void 0 : _a.nextjs) == null ? void 0 : _b.appDir) != null ? _c : false
|
|
212
194
|
}
|
|
213
195
|
},
|
|
214
|
-
//
|
|
215
|
-
// of PlasmicComponentLoader that's already in memory, so we need to
|
|
216
|
-
// make sure we don't re-use the data cached in memory.
|
|
217
|
-
// We also enforce this for dev mode, so that we don't have to restart
|
|
196
|
+
// We enforce this for dev mode, so that we don't have to restart
|
|
218
197
|
// the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader
|
|
219
198
|
// We also enforce that during build phase, we re-use the data cached in memory
|
|
220
199
|
// to avoid re-fetching the data from Plasmic servers.
|
|
@@ -321,9 +300,27 @@ function wrapRouterContext(element) {
|
|
|
321
300
|
}
|
|
322
301
|
|
|
323
302
|
// src/index.tsx
|
|
324
|
-
|
|
303
|
+
import {
|
|
304
|
+
DataCtxReader,
|
|
305
|
+
DataProvider,
|
|
306
|
+
GlobalActionsContext,
|
|
307
|
+
GlobalActionsProvider,
|
|
308
|
+
PageParamsProvider,
|
|
309
|
+
PlasmicCanvasContext,
|
|
310
|
+
PlasmicCanvasHost,
|
|
311
|
+
PlasmicComponent,
|
|
312
|
+
PlasmicTranslatorContext,
|
|
313
|
+
repeatedElement,
|
|
314
|
+
useDataEnv,
|
|
315
|
+
usePlasmicCanvasComponentInfo,
|
|
316
|
+
usePlasmicCanvasContext,
|
|
317
|
+
usePlasmicComponent,
|
|
318
|
+
usePlasmicQueryData,
|
|
319
|
+
useSelector,
|
|
320
|
+
useSelectors
|
|
321
|
+
} from "@plasmicapp/loader-react";
|
|
325
322
|
function filterCodeFromRenderData(data) {
|
|
326
|
-
if (
|
|
323
|
+
if (data.bundle.bundleKey) {
|
|
327
324
|
const entrypoints = /* @__PURE__ */ new Set([
|
|
328
325
|
...data.entryCompMetas.map((compMeta) => compMeta.entry),
|
|
329
326
|
"root-provider.js",
|
|
@@ -418,21 +415,17 @@ function parseFetchComponentDataArgs(...args) {
|
|
|
418
415
|
}
|
|
419
416
|
function initPlasmicLoader(opts) {
|
|
420
417
|
const loader = initPlasmicLoaderWithCache(
|
|
421
|
-
(
|
|
422
|
-
new InternalPlasmicComponentLoader(
|
|
418
|
+
(opts_) => new NextJsPlasmicComponentLoader(
|
|
419
|
+
new InternalPlasmicComponentLoader(opts_)
|
|
423
420
|
),
|
|
424
421
|
opts
|
|
425
422
|
);
|
|
426
423
|
loader.registerModules({
|
|
427
424
|
"next/head": NextHead,
|
|
428
425
|
"next/link": NextLink,
|
|
426
|
+
"next/navigation": NextNavigation,
|
|
429
427
|
"next/router": NextRouter
|
|
430
428
|
});
|
|
431
|
-
if (opts.nextNavigation) {
|
|
432
|
-
loader.registerModules({
|
|
433
|
-
"next/navigation": opts.nextNavigation
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
429
|
return loader;
|
|
437
430
|
}
|
|
438
431
|
function extractPlasmicQueryData(element) {
|
|
@@ -442,36 +435,15 @@ function extractPlasmicQueryData(element) {
|
|
|
442
435
|
}
|
|
443
436
|
var PlasmicNextLink = React2.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
444
437
|
if (props.href) {
|
|
445
|
-
const _a = props, {
|
|
446
|
-
href,
|
|
447
|
-
replace,
|
|
448
|
-
scroll,
|
|
449
|
-
shallow,
|
|
450
|
-
passHref,
|
|
451
|
-
prefetch,
|
|
452
|
-
locale
|
|
453
|
-
} = _a, rest = __objRest(_a, [
|
|
454
|
-
"href",
|
|
455
|
-
"replace",
|
|
456
|
-
"scroll",
|
|
457
|
-
"shallow",
|
|
458
|
-
"passHref",
|
|
459
|
-
"prefetch",
|
|
460
|
-
"locale"
|
|
461
|
-
]);
|
|
438
|
+
const _a = props, { href, scroll } = _a, rest = __objRest(_a, ["href", "scroll"]);
|
|
462
439
|
const isFragment = typeof href === "string" && href.startsWith("#");
|
|
463
440
|
return /* @__PURE__ */ React2.createElement(
|
|
464
441
|
NextLink,
|
|
465
442
|
__spreadValues({
|
|
466
443
|
href,
|
|
467
|
-
replace,
|
|
468
444
|
scroll: scroll != null ? scroll : isFragment ? false : void 0,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
prefetch,
|
|
472
|
-
locale
|
|
473
|
-
}, { legacyBehavior: true }),
|
|
474
|
-
/* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, rest), { ref }))
|
|
445
|
+
ref
|
|
446
|
+
}, rest)
|
|
475
447
|
);
|
|
476
448
|
} else {
|
|
477
449
|
return /* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, props), { href: void 0, ref }));
|
|
@@ -561,7 +533,6 @@ export {
|
|
|
561
533
|
PlasmicTranslatorContext,
|
|
562
534
|
extractPlasmicQueryData,
|
|
563
535
|
initPlasmicLoader,
|
|
564
|
-
plasmicPrepass,
|
|
565
536
|
repeatedElement,
|
|
566
537
|
useDataEnv,
|
|
567
538
|
usePlasmicCanvasComponentInfo,
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx", "../src/cache.ts", "../src/server-require.ts", "../src/mocks.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport * from \"./shared-exports\";\n// NextHead and NextLink must be default imported (`import Pkg`) instead of a namespace import (`import * as Pkg`).\n// Otherwise, there's a Next.js 12 bug when referencing these dependencies due to default import interop.\n// The transpiled CommonJS code would create a `default` field on the package,\n// causing React to think it's an invalid React object:\n// ```\n// const NextHead = __defaultInterop(require('next/head.js'))\n// assert(typeof NextHead === 'object')\n// assert(typeof NextHead.default === 'function')\n// ```\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(opts: NextInitOptions) {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/router\": NextRouter,\n });\n if (opts.nextNavigation) {\n loader.registerModules({\n \"next/navigation\": opts.nextNavigation,\n });\n }\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const {\n href,\n replace,\n scroll,\n shallow,\n passHref,\n prefetch,\n locale,\n ...rest\n } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n // We use legacyBehavior, because we don't know which\n // version of next the user has installed\n return (\n <NextLink\n href={href}\n replace={replace}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n shallow={shallow}\n passHref={passHref}\n prefetch={prefetch}\n locale={locale}\n {...({ legacyBehavior: true } as any)}\n >\n <a {...rest} ref={ref} />\n </NextLink>\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(\n initFn: (opts: InitOptions) => T,\n { nextNavigation, ...opts }: NextInitOptions\n): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: !!nextNavigation,\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE,uBAAuB;AAAA,EAGvB;AAAA,EACA;AAAA,EACA,2BAA2B;AAAA,OACtB;AAEP
|
|
6
|
-
"names": ["React", "err", "require", "err", "
|
|
4
|
+
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\n// client-only exports\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n GlobalContextMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts_) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts_)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const { href, scroll, ...rest } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n return (\n <NextLink\n href={href}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n ref={ref}\n {...rest}\n />\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) {\n h = 31 * h + str.charCodeAt(i++);\n }\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts_: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: opts.platformOptions?.nextjs?.appDir ?? false,\n },\n },\n // We enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE,uBAAuB;AAAA,EAGvB;AAAA,EACA;AAAA,EACA,2BAA2B;AAAA,OACtB;AAEP,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,YAAY,oBAAoB;AAChC,YAAY,gBAAgB;AAC5B,OAAO,YAAY;AACnB,YAAYA,YAAW;;;ACZvB,SAAS,8BAA8B;AACvC,OAAO,UAAU;;;ACFjB,IAAI;AACJ,IAAI;AAGF,kBAAgB,KAAK,SAAS;AAChC,SAAS,KAAP;AACA,MAAI;AAEF,oBAAgB,KAAK,4BAA4B;AAAA,EACnD,SAASC,MAAP;AACA,oBAAgB;AAAA,EAClB;AACF;AAEA,SAAsB,cAAiB,QAA4B;AAAA;AACjE,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,cAAc,MAAM;AAAA,EAC7B;AAAA;AAEA,SAAsB,iBACpB,QACwB;AAAA;AACxB,QAAI;AACF,YAAMC,WAAU,MAAM,cAAiB,MAAM;AAC7C,aAAOA;AAAA,IACT,SAAQ,GAAN;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAEA,SAAsB,kBACpB,SACwB;AAAA;AACxB,eAAW,UAAU,SAAS;AAC5B,YAAMA,WAAU,MAAM,iBAAoB,MAAM;AAChD,UAAIA,YAAW,MAAM;AACnB,eAAOA;AAAA,MACT;AA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AAAA,UAChC;AAAA;AAAA;AAAA;AAAA,QAIN,EACC,KAAK,IAAI,IAAI,KAAK;AAAA,MACzB;AAAA;AAAA,EACD,GACD;AAAA,IAAC;AAAA;AAAA,MACC,UAAS;AAAA,MACT,KAAK,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MACjE,IAAI,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MAChE,OAAK;AAAA,MACL,OAAK;AAAA,MACL,KAAK,OAAO,aAAa,eAAe,QAAQ,kBAAkB;AAAA;AAAA,EACpE,CACF;AAEJ;",
|
|
6
|
+
"names": ["React", "err", "require", "err", "PlasmicNextLink"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,6 @@ __export(src_exports, {
|
|
|
95
95
|
PlasmicTranslatorContext: () => import_loader_react2.PlasmicTranslatorContext,
|
|
96
96
|
extractPlasmicQueryData: () => extractPlasmicQueryData,
|
|
97
97
|
initPlasmicLoader: () => initPlasmicLoader,
|
|
98
|
-
plasmicPrepass: () => import_loader_react2.plasmicPrepass,
|
|
99
98
|
repeatedElement: () => import_loader_react2.repeatedElement,
|
|
100
99
|
useDataEnv: () => import_loader_react2.useDataEnv,
|
|
101
100
|
usePlasmicCanvasComponentInfo: () => import_loader_react2.usePlasmicCanvasComponentInfo,
|
|
@@ -107,9 +106,9 @@ __export(src_exports, {
|
|
|
107
106
|
});
|
|
108
107
|
module.exports = __toCommonJS(src_exports);
|
|
109
108
|
var import_loader_react = require("@plasmicapp/loader-react");
|
|
110
|
-
var import_loader_react2 = require("@plasmicapp/loader-react");
|
|
111
109
|
var import_head = __toESM(require("next/head.js"));
|
|
112
110
|
var import_link = __toESM(require("next/link.js"));
|
|
111
|
+
var NextNavigation = __toESM(require("next/navigation.js"));
|
|
113
112
|
var NextRouter = __toESM(require("next/router.js"));
|
|
114
113
|
var import_script = __toESM(require("next/script"));
|
|
115
114
|
var React2 = __toESM(require("react"));
|
|
@@ -205,8 +204,9 @@ var FileCache = class {
|
|
|
205
204
|
};
|
|
206
205
|
function hashString(str) {
|
|
207
206
|
let h = 0, i = 0;
|
|
208
|
-
for (; i < str.length; h &= h)
|
|
207
|
+
for (; i < str.length; h &= h) {
|
|
209
208
|
h = 31 * h + str.charCodeAt(i++);
|
|
209
|
+
}
|
|
210
210
|
return Math.abs(h);
|
|
211
211
|
}
|
|
212
212
|
function makeCache(opts) {
|
|
@@ -222,8 +222,8 @@ function makeCache(opts) {
|
|
|
222
222
|
);
|
|
223
223
|
return new FileCache(cachePath);
|
|
224
224
|
}
|
|
225
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
226
|
-
var
|
|
225
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
226
|
+
var _a, _b, _c;
|
|
227
227
|
const isBrowser = typeof window !== "undefined";
|
|
228
228
|
const isProd = process.env.NODE_ENV === "production";
|
|
229
229
|
const isBuildPhase = process.env.NEXT_PHASE === import_constants.PHASE_PRODUCTION_BUILD;
|
|
@@ -235,13 +235,10 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
235
235
|
platform: "nextjs",
|
|
236
236
|
platformOptions: {
|
|
237
237
|
nextjs: {
|
|
238
|
-
appDir:
|
|
238
|
+
appDir: (_c = (_b = (_a = opts.platformOptions) == null ? void 0 : _a.nextjs) == null ? void 0 : _b.appDir) != null ? _c : false
|
|
239
239
|
}
|
|
240
240
|
},
|
|
241
|
-
//
|
|
242
|
-
// of PlasmicComponentLoader that's already in memory, so we need to
|
|
243
|
-
// make sure we don't re-use the data cached in memory.
|
|
244
|
-
// We also enforce this for dev mode, so that we don't have to restart
|
|
241
|
+
// We enforce this for dev mode, so that we don't have to restart
|
|
245
242
|
// the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader
|
|
246
243
|
// We also enforce that during build phase, we re-use the data cached in memory
|
|
247
244
|
// to avoid re-fetching the data from Plasmic servers.
|
|
@@ -348,9 +345,9 @@ function wrapRouterContext(element) {
|
|
|
348
345
|
}
|
|
349
346
|
|
|
350
347
|
// src/index.tsx
|
|
351
|
-
var
|
|
348
|
+
var import_loader_react2 = require("@plasmicapp/loader-react");
|
|
352
349
|
function filterCodeFromRenderData(data) {
|
|
353
|
-
if (
|
|
350
|
+
if (data.bundle.bundleKey) {
|
|
354
351
|
const entrypoints = /* @__PURE__ */ new Set([
|
|
355
352
|
...data.entryCompMetas.map((compMeta) => compMeta.entry),
|
|
356
353
|
"root-provider.js",
|
|
@@ -445,21 +442,17 @@ function parseFetchComponentDataArgs(...args) {
|
|
|
445
442
|
}
|
|
446
443
|
function initPlasmicLoader(opts) {
|
|
447
444
|
const loader = initPlasmicLoaderWithCache(
|
|
448
|
-
(
|
|
449
|
-
new import_loader_react.InternalPlasmicComponentLoader(
|
|
445
|
+
(opts_) => new NextJsPlasmicComponentLoader(
|
|
446
|
+
new import_loader_react.InternalPlasmicComponentLoader(opts_)
|
|
450
447
|
),
|
|
451
448
|
opts
|
|
452
449
|
);
|
|
453
450
|
loader.registerModules({
|
|
454
451
|
"next/head": import_head.default,
|
|
455
452
|
"next/link": import_link.default,
|
|
453
|
+
"next/navigation": NextNavigation,
|
|
456
454
|
"next/router": NextRouter
|
|
457
455
|
});
|
|
458
|
-
if (opts.nextNavigation) {
|
|
459
|
-
loader.registerModules({
|
|
460
|
-
"next/navigation": opts.nextNavigation
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
456
|
return loader;
|
|
464
457
|
}
|
|
465
458
|
function extractPlasmicQueryData(element) {
|
|
@@ -469,36 +462,15 @@ function extractPlasmicQueryData(element) {
|
|
|
469
462
|
}
|
|
470
463
|
var PlasmicNextLink = React2.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
471
464
|
if (props.href) {
|
|
472
|
-
const _a = props, {
|
|
473
|
-
href,
|
|
474
|
-
replace,
|
|
475
|
-
scroll,
|
|
476
|
-
shallow,
|
|
477
|
-
passHref,
|
|
478
|
-
prefetch,
|
|
479
|
-
locale
|
|
480
|
-
} = _a, rest = __objRest(_a, [
|
|
481
|
-
"href",
|
|
482
|
-
"replace",
|
|
483
|
-
"scroll",
|
|
484
|
-
"shallow",
|
|
485
|
-
"passHref",
|
|
486
|
-
"prefetch",
|
|
487
|
-
"locale"
|
|
488
|
-
]);
|
|
465
|
+
const _a = props, { href, scroll } = _a, rest = __objRest(_a, ["href", "scroll"]);
|
|
489
466
|
const isFragment = typeof href === "string" && href.startsWith("#");
|
|
490
467
|
return /* @__PURE__ */ React2.createElement(
|
|
491
468
|
import_link.default,
|
|
492
469
|
__spreadValues({
|
|
493
470
|
href,
|
|
494
|
-
replace,
|
|
495
471
|
scroll: scroll != null ? scroll : isFragment ? false : void 0,
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
prefetch,
|
|
499
|
-
locale
|
|
500
|
-
}, { legacyBehavior: true }),
|
|
501
|
-
/* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, rest), { ref }))
|
|
472
|
+
ref
|
|
473
|
+
}, rest)
|
|
502
474
|
);
|
|
503
475
|
} else {
|
|
504
476
|
return /* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, props), { href: void 0, ref }));
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx", "../src/cache.ts", "../src/server-require.ts", "../src/mocks.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport * from \"./shared-exports\";\n// NextHead and NextLink must be default imported (`import Pkg`) instead of a namespace import (`import * as Pkg`).\n// Otherwise, there's a Next.js 12 bug when referencing these dependencies due to default import interop.\n// The transpiled CommonJS code would create a `default` field on the package,\n// causing React to think it's an invalid React object:\n// ```\n// const NextHead = __defaultInterop(require('next/head.js'))\n// assert(typeof NextHead === 'object')\n// assert(typeof NextHead.default === 'function')\n// ```\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(opts: NextInitOptions) {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/router\": NextRouter,\n });\n if (opts.nextNavigation) {\n loader.registerModules({\n \"next/navigation\": opts.nextNavigation,\n });\n }\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const {\n href,\n replace,\n scroll,\n shallow,\n passHref,\n prefetch,\n locale,\n ...rest\n } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n // We use legacyBehavior, because we don't know which\n // version of next the user has installed\n return (\n <NextLink\n href={href}\n replace={replace}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n shallow={shallow}\n passHref={passHref}\n prefetch={prefetch}\n locale={locale}\n {...({ legacyBehavior: true } as any)}\n >\n <a {...rest} ref={ref} />\n </NextLink>\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(\n initFn: (opts: InitOptions) => T,\n { nextNavigation, ...opts }: NextInitOptions\n): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: !!nextNavigation,\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\n// client-only exports\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n GlobalContextMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts_) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts_)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const { href, scroll, ...rest } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n return (\n <NextLink\n href={href}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n ref={ref}\n {...rest}\n />\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) {\n h = 31 * h + str.charCodeAt(i++);\n }\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts_: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: opts.platformOptions?.nextjs?.appDir ?? false,\n },\n },\n // We enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAOO;AAEP,kBAAqB;AACrB,kBAAqB;AACrB,qBAAgC;AAChC,iBAA4B;AAC5B,oBAAmB;AACnB,IAAAA,SAAuB;;;ACZvB,uBAAuC;AACvC,kBAAiB;;;ACFjB,IAAI;AACJ,IAAI;AAGF,kBAAgB,KAAK,SAAS;AAChC,SAAS,KAAP;AACA,MAAI;AAEF,oBAAgB,KAAK,4BAA4B;AAAA,EACnD,SAASC,MAAP;AACA,oBAAgB;AAAA,EAClB;AACF;AAEA,SAAsB,cAAiBC,SAA4B;AAAA;AACjE,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,cAAcA,OAAM;AAAA,EAC7B;AAAA;AAEA,SAAsB,iBACpBA,SACwB;AAAA;AACxB,QAAI;AACF,YAAMC,WAAU,MAAM,cAAiBD,OAAM;AAC7C,aAAOC;AAAA,IACT,SAAQ,GAAN;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAEA,SAAsB,kBACpB,SACwB;AAAA;AACxB,eAAWD,WAAU,SAAS;AAC5B,YAAMC,WAAU,MAAM,iBAAoBD,OAAM;AAChD,UAAIC,YAAW,MAAM;AACnB,eAAOA;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA;AA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AAAM;AAAA,IAAA;AAAA,MACC,UAAS;AAAA,MACT,KAAK,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MACjE,IAAI,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MAChE,OAAK;AAAA,MACL,OAAK;AAAA,MACL,KAAK,OAAO,aAAa,eAAe,QAAQ,kBAAkB;AAAA;AAAA,EACpE,CACF;AAEJ;",
|
|
6
|
+
"names": ["React", "err", "module", "require", "path", "err", "import_loader_react", "module", "NextHead", "NextLink", "internalExtractPlasmicQueryData", "PlasmicNextLink", "CommonPlasmicRootProvider", "Script"]
|
|
7
7
|
}
|
package/dist/react-server.d.ts
CHANGED
|
@@ -16,34 +16,7 @@ export { ComponentRenderData }
|
|
|
16
16
|
|
|
17
17
|
export { InitOptions }
|
|
18
18
|
|
|
19
|
-
export declare function initPlasmicLoader(opts:
|
|
20
|
-
|
|
21
|
-
export declare interface NextInitOptions extends InitOptions {
|
|
22
|
-
/**
|
|
23
|
-
* next/navigation doesn't exist prior to Next.js 13, so Plasmic can't assume the dependency exists.
|
|
24
|
-
* If you use the App Router (which depends on next/navigation), you'll need to pass the module here.
|
|
25
|
-
*
|
|
26
|
-
* ```tsx
|
|
27
|
-
* import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
28
|
-
* import * as NextNavigation from "next/navigation";
|
|
29
|
-
*
|
|
30
|
-
* export const PLASMIC = initPlasmicLoader({
|
|
31
|
-
* nextNavigation: NextNavigation,
|
|
32
|
-
* projects: [
|
|
33
|
-
* // your projects
|
|
34
|
-
* ],
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
nextNavigation?: {
|
|
39
|
-
notFound: unknown;
|
|
40
|
-
redirect: unknown;
|
|
41
|
-
useParams: unknown;
|
|
42
|
-
usePathname: unknown;
|
|
43
|
-
useRouter: unknown;
|
|
44
|
-
useSearchParams: unknown;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
19
|
+
export declare function initPlasmicLoader(opts: InitOptions): NextJsPlasmicComponentLoader;
|
|
47
20
|
|
|
48
21
|
export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {
|
|
49
22
|
constructor(internal: InternalPlasmicComponentLoader);
|
package/dist/react-server.esm.js
CHANGED
|
@@ -17,18 +17,6 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
20
|
var __async = (__this, __arguments, generator) => {
|
|
33
21
|
return new Promise((resolve, reject) => {
|
|
34
22
|
var fulfilled = (value) => {
|
|
@@ -58,7 +46,7 @@ import {
|
|
|
58
46
|
} from "@plasmicapp/loader-react/react-server";
|
|
59
47
|
import NextHead from "next/head.js";
|
|
60
48
|
import NextLink from "next/link.js";
|
|
61
|
-
import NextNavigation from "next/navigation.js";
|
|
49
|
+
import * as NextNavigation from "next/navigation.js";
|
|
62
50
|
import * as NextRouter from "next/router.js";
|
|
63
51
|
|
|
64
52
|
// src/cache.ts
|
|
@@ -152,8 +140,9 @@ var FileCache = class {
|
|
|
152
140
|
};
|
|
153
141
|
function hashString(str) {
|
|
154
142
|
let h = 0, i = 0;
|
|
155
|
-
for (; i < str.length; h &= h)
|
|
143
|
+
for (; i < str.length; h &= h) {
|
|
156
144
|
h = 31 * h + str.charCodeAt(i++);
|
|
145
|
+
}
|
|
157
146
|
return Math.abs(h);
|
|
158
147
|
}
|
|
159
148
|
function makeCache(opts) {
|
|
@@ -169,8 +158,8 @@ function makeCache(opts) {
|
|
|
169
158
|
);
|
|
170
159
|
return new FileCache(cachePath);
|
|
171
160
|
}
|
|
172
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
173
|
-
var
|
|
161
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
162
|
+
var _a, _b, _c;
|
|
174
163
|
const isBrowser = typeof window !== "undefined";
|
|
175
164
|
const isProd = process.env.NODE_ENV === "production";
|
|
176
165
|
const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;
|
|
@@ -182,13 +171,10 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
182
171
|
platform: "nextjs",
|
|
183
172
|
platformOptions: {
|
|
184
173
|
nextjs: {
|
|
185
|
-
appDir:
|
|
174
|
+
appDir: (_c = (_b = (_a = opts.platformOptions) == null ? void 0 : _a.nextjs) == null ? void 0 : _b.appDir) != null ? _c : false
|
|
186
175
|
}
|
|
187
176
|
},
|
|
188
|
-
//
|
|
189
|
-
// of PlasmicComponentLoader that's already in memory, so we need to
|
|
190
|
-
// make sure we don't re-use the data cached in memory.
|
|
191
|
-
// We also enforce this for dev mode, so that we don't have to restart
|
|
177
|
+
// We enforce this for dev mode, so that we don't have to restart
|
|
192
178
|
// the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader
|
|
193
179
|
// We also enforce that during build phase, we re-use the data cached in memory
|
|
194
180
|
// to avoid re-fetching the data from Plasmic servers.
|
|
@@ -292,7 +278,7 @@ var NextJsPlasmicComponentLoader = class extends PlasmicComponentLoader {
|
|
|
292
278
|
};
|
|
293
279
|
function initPlasmicLoader(opts) {
|
|
294
280
|
const loader = initPlasmicLoaderWithCache(
|
|
295
|
-
(
|
|
281
|
+
(opts_) => new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts_)),
|
|
296
282
|
opts
|
|
297
283
|
);
|
|
298
284
|
loader.registerModules({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/react-server.tsx", "../src/cache.ts", "../src/server-require.ts"],
|
|
4
|
-
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["err", "require", "err"
|
|
4
|
+
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts_) =>\n new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts_)),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) {\n h = 31 * h + str.charCodeAt(i++);\n }\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts_: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: opts.platformOptions?.nextjs?.appDir ?? false,\n },\n },\n // We enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,YAAY,oBAAoB;AAChC,YAAY,gBAAgB;;;ACP5B,SAA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ACjB,CAAC;AACD,SAAO;AACT;",
|
|
6
|
+
"names": ["err", "require", "err"]
|
|
7
7
|
}
|
package/dist/react-server.js
CHANGED
|
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
25
|
var __export = (target, all) => {
|
|
38
26
|
for (var name in all)
|
|
39
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -87,7 +75,7 @@ var import_server_only = require("server-only");
|
|
|
87
75
|
var import_react_server = require("@plasmicapp/loader-react/react-server");
|
|
88
76
|
var import_head = __toESM(require("next/head.js"));
|
|
89
77
|
var import_link = __toESM(require("next/link.js"));
|
|
90
|
-
var
|
|
78
|
+
var NextNavigation = __toESM(require("next/navigation.js"));
|
|
91
79
|
var NextRouter = __toESM(require("next/router.js"));
|
|
92
80
|
|
|
93
81
|
// src/cache.ts
|
|
@@ -181,8 +169,9 @@ var FileCache = class {
|
|
|
181
169
|
};
|
|
182
170
|
function hashString(str) {
|
|
183
171
|
let h = 0, i = 0;
|
|
184
|
-
for (; i < str.length; h &= h)
|
|
172
|
+
for (; i < str.length; h &= h) {
|
|
185
173
|
h = 31 * h + str.charCodeAt(i++);
|
|
174
|
+
}
|
|
186
175
|
return Math.abs(h);
|
|
187
176
|
}
|
|
188
177
|
function makeCache(opts) {
|
|
@@ -198,8 +187,8 @@ function makeCache(opts) {
|
|
|
198
187
|
);
|
|
199
188
|
return new FileCache(cachePath);
|
|
200
189
|
}
|
|
201
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
202
|
-
var
|
|
190
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
191
|
+
var _a, _b, _c;
|
|
203
192
|
const isBrowser = typeof window !== "undefined";
|
|
204
193
|
const isProd = process.env.NODE_ENV === "production";
|
|
205
194
|
const isBuildPhase = process.env.NEXT_PHASE === import_constants.PHASE_PRODUCTION_BUILD;
|
|
@@ -211,13 +200,10 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
211
200
|
platform: "nextjs",
|
|
212
201
|
platformOptions: {
|
|
213
202
|
nextjs: {
|
|
214
|
-
appDir:
|
|
203
|
+
appDir: (_c = (_b = (_a = opts.platformOptions) == null ? void 0 : _a.nextjs) == null ? void 0 : _b.appDir) != null ? _c : false
|
|
215
204
|
}
|
|
216
205
|
},
|
|
217
|
-
//
|
|
218
|
-
// of PlasmicComponentLoader that's already in memory, so we need to
|
|
219
|
-
// make sure we don't re-use the data cached in memory.
|
|
220
|
-
// We also enforce this for dev mode, so that we don't have to restart
|
|
206
|
+
// We enforce this for dev mode, so that we don't have to restart
|
|
221
207
|
// the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader
|
|
222
208
|
// We also enforce that during build phase, we re-use the data cached in memory
|
|
223
209
|
// to avoid re-fetching the data from Plasmic servers.
|
|
@@ -321,13 +307,13 @@ var NextJsPlasmicComponentLoader = class extends import_react_server.PlasmicComp
|
|
|
321
307
|
};
|
|
322
308
|
function initPlasmicLoader(opts) {
|
|
323
309
|
const loader = initPlasmicLoaderWithCache(
|
|
324
|
-
(
|
|
310
|
+
(opts_) => new import_react_server.PlasmicComponentLoader(new import_react_server.InternalPlasmicComponentLoader(opts_)),
|
|
325
311
|
opts
|
|
326
312
|
);
|
|
327
313
|
loader.registerModules({
|
|
328
314
|
"next/head": import_head.default,
|
|
329
315
|
"next/link": import_link.default,
|
|
330
|
-
"next/navigation":
|
|
316
|
+
"next/navigation": NextNavigation,
|
|
331
317
|
"next/router": NextRouter
|
|
332
318
|
});
|
|
333
319
|
return loader;
|
package/dist/react-server.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/react-server.tsx", "../src/cache.ts", "../src/server-require.ts"],
|
|
4
|
-
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["err", "module", "require", "path", "err", "
|
|
4
|
+
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts_) =>\n new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts_)),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) {\n h = 31 * h + str.charCodeAt(i++);\n }\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts_: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: opts.platformOptions?.nextjs?.appDir ?? false,\n },\n },\n // We enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AA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AAK,CAAC;AAAA,IACtE;AAAA,EACF;AACA,SAAO,gBAAgB;AAAA,IACrB,aAAa,YAAAE;AAAA,IACb,aAAa,YAAAC;AAAA,IACb,mBAAmB;AAAA,IACnB,eAAe;AAAA,EACjB,CAAC;AACD,SAAO;AACT;",
|
|
6
|
+
"names": ["err", "module", "require", "path", "err", "NextHead", "NextLink"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "2.0.0",
|
|
2
3
|
"name": "@plasmicapp/loader-nextjs",
|
|
3
|
-
"version": "2.0.0-test.0",
|
|
4
4
|
"description": "Plasmic loader SDK for Next.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"edge.d.ts"
|
|
48
48
|
],
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=18.17"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "yarn build:types && yarn build:index && yarn build:edge && yarn build:react-server",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
],
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@plasmicapp/loader-core": "
|
|
79
|
-
"@plasmicapp/loader-edge": "1.0.
|
|
80
|
-
"@plasmicapp/loader-react": "2.0.0
|
|
81
|
-
"@plasmicapp/nextjs-app-router": "1.0.
|
|
78
|
+
"@plasmicapp/loader-core": "2.0.0",
|
|
79
|
+
"@plasmicapp/loader-edge": "1.0.76",
|
|
80
|
+
"@plasmicapp/loader-react": "2.0.0",
|
|
81
|
+
"@plasmicapp/nextjs-app-router": "1.0.22",
|
|
82
82
|
"@plasmicapp/watcher": "1.0.84",
|
|
83
83
|
"server-only": "0.0.1"
|
|
84
84
|
},
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"react": ">=18.2.0",
|
|
95
95
|
"react-dom": ">=18.2.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "cf4b7bfc318b5360730e4e080925370e37870858"
|
|
98
98
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// Disambiguate `initPlasmicLoader` and `NextJsPlasmicComponentLoader`.
|
|
2
|
+
// Prefer the "default" version since it is more permissive.
|
|
3
|
+
import { initPlasmicLoader, NextJsPlasmicComponentLoader } from "./dist/index";
|
|
2
4
|
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
|
|
6
|
-
export { initPlasmicLoader };
|
|
5
|
+
export * from "./dist/index";
|
|
6
|
+
export * from "./dist/react-server";
|
|
7
|
+
export { initPlasmicLoader, NextJsPlasmicComponentLoader };
|