@chaomingd/design 0.0.68
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.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/esm/CheckGroup/context.d.ts +9 -0
- package/dist/esm/CheckGroup/context.js +6 -0
- package/dist/esm/CheckGroup/hooks/useCheckGroup.d.ts +21 -0
- package/dist/esm/CheckGroup/hooks/useCheckGroup.js +180 -0
- package/dist/esm/CheckGroup/index.d.ts +9 -0
- package/dist/esm/CheckGroup/index.js +79 -0
- package/dist/esm/CheckGroup/type.d.ts +28 -0
- package/dist/esm/CheckGroup/type.js +1 -0
- package/dist/esm/Grid/index.d.ts +15 -0
- package/dist/esm/Grid/index.js +64 -0
- package/dist/esm/Grid/index.less +7 -0
- package/dist/esm/KaTeXRenderer/index.d.ts +9 -0
- package/dist/esm/KaTeXRenderer/index.js +33 -0
- package/dist/esm/KaTeXRenderer/index.less +0 -0
- package/dist/esm/PixelPlayer/index.d.ts +28 -0
- package/dist/esm/PixelPlayer/index.js +118 -0
- package/dist/esm/PixelPlayer/index.less +29 -0
- package/dist/esm/PixelPlayer/lib/peer-stream.d.ts +62 -0
- package/dist/esm/PixelPlayer/lib/peer-stream.js +876 -0
- package/dist/esm/PixelPlayer/useAutoLayoutContainer.d.ts +2 -0
- package/dist/esm/PixelPlayer/useAutoLayoutContainer.js +53 -0
- package/dist/esm/PixelPlayer/useVideoWithCustomEvent.d.ts +5 -0
- package/dist/esm/PixelPlayer/useVideoWithCustomEvent.js +37 -0
- package/dist/esm/Resizer/index.d.ts +17 -0
- package/dist/esm/Resizer/index.js +73 -0
- package/dist/esm/Resizer/index.less +73 -0
- package/dist/esm/SetupAntApp/index.d.ts +1 -0
- package/dist/esm/SetupAntApp/index.js +10 -0
- package/dist/esm/Transition/index.d.ts +4 -0
- package/dist/esm/Transition/index.js +132 -0
- package/dist/esm/Transition/type.d.ts +33 -0
- package/dist/esm/Transition/type.js +12 -0
- package/dist/esm/Transition/utils.d.ts +6 -0
- package/dist/esm/Transition/utils.js +15 -0
- package/dist/esm/UploadFile/components/IconButton/index.d.ts +11 -0
- package/dist/esm/UploadFile/components/IconButton/index.js +26 -0
- package/dist/esm/UploadFile/components/IconButton/index.less +58 -0
- package/dist/esm/UploadFile/components/Slash.d.ts +2 -0
- package/dist/esm/UploadFile/components/Slash.js +15 -0
- package/dist/esm/UploadFile/components/SvgIcons.d.ts +11 -0
- package/dist/esm/UploadFile/components/SvgIcons.js +141 -0
- package/dist/esm/UploadFile/hooks/useUploadModel.d.ts +16 -0
- package/dist/esm/UploadFile/hooks/useUploadModel.js +376 -0
- package/dist/esm/UploadFile/index.d.ts +4 -0
- package/dist/esm/UploadFile/index.js +277 -0
- package/dist/esm/UploadFile/index.less +274 -0
- package/dist/esm/UploadFile/type.d.ts +63 -0
- package/dist/esm/UploadFile/type.js +1 -0
- package/dist/esm/UploadFile/utils/formatBitString.d.ts +1 -0
- package/dist/esm/UploadFile/utils/formatBitString.js +9 -0
- package/dist/esm/UploadFile/utils/getExt.d.ts +1 -0
- package/dist/esm/UploadFile/utils/getExt.js +6 -0
- package/dist/esm/UploadFile/utils/isImage.d.ts +1 -0
- package/dist/esm/UploadFile/utils/isImage.js +8 -0
- package/dist/esm/UploadFile/utils/normalizeExt.d.ts +1 -0
- package/dist/esm/UploadFile/utils/normalizeExt.js +4 -0
- package/dist/esm/UploadFile/utils/validateFileTypes.d.ts +13 -0
- package/dist/esm/UploadFile/utils/validateFileTypes.js +83 -0
- package/dist/esm/UploadFile/utils/validateRule.d.ts +3 -0
- package/dist/esm/UploadFile/utils/validateRule.js +22 -0
- package/dist/esm/UploadFile/utils/validateUpload.d.ts +5 -0
- package/dist/esm/UploadFile/utils/validateUpload.js +35 -0
- package/dist/esm/constant/index.d.ts +7 -0
- package/dist/esm/constant/index.js +18 -0
- package/dist/esm/constants/cssPrefix.d.ts +1 -0
- package/dist/esm/constants/cssPrefix.js +1 -0
- package/dist/esm/getAntApp/index.d.ts +8 -0
- package/dist/esm/getAntApp/index.js +17 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/interface.d.ts +1 -0
- package/dist/esm/interface.js +1 -0
- package/dist/esm/styles/cssVar.less +28 -0
- package/dist/esm/styles/reset.css +3 -0
- package/dist/esm/styles/var.d.ts +1 -0
- package/dist/esm/styles/var.js +1 -0
- package/dist/esm/styles/var.less +2 -0
- package/dist/esm/variable.less +52 -0
- package/dist/lib/CheckGroup/context.d.ts +9 -0
- package/dist/lib/CheckGroup/context.js +12 -0
- package/dist/lib/CheckGroup/hooks/useCheckGroup.d.ts +21 -0
- package/dist/lib/CheckGroup/hooks/useCheckGroup.js +164 -0
- package/dist/lib/CheckGroup/index.d.ts +9 -0
- package/dist/lib/CheckGroup/index.js +93 -0
- package/dist/lib/CheckGroup/type.d.ts +28 -0
- package/dist/lib/CheckGroup/type.js +5 -0
- package/dist/lib/Grid/index.d.ts +15 -0
- package/dist/lib/Grid/index.js +77 -0
- package/dist/lib/Grid/index.less +7 -0
- package/dist/lib/KaTeXRenderer/index.d.ts +9 -0
- package/dist/lib/KaTeXRenderer/index.js +41 -0
- package/dist/lib/KaTeXRenderer/index.less +0 -0
- package/dist/lib/PixelPlayer/index.d.ts +28 -0
- package/dist/lib/PixelPlayer/index.js +108 -0
- package/dist/lib/PixelPlayer/index.less +29 -0
- package/dist/lib/PixelPlayer/lib/peer-stream.d.ts +62 -0
- package/dist/lib/PixelPlayer/lib/peer-stream.js +707 -0
- package/dist/lib/PixelPlayer/useAutoLayoutContainer.d.ts +2 -0
- package/dist/lib/PixelPlayer/useAutoLayoutContainer.js +60 -0
- package/dist/lib/PixelPlayer/useVideoWithCustomEvent.d.ts +5 -0
- package/dist/lib/PixelPlayer/useVideoWithCustomEvent.js +35 -0
- package/dist/lib/Resizer/index.d.ts +17 -0
- package/dist/lib/Resizer/index.js +75 -0
- package/dist/lib/Resizer/index.less +73 -0
- package/dist/lib/SetupAntApp/index.d.ts +1 -0
- package/dist/lib/SetupAntApp/index.js +16 -0
- package/dist/lib/Transition/index.d.ts +4 -0
- package/dist/lib/Transition/index.js +128 -0
- package/dist/lib/Transition/type.d.ts +33 -0
- package/dist/lib/Transition/type.js +18 -0
- package/dist/lib/Transition/utils.d.ts +6 -0
- package/dist/lib/Transition/utils.js +22 -0
- package/dist/lib/UploadFile/components/IconButton/index.d.ts +11 -0
- package/dist/lib/UploadFile/components/IconButton/index.js +29 -0
- package/dist/lib/UploadFile/components/IconButton/index.less +58 -0
- package/dist/lib/UploadFile/components/Slash.d.ts +2 -0
- package/dist/lib/UploadFile/components/Slash.js +22 -0
- package/dist/lib/UploadFile/components/SvgIcons.d.ts +11 -0
- package/dist/lib/UploadFile/components/SvgIcons.js +158 -0
- package/dist/lib/UploadFile/hooks/useUploadModel.d.ts +16 -0
- package/dist/lib/UploadFile/hooks/useUploadModel.js +306 -0
- package/dist/lib/UploadFile/index.d.ts +4 -0
- package/dist/lib/UploadFile/index.js +280 -0
- package/dist/lib/UploadFile/index.less +274 -0
- package/dist/lib/UploadFile/type.d.ts +63 -0
- package/dist/lib/UploadFile/type.js +5 -0
- package/dist/lib/UploadFile/utils/formatBitString.d.ts +1 -0
- package/dist/lib/UploadFile/utils/formatBitString.js +15 -0
- package/dist/lib/UploadFile/utils/getExt.d.ts +1 -0
- package/dist/lib/UploadFile/utils/getExt.js +12 -0
- package/dist/lib/UploadFile/utils/isImage.d.ts +1 -0
- package/dist/lib/UploadFile/utils/isImage.js +14 -0
- package/dist/lib/UploadFile/utils/normalizeExt.d.ts +1 -0
- package/dist/lib/UploadFile/utils/normalizeExt.js +10 -0
- package/dist/lib/UploadFile/utils/validateFileTypes.d.ts +13 -0
- package/dist/lib/UploadFile/utils/validateFileTypes.js +87 -0
- package/dist/lib/UploadFile/utils/validateRule.d.ts +3 -0
- package/dist/lib/UploadFile/utils/validateRule.js +28 -0
- package/dist/lib/UploadFile/utils/validateUpload.d.ts +5 -0
- package/dist/lib/UploadFile/utils/validateUpload.js +31 -0
- package/dist/lib/constant/index.d.ts +7 -0
- package/dist/lib/constant/index.js +24 -0
- package/dist/lib/constants/cssPrefix.d.ts +1 -0
- package/dist/lib/constants/cssPrefix.js +7 -0
- package/dist/lib/getAntApp/index.d.ts +8 -0
- package/dist/lib/getAntApp/index.js +27 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.js +69 -0
- package/dist/lib/interface.d.ts +1 -0
- package/dist/lib/interface.js +5 -0
- package/dist/lib/styles/cssVar.less +28 -0
- package/dist/lib/styles/reset.css +3 -0
- package/dist/lib/styles/var.d.ts +1 -0
- package/dist/lib/styles/var.js +7 -0
- package/dist/lib/styles/var.less +2 -0
- package/dist/lib/variable.less +52 -0
- package/package.json +54 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fileTypeChecker from 'file-type-checker';
|
|
2
|
+
import { getExt } from "./getExt";
|
|
3
|
+
function trimDot(str) {
|
|
4
|
+
if (str[0] === '.') {
|
|
5
|
+
return str.slice(1);
|
|
6
|
+
}
|
|
7
|
+
return str;
|
|
8
|
+
}
|
|
9
|
+
export function validateFileTypes(file, types) {
|
|
10
|
+
return new Promise(function (resolve, reject) {
|
|
11
|
+
var reader = new FileReader();
|
|
12
|
+
reader.onload = function () {
|
|
13
|
+
var ext = getExt(file.name);
|
|
14
|
+
if (reader.result) {
|
|
15
|
+
try {
|
|
16
|
+
var isValid = fileTypeChecker.validateFileType(reader.result, types.map(function (type) {
|
|
17
|
+
return trimDot(type);
|
|
18
|
+
}));
|
|
19
|
+
var fileInfo = fileTypeChecker.detectFile(reader.result) || {
|
|
20
|
+
extension: ext,
|
|
21
|
+
mimeType: file.type,
|
|
22
|
+
description: file.type
|
|
23
|
+
};
|
|
24
|
+
resolve({
|
|
25
|
+
isValid: isValid,
|
|
26
|
+
fileInfo: fileInfo
|
|
27
|
+
});
|
|
28
|
+
} catch (e) {
|
|
29
|
+
resolve({
|
|
30
|
+
isValid: types.map(function (type) {
|
|
31
|
+
return trimDot(type);
|
|
32
|
+
}).includes(ext),
|
|
33
|
+
fileInfo: {
|
|
34
|
+
extension: ext,
|
|
35
|
+
mimeType: file.type,
|
|
36
|
+
description: file.type
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
reject(new Error('reader arraybuffer empty'));
|
|
43
|
+
};
|
|
44
|
+
reader.onerror = function (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
};
|
|
47
|
+
reader.readAsArrayBuffer(file);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function getFileInfo(file) {
|
|
51
|
+
return new Promise(function (resolve, reject) {
|
|
52
|
+
var reader = new FileReader();
|
|
53
|
+
reader.onload = function () {
|
|
54
|
+
if (reader.result) {
|
|
55
|
+
try {
|
|
56
|
+
var fileInfo = fileTypeChecker.detectFile(reader.result);
|
|
57
|
+
if (fileInfo) {
|
|
58
|
+
resolve(fileInfo);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
resolve({
|
|
62
|
+
extension: getExt(file.name),
|
|
63
|
+
mimeType: file.type,
|
|
64
|
+
description: file.type
|
|
65
|
+
});
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.warn('file-type-checker error', e);
|
|
68
|
+
resolve({
|
|
69
|
+
extension: getExt(file.name),
|
|
70
|
+
mimeType: file.type,
|
|
71
|
+
description: file.type
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
reject(new Error('reader arraybuffer empty'));
|
|
77
|
+
};
|
|
78
|
+
reader.onerror = function (e) {
|
|
79
|
+
reject(e);
|
|
80
|
+
};
|
|
81
|
+
reader.readAsArrayBuffer(file);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function getValidateRule() {
|
|
2
|
+
return {
|
|
3
|
+
validator: function validator(_, val) {
|
|
4
|
+
if (Array.isArray(val)) {
|
|
5
|
+
var valid = true;
|
|
6
|
+
var message = '';
|
|
7
|
+
for (var i = 0; i < val.length; i++) {
|
|
8
|
+
var item = val[i];
|
|
9
|
+
if (item.status === 'error') {
|
|
10
|
+
valid = false;
|
|
11
|
+
message = '文件上传失败';
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (!valid) {
|
|
16
|
+
return Promise.reject(new Error(message));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
export function validateUpload(fileItems) {
|
|
3
|
+
var isValid = true;
|
|
4
|
+
var message = '';
|
|
5
|
+
var _iterator = _createForOfIteratorHelper(fileItems),
|
|
6
|
+
_step;
|
|
7
|
+
try {
|
|
8
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
9
|
+
var fileItem = _step.value;
|
|
10
|
+
if (fileItem.status === 'uploading') {
|
|
11
|
+
isValid = false;
|
|
12
|
+
message = "\u6587\u4EF6".concat(fileItem.name, "\u672A\u4E0A\u4F20\u5B8C\u6210");
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
if (fileItem.validationStatus === 'validating') {
|
|
16
|
+
isValid = false;
|
|
17
|
+
message = "\u6587\u4EF6".concat(fileItem.name, "\u672A\u6821\u9A8C\u5B8C\u6210");
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (fileItem.validationStatus === 'error') {
|
|
21
|
+
isValid = false;
|
|
22
|
+
message = "\u6587\u4EF6".concat(fileItem.name, "\u6821\u9A8C\u5931\u8D25");
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
_iterator.e(err);
|
|
28
|
+
} finally {
|
|
29
|
+
_iterator.f();
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
isValid: isValid,
|
|
33
|
+
message: message
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// OB 官网链接
|
|
2
|
+
export var OB_SITE_LINK = 'https://www.xxx.com';
|
|
3
|
+
export var LOCALE_LIST = [{
|
|
4
|
+
value: 'en-US',
|
|
5
|
+
label: 'English',
|
|
6
|
+
shortLabel: 'English',
|
|
7
|
+
minLabel: 'EN'
|
|
8
|
+
}, {
|
|
9
|
+
value: 'zh-CN',
|
|
10
|
+
label: '简体中文',
|
|
11
|
+
shortLabel: '中文',
|
|
12
|
+
minLabel: '中'
|
|
13
|
+
}, {
|
|
14
|
+
value: 'zh-TW',
|
|
15
|
+
label: '繁体中文',
|
|
16
|
+
shortLabel: '繁体',
|
|
17
|
+
minLabel: '繁'
|
|
18
|
+
}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CSS_PREFIX = "cm";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var CSS_PREFIX = 'cm';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { App } from 'antd';
|
|
2
|
+
type TAntApp = ReturnType<typeof App.useApp>;
|
|
3
|
+
export declare function setAntApp(antApp: TAntApp): void;
|
|
4
|
+
export declare function clearAntApp(): void;
|
|
5
|
+
export default function getAntApp(): import("antd/es/app/context").useAppProps;
|
|
6
|
+
export declare function getAntMessage(): import("antd/es/message/interface").MessageInstance;
|
|
7
|
+
export declare function getAntModal(): import("antd/es/modal/useModal").HookAPI;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Modal, message } from 'antd';
|
|
2
|
+
var AntApp = {};
|
|
3
|
+
export function setAntApp(antApp) {
|
|
4
|
+
AntApp = antApp;
|
|
5
|
+
}
|
|
6
|
+
export function clearAntApp() {
|
|
7
|
+
AntApp = {};
|
|
8
|
+
}
|
|
9
|
+
export default function getAntApp() {
|
|
10
|
+
return AntApp;
|
|
11
|
+
}
|
|
12
|
+
export function getAntMessage() {
|
|
13
|
+
return getAntApp().message || message;
|
|
14
|
+
}
|
|
15
|
+
export function getAntModal() {
|
|
16
|
+
return getAntApp().modal || Modal;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import SetupAntApp from './SetupAntApp';
|
|
2
|
+
import getAntApp from './getAntApp';
|
|
3
|
+
import UploadFile from './UploadFile';
|
|
4
|
+
import KaTeXRenderer from './KaTeXRenderer';
|
|
5
|
+
import Grid from './Grid';
|
|
6
|
+
import Transition from './Transition';
|
|
7
|
+
import { PixelPlayer } from './PixelPlayer';
|
|
8
|
+
import CheckGroup from './CheckGroup';
|
|
9
|
+
import Resizer from './Resizer';
|
|
10
|
+
export { KaTeXRenderer, Grid, Transition, UploadFile, SetupAntApp, getAntApp, PixelPlayer, CheckGroup, Resizer, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import SetupAntApp from "./SetupAntApp";
|
|
2
|
+
import getAntApp from "./getAntApp";
|
|
3
|
+
import UploadFile from "./UploadFile";
|
|
4
|
+
import KaTeXRenderer from "./KaTeXRenderer";
|
|
5
|
+
import Grid from "./Grid";
|
|
6
|
+
import Transition from "./Transition";
|
|
7
|
+
import { PixelPlayer } from "./PixelPlayer";
|
|
8
|
+
import CheckGroup from "./CheckGroup";
|
|
9
|
+
import Resizer from "./Resizer";
|
|
10
|
+
export { KaTeXRenderer, Grid, Transition, UploadFile, SetupAntApp, getAntApp, PixelPlayer, CheckGroup, Resizer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Locale = 'zh-TW' | 'zh-CN' | 'en-US';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@import "./var.less";
|
|
2
|
+
|
|
3
|
+
// design-token.less
|
|
4
|
+
// var(--sp-color-primary, #345678);
|
|
5
|
+
.apply-design-token(@tokens) {
|
|
6
|
+
& {
|
|
7
|
+
each(@tokens, {
|
|
8
|
+
--@{prefix}-@{key}: @value;
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// mixin.less
|
|
14
|
+
.cssVar(@block, @rule, @type: '') {
|
|
15
|
+
& {
|
|
16
|
+
each(@rule, {
|
|
17
|
+
// 去除变量定义 @xx: val;
|
|
18
|
+
.css() when((replace(@key, '@', '') = @key)) {
|
|
19
|
+
@{key}: if(@type = '', ~"var(--@{prefix}-@{block}-@{key}, @{value})", ~"var(--@{prefix}-@{block}-@{key}-@{type}, @{value})");
|
|
20
|
+
}
|
|
21
|
+
.css();
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.var(@name, @default: '') {
|
|
27
|
+
@val: if((@default = ''), ~"var(--@{prefix}-@{name})", ~"var(--@{prefix}-@{name}, @{default})");
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CSS_PREFIX = "cm";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var CSS_PREFIX = 'cm';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// 限制最大宽度,避免页面被无限拉伸
|
|
2
|
+
// 暂时去除最大宽度限制
|
|
3
|
+
@maxWidth: 8192px;
|
|
4
|
+
@prefixCls: ant;
|
|
5
|
+
@iconPrefixCls: anticon;
|
|
6
|
+
|
|
7
|
+
// 边框渐变
|
|
8
|
+
.border-gradient
|
|
9
|
+
(
|
|
10
|
+
// 背景色,默认为透明色
|
|
11
|
+
@background-color: transparent,
|
|
12
|
+
// 边框色
|
|
13
|
+
@border-color,
|
|
14
|
+
// 边框宽度
|
|
15
|
+
@border-width: 1px,
|
|
16
|
+
// 边框样式
|
|
17
|
+
@border-style: solid,
|
|
18
|
+
// 边框圆角
|
|
19
|
+
@border-radius: 0px
|
|
20
|
+
) {
|
|
21
|
+
background-image: @background-color, @border-color;
|
|
22
|
+
background-clip: padding-box, border-box;
|
|
23
|
+
background-origin: padding-box, border-box;
|
|
24
|
+
border: @border-width @border-style transparent;
|
|
25
|
+
border-radius: @border-radius;
|
|
26
|
+
transition: border-width 0.3s;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@keyframes activeGradientAnimation {
|
|
30
|
+
0% {
|
|
31
|
+
background-repeat: no-repeat;
|
|
32
|
+
background-size: 0% 100%;
|
|
33
|
+
}
|
|
34
|
+
100% {
|
|
35
|
+
background-repeat: no-repeat;
|
|
36
|
+
background-size: 100% 100%;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@keyframes selectedGradientAnimation {
|
|
41
|
+
0% {
|
|
42
|
+
background-repeat: no-repeat;
|
|
43
|
+
background-size: 0% 100%;
|
|
44
|
+
// 选中态有圆角渐变动画
|
|
45
|
+
border-radius: 0;
|
|
46
|
+
}
|
|
47
|
+
100% {
|
|
48
|
+
background-repeat: no-repeat;
|
|
49
|
+
background-size: 100% 100%;
|
|
50
|
+
border-radius: 8px;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CheckGroupModel } from './hooks/useCheckGroup';
|
|
3
|
+
import { CheckGroupProps } from './type';
|
|
4
|
+
type CheckGroupContextType = {
|
|
5
|
+
model: CheckGroupModel<any>;
|
|
6
|
+
props: CheckGroupProps<any>;
|
|
7
|
+
};
|
|
8
|
+
export declare const CheckGroupContext: import("react").Context<CheckGroupContextType>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CheckGroupContext = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _useCheckGroup = require("./hooks/useCheckGroup");
|
|
9
|
+
const CheckGroupContext = exports.CheckGroupContext = /*#__PURE__*/(0, _react.createContext)({
|
|
10
|
+
model: new _useCheckGroup.CheckGroupModel(),
|
|
11
|
+
props: {}
|
|
12
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Model } from '@chaomingd/store';
|
|
2
|
+
import { CheckGroupProps, CheckGroupState, Key } from '../type';
|
|
3
|
+
export declare class CheckGroupModel<K extends Key> extends Model<CheckGroupState<K>> {
|
|
4
|
+
keys: K[];
|
|
5
|
+
timer: any;
|
|
6
|
+
props: CheckGroupProps<K>;
|
|
7
|
+
useGroupKeys: boolean;
|
|
8
|
+
constructor();
|
|
9
|
+
getCheckAllInfo(checkMap?: Map<Key, boolean>): {
|
|
10
|
+
isCheckAll: boolean;
|
|
11
|
+
indeterminate: boolean;
|
|
12
|
+
};
|
|
13
|
+
handleToggleCheckAll: () => void;
|
|
14
|
+
handleToggleCheck: (key: K) => void;
|
|
15
|
+
handleCheckOne: (key: K) => void;
|
|
16
|
+
registerKey(key: K): void;
|
|
17
|
+
setKeys(keys: K[]): void;
|
|
18
|
+
unRegisterKey(key: K): void;
|
|
19
|
+
__updateKeys(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function useCheckGroup<K extends Key>(props: CheckGroupProps<K>): CheckGroupModel<K>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CheckGroupModel = void 0;
|
|
7
|
+
exports.useCheckGroup = useCheckGroup;
|
|
8
|
+
var _store = require("@chaomingd/store");
|
|
9
|
+
var _ahooks = require("ahooks");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
class CheckGroupModel extends _store.Model {
|
|
12
|
+
keys = [];
|
|
13
|
+
timer;
|
|
14
|
+
props = {};
|
|
15
|
+
useGroupKeys = false;
|
|
16
|
+
constructor() {
|
|
17
|
+
super({
|
|
18
|
+
autoInit: false,
|
|
19
|
+
state: {
|
|
20
|
+
value: [],
|
|
21
|
+
valueMap: new Map(),
|
|
22
|
+
keys: [],
|
|
23
|
+
isCheckAll: false,
|
|
24
|
+
indeterminate: false
|
|
25
|
+
},
|
|
26
|
+
computed: [{
|
|
27
|
+
keys: ['value'],
|
|
28
|
+
hander: ({
|
|
29
|
+
value
|
|
30
|
+
}) => {
|
|
31
|
+
const m = new Map();
|
|
32
|
+
value.forEach(k => {
|
|
33
|
+
m.set(k, true);
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
valueMap: m
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
keys: ['value', 'keys'],
|
|
41
|
+
hander: ({
|
|
42
|
+
valueMap
|
|
43
|
+
}) => {
|
|
44
|
+
return {
|
|
45
|
+
...this.getCheckAllInfo(valueMap)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
this.init();
|
|
51
|
+
}
|
|
52
|
+
getCheckAllInfo(checkMap) {
|
|
53
|
+
const {
|
|
54
|
+
valueMap
|
|
55
|
+
} = this.getState();
|
|
56
|
+
const ckMap = checkMap || valueMap;
|
|
57
|
+
const {
|
|
58
|
+
keys
|
|
59
|
+
} = this;
|
|
60
|
+
let indeterminate = false;
|
|
61
|
+
let isCheckAll = true;
|
|
62
|
+
keys.forEach(k => {
|
|
63
|
+
const isCheck = ckMap.get(k);
|
|
64
|
+
if (isCheck) {
|
|
65
|
+
indeterminate = true;
|
|
66
|
+
} else {
|
|
67
|
+
isCheckAll = false;
|
|
68
|
+
}
|
|
69
|
+
return isCheck;
|
|
70
|
+
});
|
|
71
|
+
if (isCheckAll) {
|
|
72
|
+
indeterminate = false;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
isCheckAll,
|
|
76
|
+
indeterminate
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
handleToggleCheckAll = () => {
|
|
80
|
+
const {
|
|
81
|
+
isCheckAll
|
|
82
|
+
} = this.getState();
|
|
83
|
+
let newKeys;
|
|
84
|
+
if (isCheckAll) {
|
|
85
|
+
newKeys = [];
|
|
86
|
+
} else {
|
|
87
|
+
newKeys = [...this.keys];
|
|
88
|
+
}
|
|
89
|
+
if (!('value' in this.props)) {
|
|
90
|
+
this.setState({
|
|
91
|
+
value: newKeys
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
this.props.onChange?.(newKeys);
|
|
95
|
+
};
|
|
96
|
+
handleToggleCheck = key => {
|
|
97
|
+
const {
|
|
98
|
+
valueMap,
|
|
99
|
+
value
|
|
100
|
+
} = this.getState();
|
|
101
|
+
const isCheck = valueMap.get(key);
|
|
102
|
+
let newKeys = [...value];
|
|
103
|
+
if (isCheck) {
|
|
104
|
+
newKeys = newKeys.filter(k => k !== key);
|
|
105
|
+
} else {
|
|
106
|
+
newKeys.push(key);
|
|
107
|
+
}
|
|
108
|
+
if (!('value' in this.props)) {
|
|
109
|
+
this.setState({
|
|
110
|
+
value: newKeys
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
this.props.onChange?.(newKeys);
|
|
114
|
+
};
|
|
115
|
+
handleCheckOne = key => {
|
|
116
|
+
const newKeys = [key];
|
|
117
|
+
if (!('value' in this.props)) {
|
|
118
|
+
this.setState({
|
|
119
|
+
value: newKeys
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
this.props.onChange?.(newKeys);
|
|
123
|
+
};
|
|
124
|
+
registerKey(key) {
|
|
125
|
+
if (!this.keys.includes(key)) {
|
|
126
|
+
this.keys.push(key);
|
|
127
|
+
}
|
|
128
|
+
this.__updateKeys();
|
|
129
|
+
}
|
|
130
|
+
setKeys(keys) {
|
|
131
|
+
this.keys = keys;
|
|
132
|
+
this.__updateKeys();
|
|
133
|
+
}
|
|
134
|
+
unRegisterKey(key) {
|
|
135
|
+
this.keys = this.keys.filter(k => k !== key);
|
|
136
|
+
this.__updateKeys();
|
|
137
|
+
}
|
|
138
|
+
__updateKeys() {
|
|
139
|
+
clearTimeout(this.timer);
|
|
140
|
+
this.timer = setTimeout(() => {
|
|
141
|
+
this.setState({
|
|
142
|
+
keys: [...this.keys]
|
|
143
|
+
});
|
|
144
|
+
}, 10);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.CheckGroupModel = CheckGroupModel;
|
|
148
|
+
function useCheckGroup(props) {
|
|
149
|
+
const hasValue = ('value' in props);
|
|
150
|
+
const model = (0, _ahooks.useCreation)(() => {
|
|
151
|
+
return new CheckGroupModel();
|
|
152
|
+
}, []);
|
|
153
|
+
model.props = props;
|
|
154
|
+
(0, _react.useMemo)(() => {
|
|
155
|
+
if (hasValue) {
|
|
156
|
+
model.setState({
|
|
157
|
+
value: props.value || []
|
|
158
|
+
}, {
|
|
159
|
+
silent: true
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}, [props.value, model, hasValue]);
|
|
163
|
+
return model;
|
|
164
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CheckGroupProps, CheckItemProps, Key } from './type';
|
|
3
|
+
declare const CheckItem: <K extends Key>(props: CheckItemProps<K>) => import("react").ReactNode;
|
|
4
|
+
declare const CheckAllItem: <K extends Key>(props: CheckItemProps<K>) => import("react").ReactNode;
|
|
5
|
+
declare const CheckGroup: (<K extends Key>(props: CheckGroupProps<K>) => import("react/jsx-runtime").JSX.Element) & {
|
|
6
|
+
CheckItem: typeof CheckItem;
|
|
7
|
+
CheckAllItem: typeof CheckAllItem;
|
|
8
|
+
};
|
|
9
|
+
export default CheckGroup;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _context = require("./context");
|
|
9
|
+
var _useCheckGroup = require("./hooks/useCheckGroup");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
const _CheckGroup = props => {
|
|
12
|
+
const model = (0, _useCheckGroup.useCheckGroup)(props);
|
|
13
|
+
const hasKeys = ('keys' in props);
|
|
14
|
+
model.useGroupKeys = hasKeys;
|
|
15
|
+
// model.useUpdate();
|
|
16
|
+
(0, _react.useEffect)(() => {
|
|
17
|
+
if (hasKeys) {
|
|
18
|
+
model.setKeys(props.keys || []);
|
|
19
|
+
}
|
|
20
|
+
}, [props.keys, model, hasKeys]);
|
|
21
|
+
const contextValue = (0, _react.useMemo)(() => {
|
|
22
|
+
return {
|
|
23
|
+
model,
|
|
24
|
+
props
|
|
25
|
+
};
|
|
26
|
+
}, [model, props.value]);
|
|
27
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.CheckGroupContext.Provider, {
|
|
28
|
+
value: contextValue,
|
|
29
|
+
children: props.children
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const CheckItem = props => {
|
|
33
|
+
const {
|
|
34
|
+
value,
|
|
35
|
+
children
|
|
36
|
+
} = props;
|
|
37
|
+
const {
|
|
38
|
+
model
|
|
39
|
+
} = (0, _react.useContext)(_context.CheckGroupContext);
|
|
40
|
+
const multiple = model.props.multiple;
|
|
41
|
+
const useGroupKeys = model.useGroupKeys;
|
|
42
|
+
const {
|
|
43
|
+
valueMap,
|
|
44
|
+
indeterminate
|
|
45
|
+
} = model.useGetState();
|
|
46
|
+
const isCheck = valueMap.get(value) || false;
|
|
47
|
+
(0, _react.useMemo)(() => {
|
|
48
|
+
if (!useGroupKeys) {
|
|
49
|
+
model.registerKey(value);
|
|
50
|
+
}
|
|
51
|
+
return () => {
|
|
52
|
+
if (!useGroupKeys) {
|
|
53
|
+
model.unRegisterKey(value);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}, [model, value, useGroupKeys]);
|
|
57
|
+
if (typeof children === 'function') {
|
|
58
|
+
const onChange = () => {
|
|
59
|
+
multiple ? model.handleToggleCheck(value) : model.handleCheckOne(value);
|
|
60
|
+
};
|
|
61
|
+
return children({
|
|
62
|
+
checked: isCheck,
|
|
63
|
+
indeterminate,
|
|
64
|
+
onChange
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return children;
|
|
68
|
+
};
|
|
69
|
+
const CheckAllItem = props => {
|
|
70
|
+
const {
|
|
71
|
+
children
|
|
72
|
+
} = props;
|
|
73
|
+
const {
|
|
74
|
+
model
|
|
75
|
+
} = (0, _react.useContext)(_context.CheckGroupContext);
|
|
76
|
+
const {
|
|
77
|
+
isCheckAll,
|
|
78
|
+
indeterminate
|
|
79
|
+
} = model.useGetState();
|
|
80
|
+
if (typeof children === 'function') {
|
|
81
|
+
return children({
|
|
82
|
+
checked: isCheckAll,
|
|
83
|
+
indeterminate,
|
|
84
|
+
onChange: model.handleToggleCheckAll
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return children;
|
|
88
|
+
};
|
|
89
|
+
const _component = _CheckGroup;
|
|
90
|
+
const CheckGroup = _component;
|
|
91
|
+
CheckGroup.CheckItem = CheckItem;
|
|
92
|
+
CheckGroup.CheckAllItem = CheckAllItem;
|
|
93
|
+
var _default = exports.default = CheckGroup;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type Key = string | number | symbol;
|
|
3
|
+
export interface CheckGroupProps<K extends Key> {
|
|
4
|
+
value?: K[];
|
|
5
|
+
onChange?: (val: K[]) => void;
|
|
6
|
+
children?: ReactNode | ReactNode[];
|
|
7
|
+
keys?: K[];
|
|
8
|
+
multiple?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CheckGroupState<K extends Key> {
|
|
11
|
+
value: K[];
|
|
12
|
+
valueMap: Map<K, boolean>;
|
|
13
|
+
keys: K[];
|
|
14
|
+
isCheckAll: boolean;
|
|
15
|
+
indeterminate: boolean;
|
|
16
|
+
}
|
|
17
|
+
type CheckItemChildren = ReactNode | ReactNode[] | ((props: {
|
|
18
|
+
checked: boolean;
|
|
19
|
+
indeterminate: boolean;
|
|
20
|
+
onChange: () => void;
|
|
21
|
+
}) => ReactNode | ReactNode[]);
|
|
22
|
+
export interface CheckItemProps<K extends Key> {
|
|
23
|
+
value: K;
|
|
24
|
+
children?: CheckItemChildren;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
onChange?: (val: K) => void;
|
|
27
|
+
}
|
|
28
|
+
export {};
|