@thepassle/app-tools 0.7.3 → 0.7.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/api/types.d.ts +41 -0
- package/dialog/types.d.ts +15 -0
- package/package.json +2 -1
- package/router/index.js +3 -1
- package/router/plugins/data.js +5 -1
- package/router/types.d.ts +36 -0
package/api/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type ResponseType = 'text'|'json'|'stream'|'blob'|'arrayBuffer'|'formData'|'stream';
|
|
2
|
+
|
|
3
|
+
export interface Config {
|
|
4
|
+
plugins?: Plugin[];
|
|
5
|
+
responseType?: ResponseType;
|
|
6
|
+
baseURL?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type BodyMethod<R> = (url: string, data?: object, opts?: RequestOptions) => Promise<R>;
|
|
10
|
+
export type BodylessMethod<R> = (url: string, opts?: RequestOptions) => Promise<R>;
|
|
11
|
+
|
|
12
|
+
export type Method = 'GET'|'DELETE'|'HEAD'|'OPTIONS'|'POST'|'PUT'|'PATCH';
|
|
13
|
+
|
|
14
|
+
export interface Plugin {
|
|
15
|
+
beforeFetch?: (meta: MetaParams) => MetaParams | Promise<MetaParams> | void;
|
|
16
|
+
afterFetch?: (res: Response) => Response | Promise<Response>;
|
|
17
|
+
transform?: (data: any) => any;
|
|
18
|
+
name: string;
|
|
19
|
+
handleError?: (e: Error) => boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CustomRequestOptions {
|
|
23
|
+
transform?: (data: object) => object;
|
|
24
|
+
responseType?: ResponseType;
|
|
25
|
+
params?: Record<string, string>;
|
|
26
|
+
plugins?: Plugin[];
|
|
27
|
+
baseURL?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type RequestOptions = RequestInit & CustomRequestOptions;
|
|
31
|
+
|
|
32
|
+
export interface MetaParams {
|
|
33
|
+
responseType: string;
|
|
34
|
+
baseURL: string;
|
|
35
|
+
url: string;
|
|
36
|
+
method: Method;
|
|
37
|
+
headers: Headers;
|
|
38
|
+
opts?: RequestOptions;
|
|
39
|
+
data?: any;
|
|
40
|
+
fetchFn: typeof globalThis.fetch;
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type DialogNode = HTMLDialogElement & { form: HTMLFormElement };
|
|
2
|
+
|
|
3
|
+
export interface DialogCallbacks {
|
|
4
|
+
opening?: <Parameters>(opts: {dialog: DialogNode, parameters: Parameters}) => void;
|
|
5
|
+
opened?: <Parameters>(opts: {dialog: DialogNode, parameters: Parameters}) => void;
|
|
6
|
+
closing?: (opts: {dialog: DialogNode}) => void;
|
|
7
|
+
closed?: (opts: {dialog: DialogNode}) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type Config = Record<string, DialogCallbacks>;
|
|
11
|
+
|
|
12
|
+
export interface OpenDialogOptions {
|
|
13
|
+
id: string;
|
|
14
|
+
parameters?: object;
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thepassle/app-tools",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
|
+
"./**/*.d.ts",
|
|
40
41
|
"./env.js",
|
|
41
42
|
"./pwa.js",
|
|
42
43
|
"./dialog.js",
|
package/router/index.js
CHANGED
|
@@ -24,7 +24,8 @@ export class Router extends EventTarget {
|
|
|
24
24
|
params: {},
|
|
25
25
|
query: {},
|
|
26
26
|
title: '',
|
|
27
|
-
url: new URL(window.location.href)
|
|
27
|
+
url: new URL(window.location.href),
|
|
28
|
+
dispatch: this._notifyUrlChanged.bind(this)
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -93,6 +94,7 @@ export class Router extends EventTarget {
|
|
|
93
94
|
title: typeof title === 'function' ? title({params, query, url}) : title,
|
|
94
95
|
params,
|
|
95
96
|
query,
|
|
97
|
+
dispatch: this._notifyUrlChanged.bind(this)
|
|
96
98
|
}
|
|
97
99
|
return route;
|
|
98
100
|
}
|
package/router/plugins/data.js
CHANGED
|
@@ -6,7 +6,11 @@ export function data(promise){
|
|
|
6
6
|
return {
|
|
7
7
|
name: 'data',
|
|
8
8
|
beforeNavigation: async (context) => {
|
|
9
|
-
const data =
|
|
9
|
+
const data = promise(context).then((data) => {
|
|
10
|
+
context.data = data;
|
|
11
|
+
context.dispatch();
|
|
12
|
+
return data;
|
|
13
|
+
});
|
|
10
14
|
context.data = data;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
fallback?: string;
|
|
3
|
+
plugins?: Plugin[];
|
|
4
|
+
routes: RouteDefinition[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Plugin {
|
|
8
|
+
name: string;
|
|
9
|
+
shouldNavigate?: (context: Context) => {
|
|
10
|
+
redirect: string,
|
|
11
|
+
condition: () => boolean | (() => Promise<Boolean>),
|
|
12
|
+
};
|
|
13
|
+
beforeNavigation?: (context: Context) => void;
|
|
14
|
+
afterNavigation?: (context: Context) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Context {
|
|
18
|
+
title?: string;
|
|
19
|
+
query: object;
|
|
20
|
+
params: object;
|
|
21
|
+
url: URL;
|
|
22
|
+
dispatch: () => void;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type Render<RenderResult> = (context: Context) => RenderResult;
|
|
27
|
+
|
|
28
|
+
export interface RouteDefinition {
|
|
29
|
+
path: string;
|
|
30
|
+
title: string | ((context: Partial<Context>) => string);
|
|
31
|
+
render?: Render<RenderResult>;
|
|
32
|
+
plugins?: Plugin[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @TODO URLPattern type */
|
|
36
|
+
export type Route = RouteDefinition & { urlPattern?: any };
|