@xyo-network/react-event 3.0.2 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ export * from './useCustomEvent.ts';
2
+ export * from './useEvent.ts';
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,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { 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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,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,CAqCpD,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { 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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,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,CAiBnD,CAAA"}
@@ -1,16 +1,2 @@
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
+ export * from './hooks/index.ts';
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,kBAAkB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { RefObject } from 'react'\nimport { createRef, 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 type { 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;AAEzB,SAASC,WAAWC,iBAAiB;AAI9B,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;;;ACSvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["assertEx","createRef","useEffect","useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
1
+ {"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { RefObject } from 'react'\nimport { createRef, 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 // eslint-disable-next-line @eslint-react/web-api/no-leaked-event-listener\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 type { 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({\n data, noun, verb,\n })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AAEzB,SAASC,WAAWC,iBAAiB;AAI9B,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;AAEtBA,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,GAzC8B;;;ACSvB,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;MACpBK;MAAMF;MAAMC;IACd,CAAA;EACF,GAJqD;AAKrD,SAAO;IAACL;IAAKQ;;AACf,GApBwB;","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
@@ -1,27 +1,30 @@
1
1
  {
2
2
  "name": "@xyo-network/react-event",
3
- "author": {
4
- "email": "support@xyo.network",
5
- "name": "XYO Development Team",
6
- "url": "https://xyo.network"
7
- },
3
+ "version": "3.0.4",
4
+ "description": "Common React library for all XYO projects that use React",
5
+ "keywords": [
6
+ "xyo",
7
+ "utility",
8
+ "typescript",
9
+ "react"
10
+ ],
11
+ "homepage": "https://xyo.network",
8
12
  "bugs": {
9
- "email": "support@xyo.network",
10
- "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
11
- },
12
- "dependencies": {
13
- "@xylabs/assert": "^4.0.2"
13
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues",
14
+ "email": "support@xyo.network"
14
15
  },
15
- "devDependencies": {
16
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.20",
17
- "typescript": "^5.5.4"
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
18
19
  },
19
- "peerDependencies": {
20
- "react": "^18.2.0",
21
- "react-dom": "^18.2.0"
20
+ "license": "LGPL-3.0-only",
21
+ "author": {
22
+ "name": "XYO Development Team",
23
+ "email": "support@xyo.network",
24
+ "url": "https://xyo.network"
22
25
  },
23
- "description": "Common React library for all XYO projects that use React",
24
- "docs": "dist/docs.json",
26
+ "sideEffects": false,
27
+ "type": "module",
25
28
  "exports": {
26
29
  ".": {
27
30
  "import": {
@@ -34,27 +37,24 @@
34
37
  "./package.json": "./package.json"
35
38
  },
36
39
  "module": "dist/browser/index.mjs",
37
- "homepage": "https://xyo.network",
38
- "keywords": [
39
- "xyo",
40
- "utility",
41
- "typescript",
42
- "react"
43
- ],
44
- "license": "LGPL-3.0-only",
45
- "publishConfig": {
46
- "access": "public"
40
+ "types": "dist/browser/index.d.ts",
41
+ "scripts": {
42
+ "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\"",
43
+ "lint-pkg": "npmPkgJsonLint ."
47
44
  },
48
- "repository": {
49
- "type": "git",
50
- "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
45
+ "dependencies": {
46
+ "@xylabs/assert": "^4.0.5"
51
47
  },
52
- "scripts": {
53
- "lint-pkg": "npmPkgJsonLint .",
54
- "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\""
48
+ "devDependencies": {
49
+ "@xylabs/ts-scripts-yarn3": "^4.0.7",
50
+ "typescript": "^5.5.4"
55
51
  },
56
- "sideEffects": false,
57
- "types": "dist/browser/index.d.ts",
58
- "version": "3.0.2",
59
- "type": "module"
52
+ "peerDependencies": {
53
+ "react": "^18.2.0",
54
+ "react-dom": "^18.2.0"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "docs": "dist/docs.json"
60
60
  }
@@ -26,6 +26,7 @@ export const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(
26
26
  : undefined
27
27
 
28
28
  if (handler && element) {
29
+ // eslint-disable-next-line @eslint-react/web-api/no-leaked-event-listener
29
30
  element?.addEventListener(type, handler)
30
31
  }
31
32
  return () => {
@@ -28,7 +28,9 @@ export const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = Event
28
28
  )
29
29
 
30
30
  const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {
31
- return customDispatch({ data, noun, verb })
31
+ return customDispatch({
32
+ data, noun, verb,
33
+ })
32
34
  }
33
35
  return [ref, dispatch]
34
36
  }
package/xy.config.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
- browser: {
5
- src: true,
6
- },
4
+ browser: { src: true },
7
5
  node: {},
8
6
  neutral: {},
9
7
  },