Overview
The WeaveStateManipulation class is a collection of static helpers for reading and writing the Yjs document that backs the collaborative canvas state.
All canvas state in Weave.js is stored as two Y.Map roots inside a Y.Doc:
-
weave— the node tree (stage → layers → nodes) -
weaveMetadata— metadata not directly rendered
WeaveStateManipulation gives you direct access to that tree, letting you build,
insert, update, delete, and query nodes at the Yjs level without going through the
higher-level Weave instance methods.
|
Low-level API
Prefer the |
Static Methods
mapValueToYjs
static mapValueToYjs(value: unknown): unknown
Converts any JavaScript value to its Yjs-compatible equivalent, recursively:
| Input type | Output type |
|---|---|
|
returned as-is |
|
|
plain |
|
mapPropsToYjs
static mapPropsToYjs(props: Record<string, unknown>): Y.Map<unknown>
Converts a flat or nested props object into a Y.Map, mapping each value through
mapValueToYjs.
mapNodeToYjs
static mapNodeToYjs(node: WeaveStateElement): {
nodeId: string;
element: Y.Map<WeaveStateElement>;
}
Converts a WeaveStateElement JSON model into a Yjs Y.Map structure ready to be
inserted into the document. Children are handled recursively as Y.Array elements.
addElements
static addElements(
layerYjsElement: Y.Map<unknown>,
yjsElements: Y.Map<unknown>[]
): void
Appends one or more Yjs element maps to the children array of the given layer element.
updateElements
static updateElements(
layerYjsElement: Y.Map<unknown>,
yjsElements: { nodeId: string; element: Y.Map<unknown> }[]
): void
Replaces existing child elements inside a layer by matching on nodeId. For each
entry, the old element at that position is deleted and the new one is inserted at
the same index.
deleteElements
static deleteElements(
layerYjsElement: Y.Map<unknown>,
yjsElementsIds: string[]
): void
Removes child elements from a layer by their node ids.
getYjsElement
static getYjsElement(doc: Y.Doc, nodeId: string): Y.Map<unknown> | null
Searches the weave root of the document for a node by its id prop. Looks in
both direct children of the stage and one level deeper (grandchildren / container
children).
getNodesBoundingBox
static getNodesBoundingBox(nodes: WeaveStateElement[]): BoundingBox
Computes the axis-aligned bounding box that contains all the provided nodes,
based on their x, y, width, and height props.