lakelib 0.1.25 → 0.2.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 +2 -2
- package/dist/lake.css +6 -0
- package/dist/lake.min.js +13 -13
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +6 -0
- package/lib/lake.js +79 -23
- package/lib/lake.js.map +1 -1
- package/lib/types/i18n/en-US/index.d.ts +1 -0
- package/lib/types/i18n/ja/index.d.ts +1 -0
- package/lib/types/i18n/ko/index.d.ts +1 -0
- package/lib/types/i18n/types.d.ts +8 -0
- package/lib/types/i18n/zh-CN/index.d.ts +1 -0
- package/lib/types/ui/slash-popup.d.ts +3 -1
- package/package.json +11 -10
package/lib/lake.css
CHANGED
|
@@ -1271,6 +1271,12 @@ lake-box[name="equation"] .lake-box-activated .lake-equation-form {
|
|
|
1271
1271
|
.lake-equation .lake-equation-form textarea:focus-visible {
|
|
1272
1272
|
outline: 0;
|
|
1273
1273
|
}
|
|
1274
|
+
.lake-equation .lake-equation-form .lake-button-row {
|
|
1275
|
+
display: flex;
|
|
1276
|
+
flex-direction: column;
|
|
1277
|
+
justify-content: space-between;
|
|
1278
|
+
align-items: flex-end;
|
|
1279
|
+
}
|
|
1274
1280
|
/* error status */
|
|
1275
1281
|
.lake-equation-error {
|
|
1276
1282
|
padding: 0 6px;
|
package/lib/lake.js
CHANGED
|
@@ -21,6 +21,8 @@ if (customElements.get('lake-bookmark') !== undefined) {
|
|
|
21
21
|
|
|
22
22
|
var plus = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm48-88a8,8,0,0,1-8,8H136v32a8,8,0,0,1-16,0V136H88a8,8,0,0,1,0-16h32V88a8,8,0,0,1,16,0v32h32A8,8,0,0,1,176,128Z\"></path></svg>";
|
|
23
23
|
|
|
24
|
+
var question = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M140,180a12,12,0,1,1-12-12A12,12,0,0,1,140,180ZM128,72c-22.06,0-40,16.15-40,36v4a8,8,0,0,0,16,0v-4c0-11,10.77-20,24-20s24,9,24,20-10.77,20-24,20a8,8,0,0,0-8,8v8a8,8,0,0,0,16,0v-.72c18.24-3.35,32-17.9,32-35.28C168,88.15,150.06,72,128,72Zm104,56A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z\"></path></svg>";
|
|
25
|
+
|
|
24
26
|
var more = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M112,60a16,16,0,1,1,16,16A16,16,0,0,1,112,60Zm16,52a16,16,0,1,0,16,16A16,16,0,0,0,128,112Zm0,68a16,16,0,1,0,16,16A16,16,0,0,0,128,180Z\"></path></svg>";
|
|
25
27
|
|
|
26
28
|
var left = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M165.66,202.34a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L91.31,128Z\"></path></svg>";
|
|
@@ -165,6 +167,7 @@ var table = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\
|
|
|
165
167
|
// basic
|
|
166
168
|
const icons = new Map([
|
|
167
169
|
['plus', plus],
|
|
170
|
+
['question', question],
|
|
168
171
|
['more', more],
|
|
169
172
|
['left', left],
|
|
170
173
|
['right', right],
|
|
@@ -1515,7 +1518,7 @@ class Range {
|
|
|
1515
1518
|
selectBox(boxNode) {
|
|
1516
1519
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1517
1520
|
if (boxContainer.length === 0) {
|
|
1518
|
-
throw new Error(`
|
|
1521
|
+
throw new Error(`Box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
|
|
1519
1522
|
}
|
|
1520
1523
|
this.setStart(boxContainer, 0);
|
|
1521
1524
|
this.collapseToStart();
|
|
@@ -1524,7 +1527,7 @@ class Range {
|
|
|
1524
1527
|
selectBoxStart(boxNode) {
|
|
1525
1528
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1526
1529
|
if (boxStrip.length === 0) {
|
|
1527
|
-
throw new Error(`
|
|
1530
|
+
throw new Error(`Box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
|
|
1528
1531
|
}
|
|
1529
1532
|
this.selectNodeContents(boxStrip.eq(0));
|
|
1530
1533
|
this.collapseToStart();
|
|
@@ -1533,7 +1536,7 @@ class Range {
|
|
|
1533
1536
|
selectBoxEnd(boxNode) {
|
|
1534
1537
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1535
1538
|
if (boxStrip.length === 0) {
|
|
1536
|
-
throw new Error(`
|
|
1539
|
+
throw new Error(`Box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
|
|
1537
1540
|
}
|
|
1538
1541
|
this.selectNodeContents(boxStrip.eq(1));
|
|
1539
1542
|
this.collapseToStart();
|
|
@@ -3005,6 +3008,7 @@ var enUS = {
|
|
|
3005
3008
|
},
|
|
3006
3009
|
equation: {
|
|
3007
3010
|
save: 'Done',
|
|
3011
|
+
help: 'Supported functions',
|
|
3008
3012
|
placeholder: 'Type a TeX expression',
|
|
3009
3013
|
},
|
|
3010
3014
|
};
|
|
@@ -3130,6 +3134,7 @@ var zhCN = {
|
|
|
3130
3134
|
},
|
|
3131
3135
|
equation: {
|
|
3132
3136
|
save: '确定',
|
|
3137
|
+
help: '支持的功能',
|
|
3133
3138
|
placeholder: '请输入 TeX 表达式',
|
|
3134
3139
|
},
|
|
3135
3140
|
};
|
|
@@ -3255,6 +3260,7 @@ var ja = {
|
|
|
3255
3260
|
},
|
|
3256
3261
|
equation: {
|
|
3257
3262
|
save: '確認',
|
|
3263
|
+
help: 'サポートされている機能',
|
|
3258
3264
|
placeholder: 'TeX 数式を入力してください。',
|
|
3259
3265
|
},
|
|
3260
3266
|
};
|
|
@@ -3380,6 +3386,7 @@ var ko = {
|
|
|
3380
3386
|
},
|
|
3381
3387
|
equation: {
|
|
3382
3388
|
save: '확인',
|
|
3389
|
+
help: '지원되는 기능',
|
|
3383
3390
|
placeholder: 'TeX 수식을 입력하세요',
|
|
3384
3391
|
},
|
|
3385
3392
|
};
|
|
@@ -3789,7 +3796,7 @@ class Box {
|
|
|
3789
3796
|
if (typeof node === 'string') {
|
|
3790
3797
|
const component = boxes.get(node);
|
|
3791
3798
|
if (component === undefined) {
|
|
3792
|
-
throw new Error(`
|
|
3799
|
+
throw new Error(`Box "${node}" has not been defined yet.`);
|
|
3793
3800
|
}
|
|
3794
3801
|
const type = encode(component.type);
|
|
3795
3802
|
const name = encode(component.name);
|
|
@@ -3802,7 +3809,7 @@ class Box {
|
|
|
3802
3809
|
this.node = query(node);
|
|
3803
3810
|
const component = boxes.get(this.name);
|
|
3804
3811
|
if (component === undefined) {
|
|
3805
|
-
throw new Error(`
|
|
3812
|
+
throw new Error(`Box "${this.name}" has not been defined yet.`);
|
|
3806
3813
|
}
|
|
3807
3814
|
if (component.value && !this.node.hasAttr('value')) {
|
|
3808
3815
|
this.value = component.value;
|
|
@@ -3833,7 +3840,7 @@ class Box {
|
|
|
3833
3840
|
container.removeClass('lake-box-hovered');
|
|
3834
3841
|
});
|
|
3835
3842
|
container.on('click', () => {
|
|
3836
|
-
debug(`
|
|
3843
|
+
debug(`Box "${this.name}" (id = ${this.node.id}) value:`);
|
|
3837
3844
|
debug(this.value);
|
|
3838
3845
|
});
|
|
3839
3846
|
if (this.type === 'block' && this.node.isContentEditable) {
|
|
@@ -3877,7 +3884,7 @@ class Box {
|
|
|
3877
3884
|
const container = this.node.closest('div[contenteditable]');
|
|
3878
3885
|
const editor = container.length > 0 ? editors.get(container.id) : undefined;
|
|
3879
3886
|
if (!editor) {
|
|
3880
|
-
throw new Error(`
|
|
3887
|
+
throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);
|
|
3881
3888
|
}
|
|
3882
3889
|
return editor;
|
|
3883
3890
|
}
|
|
@@ -3935,7 +3942,7 @@ class Box {
|
|
|
3935
3942
|
container.empty();
|
|
3936
3943
|
container.append(content);
|
|
3937
3944
|
}
|
|
3938
|
-
debug(`
|
|
3945
|
+
debug(`Box "${this.name}" (id: ${this.node.id}) rendered`);
|
|
3939
3946
|
}
|
|
3940
3947
|
// Destroys a rendered box.
|
|
3941
3948
|
unmount() {
|
|
@@ -3943,7 +3950,7 @@ class Box {
|
|
|
3943
3950
|
this.event.emit('beforeunmount');
|
|
3944
3951
|
this.event.removeAllListeners();
|
|
3945
3952
|
this.node.empty();
|
|
3946
|
-
debug(`
|
|
3953
|
+
debug(`Box "${this.name}" (id: ${this.node.id}) unmounted`);
|
|
3947
3954
|
}
|
|
3948
3955
|
// Returns a HTML string of the box.
|
|
3949
3956
|
getHTML() {
|
|
@@ -5352,7 +5359,7 @@ function removeBox(range) {
|
|
|
5352
5359
|
return box;
|
|
5353
5360
|
}
|
|
5354
5361
|
|
|
5355
|
-
var version = "0.1
|
|
5362
|
+
var version = "0.2.1";
|
|
5356
5363
|
|
|
5357
5364
|
// Returns the attributes of the element as an key-value object.
|
|
5358
5365
|
function getAttributes(node) {
|
|
@@ -5531,12 +5538,13 @@ class Selection {
|
|
|
5531
5538
|
boxNode = box;
|
|
5532
5539
|
}
|
|
5533
5540
|
this.range.selectBox(boxNode);
|
|
5541
|
+
this.sync();
|
|
5534
5542
|
}
|
|
5535
5543
|
// Inserts a box into the position of the selection.
|
|
5536
5544
|
insertBox(boxName, boxValue) {
|
|
5537
5545
|
const box = insertBox(this.range, boxName, boxValue);
|
|
5538
5546
|
if (!box) {
|
|
5539
|
-
throw new Error(`
|
|
5547
|
+
throw new Error(`Box "${boxName}" cannot be inserted outside the editor.`);
|
|
5540
5548
|
}
|
|
5541
5549
|
return box;
|
|
5542
5550
|
}
|
|
@@ -6004,7 +6012,7 @@ class Editor {
|
|
|
6004
6012
|
if (this.root.first().length === 0) {
|
|
6005
6013
|
return;
|
|
6006
6014
|
}
|
|
6007
|
-
const range = this.selection.
|
|
6015
|
+
const range = this.selection.getCurrentRange();
|
|
6008
6016
|
const clonedRange = range.clone();
|
|
6009
6017
|
clonedRange.adjustBox();
|
|
6010
6018
|
this.container.find('lake-box').each(boxNativeNode => {
|
|
@@ -6379,7 +6387,7 @@ class Editor {
|
|
|
6379
6387
|
this.overlayContainer.append(artificialCaret);
|
|
6380
6388
|
scrollToNode(artificialCaret, {
|
|
6381
6389
|
behavior: 'instant',
|
|
6382
|
-
block: '
|
|
6390
|
+
block: 'nearest',
|
|
6383
6391
|
inline: 'nearest',
|
|
6384
6392
|
});
|
|
6385
6393
|
artificialCaret.remove();
|
|
@@ -6447,7 +6455,7 @@ class Editor {
|
|
|
6447
6455
|
const unmountPlugin = this.unmountPluginMap.get(name);
|
|
6448
6456
|
if (unmountPlugin) {
|
|
6449
6457
|
unmountPlugin();
|
|
6450
|
-
debug(`
|
|
6458
|
+
debug(`Plugin "${name}" unmounted`);
|
|
6451
6459
|
}
|
|
6452
6460
|
}
|
|
6453
6461
|
if (this.toolbar) {
|
|
@@ -7236,7 +7244,13 @@ class Toolbar {
|
|
|
7236
7244
|
editor,
|
|
7237
7245
|
name: item.name,
|
|
7238
7246
|
file,
|
|
7239
|
-
onError: error =>
|
|
7247
|
+
onError: error => {
|
|
7248
|
+
fileNativeNode.value = '';
|
|
7249
|
+
editor.config.onMessage('error', error);
|
|
7250
|
+
},
|
|
7251
|
+
onSuccess: () => {
|
|
7252
|
+
fileNativeNode.value = '';
|
|
7253
|
+
},
|
|
7240
7254
|
});
|
|
7241
7255
|
}
|
|
7242
7256
|
});
|
|
@@ -8286,7 +8300,7 @@ function renderError(box) {
|
|
|
8286
8300
|
editor.selection.selectBox(box);
|
|
8287
8301
|
});
|
|
8288
8302
|
editor.config.onMessage('warning', `
|
|
8289
|
-
|
|
8303
|
+
Box "${box.name}" (id: ${box.node.id}) failed to display because window.katex was not found.
|
|
8290
8304
|
Please check if the "katex" library is added to this page.
|
|
8291
8305
|
`.trim());
|
|
8292
8306
|
}
|
|
@@ -8304,6 +8318,7 @@ var equationBox = {
|
|
|
8304
8318
|
renderError(box);
|
|
8305
8319
|
return;
|
|
8306
8320
|
}
|
|
8321
|
+
const equationConfig = editor.config.equation;
|
|
8307
8322
|
const defaultCode = (box.value.code || '').trim();
|
|
8308
8323
|
const viewNode = query('<div class="lake-equation-view" />');
|
|
8309
8324
|
rootNode.append(viewNode);
|
|
@@ -8331,7 +8346,7 @@ var equationBox = {
|
|
|
8331
8346
|
}));
|
|
8332
8347
|
box.updateValue('code', code);
|
|
8333
8348
|
});
|
|
8334
|
-
const
|
|
8349
|
+
const saveButton = new Button({
|
|
8335
8350
|
root: formNode.find('.lake-button-row'),
|
|
8336
8351
|
name: 'save',
|
|
8337
8352
|
type: 'primary',
|
|
@@ -8342,7 +8357,17 @@ var equationBox = {
|
|
|
8342
8357
|
editor.history.save();
|
|
8343
8358
|
},
|
|
8344
8359
|
});
|
|
8345
|
-
|
|
8360
|
+
saveButton.render();
|
|
8361
|
+
const helpButton = new Button({
|
|
8362
|
+
root: formNode.find('.lake-button-row'),
|
|
8363
|
+
name: 'help',
|
|
8364
|
+
icon: icons.get('question'),
|
|
8365
|
+
tooltip: editor.locale.equation.help(),
|
|
8366
|
+
onClick: () => {
|
|
8367
|
+
window.open(equationConfig.helpUrl);
|
|
8368
|
+
},
|
|
8369
|
+
});
|
|
8370
|
+
helpButton.render();
|
|
8346
8371
|
},
|
|
8347
8372
|
};
|
|
8348
8373
|
|
|
@@ -9771,6 +9796,9 @@ var equation = (editor) => {
|
|
|
9771
9796
|
if (!window.katex) {
|
|
9772
9797
|
return;
|
|
9773
9798
|
}
|
|
9799
|
+
editor.setPluginConfig('equation', {
|
|
9800
|
+
helpUrl: 'https://katex.org/docs/supported',
|
|
9801
|
+
});
|
|
9774
9802
|
if (editor.readonly) {
|
|
9775
9803
|
return;
|
|
9776
9804
|
}
|
|
@@ -10416,6 +10444,12 @@ var backspaceKey = (editor) => {
|
|
|
10416
10444
|
editor.history.save();
|
|
10417
10445
|
return;
|
|
10418
10446
|
}
|
|
10447
|
+
if ((prevNode.isMark || prevNode.name === 'a') && prevNode.isEmpty) {
|
|
10448
|
+
event.preventDefault();
|
|
10449
|
+
prevNode.remove();
|
|
10450
|
+
editor.history.save();
|
|
10451
|
+
return;
|
|
10452
|
+
}
|
|
10419
10453
|
if (prevNode.isText && prevNode.text().length === 1 && prevNode.parent().isBlock) {
|
|
10420
10454
|
event.preventDefault();
|
|
10421
10455
|
const block = prevNode.closestBlock();
|
|
@@ -10922,6 +10956,8 @@ class SlashPopup {
|
|
|
10922
10956
|
this.range = null;
|
|
10923
10957
|
this.noMouseEvent = false;
|
|
10924
10958
|
this.keyword = null;
|
|
10959
|
+
this.horizontalDirection = 'right';
|
|
10960
|
+
this.verticalDirection = 'bottom';
|
|
10925
10961
|
this.keydownListener = (event) => {
|
|
10926
10962
|
if (isKeyHotkey('escape', event)) {
|
|
10927
10963
|
event.preventDefault();
|
|
@@ -11063,7 +11099,13 @@ class SlashPopup {
|
|
|
11063
11099
|
editor,
|
|
11064
11100
|
name: item.name,
|
|
11065
11101
|
file,
|
|
11066
|
-
onError: error =>
|
|
11102
|
+
onError: error => {
|
|
11103
|
+
fileNativeNode.value = '';
|
|
11104
|
+
editor.config.onMessage('error', error);
|
|
11105
|
+
},
|
|
11106
|
+
onSuccess: () => {
|
|
11107
|
+
fileNativeNode.value = '';
|
|
11108
|
+
},
|
|
11067
11109
|
});
|
|
11068
11110
|
}
|
|
11069
11111
|
});
|
|
@@ -11102,7 +11144,7 @@ class SlashPopup {
|
|
|
11102
11144
|
}
|
|
11103
11145
|
return items;
|
|
11104
11146
|
}
|
|
11105
|
-
position() {
|
|
11147
|
+
position(keepDirection = false) {
|
|
11106
11148
|
if (!this.range) {
|
|
11107
11149
|
return;
|
|
11108
11150
|
}
|
|
@@ -11110,13 +11152,27 @@ class SlashPopup {
|
|
|
11110
11152
|
const rangeRect = this.range.get().getBoundingClientRect();
|
|
11111
11153
|
const rangeX = rangeRect.x + window.scrollX;
|
|
11112
11154
|
const rangeY = rangeRect.y + window.scrollY;
|
|
11113
|
-
if (
|
|
11155
|
+
if (!keepDirection) {
|
|
11156
|
+
if (rangeRect.x + this.container.width() > window.innerWidth) {
|
|
11157
|
+
this.horizontalDirection = 'left';
|
|
11158
|
+
}
|
|
11159
|
+
else {
|
|
11160
|
+
this.horizontalDirection = 'right';
|
|
11161
|
+
}
|
|
11162
|
+
if (rangeRect.y + rangeRect.height + this.container.height() > window.innerHeight) {
|
|
11163
|
+
this.verticalDirection = 'top';
|
|
11164
|
+
}
|
|
11165
|
+
else {
|
|
11166
|
+
this.verticalDirection = 'bottom';
|
|
11167
|
+
}
|
|
11168
|
+
}
|
|
11169
|
+
if (this.horizontalDirection === 'left') {
|
|
11114
11170
|
this.container.css('left', `${rangeX - this.container.width() + rangeRect.width}px`);
|
|
11115
11171
|
}
|
|
11116
11172
|
else {
|
|
11117
11173
|
this.container.css('left', `${rangeX}px`);
|
|
11118
11174
|
}
|
|
11119
|
-
if (
|
|
11175
|
+
if (this.verticalDirection === 'top') {
|
|
11120
11176
|
this.container.css('top', `${rangeY - this.container.height() - 5}px`);
|
|
11121
11177
|
}
|
|
11122
11178
|
else {
|
|
@@ -11146,7 +11202,7 @@ class SlashPopup {
|
|
|
11146
11202
|
if (selectedItemNode.length === 0) {
|
|
11147
11203
|
this.container.find('.lake-slash-item').eq(0).addClass('lake-slash-item-selected');
|
|
11148
11204
|
}
|
|
11149
|
-
this.position();
|
|
11205
|
+
this.position(true);
|
|
11150
11206
|
}
|
|
11151
11207
|
show(range, keyword) {
|
|
11152
11208
|
const editor = this.editor;
|