UNPKG

3.9 kBTypeScriptView Raw
1import { Disposable } from '../common';
2import { Emitter, Event } from '../common/event';
3export declare type ContextKeyValue = null | undefined | boolean | number | string | Array<null | undefined | boolean | number | string> | Record<string, null | undefined | boolean | number | string>;
4export interface ContextKey<T extends ContextKeyValue = ContextKeyValue> {
5 set(value: T | undefined): void;
6 reset(): void;
7 get(): T | undefined;
8}
9export declare namespace ContextKey {
10 const None: ContextKey<any>;
11}
12export interface ContextKeyChangeEvent {
13 affects(keys: {
14 has(key: string): boolean;
15 }): boolean;
16}
17export declare const ContextKeyService: unique symbol;
18export interface ContextMatcher extends Disposable {
19 /**
20 * Whether the expression is satisfied. If `context` provided, the service will attempt to retrieve a context object associated with that element.
21 */
22 match(expression: string, context?: HTMLElement): boolean;
23}
24export interface ContextKeyService extends ContextMatcher {
25 readonly onDidChange: Event<ContextKeyChangeEvent>;
26 createKey<T extends ContextKeyValue>(key: string, defaultValue: T | undefined): ContextKey<T>;
27 /**
28 * @returns a Set of the keys used by the given `expression` or `undefined` if none are used or the expression cannot be parsed.
29 */
30 parseKeys(expression: string): Set<string> | undefined;
31 /**
32 * Creates a temporary context that will use the `values` passed in when evaluating {@link callback}.
33 * {@link callback | The callback} must be synchronous.
34 */
35 with<T>(values: Record<string, unknown>, callback: () => T): T;
36 /**
37 * Creates a child service with a separate context scoped to the HTML element passed in.
38 * Useful for e.g. setting the {view} context value for particular widgets.
39 */
40 createScoped(target: HTMLElement): ScopedValueStore;
41 /**
42 * @param overlay values to be used in the new {@link ContextKeyService}. These values will be static.
43 * Creates a child service with a separate context and a set of fixed values to override parent values.
44 */
45 createOverlay(overlay: Iterable<[string, unknown]>): ContextMatcher;
46 /**
47 * Set or modify a value in the service's context.
48 */
49 setContext(key: string, value: unknown): void;
50}
51export declare type ScopedValueStore = Omit<ContextKeyService, 'onDidChange' | 'match' | 'parseKeys' | 'with' | 'createOverlay'>;
52export declare class ContextKeyServiceDummyImpl implements ContextKeyService {
53 protected readonly onDidChangeEmitter: Emitter<ContextKeyChangeEvent>;
54 readonly onDidChange: Event<ContextKeyChangeEvent>;
55 protected fireDidChange(event: ContextKeyChangeEvent): void;
56 createKey<T extends ContextKeyValue>(key: string, defaultValue: T | undefined): ContextKey<T>;
57 /**
58 * It should be implemented by an extension, e.g. by the monaco extension.
59 */
60 match(expression: string, context?: HTMLElement): boolean;
61 /**
62 * It should be implemented by an extension, e.g. by the monaco extension.
63 */
64 parseKeys(expression: string): Set<string> | undefined;
65 /**
66 * Details should be implemented by an extension, e.g. by the monaco extension.
67 * Callback must be synchronous.
68 */
69 with<T>(values: Record<string, unknown>, callback: () => T): T;
70 /**
71 * Details should implemented by an extension, e.g. by the monaco extension.
72 */
73 createScoped(target: HTMLElement): ContextKeyService;
74 /**
75 * Details should be implemented by an extension, e.g. the monaco extension.
76 */
77 createOverlay(overlay: Iterable<[string, unknown]>): ContextMatcher;
78 /**
79 * Details should be implemented by an extension, e.g. by the monaco extension.
80 */
81 setContext(key: string, value: unknown): void;
82 dispose(): void;
83}
84//# sourceMappingURL=context-key-service.d.ts.map
\No newline at end of file