1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Connected md editor settings to logic for functionality

This commit is contained in:
Dan Brown
2022-11-28 12:12:36 +00:00
parent 9fd5190c70
commit ec3713bc74
10 changed files with 99 additions and 28 deletions

View File

@ -0,0 +1,40 @@
import {kebabToCamel} from "../services/text";
export class Settings {
constructor(initialSettings) {
this.settingMap = {};
this.changeListeners = {};
this.merge(initialSettings);
}
set(key, value) {
key = this.normaliseKey(key);
this.settingMap[key] = value;
for (const listener of (this.changeListeners[key] || [])) {
listener(value);
}
}
get(key) {
return this.settingMap[this.normaliseKey(key)] || null;
}
merge(settings) {
for (const [key, value] of Object.entries(settings)) {
this.set(key, value);
}
}
onChange(key, callback) {
key = this.normaliseKey(key);
const listeners = this.changeListeners[this.normaliseKey(key)] || [];
listeners.push(callback);
this.changeListeners[this.normaliseKey(key)] = listeners;
}
normaliseKey(key) {
return kebabToCamel(key.replace('md-', ''));
}
}