Commit 814f9a7addfd1810b33c4ba469a9c9bcd3de4b1a
1 parent
16117a9e
chore: update deps
Showing
6 changed files
with
132 additions
and
68 deletions
package.json
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | }, |
23 | 23 | "dependencies": { |
24 | 24 | "@iconify/iconify": "^2.0.0-rc.2", |
25 | - "@vueuse/core": "4.0.0-rc.3", | |
25 | + "@vueuse/core": "^4.0.0-rc.3", | |
26 | 26 | "ant-design-vue": "2.0.0-beta.15", |
27 | 27 | "apexcharts": "3.22.0", |
28 | 28 | "axios": "^0.21.0", |
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | "nprogress": "^0.2.0", |
34 | 34 | "path-to-regexp": "^6.2.0", |
35 | 35 | "qrcode": "^1.4.4", |
36 | - "vditor": "^3.6.2", | |
36 | + "vditor": "^3.6.3", | |
37 | 37 | "vue": "^3.0.2", |
38 | 38 | "vue-i18n": "^9.0.0-beta.8", |
39 | 39 | "vue-router": "^4.0.0-rc.3", |
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | "devDependencies": { |
46 | 46 | "@commitlint/cli": "^11.0.0", |
47 | 47 | "@commitlint/config-conventional": "^11.0.0", |
48 | - "@iconify/json": "^1.1.260", | |
48 | + "@iconify/json": "^1.1.261", | |
49 | 49 | "@ls-lint/ls-lint": "^1.9.2", |
50 | 50 | "@purge-icons/generated": "^0.4.1", |
51 | 51 | "@types/echarts": "^4.9.1", |
... | ... | @@ -69,7 +69,7 @@ |
69 | 69 | "conventional-changelog-cli": "^2.1.1", |
70 | 70 | "conventional-changelog-custom-config": "^0.3.1", |
71 | 71 | "cross-env": "^7.0.2", |
72 | - "dot-prop": "^6.0.0", | |
72 | + "dot-prop": "^6.0.1", | |
73 | 73 | "dotenv": "^8.2.0", |
74 | 74 | "eslint": "^7.13.0", |
75 | 75 | "eslint-config-prettier": "^6.15.0", |
... | ... | @@ -93,7 +93,7 @@ |
93 | 93 | "stylelint-order": "^4.1.0", |
94 | 94 | "tasksfile": "^5.1.1", |
95 | 95 | "ts-node": "^9.0.0", |
96 | - "typescript": "^4.0.5", | |
96 | + "typescript": "^4.1.2", | |
97 | 97 | "vite": "^1.0.0-rc.9", |
98 | 98 | "vite-plugin-html": "^1.0.0-beta.2", |
99 | 99 | "vite-plugin-mock": "^1.0.6", | ... | ... |
src/router/index.ts
... | ... | @@ -3,28 +3,17 @@ import type { App } from 'vue'; |
3 | 3 | |
4 | 4 | import { createRouter, createWebHashHistory } from 'vue-router'; |
5 | 5 | |
6 | -import { scrollWaiter } from './scrollWaiter'; | |
7 | - | |
8 | 6 | import { createGuard } from './guard/'; |
9 | 7 | |
10 | 8 | import { basicRoutes } from './routes/'; |
9 | +import { scrollBehavior } from './scrollBehaviour'; | |
11 | 10 | |
12 | 11 | // app router |
13 | 12 | const router = createRouter({ |
14 | 13 | history: createWebHashHistory(), |
15 | 14 | routes: basicRoutes as RouteRecordRaw[], |
16 | 15 | strict: true, |
17 | - scrollBehavior: async (to, from, savedPosition) => { | |
18 | - await scrollWaiter.wait(); | |
19 | - if (savedPosition) { | |
20 | - return savedPosition; | |
21 | - } else { | |
22 | - if (to.matched.every((record, i) => from.matched[i] !== record)) { | |
23 | - return { left: 0, top: 0 }; | |
24 | - } | |
25 | - return false; | |
26 | - } | |
27 | - }, | |
16 | + scrollBehavior: scrollBehavior, | |
28 | 17 | }); |
29 | 18 | |
30 | 19 | // reset router | ... | ... |
src/router/scrollWaiter.ts renamed to src/router/scrollBehaviour.ts
1 | +/** | |
2 | + * Handles the scroll behavior on route navigation | |
3 | + * | |
4 | + * @param {object} to Route object of next page | |
5 | + * @param {object} from Route object of previous page | |
6 | + * @param {object} savedPosition Used by popstate navigations | |
7 | + * @returns {(object|boolean)} Scroll position or `false` | |
8 | + */ | |
9 | +// @ts-ignore | |
10 | +export async function scrollBehavior(to, from, savedPosition) { | |
11 | + await scrollWaiter.wait(); | |
12 | + // Use predefined scroll behavior if defined, defaults to no scroll behavior | |
13 | + const behavior = document.documentElement.style.scrollBehavior || 'auto'; | |
14 | + | |
15 | + // Returning the `savedPosition` (if available) will result in a native-like | |
16 | + // behavior when navigating with back/forward buttons | |
17 | + if (savedPosition) { | |
18 | + return { ...savedPosition, behavior }; | |
19 | + } | |
20 | + | |
21 | + // Scroll to anchor by returning the selector | |
22 | + if (to.hash) { | |
23 | + return { el: decodeURI(to.hash), behavior }; | |
24 | + } | |
25 | + | |
26 | + // Check if any matched route config has meta that discourages scrolling to top | |
27 | + if (to.matched.some((m: any) => m.meta.scrollToTop === false)) { | |
28 | + // Leave scroll as it is | |
29 | + return false; | |
30 | + } | |
31 | + | |
32 | + // Always scroll to top | |
33 | + return { left: 0, top: 0, behavior }; | |
34 | +} | |
35 | + | |
1 | 36 | // see https://github.com/vuejs/vue-router-next/blob/master/playground/scrollWaiter.ts |
2 | 37 | class ScrollQueue { |
3 | 38 | private resolve: (() => void) | null = null; | ... | ... |
src/utils/eventHub.ts deleted
100644 โ 0
1 | -class EventHub { | |
2 | - private cache: { [key: string]: Array<(data: any) => void> } = {}; | |
3 | - on(eventName: string, fn: (data: any) => void) { | |
4 | - this.cache[eventName] = this.cache[eventName] || []; | |
5 | - this.cache[eventName].push(fn); | |
6 | - } | |
7 | - | |
8 | - once(eventName: string, fn: (data: any) => void) { | |
9 | - const decor = (...args: any[]) => { | |
10 | - fn && fn.apply(this, args); | |
11 | - this.off(eventName, decor); | |
12 | - }; | |
13 | - this.on(eventName, decor); | |
14 | - return this; | |
15 | - } | |
16 | - | |
17 | - emit(eventName: string, data?: any) { | |
18 | - if (this.cache[eventName] === undefined) return; | |
19 | - this.cache[eventName].forEach((fn) => fn(data)); | |
20 | - } | |
21 | - off(eventName: string, fn: (data: any) => void) { | |
22 | - if (this.cache[eventName] === undefined || this.cache[eventName].length === 0) return; | |
23 | - const i = this.cache[eventName].indexOf(fn); | |
24 | - if (i === -1) return; | |
25 | - this.cache[eventName].splice(i, 1); | |
26 | - } | |
27 | - | |
28 | - clear() { | |
29 | - this.cache = {}; | |
30 | - } | |
31 | -} | |
32 | - | |
33 | -export default EventHub; |
src/utils/mitt.ts
0 โ 100644
1 | +/** | |
2 | + * Mitt: Tiny functional event emitter / pubsub | |
3 | + * | |
4 | + * @name mitt | |
5 | + * @param {Array} [all] Optional array of event names to registered handler functions | |
6 | + * @returns {Function} The function's instance | |
7 | + */ | |
8 | +export default class Mitt { | |
9 | + private cache: Map<string, Array<(data: any) => void>>; | |
10 | + constructor(all = []) { | |
11 | + // A Map of event names to registered handler functions. | |
12 | + this.cache = new Map(all); | |
13 | + } | |
14 | + | |
15 | + once(type: string, handler: Fn) { | |
16 | + const decor = (...args: any[]) => { | |
17 | + handler && handler.apply(this, args); | |
18 | + this.off(type, decor); | |
19 | + }; | |
20 | + this.on(type, decor); | |
21 | + return this; | |
22 | + } | |
23 | + | |
24 | + /** | |
25 | + * Register an event handler for the given type. | |
26 | + * | |
27 | + * @param {string|symbol} type Type of event to listen for, or `"*"` for all events | |
28 | + * @param {Function} handler Function to call in response to given event | |
29 | + */ | |
30 | + on(type: string, handler: Fn) { | |
31 | + const handlers = this.cache.get(type); | |
32 | + const added = handlers && handlers.push(handler); | |
33 | + if (!added) { | |
34 | + this.cache.set(type, [handler]); | |
35 | + } | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * Remove an event handler for the given type. | |
40 | + * | |
41 | + * @param {string|symbol} type Type of event to unregister `handler` from, or `"*"` | |
42 | + * @param {Function} handler Handler function to remove | |
43 | + */ | |
44 | + off(type: string, handler: Fn) { | |
45 | + const handlers = this.cache.get(type); | |
46 | + if (handlers) { | |
47 | + handlers.splice(handlers.indexOf(handler) >>> 0, 1); | |
48 | + } | |
49 | + } | |
50 | + | |
51 | + /** | |
52 | + * Invoke all handlers for the given type. | |
53 | + * If present, `"*"` handlers are invoked after type-matched handlers. | |
54 | + * | |
55 | + * Note: Manually firing "*" handlers is not supported. | |
56 | + * | |
57 | + * @param {string|symbol} type The event type to invoke | |
58 | + * @param {*} [evt] Any value (object is recommended and powerful), passed to each handler | |
59 | + */ | |
60 | + emit(type: string, evt: any) { | |
61 | + for (const handler of (this.cache.get(type) || []).slice()) handler(evt); | |
62 | + for (const handler of (this.cache.get('*') || []).slice()) handler(type, evt); | |
63 | + } | |
64 | + | |
65 | + /** | |
66 | + * Remove all event handlers. | |
67 | + * | |
68 | + * Note: This will also remove event handlers passed via `mitt(all: EventHandlerMap)`. | |
69 | + */ | |
70 | + clear() { | |
71 | + this.cache.clear(); | |
72 | + } | |
73 | +} | ... | ... |
yarn.lock
... | ... | @@ -1050,10 +1050,10 @@ |
1050 | 1050 | resolved "https://registry.npmjs.org/@iconify/iconify/-/iconify-2.0.0-rc.2.tgz#c4a95ddc06ca9b9496df03604e66fdefb39f4c4b" |
1051 | 1051 | integrity sha512-BybEHU5/I9EQ0CcwKAqmreZ2bMnAXrqLCTptAc6vPetHMbrXdZfejP5mt57e/8PNSt/qE7BHniU5PCYA+PGIHw== |
1052 | 1052 | |
1053 | -"@iconify/json@^1.1.260": | |
1054 | - version "1.1.260" | |
1055 | - resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.260.tgz#75bfcdcaf01f1a0092bb26f4ce7aebf357da431a" | |
1056 | - integrity sha512-gpRn0o55mvBTCcZRb8jBtqxV/5Av01BnnVn7/FyboBNdGkEQ8EMTqJL10SDUf9TLM8s63KKSg/ZeCJj870THtA== | |
1053 | +"@iconify/json@^1.1.261": | |
1054 | + version "1.1.261" | |
1055 | + resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.261.tgz#9a6986b6b36d77ca147c4be149db9a43280a8fb2" | |
1056 | + integrity sha512-lnRk1OBqNxZ593oZyOXEMp/O+cr+lF54xaW6+F3krWdWhzxQgi0W1ffzvdiLySdbTEorQ2NvVU4e0+Af27rXPA== | |
1057 | 1057 | |
1058 | 1058 | "@koa/cors@^3.1.0": |
1059 | 1059 | version "3.1.0" |
... | ... | @@ -1737,7 +1737,7 @@ |
1737 | 1737 | vscode-languageserver-textdocument "^1.0.1" |
1738 | 1738 | vscode-uri "^2.1.2" |
1739 | 1739 | |
1740 | -"@vueuse/core@4.0.0-rc.3": | |
1740 | +"@vueuse/core@^4.0.0-rc.3": | |
1741 | 1741 | version "4.0.0-rc.3" |
1742 | 1742 | resolved "https://registry.npmjs.org/@vueuse/core/-/core-4.0.0-rc.3.tgz#5381ca657e10df596cd7027fc5c96b2d4b3a090c" |
1743 | 1743 | integrity sha512-dQ/FZgo0z7kBFOvDWxuzaUrmuO8X1AlQk17e3PU1TVtG2Uu+mCvjPNbuvI2fjhTjl5rzPJawwoU2WZFj+nlFvw== |
... | ... | @@ -3227,10 +3227,10 @@ dot-prop@^5.1.0: |
3227 | 3227 | dependencies: |
3228 | 3228 | is-obj "^2.0.0" |
3229 | 3229 | |
3230 | -dot-prop@^6.0.0: | |
3231 | - version "6.0.0" | |
3232 | - resolved "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.0.tgz#bd579fd704d970981c4b05de591db648959f2ebb" | |
3233 | - integrity sha512-xCbB8IN3IT+tdgoEPOnJmYTNJDrygGFOmiQEiVa5eAD+JEB1vTgMNhVGRnN5Eex/6amck7cdcrixb1qN9Go+GQ== | |
3230 | +dot-prop@^6.0.1: | |
3231 | + version "6.0.1" | |
3232 | + resolved "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz#fc26b3cf142b9e59b74dbd39ed66ce620c681083" | |
3233 | + integrity sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA== | |
3234 | 3234 | dependencies: |
3235 | 3235 | is-obj "^2.0.0" |
3236 | 3236 | |
... | ... | @@ -7869,10 +7869,10 @@ typescript@^3.9.7: |
7869 | 7869 | resolved "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" |
7870 | 7870 | integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== |
7871 | 7871 | |
7872 | -typescript@^4.0.5: | |
7873 | - version "4.0.5" | |
7874 | - resolved "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" | |
7875 | - integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== | |
7872 | +typescript@^4.1.2: | |
7873 | + version "4.1.2" | |
7874 | + resolved "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz#6369ef22516fe5e10304aae5a5c4862db55380e9" | |
7875 | + integrity sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ== | |
7876 | 7876 | |
7877 | 7877 | uglify-js@^3.1.4: |
7878 | 7878 | version "3.11.6" |
... | ... | @@ -8033,10 +8033,10 @@ vary@^1.1.2: |
8033 | 8033 | resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" |
8034 | 8034 | integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw= |
8035 | 8035 | |
8036 | -vditor@^3.6.2: | |
8037 | - version "3.6.2" | |
8038 | - resolved "https://registry.npmjs.org/vditor/-/vditor-3.6.2.tgz#ee6011efa3ec563c6356ed82efbf2e00ba2e35c6" | |
8039 | - integrity sha512-HPHHun5+IXmYGMKDWcUD83VfP1Qfncz7DmaIKoWpluJgE8ve7s+4RbFBcaEpYPXYzIuL2UTHoMnIjmTPbenOCA== | |
8036 | +vditor@^3.6.3: | |
8037 | + version "3.6.3" | |
8038 | + resolved "https://registry.npmjs.org/vditor/-/vditor-3.6.3.tgz#7d006f273208869b268268453b688ad4a0de8995" | |
8039 | + integrity sha512-skLJQrVBdeBFLdYVckfovCxNnzOR1vlgEesUFAc0WJdbfj/m4FHB7SY/LgV7KtoiK+crDPFrIdw3jkEQmhkFGA== | |
8040 | 8040 | dependencies: |
8041 | 8041 | diff-match-patch "^1.0.5" |
8042 | 8042 | ... | ... |