1
1
<script lang="ts">
2
- import { type Options } from ' ink-mde'
2
+ import { type Instance , type Options } from ' ink-mde'
3
3
import Ink from ' ink-mde/vue'
4
4
import { OverlayScrollbars } from ' overlayscrollbars'
5
5
import { type SystemAppearance } from ' #composables/useAppearance'
@@ -37,12 +37,13 @@ export default defineComponent({
37
37
const cssMaxWidth = computed (() => ` ${maxWidthInChars .value }ch ` )
38
38
const instance = computed (() => ink .value ?.instance )
39
39
40
- const editorOptions = computed (() => {
40
+ const editorOptions = computed < Options > (() => {
41
41
return {
42
42
... props .options ,
43
43
interface: {
44
44
... props .options ?.interface ,
45
45
appearance: editorAppearance .value ,
46
+ toolbar: false ,
46
47
},
47
48
}
48
49
})
@@ -75,11 +76,35 @@ export default defineComponent({
75
76
}
76
77
})
77
78
79
+ const formatSelection = (type : Parameters <Instance [' format' ]>[0 ]) => {
80
+ instance .value ?.format (type , {})
81
+ }
82
+
83
+ const handleUpload = async (event : Event ) => {
84
+ const target = event .target as HTMLInputElement
85
+
86
+ if (target ?.files ) {
87
+ try {
88
+ const url = await props .options ?.files ?.handler ?.(target .files )
89
+
90
+ if (url ) {
91
+ const markup = `  `
92
+
93
+ instance .value ?.insert (markup )
94
+ }
95
+ } catch (error ) {
96
+ console .error (error )
97
+ }
98
+ }
99
+ }
100
+
78
101
return {
79
102
cssMaxWidth ,
80
103
currentLayer ,
81
104
editorOptions ,
82
105
focus ,
106
+ formatSelection ,
107
+ handleUpload ,
83
108
ink ,
84
109
instance ,
85
110
nextLayer ,
@@ -90,14 +115,36 @@ export default defineComponent({
90
115
</script >
91
116
92
117
<template >
93
- <Ink
94
- ref =" ink"
95
- :model-value =" modelValue"
96
- :options =" editorOptions"
97
- class =" core-editor flex flex-col flex-grow flex-shrink rounded"
98
- :class =" currentLayer.class"
99
- @update:model-value =" $emit('update:modelValue', $event)"
100
- />
118
+ <div class =" core-editor flex flex-col-reverse lg:flex-col flex-grow flex-shrink min-h-0 rounded" >
119
+ <template v-if =" options ?.interface ?.toolbar " >
120
+ <CoreScrollable class =" core-editor-scrollable flex-shrink-0 w-full mx-auto" >
121
+ <CoreEditorToolbar
122
+ class =" core-editor-toolbar mx-auto px-1 overflow-hidden lg:px-0 py-1 flex-shrink-0 rounded min-w-full"
123
+ :upload =" options?.toolbar?.upload"
124
+ @blockquote =" formatSelection('quote')"
125
+ @bold =" formatSelection('bold')"
126
+ @bullet-list =" formatSelection('list')"
127
+ @code =" formatSelection('code')"
128
+ @heading =" formatSelection('heading')"
129
+ @image =" formatSelection('image')"
130
+ @italic =" formatSelection('italic')"
131
+ @link =" formatSelection('link')"
132
+ @number-list =" formatSelection('ordered_list')"
133
+ @task-list =" formatSelection('task_list')"
134
+ @upload =" handleUpload"
135
+ />
136
+ </CoreScrollable >
137
+ <CoreDivider />
138
+ </template >
139
+ <Ink
140
+ ref =" ink"
141
+ :model-value =" modelValue"
142
+ :options =" editorOptions"
143
+ class =" flex flex-col flex-grow flex-shrink min-h-0 rounded overflow-hidden"
144
+ :class =" currentLayer.class"
145
+ @update:model-value =" $emit('update:modelValue', $event)"
146
+ />
147
+ </div >
101
148
</template >
102
149
103
150
<style scoped>
@@ -115,9 +162,14 @@ export default defineComponent({
115
162
--ink-syntax-hashtag-background-color : rgb (v-bind(' nextLayer.bgCssVar' ));
116
163
--ink-syntax-processing-instruction-color : rgb (v-bind(' nextLayer.textCssVar' ) / 0.1 );
117
164
165
+ .core-editor-scrollable {
166
+ max-width : var (--core-editor-max-width-in-chars );
167
+ }
168
+
118
169
:deep(.ink-mde ) {
119
170
border : none ;
120
171
border-radius : 0 ;
172
+ padding : 0 ;
121
173
122
174
.cm-placeholder {
123
175
color : var (--core-editor-text-muted );
@@ -129,7 +181,11 @@ export default defineComponent({
129
181
130
182
.ink-mde-details {
131
183
background-color : transparent ;
132
- border-top : 1px solid var (--core-editor-layer-2-bg );
184
+ border-top : 1px solid var (--core-editor-divider );
185
+ padding : 0.25rem ;
186
+ }
187
+
188
+ .ink-mde-editor {
133
189
padding : 0.25rem ;
134
190
}
135
191
0 commit comments