chayns-api 3.4.4 → 3.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useDialogState.js +82 -15
- package/dist/cjs/wrapper/AppWrapper.js +7 -0
- package/dist/cjs/wrapper/FrameWrapper.js +16 -0
- package/dist/esm/hooks/useDialogState.js +82 -15
- package/dist/esm/wrapper/AppWrapper.js +7 -0
- package/dist/esm/wrapper/FrameWrapper.js +16 -0
- package/dist/esm/wrapper/StaticChaynsApi.js +2 -0
- package/dist/types/types/IChaynsReact.d.ts +19 -0
- package/dist/types/wrapper/StaticChaynsApi.d.ts +2 -0
- package/package.json +1 -1
|
@@ -5,34 +5,95 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useDialogState = exports.useDialogData = void 0;
|
|
7
7
|
var _reactCompilerRuntime = require("react-compiler-runtime");
|
|
8
|
+
var _react = require("react");
|
|
8
9
|
var _context = require("./context");
|
|
10
|
+
const closeRequestListeners = [];
|
|
11
|
+
let hostListenerId = null;
|
|
12
|
+
const dispatchCloseRequest = data => {
|
|
13
|
+
let isPropagationStopped = false;
|
|
14
|
+
const event = {
|
|
15
|
+
reason: data.reason,
|
|
16
|
+
stopPropagation: () => {
|
|
17
|
+
isPropagationStopped = true;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const listeners = [...closeRequestListeners].reverse();
|
|
21
|
+
for (const listener of listeners) {
|
|
22
|
+
listener(event);
|
|
23
|
+
if (isPropagationStopped) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const createAddCloseRequestListener = functions => listener => {
|
|
29
|
+
closeRequestListeners.push(listener);
|
|
30
|
+
if (closeRequestListeners.length === 1) {
|
|
31
|
+
if (!hostListenerId) {
|
|
32
|
+
var _functions$addDialogC, _functions$addDialogC2;
|
|
33
|
+
hostListenerId = (_functions$addDialogC = (_functions$addDialogC2 = functions.addDialogCloseRequestListener) === null || _functions$addDialogC2 === void 0 ? void 0 : _functions$addDialogC2.call(functions, dispatchCloseRequest)) !== null && _functions$addDialogC !== void 0 ? _functions$addDialogC : null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return () => {
|
|
37
|
+
const index = closeRequestListeners.indexOf(listener);
|
|
38
|
+
if (index === -1) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
closeRequestListeners.splice(index, 1);
|
|
42
|
+
if (closeRequestListeners.length === 0) {
|
|
43
|
+
if (hostListenerId) {
|
|
44
|
+
void hostListenerId.then(id => {
|
|
45
|
+
var _functions$removeDial;
|
|
46
|
+
return (_functions$removeDial = functions.removeDialogCloseRequestListener) === null || _functions$removeDial === void 0 ? void 0 : _functions$removeDial.call(functions, id);
|
|
47
|
+
});
|
|
48
|
+
hostListenerId = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
9
53
|
const useDialogState = () => {
|
|
10
|
-
const $ = (0, _reactCompilerRuntime.c)(
|
|
54
|
+
const $ = (0, _reactCompilerRuntime.c)(9);
|
|
11
55
|
const setResult = (0, _context.useFunctionsSelector)(_temp);
|
|
12
56
|
const sendData = (0, _context.useFunctionsSelector)(_temp2);
|
|
13
57
|
const addDataListener = (0, _context.useFunctionsSelector)(_temp3);
|
|
14
|
-
const
|
|
58
|
+
const addDialogCloseRequestListener = (0, _context.useFunctionsSelector)(_temp4);
|
|
59
|
+
const removeDialogCloseRequestListener = (0, _context.useFunctionsSelector)(_temp5);
|
|
60
|
+
const isClosingRequested = (0, _context.useValuesSelector)(_temp6);
|
|
15
61
|
let t0;
|
|
16
|
-
if ($[0] !==
|
|
17
|
-
t0 = {
|
|
62
|
+
if ($[0] !== addDialogCloseRequestListener || $[1] !== removeDialogCloseRequestListener) {
|
|
63
|
+
t0 = createAddCloseRequestListener({
|
|
64
|
+
addDialogCloseRequestListener,
|
|
65
|
+
removeDialogCloseRequestListener
|
|
66
|
+
});
|
|
67
|
+
$[0] = addDialogCloseRequestListener;
|
|
68
|
+
$[1] = removeDialogCloseRequestListener;
|
|
69
|
+
$[2] = t0;
|
|
70
|
+
} else {
|
|
71
|
+
t0 = $[2];
|
|
72
|
+
}
|
|
73
|
+
const addCloseRequestListener = t0;
|
|
74
|
+
let t1;
|
|
75
|
+
if ($[3] !== addCloseRequestListener || $[4] !== addDataListener || $[5] !== isClosingRequested || $[6] !== sendData || $[7] !== setResult) {
|
|
76
|
+
t1 = {
|
|
18
77
|
setResult,
|
|
19
78
|
sendData,
|
|
20
79
|
addDataListener,
|
|
21
|
-
isClosingRequested
|
|
80
|
+
isClosingRequested,
|
|
81
|
+
addCloseRequestListener
|
|
22
82
|
};
|
|
23
|
-
$[
|
|
24
|
-
$[
|
|
25
|
-
$[
|
|
26
|
-
$[
|
|
27
|
-
$[
|
|
83
|
+
$[3] = addCloseRequestListener;
|
|
84
|
+
$[4] = addDataListener;
|
|
85
|
+
$[5] = isClosingRequested;
|
|
86
|
+
$[6] = sendData;
|
|
87
|
+
$[7] = setResult;
|
|
88
|
+
$[8] = t1;
|
|
28
89
|
} else {
|
|
29
|
-
|
|
90
|
+
t1 = $[8];
|
|
30
91
|
}
|
|
31
|
-
return
|
|
92
|
+
return t1;
|
|
32
93
|
};
|
|
33
94
|
exports.useDialogState = useDialogState;
|
|
34
95
|
const useDialogData = () => {
|
|
35
|
-
return (0, _context.useValuesSelector)(
|
|
96
|
+
return (0, _context.useValuesSelector)(_temp7);
|
|
36
97
|
};
|
|
37
98
|
exports.useDialogData = useDialogData;
|
|
38
99
|
function _temp(f) {
|
|
@@ -44,11 +105,17 @@ function _temp2(f_0) {
|
|
|
44
105
|
function _temp3(f_1) {
|
|
45
106
|
return f_1.addDialogHostEventListener;
|
|
46
107
|
}
|
|
47
|
-
function _temp4(
|
|
108
|
+
function _temp4(f_2) {
|
|
109
|
+
return f_2.addDialogCloseRequestListener;
|
|
110
|
+
}
|
|
111
|
+
function _temp5(f_3) {
|
|
112
|
+
return f_3.removeDialogCloseRequestListener;
|
|
113
|
+
}
|
|
114
|
+
function _temp6(v) {
|
|
48
115
|
var _v$dialog$isClosingRe, _v$dialog;
|
|
49
116
|
return (_v$dialog$isClosingRe = (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested) !== null && _v$dialog$isClosingRe !== void 0 ? _v$dialog$isClosingRe : false;
|
|
50
117
|
}
|
|
51
|
-
function
|
|
118
|
+
function _temp7(v) {
|
|
52
119
|
var _v$dialog2;
|
|
53
120
|
return (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
|
|
54
121
|
}
|
|
@@ -736,6 +736,13 @@ class AppWrapper {
|
|
|
736
736
|
this.notImplemented('addDialogHostEventListener');
|
|
737
737
|
}
|
|
738
738
|
},
|
|
739
|
+
addDialogCloseRequestListener: async () => {
|
|
740
|
+
this.notImplemented('addDialogCloseRequestListener');
|
|
741
|
+
return -1;
|
|
742
|
+
},
|
|
743
|
+
removeDialogCloseRequestListener: async () => {
|
|
744
|
+
this.notImplemented('removeDialogCloseRequestListener');
|
|
745
|
+
},
|
|
739
746
|
addAnonymousAccount: async () => {
|
|
740
747
|
return this.appCall(302);
|
|
741
748
|
},
|
|
@@ -300,6 +300,22 @@ class FrameWrapper {
|
|
|
300
300
|
if (!this.initialized) await this.ready;
|
|
301
301
|
return this.exposedFunctions.removeDialogHostEventListener(id);
|
|
302
302
|
},
|
|
303
|
+
addDialogCloseRequestListener: async callback => {
|
|
304
|
+
if (!this.initialized) await this.ready;
|
|
305
|
+
try {
|
|
306
|
+
return await this.exposedFunctions.addDialogCloseRequestListener(comlink.proxy(data => {
|
|
307
|
+
callback(data);
|
|
308
|
+
}));
|
|
309
|
+
} catch {
|
|
310
|
+
console.warn('[chayns-api] addDialogCloseRequestListener is not supported by the host');
|
|
311
|
+
return -1;
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
removeDialogCloseRequestListener: async id => {
|
|
315
|
+
var _this$exposedFunction, _this$exposedFunction2;
|
|
316
|
+
if (!this.initialized) await this.ready;
|
|
317
|
+
return (_this$exposedFunction = (_this$exposedFunction2 = this.exposedFunctions).removeDialogCloseRequestListener) === null || _this$exposedFunction === void 0 ? void 0 : _this$exposedFunction.call(_this$exposedFunction2, id);
|
|
318
|
+
},
|
|
303
319
|
removeDialogClientEventListener: async () => {},
|
|
304
320
|
addAnonymousAccount: async () => {
|
|
305
321
|
if (!this.initialized) await this.ready;
|
|
@@ -1,31 +1,92 @@
|
|
|
1
1
|
import { c as _c } from "react-compiler-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import { useFunctionsSelector, useValuesSelector } from './context';
|
|
4
|
+
const closeRequestListeners = [];
|
|
5
|
+
let hostListenerId = null;
|
|
6
|
+
const dispatchCloseRequest = data => {
|
|
7
|
+
let isPropagationStopped = false;
|
|
8
|
+
const event = {
|
|
9
|
+
reason: data.reason,
|
|
10
|
+
stopPropagation: () => {
|
|
11
|
+
isPropagationStopped = true;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const listeners = [...closeRequestListeners].reverse();
|
|
15
|
+
for (const listener of listeners) {
|
|
16
|
+
listener(event);
|
|
17
|
+
if (isPropagationStopped) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const createAddCloseRequestListener = functions => listener => {
|
|
23
|
+
closeRequestListeners.push(listener);
|
|
24
|
+
if (closeRequestListeners.length === 1) {
|
|
25
|
+
if (!hostListenerId) {
|
|
26
|
+
var _functions$addDialogC, _functions$addDialogC2;
|
|
27
|
+
hostListenerId = (_functions$addDialogC = (_functions$addDialogC2 = functions.addDialogCloseRequestListener) === null || _functions$addDialogC2 === void 0 ? void 0 : _functions$addDialogC2.call(functions, dispatchCloseRequest)) !== null && _functions$addDialogC !== void 0 ? _functions$addDialogC : null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return () => {
|
|
31
|
+
const index = closeRequestListeners.indexOf(listener);
|
|
32
|
+
if (index === -1) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
closeRequestListeners.splice(index, 1);
|
|
36
|
+
if (closeRequestListeners.length === 0) {
|
|
37
|
+
if (hostListenerId) {
|
|
38
|
+
void hostListenerId.then(id => {
|
|
39
|
+
var _functions$removeDial;
|
|
40
|
+
return (_functions$removeDial = functions.removeDialogCloseRequestListener) === null || _functions$removeDial === void 0 ? void 0 : _functions$removeDial.call(functions, id);
|
|
41
|
+
});
|
|
42
|
+
hostListenerId = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
3
47
|
export const useDialogState = () => {
|
|
4
|
-
const $ = _c(
|
|
48
|
+
const $ = _c(9);
|
|
5
49
|
const setResult = useFunctionsSelector(_temp);
|
|
6
50
|
const sendData = useFunctionsSelector(_temp2);
|
|
7
51
|
const addDataListener = useFunctionsSelector(_temp3);
|
|
8
|
-
const
|
|
52
|
+
const addDialogCloseRequestListener = useFunctionsSelector(_temp4);
|
|
53
|
+
const removeDialogCloseRequestListener = useFunctionsSelector(_temp5);
|
|
54
|
+
const isClosingRequested = useValuesSelector(_temp6);
|
|
9
55
|
let t0;
|
|
10
|
-
if ($[0] !==
|
|
11
|
-
t0 = {
|
|
56
|
+
if ($[0] !== addDialogCloseRequestListener || $[1] !== removeDialogCloseRequestListener) {
|
|
57
|
+
t0 = createAddCloseRequestListener({
|
|
58
|
+
addDialogCloseRequestListener,
|
|
59
|
+
removeDialogCloseRequestListener
|
|
60
|
+
});
|
|
61
|
+
$[0] = addDialogCloseRequestListener;
|
|
62
|
+
$[1] = removeDialogCloseRequestListener;
|
|
63
|
+
$[2] = t0;
|
|
64
|
+
} else {
|
|
65
|
+
t0 = $[2];
|
|
66
|
+
}
|
|
67
|
+
const addCloseRequestListener = t0;
|
|
68
|
+
let t1;
|
|
69
|
+
if ($[3] !== addCloseRequestListener || $[4] !== addDataListener || $[5] !== isClosingRequested || $[6] !== sendData || $[7] !== setResult) {
|
|
70
|
+
t1 = {
|
|
12
71
|
setResult,
|
|
13
72
|
sendData,
|
|
14
73
|
addDataListener,
|
|
15
|
-
isClosingRequested
|
|
74
|
+
isClosingRequested,
|
|
75
|
+
addCloseRequestListener
|
|
16
76
|
};
|
|
17
|
-
$[
|
|
18
|
-
$[
|
|
19
|
-
$[
|
|
20
|
-
$[
|
|
21
|
-
$[
|
|
77
|
+
$[3] = addCloseRequestListener;
|
|
78
|
+
$[4] = addDataListener;
|
|
79
|
+
$[5] = isClosingRequested;
|
|
80
|
+
$[6] = sendData;
|
|
81
|
+
$[7] = setResult;
|
|
82
|
+
$[8] = t1;
|
|
22
83
|
} else {
|
|
23
|
-
|
|
84
|
+
t1 = $[8];
|
|
24
85
|
}
|
|
25
|
-
return
|
|
86
|
+
return t1;
|
|
26
87
|
};
|
|
27
88
|
export const useDialogData = () => {
|
|
28
|
-
return useValuesSelector(
|
|
89
|
+
return useValuesSelector(_temp7);
|
|
29
90
|
};
|
|
30
91
|
function _temp(f) {
|
|
31
92
|
return f.setDialogResult;
|
|
@@ -36,11 +97,17 @@ function _temp2(f_0) {
|
|
|
36
97
|
function _temp3(f_1) {
|
|
37
98
|
return f_1.addDialogHostEventListener;
|
|
38
99
|
}
|
|
39
|
-
function _temp4(
|
|
100
|
+
function _temp4(f_2) {
|
|
101
|
+
return f_2.addDialogCloseRequestListener;
|
|
102
|
+
}
|
|
103
|
+
function _temp5(f_3) {
|
|
104
|
+
return f_3.removeDialogCloseRequestListener;
|
|
105
|
+
}
|
|
106
|
+
function _temp6(v) {
|
|
40
107
|
var _v$dialog$isClosingRe, _v$dialog;
|
|
41
108
|
return (_v$dialog$isClosingRe = (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested) !== null && _v$dialog$isClosingRe !== void 0 ? _v$dialog$isClosingRe : false;
|
|
42
109
|
}
|
|
43
|
-
function
|
|
110
|
+
function _temp7(v) {
|
|
44
111
|
var _v$dialog2;
|
|
45
112
|
return (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
|
|
46
113
|
}
|
|
@@ -699,6 +699,13 @@ export class AppWrapper {
|
|
|
699
699
|
this.notImplemented('addDialogHostEventListener');
|
|
700
700
|
}
|
|
701
701
|
},
|
|
702
|
+
addDialogCloseRequestListener: async () => {
|
|
703
|
+
this.notImplemented('addDialogCloseRequestListener');
|
|
704
|
+
return -1;
|
|
705
|
+
},
|
|
706
|
+
removeDialogCloseRequestListener: async () => {
|
|
707
|
+
this.notImplemented('removeDialogCloseRequestListener');
|
|
708
|
+
},
|
|
702
709
|
addAnonymousAccount: async () => {
|
|
703
710
|
return this.appCall(302);
|
|
704
711
|
},
|
|
@@ -296,6 +296,22 @@ export class FrameWrapper {
|
|
|
296
296
|
if (!this.initialized) await this.ready;
|
|
297
297
|
return this.exposedFunctions.removeDialogHostEventListener(id);
|
|
298
298
|
},
|
|
299
|
+
addDialogCloseRequestListener: async callback => {
|
|
300
|
+
if (!this.initialized) await this.ready;
|
|
301
|
+
try {
|
|
302
|
+
return await this.exposedFunctions.addDialogCloseRequestListener(comlink.proxy(data => {
|
|
303
|
+
callback(data);
|
|
304
|
+
}));
|
|
305
|
+
} catch {
|
|
306
|
+
console.warn('[chayns-api] addDialogCloseRequestListener is not supported by the host');
|
|
307
|
+
return -1;
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
removeDialogCloseRequestListener: async id => {
|
|
311
|
+
var _this$exposedFunction, _this$exposedFunction2;
|
|
312
|
+
if (!this.initialized) await this.ready;
|
|
313
|
+
return (_this$exposedFunction = (_this$exposedFunction2 = this.exposedFunctions).removeDialogCloseRequestListener) === null || _this$exposedFunction === void 0 ? void 0 : _this$exposedFunction.call(_this$exposedFunction2, id);
|
|
314
|
+
},
|
|
299
315
|
removeDialogClientEventListener: async () => {},
|
|
300
316
|
addAnonymousAccount: async () => {
|
|
301
317
|
if (!this.initialized) await this.ready;
|
|
@@ -73,6 +73,8 @@ class StaticChaynsApi {
|
|
|
73
73
|
_defineProperty(this, "dispatchEventToDialogHost", void 0);
|
|
74
74
|
_defineProperty(this, "addDialogHostEventListener", void 0);
|
|
75
75
|
_defineProperty(this, "removeDialogHostEventListener", void 0);
|
|
76
|
+
_defineProperty(this, "addDialogCloseRequestListener", void 0);
|
|
77
|
+
_defineProperty(this, "removeDialogCloseRequestListener", void 0);
|
|
76
78
|
_defineProperty(this, "addAnonymousAccount", void 0);
|
|
77
79
|
_defineProperty(this, "addAccessTokenChangeListener", void 0);
|
|
78
80
|
_defineProperty(this, "removeAccessTokenChangeListener", void 0);
|
|
@@ -339,11 +339,24 @@ export type ChaynsApiDevice = {
|
|
|
339
339
|
isTouch: boolean;
|
|
340
340
|
screenSize: ScreenSize;
|
|
341
341
|
};
|
|
342
|
+
export type DialogCloseRequestReason = 'backdrop' | 'esc';
|
|
343
|
+
export interface DialogCloseRequestEvent {
|
|
344
|
+
reason: DialogCloseRequestReason;
|
|
345
|
+
/** Prevents subsequent close request listeners from being invoked. Must be called synchronously. */
|
|
346
|
+
stopPropagation: () => void;
|
|
347
|
+
}
|
|
342
348
|
export type DialogHookResult = {
|
|
343
349
|
isClosingRequested: boolean;
|
|
344
350
|
setResult: ChaynsReactFunctions["setDialogResult"];
|
|
345
351
|
sendData: ChaynsReactFunctions["dispatchEventToDialogHost"];
|
|
346
352
|
addDataListener: ChaynsReactFunctions["addDialogHostEventListener"];
|
|
353
|
+
/**
|
|
354
|
+
* Adds a listener which is invoked instead of closing the dialog when the user clicks the backdrop or presses escape.
|
|
355
|
+
* While at least one listener is registered the dialog will not be closed automatically.
|
|
356
|
+
* Listeners are invoked in reverse registration order (LIFO) until stopPropagation is called.
|
|
357
|
+
* @returns function to remove the listener
|
|
358
|
+
*/
|
|
359
|
+
addCloseRequestListener: (listener: (event: DialogCloseRequestEvent) => void) => () => void;
|
|
347
360
|
};
|
|
348
361
|
/**
|
|
349
362
|
* @ignore
|
|
@@ -503,6 +516,12 @@ export interface ChaynsReactFunctions {
|
|
|
503
516
|
addDialogHostEventListener: (callback: (data: object) => void) => Promise<number>;
|
|
504
517
|
/** Removes listeners which were added via addDialogHostEventListener */
|
|
505
518
|
removeDialogHostEventListener: (id: number) => Promise<void>;
|
|
519
|
+
/** Allows the dialog to listen for close requests (backdrop click, escape) while close interception is enabled */
|
|
520
|
+
addDialogCloseRequestListener?: (callback: (data: {
|
|
521
|
+
reason: DialogCloseRequestReason;
|
|
522
|
+
}) => void) => Promise<number>;
|
|
523
|
+
/** Removes listeners which were added via addDialogCloseRequestListener */
|
|
524
|
+
removeDialogCloseRequestListener?: (id: number) => Promise<void>;
|
|
506
525
|
addAnonymousAccount: () => Promise<AnonymousAccountResult>;
|
|
507
526
|
addAccessTokenChangeListener: (options: {
|
|
508
527
|
external?: boolean;
|
|
@@ -63,6 +63,8 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
|
|
|
63
63
|
dispatchEventToDialogHost: ChaynsReactFunctions['dispatchEventToDialogHost'];
|
|
64
64
|
addDialogHostEventListener: ChaynsReactFunctions['addDialogHostEventListener'];
|
|
65
65
|
removeDialogHostEventListener: ChaynsReactFunctions['removeDialogHostEventListener'];
|
|
66
|
+
addDialogCloseRequestListener: ChaynsReactFunctions['addDialogCloseRequestListener'];
|
|
67
|
+
removeDialogCloseRequestListener: ChaynsReactFunctions['removeDialogCloseRequestListener'];
|
|
66
68
|
addAnonymousAccount: ChaynsReactFunctions['addAnonymousAccount'];
|
|
67
69
|
addAccessTokenChangeListener: ChaynsReactFunctions['addAccessTokenChangeListener'];
|
|
68
70
|
removeAccessTokenChangeListener: ChaynsReactFunctions['removeAccessTokenChangeListener'];
|