power-compass 0.0.1-alpha.3 → 0.0.1-alpha.4
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.
- package/dist/components/context.d.ts +6 -0
- package/dist/components/hooks/useCursor.d.ts +11 -0
- package/dist/components/hooks/useDebounce.d.ts +2 -0
- package/dist/components/hooks/useShortcut.d.ts +2 -0
- package/dist/http/fetch.d.ts +1 -0
- package/dist/http/index.d.ts +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/menu/clientMenu.d.ts +13 -0
- package/dist/menu/fetchMenu.d.ts +6 -0
- package/dist/menu/fetchMenu.spec.d.ts +1 -0
- package/dist/menu/index.d.ts +2 -0
- package/dist/menu/transformations.d.ts +15 -0
- package/dist/menu/types.d.ts +19 -0
- package/dist/menu/useCompassMenu.d.ts +12 -0
- package/dist/menu/useCompassMenu.spec.d.ts +1 -0
- package/dist/search/createMenuSources.spec.d.ts +1 -0
- package/dist/search/engine.d.ts +14 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/source-scores.spec.d.ts +1 -0
- package/dist/search/sources.d.ts +9 -0
- package/dist/search/types.d.ts +32 -0
- package/dist/search/useSearch.d.ts +4 -0
- package/dist/tasks/index.d.ts +1 -0
- package/dist/tasks/types.d.ts +7 -0
- package/dist/tasks/useLocalStorage.d.ts +1 -0
- package/dist/tasks/useNotificationCenter.d.ts +11 -0
- package/package.json +4 -4
- package/dist/power-compass.es.d.ts +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { SearchResult, ResultEntry } from '../types';
|
|
3
|
+
type Cursor = {
|
|
4
|
+
cursor?: ResultEntry<unknown>;
|
|
5
|
+
previous: () => void;
|
|
6
|
+
next: () => void;
|
|
7
|
+
resetCursor: () => void;
|
|
8
|
+
updateCursor: React.Dispatch<React.SetStateAction<ResultEntry<unknown> | undefined>>;
|
|
9
|
+
};
|
|
10
|
+
declare function useCursor(searchResult: SearchResult<unknown>[]): Cursor;
|
|
11
|
+
export default useCursor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fetchBackend<T>(backend: string, contextId: string, service: string, query: ConstructorParameters<typeof URLSearchParams>[0]): Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fetch';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MenuItem, CompassMenuResult } from './types';
|
|
2
|
+
export type FutureMenuItem = () => Promise<MenuItem>;
|
|
3
|
+
export type FilterValue = true | false | undefined | string;
|
|
4
|
+
export type PluginFilterKey = keyof typeof PluginFilters;
|
|
5
|
+
export type PluginFilter = {
|
|
6
|
+
[Property in PluginFilterKey]?: FilterValue;
|
|
7
|
+
};
|
|
8
|
+
declare const PluginFilters: {
|
|
9
|
+
tagged(items: MenuItem[], tag: FilterValue): MenuItem[];
|
|
10
|
+
};
|
|
11
|
+
export declare function fetchPlugin(filters?: PluginFilter): Promise<CompassMenuResult>;
|
|
12
|
+
export declare function createMenuItem(item: MenuItem | FutureMenuItem): Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MenuItem, CompassMenuResult } from './types';
|
|
2
|
+
export type CompassMenuFilters = {
|
|
3
|
+
tagged?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function fetchMenu(backend: string, contextId: string, filters?: CompassMenuFilters): Promise<CompassMenuResult>;
|
|
6
|
+
export declare function fetchMenus(backends: string[], contextId: string, filters?: CompassMenuFilters): Promise<MenuItem[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MenuItem } from './types';
|
|
2
|
+
export type FlatMenuItem = Omit<MenuItem, "items"> & {
|
|
3
|
+
parent?: FlatMenuItem;
|
|
4
|
+
};
|
|
5
|
+
export type TransformedMenuItem<Option extends TransformOptions = TransformOptions> = Option["flatten"] extends true ? FlatMenuItem : MenuItem;
|
|
6
|
+
export declare const Transformations: {
|
|
7
|
+
flatten(menuItems: MenuItem[], parent?: FlatMenuItem): FlatMenuItem[];
|
|
8
|
+
trim(menuItems: MenuItem[]): MenuItem[];
|
|
9
|
+
};
|
|
10
|
+
export type TransformOption = true | false | undefined;
|
|
11
|
+
export type TransformOptionKey = keyof typeof Transformations;
|
|
12
|
+
export type TransformOptions = {
|
|
13
|
+
[Property in TransformOptionKey]?: TransformOption;
|
|
14
|
+
};
|
|
15
|
+
export declare function applyTransformations(items: MenuItem[], options: TransformOptions): TransformedMenuItem[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
export type MenuItem = {
|
|
3
|
+
badge?: number;
|
|
4
|
+
gravity?: number;
|
|
5
|
+
icon?: string;
|
|
6
|
+
items?: MenuItem[];
|
|
7
|
+
label: string;
|
|
8
|
+
meta?: Record<string, string>;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
url?: string;
|
|
11
|
+
modal?: ComponentType;
|
|
12
|
+
onSelect?: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type CompassMenuResult = {
|
|
15
|
+
items: MenuItem[];
|
|
16
|
+
error?: {
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CompassMenuFilters } from './fetchMenu';
|
|
2
|
+
import { CompassContext } from '../components/context';
|
|
3
|
+
import { TransformOptions, TransformedMenuItem } from './transformations';
|
|
4
|
+
type UseCompassMenuOptions = Partial<CompassContext> & TransformOptions & {
|
|
5
|
+
filters?: CompassMenuFilters;
|
|
6
|
+
};
|
|
7
|
+
type UseCompassMenu = {
|
|
8
|
+
items: TransformedMenuItem[];
|
|
9
|
+
loading: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function useCompassMenu({ filters, backends: backendsOverride, contextId: contextIdOverride, ...options }: UseCompassMenuOptions): UseCompassMenu;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SearchResult, SourceDefinition } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Sorts matches by score.
|
|
4
|
+
* Sorts sources by best match's score and move them as per specified by their `insertSourceAtIndex` key.
|
|
5
|
+
*
|
|
6
|
+
* @param {*} sources all sources added to Spotnitro. See `app/javascript/packs/spotnitro.ts`
|
|
7
|
+
* @param {*} data GraphQL data
|
|
8
|
+
* @param {*} search user's input
|
|
9
|
+
* @see source-scores-spec.js
|
|
10
|
+
*/
|
|
11
|
+
export declare function sortSearchResults<T>(results: SearchResult<T>[]): SearchResult<T>[];
|
|
12
|
+
type OnResultCallback = (result: SearchResult<unknown>) => void;
|
|
13
|
+
export declare function search(value: string, sources: SourceDefinition<unknown>[], abortController?: AbortController, onResult?: OnResultCallback): Promise<SearchResult<unknown>[]>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useSearch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SourceDefinition } from './types';
|
|
2
|
+
export declare const sources: SourceDefinition<unknown>[];
|
|
3
|
+
type SourceDefinitionCreation<T> = Omit<SourceDefinition<T>, "open" | "display"> & Partial<Pick<SourceDefinition<T>, "open" | "display">>;
|
|
4
|
+
export declare function createCompassProviderSource(contextId: string | number | undefined, providerName: string, search: string, abortController?: AbortController): Promise<SourceDefinition<unknown> | null>;
|
|
5
|
+
export declare function getCompassProviders(contextId: string | number, abortController?: AbortController): Promise<string[]>;
|
|
6
|
+
export declare function createCompassSources(contextId: string | number | undefined, search: string, abortController?: AbortController): Promise<SourceDefinition<unknown>[]>;
|
|
7
|
+
export declare function createMenuSources(backends: string[], contextId: string): SourceDefinition<unknown>[];
|
|
8
|
+
export declare function createSource<T>(source: SourceDefinitionCreation<T>): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
export type SourceDefinition<T> = {
|
|
3
|
+
label?: string;
|
|
4
|
+
tag?: string;
|
|
5
|
+
searchOptions?: Record<string, unknown>;
|
|
6
|
+
newTab?: boolean;
|
|
7
|
+
insertSourceAtIndex?: number;
|
|
8
|
+
maxEntries?: number;
|
|
9
|
+
display: ComponentType<ResultEntry<T>> | DisplayProps<T>;
|
|
10
|
+
fetch: (arg0: string, options?: RequestInit) => Promise<T[]>;
|
|
11
|
+
open: (arg0: T) => string | Promise<string> | void;
|
|
12
|
+
};
|
|
13
|
+
export type ResultEntry<T> = {
|
|
14
|
+
item: T;
|
|
15
|
+
score: number;
|
|
16
|
+
source: SourceDefinition<T>;
|
|
17
|
+
};
|
|
18
|
+
export type SearchResult<T> = {
|
|
19
|
+
source: SourceDefinition<T>;
|
|
20
|
+
entries: ResultEntry<T>[];
|
|
21
|
+
};
|
|
22
|
+
export interface SearchItem {
|
|
23
|
+
html?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
tag?: string;
|
|
26
|
+
url?: string;
|
|
27
|
+
}
|
|
28
|
+
export type DisplayProps<T> = {
|
|
29
|
+
label: (arg0: T) => Promise<string> | string;
|
|
30
|
+
category: (arg0: T) => Promise<string> | string;
|
|
31
|
+
tag: (arg0: T) => Promise<string> | string;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useNotificationCenter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useLocalStorage: <T>(key: string, initialValue: T) => any[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Notification } from './types';
|
|
2
|
+
interface Props {
|
|
3
|
+
contextId?: string | number;
|
|
4
|
+
}
|
|
5
|
+
interface UseNotificationCenterReturn {
|
|
6
|
+
notifications: Notification[];
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function useNotificationCenter({ contextId, }: Props): UseNotificationCenterReturn;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "power-compass",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/power-compass.cjs.js",
|
|
6
6
|
"module": "./dist/power-compass.es.js",
|
|
7
|
-
"types": "./dist/
|
|
7
|
+
"types": "./dist/types.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/power-compass.es.js",
|
|
11
11
|
"require": "./dist/power-compass.cjs.js",
|
|
12
|
-
"types": "./dist/
|
|
12
|
+
"types": "./dist/types.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"./cjs": {
|
|
15
15
|
"require": "./dist/power-compass.cjs.js",
|
|
16
|
-
"types": "./dist/
|
|
16
|
+
"types": "./dist/types.d.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|