1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.array.from.js");
|
4 |
|
5 | require("core-js/modules/es.string.iterator.js");
|
6 |
|
7 | require("core-js/modules/es.set.js");
|
8 |
|
9 | require("core-js/modules/es.object.to-string.js");
|
10 |
|
11 | require("core-js/modules/es.array.iterator.js");
|
12 |
|
13 | require("core-js/modules/web.dom-collections.iterator.js");
|
14 |
|
15 | require("core-js/modules/es.array.join.js");
|
16 |
|
17 | require("core-js/modules/es.array.map.js");
|
18 |
|
19 | require("core-js/modules/es.array.concat.js");
|
20 |
|
21 | var _global = _interopRequireDefault(require("global"));
|
22 |
|
23 | var _addons = require("@storybook/addons");
|
24 |
|
25 | var _coreEvents = require("@storybook/core-events");
|
26 |
|
27 | var _constants = require("./constants");
|
28 |
|
29 | var _highlight = require("./highlight");
|
30 |
|
31 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
32 |
|
33 | var document = _global.default.document;
|
34 |
|
35 | if (module && module.hot && module.hot.decline) {
|
36 | module.hot.decline();
|
37 | }
|
38 |
|
39 | var channel = _addons.addons.getChannel();
|
40 |
|
41 | var highlight = function highlight(infos) {
|
42 | var id = _constants.HIGHLIGHT_STYLE_ID;
|
43 | resetHighlight();
|
44 |
|
45 | var elements = Array.from(new Set(infos.elements));
|
46 | var sheet = document.createElement('style');
|
47 | sheet.setAttribute('id', id);
|
48 | sheet.innerHTML = elements.map(function (target) {
|
49 | return "".concat(target, "{\n ").concat((0, _highlight.highlightStyle)(infos.color), "\n }");
|
50 | }).join(' ');
|
51 | document.head.appendChild(sheet);
|
52 | };
|
53 |
|
54 | var resetHighlight = function resetHighlight() {
|
55 | var id = _constants.HIGHLIGHT_STYLE_ID;
|
56 | var sheetToBeRemoved = document.getElementById(id);
|
57 |
|
58 | if (sheetToBeRemoved) {
|
59 | sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
|
60 | }
|
61 | };
|
62 |
|
63 | channel.on(_coreEvents.STORY_CHANGED, resetHighlight);
|
64 | channel.on(_constants.EVENTS.HIGHLIGHT, highlight); |
\ | No newline at end of file |