iglooform 2.5.58 → 2.5.60

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 (73) hide show
  1. package/es/alert-message/style/index.less +2 -2
  2. package/es/input/input-date.js +6 -0
  3. package/es/input/style/index.less +1 -1
  4. package/es/login-page/style/index.less +10 -10
  5. package/es/upload-photo/style/index.less +17 -17
  6. package/es/upload-preview/style/index.less +1 -1
  7. package/es/utils/form-utils.js +1 -0
  8. package/lib/alert-message/style/index.less +2 -2
  9. package/lib/input/input-date.js +6 -0
  10. package/lib/input/style/index.less +1 -1
  11. package/lib/login-page/style/index.less +10 -10
  12. package/lib/upload-photo/style/index.less +17 -17
  13. package/lib/upload-preview/style/index.less +1 -1
  14. package/lib/utils/form-utils.js +1 -0
  15. package/package.json +1 -1
  16. package/.dumi/tmp/core/EmptyRoute.tsx +0 -9
  17. package/.dumi/tmp/core/defineApp.ts +0 -16
  18. package/.dumi/tmp/core/exportStaticRuntimePlugin.ts +0 -11
  19. package/.dumi/tmp/core/helmet.ts +0 -10
  20. package/.dumi/tmp/core/helmetContext.ts +0 -4
  21. package/.dumi/tmp/core/history.ts +0 -66
  22. package/.dumi/tmp/core/historyIntelli.ts +0 -132
  23. package/.dumi/tmp/core/plugin.ts +0 -55
  24. package/.dumi/tmp/core/pluginConfig.ts +0 -281
  25. package/.dumi/tmp/core/pluginConfigJoi.d.ts +0 -55
  26. package/.dumi/tmp/core/polyfill.ts +0 -201
  27. package/.dumi/tmp/core/route.tsx +0 -50
  28. package/.dumi/tmp/core/terminal.ts +0 -37
  29. package/.dumi/tmp/dumi/exports.ts +0 -5
  30. package/.dumi/tmp/dumi/locales/config.ts +0 -95
  31. package/.dumi/tmp/dumi/locales/runtime.tsx +0 -43
  32. package/.dumi/tmp/dumi/meta/atoms.ts +0 -4
  33. package/.dumi/tmp/dumi/meta/index.ts +0 -255
  34. package/.dumi/tmp/dumi/meta/runtime.ts +0 -31
  35. package/.dumi/tmp/dumi/meta/tabs.ts +0 -5
  36. package/.dumi/tmp/dumi/theme/ContextWrapper.tsx +0 -48
  37. package/.dumi/tmp/dumi/theme/builtins/API.ts +0 -4
  38. package/.dumi/tmp/dumi/theme/builtins/Badge.ts +0 -4
  39. package/.dumi/tmp/dumi/theme/builtins/Container.ts +0 -4
  40. package/.dumi/tmp/dumi/theme/builtins/Previewer.ts +0 -4
  41. package/.dumi/tmp/dumi/theme/builtins/SourceCode.ts +0 -4
  42. package/.dumi/tmp/dumi/theme/builtins/Table.ts +0 -4
  43. package/.dumi/tmp/dumi/theme/builtins/Tree.ts +0 -4
  44. package/.dumi/tmp/dumi/theme/layouts/DocLayout.ts +0 -4
  45. package/.dumi/tmp/dumi/theme/loading.tsx +0 -25
  46. package/.dumi/tmp/dumi/theme/nprogress.css +0 -59
  47. package/.dumi/tmp/dumi/theme/slots/ColorSwitch.ts +0 -4
  48. package/.dumi/tmp/dumi/theme/slots/Content.ts +0 -4
  49. package/.dumi/tmp/dumi/theme/slots/ContentFooter.ts +0 -4
  50. package/.dumi/tmp/dumi/theme/slots/ContentTabs.ts +0 -4
  51. package/.dumi/tmp/dumi/theme/slots/Features.ts +0 -4
  52. package/.dumi/tmp/dumi/theme/slots/Footer.ts +0 -4
  53. package/.dumi/tmp/dumi/theme/slots/Header.ts +0 -4
  54. package/.dumi/tmp/dumi/theme/slots/HeaderExtra.ts +0 -4
  55. package/.dumi/tmp/dumi/theme/slots/Hero.ts +0 -4
  56. package/.dumi/tmp/dumi/theme/slots/HeroTitle.ts +0 -4
  57. package/.dumi/tmp/dumi/theme/slots/LangSwitch.ts +0 -4
  58. package/.dumi/tmp/dumi/theme/slots/Logo.ts +0 -4
  59. package/.dumi/tmp/dumi/theme/slots/Navbar.ts +0 -4
  60. package/.dumi/tmp/dumi/theme/slots/NavbarExtra.ts +0 -4
  61. package/.dumi/tmp/dumi/theme/slots/NotFound.ts +0 -4
  62. package/.dumi/tmp/dumi/theme/slots/PreviewerActions.ts +0 -4
  63. package/.dumi/tmp/dumi/theme/slots/PreviewerActionsExtra.ts +0 -4
  64. package/.dumi/tmp/dumi/theme/slots/RtlSwitch.ts +0 -4
  65. package/.dumi/tmp/dumi/theme/slots/SearchBar.ts +0 -5
  66. package/.dumi/tmp/dumi/theme/slots/SearchResult.ts +0 -4
  67. package/.dumi/tmp/dumi/theme/slots/Sidebar.ts +0 -4
  68. package/.dumi/tmp/dumi/theme/slots/SocialIcon.ts +0 -4
  69. package/.dumi/tmp/dumi/theme/slots/Toc.ts +0 -4
  70. package/.dumi/tmp/exports.ts +0 -17
  71. package/.dumi/tmp/plugin-html2sketch/index.ts +0 -35
  72. package/.dumi/tmp/testBrowser.tsx +0 -88
  73. package/.dumi/tmp/umi.ts +0 -106
@@ -5,7 +5,7 @@
5
5
  padding: 12px 16px;
6
6
  border-width: 0px;
7
7
 
8
- &-message {
8
+ & &-message {
9
9
  font-size: 14px;
10
10
  color: #212121;
11
11
  margin-left: 8px;
@@ -18,7 +18,7 @@
18
18
  }
19
19
  }
20
20
 
21
- &-icon {
21
+ & &-icon {
22
22
  font-size: 24px;
23
23
  position: absolute;
24
24
  top: 10px;
@@ -279,6 +279,12 @@ function checkTime(value, format) {
279
279
  return Promise.resolve();
280
280
  }
281
281
 
282
+ if (value === 'error type') {
283
+ return Promise.reject(staticFormatMessage({
284
+ id: 'Please enter a valid date.'
285
+ }));
286
+ }
287
+
282
288
  return moment(value, format, true).isValid() ? Promise.resolve() : Promise.reject(staticFormatMessage({
283
289
  id: 'Please enter a valid date.'
284
290
  }));
@@ -363,7 +363,7 @@ input[type='number'] {
363
363
  font-size: 12px;
364
364
  line-height: 16px;
365
365
 
366
- &-inner {
366
+ .igloo-otp-count-down-inner {
367
367
  color: #666666;
368
368
  font-weight: bold;
369
369
  font-size: 12px;
@@ -8,7 +8,7 @@
8
8
  background-position-x: 100%;
9
9
  background-size: contain;
10
10
 
11
- &-logo {
11
+ .igloo-login-page-logo {
12
12
  position: absolute;
13
13
  width: 108px;
14
14
  height: 60px;
@@ -18,27 +18,27 @@
18
18
  background-size: contain;
19
19
  }
20
20
 
21
- &-child-box {
21
+ .igloo-login-page-child-box {
22
22
  position: absolute;
23
23
  top: 200px;
24
24
  left: 166px;
25
25
  }
26
26
 
27
- &-text-box {
27
+ .igloo-login-page-text-box {
28
28
  position: absolute;
29
29
  right: 103px;
30
30
  bottom: 128px;
31
31
 
32
- &-text {
32
+ .igloo-login-page-text-box-text {
33
33
  font-family: Semplicita Pro;
34
34
  font-weight: bold;
35
35
  color: #fff;
36
36
  }
37
37
 
38
- &-buttons {
38
+ .igloo-login-page-text-box-buttons {
39
39
  margin-top: 40px;
40
40
 
41
- &-button {
41
+ .igloo-login-page-text-box-buttons-button {
42
42
  display: inline-block;
43
43
  cursor: pointer;
44
44
  width: 140px;
@@ -47,11 +47,11 @@
47
47
  background-repeat: no-repeat;
48
48
  }
49
49
 
50
- &-apple {
50
+ .igloo-login-page-text-box-buttons-apple {
51
51
  background-image: url(./apple.svg);
52
52
  }
53
53
 
54
- &-google {
54
+ .igloo-login-page-text-box-buttons-google {
55
55
  background-image: url(./google.svg);
56
56
  margin-left: 16px;
57
57
  }
@@ -64,14 +64,14 @@
64
64
  width: 100vw;
65
65
  height: 100vh;
66
66
 
67
- &-logo {
67
+ .igloo-login-page-mobile-logo {
68
68
  width: 108px;
69
69
  height: 60px;
70
70
  background: url(./logo.svg) no-repeat;
71
71
  background-size: contain;
72
72
  }
73
73
 
74
- &-child-box {
74
+ .igloo-login-page-mobile-child-box {
75
75
  margin-top: 40px;
76
76
  }
77
77
  }
@@ -1,5 +1,5 @@
1
1
  .igloo-upload-photo {
2
- &-sample {
2
+ .igloo-upload-photo-sample {
3
3
  display: flex;
4
4
  align-items: center;
5
5
  justify-content: space-between;
@@ -8,7 +8,7 @@
8
8
  margin-bottom: 16px;
9
9
  border-radius: 3px;
10
10
 
11
- &-photos {
11
+ .igloo-upload-photo-sample-photos {
12
12
  &-photo {
13
13
  width: 100%;
14
14
  }
@@ -39,7 +39,7 @@
39
39
  }
40
40
  }
41
41
 
42
- &-descriptions {
42
+ .igloo-upload-photo-sample-descriptions {
43
43
  color: #666666;
44
44
  word-break: break-word;
45
45
  white-space: pre-wrap;
@@ -47,20 +47,20 @@
47
47
  font-size: 14px;
48
48
  }
49
49
 
50
- &-descriptions-center {
50
+ .igloo-upload-photo-sample-descriptions-center {
51
51
  display: flex;
52
52
  align-items: center;
53
53
  }
54
54
  }
55
55
 
56
- &-content {
56
+ .igloo-upload-photo-content {
57
57
  margin-bottom: 0 !important;
58
58
 
59
59
  .ant-space-item {
60
60
  height: 98px;
61
61
  }
62
62
 
63
- &-container {
63
+ .igloo-upload-photo-content-container {
64
64
  position: relative;
65
65
  border: 1px solid #eeeeee;
66
66
  border-radius: 3px;
@@ -73,7 +73,7 @@
73
73
  }
74
74
  }
75
75
 
76
- &-mask {
76
+ .igloo-upload-photo-content-mask {
77
77
  display: flex;
78
78
  position: absolute;
79
79
  top: 0;
@@ -89,7 +89,7 @@
89
89
  z-index: 1;
90
90
  }
91
91
 
92
- &-preview {
92
+ .igloo-upload-photo-content-preview {
93
93
  display: flex;
94
94
  align-items: center;
95
95
  justify-content: center;
@@ -100,11 +100,11 @@
100
100
  overflow: hidden;
101
101
  }
102
102
 
103
- &-error {
103
+ .igloo-upload-photo-content-error {
104
104
  border: 1px solid #de3618;
105
105
  }
106
106
 
107
- &-button {
107
+ .igloo-upload-photo-content-button {
108
108
  display: flex;
109
109
  width: 98px;
110
110
  height: 98px;
@@ -119,15 +119,15 @@
119
119
  }
120
120
 
121
121
  @media screen and (max-width: 768px) {
122
- &-sample {
122
+ .igloo-upload-photo-sample {
123
123
  display: block;
124
124
  padding: 16px;
125
125
 
126
- &-photos {
126
+ .igloo-upload-photo-sample-photos {
127
127
  width: 100%;
128
128
  }
129
129
 
130
- &-descriptions {
130
+ .igloo-upload-photo-sample-descriptions {
131
131
  width: 100%;
132
132
  color: #666666;
133
133
  word-break: break-word;
@@ -135,22 +135,22 @@
135
135
  }
136
136
  }
137
137
 
138
- &-content {
138
+ .igloo-upload-photo-content {
139
139
  .ant-space-item {
140
140
  height: 86px;
141
141
  }
142
142
 
143
- &-preview {
143
+ .igloo-upload-photo-content-preview {
144
144
  width: 86px;
145
145
  height: 86px;
146
146
  }
147
147
 
148
- &-container {
148
+ .igloo-upload-photo-content-container {
149
149
  width: 86px;
150
150
  height: 86px;
151
151
  }
152
152
 
153
- &-button {
153
+ .igloo-upload-photo-content-button {
154
154
  display: flex;
155
155
  width: 86px;
156
156
  height: 86px;
@@ -13,7 +13,7 @@
13
13
  .igloo-upload-preview-modal {
14
14
  position: relative;
15
15
 
16
- &-button {
16
+ & &-button {
17
17
  position: absolute;
18
18
  width: 24px;
19
19
  height: 44px;
@@ -329,6 +329,7 @@ export var calcFormItemProps = function calcFormItemProps(config, extraProps, fo
329
329
  if (type === 'InputDate') {
330
330
  rules.push({
331
331
  validator: function validator(_, date) {
332
+ if (!date) return Promise.resolve();
332
333
  var trimedDate = date.replaceAll(/\s/g, '');
333
334
  var format = elementProps.format ? elementProps.format.replaceAll(/\s/g, '') : 'DD/MM/YYYY';
334
335
 
@@ -5,7 +5,7 @@
5
5
  padding: 12px 16px;
6
6
  border-width: 0px;
7
7
 
8
- &-message {
8
+ & &-message {
9
9
  font-size: 14px;
10
10
  color: #212121;
11
11
  margin-left: 8px;
@@ -18,7 +18,7 @@
18
18
  }
19
19
  }
20
20
 
21
- &-icon {
21
+ & &-icon {
22
22
  font-size: 24px;
23
23
  position: absolute;
24
24
  top: 10px;
@@ -296,6 +296,12 @@ function checkTime(value, format) {
296
296
  return Promise.resolve();
297
297
  }
298
298
 
299
+ if (value === 'error type') {
300
+ return Promise.reject((0, _locale.staticFormatMessage)({
301
+ id: 'Please enter a valid date.'
302
+ }));
303
+ }
304
+
299
305
  return (0, _moment.default)(value, format, true).isValid() ? Promise.resolve() : Promise.reject((0, _locale.staticFormatMessage)({
300
306
  id: 'Please enter a valid date.'
301
307
  }));
@@ -363,7 +363,7 @@ input[type='number'] {
363
363
  font-size: 12px;
364
364
  line-height: 16px;
365
365
 
366
- &-inner {
366
+ .igloo-otp-count-down-inner {
367
367
  color: #666666;
368
368
  font-weight: bold;
369
369
  font-size: 12px;
@@ -8,7 +8,7 @@
8
8
  background-position-x: 100%;
9
9
  background-size: contain;
10
10
 
11
- &-logo {
11
+ .igloo-login-page-logo {
12
12
  position: absolute;
13
13
  width: 108px;
14
14
  height: 60px;
@@ -18,27 +18,27 @@
18
18
  background-size: contain;
19
19
  }
20
20
 
21
- &-child-box {
21
+ .igloo-login-page-child-box {
22
22
  position: absolute;
23
23
  top: 200px;
24
24
  left: 166px;
25
25
  }
26
26
 
27
- &-text-box {
27
+ .igloo-login-page-text-box {
28
28
  position: absolute;
29
29
  right: 103px;
30
30
  bottom: 128px;
31
31
 
32
- &-text {
32
+ .igloo-login-page-text-box-text {
33
33
  font-family: Semplicita Pro;
34
34
  font-weight: bold;
35
35
  color: #fff;
36
36
  }
37
37
 
38
- &-buttons {
38
+ .igloo-login-page-text-box-buttons {
39
39
  margin-top: 40px;
40
40
 
41
- &-button {
41
+ .igloo-login-page-text-box-buttons-button {
42
42
  display: inline-block;
43
43
  cursor: pointer;
44
44
  width: 140px;
@@ -47,11 +47,11 @@
47
47
  background-repeat: no-repeat;
48
48
  }
49
49
 
50
- &-apple {
50
+ .igloo-login-page-text-box-buttons-apple {
51
51
  background-image: url(./apple.svg);
52
52
  }
53
53
 
54
- &-google {
54
+ .igloo-login-page-text-box-buttons-google {
55
55
  background-image: url(./google.svg);
56
56
  margin-left: 16px;
57
57
  }
@@ -64,14 +64,14 @@
64
64
  width: 100vw;
65
65
  height: 100vh;
66
66
 
67
- &-logo {
67
+ .igloo-login-page-mobile-logo {
68
68
  width: 108px;
69
69
  height: 60px;
70
70
  background: url(./logo.svg) no-repeat;
71
71
  background-size: contain;
72
72
  }
73
73
 
74
- &-child-box {
74
+ .igloo-login-page-mobile-child-box {
75
75
  margin-top: 40px;
76
76
  }
77
77
  }
@@ -1,5 +1,5 @@
1
1
  .igloo-upload-photo {
2
- &-sample {
2
+ .igloo-upload-photo-sample {
3
3
  display: flex;
4
4
  align-items: center;
5
5
  justify-content: space-between;
@@ -8,7 +8,7 @@
8
8
  margin-bottom: 16px;
9
9
  border-radius: 3px;
10
10
 
11
- &-photos {
11
+ .igloo-upload-photo-sample-photos {
12
12
  &-photo {
13
13
  width: 100%;
14
14
  }
@@ -39,7 +39,7 @@
39
39
  }
40
40
  }
41
41
 
42
- &-descriptions {
42
+ .igloo-upload-photo-sample-descriptions {
43
43
  color: #666666;
44
44
  word-break: break-word;
45
45
  white-space: pre-wrap;
@@ -47,20 +47,20 @@
47
47
  font-size: 14px;
48
48
  }
49
49
 
50
- &-descriptions-center {
50
+ .igloo-upload-photo-sample-descriptions-center {
51
51
  display: flex;
52
52
  align-items: center;
53
53
  }
54
54
  }
55
55
 
56
- &-content {
56
+ .igloo-upload-photo-content {
57
57
  margin-bottom: 0 !important;
58
58
 
59
59
  .ant-space-item {
60
60
  height: 98px;
61
61
  }
62
62
 
63
- &-container {
63
+ .igloo-upload-photo-content-container {
64
64
  position: relative;
65
65
  border: 1px solid #eeeeee;
66
66
  border-radius: 3px;
@@ -73,7 +73,7 @@
73
73
  }
74
74
  }
75
75
 
76
- &-mask {
76
+ .igloo-upload-photo-content-mask {
77
77
  display: flex;
78
78
  position: absolute;
79
79
  top: 0;
@@ -89,7 +89,7 @@
89
89
  z-index: 1;
90
90
  }
91
91
 
92
- &-preview {
92
+ .igloo-upload-photo-content-preview {
93
93
  display: flex;
94
94
  align-items: center;
95
95
  justify-content: center;
@@ -100,11 +100,11 @@
100
100
  overflow: hidden;
101
101
  }
102
102
 
103
- &-error {
103
+ .igloo-upload-photo-content-error {
104
104
  border: 1px solid #de3618;
105
105
  }
106
106
 
107
- &-button {
107
+ .igloo-upload-photo-content-button {
108
108
  display: flex;
109
109
  width: 98px;
110
110
  height: 98px;
@@ -119,15 +119,15 @@
119
119
  }
120
120
 
121
121
  @media screen and (max-width: 768px) {
122
- &-sample {
122
+ .igloo-upload-photo-sample {
123
123
  display: block;
124
124
  padding: 16px;
125
125
 
126
- &-photos {
126
+ .igloo-upload-photo-sample-photos {
127
127
  width: 100%;
128
128
  }
129
129
 
130
- &-descriptions {
130
+ .igloo-upload-photo-sample-descriptions {
131
131
  width: 100%;
132
132
  color: #666666;
133
133
  word-break: break-word;
@@ -135,22 +135,22 @@
135
135
  }
136
136
  }
137
137
 
138
- &-content {
138
+ .igloo-upload-photo-content {
139
139
  .ant-space-item {
140
140
  height: 86px;
141
141
  }
142
142
 
143
- &-preview {
143
+ .igloo-upload-photo-content-preview {
144
144
  width: 86px;
145
145
  height: 86px;
146
146
  }
147
147
 
148
- &-container {
148
+ .igloo-upload-photo-content-container {
149
149
  width: 86px;
150
150
  height: 86px;
151
151
  }
152
152
 
153
- &-button {
153
+ .igloo-upload-photo-content-button {
154
154
  display: flex;
155
155
  width: 86px;
156
156
  height: 86px;
@@ -13,7 +13,7 @@
13
13
  .igloo-upload-preview-modal {
14
14
  position: relative;
15
15
 
16
- &-button {
16
+ & &-button {
17
17
  position: absolute;
18
18
  width: 24px;
19
19
  height: 44px;
@@ -348,6 +348,7 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
348
348
  if (type === 'InputDate') {
349
349
  rules.push({
350
350
  validator: function validator(_, date) {
351
+ if (!date) return Promise.resolve();
351
352
  var trimedDate = date.replaceAll(/\s/g, '');
352
353
  var format = elementProps.format ? elementProps.format.replaceAll(/\s/g, '') : 'DD/MM/YYYY';
353
354
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "2.5.58",
3
+ "version": "2.5.60",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",
@@ -1,9 +0,0 @@
1
- // @ts-nocheck
2
- // This file is generated by Umi automatically
3
- // DO NOT CHANGE IT MANUALLY!
4
- import React from 'react';
5
- import { Outlet, useOutletContext } from 'umi';
6
- export default function EmptyRoute() {
7
- const context = useOutletContext();
8
- return <Outlet context={context} />;
9
- }
@@ -1,16 +0,0 @@
1
- // @ts-nocheck
2
- // This file is generated by Umi automatically
3
- // DO NOT CHANGE IT MANUALLY!
4
- interface IDefaultRuntimeConfig {
5
- onRouteChange?: (props: { routes: any, clientRoutes: any, location: any, action: any, isFirst: boolean }) => void;
6
- patchRoutes?: (props: { routes: any }) => void;
7
- patchClientRoutes?: (props: { routes: any }) => void;
8
- render?: (oldRender: () => void) => void;
9
- rootContainer?: (lastRootContainer: JSX.Element, args?: any) => void;
10
- [key: string]: any;
11
- }
12
- export type RuntimeConfig = IDefaultRuntimeConfig
13
-
14
- export function defineApp(config: RuntimeConfig): RuntimeConfig {
15
- return config;
16
- }
@@ -1,11 +0,0 @@
1
- // @ts-nocheck
2
- // This file is generated by Umi automatically
3
- // DO NOT CHANGE IT MANUALLY!
4
- export function modifyClientRenderOpts(memo: any) {
5
- const { history, hydrate } = memo;
6
-
7
- return {
8
- ...memo,
9
- hydrate: hydrate && ![].includes(history.location.pathname),
10
- };
11
- }
@@ -1,10 +0,0 @@
1
- // @ts-nocheck
2
- // This file is generated by Umi automatically
3
- // DO NOT CHANGE IT MANUALLY!
4
- import React from 'react';
5
- import { HelmetProvider } from '/Users/lei/iglooform/node_modules/@umijs/renderer-react';
6
- import { context } from './helmetContext';
7
-
8
- export const innerProvider = (container) => {
9
- return React.createElement(HelmetProvider, { context }, container);
10
- }
@@ -1,4 +0,0 @@
1
- // @ts-nocheck
2
- // This file is generated by Umi automatically
3
- // DO NOT CHANGE IT MANUALLY!
4
- export const context = {};
@@ -1,66 +0,0 @@
1
- // @ts-nocheck
2
- // This file is generated by Umi automatically
3
- // DO NOT CHANGE IT MANUALLY!
4
- import { createHashHistory, createMemoryHistory, createBrowserHistory } from '/Users/lei/iglooform/node_modules/@umijs/renderer-react';
5
- import type { UmiHistory } from './historyIntelli';
6
-
7
- let history: UmiHistory;
8
- let basename: string = '/';
9
- export function createHistory(opts: any) {
10
- let h;
11
- if (opts.type === 'hash') {
12
- h = createHashHistory();
13
- } else if (opts.type === 'memory') {
14
- h = createMemoryHistory(opts);
15
- } else {
16
- h = createBrowserHistory();
17
- }
18
- if (opts.basename) {
19
- basename = opts.basename;
20
- }
21
-
22
-
23
- history = {
24
- ...h,
25
- push(to, state) {
26
- h.push(patchTo(to, h), state);
27
- },
28
- replace(to, state) {
29
- h.replace(patchTo(to, h), state);
30
- },
31
- get location() {
32
- return h.location;
33
- },
34
- get action() {
35
- return h.action;
36
- }
37
- }
38
-
39
- return h;
40
- }
41
-
42
- // Patch `to` to support basename
43
- // Refs:
44
- // https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L484
45
- // https://github.com/remix-run/history/blob/dev/docs/api-reference.md#to
46
- function patchTo(to: any, h: History) {
47
- if (typeof to === 'string') {
48
- return `${stripLastSlash(basename)}${to}`;
49
- } else if (typeof to === 'object') {
50
-
51
- const currentPathname = h.location.pathname;
52
-
53
- return {
54
- ...to,
55
- pathname: to.pathname? `${stripLastSlash(basename)}${to.pathname}` : currentPathname,
56
- };
57
- } else {
58
- throw new Error(`Unexpected to: ${to}`);
59
- }
60
- }
61
-
62
- function stripLastSlash(path) {
63
- return path.slice(-1) === '/' ? path.slice(0, -1) : path;
64
- }
65
-
66
- export { history };