@_tc/template-core 0.0.1-bate.37 → 0.0.1-bate.39
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/cjs/bundler/utils.js +13 -5
- package/cjs/packages/core/index.js +1 -1
- package/cjs/packages/core/loader/config.js +4 -2
- package/cjs/packages/core/loader/controller.js +2 -3
- package/cjs/packages/core/loader/extend.js +1 -2
- package/cjs/packages/core/loader/middleware.js +2 -3
- package/cjs/packages/core/loader/model.js +7 -3
- package/cjs/packages/core/loader/router-schema.js +4 -2
- package/cjs/packages/core/loader/router.js +10 -6
- package/cjs/packages/core/loader/service.js +2 -2
- package/cjs/packages/utils/runFileFn.js +46 -1
- package/esm/bundler/utils.js +13 -5
- package/esm/packages/core/index.js +1 -2
- package/esm/packages/core/loader/config.js +4 -3
- package/esm/packages/core/loader/controller.js +2 -4
- package/esm/packages/core/loader/extend.js +1 -3
- package/esm/packages/core/loader/middleware.js +2 -4
- package/esm/packages/core/loader/model.js +7 -4
- package/esm/packages/core/loader/router-schema.js +4 -3
- package/esm/packages/core/loader/router.js +10 -7
- package/esm/packages/core/loader/service.js +2 -3
- package/esm/packages/utils/runFileFn.js +47 -1
- package/fe/frontend/dash/Dashboard.js +11 -1
- package/fe/frontend/dash/dash.entry.js +19 -1
- package/fe/frontend/main.js +2 -0
- package/fe/frontend/widgets/common/CRUD/CRUD.js +1 -0
- package/fe/frontend/widgets/common/importComponent.js +1 -0
- package/fe/frontend/widgets/common/language.js +1 -0
- package/fe/frontend/widgets/common/menu.d.ts +12 -0
- package/fe/frontend/widgets/common/menu.js +21 -0
- package/fe/frontend/widgets/common/request.d.ts +3 -0
- package/fe/frontend/widgets/common/request.js +6 -0
- package/fe/frontend/widgets/components/BasePage/HeaderView.js +3 -1
- package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/PopFrom.js +15 -0
- package/fe/frontend/widgets/defaultPages/Schema/components/SchemaSearch/index.js +5 -0
- package/fe/frontend/widgets/defaultPages/Schema/components/SchemaTable/index.js +13 -1
- package/fe/frontend/widgets/defaultPages/Schema/data/eventInfo.js +4 -4
- package/fe/frontend/widgets/defaultPages/Schema/index.js +7 -0
- package/fe/frontend/widgets/defaultPages/Schema/schemaType.d.ts +9 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.d.ts +19 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.js +4 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.d.ts +14 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.js +2 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/schemaConversion.js +43 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/validator.d.ts +3 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/validator.js +5 -0
- package/fe/frontend/widgets/defaultPages/SidebarSlotPage/SidebarSlotContainer.js +7 -0
- package/fe/frontend/widgets/defaultPages/SidebarSlotPage/index.js +1 -0
- package/fe/frontend/widgets/defaultPages/SlotPage/index.js +2 -0
- package/fe/frontend/widgets/hooks/useCurrentMenuData.d.ts +8 -0
- package/fe/frontend/widgets/hooks/useCurrentMenuData.js +8 -0
- package/fe/frontend/widgets/store/mode.d.ts +3 -0
- package/fe/frontend/widgets/store/mode.js +1 -0
- package/fe/model/types/data/button.d.ts +9 -0
- package/fe/model/types/data/button.js +15 -0
- package/fe/model/types/data/component.d.ts +24 -0
- package/fe/model/types/data/component.js +10 -0
- package/fe/model/types/data/fetchInfo.d.ts +12 -0
- package/fe/model/types/data/schema.d.ts +51 -0
- package/fe/model/types/menuType.d.ts +29 -0
- package/fe/model/types/model.d.ts +13 -0
- package/fe/packages/common/i18n/default.d.ts +5 -0
- package/fe/packages/common/i18n/default.js +5 -0
- package/fe/packages/common/i18n/en-US.d.ts +5 -0
- package/fe/packages/common/i18n/en-US.js +5 -0
- package/fe/packages/common/i18n/index.d.ts +24 -0
- package/fe/packages/common/i18n/index.js +31 -0
- package/fe/packages/common/i18n/types.d.ts +24 -0
- package/fe/packages/ui/react/components/Button/Button.d.ts +33 -0
- package/fe/packages/ui/react/components/Button/Button.js +3 -0
- package/fe/packages/ui/react/components/Button/SumbitButton.d.ts +4 -0
- package/fe/packages/ui/react/components/Button/SumbitButton.js +4 -0
- package/fe/packages/ui/react/components/ConfirmDialog/ConfirmDialog.d.ts +8 -0
- package/fe/packages/ui/react/components/DataTable/index.d.ts +19 -0
- package/fe/packages/ui/react/components/DataTable/index.js +4 -0
- package/fe/packages/ui/react/components/Date/Calendar.d.ts +13 -0
- package/fe/packages/ui/react/components/Date/Calendar.js +10 -1
- package/fe/packages/ui/react/components/Date/Date.d.ts +11 -0
- package/fe/packages/ui/react/components/Date/Date.js +19 -0
- package/fe/packages/ui/react/components/Date/LocaleContext.d.ts +4 -0
- package/fe/packages/ui/react/components/Date/LocaleContext.js +4 -0
- package/fe/packages/ui/react/components/Date/LocaleProvider.d.ts +11 -0
- package/fe/packages/ui/react/components/Date/LocaleProvider.js +11 -0
- package/fe/packages/ui/react/components/Date/TimePicker.js +1 -0
- package/fe/packages/ui/react/components/Date/dateLocaleStore.d.ts +6 -0
- package/fe/packages/ui/react/components/Date/locales.d.ts +19 -0
- package/fe/packages/ui/react/components/Date/locales.js +9 -0
- package/fe/packages/ui/react/components/Drawer/Drawer.d.ts +6 -0
- package/fe/packages/ui/react/components/Dropdown/Dropdown.d.ts +1 -0
- package/fe/packages/ui/react/components/Form/Form.d.ts +6 -0
- package/fe/packages/ui/react/components/Form/FormItem.d.ts +21 -0
- package/fe/packages/ui/react/components/Form/FormItem.js +8 -1
- package/fe/packages/ui/react/components/Form/SchemaForm/data.js +1 -0
- package/fe/packages/ui/react/components/Form/SchemaForm/index.d.ts +93 -0
- package/fe/packages/ui/react/components/Form/SchemaForm/index.js +5 -1
- package/fe/packages/ui/react/components/ImagePreview/ImagePreview.js +8 -0
- package/fe/packages/ui/react/components/ImagePreview/PreviewImage.d.ts +3 -0
- package/fe/packages/ui/react/components/Input/Input.d.ts +22 -0
- package/fe/packages/ui/react/components/Input/Input.js +3 -0
- package/fe/packages/ui/react/components/InputNumber/InputNumber.d.ts +2 -0
- package/fe/packages/ui/react/components/Label/Label.d.ts +29 -0
- package/fe/packages/ui/react/components/Label/Label.js +2 -0
- package/fe/packages/ui/react/components/Menu/Menu.js +4 -0
- package/fe/packages/ui/react/components/Menu/SubMenu.d.ts +7 -0
- package/fe/packages/ui/react/components/Menu/SubMenu.js +46 -1
- package/fe/packages/ui/react/components/Menu/menuTypes.d.ts +1 -0
- package/fe/packages/ui/react/components/Message/Message.d.ts +7 -0
- package/fe/packages/ui/react/components/Message/Message.js +3 -0
- package/fe/packages/ui/react/components/Message/MessageManager.js +8 -0
- package/fe/packages/ui/react/components/Modal/Modal.d.ts +6 -0
- package/fe/packages/ui/react/components/Modal/Modal.js +1 -0
- package/fe/packages/ui/react/components/Modal/ModalManager.d.ts +12 -0
- package/fe/packages/ui/react/components/Modal/ModalManager.js +4 -1
- package/fe/packages/ui/react/components/Overlay/Overlay.d.ts +3 -0
- package/fe/packages/ui/react/components/Pagination/Pagination.d.ts +7 -0
- package/fe/packages/ui/react/components/Pagination/Pagination.js +8 -1
- package/fe/packages/ui/react/components/Popup/Popup.js +14 -2
- package/fe/packages/ui/react/components/Search/Search.d.ts +3 -0
- package/fe/packages/ui/react/components/Select/Select.d.ts +5 -0
- package/fe/packages/ui/react/components/Select/Select.js +4 -0
- package/fe/packages/ui/react/components/Skeleton/Skeleton.d.ts +15 -0
- package/fe/packages/ui/react/components/Skeleton/Skeleton.js +1 -1
- package/fe/packages/ui/react/components/TableSearch/TableSearch.d.ts +37 -0
- package/fe/packages/ui/react/components/TableSearch/TableSearch.js +4 -1
- package/fe/packages/ui/react/components/Textarea/Textarea.d.ts +46 -0
- package/fe/packages/ui/react/components/Textarea/Textarea.js +1 -0
- package/fe/packages/ui/react/components/Tooltip/Tooltip.d.ts +16 -0
- package/fe/packages/ui/react/components/Tooltip/Tooltip.js +8 -0
- package/fe/packages/ui/react/components/TreeSelect/TreeSelect.d.ts +6 -0
- package/fe/packages/ui/react/components/TreeSelect/TreeSelect.js +6 -0
- package/fe/packages/ui/react/components/Upload/Upload.d.ts +27 -0
- package/fe/packages/ui/react/components/breadcrumb/breadcrumb.js +9 -0
- package/fe/packages/ui/react/components/hooks/useDropdownPositioning.d.ts +6 -0
- package/fe/packages/ui/react/components/hooks/useDropdownPositioning.js +14 -0
- package/fe/packages/ui/react/components/hooks/useInputController.d.ts +3 -0
- package/fe/packages/ui/react/components/hooks/useInputController.js +7 -0
- package/fe/packages/ui/react/components/testPage/MenuTestPage.js +3 -0
- package/fe/packages/ui/react/components/testPage/index.js +26 -0
- package/fe/packages/ui/react/hooks/useExecuteOnce.d.ts +19 -1
- package/fe/packages/ui/react/hooks/useExecuteOnce.js +22 -1
- package/fe/packages/ui/react/hooks/useRefState.d.ts +12 -0
- package/fe/packages/ui/react/hooks/useRefState.js +1 -0
- package/fe/packages/ui/react/hooks/useWatch.d.ts +8 -0
- package/fe/packages/ui/react/i18n/I18nProvider.d.ts +18 -0
- package/fe/packages/ui/react/i18n/useI18n.d.ts +4 -0
- package/fe/packages/ui/react/i18n/useI18n.js +4 -0
- package/fe/packages/ui/react/index.js +2 -0
- package/fe/packages/ui/react/lib/export.d.ts +44 -0
- package/fe/packages/ui/react/lib/export.js +40 -0
- package/fe/packages/ui/react/lib/utils.d.ts +24 -0
- package/fe/packages/ui/react/lib/utils.js +25 -0
- package/fe/packages/ui/react/stores/breadcrumb.js +2 -0
- package/model/index.d.ts +2 -0
- package/model/types/data/button.d.ts +32 -0
- package/model/types/data/component.d.ts +61 -0
- package/model/types/data/fetchInfo.d.ts +20 -0
- package/model/types/data/schema.d.ts +98 -0
- package/model/types/data/search.d.ts +7 -0
- package/model/types/index.d.ts +2 -0
- package/model/types/menuType.d.ts +73 -0
- package/model/types/model.d.ts +33 -0
- package/model/types/test.d.ts +2 -0
- package/package.json +10 -7
- package/types/packages/utils/runFileFn.d.ts +5 -3
|
@@ -9,6 +9,7 @@ const Button = forwardRef((props, ref) => {
|
|
|
9
9
|
const loading = loadingProp;
|
|
10
10
|
const disabled = disabledProp;
|
|
11
11
|
const isDisabled = disabled || loading;
|
|
12
|
+
// 基础样式
|
|
12
13
|
const baseStyles = 'inline-flex items-center justify-center rounded-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 cursor-pointer';
|
|
13
14
|
const getVariantStyles = () => {
|
|
14
15
|
if (variant === 'text' || variant === 'link') {
|
|
@@ -34,6 +35,7 @@ const Button = forwardRef((props, ref) => {
|
|
|
34
35
|
return cn(variantStyles[variant], ghostStyles);
|
|
35
36
|
};
|
|
36
37
|
const disabledStyles = 'disabled:bg-background/60 disabled:border-border/60 disabled:text-foreground/40 disabled:hover:bg-background/60 aria-disabled:text-foreground/40 aria-disabled:hover:bg-transparent';
|
|
38
|
+
// 尺寸样式
|
|
37
39
|
const sizeStyles = {
|
|
38
40
|
sm: 'h-8 px-3 text-sm',
|
|
39
41
|
md: 'h-10 px-4 text-sm',
|
|
@@ -45,6 +47,7 @@ const Button = forwardRef((props, ref) => {
|
|
|
45
47
|
lg: 'h-5 w-5',
|
|
46
48
|
};
|
|
47
49
|
const loadingIcon = loading ? (_jsx("span", { className: cn('flex items-center', children && 'mr-2'), children: _jsxs("svg", { className: cn('animate-spin', spinnerSize[size]), xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }) }, "loading")) : null;
|
|
50
|
+
// 展示内容
|
|
48
51
|
const contents = [
|
|
49
52
|
loadingIcon,
|
|
50
53
|
!loading && leftIcon && (_jsx("span", { className: cn('flex items-center', 'mr-2'), children: leftIcon }, "left")),
|
|
@@ -3,6 +3,10 @@ import { type ButtonElementProps } from './Button';
|
|
|
3
3
|
export type SumbitButtonProps = MOmit<ButtonElementProps, 'onClick'> & {
|
|
4
4
|
onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void | boolean> | void;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* 会自动添加loading 其余同button一致
|
|
9
|
+
*/
|
|
6
10
|
declare const SumbitButton: (props: SumbitButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
11
|
declare const AsynchronousButton: (props: SumbitButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
12
|
export { AsynchronousButton, SumbitButton };
|
|
@@ -2,6 +2,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { cn } from '../../lib/utils';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
import { Button } from './Button';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* 会自动添加loading 其余同button一致
|
|
8
|
+
*/
|
|
5
9
|
const SumbitButton = (props) => {
|
|
6
10
|
const { onClick, className, loading: loadingProp, ...bprops } = props;
|
|
7
11
|
const [loading, uLoading] = useState(false);
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
export interface ConfirmDialogProps {
|
|
2
|
+
/** 是否显示 */
|
|
2
3
|
open: boolean;
|
|
4
|
+
/** 标题 */
|
|
3
5
|
title?: string;
|
|
6
|
+
/** 内容 */
|
|
4
7
|
content: string;
|
|
8
|
+
/** 确认按钮文本 */
|
|
5
9
|
okText?: string;
|
|
10
|
+
/** 取消按钮文本 */
|
|
6
11
|
cancelText?: string;
|
|
12
|
+
/** 确认按钮加载状态 */
|
|
7
13
|
loading?: boolean;
|
|
14
|
+
/** 确认回调 */
|
|
8
15
|
onOk: () => void | Promise<void>;
|
|
16
|
+
/** 取消回调 */
|
|
9
17
|
onCancel: () => void;
|
|
10
18
|
}
|
|
11
19
|
export declare function ConfirmDialog({ open, title, content, okText, cancelText, loading, onOk, onCancel, }: ConfirmDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,10 +9,25 @@ type DataTableActionColumnOptions<T> = {
|
|
|
9
9
|
};
|
|
10
10
|
type TableColumnDef<T = Record<string, unknown>> = ColumnDef<T> & DataTableActionColumnOptions<T>;
|
|
11
11
|
type RowSelection<T> = {
|
|
12
|
+
/**
|
|
13
|
+
* 受控用法:完全由外部维护选中 keys
|
|
14
|
+
*/
|
|
12
15
|
selectedRowKeys?: Array<string | number>;
|
|
16
|
+
/**
|
|
17
|
+
* 非受控用法:仅作为初始值,后续由内部维护
|
|
18
|
+
*/
|
|
13
19
|
defaultSelectedRowKeys?: Array<string | number>;
|
|
20
|
+
/**
|
|
21
|
+
* 选中项变化回调(受控/非受控都会触发)
|
|
22
|
+
*/
|
|
14
23
|
onChange?: (selectedRowKeys: Array<string | number>, selectedRows: T[], isAll: boolean) => void;
|
|
24
|
+
/**
|
|
25
|
+
* 全选 受控
|
|
26
|
+
*/
|
|
15
27
|
isAll?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* theader checkbox
|
|
30
|
+
*/
|
|
16
31
|
beforeCheckboxNode?: ReactNode;
|
|
17
32
|
};
|
|
18
33
|
interface DataTableProps<T = Record<string, unknown>> {
|
|
@@ -22,6 +37,10 @@ interface DataTableProps<T = Record<string, unknown>> {
|
|
|
22
37
|
rowSelection?: RowSelection<T>;
|
|
23
38
|
pagination?: PaginationProps;
|
|
24
39
|
loading?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 统一配置 column width 默认100px
|
|
42
|
+
* 会被columns[number].width覆盖
|
|
43
|
+
*/
|
|
25
44
|
defaultColumnWidth?: number;
|
|
26
45
|
}
|
|
27
46
|
export declare function DataTable<T = Record<string, unknown>>({ columns, data: pData, loading, rowKey, rowSelection, defaultColumnWidth, pagination: pPagination, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -35,10 +35,12 @@ export function DataTable({ columns, data: pData, loading, rowKey = defaultRowKe
|
|
|
35
35
|
let data = pData;
|
|
36
36
|
let showPagination;
|
|
37
37
|
let pageStartIndex = 0;
|
|
38
|
+
// 使用外部
|
|
38
39
|
if (pPagination) {
|
|
39
40
|
pagination = pPagination;
|
|
40
41
|
showPagination = pagination.total > 0;
|
|
41
42
|
}
|
|
43
|
+
// 使用内部
|
|
42
44
|
else {
|
|
43
45
|
pagination = {
|
|
44
46
|
onChange(v) {
|
|
@@ -82,8 +84,10 @@ export function DataTable({ columns, data: pData, loading, rowKey = defaultRowKe
|
|
|
82
84
|
const pageKeySet = new Set(pageRowKeys);
|
|
83
85
|
nextSelectedKeys = Array.from(new Set([
|
|
84
86
|
...selectedRowKeys,
|
|
87
|
+
//
|
|
85
88
|
...pageRowKeys.filter((key) => !selectedKeySet.has(key)),
|
|
86
89
|
]))
|
|
90
|
+
//
|
|
87
91
|
.filter((key) => pageKeySet.has(key) || selectedKeySet.has(key));
|
|
88
92
|
}
|
|
89
93
|
else {
|
|
@@ -5,7 +5,13 @@ export type DateRange = {
|
|
|
5
5
|
to?: Date | undefined;
|
|
6
6
|
};
|
|
7
7
|
export type QuickRangePreset = {
|
|
8
|
+
/**
|
|
9
|
+
* 展示文案
|
|
10
|
+
*/
|
|
8
11
|
label: string;
|
|
12
|
+
/**
|
|
13
|
+
* 返回一个范围对象
|
|
14
|
+
*/
|
|
9
15
|
getRange: () => DateRange;
|
|
10
16
|
};
|
|
11
17
|
export interface CalendarProps {
|
|
@@ -15,7 +21,14 @@ export interface CalendarProps {
|
|
|
15
21
|
disabledDate?: (date: Date) => boolean;
|
|
16
22
|
showTime?: boolean;
|
|
17
23
|
className?: string;
|
|
24
|
+
/**
|
|
25
|
+
* 自定义文案配置,会覆盖默认文案
|
|
26
|
+
*/
|
|
18
27
|
locale?: Partial<DateLocaleConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* 范围模式下的快捷选择配置
|
|
30
|
+
* 不传则使用默认预设
|
|
31
|
+
*/
|
|
19
32
|
quickRanges?: QuickRangePreset[];
|
|
20
33
|
}
|
|
21
34
|
export declare function Calendar({ mode, value, onChange, disabledDate, showTime, className, locale: customLocale, quickRanges, }: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,7 +11,9 @@ import { TimePicker } from './TimePicker';
|
|
|
11
11
|
export function Calendar({ mode = ModeType.Single, value, onChange, disabledDate, showTime, className, locale: customLocale, quickRanges, }) {
|
|
12
12
|
const contextLocale = useDateLocale();
|
|
13
13
|
const locale = useMemo(() => ({ ...contextLocale, ...customLocale }), [contextLocale, customLocale]);
|
|
14
|
+
// Pending value for showTime mode (confirmed on button click)
|
|
14
15
|
const [pendingValue, setPendingValue] = useState(value ?? null);
|
|
16
|
+
// 当前显示的月份
|
|
15
17
|
const [currentMonth, setCurrentMonth] = useState(() => {
|
|
16
18
|
if (value instanceof Date)
|
|
17
19
|
return value;
|
|
@@ -19,7 +21,9 @@ export function Calendar({ mode = ModeType.Single, value, onChange, disabledDate
|
|
|
19
21
|
return value.from;
|
|
20
22
|
return new Date();
|
|
21
23
|
});
|
|
24
|
+
// 悬停日期(用于范围选择预览)
|
|
22
25
|
const [hoverDate, setHoverDate] = useState(null);
|
|
26
|
+
// 生成日历网格数据
|
|
23
27
|
const days = useMemo(() => {
|
|
24
28
|
const monthStart = startOfMonth(currentMonth);
|
|
25
29
|
const monthEnd = endOfMonth(monthStart);
|
|
@@ -107,6 +111,7 @@ export function Calendar({ mode = ModeType.Single, value, onChange, disabledDate
|
|
|
107
111
|
const handleDateClick = (date) => {
|
|
108
112
|
if (disabledDate?.(date))
|
|
109
113
|
return;
|
|
114
|
+
// Preserve time when showTime is enabled
|
|
110
115
|
let dateWithTime = date;
|
|
111
116
|
if (showTime && pendingValue instanceof Date) {
|
|
112
117
|
dateWithTime = new Date(date);
|
|
@@ -116,6 +121,7 @@ export function Calendar({ mode = ModeType.Single, value, onChange, disabledDate
|
|
|
116
121
|
dateWithTime.setMilliseconds(0);
|
|
117
122
|
}
|
|
118
123
|
if (showTime) {
|
|
124
|
+
// In showTime mode, store in pending value
|
|
119
125
|
if (mode === ModeType.Single) {
|
|
120
126
|
setPendingValue(dateWithTime);
|
|
121
127
|
}
|
|
@@ -135,6 +141,7 @@ export function Calendar({ mode = ModeType.Single, value, onChange, disabledDate
|
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
143
|
else {
|
|
144
|
+
// Without showTime, directly call onChange
|
|
138
145
|
if (mode === ModeType.Single) {
|
|
139
146
|
onChange?.(dateWithTime);
|
|
140
147
|
}
|
|
@@ -191,7 +198,9 @@ export function Calendar({ mode = ModeType.Single, value, onChange, disabledDate
|
|
|
191
198
|
const isCurrentMonth = isSameMonth(date, currentMonth);
|
|
192
199
|
const isDisabled = disabledDate?.(date);
|
|
193
200
|
return (_jsx("div", { className: "flex justify-center p-0", children: _jsx(Button, { variant: "text", type: "button", onClick: () => handleDateClick(date), onMouseEnter: () => setHoverDate(date), disabled: isDisabled, className: cn('w-8 h-8 flex items-center justify-center rounded text-sm transition-colors relative z-10', !isCurrentMonth && 'text-muted-foreground/40', isCurrentMonth && !selected && !inRange && !isDisabled && 'text-foreground hover:bg-muted', selected && 'bg-theme text-theme-foreground hover:bg-theme/90', inRange && !selected && 'bg-theme/10 text-theme', !selected && !inRange && isToday && 'border border-theme text-theme', isDisabled && 'text-muted-foreground cursor-not-allowed hover:bg-transparent opacity-50'), children: format(date, 'd') }) }, i));
|
|
194
|
-
}) })] }), showTime && (_jsx("div", { className: "flex flex-col border-l border-border pl-4", children: mode === ModeType.Single ? (_jsxs("div", { className: "flex flex-col justify-center h-full", children: [_jsx("div", { className: "text-xs font-medium text-muted-foreground mb-3 text-center", children: locale.selectTime }), _jsx(TimePicker, { value: pendingValue instanceof Date ? pendingValue : undefined, onChange: handleTimeChangeInternal, className: "border-0" })] })) : (
|
|
201
|
+
}) })] }), showTime && (_jsx("div", { className: "flex flex-col border-l border-border pl-4", children: mode === ModeType.Single ? (_jsxs("div", { className: "flex flex-col justify-center h-full", children: [_jsx("div", { className: "text-xs font-medium text-muted-foreground mb-3 text-center", children: locale.selectTime }), _jsx(TimePicker, { value: pendingValue instanceof Date ? pendingValue : undefined, onChange: handleTimeChangeInternal, className: "border-0" })] })) : (
|
|
202
|
+
// Range mode: show two time pickers
|
|
203
|
+
_jsxs("div", { className: "space-y-4 flex flex-col justify-center h-full", children: [_jsxs("div", { children: [_jsx("div", { className: "text-xs font-medium text-muted-foreground mb-2 text-center", children: locale.startTime }), _jsx(TimePicker, { value: pendingValue && 'from' in pendingValue && pendingValue.from ? pendingValue.from : undefined, onChange: (newDate) => {
|
|
195
204
|
const range = pendingValue;
|
|
196
205
|
setPendingValue({
|
|
197
206
|
from: newDate,
|
|
@@ -9,6 +9,9 @@ export type DatePickerProps = {
|
|
|
9
9
|
mode?: ModeType;
|
|
10
10
|
value?: DateValue;
|
|
11
11
|
defaultValue?: DateValue;
|
|
12
|
+
/**
|
|
13
|
+
* @default 'yyyy-MM-dd'
|
|
14
|
+
*/
|
|
12
15
|
format?: string;
|
|
13
16
|
placeholder?: string;
|
|
14
17
|
disabled?: boolean;
|
|
@@ -17,8 +20,16 @@ export type DatePickerProps = {
|
|
|
17
20
|
onChange?: (value?: DateChangeStrValue, date?: Dates) => void;
|
|
18
21
|
disabledDate?: (current: Date) => boolean;
|
|
19
22
|
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* 自定义文案配置,会覆盖默认文案
|
|
25
|
+
*/
|
|
20
26
|
locale?: Partial<DateLocaleConfig>;
|
|
27
|
+
/**
|
|
28
|
+
* 范围模式下的快捷选择配置
|
|
29
|
+
* 不传则使用默认预设
|
|
30
|
+
*/
|
|
21
31
|
quickRanges?: QuickRangePreset[];
|
|
32
|
+
/** 自定义弹出容器,不传则默认挂载到 document.body */
|
|
22
33
|
getPopupContainer?: () => HTMLElement;
|
|
23
34
|
};
|
|
24
35
|
declare const DatePicker: import("react").ForwardRefExoticComponent<DatePickerProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -29,6 +29,9 @@ const formatValue = (val, format) => {
|
|
|
29
29
|
const formatDateValue = (val, format) => {
|
|
30
30
|
if (!val)
|
|
31
31
|
return "";
|
|
32
|
+
/**
|
|
33
|
+
* 将 DateBaseValue 转为 yyyy-MM-dd | [yyyy-MM-dd, yyyy-MM-dd]
|
|
34
|
+
*/
|
|
32
35
|
if (val instanceof Date)
|
|
33
36
|
return formatDate(val, format);
|
|
34
37
|
if ("from" in val) {
|
|
@@ -43,6 +46,7 @@ const DatePicker = forwardRef((props, ref) => {
|
|
|
43
46
|
const isControlled = Object.prototype.hasOwnProperty.call(props, "value");
|
|
44
47
|
const contextLocale = useDateLocale();
|
|
45
48
|
const locale = { ...contextLocale, ...customLocale };
|
|
49
|
+
// 如果没有传入 placeholder,根据模式自动选择
|
|
46
50
|
const finalPlaceholder = placeholder ||
|
|
47
51
|
(showTime
|
|
48
52
|
? mode === ModeType.Range
|
|
@@ -51,15 +55,22 @@ const DatePicker = forwardRef((props, ref) => {
|
|
|
51
55
|
: mode === ModeType.Range
|
|
52
56
|
? locale.placeholderRange
|
|
53
57
|
: locale.placeholder);
|
|
58
|
+
// Auto-adjust format based on showTime
|
|
54
59
|
const format = customFormat || (showTime ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd");
|
|
55
60
|
const { value, defaultValue } = useMemo(() => {
|
|
61
|
+
/**
|
|
62
|
+
* 将 DateChangeStrValue 转为 Dates
|
|
63
|
+
*/
|
|
56
64
|
const convertValue = (val) => {
|
|
57
65
|
if (!val)
|
|
58
66
|
return undefined;
|
|
67
|
+
// Already a Date object
|
|
59
68
|
if (val instanceof Date)
|
|
60
69
|
return val;
|
|
70
|
+
// Already a DateRange object
|
|
61
71
|
if (typeof val === "object" && "from" in val)
|
|
62
72
|
return val;
|
|
73
|
+
// String value - single date
|
|
63
74
|
if (typeof val === "string") {
|
|
64
75
|
try {
|
|
65
76
|
const parsed = parse(val, format, new Date());
|
|
@@ -69,7 +80,9 @@ const DatePicker = forwardRef((props, ref) => {
|
|
|
69
80
|
return undefined;
|
|
70
81
|
}
|
|
71
82
|
}
|
|
83
|
+
// date range
|
|
72
84
|
if (Array.isArray(val)) {
|
|
85
|
+
// string
|
|
73
86
|
if (typeof val[0] === "string" && typeof val[1] === "string") {
|
|
74
87
|
try {
|
|
75
88
|
const from = parse(val[0], format, new Date());
|
|
@@ -109,6 +122,7 @@ const DatePicker = forwardRef((props, ref) => {
|
|
|
109
122
|
matchAnchorWidth: false,
|
|
110
123
|
strategy: getDatePickerDropdownPosition,
|
|
111
124
|
});
|
|
125
|
+
// 同步外部 value 变化
|
|
112
126
|
useEffect(() => {
|
|
113
127
|
if (!isControlled)
|
|
114
128
|
return;
|
|
@@ -124,13 +138,17 @@ const DatePicker = forwardRef((props, ref) => {
|
|
|
124
138
|
const handleSelect = (date) => {
|
|
125
139
|
const newDate = date;
|
|
126
140
|
if (mode === ModeType.Range) {
|
|
141
|
+
// 如果是范围选择,只有当 from 和 to 都存在时才关闭
|
|
127
142
|
if (date && "from" in date && "to" in date && date.from && date.to) {
|
|
128
143
|
setIsOpen(false);
|
|
129
144
|
}
|
|
130
145
|
}
|
|
131
146
|
else {
|
|
147
|
+
// Single mode: always close popup when onChange is triggered
|
|
148
|
+
// (In showTime mode, this only happens when user clicks confirm button)
|
|
132
149
|
setIsOpen(false);
|
|
133
150
|
}
|
|
151
|
+
// range 选择需要保留内部草稿态,避免受控 value 把第一步点击抹掉
|
|
134
152
|
if (mode === ModeType.Range || !isControlled) {
|
|
135
153
|
setSelectedDate(newDate);
|
|
136
154
|
setInputValue(formatValue(newDate, format));
|
|
@@ -164,6 +182,7 @@ const DatePicker = forwardRef((props, ref) => {
|
|
|
164
182
|
}
|
|
165
183
|
}
|
|
166
184
|
catch {
|
|
185
|
+
// ignore invalid date
|
|
167
186
|
}
|
|
168
187
|
}
|
|
169
188
|
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { useDateLocaleStore } from './dateLocaleStore';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing the current Date component locale.
|
|
4
|
+
* Backed by Zustand, so no React Context is required.
|
|
5
|
+
*/
|
|
2
6
|
export const useDateLocale = () => {
|
|
3
7
|
return useDateLocaleStore((state) => state.locale);
|
|
4
8
|
};
|
|
@@ -4,5 +4,16 @@ export interface DateLocaleProviderProps {
|
|
|
4
4
|
locale?: DateLocaleConfig;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Date 组件文案配置 Provider
|
|
9
|
+
* 用于全局设置 Date 组件的文案
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <DateLocaleProvider locale={customLocale}>
|
|
14
|
+
* <App />
|
|
15
|
+
* </DateLocaleProvider>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
7
18
|
export declare function DateLocaleProvider({ locale, children }: DateLocaleProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
8
19
|
//# sourceMappingURL=LocaleProvider.d.ts.map
|
|
@@ -2,6 +2,17 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import { useDateLocaleStore } from './dateLocaleStore';
|
|
4
4
|
import { defaultLocale } from './locales';
|
|
5
|
+
/**
|
|
6
|
+
* Date 组件文案配置 Provider
|
|
7
|
+
* 用于全局设置 Date 组件的文案
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <DateLocaleProvider locale={customLocale}>
|
|
12
|
+
* <App />
|
|
13
|
+
* </DateLocaleProvider>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
5
16
|
export function DateLocaleProvider({ locale = defaultLocale, children }) {
|
|
6
17
|
const replaceLocale = useDateLocaleStore((state) => state.replaceLocale);
|
|
7
18
|
const resetLocale = useDateLocaleStore((state) => state.resetLocale);
|
|
@@ -4,6 +4,7 @@ import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
|
4
4
|
import { Button } from '../Button';
|
|
5
5
|
import { Input } from '../Input';
|
|
6
6
|
export function TimePicker({ value, onChange, className }) {
|
|
7
|
+
// Derive time from value prop directly
|
|
7
8
|
const hours = value?.getHours() ?? 0;
|
|
8
9
|
const minutes = value?.getMinutes() ?? 0;
|
|
9
10
|
const handleTimeChange = (newHours, newMinutes) => {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { type DateLocaleConfig } from './locales';
|
|
2
2
|
type DateLocaleState = {
|
|
3
3
|
locale: DateLocaleConfig;
|
|
4
|
+
/**
|
|
5
|
+
* Merge partial updates into the current locale.
|
|
6
|
+
*/
|
|
4
7
|
setLocale: (patch: Partial<DateLocaleConfig>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Replace the locale entirely.
|
|
10
|
+
*/
|
|
5
11
|
replaceLocale: (nextLocale: DateLocaleConfig) => void;
|
|
6
12
|
resetLocale: () => void;
|
|
7
13
|
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date 组件文案配置
|
|
3
|
+
* 支持外部修改文案内容
|
|
4
|
+
*/
|
|
1
5
|
export interface DateLocaleConfig {
|
|
2
6
|
placeholder: string;
|
|
3
7
|
placeholderDateTime: string;
|
|
@@ -9,7 +13,13 @@ export interface DateLocaleConfig {
|
|
|
9
13
|
endTime: string;
|
|
10
14
|
confirm: string;
|
|
11
15
|
monthFormat: string;
|
|
16
|
+
/**
|
|
17
|
+
* 范围模式 - 快捷选择面板标题
|
|
18
|
+
*/
|
|
12
19
|
quickRanges: string;
|
|
20
|
+
/**
|
|
21
|
+
* 范围模式 - 各快捷范围文案
|
|
22
|
+
*/
|
|
13
23
|
quickRangeToday: string;
|
|
14
24
|
quickRangeYesterday: string;
|
|
15
25
|
quickRangeLast7Days: string;
|
|
@@ -18,7 +28,16 @@ export interface DateLocaleConfig {
|
|
|
18
28
|
quickRangeLastYear: string;
|
|
19
29
|
clear: string;
|
|
20
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* 默认中文文案
|
|
33
|
+
*/
|
|
21
34
|
export declare const zhCNLocale: DateLocaleConfig;
|
|
35
|
+
/**
|
|
36
|
+
* 默认英文文案
|
|
37
|
+
*/
|
|
22
38
|
export declare const enUSLocale: DateLocaleConfig;
|
|
39
|
+
/**
|
|
40
|
+
* 默认使用中文文案
|
|
41
|
+
*/
|
|
23
42
|
export declare const defaultLocale: DateLocaleConfig;
|
|
24
43
|
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { defaultEnglishResources, defaultLanguageResources } from '../../../../common/i18n';
|
|
2
2
|
const dateDefaultLocale = defaultLanguageResources.components.date;
|
|
3
3
|
const dateDefaultEnglishLocale = defaultEnglishResources.components.date;
|
|
4
|
+
/**
|
|
5
|
+
* 默认中文文案
|
|
6
|
+
*/
|
|
4
7
|
export const zhCNLocale = {
|
|
5
8
|
...dateDefaultLocale,
|
|
6
9
|
weekDays: [...dateDefaultLocale.weekDays],
|
|
7
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* 默认英文文案
|
|
13
|
+
*/
|
|
8
14
|
export const enUSLocale = {
|
|
9
15
|
...dateDefaultEnglishLocale,
|
|
10
16
|
weekDays: [...dateDefaultEnglishLocale.weekDays],
|
|
11
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* 默认使用中文文案
|
|
20
|
+
*/
|
|
12
21
|
export const defaultLocale = zhCNLocale;
|
|
@@ -16,7 +16,13 @@ export type DrawerProps = {
|
|
|
16
16
|
width?: number | string;
|
|
17
17
|
height?: number | string;
|
|
18
18
|
zIndex?: number;
|
|
19
|
+
/**
|
|
20
|
+
* @default document.body
|
|
21
|
+
*/
|
|
19
22
|
renderNode?: HTMLElement | (() => HTMLElement);
|
|
23
|
+
/**
|
|
24
|
+
* 是否支持键盘关闭 默认开启
|
|
25
|
+
*/
|
|
20
26
|
keyboard?: boolean;
|
|
21
27
|
};
|
|
22
28
|
export declare function Drawer({ open, onClose, title, children, footer, className, contentClassName, mask, maskClosable, lockScroll, closable, placement, width, height, renderNode, keyboard, zIndex, }: DrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -18,6 +18,7 @@ export interface DropdownProps {
|
|
|
18
18
|
children: ReactNode;
|
|
19
19
|
className?: string;
|
|
20
20
|
placement?: 'bottom-end' | 'bottom-start';
|
|
21
|
+
/** 自定义弹出容器,不传则默认挂载到 document.body */
|
|
21
22
|
getPopupContainer?: () => HTMLElement;
|
|
22
23
|
}
|
|
23
24
|
export declare function Dropdown({ items, children, className, placement, getPopupContainer }: DropdownProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { FormProps as RcFormProps } from 'rc-field-form';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
export interface FormProps<T> extends Omit<RcFormProps<T>, 'component'> {
|
|
4
|
+
/**
|
|
5
|
+
* 表单类名
|
|
6
|
+
*/
|
|
4
7
|
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 表单内容
|
|
10
|
+
*/
|
|
5
11
|
children?: ReactNode;
|
|
6
12
|
}
|
|
7
13
|
declare const Form: {
|
|
@@ -3,15 +3,36 @@ import type { ReactNode } from 'react';
|
|
|
3
3
|
import { type LabelLayout } from '../Label';
|
|
4
4
|
type FieldProps = Parameters<typeof Field>[0];
|
|
5
5
|
export interface FormItemProps<T = any> extends Omit<FieldProps, 'children'> {
|
|
6
|
+
/**
|
|
7
|
+
* 表单项类名
|
|
8
|
+
*/
|
|
6
9
|
className?: string;
|
|
10
|
+
/**
|
|
11
|
+
* 标签文本
|
|
12
|
+
*/
|
|
7
13
|
label?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* 标签类名
|
|
16
|
+
*/
|
|
8
17
|
labelClassName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 是否必填(仅用于显示,实际验证通过 rules 配置)
|
|
20
|
+
*/
|
|
9
21
|
required?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 表单项内容
|
|
24
|
+
*/
|
|
10
25
|
children?: ReactNode | ((value: T, onChange: (value: T) => void, meta: {
|
|
11
26
|
errors: string[];
|
|
12
27
|
warnings: string[];
|
|
13
28
|
}) => ReactNode);
|
|
29
|
+
/**
|
|
30
|
+
* 错误信息类名
|
|
31
|
+
*/
|
|
14
32
|
errorClassName?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 是否显示错误信息
|
|
35
|
+
*/
|
|
15
36
|
showError?: boolean;
|
|
16
37
|
layout?: Required<LabelLayout>['layout'];
|
|
17
38
|
}
|
|
@@ -4,23 +4,30 @@ import { Field } from 'rc-field-form';
|
|
|
4
4
|
import React, { forwardRef } from 'react';
|
|
5
5
|
import Label from '../Label';
|
|
6
6
|
const FormItemFN = forwardRef(({ className, label, labelClassName, required, children, errorClassName, showError = true, name, rules, layout, ...props }, ref) => {
|
|
7
|
-
return (_jsx(Field, { name: name, rules: rules, ...props, children: (control, meta) => {
|
|
7
|
+
return (_jsx(Field, { name: name, rules: rules, ...props, children: (control, meta /** form */) => {
|
|
8
8
|
const { value, onChange, ...restControl } = control;
|
|
9
9
|
const { errors, warnings } = meta;
|
|
10
10
|
const hasError = errors.length > 0;
|
|
11
11
|
const hasWarning = warnings.length > 0;
|
|
12
|
+
// 如果 children 是函数,调用它并传入 value、onChange 和 meta
|
|
12
13
|
const childNode = typeof children === 'function' ? children(value, onChange, meta) : children;
|
|
14
|
+
// 克隆子元素并注入 value 和 onChange
|
|
13
15
|
const childWithProps = childNode && typeof childNode === 'object' && 'props' in childNode
|
|
14
16
|
? React.cloneElement(childNode, {
|
|
15
17
|
value: value,
|
|
16
18
|
onChange: (val) => {
|
|
19
|
+
// 兼容 Input 组件的 onChange(value, event) 格式
|
|
20
|
+
// Input 组件的 onChange 签名是: (value: string, event: ChangeEvent) => void
|
|
17
21
|
if (typeof val === 'string') {
|
|
22
|
+
// 如果第一个参数是字符串,说明是 Input 组件的格式
|
|
18
23
|
onChange(val);
|
|
19
24
|
}
|
|
20
25
|
else if (val?.target?.value !== undefined) {
|
|
26
|
+
// 原生 input 的 onChange 事件格式
|
|
21
27
|
onChange(val.target.value);
|
|
22
28
|
}
|
|
23
29
|
else {
|
|
30
|
+
// 其他情况直接使用值
|
|
24
31
|
onChange(val);
|
|
25
32
|
}
|
|
26
33
|
},
|
|
@@ -9,6 +9,7 @@ const baseComponentsMap = {
|
|
|
9
9
|
date: React.lazy(async () => ({ default: (await import('../../Date')).DatePicker })),
|
|
10
10
|
checkbox: React.lazy(async () => ({ default: (await import('../../Checkbox')).Checkbox })),
|
|
11
11
|
};
|
|
12
|
+
// componentsMap 合并内置 + 业务层扩展,支持动态注册新字段类型
|
|
12
13
|
export const componentsMap = {
|
|
13
14
|
...baseComponentsMap,
|
|
14
15
|
...businessComponentsMap,
|