Newer
Older

Дмитрий Малюгин
committed
<script setup lang="ts">
import type { IText } from '@/app/interfaces/entities';
import { useDataStore } from '@/app/stores/data';
import { deleteEntity, editEntity } from '@/app/helpers';
import StateMenu from '@/components/editEntityMenu/TextStateMenu.vue';
import PositionMenu from '@/components/editEntityMenu/TextPositionMenu.vue';
import FontMenu from '@/components/editEntityMenu/TextFontMenu.vue';

Дмитрий Малюгин
committed
interface Props {
entityData: IText;
}
const props = defineProps<Props>();
const entityData = ref(props.entityData);
const addTitle = () => {
editEntity(
{ ...entityData.value, title: 'Title', entity_title_position: 'center' },
entityData.value.entity_uuid
);
entityData.value = { ...entityData.value, title: 'Title', entity_title_position: 'center' };

Дмитрий Малюгин
committed
};
const editTitle = () => {
editEntity({ ...entityData.value, title: entityData.value.title }, entityData.value.entity_uuid);

Дмитрий Малюгин
committed
};
const editText = () => {
editEntity({ ...entityData.value, text: entityData.value.text }, entityData.value.entity_uuid);

Дмитрий Малюгин
committed
};
newState.title = null;
editEntity({ ...newState }, entityData.value.entity_uuid);
const { textarea, triggerResize } = useTextareaAutosize({ styleProp: 'minHeight' });
const dataStore = useDataStore();
const homeEntities = computed(() => dataStore.homeEntities);
function editPosition(position: 'left' | 'center' | 'right') {
entityData.value.entity_position = position;
editEntity({ ...entityData.value, entity_position: position }, entityData.value.entity_uuid);
}
function editTitlePosition(position: 'left' | 'center' | 'right') {
entityData.value.entity_title_position = position;
editEntity(
{ ...entityData.value, entity_title_position: position },
entityData.value.entity_uuid
);
}
function changeFontSize(newSize: '16' | '20' | '24' | '40' | '64') {
entityData.value.font_size = newSize;
editEntity({ ...entityData.value, font_size: newSize }, entityData.value.entity_uuid);
}
function editParagraphWidth(widthMode: 'full' | 'half') {
entityData.value.paragraph_size = widthMode;
editEntity({ ...entityData.value, paragraph_size: widthMode }, entityData.value.entity_uuid);
}

Дмитрий Малюгин
committed
</script>
<template>
<div
:class="[
'entityContainer relative flex py-8 px-16',
{
'justify-start': entityData.entity_position === 'left',
'justify-center': entityData.entity_position === 'center',
'justify-end': entityData.entity_position === 'right'
}
]"
>
:class="[
{
'w-1/2': entityData.paragraph_size === 'half',
'w-full': entityData.paragraph_size === 'full'
}
]"
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<input
ref="input"
v-if="entityData.title || entityData.title === ''"
type="text"
v-model="entityData.title"
@change="editTitle"
placeholder="Enter title..."
:style="`font-size: ${+entityData.font_size + 10}px`"
:class="[
'w-full mb-4 font-bold text-6xl pl-2',
{
'text-center': entityData.entity_title_position === 'center',
'text-end': entityData.entity_title_position === 'right'
}
]"
/>
<div class="relative leading-none">
<textarea
ref="textarea"
v-model="entityData.text"
class="w-full indent-5 leading-normal resize-none outline-0"
:style="`font-size: ${entityData.font_size}px;`"
@change="editText"
@input="triggerResize"
placeholder="Enter text..."
rows="3"
spellcheck="false"
/>
</div>
<div class="speedDial absolute left-2 top-0 transition-all select-none">
<StateMenu
:entityData="entityData"
@deleteEntity="deleteEntity"
@addTitle="addTitle"
@removeTitle="removeTitle"
/>
</div>
<div
class="speedDial h-12 absolute left-2 top-1/2 -translate-y-1/2 transition-all select-none"
>
<FontMenu :entityData="entityData" @changeFontSize="changeFontSize" />
</div>
<div
v-if="homeEntities.length > 1"
class="speedDial absolute left-2 bottom-0 transition-all select-none"
>
<PositionMenu
:entityData="entityData"
@editPosition="editPosition"
@editTitlePosition="editTitlePosition"
@editParagraphWidth="editParagraphWidth"
/>
</div>

Дмитрий Малюгин
committed
</div>
</template>
<style scoped>
textarea {
-ms-overflow-style: none;
scrollbar-width: none;
}
textarea::-webkit-scrollbar {
display: none;
}
.entityContainer .speedDial {

Дмитрий Малюгин
committed
opacity: 0;
}
.entityContainer:hover .speedDial {

Дмитрий Малюгин
committed
opacity: 100;
}
input::placeholder {
font-weight: 400;
}