Updated Squire to v1.11.1

This commit is contained in:
djmaze 2021-03-05 13:40:52 +01:00
parent 43e107b0cb
commit d351ee6367
2 changed files with 15 additions and 8 deletions

View file

@ -9,7 +9,7 @@ Squire was designed to be integrated with your own UI framework, and so does not
Squire supports all reasonably recent, and even moderately old, browsers (even IE11, although this is not tested much these days).
In addition to its use at [Fastmail](https://www.fastmail.com), it is also currently used in production at [ProtonMail](https://protonmail.com/), [StartMail](https://startmail.com/), [Tutanota](https://tutanota.com), [Zoho Mail](https://www.zoho.com/mail/) and [Superhuman](https://superhuman.com/), as well as other non-mail apps (drop me a line if you're using Squire elsewhere, I'm always interested to hear about it!).
In addition to its use at [Fastmail](https://www.fastmail.com), it is also currently used in production at [ProtonMail](https://protonmail.com/), [SnappyMail](https://github.com/the-djmaze/snappymail), [StartMail](https://startmail.com/), [Tutanota](https://tutanota.com), [Zoho Mail](https://www.zoho.com/mail/) and [Superhuman](https://superhuman.com/), as well as other non-mail apps including [Google Earth](https://www.google.com/earth/) (drop me a line if you're using Squire elsewhere, I'm always interested to hear about it!).
An example UI integration can be tried at http://neilj.github.io/Squire/. Please note though, this is an out-of-date version of Squire and a slightly buggy implementation written by an intern many years ago. For a demo of the latest version with a production-level UI integration, [sign up for a free Fastmail trial](https://www.fastmail.com/signup/) :). There's also a very bare-bones integration in the repo; just clone it and open `Demo.html`. If you are reporting a bug, please report the steps to reproduce using `Demo.html`, to make sure it's not a bug in your integration.
@ -128,7 +128,7 @@ Returns self (the Squire instance).
### setKeyHandler
Adds or removes a keyboard shortcut. You can use this to override the default keyboard shortcuts (e.g. Ctrl-B for bold  see the bottom of KeyHandlers.js for the list).
Adds or removes a keyboard shortcut. You can use this to override the default keyboard shortcuts (e.g. Ctrl-B for bold see the bottom of KeyHandlers.js for the list).
This method takes two arguments:
@ -499,5 +499,3 @@ This is useful when the document needs to be changed programmatically, but those
### linkRegExp
This is the regular expression used to automatically mark up links when inserting HTML or after pressing space. You can change it if you want to use a custom regular expression for detecting links, or set to `null` to turn off link detection.

View file

@ -2562,10 +2562,13 @@ class Squire
documentSizeThreshold: -1, // -1 means no threshold
undoLimit: -1 // -1 means no limit
},
sanitizeToDOMFragment: null,
addLinks: true
}, config, true );
if ( typeof config.sanitizeToDOMFragment !== 'function' ) {
config.sanitizeToDOMFragment = null;
}
// Users may specify block tag in lower case
config.blockTag = config.blockTag.toUpperCase();
@ -3683,7 +3686,13 @@ class Squire
_setHTML ( html ) {
let root = this._root;
let node = root;
node.innerHTML = html;
let sanitizeToDOMFragment = this._config.sanitizeToDOMFragment;
if ( sanitizeToDOMFragment ) {
empty( node );
node.appendChild( sanitizeToDOMFragment( html, false, this ) );
} else {
node.innerHTML = html;
}
do {
fixCursor( node, root );
} while ( node = getNextBlock( node, root ) );
@ -3709,7 +3718,7 @@ class Squire
let div, frag, child;
// Parse HTML into DOM tree
if ( typeof sanitizeToDOMFragment === 'function' ) {
if ( sanitizeToDOMFragment ) {
frag = sanitizeToDOMFragment( html, false, this );
} else {
div = createElement( 'DIV' );
@ -3830,7 +3839,7 @@ class Squire
html = html.slice( startFragmentIndex + 20, endFragmentIndex );
}
}
if ( typeof sanitizeToDOMFragment === 'function' ) {
if ( sanitizeToDOMFragment ) {
frag = sanitizeToDOMFragment( html, isPaste, this );
} else {
// Wrap with <tr> if html contains dangling <td> tags