lakelib 0.3.10 → 0.3.11
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 +27 -27
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.d.ts +2 -1
- package/lib/lake.js +70 -36
- package/lib/lake.js.map +1 -1
- package/package.json +11 -9
package/lib/lake.d.ts
CHANGED
|
@@ -2261,4 +2261,5 @@ declare class Dropdown {
|
|
|
2261
2261
|
unmount(): void;
|
|
2262
2262
|
}
|
|
2263
2263
|
|
|
2264
|
-
export {
|
|
2264
|
+
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 };
|
|
2265
|
+
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) {
|
|
@@ -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
4512
|
editor.config.onMessage('error', error);
|
|
4504
4513
|
},
|
|
4505
4514
|
onSuccess: () => {
|
|
4506
4515
|
fileNativeNode.value = '';
|
|
4516
|
+
editor.history.save();
|
|
4507
4517
|
},
|
|
4508
4518
|
});
|
|
4509
4519
|
}
|
|
@@ -6598,7 +6608,7 @@ function removeBox(range) {
|
|
|
6598
6608
|
return box;
|
|
6599
6609
|
}
|
|
6600
6610
|
|
|
6601
|
-
var version = "0.3.
|
|
6611
|
+
var version = "0.3.11";
|
|
6602
6612
|
|
|
6603
6613
|
// Converts the custom HTML tags to the special tags that can not be parsed by browser.
|
|
6604
6614
|
function denormalizeValue(value) {
|
|
@@ -8815,7 +8825,6 @@ var paste = (editor) => {
|
|
|
8815
8825
|
return;
|
|
8816
8826
|
}
|
|
8817
8827
|
editor.event.on('paste', event => {
|
|
8818
|
-
const { requestTypes } = editor.config.image;
|
|
8819
8828
|
const range = editor.selection.range;
|
|
8820
8829
|
if (range.isInsideBox) {
|
|
8821
8830
|
return;
|
|
@@ -8829,12 +8838,22 @@ var paste = (editor) => {
|
|
|
8829
8838
|
// upload file
|
|
8830
8839
|
if (dataTransfer.files.length > 0) {
|
|
8831
8840
|
for (const file of dataTransfer.files) {
|
|
8841
|
+
const pluginName = file.type.indexOf('image/') === 0 ? 'image' : 'file';
|
|
8842
|
+
const { requestTypes, requestMethod, requestAction, requestFieldName, requestWithCredentials, requestHeaders, transformResponse, } = editor.config[pluginName];
|
|
8832
8843
|
if (requestTypes.indexOf(file.type) >= 0) {
|
|
8833
|
-
|
|
8834
|
-
editor,
|
|
8835
|
-
|
|
8844
|
+
insertUploadBox({
|
|
8845
|
+
selection: editor.selection,
|
|
8846
|
+
boxName: pluginName,
|
|
8836
8847
|
file,
|
|
8848
|
+
requestTypes,
|
|
8849
|
+
requestMethod,
|
|
8850
|
+
requestAction,
|
|
8851
|
+
requestFieldName,
|
|
8852
|
+
requestWithCredentials,
|
|
8853
|
+
requestHeaders,
|
|
8854
|
+
transformResponse,
|
|
8837
8855
|
onError: error => editor.config.onMessage('error', error),
|
|
8856
|
+
onSuccess: () => editor.history.save(),
|
|
8838
8857
|
});
|
|
8839
8858
|
}
|
|
8840
8859
|
}
|
|
@@ -11039,8 +11058,8 @@ function renderFloatingToolbar(box) {
|
|
|
11039
11058
|
onClick: () => {
|
|
11040
11059
|
const boxContainer = box.getContainer();
|
|
11041
11060
|
const captionNode = boxContainer.find('.lake-image-caption');
|
|
11042
|
-
const caption = captionNode.text()
|
|
11043
|
-
if (caption === '') {
|
|
11061
|
+
const caption = captionNode.text();
|
|
11062
|
+
if (caption.trim() === '') {
|
|
11044
11063
|
captionNode.addClass('lake-placeholder');
|
|
11045
11064
|
}
|
|
11046
11065
|
showCaption(box, captionNode);
|
|
@@ -11273,11 +11292,11 @@ function openFullScreen(box) {
|
|
|
11273
11292
|
function renderCaption(box) {
|
|
11274
11293
|
const editor = box.getEditor();
|
|
11275
11294
|
const boxContainer = box.getContainer();
|
|
11276
|
-
const defaultCaption =
|
|
11295
|
+
const defaultCaption = box.value.caption || '';
|
|
11277
11296
|
const captionNode = query('<div class="lake-image-caption" />');
|
|
11278
11297
|
captionNode.text(defaultCaption);
|
|
11279
11298
|
boxContainer.append(captionNode);
|
|
11280
|
-
if (defaultCaption === '') {
|
|
11299
|
+
if (defaultCaption.trim() === '') {
|
|
11281
11300
|
hideCaption(box, captionNode);
|
|
11282
11301
|
}
|
|
11283
11302
|
else {
|
|
@@ -11300,7 +11319,7 @@ function renderCaption(box) {
|
|
|
11300
11319
|
immediate: false,
|
|
11301
11320
|
});
|
|
11302
11321
|
captionNode.on('input', () => {
|
|
11303
|
-
const caption = captionNode.text()
|
|
11322
|
+
const caption = captionNode.text();
|
|
11304
11323
|
if (caption === '') {
|
|
11305
11324
|
captionNode.addClass('lake-placeholder');
|
|
11306
11325
|
}
|
|
@@ -11328,8 +11347,8 @@ function renderCaption(box) {
|
|
|
11328
11347
|
}
|
|
11329
11348
|
});
|
|
11330
11349
|
captionNode.on('focusout', () => {
|
|
11331
|
-
const caption = captionNode.text()
|
|
11332
|
-
if (caption === '') {
|
|
11350
|
+
const caption = captionNode.text();
|
|
11351
|
+
if (caption.trim() === '') {
|
|
11333
11352
|
hideCaption(box, captionNode);
|
|
11334
11353
|
}
|
|
11335
11354
|
});
|
|
@@ -12294,7 +12313,6 @@ var mention = (editor) => {
|
|
|
12294
12313
|
if (editor.readonly) {
|
|
12295
12314
|
return;
|
|
12296
12315
|
}
|
|
12297
|
-
const { requestAction, requestMethod, items } = editor.config.mention;
|
|
12298
12316
|
let menu = null;
|
|
12299
12317
|
const selectListener = (event, item) => {
|
|
12300
12318
|
if (menu) {
|
|
@@ -12328,9 +12346,14 @@ var mention = (editor) => {
|
|
|
12328
12346
|
return;
|
|
12329
12347
|
}
|
|
12330
12348
|
if (!menu) {
|
|
12349
|
+
const { requestAction, items } = editor.config.mention;
|
|
12331
12350
|
if (requestAction) {
|
|
12351
|
+
const { requestMethod, requestWithCredentials, requestHeaders, transformResponse } = editor.config.mention;
|
|
12332
12352
|
request({
|
|
12333
12353
|
onSuccess: body => {
|
|
12354
|
+
if (transformResponse) {
|
|
12355
|
+
body = transformResponse(body);
|
|
12356
|
+
}
|
|
12334
12357
|
if (!body.data) {
|
|
12335
12358
|
return;
|
|
12336
12359
|
}
|
|
@@ -12344,6 +12367,8 @@ var mention = (editor) => {
|
|
|
12344
12367
|
},
|
|
12345
12368
|
action: requestAction,
|
|
12346
12369
|
method: requestMethod,
|
|
12370
|
+
withCredentials: requestWithCredentials,
|
|
12371
|
+
headers: requestHeaders,
|
|
12347
12372
|
});
|
|
12348
12373
|
}
|
|
12349
12374
|
else {
|
|
@@ -13829,20 +13854,29 @@ var slash = (editor) => {
|
|
|
13829
13854
|
if (!fileNode) {
|
|
13830
13855
|
return;
|
|
13831
13856
|
}
|
|
13857
|
+
const { requestTypes, requestMethod, requestAction, requestFieldName, requestWithCredentials, requestHeaders, transformResponse, } = editor.config[item.name];
|
|
13832
13858
|
const target = event.target;
|
|
13833
13859
|
const fileNativeNode = fileNode.get(0);
|
|
13834
13860
|
const files = target.files || [];
|
|
13835
13861
|
for (const file of files) {
|
|
13836
|
-
|
|
13837
|
-
editor,
|
|
13838
|
-
|
|
13862
|
+
insertUploadBox({
|
|
13863
|
+
selection: editor.selection,
|
|
13864
|
+
boxName: item.name,
|
|
13839
13865
|
file,
|
|
13866
|
+
requestTypes,
|
|
13867
|
+
requestMethod,
|
|
13868
|
+
requestAction,
|
|
13869
|
+
requestFieldName,
|
|
13870
|
+
requestWithCredentials,
|
|
13871
|
+
requestHeaders,
|
|
13872
|
+
transformResponse,
|
|
13840
13873
|
onError: error => {
|
|
13841
13874
|
fileNativeNode.value = '';
|
|
13842
13875
|
editor.config.onMessage('error', error);
|
|
13843
13876
|
},
|
|
13844
13877
|
onSuccess: () => {
|
|
13845
13878
|
fileNativeNode.value = '';
|
|
13879
|
+
editor.history.save();
|
|
13846
13880
|
},
|
|
13847
13881
|
});
|
|
13848
13882
|
}
|