@contember/react-client 1.1.0-alpha.9 → 1.1.0-beta.2
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/development/ClientError.js +3 -1
- package/dist/development/ClientError.js.map +1 -1
- package/dist/development/ContemberClient.js +49 -15
- package/dist/development/ContemberClient.js.map +1 -1
- package/dist/development/apiRequest/apiRequestReducer.js +3 -1
- package/dist/development/apiRequest/apiRequestReducer.js.map +1 -1
- package/dist/development/apiRequest/useApiRequest.js +33 -25
- package/dist/development/apiRequest/useApiRequest.js.map +1 -1
- package/dist/development/auth/SessionTokenContext.js +3 -1
- package/dist/development/auth/SessionTokenContext.js.map +1 -1
- package/dist/development/auth/SetSessionTokenContext.js +3 -1
- package/dist/development/auth/SetSessionTokenContext.js.map +1 -1
- package/dist/development/auth/useSessionToken.js +3 -1
- package/dist/development/auth/useSessionToken.js.map +1 -1
- package/dist/development/auth/useSetSessionToken.js +3 -1
- package/dist/development/auth/useSetSessionToken.js.map +1 -1
- package/dist/development/components/RichTextRenderer/ElementRenderer.js +18 -5
- package/dist/development/components/RichTextRenderer/ElementRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/LeafRenderer.js +11 -3
- package/dist/development/components/RichTextRenderer/LeafRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js +148 -50
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js +65 -13
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RichTextRenderMetadataContext.js +4 -1
- package/dist/development/components/RichTextRenderer/RichTextRenderMetadataContext.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js +44 -32
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RichTextRendererError.js +3 -1
- package/dist/development/components/RichTextRenderer/RichTextRendererError.js.map +1 -1
- package/dist/development/components/RichTextRenderer/defaultDeserialize.js +3 -1
- package/dist/development/components/RichTextRenderer/defaultDeserialize.js.map +1 -1
- package/dist/development/components/RichTextRenderer/renderChildren.js +31 -19
- package/dist/development/components/RichTextRenderer/renderChildren.js.map +1 -1
- package/dist/development/components/RichTextRenderer/resolveRichTextElementMetadata.js +6 -2
- package/dist/development/components/RichTextRenderer/resolveRichTextElementMetadata.js.map +1 -1
- package/dist/development/config/ApiBaseUrlContext.js +3 -1
- package/dist/development/config/ApiBaseUrlContext.js.map +1 -1
- package/dist/development/config/LoginTokenContext.js +3 -1
- package/dist/development/config/LoginTokenContext.js.map +1 -1
- package/dist/development/config/useApiBaseUrl.js +3 -1
- package/dist/development/config/useApiBaseUrl.js.map +1 -1
- package/dist/development/config/useLoginToken.js +3 -1
- package/dist/development/config/useLoginToken.js.map +1 -1
- package/dist/development/content/useContentApiRequest.js +3 -1
- package/dist/development/content/useContentApiRequest.js.map +1 -1
- package/dist/development/content/useContentGraphQlClient.js +3 -1
- package/dist/development/content/useContentGraphQlClient.js.map +1 -1
- package/dist/development/content/useCurrentContentGraphQlClient.js +3 -1
- package/dist/development/content/useCurrentContentGraphQlClient.js.map +1 -1
- package/dist/development/index.js +58 -28
- package/dist/development/project/ProjectSlugContext.js +3 -1
- package/dist/development/project/ProjectSlugContext.js.map +1 -1
- package/dist/development/project/StageSlugContext.js +3 -1
- package/dist/development/project/StageSlugContext.js.map +1 -1
- package/dist/development/project/useProjectSlug.js +3 -1
- package/dist/development/project/useProjectSlug.js.map +1 -1
- package/dist/development/project/useStageSlug.js +3 -1
- package/dist/development/project/useStageSlug.js.map +1 -1
- package/dist/development/system/useCurrentSystemGraphQlClient.js +3 -1
- package/dist/development/system/useCurrentSystemGraphQlClient.js.map +1 -1
- package/dist/development/system/useSystemApiRequest.js +3 -1
- package/dist/development/system/useSystemApiRequest.js.map +1 -1
- package/dist/development/system/useSystemGraphQlClient.js +3 -1
- package/dist/development/system/useSystemGraphQlClient.js.map +1 -1
- package/dist/development/tenant/useTenantApiRequest.js +3 -1
- package/dist/development/tenant/useTenantApiRequest.js.map +1 -1
- package/dist/development/tenant/useTenantGraphQlClient.js +3 -1
- package/dist/development/tenant/useTenantGraphQlClient.js.map +1 -1
- package/dist/development/upload/fileUploadReducer.js +4 -1
- package/dist/development/upload/fileUploadReducer.js.map +1 -1
- package/dist/development/upload/toFileId.js +3 -1
- package/dist/development/upload/toFileId.js.map +1 -1
- package/dist/development/upload/useFileUpload.js +131 -115
- package/dist/development/upload/useFileUpload.js.map +1 -1
- package/dist/development/useGraphQlClient.js +3 -1
- package/dist/development/useGraphQlClient.js.map +1 -1
- package/dist/development/utils/assertNever.js +3 -1
- package/dist/development/utils/assertNever.js.map +1 -1
- package/dist/production/ClientError.js +3 -1
- package/dist/production/ClientError.js.map +1 -1
- package/dist/production/ContemberClient.js +24 -15
- package/dist/production/ContemberClient.js.map +1 -1
- package/dist/production/apiRequest/apiRequestReducer.js +3 -1
- package/dist/production/apiRequest/apiRequestReducer.js.map +1 -1
- package/dist/production/apiRequest/useApiRequest.js +33 -25
- package/dist/production/apiRequest/useApiRequest.js.map +1 -1
- package/dist/production/auth/SessionTokenContext.js +3 -1
- package/dist/production/auth/SessionTokenContext.js.map +1 -1
- package/dist/production/auth/SetSessionTokenContext.js +3 -1
- package/dist/production/auth/SetSessionTokenContext.js.map +1 -1
- package/dist/production/auth/useSessionToken.js +3 -1
- package/dist/production/auth/useSessionToken.js.map +1 -1
- package/dist/production/auth/useSetSessionToken.js +3 -1
- package/dist/production/auth/useSetSessionToken.js.map +1 -1
- package/dist/production/components/RichTextRenderer/ElementRenderer.js +13 -5
- package/dist/production/components/RichTextRenderer/ElementRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/LeafRenderer.js +5 -2
- package/dist/production/components/RichTextRenderer/LeafRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js +81 -48
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RenderLeafFallback.js +32 -13
- package/dist/production/components/RichTextRenderer/RenderLeafFallback.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RichTextRenderMetadataContext.js +4 -1
- package/dist/production/components/RichTextRenderer/RichTextRenderMetadataContext.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js +39 -32
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RichTextRendererError.js +3 -1
- package/dist/production/components/RichTextRenderer/RichTextRendererError.js.map +1 -1
- package/dist/production/components/RichTextRenderer/defaultDeserialize.js +3 -1
- package/dist/production/components/RichTextRenderer/defaultDeserialize.js.map +1 -1
- package/dist/production/components/RichTextRenderer/renderChildren.js +22 -19
- package/dist/production/components/RichTextRenderer/renderChildren.js.map +1 -1
- package/dist/production/components/RichTextRenderer/resolveRichTextElementMetadata.js +6 -2
- package/dist/production/components/RichTextRenderer/resolveRichTextElementMetadata.js.map +1 -1
- package/dist/production/config/ApiBaseUrlContext.js +3 -1
- package/dist/production/config/ApiBaseUrlContext.js.map +1 -1
- package/dist/production/config/LoginTokenContext.js +3 -1
- package/dist/production/config/LoginTokenContext.js.map +1 -1
- package/dist/production/config/useApiBaseUrl.js +3 -1
- package/dist/production/config/useApiBaseUrl.js.map +1 -1
- package/dist/production/config/useLoginToken.js +3 -1
- package/dist/production/config/useLoginToken.js.map +1 -1
- package/dist/production/content/useContentApiRequest.js +3 -1
- package/dist/production/content/useContentApiRequest.js.map +1 -1
- package/dist/production/content/useContentGraphQlClient.js +3 -1
- package/dist/production/content/useContentGraphQlClient.js.map +1 -1
- package/dist/production/content/useCurrentContentGraphQlClient.js +3 -1
- package/dist/production/content/useCurrentContentGraphQlClient.js.map +1 -1
- package/dist/production/index.js +58 -28
- package/dist/production/project/ProjectSlugContext.js +3 -1
- package/dist/production/project/ProjectSlugContext.js.map +1 -1
- package/dist/production/project/StageSlugContext.js +3 -1
- package/dist/production/project/StageSlugContext.js.map +1 -1
- package/dist/production/project/useProjectSlug.js +3 -1
- package/dist/production/project/useProjectSlug.js.map +1 -1
- package/dist/production/project/useStageSlug.js +3 -1
- package/dist/production/project/useStageSlug.js.map +1 -1
- package/dist/production/system/useCurrentSystemGraphQlClient.js +3 -1
- package/dist/production/system/useCurrentSystemGraphQlClient.js.map +1 -1
- package/dist/production/system/useSystemApiRequest.js +3 -1
- package/dist/production/system/useSystemApiRequest.js.map +1 -1
- package/dist/production/system/useSystemGraphQlClient.js +3 -1
- package/dist/production/system/useSystemGraphQlClient.js.map +1 -1
- package/dist/production/tenant/useTenantApiRequest.js +3 -1
- package/dist/production/tenant/useTenantApiRequest.js.map +1 -1
- package/dist/production/tenant/useTenantGraphQlClient.js +3 -1
- package/dist/production/tenant/useTenantGraphQlClient.js.map +1 -1
- package/dist/production/upload/fileUploadReducer.js +4 -1
- package/dist/production/upload/fileUploadReducer.js.map +1 -1
- package/dist/production/upload/toFileId.js +3 -1
- package/dist/production/upload/toFileId.js.map +1 -1
- package/dist/production/upload/useFileUpload.js +131 -115
- package/dist/production/upload/useFileUpload.js.map +1 -1
- package/dist/production/useGraphQlClient.js +3 -1
- package/dist/production/useGraphQlClient.js.map +1 -1
- package/dist/production/utils/assertNever.js +3 -1
- package/dist/production/utils/assertNever.js.map +1 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts +2 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/upload/useFileUpload.d.ts +1 -1
- package/dist/types/upload/useFileUpload.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/RichTextRenderer/RichTextRenderer.tsx +1 -1
|
@@ -27,119 +27,130 @@ const useFileUpload = (options) => {
|
|
|
27
27
|
error
|
|
28
28
|
});
|
|
29
29
|
}, []);
|
|
30
|
-
const initializeUpload = useCallback(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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 = /* @__PURE__ */ new Map();
|
|
72
|
-
const groupedByUploader = /* @__PURE__ */ 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 = {};
|
|
30
|
+
const initializeUpload = useCallback(
|
|
31
|
+
(files) => {
|
|
32
|
+
const newFileIds = /* @__PURE__ */ new Set();
|
|
33
|
+
const fileWithMetadataByFileConfig = /* @__PURE__ */ new Map();
|
|
34
|
+
for (const fileMaybeWithId of files) {
|
|
35
|
+
const abortController = new AbortController();
|
|
36
|
+
let fileId;
|
|
37
|
+
let file;
|
|
38
|
+
if (fileMaybeWithId instanceof File) {
|
|
39
|
+
fileId = `__contember__file-${fileIdSeedRef.current++}`;
|
|
40
|
+
file = fileMaybeWithId;
|
|
41
|
+
} else {
|
|
42
|
+
fileId = fileMaybeWithId[0];
|
|
43
|
+
file = fileMaybeWithId[1];
|
|
44
|
+
}
|
|
45
|
+
abortController.signal.addEventListener("abort", () => {
|
|
46
|
+
purgeUpload([fileId]);
|
|
47
|
+
});
|
|
48
|
+
fileWithMetadataByFileConfig.set(fileId, {
|
|
49
|
+
previewUrl: URL.createObjectURL(file),
|
|
50
|
+
abortController,
|
|
51
|
+
file,
|
|
52
|
+
fileId
|
|
53
|
+
});
|
|
54
|
+
newFileIds.add(fileId);
|
|
83
55
|
}
|
|
84
|
-
|
|
85
|
-
|
|
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.`);
|
|
56
|
+
if (fileWithMetadataByFileConfig.size === 0) {
|
|
57
|
+
return fileWithMetadataByFileConfig;
|
|
89
58
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (filesWithSameUploader === void 0) {
|
|
96
|
-
groupedByUploader.set(uploader, filesWithSameUploader = /* @__PURE__ */ new Map());
|
|
59
|
+
if (newFileIds.size) {
|
|
60
|
+
dispatch({
|
|
61
|
+
type: "purge",
|
|
62
|
+
files: newFileIds
|
|
63
|
+
});
|
|
97
64
|
}
|
|
98
|
-
|
|
99
|
-
|
|
65
|
+
dispatch({
|
|
66
|
+
type: "initialize",
|
|
67
|
+
files: fileWithMetadataByFileConfig
|
|
100
68
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
69
|
+
return fileWithMetadataByFileConfig;
|
|
70
|
+
},
|
|
71
|
+
[purgeUpload]
|
|
72
|
+
);
|
|
73
|
+
const startUpload = useCallback(
|
|
74
|
+
(files) => {
|
|
75
|
+
const filesById = /* @__PURE__ */ new Map();
|
|
76
|
+
const groupedByUploader = /* @__PURE__ */ new Map();
|
|
77
|
+
const currentState = multiTemporalStateRef.current;
|
|
78
|
+
for (const fileOrIdMaybeWithOptions of files) {
|
|
79
|
+
let fileOrId;
|
|
80
|
+
let options2;
|
|
81
|
+
if (Array.isArray(fileOrIdMaybeWithOptions)) {
|
|
82
|
+
fileOrId = fileOrIdMaybeWithOptions[0];
|
|
83
|
+
options2 = fileOrIdMaybeWithOptions[1];
|
|
84
|
+
} else {
|
|
85
|
+
fileOrId = fileOrIdMaybeWithOptions;
|
|
86
|
+
options2 = {};
|
|
87
|
+
}
|
|
88
|
+
const { uploader = defaultUploader, metadata } = options2;
|
|
89
|
+
const fileId = toFileId(currentState, fileOrId);
|
|
90
|
+
const fileState = currentState.liveState.get(fileId);
|
|
91
|
+
if (fileState === void 0 || fileState.readyState !== "initializing") {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Trying to startUpload a file that hasn't been previously initialized. This will be possible in future, but isn't yet.`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
filesById.set(fileId, {
|
|
97
|
+
uploader,
|
|
98
|
+
metadata
|
|
128
99
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
100
|
+
let filesWithSameUploader = groupedByUploader.get(uploader);
|
|
101
|
+
if (filesWithSameUploader === void 0) {
|
|
102
|
+
groupedByUploader.set(uploader, filesWithSameUploader = /* @__PURE__ */ new Map());
|
|
103
|
+
}
|
|
104
|
+
filesWithSameUploader.set(fileState.file, {
|
|
105
|
+
abortSignal: fileState.abortController.signal
|
|
133
106
|
});
|
|
134
107
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
108
|
+
dispatch({
|
|
109
|
+
type: "startUploading",
|
|
110
|
+
files: filesById
|
|
111
|
+
});
|
|
112
|
+
for (const [uploader, filesForUpload] of groupedByUploader) {
|
|
113
|
+
try {
|
|
114
|
+
uploader.upload(filesForUpload, {
|
|
115
|
+
onProgress: (progress) => {
|
|
116
|
+
dispatch({
|
|
117
|
+
type: "updateUploadProgress",
|
|
118
|
+
progress
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
onSuccess: (result) => {
|
|
122
|
+
dispatch({
|
|
123
|
+
type: "finishSuccessfully",
|
|
124
|
+
result
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
onError: (error) => {
|
|
128
|
+
dispatch({
|
|
129
|
+
type: "finishWithError",
|
|
130
|
+
error
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
contentApiClient
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
dispatch({
|
|
137
|
+
type: "finishWithError",
|
|
138
|
+
error: Array.from(filesForUpload).map(([file]) => [file, error])
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
[contentApiClient, defaultUploader]
|
|
144
|
+
);
|
|
145
|
+
const operations = useMemo(
|
|
146
|
+
() => ({
|
|
147
|
+
failUpload,
|
|
148
|
+
initializeUpload,
|
|
149
|
+
purgeUpload,
|
|
150
|
+
startUpload
|
|
151
|
+
}),
|
|
152
|
+
[failUpload, initializeUpload, purgeUpload, startUpload]
|
|
153
|
+
);
|
|
143
154
|
useEffect(() => {
|
|
144
155
|
if (isFirstRenderRef.current) {
|
|
145
156
|
return;
|
|
@@ -173,18 +184,23 @@ const useFileUpload = (options) => {
|
|
|
173
184
|
multiTemporalState.publicState,
|
|
174
185
|
maxUpdateFrequency
|
|
175
186
|
]);
|
|
176
|
-
useEffect(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
useEffect(
|
|
188
|
+
() => () => {
|
|
189
|
+
for (const [, state] of multiTemporalStateRef.current.liveState) {
|
|
190
|
+
URL.revokeObjectURL(state.previewUrl);
|
|
191
|
+
}
|
|
192
|
+
for (const [, state] of multiTemporalStateRef.current.publicState) {
|
|
193
|
+
URL.revokeObjectURL(state.previewUrl);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
[]
|
|
197
|
+
);
|
|
184
198
|
useEffect(() => {
|
|
185
199
|
isFirstRenderRef.current = false;
|
|
186
200
|
}, []);
|
|
187
201
|
return [multiTemporalState.publicState, operations];
|
|
188
202
|
};
|
|
189
|
-
export {
|
|
203
|
+
export {
|
|
204
|
+
useFileUpload
|
|
205
|
+
};
|
|
190
206
|
//# sourceMappingURL=useFileUpload.js.map
|
|
@@ -1 +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":";;;;;AA6Ba,MAAA,gBAAgB,CAC5B,YACkC;AAC5B,QAAA,qBAAqB,SAAS,sBAAsB;AAE1D,QAAM,mBAAmB;AAEnB,QAAA,mBAAmB,OAA2B,MAAS;AACvD,QAAA,mBAAmB,OAAO,IAAI;AAC9B,QAAA,gBAAgB,OAAO,CAAC;AAE9B,QAAM,CAAC,oBAAoB,YAAY,WAGrC,mBAAmB,QAAW,yBAAyB;AACnD,QAAA,wBAAwB,OAAO,kBAAkB;AAEvD,QAAM,kBAAkB,QAAQ,MAAM,IAAI,eAAe,GAAG,CAAE,CAAA;AAE9D,YAAU,MAAM;AACf,0BAAsB,UAAU;AAAA,EAAA,CAChC;AAEK,QAAA,cAAc,YAAyB,CAAS,UAAA;AAC5C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AACC,QAAA,aAAa,YAAwB,CAAS,UAAA;AAC1C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AACC,QAAA,mBAAmB,YACxB,CAAS,UAAA;AACF,UAAA,iCAAiB;AACjB,UAAA,mDAAmC;AAEzC,eAAW,m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CAAC;AACrE,UAAI,YAAY,oBAAoB;AAC/B,YAAA,iBAAiB,YAAY,QAAW;AAC3C,uBAAa,iBAAiB,OAAO;AAAA,QACtC;AACS,iBAAA;AAAA,UACR,MAAM;AAAA,QAAA,CACN;AAAA,MAAA,OACK;AACF,YAAA,iBAAiB,YAAY,QAAW;AAC3C;AAAA,QACD;AACiB,yBAAA,UAAU,OAAO,WAAW,MAAM;AACzC,mBAAA;AAAA,YACR,MAAM;AAAA,UAAA,CACN;AACD,2BAAiB,UAAU;AAAA,QAAA,GACzB,qBAAqB,SAAS;AAAA,MAClC;AAAA,IACD;AAAA,EAAA,GACE;AAAA,IACF,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACA;AAED,YACC,MAAM,MAAM;AACX,eAAW,CAAA,EAAG,UAAU,sBAAsB,QAAQ,WAAW;AAC5D,UAAA,gBAAgB,MAAM,UAAU;AAAA,IACrC;AACA,eAAW,CAAA,EAAG,UAAU,sBAAsB,QAAQ,aAAa;AAC9D,UAAA,gBAAgB,MAAM,UAAU;AAAA,IACrC;AAAA,EACD,GACA,CACD,CAAA;AAGA,YAAU,MAAM;AACf,qBAAiB,UAAU;AAAA,EAC5B,GAAG,CAAE,CAAA;AAEE,SAAA,CAAC,mBAAmB,aAAa,UAAU;AACnD;;"}
|
|
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":["options"],"mappings":";;;;;AA6Ba,MAAA,gBAAgB,CAC5B,YACkC;AAC5B,QAAA,qBAAqB,SAAS,sBAAsB;AAE1D,QAAM,mBAAmB;AAEnB,QAAA,mBAAmB,OAA2B,MAAS;AACvD,QAAA,mBAAmB,OAAO,IAAI;AAC9B,QAAA,gBAAgB,OAAO,CAAC;AAE9B,QAAM,CAAC,oBAAoB,QAAQ,IAAI,WAGrC,mBAAmB,QAAW,yBAAyB;AACnD,QAAA,wBAAwB,OAAO,kBAAkB;AAEvD,QAAM,kBAAkB,QAAQ,MAAM,IAAI,eAAe,GAAG,CAAE,CAAA;AAE9D,YAAU,MAAM;AACf,0BAAsB,UAAU;AAAA,EAAA,CAChC;AAEK,QAAA,cAAc,YAAyB,CAAS,UAAA;AAC5C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AACC,QAAA,aAAa,YAAwB,CAAS,UAAA;AAC1C,aAAA;AAAA,MACR,MAAM;AAAA,MACN;AAAA,IAAA,CACA;AAAA,EACF,GAAG,CAAE,CAAA;AACL,QAAM,mBAAmB;AAAA,IACxB,CAAS,UAAA;AACF,YAAA,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,QAAI,iBAAiB,SAAS;AAC7B;AAAA,IACD;AACA,QAAI,mBAAmB,kBAAkB;AAClC,YAAA,MAAM,KAAK;AACjB,YAAM,YAAY,KAAK,IAAI,MAAM,mBAAmB,gBAAgB,CAAC;AACrE,UAAI,YAAY,oBAAoB;AAC/B,YAAA,iBAAiB,YAAY,QAAW;AAC3C,uBAAa,iBAAiB,OAAO;AAAA,QACtC;AACS,iBAAA;AAAA,UACR,MAAM;AAAA,QAAA,CACN;AAAA,MAAA,OACK;AACF,YAAA,iBAAiB,YAAY,QAAW;AAC3C;AAAA,QACD;AACiB,yBAAA,UAAU,OAAO,WAAW,MAAM;AACzC,mBAAA;AAAA,YACR,MAAM;AAAA,UAAA,CACN;AACD,2BAAiB,UAAU;AAAA,QAAA,GACzB,qBAAqB,SAAS;AAAA,MAClC;AAAA,IACD;AAAA,EAAA,GACE;AAAA,IACF,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACA;AAED;AAAA,IACC,MAAM,MAAM;AACX,iBAAW,CAAA,EAAG,KAAK,KAAK,sBAAsB,QAAQ,WAAW;AAC5D,YAAA,gBAAgB,MAAM,UAAU;AAAA,MACrC;AACA,iBAAW,CAAA,EAAG,KAAK,KAAK,sBAAsB,QAAQ,aAAa;AAC9D,YAAA,gBAAgB,MAAM,UAAU;AAAA,MACrC;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EAAA;AAIF,YAAU,MAAM;AACf,qBAAiB,UAAU;AAAA,EAC5B,GAAG,CAAE,CAAA;AAEE,SAAA,CAAC,mBAAmB,aAAa,UAAU;AACnD;"}
|
|
@@ -7,5 +7,7 @@ const useGraphQlClient = (path) => {
|
|
|
7
7
|
const sessionToken = useSessionToken();
|
|
8
8
|
return useMemo(() => new GraphQlClient(`${apiBaseUrl}${path}`, sessionToken), [apiBaseUrl, path, sessionToken]);
|
|
9
9
|
};
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
useGraphQlClient
|
|
12
|
+
};
|
|
11
13
|
//# sourceMappingURL=useGraphQlClient.js.map
|
|
@@ -1 +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":";;;;AAKa,MAAA,mBAAmB,CAAC,SAAgC;AAChE,QAAM,aAAa;AACnB,QAAM,eAAe;AACrB,SAAO,QAAQ,MAAM,IAAI,cAAc,GAAG,aAAa,QAAQ,YAAY,GAAG,CAAC,YAAY,MAAM,YAAY,CAAC;AAC/G
|
|
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":";;;;AAKa,MAAA,mBAAmB,CAAC,SAAgC;AAChE,QAAM,aAAa;AACnB,QAAM,eAAe;AACrB,SAAO,QAAQ,MAAM,IAAI,cAAc,GAAG,aAAa,QAAQ,YAAY,GAAG,CAAC,YAAY,MAAM,YAAY,CAAC;AAC/G;"}
|
|
@@ -1 +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":"AAAO,
|
|
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":"AAAO,SAAS,YAAY,GAA8B;AACzD,QAAM,IAAI,MAAM;AACjB;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType, ReactElement } from 'react';
|
|
1
|
+
import { ComponentType, ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { RenderElement } from './ElementRenderer';
|
|
3
3
|
import type { RenderLeaf } from './LeafRenderer';
|
|
4
4
|
import type { ReferenceRenderer } from './ReferenceRenderer';
|
|
@@ -23,6 +23,7 @@ export declare type RichTextRendererProps<CustomElements extends RichTextElement
|
|
|
23
23
|
attributeNamePrefix?: string;
|
|
24
24
|
renderBlock?: ComponentType<{
|
|
25
25
|
block: unknown;
|
|
26
|
+
children?: ReactNode;
|
|
26
27
|
}>;
|
|
27
28
|
} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>);
|
|
28
29
|
export declare const RichTextRenderer: <CustomElements extends RichTextElement<never, never> = never, CustomLeaves extends RichTextLeaf = never>(props: RichTextRendererProps<CustomElements, CustomLeaves>) => ReactElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextRenderer.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,YAAY,
|
|
1
|
+
{"version":3,"file":"RichTextRenderer.d.ts","sourceRoot":"","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,YAAY,EAAE,SAAS,EAAW,MAAM,OAAO,CAAA;AAE5F,OAAO,KAAK,EAAE,a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