@xyo-network/react-event 2.64.0 → 2.64.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,55 @@
1
- export * from "./useCustomEvent";
2
- export * from "./useEvent";
1
+ // src/hooks/useCustomEvent.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { createRef, useEffect } from "react";
4
+ var useCustomEvent = (type, listener, customRef) => {
5
+ const ref = customRef ?? createRef();
6
+ useEffect(() => {
7
+ const element = ref?.current;
8
+ const currentListener = listener;
9
+ const handler = currentListener ? (event) => {
10
+ const detail = assertEx(event.detail, "Event missing detail");
11
+ const stop = currentListener(detail);
12
+ if (stop) {
13
+ event.stopPropagation();
14
+ }
15
+ } : void 0;
16
+ if (handler && element) {
17
+ element?.addEventListener(type, handler);
18
+ }
19
+ return () => {
20
+ if (handler && element) {
21
+ element?.removeEventListener(type, handler);
22
+ }
23
+ };
24
+ });
25
+ const dispatch = (detail) => {
26
+ const event = new CustomEvent(type, {
27
+ bubbles: true,
28
+ cancelable: true,
29
+ composed: true,
30
+ detail
31
+ });
32
+ ref.current?.dispatchEvent(event);
33
+ };
34
+ return [ref, dispatch];
35
+ };
36
+
37
+ // src/hooks/useEvent.ts
38
+ var useEvent = (listener, sharableRef) => {
39
+ const [ref, customDispatch] = useCustomEvent(
40
+ "xyo",
41
+ listener ? (detail) => {
42
+ return listener(detail.noun, detail.verb, detail.data);
43
+ } : void 0,
44
+ sharableRef
45
+ );
46
+ const dispatch = (noun, verb, data) => {
47
+ return customDispatch({ data, noun, verb });
48
+ };
49
+ return [ref, dispatch];
50
+ };
51
+ export {
52
+ useCustomEvent,
53
+ useEvent
54
+ };
3
55
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useCustomEvent'\nexport * from './useEvent'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
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 = 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'\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,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,sBAAsB;AAC5D,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;;;AC5BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACI,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACJ;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,6 +1,7 @@
1
+ // src/hooks/useCustomEvent.ts
1
2
  import { assertEx } from "@xylabs/assert";
2
3
  import { createRef, useEffect } from "react";
3
- const useCustomEvent = (type, listener, customRef) => {
4
+ var useCustomEvent = (type, listener, customRef) => {
4
5
  const ref = customRef ?? createRef();
5
6
  useEffect(() => {
6
7
  const element = ref?.current;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useCustomEvent.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 = 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"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAsB,iBAAiB;AAIzC,MAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,aAAa,UAAoB;AAC7C,YAAU,MAAM;AACd,UAAM,UAAU,KAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,sBAAsB;AAC5D,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;","names":[]}
1
+ {"version":3,"sources":["../../../src/hooks/useCustomEvent.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 = 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"],"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,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,sBAAsB;AAC5D,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;","names":[]}
@@ -1,5 +1,41 @@
1
- import { useCustomEvent } from "./useCustomEvent";
2
- const useEvent = (listener, sharableRef) => {
1
+ // src/hooks/useCustomEvent.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { createRef, useEffect } from "react";
4
+ var useCustomEvent = (type, listener, customRef) => {
5
+ const ref = customRef ?? createRef();
6
+ useEffect(() => {
7
+ const element = ref?.current;
8
+ const currentListener = listener;
9
+ const handler = currentListener ? (event) => {
10
+ const detail = assertEx(event.detail, "Event missing detail");
11
+ const stop = currentListener(detail);
12
+ if (stop) {
13
+ event.stopPropagation();
14
+ }
15
+ } : void 0;
16
+ if (handler && element) {
17
+ element?.addEventListener(type, handler);
18
+ }
19
+ return () => {
20
+ if (handler && element) {
21
+ element?.removeEventListener(type, handler);
22
+ }
23
+ };
24
+ });
25
+ const dispatch = (detail) => {
26
+ const event = new CustomEvent(type, {
27
+ bubbles: true,
28
+ cancelable: true,
29
+ composed: true,
30
+ detail
31
+ });
32
+ ref.current?.dispatchEvent(event);
33
+ };
34
+ return [ref, dispatch];
35
+ };
36
+
37
+ // src/hooks/useEvent.ts
38
+ var useEvent = (listener, sharableRef) => {
3
39
  const [ref, customDispatch] = useCustomEvent(
4
40
  "xyo",
5
41
  listener ? (detail) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useEvent.ts"],"sourcesContent":["import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent'\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":"AAEA,SAAS,sBAAsB;AAaxB,MAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACI,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACJ;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
+ {"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 = 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'\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,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,sBAAsB;AAC5D,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;;;AC5BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACI,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACJ;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,2 +1,55 @@
1
- export * from "./hooks";
1
+ // src/hooks/useCustomEvent.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { createRef, useEffect } from "react";
4
+ var useCustomEvent = (type, listener, customRef) => {
5
+ const ref = customRef ?? createRef();
6
+ useEffect(() => {
7
+ const element = ref?.current;
8
+ const currentListener = listener;
9
+ const handler = currentListener ? (event) => {
10
+ const detail = assertEx(event.detail, "Event missing detail");
11
+ const stop = currentListener(detail);
12
+ if (stop) {
13
+ event.stopPropagation();
14
+ }
15
+ } : void 0;
16
+ if (handler && element) {
17
+ element?.addEventListener(type, handler);
18
+ }
19
+ return () => {
20
+ if (handler && element) {
21
+ element?.removeEventListener(type, handler);
22
+ }
23
+ };
24
+ });
25
+ const dispatch = (detail) => {
26
+ const event = new CustomEvent(type, {
27
+ bubbles: true,
28
+ cancelable: true,
29
+ composed: true,
30
+ detail
31
+ });
32
+ ref.current?.dispatchEvent(event);
33
+ };
34
+ return [ref, dispatch];
35
+ };
36
+
37
+ // src/hooks/useEvent.ts
38
+ var useEvent = (listener, sharableRef) => {
39
+ const [ref, customDispatch] = useCustomEvent(
40
+ "xyo",
41
+ listener ? (detail) => {
42
+ return listener(detail.noun, detail.verb, detail.data);
43
+ } : void 0,
44
+ sharableRef
45
+ );
46
+ const dispatch = (noun, verb, data) => {
47
+ return customDispatch({ data, noun, verb });
48
+ };
49
+ return [ref, dispatch];
50
+ };
51
+ export {
52
+ useCustomEvent,
53
+ useEvent
54
+ };
2
55
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './hooks'\n"],"mappings":"AAAA,cAAc;","names":[]}
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 = 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'\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,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,SAAS,SAAS,MAAM,QAAQ,sBAAsB;AAC5D,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;;;AC5BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACI,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACJ;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/docs.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "fileName": "hooks/useEvent.ts",
26
26
  "line": 9,
27
27
  "character": 2,
28
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L9"
28
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L9"
29
29
  }
30
30
  ],
31
31
  "type": {
@@ -46,7 +46,7 @@
46
46
  "fileName": "hooks/useEvent.ts",
47
47
  "line": 10,
48
48
  "character": 2,
49
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L10"
49
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L10"
50
50
  }
51
51
  ],
52
52
  "type": {
@@ -67,7 +67,7 @@
67
67
  "fileName": "hooks/useEvent.ts",
68
68
  "line": 11,
69
69
  "character": 2,
70
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L11"
70
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L11"
71
71
  }
72
72
  ],
73
73
  "type": {
@@ -93,7 +93,7 @@
93
93
  "fileName": "hooks/useEvent.ts",
94
94
  "line": 8,
95
95
  "character": 17,
96
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L8"
96
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L8"
97
97
  }
98
98
  ],
99
99
  "typeParameters": [
@@ -147,7 +147,7 @@
147
147
  "fileName": "hooks/useCustomEvent.ts",
148
148
  "line": 4,
149
149
  "character": 12,
150
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L4"
150
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L4"
151
151
  }
152
152
  ],
153
153
  "typeParameters": [
@@ -176,7 +176,7 @@
176
176
  "fileName": "hooks/useCustomEvent.ts",
177
177
  "line": 4,
178
178
  "character": 47,
179
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L4"
179
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L4"
180
180
  }
181
181
  ],
182
182
  "signatures": [
@@ -230,7 +230,7 @@
230
230
  "fileName": "hooks/useEvent.ts",
231
231
  "line": 14,
232
232
  "character": 12,
233
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L14"
233
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L14"
234
234
  }
235
235
  ],
236
236
  "typeParameters": [
@@ -285,7 +285,7 @@
285
285
  "fileName": "hooks/useEvent.ts",
286
286
  "line": 14,
287
287
  "character": 82,
288
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L14"
288
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L14"
289
289
  }
290
290
  ],
291
291
  "signatures": [
@@ -367,7 +367,7 @@
367
367
  "fileName": "hooks/useEvent.ts",
368
368
  "line": 5,
369
369
  "character": 12,
370
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L5"
370
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L5"
371
371
  }
372
372
  ],
373
373
  "type": {
@@ -411,7 +411,7 @@
411
411
  "fileName": "hooks/useEvent.ts",
412
412
  "line": 6,
413
413
  "character": 12,
414
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L6"
414
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L6"
415
415
  }
416
416
  ],
417
417
  "type": {
@@ -439,7 +439,7 @@
439
439
  "fileName": "hooks/useCustomEvent.ts",
440
440
  "line": 6,
441
441
  "character": 13,
442
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L6"
442
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L6"
443
443
  }
444
444
  ],
445
445
  "signatures": [
@@ -454,7 +454,7 @@
454
454
  "fileName": "hooks/useCustomEvent.ts",
455
455
  "line": 6,
456
456
  "character": 30,
457
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L6"
457
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L6"
458
458
  }
459
459
  ],
460
460
  "typeParameter": [
@@ -600,7 +600,7 @@
600
600
  "fileName": "hooks/useEvent.ts",
601
601
  "line": 16,
602
602
  "character": 13,
603
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L16"
603
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L16"
604
604
  }
605
605
  ],
606
606
  "signatures": [
@@ -615,7 +615,7 @@
615
615
  "fileName": "hooks/useEvent.ts",
616
616
  "line": 16,
617
617
  "character": 24,
618
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/d3056af66/packages/sdk/packages/event/src/hooks/useEvent.ts#L16"
618
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/ace39d815/packages/sdk/packages/event/src/hooks/useEvent.ts#L16"
619
619
  }
620
620
  ],
621
621
  "typeParameter": [
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": "^2.12.13"
13
+ "@xylabs/assert": "^2.12.14"
14
14
  },
15
15
  "devDependencies": {
16
- "@xylabs/ts-scripts-yarn3": "^3.0.78",
16
+ "@xylabs/ts-scripts-yarn3": "^3.0.79",
17
17
  "typescript": "^5.2.2"
18
18
  },
19
19
  "peerDependencies": {
@@ -71,6 +71,6 @@
71
71
  },
72
72
  "sideEffects": false,
73
73
  "types": "dist/browser/index.d.ts",
74
- "version": "2.64.0",
74
+ "version": "2.64.1",
75
75
  "type": "module"
76
76
  }