@ones-editor/editor 2.2.8-beta.5 → 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
@@ -858,10 +858,10 @@ div.tippy-box[data-theme=menu] .tippy-arrow::after {
858
858
  transform: rotate(45deg);
859
859
  }
860
860
  div.tippy-box[data-theme=menu] .tippy-content .editor-command-bar-root, div.tippy-box[data-theme=toolbar] .tippy-content .editor-command-bar-root {
861
- box-shadow: 0px 0px 1px rgba(48, 48, 48, 0.25), 0px 12px 24px rgba(48, 48, 48, 0.15);
861
+ box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(45, 45, 46, 0.15) 0px 8px 16px -4px, rgba(45, 45, 46, 0.2) 0px 0px 1px 0px;
862
862
  }
863
863
  div.tippy-box[data-theme=toolbar] .tippy-content .editor-command-bar-root {
864
- overflow: initial;
864
+ border-radius: 3px;
865
865
  }
866
866
  div.tippy-box button {
867
867
  outline: none;
@@ -901,7 +901,7 @@ div.tippy-box button {
901
901
  }
902
902
  .editor-command-bar.fixed.mobile .command-item.checked, .editor-command-bar.toolbar.mobile .command-item.checked {
903
903
  border-radius: 3px;
904
- background: #F0F6FF;
904
+ background: #f0f6ff;
905
905
  }
906
906
  .editor-command-bar {
907
907
  pointer-events: all;
@@ -1019,8 +1019,6 @@ div.tippy-box button {
1019
1019
  gap: 5px;
1020
1020
  padding: 5px 10px;
1021
1021
  background: #ffffff;
1022
- box-shadow: 0px 0px 1px rgba(48, 48, 48, 0.2), 0px 8px 16px rgba(48, 48, 48, 0.15);
1023
- border-radius: 3px;
1024
1022
  }
1025
1023
  .editor-command-bar.toolbar .command-item {
1026
1024
  background: transparent;
@@ -2054,11 +2052,6 @@ div.tippy-box[data-theme=editor-tooltip] > .tippy-content {
2054
2052
  border-radius: 8px;
2055
2053
  background: none;
2056
2054
  }
2057
- [data-command-bar-id=cursor-toolbar].mobile .tippy-box .tippy-content .editor-command-bar-root,
2058
- [data-command-bar-id=paste-special-button].mobile .tippy-box .tippy-content .editor-command-bar-root,
2059
- [data-command-bar-id=editor-toolbar].mobile .tippy-box .tippy-content .editor-command-bar-root {
2060
- box-shadow: none;
2061
- }
2062
2055
  [data-command-bar-id=cursor-toolbar].mobile .tippy-content,
2063
2056
  [data-command-bar-id=cursor-toolbar].mobile .editor-command-bar-root,
2064
2057
  [data-command-bar-id=cursor-toolbar].mobile .editor-command-bar,
@@ -11563,7 +11556,7 @@ var __publicField = (obj, key, value) => {
11563
11556
  }
11564
11557
  this.editor.selectionHandler.handleMouseDown(event, { autoScroll: true });
11565
11558
  }
11566
- this.editor.input.focus();
11559
+ this.editor.input.focus({ preventScroll: true });
11567
11560
  });
11568
11561
  __publicField(this, "handleMouseMove", (event) => {
11569
11562
  assert(logger$4p, this.mouseDownEvent, "no mouse down event");
@@ -13111,7 +13104,8 @@ var __publicField = (obj, key, value) => {
13111
13104
  if (pointX < rect.left) {
13112
13105
  x = rect.left;
13113
13106
  } else if (pointX > rect.right) {
13114
- x = rect.right - 50;
13107
+ const offset = targetBlock && isTextKindBlock(editor, targetBlock) ? 3 : 50;
13108
+ x = rect.right - offset;
13115
13109
  }
13116
13110
  }
13117
13111
  for (let i = 0; i < yOffsets.length; i++) {
@@ -14460,10 +14454,6 @@ var __publicField = (obj, key, value) => {
14460
14454
  }
14461
14455
  if (isTextBlockContentBoxChild(child)) {
14462
14456
  const boxChild = child;
14463
- const nextChild = children[i + 1];
14464
- if (!nextChild) {
14465
- break;
14466
- }
14467
14457
  const prevChild = children[i - 1];
14468
14458
  if (prevChild) {
14469
14459
  if (endAtNewLine(prevChild, boxChild)) {
@@ -14480,6 +14470,10 @@ var __publicField = (obj, key, value) => {
14480
14470
  });
14481
14471
  }
14482
14472
  }
14473
+ const nextChild = children[i + 1];
14474
+ if (!nextChild) {
14475
+ break;
14476
+ }
14483
14477
  if (nextChildStartsNewLine(boxChild, nextChild)) {
14484
14478
  offset += 1;
14485
14479
  lineBreaks.push({
@@ -27437,7 +27431,7 @@ var __publicField = (obj, key, value) => {
27437
27431
  }
27438
27432
  const logger$3g = getLogger("table-scroll");
27439
27433
  class DomEventHandler {
27440
- constructor(editor, dom, name, handler, data2) {
27434
+ constructor(editor, dom, name, handler, data2, options) {
27441
27435
  __publicField(this, "handleEvent", (event) => {
27442
27436
  this.handler(this.editor, event, this.data);
27443
27437
  });
@@ -27446,7 +27440,7 @@ var __publicField = (obj, key, value) => {
27446
27440
  this.name = name;
27447
27441
  this.handler = handler;
27448
27442
  this.data = data2;
27449
- dom.addEventListener(name, this.handleEvent);
27443
+ dom.addEventListener(name, this.handleEvent, options);
27450
27444
  }
27451
27445
  destroy() {
27452
27446
  this.dom.removeEventListener(this.name, this.handleEvent);
@@ -27463,16 +27457,16 @@ var __publicField = (obj, key, value) => {
27463
27457
  this.handlers.delete(element);
27464
27458
  });
27465
27459
  }
27466
- addEventListener(element, eventName, eventHandler, data2) {
27460
+ addEventListener(element, eventName, eventHandler, data2, options) {
27467
27461
  const existsHandlers = this.handlers.get(element);
27468
27462
  if (existsHandlers) {
27469
27463
  if (existsHandlers.find((handler) => handler.handler === eventHandler && handler.name === eventName)) {
27470
27464
  logger$3g.warn(`event has already registered: ${eventName}`);
27471
27465
  return;
27472
27466
  }
27473
- existsHandlers.push(new DomEventHandler(this.editor, element, eventName, eventHandler, data2));
27467
+ existsHandlers.push(new DomEventHandler(this.editor, element, eventName, eventHandler, data2, options));
27474
27468
  } else {
27475
- const handler = new DomEventHandler(this.editor, element, eventName, eventHandler, data2);
27469
+ const handler = new DomEventHandler(this.editor, element, eventName, eventHandler, data2, options);
27476
27470
  this.handlers.set(element, [handler]);
27477
27471
  }
27478
27472
  }
@@ -39905,17 +39899,23 @@ ${codeText}
39905
39899
  return true;
39906
39900
  }
39907
39901
  if (event.key === "ArrowUp") {
39908
- const prev = this.getPrevItemIndex(this.getSelectedItemIndex());
39909
- this.startPauseMouseEnter();
39910
- this.selectItem(this.items[prev].id);
39911
- event.preventDefault();
39912
- 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
+ }
39913
39910
  } else if (event.key === "ArrowDown") {
39914
- const next2 = this.getNextItemIndex(this.getSelectedItemIndex());
39915
- this.startPauseMouseEnter();
39916
- this.selectItem(this.items[next2].id);
39917
- event.preventDefault();
39918
- 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
+ }
39919
39919
  } else if (event.key === "ArrowRight") {
39920
39920
  const item = this.getSelectedItem();
39921
39921
  if (item && item.children) {
@@ -40121,7 +40121,7 @@ ${codeText}
40121
40121
  this.emit("click", this, item, target);
40122
40122
  }
40123
40123
  createPopperOptions() {
40124
- var _a, _b;
40124
+ var _a, _b, _c;
40125
40125
  const popperOptions = { modifiers: [] };
40126
40126
  const overflowBoundary = this.options.overflowBoundary;
40127
40127
  const padding = this.options.padding;
@@ -40154,6 +40154,10 @@ ${codeText}
40154
40154
  }
40155
40155
  });
40156
40156
  }
40157
+ (_c = popperOptions == null ? void 0 : popperOptions.modifiers) == null ? void 0 : _c.push({
40158
+ name: "flip",
40159
+ enabled: false
40160
+ });
40157
40161
  return popperOptions;
40158
40162
  }
40159
40163
  destroy() {
@@ -40500,6 +40504,9 @@ ${codeText}
40500
40504
  static hasExistsCommandBar() {
40501
40505
  return !!document.querySelector("[data-command-bar-id]");
40502
40506
  }
40507
+ static hideAll() {
40508
+ tippy$1.hideAll();
40509
+ }
40503
40510
  };
40504
40511
  let CommandBar = _CommandBar;
40505
40512
  __publicField(CommandBar, "commandBarCreators", /* @__PURE__ */ new Map());
@@ -52297,6 +52304,7 @@ ${codeText}
52297
52304
  __publicField(this, "editMathjaxPopup", null);
52298
52305
  __publicField(this, "onChange", null);
52299
52306
  __publicField(this, "tex", "");
52307
+ __publicField(this, "oldTex", "");
52300
52308
  __publicField(this, "observer", null);
52301
52309
  __publicField(this, "handleClose", (commandBar2) => {
52302
52310
  var _a;
@@ -52320,6 +52328,10 @@ ${codeText}
52320
52328
  });
52321
52329
  __publicField(this, "handleChange", debounce__default.default((text2) => {
52322
52330
  var _a;
52331
+ if (text2 === this.oldTex) {
52332
+ return;
52333
+ }
52334
+ this.oldTex = text2;
52323
52335
  (_a = this.onChange) == null ? void 0 : _a.call(this, text2, false);
52324
52336
  }, 300));
52325
52337
  }
@@ -52332,6 +52344,7 @@ ${codeText}
52332
52344
  const textarea2 = this.getTextarea();
52333
52345
  textarea2.value = tex;
52334
52346
  }
52347
+ this.oldTex = tex;
52335
52348
  this.tex = tex;
52336
52349
  this.editMathjaxPopup.manualShow(elem, { theme: "light", placement: options == null ? void 0 : options.placement });
52337
52350
  this.editMathjaxPopup.removeAllListeners("close");
@@ -52627,7 +52640,7 @@ ${codeText}
52627
52640
  }
52628
52641
  const data2 = editor.getBlockData(block);
52629
52642
  const embedData = data2.embedData;
52630
- editMathjax(editor, elem, embedData.mathjaxText, async (tex) => {
52643
+ editMathjax(editor, block, embedData.mathjaxText, async (tex) => {
52631
52644
  const { resourceId: src, width, height } = await convertAndUploadMathjaxForEmbed(editor, tex);
52632
52645
  const newData = {
52633
52646
  mathjaxText: tex,
@@ -60885,7 +60898,6 @@ $$${mathData.mathjaxText}$$
60885
60898
  editor.selection.setSelection(anchor2, void 0, { noScroll: direction === "next" });
60886
60899
  }
60887
60900
  }
60888
- editor.focus();
60889
60901
  if (direction === "next") {
60890
60902
  const targetElementRect = targetElement.getBoundingClientRect();
60891
60903
  const clientHeight = editor.scrollContainer.clientHeight;
@@ -62923,6 +62935,7 @@ $$${mathData.mathjaxText}$$
62923
62935
  dropdown2.setSelectedId(codeData.language);
62924
62936
  selectCodeBlock(editor2, block, { focusToEditor: false });
62925
62937
  setTimeout(() => {
62938
+ CommandBar.hideAll();
62926
62939
  dropdown2.show(select2);
62927
62940
  });
62928
62941
  addClass(codeBlock2, "editing-language");
@@ -67742,7 +67755,7 @@ ${codeText}
67742
67755
  this.editor.addListener("selectionChanged", this.handleSelectionChanged);
67743
67756
  this.editor.addListener("resize", this.handleEditorResize);
67744
67757
  this.editor.addListener("docChanged", this.handleDocChanged);
67745
- 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 });
67746
67759
  this.items.forEach((item) => item.addListener("resize", this.handleItemResize));
67747
67760
  this.groupItemHandlers = new CommentGroupItemHandlers(this, commentsProvider);
67748
67761
  document.addEventListener("click", this.handleDocumentClick);
@@ -67751,7 +67764,6 @@ ${codeText}
67751
67764
  this.editor.removeListener("selectionChanged", this.handleSelectionChanged);
67752
67765
  this.editor.removeListener("resize", this.handleEditorResize);
67753
67766
  this.editor.removeListener("docChanged", this.handleDocChanged);
67754
- this.editor.scrollContainer.removeEventListener("wheel", this.handleScroll);
67755
67767
  super.destroy();
67756
67768
  this.unbindEvents();
67757
67769
  this.removeAllListeners();
@@ -79569,6 +79581,7 @@ ${content}
79569
79581
  }
79570
79582
  destroy() {
79571
79583
  this.editor.doc.unregisterCallback(this);
79584
+ this.removeAllListeners();
79572
79585
  }
79573
79586
  isHeadingBlock(blockData) {
79574
79587
  return !!blockData.heading;
@@ -80330,22 +80343,22 @@ ${content}
80330
80343
  const image = createElement("img", ["editor-template-thumb"], imageContaniner);
80331
80344
  image.src = imageSrc;
80332
80345
  image.style.display = "none";
80333
- image.onerror = () => {
80346
+ editor.domEvents.addEventListener(image, "error", () => {
80334
80347
  var _a2;
80335
80348
  const placeholder2 = (_a2 = options == null ? void 0 : options.placeHolderImageSrc) != null ? _a2 : TEMPLATE_PLACEHOLDER;
80336
80349
  if (image.src !== placeholder2) {
80337
80350
  image.src = placeholder2;
80338
80351
  }
80339
- };
80340
- image.onload = () => {
80352
+ });
80353
+ editor.domEvents.addEventListener(image, "load", () => {
80341
80354
  image.style.display = "";
80342
- };
80355
+ });
80343
80356
  const nameDiv = createElement("div", ["editor-template-name"], card);
80344
80357
  const span = createElement("span", [], nameDiv, name);
80345
80358
  if (options == null ? void 0 : options.showTemplateTitleAttr) {
80346
80359
  span.setAttribute("title", name);
80347
80360
  }
80348
- card.onclick = () => clickHandler(card);
80361
+ editor.domEvents.addEventListener(card, "click", () => clickHandler(card));
80349
80362
  return card;
80350
80363
  }
80351
80364
  function getDocThumbImage(editor, template) {
@@ -88087,20 +88100,32 @@ ${data2.flowchartText}
88087
88100
  return docx.Packer.toBlob(doc2);
88088
88101
  }
88089
88102
  }
88103
+ class ExportImageError extends Error {
88104
+ constructor(message) {
88105
+ super(message);
88106
+ this.name = this.constructor.name;
88107
+ }
88108
+ }
88090
88109
  const logger$1 = getLogger("editor-to-docx");
88110
+ const ERROR_MESSAGE = "editor-to-docx: read image error";
88091
88111
  async function readImage(editor, _appId, _docId, _src) {
88092
- const url = editor.doc.buildResourceUrl(_src, { withToken: true });
88093
- let file2 = await downloadImageToFile$1(url);
88094
- if (!file2)
88095
- return [void 0, url];
88096
- if (file2.type.indexOf("/svg") !== -1) {
88097
- const pngFile = await convertImageFileToPng(file2);
88098
- if (pngFile) {
88099
- 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);
88100
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);
88101
88128
  }
88102
- const arrayBuffer = await file2.arrayBuffer();
88103
- return [arrayBuffer, url];
88104
88129
  }
88105
88130
  async function getDocByBlock(editor, doc2, block) {
88106
88131
  const blockClass = editor.editorBlocks.getBlockClass(block.type);
@@ -88334,13 +88359,7 @@ ${data2.flowchartText}
88334
88359
  }
88335
88360
  }
88336
88361
  });
88337
- editor.version = "2.2.8-beta.5";
88338
- if (Logger$2.level === LogLevel.DEBUG) {
88339
- window.setReauthFail = (fail) => {
88340
- window.isReauthError = fail;
88341
- };
88342
- window.reConnect = (token) => editor.doc.externalDoc.client.connection.reConnect(token);
88343
- }
88362
+ editor.version = "2.2.8-beta.7";
88344
88363
  return editor;
88345
88364
  }
88346
88365
  function isDoc(doc2) {
@@ -88435,7 +88454,7 @@ ${data2.flowchartText}
88435
88454
  });
88436
88455
  editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
88437
88456
  OnesEditorToolbar.register(editor);
88438
- editor.version = "2.2.8-beta.5";
88457
+ editor.version = "2.2.8-beta.7";
88439
88458
  return editor;
88440
88459
  }
88441
88460
  async function showDocVersions(editor, options, serverUrl) {
@@ -134214,6 +134233,7 @@ ${data2.flowchartText}
134214
134233
  exports2.EmbedBlockResizer = EmbedBlockResizer;
134215
134234
  exports2.EnforceWithDocumentTitleHandler = EnforceWithDocumentTitleHandler;
134216
134235
  exports2.EventCallbacks = EventCallbacks;
134236
+ exports2.ExportImageError = ExportImageError;
134217
134237
  exports2.FILL_CHAR = FILL_CHAR;
134218
134238
  exports2.FileExtError = FileExtError;
134219
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.5",
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",