Home Reference Source
import {Group} from './api/Group.js'
public class | source

Group

Extends:

WrappedObjectLayer → Group

Direct Subclass:

Represents a group of layers.

Static Method Summary

Static Public Methods
public static

tests(): dictionary

Return a list of tests to run for this class.

Constructor Summary

Public Constructor
public

constructor(group: MSLayerGroup, document: Document)

Make a new group object.

Member Summary

Public Members
public get

isGroup: bool: boolean

Is this an group?

Method Summary

Public Methods
public

Adjust the group to fit its children.

public

iterate(block: function(layer: Layer))

Perform a function for every sub-layer inside this one.

public

iterateWithFilter(filter: function(layer: Layer), block: function(layer: Layer))

Perform a function for every sub-layer inside this one that passes a filter.

public

newGroup(properties: dictionary): Group

Returns a newly created group, which has been added to this layer, and sets it up using the supplied properties.

public

newImage(properties: dictionary): Image

Returns a newly created image layer, which has been added to this layer, and sets it up using the supplied properties.

public

newShape(properties: dictionary): Shape

Returns a newly created shape, which has been added to this layer, and sets it up using the supplied properties.

public

newText(properties: dictionary): Text

Returns a newly created text layer, which has been added to this layer, and sets it up using the supplied properties.

public

Convert a rectangle in page coordinates to one relative to this container's coordinates.

Inherited Summary

From class WrappedObject
public static

tests(): dictionary

Return a list of tests to run for this class.

public get

id: string: *

Returns the object ID of the wrapped Sketch model object.

public get

Returns the wrapped Sketch object.

From class Layer
public static

tests(): dictionary

Return a list of tests to run for this class.

public get

Return the parent container of this layer.

public get

The frame of the layer.

public set

frame(frame: Rectangle): *

Set the frame of the layer.

public get

Return the index of this layer in it's container. The layer at the back of the container (visualy) will be layer 0. The layer at the front will be layer n - 1 (if there are n layers).

public get

Is this an artboard?

public get

isGroup: bool: boolean

Is this a group?

public get

isImage: bool: boolean

Is this an image layer?

public get

isPage: bool: boolean

Is this a page?

public get

isShape: bool: boolean

Is this a shape layer?

public get

isText: bool: boolean

Is this a text layer?

public get

name: string: *

The name of the layer.

public set

name(name: string): *

Set the name of the layer.

public

Add this layer to the selected layers.

public

Deselect this layer.

public

Duplicate this layer.

public

export(options: dictionary)

Export this layer (and the ones below it), using the options supplied.

public

Returns a list of export options with any missing ones replaced by default values.

public

Convert a rectangle in the coordinates that this layer uses to absolute (page) coordinates.

public

Convert a rectangle in the coordinates that this layer uses to it's parent's coordinates.

public

Move this layer backwards in its container.

public

Move this layer forward in its container.

public

Move this layer to the back of its container.

public

Move this layer to the front of its container.

public

remove()

Remove this layer from its parent.

public

select()

Select the layer.

Static Public Methods

public static tests(): dictionary source

Return a list of tests to run for this class.

Override:

Layer#tests

Return:

dictionary

A dictionary containing the tests to run. Each key is the name of a test, each value is a function which takes a Tester instance.

Public Constructors

public constructor(group: MSLayerGroup, document: Document) source

Make a new group object.

Params:

NameTypeAttributeDescription
group MSLayerGroup

The underlying model object from Sketch.

document Document

The document that the group belongs to.

Public Members

public get isGroup: bool: boolean source

Is this an group?

All Layer objects respond to this method, but only Groups or things that inherit from groups return true.

Override:

Layer#isGroup

Return:

bool

true for instances of Group, false for any other layer type.

Public Methods

public adjustToFit() source

Adjust the group to fit its children.

public iterate(block: function(layer: Layer)) source

Perform a function for every sub-layer inside this one. The function will be passed a single argument each time it is invoked - which will be an object representing the sub-layer.

Params:

NameTypeAttributeDescription
block function(layer: Layer)

The function to execute for each layer.

public iterateWithFilter(filter: function(layer: Layer), block: function(layer: Layer)) source

Perform a function for every sub-layer inside this one that passes a filter. The function will be passed a single argument each time it is invoked - which will be an object representing the sub-layer.

Params:

NameTypeAttributeDescription
filter function(layer: Layer)

Filter function called on each layer first to check whether it should be iterated.

block function(layer: Layer)

The function to execute for each layer.

public newGroup(properties: dictionary): Group source

Returns a newly created group, which has been added to this layer, and sets it up using the supplied properties.

Params:

NameTypeAttributeDescription
properties dictionary

Properties to apply to the group.

Return:

Group

the new group.

public newImage(properties: dictionary): Image source

Returns a newly created image layer, which has been added to this layer, and sets it up using the supplied properties.

Params:

NameTypeAttributeDescription
properties dictionary

Properties to apply to the layer.

Return:

Image

the new image layer.

public newShape(properties: dictionary): Shape source

Returns a newly created shape, which has been added to this layer, and sets it up using the supplied properties.

Params:

NameTypeAttributeDescription
properties dictionary

Properties to apply to the shape.

Return:

Shape

the new shape.

public newText(properties: dictionary): Text source

Returns a newly created text layer, which has been added to this layer, and sets it up using the supplied properties.

Params:

NameTypeAttributeDescription
properties dictionary

Properties to apply to the text layer.

Return:

Text

the new text layer.

public pageRectToLocalRect(rect: Rectangle): Rectangle source

Convert a rectangle in page coordinates to one relative to this container's coordinates.

Params:

NameTypeAttributeDescription
rect Rectangle

The rectangle to convert.

Return:

Rectangle

The rectangle in local coordinates.

See something wrong or incomplete? Improve this page.