chayns-api 2.0.7 → 2.0.9-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.
Files changed (164) hide show
  1. package/.babelrc +30 -30
  2. package/.eslintrc +17 -17
  3. package/.github/workflows/deploy_docs.yml +28 -28
  4. package/.github/workflows/publish.yml +21 -21
  5. package/LICENSE +21 -21
  6. package/README.md +67 -67
  7. package/dist/cjs/calls/dialogs/date.js +34 -34
  8. package/dist/cjs/calls/index.js +108 -108
  9. package/dist/cjs/calls/sendMessage.js +8 -8
  10. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  11. package/dist/cjs/components/AppDialogWrapper.js +2 -2
  12. package/dist/cjs/components/ChaynsContext.js +3 -5
  13. package/dist/cjs/components/ChaynsProvider.js +11 -21
  14. package/dist/cjs/components/ErrorBoundary.js +1 -1
  15. package/dist/cjs/components/withCompatMode.js +3 -3
  16. package/dist/cjs/components/withHydrationBoundary.js +1 -1
  17. package/dist/cjs/hooks/context.js +24 -0
  18. package/dist/cjs/hooks/geoLocationListener.js +7 -8
  19. package/dist/cjs/hooks/scrollListener.js +12 -13
  20. package/dist/cjs/hooks/useAccessToken.js +5 -6
  21. package/dist/cjs/hooks/useCurrentPage.js +4 -5
  22. package/dist/cjs/hooks/useCustomCallbackFunction.js +5 -10
  23. package/dist/cjs/hooks/useCustomData.js +4 -5
  24. package/dist/cjs/hooks/useDevice.js +4 -5
  25. package/dist/cjs/hooks/useDialogState.js +13 -15
  26. package/dist/cjs/hooks/useEnvironment.js +4 -5
  27. package/dist/cjs/hooks/useFunctions.js +4 -8
  28. package/dist/cjs/hooks/useIsAdminMode.js +7 -8
  29. package/dist/cjs/hooks/useLanguage.js +4 -5
  30. package/dist/cjs/hooks/usePages.js +7 -8
  31. package/dist/cjs/hooks/useParameters.js +4 -5
  32. package/dist/cjs/hooks/useSite.js +4 -5
  33. package/dist/cjs/hooks/useUser.js +7 -5
  34. package/dist/cjs/hooks/useValues.js +4 -8
  35. package/dist/cjs/hooks/windowMetricsListener.js +8 -9
  36. package/dist/cjs/host/ChaynsHost.js +1 -1
  37. package/dist/cjs/host/iframe/HostIframe.js +2 -2
  38. package/dist/cjs/host/module/ModuleHost.js +1 -1
  39. package/dist/cjs/host/module/utils/loadComponent.js +1 -1
  40. package/dist/cjs/index.js +1 -1
  41. package/dist/cjs/types/IChaynsReact.js +4 -4
  42. package/dist/cjs/util/heightHelper.js +1 -1
  43. package/dist/cjs/util/initModuleFederationSharing.js +1 -1
  44. package/dist/cjs/wrapper/AppWrapper.js +11 -1
  45. package/dist/cjs/wrapper/FrameWrapper.js +11 -1
  46. package/dist/cjs/wrapper/ModuleFederationWrapper.js +11 -1
  47. package/dist/cjs/wrapper/SsrWrapper.js +10 -0
  48. package/dist/cjs/wrapper/StaticChaynsApi.js +1 -1
  49. package/dist/esm/calls/dialogs/date.js +34 -34
  50. package/dist/esm/calls/index.js +108 -108
  51. package/dist/esm/calls/sendMessage.js +8 -8
  52. package/dist/esm/calls/visibilityChangeListener.js +4 -4
  53. package/dist/esm/components/AppDialogWrapper.js +1 -1
  54. package/dist/esm/components/ChaynsContext.js +2 -4
  55. package/dist/esm/components/ChaynsProvider.js +11 -21
  56. package/dist/esm/components/withCompatMode.js +2 -2
  57. package/dist/esm/components/withHydrationBoundary.js +1 -1
  58. package/dist/esm/handler/DialogHandler.js +1 -1
  59. package/dist/esm/hooks/context.js +16 -0
  60. package/dist/esm/hooks/geoLocationListener.js +7 -8
  61. package/dist/esm/hooks/scrollListener.js +12 -13
  62. package/dist/esm/hooks/useAccessToken.js +6 -7
  63. package/dist/esm/hooks/useCurrentPage.js +4 -5
  64. package/dist/esm/hooks/useCustomCallbackFunction.js +5 -10
  65. package/dist/esm/hooks/useCustomData.js +4 -5
  66. package/dist/esm/hooks/useDevice.js +4 -5
  67. package/dist/esm/hooks/useDialogState.js +13 -15
  68. package/dist/esm/hooks/useEnvironment.js +4 -5
  69. package/dist/esm/hooks/useFunctions.js +5 -8
  70. package/dist/esm/hooks/useIsAdminMode.js +7 -8
  71. package/dist/esm/hooks/useLanguage.js +4 -5
  72. package/dist/esm/hooks/usePages.js +7 -8
  73. package/dist/esm/hooks/useParameters.js +4 -5
  74. package/dist/esm/hooks/useSite.js +4 -5
  75. package/dist/esm/hooks/useUser.js +7 -5
  76. package/dist/esm/hooks/useValues.js +5 -8
  77. package/dist/esm/hooks/windowMetricsListener.js +8 -9
  78. package/dist/esm/host/iframe/HostIframe.js +1 -1
  79. package/dist/esm/types/IChaynsReact.js +4 -4
  80. package/dist/esm/wrapper/AppWrapper.js +11 -1
  81. package/dist/esm/wrapper/FrameWrapper.js +11 -1
  82. package/dist/esm/wrapper/ModuleFederationWrapper.js +13 -0
  83. package/dist/esm/wrapper/SsrWrapper.js +13 -0
  84. package/dist/esm/wrapper/StaticChaynsApi.js +1 -1
  85. package/dist/types/calls/dialogs/alert.d.ts +1 -1
  86. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
  87. package/dist/types/calls/dialogs/close.d.ts +1 -1
  88. package/dist/types/calls/dialogs/communication.d.ts +3 -3
  89. package/dist/types/calls/dialogs/confirm.d.ts +13 -13
  90. package/dist/types/calls/dialogs/date.d.ts +96 -96
  91. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
  92. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
  93. package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
  94. package/dist/types/calls/dialogs/index.d.ts +14 -14
  95. package/dist/types/calls/dialogs/input.d.ts +15 -15
  96. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
  97. package/dist/types/calls/dialogs/open.d.ts +1 -1
  98. package/dist/types/calls/dialogs/select.d.ts +6 -6
  99. package/dist/types/calls/dialogs/signature.d.ts +7 -7
  100. package/dist/types/calls/dialogs/toast.d.ts +1 -1
  101. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
  102. package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
  103. package/dist/types/calls/getUserInfo.d.ts +9 -9
  104. package/dist/types/calls/index.d.ts +255 -255
  105. package/dist/types/calls/sendMessage.d.ts +13 -13
  106. package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
  107. package/dist/types/components/AppDialogWrapper.d.ts +5 -5
  108. package/dist/types/components/ChaynsContext.d.ts +3 -3
  109. package/dist/types/components/ChaynsProvider.d.ts +11 -11
  110. package/dist/types/components/ErrorBoundary.d.ts +13 -13
  111. package/dist/types/components/WaitUntil.d.ts +7 -7
  112. package/dist/types/components/moduleWrapper.d.ts +4 -4
  113. package/dist/types/components/withCompatMode.d.ts +14 -14
  114. package/dist/types/components/withHydrationBoundary.d.ts +24 -24
  115. package/dist/types/constants/hydrationContext.d.ts +6 -6
  116. package/dist/types/constants/index.d.ts +1 -1
  117. package/dist/types/constants/languages.d.ts +12 -12
  118. package/dist/types/handler/DialogHandler.d.ts +24 -24
  119. package/dist/types/helper/apiListenerHelper.d.ts +6 -6
  120. package/dist/types/hooks/context.d.ts +3 -0
  121. package/dist/types/hooks/geoLocationListener.d.ts +18 -18
  122. package/dist/types/hooks/index.d.ts +18 -18
  123. package/dist/types/hooks/scrollListener.d.ts +28 -28
  124. package/dist/types/hooks/useAccessToken.d.ts +6 -6
  125. package/dist/types/hooks/useCurrentPage.d.ts +7 -7
  126. package/dist/types/hooks/useCustomCallbackFunction.d.ts +5 -5
  127. package/dist/types/hooks/useCustomData.d.ts +4 -4
  128. package/dist/types/hooks/useDevice.d.ts +5 -5
  129. package/dist/types/hooks/useDialogState.d.ts +9 -9
  130. package/dist/types/hooks/useEnvironment.d.ts +5 -5
  131. package/dist/types/hooks/useFunctions.d.ts +4 -5
  132. package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
  133. package/dist/types/hooks/useLanguage.d.ts +5 -5
  134. package/dist/types/hooks/usePages.d.ts +18 -18
  135. package/dist/types/hooks/useParameters.d.ts +5 -5
  136. package/dist/types/hooks/useSite.d.ts +5 -5
  137. package/dist/types/hooks/useUser.d.ts +4 -5
  138. package/dist/types/hooks/useValues.d.ts +4 -5
  139. package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
  140. package/dist/types/host/ChaynsHost.d.ts +29 -29
  141. package/dist/types/host/iframe/HostIframe.d.ts +26 -26
  142. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
  143. package/dist/types/host/module/ModuleHost.d.ts +28 -28
  144. package/dist/types/host/module/utils/loadComponent.d.ts +3 -3
  145. package/dist/types/index.d.ts +20 -20
  146. package/dist/types/types/IChaynsReact.d.ts +899 -897
  147. package/dist/types/types/dialog.d.ts +41 -41
  148. package/dist/types/util/appCall.d.ts +2 -2
  149. package/dist/types/util/bindChaynsApi.d.ts +1 -1
  150. package/dist/types/util/deviceHelper.d.ts +9 -9
  151. package/dist/types/util/heightHelper.d.ts +1 -1
  152. package/dist/types/util/initModuleFederationSharing.d.ts +3 -3
  153. package/dist/types/util/is.d.ts +5 -5
  154. package/dist/types/util/postIframeForm.d.ts +1 -1
  155. package/dist/types/util/transferNestedFunctions.d.ts +1 -1
  156. package/dist/types/util/url.d.ts +1 -1
  157. package/dist/types/wrapper/AppWrapper.d.ts +22 -19
  158. package/dist/types/wrapper/FrameWrapper.d.ts +18 -15
  159. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +13 -10
  160. package/dist/types/wrapper/SsrWrapper.d.ts +14 -11
  161. package/dist/types/wrapper/StaticChaynsApi.d.ts +16 -16
  162. package/package.json +87 -88
  163. package/toolkit.config.js +20 -20
  164. package/tsconfig.json +56 -56
@@ -6,7 +6,7 @@ import { AppWrapper } from '../wrapper/AppWrapper';
6
6
  import { FrameWrapper } from '../wrapper/FrameWrapper';
7
7
  import { ModuleFederationWrapper } from '../wrapper/ModuleFederationWrapper';
8
8
  import { SsrWrapper } from '../wrapper/SsrWrapper';
9
- import { ChaynsContext, ChaynsFunctionsContext } from './ChaynsContext';
9
+ import { ChaynsContext } from './ChaynsContext';
10
10
  import { moduleWrapper } from './moduleWrapper';
11
11
 
12
12
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -29,7 +29,7 @@ const InitialDataProvider = /*#__PURE__*/React.memo(_ref => {
29
29
  });
30
30
  }, () => true);
31
31
  const ChaynsProvider = _ref2 => {
32
- var _customWrapper$curren, _customWrapper$curren2, _customWrapper$curren3;
32
+ var _customWrapper$curren, _customWrapper$curren2;
33
33
  let {
34
34
  children,
35
35
  data,
@@ -64,7 +64,7 @@ const ChaynsProvider = _ref2 => {
64
64
  }
65
65
  moduleWrapper.current = customWrapper.current;
66
66
  }
67
- const [state, setState] = useState((_customWrapper$curren = (_customWrapper$curren2 = customWrapper.current) === null || _customWrapper$curren2 === void 0 ? void 0 : _customWrapper$curren2.values) !== null && _customWrapper$curren !== void 0 ? _customWrapper$curren : undefined);
67
+ const [isInitialized, setIsInitialized] = useState(!!((_customWrapper$curren = customWrapper.current) !== null && _customWrapper$curren !== void 0 && _customWrapper$curren.values));
68
68
  useEffect(() => {
69
69
  void (async () => {
70
70
  await customWrapper.current.init();
@@ -73,35 +73,25 @@ const ChaynsProvider = _ref2 => {
73
73
  type,
74
74
  value
75
75
  } = _ref3;
76
- setState(oldState => {
77
- if (oldState) return {
78
- ...oldState,
79
- [type]: value
80
- };
81
- return undefined;
82
- });
76
+ customWrapper.current.emitChange();
83
77
  });
84
- if (customWrapper.current.values && !isModule) {
85
- setState({
86
- ...customWrapper.current.values
87
- });
78
+ if (!isInitialized) {
79
+ setIsInitialized(true);
88
80
  }
89
81
  })();
90
82
  }, []);
91
83
  useEffect(() => {
92
84
  if (isModule) {
93
- setState(data);
94
85
  if (data) {
95
86
  customWrapper.current.values = data;
87
+ customWrapper.current.emitChange();
96
88
  }
97
89
  }
98
90
  }, [data, isModule]);
99
- return /*#__PURE__*/React.createElement(React.Fragment, null, !!state && /*#__PURE__*/React.createElement(ChaynsContext.Provider, {
100
- value: state
101
- }, /*#__PURE__*/React.createElement(ChaynsFunctionsContext.Provider, {
102
- value: (_customWrapper$curren3 = customWrapper.current) === null || _customWrapper$curren3 === void 0 ? void 0 : _customWrapper$curren3.functions
103
- }, children)), /*#__PURE__*/React.createElement(InitialDataProvider, {
104
- data: state,
91
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isInitialized && /*#__PURE__*/React.createElement(ChaynsContext.Provider, {
92
+ value: customWrapper.current
93
+ }, children), /*#__PURE__*/React.createElement(InitialDataProvider, {
94
+ data: (_customWrapper$curren2 = customWrapper.current) === null || _customWrapper$curren2 === void 0 ? void 0 : _customWrapper$curren2.values,
105
95
  renderedByServer: renderedByServer
106
96
  }));
107
97
  };
@@ -1,4 +1,4 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  /* eslint-disable react/jsx-props-no-spreading */
3
3
 
4
4
  import React, { PureComponent } from 'react';
@@ -51,7 +51,7 @@ export const withCompatMode = Component => {
51
51
  if (this.root) {
52
52
  this.root.unmount();
53
53
  } else {
54
- ReactDOM.render(/*#__PURE__*/React.createElement(React.Fragment, null), this.ref.current);
54
+ ReactDOM.render( /*#__PURE__*/React.createElement(React.Fragment, null), this.ref.current);
55
55
  }
56
56
  }
57
57
  render() {
@@ -1,4 +1,4 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import React, { useContext, useEffect, useState } from 'react';
3
3
  import { HydrationContext } from '../constants';
4
4
  function withHydrationBoundary(Component, initializer, useHydrationId, useProps) {
@@ -1,4 +1,4 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  export default class DialogHandler {
@@ -0,0 +1,16 @@
1
+ import { useContext, useSyncExternalStore } from 'react';
2
+ import { ChaynsContext } from '../components/ChaynsContext';
3
+ export const useValuesSelector = selector => {
4
+ const store = useContext(ChaynsContext);
5
+ if (!store) {
6
+ throw new Error('Could not find chayns context. Did you forget to add ChaynsProvider?');
7
+ }
8
+ return useSyncExternalStore(store.subscribe, () => selector(store.values));
9
+ };
10
+ export const useFunctionsSelector = selector => {
11
+ const store = useContext(ChaynsContext);
12
+ if (!store) {
13
+ throw new Error('Could not find chayns context. Did you forget to add ChaynsProvider?');
14
+ }
15
+ return useSyncExternalStore(store.subscribe, () => selector(store.functions));
16
+ };
@@ -1,12 +1,11 @@
1
- import { useContextSelector } from 'use-context-selector';
2
1
  import { useCallback, useEffect, useRef, useState } from 'react';
3
- import { ChaynsFunctionsContext } from '../components/ChaynsContext';
4
- /**
5
- * @category Hooks
2
+ import { useFunctionsSelector } from './context';
3
+ /**
4
+ * @category Hooks
6
5
  */
7
6
  export const useGeoLocationListener = () => {
8
- const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addGeoLocationListener);
9
- const removeListener = useContextSelector(ChaynsFunctionsContext, v => v.removeGeoLocationListener);
7
+ const addListener = useFunctionsSelector(f => f.addGeoLocationListener);
8
+ const removeListener = useFunctionsSelector(f => f.removeGeoLocationListener);
10
9
  const promiseRef = useRef();
11
10
  return useCallback((value, callback) => {
12
11
  promiseRef.current = addListener(value, callback);
@@ -17,8 +16,8 @@ export const useGeoLocationListener = () => {
17
16
  // eslint-disable-next-line react-hooks/exhaustive-deps
18
17
  }, []);
19
18
  };
20
- /**
21
- * @category Hooks
19
+ /**
20
+ * @category Hooks
22
21
  */
23
22
  export const useGeoLocation = function () {
24
23
  let {
@@ -1,13 +1,12 @@
1
- import { useContextSelector } from 'use-context-selector';
2
1
  import { useCallback, useEffect, useRef, useState } from 'react';
3
- import { ChaynsFunctionsContext } from '../components/ChaynsContext';
4
2
  import { useWindowMetrics } from './windowMetricsListener';
5
- /**
6
- * @category Hooks
3
+ import { useFunctionsSelector } from './context';
4
+ /**
5
+ * @category Hooks
7
6
  */
8
7
  export const useScrollListener = () => {
9
- const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addScrollListener);
10
- const removeListener = useContextSelector(ChaynsFunctionsContext, v => v.removeScrollListener);
8
+ const addListener = useFunctionsSelector(f => f.addScrollListener);
9
+ const removeListener = useFunctionsSelector(f => f.removeScrollListener);
11
10
  const promiseRef = useRef();
12
11
  return useCallback((value, callback) => {
13
12
  promiseRef.current = addListener(value, callback);
@@ -18,8 +17,8 @@ export const useScrollListener = () => {
18
17
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
18
  }, []);
20
19
  };
21
- /**
22
- * @category Hooks
20
+ /**
21
+ * @category Hooks
23
22
  */
24
23
  export const useScrollPosition = function () {
25
24
  let {
@@ -31,7 +30,7 @@ export const useScrollPosition = function () {
31
30
  scrollX: null
32
31
  });
33
32
  const addListener = useScrollListener();
34
- const getScrollPosition = useContextSelector(ChaynsFunctionsContext, v => v.getScrollPosition);
33
+ const getScrollPosition = useFunctionsSelector(f => f.getScrollPosition);
35
34
  useEffect(() => {
36
35
  if (enabled) {
37
36
  return addListener({
@@ -46,8 +45,8 @@ export const useScrollPosition = function () {
46
45
  }, [getScrollPosition]);
47
46
  return value;
48
47
  };
49
- /**
50
- * @category Hooks
48
+ /**
49
+ * @category Hooks
51
50
  */
52
51
  export const useScrollOffsetTop = function () {
53
52
  let {
@@ -69,8 +68,8 @@ export const useScrollOffsetTop = function () {
69
68
  }
70
69
  return 0;
71
70
  };
72
- /**
73
- * @category Hooks
71
+ /**
72
+ * @category Hooks
74
73
  */
75
74
  export const useScrollOffsetBottom = function () {
76
75
  let {
@@ -1,15 +1,14 @@
1
- import { useEffect, useState } from "react";
2
- import { useContextSelector } from "use-context-selector";
3
- import { ChaynsFunctionsContext } from "../components/ChaynsContext";
1
+ import { useEffect, useState } from 'react';
2
+ import { useFunctionsSelector } from './context';
4
3
 
5
- /**
6
- * @category Hooks
7
- * @deprecated Use {@link getAccessToken} instead
4
+ /**
5
+ * @category Hooks
6
+ * @deprecated Use {@link getAccessToken} instead
8
7
  */
9
8
  export const useAccessToken = accessToken => {
10
9
  const [token, setToken] = useState(null);
11
10
  const [externalToken, setExternalToken] = useState(null);
12
- const getAccessToken = useContextSelector(ChaynsFunctionsContext, s => s.getAccessToken);
11
+ const getAccessToken = useFunctionsSelector(f => f.getAccessToken);
13
12
  useEffect(() => {
14
13
  if (accessToken !== null && accessToken !== void 0 && accessToken.external) {
15
14
  void getAccessToken({
@@ -1,7 +1,6 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
1
+ import { useValuesSelector } from './context';
3
2
 
4
- /**
5
- * @category Hooks
3
+ /**
4
+ * @category Hooks
6
5
  */
7
- export const useCurrentPage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.currentPage);
6
+ export const useCurrentPage = () => useValuesSelector(v => v.currentPage);
@@ -1,12 +1,7 @@
1
- import { useFunctions } from './useFunctions';
1
+ import { useFunctionsSelector } from './context';
2
2
 
3
- /**
4
- * @category Hooks
5
- * Returns customCallbackFunction
3
+ /**
4
+ * @category Hooks
5
+ * Returns customCallbackFunction
6
6
  */
7
- export const useCustomCallbackFunction = () => {
8
- const {
9
- customCallbackFunction
10
- } = useFunctions();
11
- return customCallbackFunction;
12
- };
7
+ export const useCustomCallbackFunction = () => useFunctionsSelector(f => f.customCallbackFunction);
@@ -1,7 +1,6 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
1
+ import { useValuesSelector } from './context';
3
2
 
4
- /**
5
- * @category Hooks
3
+ /**
4
+ * @category Hooks
6
5
  */
7
- export const useCustomData = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.customData);
6
+ export const useCustomData = () => useValuesSelector(v => v.customData);
@@ -1,6 +1,5 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from "./context";
2
+ /**
3
+ * @category Hooks
5
4
  */
6
- export const useDevice = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.device);
5
+ export const useDevice = () => useValuesSelector(v => v.device);
@@ -1,16 +1,15 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext, ChaynsFunctionsContext } from '../components/ChaynsContext';
1
+ import { useFunctionsSelector, useValuesSelector } from './context';
3
2
 
4
- /**
5
- * @category Hooks
3
+ /**
4
+ * @category Hooks
6
5
  */
7
6
  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 || (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested;
7
+ const setResult = useFunctionsSelector(f => f.setDialogResult);
8
+ const sendData = useFunctionsSelector(f => f.dispatchEventToDialogHost);
9
+ const addDataListener = useFunctionsSelector(f => f.addDialogHostEventListener);
10
+ const isClosingRequested = useValuesSelector(v => {
11
+ var _v$dialog$isClosingRe, _v$dialog;
12
+ 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;
14
13
  });
15
14
  return {
16
15
  setResult,
@@ -20,13 +19,12 @@ export const useDialogState = () => {
20
19
  };
21
20
  };
22
21
 
23
- /**
24
- * @category Hooks
22
+ /**
23
+ * @category Hooks
25
24
  */
26
25
  export const useDialogData = () => {
27
- const inputData = useContextSelector(ChaynsContext, v => {
26
+ return useValuesSelector(v => {
28
27
  var _v$dialog2;
29
- return v === null || v === void 0 || (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
28
+ return (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
30
29
  });
31
- return inputData;
32
30
  };
@@ -1,6 +1,5 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from './context';
2
+ /**
3
+ * @category Hooks
5
4
  */
6
- export const useEnvironment = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.environment);
5
+ export const useEnvironment = () => useValuesSelector(v => v.environment);
@@ -1,9 +1,6 @@
1
- import { useContextSelector } from "use-context-selector";
2
- import { ChaynsFunctionsContext } from "../components/ChaynsContext";
3
- /**
4
- * @category Hooks
1
+ import { useFunctionsSelector } from './context';
2
+
3
+ /**
4
+ * @category Hooks
5
5
  */
6
- export const useFunctions = () => {
7
- const t = useContextSelector(ChaynsFunctionsContext, f => f || {});
8
- return t;
9
- };
6
+ export const useFunctions = () => useFunctionsSelector(f => f);
@@ -1,9 +1,8 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from './context';
2
+ /**
3
+ * @category Hooks
5
4
  */
6
- export const useIsAdminMode = () => {
7
- var _useContextSelector;
8
- return (_useContextSelector = useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.isAdminModeActive)) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
9
- };
5
+ export const useIsAdminMode = () => useValuesSelector(v => {
6
+ var _v$isAdminModeActive;
7
+ return (_v$isAdminModeActive = v.isAdminModeActive) !== null && _v$isAdminModeActive !== void 0 ? _v$isAdminModeActive : false;
8
+ });
@@ -1,6 +1,5 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from './context';
2
+ /**
3
+ * @category Hooks
5
4
  */
6
- export const useLanguage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
5
+ export const useLanguage = () => useValuesSelector(v => v.language);
@@ -1,8 +1,7 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
1
  import { moduleWrapper } from '../components/moduleWrapper';
4
- /**
5
- * @category Hooks
2
+ import { useValuesSelector } from './context';
3
+ /**
4
+ * @category Hooks
6
5
  */
7
6
  export const usePages = function () {
8
7
  let {
@@ -10,21 +9,21 @@ export const usePages = function () {
10
9
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
11
10
  siteId: undefined
12
11
  };
13
- const pages = useContextSelector(ChaynsContext, v => v.pages);
12
+ const pages = useValuesSelector(v => v.pages);
14
13
  if (siteId) {
15
14
  pages.filter(tapp => tapp.siteId === siteId);
16
15
  }
17
16
  return pages;
18
17
  };
19
- /**
20
- * @category Hooks
18
+ /**
19
+ * @category Hooks
21
20
  */
22
21
  export const usePage = _ref => {
23
22
  let {
24
23
  id,
25
24
  siteId
26
25
  } = _ref;
27
- const pages = useContextSelector(ChaynsContext, v => v.pages);
26
+ const pages = useValuesSelector(v => v.pages);
28
27
  if (id) {
29
28
  var _pages$find;
30
29
  return (_pages$find = pages.find(x => x.id === id && (!siteId || x.siteId === siteId))) !== null && _pages$find !== void 0 ? _pages$find : null;
@@ -1,6 +1,5 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from './context';
2
+ /**
3
+ * @category Hooks
5
4
  */
6
- export const useParameters = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.parameters) || []);
5
+ export const useParameters = () => useValuesSelector(v => v.parameters || []);
@@ -1,6 +1,5 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from './context';
2
+ /**
3
+ * @category Hooks
5
4
  */
6
- export const useSite = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.site);
5
+ export const useSite = () => useValuesSelector(v => v.site);
@@ -1,7 +1,9 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
1
+ import { useValuesSelector } from './context';
3
2
  const empty = {};
4
- /**
5
- * @category Hooks
3
+ /**
4
+ * @category Hooks
6
5
  */
7
- export const useUser = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.user) || empty);
6
+ export const useUser = () => useValuesSelector(v => {
7
+ var _v$user;
8
+ return (_v$user = v.user) !== null && _v$user !== void 0 ? _v$user : empty;
9
+ });
@@ -1,9 +1,6 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
1
+ import { useValuesSelector } from './context';
2
+
3
+ /**
4
+ * @category Hooks
5
5
  */
6
- export const useValues = () => {
7
- const t = useContextSelector(ChaynsContext, v => v || {});
8
- return t;
9
- };
6
+ export const useValues = () => useValuesSelector(v => v);
@@ -1,13 +1,12 @@
1
- import { useContextSelector } from 'use-context-selector';
2
1
  import { useCallback, useEffect, useRef, useState } from 'react';
3
- import { ChaynsFunctionsContext } from '../components/ChaynsContext';
4
2
  import { ScreenSize } from '../types/IChaynsReact';
5
- /**
6
- * @category Hooks
3
+ import { useFunctionsSelector } from './context';
4
+ /**
5
+ * @category Hooks
7
6
  */
8
7
  export const useWindowMetricsListener = () => {
9
- const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addWindowMetricsListener);
10
- const removeListener = useContextSelector(ChaynsFunctionsContext, v => v.removeWindowMetricsListener);
8
+ const addListener = useFunctionsSelector(f => f.addWindowMetricsListener);
9
+ const removeListener = useFunctionsSelector(f => f.removeWindowMetricsListener);
11
10
  const promiseRef = useRef();
12
11
  return useCallback(callback => {
13
12
  promiseRef.current = addListener(callback);
@@ -18,8 +17,8 @@ export const useWindowMetricsListener = () => {
18
17
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
18
  }, []);
20
19
  };
21
- /**
22
- * @category Hooks
20
+ /**
21
+ * @category Hooks
23
22
  */
24
23
  export const useWindowMetrics = function () {
25
24
  let {
@@ -35,7 +34,7 @@ export const useWindowMetrics = function () {
35
34
  pageSize: ScreenSize.XS
36
35
  });
37
36
  const addListener = useWindowMetricsListener();
38
- const getWindowMetrics = useContextSelector(ChaynsFunctionsContext, v => v.getWindowMetrics);
37
+ const getWindowMetrics = useFunctionsSelector(f => f.getWindowMetrics);
39
38
  useEffect(() => {
40
39
  if (enabled) {
41
40
  return addListener(v => {
@@ -1,4 +1,4 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import React, { useEffect, useRef } from 'react';
3
3
  import * as comlink from 'comlink';
4
4
  import postIframeForm from '../../util/postIframeForm';
@@ -51,12 +51,12 @@ export let ScreenSize = /*#__PURE__*/function (ScreenSize) {
51
51
  return ScreenSize;
52
52
  }({});
53
53
 
54
- /**
55
- * @ignore
54
+ /**
55
+ * @ignore
56
56
  */
57
57
 
58
- /**
59
- * @ignore
58
+ /**
59
+ * @ignore
60
60
  */
61
61
 
62
62
  export let AccessMode = /*#__PURE__*/function (AccessMode) {
@@ -1,4 +1,4 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  /* eslint-disable */
@@ -131,6 +131,7 @@ export class AppWrapper {
131
131
  var _this = this;
132
132
  _defineProperty(this, "values", null);
133
133
  _defineProperty(this, "accessToken", '');
134
+ _defineProperty(this, "listeners", []);
134
135
  _defineProperty(this, "counter", 0);
135
136
  _defineProperty(this, "functions", {
136
137
  getAccessToken: async () => ({
@@ -561,6 +562,15 @@ export class AppWrapper {
561
562
  }
562
563
  });
563
564
  _defineProperty(this, "dialogs", []);
565
+ _defineProperty(this, "subscribe", listener => {
566
+ this.listeners.push(listener);
567
+ return () => {
568
+ this.listeners = this.listeners.filter(l => l !== listener);
569
+ };
570
+ });
571
+ _defineProperty(this, "emitChange", () => {
572
+ this.listeners.forEach(l => l());
573
+ });
564
574
  }
565
575
  notImplemented(call) {
566
576
  console.warn(`call ${call} not implement in app`);
@@ -1,4 +1,4 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
@@ -18,6 +18,7 @@ export class FrameWrapper {
18
18
  this.resolve = res;
19
19
  }));
20
20
  _defineProperty(this, "values", null);
21
+ _defineProperty(this, "listeners", []);
21
22
  _defineProperty(this, "functions", {
22
23
  addGeoLocationListener: async (value, callback) => {
23
24
  if (!this.initialized) await this.ready;
@@ -297,6 +298,15 @@ export class FrameWrapper {
297
298
  }
298
299
  });
299
300
  _defineProperty(this, "initialized", false);
301
+ _defineProperty(this, "subscribe", listener => {
302
+ this.listeners.push(listener);
303
+ return () => {
304
+ this.listeners = this.listeners.filter(l => l !== listener);
305
+ };
306
+ });
307
+ _defineProperty(this, "emitChange", () => {
308
+ this.listeners.forEach(l => l());
309
+ });
300
310
  const initialDataTag = document.querySelector('#__CHAYNS_DATA__');
301
311
  if (initialDataTag) {
302
312
  this.values = JSON.parse(initialDataTag.innerHTML);