Giter VIP home page Giter VIP logo

Comments (7)

afhole avatar afhole commented on August 10, 2024 1

Hi @rpmonteiro - basically I realised that I don't need to inject a ELEM_ATTR_MAP - draft-js-import-element will now mirror any attributes you add to the entity, e.g.

Entity.create('LINK', 'MUTABLE', {
    url: 'http://example.com',
    target: '_blank',
    'data-some-custom-attribute': '123'
});

I think this was added a few releases after I first started using the library so at first I hadn't realised that was possible. The only gotcha is to remember that draft maps url > href and vice versa but everything else is 1:1 mapping with draft-js-import-element. Hope that helps :)

from draft-js-import-element.

afhole avatar afhole commented on August 10, 2024

Looking at the code it seems this is only necessary to map attributes to different names, and anything else is just pulled through like for like, so this may be a non-issue

from draft-js-import-element.

afhole avatar afhole commented on August 10, 2024

Yes, I see that attributes flow in and out nicely (well, data- attribs at least). Closing!

from draft-js-import-element.

rpmonteiro avatar rpmonteiro commented on August 10, 2024

Hey @afhole , I'm trying to achieve the same thing but I'm finding it very difficult. Would you mind just posting a little snippet on how you did it?
Cheers

from draft-js-import-element.

rpmonteiro avatar rpmonteiro commented on August 10, 2024

To be honest I still don't get it, but your help was very much appreciated. I might come back to this in a couple days and be like 'this was so simple'. Cheers

from draft-js-import-element.

afhole avatar afhole commented on August 10, 2024

Essentially if you are already creating link entities like here https://facebook.github.io/draft-js/docs/advanced-topics-entities.html#creating-and-retrieving-entities then you can just add whatever attributes you like alongside href - obviously just make sure anything with a dash is quoted, e.g. {'data-my-attribute': '123'}

from draft-js-import-element.

eessex avatar eessex commented on August 10, 2024

I would also like to import a custom ELEM_ATTR_MAP, specifically to add classes to Link elements -- class does not seem to map onto the entity when created. Is there a way to pass this into options?

from draft-js-import-element.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.