@ones-editor/editor 1.2.0-beta.6 → 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,27 +6080,28 @@ 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;
6098
6098
  justify-content: center;
6099
6099
  }
6100
6100
  .command-m-bar .child-layout {
6101
- height: 300px;
6101
+ height: 280px;
6102
6102
  width: 100%;
6103
6103
  display: flex;
6104
+ display: none;
6104
6105
  }
6105
6106
  .command-m-bar .child-layout .child-item {
6106
6107
  width: 80px;
@@ -7428,6 +7429,36 @@ var __publicField = (obj, key, value) => {
7428
7429
  });
7429
7430
  return elem || document.body;
7430
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
+ }
7431
7462
  class ScrollDomElement {
7432
7463
  constructor(element) {
7433
7464
  __publicField(this, "element");
@@ -9844,6 +9875,9 @@ var __publicField = (obj, key, value) => {
9844
9875
  }
9845
9876
  const logger$3W = getLogger("root-container");
9846
9877
  const MIN_DISTANCE_THRESHOLD = 3;
9878
+ function ensureIsMobileEvent(events2) {
9879
+ return events2 instanceof TouchEvent;
9880
+ }
9847
9881
  class RootContainer {
9848
9882
  constructor(editor, rootContainer) {
9849
9883
  __publicField(this, "resizeObserver");
@@ -9866,19 +9900,25 @@ var __publicField = (obj, key, value) => {
9866
9900
  }
9867
9901
  });
9868
9902
  __publicField(this, "handleClick", (event) => {
9869
- this.editor.emit("click", this.editor, event);
9870
- 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;
9871
9908
  if (isInBlockTools(target)) {
9909
+ this.mouseDownEvent = null;
9872
9910
  return;
9873
9911
  }
9874
- if (event.detail === 1) {
9912
+ if (event.detail === 1 || clientType.isMobile) {
9875
9913
  this.editor.input.focus();
9876
9914
  }
9877
- if (event.detail === 3) {
9915
+ if (!ensureIsMobileEvent(event) && event.detail === 3) {
9878
9916
  this.editor.selectionHandler.handleTripleClick(event);
9879
9917
  }
9880
- if (event.detail === 1 && event.button === 0) {
9881
- 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);
9882
9922
  if (elem && isChildNode(this.rootContainer, elem)) {
9883
9923
  const block = getParentBlock(elem);
9884
9924
  if (block && isChildNode(block, elem)) {
@@ -9886,17 +9926,19 @@ var __publicField = (obj, key, value) => {
9886
9926
  }
9887
9927
  }
9888
9928
  }
9929
+ this.mouseDownEvent = null;
9889
9930
  });
9890
9931
  __publicField(this, "handleBlockClick", (event, block, elem) => {
9891
9932
  var _a, _b;
9892
9933
  if (!isTextKindBlock(this.editor, block)) {
9893
9934
  return;
9894
9935
  }
9936
+ const mouseEvent = ensureIsMobileEvent(event) ? createMouseEventFromTouchEvent(event) : event;
9895
9937
  const box = getParentBox(elem);
9896
9938
  if (box) {
9897
9939
  const block2 = getParentBlock(box);
9898
9940
  assert(logger$3W, block2, "no parent block");
9899
- (_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);
9900
9942
  return;
9901
9943
  }
9902
9944
  const link2 = elem.closest("span.text.link");
@@ -9904,7 +9946,7 @@ var __publicField = (obj, key, value) => {
9904
9946
  const children = getTextBlockContentChildren(block);
9905
9947
  const index2 = children.indexOf(link2);
9906
9948
  if (index2 !== -1) {
9907
- this.editor.emit("clickLink", this.editor, event, link2);
9949
+ this.editor.emit("clickLink", this.editor, mouseEvent, link2);
9908
9950
  }
9909
9951
  }
9910
9952
  });
@@ -9928,7 +9970,7 @@ var __publicField = (obj, key, value) => {
9928
9970
  if (isInBlockTools(target)) {
9929
9971
  return;
9930
9972
  }
9931
- if (event.button === 2) {
9973
+ if (!ensureIsMobileEvent(event) && event.button === 2) {
9932
9974
  event.stopPropagation();
9933
9975
  return;
9934
9976
  }
@@ -9938,17 +9980,19 @@ var __publicField = (obj, key, value) => {
9938
9980
  this.editor.input.focus();
9939
9981
  return;
9940
9982
  }
9941
- if (event.button === 0) {
9942
- document.addEventListener("mousemove", this.handleMouseMove);
9943
- 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
+ }
9944
9988
  this.editor.selectionHandler.handleMouseDown(event, { autoScroll: true });
9945
9989
  }
9946
- if (!clientType.isMobileSafari) {
9947
- this.editor.input.focus();
9948
- }
9990
+ this.editor.input.focus();
9949
9991
  });
9950
9992
  __publicField(this, "handleMouseMove", (event) => {
9951
9993
  assert(logger$3W, this.mouseDownEvent, "no mouse down event");
9994
+ if (ensureIsMobileEvent(this.mouseDownEvent))
9995
+ return;
9952
9996
  const deltaX = event.x - this.mouseDownEvent.x;
9953
9997
  const deltaY = event.y - this.mouseDownEvent.y;
9954
9998
  if (Math.abs(deltaX) >= MIN_DISTANCE_THRESHOLD || Math.abs(deltaY) >= MIN_DISTANCE_THRESHOLD) {
@@ -9985,10 +10029,15 @@ var __publicField = (obj, key, value) => {
9985
10029
  bindEvents(rootContainer) {
9986
10030
  this.resizeObserver.observe(rootContainer);
9987
10031
  const container = this.editor.rootElement;
9988
- 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
+ }
9989
10040
  container.ondblclick = this.handleDblClick;
9990
- container.onclick = this.handleClick;
9991
- container.oncontextmenu = this.handleContextMenu;
9992
10041
  }
9993
10042
  unbindEvents() {
9994
10043
  this.resizeObserver.disconnect();
@@ -23068,7 +23117,7 @@ var __publicField = (obj, key, value) => {
23068
23117
  input2.addEventListener("compositionend", this.handleCompositionend);
23069
23118
  this.inputElement = input2;
23070
23119
  if (clientType.isMobile) {
23071
- document.addEventListener("touchend", this.handleDocumentClick);
23120
+ bindTouchEnd(document, this.handleDocumentClick);
23072
23121
  } else {
23073
23122
  document.addEventListener("click", this.handleDocumentClick);
23074
23123
  }
@@ -25259,7 +25308,7 @@ var __publicField = (obj, key, value) => {
25259
25308
  if (newEndPos.blockId !== currentBlockId) {
25260
25309
  newEndPos = createSimpleBlockPosition(block, getBlockTextLength$4(editor, block), "end");
25261
25310
  }
25262
- editor.selection.setSelection(newStartPos, newEndPos);
25311
+ editor.selection.setSelection(newStartPos, newEndPos, { noScroll: true });
25263
25312
  }
25264
25313
  function editorFocusToEnd(editor) {
25265
25314
  editorSelectEnd(editor);
@@ -25683,7 +25732,9 @@ var __publicField = (obj, key, value) => {
25683
25732
  __publicField(this, "handleMouseDown", (event, options) => {
25684
25733
  var _a;
25685
25734
  this.mouseDownEvent = event;
25686
- 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);
25687
25738
  if (range) {
25688
25739
  if (range instanceof EditorComplexSelectionRange) {
25689
25740
  return;
@@ -25719,6 +25770,8 @@ var __publicField = (obj, key, value) => {
25719
25770
  return;
25720
25771
  if (!this.mouseDownEvent)
25721
25772
  return;
25773
+ if (ensureIsMobileEvent$1(this.mouseDownEvent))
25774
+ return;
25722
25775
  if (Math.abs(this.mouseDownEvent.x - event.x) < 3 && Math.abs(this.mouseDownEvent.y - event.y) < 3) {
25723
25776
  return;
25724
25777
  }
@@ -71960,7 +72013,7 @@ ${codeText}
71960
72013
  __publicField(this, "handleLongPress", (event) => {
71961
72014
  const touch = event.touches[0];
71962
72015
  const range = getBlockRangeFromPoint(this.editor, touch.clientX, touch.clientY);
71963
- if (!range) {
72016
+ if (!range || this.isMoving) {
71964
72017
  return;
71965
72018
  }
71966
72019
  if (!range.isSimple()) {
@@ -71975,7 +72028,12 @@ ${codeText}
71975
72028
  this.editor.selection.selectBlock(block, start.offset);
71976
72029
  editorSelectWord(this.editor);
71977
72030
  });
72031
+ __publicField(this, "isMoving", false);
72032
+ __publicField(this, "handleTouchMove", (event) => {
72033
+ this.isMoving = true;
72034
+ });
71978
72035
  __publicField(this, "handleTouchStart", (event) => {
72036
+ this.isMoving = false;
71979
72037
  if (event.touches.length === 1) {
71980
72038
  this.longPressTimeout = window.setTimeout(() => {
71981
72039
  this.handleLongPress(event);
@@ -71987,11 +72045,13 @@ ${codeText}
71987
72045
  window.clearTimeout(this.longPressTimeout);
71988
72046
  this.longPressTimeout = 0;
71989
72047
  }
72048
+ this.isMoving = false;
71990
72049
  });
71991
72050
  this.editor = editor;
71992
72051
  this.editor.addListener("selectionChanged", this.handleSelectionChange);
71993
72052
  document.addEventListener("touchstart", this.handleTouchStart);
71994
72053
  document.addEventListener("touchend", this.handleTouchEnd);
72054
+ document.addEventListener("touchmove", this.handleTouchMove);
71995
72055
  this.gripper = new SelectionGripper(this.editor);
71996
72056
  }
71997
72057
  destroy() {
@@ -75327,7 +75387,9 @@ ${data.flowchartText}
75327
75387
  __publicField(this, "createLayout", (parent, children) => {
75328
75388
  const layout = new Layout(children);
75329
75389
  layout.appendTo(parent);
75330
- layout.show();
75390
+ setTimeout(() => {
75391
+ layout.show();
75392
+ }, 300);
75331
75393
  return layout;
75332
75394
  });
75333
75395
  __publicField(this, "handleChildTouchStart", (item) => {
@@ -75342,6 +75404,7 @@ ${data.flowchartText}
75342
75404
  });
75343
75405
  __publicField(this, "handleTouchStart", (event, command) => {
75344
75406
  var _a, _b;
75407
+ console.log("handleTouchStart");
75345
75408
  const elem = event.changedTouches[0].target;
75346
75409
  if (!(elem instanceof HTMLElement)) {
75347
75410
  return;
@@ -75353,13 +75416,15 @@ ${data.flowchartText}
75353
75416
  item.hidden();
75354
75417
  } else if (keyd === key) {
75355
75418
  item == null ? void 0 : item.appendTo(parent);
75356
- item.show();
75419
+ setTimeout(() => {
75420
+ item.show();
75421
+ }, 300);
75357
75422
  }
75358
75423
  });
75359
75424
  if (command.id === "add") {
75360
75425
  const children = [{ name: "\u6807\u98981" }].map((item) => {
75361
75426
  const childItem = createElement("div", ["child-item"], null, item.name);
75362
- childItem.ontouchstart = () => this.handleChildTouchStart(item);
75427
+ childItem.addEventListener("touchend", () => this.handleChildTouchStart(item));
75363
75428
  return childItem;
75364
75429
  });
75365
75430
  if (!this.layoutMap.has(key)) {
@@ -75371,7 +75436,7 @@ ${data.flowchartText}
75371
75436
  const parent2 = (_b = elem.parentElement) == null ? void 0 : _b.parentElement;
75372
75437
  const children = [{ name: "\u80CC\u666F\u8272" }].map((item) => {
75373
75438
  const childItem = createElement("div", ["child-item"], null, item.name);
75374
- childItem.ontouchstart = () => this.handleChildTouchStart(item);
75439
+ childItem.addEventListener("touchend", () => this.handleChildTouchStart(item));
75375
75440
  return childItem;
75376
75441
  });
75377
75442
  if (!this.layoutMap.has(key)) {
@@ -75384,7 +75449,7 @@ ${data.flowchartText}
75384
75449
  const fragment = document.createDocumentFragment();
75385
75450
  commands.forEach((command) => {
75386
75451
  const elem = createElement("div", ["command-item"], fragment, command.name);
75387
- elem.ontouchstart = (e2) => this.handleTouchStart(e2, command);
75452
+ bindTouchEnd(elem, (e2) => this.handleTouchStart(e2, command));
75388
75453
  });
75389
75454
  container.appendChild(fragment);
75390
75455
  });
@@ -75435,6 +75500,27 @@ ${data.flowchartText}
75435
75500
  }, {
75436
75501
  id: "color",
75437
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"
75438
75524
  }]
75439
75525
  });
75440
75526
  document.addEventListener("focusin", this.handleFocusIn);
@@ -76949,7 +77035,7 @@ ${data.flowchartText}
76949
77035
  }
76950
77036
  }
76951
77037
  });
76952
- editor.version = "1.2.0-beta.6";
77038
+ editor.version = "1.2.0-beta.9";
76953
77039
  if (Logger$2.level === LogLevel.DEBUG) {
76954
77040
  window.setReauthFail = (fail) => {
76955
77041
  window.isReauthError = fail;
@@ -77042,7 +77128,7 @@ ${data.flowchartText}
77042
77128
  });
77043
77129
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
77044
77130
  OnesEditorToolbar.register(editor);
77045
- editor.version = "1.2.0-beta.6";
77131
+ editor.version = "1.2.0-beta.9";
77046
77132
  return editor;
77047
77133
  }
77048
77134
  async function showDocVersions(editor, options, serverUrl) {
@@ -77167,6 +77253,7 @@ ${data.flowchartText}
77167
77253
  exports2.assert = assert;
77168
77254
  exports2.autoShowHideTemplates = autoShowHideTemplates;
77169
77255
  exports2.bindKeyDownEvent = bindKeyDownEvent;
77256
+ exports2.bindTouchEnd = bindTouchEnd;
77170
77257
  exports2.blockToDoc = blockToDoc;
77171
77258
  exports2.blockToHtml = blockToHtml;
77172
77259
  exports2.blockToMarkdown = blockToMarkdown;
@@ -77227,6 +77314,7 @@ ${data.flowchartText}
77227
77314
  exports2.createInsertionContentElement = createInsertionContentElement;
77228
77315
  exports2.createInsertionElement = createInsertionElement;
77229
77316
  exports2.createLocalEditor = createLocalEditor;
77317
+ exports2.createMouseEventFromTouchEvent = createMouseEventFromTouchEvent;
77230
77318
  exports2.createOnesEditor = createOnesEditor;
77231
77319
  exports2.createRange = createRange;
77232
77320
  exports2.createRichText = createRichText;
@@ -77318,6 +77406,7 @@ ${data.flowchartText}
77318
77406
  exports2.editorUpdateCompositionText = editorUpdateCompositionText;
77319
77407
  exports2.editorUpdateEmbedData = editorUpdateEmbedData;
77320
77408
  exports2.enablePageScroll = enablePageScroll;
77409
+ exports2.ensureIsMobileEvent = ensureIsMobileEvent$1;
77321
77410
  exports2.escapeHtmlText = escapeHtmlText;
77322
77411
  exports2.escapeRegExp = escapeRegExp;
77323
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.6",
3
+ "version": "1.2.0-beta.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",