elbe-ui 0.2.26 → 0.2.34

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.
Files changed (102) hide show
  1. package/dist/bit/bit.js +83 -0
  2. package/dist/bit/ctrl_bit.js +89 -0
  3. package/dist/elbe.css +621 -0
  4. package/dist/elbe.css.map +1 -0
  5. package/dist/index.d.ts +1549 -17
  6. package/dist/index.js +64 -18577
  7. package/dist/service/s_api.js +89 -0
  8. package/dist/ui/components/badge.d.ts +5 -5
  9. package/dist/ui/components/badge.js +53 -0
  10. package/dist/ui/components/base/box.d.ts +2564 -0
  11. package/dist/ui/components/base/box.js +30 -0
  12. package/dist/ui/components/base/card.d.ts +14 -0
  13. package/dist/ui/components/base/card.js +11 -0
  14. package/dist/ui/components/base/padded.js +28 -0
  15. package/dist/ui/components/button/button.d.ts +21 -0
  16. package/dist/ui/components/button/button.js +27 -0
  17. package/dist/ui/components/button/choose_button.d.ts +14 -0
  18. package/dist/ui/components/button/choose_button.js +11 -0
  19. package/dist/ui/components/button/icon_button.d.ts +17 -0
  20. package/dist/ui/components/button/icon_button.js +31 -0
  21. package/dist/ui/components/button/toggle_button.d.ts +10 -0
  22. package/dist/ui/components/button/toggle_button.js +11 -0
  23. package/dist/ui/components/dialog.js +14 -0
  24. package/dist/ui/components/error_view.js +26 -0
  25. package/dist/ui/components/input/checkbox.d.ts +1 -1
  26. package/dist/ui/components/input/checkbox.js +12 -0
  27. package/dist/ui/components/input/input_field.d.ts +1 -1
  28. package/dist/ui/components/input/input_field.js +31 -0
  29. package/dist/ui/components/input/range.d.ts +1 -1
  30. package/dist/ui/components/input/range.js +14 -0
  31. package/dist/ui/components/input/select.d.ts +1 -1
  32. package/dist/ui/components/input/select.js +8 -0
  33. package/dist/ui/components/input/text_area.d.ts +1 -1
  34. package/dist/ui/components/input/text_area.js +13 -0
  35. package/dist/ui/components/{flex.d.ts → layout/flex.d.ts} +1 -1
  36. package/dist/ui/components/layout/flex.js +23 -0
  37. package/dist/ui/components/{scaffold.d.ts → layout/scaffold.d.ts} +7 -3
  38. package/dist/ui/components/layout/scaffold.js +44 -0
  39. package/dist/ui/components/layout/scroll.d.ts +18 -0
  40. package/dist/ui/components/layout/scroll.js +20 -0
  41. package/dist/ui/components/layout/spaced.js +7 -0
  42. package/dist/ui/components/spinner.d.ts +10 -2
  43. package/dist/ui/components/spinner.js +48 -0
  44. package/dist/ui/components/text.d.ts +5 -5
  45. package/dist/ui/components/text.js +42 -0
  46. package/dist/ui/theme/color_theme.d.ts +2 -0
  47. package/dist/ui/theme/color_theme.js +63 -0
  48. package/dist/ui/theme/colors.d.ts +142 -0
  49. package/dist/ui/theme/colors.js +317 -0
  50. package/dist/ui/theme/geometry_theme.d.ts +16 -0
  51. package/dist/ui/theme/geometry_theme.js +38 -0
  52. package/dist/ui/theme/theme.d.ts +28 -0
  53. package/dist/ui/theme/theme.js +49 -0
  54. package/dist/ui/theme/type_theme.d.ts +38 -0
  55. package/dist/ui/theme/type_theme.js +98 -0
  56. package/dist/ui/util/confirm_dialog.js +46 -0
  57. package/dist/ui/util/error_view.js +8 -0
  58. package/dist/ui/util/toast.js +17 -0
  59. package/dist/ui/util/util.d.ts +2 -0
  60. package/dist/ui/util/util.js +39 -0
  61. package/package.json +14 -15
  62. package/dist/ui/color_theme.d.ts +0 -5
  63. package/dist/ui/components/box.d.ts +0 -1027
  64. package/dist/ui/components/button.d.ts +0 -23
  65. package/dist/ui/components/card.d.ts +0 -14
  66. package/dist/ui/components/icon_button.d.ts +0 -19
  67. package/dist/ui/components/toggle_button.d.ts +0 -12
  68. package/elbe.scss +0 -100
  69. package/src/bit/bit.tsx +0 -128
  70. package/src/bit/ctrl_bit.tsx +0 -112
  71. package/src/index.tsx +0 -29
  72. package/src/service/s_api.ts +0 -102
  73. package/src/ui/color_theme.ts +0 -24
  74. package/src/ui/components/badge.tsx +0 -78
  75. package/src/ui/components/box.tsx +0 -49
  76. package/src/ui/components/button.tsx +0 -61
  77. package/src/ui/components/card.tsx +0 -45
  78. package/src/ui/components/dialog.tsx +0 -51
  79. package/src/ui/components/error_view.tsx +0 -72
  80. package/src/ui/components/flex.tsx +0 -64
  81. package/src/ui/components/icon_button.tsx +0 -56
  82. package/src/ui/components/input/checkbox.tsx +0 -32
  83. package/src/ui/components/input/input_field.tsx +0 -57
  84. package/src/ui/components/input/range.tsx +0 -37
  85. package/src/ui/components/input/select.tsx +0 -29
  86. package/src/ui/components/input/text_area.tsx +0 -45
  87. package/src/ui/components/padded.tsx +0 -62
  88. package/src/ui/components/scaffold.tsx +0 -79
  89. package/src/ui/components/spinner.tsx +0 -11
  90. package/src/ui/components/text.tsx +0 -78
  91. package/src/ui/components/toggle_button.tsx +0 -52
  92. package/src/ui/components/util.tsx +0 -3
  93. package/src/ui/util/confirm_dialog.ts +0 -53
  94. package/src/ui/util/error_view.tsx +0 -16
  95. package/src/ui/util/toast.ts +0 -14
  96. package/src/ui/util/util.ts +0 -36
  97. package/style/color_style.scss +0 -149
  98. package/style/components.scss +0 -476
  99. package/style/root.scss +0 -50
  100. package/style/type_style.scss +0 -22
  101. /package/dist/ui/components/{padded.d.ts → base/padded.d.ts} +0 -0
  102. /package/dist/ui/components/{util.d.ts → layout/spaced.d.ts} +0 -0
@@ -1,23 +0,0 @@
1
- import React from "preact/compat";
2
- import type { ElbeColorManners, ElbeColorStyles } from "../color_theme";
3
- import { type ElbeProps } from "./box";
4
- import type { IconChild } from "./icon_button";
5
- export type ButtonProps = ElbeProps & {
6
- colorStyle?: ElbeColorStyles;
7
- onTap?: () => void;
8
- } & ({
9
- icon?: IconChild;
10
- label: string;
11
- } | {
12
- icon: IconChild;
13
- label?: string;
14
- });
15
- export declare class Button extends React.Component<ButtonProps & {
16
- colorManner: ElbeColorManners;
17
- }> {
18
- static major: (p: ButtonProps) => React.JSX.Element;
19
- static minor: (p: ButtonProps) => React.JSX.Element;
20
- static action: (p: ButtonProps) => React.JSX.Element;
21
- static integrated: (p: ButtonProps) => React.JSX.Element;
22
- render(): React.JSX.Element;
23
- }
@@ -1,14 +0,0 @@
1
- import type { ElbeColorManners, ElbeColorModes, ElbeColorStyles, ElbeColorThemes } from "../color_theme";
2
- import type { ElbeChildren } from "../util/util";
3
- import { type ElbeProps } from "./box";
4
- export declare function Card({ mode, colorScheme, colorStyle, colorManner, padding, margin, onTap, onLongTap, children, ...elbe }: {
5
- mode?: ElbeColorModes;
6
- colorScheme?: ElbeColorThemes;
7
- colorStyle?: ElbeColorStyles;
8
- colorManner?: ElbeColorManners;
9
- padding?: number;
10
- margin?: number;
11
- onTap?: () => void;
12
- onLongTap?: () => void;
13
- children: ElbeChildren;
14
- } & ElbeProps): import("preact").JSX.Element;
@@ -1,19 +0,0 @@
1
- import React from "preact/compat";
2
- import type { ElbeColorManners, ElbeColorStyles } from "../color_theme";
3
- import type { ElbeChild } from "../util/util";
4
- import { type ElbeProps } from "./box";
5
- export type IconChild = ElbeChild | ((_: any) => ElbeChild);
6
- export type IconButtonProps = {
7
- icon?: IconChild;
8
- colorStyle?: ElbeColorStyles;
9
- onTap?: () => void;
10
- } & ElbeProps;
11
- export declare class IconButton extends React.Component<IconButtonProps & {
12
- colorManner?: ElbeColorManners;
13
- }> {
14
- static major: (p: IconButtonProps) => React.JSX.Element;
15
- static minor: (p: IconButtonProps) => React.JSX.Element;
16
- static action: (p: IconButtonProps) => React.JSX.Element;
17
- static integrated: (p: IconButtonProps) => React.JSX.Element;
18
- render(): React.JSX.Element;
19
- }
@@ -1,12 +0,0 @@
1
- import type { ElbeChild } from "../util/util";
2
- import type { ElbeProps } from "./box";
3
- export type ToggleButtonItem<T> = {
4
- icon?: (_: any) => ElbeChild;
5
- label: string;
6
- key: T;
7
- };
8
- export declare function ToggleButton<T>({ items, onSelect, value, ...elbe }: {
9
- items: ToggleButtonItem<T>[];
10
- onSelect: ((value: T) => void) | null;
11
- value: T;
12
- } & ElbeProps): import("preact").JSX.Element;
package/elbe.scss DELETED
@@ -1,100 +0,0 @@
1
- /* BUILD CSS BY:
2
- - npm install -g sass
3
- - sass style/elbe.scss dist/elbe.css
4
- */
5
-
6
- @import url("https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap");
7
- @import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");
8
- @import url("https://fonts.googleapis.com/css2?family=Calistoga&display=swap");
9
- @import url("https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&display=swap");
10
-
11
- // COPY OF THE FUNCTION IN COLOR_STYLE
12
- @function inter($colorA, $colorB: #888888, $weight: 50%) {
13
- @return mix($colorA, $colorB, $weight);
14
- }
15
-
16
- $g-radius: 9px !default;
17
- $c-accent: #1a396f !default;
18
- $t-font-body: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif !default;
19
- $t-font-accent: Calistoga, $t-font-body !default;
20
-
21
- $c-modes: (
22
- primary: (
23
- back: #ffffff,
24
- front: #222222,
25
- border: #22222218,
26
- ),
27
- inverse: (
28
- back: #222222,
29
- front: #ffffff,
30
- border: #ffffff14,
31
- ),
32
- secondary: (
33
- back: inter($c-accent, #ffffff, 7%),
34
- front: #222222,
35
- border: #22222214,
36
- ),
37
- ) !default;
38
-
39
- $c-styles: (
40
- accent: (
41
- back: $c-accent,
42
- ),
43
- error: (
44
- back: #f34343,
45
- ),
46
- warning: (
47
- back: #ffbf00,
48
- front: #222222,
49
- ),
50
- success: (
51
- back: #29ac5e,
52
- ),
53
- info: (
54
- back: #2463aa,
55
- ),
56
- //TODO: Button Styles
57
- loud:
58
- (
59
- back: $c-accent,
60
- border: transparent,
61
- ),
62
- action: (
63
- back: transparent,
64
- front: $c-accent,
65
- border: transparent,
66
- ),
67
- integrated: (
68
- back: transparent,
69
- border: transparent,
70
- ),
71
- ) !default;
72
-
73
- $t-styles: (
74
- "s": 0.7rem,
75
- "m": 1rem,
76
- "l": 1.2rem,
77
- "huge": 4rem,
78
- ) !default;
79
-
80
- $t-headers: (
81
- "6": 1.1rem,
82
- "5": 1.2rem,
83
- "4": 1.4rem,
84
- "3": 1.5rem,
85
- "2": 1.8rem,
86
- "1": 2rem,
87
- ) !default;
88
-
89
- // CSS Variables
90
- :root {
91
- --g-radius: #{$g-radius};
92
- --c-accent: #{$c-accent};
93
- --t-font-body: #{$t-font-body};
94
- --t-font-accent: #{$t-font-accent};
95
- }
96
-
97
- @import "./style/root.scss";
98
- @import "./style/color_style.scss";
99
- @import "./style/type_style.scss";
100
- @import "./style/components.scss";
package/src/bit/bit.tsx DELETED
@@ -1,128 +0,0 @@
1
- import { Signal, useSignal } from "@preact/signals";
2
- import { type PreactContext, createContext } from "preact";
3
- import { useContext } from "preact/hooks";
4
- import { ErrorView } from "../ui/components/error_view";
5
- import { Spinner } from "../ui/components/spinner";
6
-
7
- export interface BitUseInterface<C, T> {
8
- signal: Signal<BitState<T>>;
9
- ctrl: C;
10
- map: <D>(m: TriMap<T, D>) => D | preact.JSX.Element;
11
- onData: (f: (d: T) => any) => any;
12
- }
13
-
14
- interface BitData<C, T> {
15
- ctrl: C;
16
- state: Signal<BitState<T>>;
17
- }
18
-
19
- export interface BitState<T> {
20
- loading?: boolean;
21
- error?: any;
22
- data?: T;
23
- }
24
-
25
- export type BitContext<T, C> = PreactContext<BitData<T, C> | null>;
26
-
27
- export interface TriMap<T, D> {
28
- onLoading?: () => D;
29
- onError?: (e: string) => D;
30
- onData?: (value: T) => D;
31
- }
32
-
33
- export interface TWParams<T> {
34
- emit: (t: T) => void;
35
- emitLoading: () => void;
36
- emitError: (e: any) => void;
37
- map: <D>(m: TriMap<T, D>) => D;
38
- signal: Signal<BitState<T>>;
39
- }
40
-
41
- export function makeBit<C, T>(name: string): BitContext<C, T> {
42
- const c = createContext<BitData<C, T> | null>(null);
43
- c.displayName = name;
44
- return c;
45
- }
46
-
47
- export function ProvideBit<I, C, T>(
48
- context: BitContext<C, T>,
49
- parameters: I,
50
- worker: (p: I, d: TWParams<T>, ctrl: C) => void,
51
- ctrl: (p: I, d: TWParams<T>) => C,
52
- children: any
53
- ) {
54
- const s = useSignal<BitState<T>>({ loading: true });
55
-
56
- const _set = (n: BitState<T>) => {
57
- try {
58
- if (JSON.stringify(n) === JSON.stringify(s.peek())) return;
59
- } catch (e) {}
60
- s.value = n;
61
- };
62
-
63
- const emit = (data: T) => _set({ data });
64
- const emitLoading = () => _set({ loading: true });
65
- const emitError = (error: any) => {
66
- console.warn(`BIT: ${context.displayName} emitted ERROR`, error);
67
- return _set({ error });
68
- };
69
-
70
- function map<D>(m: TriMap<T, D>) {
71
- const st = s.value;
72
- if (st.loading) return m.onLoading!();
73
- if (st.error) return m.onError!(st.error);
74
- return m.onData!(st.data ?? (null as any));
75
- }
76
-
77
- const c = ctrl(parameters, { emit, emitLoading, emitError, map, signal: s });
78
- worker(parameters, { emit, emitLoading, emitError, map, signal: s }, c);
79
-
80
- return (
81
- <context.Provider value={{ ctrl: c, state: s }}>
82
- {children}
83
- </context.Provider>
84
- );
85
- }
86
-
87
- export function useBit<C, T>(context: BitContext<C, T>): BitUseInterface<C, T> {
88
- try {
89
- const { ctrl, state } = useContext(context)!;
90
- const v = state.value;
91
-
92
- function map<D>(m: TriMap<T, D>) {
93
- if (v.loading) return (m.onLoading || (() => <Spinner />))();
94
- if (v.error)
95
- return (
96
- m.onError ||
97
- ((e) => <ErrorView error={e} retry={(ctrl as any).reload ?? null} />)
98
- )(v.error);
99
- return m.onData!(v.data ?? (null as any));
100
- }
101
-
102
- return {
103
- signal: state,
104
- ctrl,
105
- map,
106
- /**
107
- * this is a quality of life function that allows
108
- * you to chain the map function with the onData function
109
- * @param f the builder function
110
- * @returns the built component
111
- */
112
- onData: (f: (d: T) => void) => map({ onData: f }),
113
- };
114
- } catch (e) {
115
- const err = `BIT ERROR: NO ${context.displayName} PROVIDED`;
116
- console.error(err, e);
117
- return {
118
- map: (_: any) => <div>{err}</div>,
119
- ctrl: null as any,
120
- signal: null as any,
121
- onData: () => <div>{err}</div>,
122
- };
123
- }
124
- }
125
-
126
- function BitSpinner({ name }: { name: string }) {
127
- return <Spinner />;
128
- }
@@ -1,112 +0,0 @@
1
- import { useEffect } from "preact/hooks";
2
- import type { JSX } from "preact/jsx-runtime";
3
- import type { BitContext, BitUseInterface, TWParams } from "./bit";
4
- import { makeBit as mb, ProvideBit, useBit } from "./bit";
5
-
6
- abstract class BitControl<I, DT> {
7
- p: I;
8
- bit: TWParams<DT>;
9
-
10
- constructor(p: I, bit: TWParams<DT>) {
11
- this.bit = bit;
12
- this.p = p;
13
- }
14
-
15
- act(fn: (b: DT) => Promise<void>) {
16
- this.bit.map({
17
- onData: async (d) => {
18
- try {
19
- await fn(d);
20
- } catch (e: any) {
21
- if (e && e.code && e.message)
22
- console.error(`[BitERROR] act: ${e.code} (${e.message})`);
23
- else console.error("[BitERROR] act: ", e);
24
- }
25
- },
26
- });
27
- }
28
-
29
- /**
30
- * Clean up resources. This is called once
31
- * the element is removed from the DOM.
32
- */
33
- dispose() {}
34
- }
35
-
36
- export abstract class WorkerControl<I, DT> extends BitControl<I, DT> {
37
- reload: (() => Promise<void>) | null = null;
38
-
39
- abstract worker(): Promise<DT>;
40
- }
41
-
42
- export abstract class StreamControl<I, DT, Stream> extends BitControl<I, DT> {
43
- protected stream: Stream | null = null;
44
- abstract listen(): Stream;
45
-
46
- dispose(): void {
47
- if (this.stream) this.disposeStream(this.stream);
48
- }
49
- abstract disposeStream(stream: Stream): void;
50
- }
51
-
52
- function make<I, DT, C extends BitControl<I, DT>>(
53
- name: string
54
- ): BitContext<C, DT> {
55
- return mb<C, DT>(name);
56
- }
57
-
58
- function use<I, DT, C extends BitControl<I, DT>>(
59
- b: BitContext<C, DT>
60
- ): BitUseInterface<C, DT> {
61
- return useBit<C, DT>(b);
62
- }
63
-
64
- export function CtrlBit<I, DT, C extends BitControl<I, DT>>(
65
- ctrl: (p: I, d: TWParams<DT>) => C,
66
- name?: string
67
- ): {
68
- Provide: (props: I & { children: React.ReactNode }) => JSX.Element;
69
- use: () => BitUseInterface<C, DT>;
70
- } {
71
- const context = make<I, DT, C>((name || "Unknown") + "Bit");
72
-
73
- function Provide({ children, ...p }: { children: React.ReactNode } & I) {
74
- return ProvideBit(
75
- context,
76
- p,
77
- async (p, b, c) => {
78
- b.emitLoading();
79
-
80
- try {
81
- if (c instanceof WorkerControl) {
82
- if (c.reload) await c.reload();
83
- }
84
- if (c instanceof StreamControl) {
85
- (c as any).stream = c.listen();
86
- }
87
- } catch (e) {
88
- b.emitError(e);
89
- }
90
- },
91
-
92
- (p, b) => {
93
- const c = ctrl(p as I, b);
94
- // clean up on unmount
95
- useEffect(() => () => c.dispose(), []);
96
- if (c instanceof WorkerControl) {
97
- c.reload = async () => {
98
- b.emitLoading();
99
- try {
100
- b.emit(await c.worker());
101
- } catch (e) {
102
- b.emitError(e);
103
- }
104
- };
105
- }
106
- return c;
107
- },
108
- children
109
- );
110
- }
111
- return { Provide: Provide, use: () => use<I, DT, C>(context) };
112
- }
package/src/index.tsx DELETED
@@ -1,29 +0,0 @@
1
- import * as Lucide from "lucide-react";
2
-
3
- // exports
4
- export * from "./bit/bit";
5
- export * from "./bit/ctrl_bit";
6
- export * from "./service/s_api";
7
- export * from "./ui/color_theme";
8
- export * from "./ui/components/badge";
9
- export * from "./ui/components/box";
10
- export * from "./ui/components/button";
11
- export * from "./ui/components/card";
12
- export * from "./ui/components/dialog";
13
- export * from "./ui/components/flex";
14
- export * from "./ui/components/icon_button";
15
- export * from "./ui/components/input/checkbox";
16
- export * from "./ui/components/input/input_field";
17
- export * from "./ui/components/input/range";
18
- export * from "./ui/components/input/select";
19
- export * from "./ui/components/padded";
20
- export * from "./ui/components/scaffold";
21
- export * from "./ui/components/spinner";
22
- export * from "./ui/components/text";
23
- export * from "./ui/components/toggle_button";
24
- export * from "./ui/components/util";
25
- export * from "./ui/util/confirm_dialog";
26
- export * from "./ui/util/toast";
27
- export * from "./ui/util/util";
28
-
29
- export const Icons = Lucide.icons;
@@ -1,102 +0,0 @@
1
- export interface PostArgs {
2
- path?: { [key: string]: string | number | boolean | undefined };
3
- query?: { [key: string]: string | number | boolean | undefined };
4
- body?: any;
5
- }
6
-
7
- const _noArgs: PostArgs = {};
8
-
9
- /**
10
- * ApiService is a simple wrapper around fetch that handles JSON serialization and error handling.
11
- * to use it, you must first call `ApiService.init(apiURL)` with the base URL of your API.
12
- */
13
- export class ApiService {
14
- private static _i: ApiService | null = null;
15
- public static get i(): ApiService {
16
- if (!ApiService._i) throw "ApiService not initialized. Call ApiService.init(apiURL)";
17
- return ApiService._i;
18
- }
19
-
20
- private constructor(private apiURL: string) {}
21
-
22
- static init(apiURL: string) {
23
- if (ApiService._i) throw "ApiService already initialized";
24
- ApiService._i = new ApiService(apiURL);
25
- }
26
-
27
- private async _fetch(
28
- p: string,
29
- method: "GET" | "POST" | "DELETE",
30
- { path, query, body }: PostArgs
31
- ): Promise<any> {
32
- try {
33
- p = path
34
- ? p.replace(/:([a-zA-Z0-9_]+)/g, (m, p1) => {
35
- const v = path[p1];
36
- if (v === undefined)
37
- throw { code: 400, message: `missing parameter ${p1}` };
38
- return v?.toString() ?? "";
39
- })
40
- : p;
41
-
42
- const queryStr =
43
- query != null ? "?" + new URLSearchParams(query as any).toString() : "";
44
- const response = await fetch(this.apiURL + p + queryStr, {
45
- method,
46
- credentials: "include",
47
- headers: { "Content-Type": "application/json" },
48
- body: body ? JSON.stringify(body) : undefined,
49
- });
50
- if (response.ok) {
51
- try {
52
- return await response.json();
53
- } catch (e) {
54
- return null;
55
- }
56
- }
57
- let data = null;
58
- try {
59
- data = await response.clone().json();
60
- } catch (e) {
61
- data = await response.text();
62
- }
63
-
64
- throw {
65
- code: response.status,
66
- message: data.message ?? "undefined error",
67
- data,
68
- } as ApiError;
69
- } catch (e) {
70
- rethrow(e, 0, "unknown error");
71
- }
72
- }
73
-
74
- async get(path: string, args?: PostArgs): Promise<any> {
75
- return this._fetch(path, "GET", args || _noArgs);
76
- }
77
-
78
- async post(path: string, args: PostArgs): Promise<any> {
79
- return this._fetch(path, "POST", args || _noArgs);
80
- }
81
-
82
- async delete(path: string, args: PostArgs): Promise<any> {
83
- return this._fetch(path, "DELETE", args || _noArgs);
84
- }
85
- }
86
-
87
- function rethrow(e: any, code: number, message: string): ApiError {
88
- // if e implements the apiError interface, rethrow it:
89
- if (e && e.code !== null && e.message !== null) throw e;
90
- throw { code, message, data: e };
91
- }
92
-
93
- export interface ApiError {
94
- code: number;
95
- message: string;
96
- data?: any;
97
- }
98
-
99
- export function ifApiError(e: any): ApiError | null {
100
- if (e && e.code !== null && e.message !== null) return e;
101
- return null;
102
- }
@@ -1,24 +0,0 @@
1
- export type ElbeColorStyles =
2
- | "accent"
3
- | "error"
4
- | "warning"
5
- | "success"
6
- | "info";
7
-
8
- export type ElbeColorManners = "major" | "minor" | "action" | "integrated";
9
-
10
- export type ElbeColorThemes = "primary" | "secondary" | "inverse";
11
-
12
- export type ElbeColorModes = "light" | "dark";
13
-
14
- export type ElbeTypeStyles =
15
- | "header-1"
16
- | "header-2"
17
- | "header-3"
18
- | "header-4"
19
- | "header-5"
20
- | "header-6"
21
- | "text-s"
22
- | "text-m"
23
- | "text-l"
24
- | "code";
@@ -1,78 +0,0 @@
1
- import React from "preact/compat";
2
- import type { ElbeColorStyles } from "../color_theme";
3
- import type { ElbeChild, ElbeChildren } from "../util/util";
4
- import type { ElbeProps } from "./box";
5
-
6
- export type BadgeProps = {
7
- count?: number;
8
- message?: string;
9
- child?: ElbeChild;
10
- hidden?: boolean;
11
- children?: ElbeChildren;
12
- } & ElbeProps;
13
-
14
- export function TestBadge(p: BadgeProps) {
15
- return new Badge({ ...p, colorStyle: "accent" });
16
- }
17
-
18
- export class Badge extends React.Component<
19
- BadgeProps & { colorStyle: ElbeColorStyles }
20
- > {
21
- constructor(props: BadgeProps & { colorStyle: ElbeColorStyles }) {
22
- super(props);
23
- }
24
-
25
- static accent(p: BadgeProps) {
26
- return <Badge {...p} colorStyle="accent" />;
27
- }
28
-
29
- static error(p: BadgeProps) {
30
- return <Badge {...p} colorStyle="error" />;
31
- }
32
-
33
- static warning(p: BadgeProps) {
34
- return <Badge {...p} colorStyle="warning" />;
35
- }
36
-
37
- static success(p: BadgeProps) {
38
- return <Badge {...p} colorStyle="success" />;
39
- }
40
-
41
- static info(p: BadgeProps) {
42
- return <Badge {...p} colorStyle="info" />;
43
- }
44
-
45
- render() {
46
- return (
47
- <div
48
- style={{
49
- position: "relative",
50
- display: "inline-block",
51
- }}
52
- >
53
- {this.props.child}
54
- {this.props.children}
55
- <div
56
- class={`b ${this.props.colorStyle} ${this.props.class ?? ""}`}
57
- style={{
58
- position: "absolute",
59
- top: "-0.25rem",
60
- right: "-0.25rem",
61
- minWidth: "1.5rem",
62
- minHeight: "1.5rem",
63
- padding: "0rem .4rem",
64
- borderRadius: "3rem",
65
- fontWeight: "bold",
66
- display: "flex",
67
- justifyContent: "center",
68
- alignItems: "center",
69
- visibility: this.props.hidden ? "hidden" : "visible",
70
- ...this.props.style,
71
- }}
72
- >
73
- {this.props.message ?? this.props.count}
74
- </div>
75
- </div>
76
- );
77
- }
78
- }
@@ -1,49 +0,0 @@
1
- import { h } from "preact";
2
- import type { ElbeColorModes, ElbeColorThemes } from "../color_theme";
3
- import type { ElbeChildren } from "../util/util";
4
-
5
- export type ElbeProps = {
6
- class?: string;
7
- style?: React.CSSProperties;
8
- tooltip?: string;
9
- };
10
-
11
- export function applyProps(
12
- p: ElbeProps,
13
- classes?: string | null | (string | false | null | undefined)[],
14
- style?: React.CSSProperties
15
- ) {
16
- if (Array.isArray(classes)) {
17
- classes = classes.filter((c) => c).join(" ");
18
- }
19
- return {
20
- class: `${classes || ""} ${p.class || ""}`,
21
- style: { ...(style ?? {}), ...(p.style ?? {}) },
22
- ...(p.tooltip ? { ["data-tooltip"]: p.tooltip } : {}),
23
- };
24
- }
25
-
26
- export function Box({
27
- mode,
28
- scheme = "primary",
29
- padding = 0,
30
- margin = 0,
31
- children,
32
- ...elbe
33
- }: {
34
- mode?: ElbeColorModes;
35
- scheme?: ElbeColorThemes;
36
- padding?: number;
37
- margin?: number;
38
- children: ElbeChildren;
39
- } & ElbeProps) {
40
- return h(
41
- "div",
42
- applyProps(elbe, [scheme, mode], {
43
- padding: `${padding}rem`,
44
- margin: `${margin}rem`,
45
- ...elbe.style,
46
- }),
47
- children
48
- );
49
- }