@civet/events 3.0.0 → 3.0.1
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/main.d.ts +1 -0
- package/dist/main.js +79 -67
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ConfigConsumer, useConfigContext } from './context';
|
|
|
2
2
|
export { default as composeHandlers } from './composeHandlers';
|
|
3
3
|
export { default as ConfigProvider } from './ConfigProvider';
|
|
4
4
|
export { default as EventHandler } from './EventHandler';
|
|
5
|
+
export { default as eventPlugin } from './eventPlugin';
|
|
5
6
|
export { default as EventReceiver, isEventReceiver } from './EventReceiver';
|
|
6
7
|
export type { EventReceiverImplementation, GenericEventReceiver, InferEvent, InferOptions, InferResource, } from './EventReceiver';
|
|
7
8
|
export { default as useEventHandler } from './useEventHandler';
|
package/dist/main.js
CHANGED
|
@@ -1,124 +1,136 @@
|
|
|
1
|
-
import { createContext as
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useResourceContext as
|
|
4
|
-
const l =
|
|
1
|
+
import { createContext as j, useContext as q, useMemo as D, useState as y, useEffect as S } from "react";
|
|
2
|
+
import { jsx as b, Fragment as w } from "react/jsx-runtime";
|
|
3
|
+
import { useResourceContext as P, createPlugin as _ } from "@civet/core";
|
|
4
|
+
const l = j({});
|
|
5
5
|
l.displayName = "Events.ConfigContext";
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return (...e) =>
|
|
9
|
-
(t,
|
|
6
|
+
const K = l.Consumer, F = () => q(l);
|
|
7
|
+
function L(...o) {
|
|
8
|
+
return (...e) => o.reduce(
|
|
9
|
+
(t, r) => t || (typeof r == "function" ? r(...e) : !1),
|
|
10
10
|
!1
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class H {
|
|
14
14
|
_inferResource;
|
|
15
15
|
_inferEvent;
|
|
16
16
|
_inferOptions;
|
|
17
|
-
subscribe(e, t,
|
|
18
|
-
if (typeof
|
|
17
|
+
subscribe(e, t, r) {
|
|
18
|
+
if (typeof r != "function")
|
|
19
19
|
throw new Error("Handler must be a function");
|
|
20
|
-
const
|
|
20
|
+
const n = this.handleSubscribe(
|
|
21
21
|
e,
|
|
22
22
|
t,
|
|
23
|
-
|
|
23
|
+
r
|
|
24
24
|
);
|
|
25
|
-
return typeof
|
|
25
|
+
return typeof n != "function" && console.warn(
|
|
26
26
|
"EventReceiver.handleSubscribe should return a callback to cancel the subscription. Ignoring this warning may result in the execution of obsolete handlers and potential memory leaks."
|
|
27
|
-
),
|
|
27
|
+
), n;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
function
|
|
32
|
-
eventReceiver:
|
|
30
|
+
const Q = (o) => o instanceof H;
|
|
31
|
+
function T({
|
|
32
|
+
eventReceiver: o,
|
|
33
33
|
children: e
|
|
34
34
|
}) {
|
|
35
|
-
const t =
|
|
36
|
-
return /* @__PURE__ */
|
|
35
|
+
const t = D(() => ({ eventReceiver: o }), [o]);
|
|
36
|
+
return /* @__PURE__ */ b(l.Provider, { value: t, children: e });
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
38
|
+
function A(o) {
|
|
39
|
+
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
40
40
|
}
|
|
41
|
-
var g,
|
|
42
|
-
function
|
|
43
|
-
return
|
|
41
|
+
var g, E;
|
|
42
|
+
function M() {
|
|
43
|
+
return E || (E = 1, g = function o(e, t) {
|
|
44
44
|
if (e === t) return !0;
|
|
45
45
|
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
46
46
|
if (e.constructor !== t.constructor) return !1;
|
|
47
|
-
var
|
|
47
|
+
var r, n, s;
|
|
48
48
|
if (Array.isArray(e)) {
|
|
49
|
-
if (
|
|
50
|
-
for (
|
|
51
|
-
if (!
|
|
49
|
+
if (r = e.length, r != t.length) return !1;
|
|
50
|
+
for (n = r; n-- !== 0; )
|
|
51
|
+
if (!o(e[n], t[n])) return !1;
|
|
52
52
|
return !0;
|
|
53
53
|
}
|
|
54
54
|
if (e.constructor === RegExp) return e.source === t.source && e.flags === t.flags;
|
|
55
55
|
if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === t.valueOf();
|
|
56
56
|
if (e.toString !== Object.prototype.toString) return e.toString() === t.toString();
|
|
57
|
-
if (s = Object.keys(e),
|
|
58
|
-
for (
|
|
59
|
-
if (!Object.prototype.hasOwnProperty.call(t, s[
|
|
60
|
-
for (
|
|
61
|
-
var u = s[
|
|
62
|
-
if (!
|
|
57
|
+
if (s = Object.keys(e), r = s.length, r !== Object.keys(t).length) return !1;
|
|
58
|
+
for (n = r; n-- !== 0; )
|
|
59
|
+
if (!Object.prototype.hasOwnProperty.call(t, s[n])) return !1;
|
|
60
|
+
for (n = r; n-- !== 0; ) {
|
|
61
|
+
var u = s[n];
|
|
62
|
+
if (!o(e[u], t[u])) return !1;
|
|
63
63
|
}
|
|
64
64
|
return !0;
|
|
65
65
|
}
|
|
66
66
|
return e !== e && t !== t;
|
|
67
67
|
}), g;
|
|
68
68
|
}
|
|
69
|
-
var
|
|
70
|
-
const
|
|
71
|
-
function
|
|
72
|
-
eventReceiver:
|
|
69
|
+
var B = M();
|
|
70
|
+
const I = /* @__PURE__ */ A(B);
|
|
71
|
+
function C({
|
|
72
|
+
eventReceiver: o,
|
|
73
73
|
resource: e,
|
|
74
74
|
disabled: t,
|
|
75
|
-
options:
|
|
76
|
-
onEvent:
|
|
75
|
+
options: r,
|
|
76
|
+
onEvent: n,
|
|
77
77
|
onNotify: s
|
|
78
78
|
}) {
|
|
79
|
-
const u =
|
|
80
|
-
f?.request !== c?.request &&
|
|
81
|
-
const [p,
|
|
82
|
-
|
|
79
|
+
const u = F(), a = o || u.eventReceiver, O = P(), f = e || O, [c, h] = y(f);
|
|
80
|
+
f?.request !== c?.request && h(f);
|
|
81
|
+
const [p, x] = y(r);
|
|
82
|
+
I(p, r) || x(r);
|
|
83
83
|
const m = !!(t || f?.isDisabled);
|
|
84
|
-
|
|
84
|
+
S(() => a == null || m ? void 0 : a.subscribe(
|
|
85
85
|
c,
|
|
86
86
|
p,
|
|
87
87
|
(v) => {
|
|
88
88
|
if ((v?.length || 0) === 0) return;
|
|
89
89
|
let i;
|
|
90
|
-
if (typeof
|
|
90
|
+
if (typeof n == "function" ? i = v.filter((d) => !n(d)) : i = v, i.length === 0 || typeof c?.notify != "function")
|
|
91
91
|
return;
|
|
92
|
-
const
|
|
93
|
-
typeof s == "function" &&
|
|
92
|
+
const R = c.notify();
|
|
93
|
+
typeof s == "function" && R.then((d) => s(d, i));
|
|
94
94
|
}
|
|
95
|
-
), [a, m, c, p,
|
|
95
|
+
), [a, m, c, p, n, s]);
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
eventReceiver:
|
|
97
|
+
function U({
|
|
98
|
+
eventReceiver: o,
|
|
99
99
|
resource: e,
|
|
100
100
|
disabled: t,
|
|
101
|
-
options:
|
|
102
|
-
onEvent:
|
|
101
|
+
options: r,
|
|
102
|
+
onEvent: n,
|
|
103
103
|
onNotify: s,
|
|
104
104
|
children: u
|
|
105
105
|
}) {
|
|
106
|
-
return
|
|
107
|
-
eventReceiver:
|
|
106
|
+
return C({
|
|
107
|
+
eventReceiver: o,
|
|
108
108
|
resource: e,
|
|
109
109
|
disabled: t,
|
|
110
|
-
options:
|
|
111
|
-
onEvent:
|
|
110
|
+
options: r,
|
|
111
|
+
onEvent: n,
|
|
112
112
|
onNotify: s
|
|
113
|
-
}), /* @__PURE__ */
|
|
113
|
+
}), /* @__PURE__ */ b(w, { children: u });
|
|
114
114
|
}
|
|
115
|
+
const V = _(
|
|
116
|
+
(o) => class extends o {
|
|
117
|
+
extend(t) {
|
|
118
|
+
t.context(
|
|
119
|
+
(r, { events: n = !1 }) => (C(
|
|
120
|
+
typeof n == "boolean" ? { disabled: !n, resource: r } : { ...n, resource: r }
|
|
121
|
+
), r)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
);
|
|
115
126
|
export {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
K as ConfigConsumer,
|
|
128
|
+
T as ConfigProvider,
|
|
129
|
+
U as EventHandler,
|
|
130
|
+
H as EventReceiver,
|
|
131
|
+
L as composeHandlers,
|
|
132
|
+
V as eventPlugin,
|
|
133
|
+
Q as isEventReceiver,
|
|
134
|
+
F as useConfigContext,
|
|
135
|
+
C as useEventHandler
|
|
124
136
|
};
|