@civet/events 2.0.4 → 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/eventPlugin.d.ts +21 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +81 -69
- package/package.json +4 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GenericDataProviderImplementation } from '@civet/core';
|
|
2
|
+
import { GenericEventReceiver, InferEvent, InferOptions } from './EventReceiver';
|
|
3
|
+
type EventProps<EventReceiverI extends GenericEventReceiver, OptionsI extends InferOptions<EventReceiverI> = InferOptions<EventReceiverI>, EventI extends InferEvent<EventReceiverI> = InferEvent<EventReceiverI>> = {
|
|
4
|
+
events?: {
|
|
5
|
+
/** EventReceiver to be used */
|
|
6
|
+
eventReceiver?: EventReceiverI;
|
|
7
|
+
/** Disables the event handler */
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/** Options for the EventReceiver */
|
|
10
|
+
options?: OptionsI;
|
|
11
|
+
/** Callback to filter events and handle your own event logic - if true is returned, the event does not cause the resource to update */
|
|
12
|
+
onEvent?: (event: EventI) => boolean;
|
|
13
|
+
/** Provides information on when the resource has been requested to update - events contains the events that lead to the update */
|
|
14
|
+
onNotify?: (next: {
|
|
15
|
+
request: string;
|
|
16
|
+
revision: string;
|
|
17
|
+
}, events: EventI[]) => void;
|
|
18
|
+
} | boolean;
|
|
19
|
+
};
|
|
20
|
+
declare const eventPlugin: import('@civet/core').DataProviderPlugin<GenericDataProviderImplementation, unknown, EventProps<GenericEventReceiver, unknown, unknown>, unknown, unknown, unknown>;
|
|
21
|
+
export default eventPlugin;
|
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
|
|
42
|
-
function
|
|
43
|
-
return E || (E = 1,
|
|
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
|
-
|
|
83
|
-
const
|
|
84
|
-
S(() => a == null ||
|
|
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
|
+
const m = !!(t || f?.isDisabled);
|
|
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,
|
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civet/events",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Civet",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Burmeister"
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"uuid": "^13.0.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@civet/core": ">=
|
|
53
|
+
"@civet/core": ">=6.0",
|
|
54
54
|
"react": ">=18.0",
|
|
55
55
|
"react-dom": ">=18.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@civet/core": "^
|
|
58
|
+
"@civet/core": "^6.0.2",
|
|
59
59
|
"@eslint/js": "^9.35.0",
|
|
60
60
|
"@types/react": "^19.1.12",
|
|
61
61
|
"@types/react-dom": "^19.1.9",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"react": "^19.1.1",
|
|
75
75
|
"react-dom": "^19.1.1",
|
|
76
76
|
"typescript": "^5.9.2",
|
|
77
|
-
"typescript-eslint": "^8.
|
|
77
|
+
"typescript-eslint": "^8.56.0",
|
|
78
78
|
"vite": "^7.1.5",
|
|
79
79
|
"vite-plugin-dts": "^4.5.4",
|
|
80
80
|
"vite-tsconfig-paths": "^6.1.1"
|