Skip to content

Commit 45ebc94

Browse files
authored
Avoid rc package deep imports (#732)
* fix: avoid rc package deep imports * chore: address import review comments
1 parent 88c6a43 commit 45ebc94

15 files changed

Lines changed: 77 additions & 60 deletions

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
},
4747
"dependencies": {
4848
"@rc-component/mini-decimal": "^1.1.1",
49-
"@rc-component/util": "^1.4.0",
49+
"@rc-component/util": "^1.11.1",
5050
"clsx": "^2.1.1"
5151
},
5252
"devDependencies": {
53-
"@rc-component/father-plugin": "^2.0.2",
53+
"@rc-component/father-plugin": "^2.2.0",
5454
"@rc-component/np": "^1.0.3",
5555
"@swc-node/jest": "^1.5.5",
5656
"@testing-library/jest-dom": "^6.1.5",

src/InputNumber.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import getMiniDecimal, {
66
validateNumber,
77
ValueType,
88
} from '@rc-component/mini-decimal';
9-
import { useLayoutUpdateEffect } from '@rc-component/util/lib/hooks/useLayoutEffect';
10-
import proxyObject from '@rc-component/util/lib/proxyObject';
9+
import {
10+
type InputFocusOptions,
11+
proxyObject,
12+
triggerFocus,
13+
useEvent,
14+
useLayoutUpdateEffect,
15+
} from '@rc-component/util';
1116
import { clsx } from 'clsx';
1217
import * as React from 'react';
1318
import useCursor from './hooks/useCursor';
1419
import StepHandler from './StepHandler';
1520
import { getDecupleSteps } from './utils/numberUtil';
1621

17-
import { useEvent } from '@rc-component/util';
18-
import { triggerFocus, type InputFocusOptions } from '@rc-component/util/lib/Dom/focus';
1922
import useFrame from './hooks/useFrame';
2023

2124
export type { ValueType };

src/StepHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/no-unknown-property */
2-
import raf from '@rc-component/util/lib/raf';
2+
import { raf } from '@rc-component/util';
33
import { clsx } from 'clsx';
44
import * as React from 'react';
55

src/hooks/useCursor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { warning } from '@rc-component/util';
12
import { useRef } from 'react';
2-
import warning from '@rc-component/util/lib/warning';
33
/**
44
* Keep input cursor in the correct position if possible.
55
* Is this necessary since we have `formatter` which may mass the content?

src/hooks/useFrame.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useRef, useEffect } from 'react';
2-
import raf from '@rc-component/util/lib/raf';
1+
import { raf } from '@rc-component/util';
2+
import { useEffect, useRef } from 'react';
33

44
/**
55
* Always trigger latest once when call multiple time

tests/click.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { render, fireEvent, act } from '@testing-library/react';
33
import InputNumber, { InputNumberProps } from '../src';
4-
import KeyCode from '@rc-component/util/lib/KeyCode';
4+
import { KeyCode } from '@rc-component/util';
55

66
jest.mock('@rc-component/mini-decimal/lib/supportUtil');
77
const { supportBigInt } = require('@rc-component/mini-decimal/lib/supportUtil');
@@ -37,7 +37,7 @@ describe('InputNumber.Click', () => {
3737
fireEvent.click(container.querySelector(selector));
3838
expect(onChange).toHaveBeenCalledTimes(1);
3939
expect(onChange).toHaveBeenCalledWith(changedValue);
40-
expect(onStep).toHaveBeenCalledWith(changedValue, { offset: 1, type: stepType, emitter });
40+
expect(onStep).toHaveBeenCalledWith(changedValue, { offset: 1, type: stepType, emitter });
4141
unmount();
4242
});
4343
}
@@ -186,7 +186,7 @@ describe('InputNumber.Click', () => {
186186
});
187187

188188
expect(onChange).toHaveBeenCalledWith(1.1);
189-
expect(onStep).toHaveBeenCalledWith(1.1, { offset: '0.1', type: 'down', emitter: 'keyboard' });
189+
expect(onStep).toHaveBeenCalledWith(1.1, { offset: '0.1', type: 'down', emitter: 'keyboard' });
190190
});
191191

192192
it('click up button with pressing shift key', () => {

tests/cursor.test.tsx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { KeyCode } from '@rc-component/util';
12
import React from 'react';
2-
import KeyCode from '@rc-component/util/lib/KeyCode';
3-
import { render, fireEvent } from './util/wrapper';
43
import InputNumber from '../src';
4+
import { fireEvent, render } from './util/wrapper';
55

66
describe('InputNumber.Cursor', () => {
77
function cursorInput(input: HTMLInputElement, pos?: number) {
8-
98
if (pos !== undefined) {
109
input.setSelectionRange(pos, pos);
1110
}
@@ -17,12 +16,12 @@ describe('InputNumber.Cursor', () => {
1716
changeValue: string,
1817
cursorPos: number,
1918
which?: number,
20-
key?: number|string,
19+
key?: number | string,
2120
) {
22-
fireEvent.focus(input)
23-
fireEvent.keyDown(input,{which,keyCode:which,key})
24-
fireEvent.change(input,{ target: { value: changeValue, selectionStart: 1 }})
25-
fireEvent.keyUp(input,{which,keyCode:which,key})
21+
fireEvent.focus(input);
22+
fireEvent.keyDown(input, { which, keyCode: which, key });
23+
fireEvent.change(input, { target: { value: changeValue, selectionStart: 1 } });
24+
fireEvent.keyUp(input, { which, keyCode: which, key });
2625
}
2726

2827
// https://github.com/react-component/input-number/issues/235
@@ -42,12 +41,14 @@ describe('InputNumber.Cursor', () => {
4241
describe('pre-pend string', () => {
4342
it('quick typing', () => {
4443
// `$ ` => `9$ ` => `$ 9`
45-
const { container } = render(<InputNumber defaultValue="$ " formatter={(val) => `$ ${val}`} />);
44+
const { container } = render(
45+
<InputNumber defaultValue="$ " formatter={(val) => `$ ${val}`} />,
46+
);
4647
const input = container.querySelector('input');
47-
fireEvent.focus(input)
48+
fireEvent.focus(input);
4849
cursorInput(input, 0);
49-
changeOnPos(input, '9$ ', 1, KeyCode.NUM_ONE,'1');
50-
expect(cursorInput(input,3)).toEqual(3);
50+
changeOnPos(input, '9$ ', 1, KeyCode.NUM_ONE, '1');
51+
expect(cursorInput(input, 3)).toEqual(3);
5152
});
5253

5354
describe('[LEGACY]', () => {
@@ -70,50 +71,55 @@ describe('InputNumber.Cursor', () => {
7071

7172
const { container } = render(<Demo />);
7273
const input = container.querySelector('input');
73-
fireEvent.focus(input)
74+
fireEvent.focus(input);
7475
for (let i = 0; i < prependValue.length; i += 1) {
75-
fireEvent.keyDown(input,{which: KeyCode.ONE,keyCode: KeyCode.ONE})
76+
fireEvent.keyDown(input, { which: KeyCode.ONE, keyCode: KeyCode.ONE });
7677
}
7778

7879
const finalValue = prependValue + initValue;
7980
cursorInput(input, prependValue.length);
80-
fireEvent.change(input,{ target: { value: finalValue } });
81+
fireEvent.change(input, { target: { value: finalValue } });
8182

8283
return input;
8384
};
8485

8586
it('should fix caret position on case 1', () => {
8687
// '$ 1'
8788
const input = setUpCursorTest('', '1');
88-
expect(cursorInput(input,3)).toEqual(3);
89+
expect(cursorInput(input, 3)).toEqual(3);
8990
});
9091

9192
it('should fix caret position on case 2', () => {
9293
// '$ 111'
9394
const input = setUpCursorTest('', '111');
94-
expect(cursorInput(input,5)).toEqual(5);
95+
expect(cursorInput(input, 5)).toEqual(5);
9596
});
9697

9798
it('should fix caret position on case 3', () => {
9899
// '$ 111'
99100
const input = setUpCursorTest('1', '11');
100-
expect(cursorInput(input,4)).toEqual(4);
101+
expect(cursorInput(input, 4)).toEqual(4);
101102
});
102103

103104
it('should fix caret position on case 4', () => {
104105
// '$ 123,456'
105106
const input = setUpCursorTest('456', '123');
106-
expect(cursorInput(input,6)).toEqual(6);
107+
expect(cursorInput(input, 6)).toEqual(6);
107108
});
108109
});
109110
});
110111

111112
describe('append string', () => {
112113
it('position caret before appended characters', () => {
113-
const { container } = render(<InputNumber formatter={(value) => `${value}%`} parser={(value) => value.replace('%', '')} />);
114+
const { container } = render(
115+
<InputNumber
116+
formatter={(value) => `${value}%`}
117+
parser={(value) => value.replace('%', '')}
118+
/>,
119+
);
114120
const input = container.querySelector('input');
115121
fireEvent.focus(input);
116-
fireEvent.change(input,{ target: { value: '5' } });
122+
fireEvent.change(input, { target: { value: '5' } });
117123
expect(cursorInput(input)).toEqual(1);
118124
});
119125
});

tests/focus.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { spyElementPrototypes } from '@rc-component/util';
12
import { fireEvent, render } from '@testing-library/react';
2-
import InputNumber, { InputNumberRef } from '../src';
3-
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
43
import React from 'react';
4+
import InputNumber, { InputNumberRef } from '../src';
55

66
const getInputRef = () => {
77
const ref = React.createRef<InputNumberRef>();

tests/formatter.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import KeyCode from '@rc-component/util/lib/KeyCode';
1+
import { KeyCode } from '@rc-component/util';
22
import React from 'react';
33
import InputNumber from '../src';
44
import { fireEvent, render } from './util/wrapper';

tests/github.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import KeyCode from '@rc-component/util/lib/KeyCode';
1+
import { KeyCode } from '@rc-component/util';
22
import React from 'react';
33
import InputNumber from '../src';
44
import { act, fireEvent, render, screen, waitFor } from './util/wrapper';

0 commit comments

Comments
 (0)