2017-11-15 15:13:49 +01:00
|
|
|
// import polyfill
|
|
|
|
import 'babel-polyfill';
|
|
|
|
|
|
|
|
// inject tap event plugin
|
|
|
|
import injectTapEventPlugin from 'react-tap-event-plugin';
|
|
|
|
injectTapEventPlugin();
|
|
|
|
|
|
|
|
// create store
|
|
|
|
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
|
|
|
|
import thunkMiddleware from 'redux-thunk';
|
|
|
|
import promiseMiddleware from 'redux-promise-middleware';
|
|
|
|
import { createLogger } from 'redux-logger';
|
2017-12-07 16:20:18 +01:00
|
|
|
import sketcherReducer from './src/reducer/index.js';
|
2018-01-25 16:40:10 +01:00
|
|
|
|
2017-11-15 15:13:49 +01:00
|
|
|
const reducer = combineReducers({ sketcher: sketcherReducer });
|
|
|
|
const enhancer = compose(applyMiddleware(thunkMiddleware, promiseMiddleware(), createLogger({ collapsed: true })));
|
|
|
|
const store = createStore(reducer, enhancer);
|
|
|
|
|
2017-12-12 11:42:06 +01:00
|
|
|
// add actions to window
|
2017-11-17 23:34:20 +01:00
|
|
|
import actionWrapper from 'redux-action-wrapper';
|
2017-11-17 22:22:36 +01:00
|
|
|
import * as actions from './src/actions/index.js';
|
2017-11-17 23:34:20 +01:00
|
|
|
window.actions = actionWrapper(actions, store.dispatch);
|
2017-12-14 14:00:16 +01:00
|
|
|
import { saveAs as saveAsLib } from 'file-saver';
|
|
|
|
|
|
|
|
// download file
|
|
|
|
import { createFile } from './src/utils/exportUtils.js';
|
2018-01-25 16:40:10 +01:00
|
|
|
import sketchDataToJSON from './src/shape/sketchDataToJSON.js';
|
|
|
|
import { JSONToBlob } from './src/utils/binaryUtils.js';
|
|
|
|
|
2018-03-09 15:59:43 +01:00
|
|
|
//usage: downloadStl({lineWidth:20})
|
|
|
|
window.downloadStl = (options) => {
|
2017-12-14 14:00:16 +01:00
|
|
|
store.dispatch(async (dispatch, getState) => {
|
|
|
|
const state = getState();
|
2018-03-09 15:59:43 +01:00
|
|
|
const blob = await createFile(state.sketcher.present, 'stl-blob', options);
|
2017-12-14 14:00:16 +01:00
|
|
|
saveAsLib(blob, 'doodle.stl');
|
|
|
|
});
|
|
|
|
};
|
2017-11-17 22:22:36 +01:00
|
|
|
|
2018-01-25 16:40:10 +01:00
|
|
|
window.downloadSketch = () => {
|
2018-02-14 14:53:07 +01:00
|
|
|
store.dispatch((dispatch, getState) => {
|
2018-01-25 16:40:10 +01:00
|
|
|
const state = getState();
|
|
|
|
const json = sketchDataToJSON(state.sketcher.present);
|
|
|
|
const blob = JSONToBlob(json);
|
|
|
|
saveAsLib(blob, 'doodle.d3sketch');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-02-21 12:28:17 +01:00
|
|
|
// import keycode from 'keycode';
|
|
|
|
// window.addEventListener('keydown', (event) => {
|
|
|
|
// // downloadSketch
|
|
|
|
// const key = keycode(event);
|
|
|
|
// if (key === 's') window.downloadSketch();
|
|
|
|
// });
|
2018-01-25 16:40:10 +01:00
|
|
|
|
|
|
|
|
2017-12-12 11:42:06 +01:00
|
|
|
// add model to store
|
2018-01-06 20:27:09 +01:00
|
|
|
import modelData from './models/circle_error.d3sketch';
|
2017-12-07 16:21:27 +01:00
|
|
|
import JSONToSketchData from './src/shape/JSONToSketchData.js';
|
2018-02-21 12:29:33 +01:00
|
|
|
JSONToSketchData(JSON.parse(modelData)).then(data => {
|
|
|
|
store.dispatch(actions.openSketch({ data }));
|
2017-12-12 11:42:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// default css
|
|
|
|
import jss from 'jss';
|
|
|
|
import preset from 'jss-preset-default';
|
|
|
|
import normalize from 'normalize-jss';
|
|
|
|
jss.setup(preset());
|
2017-12-14 11:18:41 +01:00
|
|
|
jss.createStyleSheet(normalize).attach();
|
2017-12-12 11:42:06 +01:00
|
|
|
jss.createStyleSheet({
|
2017-12-14 11:18:41 +01:00
|
|
|
'@global': {
|
|
|
|
'*': { margin: 0, padding: 0 },
|
|
|
|
'#app, body, html': { height: '100%', fontFamily: 'sans-serif' },
|
|
|
|
body: { overflow: 'auto' },
|
|
|
|
html: { overflow: 'hidden' }
|
|
|
|
}
|
2017-12-12 11:42:06 +01:00
|
|
|
}).attach();
|
2017-11-18 21:21:16 +01:00
|
|
|
|
2017-11-15 15:13:49 +01:00
|
|
|
// render dom
|
|
|
|
import React from 'react';
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { render } from 'react-dom';
|
|
|
|
import App from './src/components/App.js';
|
|
|
|
|
2017-12-07 16:21:10 +01:00
|
|
|
async function init() {
|
|
|
|
if (process.env.TARGET === 'app') {
|
|
|
|
await new Promise(resolve => document.addEventListener('deviceready', resolve, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
render((
|
|
|
|
<Provider store={store}>
|
2018-02-14 17:20:30 +01:00
|
|
|
<App />
|
2017-12-07 16:21:10 +01:00
|
|
|
</Provider>
|
|
|
|
), document.getElementById('app'));
|
|
|
|
}
|
|
|
|
init();
|