@ones-editor/editor 2.1.1-beta.77 → 2.1.1-beta.78

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.
@@ -17,7 +17,7 @@ export declare class ReadonlyToolbar implements OnesEditorCustom {
17
17
  isInBlock(block: BlockElement, event: MouseEvent): boolean;
18
18
  handleButtonClick: (toolbar: AbstractCommandBar, item: CommandItem) => void;
19
19
  handleClose: () => void;
20
- handleClosing: (bar: unknown, event: MouseEvent) => boolean;
20
+ handleClosing: (bar: unknown, event: MouseEvent | TouchEvent) => boolean;
21
21
  bindEvents(): void;
22
22
  unbindEvents(): void;
23
23
  handleDocumentMouseDown: (event: MouseEvent) => void;
@@ -23,7 +23,7 @@ export default class OnesEditorToolbar implements OnesEditorHoveringBlockFilter,
23
23
  isInBlock(block: BlockElement, event: MouseEvent): boolean;
24
24
  handleButtonClick: (toolbar: AbstractCommandBar, item: CommandItem) => void;
25
25
  handleClose: () => void;
26
- handleClosing: (bar: unknown, event: MouseEvent) => boolean;
26
+ handleClosing: (bar: unknown, event: MouseEvent | TouchEvent) => boolean;
27
27
  bindEvents(): void;
28
28
  unbindEvents(): void;
29
29
  handleDocumentMouseDown: (event: MouseEvent) => void;
@@ -22,7 +22,7 @@ export default abstract class CommandBar extends TypedEmitter<CommandBarEvents>
22
22
  get isSubCommandBar(): boolean;
23
23
  updateItems(items: CommandItem[]): void;
24
24
  handleDocumentKeydown: (event: KeyboardEvent) => boolean;
25
- protected handleDocumentMouseDown: (event: MouseEvent) => void;
25
+ protected handleDocumentMouseDown: (event: MouseEvent | TouchEvent) => void;
26
26
  protected handleHidden: () => void;
27
27
  protected handleShown: () => void;
28
28
  protected handleShow: () => void;
@@ -8,7 +8,7 @@ export interface CommandBarEvents {
8
8
  'click': (bar: AbstractCommandBar, item: CommandItem, elem: HTMLElement) => void;
9
9
  'close': (bar: AbstractCommandBar) => void;
10
10
  'selectionChange': (bar: AbstractCommandBar, id: string) => void;
11
- 'closing': (bar: AbstractCommandBar, event: MouseEvent) => boolean | undefined;
11
+ 'closing': (bar: AbstractCommandBar, event: MouseEvent | TouchEvent) => boolean | undefined;
12
12
  'subBarShown': (bar: AbstractCommandBar, subBar: AbstractCommandBar) => void;
13
13
  }
14
14
  export interface ManualShowCommandBarOptions {
@@ -20,6 +20,6 @@ export default class ManualCloseDialog extends ManualCommandBar {
20
20
  getReferenceClientRect?: GetReferenceClientRect | null | undefined;
21
21
  }): void;
22
22
  get dialogContent(): HTMLElement | ((item: CommandItem) => HTMLElement);
23
- handleDocumentMouseDown: (event: MouseEvent) => void;
23
+ handleDocumentMouseDown: () => void;
24
24
  static getCommandItems(content: HTMLElement, options?: ManualCloseDialogOptions): CommandItem[];
25
25
  }
package/dist/index.js CHANGED
@@ -2641,6 +2641,12 @@ div.editor-root div.editor-content div[data-type=editor-container] div[data-type
2641
2641
  div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] > span.math-box .mathjax-tex-text.mathjax-error {
2642
2642
  color: var(--color-0);
2643
2643
  }
2644
+ div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] img.mathjax {
2645
+ -webkit-touch-callout: none;
2646
+ }
2647
+ div.editor-root.readonly div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] img.mathjax {
2648
+ -webkit-touch-callout: default;
2649
+ }
2644
2650
  div.editor-root div.editor-content div[data-type=editor-container] .embed-block.selected[data-embed-type=math] > div[data-type=block-content].mathjax-overflow::before {
2645
2651
  width: var(--mathjax-width, "100%");
2646
2652
  }
@@ -8955,25 +8961,13 @@ var __publicField = (obj, key, value) => {
8955
8961
  elem.removeEventListener("click", simulateDoubleClick);
8956
8962
  };
8957
8963
  }
8958
- const getVisualViewportHeightOffset = () => {
8959
- var _a, _b;
8960
- if (!clientType.isMobile) {
8961
- return 0;
8962
- }
8963
- let topWindow = window;
8964
- if (window.top) {
8965
- topWindow = window.top;
8966
- }
8967
- const visualViewportHeight = (_b = (_a = topWindow.visualViewport) == null ? void 0 : _a.height) != null ? _b : topWindow.innerHeight || topWindow.document.documentElement.clientHeight;
8968
- return Math.max(topWindow.innerHeight - visualViewportHeight + 40, 40);
8969
- };
8970
8964
  class ScrollDomElement {
8971
8965
  constructor(element) {
8972
8966
  __publicField(this, "element");
8973
8967
  this.element = element;
8974
8968
  }
8975
8969
  getClientHeight() {
8976
- return this.element.clientHeight - getVisualViewportHeightOffset();
8970
+ return this.element.clientHeight;
8977
8971
  }
8978
8972
  getHorizontalScroll() {
8979
8973
  return this.element.scrollLeft;
@@ -9073,7 +9067,7 @@ var __publicField = (obj, key, value) => {
9073
9067
  verticalOffset: 0
9074
9068
  };
9075
9069
  async function animateScrollTo(numberOrCoordsOrElement, userOptions = {}) {
9076
- var _a, _b;
9070
+ var _a, _b, _c, _d;
9077
9071
  if (!WINDOW_EXISTS) {
9078
9072
  return new Promise((resolve) => {
9079
9073
  resolve(false);
@@ -9140,10 +9134,11 @@ var __publicField = (obj, key, value) => {
9140
9134
  const maxVerticalScroll = elementToScroll.getMaxVerticalScroll();
9141
9135
  const initialVerticalScroll = elementToScroll.getVerticalScroll();
9142
9136
  if (!options.verticalOffset) {
9137
+ const clientHeight = (_d = (_c = options.getClientHeight) == null ? void 0 : _c.call(options)) != null ? _d : elementToScroll.getClientHeight();
9143
9138
  if (initialVerticalScroll < y) {
9144
- y -= elementToScroll.getClientHeight() * 3 / 4;
9139
+ y -= clientHeight * 3 / 4;
9145
9140
  } else {
9146
- y -= elementToScroll.getClientHeight() * 1 / 4;
9141
+ y -= clientHeight * 1 / 4;
9147
9142
  }
9148
9143
  }
9149
9144
  if (y > maxVerticalScroll) {
@@ -25044,10 +25039,9 @@ var __publicField = (obj, key, value) => {
25044
25039
  const x1 = rect.x < 0 ? 0 : rect.x;
25045
25040
  const y1 = rect.y < 0 ? 0 : rect.y;
25046
25041
  const x2 = rect.right > window.innerWidth ? window.innerWidth : rect.right;
25047
- let y2 = rect.bottom > window.innerHeight ? window.innerHeight : rect.bottom;
25048
- if (clientType.isIOS) {
25049
- y2 -= getVisualViewportHeightOffset();
25050
- }
25042
+ const mobileClient = editor.options.componentsOptions.mobile;
25043
+ const innerHeight = clientType.isMobile ? mobileClient.getViewPortHeight() : window.innerHeight;
25044
+ const y2 = rect.bottom > innerHeight ? innerHeight : rect.bottom;
25051
25045
  return new DOMRect(x1, y1, x2 - x1, y2 - y1);
25052
25046
  }
25053
25047
  function isBlockPositionVisible(editor, pos) {
@@ -25103,10 +25097,12 @@ var __publicField = (obj, key, value) => {
25103
25097
  disableHorizontal: false
25104
25098
  });
25105
25099
  }
25100
+ const mobileClient = editor.options.componentsOptions.mobile;
25106
25101
  animateScrollTo(target, {
25107
25102
  elementToScroll: (_a = options.elementToScroll) != null ? _a : getScrollContainer$1(target),
25108
25103
  disableHorizontal: true,
25109
- verticalOffset: options == null ? void 0 : options.verticalOffset
25104
+ verticalOffset: options == null ? void 0 : options.verticalOffset,
25105
+ getClientHeight: mobileClient && clientType.isMobile ? mobileClient.getViewPortHeight : void 0
25110
25106
  });
25111
25107
  } else if (target.scrollIntoView) {
25112
25108
  target.scrollIntoView({
@@ -40161,7 +40157,11 @@ ${codeText}
40161
40157
  });
40162
40158
  parent.appendChild(this.content);
40163
40159
  document.addEventListener("keydown", this.handleDocumentKeydown);
40164
- document.addEventListener("mousedown", this.handleDocumentMouseDown);
40160
+ if (clientType.isMobile) {
40161
+ document.addEventListener("touchend", this.handleDocumentMouseDown);
40162
+ } else {
40163
+ document.addEventListener("mousedown", this.handleDocumentMouseDown);
40164
+ }
40165
40165
  }
40166
40166
  initCommandBarElement(elem) {
40167
40167
  addClass(elem, "toolbar", "fixed");
@@ -40184,6 +40184,7 @@ ${codeText}
40184
40184
  super.destroy();
40185
40185
  document.removeEventListener("keydown", this.handleDocumentKeydown);
40186
40186
  document.removeEventListener("mousedown", this.handleDocumentMouseDown);
40187
+ document.removeEventListener("touchend", this.handleDocumentMouseDown);
40187
40188
  }
40188
40189
  getCommandBarRoot() {
40189
40190
  return this.content.parentElement;
@@ -40203,7 +40204,7 @@ ${codeText}
40203
40204
  disablePageScroll: true,
40204
40205
  ...options
40205
40206
  });
40206
- __publicField(this, "handleDocumentMouseDown", (event) => {
40207
+ __publicField(this, "handleDocumentMouseDown", () => {
40207
40208
  });
40208
40209
  }
40209
40210
  initCommandBarElement(elem) {
@@ -40356,7 +40357,7 @@ ${codeText}
40356
40357
  });
40357
40358
  this.clearSelectedItem();
40358
40359
  document.addEventListener("keydown", this.handleDocumentKeydown);
40359
- document.addEventListener("mousedown", this.handleDocumentMouseDown);
40360
+ document.addEventListener("touchend", this.handleDocumentMouseDown);
40360
40361
  setTimeout(() => {
40361
40362
  var _a2, _b2;
40362
40363
  const rect = document.body.clientHeight;
@@ -40382,6 +40383,8 @@ ${codeText}
40382
40383
  (_a = this.tippyInstance) == null ? void 0 : _a.destroy();
40383
40384
  this.tippyInstance = null;
40384
40385
  super.destroy();
40386
+ document.removeEventListener("keydown", this.handleDocumentKeydown);
40387
+ document.removeEventListener("touchend", this.handleDocumentMouseDown);
40385
40388
  }
40386
40389
  get isVisible() {
40387
40390
  var _a, _b;
@@ -41955,8 +41958,15 @@ ${codeText}
41955
41958
  if (popperRect) {
41956
41959
  const bottom = activeRect.reduce((acc, cur) => acc > cur.bottom ? acc : cur.bottom, 0);
41957
41960
  if (bottom > popperRect.top) {
41958
- const scrollContainer = editor.scrollContainer;
41959
- scrollContainer.scrollTop += bottom - popperRect.top + 20;
41961
+ const scrollContainer2 = editor.scrollContainer;
41962
+ scrollContainer2.scrollTop += bottom - popperRect.top + 20;
41963
+ return;
41964
+ }
41965
+ const top = activeRect.reduce((acc, cur) => acc < cur.top ? acc : cur.top, Infinity);
41966
+ const scrollContainer = editor.scrollContainer;
41967
+ const containerRect = scrollContainer.getBoundingClientRect();
41968
+ if (top < containerRect.top) {
41969
+ scrollContainer.scrollTop -= containerRect.top - top + 20;
41960
41970
  }
41961
41971
  }
41962
41972
  };
@@ -50046,7 +50056,7 @@ ${codeText}
50046
50056
  return [
50047
50057
  {
50048
50058
  id: "insert-link",
50049
- name: clientType.isMobile ? i18n$1.t("link.title") : i18n$1.t("quickMenu.inlineBox.link"),
50059
+ name: i18n$1.t("quickMenu.inlineBox.link"),
50050
50060
  icon: LinkIcon,
50051
50061
  states: [],
50052
50062
  subText: getShortcutById("insert-link")
@@ -59121,7 +59131,13 @@ $$${mathData.mathjaxText}$$
59121
59131
  return this.editProvider.getAvailableCommands(editor, block, range, { child });
59122
59132
  }
59123
59133
  if (((_b = this.options) == null ? void 0 : _b.linkMode) === "insert" && !child) {
59124
- return this.insertProvider.getAvailableCommands(editor, block, range, { ...params, isFilter: true });
59134
+ const commands = this.insertProvider.getAvailableCommands(editor, block, range, { ...params, isFilter: true });
59135
+ commands.forEach((command) => {
59136
+ if (command.id === "insert-link") {
59137
+ command.name = i18n$1.t("link.title");
59138
+ }
59139
+ });
59140
+ return commands;
59125
59141
  }
59126
59142
  return [];
59127
59143
  });
@@ -62401,6 +62417,7 @@ ${codeText}
62401
62417
  return editor.addCustom("markdown-converter-interceptors", () => new MarkdownConverterInterceptors());
62402
62418
  }
62403
62419
  }
62420
+ const DISABLE_MOBILE_CONVERTERS = ["mermaid", "flowchart", "plantuml"];
62404
62421
  const ENTER_CONVERTER = {
62405
62422
  mermaid: {
62406
62423
  blockType: "embed",
@@ -62527,6 +62544,9 @@ ${codeText}
62527
62544
  const block = editor.getBlockByIndex(containerId, blockIndex);
62528
62545
  const text2 = toPlainText(splitText(editor.getBlockText(block), offset).left);
62529
62546
  const converters = type === "enter" ? ENTER_CONVERTER : SPACE_CONVERTER;
62547
+ DISABLE_MOBILE_CONVERTERS.forEach((key) => {
62548
+ delete converters[key];
62549
+ });
62530
62550
  for (const [, converter] of Object.entries(converters)) {
62531
62551
  if (!text2.match(converter.reg))
62532
62552
  continue;
@@ -69754,7 +69774,8 @@ ${codeText}
69754
69774
  return editor.undoManager.runInGroup(() => {
69755
69775
  var _a, _b;
69756
69776
  const item = options.item;
69757
- const cols = (_a = item.colCount) != null ? _a : 5;
69777
+ const defaultColCount = clientType.isMobile ? 3 : 5;
69778
+ const cols = (_a = item.colCount) != null ? _a : defaultColCount;
69758
69779
  const rows = (_b = item.rowCount) != null ? _b : 3;
69759
69780
  const ret = createEmptyTableData(editor, { cols, rows });
69760
69781
  if (!ret) {
@@ -80074,26 +80095,29 @@ ${content}
80074
80095
  constructor(editor) {
80075
80096
  __publicField(this, "commandBar");
80076
80097
  __publicField(this, "observer");
80098
+ __publicField(this, "timer");
80099
+ __publicField(this, "mobileClient");
80077
80100
  __publicField(this, "toggleDelay", clientType.isSafari ? 800 : 100);
80078
- __publicField(this, "preHeight", this.virtualViewportHeight);
80101
+ __publicField(this, "preHeight", 0);
80079
80102
  __publicField(this, "layoutBar", debounce__default.default(() => {
80080
- const offsetHeight = Math.max(this.clientHeight - this.virtualViewportHeight, 0);
80081
- if (clientType.isIOS) {
80082
- if (this.preHeight > this.virtualViewportHeight) {
80103
+ var _a, _b, _c, _d, _e;
80104
+ const offsetHeight = (_b = (_a = this.mobileClient) == null ? void 0 : _a.getOffsetHeight()) != null ? _b : 0;
80105
+ if (clientType.isIOS && this.mobileClient) {
80106
+ if (this.preHeight > this.mobileClient.virtualViewportHeight) {
80083
80107
  editorScrollIntoView(this.editor);
80084
80108
  }
80085
80109
  }
80086
80110
  this.commandBar.bar.style.bottom = `${offsetHeight}px`;
80087
- if (this.preHeight !== this.virtualViewportHeight) {
80111
+ if (this.preHeight !== ((_c = this.mobileClient) == null ? void 0 : _c.virtualViewportHeight)) {
80088
80112
  this.commandBar.layoutSubBar();
80089
80113
  }
80090
- this.preHeight = this.virtualViewportHeight;
80114
+ this.preHeight = (_e = (_d = this.mobileClient) == null ? void 0 : _d.virtualViewportHeight) != null ? _e : 0;
80091
80115
  }, this.toggleDelay));
80092
80116
  __publicField(this, "handScroll", debounce__default.default(() => {
80093
80117
  const input2 = this.editor.input.getInput();
80094
- if (input2) {
80118
+ if (input2 && this.mobileClient) {
80095
80119
  const inputRect = input2.getBoundingClientRect();
80096
- if (inputRect.bottom > this.virtualViewportHeight || inputRect.top < 0) {
80120
+ if (inputRect.bottom > this.mobileClient.virtualViewportHeight || inputRect.top < 0) {
80097
80121
  input2.style.top = `${this.editor.scrollContainer.scrollTop}px`;
80098
80122
  }
80099
80123
  }
@@ -80104,6 +80128,7 @@ ${content}
80104
80128
  __publicField(this, "handleFocusOut", () => {
80105
80129
  this.layoutBar();
80106
80130
  });
80131
+ var _a, _b;
80107
80132
  this.editor = editor;
80108
80133
  this.commandBar = new MobileToolbarHandler(editor, document.body);
80109
80134
  this.observer = new ActiveElementObserver({
@@ -80112,23 +80137,19 @@ ${content}
80112
80137
  });
80113
80138
  this.layoutBar();
80114
80139
  this.editor.scrollContainer.addEventListener("scroll", this.handScroll);
80115
- }
80116
- get window() {
80117
- if (window.top) {
80118
- return window.top;
80140
+ this.mobileClient = this.editor.options.componentsOptions.mobile;
80141
+ this.preHeight = (_b = (_a = this.mobileClient) == null ? void 0 : _a.virtualViewportHeight) != null ? _b : 0;
80142
+ if (clientType.isAndroid) {
80143
+ this.timer = setInterval(() => {
80144
+ var _a2, _b2;
80145
+ if (((_a2 = this.mobileClient) == null ? void 0 : _a2.virtualViewportHeight) !== this.preHeight || ((_b2 = this.mobileClient) == null ? void 0 : _b2.virtualViewportOffsetTop) !== 0) {
80146
+ this.layoutBar();
80147
+ }
80148
+ }, 1e3);
80119
80149
  }
80120
- return window;
80121
- }
80122
- get virtualViewportHeight() {
80123
- var _a, _b;
80124
- const virtualViewportHeight = (_b = (_a = this.window.visualViewport) == null ? void 0 : _a.height) != null ? _b : this.clientHeight;
80125
- return virtualViewportHeight;
80126
- }
80127
- get clientHeight() {
80128
- const clientHeight = this.window.document.body.clientHeight;
80129
- return clientHeight;
80130
80150
  }
80131
80151
  destroy() {
80152
+ clearInterval(this.timer);
80132
80153
  this.observer.destroy();
80133
80154
  this.commandBar.destroy();
80134
80155
  this.editor.scrollContainer.removeEventListener("scroll", this.handScroll);
@@ -80216,7 +80237,6 @@ ${content}
80216
80237
  return false;
80217
80238
  }
80218
80239
  if (!range.isSimple()) {
80219
- this.editor.selection.setRange(range);
80220
80240
  return true;
80221
80241
  }
80222
80242
  const block = this.editor.getBlockById(range.start.blockId);
@@ -86719,7 +86739,7 @@ ${data2.flowchartText}
86719
86739
  }
86720
86740
  }
86721
86741
  });
86722
- editor.version = "2.1.1-beta.77";
86742
+ editor.version = "2.1.1-beta.78";
86723
86743
  if (Logger$2.level === LogLevel.DEBUG) {
86724
86744
  window.setReauthFail = (fail) => {
86725
86745
  window.isReauthError = fail;
@@ -86820,7 +86840,7 @@ ${data2.flowchartText}
86820
86840
  });
86821
86841
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
86822
86842
  OnesEditorToolbar.register(editor);
86823
- editor.version = "2.1.1-beta.77";
86843
+ editor.version = "2.1.1-beta.78";
86824
86844
  return editor;
86825
86845
  }
86826
86846
  async function showDocVersions(editor, options, serverUrl) {
@@ -132986,7 +133006,6 @@ ${data2.flowchartText}
132986
133006
  exports2.getTextOpLength = getTextOpLength;
132987
133007
  exports2.getTextWidth = getTextWidth;
132988
133008
  exports2.getToolbar = getToolbar;
132989
- exports2.getVisualViewportHeightOffset = getVisualViewportHeightOffset;
132990
133009
  exports2.groupEachCommand = groupEachCommand;
132991
133010
  exports2.handleBlockElementUpdated = handleBlockElementUpdated$1;
132992
133011
  exports2.hasAltOnly = hasAltOnly;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Embed, Box, i18n, OnesEditor, OnesEditorUser, OnesEditorUserPermission, OnesEditorBlockHook, OnesEditorCommandProvider, LogLevel, Block, ShortcutRecords, OnesEditorBlockRenderer, BuildResourceUrlOptions, UploadResourceOptions, UploadResourceResult } from '../@ones-editor/core';
1
+ import { Embed, Box, i18n, OnesEditor, OnesEditorUser, OnesEditorUserPermission, OnesEditorBlockHook, OnesEditorCommandProvider, LogLevel, Block, ShortcutRecords, OnesEditorBlockRenderer, BuildResourceUrlOptions, UploadResourceOptions, UploadResourceResult, MobileClient } from '../@ones-editor/core';
2
2
  import { DrawIoOptions } from '../@ones-editor/drawio-embed';
3
3
  import { FlowCharEmbedOptions, MermaidEmbedOptions, PlantumlEmbedOptions } from '../@ones-editor/graph-embed';
4
4
  import { ImageOptions } from '../@ones-editor/image-embed';
@@ -42,6 +42,7 @@ export type EditorComponentOptions = {
42
42
  mathjax?: MathjaxOptions;
43
43
  link?: LinkOptions;
44
44
  columns?: EditorConfigLayoutOptions;
45
+ mobile?: MobileClient;
45
46
  };
46
47
  export type EditorEvents = {
47
48
  onClickLink?: (editor: OnesEditor, event: MouseEvent, link: Element) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.1.1-beta.77",
3
+ "version": "2.1.1-beta.78",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",