vue-editify 0.2.14 → 0.2.16

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 +41 -88
  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 -28
  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 +38964 -37727
  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 +194 -202
  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 +108 -29
  126. package/src/core/tool.ts +237 -81
  127. package/src/editify/editify.less +4 -0
  128. package/src/editify/editify.vue +183 -194
  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 +126 -0
  138. package/src/feature/attachment.ts +108 -0
  139. package/src/feature/backColor.ts +169 -0
  140. package/src/feature/bold.ts +134 -0
  141. package/src/feature/code.ts +134 -0
  142. package/src/feature/codeBlock.ts +201 -0
  143. package/src/feature/fontFamily.ts +138 -0
  144. package/src/feature/fontSize.ts +140 -0
  145. package/src/feature/foreColor.ts +171 -0
  146. package/src/feature/formatClear.ts +116 -0
  147. package/src/feature/fullScreen.ts +57 -0
  148. package/src/feature/heading.ts +152 -0
  149. package/src/feature/image.ts +222 -0
  150. package/src/feature/indent.ts +72 -0
  151. package/src/feature/infoBlock.ts +93 -0
  152. package/src/feature/italic.ts +134 -0
  153. package/src/feature/lineHeight.ts +163 -0
  154. package/src/feature/link.ts +146 -0
  155. package/src/feature/mathformula.ts +146 -0
  156. package/src/feature/orderList.ts +114 -0
  157. package/src/feature/panel.ts +107 -0
  158. package/src/feature/quote.ts +60 -0
  159. package/src/feature/redo.ts +56 -0
  160. package/src/feature/separator.ts +61 -0
  161. package/src/feature/sourceView.ts +59 -0
  162. package/src/feature/strikethrough.ts +134 -0
  163. package/src/feature/sub.ts +134 -0
  164. package/src/feature/super.ts +134 -0
  165. package/src/feature/table.ts +981 -0
  166. package/src/feature/task.ts +114 -0
  167. package/src/feature/underline.ts +134 -0
  168. package/src/feature/undo.ts +56 -0
  169. package/src/feature/unorderList.ts +114 -0
  170. package/src/feature/video.ts +335 -0
  171. package/src/hljs/index.ts +1 -1
  172. package/src/index.ts +82 -25
  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,169 @@
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 { MenuSelectButtonType } from '@/core/tool'
5
+ import { hasPreInRange, queryTextStyle, setTextStyle } from '@/core/function'
6
+ import { Button, ButtonOptionsItemType } from '@/components/button'
7
+ import { Icon } from '@/components/icon'
8
+ import { Colors } from '@/components/colors'
9
+
10
+ /**
11
+ * feature名称
12
+ */
13
+ const FEATURE_NAME = 'backColor'
14
+
15
+ /**
16
+ * 工具栏 - 背景色
17
+ */
18
+ export const BackColorToolbarButton = defineComponent(
19
+ (props, { expose }) => {
20
+ const editor = inject<Ref<AlexEditor>>('editor')!
21
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
22
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
23
+
24
+ const btnRef = ref<InstanceType<typeof Button> | null>(null)
25
+
26
+ const selectVal = computed<string>(() => {
27
+ const findBackColorItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
28
+ if (DapCommon.isObject(item)) {
29
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'background', (item as ButtonOptionsItemType).value)
30
+ }
31
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'background', item as string)
32
+ })
33
+ return findBackColorItem ? (DapCommon.isObject(findBackColorItem) ? ((findBackColorItem as ButtonOptionsItemType).value as string) : (findBackColorItem as string)) : ''
34
+ })
35
+ expose({
36
+ btnRef
37
+ })
38
+ return () => {
39
+ return props.config.show
40
+ ? h(
41
+ Button,
42
+ {
43
+ ref: btnRef,
44
+ name: FEATURE_NAME,
45
+ type: 'select',
46
+ title: $editTrans('backColor'),
47
+ tooltip: props.tooltip,
48
+ color: props.color,
49
+ zIndex: props.zIndex,
50
+ leftBorder: props.config.leftBorder,
51
+ rightBorder: props.config.rightBorder,
52
+ active: false,
53
+ disabled: props.config.disabled,
54
+ selectConfig: {
55
+ options: props.config.options
56
+ },
57
+ hideScroll: true
58
+ },
59
+ {
60
+ default: () => h(Icon, { value: 'brush' }),
61
+ layer: ({ options }: { options: ButtonOptionsItemType[] }) => {
62
+ return h(Colors, {
63
+ tooltip: props.tooltip,
64
+ color: props.color,
65
+ value: selectVal.value,
66
+ data: options,
67
+ onChange: (val: string) => {
68
+ setTextStyle(editor.value, dataRangeCaches.value, {
69
+ background: val
70
+ })
71
+ btnRef.value!.show = false
72
+ editor.value.domRender()
73
+ editor.value.rangeRender()
74
+ }
75
+ })
76
+ }
77
+ }
78
+ )
79
+ : null
80
+ }
81
+ },
82
+ {
83
+ name: `_${FEATURE_NAME}`,
84
+ props: {
85
+ color: String,
86
+ zIndex: Number,
87
+ config: Object as PropType<MenuSelectButtonType>,
88
+ tooltip: Boolean
89
+ }
90
+ }
91
+ )
92
+
93
+ /**
94
+ * 菜单栏 - 背景色
95
+ */
96
+ export const BackColorMenuButton = defineComponent(
97
+ props => {
98
+ const editor = inject<Ref<AlexEditor>>('editor')!
99
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
100
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
101
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
102
+
103
+ const btnRef = ref<InstanceType<typeof Button> | null>(null)
104
+
105
+ const selectVal = computed<string>(() => {
106
+ const findBackColorItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
107
+ if (DapCommon.isObject(item)) {
108
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'background', (item as ButtonOptionsItemType).value)
109
+ }
110
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'background', item as string)
111
+ })
112
+ return findBackColorItem ? (DapCommon.isObject(findBackColorItem) ? ((findBackColorItem as ButtonOptionsItemType).value as string) : (findBackColorItem as string)) : ''
113
+ })
114
+
115
+ return () => {
116
+ return props.config.show
117
+ ? h(
118
+ Button,
119
+ {
120
+ ref: btnRef,
121
+ name: FEATURE_NAME,
122
+ tooltip: props.tooltip,
123
+ color: props.color,
124
+ zIndex: props.zIndex,
125
+ type: 'select',
126
+ selectConfig: {
127
+ options: props.config.options
128
+ },
129
+ hideScroll: true,
130
+ title: $editTrans('backColor'),
131
+ leftBorder: props.config.leftBorder,
132
+ rightBorder: props.config.rightBorder,
133
+ active: false,
134
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled
135
+ },
136
+ {
137
+ default: () => h(Icon, { value: 'brush' }),
138
+ layer: ({ options }: { options: ButtonOptionsItemType[] }) => {
139
+ return h(Colors, {
140
+ tooltip: props.tooltip,
141
+ color: props.color,
142
+ value: selectVal.value,
143
+ data: options,
144
+ onChange: (val: string) => {
145
+ setTextStyle(editor.value, dataRangeCaches.value, {
146
+ background: val
147
+ })
148
+ editor.value.domRender()
149
+ editor.value.rangeRender()
150
+ btnRef.value!.show = false
151
+ }
152
+ })
153
+ }
154
+ }
155
+ )
156
+ : null
157
+ }
158
+ },
159
+ {
160
+ name: `_${FEATURE_NAME}`,
161
+ props: {
162
+ color: String,
163
+ zIndex: Number,
164
+ config: Object as PropType<MenuSelectButtonType>,
165
+ tooltip: Boolean,
166
+ disabled: Boolean
167
+ }
168
+ }
169
+ )
@@ -0,0 +1,134 @@
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 = 'bold'
12
+
13
+ /**
14
+ * 工具栏 - 加粗
15
+ */
16
+ export const BoldToolbarButton = 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-weight', 'bold') || queryTextStyle(editor.value, dataRangeCaches.value, 'font-weight', '700')
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('bold'),
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-weight'])
50
+ } else {
51
+ setTextStyle(editor.value, dataRangeCaches.value, {
52
+ 'font-weight': 'bold'
53
+ })
54
+ }
55
+ editor.value.domRender()
56
+ editor.value.rangeRender()
57
+ }
58
+ },
59
+ {
60
+ default: () => h(Icon, { value: 'bold' })
61
+ }
62
+ )
63
+ : null
64
+ }
65
+ },
66
+ {
67
+ name: `_${FEATURE_NAME}`,
68
+ props: {
69
+ color: String,
70
+ zIndex: Number,
71
+ config: Object as PropType<MenuButtonType>,
72
+ tooltip: Boolean
73
+ }
74
+ }
75
+ )
76
+
77
+ /**
78
+ * 菜单栏 - 加粗
79
+ */
80
+ export const BoldMenuButton = defineComponent(
81
+ props => {
82
+ const editor = inject<Ref<AlexEditor>>('editor')!
83
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
84
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
85
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
86
+
87
+ const active = computed<boolean>(() => {
88
+ return queryTextStyle(editor.value, dataRangeCaches.value, 'font-weight', 'bold') || queryTextStyle(editor.value, dataRangeCaches.value, 'font-weight', '700')
89
+ })
90
+
91
+ return () => {
92
+ return props.config.show
93
+ ? h(
94
+ Button,
95
+ {
96
+ name: FEATURE_NAME,
97
+ tooltip: props.tooltip,
98
+ color: props.color,
99
+ zIndex: props.zIndex,
100
+ title: $editTrans('bold'),
101
+ leftBorder: props.config.leftBorder,
102
+ rightBorder: props.config.rightBorder,
103
+ active: active.value,
104
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
105
+ onOperate: () => {
106
+ if (active.value) {
107
+ removeTextStyle(editor.value, dataRangeCaches.value, ['font-weight'])
108
+ } else {
109
+ setTextStyle(editor.value, dataRangeCaches.value, {
110
+ 'font-weight': 'bold'
111
+ })
112
+ }
113
+ editor.value.domRender()
114
+ editor.value.rangeRender()
115
+ }
116
+ },
117
+ {
118
+ default: () => h(Icon, { value: 'bold' })
119
+ }
120
+ )
121
+ : null
122
+ }
123
+ },
124
+ {
125
+ name: `_${FEATURE_NAME}`,
126
+ props: {
127
+ color: String,
128
+ zIndex: Number,
129
+ config: Object as PropType<MenuButtonType>,
130
+ tooltip: Boolean,
131
+ disabled: Boolean
132
+ }
133
+ }
134
+ )
@@ -0,0 +1,134 @@
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, queryTextMark, removeTextMark, setTextMark } from '@/core/function'
5
+ import { Button } from '@/components/button'
6
+ import { Icon } from '@/components/icon'
7
+
8
+ /**
9
+ * feature名称
10
+ */
11
+ const FEATURE_NAME = 'code'
12
+
13
+ /**
14
+ * 工具栏 - 行内代码
15
+ */
16
+ export const CodeToolbarButton = 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 queryTextMark(editor.value, dataRangeCaches.value, 'data-editify-code')
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('code'),
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
+ removeTextMark(editor.value, dataRangeCaches.value, ['data-editify-code'])
50
+ } else {
51
+ setTextMark(editor.value, dataRangeCaches.value, {
52
+ 'data-editify-code': true
53
+ })
54
+ }
55
+ editor.value.domRender()
56
+ editor.value.rangeRender()
57
+ }
58
+ },
59
+ {
60
+ default: () => h(Icon, { value: 'code' })
61
+ }
62
+ )
63
+ : null
64
+ }
65
+ },
66
+ {
67
+ name: `_${FEATURE_NAME}`,
68
+ props: {
69
+ color: String,
70
+ zIndex: Number,
71
+ config: Object as PropType<MenuButtonType>,
72
+ tooltip: Boolean
73
+ }
74
+ }
75
+ )
76
+
77
+ /**
78
+ * 菜单栏 - 行内代码
79
+ */
80
+ export const CodeMenuButton = defineComponent(
81
+ props => {
82
+ const editor = inject<Ref<AlexEditor>>('editor')!
83
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
84
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
85
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
86
+
87
+ const active = computed<boolean>(() => {
88
+ return queryTextMark(editor.value, dataRangeCaches.value, 'data-editify-code')
89
+ })
90
+
91
+ return () => {
92
+ return props.config.show
93
+ ? h(
94
+ Button,
95
+ {
96
+ name: FEATURE_NAME,
97
+ tooltip: props.tooltip,
98
+ color: props.color,
99
+ zIndex: props.zIndex,
100
+ title: $editTrans('code'),
101
+ leftBorder: props.config.leftBorder,
102
+ rightBorder: props.config.rightBorder,
103
+ active: active.value,
104
+ disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
105
+ onOperate: () => {
106
+ if (active.value) {
107
+ removeTextMark(editor.value, dataRangeCaches.value, ['data-editify-code'])
108
+ } else {
109
+ setTextMark(editor.value, dataRangeCaches.value, {
110
+ 'data-editify-code': true
111
+ })
112
+ }
113
+ editor.value.domRender()
114
+ editor.value.rangeRender()
115
+ }
116
+ },
117
+ {
118
+ default: () => h(Icon, { value: 'code' })
119
+ }
120
+ )
121
+ : null
122
+ }
123
+ },
124
+ {
125
+ name: `_${FEATURE_NAME}`,
126
+ props: {
127
+ color: String,
128
+ zIndex: Number,
129
+ config: Object as PropType<MenuButtonType>,
130
+ tooltip: Boolean,
131
+ disabled: Boolean
132
+ }
133
+ }
134
+ )
@@ -0,0 +1,201 @@
1
+ import { computed, defineComponent, h, inject, PropType, ref, Ref } from 'vue'
2
+ import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
3
+ import { Button } from '@/components/button'
4
+ import { Icon } from '@/components/icon'
5
+ import { getMatchElementByRange, hasAttachmentInRange, hasImageInRange, hasMathformulaInRange, hasPanelInRange, hasTableInRange, hasVideoInRange, insertCodeBlock } from '@/core/function'
6
+ import { MenuButtonType, MenuDisplayButtonType } from '@/core/tool'
7
+
8
+ /**
9
+ * feature名称
10
+ */
11
+ const FEATURE_NAME = 'codeBlock'
12
+
13
+ /**
14
+ * 工具栏 - 代码块操作
15
+ */
16
+ export const CodeBlockToolbar = 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
+ const pre = getMatchElementByRange(editor.value, dataRangeCaches.value, {
26
+ parsedom: 'pre'
27
+ })
28
+ if (pre) {
29
+ return pre.marks!['data-editify-hljs'] || ''
30
+ }
31
+ return ''
32
+ })
33
+
34
+ //代码块前后插入段落
35
+ const insertParagraphWithPre = (type: 'up' | 'down' | undefined = 'up') => {
36
+ if (!editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
37
+ editor.value.range!.anchor.element = editor.value.range!.focus.element
38
+ editor.value.range!.anchor.offset = editor.value.range!.focus.offset
39
+ }
40
+ const pre = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'pre' })
41
+ if (pre) {
42
+ const paragraph = AlexElement.create({
43
+ type: 'block',
44
+ parsedom: AlexElement.BLOCK_NODE,
45
+ children: [
46
+ {
47
+ type: 'closed',
48
+ parsedom: 'br'
49
+ }
50
+ ]
51
+ })
52
+ if (type == 'up') {
53
+ editor.value.addElementBefore(paragraph, pre)
54
+ } else {
55
+ editor.value.addElementAfter(paragraph, pre)
56
+ }
57
+ editor.value.range!.anchor.moveToEnd(paragraph)
58
+ editor.value.range!.focus.moveToEnd(paragraph)
59
+ editor.value.domRender()
60
+ editor.value.rangeRender()
61
+ }
62
+ }
63
+ //选择代码语言
64
+ const selectLanguage = (value: string) => {
65
+ const pre = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'pre' })
66
+ if (pre) {
67
+ Object.assign(pre.marks!, {
68
+ 'data-editify-hljs': value
69
+ })
70
+ editor.value.domRender()
71
+ editor.value.rangeRender()
72
+ }
73
+ }
74
+
75
+ expose({
76
+ btnRef
77
+ })
78
+
79
+ return () => {
80
+ return [
81
+ //代码块前插入段落
82
+ h(
83
+ Button,
84
+ {
85
+ name: 'textWrapUp',
86
+ title: $editTrans('textWrapUp'),
87
+ tooltip: props.tooltip,
88
+ color: props.color,
89
+ zIndex: props.zIndex,
90
+ onOperate: () => insertParagraphWithPre('up')
91
+ },
92
+ {
93
+ default: () => h(Icon, { value: 'text-wrap', class: 'editify-icon-rotate' })
94
+ }
95
+ ),
96
+ //代码块后插入段落
97
+ h(
98
+ Button,
99
+ {
100
+ name: 'textWrapDown',
101
+ title: $editTrans('textWrapDown'),
102
+ tooltip: props.tooltip,
103
+ color: props.color,
104
+ zIndex: props.zIndex,
105
+ onOperate: () => insertParagraphWithPre('down')
106
+ },
107
+ {
108
+ default: () => h(Icon, { value: 'text-wrap' })
109
+ }
110
+ ),
111
+ //代码块语言选择
112
+ props.language.show
113
+ ? h(
114
+ Button,
115
+ {
116
+ ref: btnRef,
117
+ name: 'languages',
118
+ type: 'display',
119
+ title: $editTrans('selectLanguages'),
120
+ leftBorder: props.language.leftBorder,
121
+ rightBorder: props.language.rightBorder,
122
+ displayConfig: {
123
+ options: props.language.options,
124
+ value: selectVal.value,
125
+ width: props.language.width,
126
+ maxHeight: props.language.maxHeight
127
+ },
128
+ active: false,
129
+ disabled: props.language.disabled,
130
+ tooltip: props.tooltip,
131
+ color: props.color,
132
+ zIndex: props.zIndex,
133
+ onOperate: (_name, value) => selectLanguage(value)
134
+ },
135
+ {
136
+ default: () => h(Icon, { value: 'text-wrap' })
137
+ }
138
+ )
139
+ : null
140
+ ]
141
+ }
142
+ },
143
+ {
144
+ name: `_${FEATURE_NAME}`,
145
+ props: {
146
+ color: String,
147
+ zIndex: Number,
148
+ tooltip: Boolean,
149
+ language: Object as PropType<MenuDisplayButtonType>
150
+ }
151
+ }
152
+ )
153
+
154
+ /**
155
+ * 菜单栏 - 插入代码块
156
+ */
157
+ export const CodeBlockMenuButton = defineComponent(
158
+ props => {
159
+ const editor = inject<Ref<AlexEditor>>('editor')!
160
+ const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
161
+ const $editTrans = inject<(key: string) => any>('$editTrans')!
162
+ const isSourceView = inject<Ref<boolean>>('isSourceView')!
163
+
164
+ return () => {
165
+ return props.config.show
166
+ ? h(
167
+ Button,
168
+ {
169
+ name: FEATURE_NAME,
170
+ tooltip: props.tooltip,
171
+ color: props.color,
172
+ zIndex: props.zIndex,
173
+ title: $editTrans('inserCodeBlock'),
174
+ leftBorder: props.config.leftBorder,
175
+ rightBorder: props.config.rightBorder,
176
+ active: !!getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'pre' }),
177
+ disabled: props.disabled || isSourceView.value || hasTableInRange(editor.value, dataRangeCaches.value) || hasImageInRange(editor.value, dataRangeCaches.value) || hasVideoInRange(editor.value, dataRangeCaches.value) || hasAttachmentInRange(editor.value, dataRangeCaches.value) || hasMathformulaInRange(editor.value, dataRangeCaches.value) || hasPanelInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
178
+ onOperate: () => {
179
+ insertCodeBlock(editor.value, dataRangeCaches.value)
180
+ editor.value.domRender()
181
+ editor.value.rangeRender()
182
+ }
183
+ },
184
+ {
185
+ default: () => h(Icon, { value: 'code-block' })
186
+ }
187
+ )
188
+ : null
189
+ }
190
+ },
191
+ {
192
+ name: `_${FEATURE_NAME}`,
193
+ props: {
194
+ color: String,
195
+ zIndex: Number,
196
+ config: Object as PropType<MenuButtonType>,
197
+ tooltip: Boolean,
198
+ disabled: Boolean
199
+ }
200
+ }
201
+ )