@auspex-ai/react 0.0.0-stage → 1.4.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.
- package/LICENSE +202 -0
- package/dist/index.cjs +86 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.mjs +66 -0
- package/dist/react-router.cjs +55 -0
- package/dist/react-router.d.cts +44 -0
- package/dist/react-router.d.mts +44 -0
- package/dist/react-router.mjs +52 -0
- package/dist/vite.cjs +1868 -0
- package/dist/vite.d.cts +16 -0
- package/dist/vite.d.mts +16 -0
- package/dist/vite.mjs +1843 -0
- package/package.json +83 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
let _auspex_ai_core = require("@auspex-ai/core");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
//#region src/index.tsx
|
|
6
|
+
/** userLoading が true のまま計装を待つ上限(ms)。過ぎたら userId なしで始める(計測が黙って止まらないように) */
|
|
7
|
+
const USER_WAIT_MS = 3e3;
|
|
8
|
+
function AuspexProvider({ publicKey, host, userId, userLoading, buildId, getRoute, subscribe, children }) {
|
|
9
|
+
const [ready, setReady] = (0, react.useState)(userLoading !== true);
|
|
10
|
+
(0, react.useEffect)(() => {
|
|
11
|
+
if (ready) return;
|
|
12
|
+
if (userLoading !== true) {
|
|
13
|
+
setReady(true);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const t = setTimeout(() => setReady(true), USER_WAIT_MS);
|
|
17
|
+
return () => clearTimeout(t);
|
|
18
|
+
}, [ready, userLoading]);
|
|
19
|
+
const latestUserId = (0, react.useRef)(userId);
|
|
20
|
+
const latest = (0, react.useRef)({
|
|
21
|
+
buildId,
|
|
22
|
+
getRoute,
|
|
23
|
+
subscribe
|
|
24
|
+
});
|
|
25
|
+
(0, react.useEffect)(() => {
|
|
26
|
+
latestUserId.current = userId;
|
|
27
|
+
latest.current = {
|
|
28
|
+
buildId,
|
|
29
|
+
getRoute,
|
|
30
|
+
subscribe
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
(0, react.useEffect)(() => {
|
|
34
|
+
if (!publicKey) {
|
|
35
|
+
(0, _auspex_ai_core.init)({ host });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!ready) return;
|
|
39
|
+
const adapter = {
|
|
40
|
+
getRoute: () => latest.current.getRoute?.() ?? null,
|
|
41
|
+
getBuildId: () => latest.current.buildId || null
|
|
42
|
+
};
|
|
43
|
+
if (latest.current.subscribe !== void 0) adapter.onRouteChange = (cb) => latest.current.subscribe?.(cb) ?? (() => {});
|
|
44
|
+
const h = (0, _auspex_ai_core.init)({
|
|
45
|
+
publicKey,
|
|
46
|
+
host,
|
|
47
|
+
adapter,
|
|
48
|
+
userId: latestUserId.current
|
|
49
|
+
});
|
|
50
|
+
return () => h?.shutdown();
|
|
51
|
+
}, [
|
|
52
|
+
publicKey,
|
|
53
|
+
host,
|
|
54
|
+
ready
|
|
55
|
+
]);
|
|
56
|
+
(0, react.useEffect)(() => {
|
|
57
|
+
if (!publicKey || !ready || userId === void 0) return;
|
|
58
|
+
(0, _auspex_ai_core.identify)(userId);
|
|
59
|
+
}, [
|
|
60
|
+
publicKey,
|
|
61
|
+
ready,
|
|
62
|
+
userId
|
|
63
|
+
]);
|
|
64
|
+
return children;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
exports.AuspexProvider = AuspexProvider;
|
|
68
|
+
exports.USER_WAIT_MS = USER_WAIT_MS;
|
|
69
|
+
Object.defineProperty(exports, "identify", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function() {
|
|
72
|
+
return _auspex_ai_core.identify;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "isUserId", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function() {
|
|
78
|
+
return _auspex_ai_core.isUserId;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "reset", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function() {
|
|
84
|
+
return _auspex_ai_core.reset;
|
|
85
|
+
}
|
|
86
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { identify, isUserId, reset } from "@auspex-ai/core";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
export interface AuspexProviderProps {
|
|
5
|
+
/** write-only キー。無ければ何もしない(イベントもリスナーも無し) */
|
|
6
|
+
publicKey?: string | undefined;
|
|
7
|
+
/** Ingestion のベース URL */
|
|
8
|
+
host: string;
|
|
9
|
+
/**
|
|
10
|
+
* ログインしている人のアプリ側の ID(Design Doc #45)。値なら identify、null(ログインしていない)なら、このブラウザが
|
|
11
|
+
* 前に identify されていたときだけ reset する。undefined は何もしない。読み込み中は userLoading で表す
|
|
12
|
+
*/
|
|
13
|
+
userId?: string | null | undefined;
|
|
14
|
+
/** ログインしている人をまだ読み込み中なら true。true の間は USER_WAIT_MS まで計装を始めない */
|
|
15
|
+
userLoading?: boolean | undefined;
|
|
16
|
+
/** `AuspexAdapter.getBuildId()` が返す値(例: `import.meta.env.VITE_AUSPEX_BUILD_ID`)。空なら null */
|
|
17
|
+
buildId?: string | undefined;
|
|
18
|
+
/** `AuspexAdapter.getRoute()`。無いか null を返すときは core の fallbackRoute(location.pathname) */
|
|
19
|
+
getRoute?: (() => string | null) | undefined;
|
|
20
|
+
/** `AuspexAdapter.onRouteChange()`。無ければ core が history をラップする */
|
|
21
|
+
subscribe?: ((cb: () => void) => () => void) | undefined;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/** userLoading が true のまま計装を待つ上限(ms)。過ぎたら userId なしで始める(計測が黙って止まらないように) */
|
|
25
|
+
export declare const USER_WAIT_MS = 3000;
|
|
26
|
+
export declare function AuspexProvider({ publicKey, host, userId, userLoading, buildId, getRoute, subscribe, children }: AuspexProviderProps): ReactNode;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { identify, isUserId, reset };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { identify, isUserId, reset } from "@auspex-ai/core";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
export interface AuspexProviderProps {
|
|
5
|
+
/** write-only キー。無ければ何もしない(イベントもリスナーも無し) */
|
|
6
|
+
publicKey?: string | undefined;
|
|
7
|
+
/** Ingestion のベース URL */
|
|
8
|
+
host: string;
|
|
9
|
+
/**
|
|
10
|
+
* ログインしている人のアプリ側の ID(Design Doc #45)。値なら identify、null(ログインしていない)なら、このブラウザが
|
|
11
|
+
* 前に identify されていたときだけ reset する。undefined は何もしない。読み込み中は userLoading で表す
|
|
12
|
+
*/
|
|
13
|
+
userId?: string | null | undefined;
|
|
14
|
+
/** ログインしている人をまだ読み込み中なら true。true の間は USER_WAIT_MS まで計装を始めない */
|
|
15
|
+
userLoading?: boolean | undefined;
|
|
16
|
+
/** `AuspexAdapter.getBuildId()` が返す値(例: `import.meta.env.VITE_AUSPEX_BUILD_ID`)。空なら null */
|
|
17
|
+
buildId?: string | undefined;
|
|
18
|
+
/** `AuspexAdapter.getRoute()`。無いか null を返すときは core の fallbackRoute(location.pathname) */
|
|
19
|
+
getRoute?: (() => string | null) | undefined;
|
|
20
|
+
/** `AuspexAdapter.onRouteChange()`。無ければ core が history をラップする */
|
|
21
|
+
subscribe?: ((cb: () => void) => () => void) | undefined;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/** userLoading が true のまま計装を待つ上限(ms)。過ぎたら userId なしで始める(計測が黙って止まらないように) */
|
|
25
|
+
export declare const USER_WAIT_MS = 3000;
|
|
26
|
+
export declare function AuspexProvider({ publicKey, host, userId, userLoading, buildId, getRoute, subscribe, children }: AuspexProviderProps): ReactNode;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { identify, isUserId, reset };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { identify, identify as identify$1, init, isUserId, reset } from "@auspex-ai/core";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
//#region src/index.tsx
|
|
5
|
+
/** userLoading が true のまま計装を待つ上限(ms)。過ぎたら userId なしで始める(計測が黙って止まらないように) */
|
|
6
|
+
const USER_WAIT_MS = 3e3;
|
|
7
|
+
function AuspexProvider({ publicKey, host, userId, userLoading, buildId, getRoute, subscribe, children }) {
|
|
8
|
+
const [ready, setReady] = useState(userLoading !== true);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (ready) return;
|
|
11
|
+
if (userLoading !== true) {
|
|
12
|
+
setReady(true);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const t = setTimeout(() => setReady(true), USER_WAIT_MS);
|
|
16
|
+
return () => clearTimeout(t);
|
|
17
|
+
}, [ready, userLoading]);
|
|
18
|
+
const latestUserId = useRef(userId);
|
|
19
|
+
const latest = useRef({
|
|
20
|
+
buildId,
|
|
21
|
+
getRoute,
|
|
22
|
+
subscribe
|
|
23
|
+
});
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
latestUserId.current = userId;
|
|
26
|
+
latest.current = {
|
|
27
|
+
buildId,
|
|
28
|
+
getRoute,
|
|
29
|
+
subscribe
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!publicKey) {
|
|
34
|
+
init({ host });
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!ready) return;
|
|
38
|
+
const adapter = {
|
|
39
|
+
getRoute: () => latest.current.getRoute?.() ?? null,
|
|
40
|
+
getBuildId: () => latest.current.buildId || null
|
|
41
|
+
};
|
|
42
|
+
if (latest.current.subscribe !== void 0) adapter.onRouteChange = (cb) => latest.current.subscribe?.(cb) ?? (() => {});
|
|
43
|
+
const h = init({
|
|
44
|
+
publicKey,
|
|
45
|
+
host,
|
|
46
|
+
adapter,
|
|
47
|
+
userId: latestUserId.current
|
|
48
|
+
});
|
|
49
|
+
return () => h?.shutdown();
|
|
50
|
+
}, [
|
|
51
|
+
publicKey,
|
|
52
|
+
host,
|
|
53
|
+
ready
|
|
54
|
+
]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!publicKey || !ready || userId === void 0) return;
|
|
57
|
+
identify$1(userId);
|
|
58
|
+
}, [
|
|
59
|
+
publicKey,
|
|
60
|
+
ready,
|
|
61
|
+
userId
|
|
62
|
+
]);
|
|
63
|
+
return children;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { AuspexProvider, USER_WAIT_MS, identify, isUserId, reset };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react_router = require("react-router");
|
|
3
|
+
//#region src/react-router/route.ts
|
|
4
|
+
function segmentTemplate(seg) {
|
|
5
|
+
if (seg === "*") return "[...splat]";
|
|
6
|
+
if (seg.startsWith(":")) return seg.endsWith("?") ? `[[${seg.slice(1, -1)}]]` : `[${seg.slice(1)}]`;
|
|
7
|
+
return seg.endsWith("?") ? seg.slice(0, -1) : seg;
|
|
8
|
+
}
|
|
9
|
+
/** 一致したルートの `path` を親から順に連結してテンプレートにする。一致が空なら null */
|
|
10
|
+
function routeTemplate(matches) {
|
|
11
|
+
if (matches.length === 0) return null;
|
|
12
|
+
let segs = [];
|
|
13
|
+
for (const m of matches) {
|
|
14
|
+
const path = m.route.path;
|
|
15
|
+
if (path === void 0 || path === "") continue;
|
|
16
|
+
if (path.startsWith("/")) segs = [];
|
|
17
|
+
for (const s of path.split("/")) if (s !== "") segs.push(segmentTemplate(s));
|
|
18
|
+
}
|
|
19
|
+
return `/${segs.join("/")}`;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/react-router.ts
|
|
23
|
+
/** 場所の同一性。初回の `default` の key は同じ値が続くので pathname で比べる */
|
|
24
|
+
function locationToken(loc) {
|
|
25
|
+
return loc.key === "default" ? `p:${loc.pathname}` : `k:${loc.key}`;
|
|
26
|
+
}
|
|
27
|
+
/** データルーター(`createBrowserRouter` など)用。Provider に展開して渡す */
|
|
28
|
+
function fromDataRouter(router) {
|
|
29
|
+
return {
|
|
30
|
+
getRoute: () => routeTemplate(router.state.matches),
|
|
31
|
+
subscribe(cb) {
|
|
32
|
+
let last = locationToken(router.state.location);
|
|
33
|
+
return router.subscribe(() => {
|
|
34
|
+
if (router.state.navigation.state !== "idle") return;
|
|
35
|
+
const token = locationToken(router.state.location);
|
|
36
|
+
if (token === last) return;
|
|
37
|
+
last = token;
|
|
38
|
+
cb();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 宣言的ルーター用(`createRoutesFromElements` で RouteObject[] にして渡す)。subscribe は返さず、core の history のラップに任せる
|
|
45
|
+
*/
|
|
46
|
+
function fromRoutes(routes) {
|
|
47
|
+
return { getRoute() {
|
|
48
|
+
const matches = (0, react_router.matchRoutes)(routes, window.location.pathname);
|
|
49
|
+
return matches ? routeTemplate(matches) : null;
|
|
50
|
+
} };
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.fromDataRouter = fromDataRouter;
|
|
54
|
+
exports.fromRoutes = fromRoutes;
|
|
55
|
+
exports.routeTemplate = routeTemplate;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RouteObject } from "react-router";
|
|
2
|
+
//#region src/react-router/route.d.ts
|
|
3
|
+
/** 一致した 1 つのルート(React Router の `RouteMatch` / `DataRouter` の `state.matches` の要素のうち使う部分) */
|
|
4
|
+
interface RouteMatchLike {
|
|
5
|
+
route: {
|
|
6
|
+
path?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/** 一致したルートの `path` を親から順に連結してテンプレートにする。一致が空なら null */
|
|
10
|
+
export declare function routeTemplate(matches: readonly RouteMatchLike[]): string | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/react-router.d.ts
|
|
13
|
+
export interface RouteBinding {
|
|
14
|
+
getRoute: () => string | null;
|
|
15
|
+
subscribe?: (cb: () => void) => () => void;
|
|
16
|
+
}
|
|
17
|
+
/** `createBrowserRouter` などが返す DataRouter のうち使う部分(構造で型付けして、react-router の型の版に依らない) */
|
|
18
|
+
export interface DataRouterLike {
|
|
19
|
+
state: {
|
|
20
|
+
matches: readonly {
|
|
21
|
+
route: {
|
|
22
|
+
path?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
}[];
|
|
25
|
+
location: {
|
|
26
|
+
key: string;
|
|
27
|
+
pathname: string;
|
|
28
|
+
};
|
|
29
|
+
navigation: {
|
|
30
|
+
state: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
subscribe(fn: () => void): () => void;
|
|
34
|
+
}
|
|
35
|
+
/** データルーター(`createBrowserRouter` など)用。Provider に展開して渡す */
|
|
36
|
+
export declare function fromDataRouter(router: DataRouterLike): Required<RouteBinding>;
|
|
37
|
+
/**
|
|
38
|
+
* 宣言的ルーター用(`createRoutesFromElements` で RouteObject[] にして渡す)。subscribe は返さず、core の history のラップに任せる
|
|
39
|
+
*/
|
|
40
|
+
export declare function fromRoutes(routes: RouteObject[]): {
|
|
41
|
+
getRoute: () => string | null;
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export type { RouteMatchLike };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RouteObject } from "react-router";
|
|
2
|
+
//#region src/react-router/route.d.ts
|
|
3
|
+
/** 一致した 1 つのルート(React Router の `RouteMatch` / `DataRouter` の `state.matches` の要素のうち使う部分) */
|
|
4
|
+
interface RouteMatchLike {
|
|
5
|
+
route: {
|
|
6
|
+
path?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/** 一致したルートの `path` を親から順に連結してテンプレートにする。一致が空なら null */
|
|
10
|
+
export declare function routeTemplate(matches: readonly RouteMatchLike[]): string | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/react-router.d.ts
|
|
13
|
+
export interface RouteBinding {
|
|
14
|
+
getRoute: () => string | null;
|
|
15
|
+
subscribe?: (cb: () => void) => () => void;
|
|
16
|
+
}
|
|
17
|
+
/** `createBrowserRouter` などが返す DataRouter のうち使う部分(構造で型付けして、react-router の型の版に依らない) */
|
|
18
|
+
export interface DataRouterLike {
|
|
19
|
+
state: {
|
|
20
|
+
matches: readonly {
|
|
21
|
+
route: {
|
|
22
|
+
path?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
}[];
|
|
25
|
+
location: {
|
|
26
|
+
key: string;
|
|
27
|
+
pathname: string;
|
|
28
|
+
};
|
|
29
|
+
navigation: {
|
|
30
|
+
state: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
subscribe(fn: () => void): () => void;
|
|
34
|
+
}
|
|
35
|
+
/** データルーター(`createBrowserRouter` など)用。Provider に展開して渡す */
|
|
36
|
+
export declare function fromDataRouter(router: DataRouterLike): Required<RouteBinding>;
|
|
37
|
+
/**
|
|
38
|
+
* 宣言的ルーター用(`createRoutesFromElements` で RouteObject[] にして渡す)。subscribe は返さず、core の history のラップに任せる
|
|
39
|
+
*/
|
|
40
|
+
export declare function fromRoutes(routes: RouteObject[]): {
|
|
41
|
+
getRoute: () => string | null;
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export type { RouteMatchLike };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { matchRoutes } from "react-router";
|
|
2
|
+
//#region src/react-router/route.ts
|
|
3
|
+
function segmentTemplate(seg) {
|
|
4
|
+
if (seg === "*") return "[...splat]";
|
|
5
|
+
if (seg.startsWith(":")) return seg.endsWith("?") ? `[[${seg.slice(1, -1)}]]` : `[${seg.slice(1)}]`;
|
|
6
|
+
return seg.endsWith("?") ? seg.slice(0, -1) : seg;
|
|
7
|
+
}
|
|
8
|
+
/** 一致したルートの `path` を親から順に連結してテンプレートにする。一致が空なら null */
|
|
9
|
+
function routeTemplate(matches) {
|
|
10
|
+
if (matches.length === 0) return null;
|
|
11
|
+
let segs = [];
|
|
12
|
+
for (const m of matches) {
|
|
13
|
+
const path = m.route.path;
|
|
14
|
+
if (path === void 0 || path === "") continue;
|
|
15
|
+
if (path.startsWith("/")) segs = [];
|
|
16
|
+
for (const s of path.split("/")) if (s !== "") segs.push(segmentTemplate(s));
|
|
17
|
+
}
|
|
18
|
+
return `/${segs.join("/")}`;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/react-router.ts
|
|
22
|
+
/** 場所の同一性。初回の `default` の key は同じ値が続くので pathname で比べる */
|
|
23
|
+
function locationToken(loc) {
|
|
24
|
+
return loc.key === "default" ? `p:${loc.pathname}` : `k:${loc.key}`;
|
|
25
|
+
}
|
|
26
|
+
/** データルーター(`createBrowserRouter` など)用。Provider に展開して渡す */
|
|
27
|
+
function fromDataRouter(router) {
|
|
28
|
+
return {
|
|
29
|
+
getRoute: () => routeTemplate(router.state.matches),
|
|
30
|
+
subscribe(cb) {
|
|
31
|
+
let last = locationToken(router.state.location);
|
|
32
|
+
return router.subscribe(() => {
|
|
33
|
+
if (router.state.navigation.state !== "idle") return;
|
|
34
|
+
const token = locationToken(router.state.location);
|
|
35
|
+
if (token === last) return;
|
|
36
|
+
last = token;
|
|
37
|
+
cb();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 宣言的ルーター用(`createRoutesFromElements` で RouteObject[] にして渡す)。subscribe は返さず、core の history のラップに任せる
|
|
44
|
+
*/
|
|
45
|
+
function fromRoutes(routes) {
|
|
46
|
+
return { getRoute() {
|
|
47
|
+
const matches = matchRoutes(routes, window.location.pathname);
|
|
48
|
+
return matches ? routeTemplate(matches) : null;
|
|
49
|
+
} };
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { fromDataRouter, fromRoutes, routeTemplate };
|