@jx3box/jx3box-editor 1.4.11 → 1.5.1

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.
@@ -1,7 +1,11 @@
1
1
  import $ from 'jquery'
2
2
 
3
3
  function renderImgPreview(vm, selector='.c-article img'){
4
- $(selector).each((i, ele) => {
4
+ // 获取src不为空的图片
5
+ let imgs = $(selector).filter(function(){
6
+ return $(this).attr('src') != ''
7
+ })
8
+ imgs.each((i, ele) => {
5
9
  // 加载全部src(lazyload)
6
10
  vm.images.push($(ele).attr('src'))
7
11
  // 绑定事件挂钩索引位置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-editor",
3
- "version": "1.4.11",
3
+ "version": "1.5.1",
4
4
  "description": "JX3BOX Article & Editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,6 +13,10 @@
13
13
  <script>
14
14
  import markdownRender from '@jx3box/markdown/src/render.vue'
15
15
 
16
+ import Vue from "vue";
17
+ import hevueImgPreview from "hevue-img-preview";
18
+ Vue.use(hevueImgPreview);
19
+
16
20
  // 基本文本
17
21
  import execLazyload from "../assets/js/img";
18
22
  import execFilterIframe from "../assets/js/iframe";
@@ -33,6 +37,7 @@ import Buff from "./Buff";
33
37
  import Skill from "./Skill";
34
38
  import Npc from "./Npc";
35
39
  import renderJx3Element from "../assets/js/jx3_element";
40
+ import renderImgPreview from "../assets/js/renderImgPreview";
36
41
 
37
42
  import {xssOptions} from '../assets/data/markdown_whitelist.json'
38
43
 
@@ -79,6 +84,7 @@ export default {
79
84
  },
80
85
  type: "",
81
86
  },
87
+ images: [],
82
88
 
83
89
  xssOptions
84
90
  };
@@ -106,6 +112,8 @@ export default {
106
112
  renderTalent2();
107
113
  // Tatex
108
114
  renderKatex();
115
+ // 画廊
116
+ renderImgPreview(this);
109
117
  // 语法高亮
110
118
  renderCode(`code[class=^'lang-']`)
111
119
  // 物品
@@ -156,4 +164,8 @@ export default {
156
164
 
157
165
  <style lang="less">
158
166
  @import "../assets/css/article_markdown.less";
167
+
168
+ .v-note-img-wrapper {
169
+ display: none;
170
+ }
159
171
  </style>
package/src/GameText.vue CHANGED
@@ -6,7 +6,7 @@
6
6
  * @Description: 用于渲染游戏内Text标签的文本
7
7
  -->
8
8
  <template>
9
- <span v-html="html"></span>
9
+ <span v-html="html"></span>
10
10
  </template>
11
11
 
12
12
  <script>
@@ -15,170 +15,205 @@ import { getResource } from "../service/resource";
15
15
  import { escape } from "lodash";
16
16
 
17
17
  export default {
18
- name: "GameText",
19
- props: {
20
- text: {
21
- type: String,
22
- default: "",
18
+ name: "GameText",
19
+ props: {
20
+ text: {
21
+ type: String,
22
+ default: "",
23
+ },
24
+ client: {
25
+ type: String,
26
+ default: "std",
27
+ },
23
28
  },
24
- client: {
25
- type: String,
26
- default: "std",
29
+ data: function () {
30
+ return {
31
+ html: "",
32
+ };
27
33
  },
28
- },
29
- data: function () {
30
- return {
31
- html: "",
32
- };
33
- },
34
- methods: {
35
- /**
36
- * 渲染某一个单独的Text标签成Span或链接
37
- * @param {*} school_id
38
- * @returns
39
- */
40
- renderItemHtml: function (item) {
41
- let content = item.text;
42
- let style = ``;
43
- let link = null;
44
- content = content.replace(/\\n/g, "<br />").replace(/\\/g, "");
45
- if ([item.r, item.g, item.b].every((v) => v != undefined && v > 0)) {
46
- style = `color: rgb(${item.r}, ${item.g}, ${item.b});`;
47
- } else if (item.font != undefined && item.font != 100) {
48
- const fonts = require("../assets/data/game_font.json");
49
- for (let color in fonts) {
50
- if (fonts[color].includes(item.font)) {
51
- style = `color: ${color};`;
52
- break;
53
- }
54
- }
55
- }
56
- if (item.name == "iteminfolink" && item.script) {
57
- let item_type = item.script?.match(/this\.dwTabType=(\d+)/i)?.[1];
58
- let item_index = item.script?.match(/this\.dwIndex=(\d+)/i)?.[1];
59
- if (item_type && item_index) {
60
- let item_id = `${item_type}_${item_index}`;
61
- link = getLink("item", item_id);
62
- }
63
- }
64
- if (link) {
65
- return `<a style="${style} text-decoration: none;" target="_blank" href="${link}">${content}</a>`;
66
- } else {
67
- return `<span style="${style}">${content}</span>`;
68
- }
69
- },
70
- /**
71
- * 将一段游戏内文本转换为Html
72
- * @param {Object[]} texts 标签对象
73
- */
74
- renderTextHtml: function (Text) {
75
- let result = Text;
76
- const matches = Text.match(/<Text>(.*?)<\/text>/gimsy);
77
- if (!matches) return Text;
78
- for (let match of matches) {
79
- let text = extractTextContent(match);
80
- let html = this.renderItemHtml(text[0]);
81
- result = result.replace(match, html);
82
- }
83
- return result;
84
- },
85
- /**
86
- * 获取形如<BUFF 110 1 desc>, <ENCHANT 100>的资源字段并转换
87
- */
88
- renderBuffResource: function () {
89
- const matches = this.html.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
90
- if (!matches) return;
91
- let need_replaces = {};
92
- //先统计需要的资源,减少请求数量
93
- for (let match of matches) {
94
- let [token, id, level, type] = match.match(/<BUFF (\d+) (\d+) (.*?)>/i);
95
- let buff_token = `${id}_${level}`;
96
- if (!need_replaces[buff_token]) {
97
- need_replaces[buff_token] = [];
98
- }
99
- need_replaces[buff_token].push({
100
- token,
101
- type,
102
- });
103
- }
104
- //对每一个需要的资源发起请求
105
- for (let buff_token in need_replaces) {
106
- let token_item = need_replaces[buff_token];
107
- getResource(`buff.${buff_token}`, this.client)
108
- .then((res) => {
109
- let data = res.data;
110
- for (let item of token_item) {
111
- item.type = item.type.toLowerCase();
112
- let type_map = {
113
- desc: "Desc",
114
- time: "Interval",
115
- };
116
- let attr = type_map[item.type] || item.type;
117
- let value = data[attr];
118
- if (typeof value == "number" && item.type == "time") {
119
- let time = value / 16;
120
- if (time > 60) {
121
- time = `${Math.floor(time / 60)}分钟`;
122
- } else {
123
- time = `${time}秒`;
34
+ methods: {
35
+ /**
36
+ * 渲染某一个单独的Text标签成Span或链接
37
+ * @param {*} school_id
38
+ * @returns
39
+ */
40
+ renderItemHtml: function (item) {
41
+ let content = item.text;
42
+ let style = ``;
43
+ let link = null;
44
+ content = content.replace(/\\n/g, "<br />").replace(/\\/g, "");
45
+ if ([item.r, item.g, item.b].every(v => v != undefined && v > 0)) {
46
+ style = `color: rgb(${item.r}, ${item.g}, ${item.b});`;
47
+ } else if (item.font != undefined && item.font != 100) {
48
+ const fonts = require("../assets/data/game_font.json");
49
+ for (let color in fonts) {
50
+ if (fonts[color].includes(item.font)) {
51
+ style = `color: ${color};`;
52
+ break;
53
+ }
124
54
  }
125
- this.html = this.html.replace(item.token, time);
126
- return;
127
- }
128
- if (!value) return;
129
- let _matches = value.match(/<BUFF ([0-9a-zA-Z]+)>/gi);
130
- if (!_matches) this.html = this.html.replace(match, value);
131
- for (let _match of _matches) {
132
- let [, _attr] = _match.match(/<BUFF ([0-9a-zA-Z]+)>/i);
133
- for (let i = 1; i < 15; i++) {
134
- if (data[`BeginAttrib${i}`] == _attr) {
135
- value = value.replace(_match, data[`BeginValue${i}A`]);
136
- }
55
+ }
56
+ if (item.name == "iteminfolink" && item.script) {
57
+ let item_type = item.script?.match(
58
+ /this\.dwTabType=(\d+)/i
59
+ )?.[1];
60
+ let item_index =
61
+ item.script?.match(/this\.dwIndex=(\d+)/i)?.[1];
62
+ if (item_type && item_index) {
63
+ let item_id = `${item_type}_${item_index}`;
64
+ link = getLink("item", item_id);
137
65
  }
138
- }
139
- this.html = this.html.replace(item.token, value);
140
66
  }
141
- })
142
- .catch((err) => {
143
- console.log(err);
144
- });
145
- }
146
- },
147
- renderEnchantResource: function () {
148
- const matches = this.html.match(/<ENCHANT (\d+)>/gim);
149
- if(!matches) return;
150
- for (let match of matches) {
151
- let enchant_id = match.match(/<ENCHANT (\d+)>/i)[1];
152
- getResource(`enchant.${enchant_id}`, this.client)
153
- .then((res) => {
154
- let data = res.data;
155
- let time = data.Time;
156
- if (time) time = `,持续${parseInt(time) / 60}分钟。`;
157
- let result = `${data.AttriName}${time ? time : ""}`;
158
- this.html = this.html.replace(match, result);
159
- })
160
- .catch((err) => {
161
- this.html = this.html.replace(match, escape(match));
162
- console.log(err);
163
- });
164
- }
165
- },
166
- renderResource: function () {
167
- this.renderBuffResource();
168
- this.renderEnchantResource();
67
+ if (link) {
68
+ return `<a style="${style} text-decoration: none;" target="_blank" href="${link}">${content}</a>`;
69
+ } else {
70
+ return `<span style="${style}">${content}</span>`;
71
+ }
72
+ },
73
+ /**
74
+ * 将image标签转换为HTML标签
75
+ */
76
+ renderImageHtml: function (Text) {
77
+ // <image>path="fromiconid" frame=1241 w=29 h=29 </image>
78
+ let matches = Text.match(/<image>(.*?)<\/image>/gims);
79
+ console.log(Text, matches);
80
+ if (!matches) return Text;
81
+ for (let match of matches) {
82
+ let icon_id = match.match(/frame=(\d+)/i)?.[1];
83
+ let w = parseInt(match.match(/w=(\d+)/i)?.[1]) / 1.12;
84
+ let h = parseInt(match.match(/h=(\d+)/i)?.[1]) / 1.12;
85
+ let src = `https://icon.jx3box.com/icon/${icon_id}.png`;
86
+ let html = `<img src="${src}" style="width: ${w}px; height: ${h}px; margin-bottom: -5px" />`;
87
+ Text = Text.replace(match, html);
88
+ }
89
+ return Text;
90
+ },
91
+ /**
92
+ * 将一段游戏内文本转换为Html
93
+ * @param {Object[]} texts 标签对象
94
+ */
95
+ renderTextHtml: function (Text) {
96
+ let result = Text;
97
+ result = this.renderImageHtml(result);
98
+ const matches = Text.match(/<Text>(.*?)<\/text>/gims);
99
+ if (!matches) return Text;
100
+ for (let match of matches) {
101
+ let text = extractTextContent(match);
102
+ let html = this.renderItemHtml(text[0]);
103
+ result = result.replace(match, html);
104
+ }
105
+ return result;
106
+ },
107
+ /**
108
+ * 获取形如<BUFF 110 1 desc>, <ENCHANT 100>的资源字段并转换
109
+ */
110
+ renderBuffResource: function () {
111
+ const matches = this.html.match(/<BUFF (\d+) (\d+) (.*?)>/gim);
112
+ if (!matches) return;
113
+ let need_replaces = {};
114
+ //先统计需要的资源,减少请求数量
115
+ for (let match of matches) {
116
+ let [token, id, level, type] = match.match(
117
+ /<BUFF (\d+) (\d+) (.*?)>/i
118
+ );
119
+ let buff_token = `${id}_${level}`;
120
+ if (!need_replaces[buff_token]) {
121
+ need_replaces[buff_token] = [];
122
+ }
123
+ need_replaces[buff_token].push({
124
+ token,
125
+ type,
126
+ });
127
+ }
128
+ //对每一个需要的资源发起请求
129
+ for (let buff_token in need_replaces) {
130
+ let token_item = need_replaces[buff_token];
131
+ getResource(`buff.${buff_token}`, this.client)
132
+ .then(res => {
133
+ let data = res.data;
134
+ for (let item of token_item) {
135
+ item.type = item.type.toLowerCase();
136
+ let type_map = {
137
+ desc: "Desc",
138
+ time: "Interval",
139
+ };
140
+ let attr = type_map[item.type] || item.type;
141
+ let value = data[attr];
142
+ if (
143
+ typeof value == "number" &&
144
+ item.type == "time"
145
+ ) {
146
+ let time = value / 16;
147
+ if (time > 60) {
148
+ time = `${Math.floor(time / 60)}分钟`;
149
+ } else {
150
+ time = `${time}秒`;
151
+ }
152
+ this.html = this.html.replace(item.token, time);
153
+ return;
154
+ }
155
+ if (!value) return;
156
+ let _matches = value.match(
157
+ /<BUFF ([0-9a-zA-Z]+)>/gi
158
+ );
159
+ if (!_matches)
160
+ this.html = this.html.replace(match, value);
161
+ for (let _match of _matches) {
162
+ let [, _attr] = _match.match(
163
+ /<BUFF ([0-9a-zA-Z]+)>/i
164
+ );
165
+ for (let i = 1; i < 15; i++) {
166
+ if (data[`BeginAttrib${i}`] == _attr) {
167
+ value = value.replace(
168
+ _match,
169
+ data[`BeginValue${i}A`]
170
+ );
171
+ }
172
+ }
173
+ }
174
+ this.html = this.html.replace(item.token, value);
175
+ }
176
+ })
177
+ .catch(err => {
178
+ console.log(err);
179
+ });
180
+ }
181
+ },
182
+ renderEnchantResource: function () {
183
+ const matches = this.html.match(/<ENCHANT (\d+)>/gim);
184
+ if (!matches) return;
185
+ for (let match of matches) {
186
+ let enchant_id = match.match(/<ENCHANT (\d+)>/i)[1];
187
+ getResource(`enchant.${enchant_id}`, this.client)
188
+ .then(res => {
189
+ let data = res.data;
190
+ let time = data.Time;
191
+ if (time) time = `,持续${parseInt(time) / 60}分钟。`;
192
+ let result = `${data.AttriName}${time ? time : ""}`;
193
+ this.html = this.html.replace(match, result);
194
+ })
195
+ .catch(err => {
196
+ this.html = this.html.replace(match, escape(match));
197
+ console.log(err);
198
+ });
199
+ }
200
+ },
201
+ renderResource: function () {
202
+ this.renderBuffResource();
203
+ this.renderEnchantResource();
204
+ },
169
205
  },
170
- },
171
- watch: {
172
- text: {
173
- immediate: true,
174
- handler: function (val) {
175
- this.html = this.renderTextHtml(val);
176
- this.renderResource();
177
- },
206
+ watch: {
207
+ text: {
208
+ immediate: true,
209
+ handler: function (val) {
210
+ if (!val) return;
211
+ this.html = this.renderTextHtml(val);
212
+ this.renderResource();
213
+ },
214
+ },
178
215
  },
179
- },
180
216
  };
181
217
  </script>
182
218
 
183
- <style>
184
- </style>
219
+ <style></style>
package/src/Item.vue CHANGED
@@ -63,7 +63,7 @@
63
63
  <div class="u-horse-desc" v-html="attribute.label"></div>
64
64
  </span>
65
65
  <span v-else class="u-value">
66
- <span v-text="attribute.label"></span>
66
+ <game-text :text="attribute.label"></game-text>
67
67
  <!-- <span
68
68
  class="u-yellow"
69
69
  v-text="
@@ -176,9 +176,9 @@
176
176
  </div>
177
177
  <!-- 描述 -->
178
178
  <p
179
- v-if="source.DescHtml"
179
+ v-if="source.Desc"
180
180
  class="u-desc u-yellow">
181
- <game-text :client="client" :text="source.DescHtml || source.Desc"></game-text>
181
+ <game-text :client="client" :text="source.Desc"></game-text>
182
182
  </p>
183
183
  <!-- 五彩石属性 -->
184
184
  <p v-if="source.WuCaiHtml" class="u-desc" v-html="source.WuCaiHtml"></p>
package/src/Resource.vue CHANGED
@@ -102,7 +102,9 @@
102
102
  <span class="u-id">ID:{{ o.id }}</span>
103
103
  <img class="u-pic" :title="'IconID:' + o.IconID" :src="iconURL(o.IconID)" />
104
104
  <span class="u-name">{{ o.Name }}</span>
105
- <span class="u-content" v-html="o.DescHtml"></span>
105
+ <span class="u-content">
106
+ <game-text :text="o.Desc"></game-text>
107
+ </span>
106
108
  <span class="u-remark">
107
109
  {{ o.Requirement }}
108
110
  </span>
@@ -202,6 +204,7 @@ import { loadEmotions } from "../service/cms";
202
204
  import { __ossRoot, __iconPath, __Root, __OriginRoot } from "@jx3box/jx3box-common/data/jx3box.json";
203
205
  import detach_types from "../assets/data/detach_type.json";
204
206
  import { iconLink, getLink, showAvatar } from "@jx3box/jx3box-common/js/utils";
207
+ import GameText from "./GameText.vue";
205
208
  import User from "@jx3box/jx3box-common/js/user";
206
209
  import Item from './Item.vue';
207
210
  export default {
@@ -287,7 +290,7 @@ export default {
287
290
  },
288
291
  canInsertAuthor: function() {
289
292
  return User.getLevel(this.userInfo && this.userInfo.experience) >= 2;
290
- },
293
+ }
291
294
  },
292
295
  watch: {
293
296
  html: function(newval) {
@@ -502,7 +505,8 @@ export default {
502
505
  this.checkUA();
503
506
  },
504
507
  components: {
505
- 'jx3-item': Item
508
+ 'jx3-item': Item,
509
+ GameText
506
510
  },
507
511
  };
508
512
  </script>