@rc-component/trigger 1.10.0 → 1.10.1

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/README.md CHANGED
@@ -65,8 +65,6 @@ ReactDOM.render((
65
65
 
66
66
  http://localhost:9001
67
67
 
68
- online example: http://react-component.github.io/trigger/
69
-
70
68
  ## Development
71
69
 
72
70
  ```
@@ -252,75 +250,11 @@ npm start
252
250
 
253
251
  ```
254
252
  npm test
255
- npm run chrome-test
256
- ```
257
-
258
- ## Coverage
259
-
260
- ```
261
253
  npm run coverage
262
254
  ```
263
255
 
264
256
  open coverage/ dir
265
257
 
266
- ## React 16 Note
267
-
268
- After React 16, you won't access popup element's ref in parent component's componentDidMount, which means following code won't work.
269
-
270
- ```javascript
271
- class App extends React.Component {
272
- componentDidMount() {
273
- this.input.focus(); // error, this.input is undefined.
274
- }
275
-
276
- render() {
277
- return (
278
- <Trigger
279
- action={['click']}
280
- popup={<div><input ref={node => this.input = node} type="text" /></div>}
281
- >
282
- <button>click</button>
283
- </Trigger>
284
- )
285
- }
286
- }
287
- ```
288
-
289
- Consider wrap your popup element to a separate component:
290
-
291
- ```javascript
292
- class InputPopup extends React.Component {
293
- componentDidMount() {
294
- this.props.onMount();
295
- }
296
-
297
- render() {
298
- return (
299
- <div>
300
- <input ref={this.props.inputRef} type="text" />
301
- </div>
302
- );
303
- }
304
- }
305
-
306
- class App extends React.Component {
307
- handlePopupMount() {
308
- this.input.focus(); // error, this.input is undefined.
309
- }
310
-
311
- render() {
312
- return (
313
- <Trigger
314
- action={['click']}
315
- popup={<InputPopup inputRef={node => this.input = node} onMount={this.handlePopupMount} />}
316
- >
317
- <button>click</button>
318
- </Trigger>
319
- )
320
- }
321
- }
322
- ```
323
-
324
258
  ## License
325
259
 
326
260
  rc-trigger is released under the MIT license.
package/es/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { CSSMotionProps } from 'rc-motion';
2
2
  import * as React from 'react';
3
- import type { ActionType, AlignType, ArrowTypeOuter, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
4
- export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType };
3
+ import type { ActionType, AlignType, AnimationType, ArrowTypeOuter, BuildInPlacements, TransitionNameType } from './interface';
4
+ export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType, };
5
5
  export interface TriggerRef {
6
6
  forceAlign: VoidFunction;
7
7
  }
package/es/index.js CHANGED
@@ -327,19 +327,29 @@ export function generateTrigger() {
327
327
  // Click to hide is special action since click popup element should not hide
328
328
  React.useEffect(function () {
329
329
  if (clickToHide && popupEle && (!mask || maskClosable)) {
330
- var onWindowClick = function onWindowClick(_ref) {
330
+ var clickInside = false;
331
+
332
+ // User may mouseDown inside and drag out of popup and mouse up
333
+ // Record here to prevent close
334
+ var onWindowMouseDown = function onWindowMouseDown(_ref) {
331
335
  var target = _ref.target;
332
- if (openRef.current && !inPopupOrChild(target)) {
336
+ clickInside = inPopupOrChild(target);
337
+ };
338
+ var onWindowClick = function onWindowClick(_ref2) {
339
+ var target = _ref2.target;
340
+ if (openRef.current && !clickInside && !inPopupOrChild(target)) {
333
341
  triggerOpen(false);
334
342
  }
335
343
  };
336
344
  var win = getWin(popupEle);
337
345
  var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode();
346
+ win.addEventListener('mousedown', onWindowMouseDown);
338
347
  win.addEventListener('click', onWindowClick);
339
348
 
340
349
  // shadow root
341
350
  var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument;
342
351
  if (inShadow) {
352
+ targetRoot.addEventListener('mousedown', onWindowMouseDown);
343
353
  targetRoot.addEventListener('click', onWindowClick);
344
354
  }
345
355
 
@@ -349,8 +359,10 @@ export function generateTrigger() {
349
359
  warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
350
360
  }
351
361
  return function () {
362
+ win.removeEventListener('mousedown', onWindowMouseDown);
352
363
  win.removeEventListener('click', onWindowClick);
353
364
  if (inShadow) {
365
+ targetRoot.removeEventListener('mousedown', onWindowMouseDown);
354
366
  targetRoot.removeEventListener('click', onWindowClick);
355
367
  }
356
368
  };
package/lib/index.js CHANGED
@@ -336,19 +336,29 @@ function generateTrigger() {
336
336
  // Click to hide is special action since click popup element should not hide
337
337
  React.useEffect(function () {
338
338
  if (clickToHide && popupEle && (!mask || maskClosable)) {
339
- var onWindowClick = function onWindowClick(_ref) {
339
+ var clickInside = false;
340
+
341
+ // User may mouseDown inside and drag out of popup and mouse up
342
+ // Record here to prevent close
343
+ var onWindowMouseDown = function onWindowMouseDown(_ref) {
340
344
  var target = _ref.target;
341
- if (openRef.current && !inPopupOrChild(target)) {
345
+ clickInside = inPopupOrChild(target);
346
+ };
347
+ var onWindowClick = function onWindowClick(_ref2) {
348
+ var target = _ref2.target;
349
+ if (openRef.current && !clickInside && !inPopupOrChild(target)) {
342
350
  triggerOpen(false);
343
351
  }
344
352
  };
345
353
  var win = (0, _util.getWin)(popupEle);
346
354
  var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode();
355
+ win.addEventListener('mousedown', onWindowMouseDown);
347
356
  win.addEventListener('click', onWindowClick);
348
357
 
349
358
  // shadow root
350
359
  var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument;
351
360
  if (inShadow) {
361
+ targetRoot.addEventListener('mousedown', onWindowMouseDown);
352
362
  targetRoot.addEventListener('click', onWindowClick);
353
363
  }
354
364
 
@@ -358,8 +368,10 @@ function generateTrigger() {
358
368
  (0, _warning.default)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
359
369
  }
360
370
  return function () {
371
+ win.removeEventListener('mousedown', onWindowMouseDown);
361
372
  win.removeEventListener('click', onWindowClick);
362
373
  if (inShadow) {
374
+ targetRoot.removeEventListener('mousedown', onWindowMouseDown);
363
375
  targetRoot.removeEventListener('click', onWindowClick);
364
376
  }
365
377
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- import type { AlignType, ArrowType } from '../interface';
3
- export interface ArrowProps {
4
- prefixCls: string;
5
- align: AlignType;
6
- arrow: ArrowType;
7
- }
8
- export default function Arrow(props: ArrowProps): JSX.Element;
@@ -1,10 +0,0 @@
1
- /// <reference types="react" />
2
- import type { CSSMotionProps } from 'rc-motion';
3
- export interface MaskProps {
4
- prefixCls: string;
5
- open?: boolean;
6
- zIndex?: number;
7
- mask?: boolean;
8
- motion?: CSSMotionProps;
9
- }
10
- export default function Mask(props: MaskProps): JSX.Element;
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- export interface PopupContentProps {
3
- children?: React.ReactNode;
4
- cache?: boolean;
5
- }
6
- declare const PopupContent: React.MemoExoticComponent<({ children }: PopupContentProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
7
- export default PopupContent;
@@ -1,38 +0,0 @@
1
- import type { CSSMotionProps } from 'rc-motion';
2
- import * as React from 'react';
3
- import type { TriggerProps } from '../';
4
- import type { AlignType, ArrowType } from '../interface';
5
- export interface PopupProps {
6
- prefixCls: string;
7
- className?: string;
8
- style?: React.CSSProperties;
9
- popup?: TriggerProps['popup'];
10
- target: HTMLElement;
11
- onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
12
- onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
13
- zIndex?: number;
14
- mask?: boolean;
15
- onVisibleChanged: (visible: boolean) => void;
16
- align?: AlignType;
17
- arrow?: ArrowType;
18
- open: boolean;
19
- /** Tell Portal that should keep in screen. e.g. should wait all motion end */
20
- keepDom: boolean;
21
- onClick?: React.MouseEventHandler<HTMLDivElement>;
22
- motion?: CSSMotionProps;
23
- maskMotion?: CSSMotionProps;
24
- forceRender?: boolean;
25
- getPopupContainer?: TriggerProps['getPopupContainer'];
26
- autoDestroy?: boolean;
27
- portal: React.ComponentType<any>;
28
- ready: boolean;
29
- offsetX: number;
30
- offsetY: number;
31
- onAlign: VoidFunction;
32
- onPrepare: () => Promise<void>;
33
- stretch?: string;
34
- targetWidth?: number;
35
- targetHeight?: number;
36
- }
37
- declare const Popup: React.ForwardRefExoticComponent<PopupProps & React.RefAttributes<HTMLDivElement>>;
38
- export default Popup;
@@ -1,8 +0,0 @@
1
- import * as React from 'react';
2
- import type { TriggerProps } from '.';
3
- export interface TriggerWrapperProps {
4
- getTriggerDOMNode?: TriggerProps['getTriggerDOMNode'];
5
- children: React.ReactElement;
6
- }
7
- declare const TriggerWrapper: React.ForwardRefExoticComponent<TriggerWrapperProps & React.RefAttributes<HTMLElement>>;
8
- export default TriggerWrapper;
package/lib/context.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import * as React from 'react';
2
- export interface TriggerContextProps {
3
- registerSubPopup: (id: string, node: HTMLElement) => void;
4
- }
5
- declare const TriggerContext: React.Context<TriggerContextProps>;
6
- export default TriggerContext;
@@ -1,4 +0,0 @@
1
- import type { ActionType } from '../interface';
2
- declare type ActionTypes = ActionType | ActionType[];
3
- export default function useAction(mobile: boolean, action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
4
- export {};
@@ -1,13 +0,0 @@
1
- import type { TriggerProps } from '..';
2
- import type { AlignType } from '../interface';
3
- export default function useAlign(open: boolean, popupEle: HTMLElement, target: HTMLElement | [x: number, y: number], placement: string, builtinPlacements: any, popupAlign?: AlignType, onPopupAlign?: TriggerProps['onPopupAlign']): [
4
- ready: boolean,
5
- offsetX: number,
6
- offsetY: number,
7
- arrowX: number,
8
- arrowY: number,
9
- scaleX: number,
10
- scaleY: number,
11
- align: AlignType,
12
- onAlign: VoidFunction
13
- ];
@@ -1 +0,0 @@
1
- export default function useWatch(open: boolean, target: HTMLElement, popup: HTMLElement, onAlign: VoidFunction): void;
package/lib/index.d.ts DELETED
@@ -1,64 +0,0 @@
1
- import type { CSSMotionProps } from 'rc-motion';
2
- import * as React from 'react';
3
- import type { ActionType, AlignType, ArrowTypeOuter, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
4
- export type { BuildInPlacements, AlignType, ActionType, ArrowTypeOuter as ArrowType };
5
- export interface TriggerRef {
6
- forceAlign: VoidFunction;
7
- }
8
- export interface TriggerProps {
9
- children: React.ReactElement;
10
- action?: ActionType | ActionType[];
11
- showAction?: ActionType[];
12
- hideAction?: ActionType[];
13
- prefixCls?: string;
14
- zIndex?: number;
15
- onPopupAlign?: (element: HTMLElement, align: AlignType) => void;
16
- stretch?: string;
17
- popupVisible?: boolean;
18
- defaultPopupVisible?: boolean;
19
- onPopupVisibleChange?: (visible: boolean) => void;
20
- afterPopupVisibleChange?: (visible: boolean) => void;
21
- getPopupContainer?: (node: HTMLElement) => HTMLElement;
22
- forceRender?: boolean;
23
- autoDestroy?: boolean;
24
- /** @deprecated Please use `autoDestroy` instead */
25
- destroyPopupOnHide?: boolean;
26
- mask?: boolean;
27
- maskClosable?: boolean;
28
- /** Set popup motion. You can ref `rc-motion` for more info. */
29
- popupMotion?: CSSMotionProps;
30
- /** Set mask motion. You can ref `rc-motion` for more info. */
31
- maskMotion?: CSSMotionProps;
32
- /** @deprecated Please us `popupMotion` instead. */
33
- popupTransitionName?: TransitionNameType;
34
- /** @deprecated Please us `popupMotion` instead. */
35
- popupAnimation?: AnimationType;
36
- /** @deprecated Please us `maskMotion` instead. */
37
- maskTransitionName?: TransitionNameType;
38
- /** @deprecated Please us `maskMotion` instead. */
39
- maskAnimation?: AnimationType;
40
- mouseEnterDelay?: number;
41
- mouseLeaveDelay?: number;
42
- focusDelay?: number;
43
- blurDelay?: number;
44
- popup: React.ReactNode | (() => React.ReactNode);
45
- popupPlacement?: string;
46
- builtinPlacements?: BuildInPlacements;
47
- popupAlign?: AlignType;
48
- popupClassName?: string;
49
- popupStyle?: React.CSSProperties;
50
- getPopupClassNameFromAlign?: (align: AlignType) => string;
51
- onPopupClick?: React.MouseEventHandler<HTMLDivElement>;
52
- alignPoint?: boolean;
53
- arrow?: boolean | ArrowTypeOuter;
54
- /** @deprecated Add `className` on `children`. Please add `className` directly instead. */
55
- className?: string;
56
- /**
57
- * @private Get trigger DOM node.
58
- * Used for some component is function component which can not access by `findDOMNode`
59
- */
60
- getTriggerDOMNode?: (node: React.ReactInstance) => HTMLElement;
61
- }
62
- export declare function generateTrigger(PortalComponent?: React.ComponentType<any>): React.ForwardRefExoticComponent<TriggerProps & React.RefAttributes<TriggerRef>>;
63
- declare const _default: React.ForwardRefExoticComponent<TriggerProps & React.RefAttributes<TriggerRef>>;
64
- export default _default;
@@ -1,82 +0,0 @@
1
- /// <reference types="react" />
2
- import type { CSSMotionProps } from 'rc-motion';
3
- export declare type Placement = 'top' | 'left' | 'right' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom';
4
- export declare type AlignPointTopBottom = 't' | 'b' | 'c';
5
- export declare type AlignPointLeftRight = 'l' | 'r' | 'c';
6
- /** Two char of 't' 'b' 'c' 'l' 'r'. Example: 'lt' */
7
- export declare type AlignPoint = `${AlignPointTopBottom}${AlignPointLeftRight}`;
8
- export interface AlignType {
9
- /**
10
- * move point of source node to align with point of target node.
11
- * Such as ['tr','cc'], align top right point of source node with center point of target node.
12
- * Point can be 't'(top), 'b'(bottom), 'c'(center), 'l'(left), 'r'(right) */
13
- points?: (string | AlignPoint)[];
14
- /**
15
- * offset source node by offset[0] in x and offset[1] in y.
16
- * If offset contains percentage string value, it is relative to sourceNode region.
17
- */
18
- offset?: number[];
19
- /**
20
- * offset target node by offset[0] in x and offset[1] in y.
21
- * If targetOffset contains percentage string value, it is relative to targetNode region.
22
- */
23
- targetOffset?: number[];
24
- /**
25
- * If adjustX field is true, will adjust source node in x direction if source node is invisible.
26
- * If adjustY field is true, will adjust source node in y direction if source node is invisible.
27
- */
28
- overflow?: {
29
- adjustX?: boolean | number;
30
- adjustY?: boolean | number;
31
- shiftX?: boolean | number;
32
- shiftY?: boolean | number;
33
- };
34
- /** Auto adjust arrow position */
35
- autoArrow?: boolean;
36
- /**
37
- * Config visible region check of html node. Default `visible`:
38
- * - `visible`: The visible region of user browser window. Use `clientHeight` for check.
39
- * - `scroll`: The whole region of the html scroll area. Use `scrollHeight` for check.
40
- */
41
- htmlRegion?: 'visible' | 'scroll';
42
- /**
43
- * Whether use css right instead of left to position
44
- */
45
- useCssRight?: boolean;
46
- /**
47
- * Whether use css bottom instead of top to position
48
- */
49
- useCssBottom?: boolean;
50
- /**
51
- * Whether use css transform instead of left/top/right/bottom to position if browser supports.
52
- * Defaults to false.
53
- */
54
- useCssTransform?: boolean;
55
- ignoreShake?: boolean;
56
- }
57
- export interface ArrowTypeOuter {
58
- className?: string;
59
- }
60
- export declare type ArrowType = ArrowTypeOuter & {
61
- x?: number;
62
- y?: number;
63
- };
64
- export declare type BuildInPlacements = Record<string, AlignType>;
65
- export declare type StretchType = string;
66
- export declare type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';
67
- export declare type AnimationType = string;
68
- export declare type TransitionNameType = string;
69
- export interface Point {
70
- pageX: number;
71
- pageY: number;
72
- }
73
- export interface CommonEventHandler {
74
- remove: () => void;
75
- }
76
- export interface MobileConfig {
77
- /** Set popup motion. You can ref `rc-motion` for more info. */
78
- popupMotion?: CSSMotionProps;
79
- popupClassName?: string;
80
- popupStyle?: React.CSSProperties;
81
- popupRender?: (originNode: React.ReactNode) => React.ReactNode;
82
- }
package/lib/mock.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import * as React from 'react';
2
- declare const _default: React.ForwardRefExoticComponent<import("./index").TriggerProps & React.RefAttributes<import("./index").TriggerRef>>;
3
- export default _default;
package/lib/util.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import type { CSSMotionProps } from 'rc-motion';
2
- import type { AlignType, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
3
- export declare function getAlignPopupClassName(builtinPlacements: BuildInPlacements, prefixCls: string, align: AlignType, isAlignPoint: boolean): string;
4
- /** @deprecated We should not use this if we can refactor all deps */
5
- export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
6
- export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
7
- /**
8
- * Get all the scrollable parent elements of the element
9
- * @param ele The element to be detected
10
- * @param areaOnly Only return the parent which will cut visible area
11
- */
12
- export declare function collectScroller(ele: HTMLElement): HTMLElement[];
13
- export declare function toNum(num: number): number;
14
- export interface VisibleArea {
15
- left: number;
16
- top: number;
17
- right: number;
18
- bottom: number;
19
- }
20
- export declare function getVisibleArea(initArea: VisibleArea, scrollerList?: HTMLElement[]): {
21
- left: number;
22
- top: number;
23
- right: number;
24
- bottom: number;
25
- };