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