Skip to content

Commit 3bfd10f

Browse files
committed
chore(editor): entity name type
1 parent a706173 commit 3bfd10f

File tree

11 files changed

+47
-62
lines changed

11 files changed

+47
-62
lines changed

src/components/editor/entity/EditorEntityInput.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</template>
3838

3939
<script setup lang="ts">
40-
import { ContextStatePageContent } from '@/types/context'
40+
import { Entity } from '@/types/context'
4141
import { useEntity } from '@/use/entity'
4242
import { useFormat } from '@/use/format'
4343
import { useInput } from '@/use/input'
@@ -138,7 +138,7 @@
138138
raw: env.pageBreak(),
139139
createdAt: format.actually(),
140140
updatedAt: format.actually(),
141-
} as ContextStatePageContent
141+
} as Entity
142142
143143
type.value = 'paragraph'
144144
input.value.placeholder = t('editor.text.placeholder.paragraph')
@@ -156,7 +156,7 @@
156156
raw: env.lineBreak(),
157157
createdAt: format.actually(),
158158
updatedAt: format.actually(),
159-
} as ContextStatePageContent
159+
} as Entity
160160
161161
type.value = 'paragraph'
162162
input.value.placeholder = t('editor.text.placeholder.paragraph')
@@ -169,7 +169,7 @@
169169
if (entity.utils().entry(_cmp, 'im')) {
170170
cmp.value = ''
171171
172-
factory.simulate().file((content: ContextStatePageContent) => {
172+
factory.simulate().file((content: Entity) => {
173173
type.value = 'paragraph'
174174
input.value.placeholder = t('editor.text.placeholder.paragraph')
175175
@@ -190,7 +190,7 @@
190190
raw: props.modelValue,
191191
createdAt: format.actually(),
192192
updatedAt: format.actually(),
193-
} as ContextStatePageContent
193+
} as Entity
194194
195195
type.value = 'paragraph'
196196
input.value.placeholder = t('editor.text.placeholder.paragraph')
@@ -220,7 +220,7 @@
220220
raw: normalize,
221221
createdAt: format.actually(),
222222
updatedAt: format.actually(),
223-
} as ContextStatePageContent
223+
} as Entity
224224
225225
CONTEXT.addInPageWithPaste(content)
226226

src/components/editor/entity/EditorEntityShow.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"
126126
:style="{ height, whiteSpace: 'break-spaces' }"
127127
@keypress.enter.prevent="onEnter"
128-
@keydown="generalHandler"
128+
@keydown="onKeyboard"
129129
@input="onChangeArea"
130130
@click="onClick"
131131
/>
@@ -142,7 +142,7 @@
142142
import { useFactory } from '@/use/factory'
143143
import { useToast } from 'vue-toastification'
144144
import { useI18n } from 'vue-i18n'
145-
import { ContextStatePageContent } from '@/types/context'
145+
import { Entity } from '@/types/context'
146146
import { EntityShowEditOptions } from '@/types/entity'
147147
import { VueEmitterEntityOpen, VueEmitterEntityClose } from '@/types/emitter'
148148
import { useScroll } from '@/use/scroll'
@@ -154,7 +154,7 @@
154154
const props = defineProps({
155155
entity: {
156156
required: true,
157-
type: Object as () => ContextStatePageContent,
157+
type: Object as () => Entity,
158158
},
159159
})
160160
@@ -272,7 +272,7 @@
272272
data.value = ''
273273
274274
factory.simulate().file(
275-
(content: ContextStatePageContent) => {
275+
(content: Entity) => {
276276
edit.value = false
277277
278278
CONTEXT.newInExistentEntity({
@@ -290,7 +290,7 @@
290290
onMounted(() => {
291291
emitter.on(
292292
'entity-close',
293-
(ent?: ContextStatePageContent, options?: VueEmitterEntityClose) => {
293+
(ent?: Entity, options?: VueEmitterEntityClose) => {
294294
if (document.activeElement === input.value) return
295295
296296
if (options?.all) {
@@ -346,7 +346,7 @@
346346
}
347347
})
348348
349-
emitter.on('entity-not-mutate', async (entity: ContextStatePageContent) => {
349+
emitter.on('entity-not-mutate', async (entity: Entity) => {
350350
const _id = CONTEXT.entity.indexOf(entity)
351351
352352
focus.value = false
@@ -473,7 +473,7 @@
473473
})
474474
}
475475
476-
const generalHandler = async (e: KeyboardEvent) => {
476+
const onKeyboard = async (e: KeyboardEvent) => {
477477
const _input = input.value as HTMLTextAreaElement
478478
479479
// in ctrl press

src/components/editor/main/EditorBase.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<script lang="ts" setup>
4646
import { ref, nextTick } from 'vue'
47-
import { ContextStatePageContent } from '@/types/context'
47+
import { Entity } from '@/types/context'
4848
import { useScroll } from '@/use/scroll'
4949
import { useEnv } from '@/use/env'
5050
import useEmitter from '@/use/emitter'
@@ -64,7 +64,7 @@
6464
const main = ref<HTMLElement | null>(null)
6565
const entry = ref<string>('')
6666
67-
const enterListener = async (content: ContextStatePageContent) => {
67+
const enterListener = async (content: Entity) => {
6868
CONTEXT.addInPage(content)
6969
7070
await nextTick()

src/store/context.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { defineStore } from 'pinia'
2-
import {
3-
ContextState,
4-
ContextStatePageContent,
5-
EntityType,
6-
} from '../types/context'
2+
import { ContextState, Entity, EntityType } from '../types/context'
73
import { useEnv } from '../use/env'
84
import { useFormat } from '../use/format'
95
import { useUtils } from '../use/utils'
@@ -20,10 +16,10 @@ export const useContextStore = defineStore('context', {
2016
this.id = content.id
2117
this.entity = content.entity
2218
},
23-
addInPage(content: ContextStatePageContent) {
19+
addInPage(content: Entity) {
2420
this.entity.push(content)
2521
},
26-
addInPageWithPaste(content: ContextStatePageContent) {
22+
addInPageWithPaste(content: Entity) {
2723
// force nextTick for id append...
2824
},
2925
updateInPage(obj: Record<string, any>) {
@@ -39,13 +35,13 @@ export const useContextStore = defineStore('context', {
3935
this.entity[index].updatedAt = useFormat().actually()
4036
}
4137
},
42-
removeInPage(entity: ContextStatePageContent) {
38+
removeInPage(entity: Entity) {
4339
const index = this.entity.indexOf(entity)
4440

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

4743
this.entity = this.entity.filter(
48-
(item: ContextStatePageContent) => this.entity.indexOf(item) !== index
44+
(item: Entity) => this.entity.indexOf(item) !== index
4945
)
5046
},
5147
switchInPage(obj: Record<any, any>) {
@@ -78,10 +74,7 @@ export const useContextStore = defineStore('context', {
7874

7975
this.entity[index].raw = r
8076
},
81-
newInExistentEntity(
82-
this: ContextState,
83-
payload: Record<string, ContextStatePageContent>
84-
) {
77+
newInExistentEntity(this: ContextState, payload: Record<string, Entity>) {
8578
const index = this.entity.indexOf(payload.old)
8679

8780
if (index === -1) return
@@ -92,10 +85,8 @@ export const useContextStore = defineStore('context', {
9285
this.entity[index].updatedAt = useFormat().actually()
9386
this.entity[index].external = payload.new.external || {}
9487
},
95-
newInPage(payload: Record<string, ContextStatePageContent | string>) {
96-
const index = this.entity.indexOf(
97-
payload.entity as ContextStatePageContent
98-
)
88+
newInPage(payload: Record<string, Entity | string>) {
89+
const index = this.entity.indexOf(payload.entity as Entity)
9990

10091
if (index === -1) return
10192

@@ -104,16 +95,12 @@ export const useContextStore = defineStore('context', {
10495
raw: useEnv().emptyLine(),
10596
createdAt: useFormat().actually(),
10697
updatedAt: useFormat().actually(),
107-
} as ContextStatePageContent
98+
} as Entity
10899

109100
this.entity = useUtils().array().insert(this.entity, index, entity)
110101
},
111-
newInPagePosEdit(
112-
payload: Record<string, ContextStatePageContent | string>
113-
) {
114-
const index = this.entity.indexOf(
115-
payload.entity as ContextStatePageContent
116-
)
102+
newInPagePosEdit(payload: Record<string, Entity | string>) {
103+
const index = this.entity.indexOf(payload.entity as Entity)
117104

118105
if (index === -1) return
119106

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

127114
this.entity = useUtils()
128115
.array()
129116
.insert(this.entity, index + 1, entity)
130117
},
131-
alterInPage(payload: Record<string, ContextStatePageContent | EntityType>) {
132-
const index = this.entity.indexOf(
133-
payload.entity as ContextStatePageContent
134-
)
118+
alterInPage(payload: Record<string, Entity | EntityType>) {
119+
const index = this.entity.indexOf(payload.entity as Entity)
135120

136121
if (index === -1) return
137122

138-
const entity = payload.entity as ContextStatePageContent
123+
const entity = payload.entity as Entity
139124

140125
this.entity[index].type = payload.type as EntityType
141126
this.entity[index].raw = entity.raw
142127
this.entity[index].createdAt = useFormat().actually()
143128
this.entity[index].updatedAt = useFormat().actually()
144129
this.entity[index].external = entity.external || {}
145130
},
146-
insertRawInExistentEntity(entity: ContextStatePageContent) {
131+
insertRawInExistentEntity(entity: Entity) {
147132
const index = this.entity.indexOf(entity)
148133

149134
if (index === -1) return

src/store/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ContextState } from '@/types/context'
33
import { ProjectState } from '@/types/project'
44
import { useFormat } from '@/use/format'
55
import { useText } from '../use/text'
6-
import { ContextStatePageContent } from '../types/context'
6+
import { Entity } from '../types/context'
77

88
export const useProjectStore = defineStore('project', {
99
state: (): ProjectState => {
@@ -168,7 +168,7 @@ export const useProjectStore = defineStore('project', {
168168
},
169169
resetDates() {
170170
this.pages.forEach((page: ContextState) => {
171-
page.entity.forEach((line: ContextStatePageContent) => {
171+
page.entity.forEach((line: Entity) => {
172172
line.createdAt = useFormat().actually()
173173
line.updatedAt = useFormat().actually()
174174
})

src/types/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export type EntityType =
99

1010
export type ContextState = {
1111
id: number
12-
entity: Array<ContextStatePageContent>
12+
entity: Array<Entity>
1313
}
1414

15-
export type ContextStatePageContent = {
15+
export type Entity = {
1616
type: EntityType
1717
raw: string
1818
createdAt: string

src/types/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ContextStatePageContent } from './context'
1+
import { Entity } from './context'
22
export interface VueEmitterEntityClose {
33
all?: boolean
44
}
55

66
export interface VueEmitterEntityOpen {
7-
entity: ContextStatePageContent
7+
entity: Entity
88
up?: boolean
99
selectionInitial?: boolean
1010
switch?: boolean

src/use/entity.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ContextStatePageContent } from '@/types/context'
1+
import { Entity } from '@/types/context'
22
import { ContextState } from '@/types/context'
33
import { useScroll } from '@/use/scroll'
44
import { computed, reactive, nextTick, watch, ref } from 'vue'
@@ -70,7 +70,7 @@ export const useEntity = () => {
7070
// TODO: Deletar em caso de output vazio
7171
if (!entry || !output) return
7272

73-
arr.forEach((e: ContextStatePageContent) => {
73+
arr.forEach((e: Entity) => {
7474
const text = e.raw.split(' ')
7575

7676
text.forEach((t: string) => {
@@ -110,7 +110,7 @@ export const useEntity = () => {
110110
fstate.maxLetterCounter = 0
111111

112112
pages.value.forEach((context: ContextState) => {
113-
context.entity.forEach((entity: ContextStatePageContent) => {
113+
context.entity.forEach((entity: Entity) => {
114114
if (!fstate.entry) return
115115

116116
if (entity.raw.includes(fstate.entry)) {

src/use/factory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useEnv } from './env'
2-
import { ContextStatePageContent, EntityType } from '@/types/context'
2+
import { Entity, EntityType } from '@/types/context'
33
import { useFormat } from './format'
44
export const useFactory = () => {
55
const env = useEnv()
66
const format = useFormat()
77

88
const entity = () => {
9-
const create = (type: EntityType): ContextStatePageContent => {
9+
const create = (type: EntityType): Entity => {
1010
if (type === 'line-break') {
1111
return {
1212
type,
@@ -59,7 +59,7 @@ export const useFactory = () => {
5959
raw: reader.result,
6060
createdAt: format.actually(),
6161
updatedAt: format.actually(),
62-
} as ContextStatePageContent
62+
} as Entity
6363

6464
load && load(content)
6565
}

src/use/pdf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Callback } from '@/types/utils'
22
import { useToast } from 'vue-toastification'
33
import * as pdfMake from 'pdfmake/build/pdfmake'
44
import { GenerateParagraphOptions } from '@/types/pdf'
5-
import { ContextState, ContextStatePageContent } from '@/types/context'
5+
import { ContextState, Entity } from '@/types/context'
66
import { useRaw } from './raw'
77
import { useEnv } from './env'
88
import { useFonts } from './google/fonts'
@@ -227,7 +227,7 @@ export const usePDF = () => {
227227
if (!project.isBlankProject()) frontCover(arr)
228228

229229
pages.forEach((page: ContextState) => {
230-
page.entity.forEach((entity: ContextStatePageContent) => {
230+
page.entity.forEach((entity: Entity) => {
231231
let _raw = {}
232232

233233
if (entity.raw === env.emptyLine()) {

src/use/raw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ContextStatePageContent } from '@/types/context'
1+
import { Entity } from '@/types/context'
22

33
export const bold = () => {
44
const open = () => {
@@ -93,7 +93,7 @@ export const useRaw = () => {
9393
return final
9494
}
9595

96-
const convert = (entity: ContextStatePageContent) => {
96+
const convert = (entity: Entity) => {
9797
let final = ''
9898
let _italic = false
9999
let _bold = false

0 commit comments

Comments
 (0)