elbe-ui 2.0.15 → 2.0.17
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/bit/_bit_provider.js +96 -37
- package/dist/index.js +1 -0
- package/dist/ui/components/dialog/dialog_ctx.d.ts +1 -1
- package/dist/ui/components/tooltip.js +0 -1
- package/dist/ui/theme/subthemes/_theme_type.d.ts +1 -0
- package/dist/ui/theme/subthemes/color/colors/_colordef.d.ts +1 -0
- package/dist/ui/theme/theme.d.ts +1 -1
- package/dist/ui/theme/theme.js +2 -1
- package/dist/ui/util/merge_deep.d.ts +1 -0
- package/dist/ui/util/util.d.ts +3 -0
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import { useEffect, useState } from "react";
|
|
11
|
+
import { useEffect, useRef, useState } from "react";
|
|
12
12
|
import { Column, ErrorView, Spinner, } from "..";
|
|
13
13
|
import { _isFn } from "./_bit_types";
|
|
14
14
|
function _LoadView({}) {
|
|
@@ -16,45 +16,60 @@ function _LoadView({}) {
|
|
|
16
16
|
}
|
|
17
17
|
export function _makeBitProvider(context, bitP) {
|
|
18
18
|
function _BitProvider(p) {
|
|
19
|
-
const
|
|
19
|
+
const streamCancelRef = useRef(null);
|
|
20
|
+
const stateRef = useRef({
|
|
21
|
+
v: { type: "loading" },
|
|
22
|
+
history: [],
|
|
23
|
+
});
|
|
20
24
|
const [state, setState] = useState({
|
|
21
25
|
v: { type: "loading" },
|
|
22
26
|
history: [],
|
|
23
27
|
});
|
|
28
|
+
stateRef.current = state;
|
|
24
29
|
// ========== DEFINE BASIC CTRLS ==========
|
|
25
30
|
function _make() {
|
|
26
31
|
const _partCtrl = {
|
|
27
32
|
setData: (d) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
setState((prev) => {
|
|
34
|
+
// if it's the same data, don't update
|
|
35
|
+
if (prev.v.type === "data" && prev.v.value === d)
|
|
36
|
+
return prev;
|
|
37
|
+
return {
|
|
38
|
+
history: bitP.useHistory ? [...prev.history, d] : [],
|
|
39
|
+
v: { type: "data", value: d },
|
|
40
|
+
};
|
|
34
41
|
});
|
|
35
42
|
},
|
|
36
|
-
setLoading: () => setState(Object.assign(Object.assign({},
|
|
37
|
-
setError: (e) => setState(Object.assign(Object.assign({},
|
|
38
|
-
canGoBack: !!(bitP.useHistory &&
|
|
43
|
+
setLoading: () => setState((prev) => (Object.assign(Object.assign({}, prev), { v: { type: "loading" } }))),
|
|
44
|
+
setError: (e) => setState((prev) => (Object.assign(Object.assign({}, prev), { v: { type: "error", value: e } }))),
|
|
45
|
+
canGoBack: !!(bitP.useHistory && stateRef.current.history.length > 1),
|
|
39
46
|
back: () => {
|
|
40
47
|
if (!bitP.useHistory)
|
|
41
48
|
return false;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
let didGoBack = false;
|
|
50
|
+
setState((prev) => {
|
|
51
|
+
if (prev.history.length < 2)
|
|
52
|
+
return prev;
|
|
53
|
+
didGoBack = true;
|
|
54
|
+
const newHistory = prev.history.slice(0, -1);
|
|
55
|
+
const newData = newHistory[newHistory.length - 1];
|
|
56
|
+
return {
|
|
57
|
+
history: newHistory,
|
|
58
|
+
v: { type: "data", value: newData },
|
|
59
|
+
};
|
|
49
60
|
});
|
|
50
|
-
return
|
|
61
|
+
return didGoBack;
|
|
51
62
|
},
|
|
52
|
-
state:
|
|
53
|
-
isData:
|
|
54
|
-
isLoading:
|
|
55
|
-
isError:
|
|
56
|
-
data:
|
|
57
|
-
|
|
63
|
+
state: stateRef.current.v.type,
|
|
64
|
+
isData: stateRef.current.v.type === "data",
|
|
65
|
+
isLoading: stateRef.current.v.type === "loading",
|
|
66
|
+
isError: stateRef.current.v.type === "error",
|
|
67
|
+
data: stateRef.current.v.type === "data"
|
|
68
|
+
? stateRef.current.v.value
|
|
69
|
+
: undefined,
|
|
70
|
+
error: stateRef.current.v.type === "error"
|
|
71
|
+
? stateRef.current.v.value
|
|
72
|
+
: undefined,
|
|
58
73
|
};
|
|
59
74
|
// ========== DEFINE QoL FUNCTIONS ==========
|
|
60
75
|
function _worker(fn, silent, reset) {
|
|
@@ -81,10 +96,14 @@ export function _makeBitProvider(context, bitP) {
|
|
|
81
96
|
try {
|
|
82
97
|
if (!silent)
|
|
83
98
|
_partCtrl.setLoading();
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
const prevCancel = streamCancelRef.current;
|
|
100
|
+
streamCancelRef.current = null;
|
|
101
|
+
if (prevCancel)
|
|
102
|
+
prevCancel();
|
|
86
103
|
const cancel = _bit.stream(p, _partCtrl);
|
|
87
|
-
|
|
104
|
+
streamCancelRef.current = () => {
|
|
105
|
+
cancel();
|
|
106
|
+
};
|
|
88
107
|
return;
|
|
89
108
|
}
|
|
90
109
|
catch (e) {
|
|
@@ -96,7 +115,9 @@ export function _makeBitProvider(context, bitP) {
|
|
|
96
115
|
};
|
|
97
116
|
function act(fn, silent) {
|
|
98
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const data =
|
|
118
|
+
const data = stateRef.current.v.type === "data"
|
|
119
|
+
? stateRef.current.v.value
|
|
120
|
+
: undefined;
|
|
100
121
|
if (data === undefined)
|
|
101
122
|
return;
|
|
102
123
|
_worker(() => fn(data), silent);
|
|
@@ -104,14 +125,15 @@ export function _makeBitProvider(context, bitP) {
|
|
|
104
125
|
}
|
|
105
126
|
function map(onData, onError, onLoading) {
|
|
106
127
|
var _a, _b, _c;
|
|
107
|
-
|
|
128
|
+
const currentState = stateRef.current.v;
|
|
129
|
+
if (currentState.type === "data") {
|
|
108
130
|
return _isFn(onData)
|
|
109
|
-
? onData(
|
|
131
|
+
? onData(currentState.value)
|
|
110
132
|
: ((_a = onData) !== null && _a !== void 0 ? _a : null);
|
|
111
133
|
}
|
|
112
|
-
if (
|
|
134
|
+
if (currentState.type === "error") {
|
|
113
135
|
return _isFn(onError)
|
|
114
|
-
? onError(
|
|
136
|
+
? onError(currentState.value)
|
|
115
137
|
: ((_b = onError) !== null && _b !== void 0 ? _b : null);
|
|
116
138
|
}
|
|
117
139
|
return _isFn(onLoading) ? onLoading() : ((_c = onLoading) !== null && _c !== void 0 ? _c : null);
|
|
@@ -126,14 +148,51 @@ export function _makeBitProvider(context, bitP) {
|
|
|
126
148
|
return children();
|
|
127
149
|
}
|
|
128
150
|
const userCtrl = bitP.control(Object.assign(Object.assign({}, baseCtrl), { parameters: p, reload: _reload, consider: consider }));
|
|
129
|
-
|
|
151
|
+
const ctrl = Object.assign(Object.assign(Object.assign({}, baseCtrl), userCtrl), { reload: _reload, parameters: p, consider: consider });
|
|
152
|
+
Object.defineProperties(ctrl, {
|
|
153
|
+
state: {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: () => stateRef.current.v.type,
|
|
156
|
+
},
|
|
157
|
+
isData: {
|
|
158
|
+
enumerable: true,
|
|
159
|
+
get: () => stateRef.current.v.type === "data",
|
|
160
|
+
},
|
|
161
|
+
isLoading: {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: () => stateRef.current.v.type === "loading",
|
|
164
|
+
},
|
|
165
|
+
isError: {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: () => stateRef.current.v.type === "error",
|
|
168
|
+
},
|
|
169
|
+
data: {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: () => stateRef.current.v.type === "data"
|
|
172
|
+
? stateRef.current.v.value
|
|
173
|
+
: undefined,
|
|
174
|
+
},
|
|
175
|
+
error: {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: () => stateRef.current.v.type === "error"
|
|
178
|
+
? stateRef.current.v.value
|
|
179
|
+
: undefined,
|
|
180
|
+
},
|
|
181
|
+
canGoBack: {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: () => !!(bitP.useHistory && stateRef.current.history.length > 1),
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
return ctrl;
|
|
130
187
|
}
|
|
131
188
|
const ctrl = _make();
|
|
132
189
|
useEffect(() => {
|
|
133
190
|
ctrl.reload(true);
|
|
134
191
|
return () => {
|
|
135
|
-
|
|
136
|
-
|
|
192
|
+
const cancel = streamCancelRef.current;
|
|
193
|
+
streamCancelRef.current = null;
|
|
194
|
+
if (cancel)
|
|
195
|
+
cancel();
|
|
137
196
|
// call dispose if exists
|
|
138
197
|
const d = ctrl.dispose;
|
|
139
198
|
if (typeof d !== "function")
|
|
@@ -147,7 +206,7 @@ export function _makeBitProvider(context, bitP) {
|
|
|
147
206
|
};
|
|
148
207
|
}, []);
|
|
149
208
|
// ========== DEFINE THE JSX ELEMENT ==========
|
|
150
|
-
return
|
|
209
|
+
return _jsx(context.Provider, { value: ctrl, children: p.children });
|
|
151
210
|
}
|
|
152
211
|
return _BitProvider;
|
|
153
212
|
}
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,6 @@ export function WithTooltip(p) {
|
|
|
44
44
|
var _a;
|
|
45
45
|
timeoutRef.current = window.setTimeout(() => setVisible(true), (_a = p.delay) !== null && _a !== void 0 ? _a : 1000);
|
|
46
46
|
}, onMouseLeave: () => {
|
|
47
|
-
console.log("leave");
|
|
48
47
|
if (timeoutRef.current) {
|
|
49
48
|
clearTimeout(timeoutRef.current);
|
|
50
49
|
timeoutRef.current = null;
|
package/dist/ui/theme/theme.d.ts
CHANGED
package/dist/ui/theme/theme.js
CHANGED
package/dist/ui/util/util.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { int } from "../..";
|
|
2
2
|
export type Maybe<T> = T | null | undefined;
|
|
3
3
|
export type PromiseOr<T> = Promise<T> | T;
|
|
4
|
+
export type Dict<T> = {
|
|
5
|
+
[key: string]: T;
|
|
6
|
+
};
|
|
4
7
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
5
8
|
export declare function classString(classes: (string | false | null | undefined)[]): string;
|
|
6
9
|
/**
|