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