@@ -21,6 +21,9 @@ const init = (fileToLoad) => {
2121 // Enable pagination
2222 pagination: true ,
2323
24+ // Enable annotation import
25+ annotations: true ,
26+
2427 document : fileToLoad ? { data: fileToLoad } : sampleDocument,
2528
2629 // Initialize the toolbar
@@ -64,10 +67,12 @@ const restoreSnapshot = () => {
6467 }
6568}
6669
67- const SAMPLE_FIELD_ID = ' 123' ;
70+ const SAMPLE_HTML_FIELD_ID = ' 123' ;
71+ const SAMPLE_TEXT_FIELD_ID = ' 456' ;
72+
6873const replaceField = () => {
6974 const field = fieldAnnotationHelpers .findFieldAnnotationsByFieldId (
70- SAMPLE_FIELD_ID ,
75+ SAMPLE_HTML_FIELD_ID ,
7176 editor .value .state ,
7277 );
7378
@@ -89,20 +94,46 @@ const setViewing = () => {
8994const getHTMLField = () => {
9095 return {
9196 displayLabel: ' My placeholder field' ,
92- fieldId: SAMPLE_FIELD_ID ,
97+ fieldId: SAMPLE_HTML_FIELD_ID ,
9398 type: ' html' ,
9499 fieldType: ' HTMLINPUT' ,
95100 fieldColor: ' #000099' ,
96101 };
97102};
98103
104+ const getTextField = () => {
105+ return {
106+ displayLabel: ' My text field' ,
107+ fieldId: SAMPLE_TEXT_FIELD_ID ,
108+ type: ' text' ,
109+ fieldType: ' TEXTINPUT' ,
110+ fieldColor: ' #990000' ,
111+ };
112+ };
113+
99114const addField = (field ) => {
100115 if (! field) field = getHTMLField ();
101116 editor .value .commands .addFieldAnnotationAtSelection (field);
102117}
103118
119+ const exportDocx = () => {
120+ superdoc .value ? .export ();
121+ };
122+
104123const onDragStart = (event ) => {
105- const field = getHTMLField ();
124+
125+ const getField = (id ) => {
126+ switch (id) {
127+ case ' html-field' :
128+ return getHTMLField ();
129+ case ' text-field' :
130+ return getTextField ();
131+ default :
132+ return null ;
133+ }
134+ }
135+
136+ const field = getField (event .target .id );
106137 event .dataTransfer .setData (' fieldAnnotation' , JSON .stringify ({ sourceField: field }));
107138};
108139
@@ -117,32 +148,37 @@ onMounted(() => init());
117148
118149 < div id= " toolbar" class = " my-custom-toolbar" >< / div>
119150 < div class = " editor-and-button" >
120- < div class = " editor-buttons" style= " margin-right: 10px;" >
121- < div class = " draggable-field" draggable= " true" @dragstart= " onDragStart" > HTML field< / div>
151+ < div class = " editor-buttons fields" style= " margin-right: 10px;" >
152+ < div class = " draggable-field" draggable= " true" @dragstart= " onDragStart" id= " html-field" > HTML field< / div>
153+ < div class = " draggable-field" draggable= " true" @dragstart= " onDragStart" id= " text-field" > TEXT field< / div>
122154 < / div>
123155 < div id= " editor" class = " main-editor" >< / div>
124156 < div class = " editor-buttons" >
125157 < UploadFile : update- file= " handleFileUpdate" / >
126- < button class = " custom-button" @click= " addField" > Insert ' 123' field< / button>
127-
128158 < button class = " custom-button" @click= " saveSnapshot" > Save state< / button>
129159 < button class = " custom-button" @click= " restoreSnapshot" : disabled= " !snapshot" > Restore state< / button>
130- < button class = " custom-button" @click= " replaceField" > Replace ' 123 ' field< / button>
160+ < button class = " custom-button" @click= " replaceField" > Update HTML field content < / button>
131161 < textarea
132162 id= " custom-html"
133163 class = " custom-textarea"
134164 placeholder= " Type some HTML to replace custom nodes with"
135165 value= " <p>Custom <b>Node</b> Content</p>"
136166 >< / textarea>
137167
168+ < br / >
138169 < button class = " custom-button" @click= " setEditable" > Set editable< / button>
139170 < button class = " custom-button" @click= " setViewing" > Set viewing< / button>
171+ < br / >
172+ < button class = " custom-button" @click= " exportDocx" > Export docx< / button>
140173 < / div>
141174 < / div>
142175 < / div>
143176< / template>
144177
145178< style>
179+ .fields > div {
180+ margin- bottom: 10px ;
181+ }
146182textarea {
147183 margin- left: 10px ;
148184}
0 commit comments