@ones-editor/editor 2.9.2 → 2.9.4

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
@@ -26523,6 +26523,9 @@ var __publicField = (obj, key, value) => {
26523
26523
  }
26524
26524
  }
26525
26525
  function editorScrollIntoView(editor) {
26526
+ if (!editor.scrollable()) {
26527
+ return;
26528
+ }
26526
26529
  if (!isElementVisible(editor.rootContainer)) {
26527
26530
  logger$3R.warn("editorScrollIntoView: editor is not visible");
26528
26531
  return;
@@ -31866,6 +31869,7 @@ ${codeText}
31866
31869
  __publicField(this, "inputHandlers", new EditorInputHandlers(this));
31867
31870
  __publicField(this, "settingsProvider");
31868
31871
  __publicField(this, "_readonly", false);
31872
+ __publicField(this, "_scrollable", true);
31869
31873
  __publicField(this, "getColor", (index2) => {
31870
31874
  const colors = this.options.colors;
31871
31875
  if (colors.length === 0) {
@@ -32094,6 +32098,12 @@ ${codeText}
32094
32098
  return false;
32095
32099
  return elem.closest("div.editor-root") === this.rootElement;
32096
32100
  }
32101
+ scrollable() {
32102
+ return this._scrollable;
32103
+ }
32104
+ setScrollable(scrollable2) {
32105
+ this._scrollable = scrollable2;
32106
+ }
32097
32107
  insertBlock(containerId, blockIndex, blockData, newRange, options) {
32098
32108
  const defaultPos = { blockId: blockData.id, offset: 0 };
32099
32109
  const defaultRange = { anchor: defaultPos, focus: defaultPos };
@@ -38204,6 +38214,7 @@ ${codeText}
38204
38214
  }
38205
38215
  try {
38206
38216
  origHandleMessage(msg);
38217
+ this.emit("opReceived");
38207
38218
  } catch (err) {
38208
38219
  if ((err == null ? void 0 : err.type) === "writeConflict") {
38209
38220
  this.emitWriteConflictError(err, msg);
@@ -39308,9 +39319,9 @@ ${codeText}
39308
39319
  }
39309
39320
  setStatus(status) {
39310
39321
  var _a, _b, _c;
39311
- if (status === "clean") {
39322
+ if (status === "clean" || status === "busy") {
39312
39323
  if (this.dirtyTimeout) {
39313
- logger$2U.info("on clean");
39324
+ logger$2U.info(`on ${status}`);
39314
39325
  clearTimeout(this.dirtyTimeout);
39315
39326
  this.dirtyTimeout = null;
39316
39327
  }
@@ -39382,6 +39393,9 @@ ${codeText}
39382
39393
  __publicField(this, "handleWriteConflictError", (error2) => {
39383
39394
  this.handleReset(`write conflict: ${error2.message}, ${JSON.stringify(error2.orgMsg)}`);
39384
39395
  });
39396
+ __publicField(this, "handleOpReceived", () => {
39397
+ this.editStatus.setStatus("busy");
39398
+ });
39385
39399
  __publicField(this, "insertObject", async (rootObjectName, index2, obj) => {
39386
39400
  const ops = [rootObjectName, index2, { i: obj }];
39387
39401
  return this.submitOp(ops);
@@ -39475,7 +39489,10 @@ ${codeText}
39475
39489
  if (containers.length === 0) {
39476
39490
  return Promise.resolve();
39477
39491
  }
39478
- const ops = containers.map(({ containerId, blocks }) => [docObjectContainerId2EditorDocContainerId(containerId), { i: blocks }]);
39492
+ const ops = containers.map(({ containerId, blocks }) => [
39493
+ docObjectContainerId2EditorDocContainerId(containerId),
39494
+ { i: blocks }
39495
+ ]);
39479
39496
  return this.submitOp([ops]);
39480
39497
  });
39481
39498
  __publicField(this, "submitDeleteChildContainer", async (containerId) => {
@@ -39494,7 +39511,10 @@ ${codeText}
39494
39511
  if (delta.delete.length === 0 && Object.keys(delta.insert).length === 0) {
39495
39512
  return Promise.resolve();
39496
39513
  }
39497
- const ops = [docObjectContainerId2EditorDocContainerId(containerId), index2];
39514
+ const ops = [
39515
+ docObjectContainerId2EditorDocContainerId(containerId),
39516
+ index2
39517
+ ];
39498
39518
  const deletedKeysSet = new Set(delta.delete);
39499
39519
  Object.entries(delta.insert).forEach(([key, value]) => {
39500
39520
  if (deletedKeysSet.has(key)) {
@@ -39545,6 +39565,7 @@ ${codeText}
39545
39565
  this.disableLogout = disableLogout;
39546
39566
  this.registerCallback(this.remoteCaretHandler);
39547
39567
  this.editStatus = new EditStatus(options);
39568
+ this.client.connection.addListener("opReceived", this.handleOpReceived);
39548
39569
  }
39549
39570
  beginBatchUpdate() {
39550
39571
  this.doc.preventCompose = false;
@@ -39729,7 +39750,9 @@ ${codeText}
39729
39750
  this.endBatchUpdate();
39730
39751
  }
39731
39752
  getComments() {
39732
- const comments = Object.values(this.data().comments).map((comment) => shareDBDocCommentToComment(comment));
39753
+ const comments = Object.values(this.data().comments).map(
39754
+ (comment) => shareDBDocCommentToComment(comment)
39755
+ );
39733
39756
  return comments;
39734
39757
  }
39735
39758
  getComment(commentId) {
@@ -39784,47 +39807,59 @@ ${codeText}
39784
39807
  }
39785
39808
  onDeleteBlock(containerId, blockIndex, local) {
39786
39809
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
39787
- this.callbacks.forEach((cb) => {
39788
- var _a;
39789
- return (_a = cb.onDeleteBlock) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, local);
39790
- });
39810
+ this.callbacks.forEach(
39811
+ (cb) => {
39812
+ var _a;
39813
+ return (_a = cb.onDeleteBlock) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, local);
39814
+ }
39815
+ );
39791
39816
  }
39792
39817
  onInsertBlock(containerId, blockIndex, data2, local) {
39793
39818
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
39794
- this.callbacks.forEach((cb) => {
39795
- var _a;
39796
- return (_a = cb.onInsertBlock) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, data2, local);
39797
- });
39819
+ this.callbacks.forEach(
39820
+ (cb) => {
39821
+ var _a;
39822
+ return (_a = cb.onInsertBlock) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, data2, local);
39823
+ }
39824
+ );
39798
39825
  }
39799
39826
  onUpdateBlockData(containerId, blockIndex, delta, local) {
39800
39827
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
39801
- this.callbacks.forEach((cb) => {
39802
- var _a;
39803
- return (_a = cb.onUpdateBlockData) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, delta, local);
39804
- });
39828
+ this.callbacks.forEach(
39829
+ (cb) => {
39830
+ var _a;
39831
+ return (_a = cb.onUpdateBlockData) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, delta, local);
39832
+ }
39833
+ );
39805
39834
  }
39806
39835
  onUpdateBlockText(containerId, blockIndex, actions2, local) {
39807
39836
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
39808
- this.callbacks.forEach((cb) => {
39809
- var _a;
39810
- return (_a = cb.onUpdateBlockText) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, actions2, local);
39811
- });
39837
+ this.callbacks.forEach(
39838
+ (cb) => {
39839
+ var _a;
39840
+ return (_a = cb.onUpdateBlockText) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blockIndex, actions2, local);
39841
+ }
39842
+ );
39812
39843
  }
39813
39844
  onDeleteContainer(containerId, local) {
39814
39845
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
39815
39846
  assert(logger$2T, containerId !== "root", "should not delete root container in doc");
39816
- this.callbacks.forEach((cb) => {
39817
- var _a;
39818
- return (_a = cb.onDeleteChildContainer) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), local);
39819
- });
39847
+ this.callbacks.forEach(
39848
+ (cb) => {
39849
+ var _a;
39850
+ return (_a = cb.onDeleteChildContainer) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), local);
39851
+ }
39852
+ );
39820
39853
  }
39821
39854
  onCreateContainer(containerId, blocks, local) {
39822
39855
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
39823
39856
  assert(logger$2T, containerId !== "root", "should not create root container in doc");
39824
- this.callbacks.forEach((cb) => {
39825
- var _a;
39826
- return (_a = cb.onInsertChildContainer) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blocks, local);
39827
- });
39857
+ this.callbacks.forEach(
39858
+ (cb) => {
39859
+ var _a;
39860
+ return (_a = cb.onInsertChildContainer) == null ? void 0 : _a.call(cb, editorDpcContainerId2DocObjectContainerId(containerId), blocks, local);
39861
+ }
39862
+ );
39828
39863
  }
39829
39864
  onDeleteComment(commentId, local) {
39830
39865
  assert(logger$2T, this.callbacks.length > 0, "no callbacks");
@@ -70367,6 +70402,9 @@ ${codeText}
70367
70402
  }
70368
70403
  });
70369
70404
  __publicField(this, "handleSelectionChanged", () => {
70405
+ if (!this.editor.scrollable()) {
70406
+ return;
70407
+ }
70370
70408
  setTimeout(() => {
70371
70409
  var _a;
70372
70410
  if (this.type !== "current") {
@@ -70981,7 +71019,14 @@ ${codeText}
70981
71019
  }
70982
71020
  onCreateComment(commentId, local) {
70983
71021
  const comment = this.commentsProvider.getComment(commentId);
70984
- this.list.handleCreateComment(comment, local);
71022
+ try {
71023
+ this.editor.setScrollable(false);
71024
+ this.list.handleCreateComment(comment, local);
71025
+ } finally {
71026
+ setTimeout(() => {
71027
+ this.editor.setScrollable(true);
71028
+ }, 1e3);
71029
+ }
70985
71030
  this.updateCommentCount();
70986
71031
  }
70987
71032
  onDeleteComment(commentId, local) {
@@ -71653,7 +71698,14 @@ ${codeText}
71653
71698
  const range = createBlockSimpleRange(editor, block, selectedBlock.start.offset, selectedBlock.end.offset);
71654
71699
  const command = `comment-${comment.id.toLocaleLowerCase()}`;
71655
71700
  const value = comment.id;
71656
- editorAddTextAttribute(editor, block, range, command, value);
71701
+ try {
71702
+ editor.setScrollable(false);
71703
+ editorAddTextAttribute(editor, block, range, command, value);
71704
+ } finally {
71705
+ setTimeout(() => {
71706
+ editor.setScrollable(true);
71707
+ }, 1e3);
71708
+ }
71657
71709
  }
71658
71710
  function addCommentToTextBlocks(editor, range, provider) {
71659
71711
  const selectedBlocks = getAllSelectedBlocks(editor, { range });
@@ -94084,9 +94136,19 @@ ${JSON.stringify(error2, null, 2)}`);
94084
94136
  __publicField(this, "id", "comment");
94085
94137
  __publicField(this, "name", i18n$1.t("comment.command"));
94086
94138
  __publicField(this, "icon", CommentIcon$1);
94139
+ __publicField(this, "adding", false);
94087
94140
  }
94088
94141
  onClick(editor, item) {
94089
- editorAddComment(editor);
94142
+ if (this.adding) {
94143
+ return;
94144
+ }
94145
+ this.adding = true;
94146
+ setTimeout(() => {
94147
+ editorAddComment(editor);
94148
+ setTimeout(() => {
94149
+ this.adding = false;
94150
+ }, 300);
94151
+ }, 300);
94090
94152
  }
94091
94153
  }
94092
94154
  class ColorItem extends TextColorItem {
@@ -94697,7 +94759,7 @@ ${JSON.stringify(error2, null, 2)}`);
94697
94759
  }
94698
94760
  }
94699
94761
  });
94700
- editor.version = "2.9.2";
94762
+ editor.version = "2.9.4";
94701
94763
  return editor;
94702
94764
  }
94703
94765
  function isDoc(doc2) {
@@ -94811,7 +94873,7 @@ ${JSON.stringify(error2, null, 2)}`);
94811
94873
  }
94812
94874
  });
94813
94875
  OnesEditorToolbar.register(editor);
94814
- editor.version = "2.9.2";
94876
+ editor.version = "2.9.4";
94815
94877
  return editor;
94816
94878
  }
94817
94879
  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.9.2",
3
+ "version": "2.9.4",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {