Skip to content

Commit

Permalink
feat(pdf): line-break command settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Jan 19, 2022
1 parent 9170efe commit 9defd85
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<PDFConfigurationSetHeadingOne />
<PDFConfigurationSetHeadingTwo />
<PDFConfigurationSetHeadingThree />
<PDFConfigurationSetLineBreak />
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
<PDFConfigurationSlot>
<template #title>
<section class="flex gap-2">
<h2 class="text-2xl ml-2 font-bold font-poppins">
{{ t('editor.pdf.custom.generics.lineBreak') }}
</h2>
</section>
</template>
<div
class="flex flex-row flex-wrap justify-start items-center my-3 overflow-x-hidden gap-5"
>
<div class="wb-input-container">
<label class="mx-2 text-xs">{{
t('editor.pdf.lineBreak.spacing')
}}</label>
<InputNumber v-model="pdf.lineBreak.spacing" />
</div>
<div class="wb-input-container">
<label class="mx-2 text-xs">{{
t('editor.pdf.lineBreak.active')
}}</label>
<InputBoolean v-model="pdf.lineBreak.image.active" />
</div>
<div
:class="[!pdf.lineBreak.image.active ? 'wb-disabled' : '']"
class="wb-input-container"
>
<label class="mx-2 text-xs">{{ t('editor.pdf.cover.type') }}</label>
<InputFile
id="main-background"
:title="t('generics.input.image')"
:src="pdf.lineBreak.image.data"
@load="onMainImageLoad"
@exclude="onDeleteMainImage"
/>
</div>
<div
:class="[!pdf.lineBreak.image.active ? 'wb-disabled' : '']"
class="wb-input-container"
>
<label class="mx-2 text-xs">{{ t('editor.pdf.lineBreak.size') }}</label>
<section>
<label>{{ t('editor.pdf.custom.image.width') }}</label>
<InputNumber v-model="pdf.lineBreak.image.width" :step="25" />
</section>
<section>
<label>{{ t('editor.pdf.custom.image.height') }}</label>
<InputNumber v-model="pdf.lineBreak.image.height" :step="25" />
</section>
</div>
</div>
</PDFConfigurationSlot>
</template>

<script setup lang="ts">
import { usePDFStore } from '@/store/pdf'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
const PDF = usePDFStore()
const { t } = useI18n()
const pdf = computed(() => PDF.styles)
const onMainImageLoad = (e: any) => {
PDF.styles.lineBreak.image.data = e
}
const onDeleteMainImage = () => {
PDF.styles.lineBreak.image.data = ''
}
</script>
9 changes: 9 additions & 0 deletions packages/better-write-app/src/use/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ export const usePopulate = () => {
bottom: 15 as number,
},
},
lineBreak: {
spacing: 10,
image: {
data: '',
active: false,
width: 50,
height: 50,
},
},
switcher: {
cover: false,
main: false,
Expand Down
12 changes: 12 additions & 0 deletions packages/better-write-app/src/use/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ export const useStorage = () => {
})
})

if (!_.pdf.styles.lineBreak) {
_.pdf.styles.lineBreak = {
spacing: 10,
image: {
data: '',
active: false,
width: 50,
height: 50,
},
}
}

return _
}

Expand Down
12 changes: 12 additions & 0 deletions packages/better-write-plugin-pdf/src/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export const setPDFI18n = () => {
fontFamily: 'Fonte',
},
},
lineBreak: {
spacing: 'Espaçamento',
active: 'Usar Imagem',
size: 'Tamanho',
},
custom: {
image: {
height: 'Altura',
Expand Down Expand Up @@ -115,6 +120,7 @@ export const setPDFI18n = () => {
decorationStyle: 'Estilo da Decoração',
decorationColor: 'Cor da Decoração',
breakPage: 'Quebra de Página',
lineBreak: 'Quebra de Linha',
},
save: 'Salvar',
},
Expand Down Expand Up @@ -234,6 +240,11 @@ export const setPDFI18n = () => {
fontFamily: 'Fonte',
},
},
lineBreak: {
spacing: 'Spacing',
active: 'Use Image',
size: 'Size',
},
custom: {
image: {
height: 'Height',
Expand Down Expand Up @@ -263,6 +274,7 @@ export const setPDFI18n = () => {
decorationStyle: 'Decoration Style',
decorationColor: 'Decoration Color',
breakPage: 'Break Page',
lineBreak: 'Line Break',
},
save: 'Save',
},
Expand Down
40 changes: 37 additions & 3 deletions packages/better-write-plugin-pdf/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,44 @@ export const PluginPDFSet = (
}
}

const lineBreak = (value = 10) => {
const lineBreak = (fixed: boolean = true) => {
if (
stores.PDF.styles.lineBreak.image.data &&
stores.PDF.styles.lineBreak.image.active &&
fixed
) {
if (stores.PDF.styles.lineBreak.image.data.startsWith('<svg')) {
return {
svg: stores.PDF.styles.lineBreak.image.data,
width: stores.PDF.styles.lineBreak.image.width,
height: stores.PDF.styles.lineBreak.image.height,
alignment: 'center',
margin: [
0,
stores.PDF.styles.lineBreak.spacing,
0,
stores.PDF.styles.lineBreak.spacing,
],
}
}

return {
image: stores.PDF.styles.lineBreak.image.data,
width: stores.PDF.styles.lineBreak.image.width,
height: stores.PDF.styles.lineBreak.image.height,
alignment: 'center',
margin: [
0,
stores.PDF.styles.lineBreak.spacing,
0,
stores.PDF.styles.lineBreak.spacing,
],
}
}

return {
text: '',
margin: [0, value],
margin: [0, stores.PDF.styles.lineBreak.spacing],
style: 'line-break',
}
}
Expand Down Expand Up @@ -403,7 +437,7 @@ export const PluginPDFSet = (
let _raw = {}

if (entity.raw === hooks.env.emptyLine()) {
_raw = lineBreak(5)
_raw = lineBreak(false)
arr.push(_raw)
return
}
Expand Down
13 changes: 13 additions & 0 deletions packages/better-write-types/src/types/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface PDFStateStyles {
headingOne: PDFStateStylesHeading
headingTwo: PDFStateStylesHeading
headingThree: PDFStateStylesHeading
lineBreak: PDFStateStylesLineBreak
switcher: PDFStateStylesSwitcher
}

Expand Down Expand Up @@ -93,6 +94,18 @@ export interface PDFStateStylesHeading {
}
}

export interface PDFStateStylesLineBreakImage {
data: string
active: boolean
width: number
height: number
}

export interface PDFStateStylesLineBreak {
spacing: number
image: PDFStateStylesLineBreakImage
}

export interface PDFStateStylesSwitcher {
cover: boolean
main: boolean
Expand Down

0 comments on commit 9defd85

Please sign in to comment.