chayns-api 3.1.0 → 3.1.1
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.
|
@@ -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));
|
|
@@ -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));
|