Search Docs
Loading...
Skip to content

Lock Content

Lock design elements to prevent unwanted modifications using CE.SDK’s scope-based permission system.

8 mins
estimated time
GitHub

CE.SDK uses scopes to control what users can modify in a design. Each scope gates a specific capability—moving, resizing, text editing, image replacement, and more. The permission system has two layers: global scopes set defaults for the entire scene, and block-level scopes override those defaults when the global scope is set to .defer.

The example builds a sample page with four blocks—a fully locked image, an editable text block, a replaceable image, and a movable shape—then applies a different permission policy to each. This guide covers how to discover available scopes, lock an entire design, and selectively enable specific editing capabilities on individual blocks.

Understanding the Scope Permission Model#

Global and block-level scopes combine to determine whether an operation is permitted. The global scope can be set to one of three values:

Global ScopeBlock ScopeResult
.allowanyPermitted
.denyanyBlocked
.deferenabledPermitted
.deferdisabledBlocked

When global is .allow, the operation is always permitted regardless of block settings. When global is .deny, it is always blocked. When global is .defer, the block-level enabled state determines the outcome.

Discovering Available Scopes#

Retrieve every available scope name with engine.editor.findAllScopes(). It returns an array of scope identifiers you can pass to the global and block-level scope APIs.

let allScopes = engine.editor.findAllScopes()
print("Available scopes:", allScopes)

Locking an Entire Design#

To lock everything, iterate through all scopes and set each global scope to .deny. This blocks every editing operation on every block in the design.

for scope in allScopes {
try engine.editor.setGlobalScope(key: scope, value: .deny)
}

When all scopes are set to .deny, the editor/select scope is locked too. Users cannot interact with a block they cannot select, so before enabling specific capabilities you must also set editor/select to .defer and enable it on the blocks users should be able to reach.

Selective Locking Patterns#

In most real-world scenarios you want to lock some aspects while allowing others. The following patterns enable specific capabilities on individual blocks after everything has been locked.

Allowing Text Editing#

To let users edit text content but nothing else, set the text/edit and text/character global scopes to .defer, then enable them on specific text blocks with engine.block.setScopeEnabled(_:key:enabled:).

// text/edit gates the content, text/character gates styling (font, size, color).
try engine.editor.setGlobalScope(key: "text/edit", value: .defer)
try engine.editor.setGlobalScope(key: "text/character", value: .defer)
try engine.block.setScopeEnabled(editableText, key: "text/edit", enabled: true)
try engine.block.setScopeEnabled(editableText, key: "text/character", enabled: true)

Allowing Image Replacement#

To let users swap images while protecting layout, set the fill/change global scope to .defer and enable it on specific image blocks.

try engine.editor.setGlobalScope(key: "fill/change", value: .defer)
try engine.block.setScopeEnabled(replaceableImage, key: "fill/change", enabled: true)

Allowing Position Adjustments#

To allow repositioning and resizing of specific elements, set layer/move and layer/resize to .defer globally, then enable them on the chosen blocks.

try engine.editor.setGlobalScope(key: "layer/move", value: .defer)
try engine.editor.setGlobalScope(key: "layer/resize", value: .defer)
try engine.block.setScopeEnabled(movableShape, key: "layer/move", enabled: true)
try engine.block.setScopeEnabled(movableShape, key: "layer/resize", enabled: true)

Checking Permissions#

Verify the effective permission on a block with engine.block.isAllowedByScope(_:key:). It returns true when the operation is permitted after evaluating both the global and block-level settings.

let canEditText = try engine.block.isAllowedByScope(editableText, key: "text/edit")
let canMoveLockedImage = try engine.block.isAllowedByScope(lockedImage, key: "layer/move")
let canReplaceImage = try engine.block.isAllowedByScope(replaceableImage, key: "fill/change")
let canMoveShape = try engine.block.isAllowedByScope(movableShape, key: "layer/move")
print("Can edit text:", canEditText) // true
print("Can move locked image:", canMoveLockedImage) // false
print("Can replace image:", canReplaceImage) // true
print("Can move shape:", canMoveShape) // true
let textEditGlobal = try engine.editor.getGlobalScope(key: "text/edit")
let textEditEnabled = try engine.block.isScopeEnabled(editableText, key: "text/edit")
print("Global text/edit is .defer:", textEditGlobal == .defer) // true
print("Block-level text/edit enabled:", textEditEnabled) // true

isAllowedByScope(_:key:) returns the effective permission, isScopeEnabled(_:key:) returns only the block-level setting, and getGlobalScope(key:) returns only the global setting. GlobalScope is an Objective-C–backed enum, so compare it with == (for example scope == .defer) rather than printing it directly.

Available Scopes Reference#

ScopeDescription
layer/moveMove block position
layer/resizeResize block dimensions
layer/rotateRotate block
layer/flipFlip block horizontally or vertically
layer/cropCrop block content
layer/opacityChange block opacity
layer/blendModeChange blend mode
layer/visibilityToggle block visibility
layer/clippingChange clipping behavior
fill/changeChange fill content
fill/changeTypeChange fill type
stroke/changeChange stroke properties
shape/changeChange shape type
text/editEdit text content
text/characterChange text styling (font, size, color)
appearance/adjustmentsChange color adjustments
appearance/filterApply or change filters
appearance/effectApply or change effects
appearance/blurApply or change blur
appearance/shadowApply or change shadows
appearance/animationApply or change animations
lifecycle/destroyDelete the block
lifecycle/duplicateDuplicate the block
editor/addAdd new blocks
editor/selectSelect blocks

Troubleshooting#

IssueCauseSolution
Block still editableGlobal scope set to .allowChange the global scope to .deny or .defer
Block unexpectedly lockedGlobal scope set to .denySet the global scope to .defer and enable the block-level scope
Can’t interact with unlocked blockeditor/select scope is lockedEnable editor/select on blocks users should interact with
Permission check returns wrong valueChecking the wrong scope levelUse isAllowedByScope(_:key:) for the effective permission
New SDK scopes not lockedLocking code doesn’t cover new scopesUse findAllScopes() dynamically instead of a hardcoded list

Next Steps#