|
13 | 13 | import LZ from 'lz-string'
|
14 | 14 | import type { CustomComponents } from './types.js'
|
15 | 15 | import { browser } from '$app/environment'
|
| 16 | + import { prefersReducedMotion } from 'svelte/motion' |
16 | 17 |
|
17 | 18 | type InspectProps = {
|
18 | 19 | value?: any
|
19 | 20 | name?: string
|
20 |
| - rawIndent?: number |
21 | 21 | showLength?: boolean
|
22 | 22 | showTypes?: boolean
|
23 | 23 | stringCollapse?: number
|
24 | 24 | savecollapse?: 'localStorage' | 'sessionStorage'
|
25 | 25 | noanimate?: boolean
|
| 26 | + quotes?: 'single' | 'double' |
| 27 | + expandAll?: boolean |
26 | 28 | theme?: string
|
27 | 29 | draggable?: boolean
|
28 | 30 | customComponents?: CustomComponents
|
|
34 | 36 | showLength = true,
|
35 | 37 | showTypes = true,
|
36 | 38 | savecollapse = 'localStorage',
|
37 |
| - stringCollapse = undefined, |
| 39 | + quotes = 'single', |
| 40 | + expandAll = false, |
| 41 | + stringCollapse = 0, |
38 | 42 | noanimate = false,
|
39 | 43 | class: classValue = '',
|
40 |
| - theme = 'drak', |
| 44 | + theme = 'cotton-candy', |
41 | 45 | draggable = false,
|
42 | 46 | customComponents = {},
|
43 | 47 | ...rest
|
44 | 48 | }: InspectProps = $props()
|
45 | 49 |
|
46 |
| - let options = createOptions(() => ({ |
| 50 | + let options = createOptions({ |
47 | 51 | showLength,
|
48 | 52 | showTypes,
|
49 | 53 | stringCollapse,
|
50 | 54 | draggable,
|
51 | 55 | noanimate,
|
52 | 56 | customComponents,
|
53 | 57 | theme,
|
54 |
| - })) |
| 58 | + expandAll, |
| 59 | + }) |
55 | 60 |
|
56 | 61 | $effect(() => {
|
57 |
| - options.value = { |
| 62 | + options.setOptions({ |
58 | 63 | showLength,
|
59 | 64 | showTypes,
|
60 | 65 | stringCollapse,
|
61 | 66 | draggable,
|
62 | 67 | noanimate,
|
63 | 68 | customComponents,
|
64 | 69 | theme,
|
65 |
| - } |
| 70 | + expandAll, |
| 71 | + }) |
66 | 72 | })
|
67 | 73 |
|
68 | 74 | setContext('json-inspect', options)
|
|
73 | 79 | const v = localStorage.getItem('[svelte-value-inspect]' + name)
|
74 | 80 | if (v) {
|
75 | 81 | try {
|
76 |
| - initialState = JSON.parse(LZ.decompress(v)) |
| 82 | + // initialState = JSON.parse(LZ.decompress(v)) |
| 83 | + initialState = JSON.parse(v) |
77 | 84 | } catch (e) {
|
78 | 85 | console.warn('[Svelte Value Inspect] Could not restore saved state')
|
79 | 86 | }
|
|
113 | 120 | loadDraggable()
|
114 | 121 | }
|
115 | 122 | })
|
| 123 | +
|
| 124 | + let fixedBottom = $state(false) |
116 | 125 | </script>
|
117 | 126 |
|
118 | 127 | <!-- {#if browser} -->
|
| 128 | +<!-- {#if initialState} --> |
119 | 129 | <svelte:boundary>
|
120 | 130 | {#snippet failed(error, reset)}
|
121 | 131 | {#if error instanceof Error}
|
|
130 | 140 | in:fade
|
131 | 141 | class:noanimate={options.value.noanimate}
|
132 | 142 | class="ampled-json-inspect {classValue} {options.value.theme}"
|
| 143 | + class:fixedBottom |
133 | 144 | use:getAction={() => ({ handle: '.handle', disabled: !options.value.draggable })}
|
134 | 145 | {...rest}
|
135 | 146 | >
|
136 | 147 | <Options />
|
137 | 148 | <div class="body">
|
| 149 | + <!-- <button |
| 150 | + style="position: absolute; top:0; left: 0;" |
| 151 | + onclick={() => (fixedBottom = !fixedBottom)}>⇒</button |
| 152 | + > --> |
138 | 153 | {#if options.value.draggable}
|
139 | 154 | <div class="handle">⋮</div>
|
140 | 155 | {/if}
|
|
0 commit comments