@ones-editor/editor 2.2.8-beta.6 → 2.2.8-beta.7

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.
@@ -56,4 +56,5 @@ export default abstract class CommandBar extends TypedEmitter<CommandBarEvents>
56
56
  static registerManualCommandBar(type: string, creator: CreateManualCommandBarFunction): void;
57
57
  static createSubCommandBar(item: CommandItem, closeable: Closeable, options?: CommandBarOptions): AbstractManualCommandBar;
58
58
  static hasExistsCommandBar(): boolean;
59
+ static hideAll(): void;
59
60
  }
package/dist/index.js CHANGED
@@ -11556,7 +11556,7 @@ var __publicField = (obj, key, value) => {
11556
11556
  }
11557
11557
  this.editor.selectionHandler.handleMouseDown(event, { autoScroll: true });
11558
11558
  }
11559
- this.editor.input.focus();
11559
+ this.editor.input.focus({ preventScroll: true });
11560
11560
  });
11561
11561
  __publicField(this, "handleMouseMove", (event) => {
11562
11562
  assert(logger$4p, this.mouseDownEvent, "no mouse down event");
@@ -13104,7 +13104,8 @@ var __publicField = (obj, key, value) => {
13104
13104
  if (pointX < rect.left) {
13105
13105
  x = rect.left;
13106
13106
  } else if (pointX > rect.right) {
13107
- x = rect.right - 50;
13107
+ const offset = targetBlock && isTextKindBlock(editor, targetBlock) ? 3 : 50;
13108
+ x = rect.right - offset;
13108
13109
  }
13109
13110
  }
13110
13111
  for (let i = 0; i < yOffsets.length; i++) {
@@ -14453,10 +14454,6 @@ var __publicField = (obj, key, value) => {
14453
14454
  }
14454
14455
  if (isTextBlockContentBoxChild(child)) {
14455
14456
  const boxChild = child;
14456
- const nextChild = children[i + 1];
14457
- if (!nextChild) {
14458
- break;
14459
- }
14460
14457
  const prevChild = children[i - 1];
14461
14458
  if (prevChild) {
14462
14459
  if (endAtNewLine(prevChild, boxChild)) {
@@ -14473,6 +14470,10 @@ var __publicField = (obj, key, value) => {
14473
14470
  });
14474
14471
  }
14475
14472
  }
14473
+ const nextChild = children[i + 1];
14474
+ if (!nextChild) {
14475
+ break;
14476
+ }
14476
14477
  if (nextChildStartsNewLine(boxChild, nextChild)) {
14477
14478
  offset += 1;
14478
14479
  lineBreaks.push({
@@ -27430,7 +27431,7 @@ var __publicField = (obj, key, value) => {
27430
27431
  }
27431
27432
  const logger$3g = getLogger("table-scroll");
27432
27433
  class DomEventHandler {
27433
- constructor(editor, dom, name, handler, data2) {
27434
+ constructor(editor, dom, name, handler, data2, options) {
27434
27435
  __publicField(this, "handleEvent", (event) => {
27435
27436
  this.handler(this.editor, event, this.data);
27436
27437
  });
@@ -27439,7 +27440,7 @@ var __publicField = (obj, key, value) => {
27439
27440
  this.name = name;
27440
27441
  this.handler = handler;
27441
27442
  this.data = data2;
27442
- dom.addEventListener(name, this.handleEvent);
27443
+ dom.addEventListener(name, this.handleEvent, options);
27443
27444
  }
27444
27445
  destroy() {
27445
27446
  this.dom.removeEventListener(this.name, this.handleEvent);
@@ -27456,16 +27457,16 @@ var __publicField = (obj, key, value) => {
27456
27457
  this.handlers.delete(element);
27457
27458
  });
27458
27459
  }
27459
- addEventListener(element, eventName, eventHandler, data2) {
27460
+ addEventListener(element, eventName, eventHandler, data2, options) {
27460
27461
  const existsHandlers = this.handlers.get(element);
27461
27462
  if (existsHandlers) {
27462
27463
  if (existsHandlers.find((handler) => handler.handler === eventHandler && handler.name === eventName)) {
27463
27464
  logger$3g.warn(`event has already registered: ${eventName}`);
27464
27465
  return;
27465
27466
  }
27466
- existsHandlers.push(new DomEventHandler(this.editor, element, eventName, eventHandler, data2));
27467
+ existsHandlers.push(new DomEventHandler(this.editor, element, eventName, eventHandler, data2, options));
27467
27468
  } else {
27468
- const handler = new DomEventHandler(this.editor, element, eventName, eventHandler, data2);
27469
+ const handler = new DomEventHandler(this.editor, element, eventName, eventHandler, data2, options);
27469
27470
  this.handlers.set(element, [handler]);
27470
27471
  }
27471
27472
  }
@@ -39898,17 +39899,23 @@ ${codeText}
39898
39899
  return true;
39899
39900
  }
39900
39901
  if (event.key === "ArrowUp") {
39901
- const prev = this.getPrevItemIndex(this.getSelectedItemIndex());
39902
- this.startPauseMouseEnter();
39903
- this.selectItem(this.items[prev].id);
39904
- event.preventDefault();
39905
- event.stopPropagation();
39902
+ const curr = this.getSelectedItemIndex();
39903
+ const prev = this.getPrevItemIndex(curr);
39904
+ if (curr !== prev) {
39905
+ this.startPauseMouseEnter();
39906
+ this.selectItem(this.items[prev].id);
39907
+ event.preventDefault();
39908
+ event.stopPropagation();
39909
+ }
39906
39910
  } else if (event.key === "ArrowDown") {
39907
- const next2 = this.getNextItemIndex(this.getSelectedItemIndex());
39908
- this.startPauseMouseEnter();
39909
- this.selectItem(this.items[next2].id);
39910
- event.preventDefault();
39911
- event.stopPropagation();
39911
+ const curr = this.getSelectedItemIndex();
39912
+ const next2 = this.getNextItemIndex(curr);
39913
+ if (curr !== next2) {
39914
+ this.startPauseMouseEnter();
39915
+ this.selectItem(this.items[next2].id);
39916
+ event.preventDefault();
39917
+ event.stopPropagation();
39918
+ }
39912
39919
  } else if (event.key === "ArrowRight") {
39913
39920
  const item = this.getSelectedItem();
39914
39921
  if (item && item.children) {
@@ -40114,7 +40121,7 @@ ${codeText}
40114
40121
  this.emit("click", this, item, target);
40115
40122
  }
40116
40123
  createPopperOptions() {
40117
- var _a, _b;
40124
+ var _a, _b, _c;
40118
40125
  const popperOptions = { modifiers: [] };
40119
40126
  const overflowBoundary = this.options.overflowBoundary;
40120
40127
  const padding = this.options.padding;
@@ -40147,6 +40154,10 @@ ${codeText}
40147
40154
  }
40148
40155
  });
40149
40156
  }
40157
+ (_c = popperOptions == null ? void 0 : popperOptions.modifiers) == null ? void 0 : _c.push({
40158
+ name: "flip",
40159
+ enabled: false
40160
+ });
40150
40161
  return popperOptions;
40151
40162
  }
40152
40163
  destroy() {
@@ -40493,6 +40504,9 @@ ${codeText}
40493
40504
  static hasExistsCommandBar() {
40494
40505
  return !!document.querySelector("[data-command-bar-id]");
40495
40506
  }
40507
+ static hideAll() {
40508
+ tippy$1.hideAll();
40509
+ }
40496
40510
  };
40497
40511
  let CommandBar = _CommandBar;
40498
40512
  __publicField(CommandBar, "commandBarCreators", /* @__PURE__ */ new Map());
@@ -52290,6 +52304,7 @@ ${codeText}
52290
52304
  __publicField(this, "editMathjaxPopup", null);
52291
52305
  __publicField(this, "onChange", null);
52292
52306
  __publicField(this, "tex", "");
52307
+ __publicField(this, "oldTex", "");
52293
52308
  __publicField(this, "observer", null);
52294
52309
  __publicField(this, "handleClose", (commandBar2) => {
52295
52310
  var _a;
@@ -52313,6 +52328,10 @@ ${codeText}
52313
52328
  });
52314
52329
  __publicField(this, "handleChange", debounce__default.default((text2) => {
52315
52330
  var _a;
52331
+ if (text2 === this.oldTex) {
52332
+ return;
52333
+ }
52334
+ this.oldTex = text2;
52316
52335
  (_a = this.onChange) == null ? void 0 : _a.call(this, text2, false);
52317
52336
  }, 300));
52318
52337
  }
@@ -52325,6 +52344,7 @@ ${codeText}
52325
52344
  const textarea2 = this.getTextarea();
52326
52345
  textarea2.value = tex;
52327
52346
  }
52347
+ this.oldTex = tex;
52328
52348
  this.tex = tex;
52329
52349
  this.editMathjaxPopup.manualShow(elem, { theme: "light", placement: options == null ? void 0 : options.placement });
52330
52350
  this.editMathjaxPopup.removeAllListeners("close");
@@ -52620,7 +52640,7 @@ ${codeText}
52620
52640
  }
52621
52641
  const data2 = editor.getBlockData(block);
52622
52642
  const embedData = data2.embedData;
52623
- editMathjax(editor, elem, embedData.mathjaxText, async (tex) => {
52643
+ editMathjax(editor, block, embedData.mathjaxText, async (tex) => {
52624
52644
  const { resourceId: src, width, height } = await convertAndUploadMathjaxForEmbed(editor, tex);
52625
52645
  const newData = {
52626
52646
  mathjaxText: tex,
@@ -60878,7 +60898,6 @@ $$${mathData.mathjaxText}$$
60878
60898
  editor.selection.setSelection(anchor2, void 0, { noScroll: direction === "next" });
60879
60899
  }
60880
60900
  }
60881
- editor.focus();
60882
60901
  if (direction === "next") {
60883
60902
  const targetElementRect = targetElement.getBoundingClientRect();
60884
60903
  const clientHeight = editor.scrollContainer.clientHeight;
@@ -62916,6 +62935,7 @@ $$${mathData.mathjaxText}$$
62916
62935
  dropdown2.setSelectedId(codeData.language);
62917
62936
  selectCodeBlock(editor2, block, { focusToEditor: false });
62918
62937
  setTimeout(() => {
62938
+ CommandBar.hideAll();
62919
62939
  dropdown2.show(select2);
62920
62940
  });
62921
62941
  addClass(codeBlock2, "editing-language");
@@ -67735,7 +67755,7 @@ ${codeText}
67735
67755
  this.editor.addListener("selectionChanged", this.handleSelectionChanged);
67736
67756
  this.editor.addListener("resize", this.handleEditorResize);
67737
67757
  this.editor.addListener("docChanged", this.handleDocChanged);
67738
- this.editor.scrollContainer.addEventListener("wheel", this.handleScroll, { passive: false });
67758
+ this.editor.domEvents.addEventListener(this.editor.scrollContainer, "wheel", (ed, e2) => this.handleScroll(e2), { passive: false });
67739
67759
  this.items.forEach((item) => item.addListener("resize", this.handleItemResize));
67740
67760
  this.groupItemHandlers = new CommentGroupItemHandlers(this, commentsProvider);
67741
67761
  document.addEventListener("click", this.handleDocumentClick);
@@ -67744,7 +67764,6 @@ ${codeText}
67744
67764
  this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
67745
67765
  this.editor.removeListener("resize", this.handleEditorResize);
67746
67766
  this.editor.removeListener("docChanged", this.handleDocChanged);
67747
- this.editor.scrollContainer.removeEventListener("wheel", this.handleScroll);
67748
67767
  super.destroy();
67749
67768
  this.unbindEvents();
67750
67769
  this.removeAllListeners();
@@ -79562,6 +79581,7 @@ ${content}
79562
79581
  }
79563
79582
  destroy() {
79564
79583
  this.editor.doc.unregisterCallback(this);
79584
+ this.removeAllListeners();
79565
79585
  }
79566
79586
  isHeadingBlock(blockData) {
79567
79587
  return !!blockData.heading;
@@ -80323,22 +80343,22 @@ ${content}
80323
80343
  const image = createElement("img", ["editor-template-thumb"], imageContaniner);
80324
80344
  image.src = imageSrc;
80325
80345
  image.style.display = "none";
80326
- image.onerror = () => {
80346
+ editor.domEvents.addEventListener(image, "error", () => {
80327
80347
  var _a2;
80328
80348
  const placeholder2 = (_a2 = options == null ? void 0 : options.placeHolderImageSrc) != null ? _a2 : TEMPLATE_PLACEHOLDER;
80329
80349
  if (image.src !== placeholder2) {
80330
80350
  image.src = placeholder2;
80331
80351
  }
80332
- };
80333
- image.onload = () => {
80352
+ });
80353
+ editor.domEvents.addEventListener(image, "load", () => {
80334
80354
  image.style.display = "";
80335
- };
80355
+ });
80336
80356
  const nameDiv = createElement("div", ["editor-template-name"], card);
80337
80357
  const span = createElement("span", [], nameDiv, name);
80338
80358
  if (options == null ? void 0 : options.showTemplateTitleAttr) {
80339
80359
  span.setAttribute("title", name);
80340
80360
  }
80341
- card.onclick = () => clickHandler(card);
80361
+ editor.domEvents.addEventListener(card, "click", () => clickHandler(card));
80342
80362
  return card;
80343
80363
  }
80344
80364
  function getDocThumbImage(editor, template) {
@@ -88080,20 +88100,32 @@ ${data2.flowchartText}
88080
88100
  return docx.Packer.toBlob(doc2);
88081
88101
  }
88082
88102
  }
88103
+ class ExportImageError extends Error {
88104
+ constructor(message) {
88105
+ super(message);
88106
+ this.name = this.constructor.name;
88107
+ }
88108
+ }
88083
88109
  const logger$1 = getLogger("editor-to-docx");
88110
+ const ERROR_MESSAGE = "editor-to-docx: read image error";
88084
88111
  async function readImage(editor, _appId, _docId, _src) {
88085
- const url = editor.doc.buildResourceUrl(_src, { withToken: true });
88086
- let file2 = await downloadImageToFile$1(url);
88087
- if (!file2)
88088
- return [void 0, url];
88089
- if (file2.type.indexOf("/svg") !== -1) {
88090
- const pngFile = await convertImageFileToPng(file2);
88091
- if (pngFile) {
88092
- file2 = new File([pngFile], file2.name);
88112
+ try {
88113
+ const url = editor.doc.buildResourceUrl(_src, { withToken: true });
88114
+ let file2 = await downloadImageToFile$1(url);
88115
+ if (!file2) {
88116
+ throw new Error(ERROR_MESSAGE);
88093
88117
  }
88118
+ if (file2.type.indexOf("/svg") !== -1) {
88119
+ const pngFile = await convertImageFileToPng(file2);
88120
+ if (pngFile) {
88121
+ file2 = new File([pngFile], file2.name);
88122
+ }
88123
+ }
88124
+ const arrayBuffer = await file2.arrayBuffer();
88125
+ return [arrayBuffer, url];
88126
+ } catch (error2) {
88127
+ throw new ExportImageError(error2.message || ERROR_MESSAGE);
88094
88128
  }
88095
- const arrayBuffer = await file2.arrayBuffer();
88096
- return [arrayBuffer, url];
88097
88129
  }
88098
88130
  async function getDocByBlock(editor, doc2, block) {
88099
88131
  const blockClass = editor.editorBlocks.getBlockClass(block.type);
@@ -88327,13 +88359,7 @@ ${data2.flowchartText}
88327
88359
  }
88328
88360
  }
88329
88361
  });
88330
- editor.version = "2.2.8-beta.6";
88331
- if (Logger$2.level === LogLevel.DEBUG) {
88332
- window.setReauthFail = (fail) => {
88333
- window.isReauthError = fail;
88334
- };
88335
- window.reConnect = (token) => editor.doc.externalDoc.client.connection.reConnect(token);
88336
- }
88362
+ editor.version = "2.2.8-beta.7";
88337
88363
  return editor;
88338
88364
  }
88339
88365
  function isDoc(doc2) {
@@ -88428,7 +88454,7 @@ ${data2.flowchartText}
88428
88454
  });
88429
88455
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
88430
88456
  OnesEditorToolbar.register(editor);
88431
- editor.version = "2.2.8-beta.6";
88457
+ editor.version = "2.2.8-beta.7";
88432
88458
  return editor;
88433
88459
  }
88434
88460
  async function showDocVersions(editor, options, serverUrl) {
@@ -134207,6 +134233,7 @@ ${data2.flowchartText}
134207
134233
  exports2.EmbedBlockResizer = EmbedBlockResizer;
134208
134234
  exports2.EnforceWithDocumentTitleHandler = EnforceWithDocumentTitleHandler;
134209
134235
  exports2.EventCallbacks = EventCallbacks;
134236
+ exports2.ExportImageError = ExportImageError;
134210
134237
  exports2.FILL_CHAR = FILL_CHAR;
134211
134238
  exports2.FileExtError = FileExtError;
134212
134239
  exports2.FixedToolbar = FixedToolbar;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.2.8-beta.6",
3
+ "version": "2.2.8-beta.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,6 +31,7 @@
31
31
  "lodash.findlastindex": "^4.6.0",
32
32
  "lodash.intersection": "^4.4.0",
33
33
  "lodash.isequal": "^4.5.0",
34
+ "lodash.memoize": "^4.1.2",
34
35
  "lodash.merge": "^4.6.2",
35
36
  "lodash.pick": "^4.4.0",
36
37
  "lodash.throttle": "^4.1.1",