Decides what the editor offers: which features exist, where they show, and what they offer.
A feature is one thing a user recognises, such as text, crop or the dock. Options inside it nest by what
they belong to, and settings are what an option offers (font size presets, crop’s open).
Features decide what the UI offers, not what code may do: cesdk.actions.run and engine calls keep
working whatever a feature says.
Example#
cesdk.features.configure({ 'ly.img.text': { enabled: true, when: { narrow: ({ engine, blockId }) => blockId == null || !engine.block.hasMetadata(blockId, 'locked') }, options: { decoration: { enabled: false } } }});
const [blockId] = cesdk.engine.block.findAllSelected();const text = cesdk.features.evaluate('ly.img.text', { blockId });text.options.fontSize.status; // 'available'In TypeScript, every id you pass is checked against FeatureRegistry. Built-in features are in it already. A plugin’s features are in it once your code imports the plugin; add your own features to it as shown for FeatureShapeOf.
Constructors#
Constructor#
FeaturesAPI
FeaturesAPIFeature Control#
Methods to define, configure and read features.
define()#
Creates a feature. A plugin defines its own features, an integrator only those of their custom
components. Defining an id that is already defined throws; resetEditor() removes every feature
except the built-in ones, so a plugin added again after it defines its features again.
resetEditor() removes every feature
except the built-in ones, so a plugin added again after it defines its features again.enabledis the starting value; left out, it istrue. Built-in features start off.requiresis what the feature needs to work at all. It always applies, cascades to every option and cannot be overridden. It may read other features throughfeatures.evaluate.whenis the starting rule for where it shows: a function or an action id.- Any other key declares a setting with its JSON Schema and
default.
Name a feature after what it lets people do, never after the UI that shows it, such as a panel or a bar, because that UI may change. The built-in features for the editor’s areas are the exception: they are named after the area.
In TypeScript, define, configure, evaluate, explain and get take only ids in FeatureRegistry,
and define takes only the settings and options that the entry declares. Add your feature to it with
declare module '@cesdk/cesdk-js', as shown for FeatureShapeOf.
Type Parameters#
| Type Parameter |
|---|
K extends keyof FeatureRegistry |
Parameters#
| Parameter | Type | Description |
|---|---|---|
definition |
object & FeatureDefinitionOf<K> |
The feature with its id, rules, options and settings. |
Returns#
void
Example#
cesdk.features.define({ id: 'my.plugin.stamp', title: 'Stamp', requires: ({ engine, blockId }) => blockId != null && engine.block.supportsFill(blockId), options: { size: { presets: { type: 'array', items: { type: 'number', minimum: 1 }, default: [12, 24, 48] } } }});Signature#
define(definition: object & FeatureDefinitionOf<K>): voidconfigure()#
Changes features. Keys are feature ids; nested options go inside options. Entries are objects.
options. Entries are objects.enabled: the last write wins. A feature that is off turns everything inside it off.when: a rule replaces the base and resets earlier rules;{ narrow }adds a condition that must hold;{ extend }widens the base, never past a narrow. Options follow their parent’swhenuntil they write their own;'inherit'follows it again.- Settings take a value or a function of
{ previous, ...context }. A plain value replaces what is there; a function gets the value so far, so two functions both apply. Write functions that give the same result when your setup runs twice. A function runs on every read until a later plain value replaces it, so keep it cheap.previousis read-only, so return a new value, such as[...previous].sort(). - A key set to
undefinedis skipped, as indefine.
Unknown ids, dotted keys, unknown options and settings, and invalid values throw with the fix. In TypeScript, a key must be in FeatureRegistry; add the features you define to it, as shown for FeatureShapeOf.
Parameters#
| Parameter | Type | Description |
|---|---|---|
configuration |
FeatureConfiguration |
Feature ids mapped to what to change. |
Returns#
void
Example#
cesdk.features.configure({ 'ly.img.text': { enabled: true, options: { fontSize: { presets: [12, 14, 18, 24, 36] }, alignment: { alignments: ({ previous }) => previous.filter((a) => a !== 'Auto') } } }, 'ly.img.crop': { open: 'manual' }});Signature#
configure(configuration: FeatureConfiguration): voidget()#
Returns a feature as configured, without running any rule: enabled, requires, when as
{ base, extend, narrow }, options, and every setting as { schema, value }.
enabled, requires, when as
{ base, extend, narrow }, options, and every setting as { schema, value }.Type Parameters#
| Type Parameter |
|---|
K extends keyof FeatureRegistry |
Parameters#
| Parameter | Type | Description |
|---|---|---|
id |
K |
The feature id. |
Returns#
ConfiguredFeature<FeatureShapeFor<K>>
The feature’s definition with every write applied.
Signature#
get(id: K): ConfiguredFeature<FeatureShapeFor<K>>list()#
Returns every defined feature, as get returns it.
get returns it.Returns#
ConfiguredFeature<FeatureShape>[]
Every feature with its options, settings and rules.
Signature#
list(): ConfiguredFeature<FeatureShape>[]evaluate()#
Works a feature out for a block: a status on every level (‘off’, ‘unavailable’ or
‘available’) and settings as their final values.
status on every level (‘off’, ‘unavailable’ or
‘available’) and settings as their final values.blockId is never filled in from the selection. The built-in features that work on one block throw without a
blockId while they are switched on. A result keeps the configuration it was read with,
including the features its rules read. Rules run when you first read their level, so they see the
engine as it is then.
Inside the editor, a component that calls this re-renders when a feature or an engine value a rule read changes, custom components included.
A rule that reads a plain variable is not run again when it changes, so keep such state in the engine, such as block metadata.
In TypeScript, id must be in FeatureRegistry; add the features you define to it, as shown
for FeatureShapeOf.
Type Parameters#
| Type Parameter |
|---|
K extends keyof FeatureRegistry |
Parameters#
| Parameter | Type | Description |
|---|---|---|
id |
K |
The feature id. |
options? |
FeatureEvaluateOptions |
The block to ask about. |
Returns#
EvaluatedFeature<FeatureShapeFor<K>>
The feature’s tree with a status per level.
Example#
const text = cesdk.features.evaluate('ly.img.text', { blockId });if (text.options.fontSize.status === 'available') { showPresets(text.options.fontSize.presets);}Signature#
evaluate(id: K, options?: FeatureEvaluateOptions): EvaluatedFeature<FeatureShapeFor<K>>explain()#
Answers “why isn’t this showing?”: the same tree as evaluate, with reason and by on every level
that is not available.
evaluate, with reason and by on every level
that is not available.Type Parameters#
| Type Parameter |
|---|
K extends keyof FeatureRegistry |
Parameters#
| Parameter | Type | Description |
|---|---|---|
id |
K |
The feature id. |
options? |
FeatureEvaluateOptions |
The block to ask about. |
Returns#
FeatureExplanation<FeatureShapeFor<K>>
The feature’s tree with the reason for each hidden level.
Example#
cesdk.features.explain('ly.img.fill', { blockId });// { status: 'unavailable', reason: 'when', rule: 'narrow', by: '@imgly/plugin-qr-code-web', … }Signature#
explain(id: K, options?: FeatureEvaluateOptions): FeatureExplanation<FeatureShapeFor<K>>