chayns-api 3.4.3 → 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.
@@ -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)(5);
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 isClosingRequested = (0, _context.useValuesSelector)(_temp4);
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] !== addDataListener || $[1] !== isClosingRequested || $[2] !== sendData || $[3] !== setResult) {
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
- $[0] = addDataListener;
24
- $[1] = isClosingRequested;
25
- $[2] = sendData;
26
- $[3] = setResult;
27
- $[4] = t0;
83
+ $[3] = addCloseRequestListener;
84
+ $[4] = addDataListener;
85
+ $[5] = isClosingRequested;
86
+ $[6] = sendData;
87
+ $[7] = setResult;
88
+ $[8] = t1;
28
89
  } else {
29
- t0 = $[4];
90
+ t1 = $[8];
30
91
  }
31
- return t0;
92
+ return t1;
32
93
  };
33
94
  exports.useDialogState = useDialogState;
34
95
  const useDialogData = () => {
35
- return (0, _context.useValuesSelector)(_temp5);
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(v) {
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 _temp5(v) {
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(5);
48
+ const $ = _c(9);
5
49
  const setResult = useFunctionsSelector(_temp);
6
50
  const sendData = useFunctionsSelector(_temp2);
7
51
  const addDataListener = useFunctionsSelector(_temp3);
8
- const isClosingRequested = useValuesSelector(_temp4);
52
+ const addDialogCloseRequestListener = useFunctionsSelector(_temp4);
53
+ const removeDialogCloseRequestListener = useFunctionsSelector(_temp5);
54
+ const isClosingRequested = useValuesSelector(_temp6);
9
55
  let t0;
10
- if ($[0] !== addDataListener || $[1] !== isClosingRequested || $[2] !== sendData || $[3] !== setResult) {
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
- $[0] = addDataListener;
18
- $[1] = isClosingRequested;
19
- $[2] = sendData;
20
- $[3] = setResult;
21
- $[4] = t0;
77
+ $[3] = addCloseRequestListener;
78
+ $[4] = addDataListener;
79
+ $[5] = isClosingRequested;
80
+ $[6] = sendData;
81
+ $[7] = setResult;
82
+ $[8] = t1;
22
83
  } else {
23
- t0 = $[4];
84
+ t1 = $[8];
24
85
  }
25
- return t0;
86
+ return t1;
26
87
  };
27
88
  export const useDialogData = () => {
28
- return useValuesSelector(_temp5);
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(v) {
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 _temp5(v) {
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);
@@ -1 +1,2 @@
1
+ /** @deprecated Use createDialog with type DialogType.ALERT instead */
1
2
  export declare function alert(title?: string, message?: string): Promise<any> | "unsupported";
@@ -9,5 +9,6 @@ type Confirm = {
9
9
  links?: unknown;
10
10
  select?: unknown;
11
11
  };
12
+ /** @deprecated Use createDialog with type DialogType.CONFIRM instead */
12
13
  export declare function confirm(title?: string, message?: string, config?: Confirm): Promise<any> | "unsupported";
13
14
  export {};
@@ -47,6 +47,7 @@ type DateConfig = {
47
47
  dateType?: number;
48
48
  autoSelectDate?: boolean;
49
49
  };
50
+ /** @deprecated Use createDialog with type DialogType.DATE instead */
50
51
  export declare function date(config?: DateConfig): Promise<any>;
51
52
  type preSelectObj = {
52
53
  start?: number | undefined | Date;
@@ -1,5 +1,6 @@
1
1
  type DropUpAlert = {
2
2
  callType?: number;
3
3
  };
4
+ /** @deprecated This dialog type has been removed */
4
5
  export declare function dropUpAlert(dialog?: DropUpAlert): Promise<unknown>;
5
6
  export {};
@@ -12,5 +12,6 @@ type FileSelectInput = {
12
12
  directory?: boolean;
13
13
  chaynsToken?: string;
14
14
  };
15
+ /** @deprecated Use createDialog with type DialogType.FILE_SELECT instead */
15
16
  export declare function fileSelect(dialog?: FileSelectInput): Promise<unknown>;
16
17
  export {};
@@ -11,6 +11,8 @@ type IFrameDialog = {
11
11
  fullHeight?: boolean;
12
12
  customTransitionTimeout?: number;
13
13
  };
14
+ /** @deprecated Backward compatibility to open iFrame dialogs based on chayns-js.
15
+ * Consider migrating the dialog to use chayns-api and use createDialog with type DialogType.IFRAME instead */
14
16
  export declare function iFrame(dialog?: IFrameDialog): Promise<unknown>;
15
17
  export declare function _chaynsCallResponder(obj: any): void;
16
18
  export {};
@@ -4,6 +4,7 @@ type InputDialog = {
4
4
  callType?: number;
5
5
  formatter?: string;
6
6
  };
7
+ /** @deprecated Use createDialog with type DialogType.INPUT instead */
7
8
  export declare function input(dialog?: InputDialog): Promise<unknown>;
8
9
  export declare const inputType: {
9
10
  DEFAULT: number;
@@ -4,5 +4,6 @@ type MediaSelectInput = {
4
4
  callType?: number;
5
5
  chaynsToken?: string;
6
6
  };
7
+ /** @deprecated This dialog type hase been removed */
7
8
  export declare function mediaSelect(dialog?: MediaSelectInput): Promise<unknown>;
8
9
  export {};
@@ -1,4 +1,5 @@
1
1
  import { SelectInput } from '../../types/IChaynsReact';
2
+ /** @deprecated Use createDialog with type DialogType.SELECT instead */
2
3
  export declare function select(config: SelectInput): Promise<unknown>;
3
4
  export declare const selectType: {
4
5
  DEFAULT: number;
@@ -3,5 +3,6 @@ type SignatureInput = {
3
3
  buttons?: DialogButtonOld[];
4
4
  callType?: number;
5
5
  };
6
+ /** @deprecated Use createDialog with type DialogType.SIGNATURE instead */
6
7
  export declare function signature(dialog?: SignatureInput): Promise<unknown>;
7
8
  export {};
@@ -1 +1,2 @@
1
+ /** @deprecated Use createDialog with type DialogType.TOAST instead */
1
2
  export declare function toast(config?: {}): Promise<any>;
@@ -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'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.4.3",
3
+ "version": "3.5.0-beta.0",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",