|
| 1 | + |
| 2 | +import React, { Component } from 'react'; |
| 3 | +import {render} from 'react-dom'; |
| 4 | + |
| 5 | +import classNames from 'classnames'; |
| 6 | +import Dropzone from 'react-dropzone'; |
| 7 | + |
| 8 | +import { Form } from 'stardust'; |
| 9 | +import { Grid, Segment, Divider } from 'semantic-ui-react'; |
| 10 | + |
| 11 | +import * as types from '../constants/ActionTypes'; |
| 12 | + |
| 13 | +import EntryInput from '../containers/EntryInput'; |
| 14 | + |
| 15 | + |
| 16 | +export const SOURCEMAP_OFF = 'off' |
| 17 | +export const SOURCEMAP_INLINE = 'inline' |
| 18 | +export const SOURCEMAP_SEPARATE = 'separate' |
| 19 | + |
| 20 | +const SOURCEMAP_OPTIONS = [ |
| 21 | + { text: 'Off', value: SOURCEMAP_OFF }, |
| 22 | + { text: 'Inline', value: SOURCEMAP_INLINE }, |
| 23 | + { text: 'Separate', value: SOURCEMAP_SEPARATE }, |
| 24 | +]; |
| 25 | + |
| 26 | + |
| 27 | +class Options extends React.Component { |
| 28 | + |
| 29 | + componentWillMount() { |
| 30 | + this.store = this.context.store; |
| 31 | + } |
| 32 | + |
| 33 | + toggleOption(optionType) { |
| 34 | + this.store.dispatch({ |
| 35 | + 'type': optionType, |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + addDomainLock(domain) { |
| 40 | + this.store.dispatch({ |
| 41 | + 'type': types.ADD_DOMAIN_LOCK, |
| 42 | + domain, |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + removeDomainLock(domain) { |
| 47 | + this.store.dispatch({ |
| 48 | + 'type': types.REMOVE_DOMAIN_LOCK, |
| 49 | + domain, |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + addReservedName(name) { |
| 54 | + this.store.dispatch({ |
| 55 | + 'type': types.ADD_RESERVED_NAME, |
| 56 | + name, |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + removeReservedName(name) { |
| 61 | + this.store.dispatch({ |
| 62 | + 'type': types.REMOVE_RESERVED_NAME, |
| 63 | + name, |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + handleUnicodeThreshold(threshold) { |
| 68 | + this.store.dispatch({ |
| 69 | + 'type': types.SET_UNICODE_ARRAY_THRESHOLD, |
| 70 | + threshold, |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + handleSourceMapMode(mode) { |
| 75 | + this.store.dispatch({ |
| 76 | + 'type': types.SET_SOURCEMAP_MODE, |
| 77 | + mode, |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + handleSourceMapBaseUrl(baseUrl) { |
| 82 | + this.store.dispatch({ |
| 83 | + 'type': types.SET_SOURCEMAP_BASE_URL, |
| 84 | + baseUrl, |
| 85 | + }); |
| 86 | + } |
| 87 | + |
| 88 | + handleSourceMapFileName(fileName) { |
| 89 | + this.store.dispatch({ |
| 90 | + 'type': types.SET_SOURCEMAP_FILE_NAME, |
| 91 | + fileName, |
| 92 | + }); |
| 93 | + } |
| 94 | + |
| 95 | + render() { |
| 96 | + const state = this.store.getState().options; |
| 97 | + |
| 98 | + return ( |
| 99 | + <Form> |
| 100 | + <Grid columns={4} relaxed> |
| 101 | + <Grid.Column> |
| 102 | + <Segment basic> |
| 103 | + |
| 104 | + <Form.Checkbox |
| 105 | + label='Compact code' |
| 106 | + checked={state.compactCode} |
| 107 | + onChange={() => this.toggleOption(types.TOGGLE_COMPACT_CODE) } /> |
| 108 | + |
| 109 | + <Form.Checkbox |
| 110 | + label='Self Defending' |
| 111 | + checked={state.selfDefending} |
| 112 | + onChange={() => this.toggleOption(types.TOGGLE_SELF_DEFENDING) } /> |
| 113 | + |
| 114 | + <Divider /> |
| 115 | + |
| 116 | + <Form.Checkbox |
| 117 | + label='Disable Console Output' |
| 118 | + checked={state.disableConsoleOutput} |
| 119 | + onChange={() => this.toggleOption(types.TOGGLE_DISABLE_CONSOLE_OUTPUT) } /> |
| 120 | + |
| 121 | + <Divider /> |
| 122 | + |
| 123 | + <Form.Checkbox |
| 124 | + label='Debug Protection' |
| 125 | + checked={state.debugProtection} |
| 126 | + onChange={() => this.toggleOption(types.TOGGLE_DEBUG_PROTECTION) } /> |
| 127 | + |
| 128 | + <Form.Checkbox |
| 129 | + label='Debug Protection Interval' |
| 130 | + checked={state.debugProtectionInterval} |
| 131 | + disabled={!state.debugProtection} |
| 132 | + onChange={() => this.toggleOption(types.TOGGLE_DEBUG_PROTECTION_INTERVAL) } /> |
| 133 | + |
| 134 | + </Segment> |
| 135 | + </Grid.Column> |
| 136 | + |
| 137 | + <Divider vertical /> |
| 138 | + |
| 139 | + <Grid.Column> |
| 140 | + <Segment basic> |
| 141 | + |
| 142 | + <Form.Checkbox |
| 143 | + label='Unicode Array' |
| 144 | + checked={state.unicodeArray} |
| 145 | + onChange={() => this.toggleOption(types.TOGGLE_UNICODE_ARRAY) } /> |
| 146 | + |
| 147 | + <Form.Checkbox |
| 148 | + label='Rotate Unicode Array' |
| 149 | + checked={state.rotateUnicodeArray} |
| 150 | + disabled={!state.rotateUnicodeArrayEnabled} |
| 151 | + onChange={() => this.toggleOption(types.TOGGLE_ROTATE_UNICODE_ARRAY) } /> |
| 152 | + |
| 153 | + <Form.Checkbox |
| 154 | + label='Wrap Unicode Array Calls' |
| 155 | + checked={state.wrapUnicodeArrayCalls} |
| 156 | + disabled={!state.wrapUnicodeArrayCallsEnabled} |
| 157 | + onChange={() => this.toggleOption(types.TOGGLE_WRAP_UNICODE_ARRAY_CALLS) } /> |
| 158 | + |
| 159 | + <Form.Checkbox |
| 160 | + label='Encode Unicode Array Calls' |
| 161 | + checked={state.encodeUnicodeLiterals} |
| 162 | + disabled={!state.encodeUnicodeLiteralsEnabled} |
| 163 | + onChange={() => this.toggleOption(types.TOGGLE_ENCODE_UNICODE_LITERALS) } /> |
| 164 | + |
| 165 | + <Form.Input |
| 166 | + type='number' |
| 167 | + label='Unicode Array Threshold' |
| 168 | + defaultValue={state.unicodeArrayThreshold} |
| 169 | + min="0" |
| 170 | + max="1" |
| 171 | + step="0.1" |
| 172 | + onChange={(event) => this.handleUnicodeThreshold(event.target.value) } |
| 173 | + disabled={!state.unicodeArrayThresholdEnabled} /> |
| 174 | + |
| 175 | + </Segment> |
| 176 | + </Grid.Column> |
| 177 | + |
| 178 | + <Divider vertical /> |
| 179 | + |
| 180 | + <Grid.Column> |
| 181 | + <Segment basic> |
| 182 | + |
| 183 | + <Form.Select |
| 184 | + label='Sourcemaps' |
| 185 | + value={state.sourceMapMode} |
| 186 | + onChange={(event, value) => this.handleSourceMapMode(value) } |
| 187 | + options={SOURCEMAP_OPTIONS} /> |
| 188 | + |
| 189 | + <Form.Input |
| 190 | + label='Source Map Base URL' |
| 191 | + disabled={!state.sourceMapSeparate} |
| 192 | + onBlur={(event) => this.handleSourceMapBaseUrl(event.target.value) } |
| 193 | + defaultValue={state.sourceMapBaseUrl} |
| 194 | + placeholder='http://localhost:3000' /> |
| 195 | + |
| 196 | + <Form.Input |
| 197 | + label='Source Map File Name' |
| 198 | + disabled={!state.sourceMapSeparate} |
| 199 | + onChange={(event) => this.handleSourceMapFileName(event.target.value) } |
| 200 | + value={state.sourMapFileName} |
| 201 | + placeholder='example' /> |
| 202 | + |
| 203 | + </Segment> |
| 204 | + </Grid.Column> |
| 205 | + |
| 206 | + <Divider vertical /> |
| 207 | + <Grid.Column> |
| 208 | + <Segment basic> |
| 209 | + |
| 210 | + <EntryInput |
| 211 | + label='Add a domain lock' |
| 212 | + actionAddEntryToState={::this.addDomainLock} |
| 213 | + actionRemoveEntryFromState={::this.removeDomainLock} |
| 214 | + placeholder="domain.com" |
| 215 | + entries={state.domainLock} |
| 216 | + buttonIcon="plus" /> |
| 217 | + |
| 218 | + <EntryInput |
| 219 | + label='Reserved Names' |
| 220 | + actionAddEntryToState={::this.addReservedName} |
| 221 | + actionRemoveEntryFromState={::this.removeReservedName} |
| 222 | + placeholder="^someVariable" |
| 223 | + entries={state.reservedNames} |
| 224 | + buttonIcon="plus" /> |
| 225 | + |
| 226 | + </Segment> |
| 227 | + </Grid.Column> |
| 228 | + |
| 229 | + </Grid> |
| 230 | + </Form> |
| 231 | + |
| 232 | + ); |
| 233 | + |
| 234 | + } |
| 235 | + |
| 236 | +} |
| 237 | + |
| 238 | +Options.contextTypes = { |
| 239 | + store: React.PropTypes.object |
| 240 | +}; |
| 241 | + |
| 242 | +export default Options; |
0 commit comments