@theia/toolbar 1.45.1 → 1.46.0-next.72

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 (53) hide show
  1. package/README.md +32 -32
  2. package/lib/browser/abstract-toolbar-contribution.d.ts +16 -16
  3. package/lib/browser/abstract-toolbar-contribution.js +68 -68
  4. package/lib/browser/application-shell-with-toolbar-override.d.ts +15 -15
  5. package/lib/browser/application-shell-with-toolbar-override.js +101 -101
  6. package/lib/browser/codicons.d.ts +1 -1
  7. package/lib/browser/codicons.js +20 -20
  8. package/lib/browser/font-awesome-icons.d.ts +1 -1
  9. package/lib/browser/font-awesome-icons.js +20 -20
  10. package/lib/browser/package.spec.js +18 -18
  11. package/lib/browser/toolbar-command-contribution.d.ts +25 -25
  12. package/lib/browser/toolbar-command-contribution.js +211 -211
  13. package/lib/browser/toolbar-command-quick-input-service.d.ts +19 -19
  14. package/lib/browser/toolbar-command-quick-input-service.js +112 -112
  15. package/lib/browser/toolbar-constants.d.ts +23 -23
  16. package/lib/browser/toolbar-constants.js +75 -75
  17. package/lib/browser/toolbar-controller.d.ts +34 -34
  18. package/lib/browser/toolbar-controller.js +186 -186
  19. package/lib/browser/toolbar-defaults.d.ts +3 -3
  20. package/lib/browser/toolbar-defaults.js +60 -60
  21. package/lib/browser/toolbar-frontend-module.d.ts +4 -4
  22. package/lib/browser/toolbar-frontend-module.js +25 -25
  23. package/lib/browser/toolbar-icon-selector-dialog.d.ts +65 -65
  24. package/lib/browser/toolbar-icon-selector-dialog.js +235 -235
  25. package/lib/browser/toolbar-interfaces.d.ts +45 -45
  26. package/lib/browser/toolbar-interfaces.js +42 -42
  27. package/lib/browser/toolbar-preference-contribution.d.ts +9 -9
  28. package/lib/browser/toolbar-preference-contribution.js +34 -34
  29. package/lib/browser/toolbar-preference-schema.d.ts +5 -5
  30. package/lib/browser/toolbar-preference-schema.js +73 -73
  31. package/lib/browser/toolbar-storage-provider.d.ts +47 -47
  32. package/lib/browser/toolbar-storage-provider.js +357 -357
  33. package/lib/browser/toolbar.d.ts +56 -56
  34. package/lib/browser/toolbar.js +380 -380
  35. package/package.json +11 -11
  36. package/src/browser/abstract-toolbar-contribution.tsx +53 -53
  37. package/src/browser/application-shell-with-toolbar-override.ts +98 -98
  38. package/src/browser/codicons.ts +18 -18
  39. package/src/browser/font-awesome-icons.ts +18 -18
  40. package/src/browser/package.spec.ts +19 -19
  41. package/src/browser/style/toolbar.css +255 -255
  42. package/src/browser/toolbar-command-contribution.ts +211 -211
  43. package/src/browser/toolbar-command-quick-input-service.ts +86 -86
  44. package/src/browser/toolbar-constants.ts +79 -79
  45. package/src/browser/toolbar-controller.ts +185 -185
  46. package/src/browser/toolbar-defaults.ts +58 -58
  47. package/src/browser/toolbar-frontend-module.ts +30 -30
  48. package/src/browser/toolbar-icon-selector-dialog.tsx +296 -296
  49. package/src/browser/toolbar-interfaces.ts +76 -76
  50. package/src/browser/toolbar-preference-contribution.ts +38 -38
  51. package/src/browser/toolbar-preference-schema.ts +75 -75
  52. package/src/browser/toolbar-storage-provider.ts +352 -352
  53. package/src/browser/toolbar.tsx +424 -424
@@ -1,381 +1,381 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2022 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- 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;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.ToolbarImpl = exports.TOOLBAR_PROGRESSBAR_ID = void 0;
28
- const React = require("@theia/core/shared/react");
29
- const browser_1 = require("@theia/core/lib/browser");
30
- const label_parser_1 = require("@theia/core/lib/browser/label-parser");
31
- const tab_bar_toolbar_1 = require("@theia/core/lib/browser/shell/tab-bar-toolbar");
32
- const inversify_1 = require("@theia/core/shared/inversify");
33
- const core_1 = require("@theia/core");
34
- const frontend_application_state_1 = require("@theia/core/lib/browser/frontend-application-state");
35
- const progress_bar_factory_1 = require("@theia/core/lib/browser/progress-bar-factory");
36
- const promise_util_1 = require("@theia/core/lib/common/promise-util");
37
- const toolbar_interfaces_1 = require("./toolbar-interfaces");
38
- const toolbar_controller_1 = require("./toolbar-controller");
39
- const toolbar_constants_1 = require("./toolbar-constants");
40
- const TOOLBAR_BACKGROUND_DATA_ID = 'toolbar-wrapper';
41
- exports.TOOLBAR_PROGRESSBAR_ID = 'main-toolbar-progress';
42
- let ToolbarImpl = class ToolbarImpl extends tab_bar_toolbar_1.TabBarToolbar {
43
- constructor() {
44
- super(...arguments);
45
- this.deferredRef = new promise_util_1.Deferred();
46
- this.isBusyDeferred = new promise_util_1.Deferred();
47
- this.handleContextMenu = (e) => this.doHandleContextMenu(e);
48
- this.assignRef = (element) => this.doAssignRef(element);
49
- this.handleOnDragStart = (e) => this.doHandleOnDragStart(e);
50
- this.handleOnDragEnter = (e) => this.doHandleItemOnDragEnter(e);
51
- this.handleOnDragLeave = (e) => this.doHandleOnDragLeave(e);
52
- this.handleOnDrop = (e) => this.doHandleOnDrop(e);
53
- this.handleOnDragEnd = (e) => this.doHandleOnDragEnd(e);
54
- }
55
- init() {
56
- super.init();
57
- this.doInit();
58
- }
59
- async doInit() {
60
- this.hide();
61
- await this.model.ready.promise;
62
- this.updateInlineItems();
63
- this.update();
64
- this.model.onToolbarModelDidUpdate(() => {
65
- this.updateInlineItems();
66
- this.update();
67
- });
68
- this.model.onToolbarDidChangeBusyState(isBusy => {
69
- if (isBusy) {
70
- this.isBusyDeferred = new promise_util_1.Deferred();
71
- this.progressService.withProgress('', exports.TOOLBAR_PROGRESSBAR_ID, async () => this.isBusyDeferred.promise);
72
- }
73
- else {
74
- this.isBusyDeferred.resolve();
75
- }
76
- });
77
- await this.deferredRef.promise;
78
- this.progressFactory({ container: this.node, insertMode: 'append', locationId: exports.TOOLBAR_PROGRESSBAR_ID });
79
- }
80
- updateInlineItems() {
81
- var _a;
82
- this.inline.clear();
83
- const { items } = this.model.toolbarItems;
84
- const contextKeys = new Set();
85
- for (const column of Object.keys(items)) {
86
- for (const group of items[column]) {
87
- for (const item of group) {
88
- this.inline.set(item.id, item);
89
- if (item.when) {
90
- (_a = this.contextKeyService.parseKeys(item.when)) === null || _a === void 0 ? void 0 : _a.forEach(key => contextKeys.add(key));
91
- }
92
- }
93
- }
94
- }
95
- this.updateContextKeyListener(contextKeys);
96
- }
97
- doHandleContextMenu(event) {
98
- event.preventDefault();
99
- event.stopPropagation();
100
- const contextMenuArgs = this.getContextMenuArgs(event);
101
- const { menuPath, anchor } = this.getMenuDetailsForClick(event);
102
- return this.contextMenuRenderer.render({
103
- args: contextMenuArgs,
104
- menuPath,
105
- anchor,
106
- });
107
- }
108
- getMenuDetailsForClick(event) {
109
- const clickId = event.currentTarget.getAttribute('data-id');
110
- let menuPath;
111
- let anchor;
112
- if (clickId === TOOLBAR_BACKGROUND_DATA_ID) {
113
- menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_BACKGROUND_CONTEXT_MENU;
114
- const { clientX, clientY } = event;
115
- anchor = { x: clientX, y: clientY };
116
- }
117
- else {
118
- menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_ITEM_CONTEXT_MENU;
119
- const { left, bottom } = event.currentTarget.getBoundingClientRect();
120
- anchor = { x: left, y: bottom };
121
- }
122
- return { menuPath, anchor };
123
- }
124
- getContextMenuArgs(event) {
125
- const args = [this];
126
- // data-position is the stringified position of a given toolbar item, this allows
127
- // the model to be aware of start/stop positions during drag & drop and CRUD operations
128
- const position = event.currentTarget.getAttribute('data-position');
129
- const id = event.currentTarget.getAttribute('data-id');
130
- if (position) {
131
- args.push(JSON.parse(position));
132
- }
133
- else if (id) {
134
- args.push(id);
135
- }
136
- return args;
137
- }
138
- renderGroupsInColumn(groups, alignment) {
139
- const nodes = [];
140
- groups.forEach((group, groupIndex) => {
141
- if (nodes.length && group.length) {
142
- nodes.push(React.createElement("div", { key: `toolbar-separator-${groupIndex}`, className: 'separator' }));
143
- }
144
- group.forEach((item, itemIndex) => {
145
- const position = { alignment, groupIndex, itemIndex };
146
- nodes.push(this.renderItemWithDraggableWrapper(item, position));
147
- });
148
- });
149
- return nodes;
150
- }
151
- doAssignRef(element) {
152
- this.deferredRef.resolve(element);
153
- }
154
- render() {
155
- var _a, _b, _c;
156
- const leftGroups = (_a = this.model.toolbarItems) === null || _a === void 0 ? void 0 : _a.items[toolbar_interfaces_1.ToolbarAlignment.LEFT];
157
- const centerGroups = (_b = this.model.toolbarItems) === null || _b === void 0 ? void 0 : _b.items[toolbar_interfaces_1.ToolbarAlignment.CENTER];
158
- const rightGroups = (_c = this.model.toolbarItems) === null || _c === void 0 ? void 0 : _c.items[toolbar_interfaces_1.ToolbarAlignment.RIGHT];
159
- return (React.createElement("div", { className: 'toolbar-wrapper', onContextMenu: this.handleContextMenu, "data-id": TOOLBAR_BACKGROUND_DATA_ID, role: 'menu', tabIndex: 0, ref: this.assignRef },
160
- leftGroups ? this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.LEFT, leftGroups) : React.createElement(React.Fragment, null),
161
- centerGroups ? this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.CENTER, centerGroups) : React.createElement(React.Fragment, null),
162
- rightGroups ? this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.RIGHT, rightGroups) : React.createElement(React.Fragment, null)));
163
- }
164
- renderColumnWrapper(alignment, columnGroup) {
165
- let children;
166
- if (alignment === toolbar_interfaces_1.ToolbarAlignment.LEFT) {
167
- children = (React.createElement(React.Fragment, null,
168
- this.renderGroupsInColumn(columnGroup, alignment),
169
- this.renderColumnSpace(alignment)));
170
- }
171
- else if (alignment === toolbar_interfaces_1.ToolbarAlignment.CENTER) {
172
- const isCenterColumnEmpty = !columnGroup.length;
173
- if (isCenterColumnEmpty) {
174
- children = this.renderColumnSpace(alignment, 'left');
175
- }
176
- else {
177
- children = (React.createElement(React.Fragment, null,
178
- this.renderColumnSpace(alignment, 'left'),
179
- this.renderGroupsInColumn(columnGroup, alignment),
180
- this.renderColumnSpace(alignment, 'right')));
181
- }
182
- }
183
- else if (alignment === toolbar_interfaces_1.ToolbarAlignment.RIGHT) {
184
- children = (React.createElement(React.Fragment, null,
185
- this.renderColumnSpace(alignment),
186
- this.renderGroupsInColumn(columnGroup, alignment)));
187
- }
188
- return (React.createElement("div", { role: 'group', className: `toolbar-column ${alignment}` }, children));
189
- }
190
- renderColumnSpace(alignment, position) {
191
- return (React.createElement("div", { className: 'empty-column-space', "data-column": `${alignment}`, "data-center-position": position, onDrop: this.handleOnDrop, onDragOver: this.handleOnDragEnter, onDragEnter: this.handleOnDragEnter, onDragLeave: this.handleOnDragLeave, key: `column-space-${alignment}-${position}` }));
192
- }
193
- renderItemWithDraggableWrapper(item, position) {
194
- const stringifiedPosition = JSON.stringify(position);
195
- let toolbarItemClassNames = '';
196
- let renderBody;
197
- if (tab_bar_toolbar_1.TabBarToolbarItem.is(item)) {
198
- toolbarItemClassNames = tab_bar_toolbar_1.TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM;
199
- if (this.evaluateWhenClause(item.when)) {
200
- toolbarItemClassNames += ' enabled';
201
- }
202
- renderBody = this.renderItem(item);
203
- }
204
- else {
205
- const contribution = this.model.getContributionByID(item.id);
206
- if (contribution) {
207
- renderBody = contribution.render();
208
- }
209
- }
210
- return (React.createElement("div", { role: 'button', tabIndex: 0, "data-id": item.id, id: item.id, "data-position": stringifiedPosition, key: `${item.id}-${stringifiedPosition}`, className: `${toolbarItemClassNames} toolbar-item action-label`, onMouseDown: this.onMouseDownEvent, onMouseUp: this.onMouseUpEvent, onMouseOut: this.onMouseUpEvent, draggable: true, onDragStart: this.handleOnDragStart, onClick: this.executeCommand, onDragOver: this.handleOnDragEnter, onDragLeave: this.handleOnDragLeave, onContextMenu: this.handleContextMenu, onDragEnd: this.handleOnDragEnd, onDrop: this.handleOnDrop },
211
- renderBody,
212
- React.createElement("div", { className: 'hover-overlay' })));
213
- }
214
- renderItem(item) {
215
- const classNames = [];
216
- if (item.text) {
217
- for (const labelPart of this.labelParser.parse(item.text)) {
218
- if (typeof labelPart !== 'string' && label_parser_1.LabelIcon.is(labelPart)) {
219
- const className = `fa fa-${labelPart.name}${labelPart.animation ? ' fa-' + labelPart.animation : ''}`;
220
- classNames.push(...className.split(' '));
221
- }
222
- }
223
- }
224
- const command = this.commands.getCommand(item.command);
225
- const iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon || (command === null || command === void 0 ? void 0 : command.iconClass);
226
- if (iconClass) {
227
- classNames.push(iconClass);
228
- }
229
- let itemTooltip = '';
230
- if (item.tooltip) {
231
- itemTooltip = item.tooltip;
232
- }
233
- else if (command === null || command === void 0 ? void 0 : command.label) {
234
- itemTooltip = command.label;
235
- }
236
- const keybindingString = this.resolveKeybindingForCommand(command === null || command === void 0 ? void 0 : command.id);
237
- itemTooltip = `${itemTooltip}${keybindingString}`;
238
- return (React.createElement("div", { id: item.id, className: classNames.join(' '), title: itemTooltip }));
239
- }
240
- doHandleOnDragStart(e) {
241
- var _a;
242
- const draggedElement = e.currentTarget;
243
- draggedElement.classList.add('dragging');
244
- e.dataTransfer.setDragImage(draggedElement, 0, 0);
245
- const position = JSON.parse((_a = e.currentTarget.getAttribute('data-position')) !== null && _a !== void 0 ? _a : '');
246
- this.currentlyDraggedItem = e.currentTarget;
247
- this.draggedStartingPosition = position;
248
- }
249
- doHandleItemOnDragEnter(e) {
250
- var _a;
251
- e.preventDefault();
252
- e.stopPropagation();
253
- const targetItemDOMElement = e.currentTarget;
254
- const targetItemHoverOverlay = targetItemDOMElement.querySelector('.hover-overlay');
255
- const targetItemId = e.currentTarget.getAttribute('data-id');
256
- if (targetItemDOMElement.classList.contains('empty-column-space')) {
257
- targetItemDOMElement.classList.add('drag-over');
258
- }
259
- else if (targetItemDOMElement.classList.contains('toolbar-item') && targetItemHoverOverlay) {
260
- const { clientX } = e;
261
- const { left, right } = e.currentTarget.getBoundingClientRect();
262
- const targetMiddleX = (left + right) / 2;
263
- if (targetItemId !== ((_a = this.currentlyDraggedItem) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id'))) {
264
- targetItemHoverOverlay.classList.add('drag-over');
265
- if (clientX <= targetMiddleX) {
266
- targetItemHoverOverlay.classList.add('location-left');
267
- targetItemHoverOverlay.classList.remove('location-right');
268
- }
269
- else {
270
- targetItemHoverOverlay.classList.add('location-right');
271
- targetItemHoverOverlay.classList.remove('location-left');
272
- }
273
- }
274
- }
275
- }
276
- doHandleOnDragLeave(e) {
277
- e.preventDefault();
278
- e.stopPropagation();
279
- const targetItemDOMElement = e.currentTarget;
280
- const targetItemHoverOverlay = targetItemDOMElement.querySelector('.hover-overlay');
281
- if (targetItemDOMElement.classList.contains('empty-column-space')) {
282
- targetItemDOMElement.classList.remove('drag-over');
283
- }
284
- else if (targetItemHoverOverlay && targetItemDOMElement.classList.contains('toolbar-item')) {
285
- targetItemHoverOverlay === null || targetItemHoverOverlay === void 0 ? void 0 : targetItemHoverOverlay.classList.remove('drag-over', 'location-left', 'location-right');
286
- }
287
- }
288
- doHandleOnDrop(e) {
289
- e.preventDefault();
290
- e.stopPropagation();
291
- const targetItemDOMElement = e.currentTarget;
292
- const targetItemHoverOverlay = targetItemDOMElement.querySelector('.hover-overlay');
293
- if (targetItemDOMElement.classList.contains('empty-column-space')) {
294
- this.handleDropInEmptySpace(targetItemDOMElement);
295
- targetItemDOMElement.classList.remove('drag-over');
296
- }
297
- else if (targetItemHoverOverlay && targetItemDOMElement.classList.contains('toolbar-item')) {
298
- this.handleDropInExistingGroup(targetItemDOMElement);
299
- targetItemHoverOverlay.classList.remove('drag-over', 'location-left', 'location-right');
300
- }
301
- this.currentlyDraggedItem = undefined;
302
- this.draggedStartingPosition = undefined;
303
- }
304
- handleDropInExistingGroup(element) {
305
- var _a;
306
- const position = element.getAttribute('data-position');
307
- const targetDirection = (_a = element.querySelector('.hover-overlay')) === null || _a === void 0 ? void 0 : _a.classList.toString().split(' ').find(className => className.includes('location'));
308
- const dropPosition = JSON.parse(position !== null && position !== void 0 ? position : '');
309
- if (this.currentlyDraggedItem && targetDirection
310
- && this.draggedStartingPosition && !this.arePositionsEquivalent(this.draggedStartingPosition, dropPosition)) {
311
- this.model.swapValues(this.draggedStartingPosition, dropPosition, targetDirection);
312
- }
313
- }
314
- handleDropInEmptySpace(element) {
315
- const column = element.getAttribute('data-column');
316
- if (toolbar_interfaces_1.ToolbarAlignmentString.is(column) && this.draggedStartingPosition) {
317
- if (column === toolbar_interfaces_1.ToolbarAlignment.CENTER) {
318
- const centerPosition = element.getAttribute('data-center-position');
319
- this.model.moveItemToEmptySpace(this.draggedStartingPosition, column, centerPosition);
320
- }
321
- else {
322
- this.model.moveItemToEmptySpace(this.draggedStartingPosition, column);
323
- }
324
- }
325
- }
326
- arePositionsEquivalent(start, end) {
327
- return start.alignment === end.alignment
328
- && start.groupIndex === end.groupIndex
329
- && start.itemIndex === end.itemIndex;
330
- }
331
- doHandleOnDragEnd(e) {
332
- e.preventDefault();
333
- e.stopPropagation();
334
- this.currentlyDraggedItem = undefined;
335
- this.draggedStartingPosition = undefined;
336
- e.currentTarget.classList.remove('dragging');
337
- }
338
- };
339
- __decorate([
340
- (0, inversify_1.inject)(tab_bar_toolbar_1.TabBarToolbarFactory),
341
- __metadata("design:type", Function)
342
- ], ToolbarImpl.prototype, "tabbarToolbarFactory", void 0);
343
- __decorate([
344
- (0, inversify_1.inject)(browser_1.WidgetManager),
345
- __metadata("design:type", browser_1.WidgetManager)
346
- ], ToolbarImpl.prototype, "widgetManager", void 0);
347
- __decorate([
348
- (0, inversify_1.inject)(frontend_application_state_1.FrontendApplicationStateService),
349
- __metadata("design:type", frontend_application_state_1.FrontendApplicationStateService)
350
- ], ToolbarImpl.prototype, "appState", void 0);
351
- __decorate([
352
- (0, inversify_1.inject)(toolbar_controller_1.ToolbarController),
353
- __metadata("design:type", toolbar_controller_1.ToolbarController)
354
- ], ToolbarImpl.prototype, "model", void 0);
355
- __decorate([
356
- (0, inversify_1.inject)(browser_1.PreferenceService),
357
- __metadata("design:type", Object)
358
- ], ToolbarImpl.prototype, "preferenceService", void 0);
359
- __decorate([
360
- (0, inversify_1.inject)(browser_1.KeybindingRegistry),
361
- __metadata("design:type", browser_1.KeybindingRegistry)
362
- ], ToolbarImpl.prototype, "keybindingRegistry", void 0);
363
- __decorate([
364
- (0, inversify_1.inject)(progress_bar_factory_1.ProgressBarFactory),
365
- __metadata("design:type", Function)
366
- ], ToolbarImpl.prototype, "progressFactory", void 0);
367
- __decorate([
368
- (0, inversify_1.inject)(core_1.ProgressService),
369
- __metadata("design:type", core_1.ProgressService)
370
- ], ToolbarImpl.prototype, "progressService", void 0);
371
- __decorate([
372
- (0, inversify_1.postConstruct)(),
373
- __metadata("design:type", Function),
374
- __metadata("design:paramtypes", []),
375
- __metadata("design:returntype", void 0)
376
- ], ToolbarImpl.prototype, "init", null);
377
- ToolbarImpl = __decorate([
378
- (0, inversify_1.injectable)()
379
- ], ToolbarImpl);
380
- exports.ToolbarImpl = ToolbarImpl;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2022 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ 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;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.ToolbarImpl = exports.TOOLBAR_PROGRESSBAR_ID = void 0;
28
+ const React = require("@theia/core/shared/react");
29
+ const browser_1 = require("@theia/core/lib/browser");
30
+ const label_parser_1 = require("@theia/core/lib/browser/label-parser");
31
+ const tab_bar_toolbar_1 = require("@theia/core/lib/browser/shell/tab-bar-toolbar");
32
+ const inversify_1 = require("@theia/core/shared/inversify");
33
+ const core_1 = require("@theia/core");
34
+ const frontend_application_state_1 = require("@theia/core/lib/browser/frontend-application-state");
35
+ const progress_bar_factory_1 = require("@theia/core/lib/browser/progress-bar-factory");
36
+ const promise_util_1 = require("@theia/core/lib/common/promise-util");
37
+ const toolbar_interfaces_1 = require("./toolbar-interfaces");
38
+ const toolbar_controller_1 = require("./toolbar-controller");
39
+ const toolbar_constants_1 = require("./toolbar-constants");
40
+ const TOOLBAR_BACKGROUND_DATA_ID = 'toolbar-wrapper';
41
+ exports.TOOLBAR_PROGRESSBAR_ID = 'main-toolbar-progress';
42
+ let ToolbarImpl = class ToolbarImpl extends tab_bar_toolbar_1.TabBarToolbar {
43
+ constructor() {
44
+ super(...arguments);
45
+ this.deferredRef = new promise_util_1.Deferred();
46
+ this.isBusyDeferred = new promise_util_1.Deferred();
47
+ this.handleContextMenu = (e) => this.doHandleContextMenu(e);
48
+ this.assignRef = (element) => this.doAssignRef(element);
49
+ this.handleOnDragStart = (e) => this.doHandleOnDragStart(e);
50
+ this.handleOnDragEnter = (e) => this.doHandleItemOnDragEnter(e);
51
+ this.handleOnDragLeave = (e) => this.doHandleOnDragLeave(e);
52
+ this.handleOnDrop = (e) => this.doHandleOnDrop(e);
53
+ this.handleOnDragEnd = (e) => this.doHandleOnDragEnd(e);
54
+ }
55
+ init() {
56
+ super.init();
57
+ this.doInit();
58
+ }
59
+ async doInit() {
60
+ this.hide();
61
+ await this.model.ready.promise;
62
+ this.updateInlineItems();
63
+ this.update();
64
+ this.model.onToolbarModelDidUpdate(() => {
65
+ this.updateInlineItems();
66
+ this.update();
67
+ });
68
+ this.model.onToolbarDidChangeBusyState(isBusy => {
69
+ if (isBusy) {
70
+ this.isBusyDeferred = new promise_util_1.Deferred();
71
+ this.progressService.withProgress('', exports.TOOLBAR_PROGRESSBAR_ID, async () => this.isBusyDeferred.promise);
72
+ }
73
+ else {
74
+ this.isBusyDeferred.resolve();
75
+ }
76
+ });
77
+ await this.deferredRef.promise;
78
+ this.progressFactory({ container: this.node, insertMode: 'append', locationId: exports.TOOLBAR_PROGRESSBAR_ID });
79
+ }
80
+ updateInlineItems() {
81
+ var _a;
82
+ this.inline.clear();
83
+ const { items } = this.model.toolbarItems;
84
+ const contextKeys = new Set();
85
+ for (const column of Object.keys(items)) {
86
+ for (const group of items[column]) {
87
+ for (const item of group) {
88
+ this.inline.set(item.id, item);
89
+ if (item.when) {
90
+ (_a = this.contextKeyService.parseKeys(item.when)) === null || _a === void 0 ? void 0 : _a.forEach(key => contextKeys.add(key));
91
+ }
92
+ }
93
+ }
94
+ }
95
+ this.updateContextKeyListener(contextKeys);
96
+ }
97
+ doHandleContextMenu(event) {
98
+ event.preventDefault();
99
+ event.stopPropagation();
100
+ const contextMenuArgs = this.getContextMenuArgs(event);
101
+ const { menuPath, anchor } = this.getMenuDetailsForClick(event);
102
+ return this.contextMenuRenderer.render({
103
+ args: contextMenuArgs,
104
+ menuPath,
105
+ anchor,
106
+ });
107
+ }
108
+ getMenuDetailsForClick(event) {
109
+ const clickId = event.currentTarget.getAttribute('data-id');
110
+ let menuPath;
111
+ let anchor;
112
+ if (clickId === TOOLBAR_BACKGROUND_DATA_ID) {
113
+ menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_BACKGROUND_CONTEXT_MENU;
114
+ const { clientX, clientY } = event;
115
+ anchor = { x: clientX, y: clientY };
116
+ }
117
+ else {
118
+ menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_ITEM_CONTEXT_MENU;
119
+ const { left, bottom } = event.currentTarget.getBoundingClientRect();
120
+ anchor = { x: left, y: bottom };
121
+ }
122
+ return { menuPath, anchor };
123
+ }
124
+ getContextMenuArgs(event) {
125
+ const args = [this];
126
+ // data-position is the stringified position of a given toolbar item, this allows
127
+ // the model to be aware of start/stop positions during drag & drop and CRUD operations
128
+ const position = event.currentTarget.getAttribute('data-position');
129
+ const id = event.currentTarget.getAttribute('data-id');
130
+ if (position) {
131
+ args.push(JSON.parse(position));
132
+ }
133
+ else if (id) {
134
+ args.push(id);
135
+ }
136
+ return args;
137
+ }
138
+ renderGroupsInColumn(groups, alignment) {
139
+ const nodes = [];
140
+ groups.forEach((group, groupIndex) => {
141
+ if (nodes.length && group.length) {
142
+ nodes.push(React.createElement("div", { key: `toolbar-separator-${groupIndex}`, className: 'separator' }));
143
+ }
144
+ group.forEach((item, itemIndex) => {
145
+ const position = { alignment, groupIndex, itemIndex };
146
+ nodes.push(this.renderItemWithDraggableWrapper(item, position));
147
+ });
148
+ });
149
+ return nodes;
150
+ }
151
+ doAssignRef(element) {
152
+ this.deferredRef.resolve(element);
153
+ }
154
+ render() {
155
+ var _a, _b, _c;
156
+ const leftGroups = (_a = this.model.toolbarItems) === null || _a === void 0 ? void 0 : _a.items[toolbar_interfaces_1.ToolbarAlignment.LEFT];
157
+ const centerGroups = (_b = this.model.toolbarItems) === null || _b === void 0 ? void 0 : _b.items[toolbar_interfaces_1.ToolbarAlignment.CENTER];
158
+ const rightGroups = (_c = this.model.toolbarItems) === null || _c === void 0 ? void 0 : _c.items[toolbar_interfaces_1.ToolbarAlignment.RIGHT];
159
+ return (React.createElement("div", { className: 'toolbar-wrapper', onContextMenu: this.handleContextMenu, "data-id": TOOLBAR_BACKGROUND_DATA_ID, role: 'menu', tabIndex: 0, ref: this.assignRef },
160
+ leftGroups ? this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.LEFT, leftGroups) : React.createElement(React.Fragment, null),
161
+ centerGroups ? this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.CENTER, centerGroups) : React.createElement(React.Fragment, null),
162
+ rightGroups ? this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.RIGHT, rightGroups) : React.createElement(React.Fragment, null)));
163
+ }
164
+ renderColumnWrapper(alignment, columnGroup) {
165
+ let children;
166
+ if (alignment === toolbar_interfaces_1.ToolbarAlignment.LEFT) {
167
+ children = (React.createElement(React.Fragment, null,
168
+ this.renderGroupsInColumn(columnGroup, alignment),
169
+ this.renderColumnSpace(alignment)));
170
+ }
171
+ else if (alignment === toolbar_interfaces_1.ToolbarAlignment.CENTER) {
172
+ const isCenterColumnEmpty = !columnGroup.length;
173
+ if (isCenterColumnEmpty) {
174
+ children = this.renderColumnSpace(alignment, 'left');
175
+ }
176
+ else {
177
+ children = (React.createElement(React.Fragment, null,
178
+ this.renderColumnSpace(alignment, 'left'),
179
+ this.renderGroupsInColumn(columnGroup, alignment),
180
+ this.renderColumnSpace(alignment, 'right')));
181
+ }
182
+ }
183
+ else if (alignment === toolbar_interfaces_1.ToolbarAlignment.RIGHT) {
184
+ children = (React.createElement(React.Fragment, null,
185
+ this.renderColumnSpace(alignment),
186
+ this.renderGroupsInColumn(columnGroup, alignment)));
187
+ }
188
+ return (React.createElement("div", { role: 'group', className: `toolbar-column ${alignment}` }, children));
189
+ }
190
+ renderColumnSpace(alignment, position) {
191
+ return (React.createElement("div", { className: 'empty-column-space', "data-column": `${alignment}`, "data-center-position": position, onDrop: this.handleOnDrop, onDragOver: this.handleOnDragEnter, onDragEnter: this.handleOnDragEnter, onDragLeave: this.handleOnDragLeave, key: `column-space-${alignment}-${position}` }));
192
+ }
193
+ renderItemWithDraggableWrapper(item, position) {
194
+ const stringifiedPosition = JSON.stringify(position);
195
+ let toolbarItemClassNames = '';
196
+ let renderBody;
197
+ if (tab_bar_toolbar_1.TabBarToolbarItem.is(item)) {
198
+ toolbarItemClassNames = tab_bar_toolbar_1.TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM;
199
+ if (this.evaluateWhenClause(item.when)) {
200
+ toolbarItemClassNames += ' enabled';
201
+ }
202
+ renderBody = this.renderItem(item);
203
+ }
204
+ else {
205
+ const contribution = this.model.getContributionByID(item.id);
206
+ if (contribution) {
207
+ renderBody = contribution.render();
208
+ }
209
+ }
210
+ return (React.createElement("div", { role: 'button', tabIndex: 0, "data-id": item.id, id: item.id, "data-position": stringifiedPosition, key: `${item.id}-${stringifiedPosition}`, className: `${toolbarItemClassNames} toolbar-item action-label`, onMouseDown: this.onMouseDownEvent, onMouseUp: this.onMouseUpEvent, onMouseOut: this.onMouseUpEvent, draggable: true, onDragStart: this.handleOnDragStart, onClick: this.executeCommand, onDragOver: this.handleOnDragEnter, onDragLeave: this.handleOnDragLeave, onContextMenu: this.handleContextMenu, onDragEnd: this.handleOnDragEnd, onDrop: this.handleOnDrop },
211
+ renderBody,
212
+ React.createElement("div", { className: 'hover-overlay' })));
213
+ }
214
+ renderItem(item) {
215
+ const classNames = [];
216
+ if (item.text) {
217
+ for (const labelPart of this.labelParser.parse(item.text)) {
218
+ if (typeof labelPart !== 'string' && label_parser_1.LabelIcon.is(labelPart)) {
219
+ const className = `fa fa-${labelPart.name}${labelPart.animation ? ' fa-' + labelPart.animation : ''}`;
220
+ classNames.push(...className.split(' '));
221
+ }
222
+ }
223
+ }
224
+ const command = this.commands.getCommand(item.command);
225
+ const iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon || (command === null || command === void 0 ? void 0 : command.iconClass);
226
+ if (iconClass) {
227
+ classNames.push(iconClass);
228
+ }
229
+ let itemTooltip = '';
230
+ if (item.tooltip) {
231
+ itemTooltip = item.tooltip;
232
+ }
233
+ else if (command === null || command === void 0 ? void 0 : command.label) {
234
+ itemTooltip = command.label;
235
+ }
236
+ const keybindingString = this.resolveKeybindingForCommand(command === null || command === void 0 ? void 0 : command.id);
237
+ itemTooltip = `${itemTooltip}${keybindingString}`;
238
+ return (React.createElement("div", { id: item.id, className: classNames.join(' '), title: itemTooltip }));
239
+ }
240
+ doHandleOnDragStart(e) {
241
+ var _a;
242
+ const draggedElement = e.currentTarget;
243
+ draggedElement.classList.add('dragging');
244
+ e.dataTransfer.setDragImage(draggedElement, 0, 0);
245
+ const position = JSON.parse((_a = e.currentTarget.getAttribute('data-position')) !== null && _a !== void 0 ? _a : '');
246
+ this.currentlyDraggedItem = e.currentTarget;
247
+ this.draggedStartingPosition = position;
248
+ }
249
+ doHandleItemOnDragEnter(e) {
250
+ var _a;
251
+ e.preventDefault();
252
+ e.stopPropagation();
253
+ const targetItemDOMElement = e.currentTarget;
254
+ const targetItemHoverOverlay = targetItemDOMElement.querySelector('.hover-overlay');
255
+ const targetItemId = e.currentTarget.getAttribute('data-id');
256
+ if (targetItemDOMElement.classList.contains('empty-column-space')) {
257
+ targetItemDOMElement.classList.add('drag-over');
258
+ }
259
+ else if (targetItemDOMElement.classList.contains('toolbar-item') && targetItemHoverOverlay) {
260
+ const { clientX } = e;
261
+ const { left, right } = e.currentTarget.getBoundingClientRect();
262
+ const targetMiddleX = (left + right) / 2;
263
+ if (targetItemId !== ((_a = this.currentlyDraggedItem) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id'))) {
264
+ targetItemHoverOverlay.classList.add('drag-over');
265
+ if (clientX <= targetMiddleX) {
266
+ targetItemHoverOverlay.classList.add('location-left');
267
+ targetItemHoverOverlay.classList.remove('location-right');
268
+ }
269
+ else {
270
+ targetItemHoverOverlay.classList.add('location-right');
271
+ targetItemHoverOverlay.classList.remove('location-left');
272
+ }
273
+ }
274
+ }
275
+ }
276
+ doHandleOnDragLeave(e) {
277
+ e.preventDefault();
278
+ e.stopPropagation();
279
+ const targetItemDOMElement = e.currentTarget;
280
+ const targetItemHoverOverlay = targetItemDOMElement.querySelector('.hover-overlay');
281
+ if (targetItemDOMElement.classList.contains('empty-column-space')) {
282
+ targetItemDOMElement.classList.remove('drag-over');
283
+ }
284
+ else if (targetItemHoverOverlay && targetItemDOMElement.classList.contains('toolbar-item')) {
285
+ targetItemHoverOverlay === null || targetItemHoverOverlay === void 0 ? void 0 : targetItemHoverOverlay.classList.remove('drag-over', 'location-left', 'location-right');
286
+ }
287
+ }
288
+ doHandleOnDrop(e) {
289
+ e.preventDefault();
290
+ e.stopPropagation();
291
+ const targetItemDOMElement = e.currentTarget;
292
+ const targetItemHoverOverlay = targetItemDOMElement.querySelector('.hover-overlay');
293
+ if (targetItemDOMElement.classList.contains('empty-column-space')) {
294
+ this.handleDropInEmptySpace(targetItemDOMElement);
295
+ targetItemDOMElement.classList.remove('drag-over');
296
+ }
297
+ else if (targetItemHoverOverlay && targetItemDOMElement.classList.contains('toolbar-item')) {
298
+ this.handleDropInExistingGroup(targetItemDOMElement);
299
+ targetItemHoverOverlay.classList.remove('drag-over', 'location-left', 'location-right');
300
+ }
301
+ this.currentlyDraggedItem = undefined;
302
+ this.draggedStartingPosition = undefined;
303
+ }
304
+ handleDropInExistingGroup(element) {
305
+ var _a;
306
+ const position = element.getAttribute('data-position');
307
+ const targetDirection = (_a = element.querySelector('.hover-overlay')) === null || _a === void 0 ? void 0 : _a.classList.toString().split(' ').find(className => className.includes('location'));
308
+ const dropPosition = JSON.parse(position !== null && position !== void 0 ? position : '');
309
+ if (this.currentlyDraggedItem && targetDirection
310
+ && this.draggedStartingPosition && !this.arePositionsEquivalent(this.draggedStartingPosition, dropPosition)) {
311
+ this.model.swapValues(this.draggedStartingPosition, dropPosition, targetDirection);
312
+ }
313
+ }
314
+ handleDropInEmptySpace(element) {
315
+ const column = element.getAttribute('data-column');
316
+ if (toolbar_interfaces_1.ToolbarAlignmentString.is(column) && this.draggedStartingPosition) {
317
+ if (column === toolbar_interfaces_1.ToolbarAlignment.CENTER) {
318
+ const centerPosition = element.getAttribute('data-center-position');
319
+ this.model.moveItemToEmptySpace(this.draggedStartingPosition, column, centerPosition);
320
+ }
321
+ else {
322
+ this.model.moveItemToEmptySpace(this.draggedStartingPosition, column);
323
+ }
324
+ }
325
+ }
326
+ arePositionsEquivalent(start, end) {
327
+ return start.alignment === end.alignment
328
+ && start.groupIndex === end.groupIndex
329
+ && start.itemIndex === end.itemIndex;
330
+ }
331
+ doHandleOnDragEnd(e) {
332
+ e.preventDefault();
333
+ e.stopPropagation();
334
+ this.currentlyDraggedItem = undefined;
335
+ this.draggedStartingPosition = undefined;
336
+ e.currentTarget.classList.remove('dragging');
337
+ }
338
+ };
339
+ __decorate([
340
+ (0, inversify_1.inject)(tab_bar_toolbar_1.TabBarToolbarFactory),
341
+ __metadata("design:type", Function)
342
+ ], ToolbarImpl.prototype, "tabbarToolbarFactory", void 0);
343
+ __decorate([
344
+ (0, inversify_1.inject)(browser_1.WidgetManager),
345
+ __metadata("design:type", browser_1.WidgetManager)
346
+ ], ToolbarImpl.prototype, "widgetManager", void 0);
347
+ __decorate([
348
+ (0, inversify_1.inject)(frontend_application_state_1.FrontendApplicationStateService),
349
+ __metadata("design:type", frontend_application_state_1.FrontendApplicationStateService)
350
+ ], ToolbarImpl.prototype, "appState", void 0);
351
+ __decorate([
352
+ (0, inversify_1.inject)(toolbar_controller_1.ToolbarController),
353
+ __metadata("design:type", toolbar_controller_1.ToolbarController)
354
+ ], ToolbarImpl.prototype, "model", void 0);
355
+ __decorate([
356
+ (0, inversify_1.inject)(browser_1.PreferenceService),
357
+ __metadata("design:type", Object)
358
+ ], ToolbarImpl.prototype, "preferenceService", void 0);
359
+ __decorate([
360
+ (0, inversify_1.inject)(browser_1.KeybindingRegistry),
361
+ __metadata("design:type", browser_1.KeybindingRegistry)
362
+ ], ToolbarImpl.prototype, "keybindingRegistry", void 0);
363
+ __decorate([
364
+ (0, inversify_1.inject)(progress_bar_factory_1.ProgressBarFactory),
365
+ __metadata("design:type", Function)
366
+ ], ToolbarImpl.prototype, "progressFactory", void 0);
367
+ __decorate([
368
+ (0, inversify_1.inject)(core_1.ProgressService),
369
+ __metadata("design:type", core_1.ProgressService)
370
+ ], ToolbarImpl.prototype, "progressService", void 0);
371
+ __decorate([
372
+ (0, inversify_1.postConstruct)(),
373
+ __metadata("design:type", Function),
374
+ __metadata("design:paramtypes", []),
375
+ __metadata("design:returntype", void 0)
376
+ ], ToolbarImpl.prototype, "init", null);
377
+ ToolbarImpl = __decorate([
378
+ (0, inversify_1.injectable)()
379
+ ], ToolbarImpl);
380
+ exports.ToolbarImpl = ToolbarImpl;
381
381
  //# sourceMappingURL=toolbar.js.map