Web: Doceditor: added init for desktop editors, refactoring
This commit is contained in:
parent
0e76b57cee
commit
1c25b5a27c
@ -21,6 +21,8 @@ import { EditorWrapper } from "./StyledEditor";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import withDialogs from "./helpers/withDialogs";
|
||||
|
||||
import { canConvert, convertDocumentUrl } from "./helpers/utils";
|
||||
|
||||
const LoaderComponent = (
|
||||
<Loader
|
||||
type="rombs"
|
||||
@ -59,39 +61,6 @@ const onSDKError = (event) => {
|
||||
);
|
||||
};
|
||||
|
||||
const initDesktop = (cfg) => {
|
||||
const encryptionKeys = cfg?.editorConfig?.encryptionKeys;
|
||||
|
||||
regDesktop(
|
||||
user,
|
||||
!!encryptionKeys,
|
||||
encryptionKeys,
|
||||
(keys) => {
|
||||
setEncryptionKeys(keys);
|
||||
},
|
||||
true,
|
||||
(callback) => {
|
||||
getEncryptionAccess(fileId)
|
||||
.then((keys) => {
|
||||
var data = {
|
||||
keys,
|
||||
};
|
||||
|
||||
callback(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
window.toastr.error(
|
||||
typeof error === "string" ? error : error.message,
|
||||
null,
|
||||
0,
|
||||
true
|
||||
);
|
||||
});
|
||||
},
|
||||
t
|
||||
);
|
||||
};
|
||||
|
||||
const text = "text";
|
||||
const presentation = "presentation";
|
||||
let documentIsReady = false; // move to state?
|
||||
@ -124,6 +93,8 @@ function Editor({
|
||||
onSDKRequestSaveAs,
|
||||
isFileDialogVisible,
|
||||
isFolderDialogVisible,
|
||||
isDesktopEditor,
|
||||
initDesktop,
|
||||
}) {
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
const [documentTitle, setNewDocumentTitle] = useState("Loading...");
|
||||
@ -143,14 +114,51 @@ function Editor({
|
||||
if (config) {
|
||||
document.getElementById("scripDocServiceAddress").onload = onLoad();
|
||||
setDocumentTitle(config?.document?.title);
|
||||
}
|
||||
|
||||
if (isIOS && deviceType === "tablet") {
|
||||
const vh = window.innerHeight * 0.01;
|
||||
document.documentElement.style.setProperty("--vh", `${vh}px`);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (config) {
|
||||
console.log(isDesktopEditor, config);
|
||||
if (isDesktopEditor) {
|
||||
initDesktop(config, user, fileId, t);
|
||||
}
|
||||
}
|
||||
}, [isDesktopEditor]);
|
||||
|
||||
// useEffect(async () => {
|
||||
// try {
|
||||
// if (
|
||||
// url.indexOf("#message/") > -1 &&
|
||||
// fileInfo &&
|
||||
// fileInfo?.fileExst &&
|
||||
// canConvert(fileInfo.fileExst)
|
||||
// ) {
|
||||
// const result = await convertDocumentUrl();
|
||||
|
||||
// const splitUrl = url.split("#message/");
|
||||
|
||||
// if (result) {
|
||||
// const newUrl = `${result.webUrl}#message/${splitUrl[1]}`;
|
||||
|
||||
// history.pushState({}, null, newUrl);
|
||||
|
||||
// // fileInfo = result;
|
||||
// // url = newUrl;
|
||||
// // fileId = result.id;
|
||||
// // version = result.version;
|
||||
// }
|
||||
// }
|
||||
// } catch (err) {
|
||||
// console.error(err);
|
||||
// }
|
||||
// }, [url, fileInfo?.fileExst]);
|
||||
|
||||
const getDefaultFileName = (format) => {
|
||||
switch (format) {
|
||||
case "docx":
|
||||
|
@ -4,6 +4,7 @@ import { registerSW } from "@appserver/common/sw/helper";
|
||||
import App from "../App.js";
|
||||
import { useSSR } from "react-i18next";
|
||||
import useMfScripts from "../helpers/useMfScripts";
|
||||
import initDesktop from "../helpers/initDesktop";
|
||||
|
||||
const propsObj = window.__ASC_INITIAL_STATE__;
|
||||
const initialI18nStore = window.initialI18nStore;
|
||||
@ -17,6 +18,7 @@ const stateInit = document.getElementById("__ASC_INITIAL_STATE__");
|
||||
const i18nInit = document.getElementById("__ASC_I18N_INIT__");
|
||||
stateInit.parentNode.removeChild(stateInit);
|
||||
i18nInit.parentNode.removeChild(i18nInit);
|
||||
const isDesktopEditor = window["AscDesktopEditor"] !== undefined;
|
||||
|
||||
const AppWrapper = () => {
|
||||
const [isInitialized, isErrorLoading] = useMfScripts();
|
||||
@ -24,7 +26,13 @@ const AppWrapper = () => {
|
||||
|
||||
return (
|
||||
<Suspense fallback={<div />}>
|
||||
<App {...propsObj} mfReady={isInitialized} mfFailed={isErrorLoading} />
|
||||
<App
|
||||
{...propsObj}
|
||||
mfReady={isInitialized}
|
||||
mfFailed={isErrorLoading}
|
||||
isDesktopEditor={isDesktopEditor}
|
||||
initDesktop={initDesktop}
|
||||
/>
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
@ -8,7 +8,11 @@ import {
|
||||
getFileInfo,
|
||||
checkFillFormDraft,
|
||||
openEdit,
|
||||
convertFile,
|
||||
setEncryptionKeys,
|
||||
getEncryptionAccess,
|
||||
} from "@appserver/common/api/files";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
|
||||
export const canConvert = (extension, filesSettings) => {
|
||||
@ -17,13 +21,17 @@ export const canConvert = (extension, filesSettings) => {
|
||||
return result === -1 ? false : true;
|
||||
};
|
||||
|
||||
export const convertDocumentUrl = async () => {
|
||||
const convert = await convertFile(fileId, null, true);
|
||||
return convert && convert[0]?.result;
|
||||
};
|
||||
|
||||
export const initDocEditor = async (req) => {
|
||||
if (!req) return false;
|
||||
|
||||
const { headers, url, query } = req;
|
||||
const { version, desktop: isDesktop } = query;
|
||||
let error = null;
|
||||
|
||||
initSSR(headers);
|
||||
|
||||
try {
|
||||
@ -70,19 +78,6 @@ export const initDocEditor = async (req) => {
|
||||
getFileInfo(fileId),
|
||||
]);
|
||||
|
||||
if (successAuth) {
|
||||
try {
|
||||
// if (url.indexOf("#message/") > -1) {
|
||||
// if (canConvert(fileInfo.fileExst)) {
|
||||
// const url = await convertDocumentUrl();
|
||||
// history.pushState({}, null, url);
|
||||
// }
|
||||
// } TODO: move to hook?
|
||||
} catch (err) {
|
||||
error = { errorMessage: typeof err === "string" ? err : err.message };
|
||||
}
|
||||
}
|
||||
|
||||
let formUrl;
|
||||
|
||||
if (
|
||||
@ -102,12 +97,6 @@ export const initDocEditor = async (req) => {
|
||||
}
|
||||
}
|
||||
|
||||
const needInitDesktop = false;
|
||||
if (isDesktop) {
|
||||
// initDesktop(config); TODO: move to hook
|
||||
needInitDesktop = true;
|
||||
}
|
||||
|
||||
const isSharingAccess = fileInfo && fileInfo.canShare;
|
||||
|
||||
if (view) {
|
||||
@ -130,7 +119,6 @@ export const initDocEditor = async (req) => {
|
||||
url,
|
||||
doc,
|
||||
fileId,
|
||||
needInitDesktop,
|
||||
},
|
||||
};
|
||||
} catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user