-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample-05.html
More file actions
148 lines (129 loc) · 3.67 KB
/
example-05.html
File metadata and controls
148 lines (129 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
body {
background: white;
color: black;
}
.deletion {
position: relative;
color: red;
}
.addition {
position: relative;
color: green;
}
.deletion::before,
.addition::before {
display: block;
content: '';
position: absolute;
left: 0;
top: 0;
margin-left: -10px;
}
.deletion::before {
content: '-';
}
.addition::before {
content: '+';
}
.unchanged {
color: gray;
}
.diff {
font-family: monospace;
white-space: pre;
border: 1px solid gray;
padding: 10px 10px 10px 20px;
}
</style>
</head>
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="./json-diff-react.bundle.js"></script>
<script type="text/babel">
const { JsonDiffComponent } = window['json-diff-react'];
const container = document.getElementById('root');
const root = ReactDOM.createRoot(container);
// These JSON example was taken from this page https://en.wikipedia.org/wiki/JSON
const a = {
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 27,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [
"Catherine",
"Thomas",
"Trevor"
],
"spouse": null
};
// Slight modifications of JSON in “a”
const b = {
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 27,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "cellphone",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [
"Catherine",
"John",
"Trevor"
],
"spouse": null
};
const App = () => <div>
<h1>JSON diff</h1>
<p>A demo that shows how to add plus and minus signs using CSS styles.</p>
<JsonDiffComponent jsonA={a} jsonB={b} />
<p>
No elisions for objects (original behavior of <b>json-diff</b> library,{' '}
<code>{'jsonDiffOptions={{ showElisionsForObjects: false }}'}</code>).
</p>
<JsonDiffComponent jsonA={a} jsonB={b} jsonDiffOptions={{ showElisionsForObjects: false }} />
<p>A fuller diff (<code>{'jsonDiffOptions={{ full: true }}'}</code>).</p>
<JsonDiffComponent jsonA={a} jsonB={b} jsonDiffOptions={{ full: true }} />
<p>A bit more expanded diff (<code>{'jsonDiffOptions={{ keepUnchangedValues: true }}'}</code>).</p>
<JsonDiffComponent jsonA={a} jsonB={b} jsonDiffOptions={{ keepUnchangedValues: true }} />
</div>;
root.render(<App/>);
</script>
</body>
</html>