|
4 | 4 | import equal from 'fast-deep-equal'; |
5 | 5 | import DOMPurify from 'isomorphic-dompurify'; |
6 | 6 | import { marked } from 'marked'; |
7 | | - import { setContext, untrack } from 'svelte'; |
| 7 | + import { setContext } from 'svelte'; |
8 | 8 | import { writable } from 'svelte/store'; |
9 | 9 | import { _ } from 'svelte-i18n'; |
10 | 10 |
|
|
161 | 161 | widgetName === 'compute', |
162 | 162 | ); |
163 | 163 | const invalid = $derived(validity?.valid === false); |
164 | | -
|
165 | | - /** |
166 | | - * Store for the current value of the field. We use this to sync with the draft store because a |
167 | | - * direct binding with `$entryDraft.currentValues[locale][keyPath]` degrades performance. |
168 | | - * @type {any} |
169 | | - */ |
170 | | - let currentValueCache = $state(); |
171 | | -
|
172 | | - /** |
173 | | - * Timer for updating the draft store after a delay to avoid frequent updates while typing. |
174 | | - * @type {number} |
175 | | - */ |
176 | | - let updateTimer = 0; |
177 | | -
|
178 | | - $effect(() => { |
179 | | - if ($entryDraft) { |
180 | | - const _currentValue = $entryDraft.currentValues[locale][keyPath]; |
181 | | -
|
182 | | - untrack(() => { |
183 | | - window.setTimeout(() => { |
184 | | - if (currentValueCache !== _currentValue) { |
185 | | - currentValueCache = _currentValue; |
186 | | - } |
187 | | - }, 0); |
188 | | - }); |
189 | | - } |
190 | | - }); |
191 | | -
|
192 | | - $effect(() => { |
193 | | - void currentValueCache; |
194 | | -
|
195 | | - untrack(() => { |
196 | | - window.clearTimeout(updateTimer); |
197 | | - updateTimer = window.setTimeout(() => { |
198 | | - if ($entryDraft && $entryDraft.currentValues[locale][keyPath] !== currentValueCache) { |
199 | | - $entryDraft.currentValues[locale][keyPath] = currentValueCache; |
200 | | - } |
201 | | - }, 200); |
202 | | - }); |
203 | | - }); |
204 | 164 | </script> |
205 | 165 |
|
206 | 166 | {#if $entryDraft && canEdit && widgetName !== 'hidden'} |
|
329 | 289 | {fieldId} |
330 | 290 | {fieldLabel} |
331 | 291 | {fieldConfig} |
332 | | - bind:currentValue={currentValueCache} |
| 292 | + bind:currentValue={$entryDraft.currentValues[locale][keyPath]} |
333 | 293 | {readonly} |
334 | 294 | {required} |
335 | 295 | {invalid} |
|
0 commit comments