@varlet/cli 1.23.11 → 1.24.2-alpha.1640861757955

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 (49) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/generators/base/package.json +2 -2
  3. package/lib/commands/changelog.d.ts +6 -0
  4. package/lib/commands/changelog.js +27 -0
  5. package/lib/commands/commitLint.d.ts +1 -0
  6. package/lib/commands/commitLint.js +21 -0
  7. package/lib/commands/compile.js +3 -3
  8. package/lib/commands/create.js +8 -8
  9. package/lib/commands/dev.js +2 -2
  10. package/lib/commands/gen.js +3 -3
  11. package/lib/commands/jest.js +1 -1
  12. package/lib/commands/release.d.ts +1 -0
  13. package/lib/commands/release.js +197 -0
  14. package/lib/compiler/compileSFC.js +5 -5
  15. package/lib/compiler/compileScript.js +19 -19
  16. package/lib/compiler/compileSiteEntry.js +7 -7
  17. package/lib/compiler/compileStyle.js +6 -6
  18. package/lib/compiler/compileTemplateHighlight.js +4 -4
  19. package/lib/compiler/compileTypes.js +5 -5
  20. package/lib/config/jest.config.js +3 -3
  21. package/lib/config/vite.config.js +5 -5
  22. package/lib/index.js +13 -2
  23. package/package.json +30 -37
  24. package/site/components/code-example/CodeExample.vue +107 -0
  25. package/site/components/code-example/codeExample.less +23 -0
  26. package/site/components/code-example/index.ts +10 -0
  27. package/site/components/icon/icon.less +1 -0
  28. package/site/components/loading/props.ts +2 -2
  29. package/site/components/snackbar/Snackbar.vue +38 -0
  30. package/site/components/snackbar/core.vue +117 -0
  31. package/site/components/snackbar/index.tsx +270 -0
  32. package/site/components/snackbar/props.ts +94 -0
  33. package/site/components/snackbar/snackbar.less +135 -0
  34. package/site/components/utils/elements.ts +8 -0
  35. package/site/components/utils/shared.ts +3 -0
  36. package/site/mobile/App.vue +6 -6
  37. package/site/module.d.ts +4 -0
  38. package/site/pc/App.vue +8 -10
  39. package/site/pc/components/AppHeader.vue +8 -9
  40. package/site/pc/components/AppSidebar.vue +6 -6
  41. package/site/pc/main.ts +8 -2
  42. package/site/tsconfig.json +1 -6
  43. package/site/useProgress.ts +6 -2
  44. package/site/utils.ts +4 -3
  45. package/tsconfig.json +0 -2
  46. package/varlet.default.config.js +13 -0
  47. package/generators/base/.gitignore +0 -14
  48. package/site/.DS_Store +0 -0
  49. package/site/components/.DS_Store +0 -0
@@ -85,17 +85,17 @@ function compileTable(md, titleRe) {
85
85
  }
86
86
  exports.compileTable = compileTable;
87
87
  function compileTags(table, tags, componentName) {
88
- tags[(0, lodash_1.get)(varletConfig, 'namespace') + "-" + componentName] = {
88
+ tags["".concat((0, lodash_1.get)(varletConfig, 'namespace'), "-").concat(componentName)] = {
89
89
  attributes: table.attributesTable.map(function (row) { return (0, exports.replaceDot)(row[0]); }),
90
90
  };
91
91
  }
92
92
  exports.compileTags = compileTags;
93
93
  function compileAttributes(table, attributes, componentName) {
94
94
  table.attributesTable.forEach(function (row) {
95
- var attrNamespace = (0, lodash_1.get)(varletConfig, 'namespace') + "-" + componentName + "/" + (0, exports.replaceDot)(row[0]);
95
+ var attrNamespace = "".concat((0, lodash_1.get)(varletConfig, 'namespace'), "-").concat(componentName, "/").concat((0, exports.replaceDot)(row[0]));
96
96
  attributes[attrNamespace] = {
97
97
  type: (0, exports.replaceUnderline)(row[2]),
98
- description: row[1] + " \u9ED8\u8BA4\u503C\uFF1A" + (0, exports.replaceDot)(row[3]),
98
+ description: "".concat(row[1], " \u9ED8\u8BA4\u503C\uFF1A").concat((0, exports.replaceDot)(row[3])),
99
99
  };
100
100
  });
101
101
  }
@@ -120,7 +120,7 @@ function compileWebTypes(table, webTypes, componentName) {
120
120
  description: row[1],
121
121
  }); });
122
122
  webTypes.contributions.html.tags.push({
123
- name: (0, lodash_1.get)(varletConfig, 'namespace') + "-" + componentName,
123
+ name: "".concat((0, lodash_1.get)(varletConfig, 'namespace'), "-").concat(componentName),
124
124
  attributes: attributes,
125
125
  events: events,
126
126
  slots: slots,
@@ -44,7 +44,7 @@ var path_1 = require("path");
44
44
  var varlet_config_1 = require("../config/varlet.config");
45
45
  var lodash_1 = require("lodash");
46
46
  function generateReference(moduleDir) {
47
- (0, fs_extra_1.writeFileSync)((0, path_1.resolve)(moduleDir, 'index.d.ts'), "export * from '" + (0, path_1.relative)(moduleDir, constant_1.TYPES_DIR) + "'\n");
47
+ (0, fs_extra_1.writeFileSync)((0, path_1.resolve)(moduleDir, 'index.d.ts'), "export * from '".concat((0, path_1.relative)(moduleDir, constant_1.TYPES_DIR), "'\n"));
48
48
  }
49
49
  exports.generateReference = generateReference;
50
50
  function compileTypes() {
@@ -67,13 +67,13 @@ function compileTypes() {
67
67
  declares = [];
68
68
  ignoreEntryDir.forEach(function (filename) {
69
69
  var componentName = filename.slice(0, filename.indexOf('.d.ts'));
70
- exports.push("export * from './" + componentName + "'");
70
+ exports.push("export * from './".concat(componentName, "'"));
71
71
  if (!componentName.startsWith(namespace)) {
72
- declares.push("" + (0, fsUtils_1.bigCamelize)(namespace) + (0, fsUtils_1.bigCamelize)(componentName) + ": typeof import('" + name + "')['_" + (0, fsUtils_1.bigCamelize)(componentName) + "Component']");
72
+ declares.push("".concat((0, fsUtils_1.bigCamelize)(namespace)).concat((0, fsUtils_1.bigCamelize)(componentName), ": typeof import('").concat(name, "')['_").concat((0, fsUtils_1.bigCamelize)(componentName), "Component']"));
73
73
  }
74
74
  });
75
- template = "import type { App } from 'vue'\n\nexport const install: (app: App) => void\n\n" + exports.join('\n') + "\n";
76
- globalTemplate = "declare module 'vue' {\n export interface GlobalComponents {\n " + declares.join('\n ') + "\n }\n}\n\nexport {}\n";
75
+ template = "import type { App } from 'vue'\n\nexport const install: (app: App) => void\n\n".concat(exports.join('\n'), "\n");
76
+ globalTemplate = "declare module 'vue' {\n export interface GlobalComponents {\n ".concat(declares.join('\n '), "\n }\n}\n\nexport {}\n");
77
77
  return [4 /*yield*/, Promise.all([
78
78
  (0, fs_extra_1.writeFile)((0, path_1.resolve)(constant_1.TYPES_DIR, 'index.d.ts'), template),
79
79
  (0, fs_extra_1.writeFile)((0, path_1.resolve)(constant_1.TYPES_DIR, 'global.d.ts'), globalTemplate),
@@ -30,7 +30,7 @@ module.exports = __assign({ moduleNameMapper: {
30
30
  '\\.(js|jsx|ts|tsx)$': 'babel-jest',
31
31
  }, collectCoverage: true, collectCoverageFrom: [
32
32
  'src/**/*.{js,jsx,ts,tsx,vue}',
33
- "!**/" + constant_1.EXAMPLE_DIR_NAME + "/**",
34
- "!**/" + constant_1.DOCS_DIR_NAME + "/**",
35
- "!**/" + constant_1.TESTS_DIR_NAME + "/**",
33
+ "!**/".concat(constant_1.EXAMPLE_DIR_NAME, "/**"),
34
+ "!**/".concat(constant_1.DOCS_DIR_NAME, "/**"),
35
+ "!**/".concat(constant_1.TESTS_DIR_NAME, "/**"),
36
36
  ], moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'vue'], transformIgnorePatterns: ['/node_modules/(?!(@varlet/cli))/'] }, getRootConfig());
@@ -49,8 +49,8 @@ function getDevConfig(varletConfig) {
49
49
  (0, plugin_vue_jsx_1.default)(),
50
50
  (0, vite_plugin_html_1.injectHtml)({
51
51
  data: {
52
- pcTitle: (0, lodash_1.get)(varletConfig, "pc.title['" + defaultLanguage + "']"),
53
- mobileTitle: (0, lodash_1.get)(varletConfig, "mobile.title['" + defaultLanguage + "']"),
52
+ pcTitle: (0, lodash_1.get)(varletConfig, "pc.title['".concat(defaultLanguage, "']")),
53
+ mobileTitle: (0, lodash_1.get)(varletConfig, "mobile.title['".concat(defaultLanguage, "']")),
54
54
  logo: (0, lodash_1.get)(varletConfig, "logo"),
55
55
  baidu: (0, lodash_1.get)(varletConfig, "analysis.baidu", ''),
56
56
  },
@@ -86,8 +86,8 @@ function inlineCSS(fileName, dir) {
86
86
  var jsFile = (0, path_1.resolve)(dir, fileName);
87
87
  var cssCode = (0, fs_extra_1.readFileSync)(cssFile, 'utf-8');
88
88
  var jsCode = (0, fs_extra_1.readFileSync)(jsFile, 'utf-8');
89
- var injectCode = ";(function(){var style=document.createElement('style');style.type='text/css';style.rel='stylesheet';style.appendChild(document.createTextNode(`" + cssCode.replace(/\\/g, '\\\\') + "`));var head=document.querySelector('head');head.appendChild(style)})();";
90
- (0, fs_extra_1.writeFileSync)(jsFile, "" + injectCode + jsCode);
89
+ var injectCode = ";(function(){var style=document.createElement('style');style.type='text/css';style.rel='stylesheet';style.appendChild(document.createTextNode(`".concat(cssCode.replace(/\\/g, '\\\\'), "`));var head=document.querySelector('head');head.appendChild(style)})();");
90
+ (0, fs_extra_1.writeFileSync)(jsFile, "".concat(injectCode).concat(jsCode));
91
91
  (0, fs_extra_1.copyFileSync)(cssFile, (0, path_1.resolve)(constant_1.LIB_DIR, 'style.css'));
92
92
  (0, fs_extra_1.removeSync)(cssFile);
93
93
  },
@@ -104,7 +104,7 @@ function clear() {
104
104
  }
105
105
  function getUMDConfig(varletConfig) {
106
106
  var name = (0, lodash_1.get)(varletConfig, 'name');
107
- var fileName = (0, lodash_1.kebabCase)(name) + ".js";
107
+ var fileName = "".concat((0, lodash_1.kebabCase)(name), ".js");
108
108
  return {
109
109
  logLevel: 'silent',
110
110
  build: {
package/lib/index.js CHANGED
@@ -30,8 +30,11 @@ var jest_1 = require("./commands/jest");
30
30
  var lint_1 = require("./commands/lint");
31
31
  var gen_1 = require("./commands/gen");
32
32
  var preview_1 = require("./commands/preview");
33
+ var changelog_1 = require("./commands/changelog");
34
+ var release_1 = require("./commands/release");
35
+ var commitLint_1 = require("./commands/commitLint");
33
36
  var program = new commander_1.Command();
34
- program.version("varlet-cli " + require('../package.json').version).usage('<command> [options]');
37
+ program.version("varlet-cli ".concat(require('../package.json').version)).usage('<command> [options]');
35
38
  program
36
39
  .command('dev')
37
40
  .option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
@@ -55,10 +58,18 @@ program
55
58
  .option('-cc --clearCache', 'Clear test cache')
56
59
  .action(jest_1.jest);
57
60
  program.command('gen <name>').description('Generate cli application').action(gen_1.gen);
61
+ program
62
+ .command('changelog')
63
+ .option('-rc --releaseCount <releaseCount>', 'Release count')
64
+ .option('-f --file <file>', 'Changelog filename')
65
+ .description('Generate changelog')
66
+ .action(changelog_1.changelog);
67
+ program.command('release').description('Release all packages and generate changelogs').action(release_1.release);
68
+ program.command('commit-lint <gitParams>').description('Lint commit message').action(commitLint_1.commitLint);
58
69
  program.on('command:*', function (_a) {
59
70
  var _b = __read(_a, 1), cmd = _b[0];
60
71
  program.outputHelp();
61
- logger_1.default.error("\nUnknown command " + cmd + ".\n");
72
+ logger_1.default.error("\nUnknown command ".concat(cmd, ".\n"));
62
73
  process.exitCode = 1;
63
74
  });
64
75
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "1.23.11",
3
+ "version": "1.24.2-alpha.1640861757955",
4
4
  "description": "cli of varlet",
5
5
  "bin": {
6
6
  "varlet-cli": "./lib/index.js"
@@ -27,59 +27,42 @@
27
27
  "bugs": {
28
28
  "url": "https://github.com/haoziqaq/varlet/issues"
29
29
  },
30
- "scripts": {
31
- "dev": "tsc --watch",
32
- "build": "tsc"
33
- },
34
- "gitHead": "449df88f0ff65a2ad89fa48a5d443ab864bd0bb3",
30
+ "gitHead": "ee9c3866bedad96c86365b0f9888a3a6bb781b1f",
35
31
  "dependencies": {
32
+ "@varlet/icons": "1.24.2-alpha.1640861757955",
33
+ "@varlet/markdown-vite-plugin": "1.24.2-alpha.1640861757955",
34
+ "@varlet/touch-emulator": "1.24.2-alpha.1640861757955",
36
35
  "@babel/core": "^7.14.8",
37
36
  "@babel/preset-env": "^7.14.8",
38
37
  "@babel/preset-typescript": "^7.14.5",
39
- "@commitlint/cli": "^11.0.0",
40
- "@commitlint/config-conventional": "^11.0.0",
41
- "@release-it/conventional-changelog": "^3.3.0",
42
- "@varlet/eslint-config": "^1.13.0",
43
- "@varlet/icons": "^1.23.0",
44
- "@varlet/markdown-vite-plugin": "^1.22.0",
45
- "@varlet/stylelint-config": "^1.9.0",
46
- "@varlet/touch-emulator": "^1.0.1",
38
+ "@babel/helper-plugin-utils": "^7.14.5",
39
+ "vue": "3.2.16",
40
+ "vite": "2.6.5",
47
41
  "@vitejs/plugin-vue": "1.9.2",
48
42
  "@vitejs/plugin-vue-jsx": "1.1.8",
49
- "@vue/babel-plugin-jsx": "^1.0.7",
50
- "@vue/compiler-sfc": "3.2.22",
51
- "@vue/test-utils": "^2.0.0-rc.6",
52
- "babel-jest": "26.6.3",
43
+ "vite-plugin-html": "^2.1.0",
44
+ "@vue/babel-plugin-jsx": "1.0.7",
45
+ "@vue/compiler-sfc": "3.2.16",
46
+ "conventional-changelog": "^3.1.25",
53
47
  "chalk": "^4.1.0",
48
+ "glob": "^7.2.0",
49
+ "semver": "^7.3.5",
54
50
  "chokidar": "^3.5.2",
55
- "clipboard": "^2.0.6",
56
51
  "commander": "^8.3.0",
57
- "commitizen": "^4.2.2",
58
- "conventional-changelog-cli": "^2.1.1",
59
- "cz-conventional-changelog": "^3.3.0",
60
- "eslint": "^7.30.0",
61
52
  "execa": "^5.0.0",
62
53
  "fs-extra": "^9.0.1",
63
54
  "hash-sum": "^2.0.0",
64
- "husky": "^7.0.1",
65
55
  "inquirer": "^8.1.2",
66
- "jest": "^26.6.3",
67
56
  "less": "^3.12.2",
68
- "lint-staged": "^10.5.0",
69
- "live-server": "^1.2.1",
70
57
  "lodash": "^4.17.21",
71
- "lodash-es": "^4.17.21",
72
58
  "ora": "^5.4.0",
73
- "prettier": "^2.3.2",
74
- "release-it": "^14.11.5",
75
59
  "slash": "^3.0.0",
76
- "stylelint": "^13.13.1",
77
- "ts-jest": "^26.5.1",
78
60
  "typescript": "^4.4.4",
79
- "vite": "2.6.5",
80
- "vite-plugin-html": "^2.1.0",
61
+ "jest": "^26.6.3",
62
+ "babel-jest": "26.6.3",
63
+ "ts-jest": "^26.5.1",
81
64
  "vue-jest": "^5.0.0-alpha.8",
82
- "vue-router": "4.0.12"
65
+ "lodash-es": "^4.17.21"
83
66
  },
84
67
  "devDependencies": {
85
68
  "@types/babel__core": "^7.1.12",
@@ -90,6 +73,16 @@
90
73
  "@types/lodash-es": "^4.17.5"
91
74
  },
92
75
  "peerDependencies": {
93
- "vue": "3.2.16"
76
+ "@varlet/touch-emulator": "1.24.2-alpha.1640861757955",
77
+ "@vue/test-utils": "^2.0.0-rc.6",
78
+ "vue": "3.2.16",
79
+ "vue-router": "4.0.12",
80
+ "live-server": "^1.2.1",
81
+ "lodash-es": "^4.17.21",
82
+ "clipboard": "^2.0.6"
83
+ },
84
+ "scripts": {
85
+ "dev": "tsc --watch",
86
+ "build": "tsc"
94
87
  }
95
- }
88
+ }
@@ -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
+ }
@@ -0,0 +1,10 @@
1
+ import type { App } from 'vue'
2
+ import CodeExample from './CodeExample.vue'
3
+
4
+ CodeExample.install = function (app: App) {
5
+ app.component(CodeExample.name, CodeExample)
6
+ }
7
+
8
+ export const _CodeExampleComponent = CodeExample
9
+
10
+ export default CodeExample
@@ -12,6 +12,7 @@
12
12
  align-items: center;
13
13
  font-size: var(--site-icon-size);
14
14
  color: inherit;
15
+ vertical-align: bottom;
15
16
 
16
17
  &--shrinking {
17
18
  transform: scale(0);
@@ -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>