@cedx/base 0.1.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/License.md +20 -0
- package/ReadMe.md +21 -0
- package/lib/Abstractions/ILoadingIndicator.d.ts +17 -0
- package/lib/Abstractions/ILoadingIndicator.d.ts.map +1 -0
- package/lib/Abstractions/ILoadingIndicator.js +1 -0
- package/lib/DependencyInjection/Container.d.ts +43 -0
- package/lib/DependencyInjection/Container.d.ts.map +1 -0
- package/lib/DependencyInjection/Container.js +65 -0
- package/lib/Html/AppTheme.d.ts +34 -0
- package/lib/Html/AppTheme.d.ts.map +1 -0
- package/lib/Html/AppTheme.js +41 -0
- package/lib/Html/MenuAlignment.d.ts +18 -0
- package/lib/Html/MenuAlignment.d.ts.map +1 -0
- package/lib/Html/MenuAlignment.js +13 -0
- package/lib/Html/ViewportScroller.d.ts +49 -0
- package/lib/Html/ViewportScroller.d.ts.map +1 -0
- package/lib/Html/ViewportScroller.js +69 -0
- package/lib/Http/HttpClient.d.ts +68 -0
- package/lib/Http/HttpClient.d.ts.map +1 -0
- package/lib/Http/HttpClient.js +102 -0
- package/lib/Http/HttpError.d.ts +33 -0
- package/lib/Http/HttpError.d.ts.map +1 -0
- package/lib/Http/HttpError.js +66 -0
- package/lib/Http/StatusCodes.d.ts +114 -0
- package/lib/Http/StatusCodes.d.ts.map +1 -0
- package/lib/Http/StatusCodes.js +109 -0
- package/lib/Number.d.ts +8 -0
- package/lib/Number.d.ts.map +1 -0
- package/lib/Number.js +10 -0
- package/lib/UI/LoadingIndicator.d.ts +40 -0
- package/lib/UI/LoadingIndicator.d.ts.map +1 -0
- package/lib/UI/LoadingIndicator.js +50 -0
- package/lib/UI/OfflineIndicator.d.ts +39 -0
- package/lib/UI/OfflineIndicator.d.ts.map +1 -0
- package/lib/UI/OfflineIndicator.js +48 -0
- package/lib/UI/ThemeDropdown.d.ts +68 -0
- package/lib/UI/ThemeDropdown.d.ts.map +1 -0
- package/lib/UI/ThemeDropdown.js +123 -0
- package/package.json +59 -0
- package/src/Client/Abstractions/ILoadingIndicator.ts +16 -0
- package/src/Client/Abstractions/tsconfig.json +13 -0
- package/src/Client/Base/tsconfig.json +13 -0
- package/src/Client/DependencyInjection/Container.ts +75 -0
- package/src/Client/DependencyInjection/tsconfig.json +13 -0
- package/src/Client/Html/AppTheme.ts +51 -0
- package/src/Client/Html/MenuAlignment.ts +20 -0
- package/src/Client/Html/ViewportScroller.ts +89 -0
- package/src/Client/Html/tsconfig.json +13 -0
- package/src/Client/Http/HttpClient.ts +127 -0
- package/src/Client/Http/HttpError.ts +75 -0
- package/src/Client/Http/StatusCodes.ts +140 -0
- package/src/Client/Http/tsconfig.json +16 -0
- package/src/Client/Number.ts +10 -0
- package/src/Client/UI/LoadingIndicator.ts +66 -0
- package/src/Client/UI/OfflineIndicator.ts +61 -0
- package/src/Client/UI/ThemeDropdown.ts +134 -0
- package/src/Client/UI/tsconfig.json +19 -0
- package/src/Client/tsconfig.json +11 -0
package/License.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
Copyright © Cédric Belin
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/ReadMe.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Belin.io Base
|
|
2
|
+
   
|
|
3
|
+
   
|
|
4
|
+
|
|
5
|
+
Base library by [Cédric Belin](https://belin.io), full stack developer,
|
|
6
|
+
implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
|
|
7
|
+
|
|
8
|
+
> This library is dedicated to personal/side projects.
|
|
9
|
+
> **Use at your own risk!** No support will be provided.
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
- [User guide](https://github.com/cedx/base/wiki)
|
|
13
|
+
- [API reference](https://cedx.github.io/base)
|
|
14
|
+
- [Examples](https://github.com/cedx/base/tree/main/example)
|
|
15
|
+
|
|
16
|
+
## Development
|
|
17
|
+
- [Git repository](https://github.com/cedx/base)
|
|
18
|
+
- [Submit an issue](https://github.com/cedx/base/issues)
|
|
19
|
+
|
|
20
|
+
## Licence
|
|
21
|
+
[Belin.io Base](https://github.com/cedx/base) is distributed under the MIT License.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A component that shows up when an HTTP request starts, and hides when all concurrent HTTP requests are completed.
|
|
3
|
+
*/
|
|
4
|
+
export interface ILoadingIndicator {
|
|
5
|
+
/**
|
|
6
|
+
* Starts the loading indicator.
|
|
7
|
+
*/
|
|
8
|
+
start: () => void;
|
|
9
|
+
/**
|
|
10
|
+
* Stops the loading indicator.
|
|
11
|
+
* @param options Value indicating whether to force the loading indicator to stop.
|
|
12
|
+
*/
|
|
13
|
+
stop: (options?: {
|
|
14
|
+
force?: boolean;
|
|
15
|
+
}) => void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ILoadingIndicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoadingIndicator.d.ts","sourceRoot":"","sources":["../../src/Client/Abstractions/ILoadingIndicator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAEjC;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAElB;;;OAGG;IACH,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAC,KAAK,IAAI,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides a dependency container.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Container {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Removes the service registered with the specified identifier.
|
|
8
|
+
* @param id The identification token.
|
|
9
|
+
*/
|
|
10
|
+
delete(id: ContainerToken): void;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the service registered with the specified identifier.
|
|
13
|
+
* @param id The identification token.
|
|
14
|
+
* @returns The instance of the service registered with the specified identifier.
|
|
15
|
+
* @throws `Error` if there is no factory registered with the specified identifier.
|
|
16
|
+
*/
|
|
17
|
+
get<T>(id: ContainerToken): T;
|
|
18
|
+
/**
|
|
19
|
+
* Gets a value indicating whether this container has a service registered with the specified identifier.
|
|
20
|
+
* @param id The identification token.
|
|
21
|
+
* @returns `true` if a service registered with the specified identifier exists in this container, otherwise `false`.
|
|
22
|
+
*/
|
|
23
|
+
has(id: ContainerToken): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Registers a service factory with this container.
|
|
26
|
+
* @param id The identification token.
|
|
27
|
+
* @param factory The service factory.
|
|
28
|
+
* @returns This instance.
|
|
29
|
+
*/
|
|
30
|
+
register(id: ContainerToken, factory: () => unknown): this;
|
|
31
|
+
/**
|
|
32
|
+
* Registers a service instance with this container.
|
|
33
|
+
* @param id The identification token.
|
|
34
|
+
* @param service The service instance.
|
|
35
|
+
* @returns This instance.
|
|
36
|
+
*/
|
|
37
|
+
set(id: ContainerToken, service: unknown): this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A token identifying a service.
|
|
41
|
+
*/
|
|
42
|
+
export type ContainerToken = string | symbol | (new (...args: any[]) => any);
|
|
43
|
+
//# sourceMappingURL=Container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../src/Client/DependencyInjection/Container.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAS;;IAYrB;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,IAAI;IAKhC;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,cAAc,GAAG,CAAC;IAS7B;;;;OAIG;IACH,GAAG,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO;IAIhC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI;IAK1D;;;;;OAKG;IACH,GAAG,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;CAI/C;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAC,MAAM,GAAC,CAAC,KAAI,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides a dependency container.
|
|
3
|
+
*/
|
|
4
|
+
export class Container {
|
|
5
|
+
/**
|
|
6
|
+
* The registered factories.
|
|
7
|
+
*/
|
|
8
|
+
#factories = new Map;
|
|
9
|
+
/**
|
|
10
|
+
* The registered services.
|
|
11
|
+
*/
|
|
12
|
+
#services = new Map;
|
|
13
|
+
/**
|
|
14
|
+
* Removes the service registered with the specified identifier.
|
|
15
|
+
* @param id The identification token.
|
|
16
|
+
*/
|
|
17
|
+
delete(id) {
|
|
18
|
+
this.#factories.delete(id);
|
|
19
|
+
this.#services.delete(id);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets the service registered with the specified identifier.
|
|
23
|
+
* @param id The identification token.
|
|
24
|
+
* @returns The instance of the service registered with the specified identifier.
|
|
25
|
+
* @throws `Error` if there is no factory registered with the specified identifier.
|
|
26
|
+
*/
|
|
27
|
+
get(id) {
|
|
28
|
+
if (!this.#services.has(id))
|
|
29
|
+
if (this.#factories.has(id))
|
|
30
|
+
this.set(id, this.#factories.get(id)());
|
|
31
|
+
else if (typeof id == "function")
|
|
32
|
+
this.set(id, Reflect.construct(id, []));
|
|
33
|
+
else
|
|
34
|
+
throw Error("There is no factory registered with the specified identifier.");
|
|
35
|
+
return this.#services.get(id);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets a value indicating whether this container has a service registered with the specified identifier.
|
|
39
|
+
* @param id The identification token.
|
|
40
|
+
* @returns `true` if a service registered with the specified identifier exists in this container, otherwise `false`.
|
|
41
|
+
*/
|
|
42
|
+
has(id) {
|
|
43
|
+
return this.#factories.has(id) || this.#services.has(id);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Registers a service factory with this container.
|
|
47
|
+
* @param id The identification token.
|
|
48
|
+
* @param factory The service factory.
|
|
49
|
+
* @returns This instance.
|
|
50
|
+
*/
|
|
51
|
+
register(id, factory) {
|
|
52
|
+
this.#factories.set(id, factory);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Registers a service instance with this container.
|
|
57
|
+
* @param id The identification token.
|
|
58
|
+
* @param service The service instance.
|
|
59
|
+
* @returns This instance.
|
|
60
|
+
*/
|
|
61
|
+
set(id, service) {
|
|
62
|
+
this.#services.set(id, service);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumerates different themes an operating system or application can show.
|
|
3
|
+
*/
|
|
4
|
+
export declare const AppTheme: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* The system predefined theme mode.
|
|
7
|
+
*/
|
|
8
|
+
System: "System";
|
|
9
|
+
/**
|
|
10
|
+
* The light predefined theme mode.
|
|
11
|
+
*/
|
|
12
|
+
Light: "Light";
|
|
13
|
+
/**
|
|
14
|
+
* The dark predefined theme mode.
|
|
15
|
+
*/
|
|
16
|
+
Dark: "Dark";
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Enumerates different themes an operating system or application can show.
|
|
20
|
+
*/
|
|
21
|
+
export type AppTheme = typeof AppTheme[keyof typeof AppTheme];
|
|
22
|
+
/**
|
|
23
|
+
* Gets the icon corresponding to the specified theme.
|
|
24
|
+
* @param theme The theme mode.
|
|
25
|
+
* @returns The icon corresponding to the specified theme.
|
|
26
|
+
*/
|
|
27
|
+
export declare function themeIcon(theme: AppTheme): string;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the label corresponding to the specified theme.
|
|
30
|
+
* @param theme The theme mode.
|
|
31
|
+
* @returns The label corresponding to the specified theme.
|
|
32
|
+
*/
|
|
33
|
+
export declare function themeLabel(theme: AppTheme): string;
|
|
34
|
+
//# sourceMappingURL=AppTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppTheme.d.ts","sourceRoot":"","sources":["../../src/Client/Html/AppTheme.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAMjD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAMlD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumerates different themes an operating system or application can show.
|
|
3
|
+
*/
|
|
4
|
+
export const AppTheme = Object.freeze({
|
|
5
|
+
/**
|
|
6
|
+
* The system predefined theme mode.
|
|
7
|
+
*/
|
|
8
|
+
System: "System",
|
|
9
|
+
/**
|
|
10
|
+
* The light predefined theme mode.
|
|
11
|
+
*/
|
|
12
|
+
Light: "Light",
|
|
13
|
+
/**
|
|
14
|
+
* The dark predefined theme mode.
|
|
15
|
+
*/
|
|
16
|
+
Dark: "Dark"
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Gets the icon corresponding to the specified theme.
|
|
20
|
+
* @param theme The theme mode.
|
|
21
|
+
* @returns The icon corresponding to the specified theme.
|
|
22
|
+
*/
|
|
23
|
+
export function themeIcon(theme) {
|
|
24
|
+
switch (theme) {
|
|
25
|
+
case AppTheme.Dark: return "dark_mode";
|
|
26
|
+
case AppTheme.Light: return "light_mode";
|
|
27
|
+
default: return "contrast";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the label corresponding to the specified theme.
|
|
32
|
+
* @param theme The theme mode.
|
|
33
|
+
* @returns The label corresponding to the specified theme.
|
|
34
|
+
*/
|
|
35
|
+
export function themeLabel(theme) {
|
|
36
|
+
switch (theme) {
|
|
37
|
+
case AppTheme.Dark: return "Sombre";
|
|
38
|
+
case AppTheme.Light: return "Clair";
|
|
39
|
+
default: return "Auto";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the alignment of a dropdown menu.
|
|
3
|
+
*/
|
|
4
|
+
export declare const MenuAlignment: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* The dropdown menu is right aligned.
|
|
7
|
+
*/
|
|
8
|
+
End: "End";
|
|
9
|
+
/**
|
|
10
|
+
* The dropdown menu is left aligned.
|
|
11
|
+
*/
|
|
12
|
+
Start: "Start";
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Defines the alignment of a dropdown menu.
|
|
16
|
+
*/
|
|
17
|
+
export type MenuAlignment = typeof MenuAlignment[keyof typeof MenuAlignment];
|
|
18
|
+
//# sourceMappingURL=MenuAlignment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MenuAlignment.d.ts","sourceRoot":"","sources":["../../src/Client/Html/MenuAlignment.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,aAAa;IAEzB;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the scrolling options.
|
|
3
|
+
*/
|
|
4
|
+
export type ScrollOptions = Partial<{
|
|
5
|
+
/**
|
|
6
|
+
* Value indicating whether scrolling is instant or animates smoothly.
|
|
7
|
+
*/
|
|
8
|
+
behavior: ScrollBehavior;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Manages the scroll position.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ViewportScroller {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new viewport scroller.
|
|
17
|
+
* @param viewport A function that returns the element used as viewport.
|
|
18
|
+
*/
|
|
19
|
+
constructor(viewport?: () => Element);
|
|
20
|
+
/**
|
|
21
|
+
* The top offset used when scrolling to an element.
|
|
22
|
+
*/
|
|
23
|
+
get scrollOffset(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Scrolls to the specified anchor.
|
|
26
|
+
* @param anchor The identifier or name of an elment.
|
|
27
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
28
|
+
*/
|
|
29
|
+
scrollToAnchor(anchor: string, options?: ScrollOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Scrolls to the specified element.
|
|
32
|
+
* @param element The element to scroll to.
|
|
33
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
34
|
+
*/
|
|
35
|
+
scrollToElement(element: Element, options?: ScrollOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Scrolls to the specified position.
|
|
38
|
+
* @param x The pixel along the horizontal axis.
|
|
39
|
+
* @param y The pixel along the vertical axis.
|
|
40
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
41
|
+
*/
|
|
42
|
+
scrollToPosition(x: number, y: number, options?: ScrollOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Scrolls to the top.
|
|
45
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
46
|
+
*/
|
|
47
|
+
scrollToTop(options?: ScrollOptions): void;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ViewportScroller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewportScroller.d.ts","sourceRoot":"","sources":["../../src/Client/Html/ViewportScroller.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC;IAEnC;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAA;CACxB,CAAC,CAAC;AAEH;;GAEG;AACH,qBAAa,gBAAgB;;IAY5B;;;OAGG;gBACS,QAAQ,GAAE,MAAM,OAAqE;IAIjG;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAWzB;IAED;;;;OAIG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAKjE;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAMpE;;;;;OAKG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAIzE;;;OAGG;IACH,WAAW,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;CAG9C"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the scroll position.
|
|
3
|
+
*/
|
|
4
|
+
export class ViewportScroller {
|
|
5
|
+
/**
|
|
6
|
+
* The top offset used when scrolling to an element.
|
|
7
|
+
*/
|
|
8
|
+
#scrollOffset = -1;
|
|
9
|
+
/**
|
|
10
|
+
* The function returning the element used as viewport.
|
|
11
|
+
*/
|
|
12
|
+
#viewport;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new viewport scroller.
|
|
15
|
+
* @param viewport A function that returns the element used as viewport.
|
|
16
|
+
*/
|
|
17
|
+
constructor(viewport = () => document.scrollingElement ?? document.documentElement) {
|
|
18
|
+
this.#viewport = viewport;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The top offset used when scrolling to an element.
|
|
22
|
+
*/
|
|
23
|
+
get scrollOffset() {
|
|
24
|
+
if (this.#scrollOffset < 0) {
|
|
25
|
+
const fontSize = parseInt(getComputedStyle(document.body).fontSize);
|
|
26
|
+
this.#scrollOffset = Number.isNaN(fontSize) ? 0 : fontSize * 2;
|
|
27
|
+
const navbarHeight = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--navbar-height"));
|
|
28
|
+
this.#scrollOffset += Number.isNaN(navbarHeight) ? 0 : navbarHeight;
|
|
29
|
+
}
|
|
30
|
+
const actionBar = document.body.querySelector("action-bar");
|
|
31
|
+
return this.#scrollOffset + (actionBar?.offsetHeight ?? 0);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Scrolls to the specified anchor.
|
|
35
|
+
* @param anchor The identifier or name of an elment.
|
|
36
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
37
|
+
*/
|
|
38
|
+
scrollToAnchor(anchor, options = {}) {
|
|
39
|
+
const element = document.getElementById(anchor) ?? document.body.querySelector(`[name="${anchor}"]`);
|
|
40
|
+
if (element)
|
|
41
|
+
this.scrollToElement(element, options);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Scrolls to the specified element.
|
|
45
|
+
* @param element The element to scroll to.
|
|
46
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
47
|
+
*/
|
|
48
|
+
scrollToElement(element, options = {}) {
|
|
49
|
+
const { left, top } = element.getBoundingClientRect();
|
|
50
|
+
const { scrollLeft, scrollTop } = this.#viewport();
|
|
51
|
+
this.scrollToPosition(left + scrollLeft, top + scrollTop - this.scrollOffset, options);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Scrolls to the specified position.
|
|
55
|
+
* @param x The pixel along the horizontal axis.
|
|
56
|
+
* @param y The pixel along the vertical axis.
|
|
57
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
58
|
+
*/
|
|
59
|
+
scrollToPosition(x, y, options = {}) {
|
|
60
|
+
this.#viewport().scrollTo({ left: x, top: y, behavior: options.behavior ?? "auto" });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Scrolls to the top.
|
|
64
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
65
|
+
*/
|
|
66
|
+
scrollToTop(options = {}) {
|
|
67
|
+
this.scrollToPosition(0, 0, options);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ILoadingIndicator } from "#Abstractions/ILoadingIndicator.js";
|
|
2
|
+
/**
|
|
3
|
+
* Performs HTTP requests.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpClient {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* The base URL of the remote service.
|
|
9
|
+
*/
|
|
10
|
+
readonly baseUrl: URL;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new HTTP client.
|
|
13
|
+
* @param options An object providing values to initialize this instance.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: HttpClientOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Performs a DELETE request.
|
|
18
|
+
* @param url The URL of the resource to fetch.
|
|
19
|
+
* @param options The request options.
|
|
20
|
+
* @returns The server response.
|
|
21
|
+
*/
|
|
22
|
+
delete(url?: string | URL, options?: RequestInit): Promise<Response>;
|
|
23
|
+
/**
|
|
24
|
+
* Performs a GET request.
|
|
25
|
+
* @param url The URL of the resource to fetch.
|
|
26
|
+
* @param options The request options.
|
|
27
|
+
* @returns The server response.
|
|
28
|
+
*/
|
|
29
|
+
get(url?: string | URL, options?: RequestInit): Promise<Response>;
|
|
30
|
+
/**
|
|
31
|
+
* Performs a PATCH request.
|
|
32
|
+
* @param url The URL of the resource to fetch.
|
|
33
|
+
* @param body The request body.
|
|
34
|
+
* @param options The request options.
|
|
35
|
+
* @returns The server response.
|
|
36
|
+
*/
|
|
37
|
+
patch(url?: string | URL, body?: unknown, options?: RequestInit): Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* Performs a POST request.
|
|
40
|
+
* @param url The URL of the resource to fetch.
|
|
41
|
+
* @param body The request body.
|
|
42
|
+
* @param options The request options.
|
|
43
|
+
* @returns The server response.
|
|
44
|
+
*/
|
|
45
|
+
post(url?: string | URL, body?: unknown, options?: RequestInit): Promise<Response>;
|
|
46
|
+
/**
|
|
47
|
+
* Performs a PUT request.
|
|
48
|
+
* @param url The URL of the resource to fetch.
|
|
49
|
+
* @param body The request body.
|
|
50
|
+
* @param options The request options.
|
|
51
|
+
* @returns The server response.
|
|
52
|
+
*/
|
|
53
|
+
put(url?: string | URL, body?: unknown, options?: RequestInit): Promise<Response>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Defines the options of a {@link HttpClient} instance.
|
|
57
|
+
*/
|
|
58
|
+
export type HttpClientOptions = Partial<{
|
|
59
|
+
/**
|
|
60
|
+
* The base URL of the remote service.
|
|
61
|
+
*/
|
|
62
|
+
baseUrl: string | URL;
|
|
63
|
+
/**
|
|
64
|
+
* The function returning the component used as loading indicator.
|
|
65
|
+
*/
|
|
66
|
+
loadingIndicator: () => ILoadingIndicator | null;
|
|
67
|
+
}>;
|
|
68
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/Client/Http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,oCAAoC,CAAC;AAG1E;;GAEG;AACH,qBAAa,UAAU;;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IAOtB;;;OAGG;gBACS,OAAO,GAAE,iBAAsB;IAM3C;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,GAAC,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIlE;;;;;OAKG;IACH,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,GAAC,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI/D;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAC,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIjF;;;;;;OAMG;IACH,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAC,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIhF;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,GAAC,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;CAiC/E;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,OAAO,EAAE,MAAM,GAAC,GAAG,CAAC;IAEpB;;OAEG;IACH,gBAAgB,EAAE,MAAM,iBAAiB,GAAC,IAAI,CAAC;CAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { HttpError } from "./HttpError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Performs HTTP requests.
|
|
4
|
+
*/
|
|
5
|
+
export class HttpClient {
|
|
6
|
+
/**
|
|
7
|
+
* The base URL of the remote service.
|
|
8
|
+
*/
|
|
9
|
+
baseUrl;
|
|
10
|
+
/**
|
|
11
|
+
* The function returning the component used as loading indicator.
|
|
12
|
+
*/
|
|
13
|
+
#loadingIndicator;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new HTTP client.
|
|
16
|
+
* @param options An object providing values to initialize this instance.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
const url = options.baseUrl ? (options.baseUrl instanceof URL ? options.baseUrl.href : options.baseUrl) : document.baseURI;
|
|
20
|
+
this.baseUrl = new URL(url.endsWith("/") ? url : `${url}/`);
|
|
21
|
+
this.#loadingIndicator = options.loadingIndicator ?? (() => document.body.querySelector("loading-indicator"));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Performs a DELETE request.
|
|
25
|
+
* @param url The URL of the resource to fetch.
|
|
26
|
+
* @param options The request options.
|
|
27
|
+
* @returns The server response.
|
|
28
|
+
*/
|
|
29
|
+
delete(url, options) {
|
|
30
|
+
return this.#fetch("DELETE", url, null, options);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Performs a GET request.
|
|
34
|
+
* @param url The URL of the resource to fetch.
|
|
35
|
+
* @param options The request options.
|
|
36
|
+
* @returns The server response.
|
|
37
|
+
*/
|
|
38
|
+
get(url, options) {
|
|
39
|
+
return this.#fetch("GET", url, null, options);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Performs a PATCH request.
|
|
43
|
+
* @param url The URL of the resource to fetch.
|
|
44
|
+
* @param body The request body.
|
|
45
|
+
* @param options The request options.
|
|
46
|
+
* @returns The server response.
|
|
47
|
+
*/
|
|
48
|
+
patch(url, body, options) {
|
|
49
|
+
return this.#fetch("PATCH", url, body, options);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Performs a POST request.
|
|
53
|
+
* @param url The URL of the resource to fetch.
|
|
54
|
+
* @param body The request body.
|
|
55
|
+
* @param options The request options.
|
|
56
|
+
* @returns The server response.
|
|
57
|
+
*/
|
|
58
|
+
post(url, body, options) {
|
|
59
|
+
return this.#fetch("POST", url, body, options);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Performs a PUT request.
|
|
63
|
+
* @param url The URL of the resource to fetch.
|
|
64
|
+
* @param body The request body.
|
|
65
|
+
* @param options The request options.
|
|
66
|
+
* @returns The server response.
|
|
67
|
+
*/
|
|
68
|
+
put(url, body, options) {
|
|
69
|
+
return this.#fetch("PUT", url, body, options);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Performs a custom HTTP request.
|
|
73
|
+
* @param method The HTTP method.
|
|
74
|
+
* @param url The URL of the resource to fetch.
|
|
75
|
+
* @param body The request body.
|
|
76
|
+
* @param options The request options.
|
|
77
|
+
* @returns The server response.
|
|
78
|
+
*/
|
|
79
|
+
async #fetch(method, url = "", body = null, options = {}) {
|
|
80
|
+
const headers = new Headers(options.headers);
|
|
81
|
+
if (!headers.has("accept"))
|
|
82
|
+
headers.set("accept", "application/json");
|
|
83
|
+
if (body && !(body instanceof Blob || body instanceof FormData || body instanceof URLSearchParams)) {
|
|
84
|
+
if (typeof body != "string")
|
|
85
|
+
body = JSON.stringify(body);
|
|
86
|
+
if (!headers.has("content-type"))
|
|
87
|
+
headers.set("content-type", "application/json");
|
|
88
|
+
}
|
|
89
|
+
const loadingIndicator = this.#loadingIndicator();
|
|
90
|
+
try {
|
|
91
|
+
loadingIndicator?.start();
|
|
92
|
+
const request = new Request(new URL(url, this.baseUrl), { ...options, method, headers, body });
|
|
93
|
+
const response = await fetch(request);
|
|
94
|
+
if (!response.ok)
|
|
95
|
+
throw new HttpError(response);
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
loadingIndicator?.stop();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { StatusCodes } from "./StatusCodes.js";
|
|
2
|
+
/**
|
|
3
|
+
* An object thrown when an HTTP error occurs.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpError extends globalThis.Error {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new HTTP error.
|
|
9
|
+
* @param response The server response.
|
|
10
|
+
*/
|
|
11
|
+
constructor(response: Response);
|
|
12
|
+
/**
|
|
13
|
+
* The server response.
|
|
14
|
+
*/
|
|
15
|
+
get cause(): Response;
|
|
16
|
+
/**
|
|
17
|
+
* Value indicating whether the response's status code is between 400 and 499.
|
|
18
|
+
*/
|
|
19
|
+
get isClientError(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Value indicating whether the response's status code is between 500 and 599.
|
|
22
|
+
*/
|
|
23
|
+
get isServerError(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The response's status code.
|
|
26
|
+
*/
|
|
27
|
+
get status(): StatusCodes;
|
|
28
|
+
/**
|
|
29
|
+
* The validation errors.
|
|
30
|
+
*/
|
|
31
|
+
get validationErrors(): Promise<Map<string, string>>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=HttpError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpError.d.ts","sourceRoot":"","sources":["../../src/Client/Http/HttpError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAE7C;;GAEG;AACH,qBAAa,SAAU,SAAQ,UAAU,CAAC,KAAK;;IAO9C;;;OAGG;gBACS,QAAQ,EAAE,QAAQ;IAK9B;;OAEG;IACH,IAAa,KAAK,IAAI,QAAQ,CAE7B;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,OAAO,CAG3B;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,OAAO,CAG3B;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;OAEG;IACH,IAAI,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAInD;CAgBD"}
|