(function () { const defaultConfig = { src: new URL(document.currentScript.src).origin, rootPath: "/rooms/shared/", requestToken: null, width: "100%", height: "100%", name: "frameDocSpace", type: "desktop", // TODO: ["desktop", "mobile"] frameId: "ds-frame", mode: "manager", //TODO: ["manager", "editor", "viewer","room-selector", "file-selector", "system"] id: null, locale: null, theme: "Base", editorType: "embedded", //TODO: ["desktop", "embedded"] editorGoBack: true, selectorType: "exceptPrivacyTrashArchiveFolders", //TODO: ["roomsOnly", "userFolderOnly", "exceptPrivacyTrashArchiveFolders", "exceptSortedByTagsFolders"] showSelectorCancel: false, showSelectorHeader: false, showHeader: false, showTitle: true, showMenu: false, showFilter: false, destroyText: "", viewAs: "row", //TODO: ["row", "table", "tile"] viewTableColumns: "Name,Size,Type", checkCSP: true, filter: { count: 100, page: 1, sortorder: "descending", //TODO: ["descending", "ascending"] sortby: "DateAndTime", //TODO: ["DateAndTime", "AZ", "Type", "Size", "DateAndTimeCreation", "Author"] search: "", withSubfolders: false, }, keysForReload: [ "src", "rootPath", "width", "height", "name", "frameId", "id", "type", "editorType", "mode", ], events: { onSelectCallback: null, onCloseCallback: null, onAppReady: null, onAppError: (e) => console.log("onAppError", e), onEditorCloseCallback: null, onAuthSuccess: null, onSignOut: null, }, }; const cspErrorText = "The current domain is not set in the Content Security Policy (CSP) settings."; const validateCSP = async (targetSrc) => { const currentSrc = window.location.origin; if (currentSrc.indexOf(targetSrc) !== -1) return; //TODO: try work with localhost const response = await fetch(`${targetSrc}/api/2.0/security/csp`); const res = await response.json(); const passed = res.response.header && res.response.header.includes(currentSrc); if (!passed) throw new Error(cspErrorText); return; }; const getConfigFromParams = () => { const src = decodeURIComponent(document.currentScript.src); if (!src || !src.length) return null; const searchUrl = src.split("?")[1]; let object = {}; if (searchUrl && searchUrl.length) { object = JSON.parse( `{"${searchUrl.replace(/&/g, '","').replace(/=/g, '":"')}"}`, (k, v) => (v === "true" ? true : v === "false" ? false : v) ); object.filter = defaultConfig.filter; for (prop in object) { if (prop in defaultConfig.filter) { object.filter[prop] = object[prop]; delete object[prop]; } } } return { ...defaultConfig, ...object }; }; class DocSpace { #iframe; #isConnected = false; #frameOpacity = 0; #callbacks = []; #tasks = []; #classNames = ""; constructor(config) { this.config = config; } #oneOfExistInObject = (array, object) => { return Object.keys(object).some((k) => array.includes(k)); }; #createIframe = (config) => { const iframe = document.createElement("iframe"); const container = document.createElement("div"); container.style.width = config.width; container.style.height = config.height; container.style.display = "flex"; container.style.justifyContent = "center"; container.style.alignItems = "center"; const loader = document.createElement("img"); loader.setAttribute("src", `${config.src}/static/images/loader.svg`); loader.setAttribute("width", `64px`); loader.setAttribute("height", `64px`); container.appendChild(loader); const targetNode = document.getElementById(config.frameId); const isExistLoader = document.getElementById(config.frameId + "-loader"); if (!isExistLoader) targetNode.insertAdjacentElement("afterend", container); container.setAttribute("id", config.frameId + "-loader"); iframe.style.opacity = this.#frameOpacity; let path = ""; switch (config.mode) { case "manager": { if (config.filter) { if (config.id) config.filter.folder = config.id; const params = config.requestToken ? { key: config.requestToken, ...config.filter } : config.filter; if (!params.withSubfolders) { delete params.withSubfolders; } const urlParams = new URLSearchParams(params).toString(); path = `${config.rootPath}${ config.requestToken ? `?${urlParams}` : `${config.id ? config.id + "/" : ""}filter?${urlParams}` }`; } break; } case "room-selector": { path = `/sdk/room-selector`; break; } case "file-selector": { path = `/sdk/file-selector?selectorType=${config.selectorType}`; break; } case "system": { path = `/sdk/system`; break; } case "editor": { let goBack = config.editorGoBack; if ( config.events.onEditorCloseCallback && typeof config.events.onEditorCloseCallback === "function" ) { goBack = "event"; } path = `/doceditor/?fileId=${config.id}&type=${config.editorType}&editorGoBack=${goBack}`; if (config.requestToken) { path = `${path}&share=${config.requestToken}`; } break; } case "viewer": { let goBack = config.editorGoBack; if ( config.events.onEditorCloseCallback && typeof config.events.onEditorCloseCallback === "function" ) { goBack = "event"; } path = `/doceditor/?fileId=${config.id}&type=${config.editorType}&action=view&editorGoBack=${goBack}`; if (config.requestToken) { path = `${path}&share=${config.requestToken}`; } break; } default: path = config.rootPath; } iframe.src = config.src + path; iframe.width = config.width; iframe.height = config.height; iframe.name = config.name; iframe.id = config.frameId; iframe.frameBorder = 0; iframe.allowFullscreen = true; iframe.setAttribute("allow", "storage-access"); iframe.style.zIndex = 2; if (config.type == "mobile") { iframe.style.position = "fixed"; iframe.style.overflow = "hidden"; document.body.style.overscrollBehaviorY = "contain"; } if (this.config.checkCSP) { validateCSP(this.config.src).catch((e) => { const html = `