-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathApp.vue
More file actions
109 lines (92 loc) · 2.75 KB
/
App.vue
File metadata and controls
109 lines (92 loc) · 2.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<script setup>
import '@harbour-enterprises/superdoc/style.css';
import { onMounted, shallowRef } from 'vue';
import { SuperDoc } from '@harbour-enterprises/superdoc';
// This is our custom mark that we are creating for this example
import { CustomMark } from './custom-mark.js';
const superdoc = shallowRef(null);
const init = () => {
superdoc.value = new SuperDoc({
selector: '#editor', // Can also be a class ie: .main-editor
pagination: true,
// Initialize the toolbar
toolbar: '#toolbar',
toolbarGroups: ['center'],
editorExtensions: [CustomMark],
onReady: myCustomOnReady,
});
};
/**
* When SuperDoc is ready, we can listen for updates coming from the editor.
*/
const myCustomOnReady = () => {
superdoc.value?.activeEditor?.on('update', async ({ editor }) => {
// Let's log the HTML representation of the editor on each update;
console.log('Content updated: ', editor.getHTML());
// Let's also pretend we're exporting to DOCX so we can save it somewhere
exportToDocx(editor);
});
}
/**
* This is an example of how to export the content of the editor to a DOCX file.
* @param { Editor } editor - The editor instance.
* @returns { Promise<void> } - A promise that resolves when the export is complete.
*/
const exportToDocx = async (editor) => {
const docx = await editor.exportDocx();
console.debug('Exported to DOCX - we have a blob now: ', docx);
};
const insertCustomMark = () => {
const randomId = Math.random().toString(36).substring(2, 7);
superdoc.value?.activeEditor?.commands.setMyCustomMark(randomId);
};
const exportDocx = () => {
superdoc.value?.export({
exportType: ['docx']
});
};
onMounted(() => init());
</script>
<template>
<div class="example-container">
<h1>SuperDoc: Create a custom mark with custom command</h1>
<p>In this example, we create a simple custom mark to pass into SuperDoc.</p>
<div id="toolbar" class="my-custom-toolbar"></div>
<div class="editor-and-button">
<div id="editor" class="main-editor"></div>
<div class="editor-buttons">
<button class="insert-mark" @click="insertCustomMark">Insert custom mark</button>
<button class="insert-mark" @click="exportDocx">Export</button>
</div>
</div>
</div>
</template>
<style scoped>
.example-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.editor-and-button {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: center;
}
.editor-buttons {
display: flex;
flex-direction: column;
}
.editor-buttons button {
margin-bottom: 10px;
}
.insert-mark {
padding: 8px 12px;
border-radius: 8px;
margin-left: 10px;
outline: none;
border: none;
background-color: #AECEE6;
}
</style>