@plasmicapp/loader-react 1.0.38 → 1.0.39-6.beta

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