lakelib 0.1.5 → 0.1.6

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
  }
@@ -851,9 +860,6 @@ lake-box[name="image"] .lake-box-selected .lake-image-error {
851
860
  lake-box[name="codeBlock"] {
852
861
  margin: 16px 0;
853
862
  }
854
- lake-box[name="codeBlock"] .lake-box-container {
855
- overflow-x: auto;
856
- }
857
863
  lake-box[name="codeBlock"] .lake-box-focused .lake-code-block,
858
864
  lake-box[name="codeBlock"] .lake-box-activated .lake-code-block {
859
865
  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) {
@@ -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
  }
@@ -4614,7 +4608,7 @@ class Dropdown {
4614
4608
  }
4615
4609
  }
4616
4610
 
4617
- var version = "0.1.5";
4611
+ var version = "0.1.6";
4618
4612
 
4619
4613
  // Inserts a box into the specified range.
4620
4614
  function insertBox(range, boxName, boxValue) {
@@ -5215,6 +5209,7 @@ const defaultConfig = {
5215
5209
  readonly: false,
5216
5210
  spellcheck: false,
5217
5211
  tabIndex: 0,
5212
+ placeholder: '',
5218
5213
  indentWithTab: true,
5219
5214
  lang: 'en-US',
5220
5215
  minChangeSize: 5,
@@ -5344,6 +5339,7 @@ class Editor {
5344
5339
  this.emitChangeEvent = (value) => {
5345
5340
  this.rectifyContent();
5346
5341
  this.emitStateChangeEvent();
5342
+ this.togglePlaceholderClass(value);
5347
5343
  this.event.emit('change', value);
5348
5344
  };
5349
5345
  if (!config.root) {
@@ -5366,12 +5362,25 @@ class Editor {
5366
5362
  spellcheck: this.config.spellcheck ? 'true' : 'false',
5367
5363
  tabindex: this.config.tabIndex.toString(),
5368
5364
  });
5365
+ if (this.config.placeholder !== '') {
5366
+ this.container.attr('placeholder', this.config.placeholder);
5367
+ }
5369
5368
  this.selection = new Selection(this.container);
5370
5369
  this.command = new Command(this.selection);
5371
5370
  this.history = new History(this.selection);
5372
5371
  this.keystroke = new Keystroke(this.container);
5373
5372
  editors.set(this.container.id, this);
5374
5373
  }
5374
+ togglePlaceholderClass(value) {
5375
+ value = denormalizeValue(value);
5376
+ const className = 'lake-show-placeholder';
5377
+ if (value.replace('<focus />', '') === '<p><br /></p>') {
5378
+ this.container.addClass(className);
5379
+ }
5380
+ else {
5381
+ this.container.removeClass(className);
5382
+ }
5383
+ }
5375
5384
  inputInBoxStrip() {
5376
5385
  const selection = this.selection;
5377
5386
  const range = selection.range;
@@ -5552,6 +5561,7 @@ class Editor {
5552
5561
  const htmlParser = new HTMLParser(value);
5553
5562
  const fragment = htmlParser.getFragment();
5554
5563
  this.container.empty();
5564
+ this.togglePlaceholderClass(htmlParser.getHTML());
5555
5565
  this.container.append(fragment);
5556
5566
  Editor.box.renderAll(this);
5557
5567
  this.selection.synByBookmark();
@@ -5593,6 +5603,7 @@ class Editor {
5593
5603
  this.containerWrapper.append(this.container);
5594
5604
  this.containerWrapper.append(this.overlayContainer);
5595
5605
  query(document.body).append(this.popupContainer);
5606
+ this.togglePlaceholderClass(htmlParser.getHTML());
5596
5607
  this.container.append(fragment);
5597
5608
  Editor.plugin.loadAll(this);
5598
5609
  if (!this.readonly) {
@@ -5614,6 +5625,9 @@ class Editor {
5614
5625
  }
5615
5626
  // Destroys a rendered editor.
5616
5627
  unmount() {
5628
+ this.event.removeAllListeners();
5629
+ this.command.event.removeAllListeners();
5630
+ this.history.event.removeAllListeners();
5617
5631
  this.root.empty();
5618
5632
  this.popupContainer.remove();
5619
5633
  if (!this.readonly) {
@@ -7091,6 +7105,7 @@ const codeBlockBox = {
7091
7105
  }
7092
7106
  const codeBlockNode = query('<div class="lake-code-block" />');
7093
7107
  const container = box.getContainer();
7108
+ container.css('width', `${editor.container.innerWidth() - 2}px`);
7094
7109
  container.empty();
7095
7110
  container.append(codeBlockNode);
7096
7111
  const codeBlockNativeNode = codeBlockNode.get(0);
@@ -7181,8 +7196,13 @@ const codeBlockBox = {
7181
7196
  });
7182
7197
  dropdown.render();
7183
7198
  box.setData('codeEditor', codeEditor);
7199
+ const resizeListener = () => {
7200
+ container.css('width', `${editor.container.innerWidth() - 2}px`);
7201
+ };
7202
+ editor.event.on('resize', resizeListener);
7184
7203
  box.useEffect(() => () => {
7185
7204
  codeEditor.destroy();
7205
+ editor.event.off('resize', resizeListener);
7186
7206
  debug('CodeMirror destroyed');
7187
7207
  });
7188
7208
  },
@@ -7248,10 +7268,11 @@ const blockSelector = Array.from(blockTagNames).join(',');
7248
7268
  function getPasteElementRules() {
7249
7269
  const rules = getElementRules();
7250
7270
  rules.div = rules.p;
7251
- forEach(rules, (key, attributeRules) => {
7271
+ for (const key of Object.keys(rules)) {
7272
+ const attributeRules = rules[key];
7252
7273
  delete attributeRules.id;
7253
7274
  delete attributeRules.class;
7254
- });
7275
+ }
7255
7276
  return rules;
7256
7277
  }
7257
7278
  function fixNestedBlocks(block) {
@@ -7989,7 +8010,7 @@ var formatPainter = (editor) => {
7989
8010
  class LinkPopup {
7990
8011
  constructor(config) {
7991
8012
  this.linkNode = null;
7992
- this.event = new EventEmitter();
8013
+ this.config = config;
7993
8014
  this.root = config.root;
7994
8015
  this.locale = config.locale || i18nObject('en-US');
7995
8016
  this.container = query(safeTemplate `
@@ -8028,6 +8049,7 @@ class LinkPopup {
8028
8049
  }
8029
8050
  // Copy link to clipboard
8030
8051
  appendCopyButton() {
8052
+ const config = this.config;
8031
8053
  let timeoutId = null;
8032
8054
  const button = new Button({
8033
8055
  root: this.container.find('.lake-url-row'),
@@ -8044,11 +8066,15 @@ class LinkPopup {
8044
8066
  svgNode.hide();
8045
8067
  if (error) {
8046
8068
  svgNode.eq(2).show('inline');
8047
- this.event.emit('copy', error);
8069
+ if (config.onCopy) {
8070
+ config.onCopy(error);
8071
+ }
8048
8072
  return;
8049
8073
  }
8050
8074
  svgNode.eq(1).show('inline');
8051
- this.event.emit('copy', error);
8075
+ if (config.onCopy) {
8076
+ config.onCopy(error);
8077
+ }
8052
8078
  if (timeoutId) {
8053
8079
  window.clearTimeout(timeoutId);
8054
8080
  }
@@ -8100,7 +8126,9 @@ class LinkPopup {
8100
8126
  const linkNode = this.linkNode;
8101
8127
  this.save();
8102
8128
  this.hide();
8103
- this.event.emit('save', linkNode);
8129
+ if (this.config.onSave) {
8130
+ this.config.onSave(linkNode);
8131
+ }
8104
8132
  },
8105
8133
  });
8106
8134
  button.render();
@@ -8119,7 +8147,9 @@ class LinkPopup {
8119
8147
  const lastChild = this.linkNode.last();
8120
8148
  this.linkNode.remove(true);
8121
8149
  this.hide();
8122
- this.event.emit('remove', lastChild);
8150
+ if (this.config.onRemove) {
8151
+ this.config.onRemove(lastChild);
8152
+ }
8123
8153
  },
8124
8154
  });
8125
8155
  button.render();
@@ -8220,20 +8250,20 @@ var link = (editor) => {
8220
8250
  const popup = new LinkPopup({
8221
8251
  root: editor.popupContainer,
8222
8252
  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();
8253
+ onSave: node => {
8254
+ const range = editor.selection.range;
8255
+ range.setStartAfter(node);
8256
+ range.collapseToStart();
8257
+ editor.selection.addRangeToNativeSelection();
8258
+ editor.history.save();
8259
+ },
8260
+ onRemove: node => {
8261
+ const range = editor.selection.range;
8262
+ range.setStartAfter(node);
8263
+ range.collapseToStart();
8264
+ editor.selection.addRangeToNativeSelection();
8265
+ editor.history.save();
8266
+ },
8237
8267
  });
8238
8268
  editor.root.on('scroll', () => {
8239
8269
  popup.updatePosition();