@univerjs/ui 0.5.1 → 0.5.2

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.
package/lib/es/facade.js CHANGED
@@ -1,49 +1,204 @@
1
- import { FUniver as c, FHooks as d, ICommandService as i } from "@univerjs/core";
2
- import { CopyCommand as r, PasteCommand as t, ISidebarService as a, IDialogService as s, ComponentManager as S } from "@univerjs/ui";
3
- class v extends c {
1
+ var I = Object.defineProperty;
2
+ var P = (i, e, t) => e in i ? I(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var s = (i, e, t) => P(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Inject as g, Injector as l, ICommandService as d, FBase as v, Tools as x, CommandType as E, FUniver as f, FHooks as M } from "@univerjs/core";
5
+ import { IMenuManagerService as j, MenuItemType as C, RibbonStartGroup as D, RibbonPosition as O, MenuManagerPosition as T, IShortcutService as w, CopyCommand as m, PasteCommand as u, ISidebarService as B, IDialogService as F, ComponentManager as R, IMessageService as U, SheetPasteShortKeyCommandName as $ } from "@univerjs/ui";
6
+ var G = Object.defineProperty, N = Object.getOwnPropertyDescriptor, y = (i, e, t, r) => {
7
+ for (var n = r > 1 ? void 0 : r ? N(e, t) : e, o = i.length - 1, c; o >= 0; o--)
8
+ (c = i[o]) && (n = (r ? c(e, t, n) : c(n)) || n);
9
+ return r && n && G(e, t, n), n;
10
+ }, h = (i, e) => (t, r) => e(t, r, i), a;
11
+ let p = (a = class extends v {
12
+ constructor(e, t, r, n) {
13
+ super();
14
+ s(this, "_commandToRegister", /* @__PURE__ */ new Map());
15
+ s(this, "_buildingSchema");
16
+ this._item = e, this._injector = t, this._commandService = r, this._menuManagerService = n;
17
+ const o = typeof e.action == "string" ? e.action : x.generateRandomId(12);
18
+ o !== e.action && this._commandToRegister.set(o, e.action), this._buildingSchema = {
19
+ // eslint-disable-next-line ts/explicit-function-return-type
20
+ menuItemFactory: () => ({
21
+ id: e.id,
22
+ type: C.BUTTON,
23
+ // we only support button for now
24
+ icon: e.icon,
25
+ title: e.title,
26
+ tooltip: e.tooltip,
27
+ commandId: o
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: E.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
+ }, s(a, "RibbonStartGroup", D), s(a, "RibbonPosition", O), s(a, "MenuManagerPosition", T), a);
52
+ p = y([
53
+ h(1, g(l)),
54
+ h(2, d),
55
+ h(3, j)
56
+ ], p);
57
+ let S = class extends v {
58
+ constructor(e, t, r) {
59
+ super();
60
+ s(this, "_menuByGroups", []);
61
+ s(this, "_submenus", []);
62
+ s(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: C.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 n = {};
104
+ t.forEach((o) => {
105
+ Object.assign(n, o.__getSchema());
106
+ }), e[`${this._item.id}-group-${r}`] = n;
107
+ }), { [this._item.id]: Object.assign(this._buildingSchema, e) };
108
+ }
109
+ };
110
+ S = y([
111
+ h(1, g(l)),
112
+ h(2, j)
113
+ ], S);
114
+ var H = Object.defineProperty, L = Object.getOwnPropertyDescriptor, A = (i, e, t, r) => {
115
+ for (var n = r > 1 ? void 0 : r ? L(e, t) : e, o = i.length - 1, c; o >= 0; o--)
116
+ (c = i[o]) && (n = (r ? c(e, t, n) : c(n)) || n);
117
+ return r && n && H(e, t, n), n;
118
+ }, b = (i, e) => (t, r) => e(t, r, i);
119
+ let _ = class extends v {
120
+ constructor(e, t) {
121
+ super();
122
+ s(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
+ _ = A([
137
+ b(0, g(l)),
138
+ b(1, w)
139
+ ], _);
140
+ class K extends f {
141
+ getURL() {
142
+ return new URL(window.location.href);
143
+ }
144
+ getShortcut() {
145
+ return this._injector.createInstance(_);
146
+ }
4
147
  copy() {
5
- return this._commandService.executeCommand(r.id);
148
+ return this._commandService.executeCommand(m.id);
6
149
  }
7
150
  paste() {
8
- return this._commandService.executeCommand(t.id);
151
+ return this._commandService.executeCommand(u.id);
152
+ }
153
+ createMenu(e) {
154
+ return this._injector.createInstance(p, e);
155
+ }
156
+ createSubmenu(e) {
157
+ return this._injector.createInstance(S, e);
9
158
  }
10
159
  openSiderbar(e) {
11
- return this._injector.get(a).open(e);
160
+ return this._injector.get(B).open(e);
161
+ }
162
+ openSidebar(e) {
163
+ return this.openSiderbar(e);
12
164
  }
13
165
  openDialog(e) {
14
- const o = this._injector.get(s).open({
166
+ const r = this._injector.get(F).open({
15
167
  ...e,
16
168
  onClose: () => {
17
- o.dispose();
169
+ r.dispose();
18
170
  }
19
171
  });
20
- return o;
172
+ return r;
21
173
  }
22
174
  getComponentManager() {
23
- return this._injector.get(S);
175
+ return this._injector.get(R);
176
+ }
177
+ showMessage(e) {
178
+ this._injector.get(U).show(e);
24
179
  }
25
180
  }
26
- c.extend(v);
27
- class p extends d {
181
+ f.extend(K);
182
+ class q extends M {
28
183
  onBeforeCopy(e) {
29
- return this._injector.get(i).beforeCommandExecuted((o) => {
30
- o.id === r.id && e();
184
+ return this._injector.get(d).beforeCommandExecuted((r) => {
185
+ r.id === m.id && e();
31
186
  });
32
187
  }
33
188
  onCopy(e) {
34
- return this._injector.get(i).onCommandExecuted((o) => {
35
- o.id === r.id && e();
189
+ return this._injector.get(d).onCommandExecuted((r) => {
190
+ r.id === m.id && e();
36
191
  });
37
192
  }
38
193
  onBeforePaste(e) {
39
- return this._injector.get(i).beforeCommandExecuted((o) => {
40
- o.id === t.id && e();
194
+ return this._injector.get(d).beforeCommandExecuted((r) => {
195
+ r.id === u.id && e();
41
196
  });
42
197
  }
43
198
  onPaste(e) {
44
- return this._injector.get(i).onCommandExecuted((o) => {
45
- o.id === t.id && e();
199
+ return this._injector.get(d).onCommandExecuted((r) => {
200
+ (r.id === u.id || r.id === $) && e();
46
201
  });
47
202
  }
48
203
  }
49
- d.extend(p);
204
+ M.extend(q);