1 | import "core-js/modules/es.array.from.js";
|
2 | import "core-js/modules/es.string.iterator.js";
|
3 | import "core-js/modules/es.set.js";
|
4 | import "core-js/modules/es.object.to-string.js";
|
5 | import "core-js/modules/es.array.iterator.js";
|
6 | import "core-js/modules/web.dom-collections.iterator.js";
|
7 | import "core-js/modules/es.array.join.js";
|
8 | import "core-js/modules/es.array.map.js";
|
9 | import "core-js/modules/es.array.concat.js";
|
10 | import global from 'global';
|
11 | import { addons } from '@storybook/addons';
|
12 | import { STORY_CHANGED } from '@storybook/core-events';
|
13 | import { EVENTS, HIGHLIGHT_STYLE_ID } from './constants';
|
14 | import { highlightStyle } from './highlight';
|
15 | var document = global.document;
|
16 |
|
17 | if (module && module.hot && module.hot.decline) {
|
18 | module.hot.decline();
|
19 | }
|
20 |
|
21 | var channel = addons.getChannel();
|
22 |
|
23 | var highlight = function highlight(infos) {
|
24 | var id = HIGHLIGHT_STYLE_ID;
|
25 | resetHighlight();
|
26 |
|
27 | var elements = Array.from(new Set(infos.elements));
|
28 | var sheet = document.createElement('style');
|
29 | sheet.setAttribute('id', id);
|
30 | sheet.innerHTML = elements.map(function (target) {
|
31 | return "".concat(target, "{\n ").concat(highlightStyle(infos.color), "\n }");
|
32 | }).join(' ');
|
33 | document.head.appendChild(sheet);
|
34 | };
|
35 |
|
36 | var resetHighlight = function resetHighlight() {
|
37 | var id = HIGHLIGHT_STYLE_ID;
|
38 | var sheetToBeRemoved = document.getElementById(id);
|
39 |
|
40 | if (sheetToBeRemoved) {
|
41 | sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
|
42 | }
|
43 | };
|
44 |
|
45 | channel.on(STORY_CHANGED, resetHighlight);
|
46 | channel.on(EVENTS.HIGHLIGHT, highlight); |
\ | No newline at end of file |