@varlet/cli 1.23.5 → 1.23.12-alpha.25
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/CHANGELOG.md +30 -0
- package/generators/{sfc → base}/.gitignore +0 -0
- package/generators/{sfc → base}/.husky/commit-msg +0 -0
- package/generators/{sfc → base}/.husky/pre-commit +0 -0
- package/generators/{tsx → base}/.prettierignore +0 -1
- package/generators/{sfc → base}/.prettierrc +0 -0
- package/generators/{sfc → base}/README.md +0 -0
- package/generators/{sfc → base}/babel.config.js +0 -0
- package/generators/{sfc → base}/commitlint.config.js +0 -0
- package/generators/{sfc → base}/docs/home.zh-CN.md +0 -0
- package/generators/{sfc → base}/package.json +0 -0
- package/generators/{sfc → base}/public/highlight.css +0 -0
- package/generators/{sfc → base}/public/logo.svg +0 -0
- package/generators/{sfc → base}/shims/shims-md.d.ts +0 -0
- package/generators/{sfc → base}/shims/shims-vue.d.ts +0 -0
- package/generators/{sfc → base}/tsconfig.json +0 -0
- package/generators/{sfc → base}/types/basicComponent.d.ts +0 -0
- package/generators/{sfc → base}/types/button.d.ts +0 -0
- package/generators/{sfc → base}/types/index.d.ts +0 -0
- package/generators/{sfc → base}/varlet.config.js +0 -0
- package/lib/commands/dev.js +1 -1
- package/lib/commands/gen.js +7 -3
- package/lib/compiler/compileModule.js +1 -1
- package/lib/compiler/compileSiteEntry.js +1 -1
- package/lib/shared/fsUtils.d.ts +1 -0
- package/lib/shared/fsUtils.js +3 -1
- package/package.json +2 -2
- package/site/components/code-example/CodeExample.vue +107 -0
- package/site/components/code-example/codeExample.less +23 -0
- package/site/components/code-example/index.ts +10 -0
- package/site/components/icon/icon.less +1 -0
- package/site/components/loading/props.ts +2 -2
- package/site/components/snackbar/Snackbar.vue +38 -0
- package/site/components/snackbar/core.vue +117 -0
- package/site/components/snackbar/index.tsx +270 -0
- package/site/components/snackbar/props.ts +94 -0
- package/site/components/snackbar/snackbar.less +135 -0
- package/site/components/utils/elements.ts +9 -0
- package/site/components/utils/shared.ts +3 -0
- package/site/mobile/App.vue +6 -6
- package/site/module.d.ts +4 -0
- package/site/pc/App.vue +9 -11
- package/site/pc/components/AppHeader.vue +8 -9
- package/site/pc/components/AppSidebar.vue +5 -5
- package/site/pc/main.ts +8 -2
- package/site/tsconfig.json +1 -6
- package/site/useProgress.ts +6 -2
- package/site/utils.ts +4 -3
- package/tsconfig.json +0 -2
- package/varlet.default.config.js +13 -0
- package/generators/sfc/.prettierignore +0 -8
- package/generators/tsx/.gitignore +0 -14
- package/generators/tsx/.husky/commit-msg +0 -4
- package/generators/tsx/.husky/pre-commit +0 -4
- package/generators/tsx/.prettierrc +0 -5
- package/generators/tsx/README.md +0 -88
- package/generators/tsx/babel.config.js +0 -10
- package/generators/tsx/commitlint.config.js +0 -3
- package/generators/tsx/docs/home.zh-CN.md +0 -11
- package/generators/tsx/package.json +0 -98
- package/generators/tsx/public/highlight.css +0 -1
- package/generators/tsx/public/logo.svg +0 -1
- package/generators/tsx/shims/shims-md.d.ts +0 -4
- package/generators/tsx/shims/shims-vue.d.ts +0 -6
- package/generators/tsx/tsconfig.json +0 -13
- package/generators/tsx/types/basicComponent.d.ts +0 -7
- package/generators/tsx/types/button.d.ts +0 -12
- package/generators/tsx/types/index.d.ts +0 -6
- package/generators/tsx/varlet.config.js +0 -106
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.23.11](https://github.com/haoziqaq/varlet/compare/v1.23.10...v1.23.11) (2021-12-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @varlet/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.23.8](https://github.com/haoziqaq/varlet/compare/v1.23.7...v1.23.8) (2021-11-24)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **cli:** add ts ignore to generate routes ([3363578](https://github.com/haoziqaq/varlet/commit/3363578eb2763282fd3c274ab75374cbff94c92b))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [1.23.7](https://github.com/haoziqaq/varlet/compare/v1.23.6...v1.23.7) (2021-11-23)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **ui/themes, cli:** fix themes types ([f29511a](https://github.com/haoziqaq/varlet/commit/f29511a016edb462bdf578a6b5a19fbe10a22158))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## [1.23.5](https://github.com/haoziqaq/varlet/compare/v1.23.4...v1.23.5) (2021-11-21)
|
|
7
37
|
|
|
8
38
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/commands/dev.js
CHANGED
|
@@ -99,7 +99,7 @@ function startServer(force) {
|
|
|
99
99
|
watcher = chokidar_1.default.watch(constant_1.VARLET_CONFIG);
|
|
100
100
|
watcher.on('change', function () { return startServer(force); });
|
|
101
101
|
}
|
|
102
|
-
logger_1.default.
|
|
102
|
+
logger_1.default.success("\n" + (isRestart ? 'Res' : 'S') + "tart successfully!!!");
|
|
103
103
|
return [2 /*return*/];
|
|
104
104
|
}
|
|
105
105
|
});
|
package/lib/commands/gen.js
CHANGED
|
@@ -46,7 +46,7 @@ var path_1 = require("path");
|
|
|
46
46
|
var fs_extra_1 = require("fs-extra");
|
|
47
47
|
var constant_1 = require("../shared/constant");
|
|
48
48
|
function removeFiles(dest) {
|
|
49
|
-
var files = ['es', 'umd', 'highlight', 'types/index.d.ts', '.varlet', 'node_modules'];
|
|
49
|
+
var files = ['es', 'lib', 'umd', 'highlight', 'types/index.d.ts', '.varlet', 'node_modules'];
|
|
50
50
|
files.forEach(function (filename) { return (0, fs_extra_1.removeSync)((0, path_1.resolve)(dest, filename)); });
|
|
51
51
|
}
|
|
52
52
|
function syncVersion(name) {
|
|
@@ -59,7 +59,7 @@ function syncVersion(name) {
|
|
|
59
59
|
}
|
|
60
60
|
function gen(name) {
|
|
61
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
-
var dest, ret, choice, generator;
|
|
62
|
+
var dest, ret, choice, generator, base;
|
|
63
63
|
return __generator(this, function (_a) {
|
|
64
64
|
switch (_a.label) {
|
|
65
65
|
case 0:
|
|
@@ -79,8 +79,12 @@ function gen(name) {
|
|
|
79
79
|
ret = _a.sent();
|
|
80
80
|
choice = ret['Please select your component library programming style'];
|
|
81
81
|
generator = (0, path_1.resolve)(constant_1.GENERATORS_DIR, choice);
|
|
82
|
-
|
|
82
|
+
base = (0, path_1.resolve)(constant_1.GENERATORS_DIR, 'base');
|
|
83
|
+
return [4 /*yield*/, (0, fs_extra_1.copy)(base, dest)];
|
|
83
84
|
case 2:
|
|
85
|
+
_a.sent();
|
|
86
|
+
return [4 /*yield*/, (0, fs_extra_1.copy)(generator, dest)];
|
|
87
|
+
case 3:
|
|
84
88
|
_a.sent();
|
|
85
89
|
removeFiles(dest);
|
|
86
90
|
syncVersion(name);
|
|
@@ -68,7 +68,7 @@ function compileDir(dir) {
|
|
|
68
68
|
return [4 /*yield*/, Promise.all(dirs.map(function (filename) {
|
|
69
69
|
var file = (0, path_1.resolve)(dir, filename);
|
|
70
70
|
[constant_1.TESTS_DIR_NAME, constant_1.EXAMPLE_DIR_NAME, constant_1.DOCS_DIR_NAME].includes(filename) && (0, fs_extra_1.removeSync)(file);
|
|
71
|
-
if (filename === constant_1.STYLE_DIR_NAME) {
|
|
71
|
+
if ((0, fsUtils_1.isDTS)(file) || filename === constant_1.STYLE_DIR_NAME) {
|
|
72
72
|
return Promise.resolve();
|
|
73
73
|
}
|
|
74
74
|
return compileFile(file);
|
|
@@ -161,7 +161,7 @@ function buildMobileSiteRoutes() {
|
|
|
161
161
|
case 0: return [4 /*yield*/, findExamplePaths()];
|
|
162
162
|
case 1:
|
|
163
163
|
examplePaths = _a.sent();
|
|
164
|
-
routes = examplePaths.map(function (examplePath) { return "\n {\n path: '" + getExampleRoutePath(examplePath) + "',\n component: () => import('" + examplePath + "')\n }"; });
|
|
164
|
+
routes = examplePaths.map(function (examplePath) { return "\n {\n path: '" + getExampleRoutePath(examplePath) + "',\n // @ts-ignore\n component: () => import('" + examplePath + "')\n }"; });
|
|
165
165
|
source = "export default [ " + routes.join(',') + "\n]";
|
|
166
166
|
return [4 /*yield*/, (0, fsUtils_1.outputFileSyncOnChange)(constant_1.SITE_MOBILE_ROUTES, source)];
|
|
167
167
|
case 2:
|
package/lib/shared/fsUtils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const isDir: (file: string) => boolean;
|
|
|
4
4
|
export declare const isSFC: (file: string) => boolean;
|
|
5
5
|
export declare const isJSX: (file: string) => boolean;
|
|
6
6
|
export declare const isTSX: (file: string) => boolean;
|
|
7
|
+
export declare const isDTS: (file: string) => boolean;
|
|
7
8
|
export declare const isScript: (file: string) => boolean;
|
|
8
9
|
export declare const isLess: (file: string) => boolean;
|
|
9
10
|
export declare const isPublicDir: (dir: string) => boolean;
|
package/lib/shared/fsUtils.js
CHANGED
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.outputFileSyncOnChange = exports.smartAppendFileSync = exports.camelize = exports.bigCamelize = exports.replaceExt = exports.isPublicDir = exports.isLess = exports.isScript = exports.isTSX = exports.isJSX = exports.isSFC = exports.isDir = exports.isMD = exports.getPublicDirs = void 0;
|
|
39
|
+
exports.outputFileSyncOnChange = exports.smartAppendFileSync = exports.camelize = exports.bigCamelize = exports.replaceExt = exports.isPublicDir = exports.isLess = exports.isScript = exports.isDTS = exports.isTSX = exports.isJSX = exports.isSFC = exports.isDir = exports.isMD = exports.getPublicDirs = void 0;
|
|
40
40
|
var path_1 = require("path");
|
|
41
41
|
var fs_extra_1 = require("fs-extra");
|
|
42
42
|
var constant_1 = require("./constant");
|
|
@@ -64,6 +64,8 @@ var isJSX = function (file) { return (0, fs_extra_1.pathExistsSync)(file) && (0,
|
|
|
64
64
|
exports.isJSX = isJSX;
|
|
65
65
|
var isTSX = function (file) { return (0, fs_extra_1.pathExistsSync)(file) && (0, path_1.extname)(file) === '.tsx'; };
|
|
66
66
|
exports.isTSX = isTSX;
|
|
67
|
+
var isDTS = function (file) { return (0, fs_extra_1.pathExistsSync)(file) && file.endsWith('.d.ts'); };
|
|
68
|
+
exports.isDTS = isDTS;
|
|
67
69
|
var isScript = function (file) { return (0, fs_extra_1.pathExistsSync)(file) && constant_1.SCRIPTS_EXTENSIONS.includes((0, path_1.extname)(file)); };
|
|
68
70
|
exports.isScript = isScript;
|
|
69
71
|
var isLess = function (file) { return (0, fs_extra_1.pathExistsSync)(file) && (0, path_1.extname)(file) === '.less'; };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.12-alpha.25+4a1d7746",
|
|
4
4
|
"description": "cli of varlet",
|
|
5
5
|
"bin": {
|
|
6
6
|
"varlet-cli": "./lib/index.js"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dev": "tsc --watch",
|
|
32
32
|
"build": "tsc"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "4a1d774686bd66a53827bfb64a8495be97f9cf33",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/core": "^7.14.8",
|
|
37
37
|
"@babel/preset-env": "^7.14.8",
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="var-site-code-example">
|
|
3
|
+
<div class="var-site-code-example__toolbar">
|
|
4
|
+
<var-site-button text round @click="toggle" v-if="fold">
|
|
5
|
+
<var-site-icon name="xml" size="18" />
|
|
6
|
+
</var-site-button>
|
|
7
|
+
|
|
8
|
+
<var-site-button
|
|
9
|
+
:id="`clip-trigger-${cid}`"
|
|
10
|
+
:data-clipboard-target="`#clip-target-${cid}`"
|
|
11
|
+
text
|
|
12
|
+
round
|
|
13
|
+
v-if="clipboard"
|
|
14
|
+
>
|
|
15
|
+
<var-site-icon name="content-copy" size="18" />
|
|
16
|
+
</var-site-button>
|
|
17
|
+
</div>
|
|
18
|
+
<div
|
|
19
|
+
:id="`clip-target-${cid}`"
|
|
20
|
+
class="var-site-code-example__code"
|
|
21
|
+
ref="code"
|
|
22
|
+
:style="{
|
|
23
|
+
height: height >= 0 ? `${height}px` : undefined,
|
|
24
|
+
}"
|
|
25
|
+
>
|
|
26
|
+
<slot/>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script lang="ts">
|
|
32
|
+
import Icon from '../icon'
|
|
33
|
+
import Button from '../button'
|
|
34
|
+
import Snackbar from '../snackbar'
|
|
35
|
+
import Clipboard from 'clipboard'
|
|
36
|
+
import config from '@config'
|
|
37
|
+
import { defineComponent, nextTick, ref, onMounted } from 'vue'
|
|
38
|
+
import { doubleRaf } from '../utils/elements'
|
|
39
|
+
import { get } from 'lodash-es'
|
|
40
|
+
import { getPCLocationInfo } from '../../utils'
|
|
41
|
+
import type { Ref } from 'vue'
|
|
42
|
+
|
|
43
|
+
let clipId = 0
|
|
44
|
+
const offset = 10
|
|
45
|
+
|
|
46
|
+
export default defineComponent({
|
|
47
|
+
name: 'VarSiteCodeExample',
|
|
48
|
+
components: {
|
|
49
|
+
[Button.name]: Button,
|
|
50
|
+
[Icon.name]: Icon
|
|
51
|
+
},
|
|
52
|
+
setup() {
|
|
53
|
+
const code: Ref<HTMLElement | null> = ref(null)
|
|
54
|
+
const cid: Ref<number> = ref(clipId++)
|
|
55
|
+
const fold: Ref = ref(get(config, 'pc.fold'))
|
|
56
|
+
const clipboard: Ref = ref(get(config, 'pc.clipboard', {}))
|
|
57
|
+
const height: Ref<number> = ref(fold.value?.defaultFold ? fold.value?.foldHeight : -1)
|
|
58
|
+
|
|
59
|
+
const toggle = async () => {
|
|
60
|
+
const foldHeight = fold.value.foldHeight
|
|
61
|
+
|
|
62
|
+
if (height.value === foldHeight) {
|
|
63
|
+
height.value = -1
|
|
64
|
+
await nextTick()
|
|
65
|
+
const { offsetHeight } = code.value as HTMLElement
|
|
66
|
+
|
|
67
|
+
height.value = foldHeight
|
|
68
|
+
await doubleRaf()
|
|
69
|
+
|
|
70
|
+
if (offsetHeight - foldHeight < offset) {
|
|
71
|
+
Snackbar(get(config, `pc.fold.message.${getPCLocationInfo().language}`))
|
|
72
|
+
height.value = foldHeight
|
|
73
|
+
} else {
|
|
74
|
+
height.value = offsetHeight
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
const { offsetHeight } = code.value as HTMLElement
|
|
78
|
+
|
|
79
|
+
height.value = offsetHeight
|
|
80
|
+
await doubleRaf()
|
|
81
|
+
height.value = foldHeight
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onMounted(() => {
|
|
86
|
+
const trigger = new Clipboard(`#clip-trigger-${cid.value}`)
|
|
87
|
+
|
|
88
|
+
trigger.on('success', () => {
|
|
89
|
+
Snackbar.success(clipboard.value[getPCLocationInfo().language])
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
code,
|
|
95
|
+
height,
|
|
96
|
+
cid,
|
|
97
|
+
fold,
|
|
98
|
+
clipboard,
|
|
99
|
+
toggle
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<style lang="less">
|
|
106
|
+
@import "./codeExample";
|
|
107
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.var-site-code-example {
|
|
2
|
+
margin-top: 12px;
|
|
3
|
+
position: relative;
|
|
4
|
+
|
|
5
|
+
&__toolbar {
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
position: absolute;
|
|
9
|
+
z-index: 1;
|
|
10
|
+
right: 10px;
|
|
11
|
+
top: 20px;
|
|
12
|
+
|
|
13
|
+
button {
|
|
14
|
+
color: white !important;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&__code {
|
|
19
|
+
transition: all .25s;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PropType } from 'vue'
|
|
2
2
|
|
|
3
|
-
type LoadingType = 'circle' | 'wave' | 'cube' | 'rect' | 'disappear'
|
|
3
|
+
export type LoadingType = 'circle' | 'wave' | 'cube' | 'rect' | 'disappear'
|
|
4
4
|
|
|
5
|
-
type LoadingSize = 'normal' | 'mini' | 'small' | 'large'
|
|
5
|
+
export type LoadingSize = 'normal' | 'mini' | 'small' | 'large'
|
|
6
6
|
|
|
7
7
|
export function typeValidator(type: string): boolean {
|
|
8
8
|
return ['circle', 'wave', 'cube', 'rect', 'disappear'].includes(type)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<teleport :to="teleport" :disabled="disabled">
|
|
3
|
+
<transition name="var-site-snackbar-fade" @after-enter="onOpened" @after-leave="onClosed">
|
|
4
|
+
<var-site-snackbar-core v-bind="$props" class="var-site-snackbar-transition">
|
|
5
|
+
<slot>{{ content }}</slot>
|
|
6
|
+
<template #action>
|
|
7
|
+
<slot name="action" />
|
|
8
|
+
</template>
|
|
9
|
+
</var-site-snackbar-core>
|
|
10
|
+
</transition>
|
|
11
|
+
</teleport>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
import VarSiteSnackbarCore from './core'
|
|
16
|
+
import { defineComponent } from 'vue'
|
|
17
|
+
import { useTeleport } from '../utils/components'
|
|
18
|
+
import { props } from './props'
|
|
19
|
+
|
|
20
|
+
export default defineComponent({
|
|
21
|
+
name: 'VarSiteSnackbar',
|
|
22
|
+
components: {
|
|
23
|
+
VarSiteSnackbarCore,
|
|
24
|
+
},
|
|
25
|
+
props,
|
|
26
|
+
setup() {
|
|
27
|
+
const { disabled } = useTeleport()
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
disabled,
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<style lang="less">
|
|
37
|
+
@import '../styles/common';
|
|
38
|
+
</style>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="var-site-snackbar" :style="{ pointerEvents: isForbidClick ? 'auto' : 'none', zIndex }" v-show="show">
|
|
3
|
+
<div :class="snackbarClass" :style="{ zIndex }">
|
|
4
|
+
<div class="var-site-snackbar__content" :class="[contentClass]">
|
|
5
|
+
<slot>{{ content }}</slot>
|
|
6
|
+
</div>
|
|
7
|
+
<div class="var-site-snackbar__action">
|
|
8
|
+
<var-site-icon v-if="iconName" :name="iconName" />
|
|
9
|
+
<var-site-loading v-if="type === 'loading'" :type="loadingType" :size="loadingSize" />
|
|
10
|
+
<slot name="action" />
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import { defineComponent, watch, ref, onMounted, computed } from 'vue'
|
|
18
|
+
import VarSiteLoading from '../loading'
|
|
19
|
+
import VarSiteIcon from '../icon'
|
|
20
|
+
import { useZIndex } from '../context/zIndex'
|
|
21
|
+
import { props } from './props'
|
|
22
|
+
import { useLock } from '../context/lock'
|
|
23
|
+
import { SNACKBAR_TYPE } from './index'
|
|
24
|
+
import type { Ref, ComputedRef } from 'vue'
|
|
25
|
+
import type { SnackbarType } from './index'
|
|
26
|
+
|
|
27
|
+
const ICON_TYPE_DICT: Record<SnackbarType, string> = {
|
|
28
|
+
success: 'checkbox-marked-circle',
|
|
29
|
+
warning: 'warning',
|
|
30
|
+
info: 'information',
|
|
31
|
+
error: 'error',
|
|
32
|
+
loading: '',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default defineComponent({
|
|
36
|
+
name: 'VarSiteSnackbarCore',
|
|
37
|
+
components: {
|
|
38
|
+
VarSiteLoading,
|
|
39
|
+
VarSiteIcon,
|
|
40
|
+
},
|
|
41
|
+
props,
|
|
42
|
+
setup(props) {
|
|
43
|
+
const timer: Ref = ref(null)
|
|
44
|
+
const { zIndex } = useZIndex(() => props.show, 1)
|
|
45
|
+
|
|
46
|
+
useLock(props, 'show', 'lockScroll')
|
|
47
|
+
|
|
48
|
+
const snackbarClass: ComputedRef<string> = computed(() => {
|
|
49
|
+
const { position, vertical, type } = props
|
|
50
|
+
|
|
51
|
+
const baseClass = `var-site-snackbar__wrapper var-site-snackbar__wrapper-${position} var-site-elevation--4`
|
|
52
|
+
const verticalClass = vertical ? ' var-site-snackbar__vertical' : ''
|
|
53
|
+
const typeClass = type && SNACKBAR_TYPE.includes(type) ? ` var-site-snackbar__wrapper-${type}` : ''
|
|
54
|
+
|
|
55
|
+
return `${baseClass}${verticalClass}${typeClass}`
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const isForbidClick: ComputedRef<boolean> = computed(() => props.type === 'loading' || props.forbidClick)
|
|
59
|
+
|
|
60
|
+
const iconName: ComputedRef<string> = computed(() => {
|
|
61
|
+
if (!props.type) return ''
|
|
62
|
+
|
|
63
|
+
return ICON_TYPE_DICT[props.type]
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const updateAfterDuration = () => {
|
|
67
|
+
timer.value = setTimeout(() => {
|
|
68
|
+
props.type !== 'loading' && props['onUpdate:show']?.(false)
|
|
69
|
+
}, props.duration)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
watch(
|
|
73
|
+
() => props.show,
|
|
74
|
+
(show) => {
|
|
75
|
+
if (show) {
|
|
76
|
+
props.onOpen?.()
|
|
77
|
+
updateAfterDuration()
|
|
78
|
+
} else if (show === false) {
|
|
79
|
+
clearTimeout(timer.value)
|
|
80
|
+
props.onClose?.()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
watch(
|
|
86
|
+
() => props._update,
|
|
87
|
+
() => {
|
|
88
|
+
clearTimeout(timer.value)
|
|
89
|
+
updateAfterDuration()
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
onMounted(() => {
|
|
94
|
+
if (props.show) {
|
|
95
|
+
props.onOpen?.()
|
|
96
|
+
updateAfterDuration()
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
zIndex,
|
|
102
|
+
snackbarClass,
|
|
103
|
+
iconName,
|
|
104
|
+
isForbidClick,
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<style lang="less">
|
|
111
|
+
@import '../styles/common';
|
|
112
|
+
@import '../styles/elevation';
|
|
113
|
+
@import '../loading/loading';
|
|
114
|
+
@import '../button/button';
|
|
115
|
+
@import '../icon/icon';
|
|
116
|
+
@import './snackbar';
|
|
117
|
+
</style>
|