@storybook/react-native 6.5.3 → 6.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +4 -1
- package/dist/hooks.js +75 -36
- package/dist/index.js +40 -18
- package/dist/preview/View.js +165 -88
- package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +127 -81
- package/dist/preview/components/OnDeviceUI/Panel.js +24 -15
- package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.js +17 -10
- package/dist/preview/components/OnDeviceUI/addons/Addons.js +32 -23
- package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.js +69 -41
- package/dist/preview/components/OnDeviceUI/addons/List.js +15 -9
- package/dist/preview/components/OnDeviceUI/addons/Wrapper.js +27 -18
- package/dist/preview/components/OnDeviceUI/addons/index.js +8 -1
- package/dist/preview/components/OnDeviceUI/animation.js +37 -29
- package/dist/preview/components/OnDeviceUI/index.js +8 -1
- package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +31 -24
- package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.js +26 -14
- package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.js +26 -17
- package/dist/preview/components/OnDeviceUI/navigation/constants.js +6 -3
- package/dist/preview/components/OnDeviceUI/navigation/index.js +8 -1
- package/dist/preview/components/Shared/icons.js +28 -10
- package/dist/preview/components/Shared/layout.js +21 -4
- package/dist/preview/components/Shared/tabs.js +41 -27
- package/dist/preview/components/Shared/theme.js +11 -8
- package/dist/preview/components/StoryListView/StoryListView.js +161 -97
- package/dist/preview/components/StoryListView/index.js +8 -1
- package/dist/preview/components/StoryView/StoryView.js +30 -14
- package/dist/preview/components/StoryView/index.js +8 -1
- package/dist/preview/executeLoadable.d.ts +4 -1
- package/dist/preview/executeLoadable.js +43 -23
- package/dist/preview/rn-host-detect.js +3 -1
- package/dist/preview/start.js +81 -56
- package/dist/types/types-6.0.js +2 -1
- package/dist/types/types.js +2 -1
- package/package.json +3 -3
- package/readme.md +97 -55
|
@@ -1,87 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
color: theme.storyList.search.textColor,
|
|
24
|
-
}));
|
|
25
|
-
const SearchContainer = styled.View(({ theme }) => ({
|
|
26
|
-
flexDirection: 'row',
|
|
27
|
-
alignItems: 'center',
|
|
28
|
-
margin: theme.panel.paddingHorizontal,
|
|
29
|
-
paddingVertical: theme.storyList.search.paddingVertical,
|
|
30
|
-
paddingStart: theme.storyList.search.paddingHorizontal,
|
|
31
|
-
borderColor: theme.storyList.search.borderColor,
|
|
32
|
-
borderWidth: theme.storyList.search.borderWidth,
|
|
33
|
-
borderRadius: theme.storyList.search.borderRadius,
|
|
34
|
-
backgroundColor: theme.storyList.search.backgroundColor,
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
35
23
|
}));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
38
|
};
|
|
42
|
-
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
var native_1 = __importDefault(require("@emotion/native"));
|
|
41
|
+
var addons_1 = require("@storybook/addons");
|
|
42
|
+
var core_events_1 = __importDefault(require("@storybook/core-events"));
|
|
43
|
+
var react_1 = __importStar(require("react"));
|
|
44
|
+
var react_native_1 = require("react-native");
|
|
45
|
+
var icons_1 = require("../Shared/icons");
|
|
46
|
+
var layout_1 = require("../Shared/layout");
|
|
47
|
+
var hooks_1 = require("../../../hooks");
|
|
48
|
+
var SectionHeaderText = native_1.default.Text(function (_a) {
|
|
49
|
+
var theme = _a.theme;
|
|
50
|
+
return ({
|
|
51
|
+
fontSize: theme.storyList.fontSize,
|
|
52
|
+
color: theme.storyList.headerTextColor,
|
|
53
|
+
fontWeight: theme.storyList.headerFontWeight,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
var StoryNameText = native_1.default.Text(function (_a) {
|
|
57
|
+
var selected = _a.selected, theme = _a.theme;
|
|
58
|
+
return ({
|
|
59
|
+
fontSize: theme.storyList.fontSize,
|
|
60
|
+
fontWeight: selected ? theme.storyList.storySelectedFontWeight : theme.storyList.storyFontWeight,
|
|
61
|
+
color: selected ? theme.storyList.storySelectedTextColor : theme.storyList.storyTextColor,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
var SEARCH_ICON_SIZE = 24;
|
|
65
|
+
var SearchInput = native_1.default.TextInput(__assign({ padding: 0 }, react_native_1.StyleSheet.absoluteFillObject), function (_a) {
|
|
66
|
+
var theme = _a.theme;
|
|
67
|
+
return ({
|
|
68
|
+
fontSize: theme.storyList.search.fontSize,
|
|
69
|
+
paddingStart: theme.storyList.search.paddingHorizontal + SEARCH_ICON_SIZE,
|
|
70
|
+
color: theme.storyList.search.textColor,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
var SearchContainer = native_1.default.View(function (_a) {
|
|
74
|
+
var theme = _a.theme;
|
|
75
|
+
return ({
|
|
76
|
+
flexDirection: 'row',
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
margin: theme.panel.paddingHorizontal,
|
|
79
|
+
paddingVertical: theme.storyList.search.paddingVertical,
|
|
80
|
+
paddingStart: theme.storyList.search.paddingHorizontal,
|
|
81
|
+
borderColor: theme.storyList.search.borderColor,
|
|
82
|
+
borderWidth: theme.storyList.search.borderWidth,
|
|
83
|
+
borderRadius: theme.storyList.search.borderRadius,
|
|
84
|
+
backgroundColor: theme.storyList.search.backgroundColor,
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
var SearchBar = function (props) {
|
|
88
|
+
var theme = (0, hooks_1.useTheme)();
|
|
89
|
+
return (react_1.default.createElement(SearchContainer, null,
|
|
90
|
+
react_1.default.createElement(icons_1.Icon, { name: "search", opacity: 0.5, color: 'white' }),
|
|
91
|
+
react_1.default.createElement(SearchInput, __assign({}, props, { autoCapitalize: "none", autoComplete: "off", autoCorrect: false, spellCheck: false, clearButtonMode: "while-editing", disableFullscreenUI: true, placeholderTextColor: theme.storyList.search.placeholderTextColor, returnKeyType: "search" }))));
|
|
92
|
+
};
|
|
93
|
+
var HeaderContainer = native_1.default.TouchableOpacity({
|
|
43
94
|
flexDirection: 'row',
|
|
44
95
|
alignItems: 'center',
|
|
45
|
-
}, (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
96
|
+
}, function (_a) {
|
|
97
|
+
var selected = _a.selected, theme = _a.theme;
|
|
98
|
+
return ({
|
|
99
|
+
marginTop: theme.storyList.sectionSpacing,
|
|
100
|
+
paddingHorizontal: theme.storyList.headerPaddingHorizontal,
|
|
101
|
+
paddingVertical: theme.storyList.headerPaddingVertical,
|
|
102
|
+
backgroundColor: selected ? theme.storyList.sectionActiveBackgroundColor : undefined,
|
|
103
|
+
borderTopLeftRadius: theme.storyList.sectionBorderRadius,
|
|
104
|
+
borderTopRightRadius: theme.storyList.sectionBorderRadius,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
var SectionHeader = react_1.default.memo(function (_a) {
|
|
108
|
+
var title = _a.title, onPress = _a.onPress;
|
|
109
|
+
var selected = (0, hooks_1.useIsStorySectionSelected)(title);
|
|
110
|
+
return (react_1.default.createElement(HeaderContainer, { key: title, selected: selected, onPress: onPress, activeOpacity: 0.8 },
|
|
111
|
+
react_1.default.createElement(icons_1.Icon, { name: "grid", width: 12, height: 12, marginRight: 6 }),
|
|
112
|
+
react_1.default.createElement(SectionHeaderText, { selected: selected }, title)));
|
|
58
113
|
});
|
|
59
|
-
|
|
114
|
+
var ItemTouchable = native_1.default.TouchableOpacity({
|
|
60
115
|
flexDirection: 'row',
|
|
61
116
|
alignItems: 'center',
|
|
62
|
-
}, (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
:
|
|
68
|
-
? theme.storyList.
|
|
69
|
-
:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
117
|
+
}, function (_a) {
|
|
118
|
+
var selected = _a.selected, sectionSelected = _a.sectionSelected, isLastItem = _a.isLastItem, theme = _a.theme;
|
|
119
|
+
return ({
|
|
120
|
+
padding: theme.storyList.storyPaddingHorizontal,
|
|
121
|
+
paddingStart: theme.storyList.storyIndent,
|
|
122
|
+
backgroundColor: selected
|
|
123
|
+
? theme.storyList.storySelectedBackgroundColor
|
|
124
|
+
: sectionSelected
|
|
125
|
+
? theme.storyList.sectionActiveBackgroundColor
|
|
126
|
+
: undefined,
|
|
127
|
+
borderBottomLeftRadius: isLastItem ? theme.storyList.sectionBorderRadius : undefined,
|
|
128
|
+
borderBottomRightRadius: isLastItem ? theme.storyList.sectionBorderRadius : undefined,
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
var ListItem = react_1.default.memo(function (_a) {
|
|
132
|
+
var storyId = _a.storyId, kind = _a.kind, title = _a.title, isLastItem = _a.isLastItem, onPress = _a.onPress;
|
|
133
|
+
var selected = (0, hooks_1.useIsStorySelected)(storyId);
|
|
134
|
+
var sectionSelected = (0, hooks_1.useIsStorySectionSelected)(kind);
|
|
135
|
+
return (react_1.default.createElement(ItemTouchable, { key: title, onPress: onPress, activeOpacity: 0.8, testID: "Storybook.ListItem.".concat(kind, ".").concat(title), accessibilityLabel: "Storybook.ListItem.".concat(title), selected: selected, sectionSelected: sectionSelected, isLastItem: isLastItem },
|
|
136
|
+
react_1.default.createElement(icons_1.Icon, { width: 14, height: 14, name: selected ? 'story-white' : 'story-blue', marginRight: 6 }),
|
|
137
|
+
react_1.default.createElement(StoryNameText, { selected: selected }, title)));
|
|
138
|
+
}, function (prevProps, nextProps) { return prevProps.storyId === nextProps.storyId; });
|
|
139
|
+
var getStories = function (storyIndex) {
|
|
81
140
|
if (!storyIndex) {
|
|
82
141
|
return [];
|
|
83
142
|
}
|
|
84
|
-
|
|
143
|
+
var groupedStories = Object.values(storyIndex.stories).reduce(function (acc, story) {
|
|
85
144
|
var _a, _b;
|
|
86
145
|
acc[story.title] = {
|
|
87
146
|
title: story.title,
|
|
@@ -91,47 +150,52 @@ const getStories = (storyIndex) => {
|
|
|
91
150
|
}, {});
|
|
92
151
|
return Object.values(groupedStories);
|
|
93
152
|
};
|
|
94
|
-
|
|
153
|
+
var styles = react_native_1.StyleSheet.create({
|
|
95
154
|
sectionList: { flex: 1 },
|
|
96
155
|
sectionListContentContainer: { paddingBottom: 6 },
|
|
97
156
|
});
|
|
98
157
|
function keyExtractor(item, index) {
|
|
99
158
|
return item.id + index;
|
|
100
159
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
160
|
+
var StoryListView = function (_a) {
|
|
161
|
+
var storyIndex = _a.storyIndex;
|
|
162
|
+
var originalData = (0, react_1.useMemo)(function () { return getStories(storyIndex); }, [storyIndex]);
|
|
163
|
+
var _b = (0, react_1.useState)(originalData), data = _b[0], setData = _b[1];
|
|
164
|
+
var theme = (0, hooks_1.useTheme)();
|
|
165
|
+
var handleChangeSearchText = function (text) {
|
|
166
|
+
var query = text.trim();
|
|
107
167
|
if (!query) {
|
|
108
168
|
setData(originalData);
|
|
109
169
|
return;
|
|
110
170
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
171
|
+
var checkValue = function (value) { return value.toLowerCase().includes(query.toLowerCase()); };
|
|
172
|
+
var filteredData = originalData.reduce(function (acc, story) {
|
|
173
|
+
var hasTitle = checkValue(story.title);
|
|
174
|
+
var hasKind = story.data.some(function (ref) { return checkValue(ref.name); });
|
|
115
175
|
if (hasTitle || hasKind) {
|
|
116
|
-
acc.push(
|
|
176
|
+
acc.push(__assign(__assign({}, story), {
|
|
117
177
|
// in case the query matches component's title, all of its stories will be shown
|
|
118
|
-
data: !hasTitle ? story.data.filter((ref)
|
|
178
|
+
data: !hasTitle ? story.data.filter(function (ref) { return checkValue(ref.name); }) : story.data }));
|
|
119
179
|
}
|
|
120
180
|
return acc;
|
|
121
181
|
}, []);
|
|
122
182
|
setData(filteredData);
|
|
123
183
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
channel.emit(
|
|
184
|
+
var changeStory = function (storyId) {
|
|
185
|
+
var channel = addons_1.addons.getChannel();
|
|
186
|
+
channel.emit(core_events_1.default.SET_CURRENT_STORY, { storyId: storyId });
|
|
127
187
|
};
|
|
128
|
-
|
|
129
|
-
|
|
188
|
+
var renderItem = react_1.default.useCallback(function (_a) {
|
|
189
|
+
var item = _a.item, index = _a.index, section = _a.section;
|
|
190
|
+
return (react_1.default.createElement(ListItem, { storyId: item.id, title: item.name, kind: item.title, isLastItem: index === section.data.length - 1, onPress: function () { return changeStory(item.id); } }));
|
|
191
|
+
}, []);
|
|
192
|
+
var renderSectionHeader = react_1.default.useCallback(function (_a) {
|
|
193
|
+
var _b = _a.section, title = _b.title, sectionData = _b.data;
|
|
194
|
+
return (react_1.default.createElement(SectionHeader, { title: title, onPress: function () { return changeStory(sectionData[0].id); } }));
|
|
130
195
|
}, []);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
React.createElement(SectionList, { style: styles.sectionList, contentContainerStyle: [
|
|
196
|
+
return (react_1.default.createElement(layout_1.Box, { flex: true },
|
|
197
|
+
react_1.default.createElement(SearchBar, { testID: "Storybook.ListView.SearchBar", onChangeText: handleChangeSearchText, placeholder: "Find by name" }),
|
|
198
|
+
react_1.default.createElement(react_native_1.SectionList, { style: styles.sectionList, contentContainerStyle: [
|
|
135
199
|
styles.sectionListContentContainer,
|
|
136
200
|
{
|
|
137
201
|
paddingVertical: theme.panel.paddingVertical,
|
|
@@ -139,4 +203,4 @@ const StoryListView = ({ storyIndex }) => {
|
|
|
139
203
|
},
|
|
140
204
|
], testID: "Storybook.ListView", renderItem: renderItem, renderSectionHeader: renderSectionHeader, keyExtractor: keyExtractor, sections: data, stickySectionHeadersEnabled: false })));
|
|
141
205
|
};
|
|
142
|
-
|
|
206
|
+
exports.default = react_1.default.memo(StoryListView);
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var StoryListView_1 = require("./StoryListView");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StoryListView_1).default; } });
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var react_1 = __importDefault(require("react"));
|
|
18
|
+
var react_native_1 = require("react-native");
|
|
19
|
+
var hooks_1 = require("../../../hooks");
|
|
20
|
+
var layout_1 = require("../Shared/layout");
|
|
5
21
|
/**
|
|
6
22
|
* This is a handler for `onStartShouldSetResponder`, which dismisses the
|
|
7
23
|
* keyboard as a side effect but then responds with `false` to the responder
|
|
@@ -14,18 +30,18 @@ import { Box } from '../Shared/layout';
|
|
|
14
30
|
* as `ScrollView`.
|
|
15
31
|
*/
|
|
16
32
|
function dismissOnStartResponder() {
|
|
17
|
-
Keyboard.dismiss();
|
|
33
|
+
react_native_1.Keyboard.dismiss();
|
|
18
34
|
return false;
|
|
19
35
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
var StoryView = function () {
|
|
37
|
+
var context = (0, hooks_1.useStoryContext)();
|
|
38
|
+
var id = context === null || context === void 0 ? void 0 : context.id;
|
|
39
|
+
var backgroundColor = (0, hooks_1.useTheme)().backgroundColor;
|
|
24
40
|
if (context && context.unboundStoryFn) {
|
|
25
|
-
|
|
26
|
-
return (
|
|
41
|
+
var StoryComponent = context.unboundStoryFn;
|
|
42
|
+
return (react_1.default.createElement(layout_1.Box, { flex: true, key: id, testID: id, onStartShouldSetResponder: dismissOnStartResponder, backgroundColor: backgroundColor }, StoryComponent && react_1.default.createElement(StoryComponent, __assign({}, context))));
|
|
27
43
|
}
|
|
28
|
-
return (
|
|
29
|
-
|
|
44
|
+
return (react_1.default.createElement(layout_1.Box, { flex: true, padding: 16, alignItems: "center", justifyContent: "center" },
|
|
45
|
+
react_1.default.createElement(react_native_1.Text, null, "Please open the sidebar and select a story to preview.")));
|
|
30
46
|
};
|
|
31
|
-
|
|
47
|
+
exports.default = react_1.default.memo(StoryView);
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var StoryView_1 = require("./StoryView");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StoryView_1).default; } });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="webpack-env" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { ModuleExports } from '@storybook/store';
|
|
3
|
+
import { Path, ModuleExports } from '@storybook/store';
|
|
4
4
|
import { Loadable } from '../types/types';
|
|
5
|
+
declare global {
|
|
6
|
+
var lastExportsMap: Map<Path, ModuleExports>;
|
|
7
|
+
}
|
|
5
8
|
/**
|
|
6
9
|
* Executes a Loadable (function that returns exports or require context(s))
|
|
7
10
|
* and returns a map of filename => module exports
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeLoadableForChanges = exports.executeLoadable = void 0;
|
|
4
|
+
var client_logger_1 = require("@storybook/client-logger");
|
|
2
5
|
/**
|
|
3
6
|
* Executes a Loadable (function that returns exports or require context(s))
|
|
4
7
|
* and returns a map of filename => module exports
|
|
@@ -6,8 +9,8 @@ import { logger } from '@storybook/client-logger';
|
|
|
6
9
|
* @param loadable Loadable
|
|
7
10
|
* @returns Map<Path, ModuleExports>
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
function executeLoadable(loadable) {
|
|
13
|
+
var reqs = null;
|
|
11
14
|
// todo discuss / improve type check
|
|
12
15
|
if (Array.isArray(loadable)) {
|
|
13
16
|
reqs = loadable;
|
|
@@ -15,30 +18,37 @@ export function executeLoadable(loadable) {
|
|
|
15
18
|
else if (loadable.keys) {
|
|
16
19
|
reqs = [loadable]; // todo: test with metro require context
|
|
17
20
|
}
|
|
18
|
-
|
|
21
|
+
var exportsMap = new Map();
|
|
19
22
|
if (reqs) {
|
|
20
|
-
reqs.forEach((req)
|
|
21
|
-
req.keys().forEach((filename)
|
|
23
|
+
reqs.forEach(function (req) {
|
|
24
|
+
req.keys().forEach(function (filename) {
|
|
22
25
|
try {
|
|
23
|
-
|
|
26
|
+
var fileExports = req(filename);
|
|
24
27
|
exportsMap.set(typeof req.resolve === 'function' ? req.resolve(filename) : filename, fileExports);
|
|
25
28
|
}
|
|
26
29
|
catch (error) {
|
|
27
|
-
|
|
28
|
-
logger.error(
|
|
30
|
+
var errorString = error.message && error.stack ? "".concat(error.message, "\n ").concat(error.stack) : error.toString();
|
|
31
|
+
client_logger_1.logger.error("Unexpected error while loading ".concat(filename, ": ").concat(errorString));
|
|
29
32
|
}
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
36
|
else {
|
|
34
|
-
|
|
37
|
+
var exported = loadable();
|
|
35
38
|
if (typeof exported === 'object') {
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
var csfExports = Object.entries(exported).filter(function (_a) {
|
|
40
|
+
var _key = _a[0], value = _a[1];
|
|
41
|
+
return value.default != null;
|
|
42
|
+
});
|
|
43
|
+
exportsMap = new Map(csfExports.map(function (_a) {
|
|
44
|
+
var filePath = _a[0], fileExports = _a[1];
|
|
45
|
+
return [filePath, fileExports];
|
|
46
|
+
}));
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
return exportsMap;
|
|
41
50
|
}
|
|
51
|
+
exports.executeLoadable = executeLoadable;
|
|
42
52
|
global.lastExportsMap = new Map();
|
|
43
53
|
/**
|
|
44
54
|
* Executes a Loadable (function that returns exports or require context(s))
|
|
@@ -48,25 +58,35 @@ global.lastExportsMap = new Map();
|
|
|
48
58
|
* @param m NodeModule
|
|
49
59
|
* @returns { added: Map<Path, ModuleExports>, removed: Map<Path, ModuleExports> }
|
|
50
60
|
*/
|
|
51
|
-
|
|
61
|
+
function executeLoadableForChanges(loadable, m) {
|
|
52
62
|
var _a;
|
|
53
63
|
if ((_a = m === null || m === void 0 ? void 0 : m.hot) === null || _a === void 0 ? void 0 : _a.accept) {
|
|
54
64
|
m.hot.accept();
|
|
55
65
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
var lastExportsMap = global.lastExportsMap;
|
|
67
|
+
var exportsMap = executeLoadable(loadable);
|
|
68
|
+
var added = new Map();
|
|
59
69
|
Array.from(exportsMap.entries())
|
|
60
70
|
// Ignore files that do not have a default export
|
|
61
|
-
.filter((
|
|
71
|
+
.filter(function (_a) {
|
|
72
|
+
var fileExports = _a[1];
|
|
73
|
+
return !!fileExports.default;
|
|
74
|
+
})
|
|
62
75
|
// Ignore exports that are equal (by reference) to last time, this means the file hasn't changed
|
|
63
|
-
.filter(
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
.filter(function (_a) {
|
|
77
|
+
var fileName = _a[0], fileExports = _a[1];
|
|
78
|
+
return lastExportsMap.get(fileName) !== fileExports;
|
|
79
|
+
})
|
|
80
|
+
.forEach(function (_a) {
|
|
81
|
+
var fileName = _a[0], fileExports = _a[1];
|
|
82
|
+
return added.set(fileName, fileExports);
|
|
83
|
+
});
|
|
84
|
+
var removed = new Map();
|
|
66
85
|
Array.from(lastExportsMap.keys())
|
|
67
|
-
.filter((fileName)
|
|
68
|
-
.forEach((fileName)
|
|
86
|
+
.filter(function (fileName) { return !exportsMap.has(fileName); })
|
|
87
|
+
.forEach(function (fileName) { return removed.set(fileName, lastExportsMap.get(fileName)); });
|
|
69
88
|
// Save the value for the dispose() call above
|
|
70
89
|
global.lastExportsMap = exportsMap;
|
|
71
|
-
return { added, removed };
|
|
90
|
+
return { added: added, removed: removed };
|
|
72
91
|
}
|
|
92
|
+
exports.executeLoadableForChanges = executeLoadableForChanges;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
/*
|
|
3
4
|
* It only for Debug Remotely mode for Android
|
|
4
5
|
* When __DEV__ === false, we can't use window.require('NativeModules')
|
|
@@ -45,7 +46,7 @@ function getByRNRequirePolyfill(hostname) {
|
|
|
45
46
|
* Get React Native server IP if hostname is `localhost`
|
|
46
47
|
* On Android emulator, the IP of host is `10.0.2.2` (Genymotion: 10.0.3.2)
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
function getHost(hostname) {
|
|
49
50
|
// Check if it in React Native environment
|
|
50
51
|
if (typeof __fbBatchedBridge !== 'object' ||
|
|
51
52
|
(hostname !== 'localhost' && hostname !== '127.0.0.1')) {
|
|
@@ -59,3 +60,4 @@ export default function getHost(hostname) {
|
|
|
59
60
|
// Otherwise, use RN's require polyfill
|
|
60
61
|
return getByRNRequirePolyfill(hostname);
|
|
61
62
|
}
|
|
63
|
+
exports.default = getHost;
|