@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,150 +1,166 @@
|
|
|
1
|
-
import Vue from 'vue'
|
|
2
|
-
import {
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
isSamePath as _isSamePath, joinURL, normalizeURL, withQuery, withoutTrailingSlash
|
|
4
|
+
} from 'ufo';
|
|
3
5
|
|
|
4
6
|
// window.{{globals.loadedCallback}} hook
|
|
5
7
|
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
|
|
6
8
|
if (process.client) {
|
|
7
|
-
window.onNuxtReadyCbs = []
|
|
9
|
+
window.onNuxtReadyCbs = [];
|
|
8
10
|
window.onNuxtReady = (cb) => {
|
|
9
|
-
window.onNuxtReadyCbs.push(cb)
|
|
10
|
-
}
|
|
11
|
+
window.onNuxtReadyCbs.push(cb);
|
|
12
|
+
};
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export function createGetCounter
|
|
14
|
-
return function getCounter
|
|
15
|
+
export function createGetCounter(counterObject, defaultKey = '') {
|
|
16
|
+
return function getCounter(id = defaultKey) {
|
|
15
17
|
if (counterObject[id] === undefined) {
|
|
16
|
-
counterObject[id] = 0
|
|
18
|
+
counterObject[id] = 0;
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
return counterObject[id]++;
|
|
22
|
+
};
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
export function empty
|
|
25
|
+
export function empty() {}
|
|
23
26
|
|
|
24
|
-
export function globalHandleError
|
|
27
|
+
export function globalHandleError(error) {
|
|
25
28
|
if (Vue.config.errorHandler) {
|
|
26
|
-
Vue.config.errorHandler(error)
|
|
29
|
+
Vue.config.errorHandler(error);
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
export function interopDefault
|
|
31
|
-
return promise.then(m => m.default || m)
|
|
33
|
+
export function interopDefault(promise) {
|
|
34
|
+
return promise.then(m => m.default || m);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export function hasFetch(vm) {
|
|
35
|
-
return vm.$options && typeof vm.$options.fetch === 'function' && !vm.$options.fetch.length
|
|
38
|
+
return vm.$options && typeof vm.$options.fetch === 'function' && !vm.$options.fetch.length;
|
|
36
39
|
}
|
|
37
40
|
export function purifyData(data) {
|
|
38
41
|
if (process.env.NODE_ENV === 'production') {
|
|
39
|
-
return data
|
|
42
|
+
return data;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
return Object.entries(data).filter(
|
|
43
46
|
([key, value]) => {
|
|
44
|
-
const valid = !(value instanceof Function) && !(value instanceof Promise)
|
|
47
|
+
const valid = !(value instanceof Function) && !(value instanceof Promise);
|
|
48
|
+
|
|
45
49
|
if (!valid) {
|
|
46
|
-
console.warn(`${key} is not able to be stringified. This will break in a production environment.`)
|
|
50
|
+
console.warn(`${ key } is not able to be stringified. This will break in a production environment.`); // eslint-disable-line no-console
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
|
|
53
|
+
return valid;
|
|
49
54
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
).reduce((obj, [key, value]) => {
|
|
56
|
+
obj[key] = value;
|
|
57
|
+
|
|
58
|
+
return obj;
|
|
59
|
+
}, {});
|
|
54
60
|
}
|
|
55
61
|
export function getChildrenComponentInstancesUsingFetch(vm, instances = []) {
|
|
56
|
-
const children = vm.$children || []
|
|
62
|
+
const children = vm.$children || [];
|
|
63
|
+
|
|
57
64
|
for (const child of children) {
|
|
58
65
|
if (child.$fetch) {
|
|
59
|
-
instances.push(child)
|
|
66
|
+
instances.push(child);
|
|
60
67
|
continue; // Don't get the children since it will reload the template
|
|
61
68
|
}
|
|
62
69
|
if (child.$children) {
|
|
63
|
-
getChildrenComponentInstancesUsingFetch(child, instances)
|
|
70
|
+
getChildrenComponentInstancesUsingFetch(child, instances);
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
|
-
|
|
73
|
+
|
|
74
|
+
return instances;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
export function applyAsyncData
|
|
77
|
+
export function applyAsyncData(Component, asyncData) {
|
|
70
78
|
if (
|
|
71
79
|
// For SSR, we once all this function without second param to just apply asyncData
|
|
72
80
|
// Prevent doing this for each SSR request
|
|
73
81
|
!asyncData && Component.options.__hasNuxtData
|
|
74
82
|
) {
|
|
75
|
-
return
|
|
83
|
+
return;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
const ComponentData = Component.options._originDataFn || Component.options.data || function
|
|
79
|
-
|
|
86
|
+
const ComponentData = Component.options._originDataFn || Component.options.data || function() {
|
|
87
|
+
return {};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
Component.options._originDataFn = ComponentData;
|
|
91
|
+
|
|
92
|
+
Component.options.data = function() {
|
|
93
|
+
const data = ComponentData.call(this, this);
|
|
80
94
|
|
|
81
|
-
Component.options.data = function () {
|
|
82
|
-
const data = ComponentData.call(this, this)
|
|
83
95
|
if (this.$ssrContext) {
|
|
84
|
-
asyncData = this.$ssrContext.asyncData[Component.cid]
|
|
96
|
+
asyncData = this.$ssrContext.asyncData[Component.cid];
|
|
85
97
|
}
|
|
86
|
-
return { ...data, ...asyncData }
|
|
87
|
-
}
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
return { ...data, ...asyncData };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
Component.options.__hasNuxtData = true;
|
|
90
103
|
|
|
91
104
|
if (Component._Ctor && Component._Ctor.options) {
|
|
92
|
-
Component._Ctor.options.data = Component.options.data
|
|
105
|
+
Component._Ctor.options.data = Component.options.data;
|
|
93
106
|
}
|
|
94
107
|
}
|
|
95
108
|
|
|
96
|
-
export function sanitizeComponent
|
|
109
|
+
export function sanitizeComponent(Component) {
|
|
97
110
|
// If Component already sanitized
|
|
98
111
|
if (Component.options && Component._Ctor === Component) {
|
|
99
|
-
return Component
|
|
112
|
+
return Component;
|
|
100
113
|
}
|
|
101
114
|
if (!Component.options) {
|
|
102
|
-
Component = Vue.extend(Component) // fix issue #6
|
|
103
|
-
Component._Ctor = Component
|
|
115
|
+
Component = Vue.extend(Component); // fix issue #6
|
|
116
|
+
Component._Ctor = Component;
|
|
104
117
|
} else {
|
|
105
|
-
Component._Ctor = Component
|
|
106
|
-
Component.extendOptions = Component.options
|
|
118
|
+
Component._Ctor = Component;
|
|
119
|
+
Component.extendOptions = Component.options;
|
|
107
120
|
}
|
|
108
121
|
// If no component name defined, set file path as name, (also fixes #5703)
|
|
109
122
|
if (!Component.options.name && Component.options.__file) {
|
|
110
|
-
Component.options.name = Component.options.__file
|
|
123
|
+
Component.options.name = Component.options.__file;
|
|
111
124
|
}
|
|
112
|
-
|
|
125
|
+
|
|
126
|
+
return Component;
|
|
113
127
|
}
|
|
114
128
|
|
|
115
|
-
export function getMatchedComponents
|
|
129
|
+
export function getMatchedComponents(route, matches = false, prop = 'components') {
|
|
116
130
|
return Array.prototype.concat.apply([], route.matched.map((m, index) => {
|
|
117
131
|
return Object.keys(m[prop]).map((key) => {
|
|
118
|
-
matches && matches.push(index)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
132
|
+
matches && matches.push(index);
|
|
133
|
+
|
|
134
|
+
return m[prop][key];
|
|
135
|
+
});
|
|
136
|
+
}));
|
|
122
137
|
}
|
|
123
138
|
|
|
124
|
-
export function getMatchedComponentsInstances
|
|
125
|
-
return getMatchedComponents(route, matches, 'instances')
|
|
139
|
+
export function getMatchedComponentsInstances(route, matches = false) {
|
|
140
|
+
return getMatchedComponents(route, matches, 'instances');
|
|
126
141
|
}
|
|
127
142
|
|
|
128
|
-
export function flatMapComponents
|
|
143
|
+
export function flatMapComponents(route, fn) {
|
|
129
144
|
return Array.prototype.concat.apply([], route.matched.map((m, index) => {
|
|
130
145
|
return Object.keys(m.components).reduce((promises, key) => {
|
|
131
146
|
if (m.components[key]) {
|
|
132
|
-
promises.push(fn(m.components[key], m.instances[key], m, key, index))
|
|
147
|
+
promises.push(fn(m.components[key], m.instances[key], m, key, index));
|
|
133
148
|
} else {
|
|
134
|
-
delete m.components[key]
|
|
149
|
+
delete m.components[key];
|
|
135
150
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
151
|
+
|
|
152
|
+
return promises;
|
|
153
|
+
}, []);
|
|
154
|
+
}));
|
|
139
155
|
}
|
|
140
156
|
|
|
141
|
-
export function resolveRouteComponents
|
|
157
|
+
export function resolveRouteComponents(route, fn) {
|
|
142
158
|
return Promise.all(
|
|
143
|
-
flatMapComponents(route, async
|
|
159
|
+
flatMapComponents(route, async(Component, instance, match, key) => {
|
|
144
160
|
// If component is a function, resolve it
|
|
145
161
|
if (typeof Component === 'function' && !Component.options) {
|
|
146
162
|
try {
|
|
147
|
-
Component = await Component()
|
|
163
|
+
Component = await Component();
|
|
148
164
|
} catch (error) {
|
|
149
165
|
// Handle webpack chunk loading errors
|
|
150
166
|
// This may be due to a new deployment or a network problem
|
|
@@ -154,81 +170,86 @@ export function resolveRouteComponents (route, fn) {
|
|
|
154
170
|
typeof window !== 'undefined' &&
|
|
155
171
|
window.sessionStorage
|
|
156
172
|
) {
|
|
157
|
-
const timeNow = Date.now()
|
|
158
|
-
const previousReloadTime = parseInt(window.sessionStorage.getItem('nuxt-reload'))
|
|
173
|
+
const timeNow = Date.now();
|
|
174
|
+
const previousReloadTime = parseInt(window.sessionStorage.getItem('nuxt-reload'));
|
|
159
175
|
|
|
160
176
|
// check for previous reload time not to reload infinitely
|
|
161
177
|
if (!previousReloadTime || previousReloadTime + 60000 < timeNow) {
|
|
162
|
-
window.sessionStorage.setItem('nuxt-reload', timeNow)
|
|
163
|
-
window.location.reload(true /* skip cache */)
|
|
178
|
+
window.sessionStorage.setItem('nuxt-reload', timeNow);
|
|
179
|
+
window.location.reload(true /* skip cache */);
|
|
164
180
|
}
|
|
165
181
|
}
|
|
166
182
|
|
|
167
|
-
throw error
|
|
183
|
+
throw error;
|
|
168
184
|
}
|
|
169
185
|
}
|
|
170
|
-
match.components[key] = Component = sanitizeComponent(Component)
|
|
171
|
-
|
|
186
|
+
match.components[key] = Component = sanitizeComponent(Component);
|
|
187
|
+
|
|
188
|
+
return typeof fn === 'function' ? fn(Component, instance, match, key) : Component;
|
|
172
189
|
})
|
|
173
|
-
)
|
|
190
|
+
);
|
|
174
191
|
}
|
|
175
192
|
|
|
176
|
-
export async function getRouteData
|
|
193
|
+
export async function getRouteData(route) {
|
|
177
194
|
if (!route) {
|
|
178
|
-
return
|
|
195
|
+
return;
|
|
179
196
|
}
|
|
180
197
|
// Make sure the components are resolved (code-splitting)
|
|
181
|
-
await resolveRouteComponents(route)
|
|
198
|
+
await resolveRouteComponents(route);
|
|
199
|
+
|
|
182
200
|
// Send back a copy of route with meta based on Component definition
|
|
183
201
|
return {
|
|
184
202
|
...route,
|
|
185
203
|
meta: getMatchedComponents(route).map((Component, index) => {
|
|
186
|
-
return { ...Component.options.meta, ...(route.matched[index] || {}).meta }
|
|
204
|
+
return { ...Component.options.meta, ...(route.matched[index] || {}).meta };
|
|
187
205
|
})
|
|
188
|
-
}
|
|
206
|
+
};
|
|
189
207
|
}
|
|
190
208
|
|
|
191
|
-
export async function setContext
|
|
209
|
+
export async function setContext(app, context) {
|
|
192
210
|
// If context not defined, create it
|
|
193
211
|
if (!app.context) {
|
|
194
212
|
app.context = {
|
|
195
213
|
isStatic: process.static,
|
|
196
|
-
isDev:
|
|
197
|
-
isHMR:
|
|
214
|
+
isDev: true,
|
|
215
|
+
isHMR: false,
|
|
198
216
|
app,
|
|
199
|
-
store:
|
|
200
|
-
payload:
|
|
201
|
-
error:
|
|
202
|
-
base:
|
|
203
|
-
env:
|
|
204
|
-
|
|
217
|
+
store: app.store,
|
|
218
|
+
payload: context.payload,
|
|
219
|
+
error: context.error,
|
|
220
|
+
base: app.router.options.base,
|
|
221
|
+
env: {
|
|
222
|
+
commit: 'head', version: '0.1.2', dev: true, pl: 1, perfTest: false, rancherEnv: 'web', api: 'http://localhost:8989'
|
|
223
|
+
}
|
|
224
|
+
};
|
|
205
225
|
// Only set once
|
|
206
226
|
|
|
207
227
|
if (context.req) {
|
|
208
|
-
app.context.req = context.req
|
|
228
|
+
app.context.req = context.req;
|
|
209
229
|
}
|
|
210
230
|
if (context.res) {
|
|
211
|
-
app.context.res = context.res
|
|
231
|
+
app.context.res = context.res;
|
|
212
232
|
}
|
|
213
233
|
|
|
214
234
|
if (context.ssrContext) {
|
|
215
|
-
app.context.ssrContext = context.ssrContext
|
|
235
|
+
app.context.ssrContext = context.ssrContext;
|
|
216
236
|
}
|
|
217
237
|
app.context.redirect = (status, path, query) => {
|
|
218
238
|
if (!status) {
|
|
219
|
-
return
|
|
239
|
+
return;
|
|
220
240
|
}
|
|
221
|
-
app.context._redirected = true
|
|
241
|
+
app.context._redirected = true;
|
|
222
242
|
// if only 1 or 2 arguments: redirect('/') or redirect('/', { foo: 'bar' })
|
|
223
|
-
let pathType = typeof path
|
|
243
|
+
let pathType = typeof path;
|
|
244
|
+
|
|
224
245
|
if (typeof status !== 'number' && (pathType === 'undefined' || pathType === 'object')) {
|
|
225
|
-
query = path || {}
|
|
226
|
-
path = status
|
|
227
|
-
pathType = typeof path
|
|
228
|
-
status = 302
|
|
246
|
+
query = path || {};
|
|
247
|
+
path = status;
|
|
248
|
+
pathType = typeof path;
|
|
249
|
+
status = 302;
|
|
229
250
|
}
|
|
230
251
|
if (pathType === 'object') {
|
|
231
|
-
path = app.router.resolve(path).route.fullPath
|
|
252
|
+
path = app.router.resolve(path).route.fullPath;
|
|
232
253
|
}
|
|
233
254
|
// "/absolute/route", "./relative/route" or "../relative/route"
|
|
234
255
|
if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) {
|
|
@@ -236,29 +257,29 @@ export async function setContext (app, context) {
|
|
|
236
257
|
path,
|
|
237
258
|
query,
|
|
238
259
|
status
|
|
239
|
-
})
|
|
260
|
+
});
|
|
240
261
|
} else {
|
|
241
|
-
path = withQuery(path, query)
|
|
262
|
+
path = withQuery(path, query);
|
|
242
263
|
if (process.server) {
|
|
243
264
|
app.context.next({
|
|
244
265
|
path,
|
|
245
266
|
status
|
|
246
|
-
})
|
|
267
|
+
});
|
|
247
268
|
}
|
|
248
269
|
if (process.client) {
|
|
249
270
|
// https://developer.mozilla.org/en-US/docs/Web/API/Location/replace
|
|
250
|
-
window.location.replace(path)
|
|
271
|
+
window.location.replace(path);
|
|
251
272
|
|
|
252
273
|
// Throw a redirect error
|
|
253
|
-
throw new Error('ERR_REDIRECT')
|
|
274
|
+
throw new Error('ERR_REDIRECT');
|
|
254
275
|
}
|
|
255
276
|
}
|
|
256
|
-
}
|
|
277
|
+
};
|
|
257
278
|
if (process.server) {
|
|
258
|
-
app.context.beforeNuxtRender = fn => context.beforeRenderFns.push(fn)
|
|
279
|
+
app.context.beforeNuxtRender = fn => context.beforeRenderFns.push(fn);
|
|
259
280
|
}
|
|
260
281
|
if (process.client) {
|
|
261
|
-
app.context.nuxtState = window.__NUXT__
|
|
282
|
+
app.context.nuxtState = window.__NUXT__;
|
|
262
283
|
}
|
|
263
284
|
}
|
|
264
285
|
|
|
@@ -266,76 +287,78 @@ export async function setContext (app, context) {
|
|
|
266
287
|
const [currentRouteData, fromRouteData] = await Promise.all([
|
|
267
288
|
getRouteData(context.route),
|
|
268
289
|
getRouteData(context.from)
|
|
269
|
-
])
|
|
290
|
+
]);
|
|
270
291
|
|
|
271
292
|
if (context.route) {
|
|
272
|
-
app.context.route = currentRouteData
|
|
293
|
+
app.context.route = currentRouteData;
|
|
273
294
|
}
|
|
274
295
|
|
|
275
296
|
if (context.from) {
|
|
276
|
-
app.context.from = fromRouteData
|
|
297
|
+
app.context.from = fromRouteData;
|
|
277
298
|
}
|
|
278
299
|
|
|
279
|
-
app.context.next = context.next
|
|
280
|
-
app.context._redirected = false
|
|
281
|
-
app.context._errored = false
|
|
282
|
-
app.context.isHMR = Boolean(context.isHMR)
|
|
283
|
-
app.context.params = app.context.route.params || {}
|
|
284
|
-
app.context.query = app.context.route.query || {}
|
|
300
|
+
app.context.next = context.next;
|
|
301
|
+
app.context._redirected = false;
|
|
302
|
+
app.context._errored = false;
|
|
303
|
+
app.context.isHMR = Boolean(context.isHMR);
|
|
304
|
+
app.context.params = app.context.route.params || {};
|
|
305
|
+
app.context.query = app.context.route.query || {};
|
|
285
306
|
}
|
|
286
307
|
|
|
287
|
-
export function middlewareSeries
|
|
308
|
+
export function middlewareSeries(promises, appContext) {
|
|
288
309
|
if (!promises.length || appContext._redirected || appContext._errored) {
|
|
289
|
-
return Promise.resolve()
|
|
310
|
+
return Promise.resolve();
|
|
290
311
|
}
|
|
312
|
+
|
|
291
313
|
return promisify(promises[0], appContext)
|
|
292
314
|
.then(() => {
|
|
293
|
-
return middlewareSeries(promises.slice(1), appContext)
|
|
294
|
-
})
|
|
315
|
+
return middlewareSeries(promises.slice(1), appContext);
|
|
316
|
+
});
|
|
295
317
|
}
|
|
296
318
|
|
|
297
|
-
export function promisify
|
|
298
|
-
let promise
|
|
319
|
+
export function promisify(fn, context) {
|
|
320
|
+
let promise;
|
|
321
|
+
|
|
299
322
|
if (fn.length === 2) {
|
|
300
|
-
|
|
301
|
-
'Please switch to promises or async/await syntax')
|
|
323
|
+
console.warn('Callback-based asyncData, fetch or middleware calls are deprecated. Please switch to promises or async/await syntax'); // eslint-disable-line no-console
|
|
302
324
|
|
|
303
325
|
// fn(context, callback)
|
|
304
326
|
promise = new Promise((resolve) => {
|
|
305
|
-
fn(context,
|
|
327
|
+
fn(context, (err, data) => {
|
|
306
328
|
if (err) {
|
|
307
|
-
context.error(err)
|
|
329
|
+
context.error(err);
|
|
308
330
|
}
|
|
309
|
-
data = data || {}
|
|
310
|
-
resolve(data)
|
|
311
|
-
})
|
|
312
|
-
})
|
|
331
|
+
data = data || {};
|
|
332
|
+
resolve(data);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
313
335
|
} else {
|
|
314
|
-
promise = fn(context)
|
|
336
|
+
promise = fn(context);
|
|
315
337
|
}
|
|
316
338
|
|
|
317
339
|
if (promise && promise instanceof Promise && typeof promise.then === 'function') {
|
|
318
|
-
return promise
|
|
340
|
+
return promise;
|
|
319
341
|
}
|
|
320
|
-
|
|
342
|
+
|
|
343
|
+
return Promise.resolve(promise);
|
|
321
344
|
}
|
|
322
345
|
|
|
323
346
|
// Imported from vue-router
|
|
324
|
-
export function getLocation
|
|
347
|
+
export function getLocation(base, mode) {
|
|
325
348
|
if (mode === 'hash') {
|
|
326
|
-
return window.location.hash.replace(/^#\//, '')
|
|
349
|
+
return window.location.hash.replace(/^#\//, '');
|
|
327
350
|
}
|
|
328
351
|
|
|
329
|
-
base = decodeURI(base).slice(0, -1) // consideration is base is normalized with trailing slash
|
|
330
|
-
let path = decodeURI(window.location.pathname)
|
|
352
|
+
base = decodeURI(base).slice(0, -1); // consideration is base is normalized with trailing slash
|
|
353
|
+
let path = decodeURI(window.location.pathname);
|
|
331
354
|
|
|
332
355
|
if (base && path.startsWith(base)) {
|
|
333
|
-
path = path.slice(base.length)
|
|
356
|
+
path = path.slice(base.length);
|
|
334
357
|
}
|
|
335
358
|
|
|
336
|
-
const fullPath = (path || '/') + window.location.search + window.location.hash
|
|
359
|
+
const fullPath = (path || '/') + window.location.search + window.location.hash;
|
|
337
360
|
|
|
338
|
-
return normalizeURL(fullPath)
|
|
361
|
+
return normalizeURL(fullPath);
|
|
339
362
|
}
|
|
340
363
|
|
|
341
364
|
// Imported from path-to-regexp
|
|
@@ -347,37 +370,41 @@ export function getLocation (base, mode) {
|
|
|
347
370
|
* @param {Object=} options
|
|
348
371
|
* @return {!function(Object=, Object=)}
|
|
349
372
|
*/
|
|
350
|
-
export function compile
|
|
351
|
-
return tokensToFunction(parse(str, options), options)
|
|
373
|
+
export function compile(str, options) {
|
|
374
|
+
return tokensToFunction(parse(str, options), options);
|
|
352
375
|
}
|
|
353
376
|
|
|
354
|
-
export function getQueryDiff
|
|
355
|
-
const diff = {}
|
|
356
|
-
const queries = { ...toQuery, ...fromQuery }
|
|
377
|
+
export function getQueryDiff(toQuery, fromQuery) {
|
|
378
|
+
const diff = {};
|
|
379
|
+
const queries = { ...toQuery, ...fromQuery };
|
|
380
|
+
|
|
357
381
|
for (const k in queries) {
|
|
358
382
|
if (String(toQuery[k]) !== String(fromQuery[k])) {
|
|
359
|
-
diff[k] = true
|
|
383
|
+
diff[k] = true;
|
|
360
384
|
}
|
|
361
385
|
}
|
|
362
|
-
|
|
386
|
+
|
|
387
|
+
return diff;
|
|
363
388
|
}
|
|
364
389
|
|
|
365
|
-
export function normalizeError
|
|
366
|
-
let message
|
|
390
|
+
export function normalizeError(err) {
|
|
391
|
+
let message;
|
|
392
|
+
|
|
367
393
|
if (!(err.message || typeof err === 'string')) {
|
|
368
394
|
try {
|
|
369
|
-
message = JSON.stringify(err, null, 2)
|
|
395
|
+
message = JSON.stringify(err, null, 2);
|
|
370
396
|
} catch (e) {
|
|
371
|
-
message = `[${err.constructor.name}]
|
|
397
|
+
message = `[${ err.constructor.name }]`;
|
|
372
398
|
}
|
|
373
399
|
} else {
|
|
374
|
-
message = err.message || err
|
|
400
|
+
message = err.message || err;
|
|
375
401
|
}
|
|
402
|
+
|
|
376
403
|
return {
|
|
377
404
|
...err,
|
|
378
405
|
message,
|
|
379
406
|
statusCode: (err.statusCode || err.status || (err.response && err.response.status) || 500)
|
|
380
|
-
}
|
|
407
|
+
};
|
|
381
408
|
}
|
|
382
409
|
|
|
383
410
|
/**
|
|
@@ -396,7 +423,7 @@ const PATH_REGEXP = new RegExp([
|
|
|
396
423
|
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
|
|
397
424
|
// "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
|
|
398
425
|
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
|
|
399
|
-
].join('|'), 'g')
|
|
426
|
+
].join('|'), 'g');
|
|
400
427
|
|
|
401
428
|
/**
|
|
402
429
|
* Parse a string for the raw tokens.
|
|
@@ -405,70 +432,71 @@ const PATH_REGEXP = new RegExp([
|
|
|
405
432
|
* @param {Object=} options
|
|
406
433
|
* @return {!Array}
|
|
407
434
|
*/
|
|
408
|
-
function parse
|
|
409
|
-
const tokens = []
|
|
410
|
-
let key = 0
|
|
411
|
-
let index = 0
|
|
412
|
-
let path = ''
|
|
413
|
-
const defaultDelimiter = (options && options.delimiter) || '/'
|
|
414
|
-
let res
|
|
415
|
-
|
|
416
|
-
while ((res = PATH_REGEXP.exec(str))
|
|
417
|
-
const m = res[0]
|
|
418
|
-
const escaped = res[1]
|
|
419
|
-
const offset = res.index
|
|
420
|
-
|
|
421
|
-
index
|
|
435
|
+
function parse(str, options) {
|
|
436
|
+
const tokens = [];
|
|
437
|
+
let key = 0;
|
|
438
|
+
let index = 0;
|
|
439
|
+
let path = '';
|
|
440
|
+
const defaultDelimiter = (options && options.delimiter) || '/';
|
|
441
|
+
let res;
|
|
442
|
+
|
|
443
|
+
while ((res = PATH_REGEXP.exec(str)) !== null) {
|
|
444
|
+
const m = res[0];
|
|
445
|
+
const escaped = res[1];
|
|
446
|
+
const offset = res.index;
|
|
447
|
+
|
|
448
|
+
path += str.slice(index, offset);
|
|
449
|
+
index = offset + m.length;
|
|
422
450
|
|
|
423
451
|
// Ignore already escaped sequences.
|
|
424
452
|
if (escaped) {
|
|
425
|
-
path += escaped[1]
|
|
426
|
-
continue
|
|
453
|
+
path += escaped[1];
|
|
454
|
+
continue;
|
|
427
455
|
}
|
|
428
456
|
|
|
429
|
-
const next = str[index]
|
|
430
|
-
const prefix = res[2]
|
|
431
|
-
const name = res[3]
|
|
432
|
-
const capture = res[4]
|
|
433
|
-
const group = res[5]
|
|
434
|
-
const modifier = res[6]
|
|
435
|
-
const asterisk = res[7]
|
|
457
|
+
const next = str[index];
|
|
458
|
+
const prefix = res[2];
|
|
459
|
+
const name = res[3];
|
|
460
|
+
const capture = res[4];
|
|
461
|
+
const group = res[5];
|
|
462
|
+
const modifier = res[6];
|
|
463
|
+
const asterisk = res[7];
|
|
436
464
|
|
|
437
465
|
// Push the current path onto the tokens.
|
|
438
466
|
if (path) {
|
|
439
|
-
tokens.push(path)
|
|
440
|
-
path = ''
|
|
467
|
+
tokens.push(path);
|
|
468
|
+
path = '';
|
|
441
469
|
}
|
|
442
470
|
|
|
443
|
-
const partial = prefix
|
|
444
|
-
const repeat = modifier === '+' || modifier === '*'
|
|
445
|
-
const optional = modifier === '?' || modifier === '*'
|
|
446
|
-
const delimiter = res[2] || defaultDelimiter
|
|
447
|
-
const pattern = capture || group
|
|
471
|
+
const partial = prefix !== null && next !== null && next !== prefix;
|
|
472
|
+
const repeat = modifier === '+' || modifier === '*';
|
|
473
|
+
const optional = modifier === '?' || modifier === '*';
|
|
474
|
+
const delimiter = res[2] || defaultDelimiter;
|
|
475
|
+
const pattern = capture || group;
|
|
448
476
|
|
|
449
477
|
tokens.push({
|
|
450
|
-
name:
|
|
451
|
-
prefix:
|
|
478
|
+
name: name || key++,
|
|
479
|
+
prefix: prefix || '',
|
|
452
480
|
delimiter,
|
|
453
481
|
optional,
|
|
454
482
|
repeat,
|
|
455
483
|
partial,
|
|
456
484
|
asterisk: Boolean(asterisk),
|
|
457
|
-
pattern:
|
|
458
|
-
})
|
|
485
|
+
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : `[^${ escapeString(delimiter) }]+?`)
|
|
486
|
+
});
|
|
459
487
|
}
|
|
460
488
|
|
|
461
489
|
// Match any characters still remaining.
|
|
462
490
|
if (index < str.length) {
|
|
463
|
-
path += str.substr(index)
|
|
491
|
+
path += str.substr(index);
|
|
464
492
|
}
|
|
465
493
|
|
|
466
494
|
// If the path exists, push it onto the end.
|
|
467
495
|
if (path) {
|
|
468
|
-
tokens.push(path)
|
|
496
|
+
tokens.push(path);
|
|
469
497
|
}
|
|
470
498
|
|
|
471
|
-
return tokens
|
|
499
|
+
return tokens;
|
|
472
500
|
}
|
|
473
501
|
|
|
474
502
|
/**
|
|
@@ -477,11 +505,12 @@ function parse (str, options) {
|
|
|
477
505
|
* @param {string}
|
|
478
506
|
* @return {string}
|
|
479
507
|
*/
|
|
480
|
-
function encodeURIComponentPretty
|
|
481
|
-
const re = slashAllowed ? /[?#]/g : /[/?#]/g
|
|
508
|
+
function encodeURIComponentPretty(str, slashAllowed) {
|
|
509
|
+
const re = slashAllowed ? /[?#]/g : /[/?#]/g;
|
|
510
|
+
|
|
482
511
|
return encodeURI(str).replace(re, (c) => {
|
|
483
|
-
return
|
|
484
|
-
})
|
|
512
|
+
return `%${ c.charCodeAt(0).toString(16).toUpperCase() }`;
|
|
513
|
+
});
|
|
485
514
|
}
|
|
486
515
|
|
|
487
516
|
/**
|
|
@@ -490,8 +519,8 @@ function encodeURIComponentPretty (str, slashAllowed) {
|
|
|
490
519
|
* @param {string}
|
|
491
520
|
* @return {string}
|
|
492
521
|
*/
|
|
493
|
-
function encodeAsterisk
|
|
494
|
-
return encodeURIComponentPretty(str, true)
|
|
522
|
+
function encodeAsterisk(str) {
|
|
523
|
+
return encodeURIComponentPretty(str, true);
|
|
495
524
|
}
|
|
496
525
|
|
|
497
526
|
/**
|
|
@@ -500,8 +529,8 @@ function encodeAsterisk (str) {
|
|
|
500
529
|
* @param {string} str
|
|
501
530
|
* @return {string}
|
|
502
531
|
*/
|
|
503
|
-
function escapeString
|
|
504
|
-
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
|
|
532
|
+
function escapeString(str) {
|
|
533
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
|
|
505
534
|
}
|
|
506
535
|
|
|
507
536
|
/**
|
|
@@ -510,92 +539,92 @@ function escapeString (str) {
|
|
|
510
539
|
* @param {string} group
|
|
511
540
|
* @return {string}
|
|
512
541
|
*/
|
|
513
|
-
function escapeGroup
|
|
514
|
-
return group.replace(/([=!:$/()])/g, '\\$1')
|
|
542
|
+
function escapeGroup(group) {
|
|
543
|
+
return group.replace(/([=!:$/()])/g, '\\$1');
|
|
515
544
|
}
|
|
516
545
|
|
|
517
546
|
/**
|
|
518
547
|
* Expose a method for transforming tokens into the path function.
|
|
519
548
|
*/
|
|
520
|
-
function tokensToFunction
|
|
549
|
+
function tokensToFunction(tokens, options) {
|
|
521
550
|
// Compile all the tokens into regexps.
|
|
522
|
-
const matches = new Array(tokens.length)
|
|
551
|
+
const matches = new Array(tokens.length);
|
|
523
552
|
|
|
524
553
|
// Compile all the patterns before compilation.
|
|
525
554
|
for (let i = 0; i < tokens.length; i++) {
|
|
526
555
|
if (typeof tokens[i] === 'object') {
|
|
527
|
-
matches[i] = new RegExp(
|
|
556
|
+
matches[i] = new RegExp(`^(?:${ tokens[i].pattern })$`, flags(options));
|
|
528
557
|
}
|
|
529
558
|
}
|
|
530
559
|
|
|
531
|
-
return function
|
|
532
|
-
let path = ''
|
|
533
|
-
const data = obj || {}
|
|
534
|
-
const options = opts || {}
|
|
535
|
-
const encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent
|
|
560
|
+
return function(obj, opts) {
|
|
561
|
+
let path = '';
|
|
562
|
+
const data = obj || {};
|
|
563
|
+
const options = opts || {};
|
|
564
|
+
const encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
|
|
536
565
|
|
|
537
566
|
for (let i = 0; i < tokens.length; i++) {
|
|
538
|
-
const token = tokens[i]
|
|
567
|
+
const token = tokens[i];
|
|
539
568
|
|
|
540
569
|
if (typeof token === 'string') {
|
|
541
|
-
path += token
|
|
570
|
+
path += token;
|
|
542
571
|
|
|
543
|
-
continue
|
|
572
|
+
continue;
|
|
544
573
|
}
|
|
545
574
|
|
|
546
|
-
const value = data[token.name || 'pathMatch']
|
|
547
|
-
let segment
|
|
575
|
+
const value = data[token.name || 'pathMatch'];
|
|
576
|
+
let segment;
|
|
548
577
|
|
|
549
|
-
if (value
|
|
578
|
+
if (value === null) {
|
|
550
579
|
if (token.optional) {
|
|
551
580
|
// Prepend partial segment prefixes.
|
|
552
581
|
if (token.partial) {
|
|
553
|
-
path += token.prefix
|
|
582
|
+
path += token.prefix;
|
|
554
583
|
}
|
|
555
584
|
|
|
556
|
-
continue
|
|
585
|
+
continue;
|
|
557
586
|
} else {
|
|
558
|
-
throw new TypeError(
|
|
587
|
+
throw new TypeError(`Expected "${ token.name }" to be defined`);
|
|
559
588
|
}
|
|
560
589
|
}
|
|
561
590
|
|
|
562
591
|
if (Array.isArray(value)) {
|
|
563
592
|
if (!token.repeat) {
|
|
564
|
-
throw new TypeError(
|
|
593
|
+
throw new TypeError(`Expected "${ token.name }" to not repeat, but received \`${ JSON.stringify(value) }\``);
|
|
565
594
|
}
|
|
566
595
|
|
|
567
596
|
if (value.length === 0) {
|
|
568
597
|
if (token.optional) {
|
|
569
|
-
continue
|
|
598
|
+
continue;
|
|
570
599
|
} else {
|
|
571
|
-
throw new TypeError(
|
|
600
|
+
throw new TypeError(`Expected "${ token.name }" to not be empty`);
|
|
572
601
|
}
|
|
573
602
|
}
|
|
574
603
|
|
|
575
604
|
for (let j = 0; j < value.length; j++) {
|
|
576
|
-
segment = encode(value[j])
|
|
605
|
+
segment = encode(value[j]);
|
|
577
606
|
|
|
578
607
|
if (!matches[i].test(segment)) {
|
|
579
|
-
throw new TypeError(
|
|
608
|
+
throw new TypeError(`Expected all "${ token.name }" to match "${ token.pattern }", but received \`${ JSON.stringify(segment) }\``);
|
|
580
609
|
}
|
|
581
610
|
|
|
582
|
-
path += (j === 0 ? token.prefix : token.delimiter) + segment
|
|
611
|
+
path += (j === 0 ? token.prefix : token.delimiter) + segment;
|
|
583
612
|
}
|
|
584
613
|
|
|
585
|
-
continue
|
|
614
|
+
continue;
|
|
586
615
|
}
|
|
587
616
|
|
|
588
|
-
segment = token.asterisk ? encodeAsterisk(value) : encode(value)
|
|
617
|
+
segment = token.asterisk ? encodeAsterisk(value) : encode(value);
|
|
589
618
|
|
|
590
619
|
if (!matches[i].test(segment)) {
|
|
591
|
-
throw new TypeError(
|
|
620
|
+
throw new TypeError(`Expected "${ token.name }" to match "${ token.pattern }", but received "${ segment }"`);
|
|
592
621
|
}
|
|
593
622
|
|
|
594
|
-
path += token.prefix + segment
|
|
623
|
+
path += token.prefix + segment;
|
|
595
624
|
}
|
|
596
625
|
|
|
597
|
-
return path
|
|
598
|
-
}
|
|
626
|
+
return path;
|
|
627
|
+
};
|
|
599
628
|
}
|
|
600
629
|
|
|
601
630
|
/**
|
|
@@ -604,27 +633,27 @@ function tokensToFunction (tokens, options) {
|
|
|
604
633
|
* @param {Object} options
|
|
605
634
|
* @return {string}
|
|
606
635
|
*/
|
|
607
|
-
function flags
|
|
608
|
-
return options && options.sensitive ? '' : 'i'
|
|
636
|
+
function flags(options) {
|
|
637
|
+
return options && options.sensitive ? '' : 'i';
|
|
609
638
|
}
|
|
610
639
|
|
|
611
640
|
export function addLifecycleHook(vm, hook, fn) {
|
|
612
641
|
if (!vm.$options[hook]) {
|
|
613
|
-
vm.$options[hook] = []
|
|
642
|
+
vm.$options[hook] = [];
|
|
614
643
|
}
|
|
615
644
|
if (!vm.$options[hook].includes(fn)) {
|
|
616
|
-
vm.$options[hook].push(fn)
|
|
645
|
+
vm.$options[hook].push(fn);
|
|
617
646
|
}
|
|
618
647
|
}
|
|
619
648
|
|
|
620
|
-
export const urlJoin = joinURL
|
|
649
|
+
export const urlJoin = joinURL;
|
|
621
650
|
|
|
622
|
-
export const stripTrailingSlash = withoutTrailingSlash
|
|
651
|
+
export const stripTrailingSlash = withoutTrailingSlash;
|
|
623
652
|
|
|
624
|
-
export const isSamePath = _isSamePath
|
|
653
|
+
export const isSamePath = _isSamePath;
|
|
625
654
|
|
|
626
|
-
export function setScrollRestoration
|
|
655
|
+
export function setScrollRestoration(newVal) {
|
|
627
656
|
try {
|
|
628
657
|
window.history.scrollRestoration = newVal;
|
|
629
|
-
} catch(e) {}
|
|
658
|
+
} catch (e) {}
|
|
630
659
|
}
|