@plasmicapp/loader-nextjs 1.0.348 → 1.0.350
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 +5 -1
- package/dist/index.esm.js +78 -1
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +78 -1
- package/dist/index.js.map +3 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader
|
|
|
82
82
|
known?: Record<string, string>;
|
|
83
83
|
traits: Record<string, string | number | boolean>;
|
|
84
84
|
}): Promise<Record<string, string>>;
|
|
85
|
+
__unstable_maybeFetchComponentMetadata: PlasmicComponentLoader["maybeFetchComponentData"];
|
|
86
|
+
__unstable_fetchComponentMetadata: PlasmicComponentLoader["fetchComponentData"];
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
export { PageMeta }
|
|
@@ -98,7 +100,9 @@ export { PlasmicComponent }
|
|
|
98
100
|
|
|
99
101
|
export { plasmicPrepass }
|
|
100
102
|
|
|
101
|
-
export declare function PlasmicRootProvider(props: Omit<React_2.ComponentProps<typeof PlasmicRootProvider_2>, "Head">
|
|
103
|
+
export declare function PlasmicRootProvider(props: Omit<React_2.ComponentProps<typeof PlasmicRootProvider_2>, "Head"> & {
|
|
104
|
+
skipChunks?: boolean;
|
|
105
|
+
}): React_2.JSX.Element;
|
|
102
106
|
|
|
103
107
|
export { PlasmicTranslator }
|
|
104
108
|
|
package/dist/index.esm.js
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
import NextHead from "next/head.js";
|
|
61
61
|
import NextLink from "next/link.js";
|
|
62
62
|
import * as NextRouter from "next/router.js";
|
|
63
|
+
import Script from "next/script";
|
|
63
64
|
import * as React from "react";
|
|
64
65
|
|
|
65
66
|
// src/cache.ts
|
|
@@ -231,9 +232,39 @@ import {
|
|
|
231
232
|
useSelector,
|
|
232
233
|
useSelectors
|
|
233
234
|
} from "@plasmicapp/loader-react";
|
|
235
|
+
var reactMajorVersion = +React.version.split(".")[0];
|
|
236
|
+
function filterCodeFromRenderData(data) {
|
|
237
|
+
if (reactMajorVersion >= 18 && !!data.bundle.bundleUrlQuery) {
|
|
238
|
+
const entrypoints = /* @__PURE__ */ new Set([
|
|
239
|
+
...data.entryCompMetas.map((compMeta) => compMeta.entry),
|
|
240
|
+
"root-provider.js",
|
|
241
|
+
...data.bundle.projects.map((x) => x.globalContextsProviderFileName).filter((x) => !!x),
|
|
242
|
+
...data.bundle.components.filter((c) => c.isGlobalContextProvider).map((c) => c.entry),
|
|
243
|
+
...data.bundle.globalGroups.map((g) => g.contextFile)
|
|
244
|
+
]);
|
|
245
|
+
data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {
|
|
246
|
+
if (module.type !== "code" || entrypoints.has(module.fileName)) {
|
|
247
|
+
return module;
|
|
248
|
+
}
|
|
249
|
+
return __spreadProps(__spreadValues({}, module), { code: "" });
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
234
253
|
var NextJsPlasmicComponentLoader = class extends PlasmicComponentLoader {
|
|
235
254
|
constructor(internal) {
|
|
236
255
|
super(internal);
|
|
256
|
+
this.__unstable_maybeFetchComponentMetadata = (...specs) => __async(this, null, function* () {
|
|
257
|
+
const data = yield this.maybeFetchComponentData(...specs);
|
|
258
|
+
if (data) {
|
|
259
|
+
filterCodeFromRenderData(data);
|
|
260
|
+
}
|
|
261
|
+
return data;
|
|
262
|
+
});
|
|
263
|
+
this.__unstable_fetchComponentMetadata = (...specs) => __async(this, null, function* () {
|
|
264
|
+
const data = yield this.fetchComponentData(...specs);
|
|
265
|
+
filterCodeFromRenderData(data);
|
|
266
|
+
return data;
|
|
267
|
+
});
|
|
237
268
|
}
|
|
238
269
|
getActiveVariation(opts) {
|
|
239
270
|
return __async(this, null, function* () {
|
|
@@ -332,13 +363,59 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
332
363
|
}
|
|
333
364
|
});
|
|
334
365
|
function PlasmicRootProvider(props) {
|
|
335
|
-
return /* @__PURE__ */ React.createElement(
|
|
366
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, !props.skipChunks && renderDynamicPayloadScripts(props.loader, props.prefetchedData), /* @__PURE__ */ React.createElement(
|
|
336
367
|
CommonPlasmicRootProvider,
|
|
337
368
|
__spreadValues({
|
|
338
369
|
Head: NextHead,
|
|
339
370
|
Link: PlasmicNextLink
|
|
340
371
|
}, props)
|
|
372
|
+
));
|
|
373
|
+
}
|
|
374
|
+
function renderDynamicPayloadScripts(loader, prefetchedData) {
|
|
375
|
+
const missingModulesData = prefetchedData && prefetchedData.bundle.modules.browser.filter(
|
|
376
|
+
(module) => module.type === "code" && !module.code
|
|
341
377
|
);
|
|
378
|
+
if (!missingModulesData || missingModulesData.length === 0) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
382
|
+
Script,
|
|
383
|
+
{
|
|
384
|
+
strategy: "beforeInteractive",
|
|
385
|
+
key: "init:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
386
|
+
id: "init:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
387
|
+
dangerouslySetInnerHTML: {
|
|
388
|
+
__html: `
|
|
389
|
+
if (!globalThis.__PlasmicBundlePromises) {
|
|
390
|
+
globalThis.__PlasmicBundlePromises = {};
|
|
391
|
+
}
|
|
392
|
+
${missingModulesData.map(
|
|
393
|
+
(module) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(
|
|
394
|
+
module.fileName
|
|
395
|
+
)}]) {
|
|
396
|
+
globalThis.__PlasmicBundlePromises[${JSON.stringify(
|
|
397
|
+
module.fileName
|
|
398
|
+
)}] = new Promise((resolve) => {
|
|
399
|
+
globalThis.__PlasmicBundlePromises[${JSON.stringify(
|
|
400
|
+
"__promise_resolve_" + module.fileName
|
|
401
|
+
)}] = resolve;
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
`
|
|
405
|
+
).join("\n")}`.trim()
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
), missingModulesData.length > 0 && /* @__PURE__ */ React.createElement(
|
|
409
|
+
Script,
|
|
410
|
+
{
|
|
411
|
+
strategy: "beforeInteractive",
|
|
412
|
+
key: "load:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
413
|
+
id: "load:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
414
|
+
defer: true,
|
|
415
|
+
async: true,
|
|
416
|
+
src: loader.getChunksUrl(prefetchedData.bundle, missingModulesData)
|
|
417
|
+
}
|
|
418
|
+
));
|
|
342
419
|
}
|
|
343
420
|
export {
|
|
344
421
|
DataCtxReader,
|
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"],
|
|
4
|
-
"sourcesContent": ["import {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\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 * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nexport {\n DataCtxReader,\n DataProvider,\n extractPlasmicQueryData,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\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(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\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<React.ComponentProps<typeof CommonPlasmicRootProvider>, \"Head\">\n) {\n return (\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\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 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 fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${[...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")}${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 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 alwaysFresh: !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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,OAClB;
|
|
4
|
+
"sourcesContent": ["import {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\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 type { CodeModule } from \"@plasmicapp/loader-core\";\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 type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\nexport {\n DataCtxReader,\n DataProvider,\n extractPlasmicQueryData,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleUrlQuery) {\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 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 __unstable_maybeFetchComponentMetadata: PlasmicComponentLoader[\"maybeFetchComponentData\"] =\n async (...specs) => {\n const data = await this.maybeFetchComponentData(...specs);\n if (data) {\n filterCodeFromRenderData(data);\n }\n return data;\n };\n\n __unstable_fetchComponentMetadata: PlasmicComponentLoader[\"fetchComponentData\"] =\n async (...specs) => {\n const data = await this.fetchComponentData(...specs);\n filterCodeFromRenderData(data);\n return data;\n };\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\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 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 {missingModulesData.length > 0 && (\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}\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 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 fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${[...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")}${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 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 alwaysFresh: !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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,OAClB;AAYP,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,YAAY,gBAAgB;AAC5B,OAAO,YAAY;AACnB,YAAY,WAAW;;;ACjBvB,OAAO,UAAU;;;ACDjB,IAAI;AACJ,IAAI;AAGF,kBAAgB,KAAK,SAAS;AAChC,SAAS,KAAP;AACA,MAAI;AAEF,oBAAgB,KAAK,4BAA4B;AAAA,EACnD,SAASA,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,kBAAkB;AAAA;AACtC,WAAO,cAAyB,IAAI;AAAA,EACtC;AAAA;;;ADpBA,IAAM,YAAN,MAAgB;AAAA,EACd,YAAoB,UAAkB;AAAlB;AAAA,EAAmB;AAAA,EAEjC,MAAM;AAAA;AACV,YAAM,KAAK,MAAM,gBAAgB;AACjC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B,WAAW,GAAG;AAC1D,WAAO;AAAA,EACT;AACA,SACE,0DACE;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,yBAAyB;AAAA,QACvB,QAAQ;AAAA;AAAA;AAAA;AAAA,cAIJ,mBACC;AAAA,UACC,CACE,WACG,2CAA2C,KAAK;AAAA,YACnD,OAAO;AAAA,UACT;AAAA,uDACuC,KAAK;AAAA,YACxC,OAAO;AAAA,UACT;AAAA,yDACuC,KAAK;AAAA,YACxC,uBAAuB,OAAO;AAAA,UAChC;AAAA;AAAA;AAAA;AAAA,QAIN,EACC,KAAK,IAAI,IAAI,KAAK;AAAA,MACzB;AAAA;AAAA,EACD,GACA,mBAAmB,SAAS,KAC3B;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,CAEJ;AAEJ;",
|
|
6
6
|
"names": ["err", "err", "opts", "PlasmicNextLink"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -104,6 +104,7 @@ var import_loader_react = require("@plasmicapp/loader-react");
|
|
|
104
104
|
var import_head = __toESM(require("next/head.js"));
|
|
105
105
|
var import_link = __toESM(require("next/link.js"));
|
|
106
106
|
var NextRouter = __toESM(require("next/router.js"));
|
|
107
|
+
var import_script = __toESM(require("next/script"));
|
|
107
108
|
var React = __toESM(require("react"));
|
|
108
109
|
|
|
109
110
|
// src/cache.ts
|
|
@@ -259,9 +260,39 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
259
260
|
|
|
260
261
|
// src/index.tsx
|
|
261
262
|
var import_loader_react2 = require("@plasmicapp/loader-react");
|
|
263
|
+
var reactMajorVersion = +React.version.split(".")[0];
|
|
264
|
+
function filterCodeFromRenderData(data) {
|
|
265
|
+
if (reactMajorVersion >= 18 && !!data.bundle.bundleUrlQuery) {
|
|
266
|
+
const entrypoints = /* @__PURE__ */ new Set([
|
|
267
|
+
...data.entryCompMetas.map((compMeta) => compMeta.entry),
|
|
268
|
+
"root-provider.js",
|
|
269
|
+
...data.bundle.projects.map((x) => x.globalContextsProviderFileName).filter((x) => !!x),
|
|
270
|
+
...data.bundle.components.filter((c) => c.isGlobalContextProvider).map((c) => c.entry),
|
|
271
|
+
...data.bundle.globalGroups.map((g) => g.contextFile)
|
|
272
|
+
]);
|
|
273
|
+
data.bundle.modules.browser = data.bundle.modules.browser.map((module2) => {
|
|
274
|
+
if (module2.type !== "code" || entrypoints.has(module2.fileName)) {
|
|
275
|
+
return module2;
|
|
276
|
+
}
|
|
277
|
+
return __spreadProps(__spreadValues({}, module2), { code: "" });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
262
281
|
var NextJsPlasmicComponentLoader = class extends import_loader_react.PlasmicComponentLoader {
|
|
263
282
|
constructor(internal) {
|
|
264
283
|
super(internal);
|
|
284
|
+
this.__unstable_maybeFetchComponentMetadata = (...specs) => __async(this, null, function* () {
|
|
285
|
+
const data = yield this.maybeFetchComponentData(...specs);
|
|
286
|
+
if (data) {
|
|
287
|
+
filterCodeFromRenderData(data);
|
|
288
|
+
}
|
|
289
|
+
return data;
|
|
290
|
+
});
|
|
291
|
+
this.__unstable_fetchComponentMetadata = (...specs) => __async(this, null, function* () {
|
|
292
|
+
const data = yield this.fetchComponentData(...specs);
|
|
293
|
+
filterCodeFromRenderData(data);
|
|
294
|
+
return data;
|
|
295
|
+
});
|
|
265
296
|
}
|
|
266
297
|
getActiveVariation(opts) {
|
|
267
298
|
return __async(this, null, function* () {
|
|
@@ -360,12 +391,58 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
360
391
|
}
|
|
361
392
|
});
|
|
362
393
|
function PlasmicRootProvider(props) {
|
|
363
|
-
return /* @__PURE__ */ React.createElement(
|
|
394
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, !props.skipChunks && renderDynamicPayloadScripts(props.loader, props.prefetchedData), /* @__PURE__ */ React.createElement(
|
|
364
395
|
import_loader_react.PlasmicRootProvider,
|
|
365
396
|
__spreadValues({
|
|
366
397
|
Head: import_head.default,
|
|
367
398
|
Link: PlasmicNextLink
|
|
368
399
|
}, props)
|
|
400
|
+
));
|
|
401
|
+
}
|
|
402
|
+
function renderDynamicPayloadScripts(loader, prefetchedData) {
|
|
403
|
+
const missingModulesData = prefetchedData && prefetchedData.bundle.modules.browser.filter(
|
|
404
|
+
(module2) => module2.type === "code" && !module2.code
|
|
369
405
|
);
|
|
406
|
+
if (!missingModulesData || missingModulesData.length === 0) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
410
|
+
import_script.default,
|
|
411
|
+
{
|
|
412
|
+
strategy: "beforeInteractive",
|
|
413
|
+
key: "init:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
414
|
+
id: "init:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
415
|
+
dangerouslySetInnerHTML: {
|
|
416
|
+
__html: `
|
|
417
|
+
if (!globalThis.__PlasmicBundlePromises) {
|
|
418
|
+
globalThis.__PlasmicBundlePromises = {};
|
|
419
|
+
}
|
|
420
|
+
${missingModulesData.map(
|
|
421
|
+
(module2) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(
|
|
422
|
+
module2.fileName
|
|
423
|
+
)}]) {
|
|
424
|
+
globalThis.__PlasmicBundlePromises[${JSON.stringify(
|
|
425
|
+
module2.fileName
|
|
426
|
+
)}] = new Promise((resolve) => {
|
|
427
|
+
globalThis.__PlasmicBundlePromises[${JSON.stringify(
|
|
428
|
+
"__promise_resolve_" + module2.fileName
|
|
429
|
+
)}] = resolve;
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
`
|
|
433
|
+
).join("\n")}`.trim()
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
), missingModulesData.length > 0 && /* @__PURE__ */ React.createElement(
|
|
437
|
+
import_script.default,
|
|
438
|
+
{
|
|
439
|
+
strategy: "beforeInteractive",
|
|
440
|
+
key: "load:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
441
|
+
id: "load:" + missingModulesData.map((m) => m.fileName).join(";"),
|
|
442
|
+
defer: true,
|
|
443
|
+
async: true,
|
|
444
|
+
src: loader.getChunksUrl(prefetchedData.bundle, missingModulesData)
|
|
445
|
+
}
|
|
446
|
+
));
|
|
370
447
|
}
|
|
371
448
|
//# sourceMappingURL=index.js.map
|
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"],
|
|
4
|
-
"sourcesContent": ["import {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\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 * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nexport {\n DataCtxReader,\n DataProvider,\n extractPlasmicQueryData,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\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(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\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<React.ComponentProps<typeof CommonPlasmicRootProvider>, \"Head\">\n) {\n return (\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\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 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 fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${[...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")}${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 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 alwaysFresh: !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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\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,0BAIO;
|
|
6
|
-
"names": ["err", "module", "path", "err", "import_loader_react", "opts", "NextHead", "NextLink", "PlasmicNextLink", "CommonPlasmicRootProvider"]
|
|
4
|
+
"sourcesContent": ["import {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\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 type { CodeModule } from \"@plasmicapp/loader-core\";\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 type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\nexport {\n DataCtxReader,\n DataProvider,\n extractPlasmicQueryData,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleUrlQuery) {\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 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 __unstable_maybeFetchComponentMetadata: PlasmicComponentLoader[\"maybeFetchComponentData\"] =\n async (...specs) => {\n const data = await this.maybeFetchComponentData(...specs);\n if (data) {\n filterCodeFromRenderData(data);\n }\n return data;\n };\n\n __unstable_fetchComponentMetadata: PlasmicComponentLoader[\"fetchComponentData\"] =\n async (...specs) => {\n const data = await this.fetchComponentData(...specs);\n filterCodeFromRenderData(data);\n return data;\n };\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\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 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 {missingModulesData.length > 0 && (\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}\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 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 fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${[...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")}${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 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 alwaysFresh: !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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\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,0BAIO;AAYP,kBAAqB;AACrB,kBAAqB;AACrB,iBAA4B;AAC5B,oBAAmB;AACnB,YAAuB;;;ACjBvB,kBAAiB;;;ACDjB,IAAI;AACJ,IAAI;AAGF,kBAAgB,KAAK,SAAS;AA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AA,MAChE,OAAK;AAAA,MACL,OAAK;AAAA,MACL,KAAK,OAAO,aAAa,eAAe,QAAQ,kBAAkB;AAAA;AAAA,EACpE,CAEJ;AAEJ;",
|
|
6
|
+
"names": ["err", "module", "path", "err", "import_loader_react", "module", "opts", "NextHead", "NextLink", "PlasmicNextLink", "CommonPlasmicRootProvider", "Script"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.350",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
@@ -80,11 +80,11 @@
|
|
|
80
80
|
"next": "^13.2.0"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@plasmicapp/loader-core": "1.0.
|
|
84
|
-
"@plasmicapp/loader-edge": "1.0.
|
|
85
|
-
"@plasmicapp/loader-react": "1.0.
|
|
83
|
+
"@plasmicapp/loader-core": "1.0.123",
|
|
84
|
+
"@plasmicapp/loader-edge": "1.0.56",
|
|
85
|
+
"@plasmicapp/loader-react": "1.0.329",
|
|
86
86
|
"@plasmicapp/watcher": "1.0.82",
|
|
87
87
|
"server-only": "0.0.1"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "c8e66753e8f375487f4dc60f29897496fe889e51"
|
|
90
90
|
}
|