@xyo-network/react-event 2.81.10 → 2.83.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. package/dist/browser/index.d.ts +16 -2
  2. package/dist/browser/{index.js → index.mjs} +28 -19
  3. package/dist/browser/index.mjs.map +1 -0
  4. package/package.json +9 -25
  5. package/src/hooks/index.ts +2 -2
  6. package/src/hooks/useCustomEvent.ts +10 -9
  7. package/src/hooks/useEvent.ts +6 -6
  8. package/src/index.ts +1 -1
  9. package/xy.config.ts +12 -0
  10. package/dist/browser/hooks/index.d.cts +0 -3
  11. package/dist/browser/hooks/index.d.cts.map +0 -1
  12. package/dist/browser/hooks/index.d.mts +0 -3
  13. package/dist/browser/hooks/index.d.mts.map +0 -1
  14. package/dist/browser/hooks/index.d.ts +0 -3
  15. package/dist/browser/hooks/index.d.ts.map +0 -1
  16. package/dist/browser/hooks/useCustomEvent.d.cts +0 -4
  17. package/dist/browser/hooks/useCustomEvent.d.cts.map +0 -1
  18. package/dist/browser/hooks/useCustomEvent.d.mts +0 -4
  19. package/dist/browser/hooks/useCustomEvent.d.mts.map +0 -1
  20. package/dist/browser/hooks/useCustomEvent.d.ts +0 -4
  21. package/dist/browser/hooks/useCustomEvent.d.ts.map +0 -1
  22. package/dist/browser/hooks/useEvent.d.cts +0 -11
  23. package/dist/browser/hooks/useEvent.d.cts.map +0 -1
  24. package/dist/browser/hooks/useEvent.d.mts +0 -11
  25. package/dist/browser/hooks/useEvent.d.mts.map +0 -1
  26. package/dist/browser/hooks/useEvent.d.ts +0 -11
  27. package/dist/browser/hooks/useEvent.d.ts.map +0 -1
  28. package/dist/browser/index.cjs +0 -78
  29. package/dist/browser/index.cjs.map +0 -1
  30. package/dist/browser/index.d.cts +0 -2
  31. package/dist/browser/index.d.cts.map +0 -1
  32. package/dist/browser/index.d.mts +0 -2
  33. package/dist/browser/index.d.mts.map +0 -1
  34. package/dist/browser/index.d.ts.map +0 -1
  35. package/dist/browser/index.js.map +0 -1
  36. package/dist/neutral/hooks/index.d.cts +0 -3
  37. package/dist/neutral/hooks/index.d.cts.map +0 -1
  38. package/dist/neutral/hooks/index.d.mts +0 -3
  39. package/dist/neutral/hooks/index.d.mts.map +0 -1
  40. package/dist/neutral/hooks/index.d.ts +0 -3
  41. package/dist/neutral/hooks/index.d.ts.map +0 -1
  42. package/dist/neutral/hooks/useCustomEvent.d.cts +0 -4
  43. package/dist/neutral/hooks/useCustomEvent.d.cts.map +0 -1
  44. package/dist/neutral/hooks/useCustomEvent.d.mts +0 -4
  45. package/dist/neutral/hooks/useCustomEvent.d.mts.map +0 -1
  46. package/dist/neutral/hooks/useCustomEvent.d.ts +0 -4
  47. package/dist/neutral/hooks/useCustomEvent.d.ts.map +0 -1
  48. package/dist/neutral/hooks/useEvent.d.cts +0 -11
  49. package/dist/neutral/hooks/useEvent.d.cts.map +0 -1
  50. package/dist/neutral/hooks/useEvent.d.mts +0 -11
  51. package/dist/neutral/hooks/useEvent.d.mts.map +0 -1
  52. package/dist/neutral/hooks/useEvent.d.ts +0 -11
  53. package/dist/neutral/hooks/useEvent.d.ts.map +0 -1
  54. package/dist/neutral/index.cjs +0 -78
  55. package/dist/neutral/index.cjs.map +0 -1
  56. package/dist/neutral/index.d.cts +0 -2
  57. package/dist/neutral/index.d.cts.map +0 -1
  58. package/dist/neutral/index.d.mts +0 -2
  59. package/dist/neutral/index.d.mts.map +0 -1
  60. package/dist/neutral/index.d.ts +0 -2
  61. package/dist/neutral/index.d.ts.map +0 -1
  62. package/dist/neutral/index.js +0 -55
  63. package/dist/neutral/index.js.map +0 -1
  64. package/dist/node/hooks/index.d.cts +0 -3
  65. package/dist/node/hooks/index.d.cts.map +0 -1
  66. package/dist/node/hooks/index.d.mts +0 -3
  67. package/dist/node/hooks/index.d.mts.map +0 -1
  68. package/dist/node/hooks/index.d.ts +0 -3
  69. package/dist/node/hooks/index.d.ts.map +0 -1
  70. package/dist/node/hooks/useCustomEvent.d.cts +0 -4
  71. package/dist/node/hooks/useCustomEvent.d.cts.map +0 -1
  72. package/dist/node/hooks/useCustomEvent.d.mts +0 -4
  73. package/dist/node/hooks/useCustomEvent.d.mts.map +0 -1
  74. package/dist/node/hooks/useCustomEvent.d.ts +0 -4
  75. package/dist/node/hooks/useCustomEvent.d.ts.map +0 -1
  76. package/dist/node/hooks/useEvent.d.cts +0 -11
  77. package/dist/node/hooks/useEvent.d.cts.map +0 -1
  78. package/dist/node/hooks/useEvent.d.mts +0 -11
  79. package/dist/node/hooks/useEvent.d.mts.map +0 -1
  80. package/dist/node/hooks/useEvent.d.ts +0 -11
  81. package/dist/node/hooks/useEvent.d.ts.map +0 -1
  82. package/dist/node/index.cjs +0 -84
  83. package/dist/node/index.cjs.map +0 -1
  84. package/dist/node/index.d.cts +0 -2
  85. package/dist/node/index.d.cts.map +0 -1
  86. package/dist/node/index.d.mts +0 -2
  87. package/dist/node/index.d.mts.map +0 -1
  88. package/dist/node/index.d.ts +0 -2
  89. package/dist/node/index.d.ts.map +0 -1
  90. package/dist/node/index.js +0 -56
  91. package/dist/node/index.js.map +0 -1
@@ -1,2 +1,16 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
1
+ import { RefObject } from 'react';
2
+
3
+ type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
4
+ declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
5
+
6
+ type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
7
+ type EventVerb = 'click' | 'favorite';
8
+ interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
9
+ data?: TData;
10
+ noun: TNoun;
11
+ verb: TVerb;
12
+ }
13
+ type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
14
+ declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
15
+
16
+ export { type CustomEventDispatch, type Event, type EventDispatch, type EventNoun, type EventVerb, useCustomEvent, useEvent };
@@ -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 [ref, dispatch];
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
- "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
- };
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.js.map
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"]}
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.4"
13
+ "@xylabs/assert": "^3.6.12"
14
14
  },
15
15
  "devDependencies": {
16
- "@xylabs/ts-scripts-yarn3": "^3.12.4",
16
+ "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.7",
17
17
  "typescript": "^5.5.4"
18
18
  },
19
19
  "peerDependencies": {
@@ -24,32 +24,16 @@
24
24
  "docs": "dist/docs.json",
25
25
  "exports": {
26
26
  ".": {
27
- "node": {
28
- "import": {
29
- "types": "./dist/node/index.d.mts",
30
- "default": "./dist/node/index.js"
31
- },
32
- "require": {
33
- "types": "./dist/node/index.d.cts",
34
- "default": "./dist/node/index.cjs"
35
- }
27
+ "import": {
28
+ "types": "./dist/browser/index.d.ts",
29
+ "default": "./dist/browser/index.mjs"
36
30
  },
37
- "browser": {
38
- "import": {
39
- "types": "./dist/browser/index.d.mts",
40
- "default": "./dist/browser/index.js"
41
- },
42
- "require": {
43
- "types": "./dist/browser/index.d.cts",
44
- "default": "./dist/browser/index.cjs"
45
- }
46
- },
47
- "default": "./dist/browser/index.js"
31
+ "types": "./dist/browser/index.d.ts",
32
+ "default": "./dist/browser/index.mjs"
48
33
  },
49
34
  "./package.json": "./package.json"
50
35
  },
51
- "main": "dist/browser/index.cjs",
52
- "module": "dist/browser/index.js",
36
+ "module": "dist/browser/index.mjs",
53
37
  "homepage": "https://xyo.network",
54
38
  "keywords": [
55
39
  "xyo",
@@ -71,6 +55,6 @@
71
55
  },
72
56
  "sideEffects": false,
73
57
  "types": "dist/browser/index.d.ts",
74
- "version": "2.81.10",
58
+ "version": "2.83.0",
75
59
  "type": "module"
76
60
  }
@@ -1,2 +1,2 @@
1
- export * from './useCustomEvent.js'
2
- export * from './useEvent.js'
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
- const detail = assertEx(event.detail, () => 'Event missing detail')
19
- const stop = currentListener(detail)
20
- if (stop) {
21
- event.stopPropagation()
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)
@@ -1,6 +1,6 @@
1
1
  import { RefObject } from 'react'
2
2
 
3
- import { useCustomEvent } from './useCustomEvent.js'
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
- return listener(detail.noun, detail.verb, detail.data)
25
- }
26
- : undefined,
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.js'
1
+ export * from './hooks/index.ts'
package/xy.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
+ const config: XyTsupConfig = {
3
+ compile: {
4
+ browser: {
5
+ src: true,
6
+ },
7
+ node: {},
8
+ neutral: {},
9
+ },
10
+ }
11
+
12
+ export default config
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- useCustomEvent: () => useCustomEvent,
24
- useEvent: () => useEvent
25
- });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/hooks/useCustomEvent.ts
29
- var import_assert = require("@xylabs/assert");
30
- var import_react = require("react");
31
- var useCustomEvent = (type, listener, customRef) => {
32
- const ref = customRef ?? (0, import_react.createRef)();
33
- (0, import_react.useEffect)(() => {
34
- const element = ref?.current;
35
- const currentListener = listener;
36
- const handler = currentListener ? (event) => {
37
- const detail = (0, import_assert.assertEx)(event.detail, () => "Event missing detail");
38
- const stop = currentListener(detail);
39
- if (stop) {
40
- event.stopPropagation();
41
- }
42
- } : void 0;
43
- if (handler && element) {
44
- element?.addEventListener(type, handler);
45
- }
46
- return () => {
47
- if (handler && element) {
48
- element?.removeEventListener(type, handler);
49
- }
50
- };
51
- });
52
- const dispatch = (detail) => {
53
- const event = new CustomEvent(type, {
54
- bubbles: true,
55
- cancelable: true,
56
- composed: true,
57
- detail
58
- });
59
- ref.current?.dispatchEvent(event);
60
- };
61
- return [ref, dispatch];
62
- };
63
-
64
- // src/hooks/useEvent.ts
65
- var useEvent = (listener, sharableRef) => {
66
- const [ref, customDispatch] = useCustomEvent(
67
- "xyo",
68
- listener ? (detail) => {
69
- return listener(detail.noun, detail.verb, detail.data);
70
- } : void 0,
71
- sharableRef
72
- );
73
- const dispatch = (noun, verb, data) => {
74
- return customDispatch({ data, noun, verb });
75
- };
76
- return [ref, dispatch];
77
- };
78
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.js'\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 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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,mBAAgD;AAIzC,IAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,iBAAa,wBAAoB;AAC7C,8BAAU,MAAM;AACd,UAAM,UAAU,KAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UACJ,kBACE,CAAC,UAA4C;AAC3C,YAAM,aAAS,wBAAS,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,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -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,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- useCustomEvent: () => useCustomEvent,
24
- useEvent: () => useEvent
25
- });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/hooks/useCustomEvent.ts
29
- var import_assert = require("@xylabs/assert");
30
- var import_react = require("react");
31
- var useCustomEvent = (type, listener, customRef) => {
32
- const ref = customRef ?? (0, import_react.createRef)();
33
- (0, import_react.useEffect)(() => {
34
- const element = ref?.current;
35
- const currentListener = listener;
36
- const handler = currentListener ? (event) => {
37
- const detail = (0, import_assert.assertEx)(event.detail, () => "Event missing detail");
38
- const stop = currentListener(detail);
39
- if (stop) {
40
- event.stopPropagation();
41
- }
42
- } : void 0;
43
- if (handler && element) {
44
- element?.addEventListener(type, handler);
45
- }
46
- return () => {
47
- if (handler && element) {
48
- element?.removeEventListener(type, handler);
49
- }
50
- };
51
- });
52
- const dispatch = (detail) => {
53
- const event = new CustomEvent(type, {
54
- bubbles: true,
55
- cancelable: true,
56
- composed: true,
57
- detail
58
- });
59
- ref.current?.dispatchEvent(event);
60
- };
61
- return [ref, dispatch];
62
- };
63
-
64
- // src/hooks/useEvent.ts
65
- var useEvent = (listener, sharableRef) => {
66
- const [ref, customDispatch] = useCustomEvent(
67
- "xyo",
68
- listener ? (detail) => {
69
- return listener(detail.noun, detail.verb, detail.data);
70
- } : void 0,
71
- sharableRef
72
- );
73
- const dispatch = (noun, verb, data) => {
74
- return customDispatch({ data, noun, verb });
75
- };
76
- return [ref, dispatch];
77
- };
78
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.js'\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 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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,mBAAgD;AAIzC,IAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,iBAAa,wBAAoB;AAC7C,8BAAU,MAAM;AACd,UAAM,UAAU,KAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UACJ,kBACE,CAAC,UAA4C;AAC3C,YAAM,aAAS,wBAAS,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,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,55 +0,0 @@
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
- };
55
- //# sourceMappingURL=index.js.map
@@ -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,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './useCustomEvent.js';
2
- export * from './useEvent.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,4 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
3
- export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail>, customRef?: RefObject<TElement>) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
- //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -1 +0,0 @@
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,CAmCpD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,11 +0,0 @@
1
- import { RefObject } from 'react';
2
- export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
3
- export type EventVerb = 'click' | 'favorite';
4
- export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
5
- data?: TData;
6
- noun: TNoun;
7
- verb: TVerb;
8
- }
9
- export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
10
- export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData>, sharableRef?: RefObject<T>) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
- //# sourceMappingURL=useEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,cAAc,KAAK,cAAc,KAAK,sBAC9E,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAC/B,SAAS,CAAC,CAAC,CAAC,KACzB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAenD,CAAA"}
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- useCustomEvent: () => useCustomEvent,
24
- useEvent: () => useEvent
25
- });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/hooks/useCustomEvent.ts
29
- var import_assert = require("@xylabs/assert");
30
- var import_react = require("react");
31
- var useCustomEvent = (type, listener, customRef) => {
32
- const ref = customRef ?? (0, import_react.createRef)();
33
- (0, import_react.useEffect)(() => {
34
- const element = ref == null ? void 0 : ref.current;
35
- const currentListener = listener;
36
- const handler = currentListener ? (event) => {
37
- const detail = (0, import_assert.assertEx)(event.detail, () => "Event missing detail");
38
- const stop = currentListener(detail);
39
- if (stop) {
40
- event.stopPropagation();
41
- }
42
- } : void 0;
43
- if (handler && element) {
44
- element == null ? void 0 : element.addEventListener(type, handler);
45
- }
46
- return () => {
47
- if (handler && element) {
48
- element == null ? void 0 : element.removeEventListener(type, handler);
49
- }
50
- };
51
- });
52
- const dispatch = (detail) => {
53
- var _a;
54
- const event = new CustomEvent(type, {
55
- bubbles: true,
56
- cancelable: true,
57
- composed: true,
58
- detail
59
- });
60
- (_a = ref.current) == null ? void 0 : _a.dispatchEvent(event);
61
- };
62
- return [ref, dispatch];
63
- };
64
-
65
- // src/hooks/useEvent.ts
66
- var useEvent = (listener, sharableRef) => {
67
- const [ref, customDispatch] = useCustomEvent(
68
- "xyo",
69
- listener ? (detail) => {
70
- return listener(detail.noun, detail.verb, detail.data);
71
- } : void 0,
72
- sharableRef
73
- );
74
- const dispatch = (noun, verb, data) => {
75
- return customDispatch({ data, noun, verb });
76
- };
77
- return [ref, dispatch];
78
- };
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {
81
- useCustomEvent,
82
- useEvent
83
- });
84
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks/index.js'\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 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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,mBAAgD;AAIzC,IAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,iBAAa,wBAAoB;AAC7C,8BAAU,MAAM;AACd,UAAM,UAAU,2BAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UACJ,kBACE,CAAC,UAA4C;AAC3C,YAAM,aAAS,wBAAS,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":[]}
@@ -1,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './hooks/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -1,56 +0,0 @@
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 == null ? void 0 : 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 == null ? void 0 : element.addEventListener(type, handler);
18
- }
19
- return () => {
20
- if (handler && element) {
21
- element == null ? void 0 : element.removeEventListener(type, handler);
22
- }
23
- };
24
- });
25
- const dispatch = (detail) => {
26
- var _a;
27
- const event = new CustomEvent(type, {
28
- bubbles: true,
29
- cancelable: true,
30
- composed: true,
31
- detail
32
- });
33
- (_a = ref.current) == null ? void 0 : _a.dispatchEvent(event);
34
- };
35
- return [ref, dispatch];
36
- };
37
-
38
- // src/hooks/useEvent.ts
39
- var useEvent = (listener, sharableRef) => {
40
- const [ref, customDispatch] = useCustomEvent(
41
- "xyo",
42
- listener ? (detail) => {
43
- return listener(detail.noun, detail.verb, detail.data);
44
- } : void 0,
45
- sharableRef
46
- );
47
- const dispatch = (noun, verb, data) => {
48
- return customDispatch({ data, noun, verb });
49
- };
50
- return [ref, dispatch];
51
- };
52
- export {
53
- useCustomEvent,
54
- useEvent
55
- };
56
- //# sourceMappingURL=index.js.map
@@ -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":[]}