Skip to content

Commit

Permalink
fix(editor): empty lines ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 14, 2021
1 parent adab017 commit 07728f0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VITE_PROJECT_EMPTY=__NOT_CREATED__
VITE_LOCAL_STORAGE=__BETTER_WRITE__
VITE_EMPTY_LINE=__EMPTY_LINE__

VITE_GOOGLE_FONTS_KEY=AIzaSyCdyHpD96473nUqsp16vcQocd7HC8WdtNE
VITE_GOOGLE_FONTS_MAX_FONTS=100
Expand Down
26 changes: 18 additions & 8 deletions src/components/editor/entity/EditorEntityShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
props.entity.type === 'line-break'
? 'cursor-default my-4 border-b-8 border-dashed border-gray-400 dark:border-gray-800'
: '',
props.entity.raw === env.emptyLine()
? 'cursor-default py-4 bg-white-opacity dark:bg-black-opacity'
: '',
]"
@click="onEdit"
v-html="useRaw().convert(props.entity as any)"
Expand Down Expand Up @@ -141,6 +145,7 @@
import { useScroll } from '@/use/scroll'
import { useInput } from '@/use/input'
import { useFormat } from '@/use/format'
import { useEnv } from '@/use/env'
const props = defineProps({
entity: {
Expand All @@ -152,6 +157,7 @@
const store = useStore()
const emitter = useEmitter()
const format = useFormat()
const env = useEnv()
const hover = ref(false)
const edit = ref(false)
Expand All @@ -168,7 +174,7 @@
if (_edit) {
input.value?.focus()
props.entity.raw === '-'
props.entity.raw === env.emptyLine()
? (data.value = '')
: (data.value = props.entity.raw)
Expand Down Expand Up @@ -274,16 +280,20 @@
})
} else {
if (_input.selectionStart === 0) {
data.value = '-'
data.value = env.emptyLine() as string
store.commit('context/newInPagePosEdit', {
entity: props.entity,
type: 'paragraph',
raw: env.emptyLine(),
})
} else {
data.value = data.value.replace(posRaw, '')
store.commit('context/newInPagePosEdit', {
entity: props.entity,
type: 'paragraph',
raw: posRaw,
})
}
store.commit('context/newInPagePosEdit', {
entity: props.entity,
type: 'paragraph',
raw: posRaw,
})
}
await nextTick
Expand Down
5 changes: 3 additions & 2 deletions src/store/module/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContextState, ContextStatePageContent } from '@/types/context'
import { useEnv } from '@/use/env'
import { useFormat } from '@/use/format'

export default {
Expand Down Expand Up @@ -73,7 +74,7 @@ export default {

state.entity.splice(index, 0, {
type: payload.type as string,
raw: '-',
raw: useEnv().emptyLine(),
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
} as ContextStatePageContent)
Expand All @@ -88,7 +89,7 @@ export default {

state.entity.splice(index + 1, 0, {
type: payload.type as string,
raw: payload.raw || '-',
raw: payload.raw || useEnv().emptyLine(),
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
} as ContextStatePageContent)
Expand Down
5 changes: 5 additions & 0 deletions src/use/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const useEnv = () => {
return import.meta.env.MODE === 'production'
}

const emptyLine = () => {
return import.meta.env.VITE_EMPTY_LINE
}

return {
dropboxKey,
projectEmpty,
Expand All @@ -39,5 +43,6 @@ export const useEnv = () => {
maxFonts,
production,
getCorrectLocalUrl,
emptyLine,
}
}
19 changes: 11 additions & 8 deletions src/use/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const usePDF = () => {
const store = useStore()
const toast = useToast()
const emitter = useEmitter()
const env = useEnv()
const { t } = useI18n()

const init: Callback<any> = async () => {
Expand Down Expand Up @@ -221,6 +222,8 @@ export const usePDF = () => {
page.entity.forEach((entity: ContextStatePageContent) => {
let _raw = {}

if (entity.raw === env.emptyLine()) return

if ((entity as any).type === 'paragraph') {
_raw = paragraph((entity as any).raw, {
stack: false,
Expand Down Expand Up @@ -397,26 +400,26 @@ export const usePDF = () => {

const doc = (options: Record<any, any>) => {
return {
pageSize: generate().base(store).pageSize,
pageOrientation: generate().base(store).pageOrientation,
pageSize: generate().base().pageSize,
pageOrientation: generate().base().pageOrientation,
pageMargins: {
left: 0,
top: 0,
right: 0,
bottom: generate().base(store).pageMargins[3],
bottom: generate().base().pageMargins[3],
},
info: {
title: store.state.project.name,
author: 'TODO',
subject: store.state.project.subject,
keywords: '',
},
content: generate().content(store),
content: generate().content(),
styles: {
'heading-three': generate().styles(store).headingThree(),
'heading-two': generate().styles(store).headingTwo(),
'heading-one': generate().styles(store).headingOne(),
paragraph: generate().styles(store).paragraph(),
'heading-three': generate().styles().headingThree(),
'heading-two': generate().styles().headingTwo(),
'heading-one': generate().styles().headingOne(),
paragraph: generate().styles().paragraph(),
},
background: options.final
? function (currentPage: number) {
Expand Down
8 changes: 7 additions & 1 deletion src/use/raw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContextStatePageContent } from '@/types/context'
import { useEnv } from './env'

export const bold = () => {
const open = () => {
Expand Down Expand Up @@ -50,7 +51,12 @@ export const useRaw = () => {
let _italic = false
let _bold = false

if (page.type === 'page-break' || page.type === 'line-break') return ''
if (
page.type === 'page-break' ||
page.type === 'line-break' ||
page.raw === useEnv().emptyLine()
)
return ''

if (page.type !== 'paragraph' && page.type !== 'image') return page.raw

Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {
"editor-mobile": "90vh"
}),
backgroundColor: theme => ({
"black-opacity": 'rgba(0,0,0, 0.1)',
"black-opacity": 'rgba(0,0,0, 0.15)',
"white-opacity": 'rgba(255,255,255, 0.1)',
"modal": 'rgba(0,0,0, 0.6)'
}),
Expand Down

0 comments on commit 07728f0

Please sign in to comment.