UNPKG

alinea

Version:
33 lines (31 loc) 1.25 kB
import "../../../chunks/chunk-NZLE2WMY.js"; // src/dashboard/view/diff/ListDiff.tsx import { ListRow } from "alinea/core/shape/ListShape"; import { Sink } from "alinea/ui/Sink"; import { ChangeBox } from "./ChangeBox.js"; import { diffList, diffRecord } from "./DiffUtils.js"; import { jsx } from "react/jsx-runtime"; function ListDiff({ FieldsDiff, shape, valueA, valueB }) { const equals = (itemA, itemB) => { return itemA._id === itemB._id; }; const changes = diffList(valueA || [], valueB || [], equals); return /* @__PURE__ */ jsx(Sink.Root, { children: changes.map((change, i) => { const block = change.value; const kind = shape.shapes[block[ListRow.type]]; const compare = change.type === "keep" ? [change.old, change.value] : change.type === "removal" ? [change.value, {}] : [{}, change.value]; const changes2 = diffRecord(kind, compare[0], compare[1]); if (changes2.length === 0) return /* @__PURE__ */ jsx(ChangeBox, { change: "equal" }, i); return /* @__PURE__ */ jsx(ChangeBox, { change: change.type, children: /* @__PURE__ */ jsx( FieldsDiff, { changes: changes2, targetA: compare[0], targetB: compare[1] } ) }, i); }) }); } export { ListDiff };