2
2
import ' @harbour-enterprises/superdoc/style.css' ;
3
3
import { onMounted , shallowRef } from ' vue' ;
4
4
import { SuperDoc } from ' @harbour-enterprises/superdoc' ;
5
+ import UploadFile from ' ../../shared/vue/UploadFile/UploadFile.vue' ;
6
+ import sampleDocument from ' ../../shared/data/sample-document.docx?url' ;
5
7
6
8
// This is our custom mark that we are creating for this example
7
9
import { CustomMark } from ' ./custom-mark.js' ;
8
10
9
11
const superdoc = shallowRef (null );
10
- const init = () => {
12
+ const init = (fileToLoad ) => {
11
13
superdoc .value = new SuperDoc ({
12
14
selector: ' #editor' , // Can also be a class ie: .main-editor
13
15
14
16
pagination: true ,
15
17
18
+ // Load the document if provided, otherwise load the sample document
19
+ document : fileToLoad ? { data: fileToLoad } : sampleDocument,
20
+
16
21
// Initialize the toolbar
17
22
toolbar: ' #toolbar' ,
18
23
toolbarGroups: [' center' ],
@@ -30,9 +35,6 @@ const myCustomOnReady = () => {
30
35
superdoc .value ? .activeEditor ? .on (' update' , async ({ editor }) => {
31
36
// Let's log the HTML representation of the editor on each update;
32
37
console .log (' Content updated: ' , editor .getHTML ());
33
-
34
- // Let's also pretend we're exporting to DOCX so we can save it somewhere
35
- exportToDocx (editor);
36
38
});
37
39
}
38
40
@@ -58,6 +60,14 @@ const exportDocx = () => {
58
60
});
59
61
};
60
62
63
+ const handleFileUpdate = (file ) => {
64
+ // Handle file update logic here
65
+ console .log (' File updated:' , file);
66
+ superdoc .value ? .destroy ();
67
+
68
+ init (file);
69
+ };
70
+
61
71
onMounted (() => init ());
62
72
< / script>
63
73
@@ -71,39 +81,10 @@ onMounted(() => init());
71
81
< div class = " editor-and-button" >
72
82
< div id= " editor" class = " main-editor" >< / div>
73
83
< div class = " editor-buttons" >
74
- < button class = " insert-mark" @click= " insertCustomMark" > Insert custom mark< / button>
75
- < button class = " insert-mark" @click= " exportDocx" > Export< / button>
84
+ < UploadFile : update- file= " handleFileUpdate" / >
85
+ < button class = " custom-button" @click= " insertCustomMark" > Insert custom mark< / button>
86
+ < button class = " custom-button" @click= " exportDocx" > Export< / button>
76
87
< / div>
77
88
< / div>
78
89
< / div>
79
90
< / template>
80
-
81
- < style scoped>
82
- .example - container {
83
- display: flex;
84
- flex- direction: column;
85
- align- items: center;
86
- justify- content: center;
87
- }
88
- .editor - and- button {
89
- display: flex;
90
- flex- direction: row;
91
- align- items: flex- start;
92
- justify- content: center;
93
- }
94
- .editor - buttons {
95
- display: flex;
96
- flex- direction: column;
97
- }
98
- .editor - buttons button {
99
- margin- bottom: 10px ;
100
- }
101
- .insert - mark {
102
- padding: 8px 12px ;
103
- border- radius: 8px ;
104
- margin- left: 10px ;
105
- outline: none;
106
- border: none;
107
- background- color: #AECEE6 ;
108
- }
109
- < / style>
0 commit comments