2022-11-29 14:19:39 +00:00
|
|
|
export const positionEditorElement = (editor: any, rect: any) => {
|
|
|
|
if (window) {
|
|
|
|
if (rect === null) {
|
|
|
|
editor.style.opacity = "0";
|
|
|
|
editor.style.top = "-1000px";
|
|
|
|
editor.style.left = "-1000px";
|
|
|
|
} else {
|
|
|
|
editor.style.opacity = "1";
|
2022-12-05 05:42:21 +00:00
|
|
|
editor.style.top = `${rect.top + rect.height + window.pageYOffset + 10}px`;
|
2022-11-29 14:19:39 +00:00
|
|
|
editor.style.left = `${
|
|
|
|
rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2
|
|
|
|
}px`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getValidatedValue = (value: string) => {
|
|
|
|
const defaultValue =
|
|
|
|
'{"root":{"children":[{"children":[],"direction":null,"format":"","indent":0,"type":"paragraph","version":1}],"direction":null,"format":"","indent":0,"type":"root","version":1}}';
|
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
console.log("Value: ", value);
|
|
|
|
|
2022-11-29 14:19:39 +00:00
|
|
|
if (value) {
|
|
|
|
try {
|
2022-12-13 15:52:44 +00:00
|
|
|
const data = JSON.parse(value);
|
|
|
|
return JSON.stringify(data);
|
2022-12-05 05:42:21 +00:00
|
|
|
} catch (e) {
|
2022-11-29 14:19:39 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
};
|