@akanjs/next 0.0.97 → 0.0.99
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/{bootCsr.mjs → bootCsr.cjs} +52 -28
- package/bootCsr.js +28 -52
- package/createNextMiddleware.cjs +78 -0
- package/createNextMiddleware.js +13 -42
- package/createRobotPage.cjs +34 -0
- package/createRobotPage.js +3 -22
- package/createSitemapPage.cjs +26 -0
- package/createSitemapPage.js +3 -22
- package/index.cjs +60 -0
- package/index.js +40 -59
- package/lazy.cjs +35 -0
- package/lazy.js +5 -34
- package/{makePageProto.mjs → makePageProto.cjs} +32 -13
- package/makePageProto.js +13 -32
- package/package.json +4 -4
- package/types.cjs +15 -0
- package/types.js +0 -15
- package/useCamera.cjs +96 -0
- package/useCamera.js +17 -36
- package/useCodepush.cjs +103 -0
- package/useCodepush.js +25 -54
- package/useContact.cjs +55 -0
- package/useContact.js +12 -31
- package/{useCsrValues.mjs → useCsrValues.cjs} +74 -59
- package/useCsrValues.js +59 -74
- package/useDebounce.cjs +37 -0
- package/useDebounce.js +5 -24
- package/useFetch.cjs +42 -0
- package/useFetch.js +6 -25
- package/useGeoLocation.cjs +40 -0
- package/useGeoLocation.js +6 -25
- package/{useHistory.mjs → useHistory.cjs} +29 -10
- package/useHistory.js +10 -29
- package/useInterval.cjs +40 -0
- package/useInterval.js +7 -26
- package/{useLocation.mjs → useLocation.cjs} +24 -5
- package/useLocation.js +5 -24
- package/{usePurchase.mjs → usePurchase.cjs} +29 -10
- package/usePurchase.js +10 -29
- package/usePushNoti.cjs +61 -0
- package/usePushNoti.js +16 -35
- package/useThrottle.cjs +39 -0
- package/useThrottle.js +6 -25
- package/createNextMiddleware.mjs +0 -49
- package/createRobotPage.mjs +0 -15
- package/createSitemapPage.mjs +0 -7
- package/index.mjs +0 -41
- package/lazy.mjs +0 -6
- package/types.mjs +0 -0
- package/useCamera.mjs +0 -77
- package/useCodepush.mjs +0 -74
- package/useContact.mjs +0 -36
- package/useDebounce.mjs +0 -18
- package/useFetch.mjs +0 -23
- package/useGeoLocation.mjs +0 -21
- package/useInterval.mjs +0 -21
- package/usePushNoti.mjs +0 -42
- package/useThrottle.mjs +0 -20
package/useCsrValues.js
CHANGED
|
@@ -1,41 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var useCsrValues_exports = {};
|
|
20
|
-
__export(useCsrValues_exports, {
|
|
21
|
-
useCsrValues: () => useCsrValues
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(useCsrValues_exports);
|
|
24
|
-
var import_client = require("@akanjs/client");
|
|
25
|
-
var import_app = require("@capacitor/app");
|
|
26
|
-
var import_web = require("@react-spring/web");
|
|
27
|
-
var import_react = require("@use-gesture/react");
|
|
28
|
-
var import_react2 = require("react");
|
|
29
|
-
var import_useHistory = require("./useHistory");
|
|
30
|
-
var import_useLocation = require("./useLocation");
|
|
2
|
+
import {
|
|
3
|
+
defaultPageState,
|
|
4
|
+
device,
|
|
5
|
+
router
|
|
6
|
+
} from "@akanjs/client";
|
|
7
|
+
import { App } from "@capacitor/app";
|
|
8
|
+
import { useSpringValue } from "@react-spring/web";
|
|
9
|
+
import { useDrag } from "@use-gesture/react";
|
|
10
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
11
|
+
import { useHistory } from "./useHistory";
|
|
12
|
+
import { useLocation } from "./useLocation";
|
|
31
13
|
const useNoneTrans = ({ clientHeight, location, prevLocation }) => {
|
|
32
14
|
const transDirection = "none";
|
|
33
|
-
const transUnit =
|
|
34
|
-
const transUnitRange =
|
|
15
|
+
const transUnit = useSpringValue(0, { config: { clamp: true } });
|
|
16
|
+
const transUnitRange = useMemo(() => [0, 0], []);
|
|
35
17
|
const transProgress = transUnit.to((unit) => 1);
|
|
36
18
|
const transPercent = transUnit.to((unit) => 100);
|
|
37
19
|
const pageState = location.pathRoute.pageState;
|
|
38
|
-
const prevPageState = prevLocation?.pathRoute.pageState ??
|
|
20
|
+
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
39
21
|
const csrTranstionStyles = {
|
|
40
22
|
topSafeArea: {
|
|
41
23
|
containerStyle: {
|
|
@@ -101,18 +83,18 @@ const useNoneTrans = ({ clientHeight, location, prevLocation }) => {
|
|
|
101
83
|
};
|
|
102
84
|
const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }) => {
|
|
103
85
|
const transDirection = "none";
|
|
104
|
-
const transUnit =
|
|
105
|
-
const transUnitRange =
|
|
86
|
+
const transUnit = useSpringValue(1, { config: { clamp: true } });
|
|
87
|
+
const transUnitRange = useMemo(() => [0, 1], []);
|
|
106
88
|
const transProgress = transUnit.to((unit) => unit);
|
|
107
89
|
const transPercent = transUnit.to([0, 1], [0, 100], "clamp");
|
|
108
90
|
const pageState = location.pathRoute.pageState;
|
|
109
|
-
const prevPageState = prevLocation?.pathRoute.pageState ??
|
|
110
|
-
|
|
91
|
+
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
92
|
+
useEffect(() => {
|
|
111
93
|
onBack.current.fade = async () => {
|
|
112
94
|
await transUnit.start(transUnitRange[0]);
|
|
113
95
|
};
|
|
114
96
|
}, []);
|
|
115
|
-
|
|
97
|
+
useEffect(() => {
|
|
116
98
|
if (history.current.type === "forward") {
|
|
117
99
|
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
118
100
|
void transUnit.start(transUnitRange[1], { config: { duration: 150 } });
|
|
@@ -218,23 +200,23 @@ const useStackTrans = ({
|
|
|
218
200
|
onBack
|
|
219
201
|
}) => {
|
|
220
202
|
const transDirection = "horizontal";
|
|
221
|
-
const transUnit =
|
|
222
|
-
const transUnitRange =
|
|
203
|
+
const transUnit = useSpringValue(0, { config: { clamp: true } });
|
|
204
|
+
const transUnitRange = useMemo(() => [clientWidth, 0], []);
|
|
223
205
|
const transUnitReversed = transUnit.to((unit) => transUnitRange[0] - unit);
|
|
224
|
-
const transUnitRangeReversed =
|
|
206
|
+
const transUnitRangeReversed = useMemo(() => [0, clientWidth], []);
|
|
225
207
|
const transProgress = transUnitReversed.to(transUnitRangeReversed, [0, 1], "clamp");
|
|
226
208
|
const transPercent = transUnitReversed.to(transUnitRangeReversed, [0, 100], "clamp");
|
|
227
|
-
const initThreshold =
|
|
228
|
-
const threshold =
|
|
209
|
+
const initThreshold = useMemo(() => Math.floor(clientWidth), []);
|
|
210
|
+
const threshold = useMemo(() => Math.floor(clientWidth / 3), []);
|
|
229
211
|
const pageState = location.pathRoute.pageState;
|
|
230
|
-
const prevPageState = prevLocation?.pathRoute.pageState ??
|
|
212
|
+
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
231
213
|
const pageClassName = "touch-pan-y";
|
|
232
|
-
|
|
214
|
+
useEffect(() => {
|
|
233
215
|
onBack.current.stack = async () => {
|
|
234
216
|
await transUnit.start(transUnitRange[0]);
|
|
235
217
|
};
|
|
236
218
|
}, []);
|
|
237
|
-
|
|
219
|
+
useEffect(() => {
|
|
238
220
|
if (history.current.type === "forward") {
|
|
239
221
|
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
240
222
|
void transUnit.start(transUnitRange[1], { config: { duration: 150 } });
|
|
@@ -243,10 +225,10 @@ const useStackTrans = ({
|
|
|
243
225
|
return;
|
|
244
226
|
}
|
|
245
227
|
}, [location.pathname]);
|
|
246
|
-
const pageBind =
|
|
228
|
+
const pageBind = useDrag(
|
|
247
229
|
({ first, down, last, movement: [mx], initial: [ix], cancel }) => {
|
|
248
230
|
if (first)
|
|
249
|
-
void
|
|
231
|
+
void device.hideKeyboard();
|
|
250
232
|
if (ix > initThreshold) {
|
|
251
233
|
cancel();
|
|
252
234
|
return;
|
|
@@ -260,7 +242,7 @@ const useStackTrans = ({
|
|
|
260
242
|
else if (mx < threshold)
|
|
261
243
|
void transUnit.start(transUnitRange[1]);
|
|
262
244
|
if (last && mx > threshold)
|
|
263
|
-
|
|
245
|
+
router.back();
|
|
264
246
|
},
|
|
265
247
|
{ axis: "x", filterTaps: true }
|
|
266
248
|
);
|
|
@@ -366,22 +348,22 @@ const useBottomUpTrans = ({
|
|
|
366
348
|
onBack
|
|
367
349
|
}) => {
|
|
368
350
|
const transDirection = "vertical";
|
|
369
|
-
const transUnit =
|
|
370
|
-
const transUnitRange =
|
|
351
|
+
const transUnit = useSpringValue(0, { config: { clamp: true } });
|
|
352
|
+
const transUnitRange = useMemo(() => [clientHeight, 0], []);
|
|
371
353
|
const transUnitReversed = transUnit.to((unit) => transUnitRange[0] - unit);
|
|
372
|
-
const transUnitRangeReversed =
|
|
354
|
+
const transUnitRangeReversed = useMemo(() => [0, clientWidth], []);
|
|
373
355
|
const transProgress = transUnitReversed.to(transUnitRangeReversed, [0, 1], "clamp");
|
|
374
356
|
const transPercent = transUnitReversed.to(transUnitRangeReversed, [0, 100], "clamp");
|
|
375
|
-
const initThreshold =
|
|
376
|
-
const threshold =
|
|
357
|
+
const initThreshold = useMemo(() => Math.floor(clientWidth / 3), []);
|
|
358
|
+
const threshold = useMemo(() => Math.floor(clientWidth / 2), []);
|
|
377
359
|
const pageState = location.pathRoute.pageState;
|
|
378
|
-
const prevPageState = prevLocation?.pathRoute.pageState ??
|
|
379
|
-
|
|
360
|
+
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
361
|
+
useEffect(() => {
|
|
380
362
|
onBack.current.bottomUp = async () => {
|
|
381
363
|
await transUnit.start(transUnitRange[0]);
|
|
382
364
|
};
|
|
383
365
|
}, []);
|
|
384
|
-
|
|
366
|
+
useEffect(() => {
|
|
385
367
|
if (history.current.type === "forward") {
|
|
386
368
|
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
387
369
|
void transUnit.start(transUnitRange[1], { config: { duration: 150 } });
|
|
@@ -390,10 +372,10 @@ const useBottomUpTrans = ({
|
|
|
390
372
|
return;
|
|
391
373
|
}
|
|
392
374
|
}, [location.pathname]);
|
|
393
|
-
const pageBind =
|
|
375
|
+
const pageBind = useDrag(
|
|
394
376
|
({ first, last, movement: [, my], initial: [, iy], cancel }) => {
|
|
395
377
|
if (first)
|
|
396
|
-
void
|
|
378
|
+
void device.hideKeyboard();
|
|
397
379
|
if (iy > initThreshold) {
|
|
398
380
|
cancel();
|
|
399
381
|
return;
|
|
@@ -407,7 +389,7 @@ const useBottomUpTrans = ({
|
|
|
407
389
|
else if (my < threshold)
|
|
408
390
|
void transUnit.start(transUnitRange[1]);
|
|
409
391
|
if (last && my > threshold)
|
|
410
|
-
|
|
392
|
+
router.back();
|
|
411
393
|
},
|
|
412
394
|
{ axis: "y", filterTaps: true, threshold: 10 }
|
|
413
395
|
);
|
|
@@ -504,23 +486,23 @@ const useBottomUpTrans = ({
|
|
|
504
486
|
return useCsrTransition;
|
|
505
487
|
};
|
|
506
488
|
const useCsrValues = (rootRouteGuide, pathRoutes) => {
|
|
507
|
-
const clientWidth =
|
|
508
|
-
const clientHeight =
|
|
509
|
-
const topSafeAreaRef =
|
|
510
|
-
const bottomSafeAreaRef =
|
|
511
|
-
const pageContentRef =
|
|
512
|
-
const prevPageContentRef =
|
|
513
|
-
const onBack =
|
|
514
|
-
const frameRootRef =
|
|
515
|
-
const { getLocation } =
|
|
516
|
-
const { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop } =
|
|
489
|
+
const clientWidth = useRef(window.innerWidth);
|
|
490
|
+
const clientHeight = useRef(window.innerHeight);
|
|
491
|
+
const topSafeAreaRef = useRef(null);
|
|
492
|
+
const bottomSafeAreaRef = useRef(null);
|
|
493
|
+
const pageContentRef = useRef(null);
|
|
494
|
+
const prevPageContentRef = useRef(null);
|
|
495
|
+
const onBack = useRef({});
|
|
496
|
+
const frameRootRef = useRef(null);
|
|
497
|
+
const { getLocation } = useLocation({ rootRouteGuide });
|
|
498
|
+
const { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop } = useHistory([
|
|
517
499
|
getLocation(window.location.pathname)
|
|
518
500
|
]);
|
|
519
|
-
const [{ location, prevLocation }, setLocationState] =
|
|
501
|
+
const [{ location, prevLocation }, setLocationState] = useState({
|
|
520
502
|
location: getCurrentLocation(),
|
|
521
503
|
prevLocation: getPrevLocation()
|
|
522
504
|
});
|
|
523
|
-
const getRouter =
|
|
505
|
+
const getRouter = useCallback(() => {
|
|
524
506
|
const router3 = {
|
|
525
507
|
push: (href) => {
|
|
526
508
|
const location2 = getCurrentLocation();
|
|
@@ -592,16 +574,16 @@ const useCsrValues = (rootRouteGuide, pathRoutes) => {
|
|
|
592
574
|
bottomUp: useBottomUpTransition,
|
|
593
575
|
scaleOut: useNonTransition
|
|
594
576
|
};
|
|
595
|
-
|
|
577
|
+
useEffect(() => {
|
|
596
578
|
if (pageContentRef.current)
|
|
597
579
|
pageContentRef.current.scrollTop = getScrollTop(location.pathname);
|
|
598
580
|
if (prevPageContentRef.current)
|
|
599
581
|
prevPageContentRef.current.scrollTop = prevLocation ? getScrollTop(prevLocation.pathname) : 0;
|
|
600
|
-
void
|
|
582
|
+
void App.addListener("backButton", () => {
|
|
601
583
|
router2.back();
|
|
602
584
|
});
|
|
603
585
|
return () => {
|
|
604
|
-
void
|
|
586
|
+
void App.removeAllListeners();
|
|
605
587
|
};
|
|
606
588
|
}, [location.pathname]);
|
|
607
589
|
return {
|
|
@@ -609,3 +591,6 @@ const useCsrValues = (rootRouteGuide, pathRoutes) => {
|
|
|
609
591
|
...useCsrTransitionMap[location.pathRoute.pageState.transition]
|
|
610
592
|
};
|
|
611
593
|
};
|
|
594
|
+
export {
|
|
595
|
+
useCsrValues
|
|
596
|
+
};
|
package/useDebounce.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useDebounce_exports = {};
|
|
20
|
+
__export(useDebounce_exports, {
|
|
21
|
+
useDebounce: () => useDebounce
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useDebounce_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const debounce = (callback, wait = 500) => {
|
|
26
|
+
let timer;
|
|
27
|
+
return (...args) => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
timer = setTimeout(() => {
|
|
30
|
+
callback(...args);
|
|
31
|
+
}, wait);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const useDebounce = (callback, states = [], wait = 100) => {
|
|
35
|
+
const fn = (0, import_react.useCallback)(debounce(callback, wait), states);
|
|
36
|
+
return fn;
|
|
37
|
+
};
|
package/useDebounce.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var useDebounce_exports = {};
|
|
20
|
-
__export(useDebounce_exports, {
|
|
21
|
-
useDebounce: () => useDebounce
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(useDebounce_exports);
|
|
24
|
-
var import_react = require("react");
|
|
2
|
+
import { useCallback } from "react";
|
|
25
3
|
const debounce = (callback, wait = 500) => {
|
|
26
4
|
let timer;
|
|
27
5
|
return (...args) => {
|
|
@@ -32,6 +10,9 @@ const debounce = (callback, wait = 500) => {
|
|
|
32
10
|
};
|
|
33
11
|
};
|
|
34
12
|
const useDebounce = (callback, states = [], wait = 100) => {
|
|
35
|
-
const fn =
|
|
13
|
+
const fn = useCallback(debounce(callback, wait), states);
|
|
36
14
|
return fn;
|
|
37
15
|
};
|
|
16
|
+
export {
|
|
17
|
+
useDebounce
|
|
18
|
+
};
|
package/useFetch.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useFetch_exports = {};
|
|
20
|
+
__export(useFetch_exports, {
|
|
21
|
+
useFetch: () => useFetch
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useFetch_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const useFetch = (fnOrPromise, { onError } = {}) => {
|
|
26
|
+
const [fetchState, setFetchState] = (0, import_react.useState)(
|
|
27
|
+
fnOrPromise instanceof Promise ? { fulfilled: false, value: null } : { fulfilled: true, value: fnOrPromise }
|
|
28
|
+
);
|
|
29
|
+
(0, import_react.useEffect)(() => {
|
|
30
|
+
void (async () => {
|
|
31
|
+
try {
|
|
32
|
+
const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
|
|
33
|
+
setFetchState({ fulfilled: true, value: ret });
|
|
34
|
+
} catch (err) {
|
|
35
|
+
const content = `Error: ${typeof err === "string" ? err : err.message}`;
|
|
36
|
+
onError?.(content);
|
|
37
|
+
throw new Error(content);
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
}, []);
|
|
41
|
+
return fetchState;
|
|
42
|
+
};
|
package/useFetch.js
CHANGED
|
@@ -1,32 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var useFetch_exports = {};
|
|
20
|
-
__export(useFetch_exports, {
|
|
21
|
-
useFetch: () => useFetch
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(useFetch_exports);
|
|
24
|
-
var import_react = require("react");
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
25
3
|
const useFetch = (fnOrPromise, { onError } = {}) => {
|
|
26
|
-
const [fetchState, setFetchState] =
|
|
4
|
+
const [fetchState, setFetchState] = useState(
|
|
27
5
|
fnOrPromise instanceof Promise ? { fulfilled: false, value: null } : { fulfilled: true, value: fnOrPromise }
|
|
28
6
|
);
|
|
29
|
-
|
|
7
|
+
useEffect(() => {
|
|
30
8
|
void (async () => {
|
|
31
9
|
try {
|
|
32
10
|
const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
|
|
@@ -40,3 +18,6 @@ const useFetch = (fnOrPromise, { onError } = {}) => {
|
|
|
40
18
|
}, []);
|
|
41
19
|
return fetchState;
|
|
42
20
|
};
|
|
21
|
+
export {
|
|
22
|
+
useFetch
|
|
23
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useGeoLocation_exports = {};
|
|
20
|
+
__export(useGeoLocation_exports, {
|
|
21
|
+
useGeoLocation: () => useGeoLocation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useGeoLocation_exports);
|
|
24
|
+
var import_geolocation = require("@capacitor/geolocation");
|
|
25
|
+
const useGeoLocation = () => {
|
|
26
|
+
const checkPermission = async () => {
|
|
27
|
+
const { location: geolocation, coarseLocation } = await import_geolocation.Geolocation.requestPermissions();
|
|
28
|
+
return { geolocation, coarseLocation };
|
|
29
|
+
};
|
|
30
|
+
const getPosition = async () => {
|
|
31
|
+
const { geolocation, coarseLocation } = await checkPermission();
|
|
32
|
+
if (geolocation === "denied" || coarseLocation === "denied") {
|
|
33
|
+
location.assign("app-settings:");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const coordinates = await import_geolocation.Geolocation.getCurrentPosition();
|
|
37
|
+
return coordinates;
|
|
38
|
+
};
|
|
39
|
+
return { checkPermission, getPosition };
|
|
40
|
+
};
|
package/useGeoLocation.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var useGeoLocation_exports = {};
|
|
20
|
-
__export(useGeoLocation_exports, {
|
|
21
|
-
useGeoLocation: () => useGeoLocation
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(useGeoLocation_exports);
|
|
24
|
-
var import_geolocation = require("@capacitor/geolocation");
|
|
2
|
+
import { Geolocation } from "@capacitor/geolocation";
|
|
25
3
|
const useGeoLocation = () => {
|
|
26
4
|
const checkPermission = async () => {
|
|
27
|
-
const { location: geolocation, coarseLocation } = await
|
|
5
|
+
const { location: geolocation, coarseLocation } = await Geolocation.requestPermissions();
|
|
28
6
|
return { geolocation, coarseLocation };
|
|
29
7
|
};
|
|
30
8
|
const getPosition = async () => {
|
|
@@ -33,8 +11,11 @@ const useGeoLocation = () => {
|
|
|
33
11
|
location.assign("app-settings:");
|
|
34
12
|
return;
|
|
35
13
|
}
|
|
36
|
-
const coordinates = await
|
|
14
|
+
const coordinates = await Geolocation.getCurrentPosition();
|
|
37
15
|
return coordinates;
|
|
38
16
|
};
|
|
39
17
|
return { checkPermission, getPosition };
|
|
40
18
|
};
|
|
19
|
+
export {
|
|
20
|
+
useGeoLocation
|
|
21
|
+
};
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useHistory_exports = {};
|
|
20
|
+
__export(useHistory_exports, {
|
|
21
|
+
useHistory: () => useHistory
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useHistory_exports);
|
|
24
|
+
var import_react = require("react");
|
|
3
25
|
const useHistory = (locations = []) => {
|
|
4
|
-
const history = useRef({
|
|
26
|
+
const history = (0, import_react.useRef)({
|
|
5
27
|
type: "initial",
|
|
6
28
|
locations,
|
|
7
29
|
scrollMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
|
|
@@ -9,7 +31,7 @@ const useHistory = (locations = []) => {
|
|
|
9
31
|
cachedLocationMap: /* @__PURE__ */ new Map(),
|
|
10
32
|
idx: 0
|
|
11
33
|
});
|
|
12
|
-
const setHistoryForward = useCallback(({ type, location, scrollTop = 0 }) => {
|
|
34
|
+
const setHistoryForward = (0, import_react.useCallback)(({ type, location, scrollTop = 0 }) => {
|
|
13
35
|
history.current.type = "forward";
|
|
14
36
|
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
15
37
|
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
@@ -22,7 +44,7 @@ const useHistory = (locations = []) => {
|
|
|
22
44
|
if (type === "push" || type === "popForward")
|
|
23
45
|
history.current.idx++;
|
|
24
46
|
}, []);
|
|
25
|
-
const setHistoryBack = useCallback(({ location, scrollTop = 0 }) => {
|
|
47
|
+
const setHistoryBack = (0, import_react.useCallback)(({ location, scrollTop = 0 }) => {
|
|
26
48
|
history.current.type = "back";
|
|
27
49
|
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
28
50
|
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
@@ -30,17 +52,14 @@ const useHistory = (locations = []) => {
|
|
|
30
52
|
history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
31
53
|
history.current.idx--;
|
|
32
54
|
}, []);
|
|
33
|
-
const getCurrentLocation = useCallback(() => {
|
|
55
|
+
const getCurrentLocation = (0, import_react.useCallback)(() => {
|
|
34
56
|
return history.current.locations[history.current.idx];
|
|
35
57
|
}, []);
|
|
36
|
-
const getPrevLocation = useCallback(() => {
|
|
58
|
+
const getPrevLocation = (0, import_react.useCallback)(() => {
|
|
37
59
|
return history.current.locations[history.current.idx - 1] ?? null;
|
|
38
60
|
}, []);
|
|
39
|
-
const getScrollTop = useCallback((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
|
|
61
|
+
const getScrollTop = (0, import_react.useCallback)((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
|
|
40
62
|
return history.current.scrollMap.get(pathname) ?? 0;
|
|
41
63
|
}, []);
|
|
42
64
|
return { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop };
|
|
43
65
|
};
|
|
44
|
-
export {
|
|
45
|
-
useHistory
|
|
46
|
-
};
|
package/useHistory.js
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var useHistory_exports = {};
|
|
20
|
-
__export(useHistory_exports, {
|
|
21
|
-
useHistory: () => useHistory
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(useHistory_exports);
|
|
24
|
-
var import_react = require("react");
|
|
2
|
+
import { useCallback, useRef } from "react";
|
|
25
3
|
const useHistory = (locations = []) => {
|
|
26
|
-
const history =
|
|
4
|
+
const history = useRef({
|
|
27
5
|
type: "initial",
|
|
28
6
|
locations,
|
|
29
7
|
scrollMap: /* @__PURE__ */ new Map([[window.location.pathname, 0]]),
|
|
@@ -31,7 +9,7 @@ const useHistory = (locations = []) => {
|
|
|
31
9
|
cachedLocationMap: /* @__PURE__ */ new Map(),
|
|
32
10
|
idx: 0
|
|
33
11
|
});
|
|
34
|
-
const setHistoryForward =
|
|
12
|
+
const setHistoryForward = useCallback(({ type, location, scrollTop = 0 }) => {
|
|
35
13
|
history.current.type = "forward";
|
|
36
14
|
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
37
15
|
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
@@ -44,7 +22,7 @@ const useHistory = (locations = []) => {
|
|
|
44
22
|
if (type === "push" || type === "popForward")
|
|
45
23
|
history.current.idx++;
|
|
46
24
|
}, []);
|
|
47
|
-
const setHistoryBack =
|
|
25
|
+
const setHistoryBack = useCallback(({ location, scrollTop = 0 }) => {
|
|
48
26
|
history.current.type = "back";
|
|
49
27
|
history.current.scrollMap.set(location.pathname, scrollTop);
|
|
50
28
|
history.current.idxMap.set(location.pathname, history.current.idx);
|
|
@@ -52,14 +30,17 @@ const useHistory = (locations = []) => {
|
|
|
52
30
|
history.current.cachedLocationMap.set(location.pathRoute.path, location);
|
|
53
31
|
history.current.idx--;
|
|
54
32
|
}, []);
|
|
55
|
-
const getCurrentLocation =
|
|
33
|
+
const getCurrentLocation = useCallback(() => {
|
|
56
34
|
return history.current.locations[history.current.idx];
|
|
57
35
|
}, []);
|
|
58
|
-
const getPrevLocation =
|
|
36
|
+
const getPrevLocation = useCallback(() => {
|
|
59
37
|
return history.current.locations[history.current.idx - 1] ?? null;
|
|
60
38
|
}, []);
|
|
61
|
-
const getScrollTop =
|
|
39
|
+
const getScrollTop = useCallback((pathname = history.current.locations[history.current.idx]?.pathname ?? "/") => {
|
|
62
40
|
return history.current.scrollMap.get(pathname) ?? 0;
|
|
63
41
|
}, []);
|
|
64
42
|
return { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop };
|
|
65
43
|
};
|
|
44
|
+
export {
|
|
45
|
+
useHistory
|
|
46
|
+
};
|