lakelib 0.1.24 → 0.2.0

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
@@ -1271,6 +1271,12 @@ lake-box[name="equation"] .lake-box-activated .lake-equation-form {
1271
1271
  .lake-equation .lake-equation-form textarea:focus-visible {
1272
1272
  outline: 0;
1273
1273
  }
1274
+ .lake-equation .lake-equation-form .lake-button-row {
1275
+ display: flex;
1276
+ flex-direction: column;
1277
+ justify-content: space-between;
1278
+ align-items: flex-end;
1279
+ }
1274
1280
  /* error status */
1275
1281
  .lake-equation-error {
1276
1282
  padding: 0 6px;
package/lib/lake.js CHANGED
@@ -21,6 +21,8 @@ if (customElements.get('lake-bookmark') !== undefined) {
21
21
 
22
22
  var plus = "<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,216Zm48-88a8,8,0,0,1-8,8H136v32a8,8,0,0,1-16,0V136H88a8,8,0,0,1,0-16h32V88a8,8,0,0,1,16,0v32h32A8,8,0,0,1,176,128Z\"></path></svg>";
23
23
 
24
+ var question = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M140,180a12,12,0,1,1-12-12A12,12,0,0,1,140,180ZM128,72c-22.06,0-40,16.15-40,36v4a8,8,0,0,0,16,0v-4c0-11,10.77-20,24-20s24,9,24,20-10.77,20-24,20a8,8,0,0,0-8,8v8a8,8,0,0,0,16,0v-.72c18.24-3.35,32-17.9,32-35.28C168,88.15,150.06,72,128,72Zm104,56A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z\"></path></svg>";
25
+
24
26
  var more = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M112,60a16,16,0,1,1,16,16A16,16,0,0,1,112,60Zm16,52a16,16,0,1,0,16,16A16,16,0,0,0,128,112Zm0,68a16,16,0,1,0,16,16A16,16,0,0,0,128,180Z\"></path></svg>";
25
27
 
26
28
  var left = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M165.66,202.34a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L91.31,128Z\"></path></svg>";
@@ -165,6 +167,7 @@ var table = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\
165
167
  // basic
166
168
  const icons = new Map([
167
169
  ['plus', plus],
170
+ ['question', question],
168
171
  ['more', more],
169
172
  ['left', left],
170
173
  ['right', right],
@@ -1515,7 +1518,7 @@ class Range {
1515
1518
  selectBox(boxNode) {
1516
1519
  const boxContainer = boxNode.find('.lake-box-container');
1517
1520
  if (boxContainer.length === 0) {
1518
- throw new Error(`The box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
1521
+ throw new Error(`Box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
1519
1522
  }
1520
1523
  this.setStart(boxContainer, 0);
1521
1524
  this.collapseToStart();
@@ -1524,7 +1527,7 @@ class Range {
1524
1527
  selectBoxStart(boxNode) {
1525
1528
  const boxStrip = boxNode.find('.lake-box-strip');
1526
1529
  if (boxStrip.length === 0) {
1527
- throw new Error(`The box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
1530
+ throw new Error(`Box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
1528
1531
  }
1529
1532
  this.selectNodeContents(boxStrip.eq(0));
1530
1533
  this.collapseToStart();
@@ -1533,7 +1536,7 @@ class Range {
1533
1536
  selectBoxEnd(boxNode) {
1534
1537
  const boxStrip = boxNode.find('.lake-box-strip');
1535
1538
  if (boxStrip.length === 0) {
1536
- throw new Error(`The box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
1539
+ throw new Error(`Box "${boxNode.attr('name')}" (id=${boxNode.id}) cannot be selected because it has not been rendered yet.`);
1537
1540
  }
1538
1541
  this.selectNodeContents(boxStrip.eq(1));
1539
1542
  this.collapseToStart();
@@ -2931,7 +2934,7 @@ var enUS = {
2931
2934
  image: 'Image',
2932
2935
  file: 'File',
2933
2936
  emoji: 'Emoji',
2934
- equation: 'Equation',
2937
+ equation: 'Mathematical formula',
2935
2938
  removeColor: 'Remove color',
2936
2939
  },
2937
2940
  slash: {
@@ -2963,8 +2966,8 @@ var enUS = {
2963
2966
  codeBlockDesc: 'Insert a code block',
2964
2967
  video: 'Video',
2965
2968
  videoDesc: 'Insert a video from YouTube',
2966
- equation: 'Equation',
2967
- equationDesc: 'Insert TeX expression in text',
2969
+ equation: 'Mathematical formula',
2970
+ equationDesc: 'Insert a TeX expression',
2968
2971
  image: 'Image',
2969
2972
  imageDesc: 'Upload an image',
2970
2973
  file: 'File',
@@ -3005,6 +3008,7 @@ var enUS = {
3005
3008
  },
3006
3009
  equation: {
3007
3010
  save: 'Done',
3011
+ help: 'Supported Functions',
3008
3012
  placeholder: 'Type a TeX expression',
3009
3013
  },
3010
3014
  };
@@ -3056,7 +3060,7 @@ var zhCN = {
3056
3060
  image: '图片',
3057
3061
  file: '文件',
3058
3062
  emoji: '表情',
3059
- equation: '公式',
3063
+ equation: '数学公式',
3060
3064
  removeColor: '默认',
3061
3065
  },
3062
3066
  slash: {
@@ -3088,7 +3092,7 @@ var zhCN = {
3088
3092
  codeBlockDesc: '插入代码块',
3089
3093
  video: '视频',
3090
3094
  videoDesc: '插入 YouTube 视频',
3091
- equation: '公式',
3095
+ equation: '数学公式',
3092
3096
  equationDesc: '支持 TeX 语法',
3093
3097
  image: '图片',
3094
3098
  imageDesc: '上传图片',
@@ -3130,7 +3134,8 @@ var zhCN = {
3130
3134
  },
3131
3135
  equation: {
3132
3136
  save: '确定',
3133
- placeholder: '请输入 TeX 公式',
3137
+ help: '支持的功能',
3138
+ placeholder: '请输入 TeX 表达式',
3134
3139
  },
3135
3140
  };
3136
3141
 
@@ -3181,7 +3186,7 @@ var ja = {
3181
3186
  image: '画像',
3182
3187
  file: 'ファイル',
3183
3188
  emoji: '絵文字',
3184
- equation: '公式',
3189
+ equation: '数学公式',
3185
3190
  removeColor: 'デフォルト',
3186
3191
  },
3187
3192
  slash: {
@@ -3213,8 +3218,8 @@ var ja = {
3213
3218
  codeBlockDesc: 'コードブロックを挿入',
3214
3219
  video: '動画',
3215
3220
  videoDesc: 'YouTube から動画を挿入',
3216
- equation: '公式',
3217
- equationDesc: 'TeX 式を挿入',
3221
+ equation: '数学公式',
3222
+ equationDesc: 'TeX 数式を挿入',
3218
3223
  image: '画像',
3219
3224
  imageDesc: '画像をアップロード',
3220
3225
  file: 'ファイル',
@@ -3255,7 +3260,8 @@ var ja = {
3255
3260
  },
3256
3261
  equation: {
3257
3262
  save: '確認',
3258
- placeholder: 'TeX 公式を入力してください。',
3263
+ help: 'サポートされている機能',
3264
+ placeholder: 'TeX 数式を入力してください。',
3259
3265
  },
3260
3266
  };
3261
3267
 
@@ -3306,7 +3312,7 @@ var ko = {
3306
3312
  image: '이미지',
3307
3313
  file: '파일',
3308
3314
  emoji: '이모지',
3309
- equation: '수식',
3315
+ equation: '수학 공식',
3310
3316
  removeColor: '기본색',
3311
3317
  },
3312
3318
  slash: {
@@ -3338,8 +3344,8 @@ var ko = {
3338
3344
  codeBlockDesc: '코드 블록을 삽입',
3339
3345
  video: '동영상',
3340
3346
  videoDesc: '유튜브 동영상을 삽입',
3341
- equation: '수식',
3342
- equationDesc: '텍스 표현식을 삽입',
3347
+ equation: '수학 공식',
3348
+ equationDesc: 'TeX 수식을 삽입',
3343
3349
  image: '이미지',
3344
3350
  imageDesc: '이미지를 업로드',
3345
3351
  file: '파일',
@@ -3380,6 +3386,7 @@ var ko = {
3380
3386
  },
3381
3387
  equation: {
3382
3388
  save: '확인',
3389
+ help: '지원되는 기능',
3383
3390
  placeholder: 'TeX 수식을 입력하세요',
3384
3391
  },
3385
3392
  };
@@ -3789,7 +3796,7 @@ class Box {
3789
3796
  if (typeof node === 'string') {
3790
3797
  const component = boxes.get(node);
3791
3798
  if (component === undefined) {
3792
- throw new Error(`The box "${node}" has not been defined yet.`);
3799
+ throw new Error(`Box "${node}" has not been defined yet.`);
3793
3800
  }
3794
3801
  const type = encode(component.type);
3795
3802
  const name = encode(component.name);
@@ -3802,7 +3809,7 @@ class Box {
3802
3809
  this.node = query(node);
3803
3810
  const component = boxes.get(this.name);
3804
3811
  if (component === undefined) {
3805
- throw new Error(`The box "${this.name}" has not been defined yet.`);
3812
+ throw new Error(`Box "${this.name}" has not been defined yet.`);
3806
3813
  }
3807
3814
  if (component.value && !this.node.hasAttr('value')) {
3808
3815
  this.value = component.value;
@@ -3833,7 +3840,7 @@ class Box {
3833
3840
  container.removeClass('lake-box-hovered');
3834
3841
  });
3835
3842
  container.on('click', () => {
3836
- debug(`The box "${this.name}" (id = ${this.node.id}) value:`);
3843
+ debug(`Box "${this.name}" (id = ${this.node.id}) value:`);
3837
3844
  debug(this.value);
3838
3845
  });
3839
3846
  if (this.type === 'block' && this.node.isContentEditable) {
@@ -3877,7 +3884,7 @@ class Box {
3877
3884
  const container = this.node.closest('div[contenteditable]');
3878
3885
  const editor = container.length > 0 ? editors.get(container.id) : undefined;
3879
3886
  if (!editor) {
3880
- throw new Error(`The box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);
3887
+ throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);
3881
3888
  }
3882
3889
  return editor;
3883
3890
  }
@@ -3935,7 +3942,7 @@ class Box {
3935
3942
  container.empty();
3936
3943
  container.append(content);
3937
3944
  }
3938
- debug(`The box "${this.name}" (id: ${this.node.id}) rendered`);
3945
+ debug(`Box "${this.name}" (id: ${this.node.id}) rendered`);
3939
3946
  }
3940
3947
  // Destroys a rendered box.
3941
3948
  unmount() {
@@ -3943,7 +3950,7 @@ class Box {
3943
3950
  this.event.emit('beforeunmount');
3944
3951
  this.event.removeAllListeners();
3945
3952
  this.node.empty();
3946
- debug(`The box "${this.name}" (id: ${this.node.id}) unmounted`);
3953
+ debug(`Box "${this.name}" (id: ${this.node.id}) unmounted`);
3947
3954
  }
3948
3955
  // Returns a HTML string of the box.
3949
3956
  getHTML() {
@@ -5352,7 +5359,7 @@ function removeBox(range) {
5352
5359
  return box;
5353
5360
  }
5354
5361
 
5355
- var version = "0.1.24";
5362
+ var version = "0.2.0";
5356
5363
 
5357
5364
  // Returns the attributes of the element as an key-value object.
5358
5365
  function getAttributes(node) {
@@ -5536,7 +5543,7 @@ class Selection {
5536
5543
  insertBox(boxName, boxValue) {
5537
5544
  const box = insertBox(this.range, boxName, boxValue);
5538
5545
  if (!box) {
5539
- throw new Error(`The box "${boxName}" cannot be inserted outside the editor.`);
5546
+ throw new Error(`Box "${boxName}" cannot be inserted outside the editor.`);
5540
5547
  }
5541
5548
  return box;
5542
5549
  }
@@ -6447,7 +6454,7 @@ class Editor {
6447
6454
  const unmountPlugin = this.unmountPluginMap.get(name);
6448
6455
  if (unmountPlugin) {
6449
6456
  unmountPlugin();
6450
- debug(`The plugin "${name}" unmounted`);
6457
+ debug(`Plugin "${name}" unmounted`);
6451
6458
  }
6452
6459
  }
6453
6460
  if (this.toolbar) {
@@ -7236,7 +7243,13 @@ class Toolbar {
7236
7243
  editor,
7237
7244
  name: item.name,
7238
7245
  file,
7239
- onError: error => editor.config.onMessage('error', error),
7246
+ onError: error => {
7247
+ fileNativeNode.value = '';
7248
+ editor.config.onMessage('error', error);
7249
+ },
7250
+ onSuccess: () => {
7251
+ fileNativeNode.value = '';
7252
+ },
7240
7253
  });
7241
7254
  }
7242
7255
  });
@@ -7570,7 +7583,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
7570
7583
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
7571
7584
  PERFORMANCE OF THIS SOFTWARE.
7572
7585
  ***************************************************************************** */
7573
- /* global Reflect, Promise, SuppressedError, Symbol */
7586
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
7574
7587
 
7575
7588
 
7576
7589
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -8286,7 +8299,7 @@ function renderError(box) {
8286
8299
  editor.selection.selectBox(box);
8287
8300
  });
8288
8301
  editor.config.onMessage('warning', `
8289
- The box "${box.name}" (id: ${box.node.id}) failed to display because window.katex was not found.
8302
+ Box "${box.name}" (id: ${box.node.id}) failed to display because window.katex was not found.
8290
8303
  Please check if the "katex" library is added to this page.
8291
8304
  `.trim());
8292
8305
  }
@@ -8304,6 +8317,7 @@ var equationBox = {
8304
8317
  renderError(box);
8305
8318
  return;
8306
8319
  }
8320
+ const equationConfig = editor.config.equation;
8307
8321
  const defaultCode = (box.value.code || '').trim();
8308
8322
  const viewNode = query('<div class="lake-equation-view" />');
8309
8323
  rootNode.append(viewNode);
@@ -8331,7 +8345,7 @@ var equationBox = {
8331
8345
  }));
8332
8346
  box.updateValue('code', code);
8333
8347
  });
8334
- const button = new Button({
8348
+ const saveButton = new Button({
8335
8349
  root: formNode.find('.lake-button-row'),
8336
8350
  name: 'save',
8337
8351
  type: 'primary',
@@ -8342,7 +8356,17 @@ var equationBox = {
8342
8356
  editor.history.save();
8343
8357
  },
8344
8358
  });
8345
- button.render();
8359
+ saveButton.render();
8360
+ const helpButton = new Button({
8361
+ root: formNode.find('.lake-button-row'),
8362
+ name: 'help',
8363
+ icon: icons.get('question'),
8364
+ tooltip: editor.locale.equation.help(),
8365
+ onClick: () => {
8366
+ window.open(equationConfig.helpUrl);
8367
+ },
8368
+ });
8369
+ helpButton.render();
8346
8370
  },
8347
8371
  };
8348
8372
 
@@ -9771,6 +9795,9 @@ var equation = (editor) => {
9771
9795
  if (!window.katex) {
9772
9796
  return;
9773
9797
  }
9798
+ editor.setPluginConfig('equation', {
9799
+ helpUrl: 'https://katex.org/docs/supported',
9800
+ });
9774
9801
  if (editor.readonly) {
9775
9802
  return;
9776
9803
  }
@@ -10416,6 +10443,12 @@ var backspaceKey = (editor) => {
10416
10443
  editor.history.save();
10417
10444
  return;
10418
10445
  }
10446
+ if ((prevNode.isMark || prevNode.name === 'a') && prevNode.isEmpty) {
10447
+ event.preventDefault();
10448
+ prevNode.remove();
10449
+ editor.history.save();
10450
+ return;
10451
+ }
10419
10452
  if (prevNode.isText && prevNode.text().length === 1 && prevNode.parent().isBlock) {
10420
10453
  event.preventDefault();
10421
10454
  const block = prevNode.closestBlock();
@@ -10922,6 +10955,8 @@ class SlashPopup {
10922
10955
  this.range = null;
10923
10956
  this.noMouseEvent = false;
10924
10957
  this.keyword = null;
10958
+ this.horizontalDirection = 'right';
10959
+ this.verticalDirection = 'bottom';
10925
10960
  this.keydownListener = (event) => {
10926
10961
  if (isKeyHotkey('escape', event)) {
10927
10962
  event.preventDefault();
@@ -11063,7 +11098,13 @@ class SlashPopup {
11063
11098
  editor,
11064
11099
  name: item.name,
11065
11100
  file,
11066
- onError: error => editor.config.onMessage('error', error),
11101
+ onError: error => {
11102
+ fileNativeNode.value = '';
11103
+ editor.config.onMessage('error', error);
11104
+ },
11105
+ onSuccess: () => {
11106
+ fileNativeNode.value = '';
11107
+ },
11067
11108
  });
11068
11109
  }
11069
11110
  });
@@ -11102,7 +11143,7 @@ class SlashPopup {
11102
11143
  }
11103
11144
  return items;
11104
11145
  }
11105
- position() {
11146
+ position(keepDirection = false) {
11106
11147
  if (!this.range) {
11107
11148
  return;
11108
11149
  }
@@ -11110,13 +11151,27 @@ class SlashPopup {
11110
11151
  const rangeRect = this.range.get().getBoundingClientRect();
11111
11152
  const rangeX = rangeRect.x + window.scrollX;
11112
11153
  const rangeY = rangeRect.y + window.scrollY;
11113
- if (rangeRect.x + this.container.width() > window.innerWidth) {
11154
+ if (!keepDirection) {
11155
+ if (rangeRect.x + this.container.width() > window.innerWidth) {
11156
+ this.horizontalDirection = 'left';
11157
+ }
11158
+ else {
11159
+ this.horizontalDirection = 'right';
11160
+ }
11161
+ if (rangeRect.y + rangeRect.height + this.container.height() > window.innerHeight) {
11162
+ this.verticalDirection = 'top';
11163
+ }
11164
+ else {
11165
+ this.verticalDirection = 'bottom';
11166
+ }
11167
+ }
11168
+ if (this.horizontalDirection === 'left') {
11114
11169
  this.container.css('left', `${rangeX - this.container.width() + rangeRect.width}px`);
11115
11170
  }
11116
11171
  else {
11117
11172
  this.container.css('left', `${rangeX}px`);
11118
11173
  }
11119
- if (rangeRect.y + rangeRect.height + this.container.height() > window.innerHeight) {
11174
+ if (this.verticalDirection === 'top') {
11120
11175
  this.container.css('top', `${rangeY - this.container.height() - 5}px`);
11121
11176
  }
11122
11177
  else {
@@ -11146,7 +11201,7 @@ class SlashPopup {
11146
11201
  if (selectedItemNode.length === 0) {
11147
11202
  this.container.find('.lake-slash-item').eq(0).addClass('lake-slash-item-selected');
11148
11203
  }
11149
- this.position();
11204
+ this.position(true);
11150
11205
  }
11151
11206
  show(range, keyword) {
11152
11207
  const editor = this.editor;