@ones-editor/editor 1.2.0-beta.7 → 1.2.0-beta.9

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/dist/index.js CHANGED
@@ -6080,18 +6080,18 @@ div.editor-root div.editor-content div[data-type=editor-container] div[data-embe
6080
6080
  width: 100%;
6081
6081
  display: flex;
6082
6082
  flex-direction: column;
6083
- align-items: center;
6083
+ align-items: start;
6084
6084
  background-color: antiquewhite;
6085
6085
  gap: 20px;
6086
6086
  padding: 0 20px;
6087
6087
  flex-wrap: wrap;
6088
+ overflow-x: auto;
6088
6089
  }
6089
6090
  .command-m-bar .command-m-container {
6090
6091
  display: flex;
6091
- width: 100%;
6092
6092
  }
6093
6093
  .command-m-bar .command-item {
6094
- width: 40px;
6094
+ width: 80px;
6095
6095
  height: 40px;
6096
6096
  display: flex;
6097
6097
  align-items: center;
@@ -7429,6 +7429,36 @@ var __publicField = (obj, key, value) => {
7429
7429
  });
7430
7430
  return elem || document.body;
7431
7431
  }
7432
+ function ensureIsMobileEvent$1(events2) {
7433
+ return clientType.isMobile;
7434
+ }
7435
+ function createMouseEventFromTouchEvent(event, type) {
7436
+ const touch = event.changedTouches[0];
7437
+ const mouseEvent = new MouseEvent("mousedown", {
7438
+ bubbles: true,
7439
+ cancelable: true,
7440
+ clientX: touch.clientX,
7441
+ clientY: touch.clientY,
7442
+ screenX: touch.screenX,
7443
+ screenY: touch.screenY,
7444
+ button: 0
7445
+ });
7446
+ Object.defineProperty(mouseEvent, "target", { value: event.target, enumerable: true });
7447
+ return mouseEvent;
7448
+ }
7449
+ function bindTouchEnd(elem, callback) {
7450
+ let isMove = false;
7451
+ window.addEventListener("touchmove", () => {
7452
+ isMove = true;
7453
+ });
7454
+ window.addEventListener("touchend", (e2) => {
7455
+ if (isMove) {
7456
+ e2.stopPropagation();
7457
+ }
7458
+ isMove = false;
7459
+ }, true);
7460
+ elem.addEventListener("touchend", callback);
7461
+ }
7432
7462
  class ScrollDomElement {
7433
7463
  constructor(element) {
7434
7464
  __publicField(this, "element");
@@ -9845,6 +9875,9 @@ var __publicField = (obj, key, value) => {
9845
9875
  }
9846
9876
  const logger$3W = getLogger("root-container");
9847
9877
  const MIN_DISTANCE_THRESHOLD = 3;
9878
+ function ensureIsMobileEvent(events2) {
9879
+ return events2 instanceof TouchEvent;
9880
+ }
9848
9881
  class RootContainer {
9849
9882
  constructor(editor, rootContainer) {
9850
9883
  __publicField(this, "resizeObserver");
@@ -9867,19 +9900,25 @@ var __publicField = (obj, key, value) => {
9867
9900
  }
9868
9901
  });
9869
9902
  __publicField(this, "handleClick", (event) => {
9870
- this.editor.emit("click", this.editor, event);
9871
- const target = event.target;
9903
+ if (!this.mouseDownEvent)
9904
+ return;
9905
+ const mouseEvent = ensureIsMobileEvent(event) ? createMouseEventFromTouchEvent(event) : event;
9906
+ this.editor.emit("click", this.editor, mouseEvent);
9907
+ const target = ensureIsMobileEvent(this.mouseDownEvent) ? this.mouseDownEvent.changedTouches[0].target : this.mouseDownEvent.target;
9872
9908
  if (isInBlockTools(target)) {
9909
+ this.mouseDownEvent = null;
9873
9910
  return;
9874
9911
  }
9875
- if (event.detail === 1) {
9912
+ if (event.detail === 1 || clientType.isMobile) {
9876
9913
  this.editor.input.focus();
9877
9914
  }
9878
- if (event.detail === 3) {
9915
+ if (!ensureIsMobileEvent(event) && event.detail === 3) {
9879
9916
  this.editor.selectionHandler.handleTripleClick(event);
9880
9917
  }
9881
- if (event.detail === 1 && event.button === 0) {
9882
- const elem = getElementFromPoint(event.clientX, event.clientY);
9918
+ if (event.detail === 1 || (ensureIsMobileEvent(event) || event.button === 0)) {
9919
+ const clientX = ensureIsMobileEvent(event) ? event.changedTouches[0].clientX : event.clientX;
9920
+ const clientY = ensureIsMobileEvent(event) ? event.changedTouches[0].clientY : event.clientY;
9921
+ const elem = getElementFromPoint(clientX, clientY);
9883
9922
  if (elem && isChildNode(this.rootContainer, elem)) {
9884
9923
  const block = getParentBlock(elem);
9885
9924
  if (block && isChildNode(block, elem)) {
@@ -9887,17 +9926,19 @@ var __publicField = (obj, key, value) => {
9887
9926
  }
9888
9927
  }
9889
9928
  }
9929
+ this.mouseDownEvent = null;
9890
9930
  });
9891
9931
  __publicField(this, "handleBlockClick", (event, block, elem) => {
9892
9932
  var _a, _b;
9893
9933
  if (!isTextKindBlock(this.editor, block)) {
9894
9934
  return;
9895
9935
  }
9936
+ const mouseEvent = ensureIsMobileEvent(event) ? createMouseEventFromTouchEvent(event) : event;
9896
9937
  const box = getParentBox(elem);
9897
9938
  if (box) {
9898
9939
  const block2 = getParentBlock(box);
9899
9940
  assert(logger$3W, block2, "no parent block");
9900
- (_b = (_a = this.editor.editorBoxes.getBoxClass(getBoxTypeFromElement(box))) == null ? void 0 : _a.handleClickBox) == null ? void 0 : _b.call(_a, this.editor, box, event);
9941
+ (_b = (_a = this.editor.editorBoxes.getBoxClass(getBoxTypeFromElement(box))) == null ? void 0 : _a.handleClickBox) == null ? void 0 : _b.call(_a, this.editor, box, mouseEvent);
9901
9942
  return;
9902
9943
  }
9903
9944
  const link2 = elem.closest("span.text.link");
@@ -9905,7 +9946,7 @@ var __publicField = (obj, key, value) => {
9905
9946
  const children = getTextBlockContentChildren(block);
9906
9947
  const index2 = children.indexOf(link2);
9907
9948
  if (index2 !== -1) {
9908
- this.editor.emit("clickLink", this.editor, event, link2);
9949
+ this.editor.emit("clickLink", this.editor, mouseEvent, link2);
9909
9950
  }
9910
9951
  }
9911
9952
  });
@@ -9929,7 +9970,7 @@ var __publicField = (obj, key, value) => {
9929
9970
  if (isInBlockTools(target)) {
9930
9971
  return;
9931
9972
  }
9932
- if (event.button === 2) {
9973
+ if (!ensureIsMobileEvent(event) && event.button === 2) {
9933
9974
  event.stopPropagation();
9934
9975
  return;
9935
9976
  }
@@ -9939,17 +9980,19 @@ var __publicField = (obj, key, value) => {
9939
9980
  this.editor.input.focus();
9940
9981
  return;
9941
9982
  }
9942
- if (event.button === 0) {
9943
- document.addEventListener("mousemove", this.handleMouseMove);
9944
- document.addEventListener("mouseup", this.handleMouseUp);
9983
+ if (ensureIsMobileEvent(event) || event.button === 0) {
9984
+ if (!clientType.isMobile) {
9985
+ document.addEventListener("mousemove", this.handleMouseMove);
9986
+ document.addEventListener("mouseup", this.handleMouseUp);
9987
+ }
9945
9988
  this.editor.selectionHandler.handleMouseDown(event, { autoScroll: true });
9946
9989
  }
9947
- if (!clientType.isMobileSafari) {
9948
- this.editor.input.focus();
9949
- }
9990
+ this.editor.input.focus();
9950
9991
  });
9951
9992
  __publicField(this, "handleMouseMove", (event) => {
9952
9993
  assert(logger$3W, this.mouseDownEvent, "no mouse down event");
9994
+ if (ensureIsMobileEvent(this.mouseDownEvent))
9995
+ return;
9953
9996
  const deltaX = event.x - this.mouseDownEvent.x;
9954
9997
  const deltaY = event.y - this.mouseDownEvent.y;
9955
9998
  if (Math.abs(deltaX) >= MIN_DISTANCE_THRESHOLD || Math.abs(deltaY) >= MIN_DISTANCE_THRESHOLD) {
@@ -9986,10 +10029,15 @@ var __publicField = (obj, key, value) => {
9986
10029
  bindEvents(rootContainer) {
9987
10030
  this.resizeObserver.observe(rootContainer);
9988
10031
  const container = this.editor.rootElement;
9989
- container.onmousedown = this.handleMouseDown;
10032
+ if (clientType.isMobile) {
10033
+ bindTouchEnd(container, this.handleMouseDown);
10034
+ container.onclick = this.handleClick;
10035
+ } else {
10036
+ container.onmousedown = this.handleMouseDown;
10037
+ container.oncontextmenu = this.handleContextMenu;
10038
+ container.onclick = this.handleClick;
10039
+ }
9990
10040
  container.ondblclick = this.handleDblClick;
9991
- container.onclick = this.handleClick;
9992
- container.oncontextmenu = this.handleContextMenu;
9993
10041
  }
9994
10042
  unbindEvents() {
9995
10043
  this.resizeObserver.disconnect();
@@ -23069,7 +23117,7 @@ var __publicField = (obj, key, value) => {
23069
23117
  input2.addEventListener("compositionend", this.handleCompositionend);
23070
23118
  this.inputElement = input2;
23071
23119
  if (clientType.isMobile) {
23072
- document.addEventListener("touchend", this.handleDocumentClick);
23120
+ bindTouchEnd(document, this.handleDocumentClick);
23073
23121
  } else {
23074
23122
  document.addEventListener("click", this.handleDocumentClick);
23075
23123
  }
@@ -25260,7 +25308,7 @@ var __publicField = (obj, key, value) => {
25260
25308
  if (newEndPos.blockId !== currentBlockId) {
25261
25309
  newEndPos = createSimpleBlockPosition(block, getBlockTextLength$4(editor, block), "end");
25262
25310
  }
25263
- editor.selection.setSelection(newStartPos, newEndPos);
25311
+ editor.selection.setSelection(newStartPos, newEndPos, { noScroll: true });
25264
25312
  }
25265
25313
  function editorFocusToEnd(editor) {
25266
25314
  editorSelectEnd(editor);
@@ -25684,7 +25732,9 @@ var __publicField = (obj, key, value) => {
25684
25732
  __publicField(this, "handleMouseDown", (event, options) => {
25685
25733
  var _a;
25686
25734
  this.mouseDownEvent = event;
25687
- const range = getBlockNearestRangeFromPoint(this.editor, event.x, event.y);
25735
+ const x = ensureIsMobileEvent$1() ? event.changedTouches[0].clientX : event.x;
25736
+ const y = ensureIsMobileEvent$1() ? event.changedTouches[0].clientY : event.y;
25737
+ const range = getBlockNearestRangeFromPoint(this.editor, x, y);
25688
25738
  if (range) {
25689
25739
  if (range instanceof EditorComplexSelectionRange) {
25690
25740
  return;
@@ -25720,6 +25770,8 @@ var __publicField = (obj, key, value) => {
25720
25770
  return;
25721
25771
  if (!this.mouseDownEvent)
25722
25772
  return;
25773
+ if (ensureIsMobileEvent$1(this.mouseDownEvent))
25774
+ return;
25723
25775
  if (Math.abs(this.mouseDownEvent.x - event.x) < 3 && Math.abs(this.mouseDownEvent.y - event.y) < 3) {
25724
25776
  return;
25725
25777
  }
@@ -71961,7 +72013,7 @@ ${codeText}
71961
72013
  __publicField(this, "handleLongPress", (event) => {
71962
72014
  const touch = event.touches[0];
71963
72015
  const range = getBlockRangeFromPoint(this.editor, touch.clientX, touch.clientY);
71964
- if (!range) {
72016
+ if (!range || this.isMoving) {
71965
72017
  return;
71966
72018
  }
71967
72019
  if (!range.isSimple()) {
@@ -71976,7 +72028,12 @@ ${codeText}
71976
72028
  this.editor.selection.selectBlock(block, start.offset);
71977
72029
  editorSelectWord(this.editor);
71978
72030
  });
72031
+ __publicField(this, "isMoving", false);
72032
+ __publicField(this, "handleTouchMove", (event) => {
72033
+ this.isMoving = true;
72034
+ });
71979
72035
  __publicField(this, "handleTouchStart", (event) => {
72036
+ this.isMoving = false;
71980
72037
  if (event.touches.length === 1) {
71981
72038
  this.longPressTimeout = window.setTimeout(() => {
71982
72039
  this.handleLongPress(event);
@@ -71988,11 +72045,13 @@ ${codeText}
71988
72045
  window.clearTimeout(this.longPressTimeout);
71989
72046
  this.longPressTimeout = 0;
71990
72047
  }
72048
+ this.isMoving = false;
71991
72049
  });
71992
72050
  this.editor = editor;
71993
72051
  this.editor.addListener("selectionChanged", this.handleSelectionChange);
71994
72052
  document.addEventListener("touchstart", this.handleTouchStart);
71995
72053
  document.addEventListener("touchend", this.handleTouchEnd);
72054
+ document.addEventListener("touchmove", this.handleTouchMove);
71996
72055
  this.gripper = new SelectionGripper(this.editor);
71997
72056
  }
71998
72057
  destroy() {
@@ -75345,6 +75404,7 @@ ${data.flowchartText}
75345
75404
  });
75346
75405
  __publicField(this, "handleTouchStart", (event, command) => {
75347
75406
  var _a, _b;
75407
+ console.log("handleTouchStart");
75348
75408
  const elem = event.changedTouches[0].target;
75349
75409
  if (!(elem instanceof HTMLElement)) {
75350
75410
  return;
@@ -75364,7 +75424,7 @@ ${data.flowchartText}
75364
75424
  if (command.id === "add") {
75365
75425
  const children = [{ name: "\u6807\u98981" }].map((item) => {
75366
75426
  const childItem = createElement("div", ["child-item"], null, item.name);
75367
- childItem.ontouchstart = () => this.handleChildTouchStart(item);
75427
+ childItem.addEventListener("touchend", () => this.handleChildTouchStart(item));
75368
75428
  return childItem;
75369
75429
  });
75370
75430
  if (!this.layoutMap.has(key)) {
@@ -75376,7 +75436,7 @@ ${data.flowchartText}
75376
75436
  const parent2 = (_b = elem.parentElement) == null ? void 0 : _b.parentElement;
75377
75437
  const children = [{ name: "\u80CC\u666F\u8272" }].map((item) => {
75378
75438
  const childItem = createElement("div", ["child-item"], null, item.name);
75379
- childItem.ontouchstart = () => this.handleChildTouchStart(item);
75439
+ childItem.addEventListener("touchend", () => this.handleChildTouchStart(item));
75380
75440
  return childItem;
75381
75441
  });
75382
75442
  if (!this.layoutMap.has(key)) {
@@ -75389,7 +75449,7 @@ ${data.flowchartText}
75389
75449
  const fragment = document.createDocumentFragment();
75390
75450
  commands.forEach((command) => {
75391
75451
  const elem = createElement("div", ["command-item"], fragment, command.name);
75392
- elem.ontouchstart = (e2) => this.handleTouchStart(e2, command);
75452
+ bindTouchEnd(elem, (e2) => this.handleTouchStart(e2, command));
75393
75453
  });
75394
75454
  container.appendChild(fragment);
75395
75455
  });
@@ -75440,6 +75500,27 @@ ${data.flowchartText}
75440
75500
  }, {
75441
75501
  id: "color",
75442
75502
  name: "A"
75503
+ }, {
75504
+ id: "heading",
75505
+ name: "H"
75506
+ }, {
75507
+ id: "list",
75508
+ name: "L"
75509
+ }, {
75510
+ id: "table",
75511
+ name: "T"
75512
+ }, {
75513
+ id: "checkbox",
75514
+ name: "C"
75515
+ }, {
75516
+ id: "link",
75517
+ name: "L"
75518
+ }, {
75519
+ id: "quote",
75520
+ name: "Q"
75521
+ }, {
75522
+ id: "image",
75523
+ name: "I"
75443
75524
  }]
75444
75525
  });
75445
75526
  document.addEventListener("focusin", this.handleFocusIn);
@@ -76954,7 +77035,7 @@ ${data.flowchartText}
76954
77035
  }
76955
77036
  }
76956
77037
  });
76957
- editor.version = "1.2.0-beta.7";
77038
+ editor.version = "1.2.0-beta.9";
76958
77039
  if (Logger$2.level === LogLevel.DEBUG) {
76959
77040
  window.setReauthFail = (fail) => {
76960
77041
  window.isReauthError = fail;
@@ -77047,7 +77128,7 @@ ${data.flowchartText}
77047
77128
  });
77048
77129
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
77049
77130
  OnesEditorToolbar.register(editor);
77050
- editor.version = "1.2.0-beta.7";
77131
+ editor.version = "1.2.0-beta.9";
77051
77132
  return editor;
77052
77133
  }
77053
77134
  async function showDocVersions(editor, options, serverUrl) {
@@ -77172,6 +77253,7 @@ ${data.flowchartText}
77172
77253
  exports2.assert = assert;
77173
77254
  exports2.autoShowHideTemplates = autoShowHideTemplates;
77174
77255
  exports2.bindKeyDownEvent = bindKeyDownEvent;
77256
+ exports2.bindTouchEnd = bindTouchEnd;
77175
77257
  exports2.blockToDoc = blockToDoc;
77176
77258
  exports2.blockToHtml = blockToHtml;
77177
77259
  exports2.blockToMarkdown = blockToMarkdown;
@@ -77232,6 +77314,7 @@ ${data.flowchartText}
77232
77314
  exports2.createInsertionContentElement = createInsertionContentElement;
77233
77315
  exports2.createInsertionElement = createInsertionElement;
77234
77316
  exports2.createLocalEditor = createLocalEditor;
77317
+ exports2.createMouseEventFromTouchEvent = createMouseEventFromTouchEvent;
77235
77318
  exports2.createOnesEditor = createOnesEditor;
77236
77319
  exports2.createRange = createRange;
77237
77320
  exports2.createRichText = createRichText;
@@ -77323,6 +77406,7 @@ ${data.flowchartText}
77323
77406
  exports2.editorUpdateCompositionText = editorUpdateCompositionText;
77324
77407
  exports2.editorUpdateEmbedData = editorUpdateEmbedData;
77325
77408
  exports2.enablePageScroll = enablePageScroll;
77409
+ exports2.ensureIsMobileEvent = ensureIsMobileEvent$1;
77326
77410
  exports2.escapeHtmlText = escapeHtmlText;
77327
77411
  exports2.escapeRegExp = escapeRegExp;
77328
77412
  exports2.escapeSpace = escapeSpace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "1.2.0-beta.7",
3
+ "version": "1.2.0-beta.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",