@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.
Files changed (120) hide show
  1. package/assets/images/providers/outscale.svg +19 -0
  2. package/assets/styles/base/_basic.scss +18 -0
  3. package/assets/styles/base/_mixins.scss +0 -11
  4. package/assets/styles/base/_variables.scss +2 -4
  5. package/assets/styles/global/_button.scss +12 -2
  6. package/assets/translations/en-us.yaml +35 -1
  7. package/assets/translations/zh-hans.yaml +30 -10
  8. package/chart/gatekeeper.vue +3 -2
  9. package/chart/istio.vue +29 -3
  10. package/components/BrandImage.vue +1 -4
  11. package/components/Carousel.vue +85 -37
  12. package/components/EtcdInfoBanner.vue +7 -3
  13. package/components/ExplorerMembers.vue +100 -5
  14. package/components/ExplorerProjectsNamespaces.vue +32 -2
  15. package/components/GrafanaDashboard.vue +9 -2
  16. package/components/SortableTable/index.vue +23 -11
  17. package/components/SortableTable/selection.js +58 -50
  18. package/components/Wizard.vue +4 -2
  19. package/components/auth/AuthBanner.vue +6 -0
  20. package/components/auth/RoleDetailEdit.vue +2 -2
  21. package/components/form/HookOption.vue +14 -10
  22. package/components/form/Labels.vue +32 -27
  23. package/components/form/MatchExpressions.vue +2 -2
  24. package/components/form/Members/ClusterPermissionsEditor.vue +32 -7
  25. package/components/form/NameNsDescription.vue +1 -1
  26. package/components/form/ProjectMemberEditor.vue +46 -21
  27. package/components/form/Tolerations.vue +4 -1
  28. package/components/form/ValueFromResource.vue +14 -9
  29. package/components/form/WorkloadPorts.vue +2 -2
  30. package/components/form/__tests__/NameNsDescription.ts +27 -0
  31. package/components/formatter/WorkloadHealthScale.vue +8 -2
  32. package/components/nav/NamespaceFilter.vue +8 -0
  33. package/{nuxt/components → components/nuxt}/nuxt.js +1 -1
  34. package/{nuxt → config}/middleware.js +8 -8
  35. package/config/product/explorer.js +24 -3
  36. package/config/query-params.js +1 -0
  37. package/config/router.js +1 -1
  38. package/{nuxt → config}/store.js +82 -79
  39. package/config/table-headers.js +46 -12
  40. package/config/types.js +7 -0
  41. package/core/plugin.ts +4 -2
  42. package/core/types.ts +258 -1
  43. package/creators/app/files/tsconfig.json +0 -1
  44. package/creators/app/files/vue.config.js +0 -1
  45. package/creators/pkg/files/.github/workflows/build-extension.yml +3 -4
  46. package/creators/pkg/files/tsconfig.json +0 -1
  47. package/creators/pkg/pkg.package.json +3 -3
  48. package/detail/constraints.gatekeeper.sh.constraint.vue +14 -7
  49. package/detail/fleet.cattle.io.clustergroup.vue +7 -1
  50. package/edit/auth/ldap/config.vue +21 -1
  51. package/edit/auth/saml.vue +132 -37
  52. package/edit/fleet.cattle.io.gitrepo.vue +16 -1
  53. package/edit/logging.banzaicloud.io.output/index.vue +18 -5
  54. package/edit/logging.banzaicloud.io.output/providers/loki.vue +1 -0
  55. package/edit/namespace.vue +12 -8
  56. package/edit/provisioning.cattle.io.cluster/MachinePool.vue +11 -4
  57. package/edit/provisioning.cattle.io.cluster/import.vue +23 -25
  58. package/edit/provisioning.cattle.io.cluster/rke2.vue +96 -18
  59. package/edit/workload/mixins/workload.js +6 -7
  60. package/edit/workload/storage/Mount.vue +3 -3
  61. package/initialize/App.js +206 -0
  62. package/{nuxt → initialize}/client.js +406 -360
  63. package/{nuxt → initialize}/index.js +21 -22
  64. package/layouts/standalone.vue +13 -0
  65. package/list/catalog.cattle.io.clusterrepo.vue +1 -0
  66. package/list/rbac.authorization.k8s.io.clusterrolebinding.vue +48 -0
  67. package/list/workload.vue +6 -4
  68. package/mixins/chart.js +29 -1
  69. package/mixins/fetch.client.js +95 -0
  70. package/{nuxt/mixins → mixins}/fetch.server.js +30 -26
  71. package/mixins/labeled-form-element.ts +2 -2
  72. package/models/constraints.gatekeeper.sh.constraint.js +37 -0
  73. package/models/pod.js +4 -0
  74. package/models/rbac.authorization.k8s.io.clusterrolebinding.js +16 -0
  75. package/models/rbac.authorization.k8s.io.rolebinding.js +16 -0
  76. package/package.json +9 -13
  77. package/pages/c/_cluster/apps/charts/install.vue +61 -39
  78. package/pages/diagnostic.vue +32 -25
  79. package/pages/rio/mesh.vue +1 -2
  80. package/pkg/tsconfig.json +0 -1
  81. package/plugins/clean-html-directive.js +3 -0
  82. package/plugins/dashboard-store/index.js +1 -1
  83. package/plugins/plugin.js +0 -14
  84. package/plugins/portal-vue.js +4 -0
  85. package/rancher-components/components/Banner/Banner.test.ts +3 -5
  86. package/rancher-components/components/Banner/Banner.vue +1 -0
  87. package/rancher-components/components/Form/Radio/RadioButton.test.ts +31 -0
  88. package/rancher-components/components/Form/Radio/RadioButton.vue +14 -3
  89. package/scripts/extension/publish +42 -23
  90. package/scripts/serve-pkgs +6 -2
  91. package/store/type-map.js +1 -1
  92. package/tsconfig.json +0 -1
  93. package/types/rancher/index.d.ts +2 -0
  94. package/types/shell/index.d.ts +353 -284
  95. package/utils/__tests__/grafana.test.ts +44 -0
  96. package/utils/axios.js +190 -0
  97. package/{nuxt → utils}/cookie-universal-nuxt.js +7 -6
  98. package/utils/dom.js +15 -0
  99. package/utils/gc/gc.ts +1 -1
  100. package/utils/grafana.js +35 -16
  101. package/{nuxt/utils.js → utils/nuxt.js} +265 -236
  102. package/utils/router.scrollBehavior.js +1 -1
  103. package/vue.config.js +30 -19
  104. package/nuxt/App.js +0 -210
  105. package/nuxt/axios.js +0 -186
  106. package/nuxt/empty.js +0 -1
  107. package/nuxt/jsonp.js +0 -82
  108. package/nuxt/loading.html +0 -39
  109. package/nuxt/mixins/fetch.client.js +0 -90
  110. package/nuxt/portal-vue.js +0 -4
  111. package/nuxt/server.js +0 -312
  112. package/nuxt/views/app.template.html +0 -9
  113. package/nuxt/views/error.html +0 -23
  114. package/plugins/dashboard-store/extensions.js +0 -22
  115. /package/{nuxt/components → components/nuxt}/nuxt-build-indicator.vue +0 -0
  116. /package/{nuxt/components → components/nuxt}/nuxt-child.js +0 -0
  117. /package/{nuxt/components → components/nuxt}/nuxt-error.vue +0 -0
  118. /package/{nuxt/components → components/nuxt}/nuxt-link.client.js +0 -0
  119. /package/{nuxt/components → components/nuxt}/nuxt-link.server.js +0 -0
  120. /package/{nuxt/components → components/nuxt}/nuxt-loading.vue +0 -0
@@ -1,4 +1,4 @@
1
- import { getMatchedComponents, setScrollRestoration } from '../nuxt/utils';
1
+ import { getMatchedComponents, setScrollRestoration } from './nuxt';
2
2
 
3
3
  if (process.client) {
4
4
  if ('scrollRestoration' in window.history) {
package/vue.config.js CHANGED
@@ -4,8 +4,17 @@ const serveStatic = require('serve-static');
4
4
  const webpack = require('webpack');
5
5
  const { generateDynamicTypeImport } = require('./pkg/auto-import');
6
6
  const CopyWebpackPlugin = require('copy-webpack-plugin');
7
+
8
+ // Suppress info level logging messages from http-proxy-middleware
9
+ // This hides all of the "[HPM Proxy created] ..." messages
10
+ const oldInfoLogger = console.info; // eslint-disable-line no-console
11
+
12
+ console.info = () => {}; // eslint-disable-line no-console
13
+
7
14
  const { createProxyMiddleware } = require('http-proxy-middleware');
8
15
 
16
+ console.info = oldInfoLogger; // eslint-disable-line no-console
17
+
9
18
  // This is currently hardcoded to avoid importing the TS
10
19
  // const { STANDARD } = require('./config/private-label');
11
20
  const STANDARD = 1;
@@ -78,32 +87,14 @@ module.exports = function(dir, _appConfig) {
78
87
 
79
88
  const appConfig = _appConfig || {};
80
89
  const excludes = appConfig.excludes || [];
81
- const autoLoad = appConfig.autoLoad || [];
82
90
 
83
91
  const serverMiddleware = [];
84
- const autoLoadPackages = [];
85
92
  const watcherIgnores = [
86
93
  /.shell/,
87
94
  /dist-pkg/,
88
95
  /scripts\/standalone/
89
96
  ];
90
97
 
91
- autoLoad.forEach((pkg) => {
92
- // Need the version number of each file
93
- const pkgPackageFile = require(path.join(dir, 'pkg', pkg, 'package.json'));
94
- const pkgRef = `${ pkg }-${ pkgPackageFile.version }`;
95
-
96
- autoLoadPackages.push({
97
- name: `app-autoload-${ pkgRef }`,
98
- content: `/pkg/${ pkgRef }/${ pkgRef }.umd.min.js`
99
- });
100
-
101
- // Anything auto-loaded should also be excluded
102
- if (!excludes.includes(pkg)) {
103
- excludes.push(pkg);
104
- }
105
- });
106
-
107
98
  // Find any UI packages in node_modules
108
99
  const NM = path.join(dir, 'node_modules');
109
100
  const pkg = require(path.join(dir, 'package.json'));
@@ -321,6 +312,13 @@ module.exports = function(dir, _appConfig) {
321
312
  before(app, server) {
322
313
  const socketProxies = {};
323
314
 
315
+ // Close down quickly in response to CTRL + C
316
+ process.once('SIGINT', () => {
317
+ server.close();
318
+ console.log('\n'); // eslint-disable-line no-console
319
+ process.exit(1);
320
+ });
321
+
324
322
  Object.keys(proxy).forEach((p) => {
325
323
  const px = createProxyMiddleware({
326
324
  ...proxy[p],
@@ -371,7 +369,7 @@ module.exports = function(dir, _appConfig) {
371
369
 
372
370
  pages: {
373
371
  index: {
374
- entry: path.join(SHELL_ABS, '/nuxt/client.js'),
372
+ entry: path.join(SHELL_ABS, '/initialize/client.js'),
375
373
  template: path.join(SHELL_ABS, '/public/index.html')
376
374
  }
377
375
  },
@@ -561,6 +559,19 @@ module.exports = function(dir, _appConfig) {
561
559
  ];
562
560
 
563
561
  config.module.rules.push(...loaders);
562
+
563
+ // Update vue-loader to set whitespace to 'preserve'
564
+ // This was the setting with nuxt, but is not the default with vue cli
565
+ // Need to find the vue loader in the webpack config and update the setting
566
+ config.module.rules.forEach((loader) => {
567
+ if (loader.use) {
568
+ loader.use.forEach((use) => {
569
+ if (use.loader.includes('vue-loader')) {
570
+ use.options.compilerOptions.whitespace = 'preserve';
571
+ }
572
+ });
573
+ }
574
+ });
564
575
  },
565
576
  };
566
577
 
package/nuxt/App.js DELETED
@@ -1,210 +0,0 @@
1
- import Vue from 'vue'
2
- import { decode, parsePath, withoutBase, withoutTrailingSlash, normalizeURL } from 'ufo'
3
-
4
- import { getMatchedComponentsInstances, getChildrenComponentInstancesUsingFetch, promisify, globalHandleError, urlJoin, sanitizeComponent } from './utils'
5
- import NuxtError from '../layouts/error.vue'
6
- import NuxtLoading from '../components/nav/GlobalLoading.vue'
7
- import NuxtBuildIndicator from './components/nuxt-build-indicator'
8
-
9
- import '../assets/styles/app.scss'
10
-
11
- import _77180f1e from '../layouts/blank.vue'
12
- import _6f6c098b from '../layouts/default.vue'
13
- import _2d2495d5 from '../layouts/home.vue'
14
- import _77dd5794 from '../layouts/plain.vue'
15
- import _44002f80 from '../layouts/unauthenticated.vue'
16
-
17
- const layouts = { "_blank": sanitizeComponent(_77180f1e),"_default": sanitizeComponent(_6f6c098b),"_home": sanitizeComponent(_2d2495d5),"_plain": sanitizeComponent(_77dd5794),"_unauthenticated": sanitizeComponent(_44002f80) }
18
-
19
- export default {
20
- render (h, props) {
21
- const loadingEl = h('NuxtLoading', { ref: 'loading' })
22
-
23
- const layoutEl = h(this.layout || 'nuxt')
24
- const templateEl = h('div', {
25
- domProps: {
26
- id: '__layout'
27
- },
28
- key: this.layoutName
29
- }, [layoutEl])
30
-
31
- const transitionEl = h('transition', {
32
- props: {
33
- name: 'layout',
34
- mode: 'out-in'
35
- },
36
- on: {
37
- beforeEnter (el) {
38
- // Ensure to trigger scroll event after calling scrollBehavior
39
- window.$nuxt.$nextTick(() => {
40
- window.$nuxt.$emit('triggerScroll')
41
- })
42
- }
43
- }
44
- }, [templateEl])
45
-
46
- return h('div', {
47
- domProps: {
48
- id: '__nuxt'
49
- }
50
- }, [
51
- loadingEl,
52
- //h(NuxtBuildIndicator), // The build indicator doesn't work as is right now and emits an error in the console so I'm leaving it out for now
53
- transitionEl
54
- ])
55
- },
56
-
57
- data: () => ({
58
- isOnline: true,
59
-
60
- layout: null,
61
- layoutName: '',
62
-
63
- nbFetching: 0
64
- }),
65
-
66
- beforeCreate () {
67
- Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt)
68
- },
69
- created () {
70
- // Add this.$nuxt in child instances
71
- this.$root.$options.$nuxt = this
72
-
73
- if (process.client) {
74
- // add to window so we can listen when ready
75
- window.$nuxt = this
76
-
77
- this.refreshOnlineStatus()
78
- // Setup the listeners
79
- window.addEventListener('online', this.refreshOnlineStatus)
80
- window.addEventListener('offline', this.refreshOnlineStatus)
81
- }
82
- // Add $nuxt.error()
83
- this.error = this.nuxt.error
84
- // Add $nuxt.context
85
- this.context = this.$options.context
86
- },
87
-
88
- async mounted () {
89
- this.$loading = this.$refs.loading
90
- },
91
-
92
- watch: {
93
- 'nuxt.err': 'errorChanged'
94
- },
95
-
96
- computed: {
97
- isOffline () {
98
- return !this.isOnline
99
- },
100
-
101
- isFetching () {
102
- return this.nbFetching > 0
103
- },
104
- },
105
-
106
- methods: {
107
- refreshOnlineStatus () {
108
- if (process.client) {
109
- if (typeof window.navigator.onLine === 'undefined') {
110
- // If the browser doesn't support connection status reports
111
- // assume that we are online because most apps' only react
112
- // when they now that the connection has been interrupted
113
- this.isOnline = true
114
- } else {
115
- this.isOnline = window.navigator.onLine
116
- }
117
- }
118
- },
119
-
120
- async refresh () {
121
- const pages = getMatchedComponentsInstances(this.$route)
122
-
123
- if (!pages.length) {
124
- return
125
- }
126
- this.$loading.start()
127
-
128
- const promises = pages.map((page) => {
129
- const p = []
130
-
131
- // Old fetch
132
- if (page.$options.fetch && page.$options.fetch.length) {
133
- p.push(promisify(page.$options.fetch, this.context))
134
- }
135
- if (page.$fetch) {
136
- p.push(page.$fetch())
137
- } else {
138
- // Get all component instance to call $fetch
139
- for (const component of getChildrenComponentInstancesUsingFetch(page.$vnode.componentInstance)) {
140
- p.push(component.$fetch())
141
- }
142
- }
143
-
144
- if (page.$options.asyncData) {
145
- p.push(
146
- promisify(page.$options.asyncData, this.context)
147
- .then((newData) => {
148
- for (const key in newData) {
149
- Vue.set(page.$data, key, newData[key])
150
- }
151
- })
152
- )
153
- }
154
-
155
- return Promise.all(p)
156
- })
157
- try {
158
- await Promise.all(promises)
159
- } catch (error) {
160
- this.$loading.fail(error)
161
- globalHandleError(error)
162
- this.error(error)
163
- }
164
- this.$loading.finish()
165
- },
166
- errorChanged () {
167
- if (this.nuxt.err) {
168
- if (this.$loading) {
169
- if (this.$loading.fail) {
170
- this.$loading.fail(this.nuxt.err)
171
- }
172
- if (this.$loading.finish) {
173
- this.$loading.finish()
174
- }
175
- }
176
-
177
- let errorLayout = (NuxtError.options || NuxtError).layout;
178
-
179
- if (typeof errorLayout === 'function') {
180
- errorLayout = errorLayout(this.context)
181
- }
182
-
183
- this.setLayout(errorLayout)
184
- }
185
- },
186
-
187
- setLayout (layout) {
188
- if(layout && typeof layout !== 'string') {
189
- throw new Error('[nuxt] Avoid using non-string value as layout property.')
190
- }
191
-
192
- if (!layout || !layouts['_' + layout]) {
193
- layout = 'default'
194
- }
195
- this.layoutName = layout
196
- this.layout = layouts['_' + layout]
197
- return this.layout
198
- },
199
- loadLayout (layout) {
200
- if (!layout || !layouts['_' + layout]) {
201
- layout = 'default'
202
- }
203
- return Promise.resolve(layouts['_' + layout])
204
- },
205
- },
206
-
207
- components: {
208
- NuxtLoading
209
- }
210
- }
package/nuxt/axios.js DELETED
@@ -1,186 +0,0 @@
1
- import Axios from 'axios'
2
- import defu from 'defu'
3
- import axiosRetry from 'axios-retry'
4
-
5
- // Axios.prototype cannot be modified
6
- const axiosExtra = {
7
- setBaseURL (baseURL) {
8
- this.defaults.baseURL = baseURL
9
- },
10
- setHeader (name, value, scopes = 'common') {
11
- for (let scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
12
- if (!value) {
13
- delete this.defaults.headers[scope][name];
14
- return
15
- }
16
- this.defaults.headers[scope][name] = value
17
- }
18
- },
19
- setToken (token, type, scopes = 'common') {
20
- const value = !token ? null : (type ? type + ' ' : '') + token
21
- this.setHeader('Authorization', value, scopes)
22
- },
23
- onRequest(fn) {
24
- this.interceptors.request.use(config => fn(config) || config)
25
- },
26
- onResponse(fn) {
27
- this.interceptors.response.use(response => fn(response) || response)
28
- },
29
- onRequestError(fn) {
30
- this.interceptors.request.use(undefined, error => fn(error) || Promise.reject(error))
31
- },
32
- onResponseError(fn) {
33
- this.interceptors.response.use(undefined, error => fn(error) || Promise.reject(error))
34
- },
35
- onError(fn) {
36
- this.onRequestError(fn)
37
- this.onResponseError(fn)
38
- },
39
- create(options) {
40
- return createAxiosInstance(defu(options, this.defaults))
41
- }
42
- }
43
-
44
- // Request helpers ($get, $post, ...)
45
- for (let method of ['request', 'delete', 'get', 'head', 'options', 'post', 'put', 'patch']) {
46
- axiosExtra['$' + method] = function () { return this[method].apply(this, arguments).then(res => res && res.data) }
47
- }
48
-
49
- const extendAxiosInstance = axios => {
50
- for (let key in axiosExtra) {
51
- axios[key] = axiosExtra[key].bind(axios)
52
- }
53
- }
54
-
55
- const createAxiosInstance = axiosOptions => {
56
- // Create new axios instance
57
- const axios = Axios.create(axiosOptions)
58
- axios.CancelToken = Axios.CancelToken
59
- axios.isCancel = Axios.isCancel
60
-
61
- // Extend axios proto
62
- extendAxiosInstance(axios)
63
-
64
- // Setup interceptors
65
-
66
- setupProgress(axios)
67
- axiosRetry(axios, {"retries":0})
68
-
69
- return axios
70
- }
71
-
72
- const setupProgress = (axios) => {
73
- if (process.server) {
74
- return
75
- }
76
-
77
- // A noop loading inteterface for when $nuxt is not yet ready
78
- const noopLoading = {
79
- finish: () => { },
80
- start: () => { },
81
- fail: () => { },
82
- set: () => { }
83
- }
84
-
85
- const $loading = () => {
86
- const $nuxt = typeof window !== 'undefined' && window['$nuxt']
87
- return ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading
88
- }
89
-
90
- let currentRequests = 0
91
-
92
- axios.onRequest(config => {
93
- if (config && config.progress === false) {
94
- return
95
- }
96
-
97
- currentRequests++
98
- })
99
-
100
- axios.onResponse(response => {
101
- if (response && response.config && response.config.progress === false) {
102
- return
103
- }
104
-
105
- currentRequests--
106
- if (currentRequests <= 0) {
107
- currentRequests = 0
108
- $loading().finish()
109
- }
110
- })
111
-
112
- axios.onError(error => {
113
- if (error && error.config && error.config.progress === false) {
114
- return
115
- }
116
-
117
- currentRequests--
118
-
119
- if (Axios.isCancel(error)) {
120
- return
121
- }
122
-
123
- $loading().fail()
124
- $loading().finish()
125
- })
126
-
127
- const onProgress = e => {
128
- if (!currentRequests) {
129
- return
130
- }
131
- const progress = ((e.loaded * 100) / (e.total * currentRequests))
132
- $loading().set(Math.min(100, progress))
133
- }
134
-
135
- axios.defaults.onUploadProgress = onProgress
136
- axios.defaults.onDownloadProgress = onProgress
137
- }
138
-
139
- export default (ctx, inject) => {
140
- // runtimeConfig
141
- const runtimeConfig = ctx.$config && ctx.$config.axios || {}
142
- // baseURL
143
- const baseURL = process.browser
144
- ? (runtimeConfig.browserBaseURL || runtimeConfig.baseURL || '/')
145
- : (runtimeConfig.baseURL || process.env._AXIOS_BASE_URL_ || 'https://localhost:8005/')
146
-
147
- // Create fresh objects for all default header scopes
148
- // Axios creates only one which is shared across SSR requests!
149
- // https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
150
- const headers = {
151
- "common": {
152
- "Accept": "application/json, text/plain, */*"
153
- },
154
- "delete": {},
155
- "get": {},
156
- "head": {},
157
- "post": {},
158
- "put": {},
159
- "patch": {}
160
- }
161
-
162
- const axiosOptions = {
163
- baseURL,
164
- headers
165
- }
166
-
167
- // Proxy SSR request headers headers
168
- if (process.server && ctx.req && ctx.req.headers) {
169
- const reqHeaders = { ...ctx.req.headers }
170
- for (let h of ["accept","host","cf-ray","cf-connecting-ip","content-length","content-md5","content-type"]) {
171
- delete reqHeaders[h]
172
- }
173
- axiosOptions.headers.common = { ...reqHeaders, ...axiosOptions.headers.common }
174
- }
175
-
176
- if (process.server) {
177
- // Don't accept brotli encoding because Node can't parse it
178
- axiosOptions.headers.common['accept-encoding'] = 'gzip, deflate'
179
- }
180
-
181
- const axios = createAxiosInstance(axiosOptions)
182
-
183
- // Inject axios to the context as $axios
184
- ctx.$axios = axios
185
- inject('axios', axios)
186
- }
package/nuxt/empty.js DELETED
@@ -1 +0,0 @@
1
- // This file is intentionally left empty for noop aliases
package/nuxt/jsonp.js DELETED
@@ -1,82 +0,0 @@
1
- const chunks = {} // chunkId => exports
2
- const chunksInstalling = {} // chunkId => Promise
3
- const failedChunks = {}
4
-
5
- function importChunk(chunkId, src) {
6
- // Already installed
7
- if (chunks[chunkId]) {
8
- return Promise.resolve(chunks[chunkId])
9
- }
10
-
11
- // Failed loading
12
- if (failedChunks[chunkId]) {
13
- return Promise.reject(failedChunks[chunkId])
14
- }
15
-
16
- // Installing
17
- if (chunksInstalling[chunkId]) {
18
- return chunksInstalling[chunkId]
19
- }
20
-
21
- // Set a promise in chunk cache
22
- let resolve, reject
23
- const promise = chunksInstalling[chunkId] = new Promise((_resolve, _reject) => {
24
- resolve = _resolve
25
- reject = _reject
26
- })
27
-
28
- // Clear chunk data from cache
29
- delete chunks[chunkId]
30
-
31
- // Start chunk loading
32
- const script = document.createElement('script')
33
- script.charset = 'utf-8'
34
- script.timeout = 120
35
- script.src = src
36
- let timeout
37
-
38
- // Create error before stack unwound to get useful stacktrace later
39
- const error = new Error()
40
-
41
- // Complete handlers
42
- const onScriptComplete = script.onerror = script.onload = (event) => {
43
- // Cleanups
44
- clearTimeout(timeout)
45
- delete chunksInstalling[chunkId]
46
-
47
- // Avoid mem leaks in IE
48
- script.onerror = script.onload = null
49
-
50
- // Verify chunk is loaded
51
- if (chunks[chunkId]) {
52
- return resolve(chunks[chunkId])
53
- }
54
-
55
- // Something bad happened
56
- const errorType = event && (event.type === 'load' ? 'missing' : event.type)
57
- const realSrc = event && event.target && event.target.src
58
- error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')'
59
- error.name = 'ChunkLoadError'
60
- error.type = errorType
61
- error.request = realSrc
62
- failedChunks[chunkId] = error
63
- reject(error)
64
- }
65
-
66
- // Timeout
67
- timeout = setTimeout(() => {
68
- onScriptComplete({ type: 'timeout', target: script })
69
- }, 120000)
70
-
71
- // Append script
72
- document.head.appendChild(script)
73
-
74
- // Return promise
75
- return promise
76
- }
77
-
78
- export function installJsonp() {
79
- window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
80
- window.__NUXT_JSONP_CACHE__ = chunks
81
- window.__NUXT_IMPORT__ = importChunk
82
- }
package/nuxt/loading.html DELETED
@@ -1,39 +0,0 @@
1
- <style>
2
- .initial-load-spinner-container {
3
- align-items: center;
4
- background-color: #f8f8f8;
5
- display: flex;
6
- justify-content: center;
7
- height: 100vh;
8
- left: 0;
9
- position: absolute;
10
- top: 0;
11
- width: 100vw;
12
- }
13
-
14
- .initial-load-spinner {
15
- animation: initial-load-animate 1s infinite linear;
16
- background-color: #fff;
17
- box-sizing: border-box;
18
- border: 5px solid #008ACF;
19
- border-radius: 50%;
20
- border-top-color: #00B2E2;
21
- display: inline-block;
22
- height: 80px;
23
- margin: 0 auto;
24
- width: 80px;
25
- }
26
-
27
- @keyframes initial-load-animate {
28
- 0% {
29
- transform: rotate(0deg);
30
- }
31
-
32
- 100% {
33
- transform: rotate(359deg);
34
- }
35
- }
36
- </style>
37
- <div class="initial-load-spinner-container">
38
- <i class="initial-load-spinner"></i>
39
- </div>
@@ -1,90 +0,0 @@
1
- import Vue from 'vue'
2
- import { hasFetch, normalizeError, addLifecycleHook, createGetCounter } from '../utils'
3
-
4
- const isSsrHydration = (vm) => vm.$vnode && vm.$vnode.elm && vm.$vnode.elm.dataset && vm.$vnode.elm.dataset.fetchKey
5
- const nuxtState = window.__NUXT__
6
-
7
- export default {
8
- beforeCreate () {
9
- if (!hasFetch(this)) {
10
- return
11
- }
12
-
13
- this._fetchDelay = typeof this.$options.fetchDelay === 'number' ? this.$options.fetchDelay : 200
14
-
15
- Vue.util.defineReactive(this, '$fetchState', {
16
- pending: false,
17
- error: null,
18
- timestamp: Date.now()
19
- })
20
-
21
- this.$fetch = $fetch.bind(this)
22
- addLifecycleHook(this, 'created', created)
23
- addLifecycleHook(this, 'beforeMount', beforeMount)
24
- }
25
- }
26
-
27
- function beforeMount() {
28
- if (!this._hydrated) {
29
- return this.$fetch()
30
- }
31
- }
32
-
33
- function created() {
34
- if (!isSsrHydration(this)) {
35
- return
36
- }
37
-
38
- // Hydrate component
39
- this._hydrated = true
40
- this._fetchKey = this.$vnode.elm.dataset.fetchKey
41
- const data = nuxtState.fetch[this._fetchKey]
42
-
43
- // If fetch error
44
- if (data && data._error) {
45
- this.$fetchState.error = data._error
46
- return
47
- }
48
-
49
- // Merge data
50
- for (const key in data) {
51
- Vue.set(this.$data, key, data[key])
52
- }
53
- }
54
-
55
- function $fetch() {
56
- if (!this._fetchPromise) {
57
- this._fetchPromise = $_fetch.call(this)
58
- .then(() => { delete this._fetchPromise })
59
- }
60
- return this._fetchPromise
61
- }
62
-
63
- async function $_fetch() {
64
- this.$nuxt.nbFetching++
65
- this.$fetchState.pending = true
66
- this.$fetchState.error = null
67
- this._hydrated = false
68
- let error = null
69
- const startTime = Date.now()
70
-
71
- try {
72
- await this.$options.fetch.call(this)
73
- } catch (err) {
74
- if (process.dev) {
75
- console.error('Error in fetch():', err)
76
- }
77
- error = normalizeError(err)
78
- }
79
-
80
- const delayLeft = this._fetchDelay - (Date.now() - startTime)
81
- if (delayLeft > 0) {
82
- await new Promise(resolve => setTimeout(resolve, delayLeft))
83
- }
84
-
85
- this.$fetchState.error = error
86
- this.$fetchState.pending = false
87
- this.$fetchState.timestamp = Date.now()
88
-
89
- this.$nextTick(() => this.$nuxt.nbFetching--)
90
- }