Loading src/app/components.d.ts +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ declare module 'vue' { EntitiesList: typeof import('./../modules/sheets/entities/EntitiesList.vue')['default'] EntityItem: typeof import('./../modules/sheets/entities/EntityItem.vue')['default'] EntityPositionSettings: typeof import('./../components/sheets/entities/settings/EntityPositionSettings.vue')['default'] EntitySettingsModalHeader: typeof import('./../components/sheets/entities/settings/common/EntitySettingsModalHeader.vue')['default'] EntityTitle: typeof import('./../components/sheets/entities/share/EntityTitle.vue')['default'] ExitIcon: typeof import('./../shared/icons/ExitIcon.vue')['default'] HamburgerIcon: typeof import('./../shared/icons/HamburgerIcon.vue')['default'] Loading @@ -37,8 +38,10 @@ declare module 'vue' { HorizontalLineIcon: typeof import('./../shared/icons/HorizontalLineIcon.vue')['default'] ImageEditIcon: typeof import('./../shared/icons/ImageEditIcon.vue')['default'] ImageEntity: typeof import('./../modules/sheets/entities/items/ImageEntity.vue')['default'] ImageEntityImageWithText: typeof import('./../components/sheets/entities/content/ImageEntityImageWithText.vue')['default'] ImageIcon: typeof import('./../shared/icons/ImageIcon.vue')['default'] ImageSettings: typeof import('./../components/sheets/entities/settings/ImageSettings.vue')['default'] ImageSettingsEntityBlock: typeof import('./../components/sheets/entities/settings/entityBlock/ImageSettingsEntityBlock.vue')['default'] ImageSettingsList: typeof import('./../components/sheets/entities/settings/lists/ImageSettingsList.vue')['default'] MenuDial: typeof import('./../shared/ui/MenuDial.vue')['default'] Modal: typeof import('./../shared/ui/Modal.vue')['default'] Loading src/app/helpers/entities.ts +4 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import type { IEntity } from '@/app/interfaces/environment'; import { calcImageWidth, checkIsImage } from '@/app/helpers/images'; import { useFilesWebsocketStore } from '@/app/stores/filesWebsocket'; import cookies from '@/app/plugins/Cookie'; import { useWindowSize } from '@vueuse/core'; export const fetchForEntities = (sheet_uuid: string) => { const dataStore = useDataStore(); Loading Loading @@ -42,13 +41,14 @@ export const createEntity = (newEntity: IEntity) => { websocketStore.sendData(data); }; export const addImageOnLoad = async (image, url: string) => { export const addImageOnLoad = async (image, url: string, entitiesCount: number) => { const filesWebsocketStore = useFilesWebsocketStore(); const dataStore = useDataStore(); filesWebsocketStore.saveImageUrl(url); const response = await fetch(url); const blob = await response.blob(); const buffer = await blob.arrayBuffer(); const { width: windowWidth } = useWindowSize(); const windowWidth = computed(() => dataStore.windowWidth); const maxHeight = 1000; const initWidth = image.width; if (image.height > maxHeight) { Loading @@ -58,7 +58,7 @@ export const addImageOnLoad = async (image, url: string) => { const imageWidth = calcImageWidth(image.width, windowWidth.value); createEntity({ entity_type: 'image', entity_order: entitiesCount.value + 1, entity_order: entitiesCount + 1, image_buffer: buffer, entity_position: 'left', entity_title_position: 'center', Loading src/app/helpers/images.ts +28 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ import type { IImage } from '@/app/interfaces/entities'; import { useWebsocketStore } from '@/app/stores/websocket'; import { useInterfaceStore } from '@/app/stores/interface'; import { imageScaleOptions } from '@/components/sheets/entities/settings/lists/constants/options'; import type { IImageMainInfo } from '@/app/interfaces'; export const calcImageWidth = (fileWidth: number, windowWidth: number) => { let imageWidth = Math.ceil((fileWidth / (windowWidth - 128)) * 100); Loading Loading @@ -201,3 +200,31 @@ export const scaleImage = (entityData: IImage, prevScale: string) => { entityData.image_width = Math.ceil(initialWidth * +scale); return entityData; }; export const updateEntityDataTextOnSave = <T>( newEntityData: T, prevEntityData: IEntity, isEntityWidthFull: boolean, isTitle: boolean, isText?: boolean ) => { const paragraphSize = isEntityWidthFull ? 'full' : 'half'; if (paragraphSize !== prevEntityData.paragraph_size) { newEntityData.paragraph_size = paragraphSize; } if (isTitle !== !!prevEntityData.title) { if (isTitle) { newEntityData.title = 'Title'; } else { newEntityData.title = null; } } if (isText !== !!prevEntityData.text) { if (isText) { newEntityData.text = 'Text'; } else { newEntityData.text = null; } } return newEntityData; }; src/app/stores/data.ts +4 −0 Original line number Diff line number Diff line import { defineStore } from 'pinia'; import type { IEntity, ISheetInfo } from '@/app/interfaces/environment'; import cookies from '@/app/plugins/Cookie'; import { useWindowSize } from '@vueuse/core'; export const useDataStore = defineStore('dataStore', () => { const sheets = ref([ Loading Loading @@ -41,6 +42,7 @@ export const useDataStore = defineStore('dataStore', () => { sheetsData.value.find((sheet) => sheet.sheet_uuid === cookies.get('current_sheet_uuid')) ); const entities = ref<IEntity[]>([]); const { width: windowWidth, height: windowHeight } = useWindowSize(); function setCurrentSheetUuid(uuid: string) { cookies.set('current_sheet_uuid', uuid); } Loading @@ -59,6 +61,8 @@ export const useDataStore = defineStore('dataStore', () => { ); } return { windowWidth, windowHeight, sheets, entities, sheetsData, Loading src/components/common/CreateEntityMenu.vue +2 −5 Original line number Diff line number Diff line <script setup lang="ts"> import { useFileDialog, useWindowSize } from '@vueuse/core'; import { useFileDialog } from '@vueuse/core'; import { useAuthorizationStore } from '@/app/stores/authorization'; import { useFilesWebsocketStore } from '@/app/stores/filesWebsocket'; import { useDataStore } from '@/app/stores/data'; import cookies from '@/app/plugins/Cookie'; import { calcImageWidth } from '@/app/helpers/images'; import { addImageOnLoad, createEntity } from '@/app/helpers/entities'; const { open: uploadFile, onChange } = useFileDialog({ Loading @@ -25,8 +23,7 @@ const addImage = async (files: FileList) => { const url = URL.createObjectURL(files[0]); image.src = url; image.onload = async () => { // TODO посмотреть, работает ли корректно вынос функции await addImageOnLoad(image, url); await addImageOnLoad(image, url, entitiesCount.value); }; }; onChange((files) => { Loading Loading
src/app/components.d.ts +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ declare module 'vue' { EntitiesList: typeof import('./../modules/sheets/entities/EntitiesList.vue')['default'] EntityItem: typeof import('./../modules/sheets/entities/EntityItem.vue')['default'] EntityPositionSettings: typeof import('./../components/sheets/entities/settings/EntityPositionSettings.vue')['default'] EntitySettingsModalHeader: typeof import('./../components/sheets/entities/settings/common/EntitySettingsModalHeader.vue')['default'] EntityTitle: typeof import('./../components/sheets/entities/share/EntityTitle.vue')['default'] ExitIcon: typeof import('./../shared/icons/ExitIcon.vue')['default'] HamburgerIcon: typeof import('./../shared/icons/HamburgerIcon.vue')['default'] Loading @@ -37,8 +38,10 @@ declare module 'vue' { HorizontalLineIcon: typeof import('./../shared/icons/HorizontalLineIcon.vue')['default'] ImageEditIcon: typeof import('./../shared/icons/ImageEditIcon.vue')['default'] ImageEntity: typeof import('./../modules/sheets/entities/items/ImageEntity.vue')['default'] ImageEntityImageWithText: typeof import('./../components/sheets/entities/content/ImageEntityImageWithText.vue')['default'] ImageIcon: typeof import('./../shared/icons/ImageIcon.vue')['default'] ImageSettings: typeof import('./../components/sheets/entities/settings/ImageSettings.vue')['default'] ImageSettingsEntityBlock: typeof import('./../components/sheets/entities/settings/entityBlock/ImageSettingsEntityBlock.vue')['default'] ImageSettingsList: typeof import('./../components/sheets/entities/settings/lists/ImageSettingsList.vue')['default'] MenuDial: typeof import('./../shared/ui/MenuDial.vue')['default'] Modal: typeof import('./../shared/ui/Modal.vue')['default'] Loading
src/app/helpers/entities.ts +4 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import type { IEntity } from '@/app/interfaces/environment'; import { calcImageWidth, checkIsImage } from '@/app/helpers/images'; import { useFilesWebsocketStore } from '@/app/stores/filesWebsocket'; import cookies from '@/app/plugins/Cookie'; import { useWindowSize } from '@vueuse/core'; export const fetchForEntities = (sheet_uuid: string) => { const dataStore = useDataStore(); Loading Loading @@ -42,13 +41,14 @@ export const createEntity = (newEntity: IEntity) => { websocketStore.sendData(data); }; export const addImageOnLoad = async (image, url: string) => { export const addImageOnLoad = async (image, url: string, entitiesCount: number) => { const filesWebsocketStore = useFilesWebsocketStore(); const dataStore = useDataStore(); filesWebsocketStore.saveImageUrl(url); const response = await fetch(url); const blob = await response.blob(); const buffer = await blob.arrayBuffer(); const { width: windowWidth } = useWindowSize(); const windowWidth = computed(() => dataStore.windowWidth); const maxHeight = 1000; const initWidth = image.width; if (image.height > maxHeight) { Loading @@ -58,7 +58,7 @@ export const addImageOnLoad = async (image, url: string) => { const imageWidth = calcImageWidth(image.width, windowWidth.value); createEntity({ entity_type: 'image', entity_order: entitiesCount.value + 1, entity_order: entitiesCount + 1, image_buffer: buffer, entity_position: 'left', entity_title_position: 'center', Loading
src/app/helpers/images.ts +28 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ import type { IImage } from '@/app/interfaces/entities'; import { useWebsocketStore } from '@/app/stores/websocket'; import { useInterfaceStore } from '@/app/stores/interface'; import { imageScaleOptions } from '@/components/sheets/entities/settings/lists/constants/options'; import type { IImageMainInfo } from '@/app/interfaces'; export const calcImageWidth = (fileWidth: number, windowWidth: number) => { let imageWidth = Math.ceil((fileWidth / (windowWidth - 128)) * 100); Loading Loading @@ -201,3 +200,31 @@ export const scaleImage = (entityData: IImage, prevScale: string) => { entityData.image_width = Math.ceil(initialWidth * +scale); return entityData; }; export const updateEntityDataTextOnSave = <T>( newEntityData: T, prevEntityData: IEntity, isEntityWidthFull: boolean, isTitle: boolean, isText?: boolean ) => { const paragraphSize = isEntityWidthFull ? 'full' : 'half'; if (paragraphSize !== prevEntityData.paragraph_size) { newEntityData.paragraph_size = paragraphSize; } if (isTitle !== !!prevEntityData.title) { if (isTitle) { newEntityData.title = 'Title'; } else { newEntityData.title = null; } } if (isText !== !!prevEntityData.text) { if (isText) { newEntityData.text = 'Text'; } else { newEntityData.text = null; } } return newEntityData; };
src/app/stores/data.ts +4 −0 Original line number Diff line number Diff line import { defineStore } from 'pinia'; import type { IEntity, ISheetInfo } from '@/app/interfaces/environment'; import cookies from '@/app/plugins/Cookie'; import { useWindowSize } from '@vueuse/core'; export const useDataStore = defineStore('dataStore', () => { const sheets = ref([ Loading Loading @@ -41,6 +42,7 @@ export const useDataStore = defineStore('dataStore', () => { sheetsData.value.find((sheet) => sheet.sheet_uuid === cookies.get('current_sheet_uuid')) ); const entities = ref<IEntity[]>([]); const { width: windowWidth, height: windowHeight } = useWindowSize(); function setCurrentSheetUuid(uuid: string) { cookies.set('current_sheet_uuid', uuid); } Loading @@ -59,6 +61,8 @@ export const useDataStore = defineStore('dataStore', () => { ); } return { windowWidth, windowHeight, sheets, entities, sheetsData, Loading
src/components/common/CreateEntityMenu.vue +2 −5 Original line number Diff line number Diff line <script setup lang="ts"> import { useFileDialog, useWindowSize } from '@vueuse/core'; import { useFileDialog } from '@vueuse/core'; import { useAuthorizationStore } from '@/app/stores/authorization'; import { useFilesWebsocketStore } from '@/app/stores/filesWebsocket'; import { useDataStore } from '@/app/stores/data'; import cookies from '@/app/plugins/Cookie'; import { calcImageWidth } from '@/app/helpers/images'; import { addImageOnLoad, createEntity } from '@/app/helpers/entities'; const { open: uploadFile, onChange } = useFileDialog({ Loading @@ -25,8 +23,7 @@ const addImage = async (files: FileList) => { const url = URL.createObjectURL(files[0]); image.src = url; image.onload = async () => { // TODO посмотреть, работает ли корректно вынос функции await addImageOnLoad(image, url); await addImageOnLoad(image, url, entitiesCount.value); }; }; onChange((files) => { Loading