@plasmicpkgs/plasmic-giphy 0.0.1

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