vue-editify 0.2.14 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. package/examples/App.vue +49 -67
  2. package/lib/components/button/button.vue.d.ts +62 -60
  3. package/lib/components/button/index.d.ts +4 -0
  4. package/lib/components/button/props.d.ts +12 -1
  5. package/lib/components/checkbox/checkbox.vue.d.ts +9 -9
  6. package/lib/components/checkbox/index.d.ts +4 -0
  7. package/lib/components/checkbox/props.d.ts +2 -2
  8. package/lib/components/colors/colors.vue.d.ts +4 -4
  9. package/lib/components/colors/index.d.ts +4 -0
  10. package/lib/components/colors/props.d.ts +2 -2
  11. package/lib/components/icon/index.d.ts +4 -0
  12. package/lib/components/insertAttachment/index.d.ts +4 -0
  13. package/lib/{plugins/attachment → components}/insertAttachment/insertAttachment.vue.d.ts +3 -3
  14. package/lib/{plugins/attachment → components}/insertAttachment/props.d.ts +1 -1
  15. package/lib/components/insertImage/index.d.ts +4 -0
  16. package/lib/components/insertImage/insertImage.vue.d.ts +3 -3
  17. package/lib/components/insertImage/props.d.ts +1 -1
  18. package/lib/components/insertLink/index.d.ts +4 -0
  19. package/lib/components/insertLink/insertLink.vue.d.ts +6 -6
  20. package/lib/components/insertLink/props.d.ts +3 -3
  21. package/lib/components/insertMathformula/index.d.ts +4 -0
  22. package/lib/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue.d.ts +3 -3
  23. package/lib/{plugins/mathformula → components}/insertMathformula/props.d.ts +2 -2
  24. package/lib/components/insertTable/index.d.ts +4 -0
  25. package/lib/components/insertTable/insertTable.vue.d.ts +3 -3
  26. package/lib/components/insertTable/props.d.ts +2 -2
  27. package/lib/components/insertVideo/index.d.ts +4 -0
  28. package/lib/components/insertVideo/insertVideo.vue.d.ts +3 -3
  29. package/lib/components/insertVideo/props.d.ts +1 -1
  30. package/lib/components/layer/index.d.ts +4 -0
  31. package/lib/components/layer/layer.vue.d.ts +10 -8
  32. package/lib/components/tooltip/index.d.ts +4 -0
  33. package/lib/components/tooltip/tooltip.vue.d.ts +6 -4
  34. package/lib/components/triangle/index.d.ts +4 -0
  35. package/lib/components/triangle/triangle.vue.d.ts +1 -1
  36. package/lib/components/updateLink/index.d.ts +4 -0
  37. package/lib/components/updateLink/props.d.ts +17 -0
  38. package/lib/components/updateLink/updateLink.vue.d.ts +38 -0
  39. package/lib/core/function.d.ts +113 -36
  40. package/lib/core/rule.d.ts +20 -0
  41. package/lib/core/tool.d.ts +36 -34
  42. package/lib/editify/editify.vue.d.ts +18 -27
  43. package/lib/editify/menu/index.d.ts +4 -0
  44. package/lib/{components → editify}/menu/menu.vue.d.ts +3 -4
  45. package/lib/{components → editify}/menu/props.d.ts +1 -1
  46. package/lib/editify/props.d.ts +3 -7
  47. package/lib/editify/toolbar/index.d.ts +4 -0
  48. package/lib/{components → editify}/toolbar/props.d.ts +2 -2
  49. package/lib/{components → editify}/toolbar/toolbar.vue.d.ts +53 -53
  50. package/lib/editify.es.js +8797 -7560
  51. package/lib/editify.umd.js +2 -2
  52. package/lib/feature/align.d.ts +32 -0
  53. package/lib/feature/attachment.d.ts +18 -0
  54. package/lib/feature/backColor.d.ts +32 -0
  55. package/lib/feature/bold.d.ts +32 -0
  56. package/lib/feature/code.d.ts +32 -0
  57. package/lib/feature/codeBlock.d.ts +32 -0
  58. package/lib/feature/fontFamily.d.ts +32 -0
  59. package/lib/feature/fontSize.d.ts +32 -0
  60. package/lib/feature/foreColor.d.ts +32 -0
  61. package/lib/feature/formatClear.d.ts +32 -0
  62. package/lib/feature/fullScreen.d.ts +18 -0
  63. package/lib/feature/heading.d.ts +32 -0
  64. package/lib/feature/image.d.ts +32 -0
  65. package/lib/feature/indent.d.ts +18 -0
  66. package/lib/feature/infoBlock.d.ts +18 -0
  67. package/lib/feature/italic.d.ts +32 -0
  68. package/lib/feature/lineHeight.d.ts +32 -0
  69. package/lib/feature/link.d.ts +26 -0
  70. package/lib/feature/mathformula.d.ts +22 -0
  71. package/lib/feature/orderList.d.ts +32 -0
  72. package/lib/feature/panel.d.ts +18 -0
  73. package/lib/feature/quote.d.ts +18 -0
  74. package/lib/feature/redo.d.ts +18 -0
  75. package/lib/feature/separator.d.ts +18 -0
  76. package/lib/feature/sourceView.d.ts +18 -0
  77. package/lib/feature/strikethrough.d.ts +32 -0
  78. package/lib/feature/sub.d.ts +32 -0
  79. package/lib/feature/super.d.ts +32 -0
  80. package/lib/feature/table.d.ts +32 -0
  81. package/lib/feature/task.d.ts +32 -0
  82. package/lib/feature/underline.d.ts +32 -0
  83. package/lib/feature/undo.d.ts +18 -0
  84. package/lib/feature/unorderList.d.ts +32 -0
  85. package/lib/feature/video.d.ts +38 -0
  86. package/lib/index.d.ts +36 -43
  87. package/package.json +5 -5
  88. package/src/components/button/button.vue +21 -24
  89. package/src/components/button/index.ts +5 -0
  90. package/src/components/button/props.ts +14 -1
  91. package/src/components/checkbox/checkbox.vue +1 -1
  92. package/src/components/checkbox/index.ts +5 -0
  93. package/src/components/checkbox/props.ts +1 -1
  94. package/src/components/colors/colors.vue +3 -3
  95. package/src/components/colors/index.ts +5 -0
  96. package/src/components/colors/props.ts +2 -2
  97. package/src/components/icon/index.ts +5 -0
  98. package/src/components/insertAttachment/index.ts +5 -0
  99. package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.vue +4 -2
  100. package/src/{plugins/attachment → components}/insertAttachment/props.ts +1 -1
  101. package/src/components/insertImage/index.ts +5 -0
  102. package/src/components/insertImage/insertImage.vue +5 -5
  103. package/src/components/insertImage/props.ts +1 -1
  104. package/src/components/insertLink/index.ts +5 -0
  105. package/src/components/insertLink/insertLink.vue +10 -10
  106. package/src/components/insertLink/props.ts +3 -3
  107. package/src/components/insertMathformula/index.ts +5 -0
  108. package/src/{plugins/mathformula → components}/insertMathformula/props.ts +2 -2
  109. package/src/components/insertTable/index.ts +5 -0
  110. package/src/components/insertTable/props.ts +2 -2
  111. package/src/components/insertVideo/index.ts +5 -0
  112. package/src/components/insertVideo/insertVideo.vue +2 -2
  113. package/src/components/insertVideo/props.ts +1 -1
  114. package/src/components/layer/index.ts +5 -0
  115. package/src/components/layer/layer.vue +42 -4
  116. package/src/components/tooltip/index.ts +5 -0
  117. package/src/components/tooltip/tooltip.vue +1 -1
  118. package/src/components/triangle/index.ts +5 -0
  119. package/src/components/triangle/triangle.vue +1 -1
  120. package/src/components/updateLink/index.ts +5 -0
  121. package/src/components/updateLink/props.ts +21 -0
  122. package/src/components/{toolbar/toolbar.less → updateLink/updateLink.less} +4 -20
  123. package/src/components/updateLink/updateLink.vue +74 -0
  124. package/src/core/function.ts +289 -97
  125. package/src/core/rule.ts +96 -7
  126. package/src/core/tool.ts +234 -78
  127. package/src/editify/editify.less +2 -0
  128. package/src/editify/editify.vue +182 -185
  129. package/src/editify/menu/index.ts +5 -0
  130. package/src/editify/menu/menu.vue +215 -0
  131. package/src/{components → editify}/menu/props.ts +1 -1
  132. package/src/editify/props.ts +7 -11
  133. package/src/editify/toolbar/index.ts +5 -0
  134. package/src/{components → editify}/toolbar/props.ts +1 -1
  135. package/src/editify/toolbar/toolbar.less +10 -0
  136. package/src/editify/toolbar/toolbar.vue +103 -0
  137. package/src/feature/align.ts +128 -0
  138. package/src/feature/attachment.ts +109 -0
  139. package/src/feature/backColor.ts +171 -0
  140. package/src/feature/bold.ts +136 -0
  141. package/src/feature/code.ts +136 -0
  142. package/src/feature/codeBlock.ts +204 -0
  143. package/src/feature/fontFamily.ts +140 -0
  144. package/src/feature/fontSize.ts +142 -0
  145. package/src/feature/foreColor.ts +173 -0
  146. package/src/feature/formatClear.ts +118 -0
  147. package/src/feature/fullScreen.ts +57 -0
  148. package/src/feature/heading.ts +154 -0
  149. package/src/feature/image.ts +225 -0
  150. package/src/feature/indent.ts +73 -0
  151. package/src/feature/infoBlock.ts +94 -0
  152. package/src/feature/italic.ts +136 -0
  153. package/src/feature/lineHeight.ts +165 -0
  154. package/src/feature/link.ts +149 -0
  155. package/src/feature/mathformula.ts +147 -0
  156. package/src/feature/orderList.ts +116 -0
  157. package/src/feature/panel.ts +108 -0
  158. package/src/feature/quote.ts +61 -0
  159. package/src/feature/redo.ts +56 -0
  160. package/src/feature/separator.ts +62 -0
  161. package/src/feature/sourceView.ts +59 -0
  162. package/src/feature/strikethrough.ts +136 -0
  163. package/src/feature/sub.ts +136 -0
  164. package/src/feature/super.ts +136 -0
  165. package/src/feature/table.ts +994 -0
  166. package/src/feature/task.ts +116 -0
  167. package/src/feature/underline.ts +136 -0
  168. package/src/feature/undo.ts +56 -0
  169. package/src/feature/unorderList.ts +116 -0
  170. package/src/feature/video.ts +339 -0
  171. package/src/hljs/index.ts +1 -1
  172. package/src/index.ts +69 -21
  173. package/src/locale/en_US.ts +3 -3
  174. package/src/locale/zh_CN.ts +3 -3
  175. package/lib/plugins/attachment/index.d.ts +0 -37
  176. package/lib/plugins/infoBlock/index.d.ts +0 -55
  177. package/lib/plugins/mathformula/index.d.ts +0 -49
  178. package/lib/plugins/panel/index.d.ts +0 -48
  179. package/src/components/menu/menu.vue +0 -1655
  180. package/src/components/toolbar/toolbar.vue +0 -1677
  181. package/src/plugins/attachment/index.ts +0 -237
  182. package/src/plugins/infoBlock/index.ts +0 -238
  183. package/src/plugins/mathformula/index.ts +0 -295
  184. package/src/plugins/panel/index.ts +0 -228
  185. package/tsconfig.json +0 -31
  186. package/tsconfig.node.json +0 -11
  187. /package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.less +0 -0
  188. /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.less +0 -0
  189. /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue +0 -0
  190. /package/src/{components → editify}/menu/menu.less +0 -0
@@ -0,0 +1,154 @@
1
+ import { computed, defineComponent, h, inject, PropType, Ref, ref } from 'vue'
2
+ import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
3
+ import { common as DapCommon } from 'dap-util'
4
+ import { MenuDisplayButtonType } from '@/core/tool'
5
+ import { hasPanelInRange, hasPreInRange, hasTableInRange, setHeading } from '@/core/function'
6
+ import { Button, ButtonOptionsItemType } from '@/components/button'
7
+
8
+ /**
9
+ * feature名称
10
+ */
11
+ const FEATURE_NAME = 'heading'
12
+
13
+ /**
14
+ * 工具栏 - 标题
15
+ */
16
+ export const HeadingToolbarButton = defineComponent(
17
+ (props, { expose }) => {
18
+ const editor = inject<Ref<AlexEditor>>('editor')!
19
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
20
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
21
+
22
+ const btnRef = ref<InstanceType<typeof Button> | null>(null)
23
+
24
+ const selectVal = computed<string>(() => {
25
+ //显示已设置标题
26
+ const findHeadingItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
27
+ let val: string | number | ButtonOptionsItemType = item
28
+ if (DapCommon.isObject(item)) {
29
+ val = (item as ButtonOptionsItemType).value!
30
+ }
31
+ return dataRangeCaches.value.list.every(el => {
32
+ if (el.element.isBlock()) {
33
+ return el.element.parsedom == val
34
+ }
35
+ return el.element.getBlock().parsedom == val
36
+ })
37
+ })
38
+ return findHeadingItem ? (DapCommon.isObject(findHeadingItem) ? ((findHeadingItem as ButtonOptionsItemType).value as string) : (findHeadingItem as string)) : (props.config.defaultValue as string)
39
+ })
40
+
41
+ expose({
42
+ btnRef
43
+ })
44
+ return () => {
45
+ return props.config.show
46
+ ? h(Button, {
47
+ ref: btnRef,
48
+ name: FEATURE_NAME,
49
+ type: 'display',
50
+ title: $editTrans('heading'),
51
+ tooltip: props.tooltip,
52
+ color: props.color,
53
+ zIndex: props.zIndex,
54
+ leftBorder: props.config.leftBorder,
55
+ rightBorder: props.config.rightBorder,
56
+ active: false,
57
+ disabled: props.config.disabled,
58
+ displayConfig: {
59
+ options: props.config.options,
60
+ value: selectVal.value,
61
+ width: props.config.width,
62
+ maxHeight: props.config.maxHeight
63
+ },
64
+ onOperate: (_name: string, val: string) => {
65
+ setHeading(editor.value, dataRangeCaches.value, $editTrans, val)
66
+ editor.value.formatElementStack()
67
+ editor.value.domRender()
68
+ editor.value.rangeRender()
69
+ }
70
+ })
71
+ : null
72
+ }
73
+ },
74
+ {
75
+ name: `_${FEATURE_NAME}`,
76
+ props: {
77
+ color: String,
78
+ zIndex: Number,
79
+ config: Object as PropType<MenuDisplayButtonType>,
80
+ tooltip: Boolean
81
+ }
82
+ }
83
+ )
84
+
85
+ /**
86
+ * 菜单栏 - 标题
87
+ */
88
+ export const HeadingMenuButton = defineComponent(
89
+ props => {
90
+ const editor = inject<Ref<AlexEditor>>('editor')!
91
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
92
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
93
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
94
+ const rangeKey = inject<Ref<number | null>>('rangeKey')!
95
+
96
+ const selectVal = computed<string>(() => {
97
+ const findHeadingItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
98
+ let val: string | number | ButtonOptionsItemType = item
99
+ if (DapCommon.isObject(item)) {
100
+ val = (item as ButtonOptionsItemType).value!
101
+ }
102
+ if (rangeKey.value && editor.value.range && editor.value.range.anchor.isEqual(editor.value.range!.focus)) {
103
+ return editor.value.range.anchor.element.getBlock().parsedom == val
104
+ }
105
+ return dataRangeCaches.value.list.every(el => {
106
+ if (el.element.isBlock()) {
107
+ return el.element.parsedom == val
108
+ }
109
+ return el.element.getBlock().parsedom == val
110
+ })
111
+ })
112
+ return findHeadingItem ? (DapCommon.isObject(findHeadingItem) ? ((findHeadingItem as ButtonOptionsItemType).value as string) : (findHeadingItem as string)) : (props.config.defaultValue as string)
113
+ })
114
+
115
+ return () => {
116
+ return props.config.show
117
+ ? h(Button, {
118
+ name: FEATURE_NAME,
119
+ tooltip: props.tooltip,
120
+ color: props.color,
121
+ zIndex: props.zIndex,
122
+ type: 'display',
123
+ displayConfig: {
124
+ options: props.config.options,
125
+ value: selectVal.value,
126
+ width: props.config.width,
127
+ maxHeight: props.config.maxHeight
128
+ },
129
+ title: $editTrans('heading'),
130
+ leftBorder: props.config.leftBorder,
131
+ rightBorder: props.config.rightBorder,
132
+ active: false,
133
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || hasPanelInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
134
+ onOperate: (_name: string, val: string) => {
135
+ setHeading(editor.value, dataRangeCaches.value, $editTrans, val)
136
+ editor.value.formatElementStack()
137
+ editor.value.domRender()
138
+ editor.value.rangeRender()
139
+ }
140
+ })
141
+ : null
142
+ }
143
+ },
144
+ {
145
+ name: `_${FEATURE_NAME}`,
146
+ props: {
147
+ color: String,
148
+ zIndex: Number,
149
+ config: Object as PropType<MenuDisplayButtonType>,
150
+ tooltip: Boolean,
151
+ disabled: Boolean
152
+ }
153
+ }
154
+ )
@@ -0,0 +1,225 @@
1
+ import { defineComponent, h, inject, PropType, ref, Ref } from 'vue'
2
+ import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
3
+ import { Button } from '@/components/button'
4
+ import { Icon } from '@/components/icon'
5
+ import { getMatchElementByRange, hasMathformulaInRange, hasPreInRange, insertImage } from '@/core/function'
6
+ import { InsertImage } from '@/components/insertImage'
7
+ import { MenuImageButtonType } from '@/core/tool'
8
+
9
+ /**
10
+ * feature名称
11
+ */
12
+ const FEATURE_NAME = 'image'
13
+
14
+ /**
15
+ * 工具栏 - 图片操作
16
+ */
17
+ export const ImageToolbar = defineComponent(
18
+ (props, { emit }) => {
19
+ const editor = inject<Ref<AlexEditor>>('editor')!
20
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
21
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
22
+
23
+ //设置图片宽度
24
+ const setWidth = (value: string) => {
25
+ const element = editor.value.range!.anchor.element
26
+ if (element) {
27
+ const styles = {
28
+ width: value
29
+ }
30
+ if (element.hasStyles()) {
31
+ element.styles = Object.assign(element.styles!, styles)
32
+ } else {
33
+ element.styles = styles
34
+ }
35
+ editor.value.formatElementStack()
36
+ editor.value.domRender()
37
+ editor.value.rangeRender()
38
+ //更新工具条位置
39
+ setTimeout(() => {
40
+ emit('reset-toolbar')
41
+ }, 0)
42
+ }
43
+ }
44
+
45
+ return () => {
46
+ return [
47
+ //30%
48
+ h(
49
+ Button,
50
+ {
51
+ name: 'set30Width',
52
+ title: $editTrans('width30'),
53
+ tooltip: props.tooltip,
54
+ color: props.color,
55
+ zIndex: props.zIndex,
56
+ onOperate: () => setWidth('30%')
57
+ },
58
+ {
59
+ default: () => ' 30% '
60
+ }
61
+ ),
62
+ //50%
63
+ h(
64
+ Button,
65
+ {
66
+ name: 'set50Width',
67
+ title: $editTrans('width50'),
68
+ tooltip: props.tooltip,
69
+ color: props.color,
70
+ zIndex: props.zIndex,
71
+ onOperate: () => setWidth('50%')
72
+ },
73
+ {
74
+ default: () => ' 50% '
75
+ }
76
+ ),
77
+ //100%
78
+ h(
79
+ Button,
80
+ {
81
+ name: 'set100Width',
82
+ title: $editTrans('width100'),
83
+ tooltip: props.tooltip,
84
+ color: props.color,
85
+ zIndex: props.zIndex,
86
+ onOperate: () => setWidth('100%')
87
+ },
88
+ {
89
+ default: () => ' 100% '
90
+ }
91
+ ),
92
+ //宽度自适应
93
+ h(
94
+ Button,
95
+ {
96
+ name: 'setAutoWidth',
97
+ title: $editTrans('auto'),
98
+ tooltip: props.tooltip,
99
+ color: props.color,
100
+ zIndex: props.zIndex,
101
+ onOperate: () => setWidth('auto')
102
+ },
103
+ {
104
+ default: () => h(Icon, { value: 'auto-width' })
105
+ }
106
+ ),
107
+ //删除图片
108
+ h(
109
+ Button,
110
+ {
111
+ name: 'deleteImage',
112
+ title: $editTrans('deleteImage'),
113
+ tooltip: props.tooltip,
114
+ color: props.color,
115
+ zIndex: props.zIndex,
116
+ onOperate: () => {
117
+ const element = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'img' })
118
+ if (element) {
119
+ element.toEmpty()
120
+ editor.value.formatElementStack()
121
+ editor.value.domRender()
122
+ editor.value.rangeRender()
123
+ }
124
+ }
125
+ },
126
+ {
127
+ default: () => h(Icon, { value: 'delete' })
128
+ }
129
+ )
130
+ ]
131
+ }
132
+ },
133
+ {
134
+ name: `_${FEATURE_NAME}`,
135
+ props: {
136
+ color: String,
137
+ zIndex: Number,
138
+ tooltip: Boolean
139
+ },
140
+ emits: ['reset-toolbar']
141
+ }
142
+ )
143
+
144
+ /**
145
+ * 菜单栏 - 插入图片
146
+ */
147
+ export const ImageMenuButton = defineComponent(
148
+ props => {
149
+ const editor = inject<Ref<AlexEditor>>('editor')!
150
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
151
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
152
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
153
+
154
+ const btnRef = ref<InstanceType<typeof Button> | null>(null)
155
+
156
+ return () => {
157
+ return props.config.show
158
+ ? h(
159
+ Button,
160
+ {
161
+ ref: btnRef,
162
+ name: FEATURE_NAME,
163
+ tooltip: props.tooltip,
164
+ color: props.color,
165
+ zIndex: props.zIndex,
166
+ type: 'select',
167
+ hideScroll: true,
168
+ title: $editTrans('insertImage'),
169
+ leftBorder: props.config.leftBorder,
170
+ rightBorder: props.config.rightBorder,
171
+ active: false,
172
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasMathformulaInRange(editor.value, dataRangeCaches.value) || props.config.disabled
173
+ },
174
+ {
175
+ default: () =>
176
+ h(Icon, {
177
+ value: 'image'
178
+ }),
179
+ layer: () =>
180
+ h(InsertImage, {
181
+ color: props.color,
182
+ allowedFileType: props.config.allowedFileType,
183
+ multiple: props.config.multiple,
184
+ maxSize: props.config.maxSize,
185
+ minSize: props.config.minSize,
186
+ customUpload: props.config.customUpload,
187
+ handleError: props.config.handleError,
188
+ onChange: () => {
189
+ btnRef.value!.layerRef!.setPosition()
190
+ },
191
+ onInsert: (val: string[]) => {
192
+ //过滤掉空的地址
193
+ const urls = val.filter(url => {
194
+ return !!url
195
+ })
196
+ //如果数组为0
197
+ if (urls.length == 0) {
198
+ return
199
+ }
200
+ //遍历每个地址进行插入
201
+ urls.forEach(url => {
202
+ insertImage(editor.value, url)
203
+ })
204
+ editor.value.formatElementStack()
205
+ editor.value.domRender()
206
+ editor.value.rangeRender()
207
+ btnRef.value!.show = false
208
+ }
209
+ })
210
+ }
211
+ )
212
+ : null
213
+ }
214
+ },
215
+ {
216
+ name: `_${FEATURE_NAME}`,
217
+ props: {
218
+ color: String,
219
+ zIndex: Number,
220
+ config: Object as PropType<MenuImageButtonType>,
221
+ tooltip: Boolean,
222
+ disabled: Boolean
223
+ }
224
+ }
225
+ )
@@ -0,0 +1,73 @@
1
+ import { defineComponent, h, inject, PropType, Ref } from 'vue'
2
+ import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
3
+ import { Button } from '@/components/button'
4
+ import { MenuSelectButtonType } from '@/core/tool'
5
+ import { Icon } from '@/components/icon'
6
+ import { hasPreInRange, hasTableInRange, setIndentDecrease, setIndentIncrease } from '@/core/function'
7
+
8
+ /**
9
+ * feature名称
10
+ */
11
+ const FEATURE_NAME = 'indent'
12
+
13
+ /**
14
+ * 菜单栏 - 缩进
15
+ */
16
+ export const IndentMenuButton = defineComponent(
17
+ props => {
18
+ const editor = inject<Ref<AlexEditor>>('editor')!
19
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
20
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
21
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
22
+
23
+ return () => {
24
+ return props.config.show
25
+ ? h(
26
+ Button,
27
+ {
28
+ name: FEATURE_NAME,
29
+ tooltip: props.tooltip,
30
+ color: props.color,
31
+ zIndex: props.zIndex,
32
+ type: 'select',
33
+ title: $editTrans('indent'),
34
+ selectConfig: {
35
+ options: props.config.options,
36
+ width: props.config.width,
37
+ maxHeight: props.config.maxHeight
38
+ },
39
+ leftBorder: props.config.leftBorder,
40
+ rightBorder: props.config.rightBorder,
41
+ active: false,
42
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
43
+ onOperate: (_name, val: string) => {
44
+ if (val == 'indent-increase') {
45
+ setIndentIncrease(editor.value, dataRangeCaches.value)
46
+ }
47
+ //减少缩进
48
+ else if (val == 'indent-decrease') {
49
+ setIndentDecrease(editor.value, dataRangeCaches.value)
50
+ }
51
+ editor.value.formatElementStack()
52
+ editor.value.domRender()
53
+ editor.value.rangeRender()
54
+ }
55
+ },
56
+ {
57
+ default: () => h(Icon, { value: 'indent-increase' })
58
+ }
59
+ )
60
+ : null
61
+ }
62
+ },
63
+ {
64
+ name: `_${FEATURE_NAME}`,
65
+ props: {
66
+ color: String,
67
+ zIndex: Number,
68
+ config: Object as PropType<MenuSelectButtonType>,
69
+ tooltip: Boolean,
70
+ disabled: Boolean
71
+ }
72
+ }
73
+ )
@@ -0,0 +1,94 @@
1
+ import { defineComponent, h, inject, PropType, Ref } from 'vue'
2
+ import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
3
+ import { Button } from '@/components/button'
4
+ import { MenuButtonType } from '@/core/tool'
5
+ import { Icon } from '@/components/icon'
6
+ import { elementToParagraph, hasPanelInRange, hasPreInRange, hasTableInRange, rangeIsInInfoBlock } from '@/core/function'
7
+
8
+ /**
9
+ * feature名称
10
+ */
11
+ const FEATURE_NAME = 'infoBlock'
12
+
13
+ /**
14
+ * 菜单栏 - 信息块
15
+ */
16
+ export const InfoBlockMenuButton = defineComponent(
17
+ props => {
18
+ const editor = inject<Ref<AlexEditor>>('editor')!
19
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
20
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
21
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
22
+
23
+ return () => {
24
+ return props.config.show
25
+ ? h(
26
+ Button,
27
+ {
28
+ name: FEATURE_NAME,
29
+ tooltip: props.tooltip,
30
+ color: props.color,
31
+ zIndex: props.zIndex,
32
+ title: $editTrans('insertInfoBlock'),
33
+ leftBorder: props.config.leftBorder,
34
+ rightBorder: props.config.rightBorder,
35
+ active: rangeIsInInfoBlock(editor.value, dataRangeCaches.value),
36
+ disabled: props.disabled || isSourceView.value || hasPanelInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
37
+ onOperate: () => {
38
+ //是否都在信息块里
39
+ const flag = rangeIsInInfoBlock(editor.value, dataRangeCaches.value)
40
+ //起点和终点在一起
41
+ if (editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
42
+ const block = editor.value.range!.anchor.element.getBlock()
43
+ elementToParagraph(block)
44
+ if (!flag) {
45
+ block.parsedom = 'div'
46
+ block.marks = {
47
+ 'data-editify-info': 'true'
48
+ }
49
+ }
50
+ }
51
+ //起点和终点不在一起
52
+ else {
53
+ let blocks: AlexElement[] = []
54
+ dataRangeCaches.value.list.forEach(item => {
55
+ const block = item.element.getBlock()
56
+ const exist = blocks.some(el => block.isEqual(el))
57
+ if (!exist) {
58
+ blocks.push(block)
59
+ }
60
+ })
61
+ blocks.forEach(block => {
62
+ elementToParagraph(block)
63
+ if (!flag) {
64
+ block.parsedom = 'div'
65
+ block.marks = {
66
+ 'data-editify-info': 'true'
67
+ }
68
+ }
69
+ })
70
+ }
71
+ //渲染
72
+ editor.value.formatElementStack()
73
+ editor.value.domRender()
74
+ editor.value.rangeRender()
75
+ }
76
+ },
77
+ {
78
+ default: () => h(Icon, { value: 'info' })
79
+ }
80
+ )
81
+ : null
82
+ }
83
+ },
84
+ {
85
+ name: `_${FEATURE_NAME}`,
86
+ props: {
87
+ color: String,
88
+ zIndex: Number,
89
+ config: Object as PropType<MenuButtonType>,
90
+ tooltip: Boolean,
91
+ disabled: Boolean
92
+ }
93
+ }
94
+ )
@@ -0,0 +1,136 @@
1
+ import { computed, defineComponent, h, inject, PropType, Ref, ref } from 'vue'
2
+ import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
3
+ import { MenuButtonType } from '@/core/tool'
4
+ import { hasPreInRange, queryTextStyle, removeTextStyle, setTextStyle } from '@/core/function'
5
+ import { Button } from '@/components/button'
6
+ import { Icon } from '@/components/icon'
7
+
8
+ /**
9
+ * feature名称
10
+ */
11
+ const FEATURE_NAME = 'italic'
12
+
13
+ /**
14
+ * 工具栏 - 斜体
15
+ */
16
+ export const ItalicToolbarButton = defineComponent(
17
+ (props, { expose }) => {
18
+ const editor = inject<Ref<AlexEditor>>('editor')!
19
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
20
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
21
+
22
+ const btnRef = ref<InstanceType<typeof Button> | null>(null)
23
+
24
+ const active = computed<boolean>(() => {
25
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'font-style', 'italic')
26
+ })
27
+
28
+ expose({
29
+ btnRef
30
+ })
31
+
32
+ return () => {
33
+ return props.config.show
34
+ ? h(
35
+ Button,
36
+ {
37
+ ref: btnRef,
38
+ name: FEATURE_NAME,
39
+ title: $editTrans('italic'),
40
+ tooltip: props.tooltip,
41
+ color: props.color,
42
+ zIndex: props.zIndex,
43
+ leftBorder: props.config.leftBorder,
44
+ rightBorder: props.config.rightBorder,
45
+ active: active.value,
46
+ disabled: props.config.disabled,
47
+ onOperate: () => {
48
+ if (active.value) {
49
+ removeTextStyle(editor.value, dataRangeCaches.value, ['font-style'])
50
+ } else {
51
+ setTextStyle(editor.value, dataRangeCaches.value, {
52
+ 'font-style': 'italic'
53
+ })
54
+ }
55
+ editor.value.formatElementStack()
56
+ editor.value.domRender()
57
+ editor.value.rangeRender()
58
+ }
59
+ },
60
+ {
61
+ default: () => h(Icon, { value: 'italic' })
62
+ }
63
+ )
64
+ : null
65
+ }
66
+ },
67
+ {
68
+ name: `_${FEATURE_NAME}`,
69
+ props: {
70
+ color: String,
71
+ zIndex: Number,
72
+ config: Object as PropType<MenuButtonType>,
73
+ tooltip: Boolean
74
+ }
75
+ }
76
+ )
77
+
78
+ /**
79
+ * 菜单栏 - 斜体
80
+ */
81
+ export const ItalicMenuButton = defineComponent(
82
+ props => {
83
+ const editor = inject<Ref<AlexEditor>>('editor')!
84
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
85
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
86
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
87
+
88
+ const active = computed<boolean>(() => {
89
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'font-style', 'italic')
90
+ })
91
+
92
+ return () => {
93
+ return props.config.show
94
+ ? h(
95
+ Button,
96
+ {
97
+ name: FEATURE_NAME,
98
+ tooltip: props.tooltip,
99
+ color: props.color,
100
+ zIndex: props.zIndex,
101
+ title: $editTrans('italic'),
102
+ leftBorder: props.config.leftBorder,
103
+ rightBorder: props.config.rightBorder,
104
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
105
+ active: active.value,
106
+ onOperate: () => {
107
+ if (active.value) {
108
+ removeTextStyle(editor.value, dataRangeCaches.value, ['font-style'])
109
+ } else {
110
+ setTextStyle(editor.value, dataRangeCaches.value, {
111
+ 'font-style': 'italic'
112
+ })
113
+ }
114
+ editor.value.formatElementStack()
115
+ editor.value.domRender()
116
+ editor.value.rangeRender()
117
+ }
118
+ },
119
+ {
120
+ default: () => h(Icon, { value: 'italic' })
121
+ }
122
+ )
123
+ : null
124
+ }
125
+ },
126
+ {
127
+ name: `_${FEATURE_NAME}`,
128
+ props: {
129
+ color: String,
130
+ zIndex: Number,
131
+ config: Object as PropType<MenuButtonType>,
132
+ tooltip: Boolean,
133
+ disabled: Boolean
134
+ }
135
+ }
136
+ )