2025-11-24 16:51:55 +01:00
|
|
|
<template>
|
2026-02-26 15:35:45 +01:00
|
|
|
<BasePopup
|
|
|
|
|
ref="basePopup"
|
2025-11-24 16:51:55 +01:00
|
|
|
id="element-popup"
|
2026-02-26 15:35:45 +01:00
|
|
|
:display-css="displayedCss"
|
|
|
|
|
:editable-css="elementCss"
|
|
|
|
|
:popup-width="800"
|
|
|
|
|
:popup-height="600"
|
|
|
|
|
@close="close"
|
|
|
|
|
@css-input="handleCssInput"
|
|
|
|
|
@toggle-inheritance="toggleInheritance"
|
2025-11-24 16:51:55 +01:00
|
|
|
>
|
2026-02-26 15:35:45 +01:00
|
|
|
<template #header-left>
|
2026-02-26 15:47:58 +01:00
|
|
|
<span class="element-label">{{ selector || '' }}</span>
|
|
|
|
|
<span class="instance-count">{{ elementInstanceCount }} instances</span>
|
2026-02-26 15:35:45 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<template #controls>
|
|
|
|
|
<!-- Font Family -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field field-font" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="font-family">Police</label>
|
|
|
|
|
<div class="field-with-option">
|
2026-02-26 15:47:58 +01:00
|
|
|
<select v-model="fontFamily" :disabled="inheritanceLocked">
|
2026-02-26 15:35:45 +01:00
|
|
|
<option v-for="f in fonts" :key="f" :value="f">{{ f }}</option>
|
|
|
|
|
</select>
|
|
|
|
|
<div class="field-checkbox">
|
2026-02-26 15:47:58 +01:00
|
|
|
<input type="checkbox" v-model="italic" :disabled="inheritanceLocked" />
|
2026-02-26 15:35:45 +01:00
|
|
|
<label class="label-with-tooltip" data-css="font-style">Italique</label>
|
2025-12-11 13:39:23 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Font Weight -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="font-weight">Graisse</label>
|
|
|
|
|
<UnitToggle v-model="fontWeightString" :units="weights" :disabled="inheritanceLocked" />
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Font Size -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="font-size">Taille du texte</label>
|
|
|
|
|
<div class="input-with-unit">
|
|
|
|
|
<NumberInput
|
|
|
|
|
v-model="fontSize.value"
|
2026-03-02 17:29:49 +01:00
|
|
|
:min="6"
|
2026-02-26 15:35:45 +01:00
|
|
|
:step="1"
|
|
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
/>
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
:class="{ active: fontSize.unit === 'px' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
:disabled="inheritanceLocked"
|
2026-02-26 15:47:58 +01:00
|
|
|
@click="updateUnitPropUnit(fontSize, 'px')"
|
2026-02-26 15:35:45 +01:00
|
|
|
>
|
|
|
|
|
px
|
|
|
|
|
</button>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-03-02 17:29:49 +01:00
|
|
|
|
|
|
|
|
<!-- LineHeight -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="line-height">Interlignage</label>
|
|
|
|
|
<div class="input-with-unit">
|
|
|
|
|
<NumberInput
|
|
|
|
|
v-model="lineHeight.value"
|
|
|
|
|
:min="0"
|
|
|
|
|
:step="1"
|
|
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
/>
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
:class="{ active: lineHeight.unit === 'px' }"
|
|
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
@click="updateUnitPropUnit(lineHeight, 'px')"
|
|
|
|
|
>
|
|
|
|
|
px
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Text Alignment -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="text-align">Alignement</label>
|
2026-02-26 15:47:58 +01:00
|
|
|
<select v-model="textAlign" :disabled="inheritanceLocked">
|
2026-02-26 15:35:45 +01:00
|
|
|
<option value="left">Gauche</option>
|
|
|
|
|
<option value="center">Centre</option>
|
|
|
|
|
<option value="right">Droite</option>
|
|
|
|
|
<option value="justify">Justifié</option>
|
|
|
|
|
</select>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Color -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field field-simple" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="color">Couleur</label>
|
|
|
|
|
<div class="input-with-color">
|
|
|
|
|
<input
|
|
|
|
|
ref="colorInput"
|
|
|
|
|
type="text"
|
2026-02-26 15:47:58 +01:00
|
|
|
v-model="color"
|
2026-02-26 15:35:45 +01:00
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
data-coloris
|
|
|
|
|
/>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Background -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field field-simple" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="background">Arrière-plan</label>
|
|
|
|
|
<div class="input-with-color">
|
|
|
|
|
<input
|
|
|
|
|
ref="backgroundInput"
|
|
|
|
|
type="text"
|
2026-02-26 15:47:58 +01:00
|
|
|
v-model="background"
|
2026-02-26 15:35:45 +01:00
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
data-coloris
|
|
|
|
|
/>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Outer Margins -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="margin">Marges extérieures</label>
|
|
|
|
|
<div class="input-with-unit">
|
|
|
|
|
<NumberInput
|
|
|
|
|
v-model="marginOuter.value"
|
|
|
|
|
:min="0"
|
|
|
|
|
:step="1"
|
|
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
/>
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
:class="{ active: marginOuter.unit === 'mm' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
:disabled="inheritanceLocked"
|
2026-02-26 15:47:58 +01:00
|
|
|
@click="updateUnitPropUnit(marginOuter, 'mm')"
|
2026-02-26 15:35:45 +01:00
|
|
|
>
|
|
|
|
|
mm
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
:class="{ active: marginOuter.unit === 'px' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
:disabled="inheritanceLocked"
|
2026-02-26 15:47:58 +01:00
|
|
|
@click="updateUnitPropUnit(marginOuter, 'px')"
|
2026-02-26 15:35:45 +01:00
|
|
|
>
|
|
|
|
|
px
|
|
|
|
|
</button>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-11-24 16:51:55 +01:00
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
<!-- Inner Margins (Padding) -->
|
|
|
|
|
<div class="settings-subsection">
|
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
<label class="label-with-tooltip" data-css="padding">Marges intérieures</label>
|
|
|
|
|
<div class="input-with-unit">
|
|
|
|
|
<NumberInput
|
|
|
|
|
v-model="paddingInner.value"
|
|
|
|
|
:min="0"
|
|
|
|
|
:step="1"
|
2025-12-05 18:21:54 +01:00
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
/>
|
2026-02-26 15:35:45 +01:00
|
|
|
<div class="unit-toggle">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
:class="{ active: paddingInner.unit === 'mm' }"
|
|
|
|
|
:disabled="inheritanceLocked"
|
2026-02-26 15:47:58 +01:00
|
|
|
@click="updateUnitPropUnit(paddingInner, 'mm')"
|
2026-02-26 15:35:45 +01:00
|
|
|
>
|
|
|
|
|
mm
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
:class="{ active: paddingInner.unit === 'px' }"
|
|
|
|
|
:disabled="inheritanceLocked"
|
2026-02-26 15:47:58 +01:00
|
|
|
@click="updateUnitPropUnit(paddingInner, 'px')"
|
2026-02-26 15:35:45 +01:00
|
|
|
>
|
|
|
|
|
px
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
</div>
|
2025-11-24 16:51:55 +01:00
|
|
|
</div>
|
2026-02-26 15:35:45 +01:00
|
|
|
</template>
|
|
|
|
|
</BasePopup>
|
2025-11-24 16:51:55 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-02-26 15:47:58 +01:00
|
|
|
import { ref, reactive, computed, watch, nextTick } from 'vue';
|
2025-11-24 17:55:42 +01:00
|
|
|
import { useStylesheetStore } from '../stores/stylesheet';
|
2025-12-10 11:51:53 +01:00
|
|
|
import { useDebounce } from '../composables/useDebounce';
|
2025-12-09 17:08:40 +01:00
|
|
|
import NumberInput from './ui/NumberInput.vue';
|
2025-12-11 13:39:23 +01:00
|
|
|
import UnitToggle from './ui/UnitToggle.vue';
|
2026-02-26 15:35:45 +01:00
|
|
|
import BasePopup from './ui/BasePopup.vue';
|
2026-02-24 14:08:30 +01:00
|
|
|
import { convertUnit } from '../utils/unit-conversion';
|
2025-11-24 16:51:55 +01:00
|
|
|
|
2025-11-24 17:55:42 +01:00
|
|
|
const stylesheetStore = useStylesheetStore();
|
|
|
|
|
|
2025-11-24 16:51:55 +01:00
|
|
|
const props = defineProps({
|
2025-12-04 15:55:52 +01:00
|
|
|
iframeRef: Object,
|
2025-11-24 17:55:42 +01:00
|
|
|
});
|
|
|
|
|
|
2025-12-08 14:15:06 +01:00
|
|
|
const emit = defineEmits(['close']);
|
|
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
const basePopup = ref(null);
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
const visible = computed(() => basePopup.value?.visible ?? false);
|
|
|
|
|
const inheritanceLocked = computed(() => basePopup.value?.inheritanceLocked ?? true);
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2025-11-24 18:18:27 +01:00
|
|
|
const selector = ref('');
|
2025-12-05 18:21:54 +01:00
|
|
|
const selectedElement = ref(null);
|
2026-02-26 15:35:45 +01:00
|
|
|
const elementInstanceCount = ref(0);
|
2025-12-05 18:21:54 +01:00
|
|
|
const colorInput = ref(null);
|
|
|
|
|
const backgroundInput = ref(null);
|
|
|
|
|
|
|
|
|
|
let isUpdatingFromStore = false;
|
2025-12-10 11:51:53 +01:00
|
|
|
const { debouncedUpdate } = useDebounce(500);
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
// Style properties — flat refs for simple values, reactive for value+unit
|
|
|
|
|
const fontFamily = ref('Alegreya Sans');
|
|
|
|
|
const italic = ref(false);
|
|
|
|
|
const fontWeight = ref(400);
|
|
|
|
|
const textAlign = ref('left');
|
|
|
|
|
const color = ref('rgb(0, 0, 0)');
|
|
|
|
|
const background = ref('transparent');
|
|
|
|
|
const fontSize = reactive({ value: 23, unit: 'px' });
|
2026-03-02 17:29:49 +01:00
|
|
|
const lineHeight = reactive({ value: 28, unit: 'px' });
|
2026-02-26 15:47:58 +01:00
|
|
|
const marginOuter = reactive({ value: 0, unit: 'mm' });
|
|
|
|
|
const paddingInner = reactive({ value: 0, unit: 'mm' });
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2025-12-11 13:39:23 +01:00
|
|
|
// Constants
|
|
|
|
|
const fonts = ['Alegreya Sans', 'Alegreya', 'Arial', 'Georgia', 'Times New Roman'];
|
|
|
|
|
const weights = ['200', '300', '400', '600', '800'];
|
|
|
|
|
|
|
|
|
|
const fontWeightString = computed({
|
2026-02-26 15:47:58 +01:00
|
|
|
get: () => String(fontWeight.value),
|
|
|
|
|
set: (val) => { fontWeight.value = parseInt(val); }
|
2025-12-11 13:39:23 +01:00
|
|
|
});
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
// Style property descriptors
|
|
|
|
|
const styleProps = [
|
|
|
|
|
{ css: 'font-family', get: () => fontFamily.value, set: v => fontFamily.value = v.replace(/['"]/g, ''), debounce: false },
|
|
|
|
|
{ css: 'font-style', get: () => italic.value ? 'italic' : 'normal', set: v => italic.value = v === 'italic', debounce: false },
|
|
|
|
|
{ css: 'font-weight', get: () => fontWeight.value, set: v => fontWeight.value = parseInt(v), debounce: false },
|
|
|
|
|
{ css: 'text-align', get: () => textAlign.value, set: v => textAlign.value = v, debounce: false },
|
|
|
|
|
{ css: 'color', get: () => color.value, set: v => color.value = v, debounce: true },
|
|
|
|
|
{ css: 'background', get: () => background.value, set: v => background.value = v, debounce: true },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const unitProps = [
|
|
|
|
|
{ css: 'font-size', ref: fontSize, debounce: true },
|
2026-03-02 17:29:49 +01:00
|
|
|
{ css: 'line-height', ref: lineHeight, debounce: true },
|
2026-02-26 15:47:58 +01:00
|
|
|
{ css: 'margin', ref: marginOuter, debounce: true },
|
|
|
|
|
{ css: 'padding', ref: paddingInner, debounce: true },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Generic update: push a single property to the stylesheet store
|
|
|
|
|
const updateProp = (cssProp, value, unit) => {
|
|
|
|
|
if (!selector.value) return;
|
|
|
|
|
stylesheetStore.updateProperty(selector.value, cssProp, value, unit);
|
2026-02-24 14:08:30 +01:00
|
|
|
};
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
const updateUnitPropUnit = (prop, newUnit) => {
|
|
|
|
|
prop.value = convertUnit(prop.value, prop.unit, newUnit);
|
|
|
|
|
prop.unit = newUnit;
|
2026-02-24 14:08:30 +01:00
|
|
|
};
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
const getSelectorFromElement = (element) => {
|
|
|
|
|
if (element.id) {
|
|
|
|
|
return `#${element.id}`;
|
|
|
|
|
}
|
2025-11-24 18:18:27 +01:00
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
const tagName = element.tagName.toLowerCase();
|
|
|
|
|
|
2025-12-08 16:35:28 +01:00
|
|
|
const classes = Array.from(element.classList).filter(
|
|
|
|
|
(cls) => !['element-hovered', 'element-selected', 'page-hovered', 'page-selected'].includes(cls)
|
|
|
|
|
);
|
2025-12-05 18:21:54 +01:00
|
|
|
if (classes.length > 0) {
|
|
|
|
|
return `${tagName}.${classes[0]}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tagName;
|
2025-11-24 18:18:27 +01:00
|
|
|
};
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
const getInstanceCount = (sel) => {
|
2025-12-05 18:21:54 +01:00
|
|
|
if (!props.iframeRef || !props.iframeRef.contentDocument) return 0;
|
2025-11-24 18:18:27 +01:00
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
try {
|
2026-02-26 15:47:58 +01:00
|
|
|
return props.iframeRef.contentDocument.querySelectorAll(sel).length;
|
2025-12-05 18:21:54 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
return 0;
|
2025-11-24 18:18:27 +01:00
|
|
|
}
|
|
|
|
|
};
|
2025-11-24 17:55:42 +01:00
|
|
|
|
|
|
|
|
const elementCss = computed(() => {
|
2025-11-24 18:18:27 +01:00
|
|
|
if (!selector.value) return '';
|
2025-12-05 18:21:54 +01:00
|
|
|
return stylesheetStore.extractBlock(selector.value) || '';
|
2025-11-24 16:51:55 +01:00
|
|
|
});
|
|
|
|
|
|
2025-12-10 12:11:53 +01:00
|
|
|
const generatePreviewCss = () => {
|
|
|
|
|
if (!selector.value) return '';
|
|
|
|
|
|
|
|
|
|
const properties = [];
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
for (const prop of styleProps) {
|
|
|
|
|
const val = prop.get();
|
|
|
|
|
if (val && (prop.css !== 'font-style' || val === 'italic')) {
|
|
|
|
|
properties.push(` ${prop.css}: ${val};`);
|
|
|
|
|
}
|
2025-12-10 12:11:53 +01:00
|
|
|
}
|
2026-02-26 15:47:58 +01:00
|
|
|
|
|
|
|
|
for (const prop of unitProps) {
|
|
|
|
|
if (prop.ref.value !== undefined && prop.ref.value !== null) {
|
|
|
|
|
properties.push(` ${prop.css}: ${prop.ref.value}${prop.ref.unit};`);
|
|
|
|
|
}
|
2025-12-10 12:11:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (properties.length === 0) return '';
|
|
|
|
|
|
|
|
|
|
return `${selector.value} {\n${properties.join('\n')}\n}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const displayedCss = computed(() => {
|
|
|
|
|
if (!selector.value) return '';
|
|
|
|
|
|
|
|
|
|
if (!inheritanceLocked.value) {
|
|
|
|
|
return elementCss.value || generatePreviewCss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const preview = generatePreviewCss();
|
|
|
|
|
if (!preview) return '';
|
|
|
|
|
|
|
|
|
|
return '/* Héritage verrouillé - déverrouiller pour appliquer */\n/* ' +
|
|
|
|
|
preview.split('\n').join('\n ') +
|
|
|
|
|
' */';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const applyAllStyles = () => {
|
|
|
|
|
if (!selector.value) return;
|
2026-02-26 15:47:58 +01:00
|
|
|
for (const prop of styleProps) {
|
|
|
|
|
updateProp(prop.css, prop.get());
|
|
|
|
|
}
|
|
|
|
|
for (const prop of unitProps) {
|
|
|
|
|
updateProp(prop.css, prop.ref.value, prop.ref.unit);
|
|
|
|
|
}
|
2025-12-10 12:11:53 +01:00
|
|
|
};
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
// Watchers — simple props
|
|
|
|
|
for (const prop of styleProps) {
|
|
|
|
|
watch(prop.get, () => {
|
2026-02-26 15:35:45 +01:00
|
|
|
if (isUpdatingFromStore) return;
|
2026-02-26 15:47:58 +01:00
|
|
|
const fn = () => updateProp(prop.css, prop.get());
|
|
|
|
|
prop.debounce ? debouncedUpdate(fn) : fn();
|
2026-02-26 15:35:45 +01:00
|
|
|
});
|
2026-02-26 15:47:58 +01:00
|
|
|
}
|
2025-11-24 18:39:29 +01:00
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
// Watchers — unit props (watch both value and unit)
|
|
|
|
|
for (const prop of unitProps) {
|
|
|
|
|
watch(() => prop.ref.value, () => {
|
|
|
|
|
if (isUpdatingFromStore) return;
|
|
|
|
|
const fn = () => updateProp(prop.css, prop.ref.value, prop.ref.unit);
|
|
|
|
|
prop.debounce ? debouncedUpdate(fn) : fn();
|
|
|
|
|
});
|
|
|
|
|
watch(() => prop.ref.unit, () => {
|
|
|
|
|
if (isUpdatingFromStore) return;
|
|
|
|
|
updateProp(prop.css, prop.ref.value, prop.ref.unit);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-02-26 15:35:45 +01:00
|
|
|
|
|
|
|
|
const handleCssInput = (newCss) => {
|
|
|
|
|
const oldBlock = elementCss.value;
|
|
|
|
|
if (oldBlock) {
|
|
|
|
|
stylesheetStore.replaceInCustomCss(oldBlock, newCss);
|
2025-12-05 18:21:54 +01:00
|
|
|
}
|
2026-02-26 15:35:45 +01:00
|
|
|
};
|
2025-12-05 18:21:54 +01:00
|
|
|
|
|
|
|
|
// Watch stylesheet changes to sync values
|
|
|
|
|
watch(
|
2026-01-09 14:35:23 +01:00
|
|
|
() => stylesheetStore.customCss,
|
2025-12-05 18:21:54 +01:00
|
|
|
() => {
|
2026-02-26 15:35:45 +01:00
|
|
|
if (basePopup.value?.visible && !isUpdatingFromStore) {
|
2026-01-09 14:35:23 +01:00
|
|
|
isUpdatingFromStore = true;
|
2025-12-05 18:21:54 +01:00
|
|
|
loadValuesFromStylesheet();
|
2026-02-26 15:47:58 +01:00
|
|
|
nextTick(() => { isUpdatingFromStore = false; });
|
2026-01-09 14:35:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Also watch when exiting edit mode
|
|
|
|
|
watch(
|
|
|
|
|
() => stylesheetStore.isEditing,
|
|
|
|
|
(isEditing, wasEditing) => {
|
2026-02-26 15:35:45 +01:00
|
|
|
if (basePopup.value?.visible && wasEditing && !isEditing && !isUpdatingFromStore) {
|
2026-01-09 14:35:23 +01:00
|
|
|
isUpdatingFromStore = true;
|
|
|
|
|
loadValuesFromStylesheet();
|
2026-02-26 15:47:58 +01:00
|
|
|
nextTick(() => { isUpdatingFromStore = false; });
|
2025-12-05 18:21:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const loadValuesFromStylesheet = () => {
|
|
|
|
|
if (!selector.value) return;
|
|
|
|
|
|
|
|
|
|
try {
|
2026-02-26 15:47:58 +01:00
|
|
|
// Simple props
|
|
|
|
|
for (const prop of styleProps) {
|
|
|
|
|
const data = stylesheetStore.extractValue(selector.value, prop.css);
|
|
|
|
|
if (data) {
|
|
|
|
|
const value = typeof data === 'string' ? data : data.value;
|
|
|
|
|
prop.set(value);
|
|
|
|
|
}
|
2025-12-05 18:21:54 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
// Unit props
|
|
|
|
|
for (const prop of unitProps) {
|
|
|
|
|
const data = stylesheetStore.extractValue(selector.value, prop.css);
|
|
|
|
|
if (data && data.value !== undefined) {
|
|
|
|
|
prop.ref.value = data.value;
|
|
|
|
|
prop.ref.unit = data.unit;
|
|
|
|
|
}
|
2025-12-05 18:21:54 +01:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error loading values from stylesheet:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-08 14:15:06 +01:00
|
|
|
const open = (element, event, count = null) => {
|
2026-01-09 14:31:42 +01:00
|
|
|
isUpdatingFromStore = true;
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
selectedElement.value = element;
|
|
|
|
|
selector.value = getSelectorFromElement(element);
|
|
|
|
|
|
2025-12-08 14:15:06 +01:00
|
|
|
elementInstanceCount.value = count !== null ? count : getInstanceCount(selector.value);
|
|
|
|
|
|
2026-01-09 14:31:42 +01:00
|
|
|
const blockState = stylesheetStore.getBlockState(selector.value);
|
2026-02-26 15:47:58 +01:00
|
|
|
basePopup.value.inheritanceLocked = blockState !== 'active';
|
2026-01-09 14:31:42 +01:00
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
loadValuesFromStylesheet();
|
2026-02-26 15:35:45 +01:00
|
|
|
basePopup.value.open(event);
|
2025-12-05 18:21:54 +01:00
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
nextTick(() => { isUpdatingFromStore = false; });
|
2025-12-05 18:21:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const close = () => {
|
2026-02-26 15:35:45 +01:00
|
|
|
basePopup.value?.close();
|
2025-12-05 18:21:54 +01:00
|
|
|
selector.value = '';
|
|
|
|
|
selectedElement.value = null;
|
2025-12-08 14:15:06 +01:00
|
|
|
emit('close');
|
2025-12-05 18:21:54 +01:00
|
|
|
};
|
|
|
|
|
|
2025-12-08 14:15:06 +01:00
|
|
|
const handleIframeClick = (event, targetElement = null, elementCount = null) => {
|
2025-12-08 12:41:14 +01:00
|
|
|
const element = targetElement || event.target;
|
2025-12-05 18:21:54 +01:00
|
|
|
|
|
|
|
|
if (element.tagName === 'BODY' || element.tagName === 'HTML') {
|
|
|
|
|
close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
if (basePopup.value?.visible) {
|
2025-12-05 18:21:54 +01:00
|
|
|
close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 14:15:06 +01:00
|
|
|
open(element, event, elementCount);
|
2025-12-05 18:21:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toggleInheritance = () => {
|
2026-01-09 14:31:42 +01:00
|
|
|
const blockState = stylesheetStore.getBlockState(selector.value);
|
|
|
|
|
|
2026-02-26 15:35:45 +01:00
|
|
|
if (basePopup.value.inheritanceLocked && blockState === 'commented') {
|
2026-01-09 14:31:42 +01:00
|
|
|
stylesheetStore.uncommentCssBlock(selector.value);
|
2026-02-26 15:35:45 +01:00
|
|
|
basePopup.value.inheritanceLocked = false;
|
|
|
|
|
} else if (basePopup.value.inheritanceLocked && blockState === 'none') {
|
2026-01-09 14:31:42 +01:00
|
|
|
if (selectedElement.value && props.iframeRef && props.iframeRef.contentWindow) {
|
2026-02-26 15:47:58 +01:00
|
|
|
const cs = props.iframeRef.contentWindow.getComputedStyle(selectedElement.value);
|
2026-01-09 14:31:42 +01:00
|
|
|
|
|
|
|
|
isUpdatingFromStore = true;
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
fontFamily.value = cs.fontFamily.replace(/['"]/g, '').split(',')[0].trim();
|
|
|
|
|
italic.value = cs.fontStyle === 'italic';
|
|
|
|
|
fontWeight.value = parseInt(cs.fontWeight);
|
2026-01-09 14:31:42 +01:00
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
const fontSizeMatch = cs.fontSize.match(/([\d.]+)(px|rem|em|pt)/);
|
2026-01-09 14:31:42 +01:00
|
|
|
if (fontSizeMatch) {
|
2026-02-26 15:47:58 +01:00
|
|
|
fontSize.value = parseFloat(fontSizeMatch[1]);
|
|
|
|
|
fontSize.unit = fontSizeMatch[2];
|
2026-01-09 14:31:42 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 17:29:49 +01:00
|
|
|
const lineHeightMatch = cs.lineHeight.match(/([\d.]+)(px|rem|em|pt)/);
|
|
|
|
|
if (lineHeightMatch) {
|
|
|
|
|
lineHeight.value = parseFloat(lineHeightMatch[1]);
|
|
|
|
|
lineHeight.unit = lineHeightMatch[2];
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
textAlign.value = cs.textAlign;
|
|
|
|
|
color.value = cs.color;
|
|
|
|
|
background.value = cs.backgroundColor;
|
2026-01-09 14:31:42 +01:00
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
const marginMatch = cs.marginTop.match(/([\d.]+)(px|mm|pt)/);
|
2026-01-09 14:31:42 +01:00
|
|
|
if (marginMatch) {
|
2026-02-26 15:47:58 +01:00
|
|
|
marginOuter.value = parseFloat(marginMatch[1]);
|
|
|
|
|
marginOuter.unit = marginMatch[2];
|
2026-01-09 14:31:42 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:47:58 +01:00
|
|
|
const paddingMatch = cs.paddingTop.match(/([\d.]+)(px|mm|pt)/);
|
2026-01-09 14:31:42 +01:00
|
|
|
if (paddingMatch) {
|
2026-02-26 15:47:58 +01:00
|
|
|
paddingInner.value = parseFloat(paddingMatch[1]);
|
|
|
|
|
paddingInner.unit = paddingMatch[2];
|
2026-01-09 14:31:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isUpdatingFromStore = false;
|
2025-12-10 12:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-10 12:11:53 +01:00
|
|
|
applyAllStyles();
|
2026-02-26 15:35:45 +01:00
|
|
|
basePopup.value.inheritanceLocked = false;
|
|
|
|
|
} else if (!basePopup.value.inheritanceLocked && blockState === 'active') {
|
2026-01-09 14:31:42 +01:00
|
|
|
stylesheetStore.commentCssBlock(selector.value);
|
2026-02-26 15:35:45 +01:00
|
|
|
basePopup.value.inheritanceLocked = true;
|
2025-12-10 12:04:58 +01:00
|
|
|
}
|
2025-12-05 18:21:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
defineExpose({ handleIframeClick, close, visible });
|
2025-11-24 16:51:55 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2025-12-08 16:17:34 +01:00
|
|
|
/* ElementPopup-specific styles (purple theme) */
|
2025-12-05 18:21:54 +01:00
|
|
|
.element-label {
|
2025-12-08 14:15:06 +01:00
|
|
|
background: var(--color-purple);
|
2025-12-05 18:21:54 +01:00
|
|
|
color: white;
|
|
|
|
|
padding: 0.25rem 0.5rem;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.instance-count {
|
2025-12-08 14:15:06 +01:00
|
|
|
color: var(--color-purple);
|
2025-11-24 16:51:55 +01:00
|
|
|
font-size: 0.875rem;
|
|
|
|
|
}
|
|
|
|
|
</style>
|