@ones-editor/editor 2.2.22 → 2.2.23

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.
@@ -1,4 +1,5 @@
1
1
  import { OnesEditor, OnesEditorInputHandler, CommandItem, BlockElement } from '../../../../@ones-editor/core';
2
+ import type { CloneBlockResultInfo, DocObject } from '../../../../@ones-editor/core';
2
3
  import AutoSuggestMenu from './auto-suggest-menu';
3
4
  import EditorAutoSuggestMenu from './editor-auto-suggest-menu';
4
5
  export { AutoSuggestMenu };
@@ -36,10 +37,12 @@ declare class OnesEditorAutoSuggest implements OnesEditorInputHandler {
36
37
  anchor: AutoSuggestAnchor | null;
37
38
  constructor(editor: OnesEditor, options: AutoSuggestOptions);
38
39
  handleBeforeKeyDown(editor: OnesEditor, event: KeyboardEvent): boolean;
40
+ handleBeforePasteDoc(editor: OnesEditor, doc: DocObject): Promise<boolean>;
39
41
  popup(block: BlockElement, offset: number, leftText: string, trigger: string): void;
40
42
  close: () => void;
41
43
  triggerPopup(editor: OnesEditor, containerId: string, blockIndex: number, insertOffset: number, text: string): boolean;
42
44
  handleAfterInsertText(editor: OnesEditor, containerId: string, blockIndex: number, insertOffset: number, text: string): boolean;
45
+ handleAfterPasteDoc(editor: OnesEditor, doc: DocObject, cloneDocResult: CloneBlockResultInfo): Promise<boolean>;
43
46
  private oldCompositingText;
44
47
  handleUpdateCompositionText(editor: OnesEditor, containerId: string, blockIndex: number, offset: number, end: boolean): boolean;
45
48
  handleSelectionChanged: (editor: OnesEditor) => void;
package/dist/index.js CHANGED
@@ -26660,6 +26660,7 @@ var __publicField = (obj, key, value) => {
26660
26660
  }
26661
26661
  const logger$3m = getLogger("insert-doc");
26662
26662
  function editorInsertDoc(editor, block, offset, insertedDoc, cloneDocResult) {
26663
+ var _a;
26663
26664
  if (isComplexKindBlock(editor, block)) {
26664
26665
  logger$3m.warn("failed to insert doc into a complex block");
26665
26666
  return;
@@ -26668,9 +26669,13 @@ var __publicField = (obj, key, value) => {
26668
26669
  const container = getParentContainer(block);
26669
26670
  const blockIndex = getBlockIndex(block);
26670
26671
  const containerId = getContainerId(container);
26672
+ if (doc2.blocks.root.length === 1 && isTextKindBlockType(editor, doc2.blocks.root[0].type)) {
26673
+ editor.insertTextToBlock(block, offset, (_a = doc2.blocks.root[0].text) != null ? _a : []);
26674
+ return;
26675
+ }
26671
26676
  editor.doc.beginBatchUpdate();
26672
26677
  editor.undoManager.runInGroup(() => {
26673
- var _a, _b, _c;
26678
+ var _a2, _b, _c;
26674
26679
  const childContainers = [];
26675
26680
  Object.entries(doc2.blocks).forEach(([containerId2, blocks2]) => {
26676
26681
  if (containerId2 === "root")
@@ -26735,7 +26740,7 @@ var __publicField = (obj, key, value) => {
26735
26740
  if (blocks.length === 1) {
26736
26741
  const newBlock2 = blocks[0];
26737
26742
  if (isTextKindBlockType(editor, newBlock2.type)) {
26738
- editor.insertTextToBlock(block, offset, (_a = newBlock2.text) != null ? _a : []);
26743
+ editor.insertTextToBlock(block, offset, (_a2 = newBlock2.text) != null ? _a2 : []);
26739
26744
  return;
26740
26745
  }
26741
26746
  editor.breakTextBlock(block, offset);
@@ -41384,6 +41389,7 @@ ${codeText}
41384
41389
  this.options.onClickItem(this, item);
41385
41390
  }, 300, { leading: true, trailing: false }));
41386
41391
  __publicField(this, "handleShow", (menu) => {
41392
+ this.menu.content.classList.add("auto-suggest-menu");
41387
41393
  });
41388
41394
  __publicField(this, "handleShown", () => {
41389
41395
  var _a, _b;
@@ -42403,6 +42409,32 @@ ${codeText}
42403
42409
  }
42404
42410
  return this.menu.handleKeydown(event);
42405
42411
  }
42412
+ async handleBeforePasteDoc(editor, doc2) {
42413
+ var _a;
42414
+ if (!((_a = this.menu) == null ? void 0 : _a.isVisible)) {
42415
+ return false;
42416
+ }
42417
+ const shouldCancelAutoSuggest = () => {
42418
+ var _a2;
42419
+ const blocks = doc2.blocks.root;
42420
+ if (blocks.length !== 1) {
42421
+ return true;
42422
+ }
42423
+ const block = blocks[0];
42424
+ if (((_a2 = editor.editorBlocks.getBlockClass(block.type)) == null ? void 0 : _a2.blockKind) !== "text") {
42425
+ return true;
42426
+ }
42427
+ const text2 = toPlainText(block.text || []);
42428
+ if (text2.length > 50) {
42429
+ return true;
42430
+ }
42431
+ return false;
42432
+ };
42433
+ if (shouldCancelAutoSuggest()) {
42434
+ this.menu.close();
42435
+ }
42436
+ return false;
42437
+ }
42406
42438
  popup(block, offset, leftText, trigger) {
42407
42439
  this.anchor = {
42408
42440
  blockId: getBlockId(block),
@@ -42458,6 +42490,13 @@ ${codeText}
42458
42490
  }
42459
42491
  return this.triggerPopup(editor, containerId, blockIndex, insertOffset, text2);
42460
42492
  }
42493
+ async handleAfterPasteDoc(editor, doc2, cloneDocResult) {
42494
+ var _a;
42495
+ if ((_a = this.menu) == null ? void 0 : _a.isVisible) {
42496
+ this.resetItems();
42497
+ }
42498
+ return false;
42499
+ }
42461
42500
  handleUpdateCompositionText(editor, containerId, blockIndex, offset, end) {
42462
42501
  var _a;
42463
42502
  const start = editor.selection.range.start;
@@ -72043,6 +72082,16 @@ ${codeText}
72043
72082
  return false;
72044
72083
  }
72045
72084
  }
72085
+ const existsAutoSuggest = document.querySelector(".auto-suggest-menu");
72086
+ if (existsAutoSuggest) {
72087
+ const root2 = existsAutoSuggest.closest("[data-tippy-root]");
72088
+ if (root2) {
72089
+ const visibility = window.getComputedStyle(root2).visibility;
72090
+ if (visibility === "visible") {
72091
+ return false;
72092
+ }
72093
+ }
72094
+ }
72046
72095
  this.button.clearCheckedState();
72047
72096
  this.button.show(docs);
72048
72097
  this.event = event;
@@ -88483,7 +88532,7 @@ ${data2.flowchartText}
88483
88532
  }
88484
88533
  }
88485
88534
  });
88486
- editor.version = "2.2.22";
88535
+ editor.version = "2.2.23";
88487
88536
  return editor;
88488
88537
  }
88489
88538
  function isDoc(doc2) {
@@ -88578,7 +88627,7 @@ ${data2.flowchartText}
88578
88627
  });
88579
88628
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
88580
88629
  OnesEditorToolbar.register(editor);
88581
- editor.version = "2.2.22";
88630
+ editor.version = "2.2.23";
88582
88631
  return editor;
88583
88632
  }
88584
88633
  async function showDocVersions(editor, options, serverUrl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.2.22",
3
+ "version": "2.2.23",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",