diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/constants/index.js b/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/constants/index.js new file mode 100644 index 0000000000..b7cb6b1b4e --- /dev/null +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/constants/index.js @@ -0,0 +1,39 @@ +// (c) Copyright Ascensio System SIA 2009-2024 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +export const showPreviewThreshold = 720; + +export const scriptUrl = `${window.location.origin}/static/scripts/sdk/1.0.0/api.js`; + +export const dataDimensions = [ + { key: "percent", label: "%", default: true }, + { key: "pixel", label: "px" }, +]; + +export const defaultWidthDimension = dataDimensions[0]; +export const defaultHeightDimension = dataDimensions[0]; +export const defaultWidth = "100"; +export const defaultHeight = "100"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/presets/DocSpace.js b/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/presets/DocSpace.js index 672d0fa589..336ae50b0d 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/presets/DocSpace.js +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/JavascriptSDK/presets/DocSpace.js @@ -26,39 +26,32 @@ import { useState, useEffect } from "react"; import { withTranslation } from "react-i18next"; -import debounce from "lodash.debounce"; import { Box } from "@docspace/shared/components/box"; -import { TextInput } from "@docspace/shared/components/text-input"; -import { Textarea } from "@docspace/shared/components/textarea"; -import { Label } from "@docspace/shared/components/label"; -import { Text } from "@docspace/shared/components/text"; -import { ComboBox } from "@docspace/shared/components/combobox"; -import { TabsContainer } from "@docspace/shared/components/tabs-container"; -import { objectToGetParams, loadScript } from "@docspace/shared/utils/common"; import { inject, observer } from "mobx-react"; -import { isTablet, isMobile } from "@docspace/shared/utils/device"; +import { WidthSetter } from "../sub-components/WidthSetter"; +import { HeightSetter } from "../sub-components/HeightSetter"; +import { FrameIdSetter } from "../sub-components/FrameIdSetter"; +import { PresetWrapper } from "../sub-components/PresetWrapper"; +import { PreviewBlock } from "../sub-components/PreviewBlock"; -import GetCodeDialog from "../sub-components/GetCodeDialog"; -import CodeBlock from "../sub-components/CodeBlock"; -import { Button } from "@docspace/shared/components/button"; - -const showPreviewThreshold = 720; +import { loadFrame } from "../utils"; + +import { + scriptUrl, + dataDimensions, + defaultWidthDimension, + defaultHeightDimension, + defaultWidth, + defaultHeight, +} from "../constants"; import { - SDKContainer, Controls, - CategoryHeader, CategorySubHeader, - CategoryDescription, - ControlsGroup, Frame, Container, - RowContainer, - Preview, - GetCodeButtonWrapper, ControlsSection, - CodeWrapper, } from "./StyledPresets"; const DocSpace = (props) => { @@ -66,26 +59,10 @@ const DocSpace = (props) => { setDocumentTitle(t("JavascriptSdk")); - const scriptUrl = `${window.location.origin}/static/scripts/sdk/1.0.0/api.js`; - - const dataDimensions = [ - { key: "percent", label: "%", default: true }, - { key: "pixel", label: "px" }, - ]; - - const [widthDimension, setWidthDimension] = useState(dataDimensions[0]); - const [heightDimension, setHeightDimension] = useState(dataDimensions[0]); - const [width, setWidth] = useState("100"); - const [height, setHeight] = useState("100"); - const [isGetCodeDialogOpened, setIsGetCodeDialogOpened] = useState(false); - const [showPreview, setShowPreview] = useState( - window.innerWidth > showPreviewThreshold, - ); - const [config, setConfig] = useState({ mode: "manager", - width: `${width}${widthDimension.label}`, - height: `${height}${heightDimension.label}`, + width: `${defaultWidth}${defaultWidthDimension.label}`, + height: `${defaultHeight}${defaultHeightDimension.label}`, frameId: "ds-frame", showHeader: true, showTitle: true, @@ -104,33 +81,19 @@ const DocSpace = (props) => { }, }); - const params = objectToGetParams(config); - const frameId = config.frameId || "ds-frame"; const destroyFrame = () => { window.DocSpace?.SDK?.frames[frameId]?.destroyFrame(); }; - const loadFrame = debounce(() => { - const script = document.getElementById("integration"); - - if (script) { - script.remove(); - } - - const params = objectToGetParams(config); - - loadScript(`${scriptUrl}${params}`, "integration", () => - window.DocSpace.SDK.initFrame(config), - ); - }, 500); + const loadCurrentFrame = () => loadFrame(config, scriptUrl); useEffect(() => { - loadFrame(); + loadCurrentFrame(); return () => destroyFrame(); }); - + useEffect(() => { const scroll = document.getElementsByClassName("section-scroll")[0]; if (scroll) { @@ -138,208 +101,57 @@ const DocSpace = (props) => { } }, []); - const onChangeTab = () => { - loadFrame(); - }; - - const onChangeWidth = (e) => { - setConfig((config) => { - return { ...config, width: `${e.target.value}${widthDimension.label}` }; - }); - - setWidth(e.target.value); - }; - - const onChangeHeight = (e) => { - setConfig((config) => { - return { ...config, height: `${e.target.value}${heightDimension.label}` }; - }); - - setHeight(e.target.value); - }; - - const onChangeFrameId = (e) => { - setConfig((config) => { - return { ...config, frameId: e.target.value }; - }); - }; - - const onChangeWidthDimension = (item) => { - setConfig((config) => { - return { ...config, width: `${width}${item.label}` }; - }); - - setWidthDimension(item); - }; - - const onChangeHeightDimension = (item) => { - setConfig((config) => { - return { ...config, height: `${height}${item.label}` }; - }); - - setHeightDimension(item); - }; - - const openGetCodeModal = () => setIsGetCodeDialogOpened(true); - - const closeGetCodeModal = () => setIsGetCodeDialogOpened(false); - - const onResize = () => { - const isEnoughWidthForPreview = window.innerWidth > showPreviewThreshold; - if (isEnoughWidthForPreview !== showPreview) - setShowPreview(isEnoughWidthForPreview); - }; - - useEffect(() => { - window.addEventListener("resize", onResize); - return () => { - window.removeEventListener("resize", onResize); - }; - }, [showPreview]); - - const codeBlock = `
Fallback text
\n`; - const preview = ( ); - const code = ( - - - {`HTML ${t("CodeTitle")}`} - - - {t("HtmlCodeDescription")} - -