striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

App.vue (4023B)


      1 <template>
      2   <div
      3     id="app"
      4     style="font-family: Segoe UI; color: #2c3e50; margin-top: 20vh; display: flex; justify-content: center; align-items: center; flex-direction: column; padding: 0 1rem;"
      5   >
      6     <striven-editor
      7       ref="editor"
      8       v-model="content"
      9       :toolbar-hide="toolbarHide"
     10       :minimal="minimal"
     11       :toolbar-bottom="toolbarBottom"
     12       :placeholder="'Type something in here...'"
     13       style="min-height: 300px; width: 90%;"
     14       :on-enter="submitOnEnter"
     15       :on-paste="onPaste"
     16       :after-paste="afterPaste"
     17       :change="onChange"
     18     ></striven-editor>
     19 
     20     <!-- TESTING -->
     21     <!-- <button @click="safariOut">isSafari</button> -->
     22     <!-- <button @click="chromeOut">isChrome</button> -->
     23     <!-- <button @click="insertList">insertUnorderedList</button> -->
     24 
     25     <!-- <div v-html="content"></div> -->
     26     <!-- <div ref="customButton" style="display: flex; align-items: flex-end;"> -->
     27     <!--   <div class="custom-button" @click="sendContent">Send</div>           -->
     28     <!-- </div>                                                                 -->
     29   </div>
     30 </template>
     31 
     32 <script>
     33 /* eslint-disable */
     34 import './test';
     35 import { VueStrivenEditor as StrivenEditor } from "@striven-erp/striven-editor";
     36 
     37 export default {
     38   name: "app",
     39   components: { StrivenEditor },
     40   data() {
     41     return {
     42       // metaUrl: "https://mighty-anchorage-82390.herokuapp.com/meta", // metaserver.js
     43       // imageUrl: "http://localhost:4200/image", // imageserver.js
     44       minimal: false,
     45       uploadOnPaste: false,
     46       toolbarBottom: false,
     47       toolbarHide: false, // Tests will break toolbar if this is on
     48       sanitizePaste: true,
     49       onInvalidFile() {
     50         alert("invalid file");
     51       },
     52       // toolbarOptions: [
     53       //   {
     54       //     icon: 'https://innovate.test.striven.com/Images/striven-icon.svg',
     55       //     handler: () => {
     56       //       const range = this.editor.range;
     57       //       if(range && range.startContainer !== document) {
     58       //         range.insertNode(document.createTextNode('Created by a custom button!'))
     59       //       }
     60       //     }
     61       //   }
     62       // ],
     63       placeholder: "Begin typing in this editor...",
     64       submitOnEnter: e => {
     65         if (e.ctrlKey) {
     66           const content = this.editor.getContent();
     67           const files = this.editor.getFiles();
     68 
     69           if (content || files.length) {
     70             console.log({ content, files });
     71             this.editor.clearContent();
     72             this.editor.clearFiles();
     73           }
     74         }
     75       },
     76       // customButton: () => this.$refs.customButton,
     77       content: "",
     78       editor: null
     79     };
     80   },
     81   mounted() {
     82     this.editor = this.$refs.editor.editor;
     83   },
     84   methods: {
     85     onChange() {
     86       this.editor.body.style.backgroundColor = 'green';
     87       setTimeout(() => this.editor.body.style.backgroundColor = null, 200);
     88     },
     89     afterPaste() {
     90       setTimeout(() => { 
     91         [...this.editor.body.querySelectorAll('.striven-mention')]
     92           .forEach(m => (m.outerHTML = m.textContent));
     93       }, 0);
     94     },
     95     onPaste(e) {
     96       console.log(e); 
     97     },
     98     sendContent() {
     99       console.log(this.editor.getContent());
    100       this.editor.clearContent();
    101     },
    102     safariOut() {
    103       this.editor.setContent(`${this.editor.browser.isSafari()}`)
    104     },
    105     chromeOut() {
    106       this.editor.setContent(`${this.editor.browser.isChrome()}`)
    107     },
    108     insertList() {
    109       document.execCommand('insertUnorderedList');
    110     }
    111   }
    112 };
    113 </script>
    114 
    115 <style>
    116 .custom-button {
    117   height: 100%;
    118   border-color: #4cae4c;
    119   background-color: #5cb85c;
    120   display: flex;
    121   justify-content: center;
    122   align-items: center;
    123   padding: 0 15px;
    124   color: #fff;
    125   margin: 0 0 1px 0;
    126   cursor: pointer;
    127   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    128 }
    129 
    130 .custom-button:hover {
    131   background-color: #4cae4c;
    132   border-color: #398439;
    133 }
    134 </style>