@xyo-network/react-event 2.62.3 → 2.63.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/hooks/index.js +6 -0
- package/dist/cjs/hooks/index.js.map +1 -0
- package/dist/cjs/hooks/useCustomEvent.js +42 -0
- package/dist/cjs/hooks/useCustomEvent.js.map +1 -0
- package/dist/cjs/hooks/useEvent.js +17 -0
- package/dist/cjs/hooks/useEvent.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/docs.json +14 -14
- package/dist/{hooks/index.d.mts → esm/hooks/index.js} +1 -1
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/useCustomEvent.js +37 -0
- package/dist/esm/hooks/useCustomEvent.js.map +1 -0
- package/dist/esm/hooks/useEvent.js +13 -0
- package/dist/esm/hooks/useEvent.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useCustomEvent.d.ts.map +1 -0
- package/dist/types/hooks/useEvent.d.ts.map +1 -0
- package/dist/{index.d.ts.map → types/index.d.ts.map} +1 -1
- package/package.json +14 -22
- package/dist/hooks/index.d.mts.map +0 -1
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/useCustomEvent.d.mts +0 -4
- package/dist/hooks/useCustomEvent.d.mts.map +0 -1
- package/dist/hooks/useCustomEvent.d.ts.map +0 -1
- package/dist/hooks/useEvent.d.mts +0 -11
- package/dist/hooks/useEvent.d.mts.map +0 -1
- package/dist/hooks/useEvent.d.ts.map +0 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.mts.map +0 -1
- package/dist/index.js +0 -83
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -55
- package/dist/index.mjs.map +0 -1
- /package/dist/{hooks → types/hooks}/index.d.ts +0 -0
- /package/dist/{hooks → types/hooks}/useCustomEvent.d.ts +0 -0
- /package/dist/{hooks → types/hooks}/useEvent.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgC;AAChC,qDAA0B"}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.useCustomEvent = void 0;
|
4
|
+
const assert_1 = require("@xylabs/assert");
|
5
|
+
const react_1 = require("react");
|
6
|
+
const useCustomEvent = (type, listener, customRef) => {
|
7
|
+
const ref = customRef !== null && customRef !== void 0 ? customRef : (0, react_1.createRef)();
|
8
|
+
(0, react_1.useEffect)(() => {
|
9
|
+
const element = ref === null || ref === void 0 ? void 0 : ref.current;
|
10
|
+
const currentListener = listener;
|
11
|
+
const handler = currentListener
|
12
|
+
? (event) => {
|
13
|
+
const detail = (0, assert_1.assertEx)(event.detail, 'Event missing detail');
|
14
|
+
const stop = currentListener(detail);
|
15
|
+
if (stop) {
|
16
|
+
event.stopPropagation();
|
17
|
+
}
|
18
|
+
}
|
19
|
+
: undefined;
|
20
|
+
if (handler && element) {
|
21
|
+
element === null || element === void 0 ? void 0 : element.addEventListener(type, handler);
|
22
|
+
}
|
23
|
+
return () => {
|
24
|
+
if (handler && element) {
|
25
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener(type, handler);
|
26
|
+
}
|
27
|
+
};
|
28
|
+
});
|
29
|
+
const dispatch = (detail) => {
|
30
|
+
var _a;
|
31
|
+
const event = new CustomEvent(type, {
|
32
|
+
bubbles: true,
|
33
|
+
cancelable: true,
|
34
|
+
composed: true,
|
35
|
+
detail,
|
36
|
+
});
|
37
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
|
38
|
+
};
|
39
|
+
return [ref, dispatch];
|
40
|
+
};
|
41
|
+
exports.useCustomEvent = useCustomEvent;
|
42
|
+
//# sourceMappingURL=useCustomEvent.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useCustomEvent.js","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,iCAAuD;AAIhD,MAAM,cAAc,GAAG,CAC5B,IAAY,EACZ,QAAuC,EACvC,SAA+B,EACsB,EAAE;IACvD,MAAM,GAAG,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAA,iBAAS,GAAY,CAAA;IAC9C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAA;QAC5B,MAAM,eAAe,GAAG,QAAQ,CAAA;QAChC,MAAM,OAAO,GAAG,eAAe;YAC7B,CAAC,CAAC,CAAC,KAAuC,EAAE,EAAE;gBAC1C,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,KAAK,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;gBAC7D,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;gBACpC,IAAI,IAAI,EAAE;oBACR,KAAK,CAAC,eAAe,EAAE,CAAA;iBACxB;YACH,CAAC;YACH,CAAC,CAAC,SAAS,CAAA;QAEb,IAAI,OAAO,IAAI,OAAO,EAAE;YACtB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;SACzC;QACD,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,IAAI,OAAO,EAAE;gBACtB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;aAC5C;QACH,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,MAAM,QAAQ,GAAiC,CAAC,MAAgB,EAAE,EAAE;;QAClE,MAAM,KAAK,GAAG,IAAI,WAAW,CAAU,IAAI,EAAE;YAC3C,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,MAAM;SACP,CAAC,CAAA;QACF,MAAA,GAAG,CAAC,OAAO,0CAAE,aAAa,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC,CAAA;IACD,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACxB,CAAC,CAAA;AAtCY,QAAA,cAAc,kBAsC1B"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.useEvent = void 0;
|
4
|
+
const useCustomEvent_1 = require("./useCustomEvent");
|
5
|
+
const useEvent = (listener, sharableRef) => {
|
6
|
+
const [ref, customDispatch] = (0, useCustomEvent_1.useCustomEvent)('xyo', listener
|
7
|
+
? (detail) => {
|
8
|
+
return listener(detail.noun, detail.verb, detail.data);
|
9
|
+
}
|
10
|
+
: undefined, sharableRef);
|
11
|
+
const dispatch = (noun, verb, data) => {
|
12
|
+
return customDispatch({ data, noun, verb });
|
13
|
+
};
|
14
|
+
return [ref, dispatch];
|
15
|
+
};
|
16
|
+
exports.useEvent = useEvent;
|
17
|
+
//# sourceMappingURL=useEvent.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useEvent.js","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAa1C,MAAM,QAAQ,GAAG,CACtB,QAA6C,EAC7C,WAA0B,EAC0B,EAAE;IACtD,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,IAAA,+BAAc,EAC1C,KAAK,EACL,QAAQ;QACN,CAAC,CAAC,CAAC,MAAkC,EAAE,EAAE;YACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,CAAC;QACH,CAAC,CAAC,SAAS,EACb,WAAW,CACZ,CAAA;IAED,MAAM,QAAQ,GAAuC,CAAC,IAAW,EAAE,IAAW,EAAE,IAAY,EAAE,EAAE;QAC9F,OAAO,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IACD,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACxB,CAAC,CAAA;AAlBY,QAAA,QAAQ,YAkBpB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB"}
|
package/dist/docs.json
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
"fileName": "hooks/useEvent.ts",
|
26
26
|
"line": 9,
|
27
27
|
"character": 2,
|
28
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
28
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L9"
|
29
29
|
}
|
30
30
|
],
|
31
31
|
"type": {
|
@@ -46,7 +46,7 @@
|
|
46
46
|
"fileName": "hooks/useEvent.ts",
|
47
47
|
"line": 10,
|
48
48
|
"character": 2,
|
49
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
49
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L10"
|
50
50
|
}
|
51
51
|
],
|
52
52
|
"type": {
|
@@ -67,7 +67,7 @@
|
|
67
67
|
"fileName": "hooks/useEvent.ts",
|
68
68
|
"line": 11,
|
69
69
|
"character": 2,
|
70
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
70
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L11"
|
71
71
|
}
|
72
72
|
],
|
73
73
|
"type": {
|
@@ -93,7 +93,7 @@
|
|
93
93
|
"fileName": "hooks/useEvent.ts",
|
94
94
|
"line": 8,
|
95
95
|
"character": 17,
|
96
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
96
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L8"
|
97
97
|
}
|
98
98
|
],
|
99
99
|
"typeParameters": [
|
@@ -147,7 +147,7 @@
|
|
147
147
|
"fileName": "hooks/useCustomEvent.ts",
|
148
148
|
"line": 4,
|
149
149
|
"character": 12,
|
150
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
150
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L4"
|
151
151
|
}
|
152
152
|
],
|
153
153
|
"typeParameters": [
|
@@ -176,7 +176,7 @@
|
|
176
176
|
"fileName": "hooks/useCustomEvent.ts",
|
177
177
|
"line": 4,
|
178
178
|
"character": 47,
|
179
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
179
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L4"
|
180
180
|
}
|
181
181
|
],
|
182
182
|
"signatures": [
|
@@ -230,7 +230,7 @@
|
|
230
230
|
"fileName": "hooks/useEvent.ts",
|
231
231
|
"line": 14,
|
232
232
|
"character": 12,
|
233
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
233
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L14"
|
234
234
|
}
|
235
235
|
],
|
236
236
|
"typeParameters": [
|
@@ -285,7 +285,7 @@
|
|
285
285
|
"fileName": "hooks/useEvent.ts",
|
286
286
|
"line": 14,
|
287
287
|
"character": 82,
|
288
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
288
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L14"
|
289
289
|
}
|
290
290
|
],
|
291
291
|
"signatures": [
|
@@ -367,7 +367,7 @@
|
|
367
367
|
"fileName": "hooks/useEvent.ts",
|
368
368
|
"line": 5,
|
369
369
|
"character": 12,
|
370
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
370
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L5"
|
371
371
|
}
|
372
372
|
],
|
373
373
|
"type": {
|
@@ -411,7 +411,7 @@
|
|
411
411
|
"fileName": "hooks/useEvent.ts",
|
412
412
|
"line": 6,
|
413
413
|
"character": 12,
|
414
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
414
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L6"
|
415
415
|
}
|
416
416
|
],
|
417
417
|
"type": {
|
@@ -439,7 +439,7 @@
|
|
439
439
|
"fileName": "hooks/useCustomEvent.ts",
|
440
440
|
"line": 6,
|
441
441
|
"character": 13,
|
442
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
442
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L6"
|
443
443
|
}
|
444
444
|
],
|
445
445
|
"signatures": [
|
@@ -454,7 +454,7 @@
|
|
454
454
|
"fileName": "hooks/useCustomEvent.ts",
|
455
455
|
"line": 6,
|
456
456
|
"character": 30,
|
457
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
457
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useCustomEvent.ts#L6"
|
458
458
|
}
|
459
459
|
],
|
460
460
|
"typeParameter": [
|
@@ -600,7 +600,7 @@
|
|
600
600
|
"fileName": "hooks/useEvent.ts",
|
601
601
|
"line": 16,
|
602
602
|
"character": 13,
|
603
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
603
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L16"
|
604
604
|
}
|
605
605
|
],
|
606
606
|
"signatures": [
|
@@ -615,7 +615,7 @@
|
|
615
615
|
"fileName": "hooks/useEvent.ts",
|
616
616
|
"line": 16,
|
617
617
|
"character": 24,
|
618
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
618
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/979e91e13a6b/packages/sdk/packages/event/src/hooks/useEvent.ts#L16"
|
619
619
|
}
|
620
620
|
],
|
621
621
|
"typeParameter": [
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { assertEx } from '@xylabs/assert';
|
2
|
+
import { createRef, useEffect } from 'react';
|
3
|
+
export 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
|
9
|
+
? (event) => {
|
10
|
+
const detail = assertEx(event.detail, 'Event missing detail');
|
11
|
+
const stop = currentListener(detail);
|
12
|
+
if (stop) {
|
13
|
+
event.stopPropagation();
|
14
|
+
}
|
15
|
+
}
|
16
|
+
: undefined;
|
17
|
+
if (handler && element) {
|
18
|
+
element?.addEventListener(type, handler);
|
19
|
+
}
|
20
|
+
return () => {
|
21
|
+
if (handler && element) {
|
22
|
+
element?.removeEventListener(type, handler);
|
23
|
+
}
|
24
|
+
};
|
25
|
+
});
|
26
|
+
const dispatch = (detail) => {
|
27
|
+
const event = new CustomEvent(type, {
|
28
|
+
bubbles: true,
|
29
|
+
cancelable: true,
|
30
|
+
composed: true,
|
31
|
+
detail,
|
32
|
+
});
|
33
|
+
ref.current?.dispatchEvent(event);
|
34
|
+
};
|
35
|
+
return [ref, dispatch];
|
36
|
+
};
|
37
|
+
//# sourceMappingURL=useCustomEvent.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useCustomEvent.js","sourceRoot":"","sources":["../../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAa,SAAS,EAAE,MAAM,OAAO,CAAA;AAIvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,IAAY,EACZ,QAAuC,EACvC,SAA+B,EACsB,EAAE;IACvD,MAAM,GAAG,GAAG,SAAS,IAAI,SAAS,EAAY,CAAA;IAC9C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAA;QAC5B,MAAM,eAAe,GAAG,QAAQ,CAAA;QAChC,MAAM,OAAO,GAAG,eAAe;YAC7B,CAAC,CAAC,CAAC,KAAuC,EAAE,EAAE;gBAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;gBAC7D,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;gBACpC,IAAI,IAAI,EAAE;oBACR,KAAK,CAAC,eAAe,EAAE,CAAA;iBACxB;YACH,CAAC;YACH,CAAC,CAAC,SAAS,CAAA;QAEb,IAAI,OAAO,IAAI,OAAO,EAAE;YACtB,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;SACzC;QACD,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,IAAI,OAAO,EAAE;gBACtB,OAAO,EAAE,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;aAC5C;QACH,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,MAAM,QAAQ,GAAiC,CAAC,MAAgB,EAAE,EAAE;QAClE,MAAM,KAAK,GAAG,IAAI,WAAW,CAAU,IAAI,EAAE;YAC3C,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,MAAM;SACP,CAAC,CAAA;QACF,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC,CAAA;IACD,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACxB,CAAC,CAAA"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { useCustomEvent } from './useCustomEvent';
|
2
|
+
export const useEvent = (listener, sharableRef) => {
|
3
|
+
const [ref, customDispatch] = useCustomEvent('xyo', listener
|
4
|
+
? (detail) => {
|
5
|
+
return listener(detail.noun, detail.verb, detail.data);
|
6
|
+
}
|
7
|
+
: undefined, sharableRef);
|
8
|
+
const dispatch = (noun, verb, data) => {
|
9
|
+
return customDispatch({ data, noun, verb });
|
10
|
+
};
|
11
|
+
return [ref, dispatch];
|
12
|
+
};
|
13
|
+
//# sourceMappingURL=useEvent.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useEvent.js","sourceRoot":"","sources":["../../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAajD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAA6C,EAC7C,WAA0B,EAC0B,EAAE;IACtD,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,cAAc,CAC1C,KAAK,EACL,QAAQ;QACN,CAAC,CAAC,CAAC,MAAkC,EAAE,EAAE;YACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,CAAC;QACH,CAAC,CAAC,SAAS,EACb,WAAW,CACZ,CAAA;IAED,MAAM,QAAQ,GAAuC,CAAC,IAAW,EAAE,IAAW,EAAE,IAAY,EAAE,EAAE;QAC9F,OAAO,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IACD,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACxB,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,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 @@
|
|
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":"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 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
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": "^
|
16
|
+
"@xylabs/ts-scripts-yarn3": "^2.19.12",
|
17
17
|
"typescript": "^5.2.2"
|
18
18
|
},
|
19
19
|
"peerDependencies": {
|
@@ -21,35 +21,27 @@
|
|
21
21
|
"react-dom": "^18.2.0"
|
22
22
|
},
|
23
23
|
"description": "Common React library for all XYO projects that use React",
|
24
|
+
"browser": "dist/esm/index.js",
|
24
25
|
"docs": "dist/docs.json",
|
25
26
|
"exports": {
|
26
27
|
".": {
|
27
28
|
"node": {
|
28
|
-
"import":
|
29
|
-
|
30
|
-
"default": "./dist/index.mjs"
|
31
|
-
},
|
32
|
-
"require": {
|
33
|
-
"types": "./dist/index.d.ts",
|
34
|
-
"default": "./dist/index.js"
|
35
|
-
}
|
29
|
+
"import": "./dist/esm/index.js",
|
30
|
+
"require": "./dist/cjs/index.js"
|
36
31
|
},
|
37
32
|
"browser": {
|
38
|
-
"import":
|
39
|
-
|
40
|
-
"default": "./dist/index.mjs"
|
41
|
-
},
|
42
|
-
"require": {
|
43
|
-
"types": "./dist/index.d.ts",
|
44
|
-
"default": "./dist/index.js"
|
45
|
-
}
|
33
|
+
"import": "./dist/esm/index.js",
|
34
|
+
"require": "./dist/cjs/index.js"
|
46
35
|
},
|
47
|
-
"default": "./dist/index.
|
36
|
+
"default": "./dist/esm/index.js"
|
37
|
+
},
|
38
|
+
"./dist/docs.json": {
|
39
|
+
"default": "./dist/docs.json"
|
48
40
|
},
|
49
41
|
"./package.json": "./package.json"
|
50
42
|
},
|
51
|
-
"main": "dist/index.js",
|
52
|
-
"module": "dist/index.
|
43
|
+
"main": "dist/cjs/index.js",
|
44
|
+
"module": "dist/esm/index.js",
|
53
45
|
"homepage": "https://xyo.network",
|
54
46
|
"keywords": [
|
55
47
|
"xyo",
|
@@ -70,6 +62,6 @@
|
|
70
62
|
"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
63
|
},
|
72
64
|
"sideEffects": false,
|
73
|
-
"types": "dist/index.d.ts",
|
74
|
-
"version": "2.
|
65
|
+
"types": "dist/types/index.d.ts",
|
66
|
+
"version": "2.63.1"
|
75
67
|
}
|
@@ -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,4 +0,0 @@
|
|
1
|
-
import { RefObject } from 'react';
|
2
|
-
export type CustomEventDispatch<T = unknown> = (detail: T) => boolean | void;
|
3
|
-
export declare const useCustomEvent: <TElement extends HTMLElement, TDetail = unknown>(type: string, listener?: CustomEventDispatch<TDetail> | undefined, customRef?: RefObject<TElement> | undefined) => [RefObject<TElement>, CustomEventDispatch<TDetail>];
|
4
|
-
//# sourceMappingURL=useCustomEvent.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useCustomEvent.d.ts","sourceRoot":"","sources":["../../src/hooks/useCustomEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAa,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5E,eAAO,MAAM,cAAc,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,11 +0,0 @@
|
|
1
|
-
import { RefObject } from 'react';
|
2
|
-
export type EventNoun = 'payload' | 'boundwitness' | 'address' | 'hash' | 'signature' | 'schema';
|
3
|
-
export type EventVerb = 'click' | 'favorite';
|
4
|
-
export interface Event<TNoun = EventNoun, TVerb = EventVerb, TData = string> {
|
5
|
-
data?: TData;
|
6
|
-
noun: TNoun;
|
7
|
-
verb: TVerb;
|
8
|
-
}
|
9
|
-
export type EventDispatch<TNoun = EventNoun, TVerb = EventVerb, TData = string> = (noun: TNoun, verb: TVerb, data?: TData) => boolean | void;
|
10
|
-
export declare const useEvent: <T extends HTMLElement, TNoun = EventNoun, TVerb = EventVerb, TData = string>(listener?: EventDispatch<TNoun, TVerb, TData> | undefined, sharableRef?: RefObject<T> | undefined) => [RefObject<T>, EventDispatch<TNoun, TVerb, TData>];
|
11
|
-
//# sourceMappingURL=useEvent.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAChG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;AAE5C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,KAAK,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAA;AAE5I,eAAO,MAAM,QAAQ,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.d.mts
DELETED
package/dist/index.d.mts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
package/dist/index.js
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/index.ts
|
21
|
-
var src_exports = {};
|
22
|
-
__export(src_exports, {
|
23
|
-
useCustomEvent: () => useCustomEvent,
|
24
|
-
useEvent: () => useEvent
|
25
|
-
});
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
27
|
-
|
28
|
-
// src/hooks/useCustomEvent.ts
|
29
|
-
var import_assert = require("@xylabs/assert");
|
30
|
-
var import_react = require("react");
|
31
|
-
var useCustomEvent = (type, listener, customRef) => {
|
32
|
-
const ref = customRef ?? (0, import_react.createRef)();
|
33
|
-
(0, import_react.useEffect)(() => {
|
34
|
-
const element = ref?.current;
|
35
|
-
const currentListener = listener;
|
36
|
-
const handler = currentListener ? (event) => {
|
37
|
-
const detail = (0, import_assert.assertEx)(event.detail, "Event missing detail");
|
38
|
-
const stop = currentListener(detail);
|
39
|
-
if (stop) {
|
40
|
-
event.stopPropagation();
|
41
|
-
}
|
42
|
-
} : void 0;
|
43
|
-
if (handler && element) {
|
44
|
-
element?.addEventListener(type, handler);
|
45
|
-
}
|
46
|
-
return () => {
|
47
|
-
if (handler && element) {
|
48
|
-
element?.removeEventListener(type, handler);
|
49
|
-
}
|
50
|
-
};
|
51
|
-
});
|
52
|
-
const dispatch = (detail) => {
|
53
|
-
const event = new CustomEvent(type, {
|
54
|
-
bubbles: true,
|
55
|
-
cancelable: true,
|
56
|
-
composed: true,
|
57
|
-
detail
|
58
|
-
});
|
59
|
-
ref.current?.dispatchEvent(event);
|
60
|
-
};
|
61
|
-
return [ref, dispatch];
|
62
|
-
};
|
63
|
-
|
64
|
-
// src/hooks/useEvent.ts
|
65
|
-
var useEvent = (listener, sharableRef) => {
|
66
|
-
const [ref, customDispatch] = useCustomEvent(
|
67
|
-
"xyo",
|
68
|
-
listener ? (detail) => {
|
69
|
-
return listener(detail.noun, detail.verb, detail.data);
|
70
|
-
} : void 0,
|
71
|
-
sharableRef
|
72
|
-
);
|
73
|
-
const dispatch = (noun, verb, data) => {
|
74
|
-
return customDispatch({ data, noun, verb });
|
75
|
-
};
|
76
|
-
return [ref, dispatch];
|
77
|
-
};
|
78
|
-
// Annotate the CommonJS export names for ESM import in node:
|
79
|
-
0 && (module.exports = {
|
80
|
-
useCustomEvent,
|
81
|
-
useEvent
|
82
|
-
});
|
83
|
-
//# sourceMappingURL=index.js.map
|
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":[]}
|
package/dist/index.mjs
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
// src/hooks/useCustomEvent.ts
|
2
|
-
import { assertEx } from "@xylabs/assert";
|
3
|
-
import { createRef, useEffect } from "react";
|
4
|
-
var useCustomEvent = (type, listener, customRef) => {
|
5
|
-
const ref = customRef ?? createRef();
|
6
|
-
useEffect(() => {
|
7
|
-
const element = ref?.current;
|
8
|
-
const currentListener = listener;
|
9
|
-
const handler = currentListener ? (event) => {
|
10
|
-
const detail = assertEx(event.detail, "Event missing detail");
|
11
|
-
const stop = currentListener(detail);
|
12
|
-
if (stop) {
|
13
|
-
event.stopPropagation();
|
14
|
-
}
|
15
|
-
} : void 0;
|
16
|
-
if (handler && element) {
|
17
|
-
element?.addEventListener(type, handler);
|
18
|
-
}
|
19
|
-
return () => {
|
20
|
-
if (handler && element) {
|
21
|
-
element?.removeEventListener(type, handler);
|
22
|
-
}
|
23
|
-
};
|
24
|
-
});
|
25
|
-
const dispatch = (detail) => {
|
26
|
-
const event = new CustomEvent(type, {
|
27
|
-
bubbles: true,
|
28
|
-
cancelable: true,
|
29
|
-
composed: true,
|
30
|
-
detail
|
31
|
-
});
|
32
|
-
ref.current?.dispatchEvent(event);
|
33
|
-
};
|
34
|
-
return [ref, dispatch];
|
35
|
-
};
|
36
|
-
|
37
|
-
// src/hooks/useEvent.ts
|
38
|
-
var useEvent = (listener, sharableRef) => {
|
39
|
-
const [ref, customDispatch] = useCustomEvent(
|
40
|
-
"xyo",
|
41
|
-
listener ? (detail) => {
|
42
|
-
return listener(detail.noun, detail.verb, detail.data);
|
43
|
-
} : void 0,
|
44
|
-
sharableRef
|
45
|
-
);
|
46
|
-
const dispatch = (noun, verb, data) => {
|
47
|
-
return customDispatch({ data, noun, verb });
|
48
|
-
};
|
49
|
-
return [ref, dispatch];
|
50
|
-
};
|
51
|
-
export {
|
52
|
-
useCustomEvent,
|
53
|
-
useEvent
|
54
|
-
};
|
55
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
@@ -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
|