@ones-editor/editor 2.6.3 → 2.6.5

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 };
@@ -37,10 +38,12 @@ declare class OnesEditorAutoSuggest implements OnesEditorInputHandler {
37
38
  anchor: AutoSuggestAnchor | null;
38
39
  constructor(editor: OnesEditor, options: AutoSuggestOptions);
39
40
  handleBeforeKeyDown(editor: OnesEditor, event: KeyboardEvent): boolean;
41
+ handleBeforePasteDoc(editor: OnesEditor, doc: DocObject): Promise<boolean>;
40
42
  popup(block: BlockElement, offset: number, leftText: string, trigger: string): void;
41
43
  close: () => void;
42
44
  triggerPopup(editor: OnesEditor, containerId: string, blockIndex: number, insertOffset: number, text: string): boolean;
43
45
  handleAfterInsertText(editor: OnesEditor, containerId: string, blockIndex: number, insertOffset: number, text: string): boolean;
46
+ handleAfterPasteDoc(editor: OnesEditor, doc: DocObject, cloneDocResult: CloneBlockResultInfo): Promise<boolean>;
44
47
  private oldCompositingText;
45
48
  handleUpdateCompositionText(editor: OnesEditor, containerId: string, blockIndex: number, offset: number, end: boolean): boolean;
46
49
  handleSelectionChanged: (editor: OnesEditor) => void;
package/dist/index.js CHANGED
@@ -27182,6 +27182,7 @@ var __publicField = (obj, key, value) => {
27182
27182
  }
27183
27183
  const logger$3z = getLogger("insert-doc");
27184
27184
  function editorInsertDoc(editor, block, offset, insertedDoc, cloneDocResult) {
27185
+ var _a;
27185
27186
  if (isComplexKindBlock(editor, block)) {
27186
27187
  logger$3z.warn("failed to insert doc into a complex block");
27187
27188
  return;
@@ -27190,9 +27191,13 @@ var __publicField = (obj, key, value) => {
27190
27191
  const container = getParentContainer(block);
27191
27192
  const blockIndex = getBlockIndex(block);
27192
27193
  const containerId = getContainerId(container);
27194
+ if (doc2.blocks.root.length === 1 && isTextKindBlockType(editor, doc2.blocks.root[0].type)) {
27195
+ editor.insertTextToBlock(block, offset, (_a = doc2.blocks.root[0].text) != null ? _a : []);
27196
+ return;
27197
+ }
27193
27198
  editor.doc.beginBatchUpdate();
27194
27199
  editor.undoManager.runInGroup(() => {
27195
- var _a, _b, _c;
27200
+ var _a2, _b, _c;
27196
27201
  const childContainers = [];
27197
27202
  Object.entries(doc2.blocks).forEach(([containerId2, blocks2]) => {
27198
27203
  if (containerId2 === "root")
@@ -27257,7 +27262,7 @@ var __publicField = (obj, key, value) => {
27257
27262
  if (blocks.length === 1) {
27258
27263
  const newBlock2 = blocks[0];
27259
27264
  if (isTextKindBlockType(editor, newBlock2.type)) {
27260
- editor.insertTextToBlock(block, offset, (_a = newBlock2.text) != null ? _a : []);
27265
+ editor.insertTextToBlock(block, offset, (_a2 = newBlock2.text) != null ? _a2 : []);
27261
27266
  return;
27262
27267
  }
27263
27268
  editor.breakTextBlock(block, offset);
@@ -42701,6 +42706,7 @@ ${codeText}
42701
42706
  this.options.onClickItem(this, item);
42702
42707
  }, 300, { leading: true, trailing: false }));
42703
42708
  __publicField(this, "handleShow", (menu) => {
42709
+ this.menu.content.classList.add("auto-suggest-menu");
42704
42710
  });
42705
42711
  __publicField(this, "handleShown", () => {
42706
42712
  var _a, _b;
@@ -43757,6 +43763,32 @@ ${codeText}
43757
43763
  }
43758
43764
  return this.menu.handleKeydown(event);
43759
43765
  }
43766
+ async handleBeforePasteDoc(editor, doc2) {
43767
+ var _a;
43768
+ if (!((_a = this.menu) == null ? void 0 : _a.isVisible)) {
43769
+ return false;
43770
+ }
43771
+ const shouldCancelAutoSuggest = () => {
43772
+ var _a2;
43773
+ const blocks = doc2.blocks.root;
43774
+ if (blocks.length !== 1) {
43775
+ return true;
43776
+ }
43777
+ const block = blocks[0];
43778
+ if (((_a2 = editor.editorBlocks.getBlockClass(block.type)) == null ? void 0 : _a2.blockKind) !== "text") {
43779
+ return true;
43780
+ }
43781
+ const text2 = toPlainText(block.text || []);
43782
+ if (text2.length > 50) {
43783
+ return true;
43784
+ }
43785
+ return false;
43786
+ };
43787
+ if (shouldCancelAutoSuggest()) {
43788
+ this.menu.close();
43789
+ }
43790
+ return false;
43791
+ }
43760
43792
  popup(block, offset, leftText, trigger) {
43761
43793
  this.anchor = {
43762
43794
  blockId: getBlockId(block),
@@ -43812,6 +43844,13 @@ ${codeText}
43812
43844
  }
43813
43845
  return this.triggerPopup(editor, containerId, blockIndex, insertOffset, text2);
43814
43846
  }
43847
+ async handleAfterPasteDoc(editor, doc2, cloneDocResult) {
43848
+ var _a;
43849
+ if ((_a = this.menu) == null ? void 0 : _a.isVisible) {
43850
+ this.resetItems();
43851
+ }
43852
+ return false;
43853
+ }
43815
43854
  handleUpdateCompositionText(editor, containerId, blockIndex, offset, end) {
43816
43855
  var _a;
43817
43856
  const start = editor.selection.range.start;
@@ -73748,6 +73787,16 @@ ${codeText}
73748
73787
  return false;
73749
73788
  }
73750
73789
  }
73790
+ const existsAutoSuggest = document.querySelector(".auto-suggest-menu");
73791
+ if (existsAutoSuggest) {
73792
+ const root2 = existsAutoSuggest.closest("[data-tippy-root]");
73793
+ if (root2) {
73794
+ const visibility = window.getComputedStyle(root2).visibility;
73795
+ if (visibility === "visible") {
73796
+ return false;
73797
+ }
73798
+ }
73799
+ }
73751
73800
  this.button.clearCheckedState();
73752
73801
  this.button.show(docs);
73753
73802
  this.event = event;
@@ -92429,7 +92478,7 @@ ${data2.plantumlText}
92429
92478
  }
92430
92479
  }
92431
92480
  });
92432
- editor.version = "2.6.3";
92481
+ editor.version = "2.6.5";
92433
92482
  return editor;
92434
92483
  }
92435
92484
  function isDoc(doc2) {
@@ -92542,7 +92591,7 @@ ${data2.plantumlText}
92542
92591
  }
92543
92592
  });
92544
92593
  OnesEditorToolbar.register(editor);
92545
- editor.version = "2.6.3";
92594
+ editor.version = "2.6.5";
92546
92595
  return editor;
92547
92596
  }
92548
92597
  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.6.3",
3
+ "version": "2.6.5",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {