Giter Site home page Giter Site logo

Comments (9)

jlherren avatar jlherren commented on August 16, 2024 1

Works perfectly now! Many thanks! ❤️

from vanilla-picker.

Sphinxxxx avatar Sphinxxxx commented on August 16, 2024

Right... To avoid a breaking change, how about we wrap the injection in a try/catch and output a warning to the console if it fails?

from vanilla-picker.

jlherren avatar jlherren commented on August 16, 2024

It does not throw an exception. In particular, appending the style-node to the DOM is still successful, it just won't have any effect.

Wrapping the injection inside if (!options.externalCss) { ... } wouldn't be a breaking change, as long as externalCss defaults to false.

from vanilla-picker.

Sphinxxxx avatar Sphinxxxx commented on August 16, 2024

Ok, so in your case this is more of an annoyance, as you can add an external CSS file and everything works?

The breaking change is: Right now, the <style> element is injected when the script is executed. It doesn't wait for a picker to be created (where we have the options object). Changing that may break how someone uses the generated style element.

Maybe a fair trade-off would be to create the element (thus keeping it accessible in Picker.StyleElement), but only inject it once the first picker is created...

from vanilla-picker.

jlherren avatar jlherren commented on August 16, 2024

Yes, the injection part is just an annoyance, since it doesn't prevent the plugin from working correctly. However, it's quite annoying to constantly have an error in the dev console. Further, the npm package currently doesn't provide a compiled version of the styles, e.g. a CSS file. This makes it a bit harder to pull in the required styles, if for example I do not already use SCSS in my project.

Delaying the injection until first use would be of marginal benefit. I would still get an error in the end. If compatibility is an issue, perhaps providing an alternate entry point is a solution, e.g. import Picker from 'vanilla-picker/no-styles';

I also found this discussion about detecting the CSP at runtime, which might be interesting.

from vanilla-picker.

Sphinxxxx avatar Sphinxxxx commented on August 16, 2024

Thanks for your input on this!

I think the solution will be to build an additional pair of files: vanilla-picker.csp.js and .csp.css. Then, if I understand this question correctly, an extra entry point can be added in package.json for easy importing.

from vanilla-picker.

Sphinxxxx avatar Sphinxxxx commented on August 16, 2024

Could you check if the new v2.12.0 works for you?

import Picker from 'vanilla-picker/csp';

The CSS is in dist/vanilla-picker.csp.css.

from vanilla-picker.

jlherren avatar jlherren commented on August 16, 2024

Hi, thanks for the update. I can't seem to import the CSS file (I'm using webpack 5.52.1).

import 'vanilla-picker/dist/vanilla-picker.csp.css';

Output:

ERROR in ./js/backend/admin/colorPicker.js 4:0-52
Module not found: Error: Package path ./dist/vanilla-picker.csp.css is not exported from package /path/to/project/node_modules/vanilla-picker (see exports field in /path/to/project/node_modules/vanilla-picker/package.json)

Apparently it's not possible to import files that weren't explicitly exported in package.json.

This seems to be the only issue though, if I manually copy vanilla-picker.csp.css into the project and include it, everything works fine, with no CSP errors.

from vanilla-picker.

Sphinxxxx avatar Sphinxxxx commented on August 16, 2024

Ok, we're getting closer :)
Try v2.12.1

from vanilla-picker.

Related Issues (20)

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.