@storybook/web-components 10.2.0-alpha.15 → 10.2.0-alpha.16
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/_browser-chunks/{chunk-XQFQKYGQ.js → chunk-6OBW3LSX.js} +14 -1
- package/dist/_browser-chunks/chunk-6TV4DYNC.js +48 -0
- package/dist/entry-preview-argtypes.js +2 -1
- package/dist/entry-preview-docs.js +4 -34
- package/dist/index.d.ts +515 -2
- package/dist/index.js +4 -1
- package/dist/preset.js +6 -6
- package/package.json +2 -2
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
entry_preview_exports
|
|
3
3
|
} from "./chunk-UN5GYDGC.js";
|
|
4
|
+
import {
|
|
5
|
+
entry_preview_docs_exports
|
|
6
|
+
} from "./chunk-6TV4DYNC.js";
|
|
4
7
|
|
|
5
8
|
// src/index.ts
|
|
6
9
|
import { global as global3 } from "@storybook/global";
|
|
@@ -48,6 +51,15 @@ function setProjectAnnotations(projectAnnotations) {
|
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
// src/preview.ts
|
|
55
|
+
import { definePreview as definePreviewBase } from "storybook/internal/csf";
|
|
56
|
+
function __definePreview(input) {
|
|
57
|
+
return definePreviewBase({
|
|
58
|
+
...input,
|
|
59
|
+
addons: [entry_preview_exports, entry_preview_docs_exports, ...input.addons ?? []]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
// src/index.ts
|
|
52
64
|
var { window, EventSource } = global3;
|
|
53
65
|
typeof module < "u" && module?.hot?.decline && (module.hot.decline(), new EventSource("__webpack_hmr").addEventListener("message", function(event) {
|
|
@@ -64,5 +76,6 @@ export {
|
|
|
64
76
|
setCustomElements,
|
|
65
77
|
setCustomElementsManifest,
|
|
66
78
|
getCustomElements,
|
|
67
|
-
setProjectAnnotations
|
|
79
|
+
setProjectAnnotations,
|
|
80
|
+
__definePreview
|
|
68
81
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-4BE7D4DS.js";
|
|
4
|
+
|
|
5
|
+
// src/entry-preview-docs.ts
|
|
6
|
+
var entry_preview_docs_exports = {};
|
|
7
|
+
__export(entry_preview_docs_exports, {
|
|
8
|
+
decorators: () => decorators,
|
|
9
|
+
parameters: () => parameters
|
|
10
|
+
});
|
|
11
|
+
import { SourceType as SourceType2 } from "storybook/internal/docs-tools";
|
|
12
|
+
|
|
13
|
+
// src/docs/sourceDecorator.ts
|
|
14
|
+
import { SourceType } from "storybook/internal/docs-tools";
|
|
15
|
+
import { render } from "lit";
|
|
16
|
+
import { emitTransformCode, useEffect } from "storybook/preview-api";
|
|
17
|
+
var LIT_EXPRESSION_COMMENTS = /<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;
|
|
18
|
+
function skipSourceRender(context) {
|
|
19
|
+
let sourceParams = context?.parameters.docs?.source, isArgsStory = context?.parameters.__isArgsStory;
|
|
20
|
+
return sourceParams?.type === SourceType.DYNAMIC ? !1 : !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
|
|
21
|
+
}
|
|
22
|
+
function sourceDecorator(storyFn, context) {
|
|
23
|
+
let story = storyFn(), renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story, source;
|
|
24
|
+
if (useEffect(() => {
|
|
25
|
+
source && emitTransformCode(source, context);
|
|
26
|
+
}), !skipSourceRender(context)) {
|
|
27
|
+
let container = window.document.createElement("div");
|
|
28
|
+
renderedForSource instanceof DocumentFragment ? render(renderedForSource.cloneNode(!0), container) : render(renderedForSource, container), source = container.innerHTML.replace(LIT_EXPRESSION_COMMENTS, "");
|
|
29
|
+
}
|
|
30
|
+
return story;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/entry-preview-docs.ts
|
|
34
|
+
var decorators = [sourceDecorator], parameters = {
|
|
35
|
+
docs: {
|
|
36
|
+
source: {
|
|
37
|
+
type: SourceType2.DYNAMIC,
|
|
38
|
+
language: "html"
|
|
39
|
+
},
|
|
40
|
+
story: { inline: !0 }
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
decorators,
|
|
46
|
+
parameters,
|
|
47
|
+
entry_preview_docs_exports
|
|
48
|
+
};
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
getCustomElements,
|
|
3
3
|
isValidComponent,
|
|
4
4
|
isValidMetaData
|
|
5
|
-
} from "./_browser-chunks/chunk-
|
|
5
|
+
} from "./_browser-chunks/chunk-6OBW3LSX.js";
|
|
6
6
|
import "./_browser-chunks/chunk-UN5GYDGC.js";
|
|
7
|
+
import "./_browser-chunks/chunk-6TV4DYNC.js";
|
|
7
8
|
import "./_browser-chunks/chunk-4BE7D4DS.js";
|
|
8
9
|
|
|
9
10
|
// src/entry-preview-argtypes.ts
|
|
@@ -1,38 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decorators,
|
|
3
|
+
parameters
|
|
4
|
+
} from "./_browser-chunks/chunk-6TV4DYNC.js";
|
|
1
5
|
import "./_browser-chunks/chunk-4BE7D4DS.js";
|
|
2
|
-
|
|
3
|
-
// src/entry-preview-docs.ts
|
|
4
|
-
import { SourceType as SourceType2 } from "storybook/internal/docs-tools";
|
|
5
|
-
|
|
6
|
-
// src/docs/sourceDecorator.ts
|
|
7
|
-
import { SourceType } from "storybook/internal/docs-tools";
|
|
8
|
-
import { render } from "lit";
|
|
9
|
-
import { emitTransformCode, useEffect } from "storybook/preview-api";
|
|
10
|
-
var LIT_EXPRESSION_COMMENTS = /<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;
|
|
11
|
-
function skipSourceRender(context) {
|
|
12
|
-
let sourceParams = context?.parameters.docs?.source, isArgsStory = context?.parameters.__isArgsStory;
|
|
13
|
-
return sourceParams?.type === SourceType.DYNAMIC ? !1 : !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
|
|
14
|
-
}
|
|
15
|
-
function sourceDecorator(storyFn, context) {
|
|
16
|
-
let story = storyFn(), renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story, source;
|
|
17
|
-
if (useEffect(() => {
|
|
18
|
-
source && emitTransformCode(source, context);
|
|
19
|
-
}), !skipSourceRender(context)) {
|
|
20
|
-
let container = window.document.createElement("div");
|
|
21
|
-
renderedForSource instanceof DocumentFragment ? render(renderedForSource.cloneNode(!0), container) : render(renderedForSource, container), source = container.innerHTML.replace(LIT_EXPRESSION_COMMENTS, "");
|
|
22
|
-
}
|
|
23
|
-
return story;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/entry-preview-docs.ts
|
|
27
|
-
var decorators = [sourceDecorator], parameters = {
|
|
28
|
-
docs: {
|
|
29
|
-
source: {
|
|
30
|
-
type: SourceType2.DYNAMIC,
|
|
31
|
-
language: "html"
|
|
32
|
-
},
|
|
33
|
-
story: { inline: !0 }
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
6
|
export {
|
|
37
7
|
decorators,
|
|
38
8
|
parameters
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
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, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Renderer, ArgsStoryFn } from 'storybook/internal/types';
|
|
2
2
|
export { ArgTypes, Args, Parameters, StrictArgs } from 'storybook/internal/types';
|
|
3
3
|
import { TemplateResult, SVGTemplateResult } from 'lit';
|
|
4
|
+
import { PreviewAddon, InferTypes, AddonTypes, Preview as Preview$1, Meta as Meta$1, Story } from 'storybook/internal/csf';
|
|
4
5
|
|
|
5
6
|
type StoryFnHtmlReturnType = string | Node | DocumentFragment | TemplateResult | SVGTemplateResult;
|
|
6
7
|
interface WebComponentsRenderer extends WebRenderer {
|
|
7
8
|
component: string;
|
|
8
9
|
storyResult: StoryFnHtmlReturnType;
|
|
9
10
|
}
|
|
11
|
+
interface WebComponentsTypes extends WebComponentsRenderer {
|
|
12
|
+
}
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Metadata to configure the stories for a component.
|
|
@@ -59,4 +62,514 @@ declare function getCustomElements(): any;
|
|
|
59
62
|
*/
|
|
60
63
|
declare function setProjectAnnotations(projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]): NormalizedProjectAnnotations<WebComponentsRenderer>;
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
declare global {
|
|
66
|
+
interface SymbolConstructor {
|
|
67
|
+
readonly observable: symbol;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
Returns a boolean for whether the two given types are equal.
|
|
73
|
+
|
|
74
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
75
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
76
|
+
*/
|
|
77
|
+
type IsEqual<T, U> =
|
|
78
|
+
(<G>() => G extends T ? 1 : 2) extends
|
|
79
|
+
(<G>() => G extends U ? 1 : 2)
|
|
80
|
+
? true
|
|
81
|
+
: false;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
Filter out keys from an object.
|
|
85
|
+
|
|
86
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
87
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
88
|
+
Returns `Key` otherwise.
|
|
89
|
+
|
|
90
|
+
@example
|
|
91
|
+
```
|
|
92
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
93
|
+
//=> never
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
@example
|
|
97
|
+
```
|
|
98
|
+
type Filtered = Filter<'bar', string>;
|
|
99
|
+
//=> never
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
@example
|
|
103
|
+
```
|
|
104
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
105
|
+
//=> 'bar'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
@see {Except}
|
|
109
|
+
*/
|
|
110
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
Create a type from an object type without certain keys.
|
|
114
|
+
|
|
115
|
+
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.
|
|
116
|
+
|
|
117
|
+
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)).
|
|
118
|
+
|
|
119
|
+
@example
|
|
120
|
+
```
|
|
121
|
+
import type {Except} from 'type-fest';
|
|
122
|
+
|
|
123
|
+
type Foo = {
|
|
124
|
+
a: number;
|
|
125
|
+
b: string;
|
|
126
|
+
c: boolean;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
|
130
|
+
//=> {b: string};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
@category Object
|
|
134
|
+
*/
|
|
135
|
+
type Except<ObjectType, KeysType extends keyof ObjectType> = {
|
|
136
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
@see Simplify
|
|
141
|
+
*/
|
|
142
|
+
interface SimplifyOptions {
|
|
143
|
+
/**
|
|
144
|
+
Do the simplification recursively.
|
|
145
|
+
|
|
146
|
+
@default false
|
|
147
|
+
*/
|
|
148
|
+
deep?: boolean;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Flatten a type without worrying about the result.
|
|
152
|
+
type Flatten<
|
|
153
|
+
AnyType,
|
|
154
|
+
Options extends SimplifyOptions = {},
|
|
155
|
+
> = Options['deep'] extends true
|
|
156
|
+
? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>}
|
|
157
|
+
: {[KeyType in keyof AnyType]: AnyType[KeyType]};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
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.
|
|
161
|
+
|
|
162
|
+
@example
|
|
163
|
+
```
|
|
164
|
+
import type {Simplify} from 'type-fest';
|
|
165
|
+
|
|
166
|
+
type PositionProps = {
|
|
167
|
+
top: number;
|
|
168
|
+
left: number;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
type SizeProps = {
|
|
172
|
+
width: number;
|
|
173
|
+
height: number;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
177
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
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.
|
|
181
|
+
|
|
182
|
+
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`.
|
|
183
|
+
|
|
184
|
+
@example
|
|
185
|
+
```
|
|
186
|
+
import type {Simplify} from 'type-fest';
|
|
187
|
+
|
|
188
|
+
interface SomeInterface {
|
|
189
|
+
foo: number;
|
|
190
|
+
bar?: string;
|
|
191
|
+
baz: number | undefined;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
type SomeType = {
|
|
195
|
+
foo: number;
|
|
196
|
+
bar?: string;
|
|
197
|
+
baz: number | undefined;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
201
|
+
const someType: SomeType = literal;
|
|
202
|
+
const someInterface: SomeInterface = literal;
|
|
203
|
+
|
|
204
|
+
function fn(object: Record<string, unknown>): void {}
|
|
205
|
+
|
|
206
|
+
fn(literal); // Good: literal object type is sealed
|
|
207
|
+
fn(someType); // Good: type is sealed
|
|
208
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
209
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
213
|
+
|
|
214
|
+
@category Object
|
|
215
|
+
*/
|
|
216
|
+
type Simplify<
|
|
217
|
+
AnyType,
|
|
218
|
+
Options extends SimplifyOptions = {},
|
|
219
|
+
> = Flatten<AnyType> extends AnyType
|
|
220
|
+
? Flatten<AnyType, Options>
|
|
221
|
+
: AnyType;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
Remove any index signatures from the given object type, so that only explicitly defined properties remain.
|
|
225
|
+
|
|
226
|
+
Use-cases:
|
|
227
|
+
- Remove overly permissive signatures from third-party types.
|
|
228
|
+
|
|
229
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
230
|
+
|
|
231
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
232
|
+
|
|
233
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
237
|
+
|
|
238
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
239
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
type Indexed = {} extends Record<string, unknown>
|
|
246
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
247
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
248
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
249
|
+
|
|
250
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
251
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
252
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
253
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
260
|
+
|
|
261
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
262
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
263
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `RemoveIndexSignature<Foo> == Foo`.
|
|
264
|
+
};
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
271
|
+
|
|
272
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
273
|
+
[KeyType in keyof ObjectType
|
|
274
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
275
|
+
as {} extends Record<KeyType, unknown>
|
|
276
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
277
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
278
|
+
]: ObjectType[KeyType];
|
|
279
|
+
};
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
286
|
+
|
|
287
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
288
|
+
[KeyType in keyof ObjectType
|
|
289
|
+
as {} extends Record<KeyType, unknown>
|
|
290
|
+
? never // => Remove this `KeyType`.
|
|
291
|
+
: KeyType // => Keep this `KeyType` as it is.
|
|
292
|
+
]: ObjectType[KeyType];
|
|
293
|
+
};
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
@example
|
|
297
|
+
```
|
|
298
|
+
import type {RemoveIndexSignature} from 'type-fest';
|
|
299
|
+
|
|
300
|
+
interface Example {
|
|
301
|
+
// These index signatures will be removed.
|
|
302
|
+
[x: string]: any
|
|
303
|
+
[x: number]: any
|
|
304
|
+
[x: symbol]: any
|
|
305
|
+
[x: `head-${string}`]: string
|
|
306
|
+
[x: `${string}-tail`]: string
|
|
307
|
+
[x: `head-${string}-tail`]: string
|
|
308
|
+
[x: `${bigint}`]: string
|
|
309
|
+
[x: `embedded-${number}`]: string
|
|
310
|
+
|
|
311
|
+
// These explicitly defined keys will remain.
|
|
312
|
+
foo: 'bar';
|
|
313
|
+
qux?: 'baz';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
type ExampleWithoutIndexSignatures = RemoveIndexSignature<Example>;
|
|
317
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
@category Object
|
|
321
|
+
*/
|
|
322
|
+
type RemoveIndexSignature<ObjectType> = {
|
|
323
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
324
|
+
? never
|
|
325
|
+
: KeyType]: ObjectType[KeyType];
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
|
330
|
+
|
|
331
|
+
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.
|
|
332
|
+
|
|
333
|
+
@example
|
|
334
|
+
```
|
|
335
|
+
import type {SetOptional} from 'type-fest';
|
|
336
|
+
|
|
337
|
+
type Foo = {
|
|
338
|
+
a: number;
|
|
339
|
+
b?: string;
|
|
340
|
+
c: boolean;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
344
|
+
// type SomeOptional = {
|
|
345
|
+
// a: number;
|
|
346
|
+
// b?: string; // Was already optional and still is.
|
|
347
|
+
// c?: boolean; // Is now optional.
|
|
348
|
+
// }
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
@category Object
|
|
352
|
+
*/
|
|
353
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> =
|
|
354
|
+
Simplify<
|
|
355
|
+
// Pick just the keys that are readonly from the base type.
|
|
356
|
+
Except<BaseType, Keys> &
|
|
357
|
+
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
358
|
+
Partial<Pick<BaseType, Keys>>
|
|
359
|
+
>;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
363
|
+
|
|
364
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
365
|
+
|
|
366
|
+
@example
|
|
367
|
+
```
|
|
368
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
369
|
+
|
|
370
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
371
|
+
|
|
372
|
+
type Intersection = UnionToIntersection<Union>;
|
|
373
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
A more applicable example which could make its way into your library code follows.
|
|
377
|
+
|
|
378
|
+
@example
|
|
379
|
+
```
|
|
380
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
381
|
+
|
|
382
|
+
class CommandOne {
|
|
383
|
+
commands: {
|
|
384
|
+
a1: () => undefined,
|
|
385
|
+
b1: () => undefined,
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
class CommandTwo {
|
|
390
|
+
commands: {
|
|
391
|
+
a2: (argA: string) => undefined,
|
|
392
|
+
b2: (argB: string) => undefined,
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
397
|
+
type Union = typeof union;
|
|
398
|
+
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
399
|
+
|
|
400
|
+
type Intersection = UnionToIntersection<Union>;
|
|
401
|
+
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
@category Type
|
|
405
|
+
*/
|
|
406
|
+
type UnionToIntersection<Union> = (
|
|
407
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
408
|
+
// `Union` into a [distributive conditional
|
|
409
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
410
|
+
Union extends unknown
|
|
411
|
+
// The union type is used as the only argument to a function since the union
|
|
412
|
+
// of function arguments is an intersection.
|
|
413
|
+
? (distributedUnion: Union) => void
|
|
414
|
+
// This won't happen.
|
|
415
|
+
: never
|
|
416
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
417
|
+
// arguments of unions of functions as an intersection of the union.
|
|
418
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
419
|
+
? Intersection
|
|
420
|
+
: never;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Creates a Web Components-specific preview configuration with CSF factories support.
|
|
424
|
+
*
|
|
425
|
+
* This function wraps the base `definePreview` and adds Web Components-specific annotations for
|
|
426
|
+
* rendering and documentation. It returns a `WebComponentsPreview` that provides type-safe `meta()`
|
|
427
|
+
* and `story()` factory methods.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
*
|
|
431
|
+
* ```ts
|
|
432
|
+
* // .storybook/preview.ts
|
|
433
|
+
* import { definePreview } from '@storybook/web-components';
|
|
434
|
+
*
|
|
435
|
+
* export const preview = definePreview({
|
|
436
|
+
* addons: [],
|
|
437
|
+
* parameters: { layout: 'centered' },
|
|
438
|
+
* });
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
|
|
442
|
+
addons: Addons;
|
|
443
|
+
} & ProjectAnnotations<WebComponentsTypes & InferTypes<Addons>>): WebComponentsPreview<WebComponentsTypes & InferTypes<Addons>>;
|
|
444
|
+
type InferArgs<TArgs, T, Decorators> = Simplify<TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<WebComponentsTypes & T, Decorators>>>>;
|
|
445
|
+
type InferWebComponentsTypes<T, TArgs, Decorators> = WebComponentsTypes & T & {
|
|
446
|
+
args: Simplify<InferArgs<TArgs, T, Decorators>>;
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Web Components-specific Preview interface that provides type-safe CSF factory methods.
|
|
450
|
+
*
|
|
451
|
+
* Use `preview.meta()` to create a meta configuration for a component, and then `meta.story()` to
|
|
452
|
+
* create individual stories. The type system will infer args from the HTMLElement type when using a
|
|
453
|
+
* tag name as the component.
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
*
|
|
457
|
+
* ```ts
|
|
458
|
+
* const meta = preview.meta({ component: 'my-button' });
|
|
459
|
+
* export const Primary = meta.story({ args: { label: 'Click me' } });
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
interface WebComponentsPreview<T extends AddonTypes> extends Preview$1<WebComponentsTypes & T> {
|
|
463
|
+
/**
|
|
464
|
+
* Narrows the type of the preview to include additional type information. This is useful when you
|
|
465
|
+
* need to add args that aren't inferred from the component.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
*
|
|
469
|
+
* ```ts
|
|
470
|
+
* const meta = preview.type<{ args: { theme: 'light' | 'dark' } }>().meta({
|
|
471
|
+
* component: 'my-button',
|
|
472
|
+
* });
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
type<S>(): WebComponentsPreview<T & S>;
|
|
476
|
+
meta<C extends keyof HTMLElementTagNameMap, Decorators extends DecoratorFunction<WebComponentsTypes & T, any>, TMetaArgs extends Partial<HTMLElementTagNameMap[C] & T['args']>>(meta: {
|
|
477
|
+
component?: C;
|
|
478
|
+
args?: TMetaArgs;
|
|
479
|
+
decorators?: Decorators | Decorators[];
|
|
480
|
+
} & Omit<ComponentAnnotations<WebComponentsTypes & T, Partial<HTMLElementTagNameMap[C]> & T['args']>, 'decorators' | 'component' | 'args'>): WebComponentsMeta<InferWebComponentsTypes<T, Partial<HTMLElementTagNameMap[C]>, Decorators>, Omit<ComponentAnnotations<InferWebComponentsTypes<T, Partial<HTMLElementTagNameMap[C]>, Decorators>>, 'args'> & {
|
|
481
|
+
args: {} extends TMetaArgs ? {} : TMetaArgs;
|
|
482
|
+
}>;
|
|
483
|
+
meta<TArgs, Decorators extends DecoratorFunction<WebComponentsTypes & T, any>, TMetaArgs extends Partial<TArgs>>(meta: {
|
|
484
|
+
render?: ArgsStoryFn<WebComponentsTypes & T, TArgs>;
|
|
485
|
+
args?: TMetaArgs;
|
|
486
|
+
decorators?: Decorators | Decorators[];
|
|
487
|
+
} & Omit<ComponentAnnotations<WebComponentsTypes & T, TArgs & T['args']>, 'decorators' | 'component' | 'args' | 'render'>): WebComponentsMeta<InferWebComponentsTypes<T, TArgs, Decorators>, Omit<ComponentAnnotations<InferWebComponentsTypes<T, TArgs, Decorators>>, 'args'> & {
|
|
488
|
+
args: {} extends TMetaArgs ? {} : TMetaArgs;
|
|
489
|
+
}>;
|
|
490
|
+
}
|
|
491
|
+
/** Extracts and unions all args types from an array of decorators. */
|
|
492
|
+
type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
|
|
493
|
+
/**
|
|
494
|
+
* Web Components-specific Meta interface returned by `preview.meta()`.
|
|
495
|
+
*
|
|
496
|
+
* Provides the `story()` method to create individual stories with proper type inference. Args
|
|
497
|
+
* provided in meta become optional in stories, while missing required args must be provided at the
|
|
498
|
+
* story level.
|
|
499
|
+
*/
|
|
500
|
+
interface WebComponentsMeta<T extends WebComponentsTypes, MetaInput extends ComponentAnnotations<T>> extends Meta$1<T, MetaInput> {
|
|
501
|
+
/**
|
|
502
|
+
* Creates a story with a custom render function that takes no args.
|
|
503
|
+
*
|
|
504
|
+
* This overload allows you to define a story using just a render function or an object with a
|
|
505
|
+
* render function that doesn't depend on args. Since the render function doesn't use args, no
|
|
506
|
+
* args need to be provided regardless of what's required by the component.
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
*
|
|
510
|
+
* ```ts
|
|
511
|
+
* // Using just a render function with lit-html
|
|
512
|
+
* export const CustomTemplate = meta.story(() => html`<div>Custom content</div>`);
|
|
513
|
+
*
|
|
514
|
+
* // Using an object with render
|
|
515
|
+
* export const WithRender = meta.story({
|
|
516
|
+
* render: () => html`<my-element></my-element>`,
|
|
517
|
+
* });
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
story<TInput extends (() => WebComponentsTypes['storyResult']) | (StoryAnnotations<T, T['args']> & {
|
|
521
|
+
render: () => WebComponentsTypes['storyResult'];
|
|
522
|
+
})>(story: TInput): WebComponentsStory<T, TInput extends () => WebComponentsTypes['storyResult'] ? {
|
|
523
|
+
render: TInput;
|
|
524
|
+
} : TInput>;
|
|
525
|
+
/**
|
|
526
|
+
* Creates a story with custom configuration including args, decorators, or other annotations.
|
|
527
|
+
*
|
|
528
|
+
* This is the primary overload for defining stories. Args that were already provided in meta
|
|
529
|
+
* become optional, while any remaining required args must be specified here.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
*
|
|
533
|
+
* ```ts
|
|
534
|
+
* // Provide required args not in meta
|
|
535
|
+
* export const Primary = meta.story({
|
|
536
|
+
* args: { label: 'Click me', disabled: false },
|
|
537
|
+
* });
|
|
538
|
+
*
|
|
539
|
+
* // Override meta args and add story-specific configuration
|
|
540
|
+
* export const Disabled = meta.story({
|
|
541
|
+
* args: { disabled: true },
|
|
542
|
+
* decorators: [withCustomWrapper],
|
|
543
|
+
* });
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
story<TInput extends Simplify<StoryAnnotations<T, T['args'], SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']>>>>(story: TInput): WebComponentsStory<T, TInput>;
|
|
547
|
+
/**
|
|
548
|
+
* Creates a story with no additional configuration.
|
|
549
|
+
*
|
|
550
|
+
* This overload is only available when all required args have been provided in meta. The
|
|
551
|
+
* conditional type `Partial<T['args']> extends SetOptional<...>` checks if the remaining required
|
|
552
|
+
* args (after accounting for args provided in meta) are all optional. If so, the function accepts
|
|
553
|
+
* zero arguments `[]`. Otherwise, it requires `[never]` which makes this overload unmatchable,
|
|
554
|
+
* forcing the user to provide args.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
*
|
|
558
|
+
* ```ts
|
|
559
|
+
* // When meta provides all required args, story() can be called with no arguments
|
|
560
|
+
* const meta = preview.meta({ component: 'my-button', args: { label: 'Hi' } });
|
|
561
|
+
* export const Default = meta.story(); // Valid - all args provided in meta
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
story(..._args: Partial<T['args']> extends SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']> ? [] : [never]): WebComponentsStory<T, {}>;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Web Components-specific Story interface returned by `meta.story()`.
|
|
568
|
+
*
|
|
569
|
+
* Represents a single story with its configuration and provides access to the composed story for
|
|
570
|
+
* testing via `story.run()`.
|
|
571
|
+
*/
|
|
572
|
+
interface WebComponentsStory<T extends WebComponentsTypes, TInput extends StoryAnnotations<T, T['args']>> extends Story<T, TInput> {
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export { type Decorator, type Loader, type Meta, type Preview, type StoryContext, type StoryFn, type StoryObj, type WebComponentsMeta, type WebComponentsPreview, type WebComponentsRenderer, type WebComponentsStory, __definePreview, getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
+
__definePreview,
|
|
2
3
|
getCustomElements,
|
|
3
4
|
isValidComponent,
|
|
4
5
|
isValidMetaData,
|
|
5
6
|
setCustomElements,
|
|
6
7
|
setCustomElementsManifest,
|
|
7
8
|
setProjectAnnotations
|
|
8
|
-
} from "./_browser-chunks/chunk-
|
|
9
|
+
} from "./_browser-chunks/chunk-6OBW3LSX.js";
|
|
9
10
|
import "./_browser-chunks/chunk-UN5GYDGC.js";
|
|
11
|
+
import "./_browser-chunks/chunk-6TV4DYNC.js";
|
|
10
12
|
import "./_browser-chunks/chunk-4BE7D4DS.js";
|
|
11
13
|
export {
|
|
14
|
+
__definePreview,
|
|
12
15
|
getCustomElements,
|
|
13
16
|
isValidComponent,
|
|
14
17
|
isValidMetaData,
|
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_765q32q63l from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_765q32q63l from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_765q32q63l from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_765q32q63l.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_765q32q63l.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_765q32q63l.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/web-components",
|
|
3
|
-
"version": "10.2.0-alpha.
|
|
3
|
+
"version": "10.2.0-alpha.16",
|
|
4
4
|
"description": "Storybook Web Components renderer: Develop, document, and test UI components in isolation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"lit": "^2.0.0 || ^3.0.0",
|
|
65
|
-
"storybook": "^10.2.0-alpha.
|
|
65
|
+
"storybook": "^10.2.0-alpha.16"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|