Skip to content

Commit

Permalink
Added .webp support
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonin committed Mar 21, 2024
1 parent 32cf3b3 commit 4567072
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Validator/ImageValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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));
}
Expand All @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion assets/dist/bootstrap_modal_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion assets/dist/crop_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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;
Expand Down
29 changes: 14 additions & 15 deletions assets/dist/media_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion assets/dist/upload_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions assets/src/media_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 4567072

Please sign in to comment.