Search
Loading...
Skip to content

Lock Content

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

10 mins
estimated time
Download
StackBlitz
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 editor, and block-level scopes override those defaults when the global scope is set to Defer.

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’s always blocked. When global is Defer, the block-level enabled/disabled state determines the outcome.

Discovering Available Scopes#

We can retrieve all available scope names using engine.editor.findAllScopes(). This returns an array of scope identifiers that can be used with the global and block-level scope APIs.

// Get all available scopes
const allScopes = engine.editor.findAllScopes();
console.log('Available scopes:', allScopes);
console.log('');

Locking an Entire Design#

To lock everything, we iterate through all scopes and set each global scope to Deny. This prevents any editing operation on any block in the design.

// Step 1: Lock everything by setting all global scopes to 'Deny'
for (const scope of allScopes) {
engine.editor.setGlobalScope(scope, 'Deny');
}
console.log('All scopes locked globally\n');

Important: When locking all scopes, the editor/select scope is also locked. Users cannot interact with a block they cannot select. Before enabling specific capabilities, you must also enable editor/select on blocks users should be able to interact with.

Selective Locking Patterns#

In most real-world scenarios, you want to lock some aspects while allowing others. Here are common patterns for partial locking.

Allowing Text Editing#

To allow users to edit text content but nothing else, we set the text/edit and text/character global scopes to Defer, then enable them on specific text blocks.

// Step 2: Allow text editing on specific blocks
// Set text/edit scope to 'Defer' so block-level settings take effect
engine.editor.setGlobalScope('text/edit', 'Defer');
engine.editor.setGlobalScope('text/character', 'Defer');
// Enable text editing on the editable text block
engine.block.setScopeEnabled(editableText, 'text/edit', true);
engine.block.setScopeEnabled(editableText, 'text/character', true);
console.log(
'Text editing enabled for:',
engine.block.getName(editableText)
);

Allowing Image Replacement#

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

// Step 3: Allow image replacement on specific blocks
// Set fill/change scope to 'Defer'
engine.editor.setGlobalScope('fill/change', 'Defer');
// Enable image replacement on the replaceable image block
engine.block.setScopeEnabled(replaceableImage, 'fill/change', true);
console.log(
'Image replacement enabled for:',
engine.block.getName(replaceableImage)
);

Allowing Position Adjustments#

To allow repositioning of specific elements, we set layer/move and layer/resize to Defer globally, then enable them on selected blocks.

// Step 4: Allow repositioning of specific blocks
// Set layer/move scope to 'Defer'
engine.editor.setGlobalScope('layer/move', 'Defer');
engine.editor.setGlobalScope('layer/resize', 'Defer');
// Enable movement and resizing on the movable shape
engine.block.setScopeEnabled(movableShape, 'layer/move', true);
engine.block.setScopeEnabled(movableShape, 'layer/resize', true);
console.log(
'Position adjustment enabled for:',
engine.block.getName(movableShape)
);
console.log('');

Checking Permissions#

We can verify the effective permission on a block using engine.block.isAllowedByScope(). This returns true if the operation is permitted after evaluating both global and block-level settings.

/**
* Logs the effective permissions for a block
*/
function logPermissions(engine, name, blockId) {
const canMove = engine.block.isAllowedByScope(blockId, 'layer/move');
const canResize = engine.block.isAllowedByScope(blockId, 'layer/resize');
const canEditText = engine.block.isAllowedByScope(blockId, 'text/edit');
const canChangeFill = engine.block.isAllowedByScope(blockId, 'fill/change');
const canDelete = engine.block.isAllowedByScope(blockId, 'lifecycle/destroy');
console.log(`Permissions for "${name}":`);
console.log(` - Move: ${canMove}`);
console.log(` - Resize: ${canResize}`);
console.log(` - Edit text: ${canEditText}`);
console.log(` - Change fill: ${canChangeFill}`);
console.log(` - Delete: ${canDelete}`);
}

Use engine.block.isScopeEnabled() to check just the block-level setting, and engine.editor.getGlobalScope() to check the global setting.

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 global scope to Deny or Defer
Block unexpectedly lockedGlobal scope set to DenySet global scope to Defer and enable 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 wrong scope levelUse isAllowedByScope() for effective permission
New SDK scopes not lockedLocking code doesn’t cover new scopesUse findAllScopes() dynamically