22import type { Range } from ' @opentiny/fluent-editor'
33import type FluentEditor from ' @opentiny/fluent-editor'
44import { onMounted , ref } from ' vue'
5+ import ' quill-table-up/index.css'
6+ import ' quill-table-up/table-creator.css'
57
68let editor: FluentEditor
79const editorRef = ref <HTMLElement >()
@@ -12,30 +14,51 @@ const TOOLBAR_CONFIG = [
1214 [{ list: ' ordered' }, { list: ' bullet' }],
1315 [' clean' ],
1416 [' file' , ' image' , ' video' ],
17+ [{ ' table-up' : [] }],
1518]
1619
1720onMounted (() => {
1821 // ssr compat, reference: https://vitepress.dev/guide/ssr-compat#importing-in-mounted-hook
19- import (' @opentiny/fluent-editor' ).then (({ default : FluentEditor }) => {
20- if (! editorRef .value ) return
21- const Delta = FluentEditor .import (' delta' )
22- editor = new FluentEditor (editorRef .value , {
23- theme: ' snow' ,
24- modules: {
25- toolbar: TOOLBAR_CONFIG ,
26- uploader: {
27- // only allow image
28- mimetypes: [' image/*' ],
29- handler(range : Range , files : File []) {
30- return files .map ((_ , i ) => i % 2 === 0 ? false : ' https://developer.mozilla.org/static/media/chrome.5e791c51c323fbb93c31.svg' )
22+ Promise .all ([
23+ import (' @opentiny/fluent-editor' ),
24+ import (' quill-table-up' ),
25+ ]).then (
26+ ([
27+ { default: FluentEditor , generateTableUp },
28+ { defaultCustomSelect , TableMenuContextmenu , TableSelection , TableUp },
29+ ]) => {
30+ if (! editorRef .value ) {
31+ return
32+ }
33+
34+ FluentEditor .register ({ ' modules/table-up' : generateTableUp (TableUp ) }, true )
35+
36+ const Delta = FluentEditor .import (' delta' )
37+ editor = new FluentEditor (editorRef .value , {
38+ theme: ' snow' ,
39+ modules: {
40+ ' toolbar' : TOOLBAR_CONFIG ,
41+ ' uploader' : {
42+ // only allow image
43+ mimetypes: [' image/*' ],
44+ handler(range : Range , files : File []) {
45+ return files .map ((_ , i ) => i % 2 === 0 ? false : ' https://developer.mozilla.org/static/media/chrome.5e791c51c323fbb93c31.svg' )
46+ },
47+ fail(file : File , range : Range ) {
48+ this .quill .updateContents (new Delta ().retain (range .index ).delete (1 ).insert ({ image: ' https://developer.mozilla.org/static/media/edge.741dffaf92fcae238b84.svg' }))
49+ },
3150 },
32- fail(file : File , range : Range ) {
33- this .quill .updateContents (new Delta ().retain (range .index ).delete (1 ).insert ({ image: ' https://developer.mozilla.org/static/media/edge.741dffaf92fcae238b84.svg' }))
51+ ' table-up' : {
52+ customSelect: defaultCustomSelect ,
53+ selection: TableSelection ,
54+ selectionOptions: {
55+ tableMenu: TableMenuContextmenu ,
56+ },
3457 },
3558 },
36- },
37- })
38- } )
59+ })
60+ },
61+ )
3962})
4063 </script >
4164
0 commit comments