Module

Play.Extra

Package
purescript-play
Repository
shamansir/purescript-play

#ItemPath Source

type ItemPath = Array Int

A path to a specific item in the layout tree. Represented as an array of child indices, where each number indicates which child to follow at each level of the tree.

Example: [0, 2, 1] means "first child, then its third child, then its second child"

#itemAt Source

itemAt :: forall a. ItemPath -> Play a -> Maybe a

Get the item value at a specific path in the tree. Returns Nothing if the path doesn't exist. This extracts just the cell value without layout information.

#playAt Source

playAt :: forall a. ItemPath -> Play a -> Maybe (Play a)

Get a sub-layout starting from a specific path. Returns Nothing if the path doesn't exist. The returned `Play`` contains only the subtree rooted at the specified path.

#defAt Source

defAt :: forall a. ItemPath -> Play a -> Maybe Def

Get the layout definition at a specific path in the tree. Returns Nothing if the path doesn't exist. This extracts the layout properties (sizing, padding, etc.) for the item.

#updateAt Source

updateAt :: forall a. ItemPath -> (a -> a) -> Play a -> Play a

Update the item value at a specific path using a transformation function. Returns the original layout unchanged if the path doesn't exist. Only modifies the cell value, leaving layout definitions intact.

#updateDefAt Source

updateDefAt :: forall a. ItemPath -> (Def -> Def) -> Play a -> Play a

Update the layout definition at a specific path using a transformation function. Returns the original layout unchanged if the path doesn't exist. Only modifies layout properties (sizing, padding, etc.), leaving cell value intact.

#addChildAt Source

addChildAt :: forall a. ItemPath -> Play a -> Play a -> Play a

Add a new child layout at a specific path. The new child is appended to the end of the existing children list. Returns the original layout unchanged if the parent path doesn't exist.

#removeChildAt Source

removeChildAt :: forall a. ItemPath -> Int -> Play a -> Play a

Remove a child at a specific index from the element at the given path. Returns the original layout unchanged if the parent path doesn't exist or if the child index is out of bounds.

Parameters:

  • path: Path to the parent element
  • childIndex: Index of the child to remove (0-based)

#overTree Source

overTree :: forall a b. (Tree (WithDef a) -> Tree (WithDef b)) -> Play a -> Play b

Apply a transformation function to the underlying tree structure. This is a low-level function that allows direct manipulation of the tree while maintaining the Play wrapper. Use with caution.

#treeAt Source

treeAt :: forall a. ItemPath -> Play a -> Maybe (Tree (WithDef a))

Get the subtree at a specific path in the layout. Returns Nothing if the path doesn't exist.

#find Source

find :: forall a. Eq a => a -> Play a -> Maybe (ItemPath /\ (Play a))

Find the first sub-layout in the layout tree that is bound to the provided value. Returns Nothing if no such item exists. The returned value includes both the path to the item and its layout. Root is at path [].

#findBy Source

findBy :: forall a. (a -> Boolean) -> Play a -> Maybe (ItemPath /\ (Play a))

Find the first sub-layout in the layout tree in the layout tree that satisfies the given predicate. Returns Nothing if no such item exists. The returned value includes both the path to the item and the item itself. Root is at path [].

#findInLayout Source

findInLayout :: forall a. Eq a => a -> Layout a -> Maybe (ItemPath /\ (Tree (WithRect a)))

Find the first sub-layout in the layout tree that is bound to the provided value. Returns Nothing if no such item exists. The returned value includes both the path to the item and its layout. Root is at path [].

#findByInLayout Source

findByInLayout :: forall a. (a -> Boolean) -> Layout a -> Maybe (ItemPath /\ (Tree (WithRect a)))

Find the first sub-layout in the layout tree in the layout tree that satisfies the given predicate. Returns Nothing if no such item exists. The returned value includes both the path to the item and the item itself. Root is at path [].