-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVditor.razor.js
More file actions
53 lines (45 loc) · 1.65 KB
/
Vditor.razor.js
File metadata and controls
53 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { addLink, addScript } from '../BootstrapBlazor/modules/utility.js';
import Data from '../BootstrapBlazor/modules/data.js';
export async function init(id, invoke, options) {
const el = document.getElementById(id);
if (el === null) {
return;
}
await addLink('./_content/BootstrapBlazor.Vditor/css/vditor.css');
await addScript('./_content/BootstrapBlazor.Vditor/js/vditor.js');
const { options: op, value } = options;
const vditor = new Vditor(id, getOptions(invoke, { ...op, value }));
Data.set(id, { el, invoke, vditor });
return vditor;
}
const getOptions = (invoke, options) => {
return {
cache: {
enable: false,
},
...options,
after: () => invoke.invokeMethodAsync('TriggerRenderedAsync'),
input: value => invoke.invokeMethodAsync('TriggerInputAsync', value),
focus: value => invoke.invokeMethodAsync('TriggerFocusAsync', value),
blur: value => invoke.invokeMethodAsync('TriggerBlurAsync', value),
esc: value => invoke.invokeMethodAsync('TriggerEscapeAsync', value),
select: value => invoke.invokeMethodAsync('TriggerSelectAsync', value),
ctrlEnter: value => invoke.invokeMethodAsync('TriggerCtrlEnterAsync', value)
};
}
export async function reset(id, value, options) {
const md = Data.get(id);
const { invoke, vditor } = md;
if (vditor) {
vditor.destroy();
md.vditor = new Vditor(id, getOptions(invoke, { ...options, value }));
}
return md.vditor;
}
export function dispose(id) {
const md = Data.get(id);
const { vditor } = md;
if (vditor) {
vditor.destroy();
}
}