File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ # How to render in svelte
2+
3+ Here is an example of a reusable component for svelte 5:
4+
5+ ``` svelte
6+ <script lang="ts">
7+ import { create } from 'jsondiffpatch';
8+ import { format as formatHtml } from 'jsondiffpatch/formatters/html';
9+ import 'jsondiffpatch/formatters/styles/html.css';
10+
11+ let {
12+ left,
13+ right,
14+ diffOptions = undefined,
15+ hideUnchangedValues = false,
16+ }: {
17+ left: unknown;
18+ right: unknown;
19+ diffOptions?: Parameters<typeof create>[0] | undefined;
20+ hideUnchangedValues?: boolean;
21+ showAnnotated?: boolean;
22+ } = $props();
23+
24+ let htmlDiff = $derived.by(() => {
25+ const jdp = create(diffOptions ?? {});
26+ const delta = jdp.diff(left, right);
27+ return formatHtml(delta ?? {}, left);
28+ });
29+ </script>
30+
31+ <div class={`json-diff-container ${hideUnchangedValues ? 'jsondiffpatch-unchanged-hidden' : ''}`}>
32+ <div class="jsondiffpatch-result" aria-label="Visual JSON diff">
33+ {@html htmlDiff}
34+ </div>
35+ </div>
36+ ```
You can’t perform that action at this time.
0 commit comments