@plasmicapp/loader-nextjs 1.0.265 → 1.0.266
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/cache.d.ts +4 -4
- package/dist/index-react-server.d.ts +4 -0
- package/dist/index-shared.d.ts +2 -0
- package/dist/index.d.ts +22 -23
- package/dist/index.js +5 -287
- package/dist/loader-nextjs.cjs.development.js +1061 -0
- package/dist/loader-nextjs.cjs.development.js.map +1 -0
- package/dist/loader-nextjs.cjs.production.min.js +2 -0
- package/dist/loader-nextjs.cjs.production.min.js.map +1 -0
- package/dist/loader-nextjs.esm.js +967 -0
- package/dist/loader-nextjs.esm.js.map +1 -0
- package/dist/server-require.d.ts +4 -4
- package/dist-react-server/cache.d.ts +4 -0
- package/{dist/react-server.d.ts → dist-react-server/index-react-server.d.ts} +4 -4
- package/{dist/shared-exports.d.ts → dist-react-server/index-shared.d.ts} +2 -2
- package/dist-react-server/index.d.ts +22 -0
- package/dist-react-server/index.js +8 -0
- package/dist-react-server/loader-nextjs.cjs.development.js +878 -0
- package/dist-react-server/loader-nextjs.cjs.development.js.map +1 -0
- package/dist-react-server/loader-nextjs.cjs.production.min.js +2 -0
- package/dist-react-server/loader-nextjs.cjs.production.min.js.map +1 -0
- package/dist-react-server/loader-nextjs.esm.js +875 -0
- package/dist-react-server/loader-nextjs.esm.js.map +1 -0
- package/dist-react-server/server-require.d.ts +4 -0
- package/package.json +51 -21
- package/react-server-conditional.d.ts +2 -4
- package/react-server.d.ts +1 -1
- package/dist/index.js.map +0 -7
- package/dist/react-server.js +0 -212
- package/dist/react-server.js.map +0 -7
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InitOptions } from '@plasmicapp/loader-react/react-server-conditional';
|
|
2
|
-
export declare function initPlasmicLoaderWithCache<T extends {
|
|
3
|
-
clearCache(): void;
|
|
4
|
-
}>(initFn: (opts: InitOptions) => T, opts: InitOptions): T;
|
|
1
|
+
import type { InitOptions } from '@plasmicapp/loader-react/react-server-conditional';
|
|
2
|
+
export declare function initPlasmicLoaderWithCache<T extends {
|
|
3
|
+
clearCache(): void;
|
|
4
|
+
}>(initFn: (opts: InitOptions) => T, opts: InitOptions): T;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { InitOptions, InternalPlasmicComponentLoader, PlasmicComponentLoader, PlasmicRootProvider as CommonPlasmicRootProvider } from '@plasmicapp/loader-react';
|
|
3
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
export { DataCtxReader, DataProvider, extractPlasmicQueryData, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, PlasmicComponent, plasmicPrepass, repeatedElement, useDataEnv, usePlasmicCanvasContext, usePlasmicComponent, usePlasmicQueryData, useSelector, useSelectors, } from '@plasmicapp/loader-react';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function PlasmicRootProvider(props: Omit<React.ComponentProps<typeof CommonPlasmicRootProvider>, 'Head'>): JSX.Element;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { InitOptions, InternalPlasmicComponentLoader, PlasmicComponentLoader, PlasmicRootProvider as CommonPlasmicRootProvider } from '@plasmicapp/loader-react';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
export { CodeComponentMeta, DataCtxReader, DataProvider, extractPlasmicQueryData, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, PlasmicComponent, plasmicPrepass, PlasmicTranslator, PrimitiveType, PropType, repeatedElement, TokenRegistration, useDataEnv, usePlasmicCanvasContext, usePlasmicComponent, usePlasmicQueryData, useSelector, useSelectors, } from '@plasmicapp/loader-react';
|
|
6
|
+
export * from './index-shared';
|
|
7
|
+
declare type ServerRequest = IncomingMessage & {
|
|
8
|
+
cookies: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {
|
|
13
|
+
constructor(internal: InternalPlasmicComponentLoader);
|
|
14
|
+
getActiveVariation(opts: {
|
|
15
|
+
req?: ServerRequest;
|
|
16
|
+
res?: ServerResponse;
|
|
17
|
+
known?: Record<string, string>;
|
|
18
|
+
traits: Record<string, string | number | boolean>;
|
|
19
|
+
}): Promise<Record<string, string>>;
|
|
20
|
+
}
|
|
21
|
+
export declare function initPlasmicLoader(opts: InitOptions): NextJsPlasmicComponentLoader;
|
|
22
|
+
export declare function PlasmicRootProvider(props: Omit<React.ComponentProps<typeof CommonPlasmicRootProvider>, 'Head'>): JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -1,290 +1,8 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defProps = Object.defineProperties;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __export = (target, all) => {
|
|
27
|
-
for (var name in all)
|
|
28
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
-
};
|
|
30
|
-
var __copyProps = (to, from, except, desc) => {
|
|
31
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
-
for (let key of __getOwnPropNames(from))
|
|
33
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
-
}
|
|
36
|
-
return to;
|
|
37
|
-
};
|
|
38
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
39
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
40
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
41
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
42
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
43
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
44
|
-
mod
|
|
45
|
-
));
|
|
46
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
47
|
-
var __async = (__this, __arguments, generator) => {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
var fulfilled = (value) => {
|
|
50
|
-
try {
|
|
51
|
-
step(generator.next(value));
|
|
52
|
-
} catch (e) {
|
|
53
|
-
reject(e);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var rejected = (value) => {
|
|
57
|
-
try {
|
|
58
|
-
step(generator.throw(value));
|
|
59
|
-
} catch (e) {
|
|
60
|
-
reject(e);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
64
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
1
|
|
|
68
|
-
|
|
69
|
-
var src_exports = {};
|
|
70
|
-
__export(src_exports, {
|
|
71
|
-
DataCtxReader: () => import_loader_react2.DataCtxReader,
|
|
72
|
-
DataProvider: () => import_loader_react2.DataProvider,
|
|
73
|
-
NextJsPlasmicComponentLoader: () => NextJsPlasmicComponentLoader,
|
|
74
|
-
PageParamsProvider: () => import_loader_react2.PageParamsProvider,
|
|
75
|
-
PlasmicCanvasContext: () => import_loader_react2.PlasmicCanvasContext,
|
|
76
|
-
PlasmicCanvasHost: () => import_loader_react2.PlasmicCanvasHost,
|
|
77
|
-
PlasmicComponent: () => import_loader_react2.PlasmicComponent,
|
|
78
|
-
PlasmicRootProvider: () => PlasmicRootProvider,
|
|
79
|
-
extractPlasmicQueryData: () => import_loader_react2.extractPlasmicQueryData,
|
|
80
|
-
initPlasmicLoader: () => initPlasmicLoader,
|
|
81
|
-
plasmicPrepass: () => import_loader_react2.plasmicPrepass,
|
|
82
|
-
repeatedElement: () => import_loader_react2.repeatedElement,
|
|
83
|
-
useDataEnv: () => import_loader_react2.useDataEnv,
|
|
84
|
-
usePlasmicCanvasContext: () => import_loader_react2.usePlasmicCanvasContext,
|
|
85
|
-
usePlasmicComponent: () => import_loader_react2.usePlasmicComponent,
|
|
86
|
-
usePlasmicQueryData: () => import_loader_react2.usePlasmicQueryData,
|
|
87
|
-
useSelector: () => import_loader_react2.useSelector,
|
|
88
|
-
useSelectors: () => import_loader_react2.useSelectors
|
|
89
|
-
});
|
|
90
|
-
module.exports = __toCommonJS(src_exports);
|
|
91
|
-
var import_loader_react = require("@plasmicapp/loader-react");
|
|
92
|
-
var import_head = __toESM(require("next/head.js"));
|
|
93
|
-
var import_link = __toESM(require("next/link.js"));
|
|
94
|
-
var NextRouter = __toESM(require("next/router.js"));
|
|
95
|
-
var React = __toESM(require("react"));
|
|
2
|
+
'use strict'
|
|
96
3
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var secretRequire;
|
|
102
|
-
try {
|
|
103
|
-
secretRequire = eval("require");
|
|
104
|
-
} catch (err) {
|
|
105
|
-
secretRequire = void 0;
|
|
106
|
-
}
|
|
107
|
-
function serverRequire(module2) {
|
|
108
|
-
if (!secretRequire) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Unexpected serverRequire() -- can only do this from a Node server!`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return secretRequire(module2);
|
|
114
|
-
}
|
|
115
|
-
function serverRequireFs() {
|
|
116
|
-
return serverRequire("fs");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/cache.ts
|
|
120
|
-
var FileCache = class {
|
|
121
|
-
constructor(filePath) {
|
|
122
|
-
this.filePath = filePath;
|
|
123
|
-
}
|
|
124
|
-
get() {
|
|
125
|
-
return __async(this, null, function* () {
|
|
126
|
-
const fs = serverRequireFs();
|
|
127
|
-
try {
|
|
128
|
-
yield fs.promises.mkdir(import_path.default.dirname(this.filePath), { recursive: true });
|
|
129
|
-
const data = (yield fs.promises.readFile(this.filePath)).toString();
|
|
130
|
-
return JSON.parse(data);
|
|
131
|
-
} catch (e) {
|
|
132
|
-
return void 0;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
set(data) {
|
|
137
|
-
return __async(this, null, function* () {
|
|
138
|
-
const fs = serverRequireFs();
|
|
139
|
-
try {
|
|
140
|
-
yield fs.promises.writeFile(this.filePath, JSON.stringify(data));
|
|
141
|
-
} catch (err) {
|
|
142
|
-
console.warn(`Error writing to Plasmic cache: ${err}`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
clear() {
|
|
147
|
-
const fs = serverRequireFs();
|
|
148
|
-
try {
|
|
149
|
-
fs.unlinkSync(this.filePath);
|
|
150
|
-
} catch (err) {
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
function makeCache(opts) {
|
|
155
|
-
const cacheDir = import_path.default.resolve(process.cwd(), ".next", ".plasmic");
|
|
156
|
-
const cachePath = import_path.default.join(
|
|
157
|
-
cacheDir,
|
|
158
|
-
`plasmic-${[...opts.projects.map((p) => {
|
|
159
|
-
var _a;
|
|
160
|
-
return `${p.id}@${(_a = p.version) != null ? _a : ""}`;
|
|
161
|
-
})].sort().join("-")}${opts.preview ? "-preview" : ""}-cache.json`
|
|
162
|
-
);
|
|
163
|
-
return new FileCache(cachePath);
|
|
164
|
-
}
|
|
165
|
-
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
166
|
-
const isBrowser = typeof window !== "undefined";
|
|
167
|
-
const isProd = false;
|
|
168
|
-
const cache = isBrowser || isProd ? void 0 : makeCache(opts);
|
|
169
|
-
const loader = initFn(__spreadProps(__spreadValues({
|
|
170
|
-
onClientSideFetch: "warn"
|
|
171
|
-
}, opts), {
|
|
172
|
-
cache,
|
|
173
|
-
platform: "nextjs",
|
|
174
|
-
// For Nextjs 12, revalidate may in fact re-use an existing instance
|
|
175
|
-
// of PlasmicComponentLoader that's already in memory, so we need to
|
|
176
|
-
// make sure we don't re-use the data cached in memory.
|
|
177
|
-
// We also enforce this for dev mode, so that we don't have to restart
|
|
178
|
-
// the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader
|
|
179
|
-
alwaysFresh: !isBrowser
|
|
180
|
-
}));
|
|
181
|
-
if (!isProd) {
|
|
182
|
-
const stringOpts = JSON.stringify(opts);
|
|
183
|
-
if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {
|
|
184
|
-
console.warn(
|
|
185
|
-
`PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.
|
|
186
|
-
`
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
process.env.PLASMIC_OPTS = stringOpts;
|
|
190
|
-
}
|
|
191
|
-
if (cache) {
|
|
192
|
-
if (!isProd) {
|
|
193
|
-
if (process.env.PLASMIC_WATCHED !== "true") {
|
|
194
|
-
process.env.PLASMIC_WATCHED = "true";
|
|
195
|
-
console.log(`Subscribing to Plasmic changes...`);
|
|
196
|
-
const PlasmicRemoteChangeWatcher = serverRequire("@plasmicapp/watcher").PlasmicRemoteChangeWatcher;
|
|
197
|
-
const watcher = new PlasmicRemoteChangeWatcher({
|
|
198
|
-
projects: opts.projects,
|
|
199
|
-
host: opts.host
|
|
200
|
-
});
|
|
201
|
-
const clearCache = () => {
|
|
202
|
-
cache.clear();
|
|
203
|
-
loader.clearCache();
|
|
204
|
-
};
|
|
205
|
-
watcher.subscribe({
|
|
206
|
-
onUpdate: () => {
|
|
207
|
-
if (opts.preview) {
|
|
208
|
-
clearCache();
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
onPublish: () => {
|
|
212
|
-
if (!opts.preview) {
|
|
213
|
-
clearCache();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
cache.clear();
|
|
220
|
-
loader.clearCache();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return loader;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// src/index.tsx
|
|
227
|
-
var import_loader_react2 = require("@plasmicapp/loader-react");
|
|
228
|
-
var NextJsPlasmicComponentLoader = class extends import_loader_react.PlasmicComponentLoader {
|
|
229
|
-
constructor(internal) {
|
|
230
|
-
super(internal);
|
|
231
|
-
this.registerModules({
|
|
232
|
-
"next/head": import_head.default,
|
|
233
|
-
"next/link": import_link.default,
|
|
234
|
-
"next/router": NextRouter
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
getActiveVariation(opts) {
|
|
238
|
-
return __async(this, null, function* () {
|
|
239
|
-
const extractBuiltinTraits = () => {
|
|
240
|
-
var _a, _b, _c, _d;
|
|
241
|
-
const url = new URL(
|
|
242
|
-
(_b = (_a = opts.req) == null ? void 0 : _a.url) != null ? _b : "/",
|
|
243
|
-
`https://${(_d = (_c = opts.req) == null ? void 0 : _c.headers.host) != null ? _d : "server.side"}`
|
|
244
|
-
);
|
|
245
|
-
return {
|
|
246
|
-
pageUrl: url.href
|
|
247
|
-
};
|
|
248
|
-
};
|
|
249
|
-
return this._getActiveVariation({
|
|
250
|
-
traits: __spreadValues(__spreadValues({}, extractBuiltinTraits()), opts.traits),
|
|
251
|
-
getKnownValue: (key) => {
|
|
252
|
-
var _a, _b;
|
|
253
|
-
if (opts.known) {
|
|
254
|
-
return opts.known[key];
|
|
255
|
-
} else {
|
|
256
|
-
return (_b = (_a = opts.req) == null ? void 0 : _a.cookies[`plasmic:${key}`]) != null ? _b : void 0;
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
updateKnownValue: (key, value) => {
|
|
260
|
-
var _a, _b, _c;
|
|
261
|
-
if (opts.res) {
|
|
262
|
-
const cookie = `plasmic:${key}=${value}`;
|
|
263
|
-
const resCookie = (_b = (_a = opts.res) == null ? void 0 : _a.getHeader("Set-Cookie")) != null ? _b : [];
|
|
264
|
-
let newCookies = [];
|
|
265
|
-
if (Array.isArray(resCookie)) {
|
|
266
|
-
newCookies = [...resCookie, `plasmic:${key}=${value}`];
|
|
267
|
-
} else {
|
|
268
|
-
newCookies = [`${resCookie}`, cookie];
|
|
269
|
-
}
|
|
270
|
-
(_c = opts.res) == null ? void 0 : _c.setHeader("Set-Cookie", newCookies);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
var initPlasmicLoaderNext = (opts) => {
|
|
278
|
-
const internal = new import_loader_react.InternalPlasmicComponentLoader(opts);
|
|
279
|
-
return new NextJsPlasmicComponentLoader(internal);
|
|
280
|
-
};
|
|
281
|
-
function initPlasmicLoader(opts) {
|
|
282
|
-
return initPlasmicLoaderWithCache(
|
|
283
|
-
initPlasmicLoaderNext,
|
|
284
|
-
opts
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
function PlasmicRootProvider(props) {
|
|
288
|
-
return /* @__PURE__ */ React.createElement(import_loader_react.PlasmicRootProvider, __spreadValues({ Head: import_head.default }, props));
|
|
4
|
+
if (process.env.NODE_ENV === 'production') {
|
|
5
|
+
module.exports = require('./loader-nextjs.cjs.production.min.js')
|
|
6
|
+
} else {
|
|
7
|
+
module.exports = require('./loader-nextjs.cjs.development.js')
|
|
289
8
|
}
|
|
290
|
-
//# sourceMappingURL=index.js.map
|