mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-02 04:51:55 +08:00
Improved Squire WYSIWYG handling of A and IMG.
And also use Optional chaining (?.)
This commit is contained in:
parent
cad5fb6067
commit
3f3a3f9147
2 changed files with 13 additions and 22 deletions
33
dev/External/SquireUI.js
vendored
33
dev/External/SquireUI.js
vendored
|
@ -176,8 +176,8 @@ class SquireUI
|
|||
quote: {
|
||||
html: '"',
|
||||
cmd: () => {
|
||||
let parent = this.getParentNodeName('UL,OL');
|
||||
(parent && 'BLOCKQUOTE' == parent) ? squire.decreaseQuoteLevel() : squire.increaseQuoteLevel();
|
||||
let parent = squire.getSelectionClosest('UL,OL,BLOCKQUOTE')?.nodeName;
|
||||
('BLOCKQUOTE' == parent) ? squire.decreaseQuoteLevel() : squire.increaseQuoteLevel();
|
||||
},
|
||||
hint: 'Blockquote'
|
||||
},
|
||||
|
@ -198,11 +198,10 @@ class SquireUI
|
|||
link: {
|
||||
html: '🔗',
|
||||
cmd: () => {
|
||||
if ('A' === this.getParentNodeName()) {
|
||||
squire.removeLink();
|
||||
} else {
|
||||
let url = prompt("Link","https://");
|
||||
url != null && url.length && squire.makeLink(url);
|
||||
let node = squire.getSelectionClosest('A'),
|
||||
url = prompt("Link", node?.href || "https://");
|
||||
if (url != null) {
|
||||
url.length ? squire.makeLink(url) : (node && squire.removeLink());
|
||||
}
|
||||
},
|
||||
hint: 'Link'
|
||||
|
@ -210,12 +209,9 @@ class SquireUI
|
|||
imageUrl: {
|
||||
html: '🖼️',
|
||||
cmd: () => {
|
||||
if ('IMG' === this.getParentNodeName()) {
|
||||
// squire.removeLink();
|
||||
} else {
|
||||
let src = prompt("Image","https://");
|
||||
src != null && src.length && squire.insertImage(src);
|
||||
}
|
||||
let node = squire.getSelectionClosest('IMG'),
|
||||
src = prompt("Image", node?.src || "https://");
|
||||
src.length ? squire.insertImage(src) : (node && squire.detach(node));
|
||||
},
|
||||
hint: 'Image URL'
|
||||
},
|
||||
|
@ -385,15 +381,10 @@ class SquireUI
|
|||
this.squire.focus();
|
||||
}
|
||||
|
||||
getParentNodeName(selector) {
|
||||
let parent = this.squire.getSelectionClosest(selector);
|
||||
return parent ? parent.nodeName : null;
|
||||
}
|
||||
|
||||
doList(type) {
|
||||
let parent = this.getParentNodeName('UL,OL'),
|
||||
let parent = this.squire.getSelectionClosest('UL,OL')?.nodeName,
|
||||
fn = {UL:'makeUnorderedList',OL:'makeOrderedList'};
|
||||
(parent && parent == type) ? this.squire.removeList() : this.squire[fn[type]]();
|
||||
(parent == type) ? this.squire.removeList() : this.squire[fn[type]]();
|
||||
}
|
||||
|
||||
testPresenceinSelection(format, validation) {
|
||||
|
@ -412,7 +403,7 @@ class SquireUI
|
|||
}
|
||||
this.mode = mode; // 'wysiwyg' or 'plain'
|
||||
cl.add('squire-mode-'+mode);
|
||||
this.onModeChange && this.onModeChange();
|
||||
this.onModeChange?.();
|
||||
setTimeout(()=>this.focus(),1);
|
||||
}
|
||||
}
|
||||
|
|
2
vendors/squire/build/squire-raw.js
vendored
2
vendors/squire/build/squire-raw.js
vendored
|
@ -143,7 +143,7 @@ const
|
|||
return node.nodeName === tag && Object.entries(attributes).every(([k,v]) => node.getAttribute(k) === v);
|
||||
},
|
||||
getClosest = ( node, root, selector ) => {
|
||||
node = (!node || node.closest ? node : node.parentElement);
|
||||
node = (node && !node.closest) ? node.parentElement : node;
|
||||
node = node && node.closest(selector);
|
||||
return (node && root.contains(node)) ? node : null;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue