lakelib 0.3.1 → 0.3.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/README.md +1 -1
- package/dist/lake.min.css +30 -0
- package/dist/lake.min.js +14 -14
- package/dist/lake.min.js.map +1 -1
- package/lib/i18n/en-US/index.d.ts +8 -0
- package/lib/i18n/ja/index.d.ts +8 -0
- package/lib/i18n/ko/index.d.ts +8 -0
- package/lib/i18n/types.d.ts +64 -0
- package/lib/i18n/zh-CN/index.d.ts +8 -0
- package/lib/lake.js +295 -195
- package/lib/lake.js.map +1 -1
- package/lib/models/box.d.ts +5 -5
- package/lib/models/fragment.d.ts +2 -2
- package/lib/models/nodes.d.ts +5 -5
- package/lib/models/range.d.ts +1 -1
- package/lib/parsers/html-parser.d.ts +2 -2
- package/lib/parsers/text-parser.d.ts +1 -1
- package/lib/ui/button.d.ts +3 -3
- package/lib/ui/dropdown.d.ts +7 -7
- package/lib/ui/toolbar.d.ts +1 -1
- package/package.json +11 -9
- package/dist/lake.css +0 -1863
package/lib/lake.js
CHANGED
|
@@ -171,6 +171,14 @@ var tableMerge = "<svg width=\"24\" height=\"24\" fill=\"none\" viewBox=\"0 0 24
|
|
|
171
171
|
|
|
172
172
|
var tableSplit = "<svg width=\"24\" height=\"24\" fill=\"none\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12.5 10H11v4h1.5v-4Z\" fill=\"#212121\"/><path d=\"M3 6.25A3.25 3.25 0 0 1 6.25 3h11.5A3.25 3.25 0 0 1 21 6.25v11.5A3.25 3.25 0 0 1 17.75 21H6.25A3.25 3.25 0 0 1 3 17.75V6.25ZM6.25 4.5A1.75 1.75 0 0 0 4.5 6.25V7.5H11v-3H6.25Zm13.25 12h-7v3h5.25a1.75 1.75 0 0 0 1.75-1.75V16.5Zm0-10.25a1.75 1.75 0 0 0-1.75-1.75H12.5v3h7V6.25ZM4.5 16.5v1.25c0 .966.784 1.75 1.75 1.75H11v-3H4.5Zm0-1.5h15V9h-15v6Z\" fill=\"#212121\"/></svg>";
|
|
173
173
|
|
|
174
|
+
var info = "<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,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z\"></path></svg>";
|
|
175
|
+
|
|
176
|
+
var tip = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M176,232a8,8,0,0,1-8,8H88a8,8,0,0,1,0-16h80A8,8,0,0,1,176,232Zm40-128a87.55,87.55,0,0,1-33.64,69.21A16.24,16.24,0,0,0,176,186v6a16,16,0,0,1-16,16H96a16,16,0,0,1-16-16v-6a16,16,0,0,0-6.23-12.66A87.59,87.59,0,0,1,40,104.49C39.74,56.83,78.26,17.14,125.88,16A88,88,0,0,1,216,104Zm-16,0a72,72,0,0,0-73.74-72c-39,.92-70.47,33.39-70.26,72.39a71.65,71.65,0,0,0,27.64,56.3A32,32,0,0,1,96,186v6h64v-6a32.15,32.15,0,0,1,12.47-25.35A71.65,71.65,0,0,0,200,104Zm-16.11-9.34a57.6,57.6,0,0,0-46.56-46.55,8,8,0,0,0-2.66,15.78c16.57,2.79,30.63,16.85,33.44,33.45A8,8,0,0,0,176,104a9,9,0,0,0,1.35-.11A8,8,0,0,0,183.89,94.66Z\"></path></svg>";
|
|
177
|
+
|
|
178
|
+
var warning = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M236.8,188.09,149.35,36.22h0a24.76,24.76,0,0,0-42.7,0L19.2,188.09a23.51,23.51,0,0,0,0,23.72A24.35,24.35,0,0,0,40.55,224h174.9a24.35,24.35,0,0,0,21.33-12.19A23.51,23.51,0,0,0,236.8,188.09ZM222.93,203.8a8.5,8.5,0,0,1-7.48,4.2H40.55a8.5,8.5,0,0,1-7.48-4.2,7.59,7.59,0,0,1,0-7.72L120.52,44.21a8.75,8.75,0,0,1,15,0l87.45,151.87A7.59,7.59,0,0,1,222.93,203.8ZM120,144V104a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,180Z\"></path></svg>";
|
|
179
|
+
|
|
180
|
+
var danger = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M120,136V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0ZM232,91.55v72.9a15.86,15.86,0,0,1-4.69,11.31l-51.55,51.55A15.86,15.86,0,0,1,164.45,232H91.55a15.86,15.86,0,0,1-11.31-4.69L28.69,175.76A15.86,15.86,0,0,1,24,164.45V91.55a15.86,15.86,0,0,1,4.69-11.31L80.24,28.69A15.86,15.86,0,0,1,91.55,24h72.9a15.86,15.86,0,0,1,11.31,4.69l51.55,51.55A15.86,15.86,0,0,1,232,91.55Zm-16,0L164.45,40H91.55L40,91.55v72.9L91.55,216h72.9L216,164.45ZM128,160a12,12,0,1,0,12,12A12,12,0,0,0,128,160Z\"></path></svg>";
|
|
181
|
+
|
|
174
182
|
// These icons are sourced from open source projects.
|
|
175
183
|
//
|
|
176
184
|
// Fluent Icons by Microsoft (https://fluenticons.co/).
|
|
@@ -272,6 +280,11 @@ const icons = new Map([
|
|
|
272
280
|
['tableRow', tableRow],
|
|
273
281
|
['tableMerge', tableMerge],
|
|
274
282
|
['tableSplit', tableSplit],
|
|
283
|
+
// alerts
|
|
284
|
+
['info', info],
|
|
285
|
+
['tip', tip],
|
|
286
|
+
['warning', warning],
|
|
287
|
+
['danger', danger],
|
|
275
288
|
]);
|
|
276
289
|
|
|
277
290
|
// Returns an array representing a list of the document's elements.
|
|
@@ -394,7 +407,7 @@ function hex(value) {
|
|
|
394
407
|
const hexString = Number.parseInt(value, 10).toString(16).toLowerCase();
|
|
395
408
|
return hexString.length > 1 ? hexString : `0${hexString}`;
|
|
396
409
|
}
|
|
397
|
-
// Converts
|
|
410
|
+
// Converts a color in RGB or RGBA format to hex format.
|
|
398
411
|
function toHex(value) {
|
|
399
412
|
return value.replace(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/ig, (match, p1, p2, p3, p4) => {
|
|
400
413
|
if (p4 === undefined) {
|
|
@@ -424,10 +437,10 @@ function debug(...data) {
|
|
|
424
437
|
// value is an array which include types and listeners.
|
|
425
438
|
const eventData = {};
|
|
426
439
|
let lastNodeId = 0;
|
|
427
|
-
// The Nodes
|
|
440
|
+
// The Nodes interface represents a collection of the document's nodes.
|
|
428
441
|
class Nodes {
|
|
429
442
|
constructor(node) {
|
|
430
|
-
node = node !== null && node !==
|
|
443
|
+
node = node !== null && node !== undefined ? node : [];
|
|
431
444
|
this.nodeList = Array.isArray(node) ? node : [node];
|
|
432
445
|
for (let i = 0; i < this.nodeList.length; i++) {
|
|
433
446
|
// lakeId is an expando for preserving node ID.
|
|
@@ -438,12 +451,12 @@ class Nodes {
|
|
|
438
451
|
}
|
|
439
452
|
this.length = this.nodeList.length;
|
|
440
453
|
}
|
|
441
|
-
//
|
|
454
|
+
// The unique ID of the first node.
|
|
442
455
|
get id() {
|
|
443
456
|
const node = this.get(0);
|
|
444
457
|
return node.lakeId;
|
|
445
458
|
}
|
|
446
|
-
//
|
|
459
|
+
// The name of the first node.
|
|
447
460
|
get name() {
|
|
448
461
|
if (this.length === 0) {
|
|
449
462
|
return '';
|
|
@@ -451,7 +464,7 @@ class Nodes {
|
|
|
451
464
|
const node = this.get(0);
|
|
452
465
|
return node.nodeName.toLowerCase();
|
|
453
466
|
}
|
|
454
|
-
//
|
|
467
|
+
// A boolean value indicating whether the first node is an element.
|
|
455
468
|
get isElement() {
|
|
456
469
|
if (this.length === 0) {
|
|
457
470
|
return false;
|
|
@@ -459,7 +472,7 @@ class Nodes {
|
|
|
459
472
|
const node = this.get(0);
|
|
460
473
|
return node.nodeType === Node.ELEMENT_NODE;
|
|
461
474
|
}
|
|
462
|
-
//
|
|
475
|
+
// A boolean value indicating whether the first node is a text.
|
|
463
476
|
get isText() {
|
|
464
477
|
if (this.length === 0) {
|
|
465
478
|
return false;
|
|
@@ -467,65 +480,65 @@ class Nodes {
|
|
|
467
480
|
const node = this.get(0);
|
|
468
481
|
return node.nodeType === Node.TEXT_NODE;
|
|
469
482
|
}
|
|
470
|
-
//
|
|
483
|
+
// A boolean value indicating whether the first node is a block.
|
|
471
484
|
get isBlock() {
|
|
472
485
|
if (this.length === 0) {
|
|
473
486
|
return false;
|
|
474
487
|
}
|
|
475
488
|
return blockTagNames.has(this.name);
|
|
476
489
|
}
|
|
477
|
-
//
|
|
490
|
+
// A boolean value indicating whether the first node is a mark.
|
|
478
491
|
get isMark() {
|
|
479
492
|
if (this.length === 0) {
|
|
480
493
|
return false;
|
|
481
494
|
}
|
|
482
495
|
return markTagNames.has(this.name);
|
|
483
496
|
}
|
|
484
|
-
//
|
|
497
|
+
// A boolean value indicating whether the first node is a void element that cannot have any child nodes.
|
|
485
498
|
get isVoid() {
|
|
486
499
|
if (this.length === 0) {
|
|
487
500
|
return false;
|
|
488
501
|
}
|
|
489
502
|
return voidTagNames.has(this.name);
|
|
490
503
|
}
|
|
491
|
-
//
|
|
504
|
+
// A boolean value indicating whether the first node is a heading.
|
|
492
505
|
get isHeading() {
|
|
493
506
|
if (this.length === 0) {
|
|
494
507
|
return false;
|
|
495
508
|
}
|
|
496
509
|
return headingTagNames.has(this.name);
|
|
497
510
|
}
|
|
498
|
-
//
|
|
511
|
+
// A boolean value indicating whether the first node is a list.
|
|
499
512
|
get isList() {
|
|
500
513
|
if (this.length === 0) {
|
|
501
514
|
return false;
|
|
502
515
|
}
|
|
503
516
|
return listTagNames.has(this.name);
|
|
504
517
|
}
|
|
505
|
-
//
|
|
518
|
+
// A boolean value indicating whether the first node is a table.
|
|
506
519
|
get isTable() {
|
|
507
520
|
if (this.length === 0) {
|
|
508
521
|
return false;
|
|
509
522
|
}
|
|
510
523
|
return tableTagNames.has(this.name);
|
|
511
524
|
}
|
|
512
|
-
//
|
|
525
|
+
// A boolean value indicating whether the first node is a bookmark element.
|
|
513
526
|
get isBookmark() {
|
|
514
527
|
return this.name === 'lake-bookmark';
|
|
515
528
|
}
|
|
516
|
-
//
|
|
529
|
+
// A boolean value indicating whether the first node is a box element.
|
|
517
530
|
get isBox() {
|
|
518
531
|
return this.name === 'lake-box';
|
|
519
532
|
}
|
|
520
|
-
//
|
|
533
|
+
// A boolean value indicating whether the first node is an inline box element.
|
|
521
534
|
get isInlineBox() {
|
|
522
535
|
return this.isBox && this.attr('type') === 'inline';
|
|
523
536
|
}
|
|
524
|
-
//
|
|
537
|
+
// A boolean value indicating whether the first node is a block box element.
|
|
525
538
|
get isBlockBox() {
|
|
526
539
|
return this.isBox && this.attr('type') === 'block';
|
|
527
540
|
}
|
|
528
|
-
//
|
|
541
|
+
// A boolean value indicating whether the first node is a contenteditable element where users can edit the content.
|
|
529
542
|
get isContainer() {
|
|
530
543
|
if (this.length === 0) {
|
|
531
544
|
return false;
|
|
@@ -533,15 +546,15 @@ class Nodes {
|
|
|
533
546
|
const node = this.get(0);
|
|
534
547
|
return this.isElement && node.getAttribute('contenteditable') === 'true';
|
|
535
548
|
}
|
|
536
|
-
//
|
|
549
|
+
// A boolean value indicating whether the first node does not have an ancestor element which contenteditable attribute is true.
|
|
537
550
|
get isOutside() {
|
|
538
551
|
return this.closest('[contenteditable="true"]').length === 0;
|
|
539
552
|
}
|
|
540
|
-
//
|
|
553
|
+
// A boolean value indicating whether the first node has an ancestor element which contenteditable attribute is true.
|
|
541
554
|
get isInside() {
|
|
542
555
|
return !this.isOutside && !this.isContainer;
|
|
543
556
|
}
|
|
544
|
-
//
|
|
557
|
+
// A boolean value indicating whether the first node's parent element is an element which contenteditable attribute is true.
|
|
545
558
|
get isTopInside() {
|
|
546
559
|
if (this.length === 0) {
|
|
547
560
|
return false;
|
|
@@ -552,7 +565,7 @@ class Nodes {
|
|
|
552
565
|
}
|
|
553
566
|
return this.isInside && parentNode.isContainer;
|
|
554
567
|
}
|
|
555
|
-
//
|
|
568
|
+
// A boolean value indicating whether the first node is editable.
|
|
556
569
|
get isContentEditable() {
|
|
557
570
|
if (this.length === 0) {
|
|
558
571
|
return false;
|
|
@@ -570,11 +583,11 @@ class Nodes {
|
|
|
570
583
|
const element = this.get(0);
|
|
571
584
|
return element.isContentEditable;
|
|
572
585
|
}
|
|
573
|
-
//
|
|
586
|
+
// A boolean value indicating whether the first node is indivisible.
|
|
574
587
|
get isIndivisible() {
|
|
575
588
|
return this.isContainer || this.isTable;
|
|
576
589
|
}
|
|
577
|
-
//
|
|
590
|
+
// A boolean value indicating whether the first node is empty.
|
|
578
591
|
get isEmpty() {
|
|
579
592
|
if (this.isBox) {
|
|
580
593
|
return false;
|
|
@@ -594,20 +607,20 @@ class Nodes {
|
|
|
594
607
|
}
|
|
595
608
|
return true;
|
|
596
609
|
}
|
|
597
|
-
//
|
|
610
|
+
// Returns a native node at the specified index.
|
|
598
611
|
get(index) {
|
|
599
612
|
return this.nodeList[index];
|
|
600
613
|
}
|
|
601
|
-
//
|
|
614
|
+
// Returns all native nodes.
|
|
602
615
|
getAll() {
|
|
603
616
|
return this.nodeList;
|
|
604
617
|
}
|
|
605
|
-
//
|
|
618
|
+
// Returns a new Nodes object that includes only the node at the specified index.
|
|
606
619
|
eq(index) {
|
|
607
620
|
const node = this.get(index);
|
|
608
621
|
return new Nodes(node);
|
|
609
622
|
}
|
|
610
|
-
//
|
|
623
|
+
// Executes a provided function once for each node.
|
|
611
624
|
each(callback) {
|
|
612
625
|
const nodes = this.getAll();
|
|
613
626
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -617,7 +630,7 @@ class Nodes {
|
|
|
617
630
|
}
|
|
618
631
|
return this;
|
|
619
632
|
}
|
|
620
|
-
//
|
|
633
|
+
// Executes a provided function once for each element.
|
|
621
634
|
eachElement(callback) {
|
|
622
635
|
const nodes = this.getAll();
|
|
623
636
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -629,12 +642,12 @@ class Nodes {
|
|
|
629
642
|
}
|
|
630
643
|
return this;
|
|
631
644
|
}
|
|
632
|
-
//
|
|
645
|
+
// Returns a new Nodes object with the nodes in reversed order.
|
|
633
646
|
reverse() {
|
|
634
647
|
const nodes = this.getAll().reverse();
|
|
635
648
|
return new Nodes(nodes);
|
|
636
649
|
}
|
|
637
|
-
// Tests whether the
|
|
650
|
+
// Tests whether the first node would be selected by the specified CSS selector.
|
|
638
651
|
matches(selector) {
|
|
639
652
|
if (!this.isElement) {
|
|
640
653
|
return false;
|
|
@@ -642,24 +655,21 @@ class Nodes {
|
|
|
642
655
|
const element = this.get(0);
|
|
643
656
|
return element.matches(selector);
|
|
644
657
|
}
|
|
645
|
-
// Returns a boolean value indicating whether
|
|
646
|
-
// one of its direct children (childNodes), one of the children's direct children, and so on.
|
|
658
|
+
// Returns a boolean value indicating whether the first node is a descendant of a given node,
|
|
659
|
+
// that is the first node itself, one of its direct children (childNodes), one of the children's direct children, and so on.
|
|
647
660
|
contains(otherNode) {
|
|
648
|
-
if (otherNode instanceof Nodes) {
|
|
649
|
-
otherNode = otherNode.get(0);
|
|
650
|
-
}
|
|
651
661
|
const element = this.get(0);
|
|
652
|
-
return element.contains(otherNode);
|
|
662
|
+
return element.contains(otherNode.get(0));
|
|
653
663
|
}
|
|
654
|
-
// Returns a boolean value indicating whether the node and
|
|
655
|
-
isSibling(
|
|
664
|
+
// Returns a boolean value indicating whether the first node and a given node are siblings.
|
|
665
|
+
isSibling(otherNode) {
|
|
656
666
|
if (this.length === 0) {
|
|
657
667
|
return false;
|
|
658
668
|
}
|
|
659
669
|
const parent = this.get(0).parentNode;
|
|
660
|
-
return parent && parent ===
|
|
670
|
+
return parent && parent === otherNode.parent().get(0);
|
|
661
671
|
}
|
|
662
|
-
// Returns the descendants of the first
|
|
672
|
+
// Returns the descendants of the first node that match the specified CSS selector or node path.
|
|
663
673
|
find(selector) {
|
|
664
674
|
if (typeof selector === 'string') {
|
|
665
675
|
const element = this.get(0);
|
|
@@ -675,8 +685,7 @@ class Nodes {
|
|
|
675
685
|
}
|
|
676
686
|
return node;
|
|
677
687
|
}
|
|
678
|
-
// Traverses the first node and its parents (heading toward the document root)
|
|
679
|
-
// until it finds a element that matches the specified CSS selector.
|
|
688
|
+
// Traverses the first node and its parents (heading toward the document root) until it finds an element that matches the specified CSS selector.
|
|
680
689
|
closest(selector) {
|
|
681
690
|
if (this.isText) {
|
|
682
691
|
const element = this.get(0).parentNode;
|
|
@@ -721,7 +730,7 @@ class Nodes {
|
|
|
721
730
|
}
|
|
722
731
|
return block;
|
|
723
732
|
}
|
|
724
|
-
// Traverses the first node and its parents until it finds a
|
|
733
|
+
// Traverses the first node and its parents until it finds a div element which contenteditable attribute is true.
|
|
725
734
|
closestContainer() {
|
|
726
735
|
return this.closest('div[contenteditable="true"]');
|
|
727
736
|
}
|
|
@@ -751,12 +760,12 @@ class Nodes {
|
|
|
751
760
|
const node = this.get(0);
|
|
752
761
|
return new Nodes(node.nextSibling);
|
|
753
762
|
}
|
|
754
|
-
// Returns the first child of the first
|
|
763
|
+
// Returns the first child of the first node.
|
|
755
764
|
first() {
|
|
756
765
|
const element = this.get(0);
|
|
757
766
|
return new Nodes(element.firstChild);
|
|
758
767
|
}
|
|
759
|
-
// Returns the last child of the first
|
|
768
|
+
// Returns the last child of the first node.
|
|
760
769
|
last() {
|
|
761
770
|
const element = this.get(0);
|
|
762
771
|
return new Nodes(element.lastChild);
|
|
@@ -771,7 +780,7 @@ class Nodes {
|
|
|
771
780
|
}
|
|
772
781
|
return i;
|
|
773
782
|
}
|
|
774
|
-
// Returns
|
|
783
|
+
// Returns the path of the first node.
|
|
775
784
|
path() {
|
|
776
785
|
const path = [];
|
|
777
786
|
let node = this.eq(0);
|
|
@@ -791,7 +800,7 @@ class Nodes {
|
|
|
791
800
|
}
|
|
792
801
|
return path.reverse();
|
|
793
802
|
}
|
|
794
|
-
// Returns a list of child nodes of the first
|
|
803
|
+
// Returns a list which contains all of the child nodes of the first node.
|
|
795
804
|
children() {
|
|
796
805
|
const childList = [];
|
|
797
806
|
let child = this.first();
|
|
@@ -801,7 +810,7 @@ class Nodes {
|
|
|
801
810
|
}
|
|
802
811
|
return childList;
|
|
803
812
|
}
|
|
804
|
-
// Returns a
|
|
813
|
+
// Returns a generator that iterates over the descendants of the first node.
|
|
805
814
|
*getWalker() {
|
|
806
815
|
function* iterate(node) {
|
|
807
816
|
if (node.isBox) {
|
|
@@ -819,7 +828,7 @@ class Nodes {
|
|
|
819
828
|
yield node;
|
|
820
829
|
}
|
|
821
830
|
}
|
|
822
|
-
//
|
|
831
|
+
// Sets up an event listener for each element.
|
|
823
832
|
on(type, listener) {
|
|
824
833
|
return this.eachElement(element => {
|
|
825
834
|
element.addEventListener(type, listener, false);
|
|
@@ -833,12 +842,12 @@ class Nodes {
|
|
|
833
842
|
});
|
|
834
843
|
});
|
|
835
844
|
}
|
|
836
|
-
// Removes event
|
|
845
|
+
// Removes event listeners previously registered with on() method.
|
|
837
846
|
off(type, listener) {
|
|
838
847
|
return this.eachElement(element => {
|
|
839
848
|
var _a;
|
|
840
849
|
const elementId = element.lakeId;
|
|
841
|
-
const eventItems = (_a = eventData[elementId]) !== null && _a !==
|
|
850
|
+
const eventItems = (_a = eventData[elementId]) !== null && _a !== undefined ? _a : [];
|
|
842
851
|
for (let i = 0; i < eventItems.length; i++) {
|
|
843
852
|
const item = eventItems[i];
|
|
844
853
|
if (!type || type === item.type && (!listener || listener === item.listener)) {
|
|
@@ -852,40 +861,41 @@ class Nodes {
|
|
|
852
861
|
eventData[elementId] = eventItems.filter((item) => item.type !== '');
|
|
853
862
|
});
|
|
854
863
|
}
|
|
855
|
-
// Executes all event listeners attached to
|
|
864
|
+
// Executes all event listeners attached to all nodes for the given event type.
|
|
856
865
|
emit(type, event) {
|
|
857
866
|
return this.eachElement(element => {
|
|
858
867
|
const elementId = element.lakeId;
|
|
859
868
|
const eventItems = eventData[elementId];
|
|
860
869
|
for (const item of eventItems) {
|
|
861
870
|
if (item.type === type) {
|
|
862
|
-
item.listener(event !== null && event !==
|
|
871
|
+
item.listener(event !== null && event !== undefined ? event : new Event(type));
|
|
863
872
|
}
|
|
864
873
|
}
|
|
865
874
|
});
|
|
866
875
|
}
|
|
867
|
-
//
|
|
876
|
+
// Returns all event listeners attached to the node at the specified index.
|
|
868
877
|
getEventListeners(index) {
|
|
869
878
|
const elementId = this.get(index).lakeId;
|
|
870
879
|
return eventData[elementId];
|
|
871
880
|
}
|
|
872
|
-
// Sets focus on the specified
|
|
881
|
+
// Sets focus on the specified node, if it can be focused.
|
|
873
882
|
focus() {
|
|
874
883
|
const element = this.get(0);
|
|
875
884
|
element.focus();
|
|
876
885
|
return this;
|
|
877
886
|
}
|
|
878
|
-
// Removes focus from the specified
|
|
887
|
+
// Removes focus from the specified node.
|
|
879
888
|
blur() {
|
|
880
889
|
const element = this.get(0);
|
|
881
890
|
element.blur();
|
|
882
891
|
return this;
|
|
883
892
|
}
|
|
884
|
-
// Returns a
|
|
893
|
+
// Returns a copy of the first node. If deep is true, the copy also includes the node's descendants.
|
|
885
894
|
clone(deep = false) {
|
|
886
895
|
const node = this.get(0);
|
|
887
896
|
return new Nodes(node.cloneNode(deep));
|
|
888
897
|
}
|
|
898
|
+
// Returns a boolean value indicating whether the first node has the specified attribute or not.
|
|
889
899
|
hasAttr(attributeName) {
|
|
890
900
|
const element = this.get(0);
|
|
891
901
|
return element.hasAttribute(attributeName);
|
|
@@ -900,21 +910,24 @@ class Nodes {
|
|
|
900
910
|
}
|
|
901
911
|
if (value === undefined) {
|
|
902
912
|
const element = this.get(0);
|
|
903
|
-
return (_a = element.getAttribute(attributeName)) !== null && _a !==
|
|
913
|
+
return (_a = element.getAttribute(attributeName)) !== null && _a !== undefined ? _a : '';
|
|
904
914
|
}
|
|
905
915
|
return this.eachElement(element => {
|
|
906
916
|
element.setAttribute(attributeName, value);
|
|
907
917
|
});
|
|
908
918
|
}
|
|
919
|
+
// Removes the attribute with the specified name from every element.
|
|
909
920
|
removeAttr(attributeName) {
|
|
910
921
|
return this.eachElement(element => {
|
|
911
922
|
element.removeAttribute(attributeName);
|
|
912
923
|
});
|
|
913
924
|
}
|
|
925
|
+
// Returns a boolean value indicating whether the first node has the specified class or not.
|
|
914
926
|
hasClass(className) {
|
|
915
927
|
const element = this.get(0);
|
|
916
928
|
return inString(element.className, className, ' ');
|
|
917
929
|
}
|
|
930
|
+
// Adds the given class to every element.
|
|
918
931
|
addClass(className) {
|
|
919
932
|
if (Array.isArray(className)) {
|
|
920
933
|
for (const name of className) {
|
|
@@ -929,6 +942,7 @@ class Nodes {
|
|
|
929
942
|
element.classList.add(className);
|
|
930
943
|
});
|
|
931
944
|
}
|
|
945
|
+
// Removes the given class from every element.
|
|
932
946
|
removeClass(className) {
|
|
933
947
|
if (Array.isArray(className)) {
|
|
934
948
|
for (const name of className) {
|
|
@@ -946,6 +960,8 @@ class Nodes {
|
|
|
946
960
|
}
|
|
947
961
|
});
|
|
948
962
|
}
|
|
963
|
+
// Returns the value of the given CSS property of the first node,
|
|
964
|
+
// after applying active stylesheets and resolving any basic computation this value may contain.
|
|
949
965
|
computedCSS(propertyName) {
|
|
950
966
|
const element = this.get(0);
|
|
951
967
|
return getCSS(element, propertyName);
|
|
@@ -968,26 +984,28 @@ class Nodes {
|
|
|
968
984
|
}
|
|
969
985
|
});
|
|
970
986
|
}
|
|
971
|
-
// Returns the width of of the first
|
|
987
|
+
// Returns the width of of the first node.
|
|
972
988
|
width() {
|
|
973
989
|
const element = this.get(0);
|
|
974
990
|
return element.offsetWidth;
|
|
975
991
|
}
|
|
976
|
-
// Returns the interior width of the first
|
|
992
|
+
// Returns the interior width of the first node, which does not include padding.
|
|
977
993
|
innerWidth() {
|
|
978
994
|
const paddingLeft = Number.parseInt(this.computedCSS('padding-left'), 10) || 0;
|
|
979
995
|
const paddingRight = Number.parseInt(this.computedCSS('padding-right'), 10) || 0;
|
|
980
996
|
return this.width() - paddingLeft - paddingRight;
|
|
981
997
|
}
|
|
982
|
-
// Returns the height of of the first
|
|
998
|
+
// Returns the height of of the first node.
|
|
983
999
|
height() {
|
|
984
1000
|
const element = this.get(0);
|
|
985
1001
|
return element.offsetHeight;
|
|
986
1002
|
}
|
|
1003
|
+
// Displays all nodes.
|
|
987
1004
|
show(displayType = 'block') {
|
|
988
1005
|
this.css('display', displayType);
|
|
989
1006
|
return this;
|
|
990
1007
|
}
|
|
1008
|
+
// Hides all nodes.
|
|
991
1009
|
hide() {
|
|
992
1010
|
this.css('display', 'none');
|
|
993
1011
|
return this;
|
|
@@ -1006,7 +1024,7 @@ class Nodes {
|
|
|
1006
1024
|
if (value === undefined) {
|
|
1007
1025
|
const node = this.get(0);
|
|
1008
1026
|
if (this.isText) {
|
|
1009
|
-
return (_a = node.nodeValue) !== null && _a !==
|
|
1027
|
+
return (_a = node.nodeValue) !== null && _a !== undefined ? _a : '';
|
|
1010
1028
|
}
|
|
1011
1029
|
const element = node;
|
|
1012
1030
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
|
|
@@ -1025,16 +1043,17 @@ class Nodes {
|
|
|
1025
1043
|
element.value = value;
|
|
1026
1044
|
});
|
|
1027
1045
|
}
|
|
1046
|
+
// Returns the HTML string describing the first node including its descendants.
|
|
1028
1047
|
outerHTML() {
|
|
1029
1048
|
const element = this.get(0);
|
|
1030
1049
|
return element.outerHTML;
|
|
1031
1050
|
}
|
|
1032
|
-
// Removes all child nodes
|
|
1051
|
+
// Removes all child nodes for each element.
|
|
1033
1052
|
empty() {
|
|
1034
1053
|
this.html('');
|
|
1035
1054
|
return this;
|
|
1036
1055
|
}
|
|
1037
|
-
// Inserts the specified content
|
|
1056
|
+
// Inserts the specified content just inside the first node, before its first child.
|
|
1038
1057
|
prepend(content) {
|
|
1039
1058
|
const element = this.get(0);
|
|
1040
1059
|
if (typeof content === 'string') {
|
|
@@ -1060,7 +1079,7 @@ class Nodes {
|
|
|
1060
1079
|
}
|
|
1061
1080
|
return this;
|
|
1062
1081
|
}
|
|
1063
|
-
// Inserts the specified content
|
|
1082
|
+
// Inserts the specified content just inside the first node, after its last child.
|
|
1064
1083
|
append(content) {
|
|
1065
1084
|
const element = this.get(0);
|
|
1066
1085
|
if (typeof content === 'string') {
|
|
@@ -1124,7 +1143,7 @@ class Nodes {
|
|
|
1124
1143
|
}
|
|
1125
1144
|
return this;
|
|
1126
1145
|
}
|
|
1127
|
-
// Replaces the first node with the
|
|
1146
|
+
// Replaces the first node with the given new content.
|
|
1128
1147
|
replaceWith(newContent) {
|
|
1129
1148
|
const node = this.get(0);
|
|
1130
1149
|
if (!node.parentNode) {
|
|
@@ -1140,9 +1159,7 @@ class Nodes {
|
|
|
1140
1159
|
node.parentNode.replaceChild(target, node);
|
|
1141
1160
|
return this;
|
|
1142
1161
|
}
|
|
1143
|
-
// Removes
|
|
1144
|
-
// keepChildren parameter:
|
|
1145
|
-
// A boolean value; true only removes each node and keeps all descended nodes; false removes the descendants; if omitted, it defaults to false.
|
|
1162
|
+
// Removes all nodes from the DOM.
|
|
1146
1163
|
remove(keepChildren = false) {
|
|
1147
1164
|
this.each(node => {
|
|
1148
1165
|
if (!node.parentNode) {
|
|
@@ -1160,7 +1177,7 @@ class Nodes {
|
|
|
1160
1177
|
});
|
|
1161
1178
|
return this;
|
|
1162
1179
|
}
|
|
1163
|
-
//
|
|
1180
|
+
// Splits the first node, which must be a text node, into two nodes at the specified offset, keeping both as siblings in the tree.
|
|
1164
1181
|
splitText(offset) {
|
|
1165
1182
|
if (!this.isText) {
|
|
1166
1183
|
return new Nodes();
|
|
@@ -1169,7 +1186,7 @@ class Nodes {
|
|
|
1169
1186
|
const newNode = node.splitText(offset);
|
|
1170
1187
|
return new Nodes(newNode);
|
|
1171
1188
|
}
|
|
1172
|
-
// Returns information
|
|
1189
|
+
// Returns information about the first node, which is used for debugging.
|
|
1173
1190
|
toString() {
|
|
1174
1191
|
if (this.length === 0) {
|
|
1175
1192
|
return '';
|
|
@@ -1181,13 +1198,13 @@ class Nodes {
|
|
|
1181
1198
|
}
|
|
1182
1199
|
return `node (${node.lakeId}): ${nodeValue}`;
|
|
1183
1200
|
}
|
|
1184
|
-
// Prints information
|
|
1201
|
+
// Prints information about the first node, which is used for debugging.
|
|
1185
1202
|
info() {
|
|
1186
1203
|
debug(this.toString());
|
|
1187
1204
|
}
|
|
1188
1205
|
}
|
|
1189
1206
|
|
|
1190
|
-
// Returns
|
|
1207
|
+
// Returns a Nodes object representing a list of the document's nodes.
|
|
1191
1208
|
function query(content) {
|
|
1192
1209
|
if (content instanceof Nodes) {
|
|
1193
1210
|
return content;
|
|
@@ -1205,10 +1222,10 @@ const characterMap = new Map([
|
|
|
1205
1222
|
]);
|
|
1206
1223
|
// Converts all of the reserved characters in the specified string to HTML entities.
|
|
1207
1224
|
function encode(value) {
|
|
1208
|
-
return value.replace(/[&<>"\xA0]/g, match => { var _a; return (_a = characterMap.get(match)) !== null && _a !==
|
|
1225
|
+
return value.replace(/[&<>"\xA0]/g, match => { var _a; return (_a = characterMap.get(match)) !== null && _a !== undefined ? _a : ''; });
|
|
1209
1226
|
}
|
|
1210
1227
|
|
|
1211
|
-
//
|
|
1228
|
+
// A tag function for converting all of the reserved characters in the specified string to HTML entities.
|
|
1212
1229
|
function template(strings, ...keys) {
|
|
1213
1230
|
let content = strings[0];
|
|
1214
1231
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -1225,16 +1242,16 @@ function template(strings, ...keys) {
|
|
|
1225
1242
|
return content;
|
|
1226
1243
|
}
|
|
1227
1244
|
|
|
1228
|
-
// The Fragment
|
|
1245
|
+
// The Fragment interface represents a minimal document object that has no parent.
|
|
1229
1246
|
class Fragment {
|
|
1230
1247
|
constructor(fragment) {
|
|
1231
|
-
this.fragment = fragment !== null && fragment !==
|
|
1248
|
+
this.fragment = fragment !== null && fragment !== undefined ? fragment : document.createDocumentFragment();
|
|
1232
1249
|
}
|
|
1233
|
-
//
|
|
1250
|
+
// Returns a native DocumentFragment object from the fragment.
|
|
1234
1251
|
get() {
|
|
1235
1252
|
return this.fragment;
|
|
1236
1253
|
}
|
|
1237
|
-
// Returns the descendants of the fragment
|
|
1254
|
+
// Returns the descendants of the fragment that match the specified CSS selector.
|
|
1238
1255
|
find(selector) {
|
|
1239
1256
|
const nodeList = [];
|
|
1240
1257
|
let child = new Nodes(this.fragment.firstChild);
|
|
@@ -1251,49 +1268,49 @@ class Fragment {
|
|
|
1251
1268
|
}
|
|
1252
1269
|
return new Nodes(nodeList);
|
|
1253
1270
|
}
|
|
1254
|
-
// Inserts the specified
|
|
1255
|
-
append(
|
|
1256
|
-
query(
|
|
1271
|
+
// Inserts the specified content just inside the fragment, after its last child.
|
|
1272
|
+
append(content) {
|
|
1273
|
+
query(content).each(nativeNode => {
|
|
1257
1274
|
this.fragment.appendChild(nativeNode);
|
|
1258
1275
|
});
|
|
1259
1276
|
}
|
|
1260
1277
|
}
|
|
1261
1278
|
|
|
1262
|
-
// The Range
|
|
1279
|
+
// The Range interface represents a fragment of a document that can contain nodes and parts of text nodes.
|
|
1263
1280
|
class Range {
|
|
1264
1281
|
constructor(range) {
|
|
1265
|
-
this.range = range !== null && range !==
|
|
1282
|
+
this.range = range !== null && range !== undefined ? range : document.createRange();
|
|
1266
1283
|
}
|
|
1267
|
-
//
|
|
1284
|
+
// A node within which the range starts.
|
|
1268
1285
|
get startNode() {
|
|
1269
1286
|
return new Nodes(this.range.startContainer);
|
|
1270
1287
|
}
|
|
1271
|
-
//
|
|
1288
|
+
// A number representing where in the startNode the range starts.
|
|
1272
1289
|
get startOffset() {
|
|
1273
1290
|
return this.range.startOffset;
|
|
1274
1291
|
}
|
|
1275
|
-
//
|
|
1292
|
+
// A node within which the range ends.
|
|
1276
1293
|
get endNode() {
|
|
1277
1294
|
return new Nodes(this.range.endContainer);
|
|
1278
1295
|
}
|
|
1279
|
-
//
|
|
1296
|
+
// A number representing where in the endNode the range ends.
|
|
1280
1297
|
get endOffset() {
|
|
1281
1298
|
return this.range.endOffset;
|
|
1282
1299
|
}
|
|
1283
|
-
//
|
|
1300
|
+
// The deepest — or furthest down the document tree — node that contains both boundary points of the range.
|
|
1284
1301
|
get commonAncestor() {
|
|
1285
1302
|
return new Nodes(this.range.commonAncestorContainer);
|
|
1286
1303
|
}
|
|
1287
|
-
//
|
|
1304
|
+
// A boolean value indicating whether the range's start and end points are at the same position.
|
|
1288
1305
|
get isCollapsed() {
|
|
1289
1306
|
return this.range.collapsed;
|
|
1290
1307
|
}
|
|
1291
|
-
//
|
|
1308
|
+
// A boolean value indicating whether the range's start point is in a box.
|
|
1292
1309
|
get isBox() {
|
|
1293
1310
|
const boxNode = this.commonAncestor.closest('lake-box');
|
|
1294
1311
|
return boxNode.length > 0;
|
|
1295
1312
|
}
|
|
1296
|
-
//
|
|
1313
|
+
// A boolean value indicating whether the commonAncestor is in the start position of a box.
|
|
1297
1314
|
// case 1: <lake-box><span class="lake-box-strip">|</span><div class="lake-box-container"></div> ...
|
|
1298
1315
|
// case 2: <lake-box><span class="lake-box-strip"></span>|<div class="lake-box-container"></div> ...
|
|
1299
1316
|
// case 3: <lake-box>|<span class="lake-box-strip"></span><div class="lake-box-container"></div> ...
|
|
@@ -1305,7 +1322,7 @@ class Range {
|
|
|
1305
1322
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1306
1323
|
return this.compareBeforeNode(boxContainer) >= 0;
|
|
1307
1324
|
}
|
|
1308
|
-
//
|
|
1325
|
+
// A boolean value indicating whether the commonAncestor is in the center position of a box.
|
|
1309
1326
|
// case 1: ... <div class="lake-box-container"><div>|</div></div> ...
|
|
1310
1327
|
// case 2: ... <div class="lake-box-container"><div></div>|</div> ...
|
|
1311
1328
|
get isBoxCenter() {
|
|
@@ -1318,7 +1335,7 @@ class Range {
|
|
|
1318
1335
|
// case: ... <div class="lake-box-container">|<div></div></div> ...
|
|
1319
1336
|
return this.isCollapsed && this.startNode.get(0) === boxContainer.get(0) && this.startOffset === 0;
|
|
1320
1337
|
}
|
|
1321
|
-
//
|
|
1338
|
+
// A boolean value indicating whether commonAncestor is in the end position of a box.
|
|
1322
1339
|
// case 1: ... <div class="lake-box-container"></div><span class="lake-box-strip">|</span></lake-box>
|
|
1323
1340
|
// case 2: ... <div class="lake-box-container"></div>|<span class="lake-box-strip"></span></lake-box>
|
|
1324
1341
|
// case 3: ... <div class="lake-box-container"></div><span class="lake-box-strip"></span>|</lake-box>
|
|
@@ -1330,7 +1347,7 @@ class Range {
|
|
|
1330
1347
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1331
1348
|
return this.compareAfterNode(boxContainer) <= 0;
|
|
1332
1349
|
}
|
|
1333
|
-
//
|
|
1350
|
+
// A boolean value indicating whether commonAncestor is inside the container of a box.
|
|
1334
1351
|
// case 1: ... <div class="lake-box-container"><div>|</div></div> ...
|
|
1335
1352
|
// case 2: ... <div class="lake-box-container"><div></div>|</div> ...
|
|
1336
1353
|
get isInsideBox() {
|
|
@@ -1348,7 +1365,7 @@ class Range {
|
|
|
1348
1365
|
}
|
|
1349
1366
|
return this.compareBeforeNode(boxContainer) < 0 && this.compareAfterNode(boxContainer) > 0;
|
|
1350
1367
|
}
|
|
1351
|
-
//
|
|
1368
|
+
// A boolean value indicating whether the range is inoperative.
|
|
1352
1369
|
get isInoperative() {
|
|
1353
1370
|
if (this.commonAncestor.isOutside) {
|
|
1354
1371
|
return true;
|
|
@@ -1362,7 +1379,7 @@ class Range {
|
|
|
1362
1379
|
}
|
|
1363
1380
|
return false;
|
|
1364
1381
|
}
|
|
1365
|
-
//
|
|
1382
|
+
// Returns a native Range object from the range.
|
|
1366
1383
|
get() {
|
|
1367
1384
|
return this.range;
|
|
1368
1385
|
}
|
|
@@ -1419,11 +1436,13 @@ class Range {
|
|
|
1419
1436
|
height: height > 0 ? height : 1,
|
|
1420
1437
|
});
|
|
1421
1438
|
}
|
|
1422
|
-
// Returns
|
|
1439
|
+
// Returns -1, 0, or 1 depending on whether the specified node is before, the same as, or after the range.
|
|
1440
|
+
// −1 if the point is before the range. 0 if the point is in the range. 1 if the point is after the range.
|
|
1423
1441
|
comparePoint(node, offset) {
|
|
1424
1442
|
return this.range.comparePoint(node.get(0), offset);
|
|
1425
1443
|
}
|
|
1426
1444
|
// Returns -1, 0, or 1 depending on whether the beginning of the specified node is before, the same as, or after the range.
|
|
1445
|
+
// −1 if the beginning of the node is before the range. 0 if the beginning of the node is in the range. 1 if the beginning of the node is after the range.
|
|
1427
1446
|
compareBeforeNode(node) {
|
|
1428
1447
|
const targetRange = new Range();
|
|
1429
1448
|
if (node.isText) {
|
|
@@ -1436,11 +1455,12 @@ class Range {
|
|
|
1436
1455
|
return this.comparePoint(targetRange.startNode, targetRange.startOffset);
|
|
1437
1456
|
}
|
|
1438
1457
|
// Returns -1, 0, or 1 depending on whether the end of the specified node is before, the same as, or after the range.
|
|
1458
|
+
// −1 if the end of the node is before the range. 0 if the end of the node is in the range. 1 if the end of the node is after the range.
|
|
1439
1459
|
compareAfterNode(node) {
|
|
1440
1460
|
var _a;
|
|
1441
1461
|
const targetRange = new Range();
|
|
1442
1462
|
if (node.isText) {
|
|
1443
|
-
const nodeValue = (_a = node.get(0).nodeValue) !== null && _a !==
|
|
1463
|
+
const nodeValue = (_a = node.get(0).nodeValue) !== null && _a !== undefined ? _a : '';
|
|
1444
1464
|
targetRange.setStart(node, nodeValue.length);
|
|
1445
1465
|
}
|
|
1446
1466
|
else {
|
|
@@ -1449,7 +1469,7 @@ class Range {
|
|
|
1449
1469
|
targetRange.collapseToStart();
|
|
1450
1470
|
return this.comparePoint(targetRange.startNode, targetRange.startOffset);
|
|
1451
1471
|
}
|
|
1452
|
-
//
|
|
1472
|
+
// Returns a boolean value indicating whether the specified node is part of the range or intersects the range.
|
|
1453
1473
|
intersectsNode(node) {
|
|
1454
1474
|
return this.range.intersectsNode(node.get(0));
|
|
1455
1475
|
}
|
|
@@ -1457,11 +1477,11 @@ class Range {
|
|
|
1457
1477
|
setStart(node, offset) {
|
|
1458
1478
|
this.range.setStart(node.get(0), offset);
|
|
1459
1479
|
}
|
|
1460
|
-
// Sets the start position of the range
|
|
1480
|
+
// Sets the start position of the range to the beginning of the specified node.
|
|
1461
1481
|
setStartBefore(node) {
|
|
1462
1482
|
this.range.setStartBefore(node.get(0));
|
|
1463
1483
|
}
|
|
1464
|
-
// Sets the start position of the range
|
|
1484
|
+
// Sets the start position of the range to the end of the specified node.
|
|
1465
1485
|
setStartAfter(node) {
|
|
1466
1486
|
this.range.setStartAfter(node.get(0));
|
|
1467
1487
|
}
|
|
@@ -1469,19 +1489,19 @@ class Range {
|
|
|
1469
1489
|
setEnd(node, offset) {
|
|
1470
1490
|
this.range.setEnd(node.get(0), offset);
|
|
1471
1491
|
}
|
|
1472
|
-
// Sets the end position of the range
|
|
1492
|
+
// Sets the end position of the range to the beginning of the specified node.
|
|
1473
1493
|
setEndBefore(node) {
|
|
1474
1494
|
this.range.setEndBefore(node.get(0));
|
|
1475
1495
|
}
|
|
1476
|
-
// Sets the end position of the range
|
|
1496
|
+
// Sets the end position of the range to the end of the specified node.
|
|
1477
1497
|
setEndAfter(node) {
|
|
1478
1498
|
this.range.setEndAfter(node.get(0));
|
|
1479
1499
|
}
|
|
1480
|
-
// Collapses the range to
|
|
1500
|
+
// Collapses the range to its start.
|
|
1481
1501
|
collapseToStart() {
|
|
1482
1502
|
this.range.collapse(true);
|
|
1483
1503
|
}
|
|
1484
|
-
// Collapses the range to
|
|
1504
|
+
// Collapses the range to its end.
|
|
1485
1505
|
collapseToEnd() {
|
|
1486
1506
|
this.range.collapse(false);
|
|
1487
1507
|
}
|
|
@@ -1493,7 +1513,7 @@ class Range {
|
|
|
1493
1513
|
selectNodeContents(node) {
|
|
1494
1514
|
this.range.selectNodeContents(node.get(0));
|
|
1495
1515
|
}
|
|
1496
|
-
//
|
|
1516
|
+
// Collapses the range to the center position of the specified box.
|
|
1497
1517
|
selectBox(boxNode) {
|
|
1498
1518
|
const boxContainer = boxNode.find('.lake-box-container');
|
|
1499
1519
|
if (boxContainer.length === 0) {
|
|
@@ -1502,7 +1522,7 @@ class Range {
|
|
|
1502
1522
|
this.setStart(boxContainer, 0);
|
|
1503
1523
|
this.collapseToStart();
|
|
1504
1524
|
}
|
|
1505
|
-
//
|
|
1525
|
+
// Collapses the range to the start position of the specified box.
|
|
1506
1526
|
selectBoxStart(boxNode) {
|
|
1507
1527
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1508
1528
|
if (boxStrip.length === 0) {
|
|
@@ -1511,7 +1531,7 @@ class Range {
|
|
|
1511
1531
|
this.selectNodeContents(boxStrip.eq(0));
|
|
1512
1532
|
this.collapseToStart();
|
|
1513
1533
|
}
|
|
1514
|
-
//
|
|
1534
|
+
// Collapses the range to the end position of the specified box.
|
|
1515
1535
|
selectBoxEnd(boxNode) {
|
|
1516
1536
|
const boxStrip = boxNode.find('.lake-box-strip');
|
|
1517
1537
|
if (boxStrip.length === 0) {
|
|
@@ -1520,7 +1540,7 @@ class Range {
|
|
|
1520
1540
|
this.selectNodeContents(boxStrip.eq(1));
|
|
1521
1541
|
this.collapseToStart();
|
|
1522
1542
|
}
|
|
1523
|
-
// Collapses the range
|
|
1543
|
+
// Collapses the range to the deepest point at the beginning of the contents of the specified node.
|
|
1524
1544
|
shrinkBefore(node) {
|
|
1525
1545
|
if (node.isBox) {
|
|
1526
1546
|
this.selectBoxStart(node);
|
|
@@ -1544,7 +1564,7 @@ class Range {
|
|
|
1544
1564
|
}
|
|
1545
1565
|
this.collapseToStart();
|
|
1546
1566
|
}
|
|
1547
|
-
// Collapses the range
|
|
1567
|
+
// Collapses the range to the deepest point at the end of the contents of the specified node.
|
|
1548
1568
|
shrinkAfter(node) {
|
|
1549
1569
|
if (node.isBox) {
|
|
1550
1570
|
this.selectBoxEnd(node);
|
|
@@ -1570,7 +1590,7 @@ class Range {
|
|
|
1570
1590
|
this.collapseToEnd();
|
|
1571
1591
|
this.adjustBr();
|
|
1572
1592
|
}
|
|
1573
|
-
//
|
|
1593
|
+
// Sets the start and end positions of the range to the deepest start position and end position of the contents of the specified node.
|
|
1574
1594
|
// <div>[<p><strong>foo</strong></p>]</div>
|
|
1575
1595
|
// to
|
|
1576
1596
|
// <div><p><strong>[foo]</strong></p></div>
|
|
@@ -1593,7 +1613,7 @@ class Range {
|
|
|
1593
1613
|
this.setEnd(child, child.children().length);
|
|
1594
1614
|
}
|
|
1595
1615
|
}
|
|
1596
|
-
// Relocates the start and end
|
|
1616
|
+
// Relocates the start and end positions of the range for boxes.
|
|
1597
1617
|
adjustBox() {
|
|
1598
1618
|
const startBoxNode = this.startNode.closest('lake-box');
|
|
1599
1619
|
if (startBoxNode.length > 0) {
|
|
@@ -1618,7 +1638,7 @@ class Range {
|
|
|
1618
1638
|
}
|
|
1619
1639
|
}
|
|
1620
1640
|
}
|
|
1621
|
-
// Relocates the
|
|
1641
|
+
// Relocates the start and end positions of the range for tables.
|
|
1622
1642
|
adjustTable() {
|
|
1623
1643
|
const startTable = this.startNode.closest('table');
|
|
1624
1644
|
const endTable = this.endNode.closest('table');
|
|
@@ -1632,7 +1652,7 @@ class Range {
|
|
|
1632
1652
|
this.shrink();
|
|
1633
1653
|
}
|
|
1634
1654
|
}
|
|
1635
|
-
// Relocates the start
|
|
1655
|
+
// Relocates the start and end positions of the range for blocks.
|
|
1636
1656
|
// case 1:
|
|
1637
1657
|
// <p>foo</p>|<p>bar</p>
|
|
1638
1658
|
// to
|
|
@@ -1666,13 +1686,13 @@ class Range {
|
|
|
1666
1686
|
this.shrinkBefore(nextBlock);
|
|
1667
1687
|
}
|
|
1668
1688
|
}
|
|
1669
|
-
// Relocates the start and end
|
|
1689
|
+
// Relocates the start and end positions of the range for boxes, tables, and blocks.
|
|
1670
1690
|
adjust() {
|
|
1671
1691
|
this.adjustBox();
|
|
1672
1692
|
this.adjustTable();
|
|
1673
1693
|
this.adjustBlock();
|
|
1674
1694
|
}
|
|
1675
|
-
// Relocates the start and end
|
|
1695
|
+
// Relocates the start and end positions of the range for <br /> elements.
|
|
1676
1696
|
// In composition mode (e.g., when a user starts entering a Chinese character using a Pinyin IME),
|
|
1677
1697
|
// uncompleted text is inserted if the cursor is positioned behind a <br> tag.
|
|
1678
1698
|
// To fix this bug, the cursor needs to be moved to the front of the <br> tag.
|
|
@@ -1687,7 +1707,7 @@ class Range {
|
|
|
1687
1707
|
this.collapseToStart();
|
|
1688
1708
|
}
|
|
1689
1709
|
}
|
|
1690
|
-
// Returns the
|
|
1710
|
+
// Returns the node immediately preceding the start position of the range.
|
|
1691
1711
|
getPrevNode() {
|
|
1692
1712
|
let prevNode;
|
|
1693
1713
|
if (this.startNode.isText) {
|
|
@@ -1701,9 +1721,9 @@ class Range {
|
|
|
1701
1721
|
else {
|
|
1702
1722
|
prevNode = this.startNode.children()[this.startOffset - 1];
|
|
1703
1723
|
}
|
|
1704
|
-
return prevNode !== null && prevNode !==
|
|
1724
|
+
return prevNode !== null && prevNode !== undefined ? prevNode : new Nodes();
|
|
1705
1725
|
}
|
|
1706
|
-
// Returns the
|
|
1726
|
+
// Returns the node immediately following the end position of the range.
|
|
1707
1727
|
getNextNode() {
|
|
1708
1728
|
let nextNode;
|
|
1709
1729
|
if (this.endNode.isText) {
|
|
@@ -1717,9 +1737,9 @@ class Range {
|
|
|
1717
1737
|
else {
|
|
1718
1738
|
nextNode = this.endNode.children()[this.endOffset];
|
|
1719
1739
|
}
|
|
1720
|
-
return nextNode !== null && nextNode !==
|
|
1740
|
+
return nextNode !== null && nextNode !== undefined ? nextNode : new Nodes();
|
|
1721
1741
|
}
|
|
1722
|
-
// Returns
|
|
1742
|
+
// Returns the boxes contained within or intersected by the range.
|
|
1723
1743
|
getBoxes() {
|
|
1724
1744
|
if (this.isCollapsed) {
|
|
1725
1745
|
const startBox = this.startNode.closest('lake-box');
|
|
@@ -1735,7 +1755,7 @@ class Range {
|
|
|
1735
1755
|
}
|
|
1736
1756
|
return nodeList;
|
|
1737
1757
|
}
|
|
1738
|
-
// Returns
|
|
1758
|
+
// Returns the blocks contained within or intersected by the range.
|
|
1739
1759
|
getBlocks() {
|
|
1740
1760
|
if (this.isCollapsed) {
|
|
1741
1761
|
const startBlock = this.startNode.closestOperableBlock();
|
|
@@ -1774,7 +1794,7 @@ class Range {
|
|
|
1774
1794
|
}
|
|
1775
1795
|
return blocks;
|
|
1776
1796
|
}
|
|
1777
|
-
// Returns
|
|
1797
|
+
// Returns the marks and text nodes contained within or intersected by the range.
|
|
1778
1798
|
getMarks(hasText = false) {
|
|
1779
1799
|
const marks = [];
|
|
1780
1800
|
if (this.commonAncestor.isText && hasText) {
|
|
@@ -1806,7 +1826,7 @@ class Range {
|
|
|
1806
1826
|
}
|
|
1807
1827
|
return marks;
|
|
1808
1828
|
}
|
|
1809
|
-
// Returns the text
|
|
1829
|
+
// Returns the text from the start position of the closest block to the start position of the range.
|
|
1810
1830
|
// "<p>one<anchor />two<focus />three</p>" returns "one".
|
|
1811
1831
|
getStartText() {
|
|
1812
1832
|
const node = this.startNode;
|
|
@@ -1829,7 +1849,7 @@ class Range {
|
|
|
1829
1849
|
}
|
|
1830
1850
|
return text;
|
|
1831
1851
|
}
|
|
1832
|
-
// Returns the text
|
|
1852
|
+
// Returns the text from the end position of the range to the end position of the closest block.
|
|
1833
1853
|
// "<p>one<anchor />two<focus />three</p>" returns "three".
|
|
1834
1854
|
getEndText() {
|
|
1835
1855
|
const node = this.endNode;
|
|
@@ -1852,9 +1872,9 @@ class Range {
|
|
|
1852
1872
|
}
|
|
1853
1873
|
return text;
|
|
1854
1874
|
}
|
|
1855
|
-
// Returns a new
|
|
1875
|
+
// Returns a new range from the specified character to the start position of the range.
|
|
1856
1876
|
// The specified character must be preceded by a whitespace or be at the beginning of a paragraph,
|
|
1857
|
-
// without being adjacent to other characters.
|
|
1877
|
+
// without being adjacent to other characters. It will return null if not.
|
|
1858
1878
|
getCharacterRange(character) {
|
|
1859
1879
|
const newRange = this.clone();
|
|
1860
1880
|
newRange.shrink();
|
|
@@ -1891,15 +1911,15 @@ class Range {
|
|
|
1891
1911
|
}
|
|
1892
1912
|
return newRange;
|
|
1893
1913
|
}
|
|
1894
|
-
// Returns a
|
|
1914
|
+
// Returns a copy of the range.
|
|
1895
1915
|
clone() {
|
|
1896
1916
|
return new Range(this.range.cloneRange());
|
|
1897
1917
|
}
|
|
1898
|
-
// Returns a
|
|
1918
|
+
// Returns a DocumentFragment object copying the nodes included in the range.
|
|
1899
1919
|
cloneContents() {
|
|
1900
1920
|
return this.range.cloneContents();
|
|
1901
1921
|
}
|
|
1902
|
-
// Prints information
|
|
1922
|
+
// Prints information about the range, which is used for debugging.
|
|
1903
1923
|
info() {
|
|
1904
1924
|
debug('--- range information ---');
|
|
1905
1925
|
debug('start node:', this.startNode.toString(), ', offset:', this.startOffset);
|
|
@@ -2589,7 +2609,7 @@ const toolbarItems = [
|
|
|
2589
2609
|
const currentValues = [];
|
|
2590
2610
|
for (const item of activeItems) {
|
|
2591
2611
|
if (item.node.isMark) {
|
|
2592
|
-
const name = (_a = tagPluginNameMap.get(item.name)) !== null && _a !==
|
|
2612
|
+
const name = (_a = tagPluginNameMap.get(item.name)) !== null && _a !== undefined ? _a : item.name;
|
|
2593
2613
|
currentValues.push(name);
|
|
2594
2614
|
}
|
|
2595
2615
|
}
|
|
@@ -2834,7 +2854,7 @@ function uploadFile(config) {
|
|
|
2834
2854
|
return box;
|
|
2835
2855
|
}
|
|
2836
2856
|
|
|
2837
|
-
// The Button
|
|
2857
|
+
// The Button interface represents a UI component clicked by a user. Once clicked, it then performs an action.
|
|
2838
2858
|
class Button {
|
|
2839
2859
|
constructor(config) {
|
|
2840
2860
|
this.config = config;
|
|
@@ -2849,6 +2869,7 @@ class Button {
|
|
|
2849
2869
|
this.node.attr('tabindex', config.tabIndex.toString());
|
|
2850
2870
|
}
|
|
2851
2871
|
}
|
|
2872
|
+
// Renders the button.
|
|
2852
2873
|
render() {
|
|
2853
2874
|
const config = this.config;
|
|
2854
2875
|
const buttonNode = this.node;
|
|
@@ -2908,7 +2929,7 @@ function modifierText(value, userAgent) {
|
|
|
2908
2929
|
if (typeof window === 'undefined') {
|
|
2909
2930
|
return value;
|
|
2910
2931
|
}
|
|
2911
|
-
userAgent = userAgent !== null && userAgent !==
|
|
2932
|
+
userAgent = userAgent !== null && userAgent !== undefined ? userAgent : navigator.userAgent;
|
|
2912
2933
|
const isMac = userAgent.indexOf('Mac OS X') >= 0;
|
|
2913
2934
|
const modText = isMac ? '⌘' : 'Ctrl';
|
|
2914
2935
|
return value.replace(/(^|\+|\s)mod(\+|\s|$)/g, `$1${modText}$2`);
|
|
@@ -2990,6 +3011,14 @@ var enUS = {
|
|
|
2990
3011
|
checklistDesc: 'Create a checklist',
|
|
2991
3012
|
table: 'Table',
|
|
2992
3013
|
tableDesc: 'Insert a table',
|
|
3014
|
+
infoAlert: 'Info alert',
|
|
3015
|
+
infoAlertDesc: 'Create an info alert',
|
|
3016
|
+
tipAlert: 'Tip alert',
|
|
3017
|
+
tipAlertDesc: 'Create a tip alert',
|
|
3018
|
+
warningAlert: 'Warning alert',
|
|
3019
|
+
warningAlertDesc: 'Create a warning alert',
|
|
3020
|
+
dangerAlert: 'Danger alert',
|
|
3021
|
+
dangerAlertDesc: 'Create a danger alert',
|
|
2993
3022
|
hr: 'Horizontal line',
|
|
2994
3023
|
hrDesc: 'Insert a horizontal line',
|
|
2995
3024
|
codeBlock: 'Code block',
|
|
@@ -3151,6 +3180,14 @@ var zhCN = {
|
|
|
3151
3180
|
checklistDesc: '创建任务列表',
|
|
3152
3181
|
table: '表格',
|
|
3153
3182
|
tableDesc: '插入表格',
|
|
3183
|
+
infoAlert: '信息块',
|
|
3184
|
+
infoAlertDesc: '创建信息块',
|
|
3185
|
+
tipAlert: '提示块',
|
|
3186
|
+
tipAlertDesc: '创建提示块',
|
|
3187
|
+
warningAlert: '警告块',
|
|
3188
|
+
warningAlertDesc: '创建警告块',
|
|
3189
|
+
dangerAlert: '危险警告块',
|
|
3190
|
+
dangerAlertDesc: '创建危险警告块',
|
|
3154
3191
|
hr: '分割线',
|
|
3155
3192
|
hrDesc: '插入分割线',
|
|
3156
3193
|
codeBlock: '代码块',
|
|
@@ -3312,6 +3349,14 @@ var ja = {
|
|
|
3312
3349
|
checklistDesc: 'チェックリストを作成',
|
|
3313
3350
|
table: 'テーブル',
|
|
3314
3351
|
tableDesc: 'テーブルを挿入',
|
|
3352
|
+
infoAlert: '情報ブロック',
|
|
3353
|
+
infoAlertDesc: '情報ブロックを作成',
|
|
3354
|
+
tipAlert: 'ヒントブロック',
|
|
3355
|
+
tipAlertDesc: 'ヒントブロックを作成',
|
|
3356
|
+
warningAlert: '警告ブロック',
|
|
3357
|
+
warningAlertDesc: '警告ブロックを作成',
|
|
3358
|
+
dangerAlert: '危険ブロック',
|
|
3359
|
+
dangerAlertDesc: '危険ブロックを作成',
|
|
3315
3360
|
hr: '区切り線',
|
|
3316
3361
|
hrDesc: '水平線を挿入',
|
|
3317
3362
|
codeBlock: 'コードブロック',
|
|
@@ -3473,6 +3518,14 @@ var ko = {
|
|
|
3473
3518
|
checklistDesc: '체크리스트를 작성',
|
|
3474
3519
|
table: '표',
|
|
3475
3520
|
tableDesc: '표를 삽입',
|
|
3521
|
+
infoAlert: '정보 블록',
|
|
3522
|
+
infoAlertDesc: '정보 블록을 작성',
|
|
3523
|
+
tipAlert: '팁 블록',
|
|
3524
|
+
tipAlertDesc: '팁 블록을 작성',
|
|
3525
|
+
warningAlert: '경고 블록',
|
|
3526
|
+
warningAlertDesc: '경고 블록을 작성',
|
|
3527
|
+
dangerAlert: '위험 블록',
|
|
3528
|
+
dangerAlertDesc: '위험 블록을 작성',
|
|
3476
3529
|
hr: '구분선',
|
|
3477
3530
|
hrDesc: '구분선을 삽입',
|
|
3478
3531
|
codeBlock: '코드 블록',
|
|
@@ -3587,7 +3640,7 @@ const loadAllLocales = () => locales.forEach(loadLocale);
|
|
|
3587
3640
|
const i18nObject = (locale) => i18nObject$1(locale, loadedLocales[locale], loadedFormatters[locale]);
|
|
3588
3641
|
loadAllLocales();
|
|
3589
3642
|
|
|
3590
|
-
// The Dropdown
|
|
3643
|
+
// The Dropdown interface represents a UI component that provides a menu of options.
|
|
3591
3644
|
class Dropdown {
|
|
3592
3645
|
constructor(config) {
|
|
3593
3646
|
this.clickListener = (event) => {
|
|
@@ -3812,10 +3865,11 @@ class Dropdown {
|
|
|
3812
3865
|
document.removeEventListener('click', this.clickListener);
|
|
3813
3866
|
window.removeEventListener('resize', this.resizeListener);
|
|
3814
3867
|
}
|
|
3868
|
+
// Renders the dropdown.
|
|
3815
3869
|
render() {
|
|
3816
3870
|
var _a, _b;
|
|
3817
3871
|
const config = this.config;
|
|
3818
|
-
const defaultValue = (_a = config.defaultValue) !== null && _a !==
|
|
3872
|
+
const defaultValue = (_a = config.defaultValue) !== null && _a !== undefined ? _a : '';
|
|
3819
3873
|
const titleNode = this.node.find('.lake-dropdown-title');
|
|
3820
3874
|
if (!config.downIcon) {
|
|
3821
3875
|
titleNode.addClass('lake-dropdown-title-no-down');
|
|
@@ -3840,7 +3894,7 @@ class Dropdown {
|
|
|
3840
3894
|
Dropdown.setValue(this.node, [defaultValue]);
|
|
3841
3895
|
if (textNode.length > 0) {
|
|
3842
3896
|
const menuMap = Dropdown.getMenuMap(config.menuItems, this.locale);
|
|
3843
|
-
textNode.text((_b = menuMap.get(defaultValue)) !== null && _b !==
|
|
3897
|
+
textNode.text((_b = menuMap.get(defaultValue)) !== null && _b !== undefined ? _b : defaultValue);
|
|
3844
3898
|
}
|
|
3845
3899
|
if (config.menuType === 'color') {
|
|
3846
3900
|
this.updateColorAccent(titleNode, defaultValue);
|
|
@@ -3894,6 +3948,7 @@ class Dropdown {
|
|
|
3894
3948
|
this.showMenu();
|
|
3895
3949
|
});
|
|
3896
3950
|
}
|
|
3951
|
+
// Destroys the dropdown.
|
|
3897
3952
|
unmount() {
|
|
3898
3953
|
this.hideMenu();
|
|
3899
3954
|
this.menuNode.remove();
|
|
@@ -3926,7 +3981,7 @@ const toolbarItemMap = new Map();
|
|
|
3926
3981
|
for (const item of toolbarItems) {
|
|
3927
3982
|
toolbarItemMap.set(item.name, item);
|
|
3928
3983
|
}
|
|
3929
|
-
// The Toolbar
|
|
3984
|
+
// The Toolbar interface provides properties and methods for rendering and manipulating the toolbar.
|
|
3930
3985
|
class Toolbar {
|
|
3931
3986
|
constructor(config) {
|
|
3932
3987
|
this.placement = 'top';
|
|
@@ -4032,7 +4087,7 @@ class Toolbar {
|
|
|
4032
4087
|
}
|
|
4033
4088
|
});
|
|
4034
4089
|
}
|
|
4035
|
-
//
|
|
4090
|
+
// Update the state of each item in the toolbar, such as whether it is selected, disabled.
|
|
4036
4091
|
updateState(state = {
|
|
4037
4092
|
activeItems: [],
|
|
4038
4093
|
}) {
|
|
@@ -4093,7 +4148,7 @@ class Toolbar {
|
|
|
4093
4148
|
if (textNode.length > 0) {
|
|
4094
4149
|
const key = selectedValues[0] || item.defaultValue || '';
|
|
4095
4150
|
const menuMap = this.allMenuMap.get(item.name);
|
|
4096
|
-
const text = (_a = (menuMap && menuMap.get(key))) !== null && _a !==
|
|
4151
|
+
const text = (_a = (menuMap && menuMap.get(key))) !== null && _a !== undefined ? _a : key;
|
|
4097
4152
|
textNode.text(text);
|
|
4098
4153
|
}
|
|
4099
4154
|
}
|
|
@@ -4238,10 +4293,12 @@ class FloatingToolbar extends Toolbar {
|
|
|
4238
4293
|
}
|
|
4239
4294
|
}
|
|
4240
4295
|
|
|
4241
|
-
// The Box
|
|
4296
|
+
// The Box interface represents an embedded content, which is used to enhance editing capability.
|
|
4242
4297
|
class Box {
|
|
4243
4298
|
constructor(node) {
|
|
4299
|
+
// Managing events.
|
|
4244
4300
|
this.event = new EventEmitter();
|
|
4301
|
+
// A toolbar for the box.
|
|
4245
4302
|
this.toolbar = null;
|
|
4246
4303
|
if (typeof node === 'string') {
|
|
4247
4304
|
const component = boxes.get(node);
|
|
@@ -4320,19 +4377,19 @@ class Box {
|
|
|
4320
4377
|
set value(value) {
|
|
4321
4378
|
this.node.attr('value', toBase64(JSON.stringify(value)));
|
|
4322
4379
|
}
|
|
4323
|
-
updateValue(
|
|
4380
|
+
updateValue(keyName, keyValue) {
|
|
4324
4381
|
const value = this.value;
|
|
4325
|
-
if (typeof
|
|
4326
|
-
value[
|
|
4382
|
+
if (typeof keyName === 'string') {
|
|
4383
|
+
value[keyName] = keyValue;
|
|
4327
4384
|
}
|
|
4328
4385
|
else {
|
|
4329
|
-
for (const key of Object.keys(
|
|
4330
|
-
value[key] =
|
|
4386
|
+
for (const key of Object.keys(keyName)) {
|
|
4387
|
+
value[key] = keyName[key];
|
|
4331
4388
|
}
|
|
4332
4389
|
}
|
|
4333
4390
|
this.value = value;
|
|
4334
4391
|
}
|
|
4335
|
-
// Returns an instance of the editor
|
|
4392
|
+
// Returns an instance of the editor containing the box.
|
|
4336
4393
|
getEditor() {
|
|
4337
4394
|
const container = this.node.closest('div[contenteditable]');
|
|
4338
4395
|
const editor = container.length > 0 ? editors.get(container.id) : undefined;
|
|
@@ -4341,10 +4398,21 @@ class Box {
|
|
|
4341
4398
|
}
|
|
4342
4399
|
return editor;
|
|
4343
4400
|
}
|
|
4344
|
-
// Returns the container
|
|
4401
|
+
// Returns the container of the box.
|
|
4345
4402
|
getContainer() {
|
|
4346
4403
|
return this.node.find('.lake-box-container');
|
|
4347
4404
|
}
|
|
4405
|
+
// Returns the HTML string contained within the box.
|
|
4406
|
+
getHTML() {
|
|
4407
|
+
const component = boxes.get(this.name);
|
|
4408
|
+
if (component === undefined) {
|
|
4409
|
+
return '';
|
|
4410
|
+
}
|
|
4411
|
+
if (component.html === undefined) {
|
|
4412
|
+
return this.node.outerHTML();
|
|
4413
|
+
}
|
|
4414
|
+
return component.html(this);
|
|
4415
|
+
}
|
|
4348
4416
|
// Sets a floating toolbar for the box.
|
|
4349
4417
|
setToolbar(items) {
|
|
4350
4418
|
const editor = this.getEditor();
|
|
@@ -4387,7 +4455,7 @@ class Box {
|
|
|
4387
4455
|
}
|
|
4388
4456
|
debug(`Box "${this.name}" (id: ${this.node.id}) rendered`);
|
|
4389
4457
|
}
|
|
4390
|
-
// Destroys
|
|
4458
|
+
// Destroys the box.
|
|
4391
4459
|
unmount() {
|
|
4392
4460
|
this.event.emit('blur');
|
|
4393
4461
|
this.event.emit('beforeunmount');
|
|
@@ -4395,17 +4463,6 @@ class Box {
|
|
|
4395
4463
|
this.node.empty();
|
|
4396
4464
|
debug(`Box "${this.name}" (id: ${this.node.id}) unmounted`);
|
|
4397
4465
|
}
|
|
4398
|
-
// Returns a HTML string of the box.
|
|
4399
|
-
getHTML() {
|
|
4400
|
-
const component = boxes.get(this.name);
|
|
4401
|
-
if (component === undefined) {
|
|
4402
|
-
return '';
|
|
4403
|
-
}
|
|
4404
|
-
if (component.html === undefined) {
|
|
4405
|
-
return this.node.outerHTML();
|
|
4406
|
-
}
|
|
4407
|
-
return component.html(this);
|
|
4408
|
-
}
|
|
4409
4466
|
}
|
|
4410
4467
|
|
|
4411
4468
|
const blockAttributeRules = {
|
|
@@ -4528,7 +4585,7 @@ function parseStyle(styleValue) {
|
|
|
4528
4585
|
return properties;
|
|
4529
4586
|
}
|
|
4530
4587
|
|
|
4531
|
-
// The HTMLParser
|
|
4588
|
+
// The HTMLParser interface provides the ability to parse an HTML string by specified rules.
|
|
4532
4589
|
class HTMLParser {
|
|
4533
4590
|
constructor(content, rules = getElementRules()) {
|
|
4534
4591
|
this.rules = rules;
|
|
@@ -4539,7 +4596,7 @@ class HTMLParser {
|
|
|
4539
4596
|
this.source = content;
|
|
4540
4597
|
}
|
|
4541
4598
|
}
|
|
4542
|
-
// Parses HTML string and returns the
|
|
4599
|
+
// Parses the given HTML string and returns the body element from the result.
|
|
4543
4600
|
parseHTML(html) {
|
|
4544
4601
|
const parser = new DOMParser();
|
|
4545
4602
|
const doc = parser.parseFromString(html, 'text/html');
|
|
@@ -4646,7 +4703,7 @@ class HTMLParser {
|
|
|
4646
4703
|
}
|
|
4647
4704
|
return nodeValue;
|
|
4648
4705
|
}
|
|
4649
|
-
// Returns
|
|
4706
|
+
// Returns an HTML string.
|
|
4650
4707
|
getHTML() {
|
|
4651
4708
|
const rules = this.rules;
|
|
4652
4709
|
function* iterate(node) {
|
|
@@ -4684,7 +4741,7 @@ class HTMLParser {
|
|
|
4684
4741
|
}
|
|
4685
4742
|
return html.trim();
|
|
4686
4743
|
}
|
|
4687
|
-
// Returns a
|
|
4744
|
+
// Returns a DocumentFragment object.
|
|
4688
4745
|
getFragment() {
|
|
4689
4746
|
const html = this.getHTML();
|
|
4690
4747
|
const body = this.parseHTML(html);
|
|
@@ -4699,11 +4756,12 @@ class HTMLParser {
|
|
|
4699
4756
|
}
|
|
4700
4757
|
}
|
|
4701
4758
|
|
|
4702
|
-
// The TextParser
|
|
4759
|
+
// The TextParser interface provides the ability to parse a text.
|
|
4703
4760
|
class TextParser {
|
|
4704
4761
|
constructor(content) {
|
|
4705
4762
|
this.content = content;
|
|
4706
4763
|
}
|
|
4764
|
+
// Returns an HTML string.
|
|
4707
4765
|
getHTML() {
|
|
4708
4766
|
let html = this.content;
|
|
4709
4767
|
html = html.replace(/ {2}/g, ' \xA0');
|
|
@@ -4715,6 +4773,7 @@ class TextParser {
|
|
|
4715
4773
|
html = html.replace(/[\r\n]/g, '</p><p>');
|
|
4716
4774
|
return html;
|
|
4717
4775
|
}
|
|
4776
|
+
// Returns a DocumentFragment object.
|
|
4718
4777
|
getFragment() {
|
|
4719
4778
|
const htmlParser = new HTMLParser(this.getHTML());
|
|
4720
4779
|
return htmlParser.getFragment();
|
|
@@ -4728,8 +4787,7 @@ function insertNode(range, node) {
|
|
|
4728
4787
|
nativeRange.setEndAfter(nativeNode);
|
|
4729
4788
|
nativeRange.collapse(false);
|
|
4730
4789
|
}
|
|
4731
|
-
//
|
|
4732
|
-
// or the method inserts a pair of bookmarks into the beginning and the end of the range.
|
|
4790
|
+
// Inserts a bookmark at the cursor position or a pair of bookmarks at the beginning and end of the range.
|
|
4733
4791
|
// case 1: foo<lake-bookmark type="focus" />bar
|
|
4734
4792
|
// case 2: <lake-bookmark type="anchor" />foo<lake-bookmark type="focus" />
|
|
4735
4793
|
// case 3: foo<lake-box type="inline" name="image" focus="start"></lake-box>bar
|
|
@@ -4855,7 +4913,7 @@ function removeAndNormalizeNode(node, range) {
|
|
|
4855
4913
|
node.remove();
|
|
4856
4914
|
}
|
|
4857
4915
|
}
|
|
4858
|
-
// Changes the specified range to
|
|
4916
|
+
// Changes the specified range to a range represented by the bookmark.
|
|
4859
4917
|
function toBookmark(range, bookmark) {
|
|
4860
4918
|
const anchor = bookmark.anchor;
|
|
4861
4919
|
const focus = bookmark.focus;
|
|
@@ -5165,7 +5223,7 @@ function getDeepElement(element) {
|
|
|
5165
5223
|
|
|
5166
5224
|
// Appends a list of nodes to the specified element.
|
|
5167
5225
|
function wrapNodeList(nodeList, wrapper) {
|
|
5168
|
-
wrapper = wrapper !== null && wrapper !==
|
|
5226
|
+
wrapper = wrapper !== null && wrapper !== undefined ? wrapper : query('<p />');
|
|
5169
5227
|
if (nodeList.length === 0) {
|
|
5170
5228
|
return wrapper;
|
|
5171
5229
|
}
|
|
@@ -5833,7 +5891,7 @@ function removeBox(range) {
|
|
|
5833
5891
|
return box;
|
|
5834
5892
|
}
|
|
5835
5893
|
|
|
5836
|
-
var version = "0.3.
|
|
5894
|
+
var version = "0.3.3";
|
|
5837
5895
|
|
|
5838
5896
|
// Converts the custom HTML tags to the special tags that can not be parsed by browser.
|
|
5839
5897
|
function denormalizeValue(value) {
|
|
@@ -6415,7 +6473,7 @@ function insertSiblings(previousSibling, morphedNode, nextSibling) {
|
|
|
6415
6473
|
const node = stack.pop();
|
|
6416
6474
|
added.push(node); // push added preceding siblings on in order and insert
|
|
6417
6475
|
if (node) {
|
|
6418
|
-
(_a = morphedNode.parentElement) === null || _a ===
|
|
6476
|
+
(_a = morphedNode.parentElement) === null || _a === undefined ? undefined : _a.insertBefore(node, morphedNode);
|
|
6419
6477
|
}
|
|
6420
6478
|
}
|
|
6421
6479
|
added.push(morphedNode);
|
|
@@ -6428,7 +6486,7 @@ function insertSiblings(previousSibling, morphedNode, nextSibling) {
|
|
|
6428
6486
|
while (stack.length > 0) {
|
|
6429
6487
|
const node = stack.pop();
|
|
6430
6488
|
if (node) {
|
|
6431
|
-
(_b = morphedNode.parentElement) === null || _b ===
|
|
6489
|
+
(_b = morphedNode.parentElement) === null || _b === undefined ? undefined : _b.insertBefore(node, morphedNode.nextSibling);
|
|
6432
6490
|
}
|
|
6433
6491
|
}
|
|
6434
6492
|
return added;
|
|
@@ -6542,7 +6600,7 @@ function morphOldNodeTo(oldNode, newContent, ctx) {
|
|
|
6542
6600
|
return oldNode;
|
|
6543
6601
|
if (ctx.callbacks.beforeNodeAdded(newContent) === false)
|
|
6544
6602
|
return oldNode;
|
|
6545
|
-
(_a = oldNode.parentElement) === null || _a ===
|
|
6603
|
+
(_a = oldNode.parentElement) === null || _a === undefined ? undefined : _a.replaceChild(newContent, oldNode);
|
|
6546
6604
|
ctx.callbacks.afterNodeAdded(newContent);
|
|
6547
6605
|
ctx.callbacks.afterNodeRemoved(oldNode);
|
|
6548
6606
|
return newContent;
|
|
@@ -6648,8 +6706,8 @@ function morphNormalizedContent(oldNode, normalizedNewContent, ctx) {
|
|
|
6648
6706
|
// into either side of the best match
|
|
6649
6707
|
const bestMatch = findBestNodeMatch(normalizedNewContent, oldNode, ctx);
|
|
6650
6708
|
// stash the siblings that will need to be inserted on either side of the best match
|
|
6651
|
-
const previousSibling = bestMatch === null || bestMatch ===
|
|
6652
|
-
const nextSibling = bestMatch === null || bestMatch ===
|
|
6709
|
+
const previousSibling = bestMatch === null || bestMatch === undefined ? undefined : bestMatch.previousSibling;
|
|
6710
|
+
const nextSibling = bestMatch === null || bestMatch === undefined ? undefined : bestMatch.nextSibling;
|
|
6653
6711
|
// morph it
|
|
6654
6712
|
const morphedNode = morphOldNodeTo(oldNode, bestMatch, ctx);
|
|
6655
6713
|
if (bestMatch) {
|
|
@@ -6831,9 +6889,9 @@ class History {
|
|
|
6831
6889
|
}
|
|
6832
6890
|
save(options = {}) {
|
|
6833
6891
|
var _a, _b, _c;
|
|
6834
|
-
const inputType = (_a = options.inputType) !== null && _a !==
|
|
6835
|
-
const update = (_b = options.update) !== null && _b !==
|
|
6836
|
-
const emitEvent = (_c = options.emitEvent) !== null && _c !==
|
|
6892
|
+
const inputType = (_a = options.inputType) !== null && _a !== undefined ? _a : '';
|
|
6893
|
+
const update = (_b = options.update) !== null && _b !== undefined ? _b : false;
|
|
6894
|
+
const emitEvent = (_c = options.emitEvent) !== null && _c !== undefined ? _c : true;
|
|
6837
6895
|
if (!this.canSave) {
|
|
6838
6896
|
return;
|
|
6839
6897
|
}
|
|
@@ -6956,9 +7014,6 @@ class Plugin {
|
|
|
6956
7014
|
this.pluginMap = new Map();
|
|
6957
7015
|
}
|
|
6958
7016
|
add(name, plugin) {
|
|
6959
|
-
if (this.pluginMap.get(name)) {
|
|
6960
|
-
throw new Error(`Plugin "${name}" is already defined.`);
|
|
6961
|
-
}
|
|
6962
7017
|
this.pluginMap.set(name, plugin);
|
|
6963
7018
|
}
|
|
6964
7019
|
loadAll(editor) {
|
|
@@ -7005,6 +7060,7 @@ const defaultConfig = {
|
|
|
7005
7060
|
slash: false,
|
|
7006
7061
|
mention: false,
|
|
7007
7062
|
};
|
|
7063
|
+
// The Editor interface provides properties and methods for rendering and manipulating the editor.
|
|
7008
7064
|
class Editor {
|
|
7009
7065
|
constructor(config) {
|
|
7010
7066
|
// A string that has not yet been saved to the history.
|
|
@@ -7250,7 +7306,7 @@ class Editor {
|
|
|
7250
7306
|
}
|
|
7251
7307
|
const inputType = event instanceof CompositionEvent ? 'insertText' : event.inputType;
|
|
7252
7308
|
if (inputType === 'insertText') {
|
|
7253
|
-
const inputData = (_a = event.data) !== null && _a !==
|
|
7309
|
+
const inputData = (_a = event.data) !== null && _a !== undefined ? _a : '';
|
|
7254
7310
|
if (inputData.length > 1) {
|
|
7255
7311
|
this.history.save({
|
|
7256
7312
|
inputType: 'insertText',
|
|
@@ -9414,7 +9470,7 @@ class LinkPopup {
|
|
|
9414
9470
|
}
|
|
9415
9471
|
// Writes the specified text to the system clipboard
|
|
9416
9472
|
writeClipboardText(text) {
|
|
9417
|
-
return __awaiter(this,
|
|
9473
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
9418
9474
|
let error = false;
|
|
9419
9475
|
try {
|
|
9420
9476
|
if (window.LAKE_TEST) {
|
|
@@ -9936,7 +9992,7 @@ var codeBlockBox = {
|
|
|
9936
9992
|
});
|
|
9937
9993
|
const codeEditor = new EditorView({
|
|
9938
9994
|
parent: codeBlockNativeNode,
|
|
9939
|
-
doc: (_a = boxValue.code) !== null && _a !==
|
|
9995
|
+
doc: (_a = boxValue.code) !== null && _a !== undefined ? _a : '',
|
|
9940
9996
|
extensions: [
|
|
9941
9997
|
EditorState.readOnly.of(editor.readonly),
|
|
9942
9998
|
EditorView.editable.of(!editor.readonly),
|
|
@@ -10288,7 +10344,7 @@ function renderFloatingToolbar(box) {
|
|
|
10288
10344
|
}
|
|
10289
10345
|
// Loads an image and get its width and height.
|
|
10290
10346
|
function getImageInfo(url) {
|
|
10291
|
-
return __awaiter(this,
|
|
10347
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
10292
10348
|
const node = query('<img />');
|
|
10293
10349
|
node.css({
|
|
10294
10350
|
position: 'absolute',
|
|
@@ -10478,7 +10534,7 @@ function renderCaption(box) {
|
|
|
10478
10534
|
}
|
|
10479
10535
|
// Displays error icon and filename.
|
|
10480
10536
|
function renderError$1(box) {
|
|
10481
|
-
return __awaiter(this,
|
|
10537
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
10482
10538
|
const editor = box.getEditor();
|
|
10483
10539
|
const boxContainer = box.getContainer();
|
|
10484
10540
|
const value = box.value;
|
|
@@ -10521,7 +10577,7 @@ function renderError$1(box) {
|
|
|
10521
10577
|
}
|
|
10522
10578
|
// Displays an image with uplaoding progress.
|
|
10523
10579
|
function renderUploading(box) {
|
|
10524
|
-
return __awaiter(this,
|
|
10580
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
10525
10581
|
const editor = box.getEditor();
|
|
10526
10582
|
const boxContainer = box.getContainer();
|
|
10527
10583
|
const value = box.value;
|
|
@@ -10591,7 +10647,7 @@ function renderUploading(box) {
|
|
|
10591
10647
|
}
|
|
10592
10648
|
// Displays an image that can be previewed or removed.
|
|
10593
10649
|
function renderDone(box) {
|
|
10594
|
-
return __awaiter(this,
|
|
10650
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
10595
10651
|
const editor = box.getEditor();
|
|
10596
10652
|
const boxContainer = box.getContainer();
|
|
10597
10653
|
const value = box.value;
|
|
@@ -10984,7 +11040,7 @@ function setFloatingToolbar(box) {
|
|
|
10984
11040
|
box.setToolbar(items);
|
|
10985
11041
|
}
|
|
10986
11042
|
function appendContent(rootNode, box) {
|
|
10987
|
-
return __awaiter(this,
|
|
11043
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
10988
11044
|
const value = box.value;
|
|
10989
11045
|
const infoNode = query(template `
|
|
10990
11046
|
<div class="lake-file-info">
|
|
@@ -11473,7 +11529,7 @@ class MentionMenu extends Menu {
|
|
|
11473
11529
|
const itemNode = query(template `
|
|
11474
11530
|
<li>
|
|
11475
11531
|
<div class="lake-mention-avatar"></div>
|
|
11476
|
-
<div class="lake-mention-nickname">${(_a = item.nickname) !== null && _a !==
|
|
11532
|
+
<div class="lake-mention-nickname">${(_a = item.nickname) !== null && _a !== undefined ? _a : item.name}</div>
|
|
11477
11533
|
<div class="lake-mention-name">(${item.name})</div>
|
|
11478
11534
|
</li>
|
|
11479
11535
|
`);
|
|
@@ -11495,7 +11551,7 @@ class MentionMenu extends Menu {
|
|
|
11495
11551
|
keyword = keyword.toLowerCase();
|
|
11496
11552
|
const items = [];
|
|
11497
11553
|
for (const item of this.items) {
|
|
11498
|
-
const nickname = (_a = item.nickname) !== null && _a !==
|
|
11554
|
+
const nickname = (_a = item.nickname) !== null && _a !== undefined ? _a : item.name;
|
|
11499
11555
|
if (item.name.toLowerCase().indexOf(keyword) >= 0 ||
|
|
11500
11556
|
nickname.toLowerCase().indexOf(keyword) >= 0 ||
|
|
11501
11557
|
nickname.replace(/\s+/g, '').indexOf(keyword) >= 0) {
|
|
@@ -11517,7 +11573,7 @@ var mentionBox = {
|
|
|
11517
11573
|
const url = getProfileUrl ? getProfileUrl(value) : '#';
|
|
11518
11574
|
const boxContainer = box.getContainer();
|
|
11519
11575
|
const rootNode = query(template `
|
|
11520
|
-
<div class="lake-mention"><a href="${url}">@${(_a = value.nickname) !== null && _a !==
|
|
11576
|
+
<div class="lake-mention"><a href="${url}">@${(_a = value.nickname) !== null && _a !== undefined ? _a : value.name}</a></div>
|
|
11521
11577
|
`);
|
|
11522
11578
|
boxContainer.empty();
|
|
11523
11579
|
boxContainer.append(rootNode);
|
|
@@ -11720,7 +11776,7 @@ const blockItemListForSpaceKey = [
|
|
|
11720
11776
|
var _a;
|
|
11721
11777
|
return [
|
|
11722
11778
|
'heading',
|
|
11723
|
-
(_a = headingTypeMap.get(results[0])) !== null && _a !==
|
|
11779
|
+
(_a = headingTypeMap.get(results[0])) !== null && _a !== undefined ? _a : 'h6',
|
|
11724
11780
|
];
|
|
11725
11781
|
},
|
|
11726
11782
|
},
|
|
@@ -11795,7 +11851,7 @@ const blockItemListForEnterKey = [
|
|
|
11795
11851
|
return [
|
|
11796
11852
|
'codeBlock',
|
|
11797
11853
|
{
|
|
11798
|
-
lang: (_a = shortLangTypeMap.get(results[1])) !== null && _a !==
|
|
11854
|
+
lang: (_a = shortLangTypeMap.get(results[1])) !== null && _a !== undefined ? _a : results[1],
|
|
11799
11855
|
},
|
|
11800
11856
|
];
|
|
11801
11857
|
},
|
|
@@ -12766,6 +12822,46 @@ const slashItems = [
|
|
|
12766
12822
|
editor.command.execute(value);
|
|
12767
12823
|
},
|
|
12768
12824
|
},
|
|
12825
|
+
{
|
|
12826
|
+
name: 'infoAlert',
|
|
12827
|
+
type: 'button',
|
|
12828
|
+
icon: icons.get('info'),
|
|
12829
|
+
title: locale => locale.slash.infoAlert(),
|
|
12830
|
+
description: locale => locale.slash.infoAlertDesc(),
|
|
12831
|
+
onClick: editor => {
|
|
12832
|
+
editor.command.execute('blockQuote', 'info');
|
|
12833
|
+
},
|
|
12834
|
+
},
|
|
12835
|
+
{
|
|
12836
|
+
name: 'tipAlert',
|
|
12837
|
+
type: 'button',
|
|
12838
|
+
icon: icons.get('tip'),
|
|
12839
|
+
title: locale => locale.slash.tipAlert(),
|
|
12840
|
+
description: locale => locale.slash.tipAlertDesc(),
|
|
12841
|
+
onClick: editor => {
|
|
12842
|
+
editor.command.execute('blockQuote', 'tip');
|
|
12843
|
+
},
|
|
12844
|
+
},
|
|
12845
|
+
{
|
|
12846
|
+
name: 'warningAlert',
|
|
12847
|
+
type: 'button',
|
|
12848
|
+
icon: icons.get('warning'),
|
|
12849
|
+
title: locale => locale.slash.warningAlert(),
|
|
12850
|
+
description: locale => locale.slash.warningAlertDesc(),
|
|
12851
|
+
onClick: editor => {
|
|
12852
|
+
editor.command.execute('blockQuote', 'warning');
|
|
12853
|
+
},
|
|
12854
|
+
},
|
|
12855
|
+
{
|
|
12856
|
+
name: 'dangerAlert',
|
|
12857
|
+
type: 'button',
|
|
12858
|
+
icon: icons.get('danger'),
|
|
12859
|
+
title: locale => locale.slash.dangerAlert(),
|
|
12860
|
+
description: locale => locale.slash.dangerAlertDesc(),
|
|
12861
|
+
onClick: editor => {
|
|
12862
|
+
editor.command.execute('blockQuote', 'danger');
|
|
12863
|
+
},
|
|
12864
|
+
},
|
|
12769
12865
|
{
|
|
12770
12866
|
name: 'hr',
|
|
12771
12867
|
type: 'button',
|
|
@@ -12919,6 +13015,10 @@ const defaultItems = [
|
|
|
12919
13015
|
'bulletedList',
|
|
12920
13016
|
'checklist',
|
|
12921
13017
|
'table',
|
|
13018
|
+
'infoAlert',
|
|
13019
|
+
'tipAlert',
|
|
13020
|
+
'warningAlert',
|
|
13021
|
+
'dangerAlert',
|
|
12922
13022
|
'hr',
|
|
12923
13023
|
];
|
|
12924
13024
|
function getKeyword(block) {
|