添加设置边框及边框颜色的功能

This commit is contained in:
yi-ge 2019-08-03 22:59:15 +08:00
parent 7b0ff36db6
commit dbc1c15023
8 changed files with 3515 additions and 3560 deletions

View File

@ -1,4 +1,4 @@
## Office Table 转 HTML Table
# Office Table 转 HTML Table
Office Table 转 HTML Table。

View File

@ -1,19 +1,20 @@
{
"name": "office2table",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"axios": "^0.19.0",
"clean-css": "^4.2.1",
"css": "^2.2.4",
"jotform-css.js": "^1.0.1",
"minify": "^4.1.0",
"postcss": "^7.0.14",
"minify": "^4.1.3",
"postcss": "^7.0.17",
"postcss-remove-unused": "^1.2.0",
"prettier": "^1.16.1",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.3"
"prettier": "^1.18.2",
"react": "^16.8.6",
"react-color": "^2.17.3",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",

View File

@ -65,6 +65,7 @@ body {
.PowerType {
max-width: 320px;
min-height: 300px;
width: 100%;
margin: auto;
text-align: left;
@ -101,7 +102,12 @@ body {
width: 150px;
margin-top: -25px;
margin-left: -75px;
}
#colorPicker {
position: absolute;
right: 100px;
top: 20px;
}
.object {

View File

@ -1,14 +1,19 @@
import React, { Component } from 'react';
import './App.css';
import Axios from 'axios';
const removeUnused = require('postcss-remove-unused');
const postcss = require('postcss');
const prettier = require("prettier/standalone");
const plugins = [require("prettier/parser-html"), require("prettier/parser-postcss")];
import axios from 'axios';
import {
SketchPicker
} from 'react-color'
const removeUnused = require('postcss-remove-unused')
const postcss = require('postcss')
const prettier = require("prettier/standalone")
const plugins = [require("prettier/parser-html"), require("prettier/parser-postcss")]
const CSS = require('css')
const cssjs = require("jotform-css.js");
const cssjs = require("jotform-css.js")
//initialize parser object
const parser = new cssjs.cssjs();
const parser = new cssjs.cssjs()
const request = axios.create()
// 移除指定标签
function removeTags(tagName, el = document){
@ -230,7 +235,10 @@ class App extends Component {
compress: false,
removeAllCSS: false,
removeTableWidth: false,
percent: false
percent: false,
border: false,
borderColor: false,
borderColorValue: '#000'
};
}
@ -347,6 +355,23 @@ class App extends Component {
removeStyleatt(p)
}
// 添加边框
if (this.state.border) {
const tableObjects = p.getElementsByTagName('table')
for (let ob = tableObjects.length - 1; ob >= 0; ob--) {
tableObjects[ob].setAttribute("border", "1")
tableObjects[ob].style.borderCollapse = "collapse"
}
}
// 添加边框颜色
if (this.state.borderColor) {
const tableObjects = p.getElementsByTagName('table')
for (let ob = tableObjects.length - 1; ob >= 0; ob--) {
tableObjects[ob].setAttribute("bordercolor", this.state.borderColorValue)
}
}
finalCode = p.body.innerHTML
finalCode = prettier.format(finalCode, { parser: "html", plugins });
@ -354,7 +379,7 @@ class App extends Component {
if (this.state.compress) {
const {
data
} = await Axios.post('https://minifier.yige.ink', {
} = await request.post('https://minifier.yige.ink', {
code: finalCode
})
@ -363,6 +388,8 @@ class App extends Component {
}
}
p.body.innerHTML = finalCode;
this.setState(() => ({html: finalCode}));
this.textInput.style.backgroundColor="#7a9a95";
this.textareaInput.focus();
@ -390,6 +417,12 @@ class App extends Component {
this.setState(state)
}
handleBorderColorChangeComplete = (color) => {
this.setState({
borderColorValue: color.hex
});
}
render() {
return (
<div className="App">
@ -430,7 +463,19 @@ class App extends Component {
<label ><input type="checkbox" name='type' value="removeTableWidth" checked={this.state.removeTableWidth === true}
onChange={this.boxChange}/>移除表格宽度</label><br/>
<label ><input type="checkbox" name='type' value="percent" checked={this.state.percent === true}
onChange={this.boxChange}/>将表格宽度转换为百分比</label>
onChange={this.boxChange}/>将表格宽度转换为百分比</label><br/>
<label ><input type="checkbox" name='type' value="border" checked={this.state.border === true}
onChange={this.boxChange}/>添加表格默认边框</label><br/>
<label ><input type="checkbox" name='type' value="borderColor" checked={this.state.borderColor === true}
onChange={this.boxChange}/>添加表格默认边框颜色</label><br/>
<div id="colorPicker"><SketchPicker
color = {
this.state.borderColorValue
}
onChangeComplete = {
this.handleBorderColorChangeComplete
}
/></div>
</div>
</div>
<input type="text" id="input" value={this.state.value} onFocus={this.inputFocus} onBlur={this.inputBlur} onPaste={this.inputPaste} ref={(input) => { this.textInput = input; }} readOnly/>

View File

@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
it('renders without crashing', () => { // eslint-disable-line
const div = document.createElement('div')
ReactDOM.render(<App />, div)
ReactDOM.unmountComponentAtNode(div)
})

View File

@ -4,7 +4,7 @@ import './index.css'
import App from './App'
import * as serviceWorker from './serviceWorker'
ReactDOM.render( < App / > , document.getElementById('root'))
ReactDOM.render(<App />, document.getElementById('root'))
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
@ -22,5 +22,5 @@ String.prototype.replaceAll = function (s1, s2) {
// data = str1 + '<img src="' + src + j + '.gif">' + str2;
// }
// }
return this.replace(new RegExp(s1, "gm"), s2);
}
return this.replace(new RegExp(s1, 'gm'), s2)
}

View File

@ -18,25 +18,25 @@ const isLocalhost = Boolean(
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
)
export function register(config) {
export function register (config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
return
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
checkValidServiceWorker(swUrl, config)
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
@ -44,24 +44,24 @@ export function register(config) {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit http://bit.ly/CRA-PWA'
);
});
)
})
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
registerValidSW(swUrl, config)
}
});
})
}
}
function registerValidSW(swUrl, config) {
function registerValidSW (swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
const installingWorker = registration.installing
if (installingWorker == null) {
return;
return
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
@ -72,38 +72,38 @@ function registerValidSW(swUrl, config) {
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
);
)
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
config.onUpdate(registration)
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log('Content is cached for offline use.')
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
config.onSuccess(registration)
}
}
}
};
};
}
}
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
console.error('Error during service worker registration:', error)
})
}
function checkValidServiceWorker(swUrl, config) {
function checkValidServiceWorker (swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
fetch(swUrl) // eslint-disable-line
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
const contentType = response.headers.get('content-type')
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
@ -111,25 +111,25 @@ function checkValidServiceWorker(swUrl, config) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
window.location.reload()
})
})
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
registerValidSW(swUrl, config)
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
)
})
}
export function unregister() {
export function unregister () {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
registration.unregister()
})
}
}

6897
yarn.lock

File diff suppressed because it is too large Load Diff