@varlet/cli 2.10.0-alpha.1681657406626 → 2.10.0-alpha.1682265464192

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.
@@ -17,6 +17,7 @@ function getRootConfig() {
17
17
 
18
18
  module.exports = {
19
19
  testEnvironment: 'jsdom',
20
+ coverageProvider: 'v8',
20
21
  testEnvironmentOptions: {
21
22
  customExportConditions: ['node', 'node-addons'],
22
23
  },
@@ -2,6 +2,7 @@ import AppType from './appType';
2
2
  interface PCLocationInfo {
3
3
  language: string;
4
4
  menuName: string;
5
+ hash: string;
5
6
  }
6
7
  export declare type Theme = 'lightTheme' | 'darkTheme';
7
8
  export declare type StyleVars = Record<string, string>;
@@ -21,10 +21,13 @@ export function StyleProvider(styleVars = {}) {
21
21
  });
22
22
  }
23
23
  export function getPCLocationInfo() {
24
- const [, language, menuName] = window.location.hash.split('/');
24
+ var _a;
25
+ const [, language, path] = window.location.hash.split('/');
26
+ const [menuName, hash = ''] = (_a = path === null || path === void 0 ? void 0 : path.split('#')) !== null && _a !== void 0 ? _a : [];
25
27
  return {
26
28
  language,
27
29
  menuName,
30
+ hash,
28
31
  };
29
32
  }
30
33
  function getHashSearch() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.10.0-alpha.1681657406626",
3
+ "version": "2.10.0-alpha.1682265464192",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -46,6 +46,7 @@
46
46
  "@vue/compiler-sfc": "3.2.25",
47
47
  "@vue/runtime-core": "3.2.25",
48
48
  "@vue/vue3-jest": "^29.2.3",
49
+ "babel-jest": "^29.5.0",
49
50
  "chokidar": "^3.5.2",
50
51
  "commander": "^8.3.0",
51
52
  "conventional-changelog": "^3.1.25",
@@ -55,6 +56,8 @@
55
56
  "glob": "^7.2.0",
56
57
  "hash-sum": "^2.0.0",
57
58
  "inquirer": "^9.1.4",
59
+ "jest": "^29.5.0",
60
+ "jest-environment-jsdom": "^29.5.0",
58
61
  "less": "^3.12.2",
59
62
  "lodash-es": "^4.17.21",
60
63
  "markdown-it": "^12.2.3",
@@ -63,16 +66,12 @@
63
66
  "semver": "^7.3.5",
64
67
  "sharp": "0.31.1",
65
68
  "slash": "^3.0.0",
66
- "ts-jest": "^29.1.0",
67
69
  "typescript": "^4.4.4",
68
70
  "vite": "4.0.4",
69
71
  "vue": "3.2.25",
70
72
  "webfont": "^9.0.0",
71
- "babel-jest": "^29.5.0",
72
- "jest": "^29.5.0",
73
- "jest-environment-jsdom": "^29.5.0",
74
- "@varlet/shared": "2.10.0-alpha.1681657406626",
75
- "@varlet/vite-plugins": "2.10.0-alpha.1681657406626"
73
+ "@varlet/vite-plugins": "2.10.0-alpha.1682265464192",
74
+ "@varlet/shared": "2.10.0-alpha.1682265464192"
76
75
  },
77
76
  "devDependencies": {
78
77
  "@types/babel__core": "^7.1.12",
@@ -86,8 +85,8 @@
86
85
  "@types/node": "^18.7.20",
87
86
  "@types/semver": "^7.3.9",
88
87
  "@types/sharp": "0.31.1",
89
- "@varlet/icons": "2.10.0-alpha.1681657406626",
90
- "@varlet/touch-emulator": "2.10.0-alpha.1681657406626"
88
+ "@varlet/touch-emulator": "2.10.0-alpha.1682265464192",
89
+ "@varlet/icons": "2.10.0-alpha.1682265464192"
91
90
  },
92
91
  "peerDependencies": {
93
92
  "@vue/runtime-core": "3.2.47",
@@ -97,8 +96,8 @@
97
96
  "lodash-es": "^4.17.21",
98
97
  "vue": "3.2.47",
99
98
  "vue-router": "4.1.6",
100
- "@varlet/icons": "2.10.0-alpha.1681657406626",
101
- "@varlet/touch-emulator": "2.10.0-alpha.1681657406626"
99
+ "@varlet/touch-emulator": "2.10.0-alpha.1682265464192",
100
+ "@varlet/icons": "2.10.0-alpha.1682265464192"
102
101
  },
103
102
  "scripts": {
104
103
  "dev": "tsc --watch",
@@ -37,9 +37,9 @@ const router = createRouter({
37
37
  })
38
38
 
39
39
  router.beforeEach((to: any) => {
40
- const language = to.query.language ?? defaultLanguage
41
- const path = to.path
42
- const replace = to.query.replace
40
+ const { path, hash, query } = to
41
+ const language = query.language ?? defaultLanguage
42
+ const replace = query.replace
43
43
 
44
44
  if (!isPhone() && !inIframe()) {
45
45
  window.location.href = `./#/${language}${path}`
@@ -48,7 +48,7 @@ router.beforeEach((to: any) => {
48
48
  if (!isPhone() && inIframe()) {
49
49
  try {
50
50
  // @ts-ignore
51
- window.parent.onMobileRouteChange(path, language, replace)
51
+ window.parent.onMobileRouteChange(path, language, replace, hash)
52
52
  } catch (e) {
53
53
  console.log(e)
54
54
  }
@@ -18,6 +18,7 @@ const mobileRedirect = get(config, 'mobile.redirect')
18
18
  const language: Ref<string> = ref('')
19
19
  const componentName: Ref<null | string> = ref(null)
20
20
  const menuName: Ref<string> = ref('')
21
+ const hash: Ref<string> = ref('')
21
22
  const doc: Ref<HTMLElement | null> = ref(null)
22
23
  const route = useRoute()
23
24
 
@@ -48,6 +49,7 @@ const handleSidebarChange = (menu: Menu) => {
48
49
  doc.value!.scrollTop = 0
49
50
  componentName.value = getComponentNameByMenuName(menu.doc)
50
51
  menuName.value = menu.doc
52
+ hash.value = ''
51
53
  }
52
54
 
53
55
  const confirmClose = () => {
@@ -79,13 +81,14 @@ onMounted(() => {
79
81
  watch(
80
82
  () => route.path,
81
83
  () => {
82
- const { language: lang, menuName: _menuName } = getPCLocationInfo()
84
+ const { language: lang, menuName: _menuName, hash: _hash } = getPCLocationInfo()
83
85
  if (!lang || !_menuName) {
84
86
  return
85
87
  }
86
88
 
87
89
  componentName.value = getComponentNameByMenuName(_menuName)
88
90
  menuName.value = _menuName
91
+ hash.value = _hash
89
92
  language.value = lang
90
93
  useMobile.value = menu.value.find(item => item.doc === _menuName)?.useMobile ?? get(config, 'useMobile')
91
94
  document.title = get(config, 'pc.title')[lang] as string
@@ -118,6 +121,7 @@ watch(
118
121
  :component-name="componentName"
119
122
  :language="language"
120
123
  :replace="menuName"
124
+ :hash="hash"
121
125
  v-show="useMobile"
122
126
  />
123
127
  </div>
@@ -282,6 +286,19 @@ iframe {
282
286
  }
283
287
 
284
288
  &-doc {
289
+ h3 {
290
+ display: flex;
291
+ align-items: center;
292
+
293
+ .router-link-active {
294
+ font-size: 20px;
295
+ margin-right: 8px;
296
+ user-select: none;
297
+ text-decoration: none;
298
+ }
299
+ }
300
+
301
+
285
302
  a {
286
303
  color: var(--site-config-color-link);
287
304
  -webkit-font-smoothing: antialiased;
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="varlet-site-mobile varlet-site-mobile--375">
3
3
  <div class="varlet-site-mobile-content">
4
- <iframe id="mobile" :src="`./mobile.html#/${componentName}?language=${language}&platform=pc&replace=${replace}`"></iframe>
4
+ <iframe id="mobile" :src="`./mobile.html#/${componentName}?language=${language}&platform=pc&replace=${replace}${hash ? `#${hash}` : ''}`"></iframe>
5
5
  </div>
6
6
  </div>
7
7
  </template>
@@ -18,6 +18,9 @@ export default {
18
18
  },
19
19
  replace: {
20
20
  type: String
21
+ },
22
+ hash: {
23
+ type: String
21
24
  }
22
25
  }
23
26
  }
package/site/pc/main.ts CHANGED
@@ -36,14 +36,24 @@ redirect &&
36
36
 
37
37
  const router = createRouter({
38
38
  history: createWebHashHistory(),
39
- scrollBehavior: () => ({ top: 0 }),
40
39
  routes,
40
+ scrollBehavior(to: any) {
41
+ if (to.hash) {
42
+ return {
43
+ el: to.hash,
44
+ behavior: 'smooth',
45
+ top: 100
46
+ };
47
+ }
48
+
49
+ return { top: 0 };
50
+ },
41
51
  })
42
52
 
43
53
  let isEnd = true
44
54
 
45
55
  router.beforeEach((to: any, from: any) => {
46
- if (to.path === from.path) {
56
+ if (to.fullPath === from.fullPath) {
47
57
  return false
48
58
  }
49
59
 
@@ -65,13 +75,13 @@ router.afterEach(() => {
65
75
  })
66
76
 
67
77
  Object.defineProperty(window, 'onMobileRouteChange', {
68
- value: (path: string, language: string, replace: string) => {
78
+ value: (path: string, language: string, replace: string, hash: string) => {
69
79
  if (path === mobileRedirect) {
70
- router.replace(`/${language}/${replace}`)
80
+ router.replace(`/${language}/${replace}${hash}`)
71
81
  return
72
82
  }
73
83
 
74
- router.replace(`/${language}${path}`)
84
+ router.replace(`/${language}${path}${hash}`)
75
85
  }
76
86
  })
77
87