From 45670722b4e71adc8bbf24e4396227ea7c79a09c Mon Sep 17 00:00:00 2001 From: Antonin Date: Thu, 21 Mar 2024 10:23:07 +0100 Subject: [PATCH] Added .webp support --- Validator/ImageValidator.php | 5 ++-- assets/dist/bootstrap_modal_controller.js | 2 +- assets/dist/crop_controller.js | 2 +- assets/dist/media_controller.js | 29 +++++++++++------------ assets/dist/upload_controller.js | 2 +- assets/src/media_controller.js | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Validator/ImageValidator.php b/Validator/ImageValidator.php index 8b147fa..eecc9ff 100644 --- a/Validator/ImageValidator.php +++ b/Validator/ImageValidator.php @@ -8,7 +8,7 @@ class ImageValidator extends ConstraintValidator { - public const SUPPORTED_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'svg']; + public const SUPPORTED_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp']; public function validate($value, Constraint $constraint) { @@ -27,6 +27,7 @@ public function validate($value, Constraint $constraint) private function checkExtension(Constraint $constraint, string $path): void { + $extension = ''; if ($path = parse_url($path)) { $extension = mb_strtolower(pathinfo($path['path'], PATHINFO_EXTENSION)); } @@ -37,7 +38,7 @@ private function checkExtension(Constraint $constraint, string $path): void $supportedExtensions = self::SUPPORTED_EXTENSIONS; } - if (!\in_array($extension, $supportedExtensions)) { + if (!\in_array($extension, $supportedExtensions, true)) { $this->context->buildViolation($constraint->message)->addViolation(); } } diff --git a/assets/dist/bootstrap_modal_controller.js b/assets/dist/bootstrap_modal_controller.js index 8b5fc24..f0de259 100644 --- a/assets/dist/bootstrap_modal_controller.js +++ b/assets/dist/bootstrap_modal_controller.js @@ -10,10 +10,10 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec import { Controller } from '@hotwired/stimulus'; import Modal from 'bootstrap/js/dist/modal'; var _default = /*#__PURE__*/function (_Controller) { - _inheritsLoose(_default, _Controller); function _default() { return _callSuper(this, _default, arguments); } + _inheritsLoose(_default, _Controller); return _default; }(Controller); export { _default as default }; diff --git a/assets/dist/crop_controller.js b/assets/dist/crop_controller.js index b807bfc..0493aca 100644 --- a/assets/dist/crop_controller.js +++ b/assets/dist/crop_controller.js @@ -11,7 +11,6 @@ import { Controller } from '@hotwired/stimulus'; import Cropper from 'cropperjs'; import 'cropperjs'; var _default = /*#__PURE__*/function (_Controller) { - _inheritsLoose(_default, _Controller); function _default() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { @@ -21,6 +20,7 @@ var _default = /*#__PURE__*/function (_Controller) { _this.parent = void 0; return _this; } + _inheritsLoose(_default, _Controller); var _proto = _default.prototype; _proto.connect = function connect() { var _this2 = this; diff --git a/assets/dist/media_controller.js b/assets/dist/media_controller.js index 56189a2..37d80d2 100644 --- a/assets/dist/media_controller.js +++ b/assets/dist/media_controller.js @@ -2,13 +2,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } -function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } @@ -25,41 +25,41 @@ var _setErrorMessage = /*#__PURE__*/_classPrivateFieldLooseKey("setErrorMessage" var _disableCropButton = /*#__PURE__*/_classPrivateFieldLooseKey("disableCropButton"); var _hideClearButton = /*#__PURE__*/_classPrivateFieldLooseKey("hideClearButton"); var _default = /*#__PURE__*/function (_Controller) { - _inheritsLoose(_default, _Controller); function _default() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, _default, [].concat(args)); - Object.defineProperty(_assertThisInitialized(_this), _hideClearButton, { + Object.defineProperty(_this, _hideClearButton, { value: _hideClearButton2 }); - Object.defineProperty(_assertThisInitialized(_this), _disableCropButton, { + Object.defineProperty(_this, _disableCropButton, { value: _disableCropButton2 }); - Object.defineProperty(_assertThisInitialized(_this), _setErrorMessage, { + Object.defineProperty(_this, _setErrorMessage, { value: _setErrorMessage2 }); - Object.defineProperty(_assertThisInitialized(_this), _uploadFiles, { + Object.defineProperty(_this, _uploadFiles, { value: _uploadFiles2 }); - Object.defineProperty(_assertThisInitialized(_this), _toggleProgress, { + Object.defineProperty(_this, _toggleProgress, { value: _toggleProgress2 }); - Object.defineProperty(_assertThisInitialized(_this), _pathUpdateEventListener, { + Object.defineProperty(_this, _pathUpdateEventListener, { value: _pathUpdateEventListener2 }); - Object.defineProperty(_assertThisInitialized(_this), _dragCounter, { + Object.defineProperty(_this, _dragCounter, { writable: true, value: 0 }); - Object.defineProperty(_assertThisInitialized(_this), _iframeTriggered, { + Object.defineProperty(_this, _iframeTriggered, { writable: true, value: false }); return _this; } + _inheritsLoose(_default, _Controller); var _proto = _default.prototype; _proto.connect = function connect() { this.element[this.identifier] = this; @@ -95,7 +95,7 @@ var _default = /*#__PURE__*/function (_Controller) { _classPrivateFieldLooseBase(this, _disableCropButton)[_disableCropButton](); _classPrivateFieldLooseBase(this, _hideClearButton)[_hideClearButton](!hasValue); if (hasValue) { - if (this.pathValue.match(/.(jpg|jpeg|png|gif|svg)/i)) { + if (this.pathValue.match(/.(jpg|jpeg|png|gif|svg|webp)/i)) { var img = document.createElement('img'); img.src = this.pathValue; img.height = 75; @@ -105,7 +105,7 @@ var _default = /*#__PURE__*/function (_Controller) { }); img.addEventListener('load', function () { _this2.imageLoaded = true; - _classPrivateFieldLooseBase(_this2, _disableCropButton)[_disableCropButton](!img.getAttribute('src').match(/^\/.+(jpg|jpeg|png|gif)$/i)); + _classPrivateFieldLooseBase(_this2, _disableCropButton)[_disableCropButton](!img.getAttribute('src').match(/^\/.+(jpg|jpeg|png|webp)$/i)); }); this.filePreviewTarget.innerHTML = ''; this.filePreviewTarget.appendChild(img); @@ -193,13 +193,12 @@ var _default = /*#__PURE__*/function (_Controller) { _proto.dragover = function dragover(event) { event.preventDefault(); }; - _createClass(_default, [{ + return _createClass(_default, [{ key: "fileManagerUrl", get: function get() { return this.element.dataset.filemanagerUrl; } }]); - return _default; }(Controller); function _pathUpdateEventListener2(data) { this.pathValue = data.detail; diff --git a/assets/dist/upload_controller.js b/assets/dist/upload_controller.js index aa44a6d..bced3d1 100644 --- a/assets/dist/upload_controller.js +++ b/assets/dist/upload_controller.js @@ -9,10 +9,10 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.crea function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } import { Controller } from '@hotwired/stimulus'; var _default = /*#__PURE__*/function (_Controller) { - _inheritsLoose(_default, _Controller); function _default() { return _callSuper(this, _default, arguments); } + _inheritsLoose(_default, _Controller); var _proto = _default.prototype; _proto.click = function click() { this.inputFileTarget.click(); diff --git a/assets/src/media_controller.js b/assets/src/media_controller.js index 3b5b9a9..d7b89ac 100644 --- a/assets/src/media_controller.js +++ b/assets/src/media_controller.js @@ -145,7 +145,7 @@ export default class extends Controller { this.#disableCropButton(); this.#hideClearButton(!hasValue); if (hasValue) { - if (this.pathValue.match(/.(jpg|jpeg|png|gif|svg)/i)) { + if (this.pathValue.match(/.(jpg|jpeg|png|gif|svg|webp)/i)) { const img = document.createElement('img'); img.src = this.pathValue; img.height = 75; @@ -155,7 +155,7 @@ export default class extends Controller { }); img.addEventListener('load', () => { this.imageLoaded = true; - this.#disableCropButton(!img.getAttribute('src').match(/^\/.+(jpg|jpeg|png|gif)$/i)); + this.#disableCropButton(!img.getAttribute('src').match(/^\/.+(jpg|jpeg|png|webp)$/i)); }); this.filePreviewTarget.innerHTML = ''; this.filePreviewTarget.appendChild(img);