mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-26 22:43:07 +00:00
tweak cClass logic
This commit is contained in:
committed by
Charlie Humphreys
parent
ebbf0ca88b
commit
8e40cec051
@@ -456,7 +456,7 @@ const CodeEditor = createClass({
|
|||||||
// Close open widgets if click outside of a widget
|
// Close open widgets if click outside of a widget
|
||||||
if(!e.target.matches('.CodeMirror-linewidget *')) {
|
if(!e.target.matches('.CodeMirror-linewidget *')) {
|
||||||
for (const widget of this.state.widgets) {
|
for (const widget of this.state.widgets) {
|
||||||
this.state.widgetUtils.removeLineWidgets(widget);
|
widget.clear();
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
widgets : []
|
widgets : []
|
||||||
|
|||||||
@@ -73,11 +73,13 @@ module.exports = function(CodeMirror, setHints) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// checkbox widget
|
||||||
cClass : function(cm, n, prefix, cClass) {
|
cClass : function(cm, n, prefix, cClass) {
|
||||||
const { text } = cm.lineInfo(n);
|
const { text } = cm.lineInfo(n);
|
||||||
const id = `${_.kebabCase(prefix.replace('{{', ''))}-${_.kebabCase(cClass)}-${n}`;
|
const id = _.kebabCase(prefix + '-' + cClass + '-' + n);
|
||||||
const frameChange = (e)=>{
|
prefix = `{{${prefix}`;
|
||||||
if(!!e.target && e.target.checked)
|
const handleChange = (e)=>{
|
||||||
|
if(e.target?.checked)
|
||||||
cm.replaceRange(`,${cClass}`, CodeMirror.Pos(n, prefix.length), CodeMirror.Pos(n, prefix.length), '+insert');
|
cm.replaceRange(`,${cClass}`, CodeMirror.Pos(n, prefix.length), CodeMirror.Pos(n, prefix.length), '+insert');
|
||||||
else {
|
else {
|
||||||
const start = text.indexOf(`,${cClass}`);
|
const start = text.indexOf(`,${cClass}`);
|
||||||
@@ -87,8 +89,8 @@ module.exports = function(CodeMirror, setHints) {
|
|||||||
e.target.checked = true;
|
e.target.checked = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return <React.Fragment key={`${_.kebabCase(prefix)}-${cClass}-${n}`}>
|
return <React.Fragment key={id}>
|
||||||
<input type='checkbox' id={id} onChange={frameChange} checked={_.includes(text, `,${cClass}`)}/>
|
<input type='checkbox' id={id} onChange={handleChange} checked={_.includes(text, `,${cClass}`)}/>
|
||||||
<label htmlFor={id}>{_.startCase(cClass)}</label>
|
<label htmlFor={id}>{_.startCase(cClass)}</label>
|
||||||
</React.Fragment>;
|
</React.Fragment>;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module.exports = function(CodeMirror, widgets, cm, setHints) {
|
|||||||
pattern : PATTERNS.widget[widget.type](widget.name),
|
pattern : PATTERNS.widget[widget.type](widget.name),
|
||||||
createWidget : (n, node)=>{
|
createWidget : (n, node)=>{
|
||||||
const parent = document.createElement('div');
|
const parent = document.createElement('div');
|
||||||
const classes = (widget.classes || []).map((c, i)=>cClass(cm, n, `{{${widget.name}`, c));
|
const classes = (widget.classes || []).map((c, i)=>cClass(cm, n, `${widget.name}`, c));
|
||||||
const fieldNames = (widget.fields || []).map((f)=>f.name);
|
const fieldNames = (widget.fields || []).map((f)=>f.name);
|
||||||
const fields = (widget.fields || []).map((f, i)=>field(cm, n, f)).filter((f)=>!!f);
|
const fields = (widget.fields || []).map((f, i)=>field(cm, n, f)).filter((f)=>!!f);
|
||||||
const { text } = cm.lineInfo(n);
|
const { text } = cm.lineInfo(n);
|
||||||
|
|||||||
Reference in New Issue
Block a user