@thoughtbot/superglue 0.53.3 → 0.54.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.
- package/.babelrc.js +15 -0
- package/.prettierignore +6 -0
- package/.prettierrc +5 -0
- package/.tool-versions +1 -0
- package/LICENSE +21 -0
- package/dist/action_creators.d.mts +25 -0
- package/dist/action_creators.mjs +17 -0
- package/dist/action_creators.mjs.map +1 -0
- package/dist/chunk-MNVGYKSD.mjs +779 -0
- package/dist/chunk-MNVGYKSD.mjs.map +1 -0
- package/dist/cjs/action_creators.cjs +597 -0
- package/dist/cjs/action_creators.cjs.map +1 -0
- package/dist/cjs/superglue.cjs +1278 -0
- package/dist/cjs/superglue.cjs.map +1 -0
- package/dist/index-DfWsUSqv.d.mts +246 -0
- package/dist/superglue.d.mts +65 -0
- package/dist/superglue.mjs +613 -0
- package/dist/superglue.mjs.map +1 -0
- package/package.json +60 -22
- package/tsconfig.json +15 -0
- package/tsup.config.ts +29 -0
- package/typedoc.json +30 -0
- package/README.md +0 -126
- package/action_creators/index.js +0 -160
- package/action_creators/requests.js +0 -236
- package/actions.js +0 -17
- package/components/Nav.js +0 -258
- package/config.js +0 -8
- package/index.js +0 -265
- package/middleware.js +0 -78
- package/reducers/index.js +0 -263
- package/utils/helpers.js +0 -38
- package/utils/immutability.js +0 -170
- package/utils/index.js +0 -59
- package/utils/react.js +0 -47
- package/utils/request.js +0 -142
- package/utils/ujs.js +0 -133
- package/utils/url.js +0 -93
- package/utils/window.js +0 -15
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.remote = remote;
|
|
5
|
-
exports.visit = visit;
|
|
6
|
-
|
|
7
|
-
var _utils = require("../utils");
|
|
8
|
-
|
|
9
|
-
var _actions = require("../actions");
|
|
10
|
-
|
|
11
|
-
var _index = require("./index");
|
|
12
|
-
|
|
13
|
-
function beforeVisit(payload) {
|
|
14
|
-
return {
|
|
15
|
-
type: _actions.BEFORE_VISIT,
|
|
16
|
-
payload: payload
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function beforeRemote(payload) {
|
|
21
|
-
return {
|
|
22
|
-
type: _actions.BEFORE_REMOTE,
|
|
23
|
-
payload: payload
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function beforeFetch(payload) {
|
|
28
|
-
return {
|
|
29
|
-
type: _actions.BEFORE_FETCH,
|
|
30
|
-
payload: payload
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function handleError(err) {
|
|
35
|
-
return {
|
|
36
|
-
type: _actions.SUPERGLUE_ERROR,
|
|
37
|
-
payload: {
|
|
38
|
-
message: err.message
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function handleFetchErr(err, fetchArgs, dispatch) {
|
|
44
|
-
err.fetchArgs = fetchArgs;
|
|
45
|
-
err.url = fetchArgs[0];
|
|
46
|
-
err.pageKey = (0, _utils.urlToPageKey)(fetchArgs[0]);
|
|
47
|
-
dispatch(handleError(err));
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function buildMeta(pageKey, page, state) {
|
|
52
|
-
var prevAssets = state.assets;
|
|
53
|
-
var nextAssets = page.assets;
|
|
54
|
-
return {
|
|
55
|
-
pageKey: pageKey,
|
|
56
|
-
page: page,
|
|
57
|
-
componentIdentifier: page.componentIdentifier,
|
|
58
|
-
needsRefresh: (0, _utils.needsRefresh)(prevAssets, nextAssets)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function remote(path, _temp) {
|
|
63
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
64
|
-
_ref$method = _ref.method,
|
|
65
|
-
method = _ref$method === void 0 ? 'GET' : _ref$method,
|
|
66
|
-
headers = _ref.headers,
|
|
67
|
-
_ref$body = _ref.body,
|
|
68
|
-
body = _ref$body === void 0 ? '' : _ref$body,
|
|
69
|
-
pageKey = _ref.pageKey,
|
|
70
|
-
_ref$beforeSave = _ref.beforeSave,
|
|
71
|
-
beforeSave = _ref$beforeSave === void 0 ? function (prevPage, receivedPage) {
|
|
72
|
-
return receivedPage;
|
|
73
|
-
} : _ref$beforeSave;
|
|
74
|
-
|
|
75
|
-
path = (0, _utils.withoutBusters)(path);
|
|
76
|
-
pageKey = pageKey && (0, _utils.urlToPageKey)(pageKey);
|
|
77
|
-
return function (dispatch, getState) {
|
|
78
|
-
var fetchArgs = (0, _utils.argsForFetch)(getState, path, {
|
|
79
|
-
method: method,
|
|
80
|
-
headers: headers,
|
|
81
|
-
body: body
|
|
82
|
-
});
|
|
83
|
-
pageKey = pageKey || getState().superglue.currentPageKey;
|
|
84
|
-
var currentPageKey = getState().superglue.currentPageKey;
|
|
85
|
-
dispatch(beforeRemote({
|
|
86
|
-
currentPageKey: currentPageKey,
|
|
87
|
-
fetchArgs: fetchArgs
|
|
88
|
-
}));
|
|
89
|
-
dispatch(beforeFetch({
|
|
90
|
-
fetchArgs: fetchArgs
|
|
91
|
-
}));
|
|
92
|
-
return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref2) {
|
|
93
|
-
var _pages$currentPageKey;
|
|
94
|
-
|
|
95
|
-
var rsp = _ref2.rsp,
|
|
96
|
-
json = _ref2.json;
|
|
97
|
-
|
|
98
|
-
var _getState = getState(),
|
|
99
|
-
superglue = _getState.superglue,
|
|
100
|
-
_getState$pages = _getState.pages,
|
|
101
|
-
pages = _getState$pages === void 0 ? {} : _getState$pages;
|
|
102
|
-
|
|
103
|
-
var meta = Object.assign({}, buildMeta(pageKey, json, superglue), {
|
|
104
|
-
redirected: rsp.redirected,
|
|
105
|
-
rsp: rsp,
|
|
106
|
-
fetchArgs: fetchArgs
|
|
107
|
-
});
|
|
108
|
-
var willReplaceCurrent = pageKey == currentPageKey;
|
|
109
|
-
var existingId = (_pages$currentPageKey = pages[currentPageKey]) == null ? void 0 : _pages$currentPageKey.componentIdentifier;
|
|
110
|
-
var receivedId = json.componentIdentifier;
|
|
111
|
-
|
|
112
|
-
if (willReplaceCurrent && !!existingId && existingId != receivedId) {
|
|
113
|
-
console.warn("You're about replace an existing page located at pages[\"" + currentPageKey + "\"]\nthat has the componentIdentifier \"" + existingId + "\" with the contents of a\nreceived page that has a componentIdentifier of \"" + receivedId + "\".\n\nThis can happen if you're using data-sg-remote or remote but your response\nredirected to a completely different page. Since remote requests do not\nnavigate or change the current page component, your current page component may\nreceive a shape that is unexpected and cause issues with rendering.\n\nConsider using data-sg-visit, the visit function, or redirect_back.");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
var page = beforeSave(pages[pageKey], json);
|
|
117
|
-
return dispatch((0, _index.saveAndProcessPage)(pageKey, page)).then(function () {
|
|
118
|
-
meta.pageKey = pageKey;
|
|
119
|
-
return meta;
|
|
120
|
-
});
|
|
121
|
-
})["catch"](function (e) {
|
|
122
|
-
return handleFetchErr(e, fetchArgs, dispatch);
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
var lastVisitController = {
|
|
128
|
-
abort: function abort() {}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
function visit(path, _temp2) {
|
|
132
|
-
var _ref3 = _temp2 === void 0 ? {} : _temp2,
|
|
133
|
-
_ref3$method = _ref3.method,
|
|
134
|
-
method = _ref3$method === void 0 ? 'GET' : _ref3$method,
|
|
135
|
-
headers = _ref3.headers,
|
|
136
|
-
_ref3$body = _ref3.body,
|
|
137
|
-
body = _ref3$body === void 0 ? '' : _ref3$body,
|
|
138
|
-
placeholderKey = _ref3.placeholderKey,
|
|
139
|
-
_ref3$beforeSave = _ref3.beforeSave,
|
|
140
|
-
beforeSave = _ref3$beforeSave === void 0 ? function (prevPage, receivedPage) {
|
|
141
|
-
return receivedPage;
|
|
142
|
-
} : _ref3$beforeSave,
|
|
143
|
-
_ref3$revisit = _ref3.revisit,
|
|
144
|
-
revisit = _ref3$revisit === void 0 ? false : _ref3$revisit;
|
|
145
|
-
|
|
146
|
-
path = (0, _utils.withoutBusters)(path);
|
|
147
|
-
var pageKey = (0, _utils.urlToPageKey)(path);
|
|
148
|
-
return function (dispatch, getState) {
|
|
149
|
-
placeholderKey = placeholderKey && (0, _utils.urlToPageKey)(placeholderKey);
|
|
150
|
-
var hasPlaceholder = !!getState().pages[placeholderKey];
|
|
151
|
-
|
|
152
|
-
if (placeholderKey && hasPlaceholder) {
|
|
153
|
-
dispatch((0, _index.copyPage)({
|
|
154
|
-
from: placeholderKey,
|
|
155
|
-
to: pageKey
|
|
156
|
-
}));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (placeholderKey && !hasPlaceholder) {
|
|
160
|
-
console.warn("Could not find placeholder with key " + placeholderKey + " in state. The props_at param will be ignored");
|
|
161
|
-
path = (0, _utils.removePropsAt)(path);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (!placeholderKey && (0, _utils.hasPropsAt)(path)) {
|
|
165
|
-
console.warn("visit was called with props_at param in the path " + path + ", this will be ignore unless you provide a placeholder.");
|
|
166
|
-
path = (0, _utils.removePropsAt)(path);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var controller = new AbortController();
|
|
170
|
-
var signal = controller.signal;
|
|
171
|
-
var fetchArgs = (0, _utils.argsForFetch)(getState, path, {
|
|
172
|
-
headers: headers,
|
|
173
|
-
body: body,
|
|
174
|
-
method: method,
|
|
175
|
-
signal: signal
|
|
176
|
-
});
|
|
177
|
-
var currentPageKey = getState().superglue.currentPageKey;
|
|
178
|
-
dispatch(beforeVisit({
|
|
179
|
-
currentPageKey: currentPageKey,
|
|
180
|
-
fetchArgs: fetchArgs
|
|
181
|
-
}));
|
|
182
|
-
dispatch(beforeFetch({
|
|
183
|
-
fetchArgs: fetchArgs
|
|
184
|
-
}));
|
|
185
|
-
lastVisitController.abort();
|
|
186
|
-
lastVisitController = controller;
|
|
187
|
-
return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref4) {
|
|
188
|
-
var rsp = _ref4.rsp,
|
|
189
|
-
json = _ref4.json;
|
|
190
|
-
|
|
191
|
-
var _getState2 = getState(),
|
|
192
|
-
superglue = _getState2.superglue,
|
|
193
|
-
_getState2$pages = _getState2.pages,
|
|
194
|
-
pages = _getState2$pages === void 0 ? {} : _getState2$pages;
|
|
195
|
-
|
|
196
|
-
var meta = Object.assign({}, buildMeta(pageKey, json, superglue), {
|
|
197
|
-
redirected: rsp.redirected,
|
|
198
|
-
rsp: rsp,
|
|
199
|
-
fetchArgs: fetchArgs
|
|
200
|
-
});
|
|
201
|
-
meta.suggestedAction = 'push';
|
|
202
|
-
|
|
203
|
-
if (!rsp.redirected && fetchArgs[1].method != 'GET') {
|
|
204
|
-
meta.suggestedAction = 'replace';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (revisit && fetchArgs[1].method == 'GET') {
|
|
208
|
-
if (rsp.redirected) {
|
|
209
|
-
meta.suggestedAction = 'replace';
|
|
210
|
-
} else {
|
|
211
|
-
meta.suggestedAction = 'none';
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (method !== 'GET') {
|
|
216
|
-
var contentLocation = rsp.headers.get('content-location');
|
|
217
|
-
|
|
218
|
-
if (contentLocation) {
|
|
219
|
-
pageKey = (0, _utils.urlToPageKey)(contentLocation);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (rsp.redirected) {
|
|
224
|
-
pageKey = (0, _utils.urlToPageKey)(rsp.url);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
var page = beforeSave(pages[pageKey], json);
|
|
228
|
-
return dispatch((0, _index.saveAndProcessPage)(pageKey, page)).then(function () {
|
|
229
|
-
meta.pageKey = pageKey;
|
|
230
|
-
return meta;
|
|
231
|
-
});
|
|
232
|
-
})["catch"](function (e) {
|
|
233
|
-
return handleFetchErr(e, fetchArgs, dispatch);
|
|
234
|
-
});
|
|
235
|
-
};
|
|
236
|
-
}
|
package/actions.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.UPDATE_FRAGMENTS = exports.SUPERGLUE_ERROR = exports.SET_CSRF_TOKEN = exports.SAVE_RESPONSE = exports.REMOVE_PAGE = exports.HISTORY_CHANGE = exports.HANDLE_GRAFT = exports.GRAFTING_SUCCESS = exports.GRAFTING_ERROR = exports.COPY_PAGE = exports.BEFORE_VISIT = exports.BEFORE_REMOTE = exports.BEFORE_FETCH = void 0;
|
|
5
|
-
var BEFORE_FETCH = exports.BEFORE_FETCH = '@@superglue/BEFORE_FETCH';
|
|
6
|
-
var BEFORE_VISIT = exports.BEFORE_VISIT = '@@superglue/BEFORE_VISIT';
|
|
7
|
-
var BEFORE_REMOTE = exports.BEFORE_REMOTE = '@@superglue/BEFORE_REMOTE';
|
|
8
|
-
var SAVE_RESPONSE = exports.SAVE_RESPONSE = '@@superglue/SAVE_RESPONSE';
|
|
9
|
-
var HANDLE_GRAFT = exports.HANDLE_GRAFT = '@@superglue/HANDLE_GRAFT';
|
|
10
|
-
var SUPERGLUE_ERROR = exports.SUPERGLUE_ERROR = '@@superglue/ERROR';
|
|
11
|
-
var GRAFTING_ERROR = exports.GRAFTING_ERROR = '@@superglue/GRAFTING_ERROR';
|
|
12
|
-
var GRAFTING_SUCCESS = exports.GRAFTING_SUCCESS = '@@superglue/GRAFTING_SUCCESS';
|
|
13
|
-
var HISTORY_CHANGE = exports.HISTORY_CHANGE = '@@superglue/HISTORY_CHANGE';
|
|
14
|
-
var SET_CSRF_TOKEN = exports.SET_CSRF_TOKEN = '@@superglue/SET_CSRF_TOKEN';
|
|
15
|
-
var REMOVE_PAGE = exports.REMOVE_PAGE = '@@superglue/REMOVE_PAGE';
|
|
16
|
-
var COPY_PAGE = exports.COPY_PAGE = '@@superglue/COPY_PAGE';
|
|
17
|
-
var UPDATE_FRAGMENTS = exports.UPDATE_FRAGMENTS = '@@superglue/UPDATE_FRAGMENTS';
|
package/components/Nav.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports["default"] = void 0;
|
|
5
|
-
|
|
6
|
-
var _react = _interopRequireDefault(require("react"));
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
var _actions = require("../actions");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
function _extends() { _extends = Object.assign || 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); }
|
|
15
|
-
|
|
16
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
-
|
|
18
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
19
|
-
|
|
20
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
-
|
|
22
|
-
var Nav = /*#__PURE__*/function (_React$Component) {
|
|
23
|
-
_inheritsLoose(Nav, _React$Component);
|
|
24
|
-
|
|
25
|
-
function Nav(props) {
|
|
26
|
-
var _this;
|
|
27
|
-
|
|
28
|
-
_this = _React$Component.call(this, props) || this;
|
|
29
|
-
var _this$props = _this.props,
|
|
30
|
-
history = _this$props.history,
|
|
31
|
-
initialPageKey = _this$props.initialPageKey;
|
|
32
|
-
_this.history = history;
|
|
33
|
-
_this.navigateTo = _this.navigateTo.bind(_assertThisInitialized(_this));
|
|
34
|
-
_this.scrollTo = _this.scrollTo.bind(_assertThisInitialized(_this));
|
|
35
|
-
_this.onHistoryChange = _this.onHistoryChange.bind(_assertThisInitialized(_this));
|
|
36
|
-
_this.state = {
|
|
37
|
-
pageKey: initialPageKey,
|
|
38
|
-
ownProps: {}
|
|
39
|
-
};
|
|
40
|
-
_this.hasWindow = typeof window !== 'undefined';
|
|
41
|
-
return _this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var _proto = Nav.prototype;
|
|
45
|
-
|
|
46
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
47
|
-
this.unsubscribeHistory = this.history.listen(this.onHistoryChange);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
51
|
-
this.unsubscribeHistory();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
_proto.navigateTo = function navigateTo(path, _temp) {
|
|
55
|
-
var _ref = _temp === void 0 ? {
|
|
56
|
-
action: 'push',
|
|
57
|
-
ownProps: {}
|
|
58
|
-
} : _temp,
|
|
59
|
-
action = _ref.action,
|
|
60
|
-
ownProps = _ref.ownProps;
|
|
61
|
-
|
|
62
|
-
if (action === 'none') {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
path = (0, _utils.pathWithoutBZParams)(path);
|
|
67
|
-
var nextPageKey = (0, _utils.urlToPageKey)(path);
|
|
68
|
-
var store = this.props.store;
|
|
69
|
-
var hasPage = !!store.getState().pages[nextPageKey];
|
|
70
|
-
|
|
71
|
-
if (hasPage) {
|
|
72
|
-
var location = this.history.location;
|
|
73
|
-
var prevPageKey = location.state.pageKey;
|
|
74
|
-
var historyArgs = [path, {
|
|
75
|
-
pageKey: nextPageKey,
|
|
76
|
-
superglue: true,
|
|
77
|
-
posY: 0,
|
|
78
|
-
posX: 0
|
|
79
|
-
}];
|
|
80
|
-
|
|
81
|
-
if (action === 'push') {
|
|
82
|
-
var _this$history;
|
|
83
|
-
|
|
84
|
-
if (this.hasWindow) {
|
|
85
|
-
this.history.replace({
|
|
86
|
-
pathname: location.pathname,
|
|
87
|
-
search: location.search,
|
|
88
|
-
hash: location.hash
|
|
89
|
-
}, Object.assign({}, location.state, {
|
|
90
|
-
posY: window.pageYOffset,
|
|
91
|
-
posX: window.pageXOffset
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
(_this$history = this.history).push.apply(_this$history, historyArgs);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (action === 'replace') {
|
|
99
|
-
var _this$history2;
|
|
100
|
-
|
|
101
|
-
(_this$history2 = this.history).replace.apply(_this$history2, historyArgs);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.setState({
|
|
105
|
-
pageKey: nextPageKey,
|
|
106
|
-
ownProps: ownProps
|
|
107
|
-
});
|
|
108
|
-
this.scrollTo(0, 0);
|
|
109
|
-
|
|
110
|
-
if (action === 'replace' && prevPageKey && prevPageKey !== nextPageKey) {
|
|
111
|
-
store.dispatch({
|
|
112
|
-
type: _actions.REMOVE_PAGE,
|
|
113
|
-
payload: {
|
|
114
|
-
pageKey: prevPageKey
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return true;
|
|
120
|
-
} else {
|
|
121
|
-
console.warn("`navigateTo` was called , but could not find.\n the pageKey in the store. This may happen when the wrong\n content_location was set in your non-get controller action.\n No navigation will take place");
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
_proto.scrollTo = function scrollTo(posX, posY) {
|
|
127
|
-
this.hasWindow && window.scrollTo(posX, posY);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
_proto.onHistoryChange = function onHistoryChange(_ref2) {
|
|
131
|
-
var _this2 = this;
|
|
132
|
-
|
|
133
|
-
var location = _ref2.location,
|
|
134
|
-
action = _ref2.action;
|
|
135
|
-
var _this$props2 = this.props,
|
|
136
|
-
store = _this$props2.store,
|
|
137
|
-
visit = _this$props2.visit;
|
|
138
|
-
var pathname = location.pathname,
|
|
139
|
-
search = location.search,
|
|
140
|
-
hash = location.hash,
|
|
141
|
-
state = location.state;
|
|
142
|
-
|
|
143
|
-
if (state && state.superglue) {
|
|
144
|
-
store.dispatch({
|
|
145
|
-
type: _actions.HISTORY_CHANGE,
|
|
146
|
-
payload: {
|
|
147
|
-
pathname: pathname,
|
|
148
|
-
search: search,
|
|
149
|
-
hash: hash
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
if (action !== 'POP') {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
var pageKey = state.pageKey,
|
|
158
|
-
posX = state.posX,
|
|
159
|
-
posY = state.posY;
|
|
160
|
-
var containsKey = !!store.getState().pages[pageKey];
|
|
161
|
-
|
|
162
|
-
if (containsKey) {
|
|
163
|
-
var restoreStrategy = store.getState().pages[pageKey].restoreStrategy;
|
|
164
|
-
|
|
165
|
-
switch (restoreStrategy) {
|
|
166
|
-
case 'fromCacheOnly':
|
|
167
|
-
this.setState({
|
|
168
|
-
pageKey: pageKey
|
|
169
|
-
});
|
|
170
|
-
this.scrollTo(posX, posY);
|
|
171
|
-
break;
|
|
172
|
-
|
|
173
|
-
case 'fromCacheAndRevisitInBackground':
|
|
174
|
-
this.setState({
|
|
175
|
-
pageKey: pageKey
|
|
176
|
-
});
|
|
177
|
-
this.scrollTo(posX, posY);
|
|
178
|
-
visit(pageKey, {
|
|
179
|
-
revisit: true
|
|
180
|
-
});
|
|
181
|
-
break;
|
|
182
|
-
|
|
183
|
-
case 'revisitOnly':
|
|
184
|
-
default:
|
|
185
|
-
visit(pageKey, {
|
|
186
|
-
revisit: true
|
|
187
|
-
}).then(function (meta) {
|
|
188
|
-
if (meta === undefined) {
|
|
189
|
-
console.warn("scoll restoration was skipped. Your visit's then funtion\n should return the meta object it recieved if you want your\n application to restore the page's previous scroll.");
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (!!meta && meta.suggestedAction === 'none') {
|
|
193
|
-
_this2.setState({
|
|
194
|
-
pageKey: pageKey
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
_this2.scrollTo(posX, posY);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
visit(pageKey, {
|
|
203
|
-
revisit: true
|
|
204
|
-
}).then(function (meta) {
|
|
205
|
-
if (meta === undefined) {
|
|
206
|
-
console.warn("scoll restoration was skipped. Your visit's then funtion\n should return the meta object it recieved if you want your\n application to restore the page's previous scroll.");
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (!!meta && meta.suggestedAction === 'none') {
|
|
210
|
-
_this2.setState({
|
|
211
|
-
pageKey: pageKey
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
_this2.scrollTo(posX, posY);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
_proto.notFound = function notFound(identifier) {
|
|
222
|
-
var reminder = '';
|
|
223
|
-
|
|
224
|
-
if (!identifier) {
|
|
225
|
-
reminder = 'Did you forget to add `json.componentIdentifier` in your application.json.props layout?';
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
var error = new Error("Superglue Nav component was looking for " + identifier + " but could not find it in your mapping. " + reminder);
|
|
229
|
-
throw error;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
_proto.render = function render() {
|
|
233
|
-
var _this$props3 = this.props,
|
|
234
|
-
store = _this$props3.store,
|
|
235
|
-
visit = _this$props3.visit,
|
|
236
|
-
remote = _this$props3.remote;
|
|
237
|
-
var _this$state = this.state,
|
|
238
|
-
pageKey = _this$state.pageKey,
|
|
239
|
-
ownProps = _this$state.ownProps;
|
|
240
|
-
var componentIdentifier = store.getState().pages[pageKey].componentIdentifier;
|
|
241
|
-
var Component = this.props.mapping[componentIdentifier];
|
|
242
|
-
|
|
243
|
-
if (Component) {
|
|
244
|
-
return /*#__PURE__*/_react["default"].createElement(Component, _extends({
|
|
245
|
-
pageKey: pageKey,
|
|
246
|
-
navigateTo: this.navigateTo,
|
|
247
|
-
visit: visit,
|
|
248
|
-
remote: remote
|
|
249
|
-
}, ownProps));
|
|
250
|
-
} else {
|
|
251
|
-
this.notFound(componentIdentifier);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
return Nav;
|
|
256
|
-
}(_react["default"].Component);
|
|
257
|
-
|
|
258
|
-
var _default = exports["default"] = Nav;
|