@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 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 R, useContext as j, useMemo as q, useState as y, useEffect as D } from "react";
2
- import { jsx as E, Fragment as S } from "react/jsx-runtime";
3
- import { useResourceContext as w } from "@civet/core";
4
- const l = R({});
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 J = l.Consumer, _ = () => j(l);
7
- function K(...r) {
8
- return (...e) => r.reduce(
9
- (t, n) => t || (typeof n == "function" ? n(...e) : !1),
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 F {
13
+ class H {
14
14
  _inferResource;
15
15
  _inferEvent;
16
16
  _inferOptions;
17
- subscribe(e, t, n) {
18
- if (typeof n != "function")
17
+ subscribe(e, t, r) {
18
+ if (typeof r != "function")
19
19
  throw new Error("Handler must be a function");
20
- const o = this.handleSubscribe(
20
+ const n = this.handleSubscribe(
21
21
  e,
22
22
  t,
23
- n
23
+ r
24
24
  );
25
- return typeof o != "function" && console.warn(
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
- ), o;
27
+ ), n;
28
28
  }
29
29
  }
30
- const L = (r) => r instanceof F;
31
- function Q({
32
- eventReceiver: r,
30
+ const Q = (o) => o instanceof H;
31
+ function T({
32
+ eventReceiver: o,
33
33
  children: e
34
34
  }) {
35
- const t = q(() => ({ eventReceiver: r }), [r]);
36
- return /* @__PURE__ */ E(l.Provider, { value: t, children: e });
35
+ const t = D(() => ({ eventReceiver: o }), [o]);
36
+ return /* @__PURE__ */ b(l.Provider, { value: t, children: e });
37
37
  }
38
- function H(r) {
39
- return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
38
+ function A(o) {
39
+ return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
40
40
  }
41
- var g, C;
42
- function A() {
43
- return C || (C = 1, g = function r(e, t) {
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 n, o, s;
47
+ var r, n, s;
48
48
  if (Array.isArray(e)) {
49
- if (n = e.length, n != t.length) return !1;
50
- for (o = n; o-- !== 0; )
51
- if (!r(e[o], t[o])) return !1;
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), n = s.length, n !== Object.keys(t).length) return !1;
58
- for (o = n; o-- !== 0; )
59
- if (!Object.prototype.hasOwnProperty.call(t, s[o])) return !1;
60
- for (o = n; o-- !== 0; ) {
61
- var u = s[o];
62
- if (!r(e[u], t[u])) return !1;
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 M = A();
70
- const P = /* @__PURE__ */ H(M);
71
- function B({
72
- eventReceiver: r,
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: n,
76
- onEvent: o,
75
+ options: r,
76
+ onEvent: n,
77
77
  onNotify: s
78
78
  }) {
79
- const u = _(), a = r || u.eventReceiver, b = w(), f = e || b, [c, O] = y(f);
80
- f?.request !== c?.request && O(f);
81
- const [p, h] = y(n);
82
- P(p, n) || h(n);
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
- D(() => a == null || m ? void 0 : a.subscribe(
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 o == "function" ? i = v.filter((d) => !o(d)) : i = v, i.length === 0 || typeof c?.notify != "function")
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 x = c.notify();
93
- typeof s == "function" && x.then((d) => s(d, i));
92
+ const R = c.notify();
93
+ typeof s == "function" && R.then((d) => s(d, i));
94
94
  }
95
- ), [a, m, c, p, o, s]);
95
+ ), [a, m, c, p, n, s]);
96
96
  }
97
- function T({
98
- eventReceiver: r,
97
+ function U({
98
+ eventReceiver: o,
99
99
  resource: e,
100
100
  disabled: t,
101
- options: n,
102
- onEvent: o,
101
+ options: r,
102
+ onEvent: n,
103
103
  onNotify: s,
104
104
  children: u
105
105
  }) {
106
- return B({
107
- eventReceiver: r,
106
+ return C({
107
+ eventReceiver: o,
108
108
  resource: e,
109
109
  disabled: t,
110
- options: n,
111
- onEvent: o,
110
+ options: r,
111
+ onEvent: n,
112
112
  onNotify: s
113
- }), /* @__PURE__ */ E(S, { children: u });
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
- J as ConfigConsumer,
117
- Q as ConfigProvider,
118
- T as EventHandler,
119
- F as EventReceiver,
120
- K as composeHandlers,
121
- L as isEventReceiver,
122
- _ as useConfigContext,
123
- B as useEventHandler
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.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Civet",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"