UNPKG

2.56 kBJavaScriptView Raw
1function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
3import "core-js/modules/es.string.replace.js";
4import "core-js/modules/es.regexp.exec.js";
5import "core-js/modules/es.array.join.js";
6import "core-js/modules/es.string.split.js";
7import "core-js/modules/es.function.name.js";
8import "core-js/modules/es.array.concat.js";
9import "core-js/modules/es.object.assign.js";
10import global from 'global';
11import React from 'react';
12import { Consumer, isRoot, isGroup, isStory } from '@storybook/api';
13import { Preview } from '../components/preview/preview';
14var PREVIEW_URL = global.PREVIEW_URL;
15
16var splitTitleAddExtraSpace = function splitTitleAddExtraSpace(input) {
17 return input.split('/').join(' / ').replace(/\s\s/, ' ');
18};
19
20var getDescription = function getDescription(item) {
21 if (isRoot(item)) {
22 return item.name ? "".concat(item.name, " \u22C5 Storybook") : 'Storybook';
23 }
24
25 if (isGroup(item)) {
26 return item.name ? "".concat(item.name, " \u22C5 Storybook") : 'Storybook';
27 }
28
29 if (isStory(item)) {
30 var kind = item.kind,
31 name = item.name;
32 return kind && name ? splitTitleAddExtraSpace("".concat(kind, " - ").concat(name, " \u22C5 Storybook")) : 'Storybook';
33 }
34
35 return 'Storybook';
36};
37
38var mapper = function mapper(_ref) {
39 var api = _ref.api,
40 state = _ref.state;
41 var layout = state.layout,
42 location = state.location,
43 customQueryParams = state.customQueryParams,
44 storyId = state.storyId,
45 refs = state.refs,
46 viewMode = state.viewMode,
47 path = state.path,
48 refId = state.refId;
49 var story = api.getData(storyId, refId);
50 var docsOnly = story && story.parameters ? !!story.parameters.docsOnly : false;
51 return {
52 api: api,
53 story: story,
54 options: layout,
55 description: getDescription(story),
56 viewMode: viewMode,
57 path: path,
58 refs: refs,
59 storyId: storyId,
60 baseUrl: PREVIEW_URL || 'iframe.html',
61 queryParams: customQueryParams,
62 docsOnly: docsOnly,
63 location: location
64 };
65};
66
67var PreviewConnected = /*#__PURE__*/React.memo(function (props) {
68 return /*#__PURE__*/React.createElement(Consumer, {
69 filter: mapper
70 }, function (fromState) {
71 return /*#__PURE__*/React.createElement(Preview, _extends({}, props, fromState));
72 });
73});
74export default PreviewConnected;
\No newline at end of file