facade.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. var x = Object.defineProperty;
  2. var U = (n, e, t) => e in n ? x(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
  3. var o = (n, e, t) => U(n, typeof e != "symbol" ? e + "" : e, t);
  4. import { Inject as l, Injector as v, ICommandService as u, FBase as b, Tools as B, CommandType as D, FUniver as j, connectInjector as F, FHooks as P, FEnum as M } from "@univerjs/core";
  5. import { IMenuManagerService as C, MenuItemType as y, RibbonStartGroup as O, RibbonPosition as T, MenuManagerPosition as w, IShortcutService as R, CopyCommand as m, PasteCommand as p, ISidebarService as $, IDialogService as G, ComponentManager as f, IMessageService as V, IUIPartsService as d, SheetPasteShortKeyCommandName as N, BuiltInUIPart as H } from "@univerjs/ui";
  6. var L = Object.defineProperty, A = Object.getOwnPropertyDescriptor, E = (n, e, t, r) => {
  7. for (var i = r > 1 ? void 0 : r ? A(e, t) : e, s = n.length - 1, c; s >= 0; s--)
  8. (c = n[s]) && (i = (r ? c(e, t, i) : c(i)) || i);
  9. return r && i && L(e, t, i), i;
  10. }, h = (n, e) => (t, r) => e(t, r, n), a;
  11. let S = (a = class extends b {
  12. constructor(e, t, r, i) {
  13. super();
  14. o(this, "_commandToRegister", /* @__PURE__ */ new Map());
  15. o(this, "_buildingSchema");
  16. this._item = e, this._injector = t, this._commandService = r, this._menuManagerService = i;
  17. const s = typeof e.action == "string" ? e.action : B.generateRandomId(12);
  18. s !== e.action && this._commandToRegister.set(s, e.action), this._buildingSchema = {
  19. // eslint-disable-next-line ts/explicit-function-return-type
  20. menuItemFactory: () => ({
  21. id: e.id,
  22. type: y.BUTTON,
  23. // we only support button for now
  24. icon: e.icon,
  25. title: e.title,
  26. tooltip: e.tooltip,
  27. commandId: s
  28. })
  29. }, typeof e.order < "u" && (this._buildingSchema.order = e.order);
  30. }
  31. /** @ignore */
  32. __getSchema() {
  33. return this._commandToRegister.forEach((e, t) => {
  34. this._commandService.hasCommand(t) || this._commandService.registerCommand({
  35. id: t,
  36. type: D.COMMAND,
  37. handler: e
  38. });
  39. }), { [this._item.id]: this._buildingSchema };
  40. }
  41. /**
  42. * Append the menu to any menu position on Univer UI.
  43. * @param path Some predefined path to append the menu.
  44. */
  45. appendTo(e) {
  46. const t = this.__getSchema();
  47. this._menuManagerService.mergeMenu({
  48. [e]: t
  49. });
  50. }
  51. }, o(a, "RibbonStartGroup", O), o(a, "RibbonPosition", T), o(a, "MenuManagerPosition", w), a);
  52. S = E([
  53. h(1, l(v)),
  54. h(2, u),
  55. h(3, C)
  56. ], S);
  57. let _ = class extends b {
  58. constructor(e, t, r) {
  59. super();
  60. o(this, "_menuByGroups", []);
  61. o(this, "_submenus", []);
  62. o(this, "_buildingSchema");
  63. this._item = e, this._injector = t, this._menuManagerService = r, this._buildingSchema = {
  64. // eslint-disable-next-line ts/explicit-function-return-type
  65. menuItemFactory: () => ({
  66. id: e.id,
  67. type: y.SUBITEMS,
  68. icon: e.icon,
  69. title: e.title,
  70. tooltip: e.tooltip
  71. })
  72. }, typeof e.order < "u" && (this._buildingSchema.order = e.order);
  73. }
  74. /**
  75. * Add a menu to the submenu. It can be a {@link FMenu} or a {@link FSubmenu}.
  76. * @param submenu Menu to add to the submenu.
  77. * @returns The FSubmenu itself for chaining calls.
  78. */
  79. addSubmenu(e) {
  80. return this._submenus.push(e), this;
  81. }
  82. /**
  83. * Add a separator to the submenu.
  84. * @returns The FSubmenu itself for chaining calls.
  85. */
  86. addSeparator() {
  87. return this._menuByGroups.push(this._submenus), this._submenus = [], this;
  88. }
  89. /**
  90. * Append the menu to any menu position on Univer UI.
  91. * @param path Some predefined path to append the menu.
  92. */
  93. appendTo(e) {
  94. const t = this.__getSchema();
  95. this._menuManagerService.mergeMenu({
  96. [e]: t
  97. });
  98. }
  99. /** @ignore */
  100. __getSchema() {
  101. const e = {};
  102. return this.addSeparator(), this._menuByGroups.forEach((t, r) => {
  103. const i = {};
  104. t.forEach((s) => {
  105. Object.assign(i, s.__getSchema());
  106. }), e[`${this._item.id}-group-${r}`] = i;
  107. }), { [this._item.id]: Object.assign(this._buildingSchema, e) };
  108. }
  109. };
  110. _ = E([
  111. h(1, l(v)),
  112. h(2, C)
  113. ], _);
  114. var K = Object.defineProperty, W = Object.getOwnPropertyDescriptor, q = (n, e, t, r) => {
  115. for (var i = r > 1 ? void 0 : r ? W(e, t) : e, s = n.length - 1, c; s >= 0; s--)
  116. (c = n[s]) && (i = (r ? c(e, t, i) : c(i)) || i);
  117. return r && i && K(e, t, i), i;
  118. }, I = (n, e) => (t, r) => e(t, r, n);
  119. let g = class extends b {
  120. constructor(e, t) {
  121. super();
  122. o(this, "_forceEscapeDisposable", null);
  123. this._injector = e, this._shortcutService = t;
  124. }
  125. enableShortcut() {
  126. var e;
  127. (e = this._forceEscapeDisposable) == null || e.dispose(), this._forceEscapeDisposable = null;
  128. }
  129. disableShortcut() {
  130. this._forceEscapeDisposable || (this._forceEscapeDisposable = this._shortcutService.forceEscape());
  131. }
  132. dispatchShortcutEvent(e) {
  133. return this._shortcutService.dispatch(e);
  134. }
  135. };
  136. g = q([
  137. I(0, l(v)),
  138. I(1, R)
  139. ], g);
  140. class z extends j {
  141. getURL() {
  142. return new URL(window.location.href);
  143. }
  144. getShortcut() {
  145. return this._injector.createInstance(g);
  146. }
  147. copy() {
  148. return this._commandService.syncExecuteCommand(m.id);
  149. }
  150. paste() {
  151. return this._commandService.syncExecuteCommand(p.id);
  152. }
  153. createMenu(e) {
  154. return this._injector.createInstance(S, e);
  155. }
  156. createSubmenu(e) {
  157. return this._injector.createInstance(_, e);
  158. }
  159. openSiderbar(e) {
  160. return this._injector.get($).open(e);
  161. }
  162. openSidebar(e) {
  163. return this.openSiderbar(e);
  164. }
  165. openDialog(e) {
  166. const r = this._injector.get(G).open({
  167. ...e,
  168. onClose: () => {
  169. r.dispose();
  170. }
  171. });
  172. return r;
  173. }
  174. getComponentManager() {
  175. return this._injector.get(f);
  176. }
  177. showMessage(e) {
  178. return this._injector.get(V).show(e), this;
  179. }
  180. setUIVisible(e, t) {
  181. return this._injector.get(d).setUIVisible(e, t), this;
  182. }
  183. isUIVisible(e) {
  184. return this._injector.get(d).isUIVisible(e);
  185. }
  186. registerUIPart(e, t) {
  187. return this._injector.get(d).registerComponent(e, () => F(t, this._injector));
  188. }
  189. registerComponent(e, t, r) {
  190. const i = this._injector.get(f);
  191. return this.disposeWithMe(i.register(e, t, r));
  192. }
  193. }
  194. j.extend(z);
  195. class J extends P {
  196. onBeforeCopy(e) {
  197. return this._injector.get(u).beforeCommandExecuted((r) => {
  198. r.id === m.id && e();
  199. });
  200. }
  201. onCopy(e) {
  202. return this._injector.get(u).onCommandExecuted((r) => {
  203. r.id === m.id && e();
  204. });
  205. }
  206. onBeforePaste(e) {
  207. return this._injector.get(u).beforeCommandExecuted((r) => {
  208. r.id === p.id && e();
  209. });
  210. }
  211. onPaste(e) {
  212. return this._injector.get(u).onCommandExecuted((r) => {
  213. (r.id === p.id || r.id === N) && e();
  214. });
  215. }
  216. }
  217. P.extend(J);
  218. class Q extends M {
  219. get BuiltInUIPart() {
  220. return H;
  221. }
  222. }
  223. M.extend(Q);