@umijs/plugin-docs 4.0.0-rc.3 → 4.0.0-rc.6

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.
@@ -1,10 +1,17 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import useLanguage from './useLanguage';
3
3
 
4
4
  export default () => {
5
- const { currentLanguage, languages, switchLanguage } = useLanguage();
5
+ const { currentLanguage, languages, switchLanguage, isFromPath } =
6
+ useLanguage();
6
7
  const [isExpanded, setExpanded] = useState(false);
7
8
 
9
+ // 首次加载时,根据 localstorage 记录的上次语言自动切换
10
+ useEffect(() => {
11
+ const locale = window.localStorage.getItem('umi_locale');
12
+ if (locale && !isFromPath) switchLanguage(locale);
13
+ }, []);
14
+
8
15
  if (!currentLanguage) {
9
16
  return null;
10
17
  }
@@ -25,7 +32,7 @@ export default () => {
25
32
  return (
26
33
  <div>
27
34
  <div
28
- className="w-24 rounded-lg overflow-hidden cursor-pointer border
35
+ className="w-24 rounded-lg overflow-hidden cursor-pointer border text-center
29
36
  border-white hover:border-gray-100 dark:border-gray-800"
30
37
  onClick={handleClick}
31
38
  >
@@ -31,6 +31,10 @@ export default (props: any) => {
31
31
 
32
32
  const { title, description } = props.themeConfig;
33
33
 
34
+ const isHomePage =
35
+ window.location.pathname === '/' ||
36
+ window.location.pathname.replace(/[a-z]{2}-[A-Z]{2}\/?/, '') === '/';
37
+
34
38
  return (
35
39
  <ThemeContext.Provider
36
40
  value={{
@@ -54,7 +58,7 @@ export default (props: any) => {
54
58
  <div className="g-glossy-firefox-cover" />
55
59
  <div className="g-glossy-firefox" id="firefox-head-bg" />
56
60
 
57
- {window.location.pathname === '/' ? (
61
+ {isHomePage ? (
58
62
  <div id="article-body">
59
63
  <Helmet>
60
64
  <title>
@@ -71,7 +75,7 @@ export default (props: any) => {
71
75
  className="w-full flex flex-row justify-center overflow-x-hidden"
72
76
  >
73
77
  <div className="container flex flex-row justify-center">
74
- <div className="w-full lg:w-1/2 px-4 lg:px-0 m-8 z-20 lg:py-12">
78
+ <div className="w-full lg:w-1/2 px-4 lg:px-2 m-8 z-20 lg:py-12">
75
79
  <article className="flex-1">{props.children}</article>
76
80
  </div>
77
81
  </div>
@@ -1,12 +1,16 @@
1
1
  import React from 'react';
2
2
  import { useThemeContext } from './context';
3
+ import useLanguage from './useLanguage';
3
4
 
4
5
  export default () => {
5
6
  const { themeConfig, components } = useThemeContext()!;
7
+ const { isFromPath, currentLanguage } = useLanguage();
8
+
6
9
  // @ts-ignore
7
10
  const { logo } = themeConfig;
11
+
8
12
  return (
9
- <components.Link to="/">
13
+ <components.Link to={isFromPath ? '/' + currentLanguage?.locale : '/'}>
10
14
  <div className="flex flex-row items-center">
11
15
  <img src={logo} className="w-8 h-8" alt="logo" />
12
16
  <div className="text-xl font-extrabold ml-2 dark:text-white">
@@ -65,7 +65,7 @@ export default () => {
65
65
  <div
66
66
  className="rounded-lg w-40 lg:w-64 flex items-center pr-2 flex-row hover:bg-gray-50
67
67
  transition duration-300 bg-gray-100 border border-white focus-within:border-gray-100
68
- focus-within:bg-white dark:bg-gray-700 dark:border-gray-700
68
+ focus-within:bg-white dark:bg-gray-700 dark:border-gray-700 relative
69
69
  dark:focus-within:border-gray-700 dark:focus-within:bg-gray-800 dark:text-gray-100"
70
70
  >
71
71
  <input
@@ -74,7 +74,7 @@ export default () => {
74
74
  value={keyword}
75
75
  onChange={(e) => setKeyword(e.target.value)}
76
76
  id="search-input"
77
- className="w-full bg-transparent outline-0 text-sm px-4 py-2 "
77
+ className="w-full bg-transparent outline-none text-sm px-4 py-2 "
78
78
  placeholder={render('Search anything ...')}
79
79
  />
80
80
  <div
@@ -85,7 +85,7 @@ export default () => {
85
85
  </div>
86
86
  <div
87
87
  className={cx(
88
- 'absolute transition-all duration-500 top-16 w-96 rounded-lg',
88
+ 'absolute transition-all duration-500 top-12 w-96 rounded-lg',
89
89
  'cursor-pointer shadow overflow-hidden',
90
90
  result.length > 0 && isFocused ? 'max-h-80' : 'max-h-0',
91
91
  )}
@@ -36,9 +36,9 @@ export default () => {
36
36
  return (
37
37
  <div
38
38
  className={cx(
39
- 'md:w-12 md:h-6 w-12 h-4 flex items-center bg-gray-300 rounded-full ',
39
+ 'md:w-12 md:h-6 w-12 h-4 flex items-center rounded-full ',
40
40
  'py-1 px-1.5 cursor-pointer',
41
- toggle ? 'bg-blue-300' : 'bg-gray-700',
41
+ toggle ? 'bg-gray-100' : 'bg-gray-700',
42
42
  )}
43
43
  onClick={() => setToggle(!toggle)}
44
44
  >
@@ -40,7 +40,7 @@ export default () => {
40
40
  <p className="text-lg font-extrabold dark:text-white">
41
41
  {route.titles[0].title}
42
42
  </p>
43
- <ul className="max-h-[calc(100vh-360px)] overflow-y-scroll py-2">
43
+ <ul className="max-h-[calc(100vh-360px)] overflow-y-auto py-2">
44
44
  {titles.map((item: any) => {
45
45
  return (
46
46
  <li
@@ -13,22 +13,21 @@ interface MessageProps {
13
13
  }
14
14
 
15
15
  function Message(props: PropsWithChildren<MessageProps>) {
16
- let bgColor = 'bg-blue-50';
17
- let textColor = 'text-blue-900';
16
+ const messageType = props.type || 'info';
18
17
 
19
- switch (props.type) {
18
+ let messageClass: string;
19
+ switch (messageType) {
20
20
  case MessageType.Success:
21
- bgColor = 'bg-green-50';
22
- textColor = 'text-green-900';
21
+ messageClass = 'mdx-message-success';
23
22
  break;
24
23
  case MessageType.Warning:
25
- bgColor = 'bg-orange-50';
26
- textColor = 'text-orange-900';
24
+ messageClass = 'mdx-message-warning';
27
25
  break;
28
26
  case MessageType.Error:
29
- bgColor = 'bg-red-50';
30
- textColor = 'text-red-900';
27
+ messageClass = 'mdx-message-error';
31
28
  break;
29
+ default:
30
+ messageClass = 'mdx-message-info';
32
31
  }
33
32
 
34
33
  const messageText =
@@ -39,7 +38,7 @@ function Message(props: PropsWithChildren<MessageProps>) {
39
38
  return (
40
39
  <>
41
40
  <div
42
- className={`w-full py-3 px-4 ${bgColor} ${textColor} rounded-lg my-4 mdx-message`}
41
+ className={`w-full py-3 px-4 rounded-lg my-4 mdx-message ${messageClass}`}
43
42
  >
44
43
  <p>
45
44
  {props.emoji && (
@@ -3,7 +3,8 @@
3
3
  https://www.cnblogs.com/coco1s/p/14953143.html
4
4
  */
5
5
 
6
- .g-glossy-firefox, .g-glossy-firefox-cover {
6
+ .g-glossy-firefox,
7
+ .g-glossy-firefox-cover {
7
8
  display: none;
8
9
  }
9
10
 
@@ -84,12 +84,18 @@ article a code {
84
84
 
85
85
  article a {
86
86
  @apply text-blue-600 mx-1 hover:text-blue-300 transition dark:text-blue-400;
87
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
87
+ background-image: linear-gradient(
88
+ transparent 60%,
89
+ rgba(130, 199, 255, 0.28) 55%
90
+ );
88
91
  }
89
92
 
90
93
  .link-with-underline {
91
94
  @apply text-blue-600 mx-1 hover:text-blue-300 transition dark:text-blue-400;
92
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
95
+ background-image: linear-gradient(
96
+ transparent 60%,
97
+ rgba(130, 199, 255, 0.28) 55%
98
+ );
93
99
  }
94
100
 
95
101
  /*article pre {*/
@@ -111,7 +117,7 @@ article hr {
111
117
  }
112
118
 
113
119
  html {
114
- scroll-behavior: smooth
120
+ scroll-behavior: smooth;
115
121
  }
116
122
 
117
123
  :root {
@@ -119,12 +125,16 @@ html {
119
125
  }
120
126
 
121
127
  /** Anchor with offset for headings */
122
- h1, h2, h3, h4, h5, h6 {
128
+ h1,
129
+ h2,
130
+ h3,
131
+ h4,
132
+ h5,
133
+ h6 {
123
134
  scroll-margin-top: calc(var(--anchor-offset) + 88px);
124
135
  }
125
136
 
126
137
  @layer components {
127
-
128
138
  .features-dark {
129
139
  @apply bg-gray-900;
130
140
  background-image: radial-gradient(#2a2a2a 20%, transparent 20%);
@@ -147,7 +157,43 @@ h1, h2, h3, h4, h5, h6 {
147
157
  display: none;
148
158
  }
149
159
 
160
+ .mdx-message {
161
+ @apply border-l-8;
162
+ }
163
+
150
164
  .mdx-message > p {
151
165
  @apply mt-0;
152
166
  }
167
+
168
+ .mdx-message-info {
169
+ @apply bg-blue-50 border-blue-300 dark:bg-blue-100 dark:border-blue-500;
170
+ }
171
+
172
+ .mdx-message-info > p {
173
+ @apply text-blue-900 dark:text-blue-900;
174
+ }
175
+
176
+ .mdx-message-success {
177
+ @apply bg-green-50 border-green-300 dark:bg-green-100 dark:border-green-500;
178
+ }
179
+
180
+ .mdx-message-success > p {
181
+ @apply text-green-900 dark:text-green-900;
182
+ }
183
+
184
+ .mdx-message-warning {
185
+ @apply bg-orange-50 border-orange-300 dark:bg-orange-100 dark:border-orange-500;
186
+ }
187
+
188
+ .mdx-message-warning > p {
189
+ @apply text-orange-900 dark:text-orange-900;
190
+ }
191
+
192
+ .mdx-message-error {
193
+ @apply bg-red-50 border-red-300 dark:bg-red-100 dark:border-red-500;
194
+ }
195
+
196
+ .mdx-message-error > p {
197
+ @apply text-red-900 dark:text-red-900;
198
+ }
153
199
  }
@@ -515,10 +515,110 @@ Ensure the default browser behavior of the `hidden` attribute.
515
515
  display: none;
516
516
  }
517
517
 
518
+ .mdx-message {
519
+ border-left-width: 8px;
520
+ }
521
+
518
522
  .mdx-message > p {
519
523
  margin-top: 0px;
520
524
  }
521
525
 
526
+ .mdx-message-info {
527
+ --tw-border-opacity: 1;
528
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
529
+ --tw-bg-opacity: 1;
530
+ background-color: rgb(239 246 255 / var(--tw-bg-opacity));
531
+ }
532
+
533
+ .dark .mdx-message-info {
534
+ --tw-border-opacity: 1;
535
+ border-color: rgb(59 130 246 / var(--tw-border-opacity));
536
+ --tw-bg-opacity: 1;
537
+ background-color: rgb(219 234 254 / var(--tw-bg-opacity));
538
+ }
539
+
540
+ .mdx-message-info > p {
541
+ --tw-text-opacity: 1;
542
+ color: rgb(30 58 138 / var(--tw-text-opacity));
543
+ }
544
+
545
+ .dark .mdx-message-info > p {
546
+ --tw-text-opacity: 1;
547
+ color: rgb(30 58 138 / var(--tw-text-opacity));
548
+ }
549
+
550
+ .mdx-message-success {
551
+ --tw-border-opacity: 1;
552
+ border-color: rgb(134 239 172 / var(--tw-border-opacity));
553
+ --tw-bg-opacity: 1;
554
+ background-color: rgb(240 253 244 / var(--tw-bg-opacity));
555
+ }
556
+
557
+ .dark .mdx-message-success {
558
+ --tw-border-opacity: 1;
559
+ border-color: rgb(34 197 94 / var(--tw-border-opacity));
560
+ --tw-bg-opacity: 1;
561
+ background-color: rgb(220 252 231 / var(--tw-bg-opacity));
562
+ }
563
+
564
+ .mdx-message-success > p {
565
+ --tw-text-opacity: 1;
566
+ color: rgb(20 83 45 / var(--tw-text-opacity));
567
+ }
568
+
569
+ .dark .mdx-message-success > p {
570
+ --tw-text-opacity: 1;
571
+ color: rgb(20 83 45 / var(--tw-text-opacity));
572
+ }
573
+
574
+ .mdx-message-warning {
575
+ --tw-border-opacity: 1;
576
+ border-color: rgb(253 186 116 / var(--tw-border-opacity));
577
+ --tw-bg-opacity: 1;
578
+ background-color: rgb(255 247 237 / var(--tw-bg-opacity));
579
+ }
580
+
581
+ .dark .mdx-message-warning {
582
+ --tw-border-opacity: 1;
583
+ border-color: rgb(249 115 22 / var(--tw-border-opacity));
584
+ --tw-bg-opacity: 1;
585
+ background-color: rgb(255 237 213 / var(--tw-bg-opacity));
586
+ }
587
+
588
+ .mdx-message-warning > p {
589
+ --tw-text-opacity: 1;
590
+ color: rgb(124 45 18 / var(--tw-text-opacity));
591
+ }
592
+
593
+ .dark .mdx-message-warning > p {
594
+ --tw-text-opacity: 1;
595
+ color: rgb(124 45 18 / var(--tw-text-opacity));
596
+ }
597
+
598
+ .mdx-message-error {
599
+ --tw-border-opacity: 1;
600
+ border-color: rgb(252 165 165 / var(--tw-border-opacity));
601
+ --tw-bg-opacity: 1;
602
+ background-color: rgb(254 242 242 / var(--tw-bg-opacity));
603
+ }
604
+
605
+ .dark .mdx-message-error {
606
+ --tw-border-opacity: 1;
607
+ border-color: rgb(239 68 68 / var(--tw-border-opacity));
608
+ --tw-bg-opacity: 1;
609
+ background-color: rgb(254 226 226 / var(--tw-bg-opacity));
610
+ }
611
+
612
+ .mdx-message-error > p {
613
+ --tw-text-opacity: 1;
614
+ color: rgb(127 29 29 / var(--tw-text-opacity));
615
+ }
616
+
617
+ .dark .mdx-message-error > p {
618
+ --tw-text-opacity: 1;
619
+ color: rgb(127 29 29 / var(--tw-text-opacity));
620
+ }
621
+
522
622
  .fixed {
523
623
  position: fixed;
524
624
  }
@@ -560,10 +660,6 @@ Ensure the default browser behavior of the `hidden` attribute.
560
660
  top: 3rem;
561
661
  }
562
662
 
563
- .top-16 {
564
- top: 4rem;
565
- }
566
-
567
663
  .right-2 {
568
664
  right: 0.5rem;
569
665
  }
@@ -905,6 +1001,10 @@ Ensure the default browser behavior of the `hidden` attribute.
905
1001
  overflow: hidden;
906
1002
  }
907
1003
 
1004
+ .overflow-y-auto {
1005
+ overflow-y: auto;
1006
+ }
1007
+
908
1008
  .overflow-x-hidden {
909
1009
  overflow-x: hidden;
910
1010
  }
@@ -985,16 +1085,6 @@ Ensure the default browser behavior of the `hidden` attribute.
985
1085
  background-color: rgb(239 246 255 / var(--tw-bg-opacity));
986
1086
  }
987
1087
 
988
- .bg-gray-300 {
989
- --tw-bg-opacity: 1;
990
- background-color: rgb(209 213 219 / var(--tw-bg-opacity));
991
- }
992
-
993
- .bg-blue-300 {
994
- --tw-bg-opacity: 1;
995
- background-color: rgb(147 197 253 / var(--tw-bg-opacity));
996
- }
997
-
998
1088
  .bg-gray-700 {
999
1089
  --tw-bg-opacity: 1;
1000
1090
  background-color: rgb(55 65 81 / var(--tw-bg-opacity));
@@ -1015,21 +1105,6 @@ Ensure the default browser behavior of the `hidden` attribute.
1015
1105
  background-color: rgb(37 99 235 / var(--tw-bg-opacity));
1016
1106
  }
1017
1107
 
1018
- .bg-green-50 {
1019
- --tw-bg-opacity: 1;
1020
- background-color: rgb(240 253 244 / var(--tw-bg-opacity));
1021
- }
1022
-
1023
- .bg-orange-50 {
1024
- --tw-bg-opacity: 1;
1025
- background-color: rgb(255 247 237 / var(--tw-bg-opacity));
1026
- }
1027
-
1028
- .bg-red-50 {
1029
- --tw-bg-opacity: 1;
1030
- background-color: rgb(254 242 242 / var(--tw-bg-opacity));
1031
- }
1032
-
1033
1108
  .object-cover {
1034
1109
  -o-object-fit: cover;
1035
1110
  object-fit: cover;
@@ -1205,26 +1280,6 @@ Ensure the default browser behavior of the `hidden` attribute.
1205
1280
  color: rgb(147 197 253 / var(--tw-text-opacity));
1206
1281
  }
1207
1282
 
1208
- .text-blue-900 {
1209
- --tw-text-opacity: 1;
1210
- color: rgb(30 58 138 / var(--tw-text-opacity));
1211
- }
1212
-
1213
- .text-green-900 {
1214
- --tw-text-opacity: 1;
1215
- color: rgb(20 83 45 / var(--tw-text-opacity));
1216
- }
1217
-
1218
- .text-orange-900 {
1219
- --tw-text-opacity: 1;
1220
- color: rgb(124 45 18 / var(--tw-text-opacity));
1221
- }
1222
-
1223
- .text-red-900 {
1224
- --tw-text-opacity: 1;
1225
- color: rgb(127 29 29 / var(--tw-text-opacity));
1226
- }
1227
-
1228
1283
  .opacity-0 {
1229
1284
  opacity: 0;
1230
1285
  }
@@ -1267,10 +1322,6 @@ Ensure the default browser behavior of the `hidden` attribute.
1267
1322
  outline-offset: 2px;
1268
1323
  }
1269
1324
 
1270
- .outline-0 {
1271
- outline-width: 0px;
1272
- }
1273
-
1274
1325
  .blur {
1275
1326
  --tw-blur: blur(8px);
1276
1327
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
@@ -1626,7 +1677,10 @@ article a:hover {
1626
1677
  }
1627
1678
 
1628
1679
  article a {
1629
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
1680
+ background-image: linear-gradient(
1681
+ transparent 60%,
1682
+ rgba(130, 199, 255, 0.28) 55%
1683
+ );
1630
1684
  }
1631
1685
 
1632
1686
  .link-with-underline {
@@ -1652,7 +1706,10 @@ article a {
1652
1706
  }
1653
1707
 
1654
1708
  .link-with-underline {
1655
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
1709
+ background-image: linear-gradient(
1710
+ transparent 60%,
1711
+ rgba(130, 199, 255, 0.28) 55%
1712
+ );
1656
1713
  }
1657
1714
 
1658
1715
  /*article pre {*/
@@ -1684,7 +1741,7 @@ article hr {
1684
1741
  }
1685
1742
 
1686
1743
  html {
1687
- scroll-behavior: smooth
1744
+ scroll-behavior: smooth;
1688
1745
  }
1689
1746
 
1690
1747
  :root {
@@ -1693,7 +1750,12 @@ html {
1693
1750
 
1694
1751
  /** Anchor with offset for headings */
1695
1752
 
1696
- h1, h2, h3, h4, h5, h6 {
1753
+ h1,
1754
+ h2,
1755
+ h3,
1756
+ h4,
1757
+ h5,
1758
+ h6 {
1697
1759
  scroll-margin-top: calc(var(--anchor-offset) + 88px);
1698
1760
  }
1699
1761
 
@@ -1987,9 +2049,9 @@ h1, h2, h3, h4, h5, h6 {
1987
2049
  width: 75%;
1988
2050
  }
1989
2051
 
1990
- .lg\:px-0 {
1991
- padding-left: 0px;
1992
- padding-right: 0px;
2052
+ .lg\:px-2 {
2053
+ padding-left: 0.5rem;
2054
+ padding-right: 0.5rem;
1993
2055
  }
1994
2056
 
1995
2057
  .lg\:py-12 {
@@ -1,3 +1,5 @@
1
+ // @ts-ignore
2
+ import { history } from 'umi';
1
3
  import { useThemeContext } from './context';
2
4
 
3
5
  interface useLanguageResult {
@@ -33,22 +35,25 @@ function useLanguage(): useLanguageResult {
33
35
 
34
36
  // 切换到默认语言
35
37
  if (locale === languages[0].locale && isFromPath) {
38
+ window.localStorage.removeItem('umi_locale');
36
39
  let p = location.pathname.split('/');
37
40
  p.shift();
38
41
  p.shift();
39
- window.location.pathname = p.join('/');
42
+ history.push('/' + p.join('/'));
40
43
  return;
41
44
  }
42
45
 
46
+ window.localStorage.setItem('umi_locale', locale);
47
+
43
48
  // 当前在默认语言,切换到其他语言
44
49
  if (!isFromPath) {
45
- window.location.pathname = locale + location.pathname;
50
+ history.push('/' + locale + location.pathname);
46
51
  return;
47
52
  }
48
53
 
49
54
  let p = location.pathname.split('/');
50
55
  p[1] = locale;
51
- window.location.pathname = p.join('/');
56
+ history.push('/' + p.join('/'));
52
57
  }
53
58
 
54
59
  function render(key: string) {
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Compositor, Inc. and Vercel, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.