esoftplay 0.0.269-beta7318487 → 0.0.269-beta8d1f009
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/bin/build.js +2 -1
- package/modules/lib/curl.ts +10 -7
- package/modules/lib/navigation.ts +103 -50
- package/package.json +1 -1
package/bin/build.js
CHANGED
|
@@ -218,7 +218,8 @@ if (fs.existsSync(packjson)) {
|
|
|
218
218
|
}
|
|
219
219
|
}`
|
|
220
220
|
|
|
221
|
-
|
|
221
|
+
if (!fs.existsSync(easjson))
|
|
222
|
+
writeFileSyncWithLog(easjson, easconfg);
|
|
222
223
|
|
|
223
224
|
|
|
224
225
|
const metroConfig = `// Learn more https://docs.expo.io/guides/customizing-metro
|
package/modules/lib/curl.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import esp from 'esoftplay/esp';
|
|
5
5
|
import { LibCrypt } from 'esoftplay/cache/lib/crypt/import';
|
|
6
6
|
import { reportApiError } from "esoftplay/error";
|
|
7
|
+
import { File } from 'expo-file-system';
|
|
7
8
|
|
|
8
9
|
//api_logger_import
|
|
9
10
|
|
|
@@ -30,7 +31,7 @@ export default class m {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
constructor(uri?: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (error: any, timeout: boolean) => void, debug?: number) {
|
|
33
|
-
this.header = { version: esp.config()?.publish_id }
|
|
34
|
+
this.header = { version: (esp.config()?.publish_id).toString() }
|
|
34
35
|
// this.maxRetry = 2;
|
|
35
36
|
this.setUri = this.setUri.bind(this);
|
|
36
37
|
this.setUrl = this.setUrl.bind(this);
|
|
@@ -356,11 +357,12 @@ export default class m {
|
|
|
356
357
|
if (post) {
|
|
357
358
|
if (upload) {
|
|
358
359
|
let fd = new FormData();
|
|
359
|
-
Object.keys(post).map(
|
|
360
|
+
await Promise.all(Object.keys(post).map(async (key) => {
|
|
360
361
|
if (post[key] !== undefined) {
|
|
361
|
-
|
|
362
|
+
const file = new File(post[key].uri)
|
|
363
|
+
fd.append(key, file as any, post[key].name)
|
|
362
364
|
}
|
|
363
|
-
});
|
|
365
|
+
}));
|
|
364
366
|
this.post = fd
|
|
365
367
|
} else {
|
|
366
368
|
let ps = Object.keys(post).map((key) => {
|
|
@@ -383,10 +385,11 @@ export default class m {
|
|
|
383
385
|
this.setUrl(esp.config("url"))
|
|
384
386
|
}
|
|
385
387
|
await this.setHeader();
|
|
386
|
-
if (upload)
|
|
387
|
-
this.header["Content-Type"] = "multipart/form-data"
|
|
388
|
-
else
|
|
388
|
+
if (!upload)
|
|
389
389
|
this.header["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8"
|
|
390
|
+
else
|
|
391
|
+
delete this.header["Content-Type"]
|
|
392
|
+
|
|
390
393
|
let options: any = {
|
|
391
394
|
method: !this.post ? "GET" : "POST",
|
|
392
395
|
headers: this.header,
|
|
@@ -10,7 +10,7 @@ import { UserRoutes } from 'esoftplay/cache/user/routes/import';
|
|
|
10
10
|
|
|
11
11
|
import esp from 'esoftplay/esp';
|
|
12
12
|
import useGlobalState, { useGlobalReturn } from 'esoftplay/global';
|
|
13
|
-
import React, { useEffect } from "react";
|
|
13
|
+
import React, { useEffect, useSyncExternalStore } from "react";
|
|
14
14
|
|
|
15
15
|
export interface LibNavigationTabConfigReturn<S extends keyof EspArgsInterface> {
|
|
16
16
|
activeIndex: number,
|
|
@@ -23,7 +23,44 @@ export interface LibNavigationInjector {
|
|
|
23
23
|
children?: any
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
interface LibNavigationState {
|
|
27
|
+
redirect: Record<number, { func: Function }>,
|
|
28
|
+
data: Record<string | number, any>,
|
|
29
|
+
ref: any,
|
|
30
|
+
isReady: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const initialNavigationState: LibNavigationState = {
|
|
34
|
+
redirect: {},
|
|
35
|
+
data: {},
|
|
36
|
+
ref: undefined,
|
|
37
|
+
isReady: false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let navigationState = initialNavigationState
|
|
41
|
+
const navigationSubscribers = new Set<() => void>()
|
|
42
|
+
|
|
43
|
+
const navigationStore = {
|
|
44
|
+
getSnapshot: () => navigationState,
|
|
45
|
+
subscribe: (callback: () => void) => {
|
|
46
|
+
navigationSubscribers.add(callback)
|
|
47
|
+
return () => navigationSubscribers.delete(callback)
|
|
48
|
+
},
|
|
49
|
+
setState: (nextState: LibNavigationState) => {
|
|
50
|
+
navigationState = nextState
|
|
51
|
+
navigationSubscribers.forEach((callback) => callback())
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function useNavigationState(): LibNavigationState {
|
|
56
|
+
return useSyncExternalStore(
|
|
57
|
+
navigationStore.subscribe,
|
|
58
|
+
navigationStore.getSnapshot,
|
|
59
|
+
navigationStore.getSnapshot
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const lastArgs = useGlobalState(undefined, { persistKey: "lib/navigation/lastargs", inFastStorage: true, loadOnInit: true })
|
|
27
64
|
|
|
28
65
|
function logArgs(params: any) {
|
|
29
66
|
lastArgs.set(params)
|
|
@@ -31,17 +68,25 @@ function logArgs(params: any) {
|
|
|
31
68
|
|
|
32
69
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md) untuk melihat dokumentasi*/
|
|
33
70
|
export default {
|
|
34
|
-
_redirect
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
71
|
+
get _redirect() {
|
|
72
|
+
return navigationStore.getSnapshot().redirect
|
|
73
|
+
},
|
|
74
|
+
get _data() {
|
|
75
|
+
return navigationStore.getSnapshot().data
|
|
76
|
+
},
|
|
77
|
+
get _ref() {
|
|
78
|
+
return navigationStore.getSnapshot().ref
|
|
79
|
+
},
|
|
80
|
+
get _isReady() {
|
|
81
|
+
return navigationStore.getSnapshot().isReady
|
|
82
|
+
},
|
|
38
83
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setRef) untuk melihat dokumentasi*/
|
|
39
84
|
setRef(ref: any): void {
|
|
40
|
-
|
|
85
|
+
navigationStore.setState({ ...navigationStore.getSnapshot(), ref })
|
|
41
86
|
},
|
|
42
87
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setIsReady) untuk melihat dokumentasi*/
|
|
43
88
|
setIsReady(isReady: boolean): void {
|
|
44
|
-
|
|
89
|
+
navigationStore.setState({ ...navigationStore.getSnapshot(), isReady });
|
|
45
90
|
},
|
|
46
91
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#getIsReady) untuk melihat dokumentasi*/
|
|
47
92
|
getIsReady(): boolean {
|
|
@@ -49,7 +94,8 @@ export default {
|
|
|
49
94
|
},
|
|
50
95
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setNavigation) untuk melihat dokumentasi*/
|
|
51
96
|
setNavigation(nav: any): void {
|
|
52
|
-
|
|
97
|
+
const state = navigationStore.getSnapshot()
|
|
98
|
+
navigationStore.setState({ ...state, data: { ...state.data, _navigation: nav } })
|
|
53
99
|
},
|
|
54
100
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#getArgs) untuk melihat dokumentasi*/
|
|
55
101
|
getArgs(props: any, key: string, defOutput?: any): any {
|
|
@@ -72,45 +118,49 @@ export default {
|
|
|
72
118
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#setRedirect) untuk melihat dokumentasi*/
|
|
73
119
|
setRedirect(func: Function, key?: number) {
|
|
74
120
|
if (!key) key = 1
|
|
75
|
-
|
|
121
|
+
const state = navigationStore.getSnapshot()
|
|
122
|
+
navigationStore.setState({ ...state, redirect: { ...state.redirect, [key]: { func } } })
|
|
76
123
|
},
|
|
77
124
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#delRedirect) untuk melihat dokumentasi*/
|
|
78
125
|
delRedirect(key?: number) {
|
|
79
126
|
if (!key) key = 1
|
|
80
|
-
|
|
127
|
+
const state = navigationStore.getSnapshot()
|
|
128
|
+
const redirect = { ...state.redirect }
|
|
129
|
+
delete redirect[key]
|
|
130
|
+
navigationStore.setState({ ...state, redirect })
|
|
81
131
|
},
|
|
82
132
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#redirect) untuk melihat dokumentasi*/
|
|
83
133
|
redirect(key?: number) {
|
|
84
134
|
if (!key) key = 1
|
|
85
|
-
|
|
86
|
-
|
|
135
|
+
const redirect = navigationStore.getSnapshot().redirect
|
|
136
|
+
if (redirect?.[key]) {
|
|
137
|
+
const { func } = redirect[key]
|
|
87
138
|
if (typeof func == 'function')
|
|
88
139
|
func()
|
|
89
|
-
|
|
140
|
+
const state = navigationStore.getSnapshot()
|
|
141
|
+
const nextRedirect = { ...state.redirect }
|
|
142
|
+
delete nextRedirect[key]
|
|
143
|
+
navigationStore.setState({ ...state, redirect: nextRedirect })
|
|
90
144
|
}
|
|
91
145
|
},
|
|
92
146
|
/* <T EspRouterInterface>(path: T): EspRouterInterface[T] { */
|
|
93
147
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#navigate) untuk melihat dokumentasi*/
|
|
94
148
|
navigate<S extends keyof EspArgsInterface>(route: S, params?: EspArgsInterface[S]): void {
|
|
95
149
|
logArgs(params)
|
|
96
|
-
|
|
97
|
-
this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
|
|
98
|
-
})
|
|
150
|
+
this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
|
|
99
151
|
},
|
|
100
152
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#navigateTab) untuk melihat dokumentasi*/
|
|
101
153
|
navigateTab<S extends keyof EspArgsInterface>(route: S, tabIndex: number, params?: EspArgsInterface[S]): void {
|
|
102
154
|
logArgs(params)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}, 100);
|
|
113
|
-
})
|
|
155
|
+
this._ref?.navigate?.(replaceModuleByUrlParam(params, route), params)
|
|
156
|
+
setTimeout(() => {
|
|
157
|
+
const TabConfig = esp.modProp(replaceModuleByUrlParam(params, route))?.TabConfig;
|
|
158
|
+
if (TabConfig) {
|
|
159
|
+
TabConfig.set(esp.mod("lib/object").set(TabConfig.get(), tabIndex)('activeIndex'))
|
|
160
|
+
} else {
|
|
161
|
+
console.error("TabConfig not found or exported in module " + route);
|
|
162
|
+
}
|
|
163
|
+
}, 100);
|
|
114
164
|
},
|
|
115
165
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#createTabConfig) untuk melihat dokumentasi*/
|
|
116
166
|
createTabConfig<S extends keyof EspArgsInterface>(modules: S[], defaultIndex?: number): useGlobalReturn<LibNavigationTabConfigReturn<S>> {
|
|
@@ -147,7 +197,10 @@ export default {
|
|
|
147
197
|
key = 1
|
|
148
198
|
}
|
|
149
199
|
try {
|
|
150
|
-
|
|
200
|
+
const state = navigationStore.getSnapshot()
|
|
201
|
+
const data = { ...state.data }
|
|
202
|
+
delete data[key]
|
|
203
|
+
navigationStore.setState({ ...state, data })
|
|
151
204
|
} catch (error) { }
|
|
152
205
|
},
|
|
153
206
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#sendBackResult) untuk melihat dokumentasi*/
|
|
@@ -157,7 +210,10 @@ export default {
|
|
|
157
210
|
}
|
|
158
211
|
if (this._data[key] != undefined) {
|
|
159
212
|
this._data[key](result)
|
|
160
|
-
|
|
213
|
+
const state = navigationStore.getSnapshot()
|
|
214
|
+
const data = { ...state.data }
|
|
215
|
+
delete data[key]
|
|
216
|
+
navigationStore.setState({ ...state, data })
|
|
161
217
|
}
|
|
162
218
|
this.back()
|
|
163
219
|
},
|
|
@@ -172,13 +228,18 @@ export default {
|
|
|
172
228
|
}
|
|
173
229
|
params['_senderKey'] = key
|
|
174
230
|
if (!this._data.hasOwnProperty(key) && key != undefined) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
231
|
+
const state = navigationStore.getSnapshot()
|
|
232
|
+
navigationStore.setState({
|
|
233
|
+
...state,
|
|
234
|
+
data: {
|
|
235
|
+
...state.data,
|
|
236
|
+
[key]: (value: any) => {
|
|
237
|
+
r(value)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
})
|
|
178
241
|
}
|
|
179
|
-
|
|
180
|
-
this.push(replaceModuleByUrlParam(params, route), params)
|
|
181
|
-
})
|
|
242
|
+
this.push(replaceModuleByUrlParam(params, route), params)
|
|
182
243
|
})
|
|
183
244
|
},
|
|
184
245
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#replace) untuk melihat dokumentasi*/
|
|
@@ -191,14 +252,12 @@ export default {
|
|
|
191
252
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#push) untuk melihat dokumentasi*/
|
|
192
253
|
push<S extends keyof EspArgsInterface>(route: S, params?: EspArgsInterface[S]): void {
|
|
193
254
|
logArgs(params)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
params
|
|
199
|
-
)
|
|
255
|
+
this._ref?.dispatch?.(
|
|
256
|
+
StackActions.push(
|
|
257
|
+
replaceModuleByUrlParam(params, route),
|
|
258
|
+
params
|
|
200
259
|
)
|
|
201
|
-
|
|
260
|
+
)
|
|
202
261
|
},
|
|
203
262
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/navigation.md#reset) untuk melihat dokumentasi*/
|
|
204
263
|
reset(route?: LibNavigationRoutes, ...routes: LibNavigationRoutes[]): void {
|
|
@@ -219,9 +278,7 @@ export default {
|
|
|
219
278
|
back(deep?: number): void {
|
|
220
279
|
let _deep = deep || 1
|
|
221
280
|
const popAction = StackActions.pop(_deep);
|
|
222
|
-
|
|
223
|
-
this._ref?.dispatch?.(popAction)
|
|
224
|
-
})
|
|
281
|
+
this._ref?.dispatch?.(popAction)
|
|
225
282
|
},
|
|
226
283
|
|
|
227
284
|
/* return `root` on initialRoute otherwise return the route was active */
|
|
@@ -244,10 +301,6 @@ export default {
|
|
|
244
301
|
}
|
|
245
302
|
}
|
|
246
303
|
|
|
247
|
-
function doIt(func: Function) {
|
|
248
|
-
requestAnimationFrame(() => func())
|
|
249
|
-
}
|
|
250
|
-
|
|
251
304
|
|
|
252
305
|
function replaceModuleByUrlParam<S extends keyof EspArgsInterface>(params: any, defaultModule: S) {
|
|
253
306
|
let module = defaultModule
|
package/package.json
CHANGED