import { Arr, Obj, Type } from '@ephox/katamari'; import * as BehaviourBlob from '../../behaviour/common/BehaviourBlob'; import type { AlloyBehaviour, AlloyBehaviourRecord } from '../behaviour/Behaviour'; // This goes through the list of behaviours defined for a particular spec (removing anything // that has been revoked), and returns the BehaviourType (e.g. Sliding) const getBehaviours = (spec: { behaviours?: AlloyBehaviourRecord }): Array> => { const behaviours: AlloyBehaviourRecord = Obj.get(spec, 'behaviours').getOr({ }); return Arr.bind(Obj.keys(behaviours), (name) => { const behaviour = behaviours[name]; return Type.isNonNullable(behaviour) ? [ behaviour.me ] : []; }); }; const generateFrom = (spec: { behaviours?: AlloyBehaviourRecord }, all: Array>): BehaviourBlob.BehaviourData => BehaviourBlob.generateFrom(spec, all); const generate = (spec: { behaviours?: AlloyBehaviourRecord }): BehaviourBlob.BehaviourData => { const all = getBehaviours(spec); return generateFrom(spec, all); }; export { generate, generateFrom };