@orangelogic/orange-dam-content-browser-sdk 2.1.54 → 2.1.55

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.
Files changed (281) hide show
  1. package/build/ApiService.d.ts +15 -0
  2. package/build/App.d.ts +62 -0
  3. package/build/AppContext.d.ts +18 -0
  4. package/build/GlobalConfigContext.d.ts +32 -0
  5. package/build/OrangeDAMContentBrowserSDK.min.css +2 -0
  6. package/build/OrangeDAMContentBrowserSDK.min.css.map +1 -0
  7. package/build/OrangeDAMContentBrowserSDK.min.js +11468 -0
  8. package/build/OrangeDAMContentBrowserSDK.min.js.map +1 -0
  9. package/build/asset-manifest.json +13 -0
  10. package/build/components/ArrayClamp/ArrayClamp.d.ts +10 -0
  11. package/build/components/ArrayClamp/ArrayClamp.styled.d.ts +1 -0
  12. package/build/components/ArrayClamp/index.d.ts +1 -0
  13. package/build/components/Browser/Browser.constants.d.ts +3 -0
  14. package/build/components/Browser/Browser.d.ts +21 -0
  15. package/build/components/Browser/Browser.styled.d.ts +2 -0
  16. package/build/components/Browser/BrowserItem.d.ts +13 -0
  17. package/build/components/Browser/LoadMoreButton.d.ts +9 -0
  18. package/build/components/ControlBar/ControlBar.constants.d.ts +10 -0
  19. package/build/components/ControlBar/ControlBar.d.ts +23 -0
  20. package/build/components/ControlBar/ControlBar.styled.d.ts +1 -0
  21. package/build/components/ControlBar/Facet/Facet.d.ts +14 -0
  22. package/build/components/ControlBar/Facet/index.d.ts +1 -0
  23. package/build/components/FormatDialog/CropPreviewer/CropPreviewer.d.ts +41 -0
  24. package/{src/components/FormatDialog/CropPreviewer/index.ts → build/components/FormatDialog/CropPreviewer/index.d.ts} +1 -1
  25. package/build/components/FormatDialog/CustomRendition/CustomRendition.constants.d.ts +5 -0
  26. package/build/components/FormatDialog/CustomRendition/CustomRendition.d.ts +56 -0
  27. package/build/components/FormatDialog/CustomRendition/CustomRendition.styled.d.ts +1 -0
  28. package/build/components/FormatDialog/CustomRendition/index.d.ts +1 -0
  29. package/build/components/FormatDialog/CustomRendition/transformations/Crop.d.ts +26 -0
  30. package/build/components/FormatDialog/CustomRendition/transformations/Extension.d.ts +11 -0
  31. package/build/components/FormatDialog/CustomRendition/transformations/Format.d.ts +10 -0
  32. package/build/components/FormatDialog/CustomRendition/transformations/Metadata.d.ts +7 -0
  33. package/build/components/FormatDialog/CustomRendition/transformations/Quality.d.ts +7 -0
  34. package/build/components/FormatDialog/CustomRendition/transformations/Resize.d.ts +18 -0
  35. package/build/components/FormatDialog/CustomRendition/transformations/Rotate.d.ts +8 -0
  36. package/{src/components/FormatDialog/CustomRendition/transformations/index.ts → build/components/FormatDialog/CustomRendition/transformations/index.d.ts} +3 -1
  37. package/build/components/FormatDialog/FormatDialog.d.ts +49 -0
  38. package/build/components/FormatDialog/FormatDialog.styled.d.ts +3 -0
  39. package/build/components/FormatDialog/Previewer/Previewer.d.ts +17 -0
  40. package/build/components/FormatDialog/Previewer/Previewer.styled.d.ts +1 -0
  41. package/build/components/FormatDialog/Previewer/index.d.ts +1 -0
  42. package/build/components/FormatDialog/ProxyMenu/ProxyMenu.d.ts +20 -0
  43. package/build/components/FormatDialog/ProxyMenu/ProxyMenu.styled.d.ts +2 -0
  44. package/build/components/FormatDialog/ProxyMenu/index.d.ts +1 -0
  45. package/build/components/FormatDialog/TrackingParameters/TrackingParameters.d.ts +13 -0
  46. package/build/components/FormatDialog/TrackingParameters/index.d.ts +1 -0
  47. package/build/components/FormatDialog/VersionHistory/VersionHistory.d.ts +6 -0
  48. package/build/components/FormatDialog/VersionHistory/VersionHistory.styled.d.ts +1 -0
  49. package/build/components/FormatDialog/VersionHistory/index.d.ts +1 -0
  50. package/build/components/FormatDialog/index.d.ts +1 -0
  51. package/build/components/Header/Header.d.ts +15 -0
  52. package/build/components/Header/Header.styled.d.ts +5 -0
  53. package/build/components/Loader/Loader.d.ts +7 -0
  54. package/build/components/Loader/index.d.ts +1 -0
  55. package/build/components/NoResult/NoResult.d.ts +7 -0
  56. package/build/components/NoResult/index.d.ts +1 -0
  57. package/build/components/Result/AssetCard/AssetCard.d.ts +15 -0
  58. package/build/components/Result/AssetCard/AssetCard.styled.d.ts +2 -0
  59. package/build/components/Result/AssetCard/AssetCardWrapper.d.ts +18 -0
  60. package/build/components/Result/AssetCard/AssetCardWrapper.styled.d.ts +1 -0
  61. package/build/components/Result/AssetCard/index.d.ts +1 -0
  62. package/build/components/Result/AssetPreview/AssetPreview.d.ts +11 -0
  63. package/build/components/Result/AssetPreview/AssetPreview.styled.d.ts +1 -0
  64. package/build/components/Result/AssetPreview/ImagePreview/ImagePreview.d.ts +11 -0
  65. package/build/components/Result/AssetPreview/ImagePreview/index.d.ts +1 -0
  66. package/build/components/Result/AssetPreview/OtherPreview/OtherPreview.d.ts +9 -0
  67. package/build/components/Result/AssetPreview/OtherPreview/OtherPreview.styled.d.ts +1 -0
  68. package/build/components/Result/AssetPreview/OtherPreview/index.d.ts +1 -0
  69. package/build/components/Result/AssetPreview/VideoPreview/VideoPreview.d.ts +11 -0
  70. package/build/components/Result/AssetPreview/VideoPreview/index.d.ts +1 -0
  71. package/build/components/Result/AssetPreview/index.d.ts +1 -0
  72. package/build/consts/asset.d.ts +14 -0
  73. package/build/consts/auth.d.ts +4 -0
  74. package/build/consts/data.d.ts +21 -0
  75. package/build/index.d.ts +225 -0
  76. package/build/index.html +1 -0
  77. package/build/page/Authenticate/Authenticate.d.ts +2 -0
  78. package/build/page/Authenticate/ConnectingBackground.d.ts +8 -0
  79. package/build/page/Authenticate/index.d.ts +2 -0
  80. package/build/page/Home/Home.d.ts +6 -0
  81. package/build/page/Home/Home.styled.d.ts +2 -0
  82. package/build/setupTests.d.ts +1 -0
  83. package/build/store/assets/assets.api.d.ts +66 -0
  84. package/build/store/assets/assets.service.d.ts +23 -0
  85. package/build/store/assets/assets.slice.d.ts +65 -0
  86. package/build/store/auth/auth.service.d.ts +10 -0
  87. package/build/store/auth/auth.slice.d.ts +76 -0
  88. package/build/store/index.d.ts +368 -0
  89. package/build/store/search/search.api.d.ts +39 -0
  90. package/build/store/search/search.slice.d.ts +12 -0
  91. package/build/store/user/user.api.d.ts +5 -0
  92. package/build/types/assets.d.ts +68 -0
  93. package/build/types/auth.d.ts +35 -0
  94. package/build/types/common.d.ts +11 -0
  95. package/build/types/download.d.ts +8 -0
  96. package/build/types/navigation.d.ts +3 -0
  97. package/build/types/search.d.ts +148 -0
  98. package/{src/types/storage.ts → build/types/storage.d.ts} +1 -1
  99. package/build/types/user.d.ts +7 -0
  100. package/build/utils/api.d.ts +27 -0
  101. package/build/utils/array.d.ts +13 -0
  102. package/build/utils/constants.d.ts +11 -0
  103. package/build/utils/function.d.ts +1 -0
  104. package/build/utils/getRequestUrl.d.ts +1 -0
  105. package/build/utils/hooks.d.ts +1 -0
  106. package/build/utils/icon.d.ts +3 -0
  107. package/build/utils/image.d.ts +24 -0
  108. package/build/utils/number.d.ts +4 -0
  109. package/build/utils/rotate.d.ts +4 -0
  110. package/build/utils/storage.d.ts +23 -0
  111. package/build/utils/string.d.ts +12 -0
  112. package/build/view/AssetsPicker.d.ts +6 -0
  113. package/package.json +49 -8
  114. package/.env +0 -1
  115. package/.eslintignore +0 -2
  116. package/.eslintrc.json +0 -82
  117. package/.releaserc +0 -17
  118. package/.travis.yml +0 -20
  119. package/CBSDKdemo.html +0 -315
  120. package/GitVersion.yml +0 -18
  121. package/azure-pipeline.yaml +0 -93
  122. package/clientlib.config.js +0 -36
  123. package/config/env.js +0 -105
  124. package/config/getHttpsConfig.js +0 -67
  125. package/config/jest/babelTransform.js +0 -30
  126. package/config/jest/cssTransform.js +0 -14
  127. package/config/jest/fileTransform.js +0 -41
  128. package/config/modules.js +0 -135
  129. package/config/paths.js +0 -79
  130. package/config/webpack/persistentCache/createEnvironmentHash.js +0 -10
  131. package/config/webpack.config.js +0 -762
  132. package/config/webpackDevServer.config.js +0 -128
  133. package/config-overrides.js +0 -8
  134. package/gab_extension/GAB.html +0 -85
  135. package/gab_extension/GoogleChrome/manifest.json +0 -28
  136. package/gab_extension/GoogleChrome/src/assets/icon48.png +0 -0
  137. package/gab_extension/GoogleChrome/src/background/index.js +0 -6
  138. package/gab_extension/GoogleChrome/src/scripts/index.js +0 -347
  139. package/gab_extension/MozillaFirefox/manifest.json +0 -20
  140. package/gab_extension/MozillaFirefox/src/assets/icon.png +0 -0
  141. package/gab_extension/MozillaFirefox/src/background/index.js +0 -5
  142. package/gab_extension/MozillaFirefox/src/scripts/index.js +0 -347
  143. package/gab_extension/README.md +0 -11
  144. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.pbxproj +0 -927
  145. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  146. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  147. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/project.xcworkspace/xcuserdata/oldevmac01.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  148. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Orange DAM Asset Browser Extension.xcodeproj/xcuserdata/oldevmac01.xcuserdatad/xcschemes/xcschememanagement.plist +0 -19
  149. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json +0 -11
  150. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -63
  151. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/Contents.json +0 -6
  152. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json +0 -20
  153. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Base.lproj/Main.html +0 -23
  154. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Resources/Icon.png +0 -0
  155. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Resources/Script.js +0 -24
  156. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/Resources/Style.css +0 -61
  157. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (App)/ViewController.swift +0 -81
  158. package/gab_extension/Safari/Orange DAM Asset Browser Extension/Shared (Extension)/SafariWebExtensionHandler.swift +0 -26
  159. package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/AppDelegate.swift +0 -24
  160. package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/Base.lproj/LaunchScreen.storyboard +0 -36
  161. package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/Base.lproj/Main.storyboard +0 -38
  162. package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/Info.plist +0 -27
  163. package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (App)/SceneDelegate.swift +0 -18
  164. package/gab_extension/Safari/Orange DAM Asset Browser Extension/iOS (Extension)/Info.plist +0 -13
  165. package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/AppDelegate.swift +0 -21
  166. package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/Base.lproj/Main.storyboard +0 -125
  167. package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/Info.plist +0 -8
  168. package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (App)/Orange DAM Asset Browser Extension.entitlements +0 -12
  169. package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (Extension)/Info.plist +0 -13
  170. package/gab_extension/Safari/Orange DAM Asset Browser Extension/macOS (Extension)/Orange DAM Asset Browser Extension.entitlements +0 -10
  171. package/public/index.html +0 -92
  172. package/scripts/build.js +0 -218
  173. package/scripts/start.js +0 -154
  174. package/scripts/test.js +0 -53
  175. package/src/App.tsx +0 -98
  176. package/src/AppContext.ts +0 -18
  177. package/src/GlobalConfigContext.ts +0 -46
  178. package/src/components/ArrayClamp/ArrayClamp.styled.ts +0 -42
  179. package/src/components/ArrayClamp/ArrayClamp.tsx +0 -167
  180. package/src/components/ArrayClamp/index.ts +0 -1
  181. package/src/components/Browser/Browser.styled.ts +0 -82
  182. package/src/components/Browser/Browser.tsx +0 -284
  183. package/src/components/Browser/BrowserItem.tsx +0 -98
  184. package/src/components/ControlBar/ControlBar.constants.tsx +0 -66
  185. package/src/components/ControlBar/ControlBar.styled.ts +0 -82
  186. package/src/components/ControlBar/ControlBar.tsx +0 -528
  187. package/src/components/ControlBar/Facet/Facet.tsx +0 -113
  188. package/src/components/ControlBar/Facet/index.ts +0 -1
  189. package/src/components/FormatDialog/CropPreviewer/CropPreviewer.tsx +0 -224
  190. package/src/components/FormatDialog/CustomRendition/CustomRendition.constants.ts +0 -24
  191. package/src/components/FormatDialog/CustomRendition/CustomRendition.styled.ts +0 -57
  192. package/src/components/FormatDialog/CustomRendition/CustomRendition.tsx +0 -178
  193. package/src/components/FormatDialog/CustomRendition/index.ts +0 -1
  194. package/src/components/FormatDialog/CustomRendition/transformations/Crop.tsx +0 -249
  195. package/src/components/FormatDialog/CustomRendition/transformations/Extension.tsx +0 -54
  196. package/src/components/FormatDialog/CustomRendition/transformations/Format.tsx +0 -86
  197. package/src/components/FormatDialog/CustomRendition/transformations/Resize.tsx +0 -176
  198. package/src/components/FormatDialog/CustomRendition/transformations/Rotate.tsx +0 -101
  199. package/src/components/FormatDialog/FormatDialog.styled.ts +0 -137
  200. package/src/components/FormatDialog/FormatDialog.tsx +0 -1533
  201. package/src/components/FormatDialog/Previewer/Previewer.styled.ts +0 -31
  202. package/src/components/FormatDialog/Previewer/Previewer.tsx +0 -143
  203. package/src/components/FormatDialog/Previewer/index.ts +0 -1
  204. package/src/components/FormatDialog/ProxyMenu/ProxyMenu.styled.ts +0 -88
  205. package/src/components/FormatDialog/ProxyMenu/ProxyMenu.tsx +0 -74
  206. package/src/components/FormatDialog/ProxyMenu/index.ts +0 -1
  207. package/src/components/FormatDialog/TrackingParameters/TrackingParameters.tsx +0 -59
  208. package/src/components/FormatDialog/TrackingParameters/index.ts +0 -1
  209. package/src/components/FormatDialog/index.ts +0 -1
  210. package/src/components/Header/Header.styled.ts +0 -51
  211. package/src/components/Header/Header.tsx +0 -118
  212. package/src/components/Loader/Loader.tsx +0 -37
  213. package/src/components/Loader/index.ts +0 -1
  214. package/src/components/NoResult/NoResult.tsx +0 -37
  215. package/src/components/NoResult/index.tsx +0 -1
  216. package/src/components/Result/AssetCard/AssetCard.styled.ts +0 -120
  217. package/src/components/Result/AssetCard/AssetCard.tsx +0 -192
  218. package/src/components/Result/AssetCard/AssetCardWrapper.styled.ts +0 -35
  219. package/src/components/Result/AssetCard/AssetCardWrapper.tsx +0 -165
  220. package/src/components/Result/AssetCard/index.ts +0 -1
  221. package/src/components/Result/AssetPreview/AssetPreview.styled.ts +0 -108
  222. package/src/components/Result/AssetPreview/AssetPreview.tsx +0 -78
  223. package/src/components/Result/AssetPreview/ImagePreview/ImagePreview.tsx +0 -42
  224. package/src/components/Result/AssetPreview/ImagePreview/index.ts +0 -1
  225. package/src/components/Result/AssetPreview/OtherPreview/OtherPreview.styled.ts +0 -23
  226. package/src/components/Result/AssetPreview/OtherPreview/OtherPreview.tsx +0 -28
  227. package/src/components/Result/AssetPreview/OtherPreview/index.ts +0 -1
  228. package/src/components/Result/AssetPreview/VideoPreview/VideoPreview.tsx +0 -132
  229. package/src/components/Result/AssetPreview/VideoPreview/index.ts +0 -1
  230. package/src/components/Result/AssetPreview/index.ts +0 -1
  231. package/src/consts/asset.ts +0 -16
  232. package/src/consts/data.ts +0 -17
  233. package/src/index.tsx +0 -305
  234. package/src/page/Authenticate/Authenticate.tsx +0 -232
  235. package/src/page/Authenticate/ConnectingBackground.tsx +0 -44
  236. package/src/page/Authenticate/index.tsx +0 -94
  237. package/src/page/Home/Home.styled.ts +0 -46
  238. package/src/page/Home/Home.tsx +0 -941
  239. package/src/react-web-component.d.ts +0 -4617
  240. package/src/store/assets/assets.api.ts +0 -167
  241. package/src/store/assets/assets.service.ts +0 -223
  242. package/src/store/assets/assets.slice.ts +0 -104
  243. package/src/store/auth/auth.service.ts +0 -71
  244. package/src/store/auth/auth.slice.ts +0 -295
  245. package/src/store/index.ts +0 -27
  246. package/src/store/search/search.api.ts +0 -319
  247. package/src/store/search/search.slice.ts +0 -28
  248. package/src/store/user/user.api.ts +0 -29
  249. package/src/styles.css +0 -42
  250. package/src/types/assets.ts +0 -71
  251. package/src/types/auth.ts +0 -42
  252. package/src/types/common.ts +0 -11
  253. package/src/types/download.ts +0 -8
  254. package/src/types/navigation.ts +0 -3
  255. package/src/types/search.ts +0 -116
  256. package/src/types/user.ts +0 -6
  257. package/src/utils/api.ts +0 -186
  258. package/src/utils/array.ts +0 -25
  259. package/src/utils/constants.ts +0 -12
  260. package/src/utils/fetch.ts +0 -116
  261. package/src/utils/getRequestUrl.ts +0 -15
  262. package/src/utils/hooks.ts +0 -36
  263. package/src/utils/icon.ts +0 -22
  264. package/src/utils/image.ts +0 -157
  265. package/src/utils/number.ts +0 -11
  266. package/src/utils/rotate.ts +0 -23
  267. package/src/utils/storage.ts +0 -184
  268. package/src/utils/string.ts +0 -24
  269. package/src/view/AssetsPicker.tsx +0 -24
  270. package/src/web-component.d.ts +0 -8151
  271. package/tsconfig.eslint.json +0 -10
  272. package/tsconfig.json +0 -37
  273. /package/{src/components/Browser/index.ts → build/components/Browser/index.d.ts} +0 -0
  274. /package/{src/components/ControlBar/index.ts → build/components/ControlBar/index.d.ts} +0 -0
  275. /package/{src/components/Header/index.ts → build/components/Header/index.d.ts} +0 -0
  276. /package/{public → build}/favicon.ico +0 -0
  277. /package/{public → build}/logo192.png +0 -0
  278. /package/{public → build}/logo512.png +0 -0
  279. /package/{public → build}/manifest.json +0 -0
  280. /package/{src/page/Home/index.ts → build/page/Home/index.d.ts} +0 -0
  281. /package/{public → build}/robots.txt +0 -0
@@ -1,1533 +0,0 @@
1
- import _uniqBy from 'lodash-es/uniqBy';
2
- import {
3
- CSSProperties, FC, useCallback, useEffect, useMemo, useReducer, useRef, useState,
4
- } from 'react';
5
-
6
- import { TrackingParameter, Transformation, TransformationAction, Unit } from '@/types/assets';
7
- import { Asset, MediaType, Proxy } from '@/types/search';
8
- import { convertPixelsToAspectRatio } from '@/utils/number';
9
- import { rotateBox } from '@/utils/rotate';
10
- import { CxDialog, CxDrawer, CxSelectEvent } from '@/web-component';
11
-
12
- import CropPreviewer, { CropPreviewerHandle } from './CropPreviewer';
13
- import CustomRendition from './CustomRendition';
14
- import { Dialog, Drawer } from './FormatDialog.styled';
15
- import Previewer from './Previewer';
16
- import ProxyMenu from './ProxyMenu';
17
- import TrackingParameters from './TrackingParameters';
18
-
19
- type Props = {
20
- allowTracking: boolean;
21
- allowCustomFormat: boolean;
22
- autoExtension: string;
23
- availableExtensions?: Record<MediaType, { displayName: string; value: string }[]>;
24
- availableProxies?: Proxy[];
25
- ctaText?: string;
26
- extensions: string[];
27
- maxHeight?: number;
28
- open: boolean;
29
- previewUrl?: string;
30
- searchInDrive: boolean;
31
- selectedAsset: Asset | null;
32
- supportedRepresentativeSubtypes?: string[];
33
- variant?: 'dialog' | 'drawer';
34
- onClose: () => void;
35
- onProxyConfirm: (value: {
36
- extension: string;
37
- permanentLink?: string;
38
- parameters?: TrackingParameter[];
39
- useRepresentative?: boolean;
40
- value: string;
41
- }) => void;
42
- onFormatConfirm: (value: {
43
- value: Transformation[];
44
- parameters?: TrackingParameter[];
45
- proxiesPreference?: string;
46
- extension?: string;
47
- }) => void;
48
- onOpenInDriveConfirm: () => void;
49
- };
50
-
51
- type State = {
52
- previewLoadable: boolean;
53
- defaultSize: {
54
- width: number;
55
- height: number;
56
- },
57
- selectedProxy: string;
58
- selectedFormat: {
59
- url: string;
60
- originalUrl: string;
61
- width: number;
62
- height: number;
63
- x: number;
64
- y: number;
65
- extension: string;
66
- rotation: number;
67
- };
68
- resizeSize: {
69
- width: number;
70
- height: number;
71
- unit: Unit;
72
- };
73
- lastResizeSize: Record<Unit, { width: number; height: number; unit: Unit; }>;
74
- cropSize: {
75
- width: number;
76
- height: number;
77
- percentageWidth: number;
78
- percentageHeight: number;
79
- x: number;
80
- y: number;
81
- unit: Unit;
82
- };
83
- lastCropSize: Record<Unit, {
84
- width: number;
85
- height: number;
86
- percentageWidth: number;
87
- percentageHeight: number;
88
- x: number;
89
- y: number;
90
- unit: Unit;
91
- }>;
92
- rotation: number;
93
- transformations: Transformation[];
94
- enabledTracking: boolean;
95
- trackingParameters: TrackingParameter[];
96
- showCustomRendition: boolean;
97
- useCustomRendition: boolean;
98
- useRepresentative: boolean;
99
- activeSetting: string;
100
- isLoading: boolean;
101
- };
102
-
103
- type Action =
104
- | { type: 'CANCEL_USE_CUSTOM_RENDITION'; payload: { width: number; height: number, url: string, originalUrl: string, extension: string } }
105
- | { type: 'CONFIRM_USE_CUSTOM_RENDITION' }
106
- | { type: 'RESET_DATA' }
107
- | { type: 'SET_ACTIVE_SETTING'; payload: string }
108
- | { type: 'SET_CROP_SIZE'; payload: Partial<State['cropSize']> }
109
- | { type: 'SET_DEFAULT_SIZE'; payload: Partial<State['defaultSize']> }
110
- | { type: 'SET_ENABLED_TRACKING'; payload: boolean }
111
- | { type: 'SET_LAST_RESIZE_SIZE'; payload: Partial<State['lastResizeSize']> }
112
- | { type: 'SET_LAST_CROP_SIZE'; payload: Partial<State['lastCropSize']> }
113
- | { type: 'SET_LOADING'; payload: boolean }
114
- | { type: 'SET_PREVIEW_LOADABLE'; payload: boolean }
115
- | { type: 'SET_RESIZE_SIZE'; payload: Partial<State['resizeSize']> }
116
- | { type: 'SET_ROTATION'; payload: number }
117
- | { type: 'SET_SELECTED_FORMAT'; payload: Partial<State['selectedFormat']> }
118
- | { type: 'SET_SELECTED_PROXY'; payload: string | { proxy: string; useCustomRendition?: boolean } }
119
- | { type: 'SET_SHOW_CUSTOM_RENDITION'; payload: boolean }
120
- | { type: 'SET_TRACKING_PARAMETERS'; payload: TrackingParameter[] }
121
- | { type: 'SET_TRANSFORMATIONS'; payload: Transformation }
122
- | { type: 'SET_USE_REPRESENTATIVE'; payload: boolean };
123
-
124
- const initialState: State = {
125
- previewLoadable: false,
126
- defaultSize: {
127
- width: 0,
128
- height: 0,
129
- },
130
- selectedProxy: '',
131
- selectedFormat: {
132
- url: '',
133
- originalUrl: '',
134
- width: 0,
135
- height: 0,
136
- x: 0,
137
- y: 0,
138
- extension: '',
139
- rotation: 0,
140
- },
141
- resizeSize: {
142
- width: 0,
143
- height: 0,
144
- unit: Unit.Pixel,
145
- },
146
- lastResizeSize: {
147
- [Unit.AspectRatio]: {
148
- width: 0,
149
- height: 0,
150
- unit: Unit.AspectRatio,
151
- },
152
- [Unit.Pixel]: {
153
- width: 0,
154
- height: 0,
155
- unit: Unit.Pixel,
156
- },
157
- },
158
- cropSize: {
159
- width: 0,
160
- height: 0,
161
- percentageWidth: 0,
162
- percentageHeight: 0,
163
- x: 0,
164
- y: 0,
165
- unit: Unit.Pixel,
166
- },
167
- lastCropSize: {
168
- [Unit.AspectRatio]: {
169
- width: 0,
170
- height: 0,
171
- percentageWidth: 0,
172
- percentageHeight: 0,
173
- x: 0,
174
- y: 0,
175
- unit: Unit.AspectRatio,
176
- },
177
- [Unit.Pixel]: {
178
- width: 0,
179
- height: 0,
180
- percentageWidth: 0,
181
- percentageHeight: 0,
182
- x: 0,
183
- y: 0,
184
- unit: Unit.Pixel,
185
- },
186
- },
187
- rotation: 0,
188
- transformations: [],
189
- enabledTracking: false,
190
- trackingParameters: [{
191
- key: 'UTM_source',
192
- value: '',
193
- }, {
194
- key: 'UTM_campaign',
195
- value: '',
196
- }, {
197
- key: 'UTM_description',
198
- value: '',
199
- }],
200
- showCustomRendition: false,
201
- useCustomRendition: false,
202
- useRepresentative: false,
203
- activeSetting: 'format',
204
- isLoading: false,
205
- };
206
-
207
- const reducer = (state: State, action: Action): State => {
208
- switch (action.type) {
209
- case 'CANCEL_USE_CUSTOM_RENDITION':
210
- return {
211
- ...state,
212
- cropSize: {
213
- ...state.cropSize,
214
- width: action.payload.width,
215
- height: action.payload.height,
216
- },
217
- resizeSize: {
218
- ...state.resizeSize,
219
- width: action.payload.width,
220
- height: action.payload.height,
221
- },
222
- selectedFormat: {
223
- ...state.selectedFormat,
224
- ...action.payload,
225
- rotation: 0,
226
- x: 0,
227
- y: 0,
228
- },
229
- rotation: 0,
230
- transformations: [],
231
- showCustomRendition: false,
232
- useCustomRendition: false,
233
- activeSetting: 'resize',
234
- };
235
- case 'CONFIRM_USE_CUSTOM_RENDITION':
236
- return {
237
- ...state,
238
- cropSize: {
239
- ...state.cropSize,
240
- width: state.selectedFormat.width,
241
- height: state.selectedFormat.height,
242
- },
243
- resizeSize: {
244
- ...state.resizeSize,
245
- width: state.selectedFormat.width,
246
- height: state.selectedFormat.height,
247
- },
248
- rotation: 0,
249
- activeSetting: 'resize',
250
- showCustomRendition: false,
251
- useCustomRendition: true,
252
- };
253
- case 'SET_DEFAULT_SIZE':
254
- return {
255
- ...state,
256
- defaultSize: {
257
- ...state.defaultSize,
258
- ...action.payload,
259
- },
260
- };
261
- case 'RESET_DATA':
262
- return initialState;
263
- case 'SET_ACTIVE_SETTING':
264
- return {
265
- ...state,
266
- activeSetting: action.payload,
267
- };
268
- case 'SET_CROP_SIZE':
269
- return {
270
- ...state,
271
- cropSize: {
272
- ...state.cropSize,
273
- ...action.payload,
274
- },
275
- };
276
- case 'SET_ENABLED_TRACKING':
277
- return {
278
- ...state,
279
- enabledTracking: action.payload,
280
- };
281
- case 'SET_LAST_CROP_SIZE':
282
- return {
283
- ...state,
284
- lastCropSize: {
285
- ...state.lastCropSize,
286
- ...action.payload,
287
- },
288
- };
289
- case 'SET_LAST_RESIZE_SIZE':
290
- return {
291
- ...state,
292
- lastResizeSize: {
293
- ...state.lastResizeSize,
294
- ...action.payload,
295
- },
296
- };
297
- case 'SET_LOADING':
298
- return {
299
- ...state,
300
- isLoading: action.payload,
301
- };
302
- case 'SET_PREVIEW_LOADABLE':
303
- return {
304
- ...state,
305
- previewLoadable: action.payload,
306
- };
307
- case 'SET_RESIZE_SIZE':
308
- return {
309
- ...state,
310
- resizeSize: {
311
- ...state.resizeSize,
312
- ...action.payload,
313
- },
314
- };
315
- case 'SET_ROTATION':
316
- return {
317
- ...state,
318
- rotation: action.payload,
319
- };
320
- case 'SET_SELECTED_FORMAT':
321
- return {
322
- ...state,
323
- selectedFormat: {
324
- ...state.selectedFormat,
325
- ...action.payload,
326
- },
327
- };
328
- case 'SET_SELECTED_PROXY':
329
-
330
- if (typeof action.payload === 'string') {
331
- return {
332
- ...state,
333
- selectedProxy: action.payload,
334
- useCustomRendition: false,
335
- useRepresentative: false,
336
- };
337
- }
338
- return {
339
- ...state,
340
- selectedProxy: action.payload.proxy,
341
- useCustomRendition: Boolean(action.payload.useCustomRendition),
342
- useRepresentative: false,
343
- };
344
- case 'SET_SHOW_CUSTOM_RENDITION':
345
- return {
346
- ...state,
347
- // Remove selected proxy when custom rendition is selected
348
- selectedProxy: '',
349
- showCustomRendition: action.payload,
350
- useCustomRendition: false,
351
- };
352
- case 'SET_TRACKING_PARAMETERS':
353
- return {
354
- ...state,
355
- trackingParameters: action.payload,
356
- };
357
- case 'SET_TRANSFORMATIONS':
358
- return {
359
- ...state,
360
- transformations: [...state.transformations, action.payload],
361
- };
362
- case 'SET_USE_REPRESENTATIVE':
363
- return {
364
- ...state,
365
- selectedProxy: action.payload ? '' : state.selectedProxy,
366
- useRepresentative: action.payload,
367
- };
368
- default:
369
- return state;
370
- }
371
- };
372
-
373
- const FormatDialog: FC<Props> = ({
374
- allowTracking,
375
- allowCustomFormat,
376
- autoExtension,
377
- availableExtensions,
378
- availableProxies,
379
- ctaText,
380
- extensions,
381
- maxHeight,
382
- open,
383
- previewUrl,
384
- searchInDrive,
385
- selectedAsset,
386
- supportedRepresentativeSubtypes,
387
- variant = 'dialog',
388
- onClose,
389
- onProxyConfirm,
390
- onFormatConfirm,
391
- onOpenInDriveConfirm,
392
- }) => {
393
- const [state, dispatch] = useReducer(reducer, initialState);
394
- const [isDefined, setIsDefined] = useState(false);
395
- const dialogRef = useRef<CxDialog>(null);
396
- const drawerRef = useRef<CxDrawer>(null);
397
- const previewerRef = useRef<CropPreviewerHandle>(null);
398
-
399
- const setDefaultValues = useCallback(() => {
400
- if (!selectedAsset) {
401
- return;
402
- }
403
-
404
- const defaultRatio = convertPixelsToAspectRatio(
405
- state.defaultSize.width,
406
- state.defaultSize.height,
407
- );
408
-
409
- dispatch({
410
- type: 'SET_RESIZE_SIZE',
411
- payload: {
412
- ...initialState.resizeSize,
413
- width: state.defaultSize.width,
414
- height: state.defaultSize.height,
415
- },
416
- });
417
-
418
- dispatch({
419
- type: 'SET_CROP_SIZE',
420
- payload: {
421
- ...initialState.cropSize,
422
- width: state.defaultSize.width,
423
- height: state.defaultSize.height,
424
- percentageHeight: 100,
425
- percentageWidth: 100,
426
- },
427
- });
428
-
429
- dispatch({
430
- type: 'SET_ROTATION',
431
- payload: 0,
432
- });
433
-
434
- dispatch({
435
- type: 'SET_LAST_CROP_SIZE',
436
- payload: {
437
- ...initialState.lastCropSize,
438
- [Unit.Pixel]: {
439
- width: state.defaultSize.width,
440
- height: state.defaultSize.height,
441
- percentageHeight: 100,
442
- percentageWidth: 100,
443
- x: 0,
444
- y: 0,
445
- unit: Unit.Pixel,
446
- },
447
- [Unit.AspectRatio]: {
448
- width: defaultRatio.width,
449
- height: defaultRatio.height,
450
- percentageHeight: 100,
451
- percentageWidth: 100,
452
- x: 0,
453
- y: 0,
454
- unit: Unit.AspectRatio,
455
- },
456
- },
457
- });
458
-
459
- dispatch({
460
- type: 'SET_LAST_RESIZE_SIZE',
461
- payload: {
462
- [Unit.Pixel]: {
463
- width: state.defaultSize.width,
464
- height: state.defaultSize.height,
465
- unit: Unit.Pixel,
466
- },
467
- [Unit.AspectRatio]: {
468
- width: defaultRatio.width,
469
- height: defaultRatio.height,
470
- unit: Unit.AspectRatio,
471
- },
472
- },
473
- });
474
-
475
- if (availableProxies) {
476
- dispatch({
477
- type: 'SET_SELECTED_PROXY',
478
- payload: availableProxies[0]?.id,
479
- });
480
-
481
- dispatch({
482
- type: 'SET_SELECTED_FORMAT',
483
- payload: {
484
- ...initialState.selectedFormat,
485
- url: selectedAsset.imageUrl,
486
- originalUrl: selectedAsset.originalUrl,
487
- extension: autoExtension ?? selectedAsset.extension,
488
- width: availableProxies[0].formatWidth,
489
- height: availableProxies[0].formatHeight,
490
- },
491
- });
492
- } else {
493
- dispatch({
494
- type: 'SET_SELECTED_FORMAT',
495
- payload: {
496
- ...initialState.selectedFormat,
497
- url: selectedAsset.imageUrl,
498
- originalUrl: selectedAsset.originalUrl,
499
- extension: autoExtension ?? selectedAsset.extension,
500
- width: state.defaultSize.width,
501
- height: state.defaultSize.height,
502
- },
503
- });
504
- }
505
- }, [autoExtension, availableProxies, selectedAsset, state.defaultSize.height, state.defaultSize.width]);
506
-
507
- useEffect(() => {
508
- if (selectedAsset?.width && selectedAsset?.height) {
509
- dispatch({
510
- type: 'SET_DEFAULT_SIZE',
511
- payload: {
512
- width: parseInt(selectedAsset.width, 10),
513
- height: parseInt(selectedAsset.height, 10),
514
- },
515
- });
516
- }
517
- }, [selectedAsset?.width, selectedAsset?.height]);
518
-
519
-
520
- useEffect(() => {
521
- Promise.all([
522
- customElements.whenDefined('cx-dialog'),
523
- customElements.whenDefined('cx-drawer'),
524
- customElements.whenDefined('cx-dropdown'),
525
- ]).then(() => {
526
- setIsDefined(true);
527
- });
528
- }, []);
529
-
530
- useEffect(() => {
531
- const onRequestClose = () => {
532
- dispatch({ type: 'SET_PREVIEW_LOADABLE', payload: false });
533
- dispatch({ type: 'RESET_DATA' });
534
- onClose();
535
- };
536
-
537
- const dialog = dialogRef.current;
538
- const drawer = drawerRef.current;
539
-
540
- dialog?.addEventListener('cx-request-close', onRequestClose);
541
- drawer?.addEventListener('cx-request-close', onRequestClose);
542
-
543
- return () => {
544
- dialog?.removeEventListener('cx-request-close', onRequestClose);
545
- drawer?.removeEventListener('cx-request-close', onRequestClose);
546
- };
547
- }, [isDefined, onClose]);
548
-
549
- useEffect(() => {
550
- const onAfterShow = () => {
551
- dispatch({ type: 'SET_PREVIEW_LOADABLE', payload: true });
552
- };
553
-
554
- const dialog = dialogRef.current;
555
- const drawer = drawerRef.current;
556
-
557
- dialog?.addEventListener('cx-after-show', onAfterShow);
558
- drawer?.addEventListener('cx-after-show', onAfterShow);
559
-
560
- return () => {
561
- dialog?.removeEventListener('cx-after-show', onAfterShow);
562
- drawer?.removeEventListener('cx-after-show', onAfterShow);
563
- };
564
- }, [isDefined, state.showCustomRendition, variant]);
565
-
566
- useEffect(() => {
567
- const onProxySelect = (e: CxSelectEvent) => {
568
- const value = e.detail.item.value;
569
-
570
- if (value === 'custom') {
571
- dispatch({ type: 'SET_SHOW_CUSTOM_RENDITION', payload: true });
572
- if (!state.useCustomRendition) {
573
- setDefaultValues();
574
- }
575
- return;
576
- }
577
-
578
- if (value === 'tracking') {
579
- dispatch({
580
- type: 'SET_ENABLED_TRACKING',
581
- payload: !state.enabledTracking,
582
- });
583
- return;
584
- }
585
-
586
- if (value === 'use-representative') {
587
- dispatch({
588
- type: 'SET_USE_REPRESENTATIVE',
589
- payload: !state.useRepresentative,
590
- });
591
- return;
592
- }
593
-
594
- if (value && availableProxies) {
595
- if (!availableProxies.map(item => item.id).includes(value)) {
596
- return;
597
- }
598
- dispatch({ type: 'SET_SELECTED_PROXY', payload: value });
599
- }
600
- };
601
-
602
- const dialog = dialogRef.current;
603
- const drawer = drawerRef.current;
604
-
605
- dialog?.addEventListener('cx-select', onProxySelect);
606
- drawer?.addEventListener('cx-select', onProxySelect);
607
-
608
- return () => {
609
- dialog?.removeEventListener('cx-select', onProxySelect);
610
- drawer?.removeEventListener('cx-select', onProxySelect);
611
- };
612
- }, [
613
- isDefined,
614
- state.enabledTracking,
615
- state.useCustomRendition,
616
- state.useRepresentative,
617
- setDefaultValues,
618
- availableProxies,
619
- selectedAsset?.extension,
620
- ]);
621
-
622
- useEffect(() => {
623
- setDefaultValues();
624
- }, [setDefaultValues]);
625
-
626
- const supportedRepresentative = useMemo(
627
- () =>
628
- supportedRepresentativeSubtypes?.includes(selectedAsset?.docSubType ?? '') &&
629
- selectedAsset?.imageUrl,
630
- [selectedAsset, supportedRepresentativeSubtypes],
631
- );
632
-
633
- const onLoadingChange = useCallback((isLoading: boolean) => {
634
- dispatch({ type: 'SET_LOADING', payload: isLoading });
635
- }, []);
636
-
637
- const onResizeChange = useCallback(async (width: number, height: number, unit: Unit, shouldApply: boolean) => {
638
- if (!selectedAsset) {
639
- return;
640
- }
641
-
642
- const currentWidth = state.selectedFormat.width || state.defaultSize.width;
643
- const currentHeight = state.selectedFormat.height || state.defaultSize.height;
644
-
645
- dispatch({
646
- type: 'SET_RESIZE_SIZE',
647
- payload: {
648
- width,
649
- height,
650
- unit,
651
- },
652
- });
653
-
654
- if (shouldApply) {
655
- let newFormatWidth = width;
656
- let newFormatHeight = height;
657
-
658
- if (state.resizeSize.unit !== unit) {
659
- newFormatWidth = currentWidth;
660
- newFormatHeight = currentHeight;
661
- } else if (unit === Unit.AspectRatio) {
662
- newFormatWidth =
663
- Math.round((width / height) * currentHeight);
664
- newFormatHeight = currentHeight;
665
- }
666
-
667
- const newImage = await previewerRef.current?.applyResize();
668
-
669
- dispatch({
670
- type: 'SET_SELECTED_FORMAT',
671
- payload: {
672
- url: newImage,
673
- width: newFormatWidth,
674
- height: newFormatHeight,
675
- },
676
- });
677
-
678
- dispatch({
679
- type: 'SET_TRANSFORMATIONS',
680
- payload: {
681
- key: TransformationAction.Resize,
682
- value: {
683
- width: newFormatWidth,
684
- height: newFormatHeight,
685
- },
686
- },
687
- });
688
-
689
- dispatch({
690
- type: 'SET_CROP_SIZE',
691
- payload: {
692
- width: newFormatWidth,
693
- height: newFormatHeight,
694
- },
695
- });
696
-
697
- const ratio = convertPixelsToAspectRatio(newFormatWidth, newFormatHeight);
698
- dispatch({
699
- type: 'SET_LAST_RESIZE_SIZE',
700
- payload: {
701
- [Unit.Pixel]: {
702
- width: newFormatWidth,
703
- height: newFormatHeight,
704
- unit: Unit.Pixel,
705
- },
706
- [Unit.AspectRatio]: {
707
- width: unit === Unit.AspectRatio ? width : ratio.width,
708
- height: unit === Unit.AspectRatio ? height : ratio.height,
709
- unit: Unit.AspectRatio,
710
- },
711
- },
712
- });
713
-
714
- dispatch({
715
- type: 'SET_LAST_CROP_SIZE',
716
- payload: {
717
- [Unit.Pixel]: {
718
- width: newFormatWidth,
719
- height: newFormatHeight,
720
- percentageHeight: 100,
721
- percentageWidth: 100,
722
- x: 0,
723
- y: 0,
724
- unit: Unit.Pixel,
725
- },
726
- [Unit.AspectRatio]: {
727
- width: unit === Unit.AspectRatio ? width : ratio.width,
728
- height: unit === Unit.AspectRatio ? height : ratio.height,
729
- percentageHeight: 100,
730
- percentageWidth: 100,
731
- x: 0,
732
- y: 0,
733
- unit: Unit.AspectRatio,
734
- },
735
- },
736
- });
737
- }
738
- }, [selectedAsset, state.defaultSize.height, state.defaultSize.width, state.resizeSize.unit, state.selectedFormat.height, state.selectedFormat.width]);
739
-
740
- const onCropChange = useCallback(async (width: number, height: number, unit: Unit, shouldApply: boolean) => {
741
- if (!selectedAsset) {
742
- return;
743
- }
744
- const previousUnit = state.cropSize.unit;
745
- const previewHandle = previewerRef.current;
746
-
747
- if (previewHandle && state.selectedFormat?.width && state.selectedFormat?.height) {
748
-
749
- if (unit === previousUnit && unit === Unit.Pixel) {
750
- const scale = Math.max(
751
- width / state.selectedFormat.width,
752
- height / state.selectedFormat.height,
753
- );
754
- previewHandle.setZoom(1 / scale);
755
- }
756
-
757
- if (unit !== previousUnit) {
758
- previewHandle.setZoom(1);
759
- }
760
- }
761
-
762
-
763
- dispatch({
764
- type: 'SET_CROP_SIZE',
765
- payload: {
766
- width,
767
- height,
768
- unit,
769
- },
770
- });
771
-
772
- if (shouldApply) {
773
- const newImage = await previewerRef.current?.applyCrop();
774
-
775
- let newWidth = width;
776
- let newHeight = height;
777
- if (unit === Unit.AspectRatio) {
778
- newWidth = Math.round((state.cropSize.percentageWidth * state.selectedFormat.width) / 100);
779
- newHeight = Math.round((state.cropSize.percentageHeight * state.selectedFormat.height) / 100);
780
- }
781
- previewHandle?.setZoom(1);
782
-
783
- const newX = Number(
784
- ((state.cropSize.x / 100) * state.selectedFormat.width).toFixed(0),
785
- );
786
- const newY = Number(
787
- ((state.cropSize.y / 100) * state.selectedFormat.height).toFixed(0),
788
- );
789
-
790
- dispatch({
791
- type: 'SET_SELECTED_FORMAT',
792
- payload: {
793
- url: newImage,
794
- width: newWidth,
795
- height: newHeight,
796
- },
797
- });
798
-
799
- dispatch({
800
- type: 'SET_RESIZE_SIZE',
801
- payload: {
802
- width: newWidth,
803
- height: newHeight,
804
- unit: Unit.Pixel,
805
- },
806
- });
807
-
808
- dispatch({
809
- type: 'SET_TRANSFORMATIONS',
810
- payload: {
811
- key: TransformationAction.Crop,
812
- value: {
813
- width: Number(newWidth.toFixed(0)),
814
- height: Number(newHeight.toFixed(0)),
815
- x: newX,
816
- y: newY,
817
- },
818
- },
819
- });
820
-
821
- const ratio = convertPixelsToAspectRatio(newWidth, newHeight);
822
-
823
- dispatch({
824
- type: 'SET_LAST_CROP_SIZE',
825
- payload: {
826
- [Unit.Pixel]:{
827
- width: Math.round(newWidth),
828
- height: Math.round(newHeight),
829
- percentageHeight: 100,
830
- percentageWidth: 100,
831
- x: 0,
832
- y: 0,
833
- unit: Unit.Pixel,
834
- },
835
- [Unit.AspectRatio]: {
836
- width: unit === Unit.AspectRatio ? width : ratio.width,
837
- height: unit === Unit.AspectRatio ? height : ratio.height,
838
- percentageHeight: 100,
839
- percentageWidth: 100,
840
- x: 0,
841
- y: 0,
842
- unit: Unit.AspectRatio,
843
- },
844
- },
845
- });
846
-
847
- dispatch({
848
- type: 'SET_LAST_RESIZE_SIZE',
849
- payload: {
850
- [Unit.Pixel]: {
851
- width: newWidth,
852
- height: newHeight,
853
- unit: Unit.Pixel,
854
- },
855
- [Unit.AspectRatio]: {
856
- width: unit === Unit.AspectRatio ? width : ratio.width,
857
- height: unit === Unit.AspectRatio ? height : ratio.height,
858
- unit: Unit.AspectRatio,
859
- },
860
- },
861
- });
862
- }
863
- },
864
- [
865
- selectedAsset,
866
- state.cropSize,
867
- state.selectedFormat.height,
868
- state.selectedFormat.width,
869
- ],
870
- );
871
-
872
- const onRotateChange = useCallback(async (rotation: number, shouldApply: boolean) => {
873
- dispatch({
874
- type: 'SET_ROTATION',
875
- payload: shouldApply ? 0 : rotation,
876
- });
877
-
878
- if (shouldApply) {
879
- const { width: newWidth, height: newHeight } = rotateBox(
880
- state.selectedFormat.width,
881
- state.selectedFormat.height,
882
- rotation,
883
- );
884
- const newImage = await previewerRef.current?.applyRotation();
885
- dispatch({
886
- type: 'SET_SELECTED_FORMAT',
887
- payload: {
888
- rotation,
889
- url: newImage,
890
- width: newWidth,
891
- height: newHeight,
892
- },
893
- });
894
-
895
- dispatch({
896
- type: 'SET_TRANSFORMATIONS',
897
- payload: {
898
- key: TransformationAction.Rotate,
899
- value: {
900
- rotation,
901
- },
902
- },
903
- });
904
-
905
- dispatch({
906
- type: 'SET_CROP_SIZE',
907
- payload: {
908
- width: newWidth,
909
- height: newHeight,
910
- },
911
- });
912
-
913
- dispatch({
914
- type: 'SET_RESIZE_SIZE',
915
- payload: {
916
- width: newWidth,
917
- height: newHeight,
918
- unit: Unit.Pixel,
919
- },
920
- });
921
-
922
- const ratio = convertPixelsToAspectRatio(newWidth, newHeight);
923
- dispatch({
924
- type: 'SET_LAST_CROP_SIZE',
925
- payload: {
926
- [Unit.Pixel]:{
927
- width: newWidth,
928
- height: newHeight,
929
- percentageHeight: 100,
930
- percentageWidth: 100,
931
- x: 0,
932
- y: 0,
933
- unit: Unit.Pixel,
934
- },
935
- [Unit.AspectRatio]: {
936
- width: ratio.width,
937
- height: ratio.height,
938
- percentageHeight: 100,
939
- percentageWidth: 100,
940
- x: 0,
941
- y: 0,
942
- unit: Unit.AspectRatio,
943
- },
944
- },
945
- });
946
-
947
- dispatch({
948
- type: 'SET_LAST_RESIZE_SIZE',
949
- payload: {
950
- [Unit.Pixel]: {
951
- width: newWidth,
952
- height: newHeight,
953
- unit: Unit.Pixel,
954
- },
955
- [Unit.AspectRatio]: {
956
- width: ratio.width,
957
- height: ratio.height,
958
- unit: Unit.AspectRatio,
959
- },
960
- },
961
- });
962
- }
963
- }, [state.selectedFormat]);
964
-
965
- const onExtensionChange = useCallback((extension: string) => {
966
- dispatch({
967
- type: 'SET_SELECTED_FORMAT',
968
- payload: {
969
- extension,
970
- },
971
- });
972
- }, []);
973
-
974
- const onViewChange = useCallback((view: string) => {
975
- dispatch({
976
- type: 'SET_CROP_SIZE',
977
- payload: {
978
- width: state.selectedFormat.width,
979
- height: state.selectedFormat.height,
980
- unit: Unit.Pixel,
981
- },
982
- });
983
- dispatch({
984
- type: 'SET_RESIZE_SIZE',
985
- payload: {
986
- width: state.selectedFormat.width,
987
- height: state.selectedFormat.height,
988
- unit: Unit.Pixel,
989
- },
990
- });
991
- dispatch({
992
- type: 'SET_ROTATION',
993
- payload: 0,
994
- });
995
- dispatch({
996
- type: 'SET_ACTIVE_SETTING',
997
- payload: view,
998
- });
999
- }, [state.selectedFormat]);
1000
-
1001
- const onFormatChange = useCallback((format: Proxy) => {
1002
- let width = format.formatWidth;
1003
- let height = format.formatHeight;
1004
-
1005
- if (format.proxyName === 'TRX' && selectedAsset) {
1006
- width = Number(selectedAsset.width);
1007
- height = Number(selectedAsset.height);
1008
- }
1009
-
1010
- dispatch({
1011
- type: 'SET_SELECTED_PROXY',
1012
- payload: {
1013
- proxy: format.id,
1014
- useCustomRendition: true,
1015
- },
1016
- });
1017
-
1018
- dispatch({
1019
- type: 'SET_SELECTED_FORMAT',
1020
- payload: {
1021
- width,
1022
- height,
1023
- },
1024
- });
1025
- dispatch({
1026
- type: 'SET_RESIZE_SIZE',
1027
- payload: {
1028
- width,
1029
- height,
1030
- unit: Unit.Pixel,
1031
- },
1032
- });
1033
- dispatch({
1034
- type: 'SET_CROP_SIZE',
1035
- payload: {
1036
- width,
1037
- height,
1038
- percentageWidth: 100,
1039
- percentageHeight: 100,
1040
- x: 0,
1041
- y: 0,
1042
- unit: Unit.Pixel,
1043
- },
1044
- });
1045
-
1046
- const ratio = convertPixelsToAspectRatio(width, height);
1047
-
1048
- dispatch({
1049
- type: 'SET_LAST_CROP_SIZE',
1050
- payload: {
1051
- [Unit.Pixel]:{
1052
- width: Math.round(width),
1053
- height: Math.round(height),
1054
- percentageHeight: 100,
1055
- percentageWidth: 100,
1056
- x: 0,
1057
- y: 0,
1058
- unit: Unit.Pixel,
1059
- },
1060
- [Unit.AspectRatio]: {
1061
- width: ratio.width,
1062
- height: ratio.height,
1063
- percentageHeight: 100,
1064
- percentageWidth: 100,
1065
- x: 0,
1066
- y: 0,
1067
- unit: Unit.AspectRatio,
1068
- },
1069
- },
1070
- });
1071
-
1072
- dispatch({
1073
- type: 'SET_LAST_RESIZE_SIZE',
1074
- payload: {
1075
- [Unit.Pixel]: {
1076
- width: width,
1077
- height: height,
1078
- unit: Unit.Pixel,
1079
- },
1080
- [Unit.AspectRatio]: {
1081
- width: ratio.width,
1082
- height: ratio.height,
1083
- unit: Unit.AspectRatio,
1084
- },
1085
- },
1086
- });
1087
- }, [selectedAsset]);
1088
-
1089
- useEffect(() => {
1090
- if (!availableProxies || availableProxies.length === 0) {
1091
- dispatch({ type: 'SET_SELECTED_PROXY', payload: '' });
1092
- return;
1093
- }
1094
- dispatch({ type: 'SET_SELECTED_PROXY', payload: availableProxies[0].id });
1095
- }, [availableProxies, selectedAsset]);
1096
-
1097
- const renderContent = useCallback(() => {
1098
- const disabledInsert =
1099
- state.isLoading || (!state.selectedProxy && !state.useCustomRendition && !state.useRepresentative);
1100
- const supportedATS = allowCustomFormat && extensions.includes(
1101
- selectedAsset ? selectedAsset.extension : '',
1102
- );
1103
- const supportedProxies = availableProxies && Object.values(availableProxies).flat().length > 0;
1104
-
1105
- const showCustomDimension = state.selectedFormat.width && state.selectedFormat.height && state.useCustomRendition;
1106
-
1107
- const renderBody = () => {
1108
- let previewer = null;
1109
- let rendition = null;
1110
-
1111
- if (state.selectedFormat.width && state.selectedFormat.height && selectedAsset?.docType !== MediaType.Video) {
1112
- previewer = (
1113
- <CropPreviewer
1114
- ref={previewerRef}
1115
- loadable={state.previewLoadable}
1116
- image={state.selectedFormat}
1117
- selectedProxy={state.selectedProxy}
1118
- resizer={state.resizeSize}
1119
- cropper={state.cropSize}
1120
- rotation={state.rotation}
1121
- disabled={state.activeSetting !== 'crop' || !state.showCustomRendition}
1122
- onCropComplete={(croppedArea) => {
1123
- dispatch({
1124
- type: 'SET_CROP_SIZE',
1125
- payload: {
1126
- percentageWidth: croppedArea.width,
1127
- percentageHeight: croppedArea.height,
1128
- x: croppedArea.x,
1129
- y: croppedArea.y,
1130
- },
1131
- });
1132
- }}
1133
- onLoadingChange={onLoadingChange}
1134
- />
1135
- );
1136
- } else {
1137
- previewer = (
1138
- <Previewer
1139
- loadable={state.previewLoadable}
1140
- asset={{
1141
- docType: selectedAsset?.docType,
1142
- imageUrl: selectedAsset?.imageUrl,
1143
- videoUrl: previewUrl,
1144
- extension: selectedAsset?.extension,
1145
- }}
1146
- onLoad={(size) => {
1147
- if ((selectedAsset?.width && selectedAsset?.height) || !selectedAsset?.imageUrl) {
1148
- return;
1149
- }
1150
-
1151
- const defaultWidth = selectedAsset?.width ? parseInt(selectedAsset.width, 10) : size.width;
1152
- const defaultHeight = selectedAsset?.height ? parseInt(selectedAsset.height, 10) : size.height;
1153
-
1154
- dispatch({ type: 'SET_DEFAULT_SIZE', payload: {
1155
- width: defaultWidth,
1156
- height: defaultHeight,
1157
- } });
1158
- }}
1159
- />
1160
- );
1161
- }
1162
-
1163
- if (searchInDrive) {
1164
- return previewer;
1165
- }
1166
-
1167
- if (state.showCustomRendition && availableProxies) {
1168
- rendition = (
1169
- <CustomRendition
1170
- activeSetting={state.activeSetting}
1171
- extensions={
1172
- availableExtensions && selectedAsset?.docType
1173
- ? _uniqBy([
1174
- ...availableExtensions[selectedAsset.docType],
1175
- { displayName: 'Automatic', value: autoExtension },
1176
- ], 'value')
1177
- : [{ displayName: 'Automatic', value: autoExtension }]
1178
- }
1179
- availableProxies={availableProxies}
1180
- imageSize={{
1181
- width: state.selectedFormat.width
1182
- ? state.selectedFormat.width
1183
- : Infinity,
1184
- height: state.selectedFormat.height
1185
- ? state.selectedFormat.height
1186
- : Infinity,
1187
- }}
1188
- resize={{
1189
- width: state.resizeSize.width,
1190
- height: state.resizeSize.height,
1191
- unit: state.resizeSize.unit,
1192
- }}
1193
- crop={state.cropSize}
1194
- lastAppliedCrop={state.lastCropSize}
1195
- lastAppliedResize={state.lastResizeSize}
1196
- proxy={state.selectedProxy}
1197
- rotation={state.rotation}
1198
- extension={state.selectedFormat.extension}
1199
- onCropChange={onCropChange}
1200
- onExtensionChange={onExtensionChange}
1201
- onFormatChange={onFormatChange}
1202
- onResizeChange={onResizeChange}
1203
- onRotateChange={onRotateChange}
1204
- onViewChange={onViewChange}
1205
- />
1206
- );
1207
- } else {
1208
- rendition = (
1209
- <cx-space direction="vertical" spacing="small">
1210
- {supportedProxies || supportedATS ? (
1211
- <div
1212
- style={{
1213
- width: '100%',
1214
- }}
1215
- >
1216
- {supportedProxies && (
1217
- <ProxyMenu
1218
- items={availableProxies.map((proxy) => {
1219
- if (proxy.proxyName === 'TRX' && selectedAsset) {
1220
- return {
1221
- value: proxy.id,
1222
- name: proxy.proxyLabel,
1223
- cdnName: proxy.cdnName,
1224
- width: selectedAsset.width,
1225
- height: selectedAsset.height,
1226
- extension: selectedAsset.extension,
1227
- docType: selectedAsset.docType,
1228
- };
1229
- }
1230
- return {
1231
- value: proxy.id,
1232
- name: proxy.proxyLabel,
1233
- cdnName: proxy.cdnName,
1234
- width: String(proxy.formatWidth),
1235
- height: String(proxy.formatHeight),
1236
- extension: proxy.extension ?? undefined,
1237
- docType: selectedAsset?.docType,
1238
- };
1239
- })}
1240
- selectedDisabled={state.useCustomRendition}
1241
- selectedItem={state.selectedProxy}
1242
- >
1243
- {supportedRepresentative && (
1244
- <cx-menu-item value="use-representative">
1245
- <cx-typography
1246
- variant="body3"
1247
- className={`proxy__name ${
1248
- state.useRepresentative ? 'selected' : ''
1249
- }`}
1250
- >
1251
- Representative image
1252
- </cx-typography>
1253
- <cx-icon slot="suffix" name={state.useRepresentative ? 'check' : ''}></cx-icon>
1254
- </cx-menu-item>
1255
- )}
1256
- </ProxyMenu>
1257
- )}
1258
- {supportedATS && (
1259
- <ProxyMenu
1260
- items={[]}
1261
- selectedItem={state.selectedProxy}
1262
- style={{
1263
- borderTopWidth: '0',
1264
- }}
1265
- >
1266
- <cx-menu-item value="custom">
1267
- <cx-icon slot="prefix" name="crop_rotate" className='icon--large'></cx-icon>
1268
- <div>
1269
- <cx-typography
1270
- variant="body3"
1271
- className={`proxy__name ${
1272
- state.useCustomRendition ? 'selected' : ''
1273
- }`}
1274
- >
1275
- Custom format
1276
- </cx-typography>
1277
- {showCustomDimension && (
1278
- <cx-typography variant="body3" className="proxy__details">
1279
- {state.selectedFormat.width} x {state.selectedFormat.height}
1280
- {state.selectedFormat.extension && (
1281
- <div className="proxy__extension-dot"></div>
1282
- )}
1283
- {state.selectedFormat.extension?.replace(/^\./, '').toUpperCase()}
1284
- </cx-typography>
1285
- )}
1286
- </div>
1287
- <cx-icon
1288
- slot="suffix"
1289
- name={state.useCustomRendition ? 'edit' : ''}
1290
- className="icon--large"
1291
- ></cx-icon>
1292
- <cx-icon
1293
- slot="suffix"
1294
- name={state.useCustomRendition ? 'check' : ''}
1295
- className="icon--large icon--primary"
1296
- ></cx-icon>
1297
- </cx-menu-item>
1298
- </ProxyMenu>
1299
- )}
1300
- {allowTracking && (
1301
- <div
1302
- style={{
1303
- backgroundColor: 'var(--cx-color-neutral-0)',
1304
- width: '100%',
1305
- }}
1306
- >
1307
- <ProxyMenu
1308
- style={{
1309
- border: 'none',
1310
- }}
1311
- >
1312
- <cx-menu-item value="tracking" className="proxy--switch">
1313
- <cx-typography variant="body3" className="proxy__name">
1314
- Tracking parameters
1315
- </cx-typography>
1316
- <cx-switch
1317
- checked={state.enabledTracking}
1318
- onClick={(e) => e.preventDefault()}
1319
- ></cx-switch>
1320
- </cx-menu-item>
1321
- </ProxyMenu>
1322
- {state.enabledTracking && (
1323
- <TrackingParameters
1324
- values={state.trackingParameters}
1325
- onChange={(params) =>
1326
- dispatch({
1327
- type: 'SET_TRACKING_PARAMETERS',
1328
- payload: params,
1329
- })
1330
- }
1331
- />
1332
- )}
1333
- </div>
1334
- )}
1335
- </div>
1336
- ) : (
1337
- <cx-space
1338
- align-items="center"
1339
- spacing="large"
1340
- wrap="nowrap"
1341
- style={{
1342
- backgroundColor: 'var(--cx-color-neutral-0)',
1343
- width: '100%',
1344
- padding: 'var(--cx-spacing-medium)',
1345
- gap: '20px',
1346
- }}
1347
- >
1348
- <cx-icon
1349
- style={{
1350
- color: 'var(--cx-color-warning)',
1351
- }}
1352
- name="warning"
1353
- className="ic_warning_amber"
1354
- ></cx-icon>
1355
- <cx-typography variant="body3" className="proxy__name">
1356
- You don&apos;t have permission to share this asset.
1357
- </cx-typography>
1358
- </cx-space>
1359
- )}
1360
- </cx-space>
1361
- );
1362
- }
1363
-
1364
- return <>{previewer}{rendition}</>;
1365
- };
1366
-
1367
- const renderFooter = () => {
1368
- if (searchInDrive) {
1369
- return (
1370
- <cx-button
1371
- className="dialog__footer__button"
1372
- onClick={onOpenInDriveConfirm}
1373
- variant="primary"
1374
- >
1375
- <cx-icon slot="prefix" name="folder"></cx-icon>
1376
- {ctaText ?? 'Open in drive'}
1377
- </cx-button>
1378
- );
1379
- }
1380
-
1381
- if (state.showCustomRendition) {
1382
- return (
1383
- <cx-space spacing="small" style={{ width: 'fit-content' }}>
1384
- <cx-button
1385
- variant="default"
1386
- onClick={() => {
1387
- dispatch({
1388
- type: 'CANCEL_USE_CUSTOM_RENDITION',
1389
- payload: {
1390
- url: selectedAsset?.imageUrl ?? '',
1391
- originalUrl: selectedAsset?.originalUrl ?? '',
1392
- width: parseInt(selectedAsset?.width ?? '0', 10),
1393
- height: parseInt(selectedAsset?.height ?? '0', 10),
1394
- extension: selectedAsset?.extension ?? '',
1395
- },
1396
- });
1397
- }}
1398
- >
1399
- Cancel
1400
- </cx-button>
1401
- <cx-button
1402
- variant="primary"
1403
- onClick={() => {
1404
- dispatch({ type: 'CONFIRM_USE_CUSTOM_RENDITION' });
1405
- }}
1406
- >
1407
- Done
1408
- </cx-button>
1409
- </cx-space>
1410
- );
1411
- }
1412
-
1413
- return (
1414
- <cx-button
1415
- className="dialog__footer__button"
1416
- disabled={disabledInsert}
1417
- variant="primary"
1418
- style={{ flex: 1 }}
1419
- onClick={() => {
1420
- const selectedProxy = availableProxies?.find((proxy) => {
1421
- return proxy.id === state.selectedProxy;
1422
- });
1423
-
1424
- if (!state.useCustomRendition) {
1425
- if (!selectedAsset?.docType) {
1426
- return;
1427
- }
1428
-
1429
- if (!selectedProxy) {
1430
- return;
1431
- }
1432
-
1433
- onProxyConfirm({
1434
- extension: selectedProxy.extension ?? selectedAsset.extension,
1435
- value: selectedProxy.proxyName,
1436
- permanentLink: selectedProxy.permanentLink ?? undefined,
1437
- parameters: state.enabledTracking
1438
- ? state.trackingParameters
1439
- : undefined,
1440
- useRepresentative: state.useRepresentative,
1441
- });
1442
- } else {
1443
- onFormatConfirm({
1444
- value: state.transformations,
1445
- parameters: state.enabledTracking
1446
- ? state.trackingParameters
1447
- : undefined,
1448
- proxiesPreference: selectedProxy?.proxyName,
1449
- extension: state.selectedFormat.extension,
1450
- });
1451
- }
1452
- dispatch({ type: 'RESET_DATA' });
1453
- onClose();
1454
- }}
1455
- >
1456
- {ctaText ?? 'Insert'}
1457
- </cx-button>
1458
- );
1459
- };
1460
-
1461
- return (
1462
- <>
1463
- <cx-space slot="label" direction="vertical" spacing="2x-small">
1464
- <cx-typography variant="h4">Formats</cx-typography>
1465
- <cx-typography variant="body3" className='asset-name'>
1466
- <cx-line-clamp lines={1}>{selectedAsset?.name}</cx-line-clamp>
1467
- </cx-typography>
1468
- </cx-space>
1469
- {renderBody()}
1470
- <div slot="footer" className="dialog__footer">
1471
- {renderFooter()}
1472
- </div>
1473
- </>
1474
- );
1475
- }, [
1476
- allowTracking,
1477
- allowCustomFormat,
1478
- autoExtension,
1479
- availableExtensions,
1480
- availableProxies,
1481
- ctaText,
1482
- extensions,
1483
- previewUrl,
1484
- searchInDrive,
1485
- selectedAsset,
1486
- supportedRepresentative,
1487
- onClose,
1488
- onCropChange,
1489
- onExtensionChange,
1490
- onFormatChange,
1491
- onFormatConfirm,
1492
- onLoadingChange,
1493
- onOpenInDriveConfirm,
1494
- onProxyConfirm,
1495
- onResizeChange,
1496
- onRotateChange,
1497
- onViewChange,
1498
- state,
1499
- ]);
1500
-
1501
- if (variant === 'drawer') {
1502
- return (
1503
- <Drawer
1504
- ref={drawerRef}
1505
- className="dialog"
1506
- label="Drawer"
1507
- placement="bottom"
1508
- contained
1509
- open={open}
1510
- >
1511
- {renderContent()}
1512
- </Drawer>
1513
- );
1514
- }
1515
-
1516
- return (
1517
- <Dialog
1518
- ref={dialogRef}
1519
- className="dialog"
1520
- open={open}
1521
- strategy="absolute"
1522
- style={
1523
- {
1524
- '--max-height': `${maxHeight}px`,
1525
- } as CSSProperties
1526
- }
1527
- >
1528
- {renderContent()}
1529
- </Dialog>
1530
- );
1531
- };
1532
-
1533
- export default FormatDialog;