@storybook/csf 0.0.2-next.7 → 0.0.2-next.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +57 -57
- package/dist/index.js +8 -107
- package/dist/index.mjs +2 -72
- package/package.json +29 -27
package/dist/index.d.ts
CHANGED
@@ -4,42 +4,42 @@ interface SBBaseType {
|
|
4
4
|
required?: boolean;
|
5
5
|
raw?: string;
|
6
6
|
}
|
7
|
-
|
7
|
+
type SBScalarType = SBBaseType & {
|
8
8
|
name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
|
9
9
|
};
|
10
|
-
|
10
|
+
type SBArrayType = SBBaseType & {
|
11
11
|
name: 'array';
|
12
12
|
value: SBType;
|
13
13
|
};
|
14
|
-
|
14
|
+
type SBObjectType = SBBaseType & {
|
15
15
|
name: 'object';
|
16
16
|
value: Record<string, SBType>;
|
17
17
|
};
|
18
|
-
|
18
|
+
type SBEnumType = SBBaseType & {
|
19
19
|
name: 'enum';
|
20
20
|
value: (string | number)[];
|
21
21
|
};
|
22
|
-
|
22
|
+
type SBIntersectionType = SBBaseType & {
|
23
23
|
name: 'intersection';
|
24
24
|
value: SBType[];
|
25
25
|
};
|
26
|
-
|
26
|
+
type SBUnionType = SBBaseType & {
|
27
27
|
name: 'union';
|
28
28
|
value: SBType[];
|
29
29
|
};
|
30
|
-
|
30
|
+
type SBOtherType = SBBaseType & {
|
31
31
|
name: 'other';
|
32
32
|
value: string;
|
33
33
|
};
|
34
|
-
|
34
|
+
type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
type StoryId = string;
|
37
|
+
type ComponentId = string;
|
38
|
+
type ComponentTitle = string;
|
39
|
+
type StoryName = string;
|
40
40
|
/** @deprecated */
|
41
|
-
|
42
|
-
|
41
|
+
type StoryKind = ComponentTitle;
|
42
|
+
type Tag = string;
|
43
43
|
interface StoryIdentifier {
|
44
44
|
componentId: ComponentId;
|
45
45
|
title: ComponentTitle;
|
@@ -57,7 +57,7 @@ interface Parameters {
|
|
57
57
|
interface StrictParameters {
|
58
58
|
[name: string]: unknown;
|
59
59
|
}
|
60
|
-
|
60
|
+
type ConditionalTest = {
|
61
61
|
truthy?: boolean;
|
62
62
|
} | {
|
63
63
|
exists: boolean;
|
@@ -66,12 +66,12 @@ declare type ConditionalTest = {
|
|
66
66
|
} | {
|
67
67
|
neq: any;
|
68
68
|
};
|
69
|
-
|
69
|
+
type ConditionalValue = {
|
70
70
|
arg: string;
|
71
71
|
} | {
|
72
72
|
global: string;
|
73
73
|
};
|
74
|
-
|
74
|
+
type Conditional = ConditionalValue & ConditionalTest;
|
75
75
|
interface InputType {
|
76
76
|
name?: string;
|
77
77
|
description?: string;
|
@@ -90,22 +90,22 @@ interface Args {
|
|
90
90
|
interface StrictArgs {
|
91
91
|
[name: string]: unknown;
|
92
92
|
}
|
93
|
-
|
93
|
+
type ArgTypes<TArgs = Args> = {
|
94
94
|
[name in keyof TArgs]: InputType;
|
95
95
|
};
|
96
|
-
|
96
|
+
type StrictArgTypes<TArgs = Args> = {
|
97
97
|
[name in keyof TArgs]: StrictInputType;
|
98
98
|
};
|
99
|
-
|
99
|
+
type Globals = {
|
100
100
|
[name: string]: any;
|
101
101
|
};
|
102
|
-
|
102
|
+
type GlobalTypes = {
|
103
103
|
[name: string]: InputType;
|
104
104
|
};
|
105
|
-
|
105
|
+
type StrictGlobalTypes = {
|
106
106
|
[name: string]: StrictInputType;
|
107
107
|
};
|
108
|
-
|
108
|
+
type Renderer = {
|
109
109
|
/** What is the type of the `component` annotation in this renderer? */
|
110
110
|
component: unknown;
|
111
111
|
/** What does the story function return in this renderer? */
|
@@ -115,8 +115,8 @@ declare type Renderer = {
|
|
115
115
|
T?: unknown;
|
116
116
|
};
|
117
117
|
/** @deprecated - use `Renderer` */
|
118
|
-
|
119
|
-
|
118
|
+
type AnyFramework = Renderer;
|
119
|
+
type StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryIdentifier & {
|
120
120
|
component?: (TRenderer & {
|
121
121
|
T: any;
|
122
122
|
})['component'];
|
@@ -127,43 +127,43 @@ declare type StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TAr
|
|
127
127
|
initialArgs: TArgs;
|
128
128
|
argTypes: StrictArgTypes<TArgs>;
|
129
129
|
};
|
130
|
-
|
131
|
-
|
130
|
+
type ArgsEnhancer<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContextForEnhancers<TRenderer, TArgs>) => TArgs;
|
131
|
+
type ArgTypesEnhancer<TRenderer extends Renderer = Renderer, TArgs = Args> = ((context: StoryContextForEnhancers<TRenderer, TArgs>) => StrictArgTypes<TArgs>) & {
|
132
132
|
secondPass?: boolean;
|
133
133
|
};
|
134
|
-
|
134
|
+
type StoryContextUpdate<TArgs = Args> = {
|
135
135
|
args?: TArgs;
|
136
136
|
globals?: Globals;
|
137
137
|
[key: string]: any;
|
138
138
|
};
|
139
|
-
|
140
|
-
|
139
|
+
type ViewMode = 'story' | 'docs';
|
140
|
+
type StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContextForEnhancers<TRenderer, TArgs> & Required<StoryContextUpdate<TArgs>> & {
|
141
141
|
hooks: unknown;
|
142
142
|
viewMode: ViewMode;
|
143
143
|
originalStoryFn: StoryFn<TRenderer>;
|
144
144
|
};
|
145
|
-
|
146
|
-
|
145
|
+
type LoaderFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContextForLoaders<TRenderer, TArgs>) => Promise<Record<string, any>>;
|
146
|
+
type StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContextForLoaders<TRenderer, TArgs> & {
|
147
147
|
loaded: Record<string, any>;
|
148
148
|
abortSignal: AbortSignal;
|
149
149
|
canvasElement: TRenderer['canvasElement'];
|
150
150
|
};
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
type StepLabel = string;
|
152
|
+
type StepFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (label: StepLabel, play: PlayFunction<TRenderer, TArgs>) => Promise<void> | void;
|
153
|
+
type PlayFunctionContext<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContext<TRenderer, TArgs> & {
|
154
154
|
step: StepFunction<TRenderer, TArgs>;
|
155
155
|
};
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
type PlayFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: PlayFunctionContext<TRenderer, TArgs>) => Promise<void> | void;
|
157
|
+
type PartialStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (update?: StoryContextUpdate<Partial<TArgs>>) => TRenderer['storyResult'];
|
158
|
+
type LegacyStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
|
159
|
+
type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: TArgs, context: StoryContext<TRenderer, TArgs>) => (TRenderer & {
|
160
160
|
T: TArgs;
|
161
161
|
})['storyResult'];
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
type StoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = LegacyStoryFn<TRenderer, TArgs> | ArgsStoryFn<TRenderer, TArgs>;
|
163
|
+
type DecoratorFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (fn: PartialStoryFn<TRenderer, TArgs>, c: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
|
164
|
+
type DecoratorApplicator<TRenderer extends Renderer = Renderer, TArgs = Args> = (storyFn: LegacyStoryFn<TRenderer, TArgs>, decorators: DecoratorFunction<TRenderer, TArgs>[]) => LegacyStoryFn<TRenderer, TArgs>;
|
165
|
+
type StepRunner<TRenderer extends Renderer = Renderer, TArgs = Args> = (label: StepLabel, play: PlayFunction<TRenderer, TArgs>, context: PlayFunctionContext<TRenderer, TArgs>) => Promise<void>;
|
166
|
+
type BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args> = {
|
167
167
|
/**
|
168
168
|
* Wrapper components or Storybook decorators that wrap a story.
|
169
169
|
*
|
@@ -196,7 +196,7 @@ declare type BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args
|
|
196
196
|
*/
|
197
197
|
render?: ArgsStoryFn<TRenderer, TArgs>;
|
198
198
|
};
|
199
|
-
|
199
|
+
type ProjectAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args> = BaseAnnotations<TRenderer, TArgs> & {
|
200
200
|
argsEnhancers?: ArgsEnhancer<TRenderer, Args>[];
|
201
201
|
argTypesEnhancers?: ArgTypesEnhancer<TRenderer, Args>[];
|
202
202
|
globals?: Globals;
|
@@ -204,7 +204,7 @@ declare type ProjectAnnotations<TRenderer extends Renderer = Renderer, TArgs = A
|
|
204
204
|
applyDecorators?: DecoratorApplicator<TRenderer, Args>;
|
205
205
|
runStep?: StepRunner<TRenderer, TArgs>;
|
206
206
|
};
|
207
|
-
|
207
|
+
type StoryDescriptor$1 = string[] | RegExp;
|
208
208
|
interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args> extends BaseAnnotations<TRenderer, TArgs> {
|
209
209
|
/**
|
210
210
|
* Title of the component which will be presented in the navigation. **Should be unique.**
|
@@ -254,7 +254,7 @@ interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TArgs = Ar
|
|
254
254
|
* Used by addons for automatic prop table generation and display of other component metadata.
|
255
255
|
*/
|
256
256
|
component?: (TRenderer & {
|
257
|
-
T:
|
257
|
+
T: Record<string, unknown> extends Required<TArgs> ? any : TArgs;
|
258
258
|
})['component'];
|
259
259
|
/**
|
260
260
|
* Auxiliary subcomponents that are part of the stories.
|
@@ -281,7 +281,7 @@ interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TArgs = Ar
|
|
281
281
|
*/
|
282
282
|
tags?: Tag[];
|
283
283
|
}
|
284
|
-
|
284
|
+
type StoryAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args, TRequiredArgs = Partial<TArgs>> = BaseAnnotations<TRenderer, TArgs> & {
|
285
285
|
/**
|
286
286
|
* Override the display name in the UI (CSF v3)
|
287
287
|
*/
|
@@ -305,23 +305,23 @@ declare type StoryAnnotations<TRenderer extends Renderer = Renderer, TArgs = Arg
|
|
305
305
|
} : {
|
306
306
|
args: TRequiredArgs;
|
307
307
|
});
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
308
|
+
type LegacyAnnotatedStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryFn<TRenderer, TArgs> & StoryAnnotations<TRenderer, TArgs>;
|
309
|
+
type LegacyStoryAnnotationsOrFn<TRenderer extends Renderer = Renderer, TArgs = Args> = LegacyAnnotatedStoryFn<TRenderer, TArgs> | StoryAnnotations<TRenderer, TArgs>;
|
310
|
+
type AnnotatedStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = ArgsStoryFn<TRenderer, TArgs> & StoryAnnotations<TRenderer, TArgs>;
|
311
|
+
type StoryAnnotationsOrFn<TRenderer extends Renderer = Renderer, TArgs = Args> = AnnotatedStoryFn<TRenderer, TArgs> | StoryAnnotations<TRenderer, TArgs>;
|
312
|
+
type ArgsFromMeta<TRenderer extends Renderer, Meta> = Meta extends {
|
313
313
|
render?: ArgsStoryFn<TRenderer, infer RArgs>;
|
314
314
|
loaders?: (infer Loaders)[];
|
315
315
|
decorators?: (infer Decorators)[];
|
316
316
|
} ? Simplify<RemoveIndexSignature<RArgs & DecoratorsArgs<TRenderer, Decorators> & LoaderArgs<TRenderer, Loaders>>> : unknown;
|
317
|
-
|
318
|
-
|
317
|
+
type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
|
318
|
+
type LoaderArgs<TRenderer extends Renderer, Loaders> = UnionToIntersection<Loaders extends LoaderFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
|
319
319
|
|
320
320
|
/**
|
321
321
|
* Helper function to include/exclude an arg based on the value of other other args
|
322
322
|
* aka "conditional args"
|
323
323
|
*/
|
324
|
-
declare const includeConditionalArg: (argType: InputType, args: Args, globals: Globals) =>
|
324
|
+
declare const includeConditionalArg: (argType: InputType, args: Args, globals: Globals) => any;
|
325
325
|
|
326
326
|
/**
|
327
327
|
* Remove punctuation and illegal characters from a story ID.
|
@@ -337,7 +337,7 @@ declare const toId: (kind: string, name?: string) => string;
|
|
337
337
|
* Transform a CSF named export into a readable story name
|
338
338
|
*/
|
339
339
|
declare const storyNameFromExport: (key: string) => string;
|
340
|
-
|
340
|
+
type StoryDescriptor = string[] | RegExp;
|
341
341
|
interface IncludeExcludeOptions {
|
342
342
|
includeStories?: StoryDescriptor;
|
343
343
|
excludeStories?: StoryDescriptor;
|
package/dist/index.js
CHANGED
@@ -1,109 +1,10 @@
|
|
1
|
-
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
-
mod
|
23
|
-
));
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
1
|
+
'use strict';
|
25
2
|
|
26
|
-
|
27
|
-
var src_exports = {};
|
28
|
-
__export(src_exports, {
|
29
|
-
includeConditionalArg: () => includeConditionalArg,
|
30
|
-
isExportStory: () => isExportStory,
|
31
|
-
parseKind: () => parseKind,
|
32
|
-
sanitize: () => sanitize,
|
33
|
-
storyNameFromExport: () => storyNameFromExport,
|
34
|
-
toId: () => toId
|
35
|
-
});
|
36
|
-
module.exports = __toCommonJS(src_exports);
|
37
|
-
var import_startCase = __toESM(require("lodash/startCase"));
|
3
|
+
var B=Object.create;var R=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var I=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var E=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of C(r))!w.call(e,a)&&a!==n&&R(e,a,{get:()=>r[a],enumerable:!(o=b(r,a))||o.enumerable});return e};var P=(e,r,n)=>(n=e!=null?B(h(e)):{},E(r||!e||!e.__esModule?R(n,"default",{value:e,enumerable:!0}):n,e));var x=I(T=>{Object.defineProperty(T,"__esModule",{value:!0}),T.isEqual=function(){var e=Object.prototype.toString,r=Object.getPrototypeOf,n=Object.getOwnPropertySymbols?function(o){return Object.keys(o).concat(Object.getOwnPropertySymbols(o))}:Object.keys;return function(o,a){return function i(t,s,d){var y,g,p,A=e.call(t),F=e.call(s);if(t===s)return !0;if(t==null||s==null)return !1;if(d.indexOf(t)>-1&&d.indexOf(s)>-1)return !0;if(d.push(t,s),A!=F||(y=n(t),g=n(s),y.length!=g.length||y.some(function(l){return !i(t[l],s[l],d)})))return !1;switch(A.slice(8,-1)){case"Symbol":return t.valueOf()==s.valueOf();case"Date":case"Number":return +t==+s||+t!=+t&&+s!=+s;case"RegExp":case"Function":case"String":case"Boolean":return ""+t==""+s;case"Set":case"Map":y=t.entries(),g=s.entries();do if(!i((p=y.next()).value,g.next().value,d))return !1;while(!p.done);return !0;case"ArrayBuffer":t=new Uint8Array(t),s=new Uint8Array(s);case"DataView":t=new Uint8Array(t.buffer),s=new Uint8Array(s.buffer);case"Float32Array":case"Float64Array":case"Int8Array":case"Int16Array":case"Int32Array":case"Uint8Array":case"Uint16Array":case"Uint32Array":case"Uint8ClampedArray":case"Arguments":case"Array":if(t.length!=s.length)return !1;for(p=0;p<t.length;p++)if((p in t||p in s)&&(p in t!=p in s||!i(t[p],s[p],d)))return !1;return !0;case"Object":return i(r(t),r(s),d);default:return !1}}(o,a,[])}}();});function u(e){return e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,(r,n,o)=>`${n} ${o}`).replace(/([a-z])([0-9])/gi,(r,n,o)=>`${n} ${o}`).replace(/(\s|^)(\w)/g,(r,n,o)=>n+o.toUpperCase()).trim()}var c=P(x()),S=e=>e.map(r=>typeof r<"u").filter(Boolean).length,O=(e,r)=>{let{exists:n,eq:o,neq:a,truthy:i}=e;if(S([n,o,a,i])>1)throw new Error(`Invalid conditional test ${JSON.stringify({exists:n,eq:o,neq:a})}`);if(typeof o<"u")return (0, c.isEqual)(r,o);if(typeof a<"u")return !(0, c.isEqual)(r,a);if(typeof n<"u"){let s=typeof r<"u";return n?s:!s}return (typeof i>"u"?!0:i)?!!r:!r},v=(e,r,n)=>{if(!e.if)return !0;let{arg:o,global:a}=e.if;if(S([o,a])!==1)throw new Error(`Invalid conditional value ${JSON.stringify({arg:o,global:a})}`);let i=o?r[o]:n[a];return O(e.if,i)};var L=e=>e.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),m=(e,r)=>{let n=L(e);if(n==="")throw new Error(`Invalid ${r} '${e}', must include alphanumeric characters`);return n},N=(e,r)=>`${m(e,"kind")}${r?`--${m(r,"name")}`:""}`,M=e=>u(e);function f(e,r){return Array.isArray(r)?r.includes(e):e.match(r)}function G(e,{includeStories:r,excludeStories:n}){return e!=="__esModule"&&(!r||f(e,r))&&(!n||!f(e,n))}var V=(e,{rootSeparator:r,groupSeparator:n})=>{let[o,a]=e.split(r,2),i=(a||e).split(n).filter(t=>!!t);return {root:a?o:null,groups:i}};
|
38
4
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
throw new Error(`Invalid conditional test ${JSON.stringify({ exists, eq, neq })}`);
|
46
|
-
}
|
47
|
-
if (typeof eq !== "undefined") {
|
48
|
-
return (0, import_isEqual.default)(value, eq);
|
49
|
-
}
|
50
|
-
if (typeof neq !== "undefined") {
|
51
|
-
return !(0, import_isEqual.default)(value, neq);
|
52
|
-
}
|
53
|
-
if (typeof exists !== "undefined") {
|
54
|
-
const valueExists = typeof value !== "undefined";
|
55
|
-
return exists ? valueExists : !valueExists;
|
56
|
-
}
|
57
|
-
const shouldBeTruthy = typeof truthy === "undefined" ? true : truthy;
|
58
|
-
return shouldBeTruthy ? !!value : !value;
|
59
|
-
};
|
60
|
-
var includeConditionalArg = (argType, args, globals) => {
|
61
|
-
if (!argType.if)
|
62
|
-
return true;
|
63
|
-
const { arg, global } = argType.if;
|
64
|
-
if (count([arg, global]) !== 1) {
|
65
|
-
throw new Error(`Invalid conditional value ${JSON.stringify({ arg, global })}`);
|
66
|
-
}
|
67
|
-
const value = arg ? args[arg] : globals[global];
|
68
|
-
return testValue(argType.if, value);
|
69
|
-
};
|
70
|
-
|
71
|
-
// src/index.ts
|
72
|
-
var sanitize = (string) => {
|
73
|
-
return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
74
|
-
};
|
75
|
-
var sanitizeSafe = (string, part) => {
|
76
|
-
const sanitized = sanitize(string);
|
77
|
-
if (sanitized === "") {
|
78
|
-
throw new Error(`Invalid ${part} '${string}', must include alphanumeric characters`);
|
79
|
-
}
|
80
|
-
return sanitized;
|
81
|
-
};
|
82
|
-
var toId = (kind, name) => `${sanitizeSafe(kind, "kind")}${name ? `--${sanitizeSafe(name, "name")}` : ""}`;
|
83
|
-
var storyNameFromExport = (key) => (0, import_startCase.default)(key);
|
84
|
-
function matches(storyKey, arrayOrRegex) {
|
85
|
-
if (Array.isArray(arrayOrRegex)) {
|
86
|
-
return arrayOrRegex.includes(storyKey);
|
87
|
-
}
|
88
|
-
return storyKey.match(arrayOrRegex);
|
89
|
-
}
|
90
|
-
function isExportStory(key, { includeStories, excludeStories }) {
|
91
|
-
return key !== "__esModule" && (!includeStories || matches(key, includeStories)) && (!excludeStories || !matches(key, excludeStories));
|
92
|
-
}
|
93
|
-
var parseKind = (kind, { rootSeparator, groupSeparator }) => {
|
94
|
-
const [root, remainder] = kind.split(rootSeparator, 2);
|
95
|
-
const groups = (remainder || kind).split(groupSeparator).filter((i) => !!i);
|
96
|
-
return {
|
97
|
-
root: remainder ? root : null,
|
98
|
-
groups
|
99
|
-
};
|
100
|
-
};
|
101
|
-
// Annotate the CommonJS export names for ESM import in node:
|
102
|
-
0 && (module.exports = {
|
103
|
-
includeConditionalArg,
|
104
|
-
isExportStory,
|
105
|
-
parseKind,
|
106
|
-
sanitize,
|
107
|
-
storyNameFromExport,
|
108
|
-
toId
|
109
|
-
});
|
5
|
+
exports.includeConditionalArg = v;
|
6
|
+
exports.isExportStory = G;
|
7
|
+
exports.parseKind = V;
|
8
|
+
exports.sanitize = L;
|
9
|
+
exports.storyNameFromExport = M;
|
10
|
+
exports.toId = N;
|
package/dist/index.mjs
CHANGED
@@ -1,73 +1,3 @@
|
|
1
|
-
|
2
|
-
import startCase from "lodash/startCase";
|
1
|
+
var B=Object.create;var R=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var I=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var E=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of C(r))!w.call(e,a)&&a!==n&&R(e,a,{get:()=>r[a],enumerable:!(o=b(r,a))||o.enumerable});return e};var P=(e,r,n)=>(n=e!=null?B(h(e)):{},E(r||!e||!e.__esModule?R(n,"default",{value:e,enumerable:!0}):n,e));var x=I(T=>{Object.defineProperty(T,"__esModule",{value:!0}),T.isEqual=function(){var e=Object.prototype.toString,r=Object.getPrototypeOf,n=Object.getOwnPropertySymbols?function(o){return Object.keys(o).concat(Object.getOwnPropertySymbols(o))}:Object.keys;return function(o,a){return function i(t,s,d){var y,g,p,A=e.call(t),F=e.call(s);if(t===s)return !0;if(t==null||s==null)return !1;if(d.indexOf(t)>-1&&d.indexOf(s)>-1)return !0;if(d.push(t,s),A!=F||(y=n(t),g=n(s),y.length!=g.length||y.some(function(l){return !i(t[l],s[l],d)})))return !1;switch(A.slice(8,-1)){case"Symbol":return t.valueOf()==s.valueOf();case"Date":case"Number":return +t==+s||+t!=+t&&+s!=+s;case"RegExp":case"Function":case"String":case"Boolean":return ""+t==""+s;case"Set":case"Map":y=t.entries(),g=s.entries();do if(!i((p=y.next()).value,g.next().value,d))return !1;while(!p.done);return !0;case"ArrayBuffer":t=new Uint8Array(t),s=new Uint8Array(s);case"DataView":t=new Uint8Array(t.buffer),s=new Uint8Array(s.buffer);case"Float32Array":case"Float64Array":case"Int8Array":case"Int16Array":case"Int32Array":case"Uint8Array":case"Uint16Array":case"Uint32Array":case"Uint8ClampedArray":case"Arguments":case"Array":if(t.length!=s.length)return !1;for(p=0;p<t.length;p++)if((p in t||p in s)&&(p in t!=p in s||!i(t[p],s[p],d)))return !1;return !0;case"Object":return i(r(t),r(s),d);default:return !1}}(o,a,[])}}();});function u(e){return e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,(r,n,o)=>`${n} ${o}`).replace(/([a-z])([0-9])/gi,(r,n,o)=>`${n} ${o}`).replace(/(\s|^)(\w)/g,(r,n,o)=>n+o.toUpperCase()).trim()}var c=P(x()),S=e=>e.map(r=>typeof r<"u").filter(Boolean).length,O=(e,r)=>{let{exists:n,eq:o,neq:a,truthy:i}=e;if(S([n,o,a,i])>1)throw new Error(`Invalid conditional test ${JSON.stringify({exists:n,eq:o,neq:a})}`);if(typeof o<"u")return (0, c.isEqual)(r,o);if(typeof a<"u")return !(0, c.isEqual)(r,a);if(typeof n<"u"){let s=typeof r<"u";return n?s:!s}return (typeof i>"u"?!0:i)?!!r:!r},v=(e,r,n)=>{if(!e.if)return !0;let{arg:o,global:a}=e.if;if(S([o,a])!==1)throw new Error(`Invalid conditional value ${JSON.stringify({arg:o,global:a})}`);let i=o?r[o]:n[a];return O(e.if,i)};var L=e=>e.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),m=(e,r)=>{let n=L(e);if(n==="")throw new Error(`Invalid ${r} '${e}', must include alphanumeric characters`);return n},N=(e,r)=>`${m(e,"kind")}${r?`--${m(r,"name")}`:""}`,M=e=>u(e);function f(e,r){return Array.isArray(r)?r.includes(e):e.match(r)}function G(e,{includeStories:r,excludeStories:n}){return e!=="__esModule"&&(!r||f(e,r))&&(!n||!f(e,n))}var V=(e,{rootSeparator:r,groupSeparator:n})=>{let[o,a]=e.split(r,2),i=(a||e).split(n).filter(t=>!!t);return {root:a?o:null,groups:i}};
|
3
2
|
|
4
|
-
|
5
|
-
import isEqual from "lodash/isEqual";
|
6
|
-
var count = (vals) => vals.map((v) => typeof v !== "undefined").filter(Boolean).length;
|
7
|
-
var testValue = (cond, value) => {
|
8
|
-
const { exists, eq, neq, truthy } = cond;
|
9
|
-
if (count([exists, eq, neq, truthy]) > 1) {
|
10
|
-
throw new Error(`Invalid conditional test ${JSON.stringify({ exists, eq, neq })}`);
|
11
|
-
}
|
12
|
-
if (typeof eq !== "undefined") {
|
13
|
-
return isEqual(value, eq);
|
14
|
-
}
|
15
|
-
if (typeof neq !== "undefined") {
|
16
|
-
return !isEqual(value, neq);
|
17
|
-
}
|
18
|
-
if (typeof exists !== "undefined") {
|
19
|
-
const valueExists = typeof value !== "undefined";
|
20
|
-
return exists ? valueExists : !valueExists;
|
21
|
-
}
|
22
|
-
const shouldBeTruthy = typeof truthy === "undefined" ? true : truthy;
|
23
|
-
return shouldBeTruthy ? !!value : !value;
|
24
|
-
};
|
25
|
-
var includeConditionalArg = (argType, args, globals) => {
|
26
|
-
if (!argType.if)
|
27
|
-
return true;
|
28
|
-
const { arg, global } = argType.if;
|
29
|
-
if (count([arg, global]) !== 1) {
|
30
|
-
throw new Error(`Invalid conditional value ${JSON.stringify({ arg, global })}`);
|
31
|
-
}
|
32
|
-
const value = arg ? args[arg] : globals[global];
|
33
|
-
return testValue(argType.if, value);
|
34
|
-
};
|
35
|
-
|
36
|
-
// src/index.ts
|
37
|
-
var sanitize = (string) => {
|
38
|
-
return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
39
|
-
};
|
40
|
-
var sanitizeSafe = (string, part) => {
|
41
|
-
const sanitized = sanitize(string);
|
42
|
-
if (sanitized === "") {
|
43
|
-
throw new Error(`Invalid ${part} '${string}', must include alphanumeric characters`);
|
44
|
-
}
|
45
|
-
return sanitized;
|
46
|
-
};
|
47
|
-
var toId = (kind, name) => `${sanitizeSafe(kind, "kind")}${name ? `--${sanitizeSafe(name, "name")}` : ""}`;
|
48
|
-
var storyNameFromExport = (key) => startCase(key);
|
49
|
-
function matches(storyKey, arrayOrRegex) {
|
50
|
-
if (Array.isArray(arrayOrRegex)) {
|
51
|
-
return arrayOrRegex.includes(storyKey);
|
52
|
-
}
|
53
|
-
return storyKey.match(arrayOrRegex);
|
54
|
-
}
|
55
|
-
function isExportStory(key, { includeStories, excludeStories }) {
|
56
|
-
return key !== "__esModule" && (!includeStories || matches(key, includeStories)) && (!excludeStories || !matches(key, excludeStories));
|
57
|
-
}
|
58
|
-
var parseKind = (kind, { rootSeparator, groupSeparator }) => {
|
59
|
-
const [root, remainder] = kind.split(rootSeparator, 2);
|
60
|
-
const groups = (remainder || kind).split(groupSeparator).filter((i) => !!i);
|
61
|
-
return {
|
62
|
-
root: remainder ? root : null,
|
63
|
-
groups
|
64
|
-
};
|
65
|
-
};
|
66
|
-
export {
|
67
|
-
includeConditionalArg,
|
68
|
-
isExportStory,
|
69
|
-
parseKind,
|
70
|
-
sanitize,
|
71
|
-
storyNameFromExport,
|
72
|
-
toId
|
73
|
-
};
|
3
|
+
export { v as includeConditionalArg, G as isExportStory, V as parseKind, L as sanitize, M as storyNameFromExport, N as toId };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/csf",
|
3
|
-
"version": "0.0.2-next.
|
3
|
+
"version": "0.0.2-next.9",
|
4
4
|
"description": "Component Story Format (CSF) utilities",
|
5
5
|
"keywords": [
|
6
6
|
"storybook",
|
@@ -17,32 +17,33 @@
|
|
17
17
|
"url": "https://github.com/ComponentDriven/csf.git"
|
18
18
|
},
|
19
19
|
"license": "MIT",
|
20
|
-
"files": [
|
21
|
-
"dist/**/*",
|
22
|
-
"README.md",
|
23
|
-
"*.js",
|
24
|
-
"*.d.ts"
|
25
|
-
],
|
26
20
|
"exports": {
|
27
21
|
".": {
|
28
22
|
"import": "./dist/index.mjs",
|
29
|
-
"require": "./dist/index.js"
|
23
|
+
"require": "./dist/index.js",
|
24
|
+
"browser": "./dist/index.mjs",
|
25
|
+
"node": "./dist/index.js",
|
26
|
+
"types": "./dist/index.d.ts"
|
30
27
|
}
|
31
28
|
},
|
32
29
|
"main": "dist/index.js",
|
33
30
|
"module": "dist/index.mjs",
|
34
31
|
"types": "dist/index.d.ts",
|
32
|
+
"files": [
|
33
|
+
"dist/**/*",
|
34
|
+
"README.md",
|
35
|
+
"*.js",
|
36
|
+
"*.d.ts"
|
37
|
+
],
|
35
38
|
"scripts": {
|
36
|
-
"build": "tsup ./src/index.ts --format esm,cjs --dts",
|
39
|
+
"build": "tsup ./src/index.ts --format esm,cjs --dts --treeshake --minify",
|
37
40
|
"check": "tsc",
|
38
41
|
"lint": "eslint src --ext .ts",
|
39
|
-
"
|
40
|
-
"
|
42
|
+
"release": "yarn build && auto shipit",
|
43
|
+
"test": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules jest"
|
41
44
|
},
|
45
|
+
"prettier": "@storybook/linter-config/prettier.config",
|
42
46
|
"eslintConfig": {
|
43
|
-
"extends": [
|
44
|
-
"@storybook/eslint-config-storybook"
|
45
|
-
],
|
46
47
|
"parserOptions": {
|
47
48
|
"project": [
|
48
49
|
"./tsconfig.json"
|
@@ -57,6 +58,9 @@
|
|
57
58
|
}
|
58
59
|
}
|
59
60
|
},
|
61
|
+
"extends": [
|
62
|
+
"@storybook/eslint-config-storybook"
|
63
|
+
],
|
60
64
|
"rules": {
|
61
65
|
"import/no-unresolved": "error",
|
62
66
|
"jest/expect-expect": [
|
@@ -70,15 +74,18 @@
|
|
70
74
|
]
|
71
75
|
}
|
72
76
|
},
|
73
|
-
"prettier": "@storybook/linter-config/prettier.config",
|
74
77
|
"jest": {
|
75
|
-
"preset": "ts-jest/presets/default-esm",
|
76
78
|
"extensionsToTreatAsEsm": [
|
77
79
|
".ts"
|
78
80
|
],
|
79
81
|
"moduleNameMapper": {
|
80
82
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
81
83
|
},
|
84
|
+
"preset": "ts-jest/presets/default-esm",
|
85
|
+
"roots": [
|
86
|
+
"<rootDir>/src"
|
87
|
+
],
|
88
|
+
"testEnvironment": "node",
|
82
89
|
"transform": {
|
83
90
|
"^.+\\.tsx?$": [
|
84
91
|
"ts-jest",
|
@@ -86,22 +93,16 @@
|
|
86
93
|
"useESM": true
|
87
94
|
}
|
88
95
|
]
|
89
|
-
}
|
90
|
-
"testEnvironment": "node",
|
91
|
-
"roots": [
|
92
|
-
"<rootDir>/src"
|
93
|
-
]
|
96
|
+
}
|
94
97
|
},
|
95
98
|
"dependencies": {
|
96
|
-
"expect-type": "^0.14.2",
|
97
|
-
"lodash": "^4.17.15",
|
98
99
|
"type-fest": "^2.19.0"
|
99
100
|
},
|
100
101
|
"devDependencies": {
|
101
102
|
"@auto-it/released": "^10.37.6",
|
103
|
+
"@ngard/tiny-isequal": "^1.1.0",
|
102
104
|
"@storybook/eslint-config-storybook": "^3.1.2",
|
103
105
|
"@types/jest": "^29.2.0",
|
104
|
-
"@types/lodash": "^4.14.149",
|
105
106
|
"@types/node": "^18.11.0",
|
106
107
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
107
108
|
"@typescript-eslint/parser": "^5.42.1",
|
@@ -111,19 +112,20 @@
|
|
111
112
|
"eslint-import-resolver-typescript": "^3.5.2",
|
112
113
|
"eslint-plugin-import": "^2.26.0",
|
113
114
|
"eslint-plugin-jest": "^27.1.4",
|
115
|
+
"expect-type": "^0.14.2",
|
114
116
|
"jest": "^29.3.1",
|
115
117
|
"prettier": "^2.7.1",
|
116
118
|
"ts-jest": "^29.0.3",
|
117
119
|
"tsup": "^6.4.0",
|
118
120
|
"typescript": "^4.8.4"
|
119
121
|
},
|
122
|
+
"publishConfig": {
|
123
|
+
"access": "public"
|
124
|
+
},
|
120
125
|
"auto": {
|
121
126
|
"plugins": [
|
122
127
|
"npm",
|
123
128
|
"released"
|
124
129
|
]
|
125
|
-
},
|
126
|
-
"publishConfig": {
|
127
|
-
"access": "public"
|
128
130
|
}
|
129
131
|
}
|