lakelib 0.1.15 → 0.1.16

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
@@ -310,7 +310,8 @@ button.lake-primary-button.lake-button-hovered {
310
310
  cursor: default;
311
311
  }
312
312
  .lake-dropdown.lake-list-dropdown button.lake-dropdown-title-hovered,
313
- .lake-dropdown.lake-icon-dropdown button.lake-dropdown-title-hovered {
313
+ .lake-dropdown.lake-icon-dropdown button.lake-dropdown-title-hovered,
314
+ .lake-dropdown.lake-character-dropdown button.lake-dropdown-title-hovered {
314
315
  background-color: var(--background-hover-color);
315
316
  }
316
317
  .lake-dropdown button.lake-dropdown-title.lake-dropdown-title-no-down {
@@ -380,6 +381,10 @@ button.lake-primary-button.lake-button-hovered {
380
381
  top: auto;
381
382
  bottom: 30px;
382
383
  }
384
+ .lake-dropdown .lake-dropdown-menu.lake-dropdown-menu-with-scroll {
385
+ overflow-y: scroll;
386
+ scrollbar-width: thin;
387
+ }
383
388
  .lake-dropdown .lake-dropdown-menu li {
384
389
  display: flex;
385
390
  align-items: center;
@@ -446,6 +451,34 @@ button.lake-primary-button.lake-button-hovered {
446
451
  .lake-dropdown .lake-icon-dropdown-menu li .lake-dropdown-menu-text {
447
452
  display: none;
448
453
  }
454
+ /* character type */
455
+ .lake-dropdown .lake-character-dropdown-menu {
456
+ flex-wrap: wrap;
457
+ justify-content: center;
458
+ }
459
+ .lake-dropdown .lake-character-dropdown-menu li {
460
+ padding: 0;
461
+ border-radius: 2px;
462
+ }
463
+ .lake-dropdown .lake-character-dropdown-menu li.lake-dropdown-item-hovered {
464
+ background-color: var(--background-hover-color);
465
+ }
466
+ .lake-dropdown .lake-character-dropdown-menu li.lake-dropdown-item-selected {
467
+ background-color: var(--background-active-color);
468
+ }
469
+ .lake-dropdown .lake-character-dropdown-menu li .lake-dropdown-menu-check {
470
+ display: none;
471
+ }
472
+ .lake-dropdown .lake-character-dropdown-menu li .lake-dropdown-menu-icon {
473
+ display: none;
474
+ }
475
+ .lake-dropdown .lake-character-dropdown-menu li .lake-dropdown-menu-text {
476
+ text-align: center;
477
+ font-size: 24px;
478
+ width: 42px;
479
+ height: 42px;
480
+ line-height: 42px;
481
+ }
449
482
  /* color type */
450
483
  .lake-dropdown .lake-color-dropdown-menu {
451
484
  flex-wrap: wrap;
@@ -939,9 +972,6 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block .lake-dropdown {
939
972
  top: 24px;
940
973
  left: auto;
941
974
  right: 0;
942
- overflow-y: scroll;
943
- scrollbar-width: thin;
944
- height: 200px;
945
975
  }
946
976
  .lake-code-block-error {
947
977
  font-size: 14px;
package/lib/lake.js CHANGED
@@ -1,9 +1,7 @@
1
- import { Base64 } from 'js-base64';
2
1
  import EventEmitter from 'eventemitter3';
3
2
  import { i18nObject as i18nObject$1 } from 'typesafe-i18n';
4
- import debounce from 'lodash/debounce';
5
- import isEqual from 'lodash/isEqual';
6
- import md5 from 'blueimp-md5';
3
+ import debounce from 'debounce';
4
+ import isEqual from 'fast-deep-equal/es6';
7
5
  import { createKeybindingsHandler } from 'tinykeys';
8
6
  import 'photoswipe/style.css';
9
7
  import PhotoSwipeLightbox from 'photoswipe/lightbox';
@@ -145,6 +143,8 @@ var attachment = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=
145
143
 
146
144
  var emoji$1 = "<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,216ZM80,108a12,12,0,1,1,12,12A12,12,0,0,1,80,108Zm96,0a12,12,0,1,1-12-12A12,12,0,0,1,176,108Zm-1.07,48c-10.29,17.79-27.4,28-46.93,28s-36.63-10.2-46.92-28a8,8,0,1,1,13.84-8c7.47,12.91,19.21,20,33.08,20s25.61-7.1,33.07-20a8,8,0,0,1,13.86,8Z\"></path></svg>";
147
145
 
146
+ var specialCharacter = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 32 32\"><path d=\"M22.7373,25A14.3093,14.3093,0,0,0,27,15C27,8.42,22.58,4,16,4S5,8.42,5,15A14.3093,14.3093,0,0,0,9.2627,25H4v2h8V24.7617A12.5683,12.5683,0,0,1,7,15c0-5.4673,3.5327-9,9-9s9,3.5327,9,9a12.5683,12.5683,0,0,1-5,9.7617V27h8V25Z\"/></svg>";
147
+
148
148
  var table = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M224,48H32a8,8,0,0,0-8,8V192a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A8,8,0,0,0,224,48ZM40,112H80v32H40Zm56,0H216v32H96ZM216,64V96H40V64ZM40,160H80v32H40Zm176,32H96V160H216v32Z\"></path></svg>";
149
149
 
150
150
  // These icons are sourced from open source projects.
@@ -224,6 +224,7 @@ const icons = new Map([
224
224
  ['video', video$1],
225
225
  ['attachment', attachment],
226
226
  ['emoji', emoji$1],
227
+ ['specialCharacter', specialCharacter],
227
228
  ['table', table],
228
229
  ]);
229
230
 
@@ -287,6 +288,28 @@ function inString(string, value, delimiter) {
287
288
  return (delimiter + string + delimiter).indexOf(delimiter + value + delimiter) >= 0;
288
289
  }
289
290
 
291
+ // Creates a Base64-encoded ASCII string from a string.
292
+ function toBase64(value) {
293
+ const encoder = new TextEncoder();
294
+ const byteArray = encoder.encode(value);
295
+ let binaryString = '';
296
+ byteArray.forEach(byte => {
297
+ binaryString += String.fromCharCode(byte);
298
+ });
299
+ return window.btoa(binaryString);
300
+ }
301
+
302
+ // Decodes a string of data which has been encoded using Base64 encoding.
303
+ function fromBase64(value) {
304
+ const binaryString = window.atob(value);
305
+ const byteArray = new Uint8Array(binaryString.length);
306
+ for (let i = 0; i < binaryString.length; i++) {
307
+ byteArray[i] = binaryString.charCodeAt(i);
308
+ }
309
+ const decoder = new TextDecoder();
310
+ return decoder.decode(byteArray);
311
+ }
312
+
290
313
  // Converts an alpha value to a hex value.
291
314
  function alphaToHex(value) {
292
315
  const hexString = Math.round(Number.parseFloat(value) * 255).toString(16);
@@ -3204,11 +3227,11 @@ class Dropdown {
3204
3227
  if (value === '') {
3205
3228
  return [];
3206
3229
  }
3207
- return JSON.parse(Base64.decode(value));
3230
+ return JSON.parse(fromBase64(value));
3208
3231
  }
3209
3232
  // Updates the value of the node.
3210
3233
  static setValue(node, value) {
3211
- node.attr('value', Base64.encode(JSON.stringify(value)));
3234
+ node.attr('value', toBase64(JSON.stringify(value)));
3212
3235
  }
3213
3236
  static getMenuMap(menuItems, locale) {
3214
3237
  const menuMap = new Map();
@@ -3241,7 +3264,11 @@ class Dropdown {
3241
3264
  `;
3242
3265
  const listNode = query(listContent);
3243
3266
  menuNode.append(listNode);
3244
- if (config.menuType === 'color') {
3267
+ if (config.menuType === 'character') {
3268
+ listNode.attr('title', menuText);
3269
+ listNode.find('.lake-dropdown-menu-text').text(menuItem.value);
3270
+ }
3271
+ else if (config.menuType === 'color') {
3245
3272
  listNode.attr('title', menuText);
3246
3273
  listNode.find('.lake-dropdown-menu-text').css('background-color', menuItem.value);
3247
3274
  }
@@ -3357,7 +3384,11 @@ class Dropdown {
3357
3384
  });
3358
3385
  menuNode.on('click', event => {
3359
3386
  event.preventDefault();
3387
+ event.stopPropagation();
3360
3388
  const listItem = query(event.target).closest('li');
3389
+ if (listItem.length === 0) {
3390
+ return;
3391
+ }
3361
3392
  const value = listItem.attr('value');
3362
3393
  Dropdown.setValue(dropdownNode, [value]);
3363
3394
  if (textNode.length > 0) {
@@ -3403,6 +3434,10 @@ class Dropdown {
3403
3434
  if (config.menuWidth) {
3404
3435
  menuNode.css('width', config.menuWidth);
3405
3436
  }
3437
+ if (config.menuHeight) {
3438
+ menuNode.addClass('lake-dropdown-menu-with-scroll');
3439
+ menuNode.css('height', config.menuHeight);
3440
+ }
3406
3441
  Dropdown.setValue(dropdownNode, [defaultValue]);
3407
3442
  if (textNode.length > 0) {
3408
3443
  const menuMap = Dropdown.getMenuMap(config.menuItems, this.locale);
@@ -3590,11 +3625,11 @@ class Box {
3590
3625
  if (value === '') {
3591
3626
  return {};
3592
3627
  }
3593
- return JSON.parse(Base64.decode(value));
3628
+ return JSON.parse(fromBase64(value));
3594
3629
  }
3595
3630
  // Sets the value of the box.
3596
3631
  set value(value) {
3597
- this.node.attr('value', Base64.encode(JSON.stringify(value)));
3632
+ this.node.attr('value', toBase64(JSON.stringify(value)));
3598
3633
  }
3599
3634
  updateValue(valueKey, valueValue) {
3600
3635
  const value = this.value;
@@ -3918,6 +3953,7 @@ var index = /*#__PURE__*/Object.freeze({
3918
3953
  encode: encode,
3919
3954
  fileSize: fileSize,
3920
3955
  fixNumberedList: fixNumberedList,
3956
+ fromBase64: fromBase64,
3921
3957
  getBox: getBox,
3922
3958
  getCSS: getCSS,
3923
3959
  getDeepest: getDeepest,
@@ -3936,6 +3972,7 @@ var index = /*#__PURE__*/Object.freeze({
3936
3972
  setBlockIndent: setBlockIndent,
3937
3973
  splitNodes: splitNodes,
3938
3974
  template: template,
3975
+ toBase64: toBase64,
3939
3976
  toHex: toHex,
3940
3977
  toNodeList: toNodeList,
3941
3978
  uploadFile: uploadFile,
@@ -5080,7 +5117,7 @@ function removeBox(range) {
5080
5117
  return box;
5081
5118
  }
5082
5119
 
5083
- var version = "0.1.15";
5120
+ var version = "0.1.16";
5084
5121
 
5085
5122
  // Returns the attributes of the element as an key-value object.
5086
5123
  function getAttributes(node) {
@@ -5361,7 +5398,7 @@ class History {
5361
5398
  addIdToBoxes(node) {
5362
5399
  node.find('lake-box').each(nativeNode => {
5363
5400
  const boxNode = new Nodes(nativeNode);
5364
- const id = md5(`${boxNode.attr('type')}-${boxNode.attr('name')}-${boxNode.attr('value')}`);
5401
+ const id = `${boxNode.attr('name')}-${boxNode.attr('value')}`;
5365
5402
  boxNode.attr('id', id);
5366
5403
  });
5367
5404
  }
@@ -5730,9 +5767,7 @@ class Editor {
5730
5767
  box.event.emit('blur');
5731
5768
  });
5732
5769
  }, 50, {
5733
- leading: false,
5734
- trailing: true,
5735
- maxWait: 50,
5770
+ immediate: true,
5736
5771
  });
5737
5772
  // Triggers the statechange event when the current selection of the editor is changed.
5738
5773
  this.emitStateChangeEvent = debounce(() => {
@@ -5776,10 +5811,8 @@ class Editor {
5776
5811
  }
5777
5812
  this.event.emit('statechange', state);
5778
5813
  this.state = state;
5779
- }, 100, {
5780
- leading: false,
5781
- trailing: true,
5782
- maxWait: 100,
5814
+ }, 50, {
5815
+ immediate: false,
5783
5816
  });
5784
5817
  if (!config.root) {
5785
5818
  throw new Error('The root of the config must be specified.');
@@ -6033,8 +6066,12 @@ class Editor {
6033
6066
  }
6034
6067
  // Scrolls to the caret or the range of the selection.
6035
6068
  scrollToCaret() {
6069
+ const range = this.selection.range;
6070
+ if (range.isBox) {
6071
+ return;
6072
+ }
6036
6073
  // Creates an artificial caret that is the same size as the caret at the current caret position.
6037
- const rangeRect = this.selection.range.getRect();
6074
+ const rangeRect = range.getRect();
6038
6075
  if (rangeRect.x === 0 || rangeRect.y === 0) {
6039
6076
  return;
6040
6077
  }
@@ -6838,6 +6875,7 @@ class Toolbar {
6838
6875
  menuType: item.menuType,
6839
6876
  menuItems: item.menuItems,
6840
6877
  menuWidth: item.menuWidth,
6878
+ menuHeight: item.menuHeight,
6841
6879
  tabIndex: -1,
6842
6880
  placement: this.placement === 'top' ? 'bottom' : 'top',
6843
6881
  onSelect: value => {
@@ -7165,18 +7203,18 @@ const codeBlockBox = {
7165
7203
  defaultValue: langItem ? boxValue.lang : codeBlockConfig.defaultLang,
7166
7204
  tooltip: editor.locale.codeBlock.langType(),
7167
7205
  menuType: 'list',
7206
+ menuHeight: '200px',
7168
7207
  menuItems: langItems.map((item) => ({
7169
7208
  value: item.value,
7170
7209
  text: item.text,
7171
7210
  })),
7172
7211
  onSelect: value => {
7173
- const item = langItemMap.get(value);
7174
- codeEditor.dispatch({
7175
- effects: language.reconfigure(item && item.component ? item.component() : []),
7176
- });
7177
7212
  box.updateValue({
7178
7213
  lang: value,
7179
7214
  });
7215
+ box.unmount();
7216
+ box.render();
7217
+ editor.selection.selectBox(box);
7180
7218
  editor.history.save();
7181
7219
  },
7182
7220
  });