@insforge/react 0.4.5 → 0.4.7

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/forms.cjs CHANGED
@@ -171,6 +171,28 @@ function createRequirements(config) {
171
171
  }
172
172
  return requirements;
173
173
  }
174
+
175
+ // src/lib/path-utils.ts
176
+ function resolveAuthPath(targetPath) {
177
+ if (typeof window === "undefined") {
178
+ return targetPath;
179
+ }
180
+ const currentPath = window.location.pathname;
181
+ if (currentPath.startsWith("/auth/")) {
182
+ if (targetPath.startsWith("/auth/")) {
183
+ return targetPath;
184
+ }
185
+ return `/auth${targetPath}`;
186
+ }
187
+ return targetPath;
188
+ }
189
+ function resolveAuthUrl(targetPath, searchParams) {
190
+ const resolvedPath = resolveAuthPath(targetPath);
191
+ if (!searchParams || searchParams.toString() === "") {
192
+ return resolvedPath;
193
+ }
194
+ return `${resolvedPath}?${searchParams.toString()}`;
195
+ }
174
196
  function AuthPasswordField({
175
197
  label,
176
198
  id,
@@ -183,6 +205,10 @@ function AuthPasswordField({
183
205
  }) {
184
206
  const [showPassword, setShowPassword] = react.useState(false);
185
207
  const [showStrength, setShowStrength] = react.useState(false);
208
+ const resolvedForgotPasswordHref = react.useMemo(
209
+ () => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
210
+ [forgotPasswordLink]
211
+ );
186
212
  const handleFocus = (e) => {
187
213
  if (showStrengthIndicator) {
188
214
  setShowStrength(true);
@@ -192,7 +218,7 @@ function AuthPasswordField({
192
218
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
193
219
  (label || forgotPasswordLink) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-labelRow", children: [
194
220
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
195
- forgotPasswordLink && /* @__PURE__ */ jsxRuntime.jsx("a", { href: forgotPasswordLink.href, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
221
+ forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsxRuntime.jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
196
222
  ] }),
197
223
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-inputWrapper", children: [
198
224
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -245,19 +271,7 @@ function AuthSubmitButton({
245
271
  }
246
272
  function AuthLink({ text, linkText, href }) {
247
273
  const [searchParams] = reactRouterDom.useSearchParams();
248
- const currentSearch = searchParams.toString();
249
- const finalHref = (() => {
250
- if (!currentSearch) {
251
- return href;
252
- }
253
- try {
254
- const url = new URL(href, window.location.origin);
255
- url.search = currentSearch;
256
- return url.pathname + url.search;
257
- } catch {
258
- return href;
259
- }
260
- })();
274
+ const finalHref = resolveAuthUrl(href, searchParams);
261
275
  return /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
262
276
  text && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-authLink-text", children: text }),
263
277
  text && " ",