adtec-core-package 2.7.6 → 2.7.8

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": "adtec-core-package",
3
- "version": "2.7.6",
3
+ "version": "2.7.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -17,13 +17,14 @@
17
17
  <script setup lang="ts">
18
18
  import { AiEditor } from 'aieditor'
19
19
  import 'aieditor/dist/style.css'
20
- import type { WatchStopHandle } from 'vue'
20
+ import { onActivated, type WatchStopHandle } from 'vue'
21
21
  import { onMounted, onUnmounted, ref, watch } from 'vue'
22
22
  import { ElMessage } from 'element-plus'
23
23
 
24
24
  enum WatchType {
25
25
  initWatch = 'initWatch',
26
26
  }
27
+
27
28
  const watchHandlers = ref<Partial<Record<WatchType, WatchStopHandle>>>({})
28
29
 
29
30
  const divRef = ref()
@@ -56,17 +57,17 @@ const props = withDefaults(
56
57
  showToolbar: true,
57
58
  borderWidth: '1px',
58
59
  editorConfig: {},
59
- isEdit: true,
60
- },
60
+ isEdit: true
61
+ }
61
62
  )
62
63
  const model = defineModel({
63
64
  type: [String, null, undefined],
64
65
  required: false,
65
- default: null,
66
+ default: null
66
67
  })
67
68
  const text = defineModel('text', {
68
69
  type: String,
69
- required: false,
70
+ required: false
70
71
  })
71
72
  //字体对照表
72
73
  const fontSizes = [
@@ -85,8 +86,9 @@ const fontSizes = [
85
86
  { name: '小一', pt: 24, px: 28 },
86
87
  { name: '一号', pt: 26, px: 30 },
87
88
  { name: '小初', pt: 36, px: 42 },
88
- { name: '初号', pt: 42, px: 49 },
89
+ { name: '初号', pt: 42, px: 49 }
89
90
  ]
91
+
90
92
  function setDefaultPx(html: string) {
91
93
  // 创建临时div用于解析HTML
92
94
  const tempDiv = document.createElement('div')
@@ -104,6 +106,7 @@ function setDefaultPx(html: string) {
104
106
  })
105
107
  return tempDiv.innerHTML
106
108
  }
109
+
107
110
  function convertPxToPt(html: string) {
108
111
  html = setDefaultPx(html)
109
112
  const regex = /font-size: (\d+)px/g
@@ -116,6 +119,7 @@ function convertPxToPt(html: string) {
116
119
  return match
117
120
  })
118
121
  }
122
+
119
123
  function convertPtToPx(html: string) {
120
124
  const regex = /font-size: (\d+)pt/g
121
125
  return html.replace(regex, (match, ptValue) => {
@@ -127,6 +131,7 @@ function convertPtToPx(html: string) {
127
131
  return match
128
132
  })
129
133
  }
134
+
130
135
  //默认的配置
131
136
  const defaultConfig = {
132
137
  placeholder: '请输入内容...',
@@ -140,11 +145,11 @@ const defaultConfig = {
140
145
  'video',
141
146
  'ai',
142
147
  'quote',
143
- 'emoji',
148
+ 'emoji'
144
149
  ],
145
150
  textSelectionBubbleMenu: {
146
151
  enable: true,
147
- items: ['Bold', 'Italic', 'Underline', 'Strike', 'code', 'comment'],
152
+ items: ['Bold', 'Italic', 'Underline', 'Strike', 'code', 'comment']
148
153
  },
149
154
  image: {
150
155
  uploaderEvent: {
@@ -153,18 +158,18 @@ const defaultConfig = {
153
158
  ElMessage.warning('图片大小不能超过2M')
154
159
  return false
155
160
  }
156
- },
161
+ }
157
162
  // onSuccess: (file, response) => {
158
163
  // console.log('onSuccess', file, response)
159
164
  // }
160
- },
165
+ }
161
166
  },
162
167
  htmlPasteConfig: {
163
168
  pasteProcessor: (html) => {
164
169
  // return html;
165
170
  // console.log('html:', html, 'xxxxxx', removeAllFontFamilyStyles(html))
166
171
  return removeAllFontFamilyStyles(html)
167
- },
172
+ }
168
173
  },
169
174
  fontSize: {
170
175
  defaultValue: ' ',
@@ -185,8 +190,8 @@ const defaultConfig = {
185
190
  { name: '六号', value: 9 },
186
191
  { name: '小六', value: 8 },
187
192
  { name: '七号', value: 6 },
188
- { name: '八号', value: 5 },
189
- ],
193
+ { name: '八号', value: 5 }
194
+ ]
190
195
  },
191
196
  onChange: (editor: AiEditor) => {
192
197
  setFooter()
@@ -195,7 +200,7 @@ const defaultConfig = {
195
200
  setTimeout(() => {
196
201
  setContent()
197
202
  }, 200)
198
- },
203
+ }
199
204
  }
200
205
 
201
206
  /**
@@ -224,7 +229,7 @@ function removeAllFontFamilyStyles(html: string): string {
224
229
  // 使用简化的正则表达式移除字体相关属性(现在可以安全地假设每个属性后都有分号)
225
230
  style = style.replace(
226
231
  /(?:font-family|mso-(?:ascii|hansi|bidi|fareast|east-asian|font)-font-family)\s*:\s*[^;]+;/gi,
227
- '',
232
+ ''
228
233
  )
229
234
  // 清理空样式
230
235
  style = style.trim()
@@ -244,7 +249,7 @@ function removeAllFontFamilyStyles(html: string): string {
244
249
  'mso-ascii-font-family',
245
250
  'mso-fareast-font-family',
246
251
  'mso-east-asian-font-family',
247
- 'mso-font-font-family',
252
+ 'mso-font-font-family'
248
253
  ]
249
254
  fontFamilyAttrs.forEach((attr) => element.removeAttribute(attr))
250
255
 
@@ -271,6 +276,7 @@ function removeAllFontFamilyStyles(html: string): string {
271
276
  Array.from(tempDiv.children).forEach((child) => processElement(child))
272
277
  return tempDiv.innerHTML
273
278
  }
279
+
274
280
  /**
275
281
  * 计算富文本框中图片的高度并赋值
276
282
  */
@@ -284,7 +290,7 @@ function calcImagesHeight(html: string) {
284
290
  if (width > 1 && height > 1) {
285
291
  map.set(
286
292
  imageElement.src.length > 100 ? imageElement.src.substring(0, 100) : imageElement.src,
287
- height,
293
+ height
288
294
  )
289
295
  }
290
296
  })
@@ -300,7 +306,7 @@ function customStringReplacement(
300
306
  startMarker: string,
301
307
  endMarker: string,
302
308
  target: string,
303
- replacement: string,
309
+ replacement: string
304
310
  ): string {
305
311
  let result = ''
306
312
  let currentIndex = 0
@@ -333,6 +339,7 @@ function initHtml(html: string) {
333
339
  html = customStringReplacement(html, '<img', '>', 'height="[0-9]+"', 'height="auto"')
334
340
  return convertPtToPx(html)
335
341
  }
342
+
336
343
  const stopWatchByType = (type: WatchType) => {
337
344
  const stopHandle = watchHandlers.value[type]
338
345
  if (stopHandle) {
@@ -355,10 +362,11 @@ onMounted(() => {
355
362
  { name: '微软雅黑', value: 'Microsoft YaHei' },
356
363
  { name: '方正仿宋简体_GBK', value: 'FangSong_GB2312' },
357
364
  { name: 'Arial', value: 'Arial' },
358
- { name: 'Times New Roman', value: 'Times New Roman' },
359
- ],
365
+ { name: 'Times New Roman', value: 'Times New Roman' }
366
+ ]
360
367
  },
361
368
  onCreated: (editor: AiEditor) => {
369
+ setFooter()
362
370
  stopWatchByType(WatchType.initWatch)
363
371
  watchHandlers.value[WatchType.initWatch] = watch(
364
372
  () => props.isEdit,
@@ -366,19 +374,26 @@ onMounted(() => {
366
374
  if (aiEditor) {
367
375
  aiEditor.setEditable(val)
368
376
  //头尾显隐
369
- const footer = divRef.value?.querySelector('aie-footer') as HTMLElement
370
- if (footer) {
371
- footer.style.display = val ? '' : 'none'
372
- }
377
+ // const footer = divRef.value?.querySelector('aie-footer') as HTMLElement
378
+ // if (footer) {
379
+ // footer.style.display = val ? '' : 'none'
380
+ // }
373
381
  const header = divRef.value?.querySelector('aie-header') as HTMLElement
374
382
  if (header) {
375
- header.style.display = val ? '' : 'none'
383
+ const div = header.querySelector('div') as HTMLElement
384
+ div.style.justifyContent = val ? '' : 'end'
385
+ const menuItems = header.querySelectorAll('.aie-menu-item:not(:last-child)')
386
+ if (menuItems.length) {
387
+ menuItems.forEach((item) => {
388
+ item.style.display = val ? '' : 'none'
389
+ })
390
+ }
376
391
  }
377
392
  }
378
393
  },
379
- { immediate: true },
394
+ { immediate: true }
380
395
  )
381
- },
396
+ }
382
397
  }
383
398
  // 隐藏工具栏
384
399
  if (!props.showToolbar) {
@@ -386,23 +401,21 @@ onMounted(() => {
386
401
  }
387
402
  setTimeout(() => {
388
403
  aiEditor = new AiEditor(config)
389
- setTimeout(() => {
390
- //当隐藏工具栏时,也隐藏 aie-footer/aie-header 元素
391
- if (!props.showToolbar || props.editorConfig?.editable === false) {
392
- const footer = divRef.value?.querySelector('aie-footer') as HTMLElement
393
- if (footer) {
394
- footer.style.display = 'none'
395
- }
396
- const header = divRef.value?.querySelector('aie-header') as HTMLElement
397
- if (header) {
398
- header.style.display = 'none'
399
- }
400
- }
401
- setFooter()
402
- }, 100)
403
404
  }, 100)
404
405
  })
405
-
406
+ onActivated(()=>{
407
+ const header = divRef.value?.querySelector('aie-header') as HTMLElement
408
+ if (header) {
409
+ const div = header.querySelector('div') as HTMLElement
410
+ div.style.justifyContent = props.isEdit ? '' : 'end'
411
+ const menuItems = header.querySelectorAll('.aie-menu-item:not(:last-child)')
412
+ if (menuItems.length) {
413
+ menuItems.forEach((item) => {
414
+ item.style.display = props.isEdit ? '' : 'none'
415
+ })
416
+ }
417
+ }
418
+ })
406
419
  const setFooter = () => {
407
420
  const footer = divRef.value?.querySelector('aie-footer') as HTMLElement
408
421
  if (footer) {
@@ -410,7 +423,7 @@ const setFooter = () => {
410
423
  if (footerSpan && footerSpan.textContent) {
411
424
  footerSpan.textContent = footerSpan.textContent.replace(
412
425
  'Powered by AiEditor, Characters',
413
- '字数',
426
+ '字数'
414
427
  )
415
428
  }
416
429
  }
@@ -439,7 +452,7 @@ defineExpose({
439
452
  if (aiEditor) {
440
453
  aiEditor.setContent(initHtml(html), focus)
441
454
  }
442
- },
455
+ }
443
456
  })
444
457
  </script>
445
458
  <style scoped lang="scss">
@@ -448,6 +461,7 @@ defineExpose({
448
461
  border-width: v-bind(borderWidth);
449
462
  border-color: #dcdfe6;
450
463
  }
464
+
451
465
  .aie-content {
452
466
  p {
453
467
  margin: 6px 0;
@@ -75,7 +75,7 @@
75
75
  ></el-icons>
76
76
  </el-flex>
77
77
  </el-flex>
78
- <slot @submit.prevent ></slot>
78
+ <slot></slot>
79
79
  <el-flex align="flex-end" justify="flex-end" height="40px" style="border-top: var(--border)">
80
80
  <el-button @click="reset">重置</el-button>
81
81
  <el-button type="primary" @click="search">查询</el-button>