From 2023d7e9f6d2e7a3dc3a80b99546b2a1a5ecceb2 Mon Sep 17 00:00:00 2001 From: Anton Reshetov Date: Thu, 7 Dec 2023 09:33:51 +0300 Subject: [PATCH] refactor: add separate components (#20) --- src/components/email-components/EDivider.vue | 28 +++++++ src/components/email-components/EImg.vue | 33 +++++++++ src/components/email-components/EMenu.vue | 56 ++++++++++++++ src/components/email-components/ESocial.vue | 51 +++++++++++++ .../email-components/menu/Menu1.vue | 40 ++++------ .../email-components/menu/Menu2.vue | 74 ++++++++----------- .../email-components/menu/Menu3.vue | 36 ++++----- .../email-components/menu/Menu4.vue | 49 ++++++------ .../menu/components/MenuItems.vue | 47 ------------ .../menu/components/MenuItemsImg.vue | 42 ----------- .../menu/composables/common.ts | 40 +++++----- .../menu/composables/menu-2.ts | 25 +++---- .../menu/composables/menu-3.ts | 23 +++++- src/store/components/utils.ts | 4 +- src/types/email-components/components.d.ts | 16 +++- src/types/email-components/menu.d.ts | 20 ----- 16 files changed, 313 insertions(+), 271 deletions(-) create mode 100644 src/components/email-components/EDivider.vue create mode 100644 src/components/email-components/EImg.vue create mode 100644 src/components/email-components/EMenu.vue create mode 100644 src/components/email-components/ESocial.vue delete mode 100644 src/components/email-components/menu/components/MenuItems.vue delete mode 100644 src/components/email-components/menu/components/MenuItemsImg.vue delete mode 100644 src/types/email-components/menu.d.ts diff --git a/src/components/email-components/EDivider.vue b/src/components/email-components/EDivider.vue new file mode 100644 index 0000000..e2beeb8 --- /dev/null +++ b/src/components/email-components/EDivider.vue @@ -0,0 +1,28 @@ + + + + + diff --git a/src/components/email-components/EImg.vue b/src/components/email-components/EImg.vue new file mode 100644 index 0000000..6e17adb --- /dev/null +++ b/src/components/email-components/EImg.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/src/components/email-components/EMenu.vue b/src/components/email-components/EMenu.vue new file mode 100644 index 0000000..e533079 --- /dev/null +++ b/src/components/email-components/EMenu.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/src/components/email-components/ESocial.vue b/src/components/email-components/ESocial.vue new file mode 100644 index 0000000..d0cb091 --- /dev/null +++ b/src/components/email-components/ESocial.vue @@ -0,0 +1,51 @@ + + + + + diff --git a/src/components/email-components/menu/Menu1.vue b/src/components/email-components/menu/Menu1.vue index db7dc09..fef6ca0 100644 --- a/src/components/email-components/menu/Menu1.vue +++ b/src/components/email-components/menu/Menu1.vue @@ -5,41 +5,29 @@ @click.self="onEditTool('Layout', index)" > - - - - - - + - - + /> diff --git a/src/components/email-components/menu/Menu2.vue b/src/components/email-components/menu/Menu2.vue index 059a019..aac068e 100644 --- a/src/components/email-components/menu/Menu2.vue +++ b/src/components/email-components/menu/Menu2.vue @@ -4,58 +4,42 @@ :index="index" @click.self="onEditTool('Layout', index)" > - - - - - - + + - - - - - + /> - - - + diff --git a/src/components/email-components/menu/Menu3.vue b/src/components/email-components/menu/Menu3.vue index 2a95a71..cb0fe26 100644 --- a/src/components/email-components/menu/Menu3.vue +++ b/src/components/email-components/menu/Menu3.vue @@ -5,37 +5,29 @@ @click.self="onEditTool('Layout', index)" > - - - - - - + - - + /> diff --git a/src/components/email-components/menu/Menu4.vue b/src/components/email-components/menu/Menu4.vue index 25824bd..b5ac3d9 100644 --- a/src/components/email-components/menu/Menu4.vue +++ b/src/components/email-components/menu/Menu4.vue @@ -5,40 +5,32 @@ @click.self="onEditTool('Layout', index)" > - - - - - + /> - - - - + + diff --git a/src/components/email-components/menu/components/MenuItems.vue b/src/components/email-components/menu/components/MenuItems.vue deleted file mode 100644 index a1ce7a0..0000000 --- a/src/components/email-components/menu/components/MenuItems.vue +++ /dev/null @@ -1,47 +0,0 @@ - - - - - diff --git a/src/components/email-components/menu/components/MenuItemsImg.vue b/src/components/email-components/menu/components/MenuItemsImg.vue deleted file mode 100644 index 2b35352..0000000 --- a/src/components/email-components/menu/components/MenuItemsImg.vue +++ /dev/null @@ -1,42 +0,0 @@ - - - - - diff --git a/src/components/email-components/menu/composables/common.ts b/src/components/email-components/menu/composables/common.ts index 7272058..91e0523 100644 --- a/src/components/email-components/menu/composables/common.ts +++ b/src/components/email-components/menu/composables/common.ts @@ -15,7 +15,7 @@ import { getValueFromToolsByGroupByName, getValueFromToolsByName, } from '@/store/components/utils' -import type { MenuItemImg, MenuItemText } from '@/types/email-components/menu' +import type { Menu } from '@/types/email-components/components' export function useCommon(tools: Tool[]) { const toolsByGroup = computed(() => getToolsByGroup(tools)) @@ -71,6 +71,19 @@ export function useCommon(tools: Tool[]) { return getValueFromToolsByGroupByName(toolsByGroup.value, 'Menu', 'Align') }) + const menuPadding = computed(() => { + const _padding = getValueFromToolsByGroupByName( + toolsByGroup.value, + 'Menu', + 'Padding', + ) + const padding = _padding?.map(i => `${i}px`).join(' ') + + return { + padding, + } as CSSStyleDeclaration + }) + const isShowMenu = computed(() => { return getValueFromToolsByGroupByName(toolsByGroup.value, 'Menu', 'Show / Hide') }) @@ -79,7 +92,7 @@ export function useCommon(tools: Tool[]) { return getValueFromToolsByGroupByName(toolsByGroup.value, 'Logo', 'Show / Hide') }) - const itemsText = computed(() => { + const menuItems = computed(() => { const items = getValueFromToolsByGroupByName(toolsByGroup.value, 'Menu', 'List') return items?.map((i) => { @@ -89,31 +102,20 @@ export function useCommon(tools: Tool[]) { color: getValueFromToolsByName(i.tools, 'Color'), fontSize: getValueFromToolsByName(i.tools, 'Font Size'), } - }) as MenuItemText[] - }) - - const itemsImg = computed(() => { - const items = getValueFromToolsByGroupByName(toolsByGroup.value, 'Social', 'List') - - return items?.map((i) => { - return { - image: getValueFromToolsByName(i.tools, 'Image'), - link: getValueFromToolsByName(i.tools, 'Link'), - } - }) as MenuItemImg[] + }) as Menu[] }) return { - layoutBackground, isShowLogo, isShowMenu, - itemsImg, - itemsText, + menuItems, layoutAttrs, + layoutBackground, + logoAlign, logoAttrs, logoImage, - toolsByGroup, menuAlign, - logoAlign, + menuPadding, + toolsByGroup, } } diff --git a/src/components/email-components/menu/composables/menu-2.ts b/src/components/email-components/menu/composables/menu-2.ts index 152482d..b3c0fdd 100644 --- a/src/components/email-components/menu/composables/menu-2.ts +++ b/src/components/email-components/menu/composables/menu-2.ts @@ -14,34 +14,27 @@ export function useMenu2(tools: Tool[]) { ) }) - const dividerColorPadding = computed(() => { - return getValueFromToolsByGroupByName( + const dividerPadding = computed(() => { + const _padding = getValueFromToolsByGroupByName( common.toolsByGroup.value, 'Divider', 'Padding', ) + const padding = _padding?.map(i => `${i}px`).join(' ') + + return { + padding, + } as CSSStyleDeclaration }) const isShowDivider = computed(() => { return getValueFromToolsByGroupByName(common.toolsByGroup.value, 'Divider', 'Show / Hide') }) - const dividerAttrs = computed(() => { - return { - style: { - borderColor: dividerColor.value, - margin: dividerColorPadding.value - ?.map((i, index) => { - return index % 2 === 0 ? `${i}px` : 0 - }) - .join(' '), - }, - } as HTMLElement - }) - return { ...common, - dividerAttrs, + dividerColor, + dividerPadding, isShowDivider, } } diff --git a/src/components/email-components/menu/composables/menu-3.ts b/src/components/email-components/menu/composables/menu-3.ts index b72c206..59f1143 100644 --- a/src/components/email-components/menu/composables/menu-3.ts +++ b/src/components/email-components/menu/composables/menu-3.ts @@ -1,7 +1,12 @@ import { computed } from 'vue' import { useCommon } from './common' -import type { AlignTool, ColorPickerTool, PaddingTool, Tool } from '@/types/editor' -import { getToolsByGroup, getValueFromToolsByGroupByName } from '@/store/components/utils' +import type { AlignTool, ImageTool, InputTool, MultiTool, Tool } from '@/types/editor' +import { + getToolsByGroup, + getValueFromToolsByGroupByName, + getValueFromToolsByName, +} from '@/store/components/utils' +import type { Social } from '@/types/email-components/components' export function useMenu3(tools: Tool[]) { const common = useCommon(tools) @@ -16,9 +21,21 @@ export function useMenu3(tools: Tool[]) { return getValueFromToolsByGroupByName(toolsByGroup.value, 'Social', 'Align') }) + const socialItems = computed(() => { + const items = getValueFromToolsByGroupByName(toolsByGroup.value, 'Social', 'List') + + return items?.map((i) => { + return { + image: getValueFromToolsByName(i.tools, 'Image'), + link: getValueFromToolsByName(i.tools, 'Link'), + } + }) as Social[] + }) + return { ...common, - socialAlign, isShowSocial, + socialAlign, + socialItems, } } diff --git a/src/store/components/utils.ts b/src/store/components/utils.ts index 2c288d9..1f187da 100644 --- a/src/store/components/utils.ts +++ b/src/store/components/utils.ts @@ -28,9 +28,9 @@ export function getValueFromToolsByName(tools: Too const value = tools.find(i => i.label === name)?.value if (!value) - return console.warn(`Could not find tool with name "${name}"`) + console.warn(`Could not find tool with name "${name}"`) - return value as T['value'] | undefined + return (value as T['value']) || undefined } export function getValueFromToolsByGroupByName( diff --git a/src/types/email-components/components.d.ts b/src/types/email-components/components.d.ts index dc9a3e1..50cee63 100644 --- a/src/types/email-components/components.d.ts +++ b/src/types/email-components/components.d.ts @@ -1,6 +1,18 @@ -import type { Component } from '../editor' +import type { Component, ImageTool } from '../editor' -interface ComponentList { +export interface ComponentList { name: string components: Component[] } + +export interface Menu { + color: string + fontSize: number | string + text: string + link: string +} + +export interface Social { + image: ImageTool['value'] + link: string +} diff --git a/src/types/email-components/menu.d.ts b/src/types/email-components/menu.d.ts deleted file mode 100644 index 78e638a..0000000 --- a/src/types/email-components/menu.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { ImageTool } from '../editor' - -export interface Menu { - color: string - fontSize: number | string - text: string - link: string -} - -export interface MenuItemText { - color: string - fontSize: number | string - text: string - link: string -} - -export interface MenuItemImg { - image: ImageTool['value'] - link: string -}