refactor: extract debounce logic into shared composable
- Create useDebounce composable to avoid code duplication - Apply debounce to TextSettings margin/padding inputs - Harmonize debounce delay to 500ms across all components - Fix input lag when typing values like "30mm" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
35c9ab1d3b
commit
681517db21
5 changed files with 40 additions and 29 deletions
|
|
@ -130,9 +130,11 @@ import InputWithUnit from '../ui/InputWithUnit.vue';
|
|||
import MarginEditor from '../ui/MarginEditor.vue';
|
||||
import { useCssUpdater } from '../../composables/useCssUpdater';
|
||||
import { useCssSync } from '../../composables/useCssSync';
|
||||
import { useDebounce } from '../../composables/useDebounce';
|
||||
|
||||
const { updateStyle, setMargin, setDetailedMargins, setPadding, setDetailedPadding } = useCssUpdater();
|
||||
const { extractValue, extractNumericValue, extractSpacing } = useCssSync();
|
||||
const { debouncedUpdate } = useDebounce(500);
|
||||
|
||||
// Constants
|
||||
const fonts = ['Alegreya Sans', 'Arial', 'Georgia', 'Helvetica', 'Times New Roman'];
|
||||
|
|
@ -203,26 +205,32 @@ watch(weight, (val) => {
|
|||
|
||||
watch(fontSize, (val) => {
|
||||
if (isUpdatingFromStore) return;
|
||||
updateStyle('p', 'font-size', `${val.value}${val.unit}`);
|
||||
debouncedUpdate(() => {
|
||||
updateStyle('p', 'font-size', `${val.value}${val.unit}`);
|
||||
});
|
||||
}, { deep: true });
|
||||
|
||||
// Margin/Padding handlers
|
||||
const handleMarginOuterChange = ({ type, simple, detailed }) => {
|
||||
if (isUpdatingFromStore) return;
|
||||
if (type === 'simple') {
|
||||
setMargin('p', simple.value, simple.unit);
|
||||
} else {
|
||||
setDetailedMargins('p', detailed.top, detailed.right, detailed.bottom, detailed.left);
|
||||
}
|
||||
debouncedUpdate(() => {
|
||||
if (type === 'simple') {
|
||||
setMargin('p', simple.value, simple.unit);
|
||||
} else {
|
||||
setDetailedMargins('p', detailed.top, detailed.right, detailed.bottom, detailed.left);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handleMarginInnerChange = ({ type, simple, detailed }) => {
|
||||
if (isUpdatingFromStore) return;
|
||||
if (type === 'simple') {
|
||||
setPadding('p', simple.value, simple.unit);
|
||||
} else {
|
||||
setDetailedPadding('p', detailed.top, detailed.right, detailed.bottom, detailed.left);
|
||||
}
|
||||
debouncedUpdate(() => {
|
||||
if (type === 'simple') {
|
||||
setPadding('p', simple.value, simple.unit);
|
||||
} else {
|
||||
setDetailedPadding('p', detailed.top, detailed.right, detailed.bottom, detailed.left);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Sync from store
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue