@canlooks/can-ui 0.0.19 → 0.0.20
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);
|
|
@@ -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
|
};
|
|
@@ -413,11 +409,12 @@ exports.Popper = (0, react_1.forwardRef)(({ popperRef, anchorElement, container
|
|
|
413
409
|
ref: (0, react_1.useCallback)((0, utils_1.cloneRef)(children.ref, anchorRef, ref), [children.ref]),
|
|
414
410
|
...hoverable && { onPointerEnter, onPointerLeave },
|
|
415
411
|
...triggersSet.has('click') && { onClick },
|
|
416
|
-
|
|
412
|
+
// 通常点击会触发focus,因此这里需要处理点击事件
|
|
413
|
+
...triggersSet.has('focus') && { onClick, onFocus, onBlur },
|
|
417
414
|
...triggersSet.has('enter') && { onKeyDown },
|
|
418
415
|
...triggersSet.has('contextMenu') && { onContextMenu }
|
|
419
416
|
})
|
|
420
|
-
: children, renderedOnce.current && (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(clickAway_1.ClickAway, { disabled: !
|
|
417
|
+
: 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
418
|
// 非右键菜单不能点击anchor关闭
|
|
422
419
|
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
420
|
...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);
|
|
@@ -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
|
};
|
|
@@ -410,11 +406,12 @@ export const Popper = forwardRef(({ popperRef, anchorElement, container = docume
|
|
|
410
406
|
ref: useCallback(cloneRef(children.ref, anchorRef, ref), [children.ref]),
|
|
411
407
|
...hoverable && { onPointerEnter, onPointerLeave },
|
|
412
408
|
...triggersSet.has('click') && { onClick },
|
|
413
|
-
|
|
409
|
+
// 通常点击会触发focus,因此这里需要处理点击事件
|
|
410
|
+
...triggersSet.has('focus') && { onClick, onFocus, onBlur },
|
|
414
411
|
...triggersSet.has('enter') && { onKeyDown },
|
|
415
412
|
...triggersSet.has('contextMenu') && { onContextMenu }
|
|
416
413
|
})
|
|
417
|
-
: children, renderedOnce.current && createPortal(_jsx(ClickAway, { disabled: !
|
|
414
|
+
: children, renderedOnce.current && createPortal(_jsx(ClickAway, { disabled: !triggersSet.has('click') && !triggersSet.has('enter') && !triggersSet.has('contextMenu'),
|
|
418
415
|
// 非右键菜单不能点击anchor关闭
|
|
419
416
|
targets: () => contextMenuEvent.current ? null : anchorRef.current, onClickAway: onClickAway, children: _jsx("div", { ...props, ref: innerPopperRef, css: style, className: classnames(classes.root, props?.className), style: {
|
|
420
417
|
...popperSize,
|