duoyun-ui
Version:
A lightweight desktop UI component library, implemented using Gem
80 lines • 4.08 kB
TypeScript
import { TemplateResult } from '@mantou/gem/lib/element';
import type { Store } from '@mantou/gem/lib/store';
import type { NonPrimitive } from '@mantou/gem/lib/utils';
/**Similar `lodash.keyBy` */
export declare function convertToMap<T extends Record<string, any>, V = T>(list: (T | null)[], key: keyof T): Record<string, V>;
export declare function convertToMap<T extends Record<string, any>, V = string>(list: (T | null)[], key: keyof T, value: keyof T, fallback?: any): Record<string, V>;
/**Get Cascader/Tree max deep*/
export declare function getCascaderDeep<T>(list: T[], cascaderKey: keyof T): number;
/**
* Get the value from the bottom layer,
* compare the new value of the upper layer to choose a new value, bubbling to the top layer
*/
export declare function getCascaderBubbleWeakMap<T extends Record<string, any>, F extends (_: T) => any, K = Exclude<ReturnType<F>, undefined | null>>(list: T[] | undefined, cascaderKey: keyof T, getValue: F, comparerFn?: (bottomValue: K, topValue: K) => K, setValueCallback?: (item: T, bubbleValue: K) => void): WeakMap<T, K>;
/**Simple proxy object, use prop name as a fallback when reading prop */
export declare function proxyObject(object: Record<string | symbol | number, any>): Record<string | number | symbol, any>;
type ReadPropOptions = {
fill?: boolean;
onlyFillIntermediate?: boolean;
};
/**Deep read prop */
export declare function readProp(obj: Record<string, any>, paths: string | number | symbol | string[], options?: ReadPropOptions): any;
/**Only let the last add Promise take effect, don’t care about the order of Resolve */
export declare class OrderlyPromisePool {
pool: any[];
add<T>(promise: Promise<T>, callback: (r: T) => void): void;
}
export declare enum ComparerType {
Eq = "eq",
Gte = "gte",
Lte = "lte",
Lt = "lt",
Gt = "gt",
Ne = "ne",
Miss = "miss",
Have = "have"
}
/**Serialize comparer */
export declare function comparer(a: any, comparerType: ComparerType, b: any): boolean;
export declare function getStringFromTemplate(input: TemplateResult | string): string;
/**Segmentation search word */
export declare function splitString(s: string): string[];
/**Search */
export declare function isIncludesString(origin: string | TemplateResult, search: string, caseSensitive?: boolean): boolean;
export type UseCacheStoreOptions<T> = {
cacheExcludeKeys?: (keyof T)[];
prefix?: string | (() => string | undefined);
depStore?: Store<NonPrimitive>;
};
/**Create auto cache(localStorage) Store */
export declare function createCacheStore<T extends Record<string, any>>(storageKey: string, initStore: T, options?: UseCacheStoreOptions<T>): {
store: ((value?: Partial<T> | undefined) => void) & Omit<{
name: never;
apply: never;
call: never;
bind: never;
toString: never;
prototype: never;
length: never;
arguments: never;
caller: never;
[Symbol.hasInstance]: never;
[Symbol.metadata]: never;
}, keyof T> & T;
saveStore: () => void;
};
export declare function isRemoteIcon(icon: string | Element | DocumentFragment): icon is string;
/**
* Pass additional fields
*
* not support async function
*/
export declare class DyPromise<T, E extends Record<string, unknown>> extends Promise<T> {
static new<V, U extends Record<string, unknown>>(executor: (resolve: (value: V | PromiseLike<V>) => void, reject: (reason?: any) => void) => void, props: U): DyPromise<V, U> & U;
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): DyPromise<TResult1 | TResult2, E> & E;
catch<TResult>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): DyPromise<TResult | T, E> & E;
finally(onfinally?: (() => void) | null | undefined): DyPromise<T, E> & E;
}
export declare const ignoredPromiseReasonSet: WeakSet<WeakKey>;
export {};
//# sourceMappingURL=utils.d.ts.map