Skip to content

Commit 68434a6

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/minimist-1.2.8
2 parents 40f0545 + 2c12236 commit 68434a6

7 files changed

Lines changed: 483 additions & 245 deletions

File tree

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"presets": [
33
"@babel/preset-react",
44
"@babel/preset-typescript",
5-
["@babel/preset-env", { "targets": "defaults" }],
6-
"babel-preset-minify"
5+
["@babel/preset-env", { "targets": "defaults" }]
76
]
87
}

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
22
"name": "react-daum-postcode",
3-
"version": "3.1.1",
3+
"version": "3.1.3",
44
"description": "Daum Postcode service for React",
5-
"main": "./lib/index.js",
5+
"main": "./lib/index.cjs.js",
66
"types": "./lib/index.d.ts",
7+
"module": "./lib/index.esm.js",
78
"files": [
89
"lib"
910
],
1011
"scripts": {
11-
"build": "concurrently \"yarn:build:*\"",
12-
"build:babel": "babel src -d lib --extensions \".ts,.tsx\"",
13-
"build:types": "tsc --declarationDir lib"
12+
"build": "rollup -c"
1413
},
1514
"author": "kimminsik-bernard",
1615
"contributors": [
@@ -45,6 +44,10 @@
4544
{
4645
"name": "TaeSang Cho",
4746
"url": "https://github.com/Web-Engine"
47+
},
48+
{
49+
"name": "HK1211",
50+
"url": "https://github.com/HK1211"
4851
}
4952
],
5053
"repository": {
@@ -69,10 +72,12 @@
6972
"@babel/preset-env": "^7.14.9",
7073
"@babel/preset-react": "^7.14.5",
7174
"@babel/preset-typescript": "^7.14.5",
75+
"@rollup/plugin-babel": "^6.0.4",
76+
"@rollup/plugin-terser": "^0.4.4",
77+
"@rollup/plugin-typescript": "^12.1.1",
7278
"@types/react": "^17.0.15",
7379
"@typescript-eslint/eslint-plugin": "^4.29.0",
7480
"@typescript-eslint/parser": "^4.29.0",
75-
"babel-preset-minify": "^0.5.1",
7681
"concurrently": "^6.2.0",
7782
"eslint": "^7.32.0",
7883
"eslint-config-airbnb": "^18.2.1",
@@ -82,6 +87,7 @@
8287
"eslint-plugin-prettier": "^3.4.0",
8388
"eslint-plugin-react": "^7.24.0",
8489
"eslint-plugin-react-hooks": "^4.2.0",
90+
"rollup": "^4.28.1",
8591
"typescript": "^4.3.5"
8692
}
8793
}

rollup.config.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import babel from '@rollup/plugin-babel';
2+
import typescript from '@rollup/plugin-typescript';
3+
import terser from '@rollup/plugin-terser';
4+
5+
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
6+
7+
export default {
8+
input: 'src/index.ts',
9+
output: [
10+
{
11+
file: 'lib/index.cjs.js',
12+
format: 'cjs',
13+
},
14+
{
15+
file: 'lib/index.esm.js',
16+
format: 'esm',
17+
},
18+
],
19+
plugins: [
20+
babel({extensions, include: 'src' }),
21+
typescript({ declarationDir: 'lib' }),
22+
terser({ format: { comments: false }}),
23+
],
24+
external: ['react'],
25+
};

src/DaumPostcodeEmbed.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type DaumPostcodeProps = DaumPostcodeEmbedProps;
2424

2525
interface State {
2626
hasError: boolean;
27+
completed: boolean;
2728
}
2829

2930
const defaultErrorMessage = <p>현재 Daum 우편번호 서비스를 이용할 수 없습니다. 잠시 후 다시 시도해주세요.</p>;
@@ -41,19 +42,27 @@ const defaultProps = {
4142

4243
class DaumPostcodeEmbed extends Component<DaumPostcodeEmbedProps, State> {
4344
static defaultProps = defaultProps;
45+
/**
46+
* See #61
47+
*/
48+
private mounted = false;
4449

4550
wrap = createRef<HTMLDivElement>();
4651

4752
state = {
4853
hasError: false,
54+
completed: false,
4955
};
5056

5157
componentDidMount() {
5258
const { initiate, onError } = this;
5359
const { scriptUrl } = this.props;
5460

5561
if (!scriptUrl) return;
56-
loadPostcode(scriptUrl).then(initiate).catch(onError);
62+
if (!this.mounted) {
63+
loadPostcode(scriptUrl).then(initiate).catch(onError);
64+
this.mounted = true;
65+
}
5766
}
5867

5968
initiate = (Postcode: PostcodeConstructor) => {
@@ -65,7 +74,7 @@ class DaumPostcodeEmbed extends Component<DaumPostcodeEmbedProps, State> {
6574
...options,
6675
oncomplete: (address) => {
6776
if (onComplete) onComplete(address);
68-
if (autoClose && this.wrap.current) this.wrap.current.remove();
77+
this.setState({ completed: true });
6978
},
7079
onsearch: onSearch,
7180
onresize: onResize,
@@ -83,8 +92,10 @@ class DaumPostcodeEmbed extends Component<DaumPostcodeEmbedProps, State> {
8392
};
8493

8594
render() {
86-
const { className, style, errorMessage } = this.props;
87-
const { hasError } = this.state;
95+
const { className, style, errorMessage, autoClose } = this.props;
96+
const { hasError, completed } = this.state;
97+
98+
if (autoClose === true && completed === true) return null;
8899

89100
return (
90101
<div ref={this.wrap} className={className} style={{ ...defaultStyle, ...style }}>

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import DaumPostcodeEmbed, { DaumPostcodeEmbedProps, DaumPostcodeProps } from './DaumPostcodeEmbed';
2-
import useDaumPostcodePopup, { DaumPostcodePopupParams } from './useDaumPostcodePopup';
3-
import loadPostcode, { Address, Search, State } from './loadPostcode';
1+
import DaumPostcodeEmbed from './DaumPostcodeEmbed';
2+
import useDaumPostcodePopup from './useDaumPostcodePopup';
3+
import loadPostcode from './loadPostcode';
44

5-
export type { DaumPostcodeEmbedProps, DaumPostcodeProps, DaumPostcodePopupParams, Address, Search, State };
65
export { loadPostcode, DaumPostcodeEmbed, useDaumPostcodePopup };
76
export default DaumPostcodeEmbed;
7+
8+
import type { DaumPostcodeEmbedProps, DaumPostcodeProps } from './DaumPostcodeEmbed';
9+
import type { DaumPostcodePopupParams } from './useDaumPostcodePopup';
10+
import type { Address, Search, State } from './loadPostcode';
11+
12+
export type { DaumPostcodeEmbedProps, DaumPostcodeProps, DaumPostcodePopupParams, Address, Search, State };

src/loadPostcode.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface PostcodeOptions {
7979
onclose?: (state: State) => void;
8080
onsearch?: (search: Search) => void;
8181
width?: string | number;
82+
minWidth?: number;
8283
height?: string | number;
8384
animation?: boolean;
8485
focusInput?: boolean;
@@ -130,21 +131,21 @@ const loadPostcode = (function () {
130131
let promise: Promise<PostcodeConstructor> | null = null;
131132

132133
return function (url: string = postcodeScriptUrl): Promise<PostcodeConstructor> {
133-
if( promise ) return promise;
134+
if (promise) return promise;
134135

135136
promise = new Promise((resolve, reject) => {
136137
const script = document.createElement('script');
137138
script.src = url;
138139
script.onload = () => {
139-
if( window?.daum?.Postcode ) {
140+
if (window?.daum?.Postcode) {
140141
return resolve(window.daum.Postcode);
141142
}
142-
reject(new Error('Script is loaded successfully, but cannot find Postcode module. Check your scriptURL property.'))
143+
reject(new Error('Script is loaded successfully, but cannot find Postcode module. Check your scriptURL property.'));
143144
};
144145
script.onerror = (error) => reject(error);
145146
script.id = scriptId;
146147
document.body.appendChild(script);
147-
})
148+
});
148149

149150
return promise;
150151
};

0 commit comments

Comments
 (0)