@stackflow/plugin-basic-ui 1.8.4 → 1.9.0

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.
Files changed (66) hide show
  1. package/dist/components/AppBar.d.ts.map +1 -1
  2. package/dist/components/AppScreen.d.ts +2 -0
  3. package/dist/components/AppScreen.d.ts.map +1 -1
  4. package/dist/components/BottomSheet.d.ts.map +1 -1
  5. package/dist/components/Modal.d.ts.map +1 -1
  6. package/dist/hooks/index.d.ts +0 -2
  7. package/dist/hooks/useLazy.d.ts +0 -1
  8. package/dist/hooks/useMaxWidth.d.ts +0 -1
  9. package/dist/hooks/useMounted.d.ts +0 -1
  10. package/dist/hooks/useNullableActivity.d.ts +0 -1
  11. package/dist/hooks/useStyleEffect.d.ts +0 -1
  12. package/dist/hooks/useStyleEffectHide.d.ts +0 -1
  13. package/dist/hooks/useStyleEffectOffset.d.ts +0 -1
  14. package/dist/hooks/useStyleEffectSwipeBack.d.ts +0 -1
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +111 -518
  18. package/dist/index.js.map +4 -4
  19. package/dist/index.mjs +94 -480
  20. package/dist/index.mjs.map +4 -4
  21. package/dist/utils/index.d.ts +0 -5
  22. package/dist/utils/index.d.ts.map +1 -1
  23. package/dist/utils/last.d.ts +0 -1
  24. package/dist/utils/listenOnce.d.ts +0 -1
  25. package/dist/utils/listenResize.d.ts +0 -1
  26. package/dist/utils/noop.d.ts +0 -1
  27. package/dist/utils/requestNextFrame.d.ts +0 -1
  28. package/package.json +3 -2
  29. package/src/components/AppBar.tsx +6 -2
  30. package/src/components/AppScreen.css.ts +4 -4
  31. package/src/components/AppScreen.tsx +52 -14
  32. package/src/components/BottomSheet.tsx +3 -3
  33. package/src/components/Modal.tsx +3 -3
  34. package/src/index.ts +0 -1
  35. package/src/utils/index.ts +0 -5
  36. package/dist/hooks/index.d.ts.map +0 -1
  37. package/dist/hooks/useLazy.d.ts.map +0 -1
  38. package/dist/hooks/useMaxWidth.d.ts.map +0 -1
  39. package/dist/hooks/useMounted.d.ts.map +0 -1
  40. package/dist/hooks/useNullableActivity.d.ts.map +0 -1
  41. package/dist/hooks/useStyleEffect.d.ts.map +0 -1
  42. package/dist/hooks/useStyleEffectHide.d.ts.map +0 -1
  43. package/dist/hooks/useStyleEffectOffset.d.ts.map +0 -1
  44. package/dist/hooks/useStyleEffectSwipeBack.d.ts.map +0 -1
  45. package/dist/hooks/useZIndexBase.d.ts +0 -2
  46. package/dist/hooks/useZIndexBase.d.ts.map +0 -1
  47. package/dist/utils/last.d.ts.map +0 -1
  48. package/dist/utils/listenOnce.d.ts.map +0 -1
  49. package/dist/utils/listenResize.d.ts.map +0 -1
  50. package/dist/utils/noop.d.ts.map +0 -1
  51. package/dist/utils/requestNextFrame.d.ts.map +0 -1
  52. package/src/hooks/index.ts +0 -9
  53. package/src/hooks/useLazy.tsx +0 -15
  54. package/src/hooks/useMaxWidth.ts +0 -42
  55. package/src/hooks/useMounted.ts +0 -11
  56. package/src/hooks/useNullableActivity.ts +0 -6
  57. package/src/hooks/useStyleEffect.ts +0 -85
  58. package/src/hooks/useStyleEffectHide.ts +0 -51
  59. package/src/hooks/useStyleEffectOffset.ts +0 -100
  60. package/src/hooks/useStyleEffectSwipeBack.ts +0 -251
  61. package/src/hooks/useZIndexBase.ts +0 -6
  62. package/src/utils/last.ts +0 -1
  63. package/src/utils/listenOnce.ts +0 -12
  64. package/src/utils/listenResize.ts +0 -8
  65. package/src/utils/noop.ts +0 -1
  66. package/src/utils/requestNextFrame.tsx +0 -8
@@ -1,251 +0,0 @@
1
- import { globalVars } from "../basicUIPlugin.css";
2
- import * as appScreenCss from "../components/AppScreen.css";
3
- import { listenOnce, noop } from "../utils";
4
- import { useStyleEffect } from "./useStyleEffect";
5
- import { OFFSET_PX_CUPERTINO } from "./useStyleEffectOffset";
6
-
7
- export function useStyleEffectSwipeBack({
8
- theme,
9
- dimRef,
10
- edgeRef,
11
- paperRef,
12
- hasEffect,
13
- prevented,
14
- onSwiped,
15
- }: {
16
- theme: "android" | "cupertino";
17
- dimRef: React.RefObject<HTMLDivElement>;
18
- edgeRef: React.RefObject<HTMLDivElement>;
19
- paperRef: React.RefObject<HTMLDivElement>;
20
- hasEffect?: boolean;
21
- prevented?: boolean;
22
- onSwiped?: () => void;
23
- }) {
24
- useStyleEffect({
25
- styleName: "swipe-back",
26
- refs: [paperRef],
27
- effect: hasEffect
28
- ? ({ refs }) => {
29
- if (theme !== "cupertino") {
30
- return noop;
31
- }
32
-
33
- if (!dimRef.current || !edgeRef.current || !paperRef.current) {
34
- return noop;
35
- }
36
-
37
- const $dim = dimRef.current;
38
- const $edge = edgeRef.current;
39
- const $paper = paperRef.current;
40
-
41
- let x0: number | null = null;
42
- let t0: number | null = null;
43
- let x: number | null = null;
44
-
45
- let cachedRefs: Array<{
46
- style: {
47
- transform: string;
48
- transition: string;
49
- };
50
- parentElement?: {
51
- style: {
52
- display: string;
53
- };
54
- };
55
- }> = [];
56
-
57
- const resetState = () => {
58
- x0 = null;
59
- t0 = null;
60
- x = null;
61
- cachedRefs = [];
62
- };
63
-
64
- let _rAFLock = false;
65
-
66
- function movePaper(dx: number) {
67
- if (!_rAFLock) {
68
- _rAFLock = true;
69
-
70
- requestAnimationFrame(() => {
71
- const p = dx / $paper.clientWidth;
72
-
73
- $dim.style.opacity = `${1 - p}`;
74
- $dim.style.transition = "0s";
75
-
76
- $paper.style.overflowY = "hidden";
77
- $paper.style.transform = `translate3d(${dx}px, 0, 0)`;
78
- $paper.style.transition = "0s";
79
-
80
- refs.forEach((ref) => {
81
- if (!ref.current) {
82
- return;
83
- }
84
-
85
- ref.current.style.transform = `translate3d(${
86
- -1 * (1 - p) * OFFSET_PX_CUPERTINO
87
- }px, 0, 0)`;
88
- ref.current.style.transition = "0s";
89
-
90
- if (ref.current.parentElement?.style.display === "none") {
91
- ref.current.parentElement.style.display = "block";
92
- }
93
- });
94
-
95
- _rAFLock = false;
96
- });
97
- }
98
- }
99
-
100
- function resetPaper({ swiped }: { swiped: boolean }): Promise<void> {
101
- return new Promise((resolve) => {
102
- requestAnimationFrame(() => {
103
- $dim.style.opacity = `${swiped ? 0 : 1}`;
104
- $dim.style.transition = globalVars.transitionDuration;
105
-
106
- $paper.style.overflowY = "hidden";
107
- $paper.style.transform = `translateX(${swiped ? "100%" : "0"})`;
108
- $paper.style.transition = globalVars.transitionDuration;
109
-
110
- refs.forEach((ref) => {
111
- if (!ref.current) {
112
- return;
113
- }
114
-
115
- ref.current.style.transition = globalVars.transitionDuration;
116
- ref.current.style.transform = `translate3d(${
117
- swiped ? "0" : `-${OFFSET_PX_CUPERTINO / 16}rem`
118
- }, 0, 0)`;
119
- });
120
-
121
- const _cachedRefs = [...cachedRefs];
122
-
123
- resolve();
124
-
125
- listenOnce($paper, "transitionend", () => {
126
- const _swiped =
127
- swiped ||
128
- $paper.parentElement?.classList.contains(
129
- appScreenCss.exitActive,
130
- ) ||
131
- $paper.parentElement?.classList.contains(
132
- appScreenCss.exitDone,
133
- );
134
-
135
- $dim.style.opacity = "";
136
- $paper.style.overflowY = "";
137
- $paper.style.transform = "";
138
-
139
- refs.forEach((ref, i) => {
140
- if (!ref.current) {
141
- return;
142
- }
143
-
144
- const _cachedRef = _cachedRefs[i];
145
-
146
- if (_swiped) {
147
- ref.current.style.transition = "";
148
- ref.current.style.transform = "";
149
-
150
- if (ref.current.parentElement) {
151
- ref.current.parentElement.style.display = "";
152
- }
153
- } else if (_cachedRef) {
154
- ref.current.style.transition =
155
- _cachedRef.style.transition;
156
- ref.current.style.transform = _cachedRef.style.transform;
157
-
158
- if (
159
- ref.current.parentElement &&
160
- _cachedRef.parentElement
161
- ) {
162
- ref.current.parentElement.style.display =
163
- _cachedRef.parentElement.style.display;
164
- }
165
- }
166
- });
167
- });
168
- });
169
- });
170
- }
171
-
172
- const onTouchStart = (e: TouchEvent) => {
173
- const { activeElement } = document as any;
174
-
175
- activeElement?.blur?.();
176
-
177
- x0 = x = e.touches[0].clientX;
178
- t0 = Date.now();
179
-
180
- cachedRefs = refs.map((ref) => {
181
- if (!ref.current) {
182
- return {
183
- style: {
184
- transform: "",
185
- transition: "",
186
- },
187
- };
188
- }
189
-
190
- return {
191
- style: {
192
- transform: ref.current.style.transform,
193
- transition: ref.current.style.transition,
194
- },
195
- parentElement: ref.current.parentElement
196
- ? {
197
- style: {
198
- display: ref.current.parentElement.style.display,
199
- },
200
- }
201
- : undefined,
202
- };
203
- });
204
- };
205
-
206
- const onTouchMove = (e: TouchEvent) => {
207
- if (!x0) {
208
- resetState();
209
- return;
210
- }
211
-
212
- x = e.touches[0].clientX;
213
-
214
- movePaper(x - x0);
215
- };
216
-
217
- const onTouchEnd = () => {
218
- if (!x0 || !t0 || !x) {
219
- resetState();
220
- return;
221
- }
222
-
223
- const t = Date.now();
224
- const v = (x - x0) / (t - t0);
225
- const swiped = v > 1 || x / $paper.clientWidth > 0.4;
226
-
227
- if (swiped) {
228
- onSwiped?.();
229
- }
230
-
231
- Promise.resolve()
232
- .then(() => resetPaper({ swiped }))
233
- .then(() => resetState());
234
- };
235
-
236
- $edge.addEventListener("touchstart", onTouchStart, { passive: true });
237
- $edge.addEventListener("touchmove", onTouchMove, { passive: true });
238
- $edge.addEventListener("touchend", onTouchEnd, { passive: true });
239
- $edge.addEventListener("touchcancel", onTouchEnd, { passive: true });
240
-
241
- return () => {
242
- $edge.removeEventListener("touchstart", onTouchStart);
243
- $edge.removeEventListener("touchmove", onTouchMove);
244
- $edge.removeEventListener("touchend", onTouchEnd);
245
- $edge.removeEventListener("touchcancel", onTouchEnd);
246
- };
247
- }
248
- : undefined,
249
- effectDeps: [prevented],
250
- });
251
- }
@@ -1,6 +0,0 @@
1
- import { useNullableActivity } from "./useNullableActivity";
2
-
3
- export function useZIndexBase() {
4
- const activity = useNullableActivity();
5
- return (activity?.zIndex ?? 0) * 5;
6
- }
package/src/utils/last.ts DELETED
@@ -1 +0,0 @@
1
- export const last = <T>(arr: T[]) => arr[arr.length - 1];
@@ -1,12 +0,0 @@
1
- export function listenOnce<T extends HTMLElement>(
2
- el: T,
3
- type: keyof HTMLElementEventMap,
4
- cb: () => void,
5
- ) {
6
- const listener = () => {
7
- el.removeEventListener(type, listener);
8
- cb();
9
- };
10
-
11
- el.addEventListener(type, listener);
12
- }
@@ -1,8 +0,0 @@
1
- export const listenResize = (cb: () => void) => {
2
- cb();
3
- window.addEventListener("resize", cb);
4
-
5
- return () => {
6
- window.removeEventListener("resize", cb);
7
- };
8
- };
package/src/utils/noop.ts DELETED
@@ -1 +0,0 @@
1
- export const noop = () => {};
@@ -1,8 +0,0 @@
1
- // https://github.com/MingruiZhang/react-animate-mount/blob/32300c04a4fdfa97724b70aaaf0c0f403d6da247/src/Animate.js#L171-L179
2
- export function requestNextFrame(cb: () => void) {
3
- requestAnimationFrame(() => {
4
- requestAnimationFrame(() => {
5
- cb();
6
- });
7
- });
8
- }