@storybook/addon-docs 6.5.0-alpha.54 → 6.5.0-alpha.57

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.
@@ -89,16 +89,20 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
89
89
 
90
90
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
91
91
 
92
- var useArgs = function useArgs(storyId, context) {
93
- var channel = _addons.addons.getChannel();
94
-
92
+ var getContext = function getContext(storyId, context) {
95
93
  var story = context.storyById(storyId);
96
94
 
97
95
  if (!story) {
98
96
  throw new Error("Unknown story: ".concat(storyId));
99
97
  }
100
98
 
101
- var storyContext = context.getStoryContext(story);
99
+ return context.getStoryContext(story);
100
+ };
101
+
102
+ var useArgs = function useArgs(storyId, context) {
103
+ var channel = _addons.addons.getChannel();
104
+
105
+ var storyContext = getContext(storyId, context);
102
106
 
103
107
  var _useState = (0, _react.useState)(storyContext.args),
104
108
  _useState2 = _slicedToArray(_useState, 2),
@@ -132,6 +136,29 @@ var useArgs = function useArgs(storyId, context) {
132
136
  return [args, updateArgs, resetArgs];
133
137
  };
134
138
 
139
+ var useGlobals = function useGlobals(storyId, context) {
140
+ var channel = _addons.addons.getChannel();
141
+
142
+ var storyContext = getContext(storyId, context);
143
+
144
+ var _useState3 = (0, _react.useState)(storyContext.globals),
145
+ _useState4 = _slicedToArray(_useState3, 2),
146
+ globals = _useState4[0],
147
+ setGlobals = _useState4[1];
148
+
149
+ (0, _react.useEffect)(function () {
150
+ var cb = function cb(changed) {
151
+ setGlobals(changed.globals);
152
+ };
153
+
154
+ channel.on(_coreEvents.default.GLOBALS_UPDATED, cb);
155
+ return function () {
156
+ return channel.off(_coreEvents.default.GLOBALS_UPDATED, cb);
157
+ };
158
+ }, []);
159
+ return [globals];
160
+ };
161
+
135
162
  var extractComponentArgTypes = function extractComponentArgTypes(component, _ref, include, exclude) {
136
163
  var id = _ref.id,
137
164
  storyById = _ref.storyById;
@@ -237,6 +264,10 @@ var StoryTable = function StoryTable(props) {
237
264
  updateArgs = _useArgs2[1],
238
265
  resetArgs = _useArgs2[2];
239
266
 
267
+ var _useGlobals = useGlobals(storyId, context),
268
+ _useGlobals2 = _slicedToArray(_useGlobals, 1),
269
+ globals = _useGlobals2[0];
270
+
240
271
  if (!story) return /*#__PURE__*/_react.default.createElement(_components.ArgsTable, {
241
272
  isLoading: true,
242
273
  updateArgs: updateArgs,
@@ -248,6 +279,7 @@ var StoryTable = function StoryTable(props) {
248
279
  var tabs = _defineProperty({}, mainLabel, {
249
280
  rows: argTypes,
250
281
  args: args,
282
+ globals: globals,
251
283
  updateArgs: updateArgs,
252
284
  resetArgs: resetArgs
253
285
  }); // Use the dynamically generated component tabs if there are no controls
@@ -137,7 +137,7 @@ var AnchorMdx = function AnchorMdx(props) {
137
137
  } // Links to other pages of SB should use the base URL of the top level iframe instead of the base URL of the preview iframe.
138
138
 
139
139
 
140
- if (target !== '_blank') {
140
+ if (target !== '_blank' && !href.startsWith('https://')) {
141
141
  return /*#__PURE__*/_react.default.createElement(A, _extends({
142
142
  href: href,
143
143
  onClick: function onClick(event) {
@@ -44,15 +44,19 @@ import { getComponentName } from './utils';
44
44
  import { lookupStoryId } from './Story';
45
45
  import { useStory } from './useStory';
46
46
 
47
- var useArgs = function useArgs(storyId, context) {
48
- var channel = addons.getChannel();
47
+ var getContext = function getContext(storyId, context) {
49
48
  var story = context.storyById(storyId);
50
49
 
51
50
  if (!story) {
52
51
  throw new Error("Unknown story: ".concat(storyId));
53
52
  }
54
53
 
55
- var storyContext = context.getStoryContext(story);
54
+ return context.getStoryContext(story);
55
+ };
56
+
57
+ var useArgs = function useArgs(storyId, context) {
58
+ var channel = addons.getChannel();
59
+ var storyContext = getContext(storyId, context);
56
60
 
57
61
  var _useState = useState(storyContext.args),
58
62
  _useState2 = _slicedToArray(_useState, 2),
@@ -86,6 +90,28 @@ var useArgs = function useArgs(storyId, context) {
86
90
  return [args, updateArgs, resetArgs];
87
91
  };
88
92
 
93
+ var useGlobals = function useGlobals(storyId, context) {
94
+ var channel = addons.getChannel();
95
+ var storyContext = getContext(storyId, context);
96
+
97
+ var _useState3 = useState(storyContext.globals),
98
+ _useState4 = _slicedToArray(_useState3, 2),
99
+ globals = _useState4[0],
100
+ setGlobals = _useState4[1];
101
+
102
+ useEffect(function () {
103
+ var cb = function cb(changed) {
104
+ setGlobals(changed.globals);
105
+ };
106
+
107
+ channel.on(Events.GLOBALS_UPDATED, cb);
108
+ return function () {
109
+ return channel.off(Events.GLOBALS_UPDATED, cb);
110
+ };
111
+ }, []);
112
+ return [globals];
113
+ };
114
+
89
115
  export var extractComponentArgTypes = function extractComponentArgTypes(component, _ref, include, exclude) {
90
116
  var id = _ref.id,
91
117
  storyById = _ref.storyById;
@@ -187,6 +213,10 @@ export var StoryTable = function StoryTable(props) {
187
213
  updateArgs = _useArgs2[1],
188
214
  resetArgs = _useArgs2[2];
189
215
 
216
+ var _useGlobals = useGlobals(storyId, context),
217
+ _useGlobals2 = _slicedToArray(_useGlobals, 1),
218
+ globals = _useGlobals2[0];
219
+
190
220
  if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
191
221
  isLoading: true,
192
222
  updateArgs: updateArgs,
@@ -198,6 +228,7 @@ export var StoryTable = function StoryTable(props) {
198
228
  var tabs = _defineProperty({}, mainLabel, {
199
229
  rows: argTypes,
200
230
  args: args,
231
+ globals: globals,
201
232
  updateArgs: updateArgs,
202
233
  resetArgs: resetArgs
203
234
  }); // Use the dynamically generated component tabs if there are no controls
@@ -105,7 +105,7 @@ export var AnchorMdx = function AnchorMdx(props) {
105
105
  } // Links to other pages of SB should use the base URL of the top level iframe instead of the base URL of the preview iframe.
106
106
 
107
107
 
108
- if (target !== '_blank') {
108
+ if (target !== '_blank' && !href.startsWith('https://')) {
109
109
  return /*#__PURE__*/React.createElement(A, _extends({
110
110
  href: href,
111
111
  onClick: function onClick(event) {
@@ -12,15 +12,19 @@ import { getComponentName } from './utils';
12
12
  import { lookupStoryId } from './Story';
13
13
  import { useStory } from './useStory';
14
14
 
15
- const useArgs = (storyId, context) => {
16
- const channel = addons.getChannel();
15
+ const getContext = (storyId, context) => {
17
16
  const story = context.storyById(storyId);
18
17
 
19
18
  if (!story) {
20
19
  throw new Error(`Unknown story: ${storyId}`);
21
20
  }
22
21
 
23
- const storyContext = context.getStoryContext(story);
22
+ return context.getStoryContext(story);
23
+ };
24
+
25
+ const useArgs = (storyId, context) => {
26
+ const channel = addons.getChannel();
27
+ const storyContext = getContext(storyId, context);
24
28
  const [args, setArgs] = useState(storyContext.args);
25
29
  useEffect(() => {
26
30
  const cb = changed => {
@@ -43,6 +47,21 @@ const useArgs = (storyId, context) => {
43
47
  return [args, updateArgs, resetArgs];
44
48
  };
45
49
 
50
+ const useGlobals = (storyId, context) => {
51
+ const channel = addons.getChannel();
52
+ const storyContext = getContext(storyId, context);
53
+ const [globals, setGlobals] = useState(storyContext.globals);
54
+ useEffect(() => {
55
+ const cb = changed => {
56
+ setGlobals(changed.globals);
57
+ };
58
+
59
+ channel.on(Events.GLOBALS_UPDATED, cb);
60
+ return () => channel.off(Events.GLOBALS_UPDATED, cb);
61
+ }, []);
62
+ return [globals];
63
+ };
64
+
46
65
  export const extractComponentArgTypes = (component, {
47
66
  id,
48
67
  storyById
@@ -139,6 +158,7 @@ export const StoryTable = props => {
139
158
  const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
140
159
 
141
160
  let [args, updateArgs, resetArgs] = useArgs(storyId, context);
161
+ const [globals] = useGlobals(storyId, context);
142
162
  if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
143
163
  isLoading: true,
144
164
  updateArgs: updateArgs,
@@ -150,6 +170,7 @@ export const StoryTable = props => {
150
170
  [mainLabel]: {
151
171
  rows: argTypes,
152
172
  args,
173
+ globals,
153
174
  updateArgs,
154
175
  resetArgs
155
176
  }
@@ -100,7 +100,7 @@ export const AnchorMdx = props => {
100
100
  } // Links to other pages of SB should use the base URL of the top level iframe instead of the base URL of the preview iframe.
101
101
 
102
102
 
103
- if (target !== '_blank') {
103
+ if (target !== '_blank' && !href.startsWith('https://')) {
104
104
  return /*#__PURE__*/React.createElement(A, _extends({
105
105
  href: href,
106
106
  onClick: event => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-docs",
3
- "version": "6.5.0-alpha.54",
3
+ "version": "6.5.0-alpha.57",
4
4
  "description": "Document component usage and properties in Markdown",
5
5
  "keywords": [
6
6
  "addon",
@@ -59,20 +59,20 @@
59
59
  "@babel/preset-env": "^7.12.11",
60
60
  "@jest/transform": "^26.6.2",
61
61
  "@mdx-js/react": "^1.6.22",
62
- "@storybook/addons": "6.5.0-alpha.54",
63
- "@storybook/api": "6.5.0-alpha.54",
64
- "@storybook/components": "6.5.0-alpha.54",
65
- "@storybook/core-common": "6.5.0-alpha.54",
66
- "@storybook/core-events": "6.5.0-alpha.54",
67
- "@storybook/csf": "0.0.2--canary.507502b.0",
68
- "@storybook/docs-tools": "6.5.0-alpha.54",
62
+ "@storybook/addons": "6.5.0-alpha.57",
63
+ "@storybook/api": "6.5.0-alpha.57",
64
+ "@storybook/components": "6.5.0-alpha.57",
65
+ "@storybook/core-common": "6.5.0-alpha.57",
66
+ "@storybook/core-events": "6.5.0-alpha.57",
67
+ "@storybook/csf": "0.0.2--canary.7c6c115.0",
68
+ "@storybook/docs-tools": "6.5.0-alpha.57",
69
69
  "@storybook/mdx1-csf": "canary",
70
- "@storybook/node-logger": "6.5.0-alpha.54",
71
- "@storybook/postinstall": "6.5.0-alpha.54",
72
- "@storybook/preview-web": "6.5.0-alpha.54",
73
- "@storybook/source-loader": "6.5.0-alpha.54",
74
- "@storybook/store": "6.5.0-alpha.54",
75
- "@storybook/theming": "6.5.0-alpha.54",
70
+ "@storybook/node-logger": "6.5.0-alpha.57",
71
+ "@storybook/postinstall": "6.5.0-alpha.57",
72
+ "@storybook/preview-web": "6.5.0-alpha.57",
73
+ "@storybook/source-loader": "6.5.0-alpha.57",
74
+ "@storybook/store": "6.5.0-alpha.57",
75
+ "@storybook/theming": "6.5.0-alpha.57",
76
76
  "babel-loader": "^8.0.0",
77
77
  "core-js": "^3.8.2",
78
78
  "fast-deep-equal": "^3.1.3",
@@ -108,7 +108,7 @@
108
108
  "publishConfig": {
109
109
  "access": "public"
110
110
  },
111
- "gitHead": "2048f366e90e668c3f462d81f5b372a19902b67f",
111
+ "gitHead": "896ac6a6110669efbb754ed62ed211274c0d3547",
112
112
  "sbmodern": "dist/modern/index.js",
113
113
  "storybook": {
114
114
  "displayName": "Docs",