import { h, Component } from 'preact'; import { jsLibs, cssLibs } from '../libraryList'; import { trackEvent } from '../analytics'; import { LibraryAutoSuggest } from './LibraryAutoSuggest'; export default class AddLibrary extends Component { constructor(props) { super(props); this.state = { css: props.css || '', js: props.js || '' }; } onSelectChange(e) { const target = e.target; if (!target.value) { return; } const type = target.selectedOptions[0].dataset.type; if (type === 'js') { this.setState({ js: `${this.state.js}\n${target.value}` }); } else { this.setState({ css: `${this.state.css}\n${target.value}` }); } trackEvent('ui', 'addLibrarySelect', target.selectedOptions[0].label); this.props.onChange({ js: this.state.js, css: this.state.css }); // Reset the select to the default value target.value = ''; } textareaBlurHandler(e, textarea) { const target = e ? e.target : textarea; const type = target.dataset.lang; if (type === 'js') { this.setState({ js: target.value || '' }); } else { this.setState({ css: target.value || '' }); } // trackEvent('ui', 'addLibrarySelect', target.selectedOptions[0].label); this.props.onChange({ js: this.state.js, css: this.state.css }); } suggestionSelectHandler(value) { const textarea = value.match(/\.js$/) ? window.externalJsTextarea : window.externalCssTextarea; textarea.value = `${textarea.value}\n${value}`; window.externalLibrarySearchInput.value = ''; this.textareaBlurHandler(null, textarea); } render() { return (
Put each library in new line
Note: You can load external scripts only from following domains: localhost, https://ajax.googleapis.com, https://code.jquery.com, https://cdnjs.cloudflare.com, https://unpkg.com, https://maxcdn.com, https://cdn77.com, https://maxcdn.bootstrapcdn.com, https://cdn.jsdelivr.net/, https://rawgit.com, https://wzrd.in
Put each library in new line