@univerjs/ui 0.2.9 → 0.2.11

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/index.js CHANGED
@@ -956,6 +956,7 @@ const _ComponentManager = class _ComponentManager {
956
956
  // eslint-disable-next-line max-lines-per-function
957
957
  constructor() {
958
958
  __publicField(this, "_components", /* @__PURE__ */ new Map());
959
+ __publicField(this, "_componentsReverse", /* @__PURE__ */ new Map());
959
960
  const iconList = {
960
961
  AlignBottomSingle,
961
962
  AlignTopSingle,
@@ -1067,7 +1068,12 @@ const _ComponentManager = class _ComponentManager {
1067
1068
  return this._components.has(name) && console.warn(`Component ${name} already exists.`), this._components.set(name, {
1068
1069
  framework,
1069
1070
  component
1070
- }), toDisposable(() => this._components.delete(name));
1071
+ }), this._componentsReverse.set(component, name), toDisposable(() => {
1072
+ this._components.delete(name), this._componentsReverse.delete(component);
1073
+ });
1074
+ }
1075
+ getKey(component) {
1076
+ return this._componentsReverse.get(component);
1071
1077
  }
1072
1078
  get(name) {
1073
1079
  if (!name) return;
@@ -2111,7 +2117,7 @@ var MetaKeys = /* @__PURE__ */ ((MetaKeys2) => (MetaKeys2[MetaKeys2.SHIFT = 1024
2111
2117
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2112
2118
  return kind && result && __defProp$f(target, key, result), result;
2113
2119
  }, "__decorateClass$f"), __decorateParam$f = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$f");
2114
- const IShortcutService = createIdentifier("univer.shortcut");
2120
+ const IShortcutService = createIdentifier("ui.shortcut.service");
2115
2121
  var _a2;
2116
2122
  let ShortcutService = (_a2 = class extends Disposable {
2117
2123
  constructor(_commandService, _platformService, _contextService, _layoutService) {
@@ -2121,7 +2127,6 @@ let ShortcutService = (_a2 = class extends Disposable {
2121
2127
  __publicField(this, "_shortcutChanged$", new Subject());
2122
2128
  __publicField(this, "shortcutChanged$", this._shortcutChanged$.asObservable());
2123
2129
  __publicField(this, "_forceEscaped", !1);
2124
- __publicField(this, "_disable", !1);
2125
2130
  this._commandService = _commandService, this._platformService = _platformService, this._contextService = _contextService, this._layoutService = _layoutService, this.disposeWithMe(
2126
2131
  fromGlobalEvent("keydown", (e2) => {
2127
2132
  this._resolveKeyboardEvent(e2);
@@ -2130,9 +2135,6 @@ let ShortcutService = (_a2 = class extends Disposable {
2130
2135
  })
2131
2136
  );
2132
2137
  }
2133
- setDisable(disable) {
2134
- this._disable = disable;
2135
- }
2136
2138
  getAllShortcuts() {
2137
2139
  return Array.from(this._shortCutMapping.values()).map((v2) => Array.from(v2.values())).flat();
2138
2140
  }
@@ -2161,7 +2163,7 @@ let ShortcutService = (_a2 = class extends Disposable {
2161
2163
  return this._forceEscaped = !0, toDisposable(() => this._forceEscaped = !1);
2162
2164
  }
2163
2165
  _resolveKeyboardEvent(e2) {
2164
- if (this._forceEscaped || this._disable || this._layoutService && !this._layoutService.checkElementInCurrentContainers(e2.target))
2166
+ if (this._forceEscaped || this._layoutService && !this._layoutService.checkElementInCurrentContainers(e2.target))
2165
2167
  return;
2166
2168
  this._dispatch(e2) && e2.preventDefault();
2167
2169
  }
@@ -3898,7 +3900,7 @@ function Sidebar() {
3898
3900
  options == null ? void 0 : options.header,
3899
3901
  /* @__PURE__ */ jsxRuntimeExports.jsx("a", { className: styles$a.sidebarHeaderClose, onClick: handleClose, children: /* @__PURE__ */ jsxRuntimeExports.jsx(CloseSingle, {}) })
3900
3902
  ] }),
3901
- /* @__PURE__ */ jsxRuntimeExports.jsx("section", { className: styles$a.sidebarBody, children: options == null ? void 0 : options.children }),
3903
+ /* @__PURE__ */ jsxRuntimeExports.jsx("section", { className: styles$a.sidebarBody, style: options == null ? void 0 : options.bodyStyle, children: options == null ? void 0 : options.children }),
3902
3904
  (options == null ? void 0 : options.footer) && /* @__PURE__ */ jsxRuntimeExports.jsx("footer", { className: styles$a.sidebarFooter, children: options.footer })
3903
3905
  ] }) });
3904
3906
  }
@@ -4037,11 +4039,15 @@ var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPrope
4037
4039
  const STEADY_TIMEOUT$1 = 3e3;
4038
4040
  var _a5;
4039
4041
  let DesktopUIController = (_a5 = class extends Disposable {
4040
- constructor(_config, _renderManagerService, _injector, _lifecycleService, _uiPartsService, _configService, _layoutService) {
4041
- super(), this._config = _config, this._renderManagerService = _renderManagerService, this._injector = _injector, this._lifecycleService = _lifecycleService, this._uiPartsService = _uiPartsService, this._configService = _configService, this._layoutService = _layoutService, this._configService.setConfig(UI_CONFIG_KEY, this._config), this._initBuiltinComponents(), Promise.resolve().then(() => this._bootstrapWorkbench());
4042
+ constructor(_config, _renderManagerService, _instanceSrv, _injector, _lifecycleService, _uiPartsService, _configService, _layoutService) {
4043
+ super();
4044
+ __publicField(this, "_steadyTimeout");
4045
+ this._config = _config, this._renderManagerService = _renderManagerService, this._instanceSrv = _instanceSrv, this._injector = _injector, this._lifecycleService = _lifecycleService, this._uiPartsService = _uiPartsService, this._configService = _configService, this._layoutService = _layoutService, this._configService.setConfig(UI_CONFIG_KEY, this._config), this._initBuiltinComponents(), Promise.resolve().then(() => this._bootstrapWorkbench());
4042
4046
  }
4043
4047
  _bootstrapWorkbench() {
4044
- this.disposeWithMe(
4048
+ this.disposeWithMe(this._instanceSrv.unitDisposed$.subscribe(() => {
4049
+ clearTimeout(this._steadyTimeout);
4050
+ })), this.disposeWithMe(
4045
4051
  bootstrap$1(this._injector, this._config, (contentElement, containerElement) => {
4046
4052
  this._layoutService && (this.disposeWithMe(this._layoutService.registerRootContainerElement(containerElement)), this.disposeWithMe(this._layoutService.registerContentElement(contentElement))), this._renderManagerService.currentRender$.subscribe((renderId) => {
4047
4053
  if (renderId) {
@@ -4053,7 +4059,7 @@ let DesktopUIController = (_a5 = class extends Disposable {
4053
4059
  const allRenders = this._renderManagerService.getRenderAll();
4054
4060
  for (const [key, render2] of allRenders)
4055
4061
  isInternalEditorID(key) || !render2.isRenderUnit || render2.engine.setContainer(contentElement);
4056
- this._lifecycleService.stage = LifecycleStages.Rendered, setTimeout(() => this._lifecycleService.stage = LifecycleStages.Steady, STEADY_TIMEOUT$1);
4062
+ this._lifecycleService.stage = LifecycleStages.Rendered, this._steadyTimeout = setTimeout(() => this._lifecycleService.stage = LifecycleStages.Steady, STEADY_TIMEOUT$1);
4057
4063
  }, 300);
4058
4064
  })
4059
4065
  );
@@ -4065,11 +4071,12 @@ let DesktopUIController = (_a5 = class extends Disposable {
4065
4071
  DesktopUIController = __decorateClass$c([
4066
4072
  OnLifecycle(LifecycleStages.Ready, DesktopUIController),
4067
4073
  __decorateParam$c(1, IRenderManagerService),
4068
- __decorateParam$c(2, Inject(Injector)),
4069
- __decorateParam$c(3, Inject(LifecycleService)),
4070
- __decorateParam$c(4, IUIPartsService),
4071
- __decorateParam$c(5, IConfigService),
4072
- __decorateParam$c(6, Optional(ILayoutService))
4074
+ __decorateParam$c(2, IUniverInstanceService),
4075
+ __decorateParam$c(3, Inject(Injector)),
4076
+ __decorateParam$c(4, Inject(LifecycleService)),
4077
+ __decorateParam$c(5, IUIPartsService),
4078
+ __decorateParam$c(6, IConfigService),
4079
+ __decorateParam$c(7, Optional(ILayoutService))
4073
4080
  ], DesktopUIController);
4074
4081
  function bootstrap$1(injector, options, callback) {
4075
4082
  let mountContainer;
@@ -4393,6 +4400,13 @@ let DesktopDialogService = (_a9 = class extends Disposable {
4393
4400
  visible: item.id === id ? !1 : item.visible
4394
4401
  })), this._dialogOptions$.next([...this._dialogOptions]);
4395
4402
  }
4403
+ closeAll(expectIds) {
4404
+ const expectIdSet = new Set(expectIds);
4405
+ this._dialogOptions = this._dialogOptions.map((item) => ({
4406
+ ...item,
4407
+ visible: expectIdSet.has(item.id) ? item.visible : !1
4408
+ })), this._dialogOptions$.next([...this._dialogOptions]);
4409
+ }
4396
4410
  getDialogs$() {
4397
4411
  return this._dialogOptions$.asObservable();
4398
4412
  }
@@ -17,8 +17,10 @@ export type ComponentType = React.ForwardRefExoticComponent<any> | ReturnType<ty
17
17
  export type ComponentList = Map<string, IVue3Component | IReactComponent>;
18
18
  export declare class ComponentManager {
19
19
  private _components;
20
+ private _componentsReverse;
20
21
  constructor();
21
22
  register(name: string, component: ComponentType, options?: IComponentOptions): IDisposable;
23
+ getKey(component: ComponentType): string | undefined;
22
24
  get(name: string): React.ForwardRefExoticComponent<any> | ((props: any) => React.FunctionComponentElement<{
23
25
  component: ReturnType<typeof defineComponent>;
24
26
  props: Record<string, any>;
@@ -1,4 +1,4 @@
1
- import { Disposable, IConfigService, Injector, LifecycleService } from '@univerjs/core';
1
+ import { Disposable, IConfigService, Injector, IUniverInstanceService, LifecycleService } from '@univerjs/core';
2
2
  import { IRenderManagerService } from '@univerjs/engine-render';
3
3
  import { ILayoutService } from '../../services/layout/layout.service';
4
4
  import { IUIPartsService } from '../../services/parts/parts.service';
@@ -6,12 +6,14 @@ import { IUniverUIConfig } from './ui.controller';
6
6
  export declare class DesktopUIController extends Disposable {
7
7
  private readonly _config;
8
8
  private readonly _renderManagerService;
9
+ private readonly _instanceSrv;
9
10
  private readonly _injector;
10
11
  private readonly _lifecycleService;
11
12
  private readonly _uiPartsService;
12
13
  private readonly _configService;
13
14
  private readonly _layoutService?;
14
- constructor(_config: IUniverUIConfig, _renderManagerService: IRenderManagerService, _injector: Injector, _lifecycleService: LifecycleService, _uiPartsService: IUIPartsService, _configService: IConfigService, _layoutService?: ILayoutService | undefined);
15
+ private _steadyTimeout;
16
+ constructor(_config: IUniverUIConfig, _renderManagerService: IRenderManagerService, _instanceSrv: IUniverInstanceService, _injector: Injector, _lifecycleService: LifecycleService, _uiPartsService: IUIPartsService, _configService: IConfigService, _layoutService?: ILayoutService | undefined);
15
17
  private _bootstrapWorkbench;
16
18
  private _initBuiltinComponents;
17
19
  }
@@ -12,6 +12,7 @@ export declare class DesktopDialogService extends Disposable implements IDialogS
12
12
  dispose(): void;
13
13
  open(option: IDialogPartMethodOptions): IDisposable;
14
14
  close(id: string): void;
15
+ closeAll(expectIds?: string[]): void;
15
16
  getDialogs$(): import('rxjs').Observable<IDialogPartMethodOptions[]>;
16
17
  protected _initUIPart(): void;
17
18
  }
@@ -5,5 +5,10 @@ export declare const IDialogService: import('@univerjs/core').IdentifierDecorato
5
5
  export interface IDialogService {
6
6
  open(params: IDialogPartMethodOptions): IDisposable;
7
7
  close(id: string): void;
8
+ /**
9
+ * @description close all dialogs except the specified ones
10
+ * @param {string[]} [expectIds] The specified dialog ids
11
+ */
12
+ closeAll(expectIds?: string[]): void;
8
13
  getDialogs$(): Observable<IDialogPartMethodOptions[]>;
9
14
  }
@@ -3,38 +3,100 @@ import { Observable } from 'rxjs';
3
3
  import { ILayoutService } from '../layout/layout.service';
4
4
  import { IPlatformService } from '../platform/platform.service';
5
5
  import { KeyCode } from './keycode';
6
+ /**
7
+ * A shortcut item that could be registered to the {@link IShortcutService}.
8
+ */
6
9
  export interface IShortcutItem<P extends object = object> {
7
- /** This should reuse the corresponding command's id. */
10
+ /** Id of the shortcut item. It should reuse the corresponding {@link ICommand}'s id. */
8
11
  id: string;
9
12
  /** Description of the shortcut. */
10
13
  description?: string;
11
14
  /** If two shortcuts have the same binding, the one with higher priority would be check first. */
12
15
  priority?: number;
13
- /** A callback that will be triggered to examine if the shortcut should be invoked. */
16
+ /**
17
+ * A callback that will be triggered to examine if the shortcut should be invoked. The `{@link IContextService}`
18
+ * would be passed to the callback.
19
+ */
14
20
  preconditions?: (contextService: IContextService) => boolean;
15
- /** A command can be bound to several bindings, with different static parameters perhaps. */
21
+ /**
22
+ * The binding of the shortcut. It should be a combination of {@link KeyCode} and {@link MetaKeys}.
23
+ *
24
+ * A command can be bound to several bindings, with different static parameters perhaps.
25
+ *
26
+ * @example { binding: KeyCode.ENTER | MetaKeys.ALT }
27
+ */
16
28
  binding: KeyCode | number;
29
+ /**
30
+ * The binding of the shortcut for macOS. If the property is not specified, the default binding would be used.
31
+ */
17
32
  mac?: number;
33
+ /**
34
+ * The binding of the shortcut for Windows. If the property is not specified, the default binding would be used.
35
+ */
18
36
  win?: number;
37
+ /**
38
+ * The binding of the shortcut for Linux. If the property is not specified, the default binding would be used.
39
+ */
19
40
  linux?: number;
20
41
  /**
21
42
  * The group of the menu item should belong to. The shortcut item would be rendered in the
22
43
  * panel if this is set.
44
+ *
45
+ * @example { group: '10_global-shortcut' }
23
46
  */
24
47
  group?: string;
25
- /** Static parameters of this shortcut. Would be send to `CommandService.executeCommand`. */
48
+ /**
49
+ * Static parameters of this shortcut. Would be send to {@link ICommandService.executeCommand} as the second
50
+ * parameter when the corresponding command is executed.
51
+ *
52
+ * You can define multi shortcuts with the same command id but different static parameters.
53
+ */
26
54
  staticParameters?: P;
27
55
  }
56
+ /**
57
+ * The dependency injection identifier of the {@link IShortcutService}.
58
+ */
59
+ export declare const IShortcutService: import('@univerjs/core').IdentifierDecorator<IShortcutService>;
60
+ /**
61
+ * The interface of the shortcut service.
62
+ */
28
63
  export interface IShortcutService {
64
+ /**
65
+ * An observable that emits when the shortcuts are changed.
66
+ */
29
67
  shortcutChanged$: Observable<void>;
68
+ /**
69
+ * Make the shortcut service ignore all keyboard events.
70
+ * @returns {IDisposable} a disposable that could be used to cancel the force escaping.
71
+ */
30
72
  forceEscape(): IDisposable;
73
+ /**
74
+ * Register a shortcut item to the shortcut service.
75
+ * @param {IShortcutItem} shortcut - the shortcut item to be registered.
76
+ * @returns {IDisposable} a disposable that could be used to unregister the shortcut.
77
+ */
31
78
  registerShortcut(shortcut: IShortcutItem): IDisposable;
79
+ /**
80
+ * Get the display string of the shortcut item.
81
+ * @param shortcut - the shortcut item to get the display string.
82
+ * @returns {string} the display string of the shortcut. For example `Ctrl+Enter`.
83
+ */
32
84
  getShortcutDisplay(shortcut: IShortcutItem): string;
85
+ /**
86
+ * Get the display string of the shortcut of the command.
87
+ * @param id the id of the command to get the shortcut display.
88
+ * @returns {string | null} the display string of the shortcut. For example `Ctrl+Enter`.
89
+ */
33
90
  getShortcutDisplayOfCommand(id: string): string | null;
91
+ /**
92
+ * Get all the shortcuts registered in the shortcut service.
93
+ * @returns {IShortcutItem[]} all the shortcuts registered in the shortcut service.
94
+ */
34
95
  getAllShortcuts(): IShortcutItem[];
35
- setDisable(disable: boolean): void;
36
96
  }
37
- export declare const IShortcutService: import('@univerjs/core').IdentifierDecorator<IShortcutService>;
97
+ /**
98
+ * @ignore
99
+ */
38
100
  export declare class ShortcutService extends Disposable implements IShortcutService {
39
101
  private readonly _commandService;
40
102
  private readonly _platformService;
@@ -45,9 +107,7 @@ export declare class ShortcutService extends Disposable implements IShortcutServ
45
107
  private readonly _shortcutChanged$;
46
108
  readonly shortcutChanged$: Observable<void>;
47
109
  private _forceEscaped;
48
- private _disable;
49
110
  constructor(_commandService: ICommandService, _platformService: IPlatformService, _contextService: IContextService, _layoutService?: ILayoutService | undefined);
50
- setDisable(disable: boolean): void;
51
111
  getAllShortcuts(): IShortcutItem[];
52
112
  registerShortcut(shortcut: IShortcutItem): IDisposable;
53
113
  getShortcutDisplayOfCommand(id: string): string | null;
@@ -1,8 +1,10 @@
1
+ import { CSSProperties } from 'react';
1
2
  import { ICustomLabelProps } from '../../../components/custom-label/CustomLabel';
2
3
  export interface ISidebarMethodOptions {
3
4
  id?: string;
4
5
  header?: ICustomLabelProps;
5
6
  children?: ICustomLabelProps;
7
+ bodyStyle?: CSSProperties;
6
8
  footer?: ICustomLabelProps;
7
9
  visible?: boolean;
8
10
  width?: number | string;