@theia/toolbar 1.34.3 → 1.34.4

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 (54) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +32 -32
  3. package/lib/browser/abstract-toolbar-contribution.d.ts +16 -16
  4. package/lib/browser/abstract-toolbar-contribution.js +68 -68
  5. package/lib/browser/application-shell-with-toolbar-override.d.ts +14 -14
  6. package/lib/browser/application-shell-with-toolbar-override.js +98 -98
  7. package/lib/browser/codicons.d.ts +1 -1
  8. package/lib/browser/codicons.js +20 -20
  9. package/lib/browser/font-awesome-icons.d.ts +1 -1
  10. package/lib/browser/font-awesome-icons.js +20 -20
  11. package/lib/browser/package.spec.js +18 -18
  12. package/lib/browser/toolbar-command-contribution.d.ts +25 -25
  13. package/lib/browser/toolbar-command-contribution.js +211 -211
  14. package/lib/browser/toolbar-command-quick-input-service.d.ts +19 -19
  15. package/lib/browser/toolbar-command-quick-input-service.js +108 -108
  16. package/lib/browser/toolbar-constants.d.ts +23 -23
  17. package/lib/browser/toolbar-constants.js +75 -75
  18. package/lib/browser/toolbar-controller.d.ts +33 -33
  19. package/lib/browser/toolbar-controller.js +184 -184
  20. package/lib/browser/toolbar-defaults.d.ts +3 -3
  21. package/lib/browser/toolbar-defaults.js +60 -60
  22. package/lib/browser/toolbar-frontend-module.d.ts +4 -4
  23. package/lib/browser/toolbar-frontend-module.js +25 -25
  24. package/lib/browser/toolbar-icon-selector-dialog.d.ts +65 -65
  25. package/lib/browser/toolbar-icon-selector-dialog.js +235 -235
  26. package/lib/browser/toolbar-interfaces.d.ts +45 -45
  27. package/lib/browser/toolbar-interfaces.js +42 -42
  28. package/lib/browser/toolbar-preference-contribution.d.ts +9 -9
  29. package/lib/browser/toolbar-preference-contribution.js +34 -34
  30. package/lib/browser/toolbar-preference-schema.d.ts +5 -5
  31. package/lib/browser/toolbar-preference-schema.js +72 -72
  32. package/lib/browser/toolbar-storage-provider.d.ts +46 -46
  33. package/lib/browser/toolbar-storage-provider.js +354 -354
  34. package/lib/browser/toolbar.d.ts +56 -56
  35. package/lib/browser/toolbar.js +380 -380
  36. package/package.json +10 -10
  37. package/src/browser/abstract-toolbar-contribution.tsx +53 -53
  38. package/src/browser/application-shell-with-toolbar-override.ts +94 -94
  39. package/src/browser/codicons.ts +18 -18
  40. package/src/browser/font-awesome-icons.ts +18 -18
  41. package/src/browser/package.spec.ts +19 -19
  42. package/src/browser/style/toolbar.css +253 -253
  43. package/src/browser/toolbar-command-contribution.ts +211 -211
  44. package/src/browser/toolbar-command-quick-input-service.ts +86 -86
  45. package/src/browser/toolbar-constants.ts +79 -79
  46. package/src/browser/toolbar-controller.ts +182 -182
  47. package/src/browser/toolbar-defaults.ts +58 -58
  48. package/src/browser/toolbar-frontend-module.ts +30 -30
  49. package/src/browser/toolbar-icon-selector-dialog.tsx +296 -296
  50. package/src/browser/toolbar-interfaces.ts +76 -76
  51. package/src/browser/toolbar-preference-contribution.ts +38 -38
  52. package/src/browser/toolbar-preference-schema.ts +74 -74
  53. package/src/browser/toolbar-storage-provider.ts +348 -348
  54. package/src/browser/toolbar.tsx +421 -421
@@ -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 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
- async init() {
56
- this.hide();
57
- await this.model.ready.promise;
58
- this.updateInlineItems();
59
- this.update();
60
- this.model.onToolbarModelDidUpdate(() => {
61
- this.updateInlineItems();
62
- this.update();
63
- });
64
- this.model.onToolbarDidChangeBusyState(isBusy => {
65
- if (isBusy) {
66
- this.isBusyDeferred = new promise_util_1.Deferred();
67
- this.progressService.withProgress('', exports.TOOLBAR_PROGRESSBAR_ID, async () => this.isBusyDeferred.promise);
68
- }
69
- else {
70
- this.isBusyDeferred.resolve();
71
- }
72
- });
73
- await this.deferredRef.promise;
74
- this.progressFactory({ container: this.node, insertMode: 'append', locationId: exports.TOOLBAR_PROGRESSBAR_ID });
75
- }
76
- updateInlineItems() {
77
- this.inline.clear();
78
- const { items } = this.model.toolbarItems;
79
- for (const column of Object.keys(items)) {
80
- for (const group of items[column]) {
81
- for (const item of group) {
82
- this.inline.set(item.id, item);
83
- }
84
- }
85
- }
86
- }
87
- doHandleContextMenu(event) {
88
- event.preventDefault();
89
- event.stopPropagation();
90
- const contextMenuArgs = this.getContextMenuArgs(event);
91
- const { menuPath, anchor } = this.getMenuDetailsForClick(event);
92
- return this.contextMenuRenderer.render({
93
- args: contextMenuArgs,
94
- menuPath,
95
- anchor,
96
- });
97
- }
98
- getMenuDetailsForClick(event) {
99
- const clickId = event.currentTarget.getAttribute('data-id');
100
- let menuPath;
101
- let anchor;
102
- if (clickId === TOOLBAR_BACKGROUND_DATA_ID) {
103
- menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_BACKGROUND_CONTEXT_MENU;
104
- const { clientX, clientY } = event;
105
- anchor = { x: clientX, y: clientY };
106
- }
107
- else {
108
- menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_ITEM_CONTEXT_MENU;
109
- const { left, bottom } = event.currentTarget.getBoundingClientRect();
110
- anchor = { x: left, y: bottom };
111
- }
112
- return { menuPath, anchor };
113
- }
114
- getContextMenuArgs(event) {
115
- const args = [this];
116
- // data-position is the stringified position of a given toolbar item, this allows
117
- // the model to be aware of start/stop positions during drag & drop and CRUD operations
118
- const position = event.currentTarget.getAttribute('data-position');
119
- const id = event.currentTarget.getAttribute('data-id');
120
- if (position) {
121
- args.push(JSON.parse(position));
122
- }
123
- else if (id) {
124
- args.push(id);
125
- }
126
- return args;
127
- }
128
- renderGroupsInColumn(groups, alignment) {
129
- const nodes = [];
130
- groups.forEach((group, groupIndex) => {
131
- if (nodes.length && group.length) {
132
- nodes.push(React.createElement("div", { key: `toolbar-separator-${groupIndex}`, className: 'separator' }));
133
- }
134
- group.forEach((item, itemIndex) => {
135
- const position = { alignment, groupIndex, itemIndex };
136
- nodes.push(this.renderItemWithDraggableWrapper(item, position));
137
- });
138
- });
139
- return nodes;
140
- }
141
- doAssignRef(element) {
142
- this.deferredRef.resolve(element);
143
- }
144
- render() {
145
- var _a, _b, _c;
146
- const leftGroups = (_a = this.model.toolbarItems) === null || _a === void 0 ? void 0 : _a.items[toolbar_interfaces_1.ToolbarAlignment.LEFT];
147
- const centerGroups = (_b = this.model.toolbarItems) === null || _b === void 0 ? void 0 : _b.items[toolbar_interfaces_1.ToolbarAlignment.CENTER];
148
- const rightGroups = (_c = this.model.toolbarItems) === null || _c === void 0 ? void 0 : _c.items[toolbar_interfaces_1.ToolbarAlignment.RIGHT];
149
- return (React.createElement("div", { className: 'toolbar-wrapper', onContextMenu: this.handleContextMenu, "data-id": TOOLBAR_BACKGROUND_DATA_ID, role: 'menu', tabIndex: 0, ref: this.assignRef },
150
- this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.LEFT, leftGroups),
151
- this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.CENTER, centerGroups),
152
- this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.RIGHT, rightGroups)));
153
- }
154
- renderColumnWrapper(alignment, columnGroup) {
155
- let children;
156
- if (alignment === toolbar_interfaces_1.ToolbarAlignment.LEFT) {
157
- children = (React.createElement(React.Fragment, null,
158
- this.renderGroupsInColumn(columnGroup, alignment),
159
- this.renderColumnSpace(alignment)));
160
- }
161
- else if (alignment === toolbar_interfaces_1.ToolbarAlignment.CENTER) {
162
- const isCenterColumnEmpty = !columnGroup.length;
163
- if (isCenterColumnEmpty) {
164
- children = this.renderColumnSpace(alignment, 'left');
165
- }
166
- else {
167
- children = (React.createElement(React.Fragment, null,
168
- this.renderColumnSpace(alignment, 'left'),
169
- this.renderGroupsInColumn(columnGroup, alignment),
170
- this.renderColumnSpace(alignment, 'right')));
171
- }
172
- }
173
- else if (alignment === toolbar_interfaces_1.ToolbarAlignment.RIGHT) {
174
- children = (React.createElement(React.Fragment, null,
175
- this.renderColumnSpace(alignment),
176
- this.renderGroupsInColumn(columnGroup, alignment)));
177
- }
178
- return (React.createElement("div", { role: 'group', className: `toolbar-column ${alignment}` }, children));
179
- }
180
- renderColumnSpace(alignment, position) {
181
- return (React.createElement("div", { className: 'empty-column-space', "data-column": `${alignment}`, "data-center-position": position, onDrop: this.handleOnDrop, onDragEnter: this.handleOnDragEnter, onDragLeave: this.handleOnDragLeave, key: `column-space-${alignment}-${position}` }));
182
- }
183
- renderItemWithDraggableWrapper(item, position) {
184
- const stringifiedPosition = JSON.stringify(position);
185
- let toolbarItemClassNames = '';
186
- let renderBody;
187
- if (tab_bar_toolbar_1.TabBarToolbarItem.is(item)) {
188
- toolbarItemClassNames = [tab_bar_toolbar_1.TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM, 'enabled'].join(' ');
189
- renderBody = this.renderItem(item);
190
- }
191
- else {
192
- const contribution = this.model.getContributionByID(item.id);
193
- if (contribution) {
194
- renderBody = contribution.render();
195
- }
196
- }
197
- 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 },
198
- renderBody,
199
- React.createElement("div", { className: 'hover-overlay' })));
200
- }
201
- renderItem(item) {
202
- const classNames = [];
203
- if (item.text) {
204
- for (const labelPart of this.labelParser.parse(item.text)) {
205
- if (typeof labelPart !== 'string' && label_parser_1.LabelIcon.is(labelPart)) {
206
- const className = `fa fa-${labelPart.name}${labelPart.animation ? ' fa-' + labelPart.animation : ''}`;
207
- classNames.push(...className.split(' '));
208
- }
209
- }
210
- }
211
- const command = this.commands.getCommand(item.command);
212
- const iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon || (command === null || command === void 0 ? void 0 : command.iconClass);
213
- if (iconClass) {
214
- classNames.push(iconClass);
215
- }
216
- let itemTooltip = '';
217
- if (item.tooltip) {
218
- itemTooltip = item.tooltip;
219
- }
220
- else if (command === null || command === void 0 ? void 0 : command.label) {
221
- itemTooltip = command.label;
222
- }
223
- const keybindingString = this.resolveKeybindingForCommand(command === null || command === void 0 ? void 0 : command.id);
224
- itemTooltip = `${itemTooltip}${keybindingString}`;
225
- return (React.createElement("div", { id: item.id, className: classNames.join(' '), title: itemTooltip }));
226
- }
227
- resolveKeybindingForCommand(commandID) {
228
- if (!commandID) {
229
- return '';
230
- }
231
- const keybindings = this.keybindingRegistry.getKeybindingsForCommand(commandID);
232
- if (keybindings.length > 0) {
233
- const binding = keybindings[0];
234
- const bindingKeySequence = this.keybindingRegistry.resolveKeybinding(binding);
235
- const keyCode = bindingKeySequence[0];
236
- return ` (${this.keybindingRegistry.acceleratorForKeyCode(keyCode, '+')})`;
237
- }
238
- return '';
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", Promise)
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 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
+ async init() {
56
+ this.hide();
57
+ await this.model.ready.promise;
58
+ this.updateInlineItems();
59
+ this.update();
60
+ this.model.onToolbarModelDidUpdate(() => {
61
+ this.updateInlineItems();
62
+ this.update();
63
+ });
64
+ this.model.onToolbarDidChangeBusyState(isBusy => {
65
+ if (isBusy) {
66
+ this.isBusyDeferred = new promise_util_1.Deferred();
67
+ this.progressService.withProgress('', exports.TOOLBAR_PROGRESSBAR_ID, async () => this.isBusyDeferred.promise);
68
+ }
69
+ else {
70
+ this.isBusyDeferred.resolve();
71
+ }
72
+ });
73
+ await this.deferredRef.promise;
74
+ this.progressFactory({ container: this.node, insertMode: 'append', locationId: exports.TOOLBAR_PROGRESSBAR_ID });
75
+ }
76
+ updateInlineItems() {
77
+ this.inline.clear();
78
+ const { items } = this.model.toolbarItems;
79
+ for (const column of Object.keys(items)) {
80
+ for (const group of items[column]) {
81
+ for (const item of group) {
82
+ this.inline.set(item.id, item);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ doHandleContextMenu(event) {
88
+ event.preventDefault();
89
+ event.stopPropagation();
90
+ const contextMenuArgs = this.getContextMenuArgs(event);
91
+ const { menuPath, anchor } = this.getMenuDetailsForClick(event);
92
+ return this.contextMenuRenderer.render({
93
+ args: contextMenuArgs,
94
+ menuPath,
95
+ anchor,
96
+ });
97
+ }
98
+ getMenuDetailsForClick(event) {
99
+ const clickId = event.currentTarget.getAttribute('data-id');
100
+ let menuPath;
101
+ let anchor;
102
+ if (clickId === TOOLBAR_BACKGROUND_DATA_ID) {
103
+ menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_BACKGROUND_CONTEXT_MENU;
104
+ const { clientX, clientY } = event;
105
+ anchor = { x: clientX, y: clientY };
106
+ }
107
+ else {
108
+ menuPath = toolbar_constants_1.ToolbarMenus.TOOLBAR_ITEM_CONTEXT_MENU;
109
+ const { left, bottom } = event.currentTarget.getBoundingClientRect();
110
+ anchor = { x: left, y: bottom };
111
+ }
112
+ return { menuPath, anchor };
113
+ }
114
+ getContextMenuArgs(event) {
115
+ const args = [this];
116
+ // data-position is the stringified position of a given toolbar item, this allows
117
+ // the model to be aware of start/stop positions during drag & drop and CRUD operations
118
+ const position = event.currentTarget.getAttribute('data-position');
119
+ const id = event.currentTarget.getAttribute('data-id');
120
+ if (position) {
121
+ args.push(JSON.parse(position));
122
+ }
123
+ else if (id) {
124
+ args.push(id);
125
+ }
126
+ return args;
127
+ }
128
+ renderGroupsInColumn(groups, alignment) {
129
+ const nodes = [];
130
+ groups.forEach((group, groupIndex) => {
131
+ if (nodes.length && group.length) {
132
+ nodes.push(React.createElement("div", { key: `toolbar-separator-${groupIndex}`, className: 'separator' }));
133
+ }
134
+ group.forEach((item, itemIndex) => {
135
+ const position = { alignment, groupIndex, itemIndex };
136
+ nodes.push(this.renderItemWithDraggableWrapper(item, position));
137
+ });
138
+ });
139
+ return nodes;
140
+ }
141
+ doAssignRef(element) {
142
+ this.deferredRef.resolve(element);
143
+ }
144
+ render() {
145
+ var _a, _b, _c;
146
+ const leftGroups = (_a = this.model.toolbarItems) === null || _a === void 0 ? void 0 : _a.items[toolbar_interfaces_1.ToolbarAlignment.LEFT];
147
+ const centerGroups = (_b = this.model.toolbarItems) === null || _b === void 0 ? void 0 : _b.items[toolbar_interfaces_1.ToolbarAlignment.CENTER];
148
+ const rightGroups = (_c = this.model.toolbarItems) === null || _c === void 0 ? void 0 : _c.items[toolbar_interfaces_1.ToolbarAlignment.RIGHT];
149
+ return (React.createElement("div", { className: 'toolbar-wrapper', onContextMenu: this.handleContextMenu, "data-id": TOOLBAR_BACKGROUND_DATA_ID, role: 'menu', tabIndex: 0, ref: this.assignRef },
150
+ this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.LEFT, leftGroups),
151
+ this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.CENTER, centerGroups),
152
+ this.renderColumnWrapper(toolbar_interfaces_1.ToolbarAlignment.RIGHT, rightGroups)));
153
+ }
154
+ renderColumnWrapper(alignment, columnGroup) {
155
+ let children;
156
+ if (alignment === toolbar_interfaces_1.ToolbarAlignment.LEFT) {
157
+ children = (React.createElement(React.Fragment, null,
158
+ this.renderGroupsInColumn(columnGroup, alignment),
159
+ this.renderColumnSpace(alignment)));
160
+ }
161
+ else if (alignment === toolbar_interfaces_1.ToolbarAlignment.CENTER) {
162
+ const isCenterColumnEmpty = !columnGroup.length;
163
+ if (isCenterColumnEmpty) {
164
+ children = this.renderColumnSpace(alignment, 'left');
165
+ }
166
+ else {
167
+ children = (React.createElement(React.Fragment, null,
168
+ this.renderColumnSpace(alignment, 'left'),
169
+ this.renderGroupsInColumn(columnGroup, alignment),
170
+ this.renderColumnSpace(alignment, 'right')));
171
+ }
172
+ }
173
+ else if (alignment === toolbar_interfaces_1.ToolbarAlignment.RIGHT) {
174
+ children = (React.createElement(React.Fragment, null,
175
+ this.renderColumnSpace(alignment),
176
+ this.renderGroupsInColumn(columnGroup, alignment)));
177
+ }
178
+ return (React.createElement("div", { role: 'group', className: `toolbar-column ${alignment}` }, children));
179
+ }
180
+ renderColumnSpace(alignment, position) {
181
+ return (React.createElement("div", { className: 'empty-column-space', "data-column": `${alignment}`, "data-center-position": position, onDrop: this.handleOnDrop, onDragEnter: this.handleOnDragEnter, onDragLeave: this.handleOnDragLeave, key: `column-space-${alignment}-${position}` }));
182
+ }
183
+ renderItemWithDraggableWrapper(item, position) {
184
+ const stringifiedPosition = JSON.stringify(position);
185
+ let toolbarItemClassNames = '';
186
+ let renderBody;
187
+ if (tab_bar_toolbar_1.TabBarToolbarItem.is(item)) {
188
+ toolbarItemClassNames = [tab_bar_toolbar_1.TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM, 'enabled'].join(' ');
189
+ renderBody = this.renderItem(item);
190
+ }
191
+ else {
192
+ const contribution = this.model.getContributionByID(item.id);
193
+ if (contribution) {
194
+ renderBody = contribution.render();
195
+ }
196
+ }
197
+ 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 },
198
+ renderBody,
199
+ React.createElement("div", { className: 'hover-overlay' })));
200
+ }
201
+ renderItem(item) {
202
+ const classNames = [];
203
+ if (item.text) {
204
+ for (const labelPart of this.labelParser.parse(item.text)) {
205
+ if (typeof labelPart !== 'string' && label_parser_1.LabelIcon.is(labelPart)) {
206
+ const className = `fa fa-${labelPart.name}${labelPart.animation ? ' fa-' + labelPart.animation : ''}`;
207
+ classNames.push(...className.split(' '));
208
+ }
209
+ }
210
+ }
211
+ const command = this.commands.getCommand(item.command);
212
+ const iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon || (command === null || command === void 0 ? void 0 : command.iconClass);
213
+ if (iconClass) {
214
+ classNames.push(iconClass);
215
+ }
216
+ let itemTooltip = '';
217
+ if (item.tooltip) {
218
+ itemTooltip = item.tooltip;
219
+ }
220
+ else if (command === null || command === void 0 ? void 0 : command.label) {
221
+ itemTooltip = command.label;
222
+ }
223
+ const keybindingString = this.resolveKeybindingForCommand(command === null || command === void 0 ? void 0 : command.id);
224
+ itemTooltip = `${itemTooltip}${keybindingString}`;
225
+ return (React.createElement("div", { id: item.id, className: classNames.join(' '), title: itemTooltip }));
226
+ }
227
+ resolveKeybindingForCommand(commandID) {
228
+ if (!commandID) {
229
+ return '';
230
+ }
231
+ const keybindings = this.keybindingRegistry.getKeybindingsForCommand(commandID);
232
+ if (keybindings.length > 0) {
233
+ const binding = keybindings[0];
234
+ const bindingKeySequence = this.keybindingRegistry.resolveKeybinding(binding);
235
+ const keyCode = bindingKeySequence[0];
236
+ return ` (${this.keybindingRegistry.acceleratorForKeyCode(keyCode, '+')})`;
237
+ }
238
+ return '';
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", Promise)
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