@gtkx/storybook 0.0.1 → 2.0.0-beta.11
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/LICENSE +373 -0
- package/README.md +17 -0
- package/dist/actions.d.ts +0 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -9
- package/dist/actions.js.map +1 -1
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +0 -5
- package/dist/compose.js.map +1 -1
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +20 -15
- package/dist/controls.js.map +1 -1
- package/dist/types.d.ts +5 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +80 -81
- package/src/actions.ts +1 -12
- package/src/catalog.ts +1 -1
- package/src/compose.ts +0 -6
- package/src/controls.tsx +21 -15
- package/src/types.ts +8 -25
package/LICENSE
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Mozilla Public License Version 2.0
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
1. Definitions
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
1.1. "Contributor"
|
|
8
|
+
means each individual or legal entity that creates, contributes to
|
|
9
|
+
the creation of, or owns Covered Software.
|
|
10
|
+
|
|
11
|
+
1.2. "Contributor Version"
|
|
12
|
+
means the combination of the Contributions of others (if any) used
|
|
13
|
+
by a Contributor and that particular Contributor's Contribution.
|
|
14
|
+
|
|
15
|
+
1.3. "Contribution"
|
|
16
|
+
means Covered Software of a particular Contributor.
|
|
17
|
+
|
|
18
|
+
1.4. "Covered Software"
|
|
19
|
+
means Source Code Form to which the initial Contributor has attached
|
|
20
|
+
the notice in Exhibit A, the Executable Form of such Source Code
|
|
21
|
+
Form, and Modifications of such Source Code Form, in each case
|
|
22
|
+
including portions thereof.
|
|
23
|
+
|
|
24
|
+
1.5. "Incompatible With Secondary Licenses"
|
|
25
|
+
means
|
|
26
|
+
|
|
27
|
+
(a) that the initial Contributor has attached the notice described
|
|
28
|
+
in Exhibit B to the Covered Software; or
|
|
29
|
+
|
|
30
|
+
(b) that the Covered Software was made available under the terms of
|
|
31
|
+
version 1.1 or earlier of the License, but not also under the
|
|
32
|
+
terms of a Secondary License.
|
|
33
|
+
|
|
34
|
+
1.6. "Executable Form"
|
|
35
|
+
means any form of the work other than Source Code Form.
|
|
36
|
+
|
|
37
|
+
1.7. "Larger Work"
|
|
38
|
+
means a work that combines Covered Software with other material, in
|
|
39
|
+
a separate file or files, that is not Covered Software.
|
|
40
|
+
|
|
41
|
+
1.8. "License"
|
|
42
|
+
means this document.
|
|
43
|
+
|
|
44
|
+
1.9. "Licensable"
|
|
45
|
+
means having the right to grant, to the maximum extent possible,
|
|
46
|
+
whether at the time of the initial grant or subsequently, any and
|
|
47
|
+
all of the rights conveyed by this License.
|
|
48
|
+
|
|
49
|
+
1.10. "Modifications"
|
|
50
|
+
means any of the following:
|
|
51
|
+
|
|
52
|
+
(a) any file in Source Code Form that results from an addition to,
|
|
53
|
+
deletion from, or modification of the contents of Covered
|
|
54
|
+
Software; or
|
|
55
|
+
|
|
56
|
+
(b) any new file in Source Code Form that contains any Covered
|
|
57
|
+
Software.
|
|
58
|
+
|
|
59
|
+
1.11. "Patent Claims" of a Contributor
|
|
60
|
+
means any patent claim(s), including without limitation, method,
|
|
61
|
+
process, and apparatus claims, in any patent Licensable by such
|
|
62
|
+
Contributor that would be infringed, but for the grant of the
|
|
63
|
+
License, by the making, using, selling, offering for sale, having
|
|
64
|
+
made, import, or transfer of either its Contributions or its
|
|
65
|
+
Contributor Version.
|
|
66
|
+
|
|
67
|
+
1.12. "Secondary License"
|
|
68
|
+
means either the GNU General Public License, Version 2.0, the GNU
|
|
69
|
+
Lesser General Public License, Version 2.1, the GNU Affero General
|
|
70
|
+
Public License, Version 3.0, or any later versions of those
|
|
71
|
+
licenses.
|
|
72
|
+
|
|
73
|
+
1.13. "Source Code Form"
|
|
74
|
+
means the form of the work preferred for making modifications.
|
|
75
|
+
|
|
76
|
+
1.14. "You" (or "Your")
|
|
77
|
+
means an individual or a legal entity exercising rights under this
|
|
78
|
+
License. For legal entities, "You" includes any entity that
|
|
79
|
+
controls, is controlled by, or is under common control with You. For
|
|
80
|
+
purposes of this definition, "control" means (a) the power, direct
|
|
81
|
+
or indirect, to cause the direction or management of such entity,
|
|
82
|
+
whether by contract or otherwise, or (b) ownership of more than
|
|
83
|
+
fifty percent (50%) of the outstanding shares or beneficial
|
|
84
|
+
ownership of such entity.
|
|
85
|
+
|
|
86
|
+
2. License Grants and Conditions
|
|
87
|
+
--------------------------------
|
|
88
|
+
|
|
89
|
+
2.1. Grants
|
|
90
|
+
|
|
91
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
92
|
+
non-exclusive license:
|
|
93
|
+
|
|
94
|
+
(a) under intellectual property rights (other than patent or trademark)
|
|
95
|
+
Licensable by such Contributor to use, reproduce, make available,
|
|
96
|
+
modify, display, perform, distribute, and otherwise exploit its
|
|
97
|
+
Contributions, either on an unmodified basis, with Modifications, or
|
|
98
|
+
as part of a Larger Work; and
|
|
99
|
+
|
|
100
|
+
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
|
101
|
+
for sale, have made, import, and otherwise transfer either its
|
|
102
|
+
Contributions or its Contributor Version.
|
|
103
|
+
|
|
104
|
+
2.2. Effective Date
|
|
105
|
+
|
|
106
|
+
The licenses granted in Section 2.1 with respect to any Contribution
|
|
107
|
+
become effective for each Contribution on the date the Contributor first
|
|
108
|
+
distributes such Contribution.
|
|
109
|
+
|
|
110
|
+
2.3. Limitations on Grant Scope
|
|
111
|
+
|
|
112
|
+
The licenses granted in this Section 2 are the only rights granted under
|
|
113
|
+
this License. No additional rights or licenses will be implied from the
|
|
114
|
+
distribution or licensing of Covered Software under this License.
|
|
115
|
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
116
|
+
Contributor:
|
|
117
|
+
|
|
118
|
+
(a) for any code that a Contributor has removed from Covered Software;
|
|
119
|
+
or
|
|
120
|
+
|
|
121
|
+
(b) for infringements caused by: (i) Your and any other third party's
|
|
122
|
+
modifications of Covered Software, or (ii) the combination of its
|
|
123
|
+
Contributions with other software (except as part of its Contributor
|
|
124
|
+
Version); or
|
|
125
|
+
|
|
126
|
+
(c) under Patent Claims infringed by Covered Software in the absence of
|
|
127
|
+
its Contributions.
|
|
128
|
+
|
|
129
|
+
This License does not grant any rights in the trademarks, service marks,
|
|
130
|
+
or logos of any Contributor (except as may be necessary to comply with
|
|
131
|
+
the notice requirements in Section 3.4).
|
|
132
|
+
|
|
133
|
+
2.4. Subsequent Licenses
|
|
134
|
+
|
|
135
|
+
No Contributor makes additional grants as a result of Your choice to
|
|
136
|
+
distribute the Covered Software under a subsequent version of this
|
|
137
|
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
138
|
+
permitted under the terms of Section 3.3).
|
|
139
|
+
|
|
140
|
+
2.5. Representation
|
|
141
|
+
|
|
142
|
+
Each Contributor represents that the Contributor believes its
|
|
143
|
+
Contributions are its original creation(s) or it has sufficient rights
|
|
144
|
+
to grant the rights to its Contributions conveyed by this License.
|
|
145
|
+
|
|
146
|
+
2.6. Fair Use
|
|
147
|
+
|
|
148
|
+
This License is not intended to limit any rights You have under
|
|
149
|
+
applicable copyright doctrines of fair use, fair dealing, or other
|
|
150
|
+
equivalents.
|
|
151
|
+
|
|
152
|
+
2.7. Conditions
|
|
153
|
+
|
|
154
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
|
155
|
+
in Section 2.1.
|
|
156
|
+
|
|
157
|
+
3. Responsibilities
|
|
158
|
+
-------------------
|
|
159
|
+
|
|
160
|
+
3.1. Distribution of Source Form
|
|
161
|
+
|
|
162
|
+
All distribution of Covered Software in Source Code Form, including any
|
|
163
|
+
Modifications that You create or to which You contribute, must be under
|
|
164
|
+
the terms of this License. You must inform recipients that the Source
|
|
165
|
+
Code Form of the Covered Software is governed by the terms of this
|
|
166
|
+
License, and how they can obtain a copy of this License. You may not
|
|
167
|
+
attempt to alter or restrict the recipients' rights in the Source Code
|
|
168
|
+
Form.
|
|
169
|
+
|
|
170
|
+
3.2. Distribution of Executable Form
|
|
171
|
+
|
|
172
|
+
If You distribute Covered Software in Executable Form then:
|
|
173
|
+
|
|
174
|
+
(a) such Covered Software must also be made available in Source Code
|
|
175
|
+
Form, as described in Section 3.1, and You must inform recipients of
|
|
176
|
+
the Executable Form how they can obtain a copy of such Source Code
|
|
177
|
+
Form by reasonable means in a timely manner, at a charge no more
|
|
178
|
+
than the cost of distribution to the recipient; and
|
|
179
|
+
|
|
180
|
+
(b) You may distribute such Executable Form under the terms of this
|
|
181
|
+
License, or sublicense it under different terms, provided that the
|
|
182
|
+
license for the Executable Form does not attempt to limit or alter
|
|
183
|
+
the recipients' rights in the Source Code Form under this License.
|
|
184
|
+
|
|
185
|
+
3.3. Distribution of a Larger Work
|
|
186
|
+
|
|
187
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
|
188
|
+
provided that You also comply with the requirements of this License for
|
|
189
|
+
the Covered Software. If the Larger Work is a combination of Covered
|
|
190
|
+
Software with a work governed by one or more Secondary Licenses, and the
|
|
191
|
+
Covered Software is not Incompatible With Secondary Licenses, this
|
|
192
|
+
License permits You to additionally distribute such Covered Software
|
|
193
|
+
under the terms of such Secondary License(s), so that the recipient of
|
|
194
|
+
the Larger Work may, at their option, further distribute the Covered
|
|
195
|
+
Software under the terms of either this License or such Secondary
|
|
196
|
+
License(s).
|
|
197
|
+
|
|
198
|
+
3.4. Notices
|
|
199
|
+
|
|
200
|
+
You may not remove or alter the substance of any license notices
|
|
201
|
+
(including copyright notices, patent notices, disclaimers of warranty,
|
|
202
|
+
or limitations of liability) contained within the Source Code Form of
|
|
203
|
+
the Covered Software, except that You may alter any license notices to
|
|
204
|
+
the extent required to remedy known factual inaccuracies.
|
|
205
|
+
|
|
206
|
+
3.5. Application of Additional Terms
|
|
207
|
+
|
|
208
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
|
209
|
+
indemnity or liability obligations to one or more recipients of Covered
|
|
210
|
+
Software. However, You may do so only on Your own behalf, and not on
|
|
211
|
+
behalf of any Contributor. You must make it absolutely clear that any
|
|
212
|
+
such warranty, support, indemnity, or liability obligation is offered by
|
|
213
|
+
You alone, and You hereby agree to indemnify every Contributor for any
|
|
214
|
+
liability incurred by such Contributor as a result of warranty, support,
|
|
215
|
+
indemnity or liability terms You offer. You may include additional
|
|
216
|
+
disclaimers of warranty and limitations of liability specific to any
|
|
217
|
+
jurisdiction.
|
|
218
|
+
|
|
219
|
+
4. Inability to Comply Due to Statute or Regulation
|
|
220
|
+
---------------------------------------------------
|
|
221
|
+
|
|
222
|
+
If it is impossible for You to comply with any of the terms of this
|
|
223
|
+
License with respect to some or all of the Covered Software due to
|
|
224
|
+
statute, judicial order, or regulation then You must: (a) comply with
|
|
225
|
+
the terms of this License to the maximum extent possible; and (b)
|
|
226
|
+
describe the limitations and the code they affect. Such description must
|
|
227
|
+
be placed in a text file included with all distributions of the Covered
|
|
228
|
+
Software under this License. Except to the extent prohibited by statute
|
|
229
|
+
or regulation, such description must be sufficiently detailed for a
|
|
230
|
+
recipient of ordinary skill to be able to understand it.
|
|
231
|
+
|
|
232
|
+
5. Termination
|
|
233
|
+
--------------
|
|
234
|
+
|
|
235
|
+
5.1. The rights granted under this License will terminate automatically
|
|
236
|
+
if You fail to comply with any of its terms. However, if You become
|
|
237
|
+
compliant, then the rights granted under this License from a particular
|
|
238
|
+
Contributor are reinstated (a) provisionally, unless and until such
|
|
239
|
+
Contributor explicitly and finally terminates Your grants, and (b) on an
|
|
240
|
+
ongoing basis, if such Contributor fails to notify You of the
|
|
241
|
+
non-compliance by some reasonable means prior to 60 days after You have
|
|
242
|
+
come back into compliance. Moreover, Your grants from a particular
|
|
243
|
+
Contributor are reinstated on an ongoing basis if such Contributor
|
|
244
|
+
notifies You of the non-compliance by some reasonable means, this is the
|
|
245
|
+
first time You have received notice of non-compliance with this License
|
|
246
|
+
from such Contributor, and You become compliant prior to 30 days after
|
|
247
|
+
Your receipt of the notice.
|
|
248
|
+
|
|
249
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
|
250
|
+
infringement claim (excluding declaratory judgment actions,
|
|
251
|
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
252
|
+
directly or indirectly infringes any patent, then the rights granted to
|
|
253
|
+
You by any and all Contributors for the Covered Software under Section
|
|
254
|
+
2.1 of this License shall terminate.
|
|
255
|
+
|
|
256
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
|
257
|
+
end user license agreements (excluding distributors and resellers) which
|
|
258
|
+
have been validly granted by You or Your distributors under this License
|
|
259
|
+
prior to termination shall survive termination.
|
|
260
|
+
|
|
261
|
+
************************************************************************
|
|
262
|
+
* *
|
|
263
|
+
* 6. Disclaimer of Warranty *
|
|
264
|
+
* ------------------------- *
|
|
265
|
+
* *
|
|
266
|
+
* Covered Software is provided under this License on an "as is" *
|
|
267
|
+
* basis, without warranty of any kind, either expressed, implied, or *
|
|
268
|
+
* statutory, including, without limitation, warranties that the *
|
|
269
|
+
* Covered Software is free of defects, merchantable, fit for a *
|
|
270
|
+
* particular purpose or non-infringing. The entire risk as to the *
|
|
271
|
+
* quality and performance of the Covered Software is with You. *
|
|
272
|
+
* Should any Covered Software prove defective in any respect, You *
|
|
273
|
+
* (not any Contributor) assume the cost of any necessary servicing, *
|
|
274
|
+
* repair, or correction. This disclaimer of warranty constitutes an *
|
|
275
|
+
* essential part of this License. No use of any Covered Software is *
|
|
276
|
+
* authorized under this License except under this disclaimer. *
|
|
277
|
+
* *
|
|
278
|
+
************************************************************************
|
|
279
|
+
|
|
280
|
+
************************************************************************
|
|
281
|
+
* *
|
|
282
|
+
* 7. Limitation of Liability *
|
|
283
|
+
* -------------------------- *
|
|
284
|
+
* *
|
|
285
|
+
* Under no circumstances and under no legal theory, whether tort *
|
|
286
|
+
* (including negligence), contract, or otherwise, shall any *
|
|
287
|
+
* Contributor, or anyone who distributes Covered Software as *
|
|
288
|
+
* permitted above, be liable to You for any direct, indirect, *
|
|
289
|
+
* special, incidental, or consequential damages of any character *
|
|
290
|
+
* including, without limitation, damages for lost profits, loss of *
|
|
291
|
+
* goodwill, work stoppage, computer failure or malfunction, or any *
|
|
292
|
+
* and all other commercial damages or losses, even if such party *
|
|
293
|
+
* shall have been informed of the possibility of such damages. This *
|
|
294
|
+
* limitation of liability shall not apply to liability for death or *
|
|
295
|
+
* personal injury resulting from such party's negligence to the *
|
|
296
|
+
* extent applicable law prohibits such limitation. Some *
|
|
297
|
+
* jurisdictions do not allow the exclusion or limitation of *
|
|
298
|
+
* incidental or consequential damages, so this exclusion and *
|
|
299
|
+
* limitation may not apply to You. *
|
|
300
|
+
* *
|
|
301
|
+
************************************************************************
|
|
302
|
+
|
|
303
|
+
8. Litigation
|
|
304
|
+
-------------
|
|
305
|
+
|
|
306
|
+
Any litigation relating to this License may be brought only in the
|
|
307
|
+
courts of a jurisdiction where the defendant maintains its principal
|
|
308
|
+
place of business and such litigation shall be governed by laws of that
|
|
309
|
+
jurisdiction, without reference to its conflict-of-law provisions.
|
|
310
|
+
Nothing in this Section shall prevent a party's ability to bring
|
|
311
|
+
cross-claims or counter-claims.
|
|
312
|
+
|
|
313
|
+
9. Miscellaneous
|
|
314
|
+
----------------
|
|
315
|
+
|
|
316
|
+
This License represents the complete agreement concerning the subject
|
|
317
|
+
matter hereof. If any provision of this License is held to be
|
|
318
|
+
unenforceable, such provision shall be reformed only to the extent
|
|
319
|
+
necessary to make it enforceable. Any law or regulation which provides
|
|
320
|
+
that the language of a contract shall be construed against the drafter
|
|
321
|
+
shall not be used to construe this License against a Contributor.
|
|
322
|
+
|
|
323
|
+
10. Versions of the License
|
|
324
|
+
---------------------------
|
|
325
|
+
|
|
326
|
+
10.1. New Versions
|
|
327
|
+
|
|
328
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
|
329
|
+
10.3, no one other than the license steward has the right to modify or
|
|
330
|
+
publish new versions of this License. Each version will be given a
|
|
331
|
+
distinguishing version number.
|
|
332
|
+
|
|
333
|
+
10.2. Effect of New Versions
|
|
334
|
+
|
|
335
|
+
You may distribute the Covered Software under the terms of the version
|
|
336
|
+
of the License under which You originally received the Covered Software,
|
|
337
|
+
or under the terms of any subsequent version published by the license
|
|
338
|
+
steward.
|
|
339
|
+
|
|
340
|
+
10.3. Modified Versions
|
|
341
|
+
|
|
342
|
+
If you create software not governed by this License, and you want to
|
|
343
|
+
create a new license for such software, you may create and use a
|
|
344
|
+
modified version of this License if you rename the license and remove
|
|
345
|
+
any references to the name of the license steward (except to note that
|
|
346
|
+
such modified license differs from this License).
|
|
347
|
+
|
|
348
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
349
|
+
Licenses
|
|
350
|
+
|
|
351
|
+
If You choose to distribute Source Code Form that is Incompatible With
|
|
352
|
+
Secondary Licenses under the terms of this version of the License, the
|
|
353
|
+
notice described in Exhibit B of this License must be attached.
|
|
354
|
+
|
|
355
|
+
Exhibit A - Source Code Form License Notice
|
|
356
|
+
-------------------------------------------
|
|
357
|
+
|
|
358
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
359
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
360
|
+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
361
|
+
|
|
362
|
+
If it is not possible or desirable to put the notice in a particular
|
|
363
|
+
file, then You may include the notice in a location (such as a LICENSE
|
|
364
|
+
file in a relevant directory) where a recipient would be likely to look
|
|
365
|
+
for such a notice.
|
|
366
|
+
|
|
367
|
+
You may add additional accurate notices of copyright ownership.
|
|
368
|
+
|
|
369
|
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
370
|
+
---------------------------------------------------------
|
|
371
|
+
|
|
372
|
+
This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
373
|
+
defined by the Mozilla Public License, v. 2.0.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @gtkx/storybook
|
|
2
|
+
|
|
3
|
+
Explore GTKX components as native stories.
|
|
4
|
+
|
|
5
|
+
Write Component Story Format stories, open them with `gtkx storybook`, and change props through Controls. Actions record interactions, and portable stories can also serve as native integration-test fixtures.
|
|
6
|
+
|
|
7
|
+
In an existing GTKX 2.0 beta app:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @gtkx/storybook@beta
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[Guide](https://gtkx.dev/v2/guide/storybook) · [API reference](https://gtkx.dev/v2/reference/@gtkx/storybook/) · [GTKX](https://gtkx.dev)
|
|
14
|
+
|
|
15
|
+
GTKX runs on Linux with Node.js and system native libraries. See [Getting Started](https://gtkx.dev/v2/guide/getting-started) for supported versions and installation. This README describes the 2.0 beta.
|
|
16
|
+
|
|
17
|
+
[MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
|
package/dist/actions.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ type ActionEntry = {
|
|
|
3
3
|
id: number;
|
|
4
4
|
name: string;
|
|
5
5
|
args: string[];
|
|
6
|
-
timestamp: number;
|
|
7
6
|
error?: string;
|
|
8
7
|
};
|
|
9
8
|
/** A named story callback whose arguments can be recorded by the native explorer. */
|
|
@@ -21,11 +20,9 @@ declare class ActionStore {
|
|
|
21
20
|
private entries;
|
|
22
21
|
private readonly listeners;
|
|
23
22
|
private nextId;
|
|
24
|
-
private readonly limit;
|
|
25
23
|
getSnapshot: () => ActionEntry[];
|
|
26
24
|
subscribe: (listener: () => void) => (() => void);
|
|
27
25
|
clear: () => void;
|
|
28
|
-
constructor(limit?: number);
|
|
29
26
|
private publish;
|
|
30
27
|
record(name: string, args: unknown[], error?: Error): void;
|
|
31
28
|
}
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","s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,KACjC,IAiBF,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/actions.js
CHANGED
|
@@ -56,7 +56,6 @@ class ActionStore {
|
|
|
56
56
|
entries = [];
|
|
57
57
|
listeners = new Set();
|
|
58
58
|
nextId = 0;
|
|
59
|
-
limit;
|
|
60
59
|
getSnapshot = () => this.entries;
|
|
61
60
|
subscribe = (listener) => {
|
|
62
61
|
this.listeners.add(listener);
|
|
@@ -67,12 +66,6 @@ class ActionStore {
|
|
|
67
66
|
clear = () => {
|
|
68
67
|
this.publish([]);
|
|
69
68
|
};
|
|
70
|
-
constructor(limit = DEFAULT_HISTORY_LIMIT) {
|
|
71
|
-
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
72
|
-
throw new RangeError("Action history needs a positive integer limit");
|
|
73
|
-
}
|
|
74
|
-
this.limit = limit;
|
|
75
|
-
}
|
|
76
69
|
publish(entries) {
|
|
77
70
|
this.entries = entries;
|
|
78
71
|
for (const listener of this.listeners) {
|
|
@@ -84,10 +77,9 @@ class ActionStore {
|
|
|
84
77
|
id: this.nextId++,
|
|
85
78
|
name,
|
|
86
79
|
args: args.slice(0, 8).map((value) => formatArgument(value)),
|
|
87
|
-
timestamp: Date.now(),
|
|
88
80
|
...(error !== undefined && { error: error.message.slice(0, MAX_ARGUMENT_LENGTH) }),
|
|
89
81
|
};
|
|
90
|
-
this.publish([...this.entries, entry].slice(-
|
|
82
|
+
this.publish([...this.entries, entry].slice(-DEFAULT_HISTORY_LIMIT));
|
|
91
83
|
}
|
|
92
84
|
}
|
|
93
85
|
const settleCallback = async (result, succeed, fail) => {
|
package/dist/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAA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K,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAEtD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,SAAS;QACb,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { inspect } from \"node:util\";\nimport type { Args, ArgTypes } from \"./types.js\";\n\ntype ActionEntry = {\n id: number;\n name: string;\n args: string[];\n timestamp: number;\n error?: string;\n};\n\n/** A named story callback whose arguments can be recorded by the native explorer. */\ntype ActionCallback = (...args: unknown[]) => void;\ntype EventCallback = (...args: unknown[]) => unknown;\n\nconst actionNames: WeakMap<object, string> = new WeakMap();\nconst actionScope: AsyncLocalStorage<ActionStore> = new AsyncLocalStorage();\nconst DEFAULT_HISTORY_LIMIT = 100;\nconst MAX_ARGUMENT_LENGTH = 400;\n\nconst objectLabel = (value: unknown): string | undefined => {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n if (prototype === null || typeof prototype !== \"object\" || prototype === Object.prototype) {\n return undefined;\n }\n\n const constructor: unknown = Object.getOwnPropertyDescriptor(prototype, \"constructor\")?.value;\n\n return typeof constructor === \"function\" ? `[${constructor.name}]` : \"[Object]\";\n};\n\nconst formatArgument = (value: unknown): string => {\n try {\n const label = objectLabel(value);\n\n if (label !== undefined) {\n return label;\n }\n\n return inspect(value, {\n depth: 1,\n maxArrayLength: 5,\n maxStringLength: 120,\n customInspect: false,\n getters: false,\n breakLength: Infinity,\n }).slice(0, MAX_ARGUMENT_LENGTH);\n } catch {\n return \"[Unreadable value]\";\n }\n};\n\n/**\n * Creates a named action for a story's callback arguments.\n * The explorer records bounded argument summaries; calls outside its action scope have no effect.\n *\n * @param name Nonempty label displayed in the Actions panel.\n * @returns A callback to supply in story args.\n * @throws If the name is empty or contains only whitespace.\n */\nconst action = (name: string): ActionCallback => {\n if (name.trim().length === 0) {\n throw new TypeError(\"An action needs a name\");\n }\n\n const callback: ActionCallback = (...args) => {\n actionScope.getStore()?.record(name, args);\n };\n actionNames.set(callback, name);\n\n return callback;\n};\n\nclass ActionStore {\n private entries: ActionEntry[] = [];\n private readonly listeners: Set<() => void> = new Set();\n private nextId = 0;\n private readonly limit: number;\n\n getSnapshot = (): ActionEntry[] => this.entries;\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n clear = (): void => {\n this.publish([]);\n };\n\n constructor(limit: number = DEFAULT_HISTORY_LIMIT) {\n if (!Number.isSafeInteger(limit) || limit < 1) {\n throw new RangeError(\"Action history needs a positive integer limit\");\n }\n\n this.limit = limit;\n }\n\n private publish(entries: ActionEntry[]): void {\n this.entries = entries;\n\n for (const listener of this.listeners) {\n listener();\n }\n }\n\n record(name: string, args: unknown[], error?: Error): void {\n const entry: ActionEntry = {\n id: this.nextId++,\n name,\n args: args.slice(0, 8).map((value) => formatArgument(value)),\n timestamp: Date.now(),\n ...(error !== undefined && { error: error.message.slice(0, MAX_ARGUMENT_LENGTH) }),\n };\n this.publish([...this.entries, entry].slice(-this.limit));\n }\n}\n\ntype CallbackOptions = { callback?: EventCallback; name: string; onError?: (error: Error) => void };\n\nconst settleCallback = async (\n result: Promise<unknown>,\n succeed: () => void,\n fail: (cause: unknown) => void,\n): Promise<unknown> => {\n try {\n const value = await result;\n succeed();\n\n return value;\n } catch (error) {\n fail(error);\n\n return undefined;\n }\n};\n\nconst bindCallback = (\n store: ActionStore,\n options: CallbackOptions,\n): EventCallback => (...values) => {\n const succeed = (): void => {\n store.record(options.name, values);\n };\n const fail = (cause: unknown): void => {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n store.record(options.name, values, error);\n\n if (options.onError === undefined) {\n throw error;\n }\n\n options.onError(error);\n };\n\n try {\n const result = actionScope.run(store, () => options.callback?.(...values));\n\n if (result instanceof Promise) {\n return settleCallback(result, succeed, fail);\n }\n\n succeed();\n\n return result;\n } catch (error) {\n fail(error);\n\n return;\n }\n};\n\nconst actionName = (value: unknown, configuredName: unknown): string | undefined => {\n if (typeof configuredName === \"string\") {\n return configuredName;\n }\n\n return typeof value === \"function\" ? actionNames.get(value) : undefined;\n};\n\nconst isOriginalCallback = (value: unknown): value is EventCallback =>\n typeof value === \"function\" && !actionNames.has(value);\n\nconst callbackOptions = (\n value: unknown,\n name: string | undefined,\n onError: ((error: Error) => void) | undefined,\n): CallbackOptions | undefined => {\n if (name === undefined) {\n return undefined;\n }\n\n return {\n name,\n ...(isOriginalCallback(value) && { callback: value }),\n ...(onError !== undefined && { onError }),\n };\n};\n\nconst bindActions = (\n args: Args,\n argTypes: ArgTypes,\n store: ActionStore,\n onError?: (error: Error) => void,\n): Args => {\n const bound = { ...args };\n const names = new Set([...Object.keys(args), ...Object.keys(argTypes)]);\n\n for (const argument of names) {\n const value = args[argument];\n const name = actionName(value, argTypes[argument]?.action);\n const options = callbackOptions(value, name, onError);\n\n if (options === undefined) {\n continue;\n }\n\n bound[argument] = bindCallback(store, options);\n }\n\n return bound;\n};\n\nexport { action, ActionStore, bindActions };\nexport type { ActionCallback };\n"]}
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAcpC,MAAM,WAAW,GAA4B,IAAI,OAAO,EAAE,CAAC;AAC3D,MAAM,WAAW,GAAmC,IAAI,iBAAiB,EAAE,CAAC;AAC5E,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEh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AC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,CAAC;KAC5C,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAChB,IAAU,EACV,QAAkB,EAClB,KAAkB,EAClB,OAAgC,EAC5B,EAAE;IACN,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExE,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAEtD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,SAAS;QACb,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { inspect } from \"node:util\";\nimport type { Args, ArgTypes } from \"./types.js\";\n\ntype ActionEntry = {\n id: number;\n name: string;\n args: string[];\n error?: string;\n};\n\n/** A named story callback whose arguments can be recorded by the native explorer. */\ntype ActionCallback = (...args: unknown[]) => void;\ntype EventCallback = (...args: unknown[]) => unknown;\n\nconst actionNames: WeakMap<object, string> = new WeakMap();\nconst actionScope: AsyncLocalStorage<ActionStore> = new AsyncLocalStorage();\nconst DEFAULT_HISTORY_LIMIT = 100;\nconst MAX_ARGUMENT_LENGTH = 400;\n\nconst objectLabel = (value: unknown): string | undefined => {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n if (prototype === null || typeof prototype !== \"object\" || prototype === Object.prototype) {\n return undefined;\n }\n\n const constructor: unknown = Object.getOwnPropertyDescriptor(prototype, \"constructor\")?.value;\n\n return typeof constructor === \"function\" ? `[${constructor.name}]` : \"[Object]\";\n};\n\nconst formatArgument = (value: unknown): string => {\n try {\n const label = objectLabel(value);\n\n if (label !== undefined) {\n return label;\n }\n\n return inspect(value, {\n depth: 1,\n maxArrayLength: 5,\n maxStringLength: 120,\n customInspect: false,\n getters: false,\n breakLength: Infinity,\n }).slice(0, MAX_ARGUMENT_LENGTH);\n } catch {\n return \"[Unreadable value]\";\n }\n};\n\n/**\n * Creates a named action for a story's callback arguments.\n * The explorer records bounded argument summaries; calls outside its action scope have no effect.\n *\n * @param name Nonempty label displayed in the Actions panel.\n * @returns A callback to supply in story args.\n * @throws If the name is empty or contains only whitespace.\n */\nconst action = (name: string): ActionCallback => {\n if (name.trim().length === 0) {\n throw new TypeError(\"An action needs a name\");\n }\n\n const callback: ActionCallback = (...args) => {\n actionScope.getStore()?.record(name, args);\n };\n actionNames.set(callback, name);\n\n return callback;\n};\n\nclass ActionStore {\n private entries: ActionEntry[] = [];\n private readonly listeners: Set<() => void> = new Set();\n private nextId = 0;\n\n getSnapshot = (): ActionEntry[] => this.entries;\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n clear = (): void => {\n this.publish([]);\n };\n\n private publish(entries: ActionEntry[]): void {\n this.entries = entries;\n\n for (const listener of this.listeners) {\n listener();\n }\n }\n\n record(name: string, args: unknown[], error?: Error): void {\n const entry: ActionEntry = {\n id: this.nextId++,\n name,\n args: args.slice(0, 8).map((value) => formatArgument(value)),\n ...(error !== undefined && { error: error.message.slice(0, MAX_ARGUMENT_LENGTH) }),\n };\n this.publish([...this.entries, entry].slice(-DEFAULT_HISTORY_LIMIT));\n }\n}\n\ntype CallbackOptions = { callback?: EventCallback; name: string; onError?: (error: Error) => void };\n\nconst settleCallback = async (\n result: Promise<unknown>,\n succeed: () => void,\n fail: (cause: unknown) => void,\n): Promise<unknown> => {\n try {\n const value = await result;\n succeed();\n\n return value;\n } catch (error) {\n fail(error);\n\n return undefined;\n }\n};\n\nconst bindCallback = (\n store: ActionStore,\n options: CallbackOptions,\n): EventCallback => (...values) => {\n const succeed = (): void => {\n store.record(options.name, values);\n };\n const fail = (cause: unknown): void => {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n store.record(options.name, values, error);\n\n if (options.onError === undefined) {\n throw error;\n }\n\n options.onError(error);\n };\n\n try {\n const result = actionScope.run(store, () => options.callback?.(...values));\n\n if (result instanceof Promise) {\n return settleCallback(result, succeed, fail);\n }\n\n succeed();\n\n return result;\n } catch (error) {\n fail(error);\n\n return;\n }\n};\n\nconst actionName = (value: unknown, configuredName: unknown): string | undefined => {\n if (typeof configuredName === \"string\") {\n return configuredName;\n }\n\n return typeof value === \"function\" ? actionNames.get(value) : undefined;\n};\n\nconst isOriginalCallback = (value: unknown): value is EventCallback =>\n typeof value === \"function\" && !actionNames.has(value);\n\nconst callbackOptions = (\n value: unknown,\n name: string | undefined,\n onError: ((error: Error) => void) | undefined,\n): CallbackOptions | undefined => {\n if (name === undefined) {\n return undefined;\n }\n\n return {\n name,\n ...(isOriginalCallback(value) && { callback: value }),\n ...(onError !== undefined && { onError }),\n };\n};\n\nconst bindActions = (\n args: Args,\n argTypes: ArgTypes,\n store: ActionStore,\n onError?: (error: Error) => void,\n): Args => {\n const bound = { ...args };\n const names = new Set([...Object.keys(args), ...Object.keys(argTypes)]);\n\n for (const argument of names) {\n const value = args[argument];\n const name = actionName(value, argTypes[argument]?.action);\n const options = callbackOptions(value, name, onError);\n\n if (options === undefined) {\n continue;\n }\n\n bound[argument] = bindCallback(store, options);\n }\n\n return bound;\n};\n\nexport { action, ActionStore, bindActions };\nexport type { ActionCallback };\n"]}
|
package/dist/catalog.js
CHANGED
|
@@ -11,7 +11,7 @@ const explicitControls = (resolved, story, meta, preview) => {
|
|
|
11
11
|
if (control === undefined) {
|
|
12
12
|
continue;
|
|
13
13
|
}
|
|
14
|
-
controls[argument] = { ...annotation, control: control
|
|
14
|
+
controls[argument] = { ...annotation, control: control !== false && (annotation?.control ?? control) };
|
|
15
15
|
}
|
|
16
16
|
return controls;
|
|
17
17
|
};
|
package/dist/catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAyDpD,MAAM,aAAa,GAAY,EAAE,CAAC;AAElC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAS,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE5G,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEzE,MAAM,gBAAgB,GAAG,CACrB,QAAkB,EAClB,KAAyC,EACzC,IAAyB,EACzB,OAAgB,EACR,EAAE;IACV,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAA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,KAAK,CAAC,EAAE,kCAAkC,CAAC,CAAC;YACzG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC/B,MAAM,OAAO,CAAC;QAClB,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,KAAc;QACtB,IAAI,KAAK,YAAY,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,OAAO;QACX,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,YAAY,CAAC,CAAC;QACnF,IAAI,CAAC,YAAY,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,IAAI,CAAC,OAAO,CAAC;YACT,GAAG,IAAI,CAAC,QAAQ;YAChB,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC;SACzC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import type { Args, ArgTypes, ComponentMeta, ComposedStory, Preview, StoryAnnotations } from \"./types.js\";\nimport { composeStories } from \"./compose.js\";\nimport { storyNameFromExport } from \"./upstream.js\";\n\n/** A lazily loaded CSF module discovered in a Storybook project. */\ntype StorySource = {\n /** Stable module identifier used for caching and error reporting. */\n id: string;\n /** Fallback story group title when the module does not declare one. */\n title: string;\n /** Imports the module and resolves to its CSF exports. */\n load: () => Promise<unknown>;\n};\n\n/** A composed story and the metadata used to display it in the explorer. */\ntype StoryEntry = {\n /** Storybook identifier used to preserve the selected story across updates. */\n id: string;\n /** Component group title declared by the module or derived from its source. */\n title: string;\n /** Display name declared by the story or derived from its export name. */\n name: string;\n /** Name of the CSF export that defines this story. */\n exportName: string;\n /** Identifier of the module containing this story. */\n source: string;\n /** Renderable story with its metadata, decorators, and default args composed. */\n story: ComposedStory;\n /** Resolved arg types with explicitly configured explorer controls. */\n controls: ArgTypes;\n};\n\n/** A source loading or composition failure displayed alongside healthy stories. */\ntype StoryLoadError = {\n /** Identifier of the failed source, or Storybook for a session failure. */\n source: string;\n /** Normalized error raised while loading or composing the source. */\n error: Error;\n};\n\n/** Current explorer contents and loading state exposed to subscribers. */\ntype StoryCatalogSnapshot = {\n /** Successfully composed stories with duplicate identifiers excluded. */\n stories: StoryEntry[];\n /** Failures encountered during the latest load or reported by the session. */\n errors: StoryLoadError[];\n /** Whether the catalog is waiting for the latest source load to finish. */\n isLoading: boolean;\n};\n\ntype CachedStories = {\n module: unknown;\n title: string;\n preview: Preview;\n entries: StoryEntry[];\n};\n\ntype LoadedSource = StoryLoadError | { source: StorySource; cached: CachedStories };\n\nconst EMPTY_PREVIEW: Preview = {};\n\nconst normalizeError = (cause: unknown): Error => cause instanceof Error ? cause : new Error(String(cause));\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\nconst explicitControls = (\n resolved: ArgTypes,\n story: StoryAnnotations<Args> | undefined,\n meta: ComponentMeta<Args>,\n preview: Preview,\n): ArgTypes => {\n const controls: ArgTypes = {};\n\n for (const [argument, annotation] of Object.entries(resolved)) {\n const control = story?.argTypes?.[argument]?.control ??\n meta.argTypes?.[argument]?.control ?? preview.argTypes?.[argument]?.control;\n\n if (control === undefined) {\n continue;\n }\n\n controls[argument] = { ...annotation, control: control === false ? false : annotation?.control ?? control };\n }\n\n return controls;\n};\n\nconst displayName = (story: StoryAnnotations<Args> | undefined, exportName: string): string => {\n const name = story?.name;\n\n if (name === undefined) {\n return storyNameFromExport(exportName);\n }\n\n if (typeof name !== \"string\") {\n throw new TypeError(\"Expected a story display name\");\n }\n\n return name;\n};\n\nconst composeSource = (source: StorySource, module: unknown, preview: Preview): StoryEntry[] => {\n if (!isObject(module) || !isObject(module.default)) {\n throw new TypeError(`Expected CSF3 component metadata in ${source.id}`);\n }\n\n const title = module.default.title ?? source.title;\n\n if (typeof title !== \"string\" || title.trim().length === 0) {\n throw new TypeError(`Expected a story title in ${source.id}`);\n }\n\n const annotations = {\n ...module,\n default: { ...module.default, title },\n } as Record<string, StoryAnnotations<Args>> & { default: ComponentMeta<Args> };\n const stories = composeStories(annotations, preview);\n\n return Object.entries(stories).map(([exportName, story]) => ({\n id: story.id,\n title,\n name: displayName(annotations[exportName], exportName),\n exportName,\n source: source.id,\n story,\n controls: explicitControls(story.argTypes, annotations[exportName], annotations.default, preview),\n }));\n};\n\nconst withoutDuplicateIds = (entries: StoryEntry[], errors: StoryLoadError[]): StoryEntry[] => {\n const counts: Map<string, number> = new Map();\n\n for (const entry of entries) {\n counts.set(entry.id, (counts.get(entry.id) ?? 0) + 1);\n }\n\n return entries.filter((entry) => {\n if (counts.get(entry.id) === 1) {\n return true;\n }\n\n errors.push({ source: entry.source, error: new Error(`Duplicate story ID: ${entry.id}`) });\n\n return false;\n });\n};\n\nconst collectSources = (loaded: LoadedSource[]) => {\n const cache: Map<string, CachedStories> = new Map();\n const entries: StoryEntry[] = [];\n const errors: StoryLoadError[] = [];\n\n for (const result of loaded) {\n if (\"error\" in result) {\n errors.push(result);\n } else {\n cache.set(result.source.id, result.cached);\n entries.push(...result.cached.entries);\n }\n }\n\n return { cache, stories: withoutDuplicateIds(entries, errors), errors };\n};\n\nconst createSourceCache = (): Map<string, CachedStories> => new Map();\n\nconst loadSource = async (\n source: StorySource,\n preview: Preview,\n getCache: () => Map<string, CachedStories>,\n): Promise<LoadedSource> => {\n try {\n const module = await source.load();\n const previous = getCache().get(source.id);\n const cached = previous !== undefined && previous.module === module &&\n previous.title === source.title && previous.preview === preview\n ? previous\n : { module, title: source.title, preview, entries: composeSource(source, module, preview) };\n\n return { source, cached };\n } catch (error) {\n return { source: source.id, error: normalizeError(error) };\n }\n};\n\n/** Loads CSF modules and publishes subscribable explorer snapshots. */\nclass StoryCatalog {\n private snapshot: StoryCatalogSnapshot = { stories: [], errors: [], isLoading: false };\n private readonly listeners: Set<() => void> = new Set();\n private readonly loadFailures: WeakSet<Error> = new WeakSet();\n private cache = createSourceCache();\n private sessionError: StoryLoadError | undefined;\n private revision = 0;\n\n /** Returns the current snapshot, retaining its identity until the next update. */\n getSnapshot = (): StoryCatalogSnapshot => this.snapshot;\n\n /** Registers a snapshot listener and returns a function that unsubscribes it. */\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n private publish(snapshot: StoryCatalogSnapshot): void {\n this.snapshot = snapshot;\n\n for (const listener of this.listeners) {\n listener();\n }\n }\n\n /**\n * Replaces the catalog with stories composed from the supplied sources and preview.\n * Only the latest load publishes results; unchanged module identities reuse composed stories.\n * Rejects with an AggregateError after publishing healthy stories when any source fails.\n */\n async load(sources: StorySource[], preview: Preview = EMPTY_PREVIEW): Promise<void> {\n const revision = ++this.revision;\n this.publish({ ...this.snapshot, isLoading: true });\n const loaded = await Promise.all(sources.map((source) => loadSource(source, preview, () => this.cache)));\n\n if (revision !== this.revision) {\n return;\n }\n\n const { cache, stories, errors } = collectSources(loaded);\n this.cache = cache;\n this.sessionError = undefined;\n this.publish({ stories, errors, isLoading: false });\n\n if (errors.length > 0) {\n const failure = new AggregateError(errors.map(({ error }) => error), \"Some stories could not be loaded\");\n this.loadFailures.add(failure);\n throw failure;\n }\n }\n\n /**\n * Replaces the current session failure while preserving source errors and superseding pending loads.\n * Ignores aggregate failures already published by this catalog's load operation.\n */\n reportError(cause: unknown): void {\n if (cause instanceof Error && this.loadFailures.has(cause)) {\n return;\n }\n\n this.revision++;\n const errors = this.snapshot.errors.filter((entry) => entry !== this.sessionError);\n this.sessionError = { source: \"Storybook\", error: normalizeError(cause) };\n this.publish({\n ...this.snapshot,\n isLoading: false,\n errors: [...errors, this.sessionError],\n });\n }\n}\n\nexport { StoryCatalog };\nexport type { StoryCatalogSnapshot, StoryEntry, StoryLoadError, StorySource };\n"]}
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAyDpD,MAAM,aAAa,GAAY,EAAE,CAAC;AAElC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAS,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE5G,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEzE,MAAM,gBAAgB,GAAG,CACrB,QAAkB,EAClB,KAAyC,EACzC,IAAyB,EACzB,OAAgB,EACR,EAAE;IACV,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5D,MAAM,OAAO,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO;YAChD,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAEhF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,SAAS;QACb,CAAC;QAED,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO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AAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,YAAY,CAAC,CAAC;QACnF,IAAI,CAAC,YAAY,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,IAAI,CAAC,OAAO,CAAC;YACT,GAAG,IAAI,CAAC,QAAQ;YAChB,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC;SACzC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import type { Args, ArgTypes, ComponentMeta, ComposedStory, Preview, StoryAnnotations } from \"./types.js\";\nimport { composeStories } from \"./compose.js\";\nimport { storyNameFromExport } from \"./upstream.js\";\n\n/** A lazily loaded CSF module discovered in a Storybook project. */\ntype StorySource = {\n /** Stable module identifier used for caching and error reporting. */\n id: string;\n /** Fallback story group title when the module does not declare one. */\n title: string;\n /** Imports the module and resolves to its CSF exports. */\n load: () => Promise<unknown>;\n};\n\n/** A composed story and the metadata used to display it in the explorer. */\ntype StoryEntry = {\n /** Storybook identifier used to preserve the selected story across updates. */\n id: string;\n /** Component group title declared by the module or derived from its source. */\n title: string;\n /** Display name declared by the story or derived from its export name. */\n name: string;\n /** Name of the CSF export that defines this story. */\n exportName: string;\n /** Identifier of the module containing this story. */\n source: string;\n /** Renderable story with its metadata, decorators, and default args composed. */\n story: ComposedStory;\n /** Resolved arg types with explicitly configured explorer controls. */\n controls: ArgTypes;\n};\n\n/** A source loading or composition failure displayed alongside healthy stories. */\ntype StoryLoadError = {\n /** Identifier of the failed source, or Storybook for a session failure. */\n source: string;\n /** Normalized error raised while loading or composing the source. */\n error: Error;\n};\n\n/** Current explorer contents and loading state exposed to subscribers. */\ntype StoryCatalogSnapshot = {\n /** Successfully composed stories with duplicate identifiers excluded. */\n stories: StoryEntry[];\n /** Failures encountered during the latest load or reported by the session. */\n errors: StoryLoadError[];\n /** Whether the catalog is waiting for the latest source load to finish. */\n isLoading: boolean;\n};\n\ntype CachedStories = {\n module: unknown;\n title: string;\n preview: Preview;\n entries: StoryEntry[];\n};\n\ntype LoadedSource = StoryLoadError | { source: StorySource; cached: CachedStories };\n\nconst EMPTY_PREVIEW: Preview = {};\n\nconst normalizeError = (cause: unknown): Error => cause instanceof Error ? cause : new Error(String(cause));\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\nconst explicitControls = (\n resolved: ArgTypes,\n story: StoryAnnotations<Args> | undefined,\n meta: ComponentMeta<Args>,\n preview: Preview,\n): ArgTypes => {\n const controls: ArgTypes = {};\n\n for (const [argument, annotation] of Object.entries(resolved)) {\n const control = story?.argTypes?.[argument]?.control ??\n meta.argTypes?.[argument]?.control ?? preview.argTypes?.[argument]?.control;\n\n if (control === undefined) {\n continue;\n }\n\n controls[argument] = { ...annotation, control: control !== false && (annotation?.control ?? control) };\n }\n\n return controls;\n};\n\nconst displayName = (story: StoryAnnotations<Args> | undefined, exportName: string): string => {\n const name = story?.name;\n\n if (name === undefined) {\n return storyNameFromExport(exportName);\n }\n\n if (typeof name !== \"string\") {\n throw new TypeError(\"Expected a story display name\");\n }\n\n return name;\n};\n\nconst composeSource = (source: StorySource, module: unknown, preview: Preview): StoryEntry[] => {\n if (!isObject(module) || !isObject(module.default)) {\n throw new TypeError(`Expected CSF3 component metadata in ${source.id}`);\n }\n\n const title = module.default.title ?? source.title;\n\n if (typeof title !== \"string\" || title.trim().length === 0) {\n throw new TypeError(`Expected a story title in ${source.id}`);\n }\n\n const annotations = {\n ...module,\n default: { ...module.default, title },\n } as Record<string, StoryAnnotations<Args>> & { default: ComponentMeta<Args> };\n const stories = composeStories(annotations, preview);\n\n return Object.entries(stories).map(([exportName, story]) => ({\n id: story.id,\n title,\n name: displayName(annotations[exportName], exportName),\n exportName,\n source: source.id,\n story,\n controls: explicitControls(story.argTypes, annotations[exportName], annotations.default, preview),\n }));\n};\n\nconst withoutDuplicateIds = (entries: StoryEntry[], errors: StoryLoadError[]): StoryEntry[] => {\n const counts: Map<string, number> = new Map();\n\n for (const entry of entries) {\n counts.set(entry.id, (counts.get(entry.id) ?? 0) + 1);\n }\n\n return entries.filter((entry) => {\n if (counts.get(entry.id) === 1) {\n return true;\n }\n\n errors.push({ source: entry.source, error: new Error(`Duplicate story ID: ${entry.id}`) });\n\n return false;\n });\n};\n\nconst collectSources = (loaded: LoadedSource[]) => {\n const cache: Map<string, CachedStories> = new Map();\n const entries: StoryEntry[] = [];\n const errors: StoryLoadError[] = [];\n\n for (const result of loaded) {\n if (\"error\" in result) {\n errors.push(result);\n } else {\n cache.set(result.source.id, result.cached);\n entries.push(...result.cached.entries);\n }\n }\n\n return { cache, stories: withoutDuplicateIds(entries, errors), errors };\n};\n\nconst createSourceCache = (): Map<string, CachedStories> => new Map();\n\nconst loadSource = async (\n source: StorySource,\n preview: Preview,\n getCache: () => Map<string, CachedStories>,\n): Promise<LoadedSource> => {\n try {\n const module = await source.load();\n const previous = getCache().get(source.id);\n const cached = previous !== undefined && previous.module === module &&\n previous.title === source.title && previous.preview === preview\n ? previous\n : { module, title: source.title, preview, entries: composeSource(source, module, preview) };\n\n return { source, cached };\n } catch (error) {\n return { source: source.id, error: normalizeError(error) };\n }\n};\n\n/** Loads CSF modules and publishes subscribable explorer snapshots. */\nclass StoryCatalog {\n private snapshot: StoryCatalogSnapshot = { stories: [], errors: [], isLoading: false };\n private readonly listeners: Set<() => void> = new Set();\n private readonly loadFailures: WeakSet<Error> = new WeakSet();\n private cache = createSourceCache();\n private sessionError: StoryLoadError | undefined;\n private revision = 0;\n\n /** Returns the current snapshot, retaining its identity until the next update. */\n getSnapshot = (): StoryCatalogSnapshot => this.snapshot;\n\n /** Registers a snapshot listener and returns a function that unsubscribes it. */\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n private publish(snapshot: StoryCatalogSnapshot): void {\n this.snapshot = snapshot;\n\n for (const listener of this.listeners) {\n listener();\n }\n }\n\n /**\n * Replaces the catalog with stories composed from the supplied sources and preview.\n * Only the latest load publishes results; unchanged module identities reuse composed stories.\n * Rejects with an AggregateError after publishing healthy stories when any source fails.\n */\n async load(sources: StorySource[], preview: Preview = EMPTY_PREVIEW): Promise<void> {\n const revision = ++this.revision;\n this.publish({ ...this.snapshot, isLoading: true });\n const loaded = await Promise.all(sources.map((source) => loadSource(source, preview, () => this.cache)));\n\n if (revision !== this.revision) {\n return;\n }\n\n const { cache, stories, errors } = collectSources(loaded);\n this.cache = cache;\n this.sessionError = undefined;\n this.publish({ stories, errors, isLoading: false });\n\n if (errors.length > 0) {\n const failure = new AggregateError(errors.map(({ error }) => error), \"Some stories could not be loaded\");\n this.loadFailures.add(failure);\n throw failure;\n }\n }\n\n /**\n * Replaces the current session failure while preserving source errors and superseding pending loads.\n * Ignores aggregate failures already published by this catalog's load operation.\n */\n reportError(cause: unknown): void {\n if (cause instanceof Error && this.loadFailures.has(cause)) {\n return;\n }\n\n this.revision++;\n const errors = this.snapshot.errors.filter((entry) => entry !== this.sessionError);\n this.sessionError = { source: \"Storybook\", error: normalizeError(cause) };\n this.publish({\n ...this.snapshot,\n isLoading: false,\n errors: [...errors, this.sessionError],\n });\n }\n}\n\nexport { StoryCatalog };\nexport type { StoryCatalogSnapshot, StoryEntry, StoryLoadError, StorySource };\n"]}
|
package/dist/compose.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,aAAa,EACb,eAAe,EACf,aAAa,EACb,OAAO,EACP,gBAAgB,EAChB,WAAW,EACd,MAAM,YAAY,CAAC;AASpB;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,YAAY,GAAI,KAAK,SAAS,MAAM,EACtC,OAAO,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EACvC,MAAM,aAAa,CAAC,KAAK,CAAC,EAC1B,UAAS,OAAY,EACrB,aAAa,MAAM,KACpB,aAAa,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,aAAa,EACb,eAAe,EACf,aAAa,EACb,OAAO,EACP,gBAAgB,EAChB,WAAW,EACd,MAAM,YAAY,CAAC;AASpB;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,YAAY,GAAI,KAAK,SAAS,MAAM,EACtC,OAAO,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EACvC,MAAM,aAAa,CAAC,KAAK,CAAC,EAC1B,UAAS,OAAY,EACrB,aAAa,MAAM,KACpB,aAAa,CAAC,KAAK,CAcrB,CAAC;AAEF;;;;;;;;;GASG;AACH,QAAA,MAAM,cAAc,GAAI,OAAO,SAAS,WAAW,EAC/C,SAAS,OAAO,EAChB,UAAS,OAAY,KACtB,eAAe,CAAC,OAAO,CAqBzB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/compose.js
CHANGED
|
@@ -18,9 +18,6 @@ const requireObject = (value) => {
|
|
|
18
18
|
* @throws If an annotation is not an object or no component or render function is available.
|
|
19
19
|
*/
|
|
20
20
|
const composeStory = (story, meta, preview = {}, exportName) => {
|
|
21
|
-
requireObject(story);
|
|
22
|
-
requireObject(meta);
|
|
23
|
-
requireObject(preview);
|
|
24
21
|
if (!story.render && !meta.render && !preview.render && !meta.component) {
|
|
25
22
|
throw new TypeError("A story needs a component or render function");
|
|
26
23
|
}
|
|
@@ -44,9 +41,7 @@ const composeStory = (story, meta, preview = {}, exportName) => {
|
|
|
44
41
|
* @throws If metadata or a selected export is invalid, or a selected story has no renderer.
|
|
45
42
|
*/
|
|
46
43
|
const composeStories = (stories, preview = {}) => {
|
|
47
|
-
requireObject(stories);
|
|
48
44
|
requireObject(stories.default);
|
|
49
|
-
requireObject(preview);
|
|
50
45
|
const meta = stories.default;
|
|
51
46
|
const composed = {};
|
|
52
47
|
for (const [exportName, story] of Object.entries(stories)) {
|