@storybook/csf 0.0.2--canary.062665d.0 → 0.0.2--canary.835a408.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
@@ -71,15 +71,13 @@ export declare type StoryContextForLoaders<TFramework extends AnyFramework = Any
71
71
  viewMode: ViewMode;
72
72
  originalStoryFn: StoryFn<TFramework>;
73
73
  };
74
- export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (c: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
74
+ export declare type LoaderFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForLoaders<TFramework, TArgs>) => Promise<Record<string, any>>;
75
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 StoryContextForPlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContext<TFramework, TArgs> & {
79
77
  abortSignal: AbortSignal;
80
- canvas?: HTMLElement;
78
+ canvasElement: HTMLElement;
81
79
  };
82
- export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContextForPlayFunction<TFramework, TArgs>) => Promise<void> | void;
80
+ export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => Promise<void> | void;
83
81
  export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult'];
84
82
  export declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
85
83
  export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
@@ -87,20 +85,19 @@ export declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArg
87
85
  export declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult'];
88
86
  export declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>;
89
87
  export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = {
90
- decorators?: DecoratorFunction<TFramework, TArgs>[];
88
+ decorators?: DecoratorFunction<TFramework, Args>[];
91
89
  parameters?: Parameters;
92
90
  args?: Partial<TArgs>;
93
91
  argTypes?: Partial<ArgTypes<TArgs>>;
94
- loaders?: LoaderFunction<TFramework, TArgs>[];
95
- render?: ArgsStoryFn<TFramework, TArgs>;
96
- play?: PlayFunction<TFramework, TArgs>;
92
+ loaders?: LoaderFunction<TFramework, Args>[];
93
+ render?: ArgsStoryFn<TFramework, Args>;
97
94
  };
98
95
  export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
99
- argsEnhancers?: ArgsEnhancer<TFramework, TArgs>[];
100
- argTypesEnhancers?: ArgTypesEnhancer<TFramework, TArgs>[];
96
+ argsEnhancers?: ArgsEnhancer<TFramework, Args>[];
97
+ argTypesEnhancers?: ArgTypesEnhancer<TFramework, Args>[];
101
98
  globals?: Globals;
102
99
  globalTypes?: GlobalTypes;
103
- applyDecorators?: DecoratorApplicator<TFramework, TArgs>;
100
+ applyDecorators?: DecoratorApplicator<TFramework, Args>;
104
101
  };
105
102
  declare type StoryDescriptor = string[] | RegExp;
106
103
  export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
@@ -114,9 +111,10 @@ export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFr
114
111
  export declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & {
115
112
  name?: StoryName;
116
113
  storyName?: StoryName;
114
+ play?: PlayFunction<TFramework, TArgs>;
117
115
  story?: Omit<StoryAnnotations<TFramework, TArgs>, 'story'>;
118
116
  };
119
- declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
117
+ export declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
120
118
  export declare type LegacyStoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyAnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>;
121
- declare type AnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
119
+ export declare type AnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ArgsStoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>;
122
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.062665d.0",
3
+ "version": "0.0.2--canary.835a408.0",
4
4
  "description": "Component Story Format (CSF) utilities",
5
5
  "keywords": [
6
6
  "storybook",