@ray-js/api 1.4.50 → 1.4.52
Sign up to get free protection for your applications and to get access to all the features.
- package/@types/api-extend.d.ts +3 -3
- package/lib/getCdnUrl/index.d.ts +2 -2
- package/lib/getCdnUrl/index.js +1 -2
- package/lib/getCdnUrl/index.wechat.d.ts +2 -2
- package/lib/getCdnUrl/index.wechat.js +1 -2
- package/lib/panel/i18n/index.d.ts +7 -6
- package/lib/panel/i18n/index.js +26 -11
- package/lib/utils.wechat.d.ts +3 -0
- package/lib/utils.wechat.js +17 -1
- package/package.json +5 -5
package/@types/api-extend.d.ts
CHANGED
@@ -60,8 +60,8 @@ interface CreateAnimationProps {
|
|
60
60
|
|
61
61
|
interface NodesRef {
|
62
62
|
fields(e: any, t: any): SelectorQuery
|
63
|
-
boundingClientRect(e
|
64
|
-
scrollOffset(e
|
63
|
+
boundingClientRect(e?: any): SelectorQuery
|
64
|
+
scrollOffset(e?: any): SelectorQuery
|
65
65
|
}
|
66
66
|
interface SelectorQuery {
|
67
67
|
select: (e: any) => NodesRef
|
@@ -280,7 +280,7 @@ declare namespace ty {
|
|
280
280
|
export function createMapContext(mapId: string): MapContext
|
281
281
|
export function createIpcPlayerContext(deviceId: string): IpcContext
|
282
282
|
export function createCameraContext(): CameraContext
|
283
|
-
export function createWebviewContext(): WebviewContext
|
283
|
+
export function createWebviewContext(mapId: string): WebviewContext
|
284
284
|
export type env = {
|
285
285
|
USER_DATA_PATH: string
|
286
286
|
}
|
package/lib/getCdnUrl/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export default function getCdnUrl(path: string): string;
|
2
|
-
export declare function getCdnUrlAsync(path: string): Promise<string>;
|
1
|
+
export default function getCdnUrl(path: string, cdnMap?: Record<string, string>, region?: string): string;
|
2
|
+
export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string>, region?: string): Promise<string>;
|
package/lib/getCdnUrl/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export default function getCdnUrl(path: string): string;
|
2
|
-
export declare function getCdnUrlAsync(path: string): Promise<string>;
|
1
|
+
export default function getCdnUrl(path: string, cdnMap?: Record<string, string>, region?: string): string;
|
2
|
+
export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string>, region?: string): Promise<string>;
|
@@ -1,27 +1,28 @@
|
|
1
1
|
type LanguageMap = {
|
2
2
|
[key: string]: Record<string, string>;
|
3
3
|
};
|
4
|
-
export
|
4
|
+
export declare const updateI18n: (data: LanguageMap) => void;
|
5
|
+
export default class I18N<LanMap extends LanguageMap, Lan extends LanMap[keyof LanMap] = LanMap[keyof LanMap]> {
|
5
6
|
[x: string]: any;
|
6
|
-
strings:
|
7
|
+
strings: LanMap;
|
7
8
|
defaultLang: string;
|
8
9
|
__language: string;
|
9
|
-
constructor(props:
|
10
|
+
constructor(props: LanMap);
|
10
11
|
forceUpdateNetworkLang(productId: string): void;
|
11
|
-
mergeLanguage(L1: LanguageMap, L2: LanguageMap):
|
12
|
+
mergeLanguage(L1: LanguageMap, L2: LanguageMap): any;
|
12
13
|
isZh(language: string): boolean;
|
13
14
|
setLanguage(language: string): void;
|
14
15
|
buildLanguage(language: string): void;
|
15
16
|
_getBestMatchingLanguage(language: string, props: LanguageMap): any;
|
16
17
|
formatString(str: string, ...values: any[]): string;
|
17
|
-
formatValue(key:
|
18
|
+
formatValue(key: keyof Lan, ...values: any[]): any;
|
18
19
|
_replaceAll(find: string, replace: string, str: string): string;
|
19
20
|
getDpLang(code: string | number, value?: undefined | boolean | string): any;
|
20
21
|
getDpName(code: string, defaultName: string): any;
|
21
22
|
getDpsLang(key: {
|
22
23
|
[key: string]: string;
|
23
24
|
}): {};
|
24
|
-
getLang(key:
|
25
|
+
getLang(key: keyof Lan, defaultString?: string): any;
|
25
26
|
/**
|
26
27
|
* 获取picker标题
|
27
28
|
* @param {*} dpCode
|
package/lib/panel/i18n/index.js
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
import "core-js/modules/es.string.replace.js";
|
2
2
|
import { requestCloud, getSystemInfoSync, THING } from '../..';
|
3
3
|
import { getBitValue } from '../utils';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* I18n 智能小程序中用来获取多语言的对象
|
7
|
+
* 文档: https://developer.tuya.com/cn/miniapp/framework/app/i18n
|
8
|
+
*/
|
9
|
+
|
10
|
+
export const updateI18n = () => {
|
11
|
+
// 微信小程序中使用的方法,这里不需要实现
|
12
|
+
};
|
13
|
+
function hasKey(key) {
|
14
|
+
if (typeof I18n.has === 'function') {
|
15
|
+
return I18n.has(key);
|
16
|
+
}
|
17
|
+
return I18n.t(key) !== key;
|
18
|
+
}
|
4
19
|
export default class I18N {
|
5
20
|
constructor(props) {
|
6
21
|
this.strings = this.mergeLanguage(props, {});
|
@@ -107,7 +122,7 @@ export default class I18N {
|
|
107
122
|
return res;
|
108
123
|
}
|
109
124
|
formatValue(key) {
|
110
|
-
let res =
|
125
|
+
let res = this.getLang(key);
|
111
126
|
for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
112
127
|
res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
|
113
128
|
}
|
@@ -129,30 +144,30 @@ export default class I18N {
|
|
129
144
|
} else {
|
130
145
|
key = "dp_".concat(code, "_").concat(value).toLowerCase();
|
131
146
|
}
|
132
|
-
return
|
147
|
+
return hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
133
148
|
}
|
134
149
|
getDpName(code, defaultName) {
|
135
150
|
const key = "dp_".concat(code).toLowerCase();
|
136
|
-
return
|
151
|
+
return hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
|
137
152
|
}
|
138
153
|
getDpsLang(key) {
|
139
154
|
let strs = {};
|
140
155
|
if (typeof key === 'object') {
|
141
156
|
if (typeof key.strKey === 'string') {
|
142
|
-
strs =
|
157
|
+
strs = hasKey(key.strKey) ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
|
143
158
|
} else {
|
144
159
|
Object.keys(key).map(i => {
|
145
|
-
strs[key[i]] =
|
160
|
+
strs[key[i]] = hasKey(key[i]) ? I18n.t(key[i]) : typeof this[key[i]] !== 'undefined' ? this[key[i]] : I18n.t(key[i]);
|
146
161
|
return null;
|
147
162
|
});
|
148
163
|
}
|
149
164
|
} else {
|
150
|
-
strs =
|
165
|
+
strs = hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
151
166
|
}
|
152
167
|
return strs;
|
153
168
|
}
|
154
169
|
getLang(key, defaultString) {
|
155
|
-
return
|
170
|
+
return hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
|
156
171
|
}
|
157
172
|
|
158
173
|
/**
|
@@ -165,7 +180,7 @@ export default class I18N {
|
|
165
180
|
const lists = schema.range;
|
166
181
|
lists.map(v => {
|
167
182
|
const key = "dp_".concat(dpCode, "_").concat(v).toLowerCase();
|
168
|
-
result[v] =
|
183
|
+
result[v] = hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
169
184
|
return null;
|
170
185
|
});
|
171
186
|
return result;
|
@@ -180,11 +195,11 @@ export default class I18N {
|
|
180
195
|
parseCountdown(t, power) {
|
181
196
|
const h = parseFloat("".concat(t / 3600));
|
182
197
|
const m = parseFloat("".concat(t / 60 - h * 60));
|
183
|
-
const tHour =
|
184
|
-
const tMinute =
|
198
|
+
const tHour = hasKey('t_hour') ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
|
199
|
+
const tMinute = hasKey('t_minute') ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
|
185
200
|
const time = h >= 1.0 ? "".concat(Math.round(h)).concat(tHour) : "".concat(Math.round(m)).concat(tMinute);
|
186
201
|
const key = "countdown_".concat(power ? 'on' : 'off');
|
187
|
-
const str =
|
202
|
+
const str = hasKey(key) ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
188
203
|
return this.formatString(str, time);
|
189
204
|
}
|
190
205
|
getFaultStrings(schema, faultCode, faultValue) {
|
package/lib/utils.wechat.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { UrlObject } from 'query-string';
|
1
2
|
type Opts = {
|
2
3
|
deprecated?: boolean;
|
3
4
|
namespace?: string;
|
@@ -7,4 +8,6 @@ export declare function factory(name: string, opts?: Opts): (option: {
|
|
7
8
|
data?: any;
|
8
9
|
}) => any;
|
9
10
|
export declare function factoryContants(name: string, opts?: Opts): any;
|
11
|
+
export declare const parseUrl: (url: string) => import("query-string").ParsedUrl;
|
12
|
+
export declare const stringifyUrl: (object: UrlObject) => string;
|
10
13
|
export {};
|
package/lib/utils.wechat.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
// @ts-ignore
|
2
2
|
import * as tyWx from '@ray-js/wechat';
|
3
|
+
import { stringifyUrl as _stringifyUrl, parseUrl as _parseUrl } from 'query-string';
|
3
4
|
export function factory(name) {
|
4
5
|
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
5
6
|
if (/(set|get|remove|clear)+Storage(Sync)?$/.test(name)) {
|
@@ -38,4 +39,19 @@ export function factoryContants(name) {
|
|
38
39
|
return;
|
39
40
|
}
|
40
41
|
return inst[name];
|
41
|
-
}
|
42
|
+
}
|
43
|
+
export const parseUrl = url => {
|
44
|
+
return _parseUrl(url, {
|
45
|
+
arrayFormat: 'bracket',
|
46
|
+
// WARN: 这里的参数与微信不一致, 但是无法进行修改了, 存量的项目已经在使用
|
47
|
+
// 例如 url=encodeURIComponent('https://www.baidu.com?name=1&age=2') 在微信中不会进行 decode
|
48
|
+
// 而在涂鸦小程序上会进行 decode, 这里是需要注意的地方
|
49
|
+
decode: true
|
50
|
+
});
|
51
|
+
};
|
52
|
+
export const stringifyUrl = object => {
|
53
|
+
return _stringifyUrl(object, {
|
54
|
+
arrayFormat: 'bracket',
|
55
|
+
encode: true
|
56
|
+
});
|
57
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/api",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.52",
|
4
4
|
"description": "Ray universal api",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -29,14 +29,14 @@
|
|
29
29
|
"watch": "ray start --type=component"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@ray-js/framework": "1.4.
|
33
|
-
"@ray-js/router": "1.4.
|
32
|
+
"@ray-js/framework": "1.4.52",
|
33
|
+
"@ray-js/router": "1.4.52",
|
34
34
|
"@ray-js/wechat": "^0.2.8",
|
35
35
|
"base64-browser": "^1.0.1",
|
36
36
|
"query-string": "^7.1.3"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@ray-js/cli": "1.4.
|
39
|
+
"@ray-js/cli": "1.4.52",
|
40
40
|
"art-template": "^4.13.2",
|
41
41
|
"fs-extra": "^10.1.0",
|
42
42
|
"miniprogram-api-typings": "^3.12.2",
|
@@ -46,5 +46,5 @@
|
|
46
46
|
"access": "public",
|
47
47
|
"registry": "https://registry.npmjs.org"
|
48
48
|
},
|
49
|
-
"gitHead": "
|
49
|
+
"gitHead": "a33185e617507f1a5406e074e3369ce4902dc04a"
|
50
50
|
}
|