@opensumi/ide-core-browser 2.21.8-rc-1670567192.0 → 2.21.8

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 (317) hide show
  1. package/lib/components/actions/index.d.ts.map +1 -1
  2. package/lib/components/actions/index.js +22 -2
  3. package/lib/components/actions/index.js.map +1 -1
  4. package/lib/components/tree/tree.module.less +0 -1
  5. package/lib/contextkey/testing.d.ts +0 -1
  6. package/lib/contextkey/testing.d.ts.map +1 -1
  7. package/lib/contextkey/testing.js +1 -2
  8. package/lib/contextkey/testing.js.map +1 -1
  9. package/lib/menu/next/menu.contrib.interface.d.ts +2 -3
  10. package/lib/menu/next/menu.contrib.interface.d.ts.map +1 -1
  11. package/lib/menu/next/menu.contrib.interface.js.map +1 -1
  12. package/lib/preferences/preference-configurations.js +1 -1
  13. package/lib/preferences/preference-configurations.js.map +1 -1
  14. package/lib/react-providers/config-provider.d.ts +0 -4
  15. package/lib/react-providers/config-provider.d.ts.map +1 -1
  16. package/lib/react-providers/config-provider.js.map +1 -1
  17. package/lib/services/storage-service.d.ts.map +1 -1
  18. package/lib/services/storage-service.js +1 -7
  19. package/lib/services/storage-service.js.map +1 -1
  20. package/lib/utils/label.d.ts.map +1 -1
  21. package/lib/utils/label.js +9 -16
  22. package/lib/utils/label.js.map +1 -1
  23. package/package.json +6 -7
  24. package/src/application/application-state-service.ts +0 -54
  25. package/src/application/application.service.ts +0 -51
  26. package/src/application/index.ts +0 -2
  27. package/src/authentication/authentication.contribution.ts +0 -35
  28. package/src/authentication/authentication.service.ts +0 -517
  29. package/src/bootstrap/app.ts +0 -745
  30. package/src/bootstrap/app.view.tsx +0 -88
  31. package/src/bootstrap/connection.ts +0 -116
  32. package/src/bootstrap/index.ts +0 -3
  33. package/src/bootstrap/inner-providers.ts +0 -297
  34. package/src/bootstrap/lifecycle.service.ts +0 -19
  35. package/src/browser-module.ts +0 -24
  36. package/src/common/common.command.ts +0 -977
  37. package/src/common/common.contribution.ts +0 -343
  38. package/src/common/common.define.ts +0 -55
  39. package/src/common/common.module.ts +0 -33
  40. package/src/common/common.storage.ts +0 -22
  41. package/src/common/container-id.ts +0 -12
  42. package/src/common/index.ts +0 -4
  43. package/src/components/actions/index.tsx +0 -486
  44. package/src/components/actions/placements.ts +0 -47
  45. package/src/components/actions/styles.module.less +0 -144
  46. package/src/components/badge/index.tsx +0 -1
  47. package/src/components/index.ts +0 -26
  48. package/src/components/layout/box-panel.tsx +0 -88
  49. package/src/components/layout/default-layout.tsx +0 -61
  50. package/src/components/layout/index.ts +0 -4
  51. package/src/components/layout/layout.ts +0 -80
  52. package/src/components/layout/split-panel.service.ts +0 -56
  53. package/src/components/layout/split-panel.tsx +0 -296
  54. package/src/components/layout/styles.module.less +0 -21
  55. package/src/components/loading/index.ts +0 -1
  56. package/src/components/loading/loading.less +0 -14
  57. package/src/components/loading/loading.view.tsx +0 -7
  58. package/src/components/loading/media/loading-dark.svg +0 -52
  59. package/src/components/loading/media/loading-hc.svg +0 -52
  60. package/src/components/loading/media/loading.svg +0 -52
  61. package/src/components/popover/styles.module.less +0 -81
  62. package/src/components/portal/index.tsx +0 -13
  63. package/src/components/progressbar/index.tsx +0 -16
  64. package/src/components/progressbar/styles.module.less +0 -31
  65. package/src/components/recycle-tree/index.ts +0 -1
  66. package/src/components/recycle-tree/recycle-tree.view.tsx +0 -368
  67. package/src/components/resize/resize.module.less +0 -78
  68. package/src/components/resize/resize.tsx +0 -663
  69. package/src/components/scroll/index.tsx +0 -386
  70. package/src/components/scroll/scroll.module.less +0 -108
  71. package/src/components/scrollbar/index.ts +0 -1
  72. package/src/components/scrollbar/scrollbar.less +0 -36
  73. package/src/components/scrollbar/scrollbar.view.ts +0 -8
  74. package/src/components/select/index.tsx +0 -12
  75. package/src/components/select/styles.less +0 -6
  76. package/src/components/tree/index.ts +0 -3
  77. package/src/components/tree/tree-node.view.tsx +0 -546
  78. package/src/components/tree/tree.module.less +0 -297
  79. package/src/components/tree/tree.view.tsx +0 -486
  80. package/src/context-key.ts +0 -48
  81. package/src/contextkey/dialog.ts +0 -3
  82. package/src/contextkey/explorer.ts +0 -26
  83. package/src/contextkey/index.ts +0 -6
  84. package/src/contextkey/outline.ts +0 -4
  85. package/src/contextkey/resource.ts +0 -61
  86. package/src/contextkey/terminal.ts +0 -7
  87. package/src/contextkey/testing.ts +0 -9
  88. package/src/contextkey/workspace.ts +0 -7
  89. package/src/core-preferences.ts +0 -318
  90. package/src/dom/index.ts +0 -176
  91. package/src/encoding-registry.ts +0 -83
  92. package/src/extensions/extensions-point.service.ts +0 -78
  93. package/src/extensions/index.ts +0 -3
  94. package/src/extensions/schema/browserViews.ts +0 -96
  95. package/src/extensions/schema/menu.ts +0 -245
  96. package/src/extensions/schema/opensumiExtensionPackageSchema.ts +0 -12
  97. package/src/extensions/schema/toolbar.ts +0 -338
  98. package/src/extensions/schema/vscodeExtensionPackageSchema.ts +0 -330
  99. package/src/fs/index.ts +0 -12
  100. package/src/hash-calculate/hash-calculate.contribution.ts +0 -19
  101. package/src/index.ts +0 -42
  102. package/src/keybinding/index.ts +0 -1
  103. package/src/keybinding/keybinding.ts +0 -908
  104. package/src/keyboard/index.ts +0 -3
  105. package/src/keyboard/keyboard-layout-provider.ts +0 -412
  106. package/src/keyboard/keyboard-layout-service.ts +0 -449
  107. package/src/keyboard/keys.ts +0 -748
  108. package/src/keyboard/layouts/_.contribution.ts +0 -24
  109. package/src/keyboard/layouts/cz.win.ts +0 -168
  110. package/src/keyboard/layouts/de-swiss.win.ts +0 -168
  111. package/src/keyboard/layouts/de.darwin.ts +0 -131
  112. package/src/keyboard/layouts/de.linux.ts +0 -186
  113. package/src/keyboard/layouts/de.win.ts +0 -168
  114. package/src/keyboard/layouts/dk.win.ts +0 -168
  115. package/src/keyboard/layouts/dvorak.darwin.ts +0 -131
  116. package/src/keyboard/layouts/en-belgian.win.ts +0 -168
  117. package/src/keyboard/layouts/en-ext.darwin.ts +0 -131
  118. package/src/keyboard/layouts/en-in.win.ts +0 -168
  119. package/src/keyboard/layouts/en-intl.darwin.ts +0 -131
  120. package/src/keyboard/layouts/en-intl.win.ts +0 -168
  121. package/src/keyboard/layouts/en-uk.darwin.ts +0 -131
  122. package/src/keyboard/layouts/en-uk.win.ts +0 -168
  123. package/src/keyboard/layouts/en.darwin.ts +0 -139
  124. package/src/keyboard/layouts/en.linux.ts +0 -186
  125. package/src/keyboard/layouts/en.win.ts +0 -173
  126. package/src/keyboard/layouts/es-latin.win.ts +0 -168
  127. package/src/keyboard/layouts/es.darwin.ts +0 -131
  128. package/src/keyboard/layouts/es.linux.ts +0 -186
  129. package/src/keyboard/layouts/es.win.ts +0 -168
  130. package/src/keyboard/layouts/fr.darwin.ts +0 -131
  131. package/src/keyboard/layouts/fr.linux.ts +0 -186
  132. package/src/keyboard/layouts/fr.win.ts +0 -168
  133. package/src/keyboard/layouts/hu.win.ts +0 -168
  134. package/src/keyboard/layouts/it.darwin.ts +0 -131
  135. package/src/keyboard/layouts/it.win.ts +0 -168
  136. package/src/keyboard/layouts/jp-roman.darwin.ts +0 -131
  137. package/src/keyboard/layouts/jp.darwin.ts +0 -131
  138. package/src/keyboard/layouts/ko.darwin.ts +0 -131
  139. package/src/keyboard/layouts/layout.contribution.darwin.ts +0 -23
  140. package/src/keyboard/layouts/layout.contribution.linux.ts +0 -12
  141. package/src/keyboard/layouts/layout.contribution.ts +0 -9
  142. package/src/keyboard/layouts/layout.contribution.win.ts +0 -29
  143. package/src/keyboard/layouts/no.win.ts +0 -168
  144. package/src/keyboard/layouts/pl.darwin.ts +0 -131
  145. package/src/keyboard/layouts/pl.win.ts +0 -168
  146. package/src/keyboard/layouts/pt-br.win.ts +0 -169
  147. package/src/keyboard/layouts/pt.darwin.ts +0 -131
  148. package/src/keyboard/layouts/pt.win.ts +0 -168
  149. package/src/keyboard/layouts/ru.darwin.ts +0 -131
  150. package/src/keyboard/layouts/ru.linux.ts +0 -186
  151. package/src/keyboard/layouts/ru.win.ts +0 -168
  152. package/src/keyboard/layouts/sv.darwin.ts +0 -131
  153. package/src/keyboard/layouts/sv.win.ts +0 -168
  154. package/src/keyboard/layouts/thai.win.ts +0 -168
  155. package/src/keyboard/layouts/tr.win.ts +0 -168
  156. package/src/keyboard/layouts/zh-hans.darwin.ts +0 -131
  157. package/src/layout/accordion/tab-bar-toolbar.tsx +0 -59
  158. package/src/layout/accordion/view-context-key.registry.ts +0 -34
  159. package/src/layout/constants.ts +0 -7
  160. package/src/layout/index.ts +0 -5
  161. package/src/layout/layout-hooks.ts +0 -68
  162. package/src/layout/layout-state.ts +0 -107
  163. package/src/layout/layout.interface.ts +0 -101
  164. package/src/layout/layout.ts +0 -80
  165. package/src/layout/view-id.ts +0 -18
  166. package/src/logger/browser-logger.ts +0 -51
  167. package/src/logger/index.ts +0 -1
  168. package/src/markdown/index.tsx +0 -62
  169. package/src/menu/next/base.ts +0 -513
  170. package/src/menu/next/ctxmenu-service.ts +0 -188
  171. package/src/menu/next/index.ts +0 -10
  172. package/src/menu/next/menu-id.ts +0 -86
  173. package/src/menu/next/menu-service.ts +0 -252
  174. package/src/menu/next/menu-util.ts +0 -77
  175. package/src/menu/next/menu.contrib.interface.ts +0 -79
  176. package/src/menu/next/menu.interface.ts +0 -253
  177. package/src/menu/next/menubar-service.ts +0 -211
  178. package/src/menu/next/renderer/ctxmenu/base.ts +0 -18
  179. package/src/menu/next/renderer/ctxmenu/browser.ts +0 -45
  180. package/src/menu/next/renderer/ctxmenu/electron.ts +0 -207
  181. package/src/menu/next/toolbar-action.service.ts +0 -132
  182. package/src/monaco/index.ts +0 -128
  183. package/src/opener/command-opener.ts +0 -42
  184. package/src/opener/default-opener.ts +0 -31
  185. package/src/opener/http-opener.ts +0 -25
  186. package/src/opener/index.ts +0 -19
  187. package/src/opener/opener.contribution.ts +0 -57
  188. package/src/opener/opener.service.ts +0 -66
  189. package/src/preferences/early-preferences.ts +0 -117
  190. package/src/preferences/index.ts +0 -9
  191. package/src/preferences/preference-configurations.ts +0 -77
  192. package/src/preferences/preference-contribution.ts +0 -401
  193. package/src/preferences/preference-provider.ts +0 -414
  194. package/src/preferences/preference-proxy.ts +0 -292
  195. package/src/preferences/preference-scope.ts +0 -3
  196. package/src/preferences/preference-service.ts +0 -571
  197. package/src/preferences/settings.ts +0 -53
  198. package/src/preferences/types.ts +0 -111
  199. package/src/progress/index.ts +0 -58
  200. package/src/progress/progress-bar.tsx +0 -22
  201. package/src/progress/progress-indicator.ts +0 -90
  202. package/src/progress/progress.module.less +0 -46
  203. package/src/progress/progress.service.tsx +0 -429
  204. package/src/quick-open/index.ts +0 -655
  205. package/src/quick-open/recent-files.ts +0 -68
  206. package/src/raw-context-key.ts +0 -116
  207. package/src/react-hooks/event.tsx +0 -80
  208. package/src/react-hooks/hot-key.tsx +0 -58
  209. package/src/react-hooks/index.ts +0 -3
  210. package/src/react-hooks/injectable-hooks.tsx +0 -35
  211. package/src/react-hooks/portal-hooks.tsx +0 -38
  212. package/src/react-providers/config-provider.tsx +0 -263
  213. package/src/react-providers/index.tsx +0 -2
  214. package/src/react-providers/slot.module.less +0 -19
  215. package/src/react-providers/slot.tsx +0 -242
  216. package/src/services/clipboard.service.ts +0 -97
  217. package/src/services/credentials-service.ts +0 -91
  218. package/src/services/crypto-service.ts +0 -23
  219. package/src/services/external-uri.service.ts +0 -68
  220. package/src/services/index.ts +0 -7
  221. package/src/services/label-service.ts +0 -386
  222. package/src/services/status-bar-service.ts +0 -108
  223. package/src/services/storage-service.ts +0 -197
  224. package/src/style/codicons/README.md +0 -22
  225. package/src/style/codicons/codicon-animations.css +0 -15
  226. package/src/style/codicons/generator.js +0 -15
  227. package/src/style/entry.less +0 -25
  228. package/src/style/icon/fileicons/file-default.svg +0 -1
  229. package/src/style/icon/fileicons/folder-default.svg +0 -1
  230. package/src/style/icon/fileicons.less +0 -20
  231. package/src/style/icon/icon.ts +0 -543
  232. package/src/style/icon/ide-iconfont.ts +0 -13
  233. package/src/style/icon/index.less +0 -54
  234. package/src/style/icon/seti.woff +0 -0
  235. package/src/style/icon/symbol-icons/boolean-dark.svg +0 -3
  236. package/src/style/icon/symbol-icons/boolean-light.svg +0 -3
  237. package/src/style/icon/symbol-icons/class-dark.svg +0 -3
  238. package/src/style/icon/symbol-icons/class-light.svg +0 -3
  239. package/src/style/icon/symbol-icons/constant-dark.svg +0 -4
  240. package/src/style/icon/symbol-icons/constant-light.svg +0 -4
  241. package/src/style/icon/symbol-icons/enumerator-dark.svg +0 -3
  242. package/src/style/icon/symbol-icons/enumerator-item-dark.svg +0 -3
  243. package/src/style/icon/symbol-icons/enumerator-item-light.svg +0 -3
  244. package/src/style/icon/symbol-icons/enumerator-light.svg +0 -3
  245. package/src/style/icon/symbol-icons/event-dark.svg +0 -3
  246. package/src/style/icon/symbol-icons/event-light.svg +0 -3
  247. package/src/style/icon/symbol-icons/field-dark.svg +0 -3
  248. package/src/style/icon/symbol-icons/field-light.svg +0 -3
  249. package/src/style/icon/symbol-icons/file-dark.svg +0 -3
  250. package/src/style/icon/symbol-icons/file-light.svg +0 -3
  251. package/src/style/icon/symbol-icons/indexer-dark.svg +0 -3
  252. package/src/style/icon/symbol-icons/indexer-light.svg +0 -3
  253. package/src/style/icon/symbol-icons/interface-dark.svg +0 -3
  254. package/src/style/icon/symbol-icons/interface-light.svg +0 -3
  255. package/src/style/icon/symbol-icons/keyword-dark.svg +0 -3
  256. package/src/style/icon/symbol-icons/keyword-light.svg +0 -3
  257. package/src/style/icon/symbol-icons/method-dark.svg +0 -3
  258. package/src/style/icon/symbol-icons/method-light.svg +0 -3
  259. package/src/style/icon/symbol-icons/namespace-dark.svg +0 -3
  260. package/src/style/icon/symbol-icons/namespace-light.svg +0 -3
  261. package/src/style/icon/symbol-icons/numeric-dark.svg +0 -3
  262. package/src/style/icon/symbol-icons/numeric-light.svg +0 -3
  263. package/src/style/icon/symbol-icons/operator-dark.svg +0 -3
  264. package/src/style/icon/symbol-icons/operator-light.svg +0 -3
  265. package/src/style/icon/symbol-icons/property-dark.svg +0 -3
  266. package/src/style/icon/symbol-icons/property-light.svg +0 -3
  267. package/src/style/icon/symbol-icons/snippet-dark.svg +0 -3
  268. package/src/style/icon/symbol-icons/snippet-light.svg +0 -3
  269. package/src/style/icon/symbol-icons/string-dark.svg +0 -3
  270. package/src/style/icon/symbol-icons/string-light.svg +0 -3
  271. package/src/style/icon/symbol-icons/structure-dark.svg +0 -3
  272. package/src/style/icon/symbol-icons/structure-light.svg +0 -3
  273. package/src/style/icon/symbol-icons/symbol-icons.css +0 -284
  274. package/src/style/icon/symbol-icons/template-dark.svg +0 -3
  275. package/src/style/icon/symbol-icons/template-light.svg +0 -3
  276. package/src/style/icon/symbol-icons/variable-dark.svg +0 -3
  277. package/src/style/icon/symbol-icons/variable-light.svg +0 -3
  278. package/src/style/icon.less +0 -8
  279. package/src/style/index.less +0 -14
  280. package/src/style/monaco-override.less +0 -116
  281. package/src/style/normalize.less +0 -92
  282. package/src/style/octicons/octicons-cdn.css +0 -720
  283. package/src/style/octicons/octicons.css +0 -714
  284. package/src/style/octicons/octicons.html +0 -1882
  285. package/src/style/octicons/octicons.svg +0 -582
  286. package/src/style/octicons/octicons.ttf +0 -0
  287. package/src/style/override.less +0 -97
  288. package/src/style/toolbar.less +0 -199
  289. package/src/style/utilities.less +0 -8
  290. package/src/style/variable.less +0 -8
  291. package/src/terminal/index.ts +0 -7
  292. package/src/toolbar/components/auto-complete.tsx +0 -0
  293. package/src/toolbar/components/button.tsx +0 -440
  294. package/src/toolbar/components/index.ts +0 -2
  295. package/src/toolbar/components/select.tsx +0 -189
  296. package/src/toolbar/index.ts +0 -3
  297. package/src/toolbar/toolbar.popover.registry.ts +0 -32
  298. package/src/toolbar/toolbar.registry.ts +0 -352
  299. package/src/toolbar/toolbar.tsx +0 -710
  300. package/src/toolbar/types.ts +0 -383
  301. package/src/tree/index.ts +0 -3
  302. package/src/tree/tree-expansion.ts +0 -25
  303. package/src/tree/tree-selection.ts +0 -89
  304. package/src/tree/tree.ts +0 -294
  305. package/src/utils/create-overlay.tsx +0 -53
  306. package/src/utils/electron.ts +0 -92
  307. package/src/utils/env.ts +0 -26
  308. package/src/utils/icon.ts +0 -13
  309. package/src/utils/index.ts +0 -7
  310. package/src/utils/json.ts +0 -251
  311. package/src/utils/label.tsx +0 -36
  312. package/src/utils/parse.ts +0 -72
  313. package/src/utils/react-hooks.ts +0 -118
  314. package/src/variable/index.ts +0 -1
  315. package/src/variable/variable.ts +0 -84
  316. package/src/window/index.ts +0 -34
  317. package/src/window/window.service.ts +0 -100
@@ -1,710 +0,0 @@
1
- import classnames from 'classnames';
2
- import throttle from 'lodash/throttle';
3
- import React from 'react';
4
- import ReactDOM from 'react-dom';
5
-
6
- import { IEventBus, Disposable, Emitter } from '@opensumi/ide-core-common';
7
-
8
- import { DomListener } from '../dom';
9
- import { AbstractMenuService, MenuId, generateCtxMenu, ICtxMenuRenderer } from '../menu/next';
10
- import { PreferenceService } from '../preferences';
11
- import { useInjectable } from '../react-hooks';
12
- import { ConfigContext, ConfigProvider, AppConfig } from '../react-providers/config-provider';
13
- import { getIcon } from '../style/icon/icon';
14
-
15
- import {
16
- IToolbarRegistry,
17
- ToolbarActionGroupsChangedEvent,
18
- IToolbarAction,
19
- ISize,
20
- ToolbarActionsChangedEvent,
21
- IToolbarLocationProps,
22
- IToolbarLocationPreference,
23
- IToolbarActionElementProps,
24
- ToolbarRegistryReadyEvent,
25
- ToolbarActionsWhenChangeEvent,
26
- } from './types';
27
-
28
- export const DEFAULT_TOOLBAR_ACTION_MARGIN = 5;
29
- export const DEFAULT_TOOLBAR_MORE_WIDTH = 14;
30
-
31
- declare let ResizeObserver: any;
32
-
33
- const renderedActions = new Map<string, ToolbarActionRenderer>();
34
-
35
- const elementSizeDiffEmitter: Emitter<string> = new Emitter();
36
-
37
- const dropDownShouldCloseEmitter: Emitter<string> = new Emitter();
38
-
39
- export const ToolbarLocation = (props: IToolbarLocationProps & React.HTMLAttributes<HTMLDivElement>) => {
40
- const registry: IToolbarRegistry = useInjectable(IToolbarRegistry);
41
- const menuService: AbstractMenuService = useInjectable(AbstractMenuService);
42
- const contextMenuRenderer: ICtxMenuRenderer = useInjectable(ICtxMenuRenderer);
43
- if (!registry.hasLocation(props.location)) {
44
- registry.addLocation(props.location);
45
- }
46
- const context: AppConfig = React.useContext(ConfigContext);
47
- const eventBus: IEventBus = useInjectable(IEventBus);
48
- const container = React.useRef<HTMLDivElement>();
49
- const preferenceService: PreferenceService = useInjectable(PreferenceService);
50
- const { location, preferences = {} } = props;
51
- let ignoreActions: string[];
52
- const setIgnoreActions = (v) => {
53
- ignoreActions = v.slice();
54
- };
55
- setIgnoreActions(
56
- (preferenceService.get<{ [location: string]: string[] }>('toolbar.ignoreActions', {}) || {})[location] || [],
57
- );
58
-
59
- const shouldListenInitialization = !registry.isReady();
60
-
61
- React.useEffect(() => {
62
- if (container.current) {
63
- const disposer = new Disposable();
64
- const debouncedUpdate = throttle(() => {
65
- updateNow();
66
- }, 200);
67
- const updateNow = () => {
68
- if (container.current) {
69
- setIgnoreActions(
70
- (preferenceService.get<{ [location: string]: string[] }>('toolbar.ignoreActions', {}) || {})[location] ||
71
- [],
72
- );
73
- renderToolbarLocation(container.current, location, preferences, registry, context, ignoreActions);
74
- }
75
- };
76
- if (shouldListenInitialization) {
77
- disposer.addDispose(
78
- eventBus.once(ToolbarRegistryReadyEvent, (e) => {
79
- updateNow();
80
- }),
81
- );
82
- }
83
- disposer.addDispose(
84
- eventBus.on(ToolbarActionsWhenChangeEvent, () => {
85
- updateNow();
86
- }),
87
- );
88
- disposer.addDispose(
89
- eventBus.on(ToolbarActionGroupsChangedEvent, (e) => {
90
- if (e.payload.location === location) {
91
- debouncedUpdate();
92
- }
93
- }),
94
- );
95
- disposer.addDispose(
96
- eventBus.on(ToolbarActionsChangedEvent, (e) => {
97
- if (e.payload.position.location === location) {
98
- debouncedUpdate();
99
- }
100
- }),
101
- );
102
- disposer.addDispose(
103
- elementSizeDiffEmitter.event((actionId) => {
104
- const position = registry.getActionPosition(actionId);
105
- if (position && position.location === location) {
106
- debouncedUpdate();
107
- }
108
- }),
109
- );
110
- disposer.addDispose(
111
- preferenceService.onPreferenceChanged((e) => {
112
- if (e.preferenceName === 'toolbar.ignoreActions') {
113
- const newValue =
114
- (preferenceService.get<{ [location: string]: string[] }>('toolbar.ignoreActions', {}) || {})[location] ||
115
- [];
116
- // 如果两个数组存在不同,刷新
117
- for (const id of newValue) {
118
- if (ignoreActions.indexOf(id) === -1) {
119
- updateNow();
120
- return;
121
- }
122
- }
123
- for (const id of ignoreActions) {
124
- if (newValue.indexOf(id) === -1) {
125
- updateNow();
126
- return;
127
- }
128
- }
129
- }
130
- }),
131
- );
132
- if (!preferences.noDropDown) {
133
- let previousWidth = container.current.offsetWidth;
134
- renderToolbarLocation(container.current, location, preferences, registry, context, ignoreActions);
135
- const observer = new ResizeObserver((entries) => {
136
- const contentRect = entries[0].contentRect;
137
- if (contentRect.width !== previousWidth) {
138
- debouncedUpdate();
139
- }
140
- previousWidth = contentRect.width;
141
- });
142
- observer.observe(container.current);
143
- disposer.addDispose({
144
- dispose: () => observer.disconnect(),
145
- });
146
- } else {
147
- renderToolbarLocation(container.current, location, preferences, registry, context, ignoreActions);
148
- }
149
- return () => disposer.dispose();
150
- }
151
- }, []);
152
-
153
- return (
154
- <div
155
- {...props}
156
- className={classnames('kt-toolbar-location', props.className)}
157
- id={'toolbar-location-' + location}
158
- ref={container as any}
159
- onContextMenu={(event: React.MouseEvent<HTMLElement>) => {
160
- if (
161
- event.nativeEvent
162
- .composedPath()
163
- .find((e) => (e as any).getAttribute && (e as any).getAttribute('data-toolbar-no-context'))
164
- ) {
165
- return;
166
- }
167
- event.preventDefault();
168
- const menus = menuService.createMenu(MenuId.KTToolbarLocationContext);
169
- const menuNodes = generateCtxMenu({ menus });
170
- contextMenuRenderer.show({
171
- menuNodes: menuNodes[1],
172
- anchor: {
173
- x: event.clientX,
174
- y: event.clientY,
175
- },
176
- });
177
- }}
178
- ></div>
179
- );
180
- };
181
-
182
- interface ActionSplit {
183
- type: 'split';
184
- }
185
-
186
- function isActionSplit(target: IToolbarAction | ActionSplit): target is ActionSplit {
187
- return (target as ActionSplit).type === 'split';
188
- }
189
-
190
- interface IResolvedToolbarAction {
191
- action: IToolbarAction;
192
- marginLeft: number;
193
- extraClassNames?: string[];
194
- noGroupSplit?: boolean;
195
- }
196
-
197
- interface IResolvedToolbarActionOrSplit {
198
- action: IToolbarAction | ActionSplit;
199
- marginLeft: number;
200
- extraClassNames?: string[];
201
- noGroupSplit?: boolean;
202
- }
203
-
204
- function renderToolbarLocation(
205
- container: HTMLDivElement,
206
- location: string,
207
- preference: IToolbarLocationPreference,
208
- registry: IToolbarRegistry,
209
- context: AppConfig,
210
- ignoreActions: string[],
211
- ) {
212
- const TOOLBAR_ACTION_MARGIN =
213
- preference.actionMargin === undefined ? DEFAULT_TOOLBAR_ACTION_MARGIN : preference.actionMargin;
214
- const TOOLBAR_MORE_WIDTH =
215
- preference.moreActionWidth === undefined ? DEFAULT_TOOLBAR_MORE_WIDTH : preference.moreActionWidth;
216
-
217
- for (let i = 0; i < container.children.length; i++) {
218
- container.children[i].remove();
219
- i--;
220
- }
221
-
222
- const locationContainer = document.createElement('div');
223
- locationContainer.classList.add('kt-toolbar-location-visible');
224
- locationContainer.id = 'toolbar-location-visible-' + location;
225
- const dropDownId = 'toolbar-location-dropdown-' + location;
226
- let locationDropDownContainer: HTMLDivElement;
227
- if (document.getElementById(dropDownId)) {
228
- locationDropDownContainer = document.getElementById(dropDownId)! as HTMLDivElement;
229
- for (let i = 0; i < locationDropDownContainer.children.length; i++) {
230
- locationDropDownContainer.children[i].remove();
231
- i--;
232
- }
233
- } else {
234
- locationDropDownContainer = document.createElement('div');
235
- locationDropDownContainer.classList.add('kt-toolbar-location-dropdown');
236
- locationDropDownContainer.id = dropDownId;
237
- }
238
- container.append(locationContainer);
239
- document.body.append(locationDropDownContainer);
240
-
241
- const totalWidth = getContentWidth(locationContainer);
242
- let usedWidth = 0;
243
-
244
- const groups = ['_head', ...(registry.getActionGroups(location) || []).map((g) => g.id), '_tail'];
245
-
246
- const visibleActionsOrSplits: Array<IResolvedToolbarActionOrSplit> = [];
247
- const groupActions: IResolvedToolbarAction[][] = [];
248
- const dropDownActionsOrSplits: Array<IToolbarAction | ActionSplit> = [];
249
-
250
- for (const group of groups) {
251
- const result = registry.getToolbarActions({ location, group });
252
- const actions = result?.actions.filter((a) => ignoreActions.indexOf(a.id) === -1);
253
- if (actions && actions.length > 0) {
254
- if (
255
- visibleActionsOrSplits.length > 0 &&
256
- !visibleActionsOrSplits[visibleActionsOrSplits.length - 1].noGroupSplit
257
- ) {
258
- visibleActionsOrSplits.push({
259
- action: {
260
- type: 'split',
261
- },
262
- marginLeft: TOOLBAR_ACTION_MARGIN,
263
- });
264
- }
265
- const resolved = actions.map((action, i) => {
266
- const groupMargin = result!.group?.compact ? 0 : TOOLBAR_ACTION_MARGIN;
267
- const extraClassNames: string[] = [];
268
- if (result?.group?.compact) {
269
- extraClassNames.push('kt-toolbar-action-wrapper-compact');
270
- if (i === actions.length - 1) {
271
- extraClassNames.push('kt-toolbar-action-wrapper-compact-tail');
272
- }
273
- if (i === 0) {
274
- extraClassNames.push('kt-toolbar-action-wrapper-compact-head');
275
- }
276
- if (i !== 0 && i !== actions.length - 1) {
277
- extraClassNames.push('kt-toolbar-action-wrapper-compact-middle');
278
- }
279
- }
280
-
281
- return {
282
- action,
283
- marginLeft: i === 0 ? TOOLBAR_ACTION_MARGIN : groupMargin,
284
- extraClassNames,
285
- noGroupSplit: !!result!.group?.compact,
286
- };
287
- });
288
- visibleActionsOrSplits.push(...resolved);
289
- groupActions.push(resolved);
290
- }
291
- }
292
-
293
- if (visibleActionsOrSplits.length === 0) {
294
- locationContainer.classList.add('kt-toolbar-location-no-actions');
295
- } else {
296
- locationContainer.classList.remove('kt-toolbar-location-no-actions');
297
- }
298
-
299
- let shouldCollapse = false;
300
-
301
- if (!preference.noDropDown) {
302
- // 根据元素宽度计算哪些在外面,哪些在 dropdown
303
- for (let i = 0; i < visibleActionsOrSplits.length; i++) {
304
- const actionOrSplit = visibleActionsOrSplits[i];
305
- const elementWidth: number = getActionOrSplitWidth(actionOrSplit.action, false);
306
-
307
- if (!shouldCollapse) {
308
- if (
309
- usedWidth +
310
- (i !== 0 ? actionOrSplit.marginLeft : 0) +
311
- elementWidth +
312
- TOOLBAR_ACTION_MARGIN +
313
- TOOLBAR_MORE_WIDTH >
314
- totalWidth
315
- ) {
316
- // 此时,剩余的空间已经不足以容纳当前 action + more 按钮了
317
- // 判断当前 action 开始到最后的大小,是否小于 more 按钮的宽度
318
- let restWidth = 0;
319
- for (let j = i; j < visibleActionsOrSplits.length; j++) {
320
- restWidth +=
321
- (j !== 0 ? actionOrSplit.marginLeft : 0) + getActionOrSplitWidth(visibleActionsOrSplits[j].action, false);
322
- }
323
- if (restWidth < TOOLBAR_ACTION_MARGIN + TOOLBAR_MORE_WIDTH) {
324
- // 能容纳, 无需分组
325
- break;
326
- } else {
327
- // 不能容纳,先打标,继续循环以计算整个工具条的长度
328
- shouldCollapse = true;
329
- }
330
- }
331
- }
332
- usedWidth += (i !== 0 ? actionOrSplit.marginLeft : 0) + elementWidth;
333
- }
334
- }
335
-
336
- if (shouldCollapse) {
337
- // 由于需要collapse, 现在开始寻找合适的方式收起
338
- // 从右往左开始,尝试寻找能收起的元素,并将其放入dropDown元素中
339
- // 收集所有能被收集的元素的index
340
- const collapsableElementIndexes: [number, number][] = [];
341
- const dropdownGroupActions: IToolbarAction[][] = [];
342
- groupActions.forEach((group, gi) => {
343
- group.forEach((action, ai) => {
344
- if (!action.action.neverCollapse) {
345
- collapsableElementIndexes.push([gi, ai]);
346
- }
347
- });
348
- dropdownGroupActions.push([]);
349
- });
350
-
351
- // 反向pop出能收起的元素,看看去除后能否满足条件
352
- while (usedWidth + TOOLBAR_ACTION_MARGIN + TOOLBAR_MORE_WIDTH > totalWidth) {
353
- if (collapsableElementIndexes.length === 0) {
354
- // 此时已经再也无法满足条件,let it be
355
- break;
356
- }
357
- const nextElementIndex = collapsableElementIndexes.pop()!;
358
- // 虽然此处splice会改变index,但是由于我们是从后往前,所以问题不大
359
- const [action] = groupActions[nextElementIndex[0]].splice(nextElementIndex[1], 1);
360
- dropdownGroupActions[nextElementIndex[0]]!.push(action.action);
361
- // 去掉一个元素的宽度
362
- usedWidth -= TOOLBAR_ACTION_MARGIN + getActionOrSplitWidth(action.action, false);
363
- // 弹出后,如果groupActions为空且groupActions的group数量大于1,再去掉一个actionSplit的宽度
364
- if (groupActions.length > 1 && groupActions[nextElementIndex[0]].length === 0) {
365
- usedWidth -= TOOLBAR_ACTION_MARGIN + 1;
366
- }
367
- }
368
- // 获得此时的visibleActions和dropdownActions
369
- visibleActionsOrSplits.splice(0);
370
- const nonEmpty = groupActions.filter((g) => g.length > 0);
371
- nonEmpty.map((g, gi) => {
372
- if (gi !== 0 && !nonEmpty[gi - 1][0].noGroupSplit) {
373
- visibleActionsOrSplits.push({
374
- action: {
375
- type: 'split',
376
- },
377
- marginLeft: TOOLBAR_ACTION_MARGIN,
378
- });
379
- }
380
- visibleActionsOrSplits.push(...g);
381
- });
382
-
383
- dropDownActionsOrSplits.splice(0);
384
- dropdownGroupActions
385
- .reverse()
386
- .filter((g) => g.length > 0)
387
- .map((g, gi) => {
388
- if (gi !== 0) {
389
- dropDownActionsOrSplits.push({
390
- type: 'split',
391
- });
392
- }
393
- dropDownActionsOrSplits.push(...g);
394
- });
395
- dropDownActionsOrSplits.reverse();
396
- }
397
-
398
- // 开始渲染
399
- visibleActionsOrSplits.forEach((actionOrSplit) => {
400
- if (isActionSplit(actionOrSplit.action)) {
401
- const splitElement = document.createElement('div');
402
- splitElement.classList.add('kt-toolbar-action-split');
403
- locationContainer.append(splitElement);
404
- } else {
405
- appendActionToLocationContainer(
406
- locationContainer,
407
- actionOrSplit as IResolvedToolbarAction,
408
- context,
409
- false,
410
- location,
411
- preference,
412
- );
413
- }
414
- });
415
-
416
- if (dropDownActionsOrSplits.length > 0) {
417
- const moreElement = document.createElement('div');
418
- moreElement.classList.add('kt-toolbar-more');
419
- const moreLink = document.createElement('div');
420
- moreLink.classList.add(...getIcon('more').split(' '));
421
- moreElement.append(moreLink);
422
- locationContainer.append(moreElement);
423
- moreLink.addEventListener('mousedown', () => {
424
- toggleDropdown(moreElement, location);
425
- });
426
- }
427
-
428
- dropDownActionsOrSplits.forEach((actionOrSplit, i) => {
429
- if (isActionSplit(actionOrSplit)) {
430
- if (i === 0) {
431
- return;
432
- }
433
- const splitElement = document.createElement('div');
434
- splitElement.classList.add('kt-toolbar-action-split');
435
- locationDropDownContainer.appendChild(splitElement);
436
- } else {
437
- appendActionToLocationContainer(
438
- locationDropDownContainer,
439
- { action: actionOrSplit, marginLeft: 0 },
440
- context,
441
- true,
442
- location,
443
- preference,
444
- );
445
- }
446
- });
447
- }
448
-
449
- function toggleDropdown(ele, location: string) {
450
- const locationId = 'toolbar-location-visible-' + location;
451
- const dropDownId = 'toolbar-location-dropdown-' + location;
452
- const locationElement = document.getElementById(locationId);
453
- const dropDownElement = document.getElementById(dropDownId);
454
- if (locationElement && dropDownElement) {
455
- if (dropDownElement.style.display === 'block') {
456
- return;
457
- }
458
- const pos = locationElement.getBoundingClientRect();
459
- dropDownElement.style.top = pos.y + pos.height + 'px';
460
- dropDownElement.style.right = window.innerWidth - pos.x - pos.width + 'px';
461
- dropDownElement.style.display = 'block';
462
- setTimeout(() => {
463
- const disposer = new Disposable();
464
- disposer.addDispose(
465
- new DomListener(ele, 'mousedown', (e: MouseEvent) => {
466
- dropDownShouldCloseEmitter.fire(location);
467
- disposer.dispose();
468
- e.stopPropagation();
469
- }),
470
- );
471
- disposer.addDispose(
472
- new DomListener(dropDownElement, 'mousedown', (e: MouseEvent) => {
473
- e.stopPropagation();
474
- }),
475
- );
476
- disposer.addDispose(
477
- new DomListener(document.body, 'mousedown', (e: MouseEvent) => {
478
- disposer.dispose();
479
- dropDownElement.style.display = 'none';
480
- }),
481
- );
482
- disposer.addDispose(
483
- dropDownShouldCloseEmitter.event((locationName: string) => {
484
- if (locationName === location) {
485
- disposer.dispose();
486
- dropDownElement.style.display = 'none';
487
- }
488
- }),
489
- );
490
- });
491
- }
492
- }
493
-
494
- function getActionOrSplitWidth(actionOrSplit: IToolbarAction | ActionSplit, inDropDown: boolean) {
495
- if (isActionSplit(actionOrSplit)) {
496
- return 1;
497
- } else {
498
- // action 的计算逻辑
499
- const renderedSize = inDropDown
500
- ? renderedActions.get(actionOrSplit.id)?.size.inDropDown
501
- : renderedActions.get(actionOrSplit.id)?.size.visible;
502
- return renderedSize ? renderedSize.width : actionOrSplit.suggestSize ? actionOrSplit.suggestSize.width : 20;
503
- }
504
- }
505
-
506
- async function appendActionToLocationContainer(
507
- container: HTMLDivElement,
508
- toolbarAction: IResolvedToolbarAction,
509
- context: AppConfig,
510
- inDropDown: boolean,
511
- location: string,
512
- preferences?: IToolbarLocationPreference,
513
- ): Promise<void> {
514
- const actionContainer = document.createElement('div');
515
- container.appendChild(actionContainer);
516
- return rendererToolbarActionComponent(toolbarAction, actionContainer, context, inDropDown, location, preferences);
517
- }
518
-
519
- async function rendererToolbarActionComponent(
520
- toolbarAction: IResolvedToolbarAction,
521
- container: HTMLDivElement,
522
- context: AppConfig,
523
- inDropDown: boolean,
524
- location: string,
525
- preferences?: IToolbarLocationPreference,
526
- ): Promise<void> {
527
- if (!renderedActions.has(toolbarAction.action.id)) {
528
- renderedActions.set(toolbarAction.action.id, new ToolbarActionRenderer(toolbarAction, context));
529
- }
530
- return renderedActions.get(toolbarAction.action.id)!.attachTo(container, inDropDown, location, preferences);
531
- }
532
-
533
- function getContentWidth(element) {
534
- const styles = getComputedStyle(element);
535
-
536
- return element.clientWidth - parseFloat(styles.paddingLeft) - parseFloat(styles.paddingRight);
537
- }
538
-
539
- class ToolbarActionRenderer {
540
- private renderPromise: {
541
- promise: Promise<HTMLDivElement>;
542
- cancel: () => void;
543
- inDropDown: boolean;
544
- resolved?: HTMLDivElement;
545
- };
546
-
547
- private targetContainer: HTMLDivElement | undefined;
548
- private targetInDropDown = false;
549
- public size: {
550
- visible?: ISize;
551
- inDropDown?: ISize;
552
- } = {};
553
-
554
- private reactElement: {
555
- element: HTMLDivElement | undefined;
556
- setInDropDown: (inDropDown: boolean) => void;
557
- };
558
-
559
- private toolbarAction: IToolbarAction;
560
-
561
- constructor(private resolvedToolbarAction: IResolvedToolbarAction, private context: AppConfig) {
562
- this.toolbarAction = resolvedToolbarAction.action;
563
- }
564
-
565
- render(inDropDown: boolean, location: string, preferences?: IToolbarLocationPreference): Promise<HTMLDivElement> {
566
- if (this.renderPromise) {
567
- if (this.renderPromise.inDropDown === inDropDown) {
568
- return this.renderPromise.promise;
569
- }
570
- }
571
- // 取消上一次渲染
572
- if (this.renderPromise) {
573
- this.renderPromise.cancel();
574
- }
575
- return this.doRender(inDropDown, location, preferences);
576
- }
577
-
578
- get element(): HTMLDivElement | undefined {
579
- return this.renderPromise && this.renderPromise.resolved;
580
- }
581
-
582
- attachTo(
583
- container: HTMLDivElement,
584
- inDropDown: boolean,
585
- location,
586
- preferences?: IToolbarLocationPreference,
587
- ): Promise<void> {
588
- this.targetContainer = container;
589
- this.targetInDropDown = inDropDown;
590
- return this.render(inDropDown, location, preferences).then((element) => {
591
- if (this.targetContainer === container && inDropDown === this.targetInDropDown) {
592
- if (element.parentElement) {
593
- element.remove();
594
- }
595
- container.replaceWith(element);
596
- setTimeout(() => {
597
- if (!element || element.offsetWidth === 0) {
598
- return;
599
- }
600
- let previousSize;
601
- if (inDropDown) {
602
- previousSize = this.size.inDropDown || this.toolbarAction.suggestSize || { width: 20, height: 30 };
603
- this.size.inDropDown = {
604
- width: element.offsetWidth,
605
- height: element.offsetHeight,
606
- };
607
- } else {
608
- previousSize = this.size.visible || this.toolbarAction.suggestSize || { width: 20, height: 30 };
609
- this.size.visible = {
610
- width: element.offsetWidth,
611
- height: element.offsetHeight,
612
- };
613
- }
614
-
615
- if (element.offsetWidth !== previousSize.width) {
616
- elementSizeDiffEmitter.fire(this.toolbarAction.id);
617
- }
618
- });
619
- }
620
- });
621
- }
622
-
623
- doRender(inDropDown, location: string, preferences?: IToolbarLocationPreference) {
624
- let canceled = false;
625
- this.renderPromise = {
626
- cancel: () => {
627
- canceled = true;
628
- },
629
- promise: new Promise<HTMLDivElement>((resolve, reject) => {
630
- if (this.reactElement) {
631
- this.reactElement.setInDropDown(inDropDown);
632
- resolve(this.reactElement.element!);
633
- } else {
634
- const element = document.createElement('div');
635
- element.classList.add('kt-toolbar-action-wrapper');
636
- element.setAttribute('data-toolbar-action-id', this.toolbarAction.id);
637
- if (this.resolvedToolbarAction.extraClassNames) {
638
- element.classList.add(...this.resolvedToolbarAction.extraClassNames);
639
- }
640
- let setInDropDown: (inDropDown: boolean) => void | undefined;
641
- ReactDOM.render(
642
- <ToolbarActionRenderWrapper
643
- initialInDropDown={inDropDown}
644
- action={this.toolbarAction}
645
- preferences={preferences}
646
- setInDropDownHandle={(handle) => (setInDropDown = handle)}
647
- context={this.context}
648
- component={this.toolbarAction.component}
649
- closeDropdown={() => {
650
- dropDownShouldCloseEmitter.fire(location);
651
- }}
652
- location={location}
653
- />,
654
- element,
655
- () => {
656
- if (canceled) {
657
- reject('canceled render toolbar');
658
- } else {
659
- this.reactElement = {
660
- element,
661
- setInDropDown: (inDropdown: boolean) => {
662
- if (setInDropDown) {
663
- setInDropDown(inDropdown);
664
- }
665
- },
666
- };
667
- resolve(element);
668
- }
669
- },
670
- );
671
- }
672
- }).then((resolved) => {
673
- this.renderPromise.resolved = resolved;
674
- return this.renderPromise.resolved;
675
- }),
676
- inDropDown,
677
- };
678
- return this.renderPromise.promise;
679
- }
680
- }
681
-
682
- export const ToolbarActionRenderWrapper = (props: {
683
- setInDropDownHandle: (setInDropDown: (inDropDown: boolean) => void) => void;
684
- initialInDropDown: boolean;
685
- component: React.FC<IToolbarActionElementProps> | React.ComponentClass<IToolbarActionElementProps>;
686
- context: AppConfig;
687
- action: IToolbarAction;
688
- closeDropdown: () => void;
689
- preferences?: IToolbarLocationPreference;
690
- location: string;
691
- }) => {
692
- const [inDropDown, setInDropDown] = React.useState<boolean>(props.initialInDropDown);
693
- const C = props.component;
694
- React.useEffect(() => {
695
- props.setInDropDownHandle((inDropDown) => {
696
- setInDropDown(inDropDown);
697
- });
698
- }, []);
699
- return (
700
- <ConfigProvider value={props.context}>
701
- <C
702
- inDropDown={inDropDown}
703
- action={props.action}
704
- preferences={props.preferences}
705
- closeDropDown={props.closeDropdown}
706
- location={props.location}
707
- />
708
- </ConfigProvider>
709
- );
710
- };