writed one myself before the official update, on the file composerState
Hope the proposal can be accepted.
load(componentClass, attrs) {
const body = { componentClass, attrs };
if (this.preventExit()) return;
// If we load a similar component into the composer, then Mithril will be
// able to diff the old/new contents and some DOM-related state from the
// old composer will remain. To prevent this from happening, we clear the
// component and force a redraw, so that the new component will be working
// on a blank slate.
if (this.isVisible()) {
this.clear();
m.redraw.sync();
}
this.body = body;
window.composerAutosave=()=>{
let username = app.session.user.data.attributes.username;
if(app.composer.data().relationships.discussion){
let discussionID = app.composer.data().relationships.discussion.data.id;
var storageName = username + 'replyTo' +discussionID
}else{
var storageName = 'newDiscussion'
}
if(app.composer.position!='hidden'){
console.log('autosave '+storageName)
window.localStorage.setItem(storageName ,app.composer.data().content)
setTimeout(()=>{
window.composerAutosave()
},500);
}
}
window.composerAutoLoad=()=>{
let username = app.session.user.data.attributes.username;
if(app.composer.data().relationships.discussion){
let discussionID = app.composer.data().relationships.discussion.data.id;
var storageName = username + 'replyTo' +discussionID
}else{
var storageName = 'newDiscussion'
}
//console.log('autoload '+storageName+' preload')
console.log(window.localStorage.getItem(storageName)?.length)
console.log( app.composer.data().content.length )
if(!app.composer.data().content.length && window.localStorage.getItem(storageName)?.length){
console.log('autoload '+storageName)
app.composer.editor.insertAtCursor(window.localStorage.getItem(storageName))}
}
setTimeout(()=>{
window.composerAutoLoad()
window.composerAutosave()
},500)
}