MCPcopy
hub / github.com/tldraw/tldraw / toggleLock

Method toggleLock

packages/editor/src/lib/editor/Editor.ts:7184–7224  ·  view source on GitHub ↗

* Toggle the lock state of one or more shapes. If there is a mix of locked and unlocked shapes, all shapes will be locked. * * @param shapes - The shapes (or shape ids) to toggle. * * @public

(shapes: TLShapeId[] | TLShape[])

Source from the content-addressed store, hash-verified

7182 * @public
7183 */
7184 toggleLock(shapes: TLShapeId[] | TLShape[]): this {
7185 const ids =
7186 typeof shapes[0] === 'string'
7187 ? (shapes as TLShapeId[])
7188 : (shapes as TLShape[]).map((s) => s.id)
7189
7190 if (this.getIsReadonly() || ids.length === 0) return this
7191
7192 let allLocked = true,
7193 allUnlocked = true
7194 const shapesToToggle: TLShape[] = []
7195 for (const id of ids) {
7196 const shape = this.getShape(id)
7197 if (shape) {
7198 shapesToToggle.push(shape)
7199 if (shape.isLocked) {
7200 allUnlocked = false
7201 } else {
7202 allLocked = false
7203 }
7204 }
7205 }
7206 this.run(() => {
7207 if (allUnlocked) {
7208 this.updateShapes(
7209 shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
7210 )
7211 this.setSelectedShapes([])
7212 } else if (allLocked) {
7213 this.updateShapes(
7214 shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: false }))
7215 )
7216 } else {
7217 this.updateShapes(
7218 shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
7219 )
7220 }
7221 })
7222
7223 return this
7224 }
7225
7226 /**
7227 * Send shapes to the back of the page's object list.

Callers 5

onSelectFunction · 0.80
lockShapes.test.tsFile · 0.80
LockedShapesExampleFunction · 0.80

Calls 6

getIsReadonlyMethod · 0.95
getShapeMethod · 0.95
runMethod · 0.95
updateShapesMethod · 0.95
setSelectedShapesMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected