pixuireactcomponents 1.3.81 → 1.3.82

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.81",
3
+ "version": "1.3.82",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,6 @@
12
12
  "dependencies": {
13
13
  "animate.css": "^3.7.2",
14
14
  "babel-plugin-transform-decorators-legacy": "^1.3.5",
15
- "cheerio": "1.0.0-rc.12",
16
15
  "cpx": "^1.5.0",
17
16
  "gamelet-pixui-frame": "0.4.9",
18
17
  "google-protobuf": "^3.8.0",
@@ -5,17 +5,4 @@ export declare namespace tools {
5
5
  * 哈希生成一个长度20的字符串
6
6
  */
7
7
  const getHashStr: (str: string) => string;
8
- /**
9
- * 旧的富文本组件,请使用ConvertRichTextToPixuiStyle
10
- * @param str
11
- * @returns
12
- */
13
- const convertRichText: (str: string) => string;
14
- /**
15
- * 富文本组件,将富文本转换成pixui的innerHtml可以使用的格式
16
- * @param str 管理端下发的富文本
17
- * @param aLabelData 返回的富文本中的a标签的跳转数据,[id:string]:jumpdata
18
- * @returns pixui的innerHtml可以使用的格式
19
- */
20
- const convertRichTextToPixuiStyle: (str: string, aLabelData?: object[]) => string;
21
8
  }
@@ -36,7 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { GameletAPI } from 'gamelet-pixui-frame';
38
38
  import { sha1 } from './Sha1';
39
- import * as cheerio from 'cheerio';
40
39
  export var tools;
41
40
  (function (tools) {
42
41
  tools.writeCookie = function (key, value) {
@@ -77,194 +76,4 @@ export var tools;
77
76
  tools.getHashStr = function (str) {
78
77
  return sha1(str).substring(0, 20);
79
78
  };
80
- /**
81
- * 旧的富文本组件,请使用ConvertRichTextToPixuiStyle
82
- * @param str
83
- * @returns
84
- */
85
- tools.convertRichText = function (str) {
86
- var res = str
87
- .replaceAll(/<img([^>]*)>/g, '<img$1></img>') //传过来的这两个标签会少结束标签
88
- .replaceAll(/<h[1,2,3,4,5,6]><br><\/h[1,2,3,4,5,6]>/g, '<br /><div style = "width:50px;height:15px;" ></div>')
89
- .replaceAll(/<p><br><\/p>/g, '<br /><div style = "width:50px;height:15px;" ></div>')
90
- .replaceAll(/<p/g, '<text')
91
- .replaceAll(/<\/p>/g, '</text>') //包text否则会丢break word
92
- .replaceAll(/<span/g, '<text')
93
- .replaceAll(/<\/span>/g, '</text>') //包text否则会丢break word
94
- .replaceAll(/&nbsp;/g, ' '); //单一行只有nbsp的时候,会整个解析不出来,pixui innerHtml bug
95
- for (var i = 1; i <= 6; i++) {
96
- res = res.replaceAll(/(<h${i}\s[^>]*>)([^<]*)(<\/h${i}>)/g, '$1<text>$2</text>$3'); //h1-h6的内容包 text
97
- }
98
- res = res.replaceAll(/<br>/g, '<br /><div style = "width:50px;height:15px;" ></div>');
99
- for (var i = 1; i < 10; i++) {
100
- res = res.replaceAll("class=\"ql-indent-".concat(i, "\""), " style=\"padding-left: ".concat(i * 2, "rem;\""));
101
- }
102
- return res;
103
- };
104
- /**
105
- * 富文本组件,将富文本转换成pixui的innerHtml可以使用的格式
106
- * @param str 管理端下发的富文本
107
- * @param aLabelData 返回的富文本中的a标签的跳转数据,[id:string]:jumpdata
108
- * @returns pixui的innerHtml可以使用的格式
109
- */
110
- tools.convertRichTextToPixuiStyle = function (str, aLabelData) {
111
- var $ = cheerio.load(str, null, false);
112
- var _loop_1 = function (i) {
113
- var indent = "ql-indent-".concat(i);
114
- var extStyle = "padding-left: ".concat(i * 2, "rem;");
115
- $(".".concat(indent)).each(function () {
116
- var oriStyle = $(this).attr('style') || '';
117
- $(this).attr('style', "".concat(oriStyle, " ").concat(extStyle));
118
- $(this).removeClass(indent);
119
- });
120
- };
121
- //合并ql-indent class到style中
122
- for (var i = 1; i <= 10; i++) {
123
- _loop_1(i);
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
- });
135
- //找到所有的文字节点,外层包裹text标签
136
- $('*').each(function () {
137
- $(this)
138
- .contents()
139
- .each(function () {
140
- if (this.type === 'text') {
141
- var text = this.data.trim();
142
- if (text.length > 0) {
143
- $(this).replaceWith("<text style=\"word-break: break-word;flex-shrink: 0;\">".concat(text, "</text>"));
144
- }
145
- }
146
- });
147
- });
148
- //将strong em u s标签替换成text标签
149
- $('strong').each(function () {
150
- var html = $(this).html();
151
- var style = $(this).attr('style') || '';
152
- $(this).replaceWith("<text style=\"".concat(style, " font-weight: bold;flex-shrink: 0;\">").concat(html, "</text>"));
153
- });
154
- $('em').each(function () {
155
- var html = $(this).html();
156
- var style = $(this).attr('style') || '';
157
- $(this).replaceWith("<text style=\"".concat(style, " font-style: italic;flex-shrink: 0;\">").concat(html, "</text>"));
158
- });
159
- $('u').each(function () {
160
- var html = $(this).html();
161
- var style = $(this).attr('style') || '';
162
- $(this).replaceWith("<text style=\"".concat(style, " text-decoration: underline;flex-shrink: 0;\">").concat(html, "</text>"));
163
- });
164
- $('s').each(function () {
165
- var html = $(this).html();
166
- var style = $(this).attr('style') || '';
167
- $(this).replaceWith("<text style=\"".concat(style, " text-decoration: line-through;flex-shrink: 0;\">").concat(html, "</text>"));
168
- });
169
- $('span').each(function () {
170
- var html = $(this).html();
171
- var style = $(this).attr('style') || '';
172
- $(this).replaceWith("<text style=\"".concat(style, " flex-shrink: 0;\">").concat(html, "</text>"));
173
- });
174
- //p换成div
175
- $('p').each(function () {
176
- var html = $(this).html();
177
- var style = $(this).attr('style') || '';
178
- $(this).replaceWith("<div style=\"".concat(style, " ;flex-shrink: 0;\">").concat(html, "</div>"));
179
- });
180
- //pixui 连续的 br 会被吃掉,用 div 占位
181
- $('br').each(function () {
182
- $(this).replaceWith("<br><div style = \"width:50px; height:15px; flex-shrink: 0;\" />");
183
- });
184
- //补充 flex-shrink: 0
185
- ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'img'].forEach(function (tag) {
186
- $("".concat(tag)).each(function () {
187
- var style = $(this).attr('style') || '';
188
- $(this).attr('style', "".concat(style, " flex-shrink: 0;"));
189
- });
190
- });
191
- //将嵌套的text节点合并,同时合并内外的style
192
- while ($('text > text').length > 0) {
193
- $('text').each(function () {
194
- var $this = $(this);
195
- var parentStyle = $this.attr('style') || '';
196
- $this.children('text').each(function () {
197
- var $child = $(this);
198
- var childStyle = $child.attr('style') || '';
199
- // 合并style属性
200
- var mergedStyle = "".concat(parentStyle, "; ").concat(childStyle);
201
- // 更新子元素的style属性
202
- $child.attr('style', mergedStyle);
203
- });
204
- //去掉父节点
205
- if ($this.children('text').length > 0) {
206
- $this.replaceWith($this.html() || '');
207
- }
208
- });
209
- }
210
- //去除空的text节点
211
- $('text').each(function () {
212
- var t = $(this).html() || '';
213
- if (t.trim() == '') {
214
- $(this).remove();
215
- }
216
- });
217
- //!!并列的text节点在父节点为flexDirection:row时无法正确换行,将其修改为div,外层再包一个text节点
218
- ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div'].map(function (tag) {
219
- $("".concat(tag)).each(function () {
220
- $(this)
221
- .children('text')
222
- .each(function () {
223
- var text = $(this).html();
224
- var style = $(this).attr('style') || '';
225
- $(this).replaceWith("<div style=\"".concat(style, "\">").concat(text, "</div>"));
226
- });
227
- var taghtml = $(this).html();
228
- var tagstyle = $(this).attr('style') || '';
229
- //自己的子节点外套一个text,自己不变
230
- $(this).replaceWith("<".concat(tag, " style=\"").concat(tagstyle, "\"><text>").concat(taghtml, "</text></").concat(tag, ">"));
231
- });
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
- });
252
- if (aLabelData) {
253
- $('a').each(function (i, ele) {
254
- var id = "PA_RichTextATagId_".concat(i);
255
- $(this).attr('id', id);
256
- aLabelData[id] = $(this).attr('href');
257
- $(this).attr('href', '');
258
- });
259
- }
260
- //手动处理标签的结尾符
261
- var res = $.html();
262
- res = res
263
- .replaceAll(/<br>/g, '<br />')
264
- .replaceAll(/<img([^>]+)>/g, '<img$1 />')
265
- .replaceAll(/&nbsp;/g, ' ');
266
- // console.log('rrrr', res);
267
- res = "<div style=\"display:flex;flex-direction:column;width:100%;\">".concat(res, "</div>");
268
- return res;
269
- };
270
79
  })(tools || (tools = {}));