1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.object.to-string");
|
4 |
|
5 | require("core-js/modules/es.promise");
|
6 |
|
7 | require("regenerator-runtime/runtime");
|
8 |
|
9 | var _global = require("global");
|
10 |
|
11 | var _axeCore = _interopRequireDefault(require("axe-core"));
|
12 |
|
13 | var _addons = _interopRequireDefault(require("@storybook/addons"));
|
14 |
|
15 | var _constants = require("./constants");
|
16 |
|
17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
18 |
|
19 | 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); } }
|
20 |
|
21 | 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); }); }; }
|
22 |
|
23 | if (module && module.hot && module.hot.decline) {
|
24 | module.hot.decline();
|
25 | }
|
26 |
|
27 | var channel = _addons["default"].getChannel();
|
28 |
|
29 |
|
30 | var active = false;
|
31 |
|
32 | var activeStoryId;
|
33 |
|
34 | var getElement = function getElement() {
|
35 | var storyRoot = _global.document.getElementById('story-root');
|
36 |
|
37 | return storyRoot ? storyRoot.children : _global.document.getElementById('root');
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | var handleRequest = function handleRequest(storyId) {
|
46 | var _getParams = getParams(storyId),
|
47 | manual = _getParams.manual;
|
48 |
|
49 | if (!manual) {
|
50 | run(storyId);
|
51 | }
|
52 | };
|
53 |
|
54 | var run = function () {
|
55 | var _ref = _asyncToGenerator( regeneratorRuntime.mark(function _callee(storyId) {
|
56 | var input, _input$element, element, config, _input$options, options, result;
|
57 |
|
58 | return regeneratorRuntime.wrap(function _callee$(_context) {
|
59 | while (1) {
|
60 | switch (_context.prev = _context.next) {
|
61 | case 0:
|
62 | activeStoryId = storyId;
|
63 | _context.prev = 1;
|
64 | input = getParams(storyId);
|
65 |
|
66 | if (active) {
|
67 | _context.next = 13;
|
68 | break;
|
69 | }
|
70 |
|
71 | active = true;
|
72 | channel.emit(_constants.EVENTS.RUNNING);
|
73 | _input$element = input.element, element = _input$element === void 0 ? getElement() : _input$element, config = input.config, _input$options = input.options, options = _input$options === void 0 ? {
|
74 | restoreScroll: true
|
75 | } : _input$options;
|
76 |
|
77 | _axeCore["default"].reset();
|
78 |
|
79 | if (config) {
|
80 | _axeCore["default"].configure(config);
|
81 | }
|
82 |
|
83 | _context.next = 11;
|
84 | return _axeCore["default"].run(element, options);
|
85 |
|
86 | case 11:
|
87 | result = _context.sent;
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | if (activeStoryId === storyId) {
|
94 | channel.emit(_constants.EVENTS.RESULT, result);
|
95 | } else {
|
96 | active = false;
|
97 | run(activeStoryId);
|
98 | }
|
99 |
|
100 | case 13:
|
101 | _context.next = 18;
|
102 | break;
|
103 |
|
104 | case 15:
|
105 | _context.prev = 15;
|
106 | _context.t0 = _context["catch"](1);
|
107 | channel.emit(_constants.EVENTS.ERROR, _context.t0);
|
108 |
|
109 | case 18:
|
110 | _context.prev = 18;
|
111 | active = false;
|
112 | return _context.finish(18);
|
113 |
|
114 | case 21:
|
115 | case "end":
|
116 | return _context.stop();
|
117 | }
|
118 | }
|
119 | }, _callee, null, [[1, 15, 18, 21]]);
|
120 | }));
|
121 |
|
122 | return function run(_x) {
|
123 | return _ref.apply(this, arguments);
|
124 | };
|
125 | }();
|
126 |
|
127 |
|
128 |
|
129 | var getParams = function getParams(storyId) {
|
130 | var _ref2 = _global.window.__STORYBOOK_STORY_STORE__.fromId(storyId) || {},
|
131 | parameters = _ref2.parameters;
|
132 |
|
133 | return parameters.a11y || {
|
134 | config: {},
|
135 | options: {
|
136 | restoreScroll: true
|
137 | }
|
138 | };
|
139 | };
|
140 |
|
141 | channel.on(_constants.EVENTS.REQUEST, handleRequest);
|
142 | channel.on(_constants.EVENTS.MANUAL, run); |
\ | No newline at end of file |