0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-23 16:33:05 +00:00

tweak cClass logic

This commit is contained in:
Trevor Buckner
2023-07-04 03:31:21 -04:00
committed by Charlie Humphreys
parent ebbf0ca88b
commit 8e40cec051
3 changed files with 9 additions and 7 deletions

View File

@@ -456,7 +456,7 @@ const CodeEditor = createClass({
// Close open widgets if click outside of a widget
if(!e.target.matches('.CodeMirror-linewidget *')) {
for (const widget of this.state.widgets) {
this.state.widgetUtils.removeLineWidgets(widget);
widget.clear();
}
this.setState({
widgets : []

View File

@@ -73,11 +73,13 @@ module.exports = function(CodeMirror, setHints) {
};
return {
// checkbox widget
cClass : function(cm, n, prefix, cClass) {
const { text } = cm.lineInfo(n);
const id = `${_.kebabCase(prefix.replace('{{', ''))}-${_.kebabCase(cClass)}-${n}`;
const frameChange = (e)=>{
if(!!e.target && e.target.checked)
const id = _.kebabCase(prefix + '-' + cClass + '-' + n);
prefix = `{{${prefix}`;
const handleChange = (e)=>{
if(e.target?.checked)
cm.replaceRange(`,${cClass}`, CodeMirror.Pos(n, prefix.length), CodeMirror.Pos(n, prefix.length), '+insert');
else {
const start = text.indexOf(`,${cClass}`);
@@ -87,8 +89,8 @@ module.exports = function(CodeMirror, setHints) {
e.target.checked = true;
}
};
return <React.Fragment key={`${_.kebabCase(prefix)}-${cClass}-${n}`}>
<input type='checkbox' id={id} onChange={frameChange} checked={_.includes(text, `,${cClass}`)}/>
return <React.Fragment key={id}>
<input type='checkbox' id={id} onChange={handleChange} checked={_.includes(text, `,${cClass}`)}/>
<label htmlFor={id}>{_.startCase(cClass)}</label>
</React.Fragment>;
},

View File

@@ -18,7 +18,7 @@ module.exports = function(CodeMirror, widgets, cm, setHints) {
pattern : PATTERNS.widget[widget.type](widget.name),
createWidget : (n, node)=>{
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 fields = (widget.fields || []).map((f, i)=>field(cm, n, f)).filter((f)=>!!f);
const { text } = cm.lineInfo(n);