@ai-matrx/content-ir-react 0.16.0 → 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.
@@ -107,11 +107,13 @@ function sameValue(a, b) {
107
107
  if (typeof a === "object" || typeof b === "object") return safeJson(a) === safeJson(b);
108
108
  return false;
109
109
  }
110
- function itemChanges(item, current) {
110
+ function itemChanges(item, current, options = {}) {
111
111
  const out = [];
112
+ const titleColumn = options.titleColumn ?? null;
112
113
  for (const [key, raw] of Object.entries(item)) {
113
114
  if (NOT_A_CHANGE.has(key)) continue;
114
- const change = { key, label: fieldLabel(key), ...describeValue(raw) };
115
+ const label = key === titleColumn ? "Title" : fieldLabel(key);
116
+ const change = { key, label, ...describeValue(raw) };
115
117
  if (current && Object.prototype.hasOwnProperty.call(current, key)) {
116
118
  change.before = describeValue(current[key]);
117
119
  change.same = sameValue(current[key], raw);
@@ -121,6 +123,30 @@ function itemChanges(item, current) {
121
123
  return out;
122
124
  }
123
125
 
126
+ // directives/failure-words.ts
127
+ var PAST = {
128
+ create: "created",
129
+ update: "updated",
130
+ delete: "deleted"
131
+ };
132
+ function defaultFailureWords(failure) {
133
+ const verbed = PAST[failure.directiveClass] ?? "applied";
134
+ const noun = failure.nounLabel.trim().toLowerCase() || "item";
135
+ if (failure.failed && failure.total && failure.total > 1) {
136
+ return {
137
+ what: `${failure.failed} of ${failure.total} weren't ${verbed}.`,
138
+ next: "Retry to try those again."
139
+ };
140
+ }
141
+ return {
142
+ what: `The ${noun} wasn't ${verbed}.`,
143
+ next: "Try again in a moment."
144
+ };
145
+ }
146
+ function failureWords(failure, explain) {
147
+ return explain?.(failure) ?? defaultFailureWords(failure);
148
+ }
149
+
124
150
  // directives/icons.tsx
125
151
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
126
152
  function Svg({ children, ...props }) {
@@ -378,10 +404,23 @@ function ApplyDirectiveButton({
378
404
  children: [
379
405
  /* @__PURE__ */ jsxs2("span", { className: "inline-flex min-w-0 items-start gap-1", children: [
380
406
  bad ? /* @__PURE__ */ jsx3(AlertIcon, { className: "mt-px h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ jsx3(CheckCircleIcon, { className: "mt-px h-3.5 w-3.5 shrink-0" }),
381
- /* @__PURE__ */ jsxs2("span", { className: "min-w-0", children: [
382
- state.message ?? `Applied ${state.applied}`,
383
- bad && !state.message ? ` \xB7 ${state.failed} failed` : ""
384
- ] })
407
+ bad ? /* @__PURE__ */ jsx3(
408
+ FailureNotice,
409
+ {
410
+ words: failureWords(
411
+ {
412
+ raw: state.message ?? `${state.failed} failed`,
413
+ directiveClass: directive.directiveClass,
414
+ noun: directive.noun,
415
+ nounLabel: nounText,
416
+ failed: state.failed,
417
+ total: state.applied + state.failed
418
+ },
419
+ host.explainFailure
420
+ ),
421
+ raw: state.message
422
+ }
423
+ ) : /* @__PURE__ */ jsx3("span", { className: "min-w-0", children: state.message ?? `Applied ${state.applied}` })
385
424
  ] }),
386
425
  state.copies > 1 ? /* @__PURE__ */ jsx3(
387
426
  "span",
@@ -458,10 +497,64 @@ function ApplyDirectiveButton({
458
497
  ]
459
498
  }
460
499
  ),
461
- state.status === "error" ? /* @__PURE__ */ jsxs2("span", { className: "inline-flex max-w-sm items-start gap-1 text-xs text-destructive", children: [
462
- /* @__PURE__ */ jsx3(AlertIcon, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
463
- /* @__PURE__ */ jsx3("span", { children: state.message })
464
- ] }) : null
500
+ state.status === "error" ? /* @__PURE__ */ jsxs2(
501
+ "span",
502
+ {
503
+ className: "inline-flex max-w-sm items-start gap-1 text-xs text-destructive",
504
+ "data-apply-state": "error",
505
+ children: [
506
+ /* @__PURE__ */ jsx3(AlertIcon, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
507
+ /* @__PURE__ */ jsx3(
508
+ FailureNotice,
509
+ {
510
+ words: failureWords(
511
+ {
512
+ raw: state.message,
513
+ directiveClass: directive.directiveClass,
514
+ noun: directive.noun,
515
+ nounLabel: nounText
516
+ },
517
+ host.explainFailure
518
+ ),
519
+ raw: state.message
520
+ }
521
+ )
522
+ ]
523
+ }
524
+ ) : null
525
+ ] });
526
+ }
527
+ function FailureNotice({
528
+ words,
529
+ raw
530
+ }) {
531
+ const [open, setOpen] = useState(false);
532
+ const detail = raw?.trim() ?? "";
533
+ return /* @__PURE__ */ jsxs2("span", { className: "flex min-w-0 flex-col gap-0.5", "data-apply-failure": true, children: [
534
+ /* @__PURE__ */ jsxs2("span", { className: "min-w-0", children: [
535
+ words.what,
536
+ " ",
537
+ words.next,
538
+ detail ? /* @__PURE__ */ jsx3(
539
+ "button",
540
+ {
541
+ type: "button",
542
+ onClick: () => setOpen((v) => !v),
543
+ "aria-expanded": open,
544
+ className: "ml-1 underline underline-offset-2 hover:no-underline",
545
+ "data-apply-failure-details-toggle": true,
546
+ children: open ? "Hide details" : "Details"
547
+ }
548
+ ) : null
549
+ ] }),
550
+ open && detail ? /* @__PURE__ */ jsx3(
551
+ "span",
552
+ {
553
+ className: "block max-w-sm select-text break-words font-mono text-[11px] text-muted-foreground",
554
+ "data-apply-failure-details": true,
555
+ children: detail
556
+ }
557
+ ) : null
465
558
  ] });
466
559
  }
467
560
 
@@ -616,7 +709,7 @@ function TargetRow({
616
709
  isUpdate ? host.readRecord : void 0,
617
710
  isUpdate ? { noun: directive.noun, id: recordId } : null
618
711
  );
619
- const changes = isUpdate ? itemChanges(item, current.values) : [];
712
+ const changes = isUpdate ? itemChanges(item, current.values, { titleColumn: nounTitleColumn(directive.noun, host.nouns) }) : [];
620
713
  const name = host.renderRecord ? host.renderRecord({ noun: directive.noun, id: recordId, fallback, context: "row" }) : /* @__PURE__ */ jsx4("span", { className: "truncate font-medium text-foreground", children: fallback });
621
714
  return /* @__PURE__ */ jsxs3("div", { className: "py-1 text-xs", "data-directive-target": recordId, children: [
622
715
  /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 items-center gap-2", children: [
@@ -788,7 +881,9 @@ export {
788
881
  DirectiveScopeProvider,
789
882
  SideEffectDirectiveCard,
790
883
  TARGETING_CLASSES,
884
+ defaultFailureWords,
791
885
  describeChangeValue,
886
+ failureWords,
792
887
  fieldLabel,
793
888
  getDirectiveRenderer,
794
889
  itemChanges,