@xyo-network/react-event 2.64.0-rc.6 → 2.64.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/hooks/index.cjs +78 -0
- package/dist/browser/hooks/index.cjs.map +1 -0
- package/dist/browser/hooks/index.d.cts +3 -0
- package/dist/browser/hooks/index.d.cts.map +1 -0
- package/dist/browser/hooks/useCustomEvent.cjs +60 -0
- package/dist/{node/hooks/useCustomEvent.mjs.map → browser/hooks/useCustomEvent.cjs.map} +1 -1
- package/dist/browser/hooks/useCustomEvent.d.cts +4 -0
- package/dist/browser/hooks/useCustomEvent.d.cts.map +1 -0
- package/dist/browser/hooks/useEvent.cjs +77 -0
- package/dist/browser/hooks/useEvent.cjs.map +1 -0
- package/dist/browser/hooks/useEvent.d.cts +11 -0
- package/dist/browser/hooks/useEvent.d.cts.map +1 -0
- package/dist/browser/index.cjs +78 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +2 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/docs.json +982 -0
- package/dist/node/hooks/index.cjs +84 -0
- package/dist/node/hooks/index.cjs.map +1 -0
- package/dist/node/hooks/index.d.cts +3 -0
- package/dist/node/hooks/index.d.cts.map +1 -0
- package/dist/node/hooks/index.js +54 -23
- package/dist/node/hooks/index.js.map +1 -1
- package/dist/node/hooks/useCustomEvent.cjs +65 -0
- package/dist/node/hooks/useCustomEvent.cjs.map +1 -0
- package/dist/node/hooks/useCustomEvent.d.cts +4 -0
- package/dist/node/hooks/useCustomEvent.d.cts.map +1 -0
- package/dist/node/hooks/useCustomEvent.js +14 -36
- package/dist/node/hooks/useCustomEvent.js.map +1 -1
- package/dist/node/hooks/useEvent.cjs +82 -0
- package/dist/node/hooks/useEvent.cjs.map +1 -0
- package/dist/node/hooks/useEvent.d.cts +11 -0
- package/dist/node/hooks/useEvent.d.cts.map +1 -0
- package/dist/node/hooks/useEvent.js +41 -28
- package/dist/node/hooks/useEvent.js.map +1 -1
- package/dist/node/index.cjs +84 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +2 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +54 -21
- package/dist/node/index.js.map +1 -1
- package/package.json +12 -12
- package/dist/node/hooks/index.mjs +0 -3
- package/dist/node/hooks/index.mjs.map +0 -1
- package/dist/node/hooks/useCustomEvent.mjs +0 -38
- package/dist/node/hooks/useEvent.mjs +0 -18
- package/dist/node/hooks/useEvent.mjs.map +0 -1
- package/dist/node/index.mjs +0 -2
- package/dist/node/index.mjs.map +0 -1
@@ -0,0 +1,84 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
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,2BAAK;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,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;AAjCvE;AAkCI,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;;;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":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
package/dist/node/index.js
CHANGED
@@ -1,23 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
var
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
55
|
};
|
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
56
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/
|
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,2BAAK;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,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;AAjCvE;AAkCI,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;;;AC5BO,IAAM,WAAW,CACtB,UACA,gBACuD;AACvD,QAAM,CAAC,KAAK,cAAc,IAAI;AAAA,IAC5B;AAAA,IACA,WACI,CAAC,WAAuC;AACtC,aAAO,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI;AAAA,IACvD,IACA;AAAA,IACJ;AAAA,EACF;AAEA,QAAM,WAA+C,CAAC,MAAa,MAAa,SAAiB;AAC/F,WAAO,eAAe,EAAE,MAAM,MAAM,KAAK,CAAC;AAAA,EAC5C;AACA,SAAO,CAAC,KAAK,QAAQ;AACvB;","names":[]}
|
package/package.json
CHANGED
@@ -10,10 +10,10 @@
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
11
11
|
},
|
12
12
|
"dependencies": {
|
13
|
-
"@xylabs/assert": "^2.
|
13
|
+
"@xylabs/assert": "^2.12.13"
|
14
14
|
},
|
15
15
|
"devDependencies": {
|
16
|
-
"@xylabs/ts-scripts-yarn3": "^3.0.
|
16
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.78",
|
17
17
|
"typescript": "^5.2.2"
|
18
18
|
},
|
19
19
|
"peerDependencies": {
|
@@ -27,28 +27,28 @@
|
|
27
27
|
"node": {
|
28
28
|
"import": {
|
29
29
|
"types": "./dist/node/index.d.mts",
|
30
|
-
"default": "./dist/node/index.
|
30
|
+
"default": "./dist/node/index.js"
|
31
31
|
},
|
32
32
|
"require": {
|
33
|
-
"types": "./dist/node/index.d.
|
34
|
-
"default": "./dist/node/index.
|
33
|
+
"types": "./dist/node/index.d.cts",
|
34
|
+
"default": "./dist/node/index.cjs"
|
35
35
|
}
|
36
36
|
},
|
37
37
|
"browser": {
|
38
38
|
"import": {
|
39
|
-
"types": "./dist/browser/index.d.
|
39
|
+
"types": "./dist/browser/index.d.mts",
|
40
40
|
"default": "./dist/browser/index.js"
|
41
41
|
},
|
42
42
|
"require": {
|
43
|
-
"types": "./dist/browser/index.d.
|
44
|
-
"default": "./dist/browser/index.
|
43
|
+
"types": "./dist/browser/index.d.cts",
|
44
|
+
"default": "./dist/browser/index.cjs"
|
45
45
|
}
|
46
46
|
},
|
47
|
-
"default": "./dist/browser/index.
|
47
|
+
"default": "./dist/browser/index.js"
|
48
48
|
},
|
49
49
|
"./package.json": "./package.json"
|
50
50
|
},
|
51
|
-
"main": "dist/browser/index.
|
51
|
+
"main": "dist/browser/index.cjs",
|
52
52
|
"module": "dist/browser/index.js",
|
53
53
|
"homepage": "https://xyo.network",
|
54
54
|
"keywords": [
|
@@ -71,6 +71,6 @@
|
|
71
71
|
},
|
72
72
|
"sideEffects": false,
|
73
73
|
"types": "dist/browser/index.d.ts",
|
74
|
-
"version": "2.64.0
|
75
|
-
"
|
74
|
+
"version": "2.64.0",
|
75
|
+
"type": "module"
|
76
76
|
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export * from './useCustomEvent'\nexport * from './useEvent'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
@@ -1,38 +0,0 @@
|
|
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
|
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1 +0,0 @@
|
|
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":[]}
|
package/dist/node/index.mjs
DELETED
package/dist/node/index.mjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './hooks'\n"],"mappings":"AAAA,cAAc;","names":[]}
|