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.
@@ -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
- // if it's the same data, don't update
29
- if (state.v.type === "data" && state.v.value === d)
30
- return;
31
- setState({
32
- history: bitP.useHistory ? [...state.history, d] : [],
33
- v: { type: "data", value: d },
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({}, state), { v: { type: "loading" } })),
37
- setError: (e) => setState(Object.assign(Object.assign({}, state), { v: { type: "error", value: e } })),
38
- canGoBack: !!(bitP.useHistory && state.history.length > 1),
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
- if (state.history.length < 2)
43
- return false;
44
- const newHistory = state.history.slice(0, -1);
45
- const newData = newHistory[newHistory.length - 1];
46
- setState({
47
- history: newHistory,
48
- v: { type: "data", value: newData },
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 true;
61
+ return didGoBack;
51
62
  },
52
- state: state.v.type,
53
- isData: state.v.type === "data",
54
- isLoading: state.v.type === "loading",
55
- isError: state.v.type === "error",
56
- data: state.v.type === "data" ? state.v.value : undefined,
57
- error: state.v.type === "error" ? state.v.value : undefined,
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 = _partCtrl.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
- if (state.v.type === "data") {
128
+ const currentState = stateRef.current.v;
129
+ if (currentState.type === "data") {
112
130
  return _isFn(onData)
113
- ? onData(state.v.value)
131
+ ? onData(currentState.value)
114
132
  : ((_a = onData) !== null && _a !== void 0 ? _a : null);
115
133
  }
116
- if (state.v.type === "error") {
134
+ if (currentState.type === "error") {
117
135
  return _isFn(onError)
118
- ? onError(state.v.value)
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
- return Object.assign(Object.assign(Object.assign({}, baseCtrl), userCtrl), { reload: _reload, parameters: p, consider: consider });
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 (_jsx(context.Provider, { value: Object.assign({}, ctrl), children: p.children }));
209
+ return _jsx(context.Provider, { value: ctrl, children: p.children });
157
210
  }
158
211
  return _BitProvider;
159
212
  }
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as Lucide from "lucide-react";
3
+ //@ts-ignore
3
4
  import "./elbe.css";
4
5
  export * as Wouter from "wouter";
5
6
  export * as wouter_hash from "wouter/use-hash-location";
@@ -1,4 +1,4 @@
1
- import { ColorSelection, ElbeChildren } from "../../..";
1
+ import { ColorSelection, Dict, ElbeChildren } from "../../..";
2
2
  declare const _dialogs: {
3
3
  showConfirmDialog: DialogsConfig<{
4
4
  message: string;
@@ -1,3 +1,4 @@
1
+ import { Dict } from "../../util/util";
1
2
  import { ElbeSubThemeData } from "../theme";
2
3
  export type TypeStyle<T extends Dict<any> = {}> = T & {
3
4
  bold?: boolean;
@@ -1,3 +1,4 @@
1
+ import { Dict } from "../../../../..";
1
2
  export type ElbeColor<T extends string, Data extends Dict<any>, Computed extends Dict<any>> = {
2
3
  type: [T, ...string[]];
3
4
  } & Data & Computed;
@@ -1,4 +1,4 @@
1
- import "../../elbe.css";
1
+ import { Dict } from "../..";
2
2
  export type ElbeSubThemeData<Computed extends Dict<any>, Seed extends Dict<any> = Computed, Config extends Dict<any> = Computed> = {
3
3
  seed: Seed;
4
4
  _configType: Config;
@@ -1,4 +1,5 @@
1
- import "../../elbe.css";
1
+ //@ts-ignore
2
+ //import "./elbe.css";
2
3
  import { geometryThemeData } from "./subthemes/_theme_geometry";
3
4
  import { menuThemeData } from "./subthemes/_theme_menu";
4
5
  import { motionThemeData } from "./subthemes/_theme_motion";
@@ -1 +1,2 @@
1
+ import { Dict } from "../..";
1
2
  export declare function deepMerge<T extends Dict<any>>(original: T, toMerge: Partial<T>, depth?: number): T;
@@ -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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {