lakelib 0.3.11 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/lake.css CHANGED
@@ -444,7 +444,7 @@ button.lake-primary-button.lake-button-hovered {
444
444
  .lake-dropdown-menu {
445
445
  position: absolute;
446
446
  top: 30px;
447
- left: 0;
447
+ right: 0;
448
448
  z-index: var(--lake-popup-z-index);
449
449
  list-style: none;
450
450
  margin: 0;
@@ -1088,6 +1088,12 @@ button.lake-primary-button.lake-button-hovered {
1088
1088
  user-select: none;
1089
1089
  }
1090
1090
 
1091
+ .lake-toolbar .lake-toolbar-line-break {
1092
+ flex-basis: 100%;
1093
+ height: 0;
1094
+ user-select: none;
1095
+ }
1096
+
1091
1097
  .lake-toolbar .lake-upload {
1092
1098
  line-height: 0;
1093
1099
  }
package/lib/lake.d.ts CHANGED
@@ -1367,6 +1367,11 @@ declare class Selection {
1367
1367
  * Returns a list of items related to the current selection.
1368
1368
  */
1369
1369
  getActiveItems(): ActiveItem[];
1370
+ /**
1371
+ * Creates a deep clone of the current container with its content.
1372
+ * If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
1373
+ */
1374
+ cloneContainer(): Nodes;
1370
1375
  /**
1371
1376
  * Inserts a bookmark at the cursor position or a pair of bookmarks at the selection boundaries.
1372
1377
  */
@@ -1520,11 +1525,6 @@ declare class History {
1520
1525
  * A boolean value indicating whether the history can be redone.
1521
1526
  */
1522
1527
  get canRedo(): boolean;
1523
- /**
1524
- * Creates a deep clone of the current container with its content.
1525
- * If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
1526
- */
1527
- cloneContainer(): Nodes;
1528
1528
  /**
1529
1529
  * Undoes to the previous saved content.
1530
1530
  */
@@ -1691,7 +1691,7 @@ declare class Toolbar {
1691
1691
  */
1692
1692
  container: Nodes;
1693
1693
  constructor(config: ToolbarConfig);
1694
- private appendDivider;
1694
+ private appendDivision;
1695
1695
  private appendNormalButton;
1696
1696
  private appendDropdown;
1697
1697
  private appendUploadButton;
@@ -1709,7 +1709,8 @@ declare class Toolbar {
1709
1709
  unmount(): void;
1710
1710
  }
1711
1711
 
1712
- type OnMessage = (type: 'success' | 'error' | 'warning', message: string) => void;
1712
+ type ShowMessage = (type: 'success' | 'error' | 'warning', message: string) => void;
1713
+ type DownloadFile = (type: 'image' | 'file', url: string) => void;
1713
1714
  interface Config {
1714
1715
  value: string;
1715
1716
  readonly: boolean;
@@ -1721,7 +1722,8 @@ interface Config {
1721
1722
  contentRules: ContentRules;
1722
1723
  minChangeSize: number;
1723
1724
  historySize: number;
1724
- onMessage: OnMessage;
1725
+ showMessage: ShowMessage;
1726
+ downloadFile: DownloadFile;
1725
1727
  [name: string]: any;
1726
1728
  }
1727
1729
  interface EditorConfig extends Partial<Config> {
package/lib/lake.js CHANGED
@@ -4217,8 +4217,8 @@ class Dropdown {
4217
4217
  menuNode.css('right', '0');
4218
4218
  }
4219
4219
  else {
4220
- menuNode.css('left', '');
4221
- menuNode.css('right', '');
4220
+ menuNode.css('left', '0');
4221
+ menuNode.css('right', 'auto');
4222
4222
  }
4223
4223
  if (this.direction === 'top') {
4224
4224
  menuNode.css('top', 'auto');
@@ -4419,8 +4419,8 @@ class Toolbar {
4419
4419
  }
4420
4420
  this.container = query('<div class="lake-toolbar" />');
4421
4421
  }
4422
- appendDivider() {
4423
- this.container.append('<div class="lake-toolbar-divider" />');
4422
+ appendDivision(name) {
4423
+ this.container.append(`<div class="lake-toolbar-${name}" />`);
4424
4424
  }
4425
4425
  appendNormalButton(editor, item) {
4426
4426
  const button = new Button({
@@ -4509,7 +4509,7 @@ class Toolbar {
4509
4509
  transformResponse,
4510
4510
  onError: error => {
4511
4511
  fileNativeNode.value = '';
4512
- editor.config.onMessage('error', error);
4512
+ editor.config.showMessage('error', error);
4513
4513
  },
4514
4514
  onSuccess: () => {
4515
4515
  fileNativeNode.value = '';
@@ -4595,7 +4595,10 @@ class Toolbar {
4595
4595
  this.root.append(this.container);
4596
4596
  for (const name of this.items) {
4597
4597
  if (name === '|') {
4598
- this.appendDivider();
4598
+ this.appendDivision('divider');
4599
+ }
4600
+ else if (name === '-') {
4601
+ this.appendDivision('line-break');
4599
4602
  }
4600
4603
  else {
4601
4604
  let item;
@@ -5213,7 +5216,7 @@ function createIframeBox(config) {
5213
5216
  onClick: () => {
5214
5217
  const url = formNode.find('input[name="url"]').value();
5215
5218
  if (!config.validUrl(url)) {
5216
- editor.config.onMessage('error', getLocaleString(locale, config.urlError));
5219
+ editor.config.showMessage('error', getLocaleString(locale, config.urlError));
5217
5220
  return;
5218
5221
  }
5219
5222
  box.updateValue('url', url);
@@ -6608,7 +6611,7 @@ function removeBox(range) {
6608
6611
  return box;
6609
6612
  }
6610
6613
 
6611
- var version = "0.3.11";
6614
+ var version = "0.4.1";
6612
6615
 
6613
6616
  // Converts the custom HTML tags to the special tags that can not be parsed by browser.
6614
6617
  function denormalizeValue(value) {
@@ -6784,6 +6787,39 @@ class Selection {
6784
6787
  appendNextNestedNodes(activeItems, this.range);
6785
6788
  return activeItems;
6786
6789
  }
6790
+ /**
6791
+ * Creates a deep clone of the current container with its content.
6792
+ * If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
6793
+ */
6794
+ cloneContainer() {
6795
+ const range = this.range;
6796
+ const newContainer = this.container.clone(true);
6797
+ newContainer.find('lake-box').each(nativeNode => {
6798
+ const box = getBox(nativeNode);
6799
+ box.getContainer().empty();
6800
+ });
6801
+ if (!this.container.contains(range.commonAncestor)) {
6802
+ return newContainer;
6803
+ }
6804
+ if (range.isInsideBox) {
6805
+ const boxNode = range.commonAncestor.closest('lake-box');
6806
+ const boxNodePath = boxNode.path();
6807
+ const newBoxNode = newContainer.find(boxNodePath);
6808
+ const newRange = range.clone();
6809
+ newRange.selectBox(newBoxNode);
6810
+ insertBookmark(newRange);
6811
+ return newContainer;
6812
+ }
6813
+ const startNodePath = range.startNode.path();
6814
+ const endNodePath = range.endNode.path();
6815
+ const newStartNode = newContainer.find(startNodePath);
6816
+ const newEndNode = newContainer.find(endNodePath);
6817
+ const newRange = range.clone();
6818
+ newRange.setStart(newStartNode, range.startOffset);
6819
+ newRange.setEnd(newEndNode, range.endOffset);
6820
+ insertBookmark(newRange);
6821
+ return newContainer;
6822
+ }
6787
6823
  /**
6788
6824
  * Inserts a bookmark at the cursor position or a pair of bookmarks at the selection boundaries.
6789
6825
  */
@@ -7624,39 +7660,6 @@ class History {
7624
7660
  get canRedo() {
7625
7661
  return !!this.list[this.index];
7626
7662
  }
7627
- /**
7628
- * Creates a deep clone of the current container with its content.
7629
- * If there is a selection within the container, it ensures the selection is also preserved in the cloned container.
7630
- */
7631
- cloneContainer() {
7632
- const range = this.selection.range;
7633
- const newContainer = this.container.clone(true);
7634
- newContainer.find('lake-box').each(nativeNode => {
7635
- const box = getBox(nativeNode);
7636
- box.getContainer().empty();
7637
- });
7638
- if (!this.container.contains(range.commonAncestor)) {
7639
- return newContainer;
7640
- }
7641
- if (range.isInsideBox) {
7642
- const boxNode = range.commonAncestor.closest('lake-box');
7643
- const boxNodePath = boxNode.path();
7644
- const newBoxNode = newContainer.find(boxNodePath);
7645
- const newRange = range.clone();
7646
- newRange.selectBox(newBoxNode);
7647
- insertBookmark(newRange);
7648
- return newContainer;
7649
- }
7650
- const startNodePath = range.startNode.path();
7651
- const endNodePath = range.endNode.path();
7652
- const newStartNode = newContainer.find(startNodePath);
7653
- const newEndNode = newContainer.find(endNodePath);
7654
- const newRange = range.clone();
7655
- newRange.setStart(newStartNode, range.startOffset);
7656
- newRange.setEnd(newEndNode, range.endOffset);
7657
- insertBookmark(newRange);
7658
- return newContainer;
7659
- }
7660
7663
  /**
7661
7664
  * Undoes to the previous saved content.
7662
7665
  */
@@ -7733,7 +7736,7 @@ class History {
7733
7736
  if (!this.canSave) {
7734
7737
  return;
7735
7738
  }
7736
- const item = this.cloneContainer();
7739
+ const item = this.selection.cloneContainer();
7737
7740
  const value = this.getValue(item);
7738
7741
  if (this.list[this.index - 1]
7739
7742
  && this.removeBookmark(this.getValue(this.list[this.index - 1])) === this.removeBookmark(value)) {
@@ -7917,7 +7920,7 @@ const defaultConfig = {
7917
7920
  contentRules: getContentRules(),
7918
7921
  minChangeSize: 5,
7919
7922
  historySize: 100,
7920
- onMessage: (type, message) => {
7923
+ showMessage: (type, message) => {
7921
7924
  if (type === 'success') {
7922
7925
  // eslint-disable-next-line no-console
7923
7926
  console.log(message);
@@ -7931,6 +7934,9 @@ const defaultConfig = {
7931
7934
  console.error(message);
7932
7935
  }
7933
7936
  },
7937
+ downloadFile: (type, url) => {
7938
+ window.open(url);
7939
+ },
7934
7940
  slash: false,
7935
7941
  mention: false,
7936
7942
  };
@@ -8479,7 +8485,7 @@ class Editor {
8479
8485
  * Returns the editor's content.
8480
8486
  */
8481
8487
  getValue() {
8482
- const item = this.history.cloneContainer();
8488
+ const item = this.selection.cloneContainer();
8483
8489
  let value = new HTMLParser(item, this.config.contentRules).getHTML();
8484
8490
  value = denormalizeValue(value);
8485
8491
  return value;
@@ -8852,7 +8858,7 @@ var paste = (editor) => {
8852
8858
  requestWithCredentials,
8853
8859
  requestHeaders,
8854
8860
  transformResponse,
8855
- onError: error => editor.config.onMessage('error', error),
8861
+ onError: error => editor.config.showMessage('error', error),
8856
8862
  onSuccess: () => editor.history.save(),
8857
8863
  });
8858
8864
  }
@@ -11158,7 +11164,8 @@ function renderFloatingToolbar(box) {
11158
11164
  icon: icons.get('open'),
11159
11165
  tooltip: locale => locale.image.open(),
11160
11166
  onClick: () => {
11161
- window.open(box.value.url);
11167
+ const editor = box.getEditor();
11168
+ editor.config.downloadFile('image', box.value.url);
11162
11169
  },
11163
11170
  },
11164
11171
  ];
@@ -11545,21 +11552,23 @@ function renderDone(box) {
11545
11552
  });
11546
11553
  const captionNode = renderCaption(box);
11547
11554
  renderFloatingToolbar(box);
11548
- new Resizer({
11549
- root: rootNode,
11550
- target: rootNode,
11551
- onResize: newWidth => {
11552
- boxContainer.css('width', `${newWidth}px`);
11553
- updateBoxMarginBottom(box, captionNode);
11554
- },
11555
- onStop: (newWidth, newHeight) => {
11556
- box.updateValue({
11557
- width: newWidth,
11558
- height: newHeight,
11559
- });
11560
- editor.history.save();
11561
- },
11562
- }).render();
11555
+ if (!editor.readonly) {
11556
+ new Resizer({
11557
+ root: rootNode,
11558
+ target: rootNode,
11559
+ onResize: newWidth => {
11560
+ boxContainer.css('width', `${newWidth}px`);
11561
+ updateBoxMarginBottom(box, captionNode);
11562
+ },
11563
+ onStop: (newWidth, newHeight) => {
11564
+ box.updateValue({
11565
+ width: newWidth,
11566
+ height: newHeight,
11567
+ });
11568
+ editor.history.save();
11569
+ },
11570
+ }).render();
11571
+ }
11563
11572
  });
11564
11573
  }
11565
11574
  var imageBox = {
@@ -11723,7 +11732,8 @@ function setFloatingToolbar(box) {
11723
11732
  icon: icons.get('download'),
11724
11733
  tooltip: locale => locale.file.download(),
11725
11734
  onClick: () => {
11726
- window.open(box.value.url);
11735
+ const editor = box.getEditor();
11736
+ editor.config.downloadFile('file', box.value.url);
11727
11737
  },
11728
11738
  },
11729
11739
  {
@@ -11798,7 +11808,7 @@ var fileBox = {
11798
11808
  }
11799
11809
  else {
11800
11810
  rootNode.on('click', () => {
11801
- window.open(value.url);
11811
+ editor.config.downloadFile('file', value.url);
11802
11812
  });
11803
11813
  }
11804
11814
  },
@@ -11882,7 +11892,7 @@ function renderError(box) {
11882
11892
  rootNode.on('click', () => {
11883
11893
  editor.selection.selectBox(box);
11884
11894
  });
11885
- editor.config.onMessage('warning', `
11895
+ editor.config.showMessage('warning', `
11886
11896
  Box "${box.name}" (id: ${box.node.id}) failed to display because window.katex was not found.
11887
11897
  Please check if the "katex" library is added to this page.
11888
11898
  `.trim());
@@ -13872,7 +13882,7 @@ var slash = (editor) => {
13872
13882
  transformResponse,
13873
13883
  onError: error => {
13874
13884
  fileNativeNode.value = '';
13875
- editor.config.onMessage('error', error);
13885
+ editor.config.showMessage('error', error);
13876
13886
  },
13877
13887
  onSuccess: () => {
13878
13888
  fileNativeNode.value = '';