@plasmicapp/loader-react 1.0.253 → 1.0.255

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