@storybook/react-native-ui-common 10.2.1 → 10.2.2-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -3
- package/dist/index.js +27 -0
- package/package.json +5 -5
- package/src/hooks/useStoreState.ts +34 -1
- package/src/types.ts +13 -3
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import * as react_native from 'react-native';
|
|
|
7
7
|
import { TouchableOpacityProps, PressableProps, ViewStyle, TextStyle, ImageStyle, StyleProp } from 'react-native';
|
|
8
8
|
import { StoryContext, Args } from 'storybook/internal/csf';
|
|
9
9
|
import { ReactRenderer } from '@storybook/react';
|
|
10
|
-
import * as Fuse from 'fuse.js';
|
|
11
10
|
import { State, StoriesHash, API, IndexHash } from 'storybook/manager-api';
|
|
12
11
|
import { StatusesByStoryIdAndTypeId, StatusValue, API_IndexHash, API_PreparedStoryIndex, StoryIndexV2, StoryIndexV3, API_Provider, DocsOptions } from 'storybook/internal/types';
|
|
13
12
|
|
|
@@ -60,6 +59,8 @@ declare const StorageProvider: FC<PropsWithChildren<{
|
|
|
60
59
|
}>>;
|
|
61
60
|
declare const useStorage: () => Storage;
|
|
62
61
|
|
|
62
|
+
type HighlightRange = [number, number];
|
|
63
|
+
type HighlightRanges = HighlightRange[];
|
|
63
64
|
type Refs = State['refs'];
|
|
64
65
|
type RefType = Refs[keyof Refs] & {
|
|
65
66
|
allStatuses?: StatusesByStoryIdAndTypeId;
|
|
@@ -92,7 +93,11 @@ type SearchItem = Item & {
|
|
|
92
93
|
status?: StatusValue;
|
|
93
94
|
showAll?: () => void;
|
|
94
95
|
};
|
|
95
|
-
|
|
96
|
+
interface SearchResult {
|
|
97
|
+
item: SearchItem;
|
|
98
|
+
score: number | null;
|
|
99
|
+
matches: HighlightRanges[];
|
|
100
|
+
}
|
|
96
101
|
type SearchResultProps = SearchResult & {
|
|
97
102
|
icon: string;
|
|
98
103
|
isHighlighted: boolean;
|
|
@@ -188,5 +193,6 @@ declare const useLastViewed: (selection: Selection) => {
|
|
|
188
193
|
};
|
|
189
194
|
|
|
190
195
|
declare const useStoreBooleanState: (key: string, defaultValue: boolean) => ReturnType<typeof useState<boolean>>;
|
|
196
|
+
declare const useStoreNumberState: (key: string, defaultValue: number) => [number, (value: number | ((prev: number) => number)) => void];
|
|
191
197
|
|
|
192
|
-
export { Button, ButtonIcon, type ButtonProps, ButtonText, type CombinedDataset, type Dataset, type ExpandAction, type ExpandType, type ExpandedProps, type ExpandedState, type GetSearchItemProps, type Highlight, IconButton, type Item, type ItemRef, LayoutProvider, type RefType, type Refs, type SBUI, type SearchChildrenFn, type SearchItem, type SearchResult, type SearchResultProps, type Selection, type Storage, StorageProvider, type StoryRef, createId, cycle, get, getAncestorIds, getDescendantIds, getParent, getParents, getPath, getStateType, intersect, isAncestor, isExpandType, isStoryHoistable, merge, noArrayMerge, prevent, removeNoiseFromName, searchItem, transformStoryIndexToStoriesHash, transformStoryIndexV2toV3, transformStoryIndexV3toV4, transformStoryIndexV4toV5, useExpanded, useLastViewed, useLayout, useStorage, useStoreBooleanState, useStyle };
|
|
198
|
+
export { Button, ButtonIcon, type ButtonProps, ButtonText, type CombinedDataset, type Dataset, type ExpandAction, type ExpandType, type ExpandedProps, type ExpandedState, type GetSearchItemProps, type Highlight, type HighlightRange, type HighlightRanges, IconButton, type Item, type ItemRef, LayoutProvider, type RefType, type Refs, type SBUI, type SearchChildrenFn, type SearchItem, type SearchResult, type SearchResultProps, type Selection, type Storage, StorageProvider, type StoryRef, createId, cycle, get, getAncestorIds, getDescendantIds, getParent, getParents, getPath, getStateType, intersect, isAncestor, isExpandType, isStoryHoistable, merge, noArrayMerge, prevent, removeNoiseFromName, searchItem, transformStoryIndexToStoriesHash, transformStoryIndexV2toV3, transformStoryIndexV3toV4, transformStoryIndexV4toV5, useExpanded, useLastViewed, useLayout, useStorage, useStoreBooleanState, useStoreNumberState, useStyle };
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
useLayout: () => useLayout,
|
|
63
63
|
useStorage: () => useStorage,
|
|
64
64
|
useStoreBooleanState: () => useStoreBooleanState,
|
|
65
|
+
useStoreNumberState: () => useStoreNumberState,
|
|
65
66
|
useStyle: () => useStyle
|
|
66
67
|
});
|
|
67
68
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -664,6 +665,31 @@ var useStoreBooleanState = (key, defaultValue) => {
|
|
|
664
665
|
}, [key, storage, val]);
|
|
665
666
|
return [val, setVal];
|
|
666
667
|
};
|
|
668
|
+
var useStoreNumberState = (key, defaultValue) => {
|
|
669
|
+
const storage = useStorage();
|
|
670
|
+
const [val, setVal] = (0, import_react8.useState)(defaultValue);
|
|
671
|
+
(0, import_react8.useEffect)(() => {
|
|
672
|
+
storage.getItem(key).then((newVal) => {
|
|
673
|
+
if (newVal === null || newVal === void 0) {
|
|
674
|
+
setVal(defaultValue);
|
|
675
|
+
} else {
|
|
676
|
+
const parsed = parseFloat(newVal);
|
|
677
|
+
setVal(isNaN(parsed) ? defaultValue : parsed);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}, [key, storage, defaultValue]);
|
|
681
|
+
const setAndStore = (0, import_react8.useCallback)(
|
|
682
|
+
(value) => {
|
|
683
|
+
setVal((prev) => {
|
|
684
|
+
const next = typeof value === "function" ? value(prev) : value;
|
|
685
|
+
storage.setItem(key, next.toString());
|
|
686
|
+
return next;
|
|
687
|
+
});
|
|
688
|
+
},
|
|
689
|
+
[key, storage]
|
|
690
|
+
);
|
|
691
|
+
return [val, setAndStore];
|
|
692
|
+
};
|
|
667
693
|
// Annotate the CommonJS export names for ESM import in node:
|
|
668
694
|
0 && (module.exports = {
|
|
669
695
|
Button,
|
|
@@ -699,5 +725,6 @@ var useStoreBooleanState = (key, defaultValue) => {
|
|
|
699
725
|
useLayout,
|
|
700
726
|
useStorage,
|
|
701
727
|
useStoreBooleanState,
|
|
728
|
+
useStoreNumberState,
|
|
702
729
|
useStyle
|
|
703
730
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native-ui-common",
|
|
3
|
-
"version": "10.2.1",
|
|
3
|
+
"version": "10.2.2-alpha.1",
|
|
4
4
|
"description": "common ui components for react native storybook",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"typescript": "~5.9.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@storybook/react
|
|
40
|
+
"@nozbe/microfuzz": "^1.0.0",
|
|
41
|
+
"@storybook/react": "^10.2.2",
|
|
42
|
+
"@storybook/react-native-theming": "^10.2.2-alpha.1",
|
|
42
43
|
"es-toolkit": "^1.41.0",
|
|
43
|
-
"fuse.js": "^7.1.0",
|
|
44
44
|
"memoizerific": "^1.11.3",
|
|
45
45
|
"ts-dedent": "^2.2.0"
|
|
46
46
|
},
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "900db1ac2a226eb8206cc89b7142d1ea50272a9e"
|
|
59
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { useStorage } from '../StorageProvider';
|
|
3
3
|
|
|
4
4
|
export const useStoreBooleanState = (
|
|
@@ -25,3 +25,36 @@ export const useStoreBooleanState = (
|
|
|
25
25
|
|
|
26
26
|
return [val, setVal];
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export const useStoreNumberState = (
|
|
30
|
+
key: string,
|
|
31
|
+
defaultValue: number
|
|
32
|
+
): [number, (value: number | ((prev: number) => number)) => void] => {
|
|
33
|
+
const storage = useStorage();
|
|
34
|
+
|
|
35
|
+
const [val, setVal] = useState<number>(defaultValue);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
storage.getItem(key).then((newVal) => {
|
|
39
|
+
if (newVal === null || newVal === undefined) {
|
|
40
|
+
setVal(defaultValue);
|
|
41
|
+
} else {
|
|
42
|
+
const parsed = parseFloat(newVal);
|
|
43
|
+
setVal(isNaN(parsed) ? defaultValue : parsed);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}, [key, storage, defaultValue]);
|
|
47
|
+
|
|
48
|
+
const setAndStore = useCallback(
|
|
49
|
+
(value: number | ((prev: number) => number)) => {
|
|
50
|
+
setVal((prev) => {
|
|
51
|
+
const next = typeof value === 'function' ? value(prev) : value;
|
|
52
|
+
storage.setItem(key, next.toString());
|
|
53
|
+
return next;
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
[key, storage]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return [val, setAndStore];
|
|
60
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Args, StoryContext } from 'storybook/internal/csf';
|
|
|
2
2
|
import type { ReactRenderer } from '@storybook/react';
|
|
3
3
|
import { Theme } from '@storybook/react-native-theming';
|
|
4
4
|
import { Storage } from './StorageProvider';
|
|
5
|
-
import * as Fuse from 'fuse.js';
|
|
6
5
|
import { ReactElement, ReactNode } from 'react';
|
|
7
6
|
import { PressableProps } from 'react-native';
|
|
8
7
|
import type { State, StoriesHash } from 'storybook/manager-api';
|
|
@@ -12,6 +11,11 @@ import type {
|
|
|
12
11
|
StatusValue,
|
|
13
12
|
} from 'storybook/internal/types';
|
|
14
13
|
|
|
14
|
+
// Microfuzz highlight range: [startIndex, endIndex] (inclusive)
|
|
15
|
+
export type HighlightRange = [number, number];
|
|
16
|
+
// Array of highlight ranges per getText field
|
|
17
|
+
export type HighlightRanges = HighlightRange[];
|
|
18
|
+
|
|
15
19
|
export type Refs = State['refs'];
|
|
16
20
|
export type RefType = Refs[keyof Refs] & { allStatuses?: StatusesByStoryIdAndTypeId };
|
|
17
21
|
export type Item = StoriesHash[keyof StoriesHash];
|
|
@@ -51,7 +55,13 @@ export type SearchItem = Item & {
|
|
|
51
55
|
showAll?: () => void;
|
|
52
56
|
};
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
// Native microfuzz result format
|
|
59
|
+
export interface SearchResult {
|
|
60
|
+
item: SearchItem;
|
|
61
|
+
score: number | null;
|
|
62
|
+
// matches[0] = name highlights, matches[1] = path highlights
|
|
63
|
+
matches: HighlightRanges[];
|
|
64
|
+
}
|
|
55
65
|
|
|
56
66
|
export type SearchResultProps = SearchResult & {
|
|
57
67
|
icon: string;
|
|
@@ -67,7 +77,7 @@ export type GetSearchItemProps = (args: {
|
|
|
67
77
|
|
|
68
78
|
export type SearchChildrenFn = (args: {
|
|
69
79
|
query: string;
|
|
70
|
-
results: SearchResult[];
|
|
80
|
+
results: SearchResult[];
|
|
71
81
|
isBrowsing: boolean;
|
|
72
82
|
closeMenu: (cb?: () => void) => void;
|
|
73
83
|
getItemProps: GetSearchItemProps;
|