feat: add page template interaction with PagePopup
Implements page edge hover detection and click handling: - Hover near page edges (30px threshold) shows light outline - Click on page edge opens PagePopup for template customization - PagePopup component similar to ElementPopup but for @page rules - Both popups coordinate to show only one at a time 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2068e9a1f9
commit
7ae711957a
2 changed files with 247 additions and 7 deletions
91
src/App.vue
91
src/App.vue
|
|
@ -2,6 +2,7 @@
|
|||
import PagedJsWrapper from './components/PagedJsWrapper.vue';
|
||||
import EditorPanel from './components/editor/EditorPanel.vue';
|
||||
import ElementPopup from './components/ElementPopup.vue';
|
||||
import PagePopup from './components/PagePopup.vue';
|
||||
import PreviewLoader from './components/PreviewLoader.vue';
|
||||
import { onMounted, ref, watch, computed, provide } from 'vue';
|
||||
import { useStylesheetStore } from './stores/stylesheet';
|
||||
|
|
@ -11,10 +12,15 @@ const stylesheetStore = useStylesheetStore();
|
|||
const previewFrame1 = ref(null);
|
||||
const previewFrame2 = ref(null);
|
||||
const elementPopup = ref(null);
|
||||
const pagePopup = ref(null);
|
||||
const activeTab = ref('');
|
||||
|
||||
provide('activeTab', activeTab);
|
||||
|
||||
// Page interaction state
|
||||
const hoveredPage = ref(null);
|
||||
const EDGE_THRESHOLD = 30; // px from edge to trigger hover
|
||||
|
||||
let savedScrollPercentage = 0;
|
||||
const currentFrameIndex = ref(1); // 1 or 2, which iframe is currently visible
|
||||
const isTransitioning = ref(false);
|
||||
|
|
@ -25,6 +31,77 @@ const activeFrame = computed(() => {
|
|||
: previewFrame2.value;
|
||||
});
|
||||
|
||||
// Check if mouse position is near the edges of a page element
|
||||
const isNearPageEdge = (pageElement, mouseX, mouseY) => {
|
||||
const rect = pageElement.getBoundingClientRect();
|
||||
|
||||
const nearLeft = mouseX >= rect.left && mouseX <= rect.left + EDGE_THRESHOLD;
|
||||
const nearRight = mouseX >= rect.right - EDGE_THRESHOLD && mouseX <= rect.right;
|
||||
const nearTop = mouseY >= rect.top && mouseY <= rect.top + EDGE_THRESHOLD;
|
||||
const nearBottom = mouseY >= rect.bottom - EDGE_THRESHOLD && mouseY <= rect.bottom;
|
||||
|
||||
const inHorizontalRange = mouseY >= rect.top && mouseY <= rect.bottom;
|
||||
const inVerticalRange = mouseX >= rect.left && mouseX <= rect.right;
|
||||
|
||||
return (
|
||||
(nearLeft && inHorizontalRange) ||
|
||||
(nearRight && inHorizontalRange) ||
|
||||
(nearTop && inVerticalRange) ||
|
||||
(nearBottom && inVerticalRange)
|
||||
);
|
||||
};
|
||||
|
||||
// Handle mouse movement in iframe
|
||||
const handleIframeMouseMove = (event) => {
|
||||
const pages = event.target.ownerDocument.querySelectorAll('.pagedjs_page');
|
||||
let foundPage = null;
|
||||
|
||||
for (const page of pages) {
|
||||
if (isNearPageEdge(page, event.clientX, event.clientY)) {
|
||||
foundPage = page;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update hover state
|
||||
if (foundPage !== hoveredPage.value) {
|
||||
// Remove highlight from previous page
|
||||
if (hoveredPage.value) {
|
||||
hoveredPage.value.style.outline = '';
|
||||
}
|
||||
|
||||
// Add highlight to new page
|
||||
if (foundPage) {
|
||||
foundPage.style.outline = '2px solid rgba(97, 175, 239, 0.3)';
|
||||
}
|
||||
|
||||
hoveredPage.value = foundPage;
|
||||
}
|
||||
};
|
||||
|
||||
// Handle click in iframe
|
||||
const handleIframeClick = (event) => {
|
||||
const element = event.target;
|
||||
|
||||
// Check if clicking near a page edge
|
||||
if (hoveredPage.value) {
|
||||
event.stopPropagation();
|
||||
pagePopup.value.open(hoveredPage.value);
|
||||
elementPopup.value.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise handle as element click
|
||||
if (element.tagName === 'BODY' || element.tagName === 'HTML') {
|
||||
elementPopup.value.close();
|
||||
pagePopup.value.close();
|
||||
return;
|
||||
}
|
||||
|
||||
elementPopup.value.handleIframeClick(event);
|
||||
pagePopup.value.close();
|
||||
};
|
||||
|
||||
const renderPreview = async (shouldReloadFromFile = false) => {
|
||||
if (isTransitioning.value) return;
|
||||
isTransitioning.value = true;
|
||||
|
|
@ -73,10 +150,9 @@ const renderPreview = async (shouldReloadFromFile = false) => {
|
|||
`;
|
||||
|
||||
hiddenFrame.onload = () => {
|
||||
hiddenFrame.contentDocument.addEventListener(
|
||||
'click',
|
||||
elementPopup.value.handleIframeClick
|
||||
);
|
||||
// Add event listeners for page and element interactions
|
||||
hiddenFrame.contentDocument.addEventListener('mousemove', handleIframeMouseMove);
|
||||
hiddenFrame.contentDocument.addEventListener('click', handleIframeClick);
|
||||
|
||||
// Close Coloris when clicking in the iframe
|
||||
hiddenFrame.contentDocument.addEventListener('click', () => {
|
||||
|
|
@ -151,6 +227,7 @@ onMounted(() => renderPreview(true));
|
|||
<PreviewLoader :isLoading="isTransitioning" :shifted="activeTab.length > 0" />
|
||||
|
||||
<ElementPopup ref="elementPopup" :iframeRef="activeFrame" />
|
||||
<PagePopup ref="pagePopup" :iframeRef="activeFrame" />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
|
@ -168,9 +245,9 @@ onMounted(() => renderPreview(true));
|
|||
}
|
||||
|
||||
.preview-frame.shifted {
|
||||
margin-left: 19rem;
|
||||
transform: scale(0.7) translateY(-30vh);
|
||||
height: 142vh;
|
||||
margin-left: 17.55rem;
|
||||
transform: scale(0.65) translateY(-40vh);
|
||||
height: 155vh;
|
||||
}
|
||||
|
||||
.preview-frame:nth-of-type(1) {
|
||||
|
|
|
|||
163
src/components/PagePopup.vue
Normal file
163
src/components/PagePopup.vue
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
<template>
|
||||
<div
|
||||
v-if="visible"
|
||||
id="page-popup"
|
||||
:style="{ top: position.y + 'px', left: position.x + 'px' }"
|
||||
>
|
||||
<div class="popup-header">
|
||||
<span>{{ pageSelector }}</span>
|
||||
<button class="close-btn" @click="close">×</button>
|
||||
</div>
|
||||
<div class="popup-body">
|
||||
<div class="popup-controls">
|
||||
<p class="info">Gabarit de page</p>
|
||||
<!-- Additional page-specific controls will be added here later -->
|
||||
</div>
|
||||
<div class="popup-css">
|
||||
<textarea
|
||||
:value="pageCss"
|
||||
@input="handleCssInput"
|
||||
spellcheck="false"
|
||||
></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { useStylesheetStore } from '../stores/stylesheet';
|
||||
|
||||
const stylesheetStore = useStylesheetStore();
|
||||
|
||||
const props = defineProps({
|
||||
iframeRef: Object,
|
||||
});
|
||||
|
||||
const visible = ref(false);
|
||||
const position = ref({ x: 0, y: 0 });
|
||||
const pageSelector = ref('@page');
|
||||
const selectedPageElement = ref(null);
|
||||
|
||||
const calculatePosition = (pageElement) => {
|
||||
const rect = pageElement.getBoundingClientRect();
|
||||
const iframeRect = props.iframeRef.getBoundingClientRect();
|
||||
return {
|
||||
x: iframeRect.left + rect.left + 20,
|
||||
y: iframeRect.top + rect.top + 20,
|
||||
};
|
||||
};
|
||||
|
||||
const open = (pageElement) => {
|
||||
selectedPageElement.value = pageElement;
|
||||
pageSelector.value = '@page';
|
||||
position.value = calculatePosition(pageElement);
|
||||
|
||||
// Add border to the selected page
|
||||
pageElement.style.outline = '2px solid #61afef';
|
||||
|
||||
visible.value = true;
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
// Remove border from the selected page
|
||||
if (selectedPageElement.value) {
|
||||
selectedPageElement.value.style.outline = '';
|
||||
selectedPageElement.value = null;
|
||||
}
|
||||
visible.value = false;
|
||||
};
|
||||
|
||||
const pageCss = computed(() => {
|
||||
return stylesheetStore.extractBlock('@page') || '';
|
||||
});
|
||||
|
||||
let cssDebounceTimer = null;
|
||||
|
||||
const handleCssInput = (event) => {
|
||||
const newCss = event.target.value;
|
||||
|
||||
if (cssDebounceTimer) {
|
||||
clearTimeout(cssDebounceTimer);
|
||||
}
|
||||
|
||||
cssDebounceTimer = setTimeout(() => {
|
||||
const oldBlock = pageCss.value;
|
||||
if (oldBlock) {
|
||||
stylesheetStore.content = stylesheetStore.content.replace(oldBlock, newCss);
|
||||
}
|
||||
}, 500);
|
||||
};
|
||||
|
||||
defineExpose({ open, close, visible });
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
#page-popup {
|
||||
position: fixed;
|
||||
background: white;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
z-index: 10000;
|
||||
min-width: 400px;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-bottom: 1px solid #eee;
|
||||
font-size: 0.875rem;
|
||||
font-weight: bold;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 1.25rem;
|
||||
line-height: 1;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.popup-body {
|
||||
display: flex;
|
||||
gap: 1px;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.popup-controls {
|
||||
flex: 1;
|
||||
padding: 0.75rem;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.popup-css {
|
||||
flex: 1;
|
||||
background: #1e1e1e;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.popup-css textarea {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
background: #1e1e1e;
|
||||
color: #abb2bf;
|
||||
border: none;
|
||||
padding: 0.75rem;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.4;
|
||||
resize: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.info {
|
||||
font-size: 0.875rem;
|
||||
color: #666;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue