@nagiyu/react 0.1.0 → 0.2.0-next.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/dist/cjs/api-client.js +129 -0
- package/dist/cjs/api-client.js.map +1 -0
- package/dist/cjs/components/ServiceWorkerRegistration.js +48 -0
- package/dist/cjs/components/ServiceWorkerRegistration.js.map +1 -0
- package/dist/cjs/components/index.js +12 -0
- package/dist/cjs/components/index.js.map +1 -0
- package/dist/cjs/hooks/index.js +15 -0
- package/dist/cjs/hooks/index.js.map +1 -0
- package/dist/cjs/hooks/useAPIRequest.js +140 -0
- package/dist/cjs/hooks/useAPIRequest.js.map +1 -0
- package/dist/cjs/hooks/useEnterSubmit.js +73 -0
- package/dist/cjs/hooks/useEnterSubmit.js.map +1 -0
- package/dist/cjs/hooks/usePushSubscription.js +110 -0
- package/dist/cjs/hooks/usePushSubscription.js.map +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/package.json +9 -7
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Client クラス
|
|
4
|
+
*
|
|
5
|
+
* @nagiyu/common の関数型APIをクラスベースでラップし、
|
|
6
|
+
* React アプリケーションでの利用を容易にする
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ApiClient = exports.APIError = void 0;
|
|
10
|
+
const common_1 = require("@nagiyu/common");
|
|
11
|
+
var common_2 = require("@nagiyu/common");
|
|
12
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return common_2.APIError; } });
|
|
13
|
+
/**
|
|
14
|
+
* API Client クラス
|
|
15
|
+
*
|
|
16
|
+
* リトライ機能、タイムアウト、エラーマッピングを統合したHTTPクライアント
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const client = new ApiClient('/api');
|
|
21
|
+
*
|
|
22
|
+
* // GET リクエスト
|
|
23
|
+
* const user = await client.get<User>('/users/123');
|
|
24
|
+
*
|
|
25
|
+
* // POST リクエスト
|
|
26
|
+
* const newUser = await client.post<User>('/users', { name: 'John' });
|
|
27
|
+
*
|
|
28
|
+
* // カスタムリトライ設定
|
|
29
|
+
* const data = await client.get<Data>('/data', {
|
|
30
|
+
* retry: { maxRetries: 5, initialDelay: 2000 }
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class ApiClient {
|
|
35
|
+
/**
|
|
36
|
+
* API Client を作成
|
|
37
|
+
*
|
|
38
|
+
* @param baseUrl - ベースURL(デフォルト: '')
|
|
39
|
+
* @param defaultOptions - デフォルトのリクエストオプション
|
|
40
|
+
*/
|
|
41
|
+
constructor(baseUrl = '', defaultOptions = {}) {
|
|
42
|
+
this.baseUrl = baseUrl;
|
|
43
|
+
this.defaultOptions = defaultOptions;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* APIリクエストを実行
|
|
47
|
+
*
|
|
48
|
+
* @template T - レスポンスデータの型
|
|
49
|
+
* @param url - リクエストURL
|
|
50
|
+
* @param options - リクエストオプション
|
|
51
|
+
* @returns レスポンスデータ
|
|
52
|
+
*/
|
|
53
|
+
async request(url, options = {}) {
|
|
54
|
+
const fullUrl = this.baseUrl + url;
|
|
55
|
+
const mergedOptions = {
|
|
56
|
+
...this.defaultOptions,
|
|
57
|
+
...options,
|
|
58
|
+
headers: {
|
|
59
|
+
...this.defaultOptions.headers,
|
|
60
|
+
...options.headers,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
return (0, common_1.apiRequest)(fullUrl, mergedOptions);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* GET リクエスト
|
|
67
|
+
*
|
|
68
|
+
* @template T - レスポンスデータの型
|
|
69
|
+
* @param url - リクエストURL
|
|
70
|
+
* @param options - リクエストオプション(method と body は除外)
|
|
71
|
+
* @returns レスポンスデータ
|
|
72
|
+
*/
|
|
73
|
+
async get(url, options = {}) {
|
|
74
|
+
return this.request(url, { ...options, method: 'GET' });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* POST リクエスト
|
|
78
|
+
*
|
|
79
|
+
* @template T - レスポンスデータの型
|
|
80
|
+
* @param url - リクエストURL
|
|
81
|
+
* @param body - リクエストボディ
|
|
82
|
+
* @param options - リクエストオプション(method と body は除外)
|
|
83
|
+
* @returns レスポンスデータ
|
|
84
|
+
*/
|
|
85
|
+
async post(url, body, options = {}) {
|
|
86
|
+
return this.request(url, {
|
|
87
|
+
...options,
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/json',
|
|
91
|
+
...options.headers,
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify(body),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* PUT リクエスト
|
|
98
|
+
*
|
|
99
|
+
* @template T - レスポンスデータの型
|
|
100
|
+
* @param url - リクエストURL
|
|
101
|
+
* @param body - リクエストボディ
|
|
102
|
+
* @param options - リクエストオプション(method と body は除外)
|
|
103
|
+
* @returns レスポンスデータ
|
|
104
|
+
*/
|
|
105
|
+
async put(url, body, options = {}) {
|
|
106
|
+
return this.request(url, {
|
|
107
|
+
...options,
|
|
108
|
+
method: 'PUT',
|
|
109
|
+
headers: {
|
|
110
|
+
'Content-Type': 'application/json',
|
|
111
|
+
...options.headers,
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify(body),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* DELETE リクエスト
|
|
118
|
+
*
|
|
119
|
+
* @template T - レスポンスデータの型
|
|
120
|
+
* @param url - リクエストURL
|
|
121
|
+
* @param options - リクエストオプション(method と body は除外)
|
|
122
|
+
* @returns レスポンスデータ
|
|
123
|
+
*/
|
|
124
|
+
async delete(url, options = {}) {
|
|
125
|
+
return this.request(url, { ...options, method: 'DELETE' });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.ApiClient = ApiClient;
|
|
129
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/api-client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2CAAoE;AAIpE,yCAA0C;AAAjC,kGAAA,QAAQ,OAAA;AAEjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,SAAS;IAIpB;;;;;OAKG;IACH,YAAY,UAAkB,EAAE,EAAE,iBAAoC,EAAE;QACtE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAAc,GAAW,EAAE,UAA6B,EAAE;QAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnC,MAAM,aAAa,GAAG;YACpB,GAAG,IAAI,CAAC,cAAc;YACtB,GAAG,OAAO;YACV,OAAO,EAAE;gBACP,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO;gBAC9B,GAAG,OAAO,CAAC,OAAO;aACnB;SACF,CAAC;QAEF,OAAO,IAAA,mBAAU,EAAI,OAAO,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACd,GAAW,EACX,UAAsD,EAAE;QAExD,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,IAAI,CACf,GAAW,EACX,IAAa,EACb,UAAsD,EAAE;QAExD,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE;YAC1B,GAAG,OAAO;YACV,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO,CAAC,OAAO;aACnB;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,GAAG,CACd,GAAW,EACX,IAAa,EACb,UAAsD,EAAE;QAExD,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE;YAC1B,GAAG,OAAO;YACV,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO,CAAC,OAAO;aACnB;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,MAAM,CACjB,GAAW,EACX,UAAsD,EAAE;QAExD,OAAO,IAAI,CAAC,OAAO,CAAI,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC;CACF;AApHD,8BAoHC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES = void 0;
|
|
5
|
+
exports.ServiceWorkerRegistration = ServiceWorkerRegistration;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const browser_1 = require("@nagiyu/browser");
|
|
8
|
+
exports.SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES = {
|
|
9
|
+
SERVICE_WORKER_REGISTRATION_FAILED: 'Service Workerの登録に失敗しました',
|
|
10
|
+
PUSH_SUBSCRIPTION_REFRESH_FAILED: 'Push通知の購読の更新に失敗しました',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* layout に置いて Service Worker を登録し、必要なら許可済みユーザーの Push 購読を再送する。
|
|
14
|
+
* 何も描画しない。失敗は画面に影響させず console.error に出すだけにする。
|
|
15
|
+
*/
|
|
16
|
+
function ServiceWorkerRegistration({ swPath, resubscribe = false, vapidPublicKeyEndpoint, subscribeEndpoint, bodyShape, }) {
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
|
+
if (!('serviceWorker' in navigator)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const init = async () => {
|
|
22
|
+
try {
|
|
23
|
+
await (0, browser_1.registerServiceWorker)(swPath);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(exports.SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES.SERVICE_WORKER_REGISTRATION_FAILED, error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!resubscribe) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await (0, browser_1.refreshPushSubscription)({
|
|
34
|
+
swPath,
|
|
35
|
+
vapidPublicKeyEndpoint,
|
|
36
|
+
subscribeEndpoint,
|
|
37
|
+
bodyShape,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(exports.SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES.PUSH_SUBSCRIPTION_REFRESH_FAILED, error);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
void init();
|
|
45
|
+
}, [swPath, resubscribe, vapidPublicKeyEndpoint, subscribeEndpoint, bodyShape]);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=ServiceWorkerRegistration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceWorkerRegistration.js","sourceRoot":"","sources":["../../../src/components/ServiceWorkerRegistration.tsx"],"names":[],"mappings":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* React Components
|
|
4
|
+
*
|
|
5
|
+
* Export all React components from this module.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES = exports.ServiceWorkerRegistration = void 0;
|
|
9
|
+
var ServiceWorkerRegistration_1 = require("./ServiceWorkerRegistration");
|
|
10
|
+
Object.defineProperty(exports, "ServiceWorkerRegistration", { enumerable: true, get: function () { return ServiceWorkerRegistration_1.ServiceWorkerRegistration; } });
|
|
11
|
+
Object.defineProperty(exports, "SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES", { enumerable: true, get: function () { return ServiceWorkerRegistration_1.SERVICE_WORKER_REGISTRATION_ERROR_MESSAGES; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yEAGqC;AAFnC,sIAAA,yBAAyB,OAAA;AACzB,uJAAA,0CAA0C,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* React Hooks
|
|
4
|
+
*
|
|
5
|
+
* Export all custom React hooks from this module.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.useEnterSubmit = exports.usePushSubscription = exports.useAPIRequest = void 0;
|
|
9
|
+
var useAPIRequest_1 = require("./useAPIRequest");
|
|
10
|
+
Object.defineProperty(exports, "useAPIRequest", { enumerable: true, get: function () { return useAPIRequest_1.useAPIRequest; } });
|
|
11
|
+
var usePushSubscription_1 = require("./usePushSubscription");
|
|
12
|
+
Object.defineProperty(exports, "usePushSubscription", { enumerable: true, get: function () { return usePushSubscription_1.usePushSubscription; } });
|
|
13
|
+
var useEnterSubmit_1 = require("./useEnterSubmit");
|
|
14
|
+
Object.defineProperty(exports, "useEnterSubmit", { enumerable: true, get: function () { return useEnterSubmit_1.useEnterSubmit; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAE5B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useAPIRequest = useAPIRequest;
|
|
5
|
+
/**
|
|
6
|
+
* useAPIRequest Hook
|
|
7
|
+
*
|
|
8
|
+
* APIリクエストを実行し、エラーハンドリングとリトライ機能を提供するカスタムフック
|
|
9
|
+
*
|
|
10
|
+
* ## 依存注入パターン
|
|
11
|
+
* このフックはトースト通知などのUI依存を持たず、成功時・エラー時のコールバックを通じて
|
|
12
|
+
* 呼び出し側が自由にUI処理を実装できます。
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useAPIRequest } from '@nagiyu/react';
|
|
17
|
+
* import { useSnackbar } from '../components/SnackbarProvider';
|
|
18
|
+
*
|
|
19
|
+
* function MyComponent() {
|
|
20
|
+
* const { showSuccess, showError } = useSnackbar();
|
|
21
|
+
*
|
|
22
|
+
* const { data, loading, error, execute } = useAPIRequest<User>({
|
|
23
|
+
* onSuccess: (data) => showSuccess('ユーザー情報を取得しました'),
|
|
24
|
+
* onError: (error) => showError(error.message),
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const handleFetch = async () => {
|
|
28
|
+
* await execute('/api/user');
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* // ...
|
|
33
|
+
* );
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const react_1 = require("react");
|
|
38
|
+
const common_1 = require("@nagiyu/common");
|
|
39
|
+
/**
|
|
40
|
+
* useAPIRequest Hook
|
|
41
|
+
*
|
|
42
|
+
* APIリクエストを実行し、状態管理とエラーハンドリングを提供
|
|
43
|
+
*
|
|
44
|
+
* @template T - レスポンスデータの型
|
|
45
|
+
* @param options - Hook のオプション
|
|
46
|
+
* @returns APIリクエストの状態と操作関数
|
|
47
|
+
*/
|
|
48
|
+
function useAPIRequest(options = {}) {
|
|
49
|
+
const { onSuccess, onError } = options;
|
|
50
|
+
const [state, setState] = (0, react_1.useState)({
|
|
51
|
+
data: null,
|
|
52
|
+
loading: false,
|
|
53
|
+
error: null,
|
|
54
|
+
});
|
|
55
|
+
const [lastRequest, setLastRequest] = (0, react_1.useState)(null);
|
|
56
|
+
// コールバックを ref に保存して、常に最新の参照を使用
|
|
57
|
+
const onSuccessRef = (0, react_1.useRef)(onSuccess);
|
|
58
|
+
const onErrorRef = (0, react_1.useRef)(onError);
|
|
59
|
+
// コンポーネントがマウントされているかを追跡
|
|
60
|
+
const isMountedRef = (0, react_1.useRef)(true);
|
|
61
|
+
// リクエストIDを追跡して、最新のリクエストのみを処理
|
|
62
|
+
const requestIdRef = (0, react_1.useRef)(0);
|
|
63
|
+
// コールバックの参照を更新
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
onSuccessRef.current = onSuccess;
|
|
66
|
+
onErrorRef.current = onError;
|
|
67
|
+
}, [onSuccess, onError]);
|
|
68
|
+
// コンポーネントのマウント状態を追跡
|
|
69
|
+
(0, react_1.useEffect)(() => {
|
|
70
|
+
isMountedRef.current = true;
|
|
71
|
+
return () => {
|
|
72
|
+
isMountedRef.current = false;
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
/**
|
|
76
|
+
* APIリクエストを実行
|
|
77
|
+
*/
|
|
78
|
+
const execute = (0, react_1.useCallback)(async (url, requestOptions) => {
|
|
79
|
+
// 新しいリクエストIDを生成
|
|
80
|
+
const currentRequestId = ++requestIdRef.current;
|
|
81
|
+
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
82
|
+
setLastRequest({ url, options: requestOptions });
|
|
83
|
+
try {
|
|
84
|
+
const data = await (0, common_1.apiRequest)(url, requestOptions);
|
|
85
|
+
// コンポーネントがアンマウントされている、または新しいリクエストが開始された場合は状態を更新しない
|
|
86
|
+
if (!isMountedRef.current || currentRequestId !== requestIdRef.current) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
setState({ data, loading: false, error: null });
|
|
90
|
+
// 成功時コールバックを実行
|
|
91
|
+
if (onSuccessRef.current) {
|
|
92
|
+
onSuccessRef.current(data);
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const apiError = error;
|
|
98
|
+
// コンポーネントがアンマウントされている、または新しいリクエストが開始された場合は状態を更新しない
|
|
99
|
+
if (!isMountedRef.current || currentRequestId !== requestIdRef.current) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
setState({ data: null, loading: false, error: apiError });
|
|
103
|
+
// エラー時コールバックを実行
|
|
104
|
+
if (onErrorRef.current) {
|
|
105
|
+
onErrorRef.current(apiError);
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}, [] // 依存配列を空にして、refを使用することで常に最新の値にアクセス
|
|
110
|
+
);
|
|
111
|
+
/**
|
|
112
|
+
* 状態をリセット
|
|
113
|
+
*
|
|
114
|
+
* Note: reset() を実行すると lastRequest もクリアされるため、
|
|
115
|
+
* その後 retry() を呼んでも何も実行されません。
|
|
116
|
+
*/
|
|
117
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
118
|
+
setState({ data: null, loading: false, error: null });
|
|
119
|
+
setLastRequest(null);
|
|
120
|
+
}, []);
|
|
121
|
+
/**
|
|
122
|
+
* 最後のリクエストをリトライ
|
|
123
|
+
*/
|
|
124
|
+
const retry = (0, react_1.useCallback)(async () => {
|
|
125
|
+
if (!lastRequest) {
|
|
126
|
+
console.warn('No previous request to retry');
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return execute(lastRequest.url, lastRequest.options);
|
|
130
|
+
}, [lastRequest, execute]);
|
|
131
|
+
return {
|
|
132
|
+
data: state.data,
|
|
133
|
+
loading: state.loading,
|
|
134
|
+
error: state.error,
|
|
135
|
+
execute,
|
|
136
|
+
reset,
|
|
137
|
+
retry,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=useAPIRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAPIRequest.js","sourceRoot":"","sources":["../../../src/hooks/useAPIRequest.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAoHb,sCAoHC;AAtOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iCAAiE;AACjE,2CAA8E;AAuE9E;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAC3B,UAAmC,EAAE;IAErC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEvC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAqB;QACrD,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAqB,IAAI,CAAC,CAAC;IAEzE,+BAA+B;IAC/B,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,SAAS,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC;IAEnC,wBAAwB;IACxB,MAAM,YAAY,GAAG,IAAA,cA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EAAE,OAAO,CAAC,CAAC,CAAC;IAE3B,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO;QACP,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useEnterSubmit = useEnterSubmit;
|
|
5
|
+
/**
|
|
6
|
+
* useEnterSubmit Hook
|
|
7
|
+
*
|
|
8
|
+
* 単一行入力でエンターキー押下時に onSubmit を呼ぶ onKeyDown ハンドラを生成するカスタムフック。
|
|
9
|
+
* IME 変換確定中の Enter による誤発火を防ぐ。
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useEnterSubmit } from '@nagiyu/react';
|
|
14
|
+
*
|
|
15
|
+
* function SearchInput() {
|
|
16
|
+
* const [value, setValue] = React.useState('');
|
|
17
|
+
*
|
|
18
|
+
* const handleKeyDown = useEnterSubmit(() => {
|
|
19
|
+
* console.log('検索実行:', value);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <input
|
|
24
|
+
* value={value}
|
|
25
|
+
* onChange={(e) => setValue(e.target.value)}
|
|
26
|
+
* onKeyDown={handleKeyDown}
|
|
27
|
+
* />
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const react_1 = require("react");
|
|
33
|
+
/**
|
|
34
|
+
* useEnterSubmit Hook
|
|
35
|
+
*
|
|
36
|
+
* 単一行入力でエンターキー押下時に onSubmit を呼ぶ onKeyDown ハンドラを生成する。
|
|
37
|
+
* IME 変換確定中の Enter を無視し、修飾キー付きの Enter も無視する。
|
|
38
|
+
*
|
|
39
|
+
* @template T - イベントターゲットの HTML 要素型(既定: HTMLInputElement)
|
|
40
|
+
* @param onSubmit - エンターキー確定時に呼ばれるコールバック
|
|
41
|
+
* @param options - Hook のオプション
|
|
42
|
+
* @returns onKeyDown に渡すイベントハンドラ
|
|
43
|
+
*/
|
|
44
|
+
function useEnterSubmit(onSubmit, options) {
|
|
45
|
+
const disabled = options?.disabled ?? false;
|
|
46
|
+
const preventDefault = options?.preventDefault ?? true;
|
|
47
|
+
return (0, react_1.useCallback)((event) => {
|
|
48
|
+
// Enter キー以外は無視
|
|
49
|
+
if (event.key !== 'Enter') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// IME 変換確定中の Enter は無視する(誤確定防止)
|
|
53
|
+
// isComposing: 標準的な IME 確定検出
|
|
54
|
+
// keyCode === 229: 一部ブラウザ・環境での IME 確定検出(後方互換)
|
|
55
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// 修飾キー付きの Enter は無視する(改行・ショートカット等を壊さないため)
|
|
59
|
+
if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// disabled の場合は何もしない
|
|
63
|
+
if (disabled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// 確定条件を満たした場合の処理
|
|
67
|
+
if (preventDefault) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
}
|
|
70
|
+
onSubmit();
|
|
71
|
+
}, [onSubmit, disabled, preventDefault]);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=useEnterSubmit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEnterSubmit.js","sourceRoot":"","sources":["../../../src/hooks/useEnterSubmit.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AA6Db,wCAwCC;AAnGD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,iCAAoC;AAoBpC;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAC5B,QAAoB,EACpB,OAA+B;IAE/B,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,KAAK,CAAC;IAC5C,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,IAAI,CAAC;IAEvD,OAAO,IAAA,mBAAW,EAChB,CAAC,KAA6B,EAAE,EAAE;QAChC,gBAAgB;QAChB,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,gCAAgC;QAChC,6BAA6B;QAC7B,8CAA8C;QAC9C,IAAI,KAAK,CAAC,WAAW,CAAC,WAAW,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,0CAA0C;QAC1C,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACrE,OAAO;QACT,CAAC;QAED,qBAAqB;QACrB,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QAED,iBAAiB;QACjB,IAAI,cAAc,EAAE,CAAC;YACnB,KAAK,CAAC,cAAc,EAAE,CAAC;QACzB,CAAC;QAED,QAAQ,EAAE,CAAC;IACb,CAAC,EACD,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,CAAC,CACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.usePushSubscription = usePushSubscription;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const browser_1 = require("@nagiyu/browser");
|
|
7
|
+
function readPermission() {
|
|
8
|
+
return typeof window !== 'undefined' && typeof window.Notification !== 'undefined'
|
|
9
|
+
? window.Notification.permission
|
|
10
|
+
: 'default';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* プッシュ通知の購読状態を管理する React Hook。
|
|
14
|
+
*
|
|
15
|
+
* - マウント後にブラウザ対応・許可状態・既存 subscription を確認
|
|
16
|
+
* - `subscribe()` で `@nagiyu/browser` の `subscribePush` を呼び出し、公開鍵の取得とサーバー送信まで行う
|
|
17
|
+
* - `unsubscribe()` で既存 subscription を解除
|
|
18
|
+
*/
|
|
19
|
+
function usePushSubscription({ vapidPublicKeyEndpoint, subscribeEndpoint, bodyShape, swPath, } = {}) {
|
|
20
|
+
const [supported, setSupported] = (0, react_1.useState)(false);
|
|
21
|
+
const [permission, setPermission] = (0, react_1.useState)('default');
|
|
22
|
+
const [subscribed, setSubscribed] = (0, react_1.useState)(false);
|
|
23
|
+
const [ready, setReady] = (0, react_1.useState)(false);
|
|
24
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
25
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
let cancelled = false;
|
|
28
|
+
const isSupported = (0, browser_1.isPushSupported)();
|
|
29
|
+
setSupported(isSupported);
|
|
30
|
+
setPermission(readPermission());
|
|
31
|
+
if (!isSupported) {
|
|
32
|
+
setReady(true);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(async () => {
|
|
36
|
+
try {
|
|
37
|
+
const existing = await (0, browser_1.getPushSubscription)();
|
|
38
|
+
if (!cancelled) {
|
|
39
|
+
setSubscribed(Boolean(existing));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// 初期化エラーは無視(subscribe 時に再評価される)
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
if (!cancelled) {
|
|
47
|
+
setReady(true);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
return () => {
|
|
52
|
+
cancelled = true;
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
const subscribe = (0, react_1.useCallback)(async () => {
|
|
56
|
+
setLoading(true);
|
|
57
|
+
setError(null);
|
|
58
|
+
try {
|
|
59
|
+
const subscription = await (0, browser_1.subscribePush)({
|
|
60
|
+
vapidPublicKeyEndpoint,
|
|
61
|
+
subscribeEndpoint,
|
|
62
|
+
bodyShape,
|
|
63
|
+
swPath,
|
|
64
|
+
});
|
|
65
|
+
setSubscribed(true);
|
|
66
|
+
setPermission(readPermission());
|
|
67
|
+
return subscription;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
const asError = err instanceof Error ? err : new Error(String(err));
|
|
71
|
+
setError(asError);
|
|
72
|
+
setPermission(readPermission());
|
|
73
|
+
throw asError;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
setLoading(false);
|
|
77
|
+
}
|
|
78
|
+
}, [vapidPublicKeyEndpoint, subscribeEndpoint, bodyShape, swPath]);
|
|
79
|
+
const unsubscribe = (0, react_1.useCallback)(async () => {
|
|
80
|
+
setLoading(true);
|
|
81
|
+
setError(null);
|
|
82
|
+
try {
|
|
83
|
+
if (!supported) {
|
|
84
|
+
setSubscribed(false);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
await (0, browser_1.unsubscribePush)();
|
|
88
|
+
setSubscribed(false);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const asError = err instanceof Error ? err : new Error(String(err));
|
|
92
|
+
setError(asError);
|
|
93
|
+
throw asError;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
setLoading(false);
|
|
97
|
+
}
|
|
98
|
+
}, [supported]);
|
|
99
|
+
return {
|
|
100
|
+
supported,
|
|
101
|
+
permission,
|
|
102
|
+
subscribed,
|
|
103
|
+
ready,
|
|
104
|
+
loading,
|
|
105
|
+
error,
|
|
106
|
+
subscribe,
|
|
107
|
+
unsubscribe,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=usePushSubscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePushSubscription.js","sourceRoot":"","sources":["../../../src/hooks/usePushSubscription.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAsDb,kDA+FC;AAnJD,iCAAyD;AACzD,6CAKyB;AAiCzB,SAAS,cAAc;IACrB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,WAAW;QAChF,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU;QAChC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,EAClC,sBAAsB,EACtB,iBAAiB,EACjB,SAAS,EACT,MAAM,MACwB,EAAE;IAChC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAyB,SAAS,CAAC,CAAC;IAChF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IAC7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IACnD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAe,IAAI,CAAC,CAAC;IAEvD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,MAAM,WAAW,GAAG,IAAA,yBAAe,GAAE,CAAC;QACtC,YAAY,CAAC,WAAW,CAAC,CAAC;QAC1B,aAAa,CAAC,cAAc,EAAE,CAAC,C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,CAAC,CAAC;YAChC,MAAM,OAAO,CAAC;QAChB,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,sBAAsB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAEnE,MAAM,WAAW,GAAG,IAAA,mBAAW,EAAC,KAAK,IAAI,EAAE;QACzC,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,IAAI,CAAC;YACH,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,aAAa,CAAC,KAAK,CAAC,CAAC;gBACrB,OAAO;YACT,CAAC;YACD,MAAM,IAAA,yBAAe,GAAE,CAAC;YACxB,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACpE,QAAQ,CAAC,OAAO,CAAC,CAAC;YAClB,MAAM,OAAO,CAAC;QAChB,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACL,SAAS;QACT,UAAU;QACV,UAAU;QACV,KAAK;QACL,OAAO;QACP,KAAK;QACL,SAAS;QACT,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @nagiyu/react
|
|
4
|
+
*
|
|
5
|
+
* React-specific utility library for Nagiyu Platform.
|
|
6
|
+
* This package provides React hooks, components, and utilities that can be used
|
|
7
|
+
* across all React-based services.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.APIError = exports.ApiClient = exports.ServiceWorkerRegistration = exports.useEnterSubmit = exports.usePushSubscription = exports.useAPIRequest = void 0;
|
|
11
|
+
// Export React hooks
|
|
12
|
+
var hooks_1 = require("./hooks");
|
|
13
|
+
Object.defineProperty(exports, "useAPIRequest", { enumerable: true, get: function () { return hooks_1.useAPIRequest; } });
|
|
14
|
+
Object.defineProperty(exports, "usePushSubscription", { enumerable: true, get: function () { return hooks_1.usePushSubscription; } });
|
|
15
|
+
Object.defineProperty(exports, "useEnterSubmit", { enumerable: true, get: function () { return hooks_1.useEnterSubmit; } });
|
|
16
|
+
// Export React components
|
|
17
|
+
var components_1 = require("./components");
|
|
18
|
+
Object.defineProperty(exports, "ServiceWorkerRegistration", { enumerable: true, get: function () { return components_1.ServiceWorkerRegistration; } });
|
|
19
|
+
// Export API Client
|
|
20
|
+
var api_client_1 = require("./api-client");
|
|
21
|
+
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
|
|
22
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return api_client_1.APIError; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,qBAAqB;AACrB,iCAA6E;AAApE,sGAAA,aAAa,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAAE,uGAAA,cAAc,OAAA;AAS3D,0BAA0B;AAC1B,2CAAyD;AAAhD,uHAAA,yBAAyB,OAAA;AAGlC,oBAAoB;AACpB,2CAAmD;AAA1C,uGAAA,SAAS,OAAA;AAAE,sGAAA,QAAQ,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nagiyu/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-next.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "dist/
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"types": "./dist/src/index.d.ts",
|
|
10
|
-
"import": "./dist/src/index.js"
|
|
10
|
+
"import": "./dist/src/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js"
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
|
-
"dist/src"
|
|
15
|
+
"dist/src",
|
|
16
|
+
"dist/cjs"
|
|
15
17
|
],
|
|
16
18
|
"repository": {
|
|
17
19
|
"type": "git",
|
|
@@ -19,7 +21,7 @@
|
|
|
19
21
|
"directory": "libs/react"
|
|
20
22
|
},
|
|
21
23
|
"scripts": {
|
|
22
|
-
"build": "tsc",
|
|
24
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node ../write-cjs-marker.mjs",
|
|
23
25
|
"test": "jest",
|
|
24
26
|
"test:watch": "jest --watch",
|
|
25
27
|
"test:coverage": "jest --coverage",
|
|
@@ -28,8 +30,8 @@
|
|
|
28
30
|
"format:check": "prettier --check ."
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"@nagiyu/browser": "^0.
|
|
32
|
-
"@nagiyu/common": "^0.
|
|
33
|
+
"@nagiyu/browser": "^0.2.0-next.0",
|
|
34
|
+
"@nagiyu/common": "^0.2.0-next.0"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|
|
35
37
|
"react": ">=19.0.0"
|