Skip to content

Commit

Permalink
feat: update scope dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Jun 1, 2024
1 parent 46378e2 commit 15f4ac7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Requires<Schemes extends ExpectedScheme> =
export type Scopes =
| { type: 'scopepicked', data: { ids: NodeId[] } }
| { type: 'scopereleased', data: { ids: NodeId[] } }
| { type: 'scopeupdated', data: { id: NodeId } }

/**
* Scope plugin. Responsible for user interaction with scopes (nested nodes, groups)
Expand Down Expand Up @@ -114,6 +115,13 @@ export class ScopesPlugin<Schemes extends ExpectedScheme, T = never> extends Sco
await resizeParent(parent, agentParams, props)
}
}
if (context.type === 'scopeupdated') {
const parent = this.editor.getNode(context.data.id)

if (parent) {
await resizeParent(parent, agentParams, props)
}
}
return context
})
}
Expand All @@ -132,6 +140,10 @@ export class ScopesPlugin<Schemes extends ExpectedScheme, T = never> extends Sco

return node && (node.selected || hasSelectedParent(id, props))
}

public async update(scopeId: NodeId) {
await this.emit({ type: 'scopeupdated', data: { id: scopeId } })
}
}

export function getPickedNodes<S extends ExpectedScheme>(scopes: Scope<Scopes, [Requires<S>, Root<S>]>) {
Expand Down

0 comments on commit 15f4ac7

Please sign in to comment.