@spacecorexdev/core 0.0.4 → 0.0.5

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 (132) hide show
  1. package/package.json +2 -36
  2. package/src/api/_base.ts +243 -0
  3. package/src/api/index.ts +17 -0
  4. package/src/api/project.ts +1345 -0
  5. package/src/api/user.ts +1174 -0
  6. package/src/contract.ts +50 -0
  7. package/src/hooks/index.ts +2 -0
  8. package/{dist/hooks/index.js → src/hooks/useLongPress.ts} +53 -49
  9. package/src/hooks/useOnlineStatus.ts +22 -0
  10. package/src/index.ts +14 -0
  11. package/src/types/id.ts +2 -0
  12. package/src/types/index.ts +5 -0
  13. package/src/types/project/base.ts +63 -0
  14. package/src/types/project/contract.ts +79 -0
  15. package/src/types/project/contractStatus.tsx +15 -0
  16. package/src/types/project/index.ts +5 -0
  17. package/src/types/project/member.ts +46 -0
  18. package/src/types/project/progress.ts +43 -0
  19. package/src/types/projectRole.ts +17 -0
  20. package/src/types/theme.ts +1 -0
  21. package/src/types/user/index.ts +1 -0
  22. package/src/types/user/role.ts +7 -0
  23. package/src/ui/CommentTimeline/index.tsx +330 -0
  24. package/src/ui/FileManager/FileContextMenu.tsx +628 -0
  25. package/src/ui/FileManager/FileGridView.tsx +529 -0
  26. package/src/ui/FileManager/FileTableView.tsx +405 -0
  27. package/src/ui/FileManager/FileToolbar.tsx +119 -0
  28. package/src/ui/FileManager/FileVersionHistoryModal.tsx +175 -0
  29. package/src/ui/FileManager/MoveCopyToProjectModal.tsx +119 -0
  30. package/src/ui/FileManager/ShareToWechatModal.tsx +419 -0
  31. package/src/ui/FileManager/hooks/useFileManagerActions.ts +2532 -0
  32. package/src/ui/FileManager/hooks/useFileManagerState.ts +419 -0
  33. package/src/ui/FileManager/index.tsx +580 -0
  34. package/src/ui/FileManager/projectFileManagerApi.ts +57 -0
  35. package/src/ui/FileManager/types.ts +184 -0
  36. package/src/ui/FileManager/utils/fileDeltaWorker.ts +193 -0
  37. package/src/ui/FileManager/utils/fileTree.ts +178 -0
  38. package/src/ui/FileManager/utils/fileUpload.ts +714 -0
  39. package/src/ui/FileManager/utils/fileUtils.ts +65 -0
  40. package/src/ui/InvoiceRecordsList/index.tsx +813 -0
  41. package/src/ui/MyFileSelectorModal.tsx +261 -0
  42. package/src/ui/ProjectSelector/index.tsx +472 -0
  43. package/src/ui/ProjectSelector/projectCache.ts +40 -0
  44. package/src/ui/RoleSelector/index.tsx +473 -0
  45. package/src/ui/RoleSelector/roleCache.ts +40 -0
  46. package/src/ui/UIAlert.tsx +399 -0
  47. package/src/ui/UIAlertExample.tsx +129 -0
  48. package/src/ui/UIConfirm.tsx +335 -0
  49. package/src/ui/UIConfirmExample.tsx +165 -0
  50. package/src/ui/UIDatePicker.tsx +146 -0
  51. package/src/ui/UIDateRangePicker.tsx +38 -0
  52. package/src/ui/UIFilePreview/ExcelEditor/index.tsx +617 -0
  53. package/src/ui/UIFilePreview/ExcelEditor/types.ts +24 -0
  54. package/src/ui/UIFilePreview/ExportDropdown.css +85 -0
  55. package/src/ui/UIFilePreview/ExportDropdown.tsx +109 -0
  56. package/src/ui/UIFilePreview/IndexedDBUtils.ts +564 -0
  57. package/src/ui/UIFilePreview/MarkdownEditor/exportMarkdownPdf.ts +576 -0
  58. package/src/ui/UIFilePreview/MarkdownEditor/index.tsx +677 -0
  59. package/src/ui/UIFilePreview/MarkdownEditor/markdownEditor.css +1005 -0
  60. package/src/ui/UIFilePreview/MarkdownEditor/types.ts +15 -0
  61. package/src/ui/UIFilePreview/PPTXEditor/index.tsx +602 -0
  62. package/src/ui/UIFilePreview/RichDocEditor/exportRDocMarkdown.ts +77 -0
  63. package/src/ui/UIFilePreview/RichDocEditor/exportRDocPdf.ts +374 -0
  64. package/src/ui/UIFilePreview/RichDocEditor/index.tsx +730 -0
  65. package/src/ui/UIFilePreview/RichDocEditor/richdoc-editor.css +59 -0
  66. package/src/ui/UIFilePreview/UIFilePreview.tsx +611 -0
  67. package/src/ui/UIFilePreview/WordEditor/index.tsx +3933 -0
  68. package/src/ui/UIFilePreview/WordEditor/style.ts +1213 -0
  69. package/src/ui/UIFilePreview/WordEditor/word-editor.css +999 -0
  70. package/src/ui/UIFilePreview/filePreview.css +193 -0
  71. package/src/ui/UIFilePreview/filetypes/archive.tsx +66 -0
  72. package/src/ui/UIFilePreview/filetypes/cad.tsx +287 -0
  73. package/src/ui/UIFilePreview/filetypes/excel.tsx +355 -0
  74. package/src/ui/UIFilePreview/filetypes/image.tsx +20 -0
  75. package/src/ui/UIFilePreview/filetypes/imageLoader.ts +63 -0
  76. package/src/ui/UIFilePreview/filetypes/pdf.tsx +156 -0
  77. package/src/ui/UIFilePreview/filetypes/ppt.tsx +535 -0
  78. package/src/ui/UIFilePreview/filetypes/pptExportPdf.ts +523 -0
  79. package/src/ui/UIFilePreview/filetypes/video.tsx +482 -0
  80. package/src/ui/UIFilePreview/filetypes/word.tsx +245 -0
  81. package/src/ui/UIFilePreview/filetypes/wordExportMarkdown.ts +86 -0
  82. package/src/ui/UIFilePreview/filetypes/wordExportPdf.tsx +427 -0
  83. package/src/ui/UIFilePreview/index.ts +35 -0
  84. package/src/ui/UIFilePreview/pdfPagination.ts +143 -0
  85. package/src/ui/UIFilePreview/previewUtils.tsx +531 -0
  86. package/src/ui/UIFileUpload.tsx +382 -0
  87. package/src/ui/UIImageUpload.tsx +195 -0
  88. package/src/ui/UILoading.tsx +255 -0
  89. package/src/ui/UILoadingExample.tsx +139 -0
  90. package/src/ui/UISelect.tsx +105 -0
  91. package/src/ui/UIToast.tsx +381 -0
  92. package/src/ui/UIToastExample.tsx +69 -0
  93. package/src/ui/UIToastSingle.tsx +279 -0
  94. package/src/ui/UIViewToggle.tsx +64 -0
  95. package/src/ui/UserSelector/index.tsx +583 -0
  96. package/src/ui/index.ts +84 -0
  97. package/src/ui/upload/image.ts +135 -0
  98. package/src/ui/upload/index.ts +73 -0
  99. package/src/ui/upload/submitFile.ts +106 -0
  100. package/src/ui/upload/submitForm.ts +124 -0
  101. package/src/ui/upload/upload.err.ts +15 -0
  102. package/src/ui/upload/upload.ts +250 -0
  103. package/src/utils/CacheDepartmentInfo.ts +372 -0
  104. package/src/utils/CacheFileContent.ts +315 -0
  105. package/src/utils/CachePermissionInfo.ts +235 -0
  106. package/src/utils/CacheRoleInfo.ts +303 -0
  107. package/src/utils/CacheUserInfo.ts +818 -0
  108. package/src/utils/CacheViewToggleInfo.ts +182 -0
  109. package/src/utils/MessageContentUtils.ts +268 -0
  110. package/src/utils/clipboard.ts +70 -0
  111. package/src/utils/companyEmail.ts +19 -0
  112. package/src/utils/forbidDebugger.ts +59 -0
  113. package/src/utils/formatters.ts +94 -0
  114. package/src/utils/htmlUtils.tsx +59 -0
  115. package/src/utils/index.ts +18 -0
  116. package/src/utils/keyboard.ts +114 -0
  117. package/src/utils/mammothApi.ts +16 -0
  118. package/src/utils/polyfills.ts +928 -0
  119. package/src/utils/regex.ts +14 -0
  120. package/src/utils/storage.ts +95 -0
  121. package/src/utils/workerBootstrap.ts +87 -0
  122. package/dist/api/index.js +0 -1553
  123. package/dist/contract.js +0 -5
  124. package/dist/index.js +0 -4492
  125. package/dist/types/index.js +0 -49
  126. package/dist/ui/index.css +0 -1876
  127. package/dist/ui/index.js +0 -22245
  128. package/dist/utils/index.js +0 -4296
  129. /package/{dist → src}/styles/ant-modal.css +0 -0
  130. /package/{dist → src}/styles/ant-spin.css +0 -0
  131. /package/{dist → src}/styles/ant-table.css +0 -0
  132. /package/{dist → src}/styles/index.css +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spacecorexdev/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Vendorsys 基础包:API 基座、公共 UI 组件、工具函数、hooks、类型、样式、WebSocket、导航契约",
@@ -16,42 +16,8 @@
16
16
  "dev": "tsup --watch",
17
17
  "postinstall": "node scripts/patch-docx-grid.cjs"
18
18
  },
19
- "main": "./dist/index.js",
20
- "module": "./dist/index.js",
21
- "types": "./types/index.d.ts",
22
- "exports": {
23
- ".": {
24
- "types": "./types/index.d.ts",
25
- "import": "./dist/index.js"
26
- },
27
- "./contract": {
28
- "types": "./types/contract.d.ts",
29
- "import": "./dist/contract.js"
30
- },
31
- "./api": {
32
- "types": "./types/api/index.d.ts",
33
- "import": "./dist/api/index.js"
34
- },
35
- "./ui": {
36
- "types": "./types/ui.d.ts",
37
- "import": "./dist/ui/index.js"
38
- },
39
- "./utils": {
40
- "types": "./types/utils.d.ts",
41
- "import": "./dist/utils/index.js"
42
- },
43
- "./hooks": {
44
- "types": "./types/hooks.d.ts",
45
- "import": "./dist/hooks/index.js"
46
- },
47
- "./types": {
48
- "types": "./types/types/index.d.ts",
49
- "import": "./dist/types/index.js"
50
- },
51
- "./styles": "./dist/styles/index.css"
52
- },
53
19
  "files": [
54
- "dist",
20
+ "src",
55
21
  "public",
56
22
  "scripts",
57
23
  "types",
@@ -0,0 +1,243 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Copyright (c) 2025 SPACECORE Co.,Ltd. All Rights Reserved.
5
+ * Author: brian.li
6
+ * Date: 2025-02-12 22:31
7
+ * Desc:
8
+ */
9
+
10
+ import axios, { AxiosError } from 'axios';
11
+ import toast from '../ui/UIToast';
12
+ import loading from '../ui/UILoading';
13
+ import * as febs from 'febs-browser';
14
+ import { storage } from '../utils/storage';
15
+
16
+ /**
17
+ * 结果码
18
+ */
19
+ export enum ResponseCode {
20
+ SUCCESS = 200,
21
+ /**
22
+ * 操作错误
23
+ */
24
+ OPERATOR_ERROR = 400,
25
+ /**
26
+ * 未登录
27
+ */
28
+ UNAUTHORIZED = 401,
29
+ /**
30
+ * 未获得权限
31
+ */
32
+ UNPERMISSION = 402,
33
+ /**
34
+ * 未找到
35
+ */
36
+ NOT_FOUND = 404,
37
+ /**
38
+ * 服务不可用
39
+ */
40
+ SERVICE_UNAVAILABLE = 503,
41
+ /**
42
+ * 参数错误; 格式错误等.
43
+ */
44
+ PARAM_ERROR = 601,
45
+ /**
46
+ * 达到访问限制
47
+ */
48
+ REQUEST_LIMIT = 602,
49
+ }
50
+
51
+ function getResponseCodeMsg(code: ResponseCode) {
52
+ switch (code) {
53
+ case ResponseCode.NOT_FOUND:
54
+ return '资源不存在';
55
+ case ResponseCode.OPERATOR_ERROR:
56
+ return '系统操作错误';
57
+ case ResponseCode.PARAM_ERROR:
58
+ return '参数错误';
59
+ case ResponseCode.REQUEST_LIMIT:
60
+ return '达到访问限制';
61
+ case ResponseCode.SERVICE_UNAVAILABLE:
62
+ return '服务不可用';
63
+ case ResponseCode.UNAUTHORIZED:
64
+ return '未登录';
65
+ case ResponseCode.UNPERMISSION:
66
+ return '无权限';
67
+ default:
68
+ return '未知错误';
69
+ }
70
+ }
71
+
72
+ const api = axios.create({
73
+ baseURL: import.meta.env.VITE_API_BASE,
74
+ timeout: Number(import.meta.env.VITE_API_TIMEOUT) || 5000,
75
+ headers: {
76
+ 'Content-Type': 'application/json;charset=UTF-8',
77
+ },
78
+ withCredentials: true,
79
+ });
80
+
81
+ // jwt处理.
82
+ export class AuthorizationHandler {
83
+ static readonly HEADER_NAME: string = 'Authorization';
84
+ static readonly HEADER_PREFIX: string = 'SPBearer ';
85
+ static readonly TOKEN_EXP: number = 20 * 1000;
86
+
87
+ public static clearStoreToken() {
88
+ this.setStoreToken(null, 0);
89
+ }
90
+ private static getStoreToken(): { token: string; exp: number } | null {
91
+ let token = storage.namespace('bp.ss').get('ss');
92
+ if (token) {
93
+ let exp = storage.namespace('bp.ss').get('exp');
94
+ return {
95
+ token: JSON.parse(token),
96
+ exp: exp ? JSON.parse(exp) : 0,
97
+ };
98
+ }
99
+ return null;
100
+ }
101
+ public static getValidStoreToken(): string | null {
102
+ const token = AuthorizationHandler.getStoreToken();
103
+ if (token && token.exp > Date.now() - AuthorizationHandler.TOKEN_EXP) {
104
+ return token.token;
105
+ }
106
+ return null;
107
+ }
108
+ private static setStoreToken(token: string | null, exp: number) {
109
+ if (!token) {
110
+ storage.namespace('bp.ss').clear();
111
+ } else {
112
+ storage.namespace('bp.ss').set('ss', JSON.stringify(token));
113
+ storage.namespace('bp.ss').set('exp', JSON.stringify(exp));
114
+ }
115
+ }
116
+
117
+ static requestHandleSid(ctx: { headers: any }) {
118
+ let token = AuthorizationHandler.getStoreToken();
119
+ if (token) {
120
+ if (token.exp > Date.now() - AuthorizationHandler.TOKEN_EXP) {
121
+ ctx.headers.set(
122
+ AuthorizationHandler.HEADER_NAME,
123
+ AuthorizationHandler.HEADER_PREFIX + token.token,
124
+ );
125
+ }
126
+ }
127
+ }
128
+
129
+ static responseHandleSid(ctx: { headers: any }) {
130
+ let token: string = ctx.headers.get(AuthorizationHandler.HEADER_NAME);
131
+ if (token && token.startsWith(AuthorizationHandler.HEADER_PREFIX.trim())) {
132
+ token = token.replace(AuthorizationHandler.HEADER_PREFIX, '');
133
+ let oldToken = token;
134
+ token = token.split('.')[1];
135
+ if (token) {
136
+ token = febs.string.bytesToUtf8(febs.crypt.base64_decode(token));
137
+ if (token) {
138
+ let tokenObj = JSON.parse(token);
139
+ if (tokenObj.exp < Date.now() - AuthorizationHandler.TOKEN_EXP) {
140
+ // token 已过期:清除即可,不要在离线状态下触发整页重定向
141
+ AuthorizationHandler.clearStoreToken();
142
+ return false;
143
+ } else {
144
+ AuthorizationHandler.setStoreToken(oldToken, tokenObj.exp);
145
+ return true;
146
+ }
147
+ }
148
+ }
149
+
150
+ // token 解析失败:清除 token 后,仅在在线状态下跳转到首页走正常登录流程
151
+ AuthorizationHandler.clearStoreToken();
152
+ if (typeof navigator !== 'undefined' && navigator.onLine) {
153
+ window.location.href = '/';
154
+ }
155
+ }
156
+ return false;
157
+ }
158
+ }
159
+
160
+ // 请求拦截器
161
+ api.interceptors.request.use(
162
+ (config: any) => {
163
+ loading.show({
164
+ delay: 5000,
165
+ });
166
+ AuthorizationHandler.requestHandleSid(config);
167
+ return config;
168
+ },
169
+ (error: any) => {
170
+ loading.hide();
171
+ console.log('Request Error ==========');
172
+ return Promise.reject(error);
173
+ },
174
+ );
175
+
176
+ // 响应拦截器
177
+ api.interceptors.response.use(
178
+ (res: any) => {
179
+ loading.hide();
180
+ if (res.data.code !== ResponseCode.SUCCESS) {
181
+ toast.warning(res.data.message || getResponseCodeMsg(res.data.code));
182
+ }
183
+ // jwt handler
184
+ AuthorizationHandler.responseHandleSid(res);
185
+ return res.data;
186
+ },
187
+ (error: any) => {
188
+ loading.hide();
189
+
190
+ if (error instanceof AxiosError) {
191
+ if (error.code === 'ERR_NETWORK' || error.code === 'ECONNABORTED') {
192
+ toast.error('网络错误');
193
+ } else if (error.code === 'ERR_BAD_RESPONSE') {
194
+ toast.error('服务器无响应');
195
+ }
196
+ }
197
+
198
+ console.log('Response Error ==========');
199
+ return Promise.reject(error);
200
+ },
201
+ );
202
+
203
+ /**
204
+ * 请求方法
205
+ */
206
+ export const HttpRequest = {
207
+ get(url: string, params: any, data: any) {
208
+ const config = {
209
+ method: 'get',
210
+ url: url,
211
+ params,
212
+ data,
213
+ };
214
+ return api(config);
215
+ },
216
+ post(url: string, params: any, data: any) {
217
+ const config = {
218
+ method: 'post',
219
+ url: url,
220
+ params,
221
+ data,
222
+ };
223
+ return api(config);
224
+ },
225
+ put(url: string, params: any, data: any) {
226
+ const config = {
227
+ method: 'put',
228
+ url: url,
229
+ params,
230
+ data,
231
+ };
232
+ return api(config);
233
+ },
234
+ delete(url: string, params: any, data: any) {
235
+ const config = {
236
+ method: 'delete',
237
+ url: url,
238
+ params,
239
+ data,
240
+ };
241
+ return api(config);
242
+ },
243
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * core 包导出的 API 集合 —— 公共 API 基座 + 平台资源 API。
3
+ * 模块专属 API(crm/email/todo/knowledge/invoice/production)在 src/api 目录下定义。
4
+ */
5
+ import * as base from './_base';
6
+ import * as user from './user';
7
+ import * as project from './project';
8
+
9
+ export const API = {
10
+ base,
11
+ user,
12
+ project,
13
+ };
14
+
15
+ export * from './_base';
16
+ export * from './user';
17
+ export * from './project';