Fix null issues (more to do here)

This commit is contained in:
Steve Ruiz 2021-09-11 23:58:22 +01:00
parent 4b7d9c2af9
commit d79f66da4e
4 changed files with 37 additions and 36 deletions

View file

@ -18,13 +18,13 @@ function addToShapeTree<T extends TLShape, M extends Record<string, unknown>>(
branch: IShapeTreeNode<T, M>[],
shapes: TLPage<T, TLBinding>['shapes'],
pageState: {
bindingTargetId?: string
bindingId?: string
hoveredId?: string
bindingTargetId?: string | null
bindingId?: string | null
hoveredId?: string | null
selectedIds: string[]
currentParentId?: string
editingId?: string
editingBindingId?: string
currentParentId?: string | null
editingId?: string | null
editingBindingId?: string | null
},
meta?: M
) {

View file

@ -24,12 +24,12 @@ export interface TLPageState {
zoom: number
}
brush?: TLBounds
pointedId?: string
hoveredId?: string
editingId?: string
bindingId?: string
pointedId?: string | null
hoveredId?: string | null
editingId?: string | null
bindingId?: string | null
boundsRotation?: number
currentParentId?: string
currentParentId?: string | null
}
export interface TLHandle {

View file

@ -146,7 +146,7 @@ export class TextSession implements Session {
},
pageState: {
[pageId]: {
editingId: undefined,
editingId: null,
},
},
},
@ -166,7 +166,7 @@ export class TextSession implements Session {
},
pageState: {
[pageId]: {
editingId: undefined,
editingId: null,
selectedIds: [initialShape.id],
},
},

View file

@ -408,6 +408,7 @@ export class TLDrawState extends StateManager<Data> {
*/
selectTool = (tool: TLDrawShapeType | 'select'): this => {
if (this.session) return this
return this.patchState(
{
appState: {
@ -462,10 +463,10 @@ export class TLDrawState extends StateManager<Data> {
document: {
pageStates: {
[this.currentPageId]: {
bindingId: undefined,
editingId: undefined,
hoveredId: undefined,
pointedId: undefined,
bindingId: null,
editingId: null,
hoveredId: null,
pointedId: null,
},
},
},
@ -1356,6 +1357,7 @@ export class TLDrawState extends StateManager<Data> {
if (result === undefined) {
this.isCreating = false
return this.patchState(
{
appState: {
@ -1391,24 +1393,9 @@ export class TLDrawState extends StateManager<Data> {
pageStates: {
[this.currentPageId]: {
selectedIds: [],
editingId: undefined,
bindingId: undefined,
hoveredId: undefined,
},
},
},
}
// ...and set editingId back to undefined
result.after = {
...result.after,
document: {
...result.after.document,
pageStates: {
...result.after.document?.pageStates,
[this.currentPageId]: {
...(result.after.document?.pageStates || {})[this.currentPageId],
editingId: undefined,
editingId: null,
bindingId: null,
hoveredId: null,
},
},
},
@ -1431,6 +1418,17 @@ export class TLDrawState extends StateManager<Data> {
},
}
result.after.document = {
...result.after.document,
pageStates: {
...result.after.document?.pageStates,
[this.currentPageId]: {
...(result.after.document?.pageStates || {})[this.currentPageId],
editingId: null,
},
},
}
this.setState(result, `session:complete:${session.id}`)
} else {
this.patchState(
@ -1446,7 +1444,7 @@ export class TLDrawState extends StateManager<Data> {
document: {
pageStates: {
[this.currentPageId]: {
editingId: undefined,
editingId: null,
},
},
},
@ -2400,6 +2398,9 @@ export class TLDrawState extends StateManager<Data> {
}
break
}
case TLDrawStatus.EditingText: {
this.completeSession()
}
}
}