@jsb188/react 1.1.1 → 1.1.2
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/libs/README.md +75 -0
- package/libs/page-filters.helpers.ts +65 -0
- package/libs/page-filters.ts +223 -0
- package/libs/use-page-filters.ts +147 -0
- package/package.json +24 -19
- package/states/apiData.ts +18 -14
- package/states/appContext.ts +423 -1
- package/states/connected.ts +135 -11
- package/states/index.ts +4 -0
- package/states/keyDown.ts +167 -0
- package/states/keyboardLayer.ts +57 -0
- package/states/modal.ts +403 -239
- package/states/popOver.ts +394 -178
- package/states/reactiveEvents.ts +99 -0
- package/states/uploads.ts +70 -0
- package/types/PopOver.d.ts +636 -88
- package/utils/hooks.ts +406 -234
- package/utils/lazy.ts +183 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ReactiveMessageObj,
|
|
3
|
+
WSDataUpdateObj,
|
|
4
|
+
} from '@jsb188/app/types/app.d.ts';
|
|
5
|
+
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Types; reactive events
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type ReactiveEventObj = ReactiveMessageObj & {
|
|
12
|
+
id: string;
|
|
13
|
+
seen?: boolean;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type ReactiveEventInput = Pick<WSDataUpdateObj, 'id' | 'messages'> & {
|
|
18
|
+
timestamp?: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Expand one websocket update's messages into independently rendered history rows.
|
|
23
|
+
*/
|
|
24
|
+
function makeReactiveEventRows(
|
|
25
|
+
reactiveEvent: ReactiveEventInput,
|
|
26
|
+
): ReactiveEventObj[] {
|
|
27
|
+
const timestamp = reactiveEvent.timestamp ?? Date.now();
|
|
28
|
+
|
|
29
|
+
return (reactiveEvent.messages || []).map((message, index) => ({
|
|
30
|
+
...message,
|
|
31
|
+
id: `${reactiveEvent.id}:${timestamp}:${index}`,
|
|
32
|
+
timestamp,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reactive event state
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
const reactiveEventState = atom<ReactiveEventObj[]>([]);
|
|
41
|
+
const hasUnseenReactiveEventState = atom((get) =>
|
|
42
|
+
get(reactiveEventState).some((reactiveEvent) => !reactiveEvent.seen),
|
|
43
|
+
);
|
|
44
|
+
const setReactiveEventState = atom(
|
|
45
|
+
null,
|
|
46
|
+
(_get, set, reactiveEvent: ReactiveEventInput) => {
|
|
47
|
+
const savedReactiveEvents = makeReactiveEventRows(reactiveEvent);
|
|
48
|
+
if (!savedReactiveEvents.length) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
set(reactiveEventState, (reactiveEvents) =>
|
|
53
|
+
[...savedReactiveEvents, ...reactiveEvents].slice(0, 50),
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
const markReactiveEventsSeenState = atom(null, (get, set) => {
|
|
58
|
+
const reactiveEvents = get(reactiveEventState);
|
|
59
|
+
if (reactiveEvents.some((reactiveEvent) => !reactiveEvent.seen)) {
|
|
60
|
+
set(
|
|
61
|
+
reactiveEventState,
|
|
62
|
+
reactiveEvents.map((reactiveEvent) =>
|
|
63
|
+
reactiveEvent.seen ? reactiveEvent : { ...reactiveEvent, seen: true },
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Return all reactive events from newest to oldest.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
export function useReactiveEvents() {
|
|
74
|
+
return useAtomValue(reactiveEventState);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Return whether the capped event history contains an unseen event.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
export function useHasUnseenReactiveEvent() {
|
|
82
|
+
return useAtomValue(hasUnseenReactiveEventState);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Return the setter that marks the current event history as seen.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export function useMarkReactiveEventsSeen() {
|
|
90
|
+
return useSetAtom(markReactiveEventsSeenState);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Return the setter that prepends one reactive event to the capped history.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
export function useSetReactiveEvent() {
|
|
98
|
+
return useSetAtom(setReactiveEventState);
|
|
99
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface UploadEntry {
|
|
9
|
+
progress: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type UploadsMap = Record<string, UploadEntry>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Uploads; state
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const uploadsState = atom<UploadsMap>({});
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Export; get uploads state value
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function useUploadsValue() {
|
|
25
|
+
return useAtomValue(uploadsState);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Export; upload state helpers
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export function useUploadActions() {
|
|
33
|
+
const setUploads = useSetAtom(uploadsState);
|
|
34
|
+
|
|
35
|
+
const startUploadProgress = useCallback(
|
|
36
|
+
(signedUrl: string) => {
|
|
37
|
+
setUploads((prev) => ({
|
|
38
|
+
...prev,
|
|
39
|
+
[signedUrl]: { progress: 0 },
|
|
40
|
+
}));
|
|
41
|
+
},
|
|
42
|
+
[setUploads],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const updateUploadProgress = useCallback(
|
|
46
|
+
(signedUrl: string, progress: number) => {
|
|
47
|
+
setUploads((prev) => ({
|
|
48
|
+
...prev,
|
|
49
|
+
[signedUrl]: { progress },
|
|
50
|
+
}));
|
|
51
|
+
},
|
|
52
|
+
[setUploads],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const removeUploadProgress = useCallback(
|
|
56
|
+
(signedUrl: string) => {
|
|
57
|
+
setUploads((prev) => {
|
|
58
|
+
const { [signedUrl]: _, ...rest } = prev;
|
|
59
|
+
return rest;
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
[setUploads],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
startUploadProgress,
|
|
67
|
+
updateUploadProgress,
|
|
68
|
+
removeUploadProgress,
|
|
69
|
+
};
|
|
70
|
+
}
|