@@ -27,6 +27,9 @@ import adminforth from '@/adminforth';
2727import AsyncQueue from ' ./async-queue' ;
2828import Quill from " quill" ;
2929import " quill/dist/quill.snow.css" ;
30+ import QuillTableBetter from ' quill-table-better' ;
31+ import ' quill-table-better/dist/quill-table-better.css' ;
32+
3033import { useI18n } from ' vue-i18n' ;
3134
3235const { t } = useI18n ();
@@ -89,6 +92,11 @@ Quill.register(CompleteBlot);
8992// @ts-ignore
9093Quill .register (ImageBlot );
9194
95+ Quill .register ({
96+ ' modules/table-better' : QuillTableBetter
97+ }, true );
98+
99+
92100const updaterQueue = new AsyncQueue ();
93101
94102const props = defineProps <{
@@ -197,11 +205,7 @@ async function imageHandler() {
197205 };
198206}
199207
200- onMounted (() => {
201- currentValue .value = props .record [props .column .name ] || ' ' ;
202- editor .value .innerHTML = currentValue .value ;
203-
204- quill = new Quill (editor .value as HTMLElement , {
208+ const quillOptions = {
205209 theme: " snow" ,
206210 readOnly:props .column ?.editReadonly ,
207211 placeholder: ' Type here...' ,
@@ -210,6 +214,7 @@ onMounted(() => {
210214 toolbar: {
211215 container: props .meta .toolbar || [
212216 [' bold' , ' italic' , ' underline' , ' strike' ], // toggled buttons
217+ [' table-better' ],
213218 [' blockquote' , ' code-block' , ' link' , ... props .meta .uploadPluginInstanceId ? [' image' ] : []],
214219 // [
215220 // // 'image',
@@ -237,6 +242,11 @@ onMounted(() => {
237242 image: imageHandler ,
238243 },
239244 },
245+ ' table-better' : {
246+ language: ' en_US' ,
247+ menus: [' column' , ' row' , ' merge' , ' table' , ' cell' , ' wrap' , ' delete' ],
248+ toolbarTable: true
249+ },
240250 keyboard: {
241251 bindings: {
242252 tab: {
@@ -250,8 +260,24 @@ onMounted(() => {
250260 },
251261 }
252262 },
253- });
263+ };
264+
265+ function initValue(quill : Quill ) {
266+ const html = props .record [props .column .name ] || ' ' ;
267+ const delta = quill .clipboard .convert ({ html });
268+ const [range] = quill .selection .getRange ();
269+ quill .updateContents (delta , Quill .sources .USER );
270+ quill .setSelection (
271+ delta .length () - (range ?.length || 0 ),
272+ Quill .sources .SILENT
273+ );
274+ quill .scrollSelectionIntoView ();
275+ }
254276
277+ onMounted (() => {
278+ currentValue .value = props .record [props .column .name ] || ' ' ;
279+ quill = new Quill (editor .value as HTMLElement , quillOptions );
280+ initValue (quill );
255281 lastText = quill .getText ();
256282
257283 quill .on (Quill .events .TEXT_CHANGE , async (delta : any , oldDelta : any , source : string ) => {
0 commit comments