UNPKG

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