@cp949/japanpost-react 1.0.0
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/LICENSE +15 -0
- package/README.md +500 -0
- package/dist/components/AddressSearchInput.d.ts +7 -0
- package/dist/components/AddressSearchInput.d.ts.map +1 -0
- package/dist/components/PostalCodeInput.d.ts +7 -0
- package/dist/components/PostalCodeInput.d.ts.map +1 -0
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/formatters.d.ts +12 -0
- package/dist/core/formatters.d.ts.map +1 -0
- package/dist/core/normalizers.d.ts +7 -0
- package/dist/core/normalizers.d.ts.map +1 -0
- package/dist/core/types.d.ts +182 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/validators.d.ts +6 -0
- package/dist/core/validators.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +431 -0
- package/dist/index.umd.cjs +6 -0
- package/dist/react/toJapanAddressError.d.ts +7 -0
- package/dist/react/toJapanAddressError.d.ts.map +1 -0
- package/dist/react/useJapanAddress.d.ts +7 -0
- package/dist/react/useJapanAddress.d.ts.map +1 -0
- package/dist/react/useJapanAddressSearch.d.ts +7 -0
- package/dist/react/useJapanAddressSearch.d.ts.map +1 -0
- package/dist/react/useJapanPostalCode.d.ts +7 -0
- package/dist/react/useJapanPostalCode.d.ts.map +1 -0
- package/dist/react/useLatestRequestState.d.ts +17 -0
- package/dist/react/useLatestRequestState.d.ts.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 일본우정 API에서 반환되는 원본 주소 레코드 형태.
|
|
4
|
+
* 공개 API 표면에는 직접 노출하지 않고 내부에서만 사용한다.
|
|
5
|
+
*/
|
|
6
|
+
export type JapanPostApiAddressRecord = {
|
|
7
|
+
zip_code?: string | number | null;
|
|
8
|
+
pref_code?: string | number | null;
|
|
9
|
+
pref_name?: string | null;
|
|
10
|
+
pref_kana?: string | null;
|
|
11
|
+
city_name?: string | null;
|
|
12
|
+
city_kana?: string | null;
|
|
13
|
+
town_name?: string | null;
|
|
14
|
+
town_kana?: string | null;
|
|
15
|
+
block_name?: string | null;
|
|
16
|
+
other_name?: string | null;
|
|
17
|
+
address?: string | null;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 우편번호로 주소를 검색할 때(searchcode) API 응답 형태.
|
|
21
|
+
*/
|
|
22
|
+
export type JapanPostSearchCodeResponse = {
|
|
23
|
+
addresses?: JapanPostApiAddressRecord[] | null;
|
|
24
|
+
message?: string | null;
|
|
25
|
+
status?: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 주소 키워드로 검색할 때(addresszip) API 응답 형태.
|
|
29
|
+
*/
|
|
30
|
+
export type JapanPostAddressZipResponse = {
|
|
31
|
+
addresses?: JapanPostApiAddressRecord[] | null;
|
|
32
|
+
message?: string | null;
|
|
33
|
+
status?: number;
|
|
34
|
+
};
|
|
35
|
+
export type JapanPostApiResponse = JapanPostSearchCodeResponse | JapanPostAddressZipResponse;
|
|
36
|
+
/**
|
|
37
|
+
* API 응답을 정규화한 후의 중간 주소 레코드 형태.
|
|
38
|
+
* 내부 data source 처리 후 공개 JapanAddress 타입으로 변환되기 전에 사용된다.
|
|
39
|
+
*/
|
|
40
|
+
export type NormalizedJapanAddressRecord = {
|
|
41
|
+
postalCode: string;
|
|
42
|
+
prefecture: string;
|
|
43
|
+
prefectureKana?: string;
|
|
44
|
+
city: string;
|
|
45
|
+
cityKana?: string;
|
|
46
|
+
town: string;
|
|
47
|
+
townKana?: string;
|
|
48
|
+
detail?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 라이브러리 공개 주소 타입. 훅과 클라이언트가 외부로 반환하는 최종 형태.
|
|
52
|
+
*/
|
|
53
|
+
export type JapanAddress = {
|
|
54
|
+
postalCode: string;
|
|
55
|
+
prefecture: string;
|
|
56
|
+
prefectureKana?: string;
|
|
57
|
+
city: string;
|
|
58
|
+
cityKana?: string;
|
|
59
|
+
town: string;
|
|
60
|
+
townKana?: string;
|
|
61
|
+
address: string;
|
|
62
|
+
provider: "japan-post";
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 우편번호 조회 결과. 하나의 우편번호에 여러 주소가 대응될 수 있다.
|
|
66
|
+
*/
|
|
67
|
+
export type JapanPostalCodeLookupResult = {
|
|
68
|
+
postalCode: string;
|
|
69
|
+
addresses: JapanAddress[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 키워드 주소 검색 결과.
|
|
73
|
+
*/
|
|
74
|
+
export type JapanAddressSearchResult = {
|
|
75
|
+
query: string;
|
|
76
|
+
addresses: JapanAddress[];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 라이브러리 전용 오류 코드 목록.
|
|
80
|
+
*/
|
|
81
|
+
export type JapanAddressErrorCode = "invalid_postal_code" | "invalid_query" | "network_error" | "timeout" | "not_found" | "bad_response" | "data_source_error";
|
|
82
|
+
/**
|
|
83
|
+
* 라이브러리 전용 에러 타입. 훅과 data source 전반에서 일관되게 사용된다.
|
|
84
|
+
*/
|
|
85
|
+
export type JapanAddressError = Error & {
|
|
86
|
+
name: "JapanAddressError";
|
|
87
|
+
code: JapanAddressErrorCode;
|
|
88
|
+
cause?: unknown;
|
|
89
|
+
status?: number;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* data source 요청에 전달할 선택 옵션.
|
|
93
|
+
*/
|
|
94
|
+
export type JapanAddressRequestOptions = {
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* 주소 데이터를 제공하는 data source 인터페이스.
|
|
99
|
+
* 커스텀 구현체로 교체할 수 있도록 추상화되어 있다.
|
|
100
|
+
*/
|
|
101
|
+
export type JapanAddressDataSource = {
|
|
102
|
+
lookupPostalCode: (postalCode: string, options?: JapanAddressRequestOptions) => Promise<JapanAddress[]>;
|
|
103
|
+
searchAddress: (query: string, options?: JapanAddressRequestOptions) => Promise<JapanAddress[]>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* useJapanPostalCode 훅 옵션
|
|
107
|
+
*/
|
|
108
|
+
export type UseJapanPostalCodeOptions = {
|
|
109
|
+
dataSource: JapanAddressDataSource;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* useJapanAddressSearch 훅 옵션
|
|
113
|
+
*/
|
|
114
|
+
export type UseJapanAddressSearchOptions = {
|
|
115
|
+
dataSource: JapanAddressDataSource;
|
|
116
|
+
debounceMs?: number;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* useJapanAddress 훅 옵션
|
|
120
|
+
*/
|
|
121
|
+
export type UseJapanAddressOptions = {
|
|
122
|
+
dataSource: JapanAddressDataSource;
|
|
123
|
+
debounceMs?: number;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 비동기 데이터 로딩 상태를 표현하는 제네릭 타입.
|
|
127
|
+
*/
|
|
128
|
+
export type UseAsyncState<T> = {
|
|
129
|
+
loading: boolean;
|
|
130
|
+
data: T | null;
|
|
131
|
+
error: JapanAddressError | null;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* useJapanPostalCode 훅의 반환 타입
|
|
135
|
+
*/
|
|
136
|
+
export type UseJapanPostalCodeResult = UseAsyncState<JapanPostalCodeLookupResult> & {
|
|
137
|
+
reset: () => void;
|
|
138
|
+
search: (value: string) => Promise<JapanPostalCodeLookupResult | null>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* useJapanAddressSearch 훅의 반환 타입
|
|
142
|
+
*/
|
|
143
|
+
export type UseJapanAddressSearchResult = UseAsyncState<JapanAddressSearchResult> & {
|
|
144
|
+
reset: () => void;
|
|
145
|
+
search: (query: string) => Promise<JapanAddressSearchResult | null>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* useJapanAddress 훅의 반환 타입 (우편번호·키워드 통합)
|
|
149
|
+
*/
|
|
150
|
+
export type UseJapanAddressResult = UseAsyncState<JapanPostalCodeLookupResult | JapanAddressSearchResult> & {
|
|
151
|
+
reset: () => void;
|
|
152
|
+
searchByPostalCode: (value: string) => Promise<JapanPostalCodeLookupResult | null>;
|
|
153
|
+
searchByKeyword: (query: string) => Promise<JapanAddressSearchResult | null>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* 검색 입력 컴포넌트들이 공유하는 공통 props
|
|
157
|
+
*/
|
|
158
|
+
type BaseTextSearchInputProps = {
|
|
159
|
+
defaultValue?: string;
|
|
160
|
+
value?: string;
|
|
161
|
+
disabled?: boolean;
|
|
162
|
+
label?: ReactNode;
|
|
163
|
+
buttonLabel?: ReactNode;
|
|
164
|
+
inputProps?: Omit<ComponentPropsWithoutRef<"input">, "defaultValue" | "disabled" | "onChange" | "value">;
|
|
165
|
+
buttonProps?: Omit<ComponentPropsWithoutRef<"button">, "children" | "disabled" | "onClick" | "type">;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* PostalCodeInput 컴포넌트 props
|
|
169
|
+
*/
|
|
170
|
+
export type PostalCodeInputProps = BaseTextSearchInputProps & {
|
|
171
|
+
onChange?: (postalCode: string) => void;
|
|
172
|
+
onSearch: (postalCode: string) => void;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* AddressSearchInput 컴포넌트 props
|
|
176
|
+
*/
|
|
177
|
+
export type AddressSearchInputProps = BaseTextSearchInputProps & {
|
|
178
|
+
onChange?: (query: string) => void;
|
|
179
|
+
onSearch: (query: string) => void;
|
|
180
|
+
};
|
|
181
|
+
export {};
|
|
182
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","s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CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAKnC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/core/validators.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAG7D"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { AddressSearchInput } from './components/AddressSearchInput';
|
|
2
|
+
export { PostalCodeInput } from './components/PostalCodeInput';
|
|
3
|
+
export { createJapanAddressError } from './core/errors';
|
|
4
|
+
export { formatJapanPostalCode, normalizeJapanPostalCode, } from './core/formatters';
|
|
5
|
+
export { normalizeJapanPostAddressRecord } from './core/normalizers';
|
|
6
|
+
export type { AddressSearchInputProps, JapanAddress, JapanAddressDataSource, JapanAddressError, JapanAddressErrorCode, JapanAddressRequestOptions, JapanAddressSearchResult, JapanPostalCodeLookupResult, NormalizedJapanAddressRecord, PostalCodeInputProps, UseJapanAddressOptions, UseJapanAddressResult, UseJapanAddressSearchOptions, UseJapanAddressSearchResult, UseJapanPostalCodeOptions, UseJapanPostalCodeResult, } from './core/types';
|
|
7
|
+
export { isValidJapanPostalCode } from './core/validators';
|
|
8
|
+
export { useJapanAddress } from './react/useJapanAddress';
|
|
9
|
+
export { useJapanAddressSearch } from './react/useJapanAddressSearch';
|
|
10
|
+
export { useJapanPostalCode } from './react/useJapanPostalCode';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAGrE,YAAY,EACV,uBAAuB,EACvB,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,2BAA2B,EAC3B,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var a = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), o = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
4
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
5
|
+
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
6
|
+
}), s = /* @__PURE__ */ a(((e) => {
|
|
7
|
+
var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
8
|
+
function r(e, n, r) {
|
|
9
|
+
var i = null;
|
|
10
|
+
if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
|
|
11
|
+
else r = n;
|
|
12
|
+
return n = r.ref, {
|
|
13
|
+
$$typeof: t,
|
|
14
|
+
type: e,
|
|
15
|
+
key: i,
|
|
16
|
+
ref: n === void 0 ? null : n,
|
|
17
|
+
props: r
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
e.Fragment = n, e.jsx = r, e.jsxs = r;
|
|
21
|
+
})), c = /* @__PURE__ */ a(((e) => {
|
|
22
|
+
process.env.NODE_ENV !== "production" && (function() {
|
|
23
|
+
function t(e) {
|
|
24
|
+
if (e == null) return null;
|
|
25
|
+
if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
|
|
26
|
+
if (typeof e == "string") return e;
|
|
27
|
+
switch (e) {
|
|
28
|
+
case v: return "Fragment";
|
|
29
|
+
case b: return "Profiler";
|
|
30
|
+
case y: return "StrictMode";
|
|
31
|
+
case w: return "Suspense";
|
|
32
|
+
case T: return "SuspenseList";
|
|
33
|
+
case O: return "Activity";
|
|
34
|
+
}
|
|
35
|
+
if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
|
|
36
|
+
case _: return "Portal";
|
|
37
|
+
case S: return e.displayName || "Context";
|
|
38
|
+
case x: return (e._context.displayName || "Context") + ".Consumer";
|
|
39
|
+
case C:
|
|
40
|
+
var n = e.render;
|
|
41
|
+
return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
|
|
42
|
+
case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
|
|
43
|
+
case D:
|
|
44
|
+
n = e._payload, e = e._init;
|
|
45
|
+
try {
|
|
46
|
+
return t(e(n));
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function n(e) {
|
|
52
|
+
return "" + e;
|
|
53
|
+
}
|
|
54
|
+
function r(e) {
|
|
55
|
+
try {
|
|
56
|
+
n(e);
|
|
57
|
+
var t = !1;
|
|
58
|
+
} catch {
|
|
59
|
+
t = !0;
|
|
60
|
+
}
|
|
61
|
+
if (t) {
|
|
62
|
+
t = console;
|
|
63
|
+
var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
64
|
+
return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function i(e) {
|
|
68
|
+
if (e === v) return "<>";
|
|
69
|
+
if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
|
|
70
|
+
try {
|
|
71
|
+
var n = t(e);
|
|
72
|
+
return n ? "<" + n + ">" : "<...>";
|
|
73
|
+
} catch {
|
|
74
|
+
return "<...>";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function a() {
|
|
78
|
+
var e = A.A;
|
|
79
|
+
return e === null ? null : e.getOwner();
|
|
80
|
+
}
|
|
81
|
+
function s() {
|
|
82
|
+
return Error("react-stack-top-frame");
|
|
83
|
+
}
|
|
84
|
+
function c(e) {
|
|
85
|
+
if (j.call(e, "key")) {
|
|
86
|
+
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
87
|
+
if (t && t.isReactWarning) return !1;
|
|
88
|
+
}
|
|
89
|
+
return e.key !== void 0;
|
|
90
|
+
}
|
|
91
|
+
function l(e, t) {
|
|
92
|
+
function n() {
|
|
93
|
+
P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
|
|
94
|
+
}
|
|
95
|
+
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
96
|
+
get: n,
|
|
97
|
+
configurable: !0
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function u() {
|
|
101
|
+
var e = t(this.type);
|
|
102
|
+
return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
|
|
103
|
+
}
|
|
104
|
+
function d(e, t, n, r, i, a) {
|
|
105
|
+
var o = n.ref;
|
|
106
|
+
return e = {
|
|
107
|
+
$$typeof: g,
|
|
108
|
+
type: e,
|
|
109
|
+
key: t,
|
|
110
|
+
props: n,
|
|
111
|
+
_owner: r
|
|
112
|
+
}, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
|
|
113
|
+
enumerable: !1,
|
|
114
|
+
value: null
|
|
115
|
+
}) : Object.defineProperty(e, "ref", {
|
|
116
|
+
enumerable: !1,
|
|
117
|
+
get: u
|
|
118
|
+
}), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
119
|
+
configurable: !1,
|
|
120
|
+
enumerable: !1,
|
|
121
|
+
writable: !0,
|
|
122
|
+
value: 0
|
|
123
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
124
|
+
configurable: !1,
|
|
125
|
+
enumerable: !1,
|
|
126
|
+
writable: !0,
|
|
127
|
+
value: null
|
|
128
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
129
|
+
configurable: !1,
|
|
130
|
+
enumerable: !1,
|
|
131
|
+
writable: !0,
|
|
132
|
+
value: i
|
|
133
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
134
|
+
configurable: !1,
|
|
135
|
+
enumerable: !1,
|
|
136
|
+
writable: !0,
|
|
137
|
+
value: a
|
|
138
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
139
|
+
}
|
|
140
|
+
function f(e, n, i, o, s, u) {
|
|
141
|
+
var f = n.children;
|
|
142
|
+
if (f !== void 0) if (o) if (M(f)) {
|
|
143
|
+
for (o = 0; o < f.length; o++) p(f[o]);
|
|
144
|
+
Object.freeze && Object.freeze(f);
|
|
145
|
+
} else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
146
|
+
else p(f);
|
|
147
|
+
if (j.call(n, "key")) {
|
|
148
|
+
f = t(e);
|
|
149
|
+
var m = Object.keys(n).filter(function(e) {
|
|
150
|
+
return e !== "key";
|
|
151
|
+
});
|
|
152
|
+
o = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + o] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", o, f, m, f), R[f + o] = !0);
|
|
153
|
+
}
|
|
154
|
+
if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
|
|
155
|
+
else i = n;
|
|
156
|
+
return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), s, u);
|
|
157
|
+
}
|
|
158
|
+
function p(e) {
|
|
159
|
+
m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
160
|
+
}
|
|
161
|
+
function m(e) {
|
|
162
|
+
return typeof e == "object" && !!e && e.$$typeof === g;
|
|
163
|
+
}
|
|
164
|
+
var h = o("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
|
|
165
|
+
return null;
|
|
166
|
+
};
|
|
167
|
+
h = { react_stack_bottom_frame: function(e) {
|
|
168
|
+
return e();
|
|
169
|
+
} };
|
|
170
|
+
var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(i(s)), R = {};
|
|
171
|
+
e.Fragment = v, e.jsx = function(e, t, n) {
|
|
172
|
+
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
173
|
+
return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
174
|
+
}, e.jsxs = function(e, t, n) {
|
|
175
|
+
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
176
|
+
return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
177
|
+
};
|
|
178
|
+
})();
|
|
179
|
+
})), l = (/* @__PURE__ */ a(((e, t) => {
|
|
180
|
+
process.env.NODE_ENV === "production" ? t.exports = s() : t.exports = c();
|
|
181
|
+
})))();
|
|
182
|
+
function u({ defaultValue: e = "", value: t, disabled: n, label: r = "Address keyword", buttonLabel: a = "Search", inputProps: o, buttonProps: s, onChange: c, onSearch: u }) {
|
|
183
|
+
let [d, f] = i(e), p = t ?? d;
|
|
184
|
+
function m(e) {
|
|
185
|
+
e.preventDefault(), u(p.trim());
|
|
186
|
+
}
|
|
187
|
+
function h(e) {
|
|
188
|
+
t === void 0 && f(e), c?.(e);
|
|
189
|
+
}
|
|
190
|
+
return /* @__PURE__ */ (0, l.jsxs)("form", {
|
|
191
|
+
onSubmit: m,
|
|
192
|
+
children: [/* @__PURE__ */ (0, l.jsxs)("label", { children: [r, /* @__PURE__ */ (0, l.jsx)("input", {
|
|
193
|
+
...o,
|
|
194
|
+
disabled: n,
|
|
195
|
+
value: p,
|
|
196
|
+
onChange: (e) => h(e.target.value)
|
|
197
|
+
})] }), /* @__PURE__ */ (0, l.jsx)("button", {
|
|
198
|
+
...s,
|
|
199
|
+
disabled: n,
|
|
200
|
+
type: "submit",
|
|
201
|
+
children: a
|
|
202
|
+
})]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/core/formatters.ts
|
|
207
|
+
function d(e) {
|
|
208
|
+
return e.replace(/[^\d]/g, "");
|
|
209
|
+
}
|
|
210
|
+
function f(e) {
|
|
211
|
+
let t = d(e);
|
|
212
|
+
return t.length === 7 ? `${t.slice(0, 3)}-${t.slice(3)}` : t;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/components/PostalCodeInput.tsx
|
|
216
|
+
function p({ defaultValue: e = "", value: t, disabled: n, label: r = "Postal code", buttonLabel: a = "Search", inputProps: o, buttonProps: s, onChange: c, onSearch: u }) {
|
|
217
|
+
let [f, p] = i(e), m = t ?? f;
|
|
218
|
+
function h(e) {
|
|
219
|
+
e.preventDefault(), u(d(m));
|
|
220
|
+
}
|
|
221
|
+
function g(e) {
|
|
222
|
+
t === void 0 && p(e), c?.(e);
|
|
223
|
+
}
|
|
224
|
+
return /* @__PURE__ */ (0, l.jsxs)("form", {
|
|
225
|
+
onSubmit: h,
|
|
226
|
+
children: [/* @__PURE__ */ (0, l.jsxs)("label", { children: [r, /* @__PURE__ */ (0, l.jsx)("input", {
|
|
227
|
+
...o,
|
|
228
|
+
disabled: n,
|
|
229
|
+
inputMode: o?.inputMode ?? "numeric",
|
|
230
|
+
value: m,
|
|
231
|
+
onChange: (e) => g(e.target.value)
|
|
232
|
+
})] }), /* @__PURE__ */ (0, l.jsx)("button", {
|
|
233
|
+
...s,
|
|
234
|
+
disabled: n,
|
|
235
|
+
type: "submit",
|
|
236
|
+
children: a
|
|
237
|
+
})]
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/core/errors.ts
|
|
242
|
+
function m(e, t, n) {
|
|
243
|
+
let r = Error(t);
|
|
244
|
+
return r.name = "JapanAddressError", r.code = e, r.cause = n?.cause, r.status = n?.status, r;
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/core/normalizers.ts
|
|
248
|
+
function h(e) {
|
|
249
|
+
return e.filter(Boolean).join(" ").trim();
|
|
250
|
+
}
|
|
251
|
+
function g(e) {
|
|
252
|
+
let t = h([
|
|
253
|
+
e.prefecture,
|
|
254
|
+
e.city,
|
|
255
|
+
e.town,
|
|
256
|
+
e.detail ?? ""
|
|
257
|
+
]);
|
|
258
|
+
return {
|
|
259
|
+
postalCode: e.postalCode,
|
|
260
|
+
prefecture: e.prefecture,
|
|
261
|
+
prefectureKana: e.prefectureKana,
|
|
262
|
+
city: e.city,
|
|
263
|
+
cityKana: e.cityKana,
|
|
264
|
+
town: e.town,
|
|
265
|
+
townKana: e.townKana,
|
|
266
|
+
address: t,
|
|
267
|
+
provider: "japan-post"
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/core/validators.ts
|
|
272
|
+
function _(e) {
|
|
273
|
+
return /^\d{7}$/.test(d(e));
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/react/toJapanAddressError.ts
|
|
277
|
+
function v(e) {
|
|
278
|
+
return typeof e == "object" && e && "code" in e && typeof e.code == "string" ? e : m("data_source_error", e instanceof Error ? e.message : "Unknown error", { cause: e });
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/react/useLatestRequestState.ts
|
|
282
|
+
function y() {
|
|
283
|
+
let n = r(0), a = r(!0), o = r(null), [s, c] = i(!1), [l, u] = i(null), [d, f] = i(null), p = e((e) => a.current && e === n.current, []), m = e(() => {
|
|
284
|
+
n.current += 1, o.current?.abort(), o.current = null;
|
|
285
|
+
}, []);
|
|
286
|
+
return t(() => (a.current = !0, () => {
|
|
287
|
+
a.current = !1, m();
|
|
288
|
+
}), [m]), {
|
|
289
|
+
loading: s,
|
|
290
|
+
data: l,
|
|
291
|
+
error: d,
|
|
292
|
+
beginRequest: e(() => {
|
|
293
|
+
let e = n.current + 1;
|
|
294
|
+
n.current = e, o.current?.abort();
|
|
295
|
+
let t = new AbortController();
|
|
296
|
+
return o.current = t, c(!0), f(null), {
|
|
297
|
+
requestId: e,
|
|
298
|
+
signal: t.signal
|
|
299
|
+
};
|
|
300
|
+
}, []),
|
|
301
|
+
setSuccess: e((e, t) => {
|
|
302
|
+
p(e) && u(t);
|
|
303
|
+
}, [p]),
|
|
304
|
+
setFailure: e((e, t) => (p(e) && (f(t), u(null)), null), [p]),
|
|
305
|
+
finishRequest: e((e) => {
|
|
306
|
+
p(e) && (c(!1), o.current = null);
|
|
307
|
+
}, [p]),
|
|
308
|
+
reset: e(() => {
|
|
309
|
+
m(), c(!1), u(null), f(null);
|
|
310
|
+
}, [m])
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/react/useJapanAddressSearch.ts
|
|
315
|
+
function b(e) {
|
|
316
|
+
if (e) return e;
|
|
317
|
+
throw Error("useJapanAddressSearch requires options.dataSource");
|
|
318
|
+
}
|
|
319
|
+
function x(i) {
|
|
320
|
+
let a = n(() => b(i.dataSource), [i.dataSource]), o = i.debounceMs ?? 0, s = r(null), c = r(null), { loading: l, data: u, error: d, beginRequest: f, setSuccess: p, setFailure: h, finishRequest: g, reset: _ } = y(), x = e((e) => {
|
|
321
|
+
s.current !== null && (globalThis.clearTimeout(s.current), s.current = null), c.current?.(e), c.current = null;
|
|
322
|
+
}, []);
|
|
323
|
+
t(() => () => {
|
|
324
|
+
x(null);
|
|
325
|
+
}, [x]);
|
|
326
|
+
let S = e(() => {
|
|
327
|
+
x(null), _();
|
|
328
|
+
}, [x, _]), C = e(async (e, t, n) => {
|
|
329
|
+
try {
|
|
330
|
+
let r = n.trim();
|
|
331
|
+
if (!r) throw m("invalid_query", "Address query is required");
|
|
332
|
+
let i = { signal: t }, o = {
|
|
333
|
+
query: r,
|
|
334
|
+
addresses: await a.searchAddress(r, i)
|
|
335
|
+
};
|
|
336
|
+
return p(e, o), o;
|
|
337
|
+
} catch (t) {
|
|
338
|
+
return h(e, v(t));
|
|
339
|
+
} finally {
|
|
340
|
+
g(e);
|
|
341
|
+
}
|
|
342
|
+
}, [
|
|
343
|
+
a,
|
|
344
|
+
g,
|
|
345
|
+
h,
|
|
346
|
+
p
|
|
347
|
+
]);
|
|
348
|
+
return {
|
|
349
|
+
loading: l,
|
|
350
|
+
data: u,
|
|
351
|
+
error: d,
|
|
352
|
+
reset: S,
|
|
353
|
+
search: e((e) => {
|
|
354
|
+
let { requestId: t, signal: n } = f();
|
|
355
|
+
return x(null), o <= 0 ? C(t, n, e) : new Promise((r) => {
|
|
356
|
+
c.current = r, s.current = globalThis.setTimeout(() => {
|
|
357
|
+
s.current = null;
|
|
358
|
+
let r = c.current;
|
|
359
|
+
c.current = null, C(t, n, e).then((e) => {
|
|
360
|
+
r?.(e);
|
|
361
|
+
});
|
|
362
|
+
}, o);
|
|
363
|
+
});
|
|
364
|
+
}, [
|
|
365
|
+
f,
|
|
366
|
+
x,
|
|
367
|
+
o,
|
|
368
|
+
C
|
|
369
|
+
])
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/react/useJapanPostalCode.ts
|
|
374
|
+
function S(e) {
|
|
375
|
+
if (e) return e;
|
|
376
|
+
throw Error("useJapanPostalCode requires options.dataSource");
|
|
377
|
+
}
|
|
378
|
+
function C(t) {
|
|
379
|
+
let r = n(() => S(t.dataSource), [t.dataSource]), { loading: i, data: a, error: o, beginRequest: s, setSuccess: c, setFailure: l, finishRequest: u, reset: f } = y();
|
|
380
|
+
return {
|
|
381
|
+
loading: i,
|
|
382
|
+
data: a,
|
|
383
|
+
error: o,
|
|
384
|
+
reset: f,
|
|
385
|
+
search: e(async (e) => {
|
|
386
|
+
let { requestId: t, signal: n } = s();
|
|
387
|
+
try {
|
|
388
|
+
let i = d(e);
|
|
389
|
+
if (!/^\d{7}$/.test(i)) throw m("invalid_postal_code", "Postal code must contain exactly 7 digits");
|
|
390
|
+
let a = { signal: n }, o = {
|
|
391
|
+
postalCode: i,
|
|
392
|
+
addresses: await r.lookupPostalCode(i, a)
|
|
393
|
+
};
|
|
394
|
+
return c(t, o), o;
|
|
395
|
+
} catch (e) {
|
|
396
|
+
return l(t, v(e));
|
|
397
|
+
} finally {
|
|
398
|
+
u(t);
|
|
399
|
+
}
|
|
400
|
+
}, [
|
|
401
|
+
s,
|
|
402
|
+
r,
|
|
403
|
+
u,
|
|
404
|
+
l,
|
|
405
|
+
c
|
|
406
|
+
])
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/react/useJapanAddress.ts
|
|
411
|
+
function w(t) {
|
|
412
|
+
let r = n(() => {
|
|
413
|
+
if (t.dataSource) return t.dataSource;
|
|
414
|
+
throw Error("useJapanAddress requires options.dataSource");
|
|
415
|
+
}, [t.dataSource]), a = C({ dataSource: r }), o = x({
|
|
416
|
+
dataSource: r,
|
|
417
|
+
debounceMs: t.debounceMs
|
|
418
|
+
}), s = a.reset, c = a.search, l = o.reset, u = o.search, [d, f] = i(null), p = e(async (e) => (l(), f("postalCode"), c(e)), [l, c]), m = e(async (e) => (s(), f("keyword"), u(e)), [s, u]), h = e(() => {
|
|
419
|
+
s(), l(), f(null);
|
|
420
|
+
}, [l, s]), g = d === "postalCode" ? a.data : d === "keyword" ? o.data : null, _ = d === "postalCode" ? a.error : d === "keyword" ? o.error : null;
|
|
421
|
+
return {
|
|
422
|
+
loading: a.loading || o.loading,
|
|
423
|
+
data: g,
|
|
424
|
+
error: _,
|
|
425
|
+
reset: h,
|
|
426
|
+
searchByPostalCode: p,
|
|
427
|
+
searchByKeyword: m
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
export { u as AddressSearchInput, p as PostalCodeInput, m as createJapanAddressError, f as formatJapanPostalCode, _ as isValidJapanPostalCode, g as normalizeJapanPostAddressRecord, d as normalizeJapanPostalCode, w as useJapanAddress, x as useJapanAddressSearch, C as useJapanPostalCode };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`)):typeof define==`function`&&define.amd?define([`exports`,`react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.JapanPostcodeReact={},e.React))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),r=n((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),i=n((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),a=n(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=r():t.exports=i()}))();function o({defaultValue:e=``,value:n,disabled:r,label:i=`Address keyword`,buttonLabel:o=`Search`,inputProps:s,buttonProps:c,onChange:l,onSearch:u}){let[d,f]=(0,t.useState)(e),p=n??d;function m(e){e.preventDefault(),u(p.trim())}function h(e){n===void 0&&f(e),l?.(e)}return(0,a.jsxs)(`form`,{onSubmit:m,children:[(0,a.jsxs)(`label`,{children:[i,(0,a.jsx)(`input`,{...s,disabled:r,value:p,onChange:e=>h(e.target.value)})]}),(0,a.jsx)(`button`,{...c,disabled:r,type:`submit`,children:o})]})}function s(e){return e.replace(/[^\d]/g,``)}function c(e){let t=s(e);return t.length===7?`${t.slice(0,3)}-${t.slice(3)}`:t}function l({defaultValue:e=``,value:n,disabled:r,label:i=`Postal code`,buttonLabel:o=`Search`,inputProps:c,buttonProps:l,onChange:u,onSearch:d}){let[f,p]=(0,t.useState)(e),m=n??f;function h(e){e.preventDefault(),d(s(m))}function g(e){n===void 0&&p(e),u?.(e)}return(0,a.jsxs)(`form`,{onSubmit:h,children:[(0,a.jsxs)(`label`,{children:[i,(0,a.jsx)(`input`,{...c,disabled:r,inputMode:c?.inputMode??`numeric`,value:m,onChange:e=>g(e.target.value)})]}),(0,a.jsx)(`button`,{...l,disabled:r,type:`submit`,children:o})]})}function u(e,t,n){let r=Error(t);return r.name=`JapanAddressError`,r.code=e,r.cause=n?.cause,r.status=n?.status,r}function d(e){return e.filter(Boolean).join(` `).trim()}function f(e){let t=d([e.prefecture,e.city,e.town,e.detail??``]);return{postalCode:e.postalCode,prefecture:e.prefecture,prefectureKana:e.prefectureKana,city:e.city,cityKana:e.cityKana,town:e.town,townKana:e.townKana,address:t,provider:`japan-post`}}function p(e){return/^\d{7}$/.test(s(e))}function m(e){return typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e:u(`data_source_error`,e instanceof Error?e.message:`Unknown error`,{cause:e})}function h(){let e=(0,t.useRef)(0),n=(0,t.useRef)(!0),r=(0,t.useRef)(null),[i,a]=(0,t.useState)(!1),[o,s]=(0,t.useState)(null),[c,l]=(0,t.useState)(null),u=(0,t.useCallback)(t=>n.current&&t===e.current,[]),d=(0,t.useCallback)(()=>{e.current+=1,r.current?.abort(),r.current=null},[]);return(0,t.useEffect)(()=>(n.current=!0,()=>{n.current=!1,d()}),[d]),{loading:i,data:o,error:c,beginRequest:(0,t.useCallback)(()=>{let t=e.current+1;e.current=t,r.current?.abort();let n=new AbortController;return r.current=n,a(!0),l(null),{requestId:t,signal:n.signal}},[]),setSuccess:(0,t.useCallback)((e,t)=>{u(e)&&s(t)},[u]),setFailure:(0,t.useCallback)((e,t)=>(u(e)&&(l(t),s(null)),null),[u]),finishRequest:(0,t.useCallback)(e=>{u(e)&&(a(!1),r.current=null)},[u]),reset:(0,t.useCallback)(()=>{d(),a(!1),s(null),l(null)},[d])}}function g(e){if(e)return e;throw Error(`useJapanAddressSearch requires options.dataSource`)}function _(e){let n=(0,t.useMemo)(()=>g(e.dataSource),[e.dataSource]),r=e.debounceMs??0,i=(0,t.useRef)(null),a=(0,t.useRef)(null),{loading:o,data:s,error:c,beginRequest:l,setSuccess:d,setFailure:f,finishRequest:p,reset:_}=h(),v=(0,t.useCallback)(e=>{i.current!==null&&(globalThis.clearTimeout(i.current),i.current=null),a.current?.(e),a.current=null},[]);(0,t.useEffect)(()=>()=>{v(null)},[v]);let y=(0,t.useCallback)(()=>{v(null),_()},[v,_]),b=(0,t.useCallback)(async(e,t,r)=>{try{let i=r.trim();if(!i)throw u(`invalid_query`,`Address query is required`);let a={signal:t},o={query:i,addresses:await n.searchAddress(i,a)};return d(e,o),o}catch(t){return f(e,m(t))}finally{p(e)}},[n,p,f,d]);return{loading:o,data:s,error:c,reset:y,search:(0,t.useCallback)(e=>{let{requestId:t,signal:n}=l();return v(null),r<=0?b(t,n,e):new Promise(o=>{a.current=o,i.current=globalThis.setTimeout(()=>{i.current=null;let r=a.current;a.current=null,b(t,n,e).then(e=>{r?.(e)})},r)})},[l,v,r,b])}}function v(e){if(e)return e;throw Error(`useJapanPostalCode requires options.dataSource`)}function y(e){let n=(0,t.useMemo)(()=>v(e.dataSource),[e.dataSource]),{loading:r,data:i,error:a,beginRequest:o,setSuccess:c,setFailure:l,finishRequest:d,reset:f}=h();return{loading:r,data:i,error:a,reset:f,search:(0,t.useCallback)(async e=>{let{requestId:t,signal:r}=o();try{let i=s(e);if(!/^\d{7}$/.test(i))throw u(`invalid_postal_code`,`Postal code must contain exactly 7 digits`);let a={signal:r},o={postalCode:i,addresses:await n.lookupPostalCode(i,a)};return c(t,o),o}catch(e){return l(t,m(e))}finally{d(t)}},[o,n,d,l,c])}}function b(e){let n=(0,t.useMemo)(()=>{if(e.dataSource)return e.dataSource;throw Error(`useJapanAddress requires options.dataSource`)},[e.dataSource]),r=y({dataSource:n}),i=_({dataSource:n,debounceMs:e.debounceMs}),a=r.reset,o=r.search,s=i.reset,c=i.search,[l,u]=(0,t.useState)(null),d=(0,t.useCallback)(async e=>(s(),u(`postalCode`),o(e)),[s,o]),f=(0,t.useCallback)(async e=>(a(),u(`keyword`),c(e)),[a,c]),p=(0,t.useCallback)(()=>{a(),s(),u(null)},[s,a]),m=l===`postalCode`?r.data:l===`keyword`?i.data:null,h=l===`postalCode`?r.error:l===`keyword`?i.error:null;return{loading:r.loading||i.loading,data:m,error:h,reset:p,searchByPostalCode:d,searchByKeyword:f}}e.AddressSearchInput=o,e.PostalCodeInput=l,e.createJapanAddressError=u,e.formatJapanPostalCode=c,e.isValidJapanPostalCode=p,e.normalizeJapanPostAddressRecord=f,e.normalizeJapanPostalCode=s,e.useJapanAddress=b,e.useJapanAddressSearch=_,e.useJapanPostalCode=y});
|