@storybook/preact 10.3.0-alpha.6 → 10.3.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +209 -7
- package/dist/preset.js +6 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,201 @@
|
|
|
1
|
-
import { WebRenderer, Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';
|
|
1
|
+
import { WebRenderer, Args, ComponentAnnotations, AnnotatedStoryFn, ArgsStoryFn, ArgsFromMeta, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';
|
|
2
2
|
export { ArgTypes, Args, Parameters, StrictArgs } from 'storybook/internal/types';
|
|
3
|
-
import { AnyComponent } from 'preact';
|
|
3
|
+
import { AnyComponent, ComponentType, ComponentProps } from 'preact';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface SymbolConstructor {
|
|
7
|
+
readonly observable: symbol;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
Returns a boolean for whether the two given types are equal.
|
|
13
|
+
|
|
14
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
15
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
16
|
+
*/
|
|
17
|
+
type IsEqual<T, U> =
|
|
18
|
+
(<G>() => G extends T ? 1 : 2) extends
|
|
19
|
+
(<G>() => G extends U ? 1 : 2)
|
|
20
|
+
? true
|
|
21
|
+
: false;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
Filter out keys from an object.
|
|
25
|
+
|
|
26
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
27
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
28
|
+
Returns `Key` otherwise.
|
|
29
|
+
|
|
30
|
+
@example
|
|
31
|
+
```
|
|
32
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
33
|
+
//=> never
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
@example
|
|
37
|
+
```
|
|
38
|
+
type Filtered = Filter<'bar', string>;
|
|
39
|
+
//=> never
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@example
|
|
43
|
+
```
|
|
44
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
45
|
+
//=> 'bar'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
@see {Except}
|
|
49
|
+
*/
|
|
50
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
Create a type from an object type without certain keys.
|
|
54
|
+
|
|
55
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
56
|
+
|
|
57
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
58
|
+
|
|
59
|
+
@example
|
|
60
|
+
```
|
|
61
|
+
import type {Except} from 'type-fest';
|
|
62
|
+
|
|
63
|
+
type Foo = {
|
|
64
|
+
a: number;
|
|
65
|
+
b: string;
|
|
66
|
+
c: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
|
70
|
+
//=> {b: string};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
@category Object
|
|
74
|
+
*/
|
|
75
|
+
type Except<ObjectType, KeysType extends keyof ObjectType> = {
|
|
76
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
@see Simplify
|
|
81
|
+
*/
|
|
82
|
+
interface SimplifyOptions {
|
|
83
|
+
/**
|
|
84
|
+
Do the simplification recursively.
|
|
85
|
+
|
|
86
|
+
@default false
|
|
87
|
+
*/
|
|
88
|
+
deep?: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Flatten a type without worrying about the result.
|
|
92
|
+
type Flatten<
|
|
93
|
+
AnyType,
|
|
94
|
+
Options extends SimplifyOptions = {},
|
|
95
|
+
> = Options['deep'] extends true
|
|
96
|
+
? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>}
|
|
97
|
+
: {[KeyType in keyof AnyType]: AnyType[KeyType]};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
101
|
+
|
|
102
|
+
@example
|
|
103
|
+
```
|
|
104
|
+
import type {Simplify} from 'type-fest';
|
|
105
|
+
|
|
106
|
+
type PositionProps = {
|
|
107
|
+
top: number;
|
|
108
|
+
left: number;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type SizeProps = {
|
|
112
|
+
width: number;
|
|
113
|
+
height: number;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
117
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
121
|
+
|
|
122
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
123
|
+
|
|
124
|
+
@example
|
|
125
|
+
```
|
|
126
|
+
import type {Simplify} from 'type-fest';
|
|
127
|
+
|
|
128
|
+
interface SomeInterface {
|
|
129
|
+
foo: number;
|
|
130
|
+
bar?: string;
|
|
131
|
+
baz: number | undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
type SomeType = {
|
|
135
|
+
foo: number;
|
|
136
|
+
bar?: string;
|
|
137
|
+
baz: number | undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
141
|
+
const someType: SomeType = literal;
|
|
142
|
+
const someInterface: SomeInterface = literal;
|
|
143
|
+
|
|
144
|
+
function fn(object: Record<string, unknown>): void {}
|
|
145
|
+
|
|
146
|
+
fn(literal); // Good: literal object type is sealed
|
|
147
|
+
fn(someType); // Good: type is sealed
|
|
148
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
149
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
153
|
+
|
|
154
|
+
@category Object
|
|
155
|
+
*/
|
|
156
|
+
type Simplify<
|
|
157
|
+
AnyType,
|
|
158
|
+
Options extends SimplifyOptions = {},
|
|
159
|
+
> = Flatten<AnyType> extends AnyType
|
|
160
|
+
? Flatten<AnyType, Options>
|
|
161
|
+
: AnyType;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
|
165
|
+
|
|
166
|
+
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
|
|
167
|
+
|
|
168
|
+
@example
|
|
169
|
+
```
|
|
170
|
+
import type {SetOptional} from 'type-fest';
|
|
171
|
+
|
|
172
|
+
type Foo = {
|
|
173
|
+
a: number;
|
|
174
|
+
b?: string;
|
|
175
|
+
c: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
179
|
+
// type SomeOptional = {
|
|
180
|
+
// a: number;
|
|
181
|
+
// b?: string; // Was already optional and still is.
|
|
182
|
+
// c?: boolean; // Is now optional.
|
|
183
|
+
// }
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
@category Object
|
|
187
|
+
*/
|
|
188
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> =
|
|
189
|
+
Simplify<
|
|
190
|
+
// Pick just the keys that are readonly from the base type.
|
|
191
|
+
Except<BaseType, Keys> &
|
|
192
|
+
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
193
|
+
Partial<Pick<BaseType, Keys>>
|
|
194
|
+
>;
|
|
4
195
|
|
|
5
196
|
type StoryFnPreactReturnType = string | Node | preact.JSX.Element;
|
|
6
197
|
interface PreactRenderer extends WebRenderer {
|
|
7
|
-
component: AnyComponent<
|
|
198
|
+
component: AnyComponent<this['T'], any>;
|
|
8
199
|
storyResult: StoryFnPreactReturnType;
|
|
9
200
|
}
|
|
10
201
|
|
|
@@ -13,19 +204,30 @@ interface PreactRenderer extends WebRenderer {
|
|
|
13
204
|
*
|
|
14
205
|
* @see [Default export](https://storybook.js.org/docs/api/csf#default-export)
|
|
15
206
|
*/
|
|
16
|
-
type Meta<
|
|
207
|
+
type Meta<TCmpOrArgs = Args> = [TCmpOrArgs] extends [ComponentType<any>] ? ComponentAnnotations<PreactRenderer, ComponentProps<TCmpOrArgs>> : ComponentAnnotations<PreactRenderer, TCmpOrArgs>;
|
|
17
208
|
/**
|
|
18
209
|
* Story function that represents a CSFv2 component example.
|
|
19
210
|
*
|
|
20
211
|
* @see [Named Story exports](https://storybook.js.org/docs/api/csf#named-story-exports)
|
|
21
212
|
*/
|
|
22
|
-
type StoryFn<
|
|
213
|
+
type StoryFn<TCmpOrArgs = Args> = [TCmpOrArgs] extends [ComponentType<any>] ? AnnotatedStoryFn<PreactRenderer, ComponentProps<TCmpOrArgs>> : AnnotatedStoryFn<PreactRenderer, TCmpOrArgs>;
|
|
23
214
|
/**
|
|
24
215
|
* Story object that represents a CSFv3 component example.
|
|
25
216
|
*
|
|
26
217
|
* @see [Named Story exports](https://storybook.js.org/docs/api/csf#named-story-exports)
|
|
27
218
|
*/
|
|
28
|
-
type StoryObj<
|
|
219
|
+
type StoryObj<TMetaOrCmpOrArgs = Args> = [TMetaOrCmpOrArgs] extends [
|
|
220
|
+
{
|
|
221
|
+
render?: ArgsStoryFn<PreactRenderer, any>;
|
|
222
|
+
component?: infer Component;
|
|
223
|
+
args?: infer DefaultArgs;
|
|
224
|
+
}
|
|
225
|
+
] ? Simplify<(Component extends ComponentType<any> ? ComponentProps<Component> : unknown) & ArgsFromMeta<PreactRenderer, TMetaOrCmpOrArgs>> extends infer TArgs ? StoryAnnotations<PreactRenderer, AddMocks<TArgs, DefaultArgs>, SetOptional<TArgs, keyof TArgs & keyof DefaultArgs>> : never : TMetaOrCmpOrArgs extends ComponentType<any> ? StoryAnnotations<PreactRenderer, ComponentProps<TMetaOrCmpOrArgs>> : StoryAnnotations<PreactRenderer, TMetaOrCmpOrArgs>;
|
|
226
|
+
type AddMocks<TArgs, DefaultArgs> = Simplify<{
|
|
227
|
+
[T in keyof TArgs]: T extends keyof DefaultArgs ? DefaultArgs[T] extends (...args: any) => any & {
|
|
228
|
+
mock: {};
|
|
229
|
+
} ? DefaultArgs[T] : TArgs[T] : TArgs[T];
|
|
230
|
+
}>;
|
|
29
231
|
type Decorator<TArgs = StrictArgs> = DecoratorFunction<PreactRenderer, TArgs>;
|
|
30
232
|
type Loader<TArgs = StrictArgs> = LoaderFunction<PreactRenderer, TArgs>;
|
|
31
233
|
type StoryContext<TArgs = StrictArgs> = StoryContext$1<PreactRenderer, TArgs>;
|
|
@@ -52,4 +254,4 @@ type Preview = ProjectAnnotations<PreactRenderer>;
|
|
|
52
254
|
*/
|
|
53
255
|
declare function setProjectAnnotations(projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]): NormalizedProjectAnnotations<PreactRenderer>;
|
|
54
256
|
|
|
55
|
-
export { type Decorator, type Loader, type Meta, type PreactRenderer, type Preview, type StoryContext, type StoryFn, type StoryObj, setProjectAnnotations };
|
|
257
|
+
export { type AddMocks, type Decorator, type Loader, type Meta, type PreactRenderer, type Preview, type StoryContext, type StoryFn, type StoryObj, setProjectAnnotations };
|
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_yfv24zeatri from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_yfv24zeatri from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_yfv24zeatri from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_yfv24zeatri.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_yfv24zeatri.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_yfv24zeatri.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/preact",
|
|
3
|
-
"version": "10.3.0-alpha.
|
|
3
|
+
"version": "10.3.0-alpha.8",
|
|
4
4
|
"description": "Storybook Preact renderer: Develop, document, and test UI components in isolation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"preact": "^8.0.0||^10.0.0",
|
|
56
|
-
"storybook": "^10.3.0-alpha.
|
|
56
|
+
"storybook": "^10.3.0-alpha.8"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|