@ckeditor/ckeditor5-ckbox 0.0.0-nightly-20230726.0 → 0.0.0-nightly-20230728.0
Sign up to get free protection for your applications and to get access to all the features.
- package/build/ckbox.js +2 -2
- package/build/translations/ar.js +1 -1
- package/build/translations/az.js +1 -1
- package/build/translations/bg.js +1 -1
- package/build/translations/bn.js +1 -1
- package/build/translations/ca.js +1 -1
- package/build/translations/cs.js +1 -1
- package/build/translations/da.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/el.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/es-co.js +1 -1
- package/build/translations/es.js +1 -1
- package/build/translations/et.js +1 -1
- package/build/translations/fa.js +1 -1
- package/build/translations/fi.js +1 -1
- package/build/translations/fr.js +1 -1
- package/build/translations/gl.js +1 -1
- package/build/translations/he.js +1 -1
- package/build/translations/hi.js +1 -1
- package/build/translations/hr.js +1 -1
- package/build/translations/hu.js +1 -1
- package/build/translations/id.js +1 -1
- package/build/translations/it.js +1 -1
- package/build/translations/ja.js +1 -1
- package/build/translations/ko.js +1 -1
- package/build/translations/lt.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/ms.js +1 -1
- package/build/translations/nl.js +1 -1
- package/build/translations/no.js +1 -1
- package/build/translations/pl.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/pt.js +1 -1
- package/build/translations/ro.js +1 -1
- package/build/translations/ru.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/sq.js +1 -0
- package/build/translations/sr-latn.js +1 -1
- package/build/translations/sr.js +1 -1
- package/build/translations/sv.js +1 -1
- package/build/translations/th.js +1 -1
- package/build/translations/tr.js +1 -1
- package/build/translations/ug.js +1 -1
- package/build/translations/uk.js +1 -1
- package/build/translations/ur.js +1 -1
- package/build/translations/uz.js +1 -1
- package/build/translations/vi.js +1 -1
- package/build/translations/zh-cn.js +1 -1
- package/build/translations/zh.js +1 -1
- package/lang/contexts.json +2 -1
- package/lang/translations/ar.po +4 -0
- package/lang/translations/az.po +4 -0
- package/lang/translations/bg.po +4 -0
- package/lang/translations/bn.po +4 -0
- package/lang/translations/ca.po +4 -0
- package/lang/translations/cs.po +4 -0
- package/lang/translations/da.po +4 -0
- package/lang/translations/de.po +4 -0
- package/lang/translations/el.po +4 -0
- package/lang/translations/en-au.po +4 -0
- package/lang/translations/en.po +4 -0
- package/lang/translations/es-co.po +4 -0
- package/lang/translations/es.po +4 -0
- package/lang/translations/et.po +4 -0
- package/lang/translations/fa.po +4 -0
- package/lang/translations/fi.po +4 -0
- package/lang/translations/fr.po +4 -0
- package/lang/translations/gl.po +4 -0
- package/lang/translations/he.po +4 -0
- package/lang/translations/hi.po +4 -0
- package/lang/translations/hr.po +4 -0
- package/lang/translations/hu.po +4 -0
- package/lang/translations/id.po +4 -0
- package/lang/translations/it.po +4 -0
- package/lang/translations/ja.po +4 -0
- package/lang/translations/ko.po +4 -0
- package/lang/translations/lt.po +4 -0
- package/lang/translations/lv.po +4 -0
- package/lang/translations/ms.po +4 -0
- package/lang/translations/nl.po +4 -0
- package/lang/translations/no.po +4 -0
- package/lang/translations/pl.po +4 -0
- package/lang/translations/pt-br.po +4 -0
- package/lang/translations/pt.po +4 -0
- package/lang/translations/ro.po +4 -0
- package/lang/translations/ru.po +4 -0
- package/lang/translations/sk.po +4 -0
- package/lang/translations/sq.po +29 -0
- package/lang/translations/sr-latn.po +4 -0
- package/lang/translations/sr.po +4 -0
- package/lang/translations/sv.po +4 -0
- package/lang/translations/th.po +4 -0
- package/lang/translations/tr.po +4 -0
- package/lang/translations/ug.po +4 -0
- package/lang/translations/uk.po +4 -0
- package/lang/translations/ur.po +4 -0
- package/lang/translations/uz.po +4 -0
- package/lang/translations/vi.po +4 -0
- package/lang/translations/zh-cn.po +4 -0
- package/lang/translations/zh.po +4 -0
- package/package.json +2 -2
- package/src/ckboxcommand.d.ts +0 -1
- package/src/ckboxcommand.js +10 -23
- package/src/ckboxconfig.d.ts +26 -15
- package/src/ckboxediting.js +0 -1
- package/src/ckboxuploadadapter.js +24 -26
- package/src/utils.d.ts +7 -10
- package/src/utils.js +27 -68
package/src/utils.js
CHANGED
@@ -2,89 +2,48 @@
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
|
-
const IMAGE_BREAKPOINT_MAX_WIDTH = 4000;
|
6
|
-
const IMAGE_BREAKPOINT_PIXELS_THRESHOLD = 80;
|
7
|
-
const IMAGE_BREAKPOINT_PERCENTAGE_THRESHOLD = 10;
|
8
5
|
/**
|
9
|
-
*
|
6
|
+
* Converts image source set provided by the CKBox into an object containing:
|
10
7
|
* - responsive URLs for the "webp" image format,
|
11
8
|
* - one fallback URL for browsers that do not support the "webp" format.
|
12
9
|
*/
|
13
|
-
export function getImageUrls(
|
14
|
-
const
|
15
|
-
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
// - Otherwise, limit the slot width to be equal to the image width, to avoid enlarging the image beyond its width.
|
26
|
-
//
|
27
|
-
// This is a kind of a workaround. In a perfect world we could use `sizes="100vw" width="real image width"` on our single `<source>`
|
28
|
-
// element, but at the time of writing this code the `width` attribute is not supported in the `<source>` element in Firefox yet.
|
10
|
+
export function getImageUrls(imageUrls) {
|
11
|
+
const responsiveUrls = [];
|
12
|
+
let maxWidth = 0;
|
13
|
+
for (const key in imageUrls) {
|
14
|
+
const width = parseInt(key, 10);
|
15
|
+
if (!isNaN(width)) {
|
16
|
+
if (width > maxWidth) {
|
17
|
+
maxWidth = width;
|
18
|
+
}
|
19
|
+
responsiveUrls.push(`${imageUrls[key]} ${key}w`);
|
20
|
+
}
|
21
|
+
}
|
29
22
|
const imageSources = [{
|
30
|
-
srcset:
|
31
|
-
sizes: `(max-width: ${
|
23
|
+
srcset: responsiveUrls.join(','),
|
24
|
+
sizes: `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`,
|
32
25
|
type: 'image/webp'
|
33
26
|
}];
|
34
27
|
return {
|
35
|
-
imageFallbackUrl,
|
28
|
+
imageFallbackUrl: imageUrls.default,
|
36
29
|
imageSources
|
37
30
|
};
|
38
31
|
}
|
39
32
|
/**
|
40
|
-
* Returns
|
33
|
+
* Returns workspace id to use for communication with the CKBox service.
|
34
|
+
*
|
35
|
+
* @param defaultWorkspaceId The default workspace to use taken from editor config.
|
41
36
|
*/
|
42
|
-
export function
|
37
|
+
export function getWorkspaceId(token, defaultWorkspaceId) {
|
43
38
|
const [, binaryTokenPayload] = token.value.split('.');
|
44
39
|
const payload = JSON.parse(atob(binaryTokenPayload));
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
* Calculates the image breakpoints for the provided image width in the following way:
|
49
|
-
*
|
50
|
-
* 1) The breakpoint threshold (the breakpoint step in the calculations) should be equal to 10% of the image width, but not less than 80
|
51
|
-
* pixels.
|
52
|
-
*
|
53
|
-
* 2) Set the max. allowed image breakpoint (4000px) or the image width (if it is smaller than 4000px) as the first calculated breakpoint.
|
54
|
-
*
|
55
|
-
* 3) From the last computed image breakpoint subtract the computed breakpoint threshold, as long as the calculated new breakpoint value is
|
56
|
-
* greater than the threshold.
|
57
|
-
*/
|
58
|
-
function getImageBreakpoints(width) {
|
59
|
-
// Step 1) - calculating the breakpoint threshold.
|
60
|
-
const imageBreakpointThresholds = [
|
61
|
-
width * IMAGE_BREAKPOINT_PERCENTAGE_THRESHOLD / 100,
|
62
|
-
IMAGE_BREAKPOINT_PIXELS_THRESHOLD
|
63
|
-
];
|
64
|
-
const imageBreakpointThreshold = Math.floor(Math.max(...imageBreakpointThresholds));
|
65
|
-
// Step 2) - set the first breakpoint.
|
66
|
-
const imageBreakpoints = [Math.min(width, IMAGE_BREAKPOINT_MAX_WIDTH)];
|
67
|
-
// Step 3) - calculate the next breakpoint as long as it is greater than the breakpoint threshold.
|
68
|
-
let lastBreakpoint = imageBreakpoints[0];
|
69
|
-
while (lastBreakpoint - imageBreakpointThreshold >= imageBreakpointThreshold) {
|
70
|
-
lastBreakpoint -= imageBreakpointThreshold;
|
71
|
-
imageBreakpoints.unshift(lastBreakpoint);
|
40
|
+
const workspaces = (payload.auth && payload.auth.ckbox && payload.auth.ckbox.workspaces) || [payload.aud];
|
41
|
+
if (!defaultWorkspaceId) {
|
42
|
+
return workspaces[0];
|
72
43
|
}
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
* Returns the image extension for the fallback URL.
|
77
|
-
*/
|
78
|
-
function getImageFallbackExtension(extension) {
|
79
|
-
if (extension === 'bmp' || extension === 'tiff' || extension === 'jpg') {
|
80
|
-
return 'jpeg';
|
44
|
+
const role = payload.auth && payload.auth.ckbox && payload.auth.ckbox.role;
|
45
|
+
if (role == 'superadmin' || workspaces.includes(defaultWorkspaceId)) {
|
46
|
+
return defaultWorkspaceId;
|
81
47
|
}
|
82
|
-
return
|
83
|
-
}
|
84
|
-
/**
|
85
|
-
* Creates the URL for the given image.
|
86
|
-
*/
|
87
|
-
function getResponsiveImageUrl({ environmentId, id, origin, width, extension }) {
|
88
|
-
const endpoint = `${environmentId}/assets/${id}/images/${width}.${extension}`;
|
89
|
-
return new URL(endpoint, origin).toString();
|
48
|
+
return null;
|
90
49
|
}
|