@ory/elements-react 0.0.0-pr.96c07cce → 0.0.0-pr.c7aa6707

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.
@@ -2904,25 +2904,6 @@ function LoginCardFooter() {
2904
2904
  );
2905
2905
  }
2906
2906
  if (flow.refresh || flow.requested_aal === "aal2") {
2907
- if (authMethods.length > 1 && formState.current === "method_active") {
2908
- return /* @__PURE__ */ jsxs15("span", { className: "font-normal leading-normal antialiased text-interface-foreground-default-primary", children: [
2909
- intl.formatMessage({
2910
- id: "login.2fa.go-back"
2911
- }),
2912
- " ",
2913
- /* @__PURE__ */ jsx34(
2914
- "a",
2915
- {
2916
- className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
2917
- href: "",
2918
- "data-testid": "ory/screen/login/mfa/action/selectMethod",
2919
- children: intl.formatMessage({
2920
- id: "login.2fa.go-back.link"
2921
- })
2922
- }
2923
- )
2924
- ] });
2925
- }
2926
2907
  return /* @__PURE__ */ jsxs15("span", { className: "font-normal leading-normal antialiased text-interface-foreground-default-primary", children: [
2927
2908
  intl.formatMessage({
2928
2909
  id: "login.2fa.go-back"
@@ -3344,6 +3325,9 @@ var SvgArrowLeft = (props) => {
3344
3325
  };
3345
3326
  var arrow_left_default = SvgArrowLeft;
3346
3327
 
3328
+ // src/theme/default/components/card/current-identifier-button.tsx
3329
+ import { useFormContext as useFormContext12 } from "react-hook-form";
3330
+
3347
3331
  // src/theme/default/utils/attributes.ts
3348
3332
  function omit(obj, keys) {
3349
3333
  const ret = { ...obj };
@@ -3353,13 +3337,37 @@ function omit(obj, keys) {
3353
3337
  return ret;
3354
3338
  }
3355
3339
 
3340
+ // src/util/omitAttributes.ts
3341
+ function omitInputAttributes({
3342
+ ...attrs
3343
+ }) {
3344
+ return omit(attrs, [
3345
+ "autocomplete",
3346
+ "label",
3347
+ "node_type",
3348
+ "maxlength",
3349
+ "onclick",
3350
+ "onclickTrigger",
3351
+ "onload",
3352
+ "onloadTrigger"
3353
+ ]);
3354
+ }
3355
+
3356
3356
  // src/theme/default/components/card/current-identifier-button.tsx
3357
- import { useFormContext as useFormContext12 } from "react-hook-form";
3357
+ import { useEffect as useEffect3, useState as useState4 } from "react";
3358
3358
  import { jsx as jsx36, jsxs as jsxs16 } from "react/jsx-runtime";
3359
3359
  function DefaultCurrentIdentifierButton() {
3360
+ var _a;
3360
3361
  const { flow, flowType, config, formState } = useOryFlow4();
3361
- const { setValue } = useFormContext12();
3362
+ const { setValue, getValues, watch } = useFormContext12();
3363
+ const [turnstileResponse, setTurnstileResponse] = useState4();
3362
3364
  const ui = flow.ui;
3365
+ const captchaVerificationValue = (_a = watch("transient_payload")) == null ? void 0 : _a.captcha_turnstile_response;
3366
+ useEffect3(() => {
3367
+ if (captchaVerificationValue) {
3368
+ setTurnstileResponse(captchaVerificationValue);
3369
+ }
3370
+ }, [captchaVerificationValue]);
3363
3371
  if (formState.current === "provide_identifier") {
3364
3372
  return null;
3365
3373
  }
@@ -3374,11 +3382,6 @@ function DefaultCurrentIdentifierButton() {
3374
3382
  flow,
3375
3383
  `${config.sdk.url}/self-service/${flowType}/browser`
3376
3384
  );
3377
- const attributes = omit(nodeBackButton, [
3378
- "autocomplete",
3379
- "node_type",
3380
- "maxlength"
3381
- ]);
3382
3385
  const screenSelectionNode = findScreenSelectionButton(flow.ui.nodes);
3383
3386
  if (screenSelectionNode) {
3384
3387
  return /* @__PURE__ */ jsxs16("form", { action: flow.ui.action, method: flow.ui.method, children: [
@@ -3389,12 +3392,16 @@ function DefaultCurrentIdentifierButton() {
3389
3392
  return false;
3390
3393
  }).map((n) => {
3391
3394
  const attrs = n.attributes;
3395
+ let value = getValues(attrs.name) || attrs.value;
3396
+ if (attrs.name === "transient_payload.captcha_turnstile_response" && turnstileResponse) {
3397
+ value = turnstileResponse;
3398
+ }
3392
3399
  return /* @__PURE__ */ jsx36(
3393
3400
  "input",
3394
3401
  {
3395
3402
  type: "hidden",
3396
3403
  name: attrs.name,
3397
- value: attrs.value
3404
+ value
3398
3405
  },
3399
3406
  attrs.name
3400
3407
  );
@@ -3403,7 +3410,7 @@ function DefaultCurrentIdentifierButton() {
3403
3410
  "button",
3404
3411
  {
3405
3412
  className: "group inline-flex max-w-full cursor-pointer items-center gap-1 self-start rounded-identifier 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",
3406
- ...attributes,
3413
+ ...omitInputAttributes(nodeBackButton),
3407
3414
  type: "submit",
3408
3415
  onClick: () => {
3409
3416
  setValue(
@@ -3435,7 +3442,7 @@ function DefaultCurrentIdentifierButton() {
3435
3442
  "a",
3436
3443
  {
3437
3444
  className: "group inline-flex max-w-full cursor-pointer items-center gap-1 self-start rounded-identifier 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",
3438
- ...attributes,
3445
+ ...omitInputAttributes(nodeBackButton),
3439
3446
  href: initFlowUrl2,
3440
3447
  title: `Adjust ${nodeBackButton == null ? void 0 : nodeBackButton.value}`,
3441
3448
  "data-testid": `ory/screen/${flowType}/action/restart`,
@@ -3581,7 +3588,7 @@ import {
3581
3588
  uiTextToFormattedMessage as uiTextToFormattedMessage2,
3582
3589
  useOryFlow as useOryFlow7
3583
3590
  } from "@ory/elements-react";
3584
- import { useEffect as useEffect3 } from "react";
3591
+ import { useEffect as useEffect4 } from "react";
3585
3592
  import { useFormContext as useFormContext13 } from "react-hook-form";
3586
3593
  import { useIntl as useIntl11 } from "react-intl";
3587
3594
  import { useDebounceValue } from "usehooks-ts";
@@ -3801,24 +3808,6 @@ function Spinner({ className }) {
3801
3808
 
3802
3809
  // src/theme/default/components/form/social.tsx
3803
3810
  import { UiNodeGroupEnum as UiNodeGroupEnum16 } from "@ory/client-fetch";
3804
-
3805
- // src/util/omitAttributes.ts
3806
- function omitInputAttributes({
3807
- ...attrs
3808
- }) {
3809
- return omit(attrs, [
3810
- "autocomplete",
3811
- "label",
3812
- "node_type",
3813
- "maxlength",
3814
- "onclick",
3815
- "onclickTrigger",
3816
- "onload",
3817
- "onloadTrigger"
3818
- ]);
3819
- }
3820
-
3821
- // src/theme/default/components/form/social.tsx
3822
3811
  import { Fragment as Fragment9, jsx as jsx55, jsxs as jsxs29 } from "react/jsx-runtime";
3823
3812
  function extractProvider(context) {
3824
3813
  if (context && typeof context === "object" && "provider" in context && typeof context.provider === "string") {
@@ -3854,7 +3843,7 @@ function DefaultButtonSocial({
3854
3843
  onClick == null ? void 0 : onClick();
3855
3844
  setClicked(true);
3856
3845
  };
3857
- useEffect3(() => {
3846
+ useEffect4(() => {
3858
3847
  if (!isSubmitting) {
3859
3848
  setClicked(false);
3860
3849
  }
@@ -4095,7 +4084,7 @@ import {
4095
4084
  import { cva } from "class-variance-authority";
4096
4085
  import { useFormContext as useFormContext14 } from "react-hook-form";
4097
4086
  import { useIntl as useIntl14 } from "react-intl";
4098
- import { useEffect as useEffect4, useState as useState4 } from "react";
4087
+ import { useEffect as useEffect5, useState as useState5 } from "react";
4099
4088
  import { jsx as jsx65, jsxs as jsxs31 } from "react/jsx-runtime";
4100
4089
  var buttonStyles = cva(
4101
4090
  [
@@ -4136,14 +4125,14 @@ var DefaultButton = ({
4136
4125
  }) => {
4137
4126
  var _a;
4138
4127
  const { type, name, value, ...rest } = attributes;
4139
- const [clicked, setClicked] = useState4(false);
4128
+ const [clicked, setClicked] = useState5(false);
4140
4129
  const intl = useIntl14();
4141
4130
  const label = getNodeLabel(node);
4142
4131
  const {
4143
4132
  formState: { isSubmitting },
4144
4133
  setValue
4145
4134
  } = useFormContext14();
4146
- useEffect4(() => {
4135
+ useEffect5(() => {
4147
4136
  if (!isSubmitting) {
4148
4137
  setClicked(false);
4149
4138
  }
@@ -4359,7 +4348,7 @@ import {
4359
4348
  uiTextToFormattedMessage as uiTextToFormattedMessage6,
4360
4349
  useOryFlow as useOryFlow10
4361
4350
  } from "@ory/elements-react";
4362
- import { useRef as useRef2, useState as useState5 } from "react";
4351
+ import { useRef as useRef2, useState as useState6 } from "react";
4363
4352
  import { useFormContext as useFormContext16 } from "react-hook-form";
4364
4353
  import { useIntl as useIntl17 } from "react-intl";
4365
4354
 
@@ -4418,7 +4407,7 @@ var DefaultInput = ({
4418
4407
  return /* @__PURE__ */ jsx73(
4419
4408
  "input",
4420
4409
  {
4421
- ...rest,
4410
+ ...omitInputAttributes(rest),
4422
4411
  onClick,
4423
4412
  maxLength: maxlength,
4424
4413
  autoComplete: autocomplete,
@@ -4463,7 +4452,7 @@ var DefaultInput = ({
4463
4452
  function PasswordToggle({
4464
4453
  inputRef
4465
4454
  }) {
4466
- const [shown, setShown] = useState5(false);
4455
+ const [shown, setShown] = useState6(false);
4467
4456
  const handleClick = () => {
4468
4457
  setShown(!shown);
4469
4458
  if (inputRef.current) {
@@ -4981,7 +4970,7 @@ var DefaultPageHeader = (_props) => {
4981
4970
  };
4982
4971
 
4983
4972
  // src/theme/default/components/settings/settings-oidc.tsx
4984
- import { useEffect as useEffect5 } from "react";
4973
+ import { useEffect as useEffect6 } from "react";
4985
4974
  import { useFormContext as useFormContext19 } from "react-hook-form";
4986
4975
  import { useDebounceValue as useDebounceValue2 } from "usehooks-ts";
4987
4976
 
@@ -5038,7 +5027,7 @@ function UnlinkRow({ button }) {
5038
5027
  button.onClick();
5039
5028
  setClicked(true);
5040
5029
  };
5041
- useEffect5(() => {
5030
+ useEffect6(() => {
5042
5031
  if (!isSubmitting) {
5043
5032
  setClicked(false);
5044
5033
  }
@@ -5487,48 +5476,53 @@ function DefaultAuthMethodListContainer({
5487
5476
  // src/theme/default/components/form/captcha.tsx
5488
5477
  import { isUiNodeInputAttributes as isUiNodeInputAttributes9 } from "@ory/client-fetch";
5489
5478
  import { Turnstile } from "@marsidev/react-turnstile";
5490
- import { useRef as useRef3 } from "react";
5479
+ import { useEffect as useEffect7, useRef as useRef3 } from "react";
5491
5480
  import { useFormContext as useFormContext24 } from "react-hook-form";
5492
5481
  import { jsx as jsx98 } from "react/jsx-runtime";
5493
5482
  var DefaultCaptcha = ({ node }) => {
5494
- const { setValue } = useFormContext24();
5483
+ const { setValue, formState } = useFormContext24();
5495
5484
  const ref = useRef3();
5496
- const nodes = [];
5497
- if (isUiNodeInputAttributes9(node.attributes)) {
5498
- if (node.attributes.name === "transient_payload.captcha_turnstile_response") {
5499
- nodes.push(
5500
- /* @__PURE__ */ jsx98(DefaultInput, { node, attributes: node.attributes }, 1)
5501
- );
5485
+ const prevSubmitCount = useRef3(formState.submitCount);
5486
+ useEffect7(() => {
5487
+ if (formState.submitCount > prevSubmitCount.current && formState.isSubmitSuccessful) {
5488
+ prevSubmitCount.current = formState.submitCount;
5489
+ setTimeout(() => {
5490
+ if (ref.current) {
5491
+ ref.current.reset();
5492
+ }
5493
+ }, 100);
5502
5494
  }
5495
+ }, [formState.submitCount, formState.isSubmitSuccessful]);
5496
+ if (!isUiNodeInputAttributes9(node.attributes)) {
5497
+ return null;
5503
5498
  }
5504
- if (isUiNodeInputAttributes9(node.attributes) && node.attributes.name === "captcha_turnstile_options") {
5499
+ if (node.attributes.name === "transient_payload.captcha_turnstile_response") {
5500
+ return /* @__PURE__ */ jsx98(DefaultInput, { node, attributes: node.attributes }, 1);
5501
+ } else if (node.attributes.name === "captcha_turnstile_options") {
5505
5502
  const options = JSON.parse(node.attributes.value);
5506
- nodes.push(
5507
- /* @__PURE__ */ jsx98(
5508
- Turnstile,
5509
- {
5510
- ref,
5511
- siteKey: options.sitekey,
5512
- options: {
5513
- action: options.action,
5514
- size: "flexible",
5515
- theme: options.theme,
5516
- responseField: false,
5517
- responseFieldName: options.response_field_name
5518
- },
5519
- onExpire: () => {
5520
- var _a;
5521
- return (_a = ref.current) == null ? void 0 : _a.reset();
5522
- },
5523
- onSuccess: (token) => {
5524
- setValue(options.response_field_name, token);
5525
- }
5503
+ return /* @__PURE__ */ jsx98(
5504
+ Turnstile,
5505
+ {
5506
+ ref,
5507
+ siteKey: options.sitekey,
5508
+ options: {
5509
+ action: options.action,
5510
+ size: "flexible",
5511
+ theme: options.theme,
5512
+ responseField: false,
5513
+ responseFieldName: options.response_field_name
5526
5514
  },
5527
- 2
5528
- )
5515
+ onExpire: () => {
5516
+ var _a;
5517
+ return (_a = ref.current) == null ? void 0 : _a.reset();
5518
+ },
5519
+ onSuccess: (token) => {
5520
+ setValue(options.response_field_name, token);
5521
+ }
5522
+ }
5529
5523
  );
5530
5524
  }
5531
- return nodes;
5525
+ return null;
5532
5526
  };
5533
5527
 
5534
5528
  // src/theme/default/assets/icons/personal.svg