@canlooks/can-ui 0.0.19 → 0.0.21
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.
|
@@ -11,7 +11,7 @@ const button_1 = require("../button");
|
|
|
11
11
|
const react_zoom_pan_pinch_1 = require("react-zoom-pan-pinch");
|
|
12
12
|
const tooltip_1 = require("../tooltip");
|
|
13
13
|
exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], defaultIndex = 0, index, onIndexChange, defaultOpen = false, open, onOpenChange, showRotate = true, showZoom = true, showClose = true, renderControl, transformWrapperProps, transformWrapperRef, ...props }, ref) => {
|
|
14
|
-
const srcArr =
|
|
14
|
+
const srcArr = (0, utils_1.toArray)(src);
|
|
15
15
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open, onOpenChange);
|
|
16
16
|
const [innerIndex, setInnerIndex] = (0, utils_1.useControlled)(defaultIndex, index, onIndexChange);
|
|
17
17
|
const innerTransformWrapperRef = (0, react_1.useRef)(null);
|
|
@@ -48,8 +48,8 @@ exports.Popper = (0, react_1.forwardRef)(({ popperRef, anchorElement, container
|
|
|
48
48
|
if (openState || !openHolding.current) {
|
|
49
49
|
// 需要openHolding为false时才能关闭
|
|
50
50
|
_setInnerOpen(openState);
|
|
51
|
+
setContextMenuEvent(contextMenuEvent);
|
|
51
52
|
}
|
|
52
|
-
setContextMenuEvent(contextMenuEvent);
|
|
53
53
|
};
|
|
54
54
|
const renderedOnce = (0, react_1.useRef)(!!forceRender);
|
|
55
55
|
if (innerOpen.current) {
|
|
@@ -371,18 +371,14 @@ exports.Popper = (0, react_1.forwardRef)(({ popperRef, anchorElement, container
|
|
|
371
371
|
// click
|
|
372
372
|
const onClick = (0, react_1.useCallback)((e) => {
|
|
373
373
|
children?.props.onClick?.(e);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const allowClickAway = (() => {
|
|
377
|
-
let allow = false;
|
|
378
|
-
for (const trigger of triggersSet) {
|
|
379
|
-
if (trigger === 'click' || trigger === 'enter' || trigger === 'contextMenu') {
|
|
380
|
-
allow = true;
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
374
|
+
if (triggersSet.has('click')) {
|
|
375
|
+
setInnerOpen(openHolding.current = true);
|
|
383
376
|
}
|
|
384
|
-
|
|
385
|
-
|
|
377
|
+
else {
|
|
378
|
+
// trigger中不包含"click",则无需保持打开状态,否则会与focus冲突
|
|
379
|
+
openHolding.current = false;
|
|
380
|
+
}
|
|
381
|
+
}, [children?.props.onClick]);
|
|
386
382
|
const onClickAway = () => {
|
|
387
383
|
setInnerOpen(openHolding.current = false);
|
|
388
384
|
};
|
|
@@ -405,7 +401,11 @@ exports.Popper = (0, react_1.forwardRef)(({ popperRef, anchorElement, container
|
|
|
405
401
|
const contextValue = (0, react_1.useMemo)(() => ({
|
|
406
402
|
autoClose,
|
|
407
403
|
open: innerOpen.current,
|
|
408
|
-
setOpen
|
|
404
|
+
setOpen(open) {
|
|
405
|
+
// 通过context改变的open状态,需要强制将openHolding置为false
|
|
406
|
+
openHolding.current = false;
|
|
407
|
+
setInnerOpen(open);
|
|
408
|
+
},
|
|
409
409
|
beforeOpenCallbacks: beforeOpenCallbacks.current
|
|
410
410
|
}), [innerOpen.current, autoClose]);
|
|
411
411
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, react_1.isValidElement)(children)
|
|
@@ -413,11 +413,12 @@ exports.Popper = (0, react_1.forwardRef)(({ popperRef, anchorElement, container
|
|
|
413
413
|
ref: (0, react_1.useCallback)((0, utils_1.cloneRef)(children.ref, anchorRef, ref), [children.ref]),
|
|
414
414
|
...hoverable && { onPointerEnter, onPointerLeave },
|
|
415
415
|
...triggersSet.has('click') && { onClick },
|
|
416
|
-
|
|
416
|
+
// 通常点击会触发focus,因此这里需要处理点击事件
|
|
417
|
+
...triggersSet.has('focus') && { onClick, onFocus, onBlur },
|
|
417
418
|
...triggersSet.has('enter') && { onKeyDown },
|
|
418
419
|
...triggersSet.has('contextMenu') && { onContextMenu }
|
|
419
420
|
})
|
|
420
|
-
: children, renderedOnce.current && (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(clickAway_1.ClickAway, { disabled: !
|
|
421
|
+
: children, renderedOnce.current && (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(clickAway_1.ClickAway, { disabled: !triggersSet.has('click') && !triggersSet.has('enter') && !triggersSet.has('contextMenu'),
|
|
421
422
|
// 非右键菜单不能点击anchor关闭
|
|
422
423
|
targets: () => contextMenuEvent.current ? null : anchorRef.current, onClickAway: onClickAway, children: (0, jsx_runtime_1.jsx)("div", { ...props, ref: innerPopperRef, css: popper_style_1.style, className: (0, utils_1.classnames)(popper_style_1.classes.root, props?.className), style: {
|
|
423
424
|
...popperSize,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { forwardRef, memo, useRef, useState } from 'react';
|
|
3
3
|
import { Modal } from '../modal';
|
|
4
|
-
import { classnames, cloneRef, useControlled } from '../../utils';
|
|
4
|
+
import { classnames, cloneRef, toArray, useControlled } from '../../utils';
|
|
5
5
|
import { classes, style } from './imagePreview.style';
|
|
6
6
|
import { CloseOutlined, FullscreenOutlined, LeftOutlined, RightOutlined, RotateLeftOutlined, RotateRightOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
|
|
7
7
|
import { Button } from '../button';
|
|
8
8
|
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
|
|
9
9
|
import { Tooltip } from '../tooltip';
|
|
10
10
|
export const ImagePreview = memo(forwardRef(({ src = [], defaultIndex = 0, index, onIndexChange, defaultOpen = false, open, onOpenChange, showRotate = true, showZoom = true, showClose = true, renderControl, transformWrapperProps, transformWrapperRef, ...props }, ref) => {
|
|
11
|
-
const srcArr =
|
|
11
|
+
const srcArr = toArray(src);
|
|
12
12
|
const [innerOpen, setInnerOpen] = useControlled(defaultOpen, open, onOpenChange);
|
|
13
13
|
const [innerIndex, setInnerIndex] = useControlled(defaultIndex, index, onIndexChange);
|
|
14
14
|
const innerTransformWrapperRef = useRef(null);
|
|
@@ -45,8 +45,8 @@ export const Popper = forwardRef(({ popperRef, anchorElement, container = docume
|
|
|
45
45
|
if (openState || !openHolding.current) {
|
|
46
46
|
// 需要openHolding为false时才能关闭
|
|
47
47
|
_setInnerOpen(openState);
|
|
48
|
+
setContextMenuEvent(contextMenuEvent);
|
|
48
49
|
}
|
|
49
|
-
setContextMenuEvent(contextMenuEvent);
|
|
50
50
|
};
|
|
51
51
|
const renderedOnce = useRef(!!forceRender);
|
|
52
52
|
if (innerOpen.current) {
|
|
@@ -368,18 +368,14 @@ export const Popper = forwardRef(({ popperRef, anchorElement, container = docume
|
|
|
368
368
|
// click
|
|
369
369
|
const onClick = useCallback((e) => {
|
|
370
370
|
children?.props.onClick?.(e);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const allowClickAway = (() => {
|
|
374
|
-
let allow = false;
|
|
375
|
-
for (const trigger of triggersSet) {
|
|
376
|
-
if (trigger === 'click' || trigger === 'enter' || trigger === 'contextMenu') {
|
|
377
|
-
allow = true;
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
371
|
+
if (triggersSet.has('click')) {
|
|
372
|
+
setInnerOpen(openHolding.current = true);
|
|
380
373
|
}
|
|
381
|
-
|
|
382
|
-
|
|
374
|
+
else {
|
|
375
|
+
// trigger中不包含"click",则无需保持打开状态,否则会与focus冲突
|
|
376
|
+
openHolding.current = false;
|
|
377
|
+
}
|
|
378
|
+
}, [children?.props.onClick]);
|
|
383
379
|
const onClickAway = () => {
|
|
384
380
|
setInnerOpen(openHolding.current = false);
|
|
385
381
|
};
|
|
@@ -402,7 +398,11 @@ export const Popper = forwardRef(({ popperRef, anchorElement, container = docume
|
|
|
402
398
|
const contextValue = useMemo(() => ({
|
|
403
399
|
autoClose,
|
|
404
400
|
open: innerOpen.current,
|
|
405
|
-
setOpen
|
|
401
|
+
setOpen(open) {
|
|
402
|
+
// 通过context改变的open状态,需要强制将openHolding置为false
|
|
403
|
+
openHolding.current = false;
|
|
404
|
+
setInnerOpen(open);
|
|
405
|
+
},
|
|
406
406
|
beforeOpenCallbacks: beforeOpenCallbacks.current
|
|
407
407
|
}), [innerOpen.current, autoClose]);
|
|
408
408
|
return (_jsxs(_Fragment, { children: [isValidElement(children)
|
|
@@ -410,11 +410,12 @@ export const Popper = forwardRef(({ popperRef, anchorElement, container = docume
|
|
|
410
410
|
ref: useCallback(cloneRef(children.ref, anchorRef, ref), [children.ref]),
|
|
411
411
|
...hoverable && { onPointerEnter, onPointerLeave },
|
|
412
412
|
...triggersSet.has('click') && { onClick },
|
|
413
|
-
|
|
413
|
+
// 通常点击会触发focus,因此这里需要处理点击事件
|
|
414
|
+
...triggersSet.has('focus') && { onClick, onFocus, onBlur },
|
|
414
415
|
...triggersSet.has('enter') && { onKeyDown },
|
|
415
416
|
...triggersSet.has('contextMenu') && { onContextMenu }
|
|
416
417
|
})
|
|
417
|
-
: children, renderedOnce.current && createPortal(_jsx(ClickAway, { disabled: !
|
|
418
|
+
: children, renderedOnce.current && createPortal(_jsx(ClickAway, { disabled: !triggersSet.has('click') && !triggersSet.has('enter') && !triggersSet.has('contextMenu'),
|
|
418
419
|
// 非右键菜单不能点击anchor关闭
|
|
419
420
|
targets: () => contextMenuEvent.current ? null : anchorRef.current, onClickAway: onClickAway, children: _jsx("div", { ...props, ref: innerPopperRef, css: style, className: classnames(classes.root, props?.className), style: {
|
|
420
421
|
...popperSize,
|