1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.object.assign");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = void 0;
|
9 |
|
10 | var _global = require("global");
|
11 |
|
12 | var _addons = require("@storybook/addons");
|
13 |
|
14 | var _parameters = _interopRequireDefault(require("./parameters"));
|
15 |
|
16 | var _styles = _interopRequireDefault(require("./styles"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
19 |
|
20 | var INNER_ID = 'sb-addon-centered-inner';
|
21 | var WRAPPER_ID = 'sb-addon-centered-wrapper';
|
22 |
|
23 | function getOrCreate(id, style) {
|
24 | var elementOnDom = _global.document.getElementById(id);
|
25 |
|
26 | if (elementOnDom) {
|
27 | return elementOnDom;
|
28 | }
|
29 |
|
30 | var element = _global.document.createElement('div');
|
31 |
|
32 | element.setAttribute('id', id);
|
33 | Object.assign(element.style, style);
|
34 | return element;
|
35 | }
|
36 |
|
37 | function getInnerDiv() {
|
38 | return getOrCreate(INNER_ID, _styles["default"].innerStyle);
|
39 | }
|
40 |
|
41 | function getWrapperDiv() {
|
42 | return getOrCreate(WRAPPER_ID, _styles["default"].style);
|
43 | }
|
44 |
|
45 | function centered(storyFn) {
|
46 | var inner = getInnerDiv();
|
47 | var wrapper = getWrapperDiv();
|
48 | wrapper.appendChild(inner);
|
49 | var element = storyFn();
|
50 |
|
51 | if (typeof element === 'string') {
|
52 | inner.innerHTML = element;
|
53 | } else if (element instanceof _global.Node) {
|
54 | inner.innerHTML = '';
|
55 | inner.appendChild(element);
|
56 | } else {
|
57 | return element;
|
58 | }
|
59 |
|
60 | return wrapper;
|
61 | }
|
62 |
|
63 | var _default = (0, _addons.makeDecorator)(Object.assign({}, _parameters["default"], {
|
64 | wrapper: function wrapper(getStory) {
|
65 | return centered(getStory);
|
66 | }
|
67 | }));
|
68 |
|
69 | exports["default"] = _default;
|
70 |
|
71 | if (module && module.hot && module.hot.decline) {
|
72 | module.hot.decline();
|
73 | } |
\ | No newline at end of file |