UNPKG

4.99 kBJavaScriptView Raw
1"use strict";
2
3function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
5require("core-js/modules/es.symbol");
6
7require("core-js/modules/es.array.index-of");
8
9require("core-js/modules/es.object.assign");
10
11require("core-js/modules/es.object.keys");
12
13Object.defineProperty(exports, "__esModule", {
14 value: true
15});
16exports.withOptions = exports.setOptions = void 0;
17
18var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
19
20var _addons = _interopRequireWildcard(require("@storybook/addons"));
21
22var _constants = _interopRequireDefault(require("./constants"));
23
24function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
25
26function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
28function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
30function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
32function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
34function emitOptions(options) {
35 var channel = _addons["default"].getChannel();
36
37 if (!channel) {
38 throw new Error('Failed to find addon channel. This may be due to https://github.com/storybookjs/storybook/issues/1192.');
39 } // since 'undefined' and 'null' are the valid values we don't want to
40 // override the hierarchySeparator or hierarchyRootSeparator if the prop is missing
41
42
43 channel.emit(_constants["default"].SET, {
44 options: options
45 });
46} // setOptions function will send Storybook UI options when the channel is
47// ready. If called before, options will be cached until it can be sent.
48
49
50var globalOptions = {};
51var setOptions = (0, _utilDeprecate["default"])(function (options) {
52 globalOptions = options;
53 emitOptions(options);
54}, '`setOptions(options)` is deprecated. Please use the `withOptions(options)` decorator globally.');
55exports.setOptions = setOptions;
56var withOptions = (0, _addons.makeDecorator)({
57 name: 'withOptions',
58 parameterName: 'options',
59 skipIfNoParametersOrOptions: false,
60 wrapper: (0, _utilDeprecate["default"])(function (getStory, context, _ref) {
61 var inputOptions = _ref.options,
62 parameters = _ref.parameters;
63
64 // do not send hierarchy related options over the channel
65 var _globalOptions$inputO = Object.assign({}, globalOptions, {}, inputOptions, {}, parameters),
66 hierarchySeparator = _globalOptions$inputO.hierarchySeparator,
67 hierarchyRootSeparator = _globalOptions$inputO.hierarchyRootSeparator,
68 change = _objectWithoutProperties(_globalOptions$inputO, ["hierarchySeparator", "hierarchyRootSeparator"]);
69
70 if (Object.keys(change).length) {
71 emitOptions(Object.assign({}, globalOptions, {}, inputOptions, {}, parameters));
72 } // MUTATION !
73 // eslint-disable-next-line no-param-reassign
74
75
76 context.options = Object.assign({}, globalOptions, {}, inputOptions, {}, parameters);
77 return getStory(Object.assign({}, context, {
78 options: Object.assign({}, globalOptions, {}, inputOptions, {}, parameters)
79 }));
80 }, 'withOptions is deprecated, use addParameters({ options: {} }) instead')
81});
82exports.withOptions = withOptions;
83
84if (module && module.hot && module.hot.decline) {
85 module.hot.decline();
86}
\No newline at end of file