mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 14:09:34 +01:00
feat: add migration for table & checklists
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { parseHTML } from "./utils/html-parser";
|
||||
|
||||
export const migrations = {
|
||||
5.0: {},
|
||||
5.1: {},
|
||||
@@ -7,7 +9,14 @@ export const migrations = {
|
||||
tag: replaceDateEditedWithDateModified(true),
|
||||
attachment: replaceDateEditedWithDateModified(true),
|
||||
trash: replaceDateEditedWithDateModified(),
|
||||
tiny: replaceDateEditedWithDateModified(),
|
||||
tiny: (item) => {
|
||||
item = replaceDateEditedWithDateModified()(item);
|
||||
|
||||
if (!item.data || item.data.iv) return item;
|
||||
|
||||
item.data = removeToxClassFromChecklist(wrapTablesWithDiv(item.data));
|
||||
return item;
|
||||
},
|
||||
settings: replaceDateEditedWithDateModified(true),
|
||||
},
|
||||
5.3: {
|
||||
@@ -29,3 +38,30 @@ function replaceDateEditedWithDateModified(removeDateEditedProperty = false) {
|
||||
return item;
|
||||
};
|
||||
}
|
||||
|
||||
function wrapTablesWithDiv(html) {
|
||||
const document = parseHTML(html);
|
||||
const tables = document.getElementsByTagName("table");
|
||||
for (let table of tables) {
|
||||
table.setAttribute("contenteditable", "true");
|
||||
table.replaceWith(
|
||||
`<div class="table-container" contenteditable="false">${table.outerHTML}</div>`
|
||||
);
|
||||
}
|
||||
return document.outerHTML || document.body.innerHTML;
|
||||
}
|
||||
|
||||
function removeToxClassFromChecklist(html) {
|
||||
const document = parseHTML(html);
|
||||
const checklists = document.querySelectorAll(
|
||||
".tox-checklist,.tox-checklist--checked"
|
||||
);
|
||||
|
||||
for (let item of checklists) {
|
||||
if (item.classList.contains("tox-checklist--checked"))
|
||||
item.classList.replace("tox-checklist--checked", "checked");
|
||||
else if (item.classList.contains("tox-checklist"))
|
||||
item.classList.replace("tox-checklist", "checklist");
|
||||
}
|
||||
return document.outerHTML || document.body.innerHTML;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user