-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
ckboxconfig.ts
372 lines (325 loc) · 8.31 KB
/
ckboxconfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module ckbox/ckboxconfig
*/
import type { TokenUrl } from '@ckeditor/ckeditor5-cloud-services';
import type { ArrayOrItem } from 'ckeditor5/src/utils.js';
/**
* The configuration of the {@link module:ckbox/ckbox~CKBox CKBox feature}.
*
* The minimal configuration for the CKBox feature requires providing the
* {@link module:ckbox/ckboxconfig~CKBoxConfig#tokenUrl `config.ckbox.tokenUrl`}:
*
* ```ts
* ClassicEditor
* .create( editorElement, {
* ckbox: {
* tokenUrl: 'https://example.com/cs-token-endpoint'
* }
* } )
* .then( ... )
* .catch( ... );
* ```
*
* Hovewer, you can also adjust the feature to fit your needs:
*
* ```ts
* ClassicEditor
* .create( editorElement, {
* ckbox: {
* defaultUploadCategories: {
* Bitmaps: [ 'bmp' ],
* Pictures: [ 'jpg', 'jpeg' ],
* Scans: [ 'png', 'tiff' ]
* },
* ignoreDataId: true,
* serviceOrigin: 'https://example.com/',
* tokenUrl: 'https://example.com/cs-token-endpoint'
* }
* } )
* .then( ... )
* .catch( ... );
* ```
*
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
*/
export interface CKBoxConfig {
/**
* The authentication token URL for CKBox feature.
*
* Defaults to {@link module:cloud-services/cloudservicesconfig~CloudServicesConfig#tokenUrl `config.cloudServices.tokenUrl`}
*/
tokenUrl?: TokenUrl;
/**
* The theme for CKBox dialog.
*/
theme?: string;
/**
* Defines the categories to which the uploaded images will be assigned.
* If configured, it overrides the category mappings defined on the cloud service.
* The value of this option should be an object, where the keys define categories and their values are the types of images
* that will be uploaded to these categories. The categories might be referenced by their name or ID.
*
* Example:
*
* ```ts
* const ckboxConfig = {
* defaultUploadCategories: {
* Bitmaps: [ 'bmp' ],
* Pictures: [ 'jpg', 'jpeg' ],
* Scans: [ 'png', 'tiff' ],
* // The category below is referenced by its ID.
* 'fdf2a647-b67f-4a6c-b692-5ba1dc1ed87b': [ 'gif' ]
* }
* };
* ```
*
* @default null
*/
defaultUploadCategories?: Record<string, Array<string>> | null;
/**
* Defines the workspace id to use during upload when the user has access to more than one workspace.
*
* If defined, it is an error, when the user has no access to the specified workspace.
*/
defaultUploadWorkspaceId?: string;
/**
* Enforces displaying the "Powered by CKBox" link regardless of the CKBox plan used.
*/
forceDemoLabel?: boolean;
/**
* Allows editing images that are not hosted in CKBox service.
*
* This configuration option should whitelist URL(s) of images that should be editable.
* Make sure that allowed image resources have CORS enabled.
*
* The image is editable if this option is:
* * a regular expression and it matches the image URL, or
* * a custom function that returns `true` for the image URL, or
* * `'origin'` literal and the image URL is from the same origin, or
* * an array of the above and the image URL matches one of the array elements.
*
* Images hosted in CKBox are always editable.
*
* @default []
*/
allowExternalImagesEditing?: ArrayOrItem<RegExp | 'origin' | ( ( src: string ) => boolean )>;
/**
* Inserts the unique asset ID as the `data-ckbox-resource-id` attribute. To disable this behavior, set it to `true`.
*
* @default false
*/
ignoreDataId?: boolean;
/**
* Configures the base URL of the API service. Required only in on-premises installations.
*
* @default 'https://api.ckbox.io'
*/
serviceOrigin?: string;
/**
* Configures the language for the CKBox dialog.
*
* Defaults to {@link module:utils/locale~Locale#uiLanguage `Locale#uiLanguage`}
*/
language?: string;
}
/**
* Asset definition.
*
* The definition contains the unique `id`, asset `type` and an `attributes` definition.
*/
export type CKBoxAssetDefinition = CKBoxAssetImageDefinition | CKBoxAssetLinkDefinition;
/**
* Image asset definition.
*
* The definition contains the unique `id`, asset `type` and an `attributes` definition.
*/
export interface CKBoxAssetImageDefinition {
/**
* An unique asset id.
*/
id: string;
/**
* Asset type.
*/
type: 'image';
/**
* Asset attributes.
*/
attributes: CKBoxAssetImageAttributesDefinition;
}
/**
* Link asset definition.
*
* The definition contains the unique `id`, asset `type` and an `attributes` definition.
*/
export interface CKBoxAssetLinkDefinition {
/**
* An unique asset id.
*/
id: string;
/**
* Asset type.
*/
type: 'link';
/**
* Asset attributes.
*/
attributes: CKBoxAssetLinkAttributesDefinition;
}
/**
* Asset attributes definition for an image.
*
* The definition contains the `imageFallbackUrl`, an `imageSources` array with one image source definition object and the
* `imageTextAlternative`.
*
* ```ts
* {
* imageFallbackUrl: 'https://example.com/assets/asset-id/images/1000.png',
* imageSources: [
* {
* sizes: '1000px',
* srcset:
* 'https://example.com/assets/asset-id/images/100.webp 100w,' +
* 'https://example.com/assets/asset-id/images/200.webp 200w,' +
* 'https://example.com/assets/asset-id/images/300.webp 300w,' +
* 'https://example.com/assets/asset-id/images/400.webp 400w,' +
* 'https://example.com/assets/asset-id/images/500.webp 500w,' +
* 'https://example.com/assets/asset-id/images/600.webp 600w,' +
* 'https://example.com/assets/asset-id/images/700.webp 700w,' +
* 'https://example.com/assets/asset-id/images/800.webp 800w,' +
* 'https://example.com/assets/asset-id/images/900.webp 900w,' +
* 'https://example.com/assets/asset-id/images/1000.webp 1000w',
* type: 'image/webp'
* }
* ],
* imageTextAlternative: 'An alternative text for the image'
* }
* ```
*/
export interface CKBoxAssetImageAttributesDefinition {
/**
* A fallback URL for browsers that do not support the "webp" format.
*/
imageFallbackUrl: string;
/**
* An array containing one image source definition object.
*/
imageSources: Array<{
srcset: string;
sizes: string;
type: string;
}>;
/**
* An alternative text for an image.
*/
imageTextAlternative: string;
/**
* Image width.
*/
imageWidth?: number;
/**
* Image height.
*/
imageHeight?: number;
/**
* Image placeholder image.
*/
imagePlaceholder?: string;
}
/**
* Asset attributes definition for a link.
*
* The definition contains the `linkName` and `linkHref` strings.
*
* ```ts
* {
* linkName: 'File name',
* linkHref: 'https://example.com/assets/asset-id/file.pdf'
* }
* ```
*/
export interface CKBoxAssetLinkAttributesDefinition {
/**
* A link name.
*/
linkName: string;
/**
* An URL for the asset.
*/
linkHref: string;
}
/**
* The source set of the responsive image provided by the CKBox backend.
*
* Each numeric key corresponds to display width of the image.
*/
export interface CKBoxImageUrls {
[ width: number ]: string;
/**
* A fallback URL for browsers that do not support the "webp" format.
*/
default: string;
}
/**
* Raw asset definition that is received from the CKBox feature.
*/
export interface CKBoxRawAssetDefinition {
/**
* A raw asset data definition.
*/
data: CKBoxRawAssetDataDefinition;
}
/**
* Part of raw asset data that is received from the CKBox feature.
*/
export interface CKBoxRawAssetDataDefinition {
/**
* An unique asset id.
*/
id: string;
/**
* An asset name.
*/
name: string;
/**
* A raw asset metadata definition.
*/
metadata?: CKBoxRawAssetMetadataDefinition;
/**
* The source set of the responsive image.
*/
imageUrls?: CKBoxImageUrls;
/**
* The asset location.
*/
url: string;
}
/**
* Part of raw asset data that is received from the CKBox feature. Properties are set only if the chosen asset is an image.
*/
export interface CKBoxRawAssetMetadataDefinition {
/**
* Image description.
*/
description?: string;
/**
* Image width.
*/
width?: number;
/**
* Image height.
*/
height?: number;
/**
* The blurhash placeholder value.
*/
blurHash?: string;
/**
* The processing status of the asset.
*/
metadataProcessingStatus?: string;
}