Skip to content

Commit

Permalink
fix(shapes): fix adding shapes to collection
Browse files Browse the repository at this point in the history
  • Loading branch information
raminious committed Feb 21, 2023
1 parent 53736b7 commit 61aa922
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ export class Background {
const overlay = new Konva.Rect()

this.image = new ImageModel(board, image, {
internal: true,
selectable: false,
history: false
})

this.overlay = new RectModel(board, overlay, {
internal: true,
selectable: false,
history: false
})
Expand Down
10 changes: 8 additions & 2 deletions src/shape/ShapeModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,29 @@ export abstract class ShapeModel<

this.config = {
transformer: {},
internal: false,
history: true,
selectable: true,
...config
}

if (config.history ?? true) {
if (this.config.history) {
this.board.history.create(this.board.layer, [], {
undo: () => this.delete(),
redo: () => this.undelete()
})
}

if (this.config.internal === false) {
this.board.addShape(this)
}

this.board.events.emit('shape:create', {
shapes: [this]
})

if (this.selectable) {
this.node.draggable(true)
this.board.addShape(this)
}

this.board.layer.add(this.node)
Expand Down
1 change: 1 addition & 0 deletions src/types/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export declare interface ShapeConfig {
transformer?: Konva.TransformerConfig
selectable?: boolean
history?: boolean
internal?: boolean
}

export declare interface LabelConfig extends ShapeConfig {
Expand Down

0 comments on commit 61aa922

Please sign in to comment.