@oliasoft-open-source/react-ui-library 5.2.2-beta-4 → 5.2.2-beta-5
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/index.js +77 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -184615,46 +184615,99 @@ const VIEW_OPTIONS = [
|
|
|
184615
184615
|
{ value: SPLIT_VIEW, label: "Split View" },
|
|
184616
184616
|
{ value: UNIFIED_VIEW, label: "Unified View" }
|
|
184617
184617
|
];
|
|
184618
|
+
const getChangedKeys = (a2, b2, path2 = "") => {
|
|
184619
|
+
const keys2 = /* @__PURE__ */ new Set([...Object.keys(a2 || {}), ...Object.keys(b2 || {})]);
|
|
184620
|
+
const changes = [];
|
|
184621
|
+
keys2.forEach((key2) => {
|
|
184622
|
+
const valA = a2 == null ? void 0 : a2[key2];
|
|
184623
|
+
const valB = b2 == null ? void 0 : b2[key2];
|
|
184624
|
+
const fullPath = path2 ? `${path2}.${key2}` : key2;
|
|
184625
|
+
if (typeof valA === "object" && typeof valB === "object") {
|
|
184626
|
+
changes.push(...getChangedKeys(valA, valB, fullPath));
|
|
184627
|
+
} else if (valA !== valB) {
|
|
184628
|
+
changes.push(fullPath);
|
|
184629
|
+
}
|
|
184630
|
+
});
|
|
184631
|
+
return changes;
|
|
184632
|
+
};
|
|
184633
|
+
const filterByChangedKeys = (data, changedKeys) => {
|
|
184634
|
+
const filtered = {};
|
|
184635
|
+
changedKeys.forEach((keyPath) => {
|
|
184636
|
+
const parts = keyPath.split(".");
|
|
184637
|
+
let current = filtered;
|
|
184638
|
+
let source = data;
|
|
184639
|
+
parts.forEach((part, idx) => {
|
|
184640
|
+
if (idx === parts.length - 1) {
|
|
184641
|
+
current[part] = source == null ? void 0 : source[part];
|
|
184642
|
+
} else {
|
|
184643
|
+
current[part] = current[part] || {};
|
|
184644
|
+
current = current[part];
|
|
184645
|
+
source = source == null ? void 0 : source[part];
|
|
184646
|
+
}
|
|
184647
|
+
});
|
|
184648
|
+
});
|
|
184649
|
+
return filtered;
|
|
184650
|
+
};
|
|
184618
184651
|
const DiffViewer = ({
|
|
184619
184652
|
oldJson,
|
|
184620
184653
|
newJson,
|
|
184621
184654
|
viewType = SPLIT_VIEW
|
|
184622
184655
|
}) => {
|
|
184623
184656
|
const [activeViewType, setActiveViewType] = useState(viewType);
|
|
184657
|
+
const [showTrimmed, setShowTrimmed] = useState(true);
|
|
184624
184658
|
useEffect(() => {
|
|
184625
184659
|
setActiveViewType(viewType);
|
|
184626
184660
|
}, [viewType]);
|
|
184627
184661
|
const changeViewType = ({ target: { value } }) => {
|
|
184628
184662
|
setActiveViewType(value);
|
|
184629
184663
|
};
|
|
184630
|
-
const
|
|
184631
|
-
const
|
|
184632
|
-
const
|
|
184633
|
-
const
|
|
184664
|
+
const toggleTrimmed = () => setShowTrimmed((prev2) => !prev2);
|
|
184665
|
+
const parsedOld = JSON.parse(oldJson || "{}");
|
|
184666
|
+
const parsedNew = JSON.parse(newJson || "{}");
|
|
184667
|
+
const changedKeys = getChangedKeys(parsedOld, parsedNew);
|
|
184668
|
+
const trimmedOld = filterByChangedKeys(parsedOld, changedKeys);
|
|
184669
|
+
const trimmedNew = filterByChangedKeys(parsedNew, changedKeys);
|
|
184670
|
+
const added = Math.max(
|
|
184671
|
+
0,
|
|
184672
|
+
newJson.split("\n").length - oldJson.split("\n").length
|
|
184673
|
+
);
|
|
184674
|
+
const removed = Math.max(
|
|
184675
|
+
0,
|
|
184676
|
+
oldJson.split("\n").length - newJson.split("\n").length
|
|
184677
|
+
);
|
|
184634
184678
|
return /* @__PURE__ */ jsx(
|
|
184635
184679
|
Card,
|
|
184636
184680
|
{
|
|
184637
184681
|
bordered: true,
|
|
184638
|
-
heading: /* @__PURE__ */ jsxs(Flex, { gap: true, children: [
|
|
184639
|
-
/* @__PURE__ */
|
|
184640
|
-
/* @__PURE__ */
|
|
184641
|
-
|
|
184642
|
-
|
|
184643
|
-
|
|
184644
|
-
|
|
184645
|
-
|
|
184646
|
-
|
|
184647
|
-
|
|
184648
|
-
|
|
184649
|
-
|
|
184682
|
+
heading: /* @__PURE__ */ jsxs(Flex, { gap: true, justifyContent: "space-between", children: [
|
|
184683
|
+
/* @__PURE__ */ jsxs(Flex, { gap: true, children: [
|
|
184684
|
+
/* @__PURE__ */ jsx(Heading$2, { children: /* @__PURE__ */ jsxs("div", { children: [
|
|
184685
|
+
/* @__PURE__ */ jsxs(Text$1, { success: true, children: [
|
|
184686
|
+
"+",
|
|
184687
|
+
added,
|
|
184688
|
+
" "
|
|
184689
|
+
] }),
|
|
184690
|
+
/* @__PURE__ */ jsxs(Text$1, { error: true, children: [
|
|
184691
|
+
"-",
|
|
184692
|
+
removed
|
|
184693
|
+
] })
|
|
184694
|
+
] }) }),
|
|
184695
|
+
/* @__PURE__ */ jsx(
|
|
184696
|
+
RadioButton,
|
|
184697
|
+
{
|
|
184698
|
+
name: "viewType",
|
|
184699
|
+
options: VIEW_OPTIONS,
|
|
184700
|
+
value: activeViewType,
|
|
184701
|
+
onChange: changeViewType,
|
|
184702
|
+
inline: true
|
|
184703
|
+
}
|
|
184704
|
+
)
|
|
184705
|
+
] }),
|
|
184650
184706
|
/* @__PURE__ */ jsx(
|
|
184651
|
-
|
|
184707
|
+
Button$1,
|
|
184652
184708
|
{
|
|
184653
|
-
|
|
184654
|
-
|
|
184655
|
-
value: activeViewType,
|
|
184656
|
-
onChange: changeViewType,
|
|
184657
|
-
inline: true
|
|
184709
|
+
label: showTrimmed ? "Show Full JSON" : "Show Only Changes",
|
|
184710
|
+
onClick: toggleTrimmed
|
|
184658
184711
|
}
|
|
184659
184712
|
)
|
|
184660
184713
|
] }),
|
|
@@ -184662,8 +184715,8 @@ const DiffViewer = ({
|
|
|
184662
184715
|
children: /* @__PURE__ */ jsx(
|
|
184663
184716
|
ReactJsonViewCompare,
|
|
184664
184717
|
{
|
|
184665
|
-
oldData:
|
|
184666
|
-
newData:
|
|
184718
|
+
oldData: showTrimmed ? trimmedOld : parsedOld,
|
|
184719
|
+
newData: showTrimmed ? trimmedNew : parsedNew
|
|
184667
184720
|
}
|
|
184668
184721
|
)
|
|
184669
184722
|
}
|