@jx3box/jx3box-ui 2.4.12 → 2.4.14

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.
@@ -125,131 +125,140 @@
125
125
  }
126
126
  }
127
127
 
128
+ // 打赏记录:宽屏对齐列,窄容器保留寄语与时间。
129
+ .w-boxcoin-records {
130
+ container-type: inline-size;
131
+ }
128
132
  .w-boxcoin-records-list {
129
133
  max-width: 960px;
130
- border: 1px solid #eee;
131
134
  margin: 0 auto;
132
- border-radius: 6px;
133
135
  overflow: hidden;
136
+ border: 1px solid #e9ebf0;
137
+ border-radius: 8px;
138
+ background: #fff;
134
139
 
135
140
  .u-list {
136
- list-style: none;
137
- .x(left);
138
- margin: 0 auto;
141
+ margin: 0;
139
142
  padding: 0;
143
+ list-style: none;
144
+ text-align: left;
140
145
  }
141
146
  .u-item {
142
- border-bottom: 1px dashed #eee;
143
- .fz(13px,2.5);
144
- .clearfix;
145
- padding: 4px 10px;
146
- &:last-child {
147
- border: none;
148
- }
149
- display: flex;
150
- white-space: nowrap;
151
-
152
- a {
153
- color: var(--el-color-primary);
154
- }
155
- }
156
- .u-meta {
157
- .db;
158
- .fl;
147
+ display: grid;
148
+ grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1fr) 84px minmax(0, 1.4fr) 142px;
149
+ align-items: center;
150
+ gap: 12px;
151
+ padding: 10px 16px;
152
+ border-bottom: 1px solid #f0f1f5;
153
+ font-size: 13px;
154
+ line-height: 1.6;
155
+ &:last-child { border-bottom: 0; }
159
156
  }
157
+ .u-meta { min-width: 0; }
160
158
  .u-action {
161
- .w(40px);
162
- .db;
163
- padding-right: 10px;
164
- .flex;
159
+ display: flex;
165
160
  align-items: center;
166
161
  justify-content: center;
167
- svg {
168
- .size(24px);
169
- .db;
170
- .auto(x);
171
- }
172
- .x;
162
+ i { display: flex; }
163
+ svg, img { display: block; width: 20px; height: 20px; }
164
+ .el-icon svg { width: 16px; height: 16px; }
173
165
  }
174
166
  .u-user {
175
- .w(120px);
176
- .nobreak;
177
- .flex;
167
+ display: flex;
178
168
  align-items: center;
179
- &[href]:hover {
180
- text-decoration: underline;
181
- }
182
- .mr(20px);
183
-
184
- &.u-default {
185
- color: @color;
186
- &:hover {
187
- text-decoration: none;
188
- }
189
- }
169
+ gap: 6px;
170
+ color: #475569;
171
+ text-decoration: none;
172
+ span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
173
+ &[href]:hover { color: var(--el-color-primary); }
190
174
  .u-user-avatar {
191
- .y;
192
- .size(24px);
193
- .mr(5px);
194
- .r(2px);
175
+ flex: 0 0 24px;
176
+ width: 24px;
177
+ height: 24px;
178
+ border-radius: 50%;
179
+ object-fit: cover;
180
+ background: #f5f6f8;
195
181
  }
196
182
  }
197
- .u-count {
198
- .w(120px);
199
- }
200
183
  .u-head {
201
- background-color: @bg-light;
202
- color: @v4text;
184
+ padding-top: 8px;
185
+ padding-bottom: 8px;
186
+ background: #f8f9fb;
187
+ color: #7b8798;
188
+ font-size: 12px;
189
+ font-weight: 500;
190
+ .u-user { color: inherit; }
203
191
  }
204
192
  .u-body {
193
+ &:hover { background: #fdfbfc; }
205
194
  .u-count {
206
- color: #fd76a7;
207
- font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
208
- }
209
- .u-time {
210
- color: @v4tip;
211
- }
212
- .u-remark {
213
- .nobreak;
214
- .w(280px);
215
- color: @color;
216
- }
217
- .u-delete {
218
- .ml(20px);
219
- color: #c00;
220
- i {
221
- .mr(3px);
222
- }
223
- .pointer;
224
- &:hover {
225
- color: #f00;
226
- }
227
- }
228
- .u-client {
229
- color: @v4focus;
195
+ justify-self: start;
196
+ padding: 2px 8px;
197
+ border-radius: 4px;
198
+ background: #fff0f5;
199
+ color: #db5181;
200
+ font-variant-numeric: tabular-nums;
201
+ white-space: nowrap;
230
202
  }
203
+ .u-remark { color: #596273; overflow-wrap: anywhere; white-space: pre-wrap; }
204
+ .u-time { color: #8b95a5; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
205
+ }
206
+ .u-operations {
207
+ display: flex;
208
+ align-items: center;
209
+ justify-content: flex-end;
210
+ flex-wrap: wrap;
211
+ gap: 6px;
212
+ min-width: 0;
231
213
  }
214
+ .u-client { color: #929aaa; font-size: 11px; overflow-wrap: anywhere; }
215
+ .u-delete {
216
+ padding: 3px 6px;
217
+ border: 0;
218
+ border-radius: 4px;
219
+ background: transparent;
220
+ color: #b76b73;
221
+ font: inherit;
222
+ font-size: 12px;
223
+ white-space: nowrap;
224
+ cursor: pointer;
225
+ &:hover { background: #fff0f0; color: #d94757; }
226
+ }
227
+ a:focus-visible, button:focus-visible { outline: 2px solid var(--el-color-primary); outline-offset: 2px; }
228
+ }
229
+ .w-boxcoin-records.is-admin .u-item {
230
+ grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1fr) 76px minmax(0, 1.2fr) 142px 90px;
231
+ column-gap: 10px;
232
232
  }
233
233
  .w-boxcoin-records-pages {
234
+ display: flex;
234
235
  justify-content: center;
235
- padding-top: 2px;
236
+ margin-top: 12px;
236
237
  }
237
-
238
- @media screen and (max-width: @phone) {
238
+ .boxcoin-records-compact() {
239
239
  .w-boxcoin-records-list {
240
- overflow-x: auto;
241
- .u-list {
242
- .w(100%);
240
+ .u-head { display: none; }
241
+ .u-item.u-body {
242
+ grid-template-columns: 20px minmax(0, 1fr) auto;
243
+ gap: 8px;
244
+ padding: 12px;
243
245
  }
244
- .u-user {
245
- .w(100px);
246
- }
247
- .u-count {
248
- .w(80px);
249
- }
250
- .u-time,
251
- .u-remark {
252
- .none;
246
+ .u-action { grid-column: 1; grid-row: 1; }
247
+ .u-participant { grid-column: 2; grid-row: 1; }
248
+ .u-count { grid-column: 3; grid-row: 1; }
249
+ .u-author {
250
+ grid-column: 2 / -1;
251
+ &::before { content: attr(data-label); flex-shrink: 0; color: #8b95a5; font-size: 12px; }
252
+ .u-user-avatar { flex-basis: 22px; width: 22px; height: 22px; }
253
253
  }
254
+ .u-remark { grid-column: 2 / -1; }
255
+ .u-time { grid-column: 2 / -1; }
256
+ .u-operations { grid-column: 2 / -1; justify-content: flex-start; }
254
257
  }
255
258
  }
259
+ @container (max-width: 800px) {
260
+ .boxcoin-records-compact();
261
+ }
262
+ @media screen and (max-width: @phone) {
263
+ .boxcoin-records-compact();
264
+ }
@@ -407,3 +407,12 @@
407
407
  display: none;
408
408
  }
409
409
  }
410
+
411
+ @media screen and (max-width: 720px) {
412
+ .c-wiki-panel.is-surface > .m-panel-body > .m-wiki-metas {
413
+ .u-meta { max-width: 100%; flex-wrap: wrap; gap: 6px; }
414
+ .u-label { flex-shrink: 0; margin-right: 2px; white-space: nowrap; }
415
+ .u-creator { margin-right: 0; }
416
+ .u-value:not(.u-creator) { min-width: 0; overflow-wrap: anywhere; }
417
+ }
418
+ }
@@ -116,26 +116,45 @@
116
116
  }
117
117
 
118
118
  @media screen and (max-width: 720px) {
119
- .c-wiki-revisions.is-surface {
120
- .m-revisions-panel {
121
- scrollbar-width: thin;
122
- box-shadow: inset -12px 0 12px -12px rgba(15, 23, 42, 0.2);
123
- }
124
-
125
- .m-histories {
126
- min-width: 560px;
127
-
128
- th,
129
- td {
130
- min-width: 100px;
131
- padding: 8px;
132
- font-size: 12px;
133
- }
134
-
135
- th:first-child,
136
- td:first-child {
137
- min-width: 44px;
138
- }
119
+ .c-wiki-revisions.is-surface > .m-panel-body .m-revisions-panel {
120
+ min-width: 0;
121
+ max-width: 100%;
122
+ overflow-x: visible;
123
+ box-shadow: none;
124
+ .m-histories {
125
+ display: block;
126
+ width: 100%;
127
+ min-width: 0;
128
+ max-width: 100%;
129
+ margin: 0;
130
+ box-sizing: border-box;
131
+ thead { display: none; }
132
+ tbody { display: grid; gap: 10px; }
133
+ tbody, tr { min-width: 0; max-width: 100%; }
134
+ tr {
135
+ display: grid;
136
+ grid-template-columns: minmax(64px, 0.7fr) minmax(0, 1.3fr);
137
+ border: 1px solid #e4e7ed;
138
+ border-radius: 6px;
139
+ background: #fff;
140
+ overflow: hidden;
141
+ }
142
+ td, td:first-child {
143
+ display: flex;
144
+ flex-direction: column;
145
+ gap: 2px;
146
+ width: auto;
147
+ min-width: 0;
148
+ padding: 8px;
149
+ border: 0;
150
+ font-size: 12px;
151
+ white-space: normal;
152
+ overflow: visible;
153
+ overflow-wrap: anywhere;
154
+ &::before { content: attr(data-label); color: #909399; font-size: 11px; line-height: 1.4; white-space: normal; }
155
+ > a { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
156
+ }
157
+ td:nth-child(3), td:nth-child(4) { grid-column: 1 / -1; border-top: 1px solid #ebeef5; }
158
+ }
139
159
  }
140
- }
141
160
  }
@@ -265,6 +265,7 @@ export default {
265
265
  success: "Success",
266
266
  },
267
267
  boxcoinRecords: {
268
+ time: "Time",
268
269
  participant: "Sender",
269
270
  author: "Author",
270
271
  boxcoin: "BoxCoin",
@@ -265,6 +265,7 @@ export default {
265
265
  success: "Thành công",
266
266
  },
267
267
  boxcoinRecords: {
268
+ time: "Thời gian",
268
269
  participant: "Người tặng",
269
270
  author: "Tác giả nhận",
270
271
  boxcoin: "BoxCoin",
@@ -305,6 +305,7 @@ export default {
305
305
  success: "操作成功",
306
306
  },
307
307
  boxcoinRecords: {
308
+ time: "时间",
308
309
  participant: "参与打赏",
309
310
  author: "收益作者",
310
311
  boxcoin: "盒币",
@@ -265,6 +265,7 @@ export default {
265
265
  success: "操作成功",
266
266
  },
267
267
  boxcoinRecords: {
268
+ time: "時間",
268
269
  participant: "參與打賞",
269
270
  author: "收益作者",
270
271
  boxcoin: "盒幣",
package/index.js CHANGED
@@ -96,3 +96,5 @@ export {
96
96
  setJx3boxUiLocale,
97
97
  createJx3boxTrafficAnalytics,
98
98
  };
99
+
100
+ export { default as ResponsiveCodeDiff } from "./src/wiki/ResponsiveCodeDiff.vue";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-ui",
3
- "version": "2.4.12",
3
+ "version": "2.4.14",
4
4
  "description": "JX3BOX Vue3 UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,16 +1,16 @@
1
1
  <template>
2
- <div class="w-boxcoin-records" v-loading="loading">
2
+ <div class="w-boxcoin-records" :class="{ 'is-admin': isSuperAdmin }" v-loading="loading">
3
3
  <div class="w-boxcoin-records-list" v-if="list && list.length">
4
4
  <ul class="u-list">
5
5
  <li class="u-item u-head">
6
6
  <span class="u-meta u-action">
7
7
  <el-icon><Trophy /></el-icon>
8
8
  </span>
9
- <span class="u-meta u-user">{{ $jx3boxT("jx3boxUi.boxcoinRecords.participant", "参与打赏") }}</span>
10
- <span class="u-meta u-user">{{ $jx3boxT("jx3boxUi.boxcoinRecords.author", "收益作者") }}</span>
9
+ <span class="u-meta u-user u-participant">{{ $jx3boxT("jx3boxUi.boxcoinRecords.participant", "参与打赏") }}</span>
10
+ <span class="u-meta u-user u-author">{{ $jx3boxT("jx3boxUi.boxcoinRecords.author", "收益作者") }}</span>
11
11
  <span class="u-meta u-count">{{ $jx3boxT("jx3boxUi.boxcoinRecords.boxcoin", "盒币") }}</span>
12
12
  <span class="u-meta u-remark">{{ $jx3boxT("jx3boxUi.boxcoinRecords.remark", "寄语") }}</span>
13
- <time class="u-meta u-time"></time>
13
+ <span class="u-meta u-time">{{ $jx3boxT("jx3boxUi.boxcoinRecords.time", "时间") }}</span>
14
14
  </li>
15
15
  <li v-for="(item, i) in list" :key="i" class="u-item u-body">
16
16
  <span class="u-meta u-action">
@@ -22,18 +22,18 @@
22
22
  </template>
23
23
  </span>
24
24
  <template v-if="item.ext_operate_user_info?.id == 1">
25
- <span class="u-meta u-user u-default">
25
+ <span class="u-meta u-user u-participant u-default">
26
26
  <img class="u-user-avatar" :src="showAvatar(item.ext_operate_user_info.avatar)" alt />
27
27
  <span>{{ $jx3boxT("jx3boxUi.boxcoinRecords.system", "系统") }}</span>
28
28
  </span>
29
29
  </template>
30
- <a v-else class="u-meta u-user" :href="authorLink(item.operate_user_id)" target="_blank">
30
+ <a v-else class="u-meta u-user u-participant" :href="authorLink(item.operate_user_id)" target="_blank">
31
31
  <img class="u-user-avatar" :src="showAvatar(item.ext_operate_user_info.avatar)" alt />
32
- <span>{{ item.ext_operate_user_info.display_name }}</span>
32
+ <span :title="item.ext_operate_user_info.display_name">{{ item.ext_operate_user_info.display_name }}</span>
33
33
  </a>
34
- <a class="u-meta u-user" :href="authorLink(item.user_id)" target="_blank">
34
+ <a class="u-meta u-user u-author" :data-label="$jx3boxT('jx3boxUi.boxcoinRecords.author', '收益作者')" :href="authorLink(item.user_id)" target="_blank">
35
35
  <img class="u-user-avatar" :src="showAvatar(item.ext_user_info.avatar)" alt />
36
- <span>{{ item.ext_user_info.display_name }}</span>
36
+ <span :title="item.ext_user_info.display_name">{{ item.ext_user_info.display_name }}</span>
37
37
  </a>
38
38
  <span class="u-meta u-count">
39
39
  +
@@ -41,9 +41,11 @@
41
41
  </span>
42
42
  <span class="u-meta u-remark">{{ item.remark }}</span>
43
43
  <time class="u-meta u-time">{{ showTime(item.created_at) }}</time>
44
- <span class="u-delete" v-if="isSuperAdmin" @click="recovery(item, i)">
45
- <i class="Delete"></i>{{ $jx3boxT("jx3boxUi.boxcoinRecords.revoke", "撤销") }}
46
- (<span class="u-client">{{ item.client }}</span>)
44
+ <span class="u-operations" v-if="isSuperAdmin">
45
+ <button type="button" class="u-delete" @click="recovery(item, i)">
46
+ {{ $jx3boxT("jx3boxUi.boxcoinRecords.revoke", "撤销") }}
47
+ </button>
48
+ <span class="u-client" v-if="item.client">({{ item.client }})</span>
47
49
  </span>
48
50
  </li>
49
51
  </ul>
@@ -190,14 +192,8 @@ export default {
190
192
  };
191
193
  </script>
192
194
 
193
-
194
195
  <style lang="less">
195
- /* src/interact/BoxcoinRecords.vue */
196
- .w-boxcoin-records-pages{
197
-
198
-
199
-
200
- .flex(x);
201
- margin-top:5px;
196
+ @media screen and (max-width: 720px) {
197
+ .w-boxcoin-records .u-delete { display: none; }
202
198
  }
203
199
  </style>
@@ -56,17 +56,16 @@
56
56
  </div>
57
57
  </div>
58
58
  <div v-if="type === 'code'" class="m-content-container">
59
- <code-diff
59
+ <ResponsiveCodeDiff
60
60
  class="m-content-view"
61
61
  :old-string="content1"
62
62
  :new-string="content2"
63
63
  :context="1024"
64
- output-format="side-by-side"
65
64
  maxHeight="520px"
66
65
  :filename="`${content1Len}字`"
67
66
  :newFilename="`${content2Len}字`"
68
67
  ignoreMatchingLines="data:image/png;base64,"
69
- ></code-diff>
68
+ ></ResponsiveCodeDiff>
70
69
  </div>
71
70
  </div>
72
71
  </el-dialog>
@@ -75,11 +74,11 @@
75
74
  <script>
76
75
  import { getCommitByHash } from "../../service/commit-history";
77
76
  import Article from "@jx3box/jx3box-editor/src/Article.vue";
78
- import { CodeDiff } from "v-code-diff";
77
+ import ResponsiveCodeDiff from "../wiki/ResponsiveCodeDiff.vue";
79
78
  export default {
80
79
  name: "VersionDialog",
81
80
  components: {
82
- CodeDiff,
81
+ ResponsiveCodeDiff,
83
82
  Article,
84
83
  },
85
84
  props: {
@@ -236,4 +235,12 @@ export default {
236
235
  }
237
236
  }
238
237
  }
238
+ @media screen and (max-width: 720px) {
239
+ .m-version-contrast-dialog {
240
+ .m-toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
241
+ .m-toolbar .m-select { flex-direction: column; gap: 10px; }
242
+ .m-content-container { flex-direction: column; max-height: none; overflow: visible; }
243
+ .m-content-container .u-content { min-width: 0; width: 100%; height: auto; }
244
+ }
245
+ }
239
246
  </style>
@@ -0,0 +1,93 @@
1
+ <template>
2
+ <div class="w-responsive-code-diff">
3
+ <div v-if="isMobile" class="m-stacked-diff">
4
+ <section v-for="side in ['old', 'new']" :key="side" class="m-version-panel" :class="'is-' + side">
5
+ <h3>{{ side === 'old' ? filename : newFilename }}</h3>
6
+ <CodeDiff v-bind="$attrs" :old-string="oldString" :new-string="newString" :context="Number.MAX_SAFE_INTEGER" output-format="side-by-side" :hide-header="true" :max-height="mobileMaxHeight" />
7
+ </section>
8
+ </div>
9
+ <CodeDiff v-else v-bind="$attrs" :old-string="oldString" :new-string="newString" :filename="filename" :new-filename="newFilename" :context="context" output-format="side-by-side" :max-height="maxHeight" />
10
+ </div>
11
+ </template>
12
+
13
+ <script>
14
+ import { CodeDiff } from "v-code-diff";
15
+
16
+ export default {
17
+ name: "ResponsiveCodeDiff",
18
+ inheritAttrs: false,
19
+ components: { CodeDiff },
20
+ props: {
21
+ oldString: { type: String, default: "" },
22
+ newString: { type: String, default: "" },
23
+ filename: { type: String, default: "" },
24
+ newFilename: { type: String, default: "" },
25
+ context: { type: Number, default: 1024 },
26
+ maxHeight: { type: String, default: "600px" },
27
+ mobileMaxHeight: { type: String, default: "420px" },
28
+ },
29
+ data() {
30
+ return { isMobile: typeof window !== "undefined" && window.matchMedia("(max-width: 720px)").matches };
31
+ },
32
+ mounted() {
33
+ this.mobileQuery = window.matchMedia("(max-width: 720px)");
34
+ this.isMobile = this.mobileQuery.matches;
35
+ this.mobileQuery.addEventListener("change", this.updateLayout);
36
+ },
37
+ beforeUnmount() {
38
+ this.mobileQuery?.removeEventListener("change", this.updateLayout);
39
+ },
40
+ methods: {
41
+ updateLayout(event) { this.isMobile = event.matches; },
42
+ },
43
+ };
44
+ </script>
45
+
46
+ <style lang="less">
47
+ .w-responsive-code-diff {
48
+ width: 100%;
49
+ min-width: 0;
50
+ .file-header .file-info { height: auto; min-height: 24px; flex-wrap: wrap; gap: 8px; }
51
+ .file-header .info-left, .file-header .info-right { min-width: 0; overflow-wrap: anywhere; }
52
+ .m-stacked-diff {
53
+ display: grid;
54
+ gap: 16px;
55
+ }
56
+
57
+ .m-version-panel {
58
+ min-width: 0;
59
+ border: 1px solid #e4e7ed;
60
+ border-radius: 8px;
61
+ overflow: hidden;
62
+
63
+ h3 {
64
+ margin: 0;
65
+ padding: 10px 12px;
66
+ background: #f6f7fa;
67
+ border-bottom: 1px solid #e4e7ed;
68
+ font-size: 12px;
69
+ font-weight: 500;
70
+ line-height: 1.6;
71
+ white-space: normal;
72
+ overflow-wrap: anywhere;
73
+ }
74
+
75
+ .code-diff-view { margin: 0; border: 0; border-radius: 0; }
76
+ .diff-table { table-layout: fixed; }
77
+ .blob-num { min-width: 32px; padding: 0 5px; font-size: 11px; }
78
+ .blob-code { padding: 0 8px; font-size: 12px; }
79
+ .blob-code-inner { white-space: pre-wrap; overflow-wrap: anywhere; }
80
+
81
+ &.is-old {
82
+ col:nth-child(n + 3), td:nth-child(n + 3) { display: none; }
83
+ col:first-child { width: 32px; }
84
+ }
85
+ &.is-new {
86
+ col:nth-child(-n + 2), td:nth-child(-n + 2) { display: none; }
87
+ col:nth-child(3) { width: 32px; }
88
+ }
89
+ }
90
+
91
+
92
+ }
93
+ </style>
@@ -20,20 +20,22 @@
20
20
  <th>{{ $jx3boxT('jx3boxUi.wikiRevisions.remark', '修订说明') }}</th>
21
21
  </tr>
22
22
  </thead>
23
+ <tbody>
23
24
  <tr class="history" v-for="(ver, key) in versions" :key="key">
24
- <td>
25
+ <td :data-label="$jx3boxT('jx3boxUi.wikiRevisions.version', '版本')">
25
26
  <a
26
27
  :href="link(type, `${ver.source_id}/${ver.id}`)"
27
28
  v-text="'v' + (versions.length - key)"
28
29
  @click="redirectRevision(ver, $event)"
29
30
  ></a>
30
31
  </td>
31
- <td v-text="ts2str(ver.updated)"></td>
32
- <td>
32
+ <td :data-label="$jx3boxT('jx3boxUi.wikiPanel.updatedAt', '更新时间')" v-text="ts2str(ver.updated)"></td>
33
+ <td :data-label="$jx3boxT('jx3boxUi.wikiRevisions.contributor', '贡献者')">
33
34
  <a :href="ver.user_id ? author_url(ver.user_id) : null" v-text="ver.user_nickname"></a>
34
35
  </td>
35
- <td v-text="ver.remark"></td>
36
+ <td :data-label="$jx3boxT('jx3boxUi.wikiRevisions.remark', '修订说明')" v-text="ver.remark"></td>
36
37
  </tr>
38
+ </tbody>
37
39
  </table>
38
40
  </div>
39
41
  </template>
@@ -0,0 +1,61 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('node:fs');
4
+ const Vue = require('vue');
5
+ const { parse } = require('@vue/compiler-sfc');
6
+ const { compile } = require('@vue/compiler-dom');
7
+ const { renderToString } = require('@vue/server-renderer');
8
+
9
+ function loadViewer() {
10
+ const source = fs.readFileSync(require.resolve('../src/wiki/ResponsiveCodeDiff.vue'), 'utf8');
11
+ const { descriptor } = parse(source);
12
+ const CodeDiff = {
13
+ props: ['oldString', 'newString', 'outputFormat', 'hideHeader'],
14
+ render() {
15
+ return Vue.h('pre', { 'data-format': this.outputFormat, 'data-hidden-header': this.hideHeader }, this.oldString + '|' + this.newString);
16
+ },
17
+ };
18
+ const component = new Function('CodeDiff', descriptor.script.content.replace(/^import .*;$/gm, '').replace('export default', 'return'))(CodeDiff);
19
+ component.render = new Function('Vue', compile(descriptor.template.content, { mode: 'function' }).code)(Vue);
20
+ return component;
21
+ }
22
+
23
+ test('手机端两个独立版本容器保留原始对比数据,桌面端只渲染一组左右对比', async () => {
24
+ for (const mobile of [true, false]) {
25
+ const component = loadViewer();
26
+ component.data = () => ({ isMobile: mobile });
27
+ const html = await renderToString(Vue.createSSRApp(component, {
28
+ oldString: 'old <p>内容</p>', newString: 'new 内容', filename: 'v2 长说明', newFilename: 'v3 长说明',
29
+ }));
30
+ assert.equal((html.match(/<pre/g) || []).length, mobile ? 2 : 1);
31
+ assert.equal((html.match(/data-format="side-by-side"/g) || []).length, mobile ? 2 : 1);
32
+ if (mobile) {
33
+ assert.match(html, /is-old/);
34
+ assert.match(html, /is-new/);
35
+ assert.match(html, /<h3>v2 长说明<\/h3>/);
36
+ assert.match(html, /<h3>v3 长说明<\/h3>/);
37
+ }
38
+ assert.match(html, /old &lt;p&gt;内容&lt;\/p&gt;\|new 内容/);
39
+ }
40
+ });
41
+
42
+ test('屏幕宽度变化更新布局,卸载时移除监听', () => {
43
+ const component = loadViewer();
44
+ const previousWindow = global.window;
45
+ let handler;
46
+ let removed = false;
47
+ const query = { matches: true, addEventListener(name, fn) { assert.equal(name, 'change'); handler = fn; }, removeEventListener(name, fn) { removed = name === 'change' && fn === handler; } };
48
+ global.window = { matchMedia: () => query };
49
+ try {
50
+ const context = { isMobile: false, updateLayout: component.methods.updateLayout };
51
+ component.mounted.call(context);
52
+ assert.equal(context.isMobile, true);
53
+ handler.call(context, { matches: false });
54
+ assert.equal(context.isMobile, false);
55
+ component.beforeUnmount.call(context);
56
+ assert.equal(removed, true);
57
+ } finally {
58
+ if (previousWindow === undefined) delete global.window;
59
+ else global.window = previousWindow;
60
+ }
61
+ });