Skip to content

Commit

Permalink
fix(logger): convert fixed items
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 29, 2021
1 parent 4a68130 commit c2342df
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/lang/br/plugin/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ export default {
autosave: 'PROJETO SALVO AUTOMATICAMENTE COM SUCESSO!',
},
},
normalize: {
image: 'IMAGEM',
pageBreak: 'QUEBRA DE PÁGINA',
lineBreak: 'QUEBRA DE LINHA',
},
}
4 changes: 4 additions & 0 deletions src/lang/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import editor from './editor'
import toast from './toast'
import landing from './landing'
import seo from './seo'
import logger from './plugin/logger'

export default {
editor,
toast,
landing,
seo,
plugin: {
logger,
},
generics: {
input: {
image: 'Insert Image',
Expand Down
5 changes: 5 additions & 0 deletions src/lang/en/plugin/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ export default {
autosave: 'PROJECT AUTOMATICALLY SAVED SUCCESSFUL!',
},
},
normalize: {
image: 'IMAGE',
pageBreak: 'PAGE BREAK',
lineBreak: 'LINE BREAK',
},
}
4 changes: 3 additions & 1 deletion src/plugin/logger/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
PluginLoggerDefault,
PluginLoggerEntitySwapper,
} from '@/types/plugin/on'
import { useEntity } from '@/use/entity'

export const PluginLoggerActions = (
emitter: PluginEmitter,
stores: PluginStores
) => {
const format = useFormat()
const ent = useEntity()
const { t } = useI18n()

entity().PluginEntityCreate(emitter, [
Expand All @@ -21,7 +23,7 @@ export const PluginLoggerActions = (
type: 'editor',
method: 'info',
arguments: t('plugin.logger.on.entity.create', {
data: obj.data,
data: ent.utils().getNamesByTheContent(obj.data),
index: obj.index,
}),
createdAt: format.actually(),
Expand Down
36 changes: 35 additions & 1 deletion src/use/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useEditorStore } from '@/store/editor'
import { useContextStore } from '@/store/context'
import useEmitter from './emitter'
import usePlugin from './plugin/core'
import { useI18n } from 'vue-i18n'

export const useEntity = () => {
const PROJECT = useProjectStore()
Expand All @@ -17,6 +18,7 @@ export const useEntity = () => {
const env = useEnv()
const emitter = useEmitter()
const plugin = usePlugin()
const { t } = useI18n()
const pages = computed(() => PROJECT.pages)

const selection = computed(() => EDITOR.actives.text.selection.content)
Expand All @@ -43,6 +45,22 @@ export const useEntity = () => {
})

const utils = () => {
const isLink = (raw: string) => {
return raw.match('^(http|https)://')
}

const isImageCommand = (raw: string) => {
return raw.includes('data:image')
}

const isPageBreak = (raw: string) => {
return raw === env.pageBreak()
}

const isLineBreak = (raw: string) => {
return raw === env.lineBreak()
}

const entry = (input: string, target: string): boolean => {
return (
input.startsWith('/' + target) ||
Expand All @@ -64,7 +82,23 @@ export const useEntity = () => {
)
}

return { entry, isFixed }
const getNamesByTheContent = (raw: string) => {
if (isImageCommand(raw)) return t('plugin.logger.normalize.image')
if (isLineBreak(raw)) return t('plugin.logger.normalize.lineBreak')
if (isPageBreak(raw)) return t('plugin.logger.normalize.pageBreak')

return raw
}

return {
entry,
isFixed,
getNamesByTheContent,
isLink,
isImageCommand,
isPageBreak,
isLineBreak,
}
}

const swapper = () => {
Expand Down

0 comments on commit c2342df

Please sign in to comment.