lakelib 0.1.4 → 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
  }
@@ -3441,7 +3435,8 @@ function deleteContents(range) {
3441
3435
  if (range.isCollapsed) {
3442
3436
  return;
3443
3437
  }
3444
- range.adapt();
3438
+ range.adaptBox();
3439
+ range.adaptTable();
3445
3440
  if (range.isInoperative) {
3446
3441
  return;
3447
3442
  }
@@ -4613,7 +4608,7 @@ class Dropdown {
4613
4608
  }
4614
4609
  }
4615
4610
 
4616
- var version = "0.1.4";
4611
+ var version = "0.1.6";
4617
4612
 
4618
4613
  // Inserts a box into the specified range.
4619
4614
  function insertBox(range, boxName, boxValue) {
@@ -5210,10 +5205,11 @@ class Plugin {
5210
5205
  }
5211
5206
 
5212
5207
  const defaultConfig = {
5213
- value: '<p><br /><focus /></p>',
5208
+ value: '<p><br /></p>',
5214
5209
  readonly: false,
5215
5210
  spellcheck: false,
5216
5211
  tabIndex: 0,
5212
+ placeholder: '',
5217
5213
  indentWithTab: true,
5218
5214
  lang: 'en-US',
5219
5215
  minChangeSize: 5,
@@ -5221,7 +5217,7 @@ const defaultConfig = {
5221
5217
  class Editor {
5222
5218
  constructor(config) {
5223
5219
  this.unsavedInputData = '';
5224
- this.stateData = {
5220
+ this.state = {
5225
5221
  appliedItems: [],
5226
5222
  disabledNameMap: new Map(),
5227
5223
  selectedNameMap: new Map(),
@@ -5321,20 +5317,20 @@ class Editor {
5321
5317
  }
5322
5318
  }
5323
5319
  }
5324
- const stateData = {
5320
+ const state = {
5325
5321
  appliedItems,
5326
5322
  disabledNameMap,
5327
5323
  selectedNameMap,
5328
5324
  selectedValuesMap,
5329
5325
  };
5330
- if (isEqual(stateData, this.stateData)) {
5326
+ if (isEqual(state, this.state)) {
5331
5327
  return;
5332
5328
  }
5333
5329
  if (this.toolbar) {
5334
- this.toolbar.updateState(stateData);
5330
+ this.toolbar.updateState(state);
5335
5331
  }
5336
- this.event.emit('statechange', stateData);
5337
- this.stateData = stateData;
5332
+ this.event.emit('statechange', state);
5333
+ this.state = state;
5338
5334
  }, 100, {
5339
5335
  leading: false,
5340
5336
  trailing: true,
@@ -5343,6 +5339,7 @@ class Editor {
5343
5339
  this.emitChangeEvent = (value) => {
5344
5340
  this.rectifyContent();
5345
5341
  this.emitStateChangeEvent();
5342
+ this.togglePlaceholderClass(value);
5346
5343
  this.event.emit('change', value);
5347
5344
  };
5348
5345
  if (!config.root) {
@@ -5365,12 +5362,25 @@ class Editor {
5365
5362
  spellcheck: this.config.spellcheck ? 'true' : 'false',
5366
5363
  tabindex: this.config.tabIndex.toString(),
5367
5364
  });
5365
+ if (this.config.placeholder !== '') {
5366
+ this.container.attr('placeholder', this.config.placeholder);
5367
+ }
5368
5368
  this.selection = new Selection(this.container);
5369
5369
  this.command = new Command(this.selection);
5370
5370
  this.history = new History(this.selection);
5371
5371
  this.keystroke = new Keystroke(this.container);
5372
5372
  editors.set(this.container.id, this);
5373
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
+ }
5374
5384
  inputInBoxStrip() {
5375
5385
  const selection = this.selection;
5376
5386
  const range = selection.range;
@@ -5551,6 +5561,7 @@ class Editor {
5551
5561
  const htmlParser = new HTMLParser(value);
5552
5562
  const fragment = htmlParser.getFragment();
5553
5563
  this.container.empty();
5564
+ this.togglePlaceholderClass(htmlParser.getHTML());
5554
5565
  this.container.append(fragment);
5555
5566
  Editor.box.renderAll(this);
5556
5567
  this.selection.synByBookmark();
@@ -5592,6 +5603,7 @@ class Editor {
5592
5603
  this.containerWrapper.append(this.container);
5593
5604
  this.containerWrapper.append(this.overlayContainer);
5594
5605
  query(document.body).append(this.popupContainer);
5606
+ this.togglePlaceholderClass(htmlParser.getHTML());
5595
5607
  this.container.append(fragment);
5596
5608
  Editor.plugin.loadAll(this);
5597
5609
  if (!this.readonly) {
@@ -5613,6 +5625,9 @@ class Editor {
5613
5625
  }
5614
5626
  // Destroys a rendered editor.
5615
5627
  unmount() {
5628
+ this.event.removeAllListeners();
5629
+ this.command.event.removeAllListeners();
5630
+ this.history.event.removeAllListeners();
5616
5631
  this.root.empty();
5617
5632
  this.popupContainer.remove();
5618
5633
  if (!this.readonly) {
@@ -6416,9 +6431,9 @@ class Toolbar {
6416
6431
  });
6417
6432
  }
6418
6433
  // Updates state of each item such as disabled, selected.
6419
- updateState(stateData) {
6434
+ updateState(state) {
6420
6435
  var _a;
6421
- const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = stateData;
6436
+ const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = state;
6422
6437
  for (const item of this.buttonItemList) {
6423
6438
  const selectedClass = 'lake-button-selected';
6424
6439
  const buttonNode = this.container.find(`button[name="${item.name}"]`);
@@ -7090,6 +7105,7 @@ const codeBlockBox = {
7090
7105
  }
7091
7106
  const codeBlockNode = query('<div class="lake-code-block" />');
7092
7107
  const container = box.getContainer();
7108
+ container.css('width', `${editor.container.innerWidth() - 2}px`);
7093
7109
  container.empty();
7094
7110
  container.append(codeBlockNode);
7095
7111
  const codeBlockNativeNode = codeBlockNode.get(0);
@@ -7180,8 +7196,13 @@ const codeBlockBox = {
7180
7196
  });
7181
7197
  dropdown.render();
7182
7198
  box.setData('codeEditor', codeEditor);
7199
+ const resizeListener = () => {
7200
+ container.css('width', `${editor.container.innerWidth() - 2}px`);
7201
+ };
7202
+ editor.event.on('resize', resizeListener);
7183
7203
  box.useEffect(() => () => {
7184
7204
  codeEditor.destroy();
7205
+ editor.event.off('resize', resizeListener);
7185
7206
  debug('CodeMirror destroyed');
7186
7207
  });
7187
7208
  },
@@ -7247,10 +7268,11 @@ const blockSelector = Array.from(blockTagNames).join(',');
7247
7268
  function getPasteElementRules() {
7248
7269
  const rules = getElementRules();
7249
7270
  rules.div = rules.p;
7250
- forEach(rules, (key, attributeRules) => {
7271
+ for (const key of Object.keys(rules)) {
7272
+ const attributeRules = rules[key];
7251
7273
  delete attributeRules.id;
7252
7274
  delete attributeRules.class;
7253
- });
7275
+ }
7254
7276
  return rules;
7255
7277
  }
7256
7278
  function fixNestedBlocks(block) {
@@ -7988,7 +8010,7 @@ var formatPainter = (editor) => {
7988
8010
  class LinkPopup {
7989
8011
  constructor(config) {
7990
8012
  this.linkNode = null;
7991
- this.event = new EventEmitter();
8013
+ this.config = config;
7992
8014
  this.root = config.root;
7993
8015
  this.locale = config.locale || i18nObject('en-US');
7994
8016
  this.container = query(safeTemplate `
@@ -8027,6 +8049,7 @@ class LinkPopup {
8027
8049
  }
8028
8050
  // Copy link to clipboard
8029
8051
  appendCopyButton() {
8052
+ const config = this.config;
8030
8053
  let timeoutId = null;
8031
8054
  const button = new Button({
8032
8055
  root: this.container.find('.lake-url-row'),
@@ -8043,11 +8066,15 @@ class LinkPopup {
8043
8066
  svgNode.hide();
8044
8067
  if (error) {
8045
8068
  svgNode.eq(2).show('inline');
8046
- this.event.emit('copy', error);
8069
+ if (config.onCopy) {
8070
+ config.onCopy(error);
8071
+ }
8047
8072
  return;
8048
8073
  }
8049
8074
  svgNode.eq(1).show('inline');
8050
- this.event.emit('copy', error);
8075
+ if (config.onCopy) {
8076
+ config.onCopy(error);
8077
+ }
8051
8078
  if (timeoutId) {
8052
8079
  window.clearTimeout(timeoutId);
8053
8080
  }
@@ -8099,7 +8126,9 @@ class LinkPopup {
8099
8126
  const linkNode = this.linkNode;
8100
8127
  this.save();
8101
8128
  this.hide();
8102
- this.event.emit('save', linkNode);
8129
+ if (this.config.onSave) {
8130
+ this.config.onSave(linkNode);
8131
+ }
8103
8132
  },
8104
8133
  });
8105
8134
  button.render();
@@ -8118,7 +8147,9 @@ class LinkPopup {
8118
8147
  const lastChild = this.linkNode.last();
8119
8148
  this.linkNode.remove(true);
8120
8149
  this.hide();
8121
- this.event.emit('remove', lastChild);
8150
+ if (this.config.onRemove) {
8151
+ this.config.onRemove(lastChild);
8152
+ }
8122
8153
  },
8123
8154
  });
8124
8155
  button.render();
@@ -8219,20 +8250,20 @@ var link = (editor) => {
8219
8250
  const popup = new LinkPopup({
8220
8251
  root: editor.popupContainer,
8221
8252
  locale: editor.locale,
8222
- });
8223
- popup.event.on('save', node => {
8224
- const range = editor.selection.range;
8225
- range.setStartAfter(node);
8226
- range.collapseToStart();
8227
- editor.selection.addRangeToNativeSelection();
8228
- editor.history.save();
8229
- });
8230
- popup.event.on('remove', node => {
8231
- const range = editor.selection.range;
8232
- range.setStartAfter(node);
8233
- range.collapseToStart();
8234
- editor.selection.addRangeToNativeSelection();
8235
- 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
+ },
8236
8267
  });
8237
8268
  editor.root.on('scroll', () => {
8238
8269
  popup.updatePosition();