| @@ -1,457 +1,254 @@ | ||
| 1 | -/******/ (function() { // webpackBootstrap | |
| 2 | -/******/ "use strict"; | |
| 3 | -/******/ var __webpack_modules__ = ({ | |
| 1 | +(function(_elementor_query, _elementor_utils, react) { | |
| 4 | 2 | |
| 5 | -/***/ "./packages/packages/libs/wp-media/src/errors.ts": | |
| 6 | -/*!*******************************************************!*\ | |
| 7 | - !*** ./packages/packages/libs/wp-media/src/errors.ts ***! | |
| 8 | - \*******************************************************/ | |
| 9 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 3 | +//#region \0rolldown/runtime.js | |
| 4 | + var __defProp = Object.defineProperty; | |
| 5 | + var __name = (target, value) => __defProp(target, "name", { | |
| 6 | + value, | |
| 7 | + configurable: true | |
| 8 | + }); | |
| 9 | + var __exportAll = (all, no_symbols) => { | |
| 10 | + let target = {}; | |
| 11 | + for (var name in all) { | |
| 12 | + __defProp(target, name, { | |
| 13 | + get: all[name], | |
| 14 | + enumerable: true | |
| 15 | + }); | |
| 16 | + } | |
| 17 | + if (!no_symbols) { | |
| 18 | + __defProp(target, Symbol.toStringTag, { value: "Module" }); | |
| 19 | + } | |
| 20 | + return target; | |
| 21 | + }; | |
| 10 | 22 | |
| 11 | -__webpack_require__.r(__webpack_exports__); | |
| 12 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 13 | -/* harmony export */ WpMediaNotAvailableError: function() { return /* binding */ WpMediaNotAvailableError; }, | |
| 14 | -/* harmony export */ WpPluploadSettingsNotAvailableError: function() { return /* binding */ WpPluploadSettingsNotAvailableError; } | |
| 15 | -/* harmony export */ }); | |
| 16 | -/* harmony import */ var _elementor_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/utils */ "@elementor/utils"); | |
| 17 | -/* harmony import */ var _elementor_utils__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_utils__WEBPACK_IMPORTED_MODULE_0__); | |
| 23 | +//#endregion | |
| 18 | 24 | |
| 19 | -const WpMediaNotAvailableError = (0,_elementor_utils__WEBPACK_IMPORTED_MODULE_0__.createError)({ | |
| 20 | - code: 'wp_media_not_available', | |
| 21 | - message: '`wp.media` is not available, make sure the `media-models` handle is set in the dependencies array' | |
| 22 | -}); | |
| 23 | -const WpPluploadSettingsNotAvailableError = (0,_elementor_utils__WEBPACK_IMPORTED_MODULE_0__.createError)({ | |
| 24 | - code: 'wp_plupload_settings_not_available', | |
| 25 | - message: '`_wpPluploadSettings` is not available, make sure a wp media uploader is open' | |
| 26 | -}); | |
| 25 | +//#region packages/packages/libs/wp-media/src/errors.ts | |
| 26 | + var WpMediaNotAvailableError = (0, _elementor_utils.createError)({ | |
| 27 | + code: "wp_media_not_available", | |
| 28 | + message: "`wp.media` is not available, make sure the `media-models` handle is set in the dependencies array" | |
| 29 | + }); | |
| 30 | + var WpPluploadSettingsNotAvailableError = (0, _elementor_utils.createError)({ | |
| 31 | + code: "wp_plupload_settings_not_available", | |
| 32 | + message: "`_wpPluploadSettings` is not available, make sure a wp media uploader is open" | |
| 33 | + }); | |
| 27 | 34 | |
| 28 | -/***/ }), | |
| 35 | +//#endregion | |
| 36 | +//#region packages/packages/libs/wp-media/src/media.ts | |
| 37 | + var wpMediaWindow = window; | |
| 38 | + var media_default = /* @__PURE__ */ __name(() => { | |
| 39 | + if (!wpMediaWindow.wp?.media) throw new WpMediaNotAvailableError(); | |
| 40 | + return wpMediaWindow.wp.media; | |
| 41 | + }, "default"); | |
| 29 | 42 | |
| 30 | -/***/ "./packages/packages/libs/wp-media/src/get-media-attachment.ts": | |
| 31 | -/*!*********************************************************************!*\ | |
| 32 | - !*** ./packages/packages/libs/wp-media/src/get-media-attachment.ts ***! | |
| 33 | - \*********************************************************************/ | |
| 34 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 43 | +//#endregion | |
| 44 | +//#region packages/packages/libs/wp-media/src/normalize.ts | |
| 45 | + function normalize(attachment) { | |
| 46 | + const { filesizeInBytes, filesizeHumanReadable, author, authorName, ...rest } = attachment; | |
| 47 | + return { | |
| 48 | + ...rest, | |
| 49 | + filesize: { | |
| 50 | + inBytes: filesizeInBytes, | |
| 51 | + humanReadable: filesizeHumanReadable | |
| 52 | + }, | |
| 53 | + author: { | |
| 54 | + id: parseInt(author), | |
| 55 | + name: authorName | |
| 56 | + } | |
| 57 | + }; | |
| 58 | + } | |
| 35 | 59 | |
| 36 | -__webpack_require__.r(__webpack_exports__); | |
| 37 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 38 | -/* harmony export */ fetchAttachmentFromWP: function() { return /* binding */ fetchAttachmentFromWP; }, | |
| 39 | -/* harmony export */ getMediaAttachment: function() { return /* binding */ getMediaAttachment; } | |
| 40 | -/* harmony export */ }); | |
| 41 | -/* harmony import */ var _elementor_query__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/query */ "@elementor/query"); | |
| 42 | -/* harmony import */ var _elementor_query__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_query__WEBPACK_IMPORTED_MODULE_0__); | |
| 43 | -/* harmony import */ var _media__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./media */ "./packages/packages/libs/wp-media/src/media.ts"); | |
| 44 | -/* harmony import */ var _normalize__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./normalize */ "./packages/packages/libs/wp-media/src/normalize.ts"); | |
| 60 | +//#endregion | |
| 61 | +//#region packages/packages/libs/wp-media/src/get-media-attachment.ts | |
| 62 | + async function fetchAttachmentFromWP(id) { | |
| 63 | + const model = media_default().attachment(id); | |
| 64 | + const wpAttachment = model.toJSON(); | |
| 65 | + if ("url" in wpAttachment) return normalize(wpAttachment); | |
| 66 | + try { | |
| 67 | + return normalize(await model.fetch()); | |
| 68 | + } catch { | |
| 69 | + return null; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + async function getMediaAttachment({ id }) { | |
| 73 | + if (!id) return null; | |
| 74 | + return (0, _elementor_query.getQueryClient)().ensureQueryData({ | |
| 75 | + queryKey: ["wp-attachment", id], | |
| 76 | + queryFn: () => fetchAttachmentFromWP(id) | |
| 77 | + }); | |
| 78 | + } | |
| 45 | 79 | |
| 80 | +//#endregion | |
| 81 | +//#region packages/packages/libs/wp-media/src/hooks/use-wp-media-attachment.ts | |
| 82 | + function useWpMediaAttachment(id) { | |
| 83 | + return (0, _elementor_query.useQuery)({ | |
| 84 | + queryKey: ["wp-attachment", id], | |
| 85 | + queryFn: () => fetchAttachmentFromWP(id), | |
| 86 | + enabled: !!id | |
| 87 | + }); | |
| 88 | + } | |
| 46 | 89 | |
| 90 | +//#endregion | |
| 91 | +//#region packages/packages/libs/wp-media/src/wp-plupload-settings.ts | |
| 92 | + var wpPluploadSettingsWindow = window; | |
| 93 | + var wp_plupload_settings_default = /* @__PURE__ */ __name(() => { | |
| 94 | + if (!wpPluploadSettingsWindow._wpPluploadSettings) throw new WpPluploadSettingsNotAvailableError(); | |
| 95 | + return wpPluploadSettingsWindow._wpPluploadSettings; | |
| 96 | + }, "default"); | |
| 47 | 97 | |
| 48 | -async function fetchAttachmentFromWP(id) { | |
| 49 | - const model = (0,_media__WEBPACK_IMPORTED_MODULE_1__["default"])().attachment(id); | |
| 50 | - const wpAttachment = model.toJSON(); | |
| 51 | - const isFetched = 'url' in wpAttachment; | |
| 52 | - if (isFetched) { | |
| 53 | - return (0,_normalize__WEBPACK_IMPORTED_MODULE_2__["default"])(wpAttachment); | |
| 54 | - } | |
| 55 | - try { | |
| 56 | - return (0,_normalize__WEBPACK_IMPORTED_MODULE_2__["default"])(await model.fetch()); | |
| 57 | - } catch { | |
| 58 | - return null; | |
| 59 | - } | |
| 60 | -} | |
| 61 | -async function getMediaAttachment({ | |
| 62 | - id | |
| 63 | -}) { | |
| 64 | - if (!id) { | |
| 65 | - return null; | |
| 66 | - } | |
| 67 | - const queryClient = (0,_elementor_query__WEBPACK_IMPORTED_MODULE_0__.getQueryClient)(); | |
| 68 | - return queryClient.ensureQueryData({ | |
| 69 | - queryKey: ['wp-attachment', id], | |
| 70 | - queryFn: () => fetchAttachmentFromWP(id) | |
| 71 | - }); | |
| 72 | -} | |
| 98 | +//#endregion | |
| 99 | +//#region packages/packages/libs/wp-media/src/hooks/use-wp-media-frame.ts | |
| 100 | + function useWpMediaFrame(options) { | |
| 101 | + const frame = (0, react.useRef)(); | |
| 102 | + const open = (openOptions = {}) => { | |
| 103 | + cleanupFrame(frame.current); | |
| 104 | + frame.current = createFrame({ | |
| 105 | + ...options, | |
| 106 | + ...openOptions | |
| 107 | + }); | |
| 108 | + frame.current?.open(); | |
| 109 | + }; | |
| 110 | + (0, react.useEffect)(() => { | |
| 111 | + return () => { | |
| 112 | + cleanupFrame(frame.current); | |
| 113 | + }; | |
| 114 | + }, []); | |
| 115 | + return { open }; | |
| 116 | + } | |
| 117 | + function createFrame({ onSelect, onSelectUrl, allowUrlImport, multiple, mediaTypes, selected, title, mode = "browse", currentUrl, currentAlt }) { | |
| 118 | + const frame = media_default()({ | |
| 119 | + title, | |
| 120 | + multiple, | |
| 121 | + library: { type: getMimeTypes(mediaTypes) }, | |
| 122 | + ...allowUrlImport ? { frame: "post" } : {} | |
| 123 | + }).on("open", () => { | |
| 124 | + setTypeCaller(frame); | |
| 125 | + applyMode(frame, mode, currentUrl, currentAlt); | |
| 126 | + if (mode !== "url") applySelection(frame, selected); | |
| 127 | + }).on("insert select", () => select(frame, multiple, onSelect, onSelectUrl)); | |
| 128 | + if (allowUrlImport) frame.on("ready open", () => restrictFrameMenu(frame)); | |
| 129 | + handleExtensions(frame, mediaTypes); | |
| 130 | + return frame; | |
| 131 | + } | |
| 132 | + function cleanupFrame(frame) { | |
| 133 | + frame?.detach(); | |
| 134 | + frame?.remove(); | |
| 135 | + } | |
| 136 | + function applyMode(frame, mode = "browse", currentUrl, currentAlt) { | |
| 137 | + if (mode === "url") { | |
| 138 | + frame.setState("embed"); | |
| 139 | + if (currentUrl || currentAlt) setTimeout(() => { | |
| 140 | + if (currentUrl) frame.state()?.props?.set("url", currentUrl); | |
| 141 | + if (currentAlt) frame.state()?.props?.set("alt", currentAlt); | |
| 142 | + }, 0); | |
| 143 | + } else frame.content.mode(mode); | |
| 144 | + } | |
| 145 | + function applySelection(frame, selected) { | |
| 146 | + const selectedAttachments = (typeof selected === "number" ? [selected] : selected)?.filter((id) => !!id).map((id) => media_default().attachment(id)); | |
| 147 | + frame.state().get("selection").set(selectedAttachments || []); | |
| 148 | + } | |
| 149 | + function select(frame, multiple, onSelect, onSelectUrl) { | |
| 150 | + const state = frame.state(); | |
| 151 | + if (state.get("id") === "embed") { | |
| 152 | + if (onSelectUrl) { | |
| 153 | + const url = state.props?.get("url"); | |
| 154 | + const alt = state.props?.get("alt"); | |
| 155 | + if (url) onSelectUrl(url, alt); | |
| 156 | + } | |
| 157 | + return; | |
| 158 | + } | |
| 159 | + const attachments = state.get("selection").toJSON().map(normalize); | |
| 160 | + onSelect(multiple ? attachments : attachments[0]); | |
| 161 | + } | |
| 162 | + var FRAME_MENU_ITEMS_TO_REMOVE = [ | |
| 163 | + "#menu-item-gallery", | |
| 164 | + "#menu-item-featured-image", | |
| 165 | + "#menu-item-playlist", | |
| 166 | + "#menu-item-video-playlist" | |
| 167 | + ].join(","); | |
| 168 | + function restrictFrameMenu(frame) { | |
| 169 | + frame.$el?.find(FRAME_MENU_ITEMS_TO_REMOVE)?.remove(); | |
| 170 | + } | |
| 171 | + function setTypeCaller(frame) { | |
| 172 | + frame.uploader.uploader.param("uploadTypeCaller", "elementor-wp-media-upload"); | |
| 173 | + } | |
| 174 | + function handleExtensions(frame, mediaTypes) { | |
| 175 | + const defaultExtensions = wp_plupload_settings_default().defaults.filters.mime_types?.[0]?.extensions; | |
| 176 | + frame.on("ready", () => { | |
| 177 | + wp_plupload_settings_default().defaults.filters.mime_types = [{ extensions: getExtensions(mediaTypes) }]; | |
| 178 | + }); | |
| 179 | + frame.on("close", () => { | |
| 180 | + wp_plupload_settings_default().defaults.filters.mime_types = defaultExtensions ? [{ extensions: defaultExtensions }] : []; | |
| 181 | + }); | |
| 182 | + } | |
| 183 | + var imageExtensions = [ | |
| 184 | + "avif", | |
| 185 | + "bmp", | |
| 186 | + "gif", | |
| 187 | + "ico", | |
| 188 | + "jpe", | |
| 189 | + "jpeg", | |
| 190 | + "jpg", | |
| 191 | + "png", | |
| 192 | + "webp" | |
| 193 | + ]; | |
| 194 | + var videoExtensions = [ | |
| 195 | + "mp4", | |
| 196 | + "webm", | |
| 197 | + "ogg", | |
| 198 | + "mov", | |
| 199 | + "m4v", | |
| 200 | + "avi", | |
| 201 | + "wmv", | |
| 202 | + "mpg", | |
| 203 | + "mpeg", | |
| 204 | + "3gp", | |
| 205 | + "3g2" | |
| 206 | + ]; | |
| 207 | + function getMimeTypes(mediaTypes) { | |
| 208 | + const mimeTypesPerType = { | |
| 209 | + image: imageExtensions.map((extension) => `image/${extension}`), | |
| 210 | + svg: ["image/svg+xml"], | |
| 211 | + video: [ | |
| 212 | + "video/mp4", | |
| 213 | + "video/webm", | |
| 214 | + "video/ogg", | |
| 215 | + "video/quicktime", | |
| 216 | + "video/x-m4v", | |
| 217 | + "video/avi", | |
| 218 | + "video/x-ms-wmv", | |
| 219 | + "video/mpeg", | |
| 220 | + "video/3gpp", | |
| 221 | + "video/3gpp2" | |
| 222 | + ] | |
| 223 | + }; | |
| 224 | + return mediaTypes.reduce((prev, currentType) => { | |
| 225 | + return prev.concat(mimeTypesPerType[currentType]); | |
| 226 | + }, []); | |
| 227 | + } | |
| 228 | + function getExtensions(mediaTypes) { | |
| 229 | + const extensionsPerType = { | |
| 230 | + image: imageExtensions, | |
| 231 | + svg: ["svg"], | |
| 232 | + video: videoExtensions | |
| 233 | + }; | |
| 234 | + return mediaTypes.reduce((prev, currentType) => { | |
| 235 | + return prev.concat(extensionsPerType[currentType]); | |
| 236 | + }, []).join(","); | |
| 237 | + } | |
| 73 | 238 | |
| 74 | -/***/ }), | |
| 239 | +//#endregion | |
| 240 | +//#region packages/packages/libs/wp-media/src/index.ts | |
| 241 | + var src_exports = /* @__PURE__ */ __exportAll({ | |
| 242 | + getMediaAttachment: () => getMediaAttachment, | |
| 243 | + useWpMediaAttachment: () => useWpMediaAttachment, | |
| 244 | + useWpMediaFrame: () => useWpMediaFrame | |
| 245 | + }); | |
| 75 | 246 | |
| 76 | -/***/ "./packages/packages/libs/wp-media/src/hooks/use-wp-media-attachment.ts": | |
| 77 | -/*!******************************************************************************!*\ | |
| 78 | - !*** ./packages/packages/libs/wp-media/src/hooks/use-wp-media-attachment.ts ***! | |
| 79 | - \******************************************************************************/ | |
| 80 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 247 | +//#endregion | |
| 248 | +//#region \0elementor-package-library-entry | |
| 249 | + (window.elementorV2 = window.elementorV2 || {}).wpMedia = src_exports; | |
| 81 | 250 | |
| 82 | -__webpack_require__.r(__webpack_exports__); | |
| 83 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 84 | -/* harmony export */ "default": function() { return /* binding */ useWpMediaAttachment; } | |
| 85 | -/* harmony export */ }); | |
| 86 | -/* harmony import */ var _elementor_query__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/query */ "@elementor/query"); | |
| 87 | -/* harmony import */ var _elementor_query__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_query__WEBPACK_IMPORTED_MODULE_0__); | |
| 88 | -/* harmony import */ var _get_media_attachment__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../get-media-attachment */ "./packages/packages/libs/wp-media/src/get-media-attachment.ts"); | |
| 89 | - | |
| 90 | - | |
| 91 | -function useWpMediaAttachment(id) { | |
| 92 | - return (0,_elementor_query__WEBPACK_IMPORTED_MODULE_0__.useQuery)({ | |
| 93 | - queryKey: ['wp-attachment', id], | |
| 94 | - queryFn: () => (0,_get_media_attachment__WEBPACK_IMPORTED_MODULE_1__.fetchAttachmentFromWP)(id), | |
| 95 | - enabled: !!id | |
| 96 | - }); | |
| 97 | -} | |
| 98 | - | |
| 99 | -/***/ }), | |
| 100 | - | |
| 101 | -/***/ "./packages/packages/libs/wp-media/src/hooks/use-wp-media-frame.ts": | |
| 102 | -/*!*************************************************************************!*\ | |
| 103 | - !*** ./packages/packages/libs/wp-media/src/hooks/use-wp-media-frame.ts ***! | |
| 104 | - \*************************************************************************/ | |
| 105 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 106 | - | |
| 107 | -__webpack_require__.r(__webpack_exports__); | |
| 108 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 109 | -/* harmony export */ "default": function() { return /* binding */ useWpMediaFrame; } | |
| 110 | -/* harmony export */ }); | |
| 111 | -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 112 | -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 113 | -/* harmony import */ var _media__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../media */ "./packages/packages/libs/wp-media/src/media.ts"); | |
| 114 | -/* harmony import */ var _normalize__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../normalize */ "./packages/packages/libs/wp-media/src/normalize.ts"); | |
| 115 | -/* harmony import */ var _wp_plupload_settings__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../wp-plupload-settings */ "./packages/packages/libs/wp-media/src/wp-plupload-settings.ts"); | |
| 116 | - | |
| 117 | - | |
| 118 | - | |
| 119 | - | |
| 120 | -function useWpMediaFrame(options) { | |
| 121 | - const frame = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(); | |
| 122 | - const open = (openOptions = {}) => { | |
| 123 | - cleanupFrame(frame.current); | |
| 124 | - frame.current = createFrame({ | |
| 125 | - ...options, | |
| 126 | - ...openOptions | |
| 127 | - }); | |
| 128 | - frame.current?.open(); | |
| 129 | - }; | |
| 130 | - (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => { | |
| 131 | - return () => { | |
| 132 | - cleanupFrame(frame.current); | |
| 133 | - }; | |
| 134 | - }, []); | |
| 135 | - return { | |
| 136 | - open | |
| 137 | - }; | |
| 138 | -} | |
| 139 | -function createFrame({ | |
| 140 | - onSelect, | |
| 141 | - onSelectUrl, | |
| 142 | - allowUrlImport, | |
| 143 | - multiple, | |
| 144 | - mediaTypes, | |
| 145 | - selected, | |
| 146 | - title, | |
| 147 | - mode = 'browse', | |
| 148 | - currentUrl, | |
| 149 | - currentAlt | |
| 150 | -}) { | |
| 151 | - const frame = (0,_media__WEBPACK_IMPORTED_MODULE_1__["default"])()({ | |
| 152 | - title, | |
| 153 | - multiple, | |
| 154 | - library: { | |
| 155 | - type: getMimeTypes(mediaTypes) | |
| 156 | - }, | |
| 157 | - ...(allowUrlImport ? { | |
| 158 | - frame: 'post' | |
| 159 | - } : {}) | |
| 160 | - }).on('open', () => { | |
| 161 | - setTypeCaller(frame); | |
| 162 | - applyMode(frame, mode, currentUrl, currentAlt); | |
| 163 | - if (mode !== 'url') { | |
| 164 | - applySelection(frame, selected); | |
| 165 | - } | |
| 166 | - }).on('insert select', () => select(frame, multiple, onSelect, onSelectUrl)); | |
| 167 | - if (allowUrlImport) { | |
| 168 | - frame.on('ready open', () => restrictFrameMenu(frame)); | |
| 169 | - } | |
| 170 | - handleExtensions(frame, mediaTypes); | |
| 171 | - return frame; | |
| 172 | -} | |
| 173 | -function cleanupFrame(frame) { | |
| 174 | - frame?.detach(); | |
| 175 | - frame?.remove(); | |
| 176 | -} | |
| 177 | -function applyMode(frame, mode = 'browse', currentUrl, currentAlt) { | |
| 178 | - if (mode === 'url') { | |
| 179 | - frame.setState('embed'); | |
| 180 | - if (currentUrl || currentAlt) { | |
| 181 | - // Defer so the toolbar region is initialized before change:url triggers its refresh callback. | |
| 182 | - setTimeout(() => { | |
| 183 | - if (currentUrl) { | |
| 184 | - frame.state()?.props?.set('url', currentUrl); | |
| 185 | - } | |
| 186 | - if (currentAlt) { | |
| 187 | - frame.state()?.props?.set('alt', currentAlt); | |
| 188 | - } | |
| 189 | - }, 0); | |
| 190 | - } | |
| 191 | - } else { | |
| 192 | - frame.content.mode(mode); | |
| 193 | - } | |
| 194 | -} | |
| 195 | -function applySelection(frame, selected) { | |
| 196 | - const selectedAttachments = (typeof selected === 'number' ? [selected] : selected)?.filter(id => !!id).map(id => (0,_media__WEBPACK_IMPORTED_MODULE_1__["default"])().attachment(id)); | |
| 197 | - frame.state().get('selection').set(selectedAttachments || []); | |
| 198 | -} | |
| 199 | -function select(frame, multiple, onSelect, onSelectUrl) { | |
| 200 | - const state = frame.state(); | |
| 201 | - if (state.get('id') === 'embed') { | |
| 202 | - if (onSelectUrl) { | |
| 203 | - const url = state.props?.get('url'); | |
| 204 | - const alt = state.props?.get('alt'); | |
| 205 | - if (url) { | |
| 206 | - onSelectUrl(url, alt); | |
| 207 | - } | |
| 208 | - } | |
| 209 | - return; | |
| 210 | - } | |
| 211 | - const attachments = state.get('selection').toJSON().map(_normalize__WEBPACK_IMPORTED_MODULE_2__["default"]); | |
| 212 | - const onSelectFn = onSelect; | |
| 213 | - onSelectFn(multiple ? attachments : attachments[0]); | |
| 214 | -} | |
| 215 | -const FRAME_MENU_ITEMS_TO_REMOVE = ['#menu-item-gallery', '#menu-item-featured-image', '#menu-item-playlist', '#menu-item-video-playlist'].join(','); | |
| 216 | -function restrictFrameMenu(frame) { | |
| 217 | - frame.$el?.find(FRAME_MENU_ITEMS_TO_REMOVE)?.remove(); | |
| 218 | -} | |
| 219 | -function setTypeCaller(frame) { | |
| 220 | - frame.uploader.uploader.param('uploadTypeCaller', 'elementor-wp-media-upload'); | |
| 221 | -} | |
| 222 | -function handleExtensions(frame, mediaTypes) { | |
| 223 | - const defaultExtensions = (0,_wp_plupload_settings__WEBPACK_IMPORTED_MODULE_3__["default"])().defaults.filters.mime_types?.[0]?.extensions; | |
| 224 | - | |
| 225 | - // Set extensions by media types | |
| 226 | - frame.on('ready', () => { | |
| 227 | - (0,_wp_plupload_settings__WEBPACK_IMPORTED_MODULE_3__["default"])().defaults.filters.mime_types = [{ | |
| 228 | - extensions: getExtensions(mediaTypes) | |
| 229 | - }]; | |
| 230 | - }); | |
| 231 | - | |
| 232 | - // Restore default upload extensions | |
| 233 | - frame.on('close', () => { | |
| 234 | - (0,_wp_plupload_settings__WEBPACK_IMPORTED_MODULE_3__["default"])().defaults.filters.mime_types = defaultExtensions ? [{ | |
| 235 | - extensions: defaultExtensions | |
| 236 | - }] : []; | |
| 237 | - }); | |
| 238 | -} | |
| 239 | -const imageExtensions = ['avif', 'bmp', 'gif', 'ico', 'jpe', 'jpeg', 'jpg', 'png', 'webp']; | |
| 240 | -const videoExtensions = ['mp4', 'webm', 'ogg', 'mov', 'm4v', 'avi', 'wmv', 'mpg', 'mpeg', '3gp', '3g2']; | |
| 241 | -function getMimeTypes(mediaTypes) { | |
| 242 | - const mimeTypesPerType = { | |
| 243 | - image: imageExtensions.map(extension => `image/${extension}`), | |
| 244 | - svg: ['image/svg+xml'], | |
| 245 | - video: ['video/mp4', 'video/webm', 'video/ogg', 'video/quicktime', 'video/x-m4v', 'video/avi', 'video/x-ms-wmv', 'video/mpeg', 'video/3gpp', 'video/3gpp2'] | |
| 246 | - }; | |
| 247 | - return mediaTypes.reduce((prev, currentType) => { | |
| 248 | - return prev.concat(mimeTypesPerType[currentType]); | |
| 249 | - }, []); | |
| 250 | -} | |
| 251 | -function getExtensions(mediaTypes) { | |
| 252 | - const extensionsPerType = { | |
| 253 | - image: imageExtensions, | |
| 254 | - svg: ['svg'], | |
| 255 | - video: videoExtensions | |
| 256 | - }; | |
| 257 | - const extensions = mediaTypes.reduce((prev, currentType) => { | |
| 258 | - return prev.concat(extensionsPerType[currentType]); | |
| 259 | - }, []); | |
| 260 | - return extensions.join(','); | |
| 261 | -} | |
| 262 | - | |
| 263 | -/***/ }), | |
| 264 | - | |
| 265 | -/***/ "./packages/packages/libs/wp-media/src/media.ts": | |
| 266 | -/*!******************************************************!*\ | |
| 267 | - !*** ./packages/packages/libs/wp-media/src/media.ts ***! | |
| 268 | - \******************************************************/ | |
| 269 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 270 | - | |
| 271 | -__webpack_require__.r(__webpack_exports__); | |
| 272 | -/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./errors */ "./packages/packages/libs/wp-media/src/errors.ts"); | |
| 273 | - | |
| 274 | -const wpMediaWindow = window; | |
| 275 | -/* harmony default export */ __webpack_exports__["default"] = (() => { | |
| 276 | - if (!wpMediaWindow.wp?.media) { | |
| 277 | - throw new _errors__WEBPACK_IMPORTED_MODULE_0__.WpMediaNotAvailableError(); | |
| 278 | - } | |
| 279 | - return wpMediaWindow.wp.media; | |
| 280 | -}); | |
| 281 | - | |
| 282 | -/***/ }), | |
| 283 | - | |
| 284 | -/***/ "./packages/packages/libs/wp-media/src/normalize.ts": | |
| 285 | -/*!**********************************************************!*\ | |
| 286 | - !*** ./packages/packages/libs/wp-media/src/normalize.ts ***! | |
| 287 | - \**********************************************************/ | |
| 288 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 289 | - | |
| 290 | -__webpack_require__.r(__webpack_exports__); | |
| 291 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 292 | -/* harmony export */ "default": function() { return /* binding */ normalize; } | |
| 293 | -/* harmony export */ }); | |
| 294 | -function normalize(attachment) { | |
| 295 | - const { | |
| 296 | - filesizeInBytes, | |
| 297 | - filesizeHumanReadable, | |
| 298 | - author, | |
| 299 | - authorName, | |
| 300 | - ...rest | |
| 301 | - } = attachment; | |
| 302 | - return { | |
| 303 | - ...rest, | |
| 304 | - filesize: { | |
| 305 | - inBytes: filesizeInBytes, | |
| 306 | - humanReadable: filesizeHumanReadable | |
| 307 | - }, | |
| 308 | - author: { | |
| 309 | - id: parseInt(author), | |
| 310 | - name: authorName | |
| 311 | - } | |
| 312 | - }; | |
| 313 | -} | |
| 314 | - | |
| 315 | -/***/ }), | |
| 316 | - | |
| 317 | -/***/ "./packages/packages/libs/wp-media/src/wp-plupload-settings.ts": | |
| 318 | -/*!*********************************************************************!*\ | |
| 319 | - !*** ./packages/packages/libs/wp-media/src/wp-plupload-settings.ts ***! | |
| 320 | - \*********************************************************************/ | |
| 321 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 322 | - | |
| 323 | -__webpack_require__.r(__webpack_exports__); | |
| 324 | -/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./errors */ "./packages/packages/libs/wp-media/src/errors.ts"); | |
| 325 | - | |
| 326 | -const wpPluploadSettingsWindow = window; | |
| 327 | -/* harmony default export */ __webpack_exports__["default"] = (() => { | |
| 328 | - if (!wpPluploadSettingsWindow._wpPluploadSettings) { | |
| 329 | - throw new _errors__WEBPACK_IMPORTED_MODULE_0__.WpPluploadSettingsNotAvailableError(); | |
| 330 | - } | |
| 331 | - return wpPluploadSettingsWindow._wpPluploadSettings; | |
| 332 | -}); | |
| 333 | - | |
| 334 | -/***/ }), | |
| 335 | - | |
| 336 | -/***/ "@elementor/query": | |
| 337 | -/*!****************************************!*\ | |
| 338 | - !*** external ["elementorV2","query"] ***! | |
| 339 | - \****************************************/ | |
| 340 | -/***/ (function(module) { | |
| 341 | - | |
| 342 | -module.exports = window["elementorV2"]["query"]; | |
| 343 | - | |
| 344 | -/***/ }), | |
| 345 | - | |
| 346 | -/***/ "@elementor/utils": | |
| 347 | -/*!****************************************!*\ | |
| 348 | - !*** external ["elementorV2","utils"] ***! | |
| 349 | - \****************************************/ | |
| 350 | -/***/ (function(module) { | |
| 351 | - | |
| 352 | -module.exports = window["elementorV2"]["utils"]; | |
| 353 | - | |
| 354 | -/***/ }), | |
| 355 | - | |
| 356 | -/***/ "react": | |
| 357 | -/*!**************************!*\ | |
| 358 | - !*** external ["React"] ***! | |
| 359 | - \**************************/ | |
| 360 | -/***/ (function(module) { | |
| 361 | - | |
| 362 | -module.exports = window["React"]; | |
| 363 | - | |
| 364 | -/***/ }) | |
| 365 | - | |
| 366 | -/******/ }); | |
| 367 | -/************************************************************************/ | |
| 368 | -/******/ // The module cache | |
| 369 | -/******/ var __webpack_module_cache__ = {}; | |
| 370 | -/******/ | |
| 371 | -/******/ // The require function | |
| 372 | -/******/ function __webpack_require__(moduleId) { | |
| 373 | -/******/ // Check if module is in cache | |
| 374 | -/******/ var cachedModule = __webpack_module_cache__[moduleId]; | |
| 375 | -/******/ if (cachedModule !== undefined) { | |
| 376 | -/******/ return cachedModule.exports; | |
| 377 | -/******/ } | |
| 378 | -/******/ // Create a new module (and put it into the cache) | |
| 379 | -/******/ var module = __webpack_module_cache__[moduleId] = { | |
| 380 | -/******/ // no module.id needed | |
| 381 | -/******/ // no module.loaded needed | |
| 382 | -/******/ exports: {} | |
| 383 | -/******/ }; | |
| 384 | -/******/ | |
| 385 | -/******/ // Execute the module function | |
| 386 | -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | |
| 387 | -/******/ | |
| 388 | -/******/ // Return the exports of the module | |
| 389 | -/******/ return module.exports; | |
| 390 | -/******/ } | |
| 391 | -/******/ | |
| 392 | -/************************************************************************/ | |
| 393 | -/******/ /* webpack/runtime/compat get default export */ | |
| 394 | -/******/ !function() { | |
| 395 | -/******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 396 | -/******/ __webpack_require__.n = function(module) { | |
| 397 | -/******/ var getter = module && module.__esModule ? | |
| 398 | -/******/ function() { return module['default']; } : | |
| 399 | -/******/ function() { return module; }; | |
| 400 | -/******/ __webpack_require__.d(getter, { a: getter }); | |
| 401 | -/******/ return getter; | |
| 402 | -/******/ }; | |
| 403 | -/******/ }(); | |
| 404 | -/******/ | |
| 405 | -/******/ /* webpack/runtime/define property getters */ | |
| 406 | -/******/ !function() { | |
| 407 | -/******/ // define getter functions for harmony exports | |
| 408 | -/******/ __webpack_require__.d = function(exports, definition) { | |
| 409 | -/******/ for(var key in definition) { | |
| 410 | -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 411 | -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 412 | -/******/ } | |
| 413 | -/******/ } | |
| 414 | -/******/ }; | |
| 415 | -/******/ }(); | |
| 416 | -/******/ | |
| 417 | -/******/ /* webpack/runtime/hasOwnProperty shorthand */ | |
| 418 | -/******/ !function() { | |
| 419 | -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | |
| 420 | -/******/ }(); | |
| 421 | -/******/ | |
| 422 | -/******/ /* webpack/runtime/make namespace object */ | |
| 423 | -/******/ !function() { | |
| 424 | -/******/ // define __esModule on exports | |
| 425 | -/******/ __webpack_require__.r = function(exports) { | |
| 426 | -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 427 | -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
| 428 | -/******/ } | |
| 429 | -/******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
| 430 | -/******/ }; | |
| 431 | -/******/ }(); | |
| 432 | -/******/ | |
| 433 | -/************************************************************************/ | |
| 434 | -var __webpack_exports__ = {}; | |
| 435 | -// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. | |
| 436 | -!function() { | |
| 437 | -/*!******************************************************!*\ | |
| 438 | - !*** ./packages/packages/libs/wp-media/src/index.ts ***! | |
| 439 | - \******************************************************/ | |
| 440 | -__webpack_require__.r(__webpack_exports__); | |
| 441 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 442 | -/* harmony export */ getMediaAttachment: function() { return /* reexport safe */ _get_media_attachment__WEBPACK_IMPORTED_MODULE_2__.getMediaAttachment; }, | |
| 443 | -/* harmony export */ useWpMediaAttachment: function() { return /* reexport safe */ _hooks_use_wp_media_attachment__WEBPACK_IMPORTED_MODULE_0__["default"]; }, | |
| 444 | -/* harmony export */ useWpMediaFrame: function() { return /* reexport safe */ _hooks_use_wp_media_frame__WEBPACK_IMPORTED_MODULE_1__["default"]; } | |
| 445 | -/* harmony export */ }); | |
| 446 | -/* harmony import */ var _hooks_use_wp_media_attachment__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hooks/use-wp-media-attachment */ "./packages/packages/libs/wp-media/src/hooks/use-wp-media-attachment.ts"); | |
| 447 | -/* harmony import */ var _hooks_use_wp_media_frame__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./hooks/use-wp-media-frame */ "./packages/packages/libs/wp-media/src/hooks/use-wp-media-frame.ts"); | |
| 448 | -/* harmony import */ var _get_media_attachment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./get-media-attachment */ "./packages/packages/libs/wp-media/src/get-media-attachment.ts"); | |
| 449 | - | |
| 450 | - | |
| 451 | - | |
| 452 | -}(); | |
| 453 | -(window.elementorV2 = window.elementorV2 || {}).wpMedia = __webpack_exports__; | |
| 454 | -/******/ })() | |
| 455 | -; | |
| 251 | +//#endregion | |
| 252 | +})(elementorV2.query, elementorV2.utils, React); | |
| 456 | 253 | window.elementorV2.wpMedia?.init?.(); |
| 457 | 254 | //# sourceMappingURL=wp-media.js.map |