How to use the draft-js.Entity.get function in draft-js

To help you get started, we’ve selected a few draft-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Uscreen-video / atomic-builder / app / Editor / draft / toHTML / stateToHTML.js View on Github external
element = 'span';
            }
            // Normalize `className` -> `class`, etc.
            attributes = normalizeAttributes(attributes);
            if (style != null) {
              let styleAttr = styleToCSS(style);
              attributes = (attributes == null) ? {style: styleAttr} : {...attributes, style: styleAttr};
            }
            let attrString = stringifyAttrs(attributes);
            content = `<${element}${attrString}>${content}`;
          }
        }
        return content;
      }).join('');

      let entity = entityKey ? Entity.get(entityKey) : null;
      // Note: The `toUpperCase` below is for compatability with some libraries that use lower-case for image blocks.
      let entityType = (entity == null) ? null : entity.getType().toUpperCase();

      if (entityType == null) {
        return content;
      }

      let renderer = (entityRenderers != null && entityRenderers.hasOwnProperty(entityType)) ?
        entityRenderers[entityType] :
        null;

      if (renderer == null) {
        return content;
      }

      let attributes = convertDataToAttr(entity, renderer.attributeMap);
github strues / boldr / src / cms / common / components / BoldrEditor / BoldrEditor.js View on Github external
renderBlock: Function = (block): void => {
    if (block.getType() === 'atomic') {
      const entityType = Entity.get(block.getEntityAt(0)).getType();
      return this.props.customBlocks[entityType] ? this.props.customBlocks[entityType].getBlockRenderer() : null;
    }

      // fall back to default renderer
    return null;
  }
  /**
github HubSpot / draft-convert / test / spec / convertFromHTML.js View on Github external
it('handles an inline image', () => {
    const html = '<div>test<img src="test">test</div>';
    const contentState = toContentState(html);
    const blocks = contentState.getBlocksAsArray();
    expect(blocks.length).toBe(3);
    expect(blocks[1].getType()).toBe('atomic');
    expect(Entity.get(blocks[1].getEntityAt(0)).getType()).toBe('IMAGE');
    const resultHTML = convertToHTML({
      blockToHTML: {
        'atomic': {
          start: '<figure>',
          end: '</figure>'
        }
      },
      entityToHTML: (entity, originalText) =&gt; {
        if (entity.type === 'IMAGE') {
          return `<img src="${entity.data.src}">`;
        }
        return originalText;
      }
    })(contentState);
    expect(resultHTML).toBe('<p>test</p><figure><img src="test"></figure><p>test</p>');
  });
github bkniffler / draft-wysiwyg / src / draft.js View on Github external
const Link = (props) =&gt; {
   const {href} = Entity.get(props.entityKey).getData();
   return (
       <a href="{href}">
          {props.children}
       </a>
   );
};
const decorator = new CompositeDecorator([{
github strues / boldr / packages / boldr-editor / src / decorators / defaultDecorator.js View on Github external
(character) => {
      const entityKey = character.getEntity();
      return (
        entityKey !== null &&
        Entity.get(entityKey).getType() === 'LINK'
      );
    },
    callback,
github bkniffler / draft-wysiwyg / src / draft-toolbar.js View on Github external
(character) => {
                const entityKey = character.getEntity();
                return entityKey !== null && Entity.get(entityKey).getType() === 'link';
             },
             (start, end)=>{
github facebook / draft-js / examples / draft-0-9-1 / tex / js / components / TeXBlock.js View on Github external
_getValue() {
    return Entity
      .get(this.props.block.getEntityAt(0))
      .getData()['content'];
  }
github FrederikS / richie / src / main / editor / components / blocks / Atomic.js View on Github external
render() {
        const { editable } = this.props.blockProps;
        const entity = Entity.get(this.props.block.getEntityAt(0));
        const type = entity.getType();
        switch (type) {
            case Types.IMAGE: {
                const { src, title, width, height } = entity.getData();
                return this._renderComponent(
                    <img draggable="{editable}" height="{height}" width="{width}" title="{title}" src="{src}">
                , entity.getData());
            }
            default:
github FrederikS / richie / src / main / editor / components / controls / LinkControl.js View on Github external
_getCurrentUrl() {
        let url;
        const { editorState } = this.props;
        const selection = editorState.getSelection();
        const blockContent = editorState.getCurrentContent()
                                .getBlockForKey(selection.getAnchorKey());
        const linkEntityRanges = findLinkEntityRangesIn(blockContent);
        if (linkEntityRanges.length === 1 && matchesExactly(selection, linkEntityRanges[0])) {
            const entityKey = blockContent.getEntityAt(0);
            const entity = entityKey ? Entity.get(entityKey) : null;
            url = entity && entity.getType() === Types.LINK ? entity.getData().href : '';
        } else {
            url = '';
        }
        return url;
    }
github webRunes / WRIO-InternetOS / src / CoreEditor / EditorEntities / LinkEntity.js View on Github external
getProps(props) {
    const {
      linkTitle, href, linkDesc, editCallback,
    } = Entity.get(props.entityKey).getData();
    return {
      linkTitle: props.decoratedText || linkTitle,
      href,
      linkDesc,
      entityKey: props.entityKey,
      linkCallback: linkEditCallback,
    };
  }