lakelib 0.3.0 → 0.3.1
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 +3 -3
- package/dist/lake.min.js +2 -2
- package/dist/lake.min.js.map +1 -1
- package/lib/editor.d.ts +19 -19
- package/lib/lake.js +59 -48
- package/lib/lake.js.map +1 -1
- package/package.json +11 -11
package/lib/editor.d.ts
CHANGED
|
@@ -41,23 +41,23 @@ export declare class Editor {
|
|
|
41
41
|
private unsavedInputCount;
|
|
42
42
|
private state;
|
|
43
43
|
private unmountPluginMap;
|
|
44
|
-
|
|
45
|
-
static
|
|
46
|
-
static
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
container: Nodes;
|
|
52
|
-
overlayContainer: Nodes;
|
|
44
|
+
private readonly containerWrapper;
|
|
45
|
+
static readonly version: string;
|
|
46
|
+
static readonly box: BoxManager;
|
|
47
|
+
static readonly plugin: Plugin;
|
|
48
|
+
readonly root: Nodes;
|
|
49
|
+
readonly toolbar: Toolbar | undefined;
|
|
50
|
+
readonly config: Config;
|
|
51
|
+
readonly container: Nodes;
|
|
52
|
+
readonly overlayContainer: Nodes;
|
|
53
|
+
readonly event: EventEmitter;
|
|
54
|
+
readonly selection: Selection;
|
|
55
|
+
readonly command: Command;
|
|
56
|
+
readonly history: History;
|
|
57
|
+
readonly keystroke: Keystroke;
|
|
58
|
+
readonly box: BoxManager;
|
|
59
|
+
readonly readonly: boolean;
|
|
53
60
|
isComposing: boolean;
|
|
54
|
-
readonly: boolean;
|
|
55
|
-
event: EventEmitter;
|
|
56
|
-
selection: Selection;
|
|
57
|
-
command: Command;
|
|
58
|
-
history: History;
|
|
59
|
-
keystroke: Keystroke;
|
|
60
|
-
box: BoxManager;
|
|
61
61
|
popup: any;
|
|
62
62
|
constructor(config: EditorConfig);
|
|
63
63
|
private copyListener;
|
|
@@ -75,16 +75,16 @@ export declare class Editor {
|
|
|
75
75
|
private bindInputEvents;
|
|
76
76
|
private removeBoxGarbage;
|
|
77
77
|
private bindHistoryEvents;
|
|
78
|
-
get hasFocus(): boolean;
|
|
79
78
|
get locale(): TranslationFunctions;
|
|
80
|
-
fixContent(): boolean;
|
|
81
79
|
setPluginConfig(name: string, config: {
|
|
82
80
|
[key: string]: any;
|
|
83
81
|
}): void;
|
|
82
|
+
fixContent(): boolean;
|
|
84
83
|
renderBoxes(): void;
|
|
84
|
+
scrollToCursor(): void;
|
|
85
|
+
hasFocus(): boolean;
|
|
85
86
|
focus(): void;
|
|
86
87
|
blur(): void;
|
|
87
|
-
scrollToCaret(): void;
|
|
88
88
|
setValue(value: string): void;
|
|
89
89
|
getValue(): string;
|
|
90
90
|
render(): void;
|
package/lib/lake.js
CHANGED
|
@@ -1674,8 +1674,8 @@ class Range {
|
|
|
1674
1674
|
}
|
|
1675
1675
|
// Relocates the start and end points of the range for <br /> element.
|
|
1676
1676
|
// In composition mode (e.g., when a user starts entering a Chinese character using a Pinyin IME),
|
|
1677
|
-
// uncompleted text is inserted if the
|
|
1678
|
-
// To fix this bug, the
|
|
1677
|
+
// uncompleted text is inserted if the cursor is positioned behind a <br> tag.
|
|
1678
|
+
// To fix this bug, the cursor needs to be moved to the front of the <br> tag.
|
|
1679
1679
|
adjustBr() {
|
|
1680
1680
|
if (!this.isCollapsed) {
|
|
1681
1681
|
return;
|
|
@@ -5833,7 +5833,7 @@ function removeBox(range) {
|
|
|
5833
5833
|
return box;
|
|
5834
5834
|
}
|
|
5835
5835
|
|
|
5836
|
-
var version = "0.3.
|
|
5836
|
+
var version = "0.3.1";
|
|
5837
5837
|
|
|
5838
5838
|
// Converts the custom HTML tags to the special tags that can not be parsed by browser.
|
|
5839
5839
|
function denormalizeValue(value) {
|
|
@@ -7007,18 +7007,26 @@ const defaultConfig = {
|
|
|
7007
7007
|
};
|
|
7008
7008
|
class Editor {
|
|
7009
7009
|
constructor(config) {
|
|
7010
|
+
// A string that has not yet been saved to the history.
|
|
7010
7011
|
this.unsavedInputData = '';
|
|
7012
|
+
// The number of input event calls before saving to the history.
|
|
7011
7013
|
this.unsavedInputCount = 0;
|
|
7014
|
+
// The state of the current selection.
|
|
7012
7015
|
this.state = {
|
|
7013
7016
|
activeItems: [],
|
|
7014
7017
|
disabledNameMap: new Map(),
|
|
7015
7018
|
selectedNameMap: new Map(),
|
|
7016
7019
|
selectedValuesMap: new Map(),
|
|
7017
7020
|
};
|
|
7021
|
+
// The functions for unmounting plugins.
|
|
7018
7022
|
this.unmountPluginMap = new Map();
|
|
7019
|
-
|
|
7023
|
+
// Managing events.
|
|
7020
7024
|
this.event = new EventEmitter();
|
|
7025
|
+
// Managing the box components.
|
|
7021
7026
|
this.box = Editor.box;
|
|
7027
|
+
// Indicating whether a user is entering a character using a text composition system such as an Input Method Editor (IME).
|
|
7028
|
+
this.isComposing = false;
|
|
7029
|
+
// A pop-up component which is currently displayed, such as LinkPopup, MentionMenu, and SlashMenu.
|
|
7022
7030
|
this.popup = null;
|
|
7023
7031
|
this.copyListener = event => {
|
|
7024
7032
|
const range = this.selection.getCurrentRange();
|
|
@@ -7310,7 +7318,7 @@ class Editor {
|
|
|
7310
7318
|
}
|
|
7311
7319
|
this.emitStateChangeEvent();
|
|
7312
7320
|
this.togglePlaceholderClass(value);
|
|
7313
|
-
this.
|
|
7321
|
+
this.scrollToCursor();
|
|
7314
7322
|
this.event.emit('change', value);
|
|
7315
7323
|
};
|
|
7316
7324
|
this.history.event.on('undo', value => {
|
|
@@ -7332,19 +7340,22 @@ class Editor {
|
|
|
7332
7340
|
}
|
|
7333
7341
|
});
|
|
7334
7342
|
}
|
|
7335
|
-
// Returns a boolean value indicating whether the editor is focused.
|
|
7336
|
-
get hasFocus() {
|
|
7337
|
-
const activeElement = document.activeElement;
|
|
7338
|
-
if (!activeElement) {
|
|
7339
|
-
return false;
|
|
7340
|
-
}
|
|
7341
|
-
return query(activeElement).closest('.lake-container').get(0) === this.container.get(0);
|
|
7342
|
-
}
|
|
7343
7343
|
// Returns translation functions for the specified language.
|
|
7344
7344
|
get locale() {
|
|
7345
7345
|
return i18nObject(this.config.lang);
|
|
7346
7346
|
}
|
|
7347
|
-
//
|
|
7347
|
+
// Sets the default config for the specified plugin.
|
|
7348
|
+
setPluginConfig(name, config) {
|
|
7349
|
+
if (typeof this.config[name] !== 'object') {
|
|
7350
|
+
this.config[name] = {};
|
|
7351
|
+
}
|
|
7352
|
+
for (const key of Object.keys(config)) {
|
|
7353
|
+
if (this.config[name][key] === undefined) {
|
|
7354
|
+
this.config[name][key] = config[key];
|
|
7355
|
+
}
|
|
7356
|
+
}
|
|
7357
|
+
}
|
|
7358
|
+
// Fixes incorrect content, such as adding paragraphs for void elements or removing empty tags.
|
|
7348
7359
|
fixContent() {
|
|
7349
7360
|
const range = this.selection.range;
|
|
7350
7361
|
const cellNode = range.commonAncestor.closest('td');
|
|
@@ -7379,17 +7390,6 @@ class Editor {
|
|
|
7379
7390
|
range.adjustBr();
|
|
7380
7391
|
return changed;
|
|
7381
7392
|
}
|
|
7382
|
-
// Sets default config for a plugin.
|
|
7383
|
-
setPluginConfig(name, config) {
|
|
7384
|
-
if (typeof this.config[name] !== 'object') {
|
|
7385
|
-
this.config[name] = {};
|
|
7386
|
-
}
|
|
7387
|
-
for (const key of Object.keys(config)) {
|
|
7388
|
-
if (this.config[name][key] === undefined) {
|
|
7389
|
-
this.config[name][key] = config[key];
|
|
7390
|
-
}
|
|
7391
|
-
}
|
|
7392
|
-
}
|
|
7393
7393
|
// Renders all boxes that haven't been rendered yet.
|
|
7394
7394
|
renderBoxes() {
|
|
7395
7395
|
this.removeBoxGarbage();
|
|
@@ -7404,34 +7404,22 @@ class Editor {
|
|
|
7404
7404
|
box.render();
|
|
7405
7405
|
});
|
|
7406
7406
|
}
|
|
7407
|
-
//
|
|
7408
|
-
|
|
7409
|
-
const range = this.selection.range;
|
|
7410
|
-
if (this.container.contains(range.commonAncestor) && range.isBox) {
|
|
7411
|
-
return;
|
|
7412
|
-
}
|
|
7413
|
-
this.container.focus();
|
|
7414
|
-
}
|
|
7415
|
-
// Removes focus from the editor.
|
|
7416
|
-
blur() {
|
|
7417
|
-
this.container.blur();
|
|
7418
|
-
}
|
|
7419
|
-
// Scrolls to the caret or the range of the selection.
|
|
7420
|
-
scrollToCaret() {
|
|
7407
|
+
// Scrolls to the cursor.
|
|
7408
|
+
scrollToCursor() {
|
|
7421
7409
|
const range = this.selection.range;
|
|
7422
7410
|
if (range.isBox) {
|
|
7423
7411
|
return;
|
|
7424
7412
|
}
|
|
7425
|
-
// Creates an artificial
|
|
7413
|
+
// Creates an artificial cursor that is the same size as the cursor at the current cursor position.
|
|
7426
7414
|
const rangeRect = range.getRect();
|
|
7427
7415
|
if (rangeRect.x === 0 || rangeRect.y === 0) {
|
|
7428
7416
|
return;
|
|
7429
7417
|
}
|
|
7430
7418
|
const containerRect = this.container.get(0).getBoundingClientRect();
|
|
7431
|
-
const
|
|
7419
|
+
const artificialCursor = query('<div class="lake-artificial-cursor" />');
|
|
7432
7420
|
const left = rangeRect.x - containerRect.x;
|
|
7433
7421
|
const top = rangeRect.y - containerRect.y;
|
|
7434
|
-
|
|
7422
|
+
artificialCursor.css({
|
|
7435
7423
|
position: 'absolute',
|
|
7436
7424
|
top: `${top}px`,
|
|
7437
7425
|
left: `${left}px`,
|
|
@@ -7440,14 +7428,34 @@ class Editor {
|
|
|
7440
7428
|
// background: 'red',
|
|
7441
7429
|
'z-index': '-1',
|
|
7442
7430
|
});
|
|
7443
|
-
this.overlayContainer.find('.lake-artificial-
|
|
7444
|
-
this.overlayContainer.append(
|
|
7445
|
-
scrollToNode(
|
|
7431
|
+
this.overlayContainer.find('.lake-artificial-cursor').remove();
|
|
7432
|
+
this.overlayContainer.append(artificialCursor);
|
|
7433
|
+
scrollToNode(artificialCursor, {
|
|
7446
7434
|
behavior: 'instant',
|
|
7447
7435
|
block: 'nearest',
|
|
7448
7436
|
inline: 'nearest',
|
|
7449
7437
|
});
|
|
7450
|
-
|
|
7438
|
+
artificialCursor.remove();
|
|
7439
|
+
}
|
|
7440
|
+
// Checks whether the editor has focus.
|
|
7441
|
+
hasFocus() {
|
|
7442
|
+
const activeElement = document.activeElement;
|
|
7443
|
+
if (!activeElement) {
|
|
7444
|
+
return false;
|
|
7445
|
+
}
|
|
7446
|
+
return query(activeElement).closest('.lake-container').get(0) === this.container.get(0);
|
|
7447
|
+
}
|
|
7448
|
+
// Sets focus on the editor.
|
|
7449
|
+
focus() {
|
|
7450
|
+
const range = this.selection.range;
|
|
7451
|
+
if (this.container.contains(range.commonAncestor) && range.isBox) {
|
|
7452
|
+
return;
|
|
7453
|
+
}
|
|
7454
|
+
this.container.focus();
|
|
7455
|
+
}
|
|
7456
|
+
// Removes focus from the editor.
|
|
7457
|
+
blur() {
|
|
7458
|
+
this.container.blur();
|
|
7451
7459
|
}
|
|
7452
7460
|
// Sets the specified content to the editor.
|
|
7453
7461
|
setValue(value) {
|
|
@@ -7467,7 +7475,7 @@ class Editor {
|
|
|
7467
7475
|
value = denormalizeValue(value);
|
|
7468
7476
|
return value;
|
|
7469
7477
|
}
|
|
7470
|
-
// Renders an
|
|
7478
|
+
// Renders an editing area and sets default content to it.
|
|
7471
7479
|
render() {
|
|
7472
7480
|
const value = normalizeValue(this.config.value);
|
|
7473
7481
|
const htmlParser = new HTMLParser(value);
|
|
@@ -7534,8 +7542,11 @@ class Editor {
|
|
|
7534
7542
|
}
|
|
7535
7543
|
}
|
|
7536
7544
|
}
|
|
7545
|
+
// the current version of Lake.
|
|
7537
7546
|
Editor.version = version;
|
|
7547
|
+
// Managing the box components.
|
|
7538
7548
|
Editor.box = new BoxManager();
|
|
7549
|
+
// Managing the plugins.
|
|
7539
7550
|
Editor.plugin = new Plugin();
|
|
7540
7551
|
|
|
7541
7552
|
var copy = (editor) => {
|
|
@@ -12627,7 +12638,7 @@ var escapeKey = (editor) => {
|
|
|
12627
12638
|
selection.sync();
|
|
12628
12639
|
return;
|
|
12629
12640
|
}
|
|
12630
|
-
if (editor.hasFocus) {
|
|
12641
|
+
if (editor.hasFocus()) {
|
|
12631
12642
|
event.preventDefault();
|
|
12632
12643
|
editor.blur();
|
|
12633
12644
|
}
|