mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-17 12:01:13 +02:00
port atomic css
This commit is contained in:
@@ -14,6 +14,12 @@ export default class CodeMirrorBox extends Component {
|
|||||||
initEditor() {
|
initEditor() {
|
||||||
const options = this.props.options;
|
const options = this.props.options;
|
||||||
this.cm = CodeMirror.fromTextArea(this.textarea, this.props.options);
|
this.cm = CodeMirror.fromTextArea(this.textarea, this.props.options);
|
||||||
|
if (this.props.onChange) {
|
||||||
|
this.cm.on('change', this.props.onChange);
|
||||||
|
}
|
||||||
|
if (this.props.onBlur) {
|
||||||
|
this.cm.on('blur', this.props.onBlur);
|
||||||
|
}
|
||||||
this.props.onCreation(this.cm);
|
this.props.onCreation(this.cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ import { trackEvent } from '../analytics';
|
|||||||
import CodeMirror from '../CodeMirror';
|
import CodeMirror from '../CodeMirror';
|
||||||
import CodeMirrorBox from './CodeMirrorBox';
|
import CodeMirrorBox from './CodeMirrorBox';
|
||||||
import { deferred } from '../deferred';
|
import { deferred } from '../deferred';
|
||||||
|
import CssSettingsModal from './CssSettingsModal';
|
||||||
|
|
||||||
const BASE_PATH = chrome.extension || window.DEBUG ? '/' : '/app';
|
const BASE_PATH = chrome.extension || window.DEBUG ? '/' : '/app';
|
||||||
const minCodeWrapSize = 33;
|
const minCodeWrapSize = 33;
|
||||||
@@ -159,6 +160,7 @@ export default class ContentWrap extends Component {
|
|||||||
? this.detachedWindow.document.querySelector('iframe')
|
? this.detachedWindow.document.querySelector('iframe')
|
||||||
: this.frame;
|
: this.frame;
|
||||||
|
|
||||||
|
const cssMode = this.props.currentItem.cssMode;
|
||||||
// If just CSS was changed (and everything shudn't be empty),
|
// If just CSS was changed (and everything shudn't be empty),
|
||||||
// change the styles inside the iframe.
|
// change the styles inside the iframe.
|
||||||
if (
|
if (
|
||||||
@@ -166,9 +168,12 @@ export default class ContentWrap extends Component {
|
|||||||
currentCode.html === this.codeInPreview.html &&
|
currentCode.html === this.codeInPreview.html &&
|
||||||
currentCode.js === this.codeInPreview.js
|
currentCode.js === this.codeInPreview.js
|
||||||
) {
|
) {
|
||||||
computeCss(currentCode.css, this.props.currentItem.cssMode).then(function(
|
computeCss(
|
||||||
css
|
cssMode === CssModes.ACSS ? currentCode.html : currentCode.css,
|
||||||
) {
|
cssMode,
|
||||||
|
this.props.currentItem.cssSettings
|
||||||
|
).then(function(css) {
|
||||||
|
this.cm.css.setValue(css);
|
||||||
if (targetFrame.contentDocument.querySelector('#webmakerstyle')) {
|
if (targetFrame.contentDocument.querySelector('#webmakerstyle')) {
|
||||||
targetFrame.contentDocument.querySelector(
|
targetFrame.contentDocument.querySelector(
|
||||||
'#webmakerstyle'
|
'#webmakerstyle'
|
||||||
@@ -181,11 +186,15 @@ export default class ContentWrap extends Component {
|
|||||||
this.props.currentItem.htmlMode
|
this.props.currentItem.htmlMode
|
||||||
);
|
);
|
||||||
var cssPromise = computeCss(
|
var cssPromise = computeCss(
|
||||||
currentCode.css,
|
cssMode === CssModes.ACSS ? currentCode.html : currentCode.css,
|
||||||
this.props.currentItem.cssMode
|
cssMode,
|
||||||
|
this.props.currentItem.cssSettings
|
||||||
);
|
);
|
||||||
var jsPromise = computeJs(currentCode.js, this.props.currentItem.jsMode);
|
var jsPromise = computeJs(currentCode.js, this.props.currentItem.jsMode);
|
||||||
Promise.all([htmlPromise, cssPromise, jsPromise]).then(result => {
|
Promise.all([htmlPromise, cssPromise, jsPromise]).then(result => {
|
||||||
|
if (result[1]) {
|
||||||
|
this.cm.css.setValue(result[1]);
|
||||||
|
}
|
||||||
this.createPreviewFile(result[0], result[1], result[2]);
|
this.createPreviewFile(result[0], result[1], result[2]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -198,7 +207,10 @@ export default class ContentWrap extends Component {
|
|||||||
return !!item.title;
|
return !!item.title;
|
||||||
}
|
}
|
||||||
shouldComponentUpdate(nextProps, nextState) {
|
shouldComponentUpdate(nextProps, nextState) {
|
||||||
return this.state.isConsoleOpen !== nextState.isConsoleOpen;
|
return (
|
||||||
|
this.state.isConsoleOpen !== nextState.isConsoleOpen ||
|
||||||
|
this.state.isCssSettingsModalOpen !== nextState.isCssSettingsModalOpen
|
||||||
|
);
|
||||||
}
|
}
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
// HACK: becuase its a DOM manipulation
|
// HACK: becuase its a DOM manipulation
|
||||||
@@ -457,9 +469,9 @@ export default class ContentWrap extends Component {
|
|||||||
cssModeLabel.parentElement.querySelector('select').value = value;
|
cssModeLabel.parentElement.querySelector('select').value = value;
|
||||||
this.cm.css.setOption('mode', modes[value].cmMode);
|
this.cm.css.setOption('mode', modes[value].cmMode);
|
||||||
this.cm.css.setOption('readOnly', modes[value].cmDisable);
|
this.cm.css.setOption('readOnly', modes[value].cmDisable);
|
||||||
// cssSettingsBtn.classList[modes[value].hasSettings ? 'remove' : 'add'](
|
window.cssSettingsBtn.classList[
|
||||||
// 'hide'
|
modes[value].hasSettings ? 'remove' : 'add'
|
||||||
// );
|
]('hide');
|
||||||
CodeMirror.autoLoadMode(
|
CodeMirror.autoLoadMode(
|
||||||
this.cm.css,
|
this.cm.css,
|
||||||
modes[value].cmPath || modes[value].cmMode
|
modes[value].cmPath || modes[value].cmMode
|
||||||
@@ -606,6 +618,14 @@ export default class ContentWrap extends Component {
|
|||||||
trackEvent('fn', 'evalConsoleExpr');
|
trackEvent('fn', 'evalConsoleExpr');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cssSettingsBtnClickHandler() {
|
||||||
|
this.setState({ isCssSettingsModalOpen: true });
|
||||||
|
trackEvent('ui', 'cssSettingsBtnClick');
|
||||||
|
}
|
||||||
|
cssSettingsChangeHandler(settings) {
|
||||||
|
this.props.onCodeSettingsChange('css', settings);
|
||||||
|
this.setPreviewContent(true);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@@ -714,10 +734,12 @@ export default class ContentWrap extends Component {
|
|||||||
href="#"
|
href="#"
|
||||||
id="cssSettingsBtn"
|
id="cssSettingsBtn"
|
||||||
title="Atomic CSS configuration"
|
title="Atomic CSS configuration"
|
||||||
d-click="openCssSettingsModal"
|
onClick={this.cssSettingsBtnClickHandler.bind(this)}
|
||||||
class="code-wrap__header-btn hide"
|
class="code-wrap__header-btn hide"
|
||||||
>
|
>
|
||||||
Settings
|
<svg>
|
||||||
|
<use xlinkHref="#settings-icon" />
|
||||||
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
class="js-code-collapse-btn code-wrap__header-btn code-wrap__collapse-btn"
|
class="js-code-collapse-btn code-wrap__header-btn code-wrap__collapse-btn"
|
||||||
@@ -739,7 +761,6 @@ export default class ContentWrap extends Component {
|
|||||||
onChange={this.onCssCodeChange.bind(this)}
|
onChange={this.onCssCodeChange.bind(this)}
|
||||||
onCreation={el => (this.cm.css = el)}
|
onCreation={el => (this.cm.css = el)}
|
||||||
/>
|
/>
|
||||||
{/* Inlet(scope.cm.css); */}
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
data-code-wrap-id="2"
|
data-code-wrap-id="2"
|
||||||
@@ -855,6 +876,15 @@ export default class ContentWrap extends Component {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<CssSettingsModal
|
||||||
|
show={this.state.isCssSettingsModalOpen}
|
||||||
|
closeHandler={() =>
|
||||||
|
this.setState({ isCssSettingsModalOpen: false })
|
||||||
|
}
|
||||||
|
onChange={this.cssSettingsChangeHandler.bind(this)}
|
||||||
|
settings={this.props.currentItem.cssSettings}
|
||||||
|
editorTheme={this.props.prefs.editorTheme}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
);
|
);
|
||||||
|
43
webmaker/src/components/CssSettingsModal.jsx
Normal file
43
webmaker/src/components/CssSettingsModal.jsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { h, Component } from 'preact';
|
||||||
|
import Modal from './Modal';
|
||||||
|
import CodeMirrorBox from './CodeMirrorBox';
|
||||||
|
|
||||||
|
export default class CssSettingsModal extends Component {
|
||||||
|
componentDidUpdate() {
|
||||||
|
if (this.props.show) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.props.settings) {
|
||||||
|
this.cm.setValue(this.props.settings.acssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh is required because codemirror gets scaled inside modal and loses alignement.
|
||||||
|
this.cm.refresh();
|
||||||
|
this.cm.focus();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Modal show={this.props.show} closeHandler={this.props.closeHandler}>
|
||||||
|
<h1>Atomic CSS Settings</h1>
|
||||||
|
<h3>
|
||||||
|
Configure Atomizer settings.{' '}
|
||||||
|
<a href="https://github.com/acss-io/atomizer#api" target="_blank">
|
||||||
|
Read more
|
||||||
|
</a>{' '}
|
||||||
|
about available settings.
|
||||||
|
</h3>
|
||||||
|
<div style="height: calc(100vh - 350px);">
|
||||||
|
<CodeMirrorBox
|
||||||
|
options={{
|
||||||
|
mode: 'application/ld+json',
|
||||||
|
theme: this.props.editorTheme
|
||||||
|
}}
|
||||||
|
onCreation={cm => (this.cm = cm)}
|
||||||
|
onBlur={cm => this.props.onChange(cm.getValue())}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -33,7 +33,8 @@ export class SplitPane extends Component {
|
|||||||
if (this.props.onDragStart) {
|
if (this.props.onDragStart) {
|
||||||
options.onDragStart = this.props.onDragStart;
|
options.onDragStart = this.props.onDragStart;
|
||||||
}
|
}
|
||||||
log('SIZE UPDATED', options);
|
// debugger;
|
||||||
|
// log('SIZE UPDATED', options);
|
||||||
|
|
||||||
this.splitInstance = Split(
|
this.splitInstance = Split(
|
||||||
this.props.children.map(node => '#' + node.attributes.id),
|
this.props.children.map(node => '#' + node.attributes.id),
|
||||||
|
@@ -526,14 +526,6 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveCode(key) {
|
saveCode(key) {
|
||||||
// currentItem.htmlMode = htmlMode;
|
|
||||||
// currentItem.cssMode = cssMode;
|
|
||||||
// currentItem.jsMode = jsMode;
|
|
||||||
if (modes['css' || cssMode].hasSettings) {
|
|
||||||
this.state.currentItem.cssSettings = {
|
|
||||||
acssConfig: scope.acssSettingsCm.getValue()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
this.state.currentItem.updatedOn = Date.now();
|
this.state.currentItem.updatedOn = Date.now();
|
||||||
this.state.currentItem.layoutMode = this.state.currentLayoutMode;
|
this.state.currentItem.layoutMode = this.state.currentLayoutMode;
|
||||||
|
|
||||||
@@ -625,6 +617,11 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onCodeSettingsChange(type, settings) {
|
||||||
|
this.state.currentItem[`${type}Settings`] = {
|
||||||
|
acssConfig: settings
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
titleInputBlurHandler(e) {
|
titleInputBlurHandler(e) {
|
||||||
this.state.currentItem.title = e.target.value;
|
this.state.currentItem.title = e.target.value;
|
||||||
@@ -678,11 +675,6 @@ export default class App extends Component {
|
|||||||
|
|
||||||
this.contentWrap.applyCodemirrorSettings(this.state.prefs);
|
this.contentWrap.applyCodemirrorSettings(this.state.prefs);
|
||||||
|
|
||||||
/*
|
|
||||||
scope.acssSettingsCm.setOption(
|
|
||||||
'theme',
|
|
||||||
$('[data-setting=editorTheme]').value
|
|
||||||
); */
|
|
||||||
if (prefs.autoSave) {
|
if (prefs.autoSave) {
|
||||||
if (!this.autoSaveInterval) {
|
if (!this.autoSaveInterval) {
|
||||||
this.autoSaveInterval = setInterval(() => {
|
this.autoSaveInterval = setInterval(() => {
|
||||||
@@ -872,6 +864,7 @@ export default class App extends Component {
|
|||||||
currentLayoutMode={this.state.currentLayoutMode}
|
currentLayoutMode={this.state.currentLayoutMode}
|
||||||
currentItem={this.state.currentItem}
|
currentItem={this.state.currentItem}
|
||||||
onCodeChange={this.onCodeChange.bind(this)}
|
onCodeChange={this.onCodeChange.bind(this)}
|
||||||
|
onCodeSettingsChange={this.onCodeSettingsChange.bind(this)}
|
||||||
onCodeModeChange={this.onCodeModeChange.bind(this)}
|
onCodeModeChange={this.onCodeModeChange.bind(this)}
|
||||||
onRef={comp => (this.contentWrap = comp)}
|
onRef={comp => (this.contentWrap = comp)}
|
||||||
prefs={this.state.prefs}
|
prefs={this.state.prefs}
|
||||||
|
@@ -21,7 +21,7 @@ export function computeHtml(code, mode) {
|
|||||||
|
|
||||||
return d.promise;
|
return d.promise;
|
||||||
}
|
}
|
||||||
export function computeCss(code, mode) {
|
export function computeCss(code, mode, settings) {
|
||||||
var d = deferred();
|
var d = deferred();
|
||||||
// cleanupErrors('css');
|
// cleanupErrors('css');
|
||||||
|
|
||||||
@@ -77,19 +77,18 @@ export function computeCss(code, mode) {
|
|||||||
if (!window.atomizer) {
|
if (!window.atomizer) {
|
||||||
d.resolve('');
|
d.resolve('');
|
||||||
} else {
|
} else {
|
||||||
const html = scope.cm.html.getValue();
|
const html = code;
|
||||||
const foundClasses = atomizer.findClassNames(html);
|
const foundClasses = atomizer.findClassNames(html);
|
||||||
var finalConfig;
|
var finalConfig;
|
||||||
try {
|
try {
|
||||||
finalConfig = atomizer.getConfig(
|
finalConfig = atomizer.getConfig(
|
||||||
foundClasses,
|
foundClasses,
|
||||||
JSON.parse(scope.acssSettingsCm.getValue())
|
JSON.parse(settings.acssConfig)
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
finalConfig = atomizer.getConfig(foundClasses, {});
|
finalConfig = atomizer.getConfig(foundClasses, {});
|
||||||
}
|
}
|
||||||
const acss = atomizer.getCss(finalConfig);
|
const acss = atomizer.getCss(finalConfig);
|
||||||
scope.cm.css.setValue(acss);
|
|
||||||
d.resolve(acss);
|
d.resolve(acss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user