lakelib 0.3.10 → 0.4.0
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 +1 -1
- package/dist/lake.min.css +2 -2
- package/dist/lake.min.js +27 -27
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +7 -1
- package/lib/lake.d.ts +12 -9
- package/lib/lake.js +127 -85
- package/lib/lake.js.map +1 -1
- package/package.json +15 -13
package/lib/lake.css
CHANGED
|
@@ -444,7 +444,7 @@ button.lake-primary-button.lake-button-hovered {
|
|
|
444
444
|
.lake-dropdown-menu {
|
|
445
445
|
position: absolute;
|
|
446
446
|
top: 30px;
|
|
447
|
-
|
|
447
|
+
right: 0;
|
|
448
448
|
z-index: var(--lake-popup-z-index);
|
|
449
449
|
list-style: none;
|
|
450
450
|
margin: 0;
|
|
@@ -1088,6 +1088,12 @@ button.lake-primary-button.lake-button-hovered {
|
|
|
1088
1088
|
user-select: none;
|
|
1089
1089
|
}
|
|
1090
1090
|
|
|
1091
|
+
.lake-toolbar .lake-toolbar-line-break {
|
|
1092
|
+
flex-basis: 100%;
|
|
1093
|
+
height: 0;
|
|
1094
|
+
user-select: none;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1091
1097
|
.lake-toolbar .lake-upload {
|
|
1092
1098
|
line-height: 0;
|
|
1093
1099
|
}
|
package/lib/lake.d.ts
CHANGED
|
@@ -1367,6 +1367,11 @@ declare class Selection {
|
|
|
1367
1367
|
* Returns a list of items related to the current selection.
|
|
1368
1368
|
*/
|
|
1369
1369
|
getActiveItems(): ActiveItem[];
|
|
1370
|
+
/**
|
|
1371
|
+
* Creates a deep clone of the current container with its content.
|
|
1372
|
+
* If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
|
|
1373
|
+
*/
|
|
1374
|
+
cloneContainer(): Nodes;
|
|
1370
1375
|
/**
|
|
1371
1376
|
* Inserts a bookmark at the cursor position or a pair of bookmarks at the selection boundaries.
|
|
1372
1377
|
*/
|
|
@@ -1520,11 +1525,6 @@ declare class History {
|
|
|
1520
1525
|
* A boolean value indicating whether the history can be redone.
|
|
1521
1526
|
*/
|
|
1522
1527
|
get canRedo(): boolean;
|
|
1523
|
-
/**
|
|
1524
|
-
* Creates a deep clone of the current container with its content.
|
|
1525
|
-
* If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
|
|
1526
|
-
*/
|
|
1527
|
-
cloneContainer(): Nodes;
|
|
1528
1528
|
/**
|
|
1529
1529
|
* Undoes to the previous saved content.
|
|
1530
1530
|
*/
|
|
@@ -1691,7 +1691,7 @@ declare class Toolbar {
|
|
|
1691
1691
|
*/
|
|
1692
1692
|
container: Nodes;
|
|
1693
1693
|
constructor(config: ToolbarConfig);
|
|
1694
|
-
private
|
|
1694
|
+
private appendDivision;
|
|
1695
1695
|
private appendNormalButton;
|
|
1696
1696
|
private appendDropdown;
|
|
1697
1697
|
private appendUploadButton;
|
|
@@ -1709,7 +1709,8 @@ declare class Toolbar {
|
|
|
1709
1709
|
unmount(): void;
|
|
1710
1710
|
}
|
|
1711
1711
|
|
|
1712
|
-
type
|
|
1712
|
+
type ShowMessage = (type: 'success' | 'error' | 'warning', message: string) => void;
|
|
1713
|
+
type DownloadFile = (type: 'image' | 'file', url: string) => void;
|
|
1713
1714
|
interface Config {
|
|
1714
1715
|
value: string;
|
|
1715
1716
|
readonly: boolean;
|
|
@@ -1721,7 +1722,8 @@ interface Config {
|
|
|
1721
1722
|
contentRules: ContentRules;
|
|
1722
1723
|
minChangeSize: number;
|
|
1723
1724
|
historySize: number;
|
|
1724
|
-
|
|
1725
|
+
showMessage: ShowMessage;
|
|
1726
|
+
downloadFile: DownloadFile;
|
|
1725
1727
|
[name: string]: any;
|
|
1726
1728
|
}
|
|
1727
1729
|
interface EditorConfig extends Partial<Config> {
|
|
@@ -2261,4 +2263,5 @@ declare class Dropdown {
|
|
|
2261
2263
|
unmount(): void;
|
|
2262
2264
|
}
|
|
2263
2265
|
|
|
2264
|
-
export {
|
|
2266
|
+
export { Box, Button, Dropdown, Editor, Fragment, HTMLParser, Nodes, Range$1 as Range, TextParser, Toolbar, addMark, createIframeBox, deleteContents, getBox, getContentRules, icons, insertBlock, insertBookmark, insertBox, insertContents, query, removeBox, removeMark, setBlocks, splitBlock, splitMarks, template, toBookmark, toHex };
|
|
2267
|
+
export type { ActiveItem, BoxComponent, BoxValue, CommandItem, ContentRules, DropdownItem, DropdownMenuItem, InitializePlugin, KeyValue, MentionItem, NodePath, SelectionState, SlashButtonItem, SlashItem, SlashUploadItem, ToolbarButtonItem, ToolbarDropdownItem, ToolbarItem, ToolbarUploadItem, UnmountPlugin };
|
package/lib/lake.js
CHANGED
|
@@ -1268,15 +1268,10 @@ class Nodes {
|
|
|
1268
1268
|
var _a;
|
|
1269
1269
|
if (value === undefined) {
|
|
1270
1270
|
const node = this.get(0);
|
|
1271
|
-
|
|
1272
|
-
return (_a = node.nodeValue) !== null && _a !== void 0 ? _a : '';
|
|
1273
|
-
}
|
|
1274
|
-
const element = node;
|
|
1275
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
|
|
1276
|
-
return element.innerText.replace(/^\n+|\n+$/, '');
|
|
1271
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : '';
|
|
1277
1272
|
}
|
|
1278
1273
|
return this.eachElement(element => {
|
|
1279
|
-
element.
|
|
1274
|
+
element.textContent = value;
|
|
1280
1275
|
});
|
|
1281
1276
|
}
|
|
1282
1277
|
value(value) {
|
|
@@ -3104,12 +3099,12 @@ function request(option) {
|
|
|
3104
3099
|
formData.append(key, value);
|
|
3105
3100
|
});
|
|
3106
3101
|
if (option.file) {
|
|
3107
|
-
const
|
|
3102
|
+
const fieldName = option.fieldName || 'file';
|
|
3108
3103
|
if (option.file instanceof Blob) {
|
|
3109
|
-
formData.append(
|
|
3104
|
+
formData.append(fieldName, option.file, option.file.name);
|
|
3110
3105
|
}
|
|
3111
3106
|
else {
|
|
3112
|
-
formData.append(
|
|
3107
|
+
formData.append(fieldName, option.file);
|
|
3113
3108
|
}
|
|
3114
3109
|
}
|
|
3115
3110
|
xhr.onerror = e => {
|
|
@@ -3151,18 +3146,19 @@ function request(option) {
|
|
|
3151
3146
|
return xhr;
|
|
3152
3147
|
}
|
|
3153
3148
|
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3149
|
+
/**
|
|
3150
|
+
* Inserts an upload box into a given selection and sends an HTTP request to upload the file to a specified URL.
|
|
3151
|
+
*/
|
|
3152
|
+
function insertUploadBox(config) {
|
|
3153
|
+
const { selection, boxName, file, requestTypes, requestMethod, requestAction, requestFieldName, requestWithCredentials, requestHeaders, transformResponse, onError, onSuccess, } = config;
|
|
3158
3154
|
if (requestTypes.indexOf(file.type) < 0) {
|
|
3159
3155
|
if (onError) {
|
|
3160
3156
|
onError(`File "${file.name}" is not allowed for uploading.`);
|
|
3161
3157
|
}
|
|
3162
3158
|
throw new Error(`Cannot upload file "${file.name}" because its type "${file.type}" is not found in ['${requestTypes.join('\', \'')}'].`);
|
|
3163
3159
|
}
|
|
3164
|
-
const box =
|
|
3165
|
-
url: URL.createObjectURL(file),
|
|
3160
|
+
const box = selection.insertBox(boxName, {
|
|
3161
|
+
url: file.type.indexOf('image/') === 0 ? URL.createObjectURL(file) : '',
|
|
3166
3162
|
status: 'uploading',
|
|
3167
3163
|
name: file.name,
|
|
3168
3164
|
size: file.size,
|
|
@@ -3186,6 +3182,9 @@ function uploadFile(config) {
|
|
|
3186
3182
|
},
|
|
3187
3183
|
onSuccess: body => {
|
|
3188
3184
|
xhr = null;
|
|
3185
|
+
if (transformResponse) {
|
|
3186
|
+
body = transformResponse(body);
|
|
3187
|
+
}
|
|
3189
3188
|
if (!body.url) {
|
|
3190
3189
|
box.updateValue('status', 'error');
|
|
3191
3190
|
box.render();
|
|
@@ -3199,7 +3198,6 @@ function uploadFile(config) {
|
|
|
3199
3198
|
url: body.url,
|
|
3200
3199
|
});
|
|
3201
3200
|
box.render();
|
|
3202
|
-
editor.history.save();
|
|
3203
3201
|
if (onSuccess) {
|
|
3204
3202
|
onSuccess();
|
|
3205
3203
|
}
|
|
@@ -3207,6 +3205,9 @@ function uploadFile(config) {
|
|
|
3207
3205
|
file,
|
|
3208
3206
|
action: requestAction,
|
|
3209
3207
|
method: requestMethod,
|
|
3208
|
+
fieldName: requestFieldName,
|
|
3209
|
+
withCredentials: requestWithCredentials,
|
|
3210
|
+
headers: requestHeaders,
|
|
3210
3211
|
});
|
|
3211
3212
|
box.event.on('beforeunmount', () => {
|
|
3212
3213
|
if (xhr) {
|
|
@@ -4216,8 +4217,8 @@ class Dropdown {
|
|
|
4216
4217
|
menuNode.css('right', '0');
|
|
4217
4218
|
}
|
|
4218
4219
|
else {
|
|
4219
|
-
menuNode.css('left', '');
|
|
4220
|
-
menuNode.css('right', '');
|
|
4220
|
+
menuNode.css('left', '0');
|
|
4221
|
+
menuNode.css('right', 'auto');
|
|
4221
4222
|
}
|
|
4222
4223
|
if (this.direction === 'top') {
|
|
4223
4224
|
menuNode.css('top', 'auto');
|
|
@@ -4418,8 +4419,8 @@ class Toolbar {
|
|
|
4418
4419
|
}
|
|
4419
4420
|
this.container = query('<div class="lake-toolbar" />');
|
|
4420
4421
|
}
|
|
4421
|
-
|
|
4422
|
-
this.container.append(
|
|
4422
|
+
appendDivision(name) {
|
|
4423
|
+
this.container.append(`<div class="lake-toolbar-${name}" />`);
|
|
4423
4424
|
}
|
|
4424
4425
|
appendNormalButton(editor, item) {
|
|
4425
4426
|
const button = new Button({
|
|
@@ -4491,19 +4492,28 @@ class Toolbar {
|
|
|
4491
4492
|
this.container.append(uploadNode);
|
|
4492
4493
|
fileNode.on('click', event => event.stopPropagation());
|
|
4493
4494
|
fileNode.on('change', event => {
|
|
4495
|
+
const { requestTypes, requestMethod, requestAction, requestFieldName, requestWithCredentials, requestHeaders, transformResponse, } = editor.config[item.name];
|
|
4494
4496
|
const target = event.target;
|
|
4495
4497
|
const files = target.files || [];
|
|
4496
4498
|
for (const file of files) {
|
|
4497
|
-
|
|
4498
|
-
editor,
|
|
4499
|
-
|
|
4499
|
+
insertUploadBox({
|
|
4500
|
+
selection: editor.selection,
|
|
4501
|
+
boxName: item.name,
|
|
4500
4502
|
file,
|
|
4503
|
+
requestTypes,
|
|
4504
|
+
requestMethod,
|
|
4505
|
+
requestAction,
|
|
4506
|
+
requestFieldName,
|
|
4507
|
+
requestWithCredentials,
|
|
4508
|
+
requestHeaders,
|
|
4509
|
+
transformResponse,
|
|
4501
4510
|
onError: error => {
|
|
4502
4511
|
fileNativeNode.value = '';
|
|
4503
|
-
editor.config.
|
|
4512
|
+
editor.config.showMessage('error', error);
|
|
4504
4513
|
},
|
|
4505
4514
|
onSuccess: () => {
|
|
4506
4515
|
fileNativeNode.value = '';
|
|
4516
|
+
editor.history.save();
|
|
4507
4517
|
},
|
|
4508
4518
|
});
|
|
4509
4519
|
}
|
|
@@ -4585,7 +4595,10 @@ class Toolbar {
|
|
|
4585
4595
|
this.root.append(this.container);
|
|
4586
4596
|
for (const name of this.items) {
|
|
4587
4597
|
if (name === '|') {
|
|
4588
|
-
this.
|
|
4598
|
+
this.appendDivision('divider');
|
|
4599
|
+
}
|
|
4600
|
+
else if (name === '-') {
|
|
4601
|
+
this.appendDivision('line-break');
|
|
4589
4602
|
}
|
|
4590
4603
|
else {
|
|
4591
4604
|
let item;
|
|
@@ -5203,7 +5216,7 @@ function createIframeBox(config) {
|
|
|
5203
5216
|
onClick: () => {
|
|
5204
5217
|
const url = formNode.find('input[name="url"]').value();
|
|
5205
5218
|
if (!config.validUrl(url)) {
|
|
5206
|
-
editor.config.
|
|
5219
|
+
editor.config.showMessage('error', getLocaleString(locale, config.urlError));
|
|
5207
5220
|
return;
|
|
5208
5221
|
}
|
|
5209
5222
|
box.updateValue('url', url);
|
|
@@ -6598,7 +6611,7 @@ function removeBox(range) {
|
|
|
6598
6611
|
return box;
|
|
6599
6612
|
}
|
|
6600
6613
|
|
|
6601
|
-
var version = "0.
|
|
6614
|
+
var version = "0.4.0";
|
|
6602
6615
|
|
|
6603
6616
|
// Converts the custom HTML tags to the special tags that can not be parsed by browser.
|
|
6604
6617
|
function denormalizeValue(value) {
|
|
@@ -6774,6 +6787,39 @@ class Selection {
|
|
|
6774
6787
|
appendNextNestedNodes(activeItems, this.range);
|
|
6775
6788
|
return activeItems;
|
|
6776
6789
|
}
|
|
6790
|
+
/**
|
|
6791
|
+
* Creates a deep clone of the current container with its content.
|
|
6792
|
+
* If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
|
|
6793
|
+
*/
|
|
6794
|
+
cloneContainer() {
|
|
6795
|
+
const range = this.range;
|
|
6796
|
+
const newContainer = this.container.clone(true);
|
|
6797
|
+
newContainer.find('lake-box').each(nativeNode => {
|
|
6798
|
+
const box = getBox(nativeNode);
|
|
6799
|
+
box.getContainer().empty();
|
|
6800
|
+
});
|
|
6801
|
+
if (!this.container.contains(range.commonAncestor)) {
|
|
6802
|
+
return newContainer;
|
|
6803
|
+
}
|
|
6804
|
+
if (range.isInsideBox) {
|
|
6805
|
+
const boxNode = range.commonAncestor.closest('lake-box');
|
|
6806
|
+
const boxNodePath = boxNode.path();
|
|
6807
|
+
const newBoxNode = newContainer.find(boxNodePath);
|
|
6808
|
+
const newRange = range.clone();
|
|
6809
|
+
newRange.selectBox(newBoxNode);
|
|
6810
|
+
insertBookmark(newRange);
|
|
6811
|
+
return newContainer;
|
|
6812
|
+
}
|
|
6813
|
+
const startNodePath = range.startNode.path();
|
|
6814
|
+
const endNodePath = range.endNode.path();
|
|
6815
|
+
const newStartNode = newContainer.find(startNodePath);
|
|
6816
|
+
const newEndNode = newContainer.find(endNodePath);
|
|
6817
|
+
const newRange = range.clone();
|
|
6818
|
+
newRange.setStart(newStartNode, range.startOffset);
|
|
6819
|
+
newRange.setEnd(newEndNode, range.endOffset);
|
|
6820
|
+
insertBookmark(newRange);
|
|
6821
|
+
return newContainer;
|
|
6822
|
+
}
|
|
6777
6823
|
/**
|
|
6778
6824
|
* Inserts a bookmark at the cursor position or a pair of bookmarks at the selection boundaries.
|
|
6779
6825
|
*/
|
|
@@ -7614,39 +7660,6 @@ class History {
|
|
|
7614
7660
|
get canRedo() {
|
|
7615
7661
|
return !!this.list[this.index];
|
|
7616
7662
|
}
|
|
7617
|
-
/**
|
|
7618
|
-
* Creates a deep clone of the current container with its content.
|
|
7619
|
-
* If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
|
|
7620
|
-
*/
|
|
7621
|
-
cloneContainer() {
|
|
7622
|
-
const range = this.selection.range;
|
|
7623
|
-
const newContainer = this.container.clone(true);
|
|
7624
|
-
newContainer.find('lake-box').each(nativeNode => {
|
|
7625
|
-
const box = getBox(nativeNode);
|
|
7626
|
-
box.getContainer().empty();
|
|
7627
|
-
});
|
|
7628
|
-
if (!this.container.contains(range.commonAncestor)) {
|
|
7629
|
-
return newContainer;
|
|
7630
|
-
}
|
|
7631
|
-
if (range.isInsideBox) {
|
|
7632
|
-
const boxNode = range.commonAncestor.closest('lake-box');
|
|
7633
|
-
const boxNodePath = boxNode.path();
|
|
7634
|
-
const newBoxNode = newContainer.find(boxNodePath);
|
|
7635
|
-
const newRange = range.clone();
|
|
7636
|
-
newRange.selectBox(newBoxNode);
|
|
7637
|
-
insertBookmark(newRange);
|
|
7638
|
-
return newContainer;
|
|
7639
|
-
}
|
|
7640
|
-
const startNodePath = range.startNode.path();
|
|
7641
|
-
const endNodePath = range.endNode.path();
|
|
7642
|
-
const newStartNode = newContainer.find(startNodePath);
|
|
7643
|
-
const newEndNode = newContainer.find(endNodePath);
|
|
7644
|
-
const newRange = range.clone();
|
|
7645
|
-
newRange.setStart(newStartNode, range.startOffset);
|
|
7646
|
-
newRange.setEnd(newEndNode, range.endOffset);
|
|
7647
|
-
insertBookmark(newRange);
|
|
7648
|
-
return newContainer;
|
|
7649
|
-
}
|
|
7650
7663
|
/**
|
|
7651
7664
|
* Undoes to the previous saved content.
|
|
7652
7665
|
*/
|
|
@@ -7723,7 +7736,7 @@ class History {
|
|
|
7723
7736
|
if (!this.canSave) {
|
|
7724
7737
|
return;
|
|
7725
7738
|
}
|
|
7726
|
-
const item = this.cloneContainer();
|
|
7739
|
+
const item = this.selection.cloneContainer();
|
|
7727
7740
|
const value = this.getValue(item);
|
|
7728
7741
|
if (this.list[this.index - 1]
|
|
7729
7742
|
&& this.removeBookmark(this.getValue(this.list[this.index - 1])) === this.removeBookmark(value)) {
|
|
@@ -7907,7 +7920,7 @@ const defaultConfig = {
|
|
|
7907
7920
|
contentRules: getContentRules(),
|
|
7908
7921
|
minChangeSize: 5,
|
|
7909
7922
|
historySize: 100,
|
|
7910
|
-
|
|
7923
|
+
showMessage: (type, message) => {
|
|
7911
7924
|
if (type === 'success') {
|
|
7912
7925
|
// eslint-disable-next-line no-console
|
|
7913
7926
|
console.log(message);
|
|
@@ -7921,6 +7934,9 @@ const defaultConfig = {
|
|
|
7921
7934
|
console.error(message);
|
|
7922
7935
|
}
|
|
7923
7936
|
},
|
|
7937
|
+
downloadFile: (type, url) => {
|
|
7938
|
+
window.open(url);
|
|
7939
|
+
},
|
|
7924
7940
|
slash: false,
|
|
7925
7941
|
mention: false,
|
|
7926
7942
|
};
|
|
@@ -8469,7 +8485,7 @@ class Editor {
|
|
|
8469
8485
|
* Returns the editor's content.
|
|
8470
8486
|
*/
|
|
8471
8487
|
getValue() {
|
|
8472
|
-
const item = this.
|
|
8488
|
+
const item = this.selection.cloneContainer();
|
|
8473
8489
|
let value = new HTMLParser(item, this.config.contentRules).getHTML();
|
|
8474
8490
|
value = denormalizeValue(value);
|
|
8475
8491
|
return value;
|
|
@@ -8815,7 +8831,6 @@ var paste = (editor) => {
|
|
|
8815
8831
|
return;
|
|
8816
8832
|
}
|
|
8817
8833
|
editor.event.on('paste', event => {
|
|
8818
|
-
const { requestTypes } = editor.config.image;
|
|
8819
8834
|
const range = editor.selection.range;
|
|
8820
8835
|
if (range.isInsideBox) {
|
|
8821
8836
|
return;
|
|
@@ -8829,12 +8844,22 @@ var paste = (editor) => {
|
|
|
8829
8844
|
// upload file
|
|
8830
8845
|
if (dataTransfer.files.length > 0) {
|
|
8831
8846
|
for (const file of dataTransfer.files) {
|
|
8847
|
+
const pluginName = file.type.indexOf('image/') === 0 ? 'image' : 'file';
|
|
8848
|
+
const { requestTypes, requestMethod, requestAction, requestFieldName, requestWithCredentials, requestHeaders, transformResponse, } = editor.config[pluginName];
|
|
8832
8849
|
if (requestTypes.indexOf(file.type) >= 0) {
|
|
8833
|
-
|
|
8834
|
-
editor,
|
|
8835
|
-
|
|
8850
|
+
insertUploadBox({
|
|
8851
|
+
selection: editor.selection,
|
|
8852
|
+
boxName: pluginName,
|
|
8836
8853
|
file,
|
|
8837
|
-
|
|
8854
|
+
requestTypes,
|
|
8855
|
+
requestMethod,
|
|
8856
|
+
requestAction,
|
|
8857
|
+
requestFieldName,
|
|
8858
|
+
requestWithCredentials,
|
|
8859
|
+
requestHeaders,
|
|
8860
|
+
transformResponse,
|
|
8861
|
+
onError: error => editor.config.showMessage('error', error),
|
|
8862
|
+
onSuccess: () => editor.history.save(),
|
|
8838
8863
|
});
|
|
8839
8864
|
}
|
|
8840
8865
|
}
|
|
@@ -11039,8 +11064,8 @@ function renderFloatingToolbar(box) {
|
|
|
11039
11064
|
onClick: () => {
|
|
11040
11065
|
const boxContainer = box.getContainer();
|
|
11041
11066
|
const captionNode = boxContainer.find('.lake-image-caption');
|
|
11042
|
-
const caption = captionNode.text()
|
|
11043
|
-
if (caption === '') {
|
|
11067
|
+
const caption = captionNode.text();
|
|
11068
|
+
if (caption.trim() === '') {
|
|
11044
11069
|
captionNode.addClass('lake-placeholder');
|
|
11045
11070
|
}
|
|
11046
11071
|
showCaption(box, captionNode);
|
|
@@ -11139,7 +11164,8 @@ function renderFloatingToolbar(box) {
|
|
|
11139
11164
|
icon: icons.get('open'),
|
|
11140
11165
|
tooltip: locale => locale.image.open(),
|
|
11141
11166
|
onClick: () => {
|
|
11142
|
-
|
|
11167
|
+
const editor = box.getEditor();
|
|
11168
|
+
editor.config.downloadFile('image', box.value.url);
|
|
11143
11169
|
},
|
|
11144
11170
|
},
|
|
11145
11171
|
];
|
|
@@ -11273,11 +11299,11 @@ function openFullScreen(box) {
|
|
|
11273
11299
|
function renderCaption(box) {
|
|
11274
11300
|
const editor = box.getEditor();
|
|
11275
11301
|
const boxContainer = box.getContainer();
|
|
11276
|
-
const defaultCaption =
|
|
11302
|
+
const defaultCaption = box.value.caption || '';
|
|
11277
11303
|
const captionNode = query('<div class="lake-image-caption" />');
|
|
11278
11304
|
captionNode.text(defaultCaption);
|
|
11279
11305
|
boxContainer.append(captionNode);
|
|
11280
|
-
if (defaultCaption === '') {
|
|
11306
|
+
if (defaultCaption.trim() === '') {
|
|
11281
11307
|
hideCaption(box, captionNode);
|
|
11282
11308
|
}
|
|
11283
11309
|
else {
|
|
@@ -11300,7 +11326,7 @@ function renderCaption(box) {
|
|
|
11300
11326
|
immediate: false,
|
|
11301
11327
|
});
|
|
11302
11328
|
captionNode.on('input', () => {
|
|
11303
|
-
const caption = captionNode.text()
|
|
11329
|
+
const caption = captionNode.text();
|
|
11304
11330
|
if (caption === '') {
|
|
11305
11331
|
captionNode.addClass('lake-placeholder');
|
|
11306
11332
|
}
|
|
@@ -11328,8 +11354,8 @@ function renderCaption(box) {
|
|
|
11328
11354
|
}
|
|
11329
11355
|
});
|
|
11330
11356
|
captionNode.on('focusout', () => {
|
|
11331
|
-
const caption = captionNode.text()
|
|
11332
|
-
if (caption === '') {
|
|
11357
|
+
const caption = captionNode.text();
|
|
11358
|
+
if (caption.trim() === '') {
|
|
11333
11359
|
hideCaption(box, captionNode);
|
|
11334
11360
|
}
|
|
11335
11361
|
});
|
|
@@ -11704,7 +11730,8 @@ function setFloatingToolbar(box) {
|
|
|
11704
11730
|
icon: icons.get('download'),
|
|
11705
11731
|
tooltip: locale => locale.file.download(),
|
|
11706
11732
|
onClick: () => {
|
|
11707
|
-
|
|
11733
|
+
const editor = box.getEditor();
|
|
11734
|
+
editor.config.downloadFile('file', box.value.url);
|
|
11708
11735
|
},
|
|
11709
11736
|
},
|
|
11710
11737
|
{
|
|
@@ -11779,7 +11806,7 @@ var fileBox = {
|
|
|
11779
11806
|
}
|
|
11780
11807
|
else {
|
|
11781
11808
|
rootNode.on('click', () => {
|
|
11782
|
-
|
|
11809
|
+
editor.config.downloadFile('file', value.url);
|
|
11783
11810
|
});
|
|
11784
11811
|
}
|
|
11785
11812
|
},
|
|
@@ -11863,7 +11890,7 @@ function renderError(box) {
|
|
|
11863
11890
|
rootNode.on('click', () => {
|
|
11864
11891
|
editor.selection.selectBox(box);
|
|
11865
11892
|
});
|
|
11866
|
-
editor.config.
|
|
11893
|
+
editor.config.showMessage('warning', `
|
|
11867
11894
|
Box "${box.name}" (id: ${box.node.id}) failed to display because window.katex was not found.
|
|
11868
11895
|
Please check if the "katex" library is added to this page.
|
|
11869
11896
|
`.trim());
|
|
@@ -12294,7 +12321,6 @@ var mention = (editor) => {
|
|
|
12294
12321
|
if (editor.readonly) {
|
|
12295
12322
|
return;
|
|
12296
12323
|
}
|
|
12297
|
-
const { requestAction, requestMethod, items } = editor.config.mention;
|
|
12298
12324
|
let menu = null;
|
|
12299
12325
|
const selectListener = (event, item) => {
|
|
12300
12326
|
if (menu) {
|
|
@@ -12328,9 +12354,14 @@ var mention = (editor) => {
|
|
|
12328
12354
|
return;
|
|
12329
12355
|
}
|
|
12330
12356
|
if (!menu) {
|
|
12357
|
+
const { requestAction, items } = editor.config.mention;
|
|
12331
12358
|
if (requestAction) {
|
|
12359
|
+
const { requestMethod, requestWithCredentials, requestHeaders, transformResponse } = editor.config.mention;
|
|
12332
12360
|
request({
|
|
12333
12361
|
onSuccess: body => {
|
|
12362
|
+
if (transformResponse) {
|
|
12363
|
+
body = transformResponse(body);
|
|
12364
|
+
}
|
|
12334
12365
|
if (!body.data) {
|
|
12335
12366
|
return;
|
|
12336
12367
|
}
|
|
@@ -12344,6 +12375,8 @@ var mention = (editor) => {
|
|
|
12344
12375
|
},
|
|
12345
12376
|
action: requestAction,
|
|
12346
12377
|
method: requestMethod,
|
|
12378
|
+
withCredentials: requestWithCredentials,
|
|
12379
|
+
headers: requestHeaders,
|
|
12347
12380
|
});
|
|
12348
12381
|
}
|
|
12349
12382
|
else {
|
|
@@ -13829,20 +13862,29 @@ var slash = (editor) => {
|
|
|
13829
13862
|
if (!fileNode) {
|
|
13830
13863
|
return;
|
|
13831
13864
|
}
|
|
13865
|
+
const { requestTypes, requestMethod, requestAction, requestFieldName, requestWithCredentials, requestHeaders, transformResponse, } = editor.config[item.name];
|
|
13832
13866
|
const target = event.target;
|
|
13833
13867
|
const fileNativeNode = fileNode.get(0);
|
|
13834
13868
|
const files = target.files || [];
|
|
13835
13869
|
for (const file of files) {
|
|
13836
|
-
|
|
13837
|
-
editor,
|
|
13838
|
-
|
|
13870
|
+
insertUploadBox({
|
|
13871
|
+
selection: editor.selection,
|
|
13872
|
+
boxName: item.name,
|
|
13839
13873
|
file,
|
|
13874
|
+
requestTypes,
|
|
13875
|
+
requestMethod,
|
|
13876
|
+
requestAction,
|
|
13877
|
+
requestFieldName,
|
|
13878
|
+
requestWithCredentials,
|
|
13879
|
+
requestHeaders,
|
|
13880
|
+
transformResponse,
|
|
13840
13881
|
onError: error => {
|
|
13841
13882
|
fileNativeNode.value = '';
|
|
13842
|
-
editor.config.
|
|
13883
|
+
editor.config.showMessage('error', error);
|
|
13843
13884
|
},
|
|
13844
13885
|
onSuccess: () => {
|
|
13845
13886
|
fileNativeNode.value = '';
|
|
13887
|
+
editor.history.save();
|
|
13846
13888
|
},
|
|
13847
13889
|
});
|
|
13848
13890
|
}
|