Skip to content

Commit

Permalink
Update Squire to 2.2.7
Browse files Browse the repository at this point in the history
close #6534
  • Loading branch information
murilopereirame authored and charlag committed Feb 26, 2024
1 parent 1e31cb7 commit 924d185
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 48 deletions.
67 changes: 24 additions & 43 deletions libs/squire-raw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,14 @@ var fixCursor = (node) => {
fixer = document.createTextNode("");
}
}
} else if (node instanceof Element && !node.querySelector("BR")) {
} else if ((node instanceof Element || node instanceof DocumentFragment) && !node.querySelector("BR")) {
fixer = createElement("BR");
let parent = node;
let child;
while ((child = parent.lastElementChild) && !isInline(child)) {
parent = child;
}
node = parent;
}
if (fixer) {
try {
Expand Down Expand Up @@ -1313,6 +1314,7 @@ var insertTreeFragmentIntoRange = (range, frag, root, config) => {
}
if (blockContentsAfterSplit && block) {
const tempRange = range.cloneRange();
fixCursor(blockContentsAfterSplit);
mergeWithBlock(block, blockContentsAfterSplit, tempRange, root);
range.setEnd(tempRange.endContainer, tempRange.endOffset);
}
Expand Down Expand Up @@ -1864,10 +1866,13 @@ var Space = (self, event, range) => {
const text = block.textContent?.trimEnd().replace(ZWS, "");
if (text === "*" || text === "1.") {
event.preventDefault();
self.insertPlainText(" ", false);
self._docWasChanged();
self.saveUndoState(range);
const walker = new TreeIterator(block, SHOW_TEXT);
let textNode;
while (textNode = walker.nextNode()) {
textNode.data = cantFocusEmptyTextNodes ? ZWS : "";
detach(textNode);
}
if (text === "*") {
self.makeUnorderedList();
Expand Down Expand Up @@ -1900,41 +1905,12 @@ var Space = (self, event, range) => {
};

// source/keyboard/KeyHandlers.ts
var keys = {
8: "Backspace",
9: "Tab",
13: "Enter",
27: "Escape",
32: "Space",
33: "PageUp",
34: "PageDown",
37: "ArrowLeft",
38: "ArrowUp",
39: "ArrowRight",
40: "ArrowDown",
46: "Delete",
191: "/",
219: "[",
220: "\\",
221: "]"
};
var _onKey = function (event) {
const code = event.keyCode;
let key = keys[code];
let modifiers = "";
const range = this.getSelection();
if (event.defaultPrevented) {
if (event.defaultPrevented || event.isComposing) {
return;
}
if (!key) {
key = String.fromCharCode(code).toLowerCase();
if (!/^[A-Za-z0-9]$/.test(key)) {
key = "";
}
}
if (111 < code && code < 124) {
key = "F" + (code - 111);
}
let key = event.key;
let modifiers = "";
if (key !== "Backspace" && key !== "Delete") {
if (event.altKey) {
modifiers += "Alt-";
Expand All @@ -1953,11 +1929,10 @@ var _onKey = function (event) {
modifiers += "Shift-";
}
key = modifiers + key;
const range = this.getSelection();
if (this._keyHandlers[key]) {
this._keyHandlers[key](this, event, range);
} else if (!range.collapsed && // !event.isComposing stops us from blatting Kana-Kanji conversion in
// Safari
!event.isComposing && !event.ctrlKey && !event.metaKey && (event.key || key).length === 1) {
} else if (!range.collapsed && !event.ctrlKey && !event.metaKey && key.length === 1) {
this.saveUndoState(range);
deleteContentsOfRange(range, this._root);
this._ensureBottomLine();
Expand All @@ -1970,7 +1945,7 @@ var keyHandlers = {
"Delete": Delete,
"Tab": Tab,
"Shift-Tab": ShiftTab,
"Space": Space,
" ": Space,
"ArrowLeft"(self) {
self._removeZWS();
},
Expand Down Expand Up @@ -2742,22 +2717,26 @@ var Squire = class {
* Leaves bookmark.
*/
_recordUndoState(range, replace) {
if (!this._isInUndoState || replace) {
let undoIndex = this._undoIndex;
const isInUndoState = this._isInUndoState;
if (!isInUndoState || replace) {
let undoIndex = this._undoIndex + 1;
const undoStack = this._undoStack;
const undoConfig = this._config.undo;
const undoThreshold = undoConfig.documentSizeThreshold;
const undoLimit = undoConfig.undoLimit;
if (!replace) {
undoIndex += 1;
}
if (undoIndex < this._undoStackLength) {
undoStack.length = this._undoStackLength = undoIndex;
}
if (range) {
this._saveRangeToBookmark(range);
}
if (isInUndoState) {
return this;
}
const html = this._getRawHTML();
if (replace) {
undoIndex -= 1;
}
if (undoThreshold > -1 && html.length * 2 > undoThreshold) {
if (undoLimit > -1 && undoIndex > undoLimit) {
undoStack.splice(0, undoIndex - undoLimit);
Expand Down Expand Up @@ -2925,6 +2904,7 @@ var Squire = class {
let doInsert = true;
if (isPaste) {
const event = new CustomEvent("willPaste", {
cancelable: true,
detail: {
fragment: frag
}
Expand Down Expand Up @@ -3028,6 +3008,7 @@ var Squire = class {
let doInsert = true;
if (isPaste) {
const event = new CustomEvent("willPaste", {
cancelable: true,
detail: {
text: plainText
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"luxon": "3.4.4",
"mithril": "2.2.2",
"qrcode-svg": "1.0.0",
"squire-rte": "2.2.5",
"squire-rte": "2.2.7",
"systemjs": "6.10.2",
"undici": "6.6.2",
"winreg": "1.2.4",
Expand Down

0 comments on commit 924d185

Please sign in to comment.