@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
@@ -2,9 +2,6 @@ import { useActions } from "@stackflow/react";
2
2
  import { assignInlineVars } from "@vanilla-extract/dynamic";
3
3
  import { createContext, useContext, useMemo, useRef } from "react";
4
4
 
5
- import { useGlobalOptions } from "../basicUIPlugin";
6
- import type { GlobalVars } from "../basicUIPlugin.css";
7
- import { globalVars } from "../basicUIPlugin.css";
8
5
  import {
9
6
  useLazy,
10
7
  useMounted,
@@ -13,12 +10,18 @@ import {
13
10
  useStyleEffectOffset,
14
11
  useStyleEffectSwipeBack,
15
12
  useZIndexBase,
16
- } from "../hooks";
13
+ } from "@stackflow/react-ui-core";
14
+ import { useGlobalOptions } from "../basicUIPlugin";
15
+ import type { GlobalVars } from "../basicUIPlugin.css";
16
+ import { globalVars } from "../basicUIPlugin.css";
17
17
  import type { PropOf } from "../utils";
18
18
  import { compactMap } from "../utils";
19
19
  import AppBar from "./AppBar";
20
20
  import * as css from "./AppScreen.css";
21
21
 
22
+ export const OFFSET_PX_ANDROID = 32;
23
+ export const OFFSET_PX_CUPERTINO = 80;
24
+
22
25
  export type AppScreenContext = {
23
26
  scroll: (args: { top: number }) => void;
24
27
  };
@@ -70,7 +73,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
70
73
  ? ANDROID_ONLY_activityEnterStyle
71
74
  : undefined;
72
75
 
73
- const swipeBackPrevented =
76
+ const isSwipeBackPrevented =
74
77
  preventSwipeBack || modalPresentationStyle === "fullScreen";
75
78
 
76
79
  const hasAppBar = !!appBar;
@@ -108,7 +111,6 @@ const AppScreen: React.FC<AppScreenProps> = ({
108
111
 
109
112
  useStyleEffectHide({
110
113
  refs: [appScreenRef],
111
- hasEffect: true,
112
114
  });
113
115
  useStyleEffectOffset({
114
116
  refs:
@@ -116,20 +118,58 @@ const AppScreen: React.FC<AppScreenProps> = ({
116
118
  activityEnterStyle === "slideInLeft"
117
119
  ? [paperRef]
118
120
  : [paperRef, appBarRef],
119
- theme: globalOptions.theme,
120
- activityEnterStyle,
121
+ offsetStyles:
122
+ globalOptions.theme === "cupertino"
123
+ ? {
124
+ transform: `translate3d(-${OFFSET_PX_CUPERTINO / 16}rem, 0, 0)`,
125
+ opacity: "1",
126
+ }
127
+ : activityEnterStyle === "slideInLeft"
128
+ ? {
129
+ transform: "translate3d(-50%, 0, 0)",
130
+ opacity: "0",
131
+ }
132
+ : {
133
+ transform: `translate3d(0, -${OFFSET_PX_ANDROID / 16}rem, 0)`,
134
+ opacity: "1",
135
+ },
136
+ transitionDuration: globalVars.computedTransitionDuration,
121
137
  hasEffect: modalPresentationStyle !== "fullScreen",
122
138
  });
123
139
  useStyleEffectSwipeBack({
124
140
  dimRef,
125
141
  edgeRef,
126
142
  paperRef,
127
- theme: globalOptions.theme,
128
- prevented: swipeBackPrevented,
143
+ offset: OFFSET_PX_CUPERTINO,
144
+ transitionDuration: globalVars.transitionDuration,
145
+ preventSwipeBack:
146
+ isSwipeBackPrevented || globalOptions.theme !== "cupertino",
147
+ getActivityTransitionState() {
148
+ const $paper = paperRef.current;
149
+ const $appScreen = $paper?.parentElement;
150
+
151
+ if (!$appScreen) {
152
+ return null;
153
+ }
154
+
155
+ if ($appScreen.classList.contains(css.enterActive)) {
156
+ return "enter-active";
157
+ }
158
+ if ($appScreen.classList.contains(css.enterDone)) {
159
+ return "enter-done";
160
+ }
161
+ if ($appScreen.classList.contains(css.exitActive)) {
162
+ return "exit-active";
163
+ }
164
+ if ($appScreen.classList.contains(css.exitDone)) {
165
+ return "exit-done";
166
+ }
167
+
168
+ return null;
169
+ },
129
170
  onSwiped() {
130
171
  pop();
131
172
  },
132
- hasEffect: true,
133
173
  });
134
174
 
135
175
  const onAppBarTopClick: React.MouseEventHandler = (e) => {
@@ -214,7 +254,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
214
254
  </div>
215
255
  {!activity?.isRoot &&
216
256
  globalOptions.theme === "cupertino" &&
217
- !swipeBackPrevented && (
257
+ !isSwipeBackPrevented && (
218
258
  <div className={css.edge({ hasAppBar })} ref={edgeRef} />
219
259
  )}
220
260
  </div>
@@ -222,6 +262,4 @@ const AppScreen: React.FC<AppScreenProps> = ({
222
262
  );
223
263
  };
224
264
 
225
- AppScreen.displayName = "AppScreen";
226
-
227
265
  export default AppScreen;
@@ -2,14 +2,14 @@ import { useActions } from "@stackflow/react";
2
2
  import { assignInlineVars } from "@vanilla-extract/dynamic";
3
3
  import { useRef } from "react";
4
4
 
5
- import type { GlobalVars } from "../basicUIPlugin.css";
6
- import { globalVars } from "../basicUIPlugin.css";
7
5
  import {
8
6
  useLazy,
9
7
  useNullableActivity,
10
8
  useStyleEffect,
11
9
  useZIndexBase,
12
- } from "../hooks";
10
+ } from "@stackflow/react-ui-core";
11
+ import type { GlobalVars } from "../basicUIPlugin.css";
12
+ import { globalVars } from "../basicUIPlugin.css";
13
13
  import { compactMap } from "../utils";
14
14
  import * as css from "./BottomSheet.css";
15
15
 
@@ -2,14 +2,14 @@ import { useActions } from "@stackflow/react";
2
2
  import { assignInlineVars } from "@vanilla-extract/dynamic";
3
3
  import { useRef } from "react";
4
4
 
5
- import type { GlobalVars } from "../basicUIPlugin.css";
6
- import { globalVars } from "../basicUIPlugin.css";
7
5
  import {
8
6
  useLazy,
9
7
  useNullableActivity,
10
8
  useStyleEffect,
11
9
  useZIndexBase,
12
- } from "../hooks";
10
+ } from "@stackflow/react-ui-core";
11
+ import type { GlobalVars } from "../basicUIPlugin.css";
12
+ import { globalVars } from "../basicUIPlugin.css";
13
13
  import { compactMap } from "../utils";
14
14
  import * as css from "./Modal.css";
15
15
 
package/src/index.ts CHANGED
@@ -15,4 +15,3 @@ export {
15
15
  export { vars as bottomSheetVars } from "./components/BottomSheet.css";
16
16
  export { default as Modal, ModalProps } from "./components/Modal";
17
17
  export { vars as modalVars } from "./components/Modal.css";
18
- export { useStyleEffect, useZIndexBase } from "./hooks";
@@ -2,10 +2,5 @@ export * from "./compact";
2
2
  export * from "./compactMap";
3
3
  export * from "./isBrowser";
4
4
  export * from "./isServer";
5
- export * from "./last";
6
- export * from "./listenOnce";
7
- export * from "./listenResize";
8
- export * from "./noop";
9
5
  export * from "./PropOf";
10
6
  export * from "./RecursivePartial";
11
- export * from "./requestNextFrame";
@@ -1,10 +0,0 @@
1
- export * from "./useLazy";
2
- export * from "./useMaxWidth";
3
- export * from "./useMounted";
4
- export * from "./useNullableActivity";
5
- export * from "./useStyleEffect";
6
- export * from "./useStyleEffectHide";
7
- export * from "./useStyleEffectOffset";
8
- export * from "./useStyleEffectSwipeBack";
9
- export * from "./useZIndexBase";
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function useLazy<T>(value: T): T | undefined;
2
- //# sourceMappingURL=useLazy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLazy.d.ts","sourceRoot":"","sources":["../../src/hooks/useLazy.tsx"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,iBAUlC"}
@@ -1,8 +0,0 @@
1
- export declare function useMaxWidth({ outerRef, innerRef, enable, }: {
2
- outerRef: React.ForwardedRef<any>;
3
- innerRef: React.MutableRefObject<any>;
4
- enable: boolean;
5
- }): {
6
- maxWidth: number | undefined;
7
- };
8
- //# sourceMappingURL=useMaxWidth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMaxWidth.d.ts","sourceRoot":"","sources":["../../src/hooks/useMaxWidth.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,EAAE,OAAO,CAAC;CACjB;;EA6BA"}
@@ -1,2 +0,0 @@
1
- export declare function useMounted(): boolean;
2
- //# sourceMappingURL=useMounted.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMounted.d.ts","sourceRoot":"","sources":["../../src/hooks/useMounted.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,YAQzB"}
@@ -1,3 +0,0 @@
1
- import type { Activity } from "@stackflow/core";
2
- export declare function useNullableActivity(): Activity | null;
3
- //# sourceMappingURL=useNullableActivity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useNullableActivity.d.ts","sourceRoot":"","sources":["../../src/hooks/useNullableActivity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGhD,wBAAgB,mBAAmB,IACT,QAAQ,GAAG,IAAI,CACxC"}
@@ -1,11 +0,0 @@
1
- import type { ActivityTransitionState } from "@stackflow/core";
2
- export declare function useStyleEffect<T extends HTMLElement>({ styleName, refs, effect, effectDeps, }: {
3
- styleName: string;
4
- refs: Array<React.RefObject<T>>;
5
- effect?: (params: {
6
- activityTransitionState: ActivityTransitionState;
7
- refs: Array<React.RefObject<T>>;
8
- }) => (() => void) | undefined;
9
- effectDeps?: any[];
10
- }): void;
11
- //# sourceMappingURL=useStyleEffect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyleEffect.d.ts","sourceRoot":"","sources":["../../src/hooks/useStyleEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAgB/D,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,EAAE,EACpD,SAAS,EACT,IAAI,EACJ,MAAM,EACN,UAAU,GACX,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE;QAChB,uBAAuB,EAAE,uBAAuB,CAAC;QACjD,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;KACjC,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IAC/B,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;CACpB,QAuDA"}
@@ -1,5 +0,0 @@
1
- export declare function useStyleEffectHide({ refs, hasEffect, }: {
2
- refs: Array<React.RefObject<any>>;
3
- hasEffect?: boolean;
4
- }): void;
5
- //# sourceMappingURL=useStyleEffectHide.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyleEffectHide.d.ts","sourceRoot":"","sources":["../../src/hooks/useStyleEffectHide.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,SAAS,GACV,EAAE;IACD,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,QAyCA"}
@@ -1,9 +0,0 @@
1
- export declare const OFFSET_PX_ANDROID = 32;
2
- export declare const OFFSET_PX_CUPERTINO = 80;
3
- export declare function useStyleEffectOffset({ refs, theme, activityEnterStyle, hasEffect, }: {
4
- refs: Array<React.RefObject<any>>;
5
- theme: "android" | "cupertino";
6
- activityEnterStyle?: "slideInLeft";
7
- hasEffect?: boolean;
8
- }): void;
9
- //# sourceMappingURL=useStyleEffectOffset.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyleEffectOffset.d.ts","sourceRoot":"","sources":["../../src/hooks/useStyleEffectOffset.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,wBAAgB,oBAAoB,CAAC,EACnC,IAAI,EACJ,KAAK,EACL,kBAAkB,EAClB,SAAiB,GAClB,EAAE;IACD,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,kBAAkB,CAAC,EAAE,aAAa,CAAC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,QAkFA"}
@@ -1,10 +0,0 @@
1
- export declare function useStyleEffectSwipeBack({ theme, dimRef, edgeRef, paperRef, hasEffect, prevented, onSwiped, }: {
2
- theme: "android" | "cupertino";
3
- dimRef: React.RefObject<HTMLDivElement>;
4
- edgeRef: React.RefObject<HTMLDivElement>;
5
- paperRef: React.RefObject<HTMLDivElement>;
6
- hasEffect?: boolean;
7
- prevented?: boolean;
8
- onSwiped?: () => void;
9
- }): void;
10
- //# sourceMappingURL=useStyleEffectSwipeBack.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyleEffectSwipeBack.d.ts","sourceRoot":"","sources":["../../src/hooks/useStyleEffectSwipeBack.ts"],"names":[],"mappings":"AAMA,wBAAgB,uBAAuB,CAAC,EACtC,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACxC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB,QAoOA"}
@@ -1,2 +0,0 @@
1
- export declare function useZIndexBase(): number;
2
- //# sourceMappingURL=useZIndexBase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useZIndexBase.d.ts","sourceRoot":"","sources":["../../src/hooks/useZIndexBase.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,WAG5B"}
@@ -1,2 +0,0 @@
1
- export declare const last: <T>(arr: T[]) => T;
2
- //# sourceMappingURL=last.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"last.d.ts","sourceRoot":"","sources":["../../src/utils/last.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,GAAI,CAAC,OAAO,CAAC,EAAE,MAAwB,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function listenOnce<T extends HTMLElement>(el: T, type: keyof HTMLElementEventMap, cb: () => void): void;
2
- //# sourceMappingURL=listenOnce.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listenOnce.d.ts","sourceRoot":"","sources":["../../src/utils/listenOnce.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAC9C,EAAE,EAAE,CAAC,EACL,IAAI,EAAE,MAAM,mBAAmB,EAC/B,EAAE,EAAE,MAAM,IAAI,QAQf"}
@@ -1,2 +0,0 @@
1
- export declare const listenResize: (cb: () => void) => () => void;
2
- //# sourceMappingURL=listenResize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listenResize.d.ts","sourceRoot":"","sources":["../../src/utils/listenResize.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,OAAQ,MAAM,IAAI,eAO1C,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const noop: () => void;
2
- //# sourceMappingURL=noop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../src/utils/noop.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,YAAW,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function requestNextFrame(cb: () => void): void;
2
- //# sourceMappingURL=requestNextFrame.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requestNextFrame.d.ts","sourceRoot":"","sources":["../../src/utils/requestNextFrame.tsx"],"names":[],"mappings":"AACA,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,IAAI,QAM9C"}
@@ -1,9 +0,0 @@
1
- export * from "./useLazy";
2
- export * from "./useMaxWidth";
3
- export * from "./useMounted";
4
- export * from "./useNullableActivity";
5
- export * from "./useStyleEffect";
6
- export * from "./useStyleEffectHide";
7
- export * from "./useStyleEffectOffset";
8
- export * from "./useStyleEffectSwipeBack";
9
- export * from "./useZIndexBase";
@@ -1,15 +0,0 @@
1
- import { useEffect, useState } from "react";
2
-
3
- import { requestNextFrame } from "../utils";
4
-
5
- export function useLazy<T>(value: T) {
6
- const [state, setState] = useState<T | undefined>(undefined);
7
-
8
- useEffect(() => {
9
- requestNextFrame(() => {
10
- setState(value);
11
- });
12
- }, [value]);
13
-
14
- return state;
15
- }
@@ -1,42 +0,0 @@
1
- import { useEffect, useState } from "react";
2
-
3
- import { listenResize, noop } from "../utils";
4
-
5
- export function useMaxWidth({
6
- outerRef,
7
- innerRef,
8
- enable,
9
- }: {
10
- outerRef: React.ForwardedRef<any>;
11
- innerRef: React.MutableRefObject<any>;
12
- enable: boolean;
13
- }) {
14
- const [maxWidth, setMaxWidth] = useState<number | undefined>(undefined);
15
-
16
- useEffect(() => {
17
- const $outer = outerRef && "current" in outerRef && outerRef.current;
18
- const $inner = innerRef.current;
19
-
20
- if (!enable || !$outer || !$inner) {
21
- return noop;
22
- }
23
-
24
- const dispose = listenResize(() => {
25
- const screenWidth = $outer.clientWidth;
26
-
27
- const leftWidth = $inner.offsetLeft;
28
- const centerWidth = $inner.clientWidth;
29
- const rightWidth = screenWidth - leftWidth - centerWidth;
30
-
31
- const sideMargin = Math.max(leftWidth, rightWidth);
32
-
33
- setMaxWidth(screenWidth - 2 * sideMargin);
34
- });
35
-
36
- return dispose;
37
- });
38
-
39
- return {
40
- maxWidth,
41
- };
42
- }
@@ -1,11 +0,0 @@
1
- import { useEffect, useReducer, useState } from "react";
2
-
3
- export function useMounted() {
4
- const [mounted, mount] = useReducer(() => true, false);
5
-
6
- useEffect(() => {
7
- mount();
8
- }, []);
9
-
10
- return mounted;
11
- }
@@ -1,6 +0,0 @@
1
- import type { Activity } from "@stackflow/core";
2
- import { useActivity } from "@stackflow/react";
3
-
4
- export function useNullableActivity() {
5
- return useActivity() as Activity | null;
6
- }
@@ -1,85 +0,0 @@
1
- import type { ActivityTransitionState } from "@stackflow/core";
2
- import { useEffect } from "react";
3
-
4
- import { noop } from "../utils";
5
- import { useNullableActivity } from "./useNullableActivity";
6
-
7
- const connections: {
8
- [styleName: string]: Map<
9
- number,
10
- {
11
- refs: Array<React.RefObject<any>>;
12
- hasEffect: boolean;
13
- }
14
- >;
15
- } = {};
16
-
17
- export function useStyleEffect<T extends HTMLElement>({
18
- styleName,
19
- refs,
20
- effect,
21
- effectDeps,
22
- }: {
23
- styleName: string;
24
- refs: Array<React.RefObject<T>>;
25
- effect?: (params: {
26
- activityTransitionState: ActivityTransitionState;
27
- refs: Array<React.RefObject<T>>;
28
- }) => (() => void) | undefined;
29
- effectDeps?: any[];
30
- }) {
31
- const activity = useNullableActivity();
32
-
33
- useEffect(() => {
34
- if (!activity) {
35
- return noop;
36
- }
37
- if (!connections[styleName]) {
38
- connections[styleName] = new Map();
39
- }
40
-
41
- connections[styleName].set(activity.zIndex, {
42
- refs,
43
- hasEffect: !!effect,
44
- });
45
-
46
- return () => {
47
- connections[styleName].delete(activity.zIndex);
48
- };
49
- }, [activity?.id, refs, effect]);
50
-
51
- useEffect(() => {
52
- if (!activity) {
53
- return noop;
54
- }
55
- if (!effect) {
56
- return noop;
57
- }
58
-
59
- const refs = (() => {
60
- let arr: Array<React.RefObject<T>> = [];
61
-
62
- for (let i = 1; i <= activity.zIndex; i += 1) {
63
- const connection = connections[styleName].get(activity.zIndex - i);
64
-
65
- if (connection?.refs) {
66
- arr = [...arr, ...connection.refs];
67
- }
68
- if (connection?.hasEffect) {
69
- break;
70
- }
71
- }
72
-
73
- return arr;
74
- })();
75
-
76
- const cleanup = effect({
77
- activityTransitionState: activity.transitionState,
78
- refs,
79
- });
80
-
81
- return () => {
82
- cleanup?.();
83
- };
84
- }, [activity?.transitionState, ...(effectDeps ?? [])]);
85
- }
@@ -1,51 +0,0 @@
1
- import { noop } from "../utils";
2
- import { useStyleEffect } from "./useStyleEffect";
3
-
4
- export function useStyleEffectHide({
5
- refs,
6
- hasEffect,
7
- }: {
8
- refs: Array<React.RefObject<any>>;
9
- hasEffect?: boolean;
10
- }) {
11
- useStyleEffect({
12
- styleName: "hide",
13
- refs,
14
- effect: hasEffect
15
- ? ({ activityTransitionState, refs }) => {
16
- const cleanup = () => {
17
- refs.forEach((ref) => {
18
- if (!ref.current) {
19
- return;
20
- }
21
- const $ref = ref.current;
22
-
23
- $ref.style.display = "";
24
- });
25
- };
26
-
27
- switch (activityTransitionState) {
28
- case "enter-done": {
29
- refs.forEach((ref) => {
30
- if (!ref.current) {
31
- return;
32
- }
33
- const $ref = ref.current;
34
-
35
- $ref.style.display = "none";
36
- });
37
-
38
- return () => {
39
- cleanup();
40
- };
41
- }
42
- default: {
43
- cleanup();
44
-
45
- return noop;
46
- }
47
- }
48
- }
49
- : undefined,
50
- });
51
- }