@xyo-network/react-event 3.0.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useCustomEvent.ts","../../src/hooks/useEvent.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { createRef, RefObject, useEffect } from 'react'\n\nexport type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void\n\nexport const useCustomEvent = <TElement extends HTMLElement, TDetail = unknown>(\n type: string,\n listener?: CustomEventDispatch<TDetail>,\n customRef?: RefObject<TElement>,\n): [RefObject<TElement>, CustomEventDispatch<TDetail>] => {\n // eslint-disable-next-line @eslint-react/no-create-ref\n const ref = customRef ?? createRef<TElement>()\n useEffect(() => {\n const element = ref?.current\n const currentListener = listener\n const handler\n = currentListener\n ? (event: CustomEventInit<TDetail> & Event) => {\n const detail = assertEx(event.detail, () => 'Event missing detail')\n const stop = currentListener(detail)\n if (stop) {\n event.stopPropagation()\n }\n }\n : undefined\n\n if (handler && element) {\n element?.addEventListener(type, handler)\n }\n return () => {\n if (handler && element) {\n element?.removeEventListener(type, handler)\n }\n }\n })\n const dispatch: CustomEventDispatch<TDetail> = (detail?: TDetail) => {\n const event = new CustomEvent<TDetail>(type, {\n bubbles: true,\n cancelable: true,\n composed: true,\n detail,\n })\n ref.current?.dispatchEvent(event)\n }\n return [ref, dispatch]\n}\n","import { RefObject } from 'react'\n\nimport { useCustomEvent } from './useCustomEvent.ts'\n\nexport type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema'\nexport type EventVerb = 'click' | 'favorite'\n\nexport interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {\n data?: TData\n noun: TNoun\n verb: TVerb\n}\n\nexport type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void\n\nexport const useEvent = <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(\n listener?: EventDispatch<TNoun, TVerb, TData>,\n sharableRef?: RefObject<T>,\n): [RefObject<T>, EventDispatch<TNoun, TVerb, TData>] => {\n const [ref, customDispatch] = useCustomEvent<T, Event<TNoun, TVerb, TData>>(\n 'xyo',\n listener\n ? (detail: Event<TNoun, TVerb, TData>) => {\n return listener(detail.noun, detail.verb, detail.data)\n }\n : undefined,\n sharableRef,\n )\n\n const dispatch: EventDispatch<TNoun, TVerb, TData> = (noun: TNoun, verb: TVerb, data?: TData) => {\n return customDispatch({ data, noun, verb })\n }\n return [ref, dispatch]\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,WAAsBC,iBAAiB;AAIzC,IAAMC,iBAAiB,wBAC5BC,MACAC,UACAC,cAAAA;AAGA,QAAMC,MAAMD,aAAaE,UAAAA;AACzBC,YAAU,MAAA;AACR,UAAMC,UAAUH,KAAKI;AACrB,UAAMC,kBAAkBP;AACxB,UAAMQ,UACFD,kBACE,CAACE,UAAAA;AACC,YAAMC,SAASC,SAASF,MAAMC,QAAQ,MAAM,sBAAA;AAC5C,YAAME,OAAOL,gBAAgBG,MAAAA;AAC7B,UAAIE,MAAM;AACRH,cAAMI,gBAAe;MACvB;IACF,IACAC;AAEN,QAAIN,WAAWH,SAAS;AACtBA,eAASU,iBAAiBhB,MAAMS,OAAAA;IAClC;AACA,WAAO,MAAA;AACL,UAAIA,WAAWH,SAAS;AACtBA,iBAASW,oBAAoBjB,MAAMS,OAAAA;MACrC;IACF;EACF,CAAA;AACA,QAAMS,WAAyC,wBAACP,WAAAA;AAC9C,UAAMD,QAAQ,IAAIS,YAAqBnB,MAAM;MAC3CoB,SAAS;MACTC,YAAY;MACZC,UAAU;MACVX;IACF,CAAA;AACAR,QAAII,SAASgB,cAAcb,KAAAA;EAC7B,GAR+C;AAS/C,SAAO;IAACP;IAAKe;;AACf,GAxC8B;;;ACUvB,IAAMM,WAAW,wBACtBC,UACAC,gBAAAA;AAEA,QAAM,CAACC,KAAKC,cAAAA,IAAkBC,eAC5B,OACAJ,WACI,CAACK,WAAAA;AACC,WAAOL,SAASK,OAAOC,MAAMD,OAAOE,MAAMF,OAAOG,IAAI;EACvD,IACAC,QACJR,WAAAA;AAGF,QAAMS,WAA+C,wBAACJ,MAAaC,MAAaC,SAAAA;AAC9E,WAAOL,eAAe;MAAEK;MAAMF;MAAMC;IAAK,CAAA;EAC3C,GAFqD;AAGrD,SAAO;IAACL;IAAKQ;;AACf,GAlBwB;","names":["assertEx","createRef","useEffect","useCustomEvent","type","listener","customRef","ref","createRef","useEffect","element","current","currentListener","handler","event","detail","assertEx","stop","stopPropagation","undefined","addEventListener","removeEventListener","dispatch","CustomEvent","bubbles","cancelable","composed","dispatchEvent","useEvent","listener","sharableRef","ref","customDispatch","useCustomEvent","detail","noun","verb","data","undefined","dispatch"]}
1
+ {"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"]}
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  },
8
8
  "bugs": {
9
9
  "email": "support@xyo.network",
10
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
10
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^4.0.0"
13
+ "@xylabs/assert": "^4.0.2"
14
14
  },
15
15
  "devDependencies": {
16
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
16
+ "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.20",
17
17
  "typescript": "^5.5.4"
18
18
  },
19
19
  "peerDependencies": {
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "repository": {
49
49
  "type": "git",
50
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
50
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
51
51
  },
52
52
  "scripts": {
53
53
  "lint-pkg": "npmPkgJsonLint .",
@@ -55,6 +55,6 @@
55
55
  },
56
56
  "sideEffects": false,
57
57
  "types": "dist/browser/index.d.ts",
58
- "version": "3.0.0",
58
+ "version": "3.0.2",
59
59
  "type": "module"
60
60
  }
@@ -1,5 +1,6 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
- import { createRef, RefObject, useEffect } from 'react'
2
+ import type { RefObject } from 'react'
3
+ import { createRef, useEffect } from 'react'
3
4
 
4
5
  export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void
5
6
 
@@ -1,4 +1,4 @@
1
- import { RefObject } from 'react'
1
+ import type { RefObject } from 'react'
2
2
 
3
3
  import { useCustomEvent } from './useCustomEvent.ts'
4
4
 
package/xy.config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
1
+ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
4
  browser: {