chayns-api 1.0.13 → 1.0.15

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.
Files changed (46) hide show
  1. package/dist/cjs/calls/index.js +7 -2
  2. package/dist/cjs/components/AppDialogWrapper.js +42 -0
  3. package/dist/cjs/components/ChaynsProvider.js +5 -2
  4. package/dist/cjs/handler/DialogHandler.js +65 -0
  5. package/dist/cjs/hooks/index.js +14 -1
  6. package/dist/cjs/hooks/useDialogState.js +39 -0
  7. package/dist/cjs/host/ChaynsHost.js +10 -5
  8. package/dist/cjs/host/iframe/HostIframe.js +5 -2
  9. package/dist/cjs/host/module/ModuleHost.js +4 -0
  10. package/dist/cjs/types/IChaynsReact.js +22 -2
  11. package/dist/cjs/wrapper/AppWrapper.js +39 -0
  12. package/dist/cjs/wrapper/FrameWrapper.js +52 -1
  13. package/dist/cjs/wrapper/ModuleFederationWrapper.js +4 -0
  14. package/dist/esm/calls/index.js +6 -0
  15. package/dist/esm/components/AppDialogWrapper.js +33 -0
  16. package/dist/esm/components/ChaynsProvider.js +5 -2
  17. package/dist/esm/handler/DialogHandler.js +61 -0
  18. package/dist/esm/hooks/index.js +2 -1
  19. package/dist/esm/hooks/useDialogState.js +32 -0
  20. package/dist/esm/host/ChaynsHost.js +10 -5
  21. package/dist/esm/host/iframe/HostIframe.js +5 -2
  22. package/dist/esm/host/module/ModuleHost.js +4 -0
  23. package/dist/esm/types/IChaynsReact.js +19 -1
  24. package/dist/esm/wrapper/AppWrapper.js +39 -0
  25. package/dist/esm/wrapper/FrameWrapper.js +52 -1
  26. package/dist/esm/wrapper/ModuleFederationWrapper.js +4 -0
  27. package/dist/types/calls/dialogs/confirm.d.ts +4 -4
  28. package/dist/types/calls/dialogs/date.d.ts +3 -3
  29. package/dist/types/calls/dialogs/fileSelect.d.ts +2 -2
  30. package/dist/types/calls/dialogs/iFrame.d.ts +2 -2
  31. package/dist/types/calls/dialogs/input.d.ts +2 -2
  32. package/dist/types/calls/dialogs/mediaSelect.d.ts +2 -2
  33. package/dist/types/calls/dialogs/signature.d.ts +2 -2
  34. package/dist/types/calls/index.d.ts +4 -0
  35. package/dist/types/components/AppDialogWrapper.d.ts +5 -0
  36. package/dist/types/components/WaitUntil.d.ts +1 -2
  37. package/dist/types/handler/DialogHandler.d.ts +19 -0
  38. package/dist/types/hooks/index.d.ts +1 -0
  39. package/dist/types/hooks/useDialogState.d.ts +9 -0
  40. package/dist/types/host/ChaynsHost.d.ts +5 -4
  41. package/dist/types/host/iframe/HostIframe.d.ts +1 -0
  42. package/dist/types/host/module/ModuleHost.d.ts +1 -0
  43. package/dist/types/types/IChaynsReact.d.ts +90 -5
  44. package/dist/types/types/dialog.d.ts +1 -1
  45. package/dist/types/wrapper/AppWrapper.d.ts +4 -0
  46. package/package.json +4 -4
@@ -0,0 +1,32 @@
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import { ChaynsContext, ChaynsFunctionsContext } from '../components/ChaynsContext';
3
+
4
+ /**
5
+ * @category Hooks
6
+ */
7
+ export const useDialogState = () => {
8
+ const setResult = useContextSelector(ChaynsFunctionsContext, v => v === null || v === void 0 ? void 0 : v.setDialogResult);
9
+ const sendData = useContextSelector(ChaynsFunctionsContext, v => v === null || v === void 0 ? void 0 : v.dispatchEventToDialogHost);
10
+ const addDataListener = useContextSelector(ChaynsFunctionsContext, v => v === null || v === void 0 ? void 0 : v.addDialogHostEventListener);
11
+ const isClosingRequested = useContextSelector(ChaynsContext, v => {
12
+ var _v$dialog;
13
+ return v === null || v === void 0 ? void 0 : (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested;
14
+ });
15
+ return {
16
+ setResult,
17
+ sendData,
18
+ addDataListener,
19
+ isClosingRequested
20
+ };
21
+ };
22
+
23
+ /**
24
+ * @category Hooks
25
+ */
26
+ export const useDialogData = () => {
27
+ const inputData = useContextSelector(ChaynsContext, v => {
28
+ var _v$dialog2;
29
+ return v === null || v === void 0 ? void 0 : (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
30
+ });
31
+ return inputData;
32
+ };
@@ -22,7 +22,8 @@ const ChaynsHost = _ref => {
22
22
  parameters,
23
23
  customData,
24
24
  environment,
25
- preventStagingReplacement
25
+ preventStagingReplacement,
26
+ dialog
26
27
  } = _ref;
27
28
  switch (type) {
28
29
  case 'client-iframe':
@@ -41,7 +42,8 @@ const ChaynsHost = _ref => {
41
42
  parameters: parameters,
42
43
  environment: environment,
43
44
  customData: customData,
44
- preventStagingReplacement: preventStagingReplacement
45
+ preventStagingReplacement: preventStagingReplacement,
46
+ dialog: dialog
45
47
  });
46
48
  case 'client-module':
47
49
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -58,7 +60,8 @@ const ChaynsHost = _ref => {
58
60
  parameters: parameters,
59
61
  customData: customData,
60
62
  environment: environment,
61
- preventStagingReplacement: preventStagingReplacement
63
+ preventStagingReplacement: preventStagingReplacement,
64
+ dialog: dialog
62
65
  });
63
66
  case 'server-iframe':
64
67
  return /*#__PURE__*/React.createElement(HostIframe, {
@@ -77,7 +80,8 @@ const ChaynsHost = _ref => {
77
80
  parameters: parameters,
78
81
  environment: environment,
79
82
  customData: customData,
80
- preventStagingReplacement: preventStagingReplacement
83
+ preventStagingReplacement: preventStagingReplacement,
84
+ dialog: dialog
81
85
  });
82
86
  case 'server-module':
83
87
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -93,7 +97,8 @@ const ChaynsHost = _ref => {
93
97
  parameters: parameters,
94
98
  customData: customData,
95
99
  environment: environment,
96
- preventStagingReplacement: preventStagingReplacement
100
+ preventStagingReplacement: preventStagingReplacement,
101
+ dialog: dialog
97
102
  }, children);
98
103
  default:
99
104
  return null;
@@ -22,7 +22,8 @@ const HostIframe = _ref => {
22
22
  parameters,
23
23
  environment,
24
24
  customData,
25
- preventStagingReplacement
25
+ preventStagingReplacement,
26
+ dialog
26
27
  } = _ref;
27
28
  const eventTarget = useRef();
28
29
  const ref = useRef();
@@ -48,7 +49,8 @@ const HostIframe = _ref => {
48
49
  language,
49
50
  parameters,
50
51
  environment,
51
- customData
52
+ customData,
53
+ dialog
52
54
  };
53
55
  // endregion
54
56
 
@@ -108,6 +110,7 @@ const HostIframe = _ref => {
108
110
  useUpdateData(eventTarget.current, 'parameters', parameters);
109
111
  useUpdateData(eventTarget.current, 'environment', environment);
110
112
  useUpdateData(eventTarget.current, 'customData', customData);
113
+ useUpdateData(eventTarget.current, 'dialog', dialog);
111
114
  // endregion
112
115
 
113
116
  return /*#__PURE__*/React.createElement("iframe", _extends({
@@ -43,6 +43,7 @@ const ModuleHost = _ref2 => {
43
43
  language,
44
44
  parameters,
45
45
  customData,
46
+ dialog,
46
47
  environment,
47
48
  preventStagingReplacement
48
49
  } = _ref2;
@@ -61,6 +62,9 @@ const ModuleHost = _ref2 => {
61
62
  if (user) {
62
63
  initialData.user = user;
63
64
  }
65
+ if (dialog) {
66
+ initialData.dialog = dialog;
67
+ }
64
68
  // endregion
65
69
 
66
70
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
@@ -1,3 +1,9 @@
1
+ export let DialogButtonType;
2
+ (function (DialogButtonType) {
3
+ DialogButtonType[DialogButtonType["OK"] = 1] = "OK";
4
+ DialogButtonType[DialogButtonType["CANCEL"] = -1] = "CANCEL";
5
+ DialogButtonType[DialogButtonType["NEGATIVE"] = 0] = "NEGATIVE";
6
+ })(DialogButtonType || (DialogButtonType = {}));
1
7
  export let ScreenSize;
2
8
  (function (ScreenSize) {
3
9
  ScreenSize[ScreenSize["XS"] = 0] = "XS";
@@ -235,4 +241,16 @@ var selectType;
235
241
  (function (selectType) {
236
242
  selectType[selectType["DEFAULT"] = 0] = "DEFAULT";
237
243
  selectType[selectType["ICON"] = 1] = "ICON";
238
- })(selectType || (selectType = {}));
244
+ })(selectType || (selectType = {}));
245
+ export let DialogType;
246
+ (function (DialogType) {
247
+ DialogType["ALERT"] = "alert";
248
+ DialogType["CONFIRM"] = "confirm";
249
+ DialogType["DATE"] = "date";
250
+ DialogType["FILE_SELECT"] = "fileSelect";
251
+ DialogType["IFRAME"] = "iframe";
252
+ DialogType["MODULE"] = "module";
253
+ DialogType["INPUT"] = "input";
254
+ DialogType["SELECT"] = "select";
255
+ DialogType["TOAST"] = "toast";
256
+ })(DialogType || (DialogType = {}));
@@ -5,12 +5,14 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
5
5
  // @ts-nocheck
6
6
 
7
7
  import throttle from 'lodash.throttle';
8
+ import DialogHandler from '../handler/DialogHandler';
8
9
  import { Environment, Font, Gender, IconType, RuntimeEnviroment, TappEvent } from '../types/IChaynsReact';
9
10
  import invokeAppCall from '../util/appCall';
10
11
  import getDeviceInfo, { getScreenSize } from '../util/deviceHelper';
11
12
  import getUserInfo from '../calls/getUserInfo';
12
13
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
13
14
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
15
+ let appWrapperDialogId = 0;
14
16
  export class AppWrapper {
15
17
  mapOldApiToNew(retVal) {
16
18
  var _window, _window2, _AppInfo$TappSelected;
@@ -430,12 +432,46 @@ export class AppWrapper {
430
432
  void this.appCall(19, value, {
431
433
  awaitResult: false
432
434
  });
435
+ },
436
+ createDialog: config => {
437
+ return new DialogHandler(config, this.functions.openDialog, this.functions.closeDialog);
438
+ },
439
+ openDialog: async (config, callback) => {
440
+ const currentDialogId = appWrapperDialogId++;
441
+ const eventTarget = new EventTarget();
442
+ const resolve = result => {
443
+ callback(result);
444
+ this.dispatchDialogChange(this.dialogs.filter(x => x.dialogId !== currentDialogId));
445
+ };
446
+ this.dispatchDialogChange([...this.dialogs, {
447
+ config,
448
+ resolve,
449
+ dialogId: currentDialogId,
450
+ eventTarget
451
+ }]);
452
+ return currentDialogId;
453
+ },
454
+ closeDialog: dialogId => {
455
+ const dialog = this.dialogs.find(x => x.dialogId === dialogId);
456
+ if (dialog) {
457
+ dialog.resolve({
458
+ buttonType: -1
459
+ });
460
+ }
433
461
  }
434
462
  });
463
+ _defineProperty(this, "dialogs", []);
464
+ _defineProperty(this, "dialogEventTarget", new EventTarget());
435
465
  }
436
466
  notImplemented(call) {
437
467
  console.warn(`call ${call} not implement in app`);
438
468
  }
469
+ dispatchDialogChange(detail) {
470
+ this.dialogs = detail;
471
+ this.dialogEventTarget.dispatchEvent(new CustomEvent('change', {
472
+ detail
473
+ }));
474
+ }
439
475
  appCall(action) {
440
476
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
441
477
  let {
@@ -468,6 +504,9 @@ export class AppWrapper {
468
504
  });
469
505
  });
470
506
  }
507
+ getDialogEventTarget() {
508
+ return this.dialogEventTarget;
509
+ }
471
510
  async init() {
472
511
  this.values = this.mapOldApiToNew(await this.appCall(18));
473
512
  return undefined;
@@ -3,6 +3,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
3
3
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
4
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
5
5
  import * as comlink from 'comlink';
6
+ import DialogHandler from '../handler/DialogHandler';
6
7
  import { addVisibilityChangeListener, removeVisibilityChangeListener } from '../calls/visibilityChangeListener';
7
8
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
8
9
  import getUserInfo from '../calls/getUserInfo';
@@ -227,7 +228,57 @@ export class FrameWrapper {
227
228
  scrollByY: async (value, duration) => {
228
229
  if (!this.initialized) await this.ready;
229
230
  return this.exposedFunctions.scrollByY(value, duration);
230
- }
231
+ },
232
+ createDialog: config => {
233
+ return new DialogHandler(config, this.functions.openDialog, this.exposedFunctions.closeDialog, this.functions.dispatchEventToDialogClient, this.functions.addDialogClientEventListener);
234
+ },
235
+ closeDialog: async dialogId => {
236
+ if (!this.initialized) await this.ready;
237
+ return this.exposedFunctions.closeDialog(dialogId);
238
+ },
239
+ openDialog: async (config, callback) => {
240
+ if (!this.initialized) await this.ready;
241
+ return this.exposedFunctions.openDialog(config, comlink.proxy(callback));
242
+ },
243
+ setDialogResult: async (buttonType, result) => {
244
+ if (!this.initialized) await this.ready;
245
+ return this.exposedFunctions.setDialogResult(buttonType, result);
246
+ },
247
+ dispatchEventToDialogClient: async (dialogId, data) => {
248
+ if (!this.initialized) await this.ready;
249
+ return this.exposedFunctions.dispatchEventToDialogClient(dialogId, data);
250
+ },
251
+ addDialogClientEventListener: async (dialogId, callback) => {
252
+ if (!this.initialized) await this.ready;
253
+ return this.exposedFunctions.addDialogClientEventListener(dialogId, comlink.proxy(callback));
254
+ },
255
+ dispatchEventToDialogHost: async data => {
256
+ if (!this.initialized) await this.ready;
257
+ return this.exposedFunctions.dispatchEventToDialogHost(data);
258
+ },
259
+ addDialogHostEventListener: async callback => {
260
+ if (!this.initialized) await this.ready;
261
+ const listenerKey = `dialogHostEventListener`;
262
+ const {
263
+ id,
264
+ shouldInitialize
265
+ } = addApiListener(listenerKey, callback);
266
+ if (shouldInitialize) {
267
+ this.exposedFunctions.addDialogHostEventListener(comlink.proxy(data => {
268
+ dispatchApiEvent(listenerKey, data);
269
+ }));
270
+ }
271
+ return id;
272
+ },
273
+ removeDialogHostEventListener: async id => {
274
+ if (!this.initialized) await this.ready;
275
+ const listenerKey = `dialogHostEventListener`;
276
+ const shouldRemove = removeApiListener(listenerKey, id);
277
+ if (shouldRemove) {
278
+ // this.exposedFunctions.removeDialogHostEventListener(0);
279
+ }
280
+ },
281
+ removeDialogClientEventListener: async () => {}
231
282
  });
232
283
  _defineProperty(this, "initialized", false);
233
284
  const initialDataTag = document.querySelector('#__CHAYNS_DATA__');
@@ -1,3 +1,4 @@
1
+ import DialogHandler from '../handler/DialogHandler';
1
2
  import { addVisibilityChangeListener, removeVisibilityChangeListener } from '../calls/visibilityChangeListener';
2
3
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
3
4
  import getUserInfo from '../calls/getUserInfo';
@@ -20,6 +21,9 @@ export class ModuleFederationWrapper {
20
21
  return fn(...arguments);
21
22
  };
22
23
  });
24
+ this.functions.createDialog = config => {
25
+ return new DialogHandler(config, functions.openDialog, functions.closeDialog, functions.dispatchEventToDialogClient, functions.addDialogClientEventListener);
26
+ };
23
27
  this.functions.addWindowMetricsListener = async callback => {
24
28
  const {
25
29
  id,
@@ -1,10 +1,10 @@
1
- import { DialogButton } from "../../types/dialog";
1
+ import { DialogButtonOld } from "../../types/dialog";
2
2
  type Confirm = {
3
3
  headline?: string;
4
4
  text?: string;
5
- buttons?: DialogButton[] | {
6
- buttons?: DialogButton[];
7
- links?: DialogButton[];
5
+ buttons?: DialogButtonOld[] | {
6
+ buttons?: DialogButtonOld[];
7
+ links?: DialogButtonOld[];
8
8
  };
9
9
  links?: unknown;
10
10
  select?: unknown;
@@ -1,4 +1,4 @@
1
- import { DialogButton, DialogTextBlock, IntervalItem, WeekDayIntervalObject } from "../../types/dialog";
1
+ import { DialogButtonOld, DialogTextBlock, IntervalItem, WeekDayIntervalObject } from "../../types/dialog";
2
2
  /**
3
3
  * The config object for date dialog
4
4
  * @typedef {Object} dateConfig
@@ -28,7 +28,7 @@ import { DialogButton, DialogTextBlock, IntervalItem, WeekDayIntervalObject } fr
28
28
  type DateConfig = {
29
29
  title?: string;
30
30
  message?: string;
31
- buttons?: DialogButton[];
31
+ buttons?: DialogButtonOld[];
32
32
  minDate?: Date | number;
33
33
  maxDate?: Date | number;
34
34
  minuteInterval?: number;
@@ -56,7 +56,7 @@ type preSelect = preSelectObj | Date | undefined | number | number[];
56
56
  type AdvancedDateConfig = {
57
57
  title?: string;
58
58
  message?: string;
59
- buttons?: DialogButton[];
59
+ buttons?: DialogButtonOld[];
60
60
  minDate?: Date | number;
61
61
  maxDate?: Date | number;
62
62
  minuteInterval?: number;
@@ -1,4 +1,4 @@
1
- import { DialogButton } from "../../types/dialog";
1
+ import { DialogButtonOld } from "../../types/dialog";
2
2
  export declare const fileType: {
3
3
  IMAGE: string;
4
4
  VIDEO: string;
@@ -6,7 +6,7 @@ export declare const fileType: {
6
6
  DOCUMENT: string[];
7
7
  };
8
8
  type FileSelectInput = {
9
- buttons?: DialogButton[];
9
+ buttons?: DialogButtonOld[];
10
10
  callType?: number;
11
11
  multiselect?: boolean;
12
12
  directory?: boolean;
@@ -1,6 +1,6 @@
1
- import { DialogButton } from "../../types/dialog";
1
+ import { DialogButtonOld } from "../../types/dialog";
2
2
  type iFrameDialog = {
3
- buttons?: DialogButton[];
3
+ buttons?: DialogButtonOld[];
4
4
  callType?: number;
5
5
  tappIframeName?: string;
6
6
  url: string;
@@ -1,6 +1,6 @@
1
- import { DialogButton } from "../../types/dialog";
1
+ import { DialogButtonOld } from "../../types/dialog";
2
2
  type InputDialog = {
3
- buttons?: DialogButton[];
3
+ buttons?: DialogButtonOld[];
4
4
  callType?: number;
5
5
  formatter?: string;
6
6
  };
@@ -1,6 +1,6 @@
1
- import { DialogButton } from "../../types/dialog";
1
+ import { DialogButtonOld } from "../../types/dialog";
2
2
  type MediaSelectInput = {
3
- buttons?: DialogButton[];
3
+ buttons?: DialogButtonOld[];
4
4
  callType?: number;
5
5
  chaynsToken?: string;
6
6
  };
@@ -1,6 +1,6 @@
1
- import { DialogButton } from "../../types/dialog";
1
+ import { DialogButtonOld } from "../../types/dialog";
2
2
  type SignatureInput = {
3
- buttons?: DialogButton[];
3
+ buttons?: DialogButtonOld[];
4
4
  callType?: number;
5
5
  };
6
6
  export declare function signature(dialog?: SignatureInput): Promise<unknown>;
@@ -183,6 +183,10 @@ export declare const storageSetItem: ChaynsReactFunctions["storageSetItem"];
183
183
  * This method lets a smartphone vibrate for the given time.
184
184
  */
185
185
  export declare const vibrate: (value: import("../types/IChaynsReact").Vibrate) => Promise<void>;
186
+ /**
187
+ * This method creates a dialog
188
+ */
189
+ export declare const createDialog: (config: import("../types/IChaynsReact").Dialog) => import("../handler/DialogHandler").default;
186
190
  /**
187
191
  * Displays an overlay
188
192
  */
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare const AppDialogWrapper: ({ dialogEventTarget }: {
3
+ dialogEventTarget: any;
4
+ }) => JSX.Element;
5
+ export default AppDialogWrapper;
@@ -1,8 +1,7 @@
1
1
  import { FC, ReactNode } from "react";
2
- type TaskList = (TaskList | Promise<unknown> | (() => Promise<unknown>))[];
2
+ export type TaskList = (TaskList | Promise<unknown> | (() => Promise<unknown>))[];
3
3
  export declare const WaitUntil: FC<{
4
4
  tasks: TaskList;
5
5
  children?: ReactNode;
6
6
  loadingComponent?: ReactNode;
7
7
  }>;
8
- export {};
@@ -0,0 +1,19 @@
1
+ export default class DialogHandler {
2
+ private dialogId;
3
+ private isOpen;
4
+ private result;
5
+ private readonly _open;
6
+ private readonly _close;
7
+ private readonly _config;
8
+ private readonly _dispatchEvent;
9
+ private readonly _addDataListener;
10
+ private readonly _removeDataListener;
11
+ private readonly listeners;
12
+ constructor(config: any, open: any, close: any, dispatchEvent: any, addDataListener: any);
13
+ open(): Promise<unknown>;
14
+ close(buttonType: any, data: any): void;
15
+ dispatchEvent(data: object): void;
16
+ addDataListener(listener: (data: any) => void): void;
17
+ removeDataListener(listener: (data: any) => void): void;
18
+ getResult(): any;
19
+ }
@@ -14,3 +14,4 @@ export { useValues } from './useValues';
14
14
  export { useFunctions } from './useFunctions';
15
15
  export { useCurrentPage } from './useCurrentPage';
16
16
  export { useCustomData } from './useCustomData';
17
+ export { useDialogState, useDialogData } from './useDialogState';
@@ -0,0 +1,9 @@
1
+ import { DialogDataHookResult, DialogHookResult } from '../types/IChaynsReact';
2
+ /**
3
+ * @category Hooks
4
+ */
5
+ export declare const useDialogState: () => DialogHookResult;
6
+ /**
7
+ * @category Hooks
8
+ */
9
+ export declare const useDialogData: () => DialogDataHookResult;
@@ -3,16 +3,16 @@ import { TypeSystem } from './module/ModuleHost';
3
3
  import { ChaynsApiDevice, ChaynsApiSite, ChaynsApiUser, ChaynsReactFunctions, ChaynsReactValues, Page } from '../types/IChaynsReact';
4
4
  type ChaynsHostType = {
5
5
  type: string;
6
- iFrameProps: {
6
+ iFrameProps?: {
7
7
  [key: string]: unknown;
8
8
  name: string;
9
9
  };
10
10
  functions: ChaynsReactFunctions;
11
- src: string;
12
- iFrameRef: React.MutableRefObject<HTMLIFrameElement | null> | undefined;
11
+ src?: string;
12
+ iFrameRef?: React.MutableRefObject<HTMLIFrameElement | null> | undefined;
13
13
  loadingComponent?: JSX.Element;
14
14
  children?: JSX.Element;
15
- system: TypeSystem;
15
+ system?: TypeSystem;
16
16
  pages: Page[];
17
17
  isAdminModeActive: boolean;
18
18
  site: ChaynsApiSite;
@@ -24,6 +24,7 @@ type ChaynsHostType = {
24
24
  customData: any;
25
25
  environment: ChaynsReactValues["environment"];
26
26
  preventStagingReplacement?: boolean;
27
+ dialog: ChaynsReactValues["dialog"];
27
28
  };
28
29
  declare const ChaynsHost: FC<ChaynsHostType>;
29
30
  export default ChaynsHost;
@@ -20,6 +20,7 @@ type HostIframeProps = {
20
20
  environment: ChaynsReactValues["environment"];
21
21
  customData: ChaynsReactValues["customData"];
22
22
  preventStagingReplacement?: boolean;
23
+ dialog: ChaynsReactValues["dialog"];
23
24
  };
24
25
  declare const HostIframe: FC<HostIframeProps>;
25
26
  export default HostIframe;
@@ -19,6 +19,7 @@ type ModulePropTypes = {
19
19
  customData: any;
20
20
  environment: ChaynsReactValues["environment"];
21
21
  preventStagingReplacement?: boolean;
22
+ dialog: ChaynsReactValues["dialog"];
22
23
  children?: ReactNode;
23
24
  };
24
25
  declare const ModuleHost: FC<ModulePropTypes>;
@@ -1,5 +1,50 @@
1
1
  import { Browser, OperatingSystem } from 'detect-browser';
2
- import { DialogButton, SelectDialogItem } from "./dialog";
2
+ import DialogHandler from '../handler/DialogHandler';
3
+ import { DialogButtonOld, SelectDialogItem } from './dialog';
4
+ export type DialogButton = {
5
+ type: DialogButtonType;
6
+ text: string;
7
+ };
8
+ export type BaseDialog = {
9
+ text?: string;
10
+ buttons?: DialogButton[];
11
+ dialogId: number;
12
+ };
13
+ export type Dialog = BaseDialog & (DialogInput | DialogModule | DialogIFrame | DialogSelect);
14
+ export type DialogModule = {
15
+ type: DialogType.MODULE;
16
+ system: {
17
+ url: string;
18
+ module: string;
19
+ scope: string;
20
+ };
21
+ dialogInput: object;
22
+ isClosingRequested: boolean;
23
+ };
24
+ export type DialogIFrame = {
25
+ type: DialogType.IFRAME;
26
+ url: string;
27
+ dialogInput: object;
28
+ isClosingRequested: boolean;
29
+ };
30
+ export type DialogInput = {
31
+ type: DialogType.INPUT;
32
+ placeholder: string;
33
+ };
34
+ export type DialogSelect = {
35
+ type: DialogType.SELECT;
36
+ list: {
37
+ id: number;
38
+ name: string;
39
+ disabled?: boolean;
40
+ isSelected?: boolean;
41
+ }[];
42
+ };
43
+ export declare enum DialogButtonType {
44
+ OK = 1,
45
+ CANCEL = -1,
46
+ NEGATIVE = 0
47
+ }
3
48
  export type ChaynsApiUser = {
4
49
  firstName?: string;
5
50
  lastName?: string;
@@ -52,6 +97,17 @@ export type ChaynsApiDevice = {
52
97
  isTouch: boolean;
53
98
  screenSize: ScreenSize;
54
99
  };
100
+ export type DialogHookResult = {
101
+ isClosingRequested: boolean;
102
+ setResult: ChaynsReactFunctions["setDialogResult"];
103
+ sendData: ChaynsReactFunctions["dispatchEventToDialogHost"];
104
+ addDataListener: ChaynsReactFunctions["addDialogHostEventListener"];
105
+ };
106
+ export type DialogDataHookResult = {
107
+ inputData: {
108
+ [key: string | symbol]: object;
109
+ };
110
+ };
55
111
  /**
56
112
  * @ignore
57
113
  */
@@ -82,6 +138,10 @@ export interface ChaynsReactValues {
82
138
  runtimeEnvironment: RuntimeEnviroment | string;
83
139
  };
84
140
  customData: any;
141
+ dialog: {
142
+ dialogInput: any;
143
+ isClosingRequested: boolean;
144
+ };
85
145
  }
86
146
  /**
87
147
  * @ignore
@@ -139,7 +199,21 @@ export interface ChaynsReactFunctions {
139
199
  vibrate: (value: Vibrate) => Promise<void>;
140
200
  scrollByY: (position: number, duration?: number) => Promise<void>;
141
201
  setOverlay: (value: ShowOverlay, callback: () => void) => Promise<void>;
142
- }
202
+ createDialog: (config: Dialog) => DialogHandler;
203
+ openDialog: (value: any, callback: (data: any) => any) => Promise<any>;
204
+ closeDialog: (dialogId: number) => Promise<void>;
205
+ setDialogResult: (buttonType: DialogButtonType, result: any) => Promise<void>;
206
+ dispatchEventToDialogClient: (dialogId: number, data: object) => Promise<void>;
207
+ addDialogClientEventListener: (dialogId: number, callback: (data: object) => void) => Promise<number>;
208
+ removeDialogClientEventListener: (dialogId: number, id: number) => Promise<void>;
209
+ dispatchEventToDialogHost: (data: object) => Promise<void>;
210
+ addDialogHostEventListener: (callback: (data: object) => void) => Promise<number>;
211
+ removeDialogHostEventListener: (id: number) => Promise<void>;
212
+ }
213
+ export type DialogResult = {
214
+ open: () => Promise<any>;
215
+ close: (buttonType: DialogButtonType, data: any) => Promise<void>;
216
+ };
143
217
  export type SelectPage = {
144
218
  id?: number;
145
219
  position?: number;
@@ -456,7 +530,7 @@ export type DataChangeValue = {
456
530
  value: ChaynsApiSite;
457
531
  } | {
458
532
  type: 'isAdminModeActive';
459
- value: ChaynsReactValues["isAdminModeActive"];
533
+ value: ChaynsReactValues['isAdminModeActive'];
460
534
  };
461
535
  export type DataChangeCallback = ((value: DataChangeValue) => void);
462
536
  export type CleanupCallback = (() => void);
@@ -613,12 +687,23 @@ export interface SelectInput {
613
687
  quickfind?: boolean;
614
688
  type?: selectType;
615
689
  preventCloseOnClick?: boolean;
616
- buttons?: DialogButton[];
617
- links?: DialogButton[];
690
+ buttons?: DialogButtonOld[];
691
+ links?: DialogButtonOld[];
618
692
  selectAllButton?: string;
619
693
  }
620
694
  declare enum selectType {
621
695
  DEFAULT = 0,
622
696
  ICON = 1
623
697
  }
698
+ export declare enum DialogType {
699
+ ALERT = "alert",
700
+ CONFIRM = "confirm",
701
+ DATE = "date",
702
+ FILE_SELECT = "fileSelect",
703
+ IFRAME = "iframe",
704
+ MODULE = "module",
705
+ INPUT = "input",
706
+ SELECT = "select",
707
+ TOAST = "toast"
708
+ }
624
709
  export {};
@@ -20,7 +20,7 @@ export interface SelectDialogItem {
20
20
  isSelected?: boolean;
21
21
  icon?: string;
22
22
  }
23
- export interface DialogButton {
23
+ export interface DialogButtonOld {
24
24
  text: buttonText | string;
25
25
  buttonType: buttonType | number;
26
26
  collapseTime?: number;