UNPKG

1.81 kBJavaScriptView Raw
1"use strict";
2
3require("core-js/modules/es.array.from.js");
4
5require("core-js/modules/es.string.iterator.js");
6
7require("core-js/modules/es.set.js");
8
9require("core-js/modules/es.object.to-string.js");
10
11require("core-js/modules/es.array.iterator.js");
12
13require("core-js/modules/web.dom-collections.iterator.js");
14
15require("core-js/modules/es.array.join.js");
16
17require("core-js/modules/es.array.map.js");
18
19require("core-js/modules/es.array.concat.js");
20
21var _global = _interopRequireDefault(require("global"));
22
23var _addons = require("@storybook/addons");
24
25var _coreEvents = require("@storybook/core-events");
26
27var _constants = require("./constants");
28
29var _highlight = require("./highlight");
30
31function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
33var document = _global.default.document;
34
35if (module && module.hot && module.hot.decline) {
36 module.hot.decline();
37}
38
39var channel = _addons.addons.getChannel();
40
41var highlight = function highlight(infos) {
42 var id = _constants.HIGHLIGHT_STYLE_ID;
43 resetHighlight(); // Make sure there are no duplicated selectors
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
54var 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
63channel.on(_coreEvents.STORY_CHANGED, resetHighlight);
64channel.on(_constants.EVENTS.HIGHLIGHT, highlight);
\No newline at end of file