@canlooks/can-ui 0.0.181 → 0.0.183
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/dist/cjs/components/clickAway/clickAway.d.ts +1 -1
- package/dist/cjs/components/clickAway/clickAway.js +2 -2
- package/dist/cjs/components/curd/curd.d.ts +5 -2
- package/dist/cjs/components/curd/curd.js +3 -3
- package/dist/cjs/components/curd/curdColumnConfig.d.ts +2 -0
- package/dist/cjs/components/curd/curdColumnConfig.js +3 -2
- package/dist/cjs/components/curd/curdResizable.d.ts +3 -1
- package/dist/cjs/components/curd/curdResizable.js +2 -2
- package/dist/cjs/components/dataGrid/dataGridHead.js +0 -1
- package/dist/cjs/components/dateTimeRangePicker/dateTimeRangePicker.js +4 -2
- package/dist/cjs/components/overlayBase/overlayBase.d.ts +1 -1
- package/dist/cjs/components/popper/popper.js +110 -97
- package/dist/cjs/components/popper/popper.style.d.ts +1 -1
- package/dist/cjs/components/popper/popper.style.js +28 -22
- package/dist/cjs/components/snackbarBase/snackbarBase.d.ts +1 -1
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/utils/hooks.d.ts +1 -1
- package/dist/cjs/utils/hooks.js +4 -2
- package/dist/cjs/utils/utils.d.ts +0 -5
- package/dist/cjs/utils/utils.js +0 -13
- package/dist/esm/components/clickAway/clickAway.d.ts +1 -1
- package/dist/esm/components/clickAway/clickAway.js +2 -2
- package/dist/esm/components/curd/curd.d.ts +5 -2
- package/dist/esm/components/curd/curd.js +3 -3
- package/dist/esm/components/curd/curdColumnConfig.d.ts +2 -0
- package/dist/esm/components/curd/curdColumnConfig.js +3 -2
- package/dist/esm/components/curd/curdResizable.d.ts +3 -1
- package/dist/esm/components/curd/curdResizable.js +2 -2
- package/dist/esm/components/dataGrid/dataGridHead.js +0 -1
- package/dist/esm/components/dateTimeRangePicker/dateTimeRangePicker.js +4 -2
- package/dist/esm/components/overlayBase/overlayBase.d.ts +1 -1
- package/dist/esm/components/popper/popper.js +110 -97
- package/dist/esm/components/popper/popper.style.d.ts +1 -1
- package/dist/esm/components/popper/popper.style.js +28 -22
- package/dist/esm/components/snackbarBase/snackbarBase.d.ts +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/utils/hooks.d.ts +1 -1
- package/dist/esm/utils/hooks.js +4 -2
- package/dist/esm/utils/utils.d.ts +0 -5
- package/dist/esm/utils/utils.js +0 -12
- package/package.json +1 -1
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -9,7 +9,6 @@ exports.cloneDeep = cloneDeep;
|
|
|
9
9
|
exports.mergeDeep = mergeDeep;
|
|
10
10
|
exports.arrayShallowEqual = arrayShallowEqual;
|
|
11
11
|
exports.isElementOverflowed = isElementOverflowed;
|
|
12
|
-
exports.nextTick = nextTick;
|
|
13
12
|
exports.cloneRef = cloneRef;
|
|
14
13
|
exports.isUnset = isUnset;
|
|
15
14
|
exports.isPromise = isPromise;
|
|
@@ -184,18 +183,6 @@ function isElementOverflowed(target, container) {
|
|
|
184
183
|
const vHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
185
184
|
return judge({ left: 0, top: 0, right: vWidth, bottom: vHeight });
|
|
186
185
|
}
|
|
187
|
-
/**
|
|
188
|
-
* 下一个事件循环
|
|
189
|
-
* @param callback
|
|
190
|
-
*/
|
|
191
|
-
function nextTick(callback) {
|
|
192
|
-
return new Promise(resolve => {
|
|
193
|
-
queueMicrotask(() => {
|
|
194
|
-
callback?.();
|
|
195
|
-
resolve();
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
186
|
/**
|
|
200
187
|
* 克隆Ref
|
|
201
188
|
* @param refs
|
|
@@ -8,7 +8,7 @@ export interface ClickAwayProps extends DivProps {
|
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
children?: ReactElement<any>;
|
|
10
10
|
/** 用于参考的目标元素,若为数组,需要点击数组外的元素才会触发clickAway */
|
|
11
|
-
targets?: () => Element | undefined | (Element | undefined)[];
|
|
11
|
+
targets?: () => Element | null | undefined | (Element | null | undefined)[];
|
|
12
12
|
}
|
|
13
13
|
export declare function ClickAway({ ref, container, eventType, onClickAway, disabled, children, targets, ...props }: ClickAwayProps): ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").FunctionComponentElement<{
|
|
14
14
|
ref: (ref: Element | null) => void;
|
|
@@ -21,9 +21,9 @@ export function ClickAway({ ref, container = self, eventType = 'click', onClickA
|
|
|
21
21
|
};
|
|
22
22
|
const containerEl = typeof container === 'function' ? container() : container;
|
|
23
23
|
const standardEventType = eventType.toLowerCase().replace(/^on/, '');
|
|
24
|
-
containerEl
|
|
24
|
+
containerEl?.addEventListener(standardEventType, onClick);
|
|
25
25
|
return () => {
|
|
26
|
-
containerEl
|
|
26
|
+
containerEl?.removeEventListener(standardEventType, onClick);
|
|
27
27
|
};
|
|
28
28
|
}, [disabled]);
|
|
29
29
|
return !disabled && isValidElement(children)
|
|
@@ -7,6 +7,7 @@ import { FieldPath } from '../../utils/index.js';
|
|
|
7
7
|
import { ButtonProps } from '../button/index.js';
|
|
8
8
|
import { CurdDialogProps } from './curdDialog.js';
|
|
9
9
|
import { BubbleConfirmProps } from '../bubbleConfirm/index.js';
|
|
10
|
+
import { BubbleProps } from '../bubble/index.js';
|
|
10
11
|
export type CurdFormItemProps<I = any> = FormItemProps<I> & {
|
|
11
12
|
/** 对filter或form内的字段单独排序,数字越大越靠后,默认为`0` */
|
|
12
13
|
order?: number;
|
|
@@ -61,6 +62,8 @@ export interface CurdBaseProps<R extends RowType = RowType, F extends FormValue
|
|
|
61
62
|
reloadable?: boolean;
|
|
62
63
|
onReload?(): void;
|
|
63
64
|
resizable?: boolean;
|
|
65
|
+
defaultSize?: Size;
|
|
66
|
+
onSizeChange?(size: Size): void;
|
|
64
67
|
columnConfigurable?: boolean | {
|
|
65
68
|
defaultVisible?: Id[];
|
|
66
69
|
visible?: Id[];
|
|
@@ -69,8 +72,8 @@ export interface CurdBaseProps<R extends RowType = RowType, F extends FormValue
|
|
|
69
72
|
order?: Id[];
|
|
70
73
|
onOrderChange?(order: Id[]): void;
|
|
71
74
|
};
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
resizeBubbleProps?: BubbleProps;
|
|
76
|
+
columnConfigBubbleProps?: BubbleProps;
|
|
74
77
|
filterableProps?: Omit<CurdFilterableProps, 'columns'>;
|
|
75
78
|
renderFilterable?(filterableProps: CurdFilterableProps): ReactNode;
|
|
76
79
|
renderFilterConditions?: CurdFilterableProps['renderFilterConditions'];
|
|
@@ -21,7 +21,7 @@ import { faPenToSquare } from '@fortawesome/free-regular-svg-icons/faPenToSquare
|
|
|
21
21
|
import { faPlus } from '@fortawesome/free-solid-svg-icons/faPlus';
|
|
22
22
|
import { faRotateRight } from '@fortawesome/free-solid-svg-icons/faRotateRight';
|
|
23
23
|
export const Curd = memo((props) => {
|
|
24
|
-
const { ref, wrapperProps, variant = 'standard', loadRows, onLoad, columns, toolbarLeft, toolbarRight, reloadable = true, onReload, resizable = true,
|
|
24
|
+
const { ref, wrapperProps, variant = 'standard', loadRows, onLoad, columns, toolbarLeft, toolbarRight, reloadable = true, onReload, resizable = true, defaultSize = 'medium', onSizeChange, columnConfigurable = true, resizeBubbleProps, columnConfigBubbleProps, filterProps, initialFilterValue, onFilter, filterableProps, renderFilterable, renderFilterConditions, copyable, creatable = true, updatable = true, deletable = true, createButtonProps, updateButtonProps, deleteButtonProps, deleteConfirmProps, controlColumnTitle = '操作', renderExtraControl, titleKey, dataName = '', createName = '添加', updateName = '编辑', deleteName = '删除', onCreate, onUpdate, onDelete, rowToForm, dialogProps, formProps, formRef, onChange, ...dataGridProps } = props;
|
|
25
25
|
/**
|
|
26
26
|
* -------------------------------------------------------------
|
|
27
27
|
* ref
|
|
@@ -245,8 +245,8 @@ export const Curd = memo((props) => {
|
|
|
245
245
|
_jsxs(Button, { prefix: _jsx(Icon, { icon: faPlus }), ...createButtonProps, onClick: createHandler, children: [createName, dataName] }), toolbarLeft] }), _jsxs("div", { className: classes.toolbarRight, children: [!!toolbarRight &&
|
|
246
246
|
_jsxs(_Fragment, { children: [toolbarRight, _jsx(Divider, { className: classes.divider, orientation: "vertical" })] }), reloadable &&
|
|
247
247
|
_jsx(Tooltip, { title: "\u5237\u65B0", children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", prefix: _jsx(Icon, { icon: faRotateRight }), loading: innerLoading.current, onClick: reloadHandler }) }), resizable &&
|
|
248
|
-
_jsx(CurdResizable, { innerSize: innerSize.current, setInnerSize: setInnerSize }), columnConfigurable &&
|
|
249
|
-
_jsx(CurdColumnConfig, { columns: orderedColumns, innerVisible: innerVisible.current, setInnerVisible: setInnerVisible, setInnerOrder: setInnerOrder })] })] }), _jsx("div", { className: classes.card, children: _jsx(DataGrid, { ...dataGridProps, slotProps: {
|
|
248
|
+
_jsx(CurdResizable, { innerSize: innerSize.current, setInnerSize: setInnerSize, resizeBubbleProps: resizeBubbleProps }), columnConfigurable &&
|
|
249
|
+
_jsx(CurdColumnConfig, { columns: orderedColumns, innerVisible: innerVisible.current, setInnerVisible: setInnerVisible, setInnerOrder: setInnerOrder, columnConfigBubbleProps: columnConfigBubbleProps })] })] }), _jsx("div", { className: classes.card, children: _jsx(DataGrid, { ...dataGridProps, slotProps: {
|
|
250
250
|
container: { ref: cloneRef(containerRef, dataGridProps?.slotProps?.container?.ref) }
|
|
251
251
|
}, tableProps: {
|
|
252
252
|
...props.tableProps,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dispatch, ReactElement, SetStateAction } from 'react';
|
|
2
|
+
import { BubbleProps } from '../bubble/index.js';
|
|
2
3
|
import { CurdColumn } from './curd.js';
|
|
3
4
|
import { RowType } from '../dataGrid/index.js';
|
|
4
5
|
import { Id } from '../../types.js';
|
|
@@ -7,5 +8,6 @@ export type CurdColumnConfigProps<R extends RowType> = {
|
|
|
7
8
|
innerVisible: Id[] | undefined;
|
|
8
9
|
setInnerVisible: Dispatch<SetStateAction<Id[] | undefined>>;
|
|
9
10
|
setInnerOrder: Dispatch<SetStateAction<Id[] | undefined>>;
|
|
11
|
+
columnConfigBubbleProps?: BubbleProps;
|
|
10
12
|
};
|
|
11
13
|
export declare const CurdColumnConfig: <R extends RowType>(props: CurdColumnConfigProps<R>) => ReactElement;
|
|
@@ -17,7 +17,7 @@ export const CurdColumnConfig = memo((props) => {
|
|
|
17
17
|
};
|
|
18
18
|
return (_jsx(DragDropProvider, { sensors: defaultSensors, onDragEnd: dragEndHandler, children: _jsx(CurdColumnConfigContent, { ...props }) }));
|
|
19
19
|
});
|
|
20
|
-
const CurdColumnConfigContent = memo(({ columns, innerVisible, setInnerVisible }) => {
|
|
20
|
+
const CurdColumnConfigContent = memo(({ columns, innerVisible, setInnerVisible, columnConfigBubbleProps }) => {
|
|
21
21
|
const isDragging = useRef(false);
|
|
22
22
|
useDragDropMonitor({
|
|
23
23
|
onDragStart: () => isDragging.current = true,
|
|
@@ -25,6 +25,7 @@ const CurdColumnConfigContent = memo(({ columns, innerVisible, setInnerVisible }
|
|
|
25
25
|
});
|
|
26
26
|
const [open, setOpen] = useState(false);
|
|
27
27
|
const openChangeHandler = (open) => {
|
|
28
|
+
columnConfigBubbleProps?.onOpenChange?.(open);
|
|
28
29
|
if (open || !isDragging.current) {
|
|
29
30
|
setOpen(open);
|
|
30
31
|
}
|
|
@@ -37,7 +38,7 @@ const CurdColumnConfigContent = memo(({ columns, innerVisible, setInnerVisible }
|
|
|
37
38
|
? [...o, key]
|
|
38
39
|
: o.filter(k => k !== key));
|
|
39
40
|
};
|
|
40
|
-
return (_jsx(Bubble, {
|
|
41
|
+
return (_jsx(Bubble, { placement: "bottomRight", trigger: ['hover', 'click'], ...columnConfigBubbleProps, css: style, open: open, onOpenChange: openChangeHandler, content: _jsxs("div", { className: classes.content, children: [_jsxs("div", { className: classes.title, children: [_jsx("div", { className: classes.titleText, children: "\u5217\u8BBE\u7F6E" }), _jsx("div", { className: classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => {
|
|
41
42
|
const id = col._key;
|
|
42
43
|
const checked = !isUnset(id) && (!visibleSet || visibleSet.has(id));
|
|
43
44
|
return (_jsx(SortableItem, { id: id ?? i, index: i, component: MenuItem, className: classes.item, prefix: _jsx(Checkbox, { className: classes.checkbox, checked: checked, onChange: e => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { BubbleProps } from '../bubble/index.js';
|
|
2
3
|
import { Size } from '../../types.js';
|
|
3
|
-
export declare const CurdResizable: import("react").MemoExoticComponent<({ innerSize, setInnerSize }: {
|
|
4
|
+
export declare const CurdResizable: import("react").MemoExoticComponent<({ innerSize, setInnerSize, resizeBubbleProps }: {
|
|
4
5
|
innerSize: Size;
|
|
5
6
|
setInnerSize: Dispatch<SetStateAction<Size>>;
|
|
7
|
+
resizeBubbleProps?: BubbleProps;
|
|
6
8
|
}) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
@@ -6,6 +6,6 @@ import { MenuItem } from '../menuItem/index.js';
|
|
|
6
6
|
import { Button } from '../button/index.js';
|
|
7
7
|
import { Icon } from '../icon/index.js';
|
|
8
8
|
import { faArrowsUpDown } from '@fortawesome/free-solid-svg-icons/faArrowsUpDown';
|
|
9
|
-
export const CurdResizable = memo(({ innerSize, setInnerSize }) => {
|
|
10
|
-
return (_jsx(Tooltip, { title: "\u8868\u683C\u5C3A\u5BF8", clickToClose: true, children: _jsx(Bubble, { placement: "bottom", trigger: "click", content: _jsxs(_Fragment, { children: [_jsx(MenuItem, { value: "small", label: "\u5C0F", selected: innerSize === 'small', onClick: () => setInnerSize('small') }), _jsx(MenuItem, { value: "medium", label: "\u4E2D", selected: innerSize === 'medium', onClick: () => setInnerSize('medium') }), _jsx(MenuItem, { value: "large", label: "\u5927", selected: innerSize === 'large', onClick: () => setInnerSize('large') })] }), children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", children: _jsx(Icon, { icon: faArrowsUpDown }) }) }) }));
|
|
9
|
+
export const CurdResizable = memo(({ innerSize, setInnerSize, resizeBubbleProps }) => {
|
|
10
|
+
return (_jsx(Tooltip, { title: "\u8868\u683C\u5C3A\u5BF8", clickToClose: true, children: _jsx(Bubble, { placement: "bottom", trigger: "click", ...resizeBubbleProps, content: _jsxs(_Fragment, { children: [_jsx(MenuItem, { value: "small", label: "\u5C0F", selected: innerSize === 'small', onClick: () => setInnerSize('small') }), _jsx(MenuItem, { value: "medium", label: "\u4E2D", selected: innerSize === 'medium', onClick: () => setInnerSize('medium') }), _jsx(MenuItem, { value: "large", label: "\u5927", selected: innerSize === 'large', onClick: () => setInnerSize('large') })] }), children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", children: _jsx(Icon, { icon: faArrowsUpDown }) }) }) }));
|
|
11
11
|
});
|
|
@@ -104,7 +104,6 @@ export const DataGridHead = memo(({ allowSelectAll, columnResizable, flattedColu
|
|
|
104
104
|
: _jsx(Bubble, { ...mergeComponentProps({
|
|
105
105
|
style: { maxWidth: 360 },
|
|
106
106
|
trigger: 'click',
|
|
107
|
-
placement: 'bottomRight',
|
|
108
107
|
autoClose: false,
|
|
109
108
|
content: (_jsx(FilterBubbleContent, { columnKey: _key, columnFilterProps: filter })),
|
|
110
109
|
onClick: e => e.stopPropagation()
|
|
@@ -37,8 +37,10 @@ variant, size, color, disabled, readOnly, autoFocus, ...props }) => {
|
|
|
37
37
|
onChange: value => {
|
|
38
38
|
setInnerValue(o => [value, o?.[1] || null]);
|
|
39
39
|
if (value && !showTimer) {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
requestAnimationFrame(() => {
|
|
41
|
+
endPickerInputRef.current.focus();
|
|
42
|
+
innerOpen.current === 'start' && setInnerOpen('end');
|
|
43
|
+
});
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -24,4 +24,4 @@ export interface OverlayBaseProps extends DivProps {
|
|
|
24
24
|
removeFocusOnOpen?: boolean;
|
|
25
25
|
}
|
|
26
26
|
export declare const overlayBaseTransitionDuration = 300;
|
|
27
|
-
export declare function OverlayBase({ container, effectContainer, forceRender, open, onMaskClick, singleLayer, onOpened, onClosed, maskProps, removeFocusOnOpen, ...props }: OverlayBaseProps): false | React.ReactPortal | null;
|
|
27
|
+
export declare function OverlayBase({ container, effectContainer, forceRender, open, onMaskClick, singleLayer, onOpened, onClosed, maskProps, removeFocusOnOpen, ...props }: OverlayBaseProps): false | React.ReactPortal | null | undefined;
|
|
@@ -19,6 +19,20 @@ const getAttemptOrder = (placement) => {
|
|
|
19
19
|
}
|
|
20
20
|
return order;
|
|
21
21
|
};
|
|
22
|
+
const splitPlacement = {
|
|
23
|
+
top: ['top'],
|
|
24
|
+
bottom: ['bottom'],
|
|
25
|
+
left: ['left'],
|
|
26
|
+
right: ['right'],
|
|
27
|
+
topLeft: ['top', 'left'],
|
|
28
|
+
topRight: ['top', 'right'],
|
|
29
|
+
bottomLeft: ['bottom', 'left'],
|
|
30
|
+
bottomRight: ['bottom', 'right'],
|
|
31
|
+
leftTop: ['left', 'top'],
|
|
32
|
+
leftBottom: ['left', 'bottom'],
|
|
33
|
+
rightTop: ['right', 'top'],
|
|
34
|
+
rightBottom: ['right', 'bottom']
|
|
35
|
+
};
|
|
22
36
|
export function Popper({ ref, popperRef, anchorElement, container, effectContainer, content, offset, trigger = 'hover', clickToClose, placement = 'top', variant = 'zoom', sizeAdaptable = variant === 'collapse', mouseEnterDelay = 150, mouseLeaveDelay = 150, defaultOpen = false, open, onOpenChange, onOpenChangeEnd, disabled, autoClose = false, forceRender, animation = true, children, ...props }) {
|
|
23
37
|
const { spacing } = useTheme();
|
|
24
38
|
offset ??= spacing[2];
|
|
@@ -115,7 +129,7 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
115
129
|
const popperEl = innerPopperRef.current;
|
|
116
130
|
let { offsetWidth: popperWidth, offsetHeight: popperHeight } = popperEl;
|
|
117
131
|
let pA, pB;
|
|
118
|
-
let left,
|
|
132
|
+
let top, bottom, left, right;
|
|
119
133
|
let width, height;
|
|
120
134
|
let originX, originY;
|
|
121
135
|
let attempt;
|
|
@@ -124,69 +138,64 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
124
138
|
const mouseX = contextMenuEvent.current.clientX - containerRect.left;
|
|
125
139
|
const mouseY = contextMenuEvent.current.clientY - containerRect.top;
|
|
126
140
|
attempt = placement => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
switch (pA) {
|
|
162
|
-
case 'top':
|
|
163
|
-
top = mouseY - popperHeight;
|
|
164
|
-
originY = '100%';
|
|
165
|
-
break;
|
|
166
|
-
case 'bottom':
|
|
167
|
-
top = mouseY;
|
|
168
|
-
originY = '0%';
|
|
169
|
-
break;
|
|
170
|
-
case 'left':
|
|
171
|
-
left = mouseX - popperWidth;
|
|
172
|
-
originX = '100%';
|
|
173
|
-
break;
|
|
174
|
-
case 'right':
|
|
175
|
-
left = mouseX;
|
|
176
|
-
originX = '0%';
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
if (pA === 'top' || pA === 'bottom') {
|
|
141
|
+
switch (placement) {
|
|
142
|
+
case 'topLeft':
|
|
143
|
+
case 'leftTop':
|
|
144
|
+
bottom = -mouseY;
|
|
145
|
+
right = containerRect.width - mouseX;
|
|
146
|
+
originX = '100%';
|
|
147
|
+
originY = '100%';
|
|
148
|
+
break;
|
|
149
|
+
case 'topRight':
|
|
150
|
+
case 'rightTop':
|
|
151
|
+
bottom = -mouseY;
|
|
152
|
+
left = mouseX;
|
|
153
|
+
originX = '0%';
|
|
154
|
+
originY = '100%';
|
|
155
|
+
break;
|
|
156
|
+
case 'bottomLeft':
|
|
157
|
+
case 'leftBottom':
|
|
158
|
+
top = mouseY;
|
|
159
|
+
right = containerRect.width - mouseX;
|
|
160
|
+
originX = '100%';
|
|
161
|
+
originY = '0%';
|
|
162
|
+
break;
|
|
163
|
+
case 'bottomRight':
|
|
164
|
+
case 'rightBottom':
|
|
165
|
+
top = mouseY;
|
|
166
|
+
left = mouseX;
|
|
167
|
+
originX = '0%';
|
|
168
|
+
originY = '0%';
|
|
169
|
+
break;
|
|
170
|
+
case 'top':
|
|
171
|
+
top = mouseY - popperHeight;
|
|
180
172
|
left = mouseX - popperWidth / 2;
|
|
181
173
|
originX = '50%';
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
originY = '100%';
|
|
175
|
+
break;
|
|
176
|
+
case 'bottom':
|
|
177
|
+
top = mouseY;
|
|
178
|
+
left = mouseX - popperWidth / 2;
|
|
179
|
+
originX = '50%';
|
|
180
|
+
originY = '0%';
|
|
181
|
+
break;
|
|
182
|
+
case 'left':
|
|
184
183
|
top = mouseY - popperHeight / 2;
|
|
184
|
+
left = mouseX - popperWidth;
|
|
185
|
+
originX = '100%';
|
|
185
186
|
originY = '50%';
|
|
186
|
-
|
|
187
|
+
break;
|
|
188
|
+
case 'right':
|
|
189
|
+
top = mouseY - popperHeight / 2;
|
|
190
|
+
left = mouseX;
|
|
191
|
+
originX = '0%';
|
|
192
|
+
originY = '50%';
|
|
193
|
+
break;
|
|
187
194
|
}
|
|
188
|
-
popperEl.style.
|
|
189
|
-
popperEl.style.
|
|
195
|
+
popperEl.style.top = typeof top === 'undefined' ? '' : top + 'px';
|
|
196
|
+
popperEl.style.bottom = typeof bottom === 'undefined' ? '' : bottom + 'px';
|
|
197
|
+
popperEl.style.left = typeof left === 'undefined' ? '' : left + 'px';
|
|
198
|
+
popperEl.style.right = typeof right === 'undefined' ? '' : right + 'px';
|
|
190
199
|
return isElementOverflowed(popperEl, containerEl.current === document.body ? void 0 : containerEl.current);
|
|
191
200
|
};
|
|
192
201
|
}
|
|
@@ -194,9 +203,11 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
194
203
|
// 非右键菜单
|
|
195
204
|
const anchorRect = getAnchorElement().getBoundingClientRect();
|
|
196
205
|
const topEdge = anchorRect.top - containerRect.top;
|
|
206
|
+
const bottomEdge = anchorRect.bottom - containerRect.top;
|
|
197
207
|
const leftEdge = anchorRect.left - containerRect.left;
|
|
208
|
+
const rightEdge = containerRect.left + containerRect.width - anchorRect.right;
|
|
198
209
|
attempt = placement => {
|
|
199
|
-
[
|
|
210
|
+
[pA, pB] = splitPlacement[placement];
|
|
200
211
|
if (sizeAdaptable) {
|
|
201
212
|
if (pA === 'top' || pA === 'bottom') {
|
|
202
213
|
width = popperWidth = anchorRect.width;
|
|
@@ -214,39 +225,48 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
214
225
|
}
|
|
215
226
|
switch (pA) {
|
|
216
227
|
case 'top':
|
|
217
|
-
top =
|
|
228
|
+
top = void 0;
|
|
229
|
+
bottom = -(topEdge - offset);
|
|
218
230
|
originY = '100%';
|
|
219
231
|
break;
|
|
220
232
|
case 'bottom':
|
|
221
|
-
|
|
233
|
+
bottom = void 0;
|
|
234
|
+
top = bottomEdge + offset;
|
|
222
235
|
originY = '0%';
|
|
223
236
|
break;
|
|
224
237
|
case 'left':
|
|
225
|
-
left =
|
|
238
|
+
left = void 0;
|
|
239
|
+
right = leftEdge - offset;
|
|
226
240
|
originX = '100%';
|
|
227
241
|
break;
|
|
228
242
|
case 'right':
|
|
229
|
-
|
|
243
|
+
right = void 0;
|
|
244
|
+
left = rightEdge + offset;
|
|
230
245
|
originX = '0%';
|
|
231
246
|
}
|
|
232
247
|
switch (pB) {
|
|
233
|
-
case '
|
|
248
|
+
case 'left':
|
|
234
249
|
left = leftEdge;
|
|
250
|
+
right = void 0;
|
|
235
251
|
originX = '0%';
|
|
236
252
|
break;
|
|
237
|
-
case '
|
|
238
|
-
left =
|
|
253
|
+
case 'right':
|
|
254
|
+
left = void 0;
|
|
255
|
+
right = rightEdge;
|
|
239
256
|
originX = '100%';
|
|
240
257
|
break;
|
|
241
|
-
case '
|
|
258
|
+
case 'top':
|
|
242
259
|
top = topEdge;
|
|
260
|
+
bottom = void 0;
|
|
243
261
|
originY = '0%';
|
|
244
262
|
break;
|
|
245
|
-
case '
|
|
246
|
-
top =
|
|
263
|
+
case 'bottom':
|
|
264
|
+
top = void 0;
|
|
265
|
+
bottom = bottomEdge;
|
|
247
266
|
originY = '100%';
|
|
248
267
|
break;
|
|
249
268
|
default:
|
|
269
|
+
// pB === undefined
|
|
250
270
|
if (pA === 'top' || pA === 'bottom') {
|
|
251
271
|
left = leftEdge + (anchorRect.width - popperWidth) / 2;
|
|
252
272
|
originX = '50%';
|
|
@@ -256,8 +276,12 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
256
276
|
originY = '50%';
|
|
257
277
|
}
|
|
258
278
|
}
|
|
259
|
-
popperEl.style.
|
|
260
|
-
popperEl.style.
|
|
279
|
+
popperEl.style.top = typeof top === 'undefined' ? '' : top + 'px';
|
|
280
|
+
popperEl.style.bottom = typeof bottom === 'undefined' ? '' : bottom + 'px';
|
|
281
|
+
popperEl.style.left = typeof left === 'undefined' ? '' : left + 'px';
|
|
282
|
+
popperEl.style.right = typeof right === 'undefined' ? '' : right + 'px';
|
|
283
|
+
popperEl.style.width = typeof width === 'undefined' ? '' : width + 'px';
|
|
284
|
+
popperEl.style.height = typeof height === 'undefined' ? '' : height + 'px';
|
|
261
285
|
return isElementOverflowed(popperEl, containerEl.current === document.body ? void 0 : containerEl.current);
|
|
262
286
|
};
|
|
263
287
|
}
|
|
@@ -267,40 +291,29 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
267
291
|
else {
|
|
268
292
|
const attemptOrder = getAttemptOrder(placement);
|
|
269
293
|
for (let i = 0; i < attemptOrder.length; i++) {
|
|
270
|
-
|
|
294
|
+
const t = attempt(attemptOrder[i]);
|
|
295
|
+
if (t === false) {
|
|
271
296
|
break;
|
|
272
297
|
}
|
|
273
298
|
}
|
|
274
299
|
}
|
|
300
|
+
beforeOpen?.();
|
|
275
301
|
const settle = () => {
|
|
276
302
|
setPopperBounding({
|
|
277
|
-
left,
|
|
303
|
+
top, bottom, left, right, width, height,
|
|
278
304
|
transformOrigin: `${originX} ${originY}`
|
|
279
305
|
});
|
|
280
306
|
placeA.current = pA;
|
|
281
307
|
placeB.current = pB;
|
|
282
308
|
};
|
|
283
|
-
if (beforeOpen) {
|
|
284
|
-
if (sizeAdaptable) {
|
|
285
|
-
// 自适应尺寸需要在打开前设置
|
|
286
|
-
popperEl.style.width = width ? width + 'px' : '';
|
|
287
|
-
popperEl.style.height = height ? height + 'px' : '';
|
|
288
|
-
}
|
|
289
|
-
beforeOpen();
|
|
290
|
-
}
|
|
291
309
|
if (options?.openAnimation) {
|
|
292
310
|
popperEl.style.transform = variant === 'collapse'
|
|
293
311
|
? pA === 'top' || pA === 'bottom' ? 'scaleY(0)' : 'scaleX(0)'
|
|
294
312
|
: 'scale(0)';
|
|
295
313
|
animating.current = true;
|
|
296
|
-
|
|
297
|
-
settle();
|
|
298
|
-
setOpenNextFrame(true);
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
settle();
|
|
314
|
+
setOpenNextFrame(true);
|
|
303
315
|
}
|
|
316
|
+
settle();
|
|
304
317
|
};
|
|
305
318
|
useLayoutEffect(() => {
|
|
306
319
|
if (innerOpen.current) {
|
|
@@ -536,12 +549,12 @@ export function Popper({ ref, popperRef, anchorElement, container, effectContain
|
|
|
536
549
|
})
|
|
537
550
|
: children, renderedOnce.current && containerEl.current && createPortal(_jsx(ClickAway, { disabled: !clickable && !enterable && !contextMenuable,
|
|
538
551
|
// 右键菜单点击anchor需要关闭弹框
|
|
539
|
-
targets: () => contextMenuEvent.current ? void 0 : getAnchorElement(), onClickAway: onClickAway, children: _jsx("div", { ...props, ref: innerPopperRef,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
552
|
+
targets: () => contextMenuEvent.current ? void 0 : getAnchorElement(), onClickAway: onClickAway, children: _jsx("div", { css: style, className: classes.placeHelper, children: _jsx("div", { ...props, ref: innerPopperRef, className: clsx(classes.root, props.className), style: {
|
|
553
|
+
...popperBounding,
|
|
554
|
+
...!openNextFrame.current && {
|
|
555
|
+
transition: 'none',
|
|
556
|
+
transform: 'scale(1)'
|
|
557
|
+
},
|
|
558
|
+
...props.style
|
|
559
|
+
}, "data-open": innerOpen.current, "data-variant": variant, "data-place-a": placeA.current, "data-place-b": placeB.current, "data-animation": animation, onTransitionEnd: onTransitionEnd, children: _jsx(PopperContext, { value: contextValue, children: content }) }) }) }), containerEl.current)] }));
|
|
547
560
|
}
|
|
@@ -3,7 +3,7 @@ import { defineCss, defineInnerClasses } from '../../utils/index.js';
|
|
|
3
3
|
import { appStyleCallback } from '../app/app.style.js';
|
|
4
4
|
import { zIndex } from '../theme/index.js';
|
|
5
5
|
export const classes = defineInnerClasses('popper', [
|
|
6
|
-
'
|
|
6
|
+
'placeHelper'
|
|
7
7
|
]);
|
|
8
8
|
export const style = defineCss(theme => {
|
|
9
9
|
const { easing } = theme;
|
|
@@ -11,37 +11,43 @@ export const style = defineCss(theme => {
|
|
|
11
11
|
appStyleCallback(theme),
|
|
12
12
|
css `
|
|
13
13
|
@layer reset {
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: 0;
|
|
14
16
|
position: absolute;
|
|
15
17
|
top: 0;
|
|
16
18
|
left: 0;
|
|
17
|
-
z-index: ${zIndex.popper};
|
|
18
|
-
transition-property: transform, opacity;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
&[data-open=true] {
|
|
25
|
-
transition-timing-function: ${easing.bounce}, ${easing.easeOut};
|
|
26
|
-
opacity: 1;
|
|
27
|
-
transform: scale(1);
|
|
28
|
-
}
|
|
20
|
+
.${classes.root} {
|
|
21
|
+
position: absolute;
|
|
22
|
+
z-index: ${zIndex.popper};
|
|
23
|
+
transition-property: transform, opacity;
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
&[data-animation=true] {
|
|
26
|
+
transition-duration: .25s;
|
|
27
|
+
}
|
|
33
28
|
|
|
34
|
-
&[data-
|
|
35
|
-
|
|
29
|
+
&[data-open=true] {
|
|
30
|
+
transition-timing-function: ${easing.bounce}, ${easing.easeOut};
|
|
31
|
+
opacity: 1;
|
|
32
|
+
transform: scale(1);
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
&:not([data-open=true]) {
|
|
36
|
+
transition-timing-function: ${easing.easeIn};
|
|
37
|
+
opacity: 0;
|
|
38
|
+
|
|
39
|
+
&[data-variant=zoom] {
|
|
40
|
+
transform: scale(0);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
&[data-
|
|
44
|
-
|
|
43
|
+
&[data-variant=collapse] {
|
|
44
|
+
&[data-place-a=top], &[data-place-a=bottom] {
|
|
45
|
+
transform: scaleY(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&[data-place-a=left], &[data-place-a=right] {
|
|
49
|
+
transform: scaleX(0);
|
|
50
|
+
}
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
}
|
|
@@ -30,7 +30,7 @@ export declare const SnackbarBase: React.MemoExoticComponent<({ methods, useTo,
|
|
|
30
30
|
max?: number;
|
|
31
31
|
container?: DefineElement<HTMLElement>;
|
|
32
32
|
effectContainer?: DefineElement<HTMLElement>;
|
|
33
|
-
}) => React.ReactPortal | null>;
|
|
33
|
+
}) => React.ReactPortal | null | undefined>;
|
|
34
34
|
interface SnackbarBaseItemProps extends Omit<SnackbarBaseProps, 'duration' | 'onAutoClose'> {
|
|
35
35
|
id: string;
|
|
36
36
|
type: keyof SnackbarBaseMethods;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type Size = 'small' | 'medium' | 'large';
|
|
|
21
21
|
export type CornerPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom';
|
|
22
22
|
export type BlockPlacement = CornerPlacement | 'top' | 'bottom';
|
|
23
23
|
export type Placement = BlockPlacement | 'left' | 'right';
|
|
24
|
-
export type DefineElement<T = Element | null | undefined
|
|
24
|
+
export type DefineElement<T = Element> = T | null | undefined | (() => T | null | undefined);
|
|
25
25
|
/**
|
|
26
26
|
* ----------------------------------------------------------------------------------
|
|
27
27
|
* Responsive
|
|
@@ -51,7 +51,7 @@ export declare function useLoading<A extends any[], R>(fn: (...args: A) => R | P
|
|
|
51
51
|
* @param effectContainer
|
|
52
52
|
* @param defaultContainer 默认为`document.body`
|
|
53
53
|
*/
|
|
54
|
-
export declare function useContainer<T extends HTMLElement | null>(container?: DefineElement<T>, effectContainer?: DefineElement<T>, defaultContainer?: DefineElement<T>): RefObject<T | null>;
|
|
54
|
+
export declare function useContainer<T extends HTMLElement | null>(container?: DefineElement<T>, effectContainer?: DefineElement<T>, defaultContainer?: DefineElement<T>): RefObject<T | null | undefined>;
|
|
55
55
|
/**
|
|
56
56
|
* 使用外部类,该方法可避免`StrictMode`下,React渲染行为与外部类实例生命周期不同步的问题
|
|
57
57
|
*/
|