diff --git a/app/javascript/editor/editor.ts b/app/javascript/editor/editor.ts index 0990c59..a3919c8 100644 --- a/app/javascript/editor/editor.ts +++ b/app/javascript/editor/editor.ts @@ -1,4 +1,4 @@ -import { storeContent, restoreContent } from 'editor/storage' +import { storeContent, restoreContent, forgetContent } from 'editor/storage' import { isDirectChild, moveChildren, safeGetSelection, safeGetRangeAt, setAuxiliaryToolbar, parentBlockNames } from 'editor/utils' import { types, getValidChildren, getType } from 'editor/types' import { setupButtons as setupMarksButtons } from 'editor/types/marks' @@ -279,11 +279,24 @@ function setupEditor (editorEl: HTMLElement): void { } document.addEventListener("turbolinks:load", () => { + const flash = document.querySelector('.js-flash') + + if (flash) { + const keys = JSON.parse(flash.dataset.keys || '') + + switch (flash.dataset.target) { + case 'editor': + switch (flash.dataset.action) { + case 'forget-content': + keys.forEach(forgetContent) + } + } + } + for (const editorEl of document.querySelectorAll('.editor[data-editor]')) { try { setupEditor(editorEl) } catch (error) { - //alert(`No pude iniciar el editor: ${error}`) // TODO: mostrar error console.error('no se pudo iniciar el editor, error completo', error) }