@code0-tech/pictor 0.0.0-mvp.5 → 0.0.0-mvp.6
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.
|
@@ -18,5 +18,5 @@ export declare class ReactiveArrayService<T> implements ArrayService<T> {
|
|
|
18
18
|
}
|
|
19
19
|
type ArrayServiceCtor<K, S extends ArrayService<K>> = new (access: ReactiveArrayStore<K>) => S;
|
|
20
20
|
type InitialArg<K, S extends ArrayService<K>> = K[] | ((svc: S) => K[]);
|
|
21
|
-
export declare function useReactiveArrayService<K, S extends ArrayService<K>>(Ctor: ArrayServiceCtor<K, S
|
|
21
|
+
export declare function useReactiveArrayService<K, S extends ArrayService<K>>(Ctor: ArrayServiceCtor<K, S> | ((store: ReactiveArrayStore<K>) => S), initial?: InitialArg<K, S>): [K[], S];
|
|
22
22
|
export {};
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
return (e =
|
|
1
|
+
import n, { startTransition as a } from "react";
|
|
2
|
+
function v(t, e, r) {
|
|
3
|
+
return (e = y(e)) in t ? Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : t[e] = r, t;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
var e =
|
|
5
|
+
function y(t) {
|
|
6
|
+
var e = h(t, "string");
|
|
7
7
|
return typeof e == "symbol" ? e : e + "";
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
if (typeof
|
|
11
|
-
var
|
|
12
|
-
if (
|
|
13
|
-
var s =
|
|
9
|
+
function h(t, e) {
|
|
10
|
+
if (typeof t != "object" || !t) return t;
|
|
11
|
+
var r = t[Symbol.toPrimitive];
|
|
12
|
+
if (r !== void 0) {
|
|
13
|
+
var s = r.call(t, e);
|
|
14
14
|
if (typeof s != "object") return s;
|
|
15
15
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
16
16
|
}
|
|
17
|
-
return (e === "string" ? String : Number)(
|
|
17
|
+
return (e === "string" ? String : Number)(t);
|
|
18
18
|
}
|
|
19
|
-
class
|
|
19
|
+
class b {
|
|
20
20
|
constructor(e) {
|
|
21
|
-
|
|
21
|
+
v(this, "access", void 0), this.access = e;
|
|
22
22
|
}
|
|
23
23
|
delete(e) {
|
|
24
|
-
|
|
25
|
-
this.access.setState((
|
|
24
|
+
a(() => {
|
|
25
|
+
this.access.setState((r) => r.filter((s, c) => c !== e));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
add(e) {
|
|
29
|
-
|
|
30
|
-
this.access.setState((
|
|
29
|
+
a(() => {
|
|
30
|
+
this.access.setState((r) => [...r, e]);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
set(e,
|
|
34
|
-
|
|
33
|
+
set(e, r) {
|
|
34
|
+
a(() => {
|
|
35
35
|
this.access.setState((s) => {
|
|
36
36
|
const c = s.slice();
|
|
37
|
-
return c[e] =
|
|
37
|
+
return c[e] = r, c;
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
has(e) {
|
|
42
|
-
const
|
|
43
|
-
return e >= 0 && e <
|
|
42
|
+
const r = this.access.getState();
|
|
43
|
+
return e >= 0 && e < r.length;
|
|
44
44
|
}
|
|
45
45
|
get(e) {
|
|
46
46
|
return this.access.getState()[e];
|
|
@@ -49,33 +49,43 @@ class y {
|
|
|
49
49
|
return this.access.getState();
|
|
50
50
|
}
|
|
51
51
|
update() {
|
|
52
|
-
|
|
52
|
+
a(() => {
|
|
53
53
|
this.access.setState((e) => e.slice());
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
clear() {
|
|
57
|
-
|
|
57
|
+
a(() => {
|
|
58
58
|
this.access.setState(() => []);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
const [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
function g(t, e = []) {
|
|
63
|
+
const [r, s] = n.useState(Array.isArray(e) ? e : []), c = n.useRef(r);
|
|
64
|
+
n.useEffect(() => {
|
|
65
|
+
c.current = r;
|
|
66
|
+
}, [r]);
|
|
67
|
+
const u = n.useCallback(() => c.current, []), o = n.useMemo(() => {
|
|
68
|
+
const i = {
|
|
69
|
+
getState: u,
|
|
70
|
+
setState: s
|
|
71
|
+
}, f = {
|
|
72
|
+
construct() {
|
|
73
|
+
return f;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return ((l) => {
|
|
77
|
+
try {
|
|
78
|
+
return !!new new Proxy(l, f)();
|
|
79
|
+
} catch {
|
|
80
|
+
return !1;
|
|
81
|
+
}
|
|
82
|
+
})(t) ? new t(i) : t(i);
|
|
83
|
+
}, [t, u, s]);
|
|
84
|
+
return n.useEffect(() => {
|
|
85
|
+
typeof e == "function" && s(e(o));
|
|
86
|
+
}, [o, e]), [r, o];
|
|
77
87
|
}
|
|
78
88
|
export {
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
b as ReactiveArrayService,
|
|
90
|
+
g as useReactiveArrayService
|
|
81
91
|
};
|