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