@ones-editor/editor 2.1.7-beta.19 → 2.1.7-beta.20

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.
@@ -28,6 +28,7 @@ export declare class Dropdown {
28
28
  close(): void;
29
29
  destroy(): void;
30
30
  updateItems(items: CommandItem[]): void;
31
+ getItems(): CommandItem[];
31
32
  setText(text: string): void;
32
33
  clear(): void;
33
34
  setLabels(labels: string[]): void;
@@ -5,6 +5,7 @@ export interface VersionDialogOptions {
5
5
  useCreatedBy?: boolean;
6
6
  enableEdit?: boolean;
7
7
  textRenders?: OnesEditorBlockRenderer[];
8
+ autoCompareWithLastVersion?: boolean;
8
9
  getDisabledTip?: () => string | undefined;
9
10
  onMemoChanged?: (version: DocVersion) => void;
10
11
  onBeforeEditMemo?: () => Promise<boolean>;
@@ -18,8 +18,10 @@ export default class VersionsDropdown {
18
18
  createFilterMemoedFilterItem: (hasLastVersion: boolean) => HTMLDivElement;
19
19
  setVersions(versions: DocVersion[]): void;
20
20
  setCurrentVersion(ver: DocVersion, compareWithVersion?: DocVersion): void;
21
+ setCompareWithVersion(compareWithVersion: DocVersion | null): void;
21
22
  resetItems(): void;
22
23
  filterItems: (item: CommandItem, keywords: string) => boolean;
24
+ getLastVersion(): DocVersion | null;
23
25
  handleClose: () => void;
24
26
  handleClear: () => void;
25
27
  handleClickItem: (item: CommandItem) => void;
package/dist/index.js CHANGED
@@ -41058,6 +41058,9 @@ ${codeText}
41058
41058
  this.items = items;
41059
41059
  this.autoSuggest.handleSearchText("");
41060
41060
  }
41061
+ getItems() {
41062
+ return this.items;
41063
+ }
41061
41064
  setText(text2) {
41062
41065
  this.text.innerText = text2;
41063
41066
  this.input.value = text2;
@@ -77470,6 +77473,26 @@ ${content}
77470
77473
  this.compareWithVersion = compareWithVersion != null ? compareWithVersion : null;
77471
77474
  this.resetItems();
77472
77475
  }
77476
+ setCompareWithVersion(compareWithVersion) {
77477
+ this.compareWithVersion = compareWithVersion;
77478
+ if (compareWithVersion) {
77479
+ const index2 = this.dropdown.getItems().findIndex((item) => {
77480
+ const version = item.data;
77481
+ if (version) {
77482
+ if (version.version === compareWithVersion.version && version.created === compareWithVersion.created) {
77483
+ return true;
77484
+ }
77485
+ }
77486
+ return false;
77487
+ });
77488
+ if (index2 !== -1) {
77489
+ const item = this.dropdown.getItems()[index2];
77490
+ this.dropdown.setText(item.name);
77491
+ }
77492
+ } else {
77493
+ this.dropdown.setText("");
77494
+ }
77495
+ }
77473
77496
  resetItems() {
77474
77497
  var _a;
77475
77498
  if (this.versions.length === 0) {
@@ -77585,6 +77608,13 @@ ${content}
77585
77608
  }
77586
77609
  this.dropdown.updateItems(items);
77587
77610
  }
77611
+ getLastVersion() {
77612
+ const lastItem = this.dropdown.getItems().find((item) => item.id === "last-version");
77613
+ if (lastItem) {
77614
+ return lastItem.data;
77615
+ }
77616
+ return null;
77617
+ }
77588
77618
  }
77589
77619
  class VersionInfoHeader {
77590
77620
  constructor(parent, options) {
@@ -77639,10 +77669,16 @@ ${content}
77639
77669
  var _a, _b;
77640
77670
  (_b = (_a = this.versionOptions) == null ? void 0 : _a.onHelp) == null ? void 0 : _b.call(_a);
77641
77671
  });
77642
- __publicField(this, "viewVersion", async (version, compareWithVersion) => {
77643
- var _a, _b, _c, _d;
77672
+ __publicField(this, "viewVersion", async (version, compareWithVersion, options) => {
77673
+ var _a, _b, _c, _d, _e;
77644
77674
  const isLatest = this.versions[0].created === version.created;
77645
77675
  this.components.infoHeader.setVersion(version, compareWithVersion, isLatest);
77676
+ if (!compareWithVersion && (options == null ? void 0 : options.autoCompareWithLastVersion)) {
77677
+ compareWithVersion = (_a = this.components.infoHeader.dropdown.getLastVersion()) != null ? _a : void 0;
77678
+ if (compareWithVersion) {
77679
+ this.components.infoHeader.dropdown.setCompareWithVersion(compareWithVersion);
77680
+ }
77681
+ }
77646
77682
  if (this.oldViewer) {
77647
77683
  this.oldViewer.destroy();
77648
77684
  this.oldViewer = null;
@@ -77650,7 +77686,7 @@ ${content}
77650
77686
  if (!this.versionList) {
77651
77687
  return;
77652
77688
  }
77653
- if (((_a = this.versionOptions) == null ? void 0 : _a.onWillChangeVersion) && !await this.versionOptions.onWillChangeVersion(this, version)) {
77689
+ if (((_b = this.versionOptions) == null ? void 0 : _b.onWillChangeVersion) && !await this.versionOptions.onWillChangeVersion(this, version)) {
77654
77690
  return;
77655
77691
  }
77656
77692
  this.renderEditorLoading();
@@ -77673,14 +77709,14 @@ ${content}
77673
77709
  const viewer = this.provider.createHistoryEditor(editorElement, historyDoc);
77674
77710
  viewer.editorBlockRenders.registerRender(new OnesEditorHistoryRender());
77675
77711
  viewer.editorBoxes.registerBoxClass(HistoryDeletedTextBox);
77676
- (_c = (_b = this.versionOptions) == null ? void 0 : _b.textRenders) == null ? void 0 : _c.forEach((render) => viewer.editorBlockRenders.registerRender(render));
77712
+ (_d = (_c = this.versionOptions) == null ? void 0 : _c.textRenders) == null ? void 0 : _d.forEach((render) => viewer.editorBlockRenders.registerRender(render));
77677
77713
  addClass(viewer.rootElement, HistoryClass.HISTORY);
77678
77714
  try {
77679
77715
  await playHistoryData(historyDoc, this.versionHelper, historyData);
77680
77716
  } finally {
77681
77717
  this.oldViewer = viewer;
77682
77718
  }
77683
- if ((_d = this.versionOptions) == null ? void 0 : _d.onVersionChanged) {
77719
+ if ((_e = this.versionOptions) == null ? void 0 : _e.onVersionChanged) {
77684
77720
  this.versionOptions.onVersionChanged(this, viewer, version);
77685
77721
  }
77686
77722
  });
@@ -77740,19 +77776,20 @@ ${content}
77740
77776
  this.versionList = versionList2;
77741
77777
  }
77742
77778
  initViewVersion() {
77743
- var _a;
77779
+ var _a, _b;
77780
+ const autoCompareWithLastVersion = (_a = this.versionOptions) == null ? void 0 : _a.autoCompareWithLastVersion;
77744
77781
  assert(logger$r, this.versionList, "no versionList");
77745
- if ((_a = this.versionOptions) == null ? void 0 : _a.initSelectedVersion) {
77782
+ if ((_b = this.versionOptions) == null ? void 0 : _b.initSelectedVersion) {
77746
77783
  const { initSelectedVersion: versionNumber } = this.versionOptions;
77747
77784
  const version2 = this.versionList.selectVersionByVersionNum(versionNumber);
77748
77785
  if (version2) {
77749
- this.viewVersion(version2);
77786
+ this.viewVersion(version2, void 0, { autoCompareWithLastVersion });
77750
77787
  return;
77751
77788
  }
77752
77789
  }
77753
77790
  const version = this.versionList.activeVersion;
77754
77791
  if (version) {
77755
- this.viewVersion(version);
77792
+ this.viewVersion(version, void 0, { autoCompareWithLastVersion });
77756
77793
  }
77757
77794
  }
77758
77795
  renderEditorLoading() {
@@ -87818,7 +87855,7 @@ ${data2.flowchartText}
87818
87855
  }
87819
87856
  }
87820
87857
  });
87821
- editor.version = "2.1.7-beta.19";
87858
+ editor.version = "2.1.7-beta.20";
87822
87859
  if (Logger$2.level === LogLevel.DEBUG) {
87823
87860
  window.setReauthFail = (fail) => {
87824
87861
  window.isReauthError = fail;
@@ -87937,7 +87974,7 @@ ${data2.flowchartText}
87937
87974
  }
87938
87975
  }
87939
87976
  OnesEditorToolbar.register(editor);
87940
- editor.version = "2.1.7-beta.19";
87977
+ editor.version = "2.1.7-beta.20";
87941
87978
  return editor;
87942
87979
  }
87943
87980
  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.1.7-beta.19",
3
+ "version": "2.1.7-beta.20",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",