@civet/events 3.0.1 → 4.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/EventHandler.d.ts +1 -1
- package/dist/EventReceiver.d.ts +7 -7
- package/dist/eventPlugin.d.ts +1 -1
- package/dist/main.js +81 -56
- package/dist/useEventHandler.d.ts +2 -2
- package/package.json +3 -3
package/dist/EventHandler.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { GenericEventReceiver, InferEvent, InferOptions, InferResource } from '.
|
|
|
7
7
|
*
|
|
8
8
|
* onEvent can be used to directly access events allowing you to add custom event logic to your components.
|
|
9
9
|
*/
|
|
10
|
-
export default function EventHandler<EventReceiverI extends GenericEventReceiver,
|
|
10
|
+
export default function EventHandler<EventReceiverI extends GenericEventReceiver, EventI extends InferEvent<EventReceiverI> = InferEvent<EventReceiverI>, ResourceI extends InferResource<EventReceiverI> = InferResource<EventReceiverI>, OptionsI extends InferOptions<EventReceiverI> = InferOptions<EventReceiverI>>({ eventReceiver, resource, disabled, options, onEvent, onNotify, children, }: {
|
|
11
11
|
/** EventReceiver to be used */
|
|
12
12
|
eventReceiver?: EventReceiverI;
|
|
13
13
|
/** ResourceContext to be used */
|
package/dist/EventReceiver.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Constructor, GenericDataProvider, ResourceContextValue } from '@civet/core';
|
|
2
|
-
export default abstract class EventReceiver<Resource extends ResourceContextValue<GenericDataProvider>,
|
|
3
|
-
readonly _inferResource: Resource;
|
|
1
|
+
import { Notifier, Constructor, GenericDataProvider, ResourceContextValue } from '@civet/core';
|
|
2
|
+
export default abstract class EventReceiver<Event, Resource extends ResourceContextValue<GenericDataProvider>, Options> {
|
|
4
3
|
readonly _inferEvent: Event;
|
|
4
|
+
readonly _inferResource: Resource;
|
|
5
5
|
readonly _inferOptions: Options;
|
|
6
|
-
subscribe<
|
|
7
|
-
abstract handleSubscribe(resource: Resource
|
|
6
|
+
subscribe<EventI extends Event = Event, ResourceI extends Resource = Resource, OptionsI extends Options = Options>(resource: Notifier<[ResourceI | undefined]> | undefined, options: OptionsI | undefined, handler: (events: EventI[]) => void): () => void;
|
|
7
|
+
abstract handleSubscribe(resource: Notifier<[Resource | undefined]>, options: Options | undefined, handler: (events: Event[]) => void): () => void;
|
|
8
8
|
}
|
|
9
9
|
export declare const isEventReceiver: (eventReceiver: unknown) => boolean;
|
|
10
10
|
export type EventReceiverImplementation<EventReceiverI extends GenericEventReceiver, ConstructorArgs extends any[]> = Constructor<ConstructorArgs, EventReceiverI & {
|
|
11
11
|
handleSubscribe(resource: InferResource<EventReceiverI>, options: InferOptions<EventReceiverI> | undefined, handler: (events: InferEvent<EventReceiverI>[]) => void): () => void;
|
|
12
12
|
}>;
|
|
13
|
-
export type GenericEventReceiver = EventReceiver<ResourceContextValue<GenericDataProvider>, unknown
|
|
14
|
-
export type InferResource<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferResource'];
|
|
13
|
+
export type GenericEventReceiver = EventReceiver<unknown, ResourceContextValue<GenericDataProvider>, unknown>;
|
|
15
14
|
export type InferEvent<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferEvent'];
|
|
15
|
+
export type InferResource<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferResource'];
|
|
16
16
|
export type InferOptions<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferOptions'];
|
package/dist/eventPlugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GenericDataProviderImplementation } from '@civet/core';
|
|
2
2
|
import { GenericEventReceiver, InferEvent, InferOptions } from './EventReceiver';
|
|
3
|
-
type EventProps<EventReceiverI extends GenericEventReceiver,
|
|
3
|
+
type EventProps<EventReceiverI extends GenericEventReceiver, EventI extends InferEvent<EventReceiverI> = InferEvent<EventReceiverI>, OptionsI extends InferOptions<EventReceiverI> = InferOptions<EventReceiverI>> = {
|
|
4
4
|
events?: {
|
|
5
5
|
/** EventReceiver to be used */
|
|
6
6
|
eventReceiver?: EventReceiverI;
|
package/dist/main.js
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
|
-
import { createContext as
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useResourceContext as
|
|
4
|
-
const l =
|
|
1
|
+
import { createContext as P, useContext as N, useMemo as A, useState as y, useEffect as h } from "react";
|
|
2
|
+
import { jsx as x, Fragment as M } from "react/jsx-runtime";
|
|
3
|
+
import { Notifier as j, useResourceContext as B, createPlugin as I } from "@civet/core";
|
|
4
|
+
const l = P({});
|
|
5
5
|
l.displayName = "Events.ConfigContext";
|
|
6
|
-
const
|
|
7
|
-
function
|
|
6
|
+
const V = l.Consumer, k = () => N(l);
|
|
7
|
+
function W(...o) {
|
|
8
8
|
return (...e) => o.reduce(
|
|
9
9
|
(t, r) => t || (typeof r == "function" ? r(...e) : !1),
|
|
10
10
|
!1
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
-
class
|
|
14
|
-
_inferResource;
|
|
13
|
+
class z {
|
|
15
14
|
_inferEvent;
|
|
15
|
+
_inferResource;
|
|
16
16
|
_inferOptions;
|
|
17
17
|
subscribe(e, t, r) {
|
|
18
18
|
if (typeof r != "function")
|
|
19
19
|
throw new Error("Handler must be a function");
|
|
20
|
-
const n =
|
|
20
|
+
const n = e != null;
|
|
21
|
+
n || (e = new j());
|
|
22
|
+
const s = this.handleSubscribe(
|
|
21
23
|
e,
|
|
22
24
|
t,
|
|
23
25
|
r
|
|
24
26
|
);
|
|
25
|
-
return typeof
|
|
27
|
+
return n || e?.trigger(void 0), typeof s != "function" && console.warn(
|
|
26
28
|
"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
|
-
),
|
|
29
|
+
), s;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
const
|
|
31
|
-
function
|
|
32
|
+
const X = (o) => o instanceof z;
|
|
33
|
+
function Y({
|
|
32
34
|
eventReceiver: o,
|
|
33
35
|
children: e
|
|
34
36
|
}) {
|
|
35
|
-
const t =
|
|
36
|
-
return /* @__PURE__ */
|
|
37
|
+
const t = A(() => ({ eventReceiver: o }), [o]);
|
|
38
|
+
return /* @__PURE__ */ x(l.Provider, { value: t, children: e });
|
|
37
39
|
}
|
|
38
|
-
function
|
|
40
|
+
function G(o) {
|
|
39
41
|
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
|
40
42
|
}
|
|
41
|
-
var
|
|
42
|
-
function
|
|
43
|
-
return
|
|
43
|
+
var E, q;
|
|
44
|
+
function J() {
|
|
45
|
+
return q || (q = 1, E = function o(e, t) {
|
|
44
46
|
if (e === t) return !0;
|
|
45
47
|
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
46
48
|
if (e.constructor !== t.constructor) return !1;
|
|
@@ -58,17 +60,17 @@ function M() {
|
|
|
58
60
|
for (n = r; n-- !== 0; )
|
|
59
61
|
if (!Object.prototype.hasOwnProperty.call(t, s[n])) return !1;
|
|
60
62
|
for (n = r; n-- !== 0; ) {
|
|
61
|
-
var
|
|
62
|
-
if (!o(e[
|
|
63
|
+
var c = s[n];
|
|
64
|
+
if (!o(e[c], t[c])) return !1;
|
|
63
65
|
}
|
|
64
66
|
return !0;
|
|
65
67
|
}
|
|
66
68
|
return e !== e && t !== t;
|
|
67
|
-
}),
|
|
69
|
+
}), E;
|
|
68
70
|
}
|
|
69
|
-
var
|
|
70
|
-
const
|
|
71
|
-
function
|
|
71
|
+
var K = J();
|
|
72
|
+
const L = /* @__PURE__ */ G(K);
|
|
73
|
+
function w({
|
|
72
74
|
eventReceiver: o,
|
|
73
75
|
resource: e,
|
|
74
76
|
disabled: t,
|
|
@@ -76,47 +78,70 @@ function C({
|
|
|
76
78
|
onEvent: n,
|
|
77
79
|
onNotify: s
|
|
78
80
|
}) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
typeof s == "function" && R.then((d) => s(d, i));
|
|
81
|
+
const c = k(), a = o || c.eventReceiver, D = B(), u = e === null ? void 0 : e || D, [i, S] = y(
|
|
82
|
+
u
|
|
83
|
+
);
|
|
84
|
+
u?.request !== i?.request && S(u);
|
|
85
|
+
const [p, _] = y(r);
|
|
86
|
+
L(p, r) || _(r);
|
|
87
|
+
const C = !!(t || u?.isDisabled), [
|
|
88
|
+
[R, b, v] = [],
|
|
89
|
+
O
|
|
90
|
+
] = y();
|
|
91
|
+
h(() => {
|
|
92
|
+
if (a == null || C) {
|
|
93
|
+
O(void 0);
|
|
94
|
+
return;
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
+
const d = new j(), F = a.subscribe(
|
|
97
|
+
d,
|
|
98
|
+
p,
|
|
99
|
+
(g) => {
|
|
100
|
+
if ((g?.length || 0) === 0) return;
|
|
101
|
+
let f;
|
|
102
|
+
if (typeof n == "function" ? f = g.filter((m) => !n(m)) : f = g, f.length === 0 || typeof i?.notify != "function")
|
|
103
|
+
return;
|
|
104
|
+
const H = i.notify();
|
|
105
|
+
typeof s == "function" && H.then((m) => s(m, f));
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
return d.trigger(i), O([
|
|
109
|
+
i?.request,
|
|
110
|
+
i?.revision,
|
|
111
|
+
d
|
|
112
|
+
]), F;
|
|
113
|
+
}, [a, C, i, p, n, s]), h(() => {
|
|
114
|
+
v == null || u?.request !== R || u?.revision === b || v.trigger(u);
|
|
115
|
+
}, [
|
|
116
|
+
v,
|
|
117
|
+
u,
|
|
118
|
+
R,
|
|
119
|
+
b
|
|
120
|
+
]);
|
|
96
121
|
}
|
|
97
|
-
function
|
|
122
|
+
function Z({
|
|
98
123
|
eventReceiver: o,
|
|
99
124
|
resource: e,
|
|
100
125
|
disabled: t,
|
|
101
126
|
options: r,
|
|
102
127
|
onEvent: n,
|
|
103
128
|
onNotify: s,
|
|
104
|
-
children:
|
|
129
|
+
children: c
|
|
105
130
|
}) {
|
|
106
|
-
return
|
|
131
|
+
return w({
|
|
107
132
|
eventReceiver: o,
|
|
108
133
|
resource: e,
|
|
109
134
|
disabled: t,
|
|
110
135
|
options: r,
|
|
111
136
|
onEvent: n,
|
|
112
137
|
onNotify: s
|
|
113
|
-
}), /* @__PURE__ */
|
|
138
|
+
}), /* @__PURE__ */ x(M, { children: c });
|
|
114
139
|
}
|
|
115
|
-
const
|
|
140
|
+
const $ = I(
|
|
116
141
|
(o) => class extends o {
|
|
117
142
|
extend(t) {
|
|
118
143
|
t.context(
|
|
119
|
-
(r, { events: n = !1 }) => (
|
|
144
|
+
(r, { events: n = !1 }) => (w(
|
|
120
145
|
typeof n == "boolean" ? { disabled: !n, resource: r } : { ...n, resource: r }
|
|
121
146
|
), r)
|
|
122
147
|
);
|
|
@@ -124,13 +149,13 @@ const V = _(
|
|
|
124
149
|
}
|
|
125
150
|
);
|
|
126
151
|
export {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
V as ConfigConsumer,
|
|
153
|
+
Y as ConfigProvider,
|
|
154
|
+
Z as EventHandler,
|
|
155
|
+
z as EventReceiver,
|
|
156
|
+
W as composeHandlers,
|
|
157
|
+
$ as eventPlugin,
|
|
158
|
+
X as isEventReceiver,
|
|
159
|
+
k as useConfigContext,
|
|
160
|
+
w as useEventHandler
|
|
136
161
|
};
|
|
@@ -6,11 +6,11 @@ import { GenericEventReceiver, InferEvent, InferOptions, InferResource } from '.
|
|
|
6
6
|
*
|
|
7
7
|
* onEvent can be used to directly access events allowing you to add custom event logic to your components.
|
|
8
8
|
*/
|
|
9
|
-
export default function useEventHandler<EventReceiverI extends GenericEventReceiver,
|
|
9
|
+
export default function useEventHandler<EventReceiverI extends GenericEventReceiver, EventI extends InferEvent<EventReceiverI> = InferEvent<EventReceiverI>, ResourceI extends InferResource<EventReceiverI> = InferResource<EventReceiverI>, OptionsI extends InferOptions<EventReceiverI> = InferOptions<EventReceiverI>>({ eventReceiver: eventReceiverProp, resource: resourceProp, disabled, options: optionsProp, onEvent, onNotify, }: {
|
|
10
10
|
/** EventReceiver to be used */
|
|
11
11
|
eventReceiver?: EventReceiverI;
|
|
12
12
|
/** ResourceContext to be used */
|
|
13
|
-
resource?: ResourceI;
|
|
13
|
+
resource?: ResourceI | null;
|
|
14
14
|
/** Disables the event handler */
|
|
15
15
|
disabled?: boolean;
|
|
16
16
|
/** Options for the EventReceiver */
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civet/events",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Civet",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Burmeister"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/civet-org/events.git"
|
|
10
|
+
"url": "git+https://github.com/civet-org/events.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/civet-org/events/issues"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"react-dom": ">=18.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@civet/core": "^6.
|
|
58
|
+
"@civet/core": "^6.1.1",
|
|
59
59
|
"@eslint/js": "^9.35.0",
|
|
60
60
|
"@types/react": "^19.1.12",
|
|
61
61
|
"@types/react-dom": "^19.1.9",
|