@xyo-network/react-event 2.81.9 → 2.82.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/hooks/index.d.cts +2 -2
- package/dist/browser/hooks/index.d.mts +2 -2
- package/dist/browser/hooks/index.d.ts +2 -2
- package/dist/browser/hooks/useCustomEvent.d.cts.map +1 -1
- package/dist/browser/hooks/useCustomEvent.d.mts.map +1 -1
- package/dist/browser/hooks/useCustomEvent.d.ts.map +1 -1
- package/dist/browser/index.cjs +25 -18
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.mts +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/{index.js → index.mjs} +28 -19
- package/dist/browser/index.mjs.map +1 -0
- package/dist/neutral/hooks/index.d.cts +2 -2
- package/dist/neutral/hooks/index.d.mts +2 -2
- package/dist/neutral/hooks/index.d.ts +2 -2
- package/dist/neutral/hooks/useCustomEvent.d.cts.map +1 -1
- package/dist/neutral/hooks/useCustomEvent.d.mts.map +1 -1
- package/dist/neutral/hooks/useCustomEvent.d.ts.map +1 -1
- package/dist/neutral/index.cjs +25 -18
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.d.cts +1 -1
- package/dist/neutral/index.d.mts +1 -1
- package/dist/neutral/index.d.ts +1 -1
- package/dist/neutral/{index.js → index.mjs} +28 -19
- package/dist/neutral/index.mjs.map +1 -0
- package/dist/node/hooks/index.d.cts +2 -2
- package/dist/node/hooks/index.d.mts +2 -2
- package/dist/node/hooks/index.d.ts +2 -2
- package/dist/node/hooks/useCustomEvent.d.cts.map +1 -1
- package/dist/node/hooks/useCustomEvent.d.mts.map +1 -1
- package/dist/node/hooks/useCustomEvent.d.ts.map +1 -1
- package/dist/node/index.cjs +25 -18
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -1
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/{index.js → index.mjs} +28 -19
- package/dist/node/index.mjs.map +1 -0
- package/package.json +7 -7
- package/src/hooks/index.ts +2 -2
- package/src/hooks/useCustomEvent.ts +10 -9
- package/src/hooks/useEvent.ts +6 -6
- package/src/index.ts +1 -1
- package/dist/browser/index.js.map +0 -1
- package/dist/neutral/index.js.map +0 -1
- package/dist/node/index.js.map +0 -1
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
6
7
|
var __export = (target, all) => {
|
7
8
|
for (var name in all)
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -28,7 +29,7 @@ module.exports = __toCommonJS(src_exports);
|
|
28
29
|
// src/hooks/useCustomEvent.ts
|
29
30
|
var import_assert = require("@xylabs/assert");
|
30
31
|
var import_react = require("react");
|
31
|
-
var useCustomEvent = (type, listener, customRef) => {
|
32
|
+
var useCustomEvent = /* @__PURE__ */ __name((type, listener, customRef) => {
|
32
33
|
const ref = customRef ?? (0, import_react.createRef)();
|
33
34
|
(0, import_react.useEffect)(() => {
|
34
35
|
const element = ref?.current;
|
@@ -49,7 +50,7 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
49
50
|
}
|
50
51
|
};
|
51
52
|
});
|
52
|
-
const dispatch = (detail) => {
|
53
|
+
const dispatch = /* @__PURE__ */ __name((detail) => {
|
53
54
|
const event = new CustomEvent(type, {
|
54
55
|
bubbles: true,
|
55
56
|
cancelable: true,
|
@@ -57,22 +58,28 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
57
58
|
detail
|
58
59
|
});
|
59
60
|
ref.current?.dispatchEvent(event);
|
60
|
-
};
|
61
|
-
return [
|
62
|
-
|
61
|
+
}, "dispatch");
|
62
|
+
return [
|
63
|
+
ref,
|
64
|
+
dispatch
|
65
|
+
];
|
66
|
+
}, "useCustomEvent");
|
63
67
|
|
64
68
|
// src/hooks/useEvent.ts
|
65
|
-
var useEvent = (listener, sharableRef) => {
|
66
|
-
const [ref, customDispatch] = useCustomEvent(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
};
|
76
|
-
return [
|
77
|
-
|
69
|
+
var useEvent = /* @__PURE__ */ __name((listener, sharableRef) => {
|
70
|
+
const [ref, customDispatch] = useCustomEvent("xyo", listener ? (detail) => {
|
71
|
+
return listener(detail.noun, detail.verb, detail.data);
|
72
|
+
} : void 0, sharableRef);
|
73
|
+
const dispatch = /* @__PURE__ */ __name((noun, verb, data) => {
|
74
|
+
return customDispatch({
|
75
|
+
data,
|
76
|
+
noun,
|
77
|
+
verb
|
78
|
+
});
|
79
|
+
}, "dispatch");
|
80
|
+
return [
|
81
|
+
ref,
|
82
|
+
dispatch
|
83
|
+
];
|
84
|
+
}, "useEvent");
|
78
85
|
//# sourceMappingURL=index.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,mBAAgD;AAIzC,IAAMA,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,iBAAaE,wBAAAA;AACzBC,8BAAU,MAAA;AACR,UAAMC,UAAUH,KAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,aAASC,wBAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,eAASU,iBAAiBhB,MAAMS,OAAAA;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,iBAASW,oBAAoBjB,MAAMS,OAAAA;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAC9C,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,QAAII,SAASgB,cAAcb,KAAAA;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
|
package/dist/browser/index.d.cts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/browser/index.d.mts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/browser/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,7 +1,10 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
3
|
+
|
1
4
|
// src/hooks/useCustomEvent.ts
|
2
5
|
import { assertEx } from "@xylabs/assert";
|
3
6
|
import { createRef, useEffect } from "react";
|
4
|
-
var useCustomEvent = (type, listener, customRef) => {
|
7
|
+
var useCustomEvent = /* @__PURE__ */ __name((type, listener, customRef) => {
|
5
8
|
const ref = customRef ?? createRef();
|
6
9
|
useEffect(() => {
|
7
10
|
const element = ref?.current;
|
@@ -22,7 +25,7 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
22
25
|
}
|
23
26
|
};
|
24
27
|
});
|
25
|
-
const dispatch = (detail) => {
|
28
|
+
const dispatch = /* @__PURE__ */ __name((detail) => {
|
26
29
|
const event = new CustomEvent(type, {
|
27
30
|
bubbles: true,
|
28
31
|
cancelable: true,
|
@@ -30,26 +33,32 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
30
33
|
detail
|
31
34
|
});
|
32
35
|
ref.current?.dispatchEvent(event);
|
33
|
-
};
|
34
|
-
return [
|
35
|
-
|
36
|
+
}, "dispatch");
|
37
|
+
return [
|
38
|
+
ref,
|
39
|
+
dispatch
|
40
|
+
];
|
41
|
+
}, "useCustomEvent");
|
36
42
|
|
37
43
|
// src/hooks/useEvent.ts
|
38
|
-
var useEvent = (listener, sharableRef) => {
|
39
|
-
const [ref, customDispatch] = useCustomEvent(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
};
|
49
|
-
return [
|
50
|
-
|
44
|
+
var useEvent = /* @__PURE__ */ __name((listener, sharableRef) => {
|
45
|
+
const [ref, customDispatch] = useCustomEvent("xyo", listener ? (detail) => {
|
46
|
+
return listener(detail.noun, detail.verb, detail.data);
|
47
|
+
} : void 0, sharableRef);
|
48
|
+
const dispatch = /* @__PURE__ */ __name((noun, verb, data) => {
|
49
|
+
return customDispatch({
|
50
|
+
data,
|
51
|
+
noun,
|
52
|
+
verb
|
53
|
+
});
|
54
|
+
}, "dispatch");
|
55
|
+
return [
|
56
|
+
ref,
|
57
|
+
dispatch
|
58
|
+
];
|
59
|
+
}, "useEvent");
|
51
60
|
export {
|
52
61
|
useCustomEvent,
|
53
62
|
useEvent
|
54
63
|
};
|
55
|
-
//# sourceMappingURL=index.
|
64
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,WAAsBC,iBAAiB;AAIzC,IAAMC,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,aAAaE,UAAAA;AACzBC,YAAU,MAAA;AACR,UAAMC,UAAUH,KAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,SAASC,SAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,eAASU,iBAAiBhB,MAAMS,OAAAA;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,iBAASW,oBAAoBjB,MAAMS,OAAAA;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAC9C,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,QAAII,SAASgB,cAAcb,KAAAA;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["assertEx","createRef","useEffect","useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
package/dist/neutral/index.cjs
CHANGED
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
6
7
|
var __export = (target, all) => {
|
7
8
|
for (var name in all)
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -28,7 +29,7 @@ module.exports = __toCommonJS(src_exports);
|
|
28
29
|
// src/hooks/useCustomEvent.ts
|
29
30
|
var import_assert = require("@xylabs/assert");
|
30
31
|
var import_react = require("react");
|
31
|
-
var useCustomEvent = (type, listener, customRef) => {
|
32
|
+
var useCustomEvent = /* @__PURE__ */ __name((type, listener, customRef) => {
|
32
33
|
const ref = customRef ?? (0, import_react.createRef)();
|
33
34
|
(0, import_react.useEffect)(() => {
|
34
35
|
const element = ref?.current;
|
@@ -49,7 +50,7 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
49
50
|
}
|
50
51
|
};
|
51
52
|
});
|
52
|
-
const dispatch = (detail) => {
|
53
|
+
const dispatch = /* @__PURE__ */ __name((detail) => {
|
53
54
|
const event = new CustomEvent(type, {
|
54
55
|
bubbles: true,
|
55
56
|
cancelable: true,
|
@@ -57,22 +58,28 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
57
58
|
detail
|
58
59
|
});
|
59
60
|
ref.current?.dispatchEvent(event);
|
60
|
-
};
|
61
|
-
return [
|
62
|
-
|
61
|
+
}, "dispatch");
|
62
|
+
return [
|
63
|
+
ref,
|
64
|
+
dispatch
|
65
|
+
];
|
66
|
+
}, "useCustomEvent");
|
63
67
|
|
64
68
|
// src/hooks/useEvent.ts
|
65
|
-
var useEvent = (listener, sharableRef) => {
|
66
|
-
const [ref, customDispatch] = useCustomEvent(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
};
|
76
|
-
return [
|
77
|
-
|
69
|
+
var useEvent = /* @__PURE__ */ __name((listener, sharableRef) => {
|
70
|
+
const [ref, customDispatch] = useCustomEvent("xyo", listener ? (detail) => {
|
71
|
+
return listener(detail.noun, detail.verb, detail.data);
|
72
|
+
} : void 0, sharableRef);
|
73
|
+
const dispatch = /* @__PURE__ */ __name((noun, verb, data) => {
|
74
|
+
return customDispatch({
|
75
|
+
data,
|
76
|
+
noun,
|
77
|
+
verb
|
78
|
+
});
|
79
|
+
}, "dispatch");
|
80
|
+
return [
|
81
|
+
ref,
|
82
|
+
dispatch
|
83
|
+
];
|
84
|
+
}, "useEvent");
|
78
85
|
//# sourceMappingURL=index.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,mBAAgD;AAIzC,IAAMA,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,iBAAaE,wBAAAA;AACzBC,8BAAU,MAAA;AACR,UAAMC,UAAUH,KAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,aAASC,wBAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,eAASU,iBAAiBhB,MAAMS,OAAAA;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,iBAASW,oBAAoBjB,MAAMS,OAAAA;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAC9C,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,QAAII,SAASgB,cAAcb,KAAAA;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
|
package/dist/neutral/index.d.cts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/neutral/index.d.mts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/neutral/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,7 +1,10 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
3
|
+
|
1
4
|
// src/hooks/useCustomEvent.ts
|
2
5
|
import { assertEx } from "@xylabs/assert";
|
3
6
|
import { createRef, useEffect } from "react";
|
4
|
-
var useCustomEvent = (type, listener, customRef) => {
|
7
|
+
var useCustomEvent = /* @__PURE__ */ __name((type, listener, customRef) => {
|
5
8
|
const ref = customRef ?? createRef();
|
6
9
|
useEffect(() => {
|
7
10
|
const element = ref?.current;
|
@@ -22,7 +25,7 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
22
25
|
}
|
23
26
|
};
|
24
27
|
});
|
25
|
-
const dispatch = (detail) => {
|
28
|
+
const dispatch = /* @__PURE__ */ __name((detail) => {
|
26
29
|
const event = new CustomEvent(type, {
|
27
30
|
bubbles: true,
|
28
31
|
cancelable: true,
|
@@ -30,26 +33,32 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
30
33
|
detail
|
31
34
|
});
|
32
35
|
ref.current?.dispatchEvent(event);
|
33
|
-
};
|
34
|
-
return [
|
35
|
-
|
36
|
+
}, "dispatch");
|
37
|
+
return [
|
38
|
+
ref,
|
39
|
+
dispatch
|
40
|
+
];
|
41
|
+
}, "useCustomEvent");
|
36
42
|
|
37
43
|
// src/hooks/useEvent.ts
|
38
|
-
var useEvent = (listener, sharableRef) => {
|
39
|
-
const [ref, customDispatch] = useCustomEvent(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
};
|
49
|
-
return [
|
50
|
-
|
44
|
+
var useEvent = /* @__PURE__ */ __name((listener, sharableRef) => {
|
45
|
+
const [ref, customDispatch] = useCustomEvent("xyo", listener ? (detail) => {
|
46
|
+
return listener(detail.noun, detail.verb, detail.data);
|
47
|
+
} : void 0, sharableRef);
|
48
|
+
const dispatch = /* @__PURE__ */ __name((noun, verb, data) => {
|
49
|
+
return customDispatch({
|
50
|
+
data,
|
51
|
+
noun,
|
52
|
+
verb
|
53
|
+
});
|
54
|
+
}, "dispatch");
|
55
|
+
return [
|
56
|
+
ref,
|
57
|
+
dispatch
|
58
|
+
];
|
59
|
+
}, "useEvent");
|
51
60
|
export {
|
52
61
|
useCustomEvent,
|
53
62
|
useEvent
|
54
63
|
};
|
55
|
-
//# sourceMappingURL=index.
|
64
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,WAAsBC,iBAAiB;AAIzC,IAAMC,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,aAAaE,UAAAA;AACzBC,YAAU,MAAA;AACR,UAAMC,UAAUH,KAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,SAASC,SAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,eAASU,iBAAiBhB,MAAMS,OAAAA;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,iBAASW,oBAAoBjB,MAAMS,OAAAA;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAC9C,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,QAAII,SAASgB,cAAcb,KAAAA;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["assertEx","createRef","useEffect","useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts';
|
2
|
+
export * from './useEvent.ts';
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,WAAW,EAAE,OAAO,kBAC5D,MAAM,aACD,mBAAmB,CAAC,OAAO,CAAC,cAC3B,SAAS,CAAC,QAAQ,CAAC,KAC9B,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAoCpD,CAAA"}
|
package/dist/node/index.cjs
CHANGED
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
6
7
|
var __export = (target, all) => {
|
7
8
|
for (var name in all)
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -28,7 +29,7 @@ module.exports = __toCommonJS(src_exports);
|
|
28
29
|
// src/hooks/useCustomEvent.ts
|
29
30
|
var import_assert = require("@xylabs/assert");
|
30
31
|
var import_react = require("react");
|
31
|
-
var useCustomEvent = (type, listener, customRef) => {
|
32
|
+
var useCustomEvent = /* @__PURE__ */ __name((type, listener, customRef) => {
|
32
33
|
const ref = customRef ?? (0, import_react.createRef)();
|
33
34
|
(0, import_react.useEffect)(() => {
|
34
35
|
const element = ref == null ? void 0 : ref.current;
|
@@ -49,7 +50,7 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
49
50
|
}
|
50
51
|
};
|
51
52
|
});
|
52
|
-
const dispatch = (detail) => {
|
53
|
+
const dispatch = /* @__PURE__ */ __name((detail) => {
|
53
54
|
var _a;
|
54
55
|
const event = new CustomEvent(type, {
|
55
56
|
bubbles: true,
|
@@ -58,24 +59,30 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
58
59
|
detail
|
59
60
|
});
|
60
61
|
(_a = ref.current) == null ? void 0 : _a.dispatchEvent(event);
|
61
|
-
};
|
62
|
-
return [
|
63
|
-
|
62
|
+
}, "dispatch");
|
63
|
+
return [
|
64
|
+
ref,
|
65
|
+
dispatch
|
66
|
+
];
|
67
|
+
}, "useCustomEvent");
|
64
68
|
|
65
69
|
// src/hooks/useEvent.ts
|
66
|
-
var useEvent = (listener, sharableRef) => {
|
67
|
-
const [ref, customDispatch] = useCustomEvent(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
};
|
77
|
-
return [
|
78
|
-
|
70
|
+
var useEvent = /* @__PURE__ */ __name((listener, sharableRef) => {
|
71
|
+
const [ref, customDispatch] = useCustomEvent("xyo", listener ? (detail) => {
|
72
|
+
return listener(detail.noun, detail.verb, detail.data);
|
73
|
+
} : void 0, sharableRef);
|
74
|
+
const dispatch = /* @__PURE__ */ __name((noun, verb, data) => {
|
75
|
+
return customDispatch({
|
76
|
+
data,
|
77
|
+
noun,
|
78
|
+
verb
|
79
|
+
});
|
80
|
+
}, "dispatch");
|
81
|
+
return [
|
82
|
+
ref,
|
83
|
+
dispatch
|
84
|
+
];
|
85
|
+
}, "useEvent");
|
79
86
|
// Annotate the CommonJS export names for ESM import in node:
|
80
87
|
0 && (module.exports = {
|
81
88
|
useCustomEvent,
|
package/dist/node/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,mBAAgD;AAIzC,IAAMA,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,iBAAaE,wBAAAA;AACzBC,8BAAU,MAAA;AACR,UAAMC,UAAUH,2BAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,aAASC,wBAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,yCAASU,iBAAiBhB,MAAMS;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,2CAASW,oBAAoBjB,MAAMS;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAnClD;AAoCI,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,cAAII,YAAJJ,mBAAaoB,cAAcb;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
|
package/dist/node/index.d.cts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.mts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts';
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,7 +1,10 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
3
|
+
|
1
4
|
// src/hooks/useCustomEvent.ts
|
2
5
|
import { assertEx } from "@xylabs/assert";
|
3
6
|
import { createRef, useEffect } from "react";
|
4
|
-
var useCustomEvent = (type, listener, customRef) => {
|
7
|
+
var useCustomEvent = /* @__PURE__ */ __name((type, listener, customRef) => {
|
5
8
|
const ref = customRef ?? createRef();
|
6
9
|
useEffect(() => {
|
7
10
|
const element = ref == null ? void 0 : ref.current;
|
@@ -22,7 +25,7 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
22
25
|
}
|
23
26
|
};
|
24
27
|
});
|
25
|
-
const dispatch = (detail) => {
|
28
|
+
const dispatch = /* @__PURE__ */ __name((detail) => {
|
26
29
|
var _a;
|
27
30
|
const event = new CustomEvent(type, {
|
28
31
|
bubbles: true,
|
@@ -31,26 +34,32 @@ var useCustomEvent = (type, listener, customRef) => {
|
|
31
34
|
detail
|
32
35
|
});
|
33
36
|
(_a = ref.current) == null ? void 0 : _a.dispatchEvent(event);
|
34
|
-
};
|
35
|
-
return [
|
36
|
-
|
37
|
+
}, "dispatch");
|
38
|
+
return [
|
39
|
+
ref,
|
40
|
+
dispatch
|
41
|
+
];
|
42
|
+
}, "useCustomEvent");
|
37
43
|
|
38
44
|
// src/hooks/useEvent.ts
|
39
|
-
var useEvent = (listener, sharableRef) => {
|
40
|
-
const [ref, customDispatch] = useCustomEvent(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
};
|
50
|
-
return [
|
51
|
-
|
45
|
+
var useEvent = /* @__PURE__ */ __name((listener, sharableRef) => {
|
46
|
+
const [ref, customDispatch] = useCustomEvent("xyo", listener ? (detail) => {
|
47
|
+
return listener(detail.noun, detail.verb, detail.data);
|
48
|
+
} : void 0, sharableRef);
|
49
|
+
const dispatch = /* @__PURE__ */ __name((noun, verb, data) => {
|
50
|
+
return customDispatch({
|
51
|
+
data,
|
52
|
+
noun,
|
53
|
+
verb
|
54
|
+
});
|
55
|
+
}, "dispatch");
|
56
|
+
return [
|
57
|
+
ref,
|
58
|
+
dispatch
|
59
|
+
];
|
60
|
+
}, "useEvent");
|
52
61
|
export {
|
53
62
|
useCustomEvent,
|
54
63
|
useEvent
|
55
64
|
};
|
56
|
-
//# sourceMappingURL=index.
|
65
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,WAAsBC,iBAAiB;AAIzC,IAAMC,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,aAAaE,UAAAA;AACzBC,YAAU,MAAA;AACR,UAAMC,UAAUH,2BAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,SAASC,SAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,yCAASU,iBAAiBhB,MAAMS;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,2CAASW,oBAAoBjB,MAAMS;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAnClD;AAoCI,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,cAAII,YAAJJ,mBAAaoB,cAAcb;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["assertEx","createRef","useEffect","useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
|
package/package.json
CHANGED
@@ -10,10 +10,10 @@
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
11
11
|
},
|
12
12
|
"dependencies": {
|
13
|
-
"@xylabs/assert": "^3.6.
|
13
|
+
"@xylabs/assert": "^3.6.12"
|
14
14
|
},
|
15
15
|
"devDependencies": {
|
16
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
16
|
+
"@xylabs/ts-scripts-yarn3": "^3.15.16",
|
17
17
|
"typescript": "^5.5.4"
|
18
18
|
},
|
19
19
|
"peerDependencies": {
|
@@ -27,7 +27,7 @@
|
|
27
27
|
"node": {
|
28
28
|
"import": {
|
29
29
|
"types": "./dist/node/index.d.mts",
|
30
|
-
"default": "./dist/node/index.
|
30
|
+
"default": "./dist/node/index.mjs"
|
31
31
|
},
|
32
32
|
"require": {
|
33
33
|
"types": "./dist/node/index.d.cts",
|
@@ -37,19 +37,19 @@
|
|
37
37
|
"browser": {
|
38
38
|
"import": {
|
39
39
|
"types": "./dist/browser/index.d.mts",
|
40
|
-
"default": "./dist/browser/index.
|
40
|
+
"default": "./dist/browser/index.mjs"
|
41
41
|
},
|
42
42
|
"require": {
|
43
43
|
"types": "./dist/browser/index.d.cts",
|
44
44
|
"default": "./dist/browser/index.cjs"
|
45
45
|
}
|
46
46
|
},
|
47
|
-
"default": "./dist/browser/index.
|
47
|
+
"default": "./dist/browser/index.mjs"
|
48
48
|
},
|
49
49
|
"./package.json": "./package.json"
|
50
50
|
},
|
51
51
|
"main": "dist/browser/index.cjs",
|
52
|
-
"module": "dist/browser/index.
|
52
|
+
"module": "dist/browser/index.mjs",
|
53
53
|
"homepage": "https://xyo.network",
|
54
54
|
"keywords": [
|
55
55
|
"xyo",
|
@@ -71,6 +71,6 @@
|
|
71
71
|
},
|
72
72
|
"sideEffects": false,
|
73
73
|
"types": "dist/browser/index.d.ts",
|
74
|
-
"version": "2.
|
74
|
+
"version": "2.82.0",
|
75
75
|
"type": "module"
|
76
76
|
}
|
package/src/hooks/index.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './useCustomEvent.
|
2
|
-
export * from './useEvent.
|
1
|
+
export * from './useCustomEvent.ts'
|
2
|
+
export * from './useEvent.ts'
|
@@ -8,20 +8,21 @@ export const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(
|
|
8
8
|
listener?: CustomEventDispatch<TDetail>,
|
9
9
|
customRef?: RefObject<TElement>,
|
10
10
|
): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {
|
11
|
+
// eslint-disable-next-line @eslint-react/no-create-ref
|
11
12
|
const ref = customRef ?? createRef<TElement>()
|
12
13
|
useEffect(() => {
|
13
14
|
const element = ref?.current
|
14
15
|
const currentListener = listener
|
15
|
-
const handler
|
16
|
-
currentListener
|
17
|
-
(event: CustomEventInit<TDetail> & Event) => {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
const handler
|
17
|
+
= currentListener
|
18
|
+
? (event: CustomEventInit<TDetail> & Event) => {
|
19
|
+
const detail = assertEx(event.detail, () => 'Event missing detail')
|
20
|
+
const stop = currentListener(detail)
|
21
|
+
if (stop) {
|
22
|
+
event.stopPropagation()
|
23
|
+
}
|
22
24
|
}
|
23
|
-
|
24
|
-
: undefined
|
25
|
+
: undefined
|
25
26
|
|
26
27
|
if (handler && element) {
|
27
28
|
element?.addEventListener(type, handler)
|
package/src/hooks/useEvent.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { RefObject } from 'react'
|
2
2
|
|
3
|
-
import { useCustomEvent } from './useCustomEvent.
|
3
|
+
import { useCustomEvent } from './useCustomEvent.ts'
|
4
4
|
|
5
5
|
export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'
|
6
6
|
export type EventVerb = 'click' | 'favorite'
|
@@ -19,11 +19,11 @@ export const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = Event
|
|
19
19
|
): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {
|
20
20
|
const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(
|
21
21
|
'xyo',
|
22
|
-
listener
|
23
|
-
(detail: Event<TNoun, TVerb, TData>) => {
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
listener
|
23
|
+
? (detail: Event<TNoun, TVerb, TData>) => {
|
24
|
+
return listener(detail.noun, detail.verb, detail.data)
|
25
|
+
}
|
26
|
+
: undefined,
|
27
27
|
sharableRef,
|
28
28
|
)
|
29
29
|
|
package/src/index.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from './hooks/index.
|
1
|
+
export * from './hooks/index.ts'
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler =\n currentListener ?\n (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.js'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener ?\n (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAsB,iBAAiB;AAIzC,IAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,aAAa,UAAoB;AAC7C,YAAU,MAAM;AACd,UAAM,UAAU,KAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UACJ,kBACE,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,MAAM,sBAAsB;AAClE,YAAM,OAAO,gBAAgB,MAAM;AACnC,UAAI,MAAM;AACR,cAAM,gBAAgB;AAAA,MACxB;AAAA,IACF,IACA;AAEJ,QAAI,WAAW,SAAS;AACtB,eAAS,iBAAiB,MAAM,OAAO;AAAA,IACzC;AACA,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,iBAAS,oBAAoB,MAAM,OAAO;AAAA,MAC5C;AAAA,IACF;AAAA,EACF,CAAC;AACD,QAAM,WAAyC,CAAC,WAAqB;AACnE,UAAM,QAAQ,IAAI,YAAqB,MAAM;AAAA,MAC3C,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AACD,QAAI,SAAS,cAAc,KAAK;AAAA,EAClC;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;;;AC7BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACE,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAA+C,CAAC,MAAa,MAAa,SAAiB;AAC/F,WAAO,eAAe,EAAE,MAAM,MAAM,KAAK,CAAC;AAAA,EAC5C;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;","names":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler =\n currentListener ?\n (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.js'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener ?\n (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAsB,iBAAiB;AAIzC,IAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,aAAa,UAAoB;AAC7C,YAAU,MAAM;AACd,UAAM,UAAU,KAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UACJ,kBACE,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,MAAM,sBAAsB;AAClE,YAAM,OAAO,gBAAgB,MAAM;AACnC,UAAI,MAAM;AACR,cAAM,gBAAgB;AAAA,MACxB;AAAA,IACF,IACA;AAEJ,QAAI,WAAW,SAAS;AACtB,eAAS,iBAAiB,MAAM,OAAO;AAAA,IACzC;AACA,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,iBAAS,oBAAoB,MAAM,OAAO;AAAA,MAC5C;AAAA,IACF;AAAA,EACF,CAAC;AACD,QAAM,WAAyC,CAAC,WAAqB;AACnE,UAAM,QAAQ,IAAI,YAAqB,MAAM;AAAA,MAC3C,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AACD,QAAI,SAAS,cAAc,KAAK;AAAA,EAClC;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;;;AC7BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACE,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAA+C,CAAC,MAAa,MAAa,SAAiB;AAC/F,WAAO,eAAe,EAAE,MAAM,MAAM,KAAK,CAAC;AAAA,EAC5C;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;","names":[]}
|
package/dist/node/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler =\n currentListener ?\n (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.js'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener ?\n (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAsB,iBAAiB;AAIzC,IAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,aAAa,UAAoB;AAC7C,YAAU,MAAM;AACd,UAAM,UAAU,2BAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UACJ,kBACE,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,MAAM,sBAAsB;AAClE,YAAM,OAAO,gBAAgB,MAAM;AACnC,UAAI,MAAM;AACR,cAAM,gBAAgB;AAAA,MACxB;AAAA,IACF,IACA;AAEJ,QAAI,WAAW,SAAS;AACtB,yCAAS,iBAAiB,MAAM;AAAA,IAClC;AACA,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,2CAAS,oBAAoB,MAAM;AAAA,MACrC;AAAA,IACF;AAAA,EACF,CAAC;AACD,QAAM,WAAyC,CAAC,WAAqB;AAlCvE;AAmCI,UAAM,QAAQ,IAAI,YAAqB,MAAM;AAAA,MAC3C,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AACD,cAAI,YAAJ,mBAAa,cAAc;AAAA,EAC7B;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;;;AC7BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACE,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAA+C,CAAC,MAAa,MAAa,SAAiB;AAC/F,WAAO,eAAe,EAAE,MAAM,MAAM,KAAK,CAAC;AAAA,EAC5C;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;","names":[]}
|