@storybook/addon-docs 6.1.7 → 6.1.11

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.
@@ -9,7 +9,7 @@ interface MetaProps {
9
9
  decorators?: [Decorator];
10
10
  parameters?: Parameters;
11
11
  args?: Args;
12
- argTypes: ArgTypes;
12
+ argTypes?: ArgTypes;
13
13
  }
14
14
  /**
15
15
  * This component is used to declare component metadata in docs
@@ -28,5 +28,5 @@ declare type Docgen = {
28
28
  version: number;
29
29
  };
30
30
  export declare const extractArgTypes: ArgTypesExtractor;
31
- export declare const createArgTypes: (docs: Docgen) => ArgTypes;
31
+ export declare const createArgTypes: (docgen: Docgen) => ArgTypes;
32
32
  export {};
@@ -15,22 +15,32 @@ Object.defineProperty(exports, "__esModule", {
15
15
  });
16
16
  exports.createArgTypes = exports.extractArgTypes = void 0;
17
17
 
18
+ var _clientLogger = require("@storybook/client-logger");
19
+
18
20
  var extractArgTypes = function extractArgTypes(component) {
19
- // eslint-disable-next-line new-cap
20
- var comp = new component({
21
- props: {}
22
- }); // eslint-disable-next-line no-underscore-dangle
21
+ try {
22
+ // eslint-disable-next-line new-cap
23
+ var comp = new component({
24
+ props: {}
25
+ }); // eslint-disable-next-line no-underscore-dangle
26
+
27
+ var docgen = comp.__docgen;
28
+
29
+ if (docgen) {
30
+ return createArgTypes(docgen);
31
+ }
32
+ } catch (err) {
33
+ _clientLogger.logger.log("Error extracting argTypes: ".concat(err));
34
+ }
23
35
 
24
- var docs = comp.__docgen;
25
- var results = createArgTypes(docs);
26
- return results;
36
+ return {};
27
37
  };
28
38
 
29
39
  exports.extractArgTypes = extractArgTypes;
30
40
 
31
- var createArgTypes = function createArgTypes(docs) {
41
+ var createArgTypes = function createArgTypes(docgen) {
32
42
  var results = {};
33
- docs.data.forEach(function (item) {
43
+ docgen.data.forEach(function (item) {
34
44
  results[item.name] = {
35
45
  control: {
36
46
  type: parseType(item.type.type)
@@ -24,6 +24,8 @@ require("core-js/modules/es.array.join");
24
24
 
25
25
  require("core-js/modules/es.array.map");
26
26
 
27
+ require("core-js/modules/es.array.reduce");
28
+
27
29
  require("core-js/modules/es.array.slice");
28
30
 
29
31
  require("core-js/modules/es.date.to-string");
@@ -44,6 +46,8 @@ require("core-js/modules/es.string.iterator");
44
46
 
45
47
  require("core-js/modules/es.string.replace");
46
48
 
49
+ require("core-js/modules/es.string.split");
50
+
47
51
  require("core-js/modules/web.dom-collections.iterator");
48
52
 
49
53
  Object.defineProperty(exports, "__esModule", {
@@ -66,6 +70,8 @@ var _shared = require("../../shared");
66
70
 
67
71
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
68
72
 
73
+ function _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); }
74
+
69
75
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
70
76
 
71
77
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -151,7 +157,7 @@ exports.sourceDecorator = sourceDecorator;
151
157
  function vnodeToString(vnode) {
152
158
  var _vnode$data, _vnode$componentOptio, _vnode$data2;
153
159
 
154
- var attrString = [].concat(_toConsumableArray(((_vnode$data = vnode.data) === null || _vnode$data === void 0 ? void 0 : _vnode$data.slot) ? [['slot', vnode.data.slot]] : []), _toConsumableArray(((_vnode$componentOptio = vnode.componentOptions) === null || _vnode$componentOptio === void 0 ? void 0 : _vnode$componentOptio.propsData) ? Object.entries(vnode.componentOptions.propsData) : []), _toConsumableArray(((_vnode$data2 = vnode.data) === null || _vnode$data2 === void 0 ? void 0 : _vnode$data2.attrs) ? Object.entries(vnode.data.attrs) : [])).filter(function (_ref, index, list) {
160
+ var attrString = [].concat(_toConsumableArray(((_vnode$data = vnode.data) === null || _vnode$data === void 0 ? void 0 : _vnode$data.slot) ? [['slot', vnode.data.slot]] : []), [['class', stringifyClassAttribute(vnode)]], _toConsumableArray(((_vnode$componentOptio = vnode.componentOptions) === null || _vnode$componentOptio === void 0 ? void 0 : _vnode$componentOptio.propsData) ? Object.entries(vnode.componentOptions.propsData) : []), _toConsumableArray(((_vnode$data2 = vnode.data) === null || _vnode$data2 === void 0 ? void 0 : _vnode$data2.attrs) ? Object.entries(vnode.data.attrs) : [])).filter(function (_ref, index, list) {
155
161
  var _ref2 = _slicedToArray(_ref, 1),
156
162
  name = _ref2[0];
157
163
 
@@ -200,8 +206,53 @@ function vnodeToString(vnode) {
200
206
  return "<".concat(tag, " ").concat(attrString, ">").concat(vnode.componentOptions.children.map(vnodeToString).join(''), "</").concat(tag, ">");
201
207
  }
202
208
 
209
+ function stringifyClassAttribute(vnode) {
210
+ var _vnode$data$staticCla, _vnode$data$staticCla2;
211
+
212
+ if (!vnode.data || !vnode.data.staticClass && !vnode.data["class"]) {
213
+ return undefined;
214
+ }
215
+
216
+ return [].concat(_toConsumableArray((_vnode$data$staticCla = (_vnode$data$staticCla2 = vnode.data.staticClass) === null || _vnode$data$staticCla2 === void 0 ? void 0 : _vnode$data$staticCla2.split(' ')) !== null && _vnode$data$staticCla !== void 0 ? _vnode$data$staticCla : []), _toConsumableArray(normalizeClassBinding(vnode.data["class"]))).filter(Boolean).join(' ') || undefined;
217
+ } // https://vuejs.org/v2/guide/class-and-style.html#Binding-HTML-Classes
218
+
219
+
220
+ function normalizeClassBinding(binding) {
221
+ if (!binding) {
222
+ return [];
223
+ }
224
+
225
+ if (typeof binding === 'string') {
226
+ return [binding];
227
+ }
228
+
229
+ if (binding instanceof Array) {
230
+ // To handle an object-in-array binding smartly, we use recursion
231
+ return binding.map(normalizeClassBinding).reduce(function (a, b) {
232
+ return [].concat(_toConsumableArray(a), _toConsumableArray(b));
233
+ }, []);
234
+ }
235
+
236
+ if (_typeof(binding) === 'object') {
237
+ return Object.entries(binding).filter(function (_ref5) {
238
+ var _ref6 = _slicedToArray(_ref5, 2),
239
+ active = _ref6[1];
240
+
241
+ return !!active;
242
+ }).map(function (_ref7) {
243
+ var _ref8 = _slicedToArray(_ref7, 1),
244
+ className = _ref8[0];
245
+
246
+ return className;
247
+ });
248
+ } // Unknown class binding
249
+
250
+
251
+ return [];
252
+ }
253
+
203
254
  function stringifyAttr(attrName, value) {
204
- if (typeof value === 'undefined') {
255
+ if (typeof value === 'undefined' || typeof value === 'function') {
205
256
  return null;
206
257
  }
207
258
 
@@ -31,9 +31,39 @@ describe('vnodeToString', function () {
31
31
  template: "<button>Button</button>"
32
32
  }))).toMatchInlineSnapshot("<button >Button</button>");
33
33
  });
34
+ it('static class', function () {
35
+ expect((0, _sourceDecorator.vnodeToString)(getVNode({
36
+ template: "<button class=\"foo bar\">Button</button>"
37
+ }))).toMatchInlineSnapshot("<button class=\"foo bar\">Button</button>");
38
+ });
39
+ it('string dynamic class', function () {
40
+ expect((0, _sourceDecorator.vnodeToString)(getVNode({
41
+ template: "<button :class=\"'foo'\">Button</button>"
42
+ }))).toMatchInlineSnapshot("<button class=\"foo\">Button</button>");
43
+ });
44
+ it('non-string dynamic class', function () {
45
+ expect((0, _sourceDecorator.vnodeToString)(getVNode({
46
+ template: "<button :class=\"1\">Button</button>"
47
+ }))).toMatchInlineSnapshot("<button >Button</button>");
48
+ });
49
+ it('array dynamic class', function () {
50
+ expect((0, _sourceDecorator.vnodeToString)(getVNode({
51
+ template: "<button :class=\"['foo', null, false, 0, {bar: true, baz: false}]\">Button</button>"
52
+ }))).toMatchInlineSnapshot("<button class=\"foo bar\">Button</button>");
53
+ });
54
+ it('object dynamic class', function () {
55
+ expect((0, _sourceDecorator.vnodeToString)(getVNode({
56
+ template: "<button :class=\"{foo: true, bar: false}\">Button</button>"
57
+ }))).toMatchInlineSnapshot("<button class=\"foo\">Button</button>");
58
+ });
59
+ it('merge dynamic and static classes', function () {
60
+ expect((0, _sourceDecorator.vnodeToString)(getVNode({
61
+ template: "<button class=\"foo\" :class=\"{bar: null, baz: 1}\">Button</button>"
62
+ }))).toMatchInlineSnapshot("<button class=\"foo baz\">Button</button>");
63
+ });
34
64
  it('attributes', function () {
35
65
  var MyComponent = {
36
- props: ['propA', 'propB', 'propC', 'propD'],
66
+ props: ['propA', 'propB', 'propC', 'propD', 'propE', 'propF', 'propG'],
37
67
  template: '<div/>'
38
68
  };
39
69
  expect((0, _sourceDecorator.vnodeToString)(getVNode({
@@ -48,12 +78,18 @@ describe('vnodeToString', function () {
48
78
  propC: null,
49
79
  propD: {
50
80
  foo: 'bar'
51
- }
81
+ },
82
+ propE: true,
83
+ propF: function propF() {
84
+ var foo = 'bar';
85
+ return foo;
86
+ },
87
+ propG: undefined
52
88
  }
53
89
  };
54
90
  },
55
91
  template: "<my-component v-bind=\"props\"/>"
56
- }))).toMatchInlineSnapshot("<my-component :propD='{\"foo\":\"bar\"}' :propC=\"null\" :propB=\"1\" propA=\"propA\"/>");
92
+ }))).toMatchInlineSnapshot("<my-component propE :propD='{\"foo\":\"bar\"}' :propC=\"null\" :propB=\"1\" propA=\"propA\"/>");
57
93
  });
58
94
  it('children', function () {
59
95
  expect((0, _sourceDecorator.vnodeToString)(getVNode({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-docs",
3
- "version": "6.1.7",
3
+ "version": "6.1.11",
4
4
  "description": "Superior documentation for your components",
5
5
  "keywords": [
6
6
  "addon",
@@ -19,13 +19,6 @@
19
19
  "license": "MIT",
20
20
  "main": "dist/public_api.js",
21
21
  "types": "dist/public_api.d.ts",
22
- "typesVersions": {
23
- "<3.8": {
24
- "*": [
25
- "ts3.4/*"
26
- ]
27
- }
28
- },
29
22
  "files": [
30
23
  "dist/**/*",
31
24
  "angular/**/*",
@@ -55,18 +48,18 @@
55
48
  "@mdx-js/loader": "^1.6.19",
56
49
  "@mdx-js/mdx": "^1.6.19",
57
50
  "@mdx-js/react": "^1.6.19",
58
- "@storybook/addons": "6.1.7",
59
- "@storybook/api": "6.1.7",
60
- "@storybook/client-api": "6.1.7",
61
- "@storybook/client-logger": "6.1.7",
62
- "@storybook/components": "6.1.7",
63
- "@storybook/core": "6.1.7",
64
- "@storybook/core-events": "6.1.7",
51
+ "@storybook/addons": "6.1.11",
52
+ "@storybook/api": "6.1.11",
53
+ "@storybook/client-api": "6.1.11",
54
+ "@storybook/client-logger": "6.1.11",
55
+ "@storybook/components": "6.1.11",
56
+ "@storybook/core": "6.1.11",
57
+ "@storybook/core-events": "6.1.11",
65
58
  "@storybook/csf": "0.0.1",
66
- "@storybook/node-logger": "6.1.7",
67
- "@storybook/postinstall": "6.1.7",
68
- "@storybook/source-loader": "6.1.7",
69
- "@storybook/theming": "6.1.7",
59
+ "@storybook/node-logger": "6.1.11",
60
+ "@storybook/postinstall": "6.1.11",
61
+ "@storybook/source-loader": "6.1.11",
62
+ "@storybook/theming": "6.1.11",
70
63
  "acorn": "^7.1.0",
71
64
  "acorn-jsx": "^5.1.0",
72
65
  "acorn-walk": "^7.0.0",
@@ -92,9 +85,9 @@
92
85
  "@babel/core": "^7.12.3",
93
86
  "@emotion/core": "^10.1.1",
94
87
  "@emotion/styled": "^10.0.23",
95
- "@storybook/react": "6.1.7",
96
- "@storybook/vue": "6.1.7",
97
- "@storybook/web-components": "6.1.7",
88
+ "@storybook/react": "6.1.11",
89
+ "@storybook/vue": "6.1.11",
90
+ "@storybook/web-components": "6.1.11",
98
91
  "@types/cross-spawn": "^6.0.1",
99
92
  "@types/doctrine": "^0.0.3",
100
93
  "@types/enzyme": "^3.10.3",
@@ -123,7 +116,7 @@
123
116
  },
124
117
  "peerDependencies": {
125
118
  "@babel/core": "^7.11.5",
126
- "@storybook/vue": "6.1.7",
119
+ "@storybook/vue": "6.1.11",
127
120
  "babel-loader": "^8.0.0",
128
121
  "react": "^16.8.0 || ^17.0.0",
129
122
  "react-dom": "^16.8.0 || ^17.0.0",
@@ -154,5 +147,12 @@
154
147
  "publishConfig": {
155
148
  "access": "public"
156
149
  },
157
- "gitHead": "303d951f9ae4aa2241c9823e1cb6edbfd50fb093"
150
+ "gitHead": "5999b789d796414997c21d74517f7dfede6ddeff",
151
+ "typesVersions": {
152
+ "<3.8": {
153
+ "*": [
154
+ "ts3.4/*"
155
+ ]
156
+ }
157
+ }
158
158
  }
@@ -11,7 +11,7 @@ interface MetaProps {
11
11
  ];
12
12
  parameters?: Parameters;
13
13
  args?: Args;
14
- argTypes: ArgTypes;
14
+ argTypes?: ArgTypes;
15
15
  }
16
16
  /**
17
17
  * This component is used to declare component metadata in docs
@@ -38,5 +38,5 @@ declare type Docgen = {
38
38
  version: number;
39
39
  };
40
40
  export declare const extractArgTypes: ArgTypesExtractor;
41
- export declare const createArgTypes: (docs: Docgen) => ArgTypes;
41
+ export declare const createArgTypes: (docgen: Docgen) => ArgTypes;
42
42
  export {};