facade.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { FUniver as k, ICommandService as l, IUniverInstanceService as w, CanceledError as f, RichTextValue as p, DOCS_ZEN_EDITOR_UNIT_ID_KEY as g } from "@univerjs/core";
  2. import { RichTextEditingMutation as x } from "@univerjs/docs";
  3. import { IEditorBridgeService as m } from "@univerjs/sheets-ui";
  4. import { OpenZenEditorCommand as u, CancelZenEditCommand as C, ConfirmZenEditCommand as S } from "@univerjs/sheets-zen-editor";
  5. import { FWorkbook as Z } from "@univerjs/sheets/facade";
  6. class T extends k {
  7. // eslint-disable-next-line max-lines-per-function
  8. _initSheetZenEditorEvent(t) {
  9. const E = t.get(l);
  10. this.disposeWithMe(E.beforeCommandExecuted((e) => {
  11. if (e.id === u.id || e.id === C.id || e.id === S.id) {
  12. if (!this._eventListend(this.Event.BeforeSheetEditStart) && !this._eventListend(this.Event.BeforeSheetEditEnd))
  13. return;
  14. const r = this.getCommandSheetTarget(e);
  15. if (!r)
  16. return;
  17. const { workbook: s, worksheet: o } = r, h = t.get(m), v = t.get(w), a = e.params, { keycode: d, eventType: n } = a, i = h.getEditLocation();
  18. if (e.id === u.id) {
  19. const c = {
  20. row: i.row,
  21. column: i.column,
  22. eventType: n,
  23. keycode: d,
  24. workbook: s,
  25. worksheet: o,
  26. isZenEditor: !0
  27. };
  28. if (this.fireEvent(this.Event.BeforeSheetEditStart, c), c.cancel)
  29. throw new f();
  30. } else {
  31. const c = {
  32. row: i.row,
  33. column: i.column,
  34. eventType: n,
  35. keycode: d,
  36. workbook: s,
  37. worksheet: o,
  38. isZenEditor: !0,
  39. value: p.create(v.getUnit(g).getSnapshot()),
  40. isConfirm: e.id === S.id
  41. };
  42. if (this.fireEvent(this.Event.BeforeSheetEditEnd, c), c.cancel)
  43. throw new f();
  44. }
  45. }
  46. })), this.disposeWithMe(E.onCommandExecuted((e) => {
  47. if (e.id === u.id || e.id === C.id || e.id === S.id) {
  48. if (!this._eventListend(this.Event.SheetEditStarted) && !this._eventListend(this.Event.SheetEditEnded))
  49. return;
  50. const r = this.getCommandSheetTarget(e);
  51. if (!r)
  52. return;
  53. const { workbook: s, worksheet: o } = r, h = t.get(m), v = e.params, { keycode: a, eventType: d } = v, n = h.getEditLocation();
  54. if (e.id === u.id) {
  55. const i = {
  56. row: n.row,
  57. column: n.column,
  58. eventType: d,
  59. keycode: a,
  60. workbook: s,
  61. worksheet: o,
  62. isZenEditor: !0
  63. };
  64. this.fireEvent(this.Event.SheetEditStarted, i);
  65. } else {
  66. const i = {
  67. row: n.row,
  68. column: n.column,
  69. eventType: d,
  70. keycode: a,
  71. workbook: s,
  72. worksheet: o,
  73. isZenEditor: !0,
  74. isConfirm: e.id === S.id
  75. };
  76. this.fireEvent(this.Event.SheetEditEnded, i);
  77. }
  78. }
  79. if (e.id === x.id) {
  80. if (!this._eventListend(this.Event.SheetEditChanging))
  81. return;
  82. const r = this.getCommandSheetTarget(e);
  83. if (!r)
  84. return;
  85. const { workbook: s, worksheet: o } = r, h = t.get(m), v = t.get(w), a = e.params;
  86. if (!h.isVisible().visible) return;
  87. const { unitId: d } = a;
  88. if (d === g) {
  89. const { row: n, column: i } = h.getEditLocation(), c = {
  90. workbook: s,
  91. worksheet: o,
  92. row: n,
  93. column: i,
  94. value: p.create(v.getUnit(g).getSnapshot()),
  95. isZenEditor: !0
  96. };
  97. this.fireEvent(this.Event.SheetEditChanging, c);
  98. }
  99. }
  100. }));
  101. }
  102. _initialize(t) {
  103. this._initSheetZenEditorEvent(t);
  104. }
  105. }
  106. k.extend(T);
  107. class b extends Z {
  108. startZenEditingAsync() {
  109. return this._injector.get(l).executeCommand(u.id);
  110. }
  111. endZenEditingAsync(t = !0) {
  112. const E = this._injector.get(l);
  113. return t ? E.executeCommand(S.id) : E.executeCommand(C.id);
  114. }
  115. }
  116. Z.extend(b);