添加设置边框及边框颜色的功能
This commit is contained in:
parent
7b0ff36db6
commit
dbc1c15023
@ -1,4 +1,4 @@
|
|||||||
## Office Table 转 HTML Table
|
# Office Table 转 HTML Table
|
||||||
|
|
||||||
Office Table 转 HTML Table。
|
Office Table 转 HTML Table。
|
||||||
|
|
||||||
|
17
package.json
17
package.json
@ -1,19 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "office2table",
|
"name": "office2table",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.19.0",
|
||||||
"clean-css": "^4.2.1",
|
"clean-css": "^4.2.1",
|
||||||
"css": "^2.2.4",
|
"css": "^2.2.4",
|
||||||
"jotform-css.js": "^1.0.1",
|
"jotform-css.js": "^1.0.1",
|
||||||
"minify": "^4.1.0",
|
"minify": "^4.1.3",
|
||||||
"postcss": "^7.0.14",
|
"postcss": "^7.0.17",
|
||||||
"postcss-remove-unused": "^1.2.0",
|
"postcss-remove-unused": "^1.2.0",
|
||||||
"prettier": "^1.16.1",
|
"prettier": "^1.18.2",
|
||||||
"react": "^16.7.0",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.7.0",
|
"react-color": "^2.17.3",
|
||||||
"react-scripts": "2.1.3"
|
"react-dom": "^16.8.6",
|
||||||
|
"react-scripts": "3.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
@ -65,6 +65,7 @@ body {
|
|||||||
|
|
||||||
.PowerType {
|
.PowerType {
|
||||||
max-width: 320px;
|
max-width: 320px;
|
||||||
|
min-height: 300px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
@ -101,7 +102,12 @@ body {
|
|||||||
width: 150px;
|
width: 150px;
|
||||||
margin-top: -25px;
|
margin-top: -25px;
|
||||||
margin-left: -75px;
|
margin-left: -75px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#colorPicker {
|
||||||
|
position: absolute;
|
||||||
|
right: 100px;
|
||||||
|
top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.object {
|
.object {
|
||||||
|
65
src/App.js
65
src/App.js
@ -1,14 +1,19 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import Axios from 'axios';
|
import axios from 'axios';
|
||||||
const removeUnused = require('postcss-remove-unused');
|
import {
|
||||||
const postcss = require('postcss');
|
SketchPicker
|
||||||
const prettier = require("prettier/standalone");
|
} from 'react-color'
|
||||||
const plugins = [require("prettier/parser-html"), require("prettier/parser-postcss")];
|
|
||||||
|
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 CSS = require('css')
|
||||||
const cssjs = require("jotform-css.js");
|
const cssjs = require("jotform-css.js")
|
||||||
//initialize parser object
|
//initialize parser object
|
||||||
const parser = new cssjs.cssjs();
|
const parser = new cssjs.cssjs()
|
||||||
|
const request = axios.create()
|
||||||
|
|
||||||
// 移除指定标签
|
// 移除指定标签
|
||||||
function removeTags(tagName, el = document){
|
function removeTags(tagName, el = document){
|
||||||
@ -230,7 +235,10 @@ class App extends Component {
|
|||||||
compress: false,
|
compress: false,
|
||||||
removeAllCSS: false,
|
removeAllCSS: false,
|
||||||
removeTableWidth: false,
|
removeTableWidth: false,
|
||||||
percent: false
|
percent: false,
|
||||||
|
border: false,
|
||||||
|
borderColor: false,
|
||||||
|
borderColorValue: '#000'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,6 +355,23 @@ class App extends Component {
|
|||||||
removeStyleatt(p)
|
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 = p.body.innerHTML
|
||||||
finalCode = prettier.format(finalCode, { parser: "html", plugins });
|
finalCode = prettier.format(finalCode, { parser: "html", plugins });
|
||||||
|
|
||||||
@ -354,7 +379,7 @@ class App extends Component {
|
|||||||
if (this.state.compress) {
|
if (this.state.compress) {
|
||||||
const {
|
const {
|
||||||
data
|
data
|
||||||
} = await Axios.post('https://minifier.yige.ink', {
|
} = await request.post('https://minifier.yige.ink', {
|
||||||
code: finalCode
|
code: finalCode
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -363,6 +388,8 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.body.innerHTML = finalCode;
|
||||||
|
|
||||||
this.setState(() => ({html: finalCode}));
|
this.setState(() => ({html: finalCode}));
|
||||||
this.textInput.style.backgroundColor="#7a9a95";
|
this.textInput.style.backgroundColor="#7a9a95";
|
||||||
this.textareaInput.focus();
|
this.textareaInput.focus();
|
||||||
@ -390,6 +417,12 @@ class App extends Component {
|
|||||||
this.setState(state)
|
this.setState(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBorderColorChangeComplete = (color) => {
|
||||||
|
this.setState({
|
||||||
|
borderColorValue: color.hex
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
@ -430,7 +463,19 @@ class App extends Component {
|
|||||||
<label ><input type="checkbox" name='type' value="removeTableWidth" checked={this.state.removeTableWidth === true}
|
<label ><input type="checkbox" name='type' value="removeTableWidth" checked={this.state.removeTableWidth === true}
|
||||||
onChange={this.boxChange}/>移除表格宽度</label><br/>
|
onChange={this.boxChange}/>移除表格宽度</label><br/>
|
||||||
<label ><input type="checkbox" name='type' value="percent" checked={this.state.percent === true}
|
<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>
|
||||||
</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/>
|
<input type="text" id="input" value={this.state.value} onFocus={this.inputFocus} onBlur={this.inputBlur} onPaste={this.inputPaste} ref={(input) => { this.textInput = input; }} readOnly/>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom'
|
||||||
import App from './App';
|
import App from './App'
|
||||||
|
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => { // eslint-disable-line
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div')
|
||||||
ReactDOM.render(<App />, div);
|
ReactDOM.render(<App />, div)
|
||||||
ReactDOM.unmountComponentAtNode(div);
|
ReactDOM.unmountComponentAtNode(div)
|
||||||
});
|
})
|
||||||
|
@ -4,7 +4,7 @@ import './index.css'
|
|||||||
import App from './App'
|
import App from './App'
|
||||||
import * as serviceWorker from './serviceWorker'
|
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
|
// If you want your app to work offline and load faster, you can change
|
||||||
// unregister() to register() below. Note this comes with some pitfalls.
|
// 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;
|
// data = str1 + '<img src="' + src + j + '.gif">' + str2;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
return this.replace(new RegExp(s1, "gm"), s2);
|
return this.replace(new RegExp(s1, 'gm'), s2)
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,25 @@ const isLocalhost = Boolean(
|
|||||||
window.location.hostname.match(
|
window.location.hostname.match(
|
||||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
/^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) {
|
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||||
// The URL constructor is available in all browsers that support SW.
|
// 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) {
|
if (publicUrl.origin !== window.location.origin) {
|
||||||
// Our service worker won't work if PUBLIC_URL is on a different 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
|
// 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
|
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
|
||||||
|
|
||||||
if (isLocalhost) {
|
if (isLocalhost) {
|
||||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
// 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
|
// Add some additional logging to localhost, pointing developers to the
|
||||||
// service worker/PWA documentation.
|
// service worker/PWA documentation.
|
||||||
@ -44,24 +44,24 @@ export function register(config) {
|
|||||||
console.log(
|
console.log(
|
||||||
'This web app is being served cache-first by a service ' +
|
'This web app is being served cache-first by a service ' +
|
||||||
'worker. To learn more, visit http://bit.ly/CRA-PWA'
|
'worker. To learn more, visit http://bit.ly/CRA-PWA'
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
// Is not localhost. Just register service worker
|
// Is not localhost. Just register service worker
|
||||||
registerValidSW(swUrl, config);
|
registerValidSW(swUrl, config)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerValidSW(swUrl, config) {
|
function registerValidSW (swUrl, config) {
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register(swUrl)
|
.register(swUrl)
|
||||||
.then(registration => {
|
.then(registration => {
|
||||||
registration.onupdatefound = () => {
|
registration.onupdatefound = () => {
|
||||||
const installingWorker = registration.installing;
|
const installingWorker = registration.installing
|
||||||
if (installingWorker == null) {
|
if (installingWorker == null) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
installingWorker.onstatechange = () => {
|
installingWorker.onstatechange = () => {
|
||||||
if (installingWorker.state === 'installed') {
|
if (installingWorker.state === 'installed') {
|
||||||
@ -72,38 +72,38 @@ function registerValidSW(swUrl, config) {
|
|||||||
console.log(
|
console.log(
|
||||||
'New content is available and will be used when all ' +
|
'New content is available and will be used when all ' +
|
||||||
'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
|
'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
|
||||||
);
|
)
|
||||||
|
|
||||||
// Execute callback
|
// Execute callback
|
||||||
if (config && config.onUpdate) {
|
if (config && config.onUpdate) {
|
||||||
config.onUpdate(registration);
|
config.onUpdate(registration)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// At this point, everything has been precached.
|
// At this point, everything has been precached.
|
||||||
// It's the perfect time to display a
|
// It's the perfect time to display a
|
||||||
// "Content is cached for offline use." message.
|
// "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
|
// Execute callback
|
||||||
if (config && config.onSuccess) {
|
if (config && config.onSuccess) {
|
||||||
config.onSuccess(registration);
|
config.onSuccess(registration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.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.
|
// Check if the service worker can be found. If it can't reload the page.
|
||||||
fetch(swUrl)
|
fetch(swUrl) // eslint-disable-line
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// Ensure service worker exists, and that we really are getting a JS file.
|
// 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 (
|
if (
|
||||||
response.status === 404 ||
|
response.status === 404 ||
|
||||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
(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.
|
// No service worker found. Probably a different app. Reload the page.
|
||||||
navigator.serviceWorker.ready.then(registration => {
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
registration.unregister().then(() => {
|
registration.unregister().then(() => {
|
||||||
window.location.reload();
|
window.location.reload()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
// Service worker found. Proceed as normal.
|
// Service worker found. Proceed as normal.
|
||||||
registerValidSW(swUrl, config);
|
registerValidSW(swUrl, config)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.log(
|
console.log(
|
||||||
'No internet connection found. App is running in offline mode.'
|
'No internet connection found. App is running in offline mode.'
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unregister() {
|
export function unregister () {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.ready.then(registration => {
|
navigator.serviceWorker.ready.then(registration => {
|
||||||
registration.unregister();
|
registration.unregister()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user