@rainbow-oh/yee-c 0.9.2 → 0.10.0

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 (109) hide show
  1. package/dist/cjs/Input/style/index.less +1 -0
  2. package/dist/cjs/Tabs/demo/overflow-center.d.ts +3 -0
  3. package/dist/cjs/Tabs/demo/overflow-center.js +54 -0
  4. package/dist/cjs/Tabs/hooks/useNavListMove.d.ts +2 -1
  5. package/dist/cjs/Tabs/hooks/useNavListMove.js +51 -16
  6. package/dist/cjs/Tabs/hooks/useTabScroll.d.ts +1 -0
  7. package/dist/cjs/Tabs/hooks/useTabScroll.js +5 -1
  8. package/dist/cjs/Tabs/interface.d.ts +9 -0
  9. package/dist/cjs/Tabs/style/index.less +5 -0
  10. package/dist/cjs/Tabs/tab-header/index.d.ts +1 -0
  11. package/dist/cjs/Tabs/tab-header/index.js +9 -2
  12. package/dist/cjs/Tabs/tabs.js +4 -1
  13. package/dist/cjs/Upload/demo/auto-upload.d.ts +3 -0
  14. package/dist/cjs/Upload/demo/auto-upload.js +65 -0
  15. package/dist/cjs/Upload/demo/basic.js +5 -10
  16. package/dist/cjs/Upload/demo/controlled.js +4 -4
  17. package/dist/cjs/Upload/demo/pictureWall.js +14 -13
  18. package/dist/cjs/Upload/dragger.d.ts +2 -1
  19. package/dist/cjs/Upload/dragger.js +32 -21
  20. package/dist/cjs/Upload/index.d.ts +1 -1
  21. package/dist/cjs/Upload/interface.d.ts +67 -120
  22. package/dist/cjs/Upload/style/index.less +40 -13
  23. package/dist/cjs/Upload/upload.d.ts +2 -2
  24. package/dist/cjs/Upload/upload.js +435 -185
  25. package/dist/cjs/Upload/uploaded-list/index.d.ts +2 -1
  26. package/dist/cjs/Upload/uploaded-list/index.js +6 -3
  27. package/dist/cjs/Upload/uploaded-list/uploaded-item.d.ts +6 -3
  28. package/dist/cjs/Upload/uploaded-list/uploaded-item.js +127 -138
  29. package/dist/cjs/style/size.css +1 -1
  30. package/dist/cjs/style/themes.css +1 -1
  31. package/dist/cjs/style/variables.css +2 -2
  32. package/dist/cjs/utils/ax/core.d.ts +3 -1
  33. package/dist/cjs/utils/ax/core.js +24 -37
  34. package/dist/cjs/utils/ax/index.d.ts +3 -1
  35. package/dist/cjs/utils/folder-scanner.d.ts +1 -1
  36. package/dist/cjs/utils/folder-scanner.js +43 -34
  37. package/dist/cjs/version.d.ts +1 -1
  38. package/dist/cjs/version.js +1 -1
  39. package/dist/esm/Input/style/index.less +1 -0
  40. package/dist/esm/Tabs/demo/overflow-center.d.ts +3 -0
  41. package/dist/esm/Tabs/demo/overflow-center.js +61 -0
  42. package/dist/esm/Tabs/hooks/useNavListMove.d.ts +2 -1
  43. package/dist/esm/Tabs/hooks/useNavListMove.js +62 -25
  44. package/dist/esm/Tabs/hooks/useTabScroll.d.ts +1 -0
  45. package/dist/esm/Tabs/hooks/useTabScroll.js +9 -0
  46. package/dist/esm/Tabs/interface.d.ts +9 -0
  47. package/dist/esm/Tabs/style/index.less +5 -0
  48. package/dist/esm/Tabs/tab-header/index.d.ts +1 -0
  49. package/dist/esm/Tabs/tab-header/index.js +13 -2
  50. package/dist/esm/Tabs/tabs.js +4 -2
  51. package/dist/esm/Upload/demo/auto-upload.d.ts +3 -0
  52. package/dist/esm/Upload/demo/auto-upload.js +42 -0
  53. package/dist/esm/Upload/demo/basic.js +5 -11
  54. package/dist/esm/Upload/demo/controlled.js +8 -6
  55. package/dist/esm/Upload/demo/pictureWall.js +17 -14
  56. package/dist/esm/Upload/dragger.d.ts +2 -1
  57. package/dist/esm/Upload/dragger.js +10 -5
  58. package/dist/esm/Upload/index.d.ts +1 -1
  59. package/dist/esm/Upload/interface.d.ts +67 -120
  60. package/dist/esm/Upload/style/index.less +40 -13
  61. package/dist/esm/Upload/upload.d.ts +2 -2
  62. package/dist/esm/Upload/upload.js +573 -271
  63. package/dist/esm/Upload/uploaded-list/index.d.ts +2 -1
  64. package/dist/esm/Upload/uploaded-list/index.js +9 -4
  65. package/dist/esm/Upload/uploaded-list/uploaded-item.d.ts +6 -3
  66. package/dist/esm/Upload/uploaded-list/uploaded-item.js +145 -150
  67. package/dist/esm/style/size.css +1 -1
  68. package/dist/esm/style/themes.css +1 -1
  69. package/dist/esm/style/variables.css +2 -2
  70. package/dist/esm/utils/ax/core.d.ts +3 -1
  71. package/dist/esm/utils/ax/core.js +32 -40
  72. package/dist/esm/utils/ax/index.d.ts +3 -1
  73. package/dist/esm/utils/folder-scanner.d.ts +1 -1
  74. package/dist/esm/utils/folder-scanner.js +76 -75
  75. package/dist/esm/version.d.ts +1 -1
  76. package/dist/esm/version.js +1 -1
  77. package/dist/umd/yee-c.min.css +2 -2
  78. package/dist/umd/yee-c.min.js +1 -1
  79. package/package.json +1 -1
  80. package/src/Input/style/index.less +1 -0
  81. package/src/Tabs/demo/overflow-center.tsx +35 -0
  82. package/src/Tabs/hooks/useNavListMove.ts +60 -18
  83. package/src/Tabs/hooks/useTabScroll.ts +7 -1
  84. package/src/Tabs/index.en-US.md +33 -31
  85. package/src/Tabs/index.zh-CN.md +33 -31
  86. package/src/Tabs/interface.ts +9 -0
  87. package/src/Tabs/style/index.less +5 -0
  88. package/src/Tabs/tab-header/index.tsx +12 -2
  89. package/src/Tabs/tabs.tsx +2 -0
  90. package/src/Upload/demo/auto-upload.tsx +35 -0
  91. package/src/Upload/demo/basic.tsx +7 -11
  92. package/src/Upload/demo/controlled.tsx +12 -8
  93. package/src/Upload/demo/directory.tsx +3 -4
  94. package/src/Upload/demo/drag.tsx +5 -12
  95. package/src/Upload/demo/multiple.tsx +3 -4
  96. package/src/Upload/demo/pictureWall.tsx +22 -21
  97. package/src/Upload/dragger.tsx +47 -34
  98. package/src/Upload/index.en-US.md +63 -43
  99. package/src/Upload/index.ts +8 -1
  100. package/src/Upload/index.zh-CN.md +62 -42
  101. package/src/Upload/interface.ts +68 -120
  102. package/src/Upload/style/index.less +40 -13
  103. package/src/Upload/upload.tsx +546 -215
  104. package/src/Upload/uploaded-list/index.tsx +9 -5
  105. package/src/Upload/uploaded-list/uploaded-item.tsx +199 -228
  106. package/src/style/size.css +1 -1
  107. package/src/utils/ax/core.ts +28 -41
  108. package/src/utils/folder-scanner.ts +51 -37
  109. package/src/version.ts +1 -1
@@ -25,9 +25,6 @@ function buildUrl(config: Record<string, any>) {
25
25
  }
26
26
 
27
27
  class Ax {
28
- // eslint-disable-next-line @typescript-eslint/no-empty-function
29
- // constructor() {}
30
-
31
28
  request(configOrUrl: AxConfig | string) {
32
29
  let config = getDefaultConfig() as any;
33
30
  if (typeof configOrUrl === 'string') {
@@ -50,8 +47,9 @@ class Ax {
50
47
  });
51
48
  }
52
49
 
53
- return new Promise((resolve, reject) => {
54
- let xhr = new XMLHttpRequest() as any;
50
+ let xhr: any;
51
+ const request = new Promise((resolve, reject) => {
52
+ xhr = new XMLHttpRequest();
55
53
  const {
56
54
  headers,
57
55
  timeout,
@@ -63,11 +61,10 @@ class Ax {
63
61
  onUploadProgress,
64
62
  onTimeout,
65
63
  onLoaded,
66
- formDataWithBoundary = true, // Set boundary for form-data upload type
64
+ formDataWithBoundary = true,
67
65
  } = config;
68
66
 
69
67
  if ((!data || getType(data) === 'FormData') && headers) {
70
- // Delete to let browser auto-generate
71
68
  if (formDataWithBoundary) {
72
69
  delete headers['Content-Type'];
73
70
  }
@@ -82,73 +79,63 @@ class Ax {
82
79
  }
83
80
 
84
81
  xhr.upload.onprogress = function (event: any) {
85
- if (onUploadProgress) {
86
- onUploadProgress(event, xhr);
87
- }
82
+ onUploadProgress?.(event, xhr);
88
83
  };
89
84
 
90
85
  xhr.onreadystatechange = function () {
91
- if (xhr.readyState === XMLHttpRequest.DONE) {
86
+ if (xhr?.readyState === XMLHttpRequest.DONE) {
92
87
  if (xhr.status >= 200 && xhr.status <= 299) {
93
88
  const type = this.getResponseHeader('content-type') || '';
94
89
  const isJsonType = type.indexOf('application/json') > -1;
95
90
 
96
- let data;
97
-
91
+ let responseData;
98
92
  if (isJsonType) {
99
93
  try {
100
- data = JSON.parse(xhr.response);
101
- } catch (err) {
102
- data = xhr.response;
94
+ responseData = JSON.parse(xhr.response);
95
+ } catch (error) {
96
+ responseData = xhr.response;
103
97
  }
104
98
  } else {
105
- data = xhr.response;
99
+ responseData = xhr.response;
106
100
  }
107
101
 
108
- if (onSuccess) {
109
- onSuccess(data, xhr);
110
- }
111
- resolve(data);
102
+ onSuccess?.(responseData, xhr);
103
+ resolve(responseData);
112
104
  } else {
113
- if (onError) {
114
- onError(xhr.response, xhr);
115
- }
105
+ onError?.(xhr.response, xhr);
116
106
  reject({ status: 'error', error: xhr.response });
117
107
  }
118
108
  }
119
109
  };
120
110
 
121
111
  xhr.onprogress = function (event: any) {
122
- if (onProgress) {
123
- onProgress(event, xhr);
124
- }
112
+ onProgress?.(event, xhr);
125
113
  };
126
114
 
127
115
  xhr.onloadend = function (event: any) {
128
- if (onLoaded) {
129
- onLoaded(event, xhr);
130
- }
116
+ onLoaded?.(event, xhr);
131
117
  xhr = null;
132
118
  };
133
119
 
134
- xhr.onerror = function (err: any) {
135
- if (onError) {
136
- onError(xhr.response, xhr);
137
- }
138
- reject({ status: 'error', error: err });
139
- xhr = null;
120
+ xhr.onerror = function (error: any) {
121
+ onError?.(xhr.response, xhr);
122
+ reject({ status: 'error', error });
123
+ };
124
+
125
+ xhr.onabort = function (event: any) {
126
+ reject({ status: 'abort', error: event });
140
127
  };
141
128
 
142
129
  xhr.ontimeout = function (event: any) {
143
- if (onTimeout) {
144
- onTimeout(event, xhr);
145
- }
130
+ onTimeout?.(event, xhr);
146
131
  reject({ status: 'timeout', error: event });
147
- xhr = null;
148
132
  };
149
133
 
150
134
  xhr.send(data || null);
151
- });
135
+ }) as Promise<any> & { abort: () => void };
136
+
137
+ request.abort = () => xhr?.abort();
138
+ return request;
152
139
  }
153
140
  }
154
141
 
@@ -1,40 +1,54 @@
1
- export default async function folderScanner(
2
- entry: FileSystemFileEntry | FileSystemDirectoryEntry,
3
- filesList: any[],
4
- ) {
1
+ const readAllEntries = (
2
+ reader: FileSystemDirectoryReader,
3
+ ): Promise<FileSystemEntry[]> => {
4
+ return new Promise((resolve, reject) => {
5
+ const entries: FileSystemEntry[] = [];
6
+
7
+ const readNextBatch = () => {
8
+ reader.readEntries((batch) => {
9
+ if (batch.length === 0) {
10
+ resolve(entries);
11
+ return;
12
+ }
13
+ entries.push(...batch);
14
+ readNextBatch();
15
+ }, reject);
16
+ };
17
+
18
+ readNextBatch();
19
+ });
20
+ };
21
+
22
+ const readFile = (entry: FileSystemFileEntry): Promise<File> => {
5
23
  return new Promise((resolve, reject) => {
6
- if (entry.isDirectory) {
7
- const directoryReader = (
8
- entry as FileSystemDirectoryEntry
9
- ).createReader();
10
- directoryReader.readEntries(
11
- async (entries: any[]) => {
12
- entries.forEach(async (entry: any, index: number) => {
13
- await folderScanner(entry, filesList);
14
- if (index === entries.length - 1) {
15
- resolve(filesList);
16
- }
17
- });
18
- },
19
- (e: any) => {
20
- reject(e);
21
- },
22
- );
23
- } else if (entry.isFile) {
24
- (entry as FileSystemFileEntry).file(
25
- async (file: any) => {
26
- const path = entry.fullPath.substring(1);
27
- /** Modifying webkitRelativePath is the core operation, because in drag events webkitRelativePath is empty, and webkitRelativePath is read-only so normal assignment won't work. Currently the only way is to use this method to assign entry.fullPath to webkitRelativePath **/
28
- const newFile = Object.defineProperty(file, 'webkitRelativePath', {
29
- value: path,
30
- });
31
- filesList.push(newFile);
32
- resolve(filesList);
33
- },
34
- (e: any) => {
35
- reject(e);
36
- },
37
- );
38
- }
24
+ entry.file((file) => {
25
+ const path = entry.fullPath.replace(/^\//, '');
26
+ Object.defineProperty(file, 'webkitRelativePath', {
27
+ configurable: true,
28
+ value: path,
29
+ });
30
+ resolve(file);
31
+ }, reject);
39
32
  });
33
+ };
34
+
35
+ export default async function folderScanner(
36
+ entry: FileSystemEntry,
37
+ filesList: File[] = [],
38
+ ): Promise<File[]> {
39
+ if (entry.isFile) {
40
+ filesList.push(await readFile(entry as FileSystemFileEntry));
41
+ return filesList;
42
+ }
43
+
44
+ if (entry.isDirectory) {
45
+ const reader = (entry as FileSystemDirectoryEntry).createReader();
46
+ const entries = await readAllEntries(reader);
47
+ const nestedFiles = await Promise.all(
48
+ entries.map((nestedEntry) => folderScanner(nestedEntry, [])),
49
+ );
50
+ filesList.push(...nestedFiles.flat());
51
+ }
52
+
53
+ return filesList;
40
54
  }
package/src/version.ts CHANGED
@@ -4,7 +4,7 @@ declare global {
4
4
  }
5
5
  }
6
6
 
7
- export const version = "0.9.2";
7
+ export const version = "0.10.0";
8
8
 
9
9
  if (typeof window !== 'undefined') {
10
10
  window.__yee_c_version__ = version;