lakelib 0.0.7 → 0.1.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
@@ -33,12 +33,11 @@
33
33
  }
34
34
 
35
35
  .lake-container {
36
+ box-sizing: content-box;
36
37
  font-family: var(--font-family);
37
38
  font-size: 16px;
38
39
  font-weight: normal;
39
40
  line-height: normal;
40
- color: var(--text-color);
41
- background-color: #fff;
42
41
  padding: 16px 24px;
43
42
  }
44
43
  .lake-container:focus {
@@ -379,8 +378,9 @@ button.lake-text-button span {
379
378
  .lake-container h4,
380
379
  .lake-container h5,
381
380
  .lake-container h6 {
382
- color: #000000e0;
383
381
  font-weight: bold;
382
+ line-height: normal;
383
+ border: 0;
384
384
  margin: 0;
385
385
  padding: 0;
386
386
  }
@@ -496,6 +496,7 @@ button.lake-text-button span {
496
496
  padding-left: 24px;
497
497
  }
498
498
  .lake-container ul[type="checklist"] li::before {
499
+ box-sizing: content-box;
499
500
  content: '';
500
501
  position: absolute;
501
502
  top: 3px;
@@ -513,6 +514,7 @@ button.lake-text-button span {
513
514
  background-color: #fff;
514
515
  }
515
516
  .lake-container ul[type="checklist"] li::after {
517
+ box-sizing: content-box;
516
518
  content: '';
517
519
  position: absolute;
518
520
  top: 3px;
@@ -534,6 +536,7 @@ button.lake-text-button span {
534
536
  }
535
537
 
536
538
  .lake-container blockquote {
539
+ box-sizing: content-box;
537
540
  margin: 0;
538
541
  margin-bottom: 8px;
539
542
  padding: 8px 12px;
@@ -544,19 +547,21 @@ button.lake-text-button span {
544
547
  color: var(--text-color);
545
548
  border-radius: 8px;
546
549
  }
550
+ .lake-container blockquote[type="info"],
551
+ .lake-container blockquote[type="tip"] {
552
+ background-color: #e6f4ff;
553
+ border: 1px solid #91caff;
554
+ }
547
555
  .lake-container blockquote[type="success"] {
548
556
  background-color: #f6ffed;
549
557
  border: 1px solid #b7eb8f;
550
558
  }
551
- .lake-container blockquote[type="info"] {
552
- background-color: #e6f4ff;
553
- border: 1px solid #91caff;
554
- }
555
559
  .lake-container blockquote[type="warning"] {
556
560
  background-color: #fffbe6;
557
561
  border: 1px solid #ffe58f;
558
562
  }
559
- .lake-container blockquote[type="error"] {
563
+ .lake-container blockquote[type="error"],
564
+ .lake-container blockquote[type="danger"] {
560
565
  background-color: #fff2f0;
561
566
  border: 1px solid #ffccc7;
562
567
  }
@@ -658,11 +663,11 @@ lake-box[name="hr"] .lake-box-focused .lake-hr {
658
663
  .lake-image {
659
664
  position: relative;
660
665
  line-height: 0;
666
+ box-sizing: content-box;
661
667
  border: 1px solid transparent;
662
668
  border-radius: 4px;
663
669
  }
664
670
  .lake-image .lake-image-img {
665
- box-sizing: border-box;
666
671
  border: 0;
667
672
  border-radius: 4px;
668
673
  width: 100%;
@@ -881,6 +886,8 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block .lake-dropdown {
881
886
  }
882
887
  .lake-code-block .lake-dropdown .lake-dropdown-menu {
883
888
  top: 24px;
889
+ left: auto;
890
+ right: 0;
884
891
  overflow-y: scroll;
885
892
  scrollbar-width: thin;
886
893
  height: 200px;
@@ -898,6 +905,7 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block .lake-dropdown {
898
905
  top: 0;
899
906
  left: 0;
900
907
  z-index: 1;
908
+ box-sizing: content-box;
901
909
  border: 1px solid var(--border-color);
902
910
  border-radius: 5px;
903
911
  padding: 16px;
@@ -940,8 +948,6 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block .lake-dropdown {
940
948
  font-size: 14px;
941
949
  font-weight: normal;
942
950
  line-height: normal;
943
- color: var(--text-color);
944
- background-color: #fff;
945
951
  padding: 4px;
946
952
  display: flex;
947
953
  flex-wrap: wrap;
package/lib/lake.js CHANGED
@@ -11,11 +11,15 @@ import PhotoSwipe from 'photoswipe';
11
11
 
12
12
  class BoxElement extends HTMLElement {
13
13
  }
14
- customElements.define('lake-box', BoxElement);
14
+ if (customElements.get('lake-box') !== undefined) {
15
+ customElements.define('lake-box', BoxElement);
16
+ }
15
17
 
16
18
  class BookmarkElement extends HTMLElement {
17
19
  }
18
- customElements.define('lake-bookmark', BookmarkElement);
20
+ if (customElements.get('lake-bookmark') !== undefined) {
21
+ customElements.define('lake-bookmark', BookmarkElement);
22
+ }
19
23
 
20
24
  var plus = "<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,216Zm48-88a8,8,0,0,1-8,8H136v32a8,8,0,0,1-16,0V136H88a8,8,0,0,1,0-16h32V88a8,8,0,0,1,16,0v32h32A8,8,0,0,1,176,128Z\"></path></svg>";
21
25
 
@@ -2995,7 +2999,7 @@ function getElementRules() {
2995
2999
  h5: Object.assign({}, blockAttributeRules),
2996
3000
  h6: Object.assign({}, blockAttributeRules),
2997
3001
  p: Object.assign({}, blockAttributeRules),
2998
- blockquote: Object.assign(Object.assign({}, blockAttributeRules), { type: ['success', 'info', 'warning', 'error'] }),
3002
+ blockquote: Object.assign(Object.assign({}, blockAttributeRules), { type: ['info', 'tip', 'success', 'warning', 'error', 'danger'] }),
2999
3003
  ul: Object.assign(Object.assign({}, blockAttributeRules), { type: 'checklist', indent: /^\d+$/ }),
3000
3004
  ol: Object.assign(Object.assign({}, blockAttributeRules), { start: /^\d+$/, indent: /^\d+$/ }),
3001
3005
  li: {
@@ -4295,7 +4299,7 @@ class Dropdown {
4295
4299
  }
4296
4300
  }
4297
4301
 
4298
- var version = "0.0.7";
4302
+ var version = "0.1.1";
4299
4303
 
4300
4304
  // Inserts a box into the specified range.
4301
4305
  function insertBox(range, boxName, boxValue) {
@@ -4898,9 +4902,6 @@ const defaultConfig = {
4898
4902
  tabIndex: 0,
4899
4903
  indentWithTab: true,
4900
4904
  minChangeSize: 5,
4901
- imageRequestMethod: 'POST',
4902
- imageRequestAction: '/upload',
4903
- imageRequestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'],
4904
4905
  };
4905
4906
  class Editor {
4906
4907
  constructor(config) {
@@ -5034,7 +5035,10 @@ class Editor {
5034
5035
  }
5035
5036
  this.root = query(config.root);
5036
5037
  this.toolbar = config.toolbar;
5037
- this.config = Object.assign(Object.assign({}, defaultConfig), config);
5038
+ this.config = Object.assign({}, defaultConfig);
5039
+ for (const key of Object.keys(config)) {
5040
+ this.config[key] = config[key];
5041
+ }
5038
5042
  this.containerWrapper = query('<div class="lake-container-wrapper" />');
5039
5043
  this.container = query('<div class="lake-container" />');
5040
5044
  this.overlayContainer = query('<div class="lake-overlay" />');
@@ -5203,6 +5207,17 @@ class Editor {
5203
5207
  this.history.continue();
5204
5208
  this.history.save();
5205
5209
  }
5210
+ // Sets default config for a plugin.
5211
+ setPluginConfig(pluginName, pluginConfig) {
5212
+ if (!this.config[pluginName]) {
5213
+ this.config[pluginName] = {};
5214
+ }
5215
+ for (const key of Object.keys(pluginConfig)) {
5216
+ if (this.config[pluginName][key] === undefined) {
5217
+ this.config[pluginName][key] = pluginConfig[key];
5218
+ }
5219
+ }
5220
+ }
5206
5221
  // Sets focus on the editor area.
5207
5222
  focus() {
5208
5223
  this.container.focus();
@@ -5261,7 +5276,6 @@ class Editor {
5261
5276
  this.container.append(fragment);
5262
5277
  if (!this.readonly) {
5263
5278
  this.bindFocusEvents();
5264
- this.focus();
5265
5279
  this.selection.synByBookmark();
5266
5280
  this.history.save();
5267
5281
  Editor.plugin.loadAll(this);
@@ -5273,11 +5287,11 @@ class Editor {
5273
5287
  if (!this.readonly) {
5274
5288
  window.addEventListener('beforeunload', this.beforeunloadListener);
5275
5289
  document.addEventListener('selectionchange', this.selectionchangeListener);
5290
+ document.addEventListener('click', this.clickListener);
5291
+ window.addEventListener('resize', this.resizeListener);
5276
5292
  this.bindInputEvents();
5277
5293
  this.bindHistoryEvents();
5278
5294
  }
5279
- document.addEventListener('click', this.clickListener);
5280
- window.addEventListener('resize', this.resizeListener);
5281
5295
  }
5282
5296
  // Destroys a rendered editor.
5283
5297
  unmount() {
@@ -5286,9 +5300,9 @@ class Editor {
5286
5300
  if (!this.readonly) {
5287
5301
  window.removeEventListener('beforeunload', this.beforeunloadListener);
5288
5302
  document.removeEventListener('selectionchange', this.selectionchangeListener);
5303
+ document.removeEventListener('click', this.clickListener);
5304
+ window.removeEventListener('resize', this.resizeListener);
5289
5305
  }
5290
- document.removeEventListener('click', this.clickListener);
5291
- window.removeEventListener('resize', this.resizeListener);
5292
5306
  }
5293
5307
  }
5294
5308
  Editor.version = version;
@@ -6229,9 +6243,9 @@ const toolbarItems = [
6229
6243
 
6230
6244
  function uploadImage(config) {
6231
6245
  const { editor, file, onError, onSuccess } = config;
6232
- const { imageRequestMethod, imageRequestAction, imageRequestTypes } = editor.config;
6233
- if (imageRequestTypes.indexOf(file.type) < 0) {
6234
- throw new Error(`Cannot upload file because its type '${file.type}' is not found in ['${imageRequestTypes.join('\', \'')}'].`);
6246
+ const { requestMethod, requestAction, requestTypes } = editor.config.image;
6247
+ if (requestTypes.indexOf(file.type) < 0) {
6248
+ throw new Error(`Cannot upload file because its type '${file.type}' is not found in ['${requestTypes.join('\', \'')}'].`);
6235
6249
  }
6236
6250
  const box = editor.insertBox('image', {
6237
6251
  url: URL.createObjectURL(file),
@@ -6275,8 +6289,8 @@ function uploadImage(config) {
6275
6289
  }
6276
6290
  },
6277
6291
  file,
6278
- action: imageRequestAction,
6279
- method: imageRequestMethod,
6292
+ action: requestAction,
6293
+ method: requestMethod,
6280
6294
  });
6281
6295
  box.setData('xhr', xhr);
6282
6296
  return box;
@@ -6955,10 +6969,15 @@ const imageBox = {
6955
6969
  container.empty();
6956
6970
  container.append(imageNode);
6957
6971
  imageNode.find('.lake-button-view').on('click', () => openFullScreen(box));
6958
- imageNode.find('.lake-button-remove').on('click', event => {
6959
- event.stopPropagation();
6960
- removeImageBox(box);
6961
- });
6972
+ if (editor.readonly) {
6973
+ imageNode.find('.lake-button-remove').hide();
6974
+ }
6975
+ else {
6976
+ imageNode.find('.lake-button-remove').on('click', event => {
6977
+ event.stopPropagation();
6978
+ removeImageBox(box);
6979
+ });
6980
+ }
6962
6981
  box.event.emit('render');
6963
6982
  });
6964
6983
  imageNode.on('click', () => {
@@ -7358,8 +7377,8 @@ function pasteFragment(editor, fragment) {
7358
7377
  editor.history.save();
7359
7378
  }
7360
7379
  var paste = (editor) => {
7361
- const { imageRequestTypes } = editor.config;
7362
7380
  editor.container.on('paste', event => {
7381
+ const { requestTypes } = editor.config.image;
7363
7382
  const range = editor.selection.range;
7364
7383
  if (range.isInsideBox) {
7365
7384
  return;
@@ -7373,7 +7392,7 @@ var paste = (editor) => {
7373
7392
  // upload file
7374
7393
  if (dataTransfer.files.length > 0) {
7375
7394
  for (const file of dataTransfer.files) {
7376
- if (imageRequestTypes.indexOf(file.type) >= 0) {
7395
+ if (requestTypes.indexOf(file.type) >= 0) {
7377
7396
  uploadImage({
7378
7397
  editor,
7379
7398
  file,
@@ -7460,11 +7479,24 @@ var heading = (editor) => {
7460
7479
  });
7461
7480
  };
7462
7481
 
7482
+ const typeList = [
7483
+ 'info',
7484
+ 'tip',
7485
+ 'success',
7486
+ 'warning',
7487
+ 'error',
7488
+ 'danger',
7489
+ ];
7463
7490
  var blockQuote = (editor) => {
7464
7491
  editor.command.add('blockQuote', {
7465
7492
  isSelected: appliedItems => !!appliedItems.find(item => item.name === 'blockquote'),
7466
- execute: () => {
7467
- editor.selection.setBlocks('<blockquote />');
7493
+ execute: (type) => {
7494
+ if (type && typeList.indexOf(type) >= 0) {
7495
+ editor.selection.setBlocks(safeTemplate `<blockquote type="${type}" />`);
7496
+ }
7497
+ else {
7498
+ editor.selection.setBlocks('<blockquote />');
7499
+ }
7468
7500
  editor.history.save();
7469
7501
  },
7470
7502
  });
@@ -7829,9 +7861,9 @@ var removeFormat = (editor) => {
7829
7861
  });
7830
7862
  };
7831
7863
 
7832
- let markList = [];
7833
7864
  const formatPainterClassName = 'lake-format-painter';
7834
7865
  var formatPainter = (editor) => {
7866
+ let markList = [];
7835
7867
  editor.command.add('formatPainter', {
7836
7868
  execute: () => {
7837
7869
  editor.container.addClass(formatPainterClassName);
@@ -7856,7 +7888,7 @@ var formatPainter = (editor) => {
7856
7888
  editor.history.save();
7857
7889
  });
7858
7890
  editor.event.on('click', (tagetNode) => {
7859
- if (tagetNode.isInside) {
7891
+ if (tagetNode.isInside && tagetNode.closestContainer().get(0) === editor.container.get(0)) {
7860
7892
  return;
7861
7893
  }
7862
7894
  const buttonNode = tagetNode.closest('button[name="formatPainter"]');
@@ -8126,17 +8158,13 @@ var link = (editor) => {
8126
8158
  return;
8127
8159
  }
8128
8160
  if (linkNode.isOutside ||
8161
+ linkNode.closestContainer().get(0) !== editor.container.get(0) ||
8129
8162
  linkNode.closest('lake-box').length > 0) {
8163
+ popup.hide();
8130
8164
  return;
8131
8165
  }
8132
8166
  popup.show(linkNode);
8133
8167
  });
8134
- editor.container.on('click', event => {
8135
- const targetNode = new Nodes(event.target);
8136
- if (targetNode.closest('a').length > 0) {
8137
- event.preventDefault();
8138
- }
8139
- });
8140
8168
  editor.command.add('link', {
8141
8169
  execute: () => {
8142
8170
  const linkNode = editor.selection.insertLink(`<a href="">${locale.link.newLink()}</a>`);
@@ -8167,6 +8195,10 @@ var hr = (editor) => {
8167
8195
  };
8168
8196
 
8169
8197
  var image = (editor) => {
8198
+ editor.setPluginConfig('image', {
8199
+ requestMethod: 'POST',
8200
+ requestTypes: ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'],
8201
+ });
8170
8202
  editor.event.on('beforepaste', (nativeFragment) => {
8171
8203
  const fragment = new Fragment(nativeFragment);
8172
8204
  fragment.find('img').each(nativeNode => {
@@ -8310,7 +8342,22 @@ const blockItemListForSpaceKey = [
8310
8342
  ];
8311
8343
  const blockItemListForEnterKey = [
8312
8344
  {
8313
- re: /^-+$/,
8345
+ re: /^:{3,}([a-z]*)$/i,
8346
+ getParameters: (results) => {
8347
+ if (!results[1]) {
8348
+ return [
8349
+ 'blockQuote',
8350
+ 'info',
8351
+ ];
8352
+ }
8353
+ return [
8354
+ 'blockQuote',
8355
+ results[1],
8356
+ ];
8357
+ },
8358
+ },
8359
+ {
8360
+ re: /^-{3,}$/,
8314
8361
  getParameters: () => [
8315
8362
  'hr',
8316
8363
  ],