@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,66 +1,66 @@
1
- /// <reference types="lodash" />
2
- /// <reference types="react" />
3
- import * as React from '@theia/core/shared/react';
4
- import { Root } from '@theia/core/shared/react-dom/client';
5
- import { interfaces } from '@theia/core/shared/inversify';
6
- import { ReactDialog } from '@theia/core/lib/browser/dialogs/react-dialog';
7
- import { DialogProps, Message } from '@theia/core/lib/browser';
8
- import { Command } from '@theia/core';
9
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
10
- import { Deferred } from '@theia/core/lib/common/promise-util';
11
- import PerfectScrollbar from 'perfect-scrollbar';
12
- import { FuzzySearch } from '@theia/core/lib/browser/tree/fuzzy-search';
13
- import { IconSet } from './toolbar-interfaces';
14
- import { ReactInteraction } from './toolbar-constants';
15
- export interface ToolbarIconDialogFactory {
16
- (command: Command): ToolbarIconSelectorDialog;
17
- }
18
- export declare const ToolbarIconDialogFactory: unique symbol;
19
- export declare const ToolbarCommand: unique symbol;
20
- export declare const FontAwesomeIcons: unique symbol;
21
- export declare const CodiconIcons: unique symbol;
22
- export declare class ToolbarIconSelectorDialog extends ReactDialog<string | undefined> {
23
- protected readonly props: DialogProps;
24
- protected readonly toolbarCommand: Command;
25
- protected readonly fileService: FileService;
26
- protected readonly faIcons: string[];
27
- protected readonly codiconIcons: string[];
28
- protected readonly fuzzySearch: FuzzySearch;
29
- static ID: string;
30
- protected deferredScrollContainer: Deferred<HTMLDivElement>;
31
- scrollOptions: PerfectScrollbar.Options;
32
- protected filterRef: HTMLInputElement;
33
- protected selectedIcon: string | undefined;
34
- protected activeIconPrefix: IconSet;
35
- protected iconSets: Map<string, string[]>;
36
- protected filteredIcons: string[];
37
- protected doShowFilterPlaceholder: boolean;
38
- protected debounceHandleSearch: import("lodash").DebouncedFunc<any>;
39
- protected controlPanelRoot: Root;
40
- constructor(props: DialogProps);
41
- protected onUpdateRequest(msg: Message): void;
42
- protected init(): void;
43
- getScrollContainer(): Promise<HTMLElement>;
44
- protected assignScrollContainerRef: (element: HTMLDivElement) => void;
45
- protected doAssignScrollContainerRef(element: HTMLDivElement): void;
46
- protected assignFilterRef: (element: HTMLInputElement) => void;
47
- protected doAssignFilterRef(element: HTMLInputElement): void;
48
- get value(): string | undefined;
49
- protected handleSelectOnChange: (e: React.ChangeEvent<HTMLSelectElement>) => Promise<void>;
50
- protected doHandleSelectOnChange(e: React.ChangeEvent<HTMLSelectElement>): Promise<void>;
51
- protected renderIconSelectorOptions(): React.ReactNode;
52
- protected renderIconGrid(): React.ReactNode;
53
- protected render(): React.ReactNode;
54
- protected doHandleSearch(): Promise<void>;
55
- protected handleOnIconClick: (e: ReactInteraction<HTMLDivElement>) => void;
56
- protected doHandleOnIconClick(e: ReactInteraction<HTMLDivElement>): void;
57
- protected handleOnIconBlur: (e: React.FocusEvent<HTMLDivElement>) => void;
58
- protected doHandleOnIconBlur(e: React.FocusEvent<HTMLDivElement>): void;
59
- protected doAccept: (e: ReactInteraction<HTMLButtonElement>) => void;
60
- protected doClose: () => void;
61
- protected renderControls(): React.ReactElement;
62
- }
63
- export declare const ICON_DIALOG_WIDTH = 600;
64
- export declare const ICON_DIALOG_PADDING = 24;
65
- export declare const bindToolbarIconDialog: (bind: interfaces.Bind) => void;
1
+ /// <reference types="lodash" />
2
+ /// <reference types="react" />
3
+ import * as React from '@theia/core/shared/react';
4
+ import { Root } from '@theia/core/shared/react-dom/client';
5
+ import { interfaces } from '@theia/core/shared/inversify';
6
+ import { ReactDialog } from '@theia/core/lib/browser/dialogs/react-dialog';
7
+ import { DialogProps, Message } from '@theia/core/lib/browser';
8
+ import { Command } from '@theia/core';
9
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
10
+ import { Deferred } from '@theia/core/lib/common/promise-util';
11
+ import PerfectScrollbar from 'perfect-scrollbar';
12
+ import { FuzzySearch } from '@theia/core/lib/browser/tree/fuzzy-search';
13
+ import { IconSet } from './toolbar-interfaces';
14
+ import { ReactInteraction } from './toolbar-constants';
15
+ export interface ToolbarIconDialogFactory {
16
+ (command: Command): ToolbarIconSelectorDialog;
17
+ }
18
+ export declare const ToolbarIconDialogFactory: unique symbol;
19
+ export declare const ToolbarCommand: unique symbol;
20
+ export declare const FontAwesomeIcons: unique symbol;
21
+ export declare const CodiconIcons: unique symbol;
22
+ export declare class ToolbarIconSelectorDialog extends ReactDialog<string | undefined> {
23
+ protected readonly props: DialogProps;
24
+ protected readonly toolbarCommand: Command;
25
+ protected readonly fileService: FileService;
26
+ protected readonly faIcons: string[];
27
+ protected readonly codiconIcons: string[];
28
+ protected readonly fuzzySearch: FuzzySearch;
29
+ static ID: string;
30
+ protected deferredScrollContainer: Deferred<HTMLDivElement>;
31
+ scrollOptions: PerfectScrollbar.Options;
32
+ protected filterRef: HTMLInputElement;
33
+ protected selectedIcon: string | undefined;
34
+ protected activeIconPrefix: IconSet;
35
+ protected iconSets: Map<string, string[]>;
36
+ protected filteredIcons: string[];
37
+ protected doShowFilterPlaceholder: boolean;
38
+ protected debounceHandleSearch: import("lodash").DebouncedFunc<any>;
39
+ protected controlPanelRoot: Root;
40
+ constructor(props: DialogProps);
41
+ protected onUpdateRequest(msg: Message): void;
42
+ protected init(): void;
43
+ getScrollContainer(): Promise<HTMLElement>;
44
+ protected assignScrollContainerRef: (element: HTMLDivElement) => void;
45
+ protected doAssignScrollContainerRef(element: HTMLDivElement): void;
46
+ protected assignFilterRef: (element: HTMLInputElement) => void;
47
+ protected doAssignFilterRef(element: HTMLInputElement): void;
48
+ get value(): string | undefined;
49
+ protected handleSelectOnChange: (e: React.ChangeEvent<HTMLSelectElement>) => Promise<void>;
50
+ protected doHandleSelectOnChange(e: React.ChangeEvent<HTMLSelectElement>): Promise<void>;
51
+ protected renderIconSelectorOptions(): React.ReactNode;
52
+ protected renderIconGrid(): React.ReactNode;
53
+ protected render(): React.ReactNode;
54
+ protected doHandleSearch(): Promise<void>;
55
+ protected handleOnIconClick: (e: ReactInteraction<HTMLDivElement>) => void;
56
+ protected doHandleOnIconClick(e: ReactInteraction<HTMLDivElement>): void;
57
+ protected handleOnIconBlur: (e: React.FocusEvent<HTMLDivElement>) => void;
58
+ protected doHandleOnIconBlur(e: React.FocusEvent<HTMLDivElement>): void;
59
+ protected doAccept: (e: ReactInteraction<HTMLButtonElement>) => void;
60
+ protected doClose: () => void;
61
+ protected renderControls(): React.ReactElement;
62
+ }
63
+ export declare const ICON_DIALOG_WIDTH = 600;
64
+ export declare const ICON_DIALOG_PADDING = 24;
65
+ export declare const bindToolbarIconDialog: (bind: interfaces.Bind) => void;
66
66
  //# sourceMappingURL=toolbar-icon-selector-dialog.d.ts.map
@@ -1,236 +1,236 @@
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
- var __param = (this && this.__param) || function (paramIndex, decorator) {
27
- return function (target, key) { decorator(target, key, paramIndex); }
28
- };
29
- var ToolbarIconSelectorDialog_1;
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.bindToolbarIconDialog = exports.ICON_DIALOG_PADDING = exports.ICON_DIALOG_WIDTH = exports.ToolbarIconSelectorDialog = exports.CodiconIcons = exports.FontAwesomeIcons = exports.ToolbarCommand = exports.ToolbarIconDialogFactory = void 0;
32
- const React = require("@theia/core/shared/react");
33
- const client_1 = require("@theia/core/shared/react-dom/client");
34
- const inversify_1 = require("@theia/core/shared/inversify");
35
- const debounce = require("@theia/core/shared/lodash.debounce");
36
- const react_dialog_1 = require("@theia/core/lib/browser/dialogs/react-dialog");
37
- const browser_1 = require("@theia/core/lib/browser");
38
- const core_1 = require("@theia/core");
39
- const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
40
- const promise_util_1 = require("@theia/core/lib/common/promise-util");
41
- const fuzzy_search_1 = require("@theia/core/lib/browser/tree/fuzzy-search");
42
- const codicons_1 = require("./codicons");
43
- const font_awesome_icons_1 = require("./font-awesome-icons");
44
- const toolbar_interfaces_1 = require("./toolbar-interfaces");
45
- const toolbar_constants_1 = require("./toolbar-constants");
46
- exports.ToolbarIconDialogFactory = Symbol('ToolbarIconDialogFactory');
47
- exports.ToolbarCommand = Symbol('ToolbarCommand');
48
- exports.FontAwesomeIcons = Symbol('FontAwesomeIcons');
49
- exports.CodiconIcons = Symbol('CodiconIcons');
50
- const FIFTY_MS = 50;
51
- let ToolbarIconSelectorDialog = ToolbarIconSelectorDialog_1 = class ToolbarIconSelectorDialog extends react_dialog_1.ReactDialog {
52
- constructor(props) {
53
- super(props);
54
- this.props = props;
55
- this.deferredScrollContainer = new promise_util_1.Deferred();
56
- this.scrollOptions = { ...browser_1.DEFAULT_SCROLL_OPTIONS };
57
- this.activeIconPrefix = toolbar_interfaces_1.IconSet.CODICON;
58
- this.iconSets = new Map();
59
- this.filteredIcons = [];
60
- this.doShowFilterPlaceholder = false;
61
- this.debounceHandleSearch = debounce(this.doHandleSearch.bind(this), FIFTY_MS, { trailing: true });
62
- this.assignScrollContainerRef = (element) => this.doAssignScrollContainerRef(element);
63
- this.assignFilterRef = (element) => this.doAssignFilterRef(element);
64
- this.handleSelectOnChange = async (e) => this.doHandleSelectOnChange(e);
65
- this.handleOnIconClick = (e) => this.doHandleOnIconClick(e);
66
- this.handleOnIconBlur = (e) => this.doHandleOnIconBlur(e);
67
- this.doAccept = (e) => {
68
- const dataId = e.currentTarget.getAttribute('data-id');
69
- if (dataId === 'default-accept') {
70
- this.selectedIcon = this.toolbarCommand.iconClass;
71
- }
72
- this.accept();
73
- };
74
- this.doClose = () => {
75
- this.selectedIcon = undefined;
76
- this.close();
77
- };
78
- this.controlPanelRoot = (0, client_1.createRoot)(this.controlPanel);
79
- this.toDispose.push(core_1.Disposable.create(() => this.controlPanelRoot.unmount()));
80
- }
81
- onUpdateRequest(msg) {
82
- super.onUpdateRequest(msg);
83
- this.controlPanelRoot.render(this.renderControls());
84
- }
85
- init() {
86
- this.node.id = ToolbarIconSelectorDialog_1.ID;
87
- this.iconSets.set(toolbar_interfaces_1.IconSet.FA, this.faIcons);
88
- this.iconSets.set(toolbar_interfaces_1.IconSet.CODICON, this.codiconIcons);
89
- this.activeIconPrefix = toolbar_interfaces_1.IconSet.CODICON;
90
- const initialIcons = this.iconSets.get(this.activeIconPrefix);
91
- if (initialIcons) {
92
- this.filteredIcons = initialIcons;
93
- }
94
- }
95
- async getScrollContainer() {
96
- return this.deferredScrollContainer.promise;
97
- }
98
- doAssignScrollContainerRef(element) {
99
- this.deferredScrollContainer.resolve(element);
100
- }
101
- doAssignFilterRef(element) {
102
- this.filterRef = element;
103
- }
104
- get value() {
105
- return this.selectedIcon;
106
- }
107
- async doHandleSelectOnChange(e) {
108
- const { value } = e.target;
109
- this.activeIconPrefix = value;
110
- this.filteredIcons = [];
111
- await this.doHandleSearch();
112
- this.update();
113
- }
114
- renderIconSelectorOptions() {
115
- return (React.createElement("div", { className: 'icon-selector-options' },
116
- React.createElement("div", { className: 'icon-set-selector-wrapper' },
117
- core_1.nls.localize('theia/toolbar/iconSet', 'Icon Set'),
118
- ': ',
119
- React.createElement("select", { className: 'toolbar-icon-select theia-select', onChange: this.handleSelectOnChange, defaultValue: toolbar_interfaces_1.IconSet.CODICON },
120
- React.createElement("option", { key: toolbar_interfaces_1.IconSet.CODICON, value: toolbar_interfaces_1.IconSet.CODICON }, "Codicon"),
121
- React.createElement("option", { key: toolbar_interfaces_1.IconSet.FA, value: toolbar_interfaces_1.IconSet.FA }, "Font Awesome"))),
122
- React.createElement("div", { className: 'icon-fuzzy-filter' },
123
- React.createElement("input", { ref: this.assignFilterRef, placeholder: core_1.nls.localize('theia/toolbar/filterIcons', 'Filter Icons'), type: 'text', className: 'icon-filter-input theia-input', onChange: this.debounceHandleSearch, spellCheck: false }))));
124
- }
125
- renderIconGrid() {
126
- var _a;
127
- return (React.createElement("div", { className: 'toolbar-scroll-container', ref: this.assignScrollContainerRef },
128
- React.createElement("div", { className: `toolbar-icon-dialog-content ${this.doShowFilterPlaceholder ? '' : 'grid'}` }, !this.doShowFilterPlaceholder ? (_a = this.filteredIcons) === null || _a === void 0 ? void 0 : _a.map(icon => (React.createElement("div", { className: 'icon-wrapper', key: icon, role: 'button', onClick: this.handleOnIconClick, onBlur: this.handleOnIconBlur, tabIndex: 0, "data-id": `${this.activeIconPrefix} ${icon}`, title: icon, onKeyPress: this.handleOnIconClick },
129
- React.createElement("div", { className: `${this.activeIconPrefix} ${icon}` }))))
130
- : React.createElement("div", { className: 'search-placeholder' }, core_1.nls.localizeByDefault('No results found')))));
131
- }
132
- render() {
133
- return (React.createElement(React.Fragment, null,
134
- this.renderIconSelectorOptions(),
135
- this.renderIconGrid()));
136
- }
137
- async doHandleSearch() {
138
- const query = this.filterRef.value;
139
- const pattern = query;
140
- const items = this.iconSets.get(this.activeIconPrefix);
141
- if (items) {
142
- if (pattern.length) {
143
- const transform = (item) => item;
144
- const filterResults = await this.fuzzySearch.filter({ pattern, items, transform });
145
- this.filteredIcons = filterResults.map(result => result.item);
146
- if (!this.filteredIcons.length) {
147
- this.doShowFilterPlaceholder = true;
148
- }
149
- else {
150
- this.doShowFilterPlaceholder = false;
151
- }
152
- }
153
- else {
154
- this.doShowFilterPlaceholder = false;
155
- this.filteredIcons = items;
156
- }
157
- this.update();
158
- }
159
- }
160
- doHandleOnIconClick(e) {
161
- e.currentTarget.classList.add('selected');
162
- if (toolbar_constants_1.ReactKeyboardEvent.is(e) && e.key !== 'Enter') {
163
- return;
164
- }
165
- const iconId = e.currentTarget.getAttribute('data-id');
166
- if (iconId) {
167
- this.selectedIcon = iconId;
168
- this.update();
169
- }
170
- }
171
- doHandleOnIconBlur(e) {
172
- e.currentTarget.classList.remove('selected');
173
- }
174
- renderControls() {
175
- return (React.createElement("div", { className: 'toolbar-icon-controls' },
176
- React.createElement("div", null, this.toolbarCommand.iconClass
177
- && (React.createElement("button", { type: 'button', className: 'theia-button main default-button', "data-id": 'default-accept', onClick: this.doAccept },
178
- React.createElement("span", null, `${core_1.nls.localize('theia/toolbar/useDefaultIcon', 'Use Default Icon')}:`),
179
- React.createElement("div", { className: `toolbar-default-icon ${this.toolbarCommand.iconClass}` })))),
180
- React.createElement("div", null,
181
- React.createElement("button", { type: 'button', disabled: !this.selectedIcon, className: 'theia-button main', onClick: this.doAccept }, core_1.nls.localize('theia/toolbar/selectIcon', 'Select Icon')),
182
- React.createElement("button", { type: 'button', className: 'theia-button secondary', onClick: this.doClose }, browser_1.Dialog.CANCEL))));
183
- }
184
- };
185
- ToolbarIconSelectorDialog.ID = 'toolbar-icon-selector-dialog';
186
- __decorate([
187
- (0, inversify_1.inject)(exports.ToolbarCommand),
188
- __metadata("design:type", Object)
189
- ], ToolbarIconSelectorDialog.prototype, "toolbarCommand", void 0);
190
- __decorate([
191
- (0, inversify_1.inject)(file_service_1.FileService),
192
- __metadata("design:type", file_service_1.FileService)
193
- ], ToolbarIconSelectorDialog.prototype, "fileService", void 0);
194
- __decorate([
195
- (0, inversify_1.inject)(exports.FontAwesomeIcons),
196
- __metadata("design:type", Array)
197
- ], ToolbarIconSelectorDialog.prototype, "faIcons", void 0);
198
- __decorate([
199
- (0, inversify_1.inject)(exports.CodiconIcons),
200
- __metadata("design:type", Array)
201
- ], ToolbarIconSelectorDialog.prototype, "codiconIcons", void 0);
202
- __decorate([
203
- (0, inversify_1.inject)(fuzzy_search_1.FuzzySearch),
204
- __metadata("design:type", fuzzy_search_1.FuzzySearch)
205
- ], ToolbarIconSelectorDialog.prototype, "fuzzySearch", void 0);
206
- __decorate([
207
- (0, inversify_1.postConstruct)(),
208
- __metadata("design:type", Function),
209
- __metadata("design:paramtypes", []),
210
- __metadata("design:returntype", void 0)
211
- ], ToolbarIconSelectorDialog.prototype, "init", null);
212
- ToolbarIconSelectorDialog = ToolbarIconSelectorDialog_1 = __decorate([
213
- (0, inversify_1.injectable)(),
214
- __param(0, (0, inversify_1.inject)(browser_1.DialogProps)),
215
- __metadata("design:paramtypes", [browser_1.DialogProps])
216
- ], ToolbarIconSelectorDialog);
217
- exports.ToolbarIconSelectorDialog = ToolbarIconSelectorDialog;
218
- exports.ICON_DIALOG_WIDTH = 600;
219
- exports.ICON_DIALOG_PADDING = 24;
220
- const bindToolbarIconDialog = (bind) => {
221
- bind(exports.ToolbarIconDialogFactory).toFactory(ctx => (command) => {
222
- const child = ctx.container.createChild();
223
- child.bind(browser_1.DialogProps).toConstantValue({
224
- title: core_1.nls.localize('theia/toolbar/iconSelectDialog', "Select an Icon for '{0}'", command.label),
225
- maxWidth: exports.ICON_DIALOG_WIDTH + exports.ICON_DIALOG_PADDING,
226
- });
227
- child.bind(exports.FontAwesomeIcons).toConstantValue(font_awesome_icons_1.fontAwesomeIcons);
228
- child.bind(exports.CodiconIcons).toConstantValue(codicons_1.codicons);
229
- child.bind(exports.ToolbarCommand).toConstantValue(command);
230
- child.bind(fuzzy_search_1.FuzzySearch).toSelf().inSingletonScope();
231
- child.bind(ToolbarIconSelectorDialog).toSelf().inSingletonScope();
232
- return child.get(ToolbarIconSelectorDialog);
233
- });
234
- };
235
- exports.bindToolbarIconDialog = bindToolbarIconDialog;
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
27
+ return function (target, key) { decorator(target, key, paramIndex); }
28
+ };
29
+ var ToolbarIconSelectorDialog_1;
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.bindToolbarIconDialog = exports.ICON_DIALOG_PADDING = exports.ICON_DIALOG_WIDTH = exports.ToolbarIconSelectorDialog = exports.CodiconIcons = exports.FontAwesomeIcons = exports.ToolbarCommand = exports.ToolbarIconDialogFactory = void 0;
32
+ const React = require("@theia/core/shared/react");
33
+ const client_1 = require("@theia/core/shared/react-dom/client");
34
+ const inversify_1 = require("@theia/core/shared/inversify");
35
+ const debounce = require("@theia/core/shared/lodash.debounce");
36
+ const react_dialog_1 = require("@theia/core/lib/browser/dialogs/react-dialog");
37
+ const browser_1 = require("@theia/core/lib/browser");
38
+ const core_1 = require("@theia/core");
39
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
40
+ const promise_util_1 = require("@theia/core/lib/common/promise-util");
41
+ const fuzzy_search_1 = require("@theia/core/lib/browser/tree/fuzzy-search");
42
+ const codicons_1 = require("./codicons");
43
+ const font_awesome_icons_1 = require("./font-awesome-icons");
44
+ const toolbar_interfaces_1 = require("./toolbar-interfaces");
45
+ const toolbar_constants_1 = require("./toolbar-constants");
46
+ exports.ToolbarIconDialogFactory = Symbol('ToolbarIconDialogFactory');
47
+ exports.ToolbarCommand = Symbol('ToolbarCommand');
48
+ exports.FontAwesomeIcons = Symbol('FontAwesomeIcons');
49
+ exports.CodiconIcons = Symbol('CodiconIcons');
50
+ const FIFTY_MS = 50;
51
+ let ToolbarIconSelectorDialog = ToolbarIconSelectorDialog_1 = class ToolbarIconSelectorDialog extends react_dialog_1.ReactDialog {
52
+ constructor(props) {
53
+ super(props);
54
+ this.props = props;
55
+ this.deferredScrollContainer = new promise_util_1.Deferred();
56
+ this.scrollOptions = { ...browser_1.DEFAULT_SCROLL_OPTIONS };
57
+ this.activeIconPrefix = toolbar_interfaces_1.IconSet.CODICON;
58
+ this.iconSets = new Map();
59
+ this.filteredIcons = [];
60
+ this.doShowFilterPlaceholder = false;
61
+ this.debounceHandleSearch = debounce(this.doHandleSearch.bind(this), FIFTY_MS, { trailing: true });
62
+ this.assignScrollContainerRef = (element) => this.doAssignScrollContainerRef(element);
63
+ this.assignFilterRef = (element) => this.doAssignFilterRef(element);
64
+ this.handleSelectOnChange = async (e) => this.doHandleSelectOnChange(e);
65
+ this.handleOnIconClick = (e) => this.doHandleOnIconClick(e);
66
+ this.handleOnIconBlur = (e) => this.doHandleOnIconBlur(e);
67
+ this.doAccept = (e) => {
68
+ const dataId = e.currentTarget.getAttribute('data-id');
69
+ if (dataId === 'default-accept') {
70
+ this.selectedIcon = this.toolbarCommand.iconClass;
71
+ }
72
+ this.accept();
73
+ };
74
+ this.doClose = () => {
75
+ this.selectedIcon = undefined;
76
+ this.close();
77
+ };
78
+ this.controlPanelRoot = (0, client_1.createRoot)(this.controlPanel);
79
+ this.toDispose.push(core_1.Disposable.create(() => this.controlPanelRoot.unmount()));
80
+ }
81
+ onUpdateRequest(msg) {
82
+ super.onUpdateRequest(msg);
83
+ this.controlPanelRoot.render(this.renderControls());
84
+ }
85
+ init() {
86
+ this.node.id = ToolbarIconSelectorDialog_1.ID;
87
+ this.iconSets.set(toolbar_interfaces_1.IconSet.FA, this.faIcons);
88
+ this.iconSets.set(toolbar_interfaces_1.IconSet.CODICON, this.codiconIcons);
89
+ this.activeIconPrefix = toolbar_interfaces_1.IconSet.CODICON;
90
+ const initialIcons = this.iconSets.get(this.activeIconPrefix);
91
+ if (initialIcons) {
92
+ this.filteredIcons = initialIcons;
93
+ }
94
+ }
95
+ async getScrollContainer() {
96
+ return this.deferredScrollContainer.promise;
97
+ }
98
+ doAssignScrollContainerRef(element) {
99
+ this.deferredScrollContainer.resolve(element);
100
+ }
101
+ doAssignFilterRef(element) {
102
+ this.filterRef = element;
103
+ }
104
+ get value() {
105
+ return this.selectedIcon;
106
+ }
107
+ async doHandleSelectOnChange(e) {
108
+ const { value } = e.target;
109
+ this.activeIconPrefix = value;
110
+ this.filteredIcons = [];
111
+ await this.doHandleSearch();
112
+ this.update();
113
+ }
114
+ renderIconSelectorOptions() {
115
+ return (React.createElement("div", { className: 'icon-selector-options' },
116
+ React.createElement("div", { className: 'icon-set-selector-wrapper' },
117
+ core_1.nls.localize('theia/toolbar/iconSet', 'Icon Set'),
118
+ ': ',
119
+ React.createElement("select", { className: 'toolbar-icon-select theia-select', onChange: this.handleSelectOnChange, defaultValue: toolbar_interfaces_1.IconSet.CODICON },
120
+ React.createElement("option", { key: toolbar_interfaces_1.IconSet.CODICON, value: toolbar_interfaces_1.IconSet.CODICON }, "Codicon"),
121
+ React.createElement("option", { key: toolbar_interfaces_1.IconSet.FA, value: toolbar_interfaces_1.IconSet.FA }, "Font Awesome"))),
122
+ React.createElement("div", { className: 'icon-fuzzy-filter' },
123
+ React.createElement("input", { ref: this.assignFilterRef, placeholder: core_1.nls.localize('theia/toolbar/filterIcons', 'Filter Icons'), type: 'text', className: 'icon-filter-input theia-input', onChange: this.debounceHandleSearch, spellCheck: false }))));
124
+ }
125
+ renderIconGrid() {
126
+ var _a;
127
+ return (React.createElement("div", { className: 'toolbar-scroll-container', ref: this.assignScrollContainerRef },
128
+ React.createElement("div", { className: `toolbar-icon-dialog-content ${this.doShowFilterPlaceholder ? '' : 'grid'}` }, !this.doShowFilterPlaceholder ? (_a = this.filteredIcons) === null || _a === void 0 ? void 0 : _a.map(icon => (React.createElement("div", { className: 'icon-wrapper', key: icon, role: 'button', onClick: this.handleOnIconClick, onBlur: this.handleOnIconBlur, tabIndex: 0, "data-id": `${this.activeIconPrefix} ${icon}`, title: icon, onKeyPress: this.handleOnIconClick },
129
+ React.createElement("div", { className: `${this.activeIconPrefix} ${icon}` }))))
130
+ : React.createElement("div", { className: 'search-placeholder' }, core_1.nls.localizeByDefault('No results found')))));
131
+ }
132
+ render() {
133
+ return (React.createElement(React.Fragment, null,
134
+ this.renderIconSelectorOptions(),
135
+ this.renderIconGrid()));
136
+ }
137
+ async doHandleSearch() {
138
+ const query = this.filterRef.value;
139
+ const pattern = query;
140
+ const items = this.iconSets.get(this.activeIconPrefix);
141
+ if (items) {
142
+ if (pattern.length) {
143
+ const transform = (item) => item;
144
+ const filterResults = await this.fuzzySearch.filter({ pattern, items, transform });
145
+ this.filteredIcons = filterResults.map(result => result.item);
146
+ if (!this.filteredIcons.length) {
147
+ this.doShowFilterPlaceholder = true;
148
+ }
149
+ else {
150
+ this.doShowFilterPlaceholder = false;
151
+ }
152
+ }
153
+ else {
154
+ this.doShowFilterPlaceholder = false;
155
+ this.filteredIcons = items;
156
+ }
157
+ this.update();
158
+ }
159
+ }
160
+ doHandleOnIconClick(e) {
161
+ e.currentTarget.classList.add('selected');
162
+ if (toolbar_constants_1.ReactKeyboardEvent.is(e) && e.key !== 'Enter') {
163
+ return;
164
+ }
165
+ const iconId = e.currentTarget.getAttribute('data-id');
166
+ if (iconId) {
167
+ this.selectedIcon = iconId;
168
+ this.update();
169
+ }
170
+ }
171
+ doHandleOnIconBlur(e) {
172
+ e.currentTarget.classList.remove('selected');
173
+ }
174
+ renderControls() {
175
+ return (React.createElement("div", { className: 'toolbar-icon-controls' },
176
+ React.createElement("div", null, this.toolbarCommand.iconClass
177
+ && (React.createElement("button", { type: 'button', className: 'theia-button main default-button', "data-id": 'default-accept', onClick: this.doAccept },
178
+ React.createElement("span", null, `${core_1.nls.localize('theia/toolbar/useDefaultIcon', 'Use Default Icon')}:`),
179
+ React.createElement("div", { className: `toolbar-default-icon ${this.toolbarCommand.iconClass}` })))),
180
+ React.createElement("div", null,
181
+ React.createElement("button", { type: 'button', disabled: !this.selectedIcon, className: 'theia-button main', onClick: this.doAccept }, core_1.nls.localize('theia/toolbar/selectIcon', 'Select Icon')),
182
+ React.createElement("button", { type: 'button', className: 'theia-button secondary', onClick: this.doClose }, browser_1.Dialog.CANCEL))));
183
+ }
184
+ };
185
+ ToolbarIconSelectorDialog.ID = 'toolbar-icon-selector-dialog';
186
+ __decorate([
187
+ (0, inversify_1.inject)(exports.ToolbarCommand),
188
+ __metadata("design:type", Object)
189
+ ], ToolbarIconSelectorDialog.prototype, "toolbarCommand", void 0);
190
+ __decorate([
191
+ (0, inversify_1.inject)(file_service_1.FileService),
192
+ __metadata("design:type", file_service_1.FileService)
193
+ ], ToolbarIconSelectorDialog.prototype, "fileService", void 0);
194
+ __decorate([
195
+ (0, inversify_1.inject)(exports.FontAwesomeIcons),
196
+ __metadata("design:type", Array)
197
+ ], ToolbarIconSelectorDialog.prototype, "faIcons", void 0);
198
+ __decorate([
199
+ (0, inversify_1.inject)(exports.CodiconIcons),
200
+ __metadata("design:type", Array)
201
+ ], ToolbarIconSelectorDialog.prototype, "codiconIcons", void 0);
202
+ __decorate([
203
+ (0, inversify_1.inject)(fuzzy_search_1.FuzzySearch),
204
+ __metadata("design:type", fuzzy_search_1.FuzzySearch)
205
+ ], ToolbarIconSelectorDialog.prototype, "fuzzySearch", void 0);
206
+ __decorate([
207
+ (0, inversify_1.postConstruct)(),
208
+ __metadata("design:type", Function),
209
+ __metadata("design:paramtypes", []),
210
+ __metadata("design:returntype", void 0)
211
+ ], ToolbarIconSelectorDialog.prototype, "init", null);
212
+ ToolbarIconSelectorDialog = ToolbarIconSelectorDialog_1 = __decorate([
213
+ (0, inversify_1.injectable)(),
214
+ __param(0, (0, inversify_1.inject)(browser_1.DialogProps)),
215
+ __metadata("design:paramtypes", [browser_1.DialogProps])
216
+ ], ToolbarIconSelectorDialog);
217
+ exports.ToolbarIconSelectorDialog = ToolbarIconSelectorDialog;
218
+ exports.ICON_DIALOG_WIDTH = 600;
219
+ exports.ICON_DIALOG_PADDING = 24;
220
+ const bindToolbarIconDialog = (bind) => {
221
+ bind(exports.ToolbarIconDialogFactory).toFactory(ctx => (command) => {
222
+ const child = ctx.container.createChild();
223
+ child.bind(browser_1.DialogProps).toConstantValue({
224
+ title: core_1.nls.localize('theia/toolbar/iconSelectDialog', "Select an Icon for '{0}'", command.label),
225
+ maxWidth: exports.ICON_DIALOG_WIDTH + exports.ICON_DIALOG_PADDING,
226
+ });
227
+ child.bind(exports.FontAwesomeIcons).toConstantValue(font_awesome_icons_1.fontAwesomeIcons);
228
+ child.bind(exports.CodiconIcons).toConstantValue(codicons_1.codicons);
229
+ child.bind(exports.ToolbarCommand).toConstantValue(command);
230
+ child.bind(fuzzy_search_1.FuzzySearch).toSelf().inSingletonScope();
231
+ child.bind(ToolbarIconSelectorDialog).toSelf().inSingletonScope();
232
+ return child.get(ToolbarIconSelectorDialog);
233
+ });
234
+ };
235
+ exports.bindToolbarIconDialog = bindToolbarIconDialog;
236
236
  //# sourceMappingURL=toolbar-icon-selector-dialog.js.map