UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

34 lines (32 loc) 1.22 kB
import "../../../chunks/chunk-U5RRZUYZ.js"; // src/dashboard/view/diff/ListDiff.tsx import { Sink } from "alinea/ui/Sink"; import { ChangeBox } from "./ChangeBox.js"; import { diffList, diffRecord } from "./DiffUtils.js"; import { FieldsDiff } from "./FieldsDiff.js"; import { jsx } from "react/jsx-runtime"; function ListDiff({ 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.values[block.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 };