@theia/core 1.64.0-next.28 → 1.64.0

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 (95) hide show
  1. package/README.md +6 -6
  2. package/i18n/nls.cs.json +59 -9
  3. package/i18n/nls.de.json +59 -9
  4. package/i18n/nls.es.json +59 -9
  5. package/i18n/nls.fr.json +59 -9
  6. package/i18n/nls.hu.json +59 -9
  7. package/i18n/nls.it.json +59 -9
  8. package/i18n/nls.ja.json +59 -9
  9. package/i18n/nls.json +63 -13
  10. package/i18n/nls.ko.json +59 -9
  11. package/i18n/nls.pl.json +59 -9
  12. package/i18n/nls.pt-br.json +59 -9
  13. package/i18n/nls.ru.json +59 -9
  14. package/i18n/nls.tr.json +59 -9
  15. package/i18n/nls.zh-cn.json +59 -9
  16. package/i18n/nls.zh-tw.json +59 -9
  17. package/lib/browser/catalog.json +149 -15
  18. package/lib/browser/context-key-service.d.ts +4 -0
  19. package/lib/browser/context-key-service.d.ts.map +1 -1
  20. package/lib/browser/context-key-service.js.map +1 -1
  21. package/lib/browser/frontend-application-module.js +1 -1
  22. package/lib/browser/frontend-application-module.js.map +1 -1
  23. package/lib/browser/menu/browser-menu-plugin.d.ts +1 -1
  24. package/lib/browser/menu/browser-menu-plugin.d.ts.map +1 -1
  25. package/lib/browser/menu/browser-menu-plugin.js +2 -2
  26. package/lib/browser/menu/browser-menu-plugin.js.map +1 -1
  27. package/lib/browser/preload/i18n-preload-contribution.js +1 -1
  28. package/lib/browser/preload/i18n-preload-contribution.js.map +1 -1
  29. package/lib/browser/shell/application-shell.d.ts +1 -1
  30. package/lib/browser/shell/application-shell.d.ts.map +1 -1
  31. package/lib/browser/shell/application-shell.js.map +1 -1
  32. package/lib/common/array-utils.d.ts +4 -0
  33. package/lib/common/array-utils.d.ts.map +1 -1
  34. package/lib/common/array-utils.js +47 -0
  35. package/lib/common/array-utils.js.map +1 -1
  36. package/lib/common/diff.d.ts +33 -0
  37. package/lib/common/diff.d.ts.map +1 -0
  38. package/lib/common/diff.js +20 -0
  39. package/lib/common/diff.js.map +1 -0
  40. package/lib/common/message-rpc/msg-pack-extension-manager.js +2 -2
  41. package/lib/common/message-rpc/msg-pack-extension-manager.js.map +1 -1
  42. package/lib/common/observable/autorun.d.ts +81 -0
  43. package/lib/common/observable/autorun.d.ts.map +1 -0
  44. package/lib/common/observable/autorun.js +194 -0
  45. package/lib/common/observable/autorun.js.map +1 -0
  46. package/lib/common/observable/derived-observable.d.ts +71 -0
  47. package/lib/common/observable/derived-observable.d.ts.map +1 -0
  48. package/lib/common/observable/derived-observable.js +258 -0
  49. package/lib/common/observable/derived-observable.js.map +1 -0
  50. package/lib/common/observable/index.d.ts +8 -0
  51. package/lib/common/observable/index.d.ts.map +1 -0
  52. package/lib/common/observable/index.js +26 -0
  53. package/lib/common/observable/index.js.map +1 -0
  54. package/lib/common/observable/observable-base.d.ts +181 -0
  55. package/lib/common/observable/observable-base.d.ts.map +1 -0
  56. package/lib/common/observable/observable-base.js +183 -0
  57. package/lib/common/observable/observable-base.js.map +1 -0
  58. package/lib/common/observable/observable-from-event.d.ts +41 -0
  59. package/lib/common/observable/observable-from-event.d.ts.map +1 -0
  60. package/lib/common/observable/observable-from-event.js +115 -0
  61. package/lib/common/observable/observable-from-event.js.map +1 -0
  62. package/lib/common/observable/observable-signal.d.ts +9 -0
  63. package/lib/common/observable/observable-signal.d.ts.map +1 -0
  64. package/lib/common/observable/observable-signal.js +45 -0
  65. package/lib/common/observable/observable-signal.js.map +1 -0
  66. package/lib/common/observable/observable-utils.d.ts +26 -0
  67. package/lib/common/observable/observable-utils.d.ts.map +1 -0
  68. package/lib/common/observable/observable-utils.js +98 -0
  69. package/lib/common/observable/observable-utils.js.map +1 -0
  70. package/lib/common/observable/observable.spec.d.ts +2 -0
  71. package/lib/common/observable/observable.spec.d.ts.map +1 -0
  72. package/lib/common/observable/observable.spec.js +301 -0
  73. package/lib/common/observable/observable.spec.js.map +1 -0
  74. package/lib/common/observable/settable-observable.d.ts +16 -0
  75. package/lib/common/observable/settable-observable.d.ts.map +1 -0
  76. package/lib/common/observable/settable-observable.js +58 -0
  77. package/lib/common/observable/settable-observable.js.map +1 -0
  78. package/package.json +7 -8
  79. package/src/browser/context-key-service.ts +5 -0
  80. package/src/browser/frontend-application-module.ts +1 -1
  81. package/src/browser/menu/browser-menu-plugin.ts +3 -3
  82. package/src/browser/preload/i18n-preload-contribution.ts +1 -1
  83. package/src/browser/shell/application-shell.ts +1 -1
  84. package/src/common/array-utils.ts +53 -0
  85. package/src/common/diff.ts +56 -0
  86. package/src/common/message-rpc/msg-pack-extension-manager.ts +2 -2
  87. package/src/common/observable/autorun.ts +246 -0
  88. package/src/common/observable/derived-observable.ts +321 -0
  89. package/src/common/observable/index.ts +23 -0
  90. package/src/common/observable/observable-base.ts +324 -0
  91. package/src/common/observable/observable-from-event.ts +148 -0
  92. package/src/common/observable/observable-signal.ts +48 -0
  93. package/src/common/observable/observable-utils.ts +119 -0
  94. package/src/common/observable/observable.spec.ts +342 -0
  95. package/src/common/observable/settable-observable.ts +73 -0
@@ -0,0 +1,81 @@
1
+ import { Disposable } from '../disposable';
2
+ import { Observable } from './observable-base';
3
+ export declare class Autorun<TChangeSummary = unknown> implements Disposable {
4
+ protected readonly doRun: (args: Autorun.Args<TChangeSummary>) => void;
5
+ protected state: Autorun.State;
6
+ protected updateCount: number;
7
+ protected disposed: boolean;
8
+ protected isRunning: boolean;
9
+ protected dependencies: Set<Observable<unknown, unknown>>;
10
+ protected dependenciesToBeRemoved?: Set<Observable<unknown>>;
11
+ protected readonly dependencyObserver: Observable.Observer;
12
+ protected readonly createChangeSummary?: () => TChangeSummary;
13
+ protected readonly willHandleChange?: <T, TChange>(context: Observable.ChangeContext<T, TChange>, changeSummary: TChangeSummary | undefined) => boolean;
14
+ protected changeSummary?: TChangeSummary;
15
+ constructor(doRun: (args: Autorun.Args<TChangeSummary>) => void, options?: Autorun.Options<TChangeSummary>);
16
+ dispose(): void;
17
+ protected run(isFirstRun?: boolean): void;
18
+ protected watchDependency<T>(dependency: Observable<T>): T;
19
+ protected createDependencyObserver(): Observable.Observer;
20
+ }
21
+ export declare namespace Autorun {
22
+ /**
23
+ * Runs the given {@link run} function immediately, and whenever an update scope ends
24
+ * and an observable tracked as a dependency of the autorun has changed.
25
+ *
26
+ * Note that the run function of the autorun is called within an invocation context where
27
+ * the {@link Observable.Accessor.getCurrent current accessor} is set to track the autorun
28
+ * dependencies, so that any observables accessed with `get()` will automatically be tracked.
29
+ * Occasionally, it might be useful to disable such automatic tracking and track the dependencies
30
+ * manually with `get(accessor)`. This can be done using the {@link Observable.noAutoTracking} function,
31
+ * e.g.
32
+ * ```ts
33
+ * this.toDispose.push(Autorun.create(() => Observable.noAutoTracking(accessor => {
34
+ * const value1 = this.observable1.get(accessor); // the autorun will depend on this observable...
35
+ * const value2 = this.observable2.get(); // ...but not on this observable
36
+ * })));
37
+ * ```
38
+ * In particular, this pattern might be useful when copying existing autorun code from VS Code,
39
+ * where observables can only be tracked manually with `read(reader)`, which corresponds to
40
+ * `get(accessor)` in Theia; calls to `get()` never cause an observable to be tracked. This directly
41
+ * corresponds to disabling automatic tracking in Theia with {@link Observable.noAutoTracking}.
42
+ */
43
+ function create<TChangeSummary = void>(run: (args: Args<TChangeSummary>) => void, options?: Options<TChangeSummary>): Disposable;
44
+ interface Args<TChangeSummary> {
45
+ readonly autorun: Disposable;
46
+ readonly isFirstRun: boolean;
47
+ /**
48
+ * The change summary with the changes collected from the start of the previous run of the autorun until the start of this run.
49
+ *
50
+ * The change summary is created by {@link Options.createChangeSummary} and
51
+ * the changes are collected by {@link Options.willHandleChange}.
52
+ */
53
+ readonly changeSummary: TChangeSummary | undefined;
54
+ }
55
+ interface Options<TChangeSummary> {
56
+ /**
57
+ * Creates a change summary that can collect the changes reported by the observed dependencies to {@link willHandleChange}.
58
+ */
59
+ createChangeSummary?: () => TChangeSummary;
60
+ /**
61
+ * Handles a change reported by an observed dependency, e.g. by adding it to the {@link changeSummary}.
62
+ * Returns `true` if the reported change should be reacted to, and `false` if it should be ignored.
63
+ */
64
+ willHandleChange?: <T, TChange>(context: Observable.ChangeContext<T, TChange>, changeSummary: TChangeSummary | undefined) => boolean;
65
+ }
66
+ const enum State {
67
+ /**
68
+ * Dependencies might have changed. Need to check if at least one dependency has actually changed.
69
+ */
70
+ DependenciesMightHaveChanged = 0,
71
+ /**
72
+ * A dependency has changed. Need to (re-)run.
73
+ */
74
+ Stale = 1,
75
+ /**
76
+ * All is up to date.
77
+ */
78
+ UpToDate = 2
79
+ }
80
+ }
81
+ //# sourceMappingURL=autorun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autorun.d.ts","sourceRoot":"","sources":["../../../src/common/observable/autorun.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,qBAAa,OAAO,CAAC,cAAc,GAAG,OAAO,CAAE,YAAW,UAAU;IAc5D,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,IAAI;IAZ1E,SAAS,CAAC,KAAK,gBAAuB;IACtC,SAAS,CAAC,WAAW,SAAK;IAC1B,SAAS,CAAC,QAAQ,UAAS;IAC3B,SAAS,CAAC,SAAS,UAAS;IAC5B,SAAS,CAAC,YAAY,oCAAkC;IACxD,SAAS,CAAC,uBAAuB,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,SAAS,CAAC,QAAQ,CAAC,kBAAkB,sBAAmC;IACxE,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,cAAc,CAAC;IAC9D,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE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K,OAAO,CAAC;KACxI;IAED,WAAkB,KAAK;QACnB;;WAEG;QACH,4BAA4B,IAAA;QAE5B;;WAEG;QACH,KAAK,IAAA;QAEL;;WAEG;QACH,QAAQ,IAAA;KACX;CACJ"}
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2025 1C-Soft LLC 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
+ /*---------------------------------------------------------------------------------------------
18
+ * Copyright (c) Microsoft Corporation. All rights reserved.
19
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20
+ *--------------------------------------------------------------------------------------------*/
21
+ // copied and modified from https://github.com/microsoft/vscode/blob/1.96.3/src/vs/base/common/observableInternal/autorun.ts
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.Autorun = void 0;
24
+ const observable_base_1 = require("./observable-base");
25
+ class Autorun {
26
+ constructor(doRun, options) {
27
+ var _a;
28
+ this.doRun = doRun;
29
+ this.state = 1 /* Autorun.State.Stale */;
30
+ this.updateCount = 0;
31
+ this.disposed = false;
32
+ this.isRunning = false;
33
+ this.dependencies = new Set();
34
+ this.dependencyObserver = this.createDependencyObserver();
35
+ this.createChangeSummary = options === null || options === void 0 ? void 0 : options.createChangeSummary;
36
+ this.willHandleChange = options === null || options === void 0 ? void 0 : options.willHandleChange;
37
+ this.changeSummary = (_a = this.createChangeSummary) === null || _a === void 0 ? void 0 : _a.call(this);
38
+ try {
39
+ this.run(true);
40
+ }
41
+ catch (e) {
42
+ this.dispose();
43
+ throw e;
44
+ }
45
+ }
46
+ dispose() {
47
+ if (this.disposed) {
48
+ return;
49
+ }
50
+ this.disposed = true;
51
+ for (const dependency of this.dependencies) {
52
+ dependency.removeObserver(this.dependencyObserver);
53
+ }
54
+ this.dependencies.clear();
55
+ }
56
+ run(isFirstRun = false) {
57
+ var _a;
58
+ if (this.disposed) {
59
+ return;
60
+ }
61
+ this.dependenciesToBeRemoved = this.dependencies;
62
+ this.dependencies = new Set();
63
+ this.state = 2 /* Autorun.State.UpToDate */;
64
+ try {
65
+ const { changeSummary } = this;
66
+ this.changeSummary = (_a = this.createChangeSummary) === null || _a === void 0 ? void 0 : _a.call(this);
67
+ this.isRunning = true;
68
+ observable_base_1.Observable.Accessor.runWithAccessor(() => this.doRun({ autorun: this, isFirstRun, changeSummary }), dependency => this.watchDependency(dependency));
69
+ }
70
+ finally {
71
+ this.isRunning = false;
72
+ // We don't want our watched dependencies to think that they are no longer observed, even temporarily.
73
+ // Thus, we only unsubscribe from dependencies that are definitely not watched anymore.
74
+ for (const dependency of this.dependenciesToBeRemoved) {
75
+ dependency.removeObserver(this.dependencyObserver);
76
+ }
77
+ this.dependenciesToBeRemoved = undefined;
78
+ }
79
+ }
80
+ watchDependency(dependency) {
81
+ var _a;
82
+ if (!this.isRunning) {
83
+ throw new Error('The accessor may only be called while the autorun is running');
84
+ }
85
+ // In case the run action disposed the autorun.
86
+ if (this.disposed) {
87
+ return dependency.getUntracked();
88
+ }
89
+ // Subscribe before getting the value to enable caching.
90
+ dependency.addObserver(this.dependencyObserver);
91
+ // This might call handleChange indirectly, which could invalidate us.
92
+ const value = dependency.getUntracked();
93
+ // Which is why we only add the observable to the dependencies now.
94
+ this.dependencies.add(dependency);
95
+ (_a = this.dependenciesToBeRemoved) === null || _a === void 0 ? void 0 : _a.delete(dependency);
96
+ return value;
97
+ }
98
+ createDependencyObserver() {
99
+ return {
100
+ beginUpdate: () => {
101
+ if (this.state === 2 /* Autorun.State.UpToDate */) {
102
+ this.state = 0 /* Autorun.State.DependenciesMightHaveChanged */;
103
+ }
104
+ this.updateCount++;
105
+ },
106
+ endUpdate: () => {
107
+ this.updateCount--;
108
+ if (this.updateCount === 0) {
109
+ do {
110
+ if (this.state === 0 /* Autorun.State.DependenciesMightHaveChanged */) {
111
+ this.state = 2 /* Autorun.State.UpToDate */;
112
+ for (const dependency of this.dependencies) {
113
+ dependency.update(); // might call handleChange indirectly, which could make us stale
114
+ if (this.state === 1 /* Autorun.State.Stale */) {
115
+ // The other dependencies will refresh on demand
116
+ break;
117
+ }
118
+ }
119
+ }
120
+ if (this.state !== 2 /* Autorun.State.UpToDate */) {
121
+ try {
122
+ this.run();
123
+ }
124
+ catch (e) {
125
+ console.error(e);
126
+ }
127
+ }
128
+ // In case the run action changed one of our dependencies, we need to run again.
129
+ } while (this.state !== 2 /* Autorun.State.UpToDate */);
130
+ }
131
+ if (this.updateCount < 0) {
132
+ throw new Error('Unexpected update count: ' + this.updateCount);
133
+ }
134
+ },
135
+ handlePossibleChange: (observable) => {
136
+ var _a;
137
+ if (this.state === 2 /* Autorun.State.UpToDate */ && this.dependencies.has(observable) && !((_a = this.dependenciesToBeRemoved) === null || _a === void 0 ? void 0 : _a.has(observable))) {
138
+ this.state = 0 /* Autorun.State.DependenciesMightHaveChanged */;
139
+ }
140
+ },
141
+ handleChange: (observable, change) => {
142
+ var _a;
143
+ if (this.dependencies.has(observable) && !((_a = this.dependenciesToBeRemoved) === null || _a === void 0 ? void 0 : _a.has(observable))) {
144
+ let shouldReact = true;
145
+ if (this.willHandleChange) {
146
+ try {
147
+ shouldReact = this.willHandleChange({
148
+ observable,
149
+ change,
150
+ isChangeOf: (o) => o === observable
151
+ }, this.changeSummary);
152
+ }
153
+ catch (e) {
154
+ console.error(e);
155
+ }
156
+ }
157
+ if (shouldReact) {
158
+ this.state = 1 /* Autorun.State.Stale */;
159
+ }
160
+ }
161
+ }
162
+ };
163
+ }
164
+ }
165
+ exports.Autorun = Autorun;
166
+ (function (Autorun) {
167
+ /**
168
+ * Runs the given {@link run} function immediately, and whenever an update scope ends
169
+ * and an observable tracked as a dependency of the autorun has changed.
170
+ *
171
+ * Note that the run function of the autorun is called within an invocation context where
172
+ * the {@link Observable.Accessor.getCurrent current accessor} is set to track the autorun
173
+ * dependencies, so that any observables accessed with `get()` will automatically be tracked.
174
+ * Occasionally, it might be useful to disable such automatic tracking and track the dependencies
175
+ * manually with `get(accessor)`. This can be done using the {@link Observable.noAutoTracking} function,
176
+ * e.g.
177
+ * ```ts
178
+ * this.toDispose.push(Autorun.create(() => Observable.noAutoTracking(accessor => {
179
+ * const value1 = this.observable1.get(accessor); // the autorun will depend on this observable...
180
+ * const value2 = this.observable2.get(); // ...but not on this observable
181
+ * })));
182
+ * ```
183
+ * In particular, this pattern might be useful when copying existing autorun code from VS Code,
184
+ * where observables can only be tracked manually with `read(reader)`, which corresponds to
185
+ * `get(accessor)` in Theia; calls to `get()` never cause an observable to be tracked. This directly
186
+ * corresponds to disabling automatic tracking in Theia with {@link Observable.noAutoTracking}.
187
+ */
188
+ function create(run, options) {
189
+ return new Autorun(run, options);
190
+ }
191
+ Autorun.create = create;
192
+ ;
193
+ })(Autorun || (exports.Autorun = Autorun = {}));
194
+ //# sourceMappingURL=autorun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autorun.js","sourceRoot":"","sources":["../../../src/common/observable/autorun.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,6CAA6C;AAC7C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF;;;gGAGgG;AAChG,4HAA4H;;;AAG5H,uDAA+C;AAE/C,MAAa,OAAO;IAahB,YACuB,KAAmD,EACtE,OAAyC;;QADtB,UAAK,G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O,uBAAP,OAAO,QAoEvB"}
@@ -0,0 +1,71 @@
1
+ import { BaseObservable, Observable } from './observable-base';
2
+ /**
3
+ * An observable that is derived from other observables.
4
+ * Its value is only (re-)computed when absolutely needed.
5
+ */
6
+ export declare class DerivedObservable<T, TChangeSummary = unknown> extends BaseObservable<T> {
7
+ protected readonly compute: (args: DerivedObservable.Args<TChangeSummary>) => T;
8
+ protected state: DerivedObservable.State;
9
+ protected value?: T;
10
+ protected updateCount: number;
11
+ protected isComputing: boolean;
12
+ protected dependencies: Set<Observable<unknown, unknown>>;
13
+ protected dependenciesToBeRemoved?: Set<Observable<unknown>>;
14
+ protected removedObserversToCallEndUpdateOn?: Set<Observable.Observer>;
15
+ protected readonly dependencyObserver: Observable.Observer;
16
+ protected readonly isEqual: (a: T, b: T) => boolean;
17
+ protected readonly createChangeSummary?: () => TChangeSummary;
18
+ protected readonly willHandleChange?: <U, UChange>(context: Observable.ChangeContext<U, UChange>, changeSummary: TChangeSummary | undefined) => boolean;
19
+ protected changeSummary?: TChangeSummary;
20
+ constructor(compute: (args: DerivedObservable.Args<TChangeSummary>) => T, options?: DerivedObservable.Options<T, TChangeSummary>);
21
+ protected onLastObserverRemoved(): void;
22
+ protected getValue(): T;
23
+ protected recompute(): void;
24
+ protected watchDependency<U>(dependency: Observable<U>): U;
25
+ protected createDependencyObserver(): Observable.Observer;
26
+ addObserver(observer: Observable.Observer): void;
27
+ removeObserver(observer: Observable.Observer): void;
28
+ }
29
+ export declare namespace DerivedObservable {
30
+ function create<T, TChangeSummary>(compute: (args: Args<TChangeSummary>) => T, options?: Options<T, TChangeSummary>): Observable<T, void>;
31
+ interface Args<TChangeSummary> {
32
+ /**
33
+ * The change summary with the changes collected from the start of the previous run of the compute function until the start of this run.
34
+ *
35
+ * The change summary is created by {@link Options.createChangeSummary} and
36
+ * the changes are collected by {@link Options.willHandleChange}.
37
+ */
38
+ readonly changeSummary: TChangeSummary | undefined;
39
+ }
40
+ interface Options<T, TChangeSummary> {
41
+ isEqual?: (a: T, b: T) => boolean;
42
+ /**
43
+ * Creates a change summary that can collect the changes reported by the observed dependencies to {@link willHandleChange}.
44
+ */
45
+ createChangeSummary?: () => TChangeSummary;
46
+ /**
47
+ * Handles a change reported by an observed dependency, e.g. by adding it to the {@link changeSummary}.
48
+ * Returns `true` if the reported change should be reacted to, and `false` if it should be ignored.
49
+ */
50
+ willHandleChange?: <U, UChange>(context: Observable.ChangeContext<U, UChange>, changeSummary: TChangeSummary | undefined) => boolean;
51
+ }
52
+ const enum State {
53
+ /**
54
+ * Initial state. No cached value.
55
+ */
56
+ Initial = 0,
57
+ /**
58
+ * Dependencies might have changed. Need to check if at least one dependency has actually changed.
59
+ */
60
+ DependenciesMightHaveChanged = 1,
61
+ /**
62
+ * A dependency has changed. Need to recompute the cached value.
63
+ */
64
+ Stale = 2,
65
+ /**
66
+ * The cached value is up to date.
67
+ */
68
+ UpToDate = 3
69
+ }
70
+ }
71
+ //# sourceMappingURL=derived-observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derived-observable.d.ts","sourceRoot":"","sources":["../../../src/common/observable/derived-observable.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAgB7E,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;IAdnF,SAAS,CAAC,KAAK,0BAAmC;IAClD,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACpB,SAAS,CAAC,WAAW,SAAK;IAC1B,SAAS,CAAC,WAAW,UAAS;IAC9B,SAAS,CAAC,YAAY,oCAAkC;IACxD,SAAS,CAAC,uBAAuB,CAAC,EAAE,GAAG,CAAC,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,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAE/I;IAED,UAAiB,IAAI,CAAC,cAAc;QAChC;;;;;WAKG;QACH,QAAQ,CAAC,aAAa,EAAE,cAAc,GAAG,SAAS,CAAC;KACtD;IAED,UAAiB,OAAO,CAAC,CAAC,EAAE,cAAc;QACtC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;QAElC;;WAEG;QACH,mBAAmB,CAAC,EAAE,MAAM,cAAc,CAAC;QAE3C;;;WAGG;QACH,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,EAAE,cAAc,GAAG,SAAS,KAAK,OAAO,CAAC;KACxI;IAED,WAAkB,KAAK;QACnB;;WAEG;QACH,OAAO,IAAA;QAEP;;WAEG;QACH,4BAA4B,IAAA;QAE5B;;WAEG;QACH,KAAK,IAAA;QAEL;;WAEG;QACH,QAAQ,IAAA;KACX;CACJ"}
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2025 1C-Soft LLC 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
+ /*---------------------------------------------------------------------------------------------
18
+ * Copyright (c) Microsoft Corporation. All rights reserved.
19
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20
+ *--------------------------------------------------------------------------------------------*/
21
+ // copied and modified from https://github.com/microsoft/vscode/blob/1.96.3/src/vs/base/common/observableInternal/derived.ts
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.DerivedObservable = void 0;
24
+ const observable_base_1 = require("./observable-base");
25
+ /**
26
+ * An observable that is derived from other observables.
27
+ * Its value is only (re-)computed when absolutely needed.
28
+ */
29
+ class DerivedObservable extends observable_base_1.BaseObservable {
30
+ constructor(compute, options) {
31
+ var _a, _b;
32
+ super();
33
+ this.compute = compute;
34
+ this.state = 0 /* DerivedObservable.State.Initial */;
35
+ this.updateCount = 0;
36
+ this.isComputing = false;
37
+ this.dependencies = new Set();
38
+ this.dependencyObserver = this.createDependencyObserver();
39
+ this.isEqual = (_a = options === null || options === void 0 ? void 0 : options.isEqual) !== null && _a !== void 0 ? _a : ((a, b) => a === b);
40
+ this.createChangeSummary = options === null || options === void 0 ? void 0 : options.createChangeSummary;
41
+ this.willHandleChange = options === null || options === void 0 ? void 0 : options.willHandleChange;
42
+ this.changeSummary = (_b = this.createChangeSummary) === null || _b === void 0 ? void 0 : _b.call(this);
43
+ }
44
+ onLastObserverRemoved() {
45
+ // We are not tracking changes anymore, thus we have to invalidate the cached value.
46
+ this.state = 0 /* DerivedObservable.State.Initial */;
47
+ this.value = undefined;
48
+ for (const dependency of this.dependencies) {
49
+ dependency.removeObserver(this.dependencyObserver);
50
+ }
51
+ this.dependencies.clear();
52
+ }
53
+ getValue() {
54
+ if (this.isComputing) {
55
+ throw new Error('Cyclic dependencies are not allowed');
56
+ }
57
+ if (this.observers.size === 0) {
58
+ // Without observers, we don't know when to clean up stuff.
59
+ // Thus, we don't cache anything to prevent memory leaks.
60
+ let result;
61
+ try {
62
+ this.isComputing = true;
63
+ result = observable_base_1.Observable.Accessor.runWithAccessor(() => { var _a; return this.compute({ changeSummary: (_a = this.createChangeSummary) === null || _a === void 0 ? void 0 : _a.call(this) }); }, dependency => this.watchDependency(dependency));
64
+ }
65
+ finally {
66
+ this.isComputing = false;
67
+ // Clear new dependencies.
68
+ this.onLastObserverRemoved();
69
+ }
70
+ return result;
71
+ }
72
+ else {
73
+ do {
74
+ if (this.state === 1 /* DerivedObservable.State.DependenciesMightHaveChanged */) {
75
+ // Need to ask our depedencies if at least one of them has actually changed.
76
+ for (const dependency of this.dependencies) {
77
+ dependency.update(); // might call handleChange indirectly, which could make us stale
78
+ if (this.state === 2 /* DerivedObservable.State.Stale */) {
79
+ // The other dependencies will refresh on demand, so early break
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ // If we are still not stale, we can assume to be up to date again.
85
+ if (this.state === 1 /* DerivedObservable.State.DependenciesMightHaveChanged */) {
86
+ this.state = 3 /* DerivedObservable.State.UpToDate */;
87
+ }
88
+ if (this.state !== 3 /* DerivedObservable.State.UpToDate */) {
89
+ this.recompute();
90
+ }
91
+ // In case recomputation changed one of our dependencies, we need to recompute again.
92
+ } while (this.state !== 3 /* DerivedObservable.State.UpToDate */);
93
+ return this.value;
94
+ }
95
+ }
96
+ recompute() {
97
+ var _a;
98
+ this.dependenciesToBeRemoved = this.dependencies;
99
+ this.dependencies = new Set();
100
+ const hadValue = this.state !== 0 /* DerivedObservable.State.Initial */;
101
+ const oldValue = this.value;
102
+ this.state = 3 /* DerivedObservable.State.UpToDate */;
103
+ try {
104
+ const { changeSummary } = this;
105
+ this.changeSummary = (_a = this.createChangeSummary) === null || _a === void 0 ? void 0 : _a.call(this);
106
+ this.isComputing = true;
107
+ this.value = observable_base_1.Observable.Accessor.runWithAccessor(() => this.compute({ changeSummary }), dependency => this.watchDependency(dependency));
108
+ }
109
+ finally {
110
+ this.isComputing = false;
111
+ // We don't want our watched dependencies to think that they are no longer observed, even temporarily.
112
+ // Thus, we only unsubscribe from dependencies that are definitely not watched anymore.
113
+ for (const dependency of this.dependenciesToBeRemoved) {
114
+ dependency.removeObserver(this.dependencyObserver);
115
+ }
116
+ this.dependenciesToBeRemoved = undefined;
117
+ }
118
+ const didChange = hadValue && !this.isEqual(oldValue, this.value);
119
+ if (didChange) {
120
+ for (const observer of this.observers) {
121
+ observer.handleChange(this);
122
+ }
123
+ }
124
+ }
125
+ watchDependency(dependency) {
126
+ var _a;
127
+ if (!this.isComputing) {
128
+ throw new Error('The accessor may only be called while the compute function is running');
129
+ }
130
+ // Subscribe before getting the value to enable caching.
131
+ dependency.addObserver(this.dependencyObserver);
132
+ // This might call handleChange indirectly, which could invalidate us.
133
+ const value = dependency.getUntracked();
134
+ // Which is why we only add the observable to the dependencies now.
135
+ this.dependencies.add(dependency);
136
+ (_a = this.dependenciesToBeRemoved) === null || _a === void 0 ? void 0 : _a.delete(dependency);
137
+ return value;
138
+ }
139
+ createDependencyObserver() {
140
+ let inBeginUpdate = false;
141
+ return {
142
+ beginUpdate: () => {
143
+ if (inBeginUpdate) {
144
+ throw new Error('Cyclic dependencies are not allowed');
145
+ }
146
+ inBeginUpdate = true;
147
+ try {
148
+ this.updateCount++;
149
+ const propagateBeginUpdate = this.updateCount === 1;
150
+ if (this.state === 3 /* DerivedObservable.State.UpToDate */) {
151
+ this.state = 1 /* DerivedObservable.State.DependenciesMightHaveChanged */;
152
+ // If we propagate begin update, that will already signal a possible change.
153
+ if (!propagateBeginUpdate) {
154
+ for (const observer of this.observers) {
155
+ observer.handlePossibleChange(this);
156
+ }
157
+ }
158
+ }
159
+ if (propagateBeginUpdate) {
160
+ for (const observer of this.observers) {
161
+ observer.beginUpdate(this); // signals a possible change
162
+ }
163
+ }
164
+ }
165
+ finally {
166
+ inBeginUpdate = false;
167
+ }
168
+ },
169
+ endUpdate: () => {
170
+ this.updateCount--;
171
+ if (this.updateCount === 0) {
172
+ // Calls to endUpdate can potentially change the observers list.
173
+ let observers = [...this.observers];
174
+ for (const observer of observers) {
175
+ observer.endUpdate(this);
176
+ }
177
+ if (this.removedObserversToCallEndUpdateOn) {
178
+ observers = [...this.removedObserversToCallEndUpdateOn];
179
+ this.removedObserversToCallEndUpdateOn = undefined;
180
+ for (const observer of observers) {
181
+ observer.endUpdate(this);
182
+ }
183
+ }
184
+ }
185
+ if (this.updateCount < 0) {
186
+ throw new Error('Unexpected update count: ' + this.updateCount);
187
+ }
188
+ },
189
+ handlePossibleChange: (observable) => {
190
+ var _a;
191
+ // In all other states, observers already know that we might have changed.
192
+ if (this.state === 3 /* DerivedObservable.State.UpToDate */ && this.dependencies.has(observable) && !((_a = this.dependenciesToBeRemoved) === null || _a === void 0 ? void 0 : _a.has(observable))) {
193
+ this.state = 1 /* DerivedObservable.State.DependenciesMightHaveChanged */;
194
+ for (const observer of this.observers) {
195
+ observer.handlePossibleChange(this);
196
+ }
197
+ }
198
+ },
199
+ handleChange: (observable, change) => {
200
+ var _a;
201
+ if (this.dependencies.has(observable) && !((_a = this.dependenciesToBeRemoved) === null || _a === void 0 ? void 0 : _a.has(observable))) {
202
+ let shouldReact = true;
203
+ if (this.willHandleChange) {
204
+ try {
205
+ shouldReact = this.willHandleChange({
206
+ observable,
207
+ change,
208
+ isChangeOf: (o) => o === observable
209
+ }, this.changeSummary);
210
+ }
211
+ catch (e) {
212
+ console.error(e);
213
+ }
214
+ }
215
+ const wasUpToDate = this.state === 3 /* DerivedObservable.State.UpToDate */;
216
+ if (shouldReact && (this.state === 1 /* DerivedObservable.State.DependenciesMightHaveChanged */ || wasUpToDate)) {
217
+ this.state = 2 /* DerivedObservable.State.Stale */;
218
+ if (wasUpToDate) {
219
+ for (const observer of this.observers) {
220
+ observer.handlePossibleChange(this);
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ };
227
+ }
228
+ addObserver(observer) {
229
+ var _a;
230
+ const shouldCallBeginUpdate = !this.observers.has(observer) && this.updateCount > 0;
231
+ super.addObserver(observer);
232
+ if (shouldCallBeginUpdate) {
233
+ if ((_a = this.removedObserversToCallEndUpdateOn) === null || _a === void 0 ? void 0 : _a.has(observer)) {
234
+ this.removedObserversToCallEndUpdateOn.delete(observer);
235
+ }
236
+ else {
237
+ observer.beginUpdate(this);
238
+ }
239
+ }
240
+ }
241
+ removeObserver(observer) {
242
+ if (this.observers.has(observer) && this.updateCount > 0) {
243
+ if (!this.removedObserversToCallEndUpdateOn) {
244
+ this.removedObserversToCallEndUpdateOn = new Set();
245
+ }
246
+ this.removedObserversToCallEndUpdateOn.add(observer);
247
+ }
248
+ super.removeObserver(observer);
249
+ }
250
+ }
251
+ exports.DerivedObservable = DerivedObservable;
252
+ (function (DerivedObservable) {
253
+ function create(compute, options) {
254
+ return new DerivedObservable(compute, options);
255
+ }
256
+ DerivedObservable.create = create;
257
+ })(DerivedObservable || (exports.DerivedObservable = DerivedObservable = {}));
258
+ //# sourceMappingURL=derived-observable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derived-observable.js","sourceRoot":"","sources":["../../../src/common/observable/derived-observable.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,6CAA6C;AAC7C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF;;;gGAGgG;AAChG,4HAA4H;;;AAE5H,uDAA+D;AAE/D;;;GAGG;AACH,MAAa,iBAA+C,SAAQ,gCAAiB;IAejF,YACuB,OAA4D,EAC/E,OAAsD;;QAEtD,KAAK,EAAE,CAAC;QAHW,YAAO,GAAP,OAAO,CAAqD;QAdzE,UAAK,2CAAmC;QAExC,gBAAW,GAAG,CAAC,CAAC;QAChB,gBAAW,GAAG,KAAK,CAAC;QACpB,iBAAY,GAAG,IAAI,GAAG,EAAuB,CAAC;QAGrC,uBAAkB,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAWpE,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO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AC;YAC/B,CAAC;QACL,CAAC;IACL,CAAC;IAEQ,cAAc,CAAC,QAA6B;QACjD,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YACvD,IAAI,CAAC,IAAI,CAAC,iCAAiC,EAAE,CAAC;gBAC1C,IAAI,CAAC,iCAAiC,GAAG,IAAI,GAAG,EAAE,CAAC;YACvD,CAAC;YACD,IAAI,CAAC,iCAAiC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzD,CAAC;QACD,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;CACJ;AA/OD,8CA+OC;AAED,WAAiB,iBAAiB;IAE9B,SAAgB,MAAM,CAAoB,OAA0C,EAAE,OAAoC;QACtH,OAAO,IAAI,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAFe,wBAAM,SAErB,CAAA;AAgDL,CAAC,EApDgB,iBAAiB,iCAAjB,iBAAiB,QAoDjC"}
@@ -0,0 +1,8 @@
1
+ export * from './observable-base';
2
+ export * from './settable-observable';
3
+ export * from './derived-observable';
4
+ export * from './observable-signal';
5
+ export * from './observable-from-event';
6
+ export * from './autorun';
7
+ export * from './observable-utils';
8
+ //# sourceMappingURL=index.d.ts.map