lakelib 0.1.1 → 0.1.2

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.js CHANGED
@@ -737,7 +737,7 @@ class Nodes {
737
737
  }
738
738
  return block;
739
739
  }
740
- // Traverses the first node and its parents until it finds a root element which has contenteditable="true" attribute..
740
+ // Traverses the first node and its parents until it finds a root element which has contenteditable="true" attribute.
741
741
  closestContainer() {
742
742
  return this.closest('div[contenteditable="true"]');
743
743
  }
@@ -4299,7 +4299,7 @@ class Dropdown {
4299
4299
  }
4300
4300
  }
4301
4301
 
4302
- var version = "0.1.1";
4302
+ var version = "0.1.2";
4303
4303
 
4304
4304
  // Inserts a box into the specified range.
4305
4305
  function insertBox(range, boxName, boxValue) {
@@ -5274,11 +5274,11 @@ class Editor {
5274
5274
  this.containerWrapper.append(this.overlayContainer);
5275
5275
  query(document.body).append(this.popupContainer);
5276
5276
  this.container.append(fragment);
5277
+ Editor.plugin.loadAll(this);
5277
5278
  if (!this.readonly) {
5278
5279
  this.bindFocusEvents();
5279
5280
  this.selection.synByBookmark();
5280
5281
  this.history.save();
5281
- Editor.plugin.loadAll(this);
5282
5282
  }
5283
5283
  Editor.box.renderAll(this);
5284
5284
  if (this.toolbar) {
@@ -6991,7 +6991,6 @@ const imageBox = {
6991
6991
  };
6992
6992
 
6993
6993
  const config = {
6994
- defaultLang: 'text',
6995
6994
  comment: '#57606a',
6996
6995
  name: '#444d56',
6997
6996
  variableName: '#953800',
@@ -7086,19 +7085,22 @@ const codeBlockBox = {
7086
7085
  return;
7087
7086
  }
7088
7087
  // begin to create CodeMirror
7089
- const CodeMirror = window.CodeMirror;
7088
+ const CodeMirror = window.LakeCodeMirror;
7090
7089
  if (!CodeMirror) {
7091
7090
  codeBlockNode.addClass('lake-code-block-error');
7092
7091
  codeBlockNode.text(`
7093
- The code cannot be displayed because window.CodeMirror is not found.
7094
- Please check if the CodeMirror file is added to this page.
7092
+ The code cannot be displayed because window.LakeCodeMirror is not found.
7093
+ Please check if the "lake-codemirror" library is added to this page.
7095
7094
  `.trim());
7096
7095
  codeBlockNode.on('click', () => {
7097
7096
  editor.selection.range.selectBox(box.node);
7098
7097
  });
7099
7098
  return;
7100
7099
  }
7101
- const { EditorState, Compartment, EditorView, keymap, history, defaultKeymap, historyKeymap, indentWithTab, syntaxHighlighting, langItems, } = CodeMirror;
7100
+ const { EditorState, Compartment, EditorView, keymap, history, defaultKeymap, historyKeymap, indentWithTab, syntaxHighlighting, } = CodeMirror;
7101
+ const defaultLangItems = CodeMirror.langItems;
7102
+ const codeBlockConfig = editor.config.codeBlock;
7103
+ const langItems = defaultLangItems.filter((item) => codeBlockConfig.langList.indexOf(item.value) >= 0);
7102
7104
  // language menu items
7103
7105
  const langItemMap = new Map();
7104
7106
  for (const item of langItems) {
@@ -7144,7 +7146,7 @@ const codeBlockBox = {
7144
7146
  root: codeBlockNode,
7145
7147
  name: 'langType',
7146
7148
  downIcon: icons.get('down'),
7147
- defaultValue: langItem ? boxValue.lang : config.defaultLang,
7149
+ defaultValue: langItem ? boxValue.lang : codeBlockConfig.defaultLang,
7148
7150
  tooltip: locale.codeBlock.langType(),
7149
7151
  width: 'auto',
7150
7152
  menuType: 'list',
@@ -7173,6 +7175,9 @@ const codeBlockBox = {
7173
7175
  };
7174
7176
 
7175
7177
  var copy = (editor) => {
7178
+ if (editor.readonly) {
7179
+ return;
7180
+ }
7176
7181
  editor.container.on('copy', event => {
7177
7182
  const range = editor.selection.range;
7178
7183
  if (range.isInsideBox) {
@@ -7197,6 +7202,9 @@ var copy = (editor) => {
7197
7202
  };
7198
7203
 
7199
7204
  var cut = (editor) => {
7205
+ if (editor.readonly) {
7206
+ return;
7207
+ }
7200
7208
  editor.container.on('cut', event => {
7201
7209
  const range = editor.selection.range;
7202
7210
  if (range.isInsideBox) {
@@ -7377,6 +7385,9 @@ function pasteFragment(editor, fragment) {
7377
7385
  editor.history.save();
7378
7386
  }
7379
7387
  var paste = (editor) => {
7388
+ if (editor.readonly) {
7389
+ return;
7390
+ }
7380
7391
  editor.container.on('paste', event => {
7381
7392
  const { requestTypes } = editor.config.image;
7382
7393
  const range = editor.selection.range;
@@ -7423,6 +7434,9 @@ var paste = (editor) => {
7423
7434
  };
7424
7435
 
7425
7436
  var undo = (editor) => {
7437
+ if (editor.readonly) {
7438
+ return;
7439
+ }
7426
7440
  editor.command.add('undo', {
7427
7441
  execute: () => {
7428
7442
  editor.history.undo();
@@ -7439,6 +7453,9 @@ var undo = (editor) => {
7439
7453
  };
7440
7454
 
7441
7455
  var redo = (editor) => {
7456
+ if (editor.readonly) {
7457
+ return;
7458
+ }
7442
7459
  editor.command.add('redo', {
7443
7460
  execute: () => {
7444
7461
  editor.history.redo();
@@ -7457,6 +7474,9 @@ var redo = (editor) => {
7457
7474
  };
7458
7475
 
7459
7476
  var selectAll = (editor) => {
7477
+ if (editor.readonly) {
7478
+ return;
7479
+ }
7460
7480
  editor.command.add('selectAll', {
7461
7481
  execute: () => {
7462
7482
  const range = editor.selection.range;
@@ -7467,6 +7487,9 @@ var selectAll = (editor) => {
7467
7487
  };
7468
7488
 
7469
7489
  var heading = (editor) => {
7490
+ if (editor.readonly) {
7491
+ return;
7492
+ }
7470
7493
  editor.command.add('heading', {
7471
7494
  selectedValues: appliedItems => {
7472
7495
  const currentItem = appliedItems.find(item => item.node.isHeading || item.name === 'p');
@@ -7488,6 +7511,9 @@ const typeList = [
7488
7511
  'danger',
7489
7512
  ];
7490
7513
  var blockQuote = (editor) => {
7514
+ if (editor.readonly) {
7515
+ return;
7516
+ }
7491
7517
  editor.command.add('blockQuote', {
7492
7518
  isSelected: appliedItems => !!appliedItems.find(item => item.name === 'blockquote'),
7493
7519
  execute: (type) => {
@@ -7515,6 +7541,9 @@ function setChecklist(editor, value) {
7515
7541
  editor.selection.setBlocks(`<ul type="checklist"><li value="${value}"></li></ul>`);
7516
7542
  }
7517
7543
  var list = (editor) => {
7544
+ if (editor.readonly) {
7545
+ return;
7546
+ }
7518
7547
  editor.command.add('list', {
7519
7548
  selectedValues: appliedItems => {
7520
7549
  let currentValue;
@@ -7615,6 +7644,9 @@ const alignValueMap = {
7615
7644
  end: 'right',
7616
7645
  };
7617
7646
  var align = (editor) => {
7647
+ if (editor.readonly) {
7648
+ return;
7649
+ }
7618
7650
  editor.command.add('align', {
7619
7651
  selectedValues: appliedItems => {
7620
7652
  let currentValue;
@@ -7639,6 +7671,9 @@ var align = (editor) => {
7639
7671
  };
7640
7672
 
7641
7673
  var indent = (editor) => {
7674
+ if (editor.readonly) {
7675
+ return;
7676
+ }
7642
7677
  editor.command.add('indent', {
7643
7678
  execute: (type) => {
7644
7679
  const blocks = editor.selection.range.getBlocks();
@@ -7652,6 +7687,9 @@ var indent = (editor) => {
7652
7687
 
7653
7688
  const tagName$6 = 'strong';
7654
7689
  var bold = (editor) => {
7690
+ if (editor.readonly) {
7691
+ return;
7692
+ }
7655
7693
  editor.command.add('bold', {
7656
7694
  isDisabled: appliedItems => !!appliedItems.find(item => item.node.isHeading),
7657
7695
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName$6),
@@ -7673,6 +7711,9 @@ var bold = (editor) => {
7673
7711
 
7674
7712
  const tagName$5 = 'i';
7675
7713
  var italic = (editor) => {
7714
+ if (editor.readonly) {
7715
+ return;
7716
+ }
7676
7717
  editor.command.add('italic', {
7677
7718
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName$5),
7678
7719
  execute: () => {
@@ -7693,6 +7734,9 @@ var italic = (editor) => {
7693
7734
 
7694
7735
  const tagName$4 = 'u';
7695
7736
  var underline = (editor) => {
7737
+ if (editor.readonly) {
7738
+ return;
7739
+ }
7696
7740
  editor.command.add('underline', {
7697
7741
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName$4),
7698
7742
  execute: () => {
@@ -7713,6 +7757,9 @@ var underline = (editor) => {
7713
7757
 
7714
7758
  const tagName$3 = 's';
7715
7759
  var strikethrough = (editor) => {
7760
+ if (editor.readonly) {
7761
+ return;
7762
+ }
7716
7763
  editor.command.add('strikethrough', {
7717
7764
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName$3),
7718
7765
  execute: () => {
@@ -7733,6 +7780,9 @@ var strikethrough = (editor) => {
7733
7780
 
7734
7781
  const tagName$2 = 'sub';
7735
7782
  var subscript = (editor) => {
7783
+ if (editor.readonly) {
7784
+ return;
7785
+ }
7736
7786
  editor.command.add('subscript', {
7737
7787
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName$2),
7738
7788
  execute: () => {
@@ -7749,6 +7799,9 @@ var subscript = (editor) => {
7749
7799
 
7750
7800
  const tagName$1 = 'sup';
7751
7801
  var superscript = (editor) => {
7802
+ if (editor.readonly) {
7803
+ return;
7804
+ }
7752
7805
  editor.command.add('superscript', {
7753
7806
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName$1),
7754
7807
  execute: () => {
@@ -7765,6 +7818,9 @@ var superscript = (editor) => {
7765
7818
 
7766
7819
  const tagName = 'code';
7767
7820
  var code = (editor) => {
7821
+ if (editor.readonly) {
7822
+ return;
7823
+ }
7768
7824
  editor.command.add('code', {
7769
7825
  isSelected: appliedItems => !!appliedItems.find(item => item.name === tagName),
7770
7826
  execute: () => {
@@ -7780,6 +7836,9 @@ var code = (editor) => {
7780
7836
  };
7781
7837
 
7782
7838
  var fontFamily = (editor) => {
7839
+ if (editor.readonly) {
7840
+ return;
7841
+ }
7783
7842
  editor.command.add('fontFamily', {
7784
7843
  selectedValues: appliedItems => {
7785
7844
  for (const item of appliedItems) {
@@ -7798,6 +7857,9 @@ var fontFamily = (editor) => {
7798
7857
  };
7799
7858
 
7800
7859
  var fontSize = (editor) => {
7860
+ if (editor.readonly) {
7861
+ return;
7862
+ }
7801
7863
  editor.command.add('fontSize', {
7802
7864
  isDisabled: appliedItems => !!appliedItems.find(item => item.node.isHeading),
7803
7865
  selectedValues: appliedItems => {
@@ -7817,6 +7879,9 @@ var fontSize = (editor) => {
7817
7879
  };
7818
7880
 
7819
7881
  var fontColor = (editor) => {
7882
+ if (editor.readonly) {
7883
+ return;
7884
+ }
7820
7885
  editor.command.add('fontColor', {
7821
7886
  selectedValues: appliedItems => {
7822
7887
  for (const item of appliedItems) {
@@ -7835,6 +7900,9 @@ var fontColor = (editor) => {
7835
7900
  };
7836
7901
 
7837
7902
  var highlight = (editor) => {
7903
+ if (editor.readonly) {
7904
+ return;
7905
+ }
7838
7906
  editor.command.add('highlight', {
7839
7907
  selectedValues: appliedItems => {
7840
7908
  for (const item of appliedItems) {
@@ -7853,6 +7921,9 @@ var highlight = (editor) => {
7853
7921
  };
7854
7922
 
7855
7923
  var removeFormat = (editor) => {
7924
+ if (editor.readonly) {
7925
+ return;
7926
+ }
7856
7927
  editor.command.add('removeFormat', {
7857
7928
  execute: () => {
7858
7929
  editor.selection.removeMark();
@@ -7863,6 +7934,9 @@ var removeFormat = (editor) => {
7863
7934
 
7864
7935
  const formatPainterClassName = 'lake-format-painter';
7865
7936
  var formatPainter = (editor) => {
7937
+ if (editor.readonly) {
7938
+ return;
7939
+ }
7866
7940
  let markList = [];
7867
7941
  editor.command.add('formatPainter', {
7868
7942
  execute: () => {
@@ -8127,6 +8201,9 @@ class LinkPopup {
8127
8201
  }
8128
8202
 
8129
8203
  var link = (editor) => {
8204
+ if (editor.readonly) {
8205
+ return;
8206
+ }
8130
8207
  const popup = new LinkPopup(editor.popupContainer);
8131
8208
  popup.event.on('save', node => {
8132
8209
  const range = editor.selection.range;
@@ -8178,6 +8255,9 @@ var link = (editor) => {
8178
8255
  };
8179
8256
 
8180
8257
  var hr = (editor) => {
8258
+ if (editor.readonly) {
8259
+ return;
8260
+ }
8181
8261
  editor.event.on('beforepaste', (nativeFragment) => {
8182
8262
  const fragment = new Fragment(nativeFragment);
8183
8263
  fragment.find('hr').each(nativeNode => {
@@ -8199,6 +8279,9 @@ var image = (editor) => {
8199
8279
  requestMethod: 'POST',
8200
8280
  requestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'],
8201
8281
  });
8282
+ if (editor.readonly) {
8283
+ return;
8284
+ }
8202
8285
  editor.event.on('beforepaste', (nativeFragment) => {
8203
8286
  const fragment = new Fragment(nativeFragment);
8204
8287
  fragment.find('img').each(nativeNode => {
@@ -8225,8 +8308,35 @@ var image = (editor) => {
8225
8308
  });
8226
8309
  };
8227
8310
 
8311
+ const langList = [
8312
+ 'text',
8313
+ 'c',
8314
+ 'csharp',
8315
+ 'cpp',
8316
+ 'css',
8317
+ 'go',
8318
+ 'html',
8319
+ 'java',
8320
+ 'javascript',
8321
+ 'json',
8322
+ 'markdown',
8323
+ 'php',
8324
+ 'python',
8325
+ 'rust',
8326
+ 'sql',
8327
+ 'typescript',
8328
+ 'xml',
8329
+ 'yaml',
8330
+ ];
8228
8331
  var codeBlock = (editor) => {
8229
- if (!window.CodeMirror) {
8332
+ if (!window.LakeCodeMirror) {
8333
+ return;
8334
+ }
8335
+ editor.setPluginConfig('codeBlock', {
8336
+ langList,
8337
+ defaultLang: 'text',
8338
+ });
8339
+ if (editor.readonly) {
8230
8340
  return;
8231
8341
  }
8232
8342
  editor.command.add('codeBlock', {
@@ -8505,6 +8615,9 @@ function enterKeyExecutesBlockCommand(editor, block) {
8505
8615
  return false;
8506
8616
  }
8507
8617
  var markdown = (editor) => {
8618
+ if (editor.readonly) {
8619
+ return;
8620
+ }
8508
8621
  editor.keystroke.setKeydown('space', event => {
8509
8622
  const selection = editor.selection;
8510
8623
  const range = selection.range;
@@ -8609,6 +8722,9 @@ function addBlockOrSplitBlockForBox(editor) {
8609
8722
  }
8610
8723
  }
8611
8724
  var enterKey = (editor) => {
8725
+ if (editor.readonly) {
8726
+ return;
8727
+ }
8612
8728
  editor.keystroke.setKeydown('enter', event => {
8613
8729
  const range = editor.selection.range;
8614
8730
  if (range.isInsideBox) {
@@ -8692,6 +8808,9 @@ function addBlockOrLineBreakForBox(editor) {
8692
8808
  }
8693
8809
  }
8694
8810
  var shiftEnterKey = (editor) => {
8811
+ if (editor.readonly) {
8812
+ return;
8813
+ }
8695
8814
  editor.keystroke.setKeydown('shift+enter', event => {
8696
8815
  const range = editor.selection.range;
8697
8816
  if (range.isInsideBox) {
@@ -8754,6 +8873,9 @@ function mergeWithPreviousBlock(editor, block) {
8754
8873
  editor.selection.fixList();
8755
8874
  }
8756
8875
  var backspaceKey = (editor) => {
8876
+ if (editor.readonly) {
8877
+ return;
8878
+ }
8757
8879
  editor.keystroke.setKeydown('backspace', event => {
8758
8880
  const range = editor.selection.range;
8759
8881
  if (range.isInsideBox) {
@@ -8871,6 +8993,9 @@ function mergeWithNextBlock(editor, block) {
8871
8993
  editor.selection.fixList();
8872
8994
  }
8873
8995
  var deleteKey = (editor) => {
8996
+ if (editor.readonly) {
8997
+ return;
8998
+ }
8874
8999
  editor.keystroke.setKeydown('delete', event => {
8875
9000
  const range = editor.selection.range;
8876
9001
  if (range.isInsideBox) {
@@ -8949,6 +9074,9 @@ var deleteKey = (editor) => {
8949
9074
  };
8950
9075
 
8951
9076
  var tabKey = (editor) => {
9077
+ if (editor.readonly) {
9078
+ return;
9079
+ }
8952
9080
  editor.keystroke.setKeydown('tab', event => {
8953
9081
  if (editor.config.indentWithTab === false) {
8954
9082
  return;
@@ -8967,6 +9095,9 @@ var tabKey = (editor) => {
8967
9095
  };
8968
9096
 
8969
9097
  var arrowKeys = (editor) => {
9098
+ if (editor.readonly) {
9099
+ return;
9100
+ }
8970
9101
  editor.keystroke.setKeydown('arrow-left', event => {
8971
9102
  const range = editor.selection.range;
8972
9103
  if (range.isInsideBox) {
@@ -9088,6 +9219,9 @@ var arrowKeys = (editor) => {
9088
9219
  };
9089
9220
 
9090
9221
  var escapeKey = (editor) => {
9222
+ if (editor.readonly) {
9223
+ return;
9224
+ }
9091
9225
  editor.keystroke.setKeydown('escape', event => {
9092
9226
  const selection = editor.selection;
9093
9227
  const range = selection.range;