@cp949/japanpost-react 1.0.1 → 1.0.3
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.ko.md +89 -23
- package/README.md +231 -191
- package/dist/client.d.ts +1 -0
- package/dist/client.es.js +3 -0
- package/dist/index.d.ts +1 -11
- package/dist/index.es.js +156 -290
- package/dist/src/client.d.ts +7 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/components/AddressSearchInput.d.ts.map +1 -0
- package/dist/src/components/PostalCodeInput.d.ts.map +1 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/formatters.d.ts.map +1 -0
- package/dist/src/core/normalizers.d.ts.map +1 -0
- package/dist/{core → src/core}/types.d.ts +27 -7
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/validators.d.ts.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/react/toJapanAddressError.d.ts.map +1 -0
- package/dist/src/react/useJapanAddress.d.ts.map +1 -0
- package/dist/src/react/useJapanAddressSearch.d.ts.map +1 -0
- package/dist/src/react/useJapanPostalCode.d.ts.map +1 -0
- package/dist/{react → src/react}/useLatestRequestState.d.ts +1 -0
- package/dist/src/react/useLatestRequestState.d.ts.map +1 -0
- package/package.json +11 -8
- package/dist/components/AddressSearchInput.d.ts.map +0 -1
- package/dist/components/PostalCodeInput.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/formatters.d.ts.map +0 -1
- package/dist/core/normalizers.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/validators.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.cjs +0 -6
- package/dist/react/toJapanAddressError.d.ts.map +0 -1
- package/dist/react/useJapanAddress.d.ts.map +0 -1
- package/dist/react/useJapanAddressSearch.d.ts.map +0 -1
- package/dist/react/useJapanPostalCode.d.ts.map +0 -1
- package/dist/react/useLatestRequestState.d.ts.map +0 -1
- /package/dist/{components → src/components}/AddressSearchInput.d.ts +0 -0
- /package/dist/{components → src/components}/PostalCodeInput.d.ts +0 -0
- /package/dist/{core → src/core}/errors.d.ts +0 -0
- /package/dist/{core → src/core}/formatters.d.ts +0 -0
- /package/dist/{core → src/core}/normalizers.d.ts +0 -0
- /package/dist/{core → src/core}/validators.d.ts +0 -0
- /package/dist/{react → src/react}/toJapanAddressError.d.ts +0 -0
- /package/dist/{react → src/react}/useJapanAddress.d.ts +0 -0
- /package/dist/{react → src/react}/useJapanAddressSearch.d.ts +0 -0
- /package/dist/{react → src/react}/useJapanPostalCode.d.ts +0 -0
package/dist/index.es.js
CHANGED
|
@@ -1,255 +1,77 @@
|
|
|
1
1
|
import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
2
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
3
|
+
//#region src/components/AddressSearchInput.tsx
|
|
4
|
+
function s({ defaultValue: e = "", value: t, disabled: n, label: r = "Address keyword", buttonLabel: s = "Search", inputProps: c, buttonProps: l, onChange: u, onSearch: d }) {
|
|
5
|
+
let [f, p] = i(e), m = t ?? f;
|
|
187
6
|
function h(e) {
|
|
188
|
-
|
|
7
|
+
e.preventDefault(), d(m.trim());
|
|
8
|
+
}
|
|
9
|
+
function g(e) {
|
|
10
|
+
t === void 0 && p(e), u?.(e);
|
|
189
11
|
}
|
|
190
|
-
return /* @__PURE__ */ (
|
|
191
|
-
onSubmit:
|
|
192
|
-
children: [/* @__PURE__ */ (
|
|
193
|
-
...
|
|
12
|
+
return /* @__PURE__ */ o("form", {
|
|
13
|
+
onSubmit: h,
|
|
14
|
+
children: [/* @__PURE__ */ o("label", { children: [r, /* @__PURE__ */ a("input", {
|
|
15
|
+
...c,
|
|
194
16
|
disabled: n,
|
|
195
|
-
value:
|
|
196
|
-
onChange: (e) =>
|
|
197
|
-
})] }), /* @__PURE__ */ (
|
|
198
|
-
...
|
|
17
|
+
value: m,
|
|
18
|
+
onChange: (e) => g(e.target.value)
|
|
19
|
+
})] }), /* @__PURE__ */ a("button", {
|
|
20
|
+
...l,
|
|
199
21
|
disabled: n,
|
|
200
22
|
type: "submit",
|
|
201
|
-
children:
|
|
23
|
+
children: s
|
|
202
24
|
})]
|
|
203
25
|
});
|
|
204
26
|
}
|
|
205
27
|
//#endregion
|
|
206
28
|
//#region src/core/formatters.ts
|
|
207
|
-
function
|
|
29
|
+
function c(e) {
|
|
208
30
|
return e.replace(/[^\d]/g, "");
|
|
209
31
|
}
|
|
210
|
-
function
|
|
211
|
-
let t =
|
|
32
|
+
function l(e) {
|
|
33
|
+
let t = c(e);
|
|
212
34
|
return t.length === 7 ? `${t.slice(0, 3)}-${t.slice(3)}` : t;
|
|
213
35
|
}
|
|
214
36
|
//#endregion
|
|
215
37
|
//#region src/components/PostalCodeInput.tsx
|
|
216
|
-
function
|
|
217
|
-
let [
|
|
218
|
-
function h(e) {
|
|
219
|
-
e.preventDefault(), u(d(m));
|
|
220
|
-
}
|
|
38
|
+
function u({ defaultValue: e = "", value: t, disabled: n, label: r = "Postal code", buttonLabel: s = "Search", inputProps: l, buttonProps: u, onChange: d, onSearch: f }) {
|
|
39
|
+
let [p, m] = i(e), h = t ?? p;
|
|
221
40
|
function g(e) {
|
|
222
|
-
|
|
41
|
+
e.preventDefault(), f(c(h));
|
|
223
42
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
43
|
+
function _(e) {
|
|
44
|
+
t === void 0 && m(e), d?.(e);
|
|
45
|
+
}
|
|
46
|
+
return /* @__PURE__ */ o("form", {
|
|
47
|
+
onSubmit: g,
|
|
48
|
+
children: [/* @__PURE__ */ o("label", { children: [r, /* @__PURE__ */ a("input", {
|
|
49
|
+
...l,
|
|
228
50
|
disabled: n,
|
|
229
|
-
inputMode:
|
|
230
|
-
value:
|
|
231
|
-
onChange: (e) =>
|
|
232
|
-
})] }), /* @__PURE__ */ (
|
|
233
|
-
...
|
|
51
|
+
inputMode: l?.inputMode ?? "numeric",
|
|
52
|
+
value: h,
|
|
53
|
+
onChange: (e) => _(e.target.value)
|
|
54
|
+
})] }), /* @__PURE__ */ a("button", {
|
|
55
|
+
...u,
|
|
234
56
|
disabled: n,
|
|
235
57
|
type: "submit",
|
|
236
|
-
children:
|
|
58
|
+
children: s
|
|
237
59
|
})]
|
|
238
60
|
});
|
|
239
61
|
}
|
|
240
62
|
//#endregion
|
|
241
63
|
//#region src/core/errors.ts
|
|
242
|
-
function
|
|
64
|
+
function d(e, t, n) {
|
|
243
65
|
let r = Error(t);
|
|
244
66
|
return r.name = "JapanAddressError", r.code = e, r.cause = n?.cause, r.status = n?.status, r;
|
|
245
67
|
}
|
|
246
68
|
//#endregion
|
|
247
69
|
//#region src/core/normalizers.ts
|
|
248
|
-
function
|
|
70
|
+
function f(e) {
|
|
249
71
|
return e.filter(Boolean).join(" ").trim();
|
|
250
72
|
}
|
|
251
|
-
function
|
|
252
|
-
let t =
|
|
73
|
+
function p(e) {
|
|
74
|
+
let t = f([
|
|
253
75
|
e.prefecture,
|
|
254
76
|
e.city,
|
|
255
77
|
e.town,
|
|
@@ -269,104 +91,146 @@ function g(e) {
|
|
|
269
91
|
}
|
|
270
92
|
//#endregion
|
|
271
93
|
//#region src/core/validators.ts
|
|
272
|
-
function
|
|
273
|
-
return /^\d{7}$/.test(
|
|
94
|
+
function m(e) {
|
|
95
|
+
return /^\d{7}$/.test(c(e));
|
|
274
96
|
}
|
|
275
97
|
//#endregion
|
|
276
98
|
//#region src/react/toJapanAddressError.ts
|
|
277
|
-
function
|
|
278
|
-
return typeof e == "object" && e && "code" in e && typeof e.code == "string" ? e :
|
|
99
|
+
function h(e) {
|
|
100
|
+
return typeof e == "object" && e && "code" in e && typeof e.code == "string" ? e : d("data_source_error", e instanceof Error ? e.message : "Unknown error", { cause: e });
|
|
279
101
|
}
|
|
280
102
|
//#endregion
|
|
281
103
|
//#region src/react/useLatestRequestState.ts
|
|
282
|
-
function
|
|
104
|
+
function g() {
|
|
283
105
|
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
106
|
n.current += 1, o.current?.abort(), o.current = null;
|
|
285
107
|
}, []);
|
|
286
|
-
|
|
108
|
+
t(() => (a.current = !0, () => {
|
|
287
109
|
a.current = !1, m();
|
|
288
|
-
}), [m])
|
|
110
|
+
}), [m]);
|
|
111
|
+
let h = e(() => {
|
|
112
|
+
let e = n.current + 1;
|
|
113
|
+
n.current = e, o.current?.abort();
|
|
114
|
+
let t = new AbortController();
|
|
115
|
+
return o.current = t, c(!0), f(null), {
|
|
116
|
+
requestId: e,
|
|
117
|
+
signal: t.signal
|
|
118
|
+
};
|
|
119
|
+
}, []), g = e((e, t) => {
|
|
120
|
+
p(e) && u(t);
|
|
121
|
+
}, [p]), _ = e((e, t) => (p(e) && (f(t), u(null)), null), [p]), v = e(() => {
|
|
122
|
+
m(), c(!1);
|
|
123
|
+
}, [m]);
|
|
124
|
+
return {
|
|
289
125
|
loading: s,
|
|
290
126
|
data: l,
|
|
291
127
|
error: d,
|
|
292
|
-
beginRequest:
|
|
293
|
-
|
|
294
|
-
|
|
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]),
|
|
128
|
+
beginRequest: h,
|
|
129
|
+
setSuccess: g,
|
|
130
|
+
setFailure: _,
|
|
305
131
|
finishRequest: e((e) => {
|
|
306
132
|
p(e) && (c(!1), o.current = null);
|
|
307
133
|
}, [p]),
|
|
134
|
+
cancel: v,
|
|
308
135
|
reset: e(() => {
|
|
309
|
-
|
|
310
|
-
}, [
|
|
136
|
+
v(), u(null), f(null);
|
|
137
|
+
}, [v])
|
|
311
138
|
};
|
|
312
139
|
}
|
|
313
140
|
//#endregion
|
|
314
141
|
//#region src/react/useJapanAddressSearch.ts
|
|
315
|
-
function
|
|
142
|
+
function _(e) {
|
|
316
143
|
if (e) return e;
|
|
317
144
|
throw Error("useJapanAddressSearch requires options.dataSource");
|
|
318
145
|
}
|
|
146
|
+
function v(e) {
|
|
147
|
+
return e?.trim() || void 0;
|
|
148
|
+
}
|
|
149
|
+
function y(e) {
|
|
150
|
+
let t = typeof e == "string" ? { addressQuery: e } : e, n = v(t.addressQuery), r = v(t.prefCode), i = v(t.prefName), a = v(t.prefKana), o = v(t.prefRoma), s = v(t.cityCode), c = v(t.cityName), l = v(t.cityKana), u = v(t.cityRoma), d = v(t.townName), f = v(t.townKana), p = v(t.townRoma);
|
|
151
|
+
return n === void 0 && r === void 0 && i === void 0 && a === void 0 && o === void 0 && s === void 0 && c === void 0 && l === void 0 && u === void 0 && d === void 0 && f === void 0 && p === void 0 ? null : {
|
|
152
|
+
...n === void 0 ? {} : { addressQuery: n },
|
|
153
|
+
...r === void 0 ? {} : { prefCode: r },
|
|
154
|
+
...i === void 0 ? {} : { prefName: i },
|
|
155
|
+
...a === void 0 ? {} : { prefKana: a },
|
|
156
|
+
...o === void 0 ? {} : { prefRoma: o },
|
|
157
|
+
...s === void 0 ? {} : { cityCode: s },
|
|
158
|
+
...c === void 0 ? {} : { cityName: c },
|
|
159
|
+
...l === void 0 ? {} : { cityKana: l },
|
|
160
|
+
...u === void 0 ? {} : { cityRoma: u },
|
|
161
|
+
...d === void 0 ? {} : { townName: d },
|
|
162
|
+
...f === void 0 ? {} : { townKana: f },
|
|
163
|
+
...p === void 0 ? {} : { townRoma: p },
|
|
164
|
+
pageNumber: t.pageNumber ?? 0,
|
|
165
|
+
rowsPerPage: t.rowsPerPage ?? 100,
|
|
166
|
+
...t.includeCityDetails === void 0 ? {} : { includeCityDetails: t.includeCityDetails },
|
|
167
|
+
...t.includePrefectureDetails === void 0 ? {} : { includePrefectureDetails: t.includePrefectureDetails }
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function b(e) {
|
|
171
|
+
return e.aborted ? Promise.resolve(null) : new Promise((t) => {
|
|
172
|
+
let n = () => {
|
|
173
|
+
e.removeEventListener("abort", n), t(null);
|
|
174
|
+
};
|
|
175
|
+
e.addEventListener("abort", n, { once: !0 });
|
|
176
|
+
});
|
|
177
|
+
}
|
|
319
178
|
function x(i) {
|
|
320
|
-
let a = n(() =>
|
|
179
|
+
let a = n(() => _(i.dataSource), [i.dataSource]), o = i.debounceMs ?? 0, s = r(null), c = r(null), { loading: l, data: u, error: f, beginRequest: p, setSuccess: m, setFailure: v, finishRequest: x, cancel: S, reset: C } = g(), w = e((e) => {
|
|
321
180
|
s.current !== null && (globalThis.clearTimeout(s.current), s.current = null), c.current?.(e), c.current = null;
|
|
322
181
|
}, []);
|
|
323
182
|
t(() => () => {
|
|
324
|
-
|
|
325
|
-
}, [
|
|
326
|
-
let
|
|
327
|
-
|
|
328
|
-
}, [
|
|
183
|
+
w(null);
|
|
184
|
+
}, [w]);
|
|
185
|
+
let T = e(() => {
|
|
186
|
+
w(null), C();
|
|
187
|
+
}, [w, C]), E = e(() => {
|
|
188
|
+
w(null), S();
|
|
189
|
+
}, [w, S]), D = e(async (e, t, n) => {
|
|
329
190
|
try {
|
|
330
|
-
let r = n.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
pageNumber: 0,
|
|
335
|
-
rowsPerPage: 100
|
|
336
|
-
}, s = await a.searchAddress(o, i);
|
|
337
|
-
return p(e, s), s;
|
|
338
|
-
} catch (t) {
|
|
339
|
-
return h(e, v(t));
|
|
191
|
+
let r = { signal: t }, i = a.searchAddress(n, r), o = await Promise.race([i, b(t)]);
|
|
192
|
+
return t.aborted || o === null ? null : (m(e, o), o);
|
|
193
|
+
} catch (n) {
|
|
194
|
+
return t.aborted ? null : v(e, h(n));
|
|
340
195
|
} finally {
|
|
341
|
-
|
|
196
|
+
x(e);
|
|
342
197
|
}
|
|
343
198
|
}, [
|
|
344
199
|
a,
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
200
|
+
x,
|
|
201
|
+
v,
|
|
202
|
+
m
|
|
348
203
|
]);
|
|
349
204
|
return {
|
|
350
205
|
loading: l,
|
|
351
206
|
data: u,
|
|
352
|
-
error:
|
|
353
|
-
|
|
207
|
+
error: f,
|
|
208
|
+
cancel: E,
|
|
209
|
+
reset: T,
|
|
354
210
|
search: e((e) => {
|
|
355
|
-
let { requestId:
|
|
356
|
-
|
|
357
|
-
|
|
211
|
+
let t = y(e), { requestId: n, signal: r } = p();
|
|
212
|
+
if (w(null), t === null) {
|
|
213
|
+
let e = v(n, d("invalid_query", "Address query is required"));
|
|
214
|
+
return x(n), Promise.resolve(e);
|
|
215
|
+
}
|
|
216
|
+
return o <= 0 ? new Promise((e) => {
|
|
217
|
+
c.current = e, D(n, r, t).then((t) => {
|
|
218
|
+
e(t), c.current === e && (c.current = null);
|
|
219
|
+
});
|
|
220
|
+
}) : new Promise((e) => {
|
|
221
|
+
c.current = e, s.current = globalThis.setTimeout(() => {
|
|
358
222
|
s.current = null;
|
|
359
|
-
let
|
|
360
|
-
c.current = null,
|
|
361
|
-
|
|
223
|
+
let e = c.current;
|
|
224
|
+
c.current = null, D(n, r, t).then((t) => {
|
|
225
|
+
e?.(t);
|
|
362
226
|
});
|
|
363
227
|
}, o);
|
|
364
228
|
});
|
|
365
229
|
}, [
|
|
366
|
-
|
|
367
|
-
|
|
230
|
+
p,
|
|
231
|
+
w,
|
|
368
232
|
o,
|
|
369
|
-
|
|
233
|
+
D
|
|
370
234
|
])
|
|
371
235
|
};
|
|
372
236
|
}
|
|
@@ -377,34 +241,36 @@ function S(e) {
|
|
|
377
241
|
throw Error("useJapanPostalCode requires options.dataSource");
|
|
378
242
|
}
|
|
379
243
|
function C(t) {
|
|
380
|
-
let r = n(() => S(t.dataSource), [t.dataSource]), { loading: i, data: a, error: o, beginRequest: s, setSuccess:
|
|
244
|
+
let r = n(() => S(t.dataSource), [t.dataSource]), { loading: i, data: a, error: o, beginRequest: s, setSuccess: l, setFailure: u, finishRequest: f, cancel: p, reset: m } = g();
|
|
381
245
|
return {
|
|
382
246
|
loading: i,
|
|
383
247
|
data: a,
|
|
384
248
|
error: o,
|
|
385
|
-
|
|
249
|
+
cancel: p,
|
|
250
|
+
reset: m,
|
|
386
251
|
search: e(async (e) => {
|
|
387
252
|
let { requestId: t, signal: n } = s();
|
|
388
253
|
try {
|
|
389
|
-
let i =
|
|
390
|
-
if (!/^\d{3,7}$/.test(
|
|
391
|
-
let
|
|
392
|
-
|
|
393
|
-
pageNumber: 0,
|
|
394
|
-
rowsPerPage: 100
|
|
395
|
-
|
|
396
|
-
|
|
254
|
+
let i = typeof e == "string" ? { postalCode: e } : e, a = c(i.postalCode);
|
|
255
|
+
if (!/^\d{3,7}$/.test(a)) throw d("invalid_postal_code", "Postal code must contain between 3 and 7 digits");
|
|
256
|
+
let o = { signal: n }, s = {
|
|
257
|
+
postalCode: a,
|
|
258
|
+
pageNumber: i.pageNumber ?? 0,
|
|
259
|
+
rowsPerPage: i.rowsPerPage ?? 100,
|
|
260
|
+
...i.includeParenthesesTown === void 0 ? {} : { includeParenthesesTown: i.includeParenthesesTown }
|
|
261
|
+
}, u = await r.lookupPostalCode(s, o);
|
|
262
|
+
return n.aborted ? null : (l(t, u), u);
|
|
397
263
|
} catch (e) {
|
|
398
|
-
return
|
|
264
|
+
return n.aborted ? null : u(t, h(e));
|
|
399
265
|
} finally {
|
|
400
|
-
|
|
266
|
+
f(t);
|
|
401
267
|
}
|
|
402
268
|
}, [
|
|
403
269
|
s,
|
|
404
270
|
r,
|
|
271
|
+
f,
|
|
405
272
|
u,
|
|
406
|
-
l
|
|
407
|
-
c
|
|
273
|
+
l
|
|
408
274
|
])
|
|
409
275
|
};
|
|
410
276
|
}
|
|
@@ -417,17 +283,17 @@ function w(t) {
|
|
|
417
283
|
}, [t.dataSource]), a = C({ dataSource: r }), o = x({
|
|
418
284
|
dataSource: r,
|
|
419
285
|
debounceMs: t.debounceMs
|
|
420
|
-
}), 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("
|
|
286
|
+
}), 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("addressQuery"), u(e)), [s, u]), h = e(() => {
|
|
421
287
|
s(), l(), f(null);
|
|
422
|
-
}, [l, s]), g = d === "postalCode" ? a.data : d === "
|
|
288
|
+
}, [l, s]), g = d === "postalCode" ? a.data : d === "addressQuery" ? o.data : null, _ = d === "postalCode" ? a.error : d === "addressQuery" ? o.error : null;
|
|
423
289
|
return {
|
|
424
290
|
loading: a.loading || o.loading,
|
|
425
291
|
data: g,
|
|
426
292
|
error: _,
|
|
427
293
|
reset: h,
|
|
428
294
|
searchByPostalCode: p,
|
|
429
|
-
|
|
295
|
+
searchByAddressQuery: m
|
|
430
296
|
};
|
|
431
297
|
}
|
|
432
298
|
//#endregion
|
|
433
|
-
export {
|
|
299
|
+
export { s as AddressSearchInput, u as PostalCodeInput, d as createJapanAddressError, l as formatJapanPostalCode, m as isValidJapanPostalCode, p as normalizeJapanPostAddressRecord, c as normalizeJapanPostalCode, w as useJapanAddress, x as useJapanAddressSearch, C as useJapanPostalCode };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AddressSearchInput } from './components/AddressSearchInput';
|
|
2
|
+
export { PostalCodeInput } from './components/PostalCodeInput';
|
|
3
|
+
export { useJapanAddress } from './react/useJapanAddress';
|
|
4
|
+
export { useJapanAddressSearch } from './react/useJapanAddressSearch';
|
|
5
|
+
export { useJapanPostalCode } from './react/useJapanPostalCode';
|
|
6
|
+
export type * from './core/types';
|
|
7
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,mBAAmB,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddressSearchInput.d.ts","sourceRoot":"","sources":["../../../src/components/AddressSearchInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,YAAiB,EACjB,KAAK,EACL,QAAQ,EACR,KAAyB,EACzB,WAAsB,EACtB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,QAAQ,GACT,EAAE,uBAAuB,2CA4CzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostalCodeInput.d.ts","sourceRoot":"","sources":["../../../src/components/PostalCodeInput.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAC9B,YAAiB,EACjB,KAAK,EACL,QAAQ,EACR,KAAqB,EACrB,WAAsB,EACtB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,QAAQ,GACT,EAAE,oBAAoB,2CA8CtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C,iBAAiB,CAQnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../src/core/formatters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAW3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizers.d.ts","sourceRoot":"","sources":["../../../src/core/normalizers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAe1E;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,4BAA4B,GACnC,YAAY,CAoBd"}
|