mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-06-22 04:58:40 +00:00
Merge branch 'master' of https://github.com/naturalcrit/homebrewery into add-cm-features
This commit is contained in:
@@ -86,8 +86,8 @@ export function tokenizeCustomMarkdown(text) {
|
||||
if(/\~/.test(lineText)) {
|
||||
const strikethroughRegex = /~(?!\s)(.+?)(?<!\s)~/g;
|
||||
|
||||
let match = strikethroughRegex.exec(lineText);
|
||||
let type = customTags.strikethrough;
|
||||
const match = strikethroughRegex.exec(lineText);
|
||||
const type = customTags.strikethrough;
|
||||
|
||||
if(match) {
|
||||
tokens.push({
|
||||
|
||||
@@ -39,6 +39,16 @@ export async function formatCSS(view) {
|
||||
|
||||
return true;
|
||||
}
|
||||
const insertTab = (view)=>{
|
||||
const { from, to } = view.state.selection.main;
|
||||
|
||||
view.dispatch({
|
||||
changes : { from, to, insert: ' ' },
|
||||
selection : { anchor: from + 2 }
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const indentLess = (view)=>{
|
||||
const { from, to } = view.state.selection.main;
|
||||
@@ -55,20 +65,19 @@ const indentLess = (view)=>{
|
||||
};
|
||||
|
||||
const wrapSelection = (prefix, suffix)=>(view)=>{
|
||||
const { from, to } = view.state.selection.main;
|
||||
const selected = view.state.doc.sliceString(from, to);
|
||||
const changes = [];
|
||||
|
||||
let text, selection;
|
||||
for (const range of view.state.selection.ranges) {
|
||||
const { from, to } = range;
|
||||
const selected = view.state.doc.sliceString(from, to);
|
||||
|
||||
if(from === to) {
|
||||
text = prefix + suffix;
|
||||
selection = { anchor: from + prefix.length, head: from + prefix.length };
|
||||
} else if(selected.startsWith(prefix) && selected.endsWith(suffix)) {
|
||||
text = selected.slice(prefix.length, -suffix.length);
|
||||
selection = { anchor: from, head: from + text.length };
|
||||
} else {
|
||||
text = `${prefix}${selected}${suffix}`;
|
||||
selection = { anchor: from, head: from + text.length };
|
||||
let text;
|
||||
|
||||
if(from === to) { text = prefix + suffix; } else if(selected.startsWith(prefix) && selected.endsWith(suffix)) {
|
||||
text = selected.slice(prefix.length, -suffix.length);
|
||||
} else {text = `${prefix}${selected}${suffix}`;}
|
||||
|
||||
changes.push({ from, to, insert: text });
|
||||
}
|
||||
|
||||
view.dispatch({
|
||||
|
||||
@@ -30,18 +30,17 @@ import cm5Themes from 'codemirror-5-themes';
|
||||
const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
|
||||
|
||||
const themeNames = Object.entries(themes)
|
||||
.filter(([name, value]) =>
|
||||
Array.isArray(value) &&
|
||||
.filter(([name, value])=>Array.isArray(value) &&
|
||||
!name.endsWith('Init') &&
|
||||
!name.endsWith('Style')
|
||||
)
|
||||
.map(([name]) => name);
|
||||
.map(([name])=>name);
|
||||
|
||||
const EditorThemes = [
|
||||
'default',
|
||||
...themeNames
|
||||
.filter(name => name !== 'default')
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
'default',
|
||||
...themeNames
|
||||
.filter((name)=>name !== 'default')
|
||||
.sort((a, b)=>a.localeCompare(b))
|
||||
];
|
||||
|
||||
const execute = function(val, props){
|
||||
|
||||
+3
-3
@@ -101,7 +101,7 @@
|
||||
"@codemirror/language-data": "^6.5.2",
|
||||
"@codemirror/search": "^6.6.0",
|
||||
"@codemirror/state": "^6.6.0",
|
||||
"@codemirror/view": "^6.42.1",
|
||||
"@codemirror/view": "^6.43.0",
|
||||
"@dmsnell/diff-match-patch": "^1.1.0",
|
||||
"@googleapis/drive": "^20.1.0",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
@@ -146,7 +146,7 @@
|
||||
"react": "^19.2.6",
|
||||
"react-dom": "^19.2.6",
|
||||
"react-frame-component": "^5.3.2",
|
||||
"react-router": "^7.15.0",
|
||||
"react-router": "^7.15.1",
|
||||
"sanitize-filename": "1.6.4",
|
||||
"superagent": "^10.2.1"
|
||||
},
|
||||
@@ -163,7 +163,7 @@
|
||||
"jsdom": "^28.1.0",
|
||||
"jsdom-global": "^3.0.2",
|
||||
"postcss-less": "^6.0.0",
|
||||
"stylelint": "^17.11.0",
|
||||
"stylelint": "^17.11.1",
|
||||
"stylelint-config-recess-order": "^7.7.0",
|
||||
"stylelint-config-recommended": "^18.0.0",
|
||||
"supertest": "^7.1.4",
|
||||
|
||||
+19
-12
@@ -32,20 +32,20 @@ const isStaticTheme = (renderer, themeName)=>{
|
||||
// };
|
||||
|
||||
|
||||
const migrateSystemsToTags = (brew) => {
|
||||
if (!('systems' in brew)) return brew;
|
||||
const migrateSystemsToTags = (brew)=>{
|
||||
if(!('systems' in brew)) return brew;
|
||||
|
||||
if (!Array.isArray(brew.systems) || brew.systems.length === 0) {
|
||||
if(!Array.isArray(brew.systems) || brew.systems.length === 0) {
|
||||
brew.systems = undefined;
|
||||
return brew;
|
||||
}
|
||||
const systemMap = {
|
||||
'5e': 'system:D&D 5e',
|
||||
'4e': 'system:D&D 4e',
|
||||
'3.5e': 'system:D&D 3.5e',
|
||||
'Pathfinder': 'system:Pathfinder 2e'
|
||||
'5e' : 'system:D&D 5e',
|
||||
'4e' : 'system:D&D 4e',
|
||||
'3.5e' : 'system:D&D 3.5e',
|
||||
'Pathfinder' : 'system:Pathfinder 2e'
|
||||
};
|
||||
const systemTags = brew.systems.map(s => systemMap[s]);
|
||||
const systemTags = brew.systems.map((s)=>systemMap[s]);
|
||||
brew.tags = _.uniq([...(brew.tags || []), ...systemTags]);
|
||||
|
||||
brew.systems = undefined;
|
||||
@@ -188,7 +188,7 @@ const api = {
|
||||
stub.renderer = stub.renderer || undefined; // Clear empty strings
|
||||
stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields
|
||||
|
||||
|
||||
|
||||
|
||||
const fixedStub = migrateSystemsToTags(stub);
|
||||
req.brew = fixedStub;
|
||||
@@ -397,17 +397,24 @@ const api = {
|
||||
return res.status(409).send(JSON.stringify({ message: `The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.` }));
|
||||
}
|
||||
|
||||
let result = [];
|
||||
try {
|
||||
const patches = parsePatch(brewFromClient.patches);
|
||||
// Patch to a throwaway variable while parallelizing - we're more concerned with error/no error.
|
||||
const patchedResult = decodeURI(applyPatches(patches, encodeURI(brewFromServer.text))[0]);
|
||||
if(patchedResult != brewFromClient.text)
|
||||
result = applyPatches(patches, encodeURI(brewFromServer.text));
|
||||
const failedPatches = patches.map((patch, index)=>{if(!result[1][index]){ return patch; }});
|
||||
if(failedPatches > 0){
|
||||
throw (`Patch failure: ${failedPatches}/${result[1].length} did not apply`);
|
||||
}
|
||||
if(decodeURI(result[0]) != brewFromClient.text){
|
||||
throw ('Patches did not apply cleanly, text mismatch detected');
|
||||
}
|
||||
// brew.text = applyPatches(patches, brewFromServer.text)[0];
|
||||
} catch (err) {
|
||||
debugTextMismatch(brewFromClient.text, brewFromServer.text, `edit/${brewFromClient.editId}`);
|
||||
console.error('Failed to apply patches:', {
|
||||
//patches : brewFromClient.patches,
|
||||
// patches : brewFromClient.patches,
|
||||
// result : result,
|
||||
brewId : brewFromClient.editId || 'unknown',
|
||||
error : err
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ const HomebrewSchema = mongoose.Schema({
|
||||
|
||||
description : { type: String, default: '' },
|
||||
tags : { type: [String], index: true },
|
||||
systems : { type: [String], default: undefined },
|
||||
systems : { type: [String], default: undefined },
|
||||
lang : { type: String, default: 'en', index: true },
|
||||
renderer : { type: String, default: '', index: true },
|
||||
authors : { type: [String], index: true },
|
||||
|
||||
@@ -16,17 +16,17 @@ export default {
|
||||
edge : (side = 'bottom')=>{
|
||||
const styles = ()=>{
|
||||
switch (side) {
|
||||
case 'bottom':
|
||||
return `{width:100%,bottom:0%}`
|
||||
break;
|
||||
case 'top':
|
||||
return `{width:100%,top:0%}`
|
||||
break;
|
||||
default:
|
||||
return `{height:100%}`
|
||||
break;
|
||||
case 'bottom':
|
||||
return `{width:100%,bottom:0%}`;
|
||||
break;
|
||||
case 'top':
|
||||
return `{width:100%,top:0%}`;
|
||||
break;
|
||||
default:
|
||||
return `{height:100%}`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rotation = {
|
||||
'bottom' : 0,
|
||||
|
||||
@@ -93,7 +93,7 @@ export default EditorView.theme({
|
||||
'.cm-strong' : { color: '#309dd2', fontWeight: 'bold' },
|
||||
'.cm-em' : { fontStyle: 'italic' },
|
||||
'.cm-keyword' : { color: '#fff' },
|
||||
'.cm-atom, .cm-value, .cm-color' : { color: '#c1939a' },
|
||||
'.cm-atom, .cm-value, .cm-color' : { color: '#c1939a' },
|
||||
'.cm-number' : { color: '#2986cc' },
|
||||
'.cm-def' : { color: '#2986cc' },
|
||||
'.cm-list' : { color: '#3cbf30' },
|
||||
|
||||
Reference in New Issue
Block a user