@famgia/omnify-react 0.0.1

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.
@@ -0,0 +1,657 @@
1
+ // src/components/JapaneseNameField.tsx
2
+ import { Form, Input, Row, Col } from "antd";
3
+
4
+ // src/lib/zod-i18n.ts
5
+ var DEFAULT_MESSAGES = {
6
+ required: {
7
+ en: "${displayName} is required",
8
+ ja: "${displayName}\u306F\u5FC5\u9808\u3067\u3059",
9
+ vi: "${displayName} l\xE0 b\u1EAFt bu\u1ED9c",
10
+ ko: "${displayName}\uC740(\uB294) \uD544\uC218\uC785\uB2C8\uB2E4",
11
+ "zh-CN": "${displayName}\u662F\u5FC5\u586B\u9879",
12
+ "zh-TW": "${displayName}\u70BA\u5FC5\u586B\u6B04\u4F4D",
13
+ th: "${displayName} \u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E23\u0E2D\u0E01",
14
+ es: "${displayName} es obligatorio"
15
+ },
16
+ minLength: {
17
+ en: "${displayName} must be at least ${min} characters",
18
+ ja: "${displayName}\u306F${min}\u6587\u5B57\u4EE5\u4E0A\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
19
+ vi: "${displayName} ph\u1EA3i c\xF3 \xEDt nh\u1EA5t ${min} k\xFD t\u1EF1",
20
+ ko: "${displayName}\uC740(\uB294) ${min}\uC790 \uC774\uC0C1\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4",
21
+ "zh-CN": "${displayName}\u81F3\u5C11\u9700\u8981${min}\u4E2A\u5B57\u7B26",
22
+ "zh-TW": "${displayName}\u81F3\u5C11\u9700\u8981${min}\u500B\u5B57\u5143",
23
+ th: "${displayName} \u0E15\u0E49\u0E2D\u0E07\u0E21\u0E35\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E19\u0E49\u0E2D\u0E22 ${min} \u0E15\u0E31\u0E27\u0E2D\u0E31\u0E01\u0E29\u0E23",
24
+ es: "${displayName} debe tener al menos ${min} caracteres"
25
+ },
26
+ maxLength: {
27
+ en: "${displayName} must be at most ${max} characters",
28
+ ja: "${displayName}\u306F${max}\u6587\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
29
+ vi: "${displayName} kh\xF4ng \u0111\u01B0\u1EE3c qu\xE1 ${max} k\xFD t\u1EF1",
30
+ ko: "${displayName}\uC740(\uB294) ${max}\uC790 \uC774\uD558\uC5EC\uC57C \uD569\uB2C8\uB2E4",
31
+ "zh-CN": "${displayName}\u6700\u591A${max}\u4E2A\u5B57\u7B26",
32
+ "zh-TW": "${displayName}\u6700\u591A${max}\u500B\u5B57\u5143",
33
+ th: "${displayName} \u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 ${max} \u0E15\u0E31\u0E27\u0E2D\u0E31\u0E01\u0E29\u0E23",
34
+ es: "${displayName} debe tener como m\xE1ximo ${max} caracteres"
35
+ },
36
+ min: {
37
+ en: "${displayName} must be at least ${min}",
38
+ ja: "${displayName}\u306F${min}\u4EE5\u4E0A\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
39
+ vi: "${displayName} ph\u1EA3i l\u1EDBn h\u01A1n ho\u1EB7c b\u1EB1ng ${min}",
40
+ ko: "${displayName}\uC740(\uB294) ${min} \uC774\uC0C1\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4",
41
+ "zh-CN": "${displayName}\u5FC5\u987B\u5927\u4E8E\u7B49\u4E8E${min}",
42
+ "zh-TW": "${displayName}\u5FC5\u9808\u5927\u65BC\u7B49\u65BC${min}",
43
+ th: "${displayName} \u0E15\u0E49\u0E2D\u0E07\u0E21\u0E32\u0E01\u0E01\u0E27\u0E48\u0E32\u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E17\u0E48\u0E32\u0E01\u0E31\u0E1A ${min}",
44
+ es: "${displayName} debe ser al menos ${min}"
45
+ },
46
+ max: {
47
+ en: "${displayName} must be at most ${max}",
48
+ ja: "${displayName}\u306F${max}\u4EE5\u4E0B\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
49
+ vi: "${displayName} ph\u1EA3i nh\u1ECF h\u01A1n ho\u1EB7c b\u1EB1ng ${max}",
50
+ ko: "${displayName}\uC740(\uB294) ${max} \uC774\uD558\uC5EC\uC57C \uD569\uB2C8\uB2E4",
51
+ "zh-CN": "${displayName}\u5FC5\u987B\u5C0F\u4E8E\u7B49\u4E8E${max}",
52
+ "zh-TW": "${displayName}\u5FC5\u9808\u5C0F\u65BC\u7B49\u65BC${max}",
53
+ th: "${displayName} \u0E15\u0E49\u0E2D\u0E07\u0E19\u0E49\u0E2D\u0E22\u0E01\u0E27\u0E48\u0E32\u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E17\u0E48\u0E32\u0E01\u0E31\u0E1A ${max}",
54
+ es: "${displayName} debe ser como m\xE1ximo ${max}"
55
+ },
56
+ email: {
57
+ en: "Please enter a valid email address",
58
+ ja: "\u6709\u52B9\u306A\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
59
+ vi: "Vui l\xF2ng nh\u1EADp \u0111\u1ECBa ch\u1EC9 email h\u1EE3p l\u1EC7",
60
+ ko: "\uC720\uD6A8\uD55C \uC774\uBA54\uC77C \uC8FC\uC18C\uB97C \uC785\uB825\uD558\uC138\uC694",
61
+ "zh-CN": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u7535\u5B50\u90AE\u4EF6\u5730\u5740",
62
+ "zh-TW": "\u8ACB\u8F38\u5165\u6709\u6548\u7684\u96FB\u5B50\u90F5\u4EF6\u5730\u5740",
63
+ th: "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E01\u0E23\u0E2D\u0E01\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07",
64
+ es: "Por favor, introduce una direcci\xF3n de correo electr\xF3nico v\xE1lida"
65
+ },
66
+ url: {
67
+ en: "Please enter a valid URL",
68
+ ja: "\u6709\u52B9\u306AURL\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
69
+ vi: "Vui l\xF2ng nh\u1EADp URL h\u1EE3p l\u1EC7",
70
+ ko: "\uC720\uD6A8\uD55C URL\uC744 \uC785\uB825\uD558\uC138\uC694",
71
+ "zh-CN": "\u8BF7\u8F93\u5165\u6709\u6548\u7684URL",
72
+ "zh-TW": "\u8ACB\u8F38\u5165\u6709\u6548\u7684\u7DB2\u5740",
73
+ th: "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E01\u0E23\u0E2D\u0E01 URL \u0E17\u0E35\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07",
74
+ es: "Por favor, introduce una URL v\xE1lida"
75
+ },
76
+ pattern: {
77
+ en: "${displayName} format is invalid",
78
+ ja: "${displayName}\u306E\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",
79
+ vi: "${displayName} kh\xF4ng \u0111\xFAng \u0111\u1ECBnh d\u1EA1ng",
80
+ ko: "${displayName} \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
81
+ "zh-CN": "${displayName}\u683C\u5F0F\u4E0D\u6B63\u786E",
82
+ "zh-TW": "${displayName}\u683C\u5F0F\u4E0D\u6B63\u78BA",
83
+ th: "\u0E23\u0E39\u0E1B\u0E41\u0E1A\u0E1A${displayName}\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07",
84
+ es: "El formato de ${displayName} no es v\xE1lido"
85
+ }
86
+ };
87
+ var currentLocale = "ja";
88
+ var fallbackLocale = "en";
89
+ var customMessages = {};
90
+ function getZodLocale() {
91
+ return currentLocale;
92
+ }
93
+ function getZodMessage(key, params = {}) {
94
+ const messages = customMessages[key] ?? DEFAULT_MESSAGES[key];
95
+ if (!messages) return key;
96
+ let message2 = messages[currentLocale] ?? messages[fallbackLocale] ?? messages["en"] ?? key;
97
+ for (const [param, value] of Object.entries(params)) {
98
+ message2 = message2.replace(new RegExp(`\\$\\{${param}\\}`, "g"), String(value));
99
+ }
100
+ return message2;
101
+ }
102
+
103
+ // src/lib/form-validation.ts
104
+ function zodRule(schema, displayName) {
105
+ const field = displayName ?? "\u3053\u306E\u9805\u76EE";
106
+ return {
107
+ validator: async (_, value) => {
108
+ if (value === void 0 || value === null || value === "") {
109
+ if (schema.safeParse(void 0).success) return;
110
+ throw new Error(getZodMessage("required", { displayName: field }));
111
+ }
112
+ const result = schema.safeParse(value);
113
+ if (result.success) return;
114
+ const issue = result.error.issues[0];
115
+ if (!issue) {
116
+ throw new Error(getZodMessage("required", { displayName: field }));
117
+ }
118
+ const issueAny = issue;
119
+ switch (issue.code) {
120
+ case "too_small": {
121
+ const origin = issueAny.origin;
122
+ const minimum = issueAny.minimum;
123
+ if (origin === "string" && minimum === 1) {
124
+ throw new Error(getZodMessage("required", { displayName: field }));
125
+ }
126
+ if (origin === "string") {
127
+ throw new Error(getZodMessage("minLength", { displayName: field, min: minimum }));
128
+ }
129
+ throw new Error(getZodMessage("min", { displayName: field, min: minimum }));
130
+ }
131
+ case "too_big": {
132
+ const origin = issueAny.origin;
133
+ const maximum = issueAny.maximum;
134
+ if (origin === "string") {
135
+ throw new Error(getZodMessage("maxLength", { displayName: field, max: maximum }));
136
+ }
137
+ throw new Error(getZodMessage("max", { displayName: field, max: maximum }));
138
+ }
139
+ // Zod v4: 'invalid_string' → 'invalid_format'
140
+ case "invalid_format": {
141
+ const format = issueAny.format;
142
+ if (format === "email") {
143
+ throw new Error(getZodMessage("email", { displayName: field }));
144
+ }
145
+ if (format === "url") {
146
+ throw new Error(getZodMessage("url", { displayName: field }));
147
+ }
148
+ if (format === "regex") {
149
+ throw new Error(getZodMessage("pattern", { displayName: field }));
150
+ }
151
+ break;
152
+ }
153
+ // Zod v3: 'invalid_string' (handled via default case for forward compatibility)
154
+ default: {
155
+ if (issue.code === "invalid_string") {
156
+ const validation = issueAny.validation;
157
+ if (validation === "email") {
158
+ throw new Error(getZodMessage("email", { displayName: field }));
159
+ }
160
+ if (validation === "url") {
161
+ throw new Error(getZodMessage("url", { displayName: field }));
162
+ }
163
+ if (validation === "regex") {
164
+ throw new Error(getZodMessage("pattern", { displayName: field }));
165
+ }
166
+ }
167
+ break;
168
+ }
169
+ case "invalid_type": {
170
+ const expected = issueAny.expected;
171
+ if (expected && value === void 0) {
172
+ throw new Error(getZodMessage("required", { displayName: field }));
173
+ }
174
+ break;
175
+ }
176
+ }
177
+ throw new Error(issue.message);
178
+ }
179
+ };
180
+ }
181
+ function isZodRequired(schema) {
182
+ const schemaDesc = schema?._def?.typeName;
183
+ const inner = schema?._def?.innerType;
184
+ if (schemaDesc === "ZodOptional" || schemaDesc === "ZodNullable") return false;
185
+ if (inner?._def?.typeName === "ZodOptional" || inner?._def?.typeName === "ZodNullable") return false;
186
+ return true;
187
+ }
188
+
189
+ // src/components/JapaneseNameField.tsx
190
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
191
+ function getLabel(i18n, field, locale) {
192
+ return i18n.fields[field]?.label?.[locale] ?? i18n.fields[field]?.label?.["en"] ?? field;
193
+ }
194
+ function getCompoundLabel(i18n, prefix, locale) {
195
+ return i18n.fields[prefix]?.label?.[locale] ?? i18n.fields[prefix]?.label?.["en"];
196
+ }
197
+ function getPlaceholder(i18n, field, locale) {
198
+ return i18n.fields[field]?.placeholder?.[locale] ?? i18n.fields[field]?.placeholder?.["en"] ?? "";
199
+ }
200
+ function JapaneseNameField({
201
+ schemas,
202
+ i18n,
203
+ prefix = "name",
204
+ required = false,
205
+ showKana = true,
206
+ label,
207
+ kanaLabel
208
+ }) {
209
+ const locale = getZodLocale();
210
+ const lastnameField = `${prefix}_lastname`;
211
+ const firstnameField = `${prefix}_firstname`;
212
+ const kanaLastnameField = `${prefix}_kana_lastname`;
213
+ const kanaFirstnameField = `${prefix}_kana_firstname`;
214
+ const getRule = (field) => {
215
+ const schema = schemas[field];
216
+ if (!schema) return [];
217
+ return [zodRule(schema, getLabel(i18n, field, locale))];
218
+ };
219
+ const isFieldRequired = (field) => {
220
+ const schema = schemas[field];
221
+ if (!schema) return false;
222
+ return isZodRequired(schema);
223
+ };
224
+ const nameRequired = isFieldRequired(lastnameField) || isFieldRequired(firstnameField) || required;
225
+ const kanaRequired = isFieldRequired(kanaLastnameField) || isFieldRequired(kanaFirstnameField);
226
+ const nameLabel = label ?? getCompoundLabel(i18n, prefix, locale) ?? getLabel(i18n, lastnameField, locale);
227
+ const nameKanaLabel = kanaLabel ?? `${getCompoundLabel(i18n, prefix, locale) ?? getLabel(i18n, kanaLastnameField, locale)}\uFF08\u30AB\u30CA\uFF09`;
228
+ const lastnameShortLabel = locale === "ja" ? "\u59D3" : "Last";
229
+ const firstnameShortLabel = locale === "ja" ? "\u540D" : "First";
230
+ const prefixStyle = {
231
+ color: "rgba(0, 0, 0, 0.88)",
232
+ fontWeight: 500,
233
+ borderRight: "1px solid #d9d9d9",
234
+ paddingRight: 8,
235
+ marginRight: 4
236
+ };
237
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
238
+ /* @__PURE__ */ jsx(Form.Item, { label: nameLabel, required: nameRequired, style: { marginBottom: 0 }, children: /* @__PURE__ */ jsxs(Row, { gutter: 8, children: [
239
+ /* @__PURE__ */ jsx(Col, { span: 12, children: /* @__PURE__ */ jsx(Form.Item, { name: lastnameField, rules: getRule(lastnameField), style: { marginBottom: 16 }, children: /* @__PURE__ */ jsx(
240
+ Input,
241
+ {
242
+ prefix: /* @__PURE__ */ jsx("span", { style: prefixStyle, children: lastnameShortLabel }),
243
+ placeholder: getPlaceholder(i18n, lastnameField, locale)
244
+ }
245
+ ) }) }),
246
+ /* @__PURE__ */ jsx(Col, { span: 12, children: /* @__PURE__ */ jsx(Form.Item, { name: firstnameField, rules: getRule(firstnameField), style: { marginBottom: 16 }, children: /* @__PURE__ */ jsx(
247
+ Input,
248
+ {
249
+ prefix: /* @__PURE__ */ jsx("span", { style: prefixStyle, children: firstnameShortLabel }),
250
+ placeholder: getPlaceholder(i18n, firstnameField, locale)
251
+ }
252
+ ) }) })
253
+ ] }) }),
254
+ showKana && /* @__PURE__ */ jsx(Form.Item, { label: nameKanaLabel, required: kanaRequired, style: { marginBottom: 0 }, children: /* @__PURE__ */ jsxs(Row, { gutter: 8, children: [
255
+ /* @__PURE__ */ jsx(Col, { span: 12, children: /* @__PURE__ */ jsx(
256
+ Form.Item,
257
+ {
258
+ name: kanaLastnameField,
259
+ rules: getRule(kanaLastnameField),
260
+ style: { marginBottom: 16 },
261
+ children: /* @__PURE__ */ jsx(
262
+ Input,
263
+ {
264
+ prefix: /* @__PURE__ */ jsx("span", { style: prefixStyle, children: lastnameShortLabel }),
265
+ placeholder: getPlaceholder(i18n, kanaLastnameField, locale)
266
+ }
267
+ )
268
+ }
269
+ ) }),
270
+ /* @__PURE__ */ jsx(Col, { span: 12, children: /* @__PURE__ */ jsx(
271
+ Form.Item,
272
+ {
273
+ name: kanaFirstnameField,
274
+ rules: getRule(kanaFirstnameField),
275
+ style: { marginBottom: 16 },
276
+ children: /* @__PURE__ */ jsx(
277
+ Input,
278
+ {
279
+ prefix: /* @__PURE__ */ jsx("span", { style: prefixStyle, children: firstnameShortLabel }),
280
+ placeholder: getPlaceholder(i18n, kanaFirstnameField, locale)
281
+ }
282
+ )
283
+ }
284
+ ) })
285
+ ] }) })
286
+ ] });
287
+ }
288
+
289
+ // src/components/JapaneseAddressField.tsx
290
+ import { useState, useCallback } from "react";
291
+ import { Form as Form2, Input as Input2, Select, Button, message } from "antd";
292
+ import { SearchOutlined, LoadingOutlined } from "@ant-design/icons";
293
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
294
+ function getLabel2(i18n, field, locale) {
295
+ return i18n.fields[field]?.label?.[locale] ?? i18n.fields[field]?.label?.["en"] ?? field;
296
+ }
297
+ function getPlaceholder2(i18n, field, locale) {
298
+ return i18n.fields[field]?.placeholder?.[locale] ?? i18n.fields[field]?.placeholder?.["en"] ?? "";
299
+ }
300
+ async function lookupPostalCode(postalCode) {
301
+ try {
302
+ const response = await fetch(`https://zipcloud.ibsnet.co.jp/api/search?zipcode=${postalCode}`);
303
+ const data = await response.json();
304
+ if (data.results && data.results.length > 0) {
305
+ const result = data.results[0];
306
+ return {
307
+ prefectureCode: result.prefcode,
308
+ prefectureName: result.address1,
309
+ address1: result.address2,
310
+ address2: result.address3
311
+ };
312
+ }
313
+ return null;
314
+ } catch (error) {
315
+ console.error("Postal code lookup failed:", error);
316
+ return null;
317
+ }
318
+ }
319
+ var MESSAGES = {
320
+ ja: {
321
+ searchAddress: "\u4F4F\u6240\u691C\u7D22",
322
+ searching: "\u691C\u7D22\u4E2D...",
323
+ notFound: "\u90F5\u4FBF\u756A\u53F7\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F",
324
+ error: "\u4F4F\u6240\u691C\u7D22\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
325
+ invalidFormat: "\u90F5\u4FBF\u756A\u53F7\u306E\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093\uFF08\u4F8B\uFF1A123-4567\uFF09"
326
+ },
327
+ en: {
328
+ searchAddress: "Search Address",
329
+ searching: "Searching...",
330
+ notFound: "Postal code not found",
331
+ error: "Address lookup failed",
332
+ invalidFormat: "Invalid postal code format (e.g., 123-4567)"
333
+ },
334
+ vi: {
335
+ searchAddress: "T\xECm \u0111\u1ECBa ch\u1EC9",
336
+ searching: "\u0110ang t\xECm...",
337
+ notFound: "Kh\xF4ng t\xECm th\u1EA5y m\xE3 b\u01B0u \u0111i\u1EC7n",
338
+ error: "T\xECm \u0111\u1ECBa ch\u1EC9 th\u1EA5t b\u1EA1i",
339
+ invalidFormat: "\u0110\u1ECBnh d\u1EA1ng m\xE3 b\u01B0u \u0111i\u1EC7n kh\xF4ng h\u1EE3p l\u1EC7 (VD: 123-4567)"
340
+ }
341
+ };
342
+ function getMessage(key, locale) {
343
+ return MESSAGES[locale]?.[key] ?? MESSAGES.ja[key];
344
+ }
345
+ function JapaneseAddressField({
346
+ form,
347
+ schemas,
348
+ i18n,
349
+ prefix = "address",
350
+ usePrefectureId = false,
351
+ prefectureOptions,
352
+ enablePostalLookup = true,
353
+ showSearchButton = true,
354
+ autoSearch = true,
355
+ onPostalLookup
356
+ }) {
357
+ const locale = getZodLocale();
358
+ const [isSearching, setIsSearching] = useState(false);
359
+ const postalCodeField = `${prefix}_postal_code`;
360
+ const prefectureField = usePrefectureId ? `${prefix}_prefecture_id` : `${prefix}_prefecture`;
361
+ const address1Field = `${prefix}_address1`;
362
+ const address2Field = `${prefix}_address2`;
363
+ const address3Field = `${prefix}_address3`;
364
+ const getRule = (field) => {
365
+ const schema = schemas[field];
366
+ if (!schema) return [];
367
+ return [zodRule(schema, getLabel2(i18n, field, locale))];
368
+ };
369
+ const isRequired = (field) => {
370
+ const schema = schemas[field];
371
+ if (!schema) return false;
372
+ return isZodRequired(schema);
373
+ };
374
+ const doLookup = useCallback(
375
+ async (postalCode) => {
376
+ const digits = postalCode.replace(/[^0-9]/g, "");
377
+ if (digits.length !== 7) {
378
+ message.warning(getMessage("invalidFormat", locale));
379
+ return;
380
+ }
381
+ setIsSearching(true);
382
+ try {
383
+ const lookupFn = onPostalLookup ?? lookupPostalCode;
384
+ const result = await lookupFn(postalCode);
385
+ if (result) {
386
+ const prefectureValue = usePrefectureId ? result.prefectureCode : result.prefecture;
387
+ form.setFieldsValue({
388
+ [prefectureField]: prefectureValue,
389
+ [address1Field]: result.address1,
390
+ [address2Field]: result.address2
391
+ });
392
+ } else {
393
+ message.info(getMessage("notFound", locale));
394
+ }
395
+ } catch (error) {
396
+ message.error(getMessage("error", locale));
397
+ console.error("Postal code lookup failed:", error);
398
+ } finally {
399
+ setIsSearching(false);
400
+ }
401
+ },
402
+ [form, locale, onPostalLookup, prefectureField, address1Field, address2Field, usePrefectureId]
403
+ );
404
+ const handlePostalCodeChange = async (e) => {
405
+ const postalCode = e.target.value.replace(/[^0-9]/g, "");
406
+ if (autoSearch && enablePostalLookup && postalCode.length === 7) {
407
+ await doLookup(postalCode);
408
+ }
409
+ };
410
+ const handleSearchClick = async () => {
411
+ const postalCode = form.getFieldValue(postalCodeField);
412
+ if (postalCode) {
413
+ await doLookup(postalCode);
414
+ }
415
+ };
416
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
417
+ /* @__PURE__ */ jsx2(
418
+ Form2.Item,
419
+ {
420
+ name: postalCodeField,
421
+ label: getLabel2(i18n, postalCodeField, locale),
422
+ rules: getRule(postalCodeField),
423
+ required: isRequired(postalCodeField),
424
+ children: /* @__PURE__ */ jsx2(
425
+ Input2,
426
+ {
427
+ placeholder: getPlaceholder2(i18n, postalCodeField, locale),
428
+ style: { width: enablePostalLookup && showSearchButton ? "calc(100% - 110px)" : 150 },
429
+ onChange: handlePostalCodeChange,
430
+ addonAfter: enablePostalLookup && showSearchButton && /* @__PURE__ */ jsx2(
431
+ Button,
432
+ {
433
+ type: "text",
434
+ size: "small",
435
+ icon: isSearching ? /* @__PURE__ */ jsx2(LoadingOutlined, {}) : /* @__PURE__ */ jsx2(SearchOutlined, {}),
436
+ onClick: handleSearchClick,
437
+ disabled: isSearching,
438
+ children: getMessage("searchAddress", locale)
439
+ }
440
+ )
441
+ }
442
+ )
443
+ }
444
+ ),
445
+ /* @__PURE__ */ jsx2(
446
+ Form2.Item,
447
+ {
448
+ name: prefectureField,
449
+ label: getLabel2(i18n, prefectureField, locale),
450
+ rules: getRule(prefectureField),
451
+ required: isRequired(prefectureField),
452
+ children: prefectureOptions ? /* @__PURE__ */ jsx2(
453
+ Select,
454
+ {
455
+ placeholder: getPlaceholder2(i18n, prefectureField, locale),
456
+ options: prefectureOptions,
457
+ style: { width: 200 },
458
+ showSearch: true,
459
+ optionFilterProp: "label"
460
+ }
461
+ ) : /* @__PURE__ */ jsx2(
462
+ Input2,
463
+ {
464
+ placeholder: getPlaceholder2(i18n, prefectureField, locale),
465
+ style: { width: 200 }
466
+ }
467
+ )
468
+ }
469
+ ),
470
+ /* @__PURE__ */ jsx2(
471
+ Form2.Item,
472
+ {
473
+ name: address1Field,
474
+ label: getLabel2(i18n, address1Field, locale),
475
+ rules: getRule(address1Field),
476
+ required: isRequired(address1Field),
477
+ children: /* @__PURE__ */ jsx2(Input2, { placeholder: getPlaceholder2(i18n, address1Field, locale) })
478
+ }
479
+ ),
480
+ /* @__PURE__ */ jsx2(
481
+ Form2.Item,
482
+ {
483
+ name: address2Field,
484
+ label: getLabel2(i18n, address2Field, locale),
485
+ rules: getRule(address2Field),
486
+ required: isRequired(address2Field),
487
+ children: /* @__PURE__ */ jsx2(Input2, { placeholder: getPlaceholder2(i18n, address2Field, locale) })
488
+ }
489
+ ),
490
+ /* @__PURE__ */ jsx2(
491
+ Form2.Item,
492
+ {
493
+ name: address3Field,
494
+ label: getLabel2(i18n, address3Field, locale),
495
+ rules: getRule(address3Field),
496
+ required: isRequired(address3Field),
497
+ children: /* @__PURE__ */ jsx2(Input2, { placeholder: getPlaceholder2(i18n, address3Field, locale) })
498
+ }
499
+ )
500
+ ] });
501
+ }
502
+
503
+ // src/components/JapaneseBankField.tsx
504
+ import { Form as Form3, Input as Input3, Select as Select2, Row as Row2, Col as Col2 } from "antd";
505
+ import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
506
+ function getLabel3(i18n, field, locale) {
507
+ return i18n.fields[field]?.label?.[locale] ?? i18n.fields[field]?.label?.["en"] ?? field;
508
+ }
509
+ function getPlaceholder3(i18n, field, locale) {
510
+ return i18n.fields[field]?.placeholder?.[locale] ?? i18n.fields[field]?.placeholder?.["en"] ?? "";
511
+ }
512
+ function JapaneseBankField({
513
+ schemas,
514
+ i18n,
515
+ prefix = "bank",
516
+ accountTypeOptions
517
+ }) {
518
+ const locale = getZodLocale();
519
+ const bankCodeField = `${prefix}_bank_code`;
520
+ const bankNameField = `${prefix}_bank_name`;
521
+ const branchCodeField = `${prefix}_branch_code`;
522
+ const branchNameField = `${prefix}_branch_name`;
523
+ const accountTypeField = `${prefix}_account_type`;
524
+ const accountNumberField = `${prefix}_account_number`;
525
+ const accountHolderField = `${prefix}_account_holder`;
526
+ const getRule = (field) => {
527
+ const schema = schemas[field];
528
+ if (!schema) return [];
529
+ return [zodRule(schema, getLabel3(i18n, field, locale))];
530
+ };
531
+ const isRequired = (field) => {
532
+ const schema = schemas[field];
533
+ if (!schema) return false;
534
+ return isZodRequired(schema);
535
+ };
536
+ const bankRequired = isRequired(bankCodeField) || isRequired(bankNameField);
537
+ const branchRequired = isRequired(branchCodeField) || isRequired(branchNameField);
538
+ const codeShortLabel = locale === "ja" ? "\u30B3\u30FC\u30C9" : "Code";
539
+ const nameShortLabel = locale === "ja" ? "\u540D\u79F0" : "Name";
540
+ const bankLabel = locale === "ja" ? "\u9280\u884C" : "Bank";
541
+ const branchLabel = locale === "ja" ? "\u652F\u5E97" : "Branch";
542
+ const prefixStyle = {
543
+ color: "rgba(0, 0, 0, 0.88)",
544
+ fontWeight: 500,
545
+ borderRight: "1px solid #d9d9d9",
546
+ paddingRight: 8,
547
+ marginRight: 4
548
+ };
549
+ return /* @__PURE__ */ jsxs3(Fragment3, { children: [
550
+ /* @__PURE__ */ jsx3(Form3.Item, { label: bankLabel, required: bankRequired, style: { marginBottom: 0 }, children: /* @__PURE__ */ jsxs3(Row2, { gutter: 8, children: [
551
+ /* @__PURE__ */ jsx3(Col2, { span: 8, children: /* @__PURE__ */ jsx3(Form3.Item, { name: bankCodeField, rules: getRule(bankCodeField), style: { marginBottom: 16 }, children: /* @__PURE__ */ jsx3(
552
+ Input3,
553
+ {
554
+ prefix: /* @__PURE__ */ jsx3("span", { style: prefixStyle, children: codeShortLabel }),
555
+ placeholder: getPlaceholder3(i18n, bankCodeField, locale),
556
+ maxLength: 4
557
+ }
558
+ ) }) }),
559
+ /* @__PURE__ */ jsx3(Col2, { span: 16, children: /* @__PURE__ */ jsx3(Form3.Item, { name: bankNameField, rules: getRule(bankNameField), style: { marginBottom: 16 }, children: /* @__PURE__ */ jsx3(
560
+ Input3,
561
+ {
562
+ prefix: /* @__PURE__ */ jsx3("span", { style: prefixStyle, children: nameShortLabel }),
563
+ placeholder: getPlaceholder3(i18n, bankNameField, locale)
564
+ }
565
+ ) }) })
566
+ ] }) }),
567
+ /* @__PURE__ */ jsx3(Form3.Item, { label: branchLabel, required: branchRequired, style: { marginBottom: 0 }, children: /* @__PURE__ */ jsxs3(Row2, { gutter: 8, children: [
568
+ /* @__PURE__ */ jsx3(Col2, { span: 8, children: /* @__PURE__ */ jsx3(
569
+ Form3.Item,
570
+ {
571
+ name: branchCodeField,
572
+ rules: getRule(branchCodeField),
573
+ style: { marginBottom: 16 },
574
+ children: /* @__PURE__ */ jsx3(
575
+ Input3,
576
+ {
577
+ prefix: /* @__PURE__ */ jsx3("span", { style: prefixStyle, children: codeShortLabel }),
578
+ placeholder: getPlaceholder3(i18n, branchCodeField, locale),
579
+ maxLength: 3
580
+ }
581
+ )
582
+ }
583
+ ) }),
584
+ /* @__PURE__ */ jsx3(Col2, { span: 16, children: /* @__PURE__ */ jsx3(
585
+ Form3.Item,
586
+ {
587
+ name: branchNameField,
588
+ rules: getRule(branchNameField),
589
+ style: { marginBottom: 16 },
590
+ children: /* @__PURE__ */ jsx3(
591
+ Input3,
592
+ {
593
+ prefix: /* @__PURE__ */ jsx3("span", { style: prefixStyle, children: nameShortLabel }),
594
+ placeholder: getPlaceholder3(i18n, branchNameField, locale)
595
+ }
596
+ )
597
+ }
598
+ ) })
599
+ ] }) }),
600
+ /* @__PURE__ */ jsx3(
601
+ Form3.Item,
602
+ {
603
+ name: accountTypeField,
604
+ label: getLabel3(i18n, accountTypeField, locale),
605
+ rules: getRule(accountTypeField),
606
+ required: isRequired(accountTypeField),
607
+ children: accountTypeOptions ? /* @__PURE__ */ jsx3(
608
+ Select2,
609
+ {
610
+ placeholder: getPlaceholder3(i18n, accountTypeField, locale),
611
+ options: accountTypeOptions,
612
+ style: { width: 150 }
613
+ }
614
+ ) : /* @__PURE__ */ jsx3(
615
+ Input3,
616
+ {
617
+ placeholder: getPlaceholder3(i18n, accountTypeField, locale),
618
+ style: { width: 150 }
619
+ }
620
+ )
621
+ }
622
+ ),
623
+ /* @__PURE__ */ jsx3(
624
+ Form3.Item,
625
+ {
626
+ name: accountNumberField,
627
+ label: getLabel3(i18n, accountNumberField, locale),
628
+ rules: getRule(accountNumberField),
629
+ required: isRequired(accountNumberField),
630
+ children: /* @__PURE__ */ jsx3(
631
+ Input3,
632
+ {
633
+ placeholder: getPlaceholder3(i18n, accountNumberField, locale),
634
+ maxLength: 7,
635
+ style: { width: 150 }
636
+ }
637
+ )
638
+ }
639
+ ),
640
+ /* @__PURE__ */ jsx3(
641
+ Form3.Item,
642
+ {
643
+ name: accountHolderField,
644
+ label: getLabel3(i18n, accountHolderField, locale),
645
+ rules: getRule(accountHolderField),
646
+ required: isRequired(accountHolderField),
647
+ children: /* @__PURE__ */ jsx3(Input3, { placeholder: getPlaceholder3(i18n, accountHolderField, locale) })
648
+ }
649
+ )
650
+ ] });
651
+ }
652
+ export {
653
+ JapaneseAddressField,
654
+ JapaneseBankField,
655
+ JapaneseNameField
656
+ };
657
+ //# sourceMappingURL=index.js.map