@plasmicapp/loader-react 1.0.253 → 1.0.254

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/PlasmicComponent.d.ts +19 -19
  2. package/dist/PlasmicRootProvider.d.ts +92 -92
  3. package/dist/bundles.d.ts +7 -7
  4. package/dist/component-lookup.d.ts +21 -21
  5. package/dist/global-variants.d.ts +13 -13
  6. package/dist/index.d.ts +15 -12
  7. package/dist/index.js +1464 -5
  8. package/dist/index.js.map +7 -0
  9. package/dist/loader-react-server.d.ts +72 -72
  10. package/dist/loader.d.ts +173 -173
  11. package/dist/prepass.d.ts +43 -43
  12. package/dist/react-server.d.ts +5 -0
  13. package/dist/react-server.js +473 -0
  14. package/dist/react-server.js.map +7 -0
  15. package/dist/render.d.ts +27 -27
  16. package/dist/shared-exports.d.ts +6 -0
  17. package/dist/usePlasmicComponent.d.ts +15 -15
  18. package/dist/utils.d.ts +30 -30
  19. package/dist/variation.d.ts +9 -9
  20. package/package.json +21 -53
  21. package/dist/index-react-server.d.ts +0 -5
  22. package/dist/index-shared.d.ts +0 -6
  23. package/dist/loader-react.cjs.development.js +0 -2748
  24. package/dist/loader-react.cjs.development.js.map +0 -1
  25. package/dist/loader-react.cjs.production.min.js +0 -2
  26. package/dist/loader-react.cjs.production.min.js.map +0 -1
  27. package/dist/loader-react.esm.js +0 -2666
  28. package/dist/loader-react.esm.js.map +0 -1
  29. package/dist-react-server/PlasmicComponent.d.ts +0 -19
  30. package/dist-react-server/PlasmicRootProvider.d.ts +0 -92
  31. package/dist-react-server/bundles.d.ts +0 -7
  32. package/dist-react-server/component-lookup.d.ts +0 -21
  33. package/dist-react-server/global-variants.d.ts +0 -13
  34. package/dist-react-server/index-react-server.d.ts +0 -5
  35. package/dist-react-server/index-shared.d.ts +0 -6
  36. package/dist-react-server/index.d.ts +0 -12
  37. package/dist-react-server/index.js +0 -8
  38. package/dist-react-server/loader-react-server.d.ts +0 -72
  39. package/dist-react-server/loader-react.cjs.development.js +0 -1315
  40. package/dist-react-server/loader-react.cjs.development.js.map +0 -1
  41. package/dist-react-server/loader-react.cjs.production.min.js +0 -2
  42. package/dist-react-server/loader-react.cjs.production.min.js.map +0 -1
  43. package/dist-react-server/loader-react.esm.js +0 -1306
  44. package/dist-react-server/loader-react.esm.js.map +0 -1
  45. package/dist-react-server/loader.d.ts +0 -173
  46. package/dist-react-server/prepass.d.ts +0 -43
  47. package/dist-react-server/render.d.ts +0 -27
  48. package/dist-react-server/usePlasmicComponent.d.ts +0 -15
  49. package/dist-react-server/utils.d.ts +0 -30
  50. package/dist-react-server/variation.d.ts +0 -9
@@ -1,2666 +0,0 @@
1
- 'use client';import * as PlasmicDataSourcesContext from '@plasmicapp/data-sources-context';
2
- import * as PlasmicHost from '@plasmicapp/host';
3
- import { PageParamsProvider, registerComponent, registerGlobalContext, registerTrait, registerToken } from '@plasmicapp/host';
4
- export { DataCtxReader, DataProvider, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, repeatedElement, useDataEnv, usePlasmicCanvasContext, useSelector, useSelectors } from '@plasmicapp/host';
5
- import { getBundleSubset, Registry, PlasmicTracker, PlasmicModulesFetcher } from '@plasmicapp/loader-core';
6
- import { internal_getCachedBundleInNodeServer } from '@plasmicapp/loader-fetcher';
7
- import { getExternalIds, getActiveVariation } from '@plasmicapp/loader-splits';
8
- import * as PlasmicQuery from '@plasmicapp/query';
9
- import { PlasmicQueryDataProvider, PlasmicPrepassContext } from '@plasmicapp/query';
10
- export { usePlasmicQueryData } from '@plasmicapp/query';
11
- import React__default, { useState, useCallback, useEffect, useRef, useMemo, createElement, memo, useContext, createContext } from 'react';
12
- import ReactDOM from 'react-dom';
13
- import * as jsxDevRuntime from 'react/jsx-dev-runtime';
14
- import * as jsxRuntime from 'react/jsx-runtime';
15
- import pascalcase from 'pascalcase';
16
- import prepass from '@plasmicapp/react-ssr-prepass';
17
- import { isFragment } from 'react-is';
18
- import { renderToString as renderToString$1 } from 'react-dom/server';
19
-
20
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
21
- try {
22
- var info = gen[key](arg);
23
- var value = info.value;
24
- } catch (error) {
25
- reject(error);
26
- return;
27
- }
28
- if (info.done) {
29
- resolve(value);
30
- } else {
31
- Promise.resolve(value).then(_next, _throw);
32
- }
33
- }
34
- function _asyncToGenerator(fn) {
35
- return function () {
36
- var self = this,
37
- args = arguments;
38
- return new Promise(function (resolve, reject) {
39
- var gen = fn.apply(self, args);
40
- function _next(value) {
41
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
42
- }
43
- function _throw(err) {
44
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
45
- }
46
- _next(undefined);
47
- });
48
- };
49
- }
50
- function _extends() {
51
- _extends = Object.assign ? Object.assign.bind() : function (target) {
52
- for (var i = 1; i < arguments.length; i++) {
53
- var source = arguments[i];
54
- for (var key in source) {
55
- if (Object.prototype.hasOwnProperty.call(source, key)) {
56
- target[key] = source[key];
57
- }
58
- }
59
- }
60
- return target;
61
- };
62
- return _extends.apply(this, arguments);
63
- }
64
- function _inheritsLoose(subClass, superClass) {
65
- subClass.prototype = Object.create(superClass.prototype);
66
- subClass.prototype.constructor = subClass;
67
- _setPrototypeOf(subClass, superClass);
68
- }
69
- function _setPrototypeOf(o, p) {
70
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
71
- o.__proto__ = p;
72
- return o;
73
- };
74
- return _setPrototypeOf(o, p);
75
- }
76
- function _objectWithoutPropertiesLoose(source, excluded) {
77
- if (source == null) return {};
78
- var target = {};
79
- var sourceKeys = Object.keys(source);
80
- var key, i;
81
- for (i = 0; i < sourceKeys.length; i++) {
82
- key = sourceKeys[i];
83
- if (excluded.indexOf(key) >= 0) continue;
84
- target[key] = source[key];
85
- }
86
- return target;
87
- }
88
- function _unsupportedIterableToArray(o, minLen) {
89
- if (!o) return;
90
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
91
- var n = Object.prototype.toString.call(o).slice(8, -1);
92
- if (n === "Object" && o.constructor) n = o.constructor.name;
93
- if (n === "Map" || n === "Set") return Array.from(o);
94
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
95
- }
96
- function _arrayLikeToArray(arr, len) {
97
- if (len == null || len > arr.length) len = arr.length;
98
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
99
- return arr2;
100
- }
101
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
102
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
103
- if (it) return (it = it.call(o)).next.bind(it);
104
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
105
- if (it) o = it;
106
- var i = 0;
107
- return function () {
108
- if (i >= o.length) return {
109
- done: true
110
- };
111
- return {
112
- done: false,
113
- value: o[i++]
114
- };
115
- };
116
- }
117
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
118
- }
119
-
120
- function createCommonjsModule(fn, module) {
121
- return module = { exports: {} }, fn(module, module.exports), module.exports;
122
- }
123
-
124
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
125
- /**
126
- * Copyright (c) 2014-present, Facebook, Inc.
127
- *
128
- * This source code is licensed under the MIT license found in the
129
- * LICENSE file in the root directory of this source tree.
130
- */
131
-
132
- var runtime = function (exports) {
133
-
134
- var Op = Object.prototype;
135
- var hasOwn = Op.hasOwnProperty;
136
- var undefined$1; // More compressible than void 0.
137
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
138
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
139
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
140
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
141
- function define(obj, key, value) {
142
- Object.defineProperty(obj, key, {
143
- value: value,
144
- enumerable: true,
145
- configurable: true,
146
- writable: true
147
- });
148
- return obj[key];
149
- }
150
- try {
151
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
152
- define({}, "");
153
- } catch (err) {
154
- define = function define(obj, key, value) {
155
- return obj[key] = value;
156
- };
157
- }
158
- function wrap(innerFn, outerFn, self, tryLocsList) {
159
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
160
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
161
- var generator = Object.create(protoGenerator.prototype);
162
- var context = new Context(tryLocsList || []);
163
-
164
- // The ._invoke method unifies the implementations of the .next,
165
- // .throw, and .return methods.
166
- generator._invoke = makeInvokeMethod(innerFn, self, context);
167
- return generator;
168
- }
169
- exports.wrap = wrap;
170
-
171
- // Try/catch helper to minimize deoptimizations. Returns a completion
172
- // record like context.tryEntries[i].completion. This interface could
173
- // have been (and was previously) designed to take a closure to be
174
- // invoked without arguments, but in all the cases we care about we
175
- // already have an existing method we want to call, so there's no need
176
- // to create a new function object. We can even get away with assuming
177
- // the method takes exactly one argument, since that happens to be true
178
- // in every case, so we don't have to touch the arguments object. The
179
- // only additional allocation required is the completion record, which
180
- // has a stable shape and so hopefully should be cheap to allocate.
181
- function tryCatch(fn, obj, arg) {
182
- try {
183
- return {
184
- type: "normal",
185
- arg: fn.call(obj, arg)
186
- };
187
- } catch (err) {
188
- return {
189
- type: "throw",
190
- arg: err
191
- };
192
- }
193
- }
194
- var GenStateSuspendedStart = "suspendedStart";
195
- var GenStateSuspendedYield = "suspendedYield";
196
- var GenStateExecuting = "executing";
197
- var GenStateCompleted = "completed";
198
-
199
- // Returning this object from the innerFn has the same effect as
200
- // breaking out of the dispatch switch statement.
201
- var ContinueSentinel = {};
202
-
203
- // Dummy constructor functions that we use as the .constructor and
204
- // .constructor.prototype properties for functions that return Generator
205
- // objects. For full spec compliance, you may wish to configure your
206
- // minifier not to mangle the names of these two functions.
207
- function Generator() {}
208
- function GeneratorFunction() {}
209
- function GeneratorFunctionPrototype() {}
210
-
211
- // This is a polyfill for %IteratorPrototype% for environments that
212
- // don't natively support it.
213
- var IteratorPrototype = {};
214
- define(IteratorPrototype, iteratorSymbol, function () {
215
- return this;
216
- });
217
- var getProto = Object.getPrototypeOf;
218
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
219
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
220
- // This environment has a native %IteratorPrototype%; use it instead
221
- // of the polyfill.
222
- IteratorPrototype = NativeIteratorPrototype;
223
- }
224
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
225
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
226
- define(Gp, "constructor", GeneratorFunctionPrototype);
227
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
228
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
229
-
230
- // Helper for defining the .next, .throw, and .return methods of the
231
- // Iterator interface in terms of a single ._invoke method.
232
- function defineIteratorMethods(prototype) {
233
- ["next", "throw", "return"].forEach(function (method) {
234
- define(prototype, method, function (arg) {
235
- return this._invoke(method, arg);
236
- });
237
- });
238
- }
239
- exports.isGeneratorFunction = function (genFun) {
240
- var ctor = typeof genFun === "function" && genFun.constructor;
241
- return ctor ? ctor === GeneratorFunction ||
242
- // For the native GeneratorFunction constructor, the best we can
243
- // do is to check its .name property.
244
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
245
- };
246
- exports.mark = function (genFun) {
247
- if (Object.setPrototypeOf) {
248
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
249
- } else {
250
- genFun.__proto__ = GeneratorFunctionPrototype;
251
- define(genFun, toStringTagSymbol, "GeneratorFunction");
252
- }
253
- genFun.prototype = Object.create(Gp);
254
- return genFun;
255
- };
256
-
257
- // Within the body of any async function, `await x` is transformed to
258
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
259
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
260
- // meant to be awaited.
261
- exports.awrap = function (arg) {
262
- return {
263
- __await: arg
264
- };
265
- };
266
- function AsyncIterator(generator, PromiseImpl) {
267
- function invoke(method, arg, resolve, reject) {
268
- var record = tryCatch(generator[method], generator, arg);
269
- if (record.type === "throw") {
270
- reject(record.arg);
271
- } else {
272
- var result = record.arg;
273
- var value = result.value;
274
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
275
- return PromiseImpl.resolve(value.__await).then(function (value) {
276
- invoke("next", value, resolve, reject);
277
- }, function (err) {
278
- invoke("throw", err, resolve, reject);
279
- });
280
- }
281
- return PromiseImpl.resolve(value).then(function (unwrapped) {
282
- // When a yielded Promise is resolved, its final value becomes
283
- // the .value of the Promise<{value,done}> result for the
284
- // current iteration.
285
- result.value = unwrapped;
286
- resolve(result);
287
- }, function (error) {
288
- // If a rejected Promise was yielded, throw the rejection back
289
- // into the async generator function so it can be handled there.
290
- return invoke("throw", error, resolve, reject);
291
- });
292
- }
293
- }
294
- var previousPromise;
295
- function enqueue(method, arg) {
296
- function callInvokeWithMethodAndArg() {
297
- return new PromiseImpl(function (resolve, reject) {
298
- invoke(method, arg, resolve, reject);
299
- });
300
- }
301
- return previousPromise =
302
- // If enqueue has been called before, then we want to wait until
303
- // all previous Promises have been resolved before calling invoke,
304
- // so that results are always delivered in the correct order. If
305
- // enqueue has not been called before, then it is important to
306
- // call invoke immediately, without waiting on a callback to fire,
307
- // so that the async generator function has the opportunity to do
308
- // any necessary setup in a predictable way. This predictability
309
- // is why the Promise constructor synchronously invokes its
310
- // executor callback, and why async functions synchronously
311
- // execute code before the first await. Since we implement simple
312
- // async functions in terms of async generators, it is especially
313
- // important to get this right, even though it requires care.
314
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg,
315
- // Avoid propagating failures to Promises returned by later
316
- // invocations of the iterator.
317
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
318
- }
319
-
320
- // Define the unified helper method that is used to implement .next,
321
- // .throw, and .return (see defineIteratorMethods).
322
- this._invoke = enqueue;
323
- }
324
- defineIteratorMethods(AsyncIterator.prototype);
325
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
326
- return this;
327
- });
328
- exports.AsyncIterator = AsyncIterator;
329
-
330
- // Note that simple async functions are implemented on top of
331
- // AsyncIterator objects; they just return a Promise for the value of
332
- // the final result produced by the iterator.
333
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
334
- if (PromiseImpl === void 0) PromiseImpl = Promise;
335
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
336
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
337
- : iter.next().then(function (result) {
338
- return result.done ? result.value : iter.next();
339
- });
340
- };
341
- function makeInvokeMethod(innerFn, self, context) {
342
- var state = GenStateSuspendedStart;
343
- return function invoke(method, arg) {
344
- if (state === GenStateExecuting) {
345
- throw new Error("Generator is already running");
346
- }
347
- if (state === GenStateCompleted) {
348
- if (method === "throw") {
349
- throw arg;
350
- }
351
-
352
- // Be forgiving, per 25.3.3.3.3 of the spec:
353
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
354
- return doneResult();
355
- }
356
- context.method = method;
357
- context.arg = arg;
358
- while (true) {
359
- var delegate = context.delegate;
360
- if (delegate) {
361
- var delegateResult = maybeInvokeDelegate(delegate, context);
362
- if (delegateResult) {
363
- if (delegateResult === ContinueSentinel) continue;
364
- return delegateResult;
365
- }
366
- }
367
- if (context.method === "next") {
368
- // Setting context._sent for legacy support of Babel's
369
- // function.sent implementation.
370
- context.sent = context._sent = context.arg;
371
- } else if (context.method === "throw") {
372
- if (state === GenStateSuspendedStart) {
373
- state = GenStateCompleted;
374
- throw context.arg;
375
- }
376
- context.dispatchException(context.arg);
377
- } else if (context.method === "return") {
378
- context.abrupt("return", context.arg);
379
- }
380
- state = GenStateExecuting;
381
- var record = tryCatch(innerFn, self, context);
382
- if (record.type === "normal") {
383
- // If an exception is thrown from innerFn, we leave state ===
384
- // GenStateExecuting and loop back for another invocation.
385
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
386
- if (record.arg === ContinueSentinel) {
387
- continue;
388
- }
389
- return {
390
- value: record.arg,
391
- done: context.done
392
- };
393
- } else if (record.type === "throw") {
394
- state = GenStateCompleted;
395
- // Dispatch the exception by looping back around to the
396
- // context.dispatchException(context.arg) call above.
397
- context.method = "throw";
398
- context.arg = record.arg;
399
- }
400
- }
401
- };
402
- }
403
-
404
- // Call delegate.iterator[context.method](context.arg) and handle the
405
- // result, either by returning a { value, done } result from the
406
- // delegate iterator, or by modifying context.method and context.arg,
407
- // setting context.delegate to null, and returning the ContinueSentinel.
408
- function maybeInvokeDelegate(delegate, context) {
409
- var method = delegate.iterator[context.method];
410
- if (method === undefined$1) {
411
- // A .throw or .return when the delegate iterator has no .throw
412
- // method always terminates the yield* loop.
413
- context.delegate = null;
414
- if (context.method === "throw") {
415
- // Note: ["return"] must be used for ES3 parsing compatibility.
416
- if (delegate.iterator["return"]) {
417
- // If the delegate iterator has a return method, give it a
418
- // chance to clean up.
419
- context.method = "return";
420
- context.arg = undefined$1;
421
- maybeInvokeDelegate(delegate, context);
422
- if (context.method === "throw") {
423
- // If maybeInvokeDelegate(context) changed context.method from
424
- // "return" to "throw", let that override the TypeError below.
425
- return ContinueSentinel;
426
- }
427
- }
428
- context.method = "throw";
429
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
430
- }
431
- return ContinueSentinel;
432
- }
433
- var record = tryCatch(method, delegate.iterator, context.arg);
434
- if (record.type === "throw") {
435
- context.method = "throw";
436
- context.arg = record.arg;
437
- context.delegate = null;
438
- return ContinueSentinel;
439
- }
440
- var info = record.arg;
441
- if (!info) {
442
- context.method = "throw";
443
- context.arg = new TypeError("iterator result is not an object");
444
- context.delegate = null;
445
- return ContinueSentinel;
446
- }
447
- if (info.done) {
448
- // Assign the result of the finished delegate to the temporary
449
- // variable specified by delegate.resultName (see delegateYield).
450
- context[delegate.resultName] = info.value;
451
-
452
- // Resume execution at the desired location (see delegateYield).
453
- context.next = delegate.nextLoc;
454
-
455
- // If context.method was "throw" but the delegate handled the
456
- // exception, let the outer generator proceed normally. If
457
- // context.method was "next", forget context.arg since it has been
458
- // "consumed" by the delegate iterator. If context.method was
459
- // "return", allow the original .return call to continue in the
460
- // outer generator.
461
- if (context.method !== "return") {
462
- context.method = "next";
463
- context.arg = undefined$1;
464
- }
465
- } else {
466
- // Re-yield the result returned by the delegate method.
467
- return info;
468
- }
469
-
470
- // The delegate iterator is finished, so forget it and continue with
471
- // the outer generator.
472
- context.delegate = null;
473
- return ContinueSentinel;
474
- }
475
-
476
- // Define Generator.prototype.{next,throw,return} in terms of the
477
- // unified ._invoke helper method.
478
- defineIteratorMethods(Gp);
479
- define(Gp, toStringTagSymbol, "Generator");
480
-
481
- // A Generator should always return itself as the iterator object when the
482
- // @@iterator function is called on it. Some browsers' implementations of the
483
- // iterator prototype chain incorrectly implement this, causing the Generator
484
- // object to not be returned from this call. This ensures that doesn't happen.
485
- // See https://github.com/facebook/regenerator/issues/274 for more details.
486
- define(Gp, iteratorSymbol, function () {
487
- return this;
488
- });
489
- define(Gp, "toString", function () {
490
- return "[object Generator]";
491
- });
492
- function pushTryEntry(locs) {
493
- var entry = {
494
- tryLoc: locs[0]
495
- };
496
- if (1 in locs) {
497
- entry.catchLoc = locs[1];
498
- }
499
- if (2 in locs) {
500
- entry.finallyLoc = locs[2];
501
- entry.afterLoc = locs[3];
502
- }
503
- this.tryEntries.push(entry);
504
- }
505
- function resetTryEntry(entry) {
506
- var record = entry.completion || {};
507
- record.type = "normal";
508
- delete record.arg;
509
- entry.completion = record;
510
- }
511
- function Context(tryLocsList) {
512
- // The root entry object (effectively a try statement without a catch
513
- // or a finally block) gives us a place to store values thrown from
514
- // locations where there is no enclosing try statement.
515
- this.tryEntries = [{
516
- tryLoc: "root"
517
- }];
518
- tryLocsList.forEach(pushTryEntry, this);
519
- this.reset(true);
520
- }
521
- exports.keys = function (object) {
522
- var keys = [];
523
- for (var key in object) {
524
- keys.push(key);
525
- }
526
- keys.reverse();
527
-
528
- // Rather than returning an object with a next method, we keep
529
- // things simple and return the next function itself.
530
- return function next() {
531
- while (keys.length) {
532
- var key = keys.pop();
533
- if (key in object) {
534
- next.value = key;
535
- next.done = false;
536
- return next;
537
- }
538
- }
539
-
540
- // To avoid creating an additional object, we just hang the .value
541
- // and .done properties off the next function object itself. This
542
- // also ensures that the minifier will not anonymize the function.
543
- next.done = true;
544
- return next;
545
- };
546
- };
547
- function values(iterable) {
548
- if (iterable) {
549
- var iteratorMethod = iterable[iteratorSymbol];
550
- if (iteratorMethod) {
551
- return iteratorMethod.call(iterable);
552
- }
553
- if (typeof iterable.next === "function") {
554
- return iterable;
555
- }
556
- if (!isNaN(iterable.length)) {
557
- var i = -1,
558
- next = function next() {
559
- while (++i < iterable.length) {
560
- if (hasOwn.call(iterable, i)) {
561
- next.value = iterable[i];
562
- next.done = false;
563
- return next;
564
- }
565
- }
566
- next.value = undefined$1;
567
- next.done = true;
568
- return next;
569
- };
570
- return next.next = next;
571
- }
572
- }
573
-
574
- // Return an iterator with no values.
575
- return {
576
- next: doneResult
577
- };
578
- }
579
- exports.values = values;
580
- function doneResult() {
581
- return {
582
- value: undefined$1,
583
- done: true
584
- };
585
- }
586
- Context.prototype = {
587
- constructor: Context,
588
- reset: function reset(skipTempReset) {
589
- this.prev = 0;
590
- this.next = 0;
591
- // Resetting context._sent for legacy support of Babel's
592
- // function.sent implementation.
593
- this.sent = this._sent = undefined$1;
594
- this.done = false;
595
- this.delegate = null;
596
- this.method = "next";
597
- this.arg = undefined$1;
598
- this.tryEntries.forEach(resetTryEntry);
599
- if (!skipTempReset) {
600
- for (var name in this) {
601
- // Not sure about the optimal order of these conditions:
602
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
603
- this[name] = undefined$1;
604
- }
605
- }
606
- }
607
- },
608
- stop: function stop() {
609
- this.done = true;
610
- var rootEntry = this.tryEntries[0];
611
- var rootRecord = rootEntry.completion;
612
- if (rootRecord.type === "throw") {
613
- throw rootRecord.arg;
614
- }
615
- return this.rval;
616
- },
617
- dispatchException: function dispatchException(exception) {
618
- if (this.done) {
619
- throw exception;
620
- }
621
- var context = this;
622
- function handle(loc, caught) {
623
- record.type = "throw";
624
- record.arg = exception;
625
- context.next = loc;
626
- if (caught) {
627
- // If the dispatched exception was caught by a catch block,
628
- // then let that catch block handle the exception normally.
629
- context.method = "next";
630
- context.arg = undefined$1;
631
- }
632
- return !!caught;
633
- }
634
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
635
- var entry = this.tryEntries[i];
636
- var record = entry.completion;
637
- if (entry.tryLoc === "root") {
638
- // Exception thrown outside of any try block that could handle
639
- // it, so set the completion value of the entire function to
640
- // throw the exception.
641
- return handle("end");
642
- }
643
- if (entry.tryLoc <= this.prev) {
644
- var hasCatch = hasOwn.call(entry, "catchLoc");
645
- var hasFinally = hasOwn.call(entry, "finallyLoc");
646
- if (hasCatch && hasFinally) {
647
- if (this.prev < entry.catchLoc) {
648
- return handle(entry.catchLoc, true);
649
- } else if (this.prev < entry.finallyLoc) {
650
- return handle(entry.finallyLoc);
651
- }
652
- } else if (hasCatch) {
653
- if (this.prev < entry.catchLoc) {
654
- return handle(entry.catchLoc, true);
655
- }
656
- } else if (hasFinally) {
657
- if (this.prev < entry.finallyLoc) {
658
- return handle(entry.finallyLoc);
659
- }
660
- } else {
661
- throw new Error("try statement without catch or finally");
662
- }
663
- }
664
- }
665
- },
666
- abrupt: function abrupt(type, arg) {
667
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
668
- var entry = this.tryEntries[i];
669
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
670
- var finallyEntry = entry;
671
- break;
672
- }
673
- }
674
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
675
- // Ignore the finally entry if control is not jumping to a
676
- // location outside the try/catch block.
677
- finallyEntry = null;
678
- }
679
- var record = finallyEntry ? finallyEntry.completion : {};
680
- record.type = type;
681
- record.arg = arg;
682
- if (finallyEntry) {
683
- this.method = "next";
684
- this.next = finallyEntry.finallyLoc;
685
- return ContinueSentinel;
686
- }
687
- return this.complete(record);
688
- },
689
- complete: function complete(record, afterLoc) {
690
- if (record.type === "throw") {
691
- throw record.arg;
692
- }
693
- if (record.type === "break" || record.type === "continue") {
694
- this.next = record.arg;
695
- } else if (record.type === "return") {
696
- this.rval = this.arg = record.arg;
697
- this.method = "return";
698
- this.next = "end";
699
- } else if (record.type === "normal" && afterLoc) {
700
- this.next = afterLoc;
701
- }
702
- return ContinueSentinel;
703
- },
704
- finish: function finish(finallyLoc) {
705
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
706
- var entry = this.tryEntries[i];
707
- if (entry.finallyLoc === finallyLoc) {
708
- this.complete(entry.completion, entry.afterLoc);
709
- resetTryEntry(entry);
710
- return ContinueSentinel;
711
- }
712
- }
713
- },
714
- "catch": function _catch(tryLoc) {
715
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
716
- var entry = this.tryEntries[i];
717
- if (entry.tryLoc === tryLoc) {
718
- var record = entry.completion;
719
- if (record.type === "throw") {
720
- var thrown = record.arg;
721
- resetTryEntry(entry);
722
- }
723
- return thrown;
724
- }
725
- }
726
-
727
- // The context.catch method must only be called with a location
728
- // argument that corresponds to a known catch block.
729
- throw new Error("illegal catch attempt");
730
- },
731
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
732
- this.delegate = {
733
- iterator: values(iterable),
734
- resultName: resultName,
735
- nextLoc: nextLoc
736
- };
737
- if (this.method === "next") {
738
- // Deliberately forget the last sent value so that we don't
739
- // accidentally pass it on to the delegate.
740
- this.arg = undefined$1;
741
- }
742
- return ContinueSentinel;
743
- }
744
- };
745
-
746
- // Regardless of whether this script is executing as a CommonJS module
747
- // or not, return the runtime object so that we can declare the variable
748
- // regeneratorRuntime in the outer scope, which allows this module to be
749
- // injected easily by `bin/regenerator --include-runtime script.js`.
750
- return exports;
751
- }(
752
- // If this script is executing as a CommonJS module, use module.exports
753
- // as the regeneratorRuntime namespace. Otherwise create a new empty
754
- // object. Either way, the resulting object will be used to initialize
755
- // the regeneratorRuntime variable at the top of this file.
756
- module.exports );
757
- try {
758
- regeneratorRuntime = runtime;
759
- } catch (accidentalStrictMode) {
760
- // This module should not be running in strict mode, so the above
761
- // assignment should always work unless something is misconfigured. Just
762
- // in case runtime.js accidentally runs in strict mode, in modern engines
763
- // we can explicitly access globalThis. In older engines we can escape
764
- // strict mode using a global Function call. This could conceivably fail
765
- // if a Content Security Policy forbids using Function, but in that case
766
- // the proper solution is to fix the accidental strict mode problem. If
767
- // you've misconfigured your bundler to force strict mode and applied a
768
- // CSP to forbid Function, and you're not willing to fix either of those
769
- // problems, please detail your unique predicament in a GitHub issue.
770
- if (typeof globalThis === "object") {
771
- globalThis.regeneratorRuntime = runtime;
772
- } else {
773
- Function("r", "regeneratorRuntime = r")(runtime);
774
- }
775
- }
776
- });
777
-
778
- var isBrowser = typeof window !== 'undefined';
779
- function useForceUpdate() {
780
- var _React$useState = useState(0),
781
- setTick = _React$useState[1];
782
- var update = useCallback(function () {
783
- setTick(function (tick) {
784
- return tick + 1;
785
- });
786
- }, []);
787
- return update;
788
- }
789
- function useStableLookupSpec(spec) {
790
- return useStableLookupSpecs(spec)[0];
791
- }
792
- function useStableLookupSpecs() {
793
- for (var _len = arguments.length, specs = new Array(_len), _key = 0; _key < _len; _key++) {
794
- specs[_key] = arguments[_key];
795
- }
796
- var _React$useState2 = useState(specs),
797
- stableSpecs = _React$useState2[0],
798
- setStableSpecs = _React$useState2[1];
799
- useEffect(function () {
800
- if (specs.length !== stableSpecs.length || specs.some(function (s, i) {
801
- return !areLookupSpecsEqual(s, stableSpecs[i]);
802
- })) {
803
- setStableSpecs(specs);
804
- }
805
- }, [specs, stableSpecs]);
806
- return stableSpecs;
807
- }
808
- function areLookupSpecsEqual(spec1, spec2) {
809
- if (spec1 === spec2) {
810
- return true;
811
- }
812
- if (typeof spec1 !== typeof spec2) {
813
- return false;
814
- }
815
- var fullSpec1 = toFullLookup(spec1);
816
- var fullSpec2 = toFullLookup(spec2);
817
- return (isNameSpec(fullSpec1) && isNameSpec(fullSpec2) && fullSpec1.name === fullSpec2.name && fullSpec1.isCode === fullSpec2.isCode || isPathSpec(fullSpec1) && isPathSpec(fullSpec2) && fullSpec1.path === fullSpec2.path) && fullSpec1.projectId === fullSpec2.projectId;
818
- }
819
- function isNameSpec(lookup) {
820
- return 'name' in lookup;
821
- }
822
- function isPathSpec(lookup) {
823
- return 'path' in lookup;
824
- }
825
- function toFullLookup(lookup) {
826
- var namePart = typeof lookup === 'string' ? lookup : lookup.name;
827
- var projectId = typeof lookup === 'string' ? undefined : lookup.projectId;
828
- var codeComponent = typeof lookup === 'string' ? undefined : lookup.isCode;
829
- if (codeComponent !== true && namePart.startsWith('/')) {
830
- return {
831
- path: normalizePath(namePart),
832
- projectId: projectId
833
- };
834
- } else {
835
- return {
836
- name: codeComponent ? namePart : normalizeName(namePart),
837
- rawName: namePart.trim(),
838
- projectId: projectId,
839
- isCode: codeComponent
840
- };
841
- }
842
- }
843
- function normalizePath(path) {
844
- return path.trim();
845
- }
846
- function normalizeName(name) {
847
- // Not a full normalization, but should be good enough
848
- return pascalcase(name).trim();
849
- }
850
- function useIsMounted() {
851
- var ref = useRef(false);
852
- var isMounted = useCallback(function () {
853
- return ref.current;
854
- }, []);
855
- useEffect(function () {
856
- ref.current = true;
857
- return function () {
858
- ref.current = false;
859
- };
860
- }, []);
861
- return isMounted;
862
- }
863
- /**
864
- * Check if `lookup` resolves to `pagePath`. If it's a match, return an object
865
- * containing path params; otherwise, returns false.
866
- *
867
- * For example,
868
- * - `matchesPagePath("/hello/[name]", "/hello/world")` -> `{params: {name:
869
- * "world"}}`
870
- * - `matchesPagePath("/hello/[name]", "/")` -> `false`
871
- * - `matchesPagePath("/", "")` -> `{params: {}}`
872
- */
873
- function matchesPagePath(pagePath, lookup) {
874
- var _lookup$match;
875
- // Remove trailing slashes from both `pagePath` and `lookup`.
876
- pagePath = pagePath.replace(/^\/*/, '').replace(/\/*$/, '');
877
- lookup = lookup.replace(/^\/*/, '').replace(/\/*$/, '');
878
- // paramNames will contain a list of parameter names; e.g. if pagePath
879
- // is "/products/[slug]/[variant]" it will contain ["slug", "variant"].
880
- var paramNames = (pagePath.match(/\[([^\]]*)\]/g) || []).map(function (group) {
881
- return group.slice(1, -1);
882
- });
883
- var pagePathRegExp = new RegExp('^' + pagePath.replace(/\[[^\]]*\]/g, '([^/]+)') + '$');
884
- var maybeVals = (_lookup$match = lookup.match(pagePathRegExp)) == null ? void 0 : _lookup$match.slice(1);
885
- if (!maybeVals) {
886
- return false;
887
- }
888
- var params = {};
889
- for (var i = 0; i < paramNames.length; i++) {
890
- params[paramNames[i]] = maybeVals[i];
891
- }
892
- return {
893
- params: params
894
- };
895
- }
896
- function isDynamicPagePath(path) {
897
- return !!path.match(/\[[^/]*\]/);
898
- }
899
- function matchesCompMeta(lookup, meta) {
900
- if (lookup.projectId && meta.projectId !== lookup.projectId) {
901
- return false;
902
- }
903
- return isNameSpec(lookup) ? (lookup.name === meta.name || lookup.rawName === meta.name || lookup.rawName === meta.displayName) && (lookup.isCode == null || lookup.isCode === meta.isCode) : !!(meta.path && matchesPagePath(meta.path, lookup.path));
904
- }
905
- function getCompMetas(metas, lookup) {
906
- var full = toFullLookup(lookup);
907
- return metas.filter(function (meta) {
908
- return matchesCompMeta(full, meta);
909
- }).map(function (meta) {
910
- if (isNameSpec(full) || !meta.path) {
911
- return meta;
912
- }
913
- var match = matchesPagePath(meta.path, full.path);
914
- if (!match) {
915
- return meta;
916
- }
917
- return _extends({}, meta, {
918
- params: match.params
919
- });
920
- }).sort(function (meta1, meta2) {
921
- return (
922
- // We sort the matched component metas by the number of path params, so
923
- // if there are two pages `/products/foo` and `/products/[slug]`,
924
- // the first one will have higher precedence.
925
- Array.from(Object.keys(meta1.params || {})).length - Array.from(Object.keys(meta2.params || {})).length
926
- );
927
- });
928
- }
929
- function getLookupSpecName(lookup) {
930
- if (typeof lookup === 'string') {
931
- return lookup;
932
- } else if (lookup.projectId) {
933
- return lookup.name + " (project " + lookup.projectId + ")";
934
- } else {
935
- return lookup.name;
936
- }
937
- }
938
- function uniq(elements) {
939
- return Array.from(new Set(elements));
940
- }
941
-
942
- function getFirstCompMeta(metas, lookup) {
943
- var filtered = getCompMetas(metas, lookup);
944
- return filtered.length === 0 ? undefined : filtered[0];
945
- }
946
- var ComponentLookup = /*#__PURE__*/function () {
947
- function ComponentLookup(bundle, registry) {
948
- this.bundle = bundle;
949
- this.registry = registry;
950
- }
951
- var _proto = ComponentLookup.prototype;
952
- _proto.getComponentMeta = function getComponentMeta(spec) {
953
- var compMeta = getFirstCompMeta(this.bundle.components, spec);
954
- return compMeta;
955
- };
956
- _proto.getComponent = function getComponent(spec, opts) {
957
- if (opts === void 0) {
958
- opts = {};
959
- }
960
- var compMeta = getFirstCompMeta(this.bundle.components, spec);
961
- if (!compMeta) {
962
- throw new Error("Component not found: " + spec);
963
- }
964
- var moduleName = compMeta.entry;
965
- if (!this.registry.hasModule(moduleName, opts)) {
966
- throw new Error("Component not yet fetched: " + compMeta.name);
967
- }
968
- var entry = this.registry.load(moduleName, {
969
- forceOriginal: opts.forceOriginal
970
- });
971
- return !opts.forceOriginal && typeof (entry == null ? void 0 : entry.getPlasmicComponent) === 'function' ? entry.getPlasmicComponent() : entry["default"];
972
- };
973
- _proto.hasComponent = function hasComponent(spec) {
974
- var compMeta = getFirstCompMeta(this.bundle.components, spec);
975
- if (compMeta) {
976
- return this.registry.hasModule(compMeta.entry);
977
- }
978
- return false;
979
- };
980
- _proto.getGlobalContexts = function getGlobalContexts() {
981
- var _this = this;
982
- var customGlobalMetas = this.bundle.globalGroups.filter(function (m) {
983
- return m.type === 'global-user-defined';
984
- });
985
- return customGlobalMetas.map(function (meta) {
986
- return {
987
- meta: meta,
988
- context: _this.registry.load(meta.contextFile)["default"]
989
- };
990
- });
991
- };
992
- _proto.getGlobalContextsProvider = function getGlobalContextsProvider(spec) {
993
- var compMeta = getFirstCompMeta(this.bundle.components, spec);
994
- var projectMeta = compMeta ? this.bundle.projects.find(function (x) {
995
- return x.id === compMeta.projectId;
996
- }) : undefined;
997
- if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
998
- return undefined;
999
- }
1000
- var entry = this.registry.load(projectMeta.globalContextsProviderFileName);
1001
- return typeof (entry == null ? void 0 : entry.getPlasmicComponent) === 'function' ? entry.getPlasmicComponent() : entry["default"];
1002
- };
1003
- _proto.getRootProvider = function getRootProvider() {
1004
- var entry = this.registry.load('root-provider.js');
1005
- return entry["default"];
1006
- };
1007
- _proto.getCss = function getCss() {
1008
- // We can probably always get the modules from the browser build
1009
- return this.bundle.modules.browser.filter(function (mod) {
1010
- return mod.type === 'asset' && mod.fileName.endsWith('css');
1011
- });
1012
- };
1013
- _proto.getRemoteFonts = function getRemoteFonts() {
1014
- return this.bundle.projects.flatMap(function (p) {
1015
- return p.remoteFonts;
1016
- });
1017
- };
1018
- return ComponentLookup;
1019
- }();
1020
-
1021
- function getPlasmicCookieValues() {
1022
- return Object.fromEntries(document.cookie.split('; ').filter(function (cookie) {
1023
- return cookie.includes('plasmic:');
1024
- }).map(function (cookie) {
1025
- return cookie.split('=');
1026
- }).map(function (_ref) {
1027
- var key = _ref[0],
1028
- value = _ref[1];
1029
- return [key.split(':')[1], value];
1030
- }));
1031
- }
1032
- function updatePlasmicCookieValue(key, value) {
1033
- document.cookie = "plasmic:" + key + "=" + value;
1034
- }
1035
- function ensureVariationCookies(variation) {
1036
- if (variation === void 0) {
1037
- variation = {};
1038
- }
1039
- Object.keys(variation).map(function (variationKey) {
1040
- var sliceId = variation[variationKey];
1041
- updatePlasmicCookieValue(variationKey, sliceId);
1042
- });
1043
- }
1044
- var getGlobalVariantsFromSplits = function getGlobalVariantsFromSplits(splits, variation) {
1045
- var globalVariants = [];
1046
- Object.keys(variation).map(function (variationKey) {
1047
- var _variationKey$split = variationKey.split('.'),
1048
- splitId = _variationKey$split[1];
1049
- var sliceId = variation[variationKey];
1050
- var split = splits.find(function (s) {
1051
- return s.id === splitId || s.externalId === splitId;
1052
- });
1053
- if (split) {
1054
- var slice = split.slices.find(function (s) {
1055
- return s.id === sliceId || s.externalId === sliceId;
1056
- });
1057
- if (slice) {
1058
- slice.contents.map(function (x) {
1059
- globalVariants.push({
1060
- name: x.group,
1061
- value: x.variant,
1062
- projectId: x.projectId
1063
- });
1064
- });
1065
- }
1066
- }
1067
- });
1068
- return globalVariants;
1069
- };
1070
- var mergeGlobalVariantsSpec = function mergeGlobalVariantsSpec(target, from) {
1071
- var result = [].concat(target);
1072
- var existingGlobalVariants = new Set(target.map(function (t) {
1073
- var _t$projectId;
1074
- return t.name + "-" + ((_t$projectId = t.projectId) != null ? _t$projectId : '');
1075
- }));
1076
- var newGlobals = from.filter(function (t) {
1077
- var _t$projectId2;
1078
- return !existingGlobalVariants.has(t.name + "-" + ((_t$projectId2 = t.projectId) != null ? _t$projectId2 : ''));
1079
- });
1080
- if (newGlobals.length > 0) {
1081
- result = [].concat(result, newGlobals);
1082
- }
1083
- return result;
1084
- };
1085
-
1086
- var PlasmicRootContext = /*#__PURE__*/createContext(undefined);
1087
- /**
1088
- * PlasmicRootProvider should be used at the root of your page
1089
- * or application.
1090
- */
1091
- function PlasmicRootProvider(props) {
1092
- var globalVariants = props.globalVariants,
1093
- prefetchedData = props.prefetchedData,
1094
- children = props.children,
1095
- skipCss = props.skipCss,
1096
- skipFonts = props.skipFonts,
1097
- prefetchedQueryData = props.prefetchedQueryData,
1098
- suspenseForQueryData = props.suspenseForQueryData,
1099
- globalContextsProps = props.globalContextsProps,
1100
- variation = props.variation,
1101
- translator = props.translator,
1102
- Head = props.Head,
1103
- pageParams = props.pageParams,
1104
- pageQuery = props.pageQuery;
1105
- var loader = props.loader.__internal;
1106
- if (prefetchedData) {
1107
- loader.registerPrefetchedBundle(prefetchedData == null ? void 0 : prefetchedData.bundle);
1108
- }
1109
- var _React$useState = useState(loader.getActiveSplits()),
1110
- splits = _React$useState[0],
1111
- setSplits = _React$useState[1];
1112
- var forceUpdate = useForceUpdate();
1113
- var watcher = useMemo(function () {
1114
- return {
1115
- onDataFetched: function onDataFetched() {
1116
- setSplits(loader.getActiveSplits());
1117
- forceUpdate();
1118
- }
1119
- };
1120
- }, [loader, forceUpdate]);
1121
- useEffect(function () {
1122
- loader.subscribePlasmicRoot(watcher);
1123
- return function () {
1124
- return loader.unsubscribePlasmicRoot(watcher);
1125
- };
1126
- }, [watcher, loader]);
1127
- useEffect(function () {
1128
- ensureVariationCookies(variation);
1129
- loader.trackRender({
1130
- renderCtx: {
1131
- // We track the provider as a single entity
1132
- rootComponentId: 'provider',
1133
- teamIds: loader.getTeamIds(),
1134
- projectIds: loader.getProjectIds()
1135
- },
1136
- variation: variation
1137
- });
1138
- }, [loader, variation]);
1139
- var user = props.user,
1140
- userAuthToken = props.userAuthToken,
1141
- isUserLoading = props.isUserLoading,
1142
- authRedirectUri = props.authRedirectUri;
1143
- var value = useMemo(function () {
1144
- return {
1145
- globalVariants: mergeGlobalVariantsSpec(globalVariants != null ? globalVariants : [], getGlobalVariantsFromSplits(splits, variation != null ? variation : {})),
1146
- globalContextsProps: globalContextsProps,
1147
- loader: loader,
1148
- variation: variation,
1149
- translator: translator,
1150
- Head: Head,
1151
- user: user,
1152
- userAuthToken: userAuthToken,
1153
- isUserLoading: isUserLoading,
1154
- authRedirectUri: authRedirectUri
1155
- };
1156
- }, [globalVariants, variation, globalContextsProps, loader, splits, translator, Head, user, userAuthToken, isUserLoading, authRedirectUri]);
1157
- return createElement(PlasmicQueryDataProvider, {
1158
- prefetchedCache: prefetchedQueryData,
1159
- suspense: suspenseForQueryData
1160
- }, createElement(PlasmicRootContext.Provider, {
1161
- value: value
1162
- }, !skipCss && createElement(PlasmicCss, {
1163
- loader: loader,
1164
- prefetchedData: prefetchedData,
1165
- skipFonts: skipFonts
1166
- }), createElement(PageParamsProvider, {
1167
- params: pageParams,
1168
- query: pageQuery
1169
- }, children)));
1170
- }
1171
- /**
1172
- * Inject all css modules as <style/> tags. We can't use the usual styleInjector postcss
1173
- * uses because that doesn't work on the server side for SSR.
1174
- */
1175
- var PlasmicCss = /*#__PURE__*/memo(function PlasmicCss(props) {
1176
- var loader = props.loader,
1177
- prefetchedData = props.prefetchedData,
1178
- skipFonts = props.skipFonts;
1179
- var _React$useState2 = useState(!!prefetchedData),
1180
- useScopedCss = _React$useState2[0],
1181
- setUseScopedCss = _React$useState2[1];
1182
- var builtCss = buildCss(loader, {
1183
- scopedCompMetas: useScopedCss && prefetchedData ? prefetchedData.bundle.components : undefined,
1184
- skipFonts: skipFonts
1185
- });
1186
- var forceUpdate = useForceUpdate();
1187
- var watcher = useMemo(function () {
1188
- return {
1189
- onDataFetched: function onDataFetched() {
1190
- // If new data has been fetched, then use all the fetched css
1191
- setUseScopedCss(false);
1192
- forceUpdate();
1193
- }
1194
- };
1195
- }, [loader, forceUpdate]);
1196
- useEffect(function () {
1197
- loader.subscribePlasmicRoot(watcher);
1198
- return function () {
1199
- return loader.unsubscribePlasmicRoot(watcher);
1200
- };
1201
- }, [watcher, loader]);
1202
- return createElement("style", {
1203
- dangerouslySetInnerHTML: {
1204
- __html: builtCss
1205
- }
1206
- });
1207
- });
1208
- function buildCss(loader, opts) {
1209
- var scopedCompMetas = opts.scopedCompMetas,
1210
- skipFonts = opts.skipFonts;
1211
- var cssFiles = scopedCompMetas && new Set(['entrypoint.css'].concat(scopedCompMetas.map(function (c) {
1212
- return c.cssFile;
1213
- })));
1214
- var cssModules = loader.getLookup().getCss().filter(function (f) {
1215
- return !cssFiles || cssFiles.has(f.fileName);
1216
- });
1217
- var getPri = function getPri(fileName) {
1218
- return fileName === 'entrypoint.css' ? 0 : 1;
1219
- };
1220
- var compareModules = function compareModules(a, b) {
1221
- return getPri(a.fileName) !== getPri(b.fileName) ? getPri(a.fileName) - getPri(b.fileName) : a.fileName.localeCompare(b.fileName);
1222
- };
1223
- cssModules.sort(compareModules);
1224
- var remoteFonts = loader.getLookup().getRemoteFonts();
1225
- // Make sure the @import statements come at the front of css
1226
- return "\n " + (skipFonts ? '' : remoteFonts.map(function (f) {
1227
- return "@import url('" + f.url + "');";
1228
- }).join('\n')) + "\n " + cssModules.map(function (mod) {
1229
- return mod.source;
1230
- }).join('\n') + "\n ";
1231
- }
1232
- function usePlasmicRootContext() {
1233
- return useContext(PlasmicRootContext);
1234
- }
1235
-
1236
- /**
1237
- * We don't actually make use of the global variant React contexts generated
1238
- * in the bundle. That's because we would have to wait until the data is
1239
- * loaded before we can set up the context providers, but setting up context
1240
- * providers will mutate the React tree and invalidate all the children. That means
1241
- * once data comes in, we'll re-render the React tree from the providers down
1242
- * in a way that will lose all existing React state. Therefore, instead,
1243
- * we always have a single context provided -- the PlasmicRootContext -- and we
1244
- * create these fake useGlobalVariant() hooks that just read from that
1245
- * PlasmicRootContext. This allows us to have a stable React tree before and
1246
- * after the data load.
1247
- */
1248
- function createUseGlobalVariant(name, projectId) {
1249
- return function () {
1250
- var _rootContext$globalVa;
1251
- var rootContext = usePlasmicRootContext();
1252
- if (!rootContext) {
1253
- return undefined;
1254
- }
1255
- var loader = rootContext.loader;
1256
- var spec = [].concat(loader.getGlobalVariants(), (_rootContext$globalVa = rootContext.globalVariants) != null ? _rootContext$globalVa : []).find(function (spec) {
1257
- return spec.name === name && (!spec.projectId || spec.projectId === projectId);
1258
- });
1259
- return spec ? spec.value : undefined;
1260
- };
1261
- }
1262
-
1263
- function getUsedComps(allComponents, entryCompIds) {
1264
- var q = [].concat(entryCompIds);
1265
- var seenIds = new Set(entryCompIds);
1266
- var componentMetaById = new Map(allComponents.map(function (meta) {
1267
- return [meta.id, meta];
1268
- }));
1269
- var usedComps = [];
1270
- while (q.length > 0) {
1271
- var _q$splice = q.splice(0, 1),
1272
- id = _q$splice[0];
1273
- var meta = componentMetaById.get(id);
1274
- if (!meta) {
1275
- continue;
1276
- }
1277
- usedComps.push(meta);
1278
- meta.usedComponents.forEach(function (usedCompId) {
1279
- if (!seenIds.has(usedCompId)) {
1280
- seenIds.add(usedCompId);
1281
- q.push(usedCompId);
1282
- }
1283
- });
1284
- }
1285
- return usedComps;
1286
- }
1287
- function prepComponentData(bundle, compMetas, opts) {
1288
- if (compMetas.length === 0) {
1289
- return {
1290
- entryCompMetas: bundle.components,
1291
- bundle: bundle,
1292
- remoteFontUrls: []
1293
- };
1294
- }
1295
- var usedComps = getUsedComps(bundle.components, compMetas.map(function (compMeta) {
1296
- return compMeta.id;
1297
- }));
1298
- var compPaths = usedComps.map(function (compMeta) {
1299
- return compMeta.entry;
1300
- });
1301
- var subBundle = getBundleSubset(bundle, ['entrypoint.css'].concat(compPaths, ['root-provider.js'], bundle.projects.map(function (x) {
1302
- return x.globalContextsProviderFileName;
1303
- }).filter(function (x) {
1304
- return !!x;
1305
- }), bundle.components.filter(function (c) {
1306
- return c.isGlobalContextProvider;
1307
- }).map(function (c) {
1308
- return c.entry;
1309
- }), bundle.globalGroups.map(function (g) {
1310
- return g.contextFile;
1311
- })), opts);
1312
- var remoteFontUrls = [];
1313
- subBundle.projects.forEach(function (p) {
1314
- return remoteFontUrls.push.apply(remoteFontUrls, p.remoteFonts.map(function (f) {
1315
- return f.url;
1316
- }));
1317
- });
1318
- return {
1319
- entryCompMetas: compMetas,
1320
- bundle: subBundle,
1321
- remoteFontUrls: remoteFontUrls
1322
- };
1323
- }
1324
- function mergeBundles(target, from) {
1325
- var _from$activeSplits$fi;
1326
- var existingCompIds = new Set(target.components.map(function (c) {
1327
- return c.id;
1328
- }));
1329
- var newCompMetas = from.components.filter(function (m) {
1330
- return !existingCompIds.has(m.id);
1331
- });
1332
- if (newCompMetas.length > 0) {
1333
- target = _extends({}, target, {
1334
- components: [].concat(target.components, newCompMetas)
1335
- });
1336
- }
1337
- var existingProjects = new Set(target.projects.map(function (p) {
1338
- return p.id;
1339
- }));
1340
- var newProjects = from.projects.filter(function (p) {
1341
- return !existingProjects.has(p.id);
1342
- });
1343
- if (newProjects.length > 0) {
1344
- target = _extends({}, target, {
1345
- projects: [].concat(target.projects, newProjects)
1346
- });
1347
- }
1348
- var existingModules = {
1349
- browser: new Set(target.modules.browser.map(function (m) {
1350
- return m.fileName;
1351
- })),
1352
- server: new Set(target.modules.server.map(function (m) {
1353
- return m.fileName;
1354
- }))
1355
- };
1356
- var newModules = {
1357
- browser: from.modules.browser.filter(function (m) {
1358
- return !existingModules.browser.has(m.fileName);
1359
- }),
1360
- server: from.modules.server.filter(function (m) {
1361
- return !existingModules.server.has(m.fileName);
1362
- })
1363
- };
1364
- if (newModules.browser.length > 0 || newModules.server.length > 0) {
1365
- target = _extends({}, target, {
1366
- modules: {
1367
- browser: [].concat(target.modules.browser, newModules.browser),
1368
- server: [].concat(target.modules.server, newModules.server)
1369
- }
1370
- });
1371
- }
1372
- var existingGlobalIds = new Set(target.globalGroups.map(function (g) {
1373
- return g.id;
1374
- }));
1375
- var newGlobals = from.globalGroups.filter(function (g) {
1376
- return !existingGlobalIds.has(g.id);
1377
- });
1378
- if (newGlobals.length > 0) {
1379
- target = _extends({}, target, {
1380
- globalGroups: [].concat(target.globalGroups, newGlobals)
1381
- });
1382
- }
1383
- var existingExternals = new Set(target.external);
1384
- var newExternals = target.external.filter(function (x) {
1385
- return !existingExternals.has(x);
1386
- });
1387
- if (newExternals.length > 0) {
1388
- target = _extends({}, target, {
1389
- external: [].concat(target.external, newExternals)
1390
- });
1391
- }
1392
- var existingSplitIds = new Set(target.activeSplits.map(function (s) {
1393
- return s.id;
1394
- }));
1395
- var newSplits = (_from$activeSplits$fi = from.activeSplits.filter(function (s) {
1396
- return !existingSplitIds.has(s.id);
1397
- })) != null ? _from$activeSplits$fi : [];
1398
- if (newSplits.length > 0) {
1399
- target = _extends({}, target, {
1400
- activeSplits: [].concat(target.activeSplits, newSplits)
1401
- });
1402
- }
1403
- return target;
1404
- }
1405
- var convertBundlesToComponentRenderData = function convertBundlesToComponentRenderData(bundles, compMetas) {
1406
- if (bundles.length === 0) {
1407
- return null;
1408
- }
1409
- var mergedBundles = bundles.reduce(function (prev, cur) {
1410
- return mergeBundles(prev, cur);
1411
- });
1412
- return prepComponentData(mergedBundles, compMetas);
1413
- };
1414
-
1415
- /** Subset of loader functionality that works on React Server Components. */
1416
- var ReactServerPlasmicComponentLoader = /*#__PURE__*/function () {
1417
- function ReactServerPlasmicComponentLoader(args) {
1418
- this.bundle = {
1419
- modules: {
1420
- browser: [],
1421
- server: []
1422
- },
1423
- components: [],
1424
- globalGroups: [],
1425
- external: [],
1426
- projects: [],
1427
- activeSplits: []
1428
- };
1429
- this.opts = args.opts;
1430
- this.fetcher = args.fetcher;
1431
- this.tracker = args.tracker;
1432
- this.onBundleMerged = args.onBundleMerged;
1433
- this.onBundleFetched = args.onBundleFetched;
1434
- }
1435
- var _proto = ReactServerPlasmicComponentLoader.prototype;
1436
- _proto.maybeGetCompMetas = function maybeGetCompMetas() {
1437
- var found = new Set();
1438
- var missing = [];
1439
- for (var _len = arguments.length, specs = new Array(_len), _key = 0; _key < _len; _key++) {
1440
- specs[_key] = arguments[_key];
1441
- }
1442
- for (var _i = 0, _specs = specs; _i < _specs.length; _i++) {
1443
- var spec = _specs[_i];
1444
- var filteredMetas = getCompMetas(this.bundle.components, spec);
1445
- if (filteredMetas.length > 0) {
1446
- filteredMetas.forEach(function (meta) {
1447
- return found.add(meta);
1448
- });
1449
- } else {
1450
- missing.push(spec);
1451
- }
1452
- }
1453
- return {
1454
- found: Array.from(found.keys()),
1455
- missing: missing
1456
- };
1457
- };
1458
- _proto.maybeFetchComponentData = /*#__PURE__*/function () {
1459
- var _maybeFetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1460
- var _this = this;
1461
- var _parseFetchComponentD,
1462
- specs,
1463
- opts,
1464
- returnWithSpecsToFetch,
1465
- _this$maybeGetCompMet2,
1466
- existingMetas,
1467
- missingSpecs,
1468
- _args2 = arguments;
1469
- return runtime_1.wrap(function _callee2$(_context2) {
1470
- while (1) {
1471
- switch (_context2.prev = _context2.next) {
1472
- case 0:
1473
- _parseFetchComponentD = parseFetchComponentDataArgs.apply(void 0, _args2), specs = _parseFetchComponentD.specs, opts = _parseFetchComponentD.opts;
1474
- returnWithSpecsToFetch = /*#__PURE__*/function () {
1475
- var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(specsToFetch) {
1476
- var _this$maybeGetCompMet, existingMetas2, missingSpecs2;
1477
- return runtime_1.wrap(function _callee$(_context) {
1478
- while (1) {
1479
- switch (_context.prev = _context.next) {
1480
- case 0:
1481
- _context.next = 2;
1482
- return _this.fetchMissingData({
1483
- missingSpecs: specsToFetch
1484
- });
1485
- case 2:
1486
- _this$maybeGetCompMet = _this.maybeGetCompMetas.apply(_this, specs), existingMetas2 = _this$maybeGetCompMet.found, missingSpecs2 = _this$maybeGetCompMet.missing;
1487
- if (!(missingSpecs2.length > 0)) {
1488
- _context.next = 5;
1489
- break;
1490
- }
1491
- return _context.abrupt("return", null);
1492
- case 5:
1493
- return _context.abrupt("return", prepComponentData(_this.bundle, existingMetas2, opts));
1494
- case 6:
1495
- case "end":
1496
- return _context.stop();
1497
- }
1498
- }
1499
- }, _callee);
1500
- }));
1501
- return function returnWithSpecsToFetch(_x) {
1502
- return _ref.apply(this, arguments);
1503
- };
1504
- }();
1505
- if (!this.opts.alwaysFresh) {
1506
- _context2.next = 6;
1507
- break;
1508
- }
1509
- _context2.next = 5;
1510
- return returnWithSpecsToFetch(specs);
1511
- case 5:
1512
- return _context2.abrupt("return", _context2.sent);
1513
- case 6:
1514
- // Else we only fetch actually missing specs
1515
- _this$maybeGetCompMet2 = this.maybeGetCompMetas.apply(this, specs), existingMetas = _this$maybeGetCompMet2.found, missingSpecs = _this$maybeGetCompMet2.missing;
1516
- if (!(missingSpecs.length === 0)) {
1517
- _context2.next = 9;
1518
- break;
1519
- }
1520
- return _context2.abrupt("return", prepComponentData(this.bundle, existingMetas, opts));
1521
- case 9:
1522
- _context2.next = 11;
1523
- return returnWithSpecsToFetch(missingSpecs);
1524
- case 11:
1525
- return _context2.abrupt("return", _context2.sent);
1526
- case 12:
1527
- case "end":
1528
- return _context2.stop();
1529
- }
1530
- }
1531
- }, _callee2, this);
1532
- }));
1533
- function maybeFetchComponentData() {
1534
- return _maybeFetchComponentData.apply(this, arguments);
1535
- }
1536
- return maybeFetchComponentData;
1537
- }();
1538
- _proto.fetchComponentData = /*#__PURE__*/function () {
1539
- var _fetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1540
- var _parseFetchComponentD2,
1541
- specs,
1542
- opts,
1543
- data,
1544
- _this$maybeGetCompMet3,
1545
- missingSpecs,
1546
- _args3 = arguments;
1547
- return runtime_1.wrap(function _callee3$(_context3) {
1548
- while (1) {
1549
- switch (_context3.prev = _context3.next) {
1550
- case 0:
1551
- _parseFetchComponentD2 = parseFetchComponentDataArgs.apply(void 0, _args3), specs = _parseFetchComponentD2.specs, opts = _parseFetchComponentD2.opts;
1552
- _context3.next = 3;
1553
- return this.maybeFetchComponentData(specs, opts);
1554
- case 3:
1555
- data = _context3.sent;
1556
- if (data) {
1557
- _context3.next = 7;
1558
- break;
1559
- }
1560
- _this$maybeGetCompMet3 = this.maybeGetCompMetas.apply(this, specs), missingSpecs = _this$maybeGetCompMet3.missing;
1561
- throw new Error("Unable to find components " + missingSpecs.map(getLookupSpecName).join(', '));
1562
- case 7:
1563
- return _context3.abrupt("return", data);
1564
- case 8:
1565
- case "end":
1566
- return _context3.stop();
1567
- }
1568
- }
1569
- }, _callee3, this);
1570
- }));
1571
- function fetchComponentData() {
1572
- return _fetchComponentData.apply(this, arguments);
1573
- }
1574
- return fetchComponentData;
1575
- }();
1576
- _proto.fetchPages = /*#__PURE__*/function () {
1577
- var _fetchPages = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(opts) {
1578
- var data;
1579
- return runtime_1.wrap(function _callee4$(_context4) {
1580
- while (1) {
1581
- switch (_context4.prev = _context4.next) {
1582
- case 0:
1583
- this.maybeReportClientSideFetch(function () {
1584
- return "Plasmic: fetching all page metadata in the browser";
1585
- });
1586
- _context4.next = 3;
1587
- return this.fetchAllData();
1588
- case 3:
1589
- data = _context4.sent;
1590
- return _context4.abrupt("return", data.components.filter(function (comp) {
1591
- return comp.isPage && comp.path && ((opts == null ? void 0 : opts.includeDynamicPages) || !isDynamicPagePath(comp.path));
1592
- }));
1593
- case 5:
1594
- case "end":
1595
- return _context4.stop();
1596
- }
1597
- }
1598
- }, _callee4, this);
1599
- }));
1600
- function fetchPages(_x2) {
1601
- return _fetchPages.apply(this, arguments);
1602
- }
1603
- return fetchPages;
1604
- }();
1605
- _proto.fetchComponents = /*#__PURE__*/function () {
1606
- var _fetchComponents = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
1607
- var data;
1608
- return runtime_1.wrap(function _callee5$(_context5) {
1609
- while (1) {
1610
- switch (_context5.prev = _context5.next) {
1611
- case 0:
1612
- this.maybeReportClientSideFetch(function () {
1613
- return "Plasmic: fetching all component metadata in the browser";
1614
- });
1615
- _context5.next = 3;
1616
- return this.fetchAllData();
1617
- case 3:
1618
- data = _context5.sent;
1619
- return _context5.abrupt("return", data.components);
1620
- case 5:
1621
- case "end":
1622
- return _context5.stop();
1623
- }
1624
- }
1625
- }, _callee5, this);
1626
- }));
1627
- function fetchComponents() {
1628
- return _fetchComponents.apply(this, arguments);
1629
- }
1630
- return fetchComponents;
1631
- }();
1632
- _proto.getActiveSplits = function getActiveSplits() {
1633
- return this.bundle.activeSplits;
1634
- };
1635
- _proto.fetchMissingData = /*#__PURE__*/function () {
1636
- var _fetchMissingData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(opts) {
1637
- return runtime_1.wrap(function _callee6$(_context6) {
1638
- while (1) {
1639
- switch (_context6.prev = _context6.next) {
1640
- case 0:
1641
- // TODO: do better than just fetching everything
1642
- this.maybeReportClientSideFetch(function () {
1643
- return "Plasmic: fetching missing components in the browser: " + opts.missingSpecs.map(function (spec) {
1644
- return getLookupSpecName(spec);
1645
- }).join(', ');
1646
- });
1647
- return _context6.abrupt("return", this.fetchAllData());
1648
- case 2:
1649
- case "end":
1650
- return _context6.stop();
1651
- }
1652
- }
1653
- }, _callee6, this);
1654
- }));
1655
- function fetchMissingData(_x3) {
1656
- return _fetchMissingData.apply(this, arguments);
1657
- }
1658
- return fetchMissingData;
1659
- }();
1660
- _proto.maybeReportClientSideFetch = function maybeReportClientSideFetch(mkMsg) {
1661
- if (isBrowser && this.opts.onClientSideFetch) {
1662
- var msg = mkMsg();
1663
- if (this.opts.onClientSideFetch === 'warn') {
1664
- console.warn(msg);
1665
- } else {
1666
- throw new Error(msg);
1667
- }
1668
- }
1669
- };
1670
- _proto.fetchAllData = /*#__PURE__*/function () {
1671
- var _fetchAllData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
1672
- var _this$onBundleFetched;
1673
- var bundle;
1674
- return runtime_1.wrap(function _callee7$(_context7) {
1675
- while (1) {
1676
- switch (_context7.prev = _context7.next) {
1677
- case 0:
1678
- _context7.next = 2;
1679
- return this.fetcher.fetchAllData();
1680
- case 2:
1681
- bundle = _context7.sent;
1682
- this.tracker.trackFetch();
1683
- this.mergeBundle(bundle);
1684
- (_this$onBundleFetched = this.onBundleFetched) == null ? void 0 : _this$onBundleFetched.call(this);
1685
- return _context7.abrupt("return", bundle);
1686
- case 7:
1687
- case "end":
1688
- return _context7.stop();
1689
- }
1690
- }
1691
- }, _callee7, this);
1692
- }));
1693
- function fetchAllData() {
1694
- return _fetchAllData.apply(this, arguments);
1695
- }
1696
- return fetchAllData;
1697
- }();
1698
- _proto.mergeBundle = function mergeBundle(bundle) {
1699
- var _this$onBundleMerged;
1700
- this.bundle = mergeBundles(bundle, this.bundle);
1701
- (_this$onBundleMerged = this.onBundleMerged) == null ? void 0 : _this$onBundleMerged.call(this);
1702
- };
1703
- _proto.getBundle = function getBundle() {
1704
- return this.bundle;
1705
- };
1706
- _proto.clearCache = function clearCache() {
1707
- this.bundle = {
1708
- modules: {
1709
- browser: [],
1710
- server: []
1711
- },
1712
- components: [],
1713
- globalGroups: [],
1714
- external: [],
1715
- projects: [],
1716
- activeSplits: []
1717
- };
1718
- };
1719
- return ReactServerPlasmicComponentLoader;
1720
- }();
1721
- function parseFetchComponentDataArgs() {
1722
- var specs;
1723
- var opts;
1724
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1725
- args[_key2] = arguments[_key2];
1726
- }
1727
- if (Array.isArray(args[0])) {
1728
- specs = args[0];
1729
- opts = args[1];
1730
- } else {
1731
- specs = args;
1732
- opts = undefined;
1733
- }
1734
- return {
1735
- specs: specs,
1736
- opts: opts
1737
- };
1738
- }
1739
-
1740
- var SUBSTITUTED_COMPONENTS = {};
1741
- var REGISTERED_CODE_COMPONENT_HELPERS = {};
1742
- var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
1743
- var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1744
- function InternalPlasmicComponentLoader(opts) {
1745
- var _this = this;
1746
- this.opts = opts;
1747
- this.registry = new Registry();
1748
- this.subs = [];
1749
- this.roots = [];
1750
- this.globalVariants = [];
1751
- this.tracker = new PlasmicTracker({
1752
- projectIds: opts.projects.map(function (p) {
1753
- return p.id;
1754
- }),
1755
- platform: opts.platform,
1756
- preview: opts.preview
1757
- });
1758
- this.reactServerLoader = new ReactServerPlasmicComponentLoader({
1759
- opts: opts,
1760
- fetcher: new PlasmicModulesFetcher(opts),
1761
- tracker: this.tracker,
1762
- onBundleMerged: function onBundleMerged() {
1763
- _this.refreshRegistry();
1764
- },
1765
- onBundleFetched: function onBundleFetched() {
1766
- _this.roots.forEach(function (watcher) {
1767
- return watcher.onDataFetched == null ? void 0 : watcher.onDataFetched();
1768
- });
1769
- }
1770
- });
1771
- this.registerModules({
1772
- react: React__default,
1773
- 'react-dom': ReactDOM,
1774
- 'react/jsx-runtime': jsxRuntime,
1775
- 'react/jsx-dev-runtime': jsxDevRuntime,
1776
- // Also inject @plasmicapp/query and @plasmicapp/host to use the
1777
- // same contexts here and in loader-downloaded code.
1778
- '@plasmicapp/query': PlasmicQuery,
1779
- '@plasmicapp/data-sources-context': PlasmicDataSourcesContext,
1780
- '@plasmicapp/host': PlasmicHost,
1781
- '@plasmicapp/loader-runtime-registry': {
1782
- components: SUBSTITUTED_COMPONENTS,
1783
- globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
1784
- codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS
1785
- }
1786
- });
1787
- }
1788
- var _proto = InternalPlasmicComponentLoader.prototype;
1789
- _proto.getBundle = function getBundle() {
1790
- return this.reactServerLoader.getBundle();
1791
- };
1792
- _proto.setGlobalVariants = function setGlobalVariants(globalVariants) {
1793
- this.globalVariants = globalVariants;
1794
- };
1795
- _proto.getGlobalVariants = function getGlobalVariants() {
1796
- return this.globalVariants;
1797
- };
1798
- _proto.registerModules = function registerModules(modules) {
1799
- var _this2 = this;
1800
- if (Object.keys(modules).some(function (name) {
1801
- return _this2.registry.getRegisteredModule(name) !== modules[name];
1802
- })) {
1803
- if (!this.registry.isEmpty()) {
1804
- console.warn('Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over.');
1805
- this.registry.clear();
1806
- }
1807
- for (var _i = 0, _Object$keys = Object.keys(modules); _i < _Object$keys.length; _i++) {
1808
- var key = _Object$keys[_i];
1809
- this.registry.register(key, modules[key]);
1810
- }
1811
- }
1812
- };
1813
- _proto.substituteComponent = function substituteComponent(component, name) {
1814
- this.internalSubstituteComponent(component, name, undefined);
1815
- };
1816
- _proto.internalSubstituteComponent = function internalSubstituteComponent(component, name, codeComponentHelpers) {
1817
- if (!this.registry.isEmpty()) {
1818
- console.warn('Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over.');
1819
- this.registry.clear();
1820
- }
1821
- this.subs.push({
1822
- lookup: name,
1823
- component: component,
1824
- codeComponentHelpers: codeComponentHelpers
1825
- });
1826
- };
1827
- _proto.registerComponent = function registerComponent$1(component, meta) {
1828
- var _meta$states, _meta$importPath;
1829
- // making the component meta consistent between codegen and loader
1830
- var stateHelpers = Object.fromEntries(Object.entries((_meta$states = meta.states) != null ? _meta$states : {}).filter(function (_ref) {
1831
- var stateSpec = _ref[1];
1832
- return 'initFunc' in stateSpec || 'onChangeArgsToValue' in stateSpec;
1833
- }).map(function (_ref2) {
1834
- var stateName = _ref2[0],
1835
- stateSpec = _ref2[1];
1836
- return [stateName, _extends({}, 'initFunc' in stateSpec ? {
1837
- initFunc: stateSpec.initFunc
1838
- } : {}, 'onChangeArgsToValue' in stateSpec ? {
1839
- onChangeArgsToValue: stateSpec.onChangeArgsToValue
1840
- } : {})];
1841
- }));
1842
- var helpers = {
1843
- states: stateHelpers
1844
- };
1845
- this.internalSubstituteComponent(component, {
1846
- name: meta.name,
1847
- isCode: true
1848
- }, Object.keys(stateHelpers).length > 0 ? helpers : undefined);
1849
- registerComponent(component, _extends({}, meta, {
1850
- // Import path is not used as we will use component substitution
1851
- importPath: (_meta$importPath = meta.importPath) != null ? _meta$importPath : ''
1852
- }, Object.keys(stateHelpers).length > 0 ? {
1853
- componentHelpers: {
1854
- helpers: helpers,
1855
- importPath: '',
1856
- importName: ''
1857
- }
1858
- } : {}));
1859
- };
1860
- _proto.registerGlobalContext = function registerGlobalContext$1(context, meta) {
1861
- var _meta$importPath2;
1862
- this.substituteComponent(context, {
1863
- name: meta.name,
1864
- isCode: true
1865
- });
1866
- // Import path is not used as we will use component substitution
1867
- registerGlobalContext(context, _extends({}, meta, {
1868
- importPath: (_meta$importPath2 = meta.importPath) != null ? _meta$importPath2 : ''
1869
- }));
1870
- };
1871
- _proto.registerTrait = function registerTrait$1(trait, meta) {
1872
- registerTrait(trait, meta);
1873
- };
1874
- _proto.registerToken = function registerToken$1(token) {
1875
- registerToken(token);
1876
- };
1877
- _proto.registerPrefetchedBundle = function registerPrefetchedBundle(bundle) {
1878
- // For React Server Components (Next.js 13+),
1879
- // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.
1880
- // We don't want to pass them via normal page props because that will be serialized to the browser.
1881
- // Instead, we pass the bundle (including the server modules) via the Node `global` variable.
1882
- //
1883
- // This is the code that reads the stored bundle and merges it back into the loader.
1884
- if (!isBrowser) {
1885
- // Check if we have a cached bundle on this Node server.
1886
- var cachedBundle = internal_getCachedBundleInNodeServer(this.opts);
1887
- if (cachedBundle) {
1888
- // If it's there, merge the cached bundle first.
1889
- this.reactServerLoader.mergeBundle(cachedBundle);
1890
- }
1891
- }
1892
- this.reactServerLoader.mergeBundle(bundle);
1893
- };
1894
- _proto.subscribePlasmicRoot = function subscribePlasmicRoot(watcher) {
1895
- this.roots.push(watcher);
1896
- };
1897
- _proto.unsubscribePlasmicRoot = function unsubscribePlasmicRoot(watcher) {
1898
- var index = this.roots.indexOf(watcher);
1899
- if (index >= 0) {
1900
- this.roots.splice(index, 1);
1901
- }
1902
- };
1903
- _proto.clearCache = function clearCache() {
1904
- this.reactServerLoader.clearCache();
1905
- this.registry.clear();
1906
- };
1907
- _proto.getLookup = function getLookup() {
1908
- return new ComponentLookup(this.getBundle(), this.registry);
1909
- };
1910
- _proto.maybeFetchComponentData = function maybeFetchComponentData() {
1911
- var _this$reactServerLoad;
1912
- return (_this$reactServerLoad = this.reactServerLoader).maybeFetchComponentData.apply(_this$reactServerLoad, arguments);
1913
- };
1914
- _proto.fetchComponentData = function fetchComponentData() {
1915
- var _this$reactServerLoad2;
1916
- return (_this$reactServerLoad2 = this.reactServerLoader).fetchComponentData.apply(_this$reactServerLoad2, arguments);
1917
- };
1918
- _proto.fetchPages = function fetchPages(opts) {
1919
- return this.reactServerLoader.fetchPages(opts);
1920
- };
1921
- _proto.fetchComponents = function fetchComponents() {
1922
- return this.reactServerLoader.fetchComponents();
1923
- };
1924
- _proto.getActiveSplits = function getActiveSplits() {
1925
- return this.reactServerLoader.getActiveSplits();
1926
- };
1927
- _proto.trackConversion = function trackConversion(value) {
1928
- if (value === void 0) {
1929
- value = 0;
1930
- }
1931
- this.tracker.trackConversion(value);
1932
- };
1933
- _proto.getActiveVariation = /*#__PURE__*/function () {
1934
- var _getActiveVariation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(opts) {
1935
- return runtime_1.wrap(function _callee$(_context) {
1936
- while (1) {
1937
- switch (_context.prev = _context.next) {
1938
- case 0:
1939
- _context.next = 2;
1940
- return this.reactServerLoader.fetchComponents();
1941
- case 2:
1942
- return _context.abrupt("return", getActiveVariation(_extends({}, opts, {
1943
- splits: this.getBundle().activeSplits
1944
- })));
1945
- case 3:
1946
- case "end":
1947
- return _context.stop();
1948
- }
1949
- }
1950
- }, _callee, this);
1951
- }));
1952
- function getActiveVariation$1(_x) {
1953
- return _getActiveVariation2.apply(this, arguments);
1954
- }
1955
- return getActiveVariation$1;
1956
- }();
1957
- _proto.getTeamIds = function getTeamIds() {
1958
- return uniq(this.getBundle().projects.map(function (p) {
1959
- return p.teamId ? "" + p.teamId + (p.indirect ? '@indirect' : '') : null;
1960
- }).filter(function (x) {
1961
- return !!x;
1962
- }));
1963
- };
1964
- _proto.getProjectIds = function getProjectIds() {
1965
- return uniq(this.getBundle().projects.map(function (p) {
1966
- return "" + p.id + (p.indirect ? '@indirect' : '');
1967
- }));
1968
- };
1969
- _proto.trackRender = function trackRender(opts) {
1970
- this.tracker.trackRender(opts);
1971
- };
1972
- _proto.refreshRegistry = function refreshRegistry() {
1973
- var _this3 = this;
1974
- var _loop = function _loop() {
1975
- var sub = _step.value;
1976
- var metas = getCompMetas(_this3.getBundle().components, sub.lookup);
1977
- metas.forEach(function (meta) {
1978
- SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
1979
- if (sub.codeComponentHelpers) {
1980
- REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
1981
- }
1982
- });
1983
- };
1984
- // Once we have received data, we register components to
1985
- // substitute. We had to wait for data to do this so
1986
- // that we can look up the right module name to substitute
1987
- // in component meta.
1988
- for (var _iterator = _createForOfIteratorHelperLoose(this.subs), _step; !(_step = _iterator()).done;) {
1989
- _loop();
1990
- }
1991
- // We also swap global variants' useXXXGlobalVariant() hook with
1992
- // a fake one that just reads from the PlasmicRootContext. Because
1993
- // global variant values are not supplied by the generated global variant
1994
- // context providers, but instead by <PlasmicRootProvider/> and by
1995
- // PlasmicComponentLoader.setGlobalVariants(), we redirect these
1996
- // hooks to read from them instead.
1997
- for (var _iterator2 = _createForOfIteratorHelperLoose(this.getBundle().globalGroups), _step2; !(_step2 = _iterator2()).done;) {
1998
- var globalGroup = _step2.value;
1999
- if (globalGroup.type !== 'global-screen') {
2000
- SUBSTITUTED_GLOBAL_VARIANT_HOOKS[globalGroup.id] = createUseGlobalVariant(globalGroup.name, globalGroup.projectId);
2001
- }
2002
- }
2003
- this.registry.updateModules(this.getBundle());
2004
- };
2005
- return InternalPlasmicComponentLoader;
2006
- }();
2007
- /**
2008
- * Library for fetching component data, and registering
2009
- * custom components.
2010
- */
2011
- var PlasmicComponentLoader = /*#__PURE__*/function () {
2012
- function PlasmicComponentLoader(internal) {
2013
- this.warnedRegisterComponent = false;
2014
- this.__internal = internal;
2015
- }
2016
- /**
2017
- * Sets global variants to be used for all components. Note that
2018
- * this is not reactive, and will not re-render all components
2019
- * already mounted; instead, it should be used to activate global
2020
- * variants that should always be activated for the lifetime of this
2021
- * app. If you'd like to reactively change the global variants,
2022
- * you should specify them via <PlasmicRootProvider />
2023
- */
2024
- var _proto2 = PlasmicComponentLoader.prototype;
2025
- _proto2.setGlobalVariants = function setGlobalVariants(globalVariants) {
2026
- this.__internal.setGlobalVariants(globalVariants);
2027
- };
2028
- _proto2.registerModules = function registerModules(modules) {
2029
- this.__internal.registerModules(modules);
2030
- }
2031
- /**
2032
- * Register custom components that should be swapped in for
2033
- * components defined in your project. You can use this to
2034
- * swap in / substitute a Plasmic component with a "real" component.
2035
- */;
2036
- _proto2.substituteComponent = function substituteComponent(component, name) {
2037
- this.__internal.substituteComponent(component, name);
2038
- };
2039
- _proto2.registerComponent = function registerComponent(component, metaOrName) {
2040
- // 'props' is a required field in CodeComponentMeta
2041
- if (metaOrName && typeof metaOrName === 'object' && 'props' in metaOrName) {
2042
- this.__internal.registerComponent(component, metaOrName);
2043
- } else {
2044
- // Deprecated call
2045
- if (process.env.NODE_ENV === 'development' && !this.warnedRegisterComponent) {
2046
- console.warn("PlasmicLoader: Using deprecated method `registerComponent` for component substitution. " + "Please consider using `substituteComponent` instead.");
2047
- this.warnedRegisterComponent = true;
2048
- }
2049
- this.substituteComponent(component, metaOrName);
2050
- }
2051
- };
2052
- _proto2.registerGlobalContext = function registerGlobalContext(context, meta) {
2053
- this.__internal.registerGlobalContext(context, meta);
2054
- };
2055
- _proto2.registerTrait = function registerTrait(trait, meta) {
2056
- this.__internal.registerTrait(trait, meta);
2057
- };
2058
- _proto2.registerToken = function registerToken(token) {
2059
- this.__internal.registerToken(token);
2060
- }
2061
- /**
2062
- * Pre-fetches component data needed to for PlasmicLoader to render
2063
- * these components. Should be passed into PlasmicRootProvider as
2064
- * the prefetchedData prop.
2065
- *
2066
- * You can look up a component either by:
2067
- * - the name of the component
2068
- * - the path for a page component
2069
- * - an array of strings that make up parts of the path
2070
- * - object { name: "name_or_path", projectId: ...}, to specify which project
2071
- * to use, if multiple projects have the same component name
2072
- *
2073
- * Throws an Error if a specified component to fetch does not exist in
2074
- * the Plasmic project.
2075
- */;
2076
- _proto2.fetchComponentData =
2077
- /*#__PURE__*/
2078
- function () {
2079
- var _fetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
2080
- var _this$__internal;
2081
- var _args2 = arguments;
2082
- return runtime_1.wrap(function _callee2$(_context2) {
2083
- while (1) {
2084
- switch (_context2.prev = _context2.next) {
2085
- case 0:
2086
- return _context2.abrupt("return", (_this$__internal = this.__internal).fetchComponentData.apply(_this$__internal, _args2));
2087
- case 1:
2088
- case "end":
2089
- return _context2.stop();
2090
- }
2091
- }
2092
- }, _callee2, this);
2093
- }));
2094
- function fetchComponentData() {
2095
- return _fetchComponentData.apply(this, arguments);
2096
- }
2097
- return fetchComponentData;
2098
- }()
2099
- /**
2100
- * Like fetchComponentData(), but returns null instead of throwing an Error
2101
- * when a component is not found. Useful when you are implementing a catch-all
2102
- * page and want to check if a specific path had been defined for Plasmic.
2103
- */
2104
- ;
2105
- _proto2.maybeFetchComponentData =
2106
- /*#__PURE__*/
2107
- function () {
2108
- var _maybeFetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
2109
- var _this$__internal2;
2110
- var _args3 = arguments;
2111
- return runtime_1.wrap(function _callee3$(_context3) {
2112
- while (1) {
2113
- switch (_context3.prev = _context3.next) {
2114
- case 0:
2115
- return _context3.abrupt("return", (_this$__internal2 = this.__internal).maybeFetchComponentData.apply(_this$__internal2, _args3));
2116
- case 1:
2117
- case "end":
2118
- return _context3.stop();
2119
- }
2120
- }
2121
- }, _callee3, this);
2122
- }));
2123
- function maybeFetchComponentData() {
2124
- return _maybeFetchComponentData.apply(this, arguments);
2125
- }
2126
- return maybeFetchComponentData;
2127
- }()
2128
- /**
2129
- * Returns all the page component metadata for these projects.
2130
- */
2131
- ;
2132
- _proto2.fetchPages =
2133
- /*#__PURE__*/
2134
- function () {
2135
- var _fetchPages = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(opts) {
2136
- return runtime_1.wrap(function _callee4$(_context4) {
2137
- while (1) {
2138
- switch (_context4.prev = _context4.next) {
2139
- case 0:
2140
- return _context4.abrupt("return", this.__internal.fetchPages(opts));
2141
- case 1:
2142
- case "end":
2143
- return _context4.stop();
2144
- }
2145
- }
2146
- }, _callee4, this);
2147
- }));
2148
- function fetchPages(_x2) {
2149
- return _fetchPages.apply(this, arguments);
2150
- }
2151
- return fetchPages;
2152
- }()
2153
- /**
2154
- * Returns all components metadata for these projects.
2155
- */
2156
- ;
2157
- _proto2.fetchComponents =
2158
- /*#__PURE__*/
2159
- function () {
2160
- var _fetchComponents = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
2161
- return runtime_1.wrap(function _callee5$(_context5) {
2162
- while (1) {
2163
- switch (_context5.prev = _context5.next) {
2164
- case 0:
2165
- return _context5.abrupt("return", this.__internal.fetchComponents());
2166
- case 1:
2167
- case "end":
2168
- return _context5.stop();
2169
- }
2170
- }
2171
- }, _callee5, this);
2172
- }));
2173
- function fetchComponents() {
2174
- return _fetchComponents.apply(this, arguments);
2175
- }
2176
- return fetchComponents;
2177
- }();
2178
- _proto2._getActiveVariation = /*#__PURE__*/function () {
2179
- var _getActiveVariation3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(opts) {
2180
- return runtime_1.wrap(function _callee6$(_context6) {
2181
- while (1) {
2182
- switch (_context6.prev = _context6.next) {
2183
- case 0:
2184
- return _context6.abrupt("return", this.__internal.getActiveVariation(opts));
2185
- case 1:
2186
- case "end":
2187
- return _context6.stop();
2188
- }
2189
- }
2190
- }, _callee6, this);
2191
- }));
2192
- function _getActiveVariation(_x3) {
2193
- return _getActiveVariation3.apply(this, arguments);
2194
- }
2195
- return _getActiveVariation;
2196
- }();
2197
- _proto2.getActiveVariation = /*#__PURE__*/function () {
2198
- var _getActiveVariation4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(opts) {
2199
- return runtime_1.wrap(function _callee7$(_context7) {
2200
- while (1) {
2201
- switch (_context7.prev = _context7.next) {
2202
- case 0:
2203
- return _context7.abrupt("return", this._getActiveVariation({
2204
- traits: opts.traits,
2205
- getKnownValue: function getKnownValue(key) {
2206
- if (opts.known) {
2207
- return opts.known[key];
2208
- } else {
2209
- var cookies = getPlasmicCookieValues();
2210
- return cookies[key];
2211
- }
2212
- },
2213
- updateKnownValue: function updateKnownValue(key, value) {
2214
- if (!opts.known) {
2215
- updatePlasmicCookieValue(key, value);
2216
- }
2217
- }
2218
- }));
2219
- case 1:
2220
- case "end":
2221
- return _context7.stop();
2222
- }
2223
- }
2224
- }, _callee7, this);
2225
- }));
2226
- function getActiveVariation(_x4) {
2227
- return _getActiveVariation4.apply(this, arguments);
2228
- }
2229
- return getActiveVariation;
2230
- }();
2231
- _proto2.getExternalVariation = function getExternalVariation(variation) {
2232
- return getExternalIds(this.getActiveSplits(), variation);
2233
- };
2234
- _proto2.getActiveSplits = function getActiveSplits() {
2235
- return this.__internal.getActiveSplits();
2236
- };
2237
- _proto2.trackConversion = function trackConversion(value) {
2238
- if (value === void 0) {
2239
- value = 0;
2240
- }
2241
- this.__internal.trackConversion(value);
2242
- };
2243
- _proto2.clearCache = function clearCache() {
2244
- return this.__internal.clearCache();
2245
- };
2246
- return PlasmicComponentLoader;
2247
- }();
2248
-
2249
- /**
2250
- * Hook that fetches and returns a React component for rendering the argument
2251
- * Plasmic component. Returns undefined if the component data is still
2252
- * being fetched.
2253
- *
2254
- * @param opts.forceOriginal if you used PlasmicComponentLoader.registerComponent,
2255
- * then normally usePlasmicComponent will return the registered component.
2256
- * You can set forceOriginal to true if you want to return the Plasmic-generated
2257
- * component instead.
2258
- */
2259
- function usePlasmicComponent(spec, opts) {
2260
- if (opts === void 0) {
2261
- opts = {};
2262
- }
2263
- var rootContext = usePlasmicRootContext();
2264
- if (!rootContext) {
2265
- throw new Error("You can only use usePlasmicComponent if wrapped in <PlasmicRootProvider />");
2266
- }
2267
- var loader = rootContext.loader;
2268
- var lookup = loader.getLookup();
2269
- var component = lookup.hasComponent(spec) ? lookup.getComponent(spec, opts) : undefined;
2270
- var stableSpec = useStableLookupSpec(spec);
2271
- var isMounted = useIsMounted();
2272
- var forceUpdate = useForceUpdate();
2273
- useEffect(function () {
2274
- if (!component) {
2275
- _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2276
- return runtime_1.wrap(function _callee$(_context) {
2277
- while (1) {
2278
- switch (_context.prev = _context.next) {
2279
- case 0:
2280
- _context.next = 2;
2281
- return loader.fetchComponentData(stableSpec);
2282
- case 2:
2283
- if (isMounted()) {
2284
- forceUpdate();
2285
- }
2286
- case 3:
2287
- case "end":
2288
- return _context.stop();
2289
- }
2290
- }
2291
- }, _callee);
2292
- }))();
2293
- }
2294
- }, [component, stableSpec]);
2295
- return component;
2296
- }
2297
-
2298
- var _excluded = ["loader", "globalContextsProps", "variation", "userAuthToken", "isUserLoading", "authRedirectUri"];
2299
- var PlasmicComponentContext = /*#__PURE__*/createContext(false);
2300
- function PlasmicComponent(props) {
2301
- var component = props.component,
2302
- projectId = props.projectId,
2303
- componentProps = props.componentProps,
2304
- forceOriginal = props.forceOriginal;
2305
- var rootContext = usePlasmicRootContext();
2306
- var isRootLoader = !useContext(PlasmicComponentContext);
2307
- if (!rootContext) {
2308
- // no existing PlasmicRootProvider
2309
- throw new Error("You must use <PlasmicRootProvider/> at the root of your app");
2310
- }
2311
- var loader = rootContext.loader,
2312
- globalContextsProps = rootContext.globalContextsProps,
2313
- variation = rootContext.variation,
2314
- userAuthToken = rootContext.userAuthToken,
2315
- isUserLoading = rootContext.isUserLoading,
2316
- authRedirectUri = rootContext.authRedirectUri,
2317
- rest = _objectWithoutPropertiesLoose(rootContext, _excluded);
2318
- var Component = usePlasmicComponent({
2319
- name: component,
2320
- projectId: projectId,
2321
- isCode: false
2322
- }, {
2323
- forceOriginal: forceOriginal
2324
- });
2325
- useEffect(function () {
2326
- if (isRootLoader) {
2327
- var meta = loader.getLookup().getComponentMeta({
2328
- name: component,
2329
- projectId: projectId
2330
- });
2331
- if (meta) {
2332
- loader.trackRender({
2333
- renderCtx: {
2334
- rootProjectId: meta.projectId,
2335
- rootComponentId: meta.id,
2336
- rootComponentName: component,
2337
- teamIds: loader.getTeamIds(),
2338
- projectIds: loader.getProjectIds()
2339
- },
2340
- variation: variation
2341
- });
2342
- }
2343
- }
2344
- }, [component, projectId, loader, variation]);
2345
- var element = useMemo(function () {
2346
- if (!Component) {
2347
- return null;
2348
- }
2349
- var element = createElement(Component, Object.assign({}, componentProps));
2350
- if (isRootLoader) {
2351
- // If this is the root PlasmicComponent, then wrap the content with the
2352
- // react-web's PlasmicRootProvider. We are doing this here, instead of
2353
- // say PlasmicRootProvider, because we don't have access to this context
2354
- // provider until data has been loaded. If we insert this provider into
2355
- // the tree at the root after data is loaded, then we'll invalidate the
2356
- // React tree and tree state, which is bad. Instead, we do it at the
2357
- // "root-most PlasmicComponent"; we won't risk invalidating the sub-tree
2358
- // here because there were no children before the data came in.
2359
- var lookup = loader.getLookup();
2360
- var ReactWebRootProvider = lookup.getRootProvider();
2361
- var GlobalContextsProvider = lookup.getGlobalContextsProvider({
2362
- name: component,
2363
- projectId: projectId
2364
- });
2365
- element = createElement(ReactWebRootProvider, Object.assign({}, rest, {
2366
- userAuthToken: userAuthToken,
2367
- isUserLoading: isUserLoading,
2368
- authRedirectUri: authRedirectUri
2369
- }), createElement(MaybeWrap, {
2370
- cond: !!GlobalContextsProvider,
2371
- wrapper: function wrapper(children) {
2372
- return createElement(GlobalContextsProvider, Object.assign({}, globalContextsProps), children);
2373
- }
2374
- }, createElement(PlasmicComponentContext.Provider, {
2375
- value: true
2376
- }, element)));
2377
- }
2378
- return element;
2379
- }, [Component, componentProps, loader, isRootLoader, component, projectId, globalContextsProps, userAuthToken, isUserLoading, authRedirectUri]);
2380
- return element;
2381
- }
2382
- function MaybeWrap(props) {
2383
- return props.cond ? props.wrapper(props.children) : props.children;
2384
- }
2385
-
2386
- /**
2387
- * Performs a prepass over Plasmic content, kicking off the necessary
2388
- * data fetches, and populating the fetched data into a cache. This
2389
- * cache can be passed as prefetchedQueryData into PlasmicRootProvider.
2390
- *
2391
- * To limit rendering errors that can occur when you do this, we recommend
2392
- * that you pass in _only_ the PlasmicComponents that you are planning to use
2393
- * as the argument. For example:
2394
- *
2395
- * const cache = await extractPlasmicQueryData(
2396
- * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
2397
- * <PlasmicComponent component="Home" componentProps={{
2398
- * // Specify the component prop overrides you are planning to use
2399
- * // to render the page, as they may change what data is fetched.
2400
- * ...
2401
- * }} />
2402
- * <PlasmicComponent component="NavBar" componentProps={{
2403
- * ...
2404
- * }} />
2405
- * ...
2406
- * </PlasmicRootProvider>
2407
- * );
2408
- *
2409
- * If your PlasmicComponent will be wrapping components that require special
2410
- * context set up, you should also wrap the element above with those context
2411
- * providers.
2412
- *
2413
- * You should avoid passing in elements that are not related to Plasmic, as any
2414
- * rendering errors from those elements during the prepass may result in data
2415
- * not being populated in the cache.
2416
- *
2417
- * @param element a React element containing instances of PlasmicComponent.
2418
- * Will attempt to satisfy all data needs from usePlasmicDataQuery()
2419
- * in this element tree.
2420
- * @returns an object mapping query key to fetched data
2421
- */
2422
- function extractPlasmicQueryData(_x) {
2423
- return _extractPlasmicQueryData.apply(this, arguments);
2424
- }
2425
- /**
2426
- * Runs react-ssr-prepass on `element`, while isolating rendering errors
2427
- * as much as possible for each PlasmicComponent instance.
2428
- */
2429
- function _extractPlasmicQueryData() {
2430
- _extractPlasmicQueryData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(element) {
2431
- var cache, queryCache;
2432
- return runtime_1.wrap(function _callee$(_context) {
2433
- while (1) {
2434
- switch (_context.prev = _context.next) {
2435
- case 0:
2436
- cache = new Map();
2437
- _context.prev = 1;
2438
- _context.next = 4;
2439
- return plasmicPrepass(React__default.createElement(PlasmicPrepassContext, {
2440
- cache: cache
2441
- }, element));
2442
- case 4:
2443
- _context.next = 9;
2444
- break;
2445
- case 6:
2446
- _context.prev = 6;
2447
- _context.t0 = _context["catch"](1);
2448
- console.warn("PLASMIC: Error encountered while pre-rendering", _context.t0);
2449
- case 9:
2450
- queryCache = Object.fromEntries(Array.from(cache.entries()).filter(function (_ref3) {
2451
- var key = _ref3[0],
2452
- val = _ref3[1];
2453
- return !key.startsWith('$swr$') && val !== undefined;
2454
- }));
2455
- _context.prev = 10;
2456
- return _context.abrupt("return", JSON.parse(JSON.stringify(queryCache, function (key, value) {
2457
- return value !== undefined ? value : null;
2458
- })));
2459
- case 14:
2460
- _context.prev = 14;
2461
- _context.t1 = _context["catch"](10);
2462
- return _context.abrupt("return", queryCache);
2463
- case 17:
2464
- case "end":
2465
- return _context.stop();
2466
- }
2467
- }
2468
- }, _callee, null, [[1, 6], [10, 14]]);
2469
- }));
2470
- return _extractPlasmicQueryData.apply(this, arguments);
2471
- }
2472
- function plasmicPrepass(_x2) {
2473
- return _plasmicPrepass.apply(this, arguments);
2474
- }
2475
- /**
2476
- * Returns a clone of the element tree, where componentProps of PlasmicComponent
2477
- * has been processed such that any React elements found are wrapped in
2478
- * an error boundary. Makes it possible to isolate rendering errors while still
2479
- * finishing as much data fetched as possible.
2480
- */
2481
- function _plasmicPrepass() {
2482
- _plasmicPrepass = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(element) {
2483
- return runtime_1.wrap(function _callee2$(_context2) {
2484
- while (1) {
2485
- switch (_context2.prev = _context2.next) {
2486
- case 0:
2487
- _context2.next = 2;
2488
- return prepass(buildPlasmicPrepassElement(element));
2489
- case 2:
2490
- case "end":
2491
- return _context2.stop();
2492
- }
2493
- }
2494
- }, _callee2);
2495
- }));
2496
- return _plasmicPrepass.apply(this, arguments);
2497
- }
2498
- function buildPlasmicPrepassElement(element) {
2499
- return React__default.createElement(GenericErrorBoundary, null, processReactElement(element));
2500
- }
2501
- function processReactElement(element) {
2502
- if (element.type === PlasmicComponent) {
2503
- return React__default.cloneElement(element, processPlasmicComponentProps(element.props));
2504
- } else {
2505
- return React__default.cloneElement(element, processComponentProps(element.props));
2506
- }
2507
- }
2508
- function processComponentProps(props) {
2509
- if (!props || typeof props !== 'object') {
2510
- return props;
2511
- }
2512
- return Object.fromEntries(Object.entries(props).map(function (_ref) {
2513
- var k = _ref[0],
2514
- v = _ref[1];
2515
- return [k, React__default.isValidElement(v) ? processReactElement(v) : v];
2516
- }));
2517
- }
2518
- var GenericErrorBoundary = /*#__PURE__*/function (_React$Component) {
2519
- _inheritsLoose(GenericErrorBoundary, _React$Component);
2520
- function GenericErrorBoundary(props) {
2521
- return _React$Component.call(this, props) || this;
2522
- }
2523
- var _proto = GenericErrorBoundary.prototype;
2524
- _proto.componentDidCatch = function componentDidCatch(error) {
2525
- console.log("Plasmic: Encountered error while prepass rendering:", error);
2526
- };
2527
- _proto.render = function render() {
2528
- return React__default.createElement(React__default.Fragment, null, this.props.children);
2529
- };
2530
- return GenericErrorBoundary;
2531
- }(React__default.Component);
2532
- /**
2533
- * To process the componentProps passed to PlasmicComponent, wrap any
2534
- * React element we find in <GenericErrorBoundary />.
2535
- */
2536
- function processPlasmicComponentProps(x) {
2537
- if (!x) {
2538
- return x;
2539
- } else if (isFragment(x)) {
2540
- return React__default.createElement(React__default.Fragment, null, React__default.Children.map(x.props.children, processPlasmicComponentProps));
2541
- } else if (React__default.isValidElement(x)) {
2542
- return React__default.createElement(GenericErrorBoundary, null, x);
2543
- } else if (Array.isArray(x)) {
2544
- return x.map(processPlasmicComponentProps);
2545
- } else if (isLiteralObject(x)) {
2546
- return Object.fromEntries(Object.entries(x).map(function (_ref2) {
2547
- var key = _ref2[0],
2548
- val = _ref2[1];
2549
- return [key, processPlasmicComponentProps(val)];
2550
- }));
2551
- } else {
2552
- return x;
2553
- }
2554
- }
2555
- function isLiteralObject(obj) {
2556
- return !!obj && typeof obj === 'object' && obj.constructor === Object;
2557
- }
2558
-
2559
- function renderToElement(_x, _x2, _x3, _x4) {
2560
- return _renderToElement.apply(this, arguments);
2561
- }
2562
- function _renderToElement() {
2563
- _renderToElement = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(loader, target, lookup, opts) {
2564
- return runtime_1.wrap(function _callee$(_context) {
2565
- while (1) {
2566
- switch (_context.prev = _context.next) {
2567
- case 0:
2568
- if (opts === void 0) {
2569
- opts = {};
2570
- }
2571
- return _context.abrupt("return", new Promise(function (resolve) {
2572
- var element = makeElement(loader, lookup, opts);
2573
- ReactDOM.render(element, target, function () {
2574
- return resolve();
2575
- });
2576
- }));
2577
- case 2:
2578
- case "end":
2579
- return _context.stop();
2580
- }
2581
- }
2582
- }, _callee);
2583
- }));
2584
- return _renderToElement.apply(this, arguments);
2585
- }
2586
- function renderToString(loader, lookup, opts) {
2587
- if (opts === void 0) {
2588
- opts = {};
2589
- }
2590
- var element = makeElement(loader, lookup, opts);
2591
- return renderToString$1(element);
2592
- }
2593
- function extractPlasmicQueryDataFromElement(_x5, _x6, _x7) {
2594
- return _extractPlasmicQueryDataFromElement.apply(this, arguments);
2595
- }
2596
- function _extractPlasmicQueryDataFromElement() {
2597
- _extractPlasmicQueryDataFromElement = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(loader, lookup, opts) {
2598
- var element;
2599
- return runtime_1.wrap(function _callee2$(_context2) {
2600
- while (1) {
2601
- switch (_context2.prev = _context2.next) {
2602
- case 0:
2603
- if (opts === void 0) {
2604
- opts = {};
2605
- }
2606
- element = makeElement(loader, lookup, opts);
2607
- return _context2.abrupt("return", extractPlasmicQueryData(element));
2608
- case 3:
2609
- case "end":
2610
- return _context2.stop();
2611
- }
2612
- }
2613
- }, _callee2);
2614
- }));
2615
- return _extractPlasmicQueryDataFromElement.apply(this, arguments);
2616
- }
2617
- function hydrateFromElement(_x8, _x9, _x10, _x11) {
2618
- return _hydrateFromElement.apply(this, arguments);
2619
- }
2620
- function _hydrateFromElement() {
2621
- _hydrateFromElement = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(loader, target, lookup, opts) {
2622
- return runtime_1.wrap(function _callee3$(_context3) {
2623
- while (1) {
2624
- switch (_context3.prev = _context3.next) {
2625
- case 0:
2626
- if (opts === void 0) {
2627
- opts = {};
2628
- }
2629
- return _context3.abrupt("return", new Promise(function (resolve) {
2630
- var element = makeElement(loader, lookup, opts);
2631
- ReactDOM.hydrate(element, target, function () {
2632
- return resolve();
2633
- });
2634
- }));
2635
- case 2:
2636
- case "end":
2637
- return _context3.stop();
2638
- }
2639
- }
2640
- }, _callee3);
2641
- }));
2642
- return _hydrateFromElement.apply(this, arguments);
2643
- }
2644
- function makeElement(loader, lookup, opts) {
2645
- if (opts === void 0) {
2646
- opts = {};
2647
- }
2648
- return React__default.createElement(PlasmicRootProvider, {
2649
- loader: loader,
2650
- prefetchedData: opts.prefetchedData,
2651
- globalVariants: opts.globalVariants,
2652
- prefetchedQueryData: opts.prefetchedQueryData
2653
- }, React__default.createElement(PlasmicComponent, {
2654
- component: typeof lookup === 'string' ? lookup : lookup.name,
2655
- projectId: typeof lookup === 'string' ? undefined : lookup.projectId,
2656
- componentProps: opts.componentProps
2657
- }));
2658
- }
2659
-
2660
- function initPlasmicLoader(opts) {
2661
- var internal = new InternalPlasmicComponentLoader(opts);
2662
- return new PlasmicComponentLoader(internal);
2663
- }
2664
-
2665
- export { InternalPlasmicComponentLoader, PlasmicComponent, PlasmicComponentLoader, PlasmicRootProvider, convertBundlesToComponentRenderData, extractPlasmicQueryData, extractPlasmicQueryDataFromElement, hydrateFromElement, initPlasmicLoader, matchesPagePath, plasmicPrepass, renderToElement, renderToString, usePlasmicComponent };
2666
- //# sourceMappingURL=loader-react.esm.js.map