@univerjs/ui 1.4.0 → 1.5.1

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.
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IUniverUIConfig } from './config/config';
17
16
  import { IConfigService, IContextService, Injector, Plugin } from '@univerjs/core';
17
+ import type { IUniverUIConfig } from './config/config';
18
18
  export declare const DISABLE_AUTO_FOCUS_KEY = "DISABLE_AUTO_FOCUS";
19
19
  /**
20
20
  * UI plugin provides basic interaction with users. Including workbench (menus, UI parts, notifications etc.), copy paste, shortcut.
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IUniverUIConfig } from './config/config';
17
16
  import { IConfigService, IContextService, Injector, Plugin } from '@univerjs/core';
17
+ import type { IUniverUIConfig } from './config/config';
18
18
  export declare const DISABLE_AUTO_FOCUS_KEY = "DISABLE_AUTO_FOCUS";
19
19
  /**
20
20
  * UI plugin provides basic interaction with users. Including workbench (menus, UI parts, notifications etc.), copy paste, shortcut.
@@ -19,20 +19,33 @@ import { Disposable } from '@univerjs/core';
19
19
  export interface IContextMenuHostService {
20
20
  readonly activeMenuId: string | null;
21
21
  readonly activeMenuId$: Observable<string | null>;
22
- registerMenu(menuId: string, hide: () => void): IDisposable;
22
+ /** Changes when pending menu interactions and focus restoration must be discarded. */
23
+ readonly revision: number;
24
+ readonly suspended: boolean;
25
+ registerMenu(menuId: string | symbol, hide: (restoreFocus: boolean) => void): IDisposable;
23
26
  activateMenu(menuId: string): void;
24
27
  deactivateMenu(menuId: string): void;
25
28
  hideActiveMenu(exceptMenuId?: string): void;
29
+ /** Close registered menus without returning focus to their triggers. */
30
+ closeAll(): void;
31
+ /** Close host menus and prevent reopening until every replacing view releases its lease. */
32
+ suspend(): IDisposable;
26
33
  }
27
34
  export declare const IContextMenuHostService: import("@wendellhu/redi").IdentifierDecorator<IContextMenuHostService>;
28
35
  export declare class ContextMenuHostService extends Disposable implements IContextMenuHostService {
29
36
  private readonly _menuMap;
30
37
  private readonly _activeMenuId$;
38
+ private readonly _suspensions;
39
+ private _revision;
31
40
  readonly activeMenuId$: Observable<string | null>;
32
41
  get activeMenuId(): string | null;
33
- registerMenu(menuId: string, hide: () => void): IDisposable;
42
+ get revision(): number;
43
+ get suspended(): boolean;
44
+ registerMenu(menuId: string | symbol, hide: (restoreFocus: boolean) => void): IDisposable;
34
45
  activateMenu(menuId: string): void;
35
46
  deactivateMenu(menuId: string): void;
36
47
  hideActiveMenu(exceptMenuId?: string): void;
48
+ closeAll(): void;
49
+ suspend(): IDisposable;
37
50
  dispose(): void;
38
51
  }
@@ -14,17 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IDisposable } from '@univerjs/core';
17
- import type { IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';
18
- import type { IDialogService } from './dialog.service';
19
17
  import { Disposable, Injector } from '@univerjs/core';
20
18
  import { Subject } from 'rxjs';
19
+ import type { IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';
20
+ import type { IDialogService } from './dialog.service';
21
+ import { IContextMenuHostService } from '../contextmenu/contextmenu-host.service';
21
22
  import { IUIPartsService } from '../parts/parts.service';
22
23
  export declare class DesktopDialogService extends Disposable implements IDialogService {
23
24
  protected readonly _injector: Injector;
24
25
  protected readonly _uiPartsService: IUIPartsService;
26
+ private readonly _menuHostService;
25
27
  protected _dialogOptions: IDialogPartMethodOptions[];
26
28
  protected readonly _dialogOptions$: Subject<IDialogPartMethodOptions[]>;
27
- constructor(_injector: Injector, _uiPartsService: IUIPartsService);
29
+ constructor(_injector: Injector, _uiPartsService: IUIPartsService, _menuHostService: IContextMenuHostService);
28
30
  dispose(): void;
29
31
  open(option: IDialogPartMethodOptions): IDisposable;
30
32
  close(id: string): void;
@@ -14,10 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Injector } from '@univerjs/core';
17
+ import { IContextMenuHostService } from '../contextmenu/contextmenu-host.service';
17
18
  import { IUIPartsService } from '../parts/parts.service';
18
19
  import { DesktopDialogService } from './desktop-dialog.service';
19
20
  export declare class MobileDialogService extends DesktopDialogService {
20
- constructor(injector: Injector, uiPartsService: IUIPartsService);
21
+ constructor(injector: Injector, uiPartsService: IUIPartsService, menuHostService: IContextMenuHostService);
21
22
  close(id: string): void;
22
23
  protected _initUIPart(): void;
23
24
  }
@@ -44,6 +44,10 @@ export interface IFloatDom {
44
44
  * forwarding by default; interactive embed runtimes can opt out.
45
45
  */
46
46
  eventPassThrough?: boolean;
47
+ /** Cancel browser pinch/modified-wheel zoom while this host forwards events. */
48
+ preventBrowserZoom?: boolean;
49
+ /** Native listener options per event. Omitted events retain React forwarding. */
50
+ eventOptions?: Partial<Record<'wheel' | 'pointerdown' | 'pointermove' | 'pointerup', Pick<AddEventListenerOptions, 'passive' | 'capture'>>>;
47
51
  /**
48
52
  * Keep rendering this host-owned layer even when focus temporarily moves
49
53
  * into a child runtime unit. Interactive embed float blocks need this so
@@ -14,17 +14,20 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IDisposable } from '@univerjs/core';
17
- import type { ISidebarMethodOptions } from '../../views/components/sidebar/Sidebar';
18
- import type { ISidebarService } from './sidebar.service';
19
17
  import { Disposable } from '@univerjs/core';
20
18
  import { Subject } from 'rxjs';
19
+ import type { ISidebarMethodOptions } from '../../views/components/sidebar/Sidebar';
20
+ import type { ISidebarService } from './sidebar.service';
21
+ import { IContextMenuHostService } from '../contextmenu/contextmenu-host.service';
21
22
  export declare class DesktopSidebarService extends Disposable implements ISidebarService {
23
+ private readonly _menuHostService;
22
24
  private _sidebarOptions;
23
25
  readonly sidebarOptions$: Subject<ISidebarMethodOptions>;
24
26
  readonly scrollEvent$: Subject<Event>;
25
27
  private _container?;
26
28
  private _openAnimationFrameId;
27
29
  private _width?;
30
+ constructor(_menuHostService: IContextMenuHostService);
28
31
  get visible(): boolean;
29
32
  get options(): ISidebarMethodOptions;
30
33
  get width(): number | undefined;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { IContextMenuHostService } from '../services/contextmenu/contextmenu-host.service';
17
+ export declare function useMenuHost(onClose: () => void): IContextMenuHostService;
@@ -14,8 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IAccessor, IObjectPermissionTarget } from '@univerjs/core';
17
- import type { IObjectPermissionButtonProps } from './ObjectPermissionButton';
18
17
  import { UnitObject } from '@univerjs/protocol';
18
+ import type { IObjectPermissionButtonProps } from './ObjectPermissionButton';
19
19
  export declare const OBJECT_PERMISSION_PANEL = "ui.object-permission-panel";
20
20
  export interface IObjectPermissionPanelProps {
21
21
  unitId: string;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/engine-render"),require("@univerjs/ui")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/engine-render`,`@univerjs/ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverCoreFacade,e.UniverEngineRender,e.UniverUi))})(this,function(e,t,n,r){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 t.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(t,n,i,a){super(),this._item=t,this._injector=n,this._commandService=i,this._menuManagerService=a,s(this,`_commandToRegister`,/* @__PURE__ */ new Map),s(this,`_buildingSchema`,void 0);let o=typeof t.action==`string`?t.action:(0,e.generateRandomId)(12);o!==t.action&&this._commandToRegister.set(o,t.action),this._buildingSchema={menuItemFactory:()=>({id:t.id,type:r.MenuItemType.BUTTON,icon:t.icon,title:t.title,tooltip:t.tooltip,commandId:o})},t.order!==void 0&&(this._buildingSchema.order=t.order),t.gridLayout&&(this._buildingSchema.gridLayout=t.gridLayout)}__getSchema(){return this._commandToRegister.forEach((t,n)=>{this._commandService.hasCommand(n)||this._commandService.registerCommand({id:n,type:e.CommandType.COMMAND,handler:t})}),{[this._item.id]:this._buildingSchema}}};s(d,`RibbonStartGroup`,r.RibbonStartGroup),s(d,`RibbonPosition`,r.RibbonPosition),s(d,`MenuManagerPosition`,r.MenuManagerPosition),d=l([c(1,(0,e.Inject)(e.Injector)),c(2,e.ICommandService),c(3,r.IMenuManagerService)],d);let f=class extends u{constructor(e,t,n){super(),this._item=e,this._injector=t,this._menuManagerService=n,s(this,`_menuByGroups`,[]),s(this,`_submenus`,[]),s(this,`_buildingSchema`,void 0),this._buildingSchema={menuItemFactory:()=>({id:e.id,type:r.MenuItemType.SUBITEMS,icon:e.icon,title:e.title,tooltip:e.tooltip})},e.order!==void 0&&(this._buildingSchema.order=e.order),e.gridLayout&&(this._buildingSchema.gridLayout=e.gridLayout)}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,e.Inject)(e.Injector)),c(2,r.IMenuManagerService)],f);let p=class extends t.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._shortcutService.forceDisable(),this}triggerShortcut(t){let n=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=this._renderManagerService.getRenderUnitById(n.getUnitId());if(r)return r.engine.getCanvasElement().dispatchEvent(t),this._shortcutService.dispatch(t)}dispatchShortcutEvent(e){return this._shortcutService.dispatch(e)}};p=l([c(0,(0,e.Inject)(e.Injector)),c(1,(0,e.Inject)(n.IRenderManagerService)),c(2,e.IUniverInstanceService),c(3,r.IShortcutService)],p);var m=class extends t.FUniver{getURL(){return new URL(window.location.href)}getShortcut(){return this._injector.createInstance(p)}copy(){return this._commandService.executeCommand(r.CopyCommand.id)}paste(){return this._commandService.executeCommand(r.PasteCommand.id)}createMenu(e){return this._injector.createInstance(d,e)}createSubmenu(e){return this._injector.createInstance(f,e)}updateMenuConfig(e){return this._injector.get(r.IMenuManagerService).updateMenuConfig(e),this}openSidebar(e){return this._injector.get(r.ISidebarService).open(e)}openDialog(e){let t=this._injector.get(r.IDialogService).open({...e,onClose:()=>{t.dispose()}});return t}getComponentManager(){return this._injector.get(r.ComponentManager)}showMessage(e){return this._injector.get(r.IMessageService).show(e),this}setRibbonType(t){return this._injector.get(e.IConfigService).setConfig(r.UI_PLUGIN_CONFIG_KEY,{ribbonType:t},{merge:!0}),this}setUIVisible(e,t){return this._injector.get(r.IUIPartsService).setUIVisible(e,t),this}isUIVisible(e){return this._injector.get(r.IUIPartsService).isUIVisible(e)}registerUIPart(e,t){return this._injector.get(r.IUIPartsService).registerComponent(e,()=>(0,r.connectInjector)(t,this._injector))}registerComponent(e,t,n){let i=this._injector.get(r.ComponentManager);return this.disposeWithMe(i.register(e,t,{...n,override:(n==null?void 0:n.override)??!0}))}setCurrent(e){if(!this._injector.get(n.IRenderManagerService).getRenderUnitById(e))throw Error(`Unit not found`);this._univerInstanceService.setCurrentUnitForType(e)}addFonts(e){let t=this._injector.get(r.IFontService);e.forEach(e=>{t.addFont(e)})}};t.FUniver.extend(m);var h=class extends t.FEnum{get BuiltInUIPart(){return r.BuiltInUIPart}get KeyCode(){return r.KeyCode}};t.FEnum.extend(h)});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/engine-render"),require("@univerjs/ui")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/engine-render`,`@univerjs/ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverCoreFacade,e.UniverEngineRender,e.UniverUi))})(this,function(e,t,n,r){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;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==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 t.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(t,n,i,a){super(),this._item=t,this._injector=n,this._commandService=i,this._menuManagerService=a,s(this,`_commandToRegister`,/* @__PURE__ */ new Map),s(this,`_buildingSchema`,void 0);let o=typeof t.action==`string`?t.action:(0,e.generateRandomId)(12);o!==t.action&&this._commandToRegister.set(o,t.action),this._buildingSchema={menuItemFactory:()=>({id:t.id,type:r.MenuItemType.BUTTON,icon:t.icon,title:t.title,tooltip:t.tooltip,commandId:o})},t.order!==void 0&&(this._buildingSchema.order=t.order),t.gridLayout&&(this._buildingSchema.gridLayout=t.gridLayout)}__getSchema(){return this._commandToRegister.forEach((t,n)=>{this._commandService.hasCommand(n)||this._commandService.registerCommand({id:n,type:e.CommandType.COMMAND,handler:t})}),{[this._item.id]:this._buildingSchema}}};s(d,`RibbonStartGroup`,r.RibbonStartGroup),s(d,`RibbonPosition`,r.RibbonPosition),s(d,`MenuManagerPosition`,r.MenuManagerPosition),d=l([c(1,(0,e.Inject)(e.Injector)),c(2,e.ICommandService),c(3,r.IMenuManagerService)],d);let f=class extends u{constructor(e,t,n){super(),this._item=e,this._injector=t,this._menuManagerService=n,s(this,`_menuByGroups`,[]),s(this,`_submenus`,[]),s(this,`_buildingSchema`,void 0),this._buildingSchema={menuItemFactory:()=>({id:e.id,type:r.MenuItemType.SUBITEMS,icon:e.icon,title:e.title,tooltip:e.tooltip})},e.order!==void 0&&(this._buildingSchema.order=e.order),e.gridLayout&&(this._buildingSchema.gridLayout=e.gridLayout)}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,e.Inject)(e.Injector)),c(2,r.IMenuManagerService)],f);let p=class extends t.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._shortcutService.forceDisable(),this}triggerShortcut(t){let n=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=this._renderManagerService.getRenderUnitById(n.getUnitId());if(r)return r.engine.getCanvasElement().dispatchEvent(t),this._shortcutService.dispatch(t)}dispatchShortcutEvent(e){return this._shortcutService.dispatch(e)}};p=l([c(0,(0,e.Inject)(e.Injector)),c(1,(0,e.Inject)(n.IRenderManagerService)),c(2,e.IUniverInstanceService),c(3,r.IShortcutService)],p);var m=class extends t.FUniver{getURL(){return new URL(window.location.href)}getShortcut(){return this._injector.createInstance(p)}copy(){return this._commandService.executeCommand(r.CopyCommand.id)}paste(){return this._commandService.executeCommand(r.PasteCommand.id)}createMenu(e){return this._injector.createInstance(d,e)}createSubmenu(e){return this._injector.createInstance(f,e)}updateMenuConfig(e){return this._injector.get(r.IMenuManagerService).updateMenuConfig(e),this}openSidebar(e){return this._injector.get(r.ISidebarService).open(e)}openDialog(e){let t=this._injector.get(r.IDialogService).open({...e,onClose:()=>{t.dispose()}});return t}getComponentManager(){return this._injector.get(r.ComponentManager)}showMessage(e){return this._injector.get(r.IMessageService).show(e),this}setRibbonType(t){return this._injector.get(e.IConfigService).setConfig(r.UI_PLUGIN_CONFIG_KEY,{ribbonType:t},{merge:!0}),this}setUIVisible(e,t){return this._injector.get(r.IUIPartsService).setUIVisible(e,t),this}isUIVisible(e){return this._injector.get(r.IUIPartsService).isUIVisible(e)}registerUIPart(e,t){return this._injector.get(r.IUIPartsService).registerComponent(e,()=>(0,r.connectInjector)(t,this._injector))}registerComponent(e,t,n){let i=this._injector.get(r.ComponentManager);return this.disposeWithMe(i.register(e,t,{...n,override:(n==null?void 0:n.override)??!0}))}setCurrent(e){if(!this._injector.get(n.IRenderManagerService).getRenderUnitById(e))throw Error(`Unit not found`);this._univerInstanceService.setCurrentUnitForType(e)}addFonts(e){let t=this._injector.get(r.IFontService);e.forEach(e=>{t.addFont(e)})}};t.FUniver.extend(m);var h=class extends t.FEnum{get BuiltInUIPart(){return r.BuiltInUIPart}get KeyCode(){return r.KeyCode}};t.FEnum.extend(h)});