| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- var x = Object.defineProperty;
- var U = (n, e, t) => e in n ? x(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
- var o = (n, e, t) => U(n, typeof e != "symbol" ? e + "" : e, t);
- 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";
- 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";
- var L = Object.defineProperty, A = Object.getOwnPropertyDescriptor, E = (n, e, t, r) => {
- for (var i = r > 1 ? void 0 : r ? A(e, t) : e, s = n.length - 1, c; s >= 0; s--)
- (c = n[s]) && (i = (r ? c(e, t, i) : c(i)) || i);
- return r && i && L(e, t, i), i;
- }, h = (n, e) => (t, r) => e(t, r, n), a;
- let S = (a = class extends b {
- constructor(e, t, r, i) {
- super();
- o(this, "_commandToRegister", /* @__PURE__ */ new Map());
- o(this, "_buildingSchema");
- this._item = e, this._injector = t, this._commandService = r, this._menuManagerService = i;
- const s = typeof e.action == "string" ? e.action : B.generateRandomId(12);
- s !== e.action && this._commandToRegister.set(s, e.action), this._buildingSchema = {
- // eslint-disable-next-line ts/explicit-function-return-type
- menuItemFactory: () => ({
- id: e.id,
- type: y.BUTTON,
- // we only support button for now
- icon: e.icon,
- title: e.title,
- tooltip: e.tooltip,
- commandId: s
- })
- }, typeof e.order < "u" && (this._buildingSchema.order = e.order);
- }
- /** @ignore */
- __getSchema() {
- return this._commandToRegister.forEach((e, t) => {
- this._commandService.hasCommand(t) || this._commandService.registerCommand({
- id: t,
- type: D.COMMAND,
- handler: e
- });
- }), { [this._item.id]: this._buildingSchema };
- }
- /**
- * Append the menu to any menu position on Univer UI.
- * @param path Some predefined path to append the menu.
- */
- appendTo(e) {
- const t = this.__getSchema();
- this._menuManagerService.mergeMenu({
- [e]: t
- });
- }
- }, o(a, "RibbonStartGroup", O), o(a, "RibbonPosition", T), o(a, "MenuManagerPosition", w), a);
- S = E([
- h(1, l(v)),
- h(2, u),
- h(3, C)
- ], S);
- let _ = class extends b {
- constructor(e, t, r) {
- super();
- o(this, "_menuByGroups", []);
- o(this, "_submenus", []);
- o(this, "_buildingSchema");
- this._item = e, this._injector = t, this._menuManagerService = r, this._buildingSchema = {
- // eslint-disable-next-line ts/explicit-function-return-type
- menuItemFactory: () => ({
- id: e.id,
- type: y.SUBITEMS,
- icon: e.icon,
- title: e.title,
- tooltip: e.tooltip
- })
- }, typeof e.order < "u" && (this._buildingSchema.order = e.order);
- }
- /**
- * Add a menu to the submenu. It can be a {@link FMenu} or a {@link FSubmenu}.
- * @param submenu Menu to add to the submenu.
- * @returns The FSubmenu itself for chaining calls.
- */
- addSubmenu(e) {
- return this._submenus.push(e), this;
- }
- /**
- * Add a separator to the submenu.
- * @returns The FSubmenu itself for chaining calls.
- */
- addSeparator() {
- return this._menuByGroups.push(this._submenus), this._submenus = [], this;
- }
- /**
- * Append the menu to any menu position on Univer UI.
- * @param path Some predefined path to append the menu.
- */
- appendTo(e) {
- const t = this.__getSchema();
- this._menuManagerService.mergeMenu({
- [e]: t
- });
- }
- /** @ignore */
- __getSchema() {
- const e = {};
- return this.addSeparator(), this._menuByGroups.forEach((t, r) => {
- const i = {};
- t.forEach((s) => {
- Object.assign(i, s.__getSchema());
- }), e[`${this._item.id}-group-${r}`] = i;
- }), { [this._item.id]: Object.assign(this._buildingSchema, e) };
- }
- };
- _ = E([
- h(1, l(v)),
- h(2, C)
- ], _);
- var K = Object.defineProperty, W = Object.getOwnPropertyDescriptor, q = (n, e, t, r) => {
- for (var i = r > 1 ? void 0 : r ? W(e, t) : e, s = n.length - 1, c; s >= 0; s--)
- (c = n[s]) && (i = (r ? c(e, t, i) : c(i)) || i);
- return r && i && K(e, t, i), i;
- }, I = (n, e) => (t, r) => e(t, r, n);
- let g = class extends b {
- constructor(e, t) {
- super();
- o(this, "_forceEscapeDisposable", null);
- this._injector = e, this._shortcutService = t;
- }
- enableShortcut() {
- var e;
- (e = this._forceEscapeDisposable) == null || e.dispose(), this._forceEscapeDisposable = null;
- }
- disableShortcut() {
- this._forceEscapeDisposable || (this._forceEscapeDisposable = this._shortcutService.forceEscape());
- }
- dispatchShortcutEvent(e) {
- return this._shortcutService.dispatch(e);
- }
- };
- g = q([
- I(0, l(v)),
- I(1, R)
- ], g);
- class z extends j {
- getURL() {
- return new URL(window.location.href);
- }
- getShortcut() {
- return this._injector.createInstance(g);
- }
- copy() {
- return this._commandService.syncExecuteCommand(m.id);
- }
- paste() {
- return this._commandService.syncExecuteCommand(p.id);
- }
- createMenu(e) {
- return this._injector.createInstance(S, e);
- }
- createSubmenu(e) {
- return this._injector.createInstance(_, e);
- }
- openSiderbar(e) {
- return this._injector.get($).open(e);
- }
- openSidebar(e) {
- return this.openSiderbar(e);
- }
- openDialog(e) {
- const r = this._injector.get(G).open({
- ...e,
- onClose: () => {
- r.dispose();
- }
- });
- return r;
- }
- getComponentManager() {
- return this._injector.get(f);
- }
- showMessage(e) {
- return this._injector.get(V).show(e), this;
- }
- setUIVisible(e, t) {
- return this._injector.get(d).setUIVisible(e, t), this;
- }
- isUIVisible(e) {
- return this._injector.get(d).isUIVisible(e);
- }
- registerUIPart(e, t) {
- return this._injector.get(d).registerComponent(e, () => F(t, this._injector));
- }
- registerComponent(e, t, r) {
- const i = this._injector.get(f);
- return this.disposeWithMe(i.register(e, t, r));
- }
- }
- j.extend(z);
- class J extends P {
- onBeforeCopy(e) {
- return this._injector.get(u).beforeCommandExecuted((r) => {
- r.id === m.id && e();
- });
- }
- onCopy(e) {
- return this._injector.get(u).onCommandExecuted((r) => {
- r.id === m.id && e();
- });
- }
- onBeforePaste(e) {
- return this._injector.get(u).beforeCommandExecuted((r) => {
- r.id === p.id && e();
- });
- }
- onPaste(e) {
- return this._injector.get(u).onCommandExecuted((r) => {
- (r.id === p.id || r.id === N) && e();
- });
- }
- }
- P.extend(J);
- class Q extends M {
- get BuiltInUIPart() {
- return H;
- }
- }
- M.extend(Q);
|