|
1 | 1 | import BaseFormatter from './base'; |
2 | 2 |
|
3 | | -class HtmlFormatter extends BaseFormatter { |
| 3 | +export default class HtmlFormatter extends BaseFormatter { |
4 | 4 | typeFormattterErrorFormatter(context, err) { |
5 | 5 | context.out(`<pre class="jsondiffpatch-error">${err}</pre>`); |
6 | 6 | } |
@@ -162,6 +162,64 @@ class HtmlFormatter extends BaseFormatter { |
162 | 162 | this.formatTextDiffString(context, delta[0]); |
163 | 163 | context.out('</div>'); |
164 | 164 | } |
| 165 | + |
| 166 | + hideUnchanged(node, delay) { |
| 167 | + this.showUnchanged(false, node, delay); |
| 168 | + } |
| 169 | + |
| 170 | + showUnchanged(show, node, delay) { |
| 171 | + let el = node || document.body; |
| 172 | + let prefix = 'jsondiffpatch-unchanged-'; |
| 173 | + let classes = { |
| 174 | + showing: `${prefix}showing`, |
| 175 | + hiding: `${prefix}hiding`, |
| 176 | + visible: `${prefix}visible`, |
| 177 | + hidden: `${prefix}hidden`, |
| 178 | + }; |
| 179 | + let list = el.classList; |
| 180 | + if (!list) { |
| 181 | + return; |
| 182 | + } |
| 183 | + if (!delay) { |
| 184 | + list.remove(classes.showing); |
| 185 | + list.remove(classes.hiding); |
| 186 | + list.remove(classes.visible); |
| 187 | + list.remove(classes.hidden); |
| 188 | + if (show === false) { |
| 189 | + list.add(classes.hidden); |
| 190 | + } |
| 191 | + return; |
| 192 | + } |
| 193 | + if (show === false) { |
| 194 | + list.remove(classes.showing); |
| 195 | + list.add(classes.visible); |
| 196 | + setTimeout(() => { |
| 197 | + list.add(classes.hiding); |
| 198 | + }, 10); |
| 199 | + } else { |
| 200 | + list.remove(classes.hiding); |
| 201 | + list.add(classes.showing); |
| 202 | + list.remove(classes.hidden); |
| 203 | + } |
| 204 | + let intervalId = setInterval(() => { |
| 205 | + adjustArrows(el); |
| 206 | + }, 100); |
| 207 | + setTimeout(() => { |
| 208 | + list.remove(classes.showing); |
| 209 | + list.remove(classes.hiding); |
| 210 | + if (show === false) { |
| 211 | + list.add(classes.hidden); |
| 212 | + list.remove(classes.visible); |
| 213 | + } else { |
| 214 | + list.add(classes.visible); |
| 215 | + list.remove(classes.hidden); |
| 216 | + } |
| 217 | + setTimeout(() => { |
| 218 | + list.remove(classes.visible); |
| 219 | + clearInterval(intervalId); |
| 220 | + }, delay + 400); |
| 221 | + }, delay); |
| 222 | + } |
165 | 223 | } |
166 | 224 |
|
167 | 225 | function htmlEscape(text) { |
@@ -231,70 +289,3 @@ let adjustArrows = function jsondiffpatchHtmlFormatterAdjustArrows(nodeArg) { |
231 | 289 |
|
232 | 290 | /* jshint camelcase: true */ |
233 | 291 | /* eslint-enable camelcase */ |
234 | | - |
235 | | -export const showUnchanged = (show, node, delay) => { |
236 | | - let el = node || document.body; |
237 | | - let prefix = 'jsondiffpatch-unchanged-'; |
238 | | - let classes = { |
239 | | - showing: `${prefix}showing`, |
240 | | - hiding: `${prefix}hiding`, |
241 | | - visible: `${prefix}visible`, |
242 | | - hidden: `${prefix}hidden`, |
243 | | - }; |
244 | | - let list = el.classList; |
245 | | - if (!list) { |
246 | | - return; |
247 | | - } |
248 | | - if (!delay) { |
249 | | - list.remove(classes.showing); |
250 | | - list.remove(classes.hiding); |
251 | | - list.remove(classes.visible); |
252 | | - list.remove(classes.hidden); |
253 | | - if (show === false) { |
254 | | - list.add(classes.hidden); |
255 | | - } |
256 | | - return; |
257 | | - } |
258 | | - if (show === false) { |
259 | | - list.remove(classes.showing); |
260 | | - list.add(classes.visible); |
261 | | - setTimeout(() => { |
262 | | - list.add(classes.hiding); |
263 | | - }, 10); |
264 | | - } else { |
265 | | - list.remove(classes.hiding); |
266 | | - list.add(classes.showing); |
267 | | - list.remove(classes.hidden); |
268 | | - } |
269 | | - let intervalId = setInterval(() => { |
270 | | - adjustArrows(el); |
271 | | - }, 100); |
272 | | - setTimeout(() => { |
273 | | - list.remove(classes.showing); |
274 | | - list.remove(classes.hiding); |
275 | | - if (show === false) { |
276 | | - list.add(classes.hidden); |
277 | | - list.remove(classes.visible); |
278 | | - } else { |
279 | | - list.add(classes.visible); |
280 | | - list.remove(classes.hidden); |
281 | | - } |
282 | | - setTimeout(() => { |
283 | | - list.remove(classes.visible); |
284 | | - clearInterval(intervalId); |
285 | | - }, delay + 400); |
286 | | - }, delay); |
287 | | -}; |
288 | | - |
289 | | -export const hideUnchanged = (node, delay) => showUnchanged(false, node, delay); |
290 | | - |
291 | | -export default HtmlFormatter; |
292 | | - |
293 | | -let defaultInstance; |
294 | | - |
295 | | -export function format(delta, left) { |
296 | | - if (!defaultInstance) { |
297 | | - defaultInstance = new HtmlFormatter(); |
298 | | - } |
299 | | - return defaultInstance.format(delta, left); |
300 | | -} |
0 commit comments