elbe-ui 0.2.30 → 0.2.37

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 (71) hide show
  1. package/dist/bit/bit.d.ts +34 -0
  2. package/dist/bit/bit.js +83 -0
  3. package/dist/bit/ctrl_bit.d.ts +30 -0
  4. package/dist/bit/ctrl_bit.js +89 -0
  5. package/dist/elbe.css +203 -284
  6. package/dist/elbe.css.map +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/service/s_api.d.ts +30 -0
  10. package/dist/service/s_api.js +89 -0
  11. package/dist/ui/components/badge.d.ts +25 -0
  12. package/dist/ui/components/badge.js +53 -0
  13. package/dist/ui/components/base/box.d.ts +2564 -0
  14. package/dist/ui/components/base/box.js +30 -0
  15. package/dist/ui/components/base/card.d.ts +14 -0
  16. package/dist/ui/components/base/card.js +11 -0
  17. package/dist/ui/components/base/padded.d.ts +25 -0
  18. package/dist/ui/components/base/padded.js +28 -0
  19. package/dist/ui/components/button/button.d.ts +21 -0
  20. package/dist/ui/components/button/button.js +27 -0
  21. package/dist/ui/components/button/choose_button.d.ts +14 -0
  22. package/dist/ui/components/button/choose_button.js +11 -0
  23. package/dist/ui/components/button/icon_button.d.ts +17 -0
  24. package/dist/ui/components/button/icon_button.js +31 -0
  25. package/dist/ui/components/button/toggle_button.d.ts +10 -0
  26. package/dist/ui/components/button/toggle_button.js +11 -0
  27. package/dist/ui/components/dialog.d.ts +8 -0
  28. package/dist/ui/components/dialog.js +14 -0
  29. package/dist/ui/components/error_view.d.ts +15 -0
  30. package/dist/ui/components/error_view.js +26 -0
  31. package/dist/ui/components/input/checkbox.d.ts +6 -0
  32. package/dist/ui/components/input/checkbox.js +12 -0
  33. package/dist/ui/components/input/input_field.d.ts +22 -0
  34. package/dist/ui/components/input/input_field.js +31 -0
  35. package/dist/ui/components/input/range.d.ts +8 -0
  36. package/dist/ui/components/input/range.js +14 -0
  37. package/dist/ui/components/input/select.d.ts +10 -0
  38. package/dist/ui/components/input/select.js +8 -0
  39. package/dist/ui/components/input/text_area.d.ts +10 -0
  40. package/dist/ui/components/input/text_area.js +13 -0
  41. package/dist/ui/components/layout/flex.d.ts +11 -0
  42. package/dist/ui/components/layout/flex.js +23 -0
  43. package/dist/ui/components/layout/scaffold.d.ts +27 -0
  44. package/dist/ui/components/layout/scaffold.js +44 -0
  45. package/dist/ui/components/layout/scroll.d.ts +18 -0
  46. package/dist/ui/components/layout/scroll.js +20 -0
  47. package/dist/ui/components/layout/spaced.d.ts +3 -0
  48. package/dist/ui/components/layout/spaced.js +7 -0
  49. package/dist/ui/components/spinner.d.ts +11 -0
  50. package/dist/ui/components/spinner.js +48 -0
  51. package/dist/ui/components/text.d.ts +33 -0
  52. package/dist/ui/components/text.js +42 -0
  53. package/dist/ui/theme/color_theme.d.ts +2 -0
  54. package/dist/ui/theme/color_theme.js +63 -0
  55. package/dist/ui/theme/colors.d.ts +142 -0
  56. package/dist/ui/theme/colors.js +317 -0
  57. package/dist/ui/theme/geometry_theme.d.ts +16 -0
  58. package/dist/ui/theme/geometry_theme.js +38 -0
  59. package/dist/ui/theme/theme.d.ts +28 -0
  60. package/dist/ui/theme/theme.js +49 -0
  61. package/dist/ui/theme/type_theme.d.ts +38 -0
  62. package/dist/ui/theme/type_theme.js +98 -0
  63. package/dist/ui/util/confirm_dialog.d.ts +10 -0
  64. package/dist/ui/util/confirm_dialog.js +46 -0
  65. package/dist/ui/util/error_view.d.ts +1 -0
  66. package/dist/ui/util/error_view.js +8 -0
  67. package/dist/ui/util/toast.d.ts +5 -0
  68. package/dist/ui/util/toast.js +17 -0
  69. package/dist/ui/util/util.d.ts +21 -0
  70. package/dist/ui/util/util.js +39 -0
  71. package/package.json +3 -6
@@ -0,0 +1,34 @@
1
+ import { Signal } from "@preact/signals";
2
+ import { type PreactContext } from "preact";
3
+ export interface BitUseInterface<C, T> {
4
+ signal: Signal<BitState<T>>;
5
+ ctrl: C;
6
+ map: <D>(m: TriMap<T, D>) => D | preact.JSX.Element;
7
+ onData: (f: (d: T) => any) => any;
8
+ }
9
+ interface BitData<C, T> {
10
+ ctrl: C;
11
+ state: Signal<BitState<T>>;
12
+ }
13
+ export interface BitState<T> {
14
+ loading?: boolean;
15
+ error?: any;
16
+ data?: T;
17
+ }
18
+ export type BitContext<T, C> = PreactContext<BitData<T, C> | null>;
19
+ export interface TriMap<T, D> {
20
+ onLoading?: () => D;
21
+ onError?: (e: string) => D;
22
+ onData?: (value: T) => D;
23
+ }
24
+ export interface TWParams<T> {
25
+ emit: (t: T) => void;
26
+ emitLoading: () => void;
27
+ emitError: (e: any) => void;
28
+ map: <D>(m: TriMap<T, D>) => D;
29
+ signal: Signal<BitState<T>>;
30
+ }
31
+ export declare function makeBit<C, T>(name: string): BitContext<C, T>;
32
+ export declare function ProvideBit<I, C, T>(context: BitContext<C, T>, parameters: I, worker: (p: I, d: TWParams<T>, ctrl: C) => void, ctrl: (p: I, d: TWParams<T>) => C, children: any): import("preact").JSX.Element;
33
+ export declare function useBit<C, T>(context: BitContext<C, T>): BitUseInterface<C, T>;
34
+ export {};
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBit = makeBit;
4
+ exports.ProvideBit = ProvideBit;
5
+ exports.useBit = useBit;
6
+ const jsx_runtime_1 = require("preact/jsx-runtime");
7
+ const signals_1 = require("@preact/signals");
8
+ const preact_1 = require("preact");
9
+ const hooks_1 = require("preact/hooks");
10
+ const error_view_1 = require("../ui/components/error_view");
11
+ const spinner_1 = require("../ui/components/spinner");
12
+ function makeBit(name) {
13
+ const c = (0, preact_1.createContext)(null);
14
+ c.displayName = name;
15
+ return c;
16
+ }
17
+ function ProvideBit(context, parameters, worker, ctrl, children) {
18
+ const s = (0, signals_1.useSignal)({ loading: true });
19
+ const _set = (n) => {
20
+ try {
21
+ if (JSON.stringify(n) === JSON.stringify(s.peek()))
22
+ return;
23
+ }
24
+ catch (e) { }
25
+ s.value = n;
26
+ };
27
+ const emit = (data) => _set({ data });
28
+ const emitLoading = () => _set({ loading: true });
29
+ const emitError = (error) => {
30
+ console.warn(`BIT: ${context.displayName} emitted ERROR`, error);
31
+ return _set({ error });
32
+ };
33
+ function map(m) {
34
+ const st = s.value;
35
+ if (st.loading)
36
+ return m.onLoading();
37
+ if (st.error)
38
+ return m.onError(st.error);
39
+ return m.onData(st.data ?? null);
40
+ }
41
+ const c = ctrl(parameters, { emit, emitLoading, emitError, map, signal: s });
42
+ worker(parameters, { emit, emitLoading, emitError, map, signal: s }, c);
43
+ return ((0, jsx_runtime_1.jsx)(context.Provider, { value: { ctrl: c, state: s }, children: children }));
44
+ }
45
+ function useBit(context) {
46
+ try {
47
+ const { ctrl, state } = (0, hooks_1.useContext)(context);
48
+ const v = state.value;
49
+ function map(m) {
50
+ if (v.loading)
51
+ return (m.onLoading || (() => (0, jsx_runtime_1.jsx)(spinner_1.Spinner, {})))();
52
+ if (v.error)
53
+ return (m.onError ||
54
+ ((e) => (0, jsx_runtime_1.jsx)(error_view_1.ErrorView, { error: e, retry: ctrl.reload ?? null })))(v.error);
55
+ return m.onData(v.data ?? null);
56
+ }
57
+ return {
58
+ signal: state,
59
+ ctrl,
60
+ map,
61
+ /**
62
+ * this is a quality of life function that allows
63
+ * you to chain the map function with the onData function
64
+ * @param f the builder function
65
+ * @returns the built component
66
+ */
67
+ onData: (f) => map({ onData: f }),
68
+ };
69
+ }
70
+ catch (e) {
71
+ const err = `BIT ERROR: NO ${context.displayName} PROVIDED`;
72
+ console.error(err, e);
73
+ return {
74
+ map: (_) => (0, jsx_runtime_1.jsx)("div", { children: err }),
75
+ ctrl: null,
76
+ signal: null,
77
+ onData: () => (0, jsx_runtime_1.jsx)("div", { children: err }),
78
+ };
79
+ }
80
+ }
81
+ function BitSpinner({ name }) {
82
+ return (0, jsx_runtime_1.jsx)(spinner_1.Spinner, {});
83
+ }
@@ -0,0 +1,30 @@
1
+ import type { JSX } from "preact/jsx-runtime";
2
+ import type { BitUseInterface, TWParams } from "./bit";
3
+ declare abstract class BitControl<I, DT> {
4
+ p: I;
5
+ bit: TWParams<DT>;
6
+ constructor(p: I, bit: TWParams<DT>);
7
+ act(fn: (b: DT) => Promise<void>): void;
8
+ /**
9
+ * Clean up resources. This is called once
10
+ * the element is removed from the DOM.
11
+ */
12
+ dispose(): void;
13
+ }
14
+ export declare abstract class WorkerControl<I, DT> extends BitControl<I, DT> {
15
+ reload: (() => Promise<void>) | null;
16
+ abstract worker(): Promise<DT>;
17
+ }
18
+ export declare abstract class StreamControl<I, DT, Stream> extends BitControl<I, DT> {
19
+ protected stream: Stream | null;
20
+ abstract listen(): Stream;
21
+ dispose(): void;
22
+ abstract disposeStream(stream: Stream): void;
23
+ }
24
+ export declare function CtrlBit<I, DT, C extends BitControl<I, DT>>(ctrl: (p: I, d: TWParams<DT>) => C, name?: string): {
25
+ Provide: (props: I & {
26
+ children: React.ReactNode;
27
+ }) => JSX.Element;
28
+ use: () => BitUseInterface<C, DT>;
29
+ };
30
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamControl = exports.WorkerControl = void 0;
4
+ exports.CtrlBit = CtrlBit;
5
+ const hooks_1 = require("preact/hooks");
6
+ const bit_1 = require("./bit");
7
+ class BitControl {
8
+ p;
9
+ bit;
10
+ constructor(p, bit) {
11
+ this.bit = bit;
12
+ this.p = p;
13
+ }
14
+ act(fn) {
15
+ this.bit.map({
16
+ onData: async (d) => {
17
+ try {
18
+ await fn(d);
19
+ }
20
+ catch (e) {
21
+ if (e && e.code && e.message)
22
+ console.error(`[BitERROR] act: ${e.code} (${e.message})`);
23
+ else
24
+ console.error("[BitERROR] act: ", e);
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
+ class WorkerControl extends BitControl {
36
+ reload = null;
37
+ }
38
+ exports.WorkerControl = WorkerControl;
39
+ class StreamControl extends BitControl {
40
+ stream = null;
41
+ dispose() {
42
+ if (this.stream)
43
+ this.disposeStream(this.stream);
44
+ }
45
+ }
46
+ exports.StreamControl = StreamControl;
47
+ function make(name) {
48
+ return (0, bit_1.makeBit)(name);
49
+ }
50
+ function use(b) {
51
+ return (0, bit_1.useBit)(b);
52
+ }
53
+ function CtrlBit(ctrl, name) {
54
+ const context = make((name || "Unknown") + "Bit");
55
+ function Provide({ children, ...p }) {
56
+ return (0, bit_1.ProvideBit)(context, p, async (p, b, c) => {
57
+ b.emitLoading();
58
+ try {
59
+ if (c instanceof WorkerControl) {
60
+ if (c.reload)
61
+ await c.reload();
62
+ }
63
+ if (c instanceof StreamControl) {
64
+ c.stream = c.listen();
65
+ }
66
+ }
67
+ catch (e) {
68
+ b.emitError(e);
69
+ }
70
+ }, (p, b) => {
71
+ const c = ctrl(p, b);
72
+ // clean up on unmount
73
+ (0, hooks_1.useEffect)(() => () => c.dispose(), []);
74
+ if (c instanceof WorkerControl) {
75
+ c.reload = async () => {
76
+ b.emitLoading();
77
+ try {
78
+ b.emit(await c.worker());
79
+ }
80
+ catch (e) {
81
+ b.emitError(e);
82
+ }
83
+ };
84
+ }
85
+ return c;
86
+ }, children);
87
+ }
88
+ return { Provide: Provide, use: () => use(context) };
89
+ }