diff --git a/webmaker/src/components/AddLibrary.jsx b/webmaker/src/components/AddLibrary.jsx index 94df91f..1ee76a0 100644 --- a/webmaker/src/components/AddLibrary.jsx +++ b/webmaker/src/components/AddLibrary.jsx @@ -1,6 +1,7 @@ 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) { @@ -20,6 +21,10 @@ export default class AddLibrary extends Component { 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); @@ -27,17 +32,51 @@ export default class AddLibrary extends Component { // 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 (

Add Library

- +
+ + + + + + +
Powered by cdnjs
@@ -66,7 +105,9 @@ export default class AddLibrary extends Component {
-

JavaScript

+

JS

+

Put each library in new line

+

Note: You can load external scripts from following domains: localhost, https://ajax.googleapis.com, https://code.jquery.com, @@ -76,23 +117,27 @@ export default class AddLibrary extends Component {