lakelib 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lake.min.js +3 -3
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.js +66 -73
- package/lib/lake.js.map +1 -1
- package/lib/types/editor.d.ts +1 -0
- package/package.json +1 -1
package/lib/lake.js
CHANGED
|
@@ -5173,7 +5173,7 @@ function removeBox(range) {
|
|
|
5173
5173
|
return box;
|
|
5174
5174
|
}
|
|
5175
5175
|
|
|
5176
|
-
var version = "0.1.
|
|
5176
|
+
var version = "0.1.22";
|
|
5177
5177
|
|
|
5178
5178
|
// Returns the attributes of the element as an key-value object.
|
|
5179
5179
|
function getAttributes(node) {
|
|
@@ -5974,60 +5974,65 @@ class Editor {
|
|
|
5974
5974
|
this.unsavedInputData = '';
|
|
5975
5975
|
this.unsavedInputCount = 0;
|
|
5976
5976
|
}
|
|
5977
|
-
//
|
|
5977
|
+
// Handles input event.
|
|
5978
|
+
handleInputEvent(event) {
|
|
5979
|
+
var _a;
|
|
5980
|
+
this.selection.updateByRange();
|
|
5981
|
+
const range = this.selection.range;
|
|
5982
|
+
if (range.isInsideBox) {
|
|
5983
|
+
return;
|
|
5984
|
+
}
|
|
5985
|
+
if (range.isBoxStart || range.isBoxEnd) {
|
|
5986
|
+
this.moveBoxStripText();
|
|
5987
|
+
this.history.save();
|
|
5988
|
+
return;
|
|
5989
|
+
}
|
|
5990
|
+
const inputType = event instanceof CompositionEvent ? 'insertText' : event.inputType;
|
|
5991
|
+
if (inputType === 'insertText') {
|
|
5992
|
+
const inputData = (_a = event.data) !== null && _a !== void 0 ? _a : '';
|
|
5993
|
+
if (inputData.length > 1) {
|
|
5994
|
+
this.history.save({
|
|
5995
|
+
inputType: 'insertText',
|
|
5996
|
+
update: false,
|
|
5997
|
+
});
|
|
5998
|
+
return;
|
|
5999
|
+
}
|
|
6000
|
+
this.unsavedInputData += inputData;
|
|
6001
|
+
this.unsavedInputCount++;
|
|
6002
|
+
if (this.unsavedInputData.length < this.config.minChangeSize) {
|
|
6003
|
+
this.history.save({
|
|
6004
|
+
inputType: 'insertText',
|
|
6005
|
+
update: this.unsavedInputCount > 1,
|
|
6006
|
+
});
|
|
6007
|
+
}
|
|
6008
|
+
else {
|
|
6009
|
+
this.history.save({
|
|
6010
|
+
inputType: 'insertText',
|
|
6011
|
+
update: true,
|
|
6012
|
+
});
|
|
6013
|
+
this.resetUnsavedInputData();
|
|
6014
|
+
}
|
|
6015
|
+
return;
|
|
6016
|
+
}
|
|
6017
|
+
this.history.save();
|
|
6018
|
+
}
|
|
6019
|
+
// Binds events about inputting text.
|
|
5978
6020
|
bindInputEvents() {
|
|
5979
6021
|
this.container.on('compositionstart', () => {
|
|
5980
6022
|
this.isComposing = true;
|
|
6023
|
+
this.container.removeClass('lake-placeholder');
|
|
5981
6024
|
});
|
|
5982
|
-
this.container.on('compositionend',
|
|
6025
|
+
this.container.on('compositionend', event => {
|
|
5983
6026
|
this.isComposing = false;
|
|
6027
|
+
this.handleInputEvent(event);
|
|
5984
6028
|
});
|
|
5985
6029
|
this.container.on('input', event => {
|
|
5986
6030
|
const inputEvent = event;
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
return;
|
|
5993
|
-
}
|
|
5994
|
-
// isComposing is false after ending composition because compositionend event has been emitted.
|
|
5995
|
-
if (this.isComposing) {
|
|
5996
|
-
if (inputEvent.inputType === 'insertCompositionText') {
|
|
5997
|
-
this.container.removeClass('lake-placeholder');
|
|
5998
|
-
}
|
|
5999
|
-
this.event.emit('input', inputEvent);
|
|
6000
|
-
return;
|
|
6001
|
-
}
|
|
6002
|
-
if (range.isBoxStart || range.isBoxEnd) {
|
|
6003
|
-
this.moveBoxStripText();
|
|
6004
|
-
this.history.save();
|
|
6005
|
-
this.event.emit('input', inputEvent);
|
|
6006
|
-
return;
|
|
6007
|
-
}
|
|
6008
|
-
if (inputEvent.inputType === 'insertText' ||
|
|
6009
|
-
inputEvent.inputType === 'insertCompositionText') {
|
|
6010
|
-
this.unsavedInputData += (_a = inputEvent.data) !== null && _a !== void 0 ? _a : '';
|
|
6011
|
-
this.unsavedInputCount++;
|
|
6012
|
-
if (this.unsavedInputData.length < this.config.minChangeSize) {
|
|
6013
|
-
this.history.save({
|
|
6014
|
-
inputType: 'insertText',
|
|
6015
|
-
update: this.unsavedInputCount > 1,
|
|
6016
|
-
});
|
|
6017
|
-
}
|
|
6018
|
-
else {
|
|
6019
|
-
this.history.save({
|
|
6020
|
-
inputType: 'insertText',
|
|
6021
|
-
update: true,
|
|
6022
|
-
});
|
|
6023
|
-
this.resetUnsavedInputData();
|
|
6024
|
-
}
|
|
6025
|
-
this.event.emit('input', inputEvent);
|
|
6026
|
-
return;
|
|
6027
|
-
}
|
|
6028
|
-
this.history.save();
|
|
6029
|
-
this.event.emit('input', inputEvent);
|
|
6030
|
-
}, 0);
|
|
6031
|
+
this.isComposing = inputEvent.isComposing;
|
|
6032
|
+
if (this.isComposing) {
|
|
6033
|
+
return;
|
|
6034
|
+
}
|
|
6035
|
+
this.handleInputEvent(event);
|
|
6031
6036
|
});
|
|
6032
6037
|
}
|
|
6033
6038
|
// Binds events about history.
|
|
@@ -6058,8 +6063,8 @@ class Editor {
|
|
|
6058
6063
|
this.history.event.on('save', (value, options) => {
|
|
6059
6064
|
this.removeBoxGarbage();
|
|
6060
6065
|
executeCommonMethods(value);
|
|
6061
|
-
this.selection.sync();
|
|
6062
6066
|
if (options.inputType !== 'insertText') {
|
|
6067
|
+
this.selection.sync();
|
|
6063
6068
|
this.resetUnsavedInputData();
|
|
6064
6069
|
}
|
|
6065
6070
|
});
|
|
@@ -6953,10 +6958,6 @@ class Toolbar {
|
|
|
6953
6958
|
tabIndex: -1,
|
|
6954
6959
|
onClick: () => {
|
|
6955
6960
|
editor.focus();
|
|
6956
|
-
const range = editor.selection.range;
|
|
6957
|
-
if (!editor.container.contains(range.commonAncestor)) {
|
|
6958
|
-
range.shrinkAfter(editor.container);
|
|
6959
|
-
}
|
|
6960
6961
|
item.onClick(editor, item.name);
|
|
6961
6962
|
},
|
|
6962
6963
|
});
|
|
@@ -7265,16 +7266,16 @@ const codeBlockBox = {
|
|
|
7265
7266
|
const boxValue = box.value;
|
|
7266
7267
|
const langItem = langItemMap.get(boxValue.lang);
|
|
7267
7268
|
const language = new Compartment();
|
|
7268
|
-
const changeHandler = (value) => {
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
};
|
|
7269
|
+
const changeHandler = debounce((value) => {
|
|
7270
|
+
editor.selection.updateByRange();
|
|
7271
|
+
if (editor.isComposing) {
|
|
7272
|
+
return;
|
|
7273
|
+
}
|
|
7274
|
+
box.updateValue('code', value);
|
|
7275
|
+
editor.history.save();
|
|
7276
|
+
}, 1, {
|
|
7277
|
+
immediate: false,
|
|
7278
|
+
});
|
|
7278
7279
|
const updateListener = EditorView.updateListener.of((update) => {
|
|
7279
7280
|
if (!update.docChanged) {
|
|
7280
7281
|
return;
|
|
@@ -7570,20 +7571,11 @@ function openFullScreen(box) {
|
|
|
7570
7571
|
}
|
|
7571
7572
|
return placeholderSrc;
|
|
7572
7573
|
});
|
|
7573
|
-
let savedRange;
|
|
7574
7574
|
lightbox.on('openingAnimationEnd', () => {
|
|
7575
|
-
savedRange = editor.selection.range;
|
|
7576
7575
|
box.event.emit('openfullscreen');
|
|
7577
7576
|
});
|
|
7578
7577
|
lightbox.on('destroy', () => {
|
|
7579
|
-
|
|
7580
|
-
if (savedRange) {
|
|
7581
|
-
// fix(image): lose focus when zooming in the iOS
|
|
7582
|
-
editor.selection.range = savedRange;
|
|
7583
|
-
editor.selection.sync();
|
|
7584
|
-
}
|
|
7585
|
-
box.event.emit('closefullscreen');
|
|
7586
|
-
}, 0);
|
|
7578
|
+
box.event.emit('closefullscreen');
|
|
7587
7579
|
});
|
|
7588
7580
|
lightbox.init();
|
|
7589
7581
|
lightbox.loadAndOpen(currentIndex);
|
|
@@ -10194,7 +10186,8 @@ var backspaceKey = (editor) => {
|
|
|
10194
10186
|
const boxNode = range.commonAncestor.closest('lake-box');
|
|
10195
10187
|
const box = getBox(boxNode);
|
|
10196
10188
|
const boxValue = box.value;
|
|
10197
|
-
if (box.name === 'codeBlock' &&
|
|
10189
|
+
if (range.isCollapsed && box.name === 'codeBlock' &&
|
|
10190
|
+
(boxValue.code === undefined || boxValue.code === '')) {
|
|
10198
10191
|
event.preventDefault();
|
|
10199
10192
|
editor.selection.removeBox(box);
|
|
10200
10193
|
editor.history.save();
|