chayns-api 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/ChaynsProvider.js +1 -1
- package/dist/cjs/host/iframe/HostIframe.js +18 -9
- package/dist/cjs/wrapper/FrameWrapper.js +5 -2
- package/dist/esm/components/ChaynsProvider.js +1 -1
- package/dist/esm/host/iframe/HostIframe.js +18 -9
- package/dist/esm/wrapper/FrameWrapper.js +5 -2
- package/dist/types/types/IChaynsReact.d.ts +1 -1
- package/package.json +1 -1
|
@@ -124,7 +124,7 @@ const ChaynsProvider = ({
|
|
|
124
124
|
rootLayerRef.current = (0, _rootLayer.getOrInitRootChaynsHistoryLayer)(history === null || history === void 0 ? void 0 : history.url, history === null || history === void 0 ? void 0 : history.segmentCount).rootLayer;
|
|
125
125
|
}
|
|
126
126
|
const layer = (_ref2 = historyLayer !== null && historyLayer !== void 0 ? historyLayer : parentLayerRef.current) !== null && _ref2 !== void 0 ? _ref2 : rootLayerRef.current;
|
|
127
|
-
if (typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
|
|
127
|
+
if (layer && typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
|
|
128
128
|
layer.setSegmentCount(segmentCount);
|
|
129
129
|
}
|
|
130
130
|
setEffectiveLayer(layer);
|
|
@@ -101,7 +101,7 @@ const HostIframe = ({
|
|
|
101
101
|
if (eventTarget.current) eventTarget.current.addEventListener('data_update', e => e.detail && cb(e.detail));
|
|
102
102
|
},
|
|
103
103
|
getInitialData: () => currentDataRef.current,
|
|
104
|
-
history:
|
|
104
|
+
history: {
|
|
105
105
|
getInitialState: () => {
|
|
106
106
|
const l = historyLayerRef.current;
|
|
107
107
|
if (!l) return null;
|
|
@@ -118,48 +118,57 @@ const HostIframe = ({
|
|
|
118
118
|
},
|
|
119
119
|
setRoute: (route, opts) => {
|
|
120
120
|
var _historyLayerRef$curr;
|
|
121
|
-
return (_historyLayerRef$curr = historyLayerRef.current) === null || _historyLayerRef$curr === void 0 ? void 0 : _historyLayerRef$curr.setRoute(route, opts);
|
|
121
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setRoute is not allowed on this page') : (_historyLayerRef$curr = historyLayerRef.current) === null || _historyLayerRef$curr === void 0 ? void 0 : _historyLayerRef$curr.setRoute(route, opts);
|
|
122
122
|
},
|
|
123
123
|
setParams: (params, opts) => {
|
|
124
124
|
var _historyLayerRef$curr2;
|
|
125
|
-
return (_historyLayerRef$curr2 = historyLayerRef.current) === null || _historyLayerRef$curr2 === void 0 ? void 0 : _historyLayerRef$curr2.setParams(params, opts);
|
|
125
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setParams is not allowed on this page') : (_historyLayerRef$curr2 = historyLayerRef.current) === null || _historyLayerRef$curr2 === void 0 ? void 0 : _historyLayerRef$curr2.setParams(params, opts);
|
|
126
126
|
},
|
|
127
127
|
setHash: (hash, opts) => {
|
|
128
128
|
var _historyLayerRef$curr3;
|
|
129
|
-
return (_historyLayerRef$curr3 = historyLayerRef.current) === null || _historyLayerRef$curr3 === void 0 ? void 0 : _historyLayerRef$curr3.setHash(hash, opts);
|
|
129
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setHash is not allowed on this page') : (_historyLayerRef$curr3 = historyLayerRef.current) === null || _historyLayerRef$curr3 === void 0 ? void 0 : _historyLayerRef$curr3.setHash(hash, opts);
|
|
130
130
|
},
|
|
131
131
|
setState: (state, opts) => {
|
|
132
132
|
var _historyLayerRef$curr4;
|
|
133
|
-
return (_historyLayerRef$curr4 = historyLayerRef.current) === null || _historyLayerRef$curr4 === void 0 ? void 0 : _historyLayerRef$curr4.setState(state, opts);
|
|
133
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setState is not allowed on this page') : (_historyLayerRef$curr4 = historyLayerRef.current) === null || _historyLayerRef$curr4 === void 0 ? void 0 : _historyLayerRef$curr4.setState(state, opts);
|
|
134
134
|
},
|
|
135
135
|
navigate: opts => {
|
|
136
136
|
var _historyLayerRef$curr5;
|
|
137
|
-
return (_historyLayerRef$curr5 = historyLayerRef.current) === null || _historyLayerRef$curr5 === void 0 ? void 0 : _historyLayerRef$curr5.navigate(opts);
|
|
137
|
+
return !historyLayerRef.current ? new Error('[chayns-api] navigate is not allowed on this page') : (_historyLayerRef$curr5 = historyLayerRef.current) === null || _historyLayerRef$curr5 === void 0 ? void 0 : _historyLayerRef$curr5.navigate(opts);
|
|
138
138
|
},
|
|
139
139
|
setActiveChild: (id, init) => {
|
|
140
140
|
var _historyLayerRef$curr6;
|
|
141
|
-
return (_historyLayerRef$curr6 = historyLayerRef.current) === null || _historyLayerRef$curr6 === void 0 ? void 0 : _historyLayerRef$curr6.setActiveChild(id, init);
|
|
141
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setActiveChild is not allowed on this page') : (_historyLayerRef$curr6 = historyLayerRef.current) === null || _historyLayerRef$curr6 === void 0 ? void 0 : _historyLayerRef$curr6.setActiveChild(id, init);
|
|
142
142
|
},
|
|
143
143
|
setSegmentCount: n => {
|
|
144
144
|
var _historyLayerRef$curr7;
|
|
145
|
-
return (_historyLayerRef$curr7 = historyLayerRef.current) === null || _historyLayerRef$curr7 === void 0 ? void 0 : _historyLayerRef$curr7.setSegmentCount(n);
|
|
145
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setSegmentCount is not allowed on this page') : (_historyLayerRef$curr7 = historyLayerRef.current) === null || _historyLayerRef$curr7 === void 0 ? void 0 : _historyLayerRef$curr7.setSegmentCount(n);
|
|
146
146
|
},
|
|
147
147
|
addChangeListener: callback => {
|
|
148
148
|
var _historyLayerRef$curr8, _historyLayerRef$curr9;
|
|
149
|
+
if (!historyLayerRef.current) {
|
|
150
|
+
new Error('[chayns-api] addChangeListener is not allowed on this page');
|
|
151
|
+
}
|
|
149
152
|
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 : () => {};
|
|
150
153
|
return comlink.proxy(unsub);
|
|
151
154
|
},
|
|
152
155
|
addPopstateListener: callback => {
|
|
153
156
|
var _historyLayerRef$curr0, _historyLayerRef$curr1;
|
|
157
|
+
if (!historyLayerRef.current) {
|
|
158
|
+
new Error('[chayns-api] addPopstateListener is not allowed on this page');
|
|
159
|
+
}
|
|
154
160
|
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 : () => {};
|
|
155
161
|
return comlink.proxy(unsub);
|
|
156
162
|
},
|
|
157
163
|
addBlock: (callback, opts) => {
|
|
158
164
|
var _historyLayerRef$curr10, _historyLayerRef$curr11;
|
|
165
|
+
if (!historyLayerRef.current) {
|
|
166
|
+
new Error('[chayns-api] addBlock is not allowed on this page');
|
|
167
|
+
}
|
|
159
168
|
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 : () => {};
|
|
160
169
|
return comlink.proxy(unsub);
|
|
161
170
|
}
|
|
162
|
-
}
|
|
171
|
+
}
|
|
163
172
|
}
|
|
164
173
|
};
|
|
165
174
|
comlink.expose(obj, comlink.windowEndpoint(ref.current.contentWindow));
|
|
@@ -306,7 +306,7 @@ class FrameWrapper {
|
|
|
306
306
|
},
|
|
307
307
|
getHistoryLayer: () => {
|
|
308
308
|
if (!this._historyLayer) {
|
|
309
|
-
|
|
309
|
+
return null;
|
|
310
310
|
}
|
|
311
311
|
return this._historyLayer;
|
|
312
312
|
}
|
|
@@ -371,7 +371,10 @@ class FrameWrapper {
|
|
|
371
371
|
}, {});
|
|
372
372
|
const exposedHistory = exposed.history;
|
|
373
373
|
if (exposedHistory) {
|
|
374
|
-
|
|
374
|
+
let initialState = null;
|
|
375
|
+
try {
|
|
376
|
+
initialState = await exposedHistory.getInitialState();
|
|
377
|
+
} catch (ex) {}
|
|
375
378
|
if (initialState) {
|
|
376
379
|
this._historyLayer = new _FrameHistoryLayer.FrameHistoryLayer({
|
|
377
380
|
setRoute: (route, opts) => exposedHistory.setRoute(route, opts),
|
|
@@ -116,7 +116,7 @@ const ChaynsProvider = ({
|
|
|
116
116
|
rootLayerRef.current = getOrInitRootChaynsHistoryLayer(history === null || history === void 0 ? void 0 : history.url, history === null || history === void 0 ? void 0 : history.segmentCount).rootLayer;
|
|
117
117
|
}
|
|
118
118
|
const layer = (_ref2 = historyLayer !== null && historyLayer !== void 0 ? historyLayer : parentLayerRef.current) !== null && _ref2 !== void 0 ? _ref2 : rootLayerRef.current;
|
|
119
|
-
if (typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
|
|
119
|
+
if (layer && typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
|
|
120
120
|
layer.setSegmentCount(segmentCount);
|
|
121
121
|
}
|
|
122
122
|
setEffectiveLayer(layer);
|
|
@@ -93,7 +93,7 @@ const HostIframe = ({
|
|
|
93
93
|
if (eventTarget.current) eventTarget.current.addEventListener('data_update', e => e.detail && cb(e.detail));
|
|
94
94
|
},
|
|
95
95
|
getInitialData: () => currentDataRef.current,
|
|
96
|
-
history:
|
|
96
|
+
history: {
|
|
97
97
|
getInitialState: () => {
|
|
98
98
|
const l = historyLayerRef.current;
|
|
99
99
|
if (!l) return null;
|
|
@@ -110,48 +110,57 @@ const HostIframe = ({
|
|
|
110
110
|
},
|
|
111
111
|
setRoute: (route, opts) => {
|
|
112
112
|
var _historyLayerRef$curr;
|
|
113
|
-
return (_historyLayerRef$curr = historyLayerRef.current) === null || _historyLayerRef$curr === void 0 ? void 0 : _historyLayerRef$curr.setRoute(route, opts);
|
|
113
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setRoute is not allowed on this page') : (_historyLayerRef$curr = historyLayerRef.current) === null || _historyLayerRef$curr === void 0 ? void 0 : _historyLayerRef$curr.setRoute(route, opts);
|
|
114
114
|
},
|
|
115
115
|
setParams: (params, opts) => {
|
|
116
116
|
var _historyLayerRef$curr2;
|
|
117
|
-
return (_historyLayerRef$curr2 = historyLayerRef.current) === null || _historyLayerRef$curr2 === void 0 ? void 0 : _historyLayerRef$curr2.setParams(params, opts);
|
|
117
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setParams is not allowed on this page') : (_historyLayerRef$curr2 = historyLayerRef.current) === null || _historyLayerRef$curr2 === void 0 ? void 0 : _historyLayerRef$curr2.setParams(params, opts);
|
|
118
118
|
},
|
|
119
119
|
setHash: (hash, opts) => {
|
|
120
120
|
var _historyLayerRef$curr3;
|
|
121
|
-
return (_historyLayerRef$curr3 = historyLayerRef.current) === null || _historyLayerRef$curr3 === void 0 ? void 0 : _historyLayerRef$curr3.setHash(hash, opts);
|
|
121
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setHash is not allowed on this page') : (_historyLayerRef$curr3 = historyLayerRef.current) === null || _historyLayerRef$curr3 === void 0 ? void 0 : _historyLayerRef$curr3.setHash(hash, opts);
|
|
122
122
|
},
|
|
123
123
|
setState: (state, opts) => {
|
|
124
124
|
var _historyLayerRef$curr4;
|
|
125
|
-
return (_historyLayerRef$curr4 = historyLayerRef.current) === null || _historyLayerRef$curr4 === void 0 ? void 0 : _historyLayerRef$curr4.setState(state, opts);
|
|
125
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setState is not allowed on this page') : (_historyLayerRef$curr4 = historyLayerRef.current) === null || _historyLayerRef$curr4 === void 0 ? void 0 : _historyLayerRef$curr4.setState(state, opts);
|
|
126
126
|
},
|
|
127
127
|
navigate: opts => {
|
|
128
128
|
var _historyLayerRef$curr5;
|
|
129
|
-
return (_historyLayerRef$curr5 = historyLayerRef.current) === null || _historyLayerRef$curr5 === void 0 ? void 0 : _historyLayerRef$curr5.navigate(opts);
|
|
129
|
+
return !historyLayerRef.current ? new Error('[chayns-api] navigate is not allowed on this page') : (_historyLayerRef$curr5 = historyLayerRef.current) === null || _historyLayerRef$curr5 === void 0 ? void 0 : _historyLayerRef$curr5.navigate(opts);
|
|
130
130
|
},
|
|
131
131
|
setActiveChild: (id, init) => {
|
|
132
132
|
var _historyLayerRef$curr6;
|
|
133
|
-
return (_historyLayerRef$curr6 = historyLayerRef.current) === null || _historyLayerRef$curr6 === void 0 ? void 0 : _historyLayerRef$curr6.setActiveChild(id, init);
|
|
133
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setActiveChild is not allowed on this page') : (_historyLayerRef$curr6 = historyLayerRef.current) === null || _historyLayerRef$curr6 === void 0 ? void 0 : _historyLayerRef$curr6.setActiveChild(id, init);
|
|
134
134
|
},
|
|
135
135
|
setSegmentCount: n => {
|
|
136
136
|
var _historyLayerRef$curr7;
|
|
137
|
-
return (_historyLayerRef$curr7 = historyLayerRef.current) === null || _historyLayerRef$curr7 === void 0 ? void 0 : _historyLayerRef$curr7.setSegmentCount(n);
|
|
137
|
+
return !historyLayerRef.current ? new Error('[chayns-api] setSegmentCount is not allowed on this page') : (_historyLayerRef$curr7 = historyLayerRef.current) === null || _historyLayerRef$curr7 === void 0 ? void 0 : _historyLayerRef$curr7.setSegmentCount(n);
|
|
138
138
|
},
|
|
139
139
|
addChangeListener: callback => {
|
|
140
140
|
var _historyLayerRef$curr8, _historyLayerRef$curr9;
|
|
141
|
+
if (!historyLayerRef.current) {
|
|
142
|
+
new Error('[chayns-api] addChangeListener is not allowed on this page');
|
|
143
|
+
}
|
|
141
144
|
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
145
|
return comlink.proxy(unsub);
|
|
143
146
|
},
|
|
144
147
|
addPopstateListener: callback => {
|
|
145
148
|
var _historyLayerRef$curr0, _historyLayerRef$curr1;
|
|
149
|
+
if (!historyLayerRef.current) {
|
|
150
|
+
new Error('[chayns-api] addPopstateListener is not allowed on this page');
|
|
151
|
+
}
|
|
146
152
|
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
153
|
return comlink.proxy(unsub);
|
|
148
154
|
},
|
|
149
155
|
addBlock: (callback, opts) => {
|
|
150
156
|
var _historyLayerRef$curr10, _historyLayerRef$curr11;
|
|
157
|
+
if (!historyLayerRef.current) {
|
|
158
|
+
new Error('[chayns-api] addBlock is not allowed on this page');
|
|
159
|
+
}
|
|
151
160
|
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
161
|
return comlink.proxy(unsub);
|
|
153
162
|
}
|
|
154
|
-
}
|
|
163
|
+
}
|
|
155
164
|
}
|
|
156
165
|
};
|
|
157
166
|
comlink.expose(obj, comlink.windowEndpoint(ref.current.contentWindow));
|
|
@@ -302,7 +302,7 @@ export class FrameWrapper {
|
|
|
302
302
|
},
|
|
303
303
|
getHistoryLayer: () => {
|
|
304
304
|
if (!this._historyLayer) {
|
|
305
|
-
|
|
305
|
+
return null;
|
|
306
306
|
}
|
|
307
307
|
return this._historyLayer;
|
|
308
308
|
}
|
|
@@ -375,7 +375,10 @@ export class FrameWrapper {
|
|
|
375
375
|
}, {});
|
|
376
376
|
const exposedHistory = exposed.history;
|
|
377
377
|
if (exposedHistory) {
|
|
378
|
-
|
|
378
|
+
let initialState = null;
|
|
379
|
+
try {
|
|
380
|
+
initialState = await exposedHistory.getInitialState();
|
|
381
|
+
} catch (ex) {}
|
|
379
382
|
if (initialState) {
|
|
380
383
|
this._historyLayer = new FrameHistoryLayer({
|
|
381
384
|
setRoute: (route, opts) => exposedHistory.setRoute(route, opts),
|
|
@@ -467,7 +467,7 @@ export interface ChaynsReactFunctions {
|
|
|
467
467
|
destination: string;
|
|
468
468
|
isPermanent?: boolean;
|
|
469
469
|
}) => Promise<void>;
|
|
470
|
-
getHistoryLayer(): ChaynsHistoryLayer;
|
|
470
|
+
getHistoryLayer(): ChaynsHistoryLayer | null;
|
|
471
471
|
}
|
|
472
472
|
export type ChaynsReactCustomFunctions = {
|
|
473
473
|
[key: string]: (...args: any[]) => Promise<any>;
|