@krak-stack/registry 0.1.47 → 0.1.49

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @krak-stack/registry
2
2
 
3
+ ## 0.1.49
4
+
5
+ ### Patch Changes
6
+
7
+ - e026d8d: Fix silent form submission failures in `SubmitError`, including typed HTTP errors such as `Forbidden` whose messages are empty.
8
+ - Display a non-empty server or domain error message first, when available.
9
+ - Otherwise, display an English or French message for recognized HTTP errors, then a generic failure message if no useful message or recognized status is available.
10
+ - Use localized HTTP status messages instead of raw HTTP-client diagnostics for recognized statuses.
11
+ - Support the provider locale and explicit `locale` and `messages` overrides.
12
+ - Continue displaying schema validation errors beside their fields rather than in the submission error display.
13
+
14
+ ## 0.1.48
15
+
16
+ ### Patch Changes
17
+
18
+ - Fix Effect Form image previews for newly selected and replacement files. Use full-width image attachment rows with consistently sized, bordered previews, truncated filenames, compact file type and size metadata, and replace/delete actions aligned to the right. Replace the refresh icon with upload icons for changing images and files.
19
+
3
20
  ## 0.1.47
4
21
 
5
22
  ### Patch Changes
@@ -18,6 +18,14 @@ export type EffectFormMessages = {
18
18
  nameRequired: string;
19
19
  revert: string;
20
20
  submit: string;
21
+ submitBadRequest: string;
22
+ submitUnauthorized: string;
23
+ submitForbidden: string;
24
+ submitNotFound: string;
25
+ submitConflict: string;
26
+ submitRateLimited: string;
27
+ submitUnavailable: string;
28
+ submitFailed: string;
21
29
  suggestedImageSize: (width: string, height: string) => string;
22
30
  value: string;
23
31
  };
@@ -44,8 +52,10 @@ export declare const FieldWrapper: ({ children, description, editingLocale, lege
44
52
  export declare const ErrorMessage: ({ text }: {
45
53
  text: string;
46
54
  }) => JSX.Element;
47
- export declare const SubmitError: <A, E>({ result, }: {
55
+ export declare const SubmitError: <A, E>({ result, locale, messages, }: {
48
56
  result: AsyncResult.AsyncResult<A, E>;
57
+ locale?: string;
58
+ messages?: EffectFormMessageTranslations;
49
59
  }) => JSX.Element | null;
50
60
  export type SubmitForm<A, E> = {
51
61
  isDirty: Atom.Atom<boolean>;
@@ -2,6 +2,7 @@
2
2
  import { useAtomSet, useAtomValue } from "@effect/atom-react";
3
3
  import { Block } from "@tanstack/react-router";
4
4
  import { Cause, Option, Schema as Schema2 } from "effect";
5
+ import { HttpClientError } from "effect/http";
5
6
  import { AsyncResult } from "effect/reactivity";
6
7
  import { Languages, Loader2, Plus, Trash } from "lucide-react";
7
8
 
@@ -170,7 +171,7 @@ import {
170
171
  useRef,
171
172
  useState
172
173
  } from "react";
173
- import { CloudUpload, FileIcon, FileUp, RefreshCw, Trash2 } from "lucide-react";
174
+ import { CloudUpload, FileIcon, FileUp, ImageUp, Trash2 } from "lucide-react";
174
175
  import { Schema } from "effect";
175
176
 
176
177
  // ../../src/components/ui/attachment.tsx
@@ -350,7 +351,7 @@ var formatBytes = (bytes, locale) => {
350
351
  }).format(value);
351
352
  };
352
353
  var fileDescription = (file, locale) => [
353
- file.type || file.name.split(".").pop()?.toUpperCase(),
354
+ (file.name.includes(".") ? file.name.split(".").pop()?.toUpperCase() : "") || file.type.split("/").pop()?.toUpperCase(),
354
355
  formatBytes(file.size, locale)
355
356
  ].filter(Boolean).join(" · ");
356
357
  var FilePicker = ({
@@ -564,40 +565,44 @@ var FilePicker = ({
564
565
  return /* @__PURE__ */ jsxs2(Fragment, {
565
566
  children: [
566
567
  /* @__PURE__ */ jsxs2(Attachment, {
567
- className: image ? "w-fit max-w-full" : "w-full",
568
- orientation: image ? "vertical" : "horizontal",
568
+ className: "w-full",
569
+ orientation: "horizontal",
569
570
  state: invalid ? "error" : "done",
570
571
  children: [
571
572
  /* @__PURE__ */ jsx5(AttachmentMedia, {
572
573
  variant: image ? "image" : "icon",
573
- className: image ? "aspect-auto w-full max-w-full [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
574
+ className: image ? "aspect-auto max-w-full border [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
575
+ style: image ? {
576
+ width: image.width,
577
+ aspectRatio: `${image.width} / ${image.height}`
578
+ } : undefined,
574
579
  children: image && imageUrl ? /* @__PURE__ */ jsx5("img", {
575
580
  src: imageUrl,
576
581
  alt: image.alt,
577
582
  width: image.width,
578
583
  height: image.height,
579
- className: "h-auto max-w-full object-contain",
580
- style: { maxHeight: image.height }
584
+ className: "size-full object-contain"
581
585
  }) : /* @__PURE__ */ jsx5(FileIcon, {})
582
586
  }),
583
587
  /* @__PURE__ */ jsxs2(AttachmentContent, {
584
- className: image ? "w-full" : undefined,
585
588
  children: [
586
589
  /* @__PURE__ */ jsx5(AttachmentTitle, {
587
- children: title
590
+ children: file?.name ?? title
588
591
  }),
589
592
  file ? /* @__PURE__ */ jsx5(AttachmentDescription, {
593
+ className: "break-words",
590
594
  children: fileDescription(file, locale)
591
595
  }) : null
592
596
  ]
593
597
  }),
594
598
  /* @__PURE__ */ jsxs2(AttachmentActions, {
599
+ className: "ml-auto gap-1",
595
600
  children: [
596
601
  /* @__PURE__ */ jsx5(AttachmentAction, {
597
602
  type: "button",
598
603
  "aria-label": labels.replaceFile,
599
604
  onClick: () => inputRef.current?.click(),
600
- children: /* @__PURE__ */ jsx5(RefreshCw, {})
605
+ children: image ? /* @__PURE__ */ jsx5(ImageUp, {}) : /* @__PURE__ */ jsx5(FileUp, {})
601
606
  }),
602
607
  canClear ? /* @__PURE__ */ jsx5(AttachmentAction, {
603
608
  type: "button",
@@ -1284,6 +1289,14 @@ var messages3 = {
1284
1289
  nameRequired: "Name is required",
1285
1290
  revert: "Revert to default",
1286
1291
  submit: "Submit",
1292
+ submitBadRequest: "The submitted information is invalid.",
1293
+ submitUnauthorized: "Please sign in to submit this form.",
1294
+ submitForbidden: "You do not have permission to submit this form.",
1295
+ submitNotFound: "The requested resource could not be found.",
1296
+ submitConflict: "Your changes conflict with the current state. Please refresh and try again.",
1297
+ submitRateLimited: "Too many requests. Please try again later.",
1298
+ submitUnavailable: "The service is temporarily unavailable. Please try again later.",
1299
+ submitFailed: "Your changes could not be saved. Please try again.",
1287
1300
  suggestedImageSize: (width, height) => `Suggested image size: ${width} x ${height}`,
1288
1301
  value: "Value"
1289
1302
  },
@@ -1301,6 +1314,14 @@ var messages3 = {
1301
1314
  nameRequired: "Le nom est obligatoire",
1302
1315
  revert: "Revenir aux paramètres par défaut",
1303
1316
  submit: "Soumettre",
1317
+ submitBadRequest: "Les informations soumises sont invalides.",
1318
+ submitUnauthorized: "Veuillez vous connecter pour soumettre ce formulaire.",
1319
+ submitForbidden: "Vous n’avez pas la permission de soumettre ce formulaire.",
1320
+ submitNotFound: "La ressource demandée est introuvable.",
1321
+ submitConflict: "Vos modifications sont en conflit avec l’état actuel. Veuillez actualiser la page et réessayer.",
1322
+ submitRateLimited: "Trop de requêtes. Veuillez réessayer plus tard.",
1323
+ submitUnavailable: "Le service est temporairement indisponible. Veuillez réessayer plus tard.",
1324
+ submitFailed: "Vos modifications n’ont pas pu être enregistrées. Veuillez réessayer.",
1304
1325
  suggestedImageSize: (width, height) => `Taille de l'image suggérée : ${width} x ${height}`,
1305
1326
  value: "Valeur"
1306
1327
  }
@@ -1311,9 +1332,46 @@ var effectFormMessages = (locale = "en", translations) => ({
1311
1332
  ...translations?.[locale]
1312
1333
  });
1313
1334
  var useEffectFormMessages = (locale, translations) => effectFormMessages(useKrakstackLocale3(locale), translations);
1314
- var getCauseErrorMessage = (cause) => {
1335
+ var SubmitErrorDetails = Schema2.Struct({
1336
+ _tag: Schema2.optional(Schema2.String),
1337
+ status: Schema2.optional(Schema2.Number),
1338
+ statusCode: Schema2.optional(Schema2.Number)
1339
+ }).annotate({ identifier: "SubmitErrorDetails" });
1340
+ var submitErrorStatuses = new Map([
1341
+ ["BadRequest", 400],
1342
+ ["Unauthorized", 401],
1343
+ ["Forbidden", 403],
1344
+ ["NotFound", 404],
1345
+ ["Conflict", 409],
1346
+ ["TooManyRequests", 429],
1347
+ ["InternalServerError", 500],
1348
+ ["NotImplemented", 501],
1349
+ ["ServiceUnavailable", 503]
1350
+ ]);
1351
+ var getCauseErrorMessage = (cause, labels) => {
1315
1352
  const error = Cause.squash(cause);
1316
- return error instanceof Error ? error.message : String(error);
1353
+ const isHttpClientError = HttpClientError.isHttpClientError(error);
1354
+ if (!isHttpClientError && error instanceof Error && error.message.trim()) {
1355
+ return error.message.trim();
1356
+ }
1357
+ const details = Option.getOrUndefined(Schema2.decodeUnknownOption(SubmitErrorDetails)(error));
1358
+ const status = isHttpClientError ? error.response?.status : details?.status ?? details?.statusCode ?? submitErrorStatuses.get(details?._tag ?? "");
1359
+ const statusMessage = new Map([
1360
+ [400, labels.submitBadRequest],
1361
+ [401, labels.submitUnauthorized],
1362
+ [403, labels.submitForbidden],
1363
+ [404, labels.submitNotFound],
1364
+ [409, labels.submitConflict],
1365
+ [429, labels.submitRateLimited],
1366
+ [500, labels.submitFailed],
1367
+ [501, labels.submitFailed],
1368
+ [503, labels.submitUnavailable]
1369
+ ]).get(status ?? 0);
1370
+ if (statusMessage)
1371
+ return statusMessage;
1372
+ if (error instanceof Error)
1373
+ return error.message.trim() || labels.submitFailed;
1374
+ return Option.getOrElse(Schema2.decodeUnknownOption(Schema2.String)(error), () => "").trim() || labels.submitFailed;
1317
1375
  };
1318
1376
  var FieldWrapper = ({
1319
1377
  children,
@@ -1351,9 +1409,12 @@ var ErrorMessage = ({ text }) => /* @__PURE__ */ jsx13("em", {
1351
1409
  children: text
1352
1410
  });
1353
1411
  var SubmitError = ({
1354
- result
1412
+ result,
1413
+ locale,
1414
+ messages
1355
1415
  }) => {
1356
- const message = AsyncResult.isFailure(result) ? Schema2.isSchemaError(Cause.squash(result.cause)) ? undefined : getCauseErrorMessage(result.cause) : undefined;
1416
+ const labels = useEffectFormMessages(locale, messages);
1417
+ const message = AsyncResult.isFailure(result) ? Schema2.isSchemaError(Cause.squash(result.cause)) ? undefined : getCauseErrorMessage(result.cause, labels) : undefined;
1357
1418
  return message ? /* @__PURE__ */ jsx13(ErrorMessage, {
1358
1419
  text: message
1359
1420
  }) : null;
@@ -2010,14 +2071,12 @@ var ImageField = ({ field, props }) => {
2010
2071
  onBlur: field.onBlur,
2011
2072
  canClear: Boolean(field.value),
2012
2073
  ...field.value instanceof File ? { file: field.value } : {},
2013
- ...imageUrl ? {
2014
- image: {
2015
- alt: props.label,
2016
- height: props.size.height,
2017
- src: imageUrl,
2018
- width: props.size.width
2019
- }
2020
- } : {},
2074
+ image: {
2075
+ alt: props.label,
2076
+ height: props.size.height,
2077
+ src: imageUrl,
2078
+ width: props.size.width
2079
+ },
2021
2080
  id: field.path,
2022
2081
  invalid,
2023
2082
  locale: props.locale,
@@ -5,7 +5,7 @@ import {
5
5
  useRef,
6
6
  useState
7
7
  } from "react";
8
- import { CloudUpload, FileIcon, FileUp, RefreshCw, Trash2 } from "lucide-react";
8
+ import { CloudUpload, FileIcon, FileUp, ImageUp, Trash2 } from "lucide-react";
9
9
  import { Schema } from "effect";
10
10
 
11
11
  // ../../src/components/ui/attachment.tsx
@@ -233,7 +233,7 @@ var formatBytes = (bytes, locale) => {
233
233
  }).format(value);
234
234
  };
235
235
  var fileDescription = (file, locale) => [
236
- file.type || file.name.split(".").pop()?.toUpperCase(),
236
+ (file.name.includes(".") ? file.name.split(".").pop()?.toUpperCase() : "") || file.type.split("/").pop()?.toUpperCase(),
237
237
  formatBytes(file.size, locale)
238
238
  ].filter(Boolean).join(" · ");
239
239
  var FilePicker = ({
@@ -447,40 +447,44 @@ var FilePicker = ({
447
447
  return /* @__PURE__ */ jsxs(Fragment, {
448
448
  children: [
449
449
  /* @__PURE__ */ jsxs(Attachment, {
450
- className: image ? "w-fit max-w-full" : "w-full",
451
- orientation: image ? "vertical" : "horizontal",
450
+ className: "w-full",
451
+ orientation: "horizontal",
452
452
  state: invalid ? "error" : "done",
453
453
  children: [
454
454
  /* @__PURE__ */ jsx4(AttachmentMedia, {
455
455
  variant: image ? "image" : "icon",
456
- className: image ? "aspect-auto w-full max-w-full [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
456
+ className: image ? "aspect-auto max-w-full border [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
457
+ style: image ? {
458
+ width: image.width,
459
+ aspectRatio: `${image.width} / ${image.height}`
460
+ } : undefined,
457
461
  children: image && imageUrl ? /* @__PURE__ */ jsx4("img", {
458
462
  src: imageUrl,
459
463
  alt: image.alt,
460
464
  width: image.width,
461
465
  height: image.height,
462
- className: "h-auto max-w-full object-contain",
463
- style: { maxHeight: image.height }
466
+ className: "size-full object-contain"
464
467
  }) : /* @__PURE__ */ jsx4(FileIcon, {})
465
468
  }),
466
469
  /* @__PURE__ */ jsxs(AttachmentContent, {
467
- className: image ? "w-full" : undefined,
468
470
  children: [
469
471
  /* @__PURE__ */ jsx4(AttachmentTitle, {
470
- children: title
472
+ children: file?.name ?? title
471
473
  }),
472
474
  file ? /* @__PURE__ */ jsx4(AttachmentDescription, {
475
+ className: "break-words",
473
476
  children: fileDescription(file, locale)
474
477
  }) : null
475
478
  ]
476
479
  }),
477
480
  /* @__PURE__ */ jsxs(AttachmentActions, {
481
+ className: "ml-auto gap-1",
478
482
  children: [
479
483
  /* @__PURE__ */ jsx4(AttachmentAction, {
480
484
  type: "button",
481
485
  "aria-label": labels.replaceFile,
482
486
  onClick: () => inputRef.current?.click(),
483
- children: /* @__PURE__ */ jsx4(RefreshCw, {})
487
+ children: image ? /* @__PURE__ */ jsx4(ImageUp, {}) : /* @__PURE__ */ jsx4(FileUp, {})
484
488
  }),
485
489
  canClear ? /* @__PURE__ */ jsx4(AttachmentAction, {
486
490
  type: "button",
@@ -328,7 +328,7 @@ import {
328
328
  useRef,
329
329
  useState
330
330
  } from "react";
331
- import { CloudUpload, FileIcon, FileUp, RefreshCw, Trash2 } from "lucide-react";
331
+ import { CloudUpload, FileIcon, FileUp, ImageUp, Trash2 } from "lucide-react";
332
332
  import { Schema } from "effect";
333
333
 
334
334
  // ../../src/components/ui/attachment.tsx
@@ -496,7 +496,7 @@ var formatBytes = (bytes, locale) => {
496
496
  }).format(value);
497
497
  };
498
498
  var fileDescription = (file, locale) => [
499
- file.type || file.name.split(".").pop()?.toUpperCase(),
499
+ (file.name.includes(".") ? file.name.split(".").pop()?.toUpperCase() : "") || file.type.split("/").pop()?.toUpperCase(),
500
500
  formatBytes(file.size, locale)
501
501
  ].filter(Boolean).join(" · ");
502
502
  var FilePicker = ({
@@ -710,40 +710,44 @@ var FilePicker = ({
710
710
  return /* @__PURE__ */ jsxs3(Fragment, {
711
711
  children: [
712
712
  /* @__PURE__ */ jsxs3(Attachment, {
713
- className: image ? "w-fit max-w-full" : "w-full",
714
- orientation: image ? "vertical" : "horizontal",
713
+ className: "w-full",
714
+ orientation: "horizontal",
715
715
  state: invalid ? "error" : "done",
716
716
  children: [
717
717
  /* @__PURE__ */ jsx7(AttachmentMedia, {
718
718
  variant: image ? "image" : "icon",
719
- className: image ? "aspect-auto w-full max-w-full [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
719
+ className: image ? "aspect-auto max-w-full border [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
720
+ style: image ? {
721
+ width: image.width,
722
+ aspectRatio: `${image.width} / ${image.height}`
723
+ } : undefined,
720
724
  children: image && imageUrl ? /* @__PURE__ */ jsx7("img", {
721
725
  src: imageUrl,
722
726
  alt: image.alt,
723
727
  width: image.width,
724
728
  height: image.height,
725
- className: "h-auto max-w-full object-contain",
726
- style: { maxHeight: image.height }
729
+ className: "size-full object-contain"
727
730
  }) : /* @__PURE__ */ jsx7(FileIcon, {})
728
731
  }),
729
732
  /* @__PURE__ */ jsxs3(AttachmentContent, {
730
- className: image ? "w-full" : undefined,
731
733
  children: [
732
734
  /* @__PURE__ */ jsx7(AttachmentTitle, {
733
- children: title
735
+ children: file?.name ?? title
734
736
  }),
735
737
  file ? /* @__PURE__ */ jsx7(AttachmentDescription, {
738
+ className: "break-words",
736
739
  children: fileDescription(file, locale)
737
740
  }) : null
738
741
  ]
739
742
  }),
740
743
  /* @__PURE__ */ jsxs3(AttachmentActions, {
744
+ className: "ml-auto gap-1",
741
745
  children: [
742
746
  /* @__PURE__ */ jsx7(AttachmentAction, {
743
747
  type: "button",
744
748
  "aria-label": labels.replaceFile,
745
749
  onClick: () => inputRef.current?.click(),
746
- children: /* @__PURE__ */ jsx7(RefreshCw, {})
750
+ children: image ? /* @__PURE__ */ jsx7(ImageUp, {}) : /* @__PURE__ */ jsx7(FileUp, {})
747
751
  }),
748
752
  canClear ? /* @__PURE__ */ jsx7(AttachmentAction, {
749
753
  type: "button",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.47",
3
+ "version": "0.1.49",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {