@tiny-server/core 0.0.0
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/api/apiResults.d.ts +48 -0
- package/dist/api/entity.d.ts +27 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/paginationOptions.d.ts +13 -0
- package/dist/api/permissions.d.ts +55 -0
- package/dist/api/problemDetails.d.ts +16 -0
- package/dist/api/session.d.ts +38 -0
- package/dist/api/sortOptions.d.ts +17 -0
- package/dist/api/status.d.ts +27 -0
- package/dist/app/App.d.ts +12 -0
- package/dist/app/context.d.ts +6 -0
- package/dist/app/create.d.ts +12 -0
- package/dist/app/features/extensions/Extension.d.ts +32 -0
- package/dist/app/features/extensions/index.d.ts +2 -0
- package/dist/app/features/extensions/types.d.ts +43 -0
- package/dist/app/features/index.d.ts +6 -0
- package/dist/app/features/layout/Error.d.ts +15 -0
- package/dist/app/features/layout/Layout.d.ts +4 -0
- package/dist/app/features/layout/Loading.d.ts +14 -0
- package/dist/app/features/layout/Page.d.ts +6 -0
- package/dist/app/features/layout/index.d.ts +6 -0
- package/dist/app/features/layout/initializer.d.ts +2 -0
- package/dist/app/features/layout/types.d.ts +13 -0
- package/dist/app/features/menu/Menu.d.ts +7 -0
- package/dist/app/features/menu/MenuContainer.d.ts +4 -0
- package/dist/app/features/menu/MenuItem.d.ts +11 -0
- package/dist/app/features/menu/index.d.ts +5 -0
- package/dist/app/features/menu/initializer.d.ts +2 -0
- package/dist/app/features/menu/types.d.ts +71 -0
- package/dist/app/features/modals/Modal.d.ts +5 -0
- package/dist/app/features/modals/ModalBody.d.ts +4 -0
- package/dist/app/features/modals/ModalContent.d.ts +7 -0
- package/dist/app/features/modals/ModalFooter.d.ts +5 -0
- package/dist/app/features/modals/ModalHeader.d.ts +5 -0
- package/dist/app/features/modals/Modals.d.ts +4 -0
- package/dist/app/features/modals/index.d.ts +8 -0
- package/dist/app/features/modals/initializer.d.ts +2 -0
- package/dist/app/features/modals/store.d.ts +14 -0
- package/dist/app/features/modals/types.d.ts +84 -0
- package/dist/app/features/query/AppQueryClientProvider.d.ts +2 -0
- package/dist/app/features/query/client.d.ts +2 -0
- package/dist/app/features/query/index.d.ts +3 -0
- package/dist/app/features/query/initializer.d.ts +2 -0
- package/dist/app/features/query/types.d.ts +9 -0
- package/dist/app/features/router/AppLayout.d.ts +1 -0
- package/dist/app/features/router/AppRouteLayout.d.ts +5 -0
- package/dist/app/features/router/AppRouter.d.ts +4 -0
- package/dist/app/features/router/RouterErrorBoundary.d.ts +1 -0
- package/dist/app/features/router/context.d.ts +5 -0
- package/dist/app/features/router/index.d.ts +3 -0
- package/dist/app/features/router/middlewares.d.ts +42 -0
- package/dist/app/index.d.ts +5 -0
- package/dist/app/types.d.ts +78 -0
- package/dist/components/ErrorBoundary.d.ts +19 -0
- package/dist/components/WithPermissions.d.ts +30 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/fetch.d.ts +84 -0
- package/dist/i18n/InitI18n.d.ts +6 -0
- package/dist/i18n/defineLocales.d.ts +10 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/useGlobalT.d.ts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +557 -0
- package/dist/module.d.ts +7 -0
- package/dist/utils/dates.d.ts +3 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/usePagination.d.ts +31 -0
- package/dist/utils/useSearch.d.ts +19 -0
- package/dist/utils/useSession.d.ts +22 -0
- package/package.json +52 -0
- package/src/api/apiResults.ts +50 -0
- package/src/api/entity.ts +29 -0
- package/src/api/index.ts +8 -0
- package/src/api/paginationOptions.ts +13 -0
- package/src/api/permissions.ts +63 -0
- package/src/api/problemDetails.ts +19 -0
- package/src/api/session.ts +51 -0
- package/src/api/sortOptions.ts +18 -0
- package/src/api/status.ts +34 -0
- package/src/app/App.tsx +33 -0
- package/src/app/context.ts +17 -0
- package/src/app/create.ts +34 -0
- package/src/app/features/extensions/Extension.tsx +69 -0
- package/src/app/features/extensions/index.ts +2 -0
- package/src/app/features/extensions/types.tsx +52 -0
- package/src/app/features/index.ts +6 -0
- package/src/app/features/layout/Error.tsx +20 -0
- package/src/app/features/layout/Layout.tsx +7 -0
- package/src/app/features/layout/Loading.tsx +21 -0
- package/src/app/features/layout/Page.tsx +42 -0
- package/src/app/features/layout/index.ts +6 -0
- package/src/app/features/layout/initializer.ts +12 -0
- package/src/app/features/layout/types.ts +14 -0
- package/src/app/features/menu/Menu.tsx +66 -0
- package/src/app/features/menu/MenuContainer.tsx +9 -0
- package/src/app/features/menu/MenuItem.tsx +46 -0
- package/src/app/features/menu/index.ts +5 -0
- package/src/app/features/menu/initializer.ts +8 -0
- package/src/app/features/menu/types.ts +84 -0
- package/src/app/features/modals/Modal.tsx +20 -0
- package/src/app/features/modals/ModalBody.tsx +8 -0
- package/src/app/features/modals/ModalContent.tsx +35 -0
- package/src/app/features/modals/ModalFooter.tsx +19 -0
- package/src/app/features/modals/ModalHeader.tsx +15 -0
- package/src/app/features/modals/Modals.tsx +33 -0
- package/src/app/features/modals/index.ts +8 -0
- package/src/app/features/modals/initializer.ts +17 -0
- package/src/app/features/modals/store.ts +35 -0
- package/src/app/features/modals/types.ts +94 -0
- package/src/app/features/query/AppQueryClientProvider.tsx +7 -0
- package/src/app/features/query/client.ts +3 -0
- package/src/app/features/query/index.ts +3 -0
- package/src/app/features/query/initializer.ts +6 -0
- package/src/app/features/query/types.ts +10 -0
- package/src/app/features/router/AppLayout.tsx +18 -0
- package/src/app/features/router/AppRouteLayout.tsx +31 -0
- package/src/app/features/router/AppRouter.tsx +45 -0
- package/src/app/features/router/RouterErrorBoundary.tsx +20 -0
- package/src/app/features/router/context.ts +7 -0
- package/src/app/features/router/index.ts +3 -0
- package/src/app/features/router/middlewares.ts +76 -0
- package/src/app/index.ts +6 -0
- package/src/app/types.ts +82 -0
- package/src/components/ErrorBoundary.tsx +34 -0
- package/src/components/WithPermissions.tsx +59 -0
- package/src/components/index.ts +2 -0
- package/src/fetch.ts +185 -0
- package/src/i18n/InitI18n.tsx +24 -0
- package/src/i18n/defineLocales.ts +59 -0
- package/src/i18n/index.ts +3 -0
- package/src/i18n/useGlobalT.ts +13 -0
- package/src/index.ts +8 -0
- package/src/module.tsx +27 -0
- package/src/utils/dates.ts +34 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/usePagination.ts +64 -0
- package/src/utils/useSearch.ts +40 -0
- package/src/utils/useSession.ts +42 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps the result of an API endpoint and enriches that result with additional metadata.
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiResult<T> {
|
|
5
|
+
/**
|
|
6
|
+
* The data returned by the API.
|
|
7
|
+
*/
|
|
8
|
+
data: T;
|
|
9
|
+
/**
|
|
10
|
+
* The time when the API result was generated.
|
|
11
|
+
*/
|
|
12
|
+
timestamp: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A specialized {@link ApiResult} for lists of data.
|
|
16
|
+
*/
|
|
17
|
+
export interface ListApiResult<T> extends ApiResult<Array<T>> {
|
|
18
|
+
/**
|
|
19
|
+
* The total number of items returned.
|
|
20
|
+
*/
|
|
21
|
+
count: number;
|
|
22
|
+
}
|
|
23
|
+
export interface PaginationApiResult<T> extends ListApiResult<T> {
|
|
24
|
+
/**
|
|
25
|
+
* The returned page.
|
|
26
|
+
*/
|
|
27
|
+
page: number;
|
|
28
|
+
/**
|
|
29
|
+
* The number of items per page.
|
|
30
|
+
*/
|
|
31
|
+
pageSize: number;
|
|
32
|
+
/**
|
|
33
|
+
* The total number of items across all pages.
|
|
34
|
+
*/
|
|
35
|
+
totalItems: number;
|
|
36
|
+
/**
|
|
37
|
+
* The total number of pages available.
|
|
38
|
+
*/
|
|
39
|
+
totalPages: number;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a previous page exists.
|
|
42
|
+
*/
|
|
43
|
+
hasPreviousPage: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether a next page exists.
|
|
46
|
+
*/
|
|
47
|
+
hasNextPage: boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a generic entity.
|
|
3
|
+
*/
|
|
4
|
+
export interface EntityRead<TId extends string = string> {
|
|
5
|
+
/**
|
|
6
|
+
* The entity's ID.
|
|
7
|
+
*/
|
|
8
|
+
id: TId;
|
|
9
|
+
/**
|
|
10
|
+
* The date and time when the entity was created.
|
|
11
|
+
*/
|
|
12
|
+
createdOn: string;
|
|
13
|
+
/**
|
|
14
|
+
* The date and time when the entity was last updated.
|
|
15
|
+
*/
|
|
16
|
+
updatedOn: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Represents data for creating an entity.
|
|
20
|
+
*/
|
|
21
|
+
export interface EntityCreate {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Represents data for updating an entity.
|
|
25
|
+
*/
|
|
26
|
+
export interface EntityUpdate {
|
|
27
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ListApiResult } from './apiResults';
|
|
2
|
+
/**
|
|
3
|
+
* An interface mapping all known backend permissions to an arbitrary value.
|
|
4
|
+
* {@link Permissions} is derived from this interface`s key.
|
|
5
|
+
*
|
|
6
|
+
* You can extend known {@link Permission}s by declaring a module augmentation for this interface.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* declare module "@tiny-server/core" {
|
|
11
|
+
* interface PermissionsMap {
|
|
12
|
+
* ["my.permission"]: "";
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* // Results in:
|
|
17
|
+
* const permission: Permission = "my.permission"; // ✅ Valid
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface PermissionsMap {
|
|
21
|
+
['read.all']: '';
|
|
22
|
+
['write.all']: '';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Declares all known backend permissions.
|
|
26
|
+
*/
|
|
27
|
+
export type Permission = keyof PermissionsMap;
|
|
28
|
+
/**
|
|
29
|
+
* Represents a permission with its hierarchy information.
|
|
30
|
+
*/
|
|
31
|
+
export interface PermissionRead {
|
|
32
|
+
/**
|
|
33
|
+
* The permission`s name.
|
|
34
|
+
*/
|
|
35
|
+
name: Permission;
|
|
36
|
+
/**
|
|
37
|
+
* The permission`s direct parent names.
|
|
38
|
+
*/
|
|
39
|
+
parents: Array<Permission>;
|
|
40
|
+
/**
|
|
41
|
+
* All parent names, including parents of parents, and so on.
|
|
42
|
+
*/
|
|
43
|
+
allParents: Array<Permission>;
|
|
44
|
+
}
|
|
45
|
+
/** `GET /api/v1/permissions` */
|
|
46
|
+
export declare function readPermissions(): Promise<ListApiResult<PermissionRead>>;
|
|
47
|
+
/** {@link readPermissions} */
|
|
48
|
+
export declare function readPermissionsQuery(): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<ListApiResult<PermissionRead>, Error, ListApiResult<PermissionRead>, string[]>, "queryFn"> & {
|
|
49
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<ListApiResult<PermissionRead>, string[], never> | undefined;
|
|
50
|
+
} & {
|
|
51
|
+
queryKey: string[] & {
|
|
52
|
+
[dataTagSymbol]: ListApiResult<PermissionRead>;
|
|
53
|
+
[dataTagErrorSymbol]: Error;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807.
|
|
3
|
+
*/
|
|
4
|
+
export interface ProblemDetails {
|
|
5
|
+
type?: string | null;
|
|
6
|
+
title?: string | null;
|
|
7
|
+
status?: number | null;
|
|
8
|
+
detail?: string | null;
|
|
9
|
+
instance?: string | null;
|
|
10
|
+
errors?: Record<string, Array<string>>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns whether the given object is a {@link ProblemDetails} object.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isProblemDetails(obj: unknown): obj is ProblemDetails;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Permission } from './permissions';
|
|
2
|
+
/**
|
|
3
|
+
* Provides information about the current user session.
|
|
4
|
+
*/
|
|
5
|
+
export interface SessionRead {
|
|
6
|
+
/**
|
|
7
|
+
* The identifier of the user associated with the current session.
|
|
8
|
+
*/
|
|
9
|
+
userId: string;
|
|
10
|
+
/**
|
|
11
|
+
* All permissions associated with the session's user.
|
|
12
|
+
*/
|
|
13
|
+
permissions: Array<Permission>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Represents the current session state, i.e., whether the user has an active session or not.
|
|
17
|
+
*/
|
|
18
|
+
export type SessionState = {
|
|
19
|
+
hasSession: false;
|
|
20
|
+
session: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
hasSession: true;
|
|
23
|
+
session: SessionRead;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Calls `GET /api/v1/auth/session` and extracts the current {@link SessionState} from the response.
|
|
27
|
+
* Throws for any errors other than `401 Unauthorized`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readSessionState(): Promise<SessionState>;
|
|
30
|
+
/** {@link readSessionState} */
|
|
31
|
+
export declare function readSessionStateQuery(): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<SessionState, Error, SessionState, string[]>, "queryFn"> & {
|
|
32
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<SessionState, string[], never> | undefined;
|
|
33
|
+
} & {
|
|
34
|
+
queryKey: string[] & {
|
|
35
|
+
[dataTagSymbol]: SessionState;
|
|
36
|
+
[dataTagErrorSymbol]: Error;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the possible sort directions for sorting operations.
|
|
3
|
+
*/
|
|
4
|
+
export type SortDirection = 'Ascending' | 'Descending';
|
|
5
|
+
/**
|
|
6
|
+
* Defines options for sorting items.
|
|
7
|
+
*/
|
|
8
|
+
export interface SortOptions<TKey extends string> {
|
|
9
|
+
/**
|
|
10
|
+
* The key to sort by.
|
|
11
|
+
*/
|
|
12
|
+
sortBy?: TKey | null;
|
|
13
|
+
/**
|
|
14
|
+
* The direction of the sort operation.
|
|
15
|
+
*/
|
|
16
|
+
sortDirection?: SortDirection | null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Permission } from './permissions';
|
|
2
|
+
import { ApiResult } from './apiResults';
|
|
3
|
+
export type StatusVersion = `${number}.${number}.${number}`;
|
|
4
|
+
/**
|
|
5
|
+
* Provides status information about the service.
|
|
6
|
+
*/
|
|
7
|
+
export interface StatusRead {
|
|
8
|
+
/**
|
|
9
|
+
* The service version.
|
|
10
|
+
*/
|
|
11
|
+
version: StatusVersion;
|
|
12
|
+
/**
|
|
13
|
+
* All known permissions.
|
|
14
|
+
*/
|
|
15
|
+
permissions: Array<Permission>;
|
|
16
|
+
}
|
|
17
|
+
/** `GET api/v1/status` */
|
|
18
|
+
export declare function readStatus(): Promise<ApiResult<StatusRead>>;
|
|
19
|
+
/** {@link readStatus} */
|
|
20
|
+
export declare function readStatusQuery(): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<ApiResult<StatusRead>, Error, ApiResult<StatusRead>, string[]>, "queryFn"> & {
|
|
21
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<ApiResult<StatusRead>, string[], never> | undefined;
|
|
22
|
+
} & {
|
|
23
|
+
queryKey: string[] & {
|
|
24
|
+
[dataTagSymbol]: ApiResult<StatusRead>;
|
|
25
|
+
[dataTagErrorSymbol]: Error;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppInstance } from './types';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
export interface AppProps extends PropsWithChildren {
|
|
4
|
+
/**
|
|
5
|
+
* The application instance to be rendered.
|
|
6
|
+
*/
|
|
7
|
+
app: AppInstance;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The main application component, rendering an application and its configured modules.
|
|
11
|
+
*/
|
|
12
|
+
export declare function App({ app, children }: AppProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppInstance, Module, ModuleInit } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an {@link AppInstance} based on the provided configuration.
|
|
4
|
+
* {@link AppInstance} objects provide the app's central orchestration API.
|
|
5
|
+
* @param modules The modules making up the application.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createApp(modules: Array<Module>): AppInstance;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a fully configured {@link Module} based on the given {@link ModuleInit}.
|
|
10
|
+
* @param moduleInit The configuration with which to initialize the module.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createModule(moduleInit: ModuleInit): Module;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ExtensionName, ExtensionParams } from './types';
|
|
3
|
+
export interface ExtensionProps<TName extends ExtensionName | (string & {})> {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the extension to render.
|
|
6
|
+
*/
|
|
7
|
+
name: TName;
|
|
8
|
+
/**
|
|
9
|
+
* The parameters to be forwarded to the extension component.
|
|
10
|
+
*/
|
|
11
|
+
params: TName extends ExtensionName ? ExtensionParams<TName> : Record<string, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* An optional fallback to render if:
|
|
14
|
+
* - there is no extension with the given name.
|
|
15
|
+
* - no {@link loadingFallback} is provided and the extension is loading.
|
|
16
|
+
* - no {@link errorFallback} is provided and the extension errored.
|
|
17
|
+
*/
|
|
18
|
+
fallback?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* An optional fallback to render while the extension is being lazy-loaded.
|
|
21
|
+
*/
|
|
22
|
+
loadingFallback?: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* An optional fallback to render if an error is caught while rendering the extension.
|
|
25
|
+
*/
|
|
26
|
+
errorFallback?: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Renders registered extension componentsmatching the given name.
|
|
30
|
+
* If no such extension components are known, renders a fallback.
|
|
31
|
+
*/
|
|
32
|
+
export declare function Extension<Name extends ExtensionName | (string & {})>({ name, params, fallback, loadingFallback, errorFallback, }: ExtensionProps<Name>): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Maps extension keys to their corresponding component props.
|
|
4
|
+
* This interface can be extended by modules via declaration merging.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* declare module '@tiny-server/core' {
|
|
8
|
+
* export interface ExtensionParamsMap {
|
|
9
|
+
* 'my-extension': MyExtensionProps;
|
|
10
|
+
* }
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface ExtensionParamsMap {
|
|
15
|
+
'': never;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Defines all known extension names.
|
|
19
|
+
*/
|
|
20
|
+
export type ExtensionName = keyof ExtensionParamsMap;
|
|
21
|
+
/**
|
|
22
|
+
* The parameters of the extension with the given `TName`.
|
|
23
|
+
*/
|
|
24
|
+
export type ExtensionParams<TName extends ExtensionName> = ExtensionParamsMap[TName];
|
|
25
|
+
export interface ExtensionComponentProps<TName extends ExtensionName> {
|
|
26
|
+
/**
|
|
27
|
+
* The parameters to be forwarded to the extension component.
|
|
28
|
+
*/
|
|
29
|
+
params: ExtensionParams<TName>;
|
|
30
|
+
}
|
|
31
|
+
export interface ExtensionRegistration<TName extends ExtensionName> {
|
|
32
|
+
/**
|
|
33
|
+
* The name of the extension to be registered.
|
|
34
|
+
*/
|
|
35
|
+
name: TName;
|
|
36
|
+
/**
|
|
37
|
+
* The component to be rendered for the extension.
|
|
38
|
+
*/
|
|
39
|
+
component: ComponentType<ExtensionComponentProps<TName>>;
|
|
40
|
+
}
|
|
41
|
+
export type AnyExtensionRegistration = {
|
|
42
|
+
[Key in ExtensionName]: ExtensionRegistration<Key>;
|
|
43
|
+
}[ExtensionName];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ErrorKindMap {
|
|
2
|
+
unknown: '';
|
|
3
|
+
app: '';
|
|
4
|
+
route: '';
|
|
5
|
+
['route-not-found']: '';
|
|
6
|
+
['route-forbidden']: '';
|
|
7
|
+
extension: '';
|
|
8
|
+
menu: '';
|
|
9
|
+
modal: '';
|
|
10
|
+
}
|
|
11
|
+
export type ErrorKind = keyof ErrorKindMap;
|
|
12
|
+
export interface ErrorProps {
|
|
13
|
+
kind: ErrorKind;
|
|
14
|
+
}
|
|
15
|
+
export declare function DefaultError({ kind }: ErrorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface LoadingKindMap {
|
|
2
|
+
unknown: '';
|
|
3
|
+
app: '';
|
|
4
|
+
route: '';
|
|
5
|
+
page: '';
|
|
6
|
+
extension: '';
|
|
7
|
+
menu: '';
|
|
8
|
+
modal: '';
|
|
9
|
+
}
|
|
10
|
+
export type LoadingKind = keyof LoadingKindMap;
|
|
11
|
+
export interface LoadingProps {
|
|
12
|
+
kind: LoadingKind;
|
|
13
|
+
}
|
|
14
|
+
export declare function DefaultLoading(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
export interface PageProps extends PropsWithChildren {
|
|
3
|
+
header?: ReactNode;
|
|
4
|
+
actions?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare function DefaultPage({ header, actions, children }: PageProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { ErrorProps } from './Error';
|
|
3
|
+
import { LayoutProps } from './Layout';
|
|
4
|
+
import { LoadingProps } from './Loading';
|
|
5
|
+
import { PageProps } from './Page';
|
|
6
|
+
declare module '../../types' {
|
|
7
|
+
interface AppComponents {
|
|
8
|
+
Error: ComponentType<ErrorProps>;
|
|
9
|
+
Layout: ComponentType<LayoutProps>;
|
|
10
|
+
Loading: ComponentType<LoadingProps>;
|
|
11
|
+
Page: ComponentType<PageProps>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MenuComponentProps, MenuType } from './types';
|
|
2
|
+
export interface MenuProps<TMenuType extends MenuType = MenuType> extends MenuComponentProps<TMenuType> {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Renders the menu of the given type.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Menu({ type, params }: MenuProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MenuComponentProps, MenuType } from '.';
|
|
2
|
+
export interface MenuContainerProps<TMenuType extends MenuType = MenuType> extends MenuComponentProps<TMenuType> {
|
|
3
|
+
}
|
|
4
|
+
export declare function DefaultMenuContainer<TMenuType extends MenuType = MenuType>({ children, }: MenuContainerProps<TMenuType>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { MenuItemComponentProps, MenuType } from '../../..';
|
|
3
|
+
export interface MenuItemProps<TMenuType extends MenuType = MenuType> extends MenuItemComponentProps<TMenuType> {
|
|
4
|
+
label?: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
leftSection?: ReactNode;
|
|
7
|
+
rightSection?: ReactNode;
|
|
8
|
+
to?: string;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function DefaultMenuItem<TMenuType extends MenuType = MenuType>({ id, label, description, leftSection, rightSection, to, onClick, children, }: MenuItemProps<TMenuType>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ComponentType, PropsWithChildren } from 'react';
|
|
2
|
+
import { MenuContainerProps } from './MenuContainer';
|
|
3
|
+
import { MenuItemProps } from './MenuItem';
|
|
4
|
+
declare module '../../types' {
|
|
5
|
+
interface AppComponents {
|
|
6
|
+
MenuContainer: ComponentType<MenuContainerProps>;
|
|
7
|
+
MenuItem: ComponentType<MenuItemProps>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A map of all known menus.
|
|
12
|
+
* This interface can be extended by modules via declaration merging.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* declare module '@tiny-server/core' {
|
|
16
|
+
* export interface MenuParamsMap {
|
|
17
|
+
* 'my-menu': MyMenuParams;
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface MenuParamsMap {
|
|
23
|
+
default: {};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Defines all known menu types.
|
|
27
|
+
*/
|
|
28
|
+
export type MenuType = keyof MenuParamsMap;
|
|
29
|
+
/**
|
|
30
|
+
* The parameters of the menu with the given `TType`.
|
|
31
|
+
*/
|
|
32
|
+
export type MenuParams<TType extends MenuType> = MenuParamsMap[TType];
|
|
33
|
+
export interface MenuComponentProps<TMenuType extends MenuType = MenuType> extends PropsWithChildren {
|
|
34
|
+
/**
|
|
35
|
+
* The type of the menu that the item belongs to.
|
|
36
|
+
*/
|
|
37
|
+
type: TMenuType;
|
|
38
|
+
/**
|
|
39
|
+
* The parameters to be forwarded to the menu item component.
|
|
40
|
+
*/
|
|
41
|
+
params: MenuParams<TMenuType>;
|
|
42
|
+
}
|
|
43
|
+
export interface MenuItemComponentProps<TMenuType extends MenuType = MenuType> extends MenuComponentProps<TMenuType> {
|
|
44
|
+
/**
|
|
45
|
+
* The unique identifier of the menu item.
|
|
46
|
+
*/
|
|
47
|
+
id: string;
|
|
48
|
+
}
|
|
49
|
+
export interface MenuItemRegistration<TMenuType extends MenuType> {
|
|
50
|
+
/**
|
|
51
|
+
* A unique identifier for the menu item.
|
|
52
|
+
*/
|
|
53
|
+
id: string;
|
|
54
|
+
/**
|
|
55
|
+
* The unique identifier of the parent menu item.
|
|
56
|
+
* Must reference an existing parent menu item within the same menu.
|
|
57
|
+
* If no parent is found, the child is not rendered.
|
|
58
|
+
*/
|
|
59
|
+
parentId?: string;
|
|
60
|
+
/**
|
|
61
|
+
* The menu that the item belongs to.
|
|
62
|
+
*/
|
|
63
|
+
menu: TMenuType;
|
|
64
|
+
/**
|
|
65
|
+
* The component to be rendered for the menu item.
|
|
66
|
+
*/
|
|
67
|
+
component: ComponentType<MenuItemComponentProps<TMenuType>>;
|
|
68
|
+
}
|
|
69
|
+
export type AnyMenuItemRegistration = {
|
|
70
|
+
[TMenuType in MenuType]: MenuItemRegistration<TMenuType>;
|
|
71
|
+
}[MenuType];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ModalComponentProps, ModalName, ModalOptions } from '.';
|
|
2
|
+
export interface ModalProps<TModalName extends ModalName = ModalName> extends ModalComponentProps<TModalName> {
|
|
3
|
+
options?: ModalOptions;
|
|
4
|
+
}
|
|
5
|
+
export declare function DefaultModal({ name, params, options, onClose }: ModalProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ModalComponentProps, ModalName } from './types';
|
|
2
|
+
export interface ModalContentProps<TModalName extends ModalName = ModalName> extends ModalComponentProps<TModalName> {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Renders registered modal content.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ModalContent({ name, params, onClose }: ModalContentProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
export interface ModalFooterProps extends PropsWithChildren {
|
|
3
|
+
actions?: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare function DefaultModalFooter({ children, actions }: ModalFooterProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModalName, ModalParams } from './types';
|
|
2
|
+
interface OpenModal<TModalName extends ModalName = ModalName> {
|
|
3
|
+
id: string;
|
|
4
|
+
name: TModalName;
|
|
5
|
+
params: ModalParams<TModalName>;
|
|
6
|
+
}
|
|
7
|
+
interface ModalsStore {
|
|
8
|
+
_lastId: number;
|
|
9
|
+
modals: Array<OpenModal>;
|
|
10
|
+
openModal<TModalName extends ModalName>(name: TModalName, params: ModalParams<TModalName>): string;
|
|
11
|
+
closeModal(id: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const modalsStore: import('zustand').StoreApi<ModalsStore>;
|
|
14
|
+
export {};
|