Skip to content

Commit 5274e7d

Browse files
committed
Add register.js
1 parent 01aba5c commit 5274e7d

File tree

3 files changed

+211
-1
lines changed

3 files changed

+211
-1
lines changed

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"editorGroup.border": "#bf82c6",
4+
"panel.border": "#bf82c6",
5+
"sideBar.border": "#bf82c6",
6+
"statusBar.background": "#bf82c6",
7+
"statusBar.foreground": "#15202b",
8+
"statusBarItem.hoverBackground": "#ad5fb6",
9+
"tab.activeBorder": "#bf82c6",
10+
"titleBar.activeBackground": "#bf82c6",
11+
"titleBar.activeForeground": "#15202b",
12+
"titleBar.inactiveBackground": "#bf82c699",
13+
"titleBar.inactiveForeground": "#15202b99"
14+
},
15+
"peacock.color": "#bf82c6"
16+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@storybook/addon-devkit",
3-
"version": "1.3.6",
3+
"version": "1.3.7",
44
"description": "Storybook Addon Development Kit",
55
"author": {
66
"name": "Oleg Proskurin",

register.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.register = void 0;
7+
8+
var _react = _interopRequireDefault(require("react"));
9+
10+
var _addons = _interopRequireWildcard(require("@storybook/addons"));
11+
12+
var _coreEvents = require("@storybook/core-events");
13+
14+
var _rect = _interopRequireDefault(require("@reach/rect"));
15+
16+
var _config = require("./dist/config");
17+
18+
var _withChannel = _interopRequireDefault(require("./dist/withChannel"));
19+
20+
var _Layout = require("./dist/Layout");
21+
22+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
23+
24+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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; }
25+
26+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27+
28+
function _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); }
29+
30+
// todo: remove
31+
const panelDimesions = rect => rect ? {
32+
width: rect.width,
33+
height: rect.height,
34+
isLandscape: rect.width >= rect.height
35+
} : {};
36+
37+
const addonLayout = isLandscape => {
38+
const Layout = ({
39+
style,
40+
children,
41+
...props
42+
}) => _react.default.createElement("div", _extends({
43+
name: "addon-layout",
44+
style: {
45+
display: 'flex',
46+
flexDirection: isLandscape ? 'row' : 'column',
47+
justifyContent: 'space-between',
48+
alignItems: 'stretch',
49+
height: '100%',
50+
...style
51+
}
52+
}, props), children);
53+
54+
return Layout;
55+
};
56+
57+
const addonBlock = isLandscape => {
58+
const Block = ({
59+
style,
60+
children,
61+
size,
62+
...props
63+
}) => _react.default.createElement("div", _extends({
64+
name: "addon-block",
65+
style: {
66+
flexGrow: 1,
67+
...(size ? { ...(isLandscape ? {
68+
width: size
69+
} : {
70+
height: size
71+
}),
72+
flexGrow: undefined
73+
} : { ...(isLandscape ? {
74+
width: 2
75+
} : {
76+
height: 2
77+
})
78+
}),
79+
...style
80+
}
81+
}, props), children);
82+
83+
return Block;
84+
};
85+
86+
class PanelHOC extends _react.default.Component {
87+
constructor(props) {
88+
super(props);
89+
const urlState = props.api.getUrlState();
90+
this.state = { ...urlState
91+
};
92+
props.api.on(_coreEvents.STORY_CHANGED, (kind, story) => this.setState({
93+
kind,
94+
story
95+
}));
96+
}
97+
98+
render() {
99+
const Panel = this.props.component;
100+
const {
101+
api,
102+
active,
103+
data,
104+
setData,
105+
config,
106+
isFirstDataReceived
107+
} = this.props;
108+
const {
109+
ADDON_ID,
110+
PANEL_ID,
111+
PANEL_Title
112+
} = config;
113+
const {
114+
kind,
115+
story
116+
} = this.state;
117+
if (!active) return null;
118+
return _react.default.createElement(_rect.default, null, ({
119+
rect,
120+
ref
121+
}) => {
122+
const dim = panelDimesions(rect);
123+
const Layout = addonLayout(dim.isLandscape);
124+
const Block = addonBlock(dim.isLandscape);
125+
return _react.default.createElement("div", {
126+
ref: ref,
127+
name: "addon-holder",
128+
style: {
129+
height: '100%'
130+
}
131+
}, _react.default.createElement(_Layout.LayoutProvider, null, _react.default.createElement(Panel, _extends({}, this.props.actions, this.props.selectors, {
132+
api: api,
133+
active: active,
134+
store: data,
135+
setData: setData,
136+
kind: kind,
137+
story: story,
138+
ADDON_ID: ADDON_ID,
139+
PANEL_ID: PANEL_ID,
140+
PANEL_Title: PANEL_Title,
141+
rect: dim,
142+
Layout: Layout,
143+
Block: Block,
144+
isFirstDataReceived: isFirstDataReceived
145+
}))));
146+
});
147+
}
148+
149+
}
150+
151+
const register = (storeSelectors, createActions) => (Panel, {
152+
type = _addons.types.PANEL,
153+
initData
154+
} = {}) => {
155+
const config = (0, _config.getConfig)();
156+
const {
157+
EVENT_ID_INIT,
158+
EVENT_ID_DATA,
159+
EVENT_ID_BACK,
160+
ADDON_ID,
161+
PANEL_Title,
162+
PANEL_ID
163+
} = config;
164+
const WithChannel = (0, _withChannel.default)({
165+
EVENT_ID_INIT,
166+
EVENT_ID_DATA,
167+
EVENT_ID_BACK,
168+
ADDON_ID,
169+
initData,
170+
panel: true,
171+
storeSelectors,
172+
createActions
173+
})(PanelHOC);
174+
175+
_addons.default.register(ADDON_ID, api => {
176+
_addons.default.add(PANEL_ID, {
177+
title: PANEL_Title,
178+
type,
179+
id: PANEL_ID,
180+
render: ({
181+
active,
182+
key
183+
} = {}) => _react.default.createElement(WithChannel, {
184+
key: key,
185+
api: api,
186+
active: active,
187+
component: Panel,
188+
config: config
189+
})
190+
});
191+
});
192+
};
193+
194+
exports.register = register;

0 commit comments

Comments
 (0)