Skip to content

Commit

Permalink
chore(editor): entity name type
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 21, 2021
1 parent a706173 commit 3bfd10f
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 62 deletions.
12 changes: 6 additions & 6 deletions src/components/editor/entity/EditorEntityInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>

<script setup lang="ts">
import { ContextStatePageContent } from '@/types/context'
import { Entity } from '@/types/context'
import { useEntity } from '@/use/entity'
import { useFormat } from '@/use/format'
import { useInput } from '@/use/input'
Expand Down Expand Up @@ -138,7 +138,7 @@
raw: env.pageBreak(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
} as Entity
type.value = 'paragraph'
input.value.placeholder = t('editor.text.placeholder.paragraph')
Expand All @@ -156,7 +156,7 @@
raw: env.lineBreak(),
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
} as Entity
type.value = 'paragraph'
input.value.placeholder = t('editor.text.placeholder.paragraph')
Expand All @@ -169,7 +169,7 @@
if (entity.utils().entry(_cmp, 'im')) {
cmp.value = ''
factory.simulate().file((content: ContextStatePageContent) => {
factory.simulate().file((content: Entity) => {
type.value = 'paragraph'
input.value.placeholder = t('editor.text.placeholder.paragraph')
Expand All @@ -190,7 +190,7 @@
raw: props.modelValue,
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
} as Entity
type.value = 'paragraph'
input.value.placeholder = t('editor.text.placeholder.paragraph')
Expand Down Expand Up @@ -220,7 +220,7 @@
raw: normalize,
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
} as Entity
CONTEXT.addInPageWithPaste(content)
Expand Down
14 changes: 7 additions & 7 deletions src/components/editor/entity/EditorEntityShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"
:style="{ height, whiteSpace: 'break-spaces' }"
@keypress.enter.prevent="onEnter"
@keydown="generalHandler"
@keydown="onKeyboard"
@input="onChangeArea"
@click="onClick"
/>
Expand All @@ -142,7 +142,7 @@
import { useFactory } from '@/use/factory'
import { useToast } from 'vue-toastification'
import { useI18n } from 'vue-i18n'
import { ContextStatePageContent } from '@/types/context'
import { Entity } from '@/types/context'
import { EntityShowEditOptions } from '@/types/entity'
import { VueEmitterEntityOpen, VueEmitterEntityClose } from '@/types/emitter'
import { useScroll } from '@/use/scroll'
Expand All @@ -154,7 +154,7 @@
const props = defineProps({
entity: {
required: true,
type: Object as () => ContextStatePageContent,
type: Object as () => Entity,
},
})
Expand Down Expand Up @@ -272,7 +272,7 @@
data.value = ''
factory.simulate().file(
(content: ContextStatePageContent) => {
(content: Entity) => {
edit.value = false
CONTEXT.newInExistentEntity({
Expand All @@ -290,7 +290,7 @@
onMounted(() => {
emitter.on(
'entity-close',
(ent?: ContextStatePageContent, options?: VueEmitterEntityClose) => {
(ent?: Entity, options?: VueEmitterEntityClose) => {
if (document.activeElement === input.value) return
if (options?.all) {
Expand Down Expand Up @@ -346,7 +346,7 @@
}
})
emitter.on('entity-not-mutate', async (entity: ContextStatePageContent) => {
emitter.on('entity-not-mutate', async (entity: Entity) => {
const _id = CONTEXT.entity.indexOf(entity)
focus.value = false
Expand Down Expand Up @@ -473,7 +473,7 @@
})
}
const generalHandler = async (e: KeyboardEvent) => {
const onKeyboard = async (e: KeyboardEvent) => {
const _input = input.value as HTMLTextAreaElement
// in ctrl press
Expand Down
4 changes: 2 additions & 2 deletions src/components/editor/main/EditorBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<script lang="ts" setup>
import { ref, nextTick } from 'vue'
import { ContextStatePageContent } from '@/types/context'
import { Entity } from '@/types/context'
import { useScroll } from '@/use/scroll'
import { useEnv } from '@/use/env'
import useEmitter from '@/use/emitter'
Expand All @@ -64,7 +64,7 @@
const main = ref<HTMLElement | null>(null)
const entry = ref<string>('')
const enterListener = async (content: ContextStatePageContent) => {
const enterListener = async (content: Entity) => {
CONTEXT.addInPage(content)
await nextTick()
Expand Down
47 changes: 16 additions & 31 deletions src/store/context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { defineStore } from 'pinia'
import {
ContextState,
ContextStatePageContent,
EntityType,
} from '../types/context'
import { ContextState, Entity, EntityType } from '../types/context'
import { useEnv } from '../use/env'
import { useFormat } from '../use/format'
import { useUtils } from '../use/utils'
Expand All @@ -20,10 +16,10 @@ export const useContextStore = defineStore('context', {
this.id = content.id
this.entity = content.entity
},
addInPage(content: ContextStatePageContent) {
addInPage(content: Entity) {
this.entity.push(content)
},
addInPageWithPaste(content: ContextStatePageContent) {
addInPageWithPaste(content: Entity) {
// force nextTick for id append...
},
updateInPage(obj: Record<string, any>) {
Expand All @@ -39,13 +35,13 @@ export const useContextStore = defineStore('context', {
this.entity[index].updatedAt = useFormat().actually()
}
},
removeInPage(entity: ContextStatePageContent) {
removeInPage(entity: Entity) {
const index = this.entity.indexOf(entity)

if (index === -1 || entity.type === 'heading-one') return

this.entity = this.entity.filter(
(item: ContextStatePageContent) => this.entity.indexOf(item) !== index
(item: Entity) => this.entity.indexOf(item) !== index
)
},
switchInPage(obj: Record<any, any>) {
Expand Down Expand Up @@ -78,10 +74,7 @@ export const useContextStore = defineStore('context', {

this.entity[index].raw = r
},
newInExistentEntity(
this: ContextState,
payload: Record<string, ContextStatePageContent>
) {
newInExistentEntity(this: ContextState, payload: Record<string, Entity>) {
const index = this.entity.indexOf(payload.old)

if (index === -1) return
Expand All @@ -92,10 +85,8 @@ export const useContextStore = defineStore('context', {
this.entity[index].updatedAt = useFormat().actually()
this.entity[index].external = payload.new.external || {}
},
newInPage(payload: Record<string, ContextStatePageContent | string>) {
const index = this.entity.indexOf(
payload.entity as ContextStatePageContent
)
newInPage(payload: Record<string, Entity | string>) {
const index = this.entity.indexOf(payload.entity as Entity)

if (index === -1) return

Expand All @@ -104,16 +95,12 @@ export const useContextStore = defineStore('context', {
raw: useEnv().emptyLine(),
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
} as ContextStatePageContent
} as Entity

this.entity = useUtils().array().insert(this.entity, index, entity)
},
newInPagePosEdit(
payload: Record<string, ContextStatePageContent | string>
) {
const index = this.entity.indexOf(
payload.entity as ContextStatePageContent
)
newInPagePosEdit(payload: Record<string, Entity | string>) {
const index = this.entity.indexOf(payload.entity as Entity)

if (index === -1) return

Expand All @@ -122,28 +109,26 @@ export const useContextStore = defineStore('context', {
raw: payload.raw || useEnv().emptyLine(),
createdAt: useFormat().actually(),
updatedAt: useFormat().actually(),
} as ContextStatePageContent
} as Entity

this.entity = useUtils()
.array()
.insert(this.entity, index + 1, entity)
},
alterInPage(payload: Record<string, ContextStatePageContent | EntityType>) {
const index = this.entity.indexOf(
payload.entity as ContextStatePageContent
)
alterInPage(payload: Record<string, Entity | EntityType>) {
const index = this.entity.indexOf(payload.entity as Entity)

if (index === -1) return

const entity = payload.entity as ContextStatePageContent
const entity = payload.entity as Entity

this.entity[index].type = payload.type as EntityType
this.entity[index].raw = entity.raw
this.entity[index].createdAt = useFormat().actually()
this.entity[index].updatedAt = useFormat().actually()
this.entity[index].external = entity.external || {}
},
insertRawInExistentEntity(entity: ContextStatePageContent) {
insertRawInExistentEntity(entity: Entity) {
const index = this.entity.indexOf(entity)

if (index === -1) return
Expand Down
4 changes: 2 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContextState } from '@/types/context'
import { ProjectState } from '@/types/project'
import { useFormat } from '@/use/format'
import { useText } from '../use/text'
import { ContextStatePageContent } from '../types/context'
import { Entity } from '../types/context'

export const useProjectStore = defineStore('project', {
state: (): ProjectState => {
Expand Down Expand Up @@ -168,7 +168,7 @@ export const useProjectStore = defineStore('project', {
},
resetDates() {
this.pages.forEach((page: ContextState) => {
page.entity.forEach((line: ContextStatePageContent) => {
page.entity.forEach((line: Entity) => {
line.createdAt = useFormat().actually()
line.updatedAt = useFormat().actually()
})
Expand Down
4 changes: 2 additions & 2 deletions src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export type EntityType =

export type ContextState = {
id: number
entity: Array<ContextStatePageContent>
entity: Array<Entity>
}

export type ContextStatePageContent = {
export type Entity = {
type: EntityType
raw: string
createdAt: string
Expand Down
4 changes: 2 additions & 2 deletions src/types/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ContextStatePageContent } from './context'
import { Entity } from './context'
export interface VueEmitterEntityClose {
all?: boolean
}

export interface VueEmitterEntityOpen {
entity: ContextStatePageContent
entity: Entity
up?: boolean
selectionInitial?: boolean
switch?: boolean
Expand Down
6 changes: 3 additions & 3 deletions src/use/entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContextStatePageContent } from '@/types/context'
import { Entity } from '@/types/context'
import { ContextState } from '@/types/context'
import { useScroll } from '@/use/scroll'
import { computed, reactive, nextTick, watch, ref } from 'vue'
Expand Down Expand Up @@ -70,7 +70,7 @@ export const useEntity = () => {
// TODO: Deletar em caso de output vazio
if (!entry || !output) return

arr.forEach((e: ContextStatePageContent) => {
arr.forEach((e: Entity) => {
const text = e.raw.split(' ')

text.forEach((t: string) => {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const useEntity = () => {
fstate.maxLetterCounter = 0

pages.value.forEach((context: ContextState) => {
context.entity.forEach((entity: ContextStatePageContent) => {
context.entity.forEach((entity: Entity) => {
if (!fstate.entry) return

if (entity.raw.includes(fstate.entry)) {
Expand Down
6 changes: 3 additions & 3 deletions src/use/factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useEnv } from './env'
import { ContextStatePageContent, EntityType } from '@/types/context'
import { Entity, EntityType } from '@/types/context'
import { useFormat } from './format'
export const useFactory = () => {
const env = useEnv()
const format = useFormat()

const entity = () => {
const create = (type: EntityType): ContextStatePageContent => {
const create = (type: EntityType): Entity => {
if (type === 'line-break') {
return {
type,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const useFactory = () => {
raw: reader.result,
createdAt: format.actually(),
updatedAt: format.actually(),
} as ContextStatePageContent
} as Entity

load && load(content)
}
Expand Down
4 changes: 2 additions & 2 deletions src/use/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Callback } from '@/types/utils'
import { useToast } from 'vue-toastification'
import * as pdfMake from 'pdfmake/build/pdfmake'
import { GenerateParagraphOptions } from '@/types/pdf'
import { ContextState, ContextStatePageContent } from '@/types/context'
import { ContextState, Entity } from '@/types/context'
import { useRaw } from './raw'
import { useEnv } from './env'
import { useFonts } from './google/fonts'
Expand Down Expand Up @@ -227,7 +227,7 @@ export const usePDF = () => {
if (!project.isBlankProject()) frontCover(arr)

pages.forEach((page: ContextState) => {
page.entity.forEach((entity: ContextStatePageContent) => {
page.entity.forEach((entity: Entity) => {
let _raw = {}

if (entity.raw === env.emptyLine()) {
Expand Down
4 changes: 2 additions & 2 deletions src/use/raw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContextStatePageContent } from '@/types/context'
import { Entity } from '@/types/context'

export const bold = () => {
const open = () => {
Expand Down Expand Up @@ -93,7 +93,7 @@ export const useRaw = () => {
return final
}

const convert = (entity: ContextStatePageContent) => {
const convert = (entity: Entity) => {
let final = ''
let _italic = false
let _bold = false
Expand Down

0 comments on commit 3bfd10f

Please sign in to comment.