Skip to content

Conversation

@kumilingus
Copy link
Contributor

Description

  1. Make the elementView (and linkView) types more general to allow passing custom views without the need for casting.

Before:

new dia.Paper({
 elementView: CustomElementView as typeof dia.ElementView
})

After:

new dia.Paper({
  elementView: CustomElementView
})
  1. Allow elementView callback to return null or undefined (to signalize using the default view).

Before:

new dia.Paper({
 elementView: (element) => 
      if (element.get('type) === 'CustomElement') {
        return CustomElementView;
      }
      // otherwise use the default view (either one from namespace or `dia.ElementView`).
      return null;
   }
})

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the type definitions for the elementView and linkView options in dia.Paper to support custom view classes without requiring explicit type casting. The changes allow these options to accept any subclass of ElementView or LinkView through generic type parameters, and enable callback functions to return null or undefined to indicate use of default views.

Changes:

  • Updated type definitions for elementView and linkView options to use generic type parameters (<any>)
  • Modified callback return types to allow null or undefined for fallback to default views
  • Added test cases demonstrating the new functionality with custom view classes

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/joint-core/types/joint.d.ts Updated Paper.Options type definitions for elementView and linkView to support generic views and nullable callback returns
packages/joint-core/test/ts/index.test.ts Added CustomLinkView class and test cases for both direct class assignment and conditional callback with null return

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zbynekstara zbynekstara merged commit 24e263c into clientIO:master Jan 20, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants