@theia/preferences 1.25.0-next.3 → 1.25.0-next.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/views/components/preference-select-input.d.ts +8 -3
- package/lib/browser/views/components/preference-select-input.d.ts.map +1 -1
- package/lib/browser/views/components/preference-select-input.js +46 -18
- package/lib/browser/views/components/preference-select-input.js.map +1 -1
- package/package.json +8 -8
- package/src/browser/style/index.css +16 -0
- package/src/browser/views/components/preference-select-input.ts +46 -20
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { PreferenceLeafNodeRenderer, PreferenceNodeRenderer } from './preference-node-renderer';
|
|
2
3
|
import { interfaces } from '@theia/core/shared/inversify';
|
|
3
4
|
import { JSONValue } from '@theia/core/shared/@phosphor/coreutils';
|
|
5
|
+
import { SelectComponent, SelectOption } from '@theia/core/lib/browser/widgets/select-component';
|
|
4
6
|
import { Preference } from '../../util/preference-types';
|
|
5
7
|
import { PreferenceLeafNodeRendererContribution } from './preference-node-renderer-creator';
|
|
6
|
-
|
|
8
|
+
import * as React from '@theia/core/shared/react';
|
|
9
|
+
export declare class PreferenceSelectInputRenderer extends PreferenceLeafNodeRenderer<JSONValue, HTMLDivElement> {
|
|
10
|
+
protected readonly selectComponent: React.RefObject<SelectComponent>;
|
|
7
11
|
protected get enumValues(): JSONValue[];
|
|
12
|
+
protected get selectOptions(): SelectOption[];
|
|
8
13
|
protected createInteractable(parent: HTMLElement): void;
|
|
9
14
|
protected getFallbackValue(): JSONValue;
|
|
10
15
|
protected doHandleValueChange(): void;
|
|
11
16
|
/**
|
|
12
17
|
* Returns the stringified index corresponding to the currently selected value.
|
|
13
18
|
*/
|
|
14
|
-
protected getDataValue():
|
|
15
|
-
protected handleUserInteraction(): void;
|
|
19
|
+
protected getDataValue(): number;
|
|
20
|
+
protected handleUserInteraction(selected: number): void;
|
|
16
21
|
}
|
|
17
22
|
export declare class PreferenceSelectInputRendererContribution extends PreferenceLeafNodeRendererContribution {
|
|
18
23
|
static ID: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preference-select-input.d.ts","sourceRoot":"","sources":["../../../../src/browser/views/components/preference-select-input.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAAc,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"preference-select-input.d.ts","sourceRoot":"","sources":["../../../../src/browser/views/components/preference-select-input.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAAc,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,sCAAsC,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAGlD,qBACa,6BAA8B,SAAQ,0BAA0B,CAAC,SAAS,EAAE,cAAc,CAAC;IAEpG,SAAS,CAAC,QAAQ,CAAC,eAAe,mCAAsC;IAExE,SAAS,KAAK,UAAU,IAAI,SAAS,EAAE,CAEtC;IAED,SAAS,KAAK,aAAa,IAAI,YAAY,EAAE,CAsB5C;IAED,SAAS,CAAC,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAavD,SAAS,CAAC,gBAAgB,IAAI,SAAS;IAIvC,SAAS,CAAC,mBAAmB,IAAI,IAAI;IASrC;;OAEG;IACH,SAAS,CAAC,YAAY,IAAI,MAAM;IAMhC,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAI1D;AAED,qBACa,yCAA0C,SAAQ,sCAAsC;IACjG,MAAM,CAAC,EAAE,SAAsC;IAC/C,EAAE,SAAgD;IAElD,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,GAAG,MAAM;IAIpD,sBAAsB,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAG,sBAAsB;CAGlF"}
|
|
@@ -25,36 +25,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.PreferenceSelectInputRendererContribution = exports.PreferenceSelectInputRenderer = void 0;
|
|
26
26
|
const preference_node_renderer_1 = require("./preference-node-renderer");
|
|
27
27
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
28
|
+
const preference_provider_1 = require("@theia/core/lib/browser/preferences/preference-provider");
|
|
29
|
+
const select_component_1 = require("@theia/core/lib/browser/widgets/select-component");
|
|
28
30
|
const preference_node_renderer_creator_1 = require("./preference-node-renderer-creator");
|
|
31
|
+
const React = require("@theia/core/shared/react");
|
|
32
|
+
const ReactDOM = require("@theia/core/shared/react-dom");
|
|
29
33
|
let PreferenceSelectInputRenderer = class PreferenceSelectInputRenderer extends preference_node_renderer_1.PreferenceLeafNodeRenderer {
|
|
34
|
+
constructor() {
|
|
35
|
+
super(...arguments);
|
|
36
|
+
this.selectComponent = React.createRef();
|
|
37
|
+
}
|
|
30
38
|
get enumValues() {
|
|
31
39
|
return this.preferenceNode.preference.data.enum;
|
|
32
40
|
}
|
|
41
|
+
get selectOptions() {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const items = [];
|
|
44
|
+
const values = this.enumValues;
|
|
45
|
+
const defaultValue = this.preferenceNode.preference.data.default;
|
|
46
|
+
for (let i = 0; i < values.length; i++) {
|
|
47
|
+
const value = `${values[i]}`;
|
|
48
|
+
const detail = preference_provider_1.PreferenceProvider.deepEqual(defaultValue, value) ? 'default' : undefined;
|
|
49
|
+
let enumDescription = (_a = this.preferenceNode.preference.data.enumDescriptions) === null || _a === void 0 ? void 0 : _a[i];
|
|
50
|
+
let markdown = false;
|
|
51
|
+
const markdownEnumDescription = (_b = this.preferenceNode.preference.data.markdownEnumDescriptions) === null || _b === void 0 ? void 0 : _b[i];
|
|
52
|
+
if (markdownEnumDescription) {
|
|
53
|
+
enumDescription = this.markdownRenderer.renderInline(markdownEnumDescription);
|
|
54
|
+
markdown = true;
|
|
55
|
+
}
|
|
56
|
+
items.push({
|
|
57
|
+
value,
|
|
58
|
+
detail,
|
|
59
|
+
description: enumDescription,
|
|
60
|
+
markdown
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return items;
|
|
64
|
+
}
|
|
33
65
|
createInteractable(parent) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
66
|
+
const interactable = document.createElement('div');
|
|
67
|
+
const selectComponent = React.createElement(select_component_1.SelectComponent, {
|
|
68
|
+
options: this.selectOptions,
|
|
69
|
+
value: this.getDataValue(),
|
|
70
|
+
onChange: (_, index) => this.handleUserInteraction(index),
|
|
71
|
+
ref: this.selectComponent
|
|
72
|
+
});
|
|
36
73
|
this.interactable = interactable;
|
|
37
|
-
|
|
38
|
-
interactable.onchange = this.handleUserInteraction.bind(this);
|
|
39
|
-
for (const [index, value] of enumValues.entries()) {
|
|
40
|
-
const option = document.createElement('option');
|
|
41
|
-
option.value = index.toString();
|
|
42
|
-
option.textContent = `${value}`;
|
|
43
|
-
interactable.appendChild(option);
|
|
44
|
-
}
|
|
45
|
-
interactable.value = this.getDataValue();
|
|
74
|
+
ReactDOM.render(selectComponent, interactable);
|
|
46
75
|
parent.appendChild(interactable);
|
|
47
76
|
}
|
|
48
77
|
getFallbackValue() {
|
|
49
78
|
return this.preferenceNode.preference.data.enum[0];
|
|
50
79
|
}
|
|
51
80
|
doHandleValueChange() {
|
|
52
|
-
const currentValue = this.interactable.value || undefined;
|
|
53
81
|
this.updateInspection();
|
|
54
82
|
const newValue = this.getDataValue();
|
|
55
83
|
this.updateModificationStatus(this.getValue());
|
|
56
|
-
if (
|
|
57
|
-
this.
|
|
84
|
+
if (document.activeElement !== this.interactable && this.selectComponent.current) {
|
|
85
|
+
this.selectComponent.current.value = newValue;
|
|
58
86
|
}
|
|
59
87
|
}
|
|
60
88
|
/**
|
|
@@ -62,11 +90,11 @@ let PreferenceSelectInputRenderer = class PreferenceSelectInputRenderer extends
|
|
|
62
90
|
*/
|
|
63
91
|
getDataValue() {
|
|
64
92
|
const currentValue = this.getValue();
|
|
65
|
-
const selected = this.enumValues.findIndex(value => value
|
|
66
|
-
return
|
|
93
|
+
const selected = this.enumValues.findIndex(value => preference_provider_1.PreferenceProvider.deepEqual(value, currentValue));
|
|
94
|
+
return Math.max(selected, 0);
|
|
67
95
|
}
|
|
68
|
-
handleUserInteraction() {
|
|
69
|
-
const value = this.enumValues[
|
|
96
|
+
handleUserInteraction(selected) {
|
|
97
|
+
const value = this.enumValues[selected];
|
|
70
98
|
this.setPreferenceImmediately(value);
|
|
71
99
|
}
|
|
72
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preference-select-input.js","sourceRoot":"","sources":["../../../../src/browser/views/components/preference-select-input.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;;;;;;;;;;AAEhF,yEAAgG;AAChG,4DAAsE;
|
|
1
|
+
{"version":3,"file":"preference-select-input.js","sourceRoot":"","sources":["../../../../src/browser/views/components/preference-select-input.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EA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|
+
"version": "1.25.0-next.32+edd747a3e60",
|
|
4
4
|
"description": "Theia - Preferences Extension",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.25.0-next.
|
|
7
|
-
"@theia/editor": "1.25.0-next.
|
|
8
|
-
"@theia/filesystem": "1.25.0-next.
|
|
9
|
-
"@theia/monaco": "1.25.0-next.
|
|
6
|
+
"@theia/core": "1.25.0-next.32+edd747a3e60",
|
|
7
|
+
"@theia/editor": "1.25.0-next.32+edd747a3e60",
|
|
8
|
+
"@theia/filesystem": "1.25.0-next.32+edd747a3e60",
|
|
9
|
+
"@theia/monaco": "1.25.0-next.32+edd747a3e60",
|
|
10
10
|
"@theia/monaco-editor-core": "1.65.2",
|
|
11
|
-
"@theia/userstorage": "1.25.0-next.
|
|
12
|
-
"@theia/workspace": "1.25.0-next.
|
|
11
|
+
"@theia/userstorage": "1.25.0-next.32+edd747a3e60",
|
|
12
|
+
"@theia/workspace": "1.25.0-next.32+edd747a3e60",
|
|
13
13
|
"async-mutex": "^0.3.1",
|
|
14
14
|
"jsonc-parser": "^2.2.0",
|
|
15
15
|
"p-debounce": "^2.1.0"
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"nyc": {
|
|
53
53
|
"extends": "../../configs/nyc.json"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "edd747a3e60c38ff1b3cb75c487a38a05203425a"
|
|
56
56
|
}
|
|
@@ -92,6 +92,14 @@
|
|
|
92
92
|
z-index: -1;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
#theia-main-content-panel .theia-settings-container #preferences-scope-tab-bar .preferences-scope-tab {
|
|
96
|
+
color: var(--theia-panelTitle-inactiveForeground);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#theia-main-content-panel .theia-settings-container #preferences-scope-tab-bar .preferences-scope-tab:hover {
|
|
100
|
+
color: var(--theia-panelTitle-activeForeground);
|
|
101
|
+
}
|
|
102
|
+
|
|
95
103
|
#theia-main-content-panel .theia-settings-container #preferences-scope-tab-bar .preferences-scope-tab.p-mod-current {
|
|
96
104
|
color: var(--theia-panelTitle-activeForeground);
|
|
97
105
|
border-bottom: var(--theia-border-width) solid var(--theia-panelTitle-activeBorder);
|
|
@@ -434,3 +442,11 @@
|
|
|
434
442
|
.theia-settings-container .preference-modified-scope-wrapper:not(:last-child)::after {
|
|
435
443
|
content: ', ';
|
|
436
444
|
}
|
|
445
|
+
|
|
446
|
+
/** Select component */
|
|
447
|
+
|
|
448
|
+
.theia-settings-container .theia-select-component {
|
|
449
|
+
height: 26px;
|
|
450
|
+
width: 100%;
|
|
451
|
+
max-width: 320px;
|
|
452
|
+
}
|
|
@@ -17,29 +17,56 @@
|
|
|
17
17
|
import { PreferenceLeafNodeRenderer, PreferenceNodeRenderer } from './preference-node-renderer';
|
|
18
18
|
import { injectable, interfaces } from '@theia/core/shared/inversify';
|
|
19
19
|
import { JSONValue } from '@theia/core/shared/@phosphor/coreutils';
|
|
20
|
+
import { PreferenceProvider } from '@theia/core/lib/browser/preferences/preference-provider';
|
|
21
|
+
import { SelectComponent, SelectOption } from '@theia/core/lib/browser/widgets/select-component';
|
|
20
22
|
import { Preference } from '../../util/preference-types';
|
|
21
23
|
import { PreferenceLeafNodeRendererContribution } from './preference-node-renderer-creator';
|
|
24
|
+
import * as React from '@theia/core/shared/react';
|
|
25
|
+
import * as ReactDOM from '@theia/core/shared/react-dom';
|
|
22
26
|
|
|
23
27
|
@injectable()
|
|
24
|
-
export class PreferenceSelectInputRenderer extends PreferenceLeafNodeRenderer<JSONValue,
|
|
28
|
+
export class PreferenceSelectInputRenderer extends PreferenceLeafNodeRenderer<JSONValue, HTMLDivElement> {
|
|
29
|
+
|
|
30
|
+
protected readonly selectComponent = React.createRef<SelectComponent>();
|
|
25
31
|
|
|
26
32
|
protected get enumValues(): JSONValue[] {
|
|
27
33
|
return this.preferenceNode.preference.data.enum!;
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
protected get selectOptions(): SelectOption[] {
|
|
37
|
+
const items: SelectOption[] = [];
|
|
38
|
+
const values = this.enumValues;
|
|
39
|
+
const defaultValue = this.preferenceNode.preference.data.default;
|
|
40
|
+
for (let i = 0; i < values.length; i++) {
|
|
41
|
+
const value = `${values[i]}`;
|
|
42
|
+
const detail = PreferenceProvider.deepEqual(defaultValue, value) ? 'default' : undefined;
|
|
43
|
+
let enumDescription = this.preferenceNode.preference.data.enumDescriptions?.[i];
|
|
44
|
+
let markdown = false;
|
|
45
|
+
const markdownEnumDescription = this.preferenceNode.preference.data.markdownEnumDescriptions?.[i];
|
|
46
|
+
if (markdownEnumDescription) {
|
|
47
|
+
enumDescription = this.markdownRenderer.renderInline(markdownEnumDescription);
|
|
48
|
+
markdown = true;
|
|
49
|
+
}
|
|
50
|
+
items.push({
|
|
51
|
+
value,
|
|
52
|
+
detail,
|
|
53
|
+
description: enumDescription,
|
|
54
|
+
markdown
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return items;
|
|
58
|
+
}
|
|
59
|
+
|
|
30
60
|
protected createInteractable(parent: HTMLElement): void {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
61
|
+
const interactable = document.createElement('div');
|
|
62
|
+
const selectComponent = React.createElement(SelectComponent, {
|
|
63
|
+
options: this.selectOptions,
|
|
64
|
+
value: this.getDataValue(),
|
|
65
|
+
onChange: (_, index) => this.handleUserInteraction(index),
|
|
66
|
+
ref: this.selectComponent
|
|
67
|
+
});
|
|
33
68
|
this.interactable = interactable;
|
|
34
|
-
|
|
35
|
-
interactable.onchange = this.handleUserInteraction.bind(this);
|
|
36
|
-
for (const [index, value] of enumValues.entries()) {
|
|
37
|
-
const option = document.createElement('option');
|
|
38
|
-
option.value = index.toString();
|
|
39
|
-
option.textContent = `${value}`;
|
|
40
|
-
interactable.appendChild(option);
|
|
41
|
-
}
|
|
42
|
-
interactable.value = this.getDataValue();
|
|
69
|
+
ReactDOM.render(selectComponent, interactable);
|
|
43
70
|
parent.appendChild(interactable);
|
|
44
71
|
}
|
|
45
72
|
|
|
@@ -48,26 +75,25 @@ export class PreferenceSelectInputRenderer extends PreferenceLeafNodeRenderer<JS
|
|
|
48
75
|
}
|
|
49
76
|
|
|
50
77
|
protected doHandleValueChange(): void {
|
|
51
|
-
const currentValue = this.interactable.value || undefined;
|
|
52
78
|
this.updateInspection();
|
|
53
79
|
const newValue = this.getDataValue();
|
|
54
80
|
this.updateModificationStatus(this.getValue());
|
|
55
|
-
if (
|
|
56
|
-
this.
|
|
81
|
+
if (document.activeElement !== this.interactable && this.selectComponent.current) {
|
|
82
|
+
this.selectComponent.current.value = newValue;
|
|
57
83
|
}
|
|
58
84
|
}
|
|
59
85
|
|
|
60
86
|
/**
|
|
61
87
|
* Returns the stringified index corresponding to the currently selected value.
|
|
62
88
|
*/
|
|
63
|
-
protected getDataValue():
|
|
89
|
+
protected getDataValue(): number {
|
|
64
90
|
const currentValue = this.getValue();
|
|
65
|
-
const selected = this.enumValues.findIndex(value => value
|
|
66
|
-
return
|
|
91
|
+
const selected = this.enumValues.findIndex(value => PreferenceProvider.deepEqual(value, currentValue));
|
|
92
|
+
return Math.max(selected, 0);
|
|
67
93
|
}
|
|
68
94
|
|
|
69
|
-
protected handleUserInteraction(): void {
|
|
70
|
-
const value = this.enumValues[
|
|
95
|
+
protected handleUserInteraction(selected: number): void {
|
|
96
|
+
const value = this.enumValues[selected];
|
|
71
97
|
this.setPreferenceImmediately(value);
|
|
72
98
|
}
|
|
73
99
|
}
|