@ones-editor/editor 2.1.1-beta.74 → 2.1.1-beta.75

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.
@@ -51,6 +51,7 @@ declare const _default: {
51
51
  subscript: string;
52
52
  superscript: string;
53
53
  more: string;
54
+ selectBlock: string;
54
55
  };
55
56
  };
56
57
  export default _default;
@@ -51,6 +51,7 @@ declare const _default: {
51
51
  subscript: string;
52
52
  superscript: string;
53
53
  more: string;
54
+ selectBlock: string;
54
55
  };
55
56
  };
56
57
  export default _default;
@@ -51,6 +51,7 @@ declare const _default: {
51
51
  subscript: string;
52
52
  superscript: string;
53
53
  more: string;
54
+ selectBlock: string;
54
55
  };
55
56
  };
56
57
  export default _default;
@@ -1,9 +1,12 @@
1
1
  import { BlockElement, CommandItem, CommandItemWithSource, CommandParams, CommandResult, OnesEditor, OnesEditorCommandProvider, SelectionRange } from '../../../../@ones-editor/core';
2
2
  export declare class MobileLinkProvider implements OnesEditorCommandProvider {
3
+ private options?;
3
4
  id: string;
4
5
  insertProvider: OnesEditorCommandProvider;
5
6
  editProvider: OnesEditorCommandProvider;
6
- constructor(editor: OnesEditor);
7
+ constructor(editor: OnesEditor, options?: {
8
+ linkMode: 'insert' | 'edit';
9
+ } | undefined);
7
10
  getSelectedLinkChild: (editor: OnesEditor, range: SelectionRange) => import("@ones-editor/core").TextBlockContentChild | null;
8
11
  getAvailableCommands: (editor: OnesEditor, block: BlockElement, range: SelectionRange, params?: CommandParams) => CommandItem[];
9
12
  executeCommand: (editor: OnesEditor, block: BlockElement, range: SelectionRange, item: CommandItemWithSource, params: CommandParams, result?: CommandResult) => boolean;
@@ -0,0 +1,9 @@
1
+ import { BlockElement, CommandItem, CommandParams, OnesEditor, OnesEditorCommandProvider, SelectionRange } from '../../../../@ones-editor/core';
2
+ export default class SelectionProvider implements OnesEditorCommandProvider {
3
+ private editor;
4
+ id: string;
5
+ constructor(editor: OnesEditor);
6
+ getAvailableCommands(editor: OnesEditor, block: BlockElement, range: SelectionRange, params?: CommandParams): CommandItem[];
7
+ getInsertCommands: () => never[];
8
+ executeCommand(editor: OnesEditor, block: BlockElement, range: SelectionRange, command: CommandItem): boolean;
9
+ }
package/dist/index.js CHANGED
@@ -8931,29 +8931,42 @@ var __publicField = (obj, key, value) => {
8931
8931
  return events2 instanceof TouchEvent;
8932
8932
  }
8933
8933
  function bindDbClick(elem, handler) {
8934
- let touchTime = 0;
8935
- const callback = (event) => {
8936
- if (touchTime === 0) {
8937
- touchTime = new Date().getTime();
8938
- } else {
8939
- if (new Date().getTime() - touchTime < 800) {
8940
- handler(event);
8941
- }
8942
- touchTime = 0;
8934
+ let clickCount = 0;
8935
+ function simulateDoubleClick(event) {
8936
+ clickCount++;
8937
+ if (clickCount === 1) {
8938
+ setTimeout(() => {
8939
+ if (clickCount === 2) {
8940
+ handler(event);
8941
+ }
8942
+ clickCount = 0;
8943
+ }, 300);
8943
8944
  }
8944
- };
8945
- elem.addEventListener("click", callback);
8945
+ }
8946
+ elem.addEventListener("click", simulateDoubleClick);
8946
8947
  return () => {
8947
- elem.removeEventListener("click", callback);
8948
+ elem.removeEventListener("click", simulateDoubleClick);
8948
8949
  };
8949
8950
  }
8951
+ const getVisualViewportHeightOffset = () => {
8952
+ var _a, _b;
8953
+ if (!clientType.isMobile) {
8954
+ return 0;
8955
+ }
8956
+ let topWindow = window;
8957
+ if (window.top) {
8958
+ topWindow = window.top;
8959
+ }
8960
+ const visualViewportHeight = (_b = (_a = topWindow.visualViewport) == null ? void 0 : _a.height) != null ? _b : topWindow.innerHeight || topWindow.document.documentElement.clientHeight;
8961
+ return Math.max(topWindow.innerHeight - visualViewportHeight, 40);
8962
+ };
8950
8963
  class ScrollDomElement {
8951
8964
  constructor(element) {
8952
8965
  __publicField(this, "element");
8953
8966
  this.element = element;
8954
8967
  }
8955
8968
  getClientHeight() {
8956
- return this.element.clientHeight;
8969
+ return this.element.clientHeight - getVisualViewportHeightOffset();
8957
8970
  }
8958
8971
  getHorizontalScroll() {
8959
8972
  return this.element.scrollLeft;
@@ -9862,6 +9875,11 @@ var __publicField = (obj, key, value) => {
9862
9875
  });
9863
9876
  }
9864
9877
  function select(element) {
9878
+ const preventDefault = (event) => {
9879
+ event.preventDefault();
9880
+ event.stopPropagation();
9881
+ };
9882
+ document.addEventListener("selectionchange", preventDefault, { capture: true, passive: false });
9865
9883
  if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
9866
9884
  element.select();
9867
9885
  } else {
@@ -9871,6 +9889,9 @@ var __publicField = (obj, key, value) => {
9871
9889
  selection == null ? void 0 : selection.removeAllRanges();
9872
9890
  selection == null ? void 0 : selection.addRange(range);
9873
9891
  }
9892
+ setTimeout(() => {
9893
+ document.removeEventListener("selectionchange", preventDefault, { capture: true });
9894
+ });
9874
9895
  }
9875
9896
  async function copyTextToClipboard(text2) {
9876
9897
  const textarea2 = document.createElement("textarea");
@@ -11189,7 +11210,7 @@ var __publicField = (obj, key, value) => {
11189
11210
  if (event.detail === 1) {
11190
11211
  this.editor.input.focus();
11191
11212
  }
11192
- if (event.detail === 3) {
11213
+ if (event.detail === 3 && !clientType.isMobile) {
11193
11214
  this.editor.selectionHandler.handleTripleClick(event);
11194
11215
  }
11195
11216
  if (event.detail === 1 && event.button === 0) {
@@ -25009,7 +25030,10 @@ var __publicField = (obj, key, value) => {
25009
25030
  const x1 = rect.x < 0 ? 0 : rect.x;
25010
25031
  const y1 = rect.y < 0 ? 0 : rect.y;
25011
25032
  const x2 = rect.right > window.innerWidth ? window.innerWidth : rect.right;
25012
- const y2 = rect.bottom > window.innerHeight ? window.innerHeight : rect.bottom;
25033
+ let y2 = rect.bottom > window.innerHeight ? window.innerHeight : rect.bottom;
25034
+ if (clientType.isIOS) {
25035
+ y2 -= getVisualViewportHeightOffset();
25036
+ }
25013
25037
  return new DOMRect(x1, y1, x2 - x1, y2 - y1);
25014
25038
  }
25015
25039
  function isBlockPositionVisible(editor, pos) {
@@ -30466,7 +30490,7 @@ ${codeText}
30466
30490
  Array.from(this.activeBlockAttributes).forEach(([key, value]) => {
30467
30491
  const op = { attributes, insert: "" };
30468
30492
  if (key === "color" || key === "backgroundColor") {
30469
- if (!value) {
30493
+ if (value === null || value === void 0) {
30470
30494
  deleteColor(op, key);
30471
30495
  } else {
30472
30496
  addColor(op, key, value);
@@ -46397,10 +46421,11 @@ ${codeText}
46397
46421
  element: this.createPasteElement(editor),
46398
46422
  states: []
46399
46423
  };
46400
- const items = [cutItem, copyItem];
46424
+ const items = [copyItem];
46401
46425
  if (this.options.withPaste) {
46402
46426
  items.push(pasteItem);
46403
46427
  }
46428
+ items.push(cutItem);
46404
46429
  return items;
46405
46430
  });
46406
46431
  __publicField(this, "getInsertCommands", () => []);
@@ -50280,7 +50305,7 @@ ${codeText}
50280
50305
  this.clipboardProvider.executeRangeCommand(editor, range, item);
50281
50306
  });
50282
50307
  this.editor = editor;
50283
- this.clipboardProvider = new ClipboardProvider(this.editor, { withPaste: true });
50308
+ this.clipboardProvider = new ClipboardProvider(this.editor, { withPaste: false });
50284
50309
  }
50285
50310
  commands(editor, block, child) {
50286
50311
  if (!editor.isWritable()) {
@@ -50290,11 +50315,11 @@ ${codeText}
50290
50315
  return void 0;
50291
50316
  }
50292
50317
  const commands = [];
50318
+ commands.push(...this.provider.getAvailableCommands(editor, block, this.editor.selection.range, { child }));
50293
50319
  if (clientType.isMobile) {
50294
50320
  this.clipboardProvider.getAvailableCommands(editor, block).forEach((c) => commands.push(c));
50295
50321
  commands.push({ id: "separator", name: "", type: "separator" });
50296
50322
  }
50297
- commands.push(...this.provider.getAvailableCommands(editor, block, this.editor.selection.range, { child }));
50298
50323
  return {
50299
50324
  element: child,
50300
50325
  group: "hovering-toolbar",
@@ -50348,6 +50373,33 @@ ${codeText}
50348
50373
  return false;
50349
50374
  }
50350
50375
  }
50376
+ class SelectionProvider {
50377
+ constructor(editor) {
50378
+ __publicField(this, "id", "SelectionProvider");
50379
+ __publicField(this, "getInsertCommands", () => []);
50380
+ this.editor = editor;
50381
+ }
50382
+ getAvailableCommands(editor, block, range, params) {
50383
+ const disabled = !isTextKindBlock(editor, block) || isSelectBoxOnly(editor);
50384
+ if (disabled && (params == null ? void 0 : params.isFilter)) {
50385
+ return [];
50386
+ }
50387
+ return [
50388
+ {
50389
+ name: i18n$1.t("commands.selectBlock"),
50390
+ id: "select-block",
50391
+ states: disabled ? ["disabled"] : []
50392
+ }
50393
+ ];
50394
+ }
50395
+ executeCommand(editor, block, range, command) {
50396
+ if (command.id === "select-block") {
50397
+ editor.selection.selectBlock(block, 0, getBlockTextLength$6(editor, block));
50398
+ return true;
50399
+ }
50400
+ return false;
50401
+ }
50402
+ }
50351
50403
  const logger$1S = getLogger("toolbar-handler");
50352
50404
  class OnesEditorToolbar {
50353
50405
  constructor(editor) {
@@ -50487,9 +50539,11 @@ ${codeText}
50487
50539
  OnesEditorHoveringBlock.get(editor).addFilter(this);
50488
50540
  editor.blockHooks.push(new LinkCommands(editor));
50489
50541
  if (clientType.isMobile) {
50490
- editor.editorCommandProviders.registerCommandProvider(new MobileLinkProvider(editor));
50542
+ editor.editorCommandProviders.registerCommandProvider(new MobileLinkProvider(editor, { linkMode: "edit" }));
50491
50543
  editor.editorCommandProviders.registerCommandProvider(new StandardBoxProvider(editor));
50492
50544
  editor.editorCommandProviders.registerCommandProvider(new ClipboardProvider(editor, { withPaste: true }));
50545
+ editor.editorCommandProviders.registerCommandProvider(new SelectionProvider(editor));
50546
+ editor.editorCommandProviders.registerCommandProvider(new MobileLinkProvider(editor, { linkMode: "insert" }));
50493
50547
  } else {
50494
50548
  editor.editorCommandProviders.registerCommandProvider(new BlockTurnIntoCommandProvider(editor));
50495
50549
  editor.editorCommandProviders.registerCommandProvider(new ParagraphProvider$1(editor));
@@ -57992,7 +58046,8 @@ $$${mathData.mathjaxText}$$
57992
58046
  code: "\u884C\u5185\u4EE3\u7801",
57993
58047
  subscript: "\u4E0B\u6807",
57994
58048
  superscript: "\u4E0A\u6807",
57995
- more: "\u66F4\u591A"
58049
+ more: "\u66F4\u591A",
58050
+ selectBlock: "\u9009\u62E9\u533A\u5757"
57996
58051
  }
57997
58052
  };
57998
58053
  const enUS$q = {
@@ -58047,7 +58102,8 @@ $$${mathData.mathjaxText}$$
58047
58102
  code: "Inline code",
58048
58103
  subscript: "Subscript",
58049
58104
  superscript: "Superscript",
58050
- more: "More"
58105
+ more: "More",
58106
+ selectBlock: "Select Block"
58051
58107
  }
58052
58108
  };
58053
58109
  const jaJP$q = {
@@ -58102,7 +58158,8 @@ $$${mathData.mathjaxText}$$
58102
58158
  code: "\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",
58103
58159
  subscript: "\u4E0B\u4ED8\u304D\u6587\u5B57",
58104
58160
  superscript: "\u4E0A\u4ED8\u304D\u6587\u5B57",
58105
- more: "\u305D\u306E\u4ED6"
58161
+ more: "\u305D\u306E\u4ED6",
58162
+ selectBlock: "\u30D6\u30ED\u30C3\u30AF\u3092\u9078\u629E"
58106
58163
  }
58107
58164
  };
58108
58165
  i18n$1.mergeLang({
@@ -59016,7 +59073,7 @@ $$${mathData.mathjaxText}$$
59016
59073
  }
59017
59074
  }
59018
59075
  class MobileLinkProvider {
59019
- constructor(editor) {
59076
+ constructor(editor, options) {
59020
59077
  __publicField(this, "id", "MobileLinkProvider");
59021
59078
  __publicField(this, "insertProvider");
59022
59079
  __publicField(this, "editProvider");
@@ -59040,12 +59097,16 @@ $$${mathData.mathjaxText}$$
59040
59097
  return null;
59041
59098
  });
59042
59099
  __publicField(this, "getAvailableCommands", (editor, block, range, params) => {
59100
+ var _a, _b;
59043
59101
  const editorRange = editor.selection.range;
59044
59102
  const child = this.getSelectedLinkChild(editor, editorRange);
59045
- if (child) {
59103
+ if (child && ((_a = this.options) == null ? void 0 : _a.linkMode) === "edit") {
59046
59104
  return this.editProvider.getAvailableCommands(editor, block, range, { child });
59047
59105
  }
59048
- return this.insertProvider.getAvailableCommands(editor, block, range, { ...params, isFilter: true });
59106
+ if (((_b = this.options) == null ? void 0 : _b.linkMode) === "insert" && !child) {
59107
+ return this.insertProvider.getAvailableCommands(editor, block, range, { ...params, isFilter: true });
59108
+ }
59109
+ return [];
59049
59110
  });
59050
59111
  __publicField(this, "executeCommand", (editor, block, range, item, params, result) => {
59051
59112
  var _a, _b, _c, _d, _e, _f;
@@ -59056,6 +59117,7 @@ $$${mathData.mathjaxText}$$
59056
59117
  }
59057
59118
  return (_f = (_e = (_d = this.insertProvider) == null ? void 0 : _d.executeCommand) == null ? void 0 : _e.call(_d, editor, block, range, item, params, result)) != null ? _f : false;
59058
59119
  });
59120
+ this.options = options;
59059
59121
  this.insertProvider = new LinkProvider(editor);
59060
59122
  this.editProvider = new EditLinkProvider();
59061
59123
  }
@@ -79627,7 +79689,7 @@ ${content}
79627
79689
  return groupEachCommand(commands);
79628
79690
  });
79629
79691
  __publicField(this, "showToolbar", () => {
79630
- hideToolbar$1(this.editor);
79692
+ tippy$1.hideAll();
79631
79693
  const commands = this.getCommands();
79632
79694
  this.toolbar.updateItems(commands);
79633
79695
  const focusBlock = this.editor.selection.focusedBlock;
@@ -79986,8 +80048,15 @@ ${content}
79986
80048
  __publicField(this, "commandBar");
79987
80049
  __publicField(this, "observer");
79988
80050
  __publicField(this, "toggleDelay", clientType.isSafari ? 800 : 100);
80051
+ __publicField(this, "preHeight", this.virtualViewportHeight);
79989
80052
  __publicField(this, "layoutBar", debounce__default.default(() => {
79990
80053
  const offsetHeight = Math.max(this.clientHeight - this.virtualViewportHeight, 0);
80054
+ if (clientType.isIOS) {
80055
+ if (this.preHeight > this.virtualViewportHeight) {
80056
+ editorScrollIntoView(this.editor);
80057
+ }
80058
+ }
80059
+ this.preHeight = this.virtualViewportHeight;
79991
80060
  this.commandBar.bar.style.bottom = `${offsetHeight}px`;
79992
80061
  }, this.toggleDelay));
79993
80062
  __publicField(this, "handScroll", debounce__default.default(() => {
@@ -80132,17 +80201,6 @@ ${content}
80132
80201
  this.editor.selection.selectBlock(block, offset, offset + 1);
80133
80202
  return true;
80134
80203
  }
80135
- if (this.editor.selection.range.isCollapsed()) {
80136
- const rangeRect = getBlockClientRects(this.editor, block, this.editor.selection.range);
80137
- const clientX = event.touches[0].clientX;
80138
- const clientY = event.touches[0].clientY;
80139
- const step = 10;
80140
- const inRect = rangeRect.some((rect) => clientX > rect.left - step && clientX < rect.right + step && clientY > rect.top - step && clientY < rect.bottom + step);
80141
- if (inRect) {
80142
- this.cursorToolbar.showToolbar();
80143
- return true;
80144
- }
80145
- }
80146
80204
  }
80147
80205
  return false;
80148
80206
  });
@@ -80160,6 +80218,11 @@ ${content}
80160
80218
  }, LONG_PRESS_DELAY);
80161
80219
  }
80162
80220
  });
80221
+ __publicField(this, "debounceShowCursorToolbar", debounce__default.default(() => {
80222
+ if (this.editor.selection.range.isCollapsed()) {
80223
+ this.cursorToolbar.showToolbar();
80224
+ }
80225
+ }, 400));
80163
80226
  __publicField(this, "handleTouchEnd", (event) => {
80164
80227
  if (this.longPressTimeout) {
80165
80228
  window.clearTimeout(this.longPressTimeout);
@@ -80171,6 +80234,17 @@ ${content}
80171
80234
  }
80172
80235
  this.longPressTriggered = false;
80173
80236
  this.isMoving = false;
80237
+ if (this.editor.selection.range.isCollapsed()) {
80238
+ const block = this.editor.selection.focusedBlock;
80239
+ const rangeRect = getBlockClientRects(this.editor, block, this.editor.selection.range);
80240
+ const clientX = event.changedTouches[0].clientX;
80241
+ const clientY = event.changedTouches[0].clientY;
80242
+ const step = 18;
80243
+ const inRect = rangeRect.some((rect) => clientX > rect.left - step && clientX < rect.right + step && clientY > rect.top - step && clientY < rect.bottom + step);
80244
+ if (inRect) {
80245
+ this.debounceShowCursorToolbar();
80246
+ }
80247
+ }
80174
80248
  });
80175
80249
  this.editor = editor;
80176
80250
  this.editor.addListener("selectionChanged", this.handleSelectionChange);
@@ -86615,7 +86689,7 @@ ${data2.flowchartText}
86615
86689
  }
86616
86690
  }
86617
86691
  });
86618
- editor.version = "2.1.1-beta.74";
86692
+ editor.version = "2.1.1-beta.75";
86619
86693
  if (Logger$2.level === LogLevel.DEBUG) {
86620
86694
  window.setReauthFail = (fail) => {
86621
86695
  window.isReauthError = fail;
@@ -86716,7 +86790,7 @@ ${data2.flowchartText}
86716
86790
  });
86717
86791
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
86718
86792
  OnesEditorToolbar.register(editor);
86719
- editor.version = "2.1.1-beta.74";
86793
+ editor.version = "2.1.1-beta.75";
86720
86794
  return editor;
86721
86795
  }
86722
86796
  async function showDocVersions(editor, options, serverUrl) {
@@ -132723,6 +132797,7 @@ ${data2.flowchartText}
132723
132797
  exports2.editorReplaceBlockText = editorReplaceBlockText;
132724
132798
  exports2.editorReplaceContainer = editorReplaceContainer;
132725
132799
  exports2.editorRunOnce = editorRunOnce;
132800
+ exports2.editorScrollIntoView = editorScrollIntoView;
132726
132801
  exports2.editorSelectAll = editorSelectAll;
132727
132802
  exports2.editorSelectContainer = editorSelectContainer;
132728
132803
  exports2.editorSelectDown = editorSelectDown;
@@ -132881,6 +132956,7 @@ ${data2.flowchartText}
132881
132956
  exports2.getTextOpLength = getTextOpLength;
132882
132957
  exports2.getTextWidth = getTextWidth;
132883
132958
  exports2.getToolbar = getToolbar;
132959
+ exports2.getVisualViewportHeightOffset = getVisualViewportHeightOffset;
132884
132960
  exports2.groupEachCommand = groupEachCommand;
132885
132961
  exports2.handleBlockElementUpdated = handleBlockElementUpdated$1;
132886
132962
  exports2.hasAltOnly = hasAltOnly;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.1.1-beta.74",
3
+ "version": "2.1.1-beta.75",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",