11import { defineStore } from 'pinia'
2- import {
3- ContextState ,
4- ContextStatePageContent ,
5- EntityType ,
6- } from '../types/context'
2+ import { ContextState , Entity , EntityType } from '../types/context'
73import { useEnv } from '../use/env'
84import { useFormat } from '../use/format'
95import { 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
0 commit comments