chayns-api 3.0.0 → 3.1.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.
Files changed (139) hide show
  1. package/dist/cjs/calls/index.js +4 -1
  2. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  3. package/dist/cjs/components/ChaynsProvider.js +34 -6
  4. package/dist/cjs/components/withHydrationBoundary.js +2 -2
  5. package/dist/cjs/constants/index.js +0 -22
  6. package/dist/cjs/contexts/HistoryLayerContext.js +89 -0
  7. package/dist/cjs/contexts/index.js +38 -0
  8. package/dist/cjs/handler/history/FrameHistoryLayer.js +100 -0
  9. package/dist/cjs/handler/history/HistoryLayer.js +321 -0
  10. package/dist/cjs/handler/history/index.js +19 -0
  11. package/dist/cjs/hooks/history.js +454 -0
  12. package/dist/cjs/hooks/index.js +62 -1
  13. package/dist/cjs/host/ChaynsHost.js +113 -54
  14. package/dist/cjs/host/iframe/HostIframe.js +70 -5
  15. package/dist/cjs/host/module/ModuleHost.js +50 -44
  16. package/dist/cjs/index.js +139 -6
  17. package/dist/cjs/types/history.js +1 -0
  18. package/dist/cjs/umd.index.js +2 -2
  19. package/dist/cjs/utils/EventBus.js +33 -0
  20. package/dist/cjs/{util → utils}/appStorage.js +2 -2
  21. package/dist/cjs/utils/equality.js +19 -0
  22. package/dist/cjs/utils/history/BlockRegistry.js +110 -0
  23. package/dist/cjs/utils/history/NavigationQueue.js +388 -0
  24. package/dist/cjs/utils/history/layerTree.js +32 -0
  25. package/dist/cjs/utils/history/navigationIndex.js +42 -0
  26. package/dist/cjs/utils/history/rootLayer.js +175 -0
  27. package/dist/cjs/utils/history/segments.js +15 -0
  28. package/dist/cjs/utils/history/stateProjector.js +156 -0
  29. package/dist/cjs/utils/history/url.js +47 -0
  30. package/dist/cjs/utils/history/window.js +9 -0
  31. package/dist/cjs/wrapper/AppWrapper.js +23 -23
  32. package/dist/cjs/wrapper/FrameWrapper.js +35 -2
  33. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -0
  34. package/dist/cjs/wrapper/StaticChaynsApi.js +1 -1
  35. package/dist/esm/calls/index.js +2 -0
  36. package/dist/esm/calls/visibilityChangeListener.js +1 -1
  37. package/dist/esm/components/ChaynsProvider.js +34 -6
  38. package/dist/esm/components/withHydrationBoundary.js +1 -1
  39. package/dist/esm/constants/index.js +1 -3
  40. package/dist/esm/contexts/HistoryLayerContext.js +76 -0
  41. package/dist/esm/contexts/index.js +3 -0
  42. package/dist/esm/handler/history/FrameHistoryLayer.js +105 -0
  43. package/dist/esm/handler/history/HistoryLayer.js +321 -0
  44. package/dist/esm/handler/history/index.js +2 -0
  45. package/dist/esm/hooks/history.js +428 -0
  46. package/dist/esm/hooks/index.js +2 -1
  47. package/dist/esm/host/ChaynsHost.js +113 -54
  48. package/dist/esm/host/iframe/HostIframe.js +70 -5
  49. package/dist/esm/host/module/ModuleHost.js +50 -44
  50. package/dist/esm/index.js +15 -6
  51. package/dist/esm/types/history.js +1 -0
  52. package/dist/esm/umd.index.js +2 -2
  53. package/dist/esm/utils/EventBus.js +31 -0
  54. package/dist/esm/{util → utils}/appStorage.js +1 -1
  55. package/dist/esm/utils/equality.js +12 -0
  56. package/dist/esm/utils/history/BlockRegistry.js +108 -0
  57. package/dist/esm/utils/history/NavigationQueue.js +385 -0
  58. package/dist/esm/utils/history/layerTree.js +24 -0
  59. package/dist/esm/utils/history/navigationIndex.js +33 -0
  60. package/dist/esm/utils/history/rootLayer.js +167 -0
  61. package/dist/esm/utils/history/segments.js +7 -0
  62. package/dist/esm/utils/history/stateProjector.js +147 -0
  63. package/dist/esm/utils/history/url.js +40 -0
  64. package/dist/esm/utils/history/window.js +3 -0
  65. package/dist/esm/wrapper/AppWrapper.js +5 -5
  66. package/dist/esm/wrapper/FrameWrapper.js +35 -2
  67. package/dist/esm/wrapper/ModuleFederationWrapper.js +2 -0
  68. package/dist/esm/wrapper/StaticChaynsApi.js +2 -1
  69. package/dist/types/calls/index.d.ts +5 -0
  70. package/dist/types/components/ChaynsProvider.d.ts +21 -0
  71. package/dist/types/constants/index.d.ts +0 -2
  72. package/dist/types/contexts/HistoryLayerContext.d.ts +33 -0
  73. package/dist/types/contexts/index.d.ts +3 -0
  74. package/dist/types/handler/history/FrameHistoryLayer.d.ts +99 -0
  75. package/dist/types/handler/history/HistoryLayer.d.ts +117 -0
  76. package/dist/types/handler/history/index.d.ts +2 -0
  77. package/dist/types/hooks/history.d.ts +89 -0
  78. package/dist/types/hooks/index.d.ts +1 -0
  79. package/dist/types/host/ChaynsHost.d.ts +12 -0
  80. package/dist/types/host/iframe/HostIframe.d.ts +4 -0
  81. package/dist/types/host/module/ModuleHost.d.ts +4 -0
  82. package/dist/types/index.d.ts +15 -6
  83. package/dist/types/types/IChaynsReact.d.ts +3 -0
  84. package/dist/types/types/history.d.ts +74 -0
  85. package/dist/types/umd.index.d.ts +2 -2
  86. package/dist/types/utils/EventBus.d.ts +10 -0
  87. package/dist/types/{util → utils}/collectCssChunks.d.ts +1 -1
  88. package/dist/types/utils/equality.d.ts +2 -0
  89. package/dist/types/utils/history/BlockRegistry.d.ts +38 -0
  90. package/dist/types/utils/history/NavigationQueue.d.ts +109 -0
  91. package/dist/types/utils/history/layerTree.d.ts +10 -0
  92. package/dist/types/utils/history/navigationIndex.d.ts +14 -0
  93. package/dist/types/utils/history/rootLayer.d.ts +42 -0
  94. package/dist/types/utils/history/segments.d.ts +2 -0
  95. package/dist/types/utils/history/stateProjector.d.ts +24 -0
  96. package/dist/types/utils/history/url.d.ts +17 -0
  97. package/dist/types/utils/history/window.d.ts +1 -0
  98. package/dist/types/wrapper/FrameWrapper.d.ts +1 -0
  99. package/dist/types/wrapper/StaticChaynsApi.d.ts +1 -0
  100. package/package.json +2 -1
  101. /package/dist/cjs/{constants → contexts}/hydrationContext.js +0 -0
  102. /package/dist/cjs/{constants → contexts}/moduleContext.js +0 -0
  103. /package/dist/cjs/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
  104. /package/dist/cjs/{util → utils}/appCall.js +0 -0
  105. /package/dist/cjs/{util → utils}/bindChaynsApi.js +0 -0
  106. /package/dist/cjs/{util → utils}/collectCssChunks.js +0 -0
  107. /package/dist/cjs/{util → utils}/deviceHelper.js +0 -0
  108. /package/dist/cjs/{util → utils}/heightHelper.js +0 -0
  109. /package/dist/cjs/{util → utils}/initModuleFederationSharing.js +0 -0
  110. /package/dist/cjs/{util → utils}/is.js +0 -0
  111. /package/dist/cjs/{util → utils}/postIframeForm.js +0 -0
  112. /package/dist/cjs/{util → utils}/transferNestedFunctions.js +0 -0
  113. /package/dist/cjs/{util → utils}/url.js +0 -0
  114. /package/dist/esm/{constants → contexts}/hydrationContext.js +0 -0
  115. /package/dist/esm/{constants → contexts}/moduleContext.js +0 -0
  116. /package/dist/esm/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
  117. /package/dist/esm/{util → utils}/appCall.js +0 -0
  118. /package/dist/esm/{util → utils}/bindChaynsApi.js +0 -0
  119. /package/dist/esm/{util → utils}/collectCssChunks.js +0 -0
  120. /package/dist/esm/{util → utils}/deviceHelper.js +0 -0
  121. /package/dist/esm/{util → utils}/heightHelper.js +0 -0
  122. /package/dist/esm/{util → utils}/initModuleFederationSharing.js +0 -0
  123. /package/dist/esm/{util → utils}/is.js +0 -0
  124. /package/dist/esm/{util → utils}/postIframeForm.js +0 -0
  125. /package/dist/esm/{util → utils}/transferNestedFunctions.js +0 -0
  126. /package/dist/esm/{util → utils}/url.js +0 -0
  127. /package/dist/types/{constants → contexts}/hydrationContext.d.ts +0 -0
  128. /package/dist/types/{constants → contexts}/moduleContext.d.ts +0 -0
  129. /package/dist/types/{helper/apiListenerHelper.d.ts → utils/apiListener.d.ts} +0 -0
  130. /package/dist/types/{util → utils}/appCall.d.ts +0 -0
  131. /package/dist/types/{util → utils}/appStorage.d.ts +0 -0
  132. /package/dist/types/{util → utils}/bindChaynsApi.d.ts +0 -0
  133. /package/dist/types/{util → utils}/deviceHelper.d.ts +0 -0
  134. /package/dist/types/{util → utils}/heightHelper.d.ts +0 -0
  135. /package/dist/types/{util → utils}/initModuleFederationSharing.d.ts +0 -0
  136. /package/dist/types/{util → utils}/is.d.ts +0 -0
  137. /package/dist/types/{util → utils}/postIframeForm.d.ts +0 -0
  138. /package/dist/types/{util → utils}/transferNestedFunctions.d.ts +0 -0
  139. /package/dist/types/{util → utils}/url.d.ts +0 -0
@@ -1,10 +1,10 @@
1
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); }
2
2
  import React, { useEffect, useRef } from 'react';
3
3
  import * as comlink from 'comlink';
4
- import postIframeForm from '../../util/postIframeForm';
4
+ import postIframeForm from '../../utils/postIframeForm';
5
5
  import useUpdateData from './utils/useUpdateData';
6
- import { replaceStagingUrl } from "../../util/url";
7
- import { initTransferNestedFunctions } from '../../util/transferNestedFunctions';
6
+ import { replaceStagingUrl } from "../../utils/url";
7
+ import { initTransferNestedFunctions } from '../../utils/transferNestedFunctions';
8
8
  const HostIframe = ({
9
9
  iFrameProps,
10
10
  src,
@@ -24,13 +24,17 @@ const HostIframe = ({
24
24
  customData,
25
25
  preventStagingReplacement,
26
26
  dialog,
27
- styleSettings
27
+ styleSettings,
28
+ historyLayer,
29
+ isHistoryDisabled
28
30
  }) => {
29
31
  const eventTarget = useRef();
30
32
  const ref = useRef();
31
33
  const currentDataRef = useRef();
32
34
  const customFunctionsRef = useRef();
33
35
  customFunctionsRef.current = customFunctions;
36
+ const historyLayerRef = useRef(undefined);
37
+ historyLayerRef.current = historyLayer;
34
38
  if (!eventTarget.current) {
35
39
  eventTarget.current = global.document ? document.createElement('div') : undefined;
36
40
  }
@@ -42,6 +46,7 @@ const HostIframe = ({
42
46
  const initialData = {
43
47
  site,
44
48
  isAdminModeActive,
49
+ isHistoryDisabled,
45
50
  pages,
46
51
  currentPage,
47
52
  device,
@@ -87,7 +92,66 @@ const HostIframe = ({
87
92
  addDataListener: cb => {
88
93
  if (eventTarget.current) eventTarget.current.addEventListener('data_update', e => e.detail && cb(e.detail));
89
94
  },
90
- getInitialData: () => currentDataRef.current
95
+ getInitialData: () => currentDataRef.current,
96
+ history: historyLayerRef.current ? {
97
+ getInitialState: () => {
98
+ const l = historyLayerRef.current;
99
+ if (!l) return null;
100
+ return {
101
+ id: l.id,
102
+ depth: l.depth,
103
+ segments: l.getRoute(),
104
+ params: l.getParams(),
105
+ hash: l.getHash(),
106
+ state: l.getState(),
107
+ activeChildId: l.getActiveChildId(),
108
+ segmentCount: l.getSegmentCount()
109
+ };
110
+ },
111
+ setRoute: (route, opts) => {
112
+ var _historyLayerRef$curr;
113
+ return (_historyLayerRef$curr = historyLayerRef.current) === null || _historyLayerRef$curr === void 0 ? void 0 : _historyLayerRef$curr.setRoute(route, opts);
114
+ },
115
+ setParams: (params, opts) => {
116
+ var _historyLayerRef$curr2;
117
+ return (_historyLayerRef$curr2 = historyLayerRef.current) === null || _historyLayerRef$curr2 === void 0 ? void 0 : _historyLayerRef$curr2.setParams(params, opts);
118
+ },
119
+ setHash: (hash, opts) => {
120
+ var _historyLayerRef$curr3;
121
+ return (_historyLayerRef$curr3 = historyLayerRef.current) === null || _historyLayerRef$curr3 === void 0 ? void 0 : _historyLayerRef$curr3.setHash(hash, opts);
122
+ },
123
+ setState: (state, opts) => {
124
+ var _historyLayerRef$curr4;
125
+ return (_historyLayerRef$curr4 = historyLayerRef.current) === null || _historyLayerRef$curr4 === void 0 ? void 0 : _historyLayerRef$curr4.setState(state, opts);
126
+ },
127
+ navigate: opts => {
128
+ var _historyLayerRef$curr5;
129
+ return (_historyLayerRef$curr5 = historyLayerRef.current) === null || _historyLayerRef$curr5 === void 0 ? void 0 : _historyLayerRef$curr5.navigate(opts);
130
+ },
131
+ setActiveChild: (id, init) => {
132
+ var _historyLayerRef$curr6;
133
+ return (_historyLayerRef$curr6 = historyLayerRef.current) === null || _historyLayerRef$curr6 === void 0 ? void 0 : _historyLayerRef$curr6.setActiveChild(id, init);
134
+ },
135
+ setSegmentCount: n => {
136
+ var _historyLayerRef$curr7;
137
+ return (_historyLayerRef$curr7 = historyLayerRef.current) === null || _historyLayerRef$curr7 === void 0 ? void 0 : _historyLayerRef$curr7.setSegmentCount(n);
138
+ },
139
+ addChangeListener: callback => {
140
+ var _historyLayerRef$curr8, _historyLayerRef$curr9;
141
+ const unsub = (_historyLayerRef$curr8 = (_historyLayerRef$curr9 = historyLayerRef.current) === null || _historyLayerRef$curr9 === void 0 ? void 0 : _historyLayerRef$curr9.addEventListener('change', callback)) !== null && _historyLayerRef$curr8 !== void 0 ? _historyLayerRef$curr8 : () => {};
142
+ return comlink.proxy(unsub);
143
+ },
144
+ addPopstateListener: callback => {
145
+ var _historyLayerRef$curr0, _historyLayerRef$curr1;
146
+ const unsub = (_historyLayerRef$curr0 = (_historyLayerRef$curr1 = historyLayerRef.current) === null || _historyLayerRef$curr1 === void 0 ? void 0 : _historyLayerRef$curr1.addEventListener('popstate', callback)) !== null && _historyLayerRef$curr0 !== void 0 ? _historyLayerRef$curr0 : () => {};
147
+ return comlink.proxy(unsub);
148
+ },
149
+ addBlock: (callback, opts) => {
150
+ var _historyLayerRef$curr10, _historyLayerRef$curr11;
151
+ const unsub = (_historyLayerRef$curr10 = (_historyLayerRef$curr11 = historyLayerRef.current) === null || _historyLayerRef$curr11 === void 0 ? void 0 : _historyLayerRef$curr11.addBlock(callback, opts)) !== null && _historyLayerRef$curr10 !== void 0 ? _historyLayerRef$curr10 : () => {};
152
+ return comlink.proxy(unsub);
153
+ }
154
+ } : undefined
91
155
  }
92
156
  };
93
157
  comlink.expose(obj, comlink.windowEndpoint(ref.current.contentWindow));
@@ -98,6 +162,7 @@ const HostIframe = ({
98
162
  }
99
163
  return undefined;
100
164
  }, []);
165
+ useUpdateData(eventTarget.current, 'isHistoryDisabled', isHistoryDisabled);
101
166
  useUpdateData(eventTarget.current, 'isAdminModeActive', isAdminModeActive);
102
167
  useUpdateData(eventTarget.current, 'user', user);
103
168
  useUpdateData(eventTarget.current, 'site', site);
@@ -1,8 +1,8 @@
1
1
  import { c as _c } from "react-compiler-runtime";
2
2
  import React, { useContext, useMemo } from 'react';
3
- import { ModuleContext } from '../../constants/moduleContext';
3
+ import { ModuleContext } from '../../contexts/moduleContext';
4
4
  import loadComponent from './utils/loadComponent';
5
- import { replaceStagingUrl } from "../../util/url";
5
+ import { replaceStagingUrl } from "../../utils/url";
6
6
  const System = ({
7
7
  system,
8
8
  fallback,
@@ -24,7 +24,7 @@ const System = ({
24
24
  }, React.createElement(Component, props));
25
25
  };
26
26
  const ModuleHost = t0 => {
27
- const $ = _c(34);
27
+ const $ = _c(36);
28
28
  const {
29
29
  system,
30
30
  children: t1,
@@ -42,14 +42,17 @@ const ModuleHost = t0 => {
42
42
  dialog,
43
43
  environment,
44
44
  preventStagingReplacement,
45
- styleSettings
45
+ styleSettings,
46
+ historyLayer,
47
+ isHistoryDisabled
46
48
  } = t0;
47
49
  const children = t1 === undefined ? null : t1;
48
50
  let result;
49
- if ($[0] !== currentPage || $[1] !== customData || $[2] !== device || $[3] !== dialog || $[4] !== environment || $[5] !== isAdminModeActive || $[6] !== language || $[7] !== pages || $[8] !== parameters || $[9] !== site || $[10] !== styleSettings || $[11] !== user) {
51
+ if ($[0] !== currentPage || $[1] !== customData || $[2] !== device || $[3] !== dialog || $[4] !== environment || $[5] !== isAdminModeActive || $[6] !== isHistoryDisabled || $[7] !== language || $[8] !== pages || $[9] !== parameters || $[10] !== site || $[11] !== styleSettings || $[12] !== user) {
50
52
  result = {
51
53
  site,
52
54
  isAdminModeActive,
55
+ isHistoryDisabled,
53
56
  pages,
54
57
  currentPage,
55
58
  device,
@@ -71,49 +74,50 @@ const ModuleHost = t0 => {
71
74
  $[3] = dialog;
72
75
  $[4] = environment;
73
76
  $[5] = isAdminModeActive;
74
- $[6] = language;
75
- $[7] = pages;
76
- $[8] = parameters;
77
- $[9] = site;
78
- $[10] = styleSettings;
79
- $[11] = user;
80
- $[12] = result;
77
+ $[6] = isHistoryDisabled;
78
+ $[7] = language;
79
+ $[8] = pages;
80
+ $[9] = parameters;
81
+ $[10] = site;
82
+ $[11] = styleSettings;
83
+ $[12] = user;
84
+ $[13] = result;
81
85
  } else {
82
- result = $[12];
86
+ result = $[13];
83
87
  }
84
88
  const data = result;
85
89
  let t2;
86
- if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
90
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
87
91
  t2 = React.createElement("div", {
88
92
  className: "module-css"
89
93
  });
90
- $[13] = t2;
94
+ $[14] = t2;
91
95
  } else {
92
- t2 = $[13];
96
+ t2 = $[14];
93
97
  }
94
98
  const t3 = system.scope;
95
99
  let t4;
96
- if ($[14] !== environment.buildEnvironment || $[15] !== preventStagingReplacement || $[16] !== system.url) {
100
+ if ($[15] !== environment.buildEnvironment || $[16] !== preventStagingReplacement || $[17] !== system.url) {
97
101
  t4 = replaceStagingUrl(preventStagingReplacement, system.url, environment.buildEnvironment);
98
- $[14] = environment.buildEnvironment;
99
- $[15] = preventStagingReplacement;
100
- $[16] = system.url;
101
- $[17] = t4;
102
+ $[15] = environment.buildEnvironment;
103
+ $[16] = preventStagingReplacement;
104
+ $[17] = system.url;
105
+ $[18] = t4;
102
106
  } else {
103
- t4 = $[17];
107
+ t4 = $[18];
104
108
  }
105
109
  let t5;
106
- if ($[18] !== environment.buildEnvironment || $[19] !== preventStagingReplacement || $[20] !== system.serverUrl) {
110
+ if ($[19] !== environment.buildEnvironment || $[20] !== preventStagingReplacement || $[21] !== system.serverUrl) {
107
111
  t5 = replaceStagingUrl(preventStagingReplacement, system.serverUrl, environment.buildEnvironment);
108
- $[18] = environment.buildEnvironment;
109
- $[19] = preventStagingReplacement;
110
- $[20] = system.serverUrl;
111
- $[21] = t5;
112
+ $[19] = environment.buildEnvironment;
113
+ $[20] = preventStagingReplacement;
114
+ $[21] = system.serverUrl;
115
+ $[22] = t5;
112
116
  } else {
113
- t5 = $[21];
117
+ t5 = $[22];
114
118
  }
115
119
  let t6;
116
- if ($[22] !== system.module || $[23] !== system.preventSingleton || $[24] !== system.scope || $[25] !== t4 || $[26] !== t5) {
120
+ if ($[23] !== system.module || $[24] !== system.preventSingleton || $[25] !== system.scope || $[26] !== t4 || $[27] !== t5) {
117
121
  t6 = {
118
122
  scope: t3,
119
123
  url: t4,
@@ -121,33 +125,35 @@ const ModuleHost = t0 => {
121
125
  module: system.module,
122
126
  preventSingleton: system.preventSingleton
123
127
  };
124
- $[22] = system.module;
125
- $[23] = system.preventSingleton;
126
- $[24] = system.scope;
127
- $[25] = t4;
128
- $[26] = t5;
129
- $[27] = t6;
128
+ $[23] = system.module;
129
+ $[24] = system.preventSingleton;
130
+ $[25] = system.scope;
131
+ $[26] = t4;
132
+ $[27] = t5;
133
+ $[28] = t6;
130
134
  } else {
131
- t6 = $[27];
135
+ t6 = $[28];
132
136
  }
133
137
  let t7;
134
- if ($[28] !== children || $[29] !== customFunctions || $[30] !== data || $[31] !== functions || $[32] !== t6) {
138
+ if ($[29] !== children || $[30] !== customFunctions || $[31] !== data || $[32] !== functions || $[33] !== historyLayer || $[34] !== t6) {
135
139
  t7 = React.createElement(React.Fragment, null, t2, React.createElement(System, {
136
140
  system: t6,
137
141
  data: data,
138
142
  functions: functions,
139
143
  customFunctions: customFunctions,
140
144
  fallback: children,
145
+ historyLayer: historyLayer,
141
146
  isModule: true
142
147
  }));
143
- $[28] = children;
144
- $[29] = customFunctions;
145
- $[30] = data;
146
- $[31] = functions;
147
- $[32] = t6;
148
- $[33] = t7;
148
+ $[29] = children;
149
+ $[30] = customFunctions;
150
+ $[31] = data;
151
+ $[32] = functions;
152
+ $[33] = historyLayer;
153
+ $[34] = t6;
154
+ $[35] = t7;
149
155
  } else {
150
- t7 = $[33];
156
+ t7 = $[35];
151
157
  }
152
158
  return t7;
153
159
  };
package/dist/esm/index.js CHANGED
@@ -1,22 +1,31 @@
1
1
  export { default as ChaynsProvider } from './components/ChaynsProvider';
2
- export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
2
+ export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './utils/deviceHelper';
3
3
  export { default as ChaynsHost } from './host/ChaynsHost';
4
4
  export { withCompatMode } from './components/withCompatMode';
5
5
  export * from './calls';
6
6
  export * from './hooks';
7
7
  export * from './components/WaitUntil';
8
8
  export * from './types/IChaynsReact';
9
- export * from './util/is';
9
+ export * from './types/history';
10
+ export * from './utils/is';
10
11
  export * from './constants';
11
12
  export { default as withHydrationBoundary } from './components/withHydrationBoundary';
12
13
  export { default as StaticChaynsApi } from './wrapper/StaticChaynsApi';
13
14
  export { default as loadComponent, loadModule } from './host/module/utils/loadComponent';
14
15
  export { default as DialogHandler } from './handler/DialogHandler';
16
+ export * from './handler/history';
17
+ export { initRootChaynsHistoryLayer, getOrInitRootChaynsHistoryLayer } from './utils/history/rootLayer';
18
+ export { NavigationQueue } from './utils/history/NavigationQueue';
19
+ export { BlockRegistry } from './utils/history/BlockRegistry';
20
+ export { projectToUrl, parseFromUrl } from './utils/history/url';
21
+ export { projectToState, applyStateToTree, diffIncomingState, hasChaynsHistoryState } from './utils/history/stateProjector';
22
+ export { getChaynsHistoryActiveChain, findChaynsHistoryLayerById, isInChaynsHistoryActiveChain } from './utils/history/layerTree';
15
23
  import * as _dialog from './calls/dialogs/index';
16
24
  export { _dialog as dialog };
17
25
  export * from './plugins';
18
- export * from './util/initModuleFederationSharing';
19
- export * from './util/bindChaynsApi';
20
- export * from './util/appStorage';
21
- export * from './util/collectCssChunks';
26
+ export * from './utils/initModuleFederationSharing';
27
+ export * from './utils/bindChaynsApi';
28
+ export * from './utils/appStorage';
29
+ export * from './utils/collectCssChunks';
30
+ export * from './contexts';
22
31
  export { getChaynsApi } from './components/moduleWrapper';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
- export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
1
+ export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './utils/deviceHelper';
2
2
  export * from './calls';
3
3
  export * from './types/IChaynsReact';
4
- export * from './util/is';
4
+ export * from './utils/is';
5
5
  export { default as StaticChaynsApi } from './wrapper/StaticChaynsApi';
6
6
  export { default as DialogHandler } from './handler/DialogHandler';
7
7
  import * as _dialog from './calls/dialogs/index';
@@ -0,0 +1,31 @@
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; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
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
+ export class EventBus {
5
+ constructor() {
6
+ _defineProperty(this, "listeners", new Map());
7
+ }
8
+ on(type, handler) {
9
+ let set = this.listeners.get(type);
10
+ if (!set) {
11
+ set = new Set();
12
+ this.listeners.set(type, set);
13
+ }
14
+ set.add(handler);
15
+ return () => set.delete(handler);
16
+ }
17
+ emit(type, event) {
18
+ const set = this.listeners.get(type);
19
+ if (!set) return;
20
+ for (const fn of [...set]) {
21
+ try {
22
+ fn(event);
23
+ } catch (err) {
24
+ console.error('[chaynsHistory] listener threw', err);
25
+ }
26
+ }
27
+ }
28
+ clear() {
29
+ this.listeners.clear();
30
+ }
31
+ }
@@ -1,4 +1,4 @@
1
- import { addApiListener } from '../helper/apiListenerHelper';
1
+ import { addApiListener } from './apiListener';
2
2
  import { AppName } from '../types/IChaynsReact';
3
3
  export function isAppStorageAvailable() {
4
4
  var _this$values$device$a, _this$values$device$a2;
@@ -0,0 +1,12 @@
1
+ export function shallowEqualArr(a, b) {
2
+ if (a.length !== b.length) return false;
3
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
4
+ return true;
5
+ }
6
+ export function shallowEqualObj(a, b) {
7
+ const ak = Object.keys(a);
8
+ const bk = Object.keys(b);
9
+ if (ak.length !== bk.length) return false;
10
+ for (const k of ak) if (a[k] !== b[k]) return false;
11
+ return true;
12
+ }
@@ -0,0 +1,108 @@
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; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
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
+ const BLOCK_TIMEOUT_MS = 30000;
5
+ let _nextId = 1;
6
+ export class BlockRegistry {
7
+ constructor() {
8
+ _defineProperty(this, "layerBlocks", new Map());
9
+ _defineProperty(this, "beforeUnloadCount", 0);
10
+ _defineProperty(this, "beforeUnloadHandler", e => {
11
+ e.preventDefault();
12
+ e.returnValue = '';
13
+ });
14
+ }
15
+ add(layer, callback, opts = {}) {
16
+ var _opts$scope, _opts$isBeforeUnload;
17
+ const entry = {
18
+ id: String(_nextId++),
19
+ callback,
20
+ opts: {
21
+ scope: (_opts$scope = opts.scope) !== null && _opts$scope !== void 0 ? _opts$scope : 'local',
22
+ isBeforeUnload: (_opts$isBeforeUnload = opts.isBeforeUnload) !== null && _opts$isBeforeUnload !== void 0 ? _opts$isBeforeUnload : false
23
+ }
24
+ };
25
+ let set = this.layerBlocks.get(layer.id);
26
+ if (!set) {
27
+ set = new Set();
28
+ this.layerBlocks.set(layer.id, set);
29
+ }
30
+ set.add(entry);
31
+ if (entry.opts.isBeforeUnload) {
32
+ this.incrementBeforeUnload();
33
+ }
34
+ return () => this.remove(layer.id, entry);
35
+ }
36
+ remove(layerId, entry) {
37
+ const set = this.layerBlocks.get(layerId);
38
+ if (!set) return;
39
+ set.delete(entry);
40
+ if (set.size === 0) this.layerBlocks.delete(layerId);
41
+ if (entry.opts.isBeforeUnload) {
42
+ this.decrementBeforeUnload();
43
+ }
44
+ }
45
+ removeAllForLayer(layerId) {
46
+ const set = this.layerBlocks.get(layerId);
47
+ if (!set) return;
48
+ for (const entry of set) {
49
+ if (entry.opts.isBeforeUnload) this.decrementBeforeUnload();
50
+ }
51
+ this.layerBlocks.delete(layerId);
52
+ }
53
+ collectApplicableBlocks(targetLayer) {
54
+ const result = [];
55
+ const localSet = this.layerBlocks.get(targetLayer.id);
56
+ if (localSet) {
57
+ for (const entry of localSet) {
58
+ result.push(entry);
59
+ }
60
+ }
61
+ this.collectGlobalFromActiveDescendants(targetLayer, result);
62
+ return result;
63
+ }
64
+ collectGlobalFromActiveDescendants(layer, out) {
65
+ const activeChildId = layer.getActiveChildId();
66
+ if (!activeChildId) return;
67
+ const child = layer.getChildLayer(activeChildId);
68
+ if (!child) return;
69
+ const childSet = this.layerBlocks.get(child.id);
70
+ if (childSet) {
71
+ for (const entry of childSet) {
72
+ if (entry.opts.scope === 'global') {
73
+ out.push(entry);
74
+ }
75
+ }
76
+ }
77
+ this.collectGlobalFromActiveDescendants(child, out);
78
+ }
79
+ async checkBlocks(targetLayer) {
80
+ const blocks = this.collectApplicableBlocks(targetLayer);
81
+ if (blocks.length === 0) return true;
82
+ const results = await Promise.all(blocks.map(b => this.runBlock(b)));
83
+ return results.every(Boolean);
84
+ }
85
+ async runBlock(entry) {
86
+ try {
87
+ const result = await Promise.race([entry.callback(), new Promise(resolve => setTimeout(() => {
88
+ resolve(false);
89
+ }, BLOCK_TIMEOUT_MS))]);
90
+ return result;
91
+ } catch (err) {
92
+ return false;
93
+ }
94
+ }
95
+ incrementBeforeUnload() {
96
+ this.beforeUnloadCount++;
97
+ if (this.beforeUnloadCount === 1 && typeof window !== 'undefined') {
98
+ window.addEventListener('beforeunload', this.beforeUnloadHandler);
99
+ }
100
+ }
101
+ decrementBeforeUnload() {
102
+ if (this.beforeUnloadCount === 0) return;
103
+ this.beforeUnloadCount--;
104
+ if (this.beforeUnloadCount === 0 && typeof window !== 'undefined') {
105
+ window.removeEventListener('beforeunload', this.beforeUnloadHandler);
106
+ }
107
+ }
108
+ }