pagedJS reload preview : decrease timeout
This commit is contained in:
parent
07e5764ccd
commit
6a01909b38
3 changed files with 31 additions and 20 deletions
30
src/App.vue
30
src/App.vue
|
|
@ -15,7 +15,9 @@ const currentFrameIndex = ref(1); // 1 or 2, which iframe is currently visible
|
||||||
let isTransitioning = false;
|
let isTransitioning = false;
|
||||||
|
|
||||||
const activeFrame = computed(() => {
|
const activeFrame = computed(() => {
|
||||||
return currentFrameIndex.value === 1 ? previewFrame1.value : previewFrame2.value;
|
return currentFrameIndex.value === 1
|
||||||
|
? previewFrame1.value
|
||||||
|
: previewFrame2.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderPreview = async (shouldReloadFromFile = false) => {
|
const renderPreview = async (shouldReloadFromFile = false) => {
|
||||||
|
|
@ -23,8 +25,10 @@ const renderPreview = async (shouldReloadFromFile = false) => {
|
||||||
isTransitioning = true;
|
isTransitioning = true;
|
||||||
|
|
||||||
// Determine which iframe is currently visible and which to render to
|
// Determine which iframe is currently visible and which to render to
|
||||||
const visibleFrame = currentFrameIndex.value === 1 ? previewFrame1.value : previewFrame2.value;
|
const visibleFrame =
|
||||||
const hiddenFrame = currentFrameIndex.value === 1 ? previewFrame2.value : previewFrame1.value;
|
currentFrameIndex.value === 1 ? previewFrame1.value : previewFrame2.value;
|
||||||
|
const hiddenFrame =
|
||||||
|
currentFrameIndex.value === 1 ? previewFrame2.value : previewFrame1.value;
|
||||||
|
|
||||||
if (!hiddenFrame) {
|
if (!hiddenFrame) {
|
||||||
isTransitioning = false;
|
isTransitioning = false;
|
||||||
|
|
@ -32,9 +36,14 @@ const renderPreview = async (shouldReloadFromFile = false) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save scroll position from visible frame
|
// Save scroll position from visible frame
|
||||||
if (visibleFrame && visibleFrame.contentWindow && visibleFrame.contentDocument) {
|
if (
|
||||||
|
visibleFrame &&
|
||||||
|
visibleFrame.contentWindow &&
|
||||||
|
visibleFrame.contentDocument
|
||||||
|
) {
|
||||||
const scrollTop = visibleFrame.contentWindow.scrollY || 0;
|
const scrollTop = visibleFrame.contentWindow.scrollY || 0;
|
||||||
const scrollHeight = visibleFrame.contentDocument.documentElement.scrollHeight;
|
const scrollHeight =
|
||||||
|
visibleFrame.contentDocument.documentElement.scrollHeight;
|
||||||
const clientHeight = visibleFrame.contentWindow.innerHeight;
|
const clientHeight = visibleFrame.contentWindow.innerHeight;
|
||||||
const maxScroll = scrollHeight - clientHeight;
|
const maxScroll = scrollHeight - clientHeight;
|
||||||
|
|
||||||
|
|
@ -67,7 +76,8 @@ const renderPreview = async (shouldReloadFromFile = false) => {
|
||||||
// Wait for PagedJS to finish rendering
|
// Wait for PagedJS to finish rendering
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// Restore scroll position
|
// Restore scroll position
|
||||||
const scrollHeight = hiddenFrame.contentDocument.documentElement.scrollHeight;
|
const scrollHeight =
|
||||||
|
hiddenFrame.contentDocument.documentElement.scrollHeight;
|
||||||
const clientHeight = hiddenFrame.contentWindow.innerHeight;
|
const clientHeight = hiddenFrame.contentWindow.innerHeight;
|
||||||
const maxScroll = scrollHeight - clientHeight;
|
const maxScroll = scrollHeight - clientHeight;
|
||||||
const targetScroll = savedScrollPercentage * maxScroll;
|
const targetScroll = savedScrollPercentage * maxScroll;
|
||||||
|
|
@ -94,9 +104,9 @@ const renderPreview = async (shouldReloadFromFile = false) => {
|
||||||
// Swap current frame
|
// Swap current frame
|
||||||
currentFrameIndex.value = currentFrameIndex.value === 1 ? 2 : 1;
|
currentFrameIndex.value = currentFrameIndex.value === 1 ? 2 : 1;
|
||||||
isTransitioning = false;
|
isTransitioning = false;
|
||||||
}, 300); // Match CSS transition duration
|
}, 100); // Match CSS transition duration
|
||||||
}, 100); // Small delay to ensure scroll is set
|
}, 50); // Small delay to ensure scroll is set
|
||||||
}, 500); // Wait for PagedJS
|
}, 200); // Wait for PagedJS
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -131,7 +141,7 @@ onMounted(() => renderPreview(true));
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
border: none;
|
border: none;
|
||||||
transition: opacity 0.3s ease-in-out;
|
transition: opacity 0.1s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-frame:nth-of-type(1) {
|
.preview-frame:nth-of-type(1) {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import { useStylesheetStore } from '../stores/stylesheet';
|
||||||
const stylesheetStore = useStylesheetStore();
|
const stylesheetStore = useStylesheetStore();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
iframeRef: Object
|
iframeRef: Object,
|
||||||
});
|
});
|
||||||
|
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
|
|
@ -48,9 +48,7 @@ const position = ref({ x: 0, y: 0 });
|
||||||
const selector = ref('');
|
const selector = ref('');
|
||||||
|
|
||||||
const getSelectorFromElement = (element) => {
|
const getSelectorFromElement = (element) => {
|
||||||
return element.id
|
return element.id ? `#${element.id}` : `.${element.className.split(' ')[0]}`;
|
||||||
? `#${element.id}`
|
|
||||||
: `.${element.className.split(' ')[0]}`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculatePosition = (element) => {
|
const calculatePosition = (element) => {
|
||||||
|
|
@ -115,7 +113,7 @@ const handleCssInput = (event) => {
|
||||||
cssDebounceTimer = setTimeout(() => {
|
cssDebounceTimer = setTimeout(() => {
|
||||||
const oldBlock = elementCss.value;
|
const oldBlock = elementCss.value;
|
||||||
stylesheetStore.content = stylesheetStore.content.replace(oldBlock, newCss);
|
stylesheetStore.content = stylesheetStore.content.replace(oldBlock, newCss);
|
||||||
}, 1000);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({ handleIframeClick });
|
defineExpose({ handleIframeClick });
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,10 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<pre v-if="!isEditable" class="readonly"><code class="hljs language-css" v-html="highlightedCss"></code></pre>
|
<pre
|
||||||
|
v-if="!isEditable"
|
||||||
|
class="readonly"
|
||||||
|
><code class="hljs language-css" v-html="highlightedCss"></code></pre>
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
v-else
|
v-else
|
||||||
|
|
@ -47,7 +50,7 @@ const handleInput = (event) => {
|
||||||
|
|
||||||
debounceTimer = setTimeout(() => {
|
debounceTimer = setTimeout(() => {
|
||||||
stylesheetStore.content = newContent;
|
stylesheetStore.content = newContent;
|
||||||
}, 1000);
|
}, 500);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -86,7 +89,7 @@ h3 {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle input[type="checkbox"] {
|
.toggle input[type='checkbox'] {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
width: 0;
|
width: 0;
|
||||||
|
|
@ -115,11 +118,11 @@ h3 {
|
||||||
transition: transform 0.2s ease;
|
transition: transform 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle input[type="checkbox"]:checked + .toggle-switch {
|
.toggle input[type='checkbox']:checked + .toggle-switch {
|
||||||
background: #61afef;
|
background: #61afef;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle input[type="checkbox"]:checked + .toggle-switch::after {
|
.toggle input[type='checkbox']:checked + .toggle-switch::after {
|
||||||
transform: translateX(20px);
|
transform: translateX(20px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue