22import ' @harbour-enterprises/superdoc/style.css' ;
33import { onMounted , shallowRef } from ' vue' ;
44import { SuperDoc } from ' @harbour-enterprises/superdoc' ;
5+ import UploadFile from ' ../../shared/vue/UploadFile/UploadFile.vue' ;
6+ import sampleDocument from ' ../../shared/data/sample-document.docx?url' ;
57
68// This is our custom mark that we are creating for this example
79import { CustomMark } from ' ./custom-mark.js' ;
810
911const superdoc = shallowRef (null );
10- const init = () => {
12+ const init = (fileToLoad ) => {
1113 superdoc .value = new SuperDoc ({
1214 selector: ' #editor' , // Can also be a class ie: .main-editor
1315
1416 pagination: true ,
1517
18+ // Load the document if provided, otherwise load the sample document
19+ document : fileToLoad ? { data: fileToLoad } : sampleDocument,
20+
1621 // Initialize the toolbar
1722 toolbar: ' #toolbar' ,
1823 toolbarGroups: [' center' ],
@@ -30,9 +35,6 @@ const myCustomOnReady = () => {
3035 superdoc .value ? .activeEditor ? .on (' update' , async ({ editor }) => {
3136 // Let's log the HTML representation of the editor on each update;
3237 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);
3638 });
3739}
3840
@@ -58,6 +60,14 @@ const exportDocx = () => {
5860 });
5961};
6062
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+
6171onMounted (() => init ());
6272< / script>
6373
@@ -71,39 +81,10 @@ onMounted(() => init());
7181 < div class = " editor-and-button" >
7282 < div id= " editor" class = " main-editor" >< / div>
7383 < 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>
7687 < / div>
7788 < / div>
7889 < / div>
7990< / 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