@univerjs/ui 0.20.1 → 0.21.0-insiders.20260422-d7fcb4d

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.
Files changed (45) hide show
  1. package/lib/cjs/facade.js +501 -1
  2. package/lib/cjs/index.js +8117 -87
  3. package/lib/cjs/locale/ca-ES.js +79 -1
  4. package/lib/cjs/locale/en-US.js +94 -1
  5. package/lib/cjs/locale/es-ES.js +79 -1
  6. package/lib/cjs/locale/fa-IR.js +79 -1
  7. package/lib/cjs/locale/fr-FR.js +79 -1
  8. package/lib/cjs/locale/ja-JP.js +79 -1
  9. package/lib/cjs/locale/ko-KR.js +79 -1
  10. package/lib/cjs/locale/ru-RU.js +79 -1
  11. package/lib/cjs/locale/sk-SK.js +79 -1
  12. package/lib/cjs/locale/vi-VN.js +79 -1
  13. package/lib/cjs/locale/zh-CN.js +79 -1
  14. package/lib/cjs/locale/zh-TW.js +79 -1
  15. package/lib/es/facade.js +502 -1
  16. package/lib/es/index.js +7765 -87
  17. package/lib/es/locale/ca-ES.js +78 -1
  18. package/lib/es/locale/en-US.js +93 -1
  19. package/lib/es/locale/es-ES.js +78 -1
  20. package/lib/es/locale/fa-IR.js +78 -1
  21. package/lib/es/locale/fr-FR.js +78 -1
  22. package/lib/es/locale/ja-JP.js +78 -1
  23. package/lib/es/locale/ko-KR.js +78 -1
  24. package/lib/es/locale/ru-RU.js +78 -1
  25. package/lib/es/locale/sk-SK.js +78 -1
  26. package/lib/es/locale/vi-VN.js +78 -1
  27. package/lib/es/locale/zh-CN.js +78 -1
  28. package/lib/es/locale/zh-TW.js +78 -1
  29. package/lib/facade.js +502 -1
  30. package/lib/index.js +7765 -87
  31. package/lib/locale/ca-ES.js +78 -1
  32. package/lib/locale/en-US.js +93 -1
  33. package/lib/locale/es-ES.js +78 -1
  34. package/lib/locale/fa-IR.js +78 -1
  35. package/lib/locale/fr-FR.js +78 -1
  36. package/lib/locale/ja-JP.js +78 -1
  37. package/lib/locale/ko-KR.js +78 -1
  38. package/lib/locale/ru-RU.js +78 -1
  39. package/lib/locale/sk-SK.js +78 -1
  40. package/lib/locale/vi-VN.js +78 -1
  41. package/lib/locale/zh-CN.js +78 -1
  42. package/lib/locale/zh-TW.js +78 -1
  43. package/lib/umd/index.js +6 -6
  44. package/package.json +8 -8
  45. package/LICENSE +0 -176
package/lib/cjs/facade.js CHANGED
@@ -1 +1,501 @@
1
- let e=require(`@univerjs/core/facade`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/ui`),r=require(`@univerjs/core`);function i(e){"@babel/helpers - typeof";return i=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){return function(n,r){t(n,r,e)}}function l(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var u=class extends e.FBase{appendTo(e){let t=typeof e==`string`?e.split(`|`):e,n=t.length,r={},i=r,a=this.__getSchema();t.forEach((e,t)=>{t===n-1?i[e]=a:i[e]={},i=i[e]}),this._menuManagerService.mergeMenu(r)}};let d=class extends u{constructor(e,t,i,a){super(),this._item=e,this._injector=t,this._commandService=i,this._menuManagerService=a,s(this,`_commandToRegister`,new Map),s(this,`_buildingSchema`,void 0);let o=typeof e.action==`string`?e.action:(0,r.generateRandomId)(12);o!==e.action&&this._commandToRegister.set(o,e.action),this._buildingSchema={menuItemFactory:()=>({id:e.id,type:n.MenuItemType.BUTTON,icon:e.icon,title:e.title,tooltip:e.tooltip,commandId:o})},e.order!==void 0&&(this._buildingSchema.order=e.order)}__getSchema(){return this._commandToRegister.forEach((e,t)=>{this._commandService.hasCommand(t)||this._commandService.registerCommand({id:t,type:r.CommandType.COMMAND,handler:e})}),{[this._item.id]:this._buildingSchema}}};s(d,`RibbonStartGroup`,n.RibbonStartGroup),s(d,`RibbonPosition`,n.RibbonPosition),s(d,`MenuManagerPosition`,n.MenuManagerPosition),d=l([c(1,(0,r.Inject)(r.Injector)),c(2,r.ICommandService),c(3,n.IMenuManagerService)],d);let f=class extends u{constructor(e,t,r){super(),this._item=e,this._injector=t,this._menuManagerService=r,s(this,`_menuByGroups`,[]),s(this,`_submenus`,[]),s(this,`_buildingSchema`,void 0),this._buildingSchema={menuItemFactory:()=>({id:e.id,type:n.MenuItemType.SUBITEMS,icon:e.icon,title:e.title,tooltip:e.tooltip})},e.order!==void 0&&(this._buildingSchema.order=e.order)}addSubmenu(e){return this._submenus.push(e),this}addSeparator(){return this._menuByGroups.push(this._submenus),this._submenus=[],this}__getSchema(){let e={};return this.addSeparator(),this._menuByGroups.forEach((t,n)=>{let r={};t.forEach(e=>{Object.assign(r,e.__getSchema())}),e[`${this._item.id}-group-${n}`]=r}),{[this._item.id]:Object.assign(this._buildingSchema,e)}}};f=l([c(1,(0,r.Inject)(r.Injector)),c(2,n.IMenuManagerService)],f);let p=class extends e.FBase{constructor(e,t,n,r){super(),this._injector=e,this._renderManagerService=t,this._univerInstanceService=n,this._shortcutService=r,s(this,`_forceDisableDisposable`,null)}enableShortcut(){var e;return(e=this._forceDisableDisposable)==null||e.dispose(),this._forceDisableDisposable=null,this}disableShortcut(){return this._forceDisableDisposable||(this._forceDisableDisposable=this._shortcutService.forceDisable()),this}triggerShortcut(e){let t=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!t)return;let n=this._renderManagerService.getRenderById(t.getUnitId());if(n)return n.engine.getCanvasElement().dispatchEvent(e),this._shortcutService.dispatch(e)}dispatchShortcutEvent(e){return this._shortcutService.dispatch(e)}};p=l([c(0,(0,r.Inject)(r.Injector)),c(1,(0,r.Inject)(t.IRenderManagerService)),c(2,r.IUniverInstanceService),c(3,n.IShortcutService)],p);var m=class extends e.FUniver{getURL(){return new URL(window.location.href)}getShortcut(){return this._injector.createInstance(p)}copy(){return this._commandService.executeCommand(n.CopyCommand.id)}paste(){return this._commandService.executeCommand(n.PasteCommand.id)}createMenu(e){return this._injector.createInstance(d,e)}createSubmenu(e){return this._injector.createInstance(f,e)}openSiderbar(e){return this._injector.get(n.ISidebarService).open(e)}openSidebar(e){return this.openSiderbar(e)}openDialog(e){let t=this._injector.get(n.IDialogService).open({...e,onClose:()=>{t.dispose()}});return t}getComponentManager(){return this._injector.get(n.ComponentManager)}showMessage(e){return this._injector.get(n.IMessageService).show(e),this}setUIVisible(e,t){return this._injector.get(n.IUIPartsService).setUIVisible(e,t),this}isUIVisible(e){return this._injector.get(n.IUIPartsService).isUIVisible(e)}registerUIPart(e,t){return this._injector.get(n.IUIPartsService).registerComponent(e,()=>(0,n.connectInjector)(t,this._injector))}registerComponent(e,t,r){let i=this._injector.get(n.ComponentManager);return this.disposeWithMe(i.register(e,t,r))}setCurrent(e){if(!this._injector.get(t.IRenderManagerService).getRenderById(e))throw Error(`Unit not found`);this._univerInstanceService.setCurrentUnitForType(e)}addFonts(e){let t=this._injector.get(n.IFontService);e.forEach(e=>{t.addFont(e)})}};e.FUniver.extend(m);var h=class extends e.FHooks{onBeforeCopy(e){return this._injector.get(r.ICommandService).beforeCommandExecuted(t=>{t.id===n.CopyCommand.id&&e()})}onCopy(e){return this._injector.get(r.ICommandService).onCommandExecuted(t=>{t.id===n.CopyCommand.id&&e()})}onBeforePaste(e){return this._injector.get(r.ICommandService).beforeCommandExecuted(t=>{t.id===n.PasteCommand.id&&e()})}onPaste(e){return this._injector.get(r.ICommandService).onCommandExecuted(t=>{(t.id===n.PasteCommand.id||t.id===n.SheetPasteShortKeyCommandName)&&e()})}};e.FHooks.extend(h);var g=class extends e.FEnum{get BuiltInUIPart(){return n.BuiltInUIPart}get KeyCode(){return n.KeyCode}};e.FEnum.extend(g);
1
+ let _univerjs_core_facade = require("@univerjs/core/facade");
2
+ let _univerjs_engine_render = require("@univerjs/engine-render");
3
+ let _univerjs_ui = require("@univerjs/ui");
4
+ let _univerjs_core = require("@univerjs/core");
5
+
6
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
7
+ function _typeof(o) {
8
+ "@babel/helpers - typeof";
9
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
10
+ return typeof o;
11
+ } : function(o) {
12
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
13
+ }, _typeof(o);
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
18
+ function toPrimitive(t, r) {
19
+ if ("object" != _typeof(t) || !t) return t;
20
+ var e = t[Symbol.toPrimitive];
21
+ if (void 0 !== e) {
22
+ var i = e.call(t, r || "default");
23
+ if ("object" != _typeof(i)) return i;
24
+ throw new TypeError("@@toPrimitive must return a primitive value.");
25
+ }
26
+ return ("string" === r ? String : Number)(t);
27
+ }
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
31
+ function toPropertyKey(t) {
32
+ var i = toPrimitive(t, "string");
33
+ return "symbol" == _typeof(i) ? i : i + "";
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
38
+ function _defineProperty(e, r, t) {
39
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
+ value: t,
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0
44
+ }) : e[r] = t, e;
45
+ }
46
+
47
+ //#endregion
48
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
49
+ function __decorateParam(paramIndex, decorator) {
50
+ return function(target, key) {
51
+ decorator(target, key, paramIndex);
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
57
+ function __decorate(decorators, target, key, desc) {
58
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
59
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
60
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
61
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
62
+ }
63
+
64
+ //#endregion
65
+ //#region src/facade/f-menu-builder.ts
66
+ /**
67
+ * @ignore
68
+ */
69
+ var FMenuBase = class extends _univerjs_core_facade.FBase {
70
+ /**
71
+ * Append the menu to any menu position on Univer UI.
72
+ * @param {string | string[]} path - Some predefined path to append the menu. The paths can be an array,
73
+ * or an array joined by `|` separator. Since lots of submenus reuse the same name,
74
+ * you may need to specify their parent menus as well.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // This menu item will appear on every `contextMenu.others` section.
79
+ * univerAPI.createMenu({
80
+ * id: 'custom-menu-id-1',
81
+ * title: 'Custom Menu 1',
82
+ * action: () => {
83
+ * console.log('Custom Menu 1 clicked');
84
+ * },
85
+ * }).appendTo('contextMenu.others');
86
+ *
87
+ * // This menu item will only appear on the `contextMenu.others` section on the main area.
88
+ * univerAPI.createMenu({
89
+ * id: 'custom-menu-id-2',
90
+ * title: 'Custom Menu 2',
91
+ * action: () => {
92
+ * console.log('Custom Menu 2 clicked');
93
+ * },
94
+ * }).appendTo(['contextMenu.mainArea', 'contextMenu.others']);
95
+ * ```
96
+ */
97
+ appendTo(path) {
98
+ const paths = typeof path === "string" ? path.split("|") : path;
99
+ const len = paths.length;
100
+ const menuConfig = {};
101
+ let obj = menuConfig;
102
+ const schema = this.__getSchema();
103
+ paths.forEach((p, index) => {
104
+ if (index === len - 1) obj[p] = schema;
105
+ else obj[p] = {};
106
+ obj = obj[p];
107
+ });
108
+ this._menuManagerService.mergeMenu(menuConfig);
109
+ }
110
+ };
111
+ let FMenu = class FMenu extends FMenuBase {
112
+ constructor(_item, _injector, _commandService, _menuManagerService) {
113
+ super();
114
+ this._item = _item;
115
+ this._injector = _injector;
116
+ this._commandService = _commandService;
117
+ this._menuManagerService = _menuManagerService;
118
+ _defineProperty(this, "_commandToRegister", /* @__PURE__ */ new Map());
119
+ _defineProperty(this, "_buildingSchema", void 0);
120
+ const commandId = typeof _item.action === "string" ? _item.action : (0, _univerjs_core.generateRandomId)(12);
121
+ if (commandId !== _item.action) this._commandToRegister.set(commandId, _item.action);
122
+ this._buildingSchema = { menuItemFactory: () => ({
123
+ id: _item.id,
124
+ type: _univerjs_ui.MenuItemType.BUTTON,
125
+ icon: _item.icon,
126
+ title: _item.title,
127
+ tooltip: _item.tooltip,
128
+ commandId
129
+ }) };
130
+ if (typeof _item.order !== "undefined") this._buildingSchema.order = _item.order;
131
+ }
132
+ /**
133
+ * @ignore
134
+ */
135
+ __getSchema() {
136
+ this._commandToRegister.forEach((command, id) => {
137
+ if (!this._commandService.hasCommand(id)) this._commandService.registerCommand({
138
+ id,
139
+ type: _univerjs_core.CommandType.COMMAND,
140
+ handler: command
141
+ });
142
+ });
143
+ return { [this._item.id]: this._buildingSchema };
144
+ }
145
+ };
146
+ _defineProperty(FMenu, "RibbonStartGroup", _univerjs_ui.RibbonStartGroup);
147
+ _defineProperty(FMenu, "RibbonPosition", _univerjs_ui.RibbonPosition);
148
+ _defineProperty(FMenu, "MenuManagerPosition", _univerjs_ui.MenuManagerPosition);
149
+ FMenu = __decorate([
150
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
151
+ __decorateParam(2, _univerjs_core.ICommandService),
152
+ __decorateParam(3, _univerjs_ui.IMenuManagerService)
153
+ ], FMenu);
154
+ let FSubmenu = class FSubmenu extends FMenuBase {
155
+ constructor(_item, _injector, _menuManagerService) {
156
+ super();
157
+ this._item = _item;
158
+ this._injector = _injector;
159
+ this._menuManagerService = _menuManagerService;
160
+ _defineProperty(this, "_menuByGroups", []);
161
+ _defineProperty(this, "_submenus", []);
162
+ _defineProperty(this, "_buildingSchema", void 0);
163
+ this._buildingSchema = { menuItemFactory: () => ({
164
+ id: _item.id,
165
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
166
+ icon: _item.icon,
167
+ title: _item.title,
168
+ tooltip: _item.tooltip
169
+ }) };
170
+ if (typeof _item.order !== "undefined") this._buildingSchema.order = _item.order;
171
+ }
172
+ /**
173
+ * Add a menu to the submenu. It can be a {@link FMenu} or a {@link FSubmenu}.
174
+ * @param {FMenu | FSubmenu} submenu - Menu to add to the submenu.
175
+ * @returns {FSubmenu} The FSubmenu itself for chaining calls.
176
+ * @example
177
+ * ```typescript
178
+ * // Create two leaf menus.
179
+ * const menu1 = univerAPI.createMenu({
180
+ * id: 'submenu-nested-1',
181
+ * title: 'Item 1',
182
+ * action: () => {
183
+ * console.log('Item 1 clicked');
184
+ * }
185
+ * });
186
+ * const menu2 = univerAPI.createMenu({
187
+ * id: 'submenu-nested-2',
188
+ * title: 'Item 2',
189
+ * action: () => {
190
+ * console.log('Item 2 clicked');
191
+ * }
192
+ * });
193
+ *
194
+ * // Add the leaf menus to a submenu.
195
+ * const submenu = univerAPI.createSubmenu({ id: 'submenu-nested', title: 'Nested Submenu' })
196
+ * .addSubmenu(menu1)
197
+ * .addSeparator()
198
+ * .addSubmenu(menu2);
199
+ *
200
+ * // Create a root submenu append to the `contextMenu.others` section.
201
+ * univerAPI.createSubmenu({ id: 'custom-submenu', title: 'Custom Submenu' })
202
+ * .addSubmenu(submenu)
203
+ * .appendTo('contextMenu.others');
204
+ * ```
205
+ */
206
+ addSubmenu(submenu) {
207
+ this._submenus.push(submenu);
208
+ return this;
209
+ }
210
+ /**
211
+ * Add a separator to the submenu.
212
+ * @returns {FSubmenu} The FSubmenu itself for chaining calls.
213
+ * @example
214
+ * ```typescript
215
+ * // Create two leaf menus.
216
+ * const menu1 = univerAPI.createMenu({
217
+ * id: 'submenu-nested-1',
218
+ * title: 'Item 1',
219
+ * action: () => {
220
+ * console.log('Item 1 clicked');
221
+ * }
222
+ * });
223
+ * const menu2 = univerAPI.createMenu({
224
+ * id: 'submenu-nested-2',
225
+ * title: 'Item 2',
226
+ * action: () => {
227
+ * console.log('Item 2 clicked');
228
+ * }
229
+ * });
230
+ *
231
+ * // Add the leaf menus to a submenu and add a separator between them.
232
+ * // Append the submenu to the `contextMenu.others` section.
233
+ * univerAPI.createSubmenu({ id: 'submenu-nested', title: 'Nested Submenu' })
234
+ * .addSubmenu(menu1)
235
+ * .addSeparator()
236
+ * .addSubmenu(menu2)
237
+ * .appendTo('contextMenu.others');
238
+ * ```
239
+ */
240
+ addSeparator() {
241
+ this._menuByGroups.push(this._submenus);
242
+ this._submenus = [];
243
+ return this;
244
+ }
245
+ /**
246
+ * @ignore
247
+ */
248
+ __getSchema() {
249
+ const schema = {};
250
+ this.addSeparator();
251
+ this._menuByGroups.forEach((group, index) => {
252
+ const groupSchema = {};
253
+ group.forEach((menu) => {
254
+ Object.assign(groupSchema, menu.__getSchema());
255
+ });
256
+ schema[`${this._item.id}-group-${index}`] = groupSchema;
257
+ });
258
+ return { [this._item.id]: Object.assign(this._buildingSchema, schema) };
259
+ }
260
+ };
261
+ FSubmenu = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_ui.IMenuManagerService)], FSubmenu);
262
+
263
+ //#endregion
264
+ //#region src/facade/f-shortcut.ts
265
+ let FShortcut = class FShortcut extends _univerjs_core_facade.FBase {
266
+ constructor(_injector, _renderManagerService, _univerInstanceService, _shortcutService) {
267
+ super();
268
+ this._injector = _injector;
269
+ this._renderManagerService = _renderManagerService;
270
+ this._univerInstanceService = _univerInstanceService;
271
+ this._shortcutService = _shortcutService;
272
+ _defineProperty(this, "_forceDisableDisposable", null);
273
+ }
274
+ /**
275
+ * Enable shortcuts of Univer.
276
+ * @returns {FShortcut} The Facade API instance itself for chaining.
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * fShortcut.enableShortcut(); // Use the FShortcut instance used by disableShortcut before, do not create a new instance
281
+ * ```
282
+ */
283
+ enableShortcut() {
284
+ var _this$_forceDisableDi;
285
+ (_this$_forceDisableDi = this._forceDisableDisposable) === null || _this$_forceDisableDi === void 0 || _this$_forceDisableDi.dispose();
286
+ this._forceDisableDisposable = null;
287
+ return this;
288
+ }
289
+ /**
290
+ * Disable shortcuts of Univer.
291
+ * @returns {FShortcut} The Facade API instance itself for chaining.
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const fShortcut = univerAPI.getShortcut();
296
+ * fShortcut.disableShortcut();
297
+ * ```
298
+ */
299
+ disableShortcut() {
300
+ if (!this._forceDisableDisposable) this._forceDisableDisposable = this._shortcutService.forceDisable();
301
+ return this;
302
+ }
303
+ /**
304
+ * Trigger shortcut of Univer by a KeyboardEvent and return the matched shortcut item.
305
+ * @param {KeyboardEvent} e - The KeyboardEvent to trigger.
306
+ * @returns {IShortcutItem<object> | undefined} The matched shortcut item.
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * // Assum the current sheet is empty sheet.
311
+ * const fWorkbook = univerAPI.getActiveWorkbook();
312
+ * const fWorksheet = fWorkbook.getActiveSheet();
313
+ * const fRange = fWorksheet.getRange('A1');
314
+ *
315
+ * // Set A1 cell active and set value to 'Hello Univer'.
316
+ * fRange.activate();
317
+ * fRange.setValue('Hello Univer');
318
+ * console.log(fRange.getCellStyle().bold); // false
319
+ *
320
+ * // Set A1 cell bold by shortcut.
321
+ * const fShortcut = univerAPI.getShortcut();
322
+ * const pseudoEvent = new KeyboardEvent('keydown', {
323
+ * key: 'b',
324
+ * ctrlKey: true,
325
+ * keyCode: univerAPI.Enum.KeyCode.B
326
+ * });
327
+ * const ifShortcutItem = fShortcut.triggerShortcut(pseudoEvent);
328
+ * if (ifShortcutItem) {
329
+ * const commandId = ifShortcutItem.id;
330
+ * console.log(fRange.getCellStyle().bold); // true
331
+ * }
332
+ * ```
333
+ */
334
+ triggerShortcut(e) {
335
+ const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
336
+ if (!workbook) return;
337
+ const renderUnit = this._renderManagerService.getRenderById(workbook.getUnitId());
338
+ if (!renderUnit) return;
339
+ renderUnit.engine.getCanvasElement().dispatchEvent(e);
340
+ return this._shortcutService.dispatch(e);
341
+ }
342
+ /**
343
+ * Dispatch a KeyboardEvent to the shortcut service and return the matched shortcut item.
344
+ * @param {KeyboardEvent} e - The KeyboardEvent to dispatch.
345
+ * @returns {IShortcutItem<object> | undefined} The matched shortcut item.
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * const fShortcut = univerAPI.getShortcut();
350
+ * const pseudoEvent = new KeyboardEvent('keydown', { key: 's', ctrlKey: true });
351
+ * const ifShortcutItem = fShortcut.dispatchShortcutEvent(pseudoEvent);
352
+ * if (ifShortcutItem) {
353
+ * const commandId = ifShortcutItem.id;
354
+ * // Do something with the commandId.
355
+ * }
356
+ * ```
357
+ */
358
+ dispatchShortcutEvent(e) {
359
+ return this._shortcutService.dispatch(e);
360
+ }
361
+ };
362
+ FShortcut = __decorate([
363
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
364
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_render.IRenderManagerService)),
365
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
366
+ __decorateParam(3, _univerjs_ui.IShortcutService)
367
+ ], FShortcut);
368
+
369
+ //#endregion
370
+ //#region src/facade/f-univer.ts
371
+ /**
372
+ * @ignore
373
+ */
374
+ var FUniverUIMixin = class extends _univerjs_core_facade.FUniver {
375
+ getURL() {
376
+ return new URL(window.location.href);
377
+ }
378
+ getShortcut() {
379
+ return this._injector.createInstance(FShortcut);
380
+ }
381
+ copy() {
382
+ return this._commandService.executeCommand(_univerjs_ui.CopyCommand.id);
383
+ }
384
+ paste() {
385
+ return this._commandService.executeCommand(_univerjs_ui.PasteCommand.id);
386
+ }
387
+ createMenu(menuItem) {
388
+ return this._injector.createInstance(FMenu, menuItem);
389
+ }
390
+ createSubmenu(submenuItem) {
391
+ return this._injector.createInstance(FSubmenu, submenuItem);
392
+ }
393
+ openSiderbar(params) {
394
+ return this._injector.get(_univerjs_ui.ISidebarService).open(params);
395
+ }
396
+ openSidebar(params) {
397
+ return this.openSiderbar(params);
398
+ }
399
+ openDialog(dialog) {
400
+ const disposable = this._injector.get(_univerjs_ui.IDialogService).open({
401
+ ...dialog,
402
+ onClose: () => {
403
+ disposable.dispose();
404
+ }
405
+ });
406
+ return disposable;
407
+ }
408
+ getComponentManager() {
409
+ return this._injector.get(_univerjs_ui.ComponentManager);
410
+ }
411
+ showMessage(options) {
412
+ this._injector.get(_univerjs_ui.IMessageService).show(options);
413
+ return this;
414
+ }
415
+ setUIVisible(ui, visible) {
416
+ this._injector.get(_univerjs_ui.IUIPartsService).setUIVisible(ui, visible);
417
+ return this;
418
+ }
419
+ isUIVisible(ui) {
420
+ return this._injector.get(_univerjs_ui.IUIPartsService).isUIVisible(ui);
421
+ }
422
+ registerUIPart(key, component) {
423
+ return this._injector.get(_univerjs_ui.IUIPartsService).registerComponent(key, () => (0, _univerjs_ui.connectInjector)(component, this._injector));
424
+ }
425
+ registerComponent(name, component, options) {
426
+ const componentManager = this._injector.get(_univerjs_ui.ComponentManager);
427
+ return this.disposeWithMe(componentManager.register(name, component, options));
428
+ }
429
+ setCurrent(unitId) {
430
+ if (!this._injector.get(_univerjs_engine_render.IRenderManagerService).getRenderById(unitId)) throw new Error("Unit not found");
431
+ this._univerInstanceService.setCurrentUnitForType(unitId);
432
+ }
433
+ addFonts(fonts) {
434
+ const fontService = this._injector.get(_univerjs_ui.IFontService);
435
+ fonts.forEach((font) => {
436
+ fontService.addFont(font);
437
+ });
438
+ }
439
+ };
440
+ _univerjs_core_facade.FUniver.extend(FUniverUIMixin);
441
+
442
+ //#endregion
443
+ //#region src/facade/f-hooks.ts
444
+ /**
445
+ * @ignore
446
+ */
447
+ var FHooksSheetsMixin = class extends _univerjs_core_facade.FHooks {
448
+ onBeforeCopy(callback) {
449
+ return this._injector.get(_univerjs_core.ICommandService).beforeCommandExecuted((command) => {
450
+ if (command.id === _univerjs_ui.CopyCommand.id) callback();
451
+ });
452
+ }
453
+ onCopy(callback) {
454
+ return this._injector.get(_univerjs_core.ICommandService).onCommandExecuted((command) => {
455
+ if (command.id === _univerjs_ui.CopyCommand.id) callback();
456
+ });
457
+ }
458
+ onBeforePaste(callback) {
459
+ return this._injector.get(_univerjs_core.ICommandService).beforeCommandExecuted((command) => {
460
+ if (command.id === _univerjs_ui.PasteCommand.id) callback();
461
+ });
462
+ }
463
+ onPaste(callback) {
464
+ return this._injector.get(_univerjs_core.ICommandService).onCommandExecuted((command) => {
465
+ if (command.id === _univerjs_ui.PasteCommand.id || command.id === _univerjs_ui.SheetPasteShortKeyCommandName) callback();
466
+ });
467
+ }
468
+ };
469
+ _univerjs_core_facade.FHooks.extend(FHooksSheetsMixin);
470
+
471
+ //#endregion
472
+ //#region src/facade/f-enum.ts
473
+ /**
474
+ * Copyright 2023-present DreamNum Co., Ltd.
475
+ *
476
+ * Licensed under the Apache License, Version 2.0 (the "License");
477
+ * you may not use this file except in compliance with the License.
478
+ * You may obtain a copy of the License at
479
+ *
480
+ * http://www.apache.org/licenses/LICENSE-2.0
481
+ *
482
+ * Unless required by applicable law or agreed to in writing, software
483
+ * distributed under the License is distributed on an "AS IS" BASIS,
484
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
485
+ * See the License for the specific language governing permissions and
486
+ * limitations under the License.
487
+ */
488
+ /**
489
+ * @ignore
490
+ */
491
+ var FUIEnumMixin = class extends _univerjs_core_facade.FEnum {
492
+ get BuiltInUIPart() {
493
+ return _univerjs_ui.BuiltInUIPart;
494
+ }
495
+ get KeyCode() {
496
+ return _univerjs_ui.KeyCode;
497
+ }
498
+ };
499
+ _univerjs_core_facade.FEnum.extend(FUIEnumMixin);
500
+
501
+ //#endregion