Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update scope dynamically #5

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 All @@ -42,7 +43,7 @@
* @emits scopepicked
* @emits scopereleased
*/
export class ScopesPlugin<Schemes extends ExpectedScheme, T = never> extends Scope<Scopes, [Requires<Schemes>, Root<Schemes>]> {

Check warning on line 46 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 128. Maximum allowed is 120

Check warning on line 46 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 128. Maximum allowed is 120
padding: (id: NodeId) => Padding
exclude: (id: NodeId) => boolean
size: (id: NodeId, size: Size) => Size
Expand Down Expand Up @@ -114,6 +115,13 @@
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 @@

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
Loading