Skip to content

Commit

Permalink
feat: replace getTargetElement import
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxingkang committed Aug 28, 2022
1 parent cb5b5e0 commit 1e32a33
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 70 deletions.
1 change: 1 addition & 0 deletions hooks/useClickAway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-latest": "0.2.4"
},
Expand Down
4 changes: 2 additions & 2 deletions hooks/useClickAway/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useLatest } from '@pansy/use-latest';
import { getTargetElement } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
// eslint-disable-next-line @typescript-eslint/no-duplicate-imports
import { useEffectWithTarget } from '@pansy/hook-utils';

import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

/**
* 监听目标元素外的点击事件
Expand Down
1 change: 1 addition & 0 deletions hooks/useEventListener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-latest": "0.2.4"
},
Expand Down
4 changes: 2 additions & 2 deletions hooks/useEventListener/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-undef */
import { useLatest } from '@pansy/use-latest';
import { getTargetElement } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
// eslint-disable-next-line @typescript-eslint/no-duplicate-imports
import { useEffectWithTarget } from '@pansy/hook-utils';

import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

type noop = (...p: any) => void;

Expand Down
2 changes: 1 addition & 1 deletion hooks/useHover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/hook-utils": "0.3.0",
"@pansy/shared": "^1.2.0",
"@pansy/use-boolean": "0.2.5",
"@pansy/use-event-listener": "0.2.8"
},
Expand Down
3 changes: 2 additions & 1 deletion hooks/useHover/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useBoolean } from '@pansy/use-boolean';
import { useEventListener } from '@pansy/use-event-listener';
import type { BasicTarget } from '@pansy/hook-utils';

import type { BasicTarget } from '@pansy/shared/react';

export interface Options {
onEnter?: () => void;
Expand Down
1 change: 1 addition & 0 deletions hooks/useInViewport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/hook-utils": "0.3.0",
"intersection-observer": "^0.12.0"
},
Expand Down
5 changes: 3 additions & 2 deletions hooks/useInViewport/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'intersection-observer';
import { useState } from 'react';
import { getTargetElement, useEffectWithTarget } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
import { useEffectWithTarget } from '@pansy/hook-utils';

import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

export interface Options {
rootMargin?: string;
Expand Down
1 change: 1 addition & 0 deletions hooks/useKeyPress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-latest": "0.2.4"
},
Expand Down
3 changes: 2 additions & 1 deletion hooks/useKeyPress/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLatest } from '@pansy/use-latest';
import { useDeepCompareEffectWithTarget, getTargetElement } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
import { useDeepCompareEffectWithTarget } from '@pansy/hook-utils';

import { genKeyFormater } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion hooks/useKeyPress/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

export type KeyType = number | string;

Expand Down
2 changes: 1 addition & 1 deletion hooks/useMouse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/hook-utils": "0.3.0",
"@pansy/shared": "^1.2.0",
"@pansy/use-event-listener": "0.2.8",
"@pansy/use-raf-state": "0.2.5"
},
Expand Down
4 changes: 2 additions & 2 deletions hooks/useMouse/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useRafState } from '@pansy/use-raf-state';
import { useEventListener } from '@pansy/use-event-listener';
import { getTargetElement } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';

import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';
import type { CursorState } from './types';

const initState: CursorState = {
Expand Down
1 change: 1 addition & 0 deletions hooks/useScroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@pansy/hook-utils": "0.3.0",
"@pansy/shared": "^1.2.0",
"@pansy/use-latest": "0.2.4",
"@pansy/use-raf-state": "0.2.5"
},
Expand Down
3 changes: 2 additions & 1 deletion hooks/useScroll/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useLatest } from '@pansy/use-latest';
import { useRafState } from '@pansy/use-raf-state';
import { getTargetElement, useEffectWithTarget } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
import { useEffectWithTarget } from '@pansy/hook-utils';

import type { Position, ScrollListenController, Target } from './types';

Expand Down
2 changes: 1 addition & 1 deletion hooks/useScroll/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

export interface Position {
left: number;
Expand Down
5 changes: 3 additions & 2 deletions hooks/useScrollLock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"react": "^16.8.6 || ^17.0"
},
"dependencies": {
"@pansy/hook-utils": "^0.3.0",
"@pansy/shared": "^1.1.0"
"@pansy/use-get-state": "^0.2.5",
"@pansy/use-event-listener": "^0.2.8",
"@pansy/shared": "^1.2.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
6 changes: 3 additions & 3 deletions hooks/useScrollLock/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useMemo, useEffect } from 'react';
import { getTargetElement } from '@pansy/hook-utils';
import { isIOS } from '@pansy/shared';
import { getTargetElement } from '@pansy/shared/react';
import { useGetState } from '@pansy/use-get-state';
import { useEventListener } from '@pansy/use-event-listener';
import { isIOS } from '@pansy/shared';

import type { CSSProperties } from 'react';
import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

export function useScrollLock(
target: BasicTarget,
Expand Down
1 change: 1 addition & 0 deletions hooks/useSize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@juggle/resize-observer": "^3.3.1",
"@pansy/shared": "^1.2.0",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-raf-state": "0.2.5"
},
Expand Down
5 changes: 3 additions & 2 deletions hooks/useSize/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ResizeObserver } from '@juggle/resize-observer';
import { useRafState } from '@pansy/use-raf-state';
import { getTargetElement, useIsomorphicLayoutEffectWithTarget } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
import { useIsomorphicLayoutEffectWithTarget } from '@pansy/hook-utils';

import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

export interface Size {
width: number;
Expand Down
3 changes: 2 additions & 1 deletion hooks/useWatermark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-memoized-fn": "0.2.5",
"@pansy/use-unmount": "0.2.5",
"@pansy/watermark": "^2.0.10"
"@pansy/watermark": "^2.2.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
5 changes: 3 additions & 2 deletions hooks/useWatermark/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useRef } from 'react';
import { Watermark, WatermarkOptions } from '@pansy/watermark'
import { getTargetElement, useEffectWithTarget } from '@pansy/hook-utils';
import { getTargetElement } from '@pansy/shared/react';
import { useEffectWithTarget } from '@pansy/hook-utils';
import { useUnmount } from '@pansy/use-unmount';
import { useMemoizedFn } from '@pansy/use-memoized-fn';

import type { BasicTarget } from '@pansy/hook-utils';
import type { BasicTarget } from '@pansy/shared/react';

export type BaseWatermarkOptions = Omit<WatermarkOptions, 'container'>

Expand Down
1 change: 1 addition & 0 deletions hooks/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/use-memoized-fn": "0.2.5",
"@pansy/use-unmount": "0.2.5",
"@pansy/use-update-effect": "0.2.4",
Expand Down
2 changes: 0 additions & 2 deletions hooks/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { createUpdateEffect } from '@pansy/use-update-effect';
export { createUseStorageState } from './utils/createUseStorageState';
export { depsAreSame } from './utils/depsAreSame';
export { getTargetElement } from './utils/domTarget';
export { isBrowser } from './utils/isBrowser';
export {
createEffectWithTarget,
Expand All @@ -15,6 +14,5 @@ export { isFunction } from './utils/isFunction';

export { createDeepCompareEffect } from './createDeepCompareEffect';

export type { BasicTarget } from './utils/domTarget';
export type { OptionsWithDefaultValue, Options } from './utils/createUseStorageState';
export type { Noop } from './types';
37 changes: 0 additions & 37 deletions hooks/utils/src/utils/domTarget.ts

This file was deleted.

2 changes: 1 addition & 1 deletion hooks/utils/src/utils/useDeepCompareWithTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isEqual from 'lodash/isEqual';
import { useEffectWithTarget } from './useEffectWithTarget';

import type { DependencyList, EffectCallback } from 'react';
import type { BasicTarget } from './domTarget';
import type { BasicTarget } from '@pansy/shared/react';

const depsEqual = (aDeps: DependencyList, bDeps: DependencyList = []) => {
return isEqual(aDeps, bDeps);
Expand Down
4 changes: 2 additions & 2 deletions hooks/utils/src/utils/useEffectWithTarget.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useLayoutEffect, useRef } from 'react';
import { useUnmount } from '@pansy/use-unmount';
import { depsAreSame } from './depsAreSame';
import { getTargetElement } from './domTarget';
import { getTargetElement } from '@pansy/shared/react';

import type { DependencyList, EffectCallback } from 'react';
import type { BasicTarget } from './domTarget';
import type { BasicTarget } from '@pansy/shared/react';

export const createEffectWithTarget = (
useEffectType: typeof useEffect | typeof useLayoutEffect
Expand Down
Loading

0 comments on commit 1e32a33

Please sign in to comment.