1 | import "core-js/modules/es.object.assign.js";
|
2 | import "core-js/modules/web.dom-collections.for-each.js";
|
3 | import "core-js/modules/es.object.values.js";
|
4 | import "core-js/modules/es.promise.js";
|
5 | import "core-js/modules/es.object.to-string.js";
|
6 |
|
7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8 |
|
9 | import global from 'global';
|
10 | import { Channel } from '@storybook/channels';
|
11 | import { logger } from '@storybook/client-logger';
|
12 | import { types } from './types';
|
13 | export { Channel };
|
14 | export var AddonStore = function AddonStore() {
|
15 | var _this = this;
|
16 |
|
17 | _classCallCheck(this, AddonStore);
|
18 |
|
19 | this.loaders = {};
|
20 | this.elements = {};
|
21 | this.config = {};
|
22 | this.channel = void 0;
|
23 | this.serverChannel = void 0;
|
24 | this.promise = void 0;
|
25 | this.resolve = void 0;
|
26 |
|
27 | this.getChannel = function () {
|
28 |
|
29 | if (!_this.channel) {
|
30 | throw new Error('Accessing non-existent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel');
|
31 | }
|
32 |
|
33 | return _this.channel;
|
34 | };
|
35 |
|
36 | this.getServerChannel = function () {
|
37 | if (!_this.serverChannel) {
|
38 | throw new Error('Accessing non-existent serverChannel');
|
39 | }
|
40 |
|
41 | return _this.serverChannel;
|
42 | };
|
43 |
|
44 | this.ready = function () {
|
45 | return _this.promise;
|
46 | };
|
47 |
|
48 | this.hasChannel = function () {
|
49 | return !!_this.channel;
|
50 | };
|
51 |
|
52 | this.hasServerChannel = function () {
|
53 | return !!_this.serverChannel;
|
54 | };
|
55 |
|
56 | this.setChannel = function (channel) {
|
57 | _this.channel = channel;
|
58 |
|
59 | _this.resolve();
|
60 | };
|
61 |
|
62 | this.setServerChannel = function (channel) {
|
63 | _this.serverChannel = channel;
|
64 | };
|
65 |
|
66 | this.getElements = function (type) {
|
67 | if (!_this.elements[type]) {
|
68 | _this.elements[type] = {};
|
69 | }
|
70 |
|
71 | return _this.elements[type];
|
72 | };
|
73 |
|
74 | this.addPanel = function (name, options) {
|
75 | _this.add(name, Object.assign({
|
76 | type: types.PANEL
|
77 | }, options));
|
78 | };
|
79 |
|
80 | this.add = function (name, addon) {
|
81 | var type = addon.type;
|
82 |
|
83 | var collection = _this.getElements(type);
|
84 |
|
85 | collection[name] = Object.assign({
|
86 | id: name
|
87 | }, addon);
|
88 | };
|
89 |
|
90 | this.setConfig = function (value) {
|
91 | Object.assign(_this.config, value);
|
92 | };
|
93 |
|
94 | this.getConfig = function () {
|
95 | return _this.config;
|
96 | };
|
97 |
|
98 | this.register = function (name, registerCallback) {
|
99 | if (_this.loaders[name]) {
|
100 | logger.warn("".concat(name, " was loaded twice, this could have bad side-effects"));
|
101 | }
|
102 |
|
103 | _this.loaders[name] = registerCallback;
|
104 | };
|
105 |
|
106 | this.loadAddons = function (api) {
|
107 | Object.values(_this.loaders).forEach(function (value) {
|
108 | return value(api);
|
109 | });
|
110 | };
|
111 |
|
112 | this.promise = new Promise(function (res) {
|
113 | _this.resolve = function () {
|
114 | return res(_this.getChannel());
|
115 | };
|
116 | });
|
117 | };
|
118 |
|
119 | var KEY = '__STORYBOOK_ADDONS';
|
120 |
|
121 | function getAddonsStore() {
|
122 | if (!global[KEY]) {
|
123 | global[KEY] = new AddonStore();
|
124 | }
|
125 |
|
126 | return global[KEY];
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | export var addons = getAddonsStore(); |
\ | No newline at end of file |