lakelib 0.4.1 → 0.4.3
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.css +4 -4
- package/dist/lake.min.js +28 -28
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +25 -6
- package/lib/lake.d.ts +685 -7
- package/lib/lake.js +100 -36
- package/lib/lake.js.map +1 -1
- package/package.json +30 -29
package/lib/lake.js
CHANGED
|
@@ -3,6 +3,7 @@ import { i18nObject as i18nObject$1 } from 'typesafe-i18n';
|
|
|
3
3
|
import { isKeyHotkey } from 'is-hotkey';
|
|
4
4
|
import debounce from 'debounce';
|
|
5
5
|
import isEqual from 'fast-deep-equal/es6';
|
|
6
|
+
import { toHTML } from 'lake-html';
|
|
6
7
|
import 'photoswipe/style.css';
|
|
7
8
|
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
|
8
9
|
import PhotoSwipe from 'photoswipe';
|
|
@@ -1504,11 +1505,7 @@ function template(strings, ...keys) {
|
|
|
1504
1505
|
// Don't escape special characters in the template.
|
|
1505
1506
|
content += strings[i + 1];
|
|
1506
1507
|
}
|
|
1507
|
-
content
|
|
1508
|
-
.replace(/^\s+/gm, '')
|
|
1509
|
-
.replace(/\s+$/gm, '')
|
|
1510
|
-
.replace(/[\r\n]/g, '');
|
|
1511
|
-
return content;
|
|
1508
|
+
return content.replace(/^\s+|\s+$|[\r\n]/gm, '');
|
|
1512
1509
|
}
|
|
1513
1510
|
|
|
1514
1511
|
const boxInstances = new Map();
|
|
@@ -3275,7 +3272,9 @@ class Button {
|
|
|
3275
3272
|
}
|
|
3276
3273
|
}
|
|
3277
3274
|
|
|
3278
|
-
|
|
3275
|
+
/**
|
|
3276
|
+
* A tag function that removes empty spaces at the beginning and end of lines or line terminator character.
|
|
3277
|
+
*/
|
|
3279
3278
|
function unsafeTemplate(strings, ...keys) {
|
|
3280
3279
|
let content = strings[0];
|
|
3281
3280
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -3283,11 +3282,7 @@ function unsafeTemplate(strings, ...keys) {
|
|
|
3283
3282
|
content += key;
|
|
3284
3283
|
content += strings[i + 1];
|
|
3285
3284
|
}
|
|
3286
|
-
content
|
|
3287
|
-
.replace(/^\s+/gm, '')
|
|
3288
|
-
.replace(/\s+$/gm, '')
|
|
3289
|
-
.replace(/[\r\n]/g, '');
|
|
3290
|
-
return content;
|
|
3285
|
+
return content.replace(/^\s+|\s+$|[\r\n]/gm, '');
|
|
3291
3286
|
}
|
|
3292
3287
|
|
|
3293
3288
|
// Returns the text of keyboard shortcuts used for a tooltip or help.
|
|
@@ -4026,7 +4021,6 @@ const localeTranslations = {
|
|
|
4026
4021
|
ja,
|
|
4027
4022
|
ko,
|
|
4028
4023
|
};
|
|
4029
|
-
const locales = Object.keys(localeTranslations);
|
|
4030
4024
|
const loadedLocales = {};
|
|
4031
4025
|
const loadedFormatters = {};
|
|
4032
4026
|
const initFormatters = () => {
|
|
@@ -4045,11 +4039,30 @@ function loadLocale(locale) {
|
|
|
4045
4039
|
loadedLocales[locale] = localeTranslations[locale];
|
|
4046
4040
|
loadFormatters(locale);
|
|
4047
4041
|
}
|
|
4048
|
-
const loadAllLocales = () => locales.forEach(loadLocale);
|
|
4049
4042
|
function i18nObject(locale) {
|
|
4050
4043
|
return i18nObject$1(locale, loadedLocales[locale], loadedFormatters[locale]);
|
|
4051
4044
|
}
|
|
4052
|
-
|
|
4045
|
+
/**
|
|
4046
|
+
* The LocaleManager interface manages a collection of Translation objects.
|
|
4047
|
+
* It allows you to add and retrieve the names of locales.
|
|
4048
|
+
*/
|
|
4049
|
+
class LocaleManager {
|
|
4050
|
+
/**
|
|
4051
|
+
* Adds a Translation to the collection.
|
|
4052
|
+
*/
|
|
4053
|
+
add(locale, translation) {
|
|
4054
|
+
localeTranslations[locale] = translation;
|
|
4055
|
+
loadLocale(locale);
|
|
4056
|
+
}
|
|
4057
|
+
/**
|
|
4058
|
+
* Returns a list of all locale names.
|
|
4059
|
+
*/
|
|
4060
|
+
getNames() {
|
|
4061
|
+
return Object.keys(localeTranslations);
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
const locales = Object.keys(localeTranslations);
|
|
4065
|
+
locales.forEach(loadLocale);
|
|
4053
4066
|
|
|
4054
4067
|
/**
|
|
4055
4068
|
* The Dropdown component provides a user-friendly menu with selectable options. Use it to allow users to pick from a list of predefined choices.
|
|
@@ -4398,16 +4411,13 @@ const defaultItems$1 = [
|
|
|
4398
4411
|
'blockQuote',
|
|
4399
4412
|
'hr',
|
|
4400
4413
|
];
|
|
4401
|
-
const toolbarItemMap = new Map();
|
|
4402
|
-
for (const item of toolbarItems) {
|
|
4403
|
-
toolbarItemMap.set(item.name, item);
|
|
4404
|
-
}
|
|
4405
4414
|
/**
|
|
4406
4415
|
* The Toolbar interface provides properties and methods for rendering and manipulating the toolbar.
|
|
4407
4416
|
*/
|
|
4408
4417
|
class Toolbar {
|
|
4409
4418
|
constructor(config) {
|
|
4410
4419
|
this.placement = 'top';
|
|
4420
|
+
this.toolbarItemMap = new Map();
|
|
4411
4421
|
this.allMenuMap = new Map();
|
|
4412
4422
|
this.buttonItemList = [];
|
|
4413
4423
|
this.dropdownItemList = [];
|
|
@@ -4417,6 +4427,14 @@ class Toolbar {
|
|
|
4417
4427
|
if (config.placement) {
|
|
4418
4428
|
this.placement = config.placement;
|
|
4419
4429
|
}
|
|
4430
|
+
for (const item of toolbarItems) {
|
|
4431
|
+
this.toolbarItemMap.set(item.name, Object.assign({}, item));
|
|
4432
|
+
}
|
|
4433
|
+
if (config.fontFamily) {
|
|
4434
|
+
const fontFamilyItem = this.toolbarItemMap.get('fontFamily');
|
|
4435
|
+
fontFamilyItem.defaultValue = config.fontFamily.defaultValue;
|
|
4436
|
+
fontFamilyItem.menuItems = config.fontFamily.menuItems;
|
|
4437
|
+
}
|
|
4420
4438
|
this.container = query('<div class="lake-toolbar" />');
|
|
4421
4439
|
}
|
|
4422
4440
|
appendDivision(name) {
|
|
@@ -4603,7 +4621,7 @@ class Toolbar {
|
|
|
4603
4621
|
else {
|
|
4604
4622
|
let item;
|
|
4605
4623
|
if (typeof name === 'string') {
|
|
4606
|
-
item = toolbarItemMap.get(name);
|
|
4624
|
+
item = this.toolbarItemMap.get(name);
|
|
4607
4625
|
if (!item) {
|
|
4608
4626
|
throw new Error(`ToolbarItem "${name}" has not been defined yet.`);
|
|
4609
4627
|
}
|
|
@@ -6611,22 +6629,44 @@ function removeBox(range) {
|
|
|
6611
6629
|
return box;
|
|
6612
6630
|
}
|
|
6613
6631
|
|
|
6614
|
-
var version = "0.4.
|
|
6632
|
+
var version = "0.4.3";
|
|
6615
6633
|
|
|
6616
|
-
|
|
6634
|
+
/**
|
|
6635
|
+
* Converts the custom HTML tags to the special tags that can not be parsed by browser.
|
|
6636
|
+
*/
|
|
6617
6637
|
function denormalizeValue(value) {
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6638
|
+
const combinedRegex = /(<lake-box[^>]+>)[\s\S]*?<\/lake-box>|<lake-bookmark\s+type="(anchor|focus)">\s*<\/lake-bookmark>/gi;
|
|
6639
|
+
return value.replace(combinedRegex, (match, boxOpen, bookmarkType) => {
|
|
6640
|
+
if (boxOpen) {
|
|
6641
|
+
return `${boxOpen}</lake-box>`;
|
|
6642
|
+
}
|
|
6643
|
+
if (bookmarkType === 'anchor') {
|
|
6644
|
+
return '<anchor />';
|
|
6645
|
+
}
|
|
6646
|
+
if (bookmarkType === 'focus') {
|
|
6647
|
+
return '<focus />';
|
|
6648
|
+
}
|
|
6649
|
+
return match;
|
|
6650
|
+
});
|
|
6622
6651
|
}
|
|
6623
6652
|
|
|
6624
|
-
|
|
6653
|
+
/**
|
|
6654
|
+
* Converts the special tags to ordinary HTML tags that can be parsed by browser.
|
|
6655
|
+
*/
|
|
6625
6656
|
function normalizeValue(value) {
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6657
|
+
const combinedRegex = /(<lake-box[^>]+>)[\s\S]*?(?:<\/lake-box>|$)|(<anchor\s*\/>)|(<focus\s*\/>)/gi;
|
|
6658
|
+
return value.replace(combinedRegex, (match, boxOpen, anchorMatch, focusMatch) => {
|
|
6659
|
+
if (boxOpen) {
|
|
6660
|
+
return `${boxOpen}</lake-box>`;
|
|
6661
|
+
}
|
|
6662
|
+
if (anchorMatch) {
|
|
6663
|
+
return '<lake-bookmark type="anchor"></lake-bookmark>';
|
|
6664
|
+
}
|
|
6665
|
+
if (focusMatch) {
|
|
6666
|
+
return '<lake-bookmark type="focus"></lake-bookmark>';
|
|
6667
|
+
}
|
|
6668
|
+
return match;
|
|
6669
|
+
});
|
|
6630
6670
|
}
|
|
6631
6671
|
|
|
6632
6672
|
// If the specified node is not visible, scrolls the container that contains the node to its position to make it visible.
|
|
@@ -7602,9 +7642,13 @@ class History {
|
|
|
7602
7642
|
this.container = selection.container;
|
|
7603
7643
|
}
|
|
7604
7644
|
removeBookmark(value) {
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7645
|
+
const combinedRegex = /(<lake-box[^>]+)\sfocus="\w+"([^>]*>)|<lake-bookmark\s+type="(?:anchor|focus)">\s*<\/lake-bookmark>/gi;
|
|
7646
|
+
return value.replace(combinedRegex, (match, boxLeft, boxRight) => {
|
|
7647
|
+
if (boxLeft) {
|
|
7648
|
+
return `${boxLeft}${boxRight}`;
|
|
7649
|
+
}
|
|
7650
|
+
return '';
|
|
7651
|
+
});
|
|
7608
7652
|
}
|
|
7609
7653
|
getValue(container) {
|
|
7610
7654
|
return new HTMLParser(container, this.contentRules).getHTML();
|
|
@@ -8345,11 +8389,21 @@ class Editor {
|
|
|
8345
8389
|
}
|
|
8346
8390
|
else if (children.length === 1) {
|
|
8347
8391
|
const child = children[0];
|
|
8348
|
-
if (child.isVoid) {
|
|
8392
|
+
if (child.isVoid || child.isText) {
|
|
8393
|
+
const startNode = range.startNode;
|
|
8394
|
+
const startOffset = range.startOffset;
|
|
8395
|
+
const endNode = range.endNode;
|
|
8396
|
+
const endOffset = range.endOffset;
|
|
8349
8397
|
const paragraph = query('<p />');
|
|
8350
8398
|
child.before(paragraph);
|
|
8351
8399
|
paragraph.append(child);
|
|
8352
|
-
|
|
8400
|
+
if (startNode.isText || endNode.isText) {
|
|
8401
|
+
range.setStart(startNode, startOffset);
|
|
8402
|
+
range.setEnd(endNode, endOffset);
|
|
8403
|
+
}
|
|
8404
|
+
else {
|
|
8405
|
+
range.shrinkAfter(paragraph);
|
|
8406
|
+
}
|
|
8353
8407
|
changed = true;
|
|
8354
8408
|
debug(`Content fixed: void element "${child.name}" was wrapped in paragraph`);
|
|
8355
8409
|
}
|
|
@@ -8490,6 +8544,12 @@ class Editor {
|
|
|
8490
8544
|
value = denormalizeValue(value);
|
|
8491
8545
|
return value;
|
|
8492
8546
|
}
|
|
8547
|
+
/**
|
|
8548
|
+
* Returns the editor's content in HTML format.
|
|
8549
|
+
*/
|
|
8550
|
+
getHTML() {
|
|
8551
|
+
return toHTML(this.getValue());
|
|
8552
|
+
}
|
|
8493
8553
|
/**
|
|
8494
8554
|
* Renders an editing area and sets default content to it.
|
|
8495
8555
|
*/
|
|
@@ -8568,6 +8628,10 @@ class Editor {
|
|
|
8568
8628
|
* The current version of Lake.
|
|
8569
8629
|
*/
|
|
8570
8630
|
Editor.version = version;
|
|
8631
|
+
/**
|
|
8632
|
+
* A LocaleManager object that manages the locale translations.
|
|
8633
|
+
*/
|
|
8634
|
+
Editor.locale = new LocaleManager();
|
|
8571
8635
|
/**
|
|
8572
8636
|
* A BoxManager object that manages the box components.
|
|
8573
8637
|
*/
|
|
@@ -14014,5 +14078,5 @@ Editor.plugin.add('arrowKeys', arrowKeys);
|
|
|
14014
14078
|
Editor.plugin.add('escapeKey', escapeKey);
|
|
14015
14079
|
Editor.plugin.add('slash', slash);
|
|
14016
14080
|
|
|
14017
|
-
export { Box, Button, Dropdown, Editor, Fragment, HTMLParser, Nodes, Range, TextParser, Toolbar, addMark, createIframeBox, deleteContents, getBox, getContentRules, icons, insertBlock, insertBookmark, insertBox, insertContents, query, removeBox, removeMark, setBlocks, splitBlock$1 as splitBlock, splitMarks, template, toBookmark, toHex };
|
|
14081
|
+
export { Box, Button, Dropdown, Editor, Fragment, HTMLParser, Nodes, Range, TextParser, Toolbar, addMark, createIframeBox, deleteContents, getBox, getContentRules, icons, insertBlock, insertBookmark, insertBox, insertContents, modifierText, query, removeBox, removeMark, setBlocks, splitBlock$1 as splitBlock, splitMarks, template, toBookmark, toHex };
|
|
14018
14082
|
//# sourceMappingURL=lake.js.map
|