@storybook/csf 0.0.2--canary.b1d5348.0 → 0.0.2--canary.87bc651.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -30,7 +30,7 @@ export const emoji = () => <Button>😀😎👍💯</Button>;
30
30
 
31
31
  ### Who uses CSF?
32
32
 
33
- **Tools:** [Storybook](https://storybook.js.org), [WebComponents.dev](https://webcomponents.dev), [RedwoodJS](https://redwoodjs.com/), [UXPin](https://www.uxpin.com/)
33
+ **Tools:** [Storybook](https://storybook.js.org), [WebComponents.dev](https://webcomponents.dev), [Components.studio](https://components.studio), [RedwoodJS](https://redwoodjs.com/), [UXPin](https://www.uxpin.com/)
34
34
 
35
35
  **Compatible with:** [Jest](https://jestjs.io/), [Enzyme](https://enzymejs.github.io/enzyme), [Testing Library](https://testing-library.com), [Cypress](https://www.cypress.io/), [Playwright](https://playwright.dev/), [Mocha](https://mochajs.org), etc.
36
36
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const sanitize: (string: string) => string;
2
- export declare const toId: (kind: string, name: string) => string;
2
+ export declare const toId: (kind: string, name?: string | undefined) => string;
3
3
  export declare const storyNameFromExport: (key: string) => string;
4
4
  declare type StoryDescriptor = string[] | RegExp;
5
5
  export interface IncludeExcludeOptions {
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ var sanitizeSafe = function sanitizeSafe(string, part) {
69
69
 
70
70
 
71
71
  var toId = function toId(kind, name) {
72
- return "".concat(sanitizeSafe(kind, 'kind'), "--").concat(sanitizeSafe(name, 'name'));
72
+ return "".concat(sanitizeSafe(kind, 'kind')).concat(name ? "--".concat(sanitizeSafe(name, 'name')) : '');
73
73
  };
74
74
  /**
75
75
  * Transform a CSF named export into a readable story name
@@ -15,8 +15,9 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
 
17
17
  describe('toId', function () {
18
- [// name, kind, story, output
19
- ['handles simple cases', 'kind', 'story', 'kind--story'], ['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d😀e--1-2-3'], ['handles runs of non-url chars', 'a?&*b', 'story', 'a-b--story'], ['removes non-url chars from start and end', '?ab-', 'story', 'ab--story'], ['downcases', 'KIND', 'STORY', 'kind--story'], ['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'], ['korean', 'kind', '바보 (babo)', 'kind--바보-babo'], ['all punctuation', 'kind', 'unicorns,’–—―′¿`"<>()!.!!!{}[]%^&$*#&', 'kind--unicorns']].forEach(function (_ref) {
18
+ var testCases = [// name, kind, story, output
19
+ ['handles simple cases', 'kind', 'story', 'kind--story'], ['handles kind without story', 'kind', undefined, 'kind'], ['handles basic substitution', 'a b$c?d😀e', '1-2:3', 'a-b-c-d😀e--1-2-3'], ['handles runs of non-url chars', 'a?&*b', 'story', 'a-b--story'], ['removes non-url chars from start and end', '?ab-', 'story', 'ab--story'], ['downcases', 'KIND', 'STORY', 'kind--story'], ['non-latin', 'Кнопки', 'нормальный', 'кнопки--нормальный'], ['korean', 'kind', '바보 (babo)', 'kind--바보-babo'], ['all punctuation', 'kind', 'unicorns,’–—―′¿`"<>()!.!!!{}[]%^&$*#&', 'kind--unicorns']];
20
+ testCases.forEach(function (_ref) {
20
21
  var _ref2 = _slicedToArray(_ref, 4),
21
22
  name = _ref2[0],
22
23
  kind = _ref2[1],
@@ -42,10 +43,10 @@ describe('toId', function () {
42
43
  return (0, _.toId)('kind', '?');
43
44
  }).toThrow("Invalid name '?', must include alphanumeric characters");
44
45
  });
45
- it('does not allow empty story', function () {
46
+ it('allows empty story', function () {
46
47
  expect(function () {
47
48
  return (0, _.toId)('kind', '');
48
- }).toThrow("Invalid name '', must include alphanumeric characters");
49
+ }).not.toThrow();
49
50
  });
50
51
  });
51
52
  describe('storyNameFromExport', function () {
@@ -0,0 +1,75 @@
1
+ export declare enum PropertyTypes {
2
+ TEXT = "text",
3
+ NUMBER = "number",
4
+ BOOLEAN = "boolean",
5
+ OPTIONS = "options",
6
+ DATE = "date",
7
+ COLOR = "color",
8
+ BUTTON = "button",
9
+ OBJECT = "object",
10
+ ARRAY = "array",
11
+ FILES = "files"
12
+ }
13
+ export interface StoryPropertyBase<T> {
14
+ type: PropertyTypes;
15
+ label?: string;
16
+ value?: T;
17
+ hideLabel?: boolean;
18
+ hidden?: boolean;
19
+ groupId?: string;
20
+ order?: number;
21
+ }
22
+ export interface StoryPropertyText extends StoryPropertyBase<string> {
23
+ type: PropertyTypes.TEXT;
24
+ placeholder?: string;
25
+ maxRows?: number;
26
+ }
27
+ export interface StoryPropertyBoolean extends StoryPropertyBase<boolean> {
28
+ type: PropertyTypes.BOOLEAN;
29
+ }
30
+ export interface StoryPropertyColor extends StoryPropertyBase<string> {
31
+ type: PropertyTypes.COLOR;
32
+ }
33
+ export interface StoryPropertyDate extends StoryPropertyBase<Date> {
34
+ type: PropertyTypes.DATE;
35
+ datePicker?: boolean;
36
+ timePicker?: boolean;
37
+ }
38
+ export interface StoryPropertyFiles extends StoryPropertyBase<string[]> {
39
+ type: PropertyTypes.FILES;
40
+ accept?: string;
41
+ }
42
+ export interface StoryPropertyArray extends StoryPropertyBase<string[]> {
43
+ type: PropertyTypes.ARRAY;
44
+ separator?: string;
45
+ }
46
+ export interface StoryPropertyObject extends StoryPropertyBase<object> {
47
+ type: PropertyTypes.OBJECT;
48
+ }
49
+ export interface StoryPropertyButton extends StoryPropertyBase<void> {
50
+ type: PropertyTypes.BUTTON;
51
+ onClick?: (prop: StoryPropertyButton) => void;
52
+ }
53
+ export declare type OptionsValueType<T = unknown> = T | string | number | string[] | number[] | {
54
+ label: string;
55
+ value: any;
56
+ };
57
+ export declare type OptionsListType<T = unknown> = {
58
+ [key: string]: T;
59
+ } | OptionsValueType<T>[];
60
+ export interface StoryPropertyOptions<T = unknown> extends StoryPropertyBase<OptionsValueType<T>> {
61
+ type: PropertyTypes.OPTIONS;
62
+ options: OptionsListType<T>;
63
+ display?: 'select' | 'multi-select' | 'radio' | 'inline-radio' | 'check' | 'inline-check';
64
+ }
65
+ export interface StoryPropertyNumber extends StoryPropertyBase<number> {
66
+ type: PropertyTypes.NUMBER;
67
+ range?: boolean;
68
+ min?: number;
69
+ max?: number;
70
+ step?: number;
71
+ }
72
+ export declare type StoryProperty = StoryPropertyText | StoryPropertyBoolean | StoryPropertyColor | StoryPropertyDate | StoryPropertyObject | StoryPropertyButton | StoryPropertyOptions | StoryPropertyNumber | StoryPropertyArray | StoryPropertyFiles;
73
+ export interface StoryProperties {
74
+ [name: string]: StoryProperty;
75
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PropertyTypes = void 0;
7
+
8
+ /**
9
+ * Property field types
10
+ * examples are provided for the different types:
11
+ *
12
+ */
13
+ var PropertyTypes;
14
+ exports.PropertyTypes = PropertyTypes;
15
+
16
+ (function (PropertyTypes) {
17
+ PropertyTypes["TEXT"] = "text";
18
+ PropertyTypes["NUMBER"] = "number";
19
+ PropertyTypes["BOOLEAN"] = "boolean";
20
+ PropertyTypes["OPTIONS"] = "options";
21
+ PropertyTypes["DATE"] = "date";
22
+ PropertyTypes["COLOR"] = "color";
23
+ PropertyTypes["BUTTON"] = "button";
24
+ PropertyTypes["OBJECT"] = "object";
25
+ PropertyTypes["ARRAY"] = "array";
26
+ PropertyTypes["FILES"] = "files";
27
+ })(PropertyTypes || (exports.PropertyTypes = PropertyTypes = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _ = require(".");
4
+
5
+ describe('properties', function () {
6
+ it('type PropertyTypes.TEXT', function () {
7
+ expect(function () {
8
+ var prop = {
9
+ type: _.PropertyTypes.TEXT
10
+ };
11
+ return prop.type === 'text';
12
+ }).toBeTruthy();
13
+ });
14
+ });
package/dist/story.d.ts CHANGED
@@ -49,15 +49,15 @@ export declare type AnyFramework = {
49
49
  component: unknown;
50
50
  storyResult: unknown;
51
51
  };
52
- export declare type StoryContextForEnhancers<TFramework extends AnyFramework, TArgs = Args> = StoryIdentifier & {
52
+ export declare type StoryContextForEnhancers<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryIdentifier & {
53
53
  component?: TFramework['component'];
54
54
  subcomponents?: Record<string, TFramework['component']>;
55
55
  parameters: Parameters;
56
56
  initialArgs: TArgs;
57
57
  argTypes: StrictArgTypes<TArgs>;
58
58
  };
59
- export declare type ArgsEnhancer<TFramework extends AnyFramework, TArgs = Args> = (context: StoryContextForEnhancers<TFramework, TArgs>) => TArgs;
60
- export declare type ArgTypesEnhancer<TFramework extends AnyFramework, TArgs = Args> = ((context: StoryContextForEnhancers<TFramework, TArgs>) => StrictArgTypes<TArgs>) & {
59
+ export declare type ArgsEnhancer<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForEnhancers<TFramework, TArgs>) => TArgs;
60
+ export declare type ArgTypesEnhancer<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ((context: StoryContextForEnhancers<TFramework, TArgs>) => StrictArgTypes<TArgs>) & {
61
61
  secondPass?: boolean;
62
62
  };
63
63
  export declare type StoryContextUpdate<TArgs = Args> = {
@@ -66,31 +66,34 @@ export declare type StoryContextUpdate<TArgs = Args> = {
66
66
  [key: string]: any;
67
67
  };
68
68
  export declare type ViewMode = 'story' | 'docs';
69
- export declare type StoryContextForLoaders<TFramework extends AnyFramework, TArgs = Args> = StoryContextForEnhancers<TFramework, TArgs> & Required<StoryContextUpdate<TArgs>> & {
69
+ export declare type StoryContextForLoaders<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContextForEnhancers<TFramework, TArgs> & Required<StoryContextUpdate<TArgs>> & {
70
70
  hooks: unknown;
71
71
  viewMode: ViewMode;
72
72
  originalStoryFn: StoryFn<TFramework>;
73
73
  };
74
- export declare type LoaderFunction<TFramework extends AnyFramework, TArgs = Args> = (c: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
75
- export declare type StoryContext<TFramework extends AnyFramework, TArgs = Args> = StoryContextForLoaders<TFramework, TArgs> & {
74
+ export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
75
+ export declare type StoryContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContextForLoaders<TFramework, TArgs> & {
76
76
  loaded: Record<string, any>;
77
- };
78
- export declare type PartialStoryFn<TFramework extends AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult'];
79
- export declare type LegacyStoryFn<TFramework extends AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
80
- export declare type ArgsStoryFn<TFramework extends AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
81
- export declare type StoryFn<TFramework extends AnyFramework, TArgs = Args> = LegacyStoryFn<TFramework, TArgs> | ArgsStoryFn<TFramework, TArgs>;
82
- export declare type DecoratorFunction<TFramework extends AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
83
- export declare type DecoratorApplicator<TFramework extends AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
84
- export declare type BaseAnnotations<TFramework extends AnyFramework, TArgs = Args> = {
77
+ abortSignal: AbortSignal;
78
+ canvasElement: HTMLElement;
79
+ };
80
+ export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => Promise<void> | void;
81
+ export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult'];
82
+ export declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
83
+ export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
84
+ export declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyStoryFn<TFramework, TArgs> | ArgsStoryFn<TFramework, TArgs>;
85
+ export declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
86
+ export declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
87
+ export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = {
85
88
  decorators?: DecoratorFunction<TFramework, TArgs>[];
86
89
  parameters?: Parameters;
87
90
  args?: Partial<TArgs>;
88
91
  argTypes?: Partial<ArgTypes<TArgs>>;
89
92
  loaders?: LoaderFunction<TFramework, TArgs>[];
90
93
  render?: ArgsStoryFn<TFramework, TArgs>;
91
- play?: () => Promise<void>;
94
+ play?: PlayFunction<TFramework, TArgs>;
92
95
  };
93
- export declare type ProjectAnnotations<TFramework extends AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
96
+ export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
94
97
  argsEnhancers?: ArgsEnhancer<TFramework, TArgs>[];
95
98
  argTypesEnhancers?: ArgTypesEnhancer<TFramework, TArgs>[];
96
99
  globals?: Globals;
@@ -98,7 +101,7 @@ export declare type ProjectAnnotations<TFramework extends AnyFramework, TArgs =
98
101
  applyDecorators?: DecoratorApplicator<TFramework, TArgs>;
99
102
  };
100
103
  declare type StoryDescriptor = string[] | RegExp;
101
- export declare type ComponentAnnotations<TFramework extends AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
104
+ export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
102
105
  title?: ComponentTitle;
103
106
  id?: ComponentId;
104
107
  includeStories?: StoryDescriptor;
@@ -106,12 +109,12 @@ export declare type ComponentAnnotations<TFramework extends AnyFramework, TArgs
106
109
  component?: TFramework['component'];
107
110
  subcomponents?: Record<string, TFramework['component']>;
108
111
  };
109
- export declare type StoryAnnotations<TFramework extends AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
112
+ export declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
110
113
  name?: StoryName;
111
114
  storyName?: StoryName;
112
115
  story?: Omit<StoryAnnotations<TFramework, TArgs>, 'story'>;
113
116
  };
114
- declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
115
- export declare type LegacyStoryAnnotationsOrFn<TFramework extends AnyFramework, TArgs = Args> = LegacyAnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
116
- declare type AnnotatedStoryFn<TFramework extends AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
117
- export declare type StoryAnnotationsOrFn<TFramework extends AnyFramework, TArgs = Args> = AnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
117
+ export declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
118
+ export declare type LegacyStoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyAnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
119
+ export declare type AnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
120
+ export declare type StoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = AnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/csf",
3
- "version": "0.0.2--canary.b1d5348.0",
3
+ "version": "0.0.2--canary.87bc651.0",
4
4
  "description": "Component Story Format (CSF) utilities",
5
5
  "keywords": [
6
6
  "storybook",