creevey 0.9.0-non-webpack.0 → 0.9.0-non-webpack.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.
Files changed (56) hide show
  1. package/lib/cjs/client/addon/Manager.js +121 -275
  2. package/lib/cjs/client/addon/components/Addon.js +17 -38
  3. package/lib/cjs/client/addon/components/Icons.js +10 -6
  4. package/lib/cjs/client/addon/components/Panel.js +17 -13
  5. package/lib/cjs/client/addon/components/TestSelect.js +11 -9
  6. package/lib/cjs/client/addon/components/Tools.js +21 -40
  7. package/lib/cjs/client/addon/decorator.js +1 -1
  8. package/lib/cjs/client/addon/index.js +2 -2
  9. package/lib/cjs/client/addon/preset.js +11 -30
  10. package/lib/cjs/client/addon/register.js +45 -73
  11. package/lib/cjs/client/addon/utils.js +1 -1
  12. package/lib/cjs/client/addon/withCreevey.js +153 -360
  13. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +23 -21
  14. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +21 -17
  15. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +42 -64
  16. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +35 -48
  17. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +24 -43
  18. package/lib/cjs/client/shared/components/ImagesView/index.js +5 -5
  19. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +12 -8
  20. package/lib/cjs/client/shared/components/PageFooter/Paging.js +14 -18
  21. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +22 -18
  22. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +42 -67
  23. package/lib/cjs/client/shared/components/ResultsPage.js +38 -68
  24. package/lib/cjs/client/shared/creeveyClientApi.js +55 -86
  25. package/lib/cjs/client/shared/helpers.js +123 -194
  26. package/lib/cjs/client/shared/viewMode.js +4 -4
  27. package/lib/cjs/shared/index.js +26 -14
  28. package/lib/cjs/shared/serializeRegExp.js +5 -4
  29. package/lib/esm/client/addon/Manager.js +121 -275
  30. package/lib/esm/client/addon/components/Addon.js +15 -34
  31. package/lib/esm/client/addon/components/Icons.js +10 -6
  32. package/lib/esm/client/addon/components/Panel.js +17 -13
  33. package/lib/esm/client/addon/components/TestSelect.js +11 -9
  34. package/lib/esm/client/addon/components/Tools.js +19 -36
  35. package/lib/esm/client/addon/decorator.js +1 -1
  36. package/lib/esm/client/addon/preset.js +9 -24
  37. package/lib/esm/client/addon/register.js +42 -70
  38. package/lib/esm/client/addon/utils.js +1 -1
  39. package/lib/esm/client/addon/withCreevey.js +148 -357
  40. package/lib/esm/client/shared/components/ImagesView/BlendView.js +21 -17
  41. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +21 -17
  42. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +40 -60
  43. package/lib/esm/client/shared/components/ImagesView/SlideView.js +33 -44
  44. package/lib/esm/client/shared/components/ImagesView/SwapView.js +22 -39
  45. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +12 -8
  46. package/lib/esm/client/shared/components/PageFooter/Paging.js +14 -18
  47. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +22 -18
  48. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +37 -60
  49. package/lib/esm/client/shared/components/ResultsPage.js +36 -64
  50. package/lib/esm/client/shared/creeveyClientApi.js +57 -88
  51. package/lib/esm/client/shared/helpers.js +123 -194
  52. package/lib/esm/client/shared/viewMode.js +4 -4
  53. package/lib/esm/shared/index.js +26 -14
  54. package/lib/esm/shared/serializeRegExp.js +5 -4
  55. package/package.json +1 -1
  56. package/preset.js +1 -1
@@ -1,31 +1,3 @@
1
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
2
-
3
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
-
5
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
8
-
9
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
-
11
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
-
13
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
-
15
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
-
17
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
-
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
-
21
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
22
-
23
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
24
-
25
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
26
-
27
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
28
-
29
1
  import * as Events from '@storybook/core-events';
30
2
  import * as polyfill from 'event-source-polyfill';
31
3
  import { buildQueries, within } from '@storybook/testing-library';
@@ -34,59 +6,39 @@ import { isObject, noop } from '../../types';
34
6
  import { denormalizeStoryParameters, serializeRawStories } from '../../shared';
35
7
  import { getConnectionUrl } from '../shared/helpers';
36
8
 
37
- if ((typeof process === "undefined" ? "undefined" : _typeof(process)) != 'object' || typeof process.version != 'string') {
9
+ if (typeof process != 'object' || typeof process.version != 'string') {
38
10
  // NOTE If you don't use babel-polyfill or any other polyfills that add EventSource for IE11
39
11
  // You don't get hot reload in IE11. So put polyfill for that to better UX
40
12
  // Don't load in nodejs environment
41
13
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
42
- var NativeEventSource = polyfill.NativeEventSource,
43
- EventSourcePolyfill = polyfill.EventSourcePolyfill; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
14
+ const {
15
+ NativeEventSource,
16
+ EventSourcePolyfill
17
+ } = polyfill; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
44
18
 
45
19
  window.EventSource = NativeEventSource || EventSourcePolyfill;
46
20
  }
47
21
 
48
- var disableAnimationsStyles = "\n*,\n*:hover,\n*::before,\n*::after {\n animation-delay: -0.0001ms !important;\n animation-duration: 0s !important;\n animation-play-state: paused !important;\n cursor: none !important;\n caret-color: transparent !important;\n transition: 0s !important;\n}\n";
49
-
50
- function resetCurrentStory(_x) {
51
- return _resetCurrentStory.apply(this, arguments);
52
- }
22
+ const disableAnimationsStyles = "\n*,\n*:hover,\n*::before,\n*::after {\n animation-delay: -0.0001ms !important;\n animation-duration: 0s !important;\n animation-play-state: paused !important;\n cursor: none !important;\n caret-color: transparent !important;\n transition: 0s !important;\n}\n";
53
23
 
54
- function _resetCurrentStory() {
55
- _resetCurrentStory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(channel) {
56
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
57
- while (1) {
58
- switch (_context4.prev = _context4.next) {
59
- case 0:
60
- setTimeout(function () {
61
- return channel.emit(Events.SET_CURRENT_STORY, {
62
- storyId: true,
63
- name: '',
64
- kind: ''
65
- });
66
- }, 0);
67
- return _context4.abrupt("return", new Promise(function (resolve) {
68
- return channel.once(Events.STORY_MISSING, resolve);
69
- }));
70
-
71
- case 2:
72
- case "end":
73
- return _context4.stop();
74
- }
75
- }
76
- }, _callee4);
77
- }));
78
- return _resetCurrentStory.apply(this, arguments);
24
+ async function resetCurrentStory(channel) {
25
+ setTimeout(() => channel.emit(Events.SET_CURRENT_STORY, {
26
+ storyId: true,
27
+ name: '',
28
+ kind: ''
29
+ }), 0);
30
+ return new Promise(resolve => channel.once(Events.STORY_MISSING, resolve));
79
31
  }
80
32
 
81
33
  function catchRenderError(channel) {
82
- var rejectCallback;
83
- var promise = new Promise(function (_resolve, reject) {
84
- return rejectCallback = reject;
85
- });
34
+ let rejectCallback;
35
+ const promise = new Promise((_resolve, reject) => rejectCallback = reject);
86
36
 
87
37
  function errorHandler(_ref) {
88
- var title = _ref.title,
89
- description = _ref.description;
38
+ let {
39
+ title,
40
+ description
41
+ } = _ref;
90
42
  rejectCallback({
91
43
  message: title,
92
44
  stack: description
@@ -110,10 +62,8 @@ function catchRenderError(channel) {
110
62
  }
111
63
 
112
64
  function waitForStoryRendered(channel) {
113
- var resolveCallback;
114
- var promise = new Promise(function (resolve) {
115
- return resolveCallback = resolve;
116
- });
65
+ let resolveCallback;
66
+ const promise = new Promise(resolve => resolveCallback = resolve);
117
67
 
118
68
  function renderHandler() {
119
69
  resolveCallback();
@@ -131,13 +81,11 @@ function waitForStoryRendered(channel) {
131
81
 
132
82
  function waitForFontsLoaded() {
133
83
  if (!document.fonts) return;
134
- var areFontsLoading = Array.from(document.fonts).some(function (font) {
135
- return font.status == 'loading';
136
- });
84
+ const areFontsLoading = Array.from(document.fonts).some(font => font.status == 'loading');
137
85
 
138
86
  if (areFontsLoading) {
139
- return new Promise(function (resolve) {
140
- var fontsLoadedHandler = function fontsLoadedHandler() {
87
+ return new Promise(resolve => {
88
+ const fontsLoadedHandler = () => {
141
89
  document.fonts.removeEventListener('loadingdone', fontsLoadedHandler);
142
90
  resolve();
143
91
  };
@@ -148,244 +96,132 @@ function waitForFontsLoaded() {
148
96
  }
149
97
 
150
98
  function waitForCaptureCall() {
151
- return new Promise(function (resolve) {
152
- return captureResolver = resolve;
153
- });
99
+ return new Promise(resolve => captureResolver = resolve);
154
100
  }
155
101
 
156
102
  function initCreeveyState() {
157
103
  var _window$localStorage$;
158
104
 
159
- var prevState = JSON.parse((_window$localStorage$ = window.localStorage.getItem('Creevey_Tests')) !== null && _window$localStorage$ !== void 0 ? _window$localStorage$ : '{}');
105
+ const prevState = JSON.parse((_window$localStorage$ = window.localStorage.getItem('Creevey_Tests')) !== null && _window$localStorage$ !== void 0 ? _window$localStorage$ : '{}');
160
106
  if (prevState.creeveyHost) window.__CREEVEY_SERVER_HOST__ = prevState.creeveyHost;
161
107
  if (prevState.creeveyPort) window.__CREEVEY_SERVER_PORT__ = prevState.creeveyPort;
162
108
  if (prevState.setStoriesCounter) setStoriesCounter = prevState.setStoriesCounter;
163
109
  if (prevState.isTestBrowser) isTestBrowser = prevState.isTestBrowser;
164
- window.addEventListener('beforeunload', function () {
110
+ window.addEventListener('beforeunload', () => {
165
111
  window.localStorage.setItem('Creevey_Tests', JSON.stringify({
166
112
  creeveyHost: window.__CREEVEY_SERVER_HOST__,
167
113
  creeveyPort: window.__CREEVEY_SERVER_PORT__,
168
- setStoriesCounter: setStoriesCounter,
169
- isTestBrowser: isTestBrowser
114
+ setStoriesCounter,
115
+ isTestBrowser
170
116
  }));
171
117
  });
172
118
  }
173
119
 
174
- var isTestBrowser = false;
175
- var captureResolver;
176
- var waitForCreevey;
177
- var creeveyReady;
178
- var setStoriesCounter = 0;
120
+ let isTestBrowser = false;
121
+ let captureResolver;
122
+ let waitForCreevey;
123
+ let creeveyReady;
124
+ let setStoriesCounter = 0;
179
125
  export function withCreevey() {
180
- var currentStory = '';
181
- var isAnimationDisabled = false;
126
+ let currentStory = '';
127
+ let isAnimationDisabled = false;
182
128
  initCreeveyState();
183
129
 
184
130
  function disableAnimation() {
185
131
  isAnimationDisabled = true;
186
- var style = document.createElement('style');
187
- var textNode = document.createTextNode(disableAnimationsStyles);
132
+ const style = document.createElement('style');
133
+ const textNode = document.createTextNode(disableAnimationsStyles);
188
134
  style.setAttribute('type', 'text/css');
189
135
  style.appendChild(textNode);
190
136
  document.head.appendChild(style);
191
137
  }
192
138
 
193
- function getStories() {
194
- return _getStories.apply(this, arguments);
195
- }
196
-
197
- function _getStories() {
198
- _getStories = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
199
- var _window$__STORYBOOK_S;
200
-
201
- var storiesPromise, store;
202
- return _regeneratorRuntime().wrap(function _callee$(_context) {
203
- while (1) {
204
- switch (_context.prev = _context.next) {
205
- case 0:
206
- storiesPromise = new Promise(function (resolve) {
207
- return addons.getChannel().once(Events.SET_STORIES, function (data) {
208
- return resolve(serializeRawStories(denormalizeStoryParameters(data)));
209
- });
210
- });
211
- store = (_window$__STORYBOOK_S = window.__STORYBOOK_STORY_STORE__) !== null && _window$__STORYBOOK_S !== void 0 ? _window$__STORYBOOK_S : {}; // @ts-expect-error `pushToManager` exists only in Storybook 6.0 - 6.3
212
-
213
- if (!store.pushToManager) {
214
- _context.next = 6;
215
- break;
216
- }
217
-
218
- // @ts-expect-error `pushToManager` exists only in Storybook 6.0 - 6.3
219
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
220
- store.pushToManager();
221
- _context.next = 13;
222
- break;
223
-
224
- case 6:
225
- if (!store.cacheAllCSFFiles) {
226
- _context.next = 12;
227
- break;
228
- }
229
-
230
- _context.next = 9;
231
- return store.cacheAllCSFFiles();
232
-
233
- case 9:
234
- addons.getChannel().emit(Events.SET_STORIES, store.getSetStoriesPayload());
235
- _context.next = 13;
236
- break;
237
-
238
- case 12:
239
- return _context.abrupt("return");
240
-
241
- case 13:
242
- addons.getChannel().on(Events.SET_STORIES, function (data) {
243
- // TODO Figure out how to get only updated stories
244
- // TODO Subscribe on hmr? like use dummy-hmr
245
- setStoriesCounter += 1;
246
- var stories = serializeRawStories(denormalizeStoryParameters(data));
247
- var storiesByFiles = new Map();
248
- Object.values(stories).forEach(function (story) {
249
- var storiesFromFile = storiesByFiles.get(story.parameters.fileName);
250
- if (storiesFromFile) storiesFromFile.push(story);else storiesByFiles.set(story.parameters.fileName, [story]);
251
- });
252
- void fetch("http://".concat(getConnectionUrl(), "/stories"), {
253
- method: 'POST',
254
- headers: {
255
- 'Content-Type': 'application/json'
256
- },
257
- body: JSON.stringify({
258
- setStoriesCounter: setStoriesCounter,
259
- stories: _toConsumableArray(storiesByFiles.entries())
260
- })
261
- });
262
- });
263
- return _context.abrupt("return", storiesPromise);
264
-
265
- case 15:
266
- case "end":
267
- return _context.stop();
268
- }
269
- }
270
- }, _callee);
271
- }));
272
- return _getStories.apply(this, arguments);
273
- }
274
-
275
- function selectStory(_x2, _x3, _x4, _x5, _x6) {
276
- return _selectStory.apply(this, arguments);
139
+ async function getStories() {
140
+ var _window$__STORYBOOK_S;
141
+
142
+ const storiesPromise = new Promise(resolve => addons.getChannel().once(Events.SET_STORIES, data => resolve(serializeRawStories(denormalizeStoryParameters(data)))));
143
+ const store = (_window$__STORYBOOK_S = window.__STORYBOOK_STORY_STORE__) !== null && _window$__STORYBOOK_S !== void 0 ? _window$__STORYBOOK_S : {}; // @ts-expect-error `pushToManager` exists only in Storybook 6.0 - 6.3
144
+
145
+ if (store.pushToManager) {
146
+ // @ts-expect-error `pushToManager` exists only in Storybook 6.0 - 6.3
147
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
148
+ store.pushToManager();
149
+ } else if (store.cacheAllCSFFiles) {
150
+ await store.cacheAllCSFFiles();
151
+ addons.getChannel().emit(Events.SET_STORIES, store.getSetStoriesPayload());
152
+ } else return;
153
+
154
+ addons.getChannel().on(Events.SET_STORIES, data => {
155
+ // TODO Figure out how to get only updated stories
156
+ // TODO Subscribe on hmr? like use dummy-hmr
157
+ setStoriesCounter += 1;
158
+ const stories = serializeRawStories(denormalizeStoryParameters(data));
159
+ const storiesByFiles = new Map();
160
+ Object.values(stories).forEach(story => {
161
+ const storiesFromFile = storiesByFiles.get(story.parameters.fileName);
162
+ if (storiesFromFile) storiesFromFile.push(story);else storiesByFiles.set(story.parameters.fileName, [story]);
163
+ });
164
+ void fetch("http://".concat(getConnectionUrl(), "/stories"), {
165
+ method: 'POST',
166
+ headers: {
167
+ 'Content-Type': 'application/json'
168
+ },
169
+ body: JSON.stringify({
170
+ setStoriesCounter,
171
+ stories: [...storiesByFiles.entries()]
172
+ })
173
+ });
174
+ });
175
+ return storiesPromise;
277
176
  }
278
177
 
279
- function _selectStory() {
280
- _selectStory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(storyId, kind, name, shouldWaitForReady, callback) {
281
- var channel, waitForReady, isCaptureCalled, renderPromise, errorPromise, capturePromise, _reason$stack, errorMessage;
282
-
283
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
284
- while (1) {
285
- switch (_context3.prev = _context3.next) {
286
- case 0:
287
- if (!isAnimationDisabled) disableAnimation();
288
- isTestBrowser = true;
289
- channel = addons.getChannel();
290
- waitForReady = shouldWaitForReady ? new Promise(function (resolve) {
291
- return window.__CREEVEY_SET_READY_FOR_CAPTURE__ = resolve;
292
- }) : Promise.resolve();
293
-
294
- if (!(storyId == currentStory)) {
295
- _context3.next = 9;
296
- break;
297
- }
298
-
299
- _context3.next = 7;
300
- return resetCurrentStory(channel);
301
-
302
- case 7:
303
- _context3.next = 10;
304
- break;
305
-
306
- case 9:
307
- currentStory = storyId;
308
-
309
- case 10:
310
- isCaptureCalled = false;
311
- renderPromise = waitForStoryRendered(channel);
312
- errorPromise = catchRenderError(channel);
313
- capturePromise = waitForCaptureCall().then(function () {
314
- return isCaptureCalled = true;
315
- });
316
- setTimeout(function () {
317
- return channel.emit(Events.SET_CURRENT_STORY, {
318
- storyId: storyId,
319
- name: name,
320
- kind: kind
321
- });
322
- }, 0);
323
- _context3.prev = 15;
324
- _context3.next = 18;
325
- return Promise.race([_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
326
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
327
- while (1) {
328
- switch (_context2.prev = _context2.next) {
329
- case 0:
330
- _context2.next = 2;
331
- return Promise.race([renderPromise, capturePromise]);
332
-
333
- case 2:
334
- _context2.next = 4;
335
- return waitForFontsLoaded();
336
-
337
- case 4:
338
- _context2.next = 6;
339
- return waitForReady;
340
-
341
- case 6:
342
- case "end":
343
- return _context2.stop();
344
- }
345
- }
346
- }, _callee2);
347
- }))(), errorPromise]);
348
-
349
- case 18:
350
- callback([null, isCaptureCalled]);
351
- _context3.next = 25;
352
- break;
353
-
354
- case 21:
355
- _context3.prev = 21;
356
- _context3.t0 = _context3["catch"](15);
357
- // NOTE Event `STORY_THREW_EXCEPTION` triggered only in react and vue frameworks and return Error instance
358
- // NOTE Event `STORY_ERRORED` return error-like object without `name` field
359
- errorMessage = _context3.t0 instanceof Error ? (_reason$stack = _context3.t0.stack) !== null && _reason$stack !== void 0 ? _reason$stack : _context3.t0.message : isObject(_context3.t0) ? "".concat(_context3.t0.message, "\n ").concat(_context3.t0.stack) : _context3.t0;
360
- callback([errorMessage]);
361
-
362
- case 25:
363
- _context3.prev = 25;
364
- renderPromise.cancel();
365
- errorPromise.cancel();
366
- return _context3.finish(25);
367
-
368
- case 29:
369
- case "end":
370
- return _context3.stop();
371
- }
372
- }
373
- }, _callee3, null, [[15, 21, 25, 29]]);
374
- }));
375
- return _selectStory.apply(this, arguments);
178
+ async function selectStory(storyId, kind, name, shouldWaitForReady, callback) {
179
+ if (!isAnimationDisabled) disableAnimation();
180
+ isTestBrowser = true;
181
+ const channel = addons.getChannel();
182
+ const waitForReady = shouldWaitForReady ? new Promise(resolve => window.__CREEVEY_SET_READY_FOR_CAPTURE__ = resolve) : Promise.resolve();
183
+ if (storyId == currentStory) await resetCurrentStory(channel);else currentStory = storyId;
184
+ let isCaptureCalled = false;
185
+ const renderPromise = waitForStoryRendered(channel);
186
+ const errorPromise = catchRenderError(channel);
187
+ const capturePromise = waitForCaptureCall().then(() => isCaptureCalled = true);
188
+ setTimeout(() => channel.emit(Events.SET_CURRENT_STORY, {
189
+ storyId,
190
+ name,
191
+ kind
192
+ }), 0);
193
+
194
+ try {
195
+ await Promise.race([(async () => {
196
+ await Promise.race([renderPromise, capturePromise]);
197
+ await waitForFontsLoaded();
198
+ await waitForReady;
199
+ })(), errorPromise]);
200
+ callback([null, isCaptureCalled]);
201
+ } catch (reason) {
202
+ var _reason$stack;
203
+
204
+ // NOTE Event `STORY_THREW_EXCEPTION` triggered only in react and vue frameworks and return Error instance
205
+ // NOTE Event `STORY_ERRORED` return error-like object without `name` field
206
+ const errorMessage = reason instanceof Error ? (_reason$stack = reason.stack) !== null && _reason$stack !== void 0 ? _reason$stack : reason.message : isObject(reason) ? "".concat(reason.message, "\n ").concat(reason.stack) : reason;
207
+ callback([errorMessage]);
208
+ } finally {
209
+ renderPromise.cancel();
210
+ errorPromise.cancel();
211
+ }
376
212
  }
377
213
 
378
214
  function updateGlobals(globals) {
379
215
  addons.getChannel().emit(Events.UPDATE_GLOBALS, {
380
- globals: globals
216
+ globals
381
217
  });
382
218
  }
383
219
 
384
220
  function insertIgnoreStyles(ignoreSelectors) {
385
- var stylesElement = document.createElement('style');
221
+ const stylesElement = document.createElement('style');
386
222
  stylesElement.setAttribute('type', 'text/css');
387
223
  document.head.appendChild(stylesElement);
388
- ignoreSelectors.forEach(function (selector) {
224
+ ignoreSelectors.forEach(selector => {
389
225
  stylesElement.innerHTML += "\n ".concat(selector, " {\n background: #000 !important;\n box-shadow: none !important;\n text-shadow: none !important;\n outline: 0 !important;\n color: rgba(0,0,0,0) !important;\n }\n ").concat(selector, " *, ").concat(selector, "::before, ").concat(selector, "::after {\n visibility: hidden !important;\n }\n ");
390
226
  });
391
227
  return stylesElement;
@@ -399,15 +235,15 @@ export function withCreevey() {
399
235
 
400
236
  function hasPlayCompletedYet(callback) {
401
237
  creeveyReady();
402
- var isCaptureCalled = false;
403
- var isPlayCompleted = false;
404
- var channel = addons.getChannel();
405
- void waitForStoryRendered(channel).then(function () {
238
+ let isCaptureCalled = false;
239
+ let isPlayCompleted = false;
240
+ const channel = addons.getChannel();
241
+ void waitForStoryRendered(channel).then(() => {
406
242
  if (isCaptureCalled) return;
407
243
  isPlayCompleted = true;
408
244
  callback(true);
409
245
  });
410
- void waitForCaptureCall().then(function () {
246
+ void waitForCaptureCall().then(() => {
411
247
  if (isPlayCompleted) return;
412
248
  isCaptureCalled = true;
413
249
  callback(false);
@@ -422,47 +258,32 @@ export function withCreevey() {
422
258
  window.__CREEVEY_HAS_PLAY_COMPLETED_YET__ = hasPlayCompletedYet;
423
259
  window.__CREEVEY_SET_READY_FOR_CAPTURE__ = noop;
424
260
 
425
- var queryAllByQuery = function queryAllByQuery(container, query) {
426
- return _toConsumableArray(container.querySelectorAll(query)).filter(function (e) {
427
- return e instanceof HTMLElement;
428
- });
429
- };
261
+ const queryAllByQuery = (container, query) => [...container.querySelectorAll(query)].filter(e => e instanceof HTMLElement);
430
262
 
431
- var getMultipleError = function getMultipleError(_, query) {
432
- return "Found multiple elements by query: ".concat(query);
433
- };
263
+ const getMultipleError = (_, query) => "Found multiple elements by query: ".concat(query);
434
264
 
435
- var getMissingError = function getMissingError(_, query) {
436
- return "Unable to find an element by query: ".concat(query);
437
- };
265
+ const getMissingError = (_, query) => "Unable to find an element by query: ".concat(query);
438
266
 
439
- var _buildQueries = buildQueries(queryAllByQuery, getMultipleError, getMissingError),
440
- _buildQueries2 = _slicedToArray(_buildQueries, 5),
441
- queryByQuery = _buildQueries2[0],
442
- getAllByQuery = _buildQueries2[1],
443
- getByQuery = _buildQueries2[2],
444
- findAllByQuery = _buildQueries2[3],
445
- findByQuery = _buildQueries2[4];
446
-
447
- var queries = {
448
- queryByQuery: queryByQuery,
449
- getAllByQuery: getAllByQuery,
450
- getByQuery: getByQuery,
451
- findAllByQuery: findAllByQuery,
452
- findByQuery: findByQuery
267
+ const [queryByQuery, getAllByQuery, getByQuery, findAllByQuery, findByQuery] = buildQueries(queryAllByQuery, getMultipleError, getMissingError);
268
+ const queries = {
269
+ queryByQuery,
270
+ getAllByQuery,
271
+ getByQuery,
272
+ findAllByQuery,
273
+ findByQuery
453
274
  };
454
275
  return makeDecorator({
455
276
  name: 'withCreevey',
456
277
  parameterName: 'creevey',
457
- wrapper: function wrapper(getStory, context) {
278
+ wrapper: (getStory, context) => {
458
279
  var _ref2;
459
280
 
460
281
  // TODO Define proper types, like captureElement is a promise
461
- var _context$parameters$c = context.parameters.creevey = (_ref2 = context.parameters.creevey) !== null && _ref2 !== void 0 ? _ref2 : {},
462
- captureElement = _context$parameters$c.captureElement;
463
-
282
+ const {
283
+ captureElement
284
+ } = context.parameters.creevey = (_ref2 = context.parameters.creevey) !== null && _ref2 !== void 0 ? _ref2 : {};
464
285
  Object.defineProperty(context.parameters.creevey, 'captureElement', {
465
- get: function get() {
286
+ get() {
466
287
  switch (true) {
467
288
  case captureElement === undefined:
468
289
  return Promise.resolve(context.canvasElement);
@@ -478,6 +299,7 @@ export function withCreevey() {
478
299
  return Promise.resolve(captureElement(context));
479
300
  }
480
301
  },
302
+
481
303
  enumerable: true,
482
304
  configurable: true
483
305
  });
@@ -485,50 +307,19 @@ export function withCreevey() {
485
307
  }
486
308
  });
487
309
  }
488
- export function capture(_x7) {
489
- return _capture.apply(this, arguments);
490
- }
491
-
492
- function _capture() {
493
- _capture = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options) {
494
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
495
- while (1) {
496
- switch (_context5.prev = _context5.next) {
497
- case 0:
498
- if (isTestBrowser) {
499
- _context5.next = 2;
500
- break;
501
- }
502
-
503
- return _context5.abrupt("return");
504
-
505
- case 2:
506
- captureResolver();
507
- waitForCreevey = new Promise(function (resolve) {
508
- return creeveyReady = resolve;
509
- });
510
- _context5.next = 6;
511
- return fetch("http://".concat(getConnectionUrl(), "/capture"), {
512
- method: 'POST',
513
- headers: {
514
- 'Content-Type': 'application/json'
515
- },
516
- body: JSON.stringify({
517
- workerId: window.__CREEVEY_WORKER_ID__,
518
- options: options
519
- })
520
- });
521
-
522
- case 6:
523
- _context5.next = 8;
524
- return waitForCreevey;
525
-
526
- case 8:
527
- case "end":
528
- return _context5.stop();
529
- }
530
- }
531
- }, _callee5);
532
- }));
533
- return _capture.apply(this, arguments);
310
+ export async function capture(options) {
311
+ if (!isTestBrowser) return;
312
+ captureResolver();
313
+ waitForCreevey = new Promise(resolve => creeveyReady = resolve);
314
+ await fetch("http://".concat(getConnectionUrl(), "/capture"), {
315
+ method: 'POST',
316
+ headers: {
317
+ 'Content-Type': 'application/json'
318
+ },
319
+ body: JSON.stringify({
320
+ workerId: window.__CREEVEY_WORKER_ID__,
321
+ options
322
+ })
323
+ });
324
+ await waitForCreevey;
534
325
  }