lakelib 0.1.5 → 0.1.7

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
@@ -34,6 +34,7 @@
34
34
 
35
35
  .lake-container {
36
36
  box-sizing: content-box;
37
+ position: relative;
37
38
  font-family: var(--font-family);
38
39
  font-size: 16px;
39
40
  font-weight: normal;
@@ -48,6 +49,14 @@
48
49
  color: inherit;
49
50
  background: var(--selection-background-color);
50
51
  }
52
+ .lake-container.lake-show-placeholder::before {
53
+ position: absolute;
54
+ top: 8px;
55
+ left: 12px;
56
+ color: var(--secondary-text-color);
57
+ content: attr(placeholder);
58
+ pointer-events: none;
59
+ }
51
60
  .lake-container bookmark {
52
61
  display: inline;
53
62
  }
@@ -240,6 +249,10 @@ button.lake-text-button span {
240
249
  box-shadow: var(--popup-shadow);
241
250
  display: none;
242
251
  }
252
+ .lake-dropdown[placement="top"] .lake-dropdown-menu {
253
+ top: auto;
254
+ bottom: 30px;
255
+ }
243
256
  .lake-dropdown .lake-dropdown-menu li {
244
257
  display: flex;
245
258
  align-items: center;
@@ -851,9 +864,6 @@ lake-box[name="image"] .lake-box-selected .lake-image-error {
851
864
  lake-box[name="codeBlock"] {
852
865
  margin: 16px 0;
853
866
  }
854
- lake-box[name="codeBlock"] .lake-box-container {
855
- overflow-x: auto;
856
- }
857
867
  lake-box[name="codeBlock"] .lake-box-focused .lake-code-block,
858
868
  lake-box[name="codeBlock"] .lake-box-activated .lake-code-block {
859
869
  border-color: var(--box-border-color);
package/lib/lake.js CHANGED
@@ -330,14 +330,6 @@ function modifierText(value, userAgent) {
330
330
  return value.replace(/(^|\+|\s)mod(\+|\s|$)/g, `$1${modText}$2`);
331
331
  }
332
332
 
333
- function forEach(map, callback) {
334
- for (const key in map) {
335
- if (callback(key, map[key]) === false) {
336
- break;
337
- }
338
- }
339
- }
340
-
341
333
  // Returns a property value of all CSS properties of an element
342
334
  function getCSS(element, propertyName) {
343
335
  const camelPropertyName = camelCase(propertyName);
@@ -897,9 +889,9 @@ class Nodes {
897
889
  attr(attributeName, value) {
898
890
  var _a;
899
891
  if (typeof attributeName === 'object') {
900
- forEach(attributeName, (name, val) => {
901
- this.attr(name, val);
902
- });
892
+ for (const name of Object.keys(attributeName)) {
893
+ this.attr(name, attributeName[name]);
894
+ }
903
895
  return this;
904
896
  }
905
897
  if (value === undefined) {
@@ -956,9 +948,9 @@ class Nodes {
956
948
  }
957
949
  css(propertyName, value) {
958
950
  if (typeof propertyName === 'object') {
959
- forEach(propertyName, (name, val) => {
960
- this.css(name, val);
961
- });
951
+ for (const name of Object.keys(propertyName)) {
952
+ this.css(name, propertyName[name]);
953
+ }
962
954
  return this;
963
955
  }
964
956
  if (value === undefined) {
@@ -979,8 +971,8 @@ class Nodes {
979
971
  }
980
972
  // Returns the interior width of the first element, which does not include padding.
981
973
  innerWidth() {
982
- const paddingLeft = parseInt(this.computedCSS('padding-left'), 10) || 0;
983
- const paddingRight = parseInt(this.computedCSS('padding-right'), 10) || 0;
974
+ const paddingLeft = Number.parseInt(this.computedCSS('padding-left'), 10) || 0;
975
+ const paddingRight = Number.parseInt(this.computedCSS('padding-right'), 10) || 0;
984
976
  return this.width() - paddingLeft - paddingRight;
985
977
  }
986
978
  // Returns the height of of the first element.
@@ -2751,7 +2743,6 @@ var index = /*#__PURE__*/Object.freeze({
2751
2743
  denormalizeValue: denormalizeValue,
2752
2744
  encode: encode,
2753
2745
  fixNumberedList: fixNumberedList,
2754
- forEach: forEach,
2755
2746
  getCSS: getCSS,
2756
2747
  getDeepest: getDeepest,
2757
2748
  inString: inString,
@@ -2908,9 +2899,9 @@ class Box {
2908
2899
  value[valueKey] = valueValue;
2909
2900
  }
2910
2901
  else {
2911
- forEach(valueKey, (key, val) => {
2912
- value[key] = val;
2913
- });
2902
+ for (const key of Object.keys(valueKey)) {
2903
+ value[key] = valueKey[key];
2904
+ }
2914
2905
  }
2915
2906
  this.value = value;
2916
2907
  }
@@ -2966,6 +2957,7 @@ class Box {
2966
2957
  boxData[this.node.id] = {};
2967
2958
  effectData[this.node.id].setup = [];
2968
2959
  effectData[this.node.id].cleanup = [];
2960
+ this.event.removeAllListeners();
2969
2961
  this.node.empty();
2970
2962
  debug(`Box '${this.name}' (id = ${this.node.id}) unmounted`);
2971
2963
  }
@@ -3141,11 +3133,13 @@ class HTMLParser {
3141
3133
  if (attr.name === 'style') {
3142
3134
  const styleRules = attributeRules.style;
3143
3135
  const styleMap = new Map();
3144
- forEach(parseStyle(attr.value), (key, value) => {
3136
+ const styleData = parseStyle(attr.value);
3137
+ for (const key of Object.keys(styleData)) {
3138
+ const value = styleData[key];
3145
3139
  if (styleRules[key] && HTMLParser.matchRule(styleRules[key], value)) {
3146
3140
  styleMap.set(key, value);
3147
3141
  }
3148
- });
3142
+ }
3149
3143
  attributeMap.set('style', styleMap);
3150
3144
  }
3151
3145
  }
@@ -4386,8 +4380,9 @@ class Dropdown {
4386
4380
  this.config = config;
4387
4381
  this.root = config.root;
4388
4382
  this.locale = config.locale || i18nObject('en-US');
4383
+ const placement = config.placement || 'bottom';
4389
4384
  this.node = query(safeTemplate `
4390
- <div class="lake-dropdown lake-${config.menuType}-dropdown" name="${config.name}">
4385
+ <div class="lake-dropdown lake-${config.menuType}-dropdown" name="${config.name}" placement="${placement}">
4391
4386
  <button type="button" name="${config.name}" class="lake-dropdown-title">
4392
4387
  <div class="lake-dropdown-${config.icon ? 'icon' : 'text'}"></div>
4393
4388
  <div class="lake-dropdown-down-icon"></div>
@@ -4487,7 +4482,11 @@ class Dropdown {
4487
4482
  menuNode.show(config.menuType === 'color' ? 'flex' : 'block');
4488
4483
  const dropdownNativeNode = dropdownNode.get(0);
4489
4484
  const dropdownRect = dropdownNativeNode.getBoundingClientRect();
4490
- if (dropdownRect.x + menuNode.width() + 50 > window.innerWidth) {
4485
+ // A overflow width on the left side, greater than 0 indicates an overflow.
4486
+ const leftOverflow = menuNode.width() - (dropdownRect.x + dropdownRect.width);
4487
+ // A overflow width on the right side, greater than 0 indicates an overflow.
4488
+ const rightOverflow = dropdownRect.x + menuNode.width() - window.innerWidth;
4489
+ if (rightOverflow + 50 > 0 && (leftOverflow < 0 || leftOverflow < rightOverflow)) {
4491
4490
  menuNode.css('left', 'auto');
4492
4491
  menuNode.css('right', '0');
4493
4492
  }
@@ -4614,7 +4613,7 @@ class Dropdown {
4614
4613
  }
4615
4614
  }
4616
4615
 
4617
- var version = "0.1.5";
4616
+ var version = "0.1.7";
4618
4617
 
4619
4618
  // Inserts a box into the specified range.
4620
4619
  function insertBox(range, boxName, boxValue) {
@@ -5215,6 +5214,7 @@ const defaultConfig = {
5215
5214
  readonly: false,
5216
5215
  spellcheck: false,
5217
5216
  tabIndex: 0,
5217
+ placeholder: '',
5218
5218
  indentWithTab: true,
5219
5219
  lang: 'en-US',
5220
5220
  minChangeSize: 5,
@@ -5344,6 +5344,7 @@ class Editor {
5344
5344
  this.emitChangeEvent = (value) => {
5345
5345
  this.rectifyContent();
5346
5346
  this.emitStateChangeEvent();
5347
+ this.togglePlaceholderClass(value);
5347
5348
  this.event.emit('change', value);
5348
5349
  };
5349
5350
  if (!config.root) {
@@ -5366,12 +5367,25 @@ class Editor {
5366
5367
  spellcheck: this.config.spellcheck ? 'true' : 'false',
5367
5368
  tabindex: this.config.tabIndex.toString(),
5368
5369
  });
5370
+ if (this.config.placeholder !== '') {
5371
+ this.container.attr('placeholder', this.config.placeholder);
5372
+ }
5369
5373
  this.selection = new Selection(this.container);
5370
5374
  this.command = new Command(this.selection);
5371
5375
  this.history = new History(this.selection);
5372
5376
  this.keystroke = new Keystroke(this.container);
5373
5377
  editors.set(this.container.id, this);
5374
5378
  }
5379
+ togglePlaceholderClass(value) {
5380
+ value = denormalizeValue(value);
5381
+ const className = 'lake-show-placeholder';
5382
+ if (value.replace('<focus />', '') === '<p><br /></p>') {
5383
+ this.container.addClass(className);
5384
+ }
5385
+ else {
5386
+ this.container.removeClass(className);
5387
+ }
5388
+ }
5375
5389
  inputInBoxStrip() {
5376
5390
  const selection = this.selection;
5377
5391
  const range = selection.range;
@@ -5552,6 +5566,7 @@ class Editor {
5552
5566
  const htmlParser = new HTMLParser(value);
5553
5567
  const fragment = htmlParser.getFragment();
5554
5568
  this.container.empty();
5569
+ this.togglePlaceholderClass(htmlParser.getHTML());
5555
5570
  this.container.append(fragment);
5556
5571
  Editor.box.renderAll(this);
5557
5572
  this.selection.synByBookmark();
@@ -5593,6 +5608,7 @@ class Editor {
5593
5608
  this.containerWrapper.append(this.container);
5594
5609
  this.containerWrapper.append(this.overlayContainer);
5595
5610
  query(document.body).append(this.popupContainer);
5611
+ this.togglePlaceholderClass(htmlParser.getHTML());
5596
5612
  this.container.append(fragment);
5597
5613
  Editor.plugin.loadAll(this);
5598
5614
  if (!this.readonly) {
@@ -5614,6 +5630,9 @@ class Editor {
5614
5630
  }
5615
5631
  // Destroys a rendered editor.
5616
5632
  unmount() {
5633
+ this.event.removeAllListeners();
5634
+ this.command.event.removeAllListeners();
5635
+ this.history.event.removeAllListeners();
5617
5636
  this.root.empty();
5618
5637
  this.popupContainer.remove();
5619
5638
  if (!this.readonly) {
@@ -6331,11 +6350,15 @@ toolbarItems.forEach(item => {
6331
6350
  });
6332
6351
  class Toolbar {
6333
6352
  constructor(config) {
6353
+ this.placement = 'top';
6334
6354
  this.allMenuMap = new Map();
6335
6355
  this.buttonItemList = [];
6336
6356
  this.dropdownItemList = [];
6337
- this.items = config.items || defaultItems;
6338
6357
  this.root = query(config.root);
6358
+ this.items = config.items || defaultItems;
6359
+ if (config.placement) {
6360
+ this.placement = config.placement;
6361
+ }
6339
6362
  this.container = query('<div class="lake-toolbar" />');
6340
6363
  this.root.addClass('lake-custom-properties');
6341
6364
  }
@@ -6370,6 +6393,7 @@ class Toolbar {
6370
6393
  menuType: item.menuType,
6371
6394
  menuItems: item.menuItems,
6372
6395
  tabIndex: -1,
6396
+ placement: this.placement === 'top' ? 'bottom' : 'top',
6373
6397
  onSelect: value => {
6374
6398
  editor.focus();
6375
6399
  item.onSelect(editor, value);
@@ -7091,6 +7115,7 @@ const codeBlockBox = {
7091
7115
  }
7092
7116
  const codeBlockNode = query('<div class="lake-code-block" />');
7093
7117
  const container = box.getContainer();
7118
+ container.css('width', `${editor.container.innerWidth() - 2}px`);
7094
7119
  container.empty();
7095
7120
  container.append(codeBlockNode);
7096
7121
  const codeBlockNativeNode = codeBlockNode.get(0);
@@ -7181,8 +7206,13 @@ const codeBlockBox = {
7181
7206
  });
7182
7207
  dropdown.render();
7183
7208
  box.setData('codeEditor', codeEditor);
7209
+ const resizeListener = () => {
7210
+ container.css('width', `${editor.container.innerWidth() - 2}px`);
7211
+ };
7212
+ editor.event.on('resize', resizeListener);
7184
7213
  box.useEffect(() => () => {
7185
7214
  codeEditor.destroy();
7215
+ editor.event.off('resize', resizeListener);
7186
7216
  debug('CodeMirror destroyed');
7187
7217
  });
7188
7218
  },
@@ -7248,10 +7278,11 @@ const blockSelector = Array.from(blockTagNames).join(',');
7248
7278
  function getPasteElementRules() {
7249
7279
  const rules = getElementRules();
7250
7280
  rules.div = rules.p;
7251
- forEach(rules, (key, attributeRules) => {
7281
+ for (const key of Object.keys(rules)) {
7282
+ const attributeRules = rules[key];
7252
7283
  delete attributeRules.id;
7253
7284
  delete attributeRules.class;
7254
- });
7285
+ }
7255
7286
  return rules;
7256
7287
  }
7257
7288
  function fixNestedBlocks(block) {
@@ -7989,7 +8020,7 @@ var formatPainter = (editor) => {
7989
8020
  class LinkPopup {
7990
8021
  constructor(config) {
7991
8022
  this.linkNode = null;
7992
- this.event = new EventEmitter();
8023
+ this.config = config;
7993
8024
  this.root = config.root;
7994
8025
  this.locale = config.locale || i18nObject('en-US');
7995
8026
  this.container = query(safeTemplate `
@@ -8028,6 +8059,7 @@ class LinkPopup {
8028
8059
  }
8029
8060
  // Copy link to clipboard
8030
8061
  appendCopyButton() {
8062
+ const config = this.config;
8031
8063
  let timeoutId = null;
8032
8064
  const button = new Button({
8033
8065
  root: this.container.find('.lake-url-row'),
@@ -8044,11 +8076,15 @@ class LinkPopup {
8044
8076
  svgNode.hide();
8045
8077
  if (error) {
8046
8078
  svgNode.eq(2).show('inline');
8047
- this.event.emit('copy', error);
8079
+ if (config.onCopy) {
8080
+ config.onCopy(error);
8081
+ }
8048
8082
  return;
8049
8083
  }
8050
8084
  svgNode.eq(1).show('inline');
8051
- this.event.emit('copy', error);
8085
+ if (config.onCopy) {
8086
+ config.onCopy(error);
8087
+ }
8052
8088
  if (timeoutId) {
8053
8089
  window.clearTimeout(timeoutId);
8054
8090
  }
@@ -8100,7 +8136,9 @@ class LinkPopup {
8100
8136
  const linkNode = this.linkNode;
8101
8137
  this.save();
8102
8138
  this.hide();
8103
- this.event.emit('save', linkNode);
8139
+ if (this.config.onSave) {
8140
+ this.config.onSave(linkNode);
8141
+ }
8104
8142
  },
8105
8143
  });
8106
8144
  button.render();
@@ -8119,7 +8157,9 @@ class LinkPopup {
8119
8157
  const lastChild = this.linkNode.last();
8120
8158
  this.linkNode.remove(true);
8121
8159
  this.hide();
8122
- this.event.emit('remove', lastChild);
8160
+ if (this.config.onRemove) {
8161
+ this.config.onRemove(lastChild);
8162
+ }
8123
8163
  },
8124
8164
  });
8125
8165
  button.render();
@@ -8220,20 +8260,20 @@ var link = (editor) => {
8220
8260
  const popup = new LinkPopup({
8221
8261
  root: editor.popupContainer,
8222
8262
  locale: editor.locale,
8223
- });
8224
- popup.event.on('save', node => {
8225
- const range = editor.selection.range;
8226
- range.setStartAfter(node);
8227
- range.collapseToStart();
8228
- editor.selection.addRangeToNativeSelection();
8229
- editor.history.save();
8230
- });
8231
- popup.event.on('remove', node => {
8232
- const range = editor.selection.range;
8233
- range.setStartAfter(node);
8234
- range.collapseToStart();
8235
- editor.selection.addRangeToNativeSelection();
8236
- editor.history.save();
8263
+ onSave: node => {
8264
+ const range = editor.selection.range;
8265
+ range.setStartAfter(node);
8266
+ range.collapseToStart();
8267
+ editor.selection.addRangeToNativeSelection();
8268
+ editor.history.save();
8269
+ },
8270
+ onRemove: node => {
8271
+ const range = editor.selection.range;
8272
+ range.setStartAfter(node);
8273
+ range.collapseToStart();
8274
+ editor.selection.addRangeToNativeSelection();
8275
+ editor.history.save();
8276
+ },
8237
8277
  });
8238
8278
  editor.root.on('scroll', () => {
8239
8279
  popup.updatePosition();
@@ -8495,7 +8535,7 @@ const blockItemListForEnterKey = [
8495
8535
  ],
8496
8536
  },
8497
8537
  {
8498
- re: /^`+([a-z]*)$/i,
8538
+ re: /^`{3,}([a-z]*)$/i,
8499
8539
  getParameters: (results) => {
8500
8540
  var _a;
8501
8541
  if (!results[1]) {