@dotglitch/ngx-common
Version:
Angular components and utilities that are commonly used.
180 lines (179 loc) • 5.82 kB
TypeScript
import type * as monaco from 'monaco-editor';
export interface SourceCache {
isFileAvailable?: (uri: string) => Promise<boolean>;
storeFile: (uri: string, content: string) => Promise<void>;
getFile: (uri: string) => Promise<string | undefined>;
clear: () => Promise<void>;
}
export type ProgressUpdate = {
type: 'CodeChanged';
} | {
type: 'ResolveNewImports';
} | {
type: 'LookedUpTypeFile';
path: string;
success: boolean;
} | {
type: 'AttemptedLookUpFile';
path: string;
success: boolean;
} | {
type: 'LookedUpPackage';
package: string;
definitelyTyped: boolean;
success: boolean;
} | {
type: 'LoadedFromCache';
importPath: string;
} | {
type: 'StoredToCache';
importPath: string;
};
export interface Options {
/**
* Share source cache between multiple editor instances by storing
* the cache in a static property.
*
* Defaults to false.
*/
shareCache: boolean;
/**
* Only use packages specified in the `versions` property.
*
* Defaults to false.
*/
onlySpecifiedPackages: boolean;
/**
* Load typings from prespecified versions when initializing. Versions
* need to be specified in the ``versions`` option.
*
* Defaults to false.
*/
preloadPackages: boolean;
/**
* Updates compiler options to defaults suitable for auto-loaded
* declarations, specifically by setting ``moduleResolution`` to
* ``NodeJs`` and ``allowSyntheticDefaultImports`` to true.
* Other options are not changed. Set this property to true to
* disable this behaviour.
*
* Defaults to false.
*/
dontAdaptEditorOptions: boolean;
/**
* After typings were resolved and injected into monaco, auto-typings
* updates the value of the current model to trigger a refresh in
* monaco's typing logic, so that it uses the injected typings.
*/
dontRefreshModelValueAfterResolvement: boolean;
/**
* Prespecified package versions. If a package is loaded whose
* name is specified in this object, it will load with the exact
* version specified in the object.
*
* Example:
*
* ```json
* {
* "@types/react": "17.0.0",
* "csstype": "3.0.5"
* }
* ```
*
* Setting the option ``onlySpecifiedPackages`` to true makes this
* property act as a whitelist for packages.
*
* Setting the option ``preloadPackages`` makes the packages specified
* in this property load directly after initializing the auto-loader.
*/
versions?: {
[packageName: string]: string;
};
/**
* If a new package was loaded, its name and version is added to the
* version object, and this method is called with the updated object.
* @param versions updated versions object.
*/
onUpdateVersions?: (versions: {
[packageName: string]: string;
}) => void;
/**
* Supply a cache where declaration files and package.json files are
* cached to. Supply an instance of {@link LocalStorageCache} to cache
* files to localStorage.
*/
sourceCache: SourceCache;
/**
* The root directory where your edited files are. Must end with
* a slash. The default is suitable unless you change the default
* URI of files loaded in the editor.
*
* Defaults to "inmemory://model/"
*/
fileRootPath: string;
/**
* Debounces code reanalyzing after user has changed the editor contents
* by the specified amount. Set to zero to disable. Value provided in
* milliseconds.
*
* Defaults to 4000, i.e. 4 seconds.
*/
debounceDuration: number;
/**
* Maximum recursion depth for recursing packages. Determines how many
* nested package declarations are loaded. For example, if ``packageRecursionDepth``
* has the value 2, the code in the monaco editor references packages ``A1``, ``A2``
* and ``A3``, package ``A1`` references package ``B1`` and ``B1`` references ``C1``,
* then packages ``A1``, ``A2``, ``A3`` and ``B1`` are loaded. Set to zero to
* disable.
*
* Defaults to 3.
*/
packageRecursionDepth: number;
/**
* Maximum recursion depth for recursing files. Determines how many
* nested file declarations are loaded. The same as ``packageRecursionDepth``,
* but for individual files. Set to zero to disable.
*
* Defaults to 10.
*/
fileRecursionDepth: number;
/**
* Called after progress updates like loaded declarations or events.
* @param update detailed event object containing update infos.
* @param textual a textual representation of the update for debugging.
*/
onUpdate?: (update: ProgressUpdate, textual: string) => void;
/**
* Called if errors occur.
* @param error a textual representation of the error.
*/
onError?: (error: string) => void;
/**
* instance of monaco editor
*/
monaco: typeof monaco;
}
export interface ImportResourcePathPackage {
kind: 'package';
packageName: string;
importPath?: string;
}
export interface ImportResourcePathRelative {
kind: 'relative';
importPath: string;
sourcePath: string;
}
export interface ImportResourcePathRelativeInPackage {
kind: 'relative-in-package';
packageName: string;
importPath: string;
sourcePath: string;
}
export interface ImportResourceBruteForce {
kind: 'bruteforce';
packageName: string;
typingFiles: any[];
}
export type ImportResourcePath = ImportResourcePathPackage | ImportResourcePathRelative | ImportResourcePathRelativeInPackage | ImportResourceBruteForce;
export declare const importResourcePathToString: (p: ImportResourcePath) => any;