@stackflow/plugin-basic-ui 1.8.4 → 1.9.1-canary.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 (68) 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/index.css +3 -3
  7. package/dist/index.css.map +1 -1
  8. package/dist/index.d.ts +0 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +111 -518
  11. package/dist/index.js.map +4 -4
  12. package/dist/index.mjs +94 -480
  13. package/dist/index.mjs.map +4 -4
  14. package/dist/utils/index.d.ts +0 -5
  15. package/dist/utils/index.d.ts.map +1 -1
  16. package/package.json +6 -5
  17. package/src/components/AppBar.tsx +6 -2
  18. package/src/components/AppScreen.css.ts +4 -4
  19. package/src/components/AppScreen.tsx +52 -14
  20. package/src/components/BottomSheet.tsx +3 -3
  21. package/src/components/Modal.tsx +3 -3
  22. package/src/index.ts +0 -1
  23. package/src/utils/index.ts +0 -5
  24. package/dist/hooks/index.d.ts +0 -10
  25. package/dist/hooks/index.d.ts.map +0 -1
  26. package/dist/hooks/useLazy.d.ts +0 -2
  27. package/dist/hooks/useLazy.d.ts.map +0 -1
  28. package/dist/hooks/useMaxWidth.d.ts +0 -8
  29. package/dist/hooks/useMaxWidth.d.ts.map +0 -1
  30. package/dist/hooks/useMounted.d.ts +0 -2
  31. package/dist/hooks/useMounted.d.ts.map +0 -1
  32. package/dist/hooks/useNullableActivity.d.ts +0 -3
  33. package/dist/hooks/useNullableActivity.d.ts.map +0 -1
  34. package/dist/hooks/useStyleEffect.d.ts +0 -11
  35. package/dist/hooks/useStyleEffect.d.ts.map +0 -1
  36. package/dist/hooks/useStyleEffectHide.d.ts +0 -5
  37. package/dist/hooks/useStyleEffectHide.d.ts.map +0 -1
  38. package/dist/hooks/useStyleEffectOffset.d.ts +0 -9
  39. package/dist/hooks/useStyleEffectOffset.d.ts.map +0 -1
  40. package/dist/hooks/useStyleEffectSwipeBack.d.ts +0 -10
  41. package/dist/hooks/useStyleEffectSwipeBack.d.ts.map +0 -1
  42. package/dist/hooks/useZIndexBase.d.ts +0 -2
  43. package/dist/hooks/useZIndexBase.d.ts.map +0 -1
  44. package/dist/utils/last.d.ts +0 -2
  45. package/dist/utils/last.d.ts.map +0 -1
  46. package/dist/utils/listenOnce.d.ts +0 -2
  47. package/dist/utils/listenOnce.d.ts.map +0 -1
  48. package/dist/utils/listenResize.d.ts +0 -2
  49. package/dist/utils/listenResize.d.ts.map +0 -1
  50. package/dist/utils/noop.d.ts +0 -2
  51. package/dist/utils/noop.d.ts.map +0 -1
  52. package/dist/utils/requestNextFrame.d.ts +0 -2
  53. package/dist/utils/requestNextFrame.d.ts.map +0 -1
  54. package/src/hooks/index.ts +0 -9
  55. package/src/hooks/useLazy.tsx +0 -15
  56. package/src/hooks/useMaxWidth.ts +0 -42
  57. package/src/hooks/useMounted.ts +0 -11
  58. package/src/hooks/useNullableActivity.ts +0 -6
  59. package/src/hooks/useStyleEffect.ts +0 -85
  60. package/src/hooks/useStyleEffectHide.ts +0 -51
  61. package/src/hooks/useStyleEffectOffset.ts +0 -100
  62. package/src/hooks/useStyleEffectSwipeBack.ts +0 -251
  63. package/src/hooks/useZIndexBase.ts +0 -6
  64. package/src/utils/last.ts +0 -1
  65. package/src/utils/listenOnce.ts +0 -12
  66. package/src/utils/listenResize.ts +0 -8
  67. package/src/utils/noop.ts +0 -1
  68. package/src/utils/requestNextFrame.tsx +0 -8
@@ -1,100 +0,0 @@
1
- import { globalVars } from "../basicUIPlugin.css";
2
- import { listenOnce, noop, requestNextFrame } from "../utils";
3
- import { useStyleEffect } from "./useStyleEffect";
4
-
5
- export const OFFSET_PX_ANDROID = 32;
6
- export const OFFSET_PX_CUPERTINO = 80;
7
-
8
- export function useStyleEffectOffset({
9
- refs,
10
- theme,
11
- activityEnterStyle,
12
- hasEffect = false,
13
- }: {
14
- refs: Array<React.RefObject<any>>;
15
- theme: "android" | "cupertino";
16
- activityEnterStyle?: "slideInLeft";
17
- hasEffect?: boolean;
18
- }) {
19
- useStyleEffect({
20
- styleName: "offset",
21
- refs,
22
- effect: hasEffect
23
- ? ({ activityTransitionState, refs }) => {
24
- let transform: string;
25
- let opacity: string;
26
-
27
- switch (theme) {
28
- case "cupertino": {
29
- transform = `translate3d(-${OFFSET_PX_CUPERTINO / 16}rem, 0, 0)`;
30
- opacity = "1";
31
- break;
32
- }
33
- default: {
34
- transform =
35
- activityEnterStyle === "slideInLeft"
36
- ? "translate3d(-50%, 0, 0)"
37
- : `translate3d(0, -${OFFSET_PX_ANDROID / 16}rem, 0)`;
38
- opacity = activityEnterStyle === "slideInLeft" ? "0" : "1";
39
- break;
40
- }
41
- }
42
-
43
- const cleanup = () => {
44
- requestNextFrame(() => {
45
- refs.forEach((ref) => {
46
- if (!ref.current) {
47
- return;
48
- }
49
-
50
- const $el = ref.current;
51
-
52
- $el.style.transform = "";
53
- $el.style.opacity = "";
54
-
55
- listenOnce($el, "transitionend", () => {
56
- $el.style.transition = "";
57
- });
58
- });
59
- });
60
- };
61
-
62
- switch (activityTransitionState) {
63
- case "enter-active":
64
- case "enter-done": {
65
- refs.forEach((ref) => {
66
- if (!ref.current) {
67
- return;
68
- }
69
-
70
- ref.current.style.transition =
71
- globalVars.computedTransitionDuration;
72
- ref.current.style.transform = transform;
73
- ref.current.style.opacity = opacity;
74
- });
75
-
76
- switch (activityTransitionState) {
77
- case "enter-done":
78
- return () => {
79
- cleanup();
80
- };
81
- default:
82
- return noop;
83
- }
84
- }
85
- case "exit-active":
86
- case "exit-done": {
87
- requestNextFrame(() => {
88
- cleanup();
89
- });
90
-
91
- return noop;
92
- }
93
- default: {
94
- return noop;
95
- }
96
- }
97
- }
98
- : undefined,
99
- });
100
- }
@@ -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
- }