sparkling-navigation 2.0.1 → 2.1.0-rc.2
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/android/src/main/java/com/tiktok/sparkling/method/router/open/AbsRouterOpenMethodIDL.kt +1 -10
- package/android/src/main/java/com/tiktok/sparkling/method/router/open/RouterOpenMethod.kt +1 -17
- package/dist/src/navigate/navigate.d.ts.map +1 -1
- package/dist/src/navigate/navigate.js +27 -18
- package/dist/src/navigate/navigate.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/ios/Sources/Core/Methods/Open/OpenMethod.swift +2 -2
- package/ios/SparklingMethodTests/SPKRouterTest.swift +14 -3
- package/package.json +2 -2
- package/src/__tests__/navigate/navigate.test.ts +42 -0
- package/src/navigate/navigate.d.ts +18 -4
- package/src/navigate/navigate.ts +37 -21
- package/src/open/open.d.ts +1 -1
package/android/src/main/java/com/tiktok/sparkling/method/router/open/AbsRouterOpenMethodIDL.kt
CHANGED
|
@@ -22,7 +22,7 @@ import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseResultMo
|
|
|
22
22
|
*/
|
|
23
23
|
abstract class AbsRouterOpenMethodIDL : AbsSparklingIDLMethod<AbsRouterOpenMethodIDL.IDLMethodOpenParamModel, AbsRouterOpenMethodIDL.IDLMethodOpenResultModel>() {
|
|
24
24
|
|
|
25
|
-
@IDLMethodName(name = "router.open", params = ["scheme", "replace", "replaceType", "useSysBrowser", "animated", "interceptor", "extra"
|
|
25
|
+
@IDLMethodName(name = "router.open", params = ["scheme", "replace", "replaceType", "useSysBrowser", "animated", "interceptor", "extra"])
|
|
26
26
|
final override val name: String = "router.open"
|
|
27
27
|
|
|
28
28
|
|
|
@@ -49,15 +49,6 @@ abstract class AbsRouterOpenMethodIDL : AbsSparklingIDLMethod<AbsRouterOpenMetho
|
|
|
49
49
|
|
|
50
50
|
@get:IDLMethodParamField(required = false, isGetter = true, keyPath = "extra", nestedClassType = IDLMethodOpenExtra::class)
|
|
51
51
|
val extra: IDLMethodOpenExtra?
|
|
52
|
-
|
|
53
|
-
@get:IDLMethodParamField(required = false, isGetter = true, keyPath = "usePost")
|
|
54
|
-
val usePost: Boolean?
|
|
55
|
-
|
|
56
|
-
@get:IDLMethodParamField(required = false, isGetter = true, keyPath = "postBody")
|
|
57
|
-
val postBody: String?
|
|
58
|
-
|
|
59
|
-
@get:IDLMethodParamField(required = false, isGetter = true, keyPath = "postHeader")
|
|
60
|
-
val postHeader: Any?
|
|
61
52
|
}
|
|
62
53
|
|
|
63
54
|
@IDLMethodResultModel
|
|
@@ -13,7 +13,6 @@ import com.tiktok.sparkling.method.registry.core.model.idl.CompletionBlock
|
|
|
13
13
|
import com.tiktok.sparkling.method.registry.core.utils.createXModel
|
|
14
14
|
import com.tiktok.sparkling.method.router.utils.IHostRouterDepend
|
|
15
15
|
import com.tiktok.sparkling.method.router.utils.RouterProvider
|
|
16
|
-
import java.net.URLDecoder
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -23,7 +22,6 @@ import java.net.URLDecoder
|
|
|
23
22
|
class RouterOpenMethod : AbsRouterOpenMethodIDL() {
|
|
24
23
|
|
|
25
24
|
companion object {
|
|
26
|
-
const val KEY_POST_URL_CONFIG = "__post_url_config"
|
|
27
25
|
private const val TAG = "RouterOpenMethod"
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -86,20 +84,6 @@ class RouterOpenMethod : AbsRouterOpenMethodIDL() {
|
|
|
86
84
|
"extra" to (extra ?: emptyMap<Any, Any>())
|
|
87
85
|
)
|
|
88
86
|
|
|
89
|
-
// Handle POST request configuration
|
|
90
|
-
if (params.usePost == true) {
|
|
91
|
-
val decodeBody = try {
|
|
92
|
-
URLDecoder.decode(params.postBody ?: "", "UTF-8")
|
|
93
|
-
} catch (e: Exception) {
|
|
94
|
-
Log.w(TAG, "Failed to decode postBody: ${e.message}")
|
|
95
|
-
params.postBody ?: ""
|
|
96
|
-
}
|
|
97
|
-
extraInfo[KEY_POST_URL_CONFIG] = mutableMapOf<String, String>(
|
|
98
|
-
"postBody" to decodeBody,
|
|
99
|
-
"postHeader" to (params.postHeader?.toString() ?: ""),
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
87
|
// Handle non-replace open
|
|
104
88
|
if (!replace) {
|
|
105
89
|
val success = try {
|
|
@@ -154,4 +138,4 @@ enum class ReplaceType {
|
|
|
154
138
|
alwaysCloseAfterOpen,
|
|
155
139
|
alwaysCloseBeforeOpen,
|
|
156
140
|
onlyCloseAfterOpenSucceed
|
|
157
|
-
}
|
|
141
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../src/navigate/navigate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../src/navigate/navigate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,eAAe,EACf,gBAAgB,EAGnB,MAAM,cAAc,CAAC;AAqEtB,wBAAgB,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,CAgDpG"}
|
|
@@ -15,22 +15,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
15
15
|
import { open } from '../open/open';
|
|
16
16
|
const DEFAULT_ROUTER_SCHEME = 'hybrid://lynxview_page';
|
|
17
17
|
const PROTOCOL_REGEX = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
18
|
-
const ALLOWED_SCHEME_PARAMS = new Set([
|
|
19
|
-
'bundle',
|
|
20
|
-
'title',
|
|
21
|
-
'fallback_url',
|
|
22
|
-
'title_color',
|
|
23
|
-
'hide_nav_bar',
|
|
24
|
-
'nav_bar_color',
|
|
25
|
-
'screen_orientation',
|
|
26
|
-
'hide_status_bar',
|
|
27
|
-
'trans_status_bar',
|
|
28
|
-
'hide_loading',
|
|
29
|
-
'loading_bg_color',
|
|
30
|
-
'container_bg_color',
|
|
31
|
-
'hide_error',
|
|
32
|
-
'force_theme_style',
|
|
33
|
-
]);
|
|
34
18
|
function createErrorResponse(msg) {
|
|
35
19
|
return {
|
|
36
20
|
code: -1,
|
|
@@ -43,13 +27,37 @@ function normalizePath(path) {
|
|
|
43
27
|
normalized = normalized.replace(/^(?:\.\/|\/)+/, '');
|
|
44
28
|
return normalized;
|
|
45
29
|
}
|
|
30
|
+
function getDevServerBaseURL() {
|
|
31
|
+
try {
|
|
32
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__ && typeof __webpack_public_path__ === 'string' && __webpack_public_path__) {
|
|
33
|
+
return __webpack_public_path__;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (_a) {
|
|
37
|
+
// __DEV__ or __webpack_public_path__ not available
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
46
41
|
function buildScheme(baseScheme, bundlePath, params) {
|
|
47
42
|
const sanitizedBase = (baseScheme || DEFAULT_ROUTER_SCHEME).trim().replace(/[?&]+$/, '') || DEFAULT_ROUTER_SCHEME;
|
|
48
43
|
const searchParams = new URLSearchParams();
|
|
49
|
-
|
|
44
|
+
const devBaseURL = getDevServerBaseURL();
|
|
45
|
+
if (devBaseURL) {
|
|
46
|
+
// In dev mode, use url= to load bundles from the dev server
|
|
47
|
+
const fullURL = `${devBaseURL.replace(/\/+$/, '')}/${bundlePath}`;
|
|
48
|
+
searchParams.set('url', fullURL);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
searchParams.set('bundle', bundlePath);
|
|
52
|
+
}
|
|
50
53
|
if (params && typeof params === 'object') {
|
|
51
54
|
for (const key of Object.keys(params)) {
|
|
52
|
-
if (
|
|
55
|
+
if (devBaseURL) {
|
|
56
|
+
if (key === 'url' || key === 'bundle') {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (key === 'bundle' || key === 'url') {
|
|
53
61
|
continue;
|
|
54
62
|
}
|
|
55
63
|
const value = params[key];
|
|
@@ -90,6 +98,7 @@ export function navigate(params, callback) {
|
|
|
90
98
|
}
|
|
91
99
|
const bundlePath = normalizePath(params.path);
|
|
92
100
|
const _c = (_a = params.options) !== null && _a !== void 0 ? _a : {}, { params: schemeParams } = _c, restOptions = __rest(_c, ["params"]);
|
|
101
|
+
delete restOptions.extra;
|
|
93
102
|
if (!bundlePath) {
|
|
94
103
|
callback(createErrorResponse('Invalid params: path must resolve to a bundle name'));
|
|
95
104
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigate.js","sourceRoot":"","sources":["../../../src/navigate/navigate.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAsC;AACtC,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"navigate.js","sourceRoot":"","sources":["../../../src/navigate/navigate.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAsC;AACtC,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAWpC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AACvD,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,SAAS,mBAAmB,CAAC,GAAW;IACpC,OAAO;QACH,IAAI,EAAE,CAAC,CAAC;QACR,GAAG;KACN,CAAC;AACN,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IAC/B,IAAI,UAAU,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC7B,8DAA8D;IAC9D,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IACrD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,SAAS,mBAAmB;IACxB,IAAI,CAAC;QACD,IAAI,OAAO,O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C9E,OAAO;IACX,CAAC;IAED,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,KAA2C,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,EAA/D,EAAE,MAAM,EAAE,YAAY,OAAyC,EAApC,WAAW,cAAtC,UAAwC,CAAuB,CAAC;IACtE,OAAQ,WAAuC,CAAC,KAAK,CAAC;IAEtD,IAAI,CAAC,UAAU,EAAE,CAAC;QACd,QAAQ,CAAC,mBAAmB,CAAC,oDAAoD,CAAC,CAAC,CAAC;QACpF,OAAO;IACX,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAA,MAAM,CAAC,UAAU,mCAAI,qBAAqB,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IAEjG,IAAI,CACA;QACI,MAAM;QACN,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;KACrE,EACD,QAAQ,CACX,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"fileNames":["../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../sparkling-method/dist/types.d.ts","../../../sparkling-method/dist/index.d.ts","../src/close/close.d.ts","../src/close/close.ts","../src/open/open.d.ts","../src/open/open.ts","../src/navigate/navigate.d.ts","../src/navigate/navigate.ts","../index.ts","../../../../node_modules/.pnpm/@jest+expect-utils@29.7.0/node_modules/@jest/expect-utils/build/index.d.ts","../../../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/index.d.ts","../../../../node_modules/.pnpm/@sinclair+typebox@0.27.10/node_modules/@sinclair/typebox/typebox.d.ts","../../../../node_modules/.pnpm/@jest+schemas@29.6.3/node_modules/@jest/schemas/build/index.d.ts","../../../../node_modules/.pnpm/pretty-format@29.7.0/node_modules/pretty-format/build/index.d.ts","../../../../node_modules/.pnpm/jest-diff@29.7.0/node_modules/jest-diff/build/index.d.ts","../../../../node_modules/.pnpm/jest-matcher-utils@29.7.0/node_modules/jest-matcher-utils/build/index.d.ts","../../../../node_modules/.pnpm/expect@29.7.0/node_modules/expect/build/index.d.ts","../../../../node_modules/.pnpm/@types+jest@29.5.14/node_modules/@types/jest/index.d.ts"],"fileIdsList":[[26],[28,31],[24,30],[28],[25,29],[27],[17,18,19,20,21,22],[16,17],[19],[20,21],[16,19],[15]],"fileInfos":[{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},"f7633d7fe074d6a4f1d215bbc7a3b27fc0419a5a3bfbbe054ac07f3dbbc68487","bdddec6a06096ab2fc1460e59d0e8c1c954ffe72290bee32bc1ecce28ebe9393","582fe2e974682a46dcee0b08fac869d96c56ec3421ad48633f6289f497acc3fd",{"version":"437d1d1bf67ea36dbf6f48e75dc75f7385e58e91d5a0acc493cbc1cec23c59fa","signature":"f421088758adc5b04e44c1548f2d7ac1cebbdda08458c8e493a490002c8e6f7c"},"
|
|
1
|
+
{"fileNames":["../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../sparkling-method/dist/types.d.ts","../../../sparkling-method/dist/index.d.ts","../src/close/close.d.ts","../src/close/close.ts","../src/open/open.d.ts","../src/open/open.ts","../src/navigate/navigate.d.ts","../src/navigate/navigate.ts","../index.ts","../../../../node_modules/.pnpm/@jest+expect-utils@29.7.0/node_modules/@jest/expect-utils/build/index.d.ts","../../../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/index.d.ts","../../../../node_modules/.pnpm/@sinclair+typebox@0.27.10/node_modules/@sinclair/typebox/typebox.d.ts","../../../../node_modules/.pnpm/@jest+schemas@29.6.3/node_modules/@jest/schemas/build/index.d.ts","../../../../node_modules/.pnpm/pretty-format@29.7.0/node_modules/pretty-format/build/index.d.ts","../../../../node_modules/.pnpm/jest-diff@29.7.0/node_modules/jest-diff/build/index.d.ts","../../../../node_modules/.pnpm/jest-matcher-utils@29.7.0/node_modules/jest-matcher-utils/build/index.d.ts","../../../../node_modules/.pnpm/expect@29.7.0/node_modules/expect/build/index.d.ts","../../../../node_modules/.pnpm/@types+jest@29.5.14/node_modules/@types/jest/index.d.ts"],"fileIdsList":[[26],[28,31],[24,30],[28],[25,29],[27],[17,18,19,20,21,22],[16,17],[19],[20,21],[16,19],[15]],"fileInfos":[{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},"f7633d7fe074d6a4f1d215bbc7a3b27fc0419a5a3bfbbe054ac07f3dbbc68487","bdddec6a06096ab2fc1460e59d0e8c1c954ffe72290bee32bc1ecce28ebe9393","582fe2e974682a46dcee0b08fac869d96c56ec3421ad48633f6289f497acc3fd",{"version":"437d1d1bf67ea36dbf6f48e75dc75f7385e58e91d5a0acc493cbc1cec23c59fa","signature":"f421088758adc5b04e44c1548f2d7ac1cebbdda08458c8e493a490002c8e6f7c"},"a078d8603e9ef86dbed7ba0ff50276734c4cefbc5e64a6ab07144911ff701e3b",{"version":"3366f499d525b8ce28ec979521874df660d1a50c85e797781950bb4bf0bc4c95","signature":"dd1d64b74f46208aecdee3727641eff5c0262826752e37a19ca6b2eb474d45af"},"e3963382b8a425258f14e665e7a0d39b024f1e71b7c9200096cdc9604ddf5f94",{"version":"a5e2dd1926904acddffde4e6d5c673a4ed49a5bf1b9d3050f6b77b2ffc6a3305","signature":"e902e6d4f2877e301fa4cf11b50a18c6a1c078bd34edecb15ae62459310004d0"},{"version":"f4ef2dc4d2182f03365773c1c488eb01ebd07186a7d7e3c51eea5eed6c0d5252","signature":"4acdb0a03d91ac0b94410f47337f1dba8f947a74300a305e1e6a14fef3933d07"},{"version":"cdcc132f207d097d7d3aa75615ab9a2e71d6a478162dde8b67f88ea19f3e54de","impliedFormat":1},{"version":"0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","impliedFormat":1},{"version":"e1028394c1cf96d5d057ecc647e31e457b919092f882ed0c7092152b077fed9d","impliedFormat":1},{"version":"f315e1e65a1f80992f0509e84e4ae2df15ecd9ef73df975f7c98813b71e4c8da","impliedFormat":1},{"version":"5b9586e9b0b6322e5bfbd2c29bd3b8e21ab9d871f82346cb71020e3d84bae73e","impliedFormat":1},{"version":"3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","impliedFormat":1},{"version":"ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","impliedFormat":1},{"version":"d96cc6598148bf1a98fb2e8dcf01c63a4b3558bdaec6ef35e087fd0562eb40ec","impliedFormat":1},{"version":"f8db4fea512ab759b2223b90ecbbe7dae919c02f8ce95ec03f7fb1cf757cfbeb","affectsGlobalScope":true,"impliedFormat":1}],"root":[18,20,22,23],"options":{"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":false,"esModuleInterop":true,"module":5,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":true,"target":2},"referencedMap":[[27,1],[32,2],[31,3],[29,4],[30,5],[28,6],[23,7],[18,8],[21,9],[22,10],[20,11],[16,12]],"latestChangedDtsFile":"./index.d.ts","version":"5.8.3"}
|
|
@@ -38,8 +38,8 @@ public class OpenMethodParamModel: SPKMethodModel {
|
|
|
38
38
|
@objc public var useSysBrowser: Bool = false
|
|
39
39
|
@objc public var animated: Bool = false
|
|
40
40
|
@objc public var interceptor: String?
|
|
41
|
-
@objc public var extra:
|
|
42
|
-
|
|
41
|
+
@objc public var extra: NSDictionary?
|
|
42
|
+
|
|
43
43
|
public override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
|
|
44
44
|
return [
|
|
45
45
|
"scheme": "scheme",
|
|
@@ -100,14 +100,25 @@ class SPKRouterTest: XCTestCase {
|
|
|
100
100
|
paramModel.useSysBrowser = true
|
|
101
101
|
paramModel.animated = true
|
|
102
102
|
paramModel.interceptor = "test-interceptor"
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
let extraDict = NSDictionary(dictionary: ["key": "value"])
|
|
104
|
+
paramModel.extra = extraDict
|
|
105
|
+
|
|
105
106
|
XCTAssertEqual(paramModel.scheme, "test-scheme")
|
|
106
107
|
XCTAssertTrue(paramModel.replace)
|
|
107
108
|
XCTAssertEqual(paramModel.replaceType, "all")
|
|
108
109
|
XCTAssertTrue(paramModel.useSysBrowser)
|
|
109
110
|
XCTAssertTrue(paramModel.animated)
|
|
110
111
|
XCTAssertEqual(paramModel.interceptor, "test-interceptor")
|
|
111
|
-
XCTAssertEqual(paramModel.extra,
|
|
112
|
+
XCTAssertEqual(paramModel.extra, extraDict)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func testOpenMethodParamModelFromDictParsesExtraObject() throws {
|
|
116
|
+
let dict: [String: Any] = [
|
|
117
|
+
"scheme": "hybrid://lynxview_page?bundle=a.lynx.bundle",
|
|
118
|
+
"extra": ["foo": "bar"],
|
|
119
|
+
]
|
|
120
|
+
let model = try XCTUnwrap(try OpenMethodParamModel.from(dict: dict))
|
|
121
|
+
XCTAssertNotNil(model.extra)
|
|
122
|
+
XCTAssertEqual(model.extra?["foo"] as? String, "bar")
|
|
112
123
|
}
|
|
113
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sparkling-navigation",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-rc.2",
|
|
4
4
|
"homepage": "https://tiktok.github.io/sparkling/",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"description": "none",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"sparkling-method": "2.0.
|
|
27
|
+
"sparkling-method": "2.1.0-rc.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/jest": "^29.5.12",
|
|
@@ -170,5 +170,47 @@ expect(consoleErrorSpy).toHaveBeenCalledWith('[sparkling-navigation] navigate: c
|
|
|
170
170
|
callback
|
|
171
171
|
);
|
|
172
172
|
});
|
|
173
|
+
|
|
174
|
+
it('should not forward extra to open (host extra is open-only)', () => {
|
|
175
|
+
const params = {
|
|
176
|
+
path: 'main.lynx.bundle',
|
|
177
|
+
options: { animated: true, extra: { foo: 'bar' } },
|
|
178
|
+
} as NavigateRequest;
|
|
179
|
+
const callback = jest.fn();
|
|
180
|
+
|
|
181
|
+
navigate(params, callback);
|
|
182
|
+
|
|
183
|
+
expect(mockOpen).toHaveBeenCalledWith(
|
|
184
|
+
{
|
|
185
|
+
scheme: 'hybrid://lynxview_page?bundle=main.lynx.bundle',
|
|
186
|
+
options: { animated: true },
|
|
187
|
+
},
|
|
188
|
+
callback
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should pass custom (non-predefined) params through to the scheme URL', () => {
|
|
193
|
+
const params: NavigateRequest = {
|
|
194
|
+
path: 'pages/detail.lynx.bundle',
|
|
195
|
+
options: {
|
|
196
|
+
params: {
|
|
197
|
+
title: 'Detail',
|
|
198
|
+
customParam: 'hello',
|
|
199
|
+
itemId: 42,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
const callback = jest.fn();
|
|
204
|
+
|
|
205
|
+
navigate(params, callback);
|
|
206
|
+
|
|
207
|
+
expect(mockOpen).toHaveBeenCalledWith(
|
|
208
|
+
{
|
|
209
|
+
scheme: 'hybrid://lynxview_page?bundle=pages%2Fdetail.lynx.bundle&title=Detail&customParam=hello&itemId=42',
|
|
210
|
+
options: undefined,
|
|
211
|
+
},
|
|
212
|
+
callback
|
|
213
|
+
);
|
|
214
|
+
});
|
|
173
215
|
});
|
|
174
216
|
});
|
|
@@ -13,22 +13,36 @@ export interface NavigateRequest {
|
|
|
13
13
|
export type NavigateParamKey =
|
|
14
14
|
| 'bundle'
|
|
15
15
|
| 'title'
|
|
16
|
-
| 'fallback_url'
|
|
17
16
|
| 'title_color'
|
|
18
17
|
| 'hide_nav_bar'
|
|
19
18
|
| 'nav_bar_color'
|
|
20
19
|
| 'screen_orientation'
|
|
21
20
|
| 'hide_status_bar'
|
|
22
21
|
| 'trans_status_bar'
|
|
22
|
+
| 'show_nav_bar_in_trans_status_bar'
|
|
23
23
|
| 'hide_loading'
|
|
24
24
|
| 'loading_bg_color'
|
|
25
25
|
| 'container_bg_color'
|
|
26
26
|
| 'hide_error'
|
|
27
|
-
| 'force_theme_style'
|
|
27
|
+
| 'force_theme_style'
|
|
28
|
+
| 'status_font_mode'
|
|
29
|
+
| 'hide_back_button';
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
type ThemedColorKey =
|
|
32
|
+
| 'title_color_light'
|
|
33
|
+
| 'title_color_dark'
|
|
34
|
+
| 'nav_bar_color_light'
|
|
35
|
+
| 'nav_bar_color_dark'
|
|
36
|
+
| 'loading_bg_color_light'
|
|
37
|
+
| 'loading_bg_color_dark'
|
|
38
|
+
| 'container_bg_color_light'
|
|
39
|
+
| 'container_bg_color_dark';
|
|
30
40
|
|
|
31
|
-
export type
|
|
41
|
+
export type NavigateParams = Partial<Record<NavigateParamKey | ThemedColorKey, string | number | boolean>> &
|
|
42
|
+
Record<string, string | number | boolean | undefined>;
|
|
43
|
+
|
|
44
|
+
/** Same as {@link OpenOptions} except `extra` — host-only `extra` is only supported on {@link open}, not on `navigate`. */
|
|
45
|
+
export type NavigateOptions = Omit<OpenOptions, 'extra'> & {
|
|
32
46
|
params?: NavigateParams;
|
|
33
47
|
};
|
|
34
48
|
export type NavigateResponse = OpenResponse;
|
package/src/navigate/navigate.ts
CHANGED
|
@@ -2,26 +2,18 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { open } from '../open/open';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
NavigateRequest,
|
|
7
|
+
NavigateResponse,
|
|
8
|
+
NavigateOptions,
|
|
9
|
+
NavigateParams,
|
|
10
|
+
} from './navigate.d';
|
|
11
|
+
|
|
12
|
+
declare const __DEV__: boolean;
|
|
13
|
+
declare const __webpack_public_path__: string;
|
|
6
14
|
|
|
7
15
|
const DEFAULT_ROUTER_SCHEME = 'hybrid://lynxview_page';
|
|
8
16
|
const PROTOCOL_REGEX = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
9
|
-
const ALLOWED_SCHEME_PARAMS = new Set<NavigateParamKey>([
|
|
10
|
-
'bundle',
|
|
11
|
-
'title',
|
|
12
|
-
'fallback_url',
|
|
13
|
-
'title_color',
|
|
14
|
-
'hide_nav_bar',
|
|
15
|
-
'nav_bar_color',
|
|
16
|
-
'screen_orientation',
|
|
17
|
-
'hide_status_bar',
|
|
18
|
-
'trans_status_bar',
|
|
19
|
-
'hide_loading',
|
|
20
|
-
'loading_bg_color',
|
|
21
|
-
'container_bg_color',
|
|
22
|
-
'hide_error',
|
|
23
|
-
'force_theme_style',
|
|
24
|
-
]);
|
|
25
17
|
|
|
26
18
|
function createErrorResponse(msg: string): NavigateResponse {
|
|
27
19
|
return {
|
|
@@ -37,18 +29,41 @@ function normalizePath(path: string): string {
|
|
|
37
29
|
return normalized;
|
|
38
30
|
}
|
|
39
31
|
|
|
32
|
+
function getDevServerBaseURL(): string | undefined {
|
|
33
|
+
try {
|
|
34
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__ && typeof __webpack_public_path__ === 'string' && __webpack_public_path__) {
|
|
35
|
+
return __webpack_public_path__;
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// __DEV__ or __webpack_public_path__ not available
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
40
43
|
function buildScheme(baseScheme: string, bundlePath: string, params?: NavigateOptions['params']): string {
|
|
41
44
|
const sanitizedBase = (baseScheme || DEFAULT_ROUTER_SCHEME).trim().replace(/[?&]+$/, '') || DEFAULT_ROUTER_SCHEME;
|
|
42
45
|
const searchParams = new URLSearchParams();
|
|
43
|
-
|
|
46
|
+
|
|
47
|
+
const devBaseURL = getDevServerBaseURL();
|
|
48
|
+
if (devBaseURL) {
|
|
49
|
+
// In dev mode, use url= to load bundles from the dev server
|
|
50
|
+
const fullURL = `${devBaseURL.replace(/\/+$/, '')}/${bundlePath}`;
|
|
51
|
+
searchParams.set('url', fullURL);
|
|
52
|
+
} else {
|
|
53
|
+
searchParams.set('bundle', bundlePath);
|
|
54
|
+
}
|
|
44
55
|
|
|
45
56
|
if (params && typeof params === 'object') {
|
|
46
|
-
for (const key of Object.keys(params)
|
|
47
|
-
if (
|
|
57
|
+
for (const key of Object.keys(params)) {
|
|
58
|
+
if (devBaseURL) {
|
|
59
|
+
if (key === 'url' || key === 'bundle') {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
} else if (key === 'bundle' || key === 'url') {
|
|
48
63
|
continue;
|
|
49
64
|
}
|
|
50
65
|
|
|
51
|
-
const value = params[key];
|
|
66
|
+
const value = (params as Record<string, unknown>)[key];
|
|
52
67
|
|
|
53
68
|
if (value === undefined || value === null) {
|
|
54
69
|
continue;
|
|
@@ -93,6 +108,7 @@ export function navigate(params: NavigateRequest, callback: (result: NavigateRes
|
|
|
93
108
|
|
|
94
109
|
const bundlePath = normalizePath(params.path);
|
|
95
110
|
const { params: schemeParams, ...restOptions } = params.options ?? {};
|
|
111
|
+
delete (restOptions as Record<string, unknown>).extra;
|
|
96
112
|
|
|
97
113
|
if (!bundlePath) {
|
|
98
114
|
callback(createErrorResponse('Invalid params: path must resolve to a bundle name'));
|
package/src/open/open.d.ts
CHANGED