@rancher/shell 0.3.5 → 0.3.7
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/assets/images/providers/outscale.svg +19 -0
- package/assets/styles/base/_basic.scss +18 -0
- package/assets/styles/base/_mixins.scss +0 -11
- package/assets/styles/base/_variables.scss +2 -4
- package/assets/styles/global/_button.scss +12 -2
- package/assets/translations/en-us.yaml +35 -1
- package/assets/translations/zh-hans.yaml +30 -10
- package/chart/gatekeeper.vue +3 -2
- package/chart/istio.vue +29 -3
- package/components/BrandImage.vue +1 -4
- package/components/Carousel.vue +85 -37
- package/components/EtcdInfoBanner.vue +7 -3
- package/components/ExplorerMembers.vue +100 -5
- package/components/ExplorerProjectsNamespaces.vue +32 -2
- package/components/GrafanaDashboard.vue +9 -2
- package/components/SortableTable/index.vue +23 -11
- package/components/SortableTable/selection.js +58 -50
- package/components/Wizard.vue +4 -2
- package/components/auth/AuthBanner.vue +6 -0
- package/components/auth/RoleDetailEdit.vue +2 -2
- package/components/form/HookOption.vue +14 -10
- package/components/form/Labels.vue +32 -27
- package/components/form/MatchExpressions.vue +2 -2
- package/components/form/Members/ClusterPermissionsEditor.vue +32 -7
- package/components/form/NameNsDescription.vue +1 -1
- package/components/form/ProjectMemberEditor.vue +46 -21
- package/components/form/Tolerations.vue +4 -1
- package/components/form/ValueFromResource.vue +14 -9
- package/components/form/WorkloadPorts.vue +2 -2
- package/components/form/__tests__/NameNsDescription.ts +27 -0
- package/components/formatter/WorkloadHealthScale.vue +8 -2
- package/components/nav/NamespaceFilter.vue +8 -0
- package/{nuxt/components → components/nuxt}/nuxt.js +1 -1
- package/{nuxt → config}/middleware.js +8 -8
- package/config/product/explorer.js +24 -3
- package/config/query-params.js +1 -0
- package/config/router.js +1 -1
- package/{nuxt → config}/store.js +82 -79
- package/config/table-headers.js +46 -12
- package/config/types.js +7 -0
- package/core/plugin.ts +4 -2
- package/core/types.ts +258 -1
- package/creators/app/files/tsconfig.json +0 -1
- package/creators/app/files/vue.config.js +0 -1
- package/creators/pkg/files/.github/workflows/build-extension.yml +3 -4
- package/creators/pkg/files/tsconfig.json +0 -1
- package/creators/pkg/pkg.package.json +3 -3
- package/detail/constraints.gatekeeper.sh.constraint.vue +14 -7
- package/detail/fleet.cattle.io.clustergroup.vue +7 -1
- package/edit/auth/ldap/config.vue +21 -1
- package/edit/auth/saml.vue +132 -37
- package/edit/fleet.cattle.io.gitrepo.vue +16 -1
- package/edit/logging.banzaicloud.io.output/index.vue +18 -5
- package/edit/logging.banzaicloud.io.output/providers/loki.vue +1 -0
- package/edit/namespace.vue +12 -8
- package/edit/provisioning.cattle.io.cluster/MachinePool.vue +11 -4
- package/edit/provisioning.cattle.io.cluster/import.vue +23 -25
- package/edit/provisioning.cattle.io.cluster/rke2.vue +96 -18
- package/edit/workload/mixins/workload.js +6 -7
- package/edit/workload/storage/Mount.vue +3 -3
- package/initialize/App.js +206 -0
- package/{nuxt → initialize}/client.js +406 -360
- package/{nuxt → initialize}/index.js +21 -22
- package/layouts/standalone.vue +13 -0
- package/list/catalog.cattle.io.clusterrepo.vue +1 -0
- package/list/rbac.authorization.k8s.io.clusterrolebinding.vue +48 -0
- package/list/workload.vue +6 -4
- package/mixins/chart.js +29 -1
- package/mixins/fetch.client.js +95 -0
- package/{nuxt/mixins → mixins}/fetch.server.js +30 -26
- package/mixins/labeled-form-element.ts +2 -2
- package/models/constraints.gatekeeper.sh.constraint.js +37 -0
- package/models/pod.js +4 -0
- package/models/rbac.authorization.k8s.io.clusterrolebinding.js +16 -0
- package/models/rbac.authorization.k8s.io.rolebinding.js +16 -0
- package/package.json +9 -13
- package/pages/c/_cluster/apps/charts/install.vue +61 -39
- package/pages/diagnostic.vue +32 -25
- package/pages/rio/mesh.vue +1 -2
- package/pkg/tsconfig.json +0 -1
- package/plugins/clean-html-directive.js +3 -0
- package/plugins/dashboard-store/index.js +1 -1
- package/plugins/plugin.js +0 -14
- package/plugins/portal-vue.js +4 -0
- package/rancher-components/components/Banner/Banner.test.ts +3 -5
- package/rancher-components/components/Banner/Banner.vue +1 -0
- package/rancher-components/components/Form/Radio/RadioButton.test.ts +31 -0
- package/rancher-components/components/Form/Radio/RadioButton.vue +14 -3
- package/scripts/extension/publish +42 -23
- package/scripts/serve-pkgs +6 -2
- package/store/type-map.js +1 -1
- package/tsconfig.json +0 -1
- package/types/rancher/index.d.ts +2 -0
- package/types/shell/index.d.ts +353 -284
- package/utils/__tests__/grafana.test.ts +44 -0
- package/utils/axios.js +190 -0
- package/{nuxt → utils}/cookie-universal-nuxt.js +7 -6
- package/utils/dom.js +15 -0
- package/utils/gc/gc.ts +1 -1
- package/utils/grafana.js +35 -16
- package/{nuxt/utils.js → utils/nuxt.js} +265 -236
- package/utils/router.scrollBehavior.js +1 -1
- package/vue.config.js +30 -19
- package/nuxt/App.js +0 -210
- package/nuxt/axios.js +0 -186
- package/nuxt/empty.js +0 -1
- package/nuxt/jsonp.js +0 -82
- package/nuxt/loading.html +0 -39
- package/nuxt/mixins/fetch.client.js +0 -90
- package/nuxt/portal-vue.js +0 -4
- package/nuxt/server.js +0 -312
- package/nuxt/views/app.template.html +0 -9
- package/nuxt/views/error.html +0 -23
- package/plugins/dashboard-store/extensions.js +0 -22
- /package/{nuxt/components → components/nuxt}/nuxt-build-indicator.vue +0 -0
- /package/{nuxt/components → components/nuxt}/nuxt-child.js +0 -0
- /package/{nuxt/components → components/nuxt}/nuxt-error.vue +0 -0
- /package/{nuxt/components → components/nuxt}/nuxt-link.client.js +0 -0
- /package/{nuxt/components → components/nuxt}/nuxt-link.server.js +0 -0
- /package/{nuxt/components → components/nuxt}/nuxt-loading.vue +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Vue from 'vue'
|
|
2
|
-
import fetch from 'unfetch'
|
|
3
|
-
import middleware from '
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
import fetch from 'unfetch';
|
|
3
|
+
import middleware from '../config/middleware.js';
|
|
4
4
|
import {
|
|
5
5
|
applyAsyncData,
|
|
6
6
|
promisify,
|
|
@@ -11,154 +11,167 @@ import {
|
|
|
11
11
|
getMatchedComponentsInstances,
|
|
12
12
|
flatMapComponents,
|
|
13
13
|
setContext,
|
|
14
|
-
getLocation,
|
|
15
14
|
compile,
|
|
16
15
|
getQueryDiff,
|
|
17
16
|
globalHandleError,
|
|
18
17
|
isSamePath,
|
|
19
18
|
urlJoin
|
|
20
|
-
} from '
|
|
21
|
-
import { createApp, NuxtError } from './index.js'
|
|
22
|
-
import fetchMixin from '
|
|
23
|
-
import NuxtLink from '
|
|
19
|
+
} from '../utils/nuxt.js';
|
|
20
|
+
import { createApp, NuxtError } from './index.js';
|
|
21
|
+
import fetchMixin from '../mixins/fetch.client';
|
|
22
|
+
import NuxtLink from '../components/nuxt/nuxt-link.client.js'; // should be included after ./index.js
|
|
24
23
|
|
|
25
24
|
// Fetch mixin
|
|
26
25
|
if (!Vue.__nuxt__fetch__mixin__) {
|
|
27
|
-
Vue.mixin(fetchMixin)
|
|
28
|
-
Vue.__nuxt__fetch__mixin__ = true
|
|
26
|
+
Vue.mixin(fetchMixin);
|
|
27
|
+
Vue.__nuxt__fetch__mixin__ = true;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
// Component: <NuxtLink>
|
|
32
|
-
Vue.component(NuxtLink.name, NuxtLink)
|
|
33
|
-
Vue.component('NLink', NuxtLink)
|
|
31
|
+
Vue.component(NuxtLink.name, NuxtLink);
|
|
32
|
+
Vue.component('NLink', NuxtLink);
|
|
34
33
|
|
|
35
|
-
if (!global.fetch) {
|
|
34
|
+
if (!global.fetch) {
|
|
35
|
+
global.fetch = fetch;
|
|
36
|
+
}
|
|
36
37
|
|
|
37
38
|
// Global shared references
|
|
38
|
-
let _lastPaths = []
|
|
39
|
-
let app
|
|
40
|
-
let router
|
|
41
|
-
let store
|
|
39
|
+
let _lastPaths = [];
|
|
40
|
+
let app;
|
|
41
|
+
let router;
|
|
42
42
|
|
|
43
43
|
// Try to rehydrate SSR data from window
|
|
44
|
-
const NUXT = window.__NUXT__ || {}
|
|
44
|
+
const NUXT = window.__NUXT__ || {};
|
|
45
|
+
|
|
46
|
+
const $config = nuxt.publicRuntimeConfig || {}; // eslint-disable-line no-undef
|
|
45
47
|
|
|
46
|
-
const $config = nuxt.publicRuntimeConfig || {}
|
|
47
48
|
if ($config._app) {
|
|
48
|
-
__webpack_public_path__ = urlJoin($config._app.cdnURL, $config._app.assetsPath)
|
|
49
|
+
__webpack_public_path__ = urlJoin($config._app.cdnURL, $config._app.assetsPath); // eslint-disable-line camelcase, no-undef
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
Object.assign(Vue.config, {
|
|
52
|
+
Object.assign(Vue.config, { silent: false, performance: true });
|
|
53
|
+
|
|
54
|
+
const logs = NUXT.logs || [];
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.group && console.group
|
|
57
|
-
logs.forEach(logObj => (console[logObj.type] || console.log)(...logObj.args))
|
|
58
|
-
delete NUXT.logs
|
|
59
|
-
console.groupEnd && console.groupEnd()
|
|
56
|
+
if (logs.length > 0) {
|
|
57
|
+
const ssrLogStyle = 'background: #2E495E;border-radius: 0.5em;color: white;font-weight: bold;padding: 2px 0.5em;';
|
|
58
|
+
|
|
59
|
+
console.group && console.group('%cNuxt SSR', ssrLogStyle); // eslint-disable-line no-console
|
|
60
|
+
logs.forEach(logObj => (console[logObj.type] || console.log)(...logObj.args)); // eslint-disable-line no-console
|
|
61
|
+
delete NUXT.logs;
|
|
62
|
+
console.groupEnd && console.groupEnd(); // eslint-disable-line no-console
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
// Setup global Vue error handler
|
|
63
66
|
if (!Vue.config.$nuxt) {
|
|
64
|
-
const defaultErrorHandler = Vue.config.errorHandler
|
|
65
|
-
|
|
67
|
+
const defaultErrorHandler = Vue.config.errorHandler;
|
|
68
|
+
|
|
69
|
+
Vue.config.errorHandler = async(err, vm, info, ...rest) => {
|
|
66
70
|
// Call other handler if exist
|
|
67
|
-
let handled = null
|
|
71
|
+
let handled = null;
|
|
72
|
+
|
|
68
73
|
if (typeof defaultErrorHandler === 'function') {
|
|
69
|
-
handled = defaultErrorHandler(err, vm, info, ...rest)
|
|
74
|
+
handled = defaultErrorHandler(err, vm, info, ...rest);
|
|
70
75
|
}
|
|
71
76
|
if (handled === true) {
|
|
72
|
-
return handled
|
|
77
|
+
return handled;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
if (vm && vm.$root) {
|
|
76
81
|
const nuxtApp = Object.keys(Vue.config.$nuxt)
|
|
77
|
-
.find(nuxtInstance => vm.$root[nuxtInstance])
|
|
82
|
+
.find(nuxtInstance => vm.$root[nuxtInstance]);
|
|
78
83
|
|
|
79
84
|
// Show Nuxt Error Page
|
|
80
85
|
if (nuxtApp && vm.$root[nuxtApp].error && info !== 'render function') {
|
|
81
|
-
const currentApp = vm.$root[nuxtApp]
|
|
86
|
+
const currentApp = vm.$root[nuxtApp];
|
|
82
87
|
|
|
83
88
|
// Load error layout
|
|
84
|
-
let layout = (NuxtError.options || NuxtError).layout
|
|
89
|
+
let layout = (NuxtError.options || NuxtError).layout;
|
|
90
|
+
|
|
85
91
|
if (typeof layout === 'function') {
|
|
86
|
-
layout = layout(currentApp.context)
|
|
92
|
+
layout = layout(currentApp.context);
|
|
87
93
|
}
|
|
88
94
|
if (layout) {
|
|
89
|
-
await currentApp.loadLayout(layout).catch(() => {})
|
|
95
|
+
await currentApp.loadLayout(layout).catch(() => {});
|
|
90
96
|
}
|
|
91
|
-
currentApp.setLayout(layout)
|
|
97
|
+
currentApp.setLayout(layout);
|
|
92
98
|
|
|
93
|
-
currentApp.error(err)
|
|
99
|
+
currentApp.error(err);
|
|
94
100
|
}
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
if (typeof defaultErrorHandler === 'function') {
|
|
98
|
-
return handled
|
|
104
|
+
return handled;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
// Log to console
|
|
102
108
|
if (process.env.NODE_ENV !== 'production') {
|
|
103
|
-
console.error(err)
|
|
109
|
+
console.error(err); // eslint-disable-line no-console
|
|
104
110
|
} else {
|
|
105
|
-
console.error(err.message || err)
|
|
111
|
+
console.error(err.message || err); // eslint-disable-line no-console
|
|
106
112
|
}
|
|
107
|
-
}
|
|
108
|
-
Vue.config.$nuxt = {}
|
|
113
|
+
};
|
|
114
|
+
Vue.config.$nuxt = {};
|
|
109
115
|
}
|
|
110
|
-
Vue.config.$nuxt.$nuxt = true
|
|
116
|
+
Vue.config.$nuxt.$nuxt = true;
|
|
111
117
|
|
|
112
|
-
const errorHandler = Vue.config.errorHandler || console.error
|
|
118
|
+
const errorHandler = Vue.config.errorHandler || console.error; // eslint-disable-line no-console
|
|
113
119
|
|
|
114
120
|
// Create and mount App
|
|
115
|
-
createApp(null, nuxt.publicRuntimeConfig).then(mountApp).catch(errorHandler)
|
|
121
|
+
createApp(null, nuxt.publicRuntimeConfig).then(mountApp).catch(errorHandler); // eslint-disable-line no-undef
|
|
116
122
|
|
|
117
|
-
function componentOption
|
|
123
|
+
function componentOption(component, key, ...args) {
|
|
118
124
|
if (!component || !component.options || !component.options[key]) {
|
|
119
|
-
return {}
|
|
125
|
+
return {};
|
|
120
126
|
}
|
|
121
|
-
const option = component.options[key]
|
|
127
|
+
const option = component.options[key];
|
|
128
|
+
|
|
122
129
|
if (typeof option === 'function') {
|
|
123
|
-
return option(...args)
|
|
130
|
+
return option(...args);
|
|
124
131
|
}
|
|
125
|
-
|
|
132
|
+
|
|
133
|
+
return option;
|
|
126
134
|
}
|
|
127
135
|
|
|
128
|
-
function mapTransitions
|
|
136
|
+
function mapTransitions(toComponents, to, from) {
|
|
129
137
|
const componentTransitions = (component) => {
|
|
130
|
-
const transition = componentOption(component, 'transition', to, from) || {}
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
const transition = componentOption(component, 'transition', to, from) || {};
|
|
139
|
+
|
|
140
|
+
return (typeof transition === 'string' ? { name: transition } : transition);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const fromComponents = from ? getMatchedComponents(from) : [];
|
|
144
|
+
const maxDepth = Math.max(toComponents.length, fromComponents.length);
|
|
133
145
|
|
|
134
|
-
const
|
|
135
|
-
const maxDepth = Math.max(toComponents.length, fromComponents.length)
|
|
146
|
+
const mergedTransitions = [];
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
for (let i=0; i<maxDepth; i++) {
|
|
148
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
139
149
|
// Clone original objects to prevent overrides
|
|
140
|
-
const toTransitions = Object.assign({}, componentTransitions(toComponents[i]))
|
|
141
|
-
const transitions = Object.assign({}, componentTransitions(fromComponents[i]))
|
|
150
|
+
const toTransitions = Object.assign({}, componentTransitions(toComponents[i]));
|
|
151
|
+
const transitions = Object.assign({}, componentTransitions(fromComponents[i]));
|
|
142
152
|
|
|
143
153
|
// Combine transitions & prefer `leave` properties of "from" route
|
|
144
154
|
Object.keys(toTransitions)
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
.filter(key => typeof toTransitions[key] !== 'undefined' && !key.toLowerCase().includes('leave'))
|
|
156
|
+
.forEach((key) => {
|
|
157
|
+
transitions[key] = toTransitions[key];
|
|
158
|
+
});
|
|
147
159
|
|
|
148
|
-
mergedTransitions.push(transitions)
|
|
160
|
+
mergedTransitions.push(transitions);
|
|
149
161
|
}
|
|
150
|
-
|
|
162
|
+
|
|
163
|
+
return mergedTransitions;
|
|
151
164
|
}
|
|
152
165
|
|
|
153
|
-
async function loadAsyncComponents
|
|
166
|
+
async function loadAsyncComponents(to, from, next) {
|
|
154
167
|
// Check if route changed (this._routeChanged), only if the page is not an error (for validate())
|
|
155
|
-
this._routeChanged = Boolean(app.nuxt.err) || from.name !== to.name
|
|
156
|
-
this._paramChanged = !this._routeChanged && from.path !== to.path
|
|
157
|
-
this._queryChanged = !this._paramChanged && from.fullPath !== to.fullPath
|
|
158
|
-
this._diffQuery = (this._queryChanged ? getQueryDiff(to.query, from.query) : [])
|
|
168
|
+
this._routeChanged = Boolean(app.nuxt.err) || from.name !== to.name;
|
|
169
|
+
this._paramChanged = !this._routeChanged && from.path !== to.path;
|
|
170
|
+
this._queryChanged = !this._paramChanged && from.fullPath !== to.fullPath;
|
|
171
|
+
this._diffQuery = (this._queryChanged ? getQueryDiff(to.query, from.query) : []);
|
|
159
172
|
|
|
160
173
|
if ((this._routeChanged || this._paramChanged) && this.$loading.start && !this.$loading.manual) {
|
|
161
|
-
this.$loading.start()
|
|
174
|
+
this.$loading.start();
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
try {
|
|
@@ -166,405 +179,422 @@ async function loadAsyncComponents (to, from, next) {
|
|
|
166
179
|
const Components = await resolveRouteComponents(
|
|
167
180
|
to,
|
|
168
181
|
(Component, instance) => ({ Component, instance })
|
|
169
|
-
)
|
|
182
|
+
);
|
|
170
183
|
// Add a marker on each component that it needs to refresh or not
|
|
171
184
|
const startLoader = Components.some(({ Component, instance }) => {
|
|
172
|
-
const watchQuery = Component.options.watchQuery
|
|
185
|
+
const watchQuery = Component.options.watchQuery;
|
|
186
|
+
|
|
173
187
|
if (watchQuery === true) {
|
|
174
|
-
return true
|
|
188
|
+
return true;
|
|
175
189
|
}
|
|
176
190
|
if (Array.isArray(watchQuery)) {
|
|
177
|
-
return watchQuery.some(key => this._diffQuery[key])
|
|
191
|
+
return watchQuery.some(key => this._diffQuery[key]);
|
|
178
192
|
}
|
|
179
193
|
if (typeof watchQuery === 'function') {
|
|
180
|
-
return watchQuery.apply(instance, [to.query, from.query])
|
|
194
|
+
return watchQuery.apply(instance, [to.query, from.query]);
|
|
181
195
|
}
|
|
182
|
-
|
|
183
|
-
|
|
196
|
+
|
|
197
|
+
return false;
|
|
198
|
+
});
|
|
184
199
|
|
|
185
200
|
if (startLoader && this.$loading.start && !this.$loading.manual) {
|
|
186
|
-
this.$loading.start()
|
|
201
|
+
this.$loading.start();
|
|
187
202
|
}
|
|
188
203
|
}
|
|
189
204
|
// Call next()
|
|
190
|
-
next()
|
|
205
|
+
next();
|
|
191
206
|
} catch (error) {
|
|
192
|
-
const err = error || {}
|
|
193
|
-
const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500
|
|
194
|
-
const message = err.message || ''
|
|
207
|
+
const err = error || {};
|
|
208
|
+
const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500;
|
|
209
|
+
const message = err.message || '';
|
|
195
210
|
|
|
196
211
|
// Handle chunk loading errors
|
|
197
212
|
// This may be due to a new deployment or a network problem
|
|
198
213
|
if (/^Loading( CSS)? chunk (\d)+ failed\./.test(message)) {
|
|
199
|
-
window.location.reload(true /* skip cache */)
|
|
200
|
-
|
|
214
|
+
window.location.reload(true /* skip cache */);
|
|
215
|
+
|
|
216
|
+
return; // prevent error page blinking for user
|
|
201
217
|
}
|
|
202
218
|
|
|
203
|
-
this.error({ statusCode, message })
|
|
204
|
-
this.$nuxt.$emit('routeChanged', to, from, err)
|
|
205
|
-
next()
|
|
219
|
+
this.error({ statusCode, message });
|
|
220
|
+
this.$nuxt.$emit('routeChanged', to, from, err);
|
|
221
|
+
next();
|
|
206
222
|
}
|
|
207
223
|
}
|
|
208
224
|
|
|
209
|
-
function applySSRData
|
|
225
|
+
function applySSRData(Component, ssrData) {
|
|
210
226
|
if (NUXT.serverRendered && ssrData) {
|
|
211
|
-
applyAsyncData(Component, ssrData)
|
|
227
|
+
applyAsyncData(Component, ssrData);
|
|
212
228
|
}
|
|
213
229
|
|
|
214
|
-
Component._Ctor = Component
|
|
215
|
-
|
|
230
|
+
Component._Ctor = Component;
|
|
231
|
+
|
|
232
|
+
return Component;
|
|
216
233
|
}
|
|
217
234
|
|
|
218
235
|
// Get matched components
|
|
219
|
-
function resolveComponents
|
|
220
|
-
return flatMapComponents(route, async
|
|
236
|
+
function resolveComponents(route) {
|
|
237
|
+
return flatMapComponents(route, async(Component, _, match, key, index) => {
|
|
221
238
|
// If component is not resolved yet, resolve it
|
|
222
239
|
if (typeof Component === 'function' && !Component.options) {
|
|
223
|
-
Component = await Component()
|
|
240
|
+
Component = await Component();
|
|
224
241
|
}
|
|
225
242
|
// Sanitize it and save it
|
|
226
|
-
const _Component = applySSRData(sanitizeComponent(Component), NUXT.data ? NUXT.data[index] : null)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
243
|
+
const _Component = applySSRData(sanitizeComponent(Component), NUXT.data ? NUXT.data[index] : null);
|
|
244
|
+
|
|
245
|
+
match.components[key] = _Component;
|
|
246
|
+
|
|
247
|
+
return _Component;
|
|
248
|
+
});
|
|
230
249
|
}
|
|
231
250
|
|
|
232
|
-
function callMiddleware
|
|
233
|
-
let midd = [
|
|
234
|
-
let unknownMiddleware = false
|
|
251
|
+
function callMiddleware(Components, context, layout) {
|
|
252
|
+
let midd = ['i18n'];
|
|
253
|
+
let unknownMiddleware = false;
|
|
235
254
|
|
|
236
255
|
// If layout is undefined, only call global middleware
|
|
237
256
|
if (typeof layout !== 'undefined') {
|
|
238
|
-
midd = [] // Exclude global middleware if layout defined (already called before)
|
|
239
|
-
layout = sanitizeComponent(layout)
|
|
257
|
+
midd = []; // Exclude global middleware if layout defined (already called before)
|
|
258
|
+
layout = sanitizeComponent(layout);
|
|
240
259
|
if (layout.options.middleware) {
|
|
241
|
-
midd = midd.concat(layout.options.middleware)
|
|
260
|
+
midd = midd.concat(layout.options.middleware);
|
|
242
261
|
}
|
|
243
262
|
Components.forEach((Component) => {
|
|
244
263
|
if (Component.options.middleware) {
|
|
245
|
-
midd = midd.concat(Component.options.middleware)
|
|
264
|
+
midd = midd.concat(Component.options.middleware);
|
|
246
265
|
}
|
|
247
|
-
})
|
|
266
|
+
});
|
|
248
267
|
}
|
|
249
268
|
|
|
250
269
|
midd = midd.map((name) => {
|
|
251
270
|
if (typeof name === 'function') {
|
|
252
|
-
return name
|
|
271
|
+
return name;
|
|
253
272
|
}
|
|
254
273
|
if (typeof middleware[name] !== 'function') {
|
|
255
|
-
unknownMiddleware = true
|
|
256
|
-
this.error({ statusCode: 500, message:
|
|
274
|
+
unknownMiddleware = true;
|
|
275
|
+
this.error({ statusCode: 500, message: `Unknown middleware ${ name }` });
|
|
257
276
|
}
|
|
258
|
-
|
|
259
|
-
|
|
277
|
+
|
|
278
|
+
return middleware[name];
|
|
279
|
+
});
|
|
260
280
|
|
|
261
281
|
if (unknownMiddleware) {
|
|
262
|
-
return
|
|
282
|
+
return;
|
|
263
283
|
}
|
|
264
|
-
|
|
284
|
+
|
|
285
|
+
return middlewareSeries(midd, context);
|
|
265
286
|
}
|
|
266
287
|
|
|
267
|
-
async function render
|
|
288
|
+
async function render(to, from, next) {
|
|
268
289
|
if (this._routeChanged === false && this._paramChanged === false && this._queryChanged === false) {
|
|
269
|
-
return next()
|
|
290
|
+
return next();
|
|
270
291
|
}
|
|
271
|
-
|
|
272
|
-
let spaFallback = false
|
|
292
|
+
|
|
273
293
|
if (to === from) {
|
|
274
|
-
_lastPaths = []
|
|
275
|
-
spaFallback = true
|
|
294
|
+
_lastPaths = [];
|
|
276
295
|
} else {
|
|
277
|
-
const fromMatches = []
|
|
296
|
+
const fromMatches = [];
|
|
297
|
+
|
|
278
298
|
_lastPaths = getMatchedComponents(from, fromMatches).map((Component, i) => {
|
|
279
|
-
return compile(from.matched[fromMatches[i]].path)(from.params)
|
|
280
|
-
})
|
|
299
|
+
return compile(from.matched[fromMatches[i]].path)(from.params);
|
|
300
|
+
});
|
|
281
301
|
}
|
|
282
302
|
|
|
283
303
|
// nextCalled is true when redirected
|
|
284
|
-
let nextCalled = false
|
|
304
|
+
let nextCalled = false;
|
|
285
305
|
const _next = (path) => {
|
|
286
306
|
if (from.path === path.path && this.$loading.finish) {
|
|
287
|
-
this.$loading.finish()
|
|
307
|
+
this.$loading.finish();
|
|
288
308
|
}
|
|
289
309
|
|
|
290
310
|
if (from.path !== path.path && this.$loading.pause) {
|
|
291
|
-
this.$loading.pause()
|
|
311
|
+
this.$loading.pause();
|
|
292
312
|
}
|
|
293
313
|
|
|
294
314
|
if (nextCalled) {
|
|
295
|
-
return
|
|
315
|
+
return;
|
|
296
316
|
}
|
|
297
317
|
|
|
298
|
-
nextCalled = true
|
|
299
|
-
next(path)
|
|
300
|
-
}
|
|
318
|
+
nextCalled = true;
|
|
319
|
+
next(path);
|
|
320
|
+
};
|
|
301
321
|
|
|
302
322
|
// Update context
|
|
303
323
|
await setContext(app, {
|
|
304
324
|
route: to,
|
|
305
325
|
from,
|
|
306
|
-
next:
|
|
307
|
-
})
|
|
308
|
-
this._dateLastError = app.nuxt.dateErr
|
|
309
|
-
this._hadError = Boolean(app.nuxt.err)
|
|
326
|
+
next: _next.bind(this)
|
|
327
|
+
});
|
|
328
|
+
this._dateLastError = app.nuxt.dateErr;
|
|
329
|
+
this._hadError = Boolean(app.nuxt.err);
|
|
310
330
|
|
|
311
331
|
// Get route's matched components
|
|
312
|
-
const matches = []
|
|
313
|
-
const Components = getMatchedComponents(to, matches)
|
|
332
|
+
const matches = [];
|
|
333
|
+
const Components = getMatchedComponents(to, matches);
|
|
314
334
|
|
|
315
335
|
// If no Components matched, generate 404
|
|
316
336
|
if (!Components.length) {
|
|
317
337
|
// Default layout
|
|
318
|
-
await callMiddleware.call(this, Components, app.context)
|
|
338
|
+
await callMiddleware.call(this, Components, app.context);
|
|
319
339
|
if (nextCalled) {
|
|
320
|
-
return
|
|
340
|
+
return;
|
|
321
341
|
}
|
|
322
342
|
|
|
323
343
|
// Load layout for error page
|
|
324
|
-
const errorLayout = (NuxtError.options || NuxtError).layout
|
|
344
|
+
const errorLayout = (NuxtError.options || NuxtError).layout;
|
|
325
345
|
const layout = await this.loadLayout(
|
|
326
|
-
typeof errorLayout === 'function'
|
|
327
|
-
|
|
328
|
-
: errorLayout
|
|
329
|
-
)
|
|
346
|
+
typeof errorLayout === 'function' ? errorLayout.call(NuxtError, app.context) : errorLayout
|
|
347
|
+
);
|
|
330
348
|
|
|
331
|
-
await callMiddleware.call(this, Components, app.context, layout)
|
|
349
|
+
await callMiddleware.call(this, Components, app.context, layout);
|
|
332
350
|
if (nextCalled) {
|
|
333
|
-
return
|
|
351
|
+
return;
|
|
334
352
|
}
|
|
335
353
|
|
|
336
354
|
// Show error page
|
|
337
|
-
app.context.error({ statusCode: 404, message: 'This page could not be found' })
|
|
338
|
-
|
|
355
|
+
app.context.error({ statusCode: 404, message: 'This page could not be found' });
|
|
356
|
+
|
|
357
|
+
return next();
|
|
339
358
|
}
|
|
340
359
|
|
|
341
360
|
// Update ._data and other properties if hot reloaded
|
|
342
361
|
Components.forEach((Component) => {
|
|
343
362
|
if (Component._Ctor && Component._Ctor.options) {
|
|
344
|
-
Component.options.asyncData = Component._Ctor.options.asyncData
|
|
345
|
-
Component.options.fetch = Component._Ctor.options.fetch
|
|
363
|
+
Component.options.asyncData = Component._Ctor.options.asyncData;
|
|
364
|
+
Component.options.fetch = Component._Ctor.options.fetch;
|
|
346
365
|
}
|
|
347
|
-
})
|
|
366
|
+
});
|
|
348
367
|
|
|
349
368
|
// Apply transitions
|
|
350
|
-
this.setTransitions(mapTransitions(Components, to, from))
|
|
369
|
+
this.setTransitions(mapTransitions(Components, to, from));
|
|
351
370
|
|
|
352
371
|
try {
|
|
353
372
|
// Call middleware
|
|
354
|
-
await callMiddleware.call(this, Components, app.context)
|
|
373
|
+
await callMiddleware.call(this, Components, app.context);
|
|
355
374
|
if (nextCalled) {
|
|
356
|
-
return
|
|
375
|
+
return;
|
|
357
376
|
}
|
|
358
377
|
if (app.context._errored) {
|
|
359
|
-
return next()
|
|
378
|
+
return next();
|
|
360
379
|
}
|
|
361
380
|
|
|
362
381
|
// Set layout
|
|
363
|
-
let layout = Components[0].options.layout
|
|
382
|
+
let layout = Components[0].options.layout;
|
|
383
|
+
|
|
364
384
|
if (typeof layout === 'function') {
|
|
365
|
-
layout = layout(app.context)
|
|
385
|
+
layout = layout(app.context);
|
|
366
386
|
}
|
|
367
|
-
layout = await this.loadLayout(layout)
|
|
387
|
+
layout = await this.loadLayout(layout);
|
|
368
388
|
|
|
369
389
|
// Call middleware for layout
|
|
370
|
-
await callMiddleware.call(this, Components, app.context, layout)
|
|
390
|
+
await callMiddleware.call(this, Components, app.context, layout);
|
|
371
391
|
if (nextCalled) {
|
|
372
|
-
return
|
|
392
|
+
return;
|
|
373
393
|
}
|
|
374
394
|
if (app.context._errored) {
|
|
375
|
-
return next()
|
|
395
|
+
return next();
|
|
376
396
|
}
|
|
377
397
|
|
|
378
398
|
// Call .validate()
|
|
379
|
-
let isValid = true
|
|
399
|
+
let isValid = true;
|
|
400
|
+
|
|
380
401
|
try {
|
|
381
402
|
for (const Component of Components) {
|
|
382
403
|
if (typeof Component.options.validate !== 'function') {
|
|
383
|
-
continue
|
|
404
|
+
continue;
|
|
384
405
|
}
|
|
385
406
|
|
|
386
|
-
isValid = await Component.options.validate(app.context)
|
|
407
|
+
isValid = await Component.options.validate(app.context);
|
|
387
408
|
|
|
388
409
|
if (!isValid) {
|
|
389
|
-
break
|
|
410
|
+
break;
|
|
390
411
|
}
|
|
391
412
|
}
|
|
392
413
|
} catch (validationError) {
|
|
393
414
|
// ...If .validate() threw an error
|
|
394
415
|
this.error({
|
|
395
416
|
statusCode: validationError.statusCode || '500',
|
|
396
|
-
message:
|
|
397
|
-
})
|
|
398
|
-
|
|
417
|
+
message: validationError.message
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
return next();
|
|
399
421
|
}
|
|
400
422
|
|
|
401
423
|
// ...If .validate() returned false
|
|
402
424
|
if (!isValid) {
|
|
403
|
-
this.error({ statusCode: 404, message: 'This page could not be found' })
|
|
404
|
-
|
|
425
|
+
this.error({ statusCode: 404, message: 'This page could not be found' });
|
|
426
|
+
|
|
427
|
+
return next();
|
|
405
428
|
}
|
|
406
429
|
|
|
407
|
-
let instances
|
|
430
|
+
let instances;
|
|
431
|
+
|
|
408
432
|
// Call asyncData & fetch hooks on components matched by the route.
|
|
409
|
-
await Promise.all(Components.map(
|
|
433
|
+
await Promise.all(Components.map((Component, i) => {
|
|
410
434
|
// Check if only children route changed
|
|
411
|
-
Component._path = compile(to.matched[matches[i]].path)(to.params)
|
|
412
|
-
Component._dataRefresh = false
|
|
413
|
-
const childPathChanged = Component._path !== _lastPaths[i]
|
|
435
|
+
Component._path = compile(to.matched[matches[i]].path)(to.params);
|
|
436
|
+
Component._dataRefresh = false;
|
|
437
|
+
const childPathChanged = Component._path !== _lastPaths[i];
|
|
438
|
+
|
|
414
439
|
// Refresh component (call asyncData & fetch) when:
|
|
415
440
|
// Route path changed part includes current component
|
|
416
441
|
// Or route param changed part includes current component and watchParam is not `false`
|
|
417
442
|
// Or route query is changed and watchQuery returns `true`
|
|
418
443
|
if (this._routeChanged && childPathChanged) {
|
|
419
|
-
Component._dataRefresh = true
|
|
444
|
+
Component._dataRefresh = true;
|
|
420
445
|
} else if (this._paramChanged && childPathChanged) {
|
|
421
|
-
const watchParam = Component.options.watchParam
|
|
422
|
-
|
|
446
|
+
const watchParam = Component.options.watchParam;
|
|
447
|
+
|
|
448
|
+
Component._dataRefresh = watchParam !== false;
|
|
423
449
|
} else if (this._queryChanged) {
|
|
424
|
-
const watchQuery = Component.options.watchQuery
|
|
450
|
+
const watchQuery = Component.options.watchQuery;
|
|
451
|
+
|
|
425
452
|
if (watchQuery === true) {
|
|
426
|
-
Component._dataRefresh = true
|
|
453
|
+
Component._dataRefresh = true;
|
|
427
454
|
} else if (Array.isArray(watchQuery)) {
|
|
428
|
-
Component._dataRefresh = watchQuery.some(key => this._diffQuery[key])
|
|
455
|
+
Component._dataRefresh = watchQuery.some(key => this._diffQuery[key]);
|
|
429
456
|
} else if (typeof watchQuery === 'function') {
|
|
430
457
|
if (!instances) {
|
|
431
|
-
instances = getMatchedComponentsInstances(to)
|
|
458
|
+
instances = getMatchedComponentsInstances(to);
|
|
432
459
|
}
|
|
433
|
-
Component._dataRefresh = watchQuery.apply(instances[i], [to.query, from.query])
|
|
460
|
+
Component._dataRefresh = watchQuery.apply(instances[i], [to.query, from.query]);
|
|
434
461
|
}
|
|
435
462
|
}
|
|
436
463
|
if (!this._hadError && this._isMounted && !Component._dataRefresh) {
|
|
437
|
-
return
|
|
464
|
+
return;
|
|
438
465
|
}
|
|
439
466
|
|
|
440
|
-
const promises = []
|
|
467
|
+
const promises = [];
|
|
441
468
|
|
|
442
469
|
const hasAsyncData = (
|
|
443
470
|
Component.options.asyncData &&
|
|
444
471
|
typeof Component.options.asyncData === 'function'
|
|
445
|
-
)
|
|
472
|
+
);
|
|
446
473
|
|
|
447
|
-
const hasFetch = Boolean(Component.options.fetch) && Component.options.fetch.length
|
|
474
|
+
const hasFetch = Boolean(Component.options.fetch) && Component.options.fetch.length;
|
|
448
475
|
|
|
449
|
-
const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45
|
|
476
|
+
const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45;
|
|
450
477
|
|
|
451
478
|
// Call asyncData(context)
|
|
452
479
|
if (hasAsyncData) {
|
|
453
|
-
const promise = promisify(Component.options.asyncData, app.context)
|
|
480
|
+
const promise = promisify(Component.options.asyncData, app.context);
|
|
454
481
|
|
|
455
482
|
promise.then((asyncDataResult) => {
|
|
456
|
-
applyAsyncData(Component, asyncDataResult)
|
|
483
|
+
applyAsyncData(Component, asyncDataResult);
|
|
457
484
|
|
|
458
485
|
if (this.$loading.increase) {
|
|
459
|
-
this.$loading.increase(loadingIncrease)
|
|
486
|
+
this.$loading.increase(loadingIncrease);
|
|
460
487
|
}
|
|
461
|
-
})
|
|
462
|
-
promises.push(promise)
|
|
488
|
+
});
|
|
489
|
+
promises.push(promise);
|
|
463
490
|
}
|
|
464
491
|
|
|
465
492
|
// Check disabled page loading
|
|
466
|
-
this.$loading.manual = Component.options.loading === false
|
|
493
|
+
this.$loading.manual = Component.options.loading === false;
|
|
467
494
|
|
|
468
495
|
// Call fetch(context)
|
|
469
496
|
if (hasFetch) {
|
|
470
|
-
let p = Component.options.fetch(app.context)
|
|
497
|
+
let p = Component.options.fetch(app.context);
|
|
498
|
+
|
|
471
499
|
if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) {
|
|
472
|
-
p = Promise.resolve(p)
|
|
500
|
+
p = Promise.resolve(p);
|
|
473
501
|
}
|
|
474
502
|
p.then((fetchResult) => {
|
|
475
503
|
if (this.$loading.increase) {
|
|
476
|
-
this.$loading.increase(loadingIncrease)
|
|
504
|
+
this.$loading.increase(loadingIncrease);
|
|
477
505
|
}
|
|
478
|
-
})
|
|
479
|
-
promises.push(p)
|
|
506
|
+
});
|
|
507
|
+
promises.push(p);
|
|
480
508
|
}
|
|
481
509
|
|
|
482
|
-
return Promise.all(promises)
|
|
483
|
-
}))
|
|
510
|
+
return Promise.all(promises);
|
|
511
|
+
}));
|
|
484
512
|
|
|
485
513
|
// If not redirected
|
|
486
514
|
if (!nextCalled) {
|
|
487
515
|
if (this.$loading.finish && !this.$loading.manual) {
|
|
488
|
-
this.$loading.finish()
|
|
516
|
+
this.$loading.finish();
|
|
489
517
|
}
|
|
490
518
|
|
|
491
|
-
next()
|
|
519
|
+
next();
|
|
492
520
|
}
|
|
493
521
|
} catch (err) {
|
|
494
|
-
const error = err || {}
|
|
522
|
+
const error = err || {};
|
|
523
|
+
|
|
495
524
|
if (error.message === 'ERR_REDIRECT') {
|
|
496
|
-
return this.$nuxt.$emit('routeChanged', to, from, error)
|
|
525
|
+
return this.$nuxt.$emit('routeChanged', to, from, error);
|
|
497
526
|
}
|
|
498
|
-
_lastPaths = []
|
|
527
|
+
_lastPaths = [];
|
|
499
528
|
|
|
500
|
-
globalHandleError(error)
|
|
529
|
+
globalHandleError(error);
|
|
501
530
|
|
|
502
531
|
// Load error layout
|
|
503
|
-
let layout = (NuxtError.options || NuxtError).layout
|
|
532
|
+
let layout = (NuxtError.options || NuxtError).layout;
|
|
533
|
+
|
|
504
534
|
if (typeof layout === 'function') {
|
|
505
|
-
layout = layout(app.context)
|
|
535
|
+
layout = layout(app.context);
|
|
506
536
|
}
|
|
507
|
-
await this.loadLayout(layout)
|
|
537
|
+
await this.loadLayout(layout);
|
|
508
538
|
|
|
509
|
-
this.error(error)
|
|
510
|
-
this.$nuxt.$emit('routeChanged', to, from, error)
|
|
511
|
-
next()
|
|
539
|
+
this.error(error);
|
|
540
|
+
this.$nuxt.$emit('routeChanged', to, from, error);
|
|
541
|
+
next();
|
|
512
542
|
}
|
|
513
543
|
}
|
|
514
544
|
|
|
515
545
|
// Fix components format in matched, it's due to code-splitting of vue-router
|
|
516
|
-
function normalizeComponents
|
|
546
|
+
function normalizeComponents(to, ___) {
|
|
517
547
|
flatMapComponents(to, (Component, _, match, key) => {
|
|
518
548
|
if (typeof Component === 'object' && !Component.options) {
|
|
519
549
|
// Updated via vue-router resolveAsyncComponents()
|
|
520
|
-
Component = Vue.extend(Component)
|
|
521
|
-
Component._Ctor = Component
|
|
522
|
-
match.components[key] = Component
|
|
550
|
+
Component = Vue.extend(Component);
|
|
551
|
+
Component._Ctor = Component;
|
|
552
|
+
match.components[key] = Component;
|
|
523
553
|
}
|
|
524
|
-
|
|
525
|
-
|
|
554
|
+
|
|
555
|
+
return Component;
|
|
556
|
+
});
|
|
526
557
|
}
|
|
527
558
|
|
|
528
|
-
function setLayoutForNextPage
|
|
559
|
+
function setLayoutForNextPage(to) {
|
|
529
560
|
// Set layout
|
|
530
|
-
let hasError = Boolean(this.$options.nuxt.err)
|
|
561
|
+
let hasError = Boolean(this.$options.nuxt.err);
|
|
562
|
+
|
|
531
563
|
if (this._hadError && this._dateLastError === this.$options.nuxt.dateErr) {
|
|
532
|
-
hasError = false
|
|
564
|
+
hasError = false;
|
|
533
565
|
}
|
|
534
|
-
let layout = hasError
|
|
535
|
-
? (NuxtError.options || NuxtError).layout
|
|
536
|
-
: to.matched[0].components.default.options.layout
|
|
566
|
+
let layout = hasError ? (NuxtError.options || NuxtError).layout : to.matched[0].components.default.options.layout;
|
|
537
567
|
|
|
538
568
|
if (typeof layout === 'function') {
|
|
539
|
-
layout = layout(app.context)
|
|
569
|
+
layout = layout(app.context);
|
|
540
570
|
}
|
|
541
571
|
|
|
542
|
-
this.setLayout(layout)
|
|
572
|
+
this.setLayout(layout);
|
|
543
573
|
}
|
|
544
574
|
|
|
545
|
-
function checkForErrors
|
|
575
|
+
function checkForErrors(app) {
|
|
546
576
|
// Hide error component if no error
|
|
547
577
|
if (app._hadError && app._dateLastError === app.$options.nuxt.dateErr) {
|
|
548
|
-
app.error()
|
|
578
|
+
app.error();
|
|
549
579
|
}
|
|
550
580
|
}
|
|
551
581
|
|
|
552
582
|
// When navigating on a different route but the same component is used, Vue.js
|
|
553
583
|
// Will not update the instance data, so we have to update $data ourselves
|
|
554
|
-
function fixPrepatch
|
|
584
|
+
function fixPrepatch(to, ___) {
|
|
555
585
|
if (this._routeChanged === false && this._paramChanged === false && this._queryChanged === false) {
|
|
556
|
-
return
|
|
586
|
+
return;
|
|
557
587
|
}
|
|
558
588
|
|
|
559
|
-
const instances = getMatchedComponentsInstances(to)
|
|
560
|
-
const Components = getMatchedComponents(to)
|
|
589
|
+
const instances = getMatchedComponentsInstances(to);
|
|
590
|
+
const Components = getMatchedComponents(to);
|
|
561
591
|
|
|
562
|
-
let triggerScroll = false
|
|
592
|
+
let triggerScroll = false;
|
|
563
593
|
|
|
564
594
|
Vue.nextTick(() => {
|
|
565
595
|
instances.forEach((instance, i) => {
|
|
566
596
|
if (!instance || instance._isDestroyed) {
|
|
567
|
-
return
|
|
597
|
+
return;
|
|
568
598
|
}
|
|
569
599
|
|
|
570
600
|
if (
|
|
@@ -573,245 +603,261 @@ function fixPrepatch (to, ___) {
|
|
|
573
603
|
instance.$vnode.data.keepAlive !== true &&
|
|
574
604
|
typeof instance.constructor.options.data === 'function'
|
|
575
605
|
) {
|
|
576
|
-
const newData = instance.constructor.options.data.call(instance)
|
|
606
|
+
const newData = instance.constructor.options.data.call(instance);
|
|
607
|
+
|
|
577
608
|
for (const key in newData) {
|
|
578
|
-
Vue.set(instance.$data, key, newData[key])
|
|
609
|
+
Vue.set(instance.$data, key, newData[key]);
|
|
579
610
|
}
|
|
580
611
|
|
|
581
|
-
triggerScroll = true
|
|
612
|
+
triggerScroll = true;
|
|
582
613
|
}
|
|
583
|
-
})
|
|
614
|
+
});
|
|
584
615
|
|
|
585
616
|
if (triggerScroll) {
|
|
586
617
|
// Ensure to trigger scroll event after calling scrollBehavior
|
|
587
618
|
window.$nuxt.$nextTick(() => {
|
|
588
|
-
window.$nuxt.$emit('triggerScroll')
|
|
589
|
-
})
|
|
619
|
+
window.$nuxt.$emit('triggerScroll');
|
|
620
|
+
});
|
|
590
621
|
}
|
|
591
622
|
|
|
592
|
-
checkForErrors(this)
|
|
623
|
+
checkForErrors(this);
|
|
593
624
|
|
|
594
625
|
// Hot reloading
|
|
595
|
-
setTimeout(() => hotReloadAPI(this), 100)
|
|
596
|
-
})
|
|
626
|
+
setTimeout(() => hotReloadAPI(this), 100);
|
|
627
|
+
});
|
|
597
628
|
}
|
|
598
629
|
|
|
599
|
-
function nuxtReady
|
|
630
|
+
function nuxtReady(_app) {
|
|
600
631
|
window.onNuxtReadyCbs.forEach((cb) => {
|
|
601
632
|
if (typeof cb === 'function') {
|
|
602
|
-
cb(_app)
|
|
633
|
+
cb(_app);
|
|
603
634
|
}
|
|
604
|
-
})
|
|
635
|
+
});
|
|
605
636
|
// Special JSDOM
|
|
606
637
|
if (typeof window._onNuxtLoaded === 'function') {
|
|
607
|
-
window._onNuxtLoaded(_app)
|
|
638
|
+
window._onNuxtLoaded(_app);
|
|
608
639
|
}
|
|
609
640
|
// Add router hooks
|
|
610
641
|
router.afterEach((to, from) => {
|
|
611
642
|
// Wait for fixPrepatch + $data updates
|
|
612
|
-
Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from))
|
|
613
|
-
})
|
|
643
|
+
Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from));
|
|
644
|
+
});
|
|
614
645
|
}
|
|
615
646
|
|
|
616
|
-
const noopData = () => {
|
|
617
|
-
|
|
647
|
+
const noopData = () => {
|
|
648
|
+
return {};
|
|
649
|
+
};
|
|
650
|
+
const noopFetch = () => {};
|
|
618
651
|
|
|
619
652
|
// Special hot reload with asyncData(context)
|
|
620
|
-
function getNuxtChildComponents
|
|
653
|
+
function getNuxtChildComponents($parent, $components = []) {
|
|
621
654
|
$parent.$children.forEach(($child) => {
|
|
622
|
-
if ($child.$vnode && $child.$vnode.data.nuxtChild && !$components.find(c =>(c.$options.__file === $child.$options.__file))) {
|
|
623
|
-
$components.push($child)
|
|
655
|
+
if ($child.$vnode && $child.$vnode.data.nuxtChild && !$components.find(c => (c.$options.__file === $child.$options.__file))) {
|
|
656
|
+
$components.push($child);
|
|
624
657
|
}
|
|
625
658
|
if ($child.$children && $child.$children.length) {
|
|
626
|
-
getNuxtChildComponents($child, $components)
|
|
659
|
+
getNuxtChildComponents($child, $components);
|
|
627
660
|
}
|
|
628
|
-
})
|
|
661
|
+
});
|
|
629
662
|
|
|
630
|
-
return $components
|
|
663
|
+
return $components;
|
|
631
664
|
}
|
|
632
665
|
|
|
633
666
|
function hotReloadAPI(_app) {
|
|
634
|
-
if (!module.hot)
|
|
667
|
+
if (!module.hot) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
635
670
|
|
|
636
|
-
|
|
671
|
+
const $components = getNuxtChildComponents(_app.$nuxt, []);
|
|
637
672
|
|
|
638
|
-
$components.forEach(addHotReload.bind(_app))
|
|
673
|
+
$components.forEach(addHotReload.bind(_app));
|
|
639
674
|
}
|
|
640
675
|
|
|
641
|
-
function addHotReload
|
|
642
|
-
if ($component.$vnode.data._hasHotReload)
|
|
643
|
-
|
|
676
|
+
function addHotReload($component, depth) {
|
|
677
|
+
if ($component.$vnode.data._hasHotReload) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
$component.$vnode.data._hasHotReload = true;
|
|
681
|
+
|
|
682
|
+
const _forceUpdate = $component.$forceUpdate.bind($component.$parent);
|
|
644
683
|
|
|
645
|
-
|
|
684
|
+
$component.$vnode.context.$forceUpdate = async() => {
|
|
685
|
+
const Components = getMatchedComponents(router.currentRoute);
|
|
686
|
+
let Component = Components[depth];
|
|
646
687
|
|
|
647
|
-
$component.$vnode.context.$forceUpdate = async () => {
|
|
648
|
-
let Components = getMatchedComponents(router.currentRoute)
|
|
649
|
-
let Component = Components[depth]
|
|
650
688
|
if (!Component) {
|
|
651
|
-
return _forceUpdate()
|
|
689
|
+
return _forceUpdate();
|
|
652
690
|
}
|
|
653
691
|
if (typeof Component === 'object' && !Component.options) {
|
|
654
692
|
// Updated via vue-router resolveAsyncComponents()
|
|
655
|
-
Component = Vue.extend(Component)
|
|
656
|
-
Component._Ctor = Component
|
|
657
|
-
}
|
|
658
|
-
this.error()
|
|
659
|
-
let promises = []
|
|
660
|
-
const next = function (path) {
|
|
661
|
-
this.$loading.finish && this.$loading.finish()
|
|
662
|
-
router.push(path)
|
|
693
|
+
Component = Vue.extend(Component);
|
|
694
|
+
Component._Ctor = Component;
|
|
663
695
|
}
|
|
696
|
+
this.error();
|
|
697
|
+
const promises = [];
|
|
698
|
+
const next = function(path) {
|
|
699
|
+
this.$loading.finish && this.$loading.finish();
|
|
700
|
+
router.push(path);
|
|
701
|
+
};
|
|
702
|
+
|
|
664
703
|
await setContext(app, {
|
|
665
704
|
route: router.currentRoute,
|
|
666
705
|
isHMR: true,
|
|
667
|
-
next:
|
|
668
|
-
})
|
|
669
|
-
const context = app.context
|
|
706
|
+
next: next.bind(this)
|
|
707
|
+
});
|
|
708
|
+
const context = app.context;
|
|
670
709
|
|
|
671
710
|
if (this.$loading.start && !this.$loading.manual) {
|
|
672
|
-
this.$loading.start()
|
|
711
|
+
this.$loading.start();
|
|
673
712
|
}
|
|
674
713
|
|
|
675
714
|
callMiddleware.call(this, Components, context)
|
|
676
|
-
|
|
715
|
+
.then(() => {
|
|
677
716
|
// If layout changed
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
717
|
+
if (depth !== 0) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
681
720
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
layout
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
721
|
+
let layout = Component.options.layout || 'default';
|
|
722
|
+
|
|
723
|
+
if (typeof layout === 'function') {
|
|
724
|
+
layout = layout(context);
|
|
725
|
+
}
|
|
726
|
+
if (this.layoutName === layout) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
const promise = this.loadLayout(layout);
|
|
730
|
+
|
|
731
|
+
promise.then(() => {
|
|
732
|
+
this.setLayout(layout);
|
|
733
|
+
Vue.nextTick(() => hotReloadAPI(this));
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
return promise;
|
|
693
737
|
})
|
|
694
|
-
return promise
|
|
695
|
-
})
|
|
696
738
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
739
|
+
.then(() => {
|
|
740
|
+
return callMiddleware.call(this, Components, context, this.layout);
|
|
741
|
+
})
|
|
700
742
|
|
|
701
|
-
|
|
743
|
+
.then(() => {
|
|
702
744
|
// Call asyncData(context)
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
745
|
+
const pAsyncData = promisify(Component.options.asyncData || noopData, context);
|
|
746
|
+
|
|
747
|
+
pAsyncData.then((asyncDataResult) => {
|
|
748
|
+
applyAsyncData(Component, asyncDataResult);
|
|
749
|
+
this.$loading.increase && this.$loading.increase(30);
|
|
750
|
+
});
|
|
751
|
+
promises.push(pAsyncData);
|
|
752
|
+
|
|
753
|
+
// Call fetch()
|
|
754
|
+
Component.options.fetch = Component.options.fetch || noopFetch;
|
|
755
|
+
let pFetch = Component.options.fetch.length && Component.options.fetch(context);
|
|
756
|
+
|
|
757
|
+
if (!pFetch || (!(pFetch instanceof Promise) && (typeof pFetch.then !== 'function'))) {
|
|
758
|
+
pFetch = Promise.resolve(pFetch);
|
|
759
|
+
}
|
|
760
|
+
pFetch.then(() => this.$loading.increase && this.$loading.increase(30));
|
|
761
|
+
promises.push(pFetch);
|
|
762
|
+
|
|
763
|
+
return Promise.all(promises);
|
|
707
764
|
})
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
pFetch.then(() => this.$loading.increase && this.$loading.increase(30))
|
|
715
|
-
promises.push(pFetch)
|
|
716
|
-
|
|
717
|
-
return Promise.all(promises)
|
|
718
|
-
})
|
|
719
|
-
.then(() => {
|
|
720
|
-
this.$loading.finish && this.$loading.finish()
|
|
721
|
-
_forceUpdate()
|
|
722
|
-
setTimeout(() => hotReloadAPI(this), 100)
|
|
723
|
-
})
|
|
724
|
-
}
|
|
765
|
+
.then(() => {
|
|
766
|
+
this.$loading.finish && this.$loading.finish();
|
|
767
|
+
_forceUpdate();
|
|
768
|
+
setTimeout(() => hotReloadAPI(this), 100);
|
|
769
|
+
});
|
|
770
|
+
};
|
|
725
771
|
}
|
|
726
772
|
|
|
727
|
-
async function mountApp
|
|
773
|
+
async function mountApp(__app) {
|
|
728
774
|
// Set global variables
|
|
729
|
-
app = __app.app
|
|
730
|
-
router = __app.router
|
|
731
|
-
store = __app.store
|
|
775
|
+
app = __app.app;
|
|
776
|
+
router = __app.router;
|
|
732
777
|
|
|
733
778
|
// Create Vue instance
|
|
734
|
-
const _app = new Vue(app)
|
|
779
|
+
const _app = new Vue(app);
|
|
735
780
|
|
|
736
781
|
// Mounts Vue app to DOM element
|
|
737
782
|
const mount = () => {
|
|
738
|
-
_app.$mount('#app')
|
|
783
|
+
_app.$mount('#app');
|
|
739
784
|
|
|
740
785
|
// Add afterEach router hooks
|
|
741
|
-
router.afterEach(normalizeComponents)
|
|
786
|
+
router.afterEach(normalizeComponents);
|
|
742
787
|
|
|
743
|
-
router.afterEach(setLayoutForNextPage.bind(_app))
|
|
788
|
+
router.afterEach(setLayoutForNextPage.bind(_app));
|
|
744
789
|
|
|
745
|
-
router.afterEach(fixPrepatch.bind(_app))
|
|
790
|
+
router.afterEach(fixPrepatch.bind(_app));
|
|
746
791
|
|
|
747
792
|
// Listen for first Vue update
|
|
748
793
|
Vue.nextTick(() => {
|
|
749
794
|
// Call window.{{globals.readyCallback}} callbacks
|
|
750
|
-
nuxtReady(_app)
|
|
795
|
+
nuxtReady(_app);
|
|
751
796
|
|
|
752
797
|
// Enable hot reloading
|
|
753
|
-
hotReloadAPI(_app)
|
|
754
|
-
})
|
|
755
|
-
}
|
|
798
|
+
hotReloadAPI(_app);
|
|
799
|
+
});
|
|
800
|
+
};
|
|
756
801
|
|
|
757
802
|
// Resolve route components
|
|
758
|
-
const Components = await Promise.all(resolveComponents(app.context.route))
|
|
803
|
+
const Components = await Promise.all(resolveComponents(app.context.route));
|
|
759
804
|
|
|
760
805
|
// Enable transitions
|
|
761
|
-
_app.setTransitions = _app.$options.nuxt.setTransitions.bind(_app)
|
|
806
|
+
_app.setTransitions = _app.$options.nuxt.setTransitions.bind(_app);
|
|
762
807
|
if (Components.length) {
|
|
763
|
-
_app.setTransitions(mapTransitions(Components, router.currentRoute))
|
|
764
|
-
_lastPaths = router.currentRoute.matched.map(route => compile(route.path)(router.currentRoute.params))
|
|
808
|
+
_app.setTransitions(mapTransitions(Components, router.currentRoute));
|
|
809
|
+
_lastPaths = router.currentRoute.matched.map(route => compile(route.path)(router.currentRoute.params));
|
|
765
810
|
}
|
|
766
811
|
|
|
767
812
|
// Initialize error handler
|
|
768
|
-
_app.$loading = {} // To avoid error while _app.$nuxt does not exist
|
|
813
|
+
_app.$loading = {}; // To avoid error while _app.$nuxt does not exist
|
|
769
814
|
if (NUXT.error) {
|
|
770
|
-
_app.error(NUXT.error)
|
|
815
|
+
_app.error(NUXT.error);
|
|
771
816
|
}
|
|
772
817
|
|
|
773
818
|
// Add beforeEach router hooks
|
|
774
|
-
router.beforeEach(loadAsyncComponents.bind(_app))
|
|
775
|
-
router.beforeEach(render.bind(_app))
|
|
819
|
+
router.beforeEach(loadAsyncComponents.bind(_app));
|
|
820
|
+
router.beforeEach(render.bind(_app));
|
|
776
821
|
|
|
777
822
|
// Fix in static: remove trailing slash to force hydration
|
|
778
823
|
// Full static, if server-rendered: hydrate, to allow custom redirect to generated page
|
|
779
824
|
|
|
780
825
|
// Fix in static: remove trailing slash to force hydration
|
|
781
826
|
if (NUXT.serverRendered && isSamePath(NUXT.routePath, _app.context.route.path)) {
|
|
782
|
-
return mount()
|
|
827
|
+
return mount();
|
|
783
828
|
}
|
|
784
829
|
|
|
785
830
|
// First render on client-side
|
|
786
831
|
const clientFirstMount = () => {
|
|
787
|
-
normalizeComponents(router.currentRoute, router.currentRoute)
|
|
788
|
-
setLayoutForNextPage.call(_app, router.currentRoute)
|
|
789
|
-
checkForErrors(_app)
|
|
832
|
+
normalizeComponents(router.currentRoute, router.currentRoute);
|
|
833
|
+
setLayoutForNextPage.call(_app, router.currentRoute);
|
|
834
|
+
checkForErrors(_app);
|
|
790
835
|
// Don't call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render
|
|
791
|
-
mount()
|
|
792
|
-
}
|
|
836
|
+
mount();
|
|
837
|
+
};
|
|
793
838
|
|
|
794
839
|
// fix: force next tick to avoid having same timestamp when an error happen on spa fallback
|
|
795
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
840
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
796
841
|
render.call(_app, router.currentRoute, router.currentRoute, (path) => {
|
|
797
842
|
// If not redirected
|
|
798
843
|
if (!path) {
|
|
799
|
-
clientFirstMount()
|
|
800
|
-
|
|
844
|
+
clientFirstMount();
|
|
845
|
+
|
|
846
|
+
return;
|
|
801
847
|
}
|
|
802
848
|
|
|
803
849
|
// Add a one-time afterEach hook to
|
|
804
850
|
// mount the app wait for redirect and route gets resolved
|
|
805
851
|
const unregisterHook = router.afterEach((to, from) => {
|
|
806
|
-
unregisterHook()
|
|
807
|
-
clientFirstMount()
|
|
808
|
-
})
|
|
852
|
+
unregisterHook();
|
|
853
|
+
clientFirstMount();
|
|
854
|
+
});
|
|
809
855
|
|
|
810
856
|
// Push the path and let route to be resolved
|
|
811
857
|
router.push(path, undefined, (err) => {
|
|
812
858
|
if (err) {
|
|
813
|
-
errorHandler(err)
|
|
859
|
+
errorHandler(err);
|
|
814
860
|
}
|
|
815
|
-
})
|
|
816
|
-
})
|
|
861
|
+
});
|
|
862
|
+
});
|
|
817
863
|
}
|