11<script setup>
22import ' tippy.js/dist/tippy.css' ;
3- import { NSkeleton } from ' naive-ui' ;
3+ import { NSkeleton , useMessage } from ' naive-ui' ;
44import { ref , onMounted , onBeforeUnmount , shallowRef , reactive , markRaw } from ' vue' ;
55import { Editor } from ' @/index.js' ;
66import { getStarterExtensions } from ' @extensions/index.js' ;
@@ -43,6 +43,7 @@ const props = defineProps({
4343
4444const editorReady = ref (false );
4545const editor = shallowRef (null );
46+ const message = useMessage ();
4647
4748const editorWrapper = ref (null );
4849const editorElem = ref (null );
@@ -99,10 +100,16 @@ const pollForMetaMapData = (ydoc, retries = 10, interval = 500) => {
99100 checkData ();
100101};
101102
103+ const setDefaultBlankFile = async () => {
104+ fileSource .value = await getFileObject (BlankDOCX, ' blank.docx' , DOCX );
105+ };
106+
102107const loadNewFileData = async () => {
103- fileSource .value = props .fileSource ;
108+ if (! fileSource .value ) {
109+ fileSource .value = props .fileSource ;
110+ }
104111 if (! fileSource .value || fileSource .value .type !== DOCX ) {
105- fileSource . value = await getFileObject (BlankDOCX, ' blank.docx ' , DOCX );
112+ await setDefaultBlankFile ( );
106113 }
107114
108115 try {
@@ -116,7 +123,12 @@ const loadNewFileData = async () => {
116123const initializeData = async () => {
117124 // If we have the file, initialize immediately from file
118125 if (props .fileSource ) {
119- const fileData = await loadNewFileData ();
126+ let fileData = await loadNewFileData ();
127+ if (! fileData) {
128+ message .error (' Unable to load the file. Please verify the .docx is valid and not password protected.' );
129+ await setDefaultBlankFile ();
130+ fileData = await loadNewFileData ();
131+ }
120132 return initEditor (fileData);
121133 }
122134
0 commit comments