@ai-matrx/content-ir-react 0.16.1 → 0.17.0

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/react.cjs CHANGED
@@ -210,6 +210,30 @@ function itemChanges(item, current, options = {}) {
210
210
  return out;
211
211
  }
212
212
 
213
+ // directives/failure-words.ts
214
+ var PAST = {
215
+ create: "created",
216
+ update: "updated",
217
+ delete: "deleted"
218
+ };
219
+ function defaultFailureWords(failure) {
220
+ const verbed = PAST[failure.directiveClass] ?? "applied";
221
+ const noun = failure.nounLabel.trim().toLowerCase() || "item";
222
+ if (failure.failed && failure.total && failure.total > 1) {
223
+ return {
224
+ what: `${failure.failed} of ${failure.total} weren't ${verbed}.`,
225
+ next: "Retry to try those again."
226
+ };
227
+ }
228
+ return {
229
+ what: `The ${noun} wasn't ${verbed}.`,
230
+ next: "Try again in a moment."
231
+ };
232
+ }
233
+ function failureWords(failure, explain) {
234
+ return explain?.(failure) ?? defaultFailureWords(failure);
235
+ }
236
+
213
237
  // directives/icons.tsx
214
238
  var import_jsx_runtime3 = require("react/jsx-runtime");
215
239
  function Svg({ children, ...props }) {
@@ -467,10 +491,23 @@ function ApplyDirectiveButton({
467
491
  children: [
468
492
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "inline-flex min-w-0 items-start gap-1", children: [
469
493
  bad ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertIcon, { className: "mt-px h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CheckCircleIcon, { className: "mt-px h-3.5 w-3.5 shrink-0" }),
470
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "min-w-0", children: [
471
- state.message ?? `Applied ${state.applied}`,
472
- bad && !state.message ? ` \xB7 ${state.failed} failed` : ""
473
- ] })
494
+ bad ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
495
+ FailureNotice,
496
+ {
497
+ words: failureWords(
498
+ {
499
+ raw: state.message ?? `${state.failed} failed`,
500
+ directiveClass: directive.directiveClass,
501
+ noun: directive.noun,
502
+ nounLabel: nounText,
503
+ failed: state.failed,
504
+ total: state.applied + state.failed
505
+ },
506
+ host.explainFailure
507
+ ),
508
+ raw: state.message
509
+ }
510
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "min-w-0", children: state.message ?? `Applied ${state.applied}` })
474
511
  ] }),
475
512
  state.copies > 1 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
476
513
  "span",
@@ -547,10 +584,64 @@ function ApplyDirectiveButton({
547
584
  ]
548
585
  }
549
586
  ),
550
- state.status === "error" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "inline-flex max-w-sm items-start gap-1 text-xs text-destructive", children: [
551
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertIcon, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
552
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: state.message })
553
- ] }) : null
587
+ state.status === "error" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
588
+ "span",
589
+ {
590
+ className: "inline-flex max-w-sm items-start gap-1 text-xs text-destructive",
591
+ "data-apply-state": "error",
592
+ children: [
593
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertIcon, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
594
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
595
+ FailureNotice,
596
+ {
597
+ words: failureWords(
598
+ {
599
+ raw: state.message,
600
+ directiveClass: directive.directiveClass,
601
+ noun: directive.noun,
602
+ nounLabel: nounText
603
+ },
604
+ host.explainFailure
605
+ ),
606
+ raw: state.message
607
+ }
608
+ )
609
+ ]
610
+ }
611
+ ) : null
612
+ ] });
613
+ }
614
+ function FailureNotice({
615
+ words,
616
+ raw
617
+ }) {
618
+ const [open, setOpen] = (0, import_react4.useState)(false);
619
+ const detail = raw?.trim() ?? "";
620
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "flex min-w-0 flex-col gap-0.5", "data-apply-failure": true, children: [
621
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "min-w-0", children: [
622
+ words.what,
623
+ " ",
624
+ words.next,
625
+ detail ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
626
+ "button",
627
+ {
628
+ type: "button",
629
+ onClick: () => setOpen((v) => !v),
630
+ "aria-expanded": open,
631
+ className: "ml-1 underline underline-offset-2 hover:no-underline",
632
+ "data-apply-failure-details-toggle": true,
633
+ children: open ? "Hide details" : "Details"
634
+ }
635
+ ) : null
636
+ ] }),
637
+ open && detail ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
638
+ "span",
639
+ {
640
+ className: "block max-w-sm select-text break-words font-mono text-[11px] text-muted-foreground",
641
+ "data-apply-failure-details": true,
642
+ children: detail
643
+ }
644
+ ) : null
554
645
  ] });
555
646
  }
556
647