elbe-ui 2.0.16 → 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 +83 -30
- package/dist/index.js +1 -0
- package/dist/ui/components/dialog/dialog_ctx.d.ts +1 -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
|
@@ -17,44 +17,59 @@ function _LoadView({}) {
|
|
|
17
17
|
export function _makeBitProvider(context, bitP) {
|
|
18
18
|
function _BitProvider(p) {
|
|
19
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) {
|
|
@@ -100,7 +115,9 @@ export function _makeBitProvider(context, bitP) {
|
|
|
100
115
|
};
|
|
101
116
|
function act(fn, silent) {
|
|
102
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
const data =
|
|
118
|
+
const data = stateRef.current.v.type === "data"
|
|
119
|
+
? stateRef.current.v.value
|
|
120
|
+
: undefined;
|
|
104
121
|
if (data === undefined)
|
|
105
122
|
return;
|
|
106
123
|
_worker(() => fn(data), silent);
|
|
@@ -108,14 +125,15 @@ export function _makeBitProvider(context, bitP) {
|
|
|
108
125
|
}
|
|
109
126
|
function map(onData, onError, onLoading) {
|
|
110
127
|
var _a, _b, _c;
|
|
111
|
-
|
|
128
|
+
const currentState = stateRef.current.v;
|
|
129
|
+
if (currentState.type === "data") {
|
|
112
130
|
return _isFn(onData)
|
|
113
|
-
? onData(
|
|
131
|
+
? onData(currentState.value)
|
|
114
132
|
: ((_a = onData) !== null && _a !== void 0 ? _a : null);
|
|
115
133
|
}
|
|
116
|
-
if (
|
|
134
|
+
if (currentState.type === "error") {
|
|
117
135
|
return _isFn(onError)
|
|
118
|
-
? onError(
|
|
136
|
+
? onError(currentState.value)
|
|
119
137
|
: ((_b = onError) !== null && _b !== void 0 ? _b : null);
|
|
120
138
|
}
|
|
121
139
|
return _isFn(onLoading) ? onLoading() : ((_c = onLoading) !== null && _c !== void 0 ? _c : null);
|
|
@@ -130,7 +148,42 @@ export function _makeBitProvider(context, bitP) {
|
|
|
130
148
|
return children();
|
|
131
149
|
}
|
|
132
150
|
const userCtrl = bitP.control(Object.assign(Object.assign({}, baseCtrl), { parameters: p, reload: _reload, consider: consider }));
|
|
133
|
-
|
|
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;
|
|
134
187
|
}
|
|
135
188
|
const ctrl = _make();
|
|
136
189
|
useEffect(() => {
|
|
@@ -153,7 +206,7 @@ export function _makeBitProvider(context, bitP) {
|
|
|
153
206
|
};
|
|
154
207
|
}, []);
|
|
155
208
|
// ========== DEFINE THE JSX ELEMENT ==========
|
|
156
|
-
return
|
|
209
|
+
return _jsx(context.Provider, { value: ctrl, children: p.children });
|
|
157
210
|
}
|
|
158
211
|
return _BitProvider;
|
|
159
212
|
}
|
package/dist/index.js
CHANGED
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
|
/**
|