@contember/react-client 0.7.0-alpha.20
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/LICENSE +186 -0
- package/dist/development/ClientError.js +5 -0
- package/dist/development/ClientError.js.map +1 -0
- package/dist/development/ContemberClient.js +30 -0
- package/dist/development/ContemberClient.js.map +1 -0
- package/dist/development/apiRequest/apiRequestReducer.js +33 -0
- package/dist/development/apiRequest/apiRequestReducer.js.map +1 -0
- package/dist/development/apiRequest/useApiRequest.js +43 -0
- package/dist/development/apiRequest/useApiRequest.js.map +1 -0
- package/dist/development/auth/SessionTokenContext.js +6 -0
- package/dist/development/auth/SessionTokenContext.js.map +1 -0
- package/dist/development/auth/useLoginRequest.js +18 -0
- package/dist/development/auth/useLoginRequest.js.map +1 -0
- package/dist/development/auth/useSessionToken.js +7 -0
- package/dist/development/auth/useSessionToken.js.map +1 -0
- package/dist/development/components/RichTextRenderer/ElementRenderer.js +25 -0
- package/dist/development/components/RichTextRenderer/ElementRenderer.js.map +1 -0
- package/dist/development/components/RichTextRenderer/LeafRenderer.js +21 -0
- package/dist/development/components/RichTextRenderer/LeafRenderer.js.map +1 -0
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js +107 -0
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js.map +1 -0
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js +36 -0
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js.map +1 -0
- package/dist/development/components/RichTextRenderer/RichTextRenderMetadataContext.js +14 -0
- package/dist/development/components/RichTextRenderer/RichTextRenderMetadataContext.js.map +1 -0
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js +91 -0
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js.map +1 -0
- package/dist/development/components/RichTextRenderer/RichTextRendererError.js +5 -0
- package/dist/development/components/RichTextRenderer/RichTextRendererError.js.map +1 -0
- package/dist/development/components/RichTextRenderer/defaultDeserialize.js +13 -0
- package/dist/development/components/RichTextRenderer/defaultDeserialize.js.map +1 -0
- package/dist/development/components/RichTextRenderer/renderChildren.js +29 -0
- package/dist/development/components/RichTextRenderer/renderChildren.js.map +1 -0
- package/dist/development/components/RichTextRenderer/resolveRichTextElementMetadata.js +27 -0
- package/dist/development/components/RichTextRenderer/resolveRichTextElementMetadata.js.map +1 -0
- package/dist/development/config/ApiBaseUrlContext.js +6 -0
- package/dist/development/config/ApiBaseUrlContext.js.map +1 -0
- package/dist/development/config/LoginTokenContext.js +6 -0
- package/dist/development/config/LoginTokenContext.js.map +1 -0
- package/dist/development/config/useApiBaseUrl.js +7 -0
- package/dist/development/config/useApiBaseUrl.js.map +1 -0
- package/dist/development/config/useLoginToken.js +7 -0
- package/dist/development/config/useLoginToken.js.map +1 -0
- package/dist/development/content/useContentApiRequest.js +7 -0
- package/dist/development/content/useContentApiRequest.js.map +1 -0
- package/dist/development/content/useContentGraphQlClient.js +7 -0
- package/dist/development/content/useContentGraphQlClient.js.map +1 -0
- package/dist/development/content/useCurrentContentGraphQlClient.js +19 -0
- package/dist/development/content/useCurrentContentGraphQlClient.js.map +1 -0
- package/dist/development/index.js +31 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/project/ProjectSlugContext.js +6 -0
- package/dist/development/project/ProjectSlugContext.js.map +1 -0
- package/dist/development/project/StageSlugContext.js +6 -0
- package/dist/development/project/StageSlugContext.js.map +1 -0
- package/dist/development/project/useProjectSlug.js +7 -0
- package/dist/development/project/useProjectSlug.js.map +1 -0
- package/dist/development/project/useStageSlug.js +7 -0
- package/dist/development/project/useStageSlug.js.map +1 -0
- package/dist/development/system/useCurrentSystemGraphQlClient.js +14 -0
- package/dist/development/system/useCurrentSystemGraphQlClient.js.map +1 -0
- package/dist/development/system/useDiffQuery.js +17 -0
- package/dist/development/system/useDiffQuery.js.map +1 -0
- package/dist/development/system/useReleaseTreeMutation.js +17 -0
- package/dist/development/system/useReleaseTreeMutation.js.map +1 -0
- package/dist/development/system/useSystemApiRequest.js +7 -0
- package/dist/development/system/useSystemApiRequest.js.map +1 -0
- package/dist/development/system/useSystemGraphQlClient.js +7 -0
- package/dist/development/system/useSystemGraphQlClient.js.map +1 -0
- package/dist/development/tenant/useTenantApiRequest.js +7 -0
- package/dist/development/tenant/useTenantApiRequest.js.map +1 -0
- package/dist/development/tenant/useTenantGraphQlClient.js +7 -0
- package/dist/development/tenant/useTenantGraphQlClient.js.map +1 -0
- package/dist/development/upload/fileUploadReducer.js +162 -0
- package/dist/development/upload/fileUploadReducer.js.map +1 -0
- package/dist/development/upload/toFileId.js +9 -0
- package/dist/development/upload/toFileId.js.map +1 -0
- package/dist/development/upload/useFileUpload.js +192 -0
- package/dist/development/upload/useFileUpload.js.map +1 -0
- package/dist/development/useGraphQlClient.js +13 -0
- package/dist/development/useGraphQlClient.js.map +1 -0
- package/dist/development/utils/assertNever.js +6 -0
- package/dist/development/utils/assertNever.js.map +1 -0
- package/dist/production/ClientError.js +4 -0
- package/dist/production/ClientError.js.map +1 -0
- package/dist/production/ContemberClient.js +28 -0
- package/dist/production/ContemberClient.js.map +1 -0
- package/dist/production/apiRequest/apiRequestReducer.js +32 -0
- package/dist/production/apiRequest/apiRequestReducer.js.map +1 -0
- package/dist/production/apiRequest/useApiRequest.js +41 -0
- package/dist/production/apiRequest/useApiRequest.js.map +1 -0
- package/dist/production/auth/SessionTokenContext.js +4 -0
- package/dist/production/auth/SessionTokenContext.js.map +1 -0
- package/dist/production/auth/useLoginRequest.js +16 -0
- package/dist/production/auth/useLoginRequest.js.map +1 -0
- package/dist/production/auth/useSessionToken.js +5 -0
- package/dist/production/auth/useSessionToken.js.map +1 -0
- package/dist/production/components/RichTextRenderer/ElementRenderer.js +23 -0
- package/dist/production/components/RichTextRenderer/ElementRenderer.js.map +1 -0
- package/dist/production/components/RichTextRenderer/LeafRenderer.js +19 -0
- package/dist/production/components/RichTextRenderer/LeafRenderer.js.map +1 -0
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js +104 -0
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js.map +1 -0
- package/dist/production/components/RichTextRenderer/RenderLeafFallback.js +34 -0
- package/dist/production/components/RichTextRenderer/RenderLeafFallback.js.map +1 -0
- package/dist/production/components/RichTextRenderer/RichTextRenderMetadataContext.js +12 -0
- package/dist/production/components/RichTextRenderer/RichTextRenderMetadataContext.js.map +1 -0
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js +89 -0
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js.map +1 -0
- package/dist/production/components/RichTextRenderer/RichTextRendererError.js +4 -0
- package/dist/production/components/RichTextRenderer/RichTextRendererError.js.map +1 -0
- package/dist/production/components/RichTextRenderer/defaultDeserialize.js +12 -0
- package/dist/production/components/RichTextRenderer/defaultDeserialize.js.map +1 -0
- package/dist/production/components/RichTextRenderer/renderChildren.js +27 -0
- package/dist/production/components/RichTextRenderer/renderChildren.js.map +1 -0
- package/dist/production/components/RichTextRenderer/resolveRichTextElementMetadata.js +25 -0
- package/dist/production/components/RichTextRenderer/resolveRichTextElementMetadata.js.map +1 -0
- package/dist/production/config/ApiBaseUrlContext.js +4 -0
- package/dist/production/config/ApiBaseUrlContext.js.map +1 -0
- package/dist/production/config/LoginTokenContext.js +4 -0
- package/dist/production/config/LoginTokenContext.js.map +1 -0
- package/dist/production/config/useApiBaseUrl.js +5 -0
- package/dist/production/config/useApiBaseUrl.js.map +1 -0
- package/dist/production/config/useLoginToken.js +5 -0
- package/dist/production/config/useLoginToken.js.map +1 -0
- package/dist/production/content/useContentApiRequest.js +5 -0
- package/dist/production/content/useContentApiRequest.js.map +1 -0
- package/dist/production/content/useContentGraphQlClient.js +5 -0
- package/dist/production/content/useContentGraphQlClient.js.map +1 -0
- package/dist/production/content/useCurrentContentGraphQlClient.js +17 -0
- package/dist/production/content/useCurrentContentGraphQlClient.js.map +1 -0
- package/dist/production/index.js +31 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/project/ProjectSlugContext.js +4 -0
- package/dist/production/project/ProjectSlugContext.js.map +1 -0
- package/dist/production/project/StageSlugContext.js +4 -0
- package/dist/production/project/StageSlugContext.js.map +1 -0
- package/dist/production/project/useProjectSlug.js +5 -0
- package/dist/production/project/useProjectSlug.js.map +1 -0
- package/dist/production/project/useStageSlug.js +5 -0
- package/dist/production/project/useStageSlug.js.map +1 -0
- package/dist/production/system/useCurrentSystemGraphQlClient.js +12 -0
- package/dist/production/system/useCurrentSystemGraphQlClient.js.map +1 -0
- package/dist/production/system/useDiffQuery.js +15 -0
- package/dist/production/system/useDiffQuery.js.map +1 -0
- package/dist/production/system/useReleaseTreeMutation.js +15 -0
- package/dist/production/system/useReleaseTreeMutation.js.map +1 -0
- package/dist/production/system/useSystemApiRequest.js +5 -0
- package/dist/production/system/useSystemApiRequest.js.map +1 -0
- package/dist/production/system/useSystemGraphQlClient.js +5 -0
- package/dist/production/system/useSystemGraphQlClient.js.map +1 -0
- package/dist/production/tenant/useTenantApiRequest.js +5 -0
- package/dist/production/tenant/useTenantApiRequest.js.map +1 -0
- package/dist/production/tenant/useTenantGraphQlClient.js +5 -0
- package/dist/production/tenant/useTenantGraphQlClient.js.map +1 -0
- package/dist/production/upload/fileUploadReducer.js +160 -0
- package/dist/production/upload/fileUploadReducer.js.map +1 -0
- package/dist/production/upload/toFileId.js +8 -0
- package/dist/production/upload/toFileId.js.map +1 -0
- package/dist/production/upload/useFileUpload.js +190 -0
- package/dist/production/upload/useFileUpload.js.map +1 -0
- package/dist/production/useGraphQlClient.js +11 -0
- package/dist/production/useGraphQlClient.js.map +1 -0
- package/dist/production/utils/assertNever.js +5 -0
- package/dist/production/utils/assertNever.js.map +1 -0
- package/dist/react-client.d.ts +370 -0
- package/package.json +31 -0
- package/readme.md +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<\n\tResult,\n\tMetadata\n> => ({\n\tlastUpdateTime: 0,\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tliveState: new Map(),\n\tpublicState: new Map(),\n\tisLiveStateDirty: false,\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tconst publishNewState = (): FileUploadMultiTemporalState<Result, Metadata> => ({\n\t\tpublicState: previousState.liveState,\n\t\tfileIdByFile: previousState.fileIdByFile,\n\t\tlastUpdateTime: previousState.lastUpdateTime,\n\t\tisLiveStateDirty: false,\n\n\t\t// Immediately make the live state referentially unequal so that this doesn't have to happen during each action\n\t\t// several times between two publishes.\n\t\tliveState: new Map(previousState.liveState),\n\t})\n\tconst getNewDirtyState = (): FileUploadMultiTemporalState<Result, Metadata> => ({\n\t\tfileIdByFile: previousState.fileIdByFile,\n\t\tliveState: previousState.liveState,\n\t\tpublicState: previousState.publicState,\n\t\tisLiveStateDirty: true,\n\t\tlastUpdateTime: Date.now(),\n\t})\n\tswitch (action.type) {\n\t\tcase 'publishNewestState': {\n\t\t\treturn publishNewState()\n\t\t}\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\treturn publishNewState() /* Making the feedback about new files immediate*/\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = previousState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn publishNewState() /* Making the feedback about started upload immediate*/\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\t// return publishNewState() // Making the feedback about successful upload immediate.\n\t\t\treturn getNewDirtyState()\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn getNewDirtyState() // Bad news can wait.\n\t\t}\n\t\tcase 'purge': {\n\t\t\tlet atLeastOnePurged = false\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = previousState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatLeastOnePurged = true\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.delete(fileId)\n\t\t\t}\n\t\t\tif (atLeastOnePurged) {\n\t\t\t\treturn getNewDirtyState()\n\t\t\t}\n\t\t\treturn previousState\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn getNewDirtyState()\n\t\t}\n\t}\n\tassertNever(action)\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toFileId.js","sources":["../../../src/upload/toFileId.ts"],"sourcesContent":["import type { FileId } from './FileId'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\n\nexport const toFileId = <Result = unknown, Metadata = undefined>(\n\tstate: FileUploadMultiTemporalState<Result, Metadata>,\n\tfileOrId: File | FileId,\n) => {\n\tif (fileOrId instanceof File) {\n\t\treturn state.fileIdByFile.get(fileOrId)! // Should we throw instead of the yolo \"!\"?\n\t}\n\treturn fileOrId\n}\n"],"names":[],"mappings":"MAGa,WAAW,CACvB,OACA,aACI;MACA,oBAAoB,MAAM;WACtB,MAAM,aAAa,IAAI;AAAA;SAExB;AAAA;;"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { S3FileUploader } from "@contember/client";
|
|
2
|
+
import { useRef, useReducer, useMemo, useEffect, useCallback } from "react";
|
|
3
|
+
import { fileUploadReducer, initializeFileUploadState } from "./fileUploadReducer.js";
|
|
4
|
+
import { toFileId } from "./toFileId.js";
|
|
5
|
+
import { useCurrentContentGraphQlClient } from "../content/useCurrentContentGraphQlClient.js";
|
|
6
|
+
const useFileUpload = (options) => {
|
|
7
|
+
const maxUpdateFrequency = options?.maxUpdateFrequency ?? 100;
|
|
8
|
+
const contentApiClient = useCurrentContentGraphQlClient();
|
|
9
|
+
const updateTimeoutRef = useRef(void 0);
|
|
10
|
+
const isFirstRenderRef = useRef(true);
|
|
11
|
+
const fileIdSeedRef = useRef(1);
|
|
12
|
+
const [multiTemporalState, dispatch] = useReducer(fileUploadReducer, void 0, initializeFileUploadState);
|
|
13
|
+
const multiTemporalStateRef = useRef(multiTemporalState);
|
|
14
|
+
const defaultUploader = useMemo(() => new S3FileUploader(), []);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
multiTemporalStateRef.current = multiTemporalState;
|
|
17
|
+
});
|
|
18
|
+
const purgeUpload = useCallback((files) => {
|
|
19
|
+
dispatch({
|
|
20
|
+
type: "purge",
|
|
21
|
+
files
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
const failUpload = useCallback((error) => {
|
|
25
|
+
dispatch({
|
|
26
|
+
type: "finishWithError",
|
|
27
|
+
error
|
|
28
|
+
});
|
|
29
|
+
}, []);
|
|
30
|
+
const initializeUpload = useCallback((files) => {
|
|
31
|
+
const newFileIds = new Set();
|
|
32
|
+
const fileWithMetadataByFileConfig = new Map();
|
|
33
|
+
for (const fileMaybeWithId of files) {
|
|
34
|
+
const abortController = new AbortController();
|
|
35
|
+
let fileId;
|
|
36
|
+
let file;
|
|
37
|
+
if (fileMaybeWithId instanceof File) {
|
|
38
|
+
fileId = `__contember__file-${fileIdSeedRef.current++}`;
|
|
39
|
+
file = fileMaybeWithId;
|
|
40
|
+
} else {
|
|
41
|
+
fileId = fileMaybeWithId[0];
|
|
42
|
+
file = fileMaybeWithId[1];
|
|
43
|
+
}
|
|
44
|
+
abortController.signal.addEventListener("abort", () => {
|
|
45
|
+
purgeUpload([fileId]);
|
|
46
|
+
});
|
|
47
|
+
fileWithMetadataByFileConfig.set(fileId, {
|
|
48
|
+
previewUrl: URL.createObjectURL(file),
|
|
49
|
+
abortController,
|
|
50
|
+
file,
|
|
51
|
+
fileId
|
|
52
|
+
});
|
|
53
|
+
newFileIds.add(fileId);
|
|
54
|
+
}
|
|
55
|
+
if (fileWithMetadataByFileConfig.size === 0) {
|
|
56
|
+
return fileWithMetadataByFileConfig;
|
|
57
|
+
}
|
|
58
|
+
if (newFileIds.size) {
|
|
59
|
+
dispatch({
|
|
60
|
+
type: "purge",
|
|
61
|
+
files: newFileIds
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
dispatch({
|
|
65
|
+
type: "initialize",
|
|
66
|
+
files: fileWithMetadataByFileConfig
|
|
67
|
+
});
|
|
68
|
+
return fileWithMetadataByFileConfig;
|
|
69
|
+
}, [purgeUpload]);
|
|
70
|
+
const startUpload = useCallback((files) => {
|
|
71
|
+
const filesById = new Map();
|
|
72
|
+
const groupedByUploader = new Map();
|
|
73
|
+
const currentState = multiTemporalStateRef.current;
|
|
74
|
+
for (const fileOrIdMaybeWithOptions of files) {
|
|
75
|
+
let fileOrId;
|
|
76
|
+
let options2;
|
|
77
|
+
if (Array.isArray(fileOrIdMaybeWithOptions)) {
|
|
78
|
+
fileOrId = fileOrIdMaybeWithOptions[0];
|
|
79
|
+
options2 = fileOrIdMaybeWithOptions[1];
|
|
80
|
+
} else {
|
|
81
|
+
fileOrId = fileOrIdMaybeWithOptions;
|
|
82
|
+
options2 = {};
|
|
83
|
+
}
|
|
84
|
+
const { uploader = defaultUploader, metadata } = options2;
|
|
85
|
+
const fileId = toFileId(currentState, fileOrId);
|
|
86
|
+
const fileState = currentState.liveState.get(fileId);
|
|
87
|
+
if (fileState === void 0 || fileState.readyState !== "initializing") {
|
|
88
|
+
throw new Error(`Trying to startUpload a file that hasn't been previously initialized. This will be possible in future, but isn't yet.`);
|
|
89
|
+
}
|
|
90
|
+
filesById.set(fileId, {
|
|
91
|
+
uploader,
|
|
92
|
+
metadata
|
|
93
|
+
});
|
|
94
|
+
let filesWithSameUploader = groupedByUploader.get(uploader);
|
|
95
|
+
if (filesWithSameUploader === void 0) {
|
|
96
|
+
groupedByUploader.set(uploader, filesWithSameUploader = new Map());
|
|
97
|
+
}
|
|
98
|
+
filesWithSameUploader.set(fileState.file, {
|
|
99
|
+
abortSignal: fileState.abortController.signal
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
dispatch({
|
|
103
|
+
type: "startUploading",
|
|
104
|
+
files: filesById
|
|
105
|
+
});
|
|
106
|
+
for (const [uploader, filesForUpload] of groupedByUploader) {
|
|
107
|
+
try {
|
|
108
|
+
uploader.upload(filesForUpload, {
|
|
109
|
+
onProgress: (progress) => {
|
|
110
|
+
dispatch({
|
|
111
|
+
type: "updateUploadProgress",
|
|
112
|
+
progress
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
onSuccess: (result) => {
|
|
116
|
+
dispatch({
|
|
117
|
+
type: "finishSuccessfully",
|
|
118
|
+
result
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
onError: (error) => {
|
|
122
|
+
dispatch({
|
|
123
|
+
type: "finishWithError",
|
|
124
|
+
error
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
contentApiClient
|
|
128
|
+
});
|
|
129
|
+
} catch (error) {
|
|
130
|
+
dispatch({
|
|
131
|
+
type: "finishWithError",
|
|
132
|
+
error: Array.from(filesForUpload).map(([file]) => [file, error])
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}, [contentApiClient, defaultUploader]);
|
|
137
|
+
const operations = useMemo(() => ({
|
|
138
|
+
failUpload,
|
|
139
|
+
initializeUpload,
|
|
140
|
+
purgeUpload,
|
|
141
|
+
startUpload
|
|
142
|
+
}), [failUpload, initializeUpload, purgeUpload, startUpload]);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (isFirstRenderRef.current) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (multiTemporalState.isLiveStateDirty) {
|
|
148
|
+
const now = Date.now();
|
|
149
|
+
const timeDelta = Math.max(now - multiTemporalState.lastUpdateTime, 0);
|
|
150
|
+
if (timeDelta > maxUpdateFrequency) {
|
|
151
|
+
if (updateTimeoutRef.current !== void 0) {
|
|
152
|
+
clearTimeout(updateTimeoutRef.current);
|
|
153
|
+
}
|
|
154
|
+
dispatch({
|
|
155
|
+
type: "publishNewestState"
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
if (updateTimeoutRef.current !== void 0) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
updateTimeoutRef.current = window.setTimeout(() => {
|
|
162
|
+
dispatch({
|
|
163
|
+
type: "publishNewestState"
|
|
164
|
+
});
|
|
165
|
+
updateTimeoutRef.current = void 0;
|
|
166
|
+
}, maxUpdateFrequency - timeDelta);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, [
|
|
170
|
+
multiTemporalState.isLiveStateDirty,
|
|
171
|
+
multiTemporalState.lastUpdateTime,
|
|
172
|
+
multiTemporalState.liveState,
|
|
173
|
+
multiTemporalState.publicState,
|
|
174
|
+
maxUpdateFrequency
|
|
175
|
+
]);
|
|
176
|
+
useEffect(() => () => {
|
|
177
|
+
for (const [, state] of multiTemporalStateRef.current.liveState) {
|
|
178
|
+
URL.revokeObjectURL(state.previewUrl);
|
|
179
|
+
}
|
|
180
|
+
for (const [, state] of multiTemporalStateRef.current.publicState) {
|
|
181
|
+
URL.revokeObjectURL(state.previewUrl);
|
|
182
|
+
}
|
|
183
|
+
}, []);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
isFirstRenderRef.current = false;
|
|
186
|
+
}, []);
|
|
187
|
+
return [multiTemporalState.publicState, operations];
|
|
188
|
+
};
|
|
189
|
+
export { useFileUpload };
|
|
190
|
+
//# sourceMappingURL=useFileUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileUpload.js","sources":["../../../src/upload/useFileUpload.ts"],"sourcesContent":["import { FileUploader, S3FileUploader, UploadedFileMetadata } from '@contember/client'\nimport { Reducer, useCallback, useEffect, useMemo, useReducer, useRef } from 'react'\nimport { useCurrentContentGraphQlClient } from '../content'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadCompoundState } from './FileUploadCompoundState'\nimport type { FileUploadMetadata } from './FileUploadMetadata'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport type {\n\tPurgeUpload,\n\tFileUploadOperations,\n\tInitializeUpload,\n\tStartUpload,\n\tStartUploadFileOptions,\n\tFailUpload,\n} from './FileUploadOperations'\nimport { fileUploadReducer, initializeFileUploadState } from './fileUploadReducer'\nimport type { FileWithMetadata } from './FileWithMetadata'\nimport { toFileId } from './toFileId'\n\nexport type FileUpload<Result = unknown, Metadata = undefined> = [\n\tFileUploadCompoundState<Result, Metadata>,\n\tFileUploadOperations<Metadata>,\n]\n\nexport interface FileUploadOptions {\n\tmaxUpdateFrequency?: number // This does NOT apply to all kinds of updates.\n}\n\nexport const useFileUpload = <Result = unknown, Metadata = undefined>(\n\toptions?: FileUploadOptions,\n): FileUpload<Result, Metadata> => {\n\tconst maxUpdateFrequency = options?.maxUpdateFrequency ?? 100\n\n\tconst contentApiClient = useCurrentContentGraphQlClient()\n\n\tconst updateTimeoutRef = useRef<number | undefined>(undefined)\n\tconst isFirstRenderRef = useRef(true)\n\tconst fileIdSeedRef = useRef(1)\n\n\tconst [multiTemporalState, dispatch] = useReducer<\n\t\tReducer<FileUploadMultiTemporalState<Result, Metadata>, FileUploadAction<Result, Metadata>>,\n\t\tundefined\n\t>(fileUploadReducer, undefined, initializeFileUploadState)\n\tconst multiTemporalStateRef = useRef(multiTemporalState)\n\n\tconst defaultUploader = useMemo(() => new S3FileUploader(), [])\n\n\tuseEffect(() => {\n\t\tmultiTemporalStateRef.current = multiTemporalState\n\t})\n\n\tconst purgeUpload = useCallback<PurgeUpload>(files => {\n\t\tdispatch({\n\t\t\ttype: 'purge',\n\t\t\tfiles,\n\t\t})\n\t}, [])\n\tconst failUpload = useCallback<FailUpload>(error => {\n\t\tdispatch({\n\t\t\ttype: 'finishWithError',\n\t\t\terror,\n\t\t})\n\t}, [])\n\tconst initializeUpload = useCallback<InitializeUpload>(\n\t\tfiles => {\n\t\t\tconst newFileIds = new Set<FileId>()\n\t\t\tconst fileWithMetadataByFileConfig = new Map<FileId, FileWithMetadata>()\n\n\t\t\tfor (const fileMaybeWithId of files) {\n\t\t\t\tconst abortController = new AbortController()\n\n\t\t\t\tlet fileId: FileId\n\t\t\t\tlet file: File\n\n\t\t\t\tif (fileMaybeWithId instanceof File) {\n\t\t\t\t\tfileId = `__contember__file-${fileIdSeedRef.current++}`\n\t\t\t\t\tfile = fileMaybeWithId\n\t\t\t\t} else {\n\t\t\t\t\tfileId = fileMaybeWithId[0]\n\t\t\t\t\tfile = fileMaybeWithId[1]\n\t\t\t\t}\n\n\t\t\t\tabortController.signal.addEventListener('abort', () => {\n\t\t\t\t\tpurgeUpload([fileId])\n\t\t\t\t})\n\n\t\t\t\tfileWithMetadataByFileConfig.set(fileId, {\n\t\t\t\t\tpreviewUrl: URL.createObjectURL(file),\n\t\t\t\t\tabortController,\n\t\t\t\t\tfile,\n\t\t\t\t\tfileId,\n\t\t\t\t})\n\n\t\t\t\tnewFileIds.add(fileId)\n\t\t\t}\n\t\t\tif (fileWithMetadataByFileConfig.size === 0) {\n\t\t\t\treturn fileWithMetadataByFileConfig\n\t\t\t}\n\n\t\t\tif (newFileIds.size) {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: 'purge',\n\t\t\t\t\tfiles: newFileIds,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tdispatch({\n\t\t\t\ttype: 'initialize',\n\t\t\t\tfiles: fileWithMetadataByFileConfig,\n\t\t\t})\n\n\t\t\treturn fileWithMetadataByFileConfig\n\t\t},\n\t\t[purgeUpload],\n\t)\n\tconst startUpload = useCallback<StartUpload<Metadata>>(\n\t\tfiles => {\n\t\t\tconst filesById = new Map<FileId, FileUploadMetadata<Metadata>>()\n\t\t\tconst groupedByUploader: Map<FileUploader, Map<File, UploadedFileMetadata>> = new Map()\n\n\t\t\tconst currentState = multiTemporalStateRef.current\n\n\t\t\tfor (const fileOrIdMaybeWithOptions of files) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet options: StartUploadFileOptions<Metadata>\n\n\t\t\t\tif (Array.isArray(fileOrIdMaybeWithOptions)) {\n\t\t\t\t\tfileOrId = fileOrIdMaybeWithOptions[0]\n\t\t\t\t\toptions = fileOrIdMaybeWithOptions[1]\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = fileOrIdMaybeWithOptions\n\t\t\t\t\toptions = {}\n\t\t\t\t}\n\t\t\t\tconst { uploader = defaultUploader, metadata } = options\n\n\t\t\t\tconst fileId = toFileId(currentState, fileOrId)\n\t\t\t\tconst fileState = currentState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Trying to startUpload a file that hasn't been previously initialized. ` +\n\t\t\t\t\t\t\t`This will be possible in future, but isn't yet.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tfilesById.set(fileId, {\n\t\t\t\t\tuploader,\n\t\t\t\t\tmetadata,\n\t\t\t\t})\n\n\t\t\t\tlet filesWithSameUploader = groupedByUploader.get(uploader)\n\t\t\t\tif (filesWithSameUploader === undefined) {\n\t\t\t\t\tgroupedByUploader.set(uploader, (filesWithSameUploader = new Map()))\n\t\t\t\t}\n\t\t\t\tfilesWithSameUploader.set(fileState.file, {\n\t\t\t\t\tabortSignal: fileState.abortController.signal,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tdispatch({\n\t\t\t\ttype: 'startUploading',\n\t\t\t\tfiles: filesById,\n\t\t\t})\n\n\t\t\tfor (const [uploader, filesForUpload] of groupedByUploader) {\n\t\t\t\ttry {\n\t\t\t\t\tuploader.upload(filesForUpload, {\n\t\t\t\t\t\tonProgress: progress => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'updateUploadProgress',\n\t\t\t\t\t\t\t\tprogress,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonSuccess: result => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'finishSuccessfully',\n\t\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonError: error => {\n\t\t\t\t\t\t\tdispatch({\n\t\t\t\t\t\t\t\ttype: 'finishWithError',\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcontentApiClient,\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'finishWithError',\n\t\t\t\t\t\terror: Array.from(filesForUpload).map(([file]) => [file, error]),\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[contentApiClient, defaultUploader],\n\t)\n\n\tconst operations = useMemo<FileUploadOperations<Metadata>>(\n\t\t() => ({\n\t\t\tfailUpload,\n\t\t\tinitializeUpload,\n\t\t\tpurgeUpload,\n\t\t\tstartUpload,\n\t\t}),\n\t\t[failUpload, initializeUpload, purgeUpload, startUpload],\n\t)\n\n\tuseEffect(() => {\n\t\tif (isFirstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tif (multiTemporalState.isLiveStateDirty) {\n\t\t\tconst now = Date.now()\n\t\t\tconst timeDelta = Math.max(now - multiTemporalState.lastUpdateTime, 0) // The max is just a sanity check\n\t\t\tif (timeDelta > maxUpdateFrequency) {\n\t\t\t\tif (updateTimeoutRef.current !== undefined) {\n\t\t\t\t\tclearTimeout(updateTimeoutRef.current)\n\t\t\t\t}\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: 'publishNewestState',\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tif (updateTimeoutRef.current !== undefined) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tupdateTimeoutRef.current = window.setTimeout(() => {\n\t\t\t\t\tdispatch({\n\t\t\t\t\t\ttype: 'publishNewestState',\n\t\t\t\t\t})\n\t\t\t\t\tupdateTimeoutRef.current = undefined\n\t\t\t\t}, maxUpdateFrequency - timeDelta)\n\t\t\t}\n\t\t}\n\t}, [\n\t\tmultiTemporalState.isLiveStateDirty,\n\t\tmultiTemporalState.lastUpdateTime,\n\t\tmultiTemporalState.liveState,\n\t\tmultiTemporalState.publicState,\n\t\tmaxUpdateFrequency,\n\t])\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tfor (const [, state] of multiTemporalStateRef.current.liveState) {\n\t\t\t\tURL.revokeObjectURL(state.previewUrl)\n\t\t\t}\n\t\t\tfor (const [, state] of multiTemporalStateRef.current.publicState) {\n\t\t\t\tURL.revokeObjectURL(state.previewUrl)\n\t\t\t}\n\t\t},\n\t\t[],\n\t)\n\n\t// For this to work, this effect must be the last one to run.\n\tuseEffect(() => {\n\t\tisFirstRenderRef.current = false\n\t}, [])\n\n\treturn [multiTemporalState.publicState, operations]\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GraphQlClient } from "@contember/client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useApiBaseUrl } from "./config/useApiBaseUrl.js";
|
|
4
|
+
import { useSessionToken } from "./auth/useSessionToken.js";
|
|
5
|
+
const useGraphQlClient = (path) => {
|
|
6
|
+
const apiBaseUrl = useApiBaseUrl();
|
|
7
|
+
const sessionToken = useSessionToken();
|
|
8
|
+
return useMemo(() => new GraphQlClient(`${apiBaseUrl}${path}`, sessionToken), [apiBaseUrl, path, sessionToken]);
|
|
9
|
+
};
|
|
10
|
+
export { useGraphQlClient };
|
|
11
|
+
//# sourceMappingURL=useGraphQlClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGraphQlClient.js","sources":["../../src/useGraphQlClient.ts"],"sourcesContent":["import { GraphQlClient } from '@contember/client'\nimport { useMemo } from 'react'\nimport { useSessionToken } from './auth'\nimport { useApiBaseUrl } from './config'\n\nexport const useGraphQlClient = (path: string): GraphQlClient => {\n\tconst apiBaseUrl = useApiBaseUrl()\n\tconst sessionToken = useSessionToken()\n\treturn useMemo(() => new GraphQlClient(`${apiBaseUrl}${path}`, sessionToken), [apiBaseUrl, path, sessionToken])\n}\n"],"names":[],"mappings":";;;;MAKa,mBAAmB,CAAC,SAAgC;QAC1D,aAAa;QACb,eAAe;SACd,QAAQ,MAAM,IAAI,cAAc,GAAG,aAAa,QAAQ,eAAe,CAAC,YAAY,MAAM;AAAA;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertNever.js","sources":["../../../src/utils/assertNever.ts"],"sourcesContent":["export function assertNever(_: never): asserts _ is never {\n\tthrow new Error()\n}\n"],"names":[],"mappings":"qBAA4B,GAA8B;QACnD,IAAI;AAAA;;"}
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
3
|
+
import type { ComponentType } from 'react';
|
|
4
|
+
import { Context } from 'react';
|
|
5
|
+
import { DiffQueryResponse } from '@contember/client';
|
|
6
|
+
import type { FileUploader } from '@contember/client';
|
|
7
|
+
import type { FileUploadError } from '@contember/client';
|
|
8
|
+
import { GraphQlClient } from '@contember/client';
|
|
9
|
+
import type { GraphQlClientFailedRequestMetadata } from '@contember/client';
|
|
10
|
+
import type { GraphQlClientRequestOptions } from '@contember/client';
|
|
11
|
+
import type { GraphQlClientVariables } from '@contember/client';
|
|
12
|
+
import { LoginMutationResponse } from '@contember/client';
|
|
13
|
+
import { NamedExoticComponent } from 'react';
|
|
14
|
+
import { ReactElement } from 'react';
|
|
15
|
+
import type { ReactNode } from 'react';
|
|
16
|
+
import { ReleaseTreeMutationResponse } from '@contember/client';
|
|
17
|
+
import { TreeFilter } from '@contember/client';
|
|
18
|
+
|
|
19
|
+
export declare const ApiBaseUrlContext: Context<string | undefined>;
|
|
20
|
+
|
|
21
|
+
export declare type ApiRequestAction<SuccessData> = {
|
|
22
|
+
type: 'uninitialize';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'initialize';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'resolveSuccessfully';
|
|
27
|
+
data: SuccessData;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'resolveWithError';
|
|
30
|
+
error: GraphQlClientFailedRequestMetadata;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export declare type ApiRequestReducer<SuccessData> = (previousState: ApiRequestState<SuccessData>, action: ApiRequestAction<SuccessData>) => ApiRequestState<SuccessData>;
|
|
34
|
+
|
|
35
|
+
export declare const apiRequestReducer: <SuccessData>(previousState: ApiRequestState<SuccessData>, action: ApiRequestAction<SuccessData>) => ApiRequestState<SuccessData>;
|
|
36
|
+
|
|
37
|
+
export declare type ApiRequestState<SuccessData> = {
|
|
38
|
+
isLoading: false;
|
|
39
|
+
isFinished: false;
|
|
40
|
+
readyState: 'uninitialized';
|
|
41
|
+
} | {
|
|
42
|
+
isLoading: true;
|
|
43
|
+
isFinished: false;
|
|
44
|
+
readyState: 'pending';
|
|
45
|
+
} | {
|
|
46
|
+
isLoading: false;
|
|
47
|
+
isFinished: true;
|
|
48
|
+
readyState: 'networkSuccess';
|
|
49
|
+
data: SuccessData;
|
|
50
|
+
} | {
|
|
51
|
+
isLoading: false;
|
|
52
|
+
isFinished: true;
|
|
53
|
+
readyState: 'networkError';
|
|
54
|
+
data: GraphQlClientFailedRequestMetadata;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export declare type BuiltinElements<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = RichTextAnchorElement<CustomElements, CustomLeaves> | RichTextHeadingElement<CustomElements, CustomLeaves> | RichTextHorizontalRuleElement<CustomElements, CustomLeaves> | RichTextListItemElement<CustomElements, CustomLeaves> | RichTextOrderedListElement<CustomElements, CustomLeaves> | RichTextParagraphElement<CustomElements, CustomLeaves> | RichTextReferenceElement<CustomElements, CustomLeaves> | RichTextScrollTargetElement<CustomElements, CustomLeaves> | RichTextTableCellElement<CustomElements, CustomLeaves> | RichTextTableElement<CustomElements, CustomLeaves> | RichTextTableRowElement<CustomElements, CustomLeaves> | RichTextUnorderedListElement<CustomElements, CustomLeaves>;
|
|
58
|
+
|
|
59
|
+
export declare type BuiltinLeaves = RichTextBoldLeaf & RichTextCodeLeaf & RichTextHighlightLeaf & RichTextItalicLeaf & RichTextStrikeThroughLeaf & RichTextUnderlineLeaf;
|
|
60
|
+
|
|
61
|
+
export declare class ClientError extends Error {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export declare const ContemberClient: NamedExoticComponent<ContemberClientProps & {
|
|
65
|
+
children: React.ReactNode;
|
|
66
|
+
}>;
|
|
67
|
+
|
|
68
|
+
export declare interface ContemberClientProps {
|
|
69
|
+
apiBaseUrl: string;
|
|
70
|
+
sessionToken?: string;
|
|
71
|
+
loginToken?: string;
|
|
72
|
+
project?: string;
|
|
73
|
+
stage?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare type FailUpload = (files: Iterable<FileId | File | [FileId | File, any]>) => void;
|
|
77
|
+
|
|
78
|
+
export declare type FileId = string | number;
|
|
79
|
+
|
|
80
|
+
export declare type FileUpload<Result = unknown, Metadata = undefined> = [
|
|
81
|
+
FileUploadCompoundState<Result, Metadata>,
|
|
82
|
+
FileUploadOperations<Metadata>
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
export declare type FileUploadCompoundState<Result = unknown, Metadata = undefined> = Map<FileId, SingleFileUploadState<Result, Metadata>>;
|
|
86
|
+
|
|
87
|
+
export declare interface FileUploadMetadata<Metadata = undefined> {
|
|
88
|
+
uploader: FileUploader;
|
|
89
|
+
metadata: Metadata | undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare interface FileUploadOperations<Metadata = undefined> {
|
|
93
|
+
initializeUpload: InitializeUpload;
|
|
94
|
+
startUpload: StartUpload<Metadata>;
|
|
95
|
+
purgeUpload: PurgeUpload;
|
|
96
|
+
failUpload: FailUpload;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export declare interface FileUploadOptions {
|
|
100
|
+
maxUpdateFrequency?: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export declare interface FileWithMetadata {
|
|
104
|
+
file: File;
|
|
105
|
+
fileId: FileId;
|
|
106
|
+
abortController: AbortController;
|
|
107
|
+
previewUrl: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export declare type InitializeUpload = (files: Iterable<[FileId, File] | File>) => Map<FileId, FileWithMetadata>;
|
|
111
|
+
|
|
112
|
+
export declare const LoginTokenContext: Context<string | undefined>;
|
|
113
|
+
|
|
114
|
+
export declare const ProjectSlugContext: Context<string | undefined>;
|
|
115
|
+
|
|
116
|
+
export declare type PurgeUpload = (files: Iterable<FileId | File>) => void;
|
|
117
|
+
|
|
118
|
+
export declare type ReferenceRenderer<Reference extends RichTextReference = RichTextReference, CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = (props: ReferenceRendererProps<Reference, CustomElements, CustomLeaves>) => ReactNode;
|
|
119
|
+
|
|
120
|
+
export declare type ReferenceRendererProps<Reference extends RichTextReference = RichTextReference, CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = {
|
|
121
|
+
element: CustomElements | BuiltinElements<CustomElements, CustomLeaves>;
|
|
122
|
+
children: ReactElement;
|
|
123
|
+
} & {
|
|
124
|
+
[Prop in keyof RichTextElementMetadata<CustomElements, CustomLeaves, Reference>]: Exclude<RichTextElementMetadata<CustomElements, CustomLeaves, Reference>[Prop], undefined>;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export declare interface RenderChildrenOptions<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
128
|
+
renderElement?: RenderElement<CustomElements, CustomLeaves>;
|
|
129
|
+
renderLeaf?: RenderLeaf<CustomLeaves>;
|
|
130
|
+
attributeNamePrefix?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare type RenderElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never, Reference extends RichTextReference = RichTextReference> = ComponentType<{
|
|
134
|
+
element: CustomElements | BuiltinElements<CustomElements, CustomLeaves>;
|
|
135
|
+
children: ReactElement;
|
|
136
|
+
fallback: ReactElement;
|
|
137
|
+
renderChildren: (children: CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves | Array<CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves>, options: RenderChildrenOptions<CustomElements, CustomLeaves>) => ReactElement;
|
|
138
|
+
renderChildrenOptions: RenderChildrenOptions<CustomElements, CustomLeaves>;
|
|
139
|
+
} & RichTextElementMetadata<CustomElements, CustomLeaves, Reference>>;
|
|
140
|
+
|
|
141
|
+
export declare type RenderLeaf<CustomLeaves extends RichTextLeaf> = ComponentType<{
|
|
142
|
+
leaf: CustomLeaves | BuiltinLeaves;
|
|
143
|
+
fallback: ReactElement;
|
|
144
|
+
} & RichTextLeafMetadata>;
|
|
145
|
+
|
|
146
|
+
export declare interface RichTextAnchorElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
147
|
+
type: 'anchor';
|
|
148
|
+
href: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export declare type RichTextBlock = Record<string, unknown>;
|
|
152
|
+
|
|
153
|
+
export declare interface RichTextBoldLeaf extends RichTextLeaf {
|
|
154
|
+
isBold?: boolean;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export declare interface RichTextCodeLeaf extends RichTextLeaf {
|
|
158
|
+
isCode?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export declare interface RichTextElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
162
|
+
type: string;
|
|
163
|
+
children: RichTextElement<CustomElements, CustomLeaves>[] | Array<CustomLeaves | RichTextLeaf>;
|
|
164
|
+
referenceId?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export declare interface RichTextElementMetadata<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never, Reference extends RichTextReference = RichTextReference> {
|
|
168
|
+
formatVersion: number;
|
|
169
|
+
reference: Reference | undefined;
|
|
170
|
+
referenceType: string | undefined;
|
|
171
|
+
referenceRenderer: ReferenceRenderer<Reference, CustomElements, CustomLeaves> | undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare interface RichTextHeadingElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
175
|
+
type: 'heading';
|
|
176
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
177
|
+
isNumbered?: boolean;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export declare interface RichTextHighlightLeaf extends RichTextLeaf {
|
|
181
|
+
isHighlighted?: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export declare interface RichTextHorizontalRuleElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
185
|
+
type: 'horizontalRule';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export declare interface RichTextItalicLeaf extends RichTextLeaf {
|
|
189
|
+
isItalic?: boolean;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export declare interface RichTextLeaf {
|
|
193
|
+
text: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export declare interface RichTextLeafMetadata {
|
|
197
|
+
formatVersion: number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export declare interface RichTextListItemElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
201
|
+
type: 'listItem';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export declare interface RichTextOrderedListElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
205
|
+
type: 'orderedList';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export declare interface RichTextParagraphElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
209
|
+
type: 'paragraph';
|
|
210
|
+
isNumbered?: boolean;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export declare interface RichTextReference {
|
|
214
|
+
id: string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export declare interface RichTextReferenceElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
218
|
+
type: 'reference';
|
|
219
|
+
referenceId: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export declare const RichTextRenderer: <CustomElements extends RichTextElement<never, never> = never, CustomLeaves extends RichTextLeaf = never>(props: RichTextRendererProps<CustomElements, CustomLeaves>) => ReactElement;
|
|
223
|
+
|
|
224
|
+
export declare interface RichTextRendererBlockProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
225
|
+
blocks: RichTextBlock[];
|
|
226
|
+
referenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>;
|
|
227
|
+
sourceField?: string;
|
|
228
|
+
referencesField?: string;
|
|
229
|
+
referenceDiscriminationField?: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export declare class RichTextRendererError extends Error {
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export declare interface RichTextRendererFieldProps {
|
|
236
|
+
source: string | null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export declare type RichTextRendererProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = {
|
|
240
|
+
deserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>;
|
|
241
|
+
renderElement?: RenderElement<CustomElements, CustomLeaves>;
|
|
242
|
+
renderLeaf?: RenderLeaf<CustomLeaves>;
|
|
243
|
+
attributeNamePrefix?: string;
|
|
244
|
+
} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>);
|
|
245
|
+
|
|
246
|
+
export declare interface RichTextScrollTargetElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
247
|
+
type: 'scrollTarget';
|
|
248
|
+
identifier: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export declare interface RichTextStrikeThroughLeaf extends RichTextLeaf {
|
|
252
|
+
isStruckThrough?: boolean;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export declare interface RichTextTableCellElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
256
|
+
type: 'tableCell';
|
|
257
|
+
headerScope?: 'row';
|
|
258
|
+
justify?: 'start' | 'center' | 'end';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export declare interface RichTextTableElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
262
|
+
type: 'table';
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export declare interface RichTextTableRowElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
266
|
+
type: 'tableRow';
|
|
267
|
+
headerScope?: 'table';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export declare interface RichTextUnderlineLeaf extends RichTextLeaf {
|
|
271
|
+
isUnderlined?: boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export declare interface RichTextUnorderedListElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
275
|
+
type: 'unorderedList';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export declare interface RootEditorNode<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
279
|
+
formatVersion: number;
|
|
280
|
+
children: Array<BuiltinElements<CustomElements, CustomLeaves> | CustomElements | BuiltinLeaves | CustomLeaves>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export declare const SessionTokenContext: Context<string | undefined>;
|
|
284
|
+
|
|
285
|
+
export declare type SingleFileUploadState<Result = unknown, Metadata = undefined> = {
|
|
286
|
+
readyState: 'initializing';
|
|
287
|
+
abortController: AbortController;
|
|
288
|
+
file: File;
|
|
289
|
+
previewUrl: string;
|
|
290
|
+
} | {
|
|
291
|
+
readyState: 'uploading';
|
|
292
|
+
abortController: AbortController;
|
|
293
|
+
file: File;
|
|
294
|
+
metadata: Metadata;
|
|
295
|
+
previewUrl: string;
|
|
296
|
+
progress: number | undefined;
|
|
297
|
+
uploader: FileUploader;
|
|
298
|
+
} | {
|
|
299
|
+
readyState: 'success';
|
|
300
|
+
file: File;
|
|
301
|
+
metadata: Metadata;
|
|
302
|
+
previewUrl: string;
|
|
303
|
+
result: Result;
|
|
304
|
+
uploader: FileUploader;
|
|
305
|
+
} | {
|
|
306
|
+
readyState: 'error';
|
|
307
|
+
errors: FileUploadError[] | undefined;
|
|
308
|
+
rawError: any;
|
|
309
|
+
file: File;
|
|
310
|
+
metadata: Metadata | undefined;
|
|
311
|
+
previewUrl: string;
|
|
312
|
+
uploader: FileUploader | undefined;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export declare const StageSlugContext: Context<string | undefined>;
|
|
316
|
+
|
|
317
|
+
export declare type StartUpload<Metadata = undefined> = (files: Iterable<FileId | File | [FileId | File, StartUploadFileOptions<Metadata>]>) => void;
|
|
318
|
+
|
|
319
|
+
export declare interface StartUploadFileOptions<Metadata = undefined> {
|
|
320
|
+
metadata?: Metadata;
|
|
321
|
+
uploader?: FileUploader;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export declare const useApiBaseUrl: () => string | undefined;
|
|
325
|
+
|
|
326
|
+
export declare const useApiRequest: <SuccessData>(client: GraphQlClient) => UseApiRequestResult<SuccessData>;
|
|
327
|
+
|
|
328
|
+
export declare type UseApiRequestResult<SuccessData> = [
|
|
329
|
+
ApiRequestState<SuccessData>,
|
|
330
|
+
(query: string, variables?: GraphQlClientVariables, options?: Omit<GraphQlClientRequestOptions, 'variables'>) => Promise<SuccessData>
|
|
331
|
+
];
|
|
332
|
+
|
|
333
|
+
export declare const useContentApiRequest: <SuccessData>() => UseApiRequestResult<SuccessData>;
|
|
334
|
+
|
|
335
|
+
export declare const useContentGraphQlClient: (projectSlug: string, stageSlug: string) => GraphQlClient;
|
|
336
|
+
|
|
337
|
+
export declare const useCurrentContentGraphQlClient: () => GraphQlClient;
|
|
338
|
+
|
|
339
|
+
export declare const useCurrentSystemGraphQlClient: () => GraphQlClient;
|
|
340
|
+
|
|
341
|
+
export declare const useDiffQuery: () => [ApiRequestState<DiffQueryResponse>, (treeFilter: TreeFilter[]) => Promise<DiffQueryResponse>];
|
|
342
|
+
|
|
343
|
+
export declare const useFileUpload: <Result = unknown, Metadata = undefined>(options?: FileUploadOptions | undefined) => FileUpload<Result, Metadata>;
|
|
344
|
+
|
|
345
|
+
export declare const useGraphQlClient: (path: string) => GraphQlClient;
|
|
346
|
+
|
|
347
|
+
export declare const useLoginRequest: () => [ApiRequestState<LoginMutationResponse>, (email: string, password: string) => Promise<LoginMutationResponse>];
|
|
348
|
+
|
|
349
|
+
export declare const useLoginToken: () => string | undefined;
|
|
350
|
+
|
|
351
|
+
export declare const useProjectSlug: () => string | undefined;
|
|
352
|
+
|
|
353
|
+
export declare const useReleaseTreeMutation: () => [ApiRequestState<ReleaseTreeMutationResponse>, (treeFilter: TreeFilter[]) => Promise<ReleaseTreeMutationResponse>];
|
|
354
|
+
|
|
355
|
+
export declare const useSessionToken: () => string | undefined;
|
|
356
|
+
|
|
357
|
+
export declare const useStageSlug: () => string | undefined;
|
|
358
|
+
|
|
359
|
+
export declare const useSystemApiRequest: <SuccessData>() => UseApiRequestResult<SuccessData>;
|
|
360
|
+
|
|
361
|
+
export declare const useSystemGraphQlClient: (projectSlug: string) => GraphQlClient;
|
|
362
|
+
|
|
363
|
+
export declare const useTenantApiRequest: <SuccessData>() => UseApiRequestResult<SuccessData>;
|
|
364
|
+
|
|
365
|
+
export declare const useTenantGraphQlClient: () => GraphQlClient;
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
export * from "@contember/client";
|
|
369
|
+
|
|
370
|
+
export { }
|