Skip to content

V6: 🎉 Group Rewrite #7670

Closed
Closed
@ShaMan123

Description

V6

Hi everyone,
fabric is moving forward!
We have 2 main goals for v6:

  1. js/ts migration which is covered here IMPORTANT: Migrating to modern javascript/typescript #7596
  2. Group rewrite 🎉

You can see #8316

Group Rewrite

This is a tracking issue for the group rewrite, read below for more detail including the current state of things and gist.
We aim to fix and support long desired features including:

  1. Nested selection - DONE
  2. Resizing and customized layout - DONE
  3. Transform and coordinate system (which is relative to the parent group) - DONE

Motivating Issues/Discussions

#7473 #7316 #6776 #7136 #7299 #7130 #7142 #7449 and anything with a group tag

How do you fit in?

  1. You can become an alpha tester (we aim to publish an alpha tag to npm regularly).
    IMPORTANT NOTICE: all changes made to the v6 branch are experimental and can be removed or changed without notice and without proper support (including supported features from v5). fabric might change drastically between commits. Meaning if you want in - it's on you.

You can join the effort by contributing

This description is updated continuously with relevant information
You don't need to scroll and read endless comments (unless you are a maintainer :))


Current State

Fixed logic across fabric for nested objects to be selectable.
Group has been completely rewritten and Layer has been introduced. As part of the rewrite group is now a layout engine, you can use it to customize layout of objects.
In general the rewrite allows any object to be selectable and interactive if it is referenced in the _objects array of it's parent and it references it's parent via the group property. If you build custom objects with nesting this is what you are looking for.

Usage

It is advised to use set on group/objects from now on (until #7596 is done, then it might change due to setters)
Changing subTargetCheck or interactive enables/disables crucial functionality so for these props it is not an advice but a MUST.

new fabric.Group(objects, {
  subTargetCheck: true,
  interactive: true   //  enables selecting subtargets
});

Progress

Experimental

Triggering Layout

#9148 extracts layout management to a standalone class

triggerLayout forces a group to recalculate its bounding box and reposition its objects.
You can define a layout strategy and assign it to the layout manager.
Read the code, it has comments explaining stuff and types that make it clear what you need to return from the method.
Look at the modified trigger, it is possible adding more triggers.
However I will promote an overall solution.
#7882 is a POC, follow the progress trigger

BREAKING

  • all awkward methods such as addWithUpdate are removed including toGroup/toActiveSelection
  • renamed object stacking methods on canvas (e.g. moveTo -> moveObjectTo)
  • strict object tree - EXTREMELY BREAKING because it steals under the radar
    • an object can have only one parent
    • no need to call remove before adding to another group, fabric handles it internally
    • no need (and discouraged) to use awkward active selection code for removing an object
    • canvas methods still need to enforce a strict check
  • if you hacked group prior to the rewrite you will probably need to rewrite your logic

Pitfalls

All object origin methods (e.g. translateToOriginPoint) are relative methods.
You should use them ONLY in the correct plane and with points that belong to the relative plane.
IMO it makes them worthless.
#8767 changes that.

BUGS

If you encounter bugs related to group or if you have a feature request please submit a relevant ticket.
Notice that bug reports of versions below v6 will be completely disregarded and closed. This was hard work, put effort into your repro so it is in v6.

Working Examples

Using v6! stale branch
- CodeSandbox or JSFiddle
- Layer or in JSFiddle

To Do

Look

Video is running in original speed
tiger

Cutting Edge

The blue circles are rendered by a textbox and because of the rewrite with a few lines of code I got this working
Pay no attention to caching of course

This is EXTREMELY exciting because it means that anyone could create custom objects subclassing whatever object they need and have nested selection work out of the box!

ezgif com-gif-maker (13)

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions