HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -333,7 +333,6 @@
|
||||
<script>
|
||||
import marked from "marked";
|
||||
import DOMPurify from "dompurify";
|
||||
|
||||
export default {
|
||||
created() {
|
||||
// Add a hook to make all links open a new window
|
||||
@@ -355,7 +354,6 @@ export default {
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
//cleanup
|
||||
DOMPurify.removeAllHooks();
|
||||
},
|
||||
data() {
|
||||
@@ -420,14 +418,16 @@ export default {
|
||||
return "";
|
||||
}
|
||||
//replace attachment urls with tokenized local urls
|
||||
let src = this.localVal.replace(/\[ATTACH:(.*)\]/g, function(match, p1) {
|
||||
const src = this.localVal.replace(/\[ATTACH:(.*)\]/g, function(
|
||||
match,
|
||||
p1
|
||||
) {
|
||||
return window.$gz.api.attachmentDownloadUrl(p1);
|
||||
});
|
||||
|
||||
return DOMPurify.sanitize(marked(src, { breaks: true }));
|
||||
},
|
||||
onResize() {
|
||||
// this.editAreaHeight = window.innerHeight / 2;
|
||||
this.editAreaHeight = window.innerHeight * 0.8;
|
||||
},
|
||||
toggleReveal() {
|
||||
@@ -451,10 +451,9 @@ export default {
|
||||
}
|
||||
},
|
||||
getSelectedRange(forceBlock) {
|
||||
let bodyTextArea = this.$refs.editArea.$el.querySelector("textarea");
|
||||
const bodyTextArea = this.$refs.editArea.$el.querySelector("textarea");
|
||||
this.selection.start = bodyTextArea.selectionStart;
|
||||
this.selection.end = bodyTextArea.selectionEnd;
|
||||
|
||||
//some edits only work on a block so if user is just clicked on a line then add make a selection
|
||||
if (forceBlock) {
|
||||
//add a character to selection forward if possible but if not then go backward one
|
||||
@@ -474,7 +473,7 @@ export default {
|
||||
this.selection.startOfBlock = this.selection.start;
|
||||
if (this.selection.start > 0) {
|
||||
//find linefeed prior to current start
|
||||
let indexOfLineFeed = this.localVal.lastIndexOf(
|
||||
const indexOfLineFeed = this.localVal.lastIndexOf(
|
||||
"\n",
|
||||
this.selection.start
|
||||
);
|
||||
@@ -491,14 +490,14 @@ export default {
|
||||
this.selection.endOfBlock = this.selection.end;
|
||||
if (this.selection.end > 0) {
|
||||
//find linefeed prior to current start
|
||||
let indexOfLineFeed = this.localVal.indexOf("\n", this.selection.end);
|
||||
const indexOfLineFeed = this.localVal.indexOf("\n", this.selection.end);
|
||||
if (indexOfLineFeed != -1) {
|
||||
this.selection.endOfBlock = indexOfLineFeed;
|
||||
}
|
||||
}
|
||||
},
|
||||
setSelectedRange(start, end) {
|
||||
let bodyTextArea = this.$refs.editArea.$el.querySelector("textarea");
|
||||
const bodyTextArea = this.$refs.editArea.$el.querySelector("textarea");
|
||||
bodyTextArea.setSelectionRange(start, end);
|
||||
},
|
||||
getSelectedText() {
|
||||
@@ -545,9 +544,9 @@ export default {
|
||||
//the purpose of this is only to change the selection if it's got an extra space to the right
|
||||
//because double clicking on a word with another word after it causes the space to be included
|
||||
this.getSelectedRange();
|
||||
let temp = this.getSelectedText();
|
||||
let tempTrimmed = temp.trimEnd();
|
||||
let diff = temp.length - tempTrimmed.length;
|
||||
const temp = this.getSelectedText();
|
||||
const tempTrimmed = temp.trimEnd();
|
||||
const diff = temp.length - tempTrimmed.length;
|
||||
if (diff != 0) {
|
||||
//there were some spaces so update the selection range
|
||||
//force selection to be shorter by diff
|
||||
@@ -568,7 +567,6 @@ export default {
|
||||
} else {
|
||||
return "$ayiEyeSlash";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this.currentView) {
|
||||
@@ -646,7 +644,7 @@ export default {
|
||||
case "heading":
|
||||
{
|
||||
this.getSelectedRange(true); //special forces
|
||||
let prepend = "#".repeat(ex) + " ";
|
||||
const prepend = "#".repeat(ex) + " ";
|
||||
let s = this.getSelectedBlock();
|
||||
s = s.replace(/\n/gi, "\n" + prepend);
|
||||
if (s.length > 0 && s[0] != "\n") {
|
||||
@@ -688,7 +686,7 @@ export default {
|
||||
case "ol":
|
||||
{
|
||||
if (this.selection.hasSelection) {
|
||||
let s = this.getSelectedBlock();
|
||||
const s = this.getSelectedBlock();
|
||||
let ret = "\n1. ";
|
||||
let listItem = 1;
|
||||
for (let i = 0; i < s.length; i++) {
|
||||
@@ -769,7 +767,7 @@ export default {
|
||||
if (!url.includes(":")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
let t = "[" + this.linkText + "](" + url + ")";
|
||||
const t = "[" + this.linkText + "](" + url + ")";
|
||||
// [MY Awesome LINK](www.ayanova.com)
|
||||
this.replaceSelectedText(t);
|
||||
}
|
||||
@@ -801,7 +799,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
let txt = this.imageText;
|
||||
const txt = this.imageText;
|
||||
//force it to a full url so it doesn't attempt to open it as a SPA window
|
||||
if (!url.includes(":")) {
|
||||
url = "https://" + url;
|
||||
@@ -819,11 +817,7 @@ export default {
|
||||
break;
|
||||
default:
|
||||
throw new Error(`wiki-control: ${editType} NOT IMPLEMENTED`);
|
||||
break;
|
||||
}
|
||||
|
||||
// //emit input event to parent form for dirty tracking
|
||||
// this.handleInput(this.localVal);
|
||||
},
|
||||
openLinkMenu(e) {
|
||||
e.preventDefault();
|
||||
@@ -848,18 +842,18 @@ export default {
|
||||
});
|
||||
},
|
||||
async getAttachments() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
try {
|
||||
vm.attachments = [];
|
||||
let res = await window.$gz.api.get(
|
||||
const res = await window.$gz.api.get(
|
||||
"attachment/list?ayatype=" + vm.ayaType + "&ayaid=" + vm.ayaId
|
||||
);
|
||||
if (res.error) {
|
||||
window.$gz.errorHandler.handleFormError(res.error);
|
||||
} else {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for (let i = 0; i < res.data.length; i++) {
|
||||
let o = res.data[i];
|
||||
const o = res.data[i];
|
||||
|
||||
if (
|
||||
window.$gz.util.isImageAttachment(
|
||||
@@ -884,22 +878,22 @@ export default {
|
||||
},
|
||||
async upload() {
|
||||
//similar code in attachment-control upload
|
||||
let vm = this;
|
||||
let at = {
|
||||
const vm = this;
|
||||
const at = {
|
||||
ayaId: vm.ayaId,
|
||||
ayaType: vm.ayaType,
|
||||
files: vm.uploadFiles,
|
||||
notes: ""
|
||||
};
|
||||
try {
|
||||
let res = await window.$gz.api.uploadAttachment(at);
|
||||
const res = await window.$gz.api.uploadAttachment(at);
|
||||
|
||||
if (res.error) {
|
||||
window.$gz.errorHandler.handleFormError(res.error);
|
||||
} else {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for (let i = 0; i < res.data.length; i++) {
|
||||
let o = res.data[i];
|
||||
const o = res.data[i];
|
||||
|
||||
//let them attach any file type to the wiki since it supports it anyway
|
||||
ret.push({
|
||||
@@ -914,9 +908,9 @@ export default {
|
||||
//NOW iterate upload files list and insert into wiki based on attachments
|
||||
//insert into wiki
|
||||
for (let i = 0; i < vm.uploadFiles.length; i++) {
|
||||
let upFile = vm.uploadFiles[i];
|
||||
const upFile = vm.uploadFiles[i];
|
||||
for (let j = 0; j < vm.attachments.length; j++) {
|
||||
let atFile = vm.attachments[j];
|
||||
const atFile = vm.attachments[j];
|
||||
if (upFile.name == atFile.name) {
|
||||
//found it
|
||||
this.insertUrl(atFile.url, atFile.name);
|
||||
@@ -944,7 +938,7 @@ export default {
|
||||
//if an image then put it directly in viewable, if not an image then make a link and keep as an attach
|
||||
} else {
|
||||
//maybe an url?
|
||||
let url = ev.dataTransfer.getData("text");
|
||||
const url = ev.dataTransfer.getData("text");
|
||||
this.insertUrl(url);
|
||||
}
|
||||
},
|
||||
@@ -956,7 +950,7 @@ export default {
|
||||
//it's an attachment url so fixup accordingly
|
||||
//i paramter added by gzapi::attachmentDownloadUrl function
|
||||
isImageUrl = url.includes("&i=");
|
||||
let m = url.match(/attachment\/download\/(.*)\?t=/);
|
||||
const m = url.match(/attachment\/download\/(.*)\?t=/);
|
||||
if (m.length > 1) {
|
||||
url = "[ATTACH:" + m[1] + "]";
|
||||
} else {
|
||||
@@ -993,12 +987,8 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//handle accordingly
|
||||
}
|
||||
}
|
||||
|
||||
//----------end methods----------
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user