@xyo-network/react-event 2.64.0-rc.3 → 2.64.0-rc.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. package/dist/browser/hooks/index.d.mts.map +1 -0
  2. package/dist/browser/hooks/index.d.ts.map +1 -0
  3. package/dist/browser/hooks/index.js +3 -0
  4. package/dist/browser/hooks/index.js.map +1 -0
  5. package/dist/browser/hooks/useCustomEvent.d.mts.map +1 -0
  6. package/dist/browser/hooks/useCustomEvent.d.ts.map +1 -0
  7. package/dist/{index.mjs → browser/hooks/useCustomEvent.js} +3 -20
  8. package/dist/browser/hooks/useCustomEvent.js.map +1 -0
  9. package/dist/browser/hooks/useEvent.d.mts.map +1 -0
  10. package/dist/browser/hooks/useEvent.d.ts.map +1 -0
  11. package/dist/browser/hooks/useEvent.js +18 -0
  12. package/dist/browser/hooks/useEvent.js.map +1 -0
  13. package/dist/{index.d.mts.map → browser/index.d.mts.map} +1 -1
  14. package/dist/{index.d.ts.map → browser/index.d.ts.map} +1 -1
  15. package/dist/browser/index.js +2 -0
  16. package/dist/browser/index.js.map +1 -0
  17. package/dist/node/hooks/index.d.mts +3 -0
  18. package/dist/node/hooks/index.d.mts.map +1 -0
  19. package/dist/node/hooks/index.d.ts +3 -0
  20. package/dist/node/hooks/index.d.ts.map +1 -0
  21. package/dist/node/hooks/index.js +25 -0
  22. package/dist/node/hooks/index.js.map +1 -0
  23. package/dist/node/hooks/index.mjs +3 -0
  24. package/dist/node/hooks/index.mjs.map +1 -0
  25. package/dist/node/hooks/useCustomEvent.d.mts +4 -0
  26. package/dist/node/hooks/useCustomEvent.d.mts.map +1 -0
  27. package/dist/node/hooks/useCustomEvent.d.ts +4 -0
  28. package/dist/node/hooks/useCustomEvent.d.ts.map +1 -0
  29. package/dist/{index.js → node/hooks/useCustomEvent.js} +7 -28
  30. package/dist/node/hooks/useCustomEvent.js.map +1 -0
  31. package/dist/node/hooks/useCustomEvent.mjs +38 -0
  32. package/dist/node/hooks/useCustomEvent.mjs.map +1 -0
  33. package/dist/node/hooks/useEvent.d.mts +11 -0
  34. package/dist/node/hooks/useEvent.d.mts.map +1 -0
  35. package/dist/node/hooks/useEvent.d.ts +11 -0
  36. package/dist/node/hooks/useEvent.d.ts.map +1 -0
  37. package/dist/node/hooks/useEvent.js +42 -0
  38. package/dist/node/hooks/useEvent.js.map +1 -0
  39. package/dist/node/hooks/useEvent.mjs +18 -0
  40. package/dist/node/hooks/useEvent.mjs.map +1 -0
  41. package/dist/node/index.d.mts +2 -0
  42. package/dist/node/index.d.mts.map +1 -0
  43. package/dist/node/index.d.ts +2 -0
  44. package/dist/node/index.d.ts.map +1 -0
  45. package/dist/node/index.js +23 -0
  46. package/dist/node/index.js.map +1 -0
  47. package/dist/node/index.mjs +2 -0
  48. package/dist/node/index.mjs.map +1 -0
  49. package/package.json +14 -14
  50. package/dist/hooks/index.d.mts.map +0 -1
  51. package/dist/hooks/index.d.ts.map +0 -1
  52. package/dist/hooks/useCustomEvent.d.mts.map +0 -1
  53. package/dist/hooks/useCustomEvent.d.ts.map +0 -1
  54. package/dist/hooks/useEvent.d.mts.map +0 -1
  55. package/dist/hooks/useEvent.d.ts.map +0 -1
  56. package/dist/index.js.map +0 -1
  57. package/dist/index.mjs.map +0 -1
  58. /package/dist/{hooks → browser/hooks}/index.d.mts +0 -0
  59. /package/dist/{hooks → browser/hooks}/index.d.ts +0 -0
  60. /package/dist/{hooks → browser/hooks}/useCustomEvent.d.mts +0 -0
  61. /package/dist/{hooks → browser/hooks}/useCustomEvent.d.ts +0 -0
  62. /package/dist/{hooks → browser/hooks}/useEvent.d.mts +0 -0
  63. /package/dist/{hooks → browser/hooks}/useEvent.d.ts +0 -0
  64. /package/dist/{index.d.mts → browser/index.d.mts} +0 -0
  65. /package/dist/{index.d.ts → browser/index.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from "./useCustomEvent";
2
+ export * from "./useEvent";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useCustomEvent'\nexport * from './useEvent'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,0DACnB,MAAM,0JAqCb,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,0DACnB,MAAM,0JAqCb,CAAA"}
@@ -1,7 +1,6 @@
1
- // src/hooks/useCustomEvent.ts
2
1
  import { assertEx } from "@xylabs/assert";
3
2
  import { createRef, useEffect } from "react";
4
- var useCustomEvent = (type, listener, customRef) => {
3
+ const useCustomEvent = (type, listener, customRef) => {
5
4
  const ref = customRef ?? createRef();
6
5
  useEffect(() => {
7
6
  const element = ref?.current;
@@ -33,23 +32,7 @@ var useCustomEvent = (type, listener, customRef) => {
33
32
  };
34
33
  return [ref, dispatch];
35
34
  };
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
35
  export {
52
- useCustomEvent,
53
- useEvent
36
+ useCustomEvent
54
37
  };
55
- //# sourceMappingURL=index.mjs.map
38
+ //# sourceMappingURL=useCustomEvent.js.map
@@ -0,0 +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":[]}
@@ -0,0 +1 @@
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,wOAkBpB,CAAA"}
@@ -0,0 +1 @@
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,wOAkBpB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { useCustomEvent } from "./useCustomEvent";
2
+ const useEvent = (listener, sharableRef) => {
3
+ const [ref, customDispatch] = useCustomEvent(
4
+ "xyo",
5
+ listener ? (detail) => {
6
+ return listener(detail.noun, detail.verb, detail.data);
7
+ } : void 0,
8
+ sharableRef
9
+ );
10
+ const dispatch = (noun, verb, data) => {
11
+ return customDispatch({ data, noun, verb });
12
+ };
13
+ return [ref, dispatch];
14
+ };
15
+ export {
16
+ useEvent
17
+ };
18
+ //# sourceMappingURL=useEvent.js.map
@@ -0,0 +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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./hooks";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './hooks'\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -0,0 +1,3 @@
1
+ export * from './useCustomEvent';
2
+ export * from './useEvent';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './useCustomEvent';
2
+ export * from './useEvent';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,25 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var hooks_exports = {};
17
+ module.exports = __toCommonJS(hooks_exports);
18
+ __reExport(hooks_exports, require("./useCustomEvent"), module.exports);
19
+ __reExport(hooks_exports, require("./useEvent"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./useCustomEvent"),
23
+ ...require("./useEvent")
24
+ });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useCustomEvent'\nexport * from './useEvent'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,6BAAd;AACA,0BAAc,uBADd;","names":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./useCustomEvent";
2
+ export * from "./useEvent";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useCustomEvent'\nexport * from './useEvent'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,4 @@
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> | undefined, customRef?: RefObject<TElement> | undefined) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
+ //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,0DACnB,MAAM,0JAqCb,CAAA"}
@@ -0,0 +1,4 @@
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> | undefined, customRef?: RefObject<TElement> | undefined) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
4
+ //# sourceMappingURL=useCustomEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,0DACnB,MAAM,0JAqCb,CAAA"}
@@ -16,19 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
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
19
+ var useCustomEvent_exports = {};
20
+ __export(useCustomEvent_exports, {
21
+ useCustomEvent: () => useCustomEvent
25
22
  });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/hooks/useCustomEvent.ts
23
+ module.exports = __toCommonJS(useCustomEvent_exports);
29
24
  var import_assert = require("@xylabs/assert");
30
25
  var import_react = require("react");
31
- var useCustomEvent = (type, listener, customRef) => {
26
+ const useCustomEvent = (type, listener, customRef) => {
32
27
  const ref = customRef ?? (0, import_react.createRef)();
33
28
  (0, import_react.useEffect)(() => {
34
29
  const element = ref?.current;
@@ -60,24 +55,8 @@ var useCustomEvent = (type, listener, customRef) => {
60
55
  };
61
56
  return [ref, dispatch];
62
57
  };
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
58
  // Annotate the CommonJS export names for ESM import in node:
79
59
  0 && (module.exports = {
80
- useCustomEvent,
81
- useEvent
60
+ useCustomEvent
82
61
  });
83
- //# sourceMappingURL=index.js.map
62
+ //# sourceMappingURL=useCustomEvent.js.map
@@ -0,0 +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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,mBAAgD;AAIzC,MAAM,iBAAiB,CAC5B,MACA,UACA,cACwD;AACxD,QAAM,MAAM,iBAAa,wBAAoB;AAC7C,8BAAU,MAAM;AACd,UAAM,UAAU,KAAK;AACrB,UAAM,kBAAkB;AACxB,UAAM,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,aAAS,wBAAS,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":[]}
@@ -0,0 +1,38 @@
1
+ import { assertEx } from "@xylabs/assert";
2
+ import { createRef, useEffect } from "react";
3
+ const useCustomEvent = (type, listener, customRef) => {
4
+ const ref = customRef ?? createRef();
5
+ useEffect(() => {
6
+ const element = ref?.current;
7
+ const currentListener = listener;
8
+ const handler = currentListener ? (event) => {
9
+ const detail = assertEx(event.detail, "Event missing detail");
10
+ const stop = currentListener(detail);
11
+ if (stop) {
12
+ event.stopPropagation();
13
+ }
14
+ } : void 0;
15
+ if (handler && element) {
16
+ element?.addEventListener(type, handler);
17
+ }
18
+ return () => {
19
+ if (handler && element) {
20
+ element?.removeEventListener(type, handler);
21
+ }
22
+ };
23
+ });
24
+ const dispatch = (detail) => {
25
+ const event = new CustomEvent(type, {
26
+ bubbles: true,
27
+ cancelable: true,
28
+ composed: true,
29
+ detail
30
+ });
31
+ ref.current?.dispatchEvent(event);
32
+ };
33
+ return [ref, dispatch];
34
+ };
35
+ export {
36
+ useCustomEvent
37
+ };
38
+ //# sourceMappingURL=useCustomEvent.mjs.map
@@ -0,0 +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":[]}
@@ -0,0 +1,11 @@
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> | undefined, sharableRef?: RefObject<T> | undefined) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
+ //# sourceMappingURL=useEvent.d.ts.map
@@ -0,0 +1 @@
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,wOAkBpB,CAAA"}
@@ -0,0 +1,11 @@
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> | undefined, sharableRef?: RefObject<T> | undefined) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
11
+ //# sourceMappingURL=useEvent.d.ts.map
@@ -0,0 +1 @@
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,wOAkBpB,CAAA"}
@@ -0,0 +1,42 @@
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
+ var useEvent_exports = {};
20
+ __export(useEvent_exports, {
21
+ useEvent: () => useEvent
22
+ });
23
+ module.exports = __toCommonJS(useEvent_exports);
24
+ var import_useCustomEvent = require("./useCustomEvent");
25
+ const useEvent = (listener, sharableRef) => {
26
+ const [ref, customDispatch] = (0, import_useCustomEvent.useCustomEvent)(
27
+ "xyo",
28
+ listener ? (detail) => {
29
+ return listener(detail.noun, detail.verb, detail.data);
30
+ } : void 0,
31
+ sharableRef
32
+ );
33
+ const dispatch = (noun, verb, data) => {
34
+ return customDispatch({ data, noun, verb });
35
+ };
36
+ return [ref, dispatch];
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ useEvent
41
+ });
42
+ //# sourceMappingURL=useEvent.js.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAA+B;AAaxB,MAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,QAAI;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":[]}
@@ -0,0 +1,18 @@
1
+ import { useCustomEvent } from "./useCustomEvent";
2
+ const useEvent = (listener, sharableRef) => {
3
+ const [ref, customDispatch] = useCustomEvent(
4
+ "xyo",
5
+ listener ? (detail) => {
6
+ return listener(detail.noun, detail.verb, detail.data);
7
+ } : void 0,
8
+ sharableRef
9
+ );
10
+ const dispatch = (noun, verb, data) => {
11
+ return customDispatch({ data, noun, verb });
12
+ };
13
+ return [ref, dispatch];
14
+ };
15
+ export {
16
+ useEvent
17
+ };
18
+ //# sourceMappingURL=useEvent.mjs.map
@@ -0,0 +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":[]}
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,23 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./hooks"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./hooks")
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './hooks'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,oBAAd;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./hooks";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './hooks'\n"],"mappings":"AAAA,cAAc;","names":[]}
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@xylabs/assert": "^2.11.7"
14
14
  },
15
15
  "devDependencies": {
16
- "@xylabs/ts-scripts-yarn3": "^3.0.28",
16
+ "@xylabs/ts-scripts-yarn3": "^3.0.55",
17
17
  "typescript": "^5.2.2"
18
18
  },
19
19
  "peerDependencies": {
@@ -26,30 +26,30 @@
26
26
  ".": {
27
27
  "node": {
28
28
  "import": {
29
- "types": "./dist/index.d.mts",
30
- "default": "./dist/index.mjs"
29
+ "types": "./dist/node/index.d.mts",
30
+ "default": "./dist/node/index.mjs"
31
31
  },
32
32
  "require": {
33
- "types": "./dist/index.d.ts",
34
- "default": "./dist/index.js"
33
+ "types": "./dist/node/index.d.ts",
34
+ "default": "./dist/node/index.js"
35
35
  }
36
36
  },
37
37
  "browser": {
38
38
  "import": {
39
- "types": "./dist/index.d.mts",
40
- "default": "./dist/index.mjs"
39
+ "types": "./dist/browser/index.d.ts",
40
+ "default": "./dist/browser/index.js"
41
41
  },
42
42
  "require": {
43
- "types": "./dist/index.d.ts",
44
- "default": "./dist/index.js"
43
+ "types": "./dist/browser/index.d.ts",
44
+ "default": "./dist/browser/index.js"
45
45
  }
46
46
  },
47
- "default": "./dist/index.mjs"
47
+ "default": "./dist/browser/index.mjs"
48
48
  },
49
49
  "./package.json": "./package.json"
50
50
  },
51
- "main": "dist/index.js",
52
- "module": "dist/index.mjs",
51
+ "main": "dist/browser/index.js",
52
+ "module": "dist/browser/index.js",
53
53
  "homepage": "https://xyo.network",
54
54
  "keywords": [
55
55
  "xyo",
@@ -70,7 +70,7 @@
70
70
  "license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
71
71
  },
72
72
  "sideEffects": false,
73
- "types": "dist/index.d.ts",
74
- "version": "2.64.0-rc.3",
73
+ "types": "dist/browser/index.d.ts",
74
+ "version": "2.64.0-rc.4",
75
75
  "stableVersion": "2.63.1"
76
76
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -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,0DACnB,MAAM,0JAqCb,CAAA"}
@@ -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,0DACnB,MAAM,0JAqCb,CAAA"}
@@ -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,wOAkBpB,CAAA"}
@@ -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,wOAkBpB,CAAA"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/hooks/useCustomEvent.ts","../src/hooks/useEvent.ts"],"sourcesContent":["export * from './hooks'\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 = 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;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,UAAU,kBACZ,CAAC,UAA4C;AAC3C,YAAM,aAAS,wBAAS,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 +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 = 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":[]}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes