@storybook/react-native-ui-common 9.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,812 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.tsx
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ Button: () => Button,
33
+ ButtonIcon: () => ButtonIcon,
34
+ ButtonText: () => ButtonText,
35
+ IconButton: () => IconButton,
36
+ LayoutProvider: () => LayoutProvider,
37
+ StorageProvider: () => StorageProvider,
38
+ createId: () => createId,
39
+ cycle: () => cycle,
40
+ get: () => get,
41
+ getAncestorIds: () => getAncestorIds,
42
+ getDescendantIds: () => getDescendantIds,
43
+ getParent: () => getParent,
44
+ getParents: () => getParents,
45
+ getPath: () => getPath,
46
+ getStateType: () => getStateType,
47
+ intersect: () => intersect,
48
+ isAncestor: () => isAncestor,
49
+ isExpandType: () => isExpandType,
50
+ isStoryHoistable: () => isStoryHoistable,
51
+ merge: () => merge,
52
+ noArrayMerge: () => noArrayMerge,
53
+ prevent: () => prevent,
54
+ removeNoiseFromName: () => removeNoiseFromName,
55
+ searchItem: () => searchItem,
56
+ transformStoryIndexToStoriesHash: () => transformStoryIndexToStoriesHash,
57
+ transformStoryIndexV2toV3: () => transformStoryIndexV2toV3,
58
+ transformStoryIndexV3toV4: () => transformStoryIndexV3toV4,
59
+ transformStoryIndexV4toV5: () => transformStoryIndexV4toV5,
60
+ useExpanded: () => useExpanded,
61
+ useLastViewed: () => useLastViewed,
62
+ useLayout: () => useLayout,
63
+ useStorage: () => useStorage,
64
+ useStoreBooleanState: () => useStoreBooleanState,
65
+ useStyle: () => useStyle
66
+ });
67
+ module.exports = __toCommonJS(src_exports);
68
+
69
+ // src/Button.tsx
70
+ var import_react_native_theming = require("@storybook/react-native-theming");
71
+ var import_react = require("react");
72
+ var import_jsx_runtime = require("react/jsx-runtime");
73
+ var Button = (0, import_react.forwardRef)(
74
+ ({
75
+ Icon,
76
+ animation = "none",
77
+ size = "small",
78
+ variant = "outline",
79
+ padding = "medium",
80
+ disabled = false,
81
+ active = false,
82
+ onPress,
83
+ children,
84
+ text,
85
+ ...props
86
+ }, ref) => {
87
+ const [isAnimating, setIsAnimating] = (0, import_react.useState)(false);
88
+ const handleClick = (event) => {
89
+ if (onPress)
90
+ onPress(event);
91
+ if (animation === "none")
92
+ return;
93
+ setIsAnimating(true);
94
+ };
95
+ (0, import_react.useEffect)(() => {
96
+ const timer = setTimeout(() => {
97
+ if (isAnimating)
98
+ setIsAnimating(false);
99
+ }, 1e3);
100
+ return () => clearTimeout(timer);
101
+ }, [isAnimating]);
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
103
+ StyledButton,
104
+ {
105
+ ref,
106
+ variant,
107
+ size,
108
+ padding,
109
+ disabled,
110
+ active,
111
+ animating: isAnimating,
112
+ animation,
113
+ onPress: handleClick,
114
+ ...props,
115
+ children: [
116
+ Icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonIcon, { Icon, variant, active }),
117
+ text && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonText, { variant, active, children: text }),
118
+ children
119
+ ]
120
+ }
121
+ );
122
+ }
123
+ );
124
+ Button.displayName = "Button";
125
+ var StyledButton = import_react_native_theming.styled.TouchableOpacity(({ theme, variant, size, disabled, active, padding }) => ({
126
+ border: 0,
127
+ // cursor: disabled ? 'not-allowed' : 'pointer',
128
+ display: "flex",
129
+ flexDirection: "row",
130
+ gap: 6,
131
+ alignItems: "center",
132
+ justifyContent: "center",
133
+ overflow: "hidden",
134
+ paddingHorizontal: (() => {
135
+ if (padding === "small" && size === "small")
136
+ return 7;
137
+ if (padding === "small" && size === "medium")
138
+ return 9;
139
+ if (size === "small")
140
+ return 10;
141
+ if (size === "medium")
142
+ return 12;
143
+ return 0;
144
+ })(),
145
+ paddingVertical: 0,
146
+ height: size === "small" ? 28 : 32,
147
+ position: "relative",
148
+ transitionProperty: "background, box-shadow",
149
+ transitionDuration: "150ms",
150
+ transitionTimingFunction: "ease-out",
151
+ whiteSpace: "nowrap",
152
+ userSelect: "none",
153
+ opacity: disabled ? 0.5 : 1,
154
+ margin: 0,
155
+ backgroundColor: (() => {
156
+ if (variant === "solid")
157
+ return theme.color.secondary;
158
+ if (variant === "outline")
159
+ return theme.button.background;
160
+ if (variant === "ghost" && active)
161
+ return theme.background.hoverable;
162
+ return "transparent";
163
+ })(),
164
+ boxShadow: variant === "outline" ? `${theme.button.border} 0 0 0 1px inset` : "none",
165
+ borderRadius: theme.input.borderRadius,
166
+ // Making sure that the button never shrinks below its minimum size
167
+ flexShrink: 0
168
+ }));
169
+ var ButtonText = import_react_native_theming.styled.Text(({ theme, variant, active }) => ({
170
+ color: (() => {
171
+ if (variant === "solid")
172
+ return theme.color.lightest;
173
+ if (variant === "outline")
174
+ return theme.input.color;
175
+ if (variant === "ghost" && active)
176
+ return theme.color.secondary;
177
+ if (variant === "ghost")
178
+ return theme.color.mediumdark;
179
+ return theme.input.color;
180
+ })(),
181
+ flexDirection: "row",
182
+ gap: 6,
183
+ textAlign: "center",
184
+ fontSize: theme.typography.size.s1,
185
+ fontWeight: theme.typography.weight.bold
186
+ }));
187
+ var ButtonIcon = ({
188
+ Icon,
189
+ active,
190
+ variant
191
+ }) => {
192
+ const theme = (0, import_react_native_theming.useTheme)();
193
+ const color = (0, import_react.useMemo)(() => {
194
+ if (variant === "solid")
195
+ return theme.color.lightest;
196
+ if (variant === "outline")
197
+ return theme.input.color;
198
+ if (variant === "ghost" && active)
199
+ return theme.color.secondary;
200
+ if (variant === "ghost")
201
+ return theme.color.mediumdark;
202
+ return theme.input.color;
203
+ }, [
204
+ active,
205
+ theme.color.lightest,
206
+ theme.color.mediumdark,
207
+ theme.color.secondary,
208
+ theme.input.color,
209
+ variant
210
+ ]);
211
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { color });
212
+ };
213
+
214
+ // src/IconButton.tsx
215
+ var import_react2 = require("react");
216
+ var import_jsx_runtime2 = require("react/jsx-runtime");
217
+ var IconButton = (0, import_react2.forwardRef)(
218
+ ({ padding = "small", variant = "ghost", ...props }, ref) => {
219
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { padding, variant, ref, ...props });
220
+ }
221
+ );
222
+ IconButton.displayName = "IconButton";
223
+
224
+ // src/LayoutProvider.tsx
225
+ var import_react3 = require("react");
226
+ var import_react_native = require("react-native");
227
+
228
+ // src/constants.ts
229
+ var BREAKPOINT = 1e3;
230
+ var MEDIA_DESKTOP_BREAKPOINT = `@media (min-width: ${BREAKPOINT}px)`;
231
+ var DEFAULT_REF_ID = "storybook_internal";
232
+
233
+ // src/LayoutProvider.tsx
234
+ var import_jsx_runtime3 = require("react/jsx-runtime");
235
+ var LayoutContext = (0, import_react3.createContext)({
236
+ isDesktop: false,
237
+ isMobile: true
238
+ });
239
+ var LayoutProvider = ({ children }) => {
240
+ const { width } = (0, import_react_native.useWindowDimensions)();
241
+ const isDesktop = width >= BREAKPOINT;
242
+ const isMobile = !isDesktop;
243
+ const contextValue = (0, import_react3.useMemo)(
244
+ () => ({
245
+ isDesktop,
246
+ isMobile
247
+ }),
248
+ [isDesktop, isMobile]
249
+ );
250
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LayoutContext.Provider, { value: contextValue, children });
251
+ };
252
+ var useLayout = () => (0, import_react3.useContext)(LayoutContext);
253
+
254
+ // src/types.ts
255
+ function isExpandType(x2) {
256
+ return !!(x2 && x2.showAll);
257
+ }
258
+
259
+ // src/StorageProvider.tsx
260
+ var import_react4 = require("react");
261
+ var import_jsx_runtime4 = require("react/jsx-runtime");
262
+ var StorageContext = (0, import_react4.createContext)({
263
+ getItem: async () => null,
264
+ setItem: async () => {
265
+ }
266
+ });
267
+ var StorageProvider = ({
268
+ storage,
269
+ children
270
+ }) => {
271
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StorageContext.Provider, { value: storage, children });
272
+ };
273
+ var useStorage = () => (0, import_react4.useContext)(StorageContext);
274
+
275
+ // ../../node_modules/@storybook/csf/dist/index.mjs
276
+ var C = Object.create;
277
+ var u = Object.defineProperty;
278
+ var B = Object.getOwnPropertyDescriptor;
279
+ var F = Object.getOwnPropertyNames;
280
+ var h = Object.getPrototypeOf;
281
+ var w = Object.prototype.hasOwnProperty;
282
+ var E = (r, e) => () => (e || r((e = { exports: {} }).exports, e), e.exports);
283
+ var v = (r, e, n, t) => {
284
+ if (e && typeof e == "object" || typeof e == "function")
285
+ for (let a of F(e))
286
+ !w.call(r, a) && a !== n && u(r, a, { get: () => e[a], enumerable: !(t = B(e, a)) || t.enumerable });
287
+ return r;
288
+ };
289
+ var I = (r, e, n) => (n = r != null ? C(h(r)) : {}, v(e || !r || !r.__esModule ? u(n, "default", { value: r, enumerable: true }) : n, r));
290
+ var x = E((T) => {
291
+ Object.defineProperty(T, "__esModule", { value: true }), T.isEqual = function() {
292
+ var r = Object.prototype.toString, e = Object.getPrototypeOf, n = Object.getOwnPropertySymbols ? function(t) {
293
+ return Object.keys(t).concat(Object.getOwnPropertySymbols(t));
294
+ } : Object.keys;
295
+ return function(t, a) {
296
+ return function i(o, s, p) {
297
+ var g, y, d, c = r.call(o), b = r.call(s);
298
+ if (o === s)
299
+ return true;
300
+ if (o == null || s == null)
301
+ return false;
302
+ if (p.indexOf(o) > -1 && p.indexOf(s) > -1)
303
+ return true;
304
+ if (p.push(o, s), c != b || (g = n(o), y = n(s), g.length != y.length || g.some(function(A) {
305
+ return !i(o[A], s[A], p);
306
+ })))
307
+ return false;
308
+ switch (c.slice(8, -1)) {
309
+ case "Symbol":
310
+ return o.valueOf() == s.valueOf();
311
+ case "Date":
312
+ case "Number":
313
+ return +o == +s || +o != +o && +s != +s;
314
+ case "RegExp":
315
+ case "Function":
316
+ case "String":
317
+ case "Boolean":
318
+ return "" + o == "" + s;
319
+ case "Set":
320
+ case "Map":
321
+ g = o.entries(), y = s.entries();
322
+ do
323
+ if (!i((d = g.next()).value, y.next().value, p))
324
+ return false;
325
+ while (!d.done);
326
+ return true;
327
+ case "ArrayBuffer":
328
+ o = new Uint8Array(o), s = new Uint8Array(s);
329
+ case "DataView":
330
+ o = new Uint8Array(o.buffer), s = new Uint8Array(s.buffer);
331
+ case "Float32Array":
332
+ case "Float64Array":
333
+ case "Int8Array":
334
+ case "Int16Array":
335
+ case "Int32Array":
336
+ case "Uint8Array":
337
+ case "Uint16Array":
338
+ case "Uint32Array":
339
+ case "Uint8ClampedArray":
340
+ case "Arguments":
341
+ case "Array":
342
+ if (o.length != s.length)
343
+ return false;
344
+ for (d = 0; d < o.length; d++)
345
+ if ((d in o || d in s) && (d in o != d in s || !i(o[d], s[d], p)))
346
+ return false;
347
+ return true;
348
+ case "Object":
349
+ return i(e(o), e(s), p);
350
+ default:
351
+ return false;
352
+ }
353
+ }(t, a, []);
354
+ };
355
+ }();
356
+ });
357
+ var l = I(x());
358
+ var O = (r) => r.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
359
+
360
+ // src/util/StoryHash.ts
361
+ var import_ts_dedent = require("ts-dedent");
362
+ var import_client_logger = require("storybook/internal/client-logger");
363
+ var import_es_toolkit = require("es-toolkit");
364
+ var intersect = (a, b) => {
365
+ if (!Array.isArray(a) || !Array.isArray(b) || !a.length || !b.length) {
366
+ return [];
367
+ }
368
+ return a.reduce((acc, aValue) => {
369
+ if (b.includes(aValue)) {
370
+ acc.push(aValue);
371
+ }
372
+ return acc;
373
+ }, []);
374
+ };
375
+ var merge = (a, ...b) => {
376
+ let target = {};
377
+ target = (0, import_es_toolkit.mergeWith)(
378
+ {},
379
+ a,
380
+ (objValue, srcValue) => {
381
+ if (Array.isArray(srcValue) && Array.isArray(objValue)) {
382
+ srcValue.forEach((s) => {
383
+ const existing = objValue.find((o) => o === s || (0, import_es_toolkit.isEqual)(o, s));
384
+ if (!existing) {
385
+ objValue.push(s);
386
+ }
387
+ });
388
+ return objValue;
389
+ }
390
+ if (Array.isArray(objValue)) {
391
+ import_client_logger.logger.log(["the types mismatch, picking", objValue]);
392
+ return objValue;
393
+ }
394
+ }
395
+ );
396
+ for (const obj of b) {
397
+ target = (0, import_es_toolkit.mergeWith)(target, obj, (objValue, srcValue) => {
398
+ if (Array.isArray(srcValue) && Array.isArray(objValue)) {
399
+ srcValue.forEach((s) => {
400
+ const existing = objValue.find((o) => o === s || (0, import_es_toolkit.isEqual)(o, s));
401
+ if (!existing) {
402
+ objValue.push(s);
403
+ }
404
+ });
405
+ return objValue;
406
+ }
407
+ if (Array.isArray(objValue)) {
408
+ import_client_logger.logger.log(["the types mismatch, picking", objValue]);
409
+ return objValue;
410
+ }
411
+ });
412
+ }
413
+ return target;
414
+ };
415
+ var noArrayMerge = (a, ...b) => {
416
+ let target = {};
417
+ target = (0, import_es_toolkit.mergeWith)(
418
+ {},
419
+ a,
420
+ (objValue, srcValue) => {
421
+ if (Array.isArray(srcValue)) {
422
+ return srcValue;
423
+ }
424
+ }
425
+ );
426
+ for (const obj of b) {
427
+ target = (0, import_es_toolkit.mergeWith)(target, obj, (objValue, srcValue) => {
428
+ if (Array.isArray(srcValue)) {
429
+ return srcValue;
430
+ }
431
+ });
432
+ }
433
+ return target;
434
+ };
435
+ var TITLE_PATH_SEPARATOR = /\s*\/\s*/;
436
+ var transformStoryIndexToStoriesHash = (input, { provider, docsOptions, filters, allStatuses }) => {
437
+ if (!input.v) {
438
+ throw new Error("Composition: Missing stories.json version");
439
+ }
440
+ let index = input;
441
+ index = index.v === 2 ? transformStoryIndexV2toV3(index) : index;
442
+ index = index.v === 3 ? transformStoryIndexV3toV4(index) : index;
443
+ index = index.v === 4 ? transformStoryIndexV4toV5(index) : index;
444
+ index = index;
445
+ const entryValues = Object.values(index.entries).filter((entry) => {
446
+ let result = true;
447
+ const storyStatuses = allStatuses[entry.id] ?? {};
448
+ if (Object.values(storyStatuses).some(({ value }) => value === "status-value:error")) {
449
+ return result;
450
+ }
451
+ Object.values(filters).forEach((filter) => {
452
+ if (result === false) {
453
+ return;
454
+ }
455
+ result = filter({ ...entry, statuses: storyStatuses });
456
+ });
457
+ return result;
458
+ });
459
+ const { sidebar = {} } = provider.getConfig();
460
+ const { showRoots, collapsedRoots = [], renderLabel } = sidebar;
461
+ const setShowRoots = typeof showRoots !== "undefined";
462
+ const storiesHashOutOfOrder = entryValues.reduce((acc, item) => {
463
+ if (docsOptions.docsMode && item.type !== "docs") {
464
+ return acc;
465
+ }
466
+ const { title } = item;
467
+ const groups = title.trim().split(TITLE_PATH_SEPARATOR);
468
+ const root = (!setShowRoots || showRoots) && groups.length > 1 ? [groups.shift()] : [];
469
+ const names = [...root, ...groups];
470
+ const paths = names.reduce((list, name, idx) => {
471
+ const parent = idx > 0 && list[idx - 1];
472
+ const id = O(parent ? `${parent}-${name}` : name);
473
+ if (name.trim() === "") {
474
+ throw new Error(import_ts_dedent.dedent`Invalid title ${title} ending in slash.`);
475
+ }
476
+ if (parent === id) {
477
+ throw new Error(
478
+ import_ts_dedent.dedent`
479
+ Invalid part '${name}', leading to id === parentId ('${id}'), inside title '${title}'
480
+
481
+ Did you create a path that uses the separator char accidentally, such as 'Vue <docs/>' where '/' is a separator char? See https://github.com/storybookjs/storybook/issues/6128
482
+ `
483
+ );
484
+ }
485
+ list.push(id);
486
+ return list;
487
+ }, []);
488
+ paths.forEach((id, idx) => {
489
+ const childId = paths[idx + 1] || item.id;
490
+ if (root.length && idx === 0) {
491
+ acc[id] = merge(acc[id] || {}, {
492
+ type: "root",
493
+ id,
494
+ name: names[idx],
495
+ tags: [],
496
+ depth: idx,
497
+ renderLabel,
498
+ startCollapsed: collapsedRoots.includes(id),
499
+ // Note that this will later get appended to the previous list of children (see below)
500
+ children: [childId]
501
+ });
502
+ } else if ((!acc[id] || acc[id].type === "component") && idx === paths.length - 1) {
503
+ acc[id] = merge(acc[id] || {}, {
504
+ type: "component",
505
+ id,
506
+ name: names[idx],
507
+ tags: [],
508
+ parent: paths[idx - 1],
509
+ depth: idx,
510
+ renderLabel,
511
+ ...childId && {
512
+ children: [childId]
513
+ }
514
+ });
515
+ } else {
516
+ acc[id] = merge(acc[id] || {}, {
517
+ type: "group",
518
+ id,
519
+ name: names[idx],
520
+ tags: [],
521
+ parent: paths[idx - 1],
522
+ depth: idx,
523
+ renderLabel,
524
+ ...childId && {
525
+ children: [childId]
526
+ }
527
+ });
528
+ }
529
+ });
530
+ acc[item.id] = {
531
+ type: "story",
532
+ tags: [],
533
+ ...item,
534
+ depth: paths.length,
535
+ parent: paths[paths.length - 1],
536
+ renderLabel,
537
+ prepared: !!item.parameters
538
+ };
539
+ return acc;
540
+ }, {});
541
+ function addItem(acc, item) {
542
+ if (acc[item.id]) {
543
+ return acc;
544
+ }
545
+ acc[item.id] = item;
546
+ if (item.type === "root" || item.type === "group" || item.type === "component") {
547
+ item.children.forEach((childId) => addItem(acc, storiesHashOutOfOrder[childId]));
548
+ item.tags = item.children.reduce((currentTags, childId) => {
549
+ const child = acc[childId];
550
+ return currentTags === null ? child.tags : intersect(currentTags, child.tags);
551
+ }, null);
552
+ }
553
+ return acc;
554
+ }
555
+ const orphanHash = Object.values(storiesHashOutOfOrder).filter((i) => i.type !== "root" && !i.parent).reduce(addItem, {});
556
+ return Object.values(storiesHashOutOfOrder).filter((i) => i.type === "root").reduce(addItem, orphanHash);
557
+ };
558
+ var transformStoryIndexV2toV3 = (index) => {
559
+ return {
560
+ v: 3,
561
+ stories: Object.values(index.stories).reduce(
562
+ (acc, entry) => {
563
+ acc[entry.id] = {
564
+ ...entry,
565
+ title: entry.kind,
566
+ name: entry.name || entry.story,
567
+ importPath: entry.parameters.fileName || ""
568
+ };
569
+ return acc;
570
+ },
571
+ {}
572
+ )
573
+ };
574
+ };
575
+ var transformStoryIndexV3toV4 = (index) => {
576
+ const countByTitle = (0, import_es_toolkit.countBy)(Object.values(index.stories), (item) => item.title);
577
+ return {
578
+ v: 4,
579
+ entries: Object.values(index.stories).reduce(
580
+ (acc, entry) => {
581
+ let type = "story";
582
+ if (entry.parameters?.docsOnly || entry.name === "Page" && countByTitle[entry.title] === 1) {
583
+ type = "docs";
584
+ }
585
+ acc[entry.id] = {
586
+ type,
587
+ ...type === "docs" && { tags: ["stories-mdx"], storiesImports: [] },
588
+ ...entry
589
+ };
590
+ delete acc[entry.id].story;
591
+ delete acc[entry.id].kind;
592
+ return acc;
593
+ },
594
+ {}
595
+ )
596
+ };
597
+ };
598
+ var transformStoryIndexV4toV5 = (index) => {
599
+ return {
600
+ v: 5,
601
+ entries: Object.values(index.entries).reduce(
602
+ (acc, entry) => {
603
+ acc[entry.id] = {
604
+ ...entry,
605
+ tags: entry.tags ? ["dev", "test", ...entry.tags] : ["dev"]
606
+ };
607
+ return acc;
608
+ },
609
+ {}
610
+ )
611
+ };
612
+ };
613
+
614
+ // src/util/tree.ts
615
+ var import_memoizerific = __toESM(require("memoizerific"));
616
+ var createId = (itemId, refId) => !refId || refId === DEFAULT_REF_ID ? itemId : `${refId}_${itemId}`;
617
+ var prevent = (e) => {
618
+ e.preventDefault();
619
+ return false;
620
+ };
621
+ var get = (0, import_memoizerific.default)(1e3)((id, dataset) => dataset[id]);
622
+ var getParent = (0, import_memoizerific.default)(1e3)((id, dataset) => {
623
+ const item = get(id, dataset);
624
+ return item && item.type !== "root" ? get(item.parent, dataset) : void 0;
625
+ });
626
+ var getParents = (0, import_memoizerific.default)(1e3)((id, dataset) => {
627
+ const parent = getParent(id, dataset);
628
+ return parent ? [parent, ...getParents(parent.id, dataset)] : [];
629
+ });
630
+ var getAncestorIds = (0, import_memoizerific.default)(1e3)(
631
+ (data, id) => getParents(id, data).map((item) => item.id)
632
+ );
633
+ var getDescendantIds = (0, import_memoizerific.default)(1e3)((data, id, skipLeafs) => {
634
+ const entry = data[id];
635
+ const children = entry.type === "story" || entry.type === "docs" ? [] : entry.children;
636
+ return children.reduce((acc, childId) => {
637
+ const child = data[childId];
638
+ if (!child || skipLeafs && (child.type === "story" || child.type === "docs"))
639
+ return acc;
640
+ acc.push(childId, ...getDescendantIds(data, childId, skipLeafs));
641
+ return acc;
642
+ }, []);
643
+ });
644
+ function getPath(item, ref) {
645
+ const parent = item.type !== "root" && item.parent ? ref.index[item.parent] : null;
646
+ if (parent)
647
+ return [...getPath(parent, ref), parent.name];
648
+ return ref.id === DEFAULT_REF_ID ? [] : [ref.title || ref.id];
649
+ }
650
+ var searchItem = (item, ref) => {
651
+ return { ...item, refId: ref.id, path: getPath(item, ref) };
652
+ };
653
+ function cycle(array, index, delta) {
654
+ let next = index + delta % array.length;
655
+ if (next < 0)
656
+ next = array.length + next;
657
+ if (next >= array.length)
658
+ next -= array.length;
659
+ return next;
660
+ }
661
+ var getStateType = (isLoading, isAuthRequired, isError, isEmpty) => {
662
+ switch (true) {
663
+ case isAuthRequired:
664
+ return "auth";
665
+ case isError:
666
+ return "error";
667
+ case isLoading:
668
+ return "loading";
669
+ case isEmpty:
670
+ return "empty";
671
+ default:
672
+ return "ready";
673
+ }
674
+ };
675
+ var isAncestor = (element, maybeAncestor) => {
676
+ if (!element || !maybeAncestor)
677
+ return false;
678
+ if (element === maybeAncestor)
679
+ return true;
680
+ return isAncestor(element.parentElement, maybeAncestor);
681
+ };
682
+ var removeNoiseFromName = (storyName) => storyName.replaceAll(/(\s|-|_)/gi, "");
683
+ var isStoryHoistable = (storyName, componentName) => removeNoiseFromName(storyName) === removeNoiseFromName(componentName);
684
+
685
+ // src/util/useStyle.ts
686
+ var import_react5 = require("react");
687
+ var useStyle = (styleFactory, deps) => (
688
+ // eslint-disable-next-line react-hooks/exhaustive-deps
689
+ (0, import_react5.useMemo)(styleFactory, deps)
690
+ );
691
+
692
+ // src/hooks/useExpanded.ts
693
+ var import_react6 = require("react");
694
+ var initializeExpanded = ({
695
+ initialExpanded,
696
+ rootIds
697
+ }) => {
698
+ const highlightedAncestors = [];
699
+ return [...rootIds, ...highlightedAncestors].reduce(
700
+ (acc, id) => Object.assign(acc, { [id]: id in initialExpanded ? initialExpanded[id] : true }),
701
+ {}
702
+ );
703
+ };
704
+ var useExpanded = ({
705
+ refId,
706
+ data,
707
+ initialExpanded,
708
+ rootIds,
709
+ selectedStoryId
710
+ }) => {
711
+ const [expanded, setExpanded] = (0, import_react6.useReducer)(
712
+ (state, { ids, value }) => ids.reduce((acc, id) => Object.assign(acc, { [id]: value }), { ...state }),
713
+ { refId, data, rootIds, initialExpanded },
714
+ initializeExpanded
715
+ );
716
+ const updateExpanded = (0, import_react6.useCallback)(({ ids, value }) => {
717
+ setExpanded({ ids, value });
718
+ }, []);
719
+ (0, import_react6.useEffect)(() => {
720
+ setExpanded({ ids: getAncestorIds(data, selectedStoryId), value: true });
721
+ }, [data, selectedStoryId]);
722
+ return [expanded, updateExpanded];
723
+ };
724
+
725
+ // src/hooks/useLastViewed.ts
726
+ var import_react7 = require("react");
727
+ var useLastViewed = (selection) => {
728
+ const lastViewedRef = (0, import_react7.useRef)([]);
729
+ const updateLastViewed = (0, import_react7.useCallback)(
730
+ (story) => {
731
+ const items = lastViewedRef.current;
732
+ const index = items.findIndex(
733
+ ({ storyId, refId }) => storyId === story.storyId && refId === story.refId
734
+ );
735
+ if (index === 0)
736
+ return;
737
+ if (index === -1) {
738
+ lastViewedRef.current = [story, ...items];
739
+ } else {
740
+ lastViewedRef.current = [story, ...items.slice(0, index), ...items.slice(index + 1)];
741
+ }
742
+ },
743
+ [lastViewedRef]
744
+ );
745
+ (0, import_react7.useEffect)(() => {
746
+ if (selection)
747
+ updateLastViewed(selection);
748
+ }, [selection]);
749
+ return {
750
+ getLastViewed: (0, import_react7.useCallback)(() => lastViewedRef.current, [lastViewedRef]),
751
+ clearLastViewed: (0, import_react7.useCallback)(() => {
752
+ lastViewedRef.current = lastViewedRef.current.slice(0, 1);
753
+ }, [lastViewedRef])
754
+ };
755
+ };
756
+
757
+ // src/hooks/useStoreState.ts
758
+ var import_react8 = require("react");
759
+ var useStoreBooleanState = (key, defaultValue) => {
760
+ const storage = useStorage();
761
+ const [val, setVal] = (0, import_react8.useState)(defaultValue);
762
+ (0, import_react8.useEffect)(() => {
763
+ storage.getItem(key).then((newVal) => {
764
+ if (newVal === null || newVal === void 0) {
765
+ setVal(defaultValue);
766
+ } else {
767
+ setVal(newVal === "true");
768
+ }
769
+ });
770
+ }, [key, storage, defaultValue]);
771
+ (0, import_react8.useEffect)(() => {
772
+ storage.setItem(key, val.toString());
773
+ }, [key, storage, val]);
774
+ return [val, setVal];
775
+ };
776
+ // Annotate the CommonJS export names for ESM import in node:
777
+ 0 && (module.exports = {
778
+ Button,
779
+ ButtonIcon,
780
+ ButtonText,
781
+ IconButton,
782
+ LayoutProvider,
783
+ StorageProvider,
784
+ createId,
785
+ cycle,
786
+ get,
787
+ getAncestorIds,
788
+ getDescendantIds,
789
+ getParent,
790
+ getParents,
791
+ getPath,
792
+ getStateType,
793
+ intersect,
794
+ isAncestor,
795
+ isExpandType,
796
+ isStoryHoistable,
797
+ merge,
798
+ noArrayMerge,
799
+ prevent,
800
+ removeNoiseFromName,
801
+ searchItem,
802
+ transformStoryIndexToStoriesHash,
803
+ transformStoryIndexV2toV3,
804
+ transformStoryIndexV3toV4,
805
+ transformStoryIndexV4toV5,
806
+ useExpanded,
807
+ useLastViewed,
808
+ useLayout,
809
+ useStorage,
810
+ useStoreBooleanState,
811
+ useStyle
812
+ });