// OLTA.JS
/**
* initializes and sets up communication with olta dashboard
* @example
* // add Olta globally
*
*
* @example
* // initialize
* const olta = Olta()
*/
function Olta() {
// Retrieving html-to-image script dynamically
const script = document.createElement("script");
script.src =
"https://cdnjs.cloudflare.com/ajax/libs/html-to-image/1.11.11/html-to-image.min.js";
script.integrity =
"sha512-7tWCgq9tTYS/QkGVyKrtLpqAoMV9XIUxoou+sPUypsaZx56cYR/qio84fPK9EvJJtKvJEwt7vkn6je5UVzGevw==";
script.crossOrigin = "anonymous";
script.referrerPolicy = "no-referrer";
document.body.appendChild(script);
// overridable handlers
let onUpdateHandler = (update) => {
console.log("olta: UPDATE", update);
};
let onErrorHandler = (error) => {
console.error("olta: ERROR", error);
};
const state = { projectState: {} };
window.addEventListener("message", (e) => {
const { state: newState, type } = e.data ?? {};
if (type !== "state") {
return;
}
state.projectState = newState?.projectState ?? {};
// initiate update handler/ callback
onUpdateHandler(state);
});
/**
* Get all documents from a given collection
* @param {string} collectionId
* @returns {Array