@ory/elements-react 1.0.0-next.44 → 1.0.0-next.46

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/index.mjs CHANGED
@@ -190,21 +190,29 @@ function nodesToAuthMethodGroups(nodes, excludeAuthMethods = []) {
190
190
  function useNodesGroups(nodes, { omit } = {}) {
191
191
  const groupSorter = useGroupSorter();
192
192
  const groups = useMemo(() => {
193
- var _a;
193
+ var _a, _b;
194
194
  const groups2 = {};
195
+ const groupRetained = {};
195
196
  for (const node of nodes) {
197
+ const groupNodes = (_a = groups2[node.group]) != null ? _a : [];
198
+ groupNodes.push(node);
199
+ groups2[node.group] = groupNodes;
196
200
  if ((omit == null ? void 0 : omit.includes("script")) && isUiNodeScriptAttributes(node.attributes)) {
197
201
  continue;
198
202
  }
199
203
  if ((omit == null ? void 0 : omit.includes("input_hidden")) && isUiNodeInputAttributes(node.attributes) && node.attributes.type === "hidden") {
200
204
  continue;
201
205
  }
202
- const groupNodes = (_a = groups2[node.group]) != null ? _a : [];
203
- groupNodes.push(node);
204
- groups2[node.group] = groupNodes;
206
+ groupRetained[node.group] = ((_b = groupRetained[node.group]) != null ? _b : 0) + 1;
205
207
  }
206
- return groups2;
207
- }, [nodes]);
208
+ const finalGroups = {};
209
+ for (const [group, count] of Object.entries(groupRetained)) {
210
+ if (count > 0) {
211
+ finalGroups[group] = groups2[group];
212
+ }
213
+ }
214
+ return finalGroups;
215
+ }, [nodes, omit]);
208
216
  const entries = useMemo(
209
217
  () => Object.entries(groups).sort(([a], [b]) => groupSorter(a, b)),
210
218
  [groups, groupSorter]
@@ -871,7 +879,11 @@ function useOryFormSubmit(onAfterSubmit) {
871
879
  };
872
880
  return onSubmit;
873
881
  }
874
- function OryForm({ children, onAfterSubmit }) {
882
+ function OryForm({
883
+ children,
884
+ onAfterSubmit,
885
+ "data-testid": dataTestId
886
+ }) {
875
887
  const { Form } = useComponents();
876
888
  const flowContainer = useOryFlow();
877
889
  const methods = useFormContext();
@@ -899,7 +911,7 @@ function OryForm({ children, onAfterSubmit }) {
899
911
  }),
900
912
  type: "error"
901
913
  };
902
- return /* @__PURE__ */ jsxs(Fragment, { children: [
914
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-8", "data-testid": dataTestId, children: [
903
915
  /* @__PURE__ */ jsx(Message.Root, { children: /* @__PURE__ */ jsx(Message.Content, { message: m }, m.id) }),
904
916
  /* @__PURE__ */ jsx(OryCardFooter, {})
905
917
  ] });
@@ -910,6 +922,7 @@ function OryForm({ children, onAfterSubmit }) {
910
922
  return /* @__PURE__ */ jsx(
911
923
  Form.Root,
912
924
  {
925
+ "data-testid": dataTestId,
913
926
  action: flowContainer.flow.ui.action,
914
927
  method: flowContainer.flow.ui.method,
915
928
  onSubmit: (e) => void methods.handleSubmit(onSubmit)(e),
@@ -1130,7 +1143,7 @@ function OryFormSocialButtonsForm() {
1130
1143
  if (filteredNodes.length === 0) {
1131
1144
  return null;
1132
1145
  }
1133
- return /* @__PURE__ */ jsx(OryFormProvider, { children: /* @__PURE__ */ jsx(OryForm, { children: /* @__PURE__ */ jsx(OryFormOidcButtons, {}) }) });
1146
+ return /* @__PURE__ */ jsx(OryFormProvider, { children: /* @__PURE__ */ jsx(OryForm, { "data-testid": `ory/form/methods/oidc-saml`, children: /* @__PURE__ */ jsx(OryFormOidcButtons, {}) }) });
1134
1147
  }
1135
1148
  function isUINodeGroupEnum(method) {
1136
1149
  return Object.values(UiNodeGroupEnum).includes(method);
@@ -1146,7 +1159,7 @@ function OryTwoStepCard() {
1146
1159
  // We only want to render groups that have visible elements.
1147
1160
  omit: ["script", "input_hidden"]
1148
1161
  });
1149
- const options = Object.fromEntries(
1162
+ const authMethodBlocks = Object.fromEntries(
1150
1163
  Object.values(UiNodeGroupEnum).filter((group) => {
1151
1164
  var _a2;
1152
1165
  return (_a2 = groupsToShow.groups[group]) == null ? void 0 : _a2.length;
@@ -1161,7 +1174,17 @@ function OryTwoStepCard() {
1161
1174
  ].includes(group)
1162
1175
  ).map((g) => [g, {}])
1163
1176
  );
1164
- if (UiNodeGroupEnum.Code in options) {
1177
+ const authMethodAdditionalNodes = ui.nodes.filter(
1178
+ ({ group }) => [
1179
+ UiNodeGroupEnum.Oidc,
1180
+ UiNodeGroupEnum.Saml,
1181
+ UiNodeGroupEnum.Default,
1182
+ UiNodeGroupEnum.IdentifierFirst,
1183
+ UiNodeGroupEnum.Profile,
1184
+ UiNodeGroupEnum.Captcha
1185
+ ].includes(group)
1186
+ );
1187
+ if (UiNodeGroupEnum.Code in authMethodBlocks) {
1165
1188
  let identifier = (_b = (_a = findNode(ui.nodes, {
1166
1189
  group: "identifier_first",
1167
1190
  node_type: "input",
@@ -1173,7 +1196,7 @@ function OryTwoStepCard() {
1173
1196
  name: "address"
1174
1197
  })) == null ? void 0 : _c.attributes) == null ? void 0 : _d.value);
1175
1198
  if (identifier) {
1176
- options[UiNodeGroupEnum.Code] = {
1199
+ authMethodBlocks[UiNodeGroupEnum.Code] = {
1177
1200
  title: {
1178
1201
  id: "identities.messages.1010023",
1179
1202
  values: { address: identifier }
@@ -1198,47 +1221,55 @@ function OryTwoStepCard() {
1198
1221
  (node) => node.group === UiNodeGroupEnum.Oidc || node.group === UiNodeGroupEnum.Saml
1199
1222
  );
1200
1223
  const showSso = !(formState.current === "method_active" && !(formState.method === UiNodeGroupEnum.Oidc || formState.method === UiNodeGroupEnum.Saml));
1201
- const showSsoDivider = hasSso && nonSsoNodes.filter((n) => {
1224
+ const showSsoDivider = hasSso && nonSsoNodes.some((n) => {
1202
1225
  if (isUiNodeInputAttributes(n.attributes)) {
1203
1226
  return n.attributes.type !== UiNodeInputAttributesTypeEnum.Hidden;
1204
1227
  } else if (isUiNodeScriptAttributes(n.attributes)) {
1205
1228
  return false;
1206
1229
  }
1207
1230
  return true;
1208
- }).length > 0;
1209
- const captchaNodes = ui.nodes.filter(
1210
- (n) => n.group === UiNodeGroupEnum.Captcha
1211
- );
1231
+ });
1212
1232
  return /* @__PURE__ */ jsxs(OryCard, { children: [
1213
1233
  /* @__PURE__ */ jsx(OryCardHeader, {}),
1214
1234
  /* @__PURE__ */ jsxs(OryCardContent, { children: [
1215
1235
  /* @__PURE__ */ jsx(OryCardValidationMessages, {}),
1216
1236
  showSso && /* @__PURE__ */ jsx(OryFormSocialButtonsForm, {}),
1217
- /* @__PURE__ */ jsxs(OryForm, { onAfterSubmit: handleAfterFormSubmit, children: [
1218
- formState.current === "provide_identifier" && /* @__PURE__ */ jsxs(Form.Group, { children: [
1219
- showSsoDivider && /* @__PURE__ */ jsx(Card.Divider, {}),
1220
- nonSsoNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1221
- ] }),
1222
- formState.current === "select_method" && /* @__PURE__ */ jsxs(Form.Group, { children: [
1223
- Object.entries(options).length > 0 && /* @__PURE__ */ jsx(Card.Divider, {}),
1224
- Object.entries(options).length > 0 && /* @__PURE__ */ jsx(
1225
- AuthMethodList,
1226
- {
1227
- options,
1228
- setSelectedGroup: (group) => dispatchFormState({
1229
- type: "action_select_method",
1230
- method: group
1231
- })
1232
- }
1233
- ),
1234
- captchaNodes.map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1235
- ] }),
1236
- formState.current === "method_active" && /* @__PURE__ */ jsxs(Form.Group, { children: [
1237
- ui.nodes.filter((n) => n.type === "script").map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
1238
- finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1239
- ] }),
1240
- /* @__PURE__ */ jsx(OryCardFooter, {})
1241
- ] })
1237
+ /* @__PURE__ */ jsxs(
1238
+ OryForm,
1239
+ {
1240
+ "data-testid": `ory/form/methods/local`,
1241
+ onAfterSubmit: handleAfterFormSubmit,
1242
+ children: [
1243
+ formState.current === "provide_identifier" && /* @__PURE__ */ jsxs(Form.Group, { children: [
1244
+ showSsoDivider && /* @__PURE__ */ jsx(Card.Divider, {}),
1245
+ nonSsoNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1246
+ ] }),
1247
+ formState.current === "select_method" && /* @__PURE__ */ jsxs(Form.Group, { children: [
1248
+ Object.entries(authMethodBlocks).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1249
+ /* @__PURE__ */ jsx(Card.Divider, {}),
1250
+ /* @__PURE__ */ jsx(
1251
+ AuthMethodList,
1252
+ {
1253
+ options: authMethodBlocks,
1254
+ setSelectedGroup: (group) => dispatchFormState({
1255
+ type: "action_select_method",
1256
+ method: group
1257
+ })
1258
+ }
1259
+ )
1260
+ ] }),
1261
+ authMethodAdditionalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1262
+ ] }),
1263
+ formState.current === "method_active" && /* @__PURE__ */ jsxs(Form.Group, { children: [
1264
+ ui.nodes.filter(
1265
+ (n) => isUiNodeScriptAttributes(n.attributes) || n.group === UiNodeGroupEnum.Captcha || n.group === UiNodeGroupEnum.Default || n.group === UiNodeGroupEnum.Profile
1266
+ ).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k)),
1267
+ finalNodes.sort(sortNodes).map((node, k) => /* @__PURE__ */ jsx(Node, { node }, k))
1268
+ ] }),
1269
+ /* @__PURE__ */ jsx(OryCardFooter, {})
1270
+ ]
1271
+ }
1272
+ )
1242
1273
  ] })
1243
1274
  ] });
1244
1275
  }