Skip to content

Commit 94a31a8

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth-rich-editor
2 parents b29e56d + eafb7bf commit 94a31a8

File tree

5 files changed

+195
-13
lines changed

5 files changed

+195
-13
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) => {

custom/tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": ".", // This should point to your project root
3+
"baseUrl": ".",
44
"paths": {
55
"@/*": [
6-
// "node_modules/adminforth/dist/spa/src/*"
76
"../../../adminforth/spa/src/*"
87
],
98
"*": [
10-
// "node_modules/adminforth/dist/spa/node_modules/*"
119
"../../../adminforth/spa/node_modules/*"
1210
],
1311
"@@/*": [
14-
// "node_modules/adminforth/dist/spa/src/*"
1512
"."
1613
]
1714
}

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
3030
constructor(options: PluginOptions) {
3131
super(options, import.meta.url);
3232
this.options = options;
33-
if (this.options.completion.rateLimit?.limit) {
33+
if (this.options.completion?.rateLimit?.limit) {
3434
this.rateLimiter = new RateLimiter(this.options.completion.rateLimit?.limit);
3535
}
3636
}

0 commit comments

Comments
 (0)