Skip to content
Snippets Groups Projects
ParagraphItem.vue 2.91 KiB
Newer Older
import { useTextareaAutosize } from '@vueuse/core';
import type { IParagraph } from '@/app/interfaces/entities';
malyusgun's avatar
malyusgun committed
import { editEntity } from '@/app/helpers';
import { useDataStore } from '@/app/stores/data';
import type { IEntity } from '@/app/interfaces/environment';
  entityData: IParagraph;
}
const props = defineProps<Props>();
const entityData = ref(props.entityData);

const dataStore = useDataStore();
const entities = computed(() => dataStore.entities);
const entityIndex = computed(() =>
  entities.value.findIndex((entity: IEntity) => entity.entity_uuid === props.entityData.entity_uuid)
);
const entitiesLength = computed(() => entities.value.length);

malyusgun's avatar
malyusgun committed
  editEntity({ ...entityData.value, title: entityData.value.title });
malyusgun's avatar
malyusgun committed
  editEntity({ ...entityData.value, text: entityData.value.text });
const saveChanges = (newState: IParagraph) => {
  editEntity(newState);
  entityData.value = newState;
};
const { textarea, triggerResize } = useTextareaAutosize({ styleProp: 'minHeight' });
      'entityContainer relative flex 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'
        }
      ]"
malyusgun's avatar
malyusgun committed
      <EntityTitle
        v-model:title="entityData.title"
        :entityData="entityData"
        :isEditMode="isEditMode"
malyusgun's avatar
malyusgun committed
        @editTitle="editTitle"
      />
      <div class="relative leading-none">
        <textarea
          ref="textarea"
          v-model="entityData.text"
          :class="[
            'w-full indent-5 leading-normal resize-none outline-0',
            {
              'pointer-events-none': !isEditMode
            }
          ]"
          :style="`font-size: ${entityData.font_size}px;`"
          placeholder="Enter text..."
malyusgun's avatar
malyusgun committed
          @change="editText"
          @input="triggerResize"
      <ParagraphSettings v-if="isEditMode" :entityData="entityData" @saveChanges="saveChanges" />
      <EntityPositionSettings
        v-if="isEditMode && entitiesLength > 1"
        :entityUuid="entityData.entity_uuid"
        :entityIndex="entityIndex"
        :entitiesLength="entitiesLength"
      />
malyusgun's avatar
malyusgun committed
<style>
.entityContainer:hover .aggregateHigh {
  height: 140px;
}
.entityContainer:hover .aggregateMedium {
  height: 80px;
}
.entityContainer:hover .aggregateShort {
  height: 35px;
input::placeholder {
  font-weight: 400;
}