@plasmicpkgs/plasmic-sanity-io 1.0.0

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.
@@ -0,0 +1,1031 @@
1
+ import registerComponent from '@plasmicapp/host/registerComponent';
2
+ import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
3
+ import { DataProvider, repeatedElement, useSelector } from '@plasmicapp/host';
4
+ import { usePlasmicQueryData } from '@plasmicapp/query';
5
+ import sanityClient from '@sanity/client';
6
+ import imageUrlBuilder from '@sanity/image-url';
7
+ import L from 'lodash-es';
8
+ import React, { useContext } from 'react';
9
+
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
+ try {
12
+ var info = gen[key](arg);
13
+ var value = info.value;
14
+ } catch (error) {
15
+ reject(error);
16
+ return;
17
+ }
18
+
19
+ if (info.done) {
20
+ resolve(value);
21
+ } else {
22
+ Promise.resolve(value).then(_next, _throw);
23
+ }
24
+ }
25
+
26
+ function _asyncToGenerator(fn) {
27
+ return function () {
28
+ var self = this,
29
+ args = arguments;
30
+ return new Promise(function (resolve, reject) {
31
+ var gen = fn.apply(self, args);
32
+
33
+ function _next(value) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
+ }
36
+
37
+ function _throw(err) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
+ }
40
+
41
+ _next(undefined);
42
+ });
43
+ };
44
+ }
45
+
46
+ function createCommonjsModule(fn, module) {
47
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
48
+ }
49
+
50
+ var runtime_1 = createCommonjsModule(function (module) {
51
+ /**
52
+ * Copyright (c) 2014-present, Facebook, Inc.
53
+ *
54
+ * This source code is licensed under the MIT license found in the
55
+ * LICENSE file in the root directory of this source tree.
56
+ */
57
+
58
+ var runtime = (function (exports) {
59
+
60
+ var Op = Object.prototype;
61
+ var hasOwn = Op.hasOwnProperty;
62
+ var undefined$1; // More compressible than void 0.
63
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
64
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
65
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
66
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
67
+
68
+ function define(obj, key, value) {
69
+ Object.defineProperty(obj, key, {
70
+ value: value,
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true
74
+ });
75
+ return obj[key];
76
+ }
77
+ try {
78
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
79
+ define({}, "");
80
+ } catch (err) {
81
+ define = function(obj, key, value) {
82
+ return obj[key] = value;
83
+ };
84
+ }
85
+
86
+ function wrap(innerFn, outerFn, self, tryLocsList) {
87
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
88
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
89
+ var generator = Object.create(protoGenerator.prototype);
90
+ var context = new Context(tryLocsList || []);
91
+
92
+ // The ._invoke method unifies the implementations of the .next,
93
+ // .throw, and .return methods.
94
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
95
+
96
+ return generator;
97
+ }
98
+ exports.wrap = wrap;
99
+
100
+ // Try/catch helper to minimize deoptimizations. Returns a completion
101
+ // record like context.tryEntries[i].completion. This interface could
102
+ // have been (and was previously) designed to take a closure to be
103
+ // invoked without arguments, but in all the cases we care about we
104
+ // already have an existing method we want to call, so there's no need
105
+ // to create a new function object. We can even get away with assuming
106
+ // the method takes exactly one argument, since that happens to be true
107
+ // in every case, so we don't have to touch the arguments object. The
108
+ // only additional allocation required is the completion record, which
109
+ // has a stable shape and so hopefully should be cheap to allocate.
110
+ function tryCatch(fn, obj, arg) {
111
+ try {
112
+ return { type: "normal", arg: fn.call(obj, arg) };
113
+ } catch (err) {
114
+ return { type: "throw", arg: err };
115
+ }
116
+ }
117
+
118
+ var GenStateSuspendedStart = "suspendedStart";
119
+ var GenStateSuspendedYield = "suspendedYield";
120
+ var GenStateExecuting = "executing";
121
+ var GenStateCompleted = "completed";
122
+
123
+ // Returning this object from the innerFn has the same effect as
124
+ // breaking out of the dispatch switch statement.
125
+ var ContinueSentinel = {};
126
+
127
+ // Dummy constructor functions that we use as the .constructor and
128
+ // .constructor.prototype properties for functions that return Generator
129
+ // objects. For full spec compliance, you may wish to configure your
130
+ // minifier not to mangle the names of these two functions.
131
+ function Generator() {}
132
+ function GeneratorFunction() {}
133
+ function GeneratorFunctionPrototype() {}
134
+
135
+ // This is a polyfill for %IteratorPrototype% for environments that
136
+ // don't natively support it.
137
+ var IteratorPrototype = {};
138
+ define(IteratorPrototype, iteratorSymbol, function () {
139
+ return this;
140
+ });
141
+
142
+ var getProto = Object.getPrototypeOf;
143
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
144
+ if (NativeIteratorPrototype &&
145
+ NativeIteratorPrototype !== Op &&
146
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
147
+ // This environment has a native %IteratorPrototype%; use it instead
148
+ // of the polyfill.
149
+ IteratorPrototype = NativeIteratorPrototype;
150
+ }
151
+
152
+ var Gp = GeneratorFunctionPrototype.prototype =
153
+ Generator.prototype = Object.create(IteratorPrototype);
154
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
155
+ define(Gp, "constructor", GeneratorFunctionPrototype);
156
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
157
+ GeneratorFunction.displayName = define(
158
+ GeneratorFunctionPrototype,
159
+ toStringTagSymbol,
160
+ "GeneratorFunction"
161
+ );
162
+
163
+ // Helper for defining the .next, .throw, and .return methods of the
164
+ // Iterator interface in terms of a single ._invoke method.
165
+ function defineIteratorMethods(prototype) {
166
+ ["next", "throw", "return"].forEach(function(method) {
167
+ define(prototype, method, function(arg) {
168
+ return this._invoke(method, arg);
169
+ });
170
+ });
171
+ }
172
+
173
+ exports.isGeneratorFunction = function(genFun) {
174
+ var ctor = typeof genFun === "function" && genFun.constructor;
175
+ return ctor
176
+ ? ctor === GeneratorFunction ||
177
+ // For the native GeneratorFunction constructor, the best we can
178
+ // do is to check its .name property.
179
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
180
+ : false;
181
+ };
182
+
183
+ exports.mark = function(genFun) {
184
+ if (Object.setPrototypeOf) {
185
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
186
+ } else {
187
+ genFun.__proto__ = GeneratorFunctionPrototype;
188
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
189
+ }
190
+ genFun.prototype = Object.create(Gp);
191
+ return genFun;
192
+ };
193
+
194
+ // Within the body of any async function, `await x` is transformed to
195
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
196
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
197
+ // meant to be awaited.
198
+ exports.awrap = function(arg) {
199
+ return { __await: arg };
200
+ };
201
+
202
+ function AsyncIterator(generator, PromiseImpl) {
203
+ function invoke(method, arg, resolve, reject) {
204
+ var record = tryCatch(generator[method], generator, arg);
205
+ if (record.type === "throw") {
206
+ reject(record.arg);
207
+ } else {
208
+ var result = record.arg;
209
+ var value = result.value;
210
+ if (value &&
211
+ typeof value === "object" &&
212
+ hasOwn.call(value, "__await")) {
213
+ return PromiseImpl.resolve(value.__await).then(function(value) {
214
+ invoke("next", value, resolve, reject);
215
+ }, function(err) {
216
+ invoke("throw", err, resolve, reject);
217
+ });
218
+ }
219
+
220
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
221
+ // When a yielded Promise is resolved, its final value becomes
222
+ // the .value of the Promise<{value,done}> result for the
223
+ // current iteration.
224
+ result.value = unwrapped;
225
+ resolve(result);
226
+ }, function(error) {
227
+ // If a rejected Promise was yielded, throw the rejection back
228
+ // into the async generator function so it can be handled there.
229
+ return invoke("throw", error, resolve, reject);
230
+ });
231
+ }
232
+ }
233
+
234
+ var previousPromise;
235
+
236
+ function enqueue(method, arg) {
237
+ function callInvokeWithMethodAndArg() {
238
+ return new PromiseImpl(function(resolve, reject) {
239
+ invoke(method, arg, resolve, reject);
240
+ });
241
+ }
242
+
243
+ return previousPromise =
244
+ // If enqueue has been called before, then we want to wait until
245
+ // all previous Promises have been resolved before calling invoke,
246
+ // so that results are always delivered in the correct order. If
247
+ // enqueue has not been called before, then it is important to
248
+ // call invoke immediately, without waiting on a callback to fire,
249
+ // so that the async generator function has the opportunity to do
250
+ // any necessary setup in a predictable way. This predictability
251
+ // is why the Promise constructor synchronously invokes its
252
+ // executor callback, and why async functions synchronously
253
+ // execute code before the first await. Since we implement simple
254
+ // async functions in terms of async generators, it is especially
255
+ // important to get this right, even though it requires care.
256
+ previousPromise ? previousPromise.then(
257
+ callInvokeWithMethodAndArg,
258
+ // Avoid propagating failures to Promises returned by later
259
+ // invocations of the iterator.
260
+ callInvokeWithMethodAndArg
261
+ ) : callInvokeWithMethodAndArg();
262
+ }
263
+
264
+ // Define the unified helper method that is used to implement .next,
265
+ // .throw, and .return (see defineIteratorMethods).
266
+ this._invoke = enqueue;
267
+ }
268
+
269
+ defineIteratorMethods(AsyncIterator.prototype);
270
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
271
+ return this;
272
+ });
273
+ exports.AsyncIterator = AsyncIterator;
274
+
275
+ // Note that simple async functions are implemented on top of
276
+ // AsyncIterator objects; they just return a Promise for the value of
277
+ // the final result produced by the iterator.
278
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
279
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
280
+
281
+ var iter = new AsyncIterator(
282
+ wrap(innerFn, outerFn, self, tryLocsList),
283
+ PromiseImpl
284
+ );
285
+
286
+ return exports.isGeneratorFunction(outerFn)
287
+ ? iter // If outerFn is a generator, return the full iterator.
288
+ : iter.next().then(function(result) {
289
+ return result.done ? result.value : iter.next();
290
+ });
291
+ };
292
+
293
+ function makeInvokeMethod(innerFn, self, context) {
294
+ var state = GenStateSuspendedStart;
295
+
296
+ return function invoke(method, arg) {
297
+ if (state === GenStateExecuting) {
298
+ throw new Error("Generator is already running");
299
+ }
300
+
301
+ if (state === GenStateCompleted) {
302
+ if (method === "throw") {
303
+ throw arg;
304
+ }
305
+
306
+ // Be forgiving, per 25.3.3.3.3 of the spec:
307
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
308
+ return doneResult();
309
+ }
310
+
311
+ context.method = method;
312
+ context.arg = arg;
313
+
314
+ while (true) {
315
+ var delegate = context.delegate;
316
+ if (delegate) {
317
+ var delegateResult = maybeInvokeDelegate(delegate, context);
318
+ if (delegateResult) {
319
+ if (delegateResult === ContinueSentinel) continue;
320
+ return delegateResult;
321
+ }
322
+ }
323
+
324
+ if (context.method === "next") {
325
+ // Setting context._sent for legacy support of Babel's
326
+ // function.sent implementation.
327
+ context.sent = context._sent = context.arg;
328
+
329
+ } else if (context.method === "throw") {
330
+ if (state === GenStateSuspendedStart) {
331
+ state = GenStateCompleted;
332
+ throw context.arg;
333
+ }
334
+
335
+ context.dispatchException(context.arg);
336
+
337
+ } else if (context.method === "return") {
338
+ context.abrupt("return", context.arg);
339
+ }
340
+
341
+ state = GenStateExecuting;
342
+
343
+ var record = tryCatch(innerFn, self, context);
344
+ if (record.type === "normal") {
345
+ // If an exception is thrown from innerFn, we leave state ===
346
+ // GenStateExecuting and loop back for another invocation.
347
+ state = context.done
348
+ ? GenStateCompleted
349
+ : GenStateSuspendedYield;
350
+
351
+ if (record.arg === ContinueSentinel) {
352
+ continue;
353
+ }
354
+
355
+ return {
356
+ value: record.arg,
357
+ done: context.done
358
+ };
359
+
360
+ } else if (record.type === "throw") {
361
+ state = GenStateCompleted;
362
+ // Dispatch the exception by looping back around to the
363
+ // context.dispatchException(context.arg) call above.
364
+ context.method = "throw";
365
+ context.arg = record.arg;
366
+ }
367
+ }
368
+ };
369
+ }
370
+
371
+ // Call delegate.iterator[context.method](context.arg) and handle the
372
+ // result, either by returning a { value, done } result from the
373
+ // delegate iterator, or by modifying context.method and context.arg,
374
+ // setting context.delegate to null, and returning the ContinueSentinel.
375
+ function maybeInvokeDelegate(delegate, context) {
376
+ var method = delegate.iterator[context.method];
377
+ if (method === undefined$1) {
378
+ // A .throw or .return when the delegate iterator has no .throw
379
+ // method always terminates the yield* loop.
380
+ context.delegate = null;
381
+
382
+ if (context.method === "throw") {
383
+ // Note: ["return"] must be used for ES3 parsing compatibility.
384
+ if (delegate.iterator["return"]) {
385
+ // If the delegate iterator has a return method, give it a
386
+ // chance to clean up.
387
+ context.method = "return";
388
+ context.arg = undefined$1;
389
+ maybeInvokeDelegate(delegate, context);
390
+
391
+ if (context.method === "throw") {
392
+ // If maybeInvokeDelegate(context) changed context.method from
393
+ // "return" to "throw", let that override the TypeError below.
394
+ return ContinueSentinel;
395
+ }
396
+ }
397
+
398
+ context.method = "throw";
399
+ context.arg = new TypeError(
400
+ "The iterator does not provide a 'throw' method");
401
+ }
402
+
403
+ return ContinueSentinel;
404
+ }
405
+
406
+ var record = tryCatch(method, delegate.iterator, context.arg);
407
+
408
+ if (record.type === "throw") {
409
+ context.method = "throw";
410
+ context.arg = record.arg;
411
+ context.delegate = null;
412
+ return ContinueSentinel;
413
+ }
414
+
415
+ var info = record.arg;
416
+
417
+ if (! info) {
418
+ context.method = "throw";
419
+ context.arg = new TypeError("iterator result is not an object");
420
+ context.delegate = null;
421
+ return ContinueSentinel;
422
+ }
423
+
424
+ if (info.done) {
425
+ // Assign the result of the finished delegate to the temporary
426
+ // variable specified by delegate.resultName (see delegateYield).
427
+ context[delegate.resultName] = info.value;
428
+
429
+ // Resume execution at the desired location (see delegateYield).
430
+ context.next = delegate.nextLoc;
431
+
432
+ // If context.method was "throw" but the delegate handled the
433
+ // exception, let the outer generator proceed normally. If
434
+ // context.method was "next", forget context.arg since it has been
435
+ // "consumed" by the delegate iterator. If context.method was
436
+ // "return", allow the original .return call to continue in the
437
+ // outer generator.
438
+ if (context.method !== "return") {
439
+ context.method = "next";
440
+ context.arg = undefined$1;
441
+ }
442
+
443
+ } else {
444
+ // Re-yield the result returned by the delegate method.
445
+ return info;
446
+ }
447
+
448
+ // The delegate iterator is finished, so forget it and continue with
449
+ // the outer generator.
450
+ context.delegate = null;
451
+ return ContinueSentinel;
452
+ }
453
+
454
+ // Define Generator.prototype.{next,throw,return} in terms of the
455
+ // unified ._invoke helper method.
456
+ defineIteratorMethods(Gp);
457
+
458
+ define(Gp, toStringTagSymbol, "Generator");
459
+
460
+ // A Generator should always return itself as the iterator object when the
461
+ // @@iterator function is called on it. Some browsers' implementations of the
462
+ // iterator prototype chain incorrectly implement this, causing the Generator
463
+ // object to not be returned from this call. This ensures that doesn't happen.
464
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
465
+ define(Gp, iteratorSymbol, function() {
466
+ return this;
467
+ });
468
+
469
+ define(Gp, "toString", function() {
470
+ return "[object Generator]";
471
+ });
472
+
473
+ function pushTryEntry(locs) {
474
+ var entry = { tryLoc: locs[0] };
475
+
476
+ if (1 in locs) {
477
+ entry.catchLoc = locs[1];
478
+ }
479
+
480
+ if (2 in locs) {
481
+ entry.finallyLoc = locs[2];
482
+ entry.afterLoc = locs[3];
483
+ }
484
+
485
+ this.tryEntries.push(entry);
486
+ }
487
+
488
+ function resetTryEntry(entry) {
489
+ var record = entry.completion || {};
490
+ record.type = "normal";
491
+ delete record.arg;
492
+ entry.completion = record;
493
+ }
494
+
495
+ function Context(tryLocsList) {
496
+ // The root entry object (effectively a try statement without a catch
497
+ // or a finally block) gives us a place to store values thrown from
498
+ // locations where there is no enclosing try statement.
499
+ this.tryEntries = [{ tryLoc: "root" }];
500
+ tryLocsList.forEach(pushTryEntry, this);
501
+ this.reset(true);
502
+ }
503
+
504
+ exports.keys = function(object) {
505
+ var keys = [];
506
+ for (var key in object) {
507
+ keys.push(key);
508
+ }
509
+ keys.reverse();
510
+
511
+ // Rather than returning an object with a next method, we keep
512
+ // things simple and return the next function itself.
513
+ return function next() {
514
+ while (keys.length) {
515
+ var key = keys.pop();
516
+ if (key in object) {
517
+ next.value = key;
518
+ next.done = false;
519
+ return next;
520
+ }
521
+ }
522
+
523
+ // To avoid creating an additional object, we just hang the .value
524
+ // and .done properties off the next function object itself. This
525
+ // also ensures that the minifier will not anonymize the function.
526
+ next.done = true;
527
+ return next;
528
+ };
529
+ };
530
+
531
+ function values(iterable) {
532
+ if (iterable) {
533
+ var iteratorMethod = iterable[iteratorSymbol];
534
+ if (iteratorMethod) {
535
+ return iteratorMethod.call(iterable);
536
+ }
537
+
538
+ if (typeof iterable.next === "function") {
539
+ return iterable;
540
+ }
541
+
542
+ if (!isNaN(iterable.length)) {
543
+ var i = -1, next = function next() {
544
+ while (++i < iterable.length) {
545
+ if (hasOwn.call(iterable, i)) {
546
+ next.value = iterable[i];
547
+ next.done = false;
548
+ return next;
549
+ }
550
+ }
551
+
552
+ next.value = undefined$1;
553
+ next.done = true;
554
+
555
+ return next;
556
+ };
557
+
558
+ return next.next = next;
559
+ }
560
+ }
561
+
562
+ // Return an iterator with no values.
563
+ return { next: doneResult };
564
+ }
565
+ exports.values = values;
566
+
567
+ function doneResult() {
568
+ return { value: undefined$1, done: true };
569
+ }
570
+
571
+ Context.prototype = {
572
+ constructor: Context,
573
+
574
+ reset: function(skipTempReset) {
575
+ this.prev = 0;
576
+ this.next = 0;
577
+ // Resetting context._sent for legacy support of Babel's
578
+ // function.sent implementation.
579
+ this.sent = this._sent = undefined$1;
580
+ this.done = false;
581
+ this.delegate = null;
582
+
583
+ this.method = "next";
584
+ this.arg = undefined$1;
585
+
586
+ this.tryEntries.forEach(resetTryEntry);
587
+
588
+ if (!skipTempReset) {
589
+ for (var name in this) {
590
+ // Not sure about the optimal order of these conditions:
591
+ if (name.charAt(0) === "t" &&
592
+ hasOwn.call(this, name) &&
593
+ !isNaN(+name.slice(1))) {
594
+ this[name] = undefined$1;
595
+ }
596
+ }
597
+ }
598
+ },
599
+
600
+ stop: function() {
601
+ this.done = true;
602
+
603
+ var rootEntry = this.tryEntries[0];
604
+ var rootRecord = rootEntry.completion;
605
+ if (rootRecord.type === "throw") {
606
+ throw rootRecord.arg;
607
+ }
608
+
609
+ return this.rval;
610
+ },
611
+
612
+ dispatchException: function(exception) {
613
+ if (this.done) {
614
+ throw exception;
615
+ }
616
+
617
+ var context = this;
618
+ function handle(loc, caught) {
619
+ record.type = "throw";
620
+ record.arg = exception;
621
+ context.next = loc;
622
+
623
+ if (caught) {
624
+ // If the dispatched exception was caught by a catch block,
625
+ // then let that catch block handle the exception normally.
626
+ context.method = "next";
627
+ context.arg = undefined$1;
628
+ }
629
+
630
+ return !! caught;
631
+ }
632
+
633
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
634
+ var entry = this.tryEntries[i];
635
+ var record = entry.completion;
636
+
637
+ if (entry.tryLoc === "root") {
638
+ // Exception thrown outside of any try block that could handle
639
+ // it, so set the completion value of the entire function to
640
+ // throw the exception.
641
+ return handle("end");
642
+ }
643
+
644
+ if (entry.tryLoc <= this.prev) {
645
+ var hasCatch = hasOwn.call(entry, "catchLoc");
646
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
647
+
648
+ if (hasCatch && hasFinally) {
649
+ if (this.prev < entry.catchLoc) {
650
+ return handle(entry.catchLoc, true);
651
+ } else if (this.prev < entry.finallyLoc) {
652
+ return handle(entry.finallyLoc);
653
+ }
654
+
655
+ } else if (hasCatch) {
656
+ if (this.prev < entry.catchLoc) {
657
+ return handle(entry.catchLoc, true);
658
+ }
659
+
660
+ } else if (hasFinally) {
661
+ if (this.prev < entry.finallyLoc) {
662
+ return handle(entry.finallyLoc);
663
+ }
664
+
665
+ } else {
666
+ throw new Error("try statement without catch or finally");
667
+ }
668
+ }
669
+ }
670
+ },
671
+
672
+ abrupt: function(type, arg) {
673
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
674
+ var entry = this.tryEntries[i];
675
+ if (entry.tryLoc <= this.prev &&
676
+ hasOwn.call(entry, "finallyLoc") &&
677
+ this.prev < entry.finallyLoc) {
678
+ var finallyEntry = entry;
679
+ break;
680
+ }
681
+ }
682
+
683
+ if (finallyEntry &&
684
+ (type === "break" ||
685
+ type === "continue") &&
686
+ finallyEntry.tryLoc <= arg &&
687
+ arg <= finallyEntry.finallyLoc) {
688
+ // Ignore the finally entry if control is not jumping to a
689
+ // location outside the try/catch block.
690
+ finallyEntry = null;
691
+ }
692
+
693
+ var record = finallyEntry ? finallyEntry.completion : {};
694
+ record.type = type;
695
+ record.arg = arg;
696
+
697
+ if (finallyEntry) {
698
+ this.method = "next";
699
+ this.next = finallyEntry.finallyLoc;
700
+ return ContinueSentinel;
701
+ }
702
+
703
+ return this.complete(record);
704
+ },
705
+
706
+ complete: function(record, afterLoc) {
707
+ if (record.type === "throw") {
708
+ throw record.arg;
709
+ }
710
+
711
+ if (record.type === "break" ||
712
+ record.type === "continue") {
713
+ this.next = record.arg;
714
+ } else if (record.type === "return") {
715
+ this.rval = this.arg = record.arg;
716
+ this.method = "return";
717
+ this.next = "end";
718
+ } else if (record.type === "normal" && afterLoc) {
719
+ this.next = afterLoc;
720
+ }
721
+
722
+ return ContinueSentinel;
723
+ },
724
+
725
+ finish: function(finallyLoc) {
726
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
727
+ var entry = this.tryEntries[i];
728
+ if (entry.finallyLoc === finallyLoc) {
729
+ this.complete(entry.completion, entry.afterLoc);
730
+ resetTryEntry(entry);
731
+ return ContinueSentinel;
732
+ }
733
+ }
734
+ },
735
+
736
+ "catch": function(tryLoc) {
737
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
738
+ var entry = this.tryEntries[i];
739
+ if (entry.tryLoc === tryLoc) {
740
+ var record = entry.completion;
741
+ if (record.type === "throw") {
742
+ var thrown = record.arg;
743
+ resetTryEntry(entry);
744
+ }
745
+ return thrown;
746
+ }
747
+ }
748
+
749
+ // The context.catch method must only be called with a location
750
+ // argument that corresponds to a known catch block.
751
+ throw new Error("illegal catch attempt");
752
+ },
753
+
754
+ delegateYield: function(iterable, resultName, nextLoc) {
755
+ this.delegate = {
756
+ iterator: values(iterable),
757
+ resultName: resultName,
758
+ nextLoc: nextLoc
759
+ };
760
+
761
+ if (this.method === "next") {
762
+ // Deliberately forget the last sent value so that we don't
763
+ // accidentally pass it on to the delegate.
764
+ this.arg = undefined$1;
765
+ }
766
+
767
+ return ContinueSentinel;
768
+ }
769
+ };
770
+
771
+ // Regardless of whether this script is executing as a CommonJS module
772
+ // or not, return the runtime object so that we can declare the variable
773
+ // regeneratorRuntime in the outer scope, which allows this module to be
774
+ // injected easily by `bin/regenerator --include-runtime script.js`.
775
+ return exports;
776
+
777
+ }(
778
+ // If this script is executing as a CommonJS module, use module.exports
779
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
780
+ // object. Either way, the resulting object will be used to initialize
781
+ // the regeneratorRuntime variable at the top of this file.
782
+ module.exports
783
+ ));
784
+
785
+ try {
786
+ regeneratorRuntime = runtime;
787
+ } catch (accidentalStrictMode) {
788
+ // This module should not be running in strict mode, so the above
789
+ // assignment should always work unless something is misconfigured. Just
790
+ // in case runtime.js accidentally runs in strict mode, in modern engines
791
+ // we can explicitly access globalThis. In older engines we can escape
792
+ // strict mode using a global Function call. This could conceivably fail
793
+ // if a Content Security Policy forbids using Function, but in that case
794
+ // the proper solution is to fix the accidental strict mode problem. If
795
+ // you've misconfigured your bundler to force strict mode and applied a
796
+ // CSP to forbid Function, and you're not willing to fix either of those
797
+ // problems, please detail your unique predicament in a GitHub issue.
798
+ if (typeof globalThis === "object") {
799
+ globalThis.regeneratorRuntime = runtime;
800
+ } else {
801
+ Function("r", "regeneratorRuntime = r")(runtime);
802
+ }
803
+ }
804
+ });
805
+
806
+ function ensure(x) {
807
+ if (x === null || x === undefined) {
808
+ debugger;
809
+ throw new Error("Value must not be undefined or null");
810
+ } else {
811
+ return x;
812
+ }
813
+ }
814
+ var modulePath = "@plasmicpkgs/sanity-io";
815
+
816
+ function useSanityClient(creds) {
817
+ var sanity = sanityClient({
818
+ projectId: creds.projectId,
819
+ dataset: creds.dataset,
820
+ apiVersion: creds.apiVersion ? creds.apiVersion : "v1",
821
+ token: creds.token,
822
+ useCdn: creds.useCdn
823
+ });
824
+ return sanity;
825
+ }
826
+
827
+ var CredentialsContext = /*#__PURE__*/React.createContext(undefined);
828
+ var sanityCredentialsProviderMeta = {
829
+ name: "SanityCredentialsProvider",
830
+ displayName: "Sanity Credentials Provider",
831
+ importName: "SanityCredentialsProvider",
832
+ importPath: modulePath,
833
+ props: {
834
+ projectId: {
835
+ type: "string",
836
+ displayName: "Project ID",
837
+ defaultValueHint: "zp7mbokg",
838
+ description: "The ID of the project to use."
839
+ },
840
+ dataset: {
841
+ type: "string",
842
+ displayName: "Dataset",
843
+ description: "The dataset to use."
844
+ },
845
+ apiVersion: {
846
+ type: "string",
847
+ displayName: "API Version",
848
+ defaultValueHint: "v1",
849
+ description: "The API version to use (if not set, 'v1' will be used) - see https://www.sanity.io/docs/js-client#specifying-api-version."
850
+ },
851
+ token: {
852
+ type: "string",
853
+ displayName: "Token",
854
+ description: "The token to use (or leave blank for unauthenticated usage) - you can create tokens in the API section of your project (i.e. https://www.sanity.io/manage/personal/project/PROJECT_ID/api#tokens)."
855
+ },
856
+ useCdn: {
857
+ type: "boolean",
858
+ displayName: "Use CDN?",
859
+ defaultValueHint: false,
860
+ description: "Whether you want to use CDN ('false' if you want to ensure fresh data)."
861
+ }
862
+ }
863
+ };
864
+ function SanityCredentialsProvider(_ref) {
865
+ var projectId = _ref.projectId,
866
+ dataset = _ref.dataset,
867
+ apiVersion = _ref.apiVersion,
868
+ token = _ref.token,
869
+ useCdn = _ref.useCdn,
870
+ children = _ref.children;
871
+ return React.createElement(CredentialsContext.Provider, {
872
+ value: {
873
+ projectId: projectId,
874
+ dataset: dataset,
875
+ apiVersion: apiVersion,
876
+ token: token,
877
+ useCdn: useCdn
878
+ }
879
+ }, children);
880
+ }
881
+ var sanityFetcherMeta = {
882
+ name: "SanityFetcher",
883
+ displayName: "Sanity Fetcher",
884
+ importName: "SanityFetcher",
885
+ importPath: modulePath,
886
+ description: "Fetches Sanity data and repeats content of children once for every row fetched. Query Cheat Sheet - GROQ <https://www.sanity.io/docs/query-cheat-sheet>",
887
+ props: {
888
+ children: {
889
+ type: "slot",
890
+ defaultValue: {
891
+ type: "vbox",
892
+ styles: {
893
+ padding: "8px"
894
+ },
895
+ children: {
896
+ type: "component",
897
+ name: "SanityField"
898
+ }
899
+ }
900
+ },
901
+ groq: {
902
+ type: "string",
903
+ displayName: "GROQ",
904
+ description: "Query in GROQ.",
905
+ defaultValueHint: "*[_type == 'movie']"
906
+ }
907
+ }
908
+ };
909
+ function SanityFetcher(_ref2) {
910
+ var groq = _ref2.groq,
911
+ children = _ref2.children,
912
+ className = _ref2.className;
913
+ var creds = ensure(useContext(CredentialsContext));
914
+ var sanity = useSanityClient(creds);
915
+
916
+ if (!creds.dataset) {
917
+ return React.createElement("div", null, "Please specify a dataset.");
918
+ }
919
+
920
+ var data = usePlasmicQueryData(JSON.stringify({
921
+ groq: groq
922
+ }), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
923
+ var resp;
924
+ return runtime_1.wrap(function _callee$(_context) {
925
+ while (1) {
926
+ switch (_context.prev = _context.next) {
927
+ case 0:
928
+ if (groq) {
929
+ _context.next = 2;
930
+ break;
931
+ }
932
+
933
+ return _context.abrupt("return", null);
934
+
935
+ case 2:
936
+ _context.next = 4;
937
+ return sanity.fetch(groq);
938
+
939
+ case 4:
940
+ resp = _context.sent;
941
+ return _context.abrupt("return", resp);
942
+
943
+ case 6:
944
+ case "end":
945
+ return _context.stop();
946
+ }
947
+ }
948
+ }, _callee);
949
+ })));
950
+
951
+ if (!(data != null && data.data)) {
952
+ return React.createElement("div", null, "Please specify a GROQ query, such as *[_type == \"movie\"].");
953
+ }
954
+
955
+ return React.createElement("div", {
956
+ className: className
957
+ }, data == null ? void 0 : data.data.map(function (item, index) {
958
+ return React.createElement(DataProvider, {
959
+ key: item._id,
960
+ name: "sanityItem",
961
+ data: item
962
+ }, repeatedElement(index === 0, children));
963
+ }));
964
+ }
965
+ var sanityFieldMeta = {
966
+ name: "SanityField",
967
+ displayName: "Sanity Field",
968
+ importName: "SanityField",
969
+ importPath: modulePath,
970
+ props: {
971
+ path: {
972
+ type: "string",
973
+ displayName: "Path",
974
+ description: "Field path - see https://www.sanity.io/docs/ids.",
975
+ defaultValueHint: "castMembers.0._key"
976
+ }
977
+ }
978
+ };
979
+ function SanityField(_ref4) {
980
+ var className = _ref4.className,
981
+ path = _ref4.path;
982
+ var creds = ensure(useContext(CredentialsContext));
983
+ var sanity = useSanityClient(creds);
984
+ var imageBuilder = imageUrlBuilder(sanity);
985
+ var item = useSelector("sanityItem");
986
+
987
+ if (!item) {
988
+ return React.createElement("div", null, "SanityField must be used within a SanityFetcher");
989
+ }
990
+
991
+ if (!path) {
992
+ return React.createElement("div", null, "SanityField must specify a path.");
993
+ }
994
+
995
+ var data = L.get(item, path);
996
+
997
+ if (!data) {
998
+ return React.createElement("div", null, "Please specify a valid path.");
999
+ } else if ((data == null ? void 0 : data._type) === "image") {
1000
+ return React.createElement("img", {
1001
+ src: imageBuilder.image(data).ignoreImageParams().width(300).toString()
1002
+ });
1003
+ } else {
1004
+ return React.createElement("div", {
1005
+ className: className
1006
+ }, data);
1007
+ }
1008
+ }
1009
+
1010
+ function registerAll(loader) {
1011
+ var _registerComponent = function _registerComponent(Component, defaultMeta) {
1012
+ if (loader) {
1013
+ loader.registerComponent(Component, defaultMeta);
1014
+ } else {
1015
+ registerComponent(Component, defaultMeta);
1016
+ }
1017
+ };
1018
+
1019
+ if (loader) {
1020
+ loader.registerGlobalContext(SanityCredentialsProvider, sanityCredentialsProviderMeta);
1021
+ } else {
1022
+ registerGlobalContext(SanityCredentialsProvider, sanityCredentialsProviderMeta);
1023
+ }
1024
+
1025
+ _registerComponent(SanityFetcher, sanityFetcherMeta);
1026
+
1027
+ _registerComponent(SanityField, sanityFieldMeta);
1028
+ }
1029
+
1030
+ export { SanityCredentialsProvider, SanityFetcher, SanityField, ensure, registerAll, sanityCredentialsProviderMeta, sanityFetcherMeta, sanityFieldMeta };
1031
+ //# sourceMappingURL=plasmic-sanity-io.esm.js.map