2019-07-19 13:51:57 -07:00
|
|
|
<template>
|
2019-12-19 21:50:50 -08:00
|
|
|
<!-- change class to .master-note-edit to have it popup on the screen -->
|
2019-07-29 00:22:47 -07:00
|
|
|
<div
|
2019-12-19 21:50:50 -08:00
|
|
|
id="InputNotes"
|
|
|
|
class="master-note-edit"
|
2019-07-29 00:22:47 -07:00
|
|
|
@keyup.esc="close"
|
2020-02-01 14:21:22 -08:00
|
|
|
:class="[{'size-down':(sizeDown == true), 'padded-bottom':extraToolbarsVisible }, 'position-'+position ]"
|
2019-12-19 21:50:50 -08:00
|
|
|
:style="{ 'background-color':styleObject['noteBackground'], 'color':styleObject['noteText']}"
|
2019-07-29 00:22:47 -07:00
|
|
|
>
|
2019-09-10 11:10:11 -07:00
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
<!-- Loading indicator -->
|
2019-09-10 11:10:11 -07:00
|
|
|
<div v-if="loading" class="loading-note">
|
|
|
|
<div class="ui active dimmer">
|
2019-12-19 21:50:50 -08:00
|
|
|
<div class="ui text loader">{{loadingMessage}}</div>
|
2019-09-10 11:10:11 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
<div class="note-menu">
|
|
|
|
|
|
|
|
<div class="nm-button" v-on:click="close">
|
|
|
|
<i class="close icon"></i>
|
|
|
|
</div>
|
|
|
|
<div class="nm-button" v-on:click="toggleList('ol')">
|
|
|
|
<i class="list ol icon"></i>
|
|
|
|
</div>
|
|
|
|
<div class="nm-button" v-on:click="toggleList('ul')">
|
|
|
|
<i class="tasks icon"></i>
|
|
|
|
</div>
|
|
|
|
<div class="nm-button" v-on:click="toggleBold()">
|
|
|
|
<i class="bold icon"></i>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="nm-button" v-on:click="toggleItalic()">
|
|
|
|
<i class="quote left icon"></i>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="nm-button" v-on:click="modifyFont('2.286em') ">
|
|
|
|
<i class="text height icon"></i>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="usersOnNote > 1" class="nm-button">
|
|
|
|
<i class="green user circle icon"></i>{{usersOnNote}}
|
|
|
|
</div>
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2019-09-10 11:10:11 -07:00
|
|
|
</div>
|
2019-07-29 00:22:47 -07:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
<div id="squire-id" class="squire-box" ref="squirebox"></div>
|
|
|
|
|
|
|
|
<!-- && this.$store.getters.getIsUserOnMobile -->
|
|
|
|
<span class="note-status-indicator" v-on:click="save()" v-if="statusText != 'Saved' && $store.getters.getIsUserOnMobile">
|
|
|
|
<div class="ui green button">{{statusText}}</div>
|
|
|
|
</span>
|
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
<color-picker
|
|
|
|
v-if="colorPickerVisible"
|
|
|
|
:location="colorPickerLocation"
|
2020-02-01 14:21:22 -08:00
|
|
|
@changeColor="onChangeColor"
|
|
|
|
@close="onCloseColorChanger"
|
|
|
|
:style-object="styleObject"
|
2019-07-29 00:22:47 -07:00
|
|
|
/>
|
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
<!-- Note options on the bottom of note -->
|
|
|
|
<div class="all-settings" :class="{ 'low-settings':!extraToolbarsVisible }">
|
|
|
|
|
|
|
|
<div class="note-menu">
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
<!-- <note-tag-edit :noteId="noteid" :key="'tags-for-note-'+noteid"/><br> -->
|
|
|
|
|
|
|
|
<!-- Pin Button -->
|
|
|
|
<div @click="onToggleArchived" class="nm-button">
|
|
|
|
<i class="archive icon" :class="{green:(archived == 1)}"></i>
|
|
|
|
{{(archived == 1)?'Archived':'Archive'}}
|
|
|
|
</div>
|
|
|
|
<!-- archive button -->
|
|
|
|
<div @click="onTogglePinned" class="nm-button">
|
|
|
|
<i class="pin icon" :class="{green:(pinned == 1)}"></i>
|
|
|
|
{{(pinned == 1)?'Pinned':'Pin'}}
|
|
|
|
</div>
|
|
|
|
<!-- colors button -->
|
|
|
|
<span class="nm-button" v-on:click="showColorPicker">
|
|
|
|
<i class="paint brush icon"></i>
|
|
|
|
Colors
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<!-- attachment button -->
|
|
|
|
<div class="nm-button" v-on:click="openEditAttachment">
|
|
|
|
<i class="folder icon"></i> Files
|
2020-01-02 17:26:55 -08:00
|
|
|
</div>
|
2020-02-01 14:21:22 -08:00
|
|
|
<!-- file upload button -->
|
|
|
|
<file-upload-button class="nm-button" :noteId="noteid" />
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-01 14:21:22 -08:00
|
|
|
<!-- <div class="shade" v-on:click="showAllSettings = false"></div> -->
|
2019-07-19 13:51:57 -07:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import axios from 'axios'
|
2020-02-01 14:21:22 -08:00
|
|
|
const DiffMatchPatch = require('../../../server/helpers/DiffMatchPatch')
|
2019-07-19 13:51:57 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'InputNotes',
|
2019-07-20 16:07:22 -07:00
|
|
|
props: [ 'noteid', 'position' ],
|
2019-07-19 13:51:57 -07:00
|
|
|
components:{
|
2019-12-19 21:50:50 -08:00
|
|
|
'note-tag-edit': require('@/components/NoteTagEdit.vue').default,
|
|
|
|
'color-picker': require('@/components/ColorPicker.vue').default,
|
|
|
|
'file-upload-button': require('@/components/FileUploadButton.vue').default,
|
2020-01-02 17:26:55 -08:00
|
|
|
'delete-button': require('@/components/NoteDeleteButtonComponent.vue').default,
|
2019-07-19 13:51:57 -07:00
|
|
|
},
|
|
|
|
data(){
|
|
|
|
return {
|
2019-09-10 11:10:11 -07:00
|
|
|
loading: true,
|
|
|
|
loadingMessage: 'Loading Note',
|
2019-07-19 13:51:57 -07:00
|
|
|
currentNoteId: 0,
|
|
|
|
noteText: '',
|
2020-02-01 14:21:22 -08:00
|
|
|
diffNoteText: '',
|
2019-07-29 00:22:47 -07:00
|
|
|
statusText: 'Saved',
|
2019-07-19 13:51:57 -07:00
|
|
|
lastNoteHash: null,
|
2019-07-24 11:06:50 -07:00
|
|
|
saveDebounce: null, //Prevent save from being called numerous times quickly
|
2019-07-19 13:51:57 -07:00
|
|
|
updated: 'Never',
|
|
|
|
editDebounce: null,
|
2020-02-01 14:21:22 -08:00
|
|
|
emitChangeDebounce: null,
|
2019-12-19 21:50:50 -08:00
|
|
|
keyPressesCounter: 0, //Determen keys pressed between saves
|
2019-09-10 11:10:11 -07:00
|
|
|
pinned: 0,
|
|
|
|
archived: 0,
|
2019-12-19 21:50:50 -08:00
|
|
|
attachmentCount: 0,
|
|
|
|
styleObject: { 'noteText':null,'noteBackground':null, 'noteIcon':null, 'iconColor':null }, //Style object. Determines colors and badges
|
|
|
|
|
|
|
|
sizeDown: false, //Used to animate close state
|
|
|
|
colorPickerVisible: false,
|
|
|
|
colorPickerLocation: null,
|
|
|
|
|
|
|
|
tinymce: null, //Initialized editor instance
|
2020-01-02 17:26:55 -08:00
|
|
|
|
|
|
|
//Settings vars
|
|
|
|
showAllSettings: true,
|
|
|
|
lastVisibilityState: null,
|
2020-02-01 14:21:22 -08:00
|
|
|
|
|
|
|
//All the squire settings
|
|
|
|
editor: null,
|
|
|
|
// pastFocusedNode: null,
|
|
|
|
usersOnNote: 0,
|
|
|
|
|
|
|
|
extraToolbarsVisible: true,
|
2019-07-19 13:51:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
noteid:function(newVal, oldVal){
|
|
|
|
|
|
|
|
if(newVal == this.currentNoteId){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newVal == oldVal){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentNoteId = newVal
|
|
|
|
this.loadNote(this.currentNoteId)
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount(){
|
2020-02-01 14:21:22 -08:00
|
|
|
this.$bus.$on('new_file_upload', ({noteId, imageCode}) => {
|
|
|
|
if(this.noteid == noteId && this.editor){
|
|
|
|
this.editor.moveCursorToEnd()
|
|
|
|
this.editor.insertHTML(imageCode)
|
|
|
|
}
|
|
|
|
})
|
2019-07-19 13:51:57 -07:00
|
|
|
},
|
|
|
|
beforeDestroy(){
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
this.$io.emit('leave_room', this.noteid)
|
|
|
|
|
|
|
|
document.removeEventListener('visibilitychange', this.checkForUpdatedNote)
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
this.editor.destroy()
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
this.$bus.$off('new_file_upload')
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
},
|
|
|
|
mounted: function() {
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
document.addEventListener('visibilitychange', this.checkForUpdatedNote)
|
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
this.$nextTick(() => {
|
2020-02-01 14:21:22 -08:00
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
this.loadNote(this.noteid)
|
2020-02-01 14:21:22 -08:00
|
|
|
|
|
|
|
//Tell server to push this note into a room
|
|
|
|
this.$io.emit('join_room', this.noteid)
|
|
|
|
|
|
|
|
this.$io.on('update_user_count', userCount => {
|
|
|
|
this.usersOnNote = userCount
|
|
|
|
})
|
|
|
|
|
|
|
|
//Server will hand deliver diffs from other notes to this one
|
|
|
|
this.$io.on('incoming_diff', incomingDiffData => {
|
|
|
|
this.patchText(incomingDiffData)
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
})
|
2020-02-01 14:21:22 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2020-02-01 14:21:22 -08:00
|
|
|
initSquire(){
|
|
|
|
|
|
|
|
//Set up squire and load note text
|
|
|
|
this.editor = new Squire( this.$refs.squirebox, {blockTag: 'p' })
|
|
|
|
this.setText(this.noteText)
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//Open links when clicked in editor
|
|
|
|
this.editor.addEventListener('click', e => {
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//Link clicked in editor - open link
|
|
|
|
if(e.target.nodeName == 'A' && e.target.href){
|
|
|
|
window.open(e.target.href)
|
|
|
|
}
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//List Item clicked in editor - toggle link state
|
|
|
|
if(e.target.nodeName == 'LI'){
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
let el = e.target
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//Adjust ofset by 40 px
|
|
|
|
let correction = 40
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//Determine if element was clicked or area before it, before means checkbox was clicked
|
|
|
|
if (e.offsetX > e.target.offsetLeft - correction) {
|
|
|
|
//Element was clicked
|
|
|
|
} else {
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//Will hide keyboard if clicked, much better for mobile
|
|
|
|
this.editor.blur()
|
2020-01-02 17:26:55 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
//Area before element was clicked, they clicked the checkbox
|
|
|
|
this.onKeyup()
|
|
|
|
if (el.className === 'active'){
|
|
|
|
el.className = 'inactive';
|
|
|
|
} else {
|
|
|
|
el.className = 'active';
|
2020-01-02 17:26:55 -08:00
|
|
|
}
|
2020-02-01 14:21:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.editor.addEventListener('keydown', event => {
|
|
|
|
|
|
|
|
//Prevent new list items from having
|
|
|
|
this.$nextTick( () => {
|
|
|
|
//Wait a moment to get item under cursor
|
|
|
|
let selection = this.editor.getSelection()
|
|
|
|
let container = selection.commonAncestorContainer
|
|
|
|
|
|
|
|
//If user hit enter on a list, make sure the next list item isn't active
|
|
|
|
if(container.nodeName == 'LI' && event.keyCode == 13 && container.classList){
|
|
|
|
container.classList.remove('active')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
//Bind event handlers
|
|
|
|
this.editor.addEventListener('keyup', event => this.onKeyup(event) )
|
|
|
|
|
|
|
|
//Show and hide additional toolbars
|
|
|
|
this.editor.addEventListener('focus', e => {
|
|
|
|
if(this.$store.getters.getIsUserOnMobile){
|
|
|
|
this.extraToolbarsVisible = false
|
2020-01-02 17:26:55 -08:00
|
|
|
}
|
2019-12-19 21:50:50 -08:00
|
|
|
})
|
2020-02-01 14:21:22 -08:00
|
|
|
this.editor.addEventListener('blur', e => {
|
|
|
|
this.save()
|
|
|
|
this.extraToolbarsVisible = true
|
|
|
|
})
|
2019-12-19 21:50:50 -08:00
|
|
|
},
|
2020-02-01 14:21:22 -08:00
|
|
|
//If nothing is selected, select the entire line
|
|
|
|
selectLineIfNoSelect(){
|
|
|
|
//Select entire line if range is not set
|
|
|
|
let selection = this.editor.getSelection()
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
if(selection.startOffset == selection.endOffset && selection.startContainer == selection.endContainer){
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
let squireRange = this.editor.createRange(
|
|
|
|
selection.startContainer, 0,
|
|
|
|
selection.endContainer, selection.commonAncestorContainer.textContent.length)
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
this.editor.setSelection(squireRange)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
modifyFont(inSize){
|
|
|
|
this.selectLineIfNoSelect()
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
let fontInfo = this.editor.getFontInfo()
|
|
|
|
//Toggle font size between large and normal
|
|
|
|
if(fontInfo.size){
|
|
|
|
this.editor.setFontSize(null)
|
|
|
|
} else {
|
|
|
|
this.editor.setFontSize(inSize)
|
|
|
|
}
|
2019-12-19 21:50:50 -08:00
|
|
|
},
|
2020-02-01 14:21:22 -08:00
|
|
|
toggleList(type){
|
|
|
|
|
|
|
|
//Undo list if its already a lits
|
|
|
|
if(this.editor.hasFormat(type)){
|
|
|
|
this.editor.removeList()
|
|
|
|
return
|
2019-12-19 21:50:50 -08:00
|
|
|
}
|
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
if(type == 'ol'){
|
|
|
|
this.editor.makeOrderedList()
|
|
|
|
}
|
|
|
|
if(type == 'ul'){
|
|
|
|
this.editor.makeUnorderedList()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleBold(){
|
|
|
|
this.selectLineIfNoSelect()
|
|
|
|
if( this.editor.hasFormat('b') ){
|
|
|
|
this.editor.removeBold()
|
|
|
|
} else {
|
|
|
|
this.editor.bold()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleItalic(){
|
|
|
|
this.selectLineIfNoSelect()
|
|
|
|
if( this.editor.hasFormat('i') ){
|
|
|
|
this.editor.removeItalic()
|
|
|
|
} else {
|
|
|
|
this.editor.italic()
|
|
|
|
}
|
2020-01-02 17:26:55 -08:00
|
|
|
},
|
|
|
|
setText(inText){
|
2020-02-01 14:21:22 -08:00
|
|
|
|
|
|
|
this.editor.setHTML(inText)
|
|
|
|
this.noteText = this.editor._getHTML()
|
|
|
|
this.diffNoteText = this.editor._getHTML()
|
2019-12-19 21:50:50 -08:00
|
|
|
},
|
|
|
|
getText(){
|
2020-02-01 14:21:22 -08:00
|
|
|
|
|
|
|
return this.editor.getHTML()
|
2019-12-19 21:50:50 -08:00
|
|
|
},
|
|
|
|
showColorPicker(event){
|
|
|
|
this.colorPickerVisible = !this.colorPickerVisible
|
|
|
|
this.colorPickerLocation = {'x':event.clientX, 'y':event.clientY}
|
|
|
|
},
|
|
|
|
openEditAttachment(){
|
|
|
|
this.$router.push('/attachments/note/'+this.currentNoteId)
|
2019-07-21 09:28:07 -07:00
|
|
|
},
|
2019-09-10 11:10:11 -07:00
|
|
|
onTogglePinned(){
|
|
|
|
if(this.pinned == 0){
|
|
|
|
this.pinned = 1
|
|
|
|
} else {
|
|
|
|
this.pinned = 0;
|
|
|
|
}
|
|
|
|
//Update last note hash, this will tell note to save next update
|
|
|
|
this.lastNoteHash = 0
|
2019-12-19 21:50:50 -08:00
|
|
|
this.save()
|
2019-09-10 11:10:11 -07:00
|
|
|
},
|
|
|
|
onToggleArchived(){
|
|
|
|
if(this.archived == 0){
|
|
|
|
this.archived = 1
|
|
|
|
} else {
|
|
|
|
this.archived = 0;
|
|
|
|
}
|
|
|
|
//Update last note hash, this will tell note to save next update
|
|
|
|
this.lastNoteHash = 0
|
2019-12-19 21:50:50 -08:00
|
|
|
this.save()
|
2019-09-10 11:10:11 -07:00
|
|
|
},
|
2020-02-01 14:21:22 -08:00
|
|
|
onCloseColorChanger(){
|
|
|
|
this.colorPickerVisible = false
|
|
|
|
},
|
2019-12-19 21:50:50 -08:00
|
|
|
onChangeColor(newStyleObject){
|
|
|
|
|
|
|
|
//Set new style object for note, page will use some styles, styles will be saved to database
|
|
|
|
this.styleObject = newStyleObject
|
|
|
|
|
2019-07-21 09:28:07 -07:00
|
|
|
this.lastNoteHash = 0 //Update hash to force note update on next save
|
|
|
|
this.save()
|
|
|
|
},
|
2019-07-19 13:51:57 -07:00
|
|
|
loadNote(noteId){
|
2019-09-10 11:10:11 -07:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
let vm = this
|
2019-09-10 11:10:11 -07:00
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
let doing = ['Loading','Loading','Getting','Fetching','Grabbing','Sequencing','Organizing','Untangling','Processing','Refining','Extracting','Fusing','Pruning','Expanding','Enlarging','Transfiguring','Quantizing','Ingratiating','Lumping']
|
2019-09-10 11:10:11 -07:00
|
|
|
let thing = ['Note','Note','Note','Note','Data','Text','Document','Algorithm','Buffer','Client','Download','File','Frame','Graphics','Hardware','HTML','Interface','Logic','Mainframe','Memory','Media','Nodes','Network','Chaos']
|
|
|
|
let p1 = doing[Math.floor(Math.random() * doing.length)]
|
|
|
|
let p2 = thing[Math.floor(Math.random() * thing.length)]
|
|
|
|
vm.loadingMessage = p1 + ' ' + p2
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
//Component is activated with NoteId in place, lookup text with associated ID
|
|
|
|
if(this.$store.getters.getLoggedIn){
|
2019-07-30 12:21:12 -07:00
|
|
|
axios.post('/api/note/get', {'noteId': noteId})
|
2019-07-19 13:51:57 -07:00
|
|
|
.then(response => {
|
2019-07-21 09:28:07 -07:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
//Set up local data
|
|
|
|
vm.currentNoteId = noteId
|
2020-02-01 14:21:22 -08:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
vm.noteText = response.data.text
|
2020-02-01 14:21:22 -08:00
|
|
|
vm.diffNoteText = response.data.text
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
vm.updated = response.data.updated
|
|
|
|
vm.lastNoteHash = vm.hashString(response.data.text)
|
2020-02-01 14:21:22 -08:00
|
|
|
//Set up note colors
|
2019-12-19 21:50:50 -08:00
|
|
|
if(response.data.color){
|
2020-02-01 14:21:22 -08:00
|
|
|
vm.styleObject = JSON.parse(response.data.color)
|
2019-12-19 21:50:50 -08:00
|
|
|
}
|
|
|
|
|
2019-09-10 11:10:11 -07:00
|
|
|
if(response.data.pinned != null){
|
|
|
|
vm.pinned = response.data.pinned
|
|
|
|
}
|
|
|
|
vm.archived = response.data.archived
|
2019-12-19 21:50:50 -08:00
|
|
|
vm.attachmentCount = response.data.attachment_count
|
2019-07-24 11:06:50 -07:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
this.loading = false
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
vm.$nextTick(() => {
|
2020-02-01 14:21:22 -08:00
|
|
|
// this.initTinyMce()
|
|
|
|
this.initSquire()
|
2019-07-19 13:51:57 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
console.log('Could not fetch note')
|
|
|
|
}
|
|
|
|
},
|
2020-02-01 14:21:22 -08:00
|
|
|
diffText(){
|
|
|
|
|
|
|
|
// dont emit to one user
|
|
|
|
if(this.usersOnNote <= 1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//Post latest diff to server, server will emit change event to all connected clients
|
|
|
|
// clearTimeout(this.emitChangeDebounce)
|
|
|
|
this.emitChangeDebounce = setTimeout(i => {
|
|
|
|
|
|
|
|
//caldulate text diff
|
|
|
|
let oldText = this.diffNoteText
|
|
|
|
let newText = this.getText()
|
|
|
|
|
|
|
|
if(oldText == newText){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const dmp = new DiffMatchPatch.diff_match_patch()
|
|
|
|
const diff = dmp.diff_main(oldText, newText)
|
|
|
|
// dmp.diff_cleanupSemantic(diff)
|
|
|
|
const patch_list = dmp.patch_make(oldText, newText, diff);
|
|
|
|
const patch_text = dmp.patch_toText(patch_list);
|
|
|
|
|
|
|
|
|
|
|
|
var patches = dmp.patch_fromText(patch_text);
|
|
|
|
var results = dmp.patch_apply(patches, oldText);
|
|
|
|
|
|
|
|
const computedText = results[0]
|
|
|
|
|
|
|
|
//Save computed diff text
|
|
|
|
this.noteText = computedText
|
|
|
|
this.diffNoteText = computedText
|
|
|
|
|
|
|
|
if(patch_text == ''){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.log(patch_text)
|
|
|
|
this.$io.emit('note_diff', {
|
|
|
|
id:this.currentNoteId,
|
|
|
|
diff:patch_text
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}, 5)
|
|
|
|
},
|
|
|
|
patchText(patch_text){
|
|
|
|
|
|
|
|
console.log(patch_text)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Capture x,y of caret and position into string
|
|
|
|
//
|
|
|
|
|
|
|
|
let currentSelection = this.editor.getSelection()
|
|
|
|
let lineText = currentSelection.startContainer.textContent
|
|
|
|
console.log(lineText)
|
|
|
|
let cursorOffset = parseInt(currentSelection.startOffset) //number of characters in
|
|
|
|
let path = this.xpath(currentSelection.commonAncestorContainer.parentElement)
|
|
|
|
console.log(path)
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//Set up text to process diff
|
|
|
|
//
|
|
|
|
|
|
|
|
let currentText = this.editor._getHTML()
|
|
|
|
const startingLines = (currentText.match(/<br>/g) || '').length + 1
|
|
|
|
console.log('1')
|
|
|
|
|
|
|
|
const dmp = new DiffMatchPatch.diff_match_patch()
|
|
|
|
var patches = dmp.patch_fromText(patch_text);
|
|
|
|
var results = dmp.patch_apply(patches, currentText);
|
|
|
|
let newText = results[0]
|
|
|
|
console.log('2')
|
|
|
|
|
|
|
|
this.noteText = newText
|
|
|
|
this.diffNoteText = newText
|
|
|
|
console.log('3')
|
|
|
|
// this.editor._setHTML(newText)
|
|
|
|
this.editor.setHTML(newText)
|
2019-07-19 13:51:57 -07:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
console.log('4')
|
|
|
|
|
|
|
|
//
|
|
|
|
// I user hasn't selected the document, we are done here
|
|
|
|
// @TODO add code to halt execution
|
|
|
|
//
|
|
|
|
|
|
|
|
const endingLines = (newText.match(/<br>/g) || '').length + 1
|
|
|
|
|
|
|
|
// if(this.pastFocusedNode != null || true){
|
|
|
|
setTimeout( ()=>{
|
|
|
|
|
|
|
|
var root = this.editor.getRoot()
|
|
|
|
//Get node under current x,y on dom (may break on scroll)
|
|
|
|
// let node = document.elementFromPoint(mouse.x, mouse.y)
|
|
|
|
let node = this.getElementByXPath(path)
|
|
|
|
|
|
|
|
if(node.firstChild){
|
|
|
|
node = node.firstChild
|
|
|
|
}
|
|
|
|
|
|
|
|
//If the number of lines changed
|
|
|
|
if(startingLines != endingLines){
|
|
|
|
|
|
|
|
//Line diff may be +1 or -1
|
|
|
|
let lineDiff = endingLines - startingLines
|
|
|
|
console.log('Line Diff => ', lineDiff)
|
|
|
|
|
|
|
|
//Pull out node number from path
|
|
|
|
var nodeNumber = path.match(/\d+/)
|
|
|
|
let modifyNode = null
|
|
|
|
if(nodeNumber.length == 1){
|
|
|
|
modifyNode = parseInt(nodeNumber[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
path = path.replace(modifyNode, modifyNode + lineDiff )
|
|
|
|
console.log(path)
|
|
|
|
let maybeNext = this.getElementByXPath(path)
|
|
|
|
if(maybeNext && maybeNext.firstChild){
|
|
|
|
maybeNext = maybeNext.firstChild
|
|
|
|
}
|
|
|
|
|
|
|
|
if(maybeNext && maybeNext.textContent == lineText){
|
|
|
|
node = maybeNext
|
|
|
|
console.log('The Node Moved!')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Targeting Node')
|
|
|
|
console.log(node)
|
|
|
|
|
|
|
|
//Create and set range
|
|
|
|
let squireRange = this.editor.createRange(node, cursorOffset)
|
|
|
|
squireRange.collapse(true)
|
|
|
|
this.editor.setSelection(squireRange)
|
|
|
|
console.log('cursor set')
|
|
|
|
|
|
|
|
}, 20)
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
xpath(el) {
|
|
|
|
//Skip things we can't use
|
|
|
|
if (typeof el == "string") return document.evaluate(el, document, null, 0, null)
|
|
|
|
if (!el || el.nodeType != 1) return ''
|
|
|
|
|
|
|
|
//Anchor xpath using Ids or test-ids
|
|
|
|
const testId = el.getAttribute('test-id')
|
|
|
|
if (el.id) return "//*[@id='" + el.id + "']"
|
|
|
|
|
|
|
|
//Continue to build path
|
|
|
|
const sames = [].filter.call(el.parentNode.children, function (x) { return x.tagName == el.tagName })
|
|
|
|
return this.xpath(el.parentNode) + '/' + el.tagName.toLowerCase() + (sames.length > 1 ? '['+([].indexOf.call(sames, el)+1)+']' : '')
|
|
|
|
},
|
|
|
|
getElementByXPath(xpath) {
|
|
|
|
return new XPathEvaluator()
|
|
|
|
.createExpression(xpath)
|
|
|
|
.evaluate(document, XPathResult.FIRST_ORDERED_NODE_TYPE) .singleNodeValue
|
|
|
|
},
|
|
|
|
onKeyup(event){
|
|
|
|
|
|
|
|
this.statusText = 'Save'
|
|
|
|
|
|
|
|
this.diffText()
|
2019-07-19 13:51:57 -07:00
|
|
|
|
2019-07-21 09:28:07 -07:00
|
|
|
//Each note, save after 5 seconds, focus lost or 30 characters typed.
|
2019-12-19 21:50:50 -08:00
|
|
|
clearTimeout(this.editDebounce)
|
|
|
|
this.editDebounce = setTimeout(() => {
|
|
|
|
this.save()
|
2019-07-21 09:28:07 -07:00
|
|
|
}, 5000)
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2019-07-29 00:22:47 -07:00
|
|
|
//Save after 30 keystrokes
|
2019-12-19 21:50:50 -08:00
|
|
|
this.keyPressesCounter = (this.keyPressesCounter + 1)
|
|
|
|
if(this.keyPressesCounter > 30){
|
|
|
|
this.keyPressesCounter = 0
|
|
|
|
this.save()
|
2019-07-21 09:28:07 -07:00
|
|
|
}
|
|
|
|
},
|
2019-07-19 13:51:57 -07:00
|
|
|
save(){
|
2019-07-29 00:22:47 -07:00
|
|
|
return new Promise((resolve, reject) => {
|
2019-12-19 21:50:50 -08:00
|
|
|
//Clear other debounced events to prevent double calling of save
|
2020-01-02 17:26:55 -08:00
|
|
|
// clearTimeout(this.editDebounce)
|
2019-07-29 00:22:47 -07:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
// return resolve(true)
|
|
|
|
|
2019-07-29 00:22:47 -07:00
|
|
|
//Don't save note if its hash doesn't change
|
2019-12-19 21:50:50 -08:00
|
|
|
const currentNoteText = this.getText()
|
|
|
|
if( this.lastNoteHash == this.hashString( currentNoteText )){
|
2020-01-02 17:26:55 -08:00
|
|
|
this.statusText = 'Saved'
|
2019-12-19 21:50:50 -08:00
|
|
|
return resolve(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
//If user accidentally clears note, it won't delete it
|
|
|
|
if(currentNoteText == ''){
|
|
|
|
this.statusText = 'Empty'
|
|
|
|
console.log('Prevented from saving empty note.')
|
|
|
|
return resolve(true)
|
2019-07-29 00:22:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const postData = {
|
|
|
|
'noteId':this.currentNoteId,
|
2019-12-19 21:50:50 -08:00
|
|
|
'text': currentNoteText,
|
|
|
|
'color': JSON.stringify(this.styleObject), //Save little json color object
|
2019-09-10 11:10:11 -07:00
|
|
|
'pinned': this.pinned,
|
|
|
|
'archived':this.archived,
|
2019-07-29 00:22:47 -07:00
|
|
|
}
|
2019-07-20 16:07:22 -07:00
|
|
|
|
2019-07-29 00:22:47 -07:00
|
|
|
let vm = this
|
2019-12-19 21:50:50 -08:00
|
|
|
//Debounce save to prevent spamming
|
|
|
|
// clearTimeout(this.saveDebounce)
|
|
|
|
// this.saveDebounce = setTimeout(() => {
|
2019-07-29 00:22:47 -07:00
|
|
|
//Only notify user if saving - may help with debugging in the future
|
|
|
|
vm.statusText = 'Saving'
|
2019-07-30 12:21:12 -07:00
|
|
|
axios.post('/api/note/update', postData).then( response => {
|
2019-07-29 00:22:47 -07:00
|
|
|
vm.statusText = 'Saved'
|
|
|
|
vm.updated = Math.round((+new Date)/1000)
|
|
|
|
|
|
|
|
//Update last saved note hash
|
2019-12-19 21:50:50 -08:00
|
|
|
vm.lastNoteHash = vm.hashString( currentNoteText )
|
|
|
|
return resolve(true)
|
2019-07-29 00:22:47 -07:00
|
|
|
})
|
2019-12-19 21:50:50 -08:00
|
|
|
// }, 300)
|
2019-07-29 00:22:47 -07:00
|
|
|
})
|
2019-07-24 11:06:50 -07:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
},
|
2020-01-02 17:26:55 -08:00
|
|
|
checkForUpdatedNote(){
|
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
// return
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
//If user leaves page then returns to page, reload the first batch
|
|
|
|
if(this.lastVisibilityState == 'hidden' && document.visibilityState == 'visible'){
|
2020-02-01 14:21:22 -08:00
|
|
|
console.log('Checking for note updates after visibility change.')
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
const postData = {
|
|
|
|
noteId:this.currentNoteId,
|
|
|
|
text:this.getText(),
|
|
|
|
updated: this.updated
|
|
|
|
}
|
|
|
|
|
|
|
|
axios.post('/api/note/difftext', postData)
|
|
|
|
.then( ({data}) => {
|
|
|
|
|
|
|
|
//Don't do anything if nothing has changed
|
|
|
|
if(data == ''){ return }
|
|
|
|
|
|
|
|
if(data.diffs > 0){
|
|
|
|
//Update text and last updated time for note
|
|
|
|
this.setText(data.updatedText)
|
|
|
|
this.updated = data.updated
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
//Track visibility state
|
|
|
|
this.lastVisibilityState = document.visibilityState
|
|
|
|
},
|
2019-07-19 13:51:57 -07:00
|
|
|
hashString(text){
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
var hash = 0;
|
2020-02-01 14:21:22 -08:00
|
|
|
if (text == null || text.length == 0) {
|
2019-07-19 13:51:57 -07:00
|
|
|
return hash;
|
|
|
|
}
|
2019-12-19 21:50:50 -08:00
|
|
|
|
|
|
|
//Simplified for speed
|
2020-02-01 14:21:22 -08:00
|
|
|
// return text.length
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
for (let i = 0; i < text.length; i++) {
|
|
|
|
let char = text.charCodeAt(i);
|
|
|
|
hash = ((hash<<5)-hash)+char;
|
|
|
|
hash = hash & hash; // Convert to 32bit integer
|
|
|
|
}
|
2019-12-19 21:50:50 -08:00
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
return hash;
|
|
|
|
},
|
|
|
|
close(){
|
2019-12-19 21:50:50 -08:00
|
|
|
|
|
|
|
// this.loading = true
|
|
|
|
// this.loadingMessage = 'Save and Close'
|
|
|
|
|
2019-07-30 13:46:24 -07:00
|
|
|
this.save().then( result => {
|
2019-12-19 21:50:50 -08:00
|
|
|
|
|
|
|
this.sizeDown = true
|
|
|
|
//This timeout allows animation to play before closing
|
|
|
|
setTimeout(() => {
|
2020-01-02 17:26:55 -08:00
|
|
|
this.$bus.$emit('close_active_note', {position: this.position, noteId: this.noteid})
|
2019-07-30 13:46:24 -07:00
|
|
|
return
|
2019-12-19 21:50:50 -08:00
|
|
|
}, 300)
|
2019-07-29 00:22:47 -07:00
|
|
|
})
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style type="text/css" scoped>
|
2019-07-21 09:28:07 -07:00
|
|
|
|
2020-02-01 14:21:22 -08:00
|
|
|
/* squire note menu button */
|
|
|
|
|
|
|
|
.note-menu {
|
|
|
|
width: 100%;
|
|
|
|
display: block;
|
|
|
|
background: #221f2b;
|
|
|
|
color: white;
|
|
|
|
overflow: hidden;
|
|
|
|
border: 1px solid #534c68;
|
|
|
|
}
|
|
|
|
.note-menu > .nm-button {
|
|
|
|
padding: 10px 10px;
|
|
|
|
cursor: pointer;
|
|
|
|
text-align: center;
|
|
|
|
box-sizing: border-box;
|
|
|
|
font-size: 1.1em;
|
|
|
|
vertical-align: middle;
|
|
|
|
/*height: 40px;*/
|
|
|
|
display: table-cell;
|
|
|
|
}
|
|
|
|
.nm-button > i {
|
|
|
|
font-size: 1.1em;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
.nm-button:hover {
|
|
|
|
background-color: #534c68;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
.nm-button + .nm-button {
|
|
|
|
border-left: 1px solid #534c68;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* squire styles */
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
/*Settings manager styles */
|
|
|
|
.all-settings {
|
2020-02-01 14:21:22 -08:00
|
|
|
/*border-top: 1px solid #534c68;*/
|
|
|
|
background: #221f2b;
|
2020-01-02 17:26:55 -08:00
|
|
|
position: absolute;
|
2020-02-01 14:21:22 -08:00
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
|
|
|
left: 0;
|
2020-01-02 17:26:55 -08:00
|
|
|
z-index: 99;
|
2020-02-01 14:21:22 -08:00
|
|
|
/*border: 1px solid;*/
|
|
|
|
/*background-color: var(--background_color);*/
|
|
|
|
/*border-color: var(--border_color);*/
|
2020-01-02 17:26:55 -08:00
|
|
|
box-sizing: border-box;
|
2020-02-01 14:21:22 -08:00
|
|
|
/*border-radius: 7px;*/
|
|
|
|
/*box-shadow: 0px 3px 7px 0px rgba(140,140,140,1);*/
|
|
|
|
/*padding: 1.2em 0 0;*/
|
|
|
|
}
|
|
|
|
.low-settings {
|
|
|
|
bottom: 0px;
|
|
|
|
cursor: pointer;
|
|
|
|
height: 1.4em;
|
|
|
|
padding-top: 1.5em;
|
|
|
|
overflow: hidden;
|
|
|
|
border: 1px solid #534c68;
|
2020-01-02 17:26:55 -08:00
|
|
|
}
|
|
|
|
/*End Settings manager styles */
|
|
|
|
|
2019-07-21 09:28:07 -07:00
|
|
|
|
|
|
|
/* container styles change based on mobile and number of open screens */
|
2019-07-19 13:51:57 -07:00
|
|
|
.master-note-edit {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 0;
|
2019-07-29 00:22:47 -07:00
|
|
|
background: var(--background_color);
|
|
|
|
/*color: var(--text_color);*/
|
2019-07-21 09:28:07 -07:00
|
|
|
height: 100vh;
|
2019-07-19 13:51:57 -07:00
|
|
|
box-shadow: 0px 0px 5px 2px rgba(140,140,140,1);
|
2019-09-10 11:10:11 -07:00
|
|
|
z-index: 1001;
|
2019-12-19 21:50:50 -08:00
|
|
|
/*overflow-x: scroll;*/
|
2019-09-10 11:10:11 -07:00
|
|
|
}
|
2020-02-01 14:21:22 -08:00
|
|
|
.padded-bottom {
|
|
|
|
padding-bottom: 20px;
|
|
|
|
}
|
2019-09-10 11:10:11 -07:00
|
|
|
.loading-note {
|
|
|
|
position: absolute;
|
2019-12-19 21:50:50 -08:00
|
|
|
top: 0;
|
2019-09-10 11:10:11 -07:00
|
|
|
left: 0;
|
|
|
|
right: 0;
|
2019-12-19 21:50:50 -08:00
|
|
|
bottom: 0;
|
2019-07-19 13:51:57 -07:00
|
|
|
}
|
2019-07-20 16:07:22 -07:00
|
|
|
/* One note open, in the middle of the screen */
|
|
|
|
.master-note-edit.position-0 {
|
2019-12-19 21:50:50 -08:00
|
|
|
left: 50%;
|
2019-09-10 11:10:11 -07:00
|
|
|
right: 0;
|
2019-07-20 16:07:22 -07:00
|
|
|
}
|
2019-07-21 09:28:07 -07:00
|
|
|
@media only screen and (max-width: 740px) {
|
|
|
|
.master-note-edit.position-0 {
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 16:07:22 -07:00
|
|
|
/* Two Notes Open, each takes up 50% of the space */
|
|
|
|
.master-note-edit.position-1 {
|
|
|
|
left: 50%;
|
|
|
|
right: 0%;
|
|
|
|
}
|
|
|
|
.master-note-edit.position-2 {
|
|
|
|
left: 0%;
|
|
|
|
right: 50%;
|
|
|
|
}
|
2019-07-19 13:51:57 -07:00
|
|
|
|
2019-07-29 00:22:47 -07:00
|
|
|
.size-down {
|
2019-07-30 13:27:26 -07:00
|
|
|
animation: size-down 0.5s ease;
|
2019-07-29 00:22:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes size-down {
|
|
|
|
0% {
|
2019-12-19 21:50:50 -08:00
|
|
|
/*opacity: 1;*/
|
|
|
|
/*top: 0;*/
|
2019-07-29 00:22:47 -07:00
|
|
|
top: 0;
|
|
|
|
}
|
|
|
|
100% {
|
2019-12-19 21:50:50 -08:00
|
|
|
/*opacity: 0;*/
|
|
|
|
/*top: 30vh;*/
|
|
|
|
top: 150vh;
|
2019-07-29 00:22:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
</style>
|