@univerjs_ui_facade.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import {
  2. $e,
  3. Gl,
  4. L1,
  5. Le,
  6. Li,
  7. bi,
  8. f1,
  9. h3,
  10. it,
  11. l1,
  12. m1,
  13. n1,
  14. o3,
  15. rt,
  16. wt
  17. } from "./chunk-POAJ2YNP.js";
  18. import "./chunk-GBYP4PB2.js";
  19. import "./chunk-2MK3Q52E.js";
  20. import "./chunk-BSDDCPAW.js";
  21. import {
  22. B0,
  23. Fi,
  24. Ot,
  25. Pt,
  26. ar,
  27. ci,
  28. di,
  29. ot,
  30. pi,
  31. re
  32. } from "./chunk-23V3HWTR.js";
  33. import "./chunk-GNR2UJZM.js";
  34. import "./chunk-2LSFTFF7.js";
  35. // node_modules/.pnpm/@univerjs+ui@0.5.5_@grpc+grpc-js@1.13.4_react-dom@18.3.1_react@18.3.1_rxjs@7.8.1_typescript@5.4.5/node_modules/@univerjs/ui/lib/es/facade.js
  36. var x = Object.defineProperty;
  37. var U = (n, e, t) => e in n ? x(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
  38. var o = (n, e, t) => U(n, typeof e != "symbol" ? e + "" : e, t);
  39. var L = Object.defineProperty;
  40. var A = Object.getOwnPropertyDescriptor;
  41. var E = (n, e, t, r) => {
  42. for (var i = r > 1 ? void 0 : r ? A(e, t) : e, s = n.length - 1, c; s >= 0; s--)
  43. (c = n[s]) && (i = (r ? c(e, t, i) : c(i)) || i);
  44. return r && i && L(e, t, i), i;
  45. };
  46. var h = (n, e) => (t, r) => e(t, r, n);
  47. var a;
  48. var S = (a = class extends Fi {
  49. constructor(e, t, r, i) {
  50. super();
  51. o(this, "_commandToRegister", /* @__PURE__ */ new Map());
  52. o(this, "_buildingSchema");
  53. this._item = e, this._injector = t, this._commandService = r, this._menuManagerService = i;
  54. const s = typeof e.action == "string" ? e.action : re.generateRandomId(12);
  55. s !== e.action && this._commandToRegister.set(s, e.action), this._buildingSchema = {
  56. // eslint-disable-next-line ts/explicit-function-return-type
  57. menuItemFactory: () => ({
  58. id: e.id,
  59. type: $e.BUTTON,
  60. // we only support button for now
  61. icon: e.icon,
  62. title: e.title,
  63. tooltip: e.tooltip,
  64. commandId: s
  65. })
  66. }, typeof e.order < "u" && (this._buildingSchema.order = e.order);
  67. }
  68. /** @ignore */
  69. __getSchema() {
  70. return this._commandToRegister.forEach((e, t) => {
  71. this._commandService.hasCommand(t) || this._commandService.registerCommand({
  72. id: t,
  73. type: ar.COMMAND,
  74. handler: e
  75. });
  76. }), { [this._item.id]: this._buildingSchema };
  77. }
  78. /**
  79. * Append the menu to any menu position on Univer UI.
  80. * @param path Some predefined path to append the menu.
  81. */
  82. appendTo(e) {
  83. const t = this.__getSchema();
  84. this._menuManagerService.mergeMenu({
  85. [e]: t
  86. });
  87. }
  88. }, o(a, "RibbonStartGroup", l1), o(a, "RibbonPosition", L1), o(a, "MenuManagerPosition", wt), a);
  89. S = E([
  90. h(1, ot(Ot)),
  91. h(2, Pt),
  92. h(3, m1)
  93. ], S);
  94. var _ = class extends Fi {
  95. constructor(e, t, r) {
  96. super();
  97. o(this, "_menuByGroups", []);
  98. o(this, "_submenus", []);
  99. o(this, "_buildingSchema");
  100. this._item = e, this._injector = t, this._menuManagerService = r, this._buildingSchema = {
  101. // eslint-disable-next-line ts/explicit-function-return-type
  102. menuItemFactory: () => ({
  103. id: e.id,
  104. type: $e.SUBITEMS,
  105. icon: e.icon,
  106. title: e.title,
  107. tooltip: e.tooltip
  108. })
  109. }, typeof e.order < "u" && (this._buildingSchema.order = e.order);
  110. }
  111. /**
  112. * Add a menu to the submenu. It can be a {@link FMenu} or a {@link FSubmenu}.
  113. * @param submenu Menu to add to the submenu.
  114. * @returns The FSubmenu itself for chaining calls.
  115. */
  116. addSubmenu(e) {
  117. return this._submenus.push(e), this;
  118. }
  119. /**
  120. * Add a separator to the submenu.
  121. * @returns The FSubmenu itself for chaining calls.
  122. */
  123. addSeparator() {
  124. return this._menuByGroups.push(this._submenus), this._submenus = [], this;
  125. }
  126. /**
  127. * Append the menu to any menu position on Univer UI.
  128. * @param path Some predefined path to append the menu.
  129. */
  130. appendTo(e) {
  131. const t = this.__getSchema();
  132. this._menuManagerService.mergeMenu({
  133. [e]: t
  134. });
  135. }
  136. /** @ignore */
  137. __getSchema() {
  138. const e = {};
  139. return this.addSeparator(), this._menuByGroups.forEach((t, r) => {
  140. const i = {};
  141. t.forEach((s) => {
  142. Object.assign(i, s.__getSchema());
  143. }), e[`${this._item.id}-group-${r}`] = i;
  144. }), { [this._item.id]: Object.assign(this._buildingSchema, e) };
  145. }
  146. };
  147. _ = E([
  148. h(1, ot(Ot)),
  149. h(2, m1)
  150. ], _);
  151. var K = Object.defineProperty;
  152. var W = Object.getOwnPropertyDescriptor;
  153. var q = (n, e, t, r) => {
  154. for (var i = r > 1 ? void 0 : r ? W(e, t) : e, s = n.length - 1, c; s >= 0; s--)
  155. (c = n[s]) && (i = (r ? c(e, t, i) : c(i)) || i);
  156. return r && i && K(e, t, i), i;
  157. };
  158. var I = (n, e) => (t, r) => e(t, r, n);
  159. var g = class extends Fi {
  160. constructor(e, t) {
  161. super();
  162. o(this, "_forceEscapeDisposable", null);
  163. this._injector = e, this._shortcutService = t;
  164. }
  165. enableShortcut() {
  166. var e;
  167. (e = this._forceEscapeDisposable) == null || e.dispose(), this._forceEscapeDisposable = null;
  168. }
  169. disableShortcut() {
  170. this._forceEscapeDisposable || (this._forceEscapeDisposable = this._shortcutService.forceEscape());
  171. }
  172. dispatchShortcutEvent(e) {
  173. return this._shortcutService.dispatch(e);
  174. }
  175. };
  176. g = q([
  177. I(0, ot(Ot)),
  178. I(1, it)
  179. ], g);
  180. var z = class extends pi {
  181. getURL() {
  182. return new URL(window.location.href);
  183. }
  184. getShortcut() {
  185. return this._injector.createInstance(g);
  186. }
  187. copy() {
  188. return this._commandService.syncExecuteCommand(bi.id);
  189. }
  190. paste() {
  191. return this._commandService.syncExecuteCommand(Li.id);
  192. }
  193. createMenu(e) {
  194. return this._injector.createInstance(S, e);
  195. }
  196. createSubmenu(e) {
  197. return this._injector.createInstance(_, e);
  198. }
  199. openSiderbar(e) {
  200. return this._injector.get(rt).open(e);
  201. }
  202. openSidebar(e) {
  203. return this.openSiderbar(e);
  204. }
  205. openDialog(e) {
  206. const r = this._injector.get(h3).open({
  207. ...e,
  208. onClose: () => {
  209. r.dispose();
  210. }
  211. });
  212. return r;
  213. }
  214. getComponentManager() {
  215. return this._injector.get(n1);
  216. }
  217. showMessage(e) {
  218. return this._injector.get(o3).show(e), this;
  219. }
  220. setUIVisible(e, t) {
  221. return this._injector.get(f1).setUIVisible(e, t), this;
  222. }
  223. isUIVisible(e) {
  224. return this._injector.get(f1).isUIVisible(e);
  225. }
  226. registerUIPart(e, t) {
  227. return this._injector.get(f1).registerComponent(e, () => B0(t, this._injector));
  228. }
  229. registerComponent(e, t, r) {
  230. const i = this._injector.get(n1);
  231. return this.disposeWithMe(i.register(e, t, r));
  232. }
  233. };
  234. pi.extend(z);
  235. var J = class extends di {
  236. onBeforeCopy(e) {
  237. return this._injector.get(Pt).beforeCommandExecuted((r) => {
  238. r.id === bi.id && e();
  239. });
  240. }
  241. onCopy(e) {
  242. return this._injector.get(Pt).onCommandExecuted((r) => {
  243. r.id === bi.id && e();
  244. });
  245. }
  246. onBeforePaste(e) {
  247. return this._injector.get(Pt).beforeCommandExecuted((r) => {
  248. r.id === Li.id && e();
  249. });
  250. }
  251. onPaste(e) {
  252. return this._injector.get(Pt).onCommandExecuted((r) => {
  253. (r.id === Li.id || r.id === Gl) && e();
  254. });
  255. }
  256. };
  257. di.extend(J);
  258. var Q = class extends ci {
  259. get BuiltInUIPart() {
  260. return Le;
  261. }
  262. };
  263. ci.extend(Q);
  264. //# sourceMappingURL=@univerjs_ui_facade.js.map