akanjs 2.1.0-rc.2 → 2.1.0-rc.4
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/client/capacitor.ts +182 -24
- package/client/cookie.ts +14 -5
- package/client/device.ts +81 -10
- package/client/index.ts +0 -1
- package/client/storage.ts +38 -14
- package/package.json +6 -13
- package/server/di/predefinedAdaptor.ts +2 -2
- package/service/predefinedAdaptor/compress.adaptor.ts +58 -17
- package/service/predefinedAdaptor/queue.adaptor.ts +35 -16
- package/types/client/capacitor.d.ts +224 -24
- package/types/client/device.d.ts +9 -5
- package/types/client/index.d.ts +0 -1
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +8 -8
- package/types/server/di/predefinedAdaptor.d.ts +2 -2
- package/types/service/predefinedAdaptor/compress.adaptor.d.ts +8 -0
- package/types/service/predefinedAdaptor/queue.adaptor.d.ts +8 -5
- package/types/ui/Copy.d.ts +1 -1
- package/types/webkit/useCamera.d.ts +14 -3
- package/types/webkit/useContact.d.ts +6 -2
- package/types/webkit/useGeoLocation.d.ts +1 -1
- package/ui/Copy.tsx +36 -7
- package/ui/Data/ListContainer.tsx +14 -3
- package/ui/DatePicker.tsx +9 -3
- package/ui/Link/CsrLink.tsx +5 -2
- package/ui/More.tsx +2 -3
- package/ui/Refresh.tsx +3 -1
- package/webkit/useCamera.tsx +8 -4
- package/webkit/useCodepush.tsx +1 -1
- package/webkit/useContact.tsx +6 -2
- package/webkit/useCsrValues.ts +2 -1
- package/webkit/useGeoLocation.tsx +1 -1
- package/webkit/usePurchase.tsx +1 -1
- package/webkit/usePushNoti.tsx +1 -1
package/client/capacitor.ts
CHANGED
|
@@ -1,16 +1,145 @@
|
|
|
1
|
+
export type CapacitorDeviceInfo = {
|
|
2
|
+
platform: string;
|
|
3
|
+
isVirtual: boolean;
|
|
4
|
+
osVersion: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type CapacitorKeyboardInfo = {
|
|
9
|
+
keyboardHeight: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type CapacitorPermissionState = "prompt" | "prompt-with-rationale" | "granted" | "denied" | string;
|
|
13
|
+
|
|
14
|
+
export type CapacitorAppModule = {
|
|
15
|
+
App: {
|
|
16
|
+
addListener: (eventName: string, listenerFunc: (...args: unknown[]) => void) => Promise<unknown> | unknown;
|
|
17
|
+
removeAllListeners: () => Promise<void> | void;
|
|
18
|
+
getInfo: () => Promise<{ id: string; version: string; build: string; [key: string]: unknown }>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type CapacitorBrowserModule = {
|
|
23
|
+
Browser: {
|
|
24
|
+
open: (options: { url: string; presentationStyle?: string }) => Promise<void> | void;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type CapacitorCameraModule = {
|
|
29
|
+
Camera: {
|
|
30
|
+
checkPermissions: () => Promise<{ camera: CapacitorPermissionState; photos: CapacitorPermissionState }>;
|
|
31
|
+
requestPermissions: () => Promise<{ camera: CapacitorPermissionState; photos: CapacitorPermissionState }>;
|
|
32
|
+
getPhoto: (options: Record<string, unknown>) => Promise<{ dataUrl?: string; [key: string]: unknown }>;
|
|
33
|
+
pickImages: (options: Record<string, unknown>) => Promise<{ photos: unknown[]; [key: string]: unknown }>;
|
|
34
|
+
};
|
|
35
|
+
CameraResultType: { DataUrl: string };
|
|
36
|
+
CameraSource: { Prompt: string; Camera: string; Photos: string };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type CapacitorContactsModule = {
|
|
40
|
+
Contacts: {
|
|
41
|
+
checkPermissions: () => Promise<{ contacts: CapacitorPermissionState }>;
|
|
42
|
+
requestPermissions: () => Promise<{ contacts: CapacitorPermissionState }>;
|
|
43
|
+
getContacts: (options: Record<string, unknown>) => Promise<{ contacts: unknown[] }>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type CapacitorCoreModule = {
|
|
48
|
+
CapacitorCookies: {
|
|
49
|
+
setCookie: (options: { key: string; value: string; path?: string }) => Promise<void> | void;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type CapacitorDeviceModule = {
|
|
54
|
+
Device: {
|
|
55
|
+
getInfo: () => Promise<CapacitorDeviceInfo>;
|
|
56
|
+
getLanguageCode: () => Promise<{ value: string }>;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type CapacitorFcmModule = {
|
|
61
|
+
FCM: {
|
|
62
|
+
setAutoInit: (options: { enabled: boolean }) => Promise<void> | void;
|
|
63
|
+
getToken: () => Promise<{ token: string }>;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type CapacitorGeolocationModule = {
|
|
68
|
+
Geolocation: {
|
|
69
|
+
requestPermissions: () => Promise<{ location: string; coarseLocation: string; [key: string]: string }>;
|
|
70
|
+
getCurrentPosition: () => Promise<unknown>;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type CapacitorHapticsModule = {
|
|
75
|
+
ImpactStyle: { Light: string; Medium: string; Heavy: string };
|
|
76
|
+
Haptics: {
|
|
77
|
+
vibrate: (options: { duration: number }) => Promise<void> | void;
|
|
78
|
+
impact: (options: { style: string }) => Promise<void> | void;
|
|
79
|
+
selectionStart: () => Promise<void> | void;
|
|
80
|
+
selectionChanged: () => Promise<void> | void;
|
|
81
|
+
selectionEnd: () => Promise<void> | void;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type CapacitorKeyboardModule = {
|
|
86
|
+
Keyboard: {
|
|
87
|
+
show: () => Promise<void> | void;
|
|
88
|
+
hide: () => Promise<void> | void;
|
|
89
|
+
addListener: (eventName: string, listenerFunc: (info: CapacitorKeyboardInfo) => void) => Promise<unknown> | unknown;
|
|
90
|
+
removeAllListeners: () => Promise<void> | void;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type CapacitorPreferencesModule = {
|
|
95
|
+
Preferences: {
|
|
96
|
+
get: (options: { key: string }) => Promise<{ value: string | null }>;
|
|
97
|
+
set: (options: { key: string; value: string }) => Promise<void> | void;
|
|
98
|
+
remove: (options: { key: string }) => Promise<void> | void;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type CapacitorPushNotificationsModule = {
|
|
103
|
+
PushNotifications: {
|
|
104
|
+
requestPermissions: () => Promise<{ receive: "granted" | "denied" | string }>;
|
|
105
|
+
checkPermissions: () => Promise<{ receive: "granted" | "denied" | string }>;
|
|
106
|
+
register: () => Promise<void> | void;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type CapacitorSafeAreaModule = {
|
|
111
|
+
SafeArea: {
|
|
112
|
+
getSafeAreaInsets: () => Promise<{ insets: { top: number; bottom: number } }>;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type CapacitorUpdaterModule = {
|
|
117
|
+
CapacitorUpdater: {
|
|
118
|
+
notifyAppReady: () => Promise<void> | void;
|
|
119
|
+
getPluginVersion: () => Promise<{ version: string }>;
|
|
120
|
+
getDeviceId: () => Promise<{ deviceId: string }>;
|
|
121
|
+
current: () => Promise<{ bundle: { version: string }; native: string }>;
|
|
122
|
+
getBuiltinVersion: () => Promise<{ version: string }>;
|
|
123
|
+
download: (options: { url: string; version: string }) => Promise<unknown>;
|
|
124
|
+
set: (bundle: unknown) => Promise<void> | void;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
1
128
|
type CapacitorModuleMap = {
|
|
2
|
-
app:
|
|
3
|
-
browser:
|
|
4
|
-
camera:
|
|
5
|
-
contacts:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
129
|
+
app: CapacitorAppModule;
|
|
130
|
+
browser: CapacitorBrowserModule;
|
|
131
|
+
camera: CapacitorCameraModule;
|
|
132
|
+
contacts: CapacitorContactsModule;
|
|
133
|
+
core: CapacitorCoreModule;
|
|
134
|
+
device: CapacitorDeviceModule;
|
|
135
|
+
fcm: CapacitorFcmModule;
|
|
136
|
+
geolocation: CapacitorGeolocationModule;
|
|
137
|
+
haptics: CapacitorHapticsModule;
|
|
138
|
+
keyboard: CapacitorKeyboardModule;
|
|
139
|
+
preferences: CapacitorPreferencesModule;
|
|
140
|
+
pushNotifications: CapacitorPushNotificationsModule;
|
|
141
|
+
safeArea: CapacitorSafeAreaModule;
|
|
142
|
+
updater: CapacitorUpdaterModule;
|
|
14
143
|
};
|
|
15
144
|
|
|
16
145
|
type CapacitorImportCache = Partial<{
|
|
@@ -40,29 +169,58 @@ const loadCapacitorModule = <K extends keyof CapacitorModuleMap>(
|
|
|
40
169
|
return loaded;
|
|
41
170
|
};
|
|
42
171
|
|
|
43
|
-
|
|
172
|
+
const importNativeModule = <T>(specifier: string) => import(specifier) as Promise<T>;
|
|
173
|
+
|
|
174
|
+
const capacitorPackage = (name: string) => `@capacitor/${name}`;
|
|
44
175
|
|
|
45
|
-
|
|
176
|
+
const capacitorCommunityPackage = (name: string) => `@capacitor-community/${name}`;
|
|
46
177
|
|
|
47
|
-
export const
|
|
178
|
+
export const loadCapacitorApp = () =>
|
|
179
|
+
loadCapacitorModule("app", () => importNativeModule<CapacitorAppModule>(capacitorPackage("app")));
|
|
180
|
+
|
|
181
|
+
export const loadCapacitorBrowser = () =>
|
|
182
|
+
loadCapacitorModule("browser", () => importNativeModule<CapacitorBrowserModule>(capacitorPackage("browser")));
|
|
183
|
+
|
|
184
|
+
export const loadCapacitorCamera = () =>
|
|
185
|
+
loadCapacitorModule("camera", () => importNativeModule<CapacitorCameraModule>(capacitorPackage("camera")));
|
|
48
186
|
|
|
49
187
|
export const loadCapacitorContacts = () =>
|
|
50
|
-
loadCapacitorModule("contacts", () =>
|
|
188
|
+
loadCapacitorModule("contacts", () =>
|
|
189
|
+
importNativeModule<CapacitorContactsModule>(capacitorCommunityPackage("contacts")),
|
|
190
|
+
);
|
|
51
191
|
|
|
52
|
-
export const
|
|
192
|
+
export const loadCapacitorCore = () =>
|
|
193
|
+
loadCapacitorModule("core", () => importNativeModule<CapacitorCoreModule>(capacitorPackage("core")));
|
|
53
194
|
|
|
54
|
-
export const
|
|
195
|
+
export const loadCapacitorDevice = () =>
|
|
196
|
+
loadCapacitorModule("device", () => importNativeModule<CapacitorDeviceModule>(capacitorPackage("device")));
|
|
197
|
+
|
|
198
|
+
export const loadCapacitorFcm = () =>
|
|
199
|
+
loadCapacitorModule("fcm", () => importNativeModule<CapacitorFcmModule>(capacitorCommunityPackage("fcm")));
|
|
55
200
|
|
|
56
201
|
export const loadCapacitorGeolocation = () =>
|
|
57
|
-
loadCapacitorModule("geolocation", () =>
|
|
202
|
+
loadCapacitorModule("geolocation", () =>
|
|
203
|
+
importNativeModule<CapacitorGeolocationModule>(capacitorPackage("geolocation")),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
export const loadCapacitorHaptics = () =>
|
|
207
|
+
loadCapacitorModule("haptics", () => importNativeModule<CapacitorHapticsModule>(capacitorPackage("haptics")));
|
|
58
208
|
|
|
59
|
-
export const
|
|
209
|
+
export const loadCapacitorKeyboard = () =>
|
|
210
|
+
loadCapacitorModule("keyboard", () => importNativeModule<CapacitorKeyboardModule>(capacitorPackage("keyboard")));
|
|
60
211
|
|
|
61
|
-
export const
|
|
212
|
+
export const loadCapacitorPreferences = () =>
|
|
213
|
+
loadCapacitorModule("preferences", () =>
|
|
214
|
+
importNativeModule<CapacitorPreferencesModule>(capacitorPackage("preferences")),
|
|
215
|
+
);
|
|
62
216
|
|
|
63
217
|
export const loadCapacitorPushNotifications = () =>
|
|
64
|
-
loadCapacitorModule("pushNotifications", () =>
|
|
218
|
+
loadCapacitorModule("pushNotifications", () =>
|
|
219
|
+
importNativeModule<CapacitorPushNotificationsModule>(capacitorPackage("push-notifications")),
|
|
220
|
+
);
|
|
65
221
|
|
|
66
|
-
export const loadCapacitorSafeArea = () =>
|
|
222
|
+
export const loadCapacitorSafeArea = () =>
|
|
223
|
+
loadCapacitorModule("safeArea", () => importNativeModule<CapacitorSafeAreaModule>("capacitor-plugin-safe-area"));
|
|
67
224
|
|
|
68
|
-
export const loadCapacitorUpdater = () =>
|
|
225
|
+
export const loadCapacitorUpdater = () =>
|
|
226
|
+
loadCapacitorModule("updater", () => importNativeModule<CapacitorUpdaterModule>("@capgo/capacitor-updater"));
|
package/client/cookie.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { getEnv } from "akanjs/base";
|
|
|
2
2
|
import { decodeJwtPayload, Logger } from "akanjs/common";
|
|
3
3
|
import type { Account } from "akanjs/fetch";
|
|
4
4
|
import { requestStorage } from "akanjs/fetch";
|
|
5
|
+
import { loadCapacitorCore } from "./capacitor";
|
|
5
6
|
import { storage } from "./storage";
|
|
6
7
|
import { fetch } from "./useClient";
|
|
7
8
|
|
|
@@ -42,11 +43,18 @@ export const setCookie = (
|
|
|
42
43
|
value: string,
|
|
43
44
|
options: CookieOptions = { path: "/", sameSite: "none", secure: true },
|
|
44
45
|
) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const env = getEnv();
|
|
47
|
+
if (env.side === "server") return;
|
|
48
|
+
const encoded = `${key}=${value}`;
|
|
49
|
+
const path = options.path ? `; path=${options.path}` : "";
|
|
50
|
+
const sameSite = options.sameSite ? `; SameSite=${options.sameSite}` : "";
|
|
51
|
+
const secure = options.secure ? "; Secure" : "";
|
|
52
|
+
|
|
53
|
+
document.cookie = `${encoded}${path}${sameSite}${secure}`;
|
|
54
|
+
if (env.renderMode !== "csr") return;
|
|
55
|
+
void loadCapacitorCore()
|
|
56
|
+
.then(({ CapacitorCookies }) => CapacitorCookies.setCookie({ key, value, path: options.path }))
|
|
57
|
+
.catch(() => undefined);
|
|
50
58
|
};
|
|
51
59
|
|
|
52
60
|
export const getCookie = (key: string): string | undefined => {
|
|
@@ -61,6 +69,7 @@ export const getCookie = (key: string): string | undefined => {
|
|
|
61
69
|
export const removeCookie = (key: string, options: { path: string } = { path: "/" }) => {
|
|
62
70
|
if (getEnv().side === "server") return cookies().delete(key);
|
|
63
71
|
else {
|
|
72
|
+
|
|
64
73
|
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
65
74
|
}
|
|
66
75
|
};
|
package/client/device.ts
CHANGED
|
@@ -1,19 +1,82 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import type { DeviceInfo } from "@capacitor/device";
|
|
3
|
-
import type { KeyboardInfo } from "@capacitor/keyboard";
|
|
4
2
|
import type { RefObject } from "react";
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import type {
|
|
4
|
+
CapacitorDeviceInfo,
|
|
5
|
+
CapacitorHapticsModule,
|
|
6
|
+
CapacitorKeyboardInfo,
|
|
7
|
+
CapacitorKeyboardModule,
|
|
8
|
+
} from "./capacitor";
|
|
9
|
+
|
|
10
|
+
type DeviceInfo = CapacitorDeviceInfo;
|
|
11
|
+
type Keyboard = CapacitorKeyboardModule["Keyboard"];
|
|
12
|
+
type Haptics = CapacitorHapticsModule["Haptics"];
|
|
13
|
+
type ImpactStyle = CapacitorHapticsModule["ImpactStyle"];
|
|
14
|
+
type ProcessEnvLike = { env?: Record<string, string | undefined> };
|
|
15
|
+
|
|
16
|
+
const globalWithProcess = globalThis as typeof globalThis & { process?: ProcessEnvLike };
|
|
7
17
|
|
|
8
18
|
interface DeviceInitOption {
|
|
9
19
|
lang: string;
|
|
10
20
|
info: DeviceInfo;
|
|
11
21
|
topSafeArea: number;
|
|
12
22
|
bottomSafeArea: number;
|
|
13
|
-
keyboard:
|
|
14
|
-
haptics:
|
|
15
|
-
impactStyle:
|
|
23
|
+
keyboard: Keyboard;
|
|
24
|
+
haptics: Haptics;
|
|
25
|
+
impactStyle: ImpactStyle;
|
|
16
26
|
}
|
|
27
|
+
|
|
28
|
+
const noopKeyboard: Keyboard = {
|
|
29
|
+
show: async () => undefined,
|
|
30
|
+
hide: async () => undefined,
|
|
31
|
+
addListener: async () => undefined,
|
|
32
|
+
removeAllListeners: async () => undefined,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const noopHaptics: Haptics = {
|
|
36
|
+
vibrate: async () => undefined,
|
|
37
|
+
impact: async () => undefined,
|
|
38
|
+
selectionStart: async () => undefined,
|
|
39
|
+
selectionChanged: async () => undefined,
|
|
40
|
+
selectionEnd: async () => undefined,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const noopImpactStyle: ImpactStyle = {
|
|
44
|
+
Light: "light",
|
|
45
|
+
Medium: "medium",
|
|
46
|
+
Heavy: "heavy",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getRenderMode = () => globalWithProcess.process?.env?.AKAN_PUBLIC_RENDER_ENV ?? "csr";
|
|
50
|
+
|
|
51
|
+
const getBrowserLanguage = () => globalThis.navigator?.language?.split("-")[0] ?? "en";
|
|
52
|
+
|
|
53
|
+
export const isMobileDevice = () => {
|
|
54
|
+
if (typeof navigator === "undefined") return false;
|
|
55
|
+
if (typeof window !== "undefined" && window.matchMedia?.("(hover: none) and (pointer: coarse)")?.matches) return true;
|
|
56
|
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const createWebDevice = ({
|
|
60
|
+
lang,
|
|
61
|
+
supportLanguages,
|
|
62
|
+
}: {
|
|
63
|
+
lang?: string;
|
|
64
|
+
supportLanguages: string[] | readonly string[];
|
|
65
|
+
}) => {
|
|
66
|
+
const pathname = typeof window === "undefined" ? "" : window.location.pathname;
|
|
67
|
+
const predefinedLangPath = pathname.split("/")[1]?.split("?")[0];
|
|
68
|
+
const predefinedLang = supportLanguages.find((language) => language === predefinedLangPath);
|
|
69
|
+
return new Device({
|
|
70
|
+
lang: lang ?? predefinedLang ?? getBrowserLanguage(),
|
|
71
|
+
info: { platform: "web", isVirtual: false, osVersion: "" },
|
|
72
|
+
topSafeArea: 0,
|
|
73
|
+
bottomSafeArea: 0,
|
|
74
|
+
keyboard: noopKeyboard,
|
|
75
|
+
haptics: noopHaptics,
|
|
76
|
+
impactStyle: noopImpactStyle,
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
17
80
|
/** Capacitor-aware device helper for platform info, safe areas, keyboard, haptics, and scroll state. */
|
|
18
81
|
export class Device {
|
|
19
82
|
static instance: Device | null = null;
|
|
@@ -25,6 +88,14 @@ export class Device {
|
|
|
25
88
|
supportLanguages?: string[] | readonly string[];
|
|
26
89
|
}) {
|
|
27
90
|
if (Device.instance) return Device.instance;
|
|
91
|
+
if (getRenderMode() !== "csr") {
|
|
92
|
+
const device = createWebDevice({ lang, supportLanguages });
|
|
93
|
+
Device.instance = device;
|
|
94
|
+
return device;
|
|
95
|
+
}
|
|
96
|
+
const { loadCapacitorDevice, loadCapacitorHaptics, loadCapacitorKeyboard, loadCapacitorSafeArea } = await import(
|
|
97
|
+
"./capacitor"
|
|
98
|
+
);
|
|
28
99
|
const [{ Device: CapacitorDevice }, { Keyboard }, { Haptics, ImpactStyle }, { SafeArea }] = await Promise.all([
|
|
29
100
|
loadCapacitorDevice(),
|
|
30
101
|
loadCapacitorKeyboard(),
|
|
@@ -61,7 +132,7 @@ export class Device {
|
|
|
61
132
|
lang: string;
|
|
62
133
|
topSafeArea: number;
|
|
63
134
|
bottomSafeArea: number;
|
|
64
|
-
isMobile =
|
|
135
|
+
isMobile = isMobileDevice();
|
|
65
136
|
#keyboard: DeviceInitOption["keyboard"];
|
|
66
137
|
#haptics: DeviceInitOption["haptics"];
|
|
67
138
|
#impactStyle: DeviceInitOption["impactStyle"];
|
|
@@ -89,10 +160,10 @@ export class Device {
|
|
|
89
160
|
}
|
|
90
161
|
listenKeyboardChanged(onKeyboardChanged: (height: number) => void) {
|
|
91
162
|
if (this.info.platform === "web") return;
|
|
92
|
-
void this.#keyboard.addListener("keyboardWillShow", (keyboard:
|
|
163
|
+
void this.#keyboard.addListener("keyboardWillShow", (keyboard: CapacitorKeyboardInfo) => {
|
|
93
164
|
onKeyboardChanged(keyboard.keyboardHeight);
|
|
94
165
|
});
|
|
95
|
-
void this.#keyboard.addListener("keyboardDidShow", (keyboard:
|
|
166
|
+
void this.#keyboard.addListener("keyboardDidShow", (keyboard: CapacitorKeyboardInfo) => {
|
|
96
167
|
onKeyboardChanged(keyboard.keyboardHeight);
|
|
97
168
|
});
|
|
98
169
|
void this.#keyboard.addListener("keyboardWillHide", () => {
|
package/client/index.ts
CHANGED
package/client/storage.ts
CHANGED
|
@@ -1,33 +1,57 @@
|
|
|
1
1
|
import { getEnv } from "akanjs/base";
|
|
2
|
+
import { loadCapacitorPreferences } from "./capacitor";
|
|
3
|
+
|
|
4
|
+
const getLocalStorageItem = (key: string) => localStorage.getItem(key);
|
|
5
|
+
|
|
6
|
+
const setLocalStorageItem = (key: string, value: string) => {
|
|
7
|
+
localStorage.setItem(key, value);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const removeLocalStorageItem = (key: string) => {
|
|
11
|
+
localStorage.removeItem(key);
|
|
12
|
+
};
|
|
2
13
|
|
|
3
14
|
export const storage = {
|
|
4
15
|
getItem: async (key: string) => {
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
const env = getEnv();
|
|
17
|
+
if (env.side === "server") return;
|
|
18
|
+
if (env.renderMode === "ssr") return getLocalStorageItem(key);
|
|
19
|
+
try {
|
|
20
|
+
const { Preferences } = await loadCapacitorPreferences();
|
|
9
21
|
return (await Preferences.get({ key })).value;
|
|
22
|
+
} catch {
|
|
23
|
+
return getLocalStorageItem(key);
|
|
10
24
|
}
|
|
11
25
|
},
|
|
12
26
|
setItem: async (key: string, value: string) => {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
27
|
+
const env = getEnv();
|
|
28
|
+
if (env.side === "server") return;
|
|
29
|
+
if (env.renderMode === "ssr") {
|
|
30
|
+
setLocalStorageItem(key, value);
|
|
16
31
|
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const { Preferences } = await loadCapacitorPreferences();
|
|
19
35
|
await Preferences.set({ key, value });
|
|
20
36
|
return;
|
|
37
|
+
} catch {
|
|
38
|
+
setLocalStorageItem(key, value);
|
|
39
|
+
return;
|
|
21
40
|
}
|
|
22
41
|
},
|
|
23
42
|
removeItem: async (key: string) => {
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
43
|
+
const env = getEnv();
|
|
44
|
+
if (env.side === "server") return;
|
|
45
|
+
if (env.renderMode === "ssr") {
|
|
46
|
+
removeLocalStorageItem(key);
|
|
27
47
|
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const { Preferences } = await loadCapacitorPreferences();
|
|
30
51
|
return Preferences.remove({ key });
|
|
52
|
+
} catch {
|
|
53
|
+
removeLocalStorageItem(key);
|
|
54
|
+
return;
|
|
31
55
|
}
|
|
32
56
|
},
|
|
33
57
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akanjs",
|
|
3
|
-
"version": "2.1.0-rc.
|
|
3
|
+
"version": "2.1.0-rc.4",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -90,6 +90,11 @@
|
|
|
90
90
|
"import": "./client/index.ts",
|
|
91
91
|
"default": "./client/index.ts"
|
|
92
92
|
},
|
|
93
|
+
"./client/capacitor": {
|
|
94
|
+
"types": "./types/client/capacitor.d.ts",
|
|
95
|
+
"import": "./client/capacitor.ts",
|
|
96
|
+
"default": "./client/capacitor.ts"
|
|
97
|
+
},
|
|
93
98
|
"./webkit": {
|
|
94
99
|
"types": "./types/webkit/index.d.ts",
|
|
95
100
|
"import": "./webkit/index.ts",
|
|
@@ -173,15 +178,12 @@
|
|
|
173
178
|
"cordova-plugin-purchase": "^13.16.0",
|
|
174
179
|
"croner": "^10.0.1",
|
|
175
180
|
"daisyui": "^5.5.20",
|
|
176
|
-
"file-saver": "^2.0.5",
|
|
177
181
|
"ioredis": "^5.10.1",
|
|
178
182
|
"mermaid": "^11.15.0",
|
|
179
183
|
"postgres": "^3.4.9",
|
|
180
184
|
"protobufjs": "^8.4.0",
|
|
181
185
|
"react": "19.2.6",
|
|
182
|
-
"react-copy-to-clipboard": "^5.1.1",
|
|
183
186
|
"react-datepicker": "^9.1.0",
|
|
184
|
-
"react-device-detect": "^2.2.3",
|
|
185
187
|
"react-dom": "19.2.6",
|
|
186
188
|
"react-icons": "^5.6.0",
|
|
187
189
|
"react-refresh": "^0.18.0",
|
|
@@ -266,9 +268,6 @@
|
|
|
266
268
|
"daisyui": {
|
|
267
269
|
"optional": true
|
|
268
270
|
},
|
|
269
|
-
"file-saver": {
|
|
270
|
-
"optional": true
|
|
271
|
-
},
|
|
272
271
|
"ioredis": {
|
|
273
272
|
"optional": true
|
|
274
273
|
},
|
|
@@ -284,15 +283,9 @@
|
|
|
284
283
|
"react": {
|
|
285
284
|
"optional": true
|
|
286
285
|
},
|
|
287
|
-
"react-copy-to-clipboard": {
|
|
288
|
-
"optional": true
|
|
289
|
-
},
|
|
290
286
|
"react-datepicker": {
|
|
291
287
|
"optional": true
|
|
292
288
|
},
|
|
293
|
-
"react-device-detect": {
|
|
294
|
-
"optional": true
|
|
295
|
-
},
|
|
296
289
|
"react-dom": {
|
|
297
290
|
"optional": true
|
|
298
291
|
},
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
type LoggingAdaptor,
|
|
15
15
|
LoggingAdaptorRole,
|
|
16
16
|
PostgresDatabase,
|
|
17
|
-
|
|
17
|
+
JsonCompressor,
|
|
18
18
|
type QueueAdaptor,
|
|
19
19
|
QueueAdaptorRole,
|
|
20
20
|
RedisCache,
|
|
@@ -62,7 +62,7 @@ export const predefinedAdaptor = {
|
|
|
62
62
|
schedule: Scheduler,
|
|
63
63
|
logging: ConsoleLogger,
|
|
64
64
|
websocket: SolidPubSub,
|
|
65
|
-
compress:
|
|
65
|
+
compress: JsonCompressor,
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export const getPredefinedAdaptor = (mode: DatabaseMode = "single"): PredefinedAdaptor => {
|