Skip to content

Commit c20a305

Browse files
committed
feat: add support of tables
1 parent 45ba0f9 commit c20a305

File tree

3 files changed

+193
-8
lines changed

3 files changed

+193
-8
lines changed

custom/package-lock.json

Lines changed: 159 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

custom/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"quill": "^2.0.2"
13+
"quill": "^2.0.2",
14+
"quill-table-better": "^1.2.3"
1415
}
1516
}

custom/quillEditor.vue

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import adminforth from '@/adminforth';
2727
import AsyncQueue from './async-queue';
2828
import Quill from "quill";
2929
import "quill/dist/quill.snow.css";
30+
import QuillTableBetter from 'quill-table-better';
31+
import 'quill-table-better/dist/quill-table-better.css';
32+
3033
import { useI18n } from 'vue-i18n';
3134
3235
const { t } = useI18n();
@@ -89,6 +92,11 @@ Quill.register(CompleteBlot);
8992
// @ts-ignore
9093
Quill.register(ImageBlot);
9194
95+
Quill.register({
96+
'modules/table-better': QuillTableBetter
97+
}, true);
98+
99+
92100
const updaterQueue = new AsyncQueue();
93101
94102
const 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

Comments
 (0)