@ory/elements-react 1.0.0-next.19 → 1.0.0-next.20

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.
@@ -95,6 +95,37 @@ var import_client_fetch = require("@ory/client-fetch");
95
95
  var import_elements_react = require("@ory/elements-react");
96
96
  var import_react_hook_form = require("react-hook-form");
97
97
  var import_react_intl = require("react-intl");
98
+
99
+ // src/theme/default/utils/url.ts
100
+ function restartFlowUrl(flow, fallback) {
101
+ return flow.request_url || appendReturnTo(fallback, flow.return_to);
102
+ }
103
+ function initFlowUrl(sdkUrl, flowType, flow) {
104
+ const result = `${sdkUrl}/self-service/${flowType}/browser`;
105
+ const qs = new URLSearchParams();
106
+ if (flow.return_to) {
107
+ qs.set("return_to", flow.return_to);
108
+ } else if (typeof window !== "undefined") {
109
+ const searchParams = new URLSearchParams(window.location.search);
110
+ if (searchParams.has("return_to")) {
111
+ qs.set("return_to", searchParams.get("return_to") || "");
112
+ }
113
+ }
114
+ if (qs.toString().length === 0) {
115
+ return result;
116
+ }
117
+ return result + "?" + qs.toString();
118
+ }
119
+ function appendReturnTo(url, returnTo) {
120
+ if (!returnTo) {
121
+ return url;
122
+ }
123
+ const urlObj = new URL(url);
124
+ urlObj.searchParams.set("return_to", returnTo);
125
+ return urlObj.toString();
126
+ }
127
+
128
+ // src/theme/default/components/card/footer.tsx
98
129
  var import_jsx_runtime4 = require("react/jsx-runtime");
99
130
  function DefaultCardFooter() {
100
131
  const { flowType } = (0, import_elements_react.useOryFlow)();
@@ -111,23 +142,12 @@ function DefaultCardFooter() {
111
142
  return null;
112
143
  }
113
144
  }
114
- function getReturnToQueryParam() {
115
- if (typeof window !== "undefined") {
116
- const searchParams = new URLSearchParams(window.location.search);
117
- return searchParams.get("return_to");
118
- }
119
- }
120
145
  function LoginCardFooter() {
121
- const { config, formState } = (0, import_elements_react.useOryFlow)();
146
+ const { config, formState, flow } = (0, import_elements_react.useOryFlow)();
122
147
  const intl = (0, import_react_intl.useIntl)();
123
148
  if (!config.project.registration_enabled || formState.current !== "provide_identifier") {
124
149
  return null;
125
150
  }
126
- let registrationLink = `${config.sdk.url}/self-service/registration/browser`;
127
- const returnTo = getReturnToQueryParam();
128
- if (returnTo) {
129
- registrationLink += `?return_to=${returnTo}`;
130
- }
131
151
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "font-normal leading-normal antialiased text-interface-foreground-default-primary", children: [
132
152
  intl.formatMessage({
133
153
  id: "login.registration-label",
@@ -138,7 +158,8 @@ function LoginCardFooter() {
138
158
  "a",
139
159
  {
140
160
  className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
141
- href: registrationLink,
161
+ href: initFlowUrl(config.sdk.url, "registration", flow),
162
+ "data-testid": "ory/ui/login/link/registration",
142
163
  children: intl.formatMessage({
143
164
  id: "login.registration-button",
144
165
  defaultMessage: "Sign up"
@@ -166,11 +187,6 @@ function RegistrationCardFooter() {
166
187
  setValue("screen", "credential-selection");
167
188
  }
168
189
  }
169
- let loginLink = `${config.sdk.url}/self-service/login/browser`;
170
- const returnTo = getReturnToQueryParam();
171
- if (returnTo) {
172
- loginLink += `?return_to=${returnTo}`;
173
- }
174
190
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "font-normal leading-normal antialiased", children: formState.current === "method_active" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: screenSelectionNode && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
175
191
  "button",
176
192
  {
@@ -192,7 +208,8 @@ function RegistrationCardFooter() {
192
208
  "a",
193
209
  {
194
210
  className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
195
- href: loginLink,
211
+ href: initFlowUrl(config.sdk.url, "login", flow),
212
+ "data-testid": "ory/ui/login/link/login",
196
213
  children: intl.formatMessage({
197
214
  id: "registration.login-button",
198
215
  defaultMessage: "Sign in"
@@ -436,12 +453,8 @@ function omit(obj, keys) {
436
453
  // src/theme/default/components/card/current-identifier-button.tsx
437
454
  var import_jsx_runtime6 = require("react/jsx-runtime");
438
455
  function DefaultCurrentIdentifierButton() {
439
- const {
440
- flow: { ui },
441
- flowType,
442
- config,
443
- formState
444
- } = (0, import_elements_react2.useOryFlow)();
456
+ const { flow, flowType, config, formState } = (0, import_elements_react2.useOryFlow)();
457
+ const ui = flow.ui;
445
458
  if (formState.current === "provide_identifier") {
446
459
  return null;
447
460
  }
@@ -449,7 +462,10 @@ function DefaultCurrentIdentifierButton() {
449
462
  if ((nodeBackButton == null ? void 0 : nodeBackButton.attributes.node_type) !== "input" || !nodeBackButton.attributes.value) {
450
463
  return null;
451
464
  }
452
- const initFlowUrl = `${config.sdk.url}/self-service/${flowType}/browser`;
465
+ const initFlowUrl2 = restartFlowUrl(
466
+ flow,
467
+ `${config.sdk.url}/self-service/${flowType}/browser`
468
+ );
453
469
  const attributes = omit(nodeBackButton.attributes, [
454
470
  "autocomplete",
455
471
  "node_type"
@@ -459,8 +475,9 @@ function DefaultCurrentIdentifierButton() {
459
475
  {
460
476
  className: "group inline-flex max-w-full cursor-pointer items-center gap-1 self-start rounded-full border px-[11px] py-[5px] transition-colors border-button-identifier-border-border-default bg-button-identifier-background-default hover:border-button-identifier-border-border-hover hover:bg-button-identifier-background-hover",
461
477
  ...attributes,
462
- href: initFlowUrl,
478
+ href: initFlowUrl2,
463
479
  title: `Adjust ${nodeBackButton == null ? void 0 : nodeBackButton.attributes.value}`,
480
+ "data-testid": "ory/ui/login/link/restart",
464
481
  children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "inline-flex min-h-5 items-center gap-2 overflow-hidden text-ellipsis", children: [
465
482
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
466
483
  arrow_left_default,
@@ -828,6 +845,7 @@ function DefaultButtonSocial({
828
845
  value: attributes.value,
829
846
  type: "submit",
830
847
  name: "provider",
848
+ "data-testid": `ory/ui/node/input/${attributes.name}`,
831
849
  ...props,
832
850
  onClick,
833
851
  disabled: isSubmitting,
@@ -973,8 +991,7 @@ function DefaultAuthMethodListItem({
973
991
  className: "flex cursor-pointer gap-3 py-2 text-left items-start",
974
992
  onClick,
975
993
  type: isGroupImmediateSubmit(group) ? "submit" : "button",
976
- id: `auth-method-list-item-${group}`,
977
- "data-testid": "auth-method-list-item",
994
+ "data-testid": `ory/ui/groups/auth-method/${group}`,
978
995
  "aria-label": `Authenticate with ${group}`,
979
996
  children: [
980
997
  /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("span", { className: "mt-1", children: Icon && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
@@ -1063,9 +1080,6 @@ var DefaultButton = ({
1063
1080
  value,
1064
1081
  name,
1065
1082
  type: type === "button" ? "button" : "submit",
1066
- onSubmit: () => {
1067
- setValue(name, value);
1068
- },
1069
1083
  onClick: (e) => {
1070
1084
  onClick == null ? void 0 : onClick(e);
1071
1085
  if (type !== "button") {
@@ -1114,16 +1128,16 @@ var uiTextToFormattedMessage4 = ({ id, context = {}, text }, intl) => {
1114
1128
  new Date(value),
1115
1129
  /* @__PURE__ */ new Date()
1116
1130
  ),
1117
- [key + "_since_minutes"]: Math.abs(
1131
+ [key + "_since_minutes"]: Math.ceil(
1118
1132
  (value - (/* @__PURE__ */ new Date()).getTime() / 1e3) / 60
1119
- ).toFixed(2),
1133
+ ).toFixed(0),
1120
1134
  [key + "_until"]: intl.formatDateTimeRange(
1121
1135
  /* @__PURE__ */ new Date(),
1122
1136
  new Date(value)
1123
1137
  ),
1124
- [key + "_until_minutes"]: Math.abs(
1138
+ [key + "_until_minutes"]: Math.ceil(
1125
1139
  ((/* @__PURE__ */ new Date()).getTime() / 1e3 - value) / 60
1126
- ).toFixed(2)
1140
+ ).toFixed(0)
1127
1141
  };
1128
1142
  }
1129
1143
  }
@@ -1323,6 +1337,7 @@ var DefaultInput = ({
1323
1337
  maxLength: maxlength,
1324
1338
  autoComplete: autocomplete,
1325
1339
  placeholder: formattedLabel,
1340
+ "data-testid": `ory/ui/node/input/${name}`,
1326
1341
  className: cn(
1327
1342
  "antialiased rounded-forms border leading-tight transition-colors placeholder:h-[20px] placeholder:text-input-foreground-tertiary focus-visible:outline-none focus:ring-0",
1328
1343
  "bg-input-background-default border-input-border-default text-input-foreground-primary",
@@ -1376,6 +1391,7 @@ function DefaultLabel({
1376
1391
  ...(0, import_elements_react10.messageTestId)(label),
1377
1392
  className: "leading-normal text-input-foreground-primary",
1378
1393
  htmlFor: attributes.name,
1394
+ "data-testid": `ory/ui/node/input/label/${attributes.name}`,
1379
1395
  ...rest,
1380
1396
  children: (0, import_elements_react10.uiTextToFormattedMessage)(label, intl)
1381
1397
  }
@@ -1384,7 +1400,7 @@ function DefaultLabel({
1384
1400
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
1385
1401
  "a",
1386
1402
  {
1387
- href: config.project.recovery_ui_url,
1403
+ href: initFlowUrl(config.sdk.url, "recovery", flow),
1388
1404
  className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
1389
1405
  children: intl.formatMessage({
1390
1406
  id: "forms.label.forgot-password",
@@ -1425,6 +1441,7 @@ var DefaultLinkButton = (0, import_react.forwardRef)(({ attributes, node }, ref)
1425
1441
  ...attributes,
1426
1442
  ref,
1427
1443
  title: label ? (0, import_elements_react11.uiTextToFormattedMessage)(label, intl) : "",
1444
+ "data-testid": `ory/ui/node/link/${attributes.id}`,
1428
1445
  className: cn(
1429
1446
  "antialiased rounded cursor-pointer text-center border gap-3 leading-none bg-button-primary-background-default hover:bg-button-primary-background-hover transition-colors text-button-primary-foreground-default hover:text-button-primary-foreground-hover p-4 font-medium"
1430
1447
  ),
@@ -1569,8 +1586,15 @@ function DefaultText({ node, attributes }) {
1569
1586
  var _a;
1570
1587
  const intl = (0, import_react_intl12.useIntl)();
1571
1588
  return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(import_jsx_runtime44.Fragment, { children: [
1572
- /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { "data-testid": `node/text/${attributes.id}/label`, children: node.meta.label ? (0, import_elements_react13.uiTextToFormattedMessage)(node.meta.label, intl) : "" }),
1573
- (_a = attributes.text.context.secrets) == null ? void 0 : _a.map((text, index) => /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("pre", { "data-testid": `node/text/lookup_secret_codes/text`, children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("code", { children: text ? (0, import_elements_react13.uiTextToFormattedMessage)(text, intl) : "" }) }, index))
1589
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { "data-testid": `ory/ui/node/text/${attributes.id}/label`, children: node.meta.label ? (0, import_elements_react13.uiTextToFormattedMessage)(node.meta.label, intl) : "" }),
1590
+ (_a = attributes.text.context.secrets) == null ? void 0 : _a.map((text, index) => /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
1591
+ "pre",
1592
+ {
1593
+ "data-testid": `ory/ui/node/text/lookup_secret_codes/text`,
1594
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("code", { children: text ? (0, import_elements_react13.uiTextToFormattedMessage)(text, intl) : "" })
1595
+ },
1596
+ index
1597
+ ))
1574
1598
  ] });
1575
1599
  }
1576
1600
 
@@ -2340,7 +2364,7 @@ function Error2({
2340
2364
  error,
2341
2365
  children
2342
2366
  }) {
2343
- return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)("div", { children: JSON.stringify(error) || children });
2367
+ return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)("div", { "data-testid": "ory/ui/error/raw", children: JSON.stringify(error) || children });
2344
2368
  }
2345
2369
 
2346
2370
  // src/theme/default/flows/login.tsx