@storybook/csf 0.0.2--canary.0899bb7.0 → 0.0.2--canary.50.45981a0.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -15,5 +15,4 @@ export declare const parseKind: (kind: string, { rootSeparator, groupSeparator }
15
15
  root: string | null;
16
16
  groups: string[];
17
17
  };
18
- export { includeConditionalArg } from './includeConditionalArg';
19
18
  export * from './story';
package/dist/index.js CHANGED
@@ -8,22 +8,13 @@ var _exportNames = {
8
8
  toId: true,
9
9
  storyNameFromExport: true,
10
10
  isExportStory: true,
11
- parseKind: true,
12
- includeConditionalArg: true
11
+ parseKind: true
13
12
  };
14
13
  exports.isExportStory = isExportStory;
15
- Object.defineProperty(exports, "includeConditionalArg", {
16
- enumerable: true,
17
- get: function get() {
18
- return _includeConditionalArg.includeConditionalArg;
19
- }
20
- });
21
14
  exports.parseKind = exports.storyNameFromExport = exports.toId = exports.sanitize = void 0;
22
15
 
23
16
  var _startCase = _interopRequireDefault(require("lodash/startCase"));
24
17
 
25
- var _includeConditionalArg = require("./includeConditionalArg");
26
-
27
18
  var _story = require("./story");
28
19
 
29
20
  Object.keys(_story).forEach(function (key) {
package/dist/story.d.ts CHANGED
@@ -16,27 +16,11 @@ export interface StoryIdentifier {
16
16
  export declare type Parameters = {
17
17
  [name: string]: any;
18
18
  };
19
- declare type ConditionalTest = {
20
- truthy?: boolean;
21
- } | {
22
- exists: boolean;
23
- } | {
24
- eq: any;
25
- } | {
26
- neq: any;
27
- };
28
- declare type ConditionalValue = {
29
- arg: string;
30
- } | {
31
- global: string;
32
- };
33
- export declare type Conditional = ConditionalValue & ConditionalTest;
34
19
  export interface InputType {
35
20
  name?: string;
36
21
  description?: string;
37
22
  defaultValue?: any;
38
23
  type?: SBType | SBScalarType['name'];
39
- if?: Conditional;
40
24
  [key: string]: any;
41
25
  }
42
26
  export interface StrictInputType extends InputType {
@@ -93,26 +77,20 @@ export declare type StoryContext<TFramework extends AnyFramework = AnyFramework,
93
77
  abortSignal: AbortSignal;
94
78
  canvasElement: HTMLElement;
95
79
  };
96
- export declare type StepLabel = string;
97
- export declare type StepFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (label: StepLabel, play: PlayFunction<TFramework, TArgs>) => void;
98
- export declare type PlayFunctionContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContext<TFramework, TArgs> & {
99
- step: StepFunction<TFramework, TArgs>;
100
- };
101
- export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: PlayFunctionContext<TFramework, TArgs>) => Promise<void> | void;
80
+ export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => Promise<void> | void;
102
81
  export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult'];
103
82
  export declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
104
83
  export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
105
84
  export declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyStoryFn<TFramework, TArgs> | ArgsStoryFn<TFramework, TArgs>;
106
85
  export declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
107
86
  export declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
108
- export declare type StepRunner<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (label: StepLabel, play: PlayFunction<TFramework, TArgs>, context: PlayFunctionContext<TFramework, TArgs>) => Promise<void>;
109
87
  export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = {
110
88
  decorators?: DecoratorFunction<TFramework, Args>[];
111
89
  parameters?: Parameters;
112
90
  args?: Partial<TArgs>;
113
91
  argTypes?: Partial<ArgTypes<TArgs>>;
114
92
  loaders?: LoaderFunction<TFramework, Args>[];
115
- render?: ArgsStoryFn<TFramework, TArgs>;
93
+ render?: ArgsStoryFn<TFramework, Args>;
116
94
  };
117
95
  export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
118
96
  argsEnhancers?: ArgsEnhancer<TFramework, Args>[];
@@ -120,7 +98,6 @@ export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFram
120
98
  globals?: Globals;
121
99
  globalTypes?: GlobalTypes;
122
100
  applyDecorators?: DecoratorApplicator<TFramework, Args>;
123
- runStep?: StepRunner<TFramework, TArgs>;
124
101
  };
125
102
  declare type StoryDescriptor = string[] | RegExp;
126
103
  export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
3
  // NOTE Example of internal type definition for @storybook/<X> (where X is a framework)
8
4
  // NOTE Examples of using types from @storybook/<X> in real project
9
5
  var Button = function Button() {
@@ -120,7 +116,7 @@ CSF2Story.args = {
120
116
  a: 1
121
117
  };
122
118
  var CSF3Story = {
123
- render: function render(args) {
119
+ render: function render() {
124
120
  return 'Named Story';
125
121
  },
126
122
  name: 'Another name for story',
@@ -142,7 +138,7 @@ var CSF3Story = {
142
138
  }
143
139
  };
144
140
  var CSF3StoryStrict = {
145
- render: function render(args) {
141
+ render: function render() {
146
142
  return 'Named Story';
147
143
  },
148
144
  name: 'Another name for story',
@@ -161,31 +157,6 @@ var CSF3StoryStrict = {
161
157
  }],
162
158
  args: {
163
159
  x: '1'
164
- },
165
- play: function play(_ref) {
166
- var step = _ref.step;
167
- step('a step', function (_ref2) {
168
- var substep = _ref2.step;
169
- substep('a substep', function () {});
170
- });
171
- }
172
- };
173
- var project = {
174
- runStep: function runStep(label, play, context) {
175
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
176
- return regeneratorRuntime.wrap(function _callee$(_context) {
177
- while (1) {
178
- switch (_context.prev = _context.next) {
179
- case 0:
180
- return _context.abrupt("return", play(context));
181
-
182
- case 1:
183
- case "end":
184
- return _context.stop();
185
- }
186
- }
187
- }, _callee);
188
- }))();
189
160
  }
190
161
  }; // NOTE Jest forced to define at least one test in file
191
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/csf",
3
- "version": "0.0.2--canary.0899bb7.0",
3
+ "version": "0.0.2--canary.50.45981a0.0",
4
4
  "description": "Component Story Format (CSF) utilities",
5
5
  "keywords": [
6
6
  "storybook",
@@ -38,15 +38,13 @@
38
38
  },
39
39
  "prettier": "@storybook/linter-config/prettier.config",
40
40
  "jest": {
41
- "testEnvironment": "node",
42
- "roots": [
43
- "<rootDir>/src"
44
- ]
41
+ "testEnvironment": "node"
45
42
  },
46
43
  "dependencies": {
47
44
  "lodash": "^4.17.15"
48
45
  },
49
46
  "devDependencies": {
47
+ "@auto-it/released": "^10.37.1",
50
48
  "@babel/cli": "^7.8.4",
51
49
  "@babel/core": "^7.9.0",
52
50
  "@babel/preset-env": "^7.9.5",
@@ -63,6 +61,12 @@
63
61
  "prettier": "^1.19.1",
64
62
  "typescript": "^3.7.2"
65
63
  },
64
+ "auto": {
65
+ "plugins": [
66
+ "npm",
67
+ "released"
68
+ ]
69
+ },
66
70
  "publishConfig": {
67
71
  "access": "public"
68
72
  }
@@ -1,3 +0,0 @@
1
- import { Args, Globals, InputType, Conditional } from './story';
2
- export declare const testValue: (cond: Pick<Conditional, never>, value: any) => boolean;
3
- export declare const includeConditionalArg: (argType: InputType, args: Args, globals: Globals) => boolean;
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.includeConditionalArg = exports.testValue = void 0;
7
-
8
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
- var count = function count(vals) {
13
- return vals.map(function (v) {
14
- return typeof v !== 'undefined';
15
- }).filter(Boolean).length;
16
- };
17
-
18
- var testValue = function testValue(cond, value) {
19
- var _ref = cond,
20
- exists = _ref.exists,
21
- eq = _ref.eq,
22
- neq = _ref.neq,
23
- truthy = _ref.truthy;
24
-
25
- if (count([exists, eq, neq, truthy]) > 1) {
26
- throw new Error("Invalid conditional test ".concat(JSON.stringify({
27
- exists: exists,
28
- eq: eq,
29
- neq: neq
30
- })));
31
- }
32
-
33
- if (typeof eq !== 'undefined') {
34
- return (0, _isEqual["default"])(value, eq);
35
- }
36
-
37
- if (typeof neq !== 'undefined') {
38
- return !(0, _isEqual["default"])(value, neq);
39
- }
40
-
41
- if (typeof exists !== 'undefined') {
42
- var valueExists = typeof value !== 'undefined';
43
- return exists ? valueExists : !valueExists;
44
- }
45
-
46
- var shouldBeTruthy = typeof truthy === 'undefined' ? true : truthy;
47
- return shouldBeTruthy ? !!value : !value;
48
- };
49
- /**
50
- * Helper function to include/exclude an arg based on the value of other other args
51
- * aka "conditional args"
52
- */
53
-
54
-
55
- exports.testValue = testValue;
56
-
57
- var includeConditionalArg = function includeConditionalArg(argType, args, globals) {
58
- if (!argType["if"]) return true;
59
- var _ref2 = argType["if"],
60
- arg = _ref2.arg,
61
- global = _ref2.global;
62
-
63
- if (count([arg, global]) !== 1) {
64
- throw new Error("Invalid conditional value ".concat(JSON.stringify({
65
- arg: arg,
66
- global: global
67
- })));
68
- }
69
-
70
- var value = arg ? args[arg] : globals[global];
71
- return testValue(argType["if"], value);
72
- };
73
-
74
- exports.includeConditionalArg = includeConditionalArg;
@@ -1,318 +0,0 @@
1
- "use strict";
2
-
3
- var _includeConditionalArg = require("./includeConditionalArg");
4
-
5
- /* eslint-disable @typescript-eslint/ban-ts-ignore */
6
- describe('testValue', function () {
7
- describe('truthy', function () {
8
- it.each([['implicit true', {}, true, true], ['implicit truthy', {}, 1, true], ['implicit falsey', {}, 0, false], ['truthy true', {
9
- truthy: true
10
- }, true, true], ['truthy truthy', {
11
- truthy: true
12
- }, 1, true], ['truthy falsey', {
13
- truthy: true
14
- }, 0, false], ['falsey true', {
15
- truthy: false
16
- }, true, false], ['falsey truthy', {
17
- truthy: false
18
- }, 1, false], ['falsey falsey', {
19
- truthy: false
20
- }, 0, true]])('%s', function (_name, cond, value, expected) {
21
- // @ts-ignore
22
- expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
23
- });
24
- });
25
- describe('exists', function () {
26
- it.each([['exist', {
27
- exists: true
28
- }, 1, true], ['exist false', {
29
- exists: true
30
- }, undefined, false], ['nexist', {
31
- exists: false
32
- }, undefined, true], ['nexist false', {
33
- exists: false
34
- }, 1, false]])('%s', function (_name, cond, value, expected) {
35
- // @ts-ignore
36
- expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
37
- });
38
- });
39
- describe('eq', function () {
40
- it.each([['true', {
41
- eq: 1
42
- }, 1, true], ['false', {
43
- eq: 1
44
- }, 2, false], ['undefined', {
45
- eq: undefined
46
- }, undefined, false], ['undefined false', {
47
- eq: 1
48
- }, undefined, false], ['object true', {
49
- eq: {
50
- x: 1
51
- }
52
- }, {
53
- x: 1
54
- }, true], ['object true', {
55
- eq: {
56
- x: 1
57
- }
58
- }, {
59
- x: 2
60
- }, false]])('%s', function (_name, cond, value, expected) {
61
- // @ts-ignore
62
- expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
63
- });
64
- });
65
- describe('neq', function () {
66
- it.each([['true', {
67
- neq: 1
68
- }, 2, true], ['false', {
69
- neq: 1
70
- }, 1, false], ['undefined true', {
71
- neq: 1
72
- }, undefined, true], ['undefined false', {
73
- neq: undefined
74
- }, undefined, false], ['object true', {
75
- neq: {
76
- x: 1
77
- }
78
- }, {
79
- x: 2
80
- }, true], ['object false', {
81
- neq: {
82
- x: 1
83
- }
84
- }, {
85
- x: 1
86
- }, false]])('%s', function (_name, cond, value, expected) {
87
- // @ts-ignore
88
- expect((0, _includeConditionalArg.testValue)(cond, value)).toBe(expected);
89
- });
90
- });
91
- });
92
- describe('includeConditionalArg', function () {
93
- describe('errors', function () {
94
- it('should throw if arg and global are both specified', function () {
95
- expect(function () {
96
- return (0, _includeConditionalArg.includeConditionalArg)({
97
- "if": {
98
- arg: 'a',
99
- global: 'b'
100
- }
101
- }, {}, {});
102
- }).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional value {\\\"arg\\\":\\\"a\\\",\\\"global\\\":\\\"b\\\"}\"");
103
- });
104
- it('should throw if mulitiple exists / eq / neq are specified', function () {
105
- expect(function () {
106
- return (0, _includeConditionalArg.includeConditionalArg)({
107
- "if": {
108
- arg: 'a',
109
- exists: true,
110
- eq: 1
111
- }
112
- }, {}, {});
113
- }).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional test {\\\"exists\\\":true,\\\"eq\\\":1}\"");
114
- expect(function () {
115
- return (0, _includeConditionalArg.includeConditionalArg)({
116
- "if": {
117
- arg: 'a',
118
- exists: false,
119
- neq: 0
120
- }
121
- }, {}, {});
122
- }).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional test {\\\"exists\\\":false,\\\"neq\\\":0}\"");
123
- expect(function () {
124
- return (0, _includeConditionalArg.includeConditionalArg)({
125
- "if": {
126
- arg: 'a',
127
- eq: 1,
128
- neq: 0
129
- }
130
- }, {}, {});
131
- }).toThrowErrorMatchingInlineSnapshot("\"Invalid conditional test {\\\"eq\\\":1,\\\"neq\\\":0}\"");
132
- });
133
- });
134
- describe('args', function () {
135
- describe('implicit', function () {
136
- it.each([['implicit true', {
137
- "if": {
138
- arg: 'a'
139
- }
140
- }, {
141
- a: 1
142
- }, {}, true], ['truthy true', {
143
- "if": {
144
- arg: 'a',
145
- truthy: true
146
- }
147
- }, {
148
- a: 0
149
- }, {}, false], ['truthy false', {
150
- "if": {
151
- arg: 'a',
152
- truthy: false
153
- }
154
- }, {}, {}, true]])('%s', function (_name, argType, args, globals, expected) {
155
- // @ts-ignore
156
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
157
- });
158
- });
159
- describe('exists', function () {
160
- it.each([['exist', {
161
- "if": {
162
- arg: 'a',
163
- exists: true
164
- }
165
- }, {
166
- a: 1
167
- }, {}, true], ['exist false', {
168
- "if": {
169
- arg: 'a',
170
- exists: true
171
- }
172
- }, {}, {}, false]])('%s', function (_name, argType, args, globals, expected) {
173
- // @ts-ignore
174
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
175
- });
176
- });
177
- describe('eq', function () {
178
- it.each([['scalar true', {
179
- "if": {
180
- arg: 'a',
181
- eq: 1
182
- }
183
- }, {
184
- a: 1
185
- }, {}, true], ['scalar false', {
186
- "if": {
187
- arg: 'a',
188
- eq: 1
189
- }
190
- }, {
191
- a: 2
192
- }, {
193
- a: 1
194
- }, false]])('%s', function (_name, argType, args, globals, expected) {
195
- // @ts-ignore
196
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
197
- });
198
- });
199
- describe('neq', function () {
200
- it.each([['scalar true', {
201
- "if": {
202
- arg: 'a',
203
- neq: 1
204
- }
205
- }, {
206
- a: 2
207
- }, {}, true], ['scalar false', {
208
- "if": {
209
- arg: 'a',
210
- neq: 1
211
- }
212
- }, {
213
- a: 1
214
- }, {
215
- a: 2
216
- }, false]])('%s', function (_name, argType, args, globals, expected) {
217
- // @ts-ignore
218
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
219
- });
220
- });
221
- });
222
- describe('globals', function () {
223
- describe('truthy', function () {
224
- it.each([['implicit true', {
225
- "if": {
226
- global: 'a'
227
- }
228
- }, {}, {
229
- a: 1
230
- }, true], ['implicit undefined', {
231
- "if": {
232
- global: 'a'
233
- }
234
- }, {}, {}, false], ['truthy true', {
235
- "if": {
236
- global: 'a',
237
- truthy: true
238
- }
239
- }, {}, {
240
- a: 0
241
- }, false], ['truthy false', {
242
- "if": {
243
- global: 'a',
244
- truthy: false
245
- }
246
- }, {}, {
247
- a: 0
248
- }, true]])('%s', function (_name, argType, args, globals, expected) {
249
- // @ts-ignore
250
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
251
- });
252
- });
253
- describe('exists', function () {
254
- it.each([['implicit exist true', {
255
- "if": {
256
- global: 'a',
257
- exists: true
258
- }
259
- }, {}, {
260
- a: 1
261
- }, true], ['implicit exist false', {
262
- "if": {
263
- global: 'a',
264
- exists: true
265
- }
266
- }, {
267
- a: 1
268
- }, {}, false]])('%s', function (_name, argType, args, globals, expected) {
269
- // @ts-ignore
270
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
271
- });
272
- });
273
- describe('eq', function () {
274
- it.each([['scalar true', {
275
- "if": {
276
- global: 'a',
277
- eq: 1
278
- }
279
- }, {}, {
280
- a: 1
281
- }, true], ['scalar false', {
282
- "if": {
283
- arg: 'a',
284
- eq: 1
285
- }
286
- }, {
287
- a: 2
288
- }, {
289
- a: 1
290
- }, false]])('%s', function (_name, argType, args, globals, expected) {
291
- // @ts-ignore
292
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
293
- });
294
- });
295
- describe('neq', function () {
296
- it.each([['scalar true', {
297
- "if": {
298
- global: 'a',
299
- neq: 1
300
- }
301
- }, {}, {
302
- a: 2
303
- }, true], ['scalar false', {
304
- "if": {
305
- global: 'a',
306
- neq: 1
307
- }
308
- }, {
309
- a: 2
310
- }, {
311
- a: 1
312
- }, false]])('%s', function (_name, argType, args, globals, expected) {
313
- // @ts-ignore
314
- expect((0, _includeConditionalArg.includeConditionalArg)(argType, args, globals)).toBe(expected);
315
- });
316
- });
317
- });
318
- });