/** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule DraftEditorDecoratedLeaves.react * @format * @flow * * This is unstable and not part of the public API and should not be used by * production systems. This file may be update/removed without notice. */ 'use strict'; import type { BlockNodeRecord } from './BlockNodeRecord'; import type ContentState from './ContentState'; import type { DraftDecoratorType } from './DraftDecoratorType'; import type { BidiDirection } from 'fbjs/lib/UnicodeBidiDirection'; import type { Set } from 'immutable'; const DraftOffsetKey = require('./DraftOffsetKey'); const React = require('react'); const UnicodeBidi = require('fbjs/lib/UnicodeBidi'); const UnicodeBidiDirection = require('fbjs/lib/UnicodeBidiDirection'); type Props = { block: BlockNodeRecord; children: ?Array; contentState: ContentState; decorator: DraftDecoratorType; decoratorKey: string; direction: BidiDirection; text: string; leafSet: Set; }; class DraftEditorDecoratedLeaves extends React.Component { render(): React.Node { const { block, children, contentState, decorator, decoratorKey, direction, leafSet, text } = this.props; const blockKey = block.getKey(); const leavesForLeafSet = leafSet.get('leaves'); const DecoratorComponent = decorator.getComponentForKey(decoratorKey); const decoratorProps = decorator.getPropsForKey(decoratorKey); const decoratorOffsetKey = DraftOffsetKey.encode(blockKey, parseInt(decoratorKey, 10), 0); const decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end')); // Resetting dir to the same value on a child node makes Chrome/Firefox // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/ const dir = UnicodeBidiDirection.getHTMLDirIfDifferent(UnicodeBidi.getDirection(decoratedText), direction); return {children} ; } } module.exports = DraftEditorDecoratedLeaves;