@storybook/csf 0.0.2--canary.49.258942b.0 → 0.0.2--canary.51.23af5af.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,19 +1,335 @@
1
- export declare const sanitize: (string: string) => string;
2
- export declare const toId: (kind: string, name?: string | undefined) => string;
3
- export declare const storyNameFromExport: (key: string) => string;
1
+ import { Simplify, UnionToIntersection } from 'type-fest';
2
+
3
+ interface SBBaseType {
4
+ required?: boolean;
5
+ raw?: string;
6
+ }
7
+ declare type SBScalarType = SBBaseType & {
8
+ name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
9
+ };
10
+ declare type SBArrayType = SBBaseType & {
11
+ name: 'array';
12
+ value: SBType;
13
+ };
14
+ declare type SBObjectType = SBBaseType & {
15
+ name: 'object';
16
+ value: Record<string, SBType>;
17
+ };
18
+ declare type SBEnumType = SBBaseType & {
19
+ name: 'enum';
20
+ value: (string | number)[];
21
+ };
22
+ declare type SBIntersectionType = SBBaseType & {
23
+ name: 'intersection';
24
+ value: SBType[];
25
+ };
26
+ declare type SBUnionType = SBBaseType & {
27
+ name: 'union';
28
+ value: SBType[];
29
+ };
30
+ declare type SBOtherType = SBBaseType & {
31
+ name: 'other';
32
+ value: string;
33
+ };
34
+ declare type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
35
+
36
+ declare type StoryId = string;
37
+ declare type ComponentId = string;
38
+ declare type ComponentTitle = string;
39
+ declare type StoryName = string;
40
+ /** @deprecated */
41
+ declare type StoryKind = ComponentTitle;
42
+ interface StoryIdentifier {
43
+ componentId: ComponentId;
44
+ title: ComponentTitle;
45
+ /** @deprecated */
46
+ kind: ComponentTitle;
47
+ id: StoryId;
48
+ name: StoryName;
49
+ /** @deprecated */
50
+ story: StoryName;
51
+ }
52
+ declare type Parameters = {
53
+ [name: string]: any;
54
+ };
55
+ declare type ConditionalTest = {
56
+ truthy?: boolean;
57
+ } | {
58
+ exists: boolean;
59
+ } | {
60
+ eq: any;
61
+ } | {
62
+ neq: any;
63
+ };
64
+ declare type ConditionalValue = {
65
+ arg: string;
66
+ } | {
67
+ global: string;
68
+ };
69
+ declare type Conditional = ConditionalValue & ConditionalTest;
70
+ interface InputType {
71
+ name?: string;
72
+ description?: string;
73
+ defaultValue?: any;
74
+ type?: SBType | SBScalarType['name'];
75
+ if?: Conditional;
76
+ [key: string]: any;
77
+ }
78
+ interface StrictInputType extends InputType {
79
+ name: string;
80
+ type?: SBType;
81
+ }
82
+ declare type Args = {
83
+ [name: string]: any;
84
+ };
85
+ declare type ArgTypes<TArgs = Args> = {
86
+ [name in keyof TArgs]: InputType;
87
+ };
88
+ declare type StrictArgTypes<TArgs = Args> = {
89
+ [name in keyof TArgs]: StrictInputType;
90
+ };
91
+ declare type Globals = {
92
+ [name: string]: any;
93
+ };
94
+ declare type GlobalTypes = {
95
+ [name: string]: InputType;
96
+ };
97
+ declare type StrictGlobalTypes = {
98
+ [name: string]: StrictInputType;
99
+ };
100
+ declare type AnyFramework = {
101
+ component: unknown;
102
+ storyResult: unknown;
103
+ T?: unknown;
104
+ };
105
+ declare type StoryContextForEnhancers<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryIdentifier & {
106
+ component?: (TFramework & {
107
+ T: any;
108
+ })['component'];
109
+ subcomponents?: Record<string, (TFramework & {
110
+ T: any;
111
+ })['component']>;
112
+ parameters: Parameters;
113
+ initialArgs: TArgs;
114
+ argTypes: StrictArgTypes<TArgs>;
115
+ };
116
+ declare type ArgsEnhancer<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForEnhancers<TFramework, TArgs>) => TArgs;
117
+ declare type ArgTypesEnhancer<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ((context: StoryContextForEnhancers<TFramework, TArgs>) => StrictArgTypes<TArgs>) & {
118
+ secondPass?: boolean;
119
+ };
120
+ declare type StoryContextUpdate<TArgs = Args> = {
121
+ args?: TArgs;
122
+ globals?: Globals;
123
+ [key: string]: any;
124
+ };
125
+ declare type ViewMode = 'story' | 'docs';
126
+ declare type StoryContextForLoaders<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContextForEnhancers<TFramework, TArgs> & Required<StoryContextUpdate<TArgs>> & {
127
+ hooks: unknown;
128
+ viewMode: ViewMode;
129
+ originalStoryFn: StoryFn<TFramework>;
130
+ };
131
+ declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
132
+ declare type StoryContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContextForLoaders<TFramework, TArgs> & {
133
+ loaded: Record<string, any>;
134
+ abortSignal: AbortSignal;
135
+ canvasElement: HTMLElement;
136
+ };
137
+ declare type StepLabel = string;
138
+ declare type StepFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (label: StepLabel, play: PlayFunction<TFramework, TArgs>) => Promise<void> | void;
139
+ declare type PlayFunctionContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContext<TFramework, TArgs> & {
140
+ step: StepFunction<TFramework, TArgs>;
141
+ };
142
+ declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: PlayFunctionContext<TFramework, TArgs>) => Promise<void> | void;
143
+ declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<Partial<TArgs>>) => TFramework['storyResult'];
144
+ declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
145
+ declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => (TFramework & {
146
+ T: TArgs;
147
+ })['storyResult'];
148
+ declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyStoryFn<TFramework, TArgs> | ArgsStoryFn<TFramework, TArgs>;
149
+ declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
150
+ declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
151
+ declare type StepRunner<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (label: StepLabel, play: PlayFunction<TFramework, TArgs>, context: PlayFunctionContext<TFramework, TArgs>) => Promise<void>;
152
+ declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = {
153
+ /**
154
+ * Wrapper components or Storybook decorators that wrap a story.
155
+ *
156
+ * Decorators defined in Meta will be applied to every story variation.
157
+ * @see [Decorators](https://storybook.js.org/docs/addons/introduction/#1-decorators)
158
+ */
159
+ decorators?: DecoratorFunction<TFramework, TArgs>[];
160
+ /**
161
+ * Custom metadata for a story.
162
+ * @see [Parameters](https://storybook.js.org/docs/basics/writing-stories/#parameters)
163
+ */
164
+ parameters?: Parameters;
165
+ /**
166
+ * Dynamic data that are provided (and possibly updated by) Storybook and its addons.
167
+ * @see [Arg story inputs](https://storybook.js.org/docs/react/api/csf#args-story-inputs)
168
+ */
169
+ args?: Partial<TArgs>;
170
+ /**
171
+ * ArgTypes encode basic metadata for args, such as `name`, `description`, `defaultValue` for an arg. These get automatically filled in by Storybook Docs.
172
+ * @see [Control annotations](https://github.com/storybookjs/storybook/blob/91e9dee33faa8eff0b342a366845de7100415367/addons/controls/README.md#control-annotations)
173
+ */
174
+ argTypes?: Partial<ArgTypes<TArgs>>;
175
+ /**
176
+ * Asynchronous functions which provide data for a story.
177
+ * @see [Loaders](https://storybook.js.org/docs/react/writing-stories/loaders)
178
+ */
179
+ loaders?: LoaderFunction<TFramework, TArgs>[];
180
+ /**
181
+ * Define a custom render function for the story(ies). If not passed, a default render function by the framework will be used.
182
+ */
183
+ render?: ArgsStoryFn<TFramework, TArgs>;
184
+ };
185
+ declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
186
+ argsEnhancers?: ArgsEnhancer<TFramework, Args>[];
187
+ argTypesEnhancers?: ArgTypesEnhancer<TFramework, Args>[];
188
+ globals?: Globals;
189
+ globalTypes?: GlobalTypes;
190
+ applyDecorators?: DecoratorApplicator<TFramework, Args>;
191
+ runStep?: StepRunner<TFramework, TArgs>;
192
+ };
193
+ declare type StoryDescriptor$1 = string[] | RegExp;
194
+ interface ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> extends BaseAnnotations<TFramework, TArgs> {
195
+ /**
196
+ * Title of the component which will be presented in the navigation. **Should be unique.**
197
+ *
198
+ * Components can be organized in a nested structure using "/" as a separator.
199
+ *
200
+ * Since CSF 3.0 this property is optional -- it can be inferred from the filesystem path
201
+ *
202
+ * @example
203
+ * export default {
204
+ * ...
205
+ * title: 'Design System/Atoms/Button'
206
+ * }
207
+ *
208
+ * @see [Story Hierarchy](https://storybook.js.org/docs/basics/writing-stories/#story-hierarchy)
209
+ */
210
+ title?: ComponentTitle;
211
+ /**
212
+ * Id of the component (prefix of the story id) which is used for URLs.
213
+ *
214
+ * By default is inferred from sanitizing the title
215
+ *
216
+ * @see [Story Hierarchy](https://storybook.js.org/docs/basics/writing-stories/#story-hierarchy)
217
+ */
218
+ id?: ComponentId;
219
+ /**
220
+ * Used to only include certain named exports as stories. Useful when you want to have non-story exports such as mock data or ignore a few stories.
221
+ * @example
222
+ * includeStories: ['SimpleStory', 'ComplexStory']
223
+ * includeStories: /.*Story$/
224
+ *
225
+ * @see [Non-story exports](https://storybook.js.org/docs/formats/component-story-format/#non-story-exports)
226
+ */
227
+ includeStories?: StoryDescriptor$1;
228
+ /**
229
+ * Used to exclude certain named exports. Useful when you want to have non-story exports such as mock data or ignore a few stories.
230
+ * @example
231
+ * excludeStories: ['simpleData', 'complexData']
232
+ * excludeStories: /.*Data$/
233
+ *
234
+ * @see [Non-story exports](https://storybook.js.org/docs/formats/component-story-format/#non-story-exports)
235
+ */
236
+ excludeStories?: StoryDescriptor$1;
237
+ /**
238
+ * The primary component for your story.
239
+ *
240
+ * Used by addons for automatic prop table generation and display of other component metadata.
241
+ */
242
+ component?: (TFramework & {
243
+ T: Args extends TArgs ? any : TArgs;
244
+ })['component'];
245
+ /**
246
+ * Auxiliary subcomponents that are part of the stories.
247
+ *
248
+ * Used by addons for automatic prop table generation and display of other component metadata.
249
+ *
250
+ * @example
251
+ * import { Button, ButtonGroup } from './components';
252
+ *
253
+ * export default {
254
+ * ...
255
+ * subcomponents: { Button, ButtonGroup }
256
+ * }
257
+ *
258
+ * By defining them each component will have its tab in the args table.
259
+ */
260
+ subcomponents?: Record<string, TFramework['component']>;
261
+ }
262
+ declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args, TRequiredArgs = Partial<TArgs>> = BaseAnnotations<TFramework, TArgs> & {
263
+ /**
264
+ * Override the display name in the UI (CSF v3)
265
+ */
266
+ name?: StoryName;
267
+ /**
268
+ * Override the display name in the UI (CSF v2)
269
+ */
270
+ storyName?: StoryName;
271
+ /**
272
+ * Function that is executed after the story is rendered.
273
+ */
274
+ play?: PlayFunction<TFramework, TArgs>;
275
+ /** @deprecated */
276
+ story?: Omit<StoryAnnotations<TFramework, TArgs>, 'story'>;
277
+ } & ({} extends TRequiredArgs ? {
278
+ args?: TRequiredArgs;
279
+ } : {
280
+ args: TRequiredArgs;
281
+ });
282
+ declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
283
+ declare type LegacyStoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyAnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
284
+ declare type AnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
285
+ declare type StoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = AnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
286
+ declare type ArgsFromMeta<TFramework extends AnyFramework, Meta> = Meta extends {
287
+ render?: ArgsStoryFn<TFramework, infer RArgs>;
288
+ loaders?: (infer Loaders)[];
289
+ decorators?: (infer Decorators)[];
290
+ } ? Simplify<RArgs & DecoratorsArgs<TFramework, Decorators> & LoaderArgs<TFramework, Loaders>> : unknown;
291
+ declare type DecoratorsArgs<TFramework extends AnyFramework, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TFramework, infer TArgs> ? TArgs : unknown>;
292
+ declare type LoaderArgs<TFramework extends AnyFramework, Loaders> = UnionToIntersection<Loaders extends LoaderFunction<TFramework, infer TArgs> ? TArgs : unknown>;
293
+
294
+ /**
295
+ * Helper function to include/exclude an arg based on the value of other other args
296
+ * aka "conditional args"
297
+ */
298
+ declare const includeConditionalArg: (argType: InputType, args: Args, globals: Globals) => boolean;
299
+
300
+ /**
301
+ * Remove punctuation and illegal characters from a story ID.
302
+ *
303
+ * See https://gist.github.com/davidjrice/9d2af51100e41c6c4b4a
304
+ */
305
+ declare const sanitize: (string: string) => string;
306
+ /**
307
+ * Generate a storybook ID from a component/kind and story name.
308
+ */
309
+ declare const toId: (kind: string, name?: string) => string;
310
+ /**
311
+ * Transform a CSF named export into a readable story name
312
+ */
313
+ declare const storyNameFromExport: (key: string) => string;
4
314
  declare type StoryDescriptor = string[] | RegExp;
5
- export interface IncludeExcludeOptions {
315
+ interface IncludeExcludeOptions {
6
316
  includeStories?: StoryDescriptor;
7
317
  excludeStories?: StoryDescriptor;
8
318
  }
9
- export declare function isExportStory(key: string, { includeStories, excludeStories }: IncludeExcludeOptions): boolean | null;
10
- export interface SeparatorOptions {
319
+ /**
320
+ * Does a named export match CSF inclusion/exclusion options?
321
+ */
322
+ declare function isExportStory(key: string, { includeStories, excludeStories }: IncludeExcludeOptions): boolean | null;
323
+ interface SeparatorOptions {
11
324
  rootSeparator: string | RegExp;
12
325
  groupSeparator: string | RegExp;
13
326
  }
14
- export declare const parseKind: (kind: string, { rootSeparator, groupSeparator }: SeparatorOptions) => {
327
+ /**
328
+ * Parse out the component/kind name from a path, using the given separator config.
329
+ */
330
+ declare const parseKind: (kind: string, { rootSeparator, groupSeparator }: SeparatorOptions) => {
15
331
  root: string | null;
16
332
  groups: string[];
17
333
  };
18
- export { includeConditionalArg } from './includeConditionalArg';
19
- export * from './story';
334
+
335
+ export { AnnotatedStoryFn, AnyFramework, ArgTypes, ArgTypesEnhancer, Args, ArgsEnhancer, ArgsFromMeta, ArgsStoryFn, BaseAnnotations, ComponentAnnotations, ComponentId, ComponentTitle, Conditional, DecoratorApplicator, DecoratorFunction, GlobalTypes, Globals, IncludeExcludeOptions, InputType, LegacyAnnotatedStoryFn, LegacyStoryAnnotationsOrFn, LegacyStoryFn, LoaderFunction, Parameters, PartialStoryFn, PlayFunction, PlayFunctionContext, ProjectAnnotations, SBArrayType, SBEnumType, SBIntersectionType, SBObjectType, SBOtherType, SBScalarType, SBType, SBUnionType, SeparatorOptions, StepFunction, StepLabel, StepRunner, StoryAnnotations, StoryAnnotationsOrFn, StoryContext, StoryContextForEnhancers, StoryContextForLoaders, StoryContextUpdate, StoryFn, StoryId, StoryIdentifier, StoryKind, StoryName, StrictArgTypes, StrictGlobalTypes, StrictInputType, ViewMode, includeConditionalArg, isExportStory, parseKind, sanitize, storyNameFromExport, toId };
package/dist/index.js CHANGED
@@ -1,138 +1,109 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- sanitize: true,
8
- toId: true,
9
- storyNameFromExport: true,
10
- isExportStory: true,
11
- parseKind: true,
12
- includeConditionalArg: true
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 });
13
11
  };
14
- exports.isExportStory = isExportStory;
15
- Object.defineProperty(exports, "includeConditionalArg", {
16
- enumerable: true,
17
- get: function get() {
18
- return _includeConditionalArg.includeConditionalArg;
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 });
19
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);
25
+
26
+ // src/index.ts
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
20
35
  });
21
- exports.parseKind = exports.storyNameFromExport = exports.toId = exports.sanitize = void 0;
22
-
23
- var _startCase = _interopRequireDefault(require("lodash/startCase"));
24
-
25
- var _includeConditionalArg = require("./includeConditionalArg");
26
-
27
- var _story = require("./story");
28
-
29
- Object.keys(_story).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function get() {
35
- return _story[key];
36
- }
37
- });
38
- });
39
-
40
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
41
-
42
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
-
44
- 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."); }
45
-
46
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
47
-
48
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
49
-
50
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
51
-
52
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
53
-
54
- /**
55
- * Remove punctuation and illegal characters from a story ID.
56
- *
57
- * See https://gist.github.com/davidjrice/9d2af51100e41c6c4b4a
58
- */
59
- var sanitize = function sanitize(string) {
60
- return string.toLowerCase() // eslint-disable-next-line no-useless-escape
61
- .replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '-').replace(/-+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_startCase = __toESM(require("lodash/startCase"));
38
+
39
+ // src/includeConditionalArg.ts
40
+ var import_isEqual = __toESM(require("lodash/isEqual"));
41
+ var count = (vals) => vals.map((v) => typeof v !== "undefined").filter(Boolean).length;
42
+ var testValue = (cond, value) => {
43
+ const { exists, eq, neq, truthy } = cond;
44
+ if (count([exists, eq, neq, truthy]) > 1) {
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;
62
59
  };
63
-
64
- exports.sanitize = sanitize;
65
-
66
- var sanitizeSafe = function sanitizeSafe(string, part) {
67
- var sanitized = sanitize(string);
68
-
69
- if (sanitized === '') {
70
- throw new Error("Invalid ".concat(part, " '").concat(string, "', must include alphanumeric characters"));
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 })}`);
71
66
  }
72
-
73
- return sanitized;
67
+ const value = arg ? args[arg] : globals[global];
68
+ return testValue(argType.if, value);
74
69
  };
75
- /**
76
- * Generate a storybook ID from a component/kind and story name.
77
- */
78
-
79
70
 
80
- var toId = function toId(kind, name) {
81
- return "".concat(sanitizeSafe(kind, 'kind')).concat(name ? "--".concat(sanitizeSafe(name, 'name')) : '');
71
+ // src/index.ts
72
+ var sanitize = (string) => {
73
+ return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
82
74
  };
83
- /**
84
- * Transform a CSF named export into a readable story name
85
- */
86
-
87
-
88
- exports.toId = toId;
89
-
90
- var storyNameFromExport = function storyNameFromExport(key) {
91
- return (0, _startCase["default"])(key);
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;
92
81
  };
93
-
94
- exports.storyNameFromExport = storyNameFromExport;
95
-
82
+ var toId = (kind, name) => `${sanitizeSafe(kind, "kind")}${name ? `--${sanitizeSafe(name, "name")}` : ""}`;
83
+ var storyNameFromExport = (key) => (0, import_startCase.default)(key);
96
84
  function matches(storyKey, arrayOrRegex) {
97
85
  if (Array.isArray(arrayOrRegex)) {
98
86
  return arrayOrRegex.includes(storyKey);
99
87
  }
100
-
101
88
  return storyKey.match(arrayOrRegex);
102
89
  }
103
- /**
104
- * Does a named export match CSF inclusion/exclusion options?
105
- */
106
-
107
-
108
- function isExportStory(key, _ref) {
109
- var includeStories = _ref.includeStories,
110
- excludeStories = _ref.excludeStories;
111
- return (// https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs
112
- key !== '__esModule' && (!includeStories || matches(key, includeStories)) && (!excludeStories || !matches(key, excludeStories))
113
- );
90
+ function isExportStory(key, { includeStories, excludeStories }) {
91
+ return key !== "__esModule" && (!includeStories || matches(key, includeStories)) && (!excludeStories || !matches(key, excludeStories));
114
92
  }
115
-
116
- /**
117
- * Parse out the component/kind name from a path, using the given separator config.
118
- */
119
- var parseKind = function parseKind(kind, _ref2) {
120
- var rootSeparator = _ref2.rootSeparator,
121
- groupSeparator = _ref2.groupSeparator;
122
-
123
- var _kind$split = kind.split(rootSeparator, 2),
124
- _kind$split2 = _slicedToArray(_kind$split, 2),
125
- root = _kind$split2[0],
126
- remainder = _kind$split2[1];
127
-
128
- var groups = (remainder || kind).split(groupSeparator).filter(function (i) {
129
- return !!i;
130
- }); // when there's no remainder, it means the root wasn't found/split
131
-
93
+ var parseKind = (kind, { rootSeparator, groupSeparator }) => {
94
+ const [root, remainder] = kind.split(rootSeparator, 2);
95
+ const groups = (remainder || kind).split(groupSeparator).filter((i) => !!i);
132
96
  return {
133
97
  root: remainder ? root : null,
134
- groups: groups
98
+ groups
135
99
  };
136
100
  };
137
-
138
- exports.parseKind = parseKind;
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
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,73 @@
1
+ // src/index.ts
2
+ import startCase from "lodash/startCase";
3
+
4
+ // src/includeConditionalArg.ts
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
+ };