@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.
Files changed (109) hide show
  1. package/build/ckbox.js +2 -2
  2. package/build/translations/ar.js +1 -1
  3. package/build/translations/az.js +1 -1
  4. package/build/translations/bg.js +1 -1
  5. package/build/translations/bn.js +1 -1
  6. package/build/translations/ca.js +1 -1
  7. package/build/translations/cs.js +1 -1
  8. package/build/translations/da.js +1 -1
  9. package/build/translations/de.js +1 -1
  10. package/build/translations/el.js +1 -1
  11. package/build/translations/en-au.js +1 -1
  12. package/build/translations/es-co.js +1 -1
  13. package/build/translations/es.js +1 -1
  14. package/build/translations/et.js +1 -1
  15. package/build/translations/fa.js +1 -1
  16. package/build/translations/fi.js +1 -1
  17. package/build/translations/fr.js +1 -1
  18. package/build/translations/gl.js +1 -1
  19. package/build/translations/he.js +1 -1
  20. package/build/translations/hi.js +1 -1
  21. package/build/translations/hr.js +1 -1
  22. package/build/translations/hu.js +1 -1
  23. package/build/translations/id.js +1 -1
  24. package/build/translations/it.js +1 -1
  25. package/build/translations/ja.js +1 -1
  26. package/build/translations/ko.js +1 -1
  27. package/build/translations/lt.js +1 -1
  28. package/build/translations/lv.js +1 -1
  29. package/build/translations/ms.js +1 -1
  30. package/build/translations/nl.js +1 -1
  31. package/build/translations/no.js +1 -1
  32. package/build/translations/pl.js +1 -1
  33. package/build/translations/pt-br.js +1 -1
  34. package/build/translations/pt.js +1 -1
  35. package/build/translations/ro.js +1 -1
  36. package/build/translations/ru.js +1 -1
  37. package/build/translations/sk.js +1 -1
  38. package/build/translations/sq.js +1 -0
  39. package/build/translations/sr-latn.js +1 -1
  40. package/build/translations/sr.js +1 -1
  41. package/build/translations/sv.js +1 -1
  42. package/build/translations/th.js +1 -1
  43. package/build/translations/tr.js +1 -1
  44. package/build/translations/ug.js +1 -1
  45. package/build/translations/uk.js +1 -1
  46. package/build/translations/ur.js +1 -1
  47. package/build/translations/uz.js +1 -1
  48. package/build/translations/vi.js +1 -1
  49. package/build/translations/zh-cn.js +1 -1
  50. package/build/translations/zh.js +1 -1
  51. package/lang/contexts.json +2 -1
  52. package/lang/translations/ar.po +4 -0
  53. package/lang/translations/az.po +4 -0
  54. package/lang/translations/bg.po +4 -0
  55. package/lang/translations/bn.po +4 -0
  56. package/lang/translations/ca.po +4 -0
  57. package/lang/translations/cs.po +4 -0
  58. package/lang/translations/da.po +4 -0
  59. package/lang/translations/de.po +4 -0
  60. package/lang/translations/el.po +4 -0
  61. package/lang/translations/en-au.po +4 -0
  62. package/lang/translations/en.po +4 -0
  63. package/lang/translations/es-co.po +4 -0
  64. package/lang/translations/es.po +4 -0
  65. package/lang/translations/et.po +4 -0
  66. package/lang/translations/fa.po +4 -0
  67. package/lang/translations/fi.po +4 -0
  68. package/lang/translations/fr.po +4 -0
  69. package/lang/translations/gl.po +4 -0
  70. package/lang/translations/he.po +4 -0
  71. package/lang/translations/hi.po +4 -0
  72. package/lang/translations/hr.po +4 -0
  73. package/lang/translations/hu.po +4 -0
  74. package/lang/translations/id.po +4 -0
  75. package/lang/translations/it.po +4 -0
  76. package/lang/translations/ja.po +4 -0
  77. package/lang/translations/ko.po +4 -0
  78. package/lang/translations/lt.po +4 -0
  79. package/lang/translations/lv.po +4 -0
  80. package/lang/translations/ms.po +4 -0
  81. package/lang/translations/nl.po +4 -0
  82. package/lang/translations/no.po +4 -0
  83. package/lang/translations/pl.po +4 -0
  84. package/lang/translations/pt-br.po +4 -0
  85. package/lang/translations/pt.po +4 -0
  86. package/lang/translations/ro.po +4 -0
  87. package/lang/translations/ru.po +4 -0
  88. package/lang/translations/sk.po +4 -0
  89. package/lang/translations/sq.po +29 -0
  90. package/lang/translations/sr-latn.po +4 -0
  91. package/lang/translations/sr.po +4 -0
  92. package/lang/translations/sv.po +4 -0
  93. package/lang/translations/th.po +4 -0
  94. package/lang/translations/tr.po +4 -0
  95. package/lang/translations/ug.po +4 -0
  96. package/lang/translations/uk.po +4 -0
  97. package/lang/translations/ur.po +4 -0
  98. package/lang/translations/uz.po +4 -0
  99. package/lang/translations/vi.po +4 -0
  100. package/lang/translations/zh-cn.po +4 -0
  101. package/lang/translations/zh.po +4 -0
  102. package/package.json +2 -2
  103. package/src/ckboxcommand.d.ts +0 -1
  104. package/src/ckboxcommand.js +10 -23
  105. package/src/ckboxconfig.d.ts +26 -15
  106. package/src/ckboxediting.js +0 -1
  107. package/src/ckboxuploadadapter.js +24 -26
  108. package/src/utils.d.ts +7 -10
  109. 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
- * Creates URLs for the image:
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({ token, id, origin, width, extension }) {
14
- const environmentId = getEnvironmentId(token);
15
- const imageBreakpoints = getImageBreakpoints(width);
16
- const imageFallbackExtension = getImageFallbackExtension(extension);
17
- const imageFallbackUrl = getResponsiveImageUrl({ environmentId, id, origin, width, extension: imageFallbackExtension });
18
- const imageResponsiveUrls = imageBreakpoints.map(imageBreakpoint => {
19
- const responsiveImageUrl = getResponsiveImageUrl({ environmentId, id, origin, width: imageBreakpoint, extension: 'webp' });
20
- return `${responsiveImageUrl} ${imageBreakpoint}w`;
21
- });
22
- // Create just one image source definition containing all calculated URLs for each image breakpoint. Additionally, limit this source
23
- // image width by defining two allowed slot sizes:
24
- // - If the viewport width is not greater than the image width, make the image occupy the whole slot.
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: imageResponsiveUrls.join(','),
31
- sizes: `(max-width: ${width}px) 100vw, ${width}px`,
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 an environment id from a token used for communication with the CKBox service.
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 getEnvironmentId(token) {
37
+ export function getWorkspaceId(token, defaultWorkspaceId) {
43
38
  const [, binaryTokenPayload] = token.value.split('.');
44
39
  const payload = JSON.parse(atob(binaryTokenPayload));
45
- return payload.aud;
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
- return imageBreakpoints;
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 extension;
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
  }