@contember/react-client 1.0.0-alpha.8 → 1.0.0-rc.4
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/types/ClientError.d.ts +3 -0
- package/dist/types/ClientError.d.ts.map +1 -0
- package/dist/types/ContemberClient.d.ts +12 -0
- package/dist/types/ContemberClient.d.ts.map +1 -0
- package/dist/types/apiRequest/ApiRequestAction.d.ts +13 -0
- package/dist/types/apiRequest/ApiRequestAction.d.ts.map +1 -0
- package/dist/types/apiRequest/ApiRequestState.d.ts +21 -0
- package/dist/types/apiRequest/ApiRequestState.d.ts.map +1 -0
- package/dist/types/apiRequest/apiRequestReducer.d.ts +5 -0
- package/dist/types/apiRequest/apiRequestReducer.d.ts.map +1 -0
- package/dist/types/apiRequest/index.d.ts +5 -0
- package/dist/types/apiRequest/index.d.ts.map +1 -0
- package/dist/types/apiRequest/useApiRequest.d.ts +8 -0
- package/dist/types/apiRequest/useApiRequest.d.ts.map +1 -0
- package/dist/types/auth/SessionTokenContext.d.ts +3 -0
- package/dist/types/auth/SessionTokenContext.d.ts.map +1 -0
- package/dist/types/auth/SetSessionTokenContext.d.ts +3 -0
- package/dist/types/auth/SetSessionTokenContext.d.ts.map +1 -0
- package/dist/types/auth/index.d.ts +5 -0
- package/dist/types/auth/index.d.ts.map +1 -0
- package/dist/types/auth/useSessionToken.d.ts +2 -0
- package/dist/types/auth/useSessionToken.d.ts.map +1 -0
- package/dist/types/auth/useSetSessionToken.d.ts +2 -0
- package/dist/types/auth/useSetSessionToken.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/BuiltinElements.d.ts +49 -0
- package/dist/types/components/RichTextRenderer/BuiltinElements.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/BuiltinLeaves.d.ts +21 -0
- package/dist/types/components/RichTextRenderer/BuiltinLeaves.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/ElementRenderer.d.ts +22 -0
- package/dist/types/components/RichTextRenderer/ElementRenderer.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/LeafRenderer.d.ts +14 -0
- package/dist/types/components/RichTextRenderer/LeafRenderer.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/NormalizedRichTextBlock.d.ts +14 -0
- package/dist/types/components/RichTextRenderer/NormalizedRichTextBlock.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/ReferenceRenderer.d.ts +14 -0
- package/dist/types/components/RichTextRenderer/ReferenceRenderer.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RenderElementFallback.d.ts +12 -0
- package/dist/types/components/RichTextRenderer/RenderElementFallback.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RenderLeafFallback.d.ts +7 -0
- package/dist/types/components/RichTextRenderer/RenderLeafFallback.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextBlock.d.ts +2 -0
- package/dist/types/components/RichTextRenderer/RichTextBlock.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextElement.d.ts +7 -0
- package/dist/types/components/RichTextRenderer/RichTextElement.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextElementMetadata.d.ts +11 -0
- package/dist/types/components/RichTextRenderer/RichTextElementMetadata.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextLeaf.d.ts +4 -0
- package/dist/types/components/RichTextRenderer/RichTextLeaf.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextLeafMetadata.d.ts +4 -0
- package/dist/types/components/RichTextRenderer/RichTextLeafMetadata.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextReference.d.ts +4 -0
- package/dist/types/components/RichTextRenderer/RichTextReference.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderMetadata.d.ts +12 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderMetadata.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderMetadataContext.d.ts +8 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderMetadataContext.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts +29 -0
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RichTextRendererError.d.ts +3 -0
- package/dist/types/components/RichTextRenderer/RichTextRendererError.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/RootEditorNode.d.ts +9 -0
- package/dist/types/components/RichTextRenderer/RootEditorNode.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/defaultDeserialize.d.ts +5 -0
- package/dist/types/components/RichTextRenderer/defaultDeserialize.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/index.d.ts +16 -0
- package/dist/types/components/RichTextRenderer/index.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/renderChildren.d.ts +14 -0
- package/dist/types/components/RichTextRenderer/renderChildren.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer/resolveRichTextElementMetadata.d.ts +8 -0
- package/dist/types/components/RichTextRenderer/resolveRichTextElementMetadata.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/config/ApiBaseUrlContext.d.ts +3 -0
- package/dist/types/config/ApiBaseUrlContext.d.ts.map +1 -0
- package/dist/types/config/LoginTokenContext.d.ts +3 -0
- package/dist/types/config/LoginTokenContext.d.ts.map +1 -0
- package/dist/types/config/index.d.ts +5 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/config/useApiBaseUrl.d.ts +2 -0
- package/dist/types/config/useApiBaseUrl.d.ts.map +1 -0
- package/dist/types/config/useLoginToken.d.ts +2 -0
- package/dist/types/config/useLoginToken.d.ts.map +1 -0
- package/dist/types/content/index.d.ts +4 -0
- package/dist/types/content/index.d.ts.map +1 -0
- package/dist/types/content/useContentApiRequest.d.ts +3 -0
- package/dist/types/content/useContentApiRequest.d.ts.map +1 -0
- package/dist/types/content/useContentGraphQlClient.d.ts +3 -0
- package/dist/types/content/useContentGraphQlClient.d.ts.map +1 -0
- package/dist/types/content/useCurrentContentGraphQlClient.d.ts +3 -0
- package/dist/types/content/useCurrentContentGraphQlClient.d.ts.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/project/ProjectSlugContext.d.ts +3 -0
- package/dist/types/project/ProjectSlugContext.d.ts.map +1 -0
- package/dist/types/project/StageSlugContext.d.ts +3 -0
- package/dist/types/project/StageSlugContext.d.ts.map +1 -0
- package/dist/types/project/index.d.ts +5 -0
- package/dist/types/project/index.d.ts.map +1 -0
- package/dist/types/project/useProjectSlug.d.ts +2 -0
- package/dist/types/project/useProjectSlug.d.ts.map +1 -0
- package/dist/types/project/useStageSlug.d.ts +2 -0
- package/dist/types/project/useStageSlug.d.ts.map +1 -0
- package/dist/types/system/index.d.ts +4 -0
- package/dist/types/system/index.d.ts.map +1 -0
- package/dist/types/system/useCurrentSystemGraphQlClient.d.ts +3 -0
- package/dist/types/system/useCurrentSystemGraphQlClient.d.ts.map +1 -0
- package/dist/types/system/useSystemApiRequest.d.ts +3 -0
- package/dist/types/system/useSystemApiRequest.d.ts.map +1 -0
- package/dist/types/system/useSystemGraphQlClient.d.ts +2 -0
- package/dist/types/system/useSystemGraphQlClient.d.ts.map +1 -0
- package/dist/types/tenant/index.d.ts +3 -0
- package/dist/types/tenant/index.d.ts.map +1 -0
- package/dist/types/tenant/useTenantApiRequest.d.ts +3 -0
- package/dist/types/tenant/useTenantApiRequest.d.ts.map +1 -0
- package/dist/types/tenant/useTenantGraphQlClient.d.ts +2 -0
- package/dist/types/tenant/useTenantGraphQlClient.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/upload/FileId.d.ts +2 -0
- package/dist/types/upload/FileId.d.ts.map +1 -0
- package/dist/types/upload/FileUploadAction.d.ts +26 -0
- package/dist/types/upload/FileUploadAction.d.ts.map +1 -0
- package/dist/types/upload/FileUploadCompoundState.d.ts +4 -0
- package/dist/types/upload/FileUploadCompoundState.d.ts.map +1 -0
- package/dist/types/upload/FileUploadMetadata.d.ts +6 -0
- package/dist/types/upload/FileUploadMetadata.d.ts.map +1 -0
- package/dist/types/upload/FileUploadMultiTemporalState.d.ts +10 -0
- package/dist/types/upload/FileUploadMultiTemporalState.d.ts.map +1 -0
- package/dist/types/upload/FileUploadOperations.d.ts +18 -0
- package/dist/types/upload/FileUploadOperations.d.ts.map +1 -0
- package/dist/types/upload/FileWithMetadata.d.ts +8 -0
- package/dist/types/upload/FileWithMetadata.d.ts.map +1 -0
- package/dist/types/upload/SingleFileUploadState.d.ts +31 -0
- package/dist/types/upload/SingleFileUploadState.d.ts.map +1 -0
- package/dist/types/upload/fileUploadReducer.d.ts +5 -0
- package/dist/types/upload/fileUploadReducer.d.ts.map +1 -0
- package/dist/types/upload/index.d.ts +8 -0
- package/dist/types/upload/index.d.ts.map +1 -0
- package/dist/types/upload/toFileId.d.ts +4 -0
- package/dist/types/upload/toFileId.d.ts.map +1 -0
- package/dist/types/upload/useFileUpload.d.ts +11 -0
- package/dist/types/upload/useFileUpload.d.ts.map +1 -0
- package/dist/types/useGraphQlClient.d.ts +3 -0
- package/dist/types/useGraphQlClient.d.ts.map +1 -0
- package/dist/types/utils/assertNever.d.ts +2 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +6 -7
- package/src/ClientError.ts +1 -0
- package/src/ContemberClient.tsx +48 -0
- package/src/ambient.d.ts +1 -0
- package/src/apiRequest/ApiRequestAction.ts +17 -0
- package/src/apiRequest/ApiRequestState.ts +25 -0
- package/src/apiRequest/apiRequestReducer.ts +41 -0
- package/src/apiRequest/index.ts +4 -0
- package/src/apiRequest/useApiRequest.ts +73 -0
- package/src/auth/SessionTokenContext.ts +3 -0
- package/src/auth/SetSessionTokenContext.ts +5 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/useSessionToken.ts +4 -0
- package/src/auth/useSetSessionToken.ts +4 -0
- package/src/components/RichTextRenderer/BuiltinElements.ts +112 -0
- package/src/components/RichTextRenderer/BuiltinLeaves.ts +32 -0
- package/src/components/RichTextRenderer/ElementRenderer.tsx +71 -0
- package/src/components/RichTextRenderer/LeafRenderer.tsx +39 -0
- package/src/components/RichTextRenderer/NormalizedRichTextBlock.ts +17 -0
- package/src/components/RichTextRenderer/ReferenceRenderer.ts +26 -0
- package/src/components/RichTextRenderer/RenderElementFallback.tsx +147 -0
- package/src/components/RichTextRenderer/RenderLeafFallback.tsx +43 -0
- package/src/components/RichTextRenderer/RichTextBlock.ts +1 -0
- package/src/components/RichTextRenderer/RichTextElement.ts +10 -0
- package/src/components/RichTextRenderer/RichTextElementMetadata.ts +15 -0
- package/src/components/RichTextRenderer/RichTextLeaf.ts +3 -0
- package/src/components/RichTextRenderer/RichTextLeafMetadata.ts +3 -0
- package/src/components/RichTextRenderer/RichTextReference.ts +3 -0
- package/src/components/RichTextRenderer/RichTextRenderMetadata.ts +16 -0
- package/src/components/RichTextRenderer/RichTextRenderMetadataContext.ts +20 -0
- package/src/components/RichTextRenderer/RichTextRenderer.tsx +165 -0
- package/src/components/RichTextRenderer/RichTextRendererError.ts +1 -0
- package/src/components/RichTextRenderer/RootEditorNode.ts +12 -0
- package/src/components/RichTextRenderer/defaultDeserialize.ts +19 -0
- package/src/components/RichTextRenderer/index.ts +15 -0
- package/src/components/RichTextRenderer/renderChildren.tsx +50 -0
- package/src/components/RichTextRenderer/resolveRichTextElementMetadata.ts +50 -0
- package/src/components/index.ts +1 -0
- package/src/config/ApiBaseUrlContext.ts +3 -0
- package/src/config/LoginTokenContext.ts +3 -0
- package/src/config/index.ts +4 -0
- package/src/config/useApiBaseUrl.ts +4 -0
- package/src/config/useLoginToken.ts +4 -0
- package/src/content/index.ts +3 -0
- package/src/content/useContentApiRequest.ts +6 -0
- package/src/content/useContentGraphQlClient.ts +6 -0
- package/src/content/useCurrentContentGraphQlClient.ts +17 -0
- package/src/index.ts +15 -0
- package/src/project/ProjectSlugContext.ts +3 -0
- package/src/project/StageSlugContext.ts +3 -0
- package/src/project/index.ts +4 -0
- package/src/project/useProjectSlug.ts +4 -0
- package/src/project/useStageSlug.ts +4 -0
- package/src/system/index.ts +3 -0
- package/src/system/useCurrentSystemGraphQlClient.ts +13 -0
- package/src/system/useSystemApiRequest.ts +6 -0
- package/src/system/useSystemGraphQlClient.ts +4 -0
- package/src/tenant/index.ts +2 -0
- package/src/tenant/useTenantApiRequest.ts +6 -0
- package/src/tenant/useTenantGraphQlClient.ts +4 -0
- package/src/tsconfig.json +9 -0
- package/src/upload/FileId.ts +1 -0
- package/src/upload/FileUploadAction.ts +33 -0
- package/src/upload/FileUploadCompoundState.ts +7 -0
- package/src/upload/FileUploadMetadata.ts +6 -0
- package/src/upload/FileUploadMultiTemporalState.ts +10 -0
- package/src/upload/FileUploadOperations.ts +22 -0
- package/src/upload/FileWithMetadata.ts +8 -0
- package/src/upload/SingleFileUploadState.ts +35 -0
- package/src/upload/fileUploadReducer.ts +185 -0
- package/src/upload/index.ts +15 -0
- package/src/upload/toFileId.ts +12 -0
- package/src/upload/useFileUpload.ts +262 -0
- package/src/useGraphQlClient.ts +10 -0
- package/src/utils/assertNever.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/dist/react-client.d.ts +0 -367
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { FileUploader, S3FileUploader, UploadedFileMetadata } from '@contember/client'
|
|
2
|
+
import { Reducer, useCallback, useEffect, useMemo, useReducer, useRef } from 'react'
|
|
3
|
+
import { useCurrentContentGraphQlClient } from '../content'
|
|
4
|
+
import type { FileId } from './FileId'
|
|
5
|
+
import type { FileUploadAction } from './FileUploadAction'
|
|
6
|
+
import type { FileUploadCompoundState } from './FileUploadCompoundState'
|
|
7
|
+
import type { FileUploadMetadata } from './FileUploadMetadata'
|
|
8
|
+
import type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'
|
|
9
|
+
import type {
|
|
10
|
+
PurgeUpload,
|
|
11
|
+
FileUploadOperations,
|
|
12
|
+
InitializeUpload,
|
|
13
|
+
StartUpload,
|
|
14
|
+
StartUploadFileOptions,
|
|
15
|
+
FailUpload,
|
|
16
|
+
} from './FileUploadOperations'
|
|
17
|
+
import { fileUploadReducer, initializeFileUploadState } from './fileUploadReducer'
|
|
18
|
+
import type { FileWithMetadata } from './FileWithMetadata'
|
|
19
|
+
import { toFileId } from './toFileId'
|
|
20
|
+
|
|
21
|
+
export type FileUpload<Result = unknown, Metadata = undefined> = [
|
|
22
|
+
FileUploadCompoundState<Result, Metadata>,
|
|
23
|
+
FileUploadOperations<Metadata>,
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
export interface FileUploadOptions {
|
|
27
|
+
maxUpdateFrequency?: number // This does NOT apply to all kinds of updates.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const useFileUpload = <Result = unknown, Metadata = undefined>(
|
|
31
|
+
options?: FileUploadOptions,
|
|
32
|
+
): FileUpload<Result, Metadata> => {
|
|
33
|
+
const maxUpdateFrequency = options?.maxUpdateFrequency ?? 100
|
|
34
|
+
|
|
35
|
+
const contentApiClient = useCurrentContentGraphQlClient()
|
|
36
|
+
|
|
37
|
+
const updateTimeoutRef = useRef<number | undefined>(undefined)
|
|
38
|
+
const isFirstRenderRef = useRef(true)
|
|
39
|
+
const fileIdSeedRef = useRef(1)
|
|
40
|
+
|
|
41
|
+
const [multiTemporalState, dispatch] = useReducer<
|
|
42
|
+
Reducer<FileUploadMultiTemporalState<Result, Metadata>, FileUploadAction<Result, Metadata>>,
|
|
43
|
+
undefined
|
|
44
|
+
>(fileUploadReducer, undefined, initializeFileUploadState)
|
|
45
|
+
const multiTemporalStateRef = useRef(multiTemporalState)
|
|
46
|
+
|
|
47
|
+
const defaultUploader = useMemo(() => new S3FileUploader(), [])
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
multiTemporalStateRef.current = multiTemporalState
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const purgeUpload = useCallback<PurgeUpload>(files => {
|
|
54
|
+
dispatch({
|
|
55
|
+
type: 'purge',
|
|
56
|
+
files,
|
|
57
|
+
})
|
|
58
|
+
}, [])
|
|
59
|
+
const failUpload = useCallback<FailUpload>(error => {
|
|
60
|
+
dispatch({
|
|
61
|
+
type: 'finishWithError',
|
|
62
|
+
error,
|
|
63
|
+
})
|
|
64
|
+
}, [])
|
|
65
|
+
const initializeUpload = useCallback<InitializeUpload>(
|
|
66
|
+
files => {
|
|
67
|
+
const newFileIds = new Set<FileId>()
|
|
68
|
+
const fileWithMetadataByFileConfig = new Map<FileId, FileWithMetadata>()
|
|
69
|
+
|
|
70
|
+
for (const fileMaybeWithId of files) {
|
|
71
|
+
const abortController = new AbortController()
|
|
72
|
+
|
|
73
|
+
let fileId: FileId
|
|
74
|
+
let file: File
|
|
75
|
+
|
|
76
|
+
if (fileMaybeWithId instanceof File) {
|
|
77
|
+
fileId = `__contember__file-${fileIdSeedRef.current++}`
|
|
78
|
+
file = fileMaybeWithId
|
|
79
|
+
} else {
|
|
80
|
+
fileId = fileMaybeWithId[0]
|
|
81
|
+
file = fileMaybeWithId[1]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
abortController.signal.addEventListener('abort', () => {
|
|
85
|
+
purgeUpload([fileId])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
fileWithMetadataByFileConfig.set(fileId, {
|
|
89
|
+
previewUrl: URL.createObjectURL(file),
|
|
90
|
+
abortController,
|
|
91
|
+
file,
|
|
92
|
+
fileId,
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
newFileIds.add(fileId)
|
|
96
|
+
}
|
|
97
|
+
if (fileWithMetadataByFileConfig.size === 0) {
|
|
98
|
+
return fileWithMetadataByFileConfig
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (newFileIds.size) {
|
|
102
|
+
dispatch({
|
|
103
|
+
type: 'purge',
|
|
104
|
+
files: newFileIds,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
dispatch({
|
|
109
|
+
type: 'initialize',
|
|
110
|
+
files: fileWithMetadataByFileConfig,
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
return fileWithMetadataByFileConfig
|
|
114
|
+
},
|
|
115
|
+
[purgeUpload],
|
|
116
|
+
)
|
|
117
|
+
const startUpload = useCallback<StartUpload<Metadata>>(
|
|
118
|
+
files => {
|
|
119
|
+
const filesById = new Map<FileId, FileUploadMetadata<Metadata>>()
|
|
120
|
+
const groupedByUploader: Map<FileUploader, Map<File, UploadedFileMetadata>> = new Map()
|
|
121
|
+
|
|
122
|
+
const currentState = multiTemporalStateRef.current
|
|
123
|
+
|
|
124
|
+
for (const fileOrIdMaybeWithOptions of files) {
|
|
125
|
+
let fileOrId: File | FileId
|
|
126
|
+
let options: StartUploadFileOptions<Metadata>
|
|
127
|
+
|
|
128
|
+
if (Array.isArray(fileOrIdMaybeWithOptions)) {
|
|
129
|
+
fileOrId = fileOrIdMaybeWithOptions[0]
|
|
130
|
+
options = fileOrIdMaybeWithOptions[1]
|
|
131
|
+
} else {
|
|
132
|
+
fileOrId = fileOrIdMaybeWithOptions
|
|
133
|
+
options = {}
|
|
134
|
+
}
|
|
135
|
+
const { uploader = defaultUploader, metadata } = options
|
|
136
|
+
|
|
137
|
+
const fileId = toFileId(currentState, fileOrId)
|
|
138
|
+
const fileState = currentState.liveState.get(fileId)
|
|
139
|
+
|
|
140
|
+
if (fileState === undefined || fileState.readyState !== 'initializing') {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Trying to startUpload a file that hasn't been previously initialized. ` +
|
|
143
|
+
`This will be possible in future, but isn't yet.`,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
filesById.set(fileId, {
|
|
148
|
+
uploader,
|
|
149
|
+
metadata,
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
let filesWithSameUploader = groupedByUploader.get(uploader)
|
|
153
|
+
if (filesWithSameUploader === undefined) {
|
|
154
|
+
groupedByUploader.set(uploader, (filesWithSameUploader = new Map()))
|
|
155
|
+
}
|
|
156
|
+
filesWithSameUploader.set(fileState.file, {
|
|
157
|
+
abortSignal: fileState.abortController.signal,
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
dispatch({
|
|
162
|
+
type: 'startUploading',
|
|
163
|
+
files: filesById,
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
for (const [uploader, filesForUpload] of groupedByUploader) {
|
|
167
|
+
try {
|
|
168
|
+
uploader.upload(filesForUpload, {
|
|
169
|
+
onProgress: progress => {
|
|
170
|
+
dispatch({
|
|
171
|
+
type: 'updateUploadProgress',
|
|
172
|
+
progress,
|
|
173
|
+
})
|
|
174
|
+
},
|
|
175
|
+
onSuccess: result => {
|
|
176
|
+
dispatch({
|
|
177
|
+
type: 'finishSuccessfully',
|
|
178
|
+
result,
|
|
179
|
+
})
|
|
180
|
+
},
|
|
181
|
+
onError: error => {
|
|
182
|
+
dispatch({
|
|
183
|
+
type: 'finishWithError',
|
|
184
|
+
error,
|
|
185
|
+
})
|
|
186
|
+
},
|
|
187
|
+
contentApiClient,
|
|
188
|
+
})
|
|
189
|
+
} catch (error) {
|
|
190
|
+
dispatch({
|
|
191
|
+
type: 'finishWithError',
|
|
192
|
+
error: Array.from(filesForUpload).map(([file]) => [file, error]),
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
[contentApiClient, defaultUploader],
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
const operations = useMemo<FileUploadOperations<Metadata>>(
|
|
201
|
+
() => ({
|
|
202
|
+
failUpload,
|
|
203
|
+
initializeUpload,
|
|
204
|
+
purgeUpload,
|
|
205
|
+
startUpload,
|
|
206
|
+
}),
|
|
207
|
+
[failUpload, initializeUpload, purgeUpload, startUpload],
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (isFirstRenderRef.current) {
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
if (multiTemporalState.isLiveStateDirty) {
|
|
215
|
+
const now = Date.now()
|
|
216
|
+
const timeDelta = Math.max(now - multiTemporalState.lastUpdateTime, 0) // The max is just a sanity check
|
|
217
|
+
if (timeDelta > maxUpdateFrequency) {
|
|
218
|
+
if (updateTimeoutRef.current !== undefined) {
|
|
219
|
+
clearTimeout(updateTimeoutRef.current)
|
|
220
|
+
}
|
|
221
|
+
dispatch({
|
|
222
|
+
type: 'publishNewestState',
|
|
223
|
+
})
|
|
224
|
+
} else {
|
|
225
|
+
if (updateTimeoutRef.current !== undefined) {
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
updateTimeoutRef.current = window.setTimeout(() => {
|
|
229
|
+
dispatch({
|
|
230
|
+
type: 'publishNewestState',
|
|
231
|
+
})
|
|
232
|
+
updateTimeoutRef.current = undefined
|
|
233
|
+
}, maxUpdateFrequency - timeDelta)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, [
|
|
237
|
+
multiTemporalState.isLiveStateDirty,
|
|
238
|
+
multiTemporalState.lastUpdateTime,
|
|
239
|
+
multiTemporalState.liveState,
|
|
240
|
+
multiTemporalState.publicState,
|
|
241
|
+
maxUpdateFrequency,
|
|
242
|
+
])
|
|
243
|
+
|
|
244
|
+
useEffect(
|
|
245
|
+
() => () => {
|
|
246
|
+
for (const [, state] of multiTemporalStateRef.current.liveState) {
|
|
247
|
+
URL.revokeObjectURL(state.previewUrl)
|
|
248
|
+
}
|
|
249
|
+
for (const [, state] of multiTemporalStateRef.current.publicState) {
|
|
250
|
+
URL.revokeObjectURL(state.previewUrl)
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
[],
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
// For this to work, this effect must be the last one to run.
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
isFirstRenderRef.current = false
|
|
259
|
+
}, [])
|
|
260
|
+
|
|
261
|
+
return [multiTemporalState.publicState, operations]
|
|
262
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GraphQlClient } from '@contember/client'
|
|
2
|
+
import { useMemo } from 'react'
|
|
3
|
+
import { useSessionToken } from './auth'
|
|
4
|
+
import { useApiBaseUrl } from './config'
|
|
5
|
+
|
|
6
|
+
export const useGraphQlClient = (path: string): GraphQlClient => {
|
|
7
|
+
const apiBaseUrl = useApiBaseUrl()
|
|
8
|
+
const sessionToken = useSessionToken()
|
|
9
|
+
return useMemo(() => new GraphQlClient(`${apiBaseUrl}${path}`, sessionToken), [apiBaseUrl, path, sessionToken])
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './assertNever'
|
package/dist/react-client.d.ts
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
import { ComponentType } from 'react';
|
|
4
|
-
import { Context } from 'react';
|
|
5
|
-
import type { FileUploader } from '@contember/client';
|
|
6
|
-
import type { FileUploadError } from '@contember/client';
|
|
7
|
-
import { GraphQlClient } from '@contember/client';
|
|
8
|
-
import type { GraphQlClientFailedRequestMetadata } from '@contember/client';
|
|
9
|
-
import type { GraphQlClientRequestOptions } from '@contember/client';
|
|
10
|
-
import type { GraphQlClientVariables } from '@contember/client';
|
|
11
|
-
import { NamedExoticComponent } from 'react';
|
|
12
|
-
import { ReactElement } from 'react';
|
|
13
|
-
import type { ReactNode } from 'react';
|
|
14
|
-
|
|
15
|
-
export declare const ApiBaseUrlContext: Context<string | undefined>;
|
|
16
|
-
|
|
17
|
-
export declare type ApiRequestAction<SuccessData> = {
|
|
18
|
-
type: 'uninitialize';
|
|
19
|
-
} | {
|
|
20
|
-
type: 'initialize';
|
|
21
|
-
} | {
|
|
22
|
-
type: 'resolveSuccessfully';
|
|
23
|
-
data: SuccessData;
|
|
24
|
-
} | {
|
|
25
|
-
type: 'resolveWithError';
|
|
26
|
-
error: GraphQlClientFailedRequestMetadata;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export declare type ApiRequestReducer<SuccessData> = (previousState: ApiRequestState<SuccessData>, action: ApiRequestAction<SuccessData>) => ApiRequestState<SuccessData>;
|
|
30
|
-
|
|
31
|
-
export declare const apiRequestReducer: <SuccessData>(previousState: ApiRequestState<SuccessData>, action: ApiRequestAction<SuccessData>) => ApiRequestState<SuccessData>;
|
|
32
|
-
|
|
33
|
-
export declare type ApiRequestState<SuccessData> = {
|
|
34
|
-
isLoading: false;
|
|
35
|
-
isFinished: false;
|
|
36
|
-
readyState: 'uninitialized';
|
|
37
|
-
} | {
|
|
38
|
-
isLoading: true;
|
|
39
|
-
isFinished: false;
|
|
40
|
-
readyState: 'pending';
|
|
41
|
-
} | {
|
|
42
|
-
isLoading: false;
|
|
43
|
-
isFinished: true;
|
|
44
|
-
readyState: 'networkSuccess';
|
|
45
|
-
data: SuccessData;
|
|
46
|
-
} | {
|
|
47
|
-
isLoading: false;
|
|
48
|
-
isFinished: true;
|
|
49
|
-
readyState: 'networkError';
|
|
50
|
-
data: GraphQlClientFailedRequestMetadata;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
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>;
|
|
54
|
-
|
|
55
|
-
export declare type BuiltinLeaves = RichTextBoldLeaf & RichTextCodeLeaf & RichTextHighlightLeaf & RichTextItalicLeaf & RichTextStrikeThroughLeaf & RichTextUnderlineLeaf;
|
|
56
|
-
|
|
57
|
-
export declare class ClientError extends Error {
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export declare const ContemberClient: NamedExoticComponent<ContemberClientProps & {
|
|
61
|
-
children: React.ReactNode;
|
|
62
|
-
}>;
|
|
63
|
-
|
|
64
|
-
export declare interface ContemberClientProps {
|
|
65
|
-
apiBaseUrl: string;
|
|
66
|
-
sessionToken?: string;
|
|
67
|
-
loginToken?: string;
|
|
68
|
-
project?: string;
|
|
69
|
-
stage?: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export declare type FailUpload = (files: Iterable<FileId | File | [FileId | File, any]>) => void;
|
|
73
|
-
|
|
74
|
-
export declare type FileId = string | number;
|
|
75
|
-
|
|
76
|
-
export declare type FileUpload<Result = unknown, Metadata = undefined> = [
|
|
77
|
-
FileUploadCompoundState<Result, Metadata>,
|
|
78
|
-
FileUploadOperations<Metadata>
|
|
79
|
-
];
|
|
80
|
-
|
|
81
|
-
export declare type FileUploadCompoundState<Result = unknown, Metadata = undefined> = Map<FileId, SingleFileUploadState<Result, Metadata>>;
|
|
82
|
-
|
|
83
|
-
export declare interface FileUploadMetadata<Metadata = undefined> {
|
|
84
|
-
uploader: FileUploader;
|
|
85
|
-
metadata: Metadata | undefined;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export declare interface FileUploadOperations<Metadata = undefined> {
|
|
89
|
-
initializeUpload: InitializeUpload;
|
|
90
|
-
startUpload: StartUpload<Metadata>;
|
|
91
|
-
purgeUpload: PurgeUpload;
|
|
92
|
-
failUpload: FailUpload;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export declare interface FileUploadOptions {
|
|
96
|
-
maxUpdateFrequency?: number;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export declare interface FileWithMetadata {
|
|
100
|
-
file: File;
|
|
101
|
-
fileId: FileId;
|
|
102
|
-
abortController: AbortController;
|
|
103
|
-
previewUrl: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export declare type InitializeUpload = (files: Iterable<[FileId, File] | File>) => Map<FileId, FileWithMetadata>;
|
|
107
|
-
|
|
108
|
-
export declare const LoginTokenContext: Context<string | undefined>;
|
|
109
|
-
|
|
110
|
-
export declare const ProjectSlugContext: Context<string | undefined>;
|
|
111
|
-
|
|
112
|
-
export declare type PurgeUpload = (files: Iterable<FileId | File>) => void;
|
|
113
|
-
|
|
114
|
-
export declare type ReferenceRenderer<Reference extends RichTextReference = RichTextReference, CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = (props: ReferenceRendererProps<Reference, CustomElements, CustomLeaves>) => ReactNode;
|
|
115
|
-
|
|
116
|
-
export declare type ReferenceRendererProps<Reference extends RichTextReference = RichTextReference, CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = {
|
|
117
|
-
element: CustomElements | BuiltinElements<CustomElements, CustomLeaves>;
|
|
118
|
-
children: ReactElement;
|
|
119
|
-
} & {
|
|
120
|
-
[Prop in keyof RichTextElementMetadata<CustomElements, CustomLeaves, Reference>]: Exclude<RichTextElementMetadata<CustomElements, CustomLeaves, Reference>[Prop], undefined>;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export declare interface RenderChildrenOptions<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
124
|
-
renderElement?: RenderElement<CustomElements, CustomLeaves>;
|
|
125
|
-
renderLeaf?: RenderLeaf<CustomLeaves>;
|
|
126
|
-
attributeNamePrefix?: string;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export declare type RenderElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never, Reference extends RichTextReference = RichTextReference> = ComponentType<{
|
|
130
|
-
element: CustomElements | BuiltinElements<CustomElements, CustomLeaves>;
|
|
131
|
-
children: ReactElement;
|
|
132
|
-
fallback: ReactElement;
|
|
133
|
-
renderChildren: (children: CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves | Array<CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves>, options: RenderChildrenOptions<CustomElements, CustomLeaves>) => ReactElement;
|
|
134
|
-
renderChildrenOptions: RenderChildrenOptions<CustomElements, CustomLeaves>;
|
|
135
|
-
} & RichTextElementMetadata<CustomElements, CustomLeaves, Reference>>;
|
|
136
|
-
|
|
137
|
-
export declare type RenderLeaf<CustomLeaves extends RichTextLeaf> = ComponentType<{
|
|
138
|
-
leaf: CustomLeaves | BuiltinLeaves;
|
|
139
|
-
fallback: ReactElement;
|
|
140
|
-
} & RichTextLeafMetadata>;
|
|
141
|
-
|
|
142
|
-
export declare interface RichTextAnchorElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
143
|
-
type: 'anchor';
|
|
144
|
-
href: string;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export declare type RichTextBlock = Record<string, unknown>;
|
|
148
|
-
|
|
149
|
-
export declare interface RichTextBoldLeaf extends RichTextLeaf {
|
|
150
|
-
isBold?: boolean;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export declare interface RichTextCodeLeaf extends RichTextLeaf {
|
|
154
|
-
isCode?: boolean;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export declare interface RichTextElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
158
|
-
type: string;
|
|
159
|
-
children: RichTextElement<CustomElements, CustomLeaves>[] | Array<CustomLeaves | RichTextLeaf>;
|
|
160
|
-
referenceId?: string;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export declare interface RichTextElementMetadata<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never, Reference extends RichTextReference = RichTextReference> {
|
|
164
|
-
formatVersion: number;
|
|
165
|
-
reference: Reference | undefined;
|
|
166
|
-
referenceType: string | undefined;
|
|
167
|
-
referenceRenderer: ReferenceRenderer<Reference, CustomElements, CustomLeaves> | undefined;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export declare interface RichTextHeadingElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
171
|
-
type: 'heading';
|
|
172
|
-
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
173
|
-
isNumbered?: boolean;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export declare interface RichTextHighlightLeaf extends RichTextLeaf {
|
|
177
|
-
isHighlighted?: boolean;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export declare interface RichTextHorizontalRuleElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
181
|
-
type: 'horizontalRule';
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export declare interface RichTextItalicLeaf extends RichTextLeaf {
|
|
185
|
-
isItalic?: boolean;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export declare interface RichTextLeaf {
|
|
189
|
-
text: string;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export declare interface RichTextLeafMetadata {
|
|
193
|
-
formatVersion: number;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export declare interface RichTextListItemElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
197
|
-
type: 'listItem';
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export declare interface RichTextOrderedListElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
201
|
-
type: 'orderedList';
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export declare interface RichTextParagraphElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
205
|
-
type: 'paragraph';
|
|
206
|
-
isNumbered?: boolean;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export declare interface RichTextReference {
|
|
210
|
-
id: string;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export declare interface RichTextReferenceElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
214
|
-
type: 'reference';
|
|
215
|
-
referenceId: string;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export declare const RichTextRenderer: <CustomElements extends RichTextElement<never, never> = never, CustomLeaves extends RichTextLeaf = never>(props: RichTextRendererProps<CustomElements, CustomLeaves>) => ReactElement;
|
|
219
|
-
|
|
220
|
-
export declare interface RichTextRendererBlockProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
221
|
-
blocks: RichTextBlock[];
|
|
222
|
-
referenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>;
|
|
223
|
-
sourceField?: string;
|
|
224
|
-
referencesField?: string;
|
|
225
|
-
referenceDiscriminationField?: string;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export declare class RichTextRendererError extends Error {
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export declare interface RichTextRendererFieldProps {
|
|
232
|
-
source: string | null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export declare type RichTextRendererProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> = {
|
|
236
|
-
deserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>;
|
|
237
|
-
renderElement?: RenderElement<CustomElements, CustomLeaves>;
|
|
238
|
-
renderLeaf?: RenderLeaf<CustomLeaves>;
|
|
239
|
-
attributeNamePrefix?: string;
|
|
240
|
-
renderBlock?: ComponentType<{
|
|
241
|
-
block: unknown;
|
|
242
|
-
}>;
|
|
243
|
-
} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>);
|
|
244
|
-
|
|
245
|
-
export declare interface RichTextScrollTargetElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
246
|
-
type: 'scrollTarget';
|
|
247
|
-
identifier: string;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export declare interface RichTextStrikeThroughLeaf extends RichTextLeaf {
|
|
251
|
-
isStruckThrough?: boolean;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export declare interface RichTextTableCellElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
255
|
-
type: 'tableCell';
|
|
256
|
-
headerScope?: 'row';
|
|
257
|
-
justify?: 'start' | 'center' | 'end';
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export declare interface RichTextTableElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
261
|
-
type: 'table';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export declare interface RichTextTableRowElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
265
|
-
type: 'tableRow';
|
|
266
|
-
headerScope?: 'table';
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export declare interface RichTextUnderlineLeaf extends RichTextLeaf {
|
|
270
|
-
isUnderlined?: boolean;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export declare interface RichTextUnorderedListElement<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> extends RichTextElement<CustomElements, CustomLeaves> {
|
|
274
|
-
type: 'unorderedList';
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export declare interface RootEditorNode<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
|
|
278
|
-
formatVersion: number;
|
|
279
|
-
children: Array<BuiltinElements<CustomElements, CustomLeaves> | CustomElements | BuiltinLeaves | CustomLeaves>;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export declare const SessionTokenContext: Context<string | undefined>;
|
|
283
|
-
|
|
284
|
-
export declare const SetSessionTokenContext: Context<(token: string | undefined) => void>;
|
|
285
|
-
|
|
286
|
-
export declare type SingleFileUploadState<Result = unknown, Metadata = undefined> = {
|
|
287
|
-
readyState: 'initializing';
|
|
288
|
-
abortController: AbortController;
|
|
289
|
-
file: File;
|
|
290
|
-
previewUrl: string;
|
|
291
|
-
} | {
|
|
292
|
-
readyState: 'uploading';
|
|
293
|
-
abortController: AbortController;
|
|
294
|
-
file: File;
|
|
295
|
-
metadata: Metadata;
|
|
296
|
-
previewUrl: string;
|
|
297
|
-
progress: number | undefined;
|
|
298
|
-
uploader: FileUploader;
|
|
299
|
-
} | {
|
|
300
|
-
readyState: 'success';
|
|
301
|
-
file: File;
|
|
302
|
-
metadata: Metadata;
|
|
303
|
-
previewUrl: string;
|
|
304
|
-
result: Result;
|
|
305
|
-
uploader: FileUploader;
|
|
306
|
-
} | {
|
|
307
|
-
readyState: 'error';
|
|
308
|
-
errors: FileUploadError[] | undefined;
|
|
309
|
-
rawError: any;
|
|
310
|
-
file: File;
|
|
311
|
-
metadata: Metadata | undefined;
|
|
312
|
-
previewUrl: string;
|
|
313
|
-
uploader: FileUploader | undefined;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
export declare const StageSlugContext: Context<string | undefined>;
|
|
317
|
-
|
|
318
|
-
export declare type StartUpload<Metadata = undefined> = (files: Iterable<FileId | File | [FileId | File, StartUploadFileOptions<Metadata>]>) => void;
|
|
319
|
-
|
|
320
|
-
export declare interface StartUploadFileOptions<Metadata = undefined> {
|
|
321
|
-
metadata?: Metadata;
|
|
322
|
-
uploader?: FileUploader;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export declare const useApiBaseUrl: () => string | undefined;
|
|
326
|
-
|
|
327
|
-
export declare const useApiRequest: <SuccessData>(client: GraphQlClient) => UseApiRequestResult<SuccessData>;
|
|
328
|
-
|
|
329
|
-
export declare type UseApiRequestResult<SuccessData> = [
|
|
330
|
-
ApiRequestState<SuccessData>,
|
|
331
|
-
(query: string, variables?: GraphQlClientVariables, options?: Omit<GraphQlClientRequestOptions, 'variables'>) => Promise<SuccessData>
|
|
332
|
-
];
|
|
333
|
-
|
|
334
|
-
export declare const useContentApiRequest: <SuccessData>() => UseApiRequestResult<SuccessData>;
|
|
335
|
-
|
|
336
|
-
export declare const useContentGraphQlClient: (projectSlug: string, stageSlug: string) => GraphQlClient;
|
|
337
|
-
|
|
338
|
-
export declare const useCurrentContentGraphQlClient: () => GraphQlClient;
|
|
339
|
-
|
|
340
|
-
export declare const useCurrentSystemGraphQlClient: () => GraphQlClient;
|
|
341
|
-
|
|
342
|
-
export declare const useFileUpload: <Result = unknown, Metadata = undefined>(options?: FileUploadOptions | undefined) => FileUpload<Result, Metadata>;
|
|
343
|
-
|
|
344
|
-
export declare const useGraphQlClient: (path: string) => GraphQlClient;
|
|
345
|
-
|
|
346
|
-
export declare const useLoginToken: () => string | undefined;
|
|
347
|
-
|
|
348
|
-
export declare const useProjectSlug: () => string | undefined;
|
|
349
|
-
|
|
350
|
-
export declare const useSessionToken: () => string | undefined;
|
|
351
|
-
|
|
352
|
-
export declare const useSetSessionToken: () => (token: string | undefined) => void;
|
|
353
|
-
|
|
354
|
-
export declare const useStageSlug: () => string | undefined;
|
|
355
|
-
|
|
356
|
-
export declare const useSystemApiRequest: <SuccessData>() => UseApiRequestResult<SuccessData>;
|
|
357
|
-
|
|
358
|
-
export declare const useSystemGraphQlClient: (projectSlug: string) => GraphQlClient;
|
|
359
|
-
|
|
360
|
-
export declare const useTenantApiRequest: <SuccessData>() => UseApiRequestResult<SuccessData>;
|
|
361
|
-
|
|
362
|
-
export declare const useTenantGraphQlClient: () => GraphQlClient;
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
export * from "@contember/client";
|
|
366
|
-
|
|
367
|
-
export { }
|