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