pixuireactcomponents 1.3.76 → 1.3.78
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixuireactcomponents",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.78",
|
|
4
4
|
"description": "pixui react components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"animate.css": "^3.7.2",
|
|
14
14
|
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
|
15
|
-
"cheerio": "
|
|
15
|
+
"cheerio": "1.0.0-rc.12",
|
|
16
16
|
"cpx": "^1.5.0",
|
|
17
17
|
"gamelet-pixui-frame": "0.4.9",
|
|
18
18
|
"google-protobuf": "^3.8.0",
|
|
@@ -9,9 +9,5 @@ export declare namespace assetCache {
|
|
|
9
9
|
* @returns 返回本地缓存文件路径
|
|
10
10
|
*/
|
|
11
11
|
const cache: (url: string, force?: boolean, retryTimes?: number) => Promise<string>;
|
|
12
|
-
/**
|
|
13
|
-
* 返回url在本地的缓存文件路径,无缓存时返回空字符串
|
|
14
|
-
*/
|
|
15
|
-
const getAssetPath: (url: string) => string;
|
|
16
12
|
const download: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
|
|
17
13
|
}
|
|
@@ -37,11 +37,36 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
import { GameletAPI } from 'gamelet-pixui-frame';
|
|
38
38
|
import path from 'path';
|
|
39
39
|
import { tools } from './tools';
|
|
40
|
-
import { LibMgr } from '../../../lib/loadlib/lib_mgr';
|
|
41
40
|
var assetPrefix = 'cacheAsset';
|
|
42
41
|
var isJssdkEnv = function () {
|
|
43
42
|
return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
|
|
44
43
|
};
|
|
44
|
+
//动态导入lib_mgr
|
|
45
|
+
var getLibMgr = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var LibMgr, module_1, error_1;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
switch (_a.label) {
|
|
49
|
+
case 0:
|
|
50
|
+
if (!window.require) {
|
|
51
|
+
console.error('env error');
|
|
52
|
+
return [2 /*return*/, null];
|
|
53
|
+
}
|
|
54
|
+
_a.label = 1;
|
|
55
|
+
case 1:
|
|
56
|
+
_a.trys.push([1, 3, , 4]);
|
|
57
|
+
return [4 /*yield*/, import('../../../lib/loadlib/lib_mgr')];
|
|
58
|
+
case 2:
|
|
59
|
+
module_1 = _a.sent();
|
|
60
|
+
LibMgr = module_1.LibMgr;
|
|
61
|
+
return [3 /*break*/, 4];
|
|
62
|
+
case 3:
|
|
63
|
+
error_1 = _a.sent();
|
|
64
|
+
console.error('need puerts env');
|
|
65
|
+
return [2 /*return*/, null];
|
|
66
|
+
case 4: return [2 /*return*/, LibMgr];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}); };
|
|
45
70
|
/**
|
|
46
71
|
* 缓存资源到本地,仅jssdk环境可用
|
|
47
72
|
*/
|
|
@@ -60,76 +85,77 @@ export var assetCache;
|
|
|
60
85
|
var _this = this;
|
|
61
86
|
return __generator(this, function (_a) {
|
|
62
87
|
console.log('cacheAsset---', url);
|
|
63
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.log('cacheAsset file exist', localPath);
|
|
74
|
-
resolve(localPath);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
var xhr = new XMLHttpRequest();
|
|
79
|
-
xhr.open('GET', url, true);
|
|
80
|
-
xhr.responseType = 'arraybuffer';
|
|
81
|
-
xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
-
var buf;
|
|
83
|
-
return __generator(this, function (_a) {
|
|
84
|
-
if (xhr.status === 200) {
|
|
85
|
-
buf = Buffer.from(xhr.response, 'binary').buffer;
|
|
86
|
-
lib.saveToFile(localPath, buf);
|
|
87
|
-
resolve(localPath);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
console.warn('cacheAsset xhr statue!=200', xhr.status);
|
|
91
|
-
if (retryTimes > 0) {
|
|
92
|
-
console.log('retry cacheAsset', retryTimes);
|
|
93
|
-
assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
|
|
88
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
89
|
+
var mgr, lib, localPath, xhr;
|
|
90
|
+
var _this = this;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!isJssdkEnv()) {
|
|
95
|
+
console.log('非jssdk环境');
|
|
96
|
+
reject();
|
|
97
|
+
return [2 /*return*/];
|
|
94
98
|
}
|
|
95
|
-
|
|
99
|
+
return [4 /*yield*/, getLibMgr()];
|
|
100
|
+
case 1:
|
|
101
|
+
mgr = _a.sent();
|
|
102
|
+
if (!mgr) {
|
|
96
103
|
reject();
|
|
104
|
+
return [2 /*return*/];
|
|
97
105
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
lib = mgr.getInstance().getMainLib();
|
|
107
|
+
return [4 /*yield*/, getLocalPath(url)];
|
|
108
|
+
case 2:
|
|
109
|
+
localPath = _a.sent();
|
|
110
|
+
if (!force) {
|
|
111
|
+
if (lib.fileExists(localPath)) {
|
|
112
|
+
console.log('cacheAsset file exist', localPath);
|
|
113
|
+
resolve(localPath);
|
|
114
|
+
return [2 /*return*/];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
xhr = new XMLHttpRequest();
|
|
118
|
+
xhr.open('GET', url, true);
|
|
119
|
+
xhr.responseType = 'arraybuffer';
|
|
120
|
+
xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
121
|
+
var buf;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
if (xhr.status === 200) {
|
|
124
|
+
buf = Buffer.from(xhr.response, 'binary').buffer;
|
|
125
|
+
lib.saveToFile(localPath, buf);
|
|
126
|
+
resolve(localPath);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.warn('cacheAsset xhr statue!=200', xhr.status);
|
|
130
|
+
if (retryTimes > 0) {
|
|
131
|
+
console.log('retry cacheAsset', retryTimes);
|
|
132
|
+
assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
reject();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return [2 /*return*/];
|
|
139
|
+
});
|
|
140
|
+
}); };
|
|
141
|
+
xhr.onerror = function () {
|
|
142
|
+
console.warn('cacheAsset XHR error', xhr.status);
|
|
143
|
+
if (retryTimes > 0) {
|
|
144
|
+
console.log('retry cacheAsset', retryTimes);
|
|
145
|
+
assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
reject();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
xhr.send();
|
|
152
|
+
return [2 /*return*/];
|
|
110
153
|
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
})];
|
|
154
|
+
});
|
|
155
|
+
}); })];
|
|
114
156
|
});
|
|
115
157
|
});
|
|
116
158
|
};
|
|
117
|
-
/**
|
|
118
|
-
* 返回url在本地的缓存文件路径,无缓存时返回空字符串
|
|
119
|
-
*/
|
|
120
|
-
assetCache.getAssetPath = function (url) {
|
|
121
|
-
if (!isJssdkEnv()) {
|
|
122
|
-
console.log('非jssdk环境');
|
|
123
|
-
return '';
|
|
124
|
-
}
|
|
125
|
-
var lib = LibMgr.getInstance().getMainLib();
|
|
126
|
-
var localPath = getLocalPath(url);
|
|
127
|
-
if (!lib.fileExists(localPath)) {
|
|
128
|
-
console.log('getAssetPath file not exist', localPath);
|
|
129
|
-
return '';
|
|
130
|
-
}
|
|
131
|
-
return localPath;
|
|
132
|
-
};
|
|
133
159
|
assetCache.download = function (url, responseType, retryTimes) {
|
|
134
160
|
if (retryTimes === void 0) { retryTimes = 3; }
|
|
135
161
|
console.log('download---', url);
|
|
@@ -168,15 +194,27 @@ export var assetCache;
|
|
|
168
194
|
xhr.send();
|
|
169
195
|
});
|
|
170
196
|
};
|
|
171
|
-
var getLocalPath = function (url) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
197
|
+
var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
|
|
198
|
+
var mgr, lib, filePath, fileName;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0:
|
|
202
|
+
console.log('getLocalPath', url);
|
|
203
|
+
return [4 /*yield*/, getLibMgr()];
|
|
204
|
+
case 1:
|
|
205
|
+
mgr = _a.sent();
|
|
206
|
+
if (!mgr) {
|
|
207
|
+
return [2 /*return*/, ''];
|
|
208
|
+
}
|
|
209
|
+
lib = mgr.getInstance().getMainLib();
|
|
210
|
+
filePath = path.join(lib.getCachePath(), 'assetcache');
|
|
211
|
+
//检查assetcache文件夹
|
|
212
|
+
if (!lib.dirExists(filePath)) {
|
|
213
|
+
lib.makeDir(filePath);
|
|
214
|
+
}
|
|
215
|
+
fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
|
|
216
|
+
return [2 /*return*/, path.join(filePath, fileName)];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}); };
|
|
182
220
|
})(assetCache || (assetCache = {}));
|
|
@@ -122,6 +122,16 @@ export var tools;
|
|
|
122
122
|
for (var i = 1; i <= 10; i++) {
|
|
123
123
|
_loop_1(i);
|
|
124
124
|
}
|
|
125
|
+
//每个 p 节点后添加一个 br 节点
|
|
126
|
+
$('p').each(function () {
|
|
127
|
+
$(this).after('<br>');
|
|
128
|
+
});
|
|
129
|
+
//将所有的<p><br></p>改成<br>,否则之后 br 会被套在 div 里失效
|
|
130
|
+
$('p').each(function () {
|
|
131
|
+
if (($(this).html() || '').trim() === '<br>') {
|
|
132
|
+
$(this).replaceWith('<br>');
|
|
133
|
+
}
|
|
134
|
+
});
|
|
125
135
|
//找到所有的文字节点,外层包裹text标签
|
|
126
136
|
$('*').each(function () {
|
|
127
137
|
$(this)
|
|
@@ -161,14 +171,17 @@ export var tools;
|
|
|
161
171
|
var style = $(this).attr('style') || '';
|
|
162
172
|
$(this).replaceWith("<text style=\"".concat(style, " flex-shrink: 0;\">").concat(html, "</text>"));
|
|
163
173
|
});
|
|
174
|
+
//p换成div
|
|
164
175
|
$('p').each(function () {
|
|
165
176
|
var html = $(this).html();
|
|
166
177
|
var style = $(this).attr('style') || '';
|
|
167
178
|
$(this).replaceWith("<div style=\"".concat(style, " ;flex-shrink: 0;\">").concat(html, "</div>"));
|
|
168
179
|
});
|
|
180
|
+
//pixui 连续的 br 会被吃掉,用 div 占位
|
|
169
181
|
$('br').each(function () {
|
|
170
|
-
$(this).replaceWith("<br><div style = \"width:50px;height:15px;\" />");
|
|
182
|
+
$(this).replaceWith("<br><div style = \"width:50px; height:15px; flex-shrink: 0;\" />");
|
|
171
183
|
});
|
|
184
|
+
//补充 flex-shrink: 0
|
|
172
185
|
['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'img'].forEach(function (tag) {
|
|
173
186
|
$("".concat(tag)).each(function () {
|
|
174
187
|
var style = $(this).attr('style') || '';
|
|
@@ -217,6 +230,25 @@ export var tools;
|
|
|
217
230
|
$(this).replaceWith("<".concat(tag, " style=\"").concat(tagstyle, "\"><text>").concat(taghtml, "</text></").concat(tag, ">"));
|
|
218
231
|
});
|
|
219
232
|
});
|
|
233
|
+
//pixui 的 line-height只在 text 上生效,所以将所有的 div 上的 line-height 转移到父 text 上
|
|
234
|
+
//当前的结构为 div > text > div,只处理一层就行
|
|
235
|
+
//遍历每个 text 的子 div,将其中最大的 line-height 转移到 text 上
|
|
236
|
+
$('text').each(function () {
|
|
237
|
+
var $text = $(this);
|
|
238
|
+
var maxLineHeight = 0;
|
|
239
|
+
$text.children('div').each(function () {
|
|
240
|
+
var lineHeight = $(this).css('line-height') || '0';
|
|
241
|
+
var lineHeightNum = parseInt(lineHeight);
|
|
242
|
+
if (lineHeightNum > maxLineHeight) {
|
|
243
|
+
maxLineHeight = lineHeightNum;
|
|
244
|
+
}
|
|
245
|
+
// $(this).css('line-height', '0');
|
|
246
|
+
});
|
|
247
|
+
if (maxLineHeight > 0) {
|
|
248
|
+
// pixui 中的实际显示的距离与网页中实际显示的距离差距较大,暂时*5rem
|
|
249
|
+
$text.css('line-height', maxLineHeight * 5 + 'rem');
|
|
250
|
+
}
|
|
251
|
+
});
|
|
220
252
|
if (aLabelData) {
|
|
221
253
|
$('a').each(function (i, ele) {
|
|
222
254
|
var id = "PA_RichTextATagId_".concat(i);
|