lakelib 0.0.5 → 0.0.6
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/README.md +2 -2
- package/dist/lake.min.js +20 -20
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.js +59 -24
- package/lib/lake.js.map +1 -1
- package/lib/types/editor.d.ts +1 -0
- package/lib/types/managers/history.d.ts +1 -1
- package/lib/types/types/object.d.ts +6 -0
- package/lib/types/ui/toolbar.d.ts +2 -8
- package/package.json +18 -13
package/lib/lake.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Base64 } from 'js-base64';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
3
|
import debounce from 'lodash/debounce';
|
|
4
|
+
import isEqual from 'lodash/isEqual';
|
|
4
5
|
import md5 from 'blueimp-md5';
|
|
5
6
|
import { createKeybindingsHandler } from 'tinykeys';
|
|
6
7
|
import { i18nObject as i18nObject$1 } from 'typesafe-i18n';
|
|
@@ -1392,7 +1393,7 @@ class Range {
|
|
|
1392
1393
|
throw new Error(`The box cannot be selected because the box '${boxNode.attr('name')}' (id=${boxNode.id}) has not been rendered yet.`);
|
|
1393
1394
|
}
|
|
1394
1395
|
this.selectNodeContents(boxStrip.eq(0));
|
|
1395
|
-
this.
|
|
1396
|
+
this.collapseToStart();
|
|
1396
1397
|
}
|
|
1397
1398
|
// Sets the range to the start position of the box.
|
|
1398
1399
|
selectBoxEnd(boxNode) {
|
|
@@ -1401,7 +1402,7 @@ class Range {
|
|
|
1401
1402
|
throw new Error(`The box cannot be selected because the box '${boxNode.attr('name')}' (id=${boxNode.id}) has not been rendered yet.`);
|
|
1402
1403
|
}
|
|
1403
1404
|
this.selectNodeContents(boxStrip.eq(1));
|
|
1404
|
-
this.
|
|
1405
|
+
this.collapseToStart();
|
|
1405
1406
|
}
|
|
1406
1407
|
// Collapses the range and sets the range to the beginning of the contents of the specified node.
|
|
1407
1408
|
shrinkBefore(node) {
|
|
@@ -4294,7 +4295,7 @@ class Dropdown {
|
|
|
4294
4295
|
}
|
|
4295
4296
|
}
|
|
4296
4297
|
|
|
4297
|
-
var version = "0.0.
|
|
4298
|
+
var version = "0.0.6";
|
|
4298
4299
|
|
|
4299
4300
|
// Inserts a box into the specified range.
|
|
4300
4301
|
function insertBox(range, boxName, boxValue) {
|
|
@@ -4742,7 +4743,7 @@ class History {
|
|
|
4742
4743
|
pause() {
|
|
4743
4744
|
this.canSave = false;
|
|
4744
4745
|
}
|
|
4745
|
-
save() {
|
|
4746
|
+
save(emitSaveEvent = true) {
|
|
4746
4747
|
if (!this.canSave) {
|
|
4747
4748
|
return;
|
|
4748
4749
|
}
|
|
@@ -4758,7 +4759,9 @@ class History {
|
|
|
4758
4759
|
this.list.shift();
|
|
4759
4760
|
this.index = this.list.length;
|
|
4760
4761
|
}
|
|
4761
|
-
|
|
4762
|
+
if (emitSaveEvent) {
|
|
4763
|
+
this.event.emit('save', denormalizeValue(value));
|
|
4764
|
+
}
|
|
4762
4765
|
debug(`History saved, the last index is ${this.index}`);
|
|
4763
4766
|
}
|
|
4764
4767
|
}
|
|
@@ -4902,11 +4905,17 @@ const defaultConfig = {
|
|
|
4902
4905
|
class Editor {
|
|
4903
4906
|
constructor(config) {
|
|
4904
4907
|
this.unsavedInputData = '';
|
|
4908
|
+
this.stateData = {
|
|
4909
|
+
appliedItems: [],
|
|
4910
|
+
disabledNameMap: new Map(),
|
|
4911
|
+
selectedNameMap: new Map(),
|
|
4912
|
+
selectedValuesMap: new Map(),
|
|
4913
|
+
};
|
|
4905
4914
|
this.isComposing = false;
|
|
4906
4915
|
this.event = new EventEmitter();
|
|
4907
4916
|
this.box = Editor.box;
|
|
4908
4917
|
this.beforeunloadListener = () => {
|
|
4909
|
-
this.
|
|
4918
|
+
this.history.save();
|
|
4910
4919
|
};
|
|
4911
4920
|
this.selectionchangeListener = () => {
|
|
4912
4921
|
this.selection.syncByRange();
|
|
@@ -5002,10 +5011,14 @@ class Editor {
|
|
|
5002
5011
|
selectedNameMap,
|
|
5003
5012
|
selectedValuesMap,
|
|
5004
5013
|
};
|
|
5014
|
+
if (isEqual(stateData, this.stateData)) {
|
|
5015
|
+
return;
|
|
5016
|
+
}
|
|
5005
5017
|
if (this.toolbar) {
|
|
5006
5018
|
this.toolbar.updateState(stateData);
|
|
5007
5019
|
}
|
|
5008
5020
|
this.event.emit('statechange', stateData);
|
|
5021
|
+
this.stateData = stateData;
|
|
5009
5022
|
}, 100, {
|
|
5010
5023
|
leading: false,
|
|
5011
5024
|
trailing: true,
|
|
@@ -5076,11 +5089,18 @@ class Editor {
|
|
|
5076
5089
|
this.container.on('compositionend', () => {
|
|
5077
5090
|
this.isComposing = false;
|
|
5078
5091
|
});
|
|
5079
|
-
this.container.on('beforeinput',
|
|
5092
|
+
this.container.on('beforeinput', event => {
|
|
5093
|
+
const inputEvent = event;
|
|
5080
5094
|
const range = this.selection.range;
|
|
5081
5095
|
if (range.isBoxStart || range.isBoxEnd) {
|
|
5082
5096
|
this.commitUnsavedInputData();
|
|
5097
|
+
return;
|
|
5098
|
+
}
|
|
5099
|
+
if (inputEvent.inputType === 'insertText' ||
|
|
5100
|
+
inputEvent.inputType === 'insertCompositionText') {
|
|
5101
|
+
return;
|
|
5083
5102
|
}
|
|
5103
|
+
this.commitUnsavedInputData();
|
|
5084
5104
|
});
|
|
5085
5105
|
this.container.on('input', event => {
|
|
5086
5106
|
const inputEvent = event;
|
|
@@ -5096,21 +5116,22 @@ class Editor {
|
|
|
5096
5116
|
this.event.emit('input', inputEvent);
|
|
5097
5117
|
return;
|
|
5098
5118
|
}
|
|
5119
|
+
if (range.isBoxStart || range.isBoxEnd) {
|
|
5120
|
+
this.inputInBoxStrip();
|
|
5121
|
+
this.history.save();
|
|
5122
|
+
this.event.emit('input', inputEvent);
|
|
5123
|
+
return;
|
|
5124
|
+
}
|
|
5099
5125
|
if (inputEvent.inputType === 'insertText' ||
|
|
5100
5126
|
inputEvent.inputType === 'insertCompositionText') {
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
if (this.unsavedInputData.length < this.config.minChangeSize) {
|
|
5107
|
-
this.event.emit('input', inputEvent);
|
|
5108
|
-
return;
|
|
5109
|
-
}
|
|
5127
|
+
this.unsavedInputData += (_a = inputEvent.data) !== null && _a !== void 0 ? _a : '';
|
|
5128
|
+
if (this.unsavedInputData.length < this.config.minChangeSize) {
|
|
5129
|
+
this.event.emit('input', inputEvent);
|
|
5130
|
+
this.emitChangeEvent(this.getValue());
|
|
5131
|
+
return;
|
|
5110
5132
|
}
|
|
5111
5133
|
}
|
|
5112
5134
|
this.history.save();
|
|
5113
|
-
this.unsavedInputData = '';
|
|
5114
5135
|
this.event.emit('input', inputEvent);
|
|
5115
5136
|
}, 0);
|
|
5116
5137
|
});
|
|
@@ -5168,7 +5189,7 @@ class Editor {
|
|
|
5168
5189
|
// Saves the input data which is unsaved.
|
|
5169
5190
|
commitUnsavedInputData() {
|
|
5170
5191
|
if (this.unsavedInputData.length > 0) {
|
|
5171
|
-
this.history.save();
|
|
5192
|
+
this.history.save(false);
|
|
5172
5193
|
this.unsavedInputData = '';
|
|
5173
5194
|
}
|
|
5174
5195
|
}
|
|
@@ -6374,9 +6395,9 @@ class Toolbar {
|
|
|
6374
6395
|
});
|
|
6375
6396
|
}
|
|
6376
6397
|
// Updates state of each item such as disabled, selected.
|
|
6377
|
-
updateState(
|
|
6398
|
+
updateState(stateData) {
|
|
6378
6399
|
var _a;
|
|
6379
|
-
const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } =
|
|
6400
|
+
const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = stateData;
|
|
6380
6401
|
for (const item of this.buttonItemList) {
|
|
6381
6402
|
const selectedClass = 'lake-button-selected';
|
|
6382
6403
|
const buttonNode = this.container.find(`button[name="${item.name}"]`);
|
|
@@ -6645,6 +6666,7 @@ function openFullScreen(box) {
|
|
|
6645
6666
|
dataSource,
|
|
6646
6667
|
mainClass: 'lake-pswp',
|
|
6647
6668
|
zoom: false,
|
|
6669
|
+
returnFocus: false,
|
|
6648
6670
|
arrowPrevSVG: icons.get('left'),
|
|
6649
6671
|
arrowNextSVG: icons.get('right'),
|
|
6650
6672
|
closeSVG: icons.get('close'),
|
|
@@ -6699,6 +6721,9 @@ function openFullScreen(box) {
|
|
|
6699
6721
|
lightbox.on('openingAnimationEnd', () => {
|
|
6700
6722
|
box.event.emit('openfullscreen');
|
|
6701
6723
|
});
|
|
6724
|
+
lightbox.on('closingAnimationEnd', () => {
|
|
6725
|
+
box.event.emit('closefullscreen');
|
|
6726
|
+
});
|
|
6702
6727
|
lightbox.init();
|
|
6703
6728
|
lightbox.loadAndOpen(currentIndex);
|
|
6704
6729
|
}
|
|
@@ -7952,9 +7977,10 @@ class LinkPopup {
|
|
|
7952
7977
|
if (!this.linkNode) {
|
|
7953
7978
|
return;
|
|
7954
7979
|
}
|
|
7980
|
+
const linkNode = this.linkNode;
|
|
7955
7981
|
this.save();
|
|
7956
7982
|
this.hide();
|
|
7957
|
-
this.event.emit('save');
|
|
7983
|
+
this.event.emit('save', linkNode);
|
|
7958
7984
|
},
|
|
7959
7985
|
});
|
|
7960
7986
|
button.render();
|
|
@@ -7970,9 +7996,10 @@ class LinkPopup {
|
|
|
7970
7996
|
if (!this.linkNode) {
|
|
7971
7997
|
return;
|
|
7972
7998
|
}
|
|
7999
|
+
const lastChild = this.linkNode.last();
|
|
7973
8000
|
this.linkNode.remove(true);
|
|
7974
8001
|
this.hide();
|
|
7975
|
-
this.event.emit('remove');
|
|
8002
|
+
this.event.emit('remove', lastChild);
|
|
7976
8003
|
},
|
|
7977
8004
|
});
|
|
7978
8005
|
button.render();
|
|
@@ -8068,10 +8095,18 @@ class LinkPopup {
|
|
|
8068
8095
|
|
|
8069
8096
|
var link = (editor) => {
|
|
8070
8097
|
const popup = new LinkPopup(editor.popupContainer);
|
|
8071
|
-
popup.event.on('save',
|
|
8098
|
+
popup.event.on('save', node => {
|
|
8099
|
+
const range = editor.selection.range;
|
|
8100
|
+
range.setStartAfter(node);
|
|
8101
|
+
range.collapseToStart();
|
|
8102
|
+
editor.selection.addRangeToNativeSelection();
|
|
8072
8103
|
editor.history.save();
|
|
8073
8104
|
});
|
|
8074
|
-
popup.event.on('remove',
|
|
8105
|
+
popup.event.on('remove', node => {
|
|
8106
|
+
const range = editor.selection.range;
|
|
8107
|
+
range.setStartAfter(node);
|
|
8108
|
+
range.collapseToStart();
|
|
8109
|
+
editor.selection.addRangeToNativeSelection();
|
|
8075
8110
|
editor.history.save();
|
|
8076
8111
|
});
|
|
8077
8112
|
editor.root.on('scroll', () => {
|