lakelib 0.0.5 → 0.0.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
@@ -35,7 +35,10 @@
35
35
  .lake-container {
36
36
  font-family: var(--font-family);
37
37
  font-size: 16px;
38
+ font-weight: normal;
39
+ line-height: normal;
38
40
  color: var(--text-color);
41
+ background-color: #fff;
39
42
  padding: 16px 24px;
40
43
  }
41
44
  .lake-container:focus {
@@ -91,10 +94,11 @@
91
94
  background-color: #0000000a;
92
95
  }
93
96
 
94
- .lake-button {
97
+ button.lake-button {
98
+ box-sizing: content-box;
95
99
  border-radius: 5px;
96
100
  border: 0;
97
- font-family: var(--font-family);
101
+ font-family: Arial;
98
102
  font-size: 14px;
99
103
  color: var(--text-color);
100
104
  background-color: #fff;
@@ -104,41 +108,42 @@
104
108
  cursor: pointer;
105
109
  user-select: none;
106
110
  }
107
- .lake-button:focus-visible {
111
+ button.lake-button:focus-visible {
108
112
  outline: var(--button-outline);
109
113
  }
110
- .lake-button[disabled] {
114
+ button.lake-button[disabled] {
111
115
  opacity: 0.25;
112
116
  cursor: default;
113
117
  }
114
- .lake-button svg {
118
+ button.lake-button svg {
119
+ display: inline-block;
115
120
  width: 16px;
116
121
  height: 16px;
117
122
  margin: 6px;
118
123
  }
119
- .lake-icon-button.lake-button-hovered {
124
+ button.lake-icon-button.lake-button-hovered {
120
125
  background-color: var(--background-hover-color);
121
126
  }
122
- .lake-icon-button.lake-button-selected {
127
+ button.lake-icon-button.lake-button-selected {
123
128
  background-color: var(--background-active-color);
124
129
  }
125
- .lake-text-button {
130
+ button.lake-text-button {
126
131
  background-color: transparent;
127
132
  border: 1px solid var(--border-color);
128
133
  padding: 8px 16px;
129
134
  }
130
- .lake-text-button.lake-button-hovered {
135
+ button.lake-text-button.lake-button-hovered {
131
136
  background-color: var(--background-hover-color);
132
137
  }
133
- .lake-text-button.lake-button-selected {
138
+ button.lake-text-button.lake-button-selected {
134
139
  background-color: var(--background-active-color);
135
140
  }
136
- .lake-text-button svg {
141
+ button.lake-text-button svg {
137
142
  background-color: transparent;
138
143
  margin: 0 6px 0 0;
139
144
  vertical-align: middle;
140
145
  }
141
- .lake-text-button span {
146
+ button.lake-text-button span {
142
147
  display: inline-block;
143
148
  line-height: 16px;
144
149
  vertical-align: middle;
@@ -151,30 +156,34 @@
151
156
  font-size: 14px;
152
157
  user-select: none;
153
158
  }
154
- .lake-dropdown .lake-dropdown-title {
155
- display: flex;
156
- align-items: center;
157
- justify-content: space-between;
158
- padding: 0;
159
- margin-right: 4px;
159
+ .lake-dropdown button.lake-dropdown-title {
160
+ box-sizing: content-box;
160
161
  border-radius: 5px;
161
162
  border: 0;
163
+ font-family: Arial;
162
164
  font-size: 14px;
165
+ color: var(--text-color);
163
166
  background-color: #fff;
167
+ padding: 0;
168
+ display: flex;
169
+ align-items: center;
170
+ justify-content: space-between;
171
+ margin-right: 4px;
164
172
  cursor: pointer;
165
173
  }
166
- .lake-dropdown[disabled] .lake-dropdown-title {
174
+ .lake-dropdown[disabled] button.lake-dropdown-title {
167
175
  opacity: 0.25;
168
176
  cursor: default;
169
177
  }
170
- .lake-dropdown.lake-list-dropdown .lake-dropdown-title-hovered {
178
+ .lake-dropdown.lake-list-dropdown button.lake-dropdown-title-hovered {
171
179
  background-color: var(--background-hover-color);
172
180
  }
173
- .lake-dropdown .lake-dropdown-title.lake-dropdown-title-no-down {
181
+ .lake-dropdown button.lake-dropdown-title.lake-dropdown-title-no-down {
174
182
  margin-right: 0;
175
183
  }
176
184
  .lake-dropdown .lake-dropdown-text {
177
185
  height: 16px;
186
+ line-height: normal;
178
187
  margin: 6px;
179
188
  overflow: hidden;
180
189
  white-space: nowrap;
@@ -199,8 +208,8 @@
199
208
  left: 0;
200
209
  bottom: 0;
201
210
  }
202
- .lake-dropdown .lake-dropdown-title-no-down .lake-dropdown-icon svg,
203
- .lake-dropdown .lake-dropdown-title-no-down .lake-dropdown-icon img {
211
+ .lake-dropdown button.lake-dropdown-title-no-down .lake-dropdown-icon svg,
212
+ .lake-dropdown button.lake-dropdown-title-no-down .lake-dropdown-icon img {
204
213
  margin: 6px;
205
214
  }
206
215
  .lake-dropdown .lake-dropdown-down-icon {
@@ -217,6 +226,7 @@
217
226
  fill: var(--secondary-text-color);
218
227
  }
219
228
  .lake-dropdown .lake-dropdown-menu {
229
+ box-sizing: content-box;
220
230
  position: absolute;
221
231
  top: 30px;
222
232
  left: 0;
@@ -235,9 +245,9 @@
235
245
  display: flex;
236
246
  align-items: center;
237
247
  cursor: pointer;
248
+ margin: 0;
238
249
  }
239
250
  .lake-dropdown .lake-list-dropdown-menu li {
240
- margin: 0;
241
251
  padding: 6px 24px 6px 10px;
242
252
  }
243
253
  .lake-dropdown .lake-list-dropdown-menu li.lake-dropdown-item-hovered {
@@ -308,6 +318,7 @@
308
318
  }
309
319
  .lake-dropdown .lake-color-dropdown-menu li .lake-dropdown-menu-text {
310
320
  font-size: 0;
321
+ box-sizing: content-box;
311
322
  border: 1px solid var(--background-hover-color);
312
323
  border-radius: 2px;
313
324
  width: 16px;
@@ -330,11 +341,18 @@
330
341
  height: auto;
331
342
  }
332
343
 
344
+ .lake-popup {
345
+ font-family: var(--font-family);
346
+ font-size: 14px;
347
+ font-weight: normal;
348
+ line-height: normal;
349
+ color: var(--text-color);
350
+ }
333
351
  .lake-popup input[type="text"] {
352
+ box-sizing: content-box;
334
353
  font-family: var(--font-family);
335
354
  font-size: 14px;
336
355
  color: var(--text-color);
337
- width: 200px;
338
356
  border-radius: 5px;
339
357
  border: 1px solid var(--input-border-color);
340
358
  padding: 4px 10px;
@@ -544,6 +562,7 @@
544
562
  }
545
563
 
546
564
  .lake-container table {
565
+ box-sizing: content-box;
547
566
  border-collapse: collapse;
548
567
  border: 1px solid var(--border-color);
549
568
  margin-bottom: 8px;
@@ -917,6 +936,11 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block .lake-dropdown {
917
936
  }
918
937
 
919
938
  .lake-toolbar {
939
+ font-family: var(--font-family);
940
+ font-size: 14px;
941
+ font-weight: normal;
942
+ line-height: normal;
943
+ color: var(--text-color);
920
944
  background-color: #fff;
921
945
  padding: 4px;
922
946
  display: flex;
@@ -924,6 +948,7 @@ lake-box[name="codeBlock"] .lake-box-activated .lake-code-block .lake-dropdown {
924
948
  align-items: center;
925
949
  }
926
950
  .lake-toolbar .lake-toolbar-divider {
951
+ box-sizing: content-box;
927
952
  width: 1px;
928
953
  height: 20px;
929
954
  margin: 0 4px;
package/lib/lake.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Base64 } from 'js-base64';
2
2
  import EventEmitter from 'eventemitter3';
3
3
  import debounce from 'lodash/debounce';
4
+ import isEqual from 'lodash/isEqual';
4
5
  import md5 from 'blueimp-md5';
5
6
  import { createKeybindingsHandler } from 'tinykeys';
6
7
  import { i18nObject as i18nObject$1 } from 'typesafe-i18n';
@@ -1392,7 +1393,7 @@ class Range {
1392
1393
  throw new Error(`The box cannot be selected because the box '${boxNode.attr('name')}' (id=${boxNode.id}) has not been rendered yet.`);
1393
1394
  }
1394
1395
  this.selectNodeContents(boxStrip.eq(0));
1395
- this.collapseToEnd();
1396
+ this.collapseToStart();
1396
1397
  }
1397
1398
  // Sets the range to the start position of the box.
1398
1399
  selectBoxEnd(boxNode) {
@@ -1401,7 +1402,7 @@ class Range {
1401
1402
  throw new Error(`The box cannot be selected because the box '${boxNode.attr('name')}' (id=${boxNode.id}) has not been rendered yet.`);
1402
1403
  }
1403
1404
  this.selectNodeContents(boxStrip.eq(1));
1404
- this.collapseToEnd();
1405
+ this.collapseToStart();
1405
1406
  }
1406
1407
  // Collapses the range and sets the range to the beginning of the contents of the specified node.
1407
1408
  shrinkBefore(node) {
@@ -4294,7 +4295,7 @@ class Dropdown {
4294
4295
  }
4295
4296
  }
4296
4297
 
4297
- var version = "0.0.4";
4298
+ var version = "0.0.7";
4298
4299
 
4299
4300
  // Inserts a box into the specified range.
4300
4301
  function insertBox(range, boxName, boxValue) {
@@ -4742,7 +4743,7 @@ class History {
4742
4743
  pause() {
4743
4744
  this.canSave = false;
4744
4745
  }
4745
- save() {
4746
+ save(emitSaveEvent = true) {
4746
4747
  if (!this.canSave) {
4747
4748
  return;
4748
4749
  }
@@ -4758,7 +4759,9 @@ class History {
4758
4759
  this.list.shift();
4759
4760
  this.index = this.list.length;
4760
4761
  }
4761
- this.event.emit('save', value);
4762
+ if (emitSaveEvent) {
4763
+ this.event.emit('save', denormalizeValue(value));
4764
+ }
4762
4765
  debug(`History saved, the last index is ${this.index}`);
4763
4766
  }
4764
4767
  }
@@ -4902,11 +4905,17 @@ const defaultConfig = {
4902
4905
  class Editor {
4903
4906
  constructor(config) {
4904
4907
  this.unsavedInputData = '';
4908
+ this.stateData = {
4909
+ appliedItems: [],
4910
+ disabledNameMap: new Map(),
4911
+ selectedNameMap: new Map(),
4912
+ selectedValuesMap: new Map(),
4913
+ };
4905
4914
  this.isComposing = false;
4906
4915
  this.event = new EventEmitter();
4907
4916
  this.box = Editor.box;
4908
4917
  this.beforeunloadListener = () => {
4909
- this.commitUnsavedInputData();
4918
+ this.history.save();
4910
4919
  };
4911
4920
  this.selectionchangeListener = () => {
4912
4921
  this.selection.syncByRange();
@@ -5002,10 +5011,14 @@ class Editor {
5002
5011
  selectedNameMap,
5003
5012
  selectedValuesMap,
5004
5013
  };
5014
+ if (isEqual(stateData, this.stateData)) {
5015
+ return;
5016
+ }
5005
5017
  if (this.toolbar) {
5006
5018
  this.toolbar.updateState(stateData);
5007
5019
  }
5008
5020
  this.event.emit('statechange', stateData);
5021
+ this.stateData = stateData;
5009
5022
  }, 100, {
5010
5023
  leading: false,
5011
5024
  trailing: true,
@@ -5076,11 +5089,18 @@ class Editor {
5076
5089
  this.container.on('compositionend', () => {
5077
5090
  this.isComposing = false;
5078
5091
  });
5079
- this.container.on('beforeinput', () => {
5092
+ this.container.on('beforeinput', event => {
5093
+ const inputEvent = event;
5080
5094
  const range = this.selection.range;
5081
5095
  if (range.isBoxStart || range.isBoxEnd) {
5082
5096
  this.commitUnsavedInputData();
5097
+ return;
5083
5098
  }
5099
+ if (inputEvent.inputType === 'insertText' ||
5100
+ inputEvent.inputType === 'insertCompositionText') {
5101
+ return;
5102
+ }
5103
+ this.commitUnsavedInputData();
5084
5104
  });
5085
5105
  this.container.on('input', event => {
5086
5106
  const inputEvent = event;
@@ -5096,21 +5116,22 @@ class Editor {
5096
5116
  this.event.emit('input', inputEvent);
5097
5117
  return;
5098
5118
  }
5119
+ if (range.isBoxStart || range.isBoxEnd) {
5120
+ this.inputInBoxStrip();
5121
+ this.history.save();
5122
+ this.event.emit('input', inputEvent);
5123
+ return;
5124
+ }
5099
5125
  if (inputEvent.inputType === 'insertText' ||
5100
5126
  inputEvent.inputType === 'insertCompositionText') {
5101
- if (range.isBoxStart || range.isBoxEnd) {
5102
- this.inputInBoxStrip();
5103
- }
5104
- else {
5105
- this.unsavedInputData += (_a = inputEvent.data) !== null && _a !== void 0 ? _a : '';
5106
- if (this.unsavedInputData.length < this.config.minChangeSize) {
5107
- this.event.emit('input', inputEvent);
5108
- return;
5109
- }
5127
+ this.unsavedInputData += (_a = inputEvent.data) !== null && _a !== void 0 ? _a : '';
5128
+ if (this.unsavedInputData.length < this.config.minChangeSize) {
5129
+ this.event.emit('input', inputEvent);
5130
+ this.emitChangeEvent(this.getValue());
5131
+ return;
5110
5132
  }
5111
5133
  }
5112
5134
  this.history.save();
5113
- this.unsavedInputData = '';
5114
5135
  this.event.emit('input', inputEvent);
5115
5136
  }, 0);
5116
5137
  });
@@ -5168,7 +5189,7 @@ class Editor {
5168
5189
  // Saves the input data which is unsaved.
5169
5190
  commitUnsavedInputData() {
5170
5191
  if (this.unsavedInputData.length > 0) {
5171
- this.history.save();
5192
+ this.history.save(false);
5172
5193
  this.unsavedInputData = '';
5173
5194
  }
5174
5195
  }
@@ -6266,7 +6287,6 @@ const defaultItems = [
6266
6287
  'redo',
6267
6288
  '|',
6268
6289
  'heading',
6269
- 'fontSize',
6270
6290
  '|',
6271
6291
  'formatPainter',
6272
6292
  'removeFormat',
@@ -6374,9 +6394,9 @@ class Toolbar {
6374
6394
  });
6375
6395
  }
6376
6396
  // Updates state of each item such as disabled, selected.
6377
- updateState(data) {
6397
+ updateState(stateData) {
6378
6398
  var _a;
6379
- const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = data;
6399
+ const { appliedItems, disabledNameMap, selectedNameMap, selectedValuesMap } = stateData;
6380
6400
  for (const item of this.buttonItemList) {
6381
6401
  const selectedClass = 'lake-button-selected';
6382
6402
  const buttonNode = this.container.find(`button[name="${item.name}"]`);
@@ -6645,6 +6665,7 @@ function openFullScreen(box) {
6645
6665
  dataSource,
6646
6666
  mainClass: 'lake-pswp',
6647
6667
  zoom: false,
6668
+ returnFocus: false,
6648
6669
  arrowPrevSVG: icons.get('left'),
6649
6670
  arrowNextSVG: icons.get('right'),
6650
6671
  closeSVG: icons.get('close'),
@@ -6699,6 +6720,11 @@ function openFullScreen(box) {
6699
6720
  lightbox.on('openingAnimationEnd', () => {
6700
6721
  box.event.emit('openfullscreen');
6701
6722
  });
6723
+ lightbox.on('destroy', () => {
6724
+ window.setTimeout(() => {
6725
+ box.event.emit('closefullscreen');
6726
+ }, 0);
6727
+ });
6702
6728
  lightbox.init();
6703
6729
  lightbox.loadAndOpen(currentIndex);
6704
6730
  }
@@ -7952,9 +7978,10 @@ class LinkPopup {
7952
7978
  if (!this.linkNode) {
7953
7979
  return;
7954
7980
  }
7981
+ const linkNode = this.linkNode;
7955
7982
  this.save();
7956
7983
  this.hide();
7957
- this.event.emit('save');
7984
+ this.event.emit('save', linkNode);
7958
7985
  },
7959
7986
  });
7960
7987
  button.render();
@@ -7970,9 +7997,10 @@ class LinkPopup {
7970
7997
  if (!this.linkNode) {
7971
7998
  return;
7972
7999
  }
8000
+ const lastChild = this.linkNode.last();
7973
8001
  this.linkNode.remove(true);
7974
8002
  this.hide();
7975
- this.event.emit('remove');
8003
+ this.event.emit('remove', lastChild);
7976
8004
  },
7977
8005
  });
7978
8006
  button.render();
@@ -8068,10 +8096,18 @@ class LinkPopup {
8068
8096
 
8069
8097
  var link = (editor) => {
8070
8098
  const popup = new LinkPopup(editor.popupContainer);
8071
- popup.event.on('save', () => {
8099
+ popup.event.on('save', node => {
8100
+ const range = editor.selection.range;
8101
+ range.setStartAfter(node);
8102
+ range.collapseToStart();
8103
+ editor.selection.addRangeToNativeSelection();
8072
8104
  editor.history.save();
8073
8105
  });
8074
- popup.event.on('remove', () => {
8106
+ popup.event.on('remove', node => {
8107
+ const range = editor.selection.range;
8108
+ range.setStartAfter(node);
8109
+ range.collapseToStart();
8110
+ editor.selection.addRangeToNativeSelection();
8075
8111
  editor.history.save();
8076
8112
  });
8077
8113
  editor.root.on('scroll', () => {
@@ -8095,6 +8131,12 @@ var link = (editor) => {
8095
8131
  }
8096
8132
  popup.show(linkNode);
8097
8133
  });
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
+ });
8098
8140
  editor.command.add('link', {
8099
8141
  execute: () => {
8100
8142
  const linkNode = editor.selection.insertLink(`<a href="">${locale.link.newLink()}</a>`);