@oneblink/apps-react 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OneBlinkFormBase.d.ts +2 -1
- package/dist/OneBlinkFormBase.js +34 -11
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/form-elements/FormElementFiles/FormElementFile.js +1 -1
- package/dist/form-elements/FormElementFiles/FormElementFile.js.map +1 -1
- package/dist/hooks/attachments/useAttachment.js +69 -16
- package/dist/hooks/attachments/useAttachment.js.map +1 -1
- package/dist/hooks/attachments/useAttachmentBlobs.d.ts +19 -0
- package/dist/hooks/attachments/useAttachmentBlobs.js +24 -0
- package/dist/hooks/attachments/useAttachmentBlobs.js.map +1 -0
- package/dist/hooks/usePages.js +16 -5
- package/dist/hooks/usePages.js.map +1 -1
- package/dist/services/checkIfAttachmentsExist.d.ts +5 -0
- package/dist/services/checkIfAttachmentsExist.js +149 -0
- package/dist/services/checkIfAttachmentsExist.js.map +1 -0
- package/dist/services/download-file.js +4 -1
- package/dist/services/download-file.js.map +1 -1
- package/dist/styles/renderer.scss +0 -167
- package/dist/styles/steps.scss +181 -0
- package/dist/styles.css +150 -140
- package/dist/styles.css.map +1 -1
- package/dist/types/attachments.d.ts +1 -1
- package/dist/types/attachments.js.map +1 -1
- package/package.json +3 -3
@@ -0,0 +1,24 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
const AttachmentBlobsContext = React.createContext({
|
3
|
+
storeAttachmentBlobLocally: () => { },
|
4
|
+
getAttachmentBlobLocally: () => undefined,
|
5
|
+
});
|
6
|
+
export const AttachmentBlobsProvider = ({ children }) => {
|
7
|
+
const [attachmentBlobs, setAttachmentBlobs] = React.useState([]);
|
8
|
+
const storeAttachmentBlobLocally = React.useCallback((newAttachment) => {
|
9
|
+
setAttachmentBlobs((c) => [...c, newAttachment]);
|
10
|
+
}, []);
|
11
|
+
const getAttachmentBlobLocally = React.useCallback((attachmentId) => {
|
12
|
+
return attachmentBlobs.find((b) => b.attachmentId === attachmentId);
|
13
|
+
}, [attachmentBlobs]);
|
14
|
+
const value = React.useMemo(() => ({
|
15
|
+
storeAttachmentBlobLocally,
|
16
|
+
getAttachmentBlobLocally,
|
17
|
+
}), [storeAttachmentBlobLocally, getAttachmentBlobLocally]);
|
18
|
+
return (React.createElement(AttachmentBlobsContext.Provider, { value: value }, children));
|
19
|
+
};
|
20
|
+
const useAttachmentBlobs = () => {
|
21
|
+
return React.useContext(AttachmentBlobsContext);
|
22
|
+
};
|
23
|
+
export default useAttachmentBlobs;
|
24
|
+
//# sourceMappingURL=useAttachmentBlobs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useAttachmentBlobs.js","sourceRoot":"","sources":["../../../src/hooks/attachments/useAttachmentBlobs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAqB9B,MAAM,sBAAsB,GAAG,KAAK,CAAC,aAAa,CAChD;IACE,0BAA0B,EAAE,GAAG,EAAE,GAAE,CAAC;IACpC,wBAAwB,EAAE,GAAG,EAAE,CAAC,SAAS;CAC1C,CACF,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EAAE,QAAQ,EAAS,EAAE,EAAE;IAC7D,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAE1D,EAAE,CAAC,CAAA;IACL,MAAM,0BAA0B,GAAG,KAAK,CAAC,WAAW,CAClD,CAAC,aAAsC,EAAE,EAAE;QACzC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC,CAAA;IAClD,CAAC,EACD,EAAE,CACH,CAAA;IAED,MAAM,wBAAwB,GAAG,KAAK,CAAC,WAAW,CAChD,CAAC,YAAoB,EAAE,EAAE;QACvB,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;IACrE,CAAC,EACD,CAAC,eAAe,CAAC,CAClB,CAAA;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,CAAC;QACL,0BAA0B;QAC1B,wBAAwB;KACzB,CAAC,EACF,CAAC,0BAA0B,EAAE,wBAAwB,CAAC,CACvD,CAAA;IAED,OAAO,CACL,oBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC1C,QAAQ,CACuB,CACnC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,GAAG,EAAE;IAC9B,OAAO,KAAK,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAA;AACjD,CAAC,CAAA;AACD,eAAe,kBAAkB,CAAA","sourcesContent":["import * as React from 'react'\n\ntype AttachmentObjectBlob = {\n attachmentId: string\n blob: Blob\n}\ntype RegisterAttachmentParam = {\n blob: Blob\n attachmentId: string\n}\ntype AttachmentBlobsContextValue = {\n storeAttachmentBlobLocally: (options: RegisterAttachmentParam) => void\n getAttachmentBlobLocally: (\n attachmentId: string,\n ) => AttachmentObjectBlob | undefined\n}\n\ntype Props = {\n children: React.ReactNode\n}\n\nconst AttachmentBlobsContext = React.createContext<AttachmentBlobsContextValue>(\n {\n storeAttachmentBlobLocally: () => {},\n getAttachmentBlobLocally: () => undefined,\n },\n)\n\nexport const AttachmentBlobsProvider = ({ children }: Props) => {\n const [attachmentBlobs, setAttachmentBlobs] = React.useState<\n AttachmentObjectBlob[]\n >([])\n const storeAttachmentBlobLocally = React.useCallback(\n (newAttachment: RegisterAttachmentParam) => {\n setAttachmentBlobs((c) => [...c, newAttachment])\n },\n [],\n )\n\n const getAttachmentBlobLocally = React.useCallback(\n (attachmentId: string) => {\n return attachmentBlobs.find((b) => b.attachmentId === attachmentId)\n },\n [attachmentBlobs],\n )\n\n const value = React.useMemo(\n () => ({\n storeAttachmentBlobLocally,\n getAttachmentBlobLocally,\n }),\n [storeAttachmentBlobLocally, getAttachmentBlobLocally],\n )\n\n return (\n <AttachmentBlobsContext.Provider value={value}>\n {children}\n </AttachmentBlobsContext.Provider>\n )\n}\n\nconst useAttachmentBlobs = () => {\n return React.useContext(AttachmentBlobsContext)\n}\nexport default useAttachmentBlobs\n"]}
|
package/dist/hooks/usePages.js
CHANGED
@@ -44,12 +44,23 @@ export default function usePages({ pages, formElementsValidation, formElementsCo
|
|
44
44
|
closeStepsNavigation();
|
45
45
|
const scrollToTopOfPageHTMLElement = scrollToTopOfPageHTMLElementRef.current;
|
46
46
|
if (isShowingMultiplePages && scrollToTopOfPageHTMLElement) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
if (scrollToTopOfPageHTMLElement) {
|
48
|
+
window.requestAnimationFrame(() => {
|
49
|
+
scrollToTopOfPageHTMLElement.scrollIntoView({
|
50
|
+
block: 'start',
|
51
|
+
behavior: 'smooth',
|
52
|
+
});
|
53
|
+
});
|
54
|
+
}
|
55
|
+
const stepItemHTMLElement = document.getElementById(`steps-navigation-step-${pageId}`);
|
56
|
+
if (stepItemHTMLElement) {
|
57
|
+
window.requestAnimationFrame(() => {
|
58
|
+
stepItemHTMLElement.scrollIntoView({
|
59
|
+
block: 'start',
|
60
|
+
behavior: 'smooth',
|
61
|
+
});
|
51
62
|
});
|
52
|
-
}
|
63
|
+
}
|
53
64
|
}
|
54
65
|
}, [closeStepsNavigation, currentPageId, isShowingMultiplePages]);
|
55
66
|
const goToNextPage = React.useCallback(() => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usePages.js","sourceRoot":"","sources":["../../src/hooks/usePages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,gBAAgB,MAAM,+B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Z,+BAA+B;KAChC,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport useBooleanState from '../hooks/useBooleanState'\nimport { checkSectionValidity } from '../services/form-validation'\nimport scrollingService from '../services/scrolling-service'\nimport {\n FormElementsConditionallyShown,\n FormElementsValidation,\n} from '../types/form'\n\nexport default function usePages({\n pages,\n formElementsValidation,\n formElementsConditionallyShown,\n}: {\n pages: FormTypes.PageElement[]\n formElementsValidation: FormElementsValidation | undefined\n formElementsConditionallyShown: FormElementsConditionallyShown\n}) {\n const scrollToTopOfPageHTMLElementRef = React.useRef<HTMLDivElement>(null)\n const [visitedPageIds, setVisitedPageIds] = React.useState<string[]>([])\n\n const [isStepsHeaderActive, , closeStepsNavigation, toggleStepsNavigation] =\n useBooleanState(false)\n\n const visiblePages = React.useMemo<FormTypes.PageElement[]>(() => {\n return pages.filter((pageElement) => {\n return !formElementsConditionallyShown?.[pageElement.id]?.isHidden\n })\n }, [formElementsConditionallyShown, pages])\n\n const [currentPageId, setCurrentPageId] = React.useState(visiblePages[0].id)\n\n const currentPage = React.useMemo(() => {\n const currentPageById = visiblePages.find((pageElement) => {\n return pageElement.id === currentPageId\n })\n if (currentPageById) {\n return currentPageById\n } else {\n return visiblePages[0]\n }\n }, [currentPageId, visiblePages])\n\n const currentPageIndex = React.useMemo(\n () => visiblePages.indexOf(currentPage),\n [currentPage, visiblePages],\n )\n\n const currentPageNumber = React.useMemo(() => {\n if (currentPage) {\n return visiblePages.indexOf(currentPage) + 1\n }\n }, [currentPage, visiblePages])\n\n const isShowingMultiplePages = visiblePages.length > 1\n\n const setPageId = React.useCallback(\n (pageId: string) => {\n setVisitedPageIds((currentVisitedPageIds) => {\n if (currentVisitedPageIds.includes(currentPageId)) {\n return currentVisitedPageIds\n } else {\n return [...currentVisitedPageIds, currentPageId]\n }\n })\n setCurrentPageId(pageId)\n closeStepsNavigation()\n\n const scrollToTopOfPageHTMLElement =\n scrollToTopOfPageHTMLElementRef.current\n if (isShowingMultiplePages && scrollToTopOfPageHTMLElement) {\n window.requestAnimationFrame(() => {\n scrollToTopOfPageHTMLElement.scrollIntoView({\n block: 'start',\n behavior: 'smooth',\n })\n })\n }\n },\n [closeStepsNavigation, currentPageId, isShowingMultiplePages],\n )\n\n const goToNextPage = React.useCallback(() => {\n for (let i = 0; i < visiblePages.length; i++) {\n const page = visiblePages[i]\n if (page.id === currentPageId) {\n const nextVisiblePage = visiblePages[i + 1]\n if (nextVisiblePage) {\n setPageId(nextVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const goToPreviousPage = React.useCallback(() => {\n for (let i = visiblePages.length - 1; i > -1; i--) {\n const page = visiblePages[i]\n if (page && page.id === currentPageId) {\n const previousVisiblePage = visiblePages[i - 1]\n if (previousVisiblePage) {\n setPageId(previousVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const checkDisplayPageError = React.useCallback(\n (page: FormTypes.PageElement) => {\n // If we have not visited the page yet, we will not display errors\n if (!visitedPageIds.includes(page.id)) {\n return false\n }\n\n return checkSectionValidity(page, formElementsValidation)\n },\n [formElementsValidation, visitedPageIds],\n )\n\n React.useEffect(() => {\n if (isStepsHeaderActive) {\n scrollingService.disableScrolling()\n\n const activeStepElement = document.getElementById(\n `steps-navigation-step-${currentPageId}`,\n )\n\n if (activeStepElement) {\n activeStepElement.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n })\n }\n } else {\n // Re-enable scroll on body when inactive\n scrollingService.enableScrolling()\n }\n }, [currentPageId, isStepsHeaderActive])\n\n const firstVisiblePage = visiblePages[0]\n const lastVisiblePage = visiblePages[visiblePages.length - 1]\n const isLastVisiblePage =\n lastVisiblePage && lastVisiblePage.id === currentPageId\n const isFirstVisiblePage =\n firstVisiblePage && firstVisiblePage.id === currentPageId\n const isDisplayingCurrentPageError = checkDisplayPageError(currentPage)\n\n // Clean up when form is navigated away\n React.useEffect(() => {\n return () => {\n scrollingService.enableScrolling()\n }\n }, [])\n\n return {\n visiblePages,\n isFirstVisiblePage,\n isLastVisiblePage,\n isDisplayingCurrentPageError,\n isShowingMultiplePages,\n isStepsHeaderActive,\n toggleStepsNavigation,\n currentPageIndex,\n currentPage,\n currentPageNumber,\n checkDisplayPageError,\n setPageId,\n goToPreviousPage,\n goToNextPage,\n scrollToTopOfPageHTMLElementRef,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"usePages.js","sourceRoot":"","sources":["../../src/hooks/usePages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAM5D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAK,EACL,sBAAsB,EACtB,8BAA8B,GAK/B;IACC,MAAM,+BAA+B,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAA;IAC1E,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAW,EAAE,CAAC,CAAA;IAExE,MAAM,CAAC,mBAAmB,EAAE,AAAD,EAAG,oBAAoB,EAAE,qBAAqB,CAAC,GACxE,eAAe,CAAC,KAAK,CAAC,CAAA;IAExB,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAA0B,GAAG,EAAE;QAC/D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE;;YAClC,OAAO,CAAC,CAAA,MAAA,8BAA8B,aAA9B,8BAA8B,uBAA9B,8BAA8B,CAAG,WAAW,CAAC,EAAE,CAAC,0CAAE,QAAQ,CAAA,CAAA;QACpE,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC,CAAA;IAE3C,MAAM,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BAAgB,CAAC,eAAe,EAAE,CAAA;SACnC;IACH,CAAC,EAAE,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC,CAAA;IAExC,MAAM,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IACxC,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC7D,MAAM,iBAAiB,GACrB,eAAe,IAAI,eAAe,CAAC,EAAE,KAAK,aAAa,CAAA;IACzD,MAAM,kBAAkB,GACtB,gBAAgB,IAAI,gBAAgB,CAAC,EAAE,KAAK,aAAa,CAAA;IAC3D,MAAM,4BAA4B,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAA;IAEvE,uCAAuC;IACvC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,OAAO,GAAG,EAAE;YACV,gBAAgB,CAAC,eAAe,EAAE,CAAA;QACpC,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,YAAY;QACZ,kBAAkB;QAClB,iBAAiB;QACjB,4BAA4B;QAC5B,sBAAsB;QACtB,mBAAmB;QACnB,qBAAqB;QACrB,gBAAgB;QAChB,WAAW;QACX,iBAAiB;QACjB,qBAAqB;QACrB,SAAS;QACT,gBAAgB;QAChB,YAAY;QACZ,+BAA+B;KAChC,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport useBooleanState from '../hooks/useBooleanState'\nimport { checkSectionValidity } from '../services/form-validation'\nimport scrollingService from '../services/scrolling-service'\nimport {\n FormElementsConditionallyShown,\n FormElementsValidation,\n} from '../types/form'\n\nexport default function usePages({\n pages,\n formElementsValidation,\n formElementsConditionallyShown,\n}: {\n pages: FormTypes.PageElement[]\n formElementsValidation: FormElementsValidation | undefined\n formElementsConditionallyShown: FormElementsConditionallyShown\n}) {\n const scrollToTopOfPageHTMLElementRef = React.useRef<HTMLDivElement>(null)\n const [visitedPageIds, setVisitedPageIds] = React.useState<string[]>([])\n\n const [isStepsHeaderActive, , closeStepsNavigation, toggleStepsNavigation] =\n useBooleanState(false)\n\n const visiblePages = React.useMemo<FormTypes.PageElement[]>(() => {\n return pages.filter((pageElement) => {\n return !formElementsConditionallyShown?.[pageElement.id]?.isHidden\n })\n }, [formElementsConditionallyShown, pages])\n\n const [currentPageId, setCurrentPageId] = React.useState(visiblePages[0].id)\n\n const currentPage = React.useMemo(() => {\n const currentPageById = visiblePages.find((pageElement) => {\n return pageElement.id === currentPageId\n })\n if (currentPageById) {\n return currentPageById\n } else {\n return visiblePages[0]\n }\n }, [currentPageId, visiblePages])\n\n const currentPageIndex = React.useMemo(\n () => visiblePages.indexOf(currentPage),\n [currentPage, visiblePages],\n )\n\n const currentPageNumber = React.useMemo(() => {\n if (currentPage) {\n return visiblePages.indexOf(currentPage) + 1\n }\n }, [currentPage, visiblePages])\n\n const isShowingMultiplePages = visiblePages.length > 1\n\n const setPageId = React.useCallback(\n (pageId: string) => {\n setVisitedPageIds((currentVisitedPageIds) => {\n if (currentVisitedPageIds.includes(currentPageId)) {\n return currentVisitedPageIds\n } else {\n return [...currentVisitedPageIds, currentPageId]\n }\n })\n setCurrentPageId(pageId)\n closeStepsNavigation()\n\n const scrollToTopOfPageHTMLElement =\n scrollToTopOfPageHTMLElementRef.current\n if (isShowingMultiplePages && scrollToTopOfPageHTMLElement) {\n if (scrollToTopOfPageHTMLElement) {\n window.requestAnimationFrame(() => {\n scrollToTopOfPageHTMLElement.scrollIntoView({\n block: 'start',\n behavior: 'smooth',\n })\n })\n }\n const stepItemHTMLElement = document.getElementById(\n `steps-navigation-step-${pageId}`,\n )\n if (stepItemHTMLElement) {\n window.requestAnimationFrame(() => {\n stepItemHTMLElement.scrollIntoView({\n block: 'start',\n behavior: 'smooth',\n })\n })\n }\n }\n },\n [closeStepsNavigation, currentPageId, isShowingMultiplePages],\n )\n\n const goToNextPage = React.useCallback(() => {\n for (let i = 0; i < visiblePages.length; i++) {\n const page = visiblePages[i]\n if (page.id === currentPageId) {\n const nextVisiblePage = visiblePages[i + 1]\n if (nextVisiblePage) {\n setPageId(nextVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const goToPreviousPage = React.useCallback(() => {\n for (let i = visiblePages.length - 1; i > -1; i--) {\n const page = visiblePages[i]\n if (page && page.id === currentPageId) {\n const previousVisiblePage = visiblePages[i - 1]\n if (previousVisiblePage) {\n setPageId(previousVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const checkDisplayPageError = React.useCallback(\n (page: FormTypes.PageElement) => {\n // If we have not visited the page yet, we will not display errors\n if (!visitedPageIds.includes(page.id)) {\n return false\n }\n\n return checkSectionValidity(page, formElementsValidation)\n },\n [formElementsValidation, visitedPageIds],\n )\n\n React.useEffect(() => {\n if (isStepsHeaderActive) {\n scrollingService.disableScrolling()\n\n const activeStepElement = document.getElementById(\n `steps-navigation-step-${currentPageId}`,\n )\n\n if (activeStepElement) {\n activeStepElement.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n })\n }\n } else {\n // Re-enable scroll on body when inactive\n scrollingService.enableScrolling()\n }\n }, [currentPageId, isStepsHeaderActive])\n\n const firstVisiblePage = visiblePages[0]\n const lastVisiblePage = visiblePages[visiblePages.length - 1]\n const isLastVisiblePage =\n lastVisiblePage && lastVisiblePage.id === currentPageId\n const isFirstVisiblePage =\n firstVisiblePage && firstVisiblePage.id === currentPageId\n const isDisplayingCurrentPageError = checkDisplayPageError(currentPage)\n\n // Clean up when form is navigated away\n React.useEffect(() => {\n return () => {\n scrollingService.enableScrolling()\n }\n }, [])\n\n return {\n visiblePages,\n isFirstVisiblePage,\n isLastVisiblePage,\n isDisplayingCurrentPageError,\n isShowingMultiplePages,\n isStepsHeaderActive,\n toggleStepsNavigation,\n currentPageIndex,\n currentPage,\n currentPageNumber,\n checkDisplayPageError,\n setPageId,\n goToPreviousPage,\n goToNextPage,\n scrollToTopOfPageHTMLElementRef,\n }\n}\n"]}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { FormTypes } from '@oneblink/types';
|
2
|
+
import { Attachment, AttachmentError } from '../types/attachments';
|
3
|
+
import { FormSubmissionModel } from '../types/form';
|
4
|
+
export declare function validateAttachmentExists(attachment: Attachment, attachmentRetentionInDays: number | undefined): AttachmentError | void;
|
5
|
+
export default function checkIfAttachmentsExist(form: FormTypes.Form, submission: FormSubmissionModel, attachmentRetentionInDays: number | undefined): FormSubmissionModel | void;
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import { v4 as uuid } from 'uuid';
|
2
|
+
import { checkIsUsingLegacyStorage } from './attachments';
|
3
|
+
export function validateAttachmentExists(attachment, attachmentRetentionInDays) {
|
4
|
+
if (attachment.type || !attachment.uploadedAt || !attachmentRetentionInDays) {
|
5
|
+
return;
|
6
|
+
}
|
7
|
+
const uploadedAt = new Date(attachment.uploadedAt);
|
8
|
+
const expiresAt = new Date(attachment.uploadedAt);
|
9
|
+
expiresAt.setDate(uploadedAt.getDate() + attachmentRetentionInDays);
|
10
|
+
const now = new Date();
|
11
|
+
console.log('Checking if attachment still exists', {
|
12
|
+
uploadedAt,
|
13
|
+
expiresAt,
|
14
|
+
attachment,
|
15
|
+
});
|
16
|
+
// check if attachment exists
|
17
|
+
if (expiresAt > now) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
const attachmentError = {
|
21
|
+
type: 'ERROR',
|
22
|
+
errorMessage: "This attachment has been removed based on your administrator's data retention policy, please remove it and upload it again.",
|
23
|
+
_id: uuid(),
|
24
|
+
fileName: attachment.fileName,
|
25
|
+
isPrivate: attachment.isPrivate,
|
26
|
+
};
|
27
|
+
return attachmentError;
|
28
|
+
}
|
29
|
+
function validateAttachmentsExists(attachments, attachmentRetentionInDays) {
|
30
|
+
if (!Array.isArray(attachments)) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
const newAttachments = [...attachments];
|
34
|
+
let hasChanges = false;
|
35
|
+
for (let index = 0; index < newAttachments.length; index++) {
|
36
|
+
const attachmentError = validateAttachmentExists(newAttachments[index], attachmentRetentionInDays);
|
37
|
+
if (attachmentError) {
|
38
|
+
hasChanges = true;
|
39
|
+
newAttachments[index] = attachmentError;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
if (hasChanges) {
|
43
|
+
return newAttachments;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
function checkIfAttachmentsExistForFormElements(formElements, submission, attachmentRetentionInDays) {
|
47
|
+
const result = {
|
48
|
+
...submission,
|
49
|
+
};
|
50
|
+
let hasChanges = false;
|
51
|
+
for (const formElement of formElements) {
|
52
|
+
switch (formElement.type) {
|
53
|
+
case 'section':
|
54
|
+
case 'page': {
|
55
|
+
const newSubmission = checkIfAttachmentsExistForFormElements(formElement.elements, result, attachmentRetentionInDays);
|
56
|
+
if (newSubmission) {
|
57
|
+
hasChanges = true;
|
58
|
+
Object.assign(result, newSubmission);
|
59
|
+
}
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
case 'form': {
|
63
|
+
const nestedSubmission = submission[formElement.name];
|
64
|
+
if (!nestedSubmission || typeof nestedSubmission !== 'object') {
|
65
|
+
break;
|
66
|
+
}
|
67
|
+
const newSubmission = checkIfAttachmentsExistForFormElements(formElement.elements || [], nestedSubmission, attachmentRetentionInDays);
|
68
|
+
if (newSubmission) {
|
69
|
+
hasChanges = true;
|
70
|
+
result[formElement.name] = newSubmission;
|
71
|
+
}
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
case 'repeatableSet': {
|
75
|
+
const entries = submission[formElement.name];
|
76
|
+
if (!Array.isArray(entries)) {
|
77
|
+
break;
|
78
|
+
}
|
79
|
+
const newEntries = [...entries];
|
80
|
+
let hasEntryChanges = false;
|
81
|
+
for (let index = 0; index < entries.length; index++) {
|
82
|
+
const entry = entries[index];
|
83
|
+
if (typeof entry === 'object') {
|
84
|
+
const newEntry = checkIfAttachmentsExistForFormElements(formElement.elements, entry, attachmentRetentionInDays);
|
85
|
+
if (newEntry) {
|
86
|
+
hasEntryChanges = true;
|
87
|
+
newEntries[index] = newEntry;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
if (hasEntryChanges) {
|
92
|
+
hasChanges = true;
|
93
|
+
result[formElement.name] = newEntries;
|
94
|
+
}
|
95
|
+
break;
|
96
|
+
}
|
97
|
+
case 'camera':
|
98
|
+
case 'draw':
|
99
|
+
case 'compliance':
|
100
|
+
case 'files': {
|
101
|
+
if (checkIsUsingLegacyStorage(formElement)) {
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
const value = submission[formElement.name];
|
105
|
+
if (!value) {
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
// If the attachment has a type, it has not finished uploading
|
109
|
+
switch (formElement.type) {
|
110
|
+
case 'camera':
|
111
|
+
case 'draw': {
|
112
|
+
const attachmentError = validateAttachmentExists(value, attachmentRetentionInDays);
|
113
|
+
if (attachmentError) {
|
114
|
+
hasChanges = true;
|
115
|
+
result[formElement.name] = attachmentError;
|
116
|
+
}
|
117
|
+
break;
|
118
|
+
}
|
119
|
+
case 'compliance': {
|
120
|
+
const newAttachments = validateAttachmentsExists(value.files, attachmentRetentionInDays);
|
121
|
+
if (newAttachments) {
|
122
|
+
hasChanges = true;
|
123
|
+
result[formElement.name] = {
|
124
|
+
...value,
|
125
|
+
files: newAttachments,
|
126
|
+
};
|
127
|
+
}
|
128
|
+
break;
|
129
|
+
}
|
130
|
+
case 'files': {
|
131
|
+
const newAttachments = validateAttachmentsExists(value, attachmentRetentionInDays);
|
132
|
+
if (newAttachments) {
|
133
|
+
hasChanges = true;
|
134
|
+
result[formElement.name] = newAttachments;
|
135
|
+
}
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
if (hasChanges) {
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
export default function checkIfAttachmentsExist(form, submission, attachmentRetentionInDays) {
|
147
|
+
return checkIfAttachmentsExistForFormElements(form.elements, submission, attachmentRetentionInDays);
|
148
|
+
}
|
149
|
+
//# sourceMappingURL=checkIfAttachmentsExist.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"checkIfAttachmentsExist.js","sourceRoot":"","sources":["../../src/services/checkIfAttachmentsExist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAIjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAA;AAGzD,MAAM,UAAU,wBAAwB,CACtC,UAAsB,EACtB,yBAA6C;IAE7C,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,yBAAyB,EAAE;QAC3E,OAAM;KACP;IAED,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IAClD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACjD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,yBAAyB,CAAC,CAAA;IACnE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE;QACjD,UAAU;QACV,SAAS;QACT,UAAU;KACX,CAAC,CAAA;IACF,6BAA6B;IAC7B,IAAI,SAAS,GAAG,GAAG,EAAE;QACnB,OAAM;KACP;IAED,MAAM,eAAe,GAAoB;QACvC,IAAI,EAAE,OAAO;QACb,YAAY,EACV,6HAA6H;QAC/H,GAAG,EAAE,IAAI,EAAE;QACX,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAA;IACD,OAAO,eAAe,CAAA;AACxB,CAAC;AAED,SAAS,yBAAyB,CAChC,WAAoB,EACpB,yBAA6C;IAE7C,IAAI,CAAC,KA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AAU,EACV,yBAAyB,CAC1B,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport { v4 as uuid } from 'uuid'\nimport { Attachment, AttachmentError } from '../types/attachments'\n\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\nimport { checkIsUsingLegacyStorage } from './attachments'\nimport { FormSubmissionModel } from '../types/form'\n\nexport function validateAttachmentExists(\n attachment: Attachment,\n attachmentRetentionInDays: number | undefined,\n): AttachmentError | void {\n if (attachment.type || !attachment.uploadedAt || !attachmentRetentionInDays) {\n return\n }\n\n const uploadedAt = new Date(attachment.uploadedAt)\n const expiresAt = new Date(attachment.uploadedAt)\n expiresAt.setDate(uploadedAt.getDate() + attachmentRetentionInDays)\n const now = new Date()\n console.log('Checking if attachment still exists', {\n uploadedAt,\n expiresAt,\n attachment,\n })\n // check if attachment exists\n if (expiresAt > now) {\n return\n }\n\n const attachmentError: AttachmentError = {\n type: 'ERROR',\n errorMessage:\n \"This attachment has been removed based on your administrator's data retention policy, please remove it and upload it again.\",\n _id: uuid(),\n fileName: attachment.fileName,\n isPrivate: attachment.isPrivate,\n }\n return attachmentError\n}\n\nfunction validateAttachmentsExists(\n attachments: unknown,\n attachmentRetentionInDays: number | undefined,\n): Attachment[] | void {\n if (!Array.isArray(attachments)) {\n return\n }\n const newAttachments = [...attachments]\n let hasChanges = false\n for (let index = 0; index < newAttachments.length; index++) {\n const attachmentError = validateAttachmentExists(\n newAttachments[index] as Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n newAttachments[index] = attachmentError\n }\n }\n if (hasChanges) {\n return newAttachments\n }\n}\n\nfunction checkIfAttachmentsExistForFormElements(\n formElements: FormTypes.FormElement[],\n submission: FormSubmissionModel,\n attachmentRetentionInDays: number | undefined,\n): FormSubmissionModel | void {\n const result: FormSubmissionModel = {\n ...submission,\n }\n let hasChanges = false\n for (const formElement of formElements) {\n switch (formElement.type) {\n case 'section':\n case 'page': {\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n result,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n Object.assign(result, newSubmission)\n }\n break\n }\n case 'form': {\n const nestedSubmission = submission[formElement.name]\n if (!nestedSubmission || typeof nestedSubmission !== 'object') {\n break\n }\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements || [],\n nestedSubmission as FormSubmissionModel,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n result[formElement.name] = newSubmission\n }\n break\n }\n case 'repeatableSet': {\n const entries = submission[formElement.name]\n if (!Array.isArray(entries)) {\n break\n }\n const newEntries = [...entries]\n let hasEntryChanges = false\n for (let index = 0; index < entries.length; index++) {\n const entry = entries[index]\n if (typeof entry === 'object') {\n const newEntry = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n entry,\n attachmentRetentionInDays,\n )\n if (newEntry) {\n hasEntryChanges = true\n newEntries[index] = newEntry\n }\n }\n }\n if (hasEntryChanges) {\n hasChanges = true\n result[formElement.name] = newEntries\n }\n break\n }\n case 'camera':\n case 'draw':\n case 'compliance':\n case 'files': {\n if (checkIsUsingLegacyStorage(formElement)) {\n break\n }\n\n const value = submission[formElement.name]\n if (!value) {\n break\n }\n\n // If the attachment has a type, it has not finished uploading\n switch (formElement.type) {\n case 'camera':\n case 'draw': {\n const attachmentError = validateAttachmentExists(\n value as Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n result[formElement.name] = attachmentError\n }\n break\n }\n case 'compliance': {\n const newAttachments = validateAttachmentsExists(\n (value as FormElementComplianceValue).files,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = {\n ...(value as FormElementComplianceValue),\n files: newAttachments,\n }\n }\n break\n }\n case 'files': {\n const newAttachments = validateAttachmentsExists(\n value,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = newAttachments\n }\n break\n }\n }\n }\n }\n }\n if (hasChanges) {\n return result\n }\n}\n\nexport default function checkIfAttachmentsExist(\n form: FormTypes.Form,\n submission: FormSubmissionModel,\n attachmentRetentionInDays: number | undefined,\n): FormSubmissionModel | void {\n return checkIfAttachmentsExistForFormElements(\n form.elements,\n submission,\n attachmentRetentionInDays,\n )\n}\n"]}
|
@@ -73,7 +73,10 @@ export async function downloadFileLegacy(dataURI, fileName) {
|
|
73
73
|
export default async function downloadAttachment(attachment) {
|
74
74
|
try {
|
75
75
|
if (attachment.type) {
|
76
|
-
|
76
|
+
if (attachment.data) {
|
77
|
+
await downloadFile(attachment.data, attachment.fileName);
|
78
|
+
}
|
79
|
+
return;
|
77
80
|
}
|
78
81
|
if (!attachment.isPrivate) {
|
79
82
|
return await downloadFile(attachment.url, attachment.fileName);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"download-file.js","sourceRoot":"","sources":["../../src/services/download-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AACzC,OAAO,SAAS,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,KAAK,UAAU,YAAY,CAAC,IAAmB,EAAE,QAAgB;IAC/D,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QACzE,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpC,MAAM,CAAC,iBAAiB,CACtB,MAAM,CAAC,UAAU,EACjB,CAAC,EACD,CAAC,EAAE,EAAE,EAAE;gBACL,EAAE,CAAC,IAAI,CAAC,OAAO,CACb,QAAQ,EACR;oBACE,MAAM,EAAE,IAAI;oBACZ,SAAS,EAA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CAAC,SAAS,EAAE;YACzB,OAAO,MAAM,YAAY,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;SAC/D;QACD,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;QACvE,OAAO,MAAM,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;KACrD;IAAC,OAAO,KAAK,EAAE;QACd,WAAW,CAAC,KAAc,CAAC,CAAA;KAC5B;AACH,CAAC","sourcesContent":["import { Sentry } from '@oneblink/apps'\nimport * as bulmaToast from 'bulma-toast'\nimport fileSaver from 'file-saver'\nimport { Attachment } from '../types/attachments'\nimport { urlToBlobAsync } from './blob-utils'\n\nasync function downloadFile(data: Blob | string, fileName: string) {\n if (window.cordova) {\n const file = typeof data === 'string' ? await urlToBlobAsync(data) : data\n await new Promise((resolve, reject) => {\n window.requestFileSystem(\n window.PERSISTENT,\n 0,\n (fs) => {\n fs.root.getFile(\n fileName,\n {\n create: true,\n exclusive: false,\n },\n (fileEntry) => {\n // Create a FileWriter object for our FileEntry\n fileEntry.createWriter(\n (fileWriter) => {\n fileWriter.onwriteend = () => {\n // @ts-expect-error ???\n window.cordova.plugins.fileOpener2.open(\n // @ts-expect-error ???\n fileEntry.nativeURL,\n file.type,\n {\n error: (error: Error) => {\n console.log(\n 'An error occurred opening the downloaded file',\n )\n reject(error)\n },\n success: () => resolve(undefined),\n },\n )\n }\n\n fileWriter.onerror = (error) => {\n console.log(\n 'An error occurred writing the file to file system',\n )\n reject(error)\n }\n\n fileWriter.write(file)\n },\n (error) => {\n console.log(\n 'An error attempting to create file writer for new file',\n )\n reject(error)\n },\n )\n },\n (error) => {\n console.log(\n 'An error occurred getting new file data from file system',\n )\n reject(error)\n },\n )\n },\n (error) => {\n console.log('An error occurred requesting access to the file system')\n reject(error)\n },\n )\n })\n return\n } else {\n fileSaver.saveAs(data, fileName)\n }\n}\n\nconst handleError = (error?: Error) => {\n if (error) {\n console.warn('An error occurred attempting to download file:', error)\n Sentry.captureException(error)\n bulmaToast.toast({\n message:\n 'Sorry, there was an issue downloading your file, please try again.',\n // @ts-expect-error bulma sets this string as a class, so we are hacking in our own classes\n type: 'ob-toast is-danger cypress-download-file-toast',\n dismissible: true,\n closeOnClick: true,\n })\n }\n}\n\nexport async function downloadFileLegacy(dataURI: string, fileName: string) {\n try {\n return await downloadFile(dataURI, fileName)\n } catch (error) {\n handleError(error as Error)\n }\n}\n\nexport default async function downloadAttachment(attachment: Attachment) {\n try {\n if (attachment.type) {\n if (attachment.data) {\n await downloadFile(attachment.data, attachment.fileName)\n }\n return\n }\n if (!attachment.isPrivate) {\n return await downloadFile(attachment.url, attachment.fileName)\n }\n const blob = await urlToBlobAsync(attachment.url, attachment.isPrivate)\n return await downloadFile(blob, attachment.fileName)\n } catch (error) {\n handleError(error as Error)\n }\n}\n"]}
|
@@ -25,69 +25,9 @@
|
|
25
25
|
margin-left: $size-8;
|
26
26
|
}
|
27
27
|
|
28
|
-
.ob-steps-navigation__header {
|
29
|
-
display: none;
|
30
|
-
}
|
31
|
-
|
32
28
|
.ob-form-container {
|
33
29
|
position: relative;
|
34
30
|
|
35
|
-
.steps {
|
36
|
-
&.is-small {
|
37
|
-
font-size: $size-6;
|
38
|
-
}
|
39
|
-
|
40
|
-
.step-item {
|
41
|
-
font-size: $size-7;
|
42
|
-
cursor: pointer;
|
43
|
-
|
44
|
-
&:focus {
|
45
|
-
outline: none;
|
46
|
-
}
|
47
|
-
|
48
|
-
&.is-disabled {
|
49
|
-
.step-marker {
|
50
|
-
opacity: 0.2;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
&.is-error {
|
55
|
-
.step-marker {
|
56
|
-
background-color: transparent;
|
57
|
-
border-color: transparent;
|
58
|
-
|
59
|
-
.material-icons {
|
60
|
-
background-color: $white;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
.steps-content {
|
67
|
-
width: 100%;
|
68
|
-
|
69
|
-
.step-content {
|
70
|
-
width: 100%;
|
71
|
-
|
72
|
-
&.is-invisible {
|
73
|
-
position: fixed;
|
74
|
-
top: 0;
|
75
|
-
bottom: 0;
|
76
|
-
overflow: hidden;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
&.is-single-step {
|
81
|
-
margin-top: 0;
|
82
|
-
margin-bottom: 0;
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
.step-progress-mobile {
|
87
|
-
display: none;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
31
|
.field {
|
92
32
|
width: 100%;
|
93
33
|
|
@@ -105,19 +45,6 @@
|
|
105
45
|
flex: 1;
|
106
46
|
}
|
107
47
|
|
108
|
-
.steps-header-active-page-icon {
|
109
|
-
color: $primary;
|
110
|
-
border: 0.2em solid $primary;
|
111
|
-
border-radius: 50%;
|
112
|
-
min-height: $size-4;
|
113
|
-
min-width: $size-4;
|
114
|
-
font-size: $size-7;
|
115
|
-
margin-right: $size-8;
|
116
|
-
display: inline-flex;
|
117
|
-
justify-content: center;
|
118
|
-
align-items: center;
|
119
|
-
}
|
120
|
-
|
121
48
|
@media only screen and (max-width: $mobile) {
|
122
49
|
.ob-form-container {
|
123
50
|
.ob-button {
|
@@ -137,100 +64,6 @@
|
|
137
64
|
}
|
138
65
|
}
|
139
66
|
|
140
|
-
@media only screen and (max-width: $tablet) {
|
141
|
-
.ob-steps-navigation {
|
142
|
-
position: relative;
|
143
|
-
}
|
144
|
-
|
145
|
-
.ob-steps-navigation__header {
|
146
|
-
z-index: 30;
|
147
|
-
height: $size-1;
|
148
|
-
display: flex;
|
149
|
-
align-items: center;
|
150
|
-
background-color: $white-ter;
|
151
|
-
box-shadow: $elevation-2;
|
152
|
-
-webkit-transition: box-shadow 0.2s ease;
|
153
|
-
-moz-transition: box-shadow 0.2s ease;
|
154
|
-
-o-transition: box-shadow 0.2s ease;
|
155
|
-
transition: box-shadow 0.2s ease;
|
156
|
-
|
157
|
-
&:focus {
|
158
|
-
outline: none;
|
159
|
-
}
|
160
|
-
|
161
|
-
&.is-active {
|
162
|
-
box-shadow: none;
|
163
|
-
|
164
|
-
& > .dropdown.icon {
|
165
|
-
transform: rotate(180deg);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
.steps-header-active-page {
|
170
|
-
flex: 1;
|
171
|
-
min-width: 0;
|
172
|
-
display: flex;
|
173
|
-
justify-content: center;
|
174
|
-
align-items: center;
|
175
|
-
|
176
|
-
.icon {
|
177
|
-
margin-right: $size-8;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
.steps-header-active-page-label {
|
182
|
-
white-space: nowrap;
|
183
|
-
overflow: hidden;
|
184
|
-
text-overflow: ellipsis;
|
185
|
-
}
|
186
|
-
|
187
|
-
.icon {
|
188
|
-
padding: $size-7;
|
189
|
-
line-height: 1;
|
190
|
-
-webkit-transition: transform 0.2s linear;
|
191
|
-
-moz-transition: transform 0.2s linear;
|
192
|
-
-o-transition: transform 0.2s linear;
|
193
|
-
transition: transform 0.2s linear;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
.ob-steps-navigation__steps {
|
198
|
-
z-index: 30;
|
199
|
-
position: absolute;
|
200
|
-
top: $size-1;
|
201
|
-
right: 0;
|
202
|
-
left: 0;
|
203
|
-
background-color: $white;
|
204
|
-
box-shadow: none;
|
205
|
-
max-height: 0;
|
206
|
-
overflow-y: auto;
|
207
|
-
-webkit-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
208
|
-
-moz-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
209
|
-
-o-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
210
|
-
transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
211
|
-
|
212
|
-
&.is-active {
|
213
|
-
box-shadow: $elevation-3;
|
214
|
-
max-height: 40vh;
|
215
|
-
}
|
216
|
-
|
217
|
-
.steps {
|
218
|
-
padding: $size-4;
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
.ob-steps-navigation__background.is-active {
|
223
|
-
background-color: $black;
|
224
|
-
opacity: 0.2;
|
225
|
-
z-index: 20;
|
226
|
-
position: absolute;
|
227
|
-
top: 0;
|
228
|
-
bottom: 0;
|
229
|
-
right: 0;
|
230
|
-
left: 0;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
|
234
67
|
.ob-hint-tooltip {
|
235
68
|
max-width: 400px;
|
236
69
|
}
|